1 #include "AliHBTCrab.h"
2 //______________________________________________________________________
3 /////////////////////////////////////////////////////////////////////////
5 // AliRoot wrapper to CRAB //
6 // taken from http://www.nscl.msu.edu/~pratt/freecodes/crab/home.html //
7 // written by Scott Pratt //
10 /////////////////////////////////////////////////////////////////////////
12 #include "AliHBTPair.h"
16 #include "volya_complex.h"
18 AliHBTCrab* AliHBTCrab::fgCrab = 0x0;
20 const Double_t AliHBTCrab::fgkWcons = 1./0.1973;
21 const Double_t AliHBTCrab::fgkROOT2=1.41421356237309504880;
23 const complex AliHBTCrab::fgkCI(0.0,1.0);
25 const doublecomplex AliHBTCrab::fgkCI(0.0,1.0);
28 /************************************************************/
30 AliHBTCrab* AliHBTCrab::Instance()
32 // returns instance of class
35 fgCrab = new AliHBTCrab();
39 //===================================================================
41 void AliHBTCrab::Set()
43 //sets this as weighitng class
44 Info("Set","Setting CRAB as Weighing Class");
46 if ( fgWeights == 0x0 )
48 fgWeights = AliHBTCrab::Instance();
51 if ( fgWeights == AliHBTCrab::Instance() ) return;
53 fgWeights = AliHBTCrab::Instance();
55 //===================================================================
57 AliHBTCrab::AliHBTCrab():
65 Fatal("AliHBTCrab","Do not use constructor directly. Use Instance() instead.");
68 //===================================================================
70 AliHBTCrab::AliHBTCrab(const AliHBTCrab &/*source*/):
78 //===================================================================
79 AliHBTCrab & AliHBTCrab::operator=(const AliHBTCrab& /*source*/)
82 return *AliHBTCrab::Instance();
85 void AliHBTCrab::Init(Int_t pid1,Int_t pid2)
87 //Initialization method
88 fMass1 = TDatabasePDG::Instance()->GetParticle(pid1)->Mass();
89 fMass2 = TDatabasePDG::Instance()->GetParticle(pid2)->Mass();
90 fInteractionWsym = 1.0;
91 fInteractionWanti = 0.0;
92 fInteractionWnosym = 0.0;
93 fInteractionDelk = 1.0;
94 fInteractionNkmax = 100;
99 //===================================================================
101 Bool_t AliHBTCrab::SetConfig(const AliHBTPair* pair)
103 //returns the SetConfig
105 Int_t pdg1 = pair->Particle1()->GetPdgCode();
106 Int_t pdg2 = pair->Particle2()->GetPdgCode();
108 if ( ( pdg1 == fPid1) && ( pdg2 == fPid2) ) return kFALSE;
109 else Init (pdg1,pdg2);
113 //===================================================================
115 Double_t AliHBTCrab::GetWeight(const AliHBTPair* partpair)
118 Double_t qred, r, qdotr, mom;
123 GetComQuantities(partpair, &qred, &r, &qdotr, &mom, &test);
126 Info("GetWeight","Test is 0");
128 Double_t corr = CorrCalc(qred,qdotr,r);
132 //===================================================================
134 void AliHBTCrab::GetComQuantities(const AliHBTPair* pair,
135 double *qred,double *r,double *qdotr,double *mom, int *test)
137 //************************************
145 static const Double_t kCmToFm = 1.e13;
146 // static const Double_t cmtoOneOverGeV = kCmToFm*fgkWcons;
148 AliHBTParticle *part1 = pair->Particle1();
149 AliHBTParticle *part2 = pair->Particle2();
151 p1[0] = part1->Energy()*1000.0;
152 p1[1] = part1->Px()*1000.0;
153 p1[2] = part1->Py()*1000.0;
154 p1[3] = part1->Pz()*1000.0;
156 p2[0] = part2->Energy()*1000.0;
157 p2[1] = part2->Px()*1000.0;
158 p2[2] = part2->Py()*1000.0;
159 p2[3] = part2->Pz()*1000.0;
162 r1[1] = part1->Vx()*kCmToFm;
163 r1[2] = part1->Vy()*kCmToFm;
164 r1[3] = part1->Vz()*kCmToFm;
167 r2[1] = part2->Vx()*kCmToFm;
168 r2[2] = part2->Vy()*kCmToFm;
169 r2[3] = part2->Vz()*kCmToFm;
171 // END OF ALICE STUFF
173 // This code is written by Scott Pratt
174 // taken from http://www.nscl.msu.edu/~pratt/freecodes/crab/home.html
180 momtest=4.0*fMaxMomentum*fMaxMomentum;
184 momtest=fMaxMomentum*fMaxMomentum;
187 double ptot2,pdotr,pp,rr;
189 if ( part1->GetPdgCode() == part2->GetPdgCode() )
192 *mom=-(p2[0]-p1[0])*(p2[0]-p1[0]);
193 for(alpha=1;alpha<4;alpha++){
194 *mom=*mom+(p2[alpha]-p1[alpha])*(p2[alpha]-p1[alpha]);
196 //#if ! defined MIXED_PAIRS_FOR_DENOM
205 kdotr=(p2[0]-p1[0])*rr;
208 for(alpha=1;alpha<4;alpha++){
209 pp=(p1[alpha]+p2[alpha]);
210 rr=(r2[alpha]-r1[alpha]);
212 kdotr=kdotr-(p2[alpha]-p1[alpha])*rr;
225 *r=sqrt(*r+pdotr*pdotr/ptot2);
229 // const double kdotp=fMass2*fMass2-fMass1*fMass1;
230 const double kdotp = part2->GetMass()*part2->GetMass()- part1->GetMass()*part1->GetMass();
232 *mom=-(p2[0]-p1[0])*(p2[0]-p1[0]);
233 ptot2=(p1[0]+p2[0])*(p1[0]+p2[0]);
234 for(alpha=1;alpha<4;alpha++){
235 *mom=*mom+(p2[alpha]-p1[alpha])*(p2[alpha]-p1[alpha]);
236 ptot2=ptot2-(p1[alpha]+p2[alpha])*(p1[alpha]+p2[alpha]);
238 *mom=*mom+kdotp*kdotp/ptot2;
239 //#if ! defined MIXED_PAIRS_FOR_DENOM
248 kdotr=(p2[0]-p1[0])*rr;
250 for(alpha=1;alpha<4;alpha++){
251 pp=(p1[alpha]+p2[alpha]);
252 rr=(r2[alpha]-r1[alpha]);
254 kdotr=kdotr-(p2[alpha]-p1[alpha])*rr;
257 kdotr=(-kdotr+kdotp*pdotr/ptot2);
267 *r=sqrt(*r+pdotr*pdotr/ptot2);
274 //===================================================================
276 double AliHBTCrab::CorrCalc(double trueqred,double trueqdotr,double truer)
278 //#define REDUCED_MOM
279 // This code is written by Scott Pratt
280 // taken from http://www.nscl.msu.edu/~pratt/freecodes/crab/home.html
281 double eta,arg,corr0;
282 // double xx,xxprime,xxjj,p1,zk;
283 // int jj,kk,ipart,ipartcount,ispin;
285 double wsymleftover,wantileftover,wnosymleftover;
287 // const double rmass=fMass1*fMass2/(fMass1+fMass2);
289 complex cphi1,cphi2,cphis,cphia;
291 doublecomplex cphi1,cphi2,cphis,cphia;
294 arg=trueqdotr/197.323-2.0*TMath::Pi()*TMath::Floor(trueqdotr/(197.323*2.0*TMath::Pi()));
295 cphi1=exp(fgkCI*arg);
296 cphis=fgkROOT2*real(cphi1);
297 cphia=fgkCI*fgkROOT2*imag(cphi1);
298 corr0=real(fInteractionWsym*cphis*conj(cphis)
299 +fInteractionWanti*cphia*conj(cphia)
300 +fInteractionWnosym*cphi1*conj(cphi1));
301 goto OUTSIDE_INTERACTION_RANGE;
304 kk=(int)TMath::Floor(trueqred/fInteractionDelk);
305 qred=(0.5+kk)*fInteractionDelk;
307 kk=(int)TMath::Floor(2.0*trueqred/fInteractionDelk);
308 qred=(0.5+kk)*fInteractionDelk/2.0;
310 qdotr=trueqdotr*qred/trueqred;
311 if(kk>=fInteractionNkmax){
313 goto OUTSIDE_INTERACTION_RANGE;
318 arg=qdotr/197.323-2.0*TMath::Pi()*TMath::Floor(qdotr/(197.323*2.0*TMath::Pi()));
319 cphi1=exp(fgkCI*arg);
322 cphis=(cphi1+cphi2)/fgkROOT2;
323 cphia=(cphi1-cphi2)/fgkROOT2;
325 /* If there are corrections for strong interactions, add the
326 change for each partial wave. If npartial = 0 then there
327 are no strong int. corrections. */
328 wsymleftover=fInteractionWsym;
329 wantileftover=fInteractionWanti;
330 wnosymleftover=fInteractionWnosym;
332 corr0=corr0+real(wsymleftover*cphis*conj(cphis)
333 +wantileftover*cphia*conj(cphia)
334 +wnosymleftover*cphi1*conj(cphi1));
335 OUTSIDE_INTERACTION_RANGE:
338 corr0=corr0+bwcalc(trueqred,truer);
345 complex AliHBTCrab::CGamma(complex c){
346 /* This calc.s gamma functions which are in the form gamma(n+i*y)
347 where n is an int and y is real. */
348 // This code is written by Scott Pratt
349 // taken from http://www.nscl.msu.edu/~pratt/freecodes/crab/home.html
351 doublecomplex AliHBTCrab::CGamma(doublecomplex c){
352 /* This calc.s gamma functions which are in the form gamma(n+i*y)
353 where n is an int and y is real. */
354 // This code is written by Scott Pratt
355 // taken from http://www.nscl.msu.edu/~pratt/freecodes/crab/home.html
360 doublecomplex cg,cphase;
363 double x,y,phase,delp,cgmag;
367 for(j=1;j<=100000;j++){
368 delp=(y/(double)j)-atan(y/(double)j);
370 if(TMath::Abs(delp)<1E-10) goto CGamma_ESCAPE;
372 printf("oops not accurate enough, increase jmax\n");
374 phase=phase-2.0*TMath::Pi()*TMath::Floor(phase/(2.0*TMath::Pi()));
375 cphase=exp(fgkCI*phase);
376 cgmag=sqrt(TMath::Pi()*y/sinh(TMath::Pi()*y));
377 mm=(int)TMath::Floor(x+0.5);
380 for(j=1;j<=-mm+1;j++){
381 cg=cg/(1.0+(double)(-j)+fgkCI*y);
385 for(j=1;j<=mm-1;j++){
386 cg=cg*((double)(j)+fgkCI*y);