CMS 3D CMS Logo

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