7 #include "StiMaterial.h"
9 #include "StiPlanarShape.h"
10 #include "StiCylindricalShape.h"
11 #include "StiPlacement.h"
12 #include "StiDetectorContainer.h"
13 #include "StiDetector.h"
16 #include "StiMapUtilities.h"
18 int StiDetector::mgIndex=0;
19 double StiDetector::mgValue[2]={0};
23 StiDetector::StiDetector()
28 void StiDetector::reset()
31 memset(mBeg,0,mEnd-mBeg+1);
37 StiDetector::~StiDetector()
45 gas = detector.getGas();
47 shape = detector.getShape();
55 ostream& operator<<(ostream& os,
const StiDetector& d)
57 os <<
"StiDetector:" << endl
59 <<
"\t_groupId: " << d.getGroupId()
60 <<
"\tR:"<<d.getPlacement()->getNormalRadius()<<
"cm\tA:"
61 <<d.getPlacement()->getNormalRefAngle()<<
" radians" << endl;
75 int StiDetector::splitIt(StiDetVect &vect,
double dXdY,
int nMax)
77 static int nCall=0; nCall++;
83 int iShape =
shape->getShapeCode();
84 float deltaX =
shape->getThickness();
85 float halfZ =
shape->getHalfDepth();
86 float halfY =
shape->getHalfWidth();
87 float angle =
shape->getOpeningAngle();
88 float nRadius =
placement->getNormalRadius();
89 if (iShape >= kCylindrical) nRadius =
shape->getOuterRadius()-deltaX/2;
91 if (nRadius < deltaX/2) {
92 printf(
"StiDetector::splitIt %s Non splitable Rnormal < thickness/2 %g %g\n"
93 ,
getName().c_str(),nRadius,deltaX/2);
96 int ny = deltaX/(halfY*2*dXdY)+0.5;
97 int nz = deltaX/(halfZ*2*dXdY)+0.5;
98 int nSplit = (ny>nz)? ny:nz;
99 if (nSplit<=1)
return 1;
100 if (nSplit>nMax) nSplit=nMax;
105 float dX = deltaX/nSplit;
106 double sumWeight = 0;
107 for (
int iSplit=0; iSplit<nSplit; iSplit++)
109 float xc = -deltaX/2 +dX/2+iSplit*dX;
114 if (iSplit) { ts+=
"_"; ts+=iSplit;}
118 if (iSplit) { ts+=
"_"; ts+=iSplit;}
120 float myRadius = nRadius+xc;
121 assert(myRadius>1e-2 && myRadius < 1e3);
122 if (iShape==kPlanar) {
125 }
else if (iShape>=kCylindrical) {
128 }
else { assert(0 &&
"Wrong shape type");}
133 place->setNormalRep(
placement->getNormalRefAngle(),myRadius,
placement->getNormalYoffset());
134 det->setShape(myShape);
135 place->setLayerRadius(myRadius);
136 det->setPlacement(place);
137 sumWeight += det->getWeight();
140 this->copy(*vect[0]);
143 StiToolkit::instance()->getDetectorFactory()->
free(vect[0]);
153 double StiDetector::getVolume()
const
155 return shape->getVolume();
158 double StiDetector::getWeight()
const
163 int StiDetector::insideL(
const double xl[3],
int mode,
double fakt)
const
165 static int nCall = 0; nCall++;
167 double rN =
placement->getNormalRadius();
168 double acc = rN*(fakt-1);
169 if (acc<0.1) acc = 0.1;
170 if (acc>10.) acc = 10.;
173 double thick =
shape->getThickness();
175 if (
shape->getShapeCode()==1) {
178 mgValue[1] = thick/2;
179 mgValue[0] = fabs(xl[0]-rN)-mgValue[1];
180 if (mgValue[0]>acc)
return 0;
184 double y = xl[1]-
placement->getNormalYoffset();
185 mgValue[1] =
shape->getHalfWidth();
186 mgValue[0] = fabs(y)-mgValue[1];
187 if (mgValue[0]>acc)
return 0;
192 mgValue[1] = thick/2;
193 double rxy = sqrt(xl[0]*xl[0]+xl[1]*xl[1]);
194 mgValue[0] = (fabs(rxy-rN)-mgValue[1]);
195 if (mgValue[0]>acc)
return 0;
200 double ang = atan2(xl[1],xl[0]);
201 if (ang<-M_PI) ang +=M_PI*2;
202 if (ang> M_PI) ang -=M_PI*2;
203 mgValue[1] =
shape->getOpeningAngle()/2;
204 mgValue[0] = (fabs(ang)-mgValue[1]);
205 if (mgValue[0]>acc/rN)
return 0;
208 if (!(mode&4))
return 1;
210 mgValue[1] =
shape->getHalfDepth();
211 double z = xl[2]-
placement->getZcenter();
212 mgValue[0] = (fabs(z)-mgValue[1]);
213 if (mgValue[0]>acc && fabs(xl[2]) > 100)
return 0;
230 setIsActive(activeFunctor);
232 setPlacement(placement);
234 setMaterial(material);
237 int StiDetector::insideG(
const double xl[3],
int mode,
double fakt)
const
240 double alfa = getPlacement()->getNormalRefAngle();
242 return insideL(&xg[0],mode,fakt);
245 void StiDetector::getDetPlane(
double plane[4])
const
247 plane[0] = - getPlacement()->getNormalRadius();
void setProperties(std::string name, StiIsActiveFunctor *activeFunctor, StiShape *shape, StiPlacement *placement, StiMaterial *gas, StiMaterial *material)
double _cos
Convenience storage of cos(refAngle)
int _groupId
Detector group identifier.
StiIsActiveFunctor * isActiveFunctor
virtual void free(Abstract *obj)=0
Free an object for reuse.
StiMaterial * material
Discrete scatterer attributes.
StiPlacement * placement
Physical position and orientation of this detector or volume.
virtual Abstract * getInstance()=0
Get a pointer to instance of objects served by this factory.
StiMaterial * gas
Continuous scatter attributes.
function object for determine a detector's active regions
double _sin
Convenience storage of sin(refAngle)
StiShape * shape
Physical Shape attribute of this detector or voloume.
void setName(const string &newName)
Set the name of the object.
double getDensity() const
Get the material density in grams/cubic centimeter.
const string & getName() const
Get the name of the object.