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 
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;
230  validateTrackerGeometry(trackerGeometry_->detsTIB(), "TIB");
231  validateStripTopology(trackerGeometry_->detsTIB(), "TIB");
232 
233  std::cout<<"Validating TOB geometry and topology"<<std::endl;
234  validateTrackerGeometry(trackerGeometry_->detsTOB(), "TOB");
235  validateStripTopology(trackerGeometry_->detsTOB(), "TOB");
236 
237  std::cout<<"Validating TEC geometry and topology"<<std::endl;
238  validateTrackerGeometry(trackerGeometry_->detsTEC(), "TEC");
239  validateStripTopology(trackerGeometry_->detsTEC(), "TEC");
240 
241  std::cout<<"Validating TID geometry and topology"<<std::endl;
242  validateTrackerGeometry(trackerGeometry_->detsTID(), "TID");
243  validateStripTopology(trackerGeometry_->detsTID(), "TID");
244 
245  std::cout<<"Validating PXB geometry and topology"<<std::endl;
246  validateTrackerGeometry(trackerGeometry_->detsPXB(), "PXB");
247  validatePixelTopology(trackerGeometry_->detsPXB(), "PXB");
248 
249  std::cout<<"Validating PXF geometry and topology"<<std::endl;
250  validateTrackerGeometry(trackerGeometry_->detsPXF(), "PXF");
251  validatePixelTopology(trackerGeometry_->detsPXF(), "PXF");
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 == 0 )
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 == 0 )
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 == 0 )
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 == 0 )
860  {
861  std::cout <<"Failed to get points of "<< detname
862  <<" element with detid: "<< rawId <<std::endl;
863  continue;
864  }
865 
866  const CaloCellGeometry* 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 == 0 )
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  assert(parameters[0] == nrows);
957  assert(parameters[1] == ncolumns);
958 
959  for ( int row = 1; row <= nrows; ++row )
960  {
961  for ( int column = 1; column <= ncolumns; ++column )
962  {
963  LocalPoint localPoint = rpt->localPosition(MeasurementPoint(row, column));
964 
965  pixelLocalXs.push_back(localPoint.x() - fireworks::pixelLocalX(row, nrows));
966  pixelLocalYs.push_back(localPoint.y() - fireworks::pixelLocalY(column, ncolumns));
967  }
968  }
969  }
970 
971  else
972  std::cout<<"No topology for "<< detname <<" "<< rawId <<std::endl;
973  }
974 
975  else
976  std::cout<<"No geomDetUnit for "<< detname <<" "<< rawId <<std::endl;
977  }
978 
979  std::string hn(detname);
980  makeHistogram(hn+" pixelLocalX", pixelLocalXs);
981  makeHistogram(hn+" pixelLocalY", pixelLocalYs);
982 }
983 
984 void
986  const char* detname)
987 {
988  std::vector<double> radialStripLocalXs;
989  std::vector<double> rectangularStripLocalXs;
990 
991  for ( TrackerGeometry::DetContainer::const_iterator it = dets.begin(),
992  itEnd = dets.end();
993  it != itEnd; ++it )
994  {
995  unsigned int rawId = (*it)->geographicalId().rawId();
996 
997  const float* parameters = fwGeometry_.getParameters(rawId);
998 
999  if ( parameters == 0 )
1000  {
1001  std::cout<<"Parameters empty for "<< detname <<" element with detid: "
1002  << rawId <<std::endl;
1003  continue;
1004  }
1005 
1006  if ( const StripGeomDetUnit* det =
1007  dynamic_cast<const StripGeomDetUnit*>(trackerGeometry_->idToDet((*it)->geographicalId())) )
1008  {
1009  // NOTE: why the difference in dets vs. units between these and pixels? The dynamic cast above
1010  // fails for many of the detids...
1011 
1012  const StripTopology* st = dynamic_cast<const StripTopology*>(&det->specificTopology());
1013 
1014  if ( st )
1015  {
1016  //assert(parameters[0] == 0);
1017  int nstrips = st->nstrips();
1018  assert(parameters[1] == nstrips);
1019  assert(parameters[2] == st->stripLength());
1020 
1021  if( const RadialStripTopology* rst = dynamic_cast<const RadialStripTopology*>(&(det->specificType().specificTopology())) )
1022  {
1023  assert(parameters[0] == 1);
1024  assert(parameters[3] == rst->yAxisOrientation());
1025  assert(parameters[4] == rst->originToIntersection());
1026  assert(parameters[5] == rst->phiOfOneEdge());
1027  assert(parameters[6] == rst->angularWidth());
1028 
1029  for ( uint16_t strip = 1; strip <= nstrips; ++strip )
1030  {
1031  float stripAngle1 = rst->stripAngle(strip);
1032  float stripAngle2 = parameters[3] * (parameters[5] + strip*parameters[6]);
1033 
1034  assert((stripAngle1-stripAngle2) == 0);
1035 
1036  LocalPoint stripPosition = st->localPosition(strip);
1037 
1038  float stripX = parameters[4]*tan(stripAngle2);
1039  radialStripLocalXs.push_back(stripPosition.x()-stripX);
1040  }
1041  }
1042 
1043  else if( dynamic_cast<const RectangularStripTopology*>(&(det->specificType().specificTopology())) )
1044  {
1045  assert(parameters[0] == 2);
1046  assert(parameters[3] == st->pitch());
1047 
1048  for ( uint16_t strip = 1; strip <= nstrips; ++strip )
1049  {
1050  LocalPoint stripPosition = st->localPosition(strip);
1051  float stripX = -parameters[1]*0.5*parameters[3];
1052  stripX += strip*parameters[3];
1053  rectangularStripLocalXs.push_back(stripPosition.x()-stripX);
1054  }
1055  }
1056 
1057  else if( dynamic_cast<const TrapezoidalStripTopology*>(&(det->specificType().specificTopology())) )
1058  {
1059  assert(parameters[0] == 3);
1060  assert(parameters[3] == st->pitch());
1061  }
1062 
1063  else
1064  std::cout<<"Failed to get pitch for "<< detname <<" "<< rawId <<std::endl;
1065  }
1066 
1067  else
1068  std::cout<<"Failed cast to StripTopology for "<< detname <<" "<< rawId <<std::endl;
1069  }
1070 
1071  //else
1072  // std::cout<<"Failed cast to StripGeomDetUnit for "<< detname <<" "<< rawId <<std::endl;
1073  }
1074 
1075  std::string hn(detname);
1076  makeHistogram(hn+" radial strip localX", radialStripLocalXs);
1077  makeHistogram(hn+" rectangular strip localX", rectangularStripLocalXs);
1078 }
1079 
1080 
1081 void
1083  const TGeoMatrix* matrix)
1084 {
1085  double local[3] =
1086  {
1087  0.0, 0.0, 0.0
1088  };
1089 
1090  double global[3];
1091 
1092  matrix->LocalToMaster(local, global);
1093 
1094  double distance = getDistance(GlobalPoint(global[0], global[1], global[2]), gp);
1095  globalDistances_.push_back(distance);
1096 }
1097 
1098 void
1099 ValidateGeometry::compareShape(const GeomDet* det, const float* shape)
1100 {
1101  double shape_topWidth;
1102  double shape_bottomWidth;
1103  double shape_length;
1104  double shape_thickness;
1105 
1106  if ( shape[0] == 1 )
1107  {
1108  shape_topWidth = shape[2];
1109  shape_bottomWidth = shape[1];
1110  shape_length = shape[4];
1111  shape_thickness = shape[3];
1112  }
1113 
1114  else if ( shape[0] == 2 )
1115  {
1116  shape_topWidth = shape[1];
1117  shape_bottomWidth = shape[1];
1118  shape_length = shape[2];
1119  shape_thickness = shape[3];
1120  }
1121 
1122  else
1123  {
1124  std::cout<<"Failed to get box or trapezoid from shape"<<std::endl;
1125  return;
1126  }
1127 
1128  double topWidth, bottomWidth;
1129  double length, thickness;
1130 
1131  const Bounds* bounds = &(det->surface().bounds());
1132 
1133  if ( const TrapezoidalPlaneBounds* tpbs = dynamic_cast<const TrapezoidalPlaneBounds*>(bounds) )
1134  {
1135  std::array<const float, 4> const & ps = tpbs->parameters();
1136 
1137  assert(ps.size() == 4);
1138 
1139  bottomWidth = ps[0];
1140  topWidth = ps[1];
1141  thickness = ps[2];
1142  length = ps[3];
1143  }
1144 
1145  else if ( (dynamic_cast<const RectangularPlaneBounds*>(bounds)) )
1146  {
1147  length = det->surface().bounds().length()*0.5;
1148  topWidth = det->surface().bounds().width()*0.5;
1149  bottomWidth = topWidth;
1150  thickness = det->surface().bounds().thickness()*0.5;
1151  }
1152 
1153  else
1154  {
1155  std::cout<<"Failed to get bounds"<<std::endl;
1156  return;
1157  }
1158 
1159  //assert((tgeotrap && trapezoid) || (tgeobbox && rectangle));
1160 
1161  /*
1162  std::cout<<"topWidth: "<< shape_topWidth <<" "<< topWidth <<std::endl;
1163  std::cout<<"bottomWidth: "<< shape_bottomWidth <<" "<< bottomWidth <<std::endl;
1164  std::cout<<"length: "<< shape_length <<" "<< length <<std::endl;
1165  std::cout<<"thickness: "<< shape_thickness <<" "<< thickness <<std::endl;
1166  */
1167 
1168  topWidths_.push_back(fabs(shape_topWidth - topWidth));
1169  bottomWidths_.push_back(fabs(shape_bottomWidth - bottomWidth));
1170  lengths_.push_back(fabs(shape_length - length));
1171  thicknesses_.push_back(fabs(shape_thickness - thickness));
1172 
1173  return;
1174 }
1175 
1176 
1177 
1178 
1179 double
1181 {
1182  /*
1183  std::cout<<"X: "<< p1.x() <<" "<< p2.x() <<std::endl;
1184  std::cout<<"Y: "<< p1.y() <<" "<< p2.y() <<std::endl;
1185  std::cout<<"Z: "<< p1.z() <<" "<< p2.z() <<std::endl;
1186  */
1187 
1188  return sqrt((p1.x()-p2.x())*(p1.x()-p2.x())+
1189  (p1.y()-p2.y())*(p1.y()-p2.y())+
1190  (p1.z()-p2.z())*(p1.z()-p2.z()));
1191 }
1192 
1193 
1194 void
1196 {
1197  outFile_->cd();
1198 
1199  std::string d(detector);
1200 
1201  std::string gdn = d+": distance between points in global coordinates";
1203 
1204  std::string twn = d + ": absolute difference between top widths (along X)";
1205  makeHistogram(twn, topWidths_);
1206 
1207  std::string bwn = d + ": absolute difference between bottom widths (along X)";
1209 
1210  std::string ln = d + ": absolute difference between lengths (along Y)";
1211  makeHistogram(ln, lengths_);
1212 
1213  std::string tn = d + ": absolute difference between thicknesses (along Z)";
1215 
1216  return;
1217 }
1218 
1219 
1220 void
1222 {
1223  if ( data.empty() )
1224  return;
1225 
1226  std::vector<double>::iterator it;
1227 
1228  it = std::min_element(data.begin(), data.end());
1229  double minE = *it;
1230 
1231  it = std::max_element(data.begin(), data.end());
1232  double maxE = *it;
1233 
1234  std::vector<double>::iterator itEnd = data.end();
1235 
1236  TH1D hist(name.c_str(), name.c_str(), 100, minE*(1+0.10), maxE*(1+0.10));
1237 
1238  for ( it = data.begin(); it != itEnd; ++it )
1239  hist.Fill(*it);
1240 
1241  hist.GetXaxis()->SetTitle("[cm]");
1242  hist.Write();
1243 }
1244 
1245 void
1247 {
1248  outFile_->cd();
1249 }
1250 
1251 
1252 void
1254 {
1255  std::cout<<"Done. "<<std::endl;
1256  std::cout<<"Results written to "<< outfileName_ <<std::endl;
1257  outFile_->Close();
1258 }
1259 
1261 
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
virtual int nstrips() const =0
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
int i
Definition: DBlmapReader.cc:9
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
TString subdetector
#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:120
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: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)
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:93
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: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
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
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: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
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:280
double getDistance(const GlobalPoint &point1, const GlobalPoint &point2)
#define fwLog(_level_)
Definition: fwLog.h:50
Detector
Definition: DetId.h:24
const T & get() const
Definition: EventSetup.h:56
ValidateGeometry(const edm::ParameterSet &)
CornersVec const & getCorners() const
Returns the corner points of this cell&#39;s volume.
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:86
tuple cout
Definition: gather_cfg.py:145
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_
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