CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ValidateGeometry.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 
12 
14 
19 
22 
26 
32 
34 
38 
42 
48 
51 
52 #include <string>
53 #include <iostream>
54 
55 #include <TEveGeoNode.h>
56 #include <TGeoVolume.h>
57 #include <TGeoBBox.h>
58 #include <TGeoArb8.h>
59 #include <TFile.h>
60 #include <TH1.h>
61 
63 public:
64  explicit ValidateGeometry(const edm::ParameterSet&);
65  ~ValidateGeometry() override;
66 
67 private:
68  void beginJob() override;
69  void analyze(const edm::Event&, const edm::EventSetup&) override;
70  void endJob() override;
71 
72  void validateRPCGeometry(const int regionNumber, const char* regionName);
73 
76 
77  void validateCSChamberGeometry(const int endcap, const char* detname);
78 
79  void validateCSCLayerGeometry(const int endcap, const char* detname);
80 
81  void validateCaloGeometry(DetId::Detector detector, int subdetector, const char* detname);
82 
83  void validateTrackerGeometry(const TrackerGeometry::DetContainer& dets, const char* detname);
84 
85  void validatePixelTopology(const TrackerGeometry::DetContainer& dets, const char* detname);
86 
87  void validateStripTopology(const TrackerGeometry::DetContainer& dets, const char* detname);
88 
89  void compareTransform(const GlobalPoint& point, const TGeoMatrix* matrix);
90 
91  void compareShape(const GeomDet* det, const float* shape);
92 
93  double getDistance(const GlobalPoint& point1, const GlobalPoint& point2);
94 
95  void makeHistograms(const char* detector);
96  void makeHistogram(const std::string& name, std::vector<double>& data);
97 
100 
106 
112 
114 
115  TFile* outFile_;
116 
117  std::vector<double> globalDistances_;
118  std::vector<double> topWidths_;
119  std::vector<double> bottomWidths_;
120  std::vector<double> lengths_;
121  std::vector<double> thicknesses_;
122 
123  void clearData() {
124  globalDistances_.clear();
125  topWidths_.clear();
126  bottomWidths_.clear();
127  lengths_.clear();
128  thicknesses_.clear();
129  }
130 
131  bool dataEmpty() {
132  return (globalDistances_.empty() && topWidths_.empty() && bottomWidths_.empty() && lengths_.empty() &&
133  thicknesses_.empty());
134  }
135 
137  bool doMuon_;
138  bool doCalo_;
139 };
140 
142  : infileName_(iConfig.getUntrackedParameter<std::string>("infileName")),
143  outfileName_(iConfig.getUntrackedParameter<std::string>("outfileName")) {
144  doTracker_ = iConfig.getUntrackedParameter<bool>("Tracker", true);
145  doMuon_ = iConfig.getUntrackedParameter<bool>("Muon", true);
146  doCalo_ = iConfig.getUntrackedParameter<bool>("Calo", true);
147 
148  if (doMuon_) {
152  }
153  if (doCalo_) {
155  }
156  if (doTracker_) {
158  }
159 
161 
162  outFile_ = new TFile(outfileName_.c_str(), "RECREATE");
163 }
164 
166 
168  if (doMuon_) {
170 
171  if (rpcGeometry_.isValid()) {
172  std::cout << "Validating RPC -z endcap geometry" << std::endl;
173  validateRPCGeometry(-1, "RPC -z endcap");
174 
175  std::cout << "Validating RPC +z endcap geometry" << std::endl;
176  validateRPCGeometry(+1, "RPC +z endcap");
177 
178  std::cout << "Validating RPC barrel geometry" << std::endl;
179  validateRPCGeometry(0, "RPC barrel");
180  } else
181  fwLog(fwlog::kWarning) << "Invalid RPC geometry" << std::endl;
182 
183  dtGeometry_ = eventSetup.getHandle(dtGeometryToken_);
184 
185  if (dtGeometry_.isValid()) {
186  std::cout << "Validating DT chamber geometry" << std::endl;
188 
189  std::cout << "Validating DT layer geometry" << std::endl;
191  } else
192  fwLog(fwlog::kWarning) << "Invalid DT geometry" << std::endl;
193 
195 
196  if (cscGeometry_.isValid()) {
197  std::cout << "Validating CSC -z geometry" << std::endl;
198  validateCSChamberGeometry(-1, "CSC chamber -z endcap");
199 
200  std::cout << "Validating CSC +z geometry" << std::endl;
201  validateCSChamberGeometry(+1, "CSC chamber +z endcap");
202 
203  std::cout << "Validating CSC layer -z geometry" << std::endl;
204  validateCSCLayerGeometry(-1, "CSC layer -z endcap");
205 
206  std::cout << "Validating CSC layer +z geometry" << std::endl;
207  validateCSCLayerGeometry(+1, "CSC layer +z endcap");
208  } else
209  fwLog(fwlog::kWarning) << "Invalid CSC geometry" << std::endl;
210  }
211 
212  if (doTracker_) {
214 
215  if (trackerGeometry_.isValid()) {
216  std::cout << "Validating TIB geometry and topology" << std::endl;
217  validateTrackerGeometry(trackerGeometry_->detsTIB(), "TIB");
218  validateStripTopology(trackerGeometry_->detsTIB(), "TIB");
219 
220  std::cout << "Validating TOB geometry and topology" << std::endl;
221  validateTrackerGeometry(trackerGeometry_->detsTOB(), "TOB");
222  validateStripTopology(trackerGeometry_->detsTOB(), "TOB");
223 
224  std::cout << "Validating TEC geometry and topology" << std::endl;
225  validateTrackerGeometry(trackerGeometry_->detsTEC(), "TEC");
226  validateStripTopology(trackerGeometry_->detsTEC(), "TEC");
227 
228  std::cout << "Validating TID geometry and topology" << std::endl;
229  validateTrackerGeometry(trackerGeometry_->detsTID(), "TID");
230  validateStripTopology(trackerGeometry_->detsTID(), "TID");
231 
232  std::cout << "Validating PXB geometry and topology" << std::endl;
233  validateTrackerGeometry(trackerGeometry_->detsPXB(), "PXB");
234  validatePixelTopology(trackerGeometry_->detsPXB(), "PXB");
235 
236  std::cout << "Validating PXF geometry and topology" << std::endl;
237  validateTrackerGeometry(trackerGeometry_->detsPXF(), "PXF");
238  validatePixelTopology(trackerGeometry_->detsPXF(), "PXF");
239  } else
240  fwLog(fwlog::kWarning) << "Invalid Tracker geometry" << std::endl;
241  }
242 
243  if (doCalo_) {
245 
246  if (caloGeometry_.isValid()) {
247  std::cout << "Validating EB geometry" << std::endl;
249 
250  std::cout << "Validating EE geometry" << std::endl;
252 
253  std::cout << "Validating ES geometry" << std::endl;
255 
256  std::cout << "Validating HB geometry" << std::endl;
258 
259  std::cout << "Validating HE geometry" << std::endl;
261 
262  std::cout << "Validating HO geometry" << std::endl;
264 
265  std::cout << "Validating HF geometry" << std::endl;
267 
268  std::cout << "Validating Castor geometry" << std::endl;
270 
271  std::cout << "Validating ZDC geometry" << std::endl;
273  } else
274  fwLog(fwlog::kWarning) << "Invalid Calo geometry" << std::endl;
275  }
276 }
277 
278 void ValidateGeometry::validateRPCGeometry(const int regionNumber, const char* regionName) {
279  clearData();
280 
281  std::vector<double> centers;
282 
283  auto const& rolls = rpcGeometry_->rolls();
284 
285  for (auto it = rolls.begin(), itEnd = rolls.end(); it != itEnd; ++it) {
286  const RPCRoll* roll = *it;
287 
288  if (roll) {
289  RPCDetId rpcDetId = roll->id();
290 
291  if (rpcDetId.region() == regionNumber) {
292  const GeomDetUnit* det = rpcGeometry_->idToDetUnit(rpcDetId);
293  GlobalPoint gp = det->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
294 
295  const TGeoMatrix* matrix = fwGeometry_.getMatrix(rpcDetId.rawId());
296 
297  if (!matrix) {
298  std::cout << "Failed to get matrix of RPC with detid: " << rpcDetId.rawId() << std::endl;
299  continue;
300  }
301 
302  compareTransform(gp, matrix);
303 
304  const float* shape = fwGeometry_.getShapePars(rpcDetId.rawId());
305 
306  if (!shape) {
307  std::cout << "Failed to get shape of RPC with detid: " << rpcDetId.rawId() << std::endl;
308  continue;
309  }
310 
311  compareShape(det, shape);
312 
313  const float* parameters = fwGeometry_.getParameters(rpcDetId.rawId());
314 
315  if (parameters == nullptr) {
316  std::cout << "Parameters empty for RPC with detid: " << rpcDetId.rawId() << std::endl;
317  continue;
318  }
319 
320  // Yes, I know that below I'm comparing the equivalence
321  // of floating point numbers
322 
323  int nStrips = roll->nstrips();
324  assert(nStrips == parameters[0]);
325 
326  float stripLength = roll->specificTopology().stripLength();
327  assert(stripLength == parameters[1]);
328 
329  float pitch = roll->specificTopology().pitch();
330  assert(pitch == parameters[2]);
331 
332  float offset = -0.5 * nStrips * pitch;
333 
334  for (int strip = 1; strip <= roll->nstrips(); ++strip) {
335  LocalPoint centreOfStrip1 = roll->centreOfStrip(strip);
336  LocalPoint centreOfStrip2 = LocalPoint((strip - 0.5) * pitch + offset, 0.0);
337 
338  centers.push_back(centreOfStrip1.x() - centreOfStrip2.x());
339  }
340  }
341  }
342  }
343 
344  std::string hn(regionName);
345  makeHistogram(hn + ": centreOfStrip", centers);
346 
347  makeHistograms(regionName);
348 }
349 
351  clearData();
352 
353  auto const& chambers = dtGeometry_->chambers();
354 
355  for (auto it = chambers.begin(), itEnd = chambers.end(); it != itEnd; ++it) {
356  const DTChamber* chamber = *it;
357 
358  if (chamber) {
359  DTChamberId chId = chamber->id();
360  GlobalPoint gp = chamber->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
361 
362  const TGeoMatrix* matrix = fwGeometry_.getMatrix(chId.rawId());
363 
364  if (!matrix) {
365  std::cout << "Failed to get matrix of DT chamber with detid: " << chId.rawId() << std::endl;
366  continue;
367  }
368 
369  compareTransform(gp, matrix);
370 
371  const float* shape = fwGeometry_.getShapePars(chId.rawId());
372 
373  if (!shape) {
374  std::cout << "Failed to get shape of DT chamber with detid: " << chId.rawId() << std::endl;
375  continue;
376  }
377 
378  compareShape(chamber, shape);
379  }
380  }
381 
382  makeHistograms("DT chamber");
383 }
384 
386  clearData();
387 
388  std::vector<double> wire_positions;
389 
390  auto const& layers = dtGeometry_->layers();
391 
392  for (auto it = layers.begin(), itEnd = layers.end(); it != itEnd; ++it) {
393  const DTLayer* layer = *it;
394 
395  if (layer) {
396  DTLayerId layerId = layer->id();
397  GlobalPoint gp = layer->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
398 
399  const TGeoMatrix* matrix = fwGeometry_.getMatrix(layerId.rawId());
400 
401  if (!matrix) {
402  std::cout << "Failed to get matrix of DT layer with detid: " << layerId.rawId() << std::endl;
403  continue;
404  }
405 
406  compareTransform(gp, matrix);
407 
408  const float* shape = fwGeometry_.getShapePars(layerId.rawId());
409 
410  if (!shape) {
411  std::cout << "Failed to get shape of DT layer with detid: " << layerId.rawId() << std::endl;
412  continue;
413  }
414 
415  compareShape(layer, shape);
416 
417  const float* parameters = fwGeometry_.getParameters(layerId.rawId());
418 
419  if (parameters == nullptr) {
420  std::cout << "Parameters empty for DT layer with detid: " << layerId.rawId() << std::endl;
421  continue;
422  }
423 
424  float width = layer->surface().bounds().width();
425  assert(width == parameters[6]);
426 
427  float thickness = layer->surface().bounds().thickness();
428  assert(thickness == parameters[7]);
429 
430  float length = layer->surface().bounds().length();
431  assert(length == parameters[8]);
432 
433  int firstChannel = layer->specificTopology().firstChannel();
434  assert(firstChannel == parameters[3]);
435 
436  int lastChannel = layer->specificTopology().lastChannel();
437  int nChannels = parameters[5];
438  assert(nChannels == (lastChannel - firstChannel) + 1);
439 
440  for (int wireN = firstChannel; wireN - lastChannel <= 0; ++wireN) {
441  double localX1 = layer->specificTopology().wirePosition(wireN);
442  double localX2 = (wireN - (firstChannel - 1) - 0.5) * parameters[0] - nChannels / 2.0 * parameters[0];
443 
444  wire_positions.push_back(localX1 - localX2);
445 
446  //std::cout<<"wireN, localXpos: "<< wireN <<" "<< localX1 <<" "<< localX2 <<std::endl;
447  }
448  }
449  }
450 
451  makeHistogram("DT layer wire localX", wire_positions);
452 
453  makeHistograms("DT layer");
454 }
455 
456 void ValidateGeometry::validateCSChamberGeometry(const int endcap, const char* detname) {
457  clearData();
458 
459  auto const& chambers = cscGeometry_->chambers();
460 
461  for (auto it = chambers.begin(), itEnd = chambers.end(); it != itEnd; ++it) {
462  const CSCChamber* chamber = *it;
463 
464  if (chamber && chamber->id().endcap() == endcap) {
465  DetId detId = chamber->geographicalId();
466  GlobalPoint gp = chamber->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
467 
468  const TGeoMatrix* matrix = fwGeometry_.getMatrix(detId.rawId());
469 
470  if (!matrix) {
471  std::cout << "Failed to get matrix of CSC chamber with detid: " << detId.rawId() << std::endl;
472  continue;
473  }
474 
475  compareTransform(gp, matrix);
476 
477  const float* shape = fwGeometry_.getShapePars(detId.rawId());
478 
479  if (!shape) {
480  std::cout << "Failed to get shape of CSC chamber with detid: " << detId.rawId() << std::endl;
481  continue;
482  }
483 
484  compareShape(chamber, shape);
485  }
486  }
487 
488  makeHistograms(detname);
489 }
490 
491 void ValidateGeometry::validateCSCLayerGeometry(const int endcap, const char* detname) {
492  clearData();
493  std::vector<double> strip_positions;
494  std::vector<double> wire_positions;
495 
496  std::vector<double> me11_wiresLocal;
497  std::vector<double> me12_wiresLocal;
498  std::vector<double> me13_wiresLocal;
499  std::vector<double> me14_wiresLocal;
500  std::vector<double> me21_wiresLocal;
501  std::vector<double> me22_wiresLocal;
502  std::vector<double> me31_wiresLocal;
503  std::vector<double> me32_wiresLocal;
504  std::vector<double> me41_wiresLocal;
505  std::vector<double> me42_wiresLocal;
506 
507  auto const& layers = cscGeometry_->layers();
508 
509  for (auto it = layers.begin(), itEnd = layers.end(); it != itEnd; ++it) {
510  const CSCLayer* layer = *it;
511 
512  if (layer && layer->id().endcap() == endcap) {
513  DetId detId = layer->geographicalId();
514  GlobalPoint gp = layer->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
515 
516  const TGeoMatrix* matrix = fwGeometry_.getMatrix(detId.rawId());
517 
518  if (!matrix) {
519  std::cout << "Failed to get matrix of CSC layer with detid: " << detId.rawId() << std::endl;
520  continue;
521  }
522 
523  compareTransform(gp, matrix);
524 
525  const float* shape = fwGeometry_.getShapePars(detId.rawId());
526 
527  if (!shape) {
528  std::cout << "Failed to get shape of CSC layer with detid: " << detId.rawId() << std::endl;
529  continue;
530  }
531 
532  compareShape(layer, shape);
533 
534  double length;
535 
536  if (shape[0] == 1) {
537  length = shape[4];
538  }
539 
540  else {
541  std::cout << "Failed to get trapezoid from shape for CSC layer with detid: " << detId.rawId() << std::endl;
542  continue;
543  }
544 
545  const float* parameters = fwGeometry_.getParameters(detId.rawId());
546 
547  if (parameters == nullptr) {
548  std::cout << "Parameters empty for CSC layer with detid: " << detId.rawId() << std::endl;
549  continue;
550  }
551 
552  int yAxisOrientation = layer->geometry()->topology()->yAxisOrientation();
553  assert(yAxisOrientation == parameters[0]);
554 
555  float centreToIntersection = layer->geometry()->topology()->centreToIntersection();
556  assert(centreToIntersection == parameters[1]);
557 
558  float yCentre = layer->geometry()->topology()->yCentreOfStripPlane();
559  assert(yCentre == parameters[2]);
560 
561  float phiOfOneEdge = layer->geometry()->topology()->phiOfOneEdge();
562  assert(phiOfOneEdge == parameters[3]);
563 
564  float stripOffset = layer->geometry()->topology()->stripOffset();
565  assert(stripOffset == parameters[4]);
566 
567  float angularWidth = layer->geometry()->topology()->angularWidth();
568  assert(angularWidth == parameters[5]);
569 
570  for (int nStrip = 1; nStrip <= layer->geometry()->numberOfStrips(); ++nStrip) {
571  float xOfStrip1 = layer->geometry()->xOfStrip(nStrip);
572 
573  double stripAngle = phiOfOneEdge + yAxisOrientation * (nStrip - (0.5 - stripOffset)) * angularWidth;
574  double xOfStrip2 = yAxisOrientation * (centreToIntersection - yCentre) * tan(stripAngle);
575 
576  strip_positions.push_back(xOfStrip1 - xOfStrip2);
577  }
578 
579  int station = layer->id().station();
580  int ring = layer->id().ring();
581 
582  double wireSpacingInGroup = layer->geometry()->wireTopology()->wireSpacing();
583  assert(wireSpacingInGroup == parameters[6]);
584 
585  double wireSpacing = 0.0;
586  // we calculate an average wire group
587  // spacing from radialExtentOfTheWirePlane / numOfWireGroups
588 
589  double extentOfWirePlane = 0.0;
590 
591  if (ring == 2) {
592  if (station == 1)
593  extentOfWirePlane = 174.81; //wireSpacing = 174.81/64;
594  else
595  extentOfWirePlane = 323.38; //wireSpacing = 323.38/64;
596  } else if (station == 1 && (ring == 1 || ring == 4))
597  extentOfWirePlane = 150.5; //wireSpacing = 150.5/48;
598  else if (station == 1 && ring == 3)
599  extentOfWirePlane = 164.47; //wireSpacing = 164.47/32;
600  else if (station == 2 && ring == 1)
601  extentOfWirePlane = 189.97; //wireSpacing = 189.97/112;
602  else if (station == 3 && ring == 1)
603  extentOfWirePlane = 170.01; //wireSpacing = 170.01/96;
604  else if (station == 4 && ring == 1)
605  extentOfWirePlane = 149.73; //wireSpacing = 149.73/96;
606 
607  float wireAngle = layer->geometry()->wireTopology()->wireAngle();
608  assert(wireAngle == parameters[7]);
609 
610  //float cosWireAngle = cos(wireAngle);
611 
612  /* NOTE
613  Some parameters don't seem available in a public interface
614  so have to perhaps hard-code. This may not be too bad as there
615  seems to be a lot of degeneracy.
616  */
617 
618  double alignmentPinToFirstWire;
619  double yAlignmentFrame = 3.49;
620 
621  if (station == 1) {
622  if (ring == 1 || ring == 4) {
623  alignmentPinToFirstWire = 1.065;
624  yAlignmentFrame = 0.0;
625  }
626 
627  else // ME12, ME 13
628  alignmentPinToFirstWire = 2.85;
629  }
630 
631  else if (station == 4 && ring == 1)
632  alignmentPinToFirstWire = 3.04;
633 
634  else if (station == 3 && ring == 1)
635  alignmentPinToFirstWire = 2.84;
636 
637  else // ME21, ME22, ME32, ME42
638  alignmentPinToFirstWire = 2.87;
639 
640  double yOfFirstWire = (yAlignmentFrame - length) + alignmentPinToFirstWire;
641 
642  int nWireGroups = layer->geometry()->numberOfWireGroups();
643  double E = extentOfWirePlane / nWireGroups;
644 
645  for (int nWireGroup = 1; nWireGroup <= nWireGroups; ++nWireGroup) {
646  LocalPoint centerOfWireGroup = layer->geometry()->localCenterOfWireGroup(nWireGroup);
647  double yOfWire1 = centerOfWireGroup.y();
648 
649  //double yOfWire2 = (-0.5 - (nWireGroups*0.5 - 1) + (nWireGroup-1))*E;
650  //yOfWire2 += 0.5*E;
651  double yOfWire2 = yOfFirstWire + ((nWireGroup - 1) * E);
652  yOfWire2 += wireSpacing * 0.5;
653 
654  double ydiff_local = yOfWire1 - yOfWire2;
655  wire_positions.push_back(ydiff_local);
656 
657  //GlobalPoint globalPoint = layer->surface().toGlobal(LocalPoint(0.0,yOfWire1,0.0));
658 
659  /*
660  float fwLocalPoint[3] =
661  {
662  0.0, yOfWire2, 0.0
663  };
664 
665  float fwGlobalPoint[3];
666  fwGeometry_.localToGlobal(detId.rawId(), fwLocalPoint, fwGlobalPoint);
667  double ydiff_global = globalPoint.y() - fwGlobalPoint[1];
668  */
669 
670  if (station == 1) {
671  if (ring == 1) {
672  me11_wiresLocal.push_back(ydiff_local);
673  } else if (ring == 2) {
674  me12_wiresLocal.push_back(ydiff_local);
675  } else if (ring == 3) {
676  me13_wiresLocal.push_back(ydiff_local);
677  } else if (ring == 4) {
678  me14_wiresLocal.push_back(ydiff_local);
679  }
680  } else if (station == 2) {
681  if (ring == 1) {
682  me21_wiresLocal.push_back(ydiff_local);
683  } else if (ring == 2) {
684  me22_wiresLocal.push_back(ydiff_local);
685  }
686  } else if (station == 3) {
687  if (ring == 1) {
688  me31_wiresLocal.push_back(ydiff_local);
689  } else if (ring == 2) {
690  me32_wiresLocal.push_back(ydiff_local);
691  }
692  } else if (station == 4) {
693  if (ring == 1) {
694  me41_wiresLocal.push_back(ydiff_local);
695  } else if (ring == 2) {
696  me42_wiresLocal.push_back(ydiff_local);
697  }
698  }
699  }
700  }
701  }
702 
703  std::string hn(detname);
704  makeHistogram(hn + ": xOfStrip", strip_positions);
705 
706  makeHistogram(hn + ": local yOfWire", wire_positions);
707 
708  makeHistogram("ME11: local yOfWire", me11_wiresLocal);
709  makeHistogram("ME12: local yOfWire", me12_wiresLocal);
710  makeHistogram("ME13: local yOfWire", me13_wiresLocal);
711  makeHistogram("ME14: local yOfWire", me14_wiresLocal);
712  makeHistogram("ME21: local yOfWire", me21_wiresLocal);
713  makeHistogram("ME22: local yOfWire", me22_wiresLocal);
714  makeHistogram("ME31: local yOfWire", me31_wiresLocal);
715  makeHistogram("ME32: local yOfWire", me32_wiresLocal);
716  makeHistogram("ME41: local yOfWire", me41_wiresLocal);
717  makeHistogram("ME42: local yOfWire", me42_wiresLocal);
718 
719  makeHistograms(detname);
720 }
721 
722 void ValidateGeometry::validateCaloGeometry(DetId::Detector detector, int subdetector, const char* detname) {
723  clearData();
724 
725  const CaloSubdetectorGeometry* geometry = caloGeometry_->getSubdetectorGeometry(detector, subdetector);
726 
727  const std::vector<DetId>& ids = geometry->getValidDetIds(detector, subdetector);
728 
729  for (auto it = ids.begin(), iEnd = ids.end(); it != iEnd; ++it) {
730  unsigned int rawId = (*it).rawId();
731 
732  const float* points = fwGeometry_.getCorners(rawId);
733 
734  if (points == nullptr) {
735  std::cout << "Failed to get points of " << detname << " element with detid: " << rawId << std::endl;
736  continue;
737  }
738 
739  auto cellGeometry = geometry->getGeometry(*it);
740  const CaloCellGeometry::CornersVec& corners = cellGeometry->getCorners();
741 
742  assert(corners.size() == 8);
743 
744  for (unsigned int i = 0, offset = 0; i < 8; ++i) {
745  offset = 2 * i;
746 
747  double distance = getDistance(GlobalPoint(points[i + offset], points[i + 1 + offset], points[i + 2 + offset]),
748  GlobalPoint(corners[i].x(), corners[i].y(), corners[i].z()));
749 
750  globalDistances_.push_back(distance);
751  }
752  }
753 
754  makeHistograms(detname);
755 }
756 
758  clearData();
759 
760  for (TrackerGeometry::DetContainer::const_iterator it = dets.begin(), itEnd = dets.end(); it != itEnd; ++it) {
761  GlobalPoint gp =
762  (trackerGeometry_->idToDet((*it)->geographicalId()))->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
763  unsigned int rawId = (*it)->geographicalId().rawId();
764 
765  const TGeoMatrix* matrix = fwGeometry_.getMatrix(rawId);
766 
767  if (!matrix) {
768  std::cout << "Failed to get matrix of " << detname << " element with detid: " << rawId << std::endl;
769  continue;
770  }
771 
772  compareTransform(gp, matrix);
773 
774  const float* shape = fwGeometry_.getShapePars(rawId);
775 
776  if (!shape) {
777  std::cout << "Failed to get shape of " << detname << " element with detid: " << rawId << std::endl;
778  continue;
779  }
780 
781  compareShape(*it, shape);
782  }
783 
784  makeHistograms(detname);
785 }
786 
788  std::vector<double> pixelLocalXs;
789  std::vector<double> pixelLocalYs;
790 
791  for (TrackerGeometry::DetContainer::const_iterator it = dets.begin(), itEnd = dets.end(); it != itEnd; ++it) {
792  unsigned int rawId = (*it)->geographicalId().rawId();
793 
794  const float* parameters = fwGeometry_.getParameters(rawId);
795 
796  if (parameters == nullptr) {
797  std::cout << "Parameters empty for " << detname << " element with detid: " << rawId << std::endl;
798  continue;
799  }
800 
801  if (const PixelGeomDetUnit* det =
802  dynamic_cast<const PixelGeomDetUnit*>(trackerGeometry_->idToDetUnit((*it)->geographicalId()))) {
803  if (const PixelTopology* rpt = &det->specificTopology()) {
804  int nrows = rpt->nrows();
805  int ncolumns = rpt->ncolumns();
806 
807  for (int row = 1; row <= nrows; ++row) {
808  for (int column = 1; column <= ncolumns; ++column) {
809  LocalPoint localPoint = rpt->localPosition(MeasurementPoint(row, column));
810 
811  pixelLocalXs.push_back(localPoint.x() - fireworks::pixelLocalX(row, parameters));
812  pixelLocalYs.push_back(localPoint.y() - fireworks::pixelLocalY(column, parameters));
813  }
814  }
815  }
816 
817  else
818  std::cout << "No topology for " << detname << " " << rawId << std::endl;
819  }
820 
821  else
822  std::cout << "No geomDetUnit for " << detname << " " << rawId << std::endl;
823  }
824 
825  std::string hn(detname);
826  makeHistogram(hn + " pixelLocalX", pixelLocalXs);
827  makeHistogram(hn + " pixelLocalY", pixelLocalYs);
828 }
829 
831  std::vector<double> radialStripLocalXs;
832  std::vector<double> rectangularStripLocalXs;
833 
834  for (TrackerGeometry::DetContainer::const_iterator it = dets.begin(), itEnd = dets.end(); it != itEnd; ++it) {
835  unsigned int rawId = (*it)->geographicalId().rawId();
836 
837  const float* parameters = fwGeometry_.getParameters(rawId);
838 
839  if (parameters == nullptr) {
840  std::cout << "Parameters empty for " << detname << " element with detid: " << rawId << std::endl;
841  continue;
842  }
843 
844  if (const StripGeomDetUnit* det =
845  dynamic_cast<const StripGeomDetUnit*>(trackerGeometry_->idToDet((*it)->geographicalId()))) {
846  // NOTE: why the difference in dets vs. units between these and pixels? The dynamic cast above
847  // fails for many of the detids...
848 
849  const StripTopology* st = dynamic_cast<const StripTopology*>(&det->specificTopology());
850 
851  if (st) {
852  //assert(parameters[0] == 0);
853  int nstrips = st->nstrips();
854  assert(parameters[1] == nstrips);
855  assert(parameters[2] == st->stripLength());
856 
857  if (const RadialStripTopology* rst =
858  dynamic_cast<const RadialStripTopology*>(&(det->specificType().specificTopology()))) {
859  assert(parameters[0] == 1);
860  assert(parameters[3] == rst->yAxisOrientation());
861  assert(parameters[4] == rst->originToIntersection());
862  assert(parameters[5] == rst->phiOfOneEdge());
863  assert(parameters[6] == rst->angularWidth());
864 
865  for (uint16_t strip = 1; strip <= nstrips; ++strip) {
866  float stripAngle1 = rst->stripAngle(strip);
867  float stripAngle2 = parameters[3] * (parameters[5] + strip * parameters[6]);
868 
869  assert((stripAngle1 - stripAngle2) == 0);
870 
871  LocalPoint stripPosition = st->localPosition(strip);
872 
873  float stripX = parameters[4] * tan(stripAngle2);
874  radialStripLocalXs.push_back(stripPosition.x() - stripX);
875  }
876  }
877 
878  else if (dynamic_cast<const RectangularStripTopology*>(&(det->specificType().specificTopology()))) {
879  assert(parameters[0] == 2);
880  assert(parameters[3] == st->pitch());
881 
882  for (uint16_t strip = 1; strip <= nstrips; ++strip) {
883  LocalPoint stripPosition = st->localPosition(strip);
884  float stripX = -parameters[1] * 0.5 * parameters[3];
885  stripX += strip * parameters[3];
886  rectangularStripLocalXs.push_back(stripPosition.x() - stripX);
887  }
888  }
889 
890  else if (dynamic_cast<const TrapezoidalStripTopology*>(&(det->specificType().specificTopology()))) {
891  assert(parameters[0] == 3);
892  assert(parameters[3] == st->pitch());
893  }
894 
895  else
896  std::cout << "Failed to get pitch for " << detname << " " << rawId << std::endl;
897  }
898 
899  else
900  std::cout << "Failed cast to StripTopology for " << detname << " " << rawId << std::endl;
901  }
902 
903  //else
904  // std::cout<<"Failed cast to StripGeomDetUnit for "<< detname <<" "<< rawId <<std::endl;
905  }
906 
907  std::string hn(detname);
908  makeHistogram(hn + " radial strip localX", radialStripLocalXs);
909  makeHistogram(hn + " rectangular strip localX", rectangularStripLocalXs);
910 }
911 
912 void ValidateGeometry::compareTransform(const GlobalPoint& gp, const TGeoMatrix* matrix) {
913  double local[3] = {0.0, 0.0, 0.0};
914 
915  double global[3];
916 
917  matrix->LocalToMaster(local, global);
918 
919  double distance = getDistance(GlobalPoint(global[0], global[1], global[2]), gp);
920  globalDistances_.push_back(distance);
921 }
922 
923 void ValidateGeometry::compareShape(const GeomDet* det, const float* shape) {
924  double shape_topWidth;
925  double shape_bottomWidth;
926  double shape_length;
927  double shape_thickness;
928 
929  if (shape[0] == 1) {
930  shape_topWidth = shape[2];
931  shape_bottomWidth = shape[1];
932  shape_length = shape[4];
933  shape_thickness = shape[3];
934  }
935 
936  else if (shape[0] == 2) {
937  shape_topWidth = shape[1];
938  shape_bottomWidth = shape[1];
939  shape_length = shape[2];
940  shape_thickness = shape[3];
941  }
942 
943  else {
944  std::cout << "Failed to get box or trapezoid from shape" << std::endl;
945  return;
946  }
947 
948  double topWidth, bottomWidth;
949  double length, thickness;
950 
951  const Bounds* bounds = &(det->surface().bounds());
952 
953  if (const TrapezoidalPlaneBounds* tpbs = dynamic_cast<const TrapezoidalPlaneBounds*>(bounds)) {
954  std::array<const float, 4> const& ps = tpbs->parameters();
955 
956  assert(ps.size() == 4);
957 
958  bottomWidth = ps[0];
959  topWidth = ps[1];
960  thickness = ps[2];
961  length = ps[3];
962  }
963 
964  else if ((dynamic_cast<const RectangularPlaneBounds*>(bounds))) {
965  length = det->surface().bounds().length() * 0.5;
966  topWidth = det->surface().bounds().width() * 0.5;
967  bottomWidth = topWidth;
968  thickness = det->surface().bounds().thickness() * 0.5;
969  }
970 
971  else {
972  std::cout << "Failed to get bounds" << std::endl;
973  return;
974  }
975 
976  //assert((tgeotrap && trapezoid) || (tgeobbox && rectangle));
977 
978  /*
979  std::cout<<"topWidth: "<< shape_topWidth <<" "<< topWidth <<std::endl;
980  std::cout<<"bottomWidth: "<< shape_bottomWidth <<" "<< bottomWidth <<std::endl;
981  std::cout<<"length: "<< shape_length <<" "<< length <<std::endl;
982  std::cout<<"thickness: "<< shape_thickness <<" "<< thickness <<std::endl;
983  */
984 
985  topWidths_.push_back(fabs(shape_topWidth - topWidth));
986  bottomWidths_.push_back(fabs(shape_bottomWidth - bottomWidth));
987  lengths_.push_back(fabs(shape_length - length));
988  thicknesses_.push_back(fabs(shape_thickness - thickness));
989 
990  return;
991 }
992 
994  /*
995  std::cout<<"X: "<< p1.x() <<" "<< p2.x() <<std::endl;
996  std::cout<<"Y: "<< p1.y() <<" "<< p2.y() <<std::endl;
997  std::cout<<"Z: "<< p1.z() <<" "<< p2.z() <<std::endl;
998  */
999 
1000  return sqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) + (p1.y() - p2.y()) * (p1.y() - p2.y()) +
1001  (p1.z() - p2.z()) * (p1.z() - p2.z()));
1002 }
1003 
1004 void ValidateGeometry::makeHistograms(const char* detector) {
1005  outFile_->cd();
1006 
1007  std::string d(detector);
1008 
1009  std::string gdn = d + ": distance between points in global coordinates";
1011 
1012  std::string twn = d + ": absolute difference between top widths (along X)";
1013  makeHistogram(twn, topWidths_);
1014 
1015  std::string bwn = d + ": absolute difference between bottom widths (along X)";
1017 
1018  std::string ln = d + ": absolute difference between lengths (along Y)";
1019  makeHistogram(ln, lengths_);
1020 
1021  std::string tn = d + ": absolute difference between thicknesses (along Z)";
1023 
1024  return;
1025 }
1026 
1027 void ValidateGeometry::makeHistogram(const std::string& name, std::vector<double>& data) {
1028  if (data.empty())
1029  return;
1030 
1031  std::vector<double>::iterator it;
1032 
1033  it = std::min_element(data.begin(), data.end());
1034  double minE = *it;
1035 
1036  it = std::max_element(data.begin(), data.end());
1037  double maxE = *it;
1038 
1039  std::vector<double>::iterator itEnd = data.end();
1040 
1041  TH1D hist(name.c_str(), name.c_str(), 100, minE * (1 + 0.10), maxE * (1 + 0.10));
1042 
1043  for (it = data.begin(); it != itEnd; ++it)
1044  hist.Fill(*it);
1045 
1046  hist.GetXaxis()->SetTitle("[cm]");
1047  hist.Write();
1048 }
1049 
1051 
1053  std::cout << "Done. " << std::endl;
1054  std::cout << "Results written to " << outfileName_ << std::endl;
1055  outFile_->Close();
1056 }
1057 
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
float centreToIntersection() const override
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:59
edm::ESHandle< CaloGeometry > caloGeometry_
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:26
edm::ESHandle< TrackerGeometry > trackerGeometry_
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const CSCWireTopology * wireTopology() const
virtual float length() const =0
void beginJob() override
std::vector< double > topWidths_
void validateTrackerGeometry(const TrackerGeometry::DetContainer &dets, const char *detname)
const TString p2
Definition: fwPaths.cc:13
CSCDetId id() const
Get the (concrete) DetId.
Definition: CSCChamber.h:34
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:472
edm::ESGetToken< CSCGeometry, MuonGeometryRecord > cscGeometryToken_
TString subdetector
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DTLayerId id() const
Return the DetId of this SL.
Definition: DTLayer.cc:39
CSCDetId id() const
Definition: CSCLayer.h:39
edm::ESHandle< RPCGeometry > rpcGeometry_
float phiOfOneEdge() const override
int nstrips() const
Definition: RPCRoll.cc:24
std::vector< double > bottomWidths_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void makeHistograms(const char *detector)
T y() const
Definition: PV3DBase.h:60
const Bounds & bounds() const
Definition: Surface.h:87
int numberOfStrips() const
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeometryToken_
double wireSpacing() const
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:225
const StripTopology & specificTopology() const
Definition: RPCRoll.cc:49
assert(be >=bs)
tuple nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
int numberOfWireGroups() const
void makeHistogram(const std::string &name, std::vector< double > &data)
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
constexpr std::array< uint8_t, layerIndexSize > layer
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:79
float xOfStrip(int strip, float y=0.) const
float yAxisOrientation() const override
void validateDTChamberGeometry()
int endcap() const
Definition: CSCDetId.h:85
virtual float thickness() const =0
tuple d
Definition: ztail.py:151
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:483
std::vector< const GeomDet * > DetContainer
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:81
const DTTopology & specificTopology() const
Definition: DTLayer.cc:37
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeometryToken_
float wireAngle() const override
virtual float stripLength() const =0
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
RPCDetId id() const
Definition: RPCRoll.cc:16
void compareShape(const GeomDet *det, const float *shape)
void loadMap(const char *fileName)
Definition: FWGeometry.cc:103
T sqrt(T t)
Definition: SSEVec.h:19
void validateCaloGeometry(DetId::Detector detector, int subdetector, const char *detname)
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:32
T z() const
Definition: PV3DBase.h:61
const TString p1
Definition: fwPaths.cc:12
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
edm::ESHandle< DTGeometry > dtGeometry_
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
float angularWidth() const override
void validateRPCGeometry(const int regionNumber, const char *regionName)
void validatePixelTopology(const TrackerGeometry::DetContainer &dets, const char *detname)
void validateCSCLayerGeometry(const int endcap, const char *detname)
static const int SubdetectorId
float pixelLocalX(const double mpx, const float *)
Definition: TrackUtils.cc:159
edm::ESHandle< CSCGeometry > cscGeometry_
__shared__ Hist hist
void endJob() override
float pixelLocalY(const double mpy, const float *)
Definition: TrackUtils.cc:209
LocalPoint localCenterOfWireGroup(int wireGroup) const
int ring() const
Definition: CSCDetId.h:68
Definition: DetId.h:17
const CSCStripTopology * topology() const
size_type size() const
Definition: EZArrayFL.h:67
virtual float stripOffset(void) const
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
float yCentreOfStripPlane() const override
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:461
double getDistance(const GlobalPoint &point1, const GlobalPoint &point2)
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
#define fwLog(_level_)
Definition: fwLog.h:45
Detector
Definition: DetId.h:24
ValidateGeometry(const edm::ParameterSet &)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::vector< double > thicknesses_
virtual float pitch() const =0
void analyze(const edm::Event &, const edm::EventSetup &) override
virtual LocalPoint localPosition(float strip) const =0
int station() const
Definition: CSCDetId.h:79
tuple cout
Definition: gather_cfg.py:144
std::string infileName_
Definition: Bounds.h:18
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
void validateCSChamberGeometry(const int endcap, const char *detname)
void validateStripTopology(const TrackerGeometry::DetContainer &dets, const char *detname)
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
bool isValid() const
Definition: ESHandle.h:44
std::vector< double > lengths_
T x() const
Definition: PV3DBase.h:59
virtual float width() const =0
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:44
std::string outfileName_
void compareTransform(const GlobalPoint &point, const TGeoMatrix *matrix)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
std::vector< double > globalDistances_
~ValidateGeometry() override
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53