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" ) {
105  digiSource_ = consumes<HGCEEDigiCollection>(temp);
106  } else if (nameDetector_ == "HGCalHESiliconSensitive" ||
107  nameDetector_ == "HGCalHEScintillatorSensitive") {
108  digiSource_ = consumes<HGCHEDigiCollection>(temp);
109  } else if (nameDetector_ == "HCal") {
110  if (ifHCAL_) digiSource_ = consumes<QIE11DigiCollection>(temp);
111  else digiSource_ = consumes<HGCBHDigiCollection>(temp);
112  } else {
113  throw cms::Exception("BadHGCDigiSource")
114  << "HGCal DetectorName given as " << nameDetector_ << " must be: "
115  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", "
116  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
117  }
118 }
119 
122  desc.add<std::string>("DetectorName","HGCalEESensitive");
123  desc.add<edm::InputTag>("DigiSource",edm::InputTag("mix","HGCDigisEE"));
124  desc.add<bool>("ifHCAL",false);
125  desc.addUntracked<int>("Verbosity",0);
126  desc.addUntracked<int>("SampleIndx",0);
127  descriptions.add("hgcalDigiValidationEE",desc);
128 }
129 
131  const edm::EventSetup& iSetup) {
132  OccupancyMap_plus_.clear();
133  OccupancyMap_minus_.clear();
134 
135  const HGCalGeometry* geom0(nullptr);
136  const CaloGeometry* geom1(nullptr);
137  if (nameDetector_ == "HCal") {
139  iSetup.get<CaloGeometryRecord>().get(geom);
140  if (!geom.isValid())
141  edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry "
142  << "Object for " << nameDetector_;
143  geom1 = geom.product();
144  } else {
146  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
147  if (!geom.isValid())
148  edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry "
149  << "Object for " << nameDetector_;
150  geom0 = geom.product();
151  }
152 
153  unsigned int ntot(0), nused(0);
154  if (nameDetector_ == "HGCalEESensitive") {
155  //HGCalEE
156  edm::Handle<HGCEEDigiCollection> theHGCEEDigiContainers;
157  iEvent.getByToken(digiSource_, theHGCEEDigiContainers);
158  if (theHGCEEDigiContainers.isValid()) {
159  if (verbosity_>0)
160  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
161  << theHGCEEDigiContainers->size()
162  << " element(s)";
163 
164  for (const auto & it: *(theHGCEEDigiContainers.product())) {
165  ntot++; nused++;
166  HGCalDetId detId = it.id();
167  int layer = detId.layer();
168  HGCSample hgcSample = it.sample(SampleIndx_);
169  uint16_t gain = hgcSample.toa();
170  uint16_t adc = hgcSample.data();
171  double charge = adc*gain;
172  digiValidation(detId, geom0, layer, adc, charge);
173  }
174  fillDigiInfo();
175  } else {
176  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
177  << "exist for HGCEE!!!";
178  }
179  } else if ((nameDetector_ == "HGCalHESiliconSensitive") ||
180  (nameDetector_ == "HGCalHEScintillatorSensitive")) {
181  //HGCalHE
182  edm::Handle<HGCHEDigiCollection> theHGCHEDigiContainers;
183  iEvent.getByToken(digiSource_, theHGCHEDigiContainers);
184  if (theHGCHEDigiContainers.isValid()) {
185  if (verbosity_>0)
186  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
187  << theHGCHEDigiContainers->size()
188  << " element(s)";
189 
190  for (const auto & it: *(theHGCHEDigiContainers.product())) {
191  ntot++; nused++;
192  HGCalDetId detId = it.id();
193  int layer = detId.layer();
194  HGCSample hgcSample = it.sample(SampleIndx_);
195  uint16_t gain = hgcSample.toa();
196  uint16_t adc = hgcSample.data();
197  double charge = adc*gain;
198  digiValidation(detId, geom0, layer, adc, charge);
199  }
200  fillDigiInfo();
201  } else {
202  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
203  << "exist for HGCFH!!!";
204  }
205  } else if ((nameDetector_ == "HCal") && (!ifHCAL_)) {
206  //HGCalBH
207  edm::Handle<HGCBHDigiCollection> theHGCBHDigiContainers;
208  iEvent.getByToken(digiSource_, theHGCBHDigiContainers);
209  if (theHGCBHDigiContainers.isValid()) {
210  if (verbosity_>0)
211  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
212  << theHGCBHDigiContainers->size()
213  << " element(s)";
214 
215  for (const auto & it: *(theHGCBHDigiContainers.product())) {
216  ntot++; nused++;
217  HcalDetId detId = it.id();
218  int layer = detId.depth();
219  HGCSample hgcSample = it.sample(SampleIndx_);
220  uint16_t gain = hgcSample.toa();
221  uint16_t adc = hgcSample.data();
222  double charge = adc*gain;
223  digiValidation(detId, geom1, layer, adc, charge);
224  }
225  fillDigiInfo();
226  } else {
227  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
228  << "exist for HGCBH!!!";
229  }
230  } else if (nameDetector_ == "HCal") {
231  //HE
232  edm::Handle<QIE11DigiCollection> theHEDigiContainers;
233  iEvent.getByToken(digiSource_, theHEDigiContainers);
234  if (theHEDigiContainers.isValid()) {
235  if (verbosity_>0)
236  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
237  << theHEDigiContainers->size()
238  << " element(s)";
239  edm::ESHandle<HcalDbService> conditions;
240  iSetup.get<HcalDbRecord > ().get(conditions);
241 
242  for (const auto & it: *(theHEDigiContainers.product())) {
243  QIE11DataFrame df(it);
244  HcalDetId detId = (df.id());
245  ntot++;
246  if (detId.subdet() == HcalEndcap) {
247  nused++;
249  const HcalQIECoder* channelCoder = conditions->getHcalCoder(detId);
250  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
251  HcalCoderDb coder(*channelCoder, *shape);
252  CaloSamples tool;
253  coder.adc2fC(df, tool);
254  int layer = detId.depth();
255  uint16_t adc = (df)[SampleIndx_].adc();
256  int capid = (df)[SampleIndx_].capid();
257  double charge = (tool[SampleIndx_] - calibrations.pedestal(capid));
258  digiValidation(detId, geom1, layer, adc, charge);
259  }
260  }
261  fillDigiInfo();
262  } else {
263  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
264  << "exist for HGCBH!!!";
265  }
266  } else {
267  edm::LogWarning("HGCalValidation") << "invalid detector name !! "
268  << nameDetector_;
269  }
270  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event()
271  << " with " << ntot << " total and "
272  << nused << " used digis";
273 }
274 
275 template<class T1, class T2>
276 void HGCalDigiValidation::digiValidation(const T1& detId, const T2* geom,
277  int layer, uint16_t adc, double charge) {
278 
279  if (verbosity_>1) edm::LogVerbatim("HGCalValidation") << detId;
280  DetId id1 = DetId(detId.rawId());
281  const GlobalPoint& global1 = geom->getPosition(id1);
282 
283  if (verbosity_>1)
284  edm::LogVerbatim("HGCalValidation") << " adc = " << adc
285  << " charge = " << charge;
286 
287  digiInfo hinfo;
288  hinfo.x = global1.x();
289  hinfo.y = global1.y();
290  hinfo.z = global1.z();
291  hinfo.adc = adc;
292  hinfo.charge = charge; //charges[0];
293  hinfo.layer = layer;
294 
295  if (verbosity_>1)
296  edm::LogVerbatim("HGCalValidation") << "gx = " << hinfo.x
297  << " gy = " << hinfo.y
298  << " gz = " << hinfo.z;
299 
300  fillDigiInfo(hinfo);
301 
302  if (global1.eta() > 0) fillOccupancyMap(OccupancyMap_plus_, layer -1);
303  else fillOccupancyMap(OccupancyMap_minus_, layer -1);
304 
305 }
306 
307 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
308  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer] ++;
309  else OccupancyMap[layer] = 1;
310 }
311 
313  int ilayer = hinfo.layer -1;
314  charge_.at(ilayer)->Fill(hinfo.charge);
315  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
316  ADC_.at(ilayer)->Fill(hinfo.adc);
317 }
318 
320  for (const auto & itr : OccupancyMap_plus_) {
321  int layer = itr.first;
322  int occupancy = itr.second;
323  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
324  }
325  for (const auto & itr : OccupancyMap_minus_) {
326  int layer = itr.first;
327  int occupancy = itr.second;
328  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
329  }
330 }
331 
333  const edm::EventSetup& iSetup) {
334  if (nameDetector_ == "HCal") {
336  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
337  const HcalDDDRecConstants *hcons = &(*pHRNDC);
338  layers_ = hcons->getMaxDepth(1);
339  } else {
341  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
342  const HGCalDDDConstants & hgcons_ = (*pHGDC);
343  layers_ = hgcons_.layers(true);
344  }
345 
346  if (verbosity_>0)
347  edm::LogVerbatim("HGCalValidation") << "current DQM directory: "
348  << "HGCalDigiV/" << nameDetector_
349  << " layer = "<< layers_;
350 }
351 
353  edm::Run const&,
354  edm::EventSetup const&) {
355 
356  iB.setCurrentFolder("HGCalDigiV/"+nameDetector_);
357 
358  std::ostringstream histoname;
359  for (int ilayer = 0; ilayer < layers_; ilayer++ ) {
360  histoname.str(""); histoname << "charge_"<< "layer_" << ilayer;
361  charge_.push_back(iB.book1D(histoname.str().c_str(),"charge_",100,-25,25));
362 
363  histoname.str(""); histoname << "ADC_" << "layer_" << ilayer;
364  ADC_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy",200,0,1000));
365 
366  histoname.str(""); histoname << "DigiOccupancy_XY_" << "layer_" << ilayer;
367  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
368 
369  histoname.str(""); histoname << "DigiOccupancy_Plus_" << "layer_" << ilayer;
370  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
371  histoname.str(""); histoname << "DigiOccupancy_Minus_" << "layer_" << ilayer;
372  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
373  }
374 
375  histoname.str(""); histoname << "SUMOfDigiOccupancy_Plus";
376  MeanDigiOccupancy_Plus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_-0.5);
377  histoname.str(""); histoname << "SUMOfRecDigiOccupancy_Minus";
378  MeanDigiOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5,layers_-0.5);
379 }
380 
381 
382 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
383 
385 
386 //define this as a plug-in
int adc(sample_type sample)
get the ADC sample (12 bits)
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:49
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#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_
double pedestal(int fCapId) const
get pedestal for capid=0..3
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.cc:108
int iEvent
Definition: GenABIO.cc:230
unsigned int layers(bool reco) const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
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
std::vector< MonitorElement * > DigiOccupancy_Minus_
Definition: DetId.h:18
void digiValidation(const T1 &detId, const T2 *geom, int, uint16_t, double)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
T const * product() const
Definition: Handle.h:81
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
int getMaxDepth(const int &type) const
const T & get() const
Definition: EventSetup.h:59
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_
std::map< int, int > OccupancyMap_plus_
edm::EventID id() const
Definition: EventBase.h:60
size_type size() const
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:43