CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  auto temp = iConfig.getParameter<edm::InputTag>("DigiSource");
56  if( nameDetector_ == "HGCalEESensitive" ) {
57  digiSource_ = consumes<HGCEEDigiCollection>(temp);
58  } else if ( nameDetector_ == "HGCalHESiliconSensitive" ||
59  nameDetector_ == "HGCalHEScintillatorSensitive" ) {
60  digiSource_ = consumes<HGCHEDigiCollection>(temp);
61  } else if ( nameDetector_ == "HCal" ) {
62  digiSource_ =
63  consumes<edm::SortedCollection<HcalUpgradeDataFrame> >(temp);
64  } else {
65  throw cms::Exception("BadHGCDigiSource")
66  << "HGCal DetectorName given as " << nameDetector_ << " must be: "
67  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", "
68  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
69  }
70 }
71 
72 
74 
76  const edm::EventSetup& iSetup) {
77  OccupancyMap_plus_.clear();
78  OccupancyMap_minus_.clear();
79 
80  const HGCalGeometry* geom0(0);
81  const CaloGeometry* geom1(0);
82  if (nameDetector_ == "HCal") {
84  iSetup.get<CaloGeometryRecord>().get(geom);
85  if (!geom.isValid()) edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry Object for " << nameDetector_;
86  geom1 = geom.product();
87  } else {
89  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
90  if (!geom.isValid()) edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry Object for " << nameDetector_;
91  geom0 = geom.product();
92  }
93 
94  unsigned int ntot(0), nused(0);
95  if (nameDetector_ == "HGCalEESensitive") {
96  //HGCalEE
97  edm::Handle<HGCEEDigiCollection> theHGCEEDigiContainers;
98  iEvent.getByToken(digiSource_, theHGCEEDigiContainers);
99  if (theHGCEEDigiContainers.isValid()) {
100  if (verbosity_>0)
101  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
102  << theHGCEEDigiContainers->size()
103  << " element(s)";
104 
105  for (HGCEEDigiCollection::const_iterator it =theHGCEEDigiContainers->begin();
106  it !=theHGCEEDigiContainers->end(); ++it) {
107  ntot++; nused++;
108  HGCEEDetId detId = (it->id());
109  int layer = detId.layer();
110  HGCSample hgcSample = it->sample(SampleIndx_);
111  uint16_t gain = hgcSample.toa();
112  uint16_t adc = hgcSample.data();
113  double charge = adc*gain;
114  digiValidation(detId, geom0, layer, adc, charge);
115  }
116  fillDigiInfo();
117  } else {
118  edm::LogWarning("HGCalValidation") << "HGCEEDigiCollection handle does not exist !!!";
119  }
120  } else if ((nameDetector_ == "HGCalHESiliconSensitive") ||
121  (nameDetector_ == "HGCalHEScintillatorSensitive")) {
122  //HGCalHE
123  edm::Handle<HGCHEDigiCollection> theHGCHEDigiContainers;
124  iEvent.getByToken(digiSource_, theHGCHEDigiContainers);
125  if (theHGCHEDigiContainers.isValid()) {
126  if (verbosity_>0)
127  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
128  << theHGCHEDigiContainers->size()
129  << " element(s)";
130 
131  for (HGCHEDigiCollection::const_iterator it =theHGCHEDigiContainers->begin();
132  it !=theHGCHEDigiContainers->end(); ++it) {
133  ntot++; nused++;
134  HGCHEDetId detId = (it->id());
135  int layer = detId.layer();
136  HGCSample hgcSample = it->sample(SampleIndx_);
137  uint16_t gain = hgcSample.toa();
138  uint16_t adc = hgcSample.data();
139  double charge = adc*gain;
140  digiValidation(detId, geom0, layer, adc, charge);
141  }
142  fillDigiInfo();
143  } else {
144  edm::LogWarning("HGCalValidation") << "HGCHEDigiCollection handle does not exist !!!";
145  }
146  } else if (nameDetector_ == "HCal") {
147  //HE
149  iEvent.getByToken(digiSource_, theHEDigiContainers);
150  if (theHEDigiContainers.isValid()) {
151  if (verbosity_>0)
152  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
153  << theHEDigiContainers->size()
154  << " element(s)";
155  edm::ESHandle<HcalDbService> conditions;
156  iSetup.get<HcalDbRecord > ().get(conditions);
157 
158  for (edm::SortedCollection<HcalUpgradeDataFrame>::const_iterator it =theHEDigiContainers->begin();
159  it !=theHEDigiContainers->end(); ++it) {
160  HcalDetId detId = (it->id());
161  ntot++;
162  if (detId.subdet() == HcalEndcap) {
163  nused++;
164  HcalCalibrations calibrations = conditions->getHcalCalibrations(detId);
165  const HcalQIECoder* channelCoder = conditions->getHcalCoder(detId);
166  const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
167  HcalCoderDb coder(*channelCoder, *shape);
168  CaloSamples tool;
169  coder.adc2fC(*it, tool);
170  int layer = detId.depth();
171  uint16_t adc = (*it)[SampleIndx_].adc();
172  int capid = (*it)[SampleIndx_].capid();
173  double charge = (tool[SampleIndx_] - calibrations.pedestal(capid));
174  digiValidation(detId, geom1, layer, adc, charge);
175  }
176  }
177  fillDigiInfo();
178  } else {
179  edm::LogWarning("HGCalValidation") << "HGCHEDigiCollection handle does not exist !!!";
180  }
181  } else {
182  edm::LogWarning("HGCalValidation") << "invalid detector name !! "
183  << nameDetector_;
184  }
185  edm::LogInfo("HGCalValidation") << "Event " << iEvent.id().event()
186  << " with " << ntot << " total and "
187  << nused << " used digis";
188 }
189 
190 template<class T1, class T2>
191 void HGCalDigiValidation::digiValidation(const T1& detId, const T2* geom,
192  int layer, uint16_t adc, double charge) {
193 
194  if (verbosity_>1) edm::LogInfo("HGCalValidation") << detId;
195  DetId id1 = DetId(detId.rawId());
196  GlobalPoint global1 = geom->getPosition(id1);
197 
198  if (verbosity_>1)
199  edm::LogInfo("HGCalValidation") << " adc = " << adc
200  << " charge = " << charge;
201 
202  digiInfo hinfo;
203  hinfo.x = global1.x();
204  hinfo.y = global1.y();
205  hinfo.z = global1.z();
206  hinfo.adc = adc;
207  hinfo.charge = charge; //charges[0];
208  hinfo.layer = layer;
209 
210  if (verbosity_>1)
211  edm::LogInfo("HGCalValidation") << "gx = " << hinfo.x
212  << " gy = " << hinfo.y
213  << " gz = " << hinfo.z;
214 
215  fillDigiInfo(hinfo);
216 
217  if (global1.eta() > 0) fillOccupancyMap(OccupancyMap_plus_, layer -1);
218  else fillOccupancyMap(OccupancyMap_minus_, layer -1);
219 
220 }
221 
222 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
223  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer] ++;
224  else OccupancyMap[layer] = 1;
225 }
226 
228  int ilayer = hinfo.layer -1;
229  charge_.at(ilayer)->Fill(hinfo.charge);
230  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
231  ADC_.at(ilayer)->Fill(hinfo.adc);
232 }
233 
235  for (auto itr = OccupancyMap_plus_.begin();
236  itr != OccupancyMap_plus_.end(); ++itr) {
237  int layer = (*itr).first;
238  int occupancy = (*itr).second;
239  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
240  }
241  for (auto itr = OccupancyMap_minus_.begin();
242  itr != OccupancyMap_minus_.end(); ++itr) {
243  int layer = (*itr).first;
244  int occupancy = (*itr).second;
245  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
246  }
247 }
248 
250  const edm::EventSetup& iSetup) {
251  if (nameDetector_ == "HCal") {
253  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
254  const HcalDDDRecConstants *hcons = &(*pHRNDC);
255  layers_ = hcons->getMaxDepth(1);
256  } else {
258  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
259  const HGCalDDDConstants & hgcons_ = (*pHGDC);
260  layers_ = hgcons_.layers(true);
261  }
262 
263  if (verbosity_>0)
264  edm::LogInfo("HGCalValidation") << "current DQM directory: "
265  << "HGCalDigiV/" << nameDetector_
266  << " layer = "<< layers_;
267 }
268 
270  edm::Run const&,
271  edm::EventSetup const&) {
272 
273  iB.setCurrentFolder("HGCalDigiV/"+nameDetector_);
274 
275  std::ostringstream histoname;
276  for (int ilayer = 0; ilayer < layers_; ilayer++ ) {
277  histoname.str(""); histoname << "charge_"<< "layer_" << ilayer;
278  charge_.push_back(iB.book1D(histoname.str().c_str(),"charge_",100,-25,25));
279 
280  histoname.str(""); histoname << "ADC_" << "layer_" << ilayer;
281  ADC_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy",200,0,1000));
282 
283  histoname.str(""); histoname << "DigiOccupancy_XY_" << "layer_" << ilayer;
284  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
285 
286  histoname.str(""); histoname << "DigiOccupancy_Plus_" << "layer_" << ilayer;
287  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
288  histoname.str(""); histoname << "DigiOccupancy_Minus_" << "layer_" << ilayer;
289  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
290  }
291 
292  histoname.str(""); histoname << "SUMOfDigiOccupancy_Plus";
293  MeanDigiOccupancy_Plus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_-0.5);
294  histoname.str(""); histoname << "SUMOfRecDigiOccupancy_Minus";
295  MeanDigiOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5,layers_-0.5);
296 }
297 
298 
299 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
301  //The following says we do not know what parameters are allowed so do no validation
302  // Please change this to state exactly what you do use, even if it is no parameters
304  desc.setUnknown();
305  descriptions.addDefault(desc);
306 }
307 
309 
310 //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:56
std::vector< MonitorElement * > charge_
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
void analyze(const edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
wrapper for a data word
Definition: HGCSample.h:13
int getMaxDepth(const int type) const
int depth() const
get the tower depth
Definition: HcalDetId.cc:106
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
unsigned int layers(bool reco) const
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const
Definition: HcalCoderDb.cc:60
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
HGCalDigiValidation(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:75
std::vector< MonitorElement * > DigiOccupancy_Minus_
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:276
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
MonitorElement * MeanDigiOccupancy_Minus_
T const * product() const
Definition: ESHandle.h:86
edm::EDGetToken digiSource_
uint32_t toa() const
Definition: HGCSample.h:55
std::map< int, int > OccupancyMap_minus_
std::map< int, int > OccupancyMap_plus_
edm::EventID id() const
Definition: EventBase.h:59
bool isValid() const
Definition: ESHandle.h:47
std::vector< MonitorElement * > ADC_
MonitorElement * MeanDigiOccupancy_Plus_
void fillOccupancyMap(std::map< int, int > &OccupancyMap, int layer)
std::vector< MonitorElement * > DigiOccupancy_Plus_
Definition: Run.h:43