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 
17 
25 
29 
30 #include "CLHEP/Units/GlobalSystemOfUnits.h"
31 
32 // user include files
33 
35 public:
36  struct digiInfo {
38  x = y = z = charge = 0.0;
39  layer = adc = 0;
40  mode = threshold = false;
41  }
42  double x, y, z, charge;
43  int layer, adc;
44  bool mode, threshold; //tot mode and zero supression
45  };
46 
47  explicit HGCalDigiValidation(const edm::ParameterSet&);
48  ~HGCalDigiValidation() override = default;
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
52  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
53  void analyze(const edm::Event&, const edm::EventSetup&) override;
54 
55 private:
57  void fillDigiInfo();
58  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
59  template <class T1, class T2>
60  void digiValidation(
61  const T1& detId, const T2* geom, int layer, uint16_t adc, double charge, bool mode, bool threshold);
62 
63  // ----------member data ---------------------------
65  const bool ifNose_;
66  const int verbosity_, SampleIndx_;
71 
72  std::map<int, int> OccupancyMap_plus_;
73  std::map<int, int> OccupancyMap_minus_;
74 
75  std::vector<MonitorElement*> TOA_;
76  std::vector<MonitorElement*> DigiOccupancy_XY_;
77  std::vector<MonitorElement*> ADC_;
78  std::vector<MonitorElement*> TOT_;
79  std::vector<MonitorElement*> DigiOccupancy_Plus_;
80  std::vector<MonitorElement*> DigiOccupancy_Minus_;
83 };
84 
86  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
87  ifNose_(iConfig.getParameter<bool>("ifNose")),
88  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
89  SampleIndx_(iConfig.getUntrackedParameter<int>("SampleIndx", 0)),
92  tok_hgcalg_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameDetector_})),
93  digiSource_(consumes<HGCalDigiCollection>(iConfig.getParameter<edm::InputTag>("DigiSource"))),
94  firstLayer_(1) {}
95 
98  desc.add<std::string>("DetectorName", "HGCalEESensitive");
99  desc.add<edm::InputTag>("DigiSource", edm::InputTag("hgcalDigis", "EE"));
100  desc.add<bool>("ifNose", false);
101  desc.addUntracked<int>("Verbosity", 0);
102  desc.addUntracked<int>("SampleIndx", 2); // central bx
103  descriptions.add("hgcalDigiValidationEEDefault", desc);
104 }
105 
107  OccupancyMap_plus_.clear();
108  OccupancyMap_minus_.clear();
109 
110  int geomType(0);
111  const HGCalGeometry* geom0 = &iSetup.getData(tok_hgcalg_);
112  if (geom0->topology().waferHexagon8())
113  geomType = 1;
114  else
115  geomType = 2;
116  if (nameDetector_ == "HGCalHFNoseSensitive")
117  geomType = 3;
118 
119  unsigned int ntot(0), nused(0);
120  if ((nameDetector_ == "HGCalEESensitive") || (nameDetector_ == "HGCalHFNoseSensitive")) {
121  //HGCalEE
122  const edm::Handle<HGCalDigiCollection>& theHGCEEDigiContainers = iEvent.getHandle(digiSource_);
123  if (theHGCEEDigiContainers.isValid()) {
124  if (verbosity_ > 0)
125  edm::LogVerbatim("HGCalValidation")
126  << nameDetector_ << " with " << theHGCEEDigiContainers->size() << " element(s)";
127  for (const auto& it : *(theHGCEEDigiContainers.product())) {
128  ntot++;
129  nused++;
130  DetId detId = it.id();
131  int layer = ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HFNoseDetId(detId).layer());
132  const HGCSample& hgcSample = it.sample(SampleIndx_);
133  uint16_t gain = hgcSample.toa();
134  uint16_t adc = hgcSample.data();
135  double charge = gain;
136  bool totmode = hgcSample.mode();
137  bool zerothreshold = hgcSample.threshold();
138  digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
139  }
140  fillDigiInfo();
141  } else {
142  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
143  << "exist for " << nameDetector_;
144  }
145  } else if ((nameDetector_ == "HGCalHESiliconSensitive") || (nameDetector_ == "HGCalHEScintillatorSensitive")) {
146  //HGCalHE
147  const edm::Handle<HGCalDigiCollection>& theHGCHEDigiContainers = iEvent.getHandle(digiSource_);
148  if (theHGCHEDigiContainers.isValid()) {
149  if (verbosity_ > 0)
150  edm::LogVerbatim("HGCalValidation")
151  << nameDetector_ << " with " << theHGCHEDigiContainers->size() << " element(s)";
152  for (const auto& it : *(theHGCHEDigiContainers.product())) {
153  ntot++;
154  nused++;
155  DetId detId = it.id();
156  int layer = ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer());
157  const HGCSample& hgcSample = it.sample(SampleIndx_);
158  uint16_t gain = hgcSample.toa();
159  uint16_t adc = hgcSample.data();
160  double charge = gain;
161  bool totmode = hgcSample.mode();
162  bool zerothreshold = hgcSample.threshold();
163  digiValidation(detId, geom0, layer, adc, charge, totmode, zerothreshold);
164  }
165  fillDigiInfo();
166  } else {
167  edm::LogVerbatim("HGCalValidation") << "DigiCollection handle does not "
168  << "exist for " << nameDetector_;
169  }
170  } else {
171  edm::LogWarning("HGCalValidation") << "invalid detector name !! " << nameDetector_;
172  }
173  if (verbosity_ > 0)
174  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
175  << " used digis";
176 }
177 
178 template <class T1, class T2>
180  const T1& detId, const T2* geom, int layer, uint16_t adc, double charge, bool mode, bool threshold) {
181  if (verbosity_ > 1)
182  edm::LogVerbatim("HGCalValidation") << std::hex << detId.rawId() << std::dec << " " << detId.rawId();
183  DetId id1 = DetId(detId.rawId());
184  const GlobalPoint& global1 = geom->getPosition(id1);
185 
186  if (verbosity_ > 1)
187  edm::LogVerbatim("HGCalValidation") << " adc = " << adc << " toa = " << charge;
188 
189  digiInfo hinfo;
190  hinfo.x = global1.x();
191  hinfo.y = global1.y();
192  hinfo.z = global1.z();
193  hinfo.adc = adc;
194  hinfo.charge = charge;
195  hinfo.layer = layer - firstLayer_;
196  hinfo.mode = mode;
197  hinfo.threshold = threshold;
198 
199  if (verbosity_ > 1)
200  edm::LogVerbatim("HGCalValidation") << "gx = " << hinfo.x << " gy = " << hinfo.y << " gz = " << hinfo.z;
201 
202  if (global1.eta() > 0)
204  else
206 
208 }
209 
210 void HGCalDigiValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
211  if (OccupancyMap.find(layer) != OccupancyMap.end())
212  OccupancyMap[layer]++;
213  else
214  OccupancyMap[layer] = 1;
215 }
216 
218  int ilayer = hinfo.layer;
219  TOA_.at(ilayer)->Fill(hinfo.charge);
220 
221  if (hinfo.mode) {
222  TOT_.at(ilayer)->Fill(hinfo.adc);
223  }
224 
225  if (!hinfo.mode && hinfo.threshold) {
226  ADC_.at(ilayer)->Fill(hinfo.adc);
227  DigiOccupancy_XY_.at(ilayer)->Fill(hinfo.x, hinfo.y);
228  }
229 }
230 
232  for (const auto& itr : OccupancyMap_plus_) {
233  int layer = itr.first;
234  int occupancy = itr.second;
235  DigiOccupancy_Plus_.at(layer)->Fill(occupancy);
236  }
237  for (const auto& itr : OccupancyMap_minus_) {
238  int layer = itr.first;
239  int occupancy = itr.second;
240  DigiOccupancy_Minus_.at(layer)->Fill(occupancy);
241  }
242 }
243 
245  const HGCalDDDConstants* hgcons = &iSetup.getData(tok_hgcalc_);
246  layers_ = hgcons->layers(true);
247  firstLayer_ = hgcons->firstLayer();
248 
249  if (verbosity_ > 0)
250  edm::LogVerbatim("HGCalValidation") << "current DQM directory: "
251  << "HGCAL/HGCalDigisV/" << nameDetector_ << " layer = " << layers_
252  << " with the first one at " << firstLayer_;
253 }
254 
256  iB.setCurrentFolder("HGCAL/HGCalDigisV/" + nameDetector_);
257 
258  std::ostringstream histoname;
259  for (int il = 0; il < layers_; ++il) {
260  int ilayer = firstLayer_ + il;
261  auto istr1 = std::to_string(ilayer);
262  while (istr1.size() < 2) {
263  istr1.insert(0, "0");
264  }
265  histoname.str("");
266  histoname << "TOA_"
267  << "layer_" << istr1;
268  TOA_.push_back(iB.book1D(histoname.str().c_str(), "toa_", 1024, 0, 1024));
269 
270  histoname.str("");
271  histoname << "ADC_"
272  << "layer_" << istr1;
273  ADC_.push_back(iB.book1D(histoname.str().c_str(), "ADCDigiOccupancy", 1024, 0, 1024));
274 
275  histoname.str("");
276  histoname << "TOT_"
277  << "layer_" << istr1;
278  TOT_.push_back(iB.book1D(histoname.str().c_str(), "TOTDigiOccupancy", 4096, 0, 4096));
279 
280  histoname.str("");
281  histoname << "DigiOccupancy_XY_"
282  << "layer_" << istr1;
283  DigiOccupancy_XY_.push_back(iB.book2D(histoname.str().c_str(), "DigiOccupancy", 50, -500, 500, 50, -500, 500));
284 
285  histoname.str("");
286  histoname << "DigiOccupancy_Plus_"
287  << "layer_" << istr1;
288  DigiOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy +z", 100, 0, 1000));
289  histoname.str("");
290  histoname << "DigiOccupancy_Minus_"
291  << "layer_" << istr1;
292  DigiOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "DigiOccupancy -z", 100, 0, 1000));
293  }
294 
295  histoname.str("");
296  histoname << "SUMOfDigiOccupancy_Plus";
297  MeanDigiOccupancy_Plus_ = iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
298  histoname.str("");
299  histoname << "SUMOfRecDigiOccupancy_Minus";
301  iB.book1D(histoname.str().c_str(), "SUMOfDigiOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
302 }
303 
304 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
305 
307 
308 //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
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
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
uint16_t data() const
Definition: HGCSample.h:70
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
int layer() const
get the layer #
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< HGCalDigiCollection > digiSource_
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
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_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~HGCalDigiValidation() override=default
void digiValidation(const T1 &detId, const T2 *geom, int layer, uint16_t adc, double charge, bool mode, bool threshold)
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