From 7302834d92f6602d5360ccd1bc1e5d098202c21f Mon Sep 17 00:00:00 2001 From: Thomas Lenzi Date: Tue, 3 Mar 2015 14:53:52 +0100 Subject: [PATCH 1/2] Integration of the new SiPhase2Clusterizer in CMSSW --- .../python/phase2TkCustomsBE5DPixel10Ddev.py | 50 +- SimTracker/SiPhase2Digitizer/BuildFile.xml | 2 +- .../interface/ClusterizerAlgorithm.h | 83 -- .../Phase2TrackerClusterizerAlgorithm.h | 34 + .../interface/Phase2TrackerClusterizerArray.h | 28 + .../interface/PixelClusterHitArray.h | 34 - .../interface/PixelClusterSimLink.h | 34 - .../SiPhase2Digitizer/plugins/BuildFile.xml | 4 +- .../plugins/Phase2TrackerClusterizer.cc | 98 ++ .../plugins/Phase2TrackerClusterizer.h | 38 + .../plugins/SiPhase2Clusterizer.cc | 121 --- .../plugins/SiPhase2Clusterizer.h | 46 - .../python/phase2TrackerClusterizer_cfi.py | 11 + .../python/phase2clusterizer_cfi.py | 12 - .../src/ClusterizerAlgorithm.cc | 188 ---- .../src/Phase2TrackerClusterizerAlgorithm.cc | 96 ++ .../src/Phase2TrackerClusterizerArray.cc | 80 ++ .../src/PixelClusterHitArray.cc | 46 - .../SiPhase2Digitizer/test/BuildFile.xml | 20 +- .../test/ClustersValidation.cc | 488 ++++++++++ ...ation.py => ClustersValidationTest_cfg.py} | 40 +- SimTracker/SiPhase2Digitizer/test/hits.cc | 116 --- SimTracker/SiPhase2Digitizer/test/hits.h | 38 - .../test/phase2clusters_validation.cc | 873 ------------------ 24 files changed, 926 insertions(+), 1654 deletions(-) delete mode 100644 SimTracker/SiPhase2Digitizer/interface/ClusterizerAlgorithm.h create mode 100644 SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerAlgorithm.h create mode 100644 SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerArray.h delete mode 100644 SimTracker/SiPhase2Digitizer/interface/PixelClusterHitArray.h delete mode 100644 SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h create mode 100644 SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc create mode 100644 SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.h delete mode 100644 SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.cc delete mode 100644 SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.h create mode 100644 SimTracker/SiPhase2Digitizer/python/phase2TrackerClusterizer_cfi.py delete mode 100644 SimTracker/SiPhase2Digitizer/python/phase2clusterizer_cfi.py delete mode 100644 SimTracker/SiPhase2Digitizer/src/ClusterizerAlgorithm.cc create mode 100644 SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerAlgorithm.cc create mode 100644 SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerArray.cc delete mode 100644 SimTracker/SiPhase2Digitizer/src/PixelClusterHitArray.cc create mode 100644 SimTracker/SiPhase2Digitizer/test/ClustersValidation.cc rename SimTracker/SiPhase2Digitizer/test/{run_cluster_validation.py => ClustersValidationTest_cfg.py} (52%) delete mode 100644 SimTracker/SiPhase2Digitizer/test/hits.cc delete mode 100644 SimTracker/SiPhase2Digitizer/test/hits.h delete mode 100644 SimTracker/SiPhase2Digitizer/test/phase2clusters_validation.cc diff --git a/SLHCUpgradeSimulations/Configuration/python/phase2TkCustomsBE5DPixel10Ddev.py b/SLHCUpgradeSimulations/Configuration/python/phase2TkCustomsBE5DPixel10Ddev.py index 482d44b09f28d..2f9ea501d28c4 100644 --- a/SLHCUpgradeSimulations/Configuration/python/phase2TkCustomsBE5DPixel10Ddev.py +++ b/SLHCUpgradeSimulations/Configuration/python/phase2TkCustomsBE5DPixel10Ddev.py @@ -27,18 +27,18 @@ def customise(process): if hasattr(process,'validation_step'): process=customise_Validation(process,float(n)) process=customise_condOverRides(process) - + return process def customise_Digi(process): process.digitisation_step.remove(process.mix.digitizers.pixel) - process.load('Geometry.TrackerGeometryBuilder.StackedTrackerGeometry_cfi') + process.load('Geometry.TrackerGeometryBuilder.StackedTrackerGeometry_cfi') process.load('SimTracker.SiPhase2Digitizer.phase2TrackerDigitizer_cfi') process.mix.digitizers.pixel=process.phase2TrackerDigitizer process.mix.digitizers.strip.ROUList = cms.vstring("g4SimHitsTrackerHitsPixelBarrelLowTof", 'g4SimHitsTrackerHitsPixelEndcapLowTof') # Check if mergedtruth is in the sequence first, could be taken out depending on cmsDriver options - if hasattr(process.mix.digitizers,"mergedtruth") : + if hasattr(process.mix.digitizers,"mergedtruth") : process.mix.digitizers.mergedtruth.simHitCollections.tracker.remove( cms.InputTag("g4SimHits","TrackerHitsTIBLowTof")) process.mix.digitizers.mergedtruth.simHitCollections.tracker.remove( cms.InputTag("g4SimHits","TrackerHitsTIBHighTof")) process.mix.digitizers.mergedtruth.simHitCollections.tracker.remove( cms.InputTag("g4SimHits","TrackerHitsTOBLowTof")) @@ -47,7 +47,7 @@ def customise_Digi(process): process.mix.digitizers.mergedtruth.simHitCollections.tracker.remove( cms.InputTag("g4SimHits","TrackerHitsTECHighTof")) process.mix.digitizers.mergedtruth.simHitCollections.tracker.remove( cms.InputTag("g4SimHits","TrackerHitsTIDLowTof")) process.mix.digitizers.mergedtruth.simHitCollections.tracker.remove( cms.InputTag("g4SimHits","TrackerHitsTIDHighTof")) - + return process @@ -62,10 +62,10 @@ def customise_RawToDigi(process): def customise_Reco(process,pileup): # insert the new clusterizer - process.load('SimTracker.SiPhase2Digitizer.phase2clusterizer_cfi') + process.load('SimTracker.SiPhase2Digitizer.phase2TrackerClusterizer_cfi') itIndex = process.pixeltrackerlocalreco.index(process.siPixelClusters) process.pixeltrackerlocalreco.insert(itIndex, process.siPhase2Clusters) - + # keep new clusters alist=['RAWSIM','FEVTDEBUG','FEVTDEBUGHLT','GENRAW','RAWSIMHLT','FEVT'] for a in alist: @@ -124,17 +124,17 @@ def customise_Reco(process,pileup): del process.ConvStep del process.earlyMuons del process.muonSeededStepCore - del process.muonSeededStepExtra + del process.muonSeededStepExtra del process.muonSeededStep del process.muonSeededStepDebug - + # add the correct tracking back in process.load("RecoTracker.Configuration.RecoTrackerPhase2BEPixel10D_cff") process.globalreco.insert(itIndex,process.trackingGlobalReco) process.reconstruction.insert(grIndex,process.globalreco) #Note process.reconstruction_fromRECO is broken - + # End of new tracking configuration which can be removed if new Reconstruction is used. @@ -143,12 +143,12 @@ def customise_Reco(process,pileup): process.reconstruction.remove(process.ak7BasicJets) process.reconstruction.remove(process.ak7CastorJetID) - #the quadruplet merger configuration + #the quadruplet merger configuration process.load("RecoPixelVertexing.PixelTriplets.quadrupletseedmerging_cff") process.pixelseedmergerlayers.BPix.TTRHBuilder = cms.string("PixelTTRHBuilderWithoutAngle" ) process.pixelseedmergerlayers.BPix.HitProducer = cms.string("siPixelRecHits" ) process.pixelseedmergerlayers.FPix.TTRHBuilder = cms.string("PixelTTRHBuilderWithoutAngle" ) - process.pixelseedmergerlayers.FPix.HitProducer = cms.string("siPixelRecHits" ) + process.pixelseedmergerlayers.FPix.HitProducer = cms.string("siPixelRecHits" ) process.pixelseedmergerlayers.layerList = cms.vstring('BPix1+BPix2+BPix3+BPix4', 'BPix1+BPix2+BPix3+FPix1_pos','BPix1+BPix2+BPix3+FPix1_neg', 'BPix1+BPix2+FPix1_pos+FPix2_pos', 'BPix1+BPix2+FPix1_neg+FPix2_neg', @@ -160,8 +160,8 @@ def customise_Reco(process,pileup): 'FPix5_pos+FPix6_pos+FPix7_pos+FPix8_pos', 'FPix5_neg+FPix6_neg+FPix7_neg+FPix8_neg', 'FPix5_pos+FPix6_pos+FPix7_pos+FPix9_pos', 'FPix5_neg+FPix6_neg+FPix7_neg+FPix9_neg', 'FPix6_pos+FPix7_pos+FPix8_pos+FPix9_pos', 'FPix6_neg+FPix7_neg+FPix8_neg+FPix9_neg') - - + + # Need these until pixel templates are used process.load("SLHCUpgradeSimulations.Geometry.recoFromSimDigis_cff") # PixelCPEGeneric # @@ -182,7 +182,7 @@ def customise_Reco(process,pileup): process.regionalCosmicTracks.TTRHBuilder=cms.string('WithTrackAngle') process.cosmicsVetoTracksRaw.TTRHBuilder=cms.string('WithTrackAngle') # End of pixel template needed section - + process.regionalCosmicTrackerSeeds.OrderedHitsFactoryPSet.LayerPSet.layerList = cms.vstring('BPix9+BPix8') # Optimize later process.regionalCosmicTrackerSeeds.OrderedHitsFactoryPSet.LayerPSet.BPix = cms.PSet( HitProducer = cms.string('siPixelRecHits'), @@ -276,16 +276,16 @@ def customise_DQM(process,pileup): process.SiPixelRecHitSource.isUpgrade = cms.untracked.bool(True) process.SiPixelTrackResidualSource.isUpgrade = cms.untracked.bool(True) process.SiPixelHitEfficiencySource.isUpgrade = cms.untracked.bool(True) - + from DQM.TrackingMonitor.customizeTrackingMonitorSeedNumber import customise_trackMon_IterativeTracking_PHASE1PU140 process=customise_trackMon_IterativeTracking_PHASE1PU140(process) process.dqmoffline_step.remove(process.Phase1Pu70TrackMonStep2) process.dqmoffline_step.remove(process.Phase1Pu70TrackMonStep4) if hasattr(process,"globalrechitsanalyze") : # Validation takes this out if pileup is more than 30 process.globalrechitsanalyze.ROUList = cms.vstring( - 'g4SimHitsTrackerHitsPixelBarrelLowTof', - 'g4SimHitsTrackerHitsPixelBarrelHighTof', - 'g4SimHitsTrackerHitsPixelEndcapLowTof', + 'g4SimHitsTrackerHitsPixelBarrelLowTof', + 'g4SimHitsTrackerHitsPixelBarrelHighTof', + 'g4SimHitsTrackerHitsPixelEndcapLowTof', 'g4SimHitsTrackerHitsPixelEndcapHighTof') return process @@ -294,12 +294,12 @@ def customise_Validation(process,pileup): process.validation_step.remove(process.stripRecHitsValid) process.validation_step.remove(process.trackerHitsValid) process.validation_step.remove(process.StripTrackingRecHitsValid) - + # Include Phase 2 Upgrade Outer Tracker stripVIndex=process.globalValidation.index(process.trackerDigisValidation) process.load("Validation.Phase2OuterTracker.OuterTrackerSourceConfig_cff") process.validation_step.insert(stripVIndex, process.OuterTrackerSource) - + # We don't run the HLT process.validation_step.remove(process.HLTSusyExoVal) process.validation_step.remove(process.hltHiggsValidator) @@ -324,7 +324,7 @@ def customise_Validation(process,pileup): process.mix.minBunch = cms.int32(0) process.mix.maxBunch = cms.int32(0) - if hasattr(process,'simHitTPAssocProducer'): + if hasattr(process,'simHitTPAssocProducer'): process.simHitTPAssocProducer.simHitSrc=cms.VInputTag(cms.InputTag("g4SimHits","TrackerHitsPixelBarrelLowTof"), cms.InputTag("g4SimHits","TrackerHitsPixelEndcapLowTof")) @@ -335,14 +335,14 @@ def customise_harvesting(process): process.dqmHarvesting.remove(process.dataCertificationJetMET) process.dqmHarvesting.remove(process.sipixelEDAClient) process.dqmHarvesting.remove(process.sipixelCertification) - + # Include Phase 2 Upgrade Outer Tracker strip2Index=process.DQMOffline_SecondStep_PreDPG.index(process.SiStripOfflineDQMClient) process.load("DQM.Phase2OuterTracker.OuterTrackerClientConfig_cff") - process.dqmHarvesting.insert(strip2Index, process.OuterTrackerClient) - + process.dqmHarvesting.insert(strip2Index, process.OuterTrackerClient) + strip2VIndex=process.postValidation.index(process.bTagCollectorSequenceMCbcl) process.load("Validation.Phase2OuterTracker.OuterTrackerClientConfig_cff") - process.validationHarvesting.insert(strip2VIndex, process.OuterTrackerClient) + process.validationHarvesting.insert(strip2VIndex, process.OuterTrackerClient) return (process) diff --git a/SimTracker/SiPhase2Digitizer/BuildFile.xml b/SimTracker/SiPhase2Digitizer/BuildFile.xml index d1ad9c084064b..54687195002dd 100644 --- a/SimTracker/SiPhase2Digitizer/BuildFile.xml +++ b/SimTracker/SiPhase2Digitizer/BuildFile.xml @@ -12,7 +12,7 @@ - + diff --git a/SimTracker/SiPhase2Digitizer/interface/ClusterizerAlgorithm.h b/SimTracker/SiPhase2Digitizer/interface/ClusterizerAlgorithm.h deleted file mode 100644 index 25d527ed0851d..0000000000000 --- a/SimTracker/SiPhase2Digitizer/interface/ClusterizerAlgorithm.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef SimTracker_SiPhase2Digitizer_ClusterizerAlgorithm_h -#define SimTracker_SiPhase2Digitizer_ClusterizerAlgorithm_h - -#include "DataFormats/Common/interface/DetSetVector.h" -#include "DataFormats/Common/interface/DetSetVectorNew.h" -#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" -#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" - -#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterHitArray.h" -//#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h" - -#include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationServiceBase.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include -#include - -class PixelGeomDetUnit; - -class PixelClusterSimLink; - -class ClusterizerAlgorithm { - -public: - typedef edm::DetSet::const_iterator DigiIterator; - - ClusterizerAlgorithm(edm::ParameterSet const& conf, int maxClusterSize, int maxNumberClusters); - void setup(const PixelGeomDetUnit* pixDet); - void clusterizeDetUnit(const edm::DetSet & pixelDigis, const edm::Handle< edm::DetSetVector< PixelDigiSimLink > > & pixelSimLinks, edmNew::DetSetVector::FastFiller & clusters) ; - // void makeLinks(edm::OrphanHandle< edmNew::DetSetVector > & clusters, std::vector > & linksByDet); - - unsigned int getSimTrackId(const edm::Handle< edm::DetSetVector< PixelDigiSimLink > > & pixelSimLinks, int channel); - -private: - void copy_to_buffer(DigiIterator begin, DigiIterator end); - void clear_buffer(DigiIterator begin, DigiIterator end); - -public: - edm::ParameterSet conf_; - PixelClusterHitArray hits; - int maxClusterSize_; - int maxNumberClusters_; - int nrows_; - int ncols_; - unsigned int rawDetId_; - - std::map< SiPixelCluster, std::vector< unsigned int > > tmpSimLinks; - - struct AccretionCluster { - static constexpr unsigned short MAXSIZE = 256; - unsigned short adc[256]; - unsigned short x[256]; - unsigned short y[256]; - unsigned short xmin = 16000; - unsigned short xmax = 0; - unsigned short ymin = 16000; - unsigned short ymax = 0; - unsigned int isize = 0; - unsigned int curr = 0; - unsigned short top() const { return curr; } - void pop() { ++curr; } - bool empty() { return curr == isize; } - bool add(SiPixelCluster::PixelPos const & p, unsigned short const iadc) { - if (isize == MAXSIZE) return false; - xmin = std::min(xmin, (unsigned short) p.row()); - xmax = std::max(xmax, (unsigned short) p.row()); - ymin = std::min(ymin, (unsigned short) p.col()); - ymax = std::max(ymax, (unsigned short) p.col()); - adc[isize] = iadc; - x[isize] = p.row(); - y[isize++] = p.col(); - return true; - } - unsigned short size() { return isize; } - unsigned short xsize() { return xmax - xmin + 1; } - unsigned short ysize() { return ymax - ymin + 1; } - }; - -}; - -#endif diff --git a/SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerAlgorithm.h b/SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerAlgorithm.h new file mode 100644 index 0000000000000..b1df5450a23f0 --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerAlgorithm.h @@ -0,0 +1,34 @@ +#ifndef SimTracker_SiPhase2Digitizer_Phase2TrackerClusterizerAlgorithm_h +#define SimTracker_SiPhase2Digitizer_Phase2TrackerClusterizerAlgorithm_h + +#include "DataFormats/Common/interface/DetSetVector.h" +#include "DataFormats/Common/interface/DetSetVectorNew.h" +#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" +#include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h" + +#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" + +#include "SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerArray.h" + +class Phase2TrackerClusterizerAlgorithm { + + public: + + Phase2TrackerClusterizerAlgorithm(unsigned int, unsigned int); + void setup(const PixelGeomDetUnit*); + void clusterizeDetUnit(const edm::DetSet< PixelDigi >&, edmNew::DetSetVector< Phase2TrackerCluster1D >::FastFiller&); + + private: + + void fillMatrix(edm::DetSet< PixelDigi >::const_iterator, edm::DetSet< PixelDigi >::const_iterator); + void clearMatrix(edm::DetSet< PixelDigi >::const_iterator, edm::DetSet< PixelDigi >::const_iterator); + + Phase2TrackerClusterizerArray matrix_; + unsigned int maxClusterSize_; + unsigned int maxNumberClusters_; + unsigned int nrows_; + unsigned int ncols_; + +}; + +#endif diff --git a/SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerArray.h b/SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerArray.h new file mode 100644 index 0000000000000..bfecfec877823 --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerArray.h @@ -0,0 +1,28 @@ +#ifndef SimTracker_SiPhase2Digitizer_Phase2TrackerClusterizerArray_h +#define SimTracker_SiPhase2Digitizer_Phase2TrackerClusterizerArray_h + +#include + +class Phase2TrackerClusterizerArray { + + public: + + Phase2TrackerClusterizerArray(); + Phase2TrackerClusterizerArray(unsigned int, unsigned int); + void setSize(unsigned int, unsigned int); + bool operator()(unsigned int, unsigned int) const; + unsigned int rows() const; + unsigned int columns() const; + bool inside(unsigned int, unsigned int) const; + void set(unsigned int, unsigned int, bool); + unsigned int size() const; + unsigned int index(unsigned int, unsigned int) const; + + private: + + unsigned int nrows_, ncols_; + std::vector< bool > matrix_; + +}; + +#endif diff --git a/SimTracker/SiPhase2Digitizer/interface/PixelClusterHitArray.h b/SimTracker/SiPhase2Digitizer/interface/PixelClusterHitArray.h deleted file mode 100644 index 44d614bd3d3d0..0000000000000 --- a/SimTracker/SiPhase2Digitizer/interface/PixelClusterHitArray.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef SimTracker_SiPhase2Digitizer_HitArray_h -#define SimTracker_SiPhase2Digitizer_HitArray_h - -#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" - -#include - -class PixelClusterHitArray { - -public: - PixelClusterHitArray(int rows, int cols); - PixelClusterHitArray() { } - - void setSize(int rows, int cols); - int operator()(int row, int col) const; - int operator()(const SiPixelCluster::PixelPos&) const; - int rows() const { return nrows; } - int columns() const { return ncols; } - - bool inside(int row, int col) const; - void set(int row, int col, int adc); - void set(const SiPixelCluster::PixelPos&, int adc); - int size() const { return pixel_vec.size(); } - - int index(int row, int col) const { return col * nrows + row; } - int index(const SiPixelCluster::PixelPos& pix) const { return index(pix.row(), pix.col()); } - -private: - int nrows; - int ncols; - std::vector pixel_vec; -}; - -#endif diff --git a/SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h b/SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h deleted file mode 100644 index 2dc9935ea102f..0000000000000 --- a/SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef SimTracker_SiPhase2Digitizer_PixelClusterSimLinks_h -#define SimTracker_SiPhase2Digitizer_PixelClusterSimLinks_h - -#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" -#include "DataFormats/Common/interface/DetSetVector.h" -#include "DataFormats/Common/interface/DetSetVectorNew.h" -#include "DataFormats/Common/interface/Ref.h" - -#include -#include - -class PixelClusterSimLink { - -public: - PixelClusterSimLink() { }; - void setSimTracks(std::vector< unsigned int > simTrack) { - simTracks_ = simTrack; - std::sort(simTracks_.begin(), simTracks_.end() ); - simTracks_.erase(std::unique(simTracks_.begin(), simTracks_.end()), simTracks_.end()); - }; - void setCluster(edm::Ref, SiPixelCluster> cluster) { cluster_ = cluster; }; - - std::vector< unsigned int > getSimTracks() { return simTracks_; }; - edm::Ref, SiPixelCluster> getCluster() { return cluster_; }; - - inline bool operator< ( const PixelClusterSimLink& other ) const { return true; } - -private: - edm::Ref, SiPixelCluster> cluster_; - std::vector< unsigned int > simTracks_; - -}; - -#endif diff --git a/SimTracker/SiPhase2Digitizer/plugins/BuildFile.xml b/SimTracker/SiPhase2Digitizer/plugins/BuildFile.xml index f817bd87ebb21..548290eeabd8d 100644 --- a/SimTracker/SiPhase2Digitizer/plugins/BuildFile.xml +++ b/SimTracker/SiPhase2Digitizer/plugins/BuildFile.xml @@ -1,9 +1,7 @@ - - - + diff --git a/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc b/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc new file mode 100644 index 0000000000000..60e52741715b2 --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc @@ -0,0 +1,98 @@ +#include "SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.h" + +#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" + +#include "DataFormats/Common/interface/DetSetVector.h" +#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" + +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Framework/interface/ESHandle.h" + +#include + +namespace cms { + + /* + * Initialise the producer + */ + + Phase2TrackerClusterizer::Phase2TrackerClusterizer(edm::ParameterSet const& conf) : + conf_(conf), + src_(conf.getParameter< edm::InputTag >("src")), + maxClusterSize_(conf.getParameter< unsigned int >("maxClusterSize")), + maxNumberClusters_(conf.getParameter< unsigned int >("maxNumberClusters")) { + // Objects that will be produced + produces< Phase2TrackerCluster1DCollectionNew >(); + // + clusterizer_ = new Phase2TrackerClusterizerAlgorithm(maxClusterSize_, maxNumberClusters_); + } + + Phase2TrackerClusterizer::~Phase2TrackerClusterizer() { } + + /* + * Clusterize the events + */ + + void Phase2TrackerClusterizer::produce(edm::Event& event, const edm::EventSetup& eventSetup) { + + // Get the Digis + edm::Handle< edm::DetSetVector< PixelDigi > > digis; + event.getByLabel(src_, digis); + + // Get the geometry + edm::ESHandle< TrackerGeometry > geomHandle; + eventSetup.get< TrackerDigiGeometryRecord >().get(geomHandle); + const TrackerGeometry* tkGeom(&(*geomHandle)); + + edm::ESHandle< TrackerTopology > tTopoHandle; + eventSetup.get< IdealGeometryRecord >().get(tTopoHandle); + const TrackerTopology* tTopo(tTopoHandle.product()); + + // Global container for the clusters of each modules + std::auto_ptr< Phase2TrackerCluster1DCollectionNew > outputClusters(new Phase2TrackerCluster1DCollectionNew()); + + // Go over all the modules + for (edm::DetSetVector< PixelDigi >::const_iterator DSViter = digis->begin(); DSViter != digis->end(); ++DSViter) { + + DetId detId(DSViter->detId()); + if (!isOuterTracker(detId, tTopo)) continue; + + // Geometry + const GeomDetUnit* geomDetUnit(tkGeom->idToDetUnit(detId)); + const PixelGeomDetUnit* pixDet = dynamic_cast< const PixelGeomDetUnit* >(geomDetUnit); + if (!pixDet) assert(0); + + // Container for the clusters that will be produced for this modules + edmNew::DetSetVector< Phase2TrackerCluster1D >::FastFiller clusters(*outputClusters, DSViter->detId()); + + // Setup the clusterizer algorithm for this detector (see ClusterizerAlgorithm for more details) + clusterizer_->setup(pixDet); + + // Pass the list of Digis to the main algorithm + // This function will store the clusters in the previously created container + clusterizer_->clusterizeDetUnit(*DSViter, clusters); + + if (clusters.empty()) clusters.abort(); + } + + // Add the data to the output + event.put(outputClusters); + } + + bool Phase2TrackerClusterizer::isOuterTracker(const DetId& detid, const TrackerTopology* topo) { + if (detid.det() == DetId::Tracker) { + if (detid.subdetId() == PixelSubdetector::PixelBarrel) return (topo->pxbLayer(detid) >= 5); + else if (detid.subdetId() == PixelSubdetector::PixelEndcap) return (topo->pxfDisk(detid) >= 11); + else return false; + } + return false; + } +} + +using cms::Phase2TrackerClusterizer; +DEFINE_FWK_MODULE(Phase2TrackerClusterizer); diff --git a/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.h b/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.h new file mode 100644 index 0000000000000..417d109f3ad20 --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.h @@ -0,0 +1,38 @@ +#ifndef SimTracker_SiPhase2Digitizer_Phase2TrackerClusterizer_h +#define SimTracker_SiPhase2Digitizer_Phase2TrackerClusterizer_h + +#include "SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerAlgorithm.h" + +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" +#include "DataFormats/DetId/interface/DetId.h" + +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" + +namespace cms { + + class Phase2TrackerClusterizer : public edm::EDProducer { + + public: + + explicit Phase2TrackerClusterizer(const edm::ParameterSet& conf); + virtual ~Phase2TrackerClusterizer(); + virtual void produce(edm::Event& event, const edm::EventSetup& eventSetup); + + private: + + bool isOuterTracker(const DetId& detid, const TrackerTopology* topo); + + edm::ParameterSet conf_; + Phase2TrackerClusterizerAlgorithm* clusterizer_; + edm::InputTag src_; + unsigned int maxClusterSize_; + unsigned int maxNumberClusters_; + + }; +} + +#endif diff --git a/SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.cc b/SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.cc deleted file mode 100644 index 06b37ad71d4b6..0000000000000 --- a/SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.cc +++ /dev/null @@ -1,121 +0,0 @@ -#include "SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.h" -#include "SimTracker/SiPhase2Digitizer/interface/ClusterizerAlgorithm.h" -//#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h" - -#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h" -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" -#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h" -#include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h" - -#include "DataFormats/Common/interface/DetSetVector.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" -#include "DataFormats/DetId/interface/DetId.h" -#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" -#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h" -#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" - -#include "FWCore/PluginManager/interface/ModuleDef.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include - -namespace cms { - - SimTrackerSiPhase2Clusterizer::SimTrackerSiPhase2Clusterizer(edm::ParameterSet const& conf) : - conf_(conf), - src_(conf.getParameter< edm::InputTag >("src")), - maxClusterSize_(conf.getParameter< int >("maxClusterSize")), - maxNumberClusters_(conf.getParameter< int >("maxNumberClusters")), - generateClusterSimLink_(conf.getParameter< bool >("clusterSimLink")) { - - // Objects that will be produced - produces< SiPixelClusterCollectionNew >(); - - // Optionally produce simlinks - //if (generateClusterSimLink_) produces< edm::DetSetVector >(); - - // Set the algorithm to use - clusterizer_ = new ClusterizerAlgorithm(conf, maxClusterSize_, maxNumberClusters_); - } - - SimTrackerSiPhase2Clusterizer::~SimTrackerSiPhase2Clusterizer() { } - - void SimTrackerSiPhase2Clusterizer::beginJob(edm::Run const& run, edm::EventSetup const& eventSetup) { - edm::LogInfo("SimTrackerSiPhase2Clusterizer") << "[SiPhase2Clusterizer::beginJob]"; - } - - void SimTrackerSiPhase2Clusterizer::produce(edm::Event & e, const edm::EventSetup & eventSetup) { - - // Get the Digis - edm::Handle< edm::DetSetVector< PixelDigi > > digis; - e.getByLabel(src_, digis); - - // Get the simlinks for the Digis - edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixelSimLinks; - e.getByLabel(src_, pixelSimLinks); - - // Get the geometry - edm::ESHandle< TrackerGeometry > geomHandle; - eventSetup.get< TrackerDigiGeometryRecord >().get(geomHandle); - const TrackerGeometry* tkGeom = &(*geomHandle); - - edm::ESHandle tTopoHandle; - eventSetup.get().get(tTopoHandle); - const TrackerTopology* tTopo = tTopoHandle.product(); - - // Global container for the clusters of each modules - std::auto_ptr< SiPixelClusterCollectionNew > outputClusters(new SiPixelClusterCollectionNew()); - - // Go over all the modules - for (edm::DetSetVector< PixelDigi >::const_iterator DSViter = digis->begin(); DSViter != digis->end(); ++DSViter) { - - if (!isOuterTracker(DSViter->detId(), tTopo)) continue; - - // Geometry & detID - DetId detId(DSViter->detId()); - const GeomDetUnit* geomDetUnit = tkGeom->idToDetUnit(detId); - const PixelGeomDetUnit* pixDet = dynamic_cast< const PixelGeomDetUnit* >(geomDetUnit); - if (!pixDet) assert(0); - - // Container for the clusters that will be produced for this modules - edmNew::DetSetVector::FastFiller clusters(*outputClusters, DSViter->detId()); - - // Setup the clusterizer algorithm for this detector (see ClusterizerAlgorithm for more details) - clusterizer_->setup(pixDet); - - // Pass the list of Digis to the main algorithm - // This function will store the clusters in the previously created container - clusterizer_->clusterizeDetUnit(*DSViter, pixelSimLinks, clusters); - - if (clusters.empty()) clusters.abort(); - } - - // Add the data to the output - edm::OrphanHandle< edmNew::DetSetVector > clusterCollection = e.put(outputClusters); - - // Do the same operations for the SimLinks if we have to generate them - /*if (generateClusterSimLink_) { - std::vector< edm::DetSet< PixelClusterSimLink > > linksByDet; - clusterizer_->makeLinks(clusterCollection, linksByDet); - std::auto_ptr< edm::DetSetVector< PixelClusterSimLink > > outputLinks(new edm::DetSetVector< PixelClusterSimLink >(linksByDet)); - e.put(outputLinks); - }*/ - } - - bool SimTrackerSiPhase2Clusterizer::isOuterTracker(unsigned int detid, const TrackerTopology* topo) { - DetId theDetId(detid); - if (theDetId.det() == DetId::Tracker) { - if (theDetId.subdetId() == PixelSubdetector::PixelBarrel) return (topo->pxbLayer(detid) >= 5); - else if (theDetId.subdetId() == PixelSubdetector::PixelEndcap) return (topo->pxfDisk(detid) >= 11); - else return false; - } - return false; - } -} - -using cms::SimTrackerSiPhase2Clusterizer; -DEFINE_FWK_MODULE(SimTrackerSiPhase2Clusterizer); - diff --git a/SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.h b/SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.h deleted file mode 100644 index e44e3f512c8c4..0000000000000 --- a/SimTracker/SiPhase2Digitizer/plugins/SiPhase2Clusterizer.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef SimTracker_SiPhase2Digitizer_SimTrackerSiPhase2Clusterizer_h -#define SimTracker_SiPhase2Digitizer_SimTrackerSiPhase2Clusterizer_h - -#include "SimTracker/SiPhase2Digitizer/interface/ClusterizerAlgorithm.h" - -#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/Records/interface/StackedTrackerGeometryRecord.h" - -#include "DataFormats/DetId/interface/DetId.h" -#include "DataFormats/Common/interface/DetSetVector.h" -#include "DataFormats/Common/interface/DetSetVectorNew.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" -#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" -#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" -#include "DataFormats/Common/interface/Handle.h" - -#include "FWCore/Framework/interface/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/InputTag.h" - -namespace cms { - - class SimTrackerSiPhase2Clusterizer : public edm::EDProducer { - - public: - explicit SimTrackerSiPhase2Clusterizer(const edm::ParameterSet & conf); - virtual ~SimTrackerSiPhase2Clusterizer(); - void setupClusterizer(); - void beginJob(edm::Run const& run, edm::EventSetup const& eventSetup); - virtual void produce(edm::Event & e, const edm::EventSetup & eventSetup); - bool isOuterTracker(unsigned int detid, const TrackerTopology* topo); - - private: - edm::ParameterSet conf_; - ClusterizerAlgorithm* clusterizer_; - edm::InputTag src_; - int maxClusterSize_; - int maxNumberClusters_; - bool generateClusterSimLink_; - }; -} - -#endif diff --git a/SimTracker/SiPhase2Digitizer/python/phase2TrackerClusterizer_cfi.py b/SimTracker/SiPhase2Digitizer/python/phase2TrackerClusterizer_cfi.py new file mode 100644 index 0000000000000..43e69bfef401b --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/python/phase2TrackerClusterizer_cfi.py @@ -0,0 +1,11 @@ +import FWCore.ParameterSet.Config as cms + +# Clusterizer options +siPhase2Clusters = cms.EDProducer('Phase2TrackerClusterizer', + src = cms.InputTag("simSiPixelDigis"), + maxClusterSize = cms.uint32(8), + maxNumberClusters = cms.uint32(0) +) + + + diff --git a/SimTracker/SiPhase2Digitizer/python/phase2clusterizer_cfi.py b/SimTracker/SiPhase2Digitizer/python/phase2clusterizer_cfi.py deleted file mode 100644 index 8134bf3cd3012..0000000000000 --- a/SimTracker/SiPhase2Digitizer/python/phase2clusterizer_cfi.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -# Clusterizer options -siPhase2Clusters = cms.EDProducer('SimTrackerSiPhase2Clusterizer', - src = cms.InputTag("simSiPixelDigis"), - maxClusterSize = cms.int32(8), - maxNumberClusters = cms.int32(-1), - clusterSimLink = cms.bool(True) -) - - - diff --git a/SimTracker/SiPhase2Digitizer/src/ClusterizerAlgorithm.cc b/SimTracker/SiPhase2Digitizer/src/ClusterizerAlgorithm.cc deleted file mode 100644 index e9d1345d75b38..0000000000000 --- a/SimTracker/SiPhase2Digitizer/src/ClusterizerAlgorithm.cc +++ /dev/null @@ -1,188 +0,0 @@ -#include "SimTracker/SiPhase2Digitizer/interface/ClusterizerAlgorithm.h" -#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterHitArray.h" -//#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h" - -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" -#include "Geometry/CommonTopologies/interface/PixelTopology.h" - -#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h" -#include "DataFormats/SiPixelDetId/interface/PXBDetId.h" -#include "DataFormats/SiPixelDetId/interface/PXFDetId.h" -#include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigiCollection.h" - -#include -#include -#include - -ClusterizerAlgorithm::ClusterizerAlgorithm(edm::ParameterSet const& conf, int maxClusterSize, int maxNumberClusters) : conf_(conf), maxClusterSize_(maxClusterSize), maxNumberClusters_(maxNumberClusters), nrows_(0), ncols_(0), rawDetId_(0) { - // Create a 2D matrix for this module that represents the hits - hits.setSize(nrows_, ncols_); -} - -// Change the size of the 2D matrix for this module (varies from pixel to strip modules) -void ClusterizerAlgorithm::setup(const PixelGeomDetUnit* pixDet) { - const PixelTopology & topol = pixDet->specificTopology(); - hits.setSize(topol.nrows(), topol.ncolumns()); - nrows_ = topol.nrows(); - ncols_ = topol.ncolumns(); -} - -// Go over the Digis and create clusters -void ClusterizerAlgorithm::clusterizeDetUnit(const edm::DetSet & pixelDigis, const edm::Handle< edm::DetSetVector< PixelDigiSimLink > > & pixelSimLinks, edmNew::DetSetVector::FastFiller & clusters) { - - // Get the det ID - rawDetId_ = pixelDigis.detId(); - - // Fill the 2D matrix with the ADC values - copy_to_buffer(pixelDigis.begin(), pixelDigis.end()); - - // Number of clusters - int numberOfClusters(0); - - // Loop over the Digis - for (unsigned int row = 0; row < (unsigned int) nrows_; ++row) { - for (unsigned int col = 0; col < (unsigned int) ncols_; ++col) { - - // If the Digi is active - if (hits(row, col)) { - - // Try to form a cluster - - // Create an entry for the pixelClusterLink - std::vector< unsigned int > simTracks; - - // Add the simtrack of the Digi to the link - unsigned int simTrackId = getSimTrackId(pixelSimLinks, PixelDigi::pixelToChannel(row, col)); - if (simTrackId) simTracks.push_back(simTrackId); - - // Set the value of this pixel to 0 as it is used to form a Digi - hits.set(row, col, 0); - - // Create a temporary cluster (this allows to them easily form a "real" cluster with CMSSW data format) - AccretionCluster acluster; - - // Create a pixel entry for the cluster - SiPixelCluster::PixelPos firstpix(row, col); - - // Add the first pixel to the cluster - acluster.add(firstpix, 255); - - // Go over all the pixels in the cluster - while (!acluster.empty()) { - - // Get the current pixel we are looking at - unsigned int curInd = acluster.top(); - acluster.pop(); - - unsigned int from_r = acluster.x[curInd] - 1; - unsigned int to_r = acluster.x[curInd] + 1; - - // Look left and right - for (unsigned int r = from_r; r <= to_r; ++r) { - - // Look bottom and top - if (hits(r, col)) { - - // Add it to the cluster - SiPixelCluster::PixelPos newpix(r, col); - if (!acluster.add(newpix, 255)) break; - - // And change its value - hits.set(newpix, 0); - - // Add the simtrack of the Digi to the link - unsigned int simTrackId2 = getSimTrackId(pixelSimLinks, PixelDigi::pixelToChannel(r, col)); - if (simTrackId2) simTracks.push_back(simTrackId2); - - if (acluster.isize == (unsigned int) maxClusterSize_) goto form_cluster; - } - } - } - - form_cluster: - - numberOfClusters++; - - // Check if we hit the maximym number of clusters per module - if (maxNumberClusters_ != -1 and numberOfClusters > maxNumberClusters_) return; - - // Form a "real" CMSSW cluster - SiPixelCluster cluster(acluster.isize, acluster.adc, acluster.x, acluster.y, acluster.xmin, acluster.ymin); - - // Add link - tmpSimLinks.insert(std::pair< SiPixelCluster, std::vector< unsigned int > >(cluster, simTracks)); - - // Add the cluster and the link to the list - clusters.push_back(cluster); - } - } - } - - // Reset the matrix - clear_buffer(pixelDigis.begin(), pixelDigis.end()); -} - -void ClusterizerAlgorithm::copy_to_buffer(DigiIterator begin, DigiIterator end) { - // Copy the value of the Digis' ADC to the 2D matrix. An ADC of 255 means the cell is hit (binary read-out) - for (DigiIterator di = begin; di != end; ++di) hits.set(di->row(), di->column(), di->adc()); -} - -void ClusterizerAlgorithm::clear_buffer(DigiIterator begin, DigiIterator end) { - // Resets the matrix - for (DigiIterator di = begin; di != end; ++di) hits.set(di->row(), di->column(), 0); -} - -// Returns the simtrack id of a digi -unsigned int ClusterizerAlgorithm::getSimTrackId(const edm::Handle< edm::DetSetVector< PixelDigiSimLink > > & pixelSimLinks, int channel) { - edm::DetSetVector::const_iterator isearch = pixelSimLinks->find(rawDetId_); - - unsigned int simTrkId(0); - if (isearch == pixelSimLinks->end()) return simTrkId; - - edm::DetSet link_detset = (*pixelSimLinks)[rawDetId_]; - int iSimLink = 0; - for (edm::DetSet::const_iterator it = link_detset.data.begin(); it != link_detset.data.end(); it++,iSimLink++) { - if (channel == (int) it->channel()) { - simTrkId = it->SimTrackId(); - break; - } - } - return simTrkId; -} - -// Create the links between the clusters and the simTracks -/*void ClusterizerAlgorithm::makeLinks(edm::OrphanHandle< edmNew::DetSetVector > & clusters, std::vector > & linksByDet) { - - // Go over all the clusters - for (edmNew::DetSetVector< SiPixelCluster >::const_iterator DSViter = clusters->begin(); DSViter != clusters->end(); ++DSViter) { - - unsigned int nclu = 0; - - edm::DetSet< PixelClusterSimLink > links(DSViter->id()); - - for (edmNew::DetSet< SiPixelCluster >::const_iterator clustIt = DSViter->begin(); clustIt != DSViter->end(); ++clustIt) { - - // Add a cut of 10 links per module - if (nclu++ > 10) continue; - - // Look for the cluster in the existing links - std::map< SiPixelCluster, std::vector< unsigned int > >::iterator it = tmpSimLinks.find(*clustIt); - - if (it != tmpSimLinks.end()) { - // Match the cluster with the simtrack - std::vector< unsigned int > simTracks = it->second; - - PixelClusterSimLink simLink; - - simLink.setCluster(edmNew::makeRefTo(clusters, clustIt)); - simLink.setSimTracks(simTracks); - links.data.push_back(simLink); - } - } - - linksByDet.push_back(links); - } -} -*/ diff --git a/SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerAlgorithm.cc b/SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerAlgorithm.cc new file mode 100644 index 0000000000000..ae5ddc0fbc8d5 --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerAlgorithm.cc @@ -0,0 +1,96 @@ +#include "SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerAlgorithm.h" + +#include "Geometry/CommonTopologies/interface/PixelTopology.h" + +/* + * Initialise the clusterizer algorithm + */ + +Phase2TrackerClusterizerAlgorithm::Phase2TrackerClusterizerAlgorithm(unsigned int maxClusterSize, unsigned int maxNumberClusters) : maxClusterSize_(maxClusterSize), maxNumberClusters_(maxNumberClusters), nrows_(0), ncols_(0) { } + +/* + * Change the size of the 2D matrix for this module (varies from pixel to strip modules) + */ + +void Phase2TrackerClusterizerAlgorithm::setup(const PixelGeomDetUnit* pixDet) { + const PixelTopology& topol(pixDet->specificTopology()); + nrows_ = topol.nrows(); + ncols_ = topol.ncolumns(); + matrix_.setSize(nrows_, ncols_); +} + +/* + * Go over the Digis and create clusters + */ + +void Phase2TrackerClusterizerAlgorithm::clusterizeDetUnit(const edm::DetSet< PixelDigi >& digis, edmNew::DetSetVector< Phase2TrackerCluster1D >::FastFiller& clusters) { + + // Fill the 2D matrix with the ADC values + fillMatrix(digis.begin(), digis.end()); + + // Number of clusters + unsigned int numberClusters(0); + Phase2TrackerDigi firstDigi; + unsigned int sizeCluster(0); + bool closeCluster(false); + + // Loop over the Digis + // for the S modules, 1 column = 1 strip, so adjacent digis are along the rows + // same for P modules + for (unsigned int col(0); col < ncols_; ++col) { + for (unsigned int row(0); row < nrows_; ++row) { + + // If the Digi is hit + if (matrix_(row, col)) { + // No cluster is open, create a new one + if (sizeCluster == 0) { + // Define first digi + firstDigi = Phase2TrackerDigi(row, col); + sizeCluster = 1; + } + // A cluster is open, increase its size + else ++sizeCluster; + // Check if we reached the maximum size of the cluster and need to close it + closeCluster = ((maxClusterSize_ != 0 and sizeCluster >= maxClusterSize_) ? true : false); + } + // Otherwise check if we need to close a cluster (end of cluster) + else closeCluster = ((sizeCluster != 0) ? true : false); + + // Always close a cluster if we reach the end of the loop + if (sizeCluster != 0 and row == (nrows_ - 1)) closeCluster = true; + + // If we have to close a cluster, do it + if (closeCluster) { + // Add the cluster to the list + clusters.push_back(Phase2TrackerCluster1D(firstDigi, sizeCluster)); + // Reset the variables + sizeCluster = 0; + // Increase the number of clusters + ++numberClusters; + } + + // Check if we hit the maximum number of clusters per module + if (maxNumberClusters_ != 0 and numberClusters > maxNumberClusters_) return; + } + } + + // Reset the matrix + clearMatrix(digis.begin(), digis.end()); +} + +/* + * Copy the value of the Digis' ADC to the 2D matrix. An ADC of 255 means the cell is hit (binary read-out) + */ + +void Phase2TrackerClusterizerAlgorithm::fillMatrix(edm::DetSet< PixelDigi >::const_iterator begin, edm::DetSet< PixelDigi >::const_iterator end) { + for (edm::DetSet< PixelDigi >::const_iterator di(begin); di != end; ++di) matrix_.set(di->row(), di->column(), (di->adc() != 0)); +} + +/* + * Clear the array of hits + */ + +void Phase2TrackerClusterizerAlgorithm::clearMatrix(edm::DetSet< PixelDigi >::const_iterator begin, edm::DetSet< PixelDigi >::const_iterator end) { + for (edm::DetSet< PixelDigi >::const_iterator di(begin); di != end; ++di) matrix_.set(di->row(), di->column(), false); +} + diff --git a/SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerArray.cc b/SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerArray.cc new file mode 100644 index 0000000000000..40c5b97d4dfef --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/src/Phase2TrackerClusterizerArray.cc @@ -0,0 +1,80 @@ +#include "SimTracker/SiPhase2Digitizer/interface/Phase2TrackerClusterizerArray.h" + +/* + * Create a new Array of hits + */ + +Phase2TrackerClusterizerArray::Phase2TrackerClusterizerArray() : nrows_(0), ncols_(0) { } + +Phase2TrackerClusterizerArray::Phase2TrackerClusterizerArray(unsigned int nrows, unsigned int ncols) { + setSize(nrows, ncols); +} + +/* + * Resize the Array and clear the values + */ + +void Phase2TrackerClusterizerArray::setSize(unsigned int nrows, unsigned int ncols) { + nrows_ = nrows; + ncols_ = ncols; + matrix_.resize(nrows * ncols); + for (std::vector< bool >::iterator it(matrix_.begin()); it != matrix_.end(); ++it) *it = false; +} + +/* + * Return the value of an element in the Array + */ + +bool Phase2TrackerClusterizerArray::operator()(unsigned int row, unsigned int col) const { + if (inside(row, col)) return matrix_[index(row, col)]; + else return false; +} + +/* + * Return the number of rows + */ + +unsigned int Phase2TrackerClusterizerArray::rows() const { + return nrows_; +} + +/* + * Return the number of columns + */ + +unsigned int Phase2TrackerClusterizerArray::columns() const { + return ncols_; +} + +/* + * Tell if an element is inside the array or not + */ + +bool Phase2TrackerClusterizerArray::inside(unsigned int row, unsigned int col) const { + return (row < nrows_ && col < ncols_); +} + +/* + * Change the value of an element of the Array + */ + +void Phase2TrackerClusterizerArray::set(unsigned int row, unsigned int col, bool state) { + matrix_[index(row, col)] = state; +} + +/* + * Return the size of the array + */ + +unsigned int Phase2TrackerClusterizerArray::size() const { + return matrix_.size(); +} + +/* + * Get the poisiton of an element of the Array in the vector that holds the data + */ + +unsigned int Phase2TrackerClusterizerArray::index(unsigned int row, unsigned int col) const { + return col * nrows_ + row; +} + diff --git a/SimTracker/SiPhase2Digitizer/src/PixelClusterHitArray.cc b/SimTracker/SiPhase2Digitizer/src/PixelClusterHitArray.cc deleted file mode 100644 index 2d94fa95a7766..0000000000000 --- a/SimTracker/SiPhase2Digitizer/src/PixelClusterHitArray.cc +++ /dev/null @@ -1,46 +0,0 @@ -#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterHitArray.h" - -#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" - -// Create a 2D matrix of zeros of size rows x cols -PixelClusterHitArray::PixelClusterHitArray(int rows, int cols) : - nrows(rows), - ncols(cols) { - pixel_vec.resize(rows * cols); - for (std::vector::iterator it = pixel_vec.begin(); it != pixel_vec.end(); ++it) *it = 0; -} - -// Change the size of the matrix and reset it -void PixelClusterHitArray::setSize(int rows, int cols) { - nrows = rows; - ncols = cols; - pixel_vec.resize(rows * cols); - for (std::vector::iterator it = pixel_vec.begin(); it != pixel_vec.end(); ++it) *it = 0; -} - -// Check if an element is inside the matrix (no overflow) -bool PixelClusterHitArray::inside(int row, int col) const { - return (row >= 0 && row < nrows && col >= 0 && col < ncols); -} - -// Return an element of the matrix -int PixelClusterHitArray::operator()(int row, int col) const { - if (inside(row,col)) return pixel_vec[index(row,col)]; - else return 0; -} - -// Return an element of the matrix (get the row and column from the pixel data) -int PixelClusterHitArray::operator()(const SiPixelCluster::PixelPos& pix) const { - if (inside(pix.row(), pix.col())) return pixel_vec[index(pix)]; - else return 0; -} - -// Set an element of the matrix -void PixelClusterHitArray::set(int row, int col, int adc) { - pixel_vec[index(row,col)] = adc; -} - -// Set an element of the matrix (get the row and column from the pixel data) -void PixelClusterHitArray::set(const SiPixelCluster::PixelPos& pix, int adc) { - pixel_vec[index(pix)] = adc; -} diff --git a/SimTracker/SiPhase2Digitizer/test/BuildFile.xml b/SimTracker/SiPhase2Digitizer/test/BuildFile.xml index d0a9bfa641723..04c9bd69c61ad 100644 --- a/SimTracker/SiPhase2Digitizer/test/BuildFile.xml +++ b/SimTracker/SiPhase2Digitizer/test/BuildFile.xml @@ -1,5 +1,7 @@ + + @@ -13,20 +15,18 @@ - - - - - - - - - + + + + + + + - + diff --git a/SimTracker/SiPhase2Digitizer/test/ClustersValidation.cc b/SimTracker/SiPhase2Digitizer/test/ClustersValidation.cc new file mode 100644 index 0000000000000..8879d71bbfeb9 --- /dev/null +++ b/SimTracker/SiPhase2Digitizer/test/ClustersValidation.cc @@ -0,0 +1,488 @@ +#include +#include +#include + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h" +#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" + +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" +#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h" +#include "DataFormats/Common/interface/DetSetVectorNew.h" +#include "DataFormats/Common/interface/DetSetVector.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h" +#include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h" +#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" + +#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" +#include "SimDataFormats/Track/interface/SimTrackContainer.h" +#include "SimDataFormats/Vertex/interface/SimVertexContainer.h" +#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" + +#include "CommonTools/UtilAlgos/interface/TFileService.h" +#include "CommonTools/Utils/interface/TFileDirectory.h" + +#include +#include +#include + + +struct ClusterHistos { + THStack* numberClustersMixed; + TH1F* numberClusterPixel; + TH1F* numberClusterStrip; + + THStack* clustersSizeMixed; + TH1F* clusterSizePixel; + TH1F* clusterSizeStrip; + + TH2F* globalPosXY[3]; + TH2F* localPosXY[3]; + + TH1F* deltaXClusterSimHits[3]; + TH1F* deltaYClusterSimHits[3]; + + TH1F* deltaXClusterSimHits_P[3]; + TH1F* deltaYClusterSimHits_P[3]; + + TH1F* digiEfficiency[3]; + + TH1F* primarySimHits; + TH1F* otherSimHits; +}; + +class Phase2TrackerClusterizerValidation : public edm::EDAnalyzer { + + public: + + typedef std::map< unsigned int, std::vector< PSimHit > > SimHitsMap; + typedef std::map< unsigned int, SimTrack > SimTracksMap; + + explicit Phase2TrackerClusterizerValidation(const edm::ParameterSet&); + ~Phase2TrackerClusterizerValidation(); + void beginJob(); + void endJob(); + void analyze(const edm::Event&, const edm::EventSetup&); + + private: + + std::map< unsigned int, ClusterHistos >::iterator createLayerHistograms(unsigned int); + unsigned int getLayerNumber(const DetId&, const TrackerTopology*); + unsigned int getSimTrackId(const edm::Handle< edm::DetSetVector< PixelDigiSimLink > >&, const DetId&, unsigned int); + + edm::InputTag src_; + edm::InputTag links_; + TH2F* trackerLayout_; + TH2F* trackerLayoutXY_; + TH2F* trackerLayoutXYBar_; + TH2F* trackerLayoutXYEC_; + + std::map< unsigned int, ClusterHistos > histograms_; + +}; + +Phase2TrackerClusterizerValidation::Phase2TrackerClusterizerValidation(const edm::ParameterSet& conf) : + src_(conf.getParameter< edm::InputTag >("src")), + links_(conf.getParameter< edm::InputTag >("links")) { } + + Phase2TrackerClusterizerValidation::~Phase2TrackerClusterizerValidation() { } + + void Phase2TrackerClusterizerValidation::beginJob() { + edm::Service fs; + fs->file().cd("/"); + TFileDirectory td = fs->mkdir("Common"); + // Create common histograms + trackerLayout_ = td.make< TH2F >("RVsZ", "R vs. z position", 6000, -300.0, 300.0, 1200, 0.0, 120.0); + trackerLayoutXY_ = td.make< TH2F >("XVsY", "x vs. y position", 2400, -120.0, 120.0, 2400, -120.0, 120.0); + trackerLayoutXYBar_ = td.make< TH2F >("XVsYBar", "x vs. y position", 2400, -120.0, 120.0, 2400, -120.0, 120.0); + trackerLayoutXYEC_ = td.make< TH2F >("XVsYEC", "x vs. y position", 2400, -120.0, 120.0, 2400, -120.0, 120.0); + } + +void Phase2TrackerClusterizerValidation::endJob() { } + +void Phase2TrackerClusterizerValidation::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) { + + /* + * Get the needed objects + */ + + // Get the clusters + edm::Handle< Phase2TrackerCluster1DCollectionNew > clusters; + event.getByLabel(src_, clusters); + + // Get the PixelDigiSimLinks + edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixelSimLinks; + event.getByLabel(links_, pixelSimLinks); + + // Get the SimHits + edm::Handle< edm::PSimHitContainer > simHitsRaw; + event.getByLabel("g4SimHits", "TrackerHitsPixelBarrelLowTof", simHitsRaw); + + // Get the SimTracks + edm::Handle< edm::SimTrackContainer > simTracksRaw; + event.getByLabel("g4SimHits", simTracksRaw); + + // Get the SimVertex + edm::Handle< edm::SimVertexContainer > simVertices; + event.getByLabel("g4SimHits", simVertices); + + // Get the geometry + edm::ESHandle< TrackerGeometry > geomHandle; + eventSetup.get< TrackerDigiGeometryRecord >().get(geomHandle); + const TrackerGeometry* tkGeom = &(*geomHandle); + + edm::ESHandle< TrackerTopology > tTopoHandle; + eventSetup.get< IdealGeometryRecord >().get(tTopoHandle); + const TrackerTopology* tTopo = tTopoHandle.product(); + + /* + * Rearrange the simTracks + */ + + // Rearrange the simTracks for ease of use + SimTracksMap simTracks; + for (edm::SimTrackContainer::const_iterator simTrackIt(simTracksRaw->begin()); simTrackIt != simTracksRaw->end(); ++simTrackIt) simTracks.insert(std::pair< unsigned int, SimTrack >(simTrackIt->trackId(), *simTrackIt)); + + /* + * Rearrange the simHits by detUnit + */ + + // Rearrange the simHits for ease of use + SimHitsMap simHitsDetUnit; + SimHitsMap simHitsTrackId; + for (edm::PSimHitContainer::const_iterator simHitIt(simHitsRaw->begin()); simHitIt != simHitsRaw->end(); ++simHitIt) { + SimHitsMap::iterator simHitsDetUnitIt(simHitsDetUnit.find(simHitIt->detUnitId())); + if (simHitsDetUnitIt == simHitsDetUnit.end()) { + std::pair< SimHitsMap::iterator, bool > newIt(simHitsDetUnit.insert(std::pair< unsigned int, std::vector< PSimHit > >(simHitIt->detUnitId(), std::vector< PSimHit >()))); + simHitsDetUnitIt = newIt.first; + } + simHitsDetUnitIt->second.push_back(*simHitIt); + + SimHitsMap::iterator simHitsTrackIdIt(simHitsTrackId.find(simHitIt->trackId())); + if (simHitsTrackIdIt == simHitsTrackId.end()) { + std::pair< SimHitsMap::iterator, bool > newIt(simHitsTrackId.insert(std::pair< unsigned int, std::vector< PSimHit > >(simHitIt->trackId(), std::vector< PSimHit >()))); + simHitsTrackIdIt = newIt.first; + } + simHitsTrackIdIt->second.push_back(*simHitIt); + } + + /* + * Validation + */ + + // Loop over modules + for (Phase2TrackerCluster1DCollectionNew::const_iterator DSViter = clusters->begin(); DSViter != clusters->end(); ++DSViter) { + + // Get the detector unit's id + unsigned int rawid(DSViter->detId()); + DetId detId(rawid); + unsigned int layer(getLayerNumber(detId, tTopo)); + + // Get the geometry of the tracker + const GeomDetUnit* geomDetUnit(tkGeom->idToDetUnit(detId)); + const PixelGeomDetUnit* theGeomDet = dynamic_cast< const PixelGeomDetUnit* >(geomDetUnit); + const PixelTopology& topol = theGeomDet->specificTopology(); + + if (!geomDetUnit) break; + + // Create histograms for the layer if they do not yet exist + std::map< unsigned int, ClusterHistos >::iterator histogramLayer(histograms_.find(layer)); + if (histogramLayer == histograms_.end()) histogramLayer = createLayerHistograms(layer); + + // Number of clusters + unsigned int nClustersPixel(0), nClustersStrip(0); + + // Loop over the clusters in the detector unit + for (edmNew::DetSet< Phase2TrackerCluster1D >::const_iterator clustIt = DSViter->begin(); clustIt != DSViter->end(); ++clustIt) { + + /* + * Cluster related variables + */ + + MeasurementPoint mpClu(clustIt->center(), clustIt->column() + 0.5); + Local3DPoint localPosClu = geomDetUnit->topology().localPosition(mpClu); + Global3DPoint globalPosClu = geomDetUnit->surface().toGlobal(localPosClu); + + // Fill the position histograms + trackerLayout_->Fill(globalPosClu.z(), globalPosClu.perp()); + trackerLayoutXY_->Fill(globalPosClu.x(), globalPosClu.y()); + if (layer < 100) trackerLayoutXYBar_->Fill(globalPosClu.x(), globalPosClu.y()); + else trackerLayoutXYEC_->Fill(globalPosClu.x(), globalPosClu.y()); + + histogramLayer->second.localPosXY[0]->Fill(localPosClu.x(), localPosClu.y()); + histogramLayer->second.globalPosXY[0]->Fill(globalPosClu.x(), globalPosClu.y()); + + // Pixel module + if (topol.ncolumns() == 32) { + histogramLayer->second.localPosXY[1]->Fill(localPosClu.x(), localPosClu.y()); + histogramLayer->second.globalPosXY[1]->Fill(globalPosClu.x(), globalPosClu.y()); + histogramLayer->second.clusterSizePixel->Fill(clustIt->size()); + ++nClustersPixel; + } + // Strip module + else if (topol.ncolumns() == 2) { + histogramLayer->second.localPosXY[2]->Fill(localPosClu.x(), localPosClu.y()); + histogramLayer->second.globalPosXY[2]->Fill(globalPosClu.x(), globalPosClu.y()); + histogramLayer->second.clusterSizeStrip->Fill(clustIt->size()); + ++nClustersStrip; + } + + /* + * Digis related variables + */ + + std::vector< unsigned int > clusterSimTrackIds; + + // Get all the simTracks that form the cluster + for (unsigned int i(0); i < clustIt->size(); ++i) { + unsigned int channel(PixelDigi::pixelToChannel(clustIt->firstRow() + i, clustIt->column())); // Here we have to use the old pixelToChannel function (not Phase2TrackerDigi but PixelDigi), change this when using new Digis + unsigned int simTrackId(getSimTrackId(pixelSimLinks, detId, channel)); + clusterSimTrackIds.push_back(simTrackId); + } + + /* + * SimHits related variables + */ + + + unsigned int primarySimHits(0); + unsigned int otherSimHits(0); + + for (edm::PSimHitContainer::const_iterator hitIt(simHitsRaw->begin()); hitIt != simHitsRaw->end(); ++hitIt) { + if (rawid == hitIt->detUnitId() and std::find(clusterSimTrackIds.begin(), clusterSimTrackIds.end(), hitIt->trackId()) != clusterSimTrackIds.end()) { + Local3DPoint localPosHit(hitIt->localPosition()); + + histogramLayer->second.deltaXClusterSimHits[0]->Fill(localPosClu.x() - localPosHit.x()); + histogramLayer->second.deltaYClusterSimHits[0]->Fill(localPosClu.y() - localPosHit.y()); + + // Pixel module + if (topol.ncolumns() == 32) { + histogramLayer->second.deltaXClusterSimHits[1]->Fill(localPosClu.x() - localPosHit.x()); + histogramLayer->second.deltaYClusterSimHits[1]->Fill(localPosClu.y() - localPosHit.y()); + } + // Strip module + else if (topol.ncolumns() == 2) { + histogramLayer->second.deltaXClusterSimHits[2]->Fill(localPosClu.x() - localPosHit.x()); + histogramLayer->second.deltaYClusterSimHits[2]->Fill(localPosClu.y() - localPosHit.y()); + } + + ++otherSimHits; + + std::map< unsigned int, SimTrack >::const_iterator simTrackIt(simTracks.find(hitIt->trackId())); + if (simTrackIt == simTracks.end()) continue; + + // Primary particles only + unsigned int processType(hitIt->processType()); + if (simTrackIt->second.vertIndex() == 0 and (processType == 2 || processType == 7 || processType == 9 || processType == 11 || processType == 13 || processType == 15)) { + histogramLayer->second.deltaXClusterSimHits_P[0]->Fill(localPosClu.x() - localPosHit.x()); + histogramLayer->second.deltaYClusterSimHits_P[0]->Fill(localPosClu.y() - localPosHit.y()); + + // Pixel module + if (topol.ncolumns() == 32) { + histogramLayer->second.deltaXClusterSimHits_P[1]->Fill(localPosClu.x() - localPosHit.x()); + histogramLayer->second.deltaYClusterSimHits_P[1]->Fill(localPosClu.y() - localPosHit.y()); + } + // Strip module + else if (topol.ncolumns() == 2) { + histogramLayer->second.deltaXClusterSimHits_P[2]->Fill(localPosClu.x() - localPosHit.x()); + histogramLayer->second.deltaYClusterSimHits_P[2]->Fill(localPosClu.y() - localPosHit.y()); + } + + ++primarySimHits; + } + } + } + + otherSimHits -= primarySimHits; + + histogramLayer->second.primarySimHits->Fill(primarySimHits); + histogramLayer->second.otherSimHits->Fill(otherSimHits); + } + + if (nClustersPixel) histogramLayer->second.numberClusterPixel->Fill(nClustersPixel); + if (nClustersStrip) histogramLayer->second.numberClusterStrip->Fill(nClustersStrip); + } +} + +// Create the histograms +std::map< unsigned int, ClusterHistos >::iterator Phase2TrackerClusterizerValidation::createLayerHistograms(unsigned int ival) { + std::ostringstream fname1, fname2; + + edm::Service fs; + fs->file().cd("/"); + + std::string tag; + unsigned int id; + if (ival < 100) { + id = ival; + fname1 << "Barrel"; + fname2 << "Layer_" << id; + tag = "_layer_"; + } + else { + int side = ival / 100; + id = ival - side * 100; + fname1 << "EndCap_Side_" << side; + fname2 << "Disc_" << id; + tag = "_disc_"; + } + + TFileDirectory td1 = fs->mkdir(fname1.str().c_str()); + TFileDirectory td = td1.mkdir(fname2.str().c_str()); + + ClusterHistos local_histos; + + std::ostringstream histoName; + + /* + * Number of clusters + */ + + histoName.str(""); histoName << "Number_Clusters_Pixel" << tag.c_str() << id; + local_histos.numberClusterPixel = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 20, 0., 20.); + local_histos.numberClusterPixel->SetFillColor(kAzure + 7); + + histoName.str(""); histoName << "Number_Clusters_Strip" << tag.c_str() << id; + local_histos.numberClusterStrip = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 20, 0., 20.); + local_histos.numberClusterStrip->SetFillColor(kOrange - 3); + + histoName.str(""); histoName << "Number_Clusters_Mixed" << tag.c_str() << id; + local_histos.numberClustersMixed = td.make< THStack >(histoName.str().c_str(), histoName.str().c_str()); + local_histos.numberClustersMixed->Add(local_histos.numberClusterPixel); + local_histos.numberClustersMixed->Add(local_histos.numberClusterStrip); + + /* + * Cluster size + */ + + histoName.str(""); histoName << "Cluster_Size_Pixel" << tag.c_str() << id; + local_histos.clusterSizePixel = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 10, 0., 10.); + local_histos.clusterSizePixel->SetFillColor(kAzure + 7); + + histoName.str(""); histoName << "Cluster_Size_Strip" << tag.c_str() << id; + local_histos.clusterSizeStrip = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 10, 0., 10.); + local_histos.clusterSizeStrip->SetFillColor(kOrange - 3); + + histoName.str(""); histoName << "Cluster_Size_Mixed" << tag.c_str() << id; + local_histos.clustersSizeMixed = td.make< THStack >(histoName.str().c_str(), histoName.str().c_str()); + local_histos.clustersSizeMixed->Add(local_histos.clusterSizePixel); + local_histos.clustersSizeMixed->Add(local_histos.clusterSizeStrip); + + /* + * Local and Global positions + */ + + histoName.str(""); histoName << "Local_Position_XY_Mixed" << tag.c_str() << id; + local_histos.localPosXY[0] = td.make< TH2F >(histoName.str().c_str(), histoName.str().c_str(), 2000, 0., 0., 2000, 0., 0.); + + histoName.str(""); histoName << "Local_Position_XY_Pixel" << tag.c_str() << id; + local_histos.localPosXY[1] = td.make< TH2F >(histoName.str().c_str(), histoName.str().c_str(), 2000, 0., 0., 2000, 0., 0.); + + histoName.str(""); histoName << "Local_Position_XY_Strip" << tag.c_str() << id; + local_histos.localPosXY[2] = td.make< TH2F >(histoName.str().c_str(), histoName.str().c_str(), 2000, 0., 0., 2000, 0., 0.); + + histoName.str(""); histoName << "Global_Position_XY_Mixed" << tag.c_str() << id; + local_histos.globalPosXY[0] = td.make< TH2F >(histoName.str().c_str(), histoName.str().c_str(), 2400, -120.0, 120.0, 2400, -120.0, 120.0); + + histoName.str(""); histoName << "Global_Position_XY_Pixel" << tag.c_str() << id; + local_histos.globalPosXY[1] = td.make< TH2F >(histoName.str().c_str(), histoName.str().c_str(), 2400, -120.0, 120.0, 2400, -120.0, 120.0); + + histoName.str(""); histoName << "Global_Position_XY_Strip" << tag.c_str() << id; + local_histos.globalPosXY[2] = td.make< TH2F >(histoName.str().c_str(), histoName.str().c_str(), 2400, -120.0, 120.0, 2400, -120.0, 120.0); + + /* + * Delta positions with SimHits + */ + + histoName.str(""); histoName << "Delta_X_Cluster_SimHits_Mixed" << tag.c_str() << id; + local_histos.deltaXClusterSimHits[0] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_X_Cluster_SimHits_Pixel" << tag.c_str() << id; + local_histos.deltaXClusterSimHits[1] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_X_Cluster_SimHits_Strip" << tag.c_str() << id; + local_histos.deltaXClusterSimHits[2] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_Y_Cluster_SimHits_Mixed" << tag.c_str() << id; + local_histos.deltaYClusterSimHits[0] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_Y_Cluster_SimHits_Pixel" << tag.c_str() << id; + local_histos.deltaYClusterSimHits[1] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_Y_Cluster_SimHits_Strip" << tag.c_str() << id; + local_histos.deltaYClusterSimHits[2] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + /* + * Delta position with simHits for primary tracks only + */ + + histoName.str(""); histoName << "Delta_X_Cluster_SimHits_Mixed_P" << tag.c_str() << id; + local_histos.deltaXClusterSimHits_P[0] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_X_Cluster_SimHits_Pixel_P" << tag.c_str() << id; + local_histos.deltaXClusterSimHits_P[1] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_X_Cluster_SimHits_Strip_P" << tag.c_str() << id; + local_histos.deltaXClusterSimHits_P[2] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_Y_Cluster_SimHits_Mixed_P" << tag.c_str() << id; + local_histos.deltaYClusterSimHits_P[0] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_Y_Cluster_SimHits_Pixel_P" << tag.c_str() << id; + local_histos.deltaYClusterSimHits_P[1] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + histoName.str(""); histoName << "Delta_Y_Cluster_SimHits_Strip_P" << tag.c_str() << id; + local_histos.deltaYClusterSimHits_P[2] = td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 100, 0., 0.); + + /* + * Information on the Digis per cluster + */ + + histoName.str(""); histoName << "Primary_Digis" << tag.c_str() << id; + local_histos.primarySimHits= td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 10, 0., 10.); + + histoName.str(""); histoName << "Other_Digis" << tag.c_str() << id; + local_histos.otherSimHits= td.make< TH1F >(histoName.str().c_str(), histoName.str().c_str(), 10, 0., 10.); + + /* + * End + */ + + std::pair< std::map< unsigned int, ClusterHistos >::iterator, bool > insertedIt(histograms_.insert(std::make_pair(ival, local_histos))); + fs->file().cd("/"); + + return insertedIt.first; +} + +unsigned int Phase2TrackerClusterizerValidation::getLayerNumber(const DetId& detid, const TrackerTopology* topo) { + if (detid.det() == DetId::Tracker) { + if (detid.subdetId() == PixelSubdetector::PixelBarrel) return (topo->pxbLayer(detid)); + else if (detid.subdetId() == PixelSubdetector::PixelEndcap) return (100 * topo->pxfSide(detid) + topo->pxfDisk(detid)); + else return 999; + } + return 999; +} + +unsigned int Phase2TrackerClusterizerValidation::getSimTrackId(const edm::Handle< edm::DetSetVector< PixelDigiSimLink > >& pixelSimLinks, const DetId& detId, unsigned int channel) { + edm::DetSetVector< PixelDigiSimLink >::const_iterator DSViter(pixelSimLinks->find(detId)); + if (DSViter == pixelSimLinks->end()) return 0; + for (edm::DetSet< PixelDigiSimLink >::const_iterator it = DSViter->data.begin(); it != DSViter->data.end(); ++it) { + if (channel == it->channel()) return it->SimTrackId(); + } + return 0; +} + +DEFINE_FWK_MODULE(Phase2TrackerClusterizerValidation); diff --git a/SimTracker/SiPhase2Digitizer/test/run_cluster_validation.py b/SimTracker/SiPhase2Digitizer/test/ClustersValidationTest_cfg.py similarity index 52% rename from SimTracker/SiPhase2Digitizer/test/run_cluster_validation.py rename to SimTracker/SiPhase2Digitizer/test/ClustersValidationTest_cfg.py index a0e1b7f0a0c20..fc99f1f7415dc 100644 --- a/SimTracker/SiPhase2Digitizer/test/run_cluster_validation.py +++ b/SimTracker/SiPhase2Digitizer/test/ClustersValidationTest_cfg.py @@ -10,12 +10,15 @@ process.load('FWCore.MessageService.MessageLogger_cfi') process.load('Configuration.EventContent.EventContent_cff') process.load('SimGeneral.MixingModule.mixNoPU_cfi') -process.load('Configuration.Geometry.GeometryExtended2023MuonReco_cff') +process.load('Configuration.Geometry.GeometryExtended2023MuondevReco_cff') process.load('Configuration.StandardSequences.MagneticField_38T_PostLS1_cff') -process.load('Configuration.StandardSequences.Reconstruction_Data_cff') -process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.RawToDigi_cff') +process.load('Configuration.StandardSequences.L1Reco_cff') +process.load('Configuration.StandardSequences.Reconstruction_cff') +process.load('Configuration.StandardSequences.Validation_cff') +process.load('DQMOffline.Configuration.DQMOfflineMC_cff') process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') -process.load('Geometry.TrackerGeometryBuilder.StackedTrackerGeometry_cfi') +process.load('Geometry.TrackerNumberingBuilder.trackerTopologyConstants_cfi') # Number of events (-1 = all) process.maxEvents = cms.untracked.PSet( @@ -24,7 +27,7 @@ # Input file process.source = cms.Source('PoolSource', - fileNames = cms.untracked.vstring('file:reco.root') + fileNames = cms.untracked.vstring('file:step3.root') ) # TAG @@ -33,19 +36,7 @@ # Output process.TFileService = cms.Service('TFileService', - fileName = cms.string('file:val_clu.root') -) - -# Output -process.FEVTDEBUGoutput = cms.OutputModule('PoolOutputModule', - splitLevel = cms.untracked.int32(0), - eventAutoFlushCompressedSize = cms.untracked.int32(5242880), - outputCommands = process.FEVTDEBUGEventContent.outputCommands, - fileName = cms.untracked.string('file:val_clu.root'), - dataset = cms.untracked.PSet( - filterName = cms.untracked.string(''), - dataTier = cms.untracked.string('GEM-SIM-DIGI-CLU') - ) + fileName = cms.string('file:cluster_validation.root') ) # DEBUG @@ -58,13 +49,14 @@ ) # Analyzer -process.analysis = cms.EDAnalyzer('SiPhase2ClustersValidation', - useRecHits = cms.bool(False) +process.analysis = cms.EDAnalyzer('Phase2TrackerClusterizerValidation', + src = cms.InputTag("siPhase2Clusters"), + links = cms.InputTag("simSiPixelDigis") ) -process.analysis_step = cms.Path(cms.Sequence(process.analysis)) +# Processes to run +process.p = cms.Path(process.analysis) -process.FEVTDEBUGoutput_step = cms.EndPath(process.FEVTDEBUGoutput) +from SLHCUpgradeSimulations.Configuration.phase2TkCustomsBE5DPixel10Ddev import customise_condOverRides +process = customise_condOverRides(process) -# Processes to run -process.schedule = cms.Schedule(process.analysis_step) diff --git a/SimTracker/SiPhase2Digitizer/test/hits.cc b/SimTracker/SiPhase2Digitizer/test/hits.cc deleted file mode 100644 index 6bc5a3a658435..0000000000000 --- a/SimTracker/SiPhase2Digitizer/test/hits.cc +++ /dev/null @@ -1,116 +0,0 @@ -#include "SimTracker/SiPhase2Digitizer/test/hits.h" -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" - -ValHitsCollection ValHitsBuilder(const TrackerGeometry* tkGeom, edm::DetSetVector< PixelClusterSimLink >* clusterLinks) { - - ValHitsCollection hits; - - edm::DetSetVector< PixelClusterSimLink >::const_iterator DSViter; - edm::DetSet< PixelClusterSimLink >::const_iterator clusterLink; - - for (DSViter = clusterLinks->begin(); DSViter != clusterLinks->end(); ++DSViter) { - - // Get the geometry of the tracker - DetId detId(DSViter->detId()); - const GeomDetUnit* geomDetUnit = tkGeom->idToDetUnit(detId); - const PixelGeomDetUnit* pixDet = dynamic_cast< const PixelGeomDetUnit* >(geomDetUnit); - if (!pixDet) assert(0); - - // Loop over cluster links - for (clusterLink = DSViter->data.begin(); clusterLink != DSViter->data.end(); ++clusterLink) { - - PixelClusterSimLink link = *clusterLink; - - // Get the cluster - edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > const& cluster = link.getCluster(); - - // Create the Hit - ValHit newHit; - - // Set the cluster position - MeasurementPoint mp(cluster->x(), cluster->y()); - newHit.localPos = geomDetUnit->topology().localPosition(mp); - newHit.globalPos = geomDetUnit->surface().toGlobal(newHit.localPos); - - // Set the error - newHit.xx = newHit.xy = newHit.yy = -1; - - // Add the simTracks and the reference - newHit.simTracks = link.getSimTracks(); - newHit.cluster = link.getCluster(); - - // Add the Hit - hits[DSViter->detId()].push_back(newHit); - } - } - - return hits; -} - -ValHitsCollection ValHitsBuilder(const TrackerGeometry* tkGeom, edm::DetSetVector< PixelClusterSimLink >* clusterLinks, edmNew::DetSetVector< SiPixelRecHit >* recHits) { - - ValHitsCollection hits; - - edmNew::DetSetVector< SiPixelRecHit >::const_iterator DSViter; - edmNew::DetSet< SiPixelRecHit >::const_iterator rechHitIter; - - edm::DetSet< PixelClusterSimLink >::const_iterator clusterLink; - - for (DSViter = recHits->begin(); DSViter != recHits->end(); ++DSViter) { - - // Get the geometry of the tracker - DetId detId(DSViter->detId()); - const GeomDetUnit* geomDetUnit = tkGeom->idToDetUnit(detId); - - // Get the cluster simlinks DetSet - edm::DetSet< PixelClusterSimLink > clusters = (*clusterLinks)[DSViter->detId()]; - - // Loop over recHits - for (rechHitIter = DSViter->begin(); rechHitIter != DSViter->end(); ++rechHitIter) { - - // Get the cluster - edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > const& cluster = rechHitIter->cluster(); - - // Create the Hit - ValHit newHit; - - // Set the recHit position - newHit.localPos = rechHitIter->localPosition(); - - MeasurementPoint mp(rechHitIter->localPosition().x(), rechHitIter->localPosition().y()); - newHit.globalPos = geomDetUnit->surface().toGlobal(geomDetUnit->topology().localPosition(mp)); - - // Set the Error - newHit.xx = rechHitIter->localPositionError().xx(); - newHit.xy = rechHitIter->localPositionError().xy(); - newHit.yy = rechHitIter->localPositionError().yy(); - - bool clusterFound = false; - - // Loop over the clusters - for (clusterLink = clusters.begin(); clusterLink != clusters.end(); ++clusterLink) { - PixelClusterSimLink link = *clusterLink; - - edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > const& clusterFromLink = link.getCluster(); - - // Compare the clusters - if (cluster == clusterFromLink) { - - // Add the simTracks and the reference - newHit.simTracks = link.getSimTracks(); - newHit.cluster = link.getCluster(); - - clusterFound = true; - break; - } - } - - // Add the Hit - if (clusterFound) hits[DSViter->detId()].push_back(newHit); - - } - } - - return hits; -} diff --git a/SimTracker/SiPhase2Digitizer/test/hits.h b/SimTracker/SiPhase2Digitizer/test/hits.h deleted file mode 100644 index 0587c18ed772e..0000000000000 --- a/SimTracker/SiPhase2Digitizer/test/hits.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef RecoLocalTracker_SiPhase2Clusterizer_hits_H -#define RecoLocalTracker_SiPhase2Clusterizer_hits_H - -#include "DataFormats/Common/interface/DetSetVector.h" -#include "DataFormats/Common/interface/DetSetVectorNew.h" -#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" -#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h" -#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h" - -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" -#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h" -#include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h" - -#include -#include - -typedef std::map< unsigned int, std::vector< struct ValHit > > ValHitsCollection; -typedef std::vector< struct ValHit > ValHitsVector; -typedef struct ValHit ValHit; - -struct ValHit { - double x, y; - LocalPoint localPos; - GlobalPoint globalPos; - double xx, xy, yy; - std::vector< unsigned int > simTracks; - edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > cluster; -}; - - - -ValHitsCollection ValHitsBuilder(const TrackerGeometry* tkGeom, edm::DetSetVector< PixelClusterSimLink >* clusterLinks); -ValHitsCollection ValHitsBuilder(const TrackerGeometry* tkGeom, edm::DetSetVector< PixelClusterSimLink >* clusterLinks, edmNew::DetSetVector< SiPixelRecHit >* recHits); - -#endif diff --git a/SimTracker/SiPhase2Digitizer/test/phase2clusters_validation.cc b/SimTracker/SiPhase2Digitizer/test/phase2clusters_validation.cc deleted file mode 100644 index ba1391742a624..0000000000000 --- a/SimTracker/SiPhase2Digitizer/test/phase2clusters_validation.cc +++ /dev/null @@ -1,873 +0,0 @@ -#include -#include - -#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" -#include "SimDataFormats/Track/interface/SimTrackContainer.h" -#include "SimDataFormats/Vertex/interface/SimVertexContainer.h" -#include "SimTracker/SiPhase2Digitizer/interface/PixelClusterSimLink.h" -#include "SimDataFormats/TrackingHit/interface/PSimHit.h" - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "DataFormats/Common/interface/Handle.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Utilities/interface/InputTag.h" -#include "FWCore/ServiceRegistry/interface/Service.h" - -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" -#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h" -#include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h" - -#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h" -#include "DataFormats/SiPixelDetId/interface/PXBDetId.h" -#include "DataFormats/SiPixelDetId/interface/PXFDetId.h" -#include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h" -#include "DataFormats/Common/interface/DetSetVector.h" -#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" -#include "DataFormats/DetId/interface/DetId.h" -#include "DataFormats/Common/interface/Handle.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigiCollection.h" - -#include "CommonTools/UtilAlgos/interface/TFileService.h" -#include "CommonTools/Utils/interface/TFileDirectory.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SimTracker/SiPhase2Digitizer/test/hits.h" - -int verbose = 0; -const int nTypes = 18; -const int nPS=3; - -using namespace std; - -class SiPhase2ClustersValidation : public edm::EDAnalyzer { - - typedef vector< pair< PSimHit , vector< ValHit > > > V_HIT_CLUSTERS; - typedef map< int , V_HIT_CLUSTERS > M_TRK_HIT_CLUSTERS; - -public: - explicit SiPhase2ClustersValidation(const edm::ParameterSet&); - ~SiPhase2ClustersValidation(); - void beginJob(); - void analyze(const edm::Event&, const edm::EventSetup&); - void endJob(); - -private: - void calculataThor(ValHitsCollection* hitsCollection, edm::PSimHitContainer* simHits_B, edm::PSimHitContainer* simHits_E, edm::SimTrackContainer* simTracks, edm::SimVertexContainer* simVertices, const TrackerGeometry* tkGeom); - void createLayerHistograms(unsigned int iLayer); - void createHistograms(unsigned int nLayer); - unsigned int getLayerNumber(const TrackerGeometry* tkgeom, unsigned int& detid); - unsigned int getLayerNumber(unsigned int& detid); - - - bool useRecHits_; - - TH2F* trackerLayout_; - TH2F* trackerLayoutXY_; - TH2F* trackerLayoutXYBar_; - TH2F* trackerLayoutXYEC_; - - struct ClusterHistos { - THStack* NumberOfClustersSource; - TH1F* NumberOfClusterPixel; - TH1F* NumberOfClusterStrip; - - TH1F* NumberOfClustersLink; - - TH1F* NumberOfMatchedHits[nPS][nTypes]; - TH1F* NumberOfMatchedClusters[nPS][nTypes]; - TH1F* hEfficiency[nPS][nTypes]; - TH1F* h_dx_Truth[nPS]; - TH1F* h_dy_Truth[nPS]; - - THStack* ClustersSizeSource; - TH1F* clusterSizePixel; - TH1F* clusterSizeStrip; - - TH1F* clusterSize; - TH1F* clusterSizeX; - TH1F* clusterSizeY; - - TH1F* clusterShapeX; - TH1F* clusterShapeY; - TH2F* localPosXY; - TH2F* globalPosXY; - - TH2F* localPosXYPixel; - TH2F* localPosXYStrip; - - TH1F* digiType; - TH2F* digiPosition; - - TH1F* dxCluRec; - TH1F* dyCluRec; - TH1F* dRCluRec; - }; - - map< unsigned int, ClusterHistos > layerHistoMap; - - string name_PS[nPS] = {"AllMod", "PixelMod", "StripMod"}; - - string name_types[nTypes] = {"Undefined","Unknown","Primary","Hadronic", - "Decay","Compton","Annihilation","EIoni", - "HIoni","MuIoni","Photon","MuPairProd", - "Conversions","EBrem","SynchrotronRadiation", - "MuBrem","MuNucl","AllTypes"}; - -}; - -SiPhase2ClustersValidation::SiPhase2ClustersValidation(const edm::ParameterSet& iConfig) { - useRecHits_ = iConfig.getParameter< bool >("useRecHits"); - - // Use RecHits - if (useRecHits_) cout << "INFO: Using RecHits" << endl; - // Use Clusters - else cout << "INFO: Using Clusters" << endl; -} - -SiPhase2ClustersValidation::~SiPhase2ClustersValidation() { } - -void SiPhase2ClustersValidation::beginJob() { - createHistograms(19); -} - -void SiPhase2ClustersValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { - - // Get the clusters - edm::Handle< SiPixelClusterCollectionNew > clustersHandle; - iEvent.getByLabel("siPhase2Clusters", clustersHandle); - // const edmNew::DetSetVector< SiPixelCluster >& clusters = *clustersHandle; - - // Get the cluster simlinks - edm::Handle< edm::DetSetVector< PixelClusterSimLink > > clusterLinksHandle; - iEvent.getByLabel("siPhase2Clusters", clusterLinksHandle); - const edm::DetSetVector< PixelClusterSimLink >& clusterLinks = *clusterLinksHandle; - - // Get the geometry - edm::ESHandle< TrackerGeometry > geomHandle; - iSetup.get< TrackerDigiGeometryRecord >().get(geomHandle); - const TrackerGeometry* tkGeom = &(*geomHandle); - - - // Make selection on RecHits or Clusters - ValHitsCollection hitsCollection; - - //Get the RecHits - if (useRecHits_) { - edm::Handle< SiPixelRecHitCollection > recHitsHandle; - iEvent.getByLabel("siPixelRecHits", recHitsHandle); - const edmNew::DetSetVector< SiPixelRecHit >& recHits = *recHitsHandle; - - hitsCollection = ValHitsBuilder(tkGeom, (edm::DetSetVector< PixelClusterSimLink >*) & clusterLinks, (edmNew::DetSetVector< SiPixelRecHit >*) & recHits); - } - // Use Clusters - else hitsCollection = ValHitsBuilder(tkGeom, (edm::DetSetVector< PixelClusterSimLink >*) & clusterLinks); - - // SimHit - edm::Handle< edm::PSimHitContainer > simHits_BHandle; - iEvent.getByLabel("g4SimHits", "TrackerHitsPixelBarrelLowTof", simHits_BHandle); - const edm::PSimHitContainer& simHits_B = *simHits_BHandle; - - edm::Handle< edm::PSimHitContainer > simHits_EHandle; - iEvent.getByLabel("g4SimHits", "TrackerHitsPixelEndcapLowTof", simHits_EHandle); - const edm::PSimHitContainer& simHits_E = *simHits_EHandle; - - // SimTrack - edm::Handle< edm::SimTrackContainer > simTracksHandle; - iEvent.getByLabel("g4SimHits", simTracksHandle); - const edm::SimTrackContainer& simTracks = *simTracksHandle; - - // SimVertex - edm::Handle< edm::SimVertexContainer > simVerticesHandle; - iEvent.getByLabel("g4SimHits", simVerticesHandle); - const edm::SimVertexContainer& simVertices = *simVerticesHandle; - - // Validation module - calculataThor((ValHitsCollection*) & hitsCollection, (edm::PSimHitContainer*) & simHits_B, (edm::PSimHitContainer*) & simHits_E, (edm::SimTrackContainer*) & simTracks, (edm::SimVertexContainer*) & simVertices, tkGeom); -} - -void SiPhase2ClustersValidation::endJob() { } - - -void SiPhase2ClustersValidation::calculataThor(ValHitsCollection* hitsCollection, edm::PSimHitContainer* simHits_B, edm::PSimHitContainer* simHits_E, edm::SimTrackContainer* simTracks, edm::SimVertexContainer* simVertices, const TrackerGeometry* tkGeom) { - - //////////////////////////////// - // MAP SIM HITS TO SIM TRACKS // - //////////////////////////////// - vector< ValHit > matched_clusters; - V_HIT_CLUSTERS matched_hits; - M_TRK_HIT_CLUSTERS map_hits; - - // Fill the map - int nHits = 0; - for (edm::PSimHitContainer::const_iterator iHit = simHits_B->begin(); iHit != simHits_B->end(); ++iHit) { - map_hits[iHit->trackId()].push_back(make_pair(*iHit , matched_clusters)); - nHits++; - } - for (edm::PSimHitContainer::const_iterator iHit = simHits_E->begin(); iHit != simHits_E->end(); ++iHit) { - map_hits[iHit->trackId()].push_back(make_pair(*iHit , matched_clusters)); - nHits++; - } - - if (verbose > 1) cout << endl << "-- Number of SimHits in the event : " << nHits << endl; - - ////////////////////////////////// - // LOOP OVER CLUSTER COLLECTION // - ////////////////////////////////// - - // Loop over the detector units - for (ValHitsCollection::const_iterator vhCollectionIter = hitsCollection->begin(); vhCollectionIter != hitsCollection->end(); ++vhCollectionIter) { - - ValHitsVector hitsVector = vhCollectionIter->second; - - // Clusters - unsigned int nClusters = 0; - - // Get the detector unit's id - unsigned int rawid = vhCollectionIter->first; - unsigned int layer = getLayerNumber(rawid); - DetId detId(rawid); - - // Get the geometry of the tracker - const GeomDetUnit* geomDetUnit = tkGeom->idToDetUnit(detId); - const PixelGeomDetUnit* theGeomDet = dynamic_cast< const PixelGeomDetUnit* >(geomDetUnit); - const PixelTopology& topol = theGeomDet->specificTopology(); - - if (!geomDetUnit) break; - - // Create histograms for the layer if they do not yet exist - map< unsigned int, ClusterHistos >::iterator iPos = layerHistoMap.find(layer); - if (iPos == layerHistoMap.end()) { - createLayerHistograms(layer); - iPos = layerHistoMap.find(layer); - } - - // Loop over the clusters in the detector unit - for (ValHitsVector::const_iterator vhVectorIter = hitsVector.begin(); vhVectorIter != hitsVector.end(); ++vhVectorIter) { - - ValHit hit = *vhVectorIter; - edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > const& cluster = hit.cluster; - - iPos->second.clusterSize->Fill(cluster->size()); - iPos->second.clusterSizeX->Fill(cluster->sizeX()); - iPos->second.clusterSizeY->Fill(cluster->sizeY()); - - // Fill the histograms - MeasurementPoint mpClu(cluster->x(), cluster->y()); - Local3DPoint localPosClu = geomDetUnit->topology().localPosition(mpClu); - - iPos->second.dxCluRec->Fill(localPosClu.x() - hit.localPos.x()); - iPos->second.dyCluRec->Fill(localPosClu.y() - hit.localPos.y()); - iPos->second.dRCluRec->Fill(TMath::Sqrt((localPosClu.y() - hit.localPos.y()) * (localPosClu.y() - hit.localPos.y()) + (localPosClu.x() - hit.localPos.x()) * (localPosClu.x() - hit.localPos.x()))); - - - iPos->second.localPosXY->Fill(hit.localPos.x(), hit.localPos.y()); - iPos->second.globalPosXY->Fill(hit.globalPos.x(), hit.globalPos.y()); - - trackerLayout_->Fill(hit.globalPos.z(), hit.globalPos.perp()); - trackerLayoutXY_->Fill(hit.globalPos.x(), hit.globalPos.y()); - if (layer < 100) trackerLayoutXYBar_->Fill(hit.globalPos.x(), hit.globalPos.y()); - else trackerLayoutXYEC_->Fill(hit.globalPos.x(), hit.globalPos.y()); - - // Pixel module - if (topol.ncolumns() == 32) { - iPos->second.localPosXYPixel->Fill(hit.localPos.x(), hit.localPos.y()); - iPos->second.clusterSizePixel->Fill(cluster->size()); - } - // Strip module - else if (topol.ncolumns() == 2) { - iPos->second.localPosXYStrip->Fill(hit.localPos.x(), hit.localPos.y()); - iPos->second.clusterSizeStrip->Fill(cluster->size()); - } - - // Get the pixels that form the Cluster - const vector< SiPixelCluster::Pixel >& pixelsVec = cluster->pixels(); - - // Loop over the pixels - for (vector< SiPixelCluster::Pixel >::const_iterator pixelIt = pixelsVec.begin(); pixelIt != pixelsVec.end(); ++pixelIt) { - SiPixelCluster::Pixel PDigi = (SiPixelCluster::Pixel) *pixelIt; - - iPos->second.digiPosition->Fill(PDigi.x, PDigi.y); - - ////////////////////////// - // NOT WORKING !!!!!! // - ////////////////////////// - iPos->second.clusterShapeX->Fill(hit.localPos.x() - PDigi.x); - iPos->second.clusterShapeY->Fill(hit.localPos.y() - PDigi.y); - } - - ++nClusters; - } - - // Pixel module - if (topol.ncolumns() == 32) iPos->second.NumberOfClusterPixel->Fill(nClusters); - // Strip module - else if (topol.ncolumns() == 2) iPos->second.NumberOfClusterStrip->Fill(nClusters); - } - - ///////////////////////////// - // LOOP OVER CLUSTER LINKS // - ///////////////////////////// - - vector< unsigned int > simTrackID; - - // cluster and hit informations - unsigned int trkID(-1); - unsigned int sizeLink(0); - unsigned int rawid(0); - unsigned int layer(0); - unsigned int simh_detid(0); - unsigned int simh_layer(0); - int simh_type(0); - unsigned int nLinks(0); - bool combinatoric(false); - - // matching quantities - // - // all hits ; type-2 hits ; primary hits ; secondary hits - int nMatchedHits[nTypes] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - // - Local3DPoint pos_hit; - double x_hit(0), y_hit(0), z_hit(0), dx(0), dy(0); - bool found_hits(false); - bool fill_dtruth(false); - - if (verbose > 1) cout << endl << "-- Enter loop over links" << endl; - - // Loop over the Hits - for (ValHitsCollection::const_iterator vhCollectionIter = hitsCollection->begin(); vhCollectionIter != hitsCollection->end(); ++vhCollectionIter) { - - ValHitsVector hitsVector = vhCollectionIter->second; - - trkID = -1; - sizeLink = 0; - combinatoric = false; - - // Get the detector unit's id - rawid = vhCollectionIter->first; - layer = getLayerNumber(rawid); - DetId detId(rawid); - - // Get the geometry of the tracker - const GeomDetUnit* geomDetUnit = tkGeom->idToDetUnit(detId); - const PixelGeomDetUnit* theGeomDet = dynamic_cast(geomDetUnit); - const PixelTopology & topol = theGeomDet->specificTopology(); - - if (!geomDetUnit) break; - - // Create histograms for the layer if they do not yet exist - map< unsigned int, ClusterHistos >::iterator iPos = layerHistoMap.find(layer); - if (iPos == layerHistoMap.end()) { - createLayerHistograms(layer); - iPos = layerHistoMap.find(layer); - } - - // Loop over the links in the detector unit - if (verbose>1) cout << endl << endl << "--- DetId=" << rawid << endl; - - for (ValHitsVector::const_iterator vhVectorIter = hitsVector.begin(); vhVectorIter != hitsVector.end(); ++vhVectorIter) { - - ValHit hit = *vhVectorIter; - - // Link informations - combinatoric = false; - nLinks++; - simTrackID = hit.simTracks; - sizeLink = simTrackID.size(); - - // cluster matching quantities - for (int iM = 0; iM < nTypes; iM++) nMatchedHits[iM] = 0; - - // Cluster informations - edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > const& cluster = hit.cluster; - - if (verbose > 1) cout << endl << "---- Cluster size=" << cluster->size() << " | " << sizeLink << " SimTracks: ids=(" ; - - for (unsigned int i = 0; i < sizeLink; i++) { - if (verbose > 1) { - cout << simTrackID[i]; - if (i < sizeLink - 1) cout << ","; - } - if (i == 0) trkID = simTrackID[i]; - else if (simTrackID[i] != trkID) combinatoric = true; - } - - if (verbose > 1) { - if (combinatoric) cout << ") COMBINATORIC !!! "; - cout << ")" << endl << " cluster local position = (" << hit.localPos.x() << " , " << hit.localPos.y() << " , " << "n/a" << ")" << " layer=" << layer << endl; - } - - // Get matched SimHits from the map - if (!combinatoric) { - - matched_hits = map_hits[trkID]; - - if (verbose > 1) { - cout << " number of hits matched to the SimTrack = " << matched_hits.size() ; - if (matched_hits.size() != 0) cout << " ids(" ; - - // printout list of SimHits matched to the SimTrack - for (unsigned int iH = 0; iH < matched_hits.size(); ++iH) { - cout << matched_hits[iH].first.detUnitId(); - if (iH < matched_hits.size() - 1) cout << ","; - else cout << ")"; - } - cout << endl; - } - - found_hits = false; - fill_dtruth = false; - - // Loop over matched SimHits - - for (unsigned int iH = 0 ; iH < matched_hits.size(); iH++) { - - // Consider only SimHits with same DetID as current cluster - simh_detid = matched_hits[iH].first.detUnitId(); - if (simh_detid != rawid) continue; - else found_hits = true; - - - // Map current hit to current SimHit for efficiency study - map_hits[trkID][iH].second.push_back(hit); - - simh_layer = getLayerNumber(simh_detid); - simh_type = matched_hits[iH].first.processType(); - pos_hit = matched_hits[iH].first.localPosition(); - x_hit = pos_hit.x(); - y_hit = pos_hit.y(); - z_hit = pos_hit.z(); - - if (simh_type >= 0 && simh_type < 17) nMatchedHits[simh_type]++; - nMatchedHits[17]++; - - if (simh_type == 2) { - dx = x_hit - hit.localPos.x(); - dy = y_hit - hit.localPos.y(); - if (fill_dtruth == true) fill_dtruth = false; // eliminates cases with several type-2 hits - fill_dtruth = true; // toggle filling of the histo only when a type-2 hit is found - } - - if (verbose > 1) cout << "----- SimHit #" << iH << " type=" << simh_type - //<< " s_id=" << simh_detid - << " s_lay=" << simh_layer << " c_lay=" << layer << " s(" << x_hit << " , " << y_hit << " , " << z_hit << ")" - //<< " c_g(" << gPos.x() << " , " << gPos.y() << " , " << gPos.z() << ")" - << endl; - - } // end loop over matched SimHits - - if (!found_hits && verbose > 1) cout << "----- FOUND NO MATCHED HITS" << endl; - - } // endif !combinatoric - - // Number of matched hits (per type) - for(int iM=0 ; iMsecond.NumberOfMatchedHits[0][iM]-> Fill(nMatchedHits[iM]); - if(verbose>1) cout << "------ type #" << iM << " " << name_types[nTypes] << " : " ; - if(topol.ncolumns() == 32) { - if(verbose>1) cout << "module pixel : nMatchedHits=" << nMatchedHits[iM] << endl; - iPos->second.NumberOfMatchedHits[1][iM]-> Fill(nMatchedHits[iM]); - } - else if (topol.ncolumns()==2) { - if(verbose>1) cout << "module strip : nMatchedHits=" << nMatchedHits[iM] << endl; - iPos->second.NumberOfMatchedHits[2][iM]-> Fill(nMatchedHits[iM]); - } - else { - if(verbose>1) cout << "module unknown : nMatchedHits=" << nMatchedHits[iM] << endl; - } - } - - // Position resolution - if (fill_dtruth) { - iPos->second.h_dx_Truth[0]->Fill(dx); - iPos->second.h_dy_Truth[0]->Fill(dy); - if(topol.ncolumns() == 32) { - iPos->second.h_dx_Truth[1]->Fill(dx); - iPos->second.h_dy_Truth[1]->Fill(dy); - } - else if (topol.ncolumns()==2) { - iPos->second.h_dx_Truth[2]->Fill(dx); - iPos->second.h_dy_Truth[2]->Fill(dy); - } - } - - } // end loop over links within a single DetID - - iPos->second.NumberOfClustersLink-> Fill(nLinks); - - } // end loop over all links - - - //////////////////////////////////// - // COMPUTE CLUSTERIZER EFFICIENCY // - //////////////////////////////////// - - if (verbose > 1) cout << "- Enter efficiency computation" << endl; - - // Iterate over the map of hits & clusters - M_TRK_HIT_CLUSTERS::const_iterator iMapHits; - - // Counters - int nTrackHits(0); - int countHit(0); - int nMatchedClusters(0); - int nTotalHits(0); - int nMatchHits(0); - float efficiency(0); - - // Hit informations - unsigned int theHit_id(0); - unsigned int theHit_layer(0); - unsigned int theHit_type(0); - - // Prepare the map of counters for efficiency - map< unsigned int, ClusterHistos >::iterator iPos; - map< unsigned int , vector< vector< int > > > map_effi; - map< unsigned int , vector< vector< int > > >::const_iterator iMapEffi; - vector< int > init_counter; - - for (int iM = 0; iM < 2; iM++) init_counter.push_back(0); - - // Loop over the entries in the map of hits & clusters - if (verbose > 1) cout << "- loop over map of hits & clusters (size=" << map_hits.size() << ")" << endl; - - for (iMapHits = map_hits.begin(); iMapHits != map_hits.end(); iMapHits++) { - - if (verbose > 1) cout << "-- SimTrack ID=" << iMapHits->first << endl; - nTrackHits = (iMapHits->second).size(); - countHit += nTrackHits; - - // Loop over the hits matched to the current SimTrack ID - for (int iH = 0; iH < nTrackHits; iH++) { - - // Current SimHit - if (verbose > 1) cout << "--- SimHit #" << iH ; - PSimHit theHit(((iMapHits->second)[iH]).first); - theHit_id = theHit.detUnitId(); - theHit_layer = getLayerNumber(theHit_id); - theHit_type = theHit.processType(); - - const GeomDetUnit* geomDetUnit = tkGeom->idToDetUnit(theHit_id); - const PixelGeomDetUnit* theGeomDet = dynamic_cast(geomDetUnit); - const PixelTopology & topol = theGeomDet->specificTopology(); - - if(verbose>1) cout << " DetId=" << theHit_id - << " Layer=" << theHit_layer - << " Type=" << theHit_type - << " Topol nCol=" << topol.ncolumns() - << endl; - - // Check that the layer number makes sense - if (theHit_layer == 0) { - if (verbose > 1) cout << "---- !! layer=0 !!" << endl; - continue; - } - - // Clusters matched to the SimHit - if (verbose > 2) cout << "--- Getting corresponding clusters" << endl; - matched_clusters = ((iMapHits->second)[iH]).second; - nMatchedClusters = matched_clusters.size(); - - // Find layer in map of histograms - if (verbose > 2) cout << "--- Find layer=" << theHit_layer << " in map of histograms" << endl; - - iPos = layerHistoMap.find(theHit_layer); - if (iPos == layerHistoMap.end()) { - if (verbose > 2) cout << "---- add layer in the map" << endl; - createLayerHistograms(theHit_layer); - iPos = layerHistoMap.find(theHit_layer); - } - - // Fill Histograms - (iPos->second.NumberOfMatchedClusters[0][17])->Fill( nMatchedClusters ); - if (topol.ncolumns() == 32) (iPos->second.NumberOfMatchedClusters[1][17])->Fill( nMatchedClusters ); // ND - else if (topol.ncolumns() == 2) (iPos->second.NumberOfMatchedClusters[2][17])->Fill( nMatchedClusters ); // ND - - if(theHit_type<17) { - (iPos->second.NumberOfMatchedClusters[0][theHit_type])->Fill( nMatchedClusters ); - if (topol.ncolumns() == 32) (iPos->second.NumberOfMatchedClusters[1][theHit_type])->Fill( nMatchedClusters ); - else if (topol.ncolumns() == 2) (iPos->second.NumberOfMatchedClusters[2][theHit_type])->Fill( nMatchedClusters ); - } - - if (nMatchedClusters == 0 && verbose > 1) cout << "---- No Cluster Matched" << endl; - else if (verbose > 1) cout << "---- Yes Cluster Matched = " << nMatchedClusters << endl; - - if (map_effi.find(theHit_layer) == map_effi.end()) { - for (int iT = 0; iT < nTypes; iT++) { - map_effi[theHit_layer].push_back(init_counter); - if (verbose > 2) cout << "----- type #" << iT << " layer=" << theHit_layer << " map size=" << map_effi.size() << endl; - } - } - - (map_effi[theHit_layer][theHit_type][0])++; // total number of hits of this type in this layer - if (nMatchedClusters > 0) (map_effi[theHit_layer][theHit_type][1])++; // number of hits matched to >=1 cluster(s) - - (map_effi[theHit_layer][17][0])++; // total number of hits of this type in this layer - if (nMatchedClusters > 0) (map_effi[theHit_layer][17][1])++; // number of hits matched to >=1 cluster(s) - } - - } - - - // Fill histograms from the map_effi - if (verbose > 1) cout << "- fill [per layer] effi histo from effi map (size=" << map_effi.size() << ")" << endl; - - for (iMapEffi = map_effi.begin(); iMapEffi != map_effi.end(); iMapEffi++) { - - iPos = layerHistoMap.find(iMapEffi->first); - if (verbose > 1) cout << "-- layer=" << iMapEffi->first << endl; - - for (int iT = 0; iT < nTypes; iT++) { - nTotalHits = iMapEffi->second[iT][0]; - nMatchHits = iMapEffi->second[iT][1]; - efficiency = nTotalHits != 0 ? float(nMatchHits) / float(nTotalHits) : -1; - - if(efficiency>=0) { - (iPos->second.hEfficiency[0][iT])->Fill( efficiency ); - //if(topol.ncolumns() == 32) (iPos->second.hEfficiency[1][iT])->Fill( efficiency ); // ND - //else if (topol.ncolumns()==2) (iPos->second.hEfficiency[2][iT])->Fill( efficiency ); // ND - } - - if(verbose>1) cout << "--- type #" << iT - << " nTotalHits=" << nTotalHits - << " nMatchHits=" << nMatchHits - << " efficiency=" << efficiency - << endl; - } - } - - - // Check if all event's SimHits are mapped - if (countHit != nHits && verbose > 1) cout << "---- Missing hits in the efficiency computation : " << countHit << " != " << nHits << endl; - - if (verbose > 999) cout << nTotalHits << nMatchHits << efficiency << endl; -} - -// Create the histograms -void SiPhase2ClustersValidation::createLayerHistograms(unsigned int ival) { - ostringstream fname1, fname2; - - edm::Service fs; - fs->file().cd("/"); - - string tag; - unsigned int id; - if (ival < 100) { - id = ival; - fname1 << "Barrel"; - fname2 << "Layer_" << id; - tag = "_layer_"; - } - else { - int side = ival / 100; - id = ival - side*100; - fname1 << "EndCap_Side_" << side; - fname2 << "Disc_" << id; - tag = "_disc_"; - } - - TFileDirectory td1 = fs->mkdir(fname1.str().c_str()); - TFileDirectory td = td1.mkdir(fname2.str().c_str()); - - ClusterHistos local_histos; - - ostringstream histoName; - - histoName.str(""); - histoName << "Number_of_Clusters_Pixel" << tag.c_str() << id; - local_histos.NumberOfClusterPixel = td.make(histoName.str().c_str(), histoName.str().c_str(), 21, 0., 20.); - histoName.str(""); - histoName << "Number_of_Clusters_Strip" << tag.c_str() << id; - local_histos.NumberOfClusterStrip = td.make(histoName.str().c_str(), histoName.str().c_str(), 21, 0., 20.); - - local_histos.NumberOfClusterPixel->SetFillColor(kBlue); - local_histos.NumberOfClusterStrip->SetFillColor(kRed); - - histoName.str(""); - histoName << "Number_of_Clusters" << tag.c_str() << id; - local_histos.NumberOfClustersSource = td.make(histoName.str().c_str(), histoName.str().c_str()); - local_histos.NumberOfClustersSource->Add(local_histos.NumberOfClusterPixel); - local_histos.NumberOfClustersSource->Add(local_histos.NumberOfClusterStrip); - - - histoName.str(""); - histoName << "Number_of_Clusters_Link" << tag.c_str() << id; - local_histos.NumberOfClustersLink = td.make(histoName.str().c_str(), histoName.str().c_str(), 21, 0., 20.); - - // Truth Matching - for(int iPS=0 ; iPS(histoName.str().c_str(), histoName.str().c_str(), 21, 0., 20.); - - histoName.str(""); - histoName << "NumberOfMatchedClusters_" << name_PS[iPS] << "_" << name_types[iM] << tag.c_str() << id; - local_histos.NumberOfMatchedClusters[iPS][iM] = td.make(histoName.str().c_str(), histoName.str().c_str(), 21, 0., 20.); - - histoName.str(""); - histoName << "Efficiency_" << name_PS[iPS] << "_" << name_types[iM] << tag.c_str() << id; - local_histos.hEfficiency[iPS][iM] = td.make(histoName.str().c_str(), histoName.str().c_str(), 110, 0., 1.1); - } - - histoName.str(""); - histoName << "DeltaX_simhit_cluster" << "_" << name_PS[iPS] << tag.c_str() << id; - local_histos.h_dx_Truth[iPS] = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - - histoName.str(""); - histoName << "DeltaY_simhit_cluster" << "_" << name_PS[iPS] << tag.c_str() << id; - local_histos.h_dy_Truth[iPS] = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - - } - - // Cluster topology - - histoName.str(""); - histoName << "ClusterSize" << tag.c_str() << id; - local_histos.clusterSize = td.make(histoName.str().c_str(), histoName.str().c_str(), 50, 0., 50.); - histoName.str(""); - histoName << "ClusterSize_Pixel" << tag.c_str() << id; - local_histos.clusterSizePixel = td.make(histoName.str().c_str(), histoName.str().c_str(), 50, 0., 50.); - histoName.str(""); - histoName << "ClusterSize_Strip" << tag.c_str() << id; - local_histos.clusterSizeStrip = td.make(histoName.str().c_str(), histoName.str().c_str(), 50, 0., 50.); - - local_histos.clusterSizePixel->SetFillColor(kBlue); - local_histos.clusterSizeStrip->SetFillColor(kRed); - - histoName.str(""); - histoName << "Clusters_Size_Source" << tag.c_str() << id; - local_histos.ClustersSizeSource = td.make(histoName.str().c_str(), histoName.str().c_str()); - local_histos.ClustersSizeSource->Add(local_histos.clusterSizePixel); - local_histos.ClustersSizeSource->Add(local_histos.clusterSizeStrip); - - histoName.str(""); - histoName << "ClusterSizeX" << tag.c_str() << id; - local_histos.clusterSizeX = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - histoName.str(""); - histoName << "ClusterSizeY" << tag.c_str() << id; - local_histos.clusterSizeY = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - - histoName.str(""); - histoName << "ClusterShapeX" << tag.c_str() << id; - local_histos.clusterShapeX = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - histoName.str(""); - histoName << "ClusterShapeY" << tag.c_str() << id; - local_histos.clusterShapeY = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - - histoName.str(""); - histoName << "LocalPositionXY" << tag.c_str() << id; - local_histos.localPosXY = td.make(histoName.str().c_str(), histoName.str().c_str(), 2000, 0., 0., 2000, 0., 0.); - - histoName.str(""); - histoName << "GlobalPositionXY" << tag.c_str() << id; - local_histos.globalPosXY = td.make(histoName.str().c_str(), histoName.str().c_str(), 2400, -120.0, 120.0, 2400, -120.0, 120.0); - histoName.str(""); - histoName << "LocalPositionXY_Pixel" << tag.c_str() << id; - local_histos.localPosXYPixel = td.make(histoName.str().c_str(), histoName.str().c_str(), 2000, 0., 0., 2000, 0., 0.); - histoName.str(""); - histoName << "LocalPositionXY_Strip" << tag.c_str() << id; - local_histos.localPosXYStrip = td.make(histoName.str().c_str(), histoName.str().c_str(), 2000, 0., 0., 2000, 0., 0.); - - histoName.str(""); - histoName << "Digi_type_" << tag.c_str() << id; - local_histos.digiType = td.make(histoName.str().c_str(), histoName.str().c_str(), 2, 0, 1); - histoName.str(""); - histoName << "Digi_position_" << tag.c_str() << id; - local_histos.digiPosition = td.make(histoName.str().c_str(), histoName.str().c_str(), 2000, 0., 0., 2000, 0., 0.); - - histoName.str(""); - histoName << "DeltaX_Cluster_RecHit_" << tag.c_str() << id; - local_histos.dxCluRec = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - histoName.str(""); - histoName << "DeltaY_Cluster_RecHit_" << tag.c_str() << id; - local_histos.dyCluRec = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - histoName.str(""); - histoName << "DeltaR_Cluster_RecHit_" << tag.c_str() << id; - local_histos.dRCluRec = td.make(histoName.str().c_str(), histoName.str().c_str(), 1000, 0., 0.); - - - layerHistoMap.insert(make_pair(ival, local_histos)); - fs->file().cd("/"); -} - -void SiPhase2ClustersValidation::createHistograms(unsigned int nLayer) { - edm::Service fs; - fs->file().cd("/"); - TFileDirectory td = fs->mkdir("Common"); - - trackerLayout_ = td.make("RVsZ", "R vs. z position", 6000, -300.0, 300.0, 1200, 0.0, 120.0); - trackerLayoutXY_ = td.make("XVsY", "x vs. y position", 2400, -120.0, 120.0, 2400, -120.0, 120.0); - trackerLayoutXYBar_ = td.make("XVsYBar", "x vs. y position", 2400, -120.0, 120.0, 2400, -120.0, 120.0); - trackerLayoutXYEC_ = td.make("XVsYEC", "x vs. y position", 2400, -120.0, 120.0, 2400, -120.0, 120.0); -} - -// -// -- Get Layer Number -// -unsigned int SiPhase2ClustersValidation::getLayerNumber(const TrackerGeometry* tkgeom,unsigned int& detid) { - unsigned int layer = 999; - DetId theDetId(detid); - if (theDetId.subdetId() != 1) - std::cout << ">>> Method1 : Det id " << theDetId.det() << " Subdet Id " << theDetId.subdetId() << std::endl; - const PixelGeomDetUnit * theGeomDet = - dynamic_cast ( tkgeom->idToDet(theDetId) ); - - const GeomDetUnit* it = tkgeom->idToDetUnit(DetId(theDetId)); - if (!it) std::cout << ">>> rawdetid " << detid - << " GeomDetUnit " << it - << " PixelGeomDetUnit " << theGeomDet - << " DetId " << theDetId.det() - << " Subdet Id " << theDetId.subdetId() - << std::endl; - - if (it && it->type().isTracker()) { - if (it->type().isBarrel()) { - PXBDetId pb_detId = PXBDetId(detid); - layer = pb_detId.layer(); - } else if (it->type().isEndcap()) { - PXFDetId pf_detId = PXFDetId(detid); - layer = 100*pf_detId.side() + pf_detId.disk(); - } - } - return layer; -} -// -// -- Get Layer Number -// -unsigned int SiPhase2ClustersValidation::getLayerNumber(unsigned int& detid) { - unsigned int layer = 999; - DetId theDetId(detid); - if (theDetId.det() == DetId::Tracker) { - if (theDetId.subdetId() == PixelSubdetector::PixelBarrel) { - PXBDetId pb_detId = PXBDetId(detid); - layer = pb_detId.layer(); - } else if (theDetId.subdetId() == PixelSubdetector::PixelEndcap) { - PXFDetId pf_detId = PXFDetId(detid); - layer = 100*pf_detId.side() + pf_detId.disk(); - } else { - std::cout << ">>> Invalid subdetId() = " << theDetId.subdetId() << std::endl; - } - } - return layer; -} - -DEFINE_FWK_MODULE(SiPhase2ClustersValidation); From d811a6f84f049644c0d76aaade6f00a1408400cd Mon Sep 17 00:00:00 2001 From: Thomas Lenzi Date: Sat, 7 Mar 2015 13:42:34 +0100 Subject: [PATCH 2/2] Added delete instruction to free memory --- .../SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc b/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc index 60e52741715b2..14313cd543a2e 100644 --- a/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc +++ b/SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerClusterizer.cc @@ -32,7 +32,9 @@ namespace cms { clusterizer_ = new Phase2TrackerClusterizerAlgorithm(maxClusterSize_, maxNumberClusters_); } - Phase2TrackerClusterizer::~Phase2TrackerClusterizer() { } + Phase2TrackerClusterizer::~Phase2TrackerClusterizer() { + delete clusterizer_; + } /* * Clusterize the events