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 
16 
19 
27 
32 
33 #include "CLHEP/Units/GlobalSystemOfUnits.h"
34 
35 // user include files
36 
38 public:
39  struct digiInfo {
41  x = y = z = charge = 0.0;
42  layer = adc = 0;
43  mode = threshold = false;
44  }
45  double x, y, z, charge;
46  int layer, adc;
47  bool mode, threshold; //tot mode and zero supression
48  };
49 
50  explicit HGCalDigiValidation(const edm::ParameterSet&);
51  ~HGCalDigiValidation() override {}
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
55  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
56  void analyze(const edm::Event&, const edm::EventSetup&) override;
57 
58 private:
59  void fillDigiInfo(digiInfo& hinfo);
60  void fillDigiInfo();
61  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
62  template <class T1, class T2>
63  void digiValidation(
64  const T1& detId, const T2* geom, int layer, uint16_t adc, double charge, bool mode, bool threshold);
65 
66  // ----------member data ---------------------------
68  const bool ifNose_;
69  const int verbosity_, SampleIndx_;
74 
75  std::map<int, int> OccupancyMap_plus_;
76  std::map<int, int> OccupancyMap_minus_;
77 
78  std::vector<MonitorElement*> TOA_;
79  std::vector<MonitorElement*> DigiOccupancy_XY_;
80  std::vector<MonitorElement*> ADC_;
81  std::vector<MonitorElement*> TOT_;
82  std::vector<MonitorElement*> DigiOccupancy_Plus_;
83  std::vector<MonitorElement*> DigiOccupancy_Minus_;
86 };
87 
89  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
90  ifNose_(iConfig.getParameter<bool>("ifNose")),
91  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
92  SampleIndx_(iConfig.getUntrackedParameter<int>("SampleIndx", 0)),
95  tok_hgcalg_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameDetector_})),
96  firstLayer_(1) {
97  auto temp = iConfig.getParameter<edm::InputTag>("DigiSource");
98  if ((nameDetector_ == "HGCalEESensitive") || (nameDetector_ == "HGCalHESiliconSensitive") ||
99  (nameDetector_ == "HGCalHEScintillatorSensitive") || (nameDetector_ == "HGCalHFNoseSensitive")) {
100  digiSource_ = consumes<HGCalDigiCollection>(temp);
101  } else {
102  throw cms::Exception("BadHGCDigiSource") << "HGCal DetectorName given as " << nameDetector_ << " must be: "
103  << "\"HGCalEESensitive\", \"HGCalHESiliconSensitive\", or "
104  << "\"HGCalHEScintillatorSensitive\", \"HGCalHFNoseSensitive\"!";
105  }
106 }
107 
110  desc.add<std::string>("DetectorName", "HGCalEESensitive");
111  desc.add<edm::InputTag>("DigiSource", edm::InputTag("hgcalDigis", "EE"));
112  desc.add<bool>("ifNose", false);
113  desc.addUntracked<int>("Verbosity", 0);
114  desc.addUntracked<int>("SampleIndx", 2); // central bx
115  descriptions.add("hgcalDigiValidationEEDefault", desc);
116 }
117 
119  OccupancyMap_plus_.clear();
120  OccupancyMap_minus_.clear();
121 
122  int geomType(0);
123  const HGCalGeometry* geom0 = &iSetup.getData(tok_hgcalg_);
124  if (geom0->topology().waferHexagon8())
125  geomType = 1;
126  else if (geom0->topology().tileTrapezoid())
127  geomType = 2;
128  if (nameDetector_ == "HGCalHFNoseSensitive")
129  geomType = 3;
130 
131  unsigned int ntot(0), nused(0);
132  if ((nameDetector_ == "HGCalEESensitive") || (nameDetector_ == "HGCalHFNoseSensitive")) {
133  //HGCalEE
134  edm::Handle<HGCalDigiCollection> theHGCEEDigiContainers;
135  iEvent.getByToken(digiSource_, theHGCEEDigiContainers);
136  if (theHGCEEDigiContainers.isValid()) {
137  if (verbosity_ > 0)
138  edm::LogVerbatim("HGCalValidation")
139  << nameDetector_ << " with " << theHGCEEDigiContainers->size() << " element(s)";
140  for (const auto& it : *(theHGCEEDigiContainers.product())) {
141  ntot++;
142  nused++;
143  DetId detId = it.id();
144  int layer = ((geomType == 0) ? HGCalDetId(detId).layer()
145  : (geomType == 1) ? HGCSiliconDetId(detId).layer()
146  : HFNoseDetId(detId).layer());
147  const HGCSample& hgcSample = it.sample(SampleIndx_);
148  uint16_t gain = hgcSample.toa();
149  uint16_t adc = hgcSample.data();
150  double charge = gain;
151  bool totmode = hgcSample.mode();
152  bool zerothreshold = hgcSample.threshold();
153  digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
154  }
155  fillDigiInfo();
156  } else {
157  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
158  << "exist for " << nameDetector_;
159  }
160  } else if ((nameDetector_ == "HGCalHESiliconSensitive") || (nameDetector_ == "HGCalHEScintillatorSensitive")) {
161  //HGCalHE
162  edm::Handle<HGCalDigiCollection> theHGCHEDigiContainers;
163  iEvent.getByToken(digiSource_, theHGCHEDigiContainers);
164  if (theHGCHEDigiContainers.isValid()) {
165  if (verbosity_ > 0)
166  edm::LogVerbatim("HGCalValidation")
167  << nameDetector_ << " with " << theHGCHEDigiContainers->size() << " element(s)";
168  for (const auto& it : *(theHGCHEDigiContainers.product())) {
169  ntot++;
170  nused++;
171  DetId detId = it.id();
172  int layer = ((geomType == 0)
173  ? HGCalDetId(detId).layer()
174  : ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer()));
175  const HGCSample& hgcSample = it.sample(SampleIndx_);
176  uint16_t gain = hgcSample.toa();
177  uint16_t adc = hgcSample.data();
178  double charge = gain;
179  bool totmode = hgcSample.mode();
180  bool zerothreshold = hgcSample.threshold();
181  digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
182  }
183  fillDigiInfo();
184  } else {
185  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
186  << "exist for " << nameDetector_;
187  }
188  } else {
189  edm::LogWarning("HGCalValidation") << "invalid detector name !! " << nameDetector_;
190  }
191  if (verbosity_ > 0)
192  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
193  << " used digis";
194 }
195 
196 template <class T1, class T2>
198  const T1& detId, const T2* geom, int layer, uint16_t adc, double charge, bool mode, bool threshold) {
199  if (verbosity_ > 1)
200  edm::LogVerbatim("HGCalValidation") << std::hex << detId.rawId() << std::dec << " " << detId.rawId();
201  DetId id1 = DetId(detId.rawId());
202  const GlobalPoint& global1 = geom->getPosition(id1);
203 
204  if (verbosity_ > 1)
205  edm::LogVerbatim("HGCalValidation") << " adc = " << adc << " toa = " << charge;
206 
207  digiInfo hinfo;
208  hinfo.x = global1.x();
209  hinfo.y = global1.y();
210  hinfo.z = global1.z();
211  hinfo.adc = adc;
212  hinfo.charge = charge;
213  hinfo.layer = layer - firstLayer_;
214  hinfo.mode = mode;
215  hinfo.threshold = threshold;
216 
217  if (verbosity_ > 1)
218  edm::LogVerbatim("HGCalValidation") << "gx = " << hinfo.x << " gy = " << hinfo.y << " gz = " << hinfo.z;
219 
220  if (global1.eta() > 0)
222  else
224 
226 }
227 
228 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
229  if (OccupancyMap.find(layer) != OccupancyMap.end())
230  OccupancyMap[layer]++;
231  else
232  OccupancyMap[layer] = 1;
233 }
234 
236  int ilayer = hinfo.layer;
237  TOA_.at(ilayer)->Fill(hinfo.charge);
238 
239  if (hinfo.mode) {
240  TOT_.at(ilayer)->Fill(hinfo.adc);
241  }
242 
243  if (!hinfo.mode && hinfo.threshold) {
244  ADC_.at(ilayer)->Fill(hinfo.adc);
245  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
246  }
247 }
248 
250  for (const auto& itr : OccupancyMap_plus_) {
251  int layer = itr.first;
252  int occupancy = itr.second;
253  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
254  }
255  for (const auto& itr : OccupancyMap_minus_) {
256  int layer = itr.first;
257  int occupancy = itr.second;
258  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
259  }
260 }
261 
263  const HGCalDDDConstants* hgcons = &iSetup.getData(tok_hgcalc_);
264  layers_ = hgcons->layers(true);
265  firstLayer_ = hgcons->firstLayer();
266 
267  if (verbosity_ > 0)
268  edm::LogVerbatim("HGCalValidation") << "current DQM directory: "
269  << "HGCAL/HGCalDigisV/" << nameDetector_ << " layer = " << layers_
270  << " with the first one at " << firstLayer_;
271 }
272 
274  iB.setCurrentFolder("HGCAL/HGCalDigisV/" + nameDetector_);
275 
276  std::ostringstream histoname;
277  for (int il = 0; il < layers_; ++il) {
278  int ilayer = firstLayer_ + il;
279  auto istr1 = std::to_string(ilayer);
280  while (istr1.size() < 2) {
281  istr1.insert(0, "0");
282  }
283  histoname.str("");
284  histoname << "TOA_"
285  << "layer_" << istr1;
286  TOA_.push_back(iB.book1D(histoname.str().c_str(), "toa_", 1024, 0, 1024));
287 
288  histoname.str("");
289  histoname << "ADC_"
290  << "layer_" << istr1;
291  ADC_.push_back(iB.book1D(histoname.str().c_str(), "ADCDigiOccupancy", 1024, 0, 1024));
292 
293  histoname.str("");
294  histoname << "TOT_"
295  << "layer_" << istr1;
296  TOT_.push_back(iB.book1D(histoname.str().c_str(), "TOTDigiOccupancy", 4096, 0, 4096));
297 
298  histoname.str("");
299  histoname << "DigiOccupancy_XY_"
300  << "layer_" << istr1;
301  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
302 
303  histoname.str("");
304  histoname << "DigiOccupancy_Plus_"
305  << "layer_" << istr1;
306  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
307  histoname.str("");
308  histoname << "DigiOccupancy_Minus_"
309  << "layer_" << istr1;
310  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
311  }
312 
313  histoname.str("");
314  histoname << "SUMOfDigiOccupancy_Plus";
315  MeanDigiOccupancy_Plus_ = iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
316  histoname.str("");
317  histoname << "SUMOfRecDigiOccupancy_Minus";
319  iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
320 }
321 
322 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
323 
325 
326 //define this as a plug-in
Log< level::Info, true > LogVerbatim
void analyze(const edm::Event &, const edm::EventSetup &) override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
int layer() const
get the layer #
Definition: HFNoseDetId.h:57
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > tok_hgcalg_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
size_type size() const
std::vector< MonitorElement * > TOA_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< MonitorElement * > DigiOccupancy_XY_
T const * product() const
Definition: Handle.h:70
bool mode() const
Definition: HGCSample.h:67
std::vector< MonitorElement * > TOT_
std::string to_string(const V &value)
Definition: OMSAccess.h:71
int firstLayer() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
wrapper for a data word
Definition: HGCSample.h:13
constexpr std::array< uint8_t, layerIndexSize > layer
uint16_t data() const
Definition: HGCSample.h:70
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
int layer() const
get the layer #
int iEvent
Definition: GenABIO.cc:224
int layer() const
get the layer #
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > tok_hgcalc_
Transition
Definition: Transition.h:12
HGCalDigiValidation(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int layers(bool reco) const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const std::string nameDetector_
std::vector< MonitorElement * > DigiOccupancy_Minus_
uint16_t toa() const
Definition: HGCSample.h:69
Definition: DetId.h:17
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
MonitorElement * MeanDigiOccupancy_Minus_
int layer() const
get the layer #
Definition: HGCalDetId.h:46
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void digiValidation(const T1 &detId, const T2 *geom, int layer, uint16_t adc, double charge, bool mode, bool threshold)
edm::EDGetToken digiSource_
bool isValid() const
Definition: HandleBase.h:70
std::map< int, int > OccupancyMap_minus_
std::map< int, int > OccupancyMap_plus_
HLT enums.
bool threshold() const
Definition: HGCSample.h:66
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
std::vector< MonitorElement * > ADC_
MonitorElement * MeanDigiOccupancy_Plus_
void fillOccupancyMap(std::map< int, int > &OccupancyMap, int layer)
__shared__ uint32_t ntot
std::vector< MonitorElement * > DigiOccupancy_Plus_
Definition: Run.h:45
uint16_t *__restrict__ uint16_t const *__restrict__ adc