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