CMS 3D CMS Logo

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