GEAR  1.6.1
 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_unexpected( gear_unexpected ) ;
50  std::set_terminate( gear_unexpected ) ;
51 
52  if( argc != 8 ) {
53  std::cout << " printMaterials: print all materials between two points given in [mm]: " << std::endl
54  << " usage: \n"
55  << " printMaterials gearFile.xml x0 y0 z0 x1 y1 z1 " << std::endl ;
56  exit(1) ;
57  }
58 
59  //----------------------------------
60  std::stringstream ss ;
61  ss << argv[2] << " " << argv[3] << " " << argv[4] << " " << argv[5] << " " << argv[6] << " " << argv[7] ;
62  float x0,y0,z0,x1,y1,z1 ;
63 
64  ss >> x0 >> y0 >> z0 >> x1 >> y1 >> z1 ;
65 
66  if( !ss){
67  std::cout << " *** Number Format Error: " << ss.str() << std::endl;
68  exit(1) ;
69  }
70  //-----------------------------------
71 
72 
73  std::string fileName( argv[1] ) ;
74 
75  GearXML gearXML( fileName ) ;
76 
77  GearMgr* gearMgr = gearXML.createGearMgr() ;
78 
79 
81 
82  //===========================================================
83 
84 
85 
86  gear::Vector3D p0( x0 , y0 , z0 ) ;
87 
88  gear::Vector3D p1( x1 , y1 , z1 ) ;
89 
90  std::cout << " ############################################################ "
91  << " materials between the two points : \n "
92  << p0
93  << p1
94  << " ############################################################# "
95  << std::endl ;
96 
97  //convert all lengths to cm for TGeo
98  p0 = .1 * p0 ;
99  p1 = .1 * p1 ;
100 
101  gear::Vector3D dir = p1 - p0 ;
102  dir = ( 1. / dir.r() ) * dir ;
103 
104  std::vector<std::string> names = distProp.getMaterialNames( p0 , p1 ) ;
105 
106  std::vector<double> thicks = distProp.getMaterialThicknesses( p0 , p1 ) ;
107 
108  double lambda = 0. ;
109 
110 
111  for(unsigned j=0 ; j < names.size() ; ++j){
112 
113  //gear::Vector3D prev = p0 + lambda * dir ;
114  gear::Vector3D prev = p0 ;
115 
116  lambda += thicks[j] ;
117 
118  gear::Vector3D next = p0 + lambda * dir ;
119 
120  double rL = distProp.getNRadlen( prev, next ) ;
121  double iL = distProp.getNIntlen( prev, next ) ;
122 
123  // std::cout << " " << names[j] << " - " << thicks[j] * 10. << " " << rL << std::endl ;
124  // printf( "%25s %1.8e %1.8e \n" , names[j].c_str() , thicks[j] * 10. , rL ) ;
125 
126  printf( "%25s %1.8e, %1.8e, %1.8e, %1.8e %1.8e %1.8e - %1.8e %1.8e %1.8e \n" ,
127  names[j].c_str() , thicks[j] * 10., rL, iL ,
128  prev[0]*10., prev[1]*10., prev[2]*10., next[0]*10., next[1]*10., next[2]*10. ) ;
129 
130  }
131 }
132 
133 
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