Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:34

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : F.Gaede
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 "gearimpl/TPCParametersImpl.h"
0024 #include "gearimpl/FixedPadSizeDiskLayout.h"
0025 #include "gearimpl/ZPlanarParametersImpl.h"
0026 #include "gearimpl/FTDParametersImpl.h"
0027 #include "gearimpl/CalorimeterParametersImpl.h"
0028 
0029 #include <iostream>
0030 
0031 namespace dd4hep{
0032   namespace rec{
0033     
0034     using namespace detail ;
0035 
0036     /** Plugin that creates Gear objects for DetElements and attaches them 
0037      *  as extensions. Called from DDGear::createGearMgr().
0038      *  NB: this code is for backward compatibility to run 
0039      *  the old reconstruction that expects Gear information
0040      *  and should eventually be phased out.
0041      * 
0042      *  @author  F.Gaede, CERN/DESY
0043      *  @date Oct 2014
0044      *  @version $Id$
0045      */
0046     
0047     static long createGearForCLIC(Detector& description, int /*argc*/, char** /*argv*/) {
0048       
0049       std::cout << " **** running plugin createGearForCLIC ! " <<  std::endl ;
0050       
0051    
0052       //========= VXD ==============================================================================
0053       
0054       try{
0055     DetElement vxdDE = description.detector("VertexBarrel") ;
0056     
0057     ZPlanarData* vxd = vxdDE.extension<ZPlanarData>() ;
0058     
0059     //      ZPlanarParametersImpl (int type, double shellInnerRadius, double shellOuterRadius, double shellHalfLength, double shellGap, double shellRadLength)
0060     int vxdType =  gear::ZPlanarParameters::CMOS ;
0061     gear::ZPlanarParametersImpl* gearVXD = new gear::ZPlanarParametersImpl( vxdType, vxd->rInnerShell/dd4hep::mm,  vxd->rOuterShell/dd4hep::mm,
0062                                         vxd->zHalfShell/dd4hep::mm , vxd->gapShell/dd4hep::mm , 0.  ) ;
0063     
0064 //   std::cout<<"Got "<<vxd->layers.size()<<" layers."<<std::endl;
0065     for(unsigned i=0,n=vxd->layers.size() ; i<n; ++i){
0066 //     std::cout<<"Working on layer "<<i<<" for a total of "<<n<<" layers."<<std::endl;
0067     
0068       const rec::ZPlanarData::LayerLayout& l = vxd->layers[i] ;
0069       
0070       // FIXME set rad lengths to 0 -> need to get from dd4hep ....
0071       gearVXD->addLayer( l.ladderNumber, l.phi0, 
0072                  l.distanceSupport/dd4hep::mm,   l.offsetSupport/dd4hep::mm,   l.thicknessSupport/dd4hep::mm,   l.zHalfSupport/dd4hep::mm,   l.widthSupport/dd4hep::mm,   0. , 
0073                  l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l.thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. )  ;
0074     
0075     }
0076     
0077     std::cout<<"Added layers"<<std::endl;
0078   
0079     GearHandle* handle = new GearHandle( gearVXD, "VXDParameters" )  ;
0080     
0081     // quick hack for now: add the one material that is needed by KalDet :  
0082          handle->addMaterial( "VXDSupportMaterial", 2.075865162e+01, 1.039383117e+01, 2.765900000e+02, 1.014262421e+03, 3.341388059e+03)  ; 
0083     
0084     // -------- better: get right averaged material from first ladder:  ------------------
0085 //  MaterialManager matMgr ;
0086 //       
0087 //  const rec::ZPlanarData::LayerLayout& l = vxd->layers[0] ;
0088 //  
0089 //  Vector3D a( l.distanceSupport                      , l.phi0 , 0. ,  Vector3D::cylindrical ) ;
0090 //  Vector3D b( l.distanceSupport + l.thicknessSupport , l.phi0 , 0. ,  Vector3D::cylindrical ) ;
0091 //  
0092 //  const MaterialVec& materials = matMgr.materialsBetween( a , b  ) ;
0093 //  
0094 //   std::cout<<"Calculating material average."<<std::endl;
0095 //  MaterialData mat = ( materials.size() > 1  ? matMgr.createAveragedMaterial( materials ) : materials[0].first  ) ;
0096 //  
0097 //  std::cout << " ####### found materials between points : " << a << " and " << b << " : " ;
0098 //  for( unsigned i=0,n=materials.size();i<n;++i){
0099 //      std::cout <<  materials[i].first.name() << "[" <<   materials[i].second << "], " ;
0100 //  }
0101 //  std::cout << std::endl ;
0102 //  std::cout << "   averaged material : " << mat << std::endl ;
0103 //  
0104 //  handle->addMaterial( "VXDSupportMaterial", mat.A(), mat.Z() , mat.density()/(dd4hep::kg/(dd4hep::g*dd4hep::m3)) , mat.radiationLength()/dd4hep::mm , mat.interactionLength()/dd4hep::mm )  ; 
0105     
0106     
0107     vxdDE.addExtension< GearHandle >( handle ) ;
0108 
0109       } catch( std::runtime_error& e ){  
0110     std::cerr << " >>>> " << e.what() << std::endl ;
0111       } 
0112 
0113       //========= SIT ==============================================================================
0114      
0115       try{ 
0116 
0117         DetElement sitDE = description.detector("InnerTrackerBarrel") ;
0118     
0119     ZPlanarData* sit = sitDE.extension<ZPlanarData>() ;
0120     
0121     //      ZPlanarParametersImpl (int type, double shellInnerRadius, double shellOuterRadius, double shellHalfLength, double shellGap, double shellRadLength)
0122     int sitType =  gear::ZPlanarParameters::CCD ;
0123   
0124     gear::ZPlanarParametersImpl* gearSIT = new gear::ZPlanarParametersImpl( sitType, sit->rInnerShell/dd4hep::mm,  sit->rOuterShell/dd4hep::mm,
0125                                         sit->zHalfShell/dd4hep::mm , sit->gapShell/dd4hep::mm , 0.  ) ;
0126                     
0127     std::vector<int> n_sensors_per_ladder ;
0128     
0129     for(unsigned i=0,n=sit->layers.size() ; i<n; ++i){
0130       
0131       const rec::ZPlanarData::LayerLayout& l = sit->layers[i] ;
0132       
0133       // FIXME set rad lengths to 0 -> need to get from dd4hep ....
0134       gearSIT->addLayer( l.ladderNumber, l.phi0, 
0135                  l.distanceSupport/dd4hep::mm,   l.offsetSupport/dd4hep::mm,   l. thicknessSupport/dd4hep::mm,   l.zHalfSupport/dd4hep::mm,   l.widthSupport/dd4hep::mm,   0. , 
0136                  l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l. thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. )  ;
0137       
0138       
0139       n_sensors_per_ladder.push_back( l.sensorsPerLadder);
0140     }
0141     
0142     gearSIT->setDoubleVal("strip_width_mm"  , sit->widthStrip / dd4hep::mm ) ;
0143     gearSIT->setDoubleVal("strip_length_mm" , sit->lengthStrip/ dd4hep::mm ) ;
0144     gearSIT->setDoubleVal("strip_pitch_mm"  , sit->pitchStrip / dd4hep::mm ) ;
0145     gearSIT->setDoubleVal("strip_angle_deg" , sit->angleStrip / dd4hep::deg ) ;
0146     
0147     
0148     gearSIT->setIntVals("n_sensors_per_ladder",n_sensors_per_ladder);
0149     
0150     sitDE.addExtension< GearHandle >( new GearHandle( gearSIT, "SITParameters" ) ) ;
0151 
0152       } catch( std::runtime_error& e ){ 
0153     std::cerr << " >>>> " << e.what() << std::endl ;
0154       } 
0155 
0156       //============================================================================================
0157 
0158       try {
0159 
0160     DetElement setDE = description.detector("OuterTrackerBarrel") ;
0161     
0162     ZPlanarData* set = setDE.extension<ZPlanarData>() ;
0163     
0164     //      ZPlanarParametersImpl (int type, double shellInnerRadius, double shellOuterRadius, double shellHalfLength, double shellGap, double shellRadLength)
0165     int setType =  gear::ZPlanarParameters::CCD ;
0166     gear::ZPlanarParametersImpl* gearSET = new gear::ZPlanarParametersImpl( setType, set->rInnerShell/dd4hep::mm,  set->rOuterShell/dd4hep::mm,
0167                                         set->zHalfShell/dd4hep::mm , set->gapShell/dd4hep::mm , 0.  ) ;
0168     std::vector<int> n_sensors_per_ladder ;
0169     //n_sensors_per_ladder.clear() ;
0170     
0171     for(unsigned i=0,n=set->layers.size() ; i<n; ++i){
0172       
0173       const rec::ZPlanarData::LayerLayout& l = set->layers[i] ;
0174       
0175       // FIXME set rad lengths to 0 -> need to get from dd4hep ....
0176       gearSET->addLayer( l.ladderNumber, l.phi0, 
0177                  l.distanceSupport/dd4hep::mm,   l.offsetSupport/dd4hep::mm,   l. thicknessSupport/dd4hep::mm,   l.zHalfSupport/dd4hep::mm,   l.widthSupport/dd4hep::mm,   0. , 
0178                  l.distanceSensitive/dd4hep::mm, l.offsetSensitive/dd4hep::mm, l. thicknessSensitive/dd4hep::mm, l.zHalfSensitive/dd4hep::mm, l.widthSensitive/dd4hep::mm, 0. )  ;
0179       
0180       
0181       n_sensors_per_ladder.push_back( l.sensorsPerLadder);
0182     }
0183     
0184     gearSET->setDoubleVal("strip_width_mm"  , set->widthStrip / dd4hep::mm ) ;
0185     gearSET->setDoubleVal("strip_length_mm" , set->lengthStrip/ dd4hep::mm ) ;
0186     gearSET->setDoubleVal("strip_pitch_mm"  , set->pitchStrip / dd4hep::mm ) ;
0187     gearSET->setDoubleVal("strip_angle_deg" , set->angleStrip / dd4hep::deg ) ;
0188 
0189     
0190     gearSET->setIntVals("n_sensors_per_ladder",n_sensors_per_ladder);
0191     
0192     setDE.addExtension< GearHandle >( new GearHandle( gearSET, "SETParameters" ) ) ;
0193 
0194       } catch( std::runtime_error& e ){  
0195     std::cerr << " >>>> " << e.what() << std::endl ;
0196       } 
0197       
0198       //============================================================================================
0199 
0200       try {
0201 
0202     DetElement iteDE = description.detector("InnerTrackerEndcap") ;
0203     
0204     ZDiskPetalsData* iteData = iteDE.extension<ZDiskPetalsData>() ;
0205     
0206   gear::GearParametersImpl* gearFTD = new gear::GearParametersImpl();
0207   
0208   std::vector<double> thicknesses;
0209   std::vector<double> innerRadii;
0210   std::vector<double> outerRadii;
0211   std::vector<double> zPositions;
0212   
0213     
0214     for(unsigned i=0,n=iteData->layers.size() ; i<n; ++i){
0215     
0216     const rec::ZDiskPetalsData::LayerLayout& l = iteData->layers[i] ;
0217     
0218     thicknesses.push_back(l.thicknessSupport/ dd4hep::mm);
0219     innerRadii.push_back( l.distanceSensitive/ dd4hep::mm);
0220     outerRadii.push_back( (l.distanceSensitive + l.lengthSensitive)/ dd4hep::mm);
0221     zPositions.push_back( l.zPosition/ dd4hep::mm);
0222     
0223 
0224 
0225     }
0226     
0227     
0228     //Append OuterTracker
0229     DetElement oteDE = description.detector("OuterTrackerEndcap") ;
0230   ZDiskPetalsData* oteData = oteDE.extension<ZDiskPetalsData>() ;
0231    
0232   
0233   for(unsigned i=0,n=oteData->layers.size() ; i<n; ++i){
0234     
0235     const rec::ZDiskPetalsData::LayerLayout& l = oteData->layers[i] ;
0236     
0237     thicknesses.push_back(l.thicknessSupport/ dd4hep::mm);
0238     innerRadii.push_back( l.distanceSensitive/ dd4hep::mm);
0239     outerRadii.push_back( (l.distanceSensitive + l.lengthSensitive)/ dd4hep::mm);
0240     zPositions.push_back( l.zPosition/ dd4hep::mm);
0241     
0242     
0243     
0244   }
0245     
0246 
0247     gearFTD->setDoubleVals("FTDDiskSupportThickness"  ,  thicknesses) ;
0248   gearFTD->setDoubleVals("FTDInnerRadius" , innerRadii) ;
0249   gearFTD->setDoubleVals("FTDOuterRadius"  , outerRadii ) ;
0250   gearFTD->setDoubleVals("FTDZCoordinate" ,zPositions) ;
0251   
0252   //attach gear handle to inner tracker
0253   iteDE.addExtension< GearHandle >( new GearHandle( gearFTD, "FTD" ) ) ;
0254   
0255   
0256       } catch( std::runtime_error& e ){  
0257     std::cerr << " >>>> " << e.what() << std::endl ;
0258       } 
0259 
0260       //============================================================================================
0261       
0262       try {
0263     
0264     DetElement coilDE = description.detector("Solenoid") ;
0265     
0266     gear::GearParametersImpl* gearCOIL = new gear::GearParametersImpl();
0267     
0268     Tube coilTube = Tube( coilDE.volume().solid() )  ;
0269     
0270     gearCOIL->setDoubleVal("Coil_cryostat_inner_radius" , coilTube->GetRmin()/ dd4hep::mm ) ;
0271     gearCOIL->setDoubleVal("Coil_cryostat_outer_radius" , coilTube->GetRmax()/ dd4hep::mm ) ;
0272     gearCOIL->setDoubleVal("Coil_cryostat_half_z"       , coilTube->GetDZ()/ dd4hep::mm ) ;
0273     
0274     coilDE.addExtension< GearHandle >( new GearHandle( gearCOIL, "CoilParameters" ) ) ;
0275     
0276       } catch( std::runtime_error& e ){  
0277     std::cerr << " >>>> " << e.what() << std::endl ;
0278       } 
0279 
0280       //============================================================================================
0281       try {
0282 
0283     DetElement tubeDE = description.detector("Tube") ;
0284     
0285     ConicalSupportData* tube = tubeDE.extension<ConicalSupportData>() ;
0286     
0287     gear::GearParametersImpl* gearTUBE = new gear::GearParametersImpl();
0288     
0289     tube->isSymmetricInZ = true ;
0290     
0291     unsigned n = tube->sections.size() ;
0292     
0293     std::vector<double> rInner(n) ;
0294     std::vector<double> rOuter(n) ;
0295     std::vector<double> zStart(n) ;
0296     
0297     for(unsigned i=0 ; i<n ; ++i){
0298       
0299       const ConicalSupportData::Section& s = tube->sections[i] ;
0300       
0301       rInner[i] = s.rInner/ dd4hep::mm  ; 
0302       rOuter[i] = s.rOuter/ dd4hep::mm  ; 
0303       zStart[i] = s.zPos  / dd4hep::mm  ; 
0304       
0305       // FIXME set rad lengths to 0 -> need to get from dd4hep ....
0306     }
0307     
0308     gearTUBE->setDoubleVals("RInner" , rInner ) ;
0309     gearTUBE->setDoubleVals("ROuter" , rOuter ) ;
0310     gearTUBE->setDoubleVals("Z"      , zStart ) ;
0311     
0312     
0313     tubeDE.addExtension< GearHandle >( new GearHandle( gearTUBE, "Beampipe" ) ) ;
0314       
0315       } catch( std::runtime_error& e ){  
0316     std::cerr << " >>>> " << e.what() << std::endl ;
0317       }
0318 
0319       //========= CALO ==============================================================================
0320 
0321       //**********************************************************
0322       //*  gear interface w/ LayeredCalorimeterData extension
0323       //**********************************************************
0324 
0325       std::map< std::string, std::string > caloMap ;
0326       caloMap["HCalBarrel"] = "HcalBarrelParameters"  ; 
0327       caloMap["ECalBarrel"] = "EcalBarrelParameters" ;
0328       caloMap["ECalEndcap"] = "EcalEndcapParameters" ;
0329       caloMap["ECalPlug"]   = "EcalPlugParameters" ;
0330       caloMap["YokeBarrel"] = "YokeBarrelParameters" ;
0331       caloMap["YokeEndcap"] = "YokeEndcapParameters" ;
0332       caloMap["YokePlug"]   = "YokePlugParameters" ;
0333       caloMap["HCalBarrel"] = "HcalBarrelParameters" ;
0334       caloMap["HCalEndcap"] = "HcalEndcapParameters" ;
0335       caloMap["HCalRing"]   = "HcalRingParameters" ;
0336       caloMap["LumiCal"]        = "LcalParameters" ;
0337 //       caloMap["LHCal"]       = "LHcalParameters" ;
0338       caloMap["BeamCal"]    = "BeamCalParameters" ;
0339       
0340       for(  std::map< std::string, std::string >::const_iterator it = caloMap.begin() ; it != caloMap.end() ; ++it ){
0341 
0342       
0343 
0344     try {
0345 
0346       DetElement caloDE = description.detector( it->first ) ;
0347     
0348       LayeredCalorimeterData* calo = caloDE.extension<LayeredCalorimeterData>() ;
0349       
0350       gear::CalorimeterParametersImpl* gearCalo = 
0351         ( calo->layoutType == LayeredCalorimeterData::BarrelLayout  ?
0352           new gear::CalorimeterParametersImpl(  calo->extent[0]/dd4hep::mm, calo->extent[3]/dd4hep::mm, calo->inner_symmetry, calo->inner_phi0 )  :
0353           //CalorimeterParametersImpl (double rMin, double zMax, int symOrder=8, double phi0=0.0) - C'tor for a cylindrical (octagonal) BARREL calorimeter.
0354           new gear::CalorimeterParametersImpl(  calo->extent[0]/dd4hep::mm,  calo->extent[1]/dd4hep::mm,  calo->extent[2]/dd4hep::mm, calo->outer_symmetry, calo->outer_phi0 )   ) ;
0355       //CalorimeterParametersImpl (double rMin, double rMax, double zMin, int symOrder=2, double phi0=0.0) - C'tor for a cylindrical (octagonal) ENDCAP calorimeter. 
0356       
0357       for( unsigned i=0, nL = calo->layers.size() ; i <nL ; ++i ){
0358         
0359         LayeredCalorimeterData::Layer& l = calo->layers[i] ;
0360         
0361             
0362             //Do some arithmetic to get thicknesses and (approximate) absorber thickneses from "new" rec structures
0363             //The positioning should come out right, but the absorber thickness should be overestimated due to the presence of 
0364             //other less dense material
0365         if( i == 0 ) {
0366             //First layer is positioned with only its inner thickness taken into account
0367           gearCalo->layerLayout().positionLayer( l.distance/dd4hep::mm, (l.inner_thickness+l.sensitive_thickness/2.)/dd4hep::mm , 
0368                              l.cellSize0/dd4hep::mm, l.cellSize1/dd4hep::mm, (l.inner_thickness-l.sensitive_thickness/2.)/dd4hep::mm ) ;
0369         }else if ( i == nL -1 ) {
0370                     //Need to handle outermost layer differently; add its outer thickness
0371                     //This gives the right extent, but the "wrong" distance for the last layer
0372                       gearCalo->layerLayout().addLayer((l.inner_thickness+l.outer_thickness+calo->layers[i-1].outer_thickness-calo->layers[i-1].sensitive_thickness/2.)/dd4hep::mm , 
0373                                         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) ;
0374         }else{
0375             //All other layers need to be added taking into account the previous layer outer thicknesses
0376           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 , 
0377                                         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) ;
0378         }
0379         
0380       }
0381     
0382       if( it->first == "HCalBarrel" ){
0383         // additional parameters needed by MarlinPandora
0384         gearCalo->setIntVal("Hcal_outer_polygon_order"   , calo->outer_symmetry  ) ;
0385         gearCalo->setDoubleVal("Hcal_outer_polygon_phi0" ,  calo->outer_phi0 ) ;
0386       }
0387           
0388 
0389 
0390       caloDE.addExtension< GearHandle >( new GearHandle( gearCalo, it->second ) ) ;
0391 
0392     } catch( std::runtime_error& e ){  
0393       std::cerr << " >>>> " << e.what() << std::endl ;
0394     
0395     } 
0396 
0397       } // calo loop 
0398 
0399 
0400 
0401       //**********************************************************
0402       //*  test gear interface w/ LayeredExtensionImpl extension
0403       //**********************************************************
0404       
0405       // DetElement calo2DE = description.detector("EcalBarrel") ;
0406       
0407       // Calorimeter calo2( calo2DE ) ;
0408       
0409       // gear::CalorimeterParametersImpl* gearCalo2 = 
0410       //    ( calo2.isBarrel()  ?
0411       //      new gear::CalorimeterParametersImpl(  calo2.getRMin()/dd4hep::mm,                             calo2.getZMax()/dd4hep::mm, calo2.getNSides(),  0. )  :    // fixme: phi 0  is not defined ??
0412       //      new gear::CalorimeterParametersImpl(  calo2.getRMin()/dd4hep::mm, calo2.getRMax()/dd4hep::mm, calo2.getZMin()/dd4hep::mm, calo2.getNSides(),  0. ) 
0413       //      ) ;
0414 
0415       // for( unsigned i=0, nL = calo2.numberOfLayers() ; i <nL ; ++i ){
0416         
0417       //    if( i == 0 ) {
0418       //      gearCalo2->layerLayout().positionLayer( calo2.getRMin()/dd4hep::mm, calo2.thickness(i)/dd4hep::mm ,  0. /dd4hep::mm,   0. /dd4hep::mm, calo2.absorberThickness(i)/dd4hep::mm ) ;
0419 
0420       //    }else{                                                                                        //     fixme:   cell sizes  not in API !? 
0421 
0422       //      gearCalo2->layerLayout().addLayer(                                  calo2.thickness(i)/dd4hep::mm ,  0. /dd4hep::mm,   0. /dd4hep::mm, calo2.absorberThickness(i)/dd4hep::mm ) ;
0423       //    }
0424 
0425 
0426       // }
0427 
0428       // calo2DE.addExtension< GearHandle >( new GearHandle( gearCalo2, "EcalBarrelParameters" ) ) ;
0429 
0430 
0431       //============================================================================================
0432 
0433 
0434 
0435       // --- Detector::apply() expects return code 1 if all went well ! ----
0436       return 1;
0437     }
0438   }
0439 }
0440 DECLARE_APPLY( GearForCLIC, dd4hep::rec::createGearForCLIC )
0441 
0442