9 #include <phgeom/PHGeomUtility.h>
11 #include <TGeoManager.h>
35 beamProfile =
new TF2(
"beamProfile",
"exp(-0.5*(x-[0])*(x-[0])/[1]/[1])*exp(-0.5*(y-[2])*(y-[2])/[3]/[3])", -10., 10., -10., 10.);
36 beamProfile->SetParameter(0, 0.0);
37 beamProfile->SetParameter(1, 0.68);
38 beamProfile->SetParameter(2, 0.0);
39 beamProfile->SetParameter(3, 0.76);
50 if(node ==
NULL)
return;
60 for(
int i = 0; i < node->GetNdaughters(); ++i)
63 TGeoVolume* pv= node->GetDaughter(i)->GetVolume();
64 TGeoMatrix* mat= node->GetDaughter(i)->GetMatrix();
65 const Double_t* pos= mat->GetTranslation();
67 TGeoVolumeMulti* pv_multi;
68 pv_multi = (TGeoVolumeMulti*)pv;
70 TGeoShape *shape = pv->GetShape();
73 tube= (TGeoTube*)shape;
77 if(fabs(pos[0]) > 1. || fabs(pos[1]) > 7.|| pos[2]>500. || pos[2]<-800.)
continue;
79 if (node->GetDaughter(i)->GetNdaughters()==0){
81 TString name = pv->GetName();
87 if(name.Contains(
"Shielding"))
89 newObj.
length = 2.*box->GetDZ();
98 newObj.
N = newObj.
A-newObj.
Z;
103 newObj.
length = 2.*tube->GetDZ();
106 newObj.
radiusX = tube->GetRmax();
114 newObj.
N = newObj.
A-newObj.
Z;
119 interactables.push_back(newObj);
123 if(node->GetDaughter(i)->GetNdaughters()>0){
125 for(
int j=0; j<node->GetDaughter(i)->GetNdaughters();++j){
127 TGeoVolume* pv1= node->GetDaughter(i)->GetDaughter(j)->GetVolume();
128 TGeoMatrix* mat1= node->GetDaughter(i)->GetDaughter(j)->GetMatrix();
129 const Double_t* pos1= mat1->GetTranslation();
131 TGeoShape *shape1 = pv1->GetShape();
134 tube1= (TGeoTube*)shape1;
135 box1=(TGeoBBox*)shape1;
139 if(fabs(pos1[0]+pos[0]) > 1. || fabs(pos1[1]+pos[1]) > 1.|| (pos1[2]+pos[2])>500.)
continue;
141 TString name = pv1->GetName();
145 newObj1.
z0 = pos1[2]+pos[2];
147 if(name.Contains(
"fmag"))
150 newObj1.
length = 2.*box1->GetDZ();
152 newObj1.
z_up = newObj1.
z0 - 0.5*newObj1.
length + 10.*2.54;
167 newObj1.
length = 2.*box1->GetDZ();
171 if (fabs(x)<3.9 && fabs(y)<1.7){
176 newObj1.
N = newObj1.
A-newObj1.
Z;
181 interactables.push_back(newObj1);
184 std::sort(interactables.begin(), interactables.end());
191 std::sort(interactables.begin(), interactables.end());
195 TGeoMaterial* air =
new TGeoMaterial(
"Air");
198 unsigned int n_temp = interactables.size();
199 for(
unsigned int i = 1; i < n_temp; ++i)
201 if(fabs(interactables[i-1].z_down - interactables[i].z_up) < 0.1)
continue;
203 airgap.
z_up = interactables[i-1].z_down;
204 airgap.
z_down = interactables[i].z_up;
207 airgap.
name = Form(
"AirGap_%d", nGaps++);
210 airgap.
N= airgap.
A- airgap.
Z;
214 interactables.push_back(airgap);
216 std::sort(interactables.begin(), interactables.end());
220 double attenuationSum = 0.;
221 for(
unsigned int i = 0; i < interactables.size(); ++i)
223 interactables[i].attenuationSelf = 1. - TMath::Exp(-interactables[i].length/interactables[i].nucIntLen);
224 interactables[i].attenuation = (1. - attenuationSum)*interactables[i].attenuationSelf;
225 interactables[i].prob = interactables[i].attenuation*interactables[i].density*interactables[i].nucIntLen;
227 attenuationSum += interactables[i].attenuation;
232 nPieces = interactables.size();
234 interactables[0].accumulatedProb = 0.;
235 accumulatedProbs[0] = 0.;
236 for(
unsigned int i = 1; i < nPieces; ++i)
238 interactables[i].accumulatedProb = interactables[i-1].accumulatedProb + interactables[i-1].prob;
239 accumulatedProbs[i] = interactables[i].accumulatedProb;
242 accumulatedProbs[nPieces] = accumulatedProbs[nPieces-1] + interactables.back().prob;
243 probSum = accumulatedProbs[nPieces];
247 for(
int i = 0; i < nPieces+1; ++i)
249 accumulatedProbs[i] = accumulatedProbs[i]/accumulatedProbs[nPieces];
265 interactables.clear();
278 double z = interactables[index].getZ() + zOffset;
287 beamProfile->GetRandom2(x, y);
291 x=gRandom->Gaus(0.,0.414);
292 y=gRandom->Gaus(0.,0.343);
299 index = TMath::BinarySearch(nPieces+1, accumulatedProbs,gRandom->Uniform(0,1));
void traverse(TGeoNode *node, double &xvertex, double &yvertex, double &zvertex)
double length
the z position of upstram/downstream face and center
double density
nuclear interaction length in cm
void findInteractingPiece()
void InitRun(PHCompositeNode *topNode)
void generateVtxPerp(double &x, double &y)
double radiusX
length of the stuff