CMS 3D CMS Logo

Phase2OTMonitorRecHit.cc
Go to the documentation of this file.
1 // Package: Phase2OTMonitorRecHit
2 // Class: Phase2OTMonitorRecHit
3 //
7 //
8 // Author: Suvankar Roy Chowdhury
9 // Date: March 2021
10 //
11 // system include files
12 #include <memory>
13 #include <map>
23 
33 
45 
46 // DQM Histograming
50 
52 
54 public:
56  ~Phase2OTMonitorRecHit() override;
57  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
58  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
59  void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
63  void bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir);
64 
67 
70  const TrackerGeometry* tkGeom_ = nullptr;
71  const TrackerTopology* tTopo_ = nullptr;
72 
78  struct RecHitME {
79  // use TH1D instead of TH1F to avoid stauration at 2^31
80  // above this increments with +1 don't work for float, need double
85 
90  };
91  std::map<std::string, RecHitME> layerMEs_;
92 };
93 
94 //
95 // constructors
96 //
98  : config_(iConfig),
99  tokenRecHitsOT_(consumes<Phase2TrackerRecHit1DCollectionNew>(config_.getParameter<edm::InputTag>("rechitsSrc"))),
101  topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
102  edm::LogInfo("Phase2OTMonitorRecHit") << ">>> Construct Phase2OTMonitorRecHit ";
103 }
104 
105 //
106 // destructor
107 //
109  // do anything here that needs to be done at desctruction time
110  // (e.g. close files, deallocate resources etc.)
111  edm::LogInfo("Phase2OTMonitorRecHit") << ">>> Destroy Phase2OTMonitorRecHit ";
112 }
113 //
114 // -- DQM Begin Run
116  tkGeom_ = &iSetup.getData(geomToken_);
117  tTopo_ = &iSetup.getData(topoToken_);
118  ;
119 }
120 
121 //
122 // -- Analyze
123 //
125  // Get the RecHits Phase2TrackerRecHit1DCollectionNew
126  const auto& rechits = iEvent.getHandle(tokenRecHitsOT_);
127  if (!rechits.isValid())
128  return;
129  std::map<std::string, unsigned int> nrechitLayerMapP;
130  std::map<std::string, unsigned int> nrechitLayerMapS;
131  unsigned long int nTotrechitsinevt = 0;
132  // Loop over modules
134  for (DSViter = rechits->begin(); DSViter != rechits->end(); ++DSViter) {
135  // Get the detector unit's id
136  unsigned int rawid(DSViter->detId());
137  DetId detId(rawid);
138  // Get the geomdet
139  const GeomDetUnit* geomDetunit(tkGeom_->idToDetUnit(detId));
140  if (!geomDetunit)
141  continue;
142  // determine the detector we are in
145  nTotrechitsinevt += DSViter->size();
147  if (nrechitLayerMapP.find(key) == nrechitLayerMapP.end()) {
148  nrechitLayerMapP.insert(std::make_pair(key, DSViter->size()));
149  } else {
150  nrechitLayerMapP[key] += DSViter->size();
151  }
153  if (nrechitLayerMapS.find(key) == nrechitLayerMapS.end()) {
154  nrechitLayerMapS.insert(std::make_pair(key, DSViter->size()));
155  } else {
156  nrechitLayerMapS[key] += DSViter->size();
157  }
158  }
160  //loop over rechits for a single detId
161  for (rechitIt = DSViter->begin(); rechitIt != DSViter->end(); ++rechitIt) {
162  LocalPoint lp = rechitIt->localPosition();
163  Global3DPoint globalPos = geomDetunit->surface().toGlobal(lp);
164  //in mm
165  double gx = globalPos.x() * 10.;
166  double gy = globalPos.y() * 10.;
167  double gz = globalPos.z() * 10.;
168  double gr = globalPos.perp() * 10.;
169  //Fill positions
171  globalXY_P_->Fill(gx, gy);
172  globalRZ_P_->Fill(gz, gr);
173  //layer wise histo
174  layerMEs_[key].clusterSize_P->Fill(rechitIt->cluster()->size());
175  //layerMEs_[key].globalPosXY_P->Fill(gx, gy);
176  layerMEs_[key].localPosXY_P->Fill(lp.x(), lp.y());
178  globalXY_S_->Fill(gx, gy);
179  globalRZ_S_->Fill(gz, gr);
180  //layer wise histo
181  layerMEs_[key].clusterSize_S->Fill(rechitIt->cluster()->size());
182  //layerMEs_[key].globalPosXY_S->Fill(gx, gy);
183  layerMEs_[key].localPosXY_S->Fill(lp.x(), lp.y());
184  }
185  } //end loop over rechits of a detId
186  } //End loop over DetSetVector
187 
188  //fill nRecHits per event
189  numberRecHits_->Fill(nTotrechitsinevt);
190  //fill nRecHit counter per layer
191  for (auto& lme : nrechitLayerMapP) {
192  layerMEs_[lme.first].numberRecHits_P->Fill(lme.second);
193  }
194  for (auto& lme : nrechitLayerMapS) {
195  layerMEs_[lme.first].numberRecHits_S->Fill(lme.second);
196  }
197 }
198 //
199 // -- Book Histograms
200 //
202  edm::Run const& iRun,
203  edm::EventSetup const& iSetup) {
204  std::string top_folder = config_.getParameter<std::string>("TopFolderName");
205  //std::stringstream folder_name;
206 
207  ibooker.cd();
208  edm::LogInfo("Phase2OTMonitorRecHit") << " Booking Histograms in : " << top_folder;
209  ibooker.setCurrentFolder(top_folder);
210 
211  //Global histos for OT
213 
215 
217 
219 
221 
222  //Now book layer wise histos
223  edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
224  if (theTkDigiGeomWatcher.check(iSetup)) {
225  for (auto const& det_u : tkGeom_->detUnits()) {
226  //Always check TrackerNumberingBuilder before changing this part
227  if (det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
228  det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC)
229  continue;
230  unsigned int detId_raw = det_u->geographicalId().rawId();
231  bookLayerHistos(ibooker, detId_raw, top_folder);
232  }
233  }
234 }
235 
236 //
237 // -- Book Layer Histograms
238 //
239 void Phase2OTMonitorRecHit::bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir) {
241  if (layerMEs_.find(key) == layerMEs_.end()) {
242  ibooker.cd();
243  RecHitME local_histos;
244  ibooker.setCurrentFolder(subdir + "/" + key);
245  edm::LogInfo("Phase2OTMonitorRecHit") << " Booking Histograms in : " << key;
246 
248  local_histos.numberRecHits_P =
250 
251  local_histos.clusterSize_P =
253 
254  local_histos.globalPosXY_P =
255  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer_P"), ibooker);
256 
257  local_histos.localPosXY_P =
258  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_P"), ibooker);
259 
260  } //if block for P
261 
262  ibooker.setCurrentFolder(subdir + "/" + key);
263  local_histos.numberRecHits_S =
265  local_histos.clusterSize_S =
267  local_histos.localPosXY_S =
268  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_S"), ibooker);
269 
270  layerMEs_.insert(std::make_pair(key, local_histos));
271  }
272 }
273 
277  // rechitMonitorOT
279  {
281  psd0.add<std::string>("name", "NumberOfRecHits");
282  psd0.add<std::string>("title", ";Number of rechits per event;");
283  psd0.add<double>("xmin", 0.0);
284  psd0.add<bool>("switch", true);
285  psd0.add<double>("xmax", 000.0);
286  psd0.add<int>("NxBins", 150);
287  desc.add<edm::ParameterSetDescription>("GlobalNRecHits", psd0);
288  }
289  {
291  psd0.add<std::string>("name", "Global_RecHitPosition_XY_P");
292  psd0.add<std::string>("title", "Global_RecHitPosition_XY_P;x [mm];y [mm];");
293  psd0.add<int>("NxBins", 1250);
294  psd0.add<double>("xmin", -1250.0);
295  psd0.add<double>("xmax", 1250.0);
296  psd0.add<int>("NyBins", 1250);
297  psd0.add<double>("ymin", -1250.0);
298  psd0.add<double>("ymax", 1250.0);
299  psd0.add<bool>("switch", true);
300  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_P", psd0);
301  }
302  {
304  psd0.add<std::string>("name", "Global_RecHitPosition_XY_S");
305  psd0.add<std::string>("title", "Global_RecHitPosition_XY_S;x [mm];y [mm];");
306  psd0.add<int>("NxBins", 1250);
307  psd0.add<double>("xmin", -1250.0);
308  psd0.add<double>("xmax", 1250.0);
309  psd0.add<int>("NyBins", 1250);
310  psd0.add<double>("ymin", -1250.0);
311  psd0.add<double>("ymax", 1250.0);
312  psd0.add<bool>("switch", true);
313  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_S", psd0);
314  }
315 
316  {
318  psd0.add<std::string>("name", "Global_RecHitPosition_RZ_P");
319  psd0.add<std::string>("title", "Global_RecHitPosition_RZ_P;z [mm];r [mm]");
320  psd0.add<int>("NxBins", 1500);
321  psd0.add<double>("xmin", -3000.0);
322  psd0.add<double>("xmax", 3000.0);
323  psd0.add<int>("NyBins", 1250);
324  psd0.add<double>("ymin", 0.0);
325  psd0.add<double>("ymax", 1250.0);
326  psd0.add<bool>("switch", true);
327  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_P", psd0);
328  }
329  {
331  psd0.add<std::string>("name", "Global_RecHitPosition_RZ_S");
332  psd0.add<std::string>("title", "Global_RecHitPosition_RZ_S;z [mm];r [mm]");
333 
334  psd0.add<int>("NxBins", 1500);
335  psd0.add<double>("xmin", -3000.0);
336  psd0.add<double>("xmax", 3000.0);
337  psd0.add<int>("NyBins", 1250);
338  psd0.add<double>("ymin", 0.0);
339  psd0.add<double>("ymax", 1250.0);
340  psd0.add<bool>("switch", true);
341  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_S", psd0);
342  }
343  //Layer wise parameter
344  {
346  psd0.add<std::string>("name", "NumberOfRecHitsLayerP");
347  psd0.add<std::string>("title", ";Number of clusters per event(macro pixel sensor);");
348  psd0.add<double>("xmin", 0.0);
349  psd0.add<double>("xmax", 28000.0);
350  psd0.add<int>("NxBins", 150);
351  psd0.add<bool>("switch", true);
352  desc.add<edm::ParameterSetDescription>("NRecHitsLayer_P", psd0);
353  }
354 
355  {
357  psd0.add<std::string>("name", "NumberOfRecHitsLayerS");
358  psd0.add<std::string>("title", ";Number of clusters per event(strip sensor);");
359  psd0.add<double>("xmin", 0.0);
360  psd0.add<double>("xmax", 28000.0);
361  psd0.add<int>("NxBins", 150);
362  psd0.add<bool>("switch", true);
363  desc.add<edm::ParameterSetDescription>("NRecHitsLayer_S", psd0);
364  }
365 
366  {
368  psd0.add<std::string>("name", "ClusterSize_P");
369  psd0.add<std::string>("title", ";cluster size(macro pixel sensor);");
370  psd0.add<double>("xmin", -0.5);
371  psd0.add<double>("xmax", 30.5);
372  psd0.add<int>("NxBins", 31);
373  psd0.add<bool>("switch", true);
374  desc.add<edm::ParameterSetDescription>("ClusterSize_P", psd0);
375  }
376  {
378  psd0.add<std::string>("name", "ClusterSize_S");
379  psd0.add<std::string>("title", ";cluster size(strip sensor);");
380  psd0.add<double>("xmin", -0.5);
381  psd0.add<double>("xmax", 30.5);
382  psd0.add<int>("NxBins", 31);
383  psd0.add<bool>("switch", true);
384  desc.add<edm::ParameterSetDescription>("ClusterSize_S", psd0);
385  }
386  {
388  psd0.add<std::string>("name", "GlobalPositionXY_perlayer_P");
389  psd0.add<std::string>("title", "GlobalRecHitPositionXY_perlayer_P;x[mm];y[mm];");
390  psd0.add<int>("NxBins", 1250);
391  psd0.add<double>("xmin", -1250.0);
392  psd0.add<double>("xmax", 1250.0);
393  psd0.add<int>("NyBins", 1250);
394  psd0.add<double>("ymin", -1250.0);
395  psd0.add<double>("ymax", 1250.0);
396  psd0.add<bool>("switch", true);
397  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_P", psd0);
398  }
399  {
401  psd0.add<std::string>("name", "GlobalPositionXY_perlayer_S");
402  psd0.add<std::string>("title", "GlobalRecHitPositionXY_perlayer_S;x[mm];y[mm];");
403  psd0.add<int>("NxBins", 1250);
404  psd0.add<double>("xmin", -1250.0);
405  psd0.add<double>("xmax", 1250.0);
406  psd0.add<int>("NyBins", 1250);
407  psd0.add<double>("ymin", -1250.0);
408  psd0.add<double>("ymax", 1250.0);
409  psd0.add<bool>("switch", true);
410  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_S", psd0);
411  }
412  {
414  psd0.add<std::string>("name", "LocalPositionXY_P");
415  psd0.add<std::string>("title", "LocalPositionXY_P;x ;y ;");
416  psd0.add<int>("NxBins", 50);
417  psd0.add<double>("xmin", -10.0);
418  psd0.add<double>("xmax", 10.0);
419  psd0.add<int>("NyBins", 50);
420  psd0.add<double>("ymin", -10.0);
421  psd0.add<double>("ymax", 10.0);
422  psd0.add<bool>("switch", true);
423  desc.add<edm::ParameterSetDescription>("LocalPositionXY_P", psd0);
424  }
425  {
427  psd0.add<std::string>("name", "LocalPositionXY_S");
428  psd0.add<std::string>("title", "LocalPositionXY_S;x ;y ;");
429  psd0.add<int>("NxBins", 50);
430  psd0.add<double>("xmin", -10.0);
431  psd0.add<double>("xmax", 10.0);
432  psd0.add<int>("NyBins", 50);
433  psd0.add<double>("ymin", -10.0);
434  psd0.add<double>("ymax", 10.0);
435  psd0.add<bool>("switch", true);
436  desc.add<edm::ParameterSetDescription>("LocalPositionXY_S", psd0);
437  }
438  desc.add<std::string>("TopFolderName", "TrackerPhase2OTRecHit");
439  desc.add<bool>("Verbosity", false);
440  desc.add<edm::InputTag>("rechitsSrc", edm::InputTag("siPhase2RecHits"));
441  descriptions.add("Phase2OTMonitorRecHit", desc);
442  // or use the following to generate the label from the module's C++ type
443  //descriptions.addWithDefaultLabel(desc);
444 }
445 
446 //define this as a plug-in
const edm::EDGetTokenT< Phase2TrackerRecHit1DCollectionNew > tokenRecHitsOT_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T perp() const
Definition: PV3DBase.h:69
MonitorElement * book2DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const TrackerTopology * tTopo_
std::map< std::string, RecHitME > layerMEs_
MonitorElement * numberRecHits_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T z() const
Definition: PV3DBase.h:61
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
data_type const * const_iterator
Definition: DetSetNew.h:31
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
const TrackerGeometry * tkGeom_
void Fill(long long x)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
Phase2OTMonitorRecHit(const edm::ParameterSet &)
std::string getOTHistoId(uint32_t det_id, const TrackerTopology *tTopo)
ModuleType getDetectorType(DetId) const
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
void bookLayerHistos(DQMStore::IBooker &ibooker, unsigned int det_id, std::string &subdir)
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool getData(T &iHolder) const
Definition: EventSetup.h:122
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MonitorElement * book1DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
size_type size() const
Definition: DetSetNew.h:68
HLT enums.
iterator end()
Definition: DetSetNew.h:56
Definition: Run.h:45
iterator begin()
Definition: DetSetNew.h:54