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 
109  if (!clusterHandle.isValid()) {
110  edm::LogWarning("Phase2OTMonitorCluster") << "No Phase2TrackerCluster1D Collection found in the event. Skipping!";
111  return;
112  }
113 
114  // Number of clusters
115  std::map<std::string, unsigned int> nClustersCounter_P; //map of detidkey vs #cls
116  std::map<std::string, unsigned int> nClustersCounter_S; //map of detidkey vs #cls
117  unsigned int nclus = 0; //global counter
118  for (const auto& DSVItr : *clusterHandle) {
119  // Getting the id of detector unit
120  uint32_t rawid(DSVItr.detId());
121  DetId detId(rawid);
122  const GeomDetUnit* geomDetUnit(tkGeom_->idToDetUnit(detId));
123  if (!geomDetUnit)
124  continue;
125 
127 
129  // initialize the nhit counters if they don't exist for this layer
130  //the check on the detId is needed to avoid checking at the filling stage
132  auto counterDet = nClustersCounter_P.find(folderkey);
133  if (counterDet == nClustersCounter_P.end())
134  nClustersCounter_P.emplace(folderkey, DSVItr.size());
135  else
136  counterDet->second += DSVItr.size();
138  auto counterDet = nClustersCounter_S.find(folderkey);
139  if (counterDet == nClustersCounter_S.end())
140  nClustersCounter_S.emplace(folderkey, DSVItr.size());
141  else
142  counterDet->second += DSVItr.size();
143  }
144  nclus += DSVItr.size();
145 
146  for (const auto& clusterItr : DSVItr) {
147  MeasurementPoint mpCluster(clusterItr.center(), clusterItr.column() + 0.5);
148  Local3DPoint localPosCluster = geomDetUnit->topology().localPosition(mpCluster);
149  Global3DPoint globalPosCluster = geomDetUnit->surface().toGlobal(localPosCluster);
150  double gx = globalPosCluster.x() * 10.;
151  double gy = globalPosCluster.y() * 10.;
152  double gz = globalPosCluster.z() * 10.;
153  double gr = globalPosCluster.perp() * 10.;
154  auto layerMEit = layerMEs_.find(folderkey);
155  if (layerMEit == layerMEs_.end())
156  continue;
157  ClusterMEs& local_mes = layerMEit->second;
159  globalXY_P_->Fill(gx, gy);
160  globalRZ_P_->Fill(gz, gr);
161  local_mes.ClusterSize_P->Fill(clusterItr.size());
162  local_mes.XYLocalPositionMap_P->Fill(localPosCluster.x(), localPosCluster.y());
163 
164  if (local_mes.XYGlobalPositionMap_P != nullptr) //make this optional
165  local_mes.XYGlobalPositionMap_P->Fill(gx, gy);
167  globalXY_S_->Fill(gx, gy);
168  globalRZ_S_->Fill(gz, gr);
169  local_mes.ClusterSize_S->Fill(clusterItr.size());
170  local_mes.XYLocalPositionMap_S->Fill(localPosCluster.x(), localPosCluster.y());
171 
172  if (local_mes.XYGlobalPositionMap_S != nullptr) //make this optional
173  local_mes.XYGlobalPositionMap_S->Fill(gx, gy);
174  }
175  }
176  }
177  for (const auto& it : nClustersCounter_P) {
178  if (layerMEs_.find(it.first) == layerMEs_.end())
179  continue;
180  if (layerMEs_[it.first].nClusters_P != nullptr) //this check should not be required though
181  layerMEs_[it.first].nClusters_P->Fill(it.second);
182  }
183  for (const auto& it : nClustersCounter_S) {
184  if (layerMEs_.find(it.first) == layerMEs_.end())
185  continue;
186  if (layerMEs_[it.first].nClusters_S != nullptr) //this check should not be required though
187  layerMEs_[it.first].nClusters_S->Fill(it.second);
188  }
189  numberClusters_->Fill(nclus);
190 }
191 
192 //
193 // -- Book Histograms
194 //
196  edm::Run const& iRun,
197  edm::EventSetup const& iSetup) {
198  std::string top_folder = config_.getParameter<std::string>("TopFolderName");
199  ibooker.cd();
200  ibooker.setCurrentFolder(top_folder);
201  edm::LogInfo("Phase2OTMonitorCluster") << " Booking Histograms in: " << top_folder;
202 
204 
206 
208 
210 
212 
213  //Now book layer wise histos
214  edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
215  if (theTkDigiGeomWatcher.check(iSetup)) {
216  for (auto const& det_u : tkGeom_->detUnits()) {
217  //Always check TrackerNumberingBuilder before changing this part
218  //continue if Pixel
219  if ((det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
220  det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
221  continue;
222  unsigned int detId_raw = det_u->geographicalId().rawId();
223  edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
224  << "\t key=" << phase2tkutil::getITHistoId(detId_raw, tTopo_) << std::endl;
225  bookLayerHistos(ibooker, detId_raw, top_folder);
226  }
227  }
228 }
229 
233  if (folderName.empty()) {
234  edm::LogWarning("Phase2OTMonitorCluster") << ">>>> Invalid histo_id ";
235  return;
236  }
237  if (layerMEs_.find(folderName) == layerMEs_.end()) {
238  ibooker.cd();
239  ibooker.setCurrentFolder(subdir + "/" + folderName);
240  edm::LogInfo("Phase2OTMonitorCluster") << " Booking Histograms in: " << subdir + "/" + folderName;
241  ClusterMEs local_mes;
244  local_mes.nClusters_P =
246  local_mes.ClusterSize_P =
248  local_mes.XYGlobalPositionMap_P =
249  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer_P"), ibooker);
250  local_mes.XYLocalPositionMap_P =
251  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_P"), ibooker);
252  }
253 
254  local_mes.nClusters_S =
256 
257  local_mes.ClusterSize_S =
259 
260  local_mes.XYGlobalPositionMap_S =
261  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer_S"), ibooker);
262 
263  local_mes.XYLocalPositionMap_S =
264  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("LocalPositionXY_S"), ibooker);
265 
266  layerMEs_.emplace(folderName, local_mes);
267  } //if block layerME find
268 }
269 
271  // rechitMonitorOT
273  {
275  psd0.add<std::string>("name", "NumberOfClusters");
276  psd0.add<std::string>("title", ";Number of clusters per event;");
277  psd0.add<double>("xmin", 0.0);
278  psd0.add<bool>("switch", true);
279  psd0.add<double>("xmax", 350000.0);
280  psd0.add<int>("NxBins", 150);
281  desc.add<edm::ParameterSetDescription>("GlobalNClusters", psd0);
282  }
283  {
285  psd0.add<std::string>("name", "Global_ClusterPosition_XY_P");
286  psd0.add<std::string>("title", "Global_ClusterPosition_XY_P;x [mm];y [mm];");
287  psd0.add<int>("NxBins", 1250);
288  psd0.add<double>("xmin", -1250.0);
289  psd0.add<double>("xmax", 1250.0);
290  psd0.add<int>("NyBins", 1250);
291  psd0.add<double>("ymin", -1250.0);
292  psd0.add<double>("ymax", 1250.0);
293  psd0.add<bool>("switch", true);
294  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_P", psd0);
295  }
296  {
298  psd0.add<std::string>("name", "Global_ClusterPosition_XY_S");
299  psd0.add<std::string>("title", "Global_ClusterPosition_XY_S;x [mm];y [mm];");
300  psd0.add<int>("NxBins", 1250);
301  psd0.add<double>("xmin", -1250.0);
302  psd0.add<double>("xmax", 1250.0);
303  psd0.add<int>("NyBins", 1250);
304  psd0.add<double>("ymin", -1250.0);
305  psd0.add<double>("ymax", 1250.0);
306  psd0.add<bool>("switch", true);
307  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_S", psd0);
308  }
309 
310  {
312  psd0.add<std::string>("name", "Global_ClusterPosition_RZ_P");
313  psd0.add<std::string>("title", "Global_ClusterPosition_RZ_P;z [mm];r [mm]");
314  psd0.add<int>("NxBins", 1500);
315  psd0.add<double>("xmin", -3000.0);
316  psd0.add<double>("xmax", 3000.0);
317  psd0.add<int>("NyBins", 1250);
318  psd0.add<double>("ymin", 0.0);
319  psd0.add<double>("ymax", 1250.0);
320  psd0.add<bool>("switch", true);
321  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_P", psd0);
322  }
323  {
325  psd0.add<std::string>("name", "Global_ClusterPosition_RZ_S");
326  psd0.add<std::string>("title", "Global_ClusterPosition_RZ_S;z [mm];r [mm]");
327  psd0.add<int>("NxBins", 1500);
328  psd0.add<double>("xmin", -3000.0);
329  psd0.add<double>("xmax", 3000.0);
330  psd0.add<int>("NyBins", 1250);
331  psd0.add<double>("ymin", 0.0);
332  psd0.add<double>("ymax", 1250.0);
333  psd0.add<bool>("switch", true);
334  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_S", psd0);
335  }
336  //Layer wise parameter
337  {
339  psd0.add<std::string>("name", "NumberOfClustersLayerP");
340  psd0.add<std::string>("title", ";Number of clusters per event(macro pixel sensor);");
341  psd0.add<double>("xmin", 0.0);
342  psd0.add<double>("xmax", 28000.0);
343  psd0.add<int>("NxBins", 150);
344  psd0.add<bool>("switch", true);
345  desc.add<edm::ParameterSetDescription>("NClustersLayer_P", psd0);
346  }
347  {
349  psd0.add<std::string>("name", "NumberOfClustersLayerS");
350  psd0.add<std::string>("title", ";Number of clusters per event(strip sensor);");
351  psd0.add<double>("xmin", 0.0);
352  psd0.add<double>("xmax", 28000.0);
353  psd0.add<int>("NxBins", 150);
354  psd0.add<bool>("switch", true);
355  desc.add<edm::ParameterSetDescription>("NClustersLayer_S", psd0);
356  }
357  {
359  psd0.add<std::string>("name", "ClusterSize_P");
360  psd0.add<std::string>("title", ";cluster size(macro pixel sensor);");
361  psd0.add<double>("xmin", -0.5);
362  psd0.add<double>("xmax", 30.5);
363  psd0.add<int>("NxBins", 31);
364  psd0.add<bool>("switch", true);
365  desc.add<edm::ParameterSetDescription>("ClusterSize_P", psd0);
366  }
367  {
369  psd0.add<std::string>("name", "ClusterSize_S");
370  psd0.add<std::string>("title", ";cluster size(strip sensor);");
371  psd0.add<double>("xmin", -0.5);
372  psd0.add<double>("xmax", 30.5);
373  psd0.add<int>("NxBins", 31);
374  psd0.add<bool>("switch", true);
375  desc.add<edm::ParameterSetDescription>("ClusterSize_S", psd0);
376  }
377  {
379  psd0.add<std::string>("name", "GlobalPositionXY_perlayer_P");
380  psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer_P;x [mm];y [mm];");
381  psd0.add<int>("NxBins", 1250);
382  psd0.add<double>("xmin", -1250.0);
383  psd0.add<double>("xmax", 1250.0);
384  psd0.add<int>("NyBins", 1250);
385  psd0.add<double>("ymin", -1250.0);
386  psd0.add<double>("ymax", 1250.0);
387  psd0.add<bool>("switch", false);
388  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_P", psd0);
389  }
390  {
392  psd0.add<std::string>("name", "GlobalPositionXY_perlayer_S");
393  psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer_S;x [mm];y [mm];");
394  psd0.add<int>("NxBins", 1250);
395  psd0.add<double>("xmin", -1250.0);
396  psd0.add<double>("xmax", 1250.0);
397  psd0.add<int>("NyBins", 1250);
398  psd0.add<double>("ymin", -1250.0);
399  psd0.add<double>("ymax", 1250.0);
400  psd0.add<bool>("switch", false);
401  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer_S", psd0);
402  }
403  {
405  psd0.add<std::string>("name", "LocalPositionXY_P");
406  psd0.add<std::string>("title", "LocalPositionXY_P;x ;y ;");
407  psd0.add<int>("NxBins", 50);
408  psd0.add<double>("xmin", -10.0);
409  psd0.add<double>("xmax", 10.0);
410  psd0.add<int>("NyBins", 50);
411  psd0.add<double>("ymin", -10.0);
412  psd0.add<double>("ymax", 10.0);
413  psd0.add<bool>("switch", true);
414  desc.add<edm::ParameterSetDescription>("LocalPositionXY_P", psd0);
415  }
416  {
418  psd0.add<std::string>("name", "LocalPositionXY_S");
419  psd0.add<std::string>("title", "LocalPositionXY_S;x ;y ;");
420  psd0.add<int>("NxBins", 50);
421  psd0.add<double>("xmin", -10.0);
422  psd0.add<double>("xmax", 10.0);
423  psd0.add<int>("NyBins", 50);
424  psd0.add<double>("ymin", -10.0);
425  psd0.add<double>("ymax", 10.0);
426  psd0.add<bool>("switch", true);
427  desc.add<edm::ParameterSetDescription>("LocalPositionXY_S", psd0);
428  }
429 
430  desc.add<std::string>("TopFolderName", "TrackerPhase2OTCluster");
431  desc.add<edm::InputTag>("clusterSrc", edm::InputTag("siPhase2Clusters"));
432  descriptions.add("Phase2OTMonitorCluster", desc);
433 }
const TrackerTopology * tTopo_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T perp() const
Definition: PV3DBase.h:69
MonitorElement * book2DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
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:36
T z() const
Definition: PV3DBase.h:61
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
#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)
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