]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/JCORRAN/AliJCorrelations.cxx
Install macros and scripts needed for QA
[u/mrichter/AliRoot.git] / PWGCF / Correlations / JCORRAN / AliJCorrelations.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // Comment describing what this class does needed!
17
18 #include "AliJCorrelations.h"
19 #include "AliJDataManager.h"
20
21 #include "AliJCorrelations.h"
22 #include "AliJHistos.h"
23 #include "AliJBaseTrack.h"
24 #include "AliJCard.h"
25 #include "AliJHistos.h"
26 #include "AliJRunTable.h"
27
28
29
30 //==========================================================================
31 // don't count the trigger here ! You'll miss the not associated triggers
32 // but you  will miss them in the main code too, unles you loop over those
33 // fevent with no cgl (set the masMix to 1)
34 //==========================================================================
35 // blah
36
37 AliJCorrelations::AliJCorrelations( AliJCard *cardIn, AliJHistos *histosIn) :
38   fcard(cardIn),
39   fhistos(histosIn),
40   fnReal(0),
41   fnMix(0),
42   fsumTriggerAndAssoc(0),
43   fsamplingMethod(0),    // flat by default
44   fIsHeavyIon(0),
45   fawayPhiGap(0),
46   fmaxEtaRange(0),
47   fRSignalBin(0),
48   frandom(0x0),
49   fptt(0),
50   fpta(0),
51   fTrackPairEfficiency(0),
52   fIsIsolatedTrigger(false),
53   fpttBin(0),
54   fptaBin(0),
55   fPhiTrigger(0),
56   fPhiAssoc(0),
57   fDeltaPhi(0),
58   fDeltaPhiPiPi(0),
59   fDeltaEta(0),
60   fXlong(0),
61   fNearSide(true),
62   fEtaGapBin(0),
63   fPhiGapBinNear(0),
64   fPhiGapBinAway(0),
65   fRGapBinNear(0),
66   fRGapBinAway(0),
67   fCentralityBin(0),
68   fXlongBin(0),
69   fIsLikeSign(false),
70   fGeometricAcceptanceCorrection(1)
71 {
72   // constructor
73   
74   fsumTriggerAndAssoc = int( fcard->Get("sumTriggerAndAssoc") );
75   fmaxEtaRange    = fcard->Get("EtaRange");
76   fRSignalBin = int(fcard->Get("EtaGapSignalBin"));
77   
78   fDPhiUERegion[0]    = fcard->Get("DPhiUERegion",0);
79   fDPhiUERegion[1]    = fcard->Get("DPhiUERegion",1);
80   cout << fmaxEtaRange <<" fDPhiUERegion[0]="<< fDPhiUERegion[0] <<" fDPhiUERegion[1]="<< fDPhiUERegion[1] <<endl;
81   fIsHeavyIon = AliJRunTable::GetInstance().IsHeavyIon();
82
83   // -----------------------------------------------------------------------------------------------
84   // HARD CODED NUMBERS - VIOLATIONS - BREAKS the code when only on bin used in card.input!!!
85   // Who did this? Further more it us unused variable !!!!
86   // Jan
87   //fawayPhiGap = fcard->GetBinBorder(kEtaGapType, 2);
88   // -----------------------------------------------------------------------------------------------
89   
90   for(int iRGap=0; iRGap < fcard->GetNoOfBins(kRGapType); iRGap++)
91     fRGap[iRGap]   = fcard->GetBinBorder( kRGapType, iRGap);
92   
93   //dPhiRange = fhistos->GetDphiRange();
94   frandom = new TRandom3(); //FK// frandom generator for jt flow UE
95   frandom->SetSeed(0); //FK//
96   
97 }
98
99 AliJCorrelations::AliJCorrelations() :
100   fcard(0x0),
101   fhistos(0x0),
102   fnReal(0),
103   fnMix(0),
104   fsumTriggerAndAssoc(0),
105   fsamplingMethod(0),    // flat by default
106   fIsHeavyIon(0),
107   fawayPhiGap(0),
108   fmaxEtaRange(0),
109   fRSignalBin(0),
110   frandom(0x0),
111   fptt(0),
112   fpta(0),
113   fTrackPairEfficiency(0),
114   fIsIsolatedTrigger(false),
115   fpttBin(0),
116   fptaBin(0),
117   fPhiTrigger(0),
118   fPhiAssoc(0),
119   fDeltaPhi(0),
120   fDeltaPhiPiPi(0),
121   fDeltaEta(0),
122   fXlong(0),
123   fNearSide(true),
124   fEtaGapBin(0),
125   fPhiGapBinNear(0),
126   fPhiGapBinAway(0),
127   fRGapBinNear(0),
128   fRGapBinAway(0),
129   fCentralityBin(0),
130   fXlongBin(0),
131   fIsLikeSign(false),
132   fGeometricAcceptanceCorrection(1)
133 {
134   // default constructor
135 }
136
137 AliJCorrelations::AliJCorrelations(const AliJCorrelations& in) :
138   fcard(in.fcard),
139   fhistos(in.fhistos),
140   fnReal(in.fnReal),
141   fnMix(in.fnMix),
142   fsumTriggerAndAssoc(in.fsumTriggerAndAssoc),
143   fsamplingMethod(in.fsamplingMethod),
144   fIsHeavyIon(in.fIsHeavyIon),
145   fawayPhiGap(in.fawayPhiGap),
146   fmaxEtaRange(in.fmaxEtaRange),
147   fRSignalBin(in.fRSignalBin),
148   frandom(in.frandom),
149   fptt(in.fptt),
150   fpta(in.fpta),
151   fTrackPairEfficiency(in.fTrackPairEfficiency),
152   fIsIsolatedTrigger(in.fIsIsolatedTrigger),
153   fpttBin(in.fpttBin),
154   fptaBin(in.fptaBin),
155   fPhiTrigger(in.fPhiTrigger),
156   fPhiAssoc(in.fPhiAssoc),
157   fDeltaPhi(in.fDeltaPhi),
158   fDeltaPhiPiPi(in.fDeltaPhiPiPi),
159   fDeltaEta(in.fDeltaEta),
160   fXlong(in.fXlong),
161   fNearSide(in.fNearSide),
162   fEtaGapBin(in.fEtaGapBin),
163   fPhiGapBinNear(in.fPhiGapBinNear),
164   fPhiGapBinAway(in.fPhiGapBinAway),
165   fRGapBinNear(in.fRGapBinNear),
166   fRGapBinAway(in.fRGapBinAway),
167   fCentralityBin(in.fCentralityBin),
168   fXlongBin(in.fXlongBin),
169   fIsLikeSign(in.fIsLikeSign),
170   fGeometricAcceptanceCorrection(in.fGeometricAcceptanceCorrection)
171 {
172   // The pointers to card and histos are just copied. I think this is safe, since they are not created by
173   // AliJCorrelations and thus should not disappear if the AliJCorrelation managing them is destroyed.
174   
175   fDPhiUERegion[0] = in.fDPhiUERegion[0];
176   fDPhiUERegion[1] = in.fDPhiUERegion[1];
177   
178   for(int iRGap=0; iRGap < fcard->GetNoOfBins(kRGapType); iRGap++){
179     fRGap[iRGap] = in.fRGap[iRGap];
180   }
181   
182   frandom = new TRandom3(); // frandom generator for jt flow UE
183   frandom->SetSeed(0);
184 }
185
186 AliJCorrelations& AliJCorrelations::operator=(const AliJCorrelations& in){
187   // Assingment operator
188   
189   if (&in==this) return *this;
190   
191   fptt = in.fptt;
192   fpta = in.fpta;
193   fTrackPairEfficiency = in.fTrackPairEfficiency;
194   fIsIsolatedTrigger = in.fIsIsolatedTrigger;
195   fpttBin = in.fpttBin;
196   fptaBin = in.fptaBin;
197   fPhiTrigger = in.fPhiTrigger;
198   fPhiAssoc = in.fPhiAssoc;
199   fDeltaPhi = in.fDeltaPhi;
200   fDeltaPhiPiPi = in.fDeltaPhiPiPi;
201   fDeltaEta = in.fDeltaEta;
202   fXlong = in.fXlong;
203   fNearSide = in.fNearSide;
204   fEtaGapBin = in.fEtaGapBin;
205   fPhiGapBinNear = in.fPhiGapBinNear;
206   fPhiGapBinAway = in.fPhiGapBinAway;
207   fRGapBinNear = in.fRGapBinNear;
208   fRGapBinAway = in.fRGapBinAway;
209   fCentralityBin = in.fCentralityBin;
210   fXlongBin = in.fXlongBin;
211   fIsLikeSign = in.fIsLikeSign;
212   fGeometricAcceptanceCorrection = in.fGeometricAcceptanceCorrection;
213   fnReal = in.fnReal;
214   fnMix = in.fnMix;
215   fsumTriggerAndAssoc = in.fsumTriggerAndAssoc;
216   fsamplingMethod = in.fsamplingMethod;
217   fIsHeavyIon = in.fIsHeavyIon;
218   fawayPhiGap = in.fawayPhiGap;
219   fmaxEtaRange = in.fmaxEtaRange;
220   fRSignalBin = in.fRSignalBin;
221   
222   // The pointers to card and histos are just copied. I think this is safe, since they are not created by
223   // AliJCorrelations and thus should not disappear if the AliJCorrelation managing them is destroyed.
224   fcard = in.fcard;
225   fhistos = in.fhistos;
226   
227   fDPhiUERegion[0] = in.fDPhiUERegion[0];
228   fDPhiUERegion[1] = in.fDPhiUERegion[1];
229   
230   for(int iRGap=0; iRGap < fcard->GetNoOfBins(kRGapType); iRGap++){
231     fRGap[iRGap] = in.fRGap[iRGap];
232   }
233   
234   frandom = new TRandom3(); // frandom generator for jt flow UE
235   frandom->SetSeed(0);
236   
237   return *this;
238   // copy constructor
239 }
240
241
242 void AliJCorrelations::FillHisto(corrFillType cFTyp, fillType fTyp, int cBin, int zBin, AliJBaseTrack *ftk1, AliJBaseTrack *ftk2){
243   // histo filler
244   if( cFTyp == kAzimuthFill )
245     FillAzimuthHistos( fTyp, cBin, zBin, ftk1, ftk2);
246   
247 }
248
249 //=============================================================================================
250 void AliJCorrelations::FillAzimuthHistos(fillType fTyp, int CentBin, int ZBin, AliJBaseTrack *ftk1, AliJBaseTrack *ftk2)
251 //=============================================================================================
252 {
253   // histo filler
254   bool twoTracks = false;
255   if(ftk1->GetParticleType()==kJHadron && ftk2->GetParticleType()==kJHadron) twoTracks =true;
256   
257   //double-counting check
258   if(fTyp == kReal && twoTracks && ftk1->GetID()==ftk2->GetID()) return;
259   
260   // Check the signs of the paired particles
261   fIsLikeSign = false;
262   if(ftk1->GetCharge() > 0 && ftk2->GetCharge() > 0) fIsLikeSign = true;
263   if(ftk1->GetCharge() < 0 && ftk2->GetCharge() < 0) fIsLikeSign = true;
264   
265   //----------------------------------------------------------------
266   fptt = ftk1->Pt();
267   fpta = ftk2->Pt();
268   
269   fTrackPairEfficiency = 1./( ftk1->GetTrackEff() * ftk2->GetTrackEff() );
270   
271   fIsIsolatedTrigger =  ftk1->GetIsIsolated()>0  ? true : false; //FK// trigger particle is isolated hadron
272   
273   //phit= ftk1->Phi();                                 //for RP
274   fpttBin       = ftk1->GetTriggBin();
275   fptaBin       = ftk2->GetAssocBin();
276   fPhiTrigger   = ftk1->Phi();
277   fPhiAssoc     = ftk2->Phi();
278   fDeltaPhi     = DeltaPhi(fPhiTrigger, fPhiAssoc);  //radians
279   fDeltaPhiPiPi = atan2(sin(fPhiTrigger-fPhiAssoc), cos(fPhiTrigger-fPhiAssoc));
280   fDeltaEta     = ftk1->Eta() - ftk2->Eta();
281   //double dEtaFar   = ftk1->Eta() + ftk2->Eta();
282   
283   fNearSide     = cos(fPhiTrigger-fPhiAssoc) > 0 ? true : false;
284   
285   fEtaGapBin = fcard->GetBin( kEtaGapType, fabs(fDeltaEta));
286   fPhiGapBinNear = fcard->GetBin( kEtaGapType, fabs(fDeltaPhiPiPi) );
287   fPhiGapBinAway = fcard->GetBin( kEtaGapType, fabs(fDeltaPhi-kJPi) ); //here the angle must be 0-2pi and not (-pi,pi)
288   fRGapBinNear   = fcard->GetBin( kRGapType, fabs(ftk1->DeltaR(*ftk2)));
289   fRGapBinAway   = fcard->GetBin( kRGapType, sqrt(pow(fDeltaPhi-kJPi,2)+fDeltaEta*fDeltaEta) );
290   fCentralityBin = CentBin;
291   
292   TLorentzVector vTrigger = ftk1->GetLorentzVector(), vAssoc = ftk2->GetLorentzVector();    // Lorentz vectors for trigger and associated particles
293   fXlong = vTrigger.Vect().Dot(vAssoc.Vect())/pow(vTrigger.P(),2);
294   fXlongBin = fcard->GetBin(kXeType, TMath::Abs(fXlong));
295   
296   //if( rGapBin != fRGapBinNear ) cout<<"dR vs fRGapBinNear = "<<rGapBin<<"\t"<<fRGapBinNear<<endl;
297   //if( rGapBin != fRGapBinAway ) cout<<"dR vs fRGapBinAway = "<<rGapBin<<"\t"<<fRGapBinAway<<endl;
298   //----------------------------------------------------------------
299   
300   //acceptance correction  triangle  or mixed fevent
301   //  fGeometricAcceptanceCorrection = 1;
302   fGeometricAcceptanceCorrection = ( fsamplingMethod == 0 ) ? GetGeoAccCorrFlat(fDeltaEta) : GetGeoAccCorrIncl(fDeltaEta);
303   
304   
305   if(fpttBin<0 || fptaBin<0 || fEtaGapBin<0 ){
306     cout<<"Error in FillAzimuthHistos: some pT or eta out of bin. pttBin="<<fpttBin<<" pTaBin="<<fptaBin <<" etaGapBin="<< fEtaGapBin << endl;
307     ftk1->Print();
308     ftk2->Print();
309     exit(-1);
310     //return;
311   }
312   
313   if(fDeltaPhi==0) cout <<" fdphi=0; fptt="<<  fptt<<"   fpta="<<fpta<<"  TID="<<ftk1->GetID()<<"  AID="<<ftk2->GetID() <<" tphi="<< fPhiTrigger <<" aphi="<< fPhiAssoc << endl;
314   
315   // ===================================================================
316   // =====================  Fill Histograms  ===========================
317   // ===================================================================
318   
319   bool fill2DBackgroundQualityControlHistograms = false;  // Choose whether to fill the DeltaPhi DeltaEta histograms for jT background
320   
321   //FillPairPtAndCosThetaStarHistograms(fTyp, ftk1, ftk2);  // Fill the pair pT and cos(theta*) histograms TODO: Does not work! Needs debugging
322   FillXeHistograms(fTyp);  // Fill the xE and xLong histograms
323   FillJtHistograms(fTyp, ftk1, ftk2, fill2DBackgroundQualityControlHistograms);  // Fill the jT and pout histograms togerher with some background quality assurance histograms
324   FillDeltaEtaHistograms(fTyp, ZBin);  // Fill all the delta eta histograms
325   FillDeltaPhiHistograms(fTyp);  // Fill the azimuthal correlation functions
326   FillPtaHistograms(fTyp);  // Fill various pTa histograms
327   FillIAAAndMoonHistograms(fTyp, ZBin);  // Fill the I_AA and moon histograms
328   
329 }
330
331
332 void AliJCorrelations::FillPairPtAndCosThetaStarHistograms(fillType fTyp, AliJBaseTrack *ftk1, AliJBaseTrack *ftk2)
333 {
334   // This method fills the pair pT and Cos(thata*) histograms
335   
336   TVector3 v3trigg = ftk1->GetLorentzVector().Vect();
337   TVector3 v3assoc = ftk2->GetLorentzVector().Vect();
338   double pairMass = sqrt(2*v3trigg.Mag()*v3assoc.Mag()*(1-cos(v3trigg.Angle(v3assoc))));
339   int imass = fcard->GetBin(kMassType, pairMass);
340   TVector3 v3pairPt = v3trigg + v3assoc;
341   double pairPt = v3pairPt.Perp();
342   double wPairPt = pairPt>0 ? 1/pairPt : 0;
343   
344   //================================
345   // Pair pT and cos(Theta^star) ===  // TODO: Needs debugging, the code below does not work!
346   //================================
347   
348   if(!fNearSide) {
349     fhistos->fhPairPt[fTyp][fpttBin][fptaBin]->Fill( pairPt, fTrackPairEfficiency);
350     double pairDphi = v3pairPt.DeltaPhi(v3trigg);
351     if(pairDphi<-kJPi/3.0) pairDphi += kJTwoPi;
352     fhistos->fhPairPtDphi[fTyp][fpttBin][fptaBin]->Fill( pairDphi/kJPi );
353   }
354   
355   if ( fTyp == kReal ) {
356     //cout<<" fptt="<< fptt <<" fpta="<< fpta <<" fdphi="<< fDeltaPhi <<" pairPt="<< pairPt << endl;
357     
358     int ipairPt = fcard->IsLessThanUpperPairPtCut(pairPt);
359     //cout<<"ppt="<<pairPt<<" mass="<<pairMass<<" ip="<<ipairPt<<" im="<<imass<<endl;
360     if(imass>=0) {
361       fhistos->fhPairPtMass[imass]->Fill( pairPt, fTrackPairEfficiency*wPairPt );
362       fhistos->fhPairDPhi[imass]->Fill( fDeltaPhi/kJPi, fTrackPairEfficiency );
363       fhistos->fhPairDpT[imass]->Fill( fptt-fpta, fTrackPairEfficiency );
364     }
365     if(imass>=0 && ipairPt>=0 ){
366       double cmsRap = (ftk1->Eta()+ftk2->Eta())/2.;
367       double cosThetaStar = fabs(cos(2*atan(exp(-ftk1->Eta()+cmsRap))));
368       fhistos->fhCosThetaStar[fTyp][ipairPt][imass]->Fill( cosThetaStar, fTrackPairEfficiency );
369       
370       //frandom boost, Let's try just trigger phi as a cms boost.
371       cosThetaStar = fabs(cos(2*atan(exp(-ftk1->Eta()+fPhiTrigger))));
372       fhistos->fhCosThetaStar[kMixed][ipairPt][imass]->Fill( cosThetaStar, fTrackPairEfficiency );
373       
374       fhistos->fhInvMass[ipairPt]->Fill(pairMass, fTrackPairEfficiency);
375       fhistos->fhCMSrap[ipairPt][imass]->Fill( cosThetaStar, cmsRap*fTrackPairEfficiency );
376       fhistos->fpCMSrap->Fill( cosThetaStar, fabs(cmsRap)*fTrackPairEfficiency );
377     }
378   }
379   
380   //---------------------------------
381   //if(pairMass>10 && fcard->IsLessThanUpperPairPtCut(pairPt) ){
382   //    cout<<pairMass<<" e1="<<ftk1->Eta()-cmsRap<<" e2="<<ftk2->Eta()-cmsRap<<" cms="<<cmsRap;
383   //    cout<<" ppt="<<pairPt<<" tphi="<<fPhiTrigger<<" aphi="<<fPhiAssoc<<" t1="<<fptt<<" t2="<<fpta<<endl;
384   //    double thetaStar = fabs(2*atan(exp(-ftk1->Eta()-cmsRap)));
385   //    cout<<thetaStar<<" "<<fabs(cos(thetaStar))<<endl;
386   //}
387   
388   //---------------------------------
389 }
390
391 void AliJCorrelations::FillXeHistograms(fillType fTyp)
392 {
393   // This method fills the xE and xLong histograms
394   
395   double xe = -fpta*cos(fPhiTrigger-fPhiAssoc)/fptt;
396   
397   if( fTyp == kReal ) {
398     fhistos->fhxEPtBin[0][fpttBin][fptaBin]->Fill(fXlong, fGeometricAcceptanceCorrection * fTrackPairEfficiency);
399     if( fNearSide ) {
400       fhistos->fhxEPtBin[1][fpttBin][fptaBin]->Fill(fXlong, fGeometricAcceptanceCorrection * fTrackPairEfficiency);
401     } else {
402       fhistos->fhxEPtBin[2][fpttBin][fptaBin]->Fill(fXlong, fGeometricAcceptanceCorrection * fTrackPairEfficiency);
403     }
404   }
405   
406   if(fNearSide) {
407     fhistos->fhxEN [fTyp][fpttBin]->Fill(-xe, fGeometricAcceptanceCorrection * fTrackPairEfficiency);
408   } else {
409     fhistos->fhxEF [fTyp][fpttBin]->Fill(xe, fGeometricAcceptanceCorrection * fTrackPairEfficiency);
410     if(fIsIsolatedTrigger) fhistos->fhxEFIsolTrigg[fTyp][fpttBin]->Fill(xe, fGeometricAcceptanceCorrection * fTrackPairEfficiency);
411   }
412 }
413
414 void AliJCorrelations::FillJtHistograms(fillType fTyp, AliJBaseTrack *ftk1, AliJBaseTrack *ftk2, bool fill2DBackground)
415 {
416   // This method fills the jT and pout histograms
417   
418   double pout      = fabs(fpta*sin(fPhiTrigger-fPhiAssoc));
419   
420   if(fNearSide) {
421     
422     TLorentzVector vTrigger = ftk1->GetLorentzVector(), vAssoc = ftk2->GetLorentzVector();   // Lorentz vectors for tracks
423     
424     double jt = vAssoc.Perp(vTrigger.Vect());
425     double weight = jt > 1e-3 ? fGeometricAcceptanceCorrection * fTrackPairEfficiency/jt : 0;
426     
427     int iKlongBin = fcard->GetBin(kLongType, vTrigger.Vect().Dot(vAssoc.Vect())/vTrigger.P());
428     double invariantMass = sqrt(2*(vTrigger.P()*vAssoc.P()-vTrigger.Vect().Dot(vAssoc.Vect())));
429     if(iKlongBin>=0){
430       fhistos->fhJTKlong[fTyp][fCentralityBin][fpttBin][iKlongBin]->Fill(jt, weight);
431       fhistos->fhInvariantMassKlong[fTyp][fCentralityBin][fpttBin][iKlongBin]->Fill(invariantMass);
432
433       // Fill also the signed distributions
434       if(fIsLikeSign){
435         fhistos->fhJTKlongLikeSign[fTyp][fCentralityBin][fpttBin][iKlongBin]->Fill(jt, weight);
436         fhistos->fhInvariantMassKlongLikeSign[fTyp][fCentralityBin][fpttBin][iKlongBin]->Fill(invariantMass);
437       } else {
438         fhistos->fhJTKlongUnlikeSign[fTyp][fCentralityBin][fpttBin][iKlongBin]->Fill(jt, weight);
439         fhistos->fhInvariantMassKlongUnlikeSign[fTyp][fCentralityBin][fpttBin][iKlongBin]->Fill(invariantMass);
440       }
441     }
442     if(fXlongBin>=0){
443       fhistos->fhJT[fTyp][fCentralityBin][fpttBin][fXlongBin]->Fill(jt, weight);
444       fhistos->fhInvariantMassXe[fTyp][fCentralityBin][fpttBin][fXlongBin]->Fill(invariantMass);
445
446       // Fill also the signed distributions
447       if(fIsLikeSign){
448         fhistos->fhJTLikeSign[fTyp][fCentralityBin][fpttBin][fXlongBin]->Fill(jt, weight);
449         fhistos->fhInvariantMassXeLikeSign[fTyp][fCentralityBin][fpttBin][fXlongBin]->Fill(invariantMass);
450       } else {
451         fhistos->fhJTUnlikeSign[fTyp][fCentralityBin][fpttBin][fXlongBin]->Fill(jt, weight);
452         fhistos->fhInvariantMassXeUnlikeSign[fTyp][fCentralityBin][fpttBin][fXlongBin]->Fill(invariantMass);
453       }
454     }
455     if(fptaBin>=0){
456       fhistos->fhJTPta[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill(jt, weight);
457       fhistos->fhInvariantMassPta[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill(invariantMass);
458
459       // Fill also the signed distributions
460       if(fIsLikeSign){
461         fhistos->fhJTPtaLikeSign[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill(jt, weight);
462         fhistos->fhInvariantMassPtaLikeSign[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill(invariantMass);
463       } else {
464         fhistos->fhJTPtaUnlikeSign[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill(jt, weight);
465         fhistos->fhInvariantMassPtaUnlikeSign[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill(invariantMass);
466       }
467     }
468     
469     TLorentzVector vAssocRndm;
470     TLorentzVector vThrustRndm;
471     
472     //-------------------------------------
473     // Rapidity Gap background
474     // ------------------------------------
475     double etaTriggRndm, etaAssocRndm;
476     double dphiAssocRndm = 0;
477
478     if(fTyp==kReal && ( fEtaGapBin >=0 || fRGapBinNear >=0 ) ){
479       for(int iEtaGap=0; iEtaGap<=fEtaGapBin; iEtaGap++) fhistos->fhPtaEtaGapN[fCentralityBin][iEtaGap][fpttBin]->Fill(fpta, fTrackPairEfficiency);
480       for(int iRGap=0; iRGap<=fRGapBinNear; iRGap++) fhistos->fhPtaRGapN[fCentralityBin][iRGap][fpttBin]->Fill(fpta, fTrackPairEfficiency);
481       for(int itrial=0; itrial<20; itrial++){  //For each high eta gap track generate ten others
482         
483         if(fsamplingMethod == 0){
484           etaTriggRndm  = frandom->Uniform(-fmaxEtaRange, fmaxEtaRange);
485           etaAssocRndm  = frandom->Uniform(-fmaxEtaRange, fmaxEtaRange);
486         } else {
487           etaTriggRndm  = fhistos->fhIetaTriggFromFile[fCentralityBin][fpttBin]->GetRandom();
488           etaAssocRndm  = fhistos->fhIetaAssocFromFile[fCentralityBin][fptaBin]->GetRandom();
489         }
490         if( fEtaGapBin >=0 || fRGapBinNear >=0 ) {
491           if( fsamplingMethod == 0) {
492             dphiAssocRndm = kJPi * frandom->Uniform(-0.5, 0.5);
493           } else {
494             dphiAssocRndm = fhistos->fhIphiAssocFromFile[fCentralityBin][fptaBin]->GetRandom();
495           }
496           vAssocRndm.SetPtEtaPhiM(fpta, etaAssocRndm, fPhiTrigger + dphiAssocRndm, 0); //set randomized assoc  TLorentz vector
497         } else {
498           vAssocRndm.SetPtEtaPhiM(fpta, etaAssocRndm, fPhiAssoc, 0); //set randomized assoc  TLorentz vector
499         }
500         
501         vThrustRndm.SetPtEtaPhiM(vTrigger.Pt(),etaTriggRndm, fPhiTrigger, 0);
502         
503         double dEtaRndm = etaTriggRndm - etaAssocRndm;
504         double geoAccCorrRndm = (fsamplingMethod == 0 || fPhiGapBinNear<0 ) ? GetGeoAccCorrFlat(dEtaRndm) : GetGeoAccCorrIncl(dEtaRndm);
505         
506         jt = vAssocRndm.Perp(vThrustRndm.Vect());
507         
508         // TODO : shadowing of iKlongBin
509         int jKlongBin = fcard->GetBin(kLongType, vThrustRndm.Vect().Dot(vAssocRndm.Vect())/vThrustRndm.P());
510         if(jKlongBin>=0){ // 
511           if(jt>1e-3) { //here we used and BgFidCut
512             for(int iEtaGap=0; iEtaGap<=fEtaGapBin; iEtaGap++){
513               fhistos->fhJTKlongBg[fCentralityBin][iEtaGap][fpttBin][jKlongBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
514               if(fill2DBackground) fhistos->fhDphiDetaKlong[fCentralityBin][iEtaGap][fpttBin][jKlongBin]->Fill(dEtaRndm, dphiAssocRndm, geoAccCorrRndm * fTrackPairEfficiency);
515               fhistos->fhBgAssocKlong[fCentralityBin][iEtaGap][fpttBin][jKlongBin]->Fill(fpta, fTrackPairEfficiency);
516
517               // Fill the background histogram for signed pairs
518               if(fIsLikeSign){
519                 fhistos->fhJTKlongBgLikeSign[fCentralityBin][iEtaGap][fpttBin][jKlongBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
520               } else {
521                 fhistos->fhJTKlongBgUnlikeSign[fCentralityBin][iEtaGap][fpttBin][jKlongBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
522               }
523             }
524             for(int iRGap=0; iRGap<=fRGapBinNear; iRGap++){
525               fhistos->fhJTKlongBgR[fCentralityBin][iRGap][fpttBin][jKlongBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
526               if(fill2DBackground) fhistos->fhDphiDetaKlongR[fCentralityBin][iRGap][fpttBin][jKlongBin]->Fill(dEtaRndm, dphiAssocRndm, geoAccCorrRndm * fTrackPairEfficiency);
527               fhistos->fhBgAssocKlongR[fCentralityBin][iRGap][fpttBin][jKlongBin]->Fill(fpta, fTrackPairEfficiency);
528
529               // Fill the background histogram for signed pairs
530               if(fIsLikeSign){
531                 fhistos->fhJTKlongBgRLikeSign[fCentralityBin][iRGap][fpttBin][jKlongBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
532               } else {
533                 fhistos->fhJTKlongBgRUnlikeSign[fCentralityBin][iRGap][fpttBin][jKlongBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
534               }
535             }
536           }
537         }
538         int iXeBin = fcard->GetBin(kXeType, vThrustRndm.Vect().Dot(vAssocRndm.Vect())/pow(vThrustRndm.P(),2) );
539         if(iXeBin>=0){
540           if(jt>1e-3) { //here we used and BgFidCut
541             for(int iEtaGap=0; iEtaGap<=fEtaGapBin; iEtaGap++){
542               fhistos->fhJTBg[fCentralityBin][iEtaGap][fpttBin][iXeBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
543               if(fill2DBackground) fhistos->fhDphiDetaXe[fCentralityBin][iEtaGap][fpttBin][iXeBin]->Fill(dEtaRndm, dphiAssocRndm, geoAccCorrRndm * fTrackPairEfficiency);
544               fhistos->fhBgAssocXe[fCentralityBin][iEtaGap][fpttBin][iXeBin]->Fill(fpta, fTrackPairEfficiency);
545
546               // Fill the background histograms for signed pairs
547               if(fIsLikeSign){
548                 fhistos->fhJTBgLikeSign[fCentralityBin][iEtaGap][fpttBin][iXeBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
549               } else {
550                 fhistos->fhJTBgUnlikeSign[fCentralityBin][iEtaGap][fpttBin][iXeBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
551               }
552             }
553             for(int iRGap=0; iRGap<=fRGapBinNear; iRGap++){
554               fhistos->fhJTBgR[fCentralityBin][iRGap][fpttBin][iXeBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
555               if(fill2DBackground) fhistos->fhDphiDetaXeR[fCentralityBin][iRGap][fpttBin][iXeBin]->Fill(dEtaRndm, dphiAssocRndm, geoAccCorrRndm * fTrackPairEfficiency);
556               fhistos->fhBgAssocXeR[fCentralityBin][iRGap][fpttBin][iXeBin]->Fill(fpta, fTrackPairEfficiency);
557
558               // Fill the background histograms for signed pairs
559               if(fIsLikeSign){
560                 fhistos->fhJTBgRLikeSign[fCentralityBin][iRGap][fpttBin][iXeBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
561               } else {
562                 fhistos->fhJTBgRUnlikeSign[fCentralityBin][iRGap][fpttBin][iXeBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
563               }
564             }
565           }
566         }
567         if(fptaBin>=0){
568           if(jt>1e-3) { //here we used and BgFidCut
569             for(int iEtaGap=0; iEtaGap<=fEtaGapBin; iEtaGap++){
570               fhistos->fhJTPtaBg[fCentralityBin][iEtaGap][fpttBin][fptaBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
571               if(fill2DBackground) fhistos->fhDphiDetaPta[fCentralityBin][iEtaGap][fpttBin][fptaBin]->Fill(dEtaRndm, dphiAssocRndm, geoAccCorrRndm * fTrackPairEfficiency);
572               fhistos->fhBgAssocPta[fCentralityBin][iEtaGap][fpttBin][fptaBin]->Fill(fpta, fTrackPairEfficiency);
573
574               //Fill the background histograms for signed pairs
575               if(fIsLikeSign){
576                 fhistos->fhJTPtaBgLikeSign[fCentralityBin][iEtaGap][fpttBin][fptaBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
577               } else {
578                 fhistos->fhJTPtaBgUnlikeSign[fCentralityBin][iEtaGap][fpttBin][fptaBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
579               }
580             }
581             for(int iRGap=0; iRGap<=fRGapBinNear; iRGap++){
582               fhistos->fhJTPtaBgR[fCentralityBin][iRGap][fpttBin][fptaBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
583               if(fill2DBackground) fhistos->fhDphiDetaPtaR[fCentralityBin][iRGap][fpttBin][fptaBin]->Fill(dEtaRndm, dphiAssocRndm, geoAccCorrRndm * fTrackPairEfficiency);
584               fhistos->fhBgAssocPtaR[fCentralityBin][iRGap][fpttBin][fptaBin]->Fill(fpta, fTrackPairEfficiency);
585
586               //Fill the background histograms for signed pairs
587               if(fIsLikeSign){
588                 fhistos->fhJTPtaBgRLikeSign[fCentralityBin][iRGap][fpttBin][fptaBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
589               } else {
590                 fhistos->fhJTPtaBgRUnlikeSign[fCentralityBin][iRGap][fpttBin][fptaBin]->Fill(jt, geoAccCorrRndm * fTrackPairEfficiency/jt);
591               }
592             } // RGap
593           } // if jt > 1e-3 
594         } // if fptaBin >= 0
595       } //trials
596     } // Eta Gap Random
597     
598     
599   } else {
600     fhistos->fhPoutF[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill(pout, fGeometricAcceptanceCorrection * fTrackPairEfficiency);
601   }
602 }
603
604 void AliJCorrelations::FillDeltaEtaHistograms(fillType fTyp, int ZBin)
605 {
606   // This method fills the DeltaEta histograms
607   
608   if( fNearSide ){ //one could check the phiGapBin, but in the pi/2 <1.6 and thus phiGap is always>-1
609     if( fTyp == 0 ) {
610       fhistos->fhDEtaNear[fCentralityBin][ZBin][fPhiGapBinNear][fpttBin][fptaBin]->Fill( fDeltaEta , fGeometricAcceptanceCorrection * fTrackPairEfficiency );
611       if(fXlongBin>=0) fhistos->fhDEtaNearXEbin[fCentralityBin][ZBin][fPhiGapBinNear][fpttBin][fXlongBin]->Fill( fDeltaEta , fGeometricAcceptanceCorrection * fTrackPairEfficiency );
612     } else {
613       fhistos->fhDEtaNearM[fCentralityBin][ZBin][fPhiGapBinNear][fpttBin][fptaBin]->Fill( fDeltaEta , fGeometricAcceptanceCorrection * fTrackPairEfficiency );
614       if(fXlongBin>=0) fhistos->fhDEtaNearMXEbin[fCentralityBin][ZBin][fPhiGapBinNear][fpttBin][fXlongBin]->Fill( fDeltaEta , fGeometricAcceptanceCorrection * fTrackPairEfficiency );
615     }
616   } else {
617     if(fPhiGapBinAway<=3) fhistos->fhDEtaFar[fTyp][fCentralityBin][fpttBin]->Fill( fDeltaEta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
618   }
619 }
620
621 void AliJCorrelations::FillDeltaPhiHistograms(fillType fTyp)
622 {
623   // This method fills the DeltaPhi histograms
624   
625   // When hists are filled for thresholds they are not properly normalized and need to be subtracted
626   // This induced improper errors - subtraction of not-independent entries
627   
628   fhistos->fhDphiAssoc[fTyp][fCentralityBin][fEtaGapBin][fpttBin][fptaBin]->Fill( fDeltaPhi/kJPi , fGeometricAcceptanceCorrection * fTrackPairEfficiency);
629   if(fXlongBin>=0) fhistos->fhDphiAssocXEbin[fTyp][fCentralityBin][fEtaGapBin][fpttBin][fXlongBin]->Fill( fDeltaPhi/kJPi , fGeometricAcceptanceCorrection * fTrackPairEfficiency);
630   
631   if(fIsIsolatedTrigger) fhistos->fhDphiAssocIsolTrigg[fTyp][fCentralityBin][fpttBin][fptaBin]->Fill( fDeltaPhi/kJPi , fGeometricAcceptanceCorrection * fTrackPairEfficiency); //FK//
632 }
633
634 void AliJCorrelations::FillPtaHistograms(fillType fTyp)
635 {
636   // This method fills various pta histograms
637   
638   if ( fTyp == kReal ) {
639     //must be here, not in main, to avoid counting triggers
640     fhistos->fhAssocPtBin[fCentralityBin][fpttBin][fptaBin]->Fill(fpta ); //I think It should not be weighted by Eff
641     
642     //++++++++++++++++++++++++++++++++++++++++++++++++++
643     // in order to get mean pTa in the jet peak one has
644     // to fill fhMeanPtAssoc in |DeltaEta|<0.4
645     // +++++++++++++++++++++++++++++++++++++++++++++++++
646     if(fEtaGapBin>=0 && fEtaGapBin<2){
647       fhistos->fhMeanPtAssoc[fCentralityBin][fpttBin][fptaBin]->Fill( fDeltaPhi/kJPi , fpta );
648       fhistos->fhMeanZtAssoc[fCentralityBin][fpttBin][fptaBin]->Fill( fDeltaPhi/kJPi , fpta/fptt);
649     }
650     
651     //UE distribution
652     if(fabs(fDeltaPhiPiPi/kJPi)>fDPhiUERegion[0] && fabs(fDeltaPhiPiPi/kJPi)<fDPhiUERegion[1]){
653       for(int iEtaGap=0; iEtaGap<=fEtaGapBin; iEtaGap++)  //FK// UE Pta spectrum for different eta gaps
654         fhistos->fhPtAssocUE[fCentralityBin][iEtaGap][fpttBin]->Fill(fpta, fTrackPairEfficiency);
655       if(fIsIsolatedTrigger){ //FK// trigger is isolated hadron
656         fhistos->fhPtAssocUEIsolTrigg[fpttBin]->Fill(fpta, fTrackPairEfficiency); //FK//
657       }
658     }
659     if(fabs(fDeltaPhi/kJPi)<0.15) fhistos->fhPtAssocN[fpttBin]->Fill(fpta, fTrackPairEfficiency);
660     if(fabs(fDeltaPhi/kJPi-1)<0.15) fhistos->fhPtAssocF[fpttBin]->Fill(fpta, fTrackPairEfficiency);
661     
662     fnReal++;
663   } else { // only mix
664     fnMix++;
665   }
666 }
667
668 void AliJCorrelations::FillIAAAndMoonHistograms(fillType fTyp, int ZBin)
669 {
670   // This method fills the I_AA and moon histograms
671   
672   fhistos->fhDphiAssoc2DIAA[fTyp][fCentralityBin][ZBin][fpttBin][fptaBin]->Fill( fDeltaEta, fDeltaPhi/kJPi, fTrackPairEfficiency);
673   
674   if(fRGapBinNear>=0){
675     if(fRGapBinNear <= fRSignalBin) fhistos->fhDRNearPt[fTyp][fCentralityBin][ZBin][fRGapBinNear][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
676     // - moon -
677     if(fRGapBinNear>0){
678       for( int irs = 0; irs <= fRSignalBin;irs++ ){
679         if( fRGapBinNear < irs ) continue;
680         if( fPhiGapBinNear > irs ) continue;
681         for ( int ir1=0;ir1<= fRGapBinNear;ir1++ ){
682           if( irs > ir1 ) continue;
683           if( ir1 > fRGapBinNear ) continue;
684           double rGapS= fRGap[irs+1];
685           double rGap1= fRGap[ir1+1];
686           if( rGap1 < TMath::Abs(fDeltaPhiPiPi) ) continue;
687           if( rGapS < TMath::Abs(fDeltaPhiPiPi) ) continue;
688           double dEtaMin = sqrt(rGap1*rGap1-fDeltaPhiPiPi*fDeltaPhiPiPi);
689           double dEtaMax = dEtaMin + sqrt(rGapS*rGapS-fDeltaPhiPiPi*fDeltaPhiPiPi);
690           double eta = TMath::Abs( fDeltaEta );
691           if( eta > dEtaMin && eta < dEtaMax ){
692             //if( eta > dEtaMin && eta < dEtaMax && fDeltaEta <0 ){
693             // xxx
694             // fhistos->hDRNearPtMoon[fTyp][fCentralityBin][ZBin][ir1][irs][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
695             
696             if( fTyp == 0 )
697               fhistos->fhDRNearPtMoon[fCentralityBin][ZBin][ir1][irs][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
698             else
699               fhistos->fhDRNearPtMoonM[fCentralityBin][ZBin][ir1][irs][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
700             if(fTyp == kReal)       fhistos->fhDphiAssoc2D[ir1][irs]->Fill( fDeltaEta, fDeltaPhi/kJPi, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
701           }
702         }
703       }
704     }
705   }
706   
707   if(fRGapBinAway>=0){
708     if(fRGapBinAway <= fRSignalBin) fhistos->fhDRFarPt[fTyp][fCentralityBin][ZBin][fRGapBinAway][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
709     // - moon -
710     if(fRGapBinAway>0){
711       for( int irs = 0; irs <= fRSignalBin;irs++ ){
712         if( fRGapBinAway < irs ) continue;
713         if( fPhiGapBinAway > irs ) continue;
714         for ( int ir1=0;ir1<= fRGapBinAway;ir1++ ){
715           if( irs > ir1 ) continue;
716           if( ir1 > fRGapBinAway ) continue;
717           double rGapS= fRGap[irs+1];
718           double rGap1= fRGap[ir1+1];
719           if( rGap1 < TMath::Abs(fDeltaPhi-kJPi) ) continue;
720           if( rGapS < TMath::Abs(fDeltaPhi-kJPi) ) continue;
721           double dEtaMin = sqrt(rGap1*rGap1- (fDeltaPhi-kJPi)*(fDeltaPhi-kJPi) );
722           double dEtaMax = dEtaMin + sqrt(rGapS*rGapS-(fDeltaPhi-kJPi)*(fDeltaPhi-kJPi) );
723           double eta = TMath::Abs( fDeltaEta );
724           if( eta > dEtaMin && eta < dEtaMax ){
725             //if( eta > dEtaMin && eta < dEtaMax && fDeltaEta <0 ){
726             // xxx
727             //                        fhistos->hDRFarPtMoon[fTyp][fCentralityBin][ZBin][ir1][irs][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
728             if( fTyp == 0 )
729               fhistos->fhDRFarPtMoon[fCentralityBin][ZBin][ir1][irs][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
730             else
731               fhistos->fhDRFarPtMoonM[fCentralityBin][ZBin][ir1][irs][fpttBin]->Fill( fpta, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
732             
733             if(fTyp == kReal)       fhistos->fhDphiAssoc2D[ir1][irs]->Fill( fDeltaEta, fDeltaPhi/kJPi, fGeometricAcceptanceCorrection * fTrackPairEfficiency );
734           }
735         }
736       }
737     }
738   }
739 }
740
741
742 double AliJCorrelations::GetGeoAccCorrFlat(double deltaEta){
743   //FK// calculate acceptance correction on pseudorapidity triangle
744   double absDEta = fabs(deltaEta);
745   
746   double denominator = 1 - absDEta/(2*fmaxEtaRange);
747   //double denominator = 1 - (absDEta - ftriggFiducCut)/(2*fmaxEtaRange-2*ftriggFiducCut);//When Fid>0 max_Deta je mensi nez 2*EtaMax
748   //double denominator = 1 - (absDEta - ftriggFiducCut)/(2*fmaxEtaRange-ftriggFiducCut);
749   if(denominator > 1e-6)
750     return 1.0/denominator;
751   else
752     return 0;
753 }
754
755 double AliJCorrelations::GetGeoAccCorrIncl(double deltaEta){
756   // histo filler
757   
758   if(fhistos->fhDEtaNearMixFromFile[fCentralityBin][fpttBin][fptaBin]->GetEntries()<1000) return GetGeoAccCorrFlat(deltaEta);
759   
760   int bin =  fhistos->fhDEtaNearMixFromFile[fCentralityBin][fpttBin][fptaBin]->FindBin(deltaEta);
761   double denominator  =  fhistos->fhDEtaNearMixFromFile[fCentralityBin][fpttBin][fptaBin]->GetBinContent(bin);
762   if(denominator > 1e-6)
763     return 1.0/denominator;
764   else
765     return 0;
766   
767 }
768
769 double AliJCorrelations::DeltaPhi(double phi1, double phi2) {
770   // dphi
771   double res =  atan2(sin(phi1-phi2), cos(phi1-phi2));
772   //double res = phi1 - phi2;
773   //return res>-kJPi/3.0 ? res : kJTwoPi+res ;
774   return res>-kJPi*9./20. ? res : kJTwoPi+res ;
775 }
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796