CMS 3D CMS Logo

Phase2OTMonitorCluster.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //bookLayer
3 // Package: Phase2OTMonitorCluster
4 // Class: Phase2OTMonitorCluster
5 //
11 //
12 // Author: Gabriel Ramirez
13 // Date: May 23, 2020
14 //
15 #include <memory>
36 // DQM Histograming
40 
42 public:
44  ~Phase2OTMonitorCluster() override;
45  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
46  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
47  void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  struct ClusterMEs {
56 
61  };
67 
68  void fillOTHistos(const edm::Event& iEvent);
69 
70  void bookLayerHistos(DQMStore::IBooker& ibooker, uint32_t det_it, std::string& subdir);
71 
72  std::map<std::string, ClusterMEs> layerMEs_;
73 
78  const TrackerGeometry* tkGeom_ = nullptr;
79  const TrackerTopology* tTopo_ = nullptr;
80 };
82 //
83 // constructors
84 //
86  : config_(iConfig),
87  clustersToken_(consumes<Phase2TrackerCluster1DCollectionNew>(config_.getParameter<edm::InputTag>("clusterSrc"))),
89  topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
90  edm::LogInfo("Phase2OTMonitorCluster") << ">>> Construct Phase2OTMonitorCluster ";
91 }
92 
94  edm::LogInfo("Phase2OTMonitorCluster") << ">>> Destroy Phase2OTMonitorCluster ";
95 }
96 //
97 // -- DQM Begin Run
99  tkGeom_ = &iSetup.getData(geomToken_);
100  tTopo_ = &iSetup.getData(topoToken_);
101 }
102 //
103 // -- Analyze
104 //
106  // Getting the clusters
107  const auto& clusterHandle = iEvent.getHandle(clustersToken_);
108  // Number of clusters
109  std::map<std::string, unsigned int> nClustersCounter_P; //map of detidkey vs #cls
110  std::map<std::string, unsigned int> nClustersCounter_S; //map of detidkey vs #cls
111  unsigned int nclus = 0; //global counter
112  for (const auto& DSVItr : *clusterHandle) {
113  // Getting the id of detector unit
114  uint32_t rawid(DSVItr.detId());
115  DetId detId(rawid);
116  const GeomDetUnit* geomDetUnit(tkGeom_->idToDetUnit(detId));
117  if (!geomDetUnit)
118  continue;
119 
120  std::string folderkey = phase2tkutil::getOTHistoId(detId, tTopo_);
121 
123  // initialize the nhit counters if they don't exist for this layer
124  //the check on the detId is needed to avoid checking at the filling stage
126  auto counterDet = nClustersCounter_P.find(folderkey);
127  if (counterDet == nClustersCounter_P.end())
128  nClustersCounter_P.emplace(folderkey, DSVItr.size());
129  else
130  counterDet->second += DSVItr.size();
132  auto counterDet = nClustersCounter_S.find(folderkey);
133  if (counterDet == nClustersCounter_S.end())
134  nClustersCounter_S.emplace(folderkey, DSVItr.size());
135  else
136  counterDet->second += DSVItr.size();
137  }
138  nclus += DSVItr.size();
139 
140  for (const auto& clusterItr : DSVItr) {
141  MeasurementPoint mpCluster(clusterItr.center(), clusterItr.column() + 0.5);
142  Local3DPoint localPosCluster = geomDetUnit->topology().localPosition(mpCluster);
143  Global3DPoint globalPosCluster = geomDetUnit->surface().toGlobal(localPosCluster);
144  double gx = globalPosCluster.x() * 10.;
145  double gy = globalPosCluster.y() * 10.;
146  double gz = globalPosCluster.z() * 10.;
147  double gr = globalPosCluster.perp() * 10.;
148  auto layerMEit = layerMEs_.find(folderkey);
149  if (layerMEit == layerMEs_.end())
150  continue;
151  ClusterMEs& local_mes = layerMEit->second;
153  globalXY_P_->Fill(gx, gy);
154  globalRZ_P_->Fill(gz, gr);
155  local_mes.ClusterSize_P->Fill(clusterItr.size());
156  local_mes.XYLocalPositionMap_P->Fill(localPosCluster.x(), localPosCluster.y());
157 
158  if (local_mes.XYGlobalPositionMap_P != nullptr) //make this optional
159  local_mes.XYGlobalPositionMap_P->Fill(gx, gy);
161  globalXY_S_->Fill(gx, gy);
162  globalRZ_S_->Fill(gz, gr);
163  local_mes.ClusterSize_S->Fill(clusterItr.size());
164  local_mes.XYLocalPositionMap_S->Fill(localPosCluster.x(), localPosCluster.y());
165 
166  if (local_mes.XYGlobalPositionMap_S != nullptr) //make this optional
167  local_mes.XYGlobalPositionMap_S->Fill(gx, gy);
168  }
169  }
170  }
171  for (const auto& it : nClustersCounter_P) {
172  if (layerMEs_.find(it.first) == layerMEs_.end())
173  continue;
174  if (layerMEs_[it.first].nClusters_P != nullptr) //this check should not be required though
175  layerMEs_[it.first].nClusters_P->Fill(it.second);
176  }
177  for (const auto& it : nClustersCounter_S) {
178  if (layerMEs_.find(it.first) == layerMEs_.end())
179  continue;
180  if (layerMEs_[it.first].nClusters_S != nullptr) //this check should not be required though
181  layerMEs_[it.first].nClusters_S->Fill(it.second);
182  }
183  numberClusters_->Fill(nclus);
184 }
185 
186 //
187 // -- Book Histograms
188 //
190  edm::Run const& iRun,
191  edm::EventSetup const& iSetup) {
192  std::string top_folder = config_.getParameter<std::string>("TopFolderName");
193  ibooker.cd();
194  ibooker.setCurrentFolder(top_folder);
195  edm::LogInfo("Phase2OTMonitorCluster") << " Booking Histograms in: " << top_folder;
196 
198 
200 
202 
204 
206 
207  //Now book layer wise histos
208  edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
209  if (theTkDigiGeomWatcher.check(iSetup)) {
210  for (auto const& det_u : tkGeom_->detUnits()) {
211  //Always check TrackerNumberingBuilder before changing this part
212  //continue if Pixel
213  if ((det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
214  det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
215  continue;
216  unsigned int detId_raw = det_u->geographicalId().rawId();
217  edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
218  << "\t key=" << phase2tkutil::getITHistoId(detId_raw, tTopo_) << std::endl;
219  bookLayerHistos(ibooker, detId_raw, top_folder);
220  }
221  }
222 }
223 
227  if (folderName.empty()) {
228  edm::LogWarning("Phase2OTMonitorCluster") << ">>>> Invalid histo_id ";
229  return;
230  }
231  if (layerMEs_.find(folderName) == layerMEs_.end()) {
232  ibooker.cd();
233  ibooker.setCurrentFolder(subdir + "/" + folderName);
234  edm::LogInfo("Phase2OTMonitorCluster") << " Booking Histograms in: " << subdir + "/" + folderName;
235  ClusterMEs local_mes;
238  local_mes.nClusters_P =
240  local_mes.ClusterSize_P =
242  local_mes.XYGlobalPositionMap_P =
243  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer_P"), ibooker);
244  local_mes.XYLocalPositionMap_P =
245  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_P"), ibooker);
246  }
247 
248  local_mes.nClusters_S =
250 
251  local_mes.ClusterSize_S =
253 
254  local_mes.XYGlobalPositionMap_S =
255  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer_S"), ibooker);
256 
257  local_mes.XYLocalPositionMap_S =
258  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_S"), ibooker);
259 
260  layerMEs_.emplace(folderName, local_mes);
261  } //if block layerME find
262 }
263 
265  // rechitMonitorOT
267  {
269  psd0.add<std::string>("name", "NumberOfClusters");
270  psd0.add<std::string>("title", ";Number of clusters per event;");
271  psd0.add<double>("xmin", 0.0);
272  psd0.add<bool>("switch", true);
273  psd0.add<double>("xmax", 350000.0);
274  psd0.add<int>("NxBins", 150);
275  desc.add<edm::ParameterSetDescription>("GlobalNClusters", psd0);
276  }
277  {
279  psd0.add<std::string>("name", "Global_ClusterPosition_XY_P");
280  psd0.add<std::string>("title", "Global_ClusterPosition_XY_P;x [mm];y [mm];");
281  psd0.add<int>("NxBins", 1250);
282  psd0.add<double>("xmin", -1250.0);
283  psd0.add<double>("xmax", 1250.0);
284  psd0.add<int>("NyBins", 1250);
285  psd0.add<double>("ymin", -1250.0);
286  psd0.add<double>("ymax", 1250.0);
287  psd0.add<bool>("switch", true);
288  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_P", psd0);
289  }
290  {
292  psd0.add<std::string>("name", "Global_ClusterPosition_XY_S");
293  psd0.add<std::string>("title", "Global_ClusterPosition_XY_S;x [mm];y [mm];");
294  psd0.add<int>("NxBins", 1250);
295  psd0.add<double>("xmin", -1250.0);
296  psd0.add<double>("xmax", 1250.0);
297  psd0.add<int>("NyBins", 1250);
298  psd0.add<double>("ymin", -1250.0);
299  psd0.add<double>("ymax", 1250.0);
300  psd0.add<bool>("switch", true);
301  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_S", psd0);
302  }
303 
304  {
306  psd0.add<std::string>("name", "Global_ClusterPosition_RZ_P");
307  psd0.add<std::string>("title", "Global_ClusterPosition_RZ_P;z [mm];r [mm]");
308  psd0.add<int>("NxBins", 1500);
309  psd0.add<double>("xmin", -3000.0);
310  psd0.add<double>("xmax", 3000.0);
311  psd0.add<int>("NyBins", 1250);
312  psd0.add<double>("ymin", 0.0);
313  psd0.add<double>("ymax", 1250.0);
314  psd0.add<bool>("switch", true);
315  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_P", psd0);
316  }
317  {
319  psd0.add<std::string>("name", "Global_ClusterPosition_RZ_S");
320  psd0.add<std::string>("title", "Global_ClusterPosition_RZ_S;z [mm];r [mm]");
321  psd0.add<int>("NxBins", 1500);
322  psd0.add<double>("xmin", -3000.0);
323  psd0.add<double>("xmax", 3000.0);
324  psd0.add<int>("NyBins", 1250);
325  psd0.add<double>("ymin", 0.0);
326  psd0.add<double>("ymax", 1250.0);
327  psd0.add<bool>("switch", true);
328  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_S", psd0);
329  }
330  //Layer wise parameter
331  {
333  psd0.add<std::string>("name", "NumberOfClustersLayerP");
334  psd0.add<std::string>("title", ";Number of clusters per event(macro pixel sensor);");
335  psd0.add<double>("xmin", 0.0);
336  psd0.add<double>("xmax", 28000.0);
337  psd0.add<int>("NxBins", 150);
338  psd0.add<bool>("switch", true);
339  desc.add<edm::ParameterSetDescription>("NClustersLayer_P", psd0);
340  }
341  {
343  psd0.add<std::string>("name", "NumberOfClustersLayerS");
344  psd0.add<std::string>("title", ";Number of clusters per event(strip sensor);");
345  psd0.add<double>("xmin", 0.0);
346  psd0.add<double>("xmax", 28000.0);
347  psd0.add<int>("NxBins", 150);
348  psd0.add<bool>("switch", true);
349  desc.add<edm::ParameterSetDescription>("NClustersLayer_S", psd0);
350  }
351  {
353  psd0.add<std::string>("name", "ClusterSize_P");
354  psd0.add<std::string>("title", ";cluster size(macro pixel sensor);");
355  psd0.add<double>("xmin", -0.5);
356  psd0.add<double>("xmax", 30.5);
357  psd0.add<int>("NxBins", 31);
358  psd0.add<bool>("switch", true);
359  desc.add<edm::ParameterSetDescription>("ClusterSize_P", psd0);
360  }
361  {
363  psd0.add<std::string>("name", "ClusterSize_S");
364  psd0.add<std::string>("title", ";cluster size(strip sensor);");
365  psd0.add<double>("xmin", -0.5);
366  psd0.add<double>("xmax", 30.5);
367  psd0.add<int>("NxBins", 31);
368  psd0.add<bool>("switch", true);
369  desc.add<edm::ParameterSetDescription>("ClusterSize_S", psd0);
370  }
371  {
373  psd0.add<std::string>("name", "GlobalPositionXY_perlayer_P");
374  psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer_P;x [mm];y [mm];");
375  psd0.add<int>("NxBins", 1250);
376  psd0.add<double>("xmin", -1250.0);
377  psd0.add<double>("xmax", 1250.0);
378  psd0.add<int>("NyBins", 1250);
379  psd0.add<double>("ymin", -1250.0);
380  psd0.add<double>("ymax", 1250.0);
381  psd0.add<bool>("switch", false);
382  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_P", psd0);
383  }
384  {
386  psd0.add<std::string>("name", "GlobalPositionXY_perlayer_S");
387  psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer_S;x [mm];y [mm];");
388  psd0.add<int>("NxBins", 1250);
389  psd0.add<double>("xmin", -1250.0);
390  psd0.add<double>("xmax", 1250.0);
391  psd0.add<int>("NyBins", 1250);
392  psd0.add<double>("ymin", -1250.0);
393  psd0.add<double>("ymax", 1250.0);
394  psd0.add<bool>("switch", false);
395  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_S", psd0);
396  }
397  {
399  psd0.add<std::string>("name", "LocalPositionXY_P");
400  psd0.add<std::string>("title", "LocalPositionXY_P;x ;y ;");
401  psd0.add<int>("NxBins", 50);
402  psd0.add<double>("xmin", -10.0);
403  psd0.add<double>("xmax", 10.0);
404  psd0.add<int>("NyBins", 50);
405  psd0.add<double>("ymin", -10.0);
406  psd0.add<double>("ymax", 10.0);
407  psd0.add<bool>("switch", true);
408  desc.add<edm::ParameterSetDescription>("LocalPositionXY_P", psd0);
409  }
410  {
412  psd0.add<std::string>("name", "LocalPositionXY_S");
413  psd0.add<std::string>("title", "LocalPositionXY_S;x ;y ;");
414  psd0.add<int>("NxBins", 50);
415  psd0.add<double>("xmin", -10.0);
416  psd0.add<double>("xmax", 10.0);
417  psd0.add<int>("NyBins", 50);
418  psd0.add<double>("ymin", -10.0);
419  psd0.add<double>("ymax", 10.0);
420  psd0.add<bool>("switch", true);
421  desc.add<edm::ParameterSetDescription>("LocalPositionXY_S", psd0);
422  }
423 
424  desc.add<std::string>("TopFolderName", "TrackerPhase2OTCluster");
425  desc.add<edm::InputTag>("clusterSrc", edm::InputTag("siPhase2Clusters"));
426  descriptions.add("Phase2OTMonitorCluster", desc);
427 }
const TrackerTopology * tTopo_
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)
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
edm::EDGetTokenT< Phase2TrackerCluster1DCollectionNew > clustersToken_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
T z() const
Definition: PV3DBase.h:61
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
std::map< std::string, ClusterMEs > layerMEs_
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
std::string getITHistoId(uint32_t det_id, const TrackerTopology *tTopo)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
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
std::string getOTHistoId(uint32_t det_id, const TrackerTopology *tTopo)
const TrackerGeometry * tkGeom_
ModuleType getDetectorType(DetId) const
Transition
Definition: Transition.h:12
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)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
void fillOTHistos(const edm::Event &iEvent)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
Phase2OTMonitorCluster(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void bookLayerHistos(DQMStore::IBooker &ibooker, uint32_t det_it, std::string &subdir)
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
Log< level::Warning, false > LogWarning
Definition: Run.h:45