1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliGenHBTosl.h"
21 //__________________________________________________________
22 /////////////////////////////////////////////////////////////
24 // class AliGenHBTosl //
26 // Genarator simulating particle correlations //
28 // The main idea of the generator is to produce particles //
29 // according to some distribution of two particle //
30 // property. In HBT they are qout,qsie and qlong. //
31 // In order to be able to generate signal that produces //
32 // given two particle correlation background must be //
33 // known before in order to produce the shape of signal //
34 // to randomize given distribution from. //
36 // The generator works as follows: //
37 // 1. Coarse Background (fQCoarseBackground) is generated //
38 // ade from the particles //
39 // given by the external generator (variable //
40 // fGenerator) by the mixing technique. //
41 // 2. Coarse signal is prduced by multiplying Coarse //
42 // background by a required function //
43 // See method FillCoarseSignal //
44 // 3. Signal is randomized out of the coarse signal //
45 // histogram (two particle property). First particle //
46 // is taken from the external generator, and the //
47 // second one is CALCULATED on the basis of the first //
48 // one and the two particle property (qout,qside,qlong)//
49 // Background is made by the mixing out of the //
50 // genereted signal events. //
51 // This step is cotinued up to the moment signal //
52 // histogram has enough statistics (data member //
54 // See method StartSignalPass1() //
55 // 4. chi is calculated for each bin (chiarray variqable) //
56 // (not the chi2 because sign is important) //
57 // Two particle prioperty //
58 // (qout,qside,qlong) is chosen at the points that //
59 // chi is the smallest. First particle is taken from //
60 // the the external generator (fGenerator) and second's /
61 // momenta are caclulated out of their momenta and //
62 // (qout,qside,qlong). Background is updated //
63 // continuesely for all the events. This step is //
64 // continued until stability conditions are fullfiled //
65 // or maximum number of iteration is reached. //
66 // 5. The same as step 4 but events are stored. //
68 ////////////////////////////////////////////////////////////
76 #include <TParticle.h>
80 #include <TStopwatch.h>
83 #include "AliGenCocktailAfterBurner.h"
84 #include "AliGeVSimParticle.h"
85 #include "AliGenGeVSim.h"
86 #include "AliGenHIJINGpara.h"
89 /***********************************************************/
90 ClassImp(AliGenHBTosl)
92 AliGenHBTosl::AliGenHBTosl():
94 fQCoarseBackground(0x0),
99 fQSecondBackground(0x0),
105 fNBinsToScale(Int_t(fQNBins*0.1)),
107 fSignalShapeCreated(0),
108 fMaxIterations(1000),
109 fMaxChiSquereChange(0.01),
110 fMaxChiSquerePerNDF(1.5),
113 fSamplePhiMin(-0.01),
114 fSamplePhiMax(TMath::TwoPi()+0.01),
120 //default constructor
122 /***********************************************************/
124 AliGenHBTosl::AliGenHBTosl(Int_t n, Int_t pid):
126 fQCoarseBackground(0x0),
131 fQSecondBackground(0x0),
137 fNBinsToScale(Int_t(fQNBins*0.1)),
139 fSignalShapeCreated(kFALSE),
140 fMaxIterations(1000),
141 fMaxChiSquereChange(0.01),
142 fMaxChiSquerePerNDF(1.5),
145 fSamplePhiMin(-0.01),
146 fSamplePhiMax(TMath::TwoPi()+0.01),
152 //default constructor
155 AliGenHBTosl::AliGenHBTosl(const AliGenHBTosl & hbt):
157 fQCoarseBackground(0x0),
162 fQSecondBackground(0x0),
168 fNBinsToScale(Int_t(fQNBins*0.1)),
170 fSignalShapeCreated(kFALSE),
171 fMaxIterations(1000),
172 fMaxChiSquereChange(0.01),
173 fMaxChiSquerePerNDF(1.5),
176 fSamplePhiMin(-0.01),
177 fSamplePhiMax(TMath::TwoPi()+0.01),
186 /***********************************************************/
188 AliGenHBTosl::~AliGenHBTosl()
191 delete fQCoarseSignal;
192 delete fQCoarseBackground;
196 delete fQSecondSignal;
197 delete fQSecondBackground;
200 /***********************************************************/
202 void AliGenHBTosl::Init()
204 //Initializes generator
205 if (fGenerator == 0x0)
208 AliGenHIJINGpara* bkggen = new AliGenHIJINGpara(fNpart*4);
212 AliGenGeVSim * gevsim = new AliGenGeVSim(0.0);
213 AliGeVSimParticle* kplus = new AliGeVSimParticle(fPID,1,fNpart, 0.17, 0.9);
214 gevsim->AddParticleType(kplus);
221 AliMevSimConfig *c = new AliMevSimConfig(1);
222 c->SetRectPlane(1); // reaction plane control, model 4
225 AliGenMevSim *mevsim = new AliGenMevSim(c);
226 mevsim->SetPtRange(0.001, 3);
227 mevsim->SetMomentumRange(0.1, 3);
228 mevsim->SetTrackingFlag(0);
229 mevsim->SetOrigin(0.0, 0.0, 0.0);
230 mevsim->SetSigma(0.0, 0.0, 0.0);
231 AliMevSimParticle *kplus = new AliMevSimParticle(kKPlus, fNpart, 0, 0.25, 0.0, 2, 0.15, 0.0, 0.0 );
232 mevsim->AddParticleType(kplus);
236 fGenerator->SetOrigin(fOrigin[0],fOrigin[1],fOrigin[2]);
237 static const Double_t kDegToRadCF = 180./TMath::Pi();
238 fGenerator->SetMomentumRange(fPtMin,fPtMax);
239 fGenerator->SetPhiRange(kDegToRadCF*fPhiMin,kDegToRadCF*fPhiMax);
240 fGenerator->SetYRange(fYMin,fYMax);
241 fGenerator->SetThetaRange(kDegToRadCF*fThetaMin,kDegToRadCF*fThetaMax);
246 // fQCoarseBackground = new TH3D("fQCoarseBackground","",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
247 // fQCoarseSignal = new TH3D("fQCoarseSignal","fQCoarseSignal",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
248 // fQCoarseBackground->Sumw2();
249 // fQCoarseSignal->Sumw2();
251 fQSignal = new TH3D("fQSignal1","fQSignal",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
252 fQBackground = new TH3D("fQBackground1","fQBackground",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
254 fQSecondSignal = new TH3D("fQSignal2","fQSignal",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
255 fQSecondBackground = new TH3D("fQBackground2","fQBackground",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
258 fQBackground->Sumw2();
259 fQSecondSignal->Sumw2();
260 fQSecondBackground->Sumw2();
262 fLogFile = new ofstream("BadEvent",ios::out);
265 /***********************************************************/
267 void AliGenHBTosl::Generate()
271 ofstream& logfile = *fLogFile;
272 logfile<<"Generate"<<"Attempts to generate "<<fNpart<<" particles.";
275 if (fStackBuffer == 0x0) fStackBuffer = new TList();
276 //Here is initialization level
277 if (fSignalShapeCreated == kFALSE)
279 TH3D *hs = 0x0, *hb = 0x0;
282 file = TFile::Open("QTSignal.root");
285 hs = (TH3D*)file->Get("fQSignal1");
286 if (hs) hs->SetDirectory(0x0);
290 file = TFile::Open("QTBackground.root");
293 hb = (TH3D*)file->Get("fQBackground1");
294 if (hb) hb->SetDirectory(0x0);
300 Info("Generate","**********************************");
301 Info("Generate","Found starting histograms in files");
302 Info("Generate","**********************************");
310 TH3D *cs = 0x0, *cb = 0x0;
311 file = TFile::Open("QTCoarseBackground.root");
314 cb = (TH3D*)file->Get("fQCoarseBackground");
315 if (cb) cb->SetDirectory(0x0);
319 file = TFile::Open("QTCoarseSignal.root");
322 cs = (TH3D*)file->Get("fQCoarseSignal");
323 if (cs) cs->SetDirectory(0x0);
330 Info("Generate","Got Coarse signal and bkg from files");
331 delete fQCoarseBackground;
332 delete fQCoarseSignal;
334 fQCoarseBackground = cb;
340 Info("Generate","Got Coarse bkg from file");
341 delete fQCoarseBackground;
342 fQCoarseBackground = cb;
346 fQCoarseBackground = new TH3D("fQCoarseBackground","",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
347 fQCoarseBackground->Sumw2();
349 FillCoarse(); //create coarse background - just to know the spectrum
352 fQCoarseSignal = new TH3D("fQCoarseSignal","fQCoarseSignal",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
353 fQCoarseSignal->Sumw2();
354 FillCoarseSignal();//create first coarse signal by brutal multplication coarse background and required function shape
357 StartSignal(); //Initilizes the stack that is used for generation
359 fSignalShapeCreated = kTRUE;
362 AliStack* stack = RotateStack();
364 AliStack* genstack = fGenerator->GetStack();
367 genstack = new AliStack(fNpart);
368 fGenerator->SetStack(genstack);
375 fGenerator->Generate();
376 Int_t j = 0, ntr = 0;
377 if ( genstack->GetNtrack() < fNpart/2)
379 Warning("Generate","************************************************************");
380 Warning("Generate","Generator generated (%d) less particles then expected (%d).",
381 stack->GetNtrack(),fNpart/2);
382 Warning("Generate","************************************************************");
385 TH3D* work = new TH3D("work","work",fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange);
386 work->SetDirectory(0x0);
389 Double_t*** chiarray = new Double_t** [fQNBins+1];
390 Double_t*** sigarray = new Double_t** [fQNBins+1];
392 for (Int_t i = 1; i<=fQNBins; i++)
394 chiarray[i] = new Double_t* [fQNBins+1];
395 sigarray[i] = new Double_t* [fQNBins+1];
397 for (Int_t k = 1; k<=fQNBins; k++)
399 chiarray[i][k] = new Double_t [fQNBins+1];
400 sigarray[i][k] = new Double_t [fQNBins+1];
405 Double_t scale = Scale(fQSignal,fQBackground);
406 work->Divide(fQSignal,fQBackground,scale);
408 Double_t binwdh = work->GetBinWidth(1)/2.;
410 for (Int_t k = 1; k<=fQNBins; k++)
412 Double_t z = work->GetZaxis()->GetBinCenter(k);
413 for (Int_t j = 1; j<=fQNBins; j++)
415 Double_t y = work->GetYaxis()->GetBinCenter(j);
416 for (Int_t i = 1; i<=fQNBins; i++)
418 sigarray[i][j][k] = fQSignal->GetBinContent(i,j,k);//store current value of signal histogram
419 Double_t x = work->GetXaxis()->GetBinCenter(i);//get center value of a bin (qinv)
420 Double_t v = GetQOutQSideQLongCorrTheorValue(x,y,z);//get expected value of CF in that qinv
421 Double_t diff = v - work->GetBinContent(i,j,k);//store difference betweeon current value, and desired value
422 chiarray[i][j][k] = diff; // no-x x is a weight to get good distribution
430 Int_t middlebin = fQNBins/2;
432 for (Int_t k = middlebin-5; k < middlebin+5; k++)
434 Double_t tx = work->GetXaxis()->GetBinCenter(30);
435 Double_t ty = work->GetYaxis()->GetBinCenter(30);
436 Double_t tz = work->GetZaxis()->GetBinCenter(k);
437 sprintf(msg,"% 6.5f ",GetQOutQSideQLongCorrTheorValue(tx,ty,tz));
442 for (Int_t k = middlebin-5; k < middlebin+5; k++)
444 sprintf(msg,"% 6.5f ",work->GetBinContent(30,30,k));
449 for (Int_t k = middlebin-5; k < middlebin+5; k++)
451 sprintf(msg,"% 6.5f ",chiarray[30][30][k]);
456 TParticle particle(fPID,0,-1,-1,-1,-1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
457 TParticle* second = &particle;
459 Bool_t shortloop = kTRUE;
460 Int_t sc = 0;//security check against infinite loop
462 while ( (ntr+1) < fNpart)
484 loopmax = fQNBins/2+fQNBins/4;
485 loopmin = fQNBins/2-fQNBins/4;
489 for (Int_t k = loopmin; k <=loopmax; k++ )
491 qlong = work->GetZaxis()->GetBinCenter(k);
492 for (Int_t j = loopmin; j<=loopmax; j++)
494 qside = work->GetYaxis()->GetBinCenter(j);
495 for (Int_t i = loopmin; i<=loopmax; i++)
497 qout = work->GetXaxis()->GetBinCenter(i);
498 if (chiarray[xmax][ymax][zmax] < chiarray[i][j][k])
505 // Double_t qdist = TMath::Sqrt(qout*qout + qside*qside + qlong*qlong);
507 // Double_t fact = chiarray[i][j][k];//chiarray is chi2
508 // if (fact > work->GetBinError(i,j,k))//if differece between what we want and
509 // { //what we have is bigger than stat. error
510 // xmax = i; //we force to fill that bin
518 Double_t qlongc = work->GetZaxis()->GetBinCenter(zmax);
519 Double_t qsidec = work->GetYaxis()->GetBinCenter(ymax);
520 Double_t qoutc = work->GetXaxis()->GetBinCenter(xmax);
523 sprintf(msg,"Generate Fill bin chi2(%d,%d,%d)=%f",xmax,ymax,zmax,chiarray[xmax][ymax][zmax]);
526 qout = gRandom->Uniform(qoutc -binwdh, qoutc +binwdh);
527 qside = gRandom->Uniform(qsidec-binwdh, qsidec+binwdh);
528 qlong = gRandom->Uniform(qlongc-binwdh, qlongc+binwdh);
530 TParticle* first = 0;
531 while (j < genstack->GetNtrack())
533 TParticle* tmpp = genstack->Particle(j++);
534 if (tmpp->GetPdgCode() == fPID)
536 if (CheckParticle(tmpp,0x0,stack) == kFALSE)
546 if ( fDebug > 2 ) Info("StartSignal","No more particles of that type");
550 //Here put the check if this particle do not fall into signal region with other partticle
552 Int_t retval = GetThreeD(first,second,qout,qside,qlong);
555 //Info("StartSignal","Can not find momenta for this OSL and particle");
558 //in case this particle is falling into signal area with another
559 //particle we take a another pair
560 //it can intruduce artificial correlations
561 Bool_t checkresult = CheckParticle(second,first,stack);
562 if ( checkresult && (sc < 10) )
569 //Put on output stack
571 SetTrack(second,ntr);
573 //Put on internal stack
575 SetTrack(first,etmp,stack);
576 SetTrack(second,etmp,stack);
578 Double_t y = GetQOutQSideQLongCorrTheorValue(qoutc,qsidec,qlongc);
580 sigarray[xmax][ymax][zmax] ++;
581 chiarray[xmax][ymax][zmax] = scale*sigarray[xmax][ymax][zmax]/fQBackground->GetBinContent(xmax,ymax,zmax);
582 chiarray[xmax][ymax][zmax] = (y - chiarray[xmax][ymax][zmax]);
586 Mix(fStackBuffer,fQBackground,fQSecondSignal); //upgrate background
587 Mix(stack,fQSignal,fQSecondBackground); //upgrate signal
591 for (Int_t i = 1; i<=fQNBins; i++)
593 for (Int_t k = 1; k<=fQNBins; k++)
595 delete [] chiarray[i][k];
596 delete [] sigarray[i][k];
598 delete [] chiarray[i];
599 delete [] sigarray[i];
604 /***********************************************************/
606 void AliGenHBTosl::GetOneD(TParticle* first, TParticle* second,Double_t qinv)
608 //deprecated method that caclulates momenta of the second particle
609 // out of qinv and the first particle
610 //first particle is rotated that only X is non-zero
613 Double_t m = first->GetMass();
614 Double_t msqrd = m*m;
615 Double_t fourmassSquered = 4.*msqrd;
617 //Condition that R must fullfill to be possible to have qinv less smaller then randomized
618 // Double_t rRange = qinv*TMath::Sqrt(qinv*qinv + fourmassSquered)/fourmassSquered;
619 // Double_t r = gRandom->Uniform(rRange);
621 Double_t r = gRandom->Uniform(qinv);
622 Double_t phi = gRandom->Uniform(TMath::TwoPi());
624 Double_t firstPx = first->P();//first particle is rotated that only X is non-zero thus P==Px
625 Double_t px = 2.*msqrd*firstPx + firstPx*qinv*qinv;
626 Double_t temp = qinv*qinv*qinv*qinv + fourmassSquered * (qinv*qinv - r*r );
629 Error("GetOneD","temp is less then 0: %f",temp);
632 temp = temp*(msqrd+firstPx*firstPx);
634 px = (px - TMath::Sqrt(temp))/(2.*msqrd);
636 Double_t py = r*TMath::Sin(phi);
637 Double_t pz = r*TMath::Cos(phi);
639 TVector3 firstpvector(first->Px(),first->Py(),first->Pz());
640 TVector3 vector(px,py,pz);
641 Rotate(firstpvector,vector);
643 Double_t e = TMath::Sqrt(msqrd + vector.X()*vector.X() + vector.Y()*vector.Y() + vector.Z()*vector.Z());
644 second->SetMomentum(vector.X(),vector.Y(),vector.Z(),e);
645 // TParticle* f = new TParticle(first->GetPdgCode(),0,-1,-1,-1,-1, firstPx,0,0,e=TMath::Sqrt(msqrd+firstPx*firstPx),0.0,0.0,0.0,0.0);
646 // TParticle(pdg, is, parent, -1, kFirstDaughter, kLastDaughter,
647 // px, py, pz, e, vx, vy, vz, tof);
649 AliDebug(1,Form("Randomized qinv = %f, obtained = %f",qinv,GetQInv(first,second)));
652 /***********************************************************/
654 Int_t AliGenHBTosl::GetThreeD(TParticle* first,TParticle* second, Double_t qout, Double_t qside, Double_t qlong)
656 //deprecated method that caclulates momenta of the second particle
657 //out of qout qside and qlong and the first particle
658 Double_t m = first->GetMass();
661 Double_t px = first->P();//first particle is rotated that only X is non-zero thus P==Px
662 Double_t px2 = px*px;
665 Double_t qout2 = qout*qout;
666 Double_t qside2 = qside*qside;
667 Double_t qlong2 = qlong*qlong;
670 Double_t util1 = 4.*px2 - qside2;//4*P1x^2 - Y^2
673 Info("GetThreeD","4.*px2* - qside2 is negative px: %f, qside: %f",px,qside);
676 Double_t util2 = TMath::Sqrt(px2*qout2*util1);
679 Double_t p2x,p2y,p2z;
681 // if ( (qside >= 0) && (qout >= 0) && (qlong >= 0))
685 Double_t tmp = px*(2.*px2 - qside2);
690 tmp = qout - TMath::Sqrt(util1);
691 p2y = - (tmp*qside)/(2.*px);
694 tmp = 4.*m2 + 2.*qout2+qlong2;
696 tmp -= 2.*util2;//!!!
700 Double_t m2px2 = m2+px2;
701 Double_t tmp2 = m2px2*tmp;
703 tmp = 4.*(m2px2+qout2) + qlong2;
706 tmp *= 4.*(m2px2) + qlong2;
707 tmp *= qlong2*qlong2;
712 Error("","Argument of sqrt is negative");
716 tmp2 += TMath::Sqrt(tmp);
718 tmp = 8.0*px*m2px2*m2px2;
719 p2z = -TMath::Sqrt(tmp2/tmp);
720 if (qlong < 0) p2z = -p2z;
725 Double_t tmp = px*(2.*px2 - qside2);
730 tmp = qout - TMath::Sqrt(util1);
731 p2y = - (tmp*qside)/(2.*px);
734 tmp = 4.*m2 + 2.*qout2+qlong2;
736 tmp += 2.*util2;//!!!
740 Double_t m2px2 = m2+px2;
741 Double_t tmp2 = m2px2*tmp;
743 tmp = 4.*(m2px2+qout2) + qlong2;
746 tmp *= 4.*(m2px2) + qlong2;
747 tmp *= qlong2*qlong2;
752 Error("","Argument of sqrt is negative");
756 tmp2 += TMath::Sqrt(tmp);
758 tmp = 8.0*px*m2px2*m2px2;
759 p2z = -TMath::Sqrt(tmp2/tmp);
760 if (qlong < 0) p2z = -p2z;
763 // if ( (qside >= 0) && (qout >= 0) && (qlong >= 0)) p2z = -p2z;
765 TVector3 firstpvector(first->Px(),first->Py(),first->Pz());
766 TVector3 vector(p2x,p2y,p2z);
767 Rotate(firstpvector,vector);
769 Double_t e = TMath::Sqrt(m2 + vector.X()*vector.X() + vector.Y()*vector.Y() + vector.Z()*vector.Z());
770 second->SetMomentum(vector.X(),vector.Y(),vector.Z(),e);
773 if ( AliDebugLevel() > 3 )
775 e=TMath::Sqrt(m2+px*px);
776 TParticle* f = new TParticle(first->GetPdgCode(),0,-1,-1,-1,-1, px , 0.0, 0.0, e,0.0,0.0,0.0,0.0);
778 e = TMath::Sqrt(m2 + p2x*p2x + p2y*p2y + p2z*p2z);
779 TParticle* s = new TParticle(first->GetPdgCode(),0,-1,-1,-1,-1, p2x, p2y, p2z, e, 0.0, 0.0, 0.0, 0.0);
782 GetQOutQSideQLong(f,s,qo, qs, ql);
784 Info("GetThreeD","TEST");
787 Info("GetThreeD","Required %f %f %f",qout,qside,qlong);
788 Info("GetThreeD","Got %f %f %f",qo,qs,ql);
792 Info("GetThreeD","!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
797 /***********************************************************/
799 void AliGenHBTosl::StartSignal()
801 //Starts the signal histograms
802 ofstream& logfile = *fLogFile;
804 logfile<<"************************************************"<<endl;
805 logfile<<"************************************************"<<endl;
806 logfile<<" StartSignal "<<endl;
807 logfile<<"************************************************"<<endl;
808 logfile<<"************************************************"<<endl;
814 TParticle particle(fPID,0,-1,-1,-1,-1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
815 TParticle* second = &particle;
817 TIter next(fStackBuffer);
818 while(( stack=(AliStack*)next() ))
823 AliStack* genstack = fGenerator->GetStack();
826 genstack = new AliStack(fNpart);
827 fGenerator->SetStack(genstack);
835 //We alread have detailed histograms and we do not need Coarse anymore
836 delete fQCoarseSignal;
837 delete fQCoarseBackground;
838 fQCoarseSignal = 0x0;
839 fQCoarseBackground = 0x0;
842 const Double_t kNDF = fQNBins*fQNBins*fQNBins;
844 TH3D* work = new TH3D("work","work",fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange);
846 work->SetDirectory(0x0);
849 Double_t binwdh = work->GetBinWidth(1)/2.;
851 Double_t*** chiarray = new Double_t** [fQNBins+1];
852 Double_t*** sigarray = new Double_t** [fQNBins+1];
854 for (Int_t i = 1; i<=fQNBins; i++)
856 chiarray[i] = new Double_t* [fQNBins+1];
857 sigarray[i] = new Double_t* [fQNBins+1];
859 for (Int_t k = 1; k<=fQNBins; k++)
861 chiarray[i][k] = new Double_t [fQNBins+1];
862 sigarray[i][k] = new Double_t [fQNBins+1];
867 Float_t chisqrchange = fMaxChiSquereChange + 1.;
868 Float_t chisqrPerDF = fMaxChiSquerePerNDF;
869 Float_t chisqrold = 0.0;
872 Int_t niterations = 1;
873 Int_t rotaxisorder = 1;//defines order of looping over 3D histo (X,Y,Z or Y,Z,X or Z,X,Y)
876 Bool_t shortloop = kTRUE;
877 TCanvas* c1 = new TCanvas();
881 Info("StartSignal","\n\n\n\nSecond Pass\n\n\n\n");
883 while ( ( (chisqrPerDF > fMaxChiSquereChange) || flag) && (niterations++ < fMaxIterations) )
886 logfile<<"StartSignal\n";
887 logfile<<" Row 1 Theory, 2 current value, 3 Chi2 \n";
889 Double_t chisqrnew = 0.0;
892 Double_t scale = Scale(fQSignal,fQBackground);
893 work->Divide(fQSignal,fQBackground,scale);
895 if ( (counter%100) == 0)
899 sprintf(buff,"QTWorkPass2.%3d.root",counter);
900 TFile* file = TFile::Open(buff,"update");
902 work->SetDirectory(0x0);
906 sprintf(buff,"QTBackgroundPass2.%3d.root",counter);
907 file = TFile::Open(buff,"update");
908 fQBackground->Write();
909 fQBackground->SetDirectory(0x0);
913 sprintf(buff,"QTSignalPass2.%3d.root",counter);
914 file = TFile::Open(buff,"update");
916 fQSignal->SetDirectory(0x0);
922 Int_t novertresh = 0;
923 for (Int_t k = 1; k<=fQNBins; k++)
925 Double_t z = work->GetZaxis()->GetBinCenter(k);
926 for (Int_t j = 1; j<=fQNBins; j++)
928 Double_t y = work->GetYaxis()->GetBinCenter(j);
929 for (Int_t i = 1; i<=fQNBins; i++)
931 Double_t x = work->GetXaxis()->GetBinCenter(i);//get center value of a bin (qout)
932 sigarray[i][j][k] = fQSignal->GetBinContent(i,j,k);//store current value of signal histogram
933 Double_t v = GetQOutQSideQLongCorrTheorValue(x,y,z);//get expected value of CF in that qinv
934 Double_t diff = v - work->GetBinContent(i,j,k);//store difference betweeon current value, and desired value
935 chiarray[i][j][k] = diff; // no-x x is a weight to get good distribution
936 Double_t be = work->GetBinError(i,j,k);
937 chisqrnew += diff*diff/(be*be);//add up chisq
939 //even if algorithm is stable (chi sqr change less then threshold)
940 //and any bin differs more then 5% from expected value we continue
941 Double_t fact = diff;
942 if (TMath::Abs(fact) > 0.1)
956 for (Int_t k = 25; k < 36; k++)
958 Double_t tx = work->GetXaxis()->GetBinCenter(30);
959 Double_t ty = work->GetYaxis()->GetBinCenter(30);
960 Double_t tz = work->GetZaxis()->GetBinCenter(k);
961 sprintf(msg,"% 6.5f ",GetQOutQSideQLongCorrTheorValue(tx,ty,tz));
966 for (Int_t k = 25; k < 36; k++)
968 sprintf(msg,"%6.5f ",work->GetBinContent(30,30,k));
973 for (Int_t k = 25; k < 36; k++)
975 sprintf(msg,"% 6.5f ",chiarray[30][30][k]);
980 chisqrchange = TMath::Abs(chisqrnew - chisqrold)/chisqrnew;
981 chisqrold = chisqrnew;
983 chisqrPerDF = chisqrnew/kNDF;
985 Info("StartSignal","Iteration %d Chi-sq change %f%%",niterations,chisqrchange*100.0);
986 Info("StartSignal","ChiSq = %f, NDF = %f, ChiSq/NDF = %f",chisqrnew, kNDF, chisqrPerDF );
987 Info("StartSignal","novertresh = %d",novertresh);
990 stack = RotateStack();
992 fGenerator->Generate();
993 Int_t ninputparticle = 0, ntr = 0;
994 if ( genstack->GetNtrack() < fNpart/2)
996 Warning("StartSignal","**********************************");
997 Warning("StartSignal","Generator generated (%d) less particles then expected (%d).",
998 genstack->GetNtrack(),fNpart/2);
999 Warning("StartSignal","**********************************");
1002 Int_t sc = 0; //security check against infinite loop
1003 while ( (ntr+1) < fNpart)//ntr is number of track generated up to now
1018 switch (rotaxisorder)
1037 if (rotaxisorder > 3) rotaxisorder = 1;
1051 // Bool_t force = kFALSE;
1052 for ( k = 1; k <=nrange;k++ )
1054 for ( j = 1; j<=nrange; j++)
1056 for ( i = 1; i<=nrange; i++)
1058 if ( (chiarray[*cx][*cy][*cz]) > (chiarray[xmax][ymax][zmax]) )
1065 // Double_t fact = chiarray[*cx][*cy][*cz];//chiarray is chi2*qinv
1066 // if (fact > work->GetBinError(*cx,*cy,*cz))//if differece between what we want and
1067 // { //what we have is bigger than stat. error
1068 // //we force to fill that bin
1069 // qout = work->GetXaxis()->GetBinCenter(*cx);
1070 // qside = work->GetYaxis()->GetBinCenter(*cy);
1071 // qlong = work->GetZaxis()->GetBinCenter(*cz);
1073 // Info("StartSignal"," bin: (%d,%d,%d) loop status (%d,%d,%d) \nUsing Force: chiarray: %f \nq(o,s,l): (%f,%f,%f) signal: %d background: %d binerror: %f",
1074 // *cx,*cy,*cz,i,j,k,fact,qout,qside,qlong,
1075 // (Int_t)sigarray[*cx][*cy][*cz],(Int_t)fQBackground->GetBinContent(*cx,*cy,*cz),work->GetBinError(*cx,*cy,*cz));
1081 // if (force) break;
1083 // if (force) break;
1087 qout = work->GetXaxis()->GetBinCenter(xmax);
1088 qside = work->GetYaxis()->GetBinCenter(ymax);
1089 qlong = work->GetZaxis()->GetBinCenter(zmax);
1091 // Info("StartSignal"," bin: (%d,%d,%d) chiarray: %f \nq(o,s,l): (%f,%f,%f) signal: %d background: %d binerror: %f",
1092 // xmax,ymax,zmax,chiarray[xmax][ymax][zmax],qout,qside,qlong,
1093 // (Int_t)sigarray[xmax][ymax][zmax],
1094 // (Int_t)fQBackground->GetBinContent(xmax,ymax,zmax),
1095 // work->GetBinError(xmax,ymax,zmax));
1097 qout = gRandom->Uniform(qout-binwdh,qout+binwdh);
1098 qside = gRandom->Uniform(qside-binwdh,qside+binwdh);
1099 qlong = gRandom->Uniform(qlong-binwdh,qlong+binwdh);
1101 TParticle* first = 0;
1102 while (ninputparticle < genstack->GetNtrack())
1104 TParticle* tmpp = genstack->Particle(ninputparticle++);
1105 if (tmpp->GetPdgCode() == fPID)
1107 if (CheckParticle(tmpp,0x0,stack) == kFALSE)
1117 if ( fDebug > 2 ) Info("StartSignal","No more particles of that type");
1121 Int_t retval = GetThreeD(first,second,qout,qside,qlong);
1124 Info("StartSignal","Can not find momenta for this OSL and particle OSL = %f %f %f",qout,qside,qlong);
1130 //in case this particle is falling into signal area with another
1131 //particle we take a another pair
1132 //it can intruduce artificial correlations
1133 Bool_t checkresult = CheckParticle(second,first,stack);
1134 if ( checkresult && (sc < 10) )
1141 //Put on output stack
1142 SetTrack(first,ntr,stack);
1143 SetTrack(second,ntr,stack);
1145 Double_t y = GetQOutQSideQLongCorrTheorValue(qout,qside,qlong);
1147 sigarray[xmax][ymax][zmax] ++;
1148 chiarray[xmax][ymax][zmax] = scale*sigarray[xmax][ymax][zmax]/fQBackground->GetBinContent(xmax,ymax,zmax);
1149 chiarray[xmax][ymax][zmax] = (y - chiarray[xmax][ymax][zmax]);
1152 Info("StartSignal","Mixing background...");
1153 Mix(fStackBuffer,fQBackground,fQSecondBackground); //upgrate background
1154 Info("StartSignal","Mixing signal...");
1155 Mix(stack,fQSignal,fQSecondSignal); //upgrate background
1158 // if ( (chisqrPerDF < 2.0) && (fSwapped == kFALSE) )
1160 // SwapGeneratingHistograms();
1164 TFile* filef = TFile::Open("QTBackground.root","recreate");
1165 fQBackground->Write();
1166 fQBackground->SetDirectory(0x0);
1170 filef = TFile::Open("QTSignal.root","recreate");
1172 fQSignal->SetDirectory(0x0);
1180 for (Int_t i = 1; i<=fQNBins; i++)
1182 for (Int_t k = 1; k<=fQNBins; k++)
1184 delete [] chiarray[i][k];
1185 delete [] sigarray[i][k];
1187 delete [] chiarray[i];
1188 delete [] sigarray[i];
1194 /***********************************************************/
1196 void AliGenHBTosl::StartSignalPass1()
1198 //This method makes first part of the initialization of working histograms
1199 //It randomizes qout, qside and qlong from the coarse signal histogram
1201 Bool_t flag = kTRUE;
1202 TParticle particle(fPID,0,-1,-1,-1,-1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
1203 TParticle* second = &particle;
1208 Info("StartSignalPass1","\n\nFirst Pass\n\n");
1212 Info("StartSignalPass1","NextEvent");
1213 AliStack* stack = RotateStack();
1214 AliStack* genstack = fGenerator->GetStack();
1216 fGenerator->Generate();
1217 Int_t j = 0, ntr = 0;
1218 if ( genstack->GetNtrack() < fNpart/2)
1220 Warning("StartSignalPass1","**********************************");
1221 Warning("StartSignalPass1","Generator generated (%d) less particles then expected (%d).",
1222 genstack->GetNtrack(),fNpart/2);
1223 Warning("StartSignalPass1","**********************************");
1226 Int_t sc = 0;//security check against infinite loop
1227 while ((ntr+1)<fNpart)
1230 // Info("StartSignal","Number of track on output stack: = %d", ntr);
1231 // Info("StartSignal","Number of track on input stack: = %d\n", j);
1233 TParticle* first = 0;
1234 while (j < genstack->GetNtrack())
1236 TParticle* tmpp = genstack->Particle(j++);
1237 if (tmpp->GetPdgCode() == fPID)
1239 if (CheckParticle(tmpp,0x0,stack) == kFALSE)
1246 Info("StartSignalPass1","Particle did not pass the safety check 1");
1254 if ( fDebug > 2 ) Info("StartSignalPass1","No more particles of that type");
1259 SetTrack(first,ntr,stack);
1261 fQCoarseSignal->GetRandom3(qout,qside,qlong);
1263 Int_t retval = GetThreeD(first,second,qout,qside,qlong);
1266 //Info("StartSignal","Can not find momenta for this OSL and particle");
1269 //in case this particle is falling into signal area with another
1270 //particle we take a another pair
1271 //it can intruduce artificial correlations
1272 Bool_t checkresult = CheckParticle(second,first,stack);
1273 if ( checkresult && (sc < 10) )
1276 Info("StartSignalPass1","Particle did not pass the safety check 2");
1283 SetTrack(second,ntr,stack);
1286 Mix(stack,fQSignal,fQSecondSignal);
1287 Mix(fStackBuffer,fQBackground,fQSecondBackground);
1291 for (Int_t k = 1; k<=fQNBins; k++)
1293 for (Int_t j = 1; j<=fQNBins; j++)
1295 for (Int_t i = 1; i<=fQNBins; i++)
1297 if ( (fQBackground->GetBinContent(i,j,k) < fMinFill) )
1299 //(fQSignal->GetBinContent(i,j,k) < fMinFill) ||
1300 Info("StartSignalPass1","bin (%d,%d,%d): signal=%f background=%f",i,j,k,
1301 fQSignal->GetBinContent(i,j,k),fQBackground->GetBinContent(i,j,k));
1302 flag = kTRUE;//continue while
1303 break;//breakes for not while
1306 if (flag == kTRUE) break;
1308 if (flag == kTRUE) break;
1315 /***********************************************************/
1317 void AliGenHBTosl::FillCoarseSignal()
1319 //Makes coarse signal by multiplying the coarse background and required function
1320 Info("FillCoarseSignal","START");
1321 for (Int_t k = 1; k <=fQNBins ;k++ )
1323 Double_t z = fQCoarseBackground->GetZaxis()->GetBinCenter(k);
1324 for (Int_t j = 1; j <=fQNBins; j++)
1326 Double_t y = fQCoarseBackground->GetYaxis()->GetBinCenter(j);
1327 for (Int_t i = 1; i <=fQNBins; i++)
1329 Double_t x = fQCoarseBackground->GetXaxis()->GetBinCenter(i);
1330 Double_t v = GetQOutQSideQLongCorrTheorValue(x,y,z);
1331 Info("FillCoarseSignal","Bin (%d,%d,%d): osl(%f,%f,%f)=%f",i,j,k,x,y,z,v);
1332 fQCoarseSignal->SetBinContent(i,j,k,v*fQCoarseBackground->GetBinContent(i,j,k));
1337 //if (AliDebugLevel())
1340 Info("FillCoarseSignal","DONE");
1342 /***********************************************************/
1344 void AliGenHBTosl::FillCoarse()
1346 //creates the statistical background histogram on the base of input from
1348 Info("FillCoarse","START");
1354 TH3D tmph("tmph","tmph",2,0,1,2,0,1,2,0,1);
1359 // if (niter > 20) break;
1361 cout<<niter++<<" bincont "<<fQCoarseBackground->GetBinContent(30,30,28)
1362 <<" "<<fQCoarseBackground->GetBinContent(30,30,29)
1363 <<" "<<fQCoarseBackground->GetBinContent(30,30,30)
1364 <<" "<<fQCoarseBackground->GetBinContent(30,30,31)
1365 <<" "<<fQCoarseBackground->GetBinContent(30,30,32)
1369 stack = RotateStack();
1370 fGenerator->SetStack(stack);
1372 fGenerator->Generate();
1374 Mix(fStackBuffer,fQCoarseBackground,&tmph);
1378 Info("FillCoarse","fMinFill = %d",fMinFill);
1379 for (Int_t k = 1; k<=fQNBins; k++)
1381 for (Int_t j = 1; j<=fQNBins; j++)
1383 for (Int_t i = 1; i<=fQNBins; i++)
1385 if ( fQCoarseBackground->GetBinContent(i,j,k) < fMinFill )
1388 Info("FillCoarse","bin (%d,%d,%d)=%f",i,j,k,fQCoarseBackground->GetBinContent(i,j,k));
1400 fGenerator->SetStack(0x0);
1401 Info("FillCoarse","DONE");
1404 /***********************************************************/
1406 void AliGenHBTosl::Mix(TList* eventbuffer,TH3D* denominator,TH3D* denominator2)
1408 //Fills denominators
1409 //Mixes events stored in the eventbuffer and fills the background histograms
1410 static TStopwatch stoper;
1412 if (eventbuffer == 0x0)
1414 Error("Mix","Buffer List is null.");
1418 if (denominator == 0x0)
1420 Error("Mix","Denominator histogram is null.");
1424 if (denominator2 == 0x0)
1426 Error("Mix","Denominator2 histogram is null.");
1430 Info("Mix","%s",denominator->GetName());
1433 TIter next(eventbuffer);
1434 AliStack* firstevent;
1435 AliStack* secondevent = 0x0;
1437 while(( firstevent=(AliStack*)next() ))
1439 if (secondevent == 0x0)
1441 secondevent = firstevent;
1444 // Info("Mix","Mixing %#x with %#x",firstevent,secondevent);
1445 for(Int_t j = 0; j < firstevent->GetNtrack(); j++ )
1447 TParticle* firstpart = firstevent->Particle(j);
1449 Float_t phi = firstpart->Phi();
1450 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1452 // Info("Mix","Mixing %d phi %f min %f max %f",j,phi,fSamplePhiMin,fSamplePhiMax);
1454 for(Int_t i = 0; i < secondevent->GetNtrack(); i++ )
1456 TParticle* secondpart = secondevent->Particle(i);
1457 phi = secondpart->Phi();
1458 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1463 GetQOutQSideQLong(firstpart,secondpart,qout,qside,qlong);
1464 denominator->Fill(qout,qside,qlong);
1465 denominator2->Fill(qout,qside,qlong);
1469 secondevent = firstevent;
1475 /***********************************************************/
1477 void AliGenHBTosl::Mix(AliStack* stack, TH3D* numerator, TH3D* numerator2)
1479 //fils numerator with particles from stack
1480 static TStopwatch stoper;
1483 Error("Mix","Stack is null.");
1487 if ( (numerator == 0x0) || (numerator2 == 0x0) )
1489 Error("Mix","Numerator histogram is null.");
1493 Info("Mix","%s",numerator->GetName());
1496 for(Int_t j = 0; j < stack->GetNtrack(); j++ )
1498 TParticle* firstpart = stack->Particle(j);
1499 Float_t phi = firstpart->Phi();
1500 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1502 for(Int_t i = j+1; i < stack->GetNtrack(); i++ )
1504 TParticle* secondpart = stack->Particle(i);
1505 phi = secondpart->Phi();
1506 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1510 GetQOutQSideQLong(firstpart,secondpart,qout,qside,qlong);
1511 numerator->Fill(qout,qside,qlong);
1512 numerator2->Fill(qout,qside,qlong);
1519 /***********************************************************/
1521 Double_t AliGenHBTosl::GetQInv(TParticle* f, TParticle* s)
1524 // cout<<f->Px()<<" "<<s->Px()<<endl;
1525 Double_t pxdiff = f->Px() - s->Px();
1526 Double_t pydiff = f->Py() - s->Py();
1527 Double_t pzdiff = f->Pz() - s->Pz();
1528 Double_t ediff = f->Energy() - s->Energy();
1530 Double_t qinvl = ediff*ediff - ( pxdiff*pxdiff + pydiff*pydiff + pzdiff*pzdiff );
1531 Double_t qinv = TMath::Sqrt(TMath::Abs(qinvl));
1534 /***********************************************************/
1536 void AliGenHBTosl::GetQOutQSideQLong(TParticle* f, TParticle* s,Double_t& out, Double_t& side, Double_t& lon)
1538 //returns qout,qside and qlong of the pair of particles
1539 out = side = lon = 10e5;
1541 Double_t pxsum = f->Px() + s->Px();
1542 Double_t pysum = f->Py() + s->Py();
1543 Double_t pzsum = f->Pz() + s->Pz();
1544 Double_t esum = f->Energy() + s->Energy();
1545 Double_t pxdiff = f->Px() - s->Px();
1546 Double_t pydiff = f->Py() - s->Py();
1547 Double_t pzdiff = f->Pz() - s->Pz();
1548 Double_t ediff = f->Energy() - s->Energy();
1549 Double_t kt = 0.5*TMath::Hypot(pxsum,pysum);
1551 Double_t k2 = pxsum*pxdiff+pysum*pydiff;
1562 side = (f->Px()*s->Py()-s->Px()*f->Py())/kt;
1565 Double_t beta = pzsum/esum;
1566 Double_t gamma = 1.0/TMath::Sqrt(1.0 - beta*beta);
1568 lon = gamma * ( pzdiff - beta*ediff );
1570 // out = TMath::Abs(out);
1571 // side = TMath::Abs(side);
1572 // lon = TMath::Abs(lon);
1575 /***********************************************************/
1577 Double_t AliGenHBTosl::Scale(TH3D* num, TH3D* den)
1579 //Calculates the factor that should be used to scale
1580 //quatience of num and den to 1 at tail
1582 AliDebug(1,"Entered");
1585 AliError("No numerator");
1590 AliError("No denominator");
1594 if(fNBinsToScale < 1)
1596 AliError("Number of bins for scaling is smaller than 1");
1599 Int_t fNBinsToScaleX = fNBinsToScale;
1600 Int_t fNBinsToScaleY = fNBinsToScale;
1601 Int_t fNBinsToScaleZ = fNBinsToScale;
1603 Int_t nbinsX = num->GetNbinsX();
1604 if (fNBinsToScaleX > nbinsX)
1606 AliError("Number of X bins for scaling is bigger thnan number of bins in histograms");
1610 Int_t nbinsY = num->GetNbinsX();
1611 if (fNBinsToScaleY > nbinsY)
1613 AliError("Number of Y bins for scaling is bigger thnan number of bins in histograms");
1617 Int_t nbinsZ = num->GetNbinsZ();
1618 if (fNBinsToScaleZ > nbinsZ)
1620 AliError("Number of Z bins for scaling is bigger thnan number of bins in histograms");
1624 AliDebug(1,"No errors detected");
1626 Int_t offsetX = nbinsX - fNBinsToScaleX - 1; //bin that we start loop over bins in axis X
1627 Int_t offsetY = nbinsY - fNBinsToScaleY - 1; //bin that we start loop over bins in axis Y
1628 Int_t offsetZ = nbinsZ - fNBinsToScaleZ - 1; //bin that we start loop over bins in axis Z
1630 Double_t densum = 0.0;
1631 Double_t numsum = 0.0;
1633 for (Int_t k = offsetZ; k<nbinsZ; k++)
1634 for (Int_t j = offsetY; j<nbinsY; j++)
1635 for (Int_t i = offsetX; i<nbinsX; i++)
1637 if ( num->GetBinContent(i,j,k) > 0.0 )
1640 densum += den->GetBinContent(i,j,k);
1641 numsum += num->GetBinContent(i,j,k);
1645 AliDebug(1,Form("numsum=%f densum=%f fNBinsToScaleX=%d fNBinsToScaleY=%d fNBinsToScaleZ=%d",
1646 numsum,densum,fNBinsToScaleX,fNBinsToScaleY,fNBinsToScaleZ));
1648 if (numsum == 0) return 0.0;
1649 Double_t ret = densum/numsum;
1651 AliDebug(1,Form("returning %f",ret));
1655 /***********************************************************/
1657 void AliGenHBTosl::TestCoarseSignal()
1659 //Tests how works filling from generated histogram shape
1660 TH3D* work = new TH3D("work","work",fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange);
1662 // for (Int_t i = 0; i < fQCoarseBackground->GetEntries() ;i++)
1665 // fQCoarseSignal->GetRandom3(x,y,z);
1666 // work->Fill(x,y,z);
1669 TCanvas* c1 = new TCanvas();
1672 c1->SaveAs("QTwork.root");
1673 TFile* file = TFile::Open("QTwork.root","update");
1675 work->SetDirectory(0x0);
1678 fQCoarseSignal->Draw();
1679 c1->SaveAs("QTCoarseSignal.root");
1680 file = TFile::Open("QTCoarseSignal.root","update");
1681 fQCoarseSignal->Write();
1682 fQCoarseSignal->SetDirectory(0x0);
1685 fQCoarseBackground->Draw();
1686 c1->SaveAs("QTCoarseBackground.root");
1687 file = TFile::Open("QTCoarseBackground.root","update");
1688 fQCoarseBackground->Write();
1689 fQCoarseBackground->SetDirectory(0x0);
1692 TH1 *result = (TH1*)fQCoarseBackground->Clone("ratio");
1693 result->SetTitle("ratio");
1694 Float_t normfactor = Scale(work,fQCoarseBackground);
1695 result->Divide(work,fQCoarseBackground,normfactor);//work
1700 c1->SaveAs("QTresult.root");
1701 file = TFile::Open("QTresult.root","update");
1703 result->SetDirectory(0x0);
1709 /***********************************************************/
1711 void AliGenHBTosl::SetTrack(TParticle* p, Int_t& ntr)
1713 //Shortcut to PushTrack(bla,bla,bla,bla.............)
1716 Error("SetTrack(TParticle*,Int_t&)","Particle has zero momentum");
1721 Int_t pdg = p->GetPdgCode();
1722 Double_t px = p->Px();
1723 Double_t py = p->Py();
1724 Double_t pz = p->Pz();
1725 Double_t e = p->Energy();
1726 Double_t vx = p->Vx();
1727 Double_t vy = p->Vy();
1728 Double_t vz = p->Vz();
1729 Double_t tof = p->T();
1732 p->GetPolarisation(pol);
1734 Double_t polx = pol.X();
1735 Double_t poly = pol.Y();
1736 Double_t polz = pol.Z();
1737 TMCProcess mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
1738 Float_t weight = p->GetWeight();
1740 AliGenerator::PushTrack(fTrackIt, -1, pdg, px, py, pz, e, vx, vy, vz, tof,polx, poly, polz, mech, ntr, weight);
1742 /***********************************************************/
1744 void AliGenHBTosl::SetTrack(TParticle* p, Int_t& ntr, AliStack* stack) const
1746 //Shortcut to SetTrack(bla,bla,bla,bla.............)
1749 Error("SetTrack(TParticle*,Int_t&,AliStack*)","Particle has zero momentum");
1753 Int_t pdg = p->GetPdgCode();
1754 Double_t px = p->Px();
1755 Double_t py = p->Py();
1756 Double_t pz = p->Pz();
1757 Double_t e = p->Energy();
1759 stack->PushTrack(fTrackIt, -1, pdg, px, py, pz, e, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, kPPrimary, ntr,1,0);
1761 /***********************************************************/
1763 void AliGenHBTosl::Rotate(TVector3& relvector, TVector3& vector)
1765 //This method rotates vector about the angeles that are needed to rotate
1766 //relvector from postion (firstPx,0,0) to its actual positon
1767 //In other words: To make equations easier
1769 static TVector3 first;
1770 if (AliDebugLevel()>=1)
1772 first.SetXYZ(relvector.x(),relvector.y(),relvector.z());
1775 Double_t firstPx = TMath::Sqrt( relvector.x()*relvector.x() +
1776 relvector.y()*relvector.y() +
1777 relvector.z()*relvector.z() );
1779 Double_t rotAngleZ = -TMath::ATan2(relvector.y(),relvector.x());//calculating rot angles
1780 relvector.RotateZ(rotAngleZ);
1781 rotAngleZ = -rotAngleZ;
1782 Double_t rotAngleY = -TMath::ATan2(relvector.z(),relvector.x());
1784 vector.RotateY(rotAngleY);
1785 vector.RotateZ(rotAngleZ);
1787 if (AliDebugLevel()>5)
1789 TVector3 test(firstPx,0.0,0.0);
1790 test.RotateY(rotAngleY);
1791 test.RotateZ(rotAngleZ);
1792 AliInfo(Form("Rotation test: px %f %f",first.x(),test.x()));
1793 AliInfo(Form("Rotation test: py %f %f",first.y(),test.y()));
1794 AliInfo(Form("Rotation test: pz %f %f",first.z(),test.z()));
1797 /***********************************************************/
1799 Double_t AliGenHBTosl::Rotate(Double_t x,Double_t y,Double_t z)
1801 //Rotates vector to base where only x - coordinate is no-zero, and returns that
1803 Double_t xylength = TMath::Hypot(x,y);
1804 Double_t sinphi = -y/xylength;
1805 Double_t cosphi = x/xylength;
1807 Double_t xprime = cosphi*x - sinphi*y;
1808 Double_t yprime = sinphi*x + cosphi*y;
1811 Double_t a1 = -TMath::ATan2(v.Y(),v.X());
1813 if (AliDebugLevel()>5)
1815 AliInfo(Form("Xpr = %f Ypr = %f",xprime,yprime));
1816 AliInfo(Form("Calc sin = %f, and %f",sinphi,TMath::Sin(a1)));
1817 AliInfo(Form("Calc cos = %f, and %f",cosphi,TMath::Cos(a1)));
1820 Double_t xprimezlength = TMath::Hypot(xprime,z);
1822 Double_t sintheta = z/xprimezlength;
1823 Double_t costheta = xprime/xprimezlength;
1826 Double_t xbis = sintheta*z + costheta*(cosphi*x - sinphi*y);
1828 AliInfo(Form("Calculated rot %f, modulus %f",xbis,TMath::Sqrt(x*x+y*y+z*z)));
1831 /***********************************************************/
1833 AliStack* AliGenHBTosl::RotateStack()
1835 //swaps to next stack last goes to first and is reseted
1838 if ( fStackBuffer->GetSize() >= fBufferSize )
1840 stack = (AliStack*)fStackBuffer->Remove(fStackBuffer->Last());
1844 stack = new AliStack(fNpart);
1847 fStackBuffer->AddFirst(stack);
1851 /***********************************************************/
1853 Double_t AliGenHBTosl::GetQInvCorrTheorValue(Double_t qinv) const
1855 //Function (deprecated)
1856 static const Double_t kFactorsqrd = 0.197*0.197;//squared conversion factor SI<->eV
1858 return 1.0 + 0.5*TMath::Exp(-qinv*qinv*fQRadius*fQRadius/kFactorsqrd);
1860 /***********************************************************/
1862 Double_t AliGenHBTosl::GetQOutQSideQLongCorrTheorValue(Double_t& out, Double_t& side, Double_t& lon) const
1864 //Theoretical function. Wa want to get correlation of the shape of this function
1865 static const Double_t kFactorsqrd = 0.197*0.197;//squared conversion factor SI<->eV
1866 return 1.0 + 0.7*TMath::Exp(-fQRadius*fQRadius*(out*out+side*side+lon*lon)/kFactorsqrd);
1868 /***********************************************************/
1870 Bool_t AliGenHBTosl::CheckParticle(TParticle* p, TParticle* aupair ,AliStack* stack)
1872 //Checks if a given particle is falling into signal region with any other particle
1873 //already existing on stack
1876 if (fSignalRegion <=0) return kFALSE;
1878 for (Int_t i = 0; i < stack->GetNtrack(); i++)
1880 TParticle* part = stack->Particle(i);
1881 if (part == aupair) continue;
1882 Double_t qout = 10e5;
1883 Double_t qside= 10e5;
1884 Double_t qlong= 10e5;
1885 GetQOutQSideQLong(p,part,qout,qside,qlong);
1887 if (TMath::Abs(qout) < fSignalRegion)
1888 if (TMath::Abs(qside) < fSignalRegion)
1889 if (TMath::Abs(qlong) < fSignalRegion)
1894 /***********************************************************/
1896 void AliGenHBTosl::SwapGeneratingHistograms()
1898 //Checks if it is time to swap signal and background histograms
1899 //if yes it swaps them
1900 Int_t threshold = fMinFill;
1901 for (Int_t k = 1; k<=fQNBins; k++)
1903 for (Int_t j = 1; j<=fQNBins; j++)
1905 for (Int_t i = 1; i<=fQNBins; i++)
1907 if ( fQSecondBackground->GetBinContent(i,j,k) < threshold) return;
1914 Info("SwapGeneratingHistograms","*******************************************");
1915 Info("SwapGeneratingHistograms","*******************************************");
1916 Info("SwapGeneratingHistograms","*******************************************");
1917 Info("SwapGeneratingHistograms","**** SWAPPING HISTOGRAMS ****");
1918 Info("SwapGeneratingHistograms","*******************************************");
1919 Info("SwapGeneratingHistograms","*******************************************");
1920 Info("SwapGeneratingHistograms","*******************************************");
1924 fQSignal = fQSecondSignal;
1926 fQSecondSignal->Reset();
1927 fQSecondSignal->SetDirectory(0x0);
1930 fQBackground = fQSecondBackground;
1931 fQSecondBackground = h;
1932 fQSecondBackground->Reset();
1933 fQSecondBackground->SetDirectory(0x0);
1939 AliGenHBTosl& AliGenHBTosl::operator=(const AliGenHBTosl& rhs)
1941 // Assignment operator
1946 void AliGenHBTosl::Copy(TObject&) const
1951 Fatal("Copy","Not implemented!\n");