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 = default;
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 ---------------------------
65  const int verbosity_;
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  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
86  geometry_token_(esConsumes(edm::ESInputTag("", nameDetector_))),
87  geometry_beginRun_token_(esConsumes<HGCalGeometry, IdealGeometryRecord, edm::Transition::BeginRun>(
88  edm::ESInputTag("", nameDetector_))),
89  recHitSource_(consumes(iConfig.getParameter<edm::InputTag>("RecHitSource"))),
90  firstLayer_(1) {}
91 
94  desc.add<std::string>("DetectorName", "HGCalEESensitive");
95  desc.add<edm::InputTag>("RecHitSource", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
96  desc.addUntracked<int>("Verbosity", 0);
97  descriptions.add("hgcalRecHitValidationEE", desc);
98 }
99 
101  OccupancyMap_plus.clear();
102  OccupancyMap_minus.clear();
103 
104  bool ok(true);
105  unsigned int ntot(0), nused(0);
106  const edm::ESHandle<HGCalGeometry>& geomHandle = iSetup.getHandle(geometry_token_);
107  if (!geomHandle.isValid()) {
108  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
109  << "Object for " << nameDetector_;
110  } else {
111  const HGCalGeometry* geom0 = geomHandle.product();
112  int geomType = ((geom0->topology().waferHexagon8()) ? 1 : ((geom0->topology().tileTrapezoid()) ? 2 : 0));
113 
114  const edm::Handle<HGCRecHitCollection>& theRecHitContainers = iEvent.getHandle(recHitSource_);
115  if (theRecHitContainers.isValid()) {
116  if (verbosity_ > 0)
117  edm::LogVerbatim("HGCalValidation")
118  << nameDetector_ << " with " << theRecHitContainers->size() << " element(s)";
119  for (const auto& it : *(theRecHitContainers.product())) {
120  ntot++;
121  nused++;
122  DetId detId = it.id();
123  int layer = ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer());
124  recHitValidation(detId, layer, geom0, &it);
125  }
126  } else {
127  ok = false;
128  edm::LogVerbatim("HGCalValidation") << "HGCRecHitCollection Handle "
129  << "does not exist !!!";
130  }
131  }
132  if (ok)
133  fillHitsInfo();
134  if (verbosity_ > 0)
135  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
136  << " used recHits";
137 }
138 
139 template <class T1, class T2>
140 void HGCalRecHitValidation::recHitValidation(DetId& detId, int layer, const T1* geom, T2 it) {
141  const GlobalPoint& global = geom->getPosition(detId);
142  double energy = it->energy();
143 
144  float globalx = global.x();
145  float globaly = global.y();
146  float globalz = global.z();
147 
148  HitsInfo hinfo;
149  hinfo.energy = energy;
150  hinfo.x = globalx;
151  hinfo.y = globaly;
152  hinfo.z = globalz;
153  hinfo.layer = layer - firstLayer_;
154  hinfo.phi = global.phi();
155  hinfo.eta = global.eta();
156 
157  if (verbosity_ > 1)
158  edm::LogVerbatim("HGCalValidation") << "-------------------------- gx = " << globalx << " gy = " << globaly
159  << " gz = " << globalz << " phi = " << hinfo.phi << " eta = " << hinfo.eta
160  << " lay = " << hinfo.layer;
161 
163 
164  if (hinfo.eta > 0)
166  else
168 }
169 
170 void HGCalRecHitValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
171  if (OccupancyMap.find(layer) != OccupancyMap.end())
172  OccupancyMap[layer]++;
173  else
174  OccupancyMap[layer] = 1;
175 }
176 
178  for (auto const& itr : OccupancyMap_plus) {
179  int layer = itr.first;
180  int occupancy = itr.second;
181  HitOccupancy_Plus_.at(layer)->Fill(occupancy);
182  }
183 
184  for (auto const& itr : OccupancyMap_minus) {
185  int layer = itr.first;
186  int occupancy = itr.second;
187  HitOccupancy_Minus_.at(layer)->Fill(occupancy);
188  }
189 }
190 
192  unsigned int ilayer = hits.layer;
193  energy_.at(ilayer)->Fill(hits.energy);
194 
195  EtaPhi_Plus_.at(ilayer)->Fill(hits.eta, hits.phi);
196  EtaPhi_Minus_.at(ilayer)->Fill(hits.eta, hits.phi);
197 }
198 
201  if (!geomHandle.isValid()) {
202  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
203  << "Object for " << nameDetector_;
204  } else {
205  const HGCalGeometry* geom = geomHandle.product();
206  const HGCalDDDConstants& hgcons_ = geom->topology().dddConstants();
207  layers_ = hgcons_.layers(true);
208  firstLayer_ = hgcons_.firstLayer();
209  }
210 }
211 
213  iB.setCurrentFolder("HGCAL/HGCalRecHitsV/" + nameDetector_);
214  std::ostringstream histoname;
215  for (unsigned int il = 0; il < layers_; ++il) {
216  int ilayer = firstLayer_ + static_cast<int>(il);
217  auto istr1 = std::to_string(ilayer);
218  while (istr1.size() < 2) {
219  istr1.insert(0, "0");
220  }
221  histoname.str("");
222  histoname << "HitOccupancy_Plus_layer_" << istr1;
223  HitOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Plus", 100, 0, 10000));
224  histoname.str("");
225  histoname << "HitOccupancy_Minus_layer_" << istr1;
226  HitOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Minus", 100, 0, 10000));
227 
228  histoname.str("");
229  histoname << "EtaPhi_Plus_"
230  << "layer_" << istr1;
231  EtaPhi_Plus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, 1.45, 3.0, 72, -CLHEP::pi, CLHEP::pi));
232  histoname.str("");
233  histoname << "EtaPhi_Minus_"
234  << "layer_" << istr1;
235  EtaPhi_Minus_.push_back(
236  iB.book2D(histoname.str().c_str(), "Occupancy", 31, -3.0, -1.45, 72, -CLHEP::pi, CLHEP::pi));
237 
238  histoname.str("");
239  histoname << "energy_layer_" << istr1;
240  energy_.push_back(iB.book1D(histoname.str().c_str(), "energy_", 500, 0, 1));
241  } //loop over layers ends here
242 
243  histoname.str("");
244  histoname << "SUMOfRecHitOccupancy_Plus";
246  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
247  histoname.str("");
248  histoname << "SUMOfRecHitOccupancy_Minus";
250  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
251 }
252 
253 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
254 
256 
257 //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
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geometry_token_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T z() const
Definition: PV3DBase.h:61
size_type size() const
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_
constexpr std::array< uint8_t, layerIndexSize > layer
const Double_t pi
MonitorElement * MeanHitOccupancy_Plus_
const std::string nameDetector_
int layer() const
get the layer #
const edm::EDGetTokenT< HGCRecHitCollection > recHitSource_
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~HGCalRecHitValidation() override=default
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
std::map< int, int > OccupancyMap_minus
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geometry_beginRun_token_
int layer() const
get the layer #
Transition
Definition: Transition.h:12
MonitorElement * MeanHitOccupancy_Minus_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
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