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 
12 
15 
23 
28 
29 #include "CLHEP/Units/GlobalSystemOfUnits.h"
30 #include "TVector3.h"
31 
33 public:
34  struct energysum {
35  energysum() { e15 = e25 = e50 = e100 = e250 = e1000 = 0.0; }
36  double e15, e25, e50, e100, e250, e1000;
37  };
38 
39  struct HitsInfo {
41  x = y = z = time = energy = phi = eta = 0.0;
42  layer = 0;
43  }
44  float x, y, z, time, energy, phi, eta;
45  float layer;
46  };
47 
49  ~HGCalRecHitValidation() override {}
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
53  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
54  void analyze(const edm::Event&, const edm::EventSetup&) override;
55 
56 private:
57  template <class T1, class T2>
58  void recHitValidation(DetId& detId, int layer, const T1* geom, T2 it);
59  void fillHitsInfo();
60  void fillHitsInfo(HitsInfo& hits);
61  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
62 
63  // ----------member data ---------------------------
69  unsigned int layers_;
71  std::map<int, int> OccupancyMap_plus;
72  std::map<int, int> OccupancyMap_minus;
73 
74  std::vector<MonitorElement*> EtaPhi_Plus_;
75  std::vector<MonitorElement*> EtaPhi_Minus_;
76  std::vector<MonitorElement*> energy_;
77  std::vector<MonitorElement*> HitOccupancy_Plus_;
78  std::vector<MonitorElement*> HitOccupancy_Minus_;
81 };
82 
84  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
85  geometry_token_(esConsumes(edm::ESInputTag("", nameDetector_))),
86  geometry_beginRun_token_(esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(
87  edm::ESInputTag("", nameDetector_))),
88  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
89  firstLayer_(1) {
90  auto temp = iConfig.getParameter<edm::InputTag>("RecHitSource");
91  if (nameDetector_ == "HGCalEESensitive" || nameDetector_ == "HGCalHESiliconSensitive" ||
92  nameDetector_ == "HGCalHEScintillatorSensitive") {
93  recHitSource_ = consumes<HGCRecHitCollection>(temp);
94  } else {
95  throw cms::Exception("BadHGCRecHitSource") << "HGCal DetectorName given as " << nameDetector_ << " must be: "
96  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", or "
97  << "\"HGCalHEScintillatorSensitive\"!";
98  }
99 }
100 
103  desc.add<std::string>("DetectorName", "HGCalEESensitive");
104  desc.add<edm::InputTag>("RecHitSource", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
105  desc.addUntracked<int>("Verbosity", 0);
106  descriptions.add("hgcalRecHitValidationEE", desc);
107 }
108 
110  OccupancyMap_plus.clear();
111  OccupancyMap_minus.clear();
112 
113  bool ok(true);
114  unsigned int ntot(0), nused(0);
116  if (!geomHandle.isValid()) {
117  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
118  << "Object for " << nameDetector_;
119  } else {
120  const HGCalGeometry* geom0 = geomHandle.product();
121  int geomType = ((geom0->topology().waferHexagon8()) ? 1 : ((geom0->topology().tileTrapezoid()) ? 2 : 0));
122 
123  edm::Handle<HGCRecHitCollection> theRecHitContainers;
124  iEvent.getByToken(recHitSource_, theRecHitContainers);
125  if (theRecHitContainers.isValid()) {
126  if (verbosity_ > 0)
127  edm::LogVerbatim("HGCalValidation")
128  << nameDetector_ << " with " << theRecHitContainers->size() << " element(s)";
129  for (const auto& it : *(theRecHitContainers.product())) {
130  ntot++;
131  nused++;
132  DetId detId = it.id();
133  int layer = ((geomType == 0)
134  ? HGCalDetId(detId).layer()
135  : ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer()));
136  recHitValidation(detId, layer, geom0, &it);
137  }
138  } else {
139  ok = false;
140  edm::LogVerbatim("HGCalValidation") << "HGCRecHitCollection Handle "
141  << "does not exist !!!";
142  }
143  }
144  if (ok)
145  fillHitsInfo();
146  if (verbosity_ > 0)
147  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
148  << " used recHits";
149 }
150 
151 template <class T1, class T2>
152 void HGCalRecHitValidation::recHitValidation(DetId& detId, int layer, const T1* geom, T2 it) {
153  const GlobalPoint& global = geom->getPosition(detId);
154  double energy = it->energy();
155 
156  float globalx = global.x();
157  float globaly = global.y();
158  float globalz = global.z();
159 
160  HitsInfo hinfo;
161  hinfo.energy = energy;
162  hinfo.x = globalx;
163  hinfo.y = globaly;
164  hinfo.z = globalz;
165  hinfo.layer = layer - firstLayer_;
166  hinfo.phi = global.phi();
167  hinfo.eta = global.eta();
168 
169  if (verbosity_ > 1)
170  edm::LogVerbatim("HGCalValidation") << "-------------------------- gx = " << globalx << " gy = " << globaly
171  << " gz = " << globalz << " phi = " << hinfo.phi << " eta = " << hinfo.eta
172  << " lay = " << hinfo.layer;
173 
175 
176  if (hinfo.eta > 0)
178  else
180 }
181 
182 void HGCalRecHitValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
183  if (OccupancyMap.find(layer) != OccupancyMap.end())
184  OccupancyMap[layer]++;
185  else
186  OccupancyMap[layer] = 1;
187 }
188 
190  for (auto const& itr : OccupancyMap_plus) {
191  int layer = itr.first;
192  int occupancy = itr.second;
193  HitOccupancy_Plus_.at(layer)->Fill(occupancy);
194  }
195 
196  for (auto const& itr : OccupancyMap_minus) {
197  int layer = itr.first;
198  int occupancy = itr.second;
199  HitOccupancy_Minus_.at(layer)->Fill(occupancy);
200  }
201 }
202 
204  unsigned int ilayer = hits.layer;
205  energy_.at(ilayer)->Fill(hits.energy);
206 
207  EtaPhi_Plus_.at(ilayer)->Fill(hits.eta, hits.phi);
208  EtaPhi_Minus_.at(ilayer)->Fill(hits.eta, hits.phi);
209 }
210 
213  if (!geomHandle.isValid()) {
214  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
215  << "Object for " << nameDetector_;
216  } else {
217  const HGCalGeometry* geom = geomHandle.product();
218  const HGCalDDDConstants& hgcons_ = geom->topology().dddConstants();
219  layers_ = hgcons_.layers(true);
220  firstLayer_ = hgcons_.firstLayer();
221  }
222 }
223 
225  iB.setCurrentFolder("HGCAL/HGCalRecHitsV/" + nameDetector_);
226  std::ostringstream histoname;
227  for (unsigned int il = 0; il < layers_; ++il) {
228  int ilayer = firstLayer_ + (int)(il);
229  auto istr1 = std::to_string(ilayer);
230  while (istr1.size() < 2) {
231  istr1.insert(0, "0");
232  }
233  histoname.str("");
234  histoname << "HitOccupancy_Plus_layer_" << istr1;
235  HitOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Plus", 100, 0, 10000));
236  histoname.str("");
237  histoname << "HitOccupancy_Minus_layer_" << istr1;
238  HitOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Minus", 100, 0, 10000));
239 
240  histoname.str("");
241  histoname << "EtaPhi_Plus_"
242  << "layer_" << istr1;
243  EtaPhi_Plus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, 1.45, 3.0, 72, -CLHEP::pi, CLHEP::pi));
244  histoname.str("");
245  histoname << "EtaPhi_Minus_"
246  << "layer_" << istr1;
247  EtaPhi_Minus_.push_back(
248  iB.book2D(histoname.str().c_str(), "Occupancy", 31, -3.0, -1.45, 72, -CLHEP::pi, CLHEP::pi));
249 
250  histoname.str("");
251  histoname << "energy_layer_" << istr1;
252  energy_.push_back(iB.book1D(histoname.str().c_str(), "energy_", 500, 0, 1));
253  } //loop over layers ends here
254 
255  histoname.str("");
256  histoname << "SUMOfRecHitOccupancy_Plus";
258  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
259  histoname.str("");
260  histoname << "SUMOfRecHitOccupancy_Minus";
262  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
263 }
264 
265 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
266 
268 
269 //define this as a plug-in
Log< level::Info, true > LogVerbatim
HGCalRecHitValidation(const edm::ParameterSet &)
std::vector< MonitorElement * > EtaPhi_Minus_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geometry_token_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
T z() const
Definition: PV3DBase.h:61
size_type size() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
T const * product() const
Definition: Handle.h:70
std::vector< MonitorElement * > EtaPhi_Plus_
std::string to_string(const V &value)
Definition: OMSAccess.h:71
int firstLayer() const
std::vector< MonitorElement * > HitOccupancy_Minus_
edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geometry_beginRun_token_
constexpr std::array< uint8_t, layerIndexSize > layer
const Double_t pi
MonitorElement * MeanHitOccupancy_Plus_
int layer() const
get the layer #
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
std::map< int, int > OccupancyMap_minus
int layer() const
get the layer #
Transition
Definition: Transition.h:12
MonitorElement * MeanHitOccupancy_Minus_
unsigned int layers(bool reco) const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
bool isValid() const
Definition: ESHandle.h:44
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
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:212
int layer() const
get the layer #
Definition: HGCalDetId.h:46
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
std::map< int, int > OccupancyMap_plus
HLT enums.
std::vector< MonitorElement * > HitOccupancy_Plus_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
__shared__ uint32_t ntot
void recHitValidation(DetId &detId, int layer, const T1 *geom, T2 it)
std::vector< MonitorElement * > energy_
Definition: Run.h:45