CMS 3D CMS Logo

HGCalDigiValidation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HGCalDigiValidation
4 // Class: HGCalDigiValidation
5 //
11 //
12 // Original Author: Raman Khurana
14 // Created: Fri, 31 Jan 2014 18:35:18 GMT
15 // $Id$
16 
17 // system include files
24 
33 
41 
47 
48 #include "CLHEP/Units/GlobalSystemOfUnits.h"
49 #include <cmath>
50 
52  nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
53  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity",0)),
54  SampleIndx_(iConfig.getUntrackedParameter<int>("SampleIndx",5)) {
55  ifHCAL_ = iConfig.getParameter<bool>("ifHCAL");
56  auto temp = iConfig.getParameter<edm::InputTag>("DigiSource");
57  if( nameDetector_ == "HGCalEESensitive" ) {
58  digiSource_ = consumes<HGCEEDigiCollection>(temp);
59  } else if ( nameDetector_ == "HGCalHESiliconSensitive" ||
60  nameDetector_ == "HGCalHEScintillatorSensitive" ) {
61  digiSource_ = consumes<HGCHEDigiCollection>(temp);
62  } else if ( nameDetector_ == "HCal" ) {
63  if (ifHCAL_) digiSource_ = consumes<QIE11DigiCollection>(temp);
64  else digiSource_ = consumes<HGCBHDigiCollection>(temp);
65  } else {
66  throw cms::Exception("BadHGCDigiSource")
67  << "HGCal DetectorName given as " << nameDetector_ << " must be: "
68  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", "
69  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
70  }
71 }
72 
73 
75 
77  const edm::EventSetup& iSetup) {
78  OccupancyMap_plus_.clear();
79  OccupancyMap_minus_.clear();
80 
81  const HGCalGeometry* geom0(0);
82  const CaloGeometry* geom1(0);
83  if (nameDetector_ == "HCal") {
85  iSetup.get<CaloGeometryRecord>().get(geom);
86  if (!geom.isValid()) edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry Object for " << nameDetector_;
87  geom1 = geom.product();
88  } else {
90  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
91  if (!geom.isValid()) edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry Object for " << nameDetector_;
92  geom0 = geom.product();
93  }
94 
95  unsigned int ntot(0), nused(0);
96  if (nameDetector_ == "HGCalEESensitive") {
97  //HGCalEE
98  edm::Handle<HGCEEDigiCollection> theHGCEEDigiContainers;
99  iEvent.getByToken(digiSource_, theHGCEEDigiContainers);
100  if (theHGCEEDigiContainers.isValid()) {
101  if (verbosity_>0)
102  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
103  << theHGCEEDigiContainers->size()
104  << " element(s)";
105 
106  for (HGCEEDigiCollection::const_iterator it =theHGCEEDigiContainers->begin();
107  it !=theHGCEEDigiContainers->end(); ++it) {
108  ntot++; nused++;
109  HGCEEDetId detId = (it->id());
110  int layer = detId.layer();
111  HGCSample hgcSample = it->sample(SampleIndx_);
112  uint16_t gain = hgcSample.toa();
113  uint16_t adc = hgcSample.data();
114  double charge = adc*gain;
115  digiValidation(detId, geom0, layer, adc, charge);
116  }
117  fillDigiInfo();
118  } else {
119  edm::LogWarning("HGCalValidation") << "HGCEEDigiCollection handle does not exist !!!";
120  }
121  } else if ((nameDetector_ == "HGCalHESiliconSensitive") ||
122  (nameDetector_ == "HGCalHEScintillatorSensitive")) {
123  //HGCalHE
124  edm::Handle<HGCHEDigiCollection> theHGCHEDigiContainers;
125  iEvent.getByToken(digiSource_, theHGCHEDigiContainers);
126  if (theHGCHEDigiContainers.isValid()) {
127  if (verbosity_>0)
128  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
129  << theHGCHEDigiContainers->size()
130  << " element(s)";
131 
132  for (HGCHEDigiCollection::const_iterator it =theHGCHEDigiContainers->begin();
133  it !=theHGCHEDigiContainers->end(); ++it) {
134  ntot++; nused++;
135  HGCHEDetId detId = (it->id());
136  int layer = detId.layer();
137  HGCSample hgcSample = it->sample(SampleIndx_);
138  uint16_t gain = hgcSample.toa();
139  uint16_t adc = hgcSample.data();
140  double charge = adc*gain;
141  digiValidation(detId, geom0, layer, adc, charge);
142  }
143  fillDigiInfo();
144  } else {
145  edm::LogWarning("HGCalValidation") << "HGCHEDigiCollection handle does not exist !!!";
146  }
147  } else if ((nameDetector_ == "HCal") && (!ifHCAL_)) {
148  //HGCalBH
149  edm::Handle<HGCBHDigiCollection> theHGCBHDigiContainers;
150  iEvent.getByToken(digiSource_, theHGCBHDigiContainers);
151  if (theHGCBHDigiContainers.isValid()) {
152  if (verbosity_>0)
153  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
154  << theHGCBHDigiContainers->size()
155  << " element(s)";
156 
157  for (HGCBHDigiCollection::const_iterator it =theHGCBHDigiContainers->begin();
158  it !=theHGCBHDigiContainers->end(); ++it) {
159  ntot++; nused++;
160  HcalDetId detId = (it->id());
161  int layer = detId.depth();
162  HGCSample hgcSample = it->sample(SampleIndx_);
163  uint16_t gain = hgcSample.toa();
164  uint16_t adc = hgcSample.data();
165  double charge = adc*gain;
166  digiValidation(detId, geom1, layer, adc, charge);
167  }
168  fillDigiInfo();
169  } else {
170  edm::LogWarning("HGCalValidation") << "HGCBHDigiCollection handle does not exist !!!";
171  }
172  } else if (nameDetector_ == "HCal") {
173  //HE
174  edm::Handle<QIE11DigiCollection> theHEDigiContainers;
175  iEvent.getByToken(digiSource_, theHEDigiContainers);
176  if (theHEDigiContainers.isValid()) {
177  if (verbosity_>0)
178  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
179  << theHEDigiContainers->size()
180  << " element(s)";
181  edm::ESHandle<HcalDbService> conditions;
182  iSetup.get<HcalDbRecord > ().get(conditions);
183 
184  for (QIE11DigiCollection::const_iterator it =theHEDigiContainers->begin();
185  it !=theHEDigiContainers->end(); ++it) {
186  QIE11DataFrame df(*it);
187  HcalDetId detId = (df.id());
188  ntot++;
189  if (detId.subdet() == HcalEndcap) {
190  nused++;
192  const HcalQIECoder* channelCoder = conditions->getHcalCoder(detId);
193  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
194  HcalCoderDb coder(*channelCoder, *shape);
195  CaloSamples tool;
196  coder.adc2fC(df, tool);
197  int layer = detId.depth();
198  uint16_t adc = (df)[SampleIndx_].adc();
199  int capid = (df)[SampleIndx_].capid();
200  double charge = (tool[SampleIndx_] - calibrations.pedestal(capid));
201  digiValidation(detId, geom1, layer, adc, charge);
202  }
203  }
204  fillDigiInfo();
205  } else {
206  edm::LogWarning("HGCalValidation") << "HGCHEDigiCollection handle does not exist !!!";
207  }
208  } else {
209  edm::LogWarning("HGCalValidation") << "invalid detector name !! "
210  << nameDetector_;
211  }
212  edm::LogInfo("HGCalValidation") << "Event " << iEvent.id().event()
213  << " with " << ntot << " total and "
214  << nused << " used digis";
215 }
216 
217 template<class T1, class T2>
218 void HGCalDigiValidation::digiValidation(const T1& detId, const T2* geom,
219  int layer, uint16_t adc, double charge) {
220 
221  if (verbosity_>1) edm::LogInfo("HGCalValidation") << detId;
222  DetId id1 = DetId(detId.rawId());
223  GlobalPoint global1 = geom->getPosition(id1);
224 
225  if (verbosity_>1)
226  edm::LogInfo("HGCalValidation") << " adc = " << adc
227  << " charge = " << charge;
228 
229  digiInfo hinfo;
230  hinfo.x = global1.x();
231  hinfo.y = global1.y();
232  hinfo.z = global1.z();
233  hinfo.adc = adc;
234  hinfo.charge = charge; //charges[0];
235  hinfo.layer = layer;
236 
237  if (verbosity_>1)
238  edm::LogInfo("HGCalValidation") << "gx = " << hinfo.x
239  << " gy = " << hinfo.y
240  << " gz = " << hinfo.z;
241 
242  fillDigiInfo(hinfo);
243 
244  if (global1.eta() > 0) fillOccupancyMap(OccupancyMap_plus_, layer -1);
245  else fillOccupancyMap(OccupancyMap_minus_, layer -1);
246 
247 }
248 
249 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
250  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer] ++;
251  else OccupancyMap[layer] = 1;
252 }
253 
255  int ilayer = hinfo.layer -1;
256  charge_.at(ilayer)->Fill(hinfo.charge);
257  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
258  ADC_.at(ilayer)->Fill(hinfo.adc);
259 }
260 
262  for (auto itr = OccupancyMap_plus_.begin();
263  itr != OccupancyMap_plus_.end(); ++itr) {
264  int layer = (*itr).first;
265  int occupancy = (*itr).second;
266  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
267  }
268  for (auto itr = OccupancyMap_minus_.begin();
269  itr != OccupancyMap_minus_.end(); ++itr) {
270  int layer = (*itr).first;
271  int occupancy = (*itr).second;
272  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
273  }
274 }
275 
277  const edm::EventSetup& iSetup) {
278  if (nameDetector_ == "HCal") {
280  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
281  const HcalDDDRecConstants *hcons = &(*pHRNDC);
282  layers_ = hcons->getMaxDepth(1);
283  } else {
285  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
286  const HGCalDDDConstants & hgcons_ = (*pHGDC);
287  layers_ = hgcons_.layers(true);
288  }
289 
290  if (verbosity_>0)
291  edm::LogInfo("HGCalValidation") << "current DQM directory: "
292  << "HGCalDigiV/" << nameDetector_
293  << " layer = "<< layers_;
294 }
295 
297  edm::Run const&,
298  edm::EventSetup const&) {
299 
300  iB.setCurrentFolder("HGCalDigiV/"+nameDetector_);
301 
302  std::ostringstream histoname;
303  for (int ilayer = 0; ilayer < layers_; ilayer++ ) {
304  histoname.str(""); histoname << "charge_"<< "layer_" << ilayer;
305  charge_.push_back(iB.book1D(histoname.str().c_str(),"charge_",100,-25,25));
306 
307  histoname.str(""); histoname << "ADC_" << "layer_" << ilayer;
308  ADC_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy",200,0,1000));
309 
310  histoname.str(""); histoname << "DigiOccupancy_XY_" << "layer_" << ilayer;
311  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
312 
313  histoname.str(""); histoname << "DigiOccupancy_Plus_" << "layer_" << ilayer;
314  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
315  histoname.str(""); histoname << "DigiOccupancy_Minus_" << "layer_" << ilayer;
316  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
317  }
318 
319  histoname.str(""); histoname << "SUMOfDigiOccupancy_Plus";
320  MeanDigiOccupancy_Plus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_-0.5);
321  histoname.str(""); histoname << "SUMOfRecDigiOccupancy_Minus";
322  MeanDigiOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5,layers_-0.5);
323 }
324 
325 
326 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
328  //The following says we do not know what parameters are allowed so do no validation
329  // Please change this to state exactly what you do use, even if it is no parameters
331  desc.setUnknown();
332  descriptions.addDefault(desc);
333 }
334 
336 
337 //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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#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
void addDefault(ParameterSetDescription const &psetDescription)
unsigned int layers(bool reco) const
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
edm::DataFrame::id_type id() const
HGCalDigiValidation(const edm::ParameterSet &)
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:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
int getMaxDepth(const int &type) const
const T & get() const
Definition: EventSetup.h:55
MonitorElement * MeanDigiOccupancy_Minus_
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
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