CMS 3D CMS Logo

HGCGeometryValidation.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <iostream>
3 
9 
12 
26 
33 
35 
36 #include "CLHEP/Geometry/Point3D.h"
37 #include "CLHEP/Geometry/Vector3D.h"
38 #include "CLHEP/Units/GlobalSystemOfUnits.h"
39 #include "CLHEP/Units/GlobalPhysicalConstants.h"
40 
42 
43 public:
44 
45  explicit HGCGeometryValidation( const edm::ParameterSet& );
46  ~HGCGeometryValidation() override;
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49 protected:
50  void dqmBeginRun(edm::Run const&, edm::EventSetup const&) override;
51  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
52  void analyze(const edm::Event&, const edm::EventSetup&) override;
53 
54 private:
56  std::vector<std::string> geometrySource_;
57 
58  //HGCal geometry scheme
59  std::vector<const HGCalDDDConstants*> hgcGeometry_;
61 
62  //histogram related stuff
73 
78 };
79 
81 
82  g4Token_ = consumes<PHGCalValidInfo>(cfg.getParameter<edm::InputTag>("g4Source"));
83  geometrySource_ = cfg.getUntrackedParameter< std::vector<std::string> >("geometrySource");
84 }
85 
87 
90  desc.setUnknown();
91  descriptions.addDefault(desc);
92 }
93 
95  const edm::EventSetup& iSetup) {
96 
97  //initiating hgcnumbering
98  for (size_t i=0; i<geometrySource_.size(); i++) {
99  if (geometrySource_[i].find("Hcal") != std::string::npos) {
101  iSetup.get<HcalSimNumberingRecord>().get(pHRNDC);
102  if (pHRNDC.isValid()) {
103  hcons_ = &(*pHRNDC);
104  hgcGeometry_.push_back(nullptr);
105  } else {
106  edm::LogWarning("HGCalValid") << "Cannot initiate HGCalGeometry for "
107  << geometrySource_[i] << std::endl;
108  }
109  } else {
111  iSetup.get<IdealGeometryRecord>().get(geometrySource_[i],hgcGeom);
112  if (hgcGeom.isValid()) {
113  hgcGeometry_.push_back(hgcGeom.product());
114  } else {
115  edm::LogWarning("HGCalValid") << "Cannot initiate HGCalGeometry for "
116  << geometrySource_[i] << std::endl;
117  }
118  }
119  }
120 }
121 
122 
124  edm::Run const&,
125  edm::EventSetup const&) {
126 
127  iB.setCurrentFolder("HGCalSimHitsV/Geometry");
128 
129  //initiating histograms
130  heeTotEdepStep = iB.book1D("heeTotEdepStep","",100,0,100);
131  hefTotEdepStep = iB.book1D("hefTotEdepStep","",100,0,100);
132  hebTotEdepStep = iB.book1D("hebTotEdepStep","",100,0,100);
133 
134  hebLayerVsEnStep = iB.book2D("hebLayerVsEnStep","",25,0,25,100,0,0.01);
135  hefLayerVsEnStep = iB.book2D("hefLayerVsEnStep","",36,0,36,100,0,0.01);
136  heeLayerVsEnStep = iB.book2D("heeLayerVsEnStep","",84,0,84,100,0,0.01);
137 
138  heeXG4VsId = iB.book2D("heeXG4VsId","",600,-300,300,600,-300,300);
139  heeYG4VsId = iB.book2D("heeYG4VsId","",600,-300,300,600,-300,300);
140  heeZG4VsId = iB.book2D("heeZG4VsId","",3000,320,350,3000,320,350);
141 
142  hefXG4VsId = iB.book2D("hefXG4VsId","",600,-300,300,600,-300,300);
143  hefYG4VsId = iB.book2D("hefYG4VsId","",600,-300,300,600,-300,300);
144  hefZG4VsId = iB.book2D("hefZG4VsId","",6000,350,410,6000,350,410);
145 
146  hebXG4VsId = iB.book2D("hebXG4VsId","",600,-300,300,600,-300,300);
147  hebYG4VsId = iB.book2D("hebYG4VsId","",600,-300,300,600,-300,300);
148  hebZG4VsId = iB.book2D("hebZG4VsId","",220,400,620,220,400,620);
149 
150  heedzVsZ = iB.book2D("heedzVsZ","",600,320,350,100,-1,1);
151  heedyVsY = iB.book2D("heedyVsY","",400,-200,200,100,-1,1);
152  heedxVsX = iB.book2D("heedxVsX","",400,-200,200,100,-1,1);
153 
154  hefdzVsZ = iB.book2D("hefdzVsZ","",1200,350,410,100,-1,1);
155  hefdyVsY = iB.book2D("hefdyVsY","",400,-200,200,100,-1,1);
156  hefdxVsX = iB.book2D("hefdxVsX","",400,-200,200,100,-1,1);
157 
158  hebdzVsZ = iB.book2D("hebdzVsZ","",220,400,620,100,-5,5);
159  hebdyVsY = iB.book2D("hebdyVsY","",400,-200,200,100,-5,5);
160  hebdxVsX = iB.book2D("hebdxVsX","",400,-200,200,100,-5,5);
161 
162  heedzVsLayer = iB.book2D("heedzVsLayer","",100,0,100,100,-1,1);
163  hefdzVsLayer = iB.book2D("hefdzVsLayer","",40,0,40,100,-1,1);
164  hebdzVsLayer = iB.book2D("hebdzVsLayer","",50,0,25,100,-5,5);
165 
166  heedyVsLayer = iB.book2D("heedyVsLayer","",100,0,100,100,-1,1);
167  hefdyVsLayer = iB.book2D("hefdyVsLayer","",40,0,40,100,-1,1);
168  hebdyVsLayer = iB.book2D("hebdyVsLayer","",50,0,25,100,-5,5);
169 
170  heedxVsLayer = iB.book2D("heedxVsLayer","",100,0,100,100,-1,1);
171  hefdxVsLayer = iB.book2D("hefdxVsLayer","",40,0,40,500,-1,1);
172  hebdxVsLayer = iB.book2D("hebdxVsLayer","",50,0,25,500,-5,5.0);
173 
174  heedX = iB.book1D("heedX","",100,-1,1);
175  heedY = iB.book1D("heedY","",100,-1,1);
176  heedZ = iB.book1D("heedZ","",100,-1,1);
177 
178  hefdX = iB.book1D("hefdX","",100,-1,1);
179  hefdY = iB.book1D("hefdY","",100,-1,1);
180  hefdZ = iB.book1D("hefdZ","",100,-1,1);
181 
182  hebdX = iB.book1D("hebdX","",100,-1,1);
183  hebdY = iB.book1D("hebdY","",100,-1,1);
184  hebdZ = iB.book1D("hebdZ","",100,-1,1);
185 }
186 
188  const edm::EventSetup &iSetup) {
189 
190  //Accessing G4 information
192  iEvent.getByToken(g4Token_,infoLayer);
193 
194  if (infoLayer.isValid()) {
195  //step vertex information
196  std::vector<float> hitVtxX = infoLayer->hitvtxX();
197  std::vector<float> hitVtxY = infoLayer->hitvtxY();
198  std::vector<float> hitVtxZ = infoLayer->hitvtxZ();
199  std::vector<unsigned int> hitDet = infoLayer->hitDets();
200  std::vector<unsigned int> hitIdx = infoLayer->hitIndex();
201 
202  //energy information
203  std::vector<float> edepLayerEE = infoLayer->eehgcEdep();
204  std::vector<float> edepLayerHE = infoLayer->hefhgcEdep();
205  std::vector<float> edepLayerHB = infoLayer->hebhgcEdep();
206 
207  unsigned int i;
208  for(i=0; i<edepLayerEE.size(); i++) {
209  heeLayerVsEnStep->Fill(i,edepLayerEE.at(i));
210  }
211 
212  for(i=0; i<edepLayerHE.size(); i++) {
213  hefLayerVsEnStep->Fill(i,edepLayerHE.at(i));
214  }
215 
216  for(i=0; i<edepLayerHB.size(); i++) {
217  hebLayerVsEnStep->Fill(i,edepLayerHB.at(i));
218  }
219 
220  //fill total energy deposited
221  heeTotEdepStep->Fill((double)infoLayer->eeTotEdep());
222  hefTotEdepStep->Fill((double)infoLayer->hefTotEdep());
223  hebTotEdepStep->Fill((double)infoLayer->hebTotEdep());
224 
225  //loop over all hits
226  for(unsigned int i=0; i<hitVtxX.size(); i++) {
227 
228  if (hitDet.at(i) == (unsigned int)(DetId::Forward)) {
229  int subdet, zside, layer, wafer, celltype, cell;
230  HGCalTestNumbering::unpackHexagonIndex(hitIdx.at(i), subdet, zside, layer, wafer, celltype, cell);
231 
232  std::pair<float, float> xy;
233  std::pair<int,float> layerIdx;
234  double zp, xx, yx;
235 
236  if (subdet==(int)(HGCEE)) {
237  xy = hgcGeometry_[0]->locateCell(cell,layer,wafer,false); //mm
238  zp = hgcGeometry_[0]->waferZ(layer,false); //cm
239  if (zside < 0) zp = -zp;
240  xx = (zp<0) ? -xy.first/10 : xy.first/10; //mm
241  yx = xy.second/10; //mm
242  hitVtxX.at(i) = hitVtxX.at(i)/10;
243  hitVtxY.at(i) = hitVtxY.at(i)/10;
244  hitVtxZ.at(i) = hitVtxZ.at(i)/10;
245 
246  heedzVsZ->Fill(zp, (hitVtxZ.at(i)-zp));
247  heedyVsY->Fill(yx, (hitVtxY.at(i)-yx));
248  heedxVsX->Fill(xx, (hitVtxX.at(i)-xx));
249 
250  heeXG4VsId->Fill(hitVtxX.at(i),xx);
251  heeYG4VsId->Fill(hitVtxY.at(i),yx);
252  heeZG4VsId->Fill(hitVtxZ.at(i),zp);
253 
254  heedzVsLayer->Fill(layer,(hitVtxZ.at(i)-zp));
255  heedyVsLayer->Fill(layer,(hitVtxY.at(i)-yx));
256  heedxVsLayer->Fill(layer,(hitVtxX.at(i)-xx));
257 
258  heedX->Fill((hitVtxX.at(i)-xx));
259  heedZ->Fill((hitVtxZ.at(i)-zp));
260  heedY->Fill((hitVtxY.at(i)-yx));
261 
262  } else if (subdet==(int)(HGCHEF)) {
263 
264  xy = hgcGeometry_[1]->locateCell(cell,layer,wafer,false); //mm
265  zp = hgcGeometry_[1]->waferZ(layer,false); //cm
266  if (zside < 0) zp = -zp;
267  xx = (zp<0) ? -xy.first/10 : xy.first/10; //mm
268  yx = xy.second/10; //mm
269  hitVtxX.at(i) = hitVtxX.at(i)/10;
270  hitVtxY.at(i) = hitVtxY.at(i)/10;
271  hitVtxZ.at(i) = hitVtxZ.at(i)/10;
272 
273  hefdzVsZ->Fill(zp, (hitVtxZ.at(i)-zp));
274  hefdyVsY->Fill(yx, (hitVtxY.at(i)-yx));
275  hefdxVsX->Fill(xx, (hitVtxX.at(i)-xx));
276 
277  hefXG4VsId->Fill(hitVtxX.at(i),xx);
278  hefYG4VsId->Fill(hitVtxY.at(i),yx);
279  hefZG4VsId->Fill(hitVtxZ.at(i),zp);
280 
281  hefdzVsLayer->Fill(layer,(hitVtxZ.at(i)-zp));
282  hefdyVsLayer->Fill(layer,(hitVtxY.at(i)-yx));
283  hefdxVsLayer->Fill(layer,(hitVtxX.at(i)-xx));
284 
285  hefdX->Fill((hitVtxX.at(i)-xx));
286  hefdZ->Fill((hitVtxZ.at(i)-zp));
287  hefdY->Fill((hitVtxY.at(i)-yx));
288 
289  }
290 
291  } else if (hitDet.at(i) == (unsigned int)(DetId::Hcal)) {
292 
293  int subdet, zside, depth, eta, phi, lay;
294  HcalTestNumbering::unpackHcalIndex(hitIdx.at(i), subdet, zside, depth, eta, phi, lay);
295  HcalCellType::HcalCell cell = hcons_->cell(subdet, zside, lay, eta, phi);
296 
297  double zp = cell.rz/10; //mm --> cm
298  if (zside == 0) zp = -zp;
299  double rho = zp*tan(2.0*atan(exp(-cell.eta)));
300  double xp = rho * cos(cell.phi); //cm
301  double yp = rho * sin(cell.phi); //cm
302 
303  hitVtxX.at(i) = hitVtxX.at(i)/10;
304  hitVtxY.at(i) = hitVtxY.at(i)/10;
305  hitVtxZ.at(i) = hitVtxZ.at(i)/10;
306 
307  hebdzVsZ->Fill(zp, (hitVtxZ.at(i)-zp));
308  hebdyVsY->Fill(yp, (hitVtxY.at(i)-yp));
309  hebdxVsX->Fill(xp, (hitVtxX.at(i)-xp));
310 
311  hebXG4VsId->Fill(hitVtxX.at(i),xp);
312  hebYG4VsId->Fill(hitVtxY.at(i),yp);
313  hebZG4VsId->Fill(hitVtxZ.at(i),zp);
314 
315  hebdzVsLayer->Fill(lay,(hitVtxZ.at(i)-zp));
316  hebdyVsLayer->Fill(lay,(hitVtxY.at(i)-yp));
317  hebdxVsLayer->Fill(lay,(hitVtxX.at(i)-xp));
318 
319  hebdX->Fill((hitVtxX.at(i)-xp));
320  hebdZ->Fill((hitVtxZ.at(i)-zp));
321  hebdY->Fill((hitVtxY.at(i)-yp));
322  }
323 
324  }//end G4 hits
325 
326  } else {
327  edm::LogWarning("HGCalValid") << "No PHGCalInfo " << std::endl;
328  }
329 
330 }
331 
332 //define this as a plug-in
334 
335 
336 
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:519
#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)
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:279
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
const T & get() const
Definition: EventSetup.h:59
std::vector< float > hebhgcEdep() const
MonitorElement * hebLayerVsEnStep
const HcalDDDSimConstants * hcons_
float hebTotEdep() const
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:43