27 bool intersect_circles(
bool hel,
double startx,
double starty,
double rad_det,
double rad_trk,
double cx,
double cy,
double&
x,
double&
y)
29 double d2 = (cx*cx + cy*cy);
31 if(d > (rad_det + rad_trk))
35 if(d < fabs(rad_det - rad_trk))
40 double r2 = rad_trk*rad_trk;
43 double R2 = rad_det*rad_det;
44 double a = 0.5*(R2 - r2 +
d2)*d_inv;
50 double ux = -cy*d_inv;
52 double P3x1 = P2x + ux*
h;
53 double P3y1 = P2y + uy*
h;
56 double P3x2 = P2x + ux*
h;
57 double P3y2 = P2y + uy*
h;
59 double d1_2 = (startx - P3x1)*(startx - P3x1) + (starty - P3y1)*(starty - P3y1);
60 double d2_2 = (startx - P3x2)*(startx - P3x2) + (starty - P3y2)*(starty - P3y2);
79 cout<<
"usage: circle_gen <# of events> <max # of tracks per event> <output file name>"<<endl;
83 int main(
int argc,
char** argv)
86 unsigned int nmaxtracks=0;
87 unsigned int nevents=0;
89 bool all_same_track_number =
true;
92 bool faketracks =
true;
93 int nfaketracks = 250;
95 bool resolution_smear =
true;
96 double smear_x = (70.0e-4/sqrt(12.))/sqrt(2.0);
97 double smear_y = (70.0e-4/sqrt(12.))/sqrt(2.0);
98 double smear_z = 425.0e-4/sqrt(12.);
106 vector<double> radii;
107 radii.assign(nlayers,0.);
115 vector<double> smear_x_layer;smear_x_layer.assign(nlayers,0);
116 vector<double> smear_y_layer;smear_y_layer.assign(nlayers,0);
117 vector<double> smear_z_layer;smear_z_layer.assign(nlayers,0);
118 smear_x_layer[0] = (50.0e-4/sqrt(12.))/sqrt(2.0);
119 smear_y_layer[0] = (50.0e-4/sqrt(12.))/sqrt(2.0);
120 smear_z_layer[0] = (425.0e-4/sqrt(12.));
121 smear_x_layer[1] = (50.0e-4/sqrt(12.))/sqrt(2.0);
122 smear_y_layer[1] = (50.0e-4/sqrt(12.))/sqrt(2.0);
123 smear_z_layer[1] = (425.0e-4/sqrt(12.));
124 smear_x_layer[2] = (80.0e-4/sqrt(12.))/sqrt(2.0);
125 smear_y_layer[2] = (80.0e-4/sqrt(12.))/sqrt(2.0);
126 smear_z_layer[2] = (1000.0e-4/sqrt(12.));
127 smear_x_layer[3] = (80.0e-4/sqrt(12.))/sqrt(2.0);
128 smear_y_layer[3] = (80.0e-4/sqrt(12.))/sqrt(2.0);
129 smear_z_layer[3] = (1000.0e-4/sqrt(12.));
130 smear_x_layer[4] = (100.0e-4/sqrt(12.))/sqrt(2.0);
131 smear_y_layer[4] = (100.0e-4/sqrt(12.))/sqrt(2.0);
132 smear_z_layer[4] = (10000.0e-4/sqrt(12.));
133 smear_x_layer[5] = (100.0e-4/sqrt(12.))/sqrt(2.0);
134 smear_y_layer[5] = (100.0e-4/sqrt(12.))/sqrt(2.0);
135 smear_z_layer[5] = (10000.0e-4/sqrt(12.));
146 cout <<
"Circle Gen Code : running with layers = " << nlayers <<
" and resolution smearing = " << resolution_smear << endl;
148 double kappa_min=0.001;
149 double kappa_max=0.03;
153 double phi_max=6.28318530717958623;
154 double dzdl_min = -0.5;
155 double dzdl_max = 0.5;
159 ss.clear();ss.str(
"");
163 ss.clear();ss.str(
"");
167 ss.clear();ss.str(
"");
172 unsigned int track=0;
173 unsigned int nhits=0;
184 TFile*
ofile =
new TFile(filename.c_str(),
"recreate");
185 TTree* etree =
new TTree(
"events",
"event list");
186 TTree* otree =
new TTree(
"tracks",
"tracks in a single event");
187 otree->Branch(
"track", &track,
"track/i");
188 otree->Branch(
"nhits", &nhits,
"nhits/i");
189 otree->Branch(
"x_hits", x_hits,
"x_hits[nhits]/D");
190 otree->Branch(
"y_hits", y_hits,
"y_hits[nhits]/D");
191 otree->Branch(
"z_hits", z_hits,
"z_hits[nhits]/D");
192 otree->Branch(
"layer", layer,
"layer[nhits]/i");
193 otree->Branch(
"trk_kappa", &trk_kappa,
"trk_kappa/D");
194 otree->Branch(
"trk_d", &trk_d,
"trk_d/D");
195 otree->Branch(
"trk_phi", &trk_phi,
"trk_phi/D");
196 otree->Branch(
"trk_dzdl", &trk_dzdl,
"trk_dzdl/D");
197 otree->Branch(
"trk_z0", &trk_z0,
"trk_z0/D");
198 otree->Branch(
"charge", &charge,
"charge/b");
199 etree->Branch(
"tracklist", &otree);
201 double secondary_proportion=0.1;
211 for(
unsigned int ev=0;ev<nevents;ev++)
214 unsigned int ntracks = (
unsigned int)(rand.Uniform(1., nmaxtracks));
215 if (all_same_track_number) ntracks = (
unsigned int) nmaxtracks;
217 for(
unsigned int i=0;i<ntracks;i++)
219 kappa = rand.Uniform(kappa_min, kappa_max);
221 phi = rand.Uniform(phi_min, phi_max);
222 dzdl = rand.Uniform(dzdl_min, dzdl_max);
225 double temp = rand.Uniform(-1., 1.);
226 if(temp > 0.){hel =
true;}
231 if((fabs(phi) < 7.85398163397448279
e-01) || (fabs(phi - 3.1415926535897931) < 7.85398163397448279
e-01))
234 ux = sqrt(1./(1. + tanphi*tanphi));
235 if(phi > 1.57079632679489656 && phi < 4.71238898038468967){ux=-
ux;}
240 tanphi = tan(1.57079632679489656 - phi);
241 uy = sqrt(1./(tanphi*tanphi + 1.));
242 if(phi > 3.1415926535897931){uy=-
uy;}
247 double dispx = ux/kappa;
248 double dispy = uy/kappa;
249 double cx = dx + dispx;
250 double cy = dy + dispy;
260 for(
unsigned int l=0;l<radii.size();l++)
262 if(
intersect_circles(hel, startx, starty, radii[l], 1./kappa, cx, cy, x, y) ==
true)
268 if (resolution_smear) {
269 x_hits[nhits] += rand.Gaus(0.0,smear_x_layer[l]);
270 y_hits[nhits] += rand.Gaus(0.0,smear_y_layer[l]);
274 double D = sqrt((startx-x)*(startx-x) + (starty-y)*(starty-y));
280 if(v >= 0.999999){v=0.999999;}
286 double temp2 = D*0.5;
295 double dz = sqrt(s*s*dzdl*dzdl/(1. - dzdl*dzdl));
296 if(dzdl>0.){z = startz +
dz;}
297 else{z = startz -
dz;}
300 if (resolution_smear) {
301 z_hits[nhits] += rand.Gaus(0.0,smear_z_layer[l]);
305 if((x_hits[nhits] == x_hits[nhits]) && (y_hits[nhits] == y_hits[nhits]) && (z_hits[nhits] == z_hits[nhits]))
321 double v1x = x_hits[0];
322 double v1y = y_hits[0];
323 double v2x = x_hits[1];
324 double v2y = y_hits[1];
326 double diffx = v2x-v1x;
327 double diffy = v2y-v1y;
329 double cross = diffx*cy - diffy*cx;
332 if(cross < 0.){cross_sign=-1;}
342 if(hel==
true){charge=1;}
358 for(
unsigned int j=0;j<nfaketracks;j++) {
362 for(
unsigned int i=0;i<nlayers;i++)
365 kappa = rand.Uniform(kappa_min, kappa_max);
367 phi = rand.Uniform(phi_min, phi_max);
368 dzdl = rand.Uniform(dzdl_min, dzdl_max);
371 double temp = rand.Uniform(-1., 1.);
372 if(temp > 0.){hel =
true;}
377 if((fabs(phi) < 7.85398163397448279
e-01) || (fabs(phi - 3.1415926535897931) < 7.85398163397448279
e-01))
380 ux = sqrt(1./(1. + tanphi*tanphi));
381 if(phi > 1.57079632679489656 && phi < 4.71238898038468967){ux=-
ux;}
386 tanphi = tan(1.57079632679489656 - phi);
387 uy = sqrt(1./(tanphi*tanphi + 1.));
388 if(phi > 3.1415926535897931){uy=-
uy;}
393 double dispx = ux/kappa;
394 double dispy = uy/kappa;
395 double cx = dx + dispx;
396 double cy = dy + dispy;
407 for(
unsigned int l=i;l<i+1;l++)
409 if(
intersect_circles(hel, startx, starty, radii[l], 1./kappa, cx, cy, x, y) ==
true)
415 if (resolution_smear) {
416 x_hits[nhits] += rand.Gaus(0.0,smear_x);
417 y_hits[nhits] += rand.Gaus(0.0,smear_y);
421 double D = sqrt((startx-x)*(startx-x) + (starty-y)*(starty-y));
426 s = 2.*asin(0.5*k*D)/
k;
431 double temp2 = D*0.5;
440 double dz = sqrt(s*s*dzdl*dzdl/(1. - dzdl*dzdl));
441 if(dzdl>0.){z = startz +
dz;}
442 else{z = startz -
dz;}
445 if (resolution_smear) {
446 z_hits[nhits] += rand.Gaus(0.0,smear_z);
467 track=otree->GetEntries();