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