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