Fix Coverity reports
[u/mrichter/AliRoot.git] / TTherminator / Therminator / Parser.cxx
CommitLineData
2e967919 1/******************************************************************************
2 * T H E R M I N A T O R *
3 * THERMal heavy-IoN generATOR *
4 * version 1.0 *
5 * *
6 * Authors of the model: Wojciech Broniowski, Wojciech.Broniowski@ifj.edu.pl, *
7 * Wojciech Florkowski, Wojciech.Florkowski@ifj.edu.pl *
8 * Authors of the code: Adam Kisiel, kisiel@if.pw.edu.pl *
9 * Tomasz Taluc, ttaluc@if.pw.edu.pl *
10 * Code designers: Adam Kisiel, Tomasz Taluc, Wojciech Broniowski, *
11 * Wojciech Florkowski *
12 * *
13 * For the detailed description of the program and furhter references *
14 * to the description of the model plesase refer to: nucl-th/0504047, *
15 * accessibile at: http://www.arxiv.org/nucl-th/0504047 *
16 * *
17 * Homepage: http://hirg.if.pw.edu.pl/en/therminator/ *
18 * *
19 * This code can be freely used and redistributed. However if you decide to *
20 * make modifications to the code, please contact the authors, especially *
21 * if you plan to publish the results obtained with such modified code. *
22 * Any publication of results obtained using this code must include the *
23 * reference to nucl-th/0504047 and the published version of it, when *
24 * available. *
25 * *
26 *****************************************************************************/
27#include <TMath.h>
28#include "THGlobal.h"
29#include "ReadPar.h"
30#include "Parser.h"
31#include "DecayChannel.h"
32#include <sstream>
f8777da0 33#include <cstring>
2e967919 34
35extern ReadPar *sRPInstance;
36
37const double factorials[7] = {1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0 };
38
39Parser::Parser(ParticleDB *aDB)
40{
41 mDB = aDB;
42 ReadParameters();
43}
44
45Parser::~Parser()
46{
47}
48
49int Parser::check(char *a,char *b)
50{
51 int tIter3=0;
52
53 while(a[tIter3]!='\0')
54 {
55 if(a[tIter3]!=b[tIter3]) return 0;
56 tIter3++;
57 }
58 return 1;
59}
60
61int Parser::GetParticleCount()
62{
63 return mParticleCount;
64}
65
66char * Parser::GetParticleName(int i)
67{
68 return mNameBuffer[i];
69}
70
71double Parser::GetParticleMass(int i)
72{
73 return mMassBuffer[i];
74}
75
76double Parser::GetParticleGamma(int i)
77{
78 return mGammaBuffer[i];
79}
80
81double Parser::GetParticleSpin(int i)
82{
83 return mSpinBuffer[i];
84}
85
86int Parser::GetParticleBarionN(int i)
87{
88 return mBarionBuffer[i];
89}
90
91int Parser::GetParticleStrangeN(int i)
92{
93 return mStrangeBuffer[i];
94}
95
96double Parser::GetParticleI3(int i)
97{
98 return mI3Buffer[i];
99}
100
101int Parser::GetParticleDecayChannelCount(int i,int j)
102{
103 return mDecayBuffer[i][j];
104}
105
106int Parser::GetParticleNumber(int i)
107{
108 return mTypeCountBuffer[i];
109}
110
111void Parser::ReadInput()
112{
c61a7285 113 int j,tPartIter=0,l,tIter2, tIter; //variables
09b7c66c 114 char str[200];
115 char str1[200];
2e967919 116 double spin1,spin2,value;
117
118 ////// START OF "TABLES.M" /////////
119 ifstream in("tables.m");
120 if(in)
121 {
122 //START OF HEAD-LINE
123 in.ignore(100,'\n');
124 //END OF HEAD-LINE
125
126 for(tIter2=0;tIter2<50;tIter2++) str[tIter2]='\0';
127
128 tPartIter=0;
129
130 //START OF DATA
131 while(in>>str)
132 {
133 if(*str == 'x') break;
134
135 l=0;
136 //PARTICLE NAME AND MASS
137 if(str[0] == 'm' && str[1] == '[')
138 {
139 for(;;)
140 {
141 if(str[l+2] == ']') break;
142 mNameBuffer[tPartIter][l]=str[l+2]; //name
143 l++;
144 }
145 // mNameBuffer[tPartIter][l]='\0';
146 in>>str; // sign "="
147 in>>value; // mass
148 mMassBuffer[tPartIter]=value;
149 mTypeCountBuffer[tPartIter]=tPartIter;
150 for(tIter2=0;tIter2<50;tIter2++) str[tIter2]='\0';
151 }
152
153 if(str[0] == 'G' && str[3] == '[')
154 {
155 in>>str; // sign "="
156 in>>value; // gamma
157 mGammaBuffer[tPartIter]=value;
158 for(tIter2=0;tIter2<50;tIter2++) str[tIter2]='\0';
159 }
160
161 // spin
162 if(str[0] == 'J' && str[1] == '[')
163 {
164 in>>str; // sign "="
165 in>>str;
166 if(str[1] == '/')
167 {
168 *str1=str[0];spin1=atof(str1);
169 *str1=str[2];spin2=atof(str1);
170 mSpinBuffer[tPartIter]=spin1/spin2;
171 }
172 if(str[0] == '-')
173 {
174 *str1=str[1];spin1=atof(str1);
175 mSpinBuffer[tPartIter]=-spin1;
176 }
177 if(str[0]!='-' && str[1]!='/')
178 {
179 *str1=str[0];
180 spin1=atof(str1);
181 mSpinBuffer[tPartIter]=spin1;
182 }
183 tPartIter++; //next particle
184 for(tIter2=0;tIter2<50;tIter2++) str[tIter2]='\0';
185 }
186 }
187 //END OF DATA
188 }
189 mParticleCount=tPartIter;
190 ////// END OF "TABLES.M" /////////
191
192
193 ////// START OF "i200STAR.m"//////
194
195 double izospin1,izospin2; //help to calculate izospin, if niecalkowity
196 // input=fopen("i200STAR.m","r+");
197 ifstream in1("i200STAR.m");
198
199 for(tIter2=0;tIter2<369;tIter2++)
200 for(int jj=0;jj<2;jj++) mDecayBuffer[tIter2][jj]=0;
201
202 for(;;)
203 {
204 j=3; //first letter of particle in line in file
205 for(tIter=0;tIter<50;tIter++) str[tIter]='\0';
206 for(tIter=0;tIter<20;tIter++) str1[tIter]='\0';
207 tIter=0;
208
209 in1.getline(str,200);
210
211 if(str[0] == 'x') break;
212
213 if(str[0] == 'f' && str[1] == 'i')
214 {
215 //name
216 for(;;)
217 {
218 if(str[j] == ',')
219 {
220 j++; //to skip ","
221 break;
222 }
223 str1[tIter++]=str[j++];
224 }
225 for(tIter=0;tIter<369;tIter++)
226 {
227 if(check(str1,mNameBuffer[tIter]))
228 {
229 //barion number
230 for(tIter2=0;tIter2<20;tIter2++) str1[tIter2]='\0';
231 if(str[j] == '-')
232 {
233 *str1=str[j+1];
234 mBarionBuffer[tIter]=atoi(str1);
235 mBarionBuffer[tIter]=-mBarionBuffer[tIter];
236 }
237 if(str[j] != '-')
238 {
239 *str1=str[j];
240 mBarionBuffer[tIter]=atoi(str1);
241 }
242 if(str[j] == '-') j+=3;
243 else j+=2;
244
245 //strange number
246 for(tIter2=0;tIter2<20;tIter2++) str1[tIter2]='\0';
247 if(str[j] == '-')
248 {
249 *str1=str[j+1];
250 mStrangeBuffer[tIter]=atoi(str1);
251 mStrangeBuffer[tIter]=-mStrangeBuffer[tIter];
252 }
253 if(str[j] != '-')
254 {
255 *str1=str[j];
256 mStrangeBuffer[tIter]=atoi(str1);
257 }
258 if(str[j] == '-') j+=3;
259 else j+=2;
260
261 //izospin3 number
262 for(tIter2=0;tIter2<20;tIter2++) str1[tIter2]='\0';
263 if(str[j+1] == '/' && str[j+3] == ']')
264 {
265 *str1=str[j];
266 izospin1=atoi(str1);
267 *str1=str[j+2];
268 izospin2=atoi(str1);
269 mI3Buffer[tIter]=izospin1/izospin2;
270 }
271 if(str[j] == '-' && str[j+2] == '/' && str[j+4] == ']')
272 {
273 *str1=str[j+1];
274 izospin1=atoi(str1);
275 *str1=str[j+3];
276 izospin2=atoi(str1);
277 mI3Buffer[tIter]=-izospin1/izospin2;
278 }
279 if(str[j] == '-' && str[j+2] == ']')
280 {
281 *str1=str[j+1];
282 izospin1=atoi(str1);
283 mI3Buffer[tIter]=-izospin1;
284 }
285 if(str[j+1] == ']')
286 {
287 *str1=str[j];
288 mI3Buffer[tIter]=atof(str1);
289 }
290 break;
291 }
292 }
293 }
294
295 //DECAY CHANNELS
296
297 tIter=0;
298 //TWO-BODY DECAYS
299 if(str[0] == 's' && str[1] == 'e' && str[2] == '[')
300 {
301 // Reading in the decay channels
302 char *tLBrackert, *tFirstComma, *tSecondComma, *tThirdComma, *tRBracket;
2e967919 303
304 tLBrackert = strchr(str,'[');
305 tFirstComma = strchr(str,',');
306 tSecondComma = strchr(tFirstComma+1,',');
307 tThirdComma = strchr(tSecondComma+1,',');
308 tRBracket = strchr(tThirdComma,']');
309
310 if (!(tLBrackert && tFirstComma && tSecondComma && tThirdComma && tRBracket))
311 PRINT_DEBUG_1("Malformed line!: " << str);
312
f8777da0 313 char *tFather = new char[tFirstComma-tLBrackert];
314 strncpy(tFather, tLBrackert+1, tFirstComma-tLBrackert-1);
315 char *tDaughter1 = new char[tSecondComma-tFirstComma];
316 strncpy(tDaughter1, tFirstComma+1, tSecondComma-tFirstComma-1);
317 char *tDaughter2 = new char[tThirdComma-tSecondComma];
318 strncpy(tDaughter2, tSecondComma+1, tThirdComma-tSecondComma-1);
319 char *tBRatio = new char[tRBracket-tThirdComma];
320 strncpy(tBRatio, tThirdComma+1, tRBracket-tThirdComma-1);
2e967919 321
322 // Getting the ratio
323 char *tMiddle, *tRatComponent;
324 double tRatio = 1.0;
325
326 tMiddle = strchr(tBRatio,'_');
327 if (!tMiddle) tMiddle = strchr(tBRatio,' ');
328 while(tMiddle)
329 {
f8777da0 330 tRatComponent = new char[tMiddle-tBRatio+1];
331 strncpy(tRatComponent, tBRatio, tMiddle-tBRatio);
2e967919 332 if (strchr(tRatComponent,'/'))
333 tRatio *= atof(tRatComponent)/atof(tRatComponent+2);
334 else
335 tRatio *= atof(tRatComponent);
336 tBRatio = tMiddle+1;
337 tMiddle = strchr(tBRatio,'_');
338 if (!tMiddle) tMiddle = strchr(tBRatio,' ');
f8777da0 339 delete [] tRatComponent;
2e967919 340 }
341 if (strchr(tBRatio,'/'))
342 tRatio *= atof(tBRatio)/atof(tBRatio+2);
343 else
344 tRatio *= atof(tBRatio);
09b7c66c 345
8e85ac49 346 delete [] tFather;
347 delete [] tDaughter1;
348 delete [] tDaughter2;
349 delete [] tBRatio;
2e967919 350 }
351
352 //THREE-BODY DECAYS
353 j++; //because se3[]
354 if(str[0] == 's' && str[1] == 'e' && str[2] == '3' && str[3] == '[')
355 {
356 for(;;)
357 {
358 if(str[j] == ',')
359 {
360 j++; //to skip ","
361 break;
362 }
363 str1[tIter++]=str[j++]; //name
364 }
365
366 for(tIter=0;tIter<369;tIter++)
367 {
368 if(check(str1,mNameBuffer[tIter]))
369 {
370 mDecayBuffer[tIter][1]++;
371 break;
372 }
373 }
374 }
375
376
377 }
378 ////// END OF "i200STAR.m"//////
379
380 ParticleType *tPartBuf;
381 int tNum, tPart;
382
383 for(tPart=0;tPart<mParticleCount;tPart++)
384 {
385 tPartBuf = new ParticleType();
386 tPartBuf->SetName(mNameBuffer[tPart]);
387 tPartBuf->SetMass(mMassBuffer[tPart]);
388 tPartBuf->SetGamma(mGammaBuffer[tPart]);
389 tPartBuf->SetSpin(mSpinBuffer[tPart]);
390 tPartBuf->SetBarionN(mBarionBuffer[tPart]);
391 tPartBuf->SetStrangeness(mStrangeBuffer[tPart]);
392 tPartBuf->SetI3(mI3Buffer[tPart]);
393 tPartBuf->SetDecayChannelCount2(mDecayBuffer[tPart][0]);
394 tPartBuf->SetDecayChannelCount3(mDecayBuffer[tPart][1]);
395 tPartBuf->SetNumber(tPart);
396 tNum = mDB->AddParticleType(tPartBuf);
397 }
398
399 ifstream in2("i200STAR.m");
400 while (in2.getline(str,200))
401 {
402 tIter=0;
403 //TWO-BODY DECAYS
404 if(str[0] == 's' && str[1] == 'e' && str[2] == '[')
405 {
406 // Reading in the decay channels
407 char *tLBrackert, *tFirstComma, *tSecondComma, *tThirdComma, *tRBracket;
2e967919 408
409 tLBrackert = strchr(str,'[');
410 tFirstComma = strchr(str,',');
411 tSecondComma = strchr(tFirstComma+1,',');
412 tThirdComma = strchr(tSecondComma+1,',');
413 tRBracket = strchr(tThirdComma,']');
414 if (!(tLBrackert && tFirstComma && tSecondComma && tThirdComma && tRBracket))
415 PRINT_DEBUG_1("Malformed line!: " << str);
416
f8777da0 417 char *tFather = new char[tFirstComma-tLBrackert];
418 strncpy(tFather, tLBrackert+1, tFirstComma-tLBrackert-1);
419 char *tDaughter1 = new char[tSecondComma-tFirstComma];
420 strncpy(tDaughter1, tFirstComma+1, tSecondComma-tFirstComma-1);
421 char *tDaughter2 = new char[tThirdComma-tSecondComma];
422 strncpy(tDaughter2, tSecondComma+1, tThirdComma-tSecondComma-1);
423 char *tBRatio = new char[tRBracket-tThirdComma];
424 strncpy(tBRatio, tThirdComma+1, tRBracket-tThirdComma-1);
2e967919 425
426 // Getting the ratio
427 char *tMiddle, *tRatComponent;
428 double tRatio = 1.0;
429
430 tMiddle = strchr(tBRatio,'_');
431 if (!tMiddle) tMiddle = strchr(tBRatio,' ');
432 while(tMiddle)
433 {
f8777da0 434 tRatComponent = new char[tMiddle-tBRatio];
435 strncpy(tRatComponent, tBRatio, tMiddle-tBRatio);
2e967919 436 if (strchr(tRatComponent,'/'))
437 tRatio *= atof(tRatComponent)/atof(tRatComponent+2);
438 else
439 tRatio *= atof(tRatComponent);
440 tBRatio = tMiddle+1;
441 tMiddle = strchr(tBRatio,'_');
442 if (!tMiddle) tMiddle = strchr(tBRatio,' ');
f8777da0 443 delete [] tRatComponent;
2e967919 444 }
445 if (strchr(tBRatio,'/'))
446 tRatio *= atof(tBRatio)/atof(tBRatio+2);
447 else
448 tRatio *= atof(tBRatio);
449
450 DecayChannel *newChannel = new DecayChannel(tRatio, mDB->GetParticleTypeIndex(tDaughter1), mDB->GetParticleTypeIndex(tDaughter2), -1);
451 // if (mDB->GetParticleType(tDaughter1)->GetMass() +
452 // mDB->GetParticleType(tDaughter2)->GetMass()
453 // < mDB->GetParticleType(tFather)->GetMass()) {
454 // (mDB->GetParticleType(tFather))->AddDecayChannel(*newChannel);
455 // }
456 (mDB->GetParticleType(tFather))->AddDecayChannel(*newChannel);
09b7c66c 457
458 delete newChannel;
2e967919 459 }
460
461 if(str[0] == 's' && str[1] == 'e' && str[2] == '3')
462 {
463 // Reading in the decay channels
464 char *tLBrackert, *tFirstComma, *tSecondComma, *tThirdComma, *tFourthComma, *tRBracket;
2e967919 465
466 tLBrackert = strchr(str,'[');
467 tFirstComma = strchr(str,',');
468 tSecondComma = strchr(tFirstComma+1,',');
469 tThirdComma = strchr(tSecondComma+1,',');
470 tFourthComma = strchr(tThirdComma+1,',');
471 tRBracket = strchr(tThirdComma,']');
472
473 if (!(tLBrackert && tFirstComma && tSecondComma && tThirdComma && tFourthComma && tRBracket))
474 PRINT_DEBUG_1("Malformed line!: " << str);
475
f8777da0 476 char *tFather = new char[tFirstComma-tLBrackert];
477 strncpy(tFather, tLBrackert+1, tFirstComma-tLBrackert-1);
478 char *tDaughter1 = new char[tSecondComma-tFirstComma];
479 strncpy(tDaughter1, tFirstComma+1, tSecondComma-tFirstComma-1);
480 char *tDaughter2 = new char[tThirdComma-tSecondComma];
481 strncpy(tDaughter2, tSecondComma+1, tThirdComma-tSecondComma-1);
482 char *tDaughter3 = new char[tFourthComma-tThirdComma];
483 strncpy(tDaughter3, tThirdComma+1, tFourthComma-tThirdComma-1);
484 char *tBRatio = new char[tRBracket-tFourthComma];
485 strncpy(tBRatio, tFourthComma+1, tRBracket-tFourthComma-1);
2e967919 486
487 // Getting the ratio
488 char *tMiddle, *tRatComponent;
489 double tRatio = 1.0;
490
491 tMiddle = strchr(tBRatio,'_');
492 if (!tMiddle) tMiddle = strchr(tBRatio,' ');
493 while(tMiddle)
494 {
f8777da0 495 tRatComponent = new char[tMiddle-tBRatio+1];
496 strncpy(tRatComponent, tBRatio, tMiddle-tBRatio);
2e967919 497 if (strchr(tRatComponent,'/'))
498 tRatio *= atof(tRatComponent)/atof(tRatComponent+2);
499 else
500 tRatio *= atof(tRatComponent);
501 tBRatio = tMiddle+1;
502 tMiddle = strchr(tBRatio,'_');
503 if (!tMiddle) tMiddle = strchr(tBRatio,' ');
f8777da0 504 delete [] tRatComponent;
2e967919 505 }
506 if (strchr(tBRatio,'/'))
507 tRatio *= atof(tBRatio)/atof(tBRatio+2);
508 else
509 tRatio *= atof(tBRatio);
510
511 DecayChannel *newChannel = new DecayChannel(tRatio, mDB->GetParticleTypeIndex(tDaughter1), mDB->GetParticleTypeIndex(tDaughter2), mDB->GetParticleTypeIndex(tDaughter3));
512 // if (mDB->GetParticleType(tDaughter1)->GetMass() +
513 // mDB->GetParticleType(tDaughter2)->GetMass() +
514 // mDB->GetParticleType(tDaughter3)->GetMass()
515 // < mDB->GetParticleType(tFather)->GetMass())
516 (mDB->GetParticleType(tFather))->AddDecayChannel(*newChannel);
517 }
518 }
519
520 ifstream in3("pdgcodes.m");
521 while (in3.getline(str,200))
522 {
523 string tName;
524 int tCode;
525
526 std::stringstream tIS(str);
527 tIS >> tName >> tCode;
528 mDB->GetParticleType(tName)->SetPDGCode(tCode);
529 }
530
531}
532
533
534void Parser::ReadShare()
535{
536 char str[50];
537 char str1[200];
538
539 ParticleType *tPartBuf;
540 int tNum;
541
542 PRINT_DEBUG_1("Reading from |"<<(mInputDir+"/"+"particles.data").Data()<<"|");
543 ifstream in((mInputDir+"/"+"particles.data").Data());
544
545 int number=0;
546 if ((in) && (in.is_open()))
547 {
548 //START OF HEAD-LINE
549 in.ignore(200,'\n');
550 in.ignore(200,'\n');
551 in.ignore(200,'\n');
552 //END OF HEAD-LINE
553
554 while (in>>str)
555 {
556 if (/*(*str == '#')||*/(*str<65)||(*str>122))
557 {
558 in.getline(str1,200);
559 continue;
560 }
561 double mass, gamma, spin, I3, I, q, s, aq, as, c, ac, mc;
562
563 in>>mass>>gamma>>spin>>I>>I3>>q>>s>>aq>>as>>c>>ac>>mc;
564 number++;
565 PRINT_DEBUG_2(number<<" "<<str<<" "<<mass<<" "<<gamma<<" "<<spin<<" "<<I<<" "<<I3<<" "<<q<<" "<<aq<<" "<<s<<" "<<as<<" "<<c<<" "<<ac<<" "<<mc);
566
567 tPartBuf = new ParticleType();
568 tPartBuf->SetName(str);
569 tPartBuf->SetMass(mass);
570 tPartBuf->SetGamma(gamma);
571 tPartBuf->SetSpin(spin);
572 tPartBuf->SetBarionN((int) ((q+s+c)/3. - (aq+as+ac)/3.) );
573 tPartBuf->SetCharmN((int) (c - ac));
574 tPartBuf->SetStrangeness((int) (as-s));
575 tPartBuf->SetI(I);
576 tPartBuf->SetI3(I3);
577 tPartBuf->SetPDGCode((int) mc);
578 tPartBuf->SetNumber(number);
579 tNum = mDB->AddParticleType(tPartBuf);
580 }
581 in.close();
582 }
583 else
584 {
585 PRINT_MESSAGE("File "<<(mInputDir+"/"+"particles.data").Data()<<" containing particle data not found!");
586 PRINT_MESSAGE("Please set the correct path to this file in the input parameter file");
587 PRINT_MESSAGE("Aborting!");
588 exit(0);
589 }
590
591 ifstream in2((mInputDir+"/decays.data").Data());
592 if ((in2) && (in2.is_open()))
593 {
594 //START OF HEAD-LINE
595 in2.ignore(200,'\n');
596 in2.ignore(200,'\n');
597 in2.ignore(200,'\n');
598 //END OF HEAD-LINE
599
f12dabf0 600 char tFather[50], tDaughter1[50], tDaughter2[50], tDaughter3[50];
2e967919 601 double tBRatio, tRatio;
602 int CGcoeff; // complete branching ratio by Clebsch-Gordan coefficient: 0-no 1-yes
603
604 while (in2>>str)
605 {
606 if (*str == '#')
607 {
608 in2.getline(str1,200);
609 continue;
610 }
611 in2>>tDaughter1>>tDaughter2>>tDaughter3;
612 if (!mDB->ExistsParticleType(tDaughter1)) {
613 PRINT_MESSAGE("Did not find the daughter 1 particle: " << tDaughter1);
614 PRINT_MESSAGE("Not adding channel");
615 in2.getline(str1,200);
616 continue;
617 }
618 if (!mDB->ExistsParticleType(tDaughter2)) {
619 PRINT_MESSAGE("Did not find the daughter 2 particle: " << tDaughter2);
620 PRINT_MESSAGE("Not adding channel");
621 in2.getline(str1,200);
622 continue;
623 }
624 if ((*tDaughter3>65)&&(*tDaughter3<122)&&(!mDB->ExistsParticleType(tDaughter3))) {
625 PRINT_MESSAGE("Did not find the daughter 3 particle: " << tDaughter3);
626 PRINT_MESSAGE("Not adding channel");
627 in2.getline(str1,200);
628 continue;
629 }
630
631 strcpy(tFather,str);
632 PRINT_DEBUG_2(tFather<<"\t"<<tDaughter1<<"\t"<<tDaughter2<<"\t");
633 if ((*tDaughter3>65)&&(*tDaughter3<122)) // check if first char is a letter - if yes then 3-body decay
634 {
635 in2>>tBRatio>>CGcoeff;
636 PRINT_DEBUG_2(tDaughter3<<" (3-body decay)\t");
637 if (mDB->ExistsParticleType(tFather)) {
638 mDB->GetParticleType(tFather)->SetDecayChannelCount3(mDB->GetParticleType(tFather)->GetDecayChannelCount3()+1);
639
640 tRatio=tBRatio;
641 DecayChannel *newChannel = new DecayChannel(tRatio, mDB->GetParticleTypeIndex(tDaughter1), mDB->GetParticleTypeIndex(tDaughter2), mDB->GetParticleTypeIndex(tDaughter3));
642 if (mDB->GetParticleType(tDaughter1)->GetMass() +
643 mDB->GetParticleType(tDaughter2)->GetMass() +
644 mDB->GetParticleType(tDaughter3)->GetMass()
645 < mDB->GetParticleType(tFather)->GetMass())
646 (mDB->GetParticleType(tFather))->AddDecayChannel(*newChannel);
09b7c66c 647
648 delete newChannel;
2e967919 649
650 tRatio=tBRatio;
651 PRINT_DEBUG_2(tBRatio << '\t' << tRatio);
652 }
653 else {
654 PRINT_MESSAGE("Did not find the father particle: " << tFather);
655 PRINT_MESSAGE("Not adding channel");
656 }
657 }
658 else // 2-body decay
659 {
660 tBRatio=atof(tDaughter3);
661
662 in2>>CGcoeff;
663 PRINT_DEBUG_2(" (2-body decay)\t");
664 if (mDB->ExistsParticleType(tFather)) {
665 mDB->GetParticleType(tFather)->SetDecayChannelCount2(mDB->GetParticleType(tFather)->GetDecayChannelCount2()+1);
666
667 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
668 if (CGcoeff) // complete branching ratio by Clebsch-Gordan coefficient
669 {
670 double j1, m1, j2, m2, J, M, CB;
671 J=mDB->GetParticleType(tFather)->GetI();
672 M=mDB->GetParticleType(tFather)->GetI3();
673 j1=mDB->GetParticleType(tDaughter1)->GetI();
674 m1=mDB->GetParticleType(tDaughter1)->GetI3();
675 j2=mDB->GetParticleType(tDaughter2)->GetI();
676 m2=mDB->GetParticleType(tDaughter2)->GetI3();
677 PRINT_DEBUG_2(" "<<J<<" "<<M<<" "<<j1<<" "<<m1<<" "<<j2<<" "<<m2);
678
679 CB = ClebschGordan(J, M, j1, m1, j2, m2);
680 tRatio = CB*CB * tBRatio;
681
682 // Multiply the Clebsh by two?
683 // The same spin, mass, strangeness
684 // and different I3?
685 if ((fabs(mDB->GetParticleType(tDaughter1)->GetSpin() - mDB->GetParticleType(tDaughter2)->GetSpin()) < 0.01) &&
686 (fabs(mDB->GetParticleType(tDaughter1)->GetMass() - mDB->GetParticleType(tDaughter2)->GetMass()) < 0.01) &&
687 (mDB->GetParticleType(tDaughter1)->GetStrangeness() == mDB->GetParticleType(tDaughter2)->GetStrangeness()) &&
688 (fabs(mDB->GetParticleType(tDaughter1)->GetI3() - mDB->GetParticleType(tDaughter2)->GetI3()) > 0.01))
689 {
690 PRINT_DEBUG_2("Multuplying Clebsch by two for " << tFather << "->" << tDaughter1 << "+" << tDaughter2);
691 tRatio *= 2.0;
692 }
693
694 PRINT_DEBUG_2(CB << '\t' << tBRatio << '\t' << tRatio<<"\t"<<CGcoeff);
695 }
696
697 else
698 {
699 tRatio=tBRatio;
700 PRINT_DEBUG_2(tBRatio << '\t' << tRatio);
701 }
702 DecayChannel *newChannel = new DecayChannel(tRatio, mDB->GetParticleTypeIndex(tDaughter1), mDB->GetParticleTypeIndex(tDaughter2), -1);
703 if (mDB->GetParticleType(tDaughter1)->GetMass() +
704 mDB->GetParticleType(tDaughter2)->GetMass()
705 < mDB->GetParticleType(tFather)->GetMass())
706 {
707 (mDB->GetParticleType(tFather))->AddDecayChannel(*newChannel);
708 PRINT_DEBUG_2("Added channel " << newChannel << " " << mDB->GetParticleTypeIndex(tFather) << " " << mDB->GetParticleTypeIndex(tDaughter1) << " " << mDB->GetParticleTypeIndex(tDaughter2));
709 }
710 else
711 {
712
713 PRINT_DEBUG_2("Masses do not match! Not adding channel " << newChannel);
714 }
715 }
716 else {
717 PRINT_MESSAGE("Did not find the father particle: " << tFather);
718 PRINT_MESSAGE("Not adding channel");
719 }
720 }
721 }
722 in2.close();
723 }
724 else {
725 PRINT_MESSAGE("File "<<(mInputDir+"/decays.data").Data()<<" with particle decay channels not found!");
726 PRINT_MESSAGE("No particle decays will be simulated");
727 }
728}
729
730double
731Parser::ClebschGordan(double aJot, double aEm, double aJot1, double aEm1, double aJot2, double aEm2)
732{
733 int mint, maxt;
734 double cgc = 0.0;
735 int titer;
736 double coef;
737
738 maxt = lrint(aJot1 + aJot2 - aJot);
739 mint = 0;
740 if (lrint(aJot1 - aEm1) < maxt) maxt = lrint(aJot1 - aEm1);
741 if (lrint(aJot2 + aEm2) < maxt) maxt = lrint(aJot2 + aEm2);
742 if (lrint(-(aJot-aJot2+aEm1)) > mint) mint = lrint(-(aJot-aJot2+aEm1));
743 if (lrint(-(aJot-aJot1-aEm2)) > mint) mint = lrint(-(aJot-aJot1-aEm2));
744
745 PRINT_DEBUG_3("mint " << mint << " " << aJot1 << " " << aEm1);
746 PRINT_DEBUG_3("maxt " << maxt << " " << aJot2 << " " << aEm2);
747
748 for (titer = mint; titer<=maxt; titer ++)
749 {
750 coef = TMath::Power(-1, titer);
751 PRINT_DEBUG_3("coef1 " << coef);
752 coef *= TMath::Sqrt((2*aJot+1)*
753 factorials[lrint(aJot1+aEm1)] *
754 factorials[lrint(aJot1-aEm1)] *
755 factorials[lrint(aJot2+aEm2)] *
756 factorials[lrint(aJot2-aEm2)] *
757 factorials[lrint(aJot+aEm)] *
758 factorials[lrint(aJot-aEm)]);
759 PRINT_DEBUG_3("coef2 " << coef);
760 coef /= (factorials[titer] *
761 factorials[lrint(aJot1+aJot2-aJot-titer)] *
762 factorials[lrint(aJot1-aEm1-titer)] *
763 factorials[lrint(aJot2+aEm2-titer)] *
764 factorials[lrint(aJot-aJot2+aEm1+titer)] *
765 factorials[lrint(aJot-aJot1-aEm2+titer)]);
766 PRINT_DEBUG_3("coef3 " << coef);
767
768 cgc += coef;
769 }
770
771 cgc *= DeltaJ(aJot1, aJot2, aJot);
772
773 return cgc;
774}
775
776double
777Parser::DeltaJ(double aJot1, double aJot2, double aJot)
778{
779 double res = TMath::Sqrt(1.0 *
780 factorials[lrint(aJot1+aJot2-aJot)] *
781 factorials[lrint(aJot1-aJot2+aJot)] *
782 factorials[lrint(-aJot1+aJot2+aJot)] /
783 factorials[lrint(aJot1+aJot2+aJot+1)]);
784
785 return res;
786}
787
788void
789Parser::ReadParameters()
790{
791 // Read the input directory
792 try {
793 mInputDir = sRPInstance->getPar("InputDirSHARE");
794 }
795 catch (STR tError) {
796 PRINT_DEBUG_1("Parser::ReadParameters - Caught exception " << tError);
797 PRINT_MESSAGE("Did not find SHARE input file location.");
798 PRINT_MESSAGE("Using default: '../share'");
799 mInputDir = "../share";
800 }
801}