CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HGCalRecHitValidation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HGCalRecHitValidation
4 // Class: HGCalRecHitValidation
5 //
11 //
12 // Original Author: Raman Khurana
14 // Created: Sunday, 17th Augst 2014 11:30:15 GMT
15 
16 // system include files
25 
34 
35 #include "CLHEP/Units/GlobalSystemOfUnits.h"
36 #include "TVector3.h"
37 #include <cmath>
38 
39 
42  nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
43  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity",0)) {
44  auto temp = iConfig.getParameter<edm::InputTag>("RecHitSource");
45  if( nameDetector_ == "HGCalEESensitive" ||
46  nameDetector_ == "HGCalHESiliconSensitive" ||
47  nameDetector_ == "HGCalHEScintillatorSensitive" ) {
48  recHitSource_ = consumes<HGCRecHitCollection>(temp);
49  } else if ( nameDetector_ == "HCal" ) {
50  recHitSource_ =
51  consumes<HBHERecHitCollection>(temp);
52  } else {
53  throw cms::Exception("BadHGCRecHitSource")
54  << "HGCal DetectorName given as " << nameDetector_ << " must be: "
55  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", "
56  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
57  }
58 }
59 
60 
62 
64  const edm::EventSetup& iSetup) {
65  OccupancyMap_plus.clear();
66  OccupancyMap_minus.clear();
67 
68  bool ok(true);
69  unsigned int ntot(0), nused(0);
70  if (nameDetector_ == "HCal") {
72  iSetup.get<CaloGeometryRecord>().get(geom);
73  if (!geom.isValid()) edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry Object for " << nameDetector_;
74  const CaloGeometry* geom0 = geom.product();
75 
77  iEvent.getByToken(recHitSource_, hbhecoll);
78  if (hbhecoll.isValid()) {
79  if (verbosity_>0)
80  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
81  << hbhecoll->size() << " element(s)";
82  for (HBHERecHitCollection::const_iterator it=hbhecoll->begin();
83  it != hbhecoll->end(); ++it) {
84  DetId detId = it->id();
85  ntot++;
86  if (detId.subdetId() == HcalEndcap) {
87  nused++;
88  int layer = HcalDetId(detId).depth();
89  recHitValidation(detId, layer, geom0, it);
90  }
91  }
92  } else {
93  ok = false;
94  edm::LogWarning("HGCalValidation") << "HBHERecHitCollection Handle does not exist !!!";
95  }
96  } else {
98  iSetup.get<IdealGeometryRecord>().get(nameDetector_, geom);
99  if (!geom.isValid()) edm::LogWarning("HGCalValidation") << "Cannot get valid HGCalGeometry Object for " << nameDetector_;
100  const HGCalGeometry* geom0 = geom.product();
101 
102  edm::Handle<HGCRecHitCollection> theRecHitContainers;
103  iEvent.getByToken(recHitSource_, theRecHitContainers);
104  if (theRecHitContainers.isValid()) {
105  if (verbosity_>0)
106  edm::LogInfo("HGCalValidation") << nameDetector_ << " with "
107  << theRecHitContainers->size()
108  << " element(s)";
109  for (HGCRecHitCollection::const_iterator it=theRecHitContainers->begin();
110  it !=theRecHitContainers->end(); ++it) {
111  ntot++; nused++;
112  DetId detId = it->id();
113  int layer = (detId.subdetId() == HGCEE) ? (HGCEEDetId(detId).layer()) : (HGCHEDetId(detId).layer());
114  recHitValidation(detId, layer, geom0, it);
115  }
116  } else {
117  ok = false;
118  edm::LogWarning("HGCalValidation") << "HGCRecHitCollection Handle does not exist !!!";
119  }
120  }
121  if (ok) fillHitsInfo();
122  edm::LogWarning("HGCalValidation") << "Event " << iEvent.id().event()
123  << " with " << ntot << " total and "
124  << nused << " used recHits";
125 }
126 
127 template<class T1, class T2>
129  const T1* geom, T2 it) {
130 
131  GlobalPoint global = geom->getPosition(detId);
132  double energy = it->energy();
133 
134  float globalx = global.x();
135  float globaly = global.y();
136  float globalz = global.z();
137 
138  HitsInfo hinfo;
139  hinfo.energy = energy;
140  hinfo.x = globalx;
141  hinfo.y = globaly;
142  hinfo.z = globalz;
143  hinfo.layer = layer;
144  hinfo.phi = global.phi();
145  hinfo.eta = global.eta();
146 
147  if (verbosity_>1)
148  edm::LogInfo("HGCalValidation") << " -------------------------- gx = "
149  << globalx << " gy = " << globaly
150  << " gz = " << globalz << " phi = "
151  << hinfo.phi << " eta = " << hinfo.eta;
152 
153  fillHitsInfo(hinfo);
154 
155  if (hinfo.eta > 0) fillOccupancyMap(OccupancyMap_plus, layer -1);
156  else fillOccupancyMap(OccupancyMap_minus, layer -1);
157 
158 }
159 
160 void HGCalRecHitValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer){
161  if (OccupancyMap.find(layer) != OccupancyMap.end()) OccupancyMap[layer]++;
162  else OccupancyMap[layer] = 1;
163 }
164 
166 
167  for (auto itr = OccupancyMap_plus.begin() ; itr != OccupancyMap_plus.end(); ++itr) {
168  int layer = (*itr).first;
169  int occupancy = (*itr).second;
170  HitOccupancy_Plus_.at(layer)->Fill(occupancy);
171  }
172 
173  for (auto itr = OccupancyMap_minus.begin() ; itr != OccupancyMap_minus.end(); ++itr) {
174  int layer = (*itr).first;
175  int occupancy = (*itr).second;
176  HitOccupancy_Minus_.at(layer)->Fill(occupancy);
177  }
178 
179 }
180 
182 
183  unsigned int ilayer = hits.layer -1;
184  energy_.at(ilayer)->Fill(hits.energy);
185 
186  EtaPhi_Plus_.at(ilayer)->Fill(hits.eta , hits.phi);
187  EtaPhi_Minus_.at(ilayer)->Fill(hits.eta, hits.phi);
188 
189 }
190 
192  const edm::EventSetup& iSetup) {
193 
194  if (nameDetector_ == "HCal") {
196  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
197  const HcalDDDRecConstants *hcons = &(*pHRNDC);
198  layers_ = hcons->getMaxDepth(1);
199  } else {
201  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
202  const HGCalDDDConstants & hgcons_ = (*pHGDC);
203  layers_ = hgcons_.layers(true);
204  }
205 }
206 
208  edm::Run const&,
209  edm::EventSetup const&) {
210 
211  iB.setCurrentFolder("HGCalRecHitsV/"+nameDetector_);
212  std::ostringstream histoname;
213  for (unsigned int ilayer = 0; ilayer < layers_; ilayer++ ) {
214  histoname.str(""); histoname << "HitOccupancy_Plus_layer_" << ilayer;
215  HitOccupancy_Plus_.push_back(iB.book1D( histoname.str().c_str(), "RecHitOccupancy_Plus", 100, 0, 10000));
216  histoname.str(""); histoname << "HitOccupancy_Minus_layer_" << ilayer;
217  HitOccupancy_Minus_.push_back(iB.book1D( histoname.str().c_str(), "RecHitOccupancy_Minus", 100, 0, 10000));
218 
219  histoname.str(""); histoname << "EtaPhi_Plus_" << "layer_" << ilayer;
220  EtaPhi_Plus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, 1.45, 3.0, 72, -3.15, 3.15));
221  histoname.str(""); histoname << "EtaPhi_Minus_" << "layer_" << ilayer;
222  EtaPhi_Minus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, -3.0, -1.45, 72, -3.15, 3.15));
223 
224  histoname.str(""); histoname << "energy_layer_" << ilayer;
225  energy_.push_back(iB.book1D(histoname.str().c_str(),"energy_",100,0,0.002));
226  }//loop over layers ends here
227 
228  histoname.str(""); histoname << "SUMOfRecHitOccupancy_Plus";
229  MeanHitOccupancy_Plus_= iB.book1D( histoname.str().c_str(), "SUMOfRecHitOccupancy_Plus", layers_, -0.5, layers_-0.5);
230  histoname.str(""); histoname << "SUMOfRecHitOccupancy_Minus";
231  MeanHitOccupancy_Minus_ = iB.book1D( histoname.str().c_str(), "SUMOfRecHitOccupancy_Minus", layers_, -0.5,layers_-0.5);
232 }
233 
234 
235 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
238  desc.setUnknown();
239  descriptions.addDefault(desc);
240 }
241 
243 
244 //define this as a plug-in
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
HGCalRecHitValidation(const edm::ParameterSet &)
std::vector< MonitorElement * > EtaPhi_Minus_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< HBHERecHit >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:63
std::vector< MonitorElement * > EtaPhi_Plus_
int layer() const
get the layer #
Definition: HGCHEDetId.h:50
std::vector< MonitorElement * > HitOccupancy_Minus_
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
MonitorElement * MeanHitOccupancy_Plus_
int getMaxDepth(const int type) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int depth() const
get the tower depth
Definition: HcalDetId.cc:106
int iEvent
Definition: GenABIO.cc:230
std::map< int, int > OccupancyMap_minus
void addDefault(ParameterSetDescription const &psetDescription)
unsigned int layers(bool reco) const
void analyze(const edm::Event &, const edm::EventSetup &)
T z() const
Definition: PV3DBase.h:64
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
MonitorElement * MeanHitOccupancy_Minus_
bool isValid() const
Definition: HandleBase.h:75
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: DetId.h:18
int layer() const
get the layer #
Definition: HGCEEDetId.h:49
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
void fillOccupancyMap(std::map< int, int > &OccupancyMap, int layer)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
T eta() const
Definition: PV3DBase.h:76
std::map< int, int > OccupancyMap_plus
edm::EventID id() const
Definition: EventBase.h:59
std::vector< MonitorElement * > HitOccupancy_Plus_
bool isValid() const
Definition: ESHandle.h:47
T x() const
Definition: PV3DBase.h:62
void recHitValidation(DetId &detId, int layer, const T1 *geom, T2 it)
std::vector< MonitorElement * > energy_
Definition: Run.h:43