CMS 3D CMS Logo

Phase2OTMonitorVectorHits.cc
Go to the documentation of this file.
1 
4 //
5 // Author: Gourab Saha, Suvankar Roy Chowdhury
6 //
7 // system include files
8 #include <memory>
9 #include <map>
19 
24 
36 
37 // DQM Histograming
41 
43 
45 public:
47  ~Phase2OTMonitorVectorHits() override;
48  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
49  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
50  void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir);
55 
58 
62 
63  const TrackerGeometry* tkGeom_ = nullptr;
64  const TrackerTopology* tTopo_ = nullptr;
65  const MagneticField* magField_ = nullptr;
66 
72  struct VecHitME {
83  MonitorElement* phi_P = nullptr;
84  MonitorElement* phi_S = nullptr;
85  MonitorElement* eta_P = nullptr;
86  MonitorElement* eta_S = nullptr;
87  MonitorElement* pt_P = nullptr;
88  MonitorElement* pt_S = nullptr;
89  MonitorElement* chi2_P = nullptr;
90  MonitorElement* chi2_S = nullptr;
91  };
92  std::map<std::string, VecHitME> layerMEs_;
93 };
94 
95 //
96 // constructors
97 //
99  : config_(iConfig),
100  tokenVecHitsOT_(consumes<VectorHitCollection>(config_.getParameter<edm::InputTag>("vechitsSrc"))),
102  topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
103  magFieldToken_(esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>()) {
104  edm::LogInfo("Phase2OTMonitorVectorHits") << ">>> Construct Phase2OTMonitorVectorHits ";
105 }
106 
107 //
108 // destructor
109 //
111  // do anything here that needs to be done at desctruction time
112  // (e.g. close files, deallocate resources etc.)
113  edm::LogInfo("Phase2OTMonitorVectorHits") << ">>> Destroy Phase2OTMonitorVectorHits ";
114 }
115 //
116 // -- DQM Begin Run
118  tkGeom_ = &iSetup.getData(geomToken_);
119  tTopo_ = &iSetup.getData(topoToken_);
120  magField_ = &iSetup.getData(magFieldToken_);
121 }
122 
123 //
124 // -- Analyze
125 //
127  // Get the VecHits
128  const auto& vechits = iEvent.getHandle(tokenVecHitsOT_);
129  if (!vechits.isValid())
130  return;
131  std::map<std::string, unsigned int> nvechitLayerMapP;
132  std::map<std::string, unsigned int> nvechitLayerMapS;
133  unsigned long int nTotvechitsinevt = 0;
134  // Loop over modules
136  for (DSViter = vechits->begin(); DSViter != vechits->end(); ++DSViter) {
137  // Get the detector unit's id
138  unsigned int rawid(DSViter->detId());
139  DetId detId(rawid);
142  continue;
144  nTotvechitsinevt += DSViter->size();
146  if (nvechitLayerMapP.find(key) == nvechitLayerMapP.end()) {
147  nvechitLayerMapP.insert(std::make_pair(key, DSViter->size()));
148  } else {
149  nvechitLayerMapP[key] += DSViter->size();
150  }
151  } else if (mType == TrackerGeometry::ModuleType::Ph2SS) {
152  if (nvechitLayerMapS.find(key) == nvechitLayerMapS.end()) {
153  nvechitLayerMapS.insert(std::make_pair(key, DSViter->size()));
154  } else {
155  nvechitLayerMapS[key] += DSViter->size();
156  }
157  }
158 
160  for (vechitIt = DSViter->begin(); vechitIt != DSViter->end(); ++vechitIt) {
161  const Global3DPoint globalPos = vechitIt->lowerGlobalPos();
162  const LocalPoint lp = vechitIt->localPosition();
163  const double gx = globalPos.x() * 10.;
164  const double gy = globalPos.y() * 10.;
165  const double gz = globalPos.z() * 10.;
166  const double gr = globalPos.perp() * 10.;
167  const Global3DVector globalVec = vechitIt->globalDirection();
168  const float curvature = vechitIt->curvature();
169  const float curverr = vechitIt->curvatureError();
170  const float eta = globalVec.eta();
171  const float phi = globalVec.phi();
172  float QOverPT = vechitIt->transverseMomentum(magField_->inTesla(GlobalPoint(0., 0., 0.)).z());
173  const int sign = QOverPT > 0. ? 1. : -1.;
175  globalXY_P_->Fill(gx, gy);
176  globalRZ_P_->Fill(gz, gr);
177  //layer wise histo
178  layerMEs_[key].localPosXY_P->Fill(lp.x(), lp.y());
179  layerMEs_[key].curvature_P->Fill(curvature);
180  if (curvature != 0.f)
181  layerMEs_[key].curvErr_P->Fill(curverr / curvature);
182  else
183  edm::LogError("Phase2OTMonitorVectorHits") << "VectorHit with curvature zero found";
184  layerMEs_[key].phi_P->Fill(phi);
185  layerMEs_[key].eta_P->Fill(eta);
186  layerMEs_[key].pt_P->Fill(sign * QOverPT);
187  layerMEs_[key].chi2_P->Fill(vechitIt->chi2());
188  layerMEs_[key].curvatureVsEta_P->Fill(eta, curvature);
189  } else if (mType == TrackerGeometry::ModuleType::Ph2SS) {
190  globalXY_S_->Fill(gx, gy);
191  globalRZ_S_->Fill(gz, gr);
192  //layer wise histo
193  layerMEs_[key].localPosXY_S->Fill(lp.x(), lp.y());
194  layerMEs_[key].curvature_S->Fill(curvature);
195  if (curvature != 0.f)
196  layerMEs_[key].curvErr_S->Fill(curverr / curvature);
197  else
198  edm::LogError("Phase2OTMonitorVectorHits") << "VectorHit with curvature zero found";
199  layerMEs_[key].phi_S->Fill(phi);
200  layerMEs_[key].eta_S->Fill(eta);
201  layerMEs_[key].pt_S->Fill(sign * QOverPT);
202  layerMEs_[key].chi2_S->Fill(vechitIt->chi2());
203  layerMEs_[key].curvatureVsEta_S->Fill(eta, curvature);
204  }
205  }
206  }
207  //fill nVecHits per event
208  numberVecHits_->Fill(nTotvechitsinevt);
209  //fill nVecHit counter per layer
210  for (auto& lme : nvechitLayerMapP) {
211  layerMEs_[lme.first].numberVecHits_P->Fill(lme.second);
212  }
213  for (auto& lme : nvechitLayerMapS) {
214  layerMEs_[lme.first].numberVecHits_S->Fill(lme.second);
215  }
216 }
217 //
218 // -- Book Histograms
219 //
221  edm::Run const& iRun,
222  edm::EventSetup const& iSetup) {
223  std::string top_folder = config_.getParameter<std::string>("TopFolderName");
224  //std::stringstream folder_name;
225 
226  ibooker.cd();
227  edm::LogInfo("Phase2OTMonitorVectorHits") << " Booking Histograms in : " << top_folder;
228  ibooker.setCurrentFolder(top_folder);
229 
230  //Global histos for OT
232 
234 
236 
238 
240 
241  //Now book layer wise histos
242  edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
243  if (theTkDigiGeomWatcher.check(iSetup)) {
244  for (auto const& det_u : tkGeom_->detUnits()) {
245  unsigned int detId_raw = det_u->geographicalId().rawId();
246  //we only need the layerwise histos for the lower layer (?)
249  continue;
250  bookLayerHistos(ibooker, detId_raw, top_folder);
251  }
252  }
253 }
254 
255 //
256 // -- Book Layer Histograms
257 //
260  if (layerMEs_.find(key) == layerMEs_.end()) {
261  ibooker.cd();
262  VecHitME local_histos;
263  ibooker.setCurrentFolder(subdir + "/" + key);
264  edm::LogInfo("Phase2OTMonitorVectorHits") << " Booking Histograms in : " << key;
265  //either PSP or SS - ensured by the call from bookHisto
267  local_histos.numberVecHits_P =
269  local_histos.localPosXY_P =
270  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_P"), ibooker);
271  local_histos.curvature_P =
273  local_histos.curvErr_P =
279  local_histos.curvatureVsEta_P =
281  } else {
282  ibooker.setCurrentFolder(subdir + "/" + key);
283  local_histos.numberVecHits_S =
285  local_histos.localPosXY_S =
286  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_S"), ibooker);
287  local_histos.curvature_S =
289  local_histos.curvErr_S =
295  local_histos.curvatureVsEta_S =
297  }
298  layerMEs_.insert(std::make_pair(key, local_histos));
299  }
300 }
301 
305  // vechitMonitorOT
307  {
309  psd0.add<std::string>("name", "NumberOfVecHits");
310  psd0.add<std::string>("title", ";Number of vechits per event;");
311  psd0.add<double>("xmin", 0.0);
312  psd0.add<bool>("switch", true);
313  psd0.add<double>("xmax", 15000.0);
314  psd0.add<int>("NxBins", 150);
315  desc.add<edm::ParameterSetDescription>("GlobalNVecHits", psd0);
316  }
317  {
319  psd0.add<std::string>("name", "Global_VecHitPosition_XY_P");
320  psd0.add<std::string>("title", "Global_VecHitPosition_XY_P;x [mm];y [mm];");
321  psd0.add<int>("NxBins", 1250);
322  psd0.add<double>("xmin", -1250.0);
323  psd0.add<double>("xmax", 1250.0);
324  psd0.add<int>("NyBins", 1250);
325  psd0.add<double>("ymin", -1250.0);
326  psd0.add<double>("ymax", 1250.0);
327  psd0.add<bool>("switch", true);
328  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_P", psd0);
329  }
330  {
332  psd0.add<std::string>("name", "Global_VecHitPosition_XY_S");
333  psd0.add<std::string>("title", "Global_VecHitPosition_XY_S;x [mm];y [mm];");
334  psd0.add<int>("NxBins", 1250);
335  psd0.add<double>("xmin", -1250.0);
336  psd0.add<double>("xmax", 1250.0);
337  psd0.add<int>("NyBins", 1250);
338  psd0.add<double>("ymin", -1250.0);
339  psd0.add<double>("ymax", 1250.0);
340  psd0.add<bool>("switch", true);
341  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_S", psd0);
342  }
343  {
345  psd0.add<std::string>("name", "Global_VecHitPosition_RZ_P");
346  psd0.add<std::string>("title", "Global_VecHitPosition_RZ_P;z [mm];r [mm]");
347  psd0.add<int>("NxBins", 1500);
348  psd0.add<double>("xmin", -3000.0);
349  psd0.add<double>("xmax", 3000.0);
350  psd0.add<int>("NyBins", 1250);
351  psd0.add<double>("ymin", 0.0);
352  psd0.add<double>("ymax", 1250.0);
353  psd0.add<bool>("switch", true);
354  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_P", psd0);
355  }
356  {
358  psd0.add<std::string>("name", "Global_VecHitPosition_RZ_S");
359  psd0.add<std::string>("title", "Global_VecHitPosition_RZ_S;z [mm];r [mm]");
360 
361  psd0.add<int>("NxBins", 1500);
362  psd0.add<double>("xmin", -3000.0);
363  psd0.add<double>("xmax", 3000.0);
364  psd0.add<int>("NyBins", 1250);
365  psd0.add<double>("ymin", 0.0);
366  psd0.add<double>("ymax", 1250.0);
367  psd0.add<bool>("switch", true);
368  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_S", psd0);
369  }
370  //Layer wise parameter
371  {
373  psd0.add<std::string>("name", "NumberOfVecHitsLayerP");
374  psd0.add<std::string>("title", ";Number of vector hits per event(macro pixel sensor);");
375  psd0.add<double>("xmin", 0.0);
376  psd0.add<double>("xmax", 5000.0);
377  psd0.add<int>("NxBins", 100);
378  psd0.add<bool>("switch", true);
379  desc.add<edm::ParameterSetDescription>("NVecHitsLayer_P", psd0);
380  }
381 
382  {
384  psd0.add<std::string>("name", "NumberOfVecHitsLayerS");
385  psd0.add<std::string>("title", ";Number of vector hits per event(strip sensor);");
386  psd0.add<double>("xmin", 0.0);
387  psd0.add<double>("xmax", 5000.0);
388  psd0.add<int>("NxBins", 100);
389  psd0.add<bool>("switch", true);
390  desc.add<edm::ParameterSetDescription>("NVecHitsLayer_S", psd0);
391  }
392  {
394  psd0.add<std::string>("name", "LocalPositionXY_P");
395  psd0.add<std::string>("title", "LocalPositionXY_P;x ;y ;");
396  psd0.add<int>("NxBins", 50);
397  psd0.add<double>("xmin", -10.0);
398  psd0.add<double>("xmax", 10.0);
399  psd0.add<int>("NyBins", 50);
400  psd0.add<double>("ymin", -10.0);
401  psd0.add<double>("ymax", 10.0);
402  psd0.add<bool>("switch", true);
403  desc.add<edm::ParameterSetDescription>("LocalPositionXY_P", psd0);
404  }
405  {
407  psd0.add<std::string>("name", "LocalPositionXY_S");
408  psd0.add<std::string>("title", "LocalPositionXY_S;x ;y ;");
409  psd0.add<int>("NxBins", 50);
410  psd0.add<double>("xmin", -10.0);
411  psd0.add<double>("xmax", 10.0);
412  psd0.add<int>("NyBins", 50);
413  psd0.add<double>("ymin", -10.0);
414  psd0.add<double>("ymax", 10.0);
415  psd0.add<bool>("switch", true);
416  desc.add<edm::ParameterSetDescription>("LocalPositionXY_S", psd0);
417  }
418 
419  {
421  psd0.add<std::string>("name", "CurvatureOfVecHits");
422  psd0.add<std::string>("title", ";VectorHit curvature;");
423  psd0.add<double>("xmin", -0.05);
424  psd0.add<bool>("switch", true);
425  psd0.add<double>("xmax", 0.05);
426  psd0.add<int>("NxBins", 200);
427  desc.add<edm::ParameterSetDescription>("Curvature", psd0);
428  }
429  {
431  psd0.add<std::string>("name", "CurvatureErrOCurvature");
432  psd0.add<std::string>("title", ";VectorHit #delta#rho/#rho;");
433  psd0.add<double>("xmin", -0.05);
434  psd0.add<bool>("switch", true);
435  psd0.add<double>("xmax", 0.05);
436  psd0.add<int>("NxBins", 500);
437  desc.add<edm::ParameterSetDescription>("CurvErr", psd0);
438  }
439  {
441  psd0.add<std::string>("name", "PhiOfVecHits");
442  psd0.add<std::string>("title", ";VectorHit #phi;");
443  psd0.add<double>("xmin", -M_PI);
444  psd0.add<bool>("switch", true);
445  psd0.add<double>("xmax", M_PI);
446  psd0.add<int>("NxBins", 30);
447  desc.add<edm::ParameterSetDescription>("Phi", psd0);
448  }
449  {
451  psd0.add<std::string>("name", "EtaOfVecHits");
452  psd0.add<std::string>("title", ";VectorHit #eta;");
453  psd0.add<double>("xmin", -5.);
454  psd0.add<bool>("switch", true);
455  psd0.add<double>("xmax", 5.);
456  psd0.add<int>("NxBins", 50);
457  desc.add<edm::ParameterSetDescription>("Eta", psd0);
458  }
459  {
461  psd0.add<std::string>("name", "PtOfVecHits");
462  psd0.add<std::string>("title", "VectorHit p_T;p_T ;");
463  psd0.add<int>("NxBins", 100);
464  psd0.add<double>("xmin", 0.);
465  psd0.add<double>("xmax", 200.0);
466  psd0.add<bool>("switch", true);
467  desc.add<edm::ParameterSetDescription>("Pt", psd0);
468  }
469  {
471  psd0.add<std::string>("name", "Chi2OfVecHits");
472  psd0.add<std::string>("title", "VectorHit chi squared; #chi^2;");
473  psd0.add<int>("NxBins", 100);
474  psd0.add<double>("xmin", 0.);
475  psd0.add<double>("xmax", 0.000001);
476  psd0.add<bool>("switch", true);
477  desc.add<edm::ParameterSetDescription>("Chi2", psd0);
478  }
479  {
481  psd0.add<std::string>("name", "CurvatureVsEtaProf_P");
482  psd0.add<std::string>("title", "Curvature vs #eta (macro-pixel);#eta ;curvature ;");
483  psd0.add<int>("NxBins", 50);
484  psd0.add<double>("xmin", -5.0);
485  psd0.add<double>("xmax", 5.0);
486  psd0.add<double>("ymin", -0.05);
487  psd0.add<double>("ymax", 0.05);
488  psd0.add<bool>("switch", true);
489  desc.add<edm::ParameterSetDescription>("CurvatureVsEta_P", psd0);
490  }
491  {
493  psd0.add<std::string>("name", "CurvatureVsEtaProf_S");
494  psd0.add<std::string>("title", "Curvature vs #eta (strip);#eta ;curvature ;");
495  psd0.add<int>("NxBins", 25);
496  psd0.add<double>("xmin", -5.0);
497  psd0.add<double>("xmax", 5.0);
498  psd0.add<double>("ymin", -0.05);
499  psd0.add<double>("ymax", 0.05);
500  psd0.add<bool>("switch", true);
501  desc.add<edm::ParameterSetDescription>("CurvatureVsEta_S", psd0);
502  }
503  desc.add<std::string>("TopFolderName", "TrackerPhase2OTVectorHits/Accepted");
504  desc.add<bool>("Verbosity", false);
505  desc.add<edm::InputTag>("vechitsSrc", edm::InputTag("siPhase2VectorHits", "accepted"));
506  descriptions.add("Phase2OTMonitorVectorHits", desc);
507 }
508 
509 //define this as a plug-in
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void bookLayerHistos(DQMStore::IBooker &ibooker, unsigned int det_id, std::string &subdir)
T perp() const
Definition: PV3DBase.h:69
MonitorElement * book2DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T z() const
Definition: PV3DBase.h:61
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
T eta() const
Definition: PV3DBase.h:73
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
std::map< std::string, VecHitME > layerMEs_
MonitorElement * bookProfile1DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
data_type const * const_iterator
Definition: DetSetNew.h:31
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Log< level::Error, false > LogError
T curvature(T InversePt, const MagneticField &field)
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
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
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
std::string getOTHistoId(uint32_t det_id, const TrackerTopology *tTopo)
ModuleType getDetectorType(DetId) const
Transition
Definition: Transition.h:12
key
prepare the HTCondor submission files and eventually submit them
double f[11][100]
const edm::EDGetTokenT< VectorHitCollection > tokenVecHitsOT_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MonitorElement * book1DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
#define M_PI
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
HLT enums.
iterator end()
Definition: DetSetNew.h:53
Phase2OTMonitorVectorHits(const edm::ParameterSet &)
Definition: Run.h:45
iterator begin()
Definition: DetSetNew.h:51