DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DDGear.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : F.Gaede
11 //
12 //==========================================================================
13 #include "DDRec/DDGear.h"
14 
15 #include "DD4hep/Detector.h"
16 #include "DD4hep/DD4hepUnits.h"
17 #include "DD4hep/Fields.h"
18 #include "DD4hep/Plugins.h"
19 
20 // ROOT
21 //#include "TGeoManager.h"
22 
23 //---- GEAR ----
24 #include "gear/GEAR.h"
25 #include "gearxml/GearXML.h"
26 
27 #include "gearimpl/Util.h"
28 #include "gearimpl/ConstantBField.h"
29 #include "gearimpl/GearMgrImpl.h"
30 
31 #include "geartgeo/TGeoGearPointProperties.h"
32 #include "geartgeo/TGeoGearDistanceProperties.h"
33 
34 
35 namespace dd4hep{
36  namespace rec{
37  using namespace detail ;
38 
39  gear::GearMgr* createGearMgr( Detector& description , const std::string& pluginName ){
40 
41  int argc(0); char** argv = 0 ;
42 
43  description.apply( pluginName.c_str() , argc, argv) ;
44 
45  DetElement world = description.world() ;
46 
47  gear::GearMgrImpl* gearMgr = new gear::GearMgrImpl() ;
48 
49  gearMgr->setDetectorName( description.header().name() ) ;
50 
51  std::cout << " **** will convert detector " << description.header().name() << " to Gear \n"
52  << " Iterating over all subdetectors: " << std::endl ;
53 
54 
55  //------------------ SubdetectorParamters ----------------------------------
56 
57  std::vector< DetElement > dets ;
58  dets.reserve(1024) ;
59 
60  DetElement::Children chMap = world.children() ;
61 
62  // --- get all DetElements and their children into one vector
63  // ( expect gear parameters to be only at top two levels )
64 
65  for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){
66 
67  DetElement subDet = (*it).second ;
68  dets.push_back( subDet ) ;
69  // std::cout << " *** subdetector : " << subDet.name() << std::endl ;
70 
71  DetElement::Children grCh = subDet.children() ;
72 
73  for ( DetElement::Children::const_iterator jt=grCh.begin() ; jt != grCh.end() ; ++jt ){
74  DetElement jdet = (*jt).second ;
75  dets.push_back( jdet ) ;
76  // std::cout << " *** sub-subdetector : " << subDet.name() << std::endl ;
77  }
78  }
79 
80  for( unsigned i=0, N= dets.size() ; i<N ; ++i){
81 
82  GearHandle* gearH = 0 ;
83 
84  try{
85 
86  gearH = dets[i].extension<GearHandle>() ;
87 
88  std::cout << " *** subdetector " << dets[i].name() << " - found gear object : " << gearH->name() << std::endl ;
89 
90  } catch( std::exception& e) {
91 
92  // std::cout << " *** subdetector " << dets[i].name() << " : " << e.what() << std::endl ;
93 
94  continue ; // with next DetElement
95  }
96 
97  // --- check for canonical names of GearHandle objects :
98  // (fixme: will have to iterate over daughters as well ... )
99 
100  if ( gearH->name() == "TPCParameters" ) { gearMgr->setTPCParameters ( dynamic_cast<gear::TPCParameters* >( gearH->takeGearObject() ) ) ; }
101  else if( gearH->name() == "EcalBarrelParameters" ) { gearMgr->setEcalBarrelParameters( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
102  else if( gearH->name() == "EcalEndcapParameters" ) { gearMgr->setEcalEndcapParameters( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
103  else if( gearH->name() == "EcalPlugParameters" ) { gearMgr->setEcalPlugParameters ( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
104  else if( gearH->name() == "YokeBarrelParameters" ) { gearMgr->setYokeBarrelParameters( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
105  else if( gearH->name() == "YokeEndcapParameters" ) { gearMgr->setYokeEndcapParameters( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
106  else if( gearH->name() == "YokePlugParameters" ) { gearMgr->setYokePlugParameters ( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
107  else if( gearH->name() == "HcalBarrelParameters" ) { gearMgr->setHcalBarrelParameters( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
108  else if( gearH->name() == "HcalEndcapParameters" ) { gearMgr->setHcalEndcapParameters( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
109  else if( gearH->name() == "HcalRingParameters" ) { gearMgr->setHcalRingParameters ( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
110  else if( gearH->name() == "LcalParameters" ) { gearMgr->setLcalParameters ( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
111  else if( gearH->name() == "LHcalParameters" ) { gearMgr->setLHcalParameters ( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
112  else if( gearH->name() == "BeamCalParameters" ) { gearMgr->setBeamCalParameters ( dynamic_cast<gear::CalorimeterParameters* >( gearH->takeGearObject() ) ) ; }
113  else if( gearH->name() == "VXDParameters" ) { gearMgr->setVXDParameters ( dynamic_cast<gear::ZPlanarParameters* >( gearH->takeGearObject() ) ) ; }
114  else if( gearH->name() == "FTDParameters" ) { gearMgr->setFTDParameters ( dynamic_cast<gear::FTDParameters* >( gearH->takeGearObject() ) ) ; }
115  else if( gearH->name() == "SITParameters" ) { gearMgr->setSITParameters ( dynamic_cast<gear::ZPlanarParameters* >( gearH->takeGearObject() ) ) ; }
116  else if( gearH->name() == "SETParameters" ) { gearMgr->setSETParameters ( dynamic_cast<gear::ZPlanarParameters* >( gearH->takeGearObject() ) ) ; }
117  else if( gearH->name() == "SiPlanesParameters" ) { gearMgr->setSiPlanesParameters ( dynamic_cast<gear::SiPlanesParameters* >( gearH->takeGearObject() ) ) ; }
118  else {
119 
120  gearMgr->setGearParameters( gearH->name() , gearH->takeGearObject() ) ;
121  }
122 
123 
125 
126  for( unsigned j=0, M=gearH->materials().size() ; j<M ; ++j) {
127 
128  gearMgr->registerSimpleMaterial( &gearH->materials()[j] ) ;
129  }
130 
131 
132  }
133  std::cout << std::endl ;
134 
135  //------------------ Bfield ----------------------------------
136 
137  // fixme: for now we just assume a constant field - should be a real field map ...
138  double origin[3] = { 0., 0., 0. } ;
139  double bfield[3] ;
140  OverlayedField ovField = description.field() ;
141  ovField.magneticField( origin , bfield ) ;
142 
143  gearMgr->setBField( new gear::ConstantBField( gear::Vector3D( bfield[0]/ dd4hep::tesla , bfield[1]/ dd4hep::tesla , bfield[2] / dd4hep::tesla ) ) ) ;
144 
145 
146  //----------------- PointProperties and DistanceProperties -------------------------
147 
148  TGeoManager *geoManager = world.volume()->GetGeoManager();
149 
150  gearMgr->setPointProperties( new gear::TGeoGearPointProperties( geoManager ) ) ;
151 
152  gearMgr->setDistanceProperties( new gear::TGeoGearDistanceProperties( geoManager ) ) ;
153 
154  //----------------------------------------------------------------------------------
155 
156  return gearMgr ;
157 
158  }
159 
160  }}
161 
dd4hep::DetElement::children
const Children & children() const
Access to the list of children.
Definition: DetElement.cpp:207
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
Detector.h
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
dd4hep::rec::GearHandle::takeGearObject
gear::GearParametersImpl * takeGearObject()
Definition: DDGear.h:68
dd4hep::OverlayedField
Class describing a field overlay with several sources.
Definition: Fields.h:138
dd4hep::Header::name
const std::string name() const
Accessor to object name.
Definition: Objects.cpp:68
dd4hep::rec::GearHandle::name
const std::string & name()
Definition: DDGear.h:62
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
DDGear.h
dd4hep::DetElement::volume
Volume volume() const
Access to the logical volume of the detector element's placement.
Definition: DetElement.cpp:352
dd4hep::Detector::apply
virtual long apply(const char *factory, int argc, char **argv) const =0
Manipulate geometry using factory converter.
dd4hep::Detector::field
virtual OverlayedField field() const =0
Return handle to the combined electromagentic field description.
dd4hep::rec::createGearMgr
gear::GearMgr * createGearMgr(Detector &description, const std::string &pluginName="GearForILD")
Definition: DDGear.cpp:39
dd4hep::rec::GearHandle
Definition: DDGear.h:40
Plugins.h
dd4hep::rec::GearHandle::materials
const std::vector< gear::SimpleMaterialImpl > & materials()
get all materials assigned to this wrapper
Definition: DDGear.h:82
dd4hep::DetElement::Children
std::map< std::string, DetElement > Children
Definition: DetElement.h:206
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::OverlayedField::magneticField
void magneticField(const Position &pos, double *field) const
Returns the 3 magnetic field components (x, y, z).
Definition: Fields.cpp:140
DD4hepUnits.h
Fields.h
dd4hep::Detector::header
virtual Header header() const =0
Accessor to the map of header entries.