CMS 3D CMS Logo

HGCalRecHitValidation.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 
15 
17 
20 
29 
37 
38 #include "CLHEP/Units/GlobalSystemOfUnits.h"
39 #include "TVector3.h"
40 
42 public:
43  struct energysum {
44  energysum() { e15 = e25 = e50 = e100 = e250 = e1000 = 0.0; }
45  double e15, e25, e50, e100, e250, e1000;
46  };
47 
48  struct HitsInfo {
50  x = y = z = time = energy = phi = eta = 0.0;
51  layer = 0;
52  }
53  float x, y, z, time, energy, phi, eta;
54  float layer;
55  };
56 
58  ~HGCalRecHitValidation() override {}
59 
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
62  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
63  void analyze(const edm::Event&, const edm::EventSetup&) override;
64 
65 private:
66  template <class T1, class T2>
67  void recHitValidation(DetId& detId, int layer, const T1* geom, T2 it);
68  void fillHitsInfo();
69  void fillHitsInfo(HitsInfo& hits);
70  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
71 
72  // ----------member data ---------------------------
75  bool ifHCAL_;
77  unsigned int layers_;
79  std::map<int, int> OccupancyMap_plus;
80  std::map<int, int> OccupancyMap_minus;
81 
82  std::vector<MonitorElement*> EtaPhi_Plus_;
83  std::vector<MonitorElement*> EtaPhi_Minus_;
84  std::vector<MonitorElement*> energy_;
85  std::vector<MonitorElement*> HitOccupancy_Plus_;
86  std::vector<MonitorElement*> HitOccupancy_Minus_;
89 };
90 
92  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
93  ifHCAL_(iConfig.getParameter<bool>("ifHCAL")),
94  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
95  firstLayer_(1) {
96  auto temp = iConfig.getParameter<edm::InputTag>("RecHitSource");
97  if (nameDetector_ == "HGCalEESensitive" || nameDetector_ == "HGCalHESiliconSensitive" ||
98  nameDetector_ == "HGCalHEScintillatorSensitive") {
99  recHitSource_ = consumes<HGCRecHitCollection>(temp);
100  } else if (nameDetector_ == "HCal") {
101  if (ifHCAL_)
102  recHitSource_ = consumes<HBHERecHitCollection>(temp);
103  else
104  recHitSource_ = consumes<HGChebRecHitCollection>(temp);
105  } else {
106  throw cms::Exception("BadHGCRecHitSource") << "HGCal DetectorName given as " << nameDetector_ << " must be: "
107  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", "
108  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
109  }
110 }
111 
114  desc.add<std::string>("DetectorName", "HGCalEESensitive");
115  desc.add<edm::InputTag>("RecHitSource", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
116  desc.add<bool>("ifHCAL", false);
117  desc.addUntracked<int>("Verbosity", 0);
118  descriptions.add("hgcalRecHitValidationEE", desc);
119 }
120 
122  OccupancyMap_plus.clear();
123  OccupancyMap_minus.clear();
124 
125  bool ok(true);
126  unsigned int ntot(0), nused(0);
127  if (nameDetector_ == "HCal") {
129  iSetup.get<CaloGeometryRecord>().get(geom);
130  if (!geom.isValid()) {
131  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
132  << "Object for " << nameDetector_;
133  } else {
134  const CaloGeometry* geom0 = geom.product();
135  if (ifHCAL_) {
137  iEvent.getByToken(recHitSource_, hbhecoll);
138  if (hbhecoll.isValid()) {
139  if (verbosity_ > 0)
140  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with " << hbhecoll->size() << " element(s)";
141  for (const auto& it : *(hbhecoll.product())) {
142  DetId detId = it.id();
143  ntot++;
144  if (detId.subdetId() == HcalEndcap) {
145  nused++;
146  int layer = HcalDetId(detId).depth();
147  recHitValidation(detId, layer, geom0, &it);
148  }
149  }
150  } else {
151  ok = false;
152  edm::LogVerbatim("HGCalValidation") << "HBHERecHitCollection "
153  << "Handle does not exist !!!";
154  }
155  } else {
157  iEvent.getByToken(recHitSource_, hbhecoll);
158  if (hbhecoll.isValid()) {
159  if (verbosity_ > 0)
160  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with " << hbhecoll->size() << " element(s)";
161  for (const auto& it : *(hbhecoll.product())) {
162  DetId detId = it.id();
163  ntot++;
164  nused++;
165  int layer = HcalDetId(detId).depth();
166  recHitValidation(detId, layer, geom0, &it);
167  }
168  } else {
169  ok = false;
170  edm::LogVerbatim("HGCalValidation") << "HGChebRecHitCollection "
171  << "Handle does not exist !!!";
172  }
173  }
174  }
175  } else {
177  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
178  if (!geom.isValid()) {
179  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
180  << "Object for " << nameDetector_;
181  } else {
182  const HGCalGeometry* geom0 = geom.product();
184  int geomType = (((mode == HGCalGeometryMode::Hexagon8) || (mode == HGCalGeometryMode::Hexagon8Full))
185  ? 1
186  : ((mode == HGCalGeometryMode::Trapezoid) ? 2 : 0));
187 
188  edm::Handle<HGCRecHitCollection> theRecHitContainers;
189  iEvent.getByToken(recHitSource_, theRecHitContainers);
190  if (theRecHitContainers.isValid()) {
191  if (verbosity_ > 0)
192  edm::LogVerbatim("HGCalValidation")
193  << nameDetector_ << " with " << theRecHitContainers->size() << " element(s)";
194  for (const auto& it : *(theRecHitContainers.product())) {
195  ntot++;
196  nused++;
197  DetId detId = it.id();
198  int layer = ((geomType == 0)
199  ? HGCalDetId(detId).layer()
200  : ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer()));
201  recHitValidation(detId, layer, geom0, &it);
202  }
203  } else {
204  ok = false;
205  edm::LogVerbatim("HGCalValidation") << "HGCRecHitCollection Handle "
206  << "does not exist !!!";
207  }
208  }
209  }
210  if (ok)
211  fillHitsInfo();
212  if (verbosity_ > 0)
213  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
214  << " used recHits";
215 }
216 
217 template <class T1, class T2>
218 void HGCalRecHitValidation::recHitValidation(DetId& detId, int layer, const T1* geom, T2 it) {
219  const GlobalPoint& global = geom->getPosition(detId);
220  double energy = it->energy();
221 
222  float globalx = global.x();
223  float globaly = global.y();
224  float globalz = global.z();
225 
226  HitsInfo hinfo;
227  hinfo.energy = energy;
228  hinfo.x = globalx;
229  hinfo.y = globaly;
230  hinfo.z = globalz;
231  hinfo.layer = layer - firstLayer_;
232  hinfo.phi = global.phi();
233  hinfo.eta = global.eta();
234 
235  if (verbosity_ > 1)
236  edm::LogVerbatim("HGCalValidation") << "-------------------------- gx = " << globalx << " gy = " << globaly
237  << " gz = " << globalz << " phi = " << hinfo.phi << " eta = " << hinfo.eta
238  << " lay = " << hinfo.layer;
239 
240  fillHitsInfo(hinfo);
241 
242  if (hinfo.eta > 0)
244  else
246 }
247 
248 void HGCalRecHitValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
249  if (OccupancyMap.find(layer) != OccupancyMap.end())
250  OccupancyMap[layer]++;
251  else
252  OccupancyMap[layer] = 1;
253 }
254 
256  for (auto const& itr : OccupancyMap_plus) {
257  int layer = itr.first;
258  int occupancy = itr.second;
259  HitOccupancy_Plus_.at(layer)->Fill(occupancy);
260  }
261 
262  for (auto const& itr : OccupancyMap_minus) {
263  int layer = itr.first;
264  int occupancy = itr.second;
265  HitOccupancy_Minus_.at(layer)->Fill(occupancy);
266  }
267 }
268 
270  unsigned int ilayer = hits.layer;
271  energy_.at(ilayer)->Fill(hits.energy);
272 
273  EtaPhi_Plus_.at(ilayer)->Fill(hits.eta, hits.phi);
274  EtaPhi_Minus_.at(ilayer)->Fill(hits.eta, hits.phi);
275 }
276 
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  firstLayer_ = hgcons_.firstLayer();
289  }
290 }
291 
293  iB.setCurrentFolder("HGCAL/HGCalRecHitsV/" + nameDetector_);
294  std::ostringstream histoname;
295  for (unsigned int il = 0; il < layers_; ++il) {
296  int ilayer = firstLayer_ + (int)(il);
297  auto istr1 = std::to_string(ilayer);
298  while (istr1.size() < 2) {
299  istr1.insert(0, "0");
300  }
301  histoname.str("");
302  histoname << "HitOccupancy_Plus_layer_" << istr1;
303  HitOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Plus", 100, 0, 10000));
304  histoname.str("");
305  histoname << "HitOccupancy_Minus_layer_" << istr1;
306  HitOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Minus", 100, 0, 10000));
307 
308  histoname.str("");
309  histoname << "EtaPhi_Plus_"
310  << "layer_" << istr1;
311  EtaPhi_Plus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, 1.45, 3.0, 72, -CLHEP::pi, CLHEP::pi));
312  histoname.str("");
313  histoname << "EtaPhi_Minus_"
314  << "layer_" << istr1;
315  EtaPhi_Minus_.push_back(
316  iB.book2D(histoname.str().c_str(), "Occupancy", 31, -3.0, -1.45, 72, -CLHEP::pi, CLHEP::pi));
317 
318  histoname.str("");
319  histoname << "energy_layer_" << istr1;
320  energy_.push_back(iB.book1D(histoname.str().c_str(), "energy_", 500, 0, 1));
321  } //loop over layers ends here
322 
323  histoname.str("");
324  histoname << "SUMOfRecHitOccupancy_Plus";
326  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
327  histoname.str("");
328  histoname << "SUMOfRecHitOccupancy_Minus";
330  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
331 }
332 
333 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
334 
336 
337 //define this as a plug-in
HGCalGeometryMode::GeometryMode geomMode() const
Geometry mode.
Definition: HGCalTopology.h:79
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
HGCalRecHitValidation(const edm::ParameterSet &)
std::vector< MonitorElement * > EtaPhi_Minus_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T y() const
Definition: PV3DBase.h:60
std::vector< MonitorElement * > EtaPhi_Plus_
std::vector< MonitorElement * > HitOccupancy_Minus_
const Double_t pi
MonitorElement * MeanHitOccupancy_Plus_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int depth() const
get the tower depth
Definition: HcalDetId.h:164
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< int, int > OccupancyMap_minus
unsigned int layers(bool reco) const
int layer() const
get the layer #
T z() const
Definition: PV3DBase.h:61
const HGCalTopology & topology() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
MonitorElement * MeanHitOccupancy_Minus_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: DetId.h:17
void fillOccupancyMap(std::map< int, int > &OccupancyMap, int layer)
void analyze(const edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:69
int getMaxDepth(const int &type) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int layer() const
get the layer #
T eta() const
Definition: PV3DBase.h:73
std::map< int, int > OccupancyMap_plus
edm::EventID id() const
Definition: EventBase.h:59
size_type size() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
T get() const
Definition: EventSetup.h:73
std::vector< MonitorElement * > HitOccupancy_Plus_
int firstLayer() const
bool isValid() const
Definition: ESHandle.h:44
T x() const
Definition: PV3DBase.h:59
T const * product() const
Definition: ESHandle.h:86
void recHitValidation(DetId &detId, int layer, const T1 *geom, T2 it)
std::vector< MonitorElement * > energy_
int layer() const
get the layer #
Definition: HGCalDetId.h:46
Definition: Run.h:45