CMS 3D CMS Logo

HGCalDigiValidation.cc
Go to the documentation of this file.
1 // system include files
2 #include <cmath>
3 #include <fstream>
4 #include <iostream>
5 #include <map>
6 #include <string>
7 #include <vector>
8 
14 
22 
24 
27 
37 
45 
46 #include "CLHEP/Units/GlobalSystemOfUnits.h"
47 
48 // user include files
49 
50 
52 
53 public:
54  struct digiInfo{
56  x = y = z = 0.0;
57  layer = adc = charge = 0;
58  }
59  double x, y, z;
60  int layer, charge, adc;
61  };
62 
63  explicit HGCalDigiValidation(const edm::ParameterSet&);
64  ~HGCalDigiValidation() override {}
65 
66  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
67  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
68  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
69  void analyze(const edm::Event&, const edm::EventSetup&) override;
70 
71 private:
73  void fillDigiInfo();
74  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
75  template<class T1, class T2>
76  void digiValidation(const T1& detId, const T2* geom, int, uint16_t, double);
77 
78  // ----------member data ---------------------------
81  bool ifHCAL_;
83  int layers_;
84 
85  std::map<int, int> OccupancyMap_plus_;
86  std::map<int, int> OccupancyMap_minus_;
87 
88  std::vector<MonitorElement*> charge_;
89  std::vector<MonitorElement*> DigiOccupancy_XY_;
90  std::vector<MonitorElement*> ADC_;
91  std::vector<MonitorElement*> DigiOccupancy_Plus_;
92  std::vector<MonitorElement*> DigiOccupancy_Minus_;
95 };
96 
98  nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
99  ifHCAL_(iConfig.getParameter<bool>("ifHCAL")),
100  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity",0)),
101  SampleIndx_(iConfig.getUntrackedParameter<int>("SampleIndx",5)) {
102 
103  auto temp = iConfig.getParameter<edm::InputTag>("DigiSource");
104  if (nameDetector_ == "HGCalEESensitive" || nameDetector_ == "HGCalHESiliconSensitive" || nameDetector_ == "HGCalHEScintillatorSensitive") {
105  digiSource_ = consumes<HGCalDigiCollection>(temp);
106  } else if (nameDetector_ == "HCal") {
107  if (ifHCAL_) digiSource_ = consumes<QIE11DigiCollection>(temp);
108  else digiSource_ = consumes<HGCalDigiCollection>(temp);
109  } else {
110  throw cms::Exception("BadHGCDigiSource")
111  << "HGCal DetectorName given as " << nameDetector_ << " must be: "
112  << "\"HGCalEESensitive\", \"HGCalHESiliconSensitive\", "
113  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
114  }
115 }
116 
119  desc.add<std::string>("DetectorName","HGCalEESensitive");
120  desc.add<edm::InputTag>("DigiSource",edm::InputTag("hgcalDigis","EE"));
121  desc.add<bool>("ifHCAL",false);
122  desc.addUntracked<int>("Verbosity",0);
123  desc.addUntracked<int>("SampleIndx",0);
124  descriptions.add("hgcalDigiValidationEEDefault",desc);
125 }
126 
128  const edm::EventSetup& iSetup) {
129  OccupancyMap_plus_.clear();
130  OccupancyMap_minus_.clear();
131 
132  const HGCalGeometry* geom0(nullptr);
133  const CaloGeometry* geom1(nullptr);
134  int geomType(0);
135  if (nameDetector_ == "HCal") {
137  iSetup.get<CaloGeometryRecord>().get(geom);
138  if (!geom.isValid())
139  edm::LogVerbatim("HGCalValidation") << "HGCalDigiValidation: Cannot get valid "
140  << "HGCalGeometry Object for " << nameDetector_;
141  geom1 = geom.product();
142  } else {
144  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
145  if (!geom.isValid())
146  edm::LogVerbatim("HGCalValidation") << "HGCalDigiValidation: Cannot get valid "
147  << "HGCalGeometry Object for " << nameDetector_;
148  geom0 = geom.product();
150  if ((mode == HGCalGeometryMode::Hexagon8) ||
151  (mode == HGCalGeometryMode::Hexagon8Full)) geomType = 1;
152  else if (mode == HGCalGeometryMode::Trapezoid) geomType = 2;
153  }
154 
155  unsigned int ntot(0), nused(0);
156  if (nameDetector_ == "HGCalEESensitive") {
157  //HGCalEE
158  edm::Handle<HGCalDigiCollection> theHGCEEDigiContainers;
159  iEvent.getByToken(digiSource_, theHGCEEDigiContainers);
160  if (theHGCEEDigiContainers.isValid()) {
161  if (verbosity_>0)
162  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
163  << theHGCEEDigiContainers->size()
164  << " element(s)";
165 
166  for (const auto & it: *(theHGCEEDigiContainers.product())) {
167  ntot++; nused++;
168  DetId detId = it.id();
169  int layer = ((geomType == 0) ? HGCalDetId(detId).layer() :
170  HGCSiliconDetId(detId).layer());
171  const HGCSample& hgcSample = it.sample(SampleIndx_);
172  uint16_t gain = hgcSample.toa();
173  uint16_t adc = hgcSample.data();
174  double charge = adc*gain;
175  digiValidation(detId, geom0, layer, adc, charge);
176  }
177  fillDigiInfo();
178  } else {
179  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
180  << "exist for HGCEE!!!";
181  }
182  } else if ((nameDetector_ == "HGCalHESiliconSensitive") ||
183  (nameDetector_ == "HGCalHEScintillatorSensitive")) {
184  //HGCalHE
185  edm::Handle<HGCalDigiCollection> theHGCHEDigiContainers;
186  iEvent.getByToken(digiSource_, theHGCHEDigiContainers);
187  if (theHGCHEDigiContainers.isValid()) {
188  if (verbosity_>0)
189  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
190  << theHGCHEDigiContainers->size()
191  << " element(s)";
192 
193  for (const auto & it: *(theHGCHEDigiContainers.product())) {
194  ntot++; nused++;
195  DetId detId = it.id();
196  int layer = ((geomType == 0) ? HGCalDetId(detId).layer() :
197  ((geomType == 1) ? HGCSiliconDetId(detId).layer() :
198  HGCScintillatorDetId(detId).layer()));
199  const HGCSample& hgcSample = it.sample(SampleIndx_);
200  uint16_t gain = hgcSample.toa();
201  uint16_t adc = hgcSample.data();
202  double charge = adc*gain;
203  digiValidation(detId, geom0, layer, adc, charge);
204  }
205  fillDigiInfo();
206  } else {
207  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
208  << "exist for HGCFH!!!";
209  }
210  } else if ((nameDetector_ == "HCal") && (!ifHCAL_)) {
211  //HGCalBH
212  edm::Handle<HGCalDigiCollection> theHGCBHDigiContainers;
213  iEvent.getByToken(digiSource_, theHGCBHDigiContainers);
214  if (theHGCBHDigiContainers.isValid()) {
215  if (verbosity_>0)
216  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
217  << theHGCBHDigiContainers->size()
218  << " element(s)";
219 
220  for (const auto & it: *(theHGCBHDigiContainers.product())) {
221  ntot++; nused++;
222  HcalDetId detId = it.id();
223  int layer = detId.depth();
224  const HGCSample& hgcSample = it.sample(SampleIndx_);
225  uint16_t gain = hgcSample.toa();
226  uint16_t adc = hgcSample.data();
227  double charge = adc*gain;
228  digiValidation(detId, geom1, layer, adc, charge);
229  }
230  fillDigiInfo();
231  } else {
232  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
233  << "exist for HGCBH!!!";
234  }
235  } else if (nameDetector_ == "HCal") {
236  //HE
237  edm::Handle<QIE11DigiCollection> theHEDigiContainers;
238  iEvent.getByToken(digiSource_, theHEDigiContainers);
239  if (theHEDigiContainers.isValid()) {
240  if (verbosity_>0)
241  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
242  << theHEDigiContainers->size()
243  << " element(s)";
244  edm::ESHandle<HcalDbService> conditions;
245  iSetup.get<HcalDbRecord > ().get(conditions);
246 
247  for (const auto & it: *(theHEDigiContainers.product())) {
248  QIE11DataFrame df(it);
249  HcalDetId detId = (df.id());
250  ntot++;
251  if (detId.subdet() == HcalEndcap) {
252  nused++;
254  const HcalQIECoder* channelCoder = conditions->getHcalCoder(detId);
255  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
256  HcalCoderDb coder(*channelCoder, *shape);
257  CaloSamples tool;
258  coder.adc2fC(df, tool);
259  int layer = detId.depth();
260  uint16_t adc = (df)[SampleIndx_].adc();
261  int capid = (df)[SampleIndx_].capid();
262  double charge = (tool[SampleIndx_] - calibrations.pedestal(capid));
263  digiValidation(detId, geom1, layer, adc, charge);
264  }
265  }
266  fillDigiInfo();
267  } else {
268  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
269  << "exist for HGCBH!!!";
270  }
271  } else {
272  edm::LogWarning("HGCalValidation") << "invalid detector name !! "
273  << nameDetector_;
274  }
275  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event()
276  << " with " << ntot << " total and "
277  << nused << " used digis";
278 }
279 
280 template<class T1, class T2>
281 void HGCalDigiValidation::digiValidation(const T1& detId, const T2* geom,
282  int layer, uint16_t adc, double charge) {
283 
284  if (verbosity_>1) edm::LogVerbatim("HGCalValidation") << std::hex
285  << detId.rawId()
286  << std::dec;
287  DetId id1 = DetId(detId.rawId());
288  const GlobalPoint& global1 = geom->getPosition(id1);
289 
290  if (verbosity_>1)
291  edm::LogVerbatim("HGCalValidation") << " adc = " << adc
292  << " charge = " << charge;
293 
294  digiInfo hinfo;
295  hinfo.x = global1.x();
296  hinfo.y = global1.y();
297  hinfo.z = global1.z();
298  hinfo.adc = adc;
299  hinfo.charge = charge; //charges[0];
300  hinfo.layer = std::min(layer,layers_);
301 
302  if (verbosity_>1)
303  edm::LogVerbatim("HGCalValidation") << "gx = " << hinfo.x
304  << " gy = " << hinfo.y
305  << " gz = " << hinfo.z;
306 
307  fillDigiInfo(hinfo);
308 
309  if (global1.eta() > 0) fillOccupancyMap(OccupancyMap_plus_, hinfo.layer -1);
311 
312 }
313 
314 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
315  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer] ++;
316  else OccupancyMap[layer] = 1;
317 }
318 
320  int ilayer = hinfo.layer -1;
321  charge_.at(ilayer)->Fill(hinfo.charge);
322  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
323  ADC_.at(ilayer)->Fill(hinfo.adc);
324 }
325 
327  for (const auto & itr : OccupancyMap_plus_) {
328  int layer = itr.first;
329  int occupancy = itr.second;
330  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
331  }
332  for (const auto & itr : OccupancyMap_minus_) {
333  int layer = itr.first;
334  int occupancy = itr.second;
335  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
336  }
337 }
338 
340  const edm::EventSetup& iSetup) {
341  if (nameDetector_ == "HCal") {
343  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
344  const HcalDDDRecConstants *hcons = &(*pHRNDC);
345  layers_ = hcons->getMaxDepth(1);
346  } else {
348  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
349  const HGCalDDDConstants & hgcons_ = (*pHGDC);
350  layers_ = hgcons_.layers(true);
351  }
352 
353  if (verbosity_>0)
354  edm::LogVerbatim("HGCalValidation") << "current DQM directory: "
355  << "HGCAL/HGCalDigisV/" << nameDetector_
356  << " layer = "<< layers_;
357 }
358 
360  edm::Run const&,
361  edm::EventSetup const&) {
362 
363  iB.setCurrentFolder("HGCAL/HGCalDigisV/"+nameDetector_);
364 
365  std::ostringstream histoname;
366  for (int ilayer = 0; ilayer < layers_; ilayer++ ) {
367  histoname.str(""); histoname << "charge_"<< "layer_" << ilayer;
368  charge_.push_back(iB.book1D(histoname.str().c_str(),"charge_",100,-25,25));
369 
370  histoname.str(""); histoname << "ADC_" << "layer_" << ilayer;
371  ADC_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy",200,0,1000));
372 
373  histoname.str(""); histoname << "DigiOccupancy_XY_" << "layer_" << ilayer;
374  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
375 
376  histoname.str(""); histoname << "DigiOccupancy_Plus_" << "layer_" << ilayer;
377  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
378  histoname.str(""); histoname << "DigiOccupancy_Minus_" << "layer_" << ilayer;
379  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
380  }
381 
382  histoname.str(""); histoname << "SUMOfDigiOccupancy_Plus";
383  MeanDigiOccupancy_Plus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_-0.5);
384  histoname.str(""); histoname << "SUMOfRecDigiOccupancy_Minus";
385  MeanDigiOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5,layers_-0.5);
386 }
387 
388 
389 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
390 
392 
393 //define this as a plug-in
int adc(sample_type sample)
get the ADC sample (12 bits)
HGCalGeometryMode::GeometryMode geomMode() const
Geometry mode.
Definition: HGCalTopology.h:86
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
uint32_t data() const
Definition: HGCSample.h:62
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< MonitorElement * > charge_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:142
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< MonitorElement * > DigiOccupancy_XY_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
wrapper for a data word
Definition: HGCSample.h:13
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const override
Definition: HcalCoderDb.cc:68
int depth() const
get the tower depth
Definition: HcalDetId.h:162
int iEvent
Definition: GenABIO.cc:230
unsigned int layers(bool reco) const
int layer() const
get the layer #
const HGCalTopology & topology() const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
edm::DataFrame::id_type id() const
HGCalDigiValidation(const edm::ParameterSet &)
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
std::vector< MonitorElement * > DigiOccupancy_Minus_
Definition: DetId.h:18
constexpr double pedestal(int fCapId) const
get pedestal for capid=0..3
void digiValidation(const T1 &detId, const T2 *geom, int, uint16_t, double)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
T const * product() const
Definition: Handle.h:81
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
int getMaxDepth(const int &type) const
MonitorElement * MeanDigiOccupancy_Minus_
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetToken digiSource_
uint32_t toa() const
Definition: HGCSample.h:61
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
std::map< int, int > OccupancyMap_minus_
int layer() const
get the layer #
std::map< int, int > OccupancyMap_plus_
edm::EventID id() const
Definition: EventBase.h:60
size_type size() const
T get() const
Definition: EventSetup.h:63
bool isValid() const
Definition: ESHandle.h:47
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
std::vector< MonitorElement * > ADC_
MonitorElement * MeanDigiOccupancy_Plus_
T const * product() const
Definition: ESHandle.h:86
void fillOccupancyMap(std::map< int, int > &OccupancyMap, int layer)
int layer() const
get the layer #
Definition: HGCalDetId.h:48
std::vector< MonitorElement * > DigiOccupancy_Plus_
Definition: Run.h:44