6 #include "gear/geartgeo/MaterialMap.h"
7 #include "gear/GearDistanceProperties.h"
12 double ymin,
double ymax,
int nysteps,
13 double zmin,
double zmax,
int nzsteps,
int coord)
16 if(xmax<xmin || ymax<ymin || zmax<zmin)
17 throw gear::Exception(
"MaterialMap constructor: Grid range error (max value is smaller than min)!");
18 if(nxsteps<0 || nysteps<0 || nzsteps<0)
19 throw gear::Exception(
"MaterialMap constructor: Grid step error (number of steps must be positive number)!");
29 throw gear::Exception(
"MaterialMap constructor: Grid range error (r>0 for cylindrical coordinates)!");
30 if(ymin<0 || ymin>2*M_PI || ymax<0 || ymax>2*M_PI)
31 throw gear::Exception(
"MaterialMap constructor: Grid range error (0<phi<2Pi for cylindrical coordinates)!");
38 throw gear::Exception(
"MaterialMap constructor: Grid range error (r>0 for shperical coordinates)!");
39 if(ymin<0 || ymin>M_PI || ymax<0 || ymax>M_PI)
40 throw gear::Exception(
"MaterialMap constructor: Grid range error (0<theta<Pi for spherical coordinates)!");
41 if(zmin<0 || zmin>2*M_PI || zmax<0 || zmax>2*M_PI)
42 throw gear::Exception(
"MaterialMap constructor: Grid range error (0<phi<2Pi for spherical coordinates)!");
46 throw gear::Exception(
"MaterialMap constructor: unkown coordinate type");
62 _myMap.resize(nxsteps+1);
63 for(
int s=0;s<=nxsteps;++s)
65 _myMap[s].resize(nysteps+1);
66 for(
int s2=0;s2<=nysteps;++s2)
67 _myMap[s][s2].resize(nzsteps+1);
73 _xstep=(xmax-xmin)/nxsteps;
77 _ystep=(ymax-ymin)/nysteps;
81 _zstep=(zmax-zmin)/nzsteps;
89 for(
double x= xmin;x<=xmax;x+=_xstep)
91 for(
double y= ymin;y<=ymax;y+=_ystep)
93 for(
double z= zmin;z<=zmax;z+=_zstep)
114 final[0]=x*sin(y)*cos(z);
115 final[1]=x*sin(y)*sin(z);
120 throw gear::Exception(
"MaterialMap constructor: unkown coordinate type");
129 _values.first=gDP.
getNRadlen( initial,
final);
130 _values.second=gDP.
getNIntlen( initial,
final);
132 std::vector<int> pos;
133 calculateGridIndex(pos,x,y,z);
134 _myMap[pos[0]][pos[1]][pos[2]]=_values;
143 std::vector<int> pos;
144 calculateGridIndex(pos,x,y,z);
145 std::pair<double,double> result;
146 interpolateOnGrid(result,x,y,z);
147 return result.second;
153 std::vector<int> pos;
154 calculateGridIndex(pos,x,y,z);
155 std::pair<double,double> result;
156 interpolateOnGrid(result,x,y,z);
160 void MaterialMap::calculateGridIndex(std::vector<int> & gpos,
double x,
double y,
double z)
const
163 if(x+1e-5<_xmin || x-1e-5>_xmax || y+1e-5<_ymin || y-1e-5>_ymax || z+1e-5<_zmin || z-1e-5>_zmax)
164 throw Exception(
"Coordinate not found in MaterialMap!");
167 gpos[0]=int((x-_xmin)/_xstep+0.5);
168 gpos[1]=int((y-_ymin)/_ystep+0.5);
169 gpos[2]=int((z-_zmin)/_zstep+0.5);
172 void MaterialMap::interpolateOnGrid(std::pair<double,double> &result,
double x,
double y,
double z)
const
175 double px[2],py[2],pz[2];
176 px[0]=x-fmod(x-_xmin,_xstep);
178 py[0]=y-fmod(y-_ymin,_ystep);
180 pz[0]=z-fmod(z-_zmin,_zstep);
183 int xcount=0,ycount=0,zcount=0;
184 if(_xmin<=px[0] && px[0]<=_xmax)
186 if(_xmin<=px[1] && px[1]<=_xmax)
188 if(_ymin<=py[0] && py[0]<=_ymax)
190 if(_ymin<=py[1] && py[1]<=_ymax)
192 if(_zmin<=pz[0] && pz[0]<=_zmax)
194 if(_zmin<=pz[1] && pz[1]<=_zmax)
198 double sumIntL=0,sumRadL=0,sumWeight=0;
200 for(
int ix=0;ix<xcount;ix++)
202 for(
int iy=0;iy<ycount;iy++)
204 for(
int iz=0;iz<zcount;iz++)
206 double d=sqrt((x-px[ix])*(x-px[ix])+(y-py[iy])*(y-py[iy])+(z-pz[iz])*(z-pz[iz]));
207 std::vector<int> gpos;
208 calculateGridIndex(gpos,px[ix],py[iy],pz[iz]);
209 std::pair<double,double> vals=_myMap[gpos[0]][gpos[1]][gpos[2]];
221 sumRadL+=vals.first/d;
222 sumIntL+=vals.second/d;
232 result.first=sumRadL/sumWeight;
233 result.second=sumIntL/sumWeight;
static const int CYLINDRICAL
coord=1 : CYLINDRICAL (r,phi,z)
double getRadiationLength(double x, double y, double z) const
Returns the radiation length from the vertex at (0,0,0) to (x,y,z) using a distance wheighted interpo...
Abstract interface for a class that returns the (material) properties along a given distance between ...
virtual double getNIntlen(const Vector3D &p0, const Vector3D &p1) const =0
The number of interaction lengths along the distance between [p0,p1] .
Base exception class for GEAR - all other exceptions extend this.
virtual const GearDistanceProperties & getDistanceProperties() const =0
Get the distance properties object.
virtual double getNRadlen(const Vector3D &p0, const Vector3D &p1) const =0
The number of radiation lengths along the distance between [p0,p1] .
Simple three dimensional vector providing the components for cartesian, cylindrical and spherical coo...
static const int CARTESIAN
coord=0 : CARTESIAN (x,y,z)
static const int SPHERICAL
coord=2 : SPERICAL (r,theta,phi)
Abstract interface for a manager class that returns the Gear classes for the relevant subdetectors...
MaterialMap(GearMgr *gearMgr, double xmin, double xmax, int nxsteps, double ymin, double ymax, int nysteps, double zmin, double zmax, int nzsteps, int coord)
Should be called through the MaterialMapFactory! Creating a material map in memory.
double getInteractionLength(double x, double y, double z) const
Returns the interaction length from the vertex at (0,0,0) to (x,y,z) using a distance wheighted inter...