CMS 3D CMS Logo

Phase2ITMonitorCluster.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //bookLayer
3 // Package: Phase2ITMonitorCluster
4 // Class: Phase2ITMonitorCluster
5 //
11 //
12 // Author: Gabriel Ramirez
13 // Date: May 23, 2020
14 #include <memory>
35 // DQM Histograming
39 
41 public:
43  ~Phase2ITMonitorCluster() override;
44  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
45  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
46  void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49 private:
50  struct ClusterMEs {
58  };
59 
65 
66  void bookLayerHistos(DQMStore::IBooker& ibooker, uint32_t det_it, std::string& subdir);
67 
68  std::map<std::string, ClusterMEs> layerMEs_;
73  const TrackerGeometry* tkGeom_ = nullptr;
74  const TrackerTopology* tTopo_ = nullptr;
75 };
77 //
78 // constructors
79 //
81  : config_(iConfig),
82  itPixelClusterToken_(consumes<edmNew::DetSetVector<SiPixelCluster>>(
83  config_.getParameter<edm::InputTag>("InnerPixelClusterSource"))),
85  topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
86  edm::LogInfo("Phase2ITMonitorCluster") << ">>> Construct Phase2ITMonitorCluster ";
87 }
88 
90  edm::LogInfo("Phase2ITMonitorCluster") << ">>> Destroy Phase2ITMonitorCluster ";
91 }
92 //
93 // -- DQM Begin Run
95  tkGeom_ = &iSetup.getData(geomToken_);
96  tTopo_ = &iSetup.getData(topoToken_);
97 }
98 
99 //
100 // -- Analyze
101 //
103  // Getting the clusters
104  const auto& itPixelClusterHandle = iEvent.getHandle(itPixelClusterToken_);
105 
106  if (!itPixelClusterHandle.isValid()) {
107  edm::LogWarning("Phase2ITMonitorCluster") << "No SiPixelCluster Collection found in the event. Skipping!";
108  return;
109  }
110 
111  // Number of clusters
112  std::map<std::string, unsigned int> nClsmap;
113  unsigned int nclusGlobal = 0;
114  for (const auto& DSVItr : *itPixelClusterHandle) {
115  uint32_t rawid(DSVItr.detId());
116  DetId detId(rawid);
117  const GeomDet* geomDet = tkGeom_->idToDet(detId);
118  if (!geomDet)
119  continue;
120  const GeomDetUnit* geomDetUnit(tkGeom_->idToDetUnit(detId));
121  if (!geomDetUnit)
122  continue;
123  nclusGlobal += DSVItr.size();
124  std::string folderkey = phase2tkutil::getITHistoId(detId, tTopo_);
125  // initialize the nhit counters if they don't exist for this layer
126  auto counterDet = nClsmap.find(folderkey);
127  if (counterDet == nClsmap.end()) {
128  nClsmap.emplace(folderkey, DSVItr.size());
129  } else
130  counterDet->second += DSVItr.size();
131  for (const auto& clusterItr : DSVItr) {
132  MeasurementPoint mpCluster(clusterItr.x(), clusterItr.y());
133  Local3DPoint localPosCluster = geomDetUnit->topology().localPosition(mpCluster);
134  Global3DPoint globalPosCluster = geomDetUnit->surface().toGlobal(localPosCluster);
135  double gx = globalPosCluster.x() * 10.;
136  double gy = globalPosCluster.y() * 10.;
137  double gz = globalPosCluster.z() * 10.;
138  double gr = globalPosCluster.perp() * 10.;
139 
140  // cluster size
141  if (geomDetUnit->subDetector() == GeomDetEnumerators::SubDetector::P2PXB) {
142  globalXY_barrel_->Fill(gx, gy);
143  globalRZ_barrel_->Fill(gz, gr);
144  } else if (geomDetUnit->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC) {
145  globalXY_endcap_->Fill(gx, gy);
146  globalRZ_endcap_->Fill(gz, gr);
147  }
148  auto local_mesIT = layerMEs_.find(folderkey);
149  if (local_mesIT == layerMEs_.end())
150  continue;
151  ClusterMEs& local_mes = local_mesIT->second;
152  if (local_mes.XYGlobalPositionMapPixel) //make this optional
153  local_mes.XYGlobalPositionMapPixel->Fill(globalPosCluster.z(), globalPosCluster.perp());
154  local_mes.XYLocalPositionMapPixel->Fill(localPosCluster.x(), localPosCluster.y());
155  local_mes.ClusterSize->Fill(clusterItr.size());
156  local_mes.ClusterSizeX->Fill(clusterItr.sizeX());
157  local_mes.ClusterSizeY->Fill(clusterItr.sizeY());
158  local_mes.ClusterCharge->Fill(clusterItr.charge());
159  }
160  }
161 
162  for (const auto& it : nClsmap) {
163  if (layerMEs_.find(it.first) == layerMEs_.end())
164  continue;
165  layerMEs_[it.first].nClusters->Fill(it.second);
166  }
167  numberClusters_->Fill(nclusGlobal); //global histo of #clusters
168 }
169 
170 //
171 // -- Book Histograms
172 //
174  edm::Run const& iRun,
175  edm::EventSetup const& iSetup) {
176  std::string top_folder = config_.getParameter<std::string>("TopFolderName");
177  std::stringstream folder_name;
178 
179  ibooker.cd();
180  folder_name << top_folder << "/";
181  ibooker.setCurrentFolder(folder_name.str());
182 
183  edm::LogInfo("Phase2ITMonitorCluster") << " Booking Histograms in: " << folder_name.str();
184 
186 
188  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXB"), ibooker);
189 
191  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXB"), ibooker);
192 
194  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXEC"), ibooker);
195 
197  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXEC"), ibooker);
198 
199  //Now book layer wise histos
200  edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
201  if (theTkDigiGeomWatcher.check(iSetup)) {
202  for (auto const& det_u : tkGeom_->detUnits()) {
203  //Always check TrackerNumberingBuilder before changing this part
204  if (!(det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
205  det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
206  continue;
207  unsigned int detId_raw = det_u->geographicalId().rawId();
208  edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
209  << "\t key=" << phase2tkutil::getITHistoId(detId_raw, tTopo_) << std::endl;
210  bookLayerHistos(ibooker, detId_raw, top_folder);
211  }
212  }
213 }
214 
218  if (folderName.empty())
219  return;
220 
221  std::map<std::string, ClusterMEs>::iterator pos = layerMEs_.find(folderName);
222 
223  if (pos == layerMEs_.end()) {
224  ibooker.cd();
225  ibooker.setCurrentFolder(subdir + "/" + folderName);
226 
227  edm::LogInfo("Phase2ITMonitorCluster") << " Booking Histograms in: " << subdir + "/" + folderName;
228 
229  ClusterMEs local_mes;
230 
231  local_mes.nClusters =
233 
234  local_mes.ClusterSize =
236 
237  local_mes.ClusterSizeX =
239 
240  local_mes.ClusterSizeY =
242 
243  local_mes.ClusterCharge =
245 
246  local_mes.XYLocalPositionMapPixel =
248 
249  local_mes.XYGlobalPositionMapPixel =
250  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer"), ibooker);
251 
252  layerMEs_.emplace(folderName, local_mes);
253  }
254 }
255 
257  // clusterITMonitor
259  //Global Histos
260  {
262  psd0.add<std::string>("name", "NumberOfClusters");
263  psd0.add<std::string>("title", "NumberClusters;Number of Clusters;");
264  psd0.add<double>("xmin", 0.0);
265  psd0.add<bool>("switch", true);
266  psd0.add<double>("xmax", 300000.0);
267  psd0.add<int>("NxBins", 150);
268  desc.add<edm::ParameterSetDescription>("GlobalNClusters", psd0);
269  }
270  {
272  psd0.add<std::string>("name", "Global_Position_RZ_IT_barrel");
273  psd0.add<std::string>("title", "Global_Position_RZ_IT_barrel;z [mm];r [mm]");
274  psd0.add<double>("ymax", 300.0);
275  psd0.add<int>("NxBins", 1500);
276  psd0.add<int>("NyBins", 300);
277  psd0.add<bool>("switch", true);
278  psd0.add<double>("xmax", 3000.0);
279  psd0.add<double>("xmin", -3000.0);
280  psd0.add<double>("ymin", 0.0);
281  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXB", psd0);
282  }
283  {
285  psd0.add<std::string>("name", "Global_Position_XY_IT_barrel");
286  psd0.add<std::string>("title", "Global_Position_XY_IT_barrel;x [mm];y [mm];");
287  psd0.add<double>("ymax", 300.0);
288  psd0.add<int>("NxBins", 600);
289  psd0.add<int>("NyBins", 600);
290  psd0.add<bool>("switch", true);
291  psd0.add<double>("xmax", 300.0);
292  psd0.add<double>("xmin", -300.0);
293  psd0.add<double>("ymin", -300.0);
294  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXB", psd0);
295  }
296  {
298  psd0.add<std::string>("name", "Global_Position_RZ_IT_endcap");
299  psd0.add<std::string>("title", "Global_Position_RZ_IT_endcap;z [mm];r [mm]");
300  psd0.add<double>("ymax", 300.0);
301  psd0.add<int>("NxBins", 1500);
302  psd0.add<int>("NyBins", 300);
303  psd0.add<bool>("switch", true);
304  psd0.add<double>("xmax", 3000.0);
305  psd0.add<double>("xmin", -3000.0);
306  psd0.add<double>("ymin", 0.0);
307  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXEC", psd0);
308  }
309  {
311  psd0.add<std::string>("name", "Global_Position_XY_IT_endcap");
312  psd0.add<std::string>("title", "Global_Position_XY_IT_endcap; x [mm]; y [mm]");
313  psd0.add<double>("ymax", 300.0);
314  psd0.add<int>("NxBins", 600);
315  psd0.add<int>("NyBins", 600);
316  psd0.add<bool>("switch", true);
317  psd0.add<double>("xmax", 300.0);
318  psd0.add<double>("xmin", -300.0);
319  psd0.add<double>("ymin", -300.0);
320  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXEC", psd0);
321  }
322  //Local histos
323  //Per layer/ring histos
324  {
326  psd0.add<std::string>("name", "NumberOfClustersLayer");
327  psd0.add<std::string>("title", "NumberOfClutsers;Number of Clusters;");
328  psd0.add<double>("xmin", 0.0);
329  psd0.add<bool>("switch", true);
330  psd0.add<double>("xmax", 20000.0);
331  psd0.add<int>("NxBins", 150);
332  desc.add<edm::ParameterSetDescription>("NClustersLayer", psd0);
333  }
334  {
336  psd0.add<std::string>("name", "ClusterCharge");
337  psd0.add<std::string>("title", ";Cluster charge;");
338  psd0.add<double>("xmin", 0.);
339  psd0.add<bool>("switch", true);
340  psd0.add<double>("xmax", 100000.);
341  psd0.add<int>("NxBins", 100);
342  desc.add<edm::ParameterSetDescription>("ClusterCharge", psd0);
343  }
344  {
346  psd0.add<std::string>("name", "ClusterSize");
347  psd0.add<std::string>("title", ";Cluster size;");
348  psd0.add<double>("xmin", -0.5);
349  psd0.add<double>("xmax", 30.5);
350  psd0.add<int>("NxBins", 31);
351  psd0.add<bool>("switch", true);
352  desc.add<edm::ParameterSetDescription>("ClusterSize", psd0);
353  }
354  {
356  psd0.add<std::string>("name", "ClusterSizeY");
357  psd0.add<std::string>("title", ";Cluster sizeY;");
358  psd0.add<double>("xmin", -0.5);
359  psd0.add<bool>("switch", true);
360  psd0.add<double>("xmax", 30.5);
361  psd0.add<int>("NxBins", 31);
362  desc.add<edm::ParameterSetDescription>("ClusterSizeY", psd0);
363  }
364  {
366  psd0.add<std::string>("name", "ClusterSizeX");
367  psd0.add<std::string>("title", ";Cluster sizeX;");
368  psd0.add<double>("xmin", -0.5);
369  psd0.add<bool>("switch", true);
370  psd0.add<double>("xmax", 30.5);
371  psd0.add<int>("NxBins", 31);
372  desc.add<edm::ParameterSetDescription>("ClusterSizeX", psd0);
373  }
374  {
376  psd0.add<std::string>("name", "Local_ClusterPosition_XY");
377  psd0.add<std::string>("title", "Local_ClusterPosition_XY; x; y");
378  psd0.add<double>("ymax", 0.0);
379  psd0.add<int>("NxBins", 500);
380  psd0.add<int>("NyBins", 500);
381  psd0.add<bool>("switch", true);
382  psd0.add<double>("xmax", 0.0);
383  psd0.add<double>("xmin", 0.0);
384  psd0.add<double>("ymin", 0.0);
385  desc.add<edm::ParameterSetDescription>("LocalPositionXY", psd0);
386  }
387  {
389  psd0.add<std::string>("name", "GlobalPositionXY_perlayer");
390  psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer;x [mm];y [mm];");
391  psd0.add<double>("ymax", 300.0);
392  psd0.add<int>("NxBins", 600);
393  psd0.add<int>("NyBins", 600);
394  psd0.add<bool>("switch", false);
395  psd0.add<double>("xmax", 300.0);
396  psd0.add<double>("xmin", -300.0);
397  psd0.add<double>("ymin", -300.0);
398  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer", psd0);
399  }
400 
401  desc.add<std::string>("TopFolderName", "TrackerPhase2ITCluster");
402  desc.add<edm::InputTag>("InnerPixelClusterSource", edm::InputTag("siPixelClusters"));
403  descriptions.add("Phase2ITMonitorCluster", desc);
404 }
405 
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
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
Phase2ITMonitorCluster(const edm::ParameterSet &)
MonitorElement * book2DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const TrackerTopology * tTopo_
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::string getITHistoId(uint32_t det_id, const TrackerTopology *tTopo)
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
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MonitorElement * book1DFromPSet(const edm::ParameterSet &hpars, DQMStore::IBooker &ibooker)
const TrackerGeomDet * idToDet(DetId) const override
std::map< std::string, ClusterMEs > layerMEs_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Log< level::Info, false > LogInfo
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > itPixelClusterToken_
Definition: DetId.h:17
const TrackerGeometry * tkGeom_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
void bookLayerHistos(DQMStore::IBooker &ibooker, uint32_t det_it, std::string &subdir)
Pixel cluster – collection of neighboring pixels above threshold.
HLT enums.
Log< level::Warning, false > LogWarning
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:45