DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
createGearForSiD.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 "DD4hep/Detector.h"
14 #include "DD4hep/Factories.h"
15 #include "DD4hep/DD4hepUnits.h"
16 
17 #include "DDRec/DetectorData.h"
18 #include "DDRec/DDGear.h"
19 #include "DDRec/MaterialManager.h"
20 
21 #include "DDRec/Vector3D.h"
22 
23 #include "gearimpl/TPCParametersImpl.h"
24 #include "gearimpl/FixedPadSizeDiskLayout.h"
25 #include "gearimpl/ZPlanarParametersImpl.h"
26 #include "gearimpl/FTDParametersImpl.h"
27 #include "gearimpl/CalorimeterParametersImpl.h"
28 
29 #include <iostream>
30 
31 namespace dd4hep{
32  namespace rec{
33 
34  using namespace detail ;
35 
53  static long createGearForSiD(Detector& description, int /*argc*/, char** /*argv*/) {
54 
55  std::cout << " **** running plugin createGearForSiD ! " << std::endl ;
56 
57  try {
58 
59  DetElement coilDE = description.detector("Solenoid") ;
60 
61  gear::GearParametersImpl* gearCOIL = new gear::GearParametersImpl();
62 
63  Tube coilTube = Tube( coilDE.volume().solid() ) ;
64 
65  gearCOIL->setDoubleVal("Coil_cryostat_inner_radius" , coilTube->GetRmin()/ dd4hep::mm ) ;
66  gearCOIL->setDoubleVal("Coil_cryostat_outer_radius" , coilTube->GetRmax()/ dd4hep::mm ) ;
67  gearCOIL->setDoubleVal("Coil_cryostat_half_z" , coilTube->GetDZ()/ dd4hep::mm ) ;
68 
69  coilDE.addExtension< GearHandle >( new GearHandle( gearCOIL, "CoilParameters" ) ) ;
70 
71  } catch( std::runtime_error& e ){
72  std::cerr << " >>>> " << e.what() << std::endl ;
73  }
74 
75  //========= CALO ONLY ==============================================================
76 
77  //**********************************************************
78  //* gear interface w/ LayeredCalorimeterData extension
79  //**********************************************************
80 
81  std::map< std::string, std::string > caloMap ;
82  caloMap["HCalBarrel"] = "HcalBarrelParameters" ;
83  caloMap["HCalEndcap"] = "HcalEndcapParameters" ;
84  caloMap["ECalBarrel"] = "EcalBarrelParameters" ;
85  caloMap["ECalEndcap"] = "EcalEndcapParameters" ;
86  caloMap["MuonBarrel"] = "YokeBarrelParameters" ;
87  caloMap["MuonEndcap"] = "YokeEndcapParameters" ;
88  caloMap["LumiCal"] = "LcalParameters" ;
89  caloMap["BeamCal"] = "BeamCalParameters" ;
90 
91  for( std::map< std::string, std::string >::const_iterator it = caloMap.begin() ; it != caloMap.end() ; ++it ){
92 
93  try {
94 
95  DetElement caloDE = description.detector( it->first ) ;
96 
97  LayeredCalorimeterData* calo = caloDE.extension<LayeredCalorimeterData>() ;
98 
99  gear::CalorimeterParametersImpl* gearCalo =
100  ( calo->layoutType == LayeredCalorimeterData::BarrelLayout ?
101  new gear::CalorimeterParametersImpl( calo->extent[0]/dd4hep::mm, calo->extent[3]/dd4hep::mm, calo->inner_symmetry, calo->inner_phi0 ) :
102  //CalorimeterParametersImpl (double rMin, double zMax, int symOrder=8, double phi0=0.0) - C'tor for a cylindrical (octagonal) BARREL calorimeter.
103  new gear::CalorimeterParametersImpl( calo->extent[0]/dd4hep::mm, calo->extent[1]/dd4hep::mm, calo->extent[2]/dd4hep::mm, calo->outer_symmetry, calo->outer_phi0 ) ) ;
104  //CalorimeterParametersImpl (double rMin, double rMax, double zMin, int symOrder=2, double phi0=0.0) - C'tor for a cylindrical (octagonal) ENDCAP calorimeter.
105 
106  for( unsigned i=0, nL = calo->layers.size() ; i <nL ; ++i ){
107 
108  LayeredCalorimeterData::Layer& l = calo->layers[i] ;
109 
110  //Do some arithmetic to get thicknesses and (approximate) absorber thickneses from "new" rec structures
111  //The positioning should come out right, but the absorber thickness should be overestimated due to the presence of
112  //other less dense material
113  if( i == 0 ) {
114  //First layer is positioned with only its inner thickness taken into account
115  gearCalo->layerLayout().positionLayer( l.distance/dd4hep::mm, (l.inner_thickness+l.sensitive_thickness/2.)/dd4hep::mm ,
116  l.cellSize0/dd4hep::mm, l.cellSize1/dd4hep::mm, (l.inner_thickness-l.sensitive_thickness/2.)/dd4hep::mm ) ;
117  } else if ( i == nL -1 ) {
118  //Need to handle outermost layer differently; add its outer thickness
119  //This gives the right extent, but the "wrong" distance for the last layer
120  gearCalo->layerLayout().addLayer((l.inner_thickness+l.outer_thickness+calo->layers[i-1].outer_thickness-calo->layers[i-1].sensitive_thickness/2.)/dd4hep::mm ,
121  l.cellSize0/dd4hep::mm, l.cellSize1/dd4hep::mm, (l.inner_thickness+l.outer_thickness-l.sensitive_thickness+calo->layers[i-1].outer_thickness-calo->layers[i-1].sensitive_thickness/2.)/dd4hep::mm) ;
122  } else {
123  //All other layers need to be added taking into account the previous layer outer thicknesses
124  gearCalo->layerLayout().addLayer((l.inner_thickness+l.sensitive_thickness/2.+calo->layers[i-1].outer_thickness-calo->layers[i-1].sensitive_thickness/2.)/dd4hep::mm ,
125  l.cellSize0/dd4hep::mm, l.cellSize1/dd4hep::mm, (l.inner_thickness-l.sensitive_thickness/2.+calo->layers[i-1].outer_thickness-calo->layers[i-1].sensitive_thickness/2.)/dd4hep::mm) ;
126  }
127  }
128 
129  if( it->first == "HCalBarrel" ){
130  // additional parameters needed by MarlinPandora
131  gearCalo->setIntVal("Hcal_outer_polygon_order" , calo->outer_symmetry ) ;
132  gearCalo->setDoubleVal("Hcal_outer_polygon_phi0" , calo->outer_phi0 ) ;
133  }
134 
135  caloDE.addExtension< GearHandle >( new GearHandle( gearCalo, it->second ) ) ;
136 
137  } catch( std::runtime_error& e ){
138  std::cerr << " >>>> " << e.what() << std::endl ;
139  }
140 
141  } // calo loop
142 
143  // --- Detector::apply() expects return code 1 if all went well ! ----
144  return 1;
145  }
146  }
147 }
148 DECLARE_APPLY( GearForSiD, dd4hep::rec::createGearForSiD )
149 
150 
DetectorData.h
Detector.h
DECLARE_APPLY
#define DECLARE_APPLY(name, func)
Definition: Factories.h:281
Factories.h
dd4hep::rec::LayeredCalorimeterData
StructExtension< LayeredCalorimeterStruct > LayeredCalorimeterData
Definition: DetectorData.h:472
DDGear.h
gear
Definition: DDGear.h:24
MaterialManager.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
DD4hepUnits.h
Vector3D.h