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