CMS 3D CMS Logo

HGCGeometryValidation.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <iostream>
3 
9 
14 
28 
35 
37 
38 #include "CLHEP/Geometry/Point3D.h"
39 #include "CLHEP/Geometry/Vector3D.h"
40 #include "CLHEP/Units/GlobalSystemOfUnits.h"
41 #include "CLHEP/Units/GlobalPhysicalConstants.h"
42 
43 const double mmtocm = 0.1;
44 
46 
47 public:
48 
49  explicit HGCGeometryValidation( const edm::ParameterSet& );
50  ~HGCGeometryValidation() override;
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 protected:
54  void dqmBeginRun(edm::Run const&, edm::EventSetup const&) override;
55  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
56  void analyze(const edm::Event&, const edm::EventSetup&) override;
57 
58 private:
60  std::vector<std::string> geometrySource_;
62 
63  //HGCal geometry scheme
64  std::vector<const HGCalDDDConstants*> hgcGeometry_;
66 
67  //histogram related stuff
78 
83 };
84 
86 
87  g4Token_ = consumes<PHGCalValidInfo>(cfg.getParameter<edm::InputTag>("g4Source"));
88  geometrySource_ = cfg.getUntrackedParameter< std::vector<std::string> >("geometrySource");
89  verbosity_ = cfg.getUntrackedParameter<int>("verbosity",0);
90 }
91 
93 
96  desc.setUnknown();
97  descriptions.addDefault(desc);
98 }
99 
101  const edm::EventSetup& iSetup) {
102 
103  //initiating hgcnumbering
104  for (size_t i=0; i<geometrySource_.size(); i++) {
105  if (geometrySource_[i].find("Hcal") != std::string::npos) {
107  iSetup.get<HcalSimNumberingRecord>().get(pHRNDC);
108  if (pHRNDC.isValid()) {
109  hcons_ = &(*pHRNDC);
110  hgcGeometry_.push_back(nullptr);
111  } else {
112  edm::LogWarning("HGCalValid") << "Cannot initiate HGCalGeometry for "
113  << geometrySource_[i];
114  }
115  } else {
117  iSetup.get<IdealGeometryRecord>().get(geometrySource_[i],hgcGeom);
118  if (hgcGeom.isValid()) {
119  hgcGeometry_.push_back(hgcGeom.product());
120  } else {
121  edm::LogWarning("HGCalValid") << "Cannot initiate HGCalGeometry for "
122  << geometrySource_[i];
123  }
124  }
125  }
126 }
127 
128 
130  edm::Run const&,
131  edm::EventSetup const&) {
132 
133  iB.setCurrentFolder("HGCAL/HGCalSimHitsV/Geometry");
134 
135  //initiating histograms
136  heeTotEdepStep = iB.book1D("heeTotEdepStep","",100,0,100);
137  hefTotEdepStep = iB.book1D("hefTotEdepStep","",100,0,100);
138  hebTotEdepStep = iB.book1D("hebTotEdepStep","",100,0,100);
139 
140  hebLayerVsEnStep = iB.book2D("hebLayerVsEnStep","",25,0,25,100,0,0.01);
141  hefLayerVsEnStep = iB.book2D("hefLayerVsEnStep","",36,0,36,100,0,0.01);
142  heeLayerVsEnStep = iB.book2D("heeLayerVsEnStep","",84,0,84,100,0,0.01);
143 
144  heeXG4VsId = iB.book2D("heeXG4VsId","",600,-300,300,600,-300,300);
145  heeYG4VsId = iB.book2D("heeYG4VsId","",600,-300,300,600,-300,300);
146  heeZG4VsId = iB.book2D("heeZG4VsId","",3000,320,350,3000,320,350);
147 
148  hefXG4VsId = iB.book2D("hefXG4VsId","",600,-300,300,600,-300,300);
149  hefYG4VsId = iB.book2D("hefYG4VsId","",600,-300,300,600,-300,300);
150  hefZG4VsId = iB.book2D("hefZG4VsId","",6000,350,410,6000,350,410);
151 
152  hebXG4VsId = iB.book2D("hebXG4VsId","",600,-300,300,600,-300,300);
153  hebYG4VsId = iB.book2D("hebYG4VsId","",600,-300,300,600,-300,300);
154  hebZG4VsId = iB.book2D("hebZG4VsId","",220,400,620,220,400,620);
155 
156  heedzVsZ = iB.book2D("heedzVsZ","",600,320,350,100,-1,1);
157  heedyVsY = iB.book2D("heedyVsY","",400,-200,200,100,-1,1);
158  heedxVsX = iB.book2D("heedxVsX","",400,-200,200,100,-1,1);
159 
160  hefdzVsZ = iB.book2D("hefdzVsZ","",1200,350,410,100,-1,1);
161  hefdyVsY = iB.book2D("hefdyVsY","",400,-200,200,100,-1,1);
162  hefdxVsX = iB.book2D("hefdxVsX","",400,-200,200,100,-1,1);
163 
164  hebdzVsZ = iB.book2D("hebdzVsZ","",220,400,620,100,-5,5);
165  hebdyVsY = iB.book2D("hebdyVsY","",400,-200,200,100,-5,5);
166  hebdxVsX = iB.book2D("hebdxVsX","",400,-200,200,100,-5,5);
167 
168  heedzVsLayer = iB.book2D("heedzVsLayer","",100,0,100,100,-1,1);
169  hefdzVsLayer = iB.book2D("hefdzVsLayer","",40,0,40,100,-1,1);
170  hebdzVsLayer = iB.book2D("hebdzVsLayer","",50,0,25,100,-5,5);
171 
172  heedyVsLayer = iB.book2D("heedyVsLayer","",100,0,100,100,-1,1);
173  hefdyVsLayer = iB.book2D("hefdyVsLayer","",40,0,40,100,-1,1);
174  hebdyVsLayer = iB.book2D("hebdyVsLayer","",50,0,25,100,-5,5);
175 
176  heedxVsLayer = iB.book2D("heedxVsLayer","",100,0,100,100,-1,1);
177  hefdxVsLayer = iB.book2D("hefdxVsLayer","",40,0,40,500,-1,1);
178  hebdxVsLayer = iB.book2D("hebdxVsLayer","",50,0,25,500,-5,5.0);
179 
180  heedX = iB.book1D("heedX","",100,-1,1);
181  heedY = iB.book1D("heedY","",100,-1,1);
182  heedZ = iB.book1D("heedZ","",100,-1,1);
183 
184  hefdX = iB.book1D("hefdX","",100,-1,1);
185  hefdY = iB.book1D("hefdY","",100,-1,1);
186  hefdZ = iB.book1D("hefdZ","",100,-1,1);
187 
188  hebdX = iB.book1D("hebdX","",100,-1,1);
189  hebdY = iB.book1D("hebdY","",100,-1,1);
190  hebdZ = iB.book1D("hebdZ","",100,-1,1);
191 }
192 
194  const edm::EventSetup &iSetup) {
195 
196  //Accessing G4 information
198  iEvent.getByToken(g4Token_,infoLayer);
199 
200  if (infoLayer.isValid()) {
201  //step vertex information
202  std::vector<float> hitVtxX = infoLayer->hitvtxX();
203  std::vector<float> hitVtxY = infoLayer->hitvtxY();
204  std::vector<float> hitVtxZ = infoLayer->hitvtxZ();
205  std::vector<unsigned int> hitDet = infoLayer->hitDets();
206  std::vector<unsigned int> hitIdx = infoLayer->hitIndex();
207 
208  //energy information
209  std::vector<float> edepLayerEE = infoLayer->eehgcEdep();
210  std::vector<float> edepLayerHE = infoLayer->hefhgcEdep();
211  std::vector<float> edepLayerHB = infoLayer->hebhgcEdep();
212 
213  unsigned int i;
214  for(i=0; i<edepLayerEE.size(); i++) {
215  heeLayerVsEnStep->Fill(i,edepLayerEE.at(i));
216  }
217 
218  for(i=0; i<edepLayerHE.size(); i++) {
219  hefLayerVsEnStep->Fill(i,edepLayerHE.at(i));
220  }
221 
222  for(i=0; i<edepLayerHB.size(); i++) {
223  hebLayerVsEnStep->Fill(i,edepLayerHB.at(i));
224  }
225 
226  //fill total energy deposited
227  heeTotEdepStep->Fill((double)infoLayer->eeTotEdep());
228  hefTotEdepStep->Fill((double)infoLayer->hefTotEdep());
229  hebTotEdepStep->Fill((double)infoLayer->hebTotEdep());
230 
231  //loop over all hits
232  for (unsigned int i=0; i<hitVtxX.size(); i++) {
233 
234  hitVtxX.at(i) = mmtocm*hitVtxX.at(i);
235  hitVtxY.at(i) = mmtocm*hitVtxY.at(i);
236  hitVtxZ.at(i) = mmtocm*hitVtxZ.at(i);
237 
238  if ((hitDet.at(i) == (unsigned int)(DetId::Forward)) ||
239  (hitDet.at(i) == (unsigned int)(DetId::HGCalEE)) ||
240  (hitDet.at(i) == (unsigned int)(DetId::HGCalHSi)) ||
241  (hitDet.at(i) == (unsigned int)(DetId::HGCalHSc))) {
242  double xx, yy;
243  int dtype(0), layer(0), zside(1);
244  std::pair<float,float> xy;
245  if (hitDet.at(i) == (unsigned int)(DetId::Forward)) {
246  int subdet, wafer, celltype, cell;
247  HGCalTestNumbering::unpackHexagonIndex(hitIdx.at(i), subdet, zside,
248  layer, wafer, celltype,cell);
249  dtype = (subdet==(int)(HGCEE)) ? 0 : 1;
250  xy = hgcGeometry_[dtype]->locateCell(cell,layer,wafer,true); //cm
251  } else if ((hitDet.at(i) == (unsigned int)(DetId::HGCalEE)) ||
252  (hitDet.at(i) == (unsigned int)(DetId::HGCalHSi))) {
253  HGCSiliconDetId id(hitIdx.at(i));
254  dtype = (id.det() == DetId::HGCalEE) ? 0 : 1;
255  layer = id.layer();
256  zside = id.zside();
257  xy = hgcGeometry_[dtype]->locateCell(layer,id.waferU(),
258  id.waferV(),id.cellU(),
259  id.cellV(),true,true);
260  } else {
261  HGCScintillatorDetId id(hitIdx.at(i));
262  dtype = 2;
263  layer = id.layer();
264  zside = id.zside();
265  xy = hgcGeometry_[dtype]->locateCellTrap(layer,id.ietaAbs(),
266  id.iphi(), true);
267  }
268  double zz = hgcGeometry_[dtype]->waferZ(layer,true); //cm
269  if (zside < 0) zz = -zz;
270  xx = (zside<0) ? -xy.first : xy.first;
271  yy = xy.second;
272 
273  if (dtype == 0) {
274 
275  heedzVsZ->Fill(zz, (hitVtxZ.at(i)-zz));
276  heedyVsY->Fill(yy, (hitVtxY.at(i)-yy));
277  heedxVsX->Fill(xx, (hitVtxX.at(i)-xx));
278 
279  heeXG4VsId->Fill(hitVtxX.at(i),xx);
280  heeYG4VsId->Fill(hitVtxY.at(i),yy);
281  heeZG4VsId->Fill(hitVtxZ.at(i),zz);
282 
283  heedzVsLayer->Fill(layer,(hitVtxZ.at(i)-zz));
284  heedyVsLayer->Fill(layer,(hitVtxY.at(i)-yy));
285  heedxVsLayer->Fill(layer,(hitVtxX.at(i)-xx));
286 
287  heedX->Fill((hitVtxX.at(i)-xx));
288  heedZ->Fill((hitVtxZ.at(i)-zz));
289  heedY->Fill((hitVtxY.at(i)-yy));
290 
291  } else if (dtype == 1) {
292 
293  hefdzVsZ->Fill(zz, (hitVtxZ.at(i)-zz));
294  hefdyVsY->Fill(yy, (hitVtxY.at(i)-yy));
295  hefdxVsX->Fill(xx, (hitVtxX.at(i)-xx));
296 
297  hefXG4VsId->Fill(hitVtxX.at(i),xx);
298  hefYG4VsId->Fill(hitVtxY.at(i),yy);
299  hefZG4VsId->Fill(hitVtxZ.at(i),zz);
300 
301  hefdzVsLayer->Fill(layer,(hitVtxZ.at(i)-zz));
302  hefdyVsLayer->Fill(layer,(hitVtxY.at(i)-yy));
303  hefdxVsLayer->Fill(layer,(hitVtxX.at(i)-xx));
304 
305  hefdX->Fill((hitVtxX.at(i)-xx));
306  hefdZ->Fill((hitVtxZ.at(i)-zz));
307  hefdY->Fill((hitVtxY.at(i)-yy));
308 
309  } else {
310 
311  hebdzVsZ->Fill(zz, (hitVtxZ.at(i)-zz));
312  hebdyVsY->Fill(yy, (hitVtxY.at(i)-yy));
313  hebdxVsX->Fill(xx, (hitVtxX.at(i)-xx));
314 
315  hebXG4VsId->Fill(hitVtxX.at(i),xx);
316  hebYG4VsId->Fill(hitVtxY.at(i),yy);
317  hebZG4VsId->Fill(hitVtxZ.at(i),zz);
318 
319  hebdzVsLayer->Fill(layer,(hitVtxZ.at(i)-zz));
320  hebdyVsLayer->Fill(layer,(hitVtxY.at(i)-yy));
321  hebdxVsLayer->Fill(layer,(hitVtxX.at(i)-xx));
322 
323  hebdX->Fill((hitVtxX.at(i)-xx));
324  hebdZ->Fill((hitVtxZ.at(i)-zz));
325  hebdY->Fill((hitVtxY.at(i)-yy));
326 
327  }
328 
329  } else if (hitDet.at(i) == (unsigned int)(DetId::Hcal)) {
330 
331  int subdet, zside, depth, eta, phi, lay;
332  HcalTestNumbering::unpackHcalIndex(hitIdx.at(i), subdet, zside, depth, eta, phi, lay);
333  HcalCellType::HcalCell cell = hcons_->cell(subdet, zside, lay, eta, phi);
334 
335  double zz = mmtocm*cell.rz; //mm --> cm
336  if (zside == 0) zz = -zz;
337  double rho = zz*tan(2.0*atan(exp(-cell.eta)));
338  double xx = rho * cos(cell.phi); //cm
339  double yy = rho * sin(cell.phi); //cm
340 
341  hebdzVsZ->Fill(zz, (hitVtxZ.at(i)-zz));
342  hebdyVsY->Fill(yy, (hitVtxY.at(i)-yy));
343  hebdxVsX->Fill(xx, (hitVtxX.at(i)-xx));
344 
345  hebXG4VsId->Fill(hitVtxX.at(i),xx);
346  hebYG4VsId->Fill(hitVtxY.at(i),yy);
347  hebZG4VsId->Fill(hitVtxZ.at(i),zz);
348 
349  hebdzVsLayer->Fill(lay,(hitVtxZ.at(i)-zz));
350  hebdyVsLayer->Fill(lay,(hitVtxY.at(i)-yy));
351  hebdxVsLayer->Fill(lay,(hitVtxX.at(i)-xx));
352 
353  hebdX->Fill((hitVtxX.at(i)-xx));
354  hebdZ->Fill((hitVtxZ.at(i)-zz));
355  hebdY->Fill((hitVtxY.at(i)-yy));
356  }
357 
358  }//end G4 hits
359 
360  } else {
361  if (verbosity_ > 0)
362  edm::LogVerbatim("HGCalValid") << "HGCGeometryValidation::No PHGCalInfo";
363  }
364 
365 }
366 
367 //define this as a plug-in
369 
370 
371 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< PHGCalValidInfo > g4Token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define nullptr
int zside(DetId const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HcalCellType::HcalCell cell(const int &det, const int &zside, const int &depth, const int &etaR, const int &iphi) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
float eeTotEdep() const
std::vector< const HGCalDDDConstants * > hgcGeometry_
void Fill(long long x)
std::vector< float > hitvtxZ() const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
float hefTotEdep() const
void addDefault(ParameterSetDescription const &psetDescription)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
MonitorElement * hefTotEdepStep
std::vector< float > eehgcEdep() const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MonitorElement * hefLayerVsEnStep
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
MonitorElement * heeLayerVsEnStep
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
const double mmtocm
bool isValid() const
Definition: HandleBase.h:74
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< float > hitvtxX() const
MonitorElement * hebTotEdepStep
std::vector< float > hitvtxY() const
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
std::vector< float > hebhgcEdep() const
MonitorElement * hebLayerVsEnStep
const HcalDDDSimConstants * hcons_
float hebTotEdep() const
T get() const
Definition: EventSetup.h:71
HGCGeometryValidation(const edm::ParameterSet &)
std::vector< unsigned int > hitIndex() const
std::vector< std::string > geometrySource_
bool isValid() const
Definition: ESHandle.h:44
MonitorElement * heeTotEdepStep
T const * product() const
Definition: ESHandle.h:86
std::vector< unsigned int > hitDets() const
std::vector< float > hefhgcEdep() const
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
Definition: Run.h:45