DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
createGearForCLIC.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 
47  static long createGearForCLIC(Detector& description, int /*argc*/, char** /*argv*/) {
48 
49  std::cout << " **** running plugin createGearForCLIC ! " << std::endl ;
50 
51 
52  //========= VXD ==============================================================================
53 
54  try{
55  DetElement vxdDE = description.detector("VertexBarrel") ;
56 
57  ZPlanarData* vxd = vxdDE.extension<ZPlanarData>() ;
58 
59  // ZPlanarParametersImpl (int type, double shellInnerRadius, double shellOuterRadius, double shellHalfLength, double shellGap, double shellRadLength)
60  int vxdType = gear::ZPlanarParameters::CMOS ;
61  gear::ZPlanarParametersImpl* gearVXD = new gear::ZPlanarParametersImpl( vxdType, vxd->rInnerShell/dd4hep::mm, vxd->rOuterShell/dd4hep::mm,
62  vxd->zHalfShell/dd4hep::mm , vxd->gapShell/dd4hep::mm , 0. ) ;
63 
64 // std::cout<<"Got "<<vxd->layers.size()<<" layers."<<std::endl;
65  for(unsigned i=0,n=vxd->layers.size() ; i<n; ++i){
66 // std::cout<<"Working on layer "<<i<<" for a total of "<<n<<" layers."<<std::endl;
67 
68  const rec::ZPlanarData::LayerLayout& l = vxd->layers[i] ;
69 
70  // FIXME set rad lengths to 0 -> need to get from dd4hep ....
71  gearVXD->addLayer( l.ladderNumber, l.phi0,
72  l.distanceSupport/dd4hep::mm, l.offsetSupport/dd4hep::mm, l.thicknessSupport/dd4hep::mm, l.zHalfSupport/dd4hep::mm, l.widthSupport/dd4hep::mm, 0. ,
73  l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l.thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. ) ;
74 
75  }
76 
77  std::cout<<"Added layers"<<std::endl;
78 
79  GearHandle* handle = new GearHandle( gearVXD, "VXDParameters" ) ;
80 
81  // quick hack for now: add the one material that is needed by KalDet :
82  handle->addMaterial( "VXDSupportMaterial", 2.075865162e+01, 1.039383117e+01, 2.765900000e+02, 1.014262421e+03, 3.341388059e+03) ;
83 
84  // -------- better: get right averaged material from first ladder: ------------------
85 // MaterialManager matMgr ;
86 //
87 // const rec::ZPlanarData::LayerLayout& l = vxd->layers[0] ;
88 //
89 // Vector3D a( l.distanceSupport , l.phi0 , 0. , Vector3D::cylindrical ) ;
90 // Vector3D b( l.distanceSupport + l.thicknessSupport , l.phi0 , 0. , Vector3D::cylindrical ) ;
91 //
92 // const MaterialVec& materials = matMgr.materialsBetween( a , b ) ;
93 //
94 // std::cout<<"Calculating material average."<<std::endl;
95 // MaterialData mat = ( materials.size() > 1 ? matMgr.createAveragedMaterial( materials ) : materials[0].first ) ;
96 //
97 // std::cout << " ####### found materials between points : " << a << " and " << b << " : " ;
98 // for( unsigned i=0,n=materials.size();i<n;++i){
99 // std::cout << materials[i].first.name() << "[" << materials[i].second << "], " ;
100 // }
101 // std::cout << std::endl ;
102 // std::cout << " averaged material : " << mat << std::endl ;
103 //
104 // handle->addMaterial( "VXDSupportMaterial", mat.A(), mat.Z() , mat.density()/(dd4hep::kg/(dd4hep::g*dd4hep::m3)) , mat.radiationLength()/dd4hep::mm , mat.interactionLength()/dd4hep::mm ) ;
105 
106 
107  vxdDE.addExtension< GearHandle >( handle ) ;
108 
109  } catch( std::runtime_error& e ){
110  std::cerr << " >>>> " << e.what() << std::endl ;
111  }
112 
113  //========= SIT ==============================================================================
114 
115  try{
116 
117  DetElement sitDE = description.detector("InnerTrackerBarrel") ;
118 
119  ZPlanarData* sit = sitDE.extension<ZPlanarData>() ;
120 
121  // ZPlanarParametersImpl (int type, double shellInnerRadius, double shellOuterRadius, double shellHalfLength, double shellGap, double shellRadLength)
122  int sitType = gear::ZPlanarParameters::CCD ;
123 
124  gear::ZPlanarParametersImpl* gearSIT = new gear::ZPlanarParametersImpl( sitType, sit->rInnerShell/dd4hep::mm, sit->rOuterShell/dd4hep::mm,
125  sit->zHalfShell/dd4hep::mm , sit->gapShell/dd4hep::mm , 0. ) ;
126 
127  std::vector<int> n_sensors_per_ladder ;
128 
129  for(unsigned i=0,n=sit->layers.size() ; i<n; ++i){
130 
131  const rec::ZPlanarData::LayerLayout& l = sit->layers[i] ;
132 
133  // FIXME set rad lengths to 0 -> need to get from dd4hep ....
134  gearSIT->addLayer( l.ladderNumber, l.phi0,
135  l.distanceSupport/dd4hep::mm, l.offsetSupport/dd4hep::mm, l. thicknessSupport/dd4hep::mm, l.zHalfSupport/dd4hep::mm, l.widthSupport/dd4hep::mm, 0. ,
136  l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l. thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. ) ;
137 
138 
139  n_sensors_per_ladder.push_back( l.sensorsPerLadder);
140  }
141 
142  gearSIT->setDoubleVal("strip_width_mm" , sit->widthStrip / dd4hep::mm ) ;
143  gearSIT->setDoubleVal("strip_length_mm" , sit->lengthStrip/ dd4hep::mm ) ;
144  gearSIT->setDoubleVal("strip_pitch_mm" , sit->pitchStrip / dd4hep::mm ) ;
145  gearSIT->setDoubleVal("strip_angle_deg" , sit->angleStrip / dd4hep::deg ) ;
146 
147 
148  gearSIT->setIntVals("n_sensors_per_ladder",n_sensors_per_ladder);
149 
150  sitDE.addExtension< GearHandle >( new GearHandle( gearSIT, "SITParameters" ) ) ;
151 
152  } catch( std::runtime_error& e ){
153  std::cerr << " >>>> " << e.what() << std::endl ;
154  }
155 
156  //============================================================================================
157 
158  try {
159 
160  DetElement setDE = description.detector("OuterTrackerBarrel") ;
161 
162  ZPlanarData* set = setDE.extension<ZPlanarData>() ;
163 
164  // ZPlanarParametersImpl (int type, double shellInnerRadius, double shellOuterRadius, double shellHalfLength, double shellGap, double shellRadLength)
165  int setType = gear::ZPlanarParameters::CCD ;
166  gear::ZPlanarParametersImpl* gearSET = new gear::ZPlanarParametersImpl( setType, set->rInnerShell/dd4hep::mm, set->rOuterShell/dd4hep::mm,
167  set->zHalfShell/dd4hep::mm , set->gapShell/dd4hep::mm , 0. ) ;
168  std::vector<int> n_sensors_per_ladder ;
169  //n_sensors_per_ladder.clear() ;
170 
171  for(unsigned i=0,n=set->layers.size() ; i<n; ++i){
172 
173  const rec::ZPlanarData::LayerLayout& l = set->layers[i] ;
174 
175  // FIXME set rad lengths to 0 -> need to get from dd4hep ....
176  gearSET->addLayer( l.ladderNumber, l.phi0,
177  l.distanceSupport/dd4hep::mm, l.offsetSupport/dd4hep::mm, l. thicknessSupport/dd4hep::mm, l.zHalfSupport/dd4hep::mm, l.widthSupport/dd4hep::mm, 0. ,
178  l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l. thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. ) ;
179 
180 
181  n_sensors_per_ladder.push_back( l.sensorsPerLadder);
182  }
183 
184  gearSET->setDoubleVal("strip_width_mm" , set->widthStrip / dd4hep::mm ) ;
185  gearSET->setDoubleVal("strip_length_mm" , set->lengthStrip/ dd4hep::mm ) ;
186  gearSET->setDoubleVal("strip_pitch_mm" , set->pitchStrip / dd4hep::mm ) ;
187  gearSET->setDoubleVal("strip_angle_deg" , set->angleStrip / dd4hep::deg ) ;
188 
189 
190  gearSET->setIntVals("n_sensors_per_ladder",n_sensors_per_ladder);
191 
192  setDE.addExtension< GearHandle >( new GearHandle( gearSET, "SETParameters" ) ) ;
193 
194  } catch( std::runtime_error& e ){
195  std::cerr << " >>>> " << e.what() << std::endl ;
196  }
197 
198  //============================================================================================
199 
200  try {
201 
202  DetElement iteDE = description.detector("InnerTrackerEndcap") ;
203 
204  ZDiskPetalsData* iteData = iteDE.extension<ZDiskPetalsData>() ;
205 
206  gear::GearParametersImpl* gearFTD = new gear::GearParametersImpl();
207 
208  std::vector<double> thicknesses;
209  std::vector<double> innerRadii;
210  std::vector<double> outerRadii;
211  std::vector<double> zPositions;
212 
213 
214  for(unsigned i=0,n=iteData->layers.size() ; i<n; ++i){
215 
216  const rec::ZDiskPetalsData::LayerLayout& l = iteData->layers[i] ;
217 
218  thicknesses.push_back(l.thicknessSupport/ dd4hep::mm);
219  innerRadii.push_back( l.distanceSensitive/ dd4hep::mm);
220  outerRadii.push_back( (l.distanceSensitive + l.lengthSensitive)/ dd4hep::mm);
221  zPositions.push_back( l.zPosition/ dd4hep::mm);
222 
223 
224 
225  }
226 
227 
228  //Append OuterTracker
229  DetElement oteDE = description.detector("OuterTrackerEndcap") ;
230  ZDiskPetalsData* oteData = oteDE.extension<ZDiskPetalsData>() ;
231 
232 
233  for(unsigned i=0,n=oteData->layers.size() ; i<n; ++i){
234 
235  const rec::ZDiskPetalsData::LayerLayout& l = oteData->layers[i] ;
236 
237  thicknesses.push_back(l.thicknessSupport/ dd4hep::mm);
238  innerRadii.push_back( l.distanceSensitive/ dd4hep::mm);
239  outerRadii.push_back( (l.distanceSensitive + l.lengthSensitive)/ dd4hep::mm);
240  zPositions.push_back( l.zPosition/ dd4hep::mm);
241 
242 
243 
244  }
245 
246 
247  gearFTD->setDoubleVals("FTDDiskSupportThickness" , thicknesses) ;
248  gearFTD->setDoubleVals("FTDInnerRadius" , innerRadii) ;
249  gearFTD->setDoubleVals("FTDOuterRadius" , outerRadii ) ;
250  gearFTD->setDoubleVals("FTDZCoordinate" ,zPositions) ;
251 
252  //attach gear handle to inner tracker
253  iteDE.addExtension< GearHandle >( new GearHandle( gearFTD, "FTD" ) ) ;
254 
255 
256  } catch( std::runtime_error& e ){
257  std::cerr << " >>>> " << e.what() << std::endl ;
258  }
259 
260  //============================================================================================
261 
262  try {
263 
264  DetElement coilDE = description.detector("Solenoid") ;
265 
266  gear::GearParametersImpl* gearCOIL = new gear::GearParametersImpl();
267 
268  Tube coilTube = Tube( coilDE.volume().solid() ) ;
269 
270  gearCOIL->setDoubleVal("Coil_cryostat_inner_radius" , coilTube->GetRmin()/ dd4hep::mm ) ;
271  gearCOIL->setDoubleVal("Coil_cryostat_outer_radius" , coilTube->GetRmax()/ dd4hep::mm ) ;
272  gearCOIL->setDoubleVal("Coil_cryostat_half_z" , coilTube->GetDZ()/ dd4hep::mm ) ;
273 
274  coilDE.addExtension< GearHandle >( new GearHandle( gearCOIL, "CoilParameters" ) ) ;
275 
276  } catch( std::runtime_error& e ){
277  std::cerr << " >>>> " << e.what() << std::endl ;
278  }
279 
280  //============================================================================================
281  try {
282 
283  DetElement tubeDE = description.detector("Tube") ;
284 
285  ConicalSupportData* tube = tubeDE.extension<ConicalSupportData>() ;
286 
287  gear::GearParametersImpl* gearTUBE = new gear::GearParametersImpl();
288 
289  tube->isSymmetricInZ = true ;
290 
291  unsigned n = tube->sections.size() ;
292 
293  std::vector<double> rInner(n) ;
294  std::vector<double> rOuter(n) ;
295  std::vector<double> zStart(n) ;
296 
297  for(unsigned i=0 ; i<n ; ++i){
298 
299  const ConicalSupportData::Section& s = tube->sections[i] ;
300 
301  rInner[i] = s.rInner/ dd4hep::mm ;
302  rOuter[i] = s.rOuter/ dd4hep::mm ;
303  zStart[i] = s.zPos / dd4hep::mm ;
304 
305  // FIXME set rad lengths to 0 -> need to get from dd4hep ....
306  }
307 
308  gearTUBE->setDoubleVals("RInner" , rInner ) ;
309  gearTUBE->setDoubleVals("ROuter" , rOuter ) ;
310  gearTUBE->setDoubleVals("Z" , zStart ) ;
311 
312 
313  tubeDE.addExtension< GearHandle >( new GearHandle( gearTUBE, "Beampipe" ) ) ;
314 
315  } catch( std::runtime_error& e ){
316  std::cerr << " >>>> " << e.what() << std::endl ;
317  }
318 
319  //========= CALO ==============================================================================
320 
321  //**********************************************************
322  //* gear interface w/ LayeredCalorimeterData extension
323  //**********************************************************
324 
325  std::map< std::string, std::string > caloMap ;
326  caloMap["HCalBarrel"] = "HcalBarrelParameters" ;
327  caloMap["ECalBarrel"] = "EcalBarrelParameters" ;
328  caloMap["ECalEndcap"] = "EcalEndcapParameters" ;
329  caloMap["ECalPlug"] = "EcalPlugParameters" ;
330  caloMap["YokeBarrel"] = "YokeBarrelParameters" ;
331  caloMap["YokeEndcap"] = "YokeEndcapParameters" ;
332  caloMap["YokePlug"] = "YokePlugParameters" ;
333  caloMap["HCalBarrel"] = "HcalBarrelParameters" ;
334  caloMap["HCalEndcap"] = "HcalEndcapParameters" ;
335  caloMap["HCalRing"] = "HcalRingParameters" ;
336  caloMap["LumiCal"] = "LcalParameters" ;
337 // caloMap["LHCal"] = "LHcalParameters" ;
338  caloMap["BeamCal"] = "BeamCalParameters" ;
339 
340  for( std::map< std::string, std::string >::const_iterator it = caloMap.begin() ; it != caloMap.end() ; ++it ){
341 
342 
343 
344  try {
345 
346  DetElement caloDE = description.detector( it->first ) ;
347 
348  LayeredCalorimeterData* calo = caloDE.extension<LayeredCalorimeterData>() ;
349 
350  gear::CalorimeterParametersImpl* gearCalo =
351  ( calo->layoutType == LayeredCalorimeterData::BarrelLayout ?
352  new gear::CalorimeterParametersImpl( calo->extent[0]/dd4hep::mm, calo->extent[3]/dd4hep::mm, calo->inner_symmetry, calo->inner_phi0 ) :
353  //CalorimeterParametersImpl (double rMin, double zMax, int symOrder=8, double phi0=0.0) - C'tor for a cylindrical (octagonal) BARREL calorimeter.
354  new gear::CalorimeterParametersImpl( calo->extent[0]/dd4hep::mm, calo->extent[1]/dd4hep::mm, calo->extent[2]/dd4hep::mm, calo->outer_symmetry, calo->outer_phi0 ) ) ;
355  //CalorimeterParametersImpl (double rMin, double rMax, double zMin, int symOrder=2, double phi0=0.0) - C'tor for a cylindrical (octagonal) ENDCAP calorimeter.
356 
357  for( unsigned i=0, nL = calo->layers.size() ; i <nL ; ++i ){
358 
359  LayeredCalorimeterData::Layer& l = calo->layers[i] ;
360 
361 
362  //Do some arithmetic to get thicknesses and (approximate) absorber thickneses from "new" rec structures
363  //The positioning should come out right, but the absorber thickness should be overestimated due to the presence of
364  //other less dense material
365  if( i == 0 ) {
366  //First layer is positioned with only its inner thickness taken into account
367  gearCalo->layerLayout().positionLayer( l.distance/dd4hep::mm, (l.inner_thickness+l.sensitive_thickness/2.)/dd4hep::mm ,
368  l.cellSize0/dd4hep::mm, l.cellSize1/dd4hep::mm, (l.inner_thickness-l.sensitive_thickness/2.)/dd4hep::mm ) ;
369  }else if ( i == nL -1 ) {
370  //Need to handle outermost layer differently; add its outer thickness
371  //This gives the right extent, but the "wrong" distance for the last layer
372  gearCalo->layerLayout().addLayer((l.inner_thickness+l.outer_thickness+calo->layers[i-1].outer_thickness-calo->layers[i-1].sensitive_thickness/2.)/dd4hep::mm ,
373  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) ;
374  }else{
375  //All other layers need to be added taking into account the previous layer outer thicknesses
376  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 ,
377  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) ;
378  }
379 
380  }
381 
382  if( it->first == "HCalBarrel" ){
383  // additional parameters needed by MarlinPandora
384  gearCalo->setIntVal("Hcal_outer_polygon_order" , calo->outer_symmetry ) ;
385  gearCalo->setDoubleVal("Hcal_outer_polygon_phi0" , calo->outer_phi0 ) ;
386  }
387 
388 
389 
390  caloDE.addExtension< GearHandle >( new GearHandle( gearCalo, it->second ) ) ;
391 
392  } catch( std::runtime_error& e ){
393  std::cerr << " >>>> " << e.what() << std::endl ;
394 
395  }
396 
397  } // calo loop
398 
399 
400 
401  //**********************************************************
402  //* test gear interface w/ LayeredExtensionImpl extension
403  //**********************************************************
404 
405  // DetElement calo2DE = description.detector("EcalBarrel") ;
406 
407  // Calorimeter calo2( calo2DE ) ;
408 
409  // gear::CalorimeterParametersImpl* gearCalo2 =
410  // ( calo2.isBarrel() ?
411  // new gear::CalorimeterParametersImpl( calo2.getRMin()/dd4hep::mm, calo2.getZMax()/dd4hep::mm, calo2.getNSides(), 0. ) : // fixme: phi 0 is not defined ??
412  // new gear::CalorimeterParametersImpl( calo2.getRMin()/dd4hep::mm, calo2.getRMax()/dd4hep::mm, calo2.getZMin()/dd4hep::mm, calo2.getNSides(), 0. )
413  // ) ;
414 
415  // for( unsigned i=0, nL = calo2.numberOfLayers() ; i <nL ; ++i ){
416 
417  // if( i == 0 ) {
418  // gearCalo2->layerLayout().positionLayer( calo2.getRMin()/dd4hep::mm, calo2.thickness(i)/dd4hep::mm , 0. /dd4hep::mm, 0. /dd4hep::mm, calo2.absorberThickness(i)/dd4hep::mm ) ;
419 
420  // }else{ // fixme: cell sizes not in API !?
421 
422  // gearCalo2->layerLayout().addLayer( calo2.thickness(i)/dd4hep::mm , 0. /dd4hep::mm, 0. /dd4hep::mm, calo2.absorberThickness(i)/dd4hep::mm ) ;
423  // }
424 
425 
426  // }
427 
428  // calo2DE.addExtension< GearHandle >( new GearHandle( gearCalo2, "EcalBarrelParameters" ) ) ;
429 
430 
431  //============================================================================================
432 
433 
434 
435  // --- Detector::apply() expects return code 1 if all went well ! ----
436  return 1;
437  }
438  }
439 }
440 DECLARE_APPLY( GearForCLIC, dd4hep::rec::createGearForCLIC )
441 
442 
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
dd4hep::rec::ConicalSupportData
StructExtension< ConicalSupportStruct > ConicalSupportData
Definition: DetectorData.h:345
gear
Definition: DDGear.h:24
dd4hep::rec::ZDiskPetalsData
StructExtension< ZDiskPetalsStruct > ZDiskPetalsData
Definition: DetectorData.h:302
dd4hep::rec::ZPlanarData
StructExtension< ZPlanarStruct > ZPlanarData
Definition: DetectorData.h:184
MaterialManager.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
DD4hepUnits.h
Vector3D.h
handle
void handle(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1105