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 
18 
27 
35 
36 #include "CLHEP/Units/GlobalSystemOfUnits.h"
37 #include "TVector3.h"
38 
40 public:
41  struct energysum {
42  energysum() { e15 = e25 = e50 = e100 = e250 = e1000 = 0.0; }
43  double e15, e25, e50, e100, e250, e1000;
44  };
45 
46  struct HitsInfo {
48  x = y = z = time = energy = phi = eta = 0.0;
49  layer = 0;
50  }
51  float x, y, z, time, energy, phi, eta;
52  float layer;
53  };
54 
56  ~HGCalRecHitValidation() override {}
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
60  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
61  void analyze(const edm::Event&, const edm::EventSetup&) override;
62 
63 private:
64  template <class T1, class T2>
65  void recHitValidation(DetId& detId, int layer, const T1* geom, T2 it);
66  void fillHitsInfo();
67  void fillHitsInfo(HitsInfo& hits);
68  void fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer);
69 
70  // ----------member data ---------------------------
73  bool ifHCAL_;
75  unsigned int layers_;
77  std::map<int, int> OccupancyMap_plus;
78  std::map<int, int> OccupancyMap_minus;
79 
80  std::vector<MonitorElement*> EtaPhi_Plus_;
81  std::vector<MonitorElement*> EtaPhi_Minus_;
82  std::vector<MonitorElement*> energy_;
83  std::vector<MonitorElement*> HitOccupancy_Plus_;
84  std::vector<MonitorElement*> HitOccupancy_Minus_;
87 };
88 
90  : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
91  ifHCAL_(iConfig.getParameter<bool>("ifHCAL")),
92  verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
93  firstLayer_(1) {
94  auto temp = iConfig.getParameter<edm::InputTag>("RecHitSource");
95  if (nameDetector_ == "HGCalEESensitive" || nameDetector_ == "HGCalHESiliconSensitive" ||
96  nameDetector_ == "HGCalHEScintillatorSensitive") {
97  recHitSource_ = consumes<HGCRecHitCollection>(temp);
98  } else if (nameDetector_ == "HCal") {
99  if (ifHCAL_)
100  recHitSource_ = consumes<HBHERecHitCollection>(temp);
101  else
102  recHitSource_ = consumes<HGChebRecHitCollection>(temp);
103  } else {
104  throw cms::Exception("BadHGCRecHitSource") << "HGCal DetectorName given as " << nameDetector_ << " must be: "
105  << "\"HGCalHESiliconSensitive\", \"HGCalHESiliconSensitive\", "
106  << "\"HGCalHEScintillatorSensitive\", or \"HCal\"!";
107  }
108 }
109 
112  desc.add<std::string>("DetectorName", "HGCalEESensitive");
113  desc.add<edm::InputTag>("RecHitSource", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
114  desc.add<bool>("ifHCAL", false);
115  desc.addUntracked<int>("Verbosity", 0);
116  descriptions.add("hgcalRecHitValidationEE", desc);
117 }
118 
120  OccupancyMap_plus.clear();
121  OccupancyMap_minus.clear();
122 
123  bool ok(true);
124  unsigned int ntot(0), nused(0);
125  if (nameDetector_ == "HCal") {
127  iSetup.get<CaloGeometryRecord>().get(geom);
128  if (!geom.isValid()) {
129  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
130  << "Object for " << nameDetector_;
131  } else {
132  const CaloGeometry* geom0 = geom.product();
133  if (ifHCAL_) {
135  iEvent.getByToken(recHitSource_, hbhecoll);
136  if (hbhecoll.isValid()) {
137  if (verbosity_ > 0)
138  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with " << hbhecoll->size() << " element(s)";
139  for (const auto& it : *(hbhecoll.product())) {
140  DetId detId = it.id();
141  ntot++;
142  if (detId.subdetId() == HcalEndcap) {
143  nused++;
144  int layer = HcalDetId(detId).depth();
145  recHitValidation(detId, layer, geom0, &it);
146  }
147  }
148  } else {
149  ok = false;
150  edm::LogVerbatim("HGCalValidation") << "HBHERecHitCollection "
151  << "Handle does not exist !!!";
152  }
153  } else {
155  iEvent.getByToken(recHitSource_, hbhecoll);
156  if (hbhecoll.isValid()) {
157  if (verbosity_ > 0)
158  edm::LogVerbatim("HGCalValidation") << nameDetector_ << " with " << hbhecoll->size() << " element(s)";
159  for (const auto& it : *(hbhecoll.product())) {
160  DetId detId = it.id();
161  ntot++;
162  nused++;
163  int layer = HcalDetId(detId).depth();
164  recHitValidation(detId, layer, geom0, &it);
165  }
166  } else {
167  ok = false;
168  edm::LogVerbatim("HGCalValidation") << "HGChebRecHitCollection "
169  << "Handle does not exist !!!";
170  }
171  }
172  }
173  } else {
176  if (!geom.isValid()) {
177  edm::LogVerbatim("HGCalValidation") << "Cannot get valid HGCalGeometry "
178  << "Object for " << nameDetector_;
179  } else {
180  const HGCalGeometry* geom0 = geom.product();
181  int geomType = ((geom0->topology().waferHexagon8()) ? 1 : ((geom0->topology().tileTrapezoid()) ? 2 : 0));
182 
183  edm::Handle<HGCRecHitCollection> theRecHitContainers;
184  iEvent.getByToken(recHitSource_, theRecHitContainers);
185  if (theRecHitContainers.isValid()) {
186  if (verbosity_ > 0)
187  edm::LogVerbatim("HGCalValidation")
188  << nameDetector_ << " with " << theRecHitContainers->size() << " element(s)";
189  for (const auto& it : *(theRecHitContainers.product())) {
190  ntot++;
191  nused++;
192  DetId detId = it.id();
193  int layer = ((geomType == 0)
194  ? HGCalDetId(detId).layer()
195  : ((geomType == 1) ? HGCSiliconDetId(detId).layer() : HGCScintillatorDetId(detId).layer()));
196  recHitValidation(detId, layer, geom0, &it);
197  }
198  } else {
199  ok = false;
200  edm::LogVerbatim("HGCalValidation") << "HGCRecHitCollection Handle "
201  << "does not exist !!!";
202  }
203  }
204  }
205  if (ok)
206  fillHitsInfo();
207  if (verbosity_ > 0)
208  edm::LogVerbatim("HGCalValidation") << "Event " << iEvent.id().event() << " with " << ntot << " total and " << nused
209  << " used recHits";
210 }
211 
212 template <class T1, class T2>
213 void HGCalRecHitValidation::recHitValidation(DetId& detId, int layer, const T1* geom, T2 it) {
214  const GlobalPoint& global = geom->getPosition(detId);
215  double energy = it->energy();
216 
217  float globalx = global.x();
218  float globaly = global.y();
219  float globalz = global.z();
220 
221  HitsInfo hinfo;
222  hinfo.energy = energy;
223  hinfo.x = globalx;
224  hinfo.y = globaly;
225  hinfo.z = globalz;
226  hinfo.layer = layer - firstLayer_;
227  hinfo.phi = global.phi();
228  hinfo.eta = global.eta();
229 
230  if (verbosity_ > 1)
231  edm::LogVerbatim("HGCalValidation") << "-------------------------- gx = " << globalx << " gy = " << globaly
232  << " gz = " << globalz << " phi = " << hinfo.phi << " eta = " << hinfo.eta
233  << " lay = " << hinfo.layer;
234 
236 
237  if (hinfo.eta > 0)
239  else
241 }
242 
243 void HGCalRecHitValidation::fillOccupancyMap(std::map<int, int>& OccupancyMap, int layer) {
244  if (OccupancyMap.find(layer) != OccupancyMap.end())
245  OccupancyMap[layer]++;
246  else
247  OccupancyMap[layer] = 1;
248 }
249 
251  for (auto const& itr : OccupancyMap_plus) {
252  int layer = itr.first;
253  int occupancy = itr.second;
254  HitOccupancy_Plus_.at(layer)->Fill(occupancy);
255  }
256 
257  for (auto const& itr : OccupancyMap_minus) {
258  int layer = itr.first;
259  int occupancy = itr.second;
260  HitOccupancy_Minus_.at(layer)->Fill(occupancy);
261  }
262 }
263 
265  unsigned int ilayer = hits.layer;
266  energy_.at(ilayer)->Fill(hits.energy);
267 
268  EtaPhi_Plus_.at(ilayer)->Fill(hits.eta, hits.phi);
269  EtaPhi_Minus_.at(ilayer)->Fill(hits.eta, hits.phi);
270 }
271 
273  if (nameDetector_ == "HCal") {
275  iSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
276  const HcalDDDRecConstants* hcons = &(*pHRNDC);
277  layers_ = hcons->getMaxDepth(1);
278  } else {
280  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
281  const HGCalDDDConstants& hgcons_ = (*pHGDC);
282  layers_ = hgcons_.layers(true);
283  firstLayer_ = hgcons_.firstLayer();
284  }
285 }
286 
288  iB.setCurrentFolder("HGCAL/HGCalRecHitsV/" + nameDetector_);
289  std::ostringstream histoname;
290  for (unsigned int il = 0; il < layers_; ++il) {
291  int ilayer = firstLayer_ + (int)(il);
292  auto istr1 = std::to_string(ilayer);
293  while (istr1.size() < 2) {
294  istr1.insert(0, "0");
295  }
296  histoname.str("");
297  histoname << "HitOccupancy_Plus_layer_" << istr1;
298  HitOccupancy_Plus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Plus", 100, 0, 10000));
299  histoname.str("");
300  histoname << "HitOccupancy_Minus_layer_" << istr1;
301  HitOccupancy_Minus_.push_back(iB.book1D(histoname.str().c_str(), "RecHitOccupancy_Minus", 100, 0, 10000));
302 
303  histoname.str("");
304  histoname << "EtaPhi_Plus_"
305  << "layer_" << istr1;
306  EtaPhi_Plus_.push_back(iB.book2D(histoname.str().c_str(), "Occupancy", 31, 1.45, 3.0, 72, -CLHEP::pi, CLHEP::pi));
307  histoname.str("");
308  histoname << "EtaPhi_Minus_"
309  << "layer_" << istr1;
310  EtaPhi_Minus_.push_back(
311  iB.book2D(histoname.str().c_str(), "Occupancy", 31, -3.0, -1.45, 72, -CLHEP::pi, CLHEP::pi));
312 
313  histoname.str("");
314  histoname << "energy_layer_" << istr1;
315  energy_.push_back(iB.book1D(histoname.str().c_str(), "energy_", 500, 0, 1));
316  } //loop over layers ends here
317 
318  histoname.str("");
319  histoname << "SUMOfRecHitOccupancy_Plus";
321  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Plus", layers_, -0.5, layers_ - 0.5);
322  histoname.str("");
323  histoname << "SUMOfRecHitOccupancy_Minus";
325  iB.book1D(histoname.str().c_str(), "SUMOfRecHitOccupancy_Minus", layers_, -0.5, layers_ - 0.5);
326 }
327 
328 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
329 
331 
332 //define this as a plug-in
ConfigurationDescriptions.h
HGCalRecHitValidation::HitsInfo::phi
float phi
Definition: HGCalRecHitValidation.cc:51
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
electrons_cff.bool
bool
Definition: electrons_cff.py:393
ESTransientHandle.h
HGCalRecHitValidation::~HGCalRecHitValidation
~HGCalRecHitValidation() override
Definition: HGCalRecHitValidation.cc:56
HGCalRecHitValidation::nameDetector_
std::string nameDetector_
Definition: HGCalRecHitValidation.cc:71
edm::Handle::product
T const * product() const
Definition: Handle.h:70
HGCalRecHitValidation::MeanHitOccupancy_Minus_
MonitorElement * MeanHitOccupancy_Minus_
Definition: HGCalRecHitValidation.cc:86
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
ESHandle.h
HGCalRecHitValidation
Definition: HGCalRecHitValidation.cc:39
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
HGCalDDDConstants::firstLayer
int firstLayer() const
Definition: HGCalDDDConstants.h:52
HGCalRecHitValidation::fillOccupancyMap
void fillOccupancyMap(std::map< int, int > &OccupancyMap, int layer)
Definition: HGCalRecHitValidation.cc:243
edm::Run
Definition: Run.h:45
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
HGCalRecHitValidation::EtaPhi_Minus_
std::vector< MonitorElement * > EtaPhi_Minus_
Definition: HGCalRecHitValidation.cc:81
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
HGCalRecHitValidation::recHitSource_
edm::EDGetToken recHitSource_
Definition: HGCalRecHitValidation.cc:72
HGCalRecHitValidation::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: HGCalRecHitValidation.cc:287
DQMStore.h
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
HcalRecNumberingRecord.h
HcalDetId::depth
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
hinfo
Definition: TauTagValidation.h:55
HGCalRecHitValidation::OccupancyMap_plus
std::map< int, int > OccupancyMap_plus
Definition: HGCalRecHitValidation.cc:77
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle
Definition: AssociativeIterator.h:50
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
HGCalDetId::layer
int layer() const
get the layer #
Definition: HGCalDetId.h:46
HGCalRecHitValidation::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HGCalRecHitValidation.cc:110
HGCSiliconDetId
Definition: HGCSiliconDetId.h:22
HGCalDDDConstants
Definition: HGCalDDDConstants.h:26
ForwardSubdetector.h
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
HGCScintillatorDetId::layer
int layer() const
get the layer #
Definition: HGCScintillatorDetId.h:50
DetId
Definition: DetId.h:17
MakerMacros.h
HGCalRecHitValidation::energysum::e25
double e25
Definition: HGCalRecHitValidation.cc:43
CaloGeometry
Definition: CaloGeometry.h:21
HGCalRecHitValidation::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HGCalRecHitValidation.cc:119
HGCalRecHitValidation::layers_
unsigned int layers_
Definition: HGCalRecHitValidation.cc:75
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HGCalRecHitValidation::HitOccupancy_Plus_
std::vector< MonitorElement * > HitOccupancy_Plus_
Definition: HGCalRecHitValidation.cc:83
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HGCalRecHitValidation::energysum::energysum
energysum()
Definition: HGCalRecHitValidation.cc:42
HGCalRecHitValidation::HitsInfo::z
float z
Definition: HGCalRecHitValidation.cc:51
HGCalRecHitValidation::HitsInfo::layer
float layer
Definition: HGCalRecHitValidation.cc:52
HGCalRecHitValidation::energysum
Definition: HGCalRecHitValidation.cc:41
edm::ESHandle< CaloGeometry >
HGCalRecHitValidation::HGCalRecHitValidation
HGCalRecHitValidation(const edm::ParameterSet &)
Definition: HGCalRecHitValidation.cc:89
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
Point3DBase< float, GlobalTag >
HGCalGeometry
Definition: HGCalGeometry.h:29
HcalRecNumberingRecord
Definition: HcalRecNumberingRecord.h:23
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
DQMEDAnalyzer.h
CaloGeometryRecord.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HGCalRecHitValidation::recHitValidation
void recHitValidation(DetId &detId, int layer, const T1 *geom, T2 it)
Definition: HGCalRecHitValidation.cc:213
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HGCalRecHitValidation::firstLayer_
int firstLayer_
Definition: HGCalRecHitValidation.cc:76
DQMEDAnalyzer
Definition: DQMEDAnalyzer.py:1
HGCalRecHitValidation::EtaPhi_Plus_
std::vector< MonitorElement * > EtaPhi_Plus_
Definition: HGCalRecHitValidation.cc:80
HGCRecHitCollections.h
HGCalGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
HGCalRecHitValidation::HitOccupancy_Minus_
std::vector< MonitorElement * > HitOccupancy_Minus_
Definition: HGCalRecHitValidation.cc:84
Event.h
HGCalRecHitValidation::HitsInfo
Definition: HGCalRecHitValidation.cc:46
HGCalRecHitValidation::HitsInfo::HitsInfo
HitsInfo()
Definition: HGCalRecHitValidation.cc:47
HcalDetId.h
HGCalRecHitValidation::dqmBeginRun
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Definition: HGCalRecHitValidation.cc:272
HGCalRecHitValidation::energysum::e100
double e100
Definition: HGCalRecHitValidation.cc:43
HGCalRecHitValidation::HitsInfo::time
float time
Definition: HGCalRecHitValidation.cc:51
HGCalDDDConstants::layers
unsigned int layers(bool reco) const
Definition: HGCalDDDConstants.cc:561
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
HcalDetId
Definition: HcalDetId.h:12
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
HGCalRecHitValidation::HitsInfo::energy
float energy
Definition: HGCalRecHitValidation.cc:51
HGCalRecHitValidation::HitsInfo::eta
float eta
Definition: HGCalRecHitValidation.cc:51
HGCalRecHitValidation::HitsInfo::x
float x
Definition: HGCalRecHitValidation.cc:51
HGCalRecHitValidation::energysum::e1000
double e1000
Definition: HGCalRecHitValidation.cc:43
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:57
HcalSubdetector.h
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
edm::EDGetToken
Definition: EDGetToken.h:35
get
#define get
motionPolicyChamber.geom0
geom0
Definition: motionPolicyChamber.py:83
HGCalRecHitValidation::fillHitsInfo
void fillHitsInfo()
Definition: HGCalRecHitValidation.cc:250
HGCalRecHitValidation::energy_
std::vector< MonitorElement * > energy_
Definition: HGCalRecHitValidation.cc:82
InputTag.h
HGCalDetId
Definition: HGCalDetId.h:8
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HGCalRecHitValidation::MeanHitOccupancy_Plus_
MonitorElement * MeanHitOccupancy_Plus_
Definition: HGCalRecHitValidation.cc:85
std
Definition: JetResolutionObject.h:76
HcalEndcap
Definition: HcalAssistant.h:34
DetId.h
Frameworkfwd.h
HGCScintillatorDetId
Definition: HGCScintillatorDetId.h:23
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
dqm::implementation::IBooker::book2D
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
Exception
Definition: hltDiff.cc:246
HGCalRecHitValidation::HitsInfo::y
float y
Definition: HGCalRecHitValidation.cc:51
CaloGeometry.h
HGCalRecHitValidation::verbosity_
int verbosity_
Definition: HGCalRecHitValidation.cc:74
HcalDDDRecConstants.h
HGCalRecHitValidation::energysum::e15
double e15
Definition: HGCalRecHitValidation.cc:43
HGCalRecHitValidation::OccupancyMap_minus
std::map< int, int > OccupancyMap_minus
Definition: HGCalRecHitValidation.cc:78
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HcalRecHitCollections.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
HcalDDDRecConstants::getMaxDepth
int getMaxDepth(const int &type) const
Definition: HcalDDDRecConstants.h:88
HcalDDDRecConstants
Definition: HcalDDDRecConstants.h:23
pi
const Double_t pi
Definition: trackSplitPlot.h:36
HGCalDDDConstants.h
ParameterSet.h
HGCalRecHitValidation::ifHCAL_
bool ifHCAL_
Definition: HGCalRecHitValidation.cc:73
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
HGCalRecHitValidation::energysum::e250
double e250
Definition: HGCalRecHitValidation.cc:43
edm::InputTag
Definition: InputTag.h:15
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
IdealGeometryRecord
Definition: IdealGeometryRecord.h:25
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
HGCSiliconDetId::layer
int layer() const
get the layer #
Definition: HGCSiliconDetId.h:57
HGCalRecHitValidation::energysum::e50
double e50
Definition: HGCalRecHitValidation.cc:43