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 
26 
28 
31 
41 
49 
50 #include "CLHEP/Units/GlobalSystemOfUnits.h"
51 
52 // user include files
53 
54 
56 
57 public:
58  struct digiInfo{
60  x = y = z = charge = 0.0;
61  layer = adc = 0;
62  mode = threshold = false;
63  }
64  double x, y, z, charge;
65  int layer, adc;
66  bool mode, threshold; //tot mode and zero supression
67  };
68 
69  explicit HGCalDigiValidation(const edm::ParameterSet&);
70  ~HGCalDigiValidation() override {}
71 
72  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
73  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
74  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
75  void analyze(const edm::Event&, const edm::EventSetup&) override;
76 
77 private:
79  void fillDigiInfo();
80  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
81  template<class T1, class T2>
82  void digiValidation(const T1& detId, const T2* geom, int layer,
83  uint16_t adc, double charge, bool mode, bool threshold);
84 
85  // ----------member data ---------------------------
91 
92  std::map<int, int> OccupancyMap_plus_;
93  std::map<int, int> OccupancyMap_minus_;
94 
95  std::vector<MonitorElement*> TOA_;
96  std::vector<MonitorElement*> DigiOccupancy_XY_;
97  std::vector<MonitorElement*> ADC_;
98  std::vector<MonitorElement*> TOT_;
99  std::vector<MonitorElement*> DigiOccupancy_Plus_;
100  std::vector<MonitorElement*> DigiOccupancy_Minus_;
103 };
104 
106  nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
107  ifNose_(iConfig.getParameter<bool>("ifNose")),
108  ifHCAL_(iConfig.getParameter<bool>("ifHCAL")),
109  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity",0)),
110  SampleIndx_(iConfig.getUntrackedParameter<int>("SampleIndx",0)),
111  firstLayer_(1) {
112 
113  auto temp = iConfig.getParameter<edm::InputTag>("DigiSource");
114  if ((nameDetector_ == "HGCalEESensitive") ||
115  (nameDetector_ == "HGCalHESiliconSensitive") ||
116  (nameDetector_ == "HGCalHEScintillatorSensitive") ||
117  (nameDetector_ == "HGCalHFNoseSensitive")) {
118  digiSource_ = consumes<HGCalDigiCollection>(temp);
119  } else if (nameDetector_ == "HCal") {
120  if (ifHCAL_) digiSource_ = consumes<QIE11DigiCollection>(temp);
121  else digiSource_ = consumes<HGCalDigiCollection>(temp);
122  } else {
123  throw cms::Exception("BadHGCDigiSource")
124  << "HGCal DetectorName given as " << nameDetector_ << " must be: "
125  << "\"HGCalEESensitive\", \"HGCalHESiliconSensitive\", "
126  << "\"HGCalHEScintillatorSensitive\", \"HGCalHFNoseSensitive\", "
127  << "or \"HCal\"!";
128  }
129 }
130 
133  desc.add<std::string>("DetectorName","HGCalEESensitive");
134  desc.add<edm::InputTag>("DigiSource",edm::InputTag("hgcalDigis","EE"));
135  desc.add<bool>("ifNose",false);
136  desc.add<bool>("ifHCAL",false);
137  desc.addUntracked<int>("Verbosity",0);
138  desc.addUntracked<int>("SampleIndx",2); // central bx
139  descriptions.add("hgcalDigiValidationEEDefault",desc);
140 }
141 
143  const edm::EventSetup& iSetup) {
144  OccupancyMap_plus_.clear();
145  OccupancyMap_minus_.clear();
146 
147  const HGCalGeometry* geom0(nullptr);
148  const CaloGeometry* geom1(nullptr);
149  int geomType(0);
150  if (nameDetector_ == "HCal") {
152  iSetup.get<CaloGeometryRecord>().get(geom);
153  if (!geom.isValid())
154  edm::LogVerbatim("HGCalValidation") << "HGCalDigiValidation: Cannot get "
155  << "valid Geometry Object for "
156  << nameDetector_;
157  geom1 = geom.product();
158  } else {
160  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
161  if (!geom.isValid())
162  edm::LogVerbatim("HGCalValidation") << "HGCalDigiValidation: Cannot get "
163  << "valid Geometry Object for "
164  << nameDetector_;
165  geom0 = geom.product();
167  if ((mode == HGCalGeometryMode::Hexagon8) ||
168  (mode == HGCalGeometryMode::Hexagon8Full)) geomType = 1;
169  else if (mode == HGCalGeometryMode::Trapezoid) geomType = 2;
170  if (nameDetector_ == "HGCalHFNoseSensitive") geomType = 3;
171  }
172 
173  unsigned int ntot(0), nused(0);
174  if ((nameDetector_ == "HGCalEESensitive") ||
175  (nameDetector_ == "HGCalHFNoseSensitive")) {
176  //HGCalEE
177  edm::Handle<HGCalDigiCollection> theHGCEEDigiContainers;
178  iEvent.getByToken(digiSource_, theHGCEEDigiContainers);
179  if (theHGCEEDigiContainers.isValid()) {
180  if (verbosity_>0)
181  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
182  << theHGCEEDigiContainers->size()
183  << " element(s)";
184  for (const auto & it: *(theHGCEEDigiContainers.product())) {
185  ntot++; nused++;
186  DetId detId = it.id();
187  int layer = ((geomType == 0) ? HGCalDetId(detId).layer() :
188  (geomType == 1) ?
189  HGCSiliconDetId(detId).layer() :
190  HFNoseDetId(detId).layer());
191  const HGCSample& hgcSample = it.sample(SampleIndx_);
192  uint16_t gain = hgcSample.toa();
193  uint16_t adc = hgcSample.data();
194  double charge = gain;
195  bool totmode = hgcSample.mode();
196  bool zerothreshold = hgcSample.threshold();
197  digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
198  }
199  fillDigiInfo();
200  } else {
201  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
202  << "exist for " << nameDetector_;
203  }
204  } else if ((nameDetector_ == "HGCalHESiliconSensitive") ||
205  (nameDetector_ == "HGCalHEScintillatorSensitive")) {
206  //HGCalHE
207  edm::Handle<HGCalDigiCollection> theHGCHEDigiContainers;
208  iEvent.getByToken(digiSource_, theHGCHEDigiContainers);
209  if (theHGCHEDigiContainers.isValid()) {
210  if (verbosity_>0)
211  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
212  << theHGCHEDigiContainers->size()
213  << " element(s)";
214  for (const auto & it: *(theHGCHEDigiContainers.product())) {
215  ntot++; nused++;
216  DetId detId = it.id();
217  int layer = ((geomType == 0) ? HGCalDetId(detId).layer() :
218  ((geomType == 1) ? HGCSiliconDetId(detId).layer() :
219  HGCScintillatorDetId(detId).layer()));
220  const HGCSample& hgcSample = it.sample(SampleIndx_);
221  uint16_t gain = hgcSample.toa();
222  uint16_t adc = hgcSample.data();
223  double charge = gain;
224  bool totmode = hgcSample.mode();
225  bool zerothreshold = hgcSample.threshold();
226  digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
227  }
228  fillDigiInfo();
229  } else {
230  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
231  << "exist for " << nameDetector_;
232  }
233  } else if ((nameDetector_ == "HCal") && (!ifHCAL_)) {
234  //HGCalBH
235  edm::Handle<HGCalDigiCollection> theHGCBHDigiContainers;
236  iEvent.getByToken(digiSource_, theHGCBHDigiContainers);
237  if (theHGCBHDigiContainers.isValid()) {
238  if (verbosity_>0)
239  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
240  << theHGCBHDigiContainers->size()
241  << " element(s)";
242  for (const auto & it: *(theHGCBHDigiContainers.product())) {
243  ntot++; nused++;
244  HcalDetId detId = it.id();
245  int layer = detId.depth();
246  const HGCSample& hgcSample = it.sample(SampleIndx_);
247  uint16_t gain = hgcSample.toa();
248  uint16_t adc = hgcSample.data();
249  double charge = gain;
250  bool totmode = hgcSample.mode();
251  bool zerothreshold = hgcSample.threshold();
252  digiValidation(detId, geom1, layer, adc, charge, totmode, zerothreshold);
253  }
254  fillDigiInfo();
255  } else {
256  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
257  << "exist for " << nameDetector_;
258  }
259  } else if (nameDetector_ == "HCal") {
260  //HE
261  edm::Handle<QIE11DigiCollection> theHEDigiContainers;
262  iEvent.getByToken(digiSource_, theHEDigiContainers);
263  if (theHEDigiContainers.isValid()) {
264  if (verbosity_>0)
265  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
266  << theHEDigiContainers->size()
267  << " element(s)";
268  edm::ESHandle<HcalDbService> conditions;
269  iSetup.get<HcalDbRecord > ().get(conditions);
270 
271  for (const auto & it: *(theHEDigiContainers.product())) {
272  QIE11DataFrame df(it);
273  HcalDetId detId = (df.id());
274  ntot++;
275  if (detId.subdet() == HcalEndcap) {
276  nused++;
278  const HcalQIECoder* channelCoder = conditions->getHcalCoder(detId);
279  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
280  HcalCoderDb coder(*channelCoder, *shape);
281  CaloSamples tool;
282  coder.adc2fC(df, tool);
283  int layer = detId.depth();
284  uint16_t adc = (df)[SampleIndx_].adc();
285  int capid = (df)[SampleIndx_].capid();
286  double charge = (tool[SampleIndx_] - calibrations.pedestal(capid));
287  bool totmode = false;
288  bool zerothreshold = false;
289  digiValidation(detId, geom1, layer, adc, charge, totmode, zerothreshold);
290  }
291  }
292  fillDigiInfo();
293  } else {
294  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
295  << "exist for " << nameDetector_;
296  }
297  } else {
298  edm::LogWarning("HGCalValidation") << "invalid detector name !! "
299  << nameDetector_;
300  }
301  if (verbosity_>0)
302  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event()
303  << " with " << ntot << " total and "
304  << nused << " used digis";
305 }
306 
307 template<class T1, class T2>
308 void HGCalDigiValidation::digiValidation(const T1& detId, const T2* geom,
309  int layer, uint16_t adc,
310  double charge, bool mode, bool threshold) {
311 
312  if (verbosity_>1) edm::LogVerbatim("HGCalValidation") << std::hex
313  << detId.rawId()
314  << std::dec
315  << " " << detId.rawId();
316  DetId id1 = DetId(detId.rawId());
317  const GlobalPoint& global1 = geom->getPosition(id1);
318 
319  if (verbosity_>1)
320  edm::LogVerbatim("HGCalValidation") << " adc = " << adc
321  << " toa = " << charge;
322 
323  digiInfo hinfo;
324  hinfo.x = global1.x();
325  hinfo.y = global1.y();
326  hinfo.z = global1.z();
327  hinfo.adc = adc;
328  hinfo.charge = charge;
329  hinfo.layer = layer-firstLayer_;
330  hinfo.mode = mode;
331  hinfo.threshold = threshold;
332 
333  if (verbosity_>1)
334  edm::LogVerbatim("HGCalValidation") << "gx = " << hinfo.x
335  << " gy = " << hinfo.y
336  << " gz = " << hinfo.z;
337 
338  if (global1.eta() > 0) fillOccupancyMap(OccupancyMap_plus_, hinfo.layer);
340 
341  fillDigiInfo(hinfo);
342 
343 }
344 
345 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap,
346  int layer) {
347  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer] ++;
348  else OccupancyMap[layer] = 1;
349 }
350 
352  int ilayer = hinfo.layer;
353  TOA_.at(ilayer)->Fill(hinfo.charge);
354 
355  if (hinfo.mode) {
356  TOT_.at(ilayer)->Fill(hinfo.adc);
357  }
358 
359  if (!hinfo.mode && hinfo.threshold) {
360  ADC_.at(ilayer)->Fill(hinfo.adc);
361  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
362  }
363 }
364 
366  for (const auto & itr : OccupancyMap_plus_) {
367  int layer = itr.first;
368  int occupancy = itr.second;
369  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
370  }
371  for (const auto & itr : OccupancyMap_minus_) {
372  int layer = itr.first;
373  int occupancy = itr.second;
374  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
375  }
376 }
377 
379  const edm::EventSetup& iSetup) {
380  if (nameDetector_ == "HCal") {
382  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
383  const HcalDDDRecConstants *hcons = &(*pHRNDC);
384  layers_ = hcons->getMaxDepth(1);
385  } else {
387  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
388  const HGCalDDDConstants & hgcons_ = (*pHGDC);
389  layers_ = hgcons_.layers(true);
390  firstLayer_ = hgcons_.firstLayer();
391  }
392 
393  if (verbosity_>0)
394  edm::LogVerbatim("HGCalValidation") << "current DQM directory: "
395  << "HGCAL/HGCalDigisV/"
396  << nameDetector_ << " layer = "
397  << layers_ << " with the first one at "
398  << firstLayer_;
399 }
400 
402  edm::Run const&,
403  edm::EventSetup const&) {
404 
405  iB.setCurrentFolder("HGCAL/HGCalDigisV/"+nameDetector_);
406 
407  std::ostringstream histoname;
408  for (int il = 0; il < layers_; ++il) {
409  int ilayer = firstLayer_ + il;
410  histoname.str(""); histoname << "TOA_"<< "layer_" << ilayer;
411  TOA_.push_back(iB.book1D(histoname.str().c_str(),"toa_",1024,0,1024));
412 
413  histoname.str(""); histoname << "ADC_" << "layer_" << ilayer;
414  ADC_.push_back(iB.book1D(histoname.str().c_str(), "ADCDigiOccupancy",1024,0,1024));
415 
416  histoname.str(""); histoname << "TOT_" << "layer_" << ilayer;
417  TOT_.push_back(iB.book1D(histoname.str().c_str(), "TOTDigiOccupancy",4096,0,4096));
418 
419  histoname.str(""); histoname << "DigiOccupancy_XY_" << "layer_" << ilayer;
420  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
421 
422  histoname.str(""); histoname << "DigiOccupancy_Plus_" << "layer_" << ilayer;
423  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
424  histoname.str(""); histoname << "DigiOccupancy_Minus_" << "layer_" << ilayer;
425  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
426  }
427 
428  histoname.str(""); histoname << "SUMOfDigiOccupancy_Plus";
429  MeanDigiOccupancy_Plus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_-0.5);
430  histoname.str(""); histoname << "SUMOfRecDigiOccupancy_Minus";
431  MeanDigiOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5,layers_-0.5);
432 }
433 
434 
435 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
436 
438 
439 //define this as a plug-in
HGCalGeometryMode::GeometryMode geomMode() const
Geometry mode.
Definition: HGCalTopology.h:88
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
bool mode() const
Definition: HGCSample.h:59
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:146
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< MonitorElement * > TOA_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< MonitorElement * > DigiOccupancy_XY_
std::vector< MonitorElement * > TOT_
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:166
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int layers(bool reco) const
bool threshold() const
Definition: HGCSample.h:58
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
int layer() const
get the layer #
Definition: HFNoseDetId.h:58
int layer() const
get the layer #
const HGCalTopology & topology() const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
edm::DataFrame::id_type id() const
HGCalDigiValidation(const edm::ParameterSet &)
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
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
T const * product() const
Definition: Handle.h:74
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
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)
void digiValidation(const T1 &detId, const T2 *geom, int layer, uint16_t adc, double charge, bool mode, bool threshold)
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:59
size_type size() const
T get() const
Definition: EventSetup.h:71
int firstLayer() const
bool isValid() const
Definition: ESHandle.h:44
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:45