Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:12:44

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 #ifndef DDREC_MATERIALMANAGER_H
0014 #define DDREC_MATERIALMANAGER_H
0015 
0016 #include "DD4hep/Detector.h"
0017 #include "DD4hep/Objects.h"
0018 #include "DDRec/Vector3D.h"
0019 #include "DDRec/Material.h"
0020 #include "DD4hep/DD4hepUnits.h"
0021 
0022 #include <vector>
0023 
0024 
0025 class TGeoManager ;
0026 
0027 namespace dd4hep {
0028   namespace rec {
0029 
0030     typedef std::vector< std::pair< Material, double > >     MaterialVec;
0031     typedef std::vector< std::pair< PlacedVolume, double > > PlacementVec;
0032     
0033     /** Material manager provides access to the material properties of the detector.
0034      *  Material can be accessed either for a given point or as a list of materials along a straight
0035      *  line between two points.
0036      *
0037      * @author F.Gaede, DESY
0038      * @date May, 19 2014
0039      * @version $Id:$
0040      */
0041     class MaterialManager {
0042 
0043     public:
0044       static constexpr const double epsilon = 1e-4;
0045       
0046     public:
0047 
0048       /// Instantiate the MaterialManager for this (world) volume
0049       MaterialManager(Volume world);
0050 
0051 #if defined(G__ROOT)
0052       MaterialManager() = default ;
0053 #else
0054       MaterialManager() = delete ;
0055 #endif
0056 
0057       ~MaterialManager();
0058 
0059       class ScanData  {
0060       public:
0061         const MaterialVec&  materials;
0062         const PlacementVec& places;
0063       };
0064       
0065       /** Get a vector with all the materials between the two points p0 and p1 with the corresponding thicknesses -
0066        *  element type is  std::pair< Material, double >. Materials with a thickness smaller than epsilon (default 1e-4=1mu)
0067        *  are ignored. Avoid calling this method in inner loops as the computation is not cheap. Ideally the result should be cached,
0068        *  for example as an averaged material @see createAveragedMaterial().
0069        */
0070       const MaterialVec& materialsBetween(const Vector3D& p0,
0071                                           const Vector3D& p1,
0072                                           double eps = MaterialManager::epsilon);
0073       /// As above, but optionally allow access to traversed placements
0074       const ScanData     entriesBetween(const Vector3D& p0,
0075                                         const Vector3D& p1,
0076                                         double eps = MaterialManager::epsilon);
0077 
0078       /** Get a vector with all the placements between the two points p0 and p1
0079        */
0080       const PlacementVec& placementsBetween(const Vector3D& p0, const Vector3D& p1 , double eps = MaterialManager::epsilon );
0081       
0082       /** Get the material at the given position.
0083        */
0084       const Material& materialAt(const Vector3D& pos );
0085 
0086       /** Get the placed volume at the given position.
0087        */
0088       PlacedVolume placementAt(const Vector3D& pos );
0089 
0090       /** Create a material with averaged properties from all materials in the list. 
0091        *  A and Z are averaged by relative number of atoms(molecules), rho is averaged by relative volume
0092        *  and the inverse radiation and interaction lengths are averaged by relative weight. 
0093        */
0094       MaterialData createAveragedMaterial( const MaterialVec& materials ) ;
0095 
0096     protected :
0097       /// Cached materials
0098       MaterialVec  _mV ;
0099       Material     _m ;
0100       /// Cached nodes
0101       PlacedVolume _pv;
0102       PlacementVec _placeV;
0103       /// cached last points
0104       Vector3D     _p0 , _p1, _pos ;
0105       /// Reference to the TGeoManager
0106       TGeoManager* _tgeoMgr ;
0107     };
0108 
0109     /// dump Material operator 
0110     inline std::ostream& operator<<( std::ostream& os , const Material& m ) {
0111       os << "  " << m.name() << " Z: " << m.Z() << " A: " << m.A() << " density: " << m.density() 
0112          << " radiationLength: "  <<  m.radLength() 
0113          << " interactionLength: " << m.intLength() ;
0114       return os ;
0115     }
0116     
0117     /// dump MaterialVec operator 
0118     inline std::ostream& operator<<( std::ostream& os , const MaterialVec& m ) {
0119       for( unsigned i=0,n=m.size() ; i<n ; ++i ) {
0120         os << "  material: " << m[i].first << " thickness: " << m[i].second << std::endl ; 
0121       }
0122       return os ;
0123     }
0124 
0125   } /* namespace rec */
0126 } /* namespace dd4hep */
0127 
0128 
0129 
0130 #endif // DDREC_MATERIALMANAGER_H