1 #include "AliGenHBTosl.h"
2 //__________________________________________________________
3 /////////////////////////////////////////////////////////////
5 // class AliGenHBTosl //
7 // Genarator simulating particle correlations //
9 // The main idea of the generator is to produce particles //
10 // according to some distribution of two particle //
11 // property. In HBT they are qout,qsie and qlong. //
12 // In order to be able to generate signal that produces //
13 // given two particle correlation background must be //
14 // known before in order to produce the shape of signal //
15 // to randomize given distribution from. //
17 // The generator works as follows: //
18 // 1. Coarse Background (fQCoarseBackground) is generated //
19 // ade from the particles //
20 // given by the external generator (variable //
21 // fGenerator) by the mixing technique. //
22 // 2. Coarse signal is prduced by multiplying Coarse //
23 // background by a required function //
24 // See method FillCoarseSignal //
25 // 3. Signal is randomized out of the coarse signal //
26 // histogram (two particle property). First particle //
27 // is taken from the external generator, and the //
28 // second one is CALCULATED on the basis of the first //
29 // one and the two particle property (qout,qside,qlong)//
30 // Background is made by the mixing out of the //
31 // genereted signal events. //
32 // This step is cotinued up to the moment signal //
33 // histogram has enough statistics (data member //
35 // See method StartSignalPass1() //
36 // 4. chi is calculated for each bin (chiarray variqable) //
37 // (not the chi2 because sign is important) //
38 // Two particle prioperty //
39 // (qout,qside,qlong) is chosen at the points that //
40 // chi is the smallest. First particle is taken from //
41 // the the external generator (fGenerator) and second's /
42 // momenta are caclulated out of their momenta and //
43 // (qout,qside,qlong). Background is updated //
44 // continuesely for all the events. This step is //
45 // continued until stability conditions are fullfiled //
46 // or maximum number of iteration is reached. //
47 // 5. The same as step 4 but events are stored. //
49 ////////////////////////////////////////////////////////////
51 #include <Riostream.h>
58 #include <TParticle.h>
62 #include <TStopwatch.h>
65 #include "AliGenCocktailAfterBurner.h"
66 #include "AliGeVSimParticle.h"
67 #include "AliGenGeVSim.h"
68 #include "AliGenHIJINGpara.h"
70 /***********************************************************/
71 ClassImp(AliGenHBTosl)
73 AliGenHBTosl::AliGenHBTosl():
75 fQCoarseBackground(0x0),
80 fQSecondBackground(0x0),
85 fNBinsToScale(Int_t(fQNBins*0.2)),
88 fMaxChiSquereChange(0.01),
89 fMaxChiSquerePerNDF(1.5),
93 fSamplePhiMax(TMath::TwoPi()+0.01),
99 /***********************************************************/
101 AliGenHBTosl::AliGenHBTosl(Int_t n, Int_t pid):
103 fQCoarseBackground(0x0),
108 fQSecondBackground(0x0),
113 fNBinsToScale(Int_t(fQNBins*0.2)),
115 fSignalShapeCreated(kFALSE),
117 fMaxChiSquereChange(0.01),
118 fMaxChiSquerePerNDF(1.5),
121 fSamplePhiMin(-0.01),
122 fSamplePhiMax(TMath::TwoPi()+0.01),
126 //default constructor
128 /***********************************************************/
130 AliGenHBTosl::~AliGenHBTosl()
133 delete fQCoarseSignal;
134 delete fQCoarseBackground;
138 delete fQSecondSignal;
139 delete fQSecondBackground;
143 void AliGenHBTosl::Init()
145 //Initializes generator
146 if (fGenerator == 0x0)
149 AliGenHIJINGpara* bkggen = new AliGenHIJINGpara(fNpart*4);
153 AliGenGeVSim * gevsim = new AliGenGeVSim(0.0);
154 AliGeVSimParticle* kplus = new AliGeVSimParticle(fPID,1,fNpart, 0.17, 0.9);
155 gevsim->AddParticleType(kplus);
162 AliMevSimConfig *c = new AliMevSimConfig(1);
163 c->SetRectPlane(1); // reaction plane control, model 4
166 AliGenMevSim *mevsim = new AliGenMevSim(c);
167 mevsim->SetPtRange(0.001, 3);
168 mevsim->SetMomentumRange(0.1, 3);
169 mevsim->SetTrackingFlag(0);
170 mevsim->SetOrigin(0.0, 0.0, 0.0);
171 mevsim->SetSigma(0.0, 0.0, 0.0);
172 AliMevSimParticle *kplus = new AliMevSimParticle(kKPlus, fNpart, 0, 0.25, 0.0, 2, 0.15, 0.0, 0.0 );
173 mevsim->AddParticleType(kplus);
177 fGenerator->SetOrigin(fOrigin[0],fOrigin[1],fOrigin[2]);
178 static const Double_t degtoradcf = 180./TMath::Pi();
179 fGenerator->SetMomentumRange(fPtMin,fPtMax);
180 fGenerator->SetPhiRange(degtoradcf*fPhiMin,degtoradcf*fPhiMax);
181 fGenerator->SetYRange(fYMin,fYMax);
182 fGenerator->SetThetaRange(degtoradcf*fThetaMin,degtoradcf*fThetaMax);
187 fQCoarseBackground = new TH3D("fQCoarseBackground","",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
188 fQCoarseSignal = new TH3D("fQCoarseSignal","fQCoarseSignal",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
189 fQSignal = new TH3D("fQSignal1","fQSignal",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
190 fQBackground = new TH3D("fQBackground1","fQBackground",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
192 fQSecondSignal = new TH3D("fQSignal2","fQSignal",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
193 fQSecondBackground = new TH3D("fQBackground2","fQBackground",fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange, fQNBins,-fQRange,fQRange);
195 fQCoarseBackground->Sumw2();
196 fQCoarseSignal->Sumw2();
198 fQBackground->Sumw2();
199 fQSecondSignal->Sumw2();
200 fQSecondBackground->Sumw2();
202 /***********************************************************/
204 void AliGenHBTosl::Generate()
207 Info("Generate","Attempts to generate %d particles.",fNpart);
208 if (fStackBuffer == 0x0) fStackBuffer = new TList();
209 //Here is initialization level
210 if (fSignalShapeCreated == kFALSE)
212 TH3D *hs = 0x0, *hb = 0x0;
215 file = TFile::Open("QTSignal.root");
218 hs = (TH3D*)file->Get("fQSignal1");
219 if (hs) hs->SetDirectory(0x0);
223 file = TFile::Open("QTBackground.root");
226 hb = (TH3D*)file->Get("fQBackground1");
227 if (hb) hb->SetDirectory(0x0);
233 Info("Generate","**********************************");
234 Info("Generate","Found starting histograms in files");
235 Info("Generate","**********************************");
243 TH3D *cs = 0x0, *cb = 0x0;
244 file = TFile::Open("QTCoarseBackground.root");
247 cb = (TH3D*)file->Get("fQCoarseBackground");
248 if (cb) cb->SetDirectory(0x0);
252 file = TFile::Open("QTCoarseSignal.root");
255 cs = (TH3D*)file->Get("fQCoarseSignal");
256 if (cs) cs->SetDirectory(0x0);
263 Info("Generate","Got Coarse signal and bkg from files");
264 delete fQCoarseBackground;
265 delete fQCoarseSignal;
267 fQCoarseBackground = cb;
273 Info("Generate","Got Coarse bkg from file");
274 delete fQCoarseBackground;
275 fQCoarseBackground = cb;
279 FillCoarse(); //create coarse background - just to know the spectrum
281 FillCoarseSignal();//create first coarse signal by brutal multplication coarse background and required function shape
284 StartSignal(); //Initilizes the stack that is used for generation
286 fSignalShapeCreated = kTRUE;
289 AliStack* stack = RotateStack();
291 AliStack* genstack = fGenerator->GetStack();
294 genstack = new AliStack(fNpart);
295 fGenerator->SetStack(genstack);
302 fGenerator->Generate();
303 Int_t j = 0, ntr = 0;
304 if ( genstack->GetNtrack() < fNpart/2)
306 Warning("Generate","************************************************************");
307 Warning("Generate","Generator generated (%d) less particles then expected (%d).",
308 stack->GetNtrack(),fNpart/2);
309 Warning("Generate","************************************************************");
312 TH3D* work = new TH3D("work","work",fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange);
315 Double_t*** chiarray = new Double_t** [fQNBins+1];
316 Double_t*** sigarray = new Double_t** [fQNBins+1];
318 for (Int_t i = 1; i<=fQNBins; i++)
320 chiarray[i] = new Double_t* [fQNBins+1];
321 sigarray[i] = new Double_t* [fQNBins+1];
323 for (Int_t k = 1; k<=fQNBins; k++)
325 chiarray[i][k] = new Double_t [fQNBins+1];
326 sigarray[i][k] = new Double_t [fQNBins+1];
331 Double_t scale = Scale(fQSignal,fQBackground);
332 work->Divide(fQSignal,fQBackground,scale);
334 Double_t binwdh = work->GetBinWidth(1)/2.;
336 for (Int_t k = 1; k<=fQNBins; k++)
338 Double_t z = work->GetZaxis()->GetBinCenter(k);
339 for (Int_t j = 1; j<=fQNBins; j++)
341 Double_t y = work->GetYaxis()->GetBinCenter(j);
342 for (Int_t i = 1; i<=fQNBins; i++)
344 sigarray[i][j][k] = fQSignal->GetBinContent(i,j,k);//store current value of signal histogram
345 Double_t x = work->GetXaxis()->GetBinCenter(i);//get center value of a bin (qinv)
346 Double_t v = GetQOutQSideQLongCorrTheorValue(x,y,z);//get expected value of CF in that qinv
347 Double_t diff = v - work->GetBinContent(i,j,k);//store difference betweeon current value, and desired value
348 chiarray[i][j][k] = diff; // no-x x is a weight to get good distribution
354 Int_t middlebin = fQNBins/2;
355 for (Int_t k = middlebin-5; k < middlebin+5; k++)
357 printf("% 6.5f ",work->GetBinContent(1,1,k));
361 for (Int_t k = middlebin-5; k < middlebin+5; k++)
363 printf("% 6.5f ",chiarray[1][1][k]);
367 TParticle particle(fPID,0,-1,-1,-1,-1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
368 TParticle* second = &particle;
370 Bool_t shortloop = kTRUE;
371 Int_t sc = 0;//security check against infinite loop
373 while ( (ntr+1) < fNpart)
395 loopmax = fQNBins/2+fQNBins/4;
396 loopmin = fQNBins/2-fQNBins/4;
400 for (Int_t k = loopmin; k <=loopmax; k++ )
402 qlong = work->GetZaxis()->GetBinCenter(k);
403 for (Int_t j = loopmin; j<=loopmax; j++)
405 qside = work->GetYaxis()->GetBinCenter(j);
406 for (Int_t i = loopmin; i<=loopmax; i++)
408 qout = work->GetXaxis()->GetBinCenter(i);
409 if (chiarray[xmax][ymax][zmax] < chiarray[i][j][k])
416 // Double_t qdist = TMath::Sqrt(qout*qout + qside*qside + qlong*qlong);
418 // Double_t fact = chiarray[i][j][k];//chiarray is chi2
419 // if (fact > work->GetBinError(i,j,k))//if differece between what we want and
420 // { //what we have is bigger than stat. error
421 // xmax = i; //we force to fill that bin
429 qlong = work->GetZaxis()->GetBinCenter(zmax);
430 qside = work->GetYaxis()->GetBinCenter(ymax);
431 qout = work->GetXaxis()->GetBinCenter(xmax);
433 Info("Generate","Fill bin (%d,%d,%d)",xmax,ymax,zmax);
435 qout = gRandom->Uniform(qout-binwdh,qout+binwdh);
436 qside = gRandom->Uniform(qside-binwdh,qside+binwdh);
437 qlong = gRandom->Uniform(qlong-binwdh,qlong+binwdh);
439 TParticle* first = 0;
440 while (j < genstack->GetNtrack())
442 TParticle* tmpp = genstack->Particle(j++);
443 if (tmpp->GetPdgCode() == fPID)
445 if (CheckParticle(tmpp,0x0,stack) == kFALSE)
455 if ( fDebug > 2 ) Info("StartSignal","No more particles of that type");
459 //Here put the check if this particle do not fall into signal region with other partticle
461 Int_t retval = GetThreeD(first,second,qout,qside,qlong);
464 //Info("StartSignal","Can not find momenta for this OSL and particle");
467 //in case this particle is falling into signal area with another
468 //particle we take a another pair
469 //it can intruduce artificial correlations
470 Bool_t checkresult = CheckParticle(second,first,stack);
471 if ( checkresult && (sc < 10) )
478 //Put on output stack
480 SetTrack(second,ntr);
482 //Put on internal stack
484 SetTrack(first,etmp,stack);
485 SetTrack(second,etmp,stack);
487 Double_t y = GetQOutQSideQLongCorrTheorValue(qout,qside,qlong);
489 sigarray[xmax][ymax][zmax] ++;
490 chiarray[xmax][ymax][zmax] = scale*sigarray[xmax][ymax][zmax]/fQBackground->GetBinContent(xmax,ymax,zmax);
491 chiarray[xmax][ymax][zmax] = (y - chiarray[xmax][ymax][zmax]);
495 Mix(fStackBuffer,fQBackground,fQSecondSignal); //upgrate background
496 Mix(stack,fQSignal,fQSecondBackground); //upgrate signal
498 for (Int_t i = 1; i<=fQNBins; i++)
500 for (Int_t k = 1; k<=fQNBins; k++)
502 delete [] chiarray[i][k];
503 delete [] sigarray[i][k];
505 delete [] chiarray[i];
506 delete [] sigarray[i];
511 /***********************************************************/
513 void AliGenHBTosl::GetOneD(TParticle* first, TParticle* second,Double_t qinv)
515 //deprecated method that caclulates momenta of the second particle
516 // out of qinv and the first particle
517 //first particle is rotated that only X is non-zero
520 Double_t m = first->GetMass();
521 Double_t msqrd = m*m;
522 Double_t fourmassSquered = 4.*msqrd;
524 //Condition that R must fullfill to be possible to have qinv less smaller then randomized
525 // Double_t rRange = qinv*TMath::Sqrt(qinv*qinv + fourmassSquered)/fourmassSquered;
526 // Double_t r = gRandom->Uniform(rRange);
528 Double_t r = gRandom->Uniform(qinv);
529 Double_t phi = gRandom->Uniform(TMath::TwoPi());
531 Double_t firstPx = first->P();//first particle is rotated that only X is non-zero thus P==Px
532 Double_t px = 2.*msqrd*firstPx + firstPx*qinv*qinv;
533 Double_t temp = qinv*qinv*qinv*qinv + fourmassSquered * (qinv*qinv - r*r );
536 Error("GetOneD","temp is less then 0: %f",temp);
539 temp = temp*(msqrd+firstPx*firstPx);
541 px = (px - TMath::Sqrt(temp))/(2.*msqrd);
543 Double_t py = r*TMath::Sin(phi);
544 Double_t pz = r*TMath::Cos(phi);
546 TVector3 firstpvector(first->Px(),first->Py(),first->Pz());
547 TVector3 vector(px,py,pz);
548 Rotate(firstpvector,vector);
550 Double_t e = TMath::Sqrt(msqrd + vector.X()*vector.X() + vector.Y()*vector.Y() + vector.Z()*vector.Z());
551 second->SetMomentum(vector.X(),vector.Y(),vector.Z(),e);
552 // 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);
553 // TParticle(pdg, is, parent, -1, kFirstDaughter, kLastDaughter,
554 // px, py, pz, e, vx, vy, vz, tof);
556 if (GetDebug()) Info("GetOneD","Randomized qinv = %f, obtained = %f",qinv,GetQInv(first,second));
559 /***********************************************************/
561 Int_t AliGenHBTosl::GetThreeD(TParticle* first,TParticle* second, Double_t qout, Double_t qside, Double_t qlong)
563 //deprecated method that caclulates momenta of the second particle
564 //out of qout qside and qlong and the first particle
565 Double_t m = first->GetMass();
568 Double_t px = first->P();//first particle is rotated that only X is non-zero thus P==Px
569 Double_t px2 = px*px;
572 Double_t qout2 = qout*qout;
573 Double_t qside2 = qside*qside;
574 Double_t qlong2 = qlong*qlong;
577 Double_t util1 = 4.*px2 - qside2;//4*P1x^2 - Y^2
580 Info("GetThreeD","4.*px2* - qside2 is negative px: %f, qside: %f",px,qside);
583 Double_t util2 = TMath::Sqrt(px2*qout2*util1);
586 Double_t p2x,p2y,p2z;
588 // if ( (qside >= 0) && (qout >= 0) && (qlong >= 0))
592 Double_t tmp = px*(2.*px2 - qside2);
597 tmp = qout - TMath::Sqrt(util1);
598 p2y = - (tmp*qside)/(2.*px);
601 tmp = 4.*m2 + 2.*qout2+qlong2;
603 tmp -= 2.*util2;//!!!
607 Double_t m2px2 = m2+px2;
608 Double_t tmp2 = m2px2*tmp;
610 tmp = 4.*(m2px2+qout2) + qlong2;
613 tmp *= 4.*(m2px2) + qlong2;
614 tmp *= qlong2*qlong2;
619 Error("","Argument of sqrt is negative");
623 tmp2 += TMath::Sqrt(tmp);
625 tmp = 8.0*px*m2px2*m2px2;
626 p2z = -TMath::Sqrt(tmp2/tmp);
627 if (qlong < 0) p2z = -p2z;
632 Double_t tmp = px*(2.*px2 - qside2);
637 tmp = qout - TMath::Sqrt(util1);
638 p2y = - (tmp*qside)/(2.*px);
641 tmp = 4.*m2 + 2.*qout2+qlong2;
643 tmp += 2.*util2;//!!!
647 Double_t m2px2 = m2+px2;
648 Double_t tmp2 = m2px2*tmp;
650 tmp = 4.*(m2px2+qout2) + qlong2;
653 tmp *= 4.*(m2px2) + qlong2;
654 tmp *= qlong2*qlong2;
659 Error("","Argument of sqrt is negative");
663 tmp2 += TMath::Sqrt(tmp);
665 tmp = 8.0*px*m2px2*m2px2;
666 p2z = -TMath::Sqrt(tmp2/tmp);
667 if (qlong < 0) p2z = -p2z;
670 // if ( (qside >= 0) && (qout >= 0) && (qlong >= 0)) p2z = -p2z;
672 TVector3 firstpvector(first->Px(),first->Py(),first->Pz());
673 TVector3 vector(p2x,p2y,p2z);
674 Rotate(firstpvector,vector);
676 Double_t e = TMath::Sqrt(m2 + vector.X()*vector.X() + vector.Y()*vector.Y() + vector.Z()*vector.Z());
677 second->SetMomentum(vector.X(),vector.Y(),vector.Z(),e);
680 if ( GetDebug() > 3 )
682 e=TMath::Sqrt(m2+px*px);
683 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);
685 e = TMath::Sqrt(m2 + p2x*p2x + p2y*p2y + p2z*p2z);
686 TParticle* s = new TParticle(first->GetPdgCode(),0,-1,-1,-1,-1, p2x, p2y, p2z, e, 0.0, 0.0, 0.0, 0.0);
689 GetQOutQSideQLong(f,s,qo, qs, ql);
691 Info("GetThreeD","TEST");
694 Info("GetThreeD","Required %f %f %f",qout,qside,qlong);
695 Info("GetThreeD","Got %f %f %f",qo,qs,ql);
699 Info("GetThreeD","!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
704 /***********************************************************/
706 void AliGenHBTosl::StartSignal()
708 //Starts the signal histograms
713 TParticle particle(fPID,0,-1,-1,-1,-1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
714 TParticle* second = &particle;
716 TIter next(fStackBuffer);
717 while(( stack=(AliStack*)next() ))
722 AliStack* genstack = fGenerator->GetStack();
725 genstack = new AliStack(fNpart);
726 fGenerator->SetStack(genstack);
733 const Double_t ndf = fQNBins*fQNBins*fQNBins;
735 TH3D* work = new TH3D("work","work",fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange);
737 work->SetDirectory(0x0);
740 Double_t binwdh = work->GetBinWidth(1)/2.;
742 Double_t*** chiarray = new Double_t** [fQNBins+1];
743 Double_t*** sigarray = new Double_t** [fQNBins+1];
745 for (Int_t i = 1; i<=fQNBins; i++)
747 chiarray[i] = new Double_t* [fQNBins+1];
748 sigarray[i] = new Double_t* [fQNBins+1];
750 for (Int_t k = 1; k<=fQNBins; k++)
752 chiarray[i][k] = new Double_t [fQNBins+1];
753 sigarray[i][k] = new Double_t [fQNBins+1];
758 Float_t chisqrchange = fMaxChiSquereChange + 1.;
759 Float_t chisqrPerDF = fMaxChiSquerePerNDF;
760 Float_t chisqrold = 0.0;
763 Int_t niterations = 1;
764 Int_t rotaxisorder = 1;//defines order of looping over 3D histo (X,Y,Z or Y,Z,X or Z,X,Y)
767 Bool_t shortloop = kTRUE;
768 TCanvas* c1 = new TCanvas();
773 Info("StartSignal","\n\n\n\nSecond Pass\n\n\n\n");
775 while ( ( (chisqrPerDF > fMaxChiSquereChange) || flag) && (niterations++ < fMaxIterations) )
778 printf("StartSignal\n");
779 printf(" Row 1 Theory, 2 current value, 3 Chi2 \n");
781 Double_t chisqrnew = 0.0;
784 Double_t scale = Scale(fQSignal,fQBackground);
785 work->Divide(fQSignal,fQBackground,scale);
787 if ( (counter%100) == 0)
791 sprintf(buff,"QTWorkPass2.%3d.root",counter);
792 TFile* file = TFile::Open(buff,"update");
794 work->SetDirectory(0x0);
798 sprintf(buff,"QTBackgroundPass2.%3d.root",counter);
799 file = TFile::Open(buff,"update");
800 fQBackground->Write();
801 fQBackground->SetDirectory(0x0);
805 sprintf(buff,"QTSignalPass2.%3d.root",counter);
806 file = TFile::Open(buff,"update");
808 fQSignal->SetDirectory(0x0);
814 Int_t novertresh = 0;
815 for (Int_t k = 1; k<=fQNBins; k++)
817 Double_t z = work->GetZaxis()->GetBinCenter(k);
818 for (Int_t j = 1; j<=fQNBins; j++)
820 Double_t y = work->GetYaxis()->GetBinCenter(j);
821 for (Int_t i = 1; i<=fQNBins; i++)
823 Double_t x = work->GetXaxis()->GetBinCenter(i);//get center value of a bin (qout)
824 sigarray[i][j][k] = fQSignal->GetBinContent(i,j,k);//store current value of signal histogram
825 Double_t v = GetQOutQSideQLongCorrTheorValue(x,y,z);//get expected value of CF in that qinv
826 Double_t diff = v - work->GetBinContent(i,j,k);//store difference betweeon current value, and desired value
827 chiarray[i][j][k] = diff; // no-x x is a weight to get good distribution
828 Double_t be = work->GetBinError(i,j,k);
829 chisqrnew += diff*diff/(be*be);//add up chisq
831 //even if algorithm is stable (chi sqr change less then threshold)
832 //and any bin differs more then 5% from expected value we continue
833 Double_t fact = diff;
834 if (TMath::Abs(fact) > 0.1)
846 for (Int_t k = 1; k < 11; k++)
848 Double_t tx = work->GetXaxis()->GetBinCenter(1);
849 Double_t ty = work->GetYaxis()->GetBinCenter(1);
850 Double_t tz = work->GetZaxis()->GetBinCenter(k);
851 printf("% 6.5f ",GetQOutQSideQLongCorrTheorValue(tx,ty,tz));
855 for (Int_t k = 1; k < 11; k++)
857 printf("% 6.5f ",work->GetBinContent(1,1,k));
861 for (Int_t k = 1; k < 11; k++)
863 printf("% 6.5f ",chiarray[1][1][k]);
867 chisqrchange = TMath::Abs(chisqrnew - chisqrold)/chisqrnew;
868 chisqrold = chisqrnew;
870 chisqrPerDF = chisqrnew/ndf;
872 Info("StartSignal","Iteration %d Chi-sq change %f%%",niterations,chisqrchange*100.0);
873 Info("StartSignal","ChiSq = %f, NDF = %f, ChiSq/NDF = %f",chisqrnew, ndf, chisqrPerDF );
874 Info("StartSignal","novertresh = %d",novertresh);
877 stack = RotateStack();
879 fGenerator->Generate();
880 Int_t ninputparticle = 0, ntr = 0;
881 if ( genstack->GetNtrack() < fNpart/2)
883 Warning("StartSignal","**********************************");
884 Warning("StartSignal","Generator generated (%d) less particles then expected (%d).",
885 genstack->GetNtrack(),fNpart/2);
886 Warning("StartSignal","**********************************");
889 Int_t sc = 0; //security check against infinite loop
890 while ( (ntr+1) < fNpart)//ntr is number of track generated up to now
905 switch (rotaxisorder)
924 if (rotaxisorder > 3) rotaxisorder = 1;
938 // Bool_t force = kFALSE;
939 for ( k = 1; k <=nrange;k++ )
941 for ( j = 1; j<=nrange; j++)
943 for ( i = 1; i<=nrange; i++)
945 if ( (chiarray[*cx][*cy][*cz]) > (chiarray[xmax][ymax][zmax]) )
952 // Double_t fact = chiarray[*cx][*cy][*cz];//chiarray is chi2*qinv
953 // if (fact > work->GetBinError(*cx,*cy,*cz))//if differece between what we want and
954 // { //what we have is bigger than stat. error
955 // //we force to fill that bin
956 // qout = work->GetXaxis()->GetBinCenter(*cx);
957 // qside = work->GetYaxis()->GetBinCenter(*cy);
958 // qlong = work->GetZaxis()->GetBinCenter(*cz);
960 // 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",
961 // *cx,*cy,*cz,i,j,k,fact,qout,qside,qlong,
962 // (Int_t)sigarray[*cx][*cy][*cz],(Int_t)fQBackground->GetBinContent(*cx,*cy,*cz),work->GetBinError(*cx,*cy,*cz));
974 qout = work->GetXaxis()->GetBinCenter(xmax);
975 qside = work->GetYaxis()->GetBinCenter(ymax);
976 qlong = work->GetZaxis()->GetBinCenter(zmax);
978 // Info("StartSignal"," bin: (%d,%d,%d) chiarray: %f \nq(o,s,l): (%f,%f,%f) signal: %d background: %d binerror: %f",
979 // xmax,ymax,zmax,chiarray[xmax][ymax][zmax],qout,qside,qlong,
980 // (Int_t)sigarray[xmax][ymax][zmax],
981 // (Int_t)fQBackground->GetBinContent(xmax,ymax,zmax),
982 // work->GetBinError(xmax,ymax,zmax));
984 qout = gRandom->Uniform(qout-binwdh,qout+binwdh);
985 qside = gRandom->Uniform(qside-binwdh,qside+binwdh);
986 qlong = gRandom->Uniform(qlong-binwdh,qlong+binwdh);
988 TParticle* first = 0;
989 while (ninputparticle < genstack->GetNtrack())
991 TParticle* tmpp = genstack->Particle(ninputparticle++);
992 if (tmpp->GetPdgCode() == fPID)
994 if (CheckParticle(tmpp,0x0,stack) == kFALSE)
1004 if ( fDebug > 2 ) Info("StartSignal","No more particles of that type");
1008 Int_t retval = GetThreeD(first,second,qout,qside,qlong);
1011 Info("StartSignal","Can not find momenta for this OSL and particle OSL = %f %f %f",qout,qside,qlong);
1017 //in case this particle is falling into signal area with another
1018 //particle we take a another pair
1019 //it can intruduce artificial correlations
1020 Bool_t checkresult = CheckParticle(second,first,stack);
1021 if ( checkresult && (sc < 10) )
1028 //Put on output stack
1029 SetTrack(first,ntr,stack);
1030 SetTrack(second,ntr,stack);
1032 Double_t y = GetQOutQSideQLongCorrTheorValue(qout,qside,qlong);
1034 sigarray[xmax][ymax][zmax] ++;
1035 chiarray[xmax][ymax][zmax] = scale*sigarray[xmax][ymax][zmax]/fQBackground->GetBinContent(xmax,ymax,zmax);
1036 chiarray[xmax][ymax][zmax] = (y - chiarray[xmax][ymax][zmax]);
1039 Info("StartSignal","Mixing background...");
1040 Mix(fStackBuffer,fQBackground,fQSecondBackground); //upgrate background
1041 Info("StartSignal","Mixing signal...");
1042 Mix(stack,fQSignal,fQSecondSignal); //upgrate background
1044 if ( (chisqrPerDF < 2.0) && (fSwapped == kFALSE) )
1046 SwapGeneratingHistograms();
1050 TFile* filef = TFile::Open("QTBackground.root","recreate");
1051 fQBackground->Write();
1052 fQBackground->SetDirectory(0x0);
1056 filef = TFile::Open("QTSignal.root","recreate");
1058 fQSignal->SetDirectory(0x0);
1066 for (Int_t i = 1; i<=fQNBins; i++)
1068 for (Int_t k = 1; k<=fQNBins; k++)
1070 delete [] chiarray[i][k];
1071 delete [] sigarray[i][k];
1073 delete [] chiarray[i];
1074 delete [] sigarray[i];
1080 /***********************************************************/
1082 void AliGenHBTosl::StartSignalPass1()
1084 //This method makes first part of the initialization of working histograms
1085 //It randomizes qout, qside and qlong from the coarse signal histogram
1087 Bool_t flag = kTRUE;
1088 TParticle particle(fPID,0,-1,-1,-1,-1,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
1089 TParticle* second = &particle;
1094 Info("StartSignalPass1","\n\nFirst Pass\n\n");
1098 Info("StartSignalPass1","NextEvent");
1099 AliStack* stack = RotateStack();
1100 AliStack* genstack = fGenerator->GetStack();
1102 fGenerator->Generate();
1103 Int_t j = 0, ntr = 0;
1104 if ( genstack->GetNtrack() < fNpart/2)
1106 Warning("StartSignalPass1","**********************************");
1107 Warning("StartSignalPass1","Generator generated (%d) less particles then expected (%d).",
1108 genstack->GetNtrack(),fNpart/2);
1109 Warning("StartSignalPass1","**********************************");
1112 Int_t sc = 0;//security check against infinite loop
1113 while ((ntr+1)<fNpart)
1116 // Info("StartSignal","Number of track on output stack: = %d", ntr);
1117 // Info("StartSignal","Number of track on input stack: = %d\n", j);
1119 TParticle* first = 0;
1120 while (j < genstack->GetNtrack())
1122 TParticle* tmpp = genstack->Particle(j++);
1123 if (tmpp->GetPdgCode() == fPID)
1125 if (CheckParticle(tmpp,0x0,stack) == kFALSE)
1132 Info("StartSignalPass1","Particle did not pass the safety check 1");
1140 if ( fDebug > 2 ) Info("StartSignalPass1","No more particles of that type");
1145 SetTrack(first,ntr,stack);
1147 fQCoarseSignal->GetRandom3(qout,qside,qlong);
1149 Int_t retval = GetThreeD(first,second,qout,qside,qlong);
1152 //Info("StartSignal","Can not find momenta for this OSL and particle");
1155 //in case this particle is falling into signal area with another
1156 //particle we take a another pair
1157 //it can intruduce artificial correlations
1158 Bool_t checkresult = CheckParticle(second,first,stack);
1159 if ( checkresult && (sc < 10) )
1162 Info("StartSignalPass1","Particle did not pass the safety check 2");
1169 SetTrack(second,ntr,stack);
1172 Mix(stack,fQSignal,fQSecondSignal);
1173 Mix(fStackBuffer,fQBackground,fQSecondBackground);
1177 for (Int_t k = 1; k<=fQNBins; k++)
1179 for (Int_t j = 1; j<=fQNBins; j++)
1181 for (Int_t i = 1; i<=fQNBins; i++)
1183 if ( (fQBackground->GetBinContent(i,j,k) < fMinFill) )
1185 //(fQSignal->GetBinContent(i,j,k) < fMinFill) ||
1186 Info("StartSignalPass1","bin (%d,%d,%d): signal=%f background=%f",i,j,k,
1187 fQSignal->GetBinContent(i,j,k),fQBackground->GetBinContent(i,j,k));
1188 flag = kTRUE;//continue while
1189 break;//breakes for not while
1192 if (flag == kTRUE) break;
1194 if (flag == kTRUE) break;
1201 /***********************************************************/
1203 void AliGenHBTosl::FillCoarseSignal()
1205 //Makes coarse signal by multiplying the coarse background and required function
1206 Info("FillCoarseSignal","START");
1207 for (Int_t k = 1; k <=fQNBins ;k++ )
1209 Double_t z = fQCoarseBackground->GetZaxis()->GetBinCenter(k);
1210 for (Int_t j = 1; j <=fQNBins; j++)
1212 Double_t y = fQCoarseBackground->GetYaxis()->GetBinCenter(j);
1213 for (Int_t i = 1; i <=fQNBins; i++)
1215 Double_t x = fQCoarseBackground->GetXaxis()->GetBinCenter(i);
1216 Double_t v = GetQOutQSideQLongCorrTheorValue(x,y,z);
1217 Info("FillCoarseSignal","Bin (%d,%d,%d): osl(%f,%f,%f)=%f",i,j,k,x,y,z,v);
1218 fQCoarseSignal->SetBinContent(i,j,k,v*fQCoarseBackground->GetBinContent(i,j,k));
1226 Info("FillCoarseSignal","DONE");
1228 /***********************************************************/
1230 void AliGenHBTosl::FillCoarse()
1232 //creates the statistical background histogram on the base of input from
1234 Info("FillCoarse","START");
1240 TH3D tmph("tmph","tmph",2,0,1,2,0,1,2,0,1);
1245 // if (niter > 20) break;
1247 cout<<niter++<<" bincont "<<fQCoarseBackground->GetBinContent(1,1,1)
1248 <<" "<<fQCoarseBackground->GetBinContent(1,1,2)
1249 <<" "<<fQCoarseBackground->GetBinContent(1,1,3)
1250 <<" "<<fQCoarseBackground->GetBinContent(1,1,4)
1251 <<" "<<fQCoarseBackground->GetBinContent(1,1,5)
1255 stack = RotateStack();
1256 fGenerator->SetStack(stack);
1258 fGenerator->Generate();
1260 Mix(fStackBuffer,fQCoarseBackground,&tmph);
1264 Info("FillCoarse","fMinFill = %d",fMinFill);
1265 for (Int_t k = 1; k<=fQNBins; k++)
1267 for (Int_t j = 1; j<=fQNBins; j++)
1269 for (Int_t i = 1; i<=fQNBins; i++)
1271 if ( fQCoarseBackground->GetBinContent(i,j,k) < fMinFill )
1274 Info("FillCoarse","bin (%d,%d,%d)=%f",i,j,k,fQCoarseBackground->GetBinContent(i,j,k));
1286 fGenerator->SetStack(0x0);
1287 Info("FillCoarse","DONE");
1290 /***********************************************************/
1292 void AliGenHBTosl::Mix(TList* eventbuffer,TH3D* denominator,TH3D* denominator2)
1294 //Fills denominators
1295 //Mixes events stored in the eventbuffer and fills the background histograms
1296 static TStopwatch stoper;
1298 if (eventbuffer == 0x0)
1300 Error("Mix","Buffer List is null.");
1304 if (denominator == 0x0)
1306 Error("Mix","Denominator histogram is null.");
1310 if (denominator2 == 0x0)
1312 Error("Mix","Denominator2 histogram is null.");
1316 Info("Mix","%s",denominator->GetName());
1319 TIter next(eventbuffer);
1320 AliStack* firstevent;
1321 AliStack* secondevent = 0x0;
1323 while(( firstevent=(AliStack*)next() ))
1325 if (secondevent == 0x0)
1327 secondevent = firstevent;
1330 // Info("Mix","Mixing %#x with %#x",firstevent,secondevent);
1331 for(Int_t j = 0; j < firstevent->GetNtrack(); j++ )
1333 TParticle* firstpart = firstevent->Particle(j);
1335 Float_t phi = firstpart->Phi();
1336 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1338 // Info("Mix","Mixing %d phi %f min %f max %f",j,phi,fSamplePhiMin,fSamplePhiMax);
1340 for(Int_t i = 0; i < secondevent->GetNtrack(); i++ )
1342 TParticle* secondpart = secondevent->Particle(i);
1343 phi = secondpart->Phi();
1344 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1349 GetQOutQSideQLong(firstpart,secondpart,qout,qside,qlong);
1350 denominator->Fill(qout,qside,qlong);
1351 denominator2->Fill(qout,qside,qlong);
1355 secondevent = firstevent;
1361 /***********************************************************/
1363 void AliGenHBTosl::Mix(AliStack* stack, TH3D* numerator, TH3D* numerator2)
1365 //fils numerator with particles from stack
1366 static TStopwatch stoper;
1369 Error("Mix","Stack is null.");
1373 if ( (numerator == 0x0) || (numerator2 == 0x0) )
1375 Error("Mix","Numerator histogram is null.");
1379 Info("Mix","%s",numerator->GetName());
1382 for(Int_t j = 0; j < stack->GetNtrack(); j++ )
1384 TParticle* firstpart = stack->Particle(j);
1385 Float_t phi = firstpart->Phi();
1386 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1388 for(Int_t i = j+1; i < stack->GetNtrack(); i++ )
1390 TParticle* secondpart = stack->Particle(i);
1391 phi = secondpart->Phi();
1392 if ( (phi < fSamplePhiMin) || ( phi > fSamplePhiMax)) continue;
1396 GetQOutQSideQLong(firstpart,secondpart,qout,qside,qlong);
1397 numerator->Fill(qout,qside,qlong);
1398 numerator2->Fill(qout,qside,qlong);
1405 /***********************************************************/
1407 Double_t AliGenHBTosl::GetQInv(TParticle* f, TParticle* s)
1410 // cout<<f->Px()<<" "<<s->Px()<<endl;
1411 Double_t pxdiff = f->Px() - s->Px();
1412 Double_t pydiff = f->Py() - s->Py();
1413 Double_t pzdiff = f->Pz() - s->Pz();
1414 Double_t ediff = f->Energy() - s->Energy();
1416 Double_t qinvl = ediff*ediff - ( pxdiff*pxdiff + pydiff*pydiff + pzdiff*pzdiff );
1417 Double_t qinv = TMath::Sqrt(TMath::Abs(qinvl));
1420 /***********************************************************/
1422 void AliGenHBTosl::GetQOutQSideQLong(TParticle* f, TParticle* s,Double_t& out, Double_t& side, Double_t& lon)
1424 //returns qout,qside and qlong of the pair of particles
1425 out = side = lon = 10e5;
1427 Double_t pxsum = f->Px() + s->Px();
1428 Double_t pysum = f->Py() + s->Py();
1429 Double_t pzsum = f->Pz() + s->Pz();
1430 Double_t esum = f->Energy() + s->Energy();
1431 Double_t pxdiff = f->Px() - s->Px();
1432 Double_t pydiff = f->Py() - s->Py();
1433 Double_t pzdiff = f->Pz() - s->Pz();
1434 Double_t ediff = f->Energy() - s->Energy();
1435 Double_t kt = 0.5*TMath::Hypot(pxsum,pysum);
1437 Double_t k2 = pxsum*pxdiff+pysum*pydiff;
1448 side = (f->Px()*s->Py()-s->Px()*f->Py())/kt;
1451 Double_t beta = pzsum/esum;
1452 Double_t gamma = 1.0/TMath::Sqrt(1.0 - beta*beta);
1454 lon = gamma * ( pzdiff - beta*ediff );
1456 // out = TMath::Abs(out);
1457 // side = TMath::Abs(side);
1458 // lon = TMath::Abs(lon);
1461 /***********************************************************/
1463 Double_t AliGenHBTosl::Scale(TH3D* num, TH3D* den)
1465 //Calculates the factor that should be used to scale
1466 //quatience of num and den to 1 at tail
1468 if (GetDebug()) Info("Scale","Entered Scale()");
1471 Error("Scale","No numerator");
1476 Error("Scale","No denominator");
1480 if(fNBinsToScale < 1)
1483 Error("Scale","Number of bins for scaling is smaller thnan 1");
1485 Int_t fNBinsToScaleX = fNBinsToScale;
1486 Int_t fNBinsToScaleY = fNBinsToScale;
1487 Int_t fNBinsToScaleZ = fNBinsToScale;
1489 Int_t nbinsX = num->GetNbinsX();
1490 if (fNBinsToScaleX > nbinsX)
1492 Error("Scale","Number of X bins for scaling is bigger thnan number of bins in histograms");
1496 Int_t nbinsY = num->GetNbinsX();
1497 if (fNBinsToScaleY > nbinsY)
1499 Error("Scale","Number of Y bins for scaling is bigger thnan number of bins in histograms");
1503 Int_t nbinsZ = num->GetNbinsZ();
1504 if (fNBinsToScaleZ > nbinsZ)
1506 Error("Scale","Number of Z bins for scaling is bigger thnan number of bins in histograms");
1510 if (GetDebug()>0) Info("Scale","No errors detected");
1512 Int_t offsetX = nbinsX - fNBinsToScaleX - 1; //bin that we start loop over bins in axis X
1513 Int_t offsetY = nbinsY - fNBinsToScaleY - 1; //bin that we start loop over bins in axis Y
1514 Int_t offsetZ = nbinsZ - fNBinsToScaleZ - 1; //bin that we start loop over bins in axis Z
1516 Double_t densum = 0.0;
1517 Double_t numsum = 0.0;
1519 for (Int_t k = offsetZ; k<nbinsZ; k++)
1520 for (Int_t j = offsetY; j<nbinsY; j++)
1521 for (Int_t i = offsetX; i<nbinsX; i++)
1523 if ( num->GetBinContent(i,j,k) > 0.0 )
1526 densum += den->GetBinContent(i,j,k);
1527 numsum += num->GetBinContent(i,j,k);
1532 Info("Scale","numsum=%f densum=%f fNBinsToScaleX=%d fNBinsToScaleY=%d fNBinsToScaleZ=%d",
1533 numsum,densum,fNBinsToScaleX,fNBinsToScaleY,fNBinsToScaleZ);
1535 if (numsum == 0) return 0.0;
1536 Double_t ret = densum/numsum;
1538 if(GetDebug() > 0) Info("Scale","returning %f",ret);
1542 /***********************************************************/
1544 void AliGenHBTosl::TestCoarseSignal()
1546 //Tests how works filling from generated histogram shape
1547 TH3D* work = new TH3D("work","work",fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange,fQNBins,-fQRange,fQRange);
1549 // for (Int_t i = 0; i < fQCoarseBackground->GetEntries() ;i++)
1552 // fQCoarseSignal->GetRandom3(x,y,z);
1553 // work->Fill(x,y,z);
1556 TCanvas* c1 = new TCanvas();
1559 c1->SaveAs("QTwork.root");
1560 TFile* file = TFile::Open("QTwork.root","update");
1562 work->SetDirectory(0x0);
1565 fQCoarseSignal->Draw();
1566 c1->SaveAs("QTCoarseSignal.root");
1567 file = TFile::Open("QTCoarseSignal.root","update");
1568 fQCoarseSignal->Write();
1569 fQCoarseSignal->SetDirectory(0x0);
1572 fQCoarseBackground->Draw();
1573 c1->SaveAs("QTCoarseBackground.root");
1574 file = TFile::Open("QTCoarseBackground.root","update");
1575 fQCoarseBackground->Write();
1576 fQCoarseBackground->SetDirectory(0x0);
1579 TH1 *result = (TH1*)fQCoarseBackground->Clone("ratio");
1580 result->SetTitle("ratio");
1581 Float_t normfactor = Scale(work,fQCoarseBackground);
1582 result->Divide(work,fQCoarseBackground,normfactor);//work
1587 c1->SaveAs("QTresult.root");
1588 file = TFile::Open("QTresult.root","update");
1590 result->SetDirectory(0x0);
1596 /***********************************************************/
1598 void AliGenHBTosl::SetTrack(TParticle* p, Int_t& ntr)
1600 //Shortcut to PushTrack(bla,bla,bla,bla.............)
1603 Error("SetTrack(TParticle*,Int_t&)","Particle has zero momentum");
1608 Int_t pdg = p->GetPdgCode();
1609 Double_t px = p->Px();
1610 Double_t py = p->Py();
1611 Double_t pz = p->Pz();
1612 Double_t e = p->Energy();
1613 Double_t vx = p->Vx();
1614 Double_t vy = p->Vy();
1615 Double_t vz = p->Vz();
1616 Double_t tof = p->T();
1619 p->GetPolarisation(pol);
1621 Double_t polx = pol.X();
1622 Double_t poly = pol.Y();
1623 Double_t polz = pol.Z();
1624 TMCProcess mech = AliGenCocktailAfterBurner::IntToMCProcess(p->GetUniqueID());
1625 Float_t weight = p->GetWeight();
1627 AliGenerator::PushTrack(fTrackIt, -1, pdg, px, py, pz, e, vx, vy, vz, tof,polx, poly, polz, mech, ntr, weight);
1629 /***********************************************************/
1631 void AliGenHBTosl::SetTrack(TParticle* p, Int_t& ntr, AliStack* stack)
1633 //Shortcut to SetTrack(bla,bla,bla,bla.............)
1636 Error("SetTrack(TParticle*,Int_t&,AliStack*)","Particle has zero momentum");
1640 Int_t pdg = p->GetPdgCode();
1641 Double_t px = p->Px();
1642 Double_t py = p->Py();
1643 Double_t pz = p->Pz();
1644 Double_t e = p->Energy();
1646 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);
1648 /***********************************************************/
1650 void AliGenHBTosl::Rotate(TVector3& relvector, TVector3& vector)
1652 //This method rotates vector about the angeles that are needed to rotate
1653 //relvector from postion (firstPx,0,0) to its actual positon
1654 //In other words: To make equations easier
1656 static TVector3 first;
1659 first.SetXYZ(relvector.x(),relvector.y(),relvector.z());
1662 Double_t firstPx = TMath::Sqrt( relvector.x()*relvector.x() +
1663 relvector.y()*relvector.y() +
1664 relvector.z()*relvector.z() );
1666 Double_t rotAngleZ = -TMath::ATan2(relvector.y(),relvector.x());//calculating rot angles
1667 relvector.RotateZ(rotAngleZ);
1668 rotAngleZ = -rotAngleZ;
1669 Double_t rotAngleY = -TMath::ATan2(relvector.z(),relvector.x());
1671 vector.RotateY(rotAngleY);
1672 vector.RotateZ(rotAngleZ);
1676 TVector3 test(firstPx,0.0,0.0);
1677 test.RotateY(rotAngleY);
1678 test.RotateZ(rotAngleZ);
1679 ::Info("Rotate","Rotation test: px %f %f",first.x(),test.x());
1680 ::Info("Rotate","Rotation test: py %f %f",first.y(),test.y());
1681 ::Info("Rotate","Rotation test: pz %f %f",first.z(),test.z());
1684 /***********************************************************/
1686 Double_t AliGenHBTosl::Rotate(Double_t x,Double_t y,Double_t z)
1688 //Rotates vector to base where only x - coordinate is no-zero, and returns that
1690 Double_t xylength = TMath::Hypot(x,y);
1691 Double_t sinphi = -y/xylength;
1692 Double_t cosphi = x/xylength;
1694 Double_t xprime = cosphi*x - sinphi*y;
1695 Double_t yprime = sinphi*x + cosphi*y;
1698 Double_t a1 = -TMath::ATan2(v.Y(),v.X());
1700 ::Info("Rotate","Xpr = %f Ypr = %f",xprime,yprime);
1701 ::Info("Rotate","Calc sin = %f, and %f",sinphi,TMath::Sin(a1));
1702 ::Info("Rotate","Calc cos = %f, and %f",cosphi,TMath::Cos(a1));
1705 Double_t xprimezlength = TMath::Hypot(xprime,z);
1707 Double_t sintheta = z/xprimezlength;
1708 Double_t costheta = xprime/xprimezlength;
1711 Double_t xbis = sintheta*z + costheta*(cosphi*x - sinphi*y);
1713 ::Info("Rotate","Calculated rot %f, modulus %f",xbis,TMath::Sqrt(x*x+y*y+z*z));
1716 /***********************************************************/
1718 AliStack* AliGenHBTosl::RotateStack()
1720 //swaps to next stack last goes to first and is reseted
1723 if ( fStackBuffer->GetSize() >= fBufferSize )
1725 stack = (AliStack*)fStackBuffer->Remove(fStackBuffer->Last());
1729 stack = new AliStack(fNpart);
1732 fStackBuffer->AddFirst(stack);
1736 /***********************************************************/
1738 Double_t AliGenHBTosl::GetQInvCorrTheorValue(Double_t qinv) const
1740 //Function (deprecated)
1741 static const Double_t factorsqrd = 0.197*0.197;//squared conversion factor SI<->eV
1743 return 1.0 + 0.5*TMath::Exp(-qinv*qinv*fQRadius*fQRadius/factorsqrd);
1745 /***********************************************************/
1747 Double_t AliGenHBTosl::GetQOutQSideQLongCorrTheorValue(Double_t& out, Double_t& side, Double_t& lon) const
1749 //Theoretical function. Wa want to get correlation of the shape of this function
1750 static const Double_t factorsqrd = 0.197*0.197;//squared conversion factor SI<->eV
1751 return 1.0 + 0.7*TMath::Exp(-fQRadius*fQRadius*(out*out+side*side+lon*lon)/factorsqrd);
1753 /***********************************************************/
1755 Bool_t AliGenHBTosl::CheckParticle(TParticle* p, TParticle* aupair ,AliStack* stack)
1757 //Checks if a given particle is falling into signal region with any other particle
1758 //already existing on stack
1761 if (fSignalRegion <=0) return kFALSE;
1763 for (Int_t i = 0; i < stack->GetNtrack(); i++)
1765 TParticle* part = stack->Particle(i);
1766 if (part == aupair) continue;
1767 Double_t qout = 10e5;
1768 Double_t qside= 10e5;
1769 Double_t qlong= 10e5;
1770 GetQOutQSideQLong(p,part,qout,qside,qlong);
1772 if (TMath::Abs(qout) < fSignalRegion)
1773 if (TMath::Abs(qside) < fSignalRegion)
1774 if (TMath::Abs(qlong) < fSignalRegion)
1779 /***********************************************************/
1781 void AliGenHBTosl::SwapGeneratingHistograms()
1783 //Checks if it is time to swap signal and background histograms
1784 //if yes it swaps them
1785 Int_t threshold = fMinFill;
1786 for (Int_t k = 1; k<=fQNBins; k++)
1788 for (Int_t j = 1; j<=fQNBins; j++)
1790 for (Int_t i = 1; i<=fQNBins; i++)
1792 if ( fQSecondBackground->GetBinContent(i,j,k) < threshold) return;
1799 Info("SwapGeneratingHistograms","*******************************************");
1800 Info("SwapGeneratingHistograms","*******************************************");
1801 Info("SwapGeneratingHistograms","*******************************************");
1802 Info("SwapGeneratingHistograms","**** SWAPPING HISTOGRAMS ****");
1803 Info("SwapGeneratingHistograms","*******************************************");
1804 Info("SwapGeneratingHistograms","*******************************************");
1805 Info("SwapGeneratingHistograms","*******************************************");
1809 fQSignal = fQSecondSignal;
1811 fQSecondSignal->Reset();
1812 fQSecondSignal->SetDirectory(0x0);
1815 fQBackground = fQSecondBackground;
1816 fQSecondBackground = h;
1817 fQSecondBackground->Reset();
1818 fQSecondBackground->SetDirectory(0x0);