Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:15:00

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 //==========================================================================
0011 //
0012 //  Simple program to dump the complete DetElement hierarchy
0013 // 
0014 //  Author     : F.Gaede, CERN/DESY
0015 //  Date       : 07 Nov 2014
0016 //==========================================================================
0017 
0018 // Framework include files
0019 #include "DD4hep/Detector.h"
0020 #include "DD4hep/DetType.h"
0021 #include "DD4hep/DetectorSelector.h"
0022 #include "DD4hep/DD4hepUnits.h"
0023 
0024 #include "DDRec/Surface.h"
0025 #include "DDRec/DetectorSurfaces.h"
0026 #include "DDRec/DetectorData.h"
0027 #include "DDRec/SurfaceHelper.h"
0028 
0029 // C/C++ include files
0030 #include <list>
0031 
0032 
0033 using namespace std ;
0034 using namespace dd4hep ;
0035 using namespace dd4hep::detail;
0036 using namespace dd4hep::rec;
0037 
0038 
0039 //=============================================================================
0040 static void printDetectorData( DetElement det ){
0041 
0042   try{ 
0043     FixedPadSizeTPCData* d = det.extension<FixedPadSizeTPCData>() ; 
0044     std::cout << *d ;
0045   } catch(...){}
0046   try{ 
0047     ZPlanarData* d = det.extension<ZPlanarData>() ; 
0048     std::cout << *d ;
0049   } catch(...){}
0050   try{ 
0051     ZDiskPetalsData* d = det.extension<ZDiskPetalsData>() ; 
0052     std::cout << *d ;
0053   } catch(...){}
0054   try{ 
0055     ConicalSupportData* d = det.extension<ConicalSupportData>() ; 
0056     std::cout << *d ;
0057   } catch(...){}
0058   try{ 
0059     LayeredCalorimeterData* d = det.extension<LayeredCalorimeterData>() ; 
0060     std::cout << *d ;
0061   } catch(...){}
0062 
0063 }
0064 
0065 static void printDetectorSets( std::string name, unsigned int includeFlag,  unsigned int excludeFlag=DetType::IGNORE ){
0066 
0067   Detector& description = Detector::getInstance();
0068   const std::vector<DetElement>& dets = DetectorSelector(description).detectors( includeFlag, excludeFlag ) ;
0069   std::cout << " " << name  ;
0070   for(int i=0,N=dets.size();i<N;++i)  
0071     std::cout << dets[i].name() << ", " ;
0072   std::cout << endl ;
0073 } 
0074 
0075 
0076 //=============================================================================
0077 
0078 static int invoke_dump_detector(int argc, char** argv ){
0079     
0080   if( argc < 2 ) {
0081     std::cout << " usage: dumpdetector compact.xml [-s]" 
0082           << "  -d :  only print DetectorData objects " 
0083           << "  -s :  also print surfaces " 
0084           << std::endl ;
0085 
0086     exit(1) ;
0087   }
0088   
0089   std::string inFile =  argv[1] ;
0090 
0091 
0092   bool printDetData = ( argc>2 && !strcmp( argv[2] , "-d" ) );
0093 
0094   bool printSurfaces = ( argc>2 && !strcmp( argv[2] , "-s" ) );
0095 
0096 
0097   Detector& description = Detector::getInstance();
0098 
0099   description.fromCompact( inFile );
0100 
0101   DetElement world = description.world() ;
0102 
0103 
0104   std::cout << "############################################################################### "  << std::endl  ;
0105   
0106   Header h = description.header() ;
0107 
0108   std::cout << " detector model : " <<  h.name()  << std::endl 
0109         << "    title : "  << h.title() << std::endl 
0110         << "    author : " << h.author() << std::endl 
0111         << "    status : " << h.status() << std::endl ;
0112 
0113 
0114   // print a few sets of detectors (mainly to demonstrate the usage of the detector types )
0115 
0116   printDetectorSets( " barrel trackers : " , ( DetType::TRACKER | DetType::BARREL ) , ( DetType::VERTEX) ) ; 
0117   printDetectorSets( " endcap trackers : " , ( DetType::TRACKER | DetType::ENDCAP ) , ( DetType::VERTEX) ) ; 
0118 
0119   printDetectorSets( " vertex barrel trackers : " , ( DetType::TRACKER | DetType::BARREL | DetType::VERTEX) ) ; 
0120   printDetectorSets( " vertex endcap trackers : " , ( DetType::TRACKER | DetType::ENDCAP | DetType::VERTEX) ) ; 
0121 
0122   printDetectorSets( " barrel calorimeters : " , ( DetType::CALORIMETER | DetType::BARREL ) ) ; 
0123   printDetectorSets( " endcap calorimeters : " , ( DetType::CALORIMETER | DetType::ENDCAP ) ) ; 
0124 
0125   // everything that is not TRACKER or CALORIMETER
0126   printDetectorSets( " other detecors : " , ( DetType::IGNORE ) , ( DetType::CALORIMETER | DetType::TRACKER ) ) ; 
0127 
0128 
0129   if( printDetData ){
0130 
0131     dd4hep::Detector::HandleMap dets = description.detectors() ;
0132 
0133     for( dd4hep::Detector::HandleMap::const_iterator it = dets.begin() ; it != dets.end() ; ++it ){
0134       
0135       DetElement det = it->second ;
0136 
0137       std::cout << " ---------------------------- " << det.name() << " ----------------------------- " << std::endl ;
0138 
0139       DetType type( det.typeFlag() ) ;
0140       
0141       std::cout << " ------     " << type << std:: endl ;
0142 
0143       printDetectorData( det ) ;
0144 
0145     }
0146     
0147     std::cout << "############################################################################### "  << std::endl  ;
0148 
0149     return 0;
0150   }
0151 
0152 
0153 
0154 
0155   dd4hep::Detector::HandleMap sensDet = description.sensitiveDetectors() ;
0156 
0157 
0158   std::cout << "############################################################################### "  << std::endl  
0159             << "     sensitive detectors:     " << std::endl ;
0160 
0161   for( dd4hep::Detector::HandleMap::const_iterator it = sensDet.begin() ; it != sensDet.end() ; ++it ){
0162 
0163     SensitiveDetector sDet = it->second ;
0164     std::cout << "     " << it->first << " : type = " << sDet.type() << std::endl ;
0165   }
0166 
0167 
0168   std::cout << "############################################################################### "  << std::endl  << std::endl  ;
0169     
0170 
0171   //------------------ breadth first tree traversal ---------
0172   std::list< DetElement > dets ;
0173   std::list< DetElement > daugs ; 
0174   std::list< DetElement > gdaugs ; 
0175   daugs.emplace_back( world ) ;
0176   while( ! daugs.empty() ) {
0177     for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){
0178       DetElement dau = *li ;
0179       DetElement::Children chMap = dau.children() ;
0180       for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){
0181         DetElement de = (*it).second ;
0182         gdaugs.emplace_back( de ) ;
0183       }  
0184     }
0185     dets.splice( dets.end() , daugs ) ;
0186     daugs.splice( daugs.end() , gdaugs ) ;
0187   }
0188   //------------------ end tree traversal ---------
0189   
0190 
0191   for (  std::list< DetElement >::const_iterator it=dets.begin() ; it != dets.end() ; ++it ){
0192 
0193     DetElement de = (*it) ;
0194     
0195     DetElement mother = de.parent() ;
0196     unsigned parentCount = 0 ;
0197     while( mother.isValid() ) {
0198       mother = mother.parent() ;
0199       ++parentCount ;
0200     } 
0201 
0202     SurfaceHelper surfMan( de ) ;
0203 
0204     const SurfaceList& sL = surfMan.surfaceList() ;
0205 
0206     std::cout << "DetElement: " ;
0207     
0208     for(unsigned i=0 ; i < parentCount ; ++i ) std::cout << "\t" ;
0209 
0210     std::cout << de.name() << "[ path: "<< de.placementPath ()  <<  "] (id: " << de.id() << ") - sens type : " << description.sensitiveDetector( de.name() ).type() << "\t surfaces : " <<  ( sL.empty() ? 0 : sL.size()  ) << std::endl ;
0211 
0212 
0213     //    printDetectorData( de ) ;
0214 
0215     if( printSurfaces ){
0216       for( SurfaceList::const_iterator sit = sL.begin() ; sit != sL.end() ; ++sit ){
0217     const ISurface* surf =  *sit ;
0218     std::cout << " ------------------------- " 
0219           << " surface: "  << *surf         << std::endl
0220           << " ------------------------- "  << std::endl ;
0221       }
0222     }
0223   }
0224 
0225   std::cout << "############################################################################### "  << std::endl  << std::endl  ;
0226 
0227   //    FixedPadSizeTPCData* tpc = tpcDE.extension<FixedPadSizeTPCData>() ;
0228 
0229   return 0;
0230 }
0231 
0232 
0233 int main(int argc, char** argv ){
0234   try {
0235     return invoke_dump_detector(argc,argv);
0236   }
0237   catch(const std::exception& e)  {
0238     std::cout << "Got uncaught exception: " << e.what() << std::endl;
0239   }
0240   catch (...)  {
0241     std::cout << "Got UNKNOWN uncaught exception." << std::endl;
0242   }
0243   return EINVAL;    
0244 }
0245 
0246 //=============================================================================