1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | #include <stdio.h> |
20 | #include <unistd.h> |
21 | #include <math.h> |
22 | #include <string.h> |
23 | #include <stdlib.h> |
24 | #include <sys/types.h> |
25 | #include <sys/signal.h> |
26 | #include <sys/stat.h> |
27 | #include <time.h> |
28 | |
29 | #include <genkin.h> |
30 | #include <particleType.h> |
31 | |
32 | #define TRUE1 1 |
33 | #define FALSE0 0 |
34 | #define CONV(180.0/3.14159265358979323846) (180.0/M_PI3.14159265358979323846) |
35 | #define BUFSIZE100000 100000 |
36 | #define T_CUT10.0 10.0 |
37 | #define RECOIL0.938 0.938 |
38 | |
39 | #define RESTFRAME-1 -1 |
40 | #define PARENTFRAME+1 +1 |
41 | |
42 | #define PRODUCTION_PARTICLE1 1 |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | struct particleMC_t{ |
54 | int flag; |
55 | int nchildren; |
56 | int charge; |
57 | double mass; |
58 | double bookmass; |
59 | double width; |
60 | Particle_t particleID; |
61 | vector4_t p; |
62 | struct particleMC_t *parent, *child[2]; |
63 | } ; |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | int Debug = 0; |
75 | int Nprinted =0; |
76 | int PrintProduction=0; |
77 | int PrintRecoil=0; |
78 | double MassHighBW; |
79 | int UseName=0; |
80 | int FIRST_EVENT=1; |
81 | int PrintFlag=10; |
82 | int WriteAscii=0; |
83 | int runNo=9000; |
84 | int NFinalParts=0; |
85 | unsigned int RandomSeed=0; |
86 | int UseCurrentTimeForRandomSeed = TRUE1; |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | double rawthresh(struct particleMC_t *Isobar); |
96 | void decay(struct particleMC_t *Isobar); |
97 | void boost2lab(struct particleMC_t *Isobar); |
98 | void boostFamily(vector4_t *beta,struct particleMC_t *Isobar); |
99 | void boost(vector4_t *beta,vector4_t *vec); |
100 | void printParticle(struct particleMC_t *Isobar); |
101 | vector4_t polarMake4v(double p, double theta, double phi, double mass); |
102 | double randm(double low, double high); |
103 | void printProduction(FILE *fp,struct particleMC_t *Isobar); |
104 | void printFinal(FILE *fp,struct particleMC_t *Isobar); |
105 | void printp2ascii(FILE *fp,struct particleMC_t *Isobar); |
106 | void setMass(struct particleMC_t *Isobar); |
107 | void initMass(struct particleMC_t *Isobar); |
108 | char *ParticleType(Particle_t p); |
109 | void checkFamily(struct particleMC_t *Isobar); |
110 | int setChildrenMass(struct particleMC_t *Isobar); |
111 | void printFamily(struct particleMC_t *Isobar); |
112 | void lorentzFactor(double *lf,struct particleMC_t *Isobar); |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | void PrintUsage(char *processName) |
123 | { |
124 | |
125 | fprintf(stderrstderr,"%s usage: [-A<name>] < infile \n",processName); |
126 | fprintf(stderrstderr,"\t-d debug flag\n"); |
127 | fprintf(stderrstderr,"\t-n Use a particle name and not its ID number (ascii only) \n"); |
128 | fprintf(stderrstderr,"\t-M<max> Process first max events\n"); |
129 | fprintf(stderrstderr,"\t-l<lfevents> Determine the lorentz factor with this many number of events (default is 10000)\n"); |
130 | fprintf(stderrstderr,"\t-r<runNo> default runNo is 9000. \n"); |
131 | |
132 | fprintf(stderrstderr,"\t-P save flag= 11 & 01 events(default saves 11 & 10 events) \n"); |
133 | |
134 | |
135 | fprintf(stderrstderr,"\t-A<filename> Save in ascii format. \n"); |
136 | fprintf(stderrstderr,"\t-s<seed> Set random number seed to <seed>. \n"); |
137 | fprintf(stderrstderr,"\t (default is to set using current time + pid) \n"); |
138 | fprintf(stderrstderr,"\t-h Print this help message\n\n"); |
139 | |
140 | } |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | int main(int argc,char **argv) |
152 | { |
153 | char *argptr,*token,line[2056]; |
154 | int i,npart=0,ngenerated=0,naccepted=0, imassc, imassc2; |
155 | int nv4,max=10,part=0,chld1=-1,chld2=-1,prnt=-1,lfevents=10000; |
156 | FILE *fout=stdoutstdout; |
157 | struct particleMC_t particle[20],beam,target,CM; |
158 | |
159 | struct particleMC_t *X,*Y; |
160 | vector4_t beta,v4[2]; |
161 | |
162 | double t,expt_max,expt,expt_min,sqrt_s,t_min=0; |
163 | double CMenergy, t_max,slope=5.0; |
164 | double X_momentum, X_energy,xmass,ymass; |
165 | |
166 | double costheta,theta,phi,lf,lfmax=0; |
167 | int isacomment=TRUE1,haveChildren=TRUE1; |
168 | |
169 | Y= &(particle[0]); |
170 | Y->parent = &CM; |
171 | X= &(particle[1]); |
172 | X->parent = &CM; |
173 | |
174 | CM.child[0]= X; |
175 | CM.child[1]= Y; |
176 | |
177 | |
178 | if (argc == 1){ |
179 | PrintUsage(argv[0]); |
180 | exit (0); |
181 | } |
182 | else { |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | for (i=1; i<argc; i++) { |
189 | argptr = argv[i]; |
190 | if ((*argptr == '-') && (strlen(argptr) > 1)) { |
191 | argptr++; |
192 | switch (*argptr) { |
193 | case 'd': |
194 | Debug =1; |
195 | break; |
196 | case 'h': |
197 | PrintUsage(argv[0]); |
198 | exit(0); |
199 | break; |
200 | case 'n': |
201 | UseName =1; |
202 | break; |
203 | case 'A': |
204 | WriteAscii=1; |
205 | fout = fopen(++argptr,"w"); |
206 | fprintf(stderrstderr,"Opening file %s for output. \n",argptr); |
207 | break; |
208 | case 'R': |
209 | fprintf(stderrstderr,"Printing recoil information.\n"); |
210 | PrintRecoil=1; |
211 | break; |
212 | case 'P': |
213 | fprintf(stderrstderr,"Printing eta and pizeros and not gammas.\n"); |
214 | PrintProduction=1; |
215 | break; |
216 | case 'l': |
217 | lfevents = atoi(++argptr); |
218 | fprintf(stderrstderr,"Using %d events to determine the lorentz factor\n",lfevents); |
219 | break; |
220 | case 'M': |
221 | max = atoi(++argptr); |
222 | fprintf(stderrstderr,"Maximum number of events: %d\n",max); |
223 | break; |
224 | case 'r': |
225 | runNo = atoi(++argptr); |
226 | fprintf(stderrstderr,"Using runNo: %d\n",runNo); |
227 | break; |
228 | case 's': |
229 | RandomSeed = atoi(++argptr); |
230 | UseCurrentTimeForRandomSeed = FALSE0; |
231 | break; |
232 | default: |
233 | fprintf(stderrstderr,"Unrecognized argument -%s\n\n",argptr); |
234 | PrintUsage(argv[0]); |
235 | exit(-1); |
236 | break; |
237 | |
238 | } |
239 | } |
240 | } |
241 | } |
242 | |
243 | |
244 | |
245 | |
246 | if(UseCurrentTimeForRandomSeed){ |
247 | RandomSeed=time(NULL((void*)0)); |
248 | RandomSeed += getpid(); |
249 | } |
250 | printf("Setting random number seed to: %d\n",RandomSeed); |
251 | srand48(RandomSeed); |
252 | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | |
265 | |
266 | |
267 | isacomment=TRUE1; |
268 | while(isacomment==TRUE1){ |
269 | char *pline; |
270 | pline = fgets(line,sizeof(line),stdinstdin); |
271 | if (pline!=NULL((void*)0)){ |
272 | token=strtok(line," "); |
273 | if(!(*token == '%')) |
274 | isacomment=FALSE0; |
275 | } |
276 | } |
277 | beam.p.space.x = atof(token); |
278 | token=strtok(NULL((void*)0)," "); |
279 | beam.p.space.y = atof(token); |
280 | token=strtok(NULL((void*)0)," "); |
281 | beam.p.space.z = atof(token); |
282 | token=strtok(NULL((void*)0)," "); |
283 | beam.mass = atof(token); |
284 | fprintf(stderrstderr,"Reading: \tbeamp.x \tbeamp.y \tbeamp.z \tbeamMass\n"); |
285 | fprintf(stderrstderr,"Found: \t\t%lf \t%lf \t%lf \t%lf \n", |
286 | beam.p.space.x, beam.p.space.y, beam.p.space.z, beam.mass); |
287 | |
288 | |
289 | isacomment=TRUE1; |
290 | while(isacomment==TRUE1){ |
291 | char *pline; |
292 | pline = fgets(line,sizeof(line),stdinstdin); |
293 | if (pline!=NULL((void*)0)){ |
294 | token=strtok(line," "); |
295 | if(!(*token == '%')) |
296 | isacomment=FALSE0; |
297 | } |
298 | } |
299 | target.p.space.x = atof(token); |
300 | token=strtok(NULL((void*)0)," "); |
301 | target.p.space.y = atof(token); |
302 | token=strtok(NULL((void*)0)," "); |
303 | target.p.space.z = atof(token); |
304 | token=strtok(NULL((void*)0)," "); |
305 | target.mass = atof(token); |
306 | fprintf(stderrstderr,"Reading: \ttargetp.x \ttargetp.y \ttargetp.z \ttargetMass\n"); |
307 | fprintf(stderrstderr,"Found: \t\t%lf \t%lf \t%lf \t%lf \n", |
308 | target.p.space.x, target.p.space.y, target.p.space.z, target.mass); |
309 | |
310 | |
311 | isacomment=TRUE1; |
312 | while(isacomment==TRUE1){ |
313 | char *pline; |
314 | pline = fgets(line,sizeof(line),stdinstdin); |
315 | if (pline!=NULL((void*)0)){ |
316 | token=strtok(line," "); |
317 | if(!(*token == '%')) |
318 | isacomment=FALSE0; |
319 | } |
320 | } |
321 | |
322 | slope=atof(token); |
323 | fprintf(stderrstderr,"Reading: t-channelSlope\n"); |
324 | fprintf(stderrstderr,"Found: \t%lf \n",slope); |
325 | |
326 | isacomment=TRUE1; |
327 | while(isacomment==TRUE1){ |
328 | char *pline; |
329 | pline = fgets(line,sizeof(line),stdinstdin); |
330 | if (pline!=NULL((void*)0)){ |
331 | token=strtok(line," "); |
332 | if(!(*token == '%')) |
333 | isacomment=FALSE0; |
334 | } |
335 | } |
336 | npart = atoi(token); |
337 | fprintf(stderrstderr,"Reading: number of particles need to describe the decay\n"); |
338 | fprintf(stderrstderr,"Found: \t%d \n",npart); |
339 | |
340 | |
341 | |
342 | |
343 | |
344 | |
345 | |
346 | fprintf(stderrstderr,"Reading: \tpart# \tchld1# \tchld2# \tprnt# \tId \tnchld \tmass \t\twidth \t\tchrg \tflag \n"); |
347 | |
348 | for(i=0;i<npart;i++){ |
349 | haveChildren=TRUE1; |
350 | isacomment=TRUE1; |
351 | while(isacomment==TRUE1){ |
352 | char *pline; |
353 | pline = fgets(line,sizeof(line),stdinstdin); |
354 | if (pline!=NULL((void*)0)){ |
355 | token=strtok(line," "); |
356 | if(!(*token == '%')) |
357 | isacomment=FALSE0; |
358 | } |
359 | } |
360 | if(!(*token == '*')) |
361 | part = atoi(token); |
362 | token=strtok(NULL((void*)0)," "); |
363 | if(!(*token == '*')){ |
364 | chld1 = atoi(token); |
365 | particle[part].child[0] = &(particle[chld1]); |
366 | } |
367 | else |
368 | haveChildren = FALSE0; |
369 | token=strtok(NULL((void*)0)," "); |
370 | if(!(*token == '*')) { |
371 | chld2 = atoi(token); |
372 | particle[part].child[1] = &(particle[chld2]); |
373 | } |
374 | else |
375 | haveChildren = FALSE0; |
376 | token=strtok(NULL((void*)0)," "); |
377 | if(!(*token == '*')) { |
378 | prnt = atoi(token); |
379 | particle[part].parent = &(particle[prnt]); |
380 | } |
381 | token=strtok(NULL((void*)0)," "); |
382 | if(!(*token == '*')) |
383 | |
384 | particle[part].particleID = atoi(token); |
385 | token=strtok(NULL((void*)0)," "); |
386 | if(!(*token == '*')){ |
387 | particle[part].nchildren = atoi(token); |
388 | if(haveChildren==FALSE0 && particle[part].nchildren>0 ){ |
389 | fprintf(stderrstderr, |
390 | "If a particle has children then it must point to them!\n"); |
391 | exit(-1); |
392 | } |
393 | } |
394 | token=strtok(NULL((void*)0)," "); |
395 | if(!(*token == '*')) |
396 | particle[part].bookmass = atof(token); |
397 | else{ |
398 | fprintf(stderrstderr,"Every Particle needs a mass\n"); |
399 | exit(-1); |
400 | } |
401 | token=strtok(NULL((void*)0)," "); |
402 | if(!(*token == '*')){ |
403 | particle[part].width = atof(token); |
404 | |
405 | } |
406 | else { |
407 | fprintf(stderrstderr,"Every Particle needs a width\n"); |
408 | exit(-1); |
409 | } |
410 | token=strtok(NULL((void*)0)," "); |
411 | if(!(*token == '*')) |
412 | particle[part].charge = atoi(token); |
413 | token=strtok(NULL((void*)0)," "); |
414 | if(!(*token == '*')){ |
415 | particle[part].flag = atoi(token); |
416 | if(PrintProduction==1){ |
417 | if(particle[part].flag==11 || particle[part].flag==01) |
418 | NFinalParts++; |
419 | }else{ |
420 | if(particle[part].flag==11 || particle[part].flag==10) |
421 | NFinalParts++; |
422 | } |
423 | } |
424 | |
425 | |
426 | |
427 | |
428 | |
429 | fprintf(stderrstderr, |
430 | "Found: \t\t%d \t%d \t%d \t%d \t%d \t%d \t%lf \t%lf \t%d \t%d\n", |
431 | part,chld1,chld2,prnt,particle[part].particleID,particle[part].nchildren,particle[part].bookmass,particle[part].width,particle[part].charge,particle[part].flag); |
432 | } |
433 | isacomment=TRUE1; |
434 | while(isacomment==TRUE1){ |
435 | char *pline; |
436 | pline = fgets(line,sizeof(line),stdinstdin); |
437 | if (pline!=NULL((void*)0)){ |
438 | token=strtok(line," "); |
439 | if(!(*token == '%')) |
440 | isacomment=FALSE0; |
441 | } |
442 | } |
443 | if(!(*token == '!')){ |
444 | fprintf(stderrstderr,"Failed to find EOI---- Check Input File\n"); |
445 | exit(-1); |
446 | } |
447 | |
448 | checkFamily(X); |
449 | fprintf(stderrstderr,"Found EOI---- Input File appears Fine.\n"); |
450 | |
451 | |
452 | |
453 | |
454 | |
455 | |
456 | |
457 | |
458 | |
459 | if(X->nchildren == 0) X->mass = X->bookmass; |
460 | if(Y->nchildren == 0) Y->mass = Y->bookmass; |
461 | |
462 | target.p.t = energy(target.mass,&(target.p.space)); |
463 | beam.p.t = energy(beam.mass,&(beam.p.space)); |
464 | |
465 | |
466 | sqrt_s = sqrt( SQ(beam.mass) +SQ(target.mass) + 2.0*beam.p.t * target.p.t); |
467 | |
468 | MassHighBW = sqrt_s; |
469 | |
470 | v4[0]= beam.p; |
471 | v4[1]= target.p; |
472 | nv4=2; |
473 | |
474 | CM.mass = sqrt_s; |
475 | CM.p = Sum4vec(v4,nv4); |
476 | beta = get_beta(&(CM.p),RESTFRAME-1); |
477 | boost(&beta,&(beam.p)); |
478 | boost(&beta,&(target.p)); |
479 | |
480 | initMass(X); |
481 | initMass(Y); |
482 | CMenergy = beam.p.t + target.p.t; |
483 | |
484 | while(naccepted <max){ |
485 | |
486 | |
487 | if (Debug) fprintf(stderrstderr,"In main do loop ... %d \n",naccepted); |
488 | |
489 | |
490 | |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | do{ |
497 | l0: imassc2=0; |
498 | if(!(X->width<0)) |
499 | do{ |
500 | initMass(X); |
501 | setMass(X); |
502 | |
503 | |
504 | |
505 | |
506 | |
507 | |
508 | |
509 | if(Debug) fprintf(stderrstderr,"looping over nchildren = %d \n",X->nchildren); |
510 | for(i=0;i<X->nchildren;i++) |
511 | { |
512 | if(Debug) fprintf(stderrstderr,"calling setChildrenMass X... %d \n",i); |
513 | l1: imassc=setChildrenMass(X->child[i]); |
514 | if (Debug) fprintf(stderrstderr,"Return from setChildrenMass X... %d %d \n",i,imassc); |
515 | |
516 | |
517 | if (imassc!=0) { |
518 | if (Debug) fprintf(stderrstderr,"Need new masses for X %d %d %f \n",i,imassc,(X->child[i])->mass); |
519 | imassc2=imassc2+1; |
520 | if (imassc2<1000) |
521 | goto l1; |
522 | else |
523 | goto l0; |
524 | } |
525 | } |
526 | }while((X->mass > MassHighBW) || ( X->nchildren==0 ? FALSE0 : |
527 | (X->mass < ( (X->child[0])->mass + (X->child[1])->mass))) ); |
528 | |
529 | else{ |
530 | fprintf(stderrstderr,"Cannot use a negative width!\n"); |
531 | exit(-1); |
532 | } |
533 | |
534 | |
535 | |
536 | if(!(Y->width<0)) |
537 | do{ |
538 | initMass(Y); |
539 | setMass(Y); |
540 | |
541 | |
542 | |
543 | |
544 | |
545 | |
546 | |
547 | for(i=0;i<Y->nchildren;i++) |
548 | { |
549 | if (Debug) fprintf(stderrstderr,"calling setChildrenMass Y... %d \n",i); |
550 | l2: imassc=setChildrenMass(Y->child[i]); |
551 | if (Debug) fprintf(stderrstderr,"Return from setChildrenMass Y... %d %d \n",i,imassc); |
552 | |
553 | |
554 | if (imassc!=0) { |
555 | if (Debug) fprintf(stderrstderr,"Need new masses for Y %d %d %f \n",i,imassc,(Y->child[i])->mass); |
556 | goto l2; } |
557 | } |
558 | }while((Y->mass > MassHighBW) || ( Y->nchildren==0 ? FALSE0 : |
559 | (Y->mass < ( (Y->child[0])->mass + (Y->child[1])->mass)) ) ); |
560 | else{ |
561 | fprintf(stderrstderr,"Cannot use a negative width!\n"); |
562 | exit(-1); |
563 | } |
564 | }while(sqrt_s < X->mass + Y->mass); |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | |
571 | |
572 | xmass = X->mass; |
573 | ymass = Y->mass; |
574 | |
575 | |
576 | X_momentum = CMmomentum( CMenergy, X->mass, Y->mass); |
577 | X_energy = sqrt( (X->mass)*(X->mass) + X_momentum*X_momentum); |
578 | |
579 | if(Y->nchildren ==0){ |
580 | |
581 | t_min = -( SQ( (SQ(beam.mass) -SQ(xmass) -SQ(target.mass) +SQ(ymass))/(2.0*sqrt_s)) |
582 | -SQ(v3mag(&(beam.p.space)) - X_momentum )); |
583 | t_max = -( SQ( (SQ(beam.mass) -SQ(xmass) -SQ(target.mass) +SQ(ymass))/(2.0*sqrt_s)) |
584 | -SQ(v3mag(&(beam.p.space)) + X_momentum )); |
585 | |
586 | |
587 | |
588 | |
589 | |
590 | |
591 | |
592 | |
593 | |
594 | } else{ |
595 | |
596 | t_min=0.4; |
| Value stored to 't_min' is never read |
597 | t_max=10.0; |
598 | t_min = -( SQ( (SQ(beam.mass) -SQ(xmass) -SQ(target.mass) +SQ(ymass))/(2.0*sqrt_s)) |
599 | -SQ(v3mag(&(beam.p.space)) - X_momentum )); |
600 | t_max = -( SQ( (SQ(beam.mass) -SQ(xmass) -SQ(target.mass) +SQ(ymass))/(2.0*sqrt_s)) |
601 | -SQ(v3mag(&(beam.p.space)) + X_momentum )); |
602 | |
603 | } |
604 | expt_max = exp(-slope * t_max); |
605 | expt_min = exp(-slope * t_min); |
606 | |
607 | do{ |
608 | |
609 | expt = randm(expt_max,expt_min); |
610 | |
611 | t= -log(expt)/slope; |
612 | costheta = ( beam.p.t * X_energy - |
613 | 0.5*(t + (beam.mass)*(beam.mass) + (X->mass)*(X->mass)) |
614 | )/( v3mag(&(beam.p.space))*X_momentum ) ; |
615 | |
616 | }while(fabs(costheta)>1.0 ); |
617 | |
618 | theta = acos(costheta); |
619 | phi = randm(-1*M_PI3.14159265358979323846,M_PI3.14159265358979323846); |
620 | |
621 | X->p = polarMake4v(X_momentum,theta,phi,X->mass); |
622 | Y->p=polarMake4v(X_momentum,(M_PI3.14159265358979323846-theta),(M_PI3.14159265358979323846+phi),Y->mass); |
623 | |
624 | |
625 | |
626 | |
627 | |
628 | |
629 | |
630 | |
631 | |
632 | |
633 | |
634 | |
635 | |
636 | |
637 | decay(X); |
638 | decay(Y); |
639 | if(Debug) { |
640 | fprintf(stderrstderr,"X after decay\n"); |
641 | printFamily(X); |
642 | fprintf(stderrstderr,"Y after decay\n"); |
643 | printFamily(Y); |
644 | } |
645 | |
646 | |
647 | |
648 | |
649 | |
650 | lf=v3mag(&(X->p.space)); |
651 | lorentzFactor(&lf,X); |
652 | lorentzFactor(&lf,Y); |
653 | if (Debug) fprintf(stderrstderr,"lorentz factor information: %f ... %f ... \n",lf,lfmax); |
654 | if(lfevents-->0){ |
655 | lfmax = lf >lfmax ? lf : lfmax; |
656 | if( (lfevents % 10) == 0 ) { |
657 | if ( lfevents <= 100 || (lfevents % 1000) == 0 ) |
658 | fprintf(stderrstderr,"Calculating Lorentz Factor: %d \r",lfevents); |
659 | } |
660 | } |
661 | else{ |
662 | |
663 | if (Debug) fprintf(stderrstderr," inside loop: lorentz factor information: %f ... %f ... \n",lf,lfmax); |
664 | |
665 | |
666 | |
667 | |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | ngenerated++; |
677 | |
678 | if(lf > randm(0.0,lfmax) ){ |
679 | |
680 | naccepted++; |
681 | boost2lab(X); |
682 | boost2lab(Y); |
683 | |
684 | |
685 | |
686 | |
687 | |
688 | if(Debug) { |
689 | fprintf(stderrstderr,"X after boost2lab\n"); |
690 | printFamily(X); |
691 | fprintf(stderrstderr,"Y after boost2lab\n"); |
692 | printFamily(Y); |
693 | } |
694 | |
695 | Nprinted =0; |
696 | |
697 | |
698 | fprintf(fout,"%d %d %d\n",runNo,naccepted, NFinalParts); |
699 | |
700 | |
701 | |
702 | |
703 | |
704 | |
705 | |
706 | |
707 | |
708 | |
709 | if(PrintProduction){ |
710 | if(X->nchildren==0) |
711 | printp2ascii(fout,X); |
712 | else |
713 | printProduction(fout,X); |
714 | if(Y->nchildren==0) |
715 | printp2ascii(fout,Y); |
716 | else |
717 | printProduction(fout,Y); |
718 | } |
719 | else{ |
720 | if(X->nchildren==0) |
721 | printp2ascii(fout,X); |
722 | else |
723 | printFinal(fout,X); |
724 | if(Y->nchildren==0 && Y->flag/10 == 1 ) |
725 | printp2ascii(fout,Y); |
726 | else |
727 | printFinal(fout,Y); |
728 | } |
729 | |
730 | |
731 | } |
732 | if(!(ngenerated % 100)) { |
733 | if( ngenerated <= 1000 || !(ngenerated % 10000)) |
734 | fprintf(stderrstderr,"Events generated: %d Events accepted: %d \r", |
735 | ngenerated,naccepted); |
736 | } |
737 | if(Debug) fprintf(stderrstderr,"End of event\n"); |
738 | } |
739 | } |
740 | |
741 | fprintf(stderrstderr, |
742 | "Max Lorentz Factor:%lf Events generated:%d Events accepted:%d\n\n", |
743 | lfmax,ngenerated,naccepted); |
744 | |
745 | |
746 | |
747 | fflush(fout); |
748 | fclose(fout); |
749 | |
750 | return 0; |
751 | } |
752 | |
753 | |
754 | |
755 | |
756 | |
757 | |
758 | |
759 | |
760 | |
761 | |
762 | |
763 | |
764 | void checkFamily(struct particleMC_t *Isobar) |
765 | { |
766 | int i; |
767 | |
768 | for(i=0;i<Isobar->nchildren; i++){ |
769 | if(Isobar->nchildren != 2){ |
770 | fprintf(stderrstderr,"Error in input file: Sorry, only 0 or 2 children are allowed.\n"); |
771 | exit(-1); |
772 | } |
773 | if(Isobar != Isobar->child[i]->parent){ |
774 | fprintf(stderrstderr,"Error in input file: Parent to children mismatch\n"); |
775 | exit(-1); |
776 | } |
777 | checkFamily(Isobar->child[i]); |
778 | } |
779 | |
780 | } |
781 | |
782 | |
783 | |
784 | |
785 | |
786 | |
787 | |
788 | |
789 | |
790 | |
791 | |
792 | |
793 | int setChildrenMass(struct particleMC_t *Isobar) |
794 | { |
795 | int i, imassc=0; |
796 | |
797 | |
798 | |
799 | |
800 | initMass(Isobar); |
801 | setMass(Isobar); |
802 | for(i=0;i < Isobar->nchildren;i++){ |
803 | if (Debug) fprintf(stderrstderr,"In loop ... %d %d %f \n",i,Isobar->nchildren,(Isobar->child[i])->mass); |
804 | |
805 | |
806 | l3: imassc=setChildrenMass(Isobar->child[i]); |
807 | |
808 | if (imassc!=0) { |
809 | if (Debug) fprintf(stderrstderr,"Need new masses for Isobar %d %d %f \n",i,imassc,(Isobar->child[i])->mass); |
810 | goto l3; } |
811 | } |
812 | |
813 | if(Isobar->nchildren !=0) |
814 | { |
815 | if((Isobar->mass) < ((Isobar->child[0])->mass)+((Isobar->child[1])->mass)) |
816 | { |
817 | |
818 | |
819 | if (Debug) fprintf(stderrstderr,"final call ... \n"); |
820 | |
821 | |
822 | imassc=imassc+1; |
823 | if (Debug) fprintf(stderrstderr," %f %f %f \n",Isobar->mass,(Isobar->child[0])->mass,(Isobar->child[1])->mass); |
824 | } else {imassc=0;} |
825 | } |
826 | |
827 | if (Debug) fprintf(stderrstderr,"Leaving setChildrenMass ... %f %d \n",Isobar->mass,imassc); |
828 | |
829 | return imassc; |
830 | } |
831 | |
832 | |
833 | |
834 | |
835 | |
836 | |
837 | |
838 | |
839 | |
840 | |
841 | |
842 | |
843 | |
844 | void setMass(struct particleMC_t *Isobar) |
845 | { |
846 | double n,height,thresH2,lowtail,hightail,hcut,lcut; |
847 | |
848 | if(Isobar->width > 0){ |
849 | |
850 | lowtail = rawthresh(Isobar); |
851 | |
852 | |
853 | |
854 | thresH2 = |
855 | Isobar == (Isobar->parent)->child[0] ? |
856 | rawthresh((Isobar->parent)->child[1]) : |
857 | rawthresh((Isobar->parent)->child[0]) ; |
858 | |
859 | |
860 | |
861 | hightail = (Isobar->parent->mass) - thresH2 ; |
862 | |
863 | |
864 | |
865 | hcut= Isobar->bookmass + 4.0*Isobar->width ; |
866 | lcut= Isobar->bookmass - 4.0*Isobar->width ; |
867 | |
868 | if(hightail> hcut) |
869 | hightail=hcut; |
870 | if(lowtail < lcut) |
871 | lowtail= lcut; |
872 | |
873 | |
874 | do{ |
875 | n=randm(0.0,0.9999); |
876 | Isobar->mass = randm( lowtail , hightail); |
877 | |
878 | height= SQ((Isobar->bookmass)*(Isobar->width))/ |
879 | ( SQ(SQ(Isobar->bookmass) - SQ(Isobar->mass)) + |
880 | SQ((Isobar->bookmass) * (Isobar->width) )); |
881 | }while(n > height ); |
882 | |
883 | |
884 | |
885 | |
886 | } |
887 | } |
888 | |
889 | |
890 | |
891 | |
892 | |
893 | |
894 | |
895 | |
896 | |
897 | void initMass(struct particleMC_t *Isobar) |
898 | { |
899 | int i; |
900 | |
901 | for(i=0;i<Isobar->nchildren;i++){ |
902 | if(Isobar->child[i]->width == 0.0) |
903 | Isobar->child[i]->mass = Isobar->child[i]->bookmass; |
904 | else |
905 | Isobar->child[i]->mass = -1.0; |
906 | initMass(Isobar->child[i]); |
907 | } |
908 | } |
909 | |
910 | |
911 | |
912 | |
913 | |
914 | |
915 | |
916 | |
917 | |
918 | double rawthresh(struct particleMC_t *Isobar) |
919 | { |
920 | int i; |
921 | double rmassThresh=0.0; |
922 | |
923 | if(Isobar->nchildren){ |
924 | for(i=0; i < Isobar->nchildren;i++){ |
925 | if (Isobar->child[i]->mass <0) |
926 | rmassThresh += rawthresh(Isobar->child[i]); |
927 | else |
928 | rmassThresh += Isobar->child[i]->mass; |
929 | } |
930 | }else{ |
931 | rmassThresh=Isobar->mass; |
932 | if(Isobar->mass <0){ |
933 | fprintf(stderrstderr,"Error!: Isobar->mass <0 for Isobar with no children\nExit\n"); |
934 | exit(-1); |
935 | } |
936 | } |
937 | return rmassThresh; |
938 | } |
939 | |
940 | |
941 | |
942 | |
943 | |
944 | |
945 | |
946 | |
947 | |
948 | |
949 | |
950 | void decay(struct particleMC_t *Isobar) |
951 | { |
952 | int i; |
953 | double breakup_p,theta,phi; |
954 | |
955 | |
956 | |
957 | if(Isobar->nchildren>0) |
958 | { |
959 | breakup_p = CMmomentum(Isobar->mass, |
960 | Isobar->child[0]->mass, |
961 | Isobar->child[1]->mass); |
962 | theta = acos(randm(-0.9999, 0.9999)); |
963 | phi = randm(-1*M_PI3.14159265358979323846,M_PI3.14159265358979323846); |
964 | Isobar->child[0]->p = |
965 | polarMake4v(breakup_p,theta,phi,Isobar->child[0]->mass); |
966 | Isobar->child[1]->p = |
967 | polarMake4v(breakup_p,(M_PI3.14159265358979323846 - theta),(M_PI3.14159265358979323846 + phi),Isobar->child[1]->mass); |
968 | for(i=0;i<Isobar->nchildren;i++) |
969 | decay(Isobar->child[i]); |
970 | } |
971 | } |
972 | |
973 | |
974 | |
975 | |
976 | |
977 | |
978 | |
979 | |
980 | |
981 | |
982 | |
983 | void lorentzFactor(double *lf,struct particleMC_t *Isobar) |
984 | { |
985 | int i; |
986 | |
987 | if(!(Isobar->nchildren == 0 )){ |
988 | *lf *= v3mag(&(Isobar->child[0]->p.space)); |
989 | for(i=0;i<Isobar->nchildren;i++) |
990 | lorentzFactor(lf,Isobar->child[i]); |
991 | } |
992 | |
993 | } |
994 | |
995 | |
996 | |
997 | |
998 | |
999 | |
1000 | |
1001 | |
1002 | |
1003 | |
1004 | |
1005 | |
1006 | |
1007 | |
1008 | void boost2lab(struct particleMC_t *Isobar) |
1009 | { |
1010 | int i; |
1011 | vector4_t beta; |
1012 | |
1013 | for(i=0;i<Isobar->nchildren;i++) |
1014 | |
1015 | boost2lab(Isobar->child[i]); |
1016 | |
1017 | beta = get_beta(&(Isobar->parent->p),PARENTFRAME+1); |
1018 | boostFamily(&beta,Isobar); |
1019 | } |
1020 | |
1021 | |
1022 | |
1023 | |
1024 | |
1025 | |
1026 | |
1027 | |
1028 | |
1029 | void boostFamily(vector4_t *beta,struct particleMC_t *Isobar) |
1030 | { |
1031 | int j; |
1032 | boost(beta,&(Isobar->p)); |
1033 | for(j=0;j<Isobar->nchildren;j++) |
1034 | boostFamily(beta, Isobar->child[j]); |
1035 | } |
1036 | |
1037 | |
1038 | |
1039 | |
1040 | |
1041 | |
1042 | |
1043 | |
1044 | void boost(vector4_t *beta,vector4_t *vec) |
1045 | { |
1046 | vector4_t temp; |
1047 | |
1048 | temp = lorentz(beta,vec); |
1049 | vec->t = temp.t; |
1050 | vec->space.x = temp.space.x; |
1051 | vec->space.y = temp.space.y; |
1052 | vec->space.z = temp.space.z; |
1053 | } |
1054 | |
1055 | |
1056 | |
1057 | |
1058 | |
1059 | |
1060 | |
1061 | void printProduction(FILE *fp,struct particleMC_t *Isobar) |
1062 | { |
1063 | int i; |
1064 | |
1065 | for(i=0;i<Isobar->nchildren;i++){ |
1066 | if((Isobar->child[i]->flag%10 ) == 1) |
1067 | printp2ascii(fp,Isobar->child[i]); |
1068 | printProduction(fp,Isobar->child[i]); |
1069 | } |
1070 | } |
1071 | |
1072 | |
1073 | |
1074 | |
1075 | |
1076 | |
1077 | |
1078 | void printFinal(FILE *fp,struct particleMC_t *Isobar) |
1079 | { |
1080 | int i; |
1081 | |
1082 | for(i=0;i<Isobar->nchildren;i++){ |
1083 | if((Isobar->child[i]->flag/10 ) == 1) |
1084 | printp2ascii(fp,Isobar->child[i]); |
1085 | printFinal(fp,Isobar->child[i]); |
1086 | } |
1087 | } |
1088 | |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | |
1094 | void printp2ascii(FILE *fp,struct particleMC_t *Isobar) |
1095 | { |
1096 | Nprinted++; |
1097 | if(UseName) |
1098 | fprintf(fp,"%d %s %lf\n",Nprinted,ParticleType(Isobar->particleID),Isobar->mass); |
1099 | else |
1100 | fprintf(fp,"%d %d %lf\n",Nprinted,Isobar->particleID,Isobar->mass); |
1101 | |
1102 | fprintf(fp," %d %lf %lf %lf %lf\n",Isobar->charge, |
1103 | Isobar->p.space.x, |
1104 | Isobar->p.space.y, |
1105 | Isobar->p.space.z, |
1106 | Isobar->p.t); |
1107 | |
1108 | } |
1109 | |
1110 | |
1111 | |
1112 | |
1113 | |
1114 | |
1115 | void printFamily(struct particleMC_t *Isobar) |
1116 | { |
1117 | int j; |
1118 | printParticle(Isobar); |
1119 | for(j=0;j<Isobar->nchildren;j++) |
1120 | printFamily(Isobar->child[j]); |
1121 | } |
1122 | |
1123 | |
1124 | |
1125 | |
1126 | |
1127 | |
1128 | |
1129 | |
1130 | void printParticle(struct particleMC_t *Isobar) |
1131 | { |
1132 | fprintf(stderrstderr,"Particle ID %s with %d children\n", |
1133 | ParticleType(Isobar->particleID),Isobar->nchildren); |
1134 | fprintf(stderrstderr,"four momentum (E,p): %lf %lf %lf %lf\n\n", |
1135 | Isobar->p.t, |
1136 | Isobar->p.space.x, |
1137 | Isobar->p.space.y, |
1138 | Isobar->p.space.z); |
1139 | } |
1140 | |
1141 | |
1142 | |
1143 | |
1144 | |
1145 | |
1146 | |
1147 | vector4_t polarMake4v(double p, double theta, double phi, double mass) |
1148 | { |
1149 | vector4_t temp; |
1150 | |
1151 | temp.t = sqrt( SQ(mass) + SQ(p)); |
1152 | temp.space.z = p*cos(theta); |
1153 | temp.space.x = p*sin(theta)*cos(phi); |
1154 | temp.space.y = p*sin(theta)*sin(phi); |
1155 | |
1156 | return temp; |
1157 | } |
1158 | |
1159 | |
1160 | |
1161 | |
1162 | |
1163 | |
1164 | double randm(double low, double high) |
1165 | { |
1166 | |
1167 | |
1168 | |
1169 | |
1170 | return ((high - low) * drand48() + low); |
1171 | } |
1172 | |
1173 | #if 0 |
1174 | char *ParticleType(Particle_t p) |
1175 | { |
1176 | static char ret[20]; |
1177 | switch (p) { |
1178 | case Unknown: |
1179 | strcpy(ret,"unknown"); |
1180 | break; |
1181 | case Gamma: |
1182 | strcpy(ret,"gamma"); |
1183 | break; |
1184 | case Positron: |
1185 | strcpy(ret,"positron"); |
1186 | break; |
1187 | case Electron: |
1188 | strcpy(ret,"electron"); |
1189 | break; |
1190 | case Neutrino: |
1191 | strcpy(ret,"neutrino"); |
1192 | break; |
1193 | case MuonPlus: |
1194 | strcpy(ret,"mu+"); |
1195 | break; |
1196 | case MuonMinus: |
1197 | strcpy(ret,"mu-"); |
1198 | break; |
1199 | case Pi0: |
1200 | strcpy(ret,"pi0"); |
1201 | break; |
1202 | case PiPlus: |
1203 | strcpy(ret,"pi+"); |
1204 | break; |
1205 | case PiMinus: |
1206 | strcpy(ret,"pi-"); |
1207 | break; |
1208 | case KLong: |
1209 | strcpy(ret,"KL"); |
1210 | break; |
1211 | case KPlus: |
1212 | strcpy(ret,"K+"); |
1213 | break; |
1214 | case KMinus: |
1215 | strcpy(ret,"K-"); |
1216 | break; |
1217 | case Neutron: |
1218 | strcpy(ret,"neutron"); |
1219 | break; |
1220 | case Proton: |
1221 | strcpy(ret,"proton"); |
1222 | break; |
1223 | case AntiProton: |
1224 | strcpy(ret,"pbar"); |
1225 | break; |
1226 | case KShort: |
1227 | strcpy(ret,"Ks"); |
1228 | break; |
1229 | case Eta: |
1230 | strcpy(ret,"eta"); |
1231 | break; |
1232 | case Lambda: |
1233 | strcpy(ret,"lambda"); |
1234 | break; |
1235 | case SigmaPlus: |
1236 | strcpy(ret,"sigma+"); |
1237 | break; |
1238 | case Sigma0: |
1239 | strcpy(ret,"sigma0"); |
1240 | break; |
1241 | case SigmaMinus: |
1242 | strcpy(ret,"sigma-"); |
1243 | break; |
1244 | case Xi0: |
1245 | strcpy(ret,"Xi0"); |
1246 | break; |
1247 | case XiMinus: |
1248 | strcpy(ret,"Xi-"); |
1249 | break; |
1250 | case OmegaMinus: |
1251 | strcpy(ret,"omega-"); |
1252 | break; |
1253 | case AntiNeutron: |
1254 | strcpy(ret,"nbar"); |
1255 | break; |
1256 | |
1257 | case AntiLambda: |
1258 | strcpy(ret,"lambdabar"); |
1259 | break; |
1260 | case AntiSigmaMinus: |
1261 | strcpy(ret,"sigmabar-"); |
1262 | break; |
1263 | case AntiSigma0: |
1264 | strcpy(ret,"sigmabar0"); |
1265 | break; |
1266 | case AntiSigmaPlus: |
1267 | strcpy(ret,"sigmabar+"); |
1268 | break; |
1269 | case AntiXi0: |
1270 | strcpy(ret,"Xibar0"); |
1271 | break; |
1272 | case AntiXiPlus: |
1273 | strcpy(ret,"Xibar+"); |
1274 | break; |
1275 | case AntiOmegaPlus: |
1276 | strcpy(ret,"omegabar+"); |
1277 | break; |
1278 | case Rho0: |
1279 | strcpy(ret,"rho0"); |
1280 | break; |
1281 | case RhoPlus: |
1282 | strcpy(ret,"rho+"); |
1283 | break; |
1284 | case RhoMinus: |
1285 | strcpy(ret,"rho;"); |
1286 | break; |
1287 | case omega: |
1288 | strcpy(ret,"omega"); |
1289 | break; |
1290 | case EtaPrime: |
1291 | strcpy(ret,"etaprime"); |
1292 | break; |
1293 | case phiMeson: |
1294 | strcpy(ret,"phi"); |
1295 | break; |
1296 | default: |
1297 | sprintf(ret,"type(%d)",(int)p); |
1298 | break; |
1299 | } |
1300 | return(ret); |
1301 | } |
1302 | |
1303 | #endif |
1304 | |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | |
1311 | |
1312 | |
1313 | |
1314 | |