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 
24 
26 
29 
39 
47 
48 #include "CLHEP/Units/GlobalSystemOfUnits.h"
49 
50 // user include files
51 
52 
54 
55 public:
56  struct digiInfo{
58  x = y = z = 0.0;
59  layer = adc = charge = 0;
60  }
61  double x, y, z;
62  int layer, charge, adc;
63  };
64 
65  explicit HGCalDigiValidation(const edm::ParameterSet&);
66  ~HGCalDigiValidation() override {}
67 
68  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
69  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
70  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
71  void analyze(const edm::Event&, const edm::EventSetup&) override;
72 
73 private:
75  void fillDigiInfo();
76  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
77  template<class T1, class T2>
78  void digiValidation(const T1& detId, const T2* geom, int, uint16_t, double);
79 
80  // ----------member data ---------------------------
83  bool ifHCAL_;
85  int layers_;
86 
87  std::map<int, int> OccupancyMap_plus_;
88  std::map<int, int> OccupancyMap_minus_;
89 
90  std::vector<MonitorElement*> charge_;
91  std::vector<MonitorElement*> DigiOccupancy_XY_;
92  std::vector<MonitorElement*> ADC_;
93  std::vector<MonitorElement*> DigiOccupancy_Plus_;
94  std::vector<MonitorElement*> DigiOccupancy_Minus_;
97 };
98 
100  nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
101  ifHCAL_(iConfig.getParameter<bool>("ifHCAL")),
102  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity",0)),
103  SampleIndx_(iConfig.getUntrackedParameter<int>("SampleIndx",5)) {
104 
105  auto temp = iConfig.getParameter<edm::InputTag>("DigiSource");
106  if (nameDetector_ == "HGCalEESensitive" ) {
107  digiSource_ = consumes<HGCEEDigiCollection>(temp);
108  } else if (nameDetector_ == "HGCalHESiliconSensitive" ||
109  nameDetector_ == "HGCalHEScintillatorSensitive") {
110  digiSource_ = consumes<HGCHEDigiCollection>(temp);
111  } else if (nameDetector_ == "HCal") {
112  if (ifHCAL_) digiSource_ = consumes<QIE11DigiCollection>(temp);
113  else digiSource_ = consumes<HGCBHDigiCollection>(temp);
114  } else {
115  throw cms::Exception("BadHGCDigiSource")
116  << "HGCal DetectorName given as " << nameDetector_ << " must be: "
117  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", "
118  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
119  }
120 }
121 
124  desc.add<std::string>("DetectorName","HGCalEESensitive");
125  desc.add<edm::InputTag>("DigiSource",edm::InputTag("mix","HGCDigisEE"));
126  desc.add<bool>("ifHCAL",false);
127  desc.addUntracked<int>("Verbosity",0);
128  desc.addUntracked<int>("SampleIndx",0);
129  descriptions.add("hgcalDigiValidationEE",desc);
130 }
131 
133  const edm::EventSetup& iSetup) {
134  OccupancyMap_plus_.clear();
135  OccupancyMap_minus_.clear();
136 
137  const HGCalGeometry* geom0(nullptr);
138  const CaloGeometry* geom1(nullptr);
139  if (nameDetector_ == "HCal") {
141  iSetup.get<CaloGeometryRecord>().get(geom);
142  if (!geom.isValid())
143  edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry "
144  << "Object for " << nameDetector_;
145  geom1 = geom.product();
146  } else {
148  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
149  if (!geom.isValid())
150  edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry "
151  << "Object for " << nameDetector_;
152  geom0 = geom.product();
153  }
154 
155  unsigned int ntot(0), nused(0);
156  if (nameDetector_ == "HGCalEESensitive") {
157  //HGCalEE
158  edm::Handle<HGCEEDigiCollection> 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 (HGCEEDigiCollection::const_iterator it =theHGCEEDigiContainers->begin();
167  it !=theHGCEEDigiContainers->end(); ++it) {
168  ntot++; nused++;
169  HGCEEDetId detId = (it->id());
170  int layer = detId.layer();
171  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::LogWarning("HGCalValidation") << "DigiCollection handle does not "
180  << "exist for HGCEE!!!";
181  }
182  } else if ((nameDetector_ == "HGCalHESiliconSensitive") ||
183  (nameDetector_ == "HGCalHEScintillatorSensitive")) {
184  //HGCalHE
185  edm::Handle<HGCHEDigiCollection> 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 (HGCHEDigiCollection::const_iterator it =theHGCHEDigiContainers->begin();
194  it !=theHGCHEDigiContainers->end(); ++it) {
195  ntot++; nused++;
196  HGCHEDetId detId = (it->id());
197  int layer = detId.layer();
198  HGCSample hgcSample = it->sample(SampleIndx_);
199  uint16_t gain = hgcSample.toa();
200  uint16_t adc = hgcSample.data();
201  double charge = adc*gain;
202  digiValidation(detId, geom0, layer, adc, charge);
203  }
204  fillDigiInfo();
205  } else {
206  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
207  << "exist for HGCFH!!!";
208  }
209  } else if ((nameDetector_ == "HCal") && (!ifHCAL_)) {
210  //HGCalBH
211  edm::Handle<HGCBHDigiCollection> theHGCBHDigiContainers;
212  iEvent.getByToken(digiSource_, theHGCBHDigiContainers);
213  if (theHGCBHDigiContainers.isValid()) {
214  if (verbosity_>0)
215  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with "
216  << theHGCBHDigiContainers->size()
217  << " element(s)";
218 
219  for (HGCBHDigiCollection::const_iterator it =theHGCBHDigiContainers->begin();
220  it !=theHGCBHDigiContainers->end(); ++it) {
221  ntot++; nused++;
222  HcalDetId detId = (it->id());
223  int layer = detId.depth();
224  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 (QIE11DigiCollection::const_iterator it =theHEDigiContainers->begin();
248  it !=theHEDigiContainers->end(); ++it) {
249  QIE11DataFrame df(*it);
250  HcalDetId detId = (df.id());
251  ntot++;
252  if (detId.subdet() == HcalEndcap) {
253  nused++;
255  const HcalQIECoder* channelCoder = conditions->getHcalCoder(detId);
256  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
257  HcalCoderDb coder(*channelCoder, *shape);
258  CaloSamples tool;
259  coder.adc2fC(df, tool);
260  int layer = detId.depth();
261  uint16_t adc = (df)[SampleIndx_].adc();
262  int capid = (df)[SampleIndx_].capid();
263  double charge = (tool[SampleIndx_] - calibrations.pedestal(capid));
264  digiValidation(detId, geom1, layer, adc, charge);
265  }
266  }
267  fillDigiInfo();
268  } else {
269  edm::LogWarning("HGCalValidation") << "DigiCollection handle does not "
270  << "exist for HGCBH!!!";
271  }
272  } else {
273  edm::LogWarning("HGCalValidation") << "invalid detector name !! "
274  << nameDetector_;
275  }
276  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event()
277  << " with " << ntot << " total and "
278  << nused << " used digis";
279 }
280 
281 template<class T1, class T2>
282 void HGCalDigiValidation::digiValidation(const T1& detId, const T2* geom,
283  int layer, uint16_t adc, double charge) {
284 
285  if (verbosity_>1) edm::LogVerbatim("HGCalValidation") << detId;
286  DetId id1 = DetId(detId.rawId());
287  const GlobalPoint& global1 = geom->getPosition(id1);
288 
289  if (verbosity_>1)
290  edm::LogVerbatim("HGCalValidation") << " adc = " << adc
291  << " charge = " << charge;
292 
293  digiInfo hinfo;
294  hinfo.x = global1.x();
295  hinfo.y = global1.y();
296  hinfo.z = global1.z();
297  hinfo.adc = adc;
298  hinfo.charge = charge; //charges[0];
299  hinfo.layer = layer;
300 
301  if (verbosity_>1)
302  edm::LogVerbatim("HGCalValidation") << "gx = " << hinfo.x
303  << " gy = " << hinfo.y
304  << " gz = " << hinfo.z;
305 
306  fillDigiInfo(hinfo);
307 
308  if (global1.eta() > 0) fillOccupancyMap(OccupancyMap_plus_, layer -1);
309  else fillOccupancyMap(OccupancyMap_minus_, layer -1);
310 
311 }
312 
313 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
314  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer] ++;
315  else OccupancyMap[layer] = 1;
316 }
317 
319  int ilayer = hinfo.layer -1;
320  charge_.at(ilayer)->Fill(hinfo.charge);
321  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
322  ADC_.at(ilayer)->Fill(hinfo.adc);
323 }
324 
326  for (auto itr = OccupancyMap_plus_.begin();
327  itr != OccupancyMap_plus_.end(); ++itr) {
328  int layer = (*itr).first;
329  int occupancy = (*itr).second;
330  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
331  }
332  for (auto itr = OccupancyMap_minus_.begin();
333  itr != OccupancyMap_minus_.end(); ++itr) {
334  int layer = (*itr).first;
335  int occupancy = (*itr).second;
336  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
337  }
338 }
339 
341  const edm::EventSetup& iSetup) {
342  if (nameDetector_ == "HCal") {
344  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
345  const HcalDDDRecConstants *hcons = &(*pHRNDC);
346  layers_ = hcons->getMaxDepth(1);
347  } else {
349  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
350  const HGCalDDDConstants & hgcons_ = (*pHGDC);
351  layers_ = hgcons_.layers(true);
352  }
353 
354  if (verbosity_>0)
355  edm::LogVerbatim("HGCalValidation") << "current DQM directory: "
356  << "HGCalDigiV/" << nameDetector_
357  << " layer = "<< layers_;
358 }
359 
361  edm::Run const&,
362  edm::EventSetup const&) {
363 
364  iB.setCurrentFolder("HGCalDigiV/"+nameDetector_);
365 
366  std::ostringstream histoname;
367  for (int ilayer = 0; ilayer < layers_; ilayer++ ) {
368  histoname.str(""); histoname << "charge_"<< "layer_" << ilayer;
369  charge_.push_back(iB.book1D(histoname.str().c_str(),"charge_",100,-25,25));
370 
371  histoname.str(""); histoname << "ADC_" << "layer_" << ilayer;
372  ADC_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy",200,0,1000));
373 
374  histoname.str(""); histoname << "DigiOccupancy_XY_" << "layer_" << ilayer;
375  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
376 
377  histoname.str(""); histoname << "DigiOccupancy_Plus_" << "layer_" << ilayer;
378  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
379  histoname.str(""); histoname << "DigiOccupancy_Minus_" << "layer_" << ilayer;
380  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
381  }
382 
383  histoname.str(""); histoname << "SUMOfDigiOccupancy_Plus";
384  MeanDigiOccupancy_Plus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_-0.5);
385  histoname.str(""); histoname << "SUMOfRecDigiOccupancy_Minus";
386  MeanDigiOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5,layers_-0.5);
387 }
388 
389 
390 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
391 
393 
394 //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_
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
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_
std::vector< HGCEEDataFrame >::const_iterator const_iterator
double pedestal(int fCapId) const
get pedestal for capid=0..3
int layer() const
get the layer #
Definition: HGCHEDetId.h:50
const_iterator begin() const
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_
const_iterator end() const
Definition: DetId.h:18
int layer() const
get the layer #
Definition: HGCEEDetId.h:49
void digiValidation(const T1 &detId, const T2 *geom, int, uint16_t, double)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
int getMaxDepth(const int &type) const
const T & get() const
Definition: EventSetup.h:58
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_
const_iterator end() const
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)
std::vector< MonitorElement * > DigiOccupancy_Plus_
const_iterator begin() const
Definition: Run.h:43