CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWTGeoRecoGeometryESProducer.cc
Go to the documentation of this file.
4 
21 
48 
49 #include "TGeoManager.h"
50 #include "TGeoArb8.h"
51 #include "TGeoMatrix.h"
52 
53 #include "TFile.h"
54 #include "TTree.h"
55 #include "TError.h"
56 #include "TMath.h"
57 
58 #include "TEveVector.h"
59 #include "TEveTrans.h"
60 
61 
62 //std::map< const CaloCellGeometry::CCGFloat*, TGeoVolume*> caloShapeMap;
63 namespace {
64 typedef std::map< const float*, TGeoVolume*> CaloVolMap;
65 }
67 m_dummyMedium(0)
68 {
69  setWhatProduced( this );
70 }
71 
73 {}
74 
75 namespace
76 {
77 
78 void AddLeafNode(TGeoVolume* mother, TGeoVolume* daughter, const char* name, TGeoMatrix* mtx )
79 {
80  int n = mother->GetNdaughters();
81  mother->AddNode(daughter, 1, mtx);
82  mother->GetNode(n)->SetName(name);
83 }
84 
86 TGeoCombiTrans* createPlacement( const GeomDet *det )
87 {
88  // Position of the DetUnit's center
89  float posx = det->surface().position().x();
90  float posy = det->surface().position().y();
91  float posz = det->surface().position().z();
92 
93  TGeoTranslation trans( posx, posy, posz );
94 
95  // Add the coeff of the rotation matrix
96  // with a projection on the basis vectors
97  TkRotation<float> detRot = det->surface().rotation();
98 
99  TGeoRotation rotation;
100  const Double_t matrix[9] = { detRot.xx(), detRot.yx(), detRot.zx(),
101  detRot.xy(), detRot.yy(), detRot.zy(),
102  detRot.xz(), detRot.yz(), detRot.zz()
103  };
104  rotation.SetMatrix( matrix );
105 
106  return new TGeoCombiTrans( trans, rotation );
107 }
108 
109 
110 }
111 //______________________________________________________________________________
112 
113 
114 TGeoVolume* FWTGeoRecoGeometryESProducer::GetDaughter(TGeoVolume* mother, const char* prefix, ERecoDet cidx, int id)
115 {
116  TGeoVolume* res = 0;
117  if (mother->GetNdaughters()) {
118  TGeoNode* n = mother->FindNode(Form("%s_%d_1", prefix, id));
119  if ( n ) res = n->GetVolume();
120  }
121 
122  if (!res) {
123  res = new TGeoVolumeAssembly( Form("%s_%d", prefix, id ));
124  res->SetMedium(GetMedium(cidx));
125  mother->AddNode(res, 1);
126  }
127 
128  return res;
129 }
130 
131 TGeoVolume* FWTGeoRecoGeometryESProducer::GetDaughter(TGeoVolume* mother, const char* prefix, ERecoDet cidx)
132 {
133  TGeoVolume* res = 0;
134  if (mother->GetNdaughters()) {
135  TGeoNode* n = mother->FindNode(Form("%s_1",prefix));
136  if ( n ) res = n->GetVolume();
137  }
138 
139  if (!res) {
140  // printf("GetDau... new holder %s for mother %s \n", mother->GetName(), prefix);
141  res = new TGeoVolumeAssembly(prefix);
142  res->SetMedium(GetMedium(cidx));
143  mother->AddNode(res, 1);
144  }
145 
146  return res;
147 }
148 
149 TGeoVolume* FWTGeoRecoGeometryESProducer::GetTopHolder(const char* prefix, ERecoDet cidx)
150 {
151  // printf("GetTopHolder res = %s \n", prefix);
152  TGeoVolume* res = GetDaughter(gGeoManager->GetTopVolume(), prefix, cidx);
153  return res;
154 }
155 
156 namespace {
157 
158 enum GMCol { Green = 4,
159  Blue0 = 13, Blue1 = 24, Blue2 = 6,
160  Yellow0 = 3, Yellow1 = 16,
161  Pink = 10,
162  Red = 29, Orange0 = 79, Orange1 = 14,
163  Magenta = 8,
164  Gray = 12
165 };
166 
167 }
168 
169 
170 TGeoMedium*
172 {
173  std::map<ERecoDet, TGeoMedium*>::iterator it = m_recoMedium.find(det);
174  if (it != m_recoMedium.end())
175  return it->second;
176 
177  std::string name;
178  int color;
179 
180 
181  switch (det)
182  {
183  // TRACKER
184  case kSiPixel:
185  name = "SiPixel";
186  color = GMCol::Green;
187  break;
188 
189  case kSiStrip:
190  name = "SiStrip";
191  color = GMCol::Gray;
192  break;
193  // MUON
194  case kMuonDT:
195  name = "MuonDT";
196  color = GMCol::Blue2;
197  break;
198 
199  case kMuonRPC:
200  name = "MuonRPC";
201  color = GMCol::Red;
202  break;
203 
204  case kMuonGEM:
205  name = "MuonGEM";
206  color = GMCol::Yellow1;
207  break;
208 
209  case kMuonCSC:
210  name = "MuonCSC";
211  color = GMCol::Gray;
212  break;
213 
214  case kMuonME0:
215  name = "MuonME0";
216  color = GMCol::Yellow0;
217  break;
218 
219  // CALO
220  case kECal:
221  name = "ECal";
222  color = GMCol::Blue2;
223  break;
224  case kHCal:
225  name = "HCal";
226  color = GMCol::Orange1;
227  break;
228  case kHGCE:
229  name = "HGCEE";
230  color = GMCol::Blue2;
231  break;
232  case kHGCH:
233  name = "HGCEH";
234  color = GMCol::Blue1;
235  break;
236  default:
237  printf("invalid medium id \n");
238  return m_dummyMedium;
239  }
240 
241  TGeoMaterial* mat = new TGeoMaterial(name.c_str(), 0, 0, 0);
242  mat->SetZ(color);
243  m_recoMedium[det] = new TGeoMedium(name.c_str(), 0, mat);
244  mat->SetFillStyle(3000); // tansparency 3000-3100
245  mat->SetDensity(1); // disable override of transparency in TGeoManager::DefaultColors()
246 
247  return m_recoMedium[det];
248 }
249 
250 
251 //______________________________________________________________________________
252 
253 
254 
255 boost::shared_ptr<FWTGeoRecoGeometry>
257 {
258  using namespace edm;
259 
260  m_fwGeometry = boost::shared_ptr<FWTGeoRecoGeometry>( new FWTGeoRecoGeometry );
262 
263  DetId detId( DetId::Tracker, 0 );
264  m_trackerGeom = (const TrackerGeometry*) m_geomRecord->slaveGeometry( detId );
265 
266  record.getRecord<CaloGeometryRecord>().get( m_caloGeom );
267 
268  TGeoManager* geom = new TGeoManager( "cmsGeo", "CMS Detector" );
269  if( 0 == gGeoIdentity )
270  {
271  gGeoIdentity = new TGeoIdentity( "Identity" );
272  }
273 
274  m_fwGeometry->manager( geom );
275 
276  // Default material is Vacuum
277  TGeoMaterial *vacuum = new TGeoMaterial( "Vacuum", 0 ,0 ,0 );
278  m_dummyMedium = new TGeoMedium( "reco", 0, vacuum);
279 
280 
281  TGeoVolume *top = geom->MakeBox( "CMS", m_dummyMedium, 270., 270., 120. );
282 
283 
284  if( 0 == top )
285  {
286  return boost::shared_ptr<FWTGeoRecoGeometry>();
287  }
288  geom->SetTopVolume( top );
289  // ROOT chokes unless colors are assigned
290  top->SetVisibility( kFALSE );
291  top->SetLineColor( kBlue );
292 
295 
296  addTIBGeometry();
297  addTIDGeometry();
298  addTOBGeometry();
299  addTECGeometry();
300  addDTGeometry();
301 
302  addCSCGeometry();
303  addRPCGeometry();
304  addME0Geometry();
305  addGEMGeometry();
306 
310 
311  geom->CloseGeometry();
312 
313  geom->DefaultColors();
314  // printf("==== geo manager NNodes = %d \n", geom->GetNNodes());
315  geom->CloseGeometry();
316 
317  return m_fwGeometry;
318 }
319 
321 TGeoShape*
323 {
324  TGeoShape* shape = 0;
325 
326  // Trapezoidal
327  const Bounds *b = &((det->surface ()).bounds ());
328  const TrapezoidalPlaneBounds *b2 = dynamic_cast<const TrapezoidalPlaneBounds *> (b);
329  if( b2 )
330  {
331  std::array< const float, 4 > const & par = b2->parameters ();
332 
333  // These parameters are half-lengths, as in CMSIM/GEANT3
334  float hBottomEdge = par [0];
335  float hTopEdge = par [1];
336  float thickness = par [2];
337  float apothem = par [3];
338 
339  std::stringstream s;
340  s << "T_"
341  << hBottomEdge << "_"
342  << hTopEdge << "_"
343  << thickness << "_"
344  << apothem;
345  std::string name = s.str();
346 
347  // Do not create identical shape,
348  // if one already exists
349  shape = m_nameToShape[name];
350  if( 0 == shape )
351  {
352  shape = new TGeoTrap(
353  name.c_str(),
354  thickness, //dz
355  0, //theta
356  0, //phi
357  apothem, //dy1
358  hBottomEdge,//dx1
359  hTopEdge, //dx2
360  0, //alpha1
361  apothem, //dy2
362  hBottomEdge,//dx3
363  hTopEdge, //dx4
364  0); //alpha2
365 
366  m_nameToShape[name] = shape;
367  }
368  }
369  if( dynamic_cast<const RectangularPlaneBounds *> (b) != 0 )
370  {
371  // Rectangular
372  float length = det->surface().bounds().length();
373  float width = det->surface().bounds ().width();
374  float thickness = det->surface().bounds().thickness();
375 
376  std::stringstream s;
377  s << "R_"
378  << width << "_"
379  << length << "_"
380  << thickness;
381  std::string name = s.str();
382 
383  // Do not create identical shape,
384  // if one already exists
385  shape = m_nameToShape[name];
386  if( 0 == shape )
387  {
388  shape = new TGeoBBox( name.c_str(), width / 2., length / 2., thickness / 2. ); // dx, dy, dz
389 
390  m_nameToShape[name] = shape;
391  }
392  }
393 
394  return shape;
395 }
396 
398 TGeoVolume*
400 {
401  TGeoShape* solid = createShape( det );
402 
403  std::map<TGeoShape*, TGeoVolume*>::iterator vIt = m_shapeToVolume.find(solid);
404  if (vIt != m_shapeToVolume.end()) return vIt->second;
405 
406 
407  TGeoVolume* volume = new TGeoVolume( name.c_str(),solid, GetMedium(mid));
408 
409  m_shapeToVolume[solid] = volume;
410 
411  return volume;
412 }
413 
414 
415 
424 
425 
426 void
428 {
429  TGeoVolume* tv = GetTopHolder("SiPixel", kSiPixel);
430  TGeoVolume *assembly = GetDaughter(tv, "PXB", kSiPixel);
431 
432  for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsPXB().begin(),
433  end = m_trackerGeom->detsPXB().end();
434  it != end; ++it)
435  {
436  DetId detid = ( *it )->geographicalId();
437  unsigned int rawid = detid.rawId();
438 
439  PXBDetId xx(rawid);
440  std::string name = Form("PXB Ly:%d, Md:%d Ld:%d ", xx.layer(), xx.module(), xx.layer());
441  TGeoVolume* child = createVolume( name, *it, kSiPixel );
442 
443  TGeoVolume* holder = GetDaughter(assembly, "Layer", kSiPixel, xx.layer());
444  holder = GetDaughter(holder, "Module", kSiPixel, xx.module());
445 
446  AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
447  }
448 
449 
450 }
451 //______________________________________________________________________________
452 
453 
454 void
456 {
457  TGeoVolume* tv = GetTopHolder("SiPixel", kSiPixel);
458  TGeoVolume *assembly = GetDaughter(tv, "PXF", kSiPixel);
459 
460  for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsPXF().begin(),
461  end = m_trackerGeom->detsPXF().end();
462  it != end; ++it )
463  {
464  PXFDetId detid = ( *it )->geographicalId();
465  std::stringstream s;
466  s << detid;
467  std::string name = s.str();
468 
469  TGeoVolume* child = createVolume( name, *it, kSiPixel );
470 
471 
472  TGeoVolume* holder = GetDaughter(assembly, "Side", kSiPixel, detid.side());
473  holder = GetDaughter(holder, "Disk", kSiPixel, detid.disk());
474  holder = GetDaughter(holder, "Blade", kSiPixel, detid.blade());
475  holder = GetDaughter(holder, "Panel", kSiPixel, detid.panel());
476 
477  // holder->AddNode( child, 1, createPlacement( *it ));
478  AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
479 
480  }
481 
482 }
483 
484 //______________________________________________________________________________
485 
486 
487 void
489 {
490  TGeoVolume* tv = GetTopHolder( "SiStrip", kSiStrip);
491  TGeoVolume *assembly = GetDaughter(tv,"TIB", kSiStrip);
492 
493  for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTIB().begin(),
494  end = m_trackerGeom->detsTIB().end();
495  it != end; ++it )
496  {
497  TIBDetId detid(( *it )->geographicalId());
498  std::stringstream s;
499  s << detid;
500  std::string name = s.str();
501 
502  TGeoVolume* child = createVolume( name, *it, kSiStrip );
503 
504  TGeoVolume* holder = GetDaughter(assembly, "Module", kSiStrip, detid.module());
505  holder = GetDaughter(holder, "Order", kSiStrip, detid.order());
506  holder = GetDaughter(holder, "Side", kSiStrip, detid.side());
507  AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
508  }
509 }
510 
511 //______________________________________________________________________________
512 
513 
514 void
516 {
517  TGeoVolume* tv = GetTopHolder( "SiStrip", kSiStrip);
518  TGeoVolume *assembly = GetDaughter( tv, "TID", kSiStrip);
519 
520  for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTID().begin(),
521  end = m_trackerGeom->detsTID().end();
522  it != end; ++it)
523  {
524  TIDDetId detid = ( *it )->geographicalId();
525  std::stringstream s;
526  s << detid;
527  std::string name = s.str();
528 
529  TGeoVolume* child = createVolume( name, *it, kSiStrip );
530  TGeoVolume* holder = GetDaughter(assembly, "Side", kSiStrip, detid.side());
531  holder = GetDaughter(holder, "Wheel", kSiStrip, detid.wheel());
532  holder = GetDaughter(holder, "Ring", kSiStrip, detid.ring());
533  AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
534  }
535 }
536 
537 //______________________________________________________________________________
538 
539 void
541 {
542  TGeoVolume* tv = GetTopHolder( "SiStrip", kSiStrip);
543  TGeoVolume *assembly = GetDaughter(tv, "TOB", kSiStrip);
544 
545  for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTOB().begin(),
546  end = m_trackerGeom->detsTOB().end();
547  it != end; ++it )
548  {
549  TOBDetId detid(( *it )->geographicalId());
550  std::stringstream s;
551  s << detid;
552  std::string name = s.str();
553 
554  TGeoVolume* child = createVolume( name, *it, kSiStrip );
555  TGeoVolume* holder = GetDaughter(assembly, "Rod", kSiStrip, detid.rodNumber());
556  holder = GetDaughter(holder, "Side", kSiStrip, detid.side());
557  holder = GetDaughter(holder, "Module", kSiStrip, detid.moduleNumber());
558  AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
559  }
560 
561 }
562 //______________________________________________________________________________
563 
564 
565 void
567 {
568  TGeoVolume* tv = GetTopHolder( "SiStrip", kSiStrip);
569  TGeoVolume *assembly = GetDaughter(tv, "TEC", kSiStrip);
570 
571  for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTEC().begin(),
572  end = m_trackerGeom->detsTEC().end();
573  it != end; ++it )
574  {
575  TECDetId detid = ( *it )->geographicalId();
576 
577  std::stringstream s;
578  s << detid;
579  std::string name = s.str();
580 
581  TGeoVolume* child = createVolume( name, *it, kSiStrip );
582 
583  TGeoVolume* holder = GetDaughter(assembly, "Order", kSiStrip, detid.order());
584  holder = GetDaughter(holder, "Ring", kSiStrip, detid.ring());
585  holder = GetDaughter(holder, "Module", kSiStrip, detid.module());
586  AddLeafNode(holder, child, name.c_str(), createPlacement( *it ));
587  }
588 }
589 
590 //==============================================================================
591 //==============================================================================
592 //=================================== MUON =====================================
593 //==============================================================================
594 
595 
596 
597 void
599 {
600  TGeoVolume* tv = GetTopHolder("Muon", kMuonRPC);
601  TGeoVolume *assemblyTop = GetDaughter(tv, "DT", kMuonDT);
602 
603  //
604  // DT chambers geometry
605  //
606  {
607  TGeoVolume *assembly = GetDaughter(assemblyTop, "DTChamber", kMuonDT);
608  auto const & dtChamberGeom = m_geomRecord->slaveGeometry( DTChamberId())->dets();
609  for( auto it = dtChamberGeom.begin(),
610  end = dtChamberGeom.end();
611  it != end; ++it )
612  {
613  if( auto chamber = dynamic_cast< const DTChamber *>(*it))
614  {
615  DTChamberId detid = chamber->geographicalId();
616  std::stringstream s;
617  s << detid;
618  std::string name = s.str();
619 
620  TGeoVolume* child = createVolume( name, chamber, kMuonDT );
621  TGeoVolume* holder = GetDaughter(assembly, "Wheel", kMuonDT, detid.wheel());
622  holder = GetDaughter(holder, "Station", kMuonDT, detid.station());
623  holder = GetDaughter(holder, "Sector", kMuonDT, detid.sector());
624 
625  AddLeafNode(holder, child, name.c_str(), createPlacement( chamber));
626  }
627  }
628  }
629 
630  // Fill in DT super layer parameters
631  {
632  TGeoVolume *assembly = GetDaughter(assemblyTop, "DTSuperLayer", kMuonDT);
633  auto const & dtSuperLayerGeom = m_geomRecord->slaveGeometry( DTSuperLayerId())->dets();
634  for( auto it = dtSuperLayerGeom.begin(),
635  end = dtSuperLayerGeom.end();
636  it != end; ++it )
637  {
638  if( auto * superlayer = dynamic_cast<const DTSuperLayer*>(*it))
639  {
640  DTSuperLayerId detid( DetId(superlayer->geographicalId()));
641  std::stringstream s;
642  s << detid;
643  std::string name = s.str();
644 
645  TGeoVolume* child = createVolume( name, superlayer, kMuonDT );
646 
647  TGeoVolume* holder = GetDaughter(assembly, "Wheel", kMuonDT, detid.wheel());
648  holder = GetDaughter(holder, "Station", kMuonDT, detid.station());
649  holder = GetDaughter(holder, "Sector", kMuonDT, detid.sector());
650  holder = GetDaughter(holder, "SuperLayer", kMuonDT, detid.superlayer());
651  AddLeafNode(holder, child, name.c_str(), createPlacement( superlayer));
652  }
653  }
654  }
655  // Fill in DT layer parameters
656  {
657  TGeoVolume *assembly = GetDaughter(assemblyTop, "DTLayer", kMuonDT);
658  auto const & dtLayerGeom = m_geomRecord->slaveGeometry( DTLayerId())->dets();
659  for( auto it = dtLayerGeom.begin(),
660  end = dtLayerGeom.end();
661  it != end; ++it )
662  {
663  if(auto layer = dynamic_cast<const DTLayer*>(*it))
664  {
665 
666  DTLayerId detid( DetId(layer->geographicalId()));
667 
668  std::stringstream s;
669  s << detid;
670  std::string name = s.str();
671 
672  TGeoVolume* child = createVolume( name, layer, kMuonDT );
673 
674  TGeoVolume* holder = GetDaughter(assembly, "Wheel", kMuonDT, detid.wheel());
675  holder = GetDaughter(holder, "Station", kMuonDT, detid.station());
676  holder = GetDaughter(holder, "Sector", kMuonDT, detid.sector());
677  holder = GetDaughter(holder, "SuperLayer", kMuonDT, detid.superlayer());
678  holder = GetDaughter(holder, "Layer", kMuonDT, detid.layer());
679  AddLeafNode(holder, child, name.c_str(), createPlacement( layer));
680  }
681  }
682  }
683 }
684 //______________________________________________________________________________
685 
686 void
688 {
689  if(! m_geomRecord->slaveGeometry( CSCDetId()))
690  throw cms::Exception( "FatalError" ) << "Cannnot find CSCGeometry\n";
691 
692 
693  TGeoVolume* tv = GetTopHolder("Muon", kMuonRPC);
694  TGeoVolume *assembly = GetDaughter(tv, "CSC", kMuonCSC);
695 
696  auto const & cscGeom = m_geomRecord->slaveGeometry( CSCDetId())->dets();
697  for( auto it = cscGeom.begin(), itEnd = cscGeom.end(); it != itEnd; ++it )
698  {
699  unsigned int rawid = (*it)->geographicalId();
700  CSCDetId detId(rawid);
701  std::stringstream s;
702  s << "CSC" << detId;
703  std::string name = s.str();
704 
705  TGeoVolume* child = 0;
706 
707  if( auto chamber = dynamic_cast<const CSCChamber*>(*it))
708  child = createVolume( name, chamber, kMuonCSC );
709  else if( auto * layer = dynamic_cast<const CSCLayer*>(*it))
710  child = createVolume( name, layer, kMuonCSC );
711 
712 
713 
714  if (child) {
715  TGeoVolume* holder = GetDaughter(assembly, "Endcap", kMuonCSC, detId.endcap());
716  holder = GetDaughter(holder, "Station", kMuonCSC, detId.station());
717  holder = GetDaughter(holder, "Ring", kMuonCSC, detId.ring());
718  holder = GetDaughter(holder, "Chamber", kMuonCSC , detId.chamber());
719 
720  // holder->AddNode(child, 1, createPlacement( *it ));
721  AddLeafNode(holder, child, name.c_str(), createPlacement(*it));
722  }
723  }
724 
725 }
726 
727 //______________________________________________________________________________
728 
729 void
731 {
732  try {
734  const GEMGeometry* gemGeom = (const GEMGeometry*) m_geomRecord->slaveGeometry( detId );
735 
736  TGeoVolume* tv = GetTopHolder("Muon", kMuonRPC);
737  TGeoVolume *assembly = GetDaughter(tv, "GEM", kMuonGEM);
738 
739  for( auto it = gemGeom->etaPartitions().begin(),
740  end = gemGeom->etaPartitions().end();
741  it != end; ++it )
742  {
743  const GEMEtaPartition* roll = (*it);
744  if( roll )
745  {
746  GEMDetId detid = roll->geographicalId();
747  std::stringstream s;
748  s << detid;
749  std::string name = s.str();
750 
751  TGeoVolume* child = createVolume( name, roll, kMuonGEM );
752 
753  TGeoVolume* holder = GetDaughter(assembly, "ROLL Region", kMuonGEM , detid.region());
754  holder = GetDaughter(holder, "Ring", kMuonGEM , detid.ring());
755  holder = GetDaughter(holder, "Station", kMuonGEM , detid.station());
756  holder = GetDaughter(holder, "Layer", kMuonGEM , detid.layer());
757  holder = GetDaughter(holder, "Chamber", kMuonGEM , detid.chamber());
758 
759  AddLeafNode(holder, child, name.c_str(), createPlacement(*it));
760  }
761  }
762  }catch (cms::Exception &exception) {
763  edm::LogInfo("FWRecoGeometry") << "failed to produce GEM geometry " << exception.what() << std::endl;
764 
765  }
766 }
767 
768 //______________________________________________________________________________
769 
770 
771 void
773 {
774  TGeoVolume* tv = GetTopHolder("Muon", kMuonRPC);
775  TGeoVolume *assembly = GetDaughter(tv, "RPC", kMuonRPC);
776 
778  const RPCGeometry* rpcGeom = (const RPCGeometry*) m_geomRecord->slaveGeometry( detId );
779  for( auto it = rpcGeom->rolls().begin(),
780  end = rpcGeom->rolls().end();
781  it != end; ++it )
782  {
783  RPCRoll const* roll = (*it);
784  if( roll )
785  {
786  RPCDetId detid = roll->geographicalId();
787  std::stringstream s;
788  s << detid;
789  std::string name = s.str();
790 
791  TGeoVolume* child = createVolume( name, roll, kMuonRPC );
792 
793  TGeoVolume* holder = GetDaughter(assembly, "ROLL Region", kMuonRPC, detid.region());
794  holder = GetDaughter(holder, "Ring", kMuonRPC, detid.ring());
795  holder = GetDaughter(holder, "Station", kMuonRPC, detid.station());
796  holder = GetDaughter(holder, "Sector", kMuonRPC, detid.sector());
797  holder = GetDaughter(holder, "Layer", kMuonRPC, detid.layer());
798  holder = GetDaughter(holder, "Subsector", kMuonRPC, detid.subsector());
799 
800  AddLeafNode(holder, child, name.c_str(), createPlacement(*it));
801  }
802  };
803 }
804 
805 void
807 {
808  TGeoVolume* tv = GetTopHolder("Muon", kMuonME0);
809  TGeoVolume *assembly = GetDaughter(tv, "ME0", kMuonME0);
810 
811  DetId detId( DetId::Muon, 5 );
812  try
813  {
814  const ME0Geometry* me0Geom = (const ME0Geometry*) m_geomRecord->slaveGeometry( detId );
815 
816  for(auto roll : me0Geom->etaPartitions())
817  {
818  if( roll )
819  {
820  unsigned int rawid = roll->geographicalId().rawId();
821  //std::cout << "AMT FWTTTTRecoGeometryES\n" << rawid ;
822 
823  ME0DetId detid(rawid);
824  std::stringstream s;
825  s << detid;
826  std::string name = s.str();
827  TGeoVolume* child = createVolume( name, roll, kMuonME0 );
828 
829  TGeoVolume* holder = GetDaughter(assembly, "Region", kMuonME0, detid.region());
830  holder = GetDaughter(holder, "Layer", kMuonME0, detid.layer());
831  holder = GetDaughter(holder, "Chamber", kMuonME0, detid.chamber());
832  AddLeafNode(holder, child, name.c_str(), createPlacement(roll));
833 
834 
835  }
836  }
837  }
838  catch( cms::Exception &exception )
839  {
840  edm::LogInfo("FWRecoGeometry") << "failed to produce ME0 geometry " << exception.what() << std::endl;
841  }
842 }
843 
844 
845 //==============================================================================
846 //================================= CALO =======================================
847 //==============================================================================
848 
849 
850 void
852 {
853  TGeoVolume* tv = GetTopHolder("HCal", kHCal);
854  TGeoVolume *assembly = GetDaughter(tv, "HCalBarrel", kHCal);
855 
856  std::vector<DetId> vid = m_caloGeom->getValidDetIds(DetId::Hcal, HcalSubdetector::HcalBarrel);
857 
858  CaloVolMap caloShapeMapP;
859  CaloVolMap caloShapeMapN;
860  for( std::vector<DetId>::const_iterator it = vid.begin(), end = vid.end(); it != end; ++it)
861  {
862  HcalDetId detid = HcalDetId(it->rawId());
863 
864  const CaloCellGeometry* cellb= m_caloGeom->getGeometry(*it);
865 
866  const IdealObliquePrism* cell = dynamic_cast<const IdealObliquePrism*> (cellb);
867 
868  if (!cell) { printf ("HB not olique !!!\n"); continue; }
869 
870  TGeoVolume* volume = 0;
871  CaloVolMap& caloShapeMap = (cell->etaPos() > 0) ? caloShapeMapP : caloShapeMapN;
872  CaloVolMap::iterator volIt = caloShapeMap.find(cell->param());
873  if (volIt == caloShapeMap.end())
874  {
875  // printf("FIREWORKS NEW SHAPE BEGIN eta = %f etaPos = %f, phiPos %f >>>>>> \n", cell->eta(), cell->etaPos(), cell->phiPos());
878  IdealObliquePrism::localCorners( lc, cell->param(), ref);
879  HepGeom::Vector3D<float> lCenter;
880  for( int c = 0; c < 8; ++c)
881  lCenter += lc[c];
882  lCenter *= 0.125;
883 
884  static const int arr[] = { 1, 0, 3, 2, 5, 4, 7, 6 };
885  double points[16];
886  for (int c = 0; c < 8; ++c) {
887  if (cell->etaPos() > 0 )
888  points[ c*2 + 0 ] = -(lc[arr[c]].z() - lCenter.z());
889  else
890  points[ c*2 + 0 ] = (lc[arr[c]].z() - lCenter.z());
891 
892  points[ c*2 + 1 ] = (lc[arr[c]].y() - lCenter.y());
893  // printf("AMT xy[%d] <=>[%d] = (%.4f, %.4f) \n", arr[c], c, points[c*2], points[c*2+1]);
894  }
895 
896  float dz = (lc[4].x() -lc[0].x()) * 0.5;
897  TGeoShape* solid = new TGeoArb8(dz, &points[0]);
898  volume = new TGeoVolume("hcal oblique prism", solid, GetMedium(kHCal));
899  caloShapeMap[cell->param()] = volume;
900  }
901  else {
902 
903  volume = volIt->second;
904 
905  }
906 
907  HepGeom::Vector3D<float> gCenter;
908  CaloCellGeometry::CornersVec const & gc = cell->getCorners();
909  for (int c = 0; c < 8; ++c)
910  gCenter += HepGeom::Vector3D<float>(gc[c].x(), gc[c].y(), gc[c].z());
911  gCenter *= 0.125;
912 
913  TGeoTranslation gtr(gCenter.x(), gCenter.y(), gCenter.z());
914  TGeoRotation rot;
915  rot.RotateY(90);
916 
917  TGeoRotation rotPhi;
918  rotPhi.SetAngles(0, -cell->phiPos()*TMath::RadToDeg(), 0);
919  rot.MultiplyBy(&rotPhi);
920 
921  TGeoVolume* holder = GetDaughter(assembly, "side", kHCal, detid.zside());
922  holder = GetDaughter(holder, "ieta", kHCal, detid.ieta());
923  std::stringstream nname;
924  nname << detid;
925  AddLeafNode(holder, volume, nname.str().c_str(), new TGeoCombiTrans(gtr, rot));
926  }
927 
928 
929  // printf("HB map size P = %lu , N = %lu", caloShapeMapP.size(),caloShapeMapN.size() );
930 
931 }
932 //______________________________________________________________________________
933 
934 void
936 {
937 
938  CaloVolMap caloShapeMapP;
939  CaloVolMap caloShapeMapN;
940 
941  TGeoVolume* tv = GetTopHolder("HCal", kHCal);
942  TGeoVolume *assembly = GetDaughter(tv, "HCalEndcap", kHCal);
943 
944  std::vector<DetId> vid = m_caloGeom->getValidDetIds(DetId::Hcal, HcalSubdetector::HcalEndcap);
945 
946  for( std::vector<DetId>::const_iterator it = vid.begin(), end = vid.end(); it != end; ++it)
947  {
948  HcalDetId detid = HcalDetId(it->rawId());
949  const IdealObliquePrism* cell = dynamic_cast<const IdealObliquePrism*> ( m_caloGeom->getGeometry(*it));
950 
951  if (!cell) { printf ("EC not olique \n"); continue; }
952 
953  TGeoVolume* volume = 0;
954  CaloVolMap& caloShapeMap = (cell->etaPos() > 0) ? caloShapeMapP : caloShapeMapN;
955  CaloVolMap::iterator volIt = caloShapeMap.find(cell->param());
956  if ( volIt == caloShapeMap.end())
957  {
960  IdealObliquePrism::localCorners( lc, cell->param(), ref);
961  HepGeom::Vector3D<float> lCenter;
962  for( int c = 0; c < 8; ++c)
963  lCenter += lc[c];
964  lCenter *= 0.125;
965 
966  //for( int c = 0; c < 8; ++c)
967  // printf("lc.push_back(TEveVector(%.4f, %.4f, %.4f));\n", lc[c].x(), lc[c].y(), lc[c].z() );
968 
969 
970  static const int arrP[] = { 3, 2, 1, 0, 7, 6, 5, 4 };
971  static const int arrN[] = { 7, 6, 5, 4 ,3, 2, 1, 0};
972  const int* arr = (detid.ieta() > 0) ? &arrP[0] : &arrN[0];
973 
974  double points[16];
975  for (int c = 0; c < 8; ++c) {
976  points[ c*2 + 0 ] = lc[arr[c]].x() - lCenter.x();
977  points[ c*2 + 1 ] = lc[arr[c]].y() - lCenter.y();
978  }
979 
980  float dz = (lc[4].z() -lc[0].z()) * 0.5;
981  TGeoShape* solid = new TGeoArb8(dz, &points[0]);
982  volume = new TGeoVolume("ecal oblique prism", solid, GetMedium(kHCal));
983  caloShapeMap[cell->param()] = volume;
984  }
985  else {
986 
987  volume = volIt->second;
988 
989  }
990 
991  HepGeom::Vector3D<float> gCenter;
992  CaloCellGeometry::CornersVec const & gc = cell->getCorners();
993  for (int c = 0; c < 8; ++c) {
994  gCenter += HepGeom::Vector3D<float>(gc[c].x(), gc[c].y(), gc[c].z());
995  // printf("gc.push_back(TEveVector(%.4f, %.4f, %.4f));\n", gc[c].x(), gc[c].y(),gc[c].z() );
996  }
997  gCenter *= 0.125;
998 
999  TGeoTranslation gtr(gCenter.x(), gCenter.y(), gCenter.z());
1000  TGeoRotation rot;
1001  rot.SetAngles(cell->phiPos()*TMath::RadToDeg(), 0, 0);
1002 
1003  TGeoVolume* holder = GetDaughter(assembly, "side", kHCal, detid.zside());
1004  holder = GetDaughter(holder, "ieta", kHCal, detid.ieta());
1005  std::stringstream nname;
1006  nname << detid;
1007  AddLeafNode(holder, volume, nname.str().c_str(), new TGeoCombiTrans(gtr, rot));
1008  }
1009 
1010  // printf("HE map size P = %lu , N = %lu", caloShapeMapP.size(),caloShapeMapN.size() );
1011 }
1012 
1013 
1014 //______________________________________________________________________________
1015 
1017 {
1018 
1019  TEveVector gCenter;
1020  for (int i = 0; i < 8; ++i)
1021  gCenter += TEveVector(gc[i].x(), gc[i].y(), gc[i].z());
1022  gCenter *= 0.125;
1023 
1024  TEveVector tgCenter; // top center 4 corners
1025  for (int i = 4; i < 8; ++i)
1026  tgCenter += TEveVector(gc[i].x(), gc[i].y(), gc[i].z());
1027  tgCenter *= 0.25;
1028 
1029 
1030  TEveVector axis = tgCenter - gCenter;
1031  axis.Normalize();
1032 
1033  TEveTrans tr;
1034  TVector3 v1t;
1035  tr.GetBaseVec(1, v1t);
1036 
1037 
1038  TEveVector v1(v1t.x(), v1t.y(), v1t.z());
1039  double dot13 = axis.Dot(v1);
1040  TEveVector gd = axis;
1041  gd*= dot13;
1042  v1 -= gd;
1043  v1.Normalize();
1044  TEveVector v2;
1045  TMath::Cross(v1.Arr(), axis.Arr(), v2.Arr());
1046  TMath::Cross(axis.Arr(), v1.Arr(), v2.Arr());
1047  v2.Normalize();
1048 
1049  tr.SetBaseVec(1, v1.fX, v1.fY, v1.fZ);
1050  tr.SetBaseVec(2, v2.fX, v2.fY, v2.fZ);
1051  tr.SetBaseVec(3, axis.fX, axis.fY, axis.fZ);
1052  tr.Move3PF(gCenter.fX, gCenter.fY, gCenter.fZ);
1053 
1054  TGeoHMatrix* out = new TGeoHMatrix();
1055  tr.SetGeoHMatrix(*out);
1056  return out;
1057 }
1058 
1059 TGeoShape* makeEcalShape(const TruncatedPyramid* cell)
1060 {
1061  // printf("BEGIN EE SHAPE --------------------------------\n");
1062  // std::cout << detid << std::endl;
1063  const HepGeom::Transform3D idtr;
1066  TruncatedPyramid::localCorners( co, cell->param(), ref);
1067  //for( int c = 0; c < 8; ++c)
1068  // printf("lc.push_back(TEveVector(%.4f, %.4f, %.4f));\n", co[c].x(),co[c].y(),co[c].z() );
1069 
1070  double points[16];
1071  for( int c = 0; c < 8; ++c )
1072  {
1073  points[c*2 ] = co[c].x();
1074  points[c*2+1] = co[c].y();
1075  }
1076  TGeoShape* solid = new TGeoArb8(cell->param()[0], points);
1077  return solid;
1078 }
1079 
1080 //______________________________________________________________________________
1081 
1082 
1083 
1084 void
1086 {
1087 
1088  TGeoVolume* tv = GetTopHolder("ECal", kECal);
1089  CaloVolMap caloShapeMap;
1090 
1091  {
1092  TGeoVolume *assembly = GetDaughter(tv, "ECalBarrel", kECal);
1093 
1094  std::vector<DetId> vid = m_caloGeom->getValidDetIds(DetId::Ecal, EcalSubdetector::EcalBarrel);
1095  for( std::vector<DetId>::const_iterator it = vid.begin(), end = vid.end(); it != end; ++it)
1096  {
1097  EBDetId detid(*it);
1098  const TruncatedPyramid* cell = dynamic_cast<const TruncatedPyramid*> ( m_caloGeom->getGeometry( *it ));
1099  if (!cell) { printf("ecalBarrel cell not a TruncatedPyramid !!\n"); return; }
1100 
1101  TGeoVolume* volume = 0;
1102  CaloVolMap::iterator volIt = caloShapeMap.find(cell->param());
1103  if ( volIt == caloShapeMap.end())
1104  {
1105  volume = new TGeoVolume( "EE TruncatedPyramid" , makeEcalShape(cell), GetMedium(kECal));
1106  caloShapeMap[cell->param()] = volume;
1107  }
1108  else {
1109  volume = volIt->second;
1110  }
1111  TGeoHMatrix* mtx= getEcalTrans(cell->getCorners());
1112  TGeoVolume* holder = GetDaughter(assembly, "side", kECal, detid.zside());
1113  holder = GetDaughter(holder, "ieta", kECal, detid.ieta());
1114  std::stringstream nname;
1115  nname << detid;
1116  AddLeafNode(holder, volume, nname.str().c_str(), mtx);
1117  }
1118  }
1119 
1120 
1121  {
1122  TGeoVolume *assembly = GetDaughter(tv, "ECalEndcap", kECal);
1123 
1124  std::vector<DetId> vid = m_caloGeom->getValidDetIds(DetId::Ecal, EcalSubdetector::EcalEndcap);
1125  for( std::vector<DetId>::const_iterator it = vid.begin(), end = vid.end(); it != end; ++it)
1126  {
1127  EEDetId detid(*it);
1128  const TruncatedPyramid* cell = dynamic_cast<const TruncatedPyramid*> (m_caloGeom->getGeometry( *it ));
1129  if (!cell) { printf("ecalEndcap cell not a TruncatedPyramid !!\n"); continue;}
1130 
1131  TGeoVolume* volume = 0;
1132  CaloVolMap::iterator volIt = caloShapeMap.find(cell->param());
1133  if ( volIt == caloShapeMap.end())
1134  {
1135 
1136  volume = new TGeoVolume( "EE TruncatedPyramid" , makeEcalShape(cell), GetMedium(kECal));
1137  caloShapeMap[cell->param()] = volume;
1138  }
1139  else {
1140  volume = volIt->second;
1141  }
1142  TGeoHMatrix* mtx= getEcalTrans(cell->getCorners());
1143  TGeoVolume* holder = GetDaughter(assembly, "side", kECal, detid.zside());
1144  holder = GetDaughter(holder, "ix", kECal, detid.ix());
1145  std::stringstream nname;
1146  nname << detid;
1147  AddLeafNode(holder, volume, nname.str().c_str(), mtx);
1148  }
1149  }
1150 }
1151 
T xx() const
virtual char const * what() const
Definition: Exception.cc:141
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:76
virtual float length() const =0
virtual const std::array< const float, 4 > parameters() const
edm::ESHandle< CaloGeometry > m_caloGeom
JetCorrectorParameters::Record record
Definition: classes.h:7
edm::ESHandle< GlobalTrackingGeometry > m_geomRecord
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.cc:91
TGeoShape * createShape(const GeomDet *det)
float phiPos() const
const std::vector< const RPCRoll * > & rolls() const
Return a vector of all RPC rolls.
Definition: RPCGeometry.cc:67
CaloCellGeometry::Pt3D Pt3D
static const int GEM
Definition: MuonSubdetId.h:15
DTSuperLayerId
T y() const
Definition: PV3DBase.h:63
T yx() const
const Bounds & bounds() const
Definition: Surface.h:120
std::map< TGeoShape *, TGeoVolume * > m_shapeToVolume
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual float thickness() const =0
T zx() const
T xy() const
T zz() const
const CCGFloat * param() const
CaloCellGeometry::Pt3D Pt3D
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
const DetContainer & detsTEC() const
TGeoHMatrix * getEcalTrans(CaloCellGeometry::CornersVec const &gc)
std::map< std::string, TGeoShape * > m_nameToShape
T z() const
Definition: PV3DBase.h:64
CaloCellGeometry::Pt3DVec Pt3DVec
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
const DetContainer & detsPXB() const
int zside() const
Definition: EEDetId.h:70
unsigned int module() const
det id
Definition: PXBDetId.h:43
T zy() const
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM eta partitions.
Definition: GEMGeometry.cc:63
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
#define end
Definition: vmac.h:37
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
T yy() const
std::map< ERecoDet, TGeoMedium * > m_recoMedium
const DetContainer & detsTIB() const
TGeoShape * makeEcalShape(const TruncatedPyramid *cell)
TGeoVolume * GetDaughter(TGeoVolume *mother, const char *prefix, ERecoDet cidx, int id)
const std::vector< ME0EtaPartition const * > & etaPartitions() const
Return a vector of all ME0 eta partitions.
Definition: ME0Geometry.cc:57
Definition: DetId.h:18
double b
Definition: hdecay.h:120
boost::shared_ptr< FWTGeoRecoGeometry > produce(const FWTGeoRecoGeometryRecord &)
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
boost::shared_ptr< FWTGeoRecoGeometry > m_fwGeometry
static const int RPC
Definition: MuonSubdetId.h:14
T xz() const
FWTGeoRecoGeometryESProducer(const edm::ParameterSet &)
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
float etaPos() const
const RotationType & rotation() const
Definition: Bounds.h:22
TGeoVolume * GetTopHolder(const char *prefix, ERecoDet cidx)
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
const PositionType & position() const
T yz() const
CaloCellGeometry::Pt3DVec Pt3DVec
TGeoVolume * createVolume(const std::string &name, const GeomDet *det, ERecoDet=kDummy)
const DetContainer & detsTID() const
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:47