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