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  // Number of clusters
106  std::map<std::string, unsigned int> nClsmap;
107  unsigned int nclusGlobal = 0;
108  for (const auto& DSVItr : *itPixelClusterHandle) {
109  uint32_t rawid(DSVItr.detId());
110  DetId detId(rawid);
111  const GeomDet* geomDet = tkGeom_->idToDet(detId);
112  if (!geomDet)
113  continue;
114  const GeomDetUnit* geomDetUnit(tkGeom_->idToDetUnit(detId));
115  if (!geomDetUnit)
116  continue;
117  nclusGlobal += DSVItr.size();
118  std::string folderkey = phase2tkutil::getITHistoId(detId, tTopo_);
119  // initialize the nhit counters if they don't exist for this layer
120  auto counterDet = nClsmap.find(folderkey);
121  if (counterDet == nClsmap.end()) {
122  nClsmap.emplace(folderkey, DSVItr.size());
123  } else
124  counterDet->second += DSVItr.size();
125  for (const auto& clusterItr : DSVItr) {
126  MeasurementPoint mpCluster(clusterItr.x(), clusterItr.y());
127  Local3DPoint localPosCluster = geomDetUnit->topology().localPosition(mpCluster);
128  Global3DPoint globalPosCluster = geomDetUnit->surface().toGlobal(localPosCluster);
129  double gx = globalPosCluster.x() * 10.;
130  double gy = globalPosCluster.y() * 10.;
131  double gz = globalPosCluster.z() * 10.;
132  double gr = globalPosCluster.perp() * 10.;
133 
134  // cluster size
135  if (geomDetUnit->subDetector() == GeomDetEnumerators::SubDetector::P2PXB) {
136  globalXY_barrel_->Fill(gx, gy);
137  globalRZ_barrel_->Fill(gz, gr);
138  } else if (geomDetUnit->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC) {
139  globalXY_endcap_->Fill(gx, gy);
140  globalRZ_endcap_->Fill(gz, gr);
141  }
142  auto local_mesIT = layerMEs_.find(folderkey);
143  if (local_mesIT == layerMEs_.end())
144  continue;
145  ClusterMEs& local_mes = local_mesIT->second;
146  if (local_mes.XYGlobalPositionMapPixel) //make this optional
147  local_mes.XYGlobalPositionMapPixel->Fill(globalPosCluster.z(), globalPosCluster.perp());
148  local_mes.XYLocalPositionMapPixel->Fill(localPosCluster.x(), localPosCluster.y());
149  local_mes.ClusterSize->Fill(clusterItr.size());
150  local_mes.ClusterSizeX->Fill(clusterItr.sizeX());
151  local_mes.ClusterSizeY->Fill(clusterItr.sizeY());
152  local_mes.ClusterCharge->Fill(clusterItr.charge());
153  }
154  }
155 
156  for (const auto& it : nClsmap) {
157  if (layerMEs_.find(it.first) == layerMEs_.end())
158  continue;
159  layerMEs_[it.first].nClusters->Fill(it.second);
160  }
161  numberClusters_->Fill(nclusGlobal); //global histo of #clusters
162 }
163 
164 //
165 // -- Book Histograms
166 //
168  edm::Run const& iRun,
169  edm::EventSetup const& iSetup) {
170  std::string top_folder = config_.getParameter<std::string>("TopFolderName");
171  std::stringstream folder_name;
172 
173  ibooker.cd();
174  folder_name << top_folder << "/";
175  ibooker.setCurrentFolder(folder_name.str());
176 
177  edm::LogInfo("Phase2ITMonitorCluster") << " Booking Histograms in: " << folder_name.str();
178 
180 
182  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXB"), ibooker);
183 
185  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXB"), ibooker);
186 
188  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_PXEC"), ibooker);
189 
191  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionRZ_PXEC"), ibooker);
192 
193  //Now book layer wise histos
194  edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
195  if (theTkDigiGeomWatcher.check(iSetup)) {
196  for (auto const& det_u : tkGeom_->detUnits()) {
197  //Always check TrackerNumberingBuilder before changing this part
198  if (!(det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
199  det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
200  continue;
201  unsigned int detId_raw = det_u->geographicalId().rawId();
202  edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
203  << "\t key=" << phase2tkutil::getITHistoId(detId_raw, tTopo_) << std::endl;
204  bookLayerHistos(ibooker, detId_raw, top_folder);
205  }
206  }
207 }
208 
212  if (folderName.empty())
213  return;
214 
215  std::map<std::string, ClusterMEs>::iterator pos = layerMEs_.find(folderName);
216 
217  if (pos == layerMEs_.end()) {
218  ibooker.cd();
219  ibooker.setCurrentFolder(subdir + "/" + folderName);
220 
221  edm::LogInfo("Phase2ITMonitorCluster") << " Booking Histograms in: " << subdir + "/" + folderName;
222 
223  ClusterMEs local_mes;
224 
225  local_mes.nClusters =
227 
228  local_mes.ClusterSize =
230 
231  local_mes.ClusterSizeX =
233 
234  local_mes.ClusterSizeY =
236 
237  local_mes.ClusterCharge =
239 
240  local_mes.XYLocalPositionMapPixel =
242 
243  local_mes.XYGlobalPositionMapPixel =
244  phase2tkutil::book2DFromPSet(config_.getParameter<edm::ParameterSet>("GlobalPositionXY_perlayer"), ibooker);
245 
246  layerMEs_.emplace(folderName, local_mes);
247  }
248 }
249 
251  // clusterITMonitor
253  //Global Histos
254  {
256  psd0.add<std::string>("name", "NumberOfClusters");
257  psd0.add<std::string>("title", "NumberClusters;Number of Clusters;");
258  psd0.add<double>("xmin", 0.0);
259  psd0.add<bool>("switch", true);
260  psd0.add<double>("xmax", 300000.0);
261  psd0.add<int>("NxBins", 150);
262  desc.add<edm::ParameterSetDescription>("GlobalNClusters", psd0);
263  }
264  {
266  psd0.add<std::string>("name", "Global_Position_RZ_IT_barrel");
267  psd0.add<std::string>("title", "Global_Position_RZ_IT_barrel;z [mm];r [mm]");
268  psd0.add<double>("ymax", 300.0);
269  psd0.add<int>("NxBins", 1500);
270  psd0.add<int>("NyBins", 300);
271  psd0.add<bool>("switch", true);
272  psd0.add<double>("xmax", 3000.0);
273  psd0.add<double>("xmin", -3000.0);
274  psd0.add<double>("ymin", 0.0);
275  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXB", psd0);
276  }
277  {
279  psd0.add<std::string>("name", "Global_Position_XY_IT_barrel");
280  psd0.add<std::string>("title", "Global_Position_XY_IT_barrel;x [mm];y [mm];");
281  psd0.add<double>("ymax", 300.0);
282  psd0.add<int>("NxBins", 600);
283  psd0.add<int>("NyBins", 600);
284  psd0.add<bool>("switch", true);
285  psd0.add<double>("xmax", 300.0);
286  psd0.add<double>("xmin", -300.0);
287  psd0.add<double>("ymin", -300.0);
288  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXB", psd0);
289  }
290  {
292  psd0.add<std::string>("name", "Global_Position_RZ_IT_endcap");
293  psd0.add<std::string>("title", "Global_Position_RZ_IT_endcap;z [mm];r [mm]");
294  psd0.add<double>("ymax", 300.0);
295  psd0.add<int>("NxBins", 1500);
296  psd0.add<int>("NyBins", 300);
297  psd0.add<bool>("switch", true);
298  psd0.add<double>("xmax", 3000.0);
299  psd0.add<double>("xmin", -3000.0);
300  psd0.add<double>("ymin", 0.0);
301  desc.add<edm::ParameterSetDescription>("GlobalPositionRZ_PXEC", psd0);
302  }
303  {
305  psd0.add<std::string>("name", "Global_Position_XY_IT_endcap");
306  psd0.add<std::string>("title", "Global_Position_XY_IT_endcap; x [mm]; y [mm]");
307  psd0.add<double>("ymax", 300.0);
308  psd0.add<int>("NxBins", 600);
309  psd0.add<int>("NyBins", 600);
310  psd0.add<bool>("switch", true);
311  psd0.add<double>("xmax", 300.0);
312  psd0.add<double>("xmin", -300.0);
313  psd0.add<double>("ymin", -300.0);
314  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_PXEC", psd0);
315  }
316  //Local histos
317  //Per layer/ring histos
318  {
320  psd0.add<std::string>("name", "NumberOfClustersLayer");
321  psd0.add<std::string>("title", "NumberOfClutsers;Number of Clusters;");
322  psd0.add<double>("xmin", 0.0);
323  psd0.add<bool>("switch", true);
324  psd0.add<double>("xmax", 20000.0);
325  psd0.add<int>("NxBins", 150);
326  desc.add<edm::ParameterSetDescription>("NClustersLayer", psd0);
327  }
328  {
330  psd0.add<std::string>("name", "ClusterCharge");
331  psd0.add<std::string>("title", ";Cluster charge;");
332  psd0.add<double>("xmin", 0.);
333  psd0.add<bool>("switch", true);
334  psd0.add<double>("xmax", 100000.);
335  psd0.add<int>("NxBins", 100);
336  desc.add<edm::ParameterSetDescription>("ClusterCharge", psd0);
337  }
338  {
340  psd0.add<std::string>("name", "ClusterSize");
341  psd0.add<std::string>("title", ";Cluster size;");
342  psd0.add<double>("xmin", -0.5);
343  psd0.add<double>("xmax", 30.5);
344  psd0.add<int>("NxBins", 31);
345  psd0.add<bool>("switch", true);
346  desc.add<edm::ParameterSetDescription>("ClusterSize", psd0);
347  }
348  {
350  psd0.add<std::string>("name", "ClusterSizeY");
351  psd0.add<std::string>("title", ";Cluster sizeY;");
352  psd0.add<double>("xmin", -0.5);
353  psd0.add<bool>("switch", true);
354  psd0.add<double>("xmax", 30.5);
355  psd0.add<int>("NxBins", 31);
356  desc.add<edm::ParameterSetDescription>("ClusterSizeY", psd0);
357  }
358  {
360  psd0.add<std::string>("name", "ClusterSizeX");
361  psd0.add<std::string>("title", ";Cluster sizeX;");
362  psd0.add<double>("xmin", -0.5);
363  psd0.add<bool>("switch", true);
364  psd0.add<double>("xmax", 30.5);
365  psd0.add<int>("NxBins", 31);
366  desc.add<edm::ParameterSetDescription>("ClusterSizeX", psd0);
367  }
368  {
370  psd0.add<std::string>("name", "Local_ClusterPosition_XY");
371  psd0.add<std::string>("title", "Local_ClusterPosition_XY; x; y");
372  psd0.add<double>("ymax", 0.0);
373  psd0.add<int>("NxBins", 500);
374  psd0.add<int>("NyBins", 500);
375  psd0.add<bool>("switch", true);
376  psd0.add<double>("xmax", 0.0);
377  psd0.add<double>("xmin", 0.0);
378  psd0.add<double>("ymin", 0.0);
379  desc.add<edm::ParameterSetDescription>("LocalPositionXY", psd0);
380  }
381  {
383  psd0.add<std::string>("name", "GlobalPositionXY_perlayer");
384  psd0.add<std::string>("title", "GlobalClusterPositionXY_perlayer;x [mm];y [mm];");
385  psd0.add<double>("ymax", 300.0);
386  psd0.add<int>("NxBins", 600);
387  psd0.add<int>("NyBins", 600);
388  psd0.add<bool>("switch", false);
389  psd0.add<double>("xmax", 300.0);
390  psd0.add<double>("xmin", -300.0);
391  psd0.add<double>("ymin", -300.0);
392  desc.add<edm::ParameterSetDescription>("GlobalPositionXY_perlayer", psd0);
393  }
394 
395  desc.add<std::string>("TopFolderName", "TrackerPhase2ITCluster");
396  desc.add<edm::InputTag>("InnerPixelClusterSource", edm::InputTag("siPixelClusters"));
397  descriptions.add("Phase2ITMonitorCluster", desc);
398 }
399 
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.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:45