CMS 3D CMS Logo

Phase2OTValidateRecHit.cc
Go to the documentation of this file.
1 // Package: Phase2OTValidateRecHit
2 // Class: Phase2OTValidateRecHit
3 //
7 //
8 // Author: Suvankar Roy Chowdhury
9 // Date: March 2021
10 //
11 // system include files
20 
30 
45 
48 
50 public:
52  ~Phase2OTValidateRecHit() override;
53  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57 private:
58  void fillOTHistos(const edm::Event& iEvent,
59  const TrackerHitAssociator& associateRecHit,
61  const std::map<unsigned int, SimTrack>& selectedSimTrackMap);
62 
64  const double simtrackminpt_;
67  std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> simHitTokens_;
68 };
69 
70 //
71 // constructors
72 //
74  : Phase2OTValidateRecHitBase(iConfig),
75  trackerHitAssociatorConfig_(iConfig, consumesCollector()),
76  simtrackminpt_(iConfig.getParameter<double>("SimTrackMinPt")),
77  tokenRecHitsOT_(consumes<Phase2TrackerRecHit1DCollectionNew>(iConfig.getParameter<edm::InputTag>("rechitsSrc"))),
78  simTracksToken_(consumes<edm::SimTrackContainer>(iConfig.getParameter<edm::InputTag>("simTracksSrc"))) {
79  edm::LogInfo("Phase2OTValidateRecHit") << ">>> Construct Phase2OTValidateRecHit ";
80  for (const auto& itag : config_.getParameter<std::vector<edm::InputTag>>("PSimHitSource"))
81  simHitTokens_.push_back(consumes<edm::PSimHitContainer>(itag));
82 }
83 
84 //
85 // destructor
86 //
88  // do anything here that needs to be done at desctruction time
89  // (e.g. close files, deallocate resources etc.)
90  edm::LogInfo("Phase2OTValidateRecHit") << ">>> Destroy Phase2OTValidateRecHit ";
91 }
92 
93 //
94 // -- Analyze
95 //
97  std::vector<edm::Handle<edm::PSimHitContainer>> simHits;
98  for (const auto& itoken : simHitTokens_) {
99  const auto& simHitHandle = iEvent.getHandle(itoken);
100  if (!simHitHandle.isValid())
101  continue;
102  simHits.emplace_back(simHitHandle);
103  }
104  // Get the SimTracks and push them in a map of id, SimTrack
105  const auto& simTracks = iEvent.getHandle(simTracksToken_);
106  std::map<unsigned int, SimTrack> selectedSimTrackMap;
107  for (const auto& simTrackIt : *simTracks)
108  if (simTrackIt.momentum().pt() > simtrackminpt_) {
109  selectedSimTrackMap.insert(std::make_pair(simTrackIt.trackId(), simTrackIt));
110  }
112  fillOTHistos(iEvent, associateRecHit, simHits, selectedSimTrackMap);
113 }
114 
116  const TrackerHitAssociator& associateRecHit,
118  const std::map<unsigned int, SimTrack>& selectedSimTrackMap) {
119  // Get the RecHits
120  const auto& rechits = iEvent.getHandle(tokenRecHitsOT_);
121  if (!rechits.isValid())
122  return;
123  std::map<std::string, unsigned int> nrechitLayerMapP_primary;
124  std::map<std::string, unsigned int> nrechitLayerMapS_primary;
125  // Loop over modules
127  for (const auto& DSViter : *rechits) {
128  // Get the detector unit's id
129  unsigned int rawid(DSViter.detId());
130  DetId detId(rawid);
131  // determine the detector we are in
135  if (nrechitLayerMapP_primary.find(key) == nrechitLayerMapP_primary.end()) {
136  nrechitLayerMapP_primary.insert(std::make_pair(key, DSViter.size()));
137  } else {
138  nrechitLayerMapP_primary[key] += DSViter.size();
139  }
141  if (nrechitLayerMapS_primary.find(key) == nrechitLayerMapS_primary.end()) {
142  nrechitLayerMapS_primary.insert(std::make_pair(key, DSViter.size()));
143  } else {
144  nrechitLayerMapS_primary[key] += DSViter.size();
145  }
146  }
147  //loop over rechits for a single detId
148  for (const auto& rechit : DSViter) {
149  //GetSimHits
150  const std::vector<SimHitIdpr>& matchedId = associateRecHit.associateHitId(rechit);
151  const PSimHit* simhitClosest = nullptr;
152  LocalPoint lp = rechit.localPosition();
153  float mind = 1e4;
154  for (const auto& simHitCol : simHits) {
155  for (const auto& simhitIt : *simHitCol) {
156  if (detId.rawId() != simhitIt.detUnitId())
157  continue;
158  for (auto& mId : matchedId) {
159  if (simhitIt.trackId() == mId.first) {
160  float dx = simhitIt.localPosition().x() - lp.x();
161  float dy = simhitIt.localPosition().y() - lp.y();
162  float dist = dx * dx + dy * dy;
163  if (!simhitClosest || dist < mind) {
164  mind = dist;
165  simhitClosest = &simhitIt;
166  }
167  }
168  }
169  } //end loop over PSimhitcontainers
170  } //end loop over simHits
171  if (!simhitClosest)
172  continue;
174  simhitClosest, &rechit, selectedSimTrackMap, nrechitLayerMapP_primary, nrechitLayerMapS_primary);
175 
176  } //end loop over rechits of a detId
177  } //End loop over DetSetVector
178 
179  //fill nRecHits per event
180  //fill nRecHit counter per layer
181  for (auto& lme : nrechitLayerMapP_primary) {
182  layerMEs_[lme.first].numberRecHitsprimary_P->Fill(nrechitLayerMapP_primary[lme.first]);
183  }
184  for (auto& lme : nrechitLayerMapS_primary) {
185  layerMEs_[lme.first].numberRecHitsprimary_S->Fill(nrechitLayerMapS_primary[lme.first]);
186  }
187 }
188 
191  // call the base fillPsetDescription for the plots bookings
193 
194  //for macro-pixel sensors
196  desc.add<edm::InputTag>("SimVertexSource", edm::InputTag("g4SimHits"));
197  desc.add<bool>("associatePixel", false);
198  desc.add<std::string>("TopFolderName", "TrackerPhase2OTRecHitV");
199  desc.add<bool>("associateHitbySimTrack", true);
200  desc.add<bool>("Verbosity", false);
201  desc.add<bool>("associateStrip", true);
202  desc.add<edm::InputTag>("phase2TrackerSimLinkSrc", edm::InputTag("simSiPixelDigis", "Tracker"));
203  desc.add<bool>("associateRecoTracks", false);
204  desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis", "Pixel"));
205  desc.add<bool>("usePhase2Tracker", true);
206  desc.add<edm::InputTag>("rechitsSrc", edm::InputTag("siPhase2RecHits"));
207  desc.add<edm::InputTag>("simTracksSrc", edm::InputTag("g4SimHits"));
208  desc.add<double>("SimTrackMinPt", 2.0);
209  desc.add<std::vector<edm::InputTag>>("PSimHitSource",
210  {
211  edm::InputTag("g4SimHits:TrackerHitsTIBLowTof"),
212  edm::InputTag("g4SimHits:TrackerHitsTIBHighTof"),
213  edm::InputTag("g4SimHits:TrackerHitsTIDLowTof"),
214  edm::InputTag("g4SimHits:TrackerHitsTIDHighTof"),
215  edm::InputTag("g4SimHits:TrackerHitsTOBLowTof"),
216  edm::InputTag("g4SimHits:TrackerHitsTOBHighTof"),
217  edm::InputTag("g4SimHits:TrackerHitsTECLowTof"),
218  edm::InputTag("g4SimHits:TrackerHitsTECHighTof"),
219  edm::InputTag("g4SimHits:TrackerHitsPixelBarrelLowTof"),
220  edm::InputTag("g4SimHits:TrackerHitsPixelBarrelHighTof"),
221  edm::InputTag("g4SimHits:TrackerHitsPixelEndcapLowTof"),
222  edm::InputTag("g4SimHits:TrackerHitsPixelEndcapHighTof"),
223  });
224 
225  desc.add<std::vector<std::string>>("ROUList",
226  {"TrackerHitsPixelBarrelLowTof",
227  "TrackerHitsPixelBarrelHighTof",
228  "TrackerHitsTIBLowTof",
229  "TrackerHitsTIBHighTof",
230  "TrackerHitsTIDLowTof",
231  "TrackerHitsTIDHighTof",
232  "TrackerHitsTOBLowTof",
233  "TrackerHitsTOBHighTof",
234  "TrackerHitsPixelEndcapLowTof",
235  "TrackerHitsPixelEndcapHighTof",
236  "TrackerHitsTECLowTof",
237  "TrackerHitsTECHighTof"});
238 
239  descriptions.add("Phase2OTValidateRecHit", desc);
240 }
241 
242 //define this as a plug-in
Handle.h
PixelSubdetector.h
MessageLogger.h
TrackerGeometry.h
Phase2OTValidateRecHit::Phase2OTValidateRecHit
Phase2OTValidateRecHit(const edm::ParameterSet &)
Definition: Phase2OTValidateRecHit.cc:73
Phase2OTValidateRecHitBase::layerMEs_
std::map< std::string, RecHitME > layerMEs_
Definition: Phase2OTValidateRecHitBase.h:102
ESHandle.h
TrackerGeometry::ModuleType::Ph2SS
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::EDGetTokenT
Definition: EDGetToken.h:33
Phase2OTValidateRecHitBase::tTopo_
const TrackerTopology * tTopo_
Definition: Phase2OTValidateRecHitBase.h:65
edm
HLT enums.
Definition: AlignableModifier.h:19
Phase2OTValidateRecHit::tokenRecHitsOT_
const edm::EDGetTokenT< Phase2TrackerRecHit1DCollectionNew > tokenRecHitsOT_
Definition: Phase2OTValidateRecHit.cc:65
PSimHitContainer.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:197
Phase2OTValidateRecHitBase::fillPSetDescription
static void fillPSetDescription(edm::ParameterSetDescription &desc)
Definition: Phase2OTValidateRecHitBase.cc:254
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
TrackCandidateProducer_cfi.simTracks
simTracks
Definition: TrackCandidateProducer_cfi.py:15
Phase2OTValidateRecHitBase::fillOTRecHitHistos
void fillOTRecHitHistos(const PSimHit *simhitClosest, const Phase2TrackerRecHit1D *rechit, const std::map< unsigned int, SimTrack > &selectedSimTrackMap, std::map< std::string, unsigned int > &nrechitLayerMapP_primary, std::map< std::string, unsigned int > &nrechitLayerMapS_primary)
Definition: Phase2OTValidateRecHitBase.cc:52
TrackerHitAssociator.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
TrackerHitAssociator::Config
Definition: TrackerHitAssociator.h:57
TrackerGeometry::getDetectorType
ModuleType getDetectorType(DetId) const
Definition: TrackerGeometry.cc:247
edm::Handle< edm::PSimHitContainer >
DetId
Definition: DetId.h:17
Phase2OTValidateRecHit::~Phase2OTValidateRecHit
~Phase2OTValidateRecHit() override
Definition: Phase2OTValidateRecHit.cc:87
MakerMacros.h
TrackerTopology.h
PSimHit.h
Phase2OTValidateRecHitBase
Definition: Phase2OTValidateRecHitBase.h:44
Phase2OTValidateRecHit::fillOTHistos
void fillOTHistos(const edm::Event &iEvent, const TrackerHitAssociator &associateRecHit, const std::vector< edm::Handle< edm::PSimHitContainer >> &simHits, const std::map< unsigned int, SimTrack > &selectedSimTrackMap)
Definition: Phase2OTValidateRecHit.cc:115
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
TrackerGeometry::ModuleType
ModuleType
Definition: TrackerGeometry.h:29
Phase2OTValidateRecHitBase.h
TrackerPhase2DQMUtil.h
HI_PhotonSkim_cff.rechits
rechits
Definition: HI_PhotonSkim_cff.py:76
Point3DBase< float, LocalTag >
PixelGeomDetType.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TrackerDigiGeometryRecord.h
Phase2TrackerRecHit1D.h
Phase2OTValidateRecHitBase::tkGeom_
const TrackerGeometry * tkGeom_
Definition: Phase2OTValidateRecHitBase.h:64
Phase2OTValidateRecHit::simTracksToken_
const edm::EDGetTokenT< edm::SimTrackContainer > simTracksToken_
Definition: Phase2OTValidateRecHit.cc:66
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
Phase2OTValidateRecHit
Definition: Phase2OTValidateRecHit.cc:49
TrackerGeomDet.h
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
Phase2OTValidateRecHit::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Phase2OTValidateRecHit.cc:189
PVValHelper::dy
Definition: PVValidationHelpers.h:50
edm::EventSetup
Definition: EventSetup.h:58
Phase2OTValidateRecHit::simHitTokens_
std::vector< edm::EDGetTokenT< edm::PSimHitContainer > > simHitTokens_
Definition: Phase2OTValidateRecHit.cc:67
DetSetVector.h
TrackerGeometry::ModuleType::Ph2PSS
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Phase2OTValidateRecHit::trackerHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: Phase2OTValidateRecHit.cc:63
InputTag.h
TrackerHitAssociator
Definition: TrackerHitAssociator.h:55
GeomDet.h
edmNew::DetSetVector
Definition: DetSetNew.h:13
Phase2OTValidateRecHit::simtrackminpt_
const double simtrackminpt_
Definition: Phase2OTValidateRecHit.cc:64
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::SimTrackContainer
std::vector< SimTrack > SimTrackContainer
Definition: SimTrackContainer.h:12
DetId.h
ESWatcher.h
PixelGeomDetUnit.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Phase2TrackerDigitizerFwd.h
ParameterSet.h
PSimHit
Definition: PSimHit.h:15
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
TrackerHitAssociator::associateHitId
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
Definition: TrackerHitAssociator.cc:332
SimTrackContainer.h
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
PVValHelper::dx
Definition: PVValidationHelpers.h:49
vertexPlots.e4
e4
Definition: vertexPlots.py:64
phase2tkutil::getOTHistoId
std::string getOTHistoId(uint32_t det_id, const TrackerTopology *tTopo)
Definition: TrackerPhase2DQMUtil.cc:25
TrackerGeometry::ModuleType::Ph2PSP
Phase2OTValidateRecHitBase::config_
edm::ParameterSet config_
Definition: Phase2OTValidateRecHitBase.h:60
Phase2OTValidateRecHit::analyze
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: Phase2OTValidateRecHit.cc:96