CMS 3D CMS Logo

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