File indexing completed on 2025-01-18 09:14:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include "DD4hep/Detector.h"
0014 #include "DD4hep/Factories.h"
0015 #include "DD4hep/DD4hepUnits.h"
0016
0017 #include "DDRec/DetectorData.h"
0018 #include "DDRec/DDGear.h"
0019 #include "DDRec/MaterialManager.h"
0020
0021 #include "DDRec/Vector3D.h"
0022
0023 #include "DDSegmentation/Segmentation.h"
0024
0025 #include "gearimpl/TPCParametersImpl.h"
0026 #include "gearimpl/FixedPadSizeDiskLayout.h"
0027 #include "gearimpl/ZPlanarParametersImpl.h"
0028 #include "gearimpl/FTDParametersImpl.h"
0029 #include "gearimpl/CalorimeterParametersImpl.h"
0030
0031 #include <iostream>
0032
0033 namespace dd4hep{
0034 namespace rec{
0035
0036 using namespace detail ;
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 static long createGearForILD(Detector& description, int , char** ) {
0050
0051 std::cout << " **** running plugin createGearForILD ! " << std::endl ;
0052
0053
0054
0055
0056
0057 double crossing_angle(0.) ;
0058 try{ crossing_angle = description.constant<double>("ILC_Main_Crossing_Angle") ; } catch(std::runtime_error&e) {std::cerr << " >>>> " << e.what() << std::endl ;}
0059
0060
0061
0062 try{
0063
0064 DetElement tpcDE = description.detector("TPC") ;
0065
0066 FixedPadSizeTPCData* tpc = tpcDE.extension<FixedPadSizeTPCData>() ;
0067
0068 gear::TPCParametersImpl* gearTPC = new gear::TPCParametersImpl( tpc->driftLength /dd4hep::mm , gear::PadRowLayout2D::POLAR ) ;
0069
0070 gearTPC->setPadLayout( new gear::FixedPadSizeDiskLayout( tpc->rMinReadout/dd4hep::mm , tpc->rMaxReadout/dd4hep::mm, tpc->padHeight/dd4hep::mm,
0071 tpc->padWidth/dd4hep::mm , tpc->maxRow, tpc->padGap /dd4hep::mm ) ) ;
0072
0073 gearTPC->setDoubleVal("tpcInnerRadius", tpc->rMin/dd4hep::mm ) ;
0074 gearTPC->setDoubleVal("tpcOuterRadius", tpc->rMax/dd4hep::mm ) ;
0075 gearTPC->setDoubleVal("tpcInnerWallThickness", tpc->innerWallThickness/dd4hep::mm ) ;
0076 gearTPC->setDoubleVal("tpcOuterWallThickness", tpc->outerWallThickness/dd4hep::mm ) ;
0077
0078 tpcDE.addExtension< GearHandle >( new GearHandle( gearTPC, "TPCParameters" ) ) ;
0079
0080 } catch( std::runtime_error& e ){
0081 std::cerr << " >>>> " << e.what() << std::endl ;
0082 }
0083
0084
0085
0086 try{
0087 DetElement vxdDE = description.detector("VXD") ;
0088
0089 ZPlanarData* vxd = vxdDE.extension<ZPlanarData>() ;
0090
0091
0092 int vxdType = gear::ZPlanarParameters::CMOS ;
0093 gear::ZPlanarParametersImpl* gearVXD = new gear::ZPlanarParametersImpl( vxdType, vxd->rInnerShell/dd4hep::mm, vxd->rOuterShell/dd4hep::mm,
0094 vxd->zHalfShell/dd4hep::mm , vxd->gapShell/dd4hep::mm , 0. ) ;
0095
0096 for(unsigned i=0,n=vxd->layers.size() ; i<n; ++i){
0097
0098 const rec::ZPlanarData::LayerLayout& l = vxd->layers[i] ;
0099
0100
0101 gearVXD->addLayer( l.ladderNumber, l.phi0,
0102 l.distanceSupport/dd4hep::mm, l.offsetSupport/dd4hep::mm, l.thicknessSupport/dd4hep::mm, l.zHalfSupport/dd4hep::mm, l.widthSupport/dd4hep::mm, 0. ,
0103 l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l.thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. ) ;
0104
0105 }
0106
0107 GearHandle* handle = new GearHandle( gearVXD, "VXDParameters" ) ;
0108
0109
0110
0111
0112
0113 MaterialManager matMgr( Detector::getInstance().world().volume() ) ;
0114
0115 const rec::ZPlanarData::LayerLayout& l = vxd->layers[0] ;
0116
0117 Vector3D a( l.distanceSupport , l.phi0 , 0. , Vector3D::cylindrical ) ;
0118 Vector3D b( l.distanceSupport + l.thicknessSupport , l.phi0 , 0. , Vector3D::cylindrical ) ;
0119
0120 const MaterialVec& materials = matMgr.materialsBetween( a , b ) ;
0121
0122 MaterialData mat = ( materials.size() > 1 ? matMgr.createAveragedMaterial( materials ) : materials[0].first ) ;
0123
0124
0125
0126
0127
0128
0129
0130
0131 handle->addMaterial( "VXDSupportMaterial", mat.A(), mat.Z() , mat.density()/(dd4hep::kg/(dd4hep::g*dd4hep::m3)) , mat.radiationLength()/dd4hep::mm , mat.interactionLength()/dd4hep::mm ) ;
0132
0133
0134 vxdDE.addExtension< GearHandle >( handle ) ;
0135
0136 } catch( std::runtime_error& e ){
0137 std::cerr << " >>>> " << e.what() << std::endl ;
0138 }
0139
0140
0141
0142 try{
0143
0144 DetElement sitDE = description.detector("SIT") ;
0145
0146 ZPlanarData* sit = sitDE.extension<ZPlanarData>() ;
0147
0148
0149 int sitType = gear::ZPlanarParameters::CCD ;
0150 gear::ZPlanarParametersImpl* gearSIT = new gear::ZPlanarParametersImpl( sitType, sit->rInnerShell/dd4hep::mm, sit->rOuterShell/dd4hep::mm,
0151 sit->zHalfShell/dd4hep::mm , sit->gapShell/dd4hep::mm , 0. ) ;
0152 std::vector<int> n_sensors_per_ladder ;
0153
0154 for(unsigned i=0,n=sit->layers.size() ; i<n; ++i){
0155
0156 const rec::ZPlanarData::LayerLayout& l = sit->layers[i] ;
0157
0158
0159 gearSIT->addLayer( l.ladderNumber, l.phi0,
0160 l.distanceSupport/dd4hep::mm, l.offsetSupport/dd4hep::mm, l. thicknessSupport/dd4hep::mm, l.zHalfSupport/dd4hep::mm, l.widthSupport/dd4hep::mm, 0. ,
0161 l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l. thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. ) ;
0162
0163
0164 n_sensors_per_ladder.push_back( l.sensorsPerLadder);
0165 }
0166
0167 gearSIT->setDoubleVal("strip_width_mm" , sit->widthStrip / dd4hep::mm ) ;
0168 gearSIT->setDoubleVal("strip_length_mm" , sit->lengthStrip/ dd4hep::mm ) ;
0169 gearSIT->setDoubleVal("strip_pitch_mm" , sit->pitchStrip / dd4hep::mm ) ;
0170 gearSIT->setDoubleVal("strip_angle_deg" , sit->angleStrip / dd4hep::deg ) ;
0171
0172
0173 gearSIT->setIntVals("n_sensors_per_ladder",n_sensors_per_ladder);
0174
0175 sitDE.addExtension< GearHandle >( new GearHandle( gearSIT, "SITParameters" ) ) ;
0176
0177 } catch( std::runtime_error& e ){
0178 std::cerr << " >>>> " << e.what() << std::endl ;
0179 }
0180
0181
0182
0183 try {
0184
0185 DetElement setDE = description.detector("SET") ;
0186
0187 ZPlanarData* set = setDE.extension<ZPlanarData>() ;
0188
0189
0190 int setType = gear::ZPlanarParameters::CCD ;
0191 gear::ZPlanarParametersImpl* gearSET = new gear::ZPlanarParametersImpl( setType, set->rInnerShell/dd4hep::mm, set->rOuterShell/dd4hep::mm,
0192 set->zHalfShell/dd4hep::mm , set->gapShell/dd4hep::mm , 0. ) ;
0193 std::vector<int> n_sensors_per_ladder ;
0194
0195
0196 for(unsigned i=0,n=set->layers.size() ; i<n; ++i){
0197
0198 const rec::ZPlanarData::LayerLayout& l = set->layers[i] ;
0199
0200
0201 gearSET->addLayer( l.ladderNumber, l.phi0,
0202 l.distanceSupport/dd4hep::mm, l.offsetSupport/dd4hep::mm, l. thicknessSupport/dd4hep::mm, l.zHalfSupport/dd4hep::mm, l.widthSupport/dd4hep::mm, 0. ,
0203 l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l. thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. ) ;
0204
0205
0206 n_sensors_per_ladder.push_back( l.sensorsPerLadder);
0207 }
0208
0209 gearSET->setDoubleVal("strip_width_mm" , set->widthStrip / dd4hep::mm ) ;
0210 gearSET->setDoubleVal("strip_length_mm" , set->lengthStrip/ dd4hep::mm ) ;
0211 gearSET->setDoubleVal("strip_pitch_mm" , set->pitchStrip / dd4hep::mm ) ;
0212 gearSET->setDoubleVal("strip_angle_deg" , set->angleStrip / dd4hep::deg ) ;
0213
0214
0215 gearSET->setIntVals("n_sensors_per_ladder",n_sensors_per_ladder);
0216
0217 setDE.addExtension< GearHandle >( new GearHandle( gearSET, "SETParameters" ) ) ;
0218
0219 } catch( std::runtime_error& e ){
0220 std::cerr << " >>>> " << e.what() << std::endl ;
0221 }
0222
0223
0224
0225 try {
0226
0227 DetElement ftdDE = description.detector("FTD") ;
0228
0229 ZDiskPetalsData* ftd = ftdDE.extension<ZDiskPetalsData>() ;
0230
0231 gear::FTDParametersImpl* gearFTD = new gear::FTDParametersImpl();
0232
0233 for(unsigned i=0,n=ftd->layers.size() ; i<n; ++i){
0234
0235 const rec::ZDiskPetalsData::LayerLayout& l = ftd->layers[i] ;
0236
0237
0238 bool isDoubleSided = l.typeFlags[ rec::ZDiskPetalsStruct::SensorType::DoubleSided ] ;
0239
0240
0241 static const int PIXEL = gear::FTDParameters::PIXEL ;
0242 static const int STRIP = gear::FTDParameters::STRIP ;
0243 int sensorType = ( l.typeFlags[ rec::ZDiskPetalsStruct::SensorType::Pixel ] ? PIXEL : STRIP ) ;
0244
0245
0246 double zoffset = fabs( l.zOffsetSupport ) ;
0247 double signoffset = l.zOffsetSupport > 0 ? 1. : -1 ;
0248
0249 gearFTD->addLayer( l.petalNumber, l.sensorsPerPetal,
0250 isDoubleSided, sensorType,
0251 l.petalHalfAngle, l.phi0, l.alphaPetal,
0252 l.zPosition/dd4hep::mm, zoffset/dd4hep::mm, signoffset,
0253 l.distanceSupport/dd4hep::mm, l.thicknessSupport/dd4hep::mm,
0254 l.widthInnerSupport/dd4hep::mm, l.widthOuterSupport/dd4hep::mm,
0255 l.lengthSupport/dd4hep::mm,
0256 0.,
0257 l.distanceSensitive/dd4hep::mm, l.thicknessSensitive/dd4hep::mm,
0258 l.widthInnerSensitive/dd4hep::mm, l.widthOuterSensitive/dd4hep::mm,
0259 l.lengthSensitive/dd4hep::mm,
0260 0. ) ;
0261
0262
0263
0264 }
0265
0266 gearFTD->setDoubleVal("strip_width_mm" , ftd->widthStrip / dd4hep::mm ) ;
0267 gearFTD->setDoubleVal("strip_length_mm" , ftd->lengthStrip/ dd4hep::mm ) ;
0268 gearFTD->setDoubleVal("strip_pitch_mm" , ftd->pitchStrip / dd4hep::mm ) ;
0269 gearFTD->setDoubleVal("strip_angle_deg" , ftd->angleStrip / dd4hep::deg ) ;
0270
0271
0272 ftdDE.addExtension< GearHandle >( new GearHandle( gearFTD, "FTDParameters" ) ) ;
0273
0274 } catch( std::runtime_error& e ){
0275 std::cerr << " >>>> " << e.what() << std::endl ;
0276 }
0277
0278
0279
0280 try {
0281
0282 DetElement coilDE = description.detector("Coil") ;
0283
0284 gear::GearParametersImpl* gearCOIL = new gear::GearParametersImpl();
0285
0286 Tube coilTube = Tube( coilDE.volume().solid() ) ;
0287
0288 gearCOIL->setDoubleVal("Coil_cryostat_inner_radius" , coilTube->GetRmin()/ dd4hep::mm ) ;
0289 gearCOIL->setDoubleVal("Coil_cryostat_outer_radius" , coilTube->GetRmax()/ dd4hep::mm ) ;
0290 gearCOIL->setDoubleVal("Coil_cryostat_half_z" , coilTube->GetDZ()/ dd4hep::mm ) ;
0291
0292 coilDE.addExtension< GearHandle >( new GearHandle( gearCOIL, "CoilParameters" ) ) ;
0293
0294 } catch( std::runtime_error& e ){
0295 std::cerr << " >>>> " << e.what() << std::endl ;
0296 }
0297
0298
0299
0300 try {
0301
0302 DetElement tubeDE = description.detector("Tube") ;
0303
0304 ConicalSupportData* tube = tubeDE.extension<ConicalSupportData>() ;
0305
0306 gear::GearParametersImpl* gearTUBE = new gear::GearParametersImpl();
0307
0308 tube->isSymmetricInZ = true ;
0309
0310 unsigned n = tube->sections.size() ;
0311
0312 std::vector<double> rInner(n) ;
0313 std::vector<double> rOuter(n) ;
0314 std::vector<double> zStart(n) ;
0315
0316 for(unsigned i=0 ; i<n ; ++i){
0317
0318 const ConicalSupportData::Section& s = tube->sections[i] ;
0319
0320 rInner[i] = s.rInner/ dd4hep::mm ;
0321 rOuter[i] = s.rOuter/ dd4hep::mm ;
0322 zStart[i] = s.zPos / dd4hep::mm ;
0323
0324
0325 }
0326
0327 gearTUBE->setDoubleVals("RInner" , rInner ) ;
0328 gearTUBE->setDoubleVals("ROuter" , rOuter ) ;
0329 gearTUBE->setDoubleVals("Z" , zStart ) ;
0330
0331
0332 tubeDE.addExtension< GearHandle >( new GearHandle( gearTUBE, "BeamPipe" ) ) ;
0333
0334 } catch( std::runtime_error& e ){
0335 std::cerr << " >>>> " << e.what() << std::endl ;
0336 }
0337
0338
0339
0340
0341
0342
0343
0344 std::map< std::string, std::string > caloMap ;
0345 caloMap["HcalBarrel"] = "HcalBarrelParameters" ;
0346 caloMap["EcalBarrel"] = "EcalBarrelParameters" ;
0347 caloMap["EcalEndcap"] = "EcalEndcapParameters" ;
0348 caloMap["EcalPlug"] = "EcalPlugParameters" ;
0349 caloMap["YokeBarrel"] = "YokeBarrelParameters" ;
0350 caloMap["YokeEndcap"] = "YokeEndcapParameters" ;
0351 caloMap["YokePlug"] = "YokePlugParameters" ;
0352 caloMap["HcalBarrel"] = "HcalBarrelParameters" ;
0353 caloMap["HcalEndcap"] = "HcalEndcapParameters" ;
0354 caloMap["HcalRing"] = "HcalRingParameters" ;
0355 caloMap["Lcal"] = "LcalParameters" ;
0356 caloMap["LHcal"] = "LHcalParameters" ;
0357 caloMap["BeamCal"] = "BeamCalParameters" ;
0358
0359 for( std::map< std::string, std::string >::const_iterator it = caloMap.begin() ; it != caloMap.end() ; ++it ){
0360
0361
0362
0363 try {
0364
0365 DetElement caloDE = description.detector( it->first ) ;
0366
0367 LayeredCalorimeterData* calo = caloDE.extension<LayeredCalorimeterData>() ;
0368
0369 gear::CalorimeterParametersImpl* gearCalo =
0370 ( calo->layoutType == LayeredCalorimeterData::BarrelLayout ?
0371 new gear::CalorimeterParametersImpl( calo->extent[0]/dd4hep::mm, calo->extent[3]/dd4hep::mm, calo->inner_symmetry, calo->phi0 ) :
0372
0373 new gear::CalorimeterParametersImpl( calo->extent[0]/dd4hep::mm, calo->extent[1]/dd4hep::mm, calo->extent[2]/dd4hep::mm, calo->outer_symmetry, calo->phi0 ) ) ;
0374
0375
0376 for( unsigned i=0, nL = calo->layers.size() ; i <nL ; ++i ){
0377
0378 LayeredCalorimeterData::Layer& l = calo->layers[i] ;
0379
0380
0381
0382
0383 if( i == 0 ) {
0384 gearCalo->layerLayout().positionLayer( l.distance/dd4hep::mm,
0385 (l.inner_thickness+l.sensitive_thickness/2.)/dd4hep::mm ,
0386 l.cellSize0/dd4hep::mm, l.cellSize1/dd4hep::mm,
0387 (l.inner_thickness-l.sensitive_thickness/2.)/dd4hep::mm ) ;
0388 }else{
0389 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 ,
0390 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) ;
0391 }
0392
0393
0394
0395
0396
0397
0398
0399
0400 }
0401
0402 if( it->first == "HcalBarrel" ){
0403
0404 gearCalo->setIntVal("Hcal_outer_polygon_order" , calo->outer_symmetry ) ;
0405 gearCalo->setDoubleVal("Hcal_outer_polygon_phi0" , calo->phi0 ) ;
0406 }
0407
0408 if( it->first == "BeamCal" ){
0409
0410 try{
0411
0412
0413 SensitiveDetector sD = description.sensitiveDetector( it->first ) ;
0414 Readout readOut = sD.readout() ;
0415 Segmentation seg = readOut.segmentation() ;
0416
0417
0418 DDSegmentation::DoubleVecParameter pPar = dynamic_cast<DDSegmentation::DoubleVecParameter>( seg.parameter("grid_phi_values"));
0419 DDSegmentation::DoubleParameter oPPar= dynamic_cast<DDSegmentation::DoubleParameter>( seg.parameter("offset_phi"));
0420
0421
0422
0423 double offsetPhi = oPPar->typedValue() ;
0424 double spanningPhi = 360.*dd4hep::deg - 2.*( offsetPhi + 180.*dd4hep::deg ) ;
0425
0426 gearCalo->setDoubleVals( "phi_segmentation" , pPar->typedValue() );
0427 gearCalo->setDoubleVal( "cylinder_starting_phi", offsetPhi );
0428 gearCalo->setDoubleVal( "cylinder_spanning_phi", spanningPhi );
0429 gearCalo->setDoubleVal( "beam_crossing_angle" , crossing_angle );
0430
0431
0432
0433 gearCalo->setDoubleVal( "dead_area_outer_r" , 0 );
0434 gearCalo->setDoubleVal( "pairsMonitorZ" , 0. );
0435 gearCalo->setDoubleVal( "FIXME_dead_area_outer_r" , -1. );
0436 gearCalo->setDoubleVal( "FIXME_pairsMonitorZ" , -1. );
0437
0438 } catch( std::runtime_error& e ){
0439 std::cerr << " >>>> BeamCal: " << e.what() << std::endl ;
0440 }
0441 }
0442
0443 if( it->first == "Lcal" || it->first == "LHcal" ){
0444 gearCalo->setDoubleVal( "beam_crossing_angle" , crossing_angle );
0445 }
0446
0447 caloDE.addExtension< GearHandle >( new GearHandle( gearCalo, it->second ) ) ;
0448
0449 } catch( std::runtime_error& e ){
0450 std::cerr << " >>>> " << e.what() << std::endl ;
0451 }
0452
0453 }
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492 return 1;
0493 }
0494 }
0495 }
0496 DECLARE_APPLY( GearForILD, dd4hep::rec::createGearForILD )
0497
0498