DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
print_materials.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 //==========================================================================
11 // Simple program to print all the materials in a detector on
12 // a straight line between two given points
13 //
14 // Author : F.Gaede, DESY
15 //
16 //==========================================================================
17 
18 // Framework include files
19 #include "DD4hep/Detector.h"
20 #include "DD4hep/DD4hepUnits.h"
21 #include "DDRec/MaterialManager.h"
22 
23 using namespace std ;
24 using namespace dd4hep::detail;
25 using namespace dd4hep::rec;
26 using namespace dd4hep ;
27 
28 
29 //=============================================================================
30 #include "main.h"
31 
32 int main_wrapper(int argc, char** argv ){
33 
34  if( argc != 8 ) {
35  std::cout << " usage: print_materials compact.xml x0 y0 z0 x1 y1 z1 " << std::endl
36  << " -> prints the materials on a straight line between the two given points ( unit is cm) "
37  << std::endl ;
38  exit(1) ;
39  }
40 
41  std::string inFile = argv[1] ;
42 
43  std::stringstream sstr ;
44  sstr << argv[2] << " " << argv[3] << " " << argv[4] << " " << argv[5] << " " << argv[6] << " " << argv[7] ;
45 
46  double x0,y0,z0,x1,y1,z1 ;
47  sstr >> x0 ;
48  sstr >> y0 ;
49  sstr >> z0 ;
50  sstr >> x1 ;
51  sstr >> y1 ;
52  sstr >> z1 ;
53 
54  Detector& description = Detector::getInstance();
55 
56  description.fromCompact( inFile );
57 
58  Vector3D p0( x0, y0, z0 ) ;
59  Vector3D p1( x1, y1, z1 ) ;
60 
61  MaterialManager matMgr( description.world().volume() ) ;
62 
63  const MaterialVec& materials = matMgr.materialsBetween( p0 , p1 ) ;
64 
65  std::cout << std::endl << " ####### materials between the two points : " << p0 << "*cm and " << p1 << "*cm : " << std::endl ;
66 
67  double sum_x0 = 0 ;
68  double sum_lambda = 0 ;
69  double path_length = 0 ;
70  for( unsigned i=0,n=materials.size();i<n;++i){
71 
72  Material mat = materials[i].first ;
73  double length = materials[i].second ;
74 
75  double nx0 = length / mat.radLength() ;
76  sum_x0 += nx0 ;
77 
78  double nLambda = length / mat.intLength() ;
79  sum_lambda += nLambda ;
80 
81  path_length += length ;
82 
83  std::cout << " " << mat << " thickness: " << length << " path_length:" << path_length << " integrated_X0: " << sum_x0 << " integrated_lambda: " << sum_lambda << std::endl ;
84  }
85 
86  std::cout << "############################################################################### " << std::endl << std::endl ;
87 
88 
89  const MaterialData& avMat = matMgr.createAveragedMaterial( materials ) ;
90 
91  std::cout << " averaged Material : " << " Z: " << avMat.Z() << " A: " << avMat.A() << " densitiy: " << avMat.density()
92  << " radiationLength: " << avMat.radiationLength()
93  << " interactionLength: " << avMat.interactionLength() << std::endl << std::endl ;
94 
95 
96  std::cout << " Total length : " << path_length / dd4hep::mm << " mm " << std::endl ;
97 
98  std::cout << " Integrated radiation lengths : " << path_length / avMat.radiationLength() << " X0 " << std::endl ;
99 
100  std::cout << " Integrated interaction lengths : " << path_length / avMat.interactionLength() << " lambda " << std::endl ;
101 
102  std::cout << "############################################################################### " << std::endl << std::endl ;
103 
104 
105  return 0;
106 }
107 
108 //=============================================================================
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
dd4hep::rec
Namespace for the reconstruction part of the AIDA detector description toolkit.
Definition: SurfaceInstaller.h:28
dd4hep::rec::MaterialData::radiationLength
virtual double radiationLength() const
radiation length - tgeo units
Definition: Material.h:170
dd4hep::rec::MaterialData::density
virtual double density() const
density
Definition: Material.h:167
dd4hep::rec::Vector3D
Definition: Vector3D.h:32
Detector.h
dd4hep::rec::MaterialManager::createAveragedMaterial
MaterialData createAveragedMaterial(const MaterialVec &materials)
Definition: MaterialManager.cpp:196
dd4hep::rec::MaterialData::interactionLength
virtual double interactionLength() const
interaction length - tgeo units
Definition: Material.h:173
dd4hep::rec::MaterialVec
std::vector< std::pair< Material, double > > MaterialVec
Definition: MaterialManager.h:30
dd4hep::Material::intLength
double intLength() const
Access the interaction length of the underlying material.
Definition: Objects.cpp:221
dd4hep::Material
Handle class describing a material.
Definition: Objects.h:272
dd4hep::detail
DD4hep internal namespace.
Definition: Alignments.h:32
dd4hep::DetElement::volume
Volume volume() const
Access to the logical volume of the detector element's placement.
Definition: DetElement.cpp:352
dd4hep::rec::MaterialManager
Definition: MaterialManager.h:41
dd4hep::Detector::fromCompact
virtual void fromCompact(const std::string &fname, DetectorBuildType type=BUILD_DEFAULT)=0
Deprecated call (use fromXML): Read compact geometry description or alignment file.
dd4hep::rec::MaterialData::A
virtual double A() const
averaged atomic number
Definition: Material.h:164
dd4hep::rec::MaterialManager::materialsBetween
const MaterialVec & materialsBetween(const Vector3D &p0, const Vector3D &p1, double epsilon=1e-4)
Definition: MaterialManager.cpp:40
dd4hep::rec::MaterialData
Definition: Material.h:33
dd4hep::rec::MaterialData::Z
virtual double Z() const
averaged proton number
Definition: Material.h:161
main.h
MaterialManager.h
std
Definition: Plugins.h:30
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::Material::radLength
double radLength() const
Access the radiation length of the underlying material.
Definition: Objects.cpp:210
DD4hepUnits.h
main_wrapper
int main_wrapper(int argc, char **argv)
Definition: print_materials.cpp:32