CMS 3D CMS Logo

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 {
64 public:
65  explicit ValidateGeometry(const edm::ParameterSet&);
66  ~ValidateGeometry() override;
67 
68 private:
69  void beginJob() override;
70  void analyze(const edm::Event&, const edm::EventSetup&) override;
71  void endJob() override;
72 
73  void validateRPCGeometry(const int regionNumber,
74  const char* regionName);
75 
78 
79  void validateCSChamberGeometry(const int endcap,
80  const char* detname);
81 
82  void validateCSCLayerGeometry(const int endcap,
83  const char* detname);
84 
86  const char* detname);
87 
89  const char* detname);
90 
92  const char* detname);
93 
95  const char* detname);
96 
97  void compareTransform(const GlobalPoint& point, const TGeoMatrix* matrix);
98 
99  void compareShape(const GeomDet* det, const float* shape);
100 
101  double getDistance(const GlobalPoint& point1, const GlobalPoint& point2);
102 
103  void makeHistograms(const char* detector);
104  void makeHistogram(const std::string& name, std::vector<double>& data);
105 
108 
114 
116 
117  TFile* outFile_;
118 
119  std::vector<double> globalDistances_;
120  std::vector<double> topWidths_;
121  std::vector<double> bottomWidths_;
122  std::vector<double> lengths_;
123  std::vector<double> thicknesses_;
124 
125  void clearData()
126  {
127  globalDistances_.clear();
128  topWidths_.clear();
129  bottomWidths_.clear();
130  lengths_.clear();
131  thicknesses_.clear();
132  }
133 
134  bool dataEmpty()
135  {
136  return (globalDistances_.empty() &&
137  topWidths_.empty() &&
138  bottomWidths_.empty() &&
139  lengths_.empty() &&
140  thicknesses_.empty());
141  }
142 
144  bool doMuon_;
145  bool doCalo_;
146 };
147 
148 
150  : infileName_(iConfig.getUntrackedParameter<std::string>("infileName")),
151  outfileName_(iConfig.getUntrackedParameter<std::string>("outfileName"))
152 {
153  doTracker_ = iConfig.getUntrackedParameter<bool>( "Tracker", true );
154  doMuon_ = iConfig.getUntrackedParameter<bool>( "Muon", true );
155  doCalo_ = iConfig.getUntrackedParameter<bool>( "Calo", true );
156 
158 
159  outFile_ = new TFile(outfileName_.c_str(), "RECREATE");
160 }
161 
162 
164 {}
165 
166 
167 void
169 {
170  if( doMuon_ )
171  {
172  eventSetup.get<MuonGeometryRecord>().get(rpcGeometry_);
173 
174  if ( rpcGeometry_.isValid() )
175  {
176  std::cout<<"Validating RPC -z endcap geometry"<<std::endl;
177  validateRPCGeometry(-1, "RPC -z endcap");
178 
179  std::cout<<"Validating RPC +z endcap geometry"<<std::endl;
180  validateRPCGeometry(+1, "RPC +z endcap");
181 
182  std::cout<<"Validating RPC barrel geometry"<<std::endl;
183  validateRPCGeometry(0, "RPC barrel");
184  }
185  else
186  fwLog(fwlog::kWarning)<<"Invalid RPC geometry"<<std::endl;
187 
188 
189  eventSetup.get<MuonGeometryRecord>().get(dtGeometry_);
190 
191  if ( dtGeometry_.isValid() )
192  {
193  std::cout<<"Validating DT chamber geometry"<<std::endl;
195 
196  std::cout<<"Validating DT layer geometry"<<std::endl;
198  }
199  else
200  fwLog(fwlog::kWarning)<<"Invalid DT geometry"<<std::endl;
201 
202 
203  eventSetup.get<MuonGeometryRecord>().get(cscGeometry_);
204 
205  if ( cscGeometry_.isValid() )
206  {
207  std::cout<<"Validating CSC -z geometry"<<std::endl;
208  validateCSChamberGeometry(-1, "CSC chamber -z endcap");
209 
210  std::cout<<"Validating CSC +z geometry"<<std::endl;
211  validateCSChamberGeometry(+1, "CSC chamber +z endcap");
212 
213  std::cout<<"Validating CSC layer -z geometry"<<std::endl;
214  validateCSCLayerGeometry(-1, "CSC layer -z endcap");
215 
216  std::cout<<"Validating CSC layer +z geometry"<<std::endl;
217  validateCSCLayerGeometry(+1, "CSC layer +z endcap");
218  }
219  else
220  fwLog(fwlog::kWarning)<<"Invalid CSC geometry"<<std::endl;
221  }
222 
223  if( doTracker_ )
224  {
226 
227  if ( trackerGeometry_.isValid() )
228  {
229  std::cout<<"Validating TIB geometry and topology"<<std::endl;
232 
233  std::cout<<"Validating TOB geometry and topology"<<std::endl;
236 
237  std::cout<<"Validating TEC geometry and topology"<<std::endl;
240 
241  std::cout<<"Validating TID geometry and topology"<<std::endl;
244 
245  std::cout<<"Validating PXB geometry and topology"<<std::endl;
248 
249  std::cout<<"Validating PXF geometry and topology"<<std::endl;
252  }
253  else
254  fwLog(fwlog::kWarning)<<"Invalid Tracker geometry"<<std::endl;
255  }
256 
257  if( doCalo_ )
258  {
259  eventSetup.get<CaloGeometryRecord>().get(caloGeometry_);
260 
261 
262  if ( caloGeometry_.isValid() )
263  {
264  std::cout<<"Validating EB geometry"<<std::endl;
266 
267  std::cout<<"Validating EE geometry"<<std::endl;
269 
270  std::cout<<"Validating ES geometry"<<std::endl;
272 
273  std::cout<<"Validating HB geometry"<<std::endl;
275 
276  std::cout<<"Validating HE geometry"<<std::endl;
278 
279  std::cout<<"Validating HO geometry"<<std::endl;
281 
282  std::cout<<"Validating HF geometry"<<std::endl;
284 
285  std::cout<<"Validating Castor geometry"<<std::endl;
287 
288  std::cout<<"Validating ZDC geometry"<<std::endl;
290  }
291  else
292  fwLog(fwlog::kWarning)<<"Invalid Calo geometry"<<std::endl;
293  }
294 }
295 
296 
297 void
298 ValidateGeometry::validateRPCGeometry(const int regionNumber, const char* regionName)
299 {
300  clearData();
301 
302  std::vector<double> centers;
303 
304  auto const& rolls = rpcGeometry_->rolls();
305 
306  for ( auto it = rolls.begin(),
307  itEnd = rolls.end();
308  it != itEnd; ++it )
309  {
310  const RPCRoll* roll = *it;
311 
312  if ( roll )
313  {
314  RPCDetId rpcDetId = roll->id();
315 
316  if ( rpcDetId.region() == regionNumber )
317  {
318  const GeomDetUnit* det = rpcGeometry_->idToDetUnit(rpcDetId);
319  GlobalPoint gp = det->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
320 
321  const TGeoMatrix* matrix = fwGeometry_.getMatrix(rpcDetId.rawId());
322 
323  if ( ! matrix )
324  {
325  std::cout<<"Failed to get matrix of RPC with detid: "
326  << rpcDetId.rawId() <<std::endl;
327  continue;
328  }
329 
330  compareTransform(gp, matrix);
331 
332  const float* shape = fwGeometry_.getShapePars(rpcDetId.rawId());
333 
334  if ( ! shape )
335  {
336  std::cout<<"Failed to get shape of RPC with detid: "
337  << rpcDetId.rawId() <<std::endl;
338  continue;
339  }
340 
341  compareShape(det, shape);
342 
343  const float* parameters = fwGeometry_.getParameters(rpcDetId.rawId());
344 
345  if ( parameters == nullptr )
346  {
347  std::cout<<"Parameters empty for RPC with detid: "
348  << rpcDetId.rawId() <<std::endl;
349  continue;
350  }
351 
352  // Yes, I know that below I'm comparing the equivalence
353  // of floating point numbers
354 
355  int nStrips = roll->nstrips();
356  assert(nStrips == parameters[0]);
357 
358  float stripLength = roll->specificTopology().stripLength();
359  assert(stripLength == parameters[1]);
360 
361  float pitch = roll->specificTopology().pitch();
362  assert(pitch == parameters[2]);
363 
364  float offset = -0.5*nStrips*pitch;
365 
366  for ( int strip = 1; strip <= roll->nstrips(); ++strip )
367  {
368  LocalPoint centreOfStrip1 = roll->centreOfStrip(strip);
369  LocalPoint centreOfStrip2 = LocalPoint((strip-0.5)*pitch + offset, 0.0);
370 
371  centers.push_back(centreOfStrip1.x()-centreOfStrip2.x());
372  }
373  }
374  }
375  }
376 
377  std::string hn(regionName);
378  makeHistogram(hn+": centreOfStrip", centers);
379 
380 
381  makeHistograms(regionName);
382 }
383 
384 
385 void
387 {
388  clearData();
389 
390  auto const& chambers = dtGeometry_->chambers();
391 
392  for ( auto it = chambers.begin(),
393  itEnd = chambers.end();
394  it != itEnd; ++it)
395  {
396  const DTChamber* chamber = *it;
397 
398  if ( chamber )
399  {
400  DTChamberId chId = chamber->id();
401  GlobalPoint gp = chamber->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
402 
403  const TGeoMatrix* matrix = fwGeometry_.getMatrix(chId.rawId());
404 
405  if ( ! matrix )
406  {
407  std::cout<<"Failed to get matrix of DT chamber with detid: "
408  << chId.rawId() <<std::endl;
409  continue;
410  }
411 
412  compareTransform(gp, matrix);
413 
414  const float* shape = fwGeometry_.getShapePars(chId.rawId());
415 
416  if ( ! shape )
417  {
418  std::cout<<"Failed to get shape of DT chamber with detid: "
419  << chId.rawId() <<std::endl;
420  continue;
421  }
422 
423  compareShape(chamber, shape);
424  }
425  }
426 
427  makeHistograms("DT chamber");
428 }
429 
430 
431 void
433 {
434  clearData();
435 
436  std::vector<double> wire_positions;
437 
438  auto const& layers = dtGeometry_->layers();
439 
440  for ( auto it = layers.begin(),
441  itEnd = layers.end();
442  it != itEnd; ++it)
443  {
444  const DTLayer* layer = *it;
445 
446  if ( layer )
447  {
448  DTLayerId layerId = layer->id();
449  GlobalPoint gp = layer->surface().toGlobal(LocalPoint(0.0, 0.0, 0.0));
450 
451  const TGeoMatrix* matrix = fwGeometry_.getMatrix(layerId.rawId());
452 
453  if ( ! matrix )
454  {
455  std::cout<<"Failed to get matrix of DT layer with detid: "
456  << layerId.rawId() <<std::endl;
457  continue;
458  }
459 
460  compareTransform(gp, matrix);
461 
462  const float* shape = fwGeometry_.getShapePars(layerId.rawId());
463 
464  if ( ! shape )
465  {
466  std::cout<<"Failed to get shape of DT layer with detid: "
467  << layerId.rawId() <<std::endl;
468  continue;
469  }
470 
471  compareShape(layer, shape);
472 
473 
474  const float* parameters = fwGeometry_.getParameters(layerId.rawId());
475 
476  if ( parameters == nullptr )
477  {
478  std::cout<<"Parameters empty for DT layer with detid: "
479  << layerId.rawId() <<std::endl;
480  continue;
481  }
482 
483  float width = layer->surface().bounds().width();
484  assert(width == parameters[6]);
485 
486  float thickness = layer->surface().bounds().thickness();
487  assert(thickness == parameters[7]);
488 
489  float length = layer->surface().bounds().length();
490  assert(length == parameters[8]);
491 
492  int firstChannel = layer->specificTopology().firstChannel();
493  assert(firstChannel == parameters[3]);
494 
495  int lastChannel = layer->specificTopology().lastChannel();
496  int nChannels = parameters[5];
497  assert(nChannels == (lastChannel-firstChannel)+1);
498 
499  for ( int wireN = firstChannel; wireN - lastChannel <= 0; ++wireN )
500  {
501  double localX1 = layer->specificTopology().wirePosition(wireN);
502  double localX2 = (wireN -(firstChannel-1)-0.5)*parameters[0] - nChannels/2.0*parameters[0];
503 
504  wire_positions.push_back(localX1-localX2);
505 
506  //std::cout<<"wireN, localXpos: "<< wireN <<" "<< localX1 <<" "<< localX2 <<std::endl;
507 
508  }
509  }
510  }
511 
512  makeHistogram("DT layer wire localX", wire_positions);
513 
514  makeHistograms("DT layer");
515 }
516 
517 
518 void
520 {
521  clearData();
522 
523  auto const& chambers = cscGeometry_->chambers();
524 
525  for ( auto it = chambers.begin(),
526  itEnd = chambers.end();
527  it != itEnd; ++it )
528  {
529  const CSCChamber* chamber = *it;
530 
531  if ( chamber && chamber->id().endcap() == endcap )
532  {
533  DetId detId = chamber->geographicalId();
534  GlobalPoint gp = chamber->surface().toGlobal(LocalPoint(0.0,0.0,0.0));
535 
536  const TGeoMatrix* matrix = fwGeometry_.getMatrix(detId.rawId());
537 
538  if ( ! matrix )
539  {
540  std::cout<<"Failed to get matrix of CSC chamber with detid: "
541  << detId.rawId() <<std::endl;
542  continue;
543  }
544 
545  compareTransform(gp, matrix);
546 
547  const float* shape = fwGeometry_.getShapePars(detId.rawId());
548 
549  if ( ! shape )
550  {
551  std::cout<<"Failed to get shape of CSC chamber with detid: "
552  << detId.rawId() <<std::endl;
553  continue;
554  }
555 
556  compareShape(chamber, shape);
557  }
558  }
559 
560  makeHistograms(detname);
561 }
562 
563 void
564 ValidateGeometry::validateCSCLayerGeometry(const int endcap, const char* detname)
565 {
566  clearData();
567  std::vector<double> strip_positions;
568  std::vector<double> wire_positions;
569 
570  std::vector<double> me11_wiresLocal;
571  std::vector<double> me12_wiresLocal;
572  std::vector<double> me13_wiresLocal;
573  std::vector<double> me14_wiresLocal;
574  std::vector<double> me21_wiresLocal;
575  std::vector<double> me22_wiresLocal;
576  std::vector<double> me31_wiresLocal;
577  std::vector<double> me32_wiresLocal;
578  std::vector<double> me41_wiresLocal;
579  std::vector<double> me42_wiresLocal;
580 
581  auto const& layers = cscGeometry_->layers();
582 
583  for ( auto it = layers.begin(),
584  itEnd = layers.end();
585  it != itEnd; ++it )
586  {
587  const CSCLayer* layer = *it;
588 
589  if ( layer && layer->id().endcap() == endcap )
590  {
591  DetId detId = layer->geographicalId();
592  GlobalPoint gp = layer->surface().toGlobal(LocalPoint(0.0,0.0,0.0));
593 
594  const TGeoMatrix* matrix = fwGeometry_.getMatrix(detId.rawId());
595 
596  if ( ! matrix )
597  {
598  std::cout<<"Failed to get matrix of CSC layer with detid: "
599  << detId.rawId() <<std::endl;
600  continue;
601  }
602 
603  compareTransform(gp, matrix);
604 
605  const float* shape = fwGeometry_.getShapePars(detId.rawId());
606 
607  if ( ! shape )
608  {
609  std::cout<<"Failed to get shape of CSC layer with detid: "
610  << detId.rawId() <<std::endl;
611  continue;
612  }
613 
614  compareShape(layer, shape);
615 
616  double length;
617 
618  if ( shape[0] == 1 )
619  {
620  length = shape[4];
621  }
622 
623  else
624  {
625  std::cout<<"Failed to get trapezoid from shape for CSC layer with detid: "
626  << detId.rawId() <<std::endl;
627  continue;
628  }
629 
630  const float* parameters = fwGeometry_.getParameters(detId.rawId());
631 
632  if ( parameters == nullptr )
633  {
634  std::cout<<"Parameters empty for CSC layer with detid: "
635  << detId.rawId() <<std::endl;
636  continue;
637  }
638 
639  int yAxisOrientation = layer->geometry()->topology()->yAxisOrientation();
640  assert(yAxisOrientation == parameters[0]);
641 
642  float centreToIntersection = layer->geometry()->topology()->centreToIntersection();
643  assert(centreToIntersection == parameters[1]);
644 
645  float yCentre = layer->geometry()->topology()->yCentreOfStripPlane();
646  assert(yCentre == parameters[2]);
647 
648  float phiOfOneEdge = layer->geometry()->topology()->phiOfOneEdge();
649  assert(phiOfOneEdge == parameters[3]);
650 
651  float stripOffset = layer->geometry()->topology()->stripOffset();
652  assert(stripOffset == parameters[4]);
653 
654  float angularWidth = layer->geometry()->topology()->angularWidth();
655  assert(angularWidth == parameters[5]);
656 
657  for ( int nStrip = 1; nStrip <= layer->geometry()->numberOfStrips();
658  ++nStrip )
659  {
660  float xOfStrip1 = layer->geometry()->xOfStrip(nStrip);
661 
662  double stripAngle = phiOfOneEdge + yAxisOrientation*(nStrip-(0.5-stripOffset))*angularWidth;
663  double xOfStrip2 = yAxisOrientation*(centreToIntersection-yCentre)*tan(stripAngle);
664 
665  strip_positions.push_back(xOfStrip1-xOfStrip2);
666  }
667 
668  int station = layer->id().station();
669  int ring = layer->id().ring();
670 
671  double wireSpacingInGroup = layer->geometry()->wireTopology()->wireSpacing();
672  assert(wireSpacingInGroup == parameters[6]);
673 
674  double wireSpacing = 0.0;
675  // we calculate an average wire group
676  // spacing from radialExtentOfTheWirePlane / numOfWireGroups
677 
678  double extentOfWirePlane = 0.0;
679 
680  if ( ring == 2 )
681  {
682  if ( station == 1 )
683  extentOfWirePlane = 174.81; //wireSpacing = 174.81/64;
684  else
685  extentOfWirePlane = 323.38; //wireSpacing = 323.38/64;
686  }
687  else if ( station == 1 && (ring == 1 || ring == 4))
688  extentOfWirePlane = 150.5; //wireSpacing = 150.5/48;
689  else if ( station == 1 && ring == 3 )
690  extentOfWirePlane = 164.47; //wireSpacing = 164.47/32;
691  else if ( station == 2 && ring == 1 )
692  extentOfWirePlane = 189.97; //wireSpacing = 189.97/112;
693  else if ( station == 3 && ring == 1 )
694  extentOfWirePlane = 170.01; //wireSpacing = 170.01/96;
695  else if ( station == 4 && ring == 1 )
696  extentOfWirePlane = 149.73; //wireSpacing = 149.73/96;
697 
698  float wireAngle = layer->geometry()->wireTopology()->wireAngle();
699  assert(wireAngle == parameters[7]);
700 
701  //float cosWireAngle = cos(wireAngle);
702 
703  /* NOTE
704  Some parameters don't seem available in a public interface
705  so have to perhaps hard-code. This may not be too bad as there
706  seems to be a lot of degeneracy.
707  */
708 
709  double alignmentPinToFirstWire;
710  double yAlignmentFrame = 3.49;
711 
712  if ( station == 1 )
713  {
714  if ( ring == 1 || ring == 4 )
715  {
716  alignmentPinToFirstWire = 1.065;
717  yAlignmentFrame = 0.0;
718  }
719 
720  else // ME12, ME 13
721  alignmentPinToFirstWire = 2.85;
722  }
723 
724  else if ( station == 4 && ring == 1 )
725  alignmentPinToFirstWire = 3.04;
726 
727  else if ( station == 3 && ring == 1 )
728  alignmentPinToFirstWire = 2.84;
729 
730  else // ME21, ME22, ME32, ME42
731  alignmentPinToFirstWire = 2.87;
732 
733  double yOfFirstWire = (yAlignmentFrame-length) + alignmentPinToFirstWire;
734 
735  int nWireGroups = layer->geometry()->numberOfWireGroups();
736  double E = extentOfWirePlane/nWireGroups;
737 
738  for ( int nWireGroup = 1; nWireGroup <= nWireGroups; ++nWireGroup )
739  {
740  LocalPoint centerOfWireGroup = layer->geometry()->localCenterOfWireGroup(nWireGroup);
741  double yOfWire1 = centerOfWireGroup.y();
742 
743  //double yOfWire2 = (-0.5 - (nWireGroups*0.5 - 1) + (nWireGroup-1))*E;
744  //yOfWire2 += 0.5*E;
745  double yOfWire2 = yOfFirstWire + ((nWireGroup-1)*E);
746  yOfWire2 += wireSpacing*0.5;
747 
748  double ydiff_local = yOfWire1 - yOfWire2;
749  wire_positions.push_back(ydiff_local);
750 
751  //GlobalPoint globalPoint = layer->surface().toGlobal(LocalPoint(0.0,yOfWire1,0.0));
752 
753  /*
754  float fwLocalPoint[3] =
755  {
756  0.0, yOfWire2, 0.0
757  };
758 
759  float fwGlobalPoint[3];
760  fwGeometry_.localToGlobal(detId.rawId(), fwLocalPoint, fwGlobalPoint);
761  double ydiff_global = globalPoint.y() - fwGlobalPoint[1];
762  */
763 
764  if ( station == 1 )
765  {
766  if ( ring == 1 )
767  {
768  me11_wiresLocal.push_back(ydiff_local);
769  }
770  else if ( ring == 2 )
771  {
772  me12_wiresLocal.push_back(ydiff_local);
773  }
774  else if ( ring == 3 )
775  {
776  me13_wiresLocal.push_back(ydiff_local);
777  }
778  else if ( ring == 4 )
779  {
780  me14_wiresLocal.push_back(ydiff_local);
781  }
782  }
783  else if ( station == 2 )
784  {
785  if ( ring == 1 )
786  {
787  me21_wiresLocal.push_back(ydiff_local);
788  }
789  else if ( ring == 2 )
790  {
791  me22_wiresLocal.push_back(ydiff_local);
792  }
793  }
794  else if ( station == 3 )
795  {
796  if ( ring == 1 )
797  {
798  me31_wiresLocal.push_back(ydiff_local);
799  }
800  else if ( ring == 2 )
801  {
802  me32_wiresLocal.push_back(ydiff_local);
803  }
804  }
805  else if ( station == 4 )
806  {
807  if ( ring == 1 )
808  {
809  me41_wiresLocal.push_back(ydiff_local);
810  }
811  else if ( ring == 2 )
812  {
813  me42_wiresLocal.push_back(ydiff_local);
814  }
815  }
816  }
817  }
818  }
819 
820  std::string hn(detname);
821  makeHistogram(hn+": xOfStrip", strip_positions);
822 
823  makeHistogram(hn+": local yOfWire", wire_positions);
824 
825  makeHistogram("ME11: local yOfWire", me11_wiresLocal);
826  makeHistogram("ME12: local yOfWire", me12_wiresLocal);
827  makeHistogram("ME13: local yOfWire", me13_wiresLocal);
828  makeHistogram("ME14: local yOfWire", me14_wiresLocal);
829  makeHistogram("ME21: local yOfWire", me21_wiresLocal);
830  makeHistogram("ME22: local yOfWire", me22_wiresLocal);
831  makeHistogram("ME31: local yOfWire", me31_wiresLocal);
832  makeHistogram("ME32: local yOfWire", me32_wiresLocal);
833  makeHistogram("ME41: local yOfWire", me41_wiresLocal);
834  makeHistogram("ME42: local yOfWire", me42_wiresLocal);
835 
836  makeHistograms(detname);
837 }
838 
839 void
841  int subdetector,
842  const char* detname)
843 {
844  clearData();
845 
847  caloGeometry_->getSubdetectorGeometry(detector, subdetector);
848 
849  const std::vector<DetId>& ids = geometry->getValidDetIds(detector, subdetector);
850 
851  for (auto it = ids.begin(),
852  iEnd = ids.end();
853  it != iEnd; ++it)
854  {
855  unsigned int rawId = (*it).rawId();
856 
857  const float* points = fwGeometry_.getCorners(rawId);
858 
859  if ( points == nullptr )
860  {
861  std::cout <<"Failed to get points of "<< detname
862  <<" element with detid: "<< rawId <<std::endl;
863  continue;
864  }
865 
866  auto cellGeometry = geometry->getGeometry(*it);
867  const CaloCellGeometry::CornersVec& corners = cellGeometry->getCorners();
868 
869  assert(corners.size() == 8);
870 
871  for ( unsigned int i = 0, offset = 0; i < 8; ++i )
872  {
873  offset = 2*i;
874 
875  double distance = getDistance(GlobalPoint(points[i+offset], points[i+1+offset], points[i+2+offset]),
876  GlobalPoint(corners[i].x(), corners[i].y(), corners[i].z()));
877 
878  globalDistances_.push_back(distance);
879  }
880  }
881 
882  makeHistograms(detname);
883 }
884 
885 
886 void
888  const char* detname)
889 {
890  clearData();
891 
892  for ( TrackerGeometry::DetContainer::const_iterator it = dets.begin(),
893  itEnd = dets.end();
894  it != itEnd; ++it )
895  {
896  GlobalPoint gp = (trackerGeometry_->idToDet((*it)->geographicalId()))->surface().toGlobal(LocalPoint(0.0,0.0,0.0));
897  unsigned int rawId = (*it)->geographicalId().rawId();
898 
899  const TGeoMatrix* matrix = fwGeometry_.getMatrix(rawId);
900 
901  if ( ! matrix )
902  {
903  std::cout <<"Failed to get matrix of "<< detname
904  <<" element with detid: "<< rawId <<std::endl;
905  continue;
906  }
907 
908  compareTransform(gp, matrix);
909 
910  const float* shape = fwGeometry_.getShapePars(rawId);
911 
912  if ( ! shape )
913  {
914  std::cout<<"Failed to get shape of "<< detname
915  <<" element with detid: "<< rawId <<std::endl;
916  continue;
917  }
918 
919  compareShape(*it, shape);
920  }
921 
922  makeHistograms(detname);
923 }
924 
925 
926 void
928  const char* detname)
929 {
930  std::vector<double> pixelLocalXs;
931  std::vector<double> pixelLocalYs;
932 
933  for ( TrackerGeometry::DetContainer::const_iterator it = dets.begin(),
934  itEnd = dets.end();
935  it != itEnd; ++it )
936  {
937  unsigned int rawId = (*it)->geographicalId().rawId();
938 
939  const float* parameters = fwGeometry_.getParameters(rawId);
940 
941  if ( parameters == nullptr )
942  {
943  std::cout<<"Parameters empty for "<< detname <<" element with detid: "
944  << rawId <<std::endl;
945  continue;
946  }
947 
948  if ( const PixelGeomDetUnit* det =
949  dynamic_cast<const PixelGeomDetUnit*>(trackerGeometry_->idToDetUnit((*it)->geographicalId())) )
950  {
951  if ( const PixelTopology* rpt = &det->specificTopology() )
952  {
953  int nrows = rpt->nrows();
954  int ncolumns = rpt->ncolumns();
955 
956  for ( int row = 1; row <= nrows; ++row )
957  {
958  for ( int column = 1; column <= ncolumns; ++column )
959  {
960  LocalPoint localPoint = rpt->localPosition(MeasurementPoint(row, column));
961 
962  pixelLocalXs.push_back(localPoint.x() - fireworks::pixelLocalX(row, parameters));
963  pixelLocalYs.push_back(localPoint.y() - fireworks::pixelLocalY(column, parameters));
964  }
965  }
966  }
967 
968  else
969  std::cout<<"No topology for "<< detname <<" "<< rawId <<std::endl;
970  }
971 
972  else
973  std::cout<<"No geomDetUnit for "<< detname <<" "<< rawId <<std::endl;
974  }
975 
976  std::string hn(detname);
977  makeHistogram(hn+" pixelLocalX", pixelLocalXs);
978  makeHistogram(hn+" pixelLocalY", pixelLocalYs);
979 }
980 
981 void
983  const char* detname)
984 {
985  std::vector<double> radialStripLocalXs;
986  std::vector<double> rectangularStripLocalXs;
987 
988  for ( TrackerGeometry::DetContainer::const_iterator it = dets.begin(),
989  itEnd = dets.end();
990  it != itEnd; ++it )
991  {
992  unsigned int rawId = (*it)->geographicalId().rawId();
993 
994  const float* parameters = fwGeometry_.getParameters(rawId);
995 
996  if ( parameters == nullptr )
997  {
998  std::cout<<"Parameters empty for "<< detname <<" element with detid: "
999  << rawId <<std::endl;
1000  continue;
1001  }
1002 
1003  if ( const StripGeomDetUnit* det =
1004  dynamic_cast<const StripGeomDetUnit*>(trackerGeometry_->idToDet((*it)->geographicalId())) )
1005  {
1006  // NOTE: why the difference in dets vs. units between these and pixels? The dynamic cast above
1007  // fails for many of the detids...
1008 
1009  const StripTopology* st = dynamic_cast<const StripTopology*>(&det->specificTopology());
1010 
1011  if ( st )
1012  {
1013  //assert(parameters[0] == 0);
1014  int nstrips = st->nstrips();
1015  assert(parameters[1] == nstrips);
1016  assert(parameters[2] == st->stripLength());
1017 
1018  if( const RadialStripTopology* rst = dynamic_cast<const RadialStripTopology*>(&(det->specificType().specificTopology())) )
1019  {
1020  assert(parameters[0] == 1);
1021  assert(parameters[3] == rst->yAxisOrientation());
1022  assert(parameters[4] == rst->originToIntersection());
1023  assert(parameters[5] == rst->phiOfOneEdge());
1024  assert(parameters[6] == rst->angularWidth());
1025 
1026  for ( uint16_t strip = 1; strip <= nstrips; ++strip )
1027  {
1028  float stripAngle1 = rst->stripAngle(strip);
1029  float stripAngle2 = parameters[3] * (parameters[5] + strip*parameters[6]);
1030 
1031  assert((stripAngle1-stripAngle2) == 0);
1032 
1033  LocalPoint stripPosition = st->localPosition(strip);
1034 
1035  float stripX = parameters[4]*tan(stripAngle2);
1036  radialStripLocalXs.push_back(stripPosition.x()-stripX);
1037  }
1038  }
1039 
1040  else if( dynamic_cast<const RectangularStripTopology*>(&(det->specificType().specificTopology())) )
1041  {
1042  assert(parameters[0] == 2);
1043  assert(parameters[3] == st->pitch());
1044 
1045  for ( uint16_t strip = 1; strip <= nstrips; ++strip )
1046  {
1047  LocalPoint stripPosition = st->localPosition(strip);
1048  float stripX = -parameters[1]*0.5*parameters[3];
1049  stripX += strip*parameters[3];
1050  rectangularStripLocalXs.push_back(stripPosition.x()-stripX);
1051  }
1052  }
1053 
1054  else if( dynamic_cast<const TrapezoidalStripTopology*>(&(det->specificType().specificTopology())) )
1055  {
1056  assert(parameters[0] == 3);
1057  assert(parameters[3] == st->pitch());
1058  }
1059 
1060  else
1061  std::cout<<"Failed to get pitch for "<< detname <<" "<< rawId <<std::endl;
1062  }
1063 
1064  else
1065  std::cout<<"Failed cast to StripTopology for "<< detname <<" "<< rawId <<std::endl;
1066  }
1067 
1068  //else
1069  // std::cout<<"Failed cast to StripGeomDetUnit for "<< detname <<" "<< rawId <<std::endl;
1070  }
1071 
1072  std::string hn(detname);
1073  makeHistogram(hn+" radial strip localX", radialStripLocalXs);
1074  makeHistogram(hn+" rectangular strip localX", rectangularStripLocalXs);
1075 }
1076 
1077 
1078 void
1080  const TGeoMatrix* matrix)
1081 {
1082  double local[3] =
1083  {
1084  0.0, 0.0, 0.0
1085  };
1086 
1087  double global[3];
1088 
1089  matrix->LocalToMaster(local, global);
1090 
1091  double distance = getDistance(GlobalPoint(global[0], global[1], global[2]), gp);
1092  globalDistances_.push_back(distance);
1093 }
1094 
1095 void
1096 ValidateGeometry::compareShape(const GeomDet* det, const float* shape)
1097 {
1098  double shape_topWidth;
1099  double shape_bottomWidth;
1100  double shape_length;
1101  double shape_thickness;
1102 
1103  if ( shape[0] == 1 )
1104  {
1105  shape_topWidth = shape[2];
1106  shape_bottomWidth = shape[1];
1107  shape_length = shape[4];
1108  shape_thickness = shape[3];
1109  }
1110 
1111  else if ( shape[0] == 2 )
1112  {
1113  shape_topWidth = shape[1];
1114  shape_bottomWidth = shape[1];
1115  shape_length = shape[2];
1116  shape_thickness = shape[3];
1117  }
1118 
1119  else
1120  {
1121  std::cout<<"Failed to get box or trapezoid from shape"<<std::endl;
1122  return;
1123  }
1124 
1125  double topWidth, bottomWidth;
1126  double length, thickness;
1127 
1128  const Bounds* bounds = &(det->surface().bounds());
1129 
1130  if ( const TrapezoidalPlaneBounds* tpbs = dynamic_cast<const TrapezoidalPlaneBounds*>(bounds) )
1131  {
1132  std::array<const float, 4> const & ps = tpbs->parameters();
1133 
1134  assert(ps.size() == 4);
1135 
1136  bottomWidth = ps[0];
1137  topWidth = ps[1];
1138  thickness = ps[2];
1139  length = ps[3];
1140  }
1141 
1142  else if ( (dynamic_cast<const RectangularPlaneBounds*>(bounds)) )
1143  {
1144  length = det->surface().bounds().length()*0.5;
1145  topWidth = det->surface().bounds().width()*0.5;
1146  bottomWidth = topWidth;
1147  thickness = det->surface().bounds().thickness()*0.5;
1148  }
1149 
1150  else
1151  {
1152  std::cout<<"Failed to get bounds"<<std::endl;
1153  return;
1154  }
1155 
1156  //assert((tgeotrap && trapezoid) || (tgeobbox && rectangle));
1157 
1158  /*
1159  std::cout<<"topWidth: "<< shape_topWidth <<" "<< topWidth <<std::endl;
1160  std::cout<<"bottomWidth: "<< shape_bottomWidth <<" "<< bottomWidth <<std::endl;
1161  std::cout<<"length: "<< shape_length <<" "<< length <<std::endl;
1162  std::cout<<"thickness: "<< shape_thickness <<" "<< thickness <<std::endl;
1163  */
1164 
1165  topWidths_.push_back(fabs(shape_topWidth - topWidth));
1166  bottomWidths_.push_back(fabs(shape_bottomWidth - bottomWidth));
1167  lengths_.push_back(fabs(shape_length - length));
1168  thicknesses_.push_back(fabs(shape_thickness - thickness));
1169 
1170  return;
1171 }
1172 
1173 
1174 
1175 
1176 double
1178 {
1179  /*
1180  std::cout<<"X: "<< p1.x() <<" "<< p2.x() <<std::endl;
1181  std::cout<<"Y: "<< p1.y() <<" "<< p2.y() <<std::endl;
1182  std::cout<<"Z: "<< p1.z() <<" "<< p2.z() <<std::endl;
1183  */
1184 
1185  return sqrt((p1.x()-p2.x())*(p1.x()-p2.x())+
1186  (p1.y()-p2.y())*(p1.y()-p2.y())+
1187  (p1.z()-p2.z())*(p1.z()-p2.z()));
1188 }
1189 
1190 
1191 void
1193 {
1194  outFile_->cd();
1195 
1196  std::string d(detector);
1197 
1198  std::string gdn = d+": distance between points in global coordinates";
1200 
1201  std::string twn = d + ": absolute difference between top widths (along X)";
1202  makeHistogram(twn, topWidths_);
1203 
1204  std::string bwn = d + ": absolute difference between bottom widths (along X)";
1206 
1207  std::string ln = d + ": absolute difference between lengths (along Y)";
1208  makeHistogram(ln, lengths_);
1209 
1210  std::string tn = d + ": absolute difference between thicknesses (along Z)";
1212 
1213  return;
1214 }
1215 
1216 
1217 void
1219 {
1220  if ( data.empty() )
1221  return;
1222 
1223  std::vector<double>::iterator it;
1224 
1225  it = std::min_element(data.begin(), data.end());
1226  double minE = *it;
1227 
1228  it = std::max_element(data.begin(), data.end());
1229  double maxE = *it;
1230 
1231  std::vector<double>::iterator itEnd = data.end();
1232 
1233  TH1D hist(name.c_str(), name.c_str(), 100, minE*(1+0.10), maxE*(1+0.10));
1234 
1235  for ( it = data.begin(); it != itEnd; ++it )
1236  hist.Fill(*it);
1237 
1238  hist.GetXaxis()->SetTitle("[cm]");
1239  hist.Write();
1240 }
1241 
1242 void
1244 {
1245  outFile_->cd();
1246 }
1247 
1248 
1249 void
1251 {
1252  std::cout<<"Done. "<<std::endl;
1253  std::cout<<"Results written to "<< outfileName_ <<std::endl;
1254  outFile_->Close();
1255 }
1256 
1258 
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
T getUntrackedParameter(std::string const &, T const &) const
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:86
virtual float stripLength() const =0
edm::ESHandle< CaloGeometry > caloGeometry_
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
edm::ESHandle< TrackerGeometry > trackerGeometry_
virtual float length() const =0
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: RPCGeometry.cc:48
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const CSCWireTopology * wireTopology() const
void beginJob() override
std::vector< double > topWidths_
void validateTrackerGeometry(const TrackerGeometry::DetContainer &dets, const char *detname)
CSCDetId id() const
Get the (concrete) DetId.
Definition: CSCChamber.h:37
float centreToIntersection() const override
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:313
TString subdetector
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
DTLayerId id() const
Return the DetId of this SL.
Definition: DTLayer.cc:46
const std::vector< const RPCRoll * > & rolls() const
Return a vector of all RPC rolls.
Definition: RPCGeometry.cc:67
CSCDetId id() const
Definition: CSCLayer.h:42
edm::ESHandle< RPCGeometry > rpcGeometry_
int nstrips() const
Definition: RPCRoll.cc:46
std::vector< double > bottomWidths_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
void makeHistograms(const char *detector)
T y() const
Definition: PV3DBase.h:63
const Bounds & bounds() const
Definition: Surface.h:120
int numberOfStrips() const
const ChamberContainer & chambers() const
Return a vector of all chambers.
Definition: CSCGeometry.cc:106
double wireSpacing() const
const TGeoMatrix * getMatrix(unsigned int id) const
Definition: FWGeometry.cc:186
const StripTopology & specificTopology() const
Definition: RPCRoll.cc:107
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
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)
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:78
float xOfStrip(int strip, float y=0.) const
void validateDTChamberGeometry()
int endcap() const
Definition: CSCDetId.h:93
virtual float width() const =0
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:329
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:80
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const DTTopology & specificTopology() const
Definition: DTLayer.cc:42
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
RPCDetId id() const
Definition: RPCRoll.cc:24
const DetContainer & detsTEC() const
float yCentreOfStripPlane() const override
void compareShape(const GeomDet *det, const float *shape)
virtual LocalPoint localPosition(float strip) const =0
void loadMap(const char *fileName)
Definition: FWGeometry.cc:56
T sqrt(T t)
Definition: SSEVec.h:18
void validateCaloGeometry(DetId::Detector detector, int subdetector, const char *detname)
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:33
T z() const
Definition: PV3DBase.h:64
const DetContainer & detsPXB() const
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:79
float phiOfOneEdge() 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
double p2[4]
Definition: TauolaWrapper.h:90
float pixelLocalX(const double mpx, const float *)
Definition: TrackUtils.cc:160
const DetContainer & detsTIB() const
edm::ESHandle< CSCGeometry > cscGeometry_
void endJob() override
float pixelLocalY(const double mpy, const float *)
Definition: TrackUtils.cc:216
LocalPoint localCenterOfWireGroup(int wireGroup) const
int ring() const
Definition: CSCDetId.h:75
Definition: DetId.h:18
const CSCStripTopology * topology() const
size_type size() const
Definition: EZArrayFL.h:81
virtual float stripOffset(void) const
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
float yAxisOrientation() const override
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:297
double getDistance(const GlobalPoint &point1, const GlobalPoint &point2)
virtual float thickness() const =0
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:50
const std::vector< const DTLayer * > & layers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:94
virtual int nstrips() const =0
Detector
Definition: DetId.h:26
ValidateGeometry(const edm::ParameterSet &)
float angularWidth() const override
std::vector< const GeomDet * > DetContainer
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double p1[4]
Definition: TauolaWrapper.h:89
std::vector< double > thicknesses_
T get() const
Definition: EventSetup.h:63
const DetContainer & detsPXF() const
const TrackerGeomDet * idToDet(DetId) const override
const DetContainer & detsTOB() const
void analyze(const edm::Event &, const edm::EventSetup &) override
virtual float pitch() const =0
int station() const
Definition: CSCDetId.h:86
std::string infileName_
Definition: Bounds.h:22
void validateCSChamberGeometry(const int endcap, const char *detname)
float wireAngle() const override
void validateStripTopology(const TrackerGeometry::DetContainer &dets, const char *detname)
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
bool isValid() const
Definition: ESHandle.h:47
std::vector< double > lengths_
T x() const
Definition: PV3DBase.h:62
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:47
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
Definition: event.py:1
std::vector< double > globalDistances_
const DetContainer & detsTID() const
const LayerContainer & layers() const
Return a vector of all layers.
Definition: CSCGeometry.cc:112
~ValidateGeometry() override
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63