GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
printMaterials.cc
1 
2 #include "gearimpl/Util.h"
3 #include "gearxml/GearXML.h"
4 #include "gear/GearMgr.h"
5 #include "gear/GEAR.h"
6 
7 #include "geartgeo/TGeoGearDistanceProperties.h"
8 #include "geartgeo/TGeoGearPointProperties.h"
9 
10 #include <iostream>
11 #include <assert.h>
12 
13 #include <exception>
14 #include <typeinfo>
15 #include <cstdlib>
16 
17 #include <sstream>
18 #include <fstream>
19 #include <math.h>
20 
21 using namespace gear ;
22 
23 
24 void gear_unexpected(){
25 
26  try {
27 
28  throw ;
29 
30  } catch( std::exception& e) {
31 
32  std::cout << " A runtime error has occured : "
33  << e.what()
34  << std::endl
35  << " the program will have to be terminated - sorry." << std::endl ;
36  exit(1) ;
37  }
38 }
39 
40 
46 int main(int argc, char**argv){
47 
48 
49  std::set_terminate( gear_unexpected ) ;
50 
51  if( argc != 8 ) {
52  std::cout << " printMaterials: print all materials between two points given in [mm]: " << std::endl
53  << " usage: \n"
54  << " printMaterials gearFile.xml x0 y0 z0 x1 y1 z1 " << std::endl ;
55  exit(1) ;
56  }
57 
58  //----------------------------------
59  std::stringstream ss ;
60  ss << argv[2] << " " << argv[3] << " " << argv[4] << " " << argv[5] << " " << argv[6] << " " << argv[7] ;
61  float x0,y0,z0,x1,y1,z1 ;
62 
63  ss >> x0 >> y0 >> z0 >> x1 >> y1 >> z1 ;
64 
65  if( !ss){
66  std::cout << " *** Number Format Error: " << ss.str() << std::endl;
67  exit(1) ;
68  }
69  //-----------------------------------
70 
71 
72  std::string fileName( argv[1] ) ;
73 
74  GearXML gearXML( fileName ) ;
75 
76  GearMgr* gearMgr = gearXML.createGearMgr() ;
77 
78 
80 
81  //===========================================================
82 
83 
84 
85  gear::Vector3D p0( x0 , y0 , z0 ) ;
86 
87  gear::Vector3D p1( x1 , y1 , z1 ) ;
88 
89  std::cout << " ############################################################ "
90  << " materials between the two points : \n "
91  << p0
92  << p1
93  << " ############################################################# "
94  << std::endl ;
95 
96  //convert all lengths to cm for TGeo
97  p0 = .1 * p0 ;
98  p1 = .1 * p1 ;
99 
100  gear::Vector3D dir = p1 - p0 ;
101  dir = ( 1. / dir.r() ) * dir ;
102 
103  std::vector<std::string> names = distProp.getMaterialNames( p0 , p1 ) ;
104 
105  std::vector<double> thicks = distProp.getMaterialThicknesses( p0 , p1 ) ;
106 
107  double lambda = 0. ;
108 
109 
110  for(unsigned j=0 ; j < names.size() ; ++j){
111 
112  //gear::Vector3D prev = p0 + lambda * dir ;
113  gear::Vector3D prev = p0 ;
114 
115  lambda += thicks[j] ;
116 
117  gear::Vector3D next = p0 + lambda * dir ;
118 
119  double rL = distProp.getNRadlen( prev, next ) ;
120  double iL = distProp.getNIntlen( prev, next ) ;
121 
122  // std::cout << " " << names[j] << " - " << thicks[j] * 10. << " " << rL << std::endl ;
123  // printf( "%25s %1.8e %1.8e \n" , names[j].c_str() , thicks[j] * 10. , rL ) ;
124 
125  printf( "%25s %1.8e, %1.8e, %1.8e, %1.8e %1.8e %1.8e - %1.8e %1.8e %1.8e \n" ,
126  names[j].c_str() , thicks[j] * 10., rL, iL ,
127  prev[0]*10., prev[1]*10., prev[2]*10., next[0]*10., next[1]*10., next[2]*10. ) ;
128 
129  }
130 }
131 
132 
virtual double getNRadlen(const Vector3D &p0, const Vector3D &p1) const
The number of radiation lengths along the distance between [p0,p1] .
virtual double getNIntlen(const Vector3D &p0, const Vector3D &p1) const
The number of interaction lengths along the distance between [p0,p1] .
virtual const std::vector< std::string > & getMaterialNames(const Vector3D &p0, const Vector3D &p1) const
List of matrial names along the distance between [p0,p1]- WARNING: this method returns a reference to...
virtual const GearDistanceProperties & getDistanceProperties() const =0
Get the distance properties object.
TGeo Implementation of the abstract interface that returns the (material) properties along a given di...
Implementation of GEAR using XML.
Definition: GearXML.h:18
Simple three dimensional vector providing the components for cartesian, cylindrical and spherical coo...
Definition: Vector3D.h:18
virtual const std::vector< double > & getMaterialThicknesses(const Vector3D &p0, const Vector3D &p1) const
List of matrial thicknesses in mm along the distance between [p0,p1] - runs parallel to the array ret...
double r() const
Spherical r/magnitude.
Definition: Vector3D.h:119
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
Definition: GearMgr.h:36