CMS 3D CMS Logo

Phase2ITMonitorRecHit.cc
Go to the documentation of this file.
1 // Package: Phase2ITMonitorRecHit
2 // Class: Phase2ITMonitorRecHit
3 //
7 //
8 // Author: Shubhi Parolia, Suvankar Roy Chowdhury
9 // Date: July 2020
10 #include <memory>
11 #include <map>
12 #include <vector>
13 #include <algorithm>
40 // DQM Histograming
44 
46 public:
48  ~Phase2ITMonitorRecHit() override;
49  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
50  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
51  void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void fillITHistos(const edm::Event& iEvent);
56  void bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir);
57 
63  const TrackerGeometry* tkGeom_ = nullptr;
64  const TrackerTopology* tTopo_ = nullptr;
65  static constexpr float million = 1e6;
71 
72  struct RecHitME {
77  MonitorElement* posX = nullptr;
78  MonitorElement* posY = nullptr;
79  MonitorElement* poserrX = nullptr;
80  MonitorElement* poserrY = nullptr;
83  };
84  std::map<std::string, RecHitME> layerMEs_;
85 };
87 
89  : config_(iConfig),
90  tokenRecHitsIT_(consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("rechitsSrc"))),
92  topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
93  edm::LogInfo("Phase2ITMonitorRecHit") << ">>> Construct Phase2ITMonitorRecHit ";
94 }
95 
97  edm::LogInfo("Phase2ITMonitorRecHit") << ">>> Destroy Phase2ITMonitorRecHit ";
98 }
99 // -- Analyze
101 
103  // Get the RecHits
104  const auto& rechits = iEvent.getHandle(tokenRecHitsIT_);
105  if (!rechits.isValid())
106  return;
107  std::map<std::string, unsigned int> nrechitLayerMap;
108  unsigned long int nTotrechitsinevt = 0;
109  // Loop over modules
110  for (const auto& DSViter : *rechits) {
111  // Get the detector id
112  unsigned int rawid(DSViter.detId());
113  DetId detId(rawid);
114  // Get the geomdet
115  const GeomDetUnit* geomDetunit(tkGeom_->idToDetUnit(detId));
116  if (!geomDetunit)
117  continue;
119  nTotrechitsinevt += DSViter.size();
120  auto counterDet = nrechitLayerMap.find(key);
121  if (nrechitLayerMap.find(key) == nrechitLayerMap.end()) {
122  nrechitLayerMap.emplace(key, DSViter.size());
123  } else
124  counterDet->second += DSViter.size();
125 
126  //loop over rechits for a single detId
127  for (const auto& rechit : DSViter) {
128  LocalPoint lp = rechit.localPosition();
129  Global3DPoint globalPos = geomDetunit->surface().toGlobal(lp);
130  //in mm
131  double gx = globalPos.x() * 10.;
132  double gy = globalPos.y() * 10.;
133  double gz = globalPos.z() * 10.;
134  double gr = globalPos.perp() * 10.;
135  //Fill global positions
136  if (geomDetunit->subDetector() == GeomDetEnumerators::SubDetector::P2PXB) {
137  globalXY_barrel_->Fill(gx, gy);
138  globalRZ_barrel_->Fill(gz, gr);
139  } else if (geomDetunit->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC) {
140  globalXY_endcap_->Fill(gx, gy);
141  globalRZ_endcap_->Fill(gz, gr);
142  }
143  //layer wise histo
144  if (layerMEs_[key].clusterSizeX)
145  layerMEs_[key].clusterSizeX->Fill(rechit.cluster()->sizeX());
146  if (layerMEs_[key].clusterSizeY)
147  layerMEs_[key].clusterSizeY->Fill(rechit.cluster()->sizeY());
148  if (layerMEs_[key].globalPosXY)
149  layerMEs_[key].globalPosXY->Fill(gx, gy);
150  if (layerMEs_[key].globalPosRZ)
151  layerMEs_[key].globalPosRZ->Fill(gz, gr);
152  if (layerMEs_[key].localPosXY)
153  layerMEs_[key].localPosXY->Fill(lp.x(), lp.y());
154  if (layerMEs_[key].posX)
155  layerMEs_[key].posX->Fill(lp.x());
156  if (layerMEs_[key].posY)
157  layerMEs_[key].posY->Fill(lp.y());
158  float eta = geomDetunit->surface().toGlobal(lp).eta();
159  if (layerMEs_[key].poserrX)
160  layerMEs_[key].poserrX->Fill(eta, million * rechit.localPositionError().xx());
161  if (layerMEs_[key].poserrY)
162  layerMEs_[key].poserrY->Fill(eta, million * rechit.localPositionError().yy());
163  } //end loop over rechits of a detId
164  } //End loop over DetSetVector
165 
166  //fill nRecHits per event
167  numberRecHits_->Fill(nTotrechitsinevt);
168  //fill nRecHit counter per layer
169  for (const auto& lme : nrechitLayerMap)
170  if (layerMEs_[lme.first].numberRecHits)
171  layerMEs_[lme.first].numberRecHits->Fill(lme.second);
172 }
173 
175  tkGeom_ = &iSetup.getData(geomToken_);
176  tTopo_ = &iSetup.getData(topoToken_);
177 }
178 
180  edm::Run const& iRun,
181  edm::EventSetup const& iSetup) {
182  std::string top_folder = config_.getParameter<std::string>("TopFolderName");
183  ibooker.cd();
184  edm::LogInfo("Phase2ITMonitorRecHit") << " Booking Histograms in : " << top_folder;
185  std::string dir = top_folder;
186  ibooker.setCurrentFolder(dir);
187  //Global histos for IT
189  phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalNumberRecHits"), ibooker);
190 
192  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXB"), ibooker);
193 
195  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXB"), ibooker);
196 
198  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXEC"), ibooker);
199 
201  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXEC"), ibooker);
202 
203  //Now book layer wise histos
204  edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
205  if (theTkDigiGeomWatcher.check(iSetup)) {
206  for (auto const& det_u : tkGeom_->detUnits()) {
207  //Always check TrackerNumberingBuilder before changing this part
208  if (!(det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
209  det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
210  continue;
211  unsigned int detId_raw = det_u->geographicalId().rawId();
212  edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
213  << "\t key=" << phase2tkutil::getITHistoId(detId_raw, tTopo_) << std::endl;
214  bookLayerHistos(ibooker, detId_raw, dir);
215  }
216  }
217 }
218 // -- Book Layer Histograms
219 void Phase2ITMonitorRecHit::bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir) {
221  if (key.empty())
222  return;
223  if (layerMEs_.find(key) == layerMEs_.end()) {
224  ibooker.cd();
225  RecHitME local_histos;
226  ibooker.setCurrentFolder(subdir + "/" + key);
227  edm::LogInfo("Phase2ITMonitorRecHit") << " Booking Histograms in : " << (subdir + "/" + key);
228 
229  local_histos.numberRecHits =
230  phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("LocalNumberRecHits"), ibooker);
231 
232  local_histos.posX = phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("RecHitPosX"), ibooker);
233 
234  local_histos.posY = phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("RecHitPosY"), ibooker);
235 
236  local_histos.poserrX =
238 
239  local_histos.poserrY =
241 
242  local_histos.clusterSizeX =
243  phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("LocalClusterSizeX"), ibooker);
244 
245  local_histos.clusterSizeY =
246  phase2tkutil::book1DFromPSet(config_.getParameter<edm::ParameterSet>("LocalClusterSizeY"), ibooker);
247 
248  local_histos.globalPosXY =
249  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer"), ibooker);
250 
251  local_histos.globalPosRZ =
252  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_perlayer"), ibooker);
253 
254  local_histos.localPosXY =
256  layerMEs_.emplace(key, local_histos);
257  }
258 }
259 
261  // rechitMonitorIT
263  {
265  psd0.add<std::string>("name", "NumberRecHits");
266  psd0.add<std::string>("title", "NumberRecHits;Number of RecHits;");
267  psd0.add<double>("xmin", 0.0);
268  psd0.add<bool>("switch", true);
269  psd0.add<double>("xmax", 250000.0);
270  psd0.add<int>("NxBins", 250);
271  desc.add<edm::ParameterSetDescription>("GlobalNumberRecHits", psd0);
272  }
273  {
275  psd0.add<std::string>("name", "Global_Position_RZ_IT_barrel");
276  psd0.add<std::string>("title", "Global_Position_RZ_IT_barrel;z [mm];r [mm]");
277  psd0.add<double>("ymax", 300.0);
278  psd0.add<int>("NxBins", 1500);
279  psd0.add<int>("NyBins", 300);
280  psd0.add<bool>("switch", true);
281  psd0.add<double>("xmax", 3000.0);
282  psd0.add<double>("xmin", -3000.0);
283  psd0.add<double>("ymin", 0.0);
284  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXB", psd0);
285  }
286  {
288  psd0.add<std::string>("name", "Global_Position_XY_IT_barrel");
289  psd0.add<std::string>("title", "Global_Position_XY_IT_barrel;x [mm];y [mm];");
290  psd0.add<double>("ymax", 300.0);
291  psd0.add<int>("NxBins", 600);
292  psd0.add<int>("NyBins", 600);
293  psd0.add<bool>("switch", true);
294  psd0.add<double>("xmax", 300.0);
295  psd0.add<double>("xmin", -300.0);
296  psd0.add<double>("ymin", -300.0);
297  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXB", psd0);
298  }
299  {
301  psd0.add<std::string>("name", "Global_Position_RZ_IT_endcap");
302  psd0.add<std::string>("title", "Global_Position_RZ_IT_endcap;z [mm];r [mm]");
303  psd0.add<double>("ymax", 300.0);
304  psd0.add<int>("NxBins", 1500);
305  psd0.add<int>("NyBins", 300);
306  psd0.add<bool>("switch", true);
307  psd0.add<double>("xmax", 3000.0);
308  psd0.add<double>("xmin", -3000.0);
309  psd0.add<double>("ymin", 0.0);
310  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXEC", psd0);
311  }
312  {
314  psd0.add<std::string>("name", "Global_Position_XY_IT_endcap");
315  psd0.add<std::string>("title", "Global_Position_XY_IT_endcap; x [mm]; y [mm]");
316  psd0.add<double>("ymax", 300.0);
317  psd0.add<int>("NxBins", 600);
318  psd0.add<int>("NyBins", 600);
319  psd0.add<bool>("switch", true);
320  psd0.add<double>("xmax", 300.0);
321  psd0.add<double>("xmin", -300.0);
322  psd0.add<double>("ymin", -300.0);
323  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXEC", psd0);
324  }
325  //Per layer/ring histos
326  {
328  psd0.add<std::string>("name", "LocalNumberRecHits");
329  psd0.add<std::string>("title", "NumberRecHits;Number of RecHits;");
330  psd0.add<double>("xmin", 0.0);
331  psd0.add<bool>("switch", true);
332  psd0.add<double>("xmax", 150000.0);
333  psd0.add<int>("NxBins", 150);
334  desc.add<edm::ParameterSetDescription>("LocalNumberRecHits", psd0);
335  }
336  {
338  psd0.add<std::string>("name", "Global_Position_RZ");
339  psd0.add<std::string>("title", "Global_Position_RZ;z [mm];r [mm]");
340  psd0.add<double>("ymax", 300.0);
341  psd0.add<int>("NxBins", 1500);
342  psd0.add<int>("NyBins", 300);
343  psd0.add<bool>("switch", false);
344  psd0.add<double>("xmax", 3000.0);
345  psd0.add<double>("xmin", -3000.0);
346  psd0.add<double>("ymin", 0.0);
347  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_perlayer", psd0);
348  }
349  {
351  psd0.add<std::string>("name", "Global_Position_XY");
352  psd0.add<std::string>("title", "Global_Position_XY;x [mm]; y[mm]");
353  psd0.add<double>("ymax", 300.0);
354  psd0.add<int>("NxBins", 600);
355  psd0.add<int>("NyBins", 600);
356  psd0.add<bool>("switch", false);
357  psd0.add<double>("xmax", 300.0);
358  psd0.add<double>("xmin", -300.0);
359  psd0.add<double>("ymin", -300.0);
360  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer", psd0);
361  }
362  {
364  psd0.add<std::string>("name", "Local_Position_XY");
365  psd0.add<std::string>("title", "Local_Position_XY; x; y");
366  psd0.add<double>("ymax", 0.0);
367  psd0.add<int>("NxBins", 500);
368  psd0.add<int>("NyBins", 500);
369  psd0.add<bool>("switch", true);
370  psd0.add<double>("xmax", 0.0);
371  psd0.add<double>("xmin", 0.0);
372  psd0.add<double>("ymin", 0.0);
373  desc.add<edm::ParameterSetDescription>("LocalPositionXY", psd0);
374  }
375  {
377  psd0.add<std::string>("name", "Cluster_SizeX");
378  psd0.add<std::string>("title", "Cluster_SizeX; cluster size x;");
379  psd0.add<double>("xmin", -0.5);
380  psd0.add<bool>("switch", true);
381  psd0.add<double>("xmax", 20.5);
382  psd0.add<int>("NxBins", 21);
383  desc.add<edm::ParameterSetDescription>("LocalClusterSizeX", psd0);
384  }
385  {
387  psd0.add<std::string>("name", "Cluster_SizeY");
388  psd0.add<std::string>("title", "Cluster_SizeY;cluster size y;");
389  psd0.add<double>("xmin", -0.5);
390  psd0.add<bool>("switch", true);
391  psd0.add<double>("xmax", 25.5);
392  psd0.add<int>("NxBins", 26);
393  desc.add<edm::ParameterSetDescription>("LocalClusterSizeY", psd0);
394  }
395  {
397  psd0.add<std::string>("name", "RecHit_X");
398  psd0.add<std::string>("title", "RecHit_X;RecHit position X dimension;");
399  psd0.add<double>("xmin", -2.5);
400  psd0.add<bool>("switch", true);
401  psd0.add<double>("xmax", 2.5);
402  psd0.add<int>("NxBins", 100);
403  desc.add<edm::ParameterSetDescription>("RecHitPosX", psd0);
404  }
405  {
407  psd0.add<std::string>("name", "RecHit_Y");
408  psd0.add<std::string>("title", "RecHit_Y;RecHit position X dimension;");
409  psd0.add<double>("xmin", -2.5);
410  psd0.add<bool>("switch", true);
411  psd0.add<double>("xmax", 2.5);
412  psd0.add<int>("NxBins", 100);
413  desc.add<edm::ParameterSetDescription>("RecHitPosY", psd0);
414  }
415  {
417  psd0.add<std::string>("name", "RecHit_X_error_Vs_eta");
418  psd0.add<std::string>("title", "RecHit_X_error_Vs_eta;#eta;x error [#mum]");
419  psd0.add<bool>("switch", true);
420  psd0.add<int>("NxBins", 82);
421  psd0.add<double>("xmax", 4.1);
422  psd0.add<double>("xmin", -4.1);
423  psd0.add<double>("ymax", 10.0);
424  psd0.add<double>("ymin", 0.);
425  desc.add<edm::ParameterSetDescription>("RecHitPosErrorX_Eta", psd0);
426  }
427  {
429  psd0.add<std::string>("name", "RecHit_Y_error_Vs_eta");
430  psd0.add<std::string>("title", "RecHit_Y_error_Vs_eta;#eta;y error [#mum]");
431  psd0.add<bool>("switch", true);
432  psd0.add<int>("NxBins", 82);
433  psd0.add<double>("xmax", 4.1);
434  psd0.add<double>("xmin", -4.1);
435  psd0.add<double>("ymax", 10.0);
436  psd0.add<double>("ymin", 0.);
437  desc.add<edm::ParameterSetDescription>("RecHitPosErrorY_Eta", psd0);
438  }
439  desc.add<std::string>("TopFolderName", "TrackerPhase2ITRecHit");
440  desc.add<edm::InputTag>("rechitsSrc", edm::InputTag("siPixelRecHits"));
441  descriptions.add("Phase2ITMonitorRecHit", desc);
442 }
443 //define this as a plug-in
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
const TrackerGeometry * tkGeom_
const edm::EDGetTokenT< SiPixelRecHitCollection > tokenRecHitsIT_
MonitorElement * globalRZ_barrel_
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)
Phase2ITMonitorRecHit(const edm::ParameterSet &)
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T z() const
Definition: PV3DBase.h:61
MonitorElement * bookProfile1DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static constexpr float million
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
std::string getITHistoId(uint32_t det_id, const TrackerTopology *tTopo)
MonitorElement * globalXY_barrel_
void Fill(long long x)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
MonitorElement * numberRecHits_
int iEvent
Definition: GenABIO.cc:224
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
Transition
Definition: Transition.h:12
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
void bookLayerHistos(DQMStore::IBooker &ibooker, unsigned int det_id, std::string &subdir)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::map< std::string, RecHitME > layerMEs_
HLT enums.
const TrackerTopology * tTopo_
void fillITHistos(const edm::Event &iEvent)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
MonitorElement * globalRZ_endcap_
MonitorElement * globalXY_endcap_
Definition: Run.h:45