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