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 
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 
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
ConfigurationDescriptions.h
HGCalRecHitValidation::HitsInfo::phi
float phi
Definition: HGCalRecHitValidation.cc:45
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
dqm::impl::MonitorElement
Definition: MonitorElement.h:99
ESTransientHandle.h
HGCalRecHitValidation::~HGCalRecHitValidation
~HGCalRecHitValidation() override
Definition: HGCalRecHitValidation.cc:50
HGCalRecHitValidation::nameDetector_
std::string nameDetector_
Definition: HGCalRecHitValidation.cc:65
edm::Handle::product
T const * product() const
Definition: Handle.h:70
HGCalRecHitValidation::MeanHitOccupancy_Minus_
MonitorElement * MeanHitOccupancy_Minus_
Definition: HGCalRecHitValidation.cc:81
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
ESHandle.h
HGCalRecHitValidation
Definition: HGCalRecHitValidation.cc:33
ESInputTag
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
HGCalDDDConstants::firstLayer
int firstLayer() const
Definition: HGCalDDDConstants.h:53
HGCalRecHitValidation::fillOccupancyMap
void fillOccupancyMap(std::map< int, int > &OccupancyMap, int layer)
Definition: HGCalRecHitValidation.cc:183
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
HGCalRecHitValidation::EtaPhi_Minus_
std::vector< MonitorElement * > EtaPhi_Minus_
Definition: HGCalRecHitValidation.cc:76
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
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:68
HGCalRecHitValidation::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: HGCalRecHitValidation.cc:225
gpuPixelDoublets::ntot
__shared__ uint32_t ntot
Definition: gpuPixelDoubletsAlgos.h:67
HGCalRecHitValidation::geometry_token_
edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geometry_token_
Definition: HGCalRecHitValidation.cc:66
DQMStore.h
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
hinfo
Definition: TauTagValidation.h:55
HGCalRecHitValidation::OccupancyMap_plus
std::map< int, int > OccupancyMap_plus
Definition: HGCalRecHitValidation.cc:72
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:102
HGCSiliconDetId
Definition: HGCSiliconDetId.h:22
HGCalDDDConstants
Definition: HGCalDDDConstants.h:27
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:37
HGCalRecHitValidation::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HGCalRecHitValidation.cc:110
HGCalRecHitValidation::layers_
unsigned int layers_
Definition: HGCalRecHitValidation.cc:70
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HGCalRecHitValidation::HitOccupancy_Plus_
std::vector< MonitorElement * > HitOccupancy_Plus_
Definition: HGCalRecHitValidation.cc:78
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HGCalRecHitValidation::energysum::energysum
energysum()
Definition: HGCalRecHitValidation.cc:36
HGCalRecHitValidation::HitsInfo::z
float z
Definition: HGCalRecHitValidation.cc:45
HGCalRecHitValidation::HitsInfo::layer
float layer
Definition: HGCalRecHitValidation.cc:46
HGCalRecHitValidation::energysum
Definition: HGCalRecHitValidation.cc:35
edm::ESHandle
Definition: DTSurvey.h:22
HGCalRecHitValidation::HGCalRecHitValidation
HGCalRecHitValidation(const edm::ParameterSet &)
Definition: HGCalRecHitValidation.cc:84
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
Point3DBase< float, GlobalTag >
HGCalGeometry
Definition: HGCalGeometry.h:29
DQMEDAnalyzer.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HGCalRecHitValidation::recHitValidation
void recHitValidation(DetId &detId, int layer, const T1 *geom, T2 it)
Definition: HGCalRecHitValidation.cc:153
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
HGCalRecHitValidation::firstLayer_
int firstLayer_
Definition: HGCalRecHitValidation.cc:71
DQMEDAnalyzer
Definition: DQMEDAnalyzer.py:1
HGCalRecHitValidation::EtaPhi_Plus_
std::vector< MonitorElement * > EtaPhi_Plus_
Definition: HGCalRecHitValidation.cc:75
HGCRecHitCollections.h
HGCalGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
HGCalRecHitValidation::HitOccupancy_Minus_
std::vector< MonitorElement * > HitOccupancy_Minus_
Definition: HGCalRecHitValidation.cc:79
Event.h
HGCalRecHitValidation::HitsInfo
Definition: HGCalRecHitValidation.cc:40
HGCalRecHitValidation::HitsInfo::HitsInfo
HitsInfo()
Definition: HGCalRecHitValidation.cc:41
HGCalRecHitValidation::dqmBeginRun
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Definition: HGCalRecHitValidation.cc:212
HGCalRecHitValidation::energysum::e100
double e100
Definition: HGCalRecHitValidation.cc:37
HGCalRecHitValidation::HitsInfo::time
float time
Definition: HGCalRecHitValidation.cc:45
HGCalDDDConstants::layers
unsigned int layers(bool reco) const
Definition: HGCalDDDConstants.cc:577
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
HGCalRecHitValidation::HitsInfo::energy
float energy
Definition: HGCalRecHitValidation.cc:45
HGCalRecHitValidation::HitsInfo::eta
float eta
Definition: HGCalRecHitValidation.cc:45
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
HGCalRecHitValidation::HitsInfo::x
float x
Definition: HGCalRecHitValidation.cc:45
HGCalRecHitValidation::energysum::e1000
double e1000
Definition: HGCalRecHitValidation.cc:37
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:58
edm::EDGetToken
Definition: EDGetToken.h:35
motionPolicyChamber.geom0
geom0
Definition: motionPolicyChamber.py:83
HGCalRecHitValidation::fillHitsInfo
void fillHitsInfo()
Definition: HGCalRecHitValidation.cc:190
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
edm::ESGetToken< HGCalGeometry, IdealGeometryRecord >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HGCalRecHitValidation::energy_
std::vector< MonitorElement * > energy_
Definition: HGCalRecHitValidation.cc:77
InputTag.h
HGCalDetId
Definition: HGCalDetId.h:8
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HGCalRecHitValidation::MeanHitOccupancy_Plus_
MonitorElement * MeanHitOccupancy_Plus_
Definition: HGCalRecHitValidation.cc:80
std
Definition: JetResolutionObject.h:76
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:245
HGCalRecHitValidation::HitsInfo::y
float y
Definition: HGCalRecHitValidation.cc:45
CaloGeometry.h
HGCalRecHitValidation::verbosity_
int verbosity_
Definition: HGCalRecHitValidation.cc:69
HGCalRecHitValidation::energysum::e15
double e15
Definition: HGCalRecHitValidation.cc:37
HGCalRecHitValidation::OccupancyMap_minus
std::map< int, int > OccupancyMap_minus
Definition: HGCalRecHitValidation.cc:73
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm::implementation::IBooker
Definition: DQMStore.h:43
HGCalRecHitValidation::geometry_beginRun_token_
edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geometry_beginRun_token_
Definition: HGCalRecHitValidation.cc:67
pi
const Double_t pi
Definition: trackSplitPlot.h:36
HGCalDDDConstants.h
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
HGCalRecHitValidation::energysum::e250
double e250
Definition: HGCalRecHitValidation.cc:37
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:37