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 "
160  << "Handle 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  if (verbosity_>0)
220  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event()
221  << " with " << ntot << " total and "
222  << nused << " used recHits";
223 }
224 
225 template<class T1, class T2>
227  const T1* geom, T2 it) {
228 
229  const GlobalPoint& global = geom->getPosition(detId);
230  double energy = it->energy();
231 
232  float globalx = global.x();
233  float globaly = global.y();
234  float globalz = global.z();
235 
236  HitsInfo hinfo;
237  hinfo.energy = energy;
238  hinfo.x = globalx;
239  hinfo.y = globaly;
240  hinfo.z = globalz;
241  hinfo.layer = layer-firstLayer_;
242  hinfo.phi = global.phi();
243  hinfo.eta = global.eta();
244 
245  if (verbosity_>1)
246  edm::LogVerbatim("HGCalValidation") << "-------------------------- gx = "
247  << globalx << " gy = " << globaly
248  << " gz = " << globalz << " phi = "
249  << hinfo.phi << " eta = " << hinfo.eta
250  << " lay = " << hinfo.layer;
251 
252  fillHitsInfo(hinfo);
253 
254  if (hinfo.eta > 0) fillOccupancyMap(OccupancyMap_plus, hinfo.layer);
256 
257 }
258 
259 void HGCalRecHitValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap,
260  int layer) {
261  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer]++;
262  else OccupancyMap[layer] = 1;
263 }
264 
266 
267  for (auto const& itr : OccupancyMap_plus) {
268  int layer = itr.first;
269  int occupancy = itr.second;
270  HitOccupancy_Plus_.at(layer)->Fill(occupancy);
271  }
272 
273  for (auto const & itr : OccupancyMap_minus) {
274  int layer = itr.first;
275  int occupancy = itr.second;
276  HitOccupancy_Minus_.at(layer)->Fill(occupancy);
277  }
278 
279 }
280 
282 
283  unsigned int ilayer = hits.layer;
284  energy_.at(ilayer)->Fill(hits.energy);
285 
286  EtaPhi_Plus_.at(ilayer)->Fill(hits.eta , hits.phi);
287  EtaPhi_Minus_.at(ilayer)->Fill(hits.eta, hits.phi);
288 
289 }
290 
292  const edm::EventSetup& iSetup) {
293 
294  if (nameDetector_ == "HCal") {
296  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
297  const HcalDDDRecConstants *hcons = &(*pHRNDC);
298  layers_ = hcons->getMaxDepth(1);
299  } else {
301  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
302  const HGCalDDDConstants & hgcons_ = (*pHGDC);
303  layers_ = hgcons_.layers(true);
304  firstLayer_ = hgcons_.firstLayer();
305  }
306 }
307 
309  edm::Run const&,
310  edm::EventSetup const&) {
311 
312  iB.setCurrentFolder("HGCAL/HGCalRecHitsV/"+nameDetector_);
313  std::ostringstream histoname;
314  for (unsigned int il=0; il<layers_; ++il) {
315  int ilayer = firstLayer_ + (int)(il);
316  histoname.str(""); histoname << "HitOccupancy_Plus_layer_" << ilayer;
317  HitOccupancy_Plus_.push_back(iB.book1D( histoname.str().c_str(), "RecHitOccupancy_Plus", 100, 0, 10000));
318  histoname.str(""); histoname << "HitOccupancy_Minus_layer_" << ilayer;
319  HitOccupancy_Minus_.push_back(iB.book1D( histoname.str().c_str(), "RecHitOccupancy_Minus", 100, 0, 10000));
320 
321  histoname.str(""); histoname << "EtaPhi_Plus_" << "layer_" << ilayer;
322  EtaPhi_Plus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, 1.45, 3.0, 72, -CLHEP::pi, CLHEP::pi));
323  histoname.str(""); histoname << "EtaPhi_Minus_" << "layer_" << ilayer;
324  EtaPhi_Minus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, -3.0, -1.45, 72, -CLHEP::pi, CLHEP::pi));
325 
326  histoname.str(""); histoname << "energy_layer_" << ilayer;
327  energy_.push_back(iB.book1D(histoname.str().c_str(),"energy_",500,0,1));
328  }//loop over layers ends here
329 
330  histoname.str(""); histoname << "SUMOfRecHitOccupancy_Plus";
331  MeanHitOccupancy_Plus_= iB.book1D( histoname.str().c_str(), "SUMOfRecHitOccupancy_Plus", layers_, -0.5, layers_-0.5);
332  histoname.str(""); histoname << "SUMOfRecHitOccupancy_Minus";
333  MeanHitOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfRecHitOccupancy_Minus", layers_, -0.5,layers_-0.5);
334 }
335 
336 
337 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
338 
340 
341 //define this as a plug-in
HGCalGeometryMode::GeometryMode geomMode() const
Geometry mode.
Definition: HGCalTopology.h:88
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:517
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:166
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
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:74
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:59
size_type size() const
T get() const
Definition: EventSetup.h:71
std::vector< MonitorElement * > HitOccupancy_Plus_
int firstLayer() const
bool isValid() const
Definition: ESHandle.h:44
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:45