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