]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx
6797f0ef560c65783290a85325c6a90e70cc6174
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowCommon / AliFlowAnalysisWithQCumulants.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2008, 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 /********************************** 
17  * flow analysis with Q-cumulants * 
18  *                                * 
19  * author:  Ante Bilandzic        * 
20  *           (anteb@nikhef.nl)    *
21  *********************************/ 
22
23 #define AliFlowAnalysisWithQCumulants_cxx
24
25 #include "Riostream.h"
26 #include "AliFlowCommonConstants.h"
27 #include "AliFlowCommonHist.h"
28 #include "AliFlowCommonHistResults.h"
29 #include "TChain.h"
30
31 #include "TFile.h"
32 #include "TList.h"
33 #include "TGraph.h"
34 #include "TParticle.h"
35 #include "TRandom3.h"
36 #include "TStyle.h"
37 #include "TProfile.h"
38 #include "TProfile2D.h" 
39 #include "TProfile3D.h"
40 #include "TMath.h"
41 #include "TArrow.h"
42 #include "TPaveLabel.h"
43 #include "TCanvas.h"
44 #include "AliFlowEventSimple.h"
45 #include "AliFlowTrackSimple.h"
46 #include "AliFlowAnalysisWithQCumulants.h"
47 #include "TArrayD.h"
48 #include "TRandom.h"
49 #include "TF1.h"
50
51 class TH1;
52 class TH2;
53 class TGraph;
54 class TPave;
55 class TLatex;
56 class TMarker;
57 class TRandom3;
58 class TObjArray;
59 class TList;
60 class TCanvas;
61 class TSystem;
62 class TROOT;
63 class AliFlowVector;
64 class TVector;
65
66
67 //================================================================================================================
68
69
70 ClassImp(AliFlowAnalysisWithQCumulants)
71
72 AliFlowAnalysisWithQCumulants::AliFlowAnalysisWithQCumulants(): 
73  // 0.) base:
74  fHistList(NULL),
75  // 1.) common:
76  fCommonHists(NULL),
77  fCommonHists2nd(NULL), 
78  fCommonHists4th(NULL),
79  fCommonHists6th(NULL),
80  fCommonHists8th(NULL),
81  fCommonHistsResults2nd(NULL),
82  fCommonHistsResults4th(NULL),
83  fCommonHistsResults6th(NULL),
84  fCommonHistsResults8th(NULL),
85  fnBinsPhi(0),
86  fPhiMin(0),
87  fPhiMax(0),
88  fPhiBinWidth(0),
89  fnBinsPt(0),
90  fPtMin(0),
91  fPtMax(0),
92  fPtBinWidth(0),
93  fnBinsEta(0),
94  fEtaMin(0),
95  fEtaMax(0),
96  fEtaBinWidth(0),
97  fHarmonic(2),
98  fAnalysisLabel(NULL),
99  // 2a.) particle weights:
100  fWeightsList(NULL),
101  fUsePhiWeights(kFALSE),
102  fUsePtWeights(kFALSE),
103  fUseEtaWeights(kFALSE),
104  fUseParticleWeights(NULL),
105  fPhiWeights(NULL),
106  fPtWeights(NULL),
107  fEtaWeights(NULL),
108  // 2b.) event weights:
109  fMultiplicityWeight(NULL),
110  // 3.) integrated flow:
111  fIntFlowList(NULL), 
112  fIntFlowProfiles(NULL),
113  fIntFlowResults(NULL),
114  fIntFlowFlags(NULL),
115  fApplyCorrectionForNUA(kTRUE), 
116  fReQ(NULL),
117  fImQ(NULL),
118  fSMpk(NULL),
119  fIntFlowCorrelationsEBE(NULL),
120  fIntFlowEventWeightsForCorrelationsEBE(NULL),
121  fIntFlowCorrelationsAllEBE(NULL),
122  fAvMultiplicity(NULL),
123  fIntFlowCorrelationsPro(NULL),
124  fIntFlowCorrelationsAllPro(NULL),
125  fIntFlowExtraCorrelationsPro(NULL),
126  fIntFlowProductOfCorrelationsPro(NULL),
127  fIntFlowCorrelationsHist(NULL),
128  fIntFlowCorrelationsAllHist(NULL),
129  fIntFlowCovariances(NULL),
130  fIntFlowSumOfProductOfEventWeights(NULL),
131  fIntFlowQcumulants(NULL),
132  fIntFlow(NULL),
133  // 4.) differential flow:
134  fDiffFlowList(NULL),
135  fDiffFlowProfiles(NULL),
136  fDiffFlowResults(NULL),
137  fDiffFlowFlags(NULL),
138  fCalculate2DFlow(kFALSE),
139  // 5.) distributions:
140  fDistributionsList(NULL),
141  fDistributionsFlags(NULL),
142  fStoreDistributions(kFALSE),
143  // x.) debugging and cross-checking:
144  fNestedLoopsList(NULL),
145  fEvaluateIntFlowNestedLoops(kFALSE),
146  fEvaluateDiffFlowNestedLoops(kFALSE),
147  fMaxAllowedMultiplicity(10),
148  fEvaluateNestedLoops(NULL),
149  fIntFlowDirectCorrelations(NULL),
150  fIntFlowExtraDirectCorrelations(NULL),
151  fCrossCheckInPtBinNo(10),
152  fCrossCheckInEtaBinNo(20),
153  fNoOfParticlesInBin(NULL)
154  {
155   // constructor  
156   
157   // base list to hold all output objects:
158   fHistList = new TList();
159   fHistList->SetName("cobjQC");
160   fHistList->SetOwner(kTRUE);
161   
162   // list to hold histograms with phi, pt and eta weights:      
163   fWeightsList = new TList();
164   
165   // multiplicity weight:
166   fMultiplicityWeight = new TString("combinations");
167     
168   // analysis label;
169   fAnalysisLabel = new TString();
170       
171   // initialize all arrays:  
172   this->InitializeArraysForIntFlow();
173   this->InitializeArraysForDiffFlow();
174   this->InitializeArraysForDistributions();
175   this->InitializeArraysForNestedLoops();
176   
177  } // end of constructor
178  
179
180 //================================================================================================================  
181
182
183 AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
184 {
185  // destructor
186  
187  delete fHistList;
188
189 } // end of AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
190
191
192 //================================================================================================================
193
194
195 void AliFlowAnalysisWithQCumulants::Init()
196 {
197  // a) Cross check if the settings make sense before starting the QC adventure;
198  // b) Access all common constants;
199  // c) Book all objects;
200  // d) Store flags for integrated and differential flow;
201  // e) Store flags for distributions of corelations;
202  // f) Store harmonic which will be estimated.
203   
204  //save old value and prevent histograms from being added to directory
205  //to avoid name clashes in case multiple analaysis objects are used
206  //in an analysis
207  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
208  TH1::AddDirectory(kFALSE);
209  
210  // a) Cross check if the settings make sense before starting the QC adventure; 
211  this->CrossCheckSettings();
212  // b) Access all common constants:
213  this->AccessConstants();
214  // c) Book all objects:
215  this->BookAndFillWeightsHistograms();
216  this->BookAndNestAllLists();
217  this->BookCommonHistograms();
218  this->BookEverythingForIntegratedFlow(); 
219  this->BookEverythingForDifferentialFlow(); 
220  this->BookEverythingForDistributions();
221  this->BookEverythingForNestedLoops();
222  // d) Store flags for integrated and differential flow:
223  this->StoreIntFlowFlags();
224  this->StoreDiffFlowFlags();
225  // e) Store flags for distributions of corelations:
226  this->StoreFlagsForDistributions();
227  // f) Store harmonic which will be estimated:
228  this->StoreHarmonic();
229  
230  TH1::AddDirectory(oldHistAddStatus);
231 } // end of void AliFlowAnalysisWithQCumulants::Init()
232
233
234 //================================================================================================================
235
236
237 void AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
238 {
239  // Running over data only in this method.
240  
241  //  a) Fill the common control histograms and call the method to fill fAvMultiplicity;
242  //  b) Loop over data and calculate e-b-e quantities;
243  //  c) Call all the methods;
244  //  d) Debugging and cross-checking (evaluate nested loops);
245  //  e) Reset all event by event quantities. 
246  
247  Double_t dPhi = 0.; // azimuthal angle in the laboratory frame
248  Double_t dPt  = 0.; // transverse momentum
249  Double_t dEta = 0.; // pseudorapidity
250
251  Double_t wPhi = 1.; // phi weight
252  Double_t wPt  = 1.; // pt weight
253  Double_t wEta = 1.; // eta weight
254  
255  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
256  
257  // a) Fill the common control histograms and call the method to fill fAvMultiplicity:
258  this->FillCommonControlHistograms(anEvent);                                                               
259  this->FillAverageMultiplicities(nRP);                                                                  
260                                                                                                                                                                                                                                                                                         
261  // b) Loop over data and calculate e-b-e quantities:
262  Int_t nPrim = anEvent->NumberOfTracks();  // nPrim = total number of primary tracks, i.e. nPrim = nRP + nPOI + rest, where:
263                                            // nRP   = # of particles used to determine the reaction plane;
264                                            // nPOI  = # of particles of interest for a detailed flow analysis;
265                                            // rest  = # of particles which are not niether RPs nor POIs.  
266  
267  AliFlowTrackSimple *aftsTrack = NULL;
268  
269  for(Int_t i=0;i<nPrim;i++) 
270  { 
271   aftsTrack=anEvent->GetTrack(i);
272   if(aftsTrack)
273   {
274    if(!(aftsTrack->InRPSelection() || aftsTrack->InPOISelection())) continue; // consider only tracks which are RPs or POIs
275    Int_t n = fHarmonic; // shortcut for the harmonic
276    if(aftsTrack->InRPSelection()) // RP condition:
277    {    
278     dPhi = aftsTrack->Phi();
279     dPt  = aftsTrack->Pt();
280     dEta = aftsTrack->Eta();
281     if(fUsePhiWeights && fPhiWeights && fnBinsPhi) // determine phi weight for this particle:
282     {
283      wPhi = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*fnBinsPhi/TMath::TwoPi())));
284     }
285     if(fUsePtWeights && fPtWeights && fnBinsPt) // determine pt weight for this particle:
286     {
287      wPt = fPtWeights->GetBinContent(1+(Int_t)(TMath::Floor((dPt-fPtMin)/fPtBinWidth))); 
288     }              
289     if(fUseEtaWeights && fEtaWeights && fEtaBinWidth) // determine eta weight for this particle: 
290     {
291      wEta = fEtaWeights->GetBinContent(1+(Int_t)(TMath::Floor((dEta-fEtaMin)/fEtaBinWidth))); 
292     } 
293       
294     // integrated flow: 
295     // calculate Re[Q_{m*n,k}] and Im[Q_{m*n,k}], m = 1,2,3,4, for this event:
296     for(Int_t m=0;m<4;m++)
297     {
298      for(Int_t k=0;k<9;k++)
299      {
300       (*fReQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1)*n*dPhi); 
301       (*fImQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1)*n*dPhi); 
302      } 
303     }
304     // calculate S^{M}_{p,k} for this event 
305     // Remark: final calculation of S^{M}_{p,k} follows after the loop over data bellow:
306     for(Int_t p=0;p<8;p++)
307     {
308      for(Int_t k=0;k<9;k++)
309      {     
310       (*fSMpk)(p,k)+=pow(wPhi*wPt*wEta,k);
311      }
312     } 
313     
314     // differential flow:
315     // 1D (pt):
316     // (r_{m*m,k}(pt)): 
317     for(Int_t m=0;m<4;m++)
318     {
319      for(Int_t k=0;k<9;k++)
320      {
321       fReRPQ1dEBE[0][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
322       fImRPQ1dEBE[0][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
323      }
324     }
325            
326     // s_{k}(pt) for RPs // to be improved (clarified)
327     // Remark: final calculation of s_{p,k}(pt) follows after the loop over data bellow:
328     for(Int_t k=0;k<9;k++)
329     {
330      fs1dEBE[0][0][k]->Fill(dPt,pow(wPhi*wPt*wEta,k),1.);
331     }
332     // 1D (eta):
333     // (r_{m*m,k}(eta)): 
334     for(Int_t m=0;m<4;m++)
335     {
336      for(Int_t k=0;k<9;k++)
337      {
338       fReRPQ1dEBE[0][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
339       fImRPQ1dEBE[0][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
340      }
341     }   
342     // s_{k}(eta) for RPs // to be improved (clarified)
343     // Remark: final calculation of s_{p,k}(eta) follows after the loop over data bellow:
344     for(Int_t k=0;k<9;k++)
345     {
346      fs1dEBE[0][1][k]->Fill(dEta,pow(wPhi*wPt*wEta,k),1.);
347     }
348     
349     
350     
351     /*
352     // 2D (pt,eta):
353     if(fCalculate2DFlow)
354     {
355      // (r_{m*m,k}(pt,eta)): 
356      for(Int_t m=0;m<4;m++)
357      {
358       for(Int_t k=0;k<9;k++)
359       {
360        fReRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
361        fImRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
362       }
363      }    
364      // s_{k}(pt,eta) for RPs // to be improved (clarified)
365      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
366      for(Int_t k=0;k<9;k++)
367      {
368       fs2dEBE[0][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
369      }
370     } // end of if(fCalculate2DFlow)  
371     */ 
372     
373       
374      
375     if(aftsTrack->InPOISelection())
376     {
377      // 1D (pt): 
378      // (q_{m*m,k}(pt)): 
379      for(Int_t m=0;m<4;m++)
380      {
381       for(Int_t k=0;k<9;k++)
382       {
383        fReRPQ1dEBE[2][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
384        fImRPQ1dEBE[2][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
385       }
386      } 
387      // s_{k}(pt) for RP&&POIs // to be improved (clarified)
388      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
389      for(Int_t k=0;k<9;k++)
390      {
391       fs1dEBE[2][0][k]->Fill(dPt,pow(wPhi*wPt*wEta,k),1.);
392      }
393      // 1D (eta): 
394      // (q_{m*m,k}(eta)): 
395      for(Int_t m=0;m<4;m++)
396      {
397       for(Int_t k=0;k<9;k++)
398       {
399        fReRPQ1dEBE[2][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
400        fImRPQ1dEBE[2][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
401       }
402      } 
403      // s_{k}(eta) for RP&&POIs // to be improved (clarified)
404      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
405      for(Int_t k=0;k<9;k++)
406      {
407       fs1dEBE[2][1][k]->Fill(dEta,pow(wPhi*wPt*wEta,k),1.);
408      }
409      
410      /*
411      // 2D (pt,eta) 
412      if(fCalculate2DFlow)
413      {
414       // (q_{m*m,k}(pt,eta)): 
415       for(Int_t m=0;m<4;m++)
416       {
417        for(Int_t k=0;k<9;k++)
418        {
419         fReRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
420         fImRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
421        }
422       } 
423       // s_{k}(pt,eta) for RP&&POIs // to be improved (clarified)
424       // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
425       for(Int_t k=0;k<9;k++)
426       {
427        fs2dEBE[2][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
428       }
429      } // end of if(fCalculate2DFlow) 
430      */
431       
432     } // end of if(aftsTrack->InPOISelection())
433     
434
435      
436    } // end of if(pTrack->InRPSelection())
437
438   
439   
440    if(aftsTrack->InPOISelection())
441    {
442     dPhi = aftsTrack->Phi();
443     dPt  = aftsTrack->Pt();
444     dEta = aftsTrack->Eta();
445     
446     // 1D (pt)
447     // p_n(m*n,0):   
448     for(Int_t m=0;m<4;m++)
449     {
450      fReRPQ1dEBE[1][0][m][0]->Fill(dPt,TMath::Cos((m+1.)*n*dPhi),1.);
451      fImRPQ1dEBE[1][0][m][0]->Fill(dPt,TMath::Sin((m+1.)*n*dPhi),1.);
452     }
453     // 1D (eta)
454     // p_n(m*n,0):   
455     for(Int_t m=0;m<4;m++)
456     {
457      fReRPQ1dEBE[1][1][m][0]->Fill(dEta,TMath::Cos((m+1.)*n*dPhi),1.);
458      fImRPQ1dEBE[1][1][m][0]->Fill(dEta,TMath::Sin((m+1.)*n*dPhi),1.);
459     }
460     
461     
462     /*
463     // 2D (pt,eta):
464     if(fCalculate2DFlow)
465     {      
466      // p_n(m*n,0):   
467      for(Int_t m=0;m<4;m++)
468      {
469       fReRPQ2dEBE[1][m][0]->Fill(dPt,dEta,TMath::Cos((m+1.)*n*dPhi),1.);
470       fImRPQ2dEBE[1][m][0]->Fill(dPt,dEta,TMath::Sin((m+1.)*n*dPhi),1.);
471      }
472     } // end of if(fCalculate2DFlow)  
473     */
474     
475     
476    } // end of if(pTrack->InPOISelection() )   
477  
478   
479   } else // to if(aftsTrack)
480     {
481      cout<<endl;
482      cout<<" WARNING: no particle! (i.e. aftsTrack is a NULL pointer in AFAWQC::Make().)"<<endl;
483      cout<<endl;       
484     }
485  } // end of for(Int_t i=0;i<nPrim;i++) 
486
487  // calculate the final expressions for S^{M}_{p,k}:
488  for(Int_t p=0;p<8;p++)
489  {
490   for(Int_t k=0;k<9;k++)
491   {
492    (*fSMpk)(p,k)=pow((*fSMpk)(p,k),p+1);
493   }  
494  } 
495  
496  // *****************************
497  // **** CALL THE METHODS *******
498  // *****************************
499  // integrated flow:
500  if(!fEvaluateIntFlowNestedLoops)
501  {
502   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
503   {
504    if(nRP>1) this->CalculateIntFlowCorrelations(); // without using particle weights
505   } else 
506     {
507      if(nRP>1) this->CalculateIntFlowCorrelationsUsingParticleWeights(); // with using particle weights   
508     } 
509        
510   if(nRP>3) this->CalculateIntFlowProductOfCorrelations();
511   if(nRP>1) this->CalculateIntFlowSumOfEventWeights();
512   if(nRP>1) this->CalculateIntFlowSumOfProductOfEventWeights();
513   if(fApplyCorrectionForNUA)
514   {
515    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
516    {
517     if(nRP>0) this->CalculateIntFlowCorrectionsForNUASinTerms();
518     if(nRP>0) this->CalculateIntFlowCorrectionsForNUACosTerms();
519    } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
520      {
521       if(nRP>0) this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights();
522       if(nRP>0) this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights();     
523      }  
524   } // end of if(fApplyCorrectionForNUA)
525  } // end of if(!fEvaluateIntFlowNestedLoops)
526
527  // differential flow:
528  if(!fEvaluateDiffFlowNestedLoops)
529  {
530   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
531   {
532    // without using particle weights:
533    this->CalculateDiffFlowCorrelations("RP","Pt"); 
534    this->CalculateDiffFlowCorrelations("RP","Eta");
535    this->CalculateDiffFlowCorrelations("POI","Pt");
536    this->CalculateDiffFlowCorrelations("POI","Eta");
537    if(fApplyCorrectionForNUA)
538    {
539     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
540     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");
541     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
542     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");
543     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
544     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");
545     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
546     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");   
547    } // end of if(fApplyCorrectionForNUA)  
548   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
549     {
550      // with using particle weights:   
551      this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
552      this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta"); 
553      this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
554      this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta"); 
555      if(fApplyCorrectionForNUA)
556      {
557       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
558       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");
559       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
560       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");
561       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
562       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");
563       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
564       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");   
565      } // end of if(fApplyCorrectionForNUA)  
566     } 
567     
568   // whether or not using particle weights the following is calculated in the same way:  
569   this->CalculateDiffFlowProductOfCorrelations("RP","Pt");
570   this->CalculateDiffFlowProductOfCorrelations("RP","Eta");
571   this->CalculateDiffFlowProductOfCorrelations("POI","Pt");
572   this->CalculateDiffFlowProductOfCorrelations("POI","Eta");
573   this->CalculateDiffFlowSumOfEventWeights("RP","Pt");
574   this->CalculateDiffFlowSumOfEventWeights("RP","Eta");
575   this->CalculateDiffFlowSumOfEventWeights("POI","Pt");
576   this->CalculateDiffFlowSumOfEventWeights("POI","Eta");
577   this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Pt");
578   this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Eta");
579   this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Pt");
580   this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Eta");   
581  } // end of if(!fEvaluateDiffFlowNestedLoops)
582
583
584    
585   // with weights:
586   // ... 
587   
588   /*
589   // 2D differential flow
590   if(fCalculate2DFlow)
591   {
592    // without weights:
593    if(nRP>1) this->CalculateCorrelationsForDifferentialFlow2D("RP");
594    if(nRP>1) this->CalculateCorrelationsForDifferentialFlow2D("POI");
595   
596    // with weights:
597    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
598    {
599     if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow2D("RP");
600     if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow2D("POI");
601    } 
602   } // end of if(fCalculate2DFlow)
603   */
604   
605  // distributions of correlations:
606  if(fStoreDistributions)
607  {
608   this->StoreDistributionsOfCorrelations();
609  }
610   
611  // d) Debugging and cross-checking (evaluate nested loops):
612  //  d1) cross-checking results for integrated flow:
613  if(fEvaluateIntFlowNestedLoops)
614  {
615   if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10 
616   {
617    // without using particle weights:
618    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
619    {
620     // correlations:
621     this->CalculateIntFlowCorrelations(); // from Q-vectors
622     this->EvaluateIntFlowCorrelationsWithNestedLoops(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
623     // correction for non-uniform acceptance:
624     this->CalculateIntFlowCorrectionsForNUASinTerms(); // from Q-vectors (sin terms)
625     this->CalculateIntFlowCorrectionsForNUACosTerms(); // from Q-vectors (cos terms)
626     this->EvaluateIntFlowCorrectionsForNUAWithNestedLoops(anEvent); // from nested loops (both sin and cos terms)
627    }
628    // using particle weights:
629    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
630    {
631     // correlations:
632     this->CalculateIntFlowCorrelationsUsingParticleWeights(); // from Q-vectors
633     this->EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
634     // correction for non-uniform acceptance:
635     this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights(); // from Q-vectors (sin terms)
636     this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights(); // from Q-vectors (cos terms)
637     this->EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (both sin and cos terms)   
638    }
639   } else if (nPrim>fMaxAllowedMultiplicity) // to if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity)
640     {
641      cout<<endl;
642      cout<<"Skipping the event because multiplicity is "<<nPrim<<". Too high to evaluate nested loops!"<<endl;
643     } else
644       {
645        cout<<endl;
646        cout<<"Skipping the event because multiplicity is "<<nPrim<<"."<<endl;      
647       } 
648  } // end of if(fEvaluateIntFlowNestedLoops) 
649  
650  //  d2) cross-checking results for differential flow:
651  if(fEvaluateDiffFlowNestedLoops)
652  {
653   if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
654   {
655    // without using particle weights:
656    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
657    {
658     // reduced correlations:
659     // Q-vectors:
660     this->CalculateDiffFlowCorrelations("RP","Pt");
661     this->CalculateDiffFlowCorrelations("RP","Eta");
662     this->CalculateDiffFlowCorrelations("POI","Pt");
663     this->CalculateDiffFlowCorrelations("POI","Eta");
664     // nested loops:
665     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Pt"); 
666     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Eta"); 
667     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Pt"); 
668     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Eta"); 
669     // reduced corrections for non-uniform acceptance:
670     // Q-vectors:
671     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
672     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");
673     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
674     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");
675     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
676     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");
677     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
678     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");
679     // nested loops:
680     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Pt");
681     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Eta");
682     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Pt"); 
683     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Eta"); 
684    } // end of if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
685    // using particle weights:
686    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
687    {
688     this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
689     this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta"); 
690     this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
691     this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta"); 
692     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
693     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");
694     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
695     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");
696     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
697     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");
698     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
699     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");
700     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
701     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta");
702     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
703     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta");   
704     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
705     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta"); 
706     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
707     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta"); 
708    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
709   } // end of if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
710  } // end of if(fEvaluateDiffFlowNestedLoops) 
711  
712  // e) Reset all event by event quantities: 
713  this->ResetEventByEventQuantities();
714  
715 } // end of AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
716
717
718 //================================================================================================================================
719
720
721 void AliFlowAnalysisWithQCumulants::Finish()
722 {
723  // Calculate the final results.
724  //  a) acces the constants;
725  //  b) access the flags;
726  //  c) calculate the final results for integrated flow (without and with weights);
727  //  d) store in AliFlowCommonHistResults and print the final results for integrated flow;
728  //  e) calculate the final results for differential flow (without and with weights);
729  //  f) print the final results for integrated flow obtained from differential flow (to be improved (terminology));
730  //  g) cross-check the results: results from Q-vectors vs results from nested loops
731  
732  // ******************************
733  // **** ACCESS THE CONSTANTS ****
734  // ******************************
735  
736  this->AccessConstants();          
737  
738  if(fCommonHists && fCommonHists->GetHarmonic())
739  {
740   fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1); // to be improved (moved somewhere else)
741  } 
742
743  // **************************
744  // **** ACCESS THE FLAGS ****
745  // **************************    
746  fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
747  fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
748  fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3);  
749  fApplyCorrectionForNUA = (Int_t)fIntFlowFlags->GetBinContent(3); 
750  fPrintFinalResults[0] = (Int_t)fIntFlowFlags->GetBinContent(4);
751  fPrintFinalResults[1] = (Int_t)fIntFlowFlags->GetBinContent(5);
752  fPrintFinalResults[2] = (Int_t)fIntFlowFlags->GetBinContent(6);
753  fEvaluateIntFlowNestedLoops = (Int_t)fEvaluateNestedLoops->GetBinContent(1);
754  fEvaluateDiffFlowNestedLoops = (Int_t)fEvaluateNestedLoops->GetBinContent(2); 
755  fCrossCheckInPtBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(3);
756  fCrossCheckInEtaBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(4); 
757     
758  // *********************************************************
759  // **** CALCULATE THE FINAL RESULTS FOR INTEGRATED FLOW ****
760  // *********************************************************     
761  
762  this->FinalizeCorrelationsIntFlow();
763  this->CalculateCovariancesIntFlow();
764  this->CalculateCumulantsIntFlow();
765  this->CalculateIntFlow(); 
766
767  if(fApplyCorrectionForNUA) // to be improved (reorganized, etc)
768  {
769   this->FinalizeCorrectionTermsForNUAIntFlow();
770   this->CalculateQcumulantsCorrectedForNUAIntFlow();   
771   this->CalculateIntFlowCorrectedForNUA(); 
772  }
773   
774  // ***************************************************************
775  // **** STORE AND PRINT THE FINAL RESULTS FOR INTEGRATED FLOW ****
776  // ***************************************************************
777  
778  this->FillCommonHistResultsIntFlow();  
779   
780  if(fPrintFinalResults[0])
781  {
782   this->PrintFinalResultsForIntegratedFlow("NONAME"); // to be improved (name)
783  }
784  
785  // ***********************************************************
786  // **** CALCULATE THE FINAL RESULTS FOR DIFFERENTIAL FLOW ****
787  // ***********************************************************    
788  
789  this->FinalizeReducedCorrelations("RP","Pt"); 
790  this->FinalizeReducedCorrelations("RP","Eta"); 
791  this->FinalizeReducedCorrelations("POI","Pt"); 
792  this->FinalizeReducedCorrelations("POI","Eta");
793  this->CalculateDiffFlowCovariances("RP","Pt");
794  this->CalculateDiffFlowCovariances("RP","Eta");
795  this->CalculateDiffFlowCovariances("POI","Pt");
796  this->CalculateDiffFlowCovariances("POI","Eta");
797  this->CalculateDiffFlowCumulants("RP","Pt");
798  this->CalculateDiffFlowCumulants("RP","Eta");
799  this->CalculateDiffFlowCumulants("POI","Pt");
800  this->CalculateDiffFlowCumulants("POI","Eta");
801  this->CalculateDiffFlow("RP","Pt");
802  this->CalculateDiffFlow("RP","Eta");
803  this->CalculateDiffFlow("POI","Pt");
804  this->CalculateDiffFlow("POI","Eta");
805  
806  if(fApplyCorrectionForNUA) // to be improved (reorganized, etc)
807  {
808   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Pt");
809   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Eta");
810   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Pt");
811   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Eta");      
812   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Pt");   
813   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Eta");   
814   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Pt");   
815   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Eta");  
816   this->CalculateDiffFlowCorrectedForNUA("RP","Pt"); 
817   this->CalculateDiffFlowCorrectedForNUA("RP","Eta"); 
818   this->CalculateDiffFlowCorrectedForNUA("POI","Pt"); 
819   this->CalculateDiffFlowCorrectedForNUA("POI","Eta"); 
820  }
821  
822  this->CalculateFinalResultsForRPandPOIIntegratedFlow("RP");
823  this->CalculateFinalResultsForRPandPOIIntegratedFlow("POI");
824
825  // *****************************************************************
826  // **** STORE AND PRINT THE FINAL RESULTS FOR DIFFERENTIAL FLOW ****
827  // *****************************************************************
828  this->FillCommonHistResultsDiffFlow("RP");
829  this->FillCommonHistResultsDiffFlow("POI");
830
831  if(fPrintFinalResults[1])
832  {
833   this->PrintFinalResultsForIntegratedFlow("RP"); 
834  } 
835  if(fPrintFinalResults[2])
836  {
837   this->PrintFinalResultsForIntegratedFlow("POI"); 
838  } 
839  // g) cross-check the results: results from Q-vectors vs results from nested loops
840  
841  //  g1) integrated flow:
842  if(fEvaluateIntFlowNestedLoops)
843  {
844   this->CrossCheckIntFlowCorrelations();
845   this->CrossCheckIntFlowCorrectionTermsForNUA(); 
846   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) this->CrossCheckIntFlowExtraCorrelations();     
847  } // end of if(fEvaluateIntFlowNestedLoops)  
848  
849  //  g2) differential flow: 
850  if(fEvaluateDiffFlowNestedLoops) 
851  {
852   // correlations:
853   this->PrintNumberOfParticlesInSelectedBin();
854   this->CrossCheckDiffFlowCorrelations("RP","Pt");  
855   this->CrossCheckDiffFlowCorrelations("RP","Eta"); 
856   this->CrossCheckDiffFlowCorrelations("POI","Pt");  
857   this->CrossCheckDiffFlowCorrelations("POI","Eta");
858   // correction terms for non-uniform acceptance:
859   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Pt");      
860   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Eta");       
861   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Pt");      
862   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Eta");       
863  } // end of if(fEvaluateDiffFlowNestedLoops)
864                                                                                                                                                                                                                                                                                                                                    
865 } // end of AliFlowAnalysisWithQCumulants::Finish()
866
867
868 //================================================================================================================================
869
870
871 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
872 {
873  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (cos terms)
874  
875  // multiplicity:
876  Double_t dMult = (*fSMpk)(0,0);
877  
878  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
879  Double_t dReQ1n = (*fReQ)(0,0);
880  Double_t dReQ2n = (*fReQ)(1,0);
881  //Double_t dReQ3n = (*fReQ)(2,0);
882  //Double_t dReQ4n = (*fReQ)(3,0);
883  Double_t dImQ1n = (*fImQ)(0,0);
884  Double_t dImQ2n = (*fImQ)(1,0);
885  //Double_t dImQ3n = (*fImQ)(2,0);
886  //Double_t dImQ4n = (*fImQ)(3,0);
887         
888  //                                  *************************************************************
889  //                                  **** corrections for non-uniform acceptance (cos terms): ****
890  //                                  *************************************************************
891  //
892  // Remark 1: corrections for non-uniform acceptance (cos terms) calculated with non-weighted Q-vectors 
893  //           are stored in 1D profile fQCorrectionsCos.
894  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
895  // --------------------------------------------------------------------------------------------------------------------
896  // 1st bin: <<cos(n*(phi1))>> = cosP1n
897  // 2nd bin: <<cos(n*(phi1+phi2))>> = cosP1nP1n
898  // 3rd bin: <<cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1n
899  // 4th bin: <<cos(n*(2phi1-phi2))>> = cosP2nM1n
900  // --------------------------------------------------------------------------------------------------------------------
901   
902  // 1-particle:
903  Double_t cosP1n = 0.; // <<cos(n*(phi1))>>
904    
905  if(dMult>0)
906  {
907   cosP1n = dReQ1n/dMult; 
908   
909   // average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
910   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1n);
911   
912   // final average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
913   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1n,dMult);  
914  } 
915  
916  // 2-particle:
917  Double_t cosP1nP1n = 0.; // <<cos(n*(phi1+phi2))>>
918  Double_t cosP2nM1n = 0.; // <<cos(n*(2phi1-phi2))>>
919  
920  if(dMult>1)
921  {
922   cosP1nP1n = (pow(dReQ1n,2)-pow(dImQ1n,2)-dReQ2n)/(dMult*(dMult-1)); 
923   cosP2nM1n = (dReQ2n*dReQ1n+dImQ2n*dImQ1n-dReQ1n)/(dMult*(dMult-1)); 
924   
925   // average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
926   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1n);
927   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(4,cosP2nM1n);
928   
929   // final average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
930   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1n,dMult*(dMult-1));  
931   fIntFlowCorrectionTermsForNUAPro[1]->Fill(3.5,cosP2nM1n,dMult*(dMult-1));
932  } 
933  
934  // 3-particle:
935  Double_t cosP1nM1nM1n = 0.; // <<cos(n*(phi1-phi2-phi3))>>
936  
937  if(dMult>2)
938  {
939   cosP1nM1nM1n = (dReQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))-dReQ1n*dReQ2n-dImQ1n*dImQ2n-2.*(dMult-1)*dReQ1n)
940                / (dMult*(dMult-1)*(dMult-2)); 
941   
942   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
943   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1n);
944   
945   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
946   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));  
947  } 
948  
949 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
950
951
952 //================================================================================================================================
953
954
955 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
956 {
957  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
958  
959  // multiplicity:
960  Double_t dMult = (*fSMpk)(0,0);
961  
962  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
963  Double_t dReQ1n = (*fReQ)(0,0);
964  Double_t dReQ2n = (*fReQ)(1,0);
965  //Double_t dReQ3n = (*fReQ)(2,0);
966  //Double_t dReQ4n = (*fReQ)(3,0);
967  Double_t dImQ1n = (*fImQ)(0,0);
968  Double_t dImQ2n = (*fImQ)(1,0);
969  //Double_t dImQ3n = (*fImQ)(2,0);
970  //Double_t dImQ4n = (*fImQ)(3,0);
971         
972  //                                  *************************************************************
973  //                                  **** corrections for non-uniform acceptance (sin terms): ****
974  //                                  *************************************************************
975  //
976  // Remark 1: corrections for non-uniform acceptance (sin terms) calculated with non-weighted Q-vectors 
977  //           are stored in 1D profile fQCorrectionsSin.
978  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
979  // --------------------------------------------------------------------------------------------------------------------
980  // 1st bin: <<sin(n*(phi1))>> = sinP1n
981  // 2nd bin: <<sin(n*(phi1+phi2))>> = sinP1nP1n
982  // 3rd bin: <<sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1n
983  // 4th bin: <<sin(n*(2phi1-phi2))>> = sinP2nM1n
984  // --------------------------------------------------------------------------------------------------------------------
985  
986  // 1-particle:
987  Double_t sinP1n = 0.; // <sin(n*(phi1))>
988  
989  if(dMult>0)
990  {
991   sinP1n = dImQ1n/dMult; 
992      
993   // average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
994   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1n);
995   
996   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
997   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1n,dMult);  
998  } 
999  
1000  // 2-particle:
1001  Double_t sinP1nP1n = 0.; // <<sin(n*(phi1+phi2))>>
1002  Double_t sinP2nM1n = 0.; // <<sin(n*(2phi1-phi2))>>
1003  if(dMult>1)
1004  {
1005   sinP1nP1n = (2.*dReQ1n*dImQ1n-dImQ2n)/(dMult*(dMult-1)); 
1006   sinP2nM1n = (dImQ2n*dReQ1n-dReQ2n*dImQ1n-dImQ1n)/(dMult*(dMult-1)); 
1007      
1008   // average non-weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
1009   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1n);
1010   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(4,sinP2nM1n);
1011   
1012   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
1013   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1n,dMult*(dMult-1));  
1014   fIntFlowCorrectionTermsForNUAPro[0]->Fill(3.5,sinP2nM1n,dMult*(dMult-1));  
1015  } 
1016  
1017  // 3-particle:
1018  Double_t sinP1nM1nM1n = 0.; // <<sin(n*(phi1-phi2-phi3))>>
1019  
1020  if(dMult>2)
1021  {
1022   sinP1nM1nM1n = (-dImQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))+dReQ1n*dImQ2n-dImQ1n*dReQ2n+2.*(dMult-1)*dImQ1n)
1023                / (dMult*(dMult-1)*(dMult-2)); 
1024   
1025   // average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
1026   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1n);
1027   
1028   // final average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
1029   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));  
1030  } 
1031  
1032 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
1033
1034
1035 //================================================================================================================================
1036
1037
1038 void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1039 {
1040  // a) Get pointers for common control and common result histograms and profiles.
1041  // b) Get pointers for histograms with particle weights.
1042  // c) Get pointers for histograms and profiles relevant for integrated flow.
1043  // d) Get pointers for histograms and profiles relevant for differental flow.
1044  // e) Get pointers for histograms and profiles holding results obtained with nested loops.
1045  
1046  if(outputListHistos)
1047  {      
1048   this->SetHistList(outputListHistos);
1049   if(!fHistList)
1050   {
1051    cout<<endl;
1052    cout<<" WARNING (QC): fHistList is NULL in AFAWQC::GOH() !!!!"<<endl;
1053    cout<<endl;
1054    exit(0);
1055   }
1056   this->GetPointersForCommonHistograms(); 
1057   this->GetPointersForParticleWeightsHistograms(); 
1058   this->GetPointersForIntFlowHistograms();
1059   this->GetPointersForDiffFlowHistograms(); 
1060   this->GetPointersForNestedLoopsHistograms(); 
1061  } else 
1062    {
1063     cout<<endl;
1064     cout<<" WARNING (QC): outputListHistos is NULL in AFAWQC::GOH() !!!!"<<endl;
1065     cout<<endl;
1066     exit(0);
1067    }
1068    
1069 } // end of void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1070
1071
1072 //================================================================================================================================
1073
1074
1075 TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta) const
1076 {
1077  // project 2D profile onto pt axis to get 1D profile
1078  
1079  Int_t nBinsPt   = profilePtEta->GetNbinsX();
1080  Double_t dPtMin = (profilePtEta->GetXaxis())->GetXmin();
1081  Double_t dPtMax = (profilePtEta->GetXaxis())->GetXmax();
1082  
1083  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1084  
1085  TProfile *profilePt = new TProfile("","",nBinsPt,dPtMin,dPtMax); 
1086  
1087  for(Int_t p=1;p<=nBinsPt;p++)
1088  {
1089   Double_t contentPt = 0.;
1090   Double_t entryPt = 0.;
1091   Double_t spreadPt = 0.;
1092   Double_t sum1 = 0.;
1093   Double_t sum2 = 0.;
1094   Double_t sum3 = 0.;
1095   for(Int_t e=1;e<=nBinsEta;e++)
1096   {
1097    contentPt += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1098               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1099    entryPt   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1100    
1101    sum1 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1102          * (pow(profilePtEta->GetBinError(profilePtEta->GetBin(p,e)),2.)
1103             + pow(profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)),2.)); 
1104    sum2 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1105    sum3 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1106          * (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)));            
1107   }
1108   if(sum2>0. && sum1/sum2-pow(sum3/sum2,2.) > 0.)
1109   {
1110    spreadPt = pow(sum1/sum2-pow(sum3/sum2,2.),0.5);
1111   }
1112   profilePt->SetBinContent(p,contentPt);
1113   profilePt->SetBinEntries(p,entryPt);
1114   {
1115    profilePt->SetBinError(p,spreadPt);
1116   }
1117   
1118  }
1119  
1120  return profilePt;
1121  
1122 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta)
1123
1124
1125 //================================================================================================================================
1126
1127
1128 TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta) const
1129 {
1130  // project 2D profile onto eta axis to get 1D profile
1131  
1132  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1133  Double_t dEtaMin = (profilePtEta->GetYaxis())->GetXmin();
1134  Double_t dEtaMax = (profilePtEta->GetYaxis())->GetXmax();
1135  
1136  Int_t nBinsPt = profilePtEta->GetNbinsX();
1137  
1138  TProfile *profileEta = new TProfile("","",nBinsEta,dEtaMin,dEtaMax); 
1139  
1140  for(Int_t e=1;e<=nBinsEta;e++)
1141  {
1142   Double_t contentEta = 0.;
1143   Double_t entryEta = 0.;
1144   for(Int_t p=1;p<=nBinsPt;p++)
1145   {
1146    contentEta += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1147               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1148    entryEta   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1149   }
1150   profileEta->SetBinContent(e,contentEta);
1151   profileEta->SetBinEntries(e,entryEta);
1152  }
1153  
1154  return profileEta;
1155  
1156 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta)
1157
1158
1159 //================================================================================================================================
1160
1161
1162 void AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type)
1163 {
1164  // printing on the screen the final results for integrated flow (NONAME, POI and RP) // to be improved (NONAME) 
1165  
1166  Int_t n = fHarmonic; 
1167  
1168  if(type == "NONAME" || type == "RP" || type == "POI")
1169  {
1170   if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
1171   {
1172    cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl;
1173    cout<<"         is NULL in AFAWQC::PFRFIF() !!!!"<<endl;
1174   }
1175  } else
1176    {
1177     cout<<"WARNING: type in not from {NONAME, RP, POI} in AFAWQC::PFRFIF() !!!!"<<endl;
1178     exit(0);
1179    }
1180  
1181  Double_t dVn[4] = {0.}; // array to hold Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1182  Double_t dVnErr[4] = {0.}; // array to hold errors of Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1183  
1184  if(type == "NONAME")
1185  {
1186   dVn[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinContent(1); 
1187   dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinError(1); 
1188   dVn[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinContent(1); 
1189   dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinError(1); 
1190   dVn[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinContent(1); 
1191   dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinError(1); 
1192   dVn[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinContent(1); 
1193   dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinError(1); 
1194  } else if(type == "RP")
1195    {
1196     dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinContent(1); 
1197     dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinError(1); 
1198     dVn[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinContent(1); 
1199     dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinError(1); 
1200     dVn[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinContent(1); 
1201     dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinError(1); 
1202     dVn[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinContent(1); 
1203     dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinError(1); 
1204    } else if(type == "POI")
1205      {
1206       dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinContent(1); 
1207       dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinError(1); 
1208       dVn[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinContent(1); 
1209       dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinError(1); 
1210       dVn[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinContent(1); 
1211       dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinError(1); 
1212       dVn[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinContent(1); 
1213       dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinError(1); 
1214      }
1215  
1216  TString title = " flow estimates from Q-cumulants"; 
1217  TString subtitle = "    ("; 
1218  
1219  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
1220  {
1221   subtitle.Append(type);
1222   subtitle.Append(", without weights)");
1223  } else  
1224    {
1225     subtitle.Append(type);
1226     subtitle.Append(", with weights)");
1227    }
1228   
1229  cout<<endl;
1230  cout<<"*************************************"<<endl;
1231  cout<<"*************************************"<<endl;
1232  cout<<title.Data()<<endl; 
1233  cout<<subtitle.Data()<<endl; 
1234  cout<<endl;
1235   
1236  for(Int_t i=0;i<4;i++)
1237  {
1238   if(dVn[i]>=0.)
1239   {
1240    cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = "<<dVn[i]<<" +/- "<<dVnErr[i]<<endl;
1241   }
1242   else
1243   {
1244    cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = Im"<<endl;
1245   }  
1246  }
1247
1248  cout<<endl;
1249  /*
1250  if(type == "NONAME")
1251  {
1252   cout<<"     nEvts = "<<nEvtsNoName<<", AvM = "<<dMultNoName<<endl; // to be improved
1253  }
1254  else if (type == "RP")
1255  {
1256   cout<<"     nEvts = "<<nEvtsRP<<", AvM = "<<dMultRP<<endl; // to be improved  
1257  } 
1258  else if (type == "POI")
1259  {
1260   cout<<"     nEvts = "<<nEvtsPOI<<", AvM = "<<dMultPOI<<endl; // to be improved  
1261  } 
1262  */
1263  cout<<"*************************************"<<endl;
1264  cout<<"*************************************"<<endl;
1265  cout<<endl; 
1266   
1267 }// end of AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type="NONAME");
1268
1269
1270 //================================================================================================================================
1271
1272
1273 void AliFlowAnalysisWithQCumulants::WriteHistograms(TString outputFileName)
1274 {
1275  //store the final results in output .root file
1276  TFile *output = new TFile(outputFileName.Data(),"RECREATE");
1277  //output->WriteObject(fHistList, "cobjQC","SingleKey");
1278  fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
1279  delete output;
1280 }
1281
1282
1283 //================================================================================================================================
1284
1285
1286 void AliFlowAnalysisWithQCumulants::WriteHistograms(TDirectoryFile *outputFileName)
1287 {
1288  //store the final results in output .root file
1289  fHistList->SetName("cobjQC");
1290  fHistList->SetOwner(kTRUE);
1291  outputFileName->Add(fHistList);
1292  outputFileName->Write(outputFileName->GetName(), TObject::kSingleKey);
1293 }
1294
1295
1296 //================================================================================================================================
1297
1298
1299 void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1300 {
1301  // Book common control histograms and common histograms for final results.
1302  // common control histogram (ALL events)
1303  TString commonHistsName = "AliFlowCommonHistQC";
1304  commonHistsName += fAnalysisLabel->Data();
1305  fCommonHists = new AliFlowCommonHist(commonHistsName.Data());
1306  fHistList->Add(fCommonHists);  
1307  // common control histogram (for events with 2 and more particles)
1308  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
1309  commonHists2ndOrderName += fAnalysisLabel->Data();
1310  fCommonHists2nd = new AliFlowCommonHist(commonHists2ndOrderName.Data());
1311  fHistList->Add(fCommonHists2nd);  
1312  // common control histogram (for events with 4 and more particles)
1313  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
1314  commonHists4thOrderName += fAnalysisLabel->Data();
1315  fCommonHists4th = new AliFlowCommonHist(commonHists4thOrderName.Data());
1316  fHistList->Add(fCommonHists4th);  
1317  // common control histogram (for events with 6 and more particles)
1318  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
1319  commonHists6thOrderName += fAnalysisLabel->Data();
1320  fCommonHists6th = new AliFlowCommonHist(commonHists6thOrderName.Data());
1321  fHistList->Add(fCommonHists6th);  
1322  // common control histogram (for events with 8 and more particles)
1323  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
1324  commonHists8thOrderName += fAnalysisLabel->Data();
1325  fCommonHists8th = new AliFlowCommonHist(commonHists8thOrderName.Data());
1326  fHistList->Add(fCommonHists8th);    
1327  // common histograms for final results (calculated for events with 2 and more particles)
1328  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC";
1329  commonHistResults2ndOrderName += fAnalysisLabel->Data();
1330  fCommonHistsResults2nd = new AliFlowCommonHistResults(commonHistResults2ndOrderName.Data());
1331  fHistList->Add(fCommonHistsResults2nd);  
1332  // common histograms for final results (calculated for events with 4 and more particles)
1333  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
1334  commonHistResults4thOrderName += fAnalysisLabel->Data();
1335  fCommonHistsResults4th = new AliFlowCommonHistResults(commonHistResults4thOrderName.Data());
1336  fHistList->Add(fCommonHistsResults4th); 
1337  // common histograms for final results (calculated for events with 6 and more particles)
1338  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
1339  commonHistResults6thOrderName += fAnalysisLabel->Data();
1340  fCommonHistsResults6th = new AliFlowCommonHistResults(commonHistResults6thOrderName.Data());
1341  fHistList->Add(fCommonHistsResults6th);  
1342  // common histograms for final results (calculated for events with 8 and more particles)
1343  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
1344  commonHistResults8thOrderName += fAnalysisLabel->Data();
1345  fCommonHistsResults8th = new AliFlowCommonHistResults(commonHistResults8thOrderName.Data());
1346  fHistList->Add(fCommonHistsResults8th); 
1347  
1348 } // end of void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1349
1350
1351 //================================================================================================================================
1352
1353
1354 void AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1355 {
1356  // book and fill histograms which hold phi, pt and eta weights
1357
1358  if(!fWeightsList)
1359  {
1360   cout<<"WARNING: fWeightsList is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1361   exit(0);  
1362  }
1363     
1364  TString fUseParticleWeightsName = "fUseParticleWeightsQC";
1365  fUseParticleWeightsName += fAnalysisLabel->Data();
1366  fUseParticleWeights = new TProfile(fUseParticleWeightsName.Data(),"0 = particle weight not used, 1 = particle weight used ",3,0,3);
1367  fUseParticleWeights->SetLabelSize(0.06);
1368  (fUseParticleWeights->GetXaxis())->SetBinLabel(1,"w_{#phi}");
1369  (fUseParticleWeights->GetXaxis())->SetBinLabel(2,"w_{p_{T}}");
1370  (fUseParticleWeights->GetXaxis())->SetBinLabel(3,"w_{#eta}");
1371  fUseParticleWeights->Fill(0.5,(Int_t)fUsePhiWeights);
1372  fUseParticleWeights->Fill(1.5,(Int_t)fUsePtWeights);
1373  fUseParticleWeights->Fill(2.5,(Int_t)fUseEtaWeights);
1374  fWeightsList->Add(fUseParticleWeights); 
1375   
1376  if(fUsePhiWeights)
1377  {
1378   if(fWeightsList->FindObject("phi_weights"))
1379   {
1380    fPhiWeights = dynamic_cast<TH1F*>(fWeightsList->FindObject("phi_weights"));
1381    if(TMath::Abs(fPhiWeights->GetBinWidth(1)-fPhiBinWidth)>pow(10.,-6.))
1382    {
1383     cout<<endl;
1384     cout<<"WARNING (QC): Inconsistent binning in histograms for phi-weights throughout the code."<<endl;
1385     cout<<endl;
1386     exit(0);
1387    }
1388   } else 
1389     {
1390      cout<<"WARNING: fWeightsList->FindObject(\"phi_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1391      exit(0);
1392     }
1393  } // end of if(fUsePhiWeights)
1394  
1395  if(fUsePtWeights) 
1396  {
1397   if(fWeightsList->FindObject("pt_weights"))
1398   {
1399    fPtWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("pt_weights"));
1400    if(TMath::Abs(fPtWeights->GetBinWidth(1)-fPtBinWidth)>pow(10.,-6.))
1401    {
1402     cout<<endl;
1403     cout<<"WARNING (QC): Inconsistent binning in histograms for pt-weights throughout the code."<<endl;
1404     cout<<endl;
1405     exit(0);
1406    }
1407   } else 
1408     {
1409      cout<<"WARNING: fWeightsList->FindObject(\"pt_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1410      exit(0);
1411     }
1412  } // end of if(fUsePtWeights)    
1413
1414  if(fUseEtaWeights) 
1415  {
1416   if(fWeightsList->FindObject("eta_weights"))
1417   {
1418    fEtaWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("eta_weights"));
1419    if(TMath::Abs(fEtaWeights->GetBinWidth(1)-fEtaBinWidth)>pow(10.,-6.))
1420    {
1421     cout<<endl;
1422     cout<<"WARNING (QC): Inconsistent binning in histograms for eta-weights throughout the code."<<endl;
1423     cout<<endl;
1424     exit(0);
1425    }
1426   } else 
1427     {
1428      cout<<"WARNING: fUseEtaWeights && fWeightsList->FindObject(\"eta_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1429      exit(0);
1430     }
1431  } // end of if(fUseEtaWeights)
1432  
1433 } // end of AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1434
1435
1436 //================================================================================================================================
1437
1438
1439 void AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
1440 {
1441  // Book all objects for integrated flow:
1442  //  a) Book profile to hold all flags for integrated flow.
1443  //  b) Book event-by-event quantities.
1444  //  c) Book profiles. // to be improved (comment)
1445  //  d) Book histograms holding the final results.
1446  
1447  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
1448  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data members?)
1449  
1450  // a) Book profile to hold all flags for integrated flow:
1451  TString intFlowFlagsName = "fIntFlowFlags";
1452  intFlowFlagsName += fAnalysisLabel->Data();
1453  fIntFlowFlags = new TProfile(intFlowFlagsName.Data(),"Flags for Integrated Flow",6,0,6);
1454  fIntFlowFlags->SetTickLength(-0.01,"Y");
1455  fIntFlowFlags->SetMarkerStyle(25);
1456  fIntFlowFlags->SetLabelSize(0.05);
1457  fIntFlowFlags->SetLabelOffset(0.02,"Y");
1458  fIntFlowFlags->GetXaxis()->SetBinLabel(1,"Particle Weights");
1459  fIntFlowFlags->GetXaxis()->SetBinLabel(2,"Event Weights");
1460  fIntFlowFlags->GetXaxis()->SetBinLabel(3,"Corrected for NUA?");
1461  fIntFlowFlags->GetXaxis()->SetBinLabel(4,"Print NONAME results");
1462  fIntFlowFlags->GetXaxis()->SetBinLabel(5,"Print RP results");
1463  fIntFlowFlags->GetXaxis()->SetBinLabel(6,"Print POI results");
1464  fIntFlowList->Add(fIntFlowFlags);
1465
1466  // b) Book event-by-event quantities:
1467  // Re[Q_{m*n,k}], Im[Q_{m*n,k}] and S_{p,k}^M: 
1468  fReQ  = new TMatrixD(4,9);
1469  fImQ  = new TMatrixD(4,9);
1470  fSMpk = new TMatrixD(8,9);
1471  // average correlations <2>, <4>, <6> and <8> for single event (bining is the same as in fIntFlowCorrelationsPro and fIntFlowCorrelationsHist):
1472  TString intFlowCorrelationsEBEName = "fIntFlowCorrelationsEBE";
1473  intFlowCorrelationsEBEName += fAnalysisLabel->Data();
1474  fIntFlowCorrelationsEBE = new TH1D(intFlowCorrelationsEBEName.Data(),intFlowCorrelationsEBEName.Data(),4,0,4);
1475  // weights for average correlations <2>, <4>, <6> and <8> for single event:
1476  TString intFlowEventWeightsForCorrelationsEBEName = "fIntFlowEventWeightsForCorrelationsEBE";
1477  intFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
1478  fIntFlowEventWeightsForCorrelationsEBE = new TH1D(intFlowEventWeightsForCorrelationsEBEName.Data(),intFlowEventWeightsForCorrelationsEBEName.Data(),4,0,4);
1479  // average all correlations for single event (bining is the same as in fIntFlowCorrelationsAllPro and fIntFlowCorrelationsAllHist):
1480  TString intFlowCorrelationsAllEBEName = "fIntFlowCorrelationsAllEBE";
1481  intFlowCorrelationsAllEBEName += fAnalysisLabel->Data();
1482  fIntFlowCorrelationsAllEBE = new TH1D(intFlowCorrelationsAllEBEName.Data(),intFlowCorrelationsAllEBEName.Data(),32,0,32);
1483  // average correction terms for non-uniform acceptance for single event 
1484  // (binning is the same as in fIntFlowCorrectionTermsForNUAPro[2] and fIntFlowCorrectionTermsForNUAHist[2]):
1485  TString fIntFlowCorrectionTermsForNUAEBEName = "fIntFlowCorrectionTermsForNUAEBE";
1486  fIntFlowCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1487  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1488  {
1489   fIntFlowCorrectionTermsForNUAEBE[sc] = new TH1D(Form("%s: %s terms",fIntFlowCorrectionTermsForNUAEBEName.Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),10,0,10);  
1490  }
1491  
1492  // c) Book profiles: // to be improved (comment)
1493  // profile to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8:
1494  TString avMultiplicityName = "fAvMultiplicity";
1495  avMultiplicityName += fAnalysisLabel->Data();
1496  fAvMultiplicity = new TProfile(avMultiplicityName.Data(),"Average Multiplicities of RPs",9,0,9);
1497  fAvMultiplicity->SetTickLength(-0.01,"Y");
1498  fAvMultiplicity->SetMarkerStyle(25);
1499  fAvMultiplicity->SetLabelSize(0.05);
1500  fAvMultiplicity->SetLabelOffset(0.02,"Y");
1501  fAvMultiplicity->SetYTitle("Average Multiplicity");
1502  (fAvMultiplicity->GetXaxis())->SetBinLabel(1,"all evts");
1503  (fAvMultiplicity->GetXaxis())->SetBinLabel(2,"n_{RP} #geq 1");
1504  (fAvMultiplicity->GetXaxis())->SetBinLabel(3,"n_{RP} #geq 2");
1505  (fAvMultiplicity->GetXaxis())->SetBinLabel(4,"n_{RP} #geq 3");
1506  (fAvMultiplicity->GetXaxis())->SetBinLabel(5,"n_{RP} #geq 4");
1507  (fAvMultiplicity->GetXaxis())->SetBinLabel(6,"n_{RP} #geq 5");
1508  (fAvMultiplicity->GetXaxis())->SetBinLabel(7,"n_{RP} #geq 6");
1509  (fAvMultiplicity->GetXaxis())->SetBinLabel(8,"n_{RP} #geq 7");
1510  (fAvMultiplicity->GetXaxis())->SetBinLabel(9,"n_{RP} #geq 8");
1511  fIntFlowProfiles->Add(fAvMultiplicity);
1512  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with wrong errors!):
1513  TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
1514  intFlowCorrelationsProName += fAnalysisLabel->Data();
1515  fIntFlowCorrelationsPro = new TProfile(intFlowCorrelationsProName.Data(),"Average correlations for all events",4,0,4,"s");
1516  fIntFlowCorrelationsPro->SetTickLength(-0.01,"Y");
1517  fIntFlowCorrelationsPro->SetMarkerStyle(25);
1518  fIntFlowCorrelationsPro->SetLabelSize(0.06);
1519  fIntFlowCorrelationsPro->SetLabelOffset(0.01,"Y");
1520  (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(1,"<<2>>");
1521  (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(2,"<<4>>");
1522  (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(3,"<<6>>");
1523  (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(4,"<<8>>");
1524  fIntFlowProfiles->Add(fIntFlowCorrelationsPro);
1525  // averaged all correlations for all events (with wrong errors!):
1526  TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
1527  intFlowCorrelationsAllProName += fAnalysisLabel->Data();
1528  fIntFlowCorrelationsAllPro = new TProfile(intFlowCorrelationsAllProName.Data(),"Average correlations for all events",32,0,32,"s");
1529  fIntFlowCorrelationsAllPro->SetTickLength(-0.01,"Y");
1530  fIntFlowCorrelationsAllPro->SetMarkerStyle(25);
1531  fIntFlowCorrelationsAllPro->SetLabelSize(0.03);
1532  fIntFlowCorrelationsAllPro->SetLabelOffset(0.01,"Y");
1533  // 2-p correlations:
1534  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1535  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1536  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1537  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1538  // 3-p correlations:
1539  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1540  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1541  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1542  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1543  // 4-p correlations:
1544  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1545  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1546  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1547  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1548  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1549  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1550  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1551  // 5-p correlations:
1552  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1553  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1554  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1555  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1556  // 6-p correlations:
1557  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1558  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1559  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1560  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1561  // 7-p correlations:  
1562  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1563  // 8-p correlations:
1564  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1565  fIntFlowProfiles->Add(fIntFlowCorrelationsAllPro);
1566  // when particle weights are used some extra correlations appear:
1567  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) 
1568  {
1569   TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
1570   intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
1571   fIntFlowExtraCorrelationsPro = new TProfile(intFlowExtraCorrelationsProName.Data(),"Average extra correlations for all events",100,0,100,"s");
1572   fIntFlowExtraCorrelationsPro->SetTickLength(-0.01,"Y");
1573   fIntFlowExtraCorrelationsPro->SetMarkerStyle(25);
1574   fIntFlowExtraCorrelationsPro->SetLabelSize(0.03);
1575   fIntFlowExtraCorrelationsPro->SetLabelOffset(0.01,"Y");
1576   // extra 2-p correlations:
1577   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(1,"<<w1^3 w2 cos(n*(phi1-phi2))>>");
1578   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(2,"<<w1 w2 w3^2 cos(n*(phi1-phi2))>>");
1579   fIntFlowProfiles->Add(fIntFlowExtraCorrelationsPro);
1580  } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
1581  // average product of correlations <2>, <4>, <6> and <8>:  
1582  TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
1583  intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
1584  fIntFlowProductOfCorrelationsPro = new TProfile(intFlowProductOfCorrelationsProName.Data(),"Average products of correlations",6,0,6);
1585  fIntFlowProductOfCorrelationsPro->SetTickLength(-0.01,"Y");
1586  fIntFlowProductOfCorrelationsPro->SetMarkerStyle(25); 
1587  fIntFlowProductOfCorrelationsPro->SetLabelSize(0.05);
1588  fIntFlowProductOfCorrelationsPro->SetLabelOffset(0.01,"Y");
1589  (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(1,"<<2><4>>");
1590  (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(2,"<<2><6>>");
1591  (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(3,"<<2><8>>");
1592  (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(4,"<<4><6>>");
1593  (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(5,"<<4><8>>");
1594  (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(6,"<<6><8>>");
1595  fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsPro);
1596  // average correction terms for non-uniform acceptance (with wrong errors!):
1597  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1598  {
1599   TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
1600   intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
1601   fIntFlowCorrectionTermsForNUAPro[sc] = new TProfile(Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),10,0,10,"s");
1602   fIntFlowCorrectionTermsForNUAPro[sc]->SetTickLength(-0.01,"Y");
1603   fIntFlowCorrectionTermsForNUAPro[sc]->SetMarkerStyle(25);
1604   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelSize(0.03);
1605   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelOffset(0.01,"Y");
1606   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(1,Form("<<%s(n(phi1))>>",sinCosFlag[sc].Data()));
1607   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(2,Form("<<%s(n(phi1+phi2))>>",sinCosFlag[sc].Data()));  
1608   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(3,Form("<<%s(n(phi1-phi2-phi3))>>",sinCosFlag[sc].Data()));  
1609   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(4,Form("<<%s(n(2phi1-phi2))>>",sinCosFlag[sc].Data()));  
1610   fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAPro[sc]);
1611  } // end of for(Int_t sc=0;sc<2;sc++) 
1612  
1613  // d) Book histograms holding the final results:
1614  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!):
1615  TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
1616  intFlowCorrelationsHistName += fAnalysisLabel->Data();
1617  fIntFlowCorrelationsHist = new TH1D(intFlowCorrelationsHistName.Data(),"Average correlations for all events",4,0,4);
1618  fIntFlowCorrelationsHist->SetTickLength(-0.01,"Y");
1619  fIntFlowCorrelationsHist->SetMarkerStyle(25);
1620  fIntFlowCorrelationsHist->SetLabelSize(0.06);
1621  fIntFlowCorrelationsHist->SetLabelOffset(0.01,"Y");
1622  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(1,"<<2>>");
1623  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(2,"<<4>>");
1624  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(3,"<<6>>");
1625  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(4,"<<8>>");
1626  fIntFlowResults->Add(fIntFlowCorrelationsHist);
1627  // average all correlations for all events (with correct errors!):
1628  TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
1629  intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
1630  fIntFlowCorrelationsAllHist = new TH1D(intFlowCorrelationsAllHistName.Data(),"Average correlations for all events",32,0,32);
1631  fIntFlowCorrelationsAllHist->SetTickLength(-0.01,"Y");
1632  fIntFlowCorrelationsAllHist->SetMarkerStyle(25);
1633  fIntFlowCorrelationsAllHist->SetLabelSize(0.03);
1634  fIntFlowCorrelationsAllHist->SetLabelOffset(0.01,"Y");
1635  // 2-p correlations:
1636  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1637  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1638  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1639  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1640  // 3-p correlations:
1641  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1642  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1643  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1644  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1645  // 4-p correlations:
1646  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1647  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1648  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1649  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1650  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1651  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1652  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1653  // 5-p correlations:
1654  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1655  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1656  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1657  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1658  // 6-p correlations:
1659  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1660  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1661  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1662  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1663  // 7-p correlations:  
1664  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1665  // 8-p correlations:
1666  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1667  fIntFlowResults->Add(fIntFlowCorrelationsAllHist);
1668  // average correction terms for non-uniform acceptance (with correct errors!):
1669  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1670  {
1671   TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
1672   intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
1673   fIntFlowCorrectionTermsForNUAHist[sc] = new TH1D(Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),10,0,10);
1674   fIntFlowCorrectionTermsForNUAHist[sc]->SetTickLength(-0.01,"Y");
1675   fIntFlowCorrectionTermsForNUAHist[sc]->SetMarkerStyle(25);
1676   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelSize(0.03);
1677   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelOffset(0.01,"Y");
1678   // ......................................................................... 
1679   // 1-p terms:
1680   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(1,Form("%s(n(#phi_{1}))>",sinCosFlag[sc].Data()));
1681   // 2-p terms:
1682   // 3-p terms:
1683   // ...
1684   // ......................................................................... 
1685   fIntFlowResults->Add(fIntFlowCorrectionTermsForNUAHist[sc]);
1686  } // end of for(Int_t sc=0;sc<2;sc++) 
1687  // covariances (multiplied with weight dependent prefactor):
1688  TString intFlowCovariancesName = "fIntFlowCovariances";
1689  intFlowCovariancesName += fAnalysisLabel->Data();
1690  fIntFlowCovariances = new TH1D(intFlowCovariancesName.Data(),"Covariances (multiplied with weight dependent prefactor)",6,0,6);
1691  fIntFlowCovariances->SetLabelSize(0.04);
1692  fIntFlowCovariances->SetMarkerStyle(25);
1693  (fIntFlowCovariances->GetXaxis())->SetBinLabel(1,"Cov(<2>,<4>)");
1694  (fIntFlowCovariances->GetXaxis())->SetBinLabel(2,"Cov(<2>,<6>)");
1695  (fIntFlowCovariances->GetXaxis())->SetBinLabel(3,"Cov(<2>,<8>)");
1696  (fIntFlowCovariances->GetXaxis())->SetBinLabel(4,"Cov(<4>,<6>)");
1697  (fIntFlowCovariances->GetXaxis())->SetBinLabel(5,"Cov(<4>,<8>)");
1698  (fIntFlowCovariances->GetXaxis())->SetBinLabel(6,"Cov(<6>,<8>)");  
1699  fIntFlowResults->Add(fIntFlowCovariances);
1700  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
1701  TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
1702  intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
1703  for(Int_t power=0;power<2;power++)
1704  {
1705   fIntFlowSumOfEventWeights[power] = new TH1D(Form("%s: %s",intFlowSumOfEventWeightsName.Data(),powerFlag[power].Data()),Form("Sum of %s event weights for correlations",powerFlag[power].Data()),4,0,4);
1706   fIntFlowSumOfEventWeights[power]->SetLabelSize(0.05);
1707   fIntFlowSumOfEventWeights[power]->SetMarkerStyle(25);
1708   if(power == 0)
1709   {
1710    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}");
1711    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}");
1712    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}");
1713    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}");
1714   } else if (power == 1) 
1715     {
1716      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}^{2}");
1717      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}^{2}");
1718      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}^{2}");
1719      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}^{2}");
1720     }
1721   fIntFlowResults->Add(fIntFlowSumOfEventWeights[power]);
1722  } 
1723  // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
1724  TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
1725  intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
1726  fIntFlowSumOfProductOfEventWeights = new TH1D(intFlowSumOfProductOfEventWeightsName.Data(),"Sum of product of event weights for correlations",6,0,6);
1727  fIntFlowSumOfProductOfEventWeights->SetLabelSize(0.05);
1728  fIntFlowSumOfProductOfEventWeights->SetMarkerStyle(25);
1729  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<4>}");
1730  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<6>}");
1731  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<2>} w_{<8>}");
1732  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<4>} w_{<6>}");
1733  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(5,"#sum_{i=1}^{N} w_{<4>} w_{<8>}");
1734  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(6,"#sum_{i=1}^{N} w_{<6>} w_{<8>}");
1735  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeights);
1736  // final results for integrated Q-cumulants:
1737  TString intFlowQcumulantsName = "fIntFlowQcumulants";
1738  intFlowQcumulantsName += fAnalysisLabel->Data();
1739  fIntFlowQcumulants = new TH1D(intFlowQcumulantsName.Data(),"Integrated Q-cumulants",4,0,4);
1740  fIntFlowQcumulants->SetLabelSize(0.05);
1741  fIntFlowQcumulants->SetMarkerStyle(25);
1742  (fIntFlowQcumulants->GetXaxis())->SetBinLabel(1,"QC{2}");
1743  (fIntFlowQcumulants->GetXaxis())->SetBinLabel(2,"QC{4}");
1744  (fIntFlowQcumulants->GetXaxis())->SetBinLabel(3,"QC{6}");
1745  (fIntFlowQcumulants->GetXaxis())->SetBinLabel(4,"QC{8}");
1746  fIntFlowResults->Add(fIntFlowQcumulants);
1747  // final integrated flow estimates from Q-cumulants:
1748  TString intFlowName = "fIntFlow";
1749  intFlowName += fAnalysisLabel->Data();  
1750  // integrated flow from Q-cumulants:
1751  fIntFlow = new TH1D(intFlowName.Data(),"Integrated flow estimates from Q-cumulants",4,0,4);
1752  fIntFlow->SetLabelSize(0.05);
1753  fIntFlow->SetMarkerStyle(25);
1754  (fIntFlow->GetXaxis())->SetBinLabel(1,"v_{2}{2,QC}");
1755  (fIntFlow->GetXaxis())->SetBinLabel(2,"v_{2}{4,QC}");
1756  (fIntFlow->GetXaxis())->SetBinLabel(3,"v_{2}{6,QC}");
1757  (fIntFlow->GetXaxis())->SetBinLabel(4,"v_{2}{8,QC}");
1758  fIntFlowResults->Add(fIntFlow);
1759
1760  /* // to be improved (removed):
1761   // final average weighted multi-particle correlations for all events calculated from Q-vectors
1762   fQCorrelations[1] = new TProfile("Weighted correlations","final average multi-particle correlations from weighted Q-vectors",200,0,200,"s");
1763   fQCorrelations[1]->SetTickLength(-0.01,"Y");
1764   fQCorrelations[1]->SetMarkerStyle(25);
1765   fQCorrelations[1]->SetLabelSize(0.03);
1766   fQCorrelations[1]->SetLabelOffset(0.01,"Y");
1767   // 2-particle correlations:
1768   (fQCorrelations[1]->GetXaxis())->SetBinLabel(1,"<w_{1}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
1769   (fQCorrelations[1]->GetXaxis())->SetBinLabel(2,"<w_{1}^{2}w_{2}^{2}cos(2n(#phi_{1}-#phi_{2}))>");
1770   (fQCorrelations[1]->GetXaxis())->SetBinLabel(3,"<w_{1}^{3}w_{2}^{3}cos(3n(#phi_{1}-#phi_{2}))>");
1771   (fQCorrelations[1]->GetXaxis())->SetBinLabel(4,"<w_{1}^{4}w_{2}^{4}cos(4n(#phi_{1}-#phi_{2}))>");
1772   (fQCorrelations[1]->GetXaxis())->SetBinLabel(5,"<w_{1}^{3}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
1773   (fQCorrelations[1]->GetXaxis())->SetBinLabel(6,"<w_{1}^{2}w_{2}w_{3}cos(n(#phi_{1}-#phi_{2}))>");
1774   // 3-particle correlations:
1775   (fQCorrelations[1]->GetXaxis())->SetBinLabel(21,"<w_{1}w_{2}w_{3}^{2}cos(n(2#phi_{1}-#phi_{2}-#phi_{3}))>");
1776   // 4-particle correlations:
1777   (fQCorrelations[1]->GetXaxis())->SetBinLabel(41,"<w_{1}w_{2}w_{3}w_{4}cos(n(#phi_{1}+#phi_{2}-#phi_{3}-#phi_{4}))>");
1778   // add fQCorrelations[1] to the list fIntFlowList:
1779   fIntFlowList->Add(fQCorrelations[1]); 
1780  */
1781   
1782 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
1783
1784
1785 //================================================================================================================================
1786
1787
1788 void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
1789 {
1790  // Initialize arrays of all objects relevant for calculations with nested loops.
1791  
1792  // integrated flow:
1793  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1794  {
1795   fIntFlowDirectCorrectionTermsForNUA[sc] = NULL;
1796  } 
1797
1798  // differential flow:  
1799  // correlations:
1800  for(Int_t t=0;t<2;t++) // type: RP or POI
1801  { 
1802   for(Int_t pe=0;pe<2;pe++) // pt or eta
1803   {
1804    for(Int_t ci=0;ci<4;ci++) // correlation index
1805    {
1806     fDiffFlowDirectCorrelations[t][pe][ci] = NULL;
1807    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
1808   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
1809  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
1810  // correction terms for non-uniform acceptance:
1811  for(Int_t t=0;t<2;t++) // type: RP or POI
1812  { 
1813   for(Int_t pe=0;pe<2;pe++) // pt or eta
1814   {
1815    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1816    {
1817     for(Int_t cti=0;cti<9;cti++) // correction term index
1818     {
1819      fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] = NULL;
1820     }   
1821    }
1822   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
1823  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
1824
1825
1826 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
1827
1828
1829 //================================================================================================================================
1830
1831
1832 void AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
1833 {
1834  // Book all objects relevant for calculations with nested loops.
1835  
1836  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
1837  TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
1838  TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
1839  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
1840  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
1841  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
1842
1843  TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
1844  evaluateNestedLoopsName += fAnalysisLabel->Data();
1845  fEvaluateNestedLoops = new TProfile(evaluateNestedLoopsName.Data(),"Flags for nested loops",4,0,4);
1846  fEvaluateNestedLoops->SetLabelSize(0.03);
1847  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(1,"fEvaluateIntFlowNestedLoops");
1848  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(2,"fEvaluateDiffFlowNestedLoops");
1849  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(3,"fCrossCheckInPtBinNo");
1850  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(4,"fCrossCheckInEtaBinNo");
1851  fEvaluateNestedLoops->Fill(0.5,(Int_t)fEvaluateIntFlowNestedLoops);
1852  fEvaluateNestedLoops->Fill(1.5,(Int_t)fEvaluateDiffFlowNestedLoops);
1853  fEvaluateNestedLoops->Fill(2.5,fCrossCheckInPtBinNo);
1854  fEvaluateNestedLoops->Fill(3.5,fCrossCheckInEtaBinNo);
1855  fNestedLoopsList->Add(fEvaluateNestedLoops);
1856  // nested loops for integrated flow:
1857  if(fEvaluateIntFlowNestedLoops)
1858  {
1859   // correlations:
1860   TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
1861   intFlowDirectCorrelationsName += fAnalysisLabel->Data();
1862   fIntFlowDirectCorrelations = new TProfile(intFlowDirectCorrelationsName.Data(),"Multiparticle correlations calculated with nested loops (for int. flow)",32,0,32,"s");
1863   fNestedLoopsList->Add(fIntFlowDirectCorrelations);
1864   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
1865   {
1866    TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
1867    intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
1868    fIntFlowExtraDirectCorrelations = new TProfile(intFlowExtraDirectCorrelationsName.Data(),"Extra multiparticle correlations calculated with nested loops (for int. flow)",100,0,100,"s");
1869    fNestedLoopsList->Add(fIntFlowExtraDirectCorrelations);  
1870   } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
1871   // correction terms for non-uniform acceptance:
1872   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1873   {
1874    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
1875    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
1876    fIntFlowDirectCorrectionTermsForNUA[sc] = new TProfile(Form("%s: %s terms",intFlowDirectCorrectionTermsForNUAName.Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),10,0,10,"s");
1877    fNestedLoopsList->Add(fIntFlowDirectCorrectionTermsForNUA[sc]);
1878   } // end of for(Int_t sc=0;sc<2;sc++) 
1879  } // end of if(fEvaluateIntFlowNestedLoops)
1880  
1881  // nested loops for differential flow: 
1882  if(fEvaluateDiffFlowNestedLoops)
1883  {
1884   // reduced correlations:
1885   TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
1886   diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
1887   for(Int_t t=0;t<2;t++) // type: RP or POI
1888   { 
1889    for(Int_t pe=0;pe<2;pe++) // pt or eta
1890    {
1891     for(Int_t rci=0;rci<4;rci++) // reduced correlation index
1892     {
1893      // reduced correlations:
1894      fDiffFlowDirectCorrelations[t][pe][rci] = new TProfile(Form("%s, %s, %s, %s",diffFlowDirectCorrelationsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),Form("%s, %s, %s, %s",diffFlowDirectCorrelationsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),1,lowerPtEtaEdge[pe],upperPtEtaEdge[pe],"s");
1895      fDiffFlowDirectCorrelations[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
1896      fNestedLoopsList->Add(fDiffFlowDirectCorrelations[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
1897     } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
1898    } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
1899   } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
1900   // correction terms for non-uniform acceptance:
1901   TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
1902   diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
1903   for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
1904   { 
1905    for(Int_t pe=0;pe<2;pe++) // pt or eta
1906    {
1907     for(Int_t sc=0;sc<2;sc++) // sin or cos
1908     {
1909      for(Int_t cti=0;cti<9;cti++) // correction term index
1910      {
1911       fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] = new TProfile(Form("%s, %s, %s, %s, cti = %d",diffFlowDirectCorrectionTermsForNUAName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1),Form("%s, %s, %s, %s, cti = %d",diffFlowDirectCorrectionTermsForNUAName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1),1,lowerPtEtaEdge[pe],upperPtEtaEdge[pe],"s"); 
1912       fNestedLoopsList->Add(fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]);
1913      }
1914     }
1915    }
1916   } 
1917   // number of RPs and POIs in selected pt and eta bins for cross-checkings:
1918   TString noOfParticlesInBinName = "fNoOfParticlesInBin";
1919   fNoOfParticlesInBin = new TH1D(noOfParticlesInBinName.Data(),"Number of RPs and POIs in selected p_{T} and #eta bin",4,0,4);
1920   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(1,"# of RPs in p_{T} bin");
1921   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(2,"# of RPs in #eta bin");
1922   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(3,"# of POIs in p_{T} bin");
1923   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(4,"# of POIs in #eta bin");
1924   fNestedLoopsList->Add(fNoOfParticlesInBin);
1925  } // end of if(fEvaluateDiffFlowNestedLoops)
1926
1927 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
1928
1929
1930 //================================================================================================================================
1931
1932
1933 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
1934 {
1935  // calculate all correlations needed for integrated flow
1936  
1937  // multiplicity:
1938  Double_t dMult = (*fSMpk)(0,0);
1939  
1940  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
1941  Double_t dReQ1n = (*fReQ)(0,0);
1942  Double_t dReQ2n = (*fReQ)(1,0);
1943  Double_t dReQ3n = (*fReQ)(2,0);
1944  Double_t dReQ4n = (*fReQ)(3,0);
1945  Double_t dImQ1n = (*fImQ)(0,0);
1946  Double_t dImQ2n = (*fImQ)(1,0);
1947  Double_t dImQ3n = (*fImQ)(2,0);
1948  Double_t dImQ4n = (*fImQ)(3,0);
1949   
1950  // real and imaginary parts of some expressions involving various combinations of Q-vectors evaluated in harmonics n, 2n, 3n and 4n:
1951  // (these expression appear in the Eqs. for the multi-particle correlations bellow)
1952  
1953  // Re[Q_{2n} Q_{n}^* Q_{n}^*]
1954  Double_t reQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dReQ2n + 2.*dReQ1n*dImQ1n*dImQ2n - pow(dImQ1n,2.)*dReQ2n; 
1955  
1956  // Im[Q_{2n} Q_{n}^* Q_{n}^*]
1957  //Double_t imQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dImQ2n-2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n; 
1958  
1959  // Re[Q_{n} Q_{n} Q_{2n}^*] = Re[Q_{2n} Q_{n}^* Q_{n}^*]
1960  Double_t reQ1nQ1nQ2nstar = reQ2nQ1nstarQ1nstar; 
1961  
1962  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
1963  Double_t reQ3nQ1nQ2nstarQ2nstar = (pow(dReQ2n,2.)-pow(dImQ2n,2.))*(dReQ3n*dReQ1n-dImQ3n*dImQ1n) 
1964                                  + 2.*dReQ2n*dImQ2n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
1965
1966  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]                                                                  
1967  //Double_t imQ3nQ1nQ2nstarQ2nstar = calculate and implement this (deleteMe)
1968   
1969  // Re[Q_{2n} Q_{2n} Q_{3n}^* Q_{1n}^*] = Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
1970  Double_t reQ2nQ2nQ3nstarQ1nstar = reQ3nQ1nQ2nstarQ2nstar;
1971   
1972  // Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
1973  Double_t reQ4nQ2nstarQ2nstar = pow(dReQ2n,2.)*dReQ4n+2.*dReQ2n*dImQ2n*dImQ4n-pow(dImQ2n,2.)*dReQ4n;
1974
1975  // Im[Q_{4n} Q_{2n}^* Q_{2n}^*]
1976  //Double_t imQ4nQ2nstarQ2nstar = calculate and implement this (deleteMe)
1977  
1978  // Re[Q_{2n} Q_{2n} Q_{4n}^*] =  Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
1979  Double_t reQ2nQ2nQ4nstar = reQ4nQ2nstarQ2nstar;
1980  
1981  // Re[Q_{4n} Q_{3n}^* Q_{n}^*]
1982  Double_t reQ4nQ3nstarQ1nstar = dReQ4n*(dReQ3n*dReQ1n-dImQ3n*dImQ1n)+dImQ4n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
1983  
1984  // Re[Q_{3n} Q_{n} Q_{4n}^*] = Re[Q_{4n} Q_{3n}^* Q_{n}^*]
1985  Double_t reQ3nQ1nQ4nstar = reQ4nQ3nstarQ1nstar;
1986  
1987  // Im[Q_{4n} Q_{3n}^* Q_{n}^*]
1988  //Double_t imQ4nQ3nstarQ1nstar = calculate and implement this (deleteMe)
1989
1990  // Re[Q_{3n} Q_{2n}^* Q_{n}^*]
1991  Double_t reQ3nQ2nstarQ1nstar = dReQ3n*dReQ2n*dReQ1n-dReQ3n*dImQ2n*dImQ1n+dImQ3n*dReQ2n*dImQ1n
1992                               + dImQ3n*dImQ2n*dReQ1n;
1993                               
1994  // Re[Q_{2n} Q_{n} Q_{3n}^*] = Re[Q_{3n} Q_{2n}^* Q_{n}^*]
1995  Double_t reQ2nQ1nQ3nstar = reQ3nQ2nstarQ1nstar;
1996  
1997  // Im[Q_{3n} Q_{2n}^* Q_{n}^*]
1998  //Double_t imQ3nQ2nstarQ1nstar; //calculate and implement this (deleteMe)
1999  
2000  // Re[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2001  Double_t reQ3nQ1nstarQ1nstarQ1nstar = dReQ3n*pow(dReQ1n,3)-3.*dReQ1n*dReQ3n*pow(dImQ1n,2)
2002                                      + 3.*dImQ1n*dImQ3n*pow(dReQ1n,2)-dImQ3n*pow(dImQ1n,3);
2003
2004  // Im[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2005  //Double_t imQ3nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2006  
2007  // |Q_{2n}|^2 |Q_{n}|^2
2008  Double_t dQ2nQ1nQ2nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
2009  
2010  // Re[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2011  Double_t reQ4nQ2nstarQ1nstarQ1nstar = (dReQ4n*dReQ2n+dImQ4n*dImQ2n)*(pow(dReQ1n,2)-pow(dImQ1n,2))
2012                                      + 2.*dReQ1n*dImQ1n*(dImQ4n*dReQ2n-dReQ4n*dImQ2n); 
2013  
2014  // Im[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2015  //Double_t imQ4nQ2nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2016  
2017  // Re[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*]
2018  Double_t reQ2nQ1nQ1nstarQ1nstarQ1nstar = (dReQ2n*dReQ1n-dImQ2n*dImQ1n)*(pow(dReQ1n,3)-3.*dReQ1n*pow(dImQ1n,2))
2019                                         + (dReQ2n*dImQ1n+dReQ1n*dImQ2n)*(3.*dImQ1n*pow(dReQ1n,2)-pow(dImQ1n,3));
2020
2021  // Im[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*] 
2022  //Double_t imQ2nQ1nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2023  
2024  // Re[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2025  Double_t reQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2026                                         * (dReQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) + 2.*dImQ2n*dReQ1n*dImQ1n);
2027
2028  // Im[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2029  //Double_t imQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2030  //                                       * (dImQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) - 2.*dReQ2n*dReQ1n*dImQ1n);
2031  
2032  // Re[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2033  Double_t reQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dReQ4n-6.*pow(dReQ1n,2.)*dReQ4n*pow(dImQ1n,2.)
2034                                             + pow(dImQ1n,4.)*dReQ4n+4.*pow(dReQ1n,3.)*dImQ1n*dImQ4n
2035                                             - 4.*pow(dImQ1n,3.)*dReQ1n*dImQ4n;
2036                                             
2037  // Im[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2038  //Double_t imQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dImQ4n-6.*pow(dReQ1n,2.)*dImQ4n*pow(dImQ1n,2.)
2039  //                                           + pow(dImQ1n,4.)*dImQ4n+4.*pow(dImQ1n,3.)*dReQ1n*dReQ4n
2040  //                                           - 4.*pow(dReQ1n,3.)*dImQ1n*dReQ4n;
2041  
2042  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2043  Double_t reQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2044                                         * (dReQ1n*dReQ2n*dReQ3n-dReQ3n*dImQ1n*dImQ2n+dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n);
2045  
2046  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2047  //Double_t imQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2048  //                                       * (-dReQ2n*dReQ3n*dImQ1n-dReQ1n*dReQ3n*dImQ2n+dReQ1n*dReQ2n*dImQ3n-dImQ1n*dImQ2n*dImQ3n);
2049  
2050  
2051  // Re[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2052  Double_t reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)*dReQ2n-2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2053                                                + dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n-pow(dImQ1n,2.)*dImQ2n)
2054                                                * (pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2055                                                - dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n+pow(dImQ1n,2.)*dImQ2n);
2056  
2057  // Im[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2058  //Double_t imQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = 2.*(pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2059  //                                              + 2.*dReQ1n*dImQ1n*dImQ2n)*(pow(dReQ1n,2.)*dImQ2n
2060  //                                              - 2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n);
2061  
2062  // Re[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2063  Double_t reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2064                                                * (pow(dReQ1n,3.)*dReQ3n-3.*dReQ1n*dReQ3n*pow(dImQ1n,2.)
2065                                                + 3.*pow(dReQ1n,2.)*dImQ1n*dImQ3n-pow(dImQ1n,3.)*dImQ3n);
2066   
2067  // Im[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                                                           
2068  //Double_t imQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2069  //                                              * (pow(dImQ1n,3.)*dReQ3n-3.*dImQ1n*dReQ3n*pow(dReQ1n,2.)
2070  //                                              - 3.*pow(dImQ1n,2.)*dReQ1n*dImQ3n+pow(dReQ1n,3.)*dImQ3n);
2071  
2072  // |Q_{2n}|^2 |Q_{n}|^4
2073  Double_t dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.);
2074  
2075  // Re[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2076  Double_t reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2077                                                   * (pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2078                                                   + 2.*dReQ1n*dImQ1n*dImQ2n);
2079                                                   
2080  // Im[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                  
2081  //Double_t imQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2082  //                                                 * (pow(dReQ1n,2.)*dImQ2n-dImQ2n*pow(dImQ1n,2.)
2083  //                                                 - 2.*dReQ1n*dReQ2n*dImQ1n);
2084  
2085   
2086  
2087        
2088  //                                        **************************************
2089  //                                        **** multi-particle correlations: ****
2090  //                                        **************************************
2091  //
2092  // Remark 1: multi-particle correlations calculated with non-weighted Q-vectors are stored in 1D profile fQCorrelations[0]. // to be improved (wrong profiles)
2093  // Remark 2: binning of fQCorrelations[0] is organized as follows: // to be improved (wrong profiles)
2094  // --------------------------------------------------------------------------------------------------------------------
2095  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
2096  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
2097  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
2098  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
2099  //  5th bin:           ----  EMPTY ----
2100  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
2101  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
2102  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2103  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
2104  // 10th bin:           ----  EMPTY ----
2105  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
2106  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
2107  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
2108  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2109  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
2110  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
2111  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
2112  // 18th bin:           ----  EMPTY ----
2113  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2114  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2115  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2116  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2117  // 23rd bin:           ----  EMPTY ----
2118  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2119  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2120  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2121  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2122  // 28th bin:           ----  EMPTY ----
2123  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2124  // 30th bin:           ----  EMPTY ----
2125  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2126  // --------------------------------------------------------------------------------------------------------------------
2127     
2128  // 2-particle:
2129  Double_t two1n1n = 0.; // <cos(n*(phi1-phi2))>
2130  Double_t two2n2n = 0.; // <cos(2n*(phi1-phi2))>
2131  Double_t two3n3n = 0.; // <cos(3n*(phi1-phi2))>
2132  Double_t two4n4n = 0.; // <cos(4n*(phi1-phi2))>
2133  
2134  if(dMult>1)
2135  {
2136   two1n1n = (pow(dReQ1n,2.)+pow(dImQ1n,2.)-dMult)/(dMult*(dMult-1.)); 
2137   two2n2n = (pow(dReQ2n,2.)+pow(dImQ2n,2.)-dMult)/(dMult*(dMult-1.)); 
2138   two3n3n = (pow(dReQ3n,2.)+pow(dImQ3n,2.)-dMult)/(dMult*(dMult-1.)); 
2139   two4n4n = (pow(dReQ4n,2.)+pow(dImQ4n,2.)-dMult)/(dMult*(dMult-1.)); 
2140   
2141   // average 2-particle correlations for single event: 
2142   fIntFlowCorrelationsAllEBE->SetBinContent(1,two1n1n);
2143   fIntFlowCorrelationsAllEBE->SetBinContent(2,two2n2n);
2144   fIntFlowCorrelationsAllEBE->SetBinContent(3,two3n3n);
2145   fIntFlowCorrelationsAllEBE->SetBinContent(4,two4n4n);
2146           
2147   // average 2-particle correlations for all events:      
2148   fIntFlowCorrelationsAllPro->Fill(0.5,two1n1n,dMult*(dMult-1.));  
2149   fIntFlowCorrelationsAllPro->Fill(1.5,two2n2n,dMult*(dMult-1.)); 
2150   fIntFlowCorrelationsAllPro->Fill(2.5,two3n3n,dMult*(dMult-1.)); 
2151   fIntFlowCorrelationsAllPro->Fill(3.5,two4n4n,dMult*(dMult-1.)); 
2152   
2153   // store separetately <2> (to be improved: do I really need this?)
2154   fIntFlowCorrelationsEBE->SetBinContent(1,two1n1n); // <2>
2155   
2156   // to be improved (this can be implemented better):
2157   Double_t mWeight2p = 0.;
2158   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2159   {
2160    mWeight2p = dMult*(dMult-1.);
2161   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2162     {
2163      mWeight2p = 1.;    
2164     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2165       {
2166        mWeight2p = dMult;           
2167       }
2168             
2169   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,mWeight2p); // eW_<2>
2170   fIntFlowCorrelationsPro->Fill(0.5,two1n1n,mWeight2p);
2171     
2172   // distribution of <cos(n*(phi1-phi2))>:
2173   //f2pDistribution->Fill(two1n1n,dMult*(dMult-1.)); 
2174  } // end of if(dMult>1)
2175  
2176  // 3-particle:
2177  Double_t three2n1n1n = 0.; // <cos(n*(2.*phi1-phi2-phi3))>
2178  Double_t three3n2n1n = 0.; // <cos(n*(3.*phi1-2.*phi2-phi3))>
2179  Double_t three4n2n2n = 0.; // <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2180  Double_t three4n3n1n = 0.; // <cos(n*(4.*phi1-3.*phi2-phi3))>
2181  
2182  if(dMult>2)
2183  {
2184   three2n1n1n = (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2185               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
2186               / (dMult*(dMult-1.)*(dMult-2.));                     
2187   three3n2n1n = (reQ3nQ2nstarQ1nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2188               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2189               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2190               / (dMult*(dMult-1.)*(dMult-2.));
2191   three4n2n2n = (reQ4nQ2nstarQ2nstar-2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2192               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*dMult)
2193               / (dMult*(dMult-1.)*(dMult-2.)); 
2194   three4n3n1n = (reQ4nQ3nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2195               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
2196               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2197               / (dMult*(dMult-1.)*(dMult-2.)); 
2198               
2199   // average 3-particle correlations for single event: 
2200   fIntFlowCorrelationsAllEBE->SetBinContent(6,three2n1n1n);
2201   fIntFlowCorrelationsAllEBE->SetBinContent(7,three3n2n1n);
2202   fIntFlowCorrelationsAllEBE->SetBinContent(8,three4n2n2n);
2203   fIntFlowCorrelationsAllEBE->SetBinContent(9,three4n3n1n);
2204         
2205   // average 3-particle correlations for all events:                
2206   fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.)); 
2207   fIntFlowCorrelationsAllPro->Fill(6.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
2208   fIntFlowCorrelationsAllPro->Fill(7.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.)); 
2209   fIntFlowCorrelationsAllPro->Fill(8.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));    
2210  } // end of if(dMult>2)
2211  
2212  // 4-particle:
2213  Double_t four1n1n1n1n = 0.; // <cos(n*(phi1+phi2-phi3-phi4))>
2214  Double_t four2n2n2n2n = 0.; // <cos(2.*n*(phi1+phi2-phi3-phi4))>
2215  Double_t four2n1n2n1n = 0.; // <cos(n*(2.*phi1+phi2-2.*phi3-phi4))> 
2216  Double_t four3n1n1n1n = 0.; // <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2217  Double_t four4n2n1n1n = 0.; // <cos(n*(4.*phi1-2.*phi2-phi3-phi4))> 
2218  Double_t four3n1n2n2n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))> 
2219  Double_t four3n1n3n1n = 0.; // <cos(n*(3.*phi1+phi2-3.*phi3-phi4))>   
2220  
2221  if(dMult>3)
2222  {
2223   four1n1n1n1n = (2.*dMult*(dMult-3.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ1n,2.)
2224                + pow(dImQ1n,2.))-2.*reQ2nQ1nstarQ1nstar+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2225                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));     
2226   four2n2n2n2n = (2.*dMult*(dMult-3.)+pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ2n,2.)
2227                + pow(dImQ2n,2.))-2.*reQ4nQ2nstarQ2nstar+(pow(dReQ4n,2.)+pow(dImQ4n,2.)))
2228                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));
2229   four2n1n2n1n = (dQ2nQ1nQ2nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar-2.*reQ2nQ1nstarQ1nstar)
2230                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2231                - ((dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2232                + (dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2233                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2234                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2235   four3n1n1n1n = (reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar-3.*reQ2nQ1nstarQ1nstar)
2236                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2237                + (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2238                + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
2239                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2240   four4n2n1n1n = (reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar)
2241                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2242                - (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2243                - 3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2244                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2245                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2246   four3n1n2n2n = (reQ3nQ1nQ2nstarQ2nstar-reQ4nQ2nstarQ2nstar-reQ3nQ1nQ4nstar-2.*reQ3nQ2nstarQ1nstar)
2247                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2248                - (2.*reQ1nQ1nQ2nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2249                - 4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2250                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2251                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.)); 
2252   four3n1n3n1n = ((pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2253                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar)
2254                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2255                + ((pow(dReQ4n,2.)+pow(dImQ4n,2.))-(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2256                + (pow(dReQ2n,2.)+pow(dImQ2n,2.))-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2257                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2258                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2259                
2260   // average 4-particle correlations for single event: 
2261   fIntFlowCorrelationsAllEBE->SetBinContent(11,four1n1n1n1n);
2262   fIntFlowCorrelationsAllEBE->SetBinContent(12,four2n1n2n1n);
2263   fIntFlowCorrelationsAllEBE->SetBinContent(13,four2n2n2n2n);
2264   fIntFlowCorrelationsAllEBE->SetBinContent(14,four3n1n1n1n);
2265   fIntFlowCorrelationsAllEBE->SetBinContent(15,four3n1n3n1n);
2266   fIntFlowCorrelationsAllEBE->SetBinContent(16,four3n1n2n2n);
2267   fIntFlowCorrelationsAllEBE->SetBinContent(17,four4n2n1n1n);
2268         
2269   // average 4-particle correlations for all events:                
2270   fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2271   fIntFlowCorrelationsAllPro->Fill(11.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2272   fIntFlowCorrelationsAllPro->Fill(12.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2273   fIntFlowCorrelationsAllPro->Fill(13.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2274   fIntFlowCorrelationsAllPro->Fill(14.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2275   fIntFlowCorrelationsAllPro->Fill(15.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
2276   fIntFlowCorrelationsAllPro->Fill(16.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
2277   
2278   // store separetately <4> (to be improved: do I really need this?)
2279   fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1n); // <4>
2280   
2281   // to be improved (this can be implemented better):
2282   Double_t mWeight4p = 0.;
2283   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2284   {
2285    mWeight4p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.);
2286   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2287     {
2288      mWeight4p = 1.;    
2289     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2290       {
2291        mWeight4p = dMult;           
2292       }
2293       
2294   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,mWeight4p); // eW_<4>
2295   fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1n,mWeight4p);
2296   
2297   // distribution of <cos(n*(phi1+phi2-phi3-phi4))>
2298   //f4pDistribution->Fill(four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2299   
2300  } // end of if(dMult>3)
2301
2302  // 5-particle:
2303  Double_t five2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2304  Double_t five2n2n2n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2305  Double_t five3n1n2n1n1n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2306  Double_t five4n1n1n1n1n = 0.; // <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2307  
2308  if(dMult>4)
2309  {
2310   five2n1n1n1n1n = (reQ2nQ1nQ1nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar+6.*reQ3nQ2nstarQ1nstar)
2311                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2312                  - (reQ2nQ1nQ3nstar+3.*(dMult-6.)*reQ2nQ1nstarQ1nstar+3.*reQ1nQ1nQ2nstar)
2313                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2314                  - (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2315                  + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))     
2316                  - 3.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2317                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2318                  - 3.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2319                  - 2.*(2*dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult*(dMult-4.))
2320                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2321                  
2322   five2n2n2n1n1n = (reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ2nQ2nQ3nstarQ1nstar)
2323                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2324                  + 2.*(reQ4nQ2nstarQ2nstar+4.*reQ3nQ2nstarQ1nstar+reQ3nQ1nQ4nstar)
2325                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2326                  + (reQ2nQ2nQ4nstar-2.*(dMult-5.)*reQ2nQ1nstarQ1nstar+2.*reQ1nQ1nQ2nstar)
2327                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2328                  - (2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2329                  + 1.*pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)
2330                  - 2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2331                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2332                  - (4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2333                  - 4.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+4.*dMult*(dMult-6.))
2334                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2335
2336   five4n1n1n1n1n = (reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ4nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nstarQ1nstarQ1nstar)
2337                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2338                  + (8.*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+12.*reQ3nQ2nstarQ1nstar+12.*reQ2nQ1nstarQ1nstar)
2339                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2340                  - (6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+8.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2341                  + 12.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-24.*dMult)
2342                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2343   
2344   five3n1n2n1n1n = (reQ3nQ1nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar)
2345                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2346                  - (reQ3nQ1nQ2nstarQ2nstar-3.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar)
2347                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2348                  - ((2.*dMult-13.)*reQ3nQ2nstarQ1nstar-reQ3nQ1nQ4nstar-9.*reQ2nQ1nstarQ1nstar)
2349                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2350                  - (2.*reQ1nQ1nQ2nstar+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2351                  - 2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+2.*(pow(dReQ3n,2.)
2352                  + pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2353                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2354                  + (2.*(dMult-6.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2355                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2356                  - pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2357                  + 2.*(3.*dMult-11.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2358                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2359                  - 4.*(dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2360                  
2361   // average 5-particle correlations for single event: 
2362   fIntFlowCorrelationsAllEBE->SetBinContent(19,five2n1n1n1n1n);
2363   fIntFlowCorrelationsAllEBE->SetBinContent(20,five2n2n2n1n1n);
2364   fIntFlowCorrelationsAllEBE->SetBinContent(21,five3n1n2n1n1n);
2365   fIntFlowCorrelationsAllEBE->SetBinContent(22,five4n1n1n1n1n);
2366         
2367   // average 5-particle correlations for all events:                         
2368   fIntFlowCorrelationsAllPro->Fill(18.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2369   fIntFlowCorrelationsAllPro->Fill(19.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2370   fIntFlowCorrelationsAllPro->Fill(20.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2371   fIntFlowCorrelationsAllPro->Fill(21.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2372  } // end of if(dMult>4)
2373     
2374  // 6-particle:
2375  Double_t six1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2376  Double_t six2n2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2377  Double_t six3n1n1n1n1n1n = 0.; // <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2378  Double_t six2n1n1n2n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2379  
2380  if(dMult>5)
2381  {
2382   six1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)+9.*dQ2nQ1nQ2nstarQ1nstar-6.*reQ2nQ1nQ1nstarQ1nstarQ1nstar)
2383                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2384                   + 4.*(reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar)
2385                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2386                   + 2.*(9.*(dMult-4.)*reQ2nQ1nstarQ1nstar+2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2387                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2388                   - 9.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2389                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-5.))
2390                   + (18.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2391                   / (dMult*(dMult-1)*(dMult-3)*(dMult-4))
2392                   - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2393                   
2394   six2n1n1n2n1n1n = (dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2395                   * (2.*five2n2n2n1n1n+4.*five2n1n1n1n1n+4.*five3n1n2n1n1n+4.*four2n1n2n1n+1.*four1n1n1n1n)
2396                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four1n1n1n1n+4.*two1n1n
2397                   + 2.*three2n1n1n+2.*three2n1n1n+4.*four3n1n1n1n+8.*three2n1n1n+2.*four4n2n1n1n
2398                   + 4.*four2n1n2n1n+2.*two2n2n+8.*four2n1n2n1n+4.*four3n1n3n1n+8.*three3n2n1n
2399                   + 4.*four3n1n2n2n+4.*four1n1n1n1n+4.*four2n1n2n1n+1.*four2n2n2n2n)
2400                   - dMult*(dMult-1.)*(dMult-2.)*(2.*three2n1n1n+8.*two1n1n+4.*two1n1n+2.
2401                   + 4.*two1n1n+4.*three2n1n1n+2.*two2n2n+4.*three2n1n1n+8.*three3n2n1n
2402                   + 8.*two2n2n+4.*three4n3n1n+4.*two3n3n+4.*three3n2n1n+4.*two1n1n
2403                   + 8.*three2n1n1n+4.*two1n1n+4.*three3n2n1n+4.*three2n1n1n+2.*two2n2n
2404                   + 4.*three3n2n1n+2.*three4n2n2n)-dMult*(dMult-1.)
2405                   * (4.*two1n1n+4.+4.*two1n1n+2.*two2n2n+1.+4.*two1n1n+4.*two2n2n+4.*two3n3n
2406                   + 1.+2.*two2n2n+1.*two4n4n)-dMult)
2407                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2408  
2409   six2n2n1n1n1n1n = (reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2410                   * (five4n1n1n1n1n+8.*five2n1n1n1n1n+6.*five2n2n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2411                   * (4.*four3n1n1n1n+6.*four4n2n1n1n+12.*three2n1n1n+12.*four1n1n1n1n+24.*four2n1n2n1n
2412                   + 4.*four3n1n2n2n+3.*four2n2n2n2n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n
2413                   + 4.*three4n3n1n+3.*three4n2n2n+8.*three2n1n1n+24.*two1n1n+12.*two2n2n+12.*three2n1n1n+8.*three3n2n1n
2414                   + 1.*three4n2n2n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+2.*two2n2n+8.*two1n1n+6.)-dMult)
2415                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2416    
2417   six3n1n1n1n1n1n = (reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2418                   * (five4n1n1n1n1n+4.*five2n1n1n1n1n+6.*five3n1n2n1n1n+4.*four3n1n1n1n)
2419                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+6.*four1n1n1n1n
2420                   + 12.*three2n1n1n+12.*four2n1n2n1n+6.*four3n1n1n1n+12.*three3n2n1n+4.*four3n1n3n1n+3.*four3n1n2n2n)
2421                   - dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n+4.*three4n3n1n+3.*three4n2n2n+4.*two1n1n
2422                   + 12.*two1n1n+6.*three2n1n1n+12.*three2n1n1n+4.*three3n2n1n+12.*two2n2n+4.*three3n2n1n+4.*two3n3n+1.*three4n3n1n
2423                   + 6.*three3n2n1n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+1.*two1n1n+4.+6.*two1n1n+4.*two2n2n
2424                   + 1.*two3n3n)-dMult)/(dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2425                                  
2426   // average 6-particle correlations for single event: 
2427   fIntFlowCorrelationsAllEBE->SetBinContent(24,six1n1n1n1n1n1n);
2428   fIntFlowCorrelationsAllEBE->SetBinContent(25,six2n1n1n2n1n1n);
2429   fIntFlowCorrelationsAllEBE->SetBinContent(26,six2n2n1n1n1n1n);
2430   fIntFlowCorrelationsAllEBE->SetBinContent(27,six3n1n1n1n1n1n);
2431         
2432   // average 6-particle correlations for all events:         
2433   fIntFlowCorrelationsAllPro->Fill(23.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2434   fIntFlowCorrelationsAllPro->Fill(24.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2435   fIntFlowCorrelationsAllPro->Fill(25.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
2436   fIntFlowCorrelationsAllPro->Fill(26.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2437
2438   // store separetately <6> (to be improved: do I really need this?)
2439   fIntFlowCorrelationsEBE->SetBinContent(3,six1n1n1n1n1n1n); // <6>
2440   
2441   // to be improved (this can be implemented better):
2442   Double_t mWeight6p = 0.;
2443   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2444   {
2445    mWeight6p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.);
2446   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2447     {
2448      mWeight6p = 1.;    
2449     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2450       {
2451        mWeight6p = dMult;           
2452       }
2453       
2454   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(3,mWeight6p); // eW_<6>
2455   fIntFlowCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n,mWeight6p);
2456  
2457   // distribution of <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2458   //f6pDistribution->Fill(six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2459  } // end of if(dMult>5)
2460  
2461  // 7-particle:
2462  Double_t seven2n1n1n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2463  
2464  if(dMult>6)
2465  {
2466   seven2n1n1n1n1n1n1n = (reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2467                       * (2.*six3n1n1n1n1n1n+4.*six1n1n1n1n1n1n+1.*six2n2n1n1n1n1n+6.*six2n1n1n2n1n1n+8.*five2n1n1n1n1n)
2468                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(1.*five4n1n1n1n1n +8.*five2n1n1n1n1n+8.*four3n1n1n1n
2469                       + 12.*five3n1n2n1n1n+4.*five2n1n1n1n1n+3.*five2n2n2n1n1n+6.*five2n2n2n1n1n+6.*four1n1n1n1n+24.*four1n1n1n1n
2470                       + 12.*five2n1n1n1n1n+12.*five2n1n1n1n1n+12.*three2n1n1n+24.*four2n1n2n1n+4.*five3n1n2n1n1n+4.*five2n1n1n1n1n)
2471                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+12.*four1n1n1n1n+24.*three2n1n1n
2472                       + 24.*four2n1n2n1n+12.*four3n1n1n1n+24.*three3n2n1n+8.*four3n1n3n1n+6.*four3n1n2n2n+6.*three2n1n1n+12.*four1n1n1n1n
2473                       + 12.*four2n1n2n1n+6.*three2n1n1n+12.*four2n1n2n1n+4.*four3n1n2n2n+3.*four2n2n2n2n+4.*four1n1n1n1n+6.*three2n1n1n
2474                       + 24.*two1n1n+24.*four1n1n1n1n+4.*four3n1n1n1n+24.*two1n1n+24.*three2n1n1n+12.*two2n2n+24.*three2n1n1n+12.*four2n1n2n1n
2475                       + 8.*three3n2n1n+8.*four2n1n2n1n+1.*four4n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+1.*three2n1n1n+8.*two1n1n
2476                       + 12.*three3n2n1n+24.*two1n1n+12.*three2n1n1n+4.*three2n1n1n+8.*two1n1n+4.*three4n3n1n+24.*three2n1n1n+8.*three3n2n1n
2477                       + 12.*two1n1n+12.*two1n1n+3.*three4n2n2n+24.*two2n2n+6.*two2n2n+12.+12.*three3n2n1n+8.*two3n3n+12.*three2n1n1n+24.*two1n1n
2478                       + 4.*three3n2n1n+8.*three3n2n1n+2.*three4n3n1n+12.*two1n1n+8.*three2n1n1n+4.*three2n1n1n+2.*three3n2n1n+6.*two2n2n+8.*two2n2n
2479                       + 1.*three4n2n2n+4.*three3n2n1n+6.*three2n1n1n)-dMult*(dMult-1.)*(4.*two1n1n+2.*two1n1n+6.*two2n2n+8.+1.*two2n2n+4.*two3n3n
2480                       + 12.*two1n1n+4.*two1n1n+1.*two4n4n+8.*two2n2n+6.+2.*two3n3n+4.*two1n1n+1.*two2n2n)-dMult)
2481                       / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)); // to be improved (direct formula needed)
2482         
2483   // average 7-particle correlations for single event: 
2484   fIntFlowCorrelationsAllEBE->SetBinContent(29,seven2n1n1n1n1n1n1n);
2485        
2486   // average 7-particle correlations for all events:                      
2487   fIntFlowCorrelationsAllPro->Fill(28.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.));
2488  } // end of if(dMult>6)
2489  
2490  // 8-particle:
2491  Double_t eight1n1n1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2492  if(dMult>7)
2493  {
2494   eight1n1n1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),4.)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)
2495                         * (12.*seven2n1n1n1n1n1n1n+16.*six1n1n1n1n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2496                         * (8.*six3n1n1n1n1n1n+48.*six1n1n1n1n1n1n+6.*six2n2n1n1n1n1n+96.*five2n1n1n1n1n+72.*four1n1n1n1n+36.*six2n1n1n2n1n1n)
2497                         - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(2.*five4n1n1n1n1n+32.*five2n1n1n1n1n+36.*four1n1n1n1n
2498                         + 32.*four3n1n1n1n+48.*five2n1n1n1n1n+48.*five3n1n2n1n1n+144.*five2n1n1n1n1n+288.*four1n1n1n1n+36.*five2n2n2n1n1n
2499                         + 144.*three2n1n1n+96.*two1n1n+144.*four2n1n2n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2500                         * (8.*four3n1n1n1n+48.*four1n1n1n1n+12.*four4n2n1n1n+96.*four2n1n2n1n+96.*three2n1n1n+72.*three2n1n1n+144.*two1n1n
2501                         + 16.*four3n1n3n1n+48.*four3n1n1n1n+144.*four1n1n1n1n+72.*four1n1n1n1n+96.*three3n2n1n+24.*four3n1n2n2n+144.*four2n1n2n1n
2502                         + 288.*two1n1n+288.*three2n1n1n+9.*four2n2n2n2n+72.*two2n2n+24.)-dMult*(dMult-1.)*(dMult-2.)*(12.*three2n1n1n+16.*two1n1n
2503                         + 24.*three3n2n1n+48.*three2n1n1n+96.*two1n1n+8.*three4n3n1n+32.*three3n2n1n+96.*three2n1n1n+144.*two1n1n+6.*three4n2n2n
2504                         + 96.*two2n2n+36.*two2n2n+72.+48.*three3n2n1n+16.*two3n3n+72.*three2n1n1n+144.*two1n1n)-dMult*(dMult-1.)*(8.*two1n1n
2505                         + 12.*two2n2n+16.+8.*two3n3n+48.*two1n1n+1.*two4n4n+16.*two2n2n+18.)-dMult)
2506                         / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.)); // to be improved (direct formula needed)
2507   
2508   // average 8-particle correlations for single event: 
2509   fIntFlowCorrelationsAllEBE->SetBinContent(31,eight1n1n1n1n1n1n1n1n);
2510        
2511   // average 8-particle correlations for all events:                       
2512   fIntFlowCorrelationsAllPro->Fill(30.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2513  
2514   // store separetately <8> (to be improved: do I really need this?)
2515   fIntFlowCorrelationsEBE->SetBinContent(4,eight1n1n1n1n1n1n1n1n); // <8>
2516   
2517   // to be improved (this can be implemented better):
2518   Double_t mWeight8p = 0.;
2519   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2520   {
2521    mWeight8p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.);
2522   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2523     {
2524      mWeight8p = 1.;    
2525     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2526       {
2527        mWeight8p = dMult;           
2528       }
2529         
2530   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(4,mWeight8p); // eW_<8>
2531   fIntFlowCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n,mWeight8p);  
2532   
2533   // distribution of <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2534   //f8pDistribution->Fill(eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2535  } // end of if(dMult>7) 
2536  
2537 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
2538
2539
2540 //================================================================================================================================
2541
2542
2543 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
2544 {
2545  // Calculate averages of products of correlations for integrated flow  // to be improved (this method can be implemented better)
2546  
2547  // a) Binning of fIntFlowProductOfCorrelationsPro is organized as follows:
2548  //     1st bin: <<2><4>> 
2549  //     2nd bin: <<2><6>>
2550  //     3rd bin: <<2><8>>
2551  //     4th bin: <<4><6>>
2552  //     5th bin: <<4><8>>
2553  //     6th bin: <<6><8>>
2554
2555  /*
2556  Double_t dMult = (*fSMpk)(0,0); // multiplicity 
2557
2558  Double_t twoEBE = fIntFlowCorrelationsEBE->GetBinContent(1); // <2>
2559  Double_t fourEBE = fIntFlowCorrelationsEBE->GetBinContent(2); // <4>
2560  Double_t sixEBE = fIntFlowCorrelationsEBE->GetBinContent(3); // <6>
2561  Double_t eightEBE = fIntFlowCorrelationsEBE->GetBinContent(4); // <8>
2562  
2563  Double_t eW2 = 0.; // event weight for <2>
2564  Double_t eW4 = 0.; // event weight for <4>
2565  Double_t eW6 = 0.; // event weight for <6>
2566  Double_t eW8 = 0.; // event weight for <8>
2567  
2568  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
2569  {
2570   eW2 = dMult*(dMult-1);
2571   eW4 = dMult*(dMult-1)*(dMult-2)*(dMult-3);
2572   eW6 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5);
2573   eW8 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7);
2574  } else 
2575    {
2576     eW2 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j;
2577     eW4 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
2578         + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
2579         + 3.*(*fSMpk)(1,2)-6.*(*fSMpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
2580    }
2581   
2582  fIntFlowProductOfCorrelationsPro->Fill(0.5,twoEBE*fourEBE,eW2*eW4); // <<2><4>> 
2583  fIntFlowProductOfCorrelationsPro->Fill(1.5,twoEBE*sixEBE,eW2*eW6); // <<2><6>>
2584  fIntFlowProductOfCorrelationsPro->Fill(2.5,twoEBE*eightEBE,eW2*eW8); // <<2><8>>
2585  fIntFlowProductOfCorrelationsPro->Fill(3.5,fourEBE*sixEBE,eW4*eW6); // <<4><6>>
2586  fIntFlowProductOfCorrelationsPro->Fill(4.5,fourEBE*eightEBE,eW4*eW8); // <<4><8>>
2587  fIntFlowProductOfCorrelationsPro->Fill(5.5,sixEBE*eightEBE,eW6*eW8); // <<6><8>>
2588  */
2589  
2590  
2591  Int_t counter = 0;
2592  
2593  for(Int_t ci1=1;ci1<4;ci1++)
2594  {
2595   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
2596   {
2597    fIntFlowProductOfCorrelationsPro->Fill(0.5+counter++,
2598                                           fIntFlowCorrelationsEBE->GetBinContent(ci1)*fIntFlowCorrelationsEBE->GetBinContent(ci2),
2599                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
2600   }
2601  }
2602  
2603 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
2604
2605
2606 //================================================================================================================================
2607
2608
2609 void AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
2610 {
2611  // a) Calculate unbiased estimators Cov(<2>,<4>), Cov(<2>,<6>), Cov(<2>,<8>), Cov(<4>,<6>), Cov(<4>,<8>) and Cov(<6>,<8>)
2612  //    for covariances V_(<2>,<4>), V_(<2>,<6>), V_(<2>,<8>), V_(<4>,<6>), V_(<4>,<8>) and V_(<6>,<8>).
2613  // b) Store in histogram fIntFlowCovariances for instance the following: 
2614  //
2615  //             Cov(<2>,<4>) * (sum_{i=1}^{N} w_{<2>}_i w_{<4>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<4>}_j)]
2616  // 
2617  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<4>} is event weight for <4>.
2618  // c) Binning of fIntFlowCovariances is organized as follows:
2619  // 
2620  //     1st bin: Cov(<2>,<4>) * (sum_{i=1}^{N} w_{<2>}_i w_{<4>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<4>}_j)] 
2621  //     2nd bin: Cov(<2>,<6>) * (sum_{i=1}^{N} w_{<2>}_i w_{<6>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<6>}_j)]
2622  //     3rd bin: Cov(<2>,<8>) * (sum_{i=1}^{N} w_{<2>}_i w_{<8>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<8>}_j)]
2623  //     4th bin: Cov(<4>,<6>) * (sum_{i=1}^{N} w_{<4>}_i w_{<6>}_i )/[(sum_{i=1}^{N} w_{<4>}_i) * (sum_{j=1}^{N} w_{<6>}_j)]
2624  //     5th bin: Cov(<4>,<8>) * (sum_{i=1}^{N} w_{<4>}_i w_{<8>}_i )/[(sum_{i=1}^{N} w_{<4>}_i) * (sum_{j=1}^{N} w_{<8>}_j)]
2625  //     6th bin: Cov(<6>,<8>) * (sum_{i=1}^{N} w_{<6>}_i w_{<8>}_i )/[(sum_{i=1}^{N} w_{<6>}_i) * (sum_{j=1}^{N} w_{<8>}_j)]
2626     
2627  for(Int_t power=0;power<2;power++)
2628  { 
2629   if(!(fIntFlowCorrelationsPro && fIntFlowProductOfCorrelationsPro 
2630        && fIntFlowSumOfEventWeights[power] && fIntFlowSumOfProductOfEventWeights
2631        && fIntFlowCovariances)) 
2632   {
2633    cout<<"WARNING: fIntFlowCorrelationsPro && fIntFlowProductOfCorrelationsPro "<<endl;
2634    cout<<"         && fIntFlowSumOfEventWeights[power] && fIntFlowSumOfProductOfEventWeights"<<endl;
2635    cout<<"         && fIntFlowCovariances is NULL in AFAWQC::FCIF() !!!!"<<endl;
2636    cout<<"power = "<<power<<endl;
2637    exit(0);
2638   }
2639  }
2640    
2641  // average 2-, 4-, 6- and 8-particle correlations for all events:
2642  Double_t correlation[4] = {0.};
2643  for(Int_t ci=0;ci<4;ci++)
2644  {
2645   correlation[ci] = fIntFlowCorrelationsPro->GetBinContent(ci+1);
2646  } 
2647  // average products of 2-, 4-, 6- and 8-particle correlations: 
2648  Double_t productOfCorrelations[4][4] = {{0.}};
2649  Int_t productOfCorrelationsLabel = 1;
2650  // denominators in the expressions for the unbiased estimator for covariance:
2651  Double_t denominator[4][4] = {{0.}};
2652  Int_t sumOfProductOfEventWeightsLabel1 = 1;
2653  // weight dependent prefactor which multiply unbiased estimators for covariances:
2654  Double_t wPrefactor[4][4] = {{0.}}; 
2655  Int_t sumOfProductOfEventWeightsLabel2 = 1;
2656  for(Int_t c1=0;c1<4;c1++)
2657  {
2658   for(Int_t c2=c1+1;c2<4;c2++)
2659   {
2660    productOfCorrelations[c1][c2] = fIntFlowProductOfCorrelationsPro->GetBinContent(productOfCorrelationsLabel);
2661    if(fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1) && fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1))
2662    {
2663     denominator[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel1))/
2664                              (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1) 
2665                               * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));
2666                               
2667     wPrefactor[c1][c2] =  fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel2)/ 
2668                           (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)
2669                             * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));
2670                           
2671                               
2672    }
2673    productOfCorrelationsLabel++;
2674    sumOfProductOfEventWeightsLabel1++;
2675    sumOfProductOfEventWeightsLabel2++;  
2676   }
2677  }
2678  
2679  // covariance label:
2680  Int_t covarianceLabel = 1;
2681  for(Int_t c1=0;c1<4;c1++)
2682  {
2683   for(Int_t c2=c1+1;c2<4;c2++)
2684   {
2685    if(denominator[c1][c2])
2686    {
2687     // covariances:
2688     Double_t cov = (productOfCorrelations[c1][c2]-correlation[c1]*correlation[c2])/denominator[c1][c2]; 
2689     // covarianced multiplied with weight dependent prefactor:
2690     Double_t wCov = cov * wPrefactor[c1][c2];
2691     fIntFlowCovariances->SetBinContent(covarianceLabel,wCov);
2692    }
2693    covarianceLabel++;
2694   }
2695  }
2696  
2697 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
2698
2699
2700 //================================================================================================================================
2701
2702
2703 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow() 
2704 {
2705  // From profile fIntFlowCorrelationsPro access measured correlations and spread, 
2706  // correctly calculate the statistical errors and store the final results and 
2707  // statistical errors for correlations in histogram fIntFlowCorrelationsHist.
2708  //
2709  // Remark: Statistical error of correlation is calculated as:
2710  //
2711  //          statistical error = termA * spread * termB:
2712  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
2713  //          termB = 1/sqrt(1-termA^2)   
2714  
2715  for(Int_t power=0;power<2;power++)
2716  { 
2717   if(!(fIntFlowCorrelationsHist && fIntFlowCorrelationsPro && fIntFlowSumOfEventWeights[power])) 
2718   {
2719    cout<<"WARNING: fIntFlowCorrelationsHist && fIntFlowCorrelationsPro && fIntFlowSumOfEventWeights[power] is NULL in AFAWQC::FCIF() !!!!"<<endl;
2720    cout<<"power = "<<power<<endl;
2721    exit(0);
2722   }
2723  }
2724   
2725  for(Int_t ci=1;ci<=4;ci++) // correlation index
2726  {
2727   Double_t correlation = fIntFlowCorrelationsPro->GetBinContent(ci);
2728   Double_t spread = fIntFlowCorrelationsPro->GetBinError(ci);
2729   Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeights[0]->GetBinContent(ci);
2730   Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeights[1]->GetBinContent(ci);
2731   Double_t termA = 0.;
2732   Double_t termB = 0.;
2733   if(sumOfLinearEventWeights)
2734   {
2735    termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
2736   } else
2737     {
2738      cout<<"WARNING: sumOfLinearEventWeights == 0 in AFAWQC::FCIF() !!!!"<<endl;
2739      cout<<"         (for "<<2*ci<<"-particle correlation)"<<endl;
2740     }
2741   if(1.-pow(termA,2.) > 0.)
2742   {
2743    termB = 1./pow(1-pow(termA,2.),0.5);
2744   } else
2745     {
2746      cout<<"WARNING: 1.-pow(termA,2.) <= 0 in AFAWQC::FCIF() !!!!"<<endl;   
2747      cout<<"         (for "<<2*ci<<"-particle correlation)"<<endl;
2748     }     
2749   Double_t statisticalError = termA * spread * termB;
2750   fIntFlowCorrelationsHist->SetBinContent(ci,correlation);
2751   fIntFlowCorrelationsHist->SetBinError(ci,statisticalError);
2752  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index                                                                
2753                                                                                                                               
2754 } // end of AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow()
2755
2756
2757 //================================================================================================================================
2758
2759
2760 void AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(Int_t nRP)
2761 {
2762  // Fill profile fAverageMultiplicity to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
2763  
2764  // Binning of fAverageMultiplicity is organized as follows:
2765  //  1st bin: all events (including the empty ones)
2766  //  2nd bin: event with # of RPs greater or equal to 1
2767  //  3rd bin: event with # of RPs greater or equal to 2
2768  //  4th bin: event with # of RPs greater or equal to 3
2769  //  5th bin: event with # of RPs greater or equal to 4
2770  //  6th bin: event with # of RPs greater or equal to 5
2771  //  7th bin: event with # of RPs greater or equal to 6
2772  //  8th bin: event with # of RPs greater or equal to 7
2773  //  9th bin: event with # of RPs greater or equal to 8
2774  
2775  if(!fAvMultiplicity)
2776  {
2777   cout<<"WARNING: fAvMultiplicity is NULL in AFAWQC::FAM() !!!!"<<endl;
2778   exit(0);
2779  }
2780  
2781  if(nRP<0)
2782  {
2783   cout<<"WARNING: nRP<0 in in AFAWQC::FAM() !!!!"<<endl;
2784   exit(0);
2785  }
2786  
2787  for(Int_t i=0;i<9;i++)
2788  {
2789   if(nRP>=i) fAvMultiplicity->Fill(i+0.5,nRP,1);
2790  }
2791  
2792 } // end of AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(nRP)
2793
2794
2795 //================================================================================================================================
2796
2797
2798 void AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
2799 {
2800  // a) Calculate Q-cumulants from the measured multiparticle correlations.
2801  // b) Propagate the statistical errors of measured multiparticle correlations to statistical errors of Q-cumulants.  
2802  // c) REMARK: Q-cumulants calculated in this method are biased by non-uniform acceptance of detector !!!! 
2803  //            Method ApplyCorrectionForNonUniformAcceptance* (to be improved: finalize the name here)
2804  //            is called afterwards to correct for this bias.   
2805  // d) Store the results and statistical error of Q-cumulants in histogram fCumulants.
2806  //    Binning of fCumulants is organized as follows:
2807  //
2808  //     1st bin: QC{2}
2809  //     2nd bin: QC{4}
2810  //     3rd bin: QC{6}
2811  //     4th bin: QC{8}
2812  
2813  if(!(fIntFlowCorrelationsHist && fIntFlowCovariances && fIntFlowQcumulants))
2814  {
2815   cout<<"WARNING: fIntFlowCorrelationsHist && fIntFlowCovariances && fIntFlowQcumulants is NULL in AFAWQC::CCIF() !!!!"<<endl;
2816   exit(0);
2817  }
2818  
2819  // correlations:
2820  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
2821  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
2822  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
2823  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
2824  
2825  // statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
2826  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
2827  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
2828  Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
2829  Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
2830  
2831  // covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
2832  Double_t wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
2833  Double_t wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
2834  Double_t wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
2835  Double_t wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
2836  Double_t wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
2837  Double_t wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>)
2838  
2839  // Q-cumulants: 
2840  Double_t qc2 = 0.; // QC{2}
2841  Double_t qc4 = 0.; // QC{4}
2842  Double_t qc6 = 0.; // QC{6}
2843  Double_t qc8 = 0.; // QC{8}
2844  if(two) qc2 = two; 
2845  if(four) qc4 = four-2.*pow(two,2.); 
2846  if(six) qc6 = six-9.*two*four+12.*pow(two,3.); 
2847  if(eight) qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.); 
2848  
2849  // statistical errors of Q-cumulants:       
2850  Double_t qc2Error = 0.;
2851  Double_t qc4Error = 0.;
2852  Double_t qc6Error = 0.;
2853  Double_t qc8Error = 0.;
2854  
2855  // squared statistical errors of Q-cumulants:       
2856  //Double_t qc2ErrorSquared = 0.;
2857  Double_t qc4ErrorSquared = 0.;
2858  Double_t qc6ErrorSquared = 0.;
2859  Double_t qc8ErrorSquared = 0.;
2860         
2861  // statistical error of QC{2}:              
2862  qc2Error = twoError;                     
2863                              
2864  // statistical error of QC{4}:              
2865  qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
2866                  - 8.*two*wCov24;                     
2867  if(qc4ErrorSquared>0.)
2868  {
2869   qc4Error = pow(qc4ErrorSquared,0.5);
2870  } else 
2871    {
2872     cout<<"WARNING: Statistical error of QC{4} is imaginary !!!!"<<endl;
2873    }
2874                                            
2875  // statistical error of QC{6}:              
2876  qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
2877                  + 81.*pow(two,2.)*pow(fourError,2.)
2878                  + pow(sixError,2.)
2879                  - 162.*two*(4.*pow(two,2.)-four)*wCov24
2880                  + 18.*(4.*pow(two,2.)-four)*wCov26
2881                  - 18.*two*wCov46; 
2882                     
2883  if(qc6ErrorSquared>0.)
2884  {
2885   qc6Error = pow(qc6ErrorSquared,0.5);
2886  } else 
2887    {
2888     cout<<"WARNING: Statistical error of QC{6} is imaginary !!!!"<<endl;
2889    }
2890                             
2891  // statistical error of QC{8}:              
2892  qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
2893                  + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
2894                  + 256.*pow(two,2.)*pow(sixError,2.)
2895                  + pow(eightError,2.)
2896                  - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
2897                  + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
2898                  - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
2899                  - 1152.*two*(4.*pow(two,2.)-four)*wCov46
2900                  + 72.*(4.*pow(two,2.)-four)*wCov48
2901                  - 32.*two*wCov68;      
2902  if(qc8ErrorSquared>0.)
2903  {
2904   qc8Error = pow(qc8ErrorSquared,0.5);
2905  } else 
2906    {
2907     cout<<"WARNING: Statistical error of QC{8} is imaginary !!!!"<<endl;
2908    }
2909
2910  // store the results and statistical errors for Q-cumulants:
2911  fIntFlowQcumulants->SetBinContent(1,qc2);
2912  fIntFlowQcumulants->SetBinError(1,qc2Error);
2913  fIntFlowQcumulants->SetBinContent(2,qc4);
2914  fIntFlowQcumulants->SetBinError(2,qc4Error);
2915  fIntFlowQcumulants->SetBinContent(3,qc6);
2916  fIntFlowQcumulants->SetBinError(3,qc6Error);
2917  fIntFlowQcumulants->SetBinContent(4,qc8); 
2918  fIntFlowQcumulants->SetBinError(4,qc8Error); 
2919   
2920 } // end of AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
2921
2922
2923 //================================================================================================================================ 
2924
2925
2926 void AliFlowAnalysisWithQCumulants::CalculateIntFlow()
2927 {
2928  // a) Calculate the final results for integrated flow estimates from Q-cumulants.
2929  // b) Propagate the statistical errors of measured multiparticle correlations to statistical errors of integrated flow estimates.  
2930  // c) Store the results and statistical errors of integrated flow estimates in histogram fIntFlow.
2931  //    Binning of fIntFlow is organized as follows:
2932  //
2933  //     1st bin: v{2,QC}
2934  //     2nd bin: v{4,QC}
2935  //     3rd bin: v{6,QC}
2936  //     4th bin: v{8,QC}
2937  
2938  if(!(fIntFlowCorrelationsHist && fIntFlowCovariances && fIntFlowQcumulants && fIntFlow))
2939  {
2940   cout<<"WARNING: fIntFlowCorrelationsHist && fIntFlowCovariances && fIntFlowQcumulants && fIntFlow is NULL in AFAWQC::CCIF() !!!!"<<endl;
2941   exit(0);
2942  }
2943    
2944  // Q-cumulants:
2945  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
2946  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
2947  Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
2948  Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
2949   
2950  // correlations:
2951  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
2952  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
2953  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
2954  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
2955  
2956  // statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
2957  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
2958  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
2959  Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
2960  Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
2961  
2962  // covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
2963  Double_t wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
2964  Double_t wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
2965  Double_t wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
2966  Double_t wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
2967  Double_t wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
2968  Double_t wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>)
2969   
2970  // integrated flow estimates:
2971  Double_t v2 = 0.; // v{2,QC}  
2972  Double_t v4 = 0.; // v{4,QC}  
2973  Double_t v6 = 0.; // v{6,QC}  
2974  Double_t v8 = 0.; // v{8,QC}
2975  
2976  // calculate integrated flow estimates from Q-cumulants: 
2977  if(qc2>=0.) v2 = pow(qc2,1./2.); 
2978  if(qc4<=0.) v4 = pow(-1.*qc4,1./4.); 
2979  if(qc6>=0.) v6 = pow((1./4.)*qc6,1./6.); 
2980  if(qc8<=0.) v8 = pow((-1./33.)*qc8,1./8.); 
2981    
2982  // statistical errors of integrated flow estimates:
2983  Double_t v2Error = 0.; // statistical error of v{2,QC}  
2984  Double_t v4Error = 0.; // statistical error of v{4,QC}  
2985  Double_t v6Error = 0.; // statistical error of v{6,QC}  
2986  Double_t v8Error = 0.; // statistical error of v{8,QC}
2987    
2988  // squares of statistical errors of integrated flow estimates:
2989  Double_t v2ErrorSquared = 0.; // squared statistical error of v{2,QC} 
2990  Double_t v4ErrorSquared = 0.; // squared statistical error of v{4,QC}   
2991  Double_t v6ErrorSquared = 0.; // squared statistical error of v{6,QC}   
2992  Double_t v8ErrorSquared = 0.; // squared statistical error of v{8,QC} 
2993  
2994  // calculate squared statistical errors of integrated flow estimates:
2995  if(two > 0.) 
2996  { 
2997   v2ErrorSquared = (1./(4.*two))*pow(twoError,2.);
2998  } 
2999  if(2.*pow(two,2.)-four > 0.)
3000  {
3001   v4ErrorSquared = (1./pow(2.*pow(two,2.)-four,3./2.))*
3002                    (pow(two,2.)*pow(twoError,2.)+(1./16.)*pow(fourError,2.)-(1./2.)*two*wCov24);
3003  }
3004  if(six-9.*four*two+12.*pow(two,3.) > 0.) 
3005  {
3006   v6ErrorSquared = ((1./2.)*(1./pow(2.,2./3.))*(1./pow(six-9.*four*two+12.*pow(two,3.),5./3.)))*
3007                    ((9./2.)*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.) 
3008                     + (9./2.)*pow(two,2.)*pow(fourError,2.)+(1./18.)*pow(sixError,2.)
3009                     - 9.*two*(4.*pow(two,2.)-four)*wCov24+(4.*pow(two,2.)-four)*wCov26-two*wCov46); 
3010  }
3011  if(-1.*eight+16.*six*two+18.*pow(four,2.)-144.*four*pow(two,2.)+144.*pow(two,4.) > 0.) 
3012  {
3013   v8ErrorSquared = (4./pow(33,1./4.))*(1./pow(-1.*eight+16.*six*two+18.*pow(four,2.)-144.*four*pow(two,2.)+144.*pow(two,4.),7./4.))*
3014                    (pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
3015                     + (81./16.)*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
3016                     + pow(two,2.)*pow(sixError,2.)
3017                     + (1./256.)*pow(eightError,2.)
3018                     - (9./2.)*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
3019                     + 2.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
3020                     - (1./8.)*(36.*pow(two,3.)-18.*four*two+six)*wCov28                    
3021                     - (9./2.)*two*(4.*pow(two,2.)-four)*wCov46                   
3022                     + (9./32.)*(4.*pow(two,2.)-four)*wCov48                    
3023                     - (1./8.)*two*wCov68);
3024  } 
3025
3026  // calculate statistical errors of integrated flow estimates: 
3027  if(v2ErrorSquared > 0.)
3028  {
3029   v2Error = pow(v2ErrorSquared,0.5);
3030  } else
3031    {
3032     cout<<"WARNING: Statistical error of v{2,QC} is imaginary !!!!"<<endl;
3033    }    
3034  if(v4ErrorSquared > 0.)
3035  {
3036   v4Error = pow(v4ErrorSquared,0.5);
3037  } else
3038    {
3039     cout<<"WARNING: Statistical error of v{4,QC} is imaginary !!!!"<<endl;
3040    }     
3041  if(v6ErrorSquared > 0.)
3042  {
3043   v6Error = pow(v6ErrorSquared,0.5);
3044  } else
3045    {
3046     cout<<"WARNING: Statistical error of v{6,QC} is imaginary !!!!"<<endl;
3047    }     
3048  if(v8ErrorSquared > 0.)
3049  {
3050   v8Error = pow(v8ErrorSquared,0.5);
3051  } else
3052    {
3053     cout<<"WARNING: Statistical error of v{8,QC} is imaginary !!!!"<<endl;
3054    }    
3055                      
3056  // store the results and statistical errors of integrated flow estimates:
3057  fIntFlow->SetBinContent(1,v2);
3058  fIntFlow->SetBinError(1,v2Error);
3059  fIntFlow->SetBinContent(2,v4);
3060  fIntFlow->SetBinError(2,v4Error);
3061  fIntFlow->SetBinContent(3,v6);
3062  fIntFlow->SetBinError(3,v6Error);
3063  fIntFlow->SetBinContent(4,v8);
3064  fIntFlow->SetBinError(4,v8Error);
3065        
3066 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlow()
3067
3068
3069 //================================================================================================================================ 
3070
3071
3072 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
3073 {
3074  // Fill in AliFlowCommonHistResults histograms relevant for 'NONAME' integrated flow (to be improved (name))
3075  
3076  if(!fIntFlow)
3077  {
3078   cout<<"WARNING: fIntFlow is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
3079   exit(0); 
3080  }  
3081     
3082  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
3083  {
3084   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
3085   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
3086   exit(0);
3087  }
3088  
3089  Double_t v2 = fIntFlow->GetBinContent(1);
3090  Double_t v4 = fIntFlow->GetBinContent(2);
3091  Double_t v6 = fIntFlow->GetBinContent(3);
3092  Double_t v8 = fIntFlow->GetBinContent(4);
3093   
3094  Double_t v2Error = fIntFlow->GetBinError(1);
3095  Double_t v4Error = fIntFlow->GetBinError(2);
3096  Double_t v6Error = fIntFlow->GetBinError(3);
3097  Double_t v8Error = fIntFlow->GetBinError(4);
3098  
3099  fCommonHistsResults2nd->FillIntegratedFlow(v2,v2Error); // to be improved (hardwired 2nd in the name)  
3100  fCommonHistsResults4th->FillIntegratedFlow(v4,v4Error); // to be improved (hardwired 4th in the name)
3101  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)) // to be improved (calculate also 6th and 8th order)
3102  {
3103   fCommonHistsResults6th->FillIntegratedFlow(v6,v6Error); // to be improved (hardwired 6th in the name)
3104   fCommonHistsResults8th->FillIntegratedFlow(v8,v8Error); // to be improved (hardwired 8th in the name) 
3105  }
3106  
3107 } // end of AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
3108
3109
3110 //================================================================================================================================ 
3111
3112
3113 /*
3114 void AliFlowAnalysisWithQCumulants::ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
3115 {
3116  // apply correction for non-uniform acceptance to cumulants for integrated flow 
3117  // (Remark: non-corrected cumulants are accessed from fCumulants[pW][0], corrected cumulants are stored in fCumulants[pW][1])
3118  
3119  // shortcuts for the flags:
3120  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not used, 1=pWeights used
3121  Int_t eW = -1;
3122  
3123  if(eventWeights == "exact")
3124  {
3125   eW = 0;
3126  }
3127  
3128  if(!(fCumulants[pW][eW][0] && fCumulants[pW][eW][1] && fCorrections[pW][eW]))
3129  {
3130   cout<<"WARNING: fCumulants[pW][eW][0] && fCumulants[pW][eW][1] && fCorrections[pW][eW] is NULL in AFAWQC::ACFNUATCFIF() !!!!"<<endl;
3131   cout<<"pW = "<<pW<<endl;
3132   cout<<"eW = "<<eW<<endl;
3133   exit(0);
3134  } 
3135   
3136  // non-corrected cumulants:
3137  Double_t qc2 = fCumulants[pW][eW][0]->GetBinContent(1); 
3138  Double_t qc4 = fCumulants[pW][eW][0]->GetBinContent(2); 
3139  Double_t qc6 = fCumulants[pW][eW][0]->GetBinContent(3); 
3140  Double_t qc8 = fCumulants[pW][eW][0]->GetBinContent(4); 
3141  // statistical error of non-corrected cumulants:  
3142  Double_t qc2Error = fCumulants[pW][eW][0]->GetBinError(1); 
3143  Double_t qc4Error = fCumulants[pW][eW][0]->GetBinError(2); 
3144  Double_t qc6Error = fCumulants[pW][eW][0]->GetBinError(3); 
3145  Double_t qc8Error = fCumulants[pW][eW][0]->GetBinError(4); 
3146  // corrections for non-uniform acceptance:
3147  Double_t qc2Correction = fCorrections[pW][eW]->GetBinContent(1); 
3148  Double_t qc4Correction = fCorrections[pW][eW]->GetBinContent(2); 
3149  Double_t qc6Correction = fCorrections[pW][eW]->GetBinContent(3); 
3150  Double_t qc8Correction = fCorrections[pW][eW]->GetBinContent(4); 
3151  // corrected cumulants:
3152  Double_t qc2Corrected = qc2 + qc2Correction;
3153  Double_t qc4Corrected = qc4 + qc4Correction;
3154  Double_t qc6Corrected = qc6 + qc6Correction;
3155  Double_t qc8Corrected = qc8 + qc8Correction;
3156   
3157  // ... to be improved (I need here also to correct error of QCs for NUA. 
3158  // For simplicity sake I assume at the moment that this correction is negliglible, but it will be added eventually...)
3159  
3160  // store corrected results and statistical errors for cumulants:   
3161  fCumulants[pW][eW][1]->SetBinContent(1,qc2Corrected);
3162  fCumulants[pW][eW][1]->SetBinContent(2,qc4Corrected);
3163  fCumulants[pW][eW][1]->SetBinContent(3,qc6Corrected);
3164  fCumulants[pW][eW][1]->SetBinContent(4,qc8Corrected);
3165  fCumulants[pW][eW][1]->SetBinError(1,qc2Error); // to be improved (correct also qc2Error for NUA)
3166  fCumulants[pW][eW][1]->SetBinError(2,qc4Error); // to be improved (correct also qc4Error for NUA)
3167  fCumulants[pW][eW][1]->SetBinError(3,qc6Error); // to be improved (correct also qc6Error for NUA)
3168  fCumulants[pW][eW][1]->SetBinError(4,qc8Error); // to be improved (correct also qc8Error for NUA)  
3169   
3170 } // end of AliFlowAnalysisWithQCumulants::ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
3171 */
3172
3173
3174 //================================================================================================================================
3175
3176
3177 /*  
3178 void AliFlowAnalysisWithQCumulants::PrintQuantifyingCorrectionsForNonUniformAcceptance(Bool_t useParticleWeights, TString eventWeights)
3179 {
3180  // print on the screen QC{n,biased}/QC{n,corrected}
3181  
3182  // shortcuts for the flags:
3183  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not used, 1=pWeights used
3184  
3185  Int_t eW = -1;
3186  
3187  if(eventWeights == "exact")
3188  {
3189   eW = 0;
3190  } 
3191  
3192  if(!(fCumulants[pW][eW][0] && fCumulants[pW][eW][1]))
3193  {
3194   cout<<"WARNING: fCumulants[pW][eW][0] && fCumulants[pW][eW][1] is NULL in AFAWQC::PQCFNUA() !!!!"<<endl;
3195   cout<<"pW = "<<pW<<endl;
3196   cout<<"eW = "<<eW<<endl;
3197   exit(0);
3198  }
3199    
3200  cout<<endl;
3201  cout<<" Quantifying the bias to Q-cumulants from"<<endl;
3202  cout<<"  non-uniform acceptance of the detector:"<<endl;
3203  cout<<endl;
3204   
3205  if(fCumulants[pW][eW][1]->GetBinContent(1)) 
3206  { 
3207   cout<<"  QC{2,biased}/QC{2,corrected} = "<<(fCumulants[pW][eW][0]->GetBinContent(1))/(fCumulants[pW][eW][1]->GetBinContent(1))<<endl;   
3208  }
3209  if(fCumulants[pW][eW][1]->GetBinContent(2)) 
3210  { 
3211   cout<<"  QC{4,biased}/QC{4,corrected} = "<<fCumulants[pW][eW][0]->GetBinContent(2)/fCumulants[pW][eW][1]->GetBinContent(2)<<endl;   
3212  }
3213  
3214  cout<<endl;
3215             
3216 } // end of AliFlowAnalysisWithQCumulants::PrintQuantifyingCorrectionsForNonUniformAcceptance(Bool_t useParticleWeights, TString eventWeights)
3217 */
3218
3219
3220 //================================================================================================================================
3221
3222
3223 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
3224 {
3225  // Calculate all correlations needed for integrated flow using particle weights.
3226   
3227  // Remark 1: When particle weights are used the binning of fIntFlowCorrelationAllPro is organized as follows:
3228  //
3229  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
3230  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
3231  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
3232  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
3233  //  5th bin:           ----  EMPTY ----
3234  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
3235  //  7th bin: <3>_{3n|2n,1n} = ...
3236  //  8th bin: <3>_{4n|2n,2n} = ...
3237  //  9th bin: <3>_{4n|3n,1n} = ...
3238  // 10th bin:           ----  EMPTY ----
3239  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
3240  // 12th bin: <4>_{2n,1n|2n,1n} = ...
3241  // 13th bin: <4>_{2n,2n|2n,2n} = ...
3242  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
3243  // 15th bin: <4>_{3n,1n|3n,1n} = ...
3244  // 16th bin: <4>_{3n,1n|2n,2n} = ...
3245  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
3246  // 18th bin:           ----  EMPTY ----
3247  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
3248  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
3249  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
3250  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
3251  // 23rd bin:           ----  EMPTY ----
3252  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
3253  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
3254  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
3255  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
3256  // 28th bin:           ----  EMPTY ----
3257  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
3258  // 30th bin:           ----  EMPTY ----
3259  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
3260  
3261  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
3262  // fIntFlowExtraCorrelationsPro binning of which is organized as follows:
3263  
3264  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
3265  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
3266  
3267  // multiplicity (number of particles used to determine the reaction plane)
3268  Double_t dMult = (*fSMpk)(0,0);
3269  
3270  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
3271  Double_t dReQ1n1k = (*fReQ)(0,1);
3272  Double_t dReQ2n2k = (*fReQ)(1,2);
3273  Double_t dReQ3n3k = (*fReQ)(2,3);
3274  Double_t dReQ4n4k = (*fReQ)(3,4);
3275  Double_t dReQ1n3k = (*fReQ)(0,3);
3276  Double_t dImQ1n1k = (*fImQ)(0,1);
3277  Double_t dImQ2n2k = (*fImQ)(1,2);
3278  Double_t dImQ3n3k = (*fImQ)(2,3);
3279  Double_t dImQ4n4k = (*fImQ)(3,4);
3280  Double_t dImQ1n3k = (*fImQ)(0,3);
3281
3282  // dMs are variables introduced in order to simplify some Eqs. bellow:
3283  //..............................................................................................
3284  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
3285  Double_t dM22 = (*fSMpk)(1,2)-(*fSMpk)(0,4); // dM22 = sum_{i,j=1,i!=j}^M w_i^2 w_j^2
3286  Double_t dM33 = (*fSMpk)(1,3)-(*fSMpk)(0,6); // dM33 = sum_{i,j=1,i!=j}^M w_i^3 w_j^3
3287  Double_t dM44 = (*fSMpk)(1,4)-(*fSMpk)(0,8); // dM44 = sum_{i,j=1,i!=j}^M w_i^4 w_j^4
3288  Double_t dM31 = (*fSMpk)(0,3)*(*fSMpk)(0,1)-(*fSMpk)(0,4); // dM31 = sum_{i,j=1,i!=j}^M w_i^3 w_j
3289  Double_t dM211 = (*fSMpk)(0,2)*(*fSMpk)(1,1)-2.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
3290                 - (*fSMpk)(1,2)+2.*(*fSMpk)(0,4); // dM211 = sum_{i,j,k=1,i!=j!=k}^M w_i^2 w_j w_k
3291  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
3292                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
3293                  + 3.*(*fSMpk)(1,2)-6.*(*fSMpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
3294  //..............................................................................................
3295
3296  // 2-particle correlations:
3297  Double_t two1n1nW1W1 = 0.; // <w1 w2 cos(n*(phi1-phi2))>
3298  Double_t two2n2nW2W2 = 0.; // <w1^2 w2^2 cos(2n*(phi1-phi2))>
3299  Double_t two3n3nW3W3 = 0.; // <w1^3 w2^3 cos(3n*(phi1-phi2))>
3300  Double_t two4n4nW4W4 = 0.; // <w1^4 w2^4 cos(4n*(phi1-phi2))>
3301  if(dMult>1) 
3302  { 
3303   if(dM11)
3304   {
3305    two1n1nW1W1 = (pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))/dM11;    
3306    // average correlation <w1 w2 cos(n*(phi1-phi2))> for single event: 
3307    fIntFlowCorrelationsEBE->SetBinContent(1,two1n1nW1W1);
3308    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,dM11);
3309    // average correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
3310    fIntFlowCorrelationsPro->Fill(0.5,two1n1nW1W1,dM11);   
3311    fIntFlowCorrelationsAllPro->Fill(0.5,two1n1nW1W1,dM11);   
3312   }
3313   if(dM22)
3314   {
3315    two2n2nW2W2 = (pow(dReQ2n2k,2)+pow(dImQ2n2k,2)-(*fSMpk)(0,4))/dM22; 
3316    // ...
3317    // average correlation <w1^2 w2^2 cos(2n*(phi1-phi2))> for all events:
3318    fIntFlowCorrelationsAllPro->Fill(1.5,two2n2nW2W2,dM22);   
3319   }
3320   if(dM33)
3321   {
3322    two3n3nW3W3 = (pow(dReQ3n3k,2)+pow(dImQ3n3k,2)-(*fSMpk)(0,6))/dM33;
3323    // ...
3324    // average correlation <w1^3 w2^3 cos(3n*(phi1-phi2))> for all events:
3325    fIntFlowCorrelationsAllPro->Fill(2.5,two3n3nW3W3,dM33);   
3326   }
3327   if(dM44)
3328   {
3329    two4n4nW4W4 = (pow(dReQ4n4k,2)+pow(dImQ4n4k,2)-(*fSMpk)(0,8))/dM44; 
3330    // ...
3331    // average correlation <w1^4 w2^4 cos(4n*(phi1-phi2))> for all events:
3332    fIntFlowCorrelationsAllPro->Fill(3.5,two4n4nW4W4,dM44);      
3333   }
3334  } // end of if(dMult>1) 
3335
3336  // extra 2-particle correlations:
3337  Double_t two1n1nW3W1 = 0.; // <w1^3 w2 cos(n*(phi1-phi2))>
3338  Double_t two1n1nW1W1W2 = 0.; // <w1 w2 w3^2 cos(n*(phi1-phi2))> 
3339  if(dMult>1) 
3340  {    
3341   if(dM31)
3342   {
3343    two1n1nW3W1 = (dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k-(*fSMpk)(0,4))/dM31; 
3344    fIntFlowExtraCorrelationsPro->Fill(0.5,two1n1nW3W1,dM31);  
3345   } 
3346   if(dM211)
3347   {
3348    two1n1nW1W1W2 = ((*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))
3349                  - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k
3350                  - (*fSMpk)(0,4)))/dM211;
3351    fIntFlowExtraCorrelationsPro->Fill(1.5,two1n1nW1W1W2,dM211);  
3352   }  
3353  } // end of if(dMult>1)
3354  //..............................................................................................
3355  
3356  //..............................................................................................
3357  // 3-particle correlations:
3358  Double_t three2n1n1nW2W1W1 = 0.; // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
3359  
3360  if(dMult>2) 
3361  { 
3362   if(dM211)
3363   {                                                       
3364    three2n1n1nW2W1W1 = (pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k
3365                      - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
3366                      - pow(dReQ2n2k,2)-pow(dImQ2n2k,2)
3367                      + 2.*(*fSMpk)(0,4))/dM211;                                                                               
3368    fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1nW2W1W1,dM211);
3369   } 
3370  } // end of if(dMult>2) 
3371  //..............................................................................................
3372  
3373  //..............................................................................................
3374  // 4-particle correlations:
3375  Double_t four1n1n1n1nW1W1W1W1 = 0.; // <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
3376  if(dMult>3) 
3377  { 
3378   if(dM1111)
3379   {      
3380    four1n1n1n1nW1W1W1W1 = (pow(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.),2)
3381                         - 2.*(pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k)
3382                         + 8.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
3383                         + (pow(dReQ2n2k,2)+pow(dImQ2n2k,2))
3384                         - 4.*(*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
3385                         - 6.*(*fSMpk)(0,4)+2.*(*fSMpk)(1,2))/dM1111;  
3386                           
3387    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for single event: 
3388    fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1nW1W1W1W1);
3389    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,dM1111);
3390    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
3391    fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1,dM1111);   
3392    fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1nW1W1W1W1,dM1111);   
3393   } 
3394  } // end of if(dMult>3) 
3395  //..............................................................................................
3396  
3397 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
3398
3399
3400 //================================================================================================================================
3401
3402
3403 void AliFlowAnalysisWithQCumulants::CalculateWeightedQProductsForIntFlow() // to be improved (completed)
3404 {
3405  // calculate averages like <<2><4>>, <<2><6>>, <<4><6>>, etc. which are needed to calculate covariances 
3406  // Remark: here we take weighted correlations!
3407  
3408  /*
3409  
3410  // binning of fQProductsW is organized as follows:
3411  // 
3412  // 1st bin: <2><4> 
3413  // 2nd bin: <2><6>
3414  // 3rd bin: <2><8>
3415  // 4th bin: <4><6>
3416  // 5th bin: <4><8>
3417  // 6th bin: <6><8>
3418  
3419  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
3420
3421  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
3422  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
3423                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
3424                  + 3.*(*fSMpk)(1,2)-6.*(*fSMpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
3425
3426  Double_t twoEBEW = 0.; // <2>
3427  Double_t fourEBEW = 0.; // <4>
3428  
3429  twoEBEW = fQCorrelationsEBE[1]->GetBinContent(1);
3430  fourEBEW = fQCorrelationsEBE[1]->GetBinContent(11);
3431  
3432  // <2><4>
3433  if(dMult>3)
3434  {
3435   fQProducts[1][0]->Fill(0.5,twoEBEW*fourEBEW,dM11*dM1111);
3436  }
3437  
3438  */
3439  
3440 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedQProductsForIntFlow()  
3441
3442
3443 //================================================================================================================================
3444
3445
3446 void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
3447 {
3448  // Initialize all arrays used to calculate integrated flow.
3449  
3450  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
3451  {
3452   fIntFlowCorrectionTermsForNUAEBE[sc] = NULL;
3453   fIntFlowCorrectionTermsForNUAPro[sc] = NULL;
3454   fIntFlowCorrectionTermsForNUAHist[sc] = NULL;
3455  }
3456  for(Int_t power=0;power<2;power++) // linear or quadratic 
3457  {
3458   fIntFlowSumOfEventWeights[power] = NULL;    
3459  }
3460  for(Int_t i=0;i<3;i++) // print on the screen the final results (0=NONAME, 1=RP, 2=POI)
3461  {
3462   fPrintFinalResults[i] = kTRUE;
3463  }
3464  
3465 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
3466
3467
3468 //================================================================================================================================
3469
3470
3471 void AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
3472 {
3473  // Initialize all arrays needed to calculate differential flow.
3474  //  a) Initialize lists holding profiles;
3475  //  b) Initialize lists holding histograms;
3476  //  c) Initialize event-by-event quantities;
3477  //  d) Initialize profiles;
3478  //  e) Initialize histograms holding final results.
3479  
3480  // a) Initialize lists holding profiles;
3481  for(Int_t t=0;t<2;t++) // type (RP, POI)
3482  {
3483   for(Int_t pe=0;pe<2;pe++) // pt or eta
3484   {
3485    fDiffFlowCorrelationsProList[t][pe] = NULL;
3486    fDiffFlowProductOfCorrelationsProList[t][pe] = NULL;
3487    fDiffFlowCorrectionsProList[t][pe] = NULL;
3488   }
3489  }  
3490  
3491  // b) Initialize lists holding histograms;
3492  for(Int_t t=0;t<2;t++) // type (RP, POI)
3493  {
3494   for(Int_t pe=0;pe<2;pe++) // pt or eta
3495   {
3496    fDiffFlowCorrelationsHistList[t][pe] = NULL;
3497    for(Int_t power=0;power<2;power++)
3498    {
3499     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = NULL;
3500    } // end of for(Int_t power=0;power<2;power++)  
3501    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = NULL;
3502    fDiffFlowCorrectionsHistList[t][pe] = NULL;
3503    fDiffFlowCovariancesHistList[t][pe] = NULL;
3504    fDiffFlowCumulantsHistList[t][pe] = NULL;
3505    fDiffFlowHistList[t][pe] = NULL;
3506   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
3507  } // enf of for(Int_t t=0;t<2;t++) // type (RP, POI) 
3508  
3509  // c) Initialize event-by-event quantities:
3510  // 1D:
3511  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
3512  {
3513   for(Int_t pe=0;pe<2;pe++) // pt or eta
3514   { 
3515    for(Int_t m=0;m<4;m++) // multiple of harmonic
3516    {
3517     for(Int_t k=0;k<9;k++) // power of weight
3518     {
3519      fReRPQ1dEBE[t][pe][m][k] = NULL;
3520      fImRPQ1dEBE[t][pe][m][k] = NULL;
3521      fs1dEBE[t][pe][k] = NULL; // to be improved (this doesn't need to be within loop over m)
3522     }   
3523    }
3524   }
3525  }
3526  // 1D:
3527  for(Int_t t=0;t<2;t++) // type (RP or POI)
3528  {
3529   for(Int_t pe=0;pe<2;pe++) // pt or eta
3530   { 
3531    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
3532    {
3533     for(Int_t cti=0;cti<9;cti++) // correction term index
3534     {
3535      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = NULL;
3536     }   
3537    }
3538   }
3539  }
3540  // 2D:  
3541  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
3542  {
3543   for(Int_t m=0;m<4;m++) // multiple of harmonic
3544   {
3545    for(Int_t k=0;k<9;k++) // power of weight
3546    {
3547     fReRPQ2dEBE[t][m][k] = NULL;
3548     fImRPQ2dEBE[t][m][k] = NULL;
3549     fs2dEBE[t][k] = NULL; // to be improved (this doesn't need to be within loop over m)
3550    }   
3551   }
3552  }
3553  
3554  // d) Initialize profiles:
3555  for(Int_t t=0;t<2;t++) // type: RP or POI
3556  { 
3557   for(Int_t pe=0;pe<2;pe++) // pt or eta
3558   {
3559    for(Int_t ci=0;ci<4;ci++) // correlation index
3560    {
3561     fDiffFlowCorrelationsPro[t][pe][ci] = NULL;
3562    } // end of for(Int_t ci=0;ci<4;ci++)   
3563    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
3564    {
3565     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
3566     {
3567      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = NULL;
3568     } // end of for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
3569    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index  
3570    // correction terms for nua:
3571    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
3572    {
3573     for(Int_t cti=0;cti<9;cti++) // correction term index
3574     {
3575      fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = NULL;
3576     }   
3577    }
3578   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
3579  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
3580   
3581  // e) Initialize histograms holding final results.
3582  for(Int_t t=0;t<2;t++) // type: RP or POI
3583  { 
3584   for(Int_t pe=0;pe<2;pe++) // pt or eta
3585   {
3586    for(Int_t ci=0;ci<4;ci++) // correlation index
3587    {
3588     fDiffFlowCorrelationsHist[t][pe][ci] = NULL;
3589     fDiffFlowCumulants[t][pe][ci] = NULL;
3590     fDiffFlow[t][pe][ci] = NULL;
3591    } // end of for(Int_t ci=0;ci<4;ci++)    
3592    for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
3593    {
3594     fDiffFlowCovariances[t][pe][covarianceIndex] = NULL;     
3595    } // end of for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
3596    // correction terms for nua:
3597    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
3598    {
3599     for(Int_t cti=0;cti<9;cti++) // correction term index
3600     {
3601      fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = NULL;
3602     }   
3603    }
3604   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
3605  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
3606  
3607  // sum of event weights for reduced correlations:
3608  for(Int_t t=0;t<2;t++) // type = RP or POI
3609  {
3610   for(Int_t pe=0;pe<2;pe++) // pt or eta
3611   {
3612    for(Int_t p=0;p<2;p++) // power of weight is 1 or 2
3613    {
3614     for(Int_t ew=0;ew<4;ew++) // event weight index for reduced correlations
3615     {
3616      fDiffFlowSumOfEventWeights[t][pe][p][ew] = NULL;
3617     } 
3618    }   
3619   }
3620  }
3621  // product of event weights for both types of correlations:
3622  for(Int_t t=0;t<2;t++) // type = RP or POI
3623  {
3624   for(Int_t pe=0;pe<2;pe++) // pt or eta
3625   {
3626    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
3627    {
3628     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
3629     {
3630      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = NULL;
3631     } 
3632    }   
3633   }
3634  }
3635
3636  
3637  
3638  
3639  /*
3640  
3641  // nested lists in fDiffFlowProfiles:
3642  for(Int_t t=0;t<2;t++)
3643  {
3644   fDFPType[t] = NULL;
3645   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
3646   {
3647    fDFPParticleWeights[t][pW] = NULL;
3648    for(Int_t eW=0;eW<2;eW++)
3649    {   
3650     fDFPEventWeights[t][pW][eW] = NULL;
3651     fDiffFlowCorrelations[t][pW][eW] = NULL;
3652     fDiffFlowProductsOfCorrelations[t][pW][eW] = NULL;
3653     for(Int_t sc=0;sc<2;sc++)
3654     {
3655      fDiffFlowCorrectionTerms[t][pW][eW][sc] = NULL;
3656     }
3657    } 
3658   }
3659  }  
3660  
3661  
3662  */
3663  
3664   
3665   
3666   /*
3667   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
3668   {
3669    for(Int_t eW=0;eW<2;eW++)
3670    {
3671     // correlations:
3672     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
3673     {
3674      fCorrelationsPro[t][pW][eW][correlationIndex] = NULL;
3675     }
3676     // products of correlations:
3677     for(Int_t productOfCorrelationsIndex=0;productOfCorrelationsIndex<6;productOfCorrelationsIndex++)
3678     {
3679      fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] = NULL;
3680     }
3681     // correction terms:
3682     for(Int_t sc=0;sc<2;sc++)
3683     {
3684      for(Int_t correctionsIndex=0;correctionsIndex<2;correctionsIndex++)
3685      {
3686       fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex] = NULL;
3687      } 
3688     } 
3689    }
3690   } 
3691   */
3692     
3693 } // end of AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
3694
3695
3696 //================================================================================================================================
3697  /*
3698
3699
3700 void AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D(TString type)
3701 {
3702  // calculate all reduced correlations needed for differential flow for each (pt,eta) bin: 
3703  
3704  if(type == "RP") // to be improved (removed)
3705  {
3706   cout<<endl;
3707  }
3708  // ... 
3709  
3710  
3711  Int_t typeFlag = -1; 
3712   
3713  // reduced correlations ares stored in fCorrelationsPro[t][pW][index] and are indexed as follows:
3714  // index:
3715  // 0: <2'>
3716  // 1: <4'>
3717
3718  // multiplicity:
3719  Double_t dMult = (*fSMpk)(0,0);
3720  
3721  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
3722  Double_t dReQ1n = (*fReQ)(0,0);
3723  Double_t dReQ2n = (*fReQ)(1,0);
3724  //Double_t dReQ3n = (*fReQ)(2,0);
3725  //Double_t dReQ4n = (*fReQ)(3,0);
3726  Double_t dImQ1n = (*fImQ)(0,0);
3727  Double_t dImQ2n = (*fImQ)(1,0);
3728  //Double_t dImQ3n = (*fImQ)(2,0);
3729  //Double_t dImQ4n = (*fImQ)(3,0);
3730
3731  // looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
3732  for(Int_t p=1;p<=fnBinsPt;p++)
3733  {
3734   for(Int_t e=1;e<=fnBinsEta;e++)
3735   {
3736    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin): 
3737    Double_t p1n0kRe = 0.;
3738    Double_t p1n0kIm = 0.;
3739
3740    // number of POIs in particular (pt,eta) bin:
3741    Double_t mp = 0.;
3742
3743    // real and imaginary parts of q_{m*n,0} (non-weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin):
3744    Double_t q1n0kRe = 0.;
3745    Double_t q1n0kIm = 0.;
3746    Double_t q2n0kRe = 0.;
3747    Double_t q2n0kIm = 0.;
3748
3749    // number of particles which are both RPs and POIs in particular (pt,eta) bin:
3750    Double_t mq = 0.;
3751    
3752    // q_{m*n,0}:
3753    q1n0kRe = fReEBE2D[2][0][0]->GetBinContent(fReEBE2D[2][0][0]->GetBin(p,e))
3754            * fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e));
3755    q1n0kIm = fImEBE2D[2][0][0]->GetBinContent(fImEBE2D[2][0][0]->GetBin(p,e))
3756            * fImEBE2D[2][0][0]->GetBinEntries(fImEBE2D[2][0][0]->GetBin(p,e));
3757    q2n0kRe = fReEBE2D[2][1][0]->GetBinContent(fReEBE2D[2][1][0]->GetBin(p,e))
3758            * fReEBE2D[2][1][0]->GetBinEntries(fReEBE2D[2][1][0]->GetBin(p,e));
3759    q2n0kIm = fImEBE2D[2][1][0]->GetBinContent(fImEBE2D[2][1][0]->GetBin(p,e))
3760            * fImEBE2D[2][1][0]->GetBinEntries(fImEBE2D[2][1][0]->GetBin(p,e));
3761            
3762    mq = fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
3763    
3764    if(type == "POI")
3765    {
3766     // p_{m*n,0}:
3767     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
3768             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
3769     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))  
3770             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e));
3771             
3772     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
3773     
3774     typeFlag = 1;
3775    }
3776    else if(type == "RP")
3777    {
3778     // p_{m*n,0} = q_{m*n,0}:
3779     p1n0kRe = q1n0kRe; 
3780     p1n0kIm = q1n0kIm; 
3781     mp = mq; 
3782     
3783     typeFlag = 0;
3784    }
3785    
3786    // count events with non-empty (pt,eta) bin:
3787    if(mp>0)
3788    {
3789     fNonEmptyBins2D[typeFlag]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,1);
3790    }
3791    
3792    // 2'-particle correlation for particular (pt,eta) bin:
3793    Double_t two1n1nPtEta = 0.;
3794    if(mp*dMult-mq)
3795    {
3796     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
3797                  / (mp*dMult-mq);
3798    
3799     // fill the 2D profile to get the average correlation for each (pt,eta) bin:
3800     if(type == "POI")
3801     { 
3802      //f2pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
3803      
3804      fCorrelationsPro[1][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
3805     }
3806     else if(type == "RP")
3807     {
3808      //f2pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);   
3809      fCorrelationsPro[0][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
3810     }
3811    } // end of if(mp*dMult-mq)
3812   
3813    // 4'-particle correlation:
3814    Double_t four1n1n1n1nPtEta = 0.;
3815    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
3816        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
3817    {
3818     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
3819                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
3820                       - 2.*q2n0kIm*dReQ1n*dImQ1n
3821                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
3822                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
3823                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
3824                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
3825                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
3826                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
3827                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
3828                       + 2.*mq*dMult                      
3829                       - 6.*mq)        
3830                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
3831                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
3832     
3833     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
3834     if(type == "POI")
3835     {
3836      //f4pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
3837      //                  (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
3838      //                   + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
3839      
3840      fCorrelationsPro[1][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
3841                                      (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
3842                                      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
3843     }
3844     else if(type == "RP")
3845     {
3846      //f4pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
3847      //                 (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
3848      //                  + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));   
3849                        
3850      fCorrelationsPro[0][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
3851                                        (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
3852                                        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
3853     }
3854    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
3855      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
3856    
3857   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
3858  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
3859
3860  
3861    
3862     
3863       
3864 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D()
3865
3866
3867
3868  
3869  
3870
3871 //================================================================================================================================
3872
3873
3874 void AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
3875 {
3876  // calculate all weighted correlations needed for differential flow 
3877  
3878   if(type == "RP") // to be improved (removed)
3879  {
3880   cout<<endl;
3881  }
3882  // ... 
3883  
3884  
3885  
3886  
3887  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
3888  Double_t dReQ1n1k = (*fReQ)(0,1);
3889  Double_t dReQ2n2k = (*fReQ)(1,2);
3890  Double_t dReQ1n3k = (*fReQ)(0,3);
3891  //Double_t dReQ4n4k = (*fReQ)(3,4);
3892  Double_t dImQ1n1k = (*fImQ)(0,1);
3893  Double_t dImQ2n2k = (*fImQ)(1,2);
3894  Double_t dImQ1n3k = (*fImQ)(0,3);
3895  //Double_t dImQ4n4k = (*fImQ)(3,4);
3896  
3897  // S^M_{p,k} (see .h file for the definition of fSMpk):
3898  Double_t dSM1p1k = (*fSMpk)(0,1);
3899  Double_t dSM1p2k = (*fSMpk)(0,2);
3900  Double_t dSM1p3k = (*fSMpk)(0,3);
3901  Double_t dSM2p1k = (*fSMpk)(1,1);
3902  Double_t dSM3p1k = (*fSMpk)(2,1);
3903  
3904  // looping over all (pt,eta) bins and calculating weighted correlations needed for differential flow: 
3905  for(Int_t p=1;p<=fnBinsPt;p++)
3906  {
3907   for(Int_t e=1;e<=fnBinsEta;e++)
3908   {
3909    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
3910    Double_t p1n0kRe = 0.;
3911    Double_t p1n0kIm = 0.;
3912
3913    // number of POIs in particular (pt,eta) bin):
3914    Double_t mp = 0.;
3915
3916    // real and imaginary parts of q_{m*n,k}: 
3917    // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
3918    Double_t q1n2kRe = 0.;
3919    Double_t q1n2kIm = 0.;
3920    Double_t q2n1kRe = 0.;
3921    Double_t q2n1kIm = 0.;
3922
3923    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
3924    Double_t s1p1k = 0.; 
3925    Double_t s1p2k = 0.; 
3926    Double_t s1p3k = 0.; 
3927    
3928    // M0111 from Eq. (118) in QC2c (to be improved (notation))
3929    Double_t dM0111 = 0.;
3930  
3931    if(type == "POI")
3932    {
3933     // p_{m*n,0}:
3934     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
3935             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
3936     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))
3937             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e)); 
3938             
3939     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
3940     
3941     // q_{m*n,k}: 
3942     q1n2kRe = fReEBE2D[2][0][2]->GetBinContent(fReEBE2D[2][0][2]->GetBin(p,e))
3943             * fReEBE2D[2][0][2]->GetBinEntries(fReEBE2D[2][0][2]->GetBin(p,e));
3944     q1n2kIm = fImEBE2D[2][0][2]->GetBinContent(fImEBE2D[2][0][2]->GetBin(p,e))
3945             * fImEBE2D[2][0][2]->GetBinEntries(fImEBE2D[2][0][2]->GetBin(p,e));
3946     q2n1kRe = fReEBE2D[2][1][1]->GetBinContent(fReEBE2D[2][1][1]->GetBin(p,e))
3947             * fReEBE2D[2][1][1]->GetBinEntries(fReEBE2D[2][1][1]->GetBin(p,e)); 
3948     q2n1kIm = fImEBE2D[2][1][1]->GetBinContent(fImEBE2D[2][1][1]->GetBin(p,e))
3949             * fImEBE2D[2][1][1]->GetBinEntries(fImEBE2D[2][1][1]->GetBin(p,e));
3950        
3951     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
3952     s1p1k = pow(fs2D[2][1]->GetBinContent(fs2D[2][1]->GetBin(p,e)),1.); 
3953     s1p2k = pow(fs2D[2][2]->GetBinContent(fs2D[2][2]->GetBin(p,e)),1.); 
3954     s1p3k = pow(fs2D[2][3]->GetBinContent(fs2D[2][3]->GetBin(p,e)),1.); 
3955    
3956     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
3957     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
3958            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
3959            + 2.*(s1p3k-s1p2k*dSM1p1k));
3960    }
3961    else if(type == "RP")
3962    {
3963     p1n0kRe = fReEBE2D[0][0][0]->GetBinContent(fReEBE2D[0][0][0]->GetBin(p,e))
3964             * fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
3965     p1n0kIm = fImEBE2D[0][0][0]->GetBinContent(fImEBE2D[0][0][0]->GetBin(p,e))
3966             * fImEBE2D[0][0][0]->GetBinEntries(fImEBE2D[0][0][0]->GetBin(p,e));
3967             
3968     mp = fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
3969     
3970     // q_{m*n,k}: 
3971     q1n2kRe = fReEBE2D[0][0][2]->GetBinContent(fReEBE2D[0][0][2]->GetBin(p,e))
3972             * fReEBE2D[0][0][2]->GetBinEntries(fReEBE2D[0][0][2]->GetBin(p,e));
3973     q1n2kIm = fImEBE2D[0][0][2]->GetBinContent(fImEBE2D[0][0][2]->GetBin(p,e))
3974             * fImEBE2D[0][0][2]->GetBinEntries(fImEBE2D[0][0][2]->GetBin(p,e));
3975     q2n1kRe = fReEBE2D[0][1][1]->GetBinContent(fReEBE2D[0][1][1]->GetBin(p,e))
3976             * fReEBE2D[0][1][1]->GetBinEntries(fReEBE2D[0][1][1]->GetBin(p,e));
3977     q2n1kIm = fImEBE2D[0][1][1]->GetBinContent(fImEBE2D[0][1][1]->GetBin(p,e))
3978             * fImEBE2D[0][1][1]->GetBinEntries(fImEBE2D[0][1][1]->GetBin(p,e));
3979    
3980     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
3981     s1p1k = pow(fs2D[0][1]->GetBinContent(fs2D[0][1]->GetBin(p,e)),1.); 
3982     s1p2k = pow(fs2D[0][2]->GetBinContent(fs2D[0][2]->GetBin(p,e)),1.); 
3983     s1p3k = pow(fs2D[0][3]->GetBinContent(fs2D[0][3]->GetBin(p,e)),1.); 
3984    
3985     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
3986     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
3987            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
3988            + 2.*(s1p3k-s1p2k*dSM1p1k));
3989     //...............................................................................................   
3990    }
3991    
3992    // 2'-particle correlation:
3993    Double_t two1n1nW0W1PtEta = 0.;
3994    if(mp*dSM1p1k-s1p1k)
3995    {
3996     two1n1nW0W1PtEta = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
3997                  / (mp*dSM1p1k-s1p1k);
3998    
3999     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
4000     if(type == "POI")
4001     {
4002      //f2pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
4003      //                   mp*dSM1p1k-s1p1k);
4004      fCorrelationsPro[1][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);
4005     }
4006     else if(type == "RP")
4007     {
4008      //f2pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
4009      //                  mp*dSM1p1k-s1p1k); 
4010      fCorrelationsPro[0][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);  
4011     }
4012    } // end of if(mp*dMult-dmPrimePrimePtEta)
4013    
4014    // 4'-particle correlation:
4015    Double_t four1n1n1n1nW0W1W1W1PtEta = 0.;
4016    if(dM0111)
4017    {
4018     four1n1n1n1nW0W1W1W1PtEta = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
4019                       - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
4020                       - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
4021                       - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
4022                       + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
4023                       - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
4024                       - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
4025                       + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
4026                       + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
4027                       + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
4028                       + 2.*s1p1k*dSM1p2k                                      
4029                       - 6.*s1p3k)        
4030                       / dM0111; // to be imropoved (notation of dM0111)
4031    
4032     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
4033     if(type == "POI")
4034     {
4035      //f4pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
4036      fCorrelationsPro[1][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
4037     }
4038     else if(type == "RP")
4039     {
4040      //f4pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
4041      fCorrelationsPro[0][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
4042     }
4043    } // end of if(dM0111)
4044   
4045   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
4046  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
4047  
4048   
4049     
4050       
4051 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
4052
4053
4054 //================================================================================================================================
4055
4056  */  
4057
4058 /*
4059 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
4060 {
4061  // 1.) Access average for 2D correlations from profiles and store them in 2D final results histograms;
4062  // 2.) Access spread for 2D correlations from profiles, calculate error and store it in 2D final results histograms;
4063  // 3.) Make projections along pt and eta axis and store results and errors in 1D final results histograms. 
4064  
4065  Int_t typeFlag = -1;
4066  Int_t pWeightsFlag = -1;
4067  Int_t eWeightsFlag = -1;
4068
4069  if(type == "RP")
4070  {
4071   typeFlag = 0;
4072  } else if(type == "POI")
4073    {
4074     typeFlag = 1;
4075    } else 
4076      {
4077       cout<<"WARNING: type must be either RP or POI in AFAWQC::FCFDF() !!!!"<<endl;
4078       exit(0);
4079      }
4080      
4081  if(!useParticleWeights)
4082  {
4083   pWeightsFlag = 0;
4084  } else 
4085    {
4086     pWeightsFlag = 1;   
4087    }   
4088    
4089  if(eventWeights == "exact")
4090  {
4091   eWeightsFlag = 0;
4092  }          
4093   
4094  // shortcuts:
4095  Int_t t = typeFlag;
4096  Int_t pW = pWeightsFlag;
4097  Int_t eW = eWeightsFlag;
4098  
4099  // from 2D histogram fNonEmptyBins2D make two 1D histograms fNonEmptyBins1D in pt and eta (to be improved (i.e. moved somewhere else))  
4100  // pt:
4101  for(Int_t p=1;p<fnBinsPt;p++)
4102  {
4103   Double_t contentPt = 0.;
4104   for(Int_t e=1;e<=fnBinsEta;e++)
4105   {
4106    contentPt += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
4107   }
4108   fNonEmptyBins1D[t][0]->SetBinContent(p,contentPt);
4109  }
4110  // eta:
4111  for(Int_t e=1;e<fnBinsEta;e++)
4112  {
4113   Double_t contentEta = 0.;
4114   for(Int_t p=1;p<=fnBinsPt;p++)
4115   {
4116    contentEta += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
4117   }
4118   fNonEmptyBins1D[t][1]->SetBinContent(e,contentEta);
4119  }
4120  
4121  // from 2D profile in (pt,eta) make two 1D profiles in (pt) and (eta):
4122  TProfile *profile[2][4]; // [0=pt,1=eta][correlation index] // to be improved (do not hardwire the correlation index)
4123  
4124  for(Int_t pe=0;pe<2;pe++) // pt or eta
4125  {
4126   for(Int_t ci=0;ci<4;ci++) // correlation index
4127   {
4128    if(pe==0) profile[pe][ci] = this->MakePtProjection(fCorrelationsPro[t][pW][eW][ci]);
4129    if(pe==1) profile[pe][ci] = this->MakeEtaProjection(fCorrelationsPro[t][pW][eW][ci]);
4130   }
4131  }
4132   
4133  // transfer 2D profile into 2D histogram:
4134  // to be improved (see in documentation if there is a method to transfer values from 2D profile into 2D histogram)    
4135  for(Int_t ci=0;ci<4;ci++)
4136  {
4137   for(Int_t p=1;p<=fnBinsPt;p++)
4138   {
4139    for(Int_t e=1;e<=fnBinsEta;e++)
4140    {
4141     Double_t correlation = fCorrelationsPro[t][pW][eW][ci]->GetBinContent(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e)); 
4142     Double_t spread = fCorrelationsPro[t][pW][eW][ci]->GetBinError(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e));
4143     Double_t nEvts = fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e));
4144     Double_t error = 0.;
4145     fFinalCorrelations2D[t][pW][eW][ci]->SetBinContent(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),correlation);          
4146     if(nEvts>0)
4147     {
4148      error = spread/pow(nEvts,0.5);
4149      fFinalCorrelations2D[t][pW][eW][ci]->SetBinError(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),error);
4150     }
4151    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
4152   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
4153  } // end of for(Int_t ci=0;ci<4;ci++)
4154  
4155  // transfer 1D profile into 1D histogram (pt):
4156  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
4157  for(Int_t ci=0;ci<4;ci++)
4158  {
4159   for(Int_t p=1;p<=fnBinsPt;p++)
4160   {
4161    if(profile[0][ci])
4162    {
4163     Double_t correlation = profile[0][ci]->GetBinContent(p); 
4164     Double_t spread = profile[0][ci]->GetBinError(p);
4165     Double_t nEvts = fNonEmptyBins1D[t][0]->GetBinContent(p);
4166     Double_t error = 0.;
4167     fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinContent(p,correlation); 
4168     if(nEvts>0)
4169     {
4170      error = spread/pow(nEvts,0.5);
4171      fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinError(p,error);
4172     }  
4173    }   
4174   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
4175  } // end of for(Int_t ci=0;ci<4;ci++)
4176  
4177  // transfer 1D profile into 1D histogram (eta):
4178  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
4179  for(Int_t ci=0;ci<4;ci++)
4180  {
4181   for(Int_t e=1;e<=fnBinsEta;e++)
4182   {
4183    if(profile[1][ci])
4184    {
4185     Double_t correlation = profile[1][ci]->GetBinContent(e); 
4186     fFinalCorrelations1D[t][pW][eW][1][ci]->SetBinContent(e,correlation);      
4187    }    
4188   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
4189  } // end of for(Int_t ci=0;ci<4;ci++)
4190         
4191 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
4192 */
4193
4194
4195 //================================================================================================================================
4196
4197
4198 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, TString ptOrEta)
4199 {
4200  // calcualate cumulants for differential flow from measured correlations
4201  // Remark: cumulants calculated here are NOT corrected for non-uniform acceptance. This correction is applied in the method ...
4202  // to be improved (description) 
4203  
4204  Int_t typeFlag = -1;
4205  Int_t ptEtaFlag = -1;
4206
4207  if(type == "RP")
4208  {
4209   typeFlag = 0;
4210  } else if(type == "POI")
4211    {
4212     typeFlag = 1;
4213    } 
4214      
4215  if(ptOrEta == "Pt")
4216  {
4217   ptEtaFlag = 0;
4218  } else if(ptOrEta == "Eta")
4219    {
4220     ptEtaFlag = 1;
4221    } 
4222   
4223  // shortcuts:
4224  Int_t t = typeFlag;
4225  Int_t pe = ptEtaFlag;
4226      
4227  // common:
4228  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
4229  
4230  // correlation <<2>>: 
4231  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
4232  
4233  // 1D:
4234  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
4235  {
4236   // reduced correlations:   
4237   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>(pt)
4238   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>(pt)
4239   // final statistical error of reduced correlations:
4240   //Double_t twoPrimeError = fFinalCorrelations1D[t][pW][eW][0][0]->GetBinError(p); 
4241   // QC{2'}:
4242   Double_t qc2Prime = twoPrime; // QC{2'}
4243   //Double_t qc2PrimeError = twoPrimeError; // final stat. error of QC{2'}
4244   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime); 
4245   //fFinalCumulantsPt[t][pW][eW][nua][0]->SetBinError(p,qc2PrimeError);   
4246   // QC{4'}:
4247   Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
4248   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime); 
4249  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
4250  
4251     
4252  /* 
4253  // 2D (pt,eta):
4254  // to be improved (see documentation if I can do all this without looping)
4255  for(Int_t p=1;p<=fnBinsPt;p++)
4256  {
4257   for(Int_t e=1;e<=fnBinsEta;e++) 
4258   {  
4259    // reduced correlations:   
4260    Double_t twoPrime = fFinalCorrelations2D[t][pW][eW][0]->GetBinContent(fFinalCorrelations2D[t][pW][eW][0]->GetBin(p,e)); // <<2'>>(pt,eta)
4261    Double_t fourPrime = fFinalCorrelations2D[t][pW][eW][1]->GetBinContent(fFinalCorrelations2D[t][pW][eW][1]->GetBin(p,e)); // <<4'>>(pt,eta)
4262    for(Int_t nua=0;nua<2;nua++)
4263    {
4264     // QC{2'}:
4265     Double_t qc2Prime = twoPrime; // QC{2'} = <<2'>>
4266     fFinalCumulants2D[t][pW][eW][nua][0]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e),qc2Prime);    
4267     // QC{4'}:
4268     Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
4269     fFinalCumulants2D[t][pW][eW][nua][1]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e),qc4Prime);   
4270    } // end of for(Int_t nua=0;nua<2;nua++)   
4271   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
4272  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
4273  */
4274    
4275 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, Bool_t useParticleWeights, TString eventWeights); 
4276
4277
4278 //================================================================================================================================
4279
4280
4281 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
4282 {
4283  // calculate final results for integrated flow of RPs and POIs 
4284   
4285  Int_t typeFlag = -1;
4286
4287  if(type == "RP")
4288  {
4289   typeFlag = 0;
4290  } else if(type == "POI")
4291    {
4292     typeFlag = 1;
4293    } else 
4294      {
4295       cout<<"WARNING: type must be either RP or POI in AFAWQC::CDF() !!!!"<<endl;
4296       exit(0);
4297      }
4298      
4299  // shortcuts:
4300  Int_t t = typeFlag;
4301   
4302  // pt yield:    
4303  TH1F *yield2ndPt = NULL;
4304  TH1F *yield4thPt = NULL;
4305  TH1F *yield6thPt = NULL;
4306  TH1F *yield8thPt = NULL;
4307  
4308  if(type == "POI")
4309  {
4310   yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtPOI())->Clone();
4311   yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtPOI())->Clone();
4312   yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtPOI())->Clone();
4313   yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtPOI())->Clone();  
4314  } 
4315  else if(type == "RP")
4316  {
4317   yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtRP())->Clone();
4318   yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtRP())->Clone();
4319   yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtRP())->Clone();
4320   yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtRP())->Clone();  
4321  } 
4322  
4323  Int_t nBinsPt = yield2ndPt->GetNbinsX();
4324  
4325  TH1D *flow2ndPt = NULL;
4326  TH1D *flow4thPt = NULL;
4327  TH1D *flow6thPt = NULL;
4328  TH1D *flow8thPt = NULL;
4329  
4330  // to be improved (hardwired pt index)
4331  flow2ndPt = (TH1D*)fDiffFlow[t][0][0]->Clone();
4332  flow4thPt = (TH1D*)fDiffFlow[t][0][1]->Clone();
4333  flow6thPt = (TH1D*)fDiffFlow[t][0][2]->Clone();
4334  flow8thPt = (TH1D*)fDiffFlow[t][0][3]->Clone(); 
4335    
4336  Double_t dvn2nd = 0., dvn4th = 0., dvn6th = 0., dvn8th = 0.; // differential flow
4337  Double_t dErrvn2nd = 0., dErrvn4th = 0., dErrvn6th = 0., dErrvn8th = 0.; // error on differential flow
4338  
4339  Double_t dVn2nd = 0., dVn4th = 0., dVn6th = 0., dVn8th = 0.; // integrated flow 
4340  Double_t dErrVn2nd = 0., dErrVn4th = 0., dErrVn6th = 0., dErrVn8th = 0.; // error on integrated flow
4341
4342  Double_t dYield2nd = 0., dYield4th = 0., dYield6th = 0., dYield8th = 0.; // pt yield 
4343  Double_t dSum2nd = 0., dSum4th = 0., dSum6th = 0., dSum8th = 0.; // needed for normalizing integrated flow
4344  
4345  // looping over pt bins:
4346  for(Int_t p=1;p<nBinsPt+1;p++)
4347  {
4348   dvn2nd = flow2ndPt->GetBinContent(p);
4349   dvn4th = flow4thPt->GetBinContent(p);
4350   dvn6th = flow6thPt->GetBinContent(p);
4351   dvn8th = flow8thPt->GetBinContent(p);
4352   
4353   dErrvn2nd = flow2ndPt->GetBinError(p);
4354   dErrvn4th = flow4thPt->GetBinError(p);
4355   dErrvn6th = flow6thPt->GetBinError(p);
4356   dErrvn8th = flow8thPt->GetBinError(p);
4357
4358   dYield2nd = yield2ndPt->GetBinContent(p);  
4359   dYield4th = yield4thPt->GetBinContent(p);
4360   dYield6th = yield6thPt->GetBinContent(p);
4361   dYield8th = yield8thPt->GetBinContent(p);
4362   
4363   dVn2nd += dvn2nd*dYield2nd;
4364   dVn4th += dvn4th*dYield4th;
4365   dVn6th += dvn6th*dYield6th;
4366   dVn8th += dvn8th*dYield8th;
4367   
4368   dSum2nd += dYield2nd;
4369   dSum4th += dYield4th;
4370   dSum6th += dYield6th;
4371   dSum8th += dYield8th;
4372   
4373   dErrVn2nd += dYield2nd*dYield2nd*dErrvn2nd*dErrvn2nd; // ro be improved (check this relation)
4374   dErrVn4th += dYield4th*dYield4th*dErrvn4th*dErrvn4th;
4375   dErrVn6th += dYield6th*dYield6th*dErrvn6th*dErrvn6th;
4376   dErrVn8th += dYield8th*dYield8th*dErrvn8th*dErrvn8th;
4377     
4378  } // end of for(Int_t p=1;p<nBinsPt+1;p++)
4379
4380  // normalizing the results for integrated flow:
4381  if(dSum2nd) 
4382  {
4383   dVn2nd /= dSum2nd;
4384   dErrVn2nd /= (dSum2nd*dSum2nd);
4385   dErrVn2nd = TMath::Sqrt(dErrVn2nd);
4386  } 
4387  if(dSum4th) 
4388  {
4389   dVn4th /= dSum4th;
4390   dErrVn4th /= (dSum4th*dSum4th);
4391   dErrVn4th = TMath::Sqrt(dErrVn4th);
4392  } 
4393  //if(dSum6th) dVn6th/=dSum6th;
4394  //if(dSum8th) dVn8th/=dSum8th;
4395   
4396  // storing the results for integrated flow in common histos: (to be improved: new method for this?)
4397  if(type == "POI")
4398  {
4399   fCommonHistsResults2nd->FillIntegratedFlowPOI(dVn2nd,dErrVn2nd); 
4400   fCommonHistsResults4th->FillIntegratedFlowPOI(dVn4th,dErrVn4th); 
4401   fCommonHistsResults6th->FillIntegratedFlowPOI(dVn6th,0.); // to be improved (errors)
4402   fCommonHistsResults8th->FillIntegratedFlowPOI(dVn8th,0.); // to be improved (errors)
4403  }
4404  else if (type == "RP")
4405  {
4406   fCommonHistsResults2nd->FillIntegratedFlowRP(dVn2nd,dErrVn2nd); 
4407   fCommonHistsResults4th->FillIntegratedFlowRP(dVn4th,dErrVn4th);
4408   fCommonHistsResults6th->FillIntegratedFlowRP(dVn6th,0.); // to be improved (errors)
4409   fCommonHistsResults8th->FillIntegratedFlowRP(dVn8th,0.); // to be improved (errors)
4410  }
4411  
4412  delete flow2ndPt;
4413  delete flow4thPt;
4414  //delete flow6thPt;
4415  //delete flow8thPt;
4416  
4417  delete yield2ndPt;
4418  delete yield4thPt;
4419  delete yield6thPt;
4420  delete yield8thPt;
4421            
4422 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
4423
4424
4425 //================================================================================================================================
4426
4427
4428 void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
4429 {
4430  // Initialize all arrays used for distributions.
4431  
4432  // a) Initialize arrays of histograms used to hold distributions of correlations; 
4433  // b) Initialize array to hold min and max values of correlations.
4434  
4435  // a) Initialize arrays of histograms used to hold distributions of correlations:
4436  for(Int_t di=0;di<4;di++) // distribution index
4437  {
4438   fDistributions[di] = NULL;
4439  }
4440  
4441  // b) Initialize default min and max values of correlations:
4442  //    (Remark: The default values bellow were chosen for v2=5% and M=500)
4443  fMinValueOfCorrelation[0] = -0.01; // <2>_min 
4444  fMaxValueOfCorrelation[0] = 0.04; // <2>_max 
4445  fMinValueOfCorrelation[1] = -0.00002; // <4>_min 
4446  fMaxValueOfCorrelation[1] = 0.00015; // <4>_max  
4447  fMinValueOfCorrelation[2] = -0.0000003; // <6>_min 
4448  fMaxValueOfCorrelation[2] = 0.0000006; // <6>_max  
4449  fMinValueOfCorrelation[3] = -0.000000006; // <8>_min 
4450  fMaxValueOfCorrelation[3] = 0.000000003; // <8>_max 
4451  
4452 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
4453
4454
4455 //================================================================================================================================
4456
4457
4458 void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
4459 {
4460  // a) Book profile to hold all flags for distributions of correlations;
4461  // b) Book all histograms to hold distributions of correlations.
4462  
4463  TString correlationIndex[4] = {"<2>","<4>","<6>","<8>"}; // to be improved (should I promote this to data members?)
4464   
4465  // a) Book profile to hold all flags for distributions of correlations:
4466  TString distributionsFlagsName = "fDistributionsFlags";
4467  distributionsFlagsName += fAnalysisLabel->Data();
4468  fDistributionsFlags = new TProfile(distributionsFlagsName.Data(),"Flags for Distributions of Correlations",9,0,9);
4469  fDistributionsFlags->SetTickLength(-0.01,"Y");
4470  fDistributionsFlags->SetMarkerStyle(25);
4471  fDistributionsFlags->SetLabelSize(0.05);
4472  fDistributionsFlags->SetLabelOffset(0.02,"Y");
4473  fDistributionsFlags->GetXaxis()->SetBinLabel(1,"Store or not?");
4474  fDistributionsFlags->GetXaxis()->SetBinLabel(2,"<2>_{min}");
4475  fDistributionsFlags->GetXaxis()->SetBinLabel(3,"<2>_{max}");
4476  fDistributionsFlags->GetXaxis()->SetBinLabel(4,"<4>_{min}");
4477  fDistributionsFlags->GetXaxis()->SetBinLabel(5,"<4>_{max}");
4478  fDistributionsFlags->GetXaxis()->SetBinLabel(6,"<6>_{min}");
4479  fDistributionsFlags->GetXaxis()->SetBinLabel(7,"<6>_{max}");
4480  fDistributionsFlags->GetXaxis()->SetBinLabel(8,"<8>_{min}");
4481  fDistributionsFlags->GetXaxis()->SetBinLabel(9,"<8>_{max}");
4482  fDistributionsList->Add(fDistributionsFlags);
4483  
4484  // b) Book all histograms to hold distributions of correlations.
4485  if(fStoreDistributions)
4486  { 
4487   TString distributionsName = "fDistributions";
4488   distributionsName += fAnalysisLabel->Data();
4489   for(Int_t di=0;di<4;di++) // distribution index
4490   {
4491    fDistributions[di] = new TH1D(Form("Distribution of %s",correlationIndex[di].Data()),Form("Distribution of %s",correlationIndex[di].Data()),10000,fMinValueOfCorrelation[di],fMaxValueOfCorrelation[di]); 
4492    fDistributions[di]->SetXTitle(correlationIndex[di].Data());
4493    fDistributionsList->Add(fDistributions[di]);
4494   } // end of for(Int_t di=0;di<4;di++) // distribution index
4495  } // end of if(fStoreDistributions)
4496  
4497 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
4498
4499
4500 //================================================================================================================================
4501
4502
4503 void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
4504 {
4505  // Store all flags for distributiuons of correlations in profile fDistributionsFlags.
4506  
4507  if(!fDistributionsFlags)
4508  {
4509   cout<<"WARNING: fDistributionsFlags is NULL in AFAWQC::SDF() !!!!"<<endl;
4510   exit(0);
4511  } 
4512
4513  fDistributionsFlags->Fill(0.5,(Int_t)fStoreDistributions); // histos with distributions of correlations stored or not in the output file
4514  // store min and max values of correlations:
4515  for(Int_t di=0;di<4;di++) // distribution index
4516  {
4517   fDistributionsFlags->Fill(1.5+2.*(Double_t)di,fMinValueOfCorrelation[di]);
4518   fDistributionsFlags->Fill(2.5+2.*(Double_t)di,fMaxValueOfCorrelation[di]);
4519  }
4520      
4521 } // end of void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
4522
4523
4524 //================================================================================================================================
4525
4526
4527 void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
4528 {
4529  // Store distributions of correlations.
4530  
4531  if(!(fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE))
4532  {
4533   cout<<"WARNING: fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE"<<endl; 
4534   cout<<"         is NULL in AFAWQC::SDOC() !!!!"<<endl;
4535   exit(0);
4536  }
4537
4538  for(Int_t di=0;di<4;di++) // distribution index
4539  {
4540   if(!fDistributions[di])
4541   { 
4542    cout<<"WARNING: fDistributions[di] is NULL in AFAWQC::SDOC() !!!!"<<endl;
4543    cout<<"di = "<<di<<endl;
4544    exit(0);
4545   } else 
4546     {
4547      fDistributions[di]->Fill(fIntFlowCorrelationsEBE->GetBinContent(di+1),fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(di+1)); 
4548     } 
4549  } // end of for(Int_t di=0;di<4;di++) // distribution index
4550
4551 } // end of void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
4552
4553
4554 //================================================================================================================================
4555
4556
4557 void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
4558 {
4559  // Book and nest all lists nested in the base list fHistList.
4560  //  a) Book and nest lists for integrated flow;
4561  //  b) Book and nest lists for differential flow;
4562  //  c) Book and nest list for particle weights;
4563  //  d) Book and nest list for distributions;
4564  //  e) Book and nest list for nested loops;
4565  
4566  // a) Book and nest all lists for integrated flow:
4567  // base list for integrated flow:
4568  fIntFlowList = new TList();
4569  fIntFlowList->SetName("Integrated Flow");
4570  fIntFlowList->SetOwner(kTRUE);
4571  fHistList->Add(fIntFlowList);
4572  // list holding profiles: 
4573  fIntFlowProfiles = new TList();
4574  fIntFlowProfiles->SetName("Profiles");
4575  fIntFlowProfiles->SetOwner(kTRUE);
4576  fIntFlowList->Add(fIntFlowProfiles);
4577  // list holding histograms with results:
4578  fIntFlowResults = new TList();
4579  fIntFlowResults->SetName("Results");
4580  fIntFlowResults->SetOwner(kTRUE);
4581  fIntFlowList->Add(fIntFlowResults);
4582  
4583  // b) Book and nest lists for differential flow;
4584  fDiffFlowList = new TList();
4585  fDiffFlowList->SetName("Differential Flow");
4586  fDiffFlowList->SetOwner(kTRUE); 
4587  fHistList->Add(fDiffFlowList);
4588  // list holding profiles: 
4589  fDiffFlowProfiles = new TList(); 
4590  fDiffFlowProfiles->SetName("Profiles");
4591  fDiffFlowProfiles->SetOwner(kTRUE);
4592  fDiffFlowList->Add(fDiffFlowProfiles);
4593  // list holding histograms with results: 
4594  fDiffFlowResults = new TList();
4595  fDiffFlowResults->SetName("Results");
4596  fDiffFlowResults->SetOwner(kTRUE);
4597  fDiffFlowList->Add(fDiffFlowResults);
4598  // flags used for naming nested lists in list fDiffFlowProfiles and fDiffFlowResults:  
4599  TList list;
4600  list.SetOwner(kTRUE);
4601  TString typeFlag[2] = {"RP","POI"};  
4602  TString ptEtaFlag[2] = {"p_{T}","#eta"}; 
4603  TString powerFlag[2] = {"linear","quadratic"};   
4604  // nested lists in fDiffFlowProfiles (~/Differential Flow/Profiles):
4605  for(Int_t t=0;t<2;t++) // type: RP or POI
4606  {
4607   for(Int_t pe=0;pe<2;pe++) // pt or eta
4608   {
4609    // list holding profiles with correlations:
4610    fDiffFlowCorrelationsProList[t][pe] = (TList*)list.Clone();
4611    fDiffFlowCorrelationsProList[t][pe]->SetName(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4612    fDiffFlowProfiles->Add(fDiffFlowCorrelationsProList[t][pe]);
4613    // list holding profiles with products of correlations:
4614    fDiffFlowProductOfCorrelationsProList[t][pe] = (TList*)list.Clone();
4615    fDiffFlowProductOfCorrelationsProList[t][pe]->SetName(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4616    fDiffFlowProfiles->Add(fDiffFlowProductOfCorrelationsProList[t][pe]);
4617    // list holding profiles with corrections:
4618    fDiffFlowCorrectionsProList[t][pe] = (TList*)list.Clone();
4619    fDiffFlowCorrectionsProList[t][pe]->SetName(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4620    fDiffFlowProfiles->Add(fDiffFlowCorrectionsProList[t][pe]);   
4621   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
4622  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI   
4623  // nested lists in fDiffFlowResults (~/Differential Flow/Results):
4624  for(Int_t t=0;t<2;t++) // type: RP or POI
4625  {
4626   for(Int_t pe=0;pe<2;pe++) // pt or eta
4627   {
4628    // list holding histograms with correlations:
4629    fDiffFlowCorrelationsHistList[t][pe] = (TList*)list.Clone();
4630    fDiffFlowCorrelationsHistList[t][pe]->SetName(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4631    fDiffFlowResults->Add(fDiffFlowCorrelationsHistList[t][pe]);
4632    // list holding histograms with corrections:
4633    fDiffFlowCorrectionsHistList[t][pe] = (TList*)list.Clone();
4634    fDiffFlowCorrectionsHistList[t][pe]->SetName(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4635    fDiffFlowResults->Add(fDiffFlowCorrectionsHistList[t][pe]);   
4636    for(Int_t power=0;power<2;power++)
4637    {
4638     // list holding histograms with sums of event weights:
4639     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = (TList*)list.Clone();
4640     fDiffFlowSumOfEventWeightsHistList[t][pe][power]->SetName(Form("Sum of %s event weights (%s, %s)",powerFlag[power].Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4641     fDiffFlowResults->Add(fDiffFlowSumOfEventWeightsHistList[t][pe][power]);    
4642    } // end of for(Int_t power=0;power<2;power++)
4643    // list holding histograms with sums of products of event weights:
4644    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = (TList*)list.Clone();
4645    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->SetName(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4646    fDiffFlowResults->Add(fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]);
4647    // list holding histograms with covariances of correlations:
4648    fDiffFlowCovariancesHistList[t][pe] = (TList*)list.Clone();
4649    fDiffFlowCovariancesHistList[t][pe]->SetName(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4650    fDiffFlowResults->Add(fDiffFlowCovariancesHistList[t][pe]);
4651    // list holding histograms with differential Q-cumulants:
4652    fDiffFlowCumulantsHistList[t][pe] = (TList*)list.Clone();
4653    fDiffFlowCumulantsHistList[t][pe]->SetName(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4654    fDiffFlowResults->Add(fDiffFlowCumulantsHistList[t][pe]);   
4655    // list holding histograms with differential flow estimates from Q-cumulants:
4656    fDiffFlowHistList[t][pe] = (TList*)list.Clone();
4657    fDiffFlowHistList[t][pe]->SetName(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
4658    fDiffFlowResults->Add(fDiffFlowHistList[t][pe]);      
4659   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
4660  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
4661   
4662  // c) Book and nest list for particle weights:
4663  fWeightsList->SetName("Weights");
4664  fWeightsList->SetOwner(kTRUE);   
4665  fHistList->Add(fWeightsList); 
4666
4667  // d) Book and nest list for distributions:
4668  fDistributionsList = new TList();
4669  fDistributionsList->SetName("Distributions");
4670  fDistributionsList->SetOwner(kTRUE);
4671  fHistList->Add(fDistributionsList);
4672  
4673  // e) Book and nest list for nested loops:
4674  fNestedLoopsList = new TList();
4675  fNestedLoopsList->SetName("Nested Loops");
4676  fNestedLoopsList->SetOwner(kTRUE);
4677  fHistList->Add(fNestedLoopsList);
4678  
4679 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
4680
4681
4682 //================================================================================================================================
4683
4684
4685 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type)
4686 {
4687  // fill common result histograms for differential flow
4688  
4689  Int_t typeFlag = -1;
4690  //Int_t ptEtaFlag = -1;
4691
4692  if(type == "RP")
4693  {
4694   typeFlag = 0;
4695  } else if(type == "POI")
4696    {
4697     typeFlag = 1;
4698    } 
4699   
4700  // shortcuts:
4701  Int_t t = typeFlag;
4702  //Int_t pe = ptEtaFlag;
4703
4704  // to be improved (implement protection here)
4705      
4706  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
4707  {
4708   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
4709   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
4710   exit(0);
4711  }
4712  
4713  // pt:
4714  for(Int_t p=1;p<=fnBinsPt;p++)
4715  {
4716   Double_t v2 = fDiffFlow[t][0][0]->GetBinContent(p);
4717   Double_t v4 = fDiffFlow[t][0][1]->GetBinContent(p);
4718   Double_t v6 = fDiffFlow[t][0][2]->GetBinContent(p);
4719   Double_t v8 = fDiffFlow[t][0][3]->GetBinContent(p);
4720   
4721   Double_t v2Error = fDiffFlow[t][0][0]->GetBinError(p);
4722   Double_t v4Error = fDiffFlow[t][0][1]->GetBinError(p);
4723   //Double_t v6Error = fFinalFlow1D[t][pW][nua][0][2]->GetBinError(p);
4724   //Double_t v8Error = fFinalFlow1D[t][pW][nua][0][3]->GetBinError(p);
4725  
4726   if(type == "RP")
4727   {
4728    fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,v2,v2Error);
4729    fCommonHistsResults4th->FillDifferentialFlowPtRP(p,v4,v4Error);
4730    fCommonHistsResults6th->FillDifferentialFlowPtRP(p,v6,0.);
4731    fCommonHistsResults8th->FillDifferentialFlowPtRP(p,v8,0.);
4732   } else if(type == "POI")
4733     {
4734      fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,v2,v2Error);
4735      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,v4,v4Error);
4736      fCommonHistsResults6th->FillDifferentialFlowPtPOI(p,v6,0.);
4737      fCommonHistsResults8th->FillDifferentialFlowPtPOI(p,v8,0.);
4738     }
4739  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
4740  
4741  // eta:
4742  for(Int_t e=1;e<=fnBinsEta;e++)
4743  {
4744   Double_t v2 = fDiffFlow[t][1][0]->GetBinContent(e);
4745   Double_t v4 = fDiffFlow[t][1][1]->GetBinContent(e);
4746   Double_t v6 = fDiffFlow[t][1][2]->GetBinContent(e);
4747   Double_t v8 = fDiffFlow[t][1][3]->GetBinContent(e);
4748   
4749   Double_t v2Error = fDiffFlow[t][1][0]->GetBinError(e);
4750   Double_t v4Error = fDiffFlow[t][1][1]->GetBinError(e);
4751   //Double_t v6Error = fDiffFlow[t][1][2]->GetBinError(e);
4752   //Double_t v8Error = fDiffFlow[t][1][3]->GetBinError(e);
4753  
4754   if(type == "RP")
4755   {
4756    fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,v2,v2Error);
4757    fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,v4,v4Error);
4758    fCommonHistsResults6th->FillDifferentialFlowEtaRP(e,v6,0.);
4759    fCommonHistsResults8th->FillDifferentialFlowEtaRP(e,v8,0.);
4760   } else if(type == "POI")
4761     {
4762      fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,v2,v2Error);
4763      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,v4,v4Error);
4764      fCommonHistsResults6th->FillDifferentialFlowEtaPOI(e,v6,0.);
4765      fCommonHistsResults8th->FillDifferentialFlowEtaPOI(e,v8,0.);
4766     }
4767  } // end of for(Int_t e=1;e<=fnBinsEta;e++)    
4768  
4769 } // end of void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
4770
4771
4772 //================================================================================================================================
4773
4774
4775 void AliFlowAnalysisWithQCumulants::AccessConstants()
4776 {
4777  // Access needed common constants from AliFlowCommonConstants
4778  
4779  fnBinsPhi = AliFlowCommonConstants::GetMaster()->GetNbinsPhi();
4780  fPhiMin = AliFlowCommonConstants::GetMaster()->GetPhiMin();         
4781  fPhiMax = AliFlowCommonConstants::GetMaster()->GetPhiMax();
4782  if(fnBinsPhi) fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;  
4783  fnBinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
4784  fPtMin = AliFlowCommonConstants::GetMaster()->GetPtMin();           
4785  fPtMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
4786  if(fnBinsPt) fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;  
4787  fnBinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
4788  fEtaMin = AliFlowCommonConstants::GetMaster()->GetEtaMin();         
4789  fEtaMax = AliFlowCommonConstants::GetMaster()->GetEtaMax();
4790  if(fnBinsEta) fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;  
4791  
4792 } // end of void AliFlowAnalysisWithQCumulants::AccessConstants()
4793
4794
4795 //================================================================================================================================
4796
4797
4798 void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
4799 {
4800  // a) Cross check if the choice for multiplicity weights make sense;
4801  
4802  // a) Cross check if the choice for multiplicity weights make sense:
4803  if(strcmp(fMultiplicityWeight->Data(),"combinations") && 
4804     strcmp(fMultiplicityWeight->Data(),"unit") &&
4805     strcmp(fMultiplicityWeight->Data(),"multiplicity"))
4806  {
4807   cout<<"WARNING (QC): Multiplicity weight can be either \"combinations\", \"unit\""<<endl;
4808   cout<<"              or \"multiplicity\". Certainly not \""<<fMultiplicityWeight->Data()<<"\"."<<endl;
4809   exit(0);
4810  }   
4811  
4812 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
4813
4814
4815 //================================================================================================================================
4816
4817
4818 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
4819 {
4820  // Calculate sum of linear and quadratic event weights for correlations
4821  
4822  
4823  /*
4824  Double_t dMult = (*fSMpk)(0,0); // multiplicity 
4825
4826  Double_t eventWeight[4] = {0}; 
4827  
4828  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
4829  {
4830   eventWeight[0] = dMult*(dMult-1); // event weight for <2> 
4831   eventWeight[1] = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
4832   eventWeight[2] = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
4833   eventWeight[3] = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
4834  } else
4835    {
4836     eventWeight[0] = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j;
4837     eventWeight[1] = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
4838                    + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4839                    + 3.*(*fSMpk)(1,2)-6.*(*fSMpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
4840     //eventWeight[2] = ... // to be improved (calculated)               
4841     //eventWeight[3] = ... // to be improved (calculated)              
4842    }
4843  */
4844         
4845                       
4846  for(Int_t p=0;p<2;p++) // power-1
4847  {
4848   for(Int_t ci=0;ci<4;ci++) // correlation index
4849   { 
4850    fIntFlowSumOfEventWeights[p]->Fill(ci+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); 
4851   }
4852  }
4853   
4854 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
4855
4856
4857 //================================================================================================================================
4858
4859
4860 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
4861 {
4862  // Calculate sum of product of event weights for correlations
4863  
4864  
4865  /*
4866  Double_t dMult = (*fSMpk)(0,0); // multiplicity 
4867
4868  Double_t eventWeight[4] = {0}; 
4869  
4870  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
4871  {
4872   eventWeight[0] = dMult*(dMult-1); // event weight for <2> 
4873   eventWeight[1] = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
4874   eventWeight[2] = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
4875   eventWeight[3] = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
4876  } else
4877    {
4878     eventWeight[0] = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j;
4879     eventWeight[1] = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
4880                    + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4881                    + 3.*(*fSMpk)(1,2)-6.*(*fSMpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
4882     //eventWeight[2] = ... // to be improved (calculated)               
4883     //eventWeight[3] = ... // to be improved (calculated)              
4884    }
4885
4886  fIntFlowSumOfProductOfEventWeights->Fill(0.5,eventWeight[0]*eventWeight[1]); 
4887  fIntFlowSumOfProductOfEventWeights->Fill(1.5,eventWeight[0]*eventWeight[2]); 
4888  fIntFlowSumOfProductOfEventWeights->Fill(2.5,eventWeight[0]*eventWeight[3]); 
4889  fIntFlowSumOfProductOfEventWeights->Fill(3.5,eventWeight[1]*eventWeight[2]); 
4890  fIntFlowSumOfProductOfEventWeights->Fill(4.5,eventWeight[1]*eventWeight[3]); 
4891  fIntFlowSumOfProductOfEventWeights->Fill(5.5,eventWeight[2]*eventWeight[3]); 
4892  */
4893   
4894  
4895  Int_t counter = 0;
4896  
4897  for(Int_t ci1=1;ci1<4;ci1++)
4898  {
4899   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
4900   {
4901    fIntFlowSumOfProductOfEventWeights->Fill(0.5+counter++,
4902                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
4903   }
4904  }
4905
4906  
4907
4908 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowIntFlowSumOfProductOfEventWeights()
4909
4910
4911 //================================================================================================================================
4912
4913
4914 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta)
4915 {
4916  // calculate reduced correlations for RPs or POIs in pt or eta bins
4917
4918  // multiplicity:
4919  Double_t dMult = (*fSMpk)(0,0);
4920  
4921  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
4922  Double_t dReQ1n = (*fReQ)(0,0);
4923  Double_t dReQ2n = (*fReQ)(1,0);
4924  //Double_t dReQ3n = (*fReQ)(2,0);
4925  //Double_t dReQ4n = (*fReQ)(3,0);
4926  Double_t dImQ1n = (*fImQ)(0,0);
4927  Double_t dImQ2n = (*fImQ)(1,0);
4928  //Double_t dImQ3n = (*fImQ)(2,0);
4929  //Double_t dImQ4n = (*fImQ)(3,0);
4930
4931  // reduced correlations are stored in fDiffFlowCorrelationsPro[0=RP,1=POI][0=pt,1=eta][correlation index]. Correlation index runs as follows:
4932  // 
4933  // 0: <<2'>>
4934  // 1: <<4'>>
4935  // 2: <<6'>>
4936  // 3: <<8'>>
4937  
4938  Int_t t = -1; // type flag 
4939  Int_t pe = -1; // ptEta flag
4940  
4941  if(type == "RP")
4942  {
4943   t = 0;
4944  } else if(type == "POI")
4945    {
4946     t = 1;
4947    }
4948
4949  if(ptOrEta == "Pt")
4950  {
4951   pe = 0;
4952  } else if(ptOrEta == "Eta")
4953    {
4954     pe = 1;
4955    }
4956     
4957  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
4958  Double_t minPtEta[2] = {fPtMin,fEtaMin};
4959  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
4960  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
4961
4962  // looping over all bins and calculating reduced correlations: 
4963  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
4964  {
4965   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
4966   Double_t p1n0kRe = 0.;
4967   Double_t p1n0kIm = 0.;
4968
4969   // number of POIs in particular pt or eta bin:
4970   Double_t mp = 0.;
4971
4972   // real and imaginary parts of q_{m*n,0} (non-weighted Q-vector evaluated for particles which are both RPs and POIs in particular pt or eta bin):
4973   Double_t q1n0kRe = 0.;
4974   Double_t q1n0kIm = 0.;
4975   Double_t q2n0kRe = 0.;
4976   Double_t q2n0kIm = 0.;
4977
4978   // number of particles which are both RPs and POIs in particular pt or eta bin:
4979   Double_t mq = 0.;
4980    
4981   if(type == "POI")
4982   {
4983    // q_{m*n,0}:
4984    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
4985            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
4986    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
4987            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
4988    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
4989            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
4990    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
4991            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
4992                  
4993    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
4994   } 
4995   else if(type == "RP")
4996   {
4997    // q_{m*n,0}:
4998    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
4999            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
5000    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
5001            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
5002    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
5003            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
5004    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
5005            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
5006                  
5007    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
5008   }
5009       
5010    if(type == "POI")
5011    {
5012     // p_{m*n,0}:
5013     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
5014             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
5015     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
5016             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
5017             
5018     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
5019     
5020     t = 1; // typeFlag = RP or POI
5021    }
5022    else if(type == "RP")
5023    {
5024     // p_{m*n,0} = q_{m*n,0}:
5025     p1n0kRe = q1n0kRe; 
5026     p1n0kIm = q1n0kIm; 
5027             
5028     mp = mq; 
5029     
5030     t = 0; // typeFlag = RP or POI
5031    }
5032       
5033    // 2'-particle correlation for particular (pt,eta) bin:
5034    Double_t two1n1nPtEta = 0.;
5035    if(mp*dMult-mq)
5036    {
5037     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
5038                  / (mp*dMult-mq);
5039    
5040     if(type == "POI") // to be improved (I do not this if)
5041     { 
5042      // fill profile to get <<2'>> for POIs
5043      fDiffFlowCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mp*dMult-mq);
5044      // histogram to store <2'> for POIs e-b-e (needed in some other methods):
5045      fDiffFlowCorrelationsEBE[1][pe][0]->SetBinContent(b,two1n1nPtEta);      
5046      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][0]->SetBinContent(b,mp*dMult-mq);      
5047     }
5048     else if(type == "RP") // to be improved (I do not this if)
5049     {
5050      // profile to get <<2'>> for RPs:
5051      fDiffFlowCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mp*dMult-mq);
5052      // histogram to store <2'> for RPs e-b-e (needed in some other methods):
5053      fDiffFlowCorrelationsEBE[0][pe][0]->SetBinContent(b,two1n1nPtEta); 
5054      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][0]->SetBinContent(b,mp*dMult-mq); 
5055     }
5056    } // end of if(mp*dMult-mq)
5057   
5058    // 4'-particle correlation:
5059    Double_t four1n1n1n1nPtEta = 0.;
5060    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5061        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
5062    {
5063     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5064                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
5065                       - 2.*q2n0kIm*dReQ1n*dImQ1n
5066                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
5067                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
5068                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5069                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
5070                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
5071                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
5072                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
5073                       + 2.*mq*dMult                      
5074                       - 6.*mq)        
5075                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5076                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
5077     
5078     if(type == "POI")
5079     {
5080      // profile to get <<4'>> for POIs:
5081      fDiffFlowCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,
5082                                      (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5083                                      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
5084      // histogram to store <4'> for POIs e-b-e (needed in some other methods):
5085      fDiffFlowCorrelationsEBE[1][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                               
5086      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][1]->SetBinContent(b,(mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5087                                                                         + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                               
5088     }
5089     else if(type == "RP")
5090     {
5091      // profile to get <<4'>> for RPs:
5092      fDiffFlowCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,
5093                                        (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5094                                        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
5095      // histogram to store <4'> for RPs e-b-e (needed in some other methods):
5096      fDiffFlowCorrelationsEBE[0][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                   
5097      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][1]->SetBinContent(b,(mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5098                                                                         + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
5099     }
5100    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5101      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
5102    
5103  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5104  
5105    
5106 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta);
5107
5108
5109 //================================================================================================================================
5110
5111
5112 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights(TString type, TString ptOrEta)
5113 {
5114  // Calculate sums of various event weights for reduced correlations. 
5115  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
5116
5117  Int_t typeFlag = -1;
5118  Int_t ptEtaFlag = -1;
5119
5120  if(type == "RP")
5121  {
5122   typeFlag = 0;
5123  } else if(type == "POI")
5124    {
5125     typeFlag = 1;
5126    } 
5127      
5128  if(ptOrEta == "Pt")
5129  {
5130   ptEtaFlag = 0;
5131  } else if(ptOrEta == "Eta")
5132    {
5133     ptEtaFlag = 1;
5134    } 
5135    
5136  // shortcuts:
5137  Int_t t = typeFlag;
5138  Int_t pe = ptEtaFlag;
5139  
5140  // binning:
5141  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5142  Double_t minPtEta[2] = {fPtMin,fEtaMin};
5143  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
5144  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
5145  
5146  for(Int_t rpq=0;rpq<3;rpq++)
5147  {
5148   for(Int_t m=0;m<4;m++)
5149   {
5150    for(Int_t k=0;k<9;k++)
5151    {
5152     if(!fReRPQ1dEBE[rpq][pe][m][k])
5153     {
5154      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
5155      cout<<"pe  = "<<pe<<endl;
5156      cout<<"rpq = "<<rpq<<endl;
5157      cout<<"m   = "<<m<<endl;
5158      cout<<"k   = "<<k<<endl;
5159      exit(0); 
5160     }
5161    }
5162   }
5163  }  
5164
5165  // multiplicities:
5166  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
5167  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
5168  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
5169  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
5170  
5171  // event weights for reduced correlations:
5172  Double_t dw2 = 0.; // event weight for <2'>
5173  Double_t dw4 = 0.; // event weight for <4'>
5174  //Double_t dw6 = 0.; // event weight for <6'>
5175  //Double_t dw8 = 0.; // event weight for <8'>
5176
5177  // looping over bins:
5178  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5179  {
5180   if(type == "RP")
5181   {
5182    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
5183    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
5184   } else if(type == "POI")
5185     {
5186      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
5187      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
5188     }
5189   
5190   // event weight for <2'>:
5191   dw2 = mp*dMult-mq;  
5192   fDiffFlowSumOfEventWeights[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2);
5193   fDiffFlowSumOfEventWeights[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw2,2.));
5194   
5195   // event weight for <4'>:
5196   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5197      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
5198   fDiffFlowSumOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4);
5199   fDiffFlowSumOfEventWeights[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw4,2.));
5200   
5201   // event weight for <6'>:
5202   //dw6 = ...;  
5203   //fDiffFlowSumOfEventWeights[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6);
5204   //fDiffFlowSumOfEventWeights[t][pe][t][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw6,2.));
5205   
5206   // event weight for <8'>:
5207   //dw8 = ...;  
5208   //fDiffFlowSumOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw8);
5209   //fDiffFlowSumOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw8,2.));   
5210  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++) 
5211  
5212 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights()
5213
5214
5215 //================================================================================================================================
5216
5217
5218 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
5219 {
5220  // Calculate sum of products of various event weights for both types of correlations (the ones for int. and diff. flow). 
5221  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
5222  //
5223  // Important: To fill fDiffFlowSumOfProductOfEventWeights[][][][] use bellow table (i,j) with following constraints: 
5224  // 1.) i<j  
5225  // 2.) do not store terms which DO NOT include reduced correlations;
5226  // Table:
5227  // [0=<2>,1=<2'>,2=<4>,3=<4'>,4=<6>,5=<6'>,6=<8>,7=<8'>] x [0=<2>,1=<2'>,2=<4>,3=<4'>,4=<6>,5=<6'>,6=<8>,7=<8'>]
5228   
5229  Int_t typeFlag = -1;
5230  Int_t ptEtaFlag = -1;
5231
5232  if(type == "RP")
5233  {
5234   typeFlag = 0;
5235  } else if(type == "POI")
5236    {
5237     typeFlag = 1;
5238    } 
5239      
5240  if(ptOrEta == "Pt")
5241  {
5242   ptEtaFlag = 0;
5243  } else if(ptOrEta == "Eta")
5244    {
5245     ptEtaFlag = 1;
5246    } 
5247      
5248  // shortcuts:
5249  Int_t t = typeFlag;
5250  Int_t pe = ptEtaFlag;
5251   
5252  // binning:
5253  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5254  Double_t minPtEta[2] = {fPtMin,fEtaMin};
5255  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
5256  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
5257  
5258  // protection:
5259  for(Int_t rpq=0;rpq<3;rpq++)
5260  {
5261   for(Int_t m=0;m<4;m++)
5262   {
5263    for(Int_t k=0;k<9;k++)
5264    {
5265     if(!fReRPQ1dEBE[rpq][pe][m][k])
5266     {
5267      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
5268      cout<<"pe  = "<<pe<<endl;
5269      cout<<"rpq = "<<rpq<<endl;
5270      cout<<"m   = "<<m<<endl;
5271      cout<<"k   = "<<k<<endl;
5272      exit(0); 
5273     }
5274    }
5275   }
5276  }  
5277  
5278  // multiplicities:
5279  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
5280  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
5281  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
5282  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
5283  
5284  // event weights for correlations:
5285  Double_t dW2 = dMult*(dMult-1); // event weight for <2> 
5286  Double_t dW4 = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
5287  Double_t dW6 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
5288  Double_t dW8 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
5289
5290  // event weights for reduced correlations:
5291  Double_t dw2 = 0.; // event weight for <2'>
5292  Double_t dw4 = 0.; // event weight for <4'>
5293  //Double_t dw6 = 0.; // event weight for <6'>
5294  //Double_t dw8 = 0.; // event weight for <8'>
5295  
5296  // looping over bins:
5297  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5298  {
5299   if(type == "RP")
5300   {
5301    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
5302    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
5303   } else if(type == "POI")
5304     {
5305      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
5306      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
5307     }
5308   
5309   // event weight for <2'>:
5310   dw2 = mp*dMult-mq;  
5311   fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw2); // storing product of even weights for <2> and <2'>
5312   fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW4); // storing product of even weights for <4> and <2'>
5313   fDiffFlowSumOfProductOfEventWeights[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW6); // storing product of even weights for <6> and <2'>
5314   fDiffFlowSumOfProductOfEventWeights[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW8); // storing product of even weights for <8> and <2'>
5315   
5316   // event weight for <4'>:
5317   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5318      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
5319   fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw4); // storing product of even weights for <2> and <4'>
5320   fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw4); // storing product of even weights for <2'> and <4'>
5321   fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw4); // storing product of even weights for <4> and <4'>
5322   fDiffFlowSumOfProductOfEventWeights[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW6); // storing product of even weights for <6> and <4'> 
5323   fDiffFlowSumOfProductOfEventWeights[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW8); // storing product of even weights for <8> and <4'>
5324
5325   // event weight for <6'>:
5326   //dw6 = ...;  
5327   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw6); // storing product of even weights for <2> and <6'>
5328   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw6); // storing product of even weights for <2'> and <6'>
5329   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw6); // storing product of even weights for <4> and <6'>
5330   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw6); // storing product of even weights for <4'> and <6'> 
5331   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw6); // storing product of even weights for <6> and <6'>
5332   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dW8); // storing product of even weights for <6'> and <8>
5333   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
5334
5335   // event weight for <8'>:
5336   //dw8 = ...;  
5337   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw8); // storing product of even weights for <2> and <8'>
5338   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw8); // storing product of even weights for <2'> and <8'>
5339   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw8); // storing product of even weights for <4> and <8'>
5340   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw8); // storing product of even weights for <4'> and <8'> 
5341   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw8); // storing product of even weights for <6> and <8'>
5342   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
5343   //fDiffFlowSumOfProductOfEventWeights[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW8*dw8); // storing product of even weights for <8> and <8'>
5344   
5345   // Table:
5346   // [0=<2>,1=<2'>,2=<4>,3=<4'>,4=<6>,5=<6'>,6=<8>,7=<8'>] x [0=<2>,1=<2'>,2=<4>,3=<4'>,4=<6>,5=<6'>,6=<8>,7=<8'>]
5347    
5348  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5349  
5350
5351
5352 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
5353
5354
5355 //================================================================================================================================
5356
5357
5358 void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
5359 {
5360  // Transfer profiles into histograms and calculate statistical errors correctly.
5361
5362  Int_t typeFlag = -1;
5363  Int_t ptEtaFlag = -1;
5364
5365  if(type == "RP")
5366  {
5367   typeFlag = 0;
5368  } else if(type == "POI")
5369    {
5370     typeFlag = 1;
5371    } 
5372      
5373  if(ptOrEta == "Pt")
5374  {
5375   ptEtaFlag = 0;
5376  } else if(ptOrEta == "Eta")
5377    {
5378     ptEtaFlag = 1;
5379    } 
5380   
5381  // shortcuts:
5382  Int_t t = typeFlag;
5383  Int_t pe = ptEtaFlag;
5384              
5385  for(Int_t rci=0;rci<4;rci++)
5386  {
5387   if(!fDiffFlowCorrelationsPro[t][pe][rci])
5388   {
5389    cout<<"WARNING: fDiffFlowCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
5390    cout<<"t   = "<<t<<endl; 
5391    cout<<"pe  = "<<pe<<endl; 
5392    cout<<"rci = "<<rci<<endl;
5393    exit(0); 
5394   }
5395   for(Int_t power=0;power<2;power++)
5396   {
5397    if(!fDiffFlowSumOfEventWeights[t][pe][power][rci])
5398    {
5399     cout<<"WARNING: fDiffFlowSumOfEventWeights[t][pe][power][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
5400     cout<<"t     = "<<t<<endl; 
5401     cout<<"pe    = "<<pe<<endl;
5402     cout<<"power = "<<power<<endl; 
5403     cout<<"rci   = "<<rci<<endl;
5404     exit(0); 
5405    }   
5406   } // end of for(Int_t power=0;power<2;power++)
5407  } // end of for(Int_t rci=0;rci<4;rci++)
5408     
5409  // common:
5410  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5411  
5412  // transfer 1D profile into 1D histogram:
5413  Double_t correlation = 0.;
5414  Double_t spread = 0.;
5415  Double_t sumOfWeights = 0.; // sum of weights for particular reduced correlations for particular pt or eta bin
5416  Double_t sumOfSquaredWeights = 0.; // sum of squared weights for particular reduced correlations for particular pt or eta bin
5417  Double_t error = 0.; // error = termA * spread * termB
5418                       // termA = (sqrt(sumOfSquaredWeights)/sumOfWeights) 
5419                       // termB = 1/pow(1-termA^2,0.5)
5420  Double_t termA = 0.;                      
5421  Double_t termB = 0.;                      
5422  for(Int_t rci=0;rci<4;rci++) // index of reduced correlation
5423  {
5424   for(Int_t b=1;b<=nBinsPtEta[pe];b++) // number of pt or eta bins
5425   {
5426    correlation = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(b); 
5427    spread = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinError(b);
5428    sumOfWeights = fDiffFlowSumOfEventWeights[t][pe][0][rci]->GetBinContent(b);
5429    sumOfSquaredWeights = fDiffFlowSumOfEventWeights[t][pe][1][rci]->GetBinContent(b);
5430    if(sumOfWeights) termA = (pow(sumOfSquaredWeights,0.5)/sumOfWeights);
5431    if(1.-pow(termA,2.)>0.) termB = 1./pow(1.-pow(termA,2.),0.5); 
5432    error = termA*spread*termB; // final error (unbiased estimator for standard deviation)
5433    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinContent(b,correlation); 
5434    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinError(b,error); 
5435   } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5436  } // end of for(Int_t rci=0;rci<4;rci++)
5437  
5438 } // end of void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
5439
5440
5441 //================================================================================================================================
5442
5443
5444 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
5445 {
5446  // store products: <2><2'>, <2><4'>, <2><6'>, <2><8'>, <2'><4>, 
5447  //                 <2'><4'>, <2'><6>, <2'><6'>, <2'><8>, <2'><8'>,
5448  //                 <4><4'>, <4><6'>, <4><8'>, <4'><6>, <4'><6'>, 
5449  //                 <4'><8>, <4'><8'>, <6><6'>, <6><8'>, <6'><8>, 
5450  //                 <6'><8'>, <8><8'>.
5451   
5452  Int_t typeFlag = -1;
5453  Int_t ptEtaFlag = -1;
5454
5455  if(type == "RP")
5456  {
5457   typeFlag = 0;
5458  } else if(type == "POI")
5459    {
5460     typeFlag = 1;
5461    } 
5462      
5463  if(ptOrEta == "Pt")
5464  {
5465   ptEtaFlag = 0;
5466  } else if(ptOrEta == "Eta")
5467    {
5468     ptEtaFlag = 1;
5469    } 
5470   
5471  // shortcuts:
5472  Int_t t = typeFlag;
5473  Int_t pe = ptEtaFlag;
5474      
5475  // common:
5476  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5477  Double_t minPtEta[2] = {fPtMin,fEtaMin};
5478  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
5479    
5480  // protections // to be improved (add protection for all pointers in this method)
5481  if(!fIntFlowCorrelationsEBE)
5482  {
5483   cout<<"WARNING: fIntFlowCorrelationsEBE is NULL in AFAWQC::CDFPOC() !!!!"<<endl;
5484   exit(0);
5485  } 
5486  
5487  /*    
5488  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
5489  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
5490  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
5491  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
5492  */
5493
5494  // e-b-e correlations:
5495  Double_t twoEBE = fIntFlowCorrelationsEBE->GetBinContent(1); // <2>
5496  Double_t fourEBE = fIntFlowCorrelationsEBE->GetBinContent(2); // <4>
5497  Double_t sixEBE = fIntFlowCorrelationsEBE->GetBinContent(3); // <6>
5498  Double_t eightEBE = fIntFlowCorrelationsEBE->GetBinContent(4); // <8>
5499  
5500  // event weights for correlations:
5501  Double_t dW2 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1); // event weight for <2> 
5502  Double_t dW4 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2); // event weight for <4> 
5503  Double_t dW6 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(3); // event weight for <6> 
5504  Double_t dW8 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(4); // event weight for <8> 
5505   
5506  // e-b-e reduced correlations:
5507  Double_t twoReducedEBE = 0.; // <2'>
5508  Double_t fourReducedEBE = 0.; // <4'>
5509  Double_t sixReducedEBE = 0.; // <6'>
5510  Double_t eightReducedEBE = 0.; // <8'> 
5511  
5512  // event weights for reduced correlations:
5513  Double_t dw2 = 0.; // event weight for <2'>
5514  Double_t dw4 = 0.; // event weight for <4'>
5515  //Double_t dw6 = 0.; // event weight for <6'>
5516  //Double_t dw8 = 0.; // event weight for <8'>
5517
5518  // looping over bins:
5519  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5520  {
5521   // e-b-e reduced correlations:
5522   twoReducedEBE = fDiffFlowCorrelationsEBE[t][pe][0]->GetBinContent(b);
5523   fourReducedEBE = fDiffFlowCorrelationsEBE[t][pe][1]->GetBinContent(b);
5524   sixReducedEBE = fDiffFlowCorrelationsEBE[t][pe][2]->GetBinContent(b);
5525   eightReducedEBE = fDiffFlowCorrelationsEBE[t][pe][3]->GetBinContent(b);
5526   
5527   /*
5528   // to be improved (I should not do this here again)
5529   if(type == "RP")
5530   {
5531    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
5532    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
5533   } else if(type == "POI")
5534     {
5535      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
5536      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
5537     }
5538   
5539   // event weights for reduced correlations:
5540   dw2 = mp*dMult-mq; // weight for <2'> 
5541   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5542      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.); // weight for <4'>
5543   //dw6 = ...     
5544   //dw8 = ...     
5545   
5546   */
5547   
5548   dw2 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->GetBinContent(b);
5549   dw4 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->GetBinContent(b);
5550  
5551   // storing all products:
5552   fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*twoReducedEBE,dW2*dw2); // storing <2><2'>
5553   fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*twoReducedEBE,dW4*dw2); // storing <4><2'>
5554   fDiffFlowProductOfCorrelationsPro[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*twoReducedEBE,dW6*dw2); // storing <6><2'>
5555   fDiffFlowProductOfCorrelationsPro[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*twoReducedEBE,dW8*dw2); // storing <8><2'>
5556   
5557   // event weight for <4'>:
5558   fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*fourReducedEBE,dW2*dw4); // storing <2><4'>
5559   fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*fourReducedEBE,dw2*dw4); // storing <2'><4'>
5560   fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*fourReducedEBE,dW4*dw4); // storing <4><4'>
5561   fDiffFlowProductOfCorrelationsPro[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*fourReducedEBE,dW6*dw4); // storing <6><4'> 
5562   fDiffFlowProductOfCorrelationsPro[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*fourReducedEBE,dW8*dw4); // storing <8><4'>
5563
5564   // event weight for <6'>:
5565   //dw6 = ...;  
5566   //fDiffFlowProductOfCorrelationsPro[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*sixReducedEBE,dW2*dw6); // storing <2><6'>
5567   //fDiffFlowProductOfCorrelationsPro[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*sixReducedEBE,dw2*dw6); // storing <2'><6'>
5568   //fDiffFlowProductOfCorrelationsPro[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*sixReducedEBE,dW4*dw6); // storing <4><6'>
5569   //fDiffFlowProductOfCorrelationsPro[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*sixReducedEBE,dw4*dw6); // storing <4'><6'> 
5570   //fDiffFlowProductOfCorrelationsPro[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*sixReducedEBE,dW6*dw6); // storing <6><6'>
5571   //fDiffFlowProductOfCorrelationsPro[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightEBE,dw6*dW8); // storing <6'><8>
5572   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
5573
5574   // event weight for <8'>:
5575   //dw8 = ...;  
5576   //fDiffFlowProductOfCorrelationsPro[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*eightReducedEBE,dW2*dw8); // storing <2><8'>
5577   //fDiffFlowProductOfCorrelationsPro[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*eightReducedEBE,dw2*dw8); // storing <2'><8'>
5578   //fDiffFlowProductOfCorrelationsPro[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*eightReducedEBE,dW4*dw8); // storing <4><8'>
5579   //fDiffFlowProductOfCorrelationsPro[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*eightReducedEBE,dw4*dw8); // storing <4'><8'> 
5580   //fDiffFlowProductOfCorrelationsPro[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*eightReducedEBE,dW6*dw8); // storing <6><8'>
5581   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
5582   //fDiffFlowProductOfCorrelationsPro[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*eightReducedEBE,dW8*dw8); // storing <8><8'> 
5583  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++       
5584      
5585 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
5586
5587
5588 //================================================================================================================================
5589     
5590     
5591 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta) // to be improved (reimplemented)
5592 {
5593  // a) Calculate unbiased estimators Cov(<2>,<2'>), Cov(<2>,<4'>), Cov(<4>,<2'>), Cov(<4>,<4'>) and Cov(<2'>,<4'>)
5594  //    for covariances V(<2>,<2'>), V(<2>,<4'>), V(<4>,<2'>), V(<4>,<4'>) and V(<2'>,<4'>).  
5595  // b) Store in histogram fDiffFlowCovariances[t][pe][index] for instance the following: 
5596  //
5597  //             Cov(<2>,<2'>) * (sum_{i=1}^{N} w_{<2>}_i w_{<2'>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<2'>}_j)]
5598  // 
5599  //     where N is the number of events, w_{<2>} is event weight for <2> and w_{<2'>} is event weight for <2'>.
5600  // c) Binning of fDiffFlowCovariances[t][pe][index] is organized as follows:
5601  // 
5602  //     1st bin: Cov(<2>,<2'>) * (sum_{i=1}^{N} w_{<2>}_i w_{<2'>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<2'>}_j)] 
5603  //     2nd bin: Cov(<2>,<4'>) * (sum_{i=1}^{N} w_{<2>}_i w_{<4'>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<4'>}_j)] 
5604  //     3rd bin: Cov(<4>,<2'>) * (sum_{i=1}^{N} w_{<4>}_i w_{<2'>}_i )/[(sum_{i=1}^{N} w_{<4>}_i) * (sum_{j=1}^{N} w_{<2'>}_j)] 
5605  //     4th bin: Cov(<4>,<4'>) * (sum_{i=1}^{N} w_{<4>}_i w_{<4'>}_i )/[(sum_{i=1}^{N} w_{<4>}_i) * (sum_{j=1}^{N} w_{<4'>}_j)] 
5606  //     5th bin: Cov(<2'>,<4'>) * (sum_{i=1}^{N} w_{<2'>}_i w_{<4'>}_i )/[(sum_{i=1}^{N} w_{<2'>}_i) * (sum_{j=1}^{N} w_{<4'>}_j)] 
5607  //     ...
5608   
5609  Int_t typeFlag = -1;
5610  Int_t ptEtaFlag = -1;
5611
5612  if(type == "RP")
5613  {
5614   typeFlag = 0;
5615  } else if(type == "POI")
5616    {
5617     typeFlag = 1;
5618    } 
5619      
5620  if(ptOrEta == "Pt")
5621  {
5622   ptEtaFlag = 0;
5623  } else if(ptOrEta == "Eta")
5624    {
5625     ptEtaFlag = 1;
5626    } 
5627   
5628  // shortcuts:
5629  Int_t t = typeFlag;
5630  Int_t pe = ptEtaFlag;
5631      
5632  // common:
5633  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5634  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
5635  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
5636  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
5637  
5638  // average correlations:
5639  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
5640  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
5641  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
5642  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
5643  
5644  // sum of weights for correlation:
5645  Double_t sumOfWeightsForTwo = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // sum_{i=1}^{N} w_{<2>}
5646  Double_t sumOfWeightsForFour = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // sum_{i=1}^{N} w_{<4>}
5647  //Double_t sumOfWeightsForSix = fIntFlowSumOfEventWeights[0]->GetBinContent(3); // sum_{i=1}^{N} w_{<6>}
5648  //Double_t sumOfWeightsForEight = fIntFlowSumOfEventWeights[0]->GetBinContent(4); // sum_{i=1}^{N} w_{<8>}
5649  
5650  // average reduced correlations:
5651  Double_t twoReduced = 0.; // <<2'>> 
5652  Double_t fourReduced = 0.; // <<4'>>
5653  //Double_t sixReduced = 0.; // <<6'>>
5654  //Double_t eightReduced = 0.; // <<8'>>
5655
5656  // sum of weights for reduced correlation:
5657  Double_t sumOfWeightsForTwoReduced = 0.; // sum_{i=1}^{N} w_{<2'>}
5658  Double_t sumOfWeightsForFourReduced = 0.; // sum_{i=1}^{N} w_{<4'>}
5659  //Double_t sumOfWeightsForSixReduced = 0.; // sum_{i=1}^{N} w_{<6'>}
5660  //Double_t sumOfWeightsForEightReduced = 0.; // sum_{i=1}^{N} w_{<8'>}
5661   
5662  // product of weights for reduced correlation:
5663  Double_t productOfWeightsForTwoTwoReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<2'>}
5664  Double_t productOfWeightsForTwoFourReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<4'>}
5665  Double_t productOfWeightsForFourTwoReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<2'>}
5666  Double_t productOfWeightsForFourFourReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<4'>}
5667  Double_t productOfWeightsForTwoReducedFourReduced = 0.; // sum_{i=1}^{N} w_{<2'>}w_{<4'>}
5668  // ...
5669  
5670  // products for differential flow:
5671  Double_t twoTwoReduced = 0; // <<2><2'>> 
5672  Double_t twoFourReduced = 0; // <<2><4'>> 
5673  Double_t fourTwoReduced = 0; // <<4><2'>> 
5674  Double_t fourFourReduced = 0; // <<4><4'>> 
5675  Double_t twoReducedFourReduced = 0; // <<2'><4'>> 
5676
5677  // denominators in the expressions for the unbiased estimators for covariances:
5678  // denominator = 1 - term1/(term2*term3)
5679  // prefactor = term1/(term2*term3)
5680  Double_t denominator = 0.; 
5681  Double_t prefactor = 0.;
5682  Double_t term1 = 0.; 
5683  Double_t term2 = 0.; 
5684  Double_t term3 = 0.; 
5685  
5686  // unbiased estimators for covariances for differential flow:
5687  Double_t covTwoTwoReduced = 0.; // Cov(<2>,<2'>)
5688  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(w_{<2>},w_{<2'>})
5689  Double_t covTwoFourReduced = 0.; // Cov(<2>,<4'>)
5690  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(w_{<2>},w_{<4'>})
5691  Double_t covFourTwoReduced = 0.; // Cov(<4>,<2'>)
5692  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(w_{<4>},w_{<2'>})
5693  Double_t covFourFourReduced = 0.; // Cov(<4>,<4'>)
5694  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(w_{<4>},w_{<4'>})
5695  Double_t covTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>)
5696  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(w_{<2'>},w_{<4'>})
5697  
5698  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5699  {
5700   // average reduced corelations:
5701   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
5702   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
5703   // average products:
5704   twoTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->GetBinContent(b);
5705   twoFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->GetBinContent(b);
5706   fourTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->GetBinContent(b);
5707   fourFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->GetBinContent(b);
5708   twoReducedFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->GetBinContent(b);  
5709   // sum of weights for reduced correlations:
5710   sumOfWeightsForTwoReduced = fDiffFlowSumOfEventWeights[t][pe][0][0]->GetBinContent(b);
5711   sumOfWeightsForFourReduced = fDiffFlowSumOfEventWeights[t][pe][0][1]->GetBinContent(b);
5712   // products of weights for correlations:
5713   productOfWeightsForTwoTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->GetBinContent(b); 
5714   productOfWeightsForTwoFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->GetBinContent(b);
5715   productOfWeightsForFourTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->GetBinContent(b);
5716   productOfWeightsForFourFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->GetBinContent(b);
5717   productOfWeightsForTwoReducedFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->GetBinContent(b);
5718   // denominator for the unbiased estimator for covariances: 1 - term1/(term2*term3) 
5719   // prefactor (multiplies Cov's) = term1/(term2*term3)       
5720   // <2>,<2'>:
5721   term1 = productOfWeightsForTwoTwoReduced;      
5722   term2 = sumOfWeightsForTwo;
5723   term3 = sumOfWeightsForTwoReduced;        
5724   if(term2*term3>0.)
5725   {
5726    denominator = 1.-term1/(term2*term3);
5727    prefactor = term1/(term2*term3);
5728    if(denominator!=0)
5729    {
5730     covTwoTwoReduced = (twoTwoReduced-two*twoReduced)/denominator;            
5731     wCovTwoTwoReduced = covTwoTwoReduced*prefactor; 
5732     fDiffFlowCovariances[t][pe][0]->SetBinContent(b,wCovTwoTwoReduced);
5733    }
5734   }
5735   // <2>,<4'>:
5736   term1 = productOfWeightsForTwoFourReduced;      
5737   term2 = sumOfWeightsForTwo;
5738   term3 = sumOfWeightsForFourReduced;        
5739   if(term2*term3>0.)
5740   {
5741    denominator = 1.-term1/(term2*term3);
5742    prefactor = term1/(term2*term3);
5743    if(denominator!=0)
5744    {
5745     covTwoFourReduced = (twoFourReduced-two*fourReduced)/denominator;            
5746     wCovTwoFourReduced = covTwoFourReduced*prefactor; 
5747     fDiffFlowCovariances[t][pe][1]->SetBinContent(b,wCovTwoFourReduced);
5748    }
5749   }
5750   // <4>,<2'>:
5751   term1 = productOfWeightsForFourTwoReduced;      
5752   term2 = sumOfWeightsForFour;
5753   term3 = sumOfWeightsForTwoReduced;        
5754   if(term2*term3>0.)
5755   {
5756    denominator = 1.-term1/(term2*term3);
5757    prefactor = term1/(term2*term3);
5758    if(denominator!=0)
5759    {
5760     covFourTwoReduced = (fourTwoReduced-four*twoReduced)/denominator;            
5761     wCovFourTwoReduced = covFourTwoReduced*prefactor; 
5762     fDiffFlowCovariances[t][pe][2]->SetBinContent(b,wCovFourTwoReduced);
5763    }
5764   }
5765   // <4>,<4'>:
5766   term1 = productOfWeightsForFourFourReduced;      
5767   term2 = sumOfWeightsForFour;
5768   term3 = sumOfWeightsForFourReduced;        
5769   if(term2*term3>0.)
5770   {
5771    denominator = 1.-term1/(term2*term3);
5772    prefactor = term1/(term2*term3);
5773    if(denominator!=0)
5774    {
5775     covFourFourReduced = (fourFourReduced-four*fourReduced)/denominator;            
5776     wCovFourFourReduced = covFourFourReduced*prefactor; 
5777     fDiffFlowCovariances[t][pe][3]->SetBinContent(b,wCovFourFourReduced);
5778    }
5779   }
5780   // <2'>,<4'>:
5781   term1 = productOfWeightsForTwoReducedFourReduced;      
5782   term2 = sumOfWeightsForTwoReduced;
5783   term3 = sumOfWeightsForFourReduced;        
5784   if(term2*term3>0.)
5785   {
5786    denominator = 1.-term1/(term2*term3);
5787    prefactor = term1/(term2*term3);
5788    if(denominator!=0)
5789    {
5790     covTwoReducedFourReduced = (twoReducedFourReduced-twoReduced*fourReduced)/denominator;            
5791     wCovTwoReducedFourReduced = covTwoReducedFourReduced*prefactor; 
5792     fDiffFlowCovariances[t][pe][4]->SetBinContent(b,wCovTwoReducedFourReduced);
5793    }
5794   }   
5795  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5796   
5797 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta)
5798
5799
5800 //================================================================================================================================
5801
5802
5803 void AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, TString ptOrEta)
5804 {
5805  // calculate differential flow from differential cumulants and previously obtained integrated flow: (to be improved: description)
5806  
5807  Int_t typeFlag = -1;
5808  Int_t ptEtaFlag = -1;
5809
5810  if(type == "RP")
5811  {
5812   typeFlag = 0;
5813  } else if(type == "POI")
5814    {
5815     typeFlag = 1;
5816    } 
5817      
5818  if(ptOrEta == "Pt")
5819  {
5820   ptEtaFlag = 0;
5821  } else if(ptOrEta == "Eta")
5822    {
5823     ptEtaFlag = 1;
5824    } 
5825   
5826  // shortcuts:
5827  Int_t t = typeFlag;
5828  Int_t pe = ptEtaFlag;
5829      
5830  // common:
5831  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5832    
5833  // correlations:
5834  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
5835  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
5836  
5837  // statistical errors of correlations:
5838  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
5839  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2);   
5840     
5841  // reduced correlations:
5842  Double_t twoReduced = 0.; // <<2'>>
5843  Double_t fourReduced = 0.; // <<4'>>
5844  
5845  // statistical errors of reduced correlations:
5846  Double_t twoReducedError = 0.; 
5847  Double_t fourReducedError = 0.; 
5848
5849  // covariances:
5850  Double_t wCovTwoFour = fIntFlowCovariances->GetBinContent(1);// // Cov(<2>,<4>) * prefactor(<2>,<4>)
5851  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
5852  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
5853  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(<4>,<2'>)
5854  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(<4>,<4'>)
5855  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
5856  
5857  // differential flow:
5858  Double_t v2Prime = 0.; // v'{2}                   
5859  Double_t v4Prime = 0.; // v'{4}
5860  
5861  // statistical error of differential flow:
5862  Double_t v2PrimeError = 0.;                    
5863  Double_t v4PrimeError = 0.; 
5864  
5865  // squared statistical error of differential flow:
5866  Double_t v2PrimeErrorSquared = 0.;                    
5867  Double_t v4PrimeErrorSquared = 0.; 
5868  
5869  // loop over pt or eta bins:
5870  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5871  {
5872   // reduced correlations and statistical errors:
5873   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
5874   twoReducedError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b);
5875   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
5876   fourReducedError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b);
5877   // covariances:
5878   wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b);
5879   wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b);
5880   wCovFourTwoReduced = fDiffFlowCovariances[t][pe][2]->GetBinContent(b);
5881   wCovFourFourReduced = fDiffFlowCovariances[t][pe][3]->GetBinContent(b);
5882   wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b);
5883   // differential flow:
5884   // v'{2}:
5885   if(two>0.) 
5886   {
5887    v2Prime = twoReduced/pow(two,0.5);
5888    v2PrimeErrorSquared = (1./4.)*pow(two,-3.)*
5889                          (pow(twoReduced,2.)*pow(twoError,2.)
5890                           + 4.*pow(two,2.)*pow(twoReducedError,2.)
5891                           - 4.*two*twoReduced*wCovTwoTwoReduced);
5892      
5893                                                             
5894    if(v2PrimeErrorSquared>0.) v2PrimeError = pow(v2PrimeErrorSquared,0.5);
5895    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
5896    fDiffFlow[t][pe][0]->SetBinError(b,v2PrimeError);     
5897   }
5898   // differential flow:
5899   // v'{4}
5900   if(2.*pow(two,2.)-four > 0.) 
5901   {
5902    v4Prime = (2.*two*twoReduced-fourReduced)/pow(2.*pow(two,2.)-four,3./4.);
5903    v4PrimeErrorSquared = pow(2.*pow(two,2.)-four,-7./2.)*
5904                          (pow(2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced,2.)*pow(twoError,2.)
5905                           + (9./16.)*pow(2.*two*twoReduced-fourReduced,2.)*pow(fourError,2.)
5906                           + 4.*pow(two,2.)*pow(2.*pow(two,2.)-four,2.)*pow(twoReducedError,2.)
5907                           + pow(2.*pow(two,2.)-four,2.)*pow(fourReducedError,2.)                          
5908                           - (3./2.)*(2.*two*twoReduced-fourReduced)
5909                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFour
5910                           - 4.*two*(2.*pow(two,2.)-four)
5911                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoTwoReduced
5912                           + 2.*(2.*pow(two,2.)-four)
5913                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFourReduced
5914                           + 3.*two*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourTwoReduced
5915                           - (3./2.)*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourFourReduced 
5916                           - 4.*two*pow(2.*pow(two,2.)-four,2.)*wCovTwoReducedFourReduced);  
5917    if(v4PrimeErrorSquared>0.) v4PrimeError = pow(v4PrimeErrorSquared,0.5);        
5918    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);
5919    fDiffFlow[t][pe][1]->SetBinError(b,v4PrimeError);     
5920   }
5921   
5922  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
5923  
5924    
5925  
5926  
5927  /*
5928  // 2D:
5929  for(Int_t nua=0;nua<2;nua++)
5930  {
5931   for(Int_t p=1;p<=fnBinsPt;p++)
5932   {
5933    for(Int_t e=1;e<=fnBinsEta;e++) 
5934    { 
5935     // differential cumulants:
5936     Double_t qc2Prime = fFinalCumulants2D[t][pW][eW][nua][0]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e)); // QC{2'}                    
5937     Double_t qc4Prime = fFinalCumulants2D[t][pW][eW][nua][1]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e)); // QC{4'}
5938     // differential flow:
5939     Double_t v2Prime = 0.;                    
5940     Double_t v4Prime = 0.; 
5941     if(v2) 
5942     {
5943      v2Prime = qc2Prime/v2;
5944      fFinalFlow2D[t][pW][eW][nua][0]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][0]->GetBin(p,e),v2Prime);  
5945     }                   
5946     if(v4)
5947     {
5948      v4Prime = -qc4Prime/pow(v4,3.); 
5949      fFinalFlow2D[t][pW][eW][nua][1]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][1]->GetBin(p,e),v4Prime);  
5950     }                    
5951    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5952   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5953  } // end of for(Int_t nua=0;nua<2;nua++)
5954  */
5955
5956 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights)
5957
5958
5959 //================================================================================================================================
5960
5961
5962 void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
5963 {
5964  // a) Store all flags for integrated flow in profile fIntFlowFlags.
5965  
5966  if(!fIntFlowFlags)
5967  {
5968   cout<<"WARNING: fIntFlowFlags is NULL in AFAWQC::SFFIF() !!!!"<<endl;
5969   exit(0);
5970  } 
5971
5972  // particle weights used or not:
5973  fIntFlowFlags->Fill(0.5,(Int_t)fUsePhiWeights||fUsePtWeights||fUseEtaWeights);
5974  // which event weights were used:
5975  if(strcmp(fMultiplicityWeight->Data(),"combinations"))
5976  {
5977   fIntFlowFlags->Fill(1.5,0); // 0 = "combinations" (default)
5978  } else if(strcmp(fMultiplicityWeight->Data(),"unit"))
5979    {
5980     fIntFlowFlags->Fill(1.5,1); // 1 = "unit"   
5981    } else if(strcmp(fMultiplicityWeight->Data(),"multiplicity"))
5982      {
5983       fIntFlowFlags->Fill(1.5,2); // 2 = "multiplicity"        
5984      } 
5985  // corrected for non-uniform acceptance or not:
5986  fIntFlowFlags->Fill(2.5,(Int_t)fApplyCorrectionForNUA);
5987  fIntFlowFlags->Fill(3.5,(Int_t)fPrintFinalResults[0]);
5988  fIntFlowFlags->Fill(4.5,(Int_t)fPrintFinalResults[1]);
5989  fIntFlowFlags->Fill(5.5,(Int_t)fPrintFinalResults[2]);
5990   
5991 } // end of void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
5992
5993
5994 //================================================================================================================================
5995
5996
5997 void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
5998 {
5999  // Store all flags for differential flow in the profile fDiffFlowFlags.
6000   
6001  if(!fDiffFlowFlags)
6002  {
6003   cout<<"WARNING: fDiffFlowFlags is NULL in AFAWQC::SFFDF() !!!!"<<endl;
6004   exit(0);
6005  } 
6006  
6007  fDiffFlowFlags->Fill(0.5,fUsePhiWeights||fUsePtWeights||fUseEtaWeights); // particle weights used or not
6008  //fDiffFlowFlags->Fill(1.5,""); // which event weight was used? // to be improved
6009  fDiffFlowFlags->Fill(2.5,fApplyCorrectionForNUA); // corrected for non-uniform acceptance or not
6010  fDiffFlowFlags->Fill(3.5,fCalculate2DFlow); // calculate also 2D differential flow in (pt,eta) or not
6011     
6012 } // end of void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
6013
6014
6015 //================================================================================================================================
6016
6017
6018 void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
6019 {
6020  // Access all pointers to common control and common result histograms and profiles.
6021  
6022  TString commonHistsName = "AliFlowCommonHistQC";
6023  commonHistsName += fAnalysisLabel->Data();
6024  AliFlowCommonHist *commonHist = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHistsName.Data()));
6025  if(commonHist) this->SetCommonHists(commonHist); 
6026  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
6027  commonHists2ndOrderName += fAnalysisLabel->Data();
6028  AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists2ndOrderName.Data()));
6029  if(commonHist2nd) this->SetCommonHists2nd(commonHist2nd);   
6030  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
6031  commonHists4thOrderName += fAnalysisLabel->Data();
6032  AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists4thOrderName.Data()));
6033  if(commonHist4th) this->SetCommonHists4th(commonHist4th);  
6034  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
6035  commonHists6thOrderName += fAnalysisLabel->Data();
6036  AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists6thOrderName.Data()));
6037  if(commonHist6th) this->SetCommonHists6th(commonHist6th);  
6038  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
6039  commonHists8thOrderName += fAnalysisLabel->Data();
6040  AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists8thOrderName.Data()));
6041  if(commonHist8th) this->SetCommonHists8th(commonHist8th);  
6042  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC"; 
6043  commonHistResults2ndOrderName += fAnalysisLabel->Data(); 
6044  AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>\r                                              (fHistList->FindObject(commonHistResults2ndOrderName.Data()));
6045  if(commonHistRes2nd) this->SetCommonHistsResults2nd(commonHistRes2nd);   
6046  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
6047  commonHistResults4thOrderName += fAnalysisLabel->Data();
6048  AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>
6049                                               (fHistList->FindObject(commonHistResults4thOrderName.Data()));
6050  if(commonHistRes4th) this->SetCommonHistsResults4th(commonHistRes4th);  
6051  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
6052  commonHistResults6thOrderName += fAnalysisLabel->Data();
6053  AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>
6054                                               (fHistList->FindObject(commonHistResults6thOrderName.Data()));
6055  if(commonHistRes6th) this->SetCommonHistsResults6th(commonHistRes6th);  
6056  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
6057  commonHistResults8thOrderName += fAnalysisLabel->Data();
6058  AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>
6059                                               (fHistList->FindObject(commonHistResults8thOrderName.Data()));  
6060  if(commonHistRes8th) this->SetCommonHistsResults8th(commonHistRes8th);
6061        
6062 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
6063
6064
6065 //================================================================================================================================
6066
6067
6068 void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms() 
6069 {
6070  // Get pointers for histograms with particle weights.
6071
6072  TList *weightsList = dynamic_cast<TList*>(fHistList->FindObject("Weights"));
6073  if(weightsList) this->SetWeightsList(weightsList);
6074  TString fUseParticleWeightsName = "fUseParticleWeightsQC"; // to be improved (hirdwired label QC)
6075  fUseParticleWeightsName += fAnalysisLabel->Data();
6076  TProfile *useParticleWeights = dynamic_cast<TProfile*>(weightsList->FindObject(fUseParticleWeightsName.Data()));
6077  if(useParticleWeights)
6078  {
6079   this->SetUseParticleWeights(useParticleWeights);  
6080   fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
6081   fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
6082   fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3);  
6083  }
6084 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms(); 
6085
6086
6087 //================================================================================================================================
6088
6089
6090 void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms() 
6091 {
6092  // Get pointers for histograms and profiles relevant for integrated flow:
6093  //  a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults.
6094  //  b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow.
6095  //  c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds. 
6096  //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
6097   
6098  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data member?)
6099  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data member?)
6100  
6101  // a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults:
6102  TList *intFlowList = NULL;
6103  intFlowList = dynamic_cast<TList*>(fHistList->FindObject("Integrated Flow"));
6104  if(!intFlowList) 
6105  {
6106   cout<<"WARNING: intFlowList is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6107   exit(0); 
6108  }  
6109   
6110   // b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow:
6111   TString intFlowFlagsName = "fIntFlowFlags";
6112   intFlowFlagsName += fAnalysisLabel->Data();
6113   TProfile *intFlowFlags = dynamic_cast<TProfile*>(intFlowList->FindObject(intFlowFlagsName.Data()));
6114   Bool_t bApplyCorrectionForNUA = kFALSE;
6115   if(intFlowFlags)
6116   {
6117    this->SetIntFlowFlags(intFlowFlags);  
6118    bApplyCorrectionForNUA = (Int_t)intFlowFlags->GetBinContent(3); 
6119    this->SetApplyCorrectionForNUA(bApplyCorrectionForNUA);      
6120   } else 
6121     {
6122      cout<<"WARNING: intFlowFlags is NULL in FAWQC::GPFIFH() !!!!"<<endl;
6123     }
6124   
6125   // c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds:
6126   TList *intFlowProfiles = NULL;
6127   intFlowProfiles = dynamic_cast<TList*>(intFlowList->FindObject("Profiles"));
6128   if(intFlowProfiles)  
6129   {
6130    // average multiplicities:
6131    TString avMultiplicityName = "fAvMultiplicity";
6132    avMultiplicityName += fAnalysisLabel->Data();
6133    TProfile *avMultiplicity = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(avMultiplicityName.Data()));
6134    if(avMultiplicity) 
6135    {
6136     this->SetAvMultiplicity(avMultiplicity);
6137    } else 
6138      {
6139       cout<<"WARNING: avMultiplicity is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6140      }
6141    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with wrong errors!):
6142    TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
6143    intFlowCorrelationsProName += fAnalysisLabel->Data();
6144    TProfile *intFlowCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsProName.Data()));
6145    if(intFlowCorrelationsPro) 
6146    {
6147     this->SetIntFlowCorrelationsPro(intFlowCorrelationsPro);
6148    } else 
6149      {
6150       cout<<"WARNING: intFlowCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6151      } 
6152    // average all correlations for integrated flow (with wrong errors!):
6153    TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
6154    intFlowCorrelationsAllProName += fAnalysisLabel->Data();
6155    TProfile *intFlowCorrelationsAllPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsAllProName.Data()));
6156    if(intFlowCorrelationsAllPro) 
6157    {
6158     this->SetIntFlowCorrelationsAllPro(intFlowCorrelationsAllPro);
6159    } else 
6160      {
6161       cout<<"WARNING: intFlowCorrelationsAllPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6162      }     
6163    // average extra correlations for integrated flow (which appear only when particle weights are used):
6164    // (to be improved: Weak point in implementation, I am assuming here that method GetPointersForParticleWeightsHistograms() was called)
6165    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
6166    {
6167     TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
6168     intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
6169     TProfile *intFlowExtraCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowExtraCorrelationsProName.Data()));
6170     if(intFlowExtraCorrelationsPro) 
6171     {
6172      this->SetIntFlowExtraCorrelationsPro(intFlowExtraCorrelationsPro);
6173     } else 
6174       {
6175        cout<<"WARNING: intFlowExtraCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6176       }
6177    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)        
6178    // average products of correlations <2>, <4>, <6> and <8>:  
6179    TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
6180    intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
6181    TProfile *intFlowProductOfCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrelationsProName.Data()));
6182    if(intFlowProductOfCorrelationsPro) 
6183    {
6184     this->SetIntFlowProductOfCorrelationsPro(intFlowProductOfCorrelationsPro);
6185    } else 
6186      {
6187       cout<<"WARNING: intFlowProductOfCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6188      }     
6189    // average correction terms for non-uniform acceptance (with wrong errors!):
6190    for(Int_t sc=0;sc<2;sc++)
6191    {
6192     TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
6193     intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
6194     TProfile *intFlowCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()))));
6195     if(intFlowCorrectionTermsForNUAPro) 
6196     {
6197      this->SetIntFlowCorrectionTermsForNUAPro(intFlowCorrectionTermsForNUAPro,sc);
6198     } else 
6199       {
6200        cout<<"WARNING: intFlowCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6201        cout<<"sc = "<<sc<<endl;
6202       } 
6203    } // end of for(Int_t sc=0;sc<2;sc++)           
6204   } else // to if(intFlowProfiles)  
6205     {
6206      cout<<"WARNING: intFlowProfiles is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6207     }
6208    
6209   //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
6210   TList *intFlowResults = NULL;
6211   intFlowResults = dynamic_cast<TList*>(intFlowList->FindObject("Results"));
6212   if(intFlowResults)
6213   {
6214    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!):
6215    TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
6216    intFlowCorrelationsHistName += fAnalysisLabel->Data();
6217    TH1D *intFlowCorrelationsHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsHistName.Data()));
6218    if(intFlowCorrelationsHist) 
6219    {
6220     this->SetIntFlowCorrelationsHist(intFlowCorrelationsHist);
6221    } else 
6222      {
6223       cout<<"WARNING: intFlowCorrelationsHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6224      } 
6225    // average all correlations for integrated flow (with correct errors!):
6226    TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
6227    intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
6228    TH1D *intFlowCorrelationsAllHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsAllHistName.Data()));
6229    if(intFlowCorrelationsAllHist) 
6230    {
6231     this->SetIntFlowCorrelationsAllHist(intFlowCorrelationsAllHist);
6232    } else 
6233      {
6234       cout<<"WARNING: intFlowCorrelationsAllHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6235      }  
6236    // average correction terms for non-uniform acceptance (with correct errors!):
6237    TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
6238    intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
6239    for(Int_t sc=0;sc<2;sc++)
6240    {
6241     TH1D *intFlowCorrectionTermsForNUAHist = dynamic_cast<TH1D*>(intFlowResults->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()))));
6242     if(intFlowCorrectionTermsForNUAHist) 
6243     {
6244      this->SetIntFlowCorrectionTermsForNUAHist(intFlowCorrectionTermsForNUAHist,sc);
6245     } else 
6246       {
6247        cout<<"WARNING: intFlowCorrectionTermsForNUAHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6248        cout<<"sc = "<<sc<<endl;
6249       } 
6250    } // end of for(Int_t sc=0;sc<2;sc++)           
6251    // covariances (multiplied with weight dependent prefactor):
6252    TString intFlowCovariancesName = "fIntFlowCovariances";
6253    intFlowCovariancesName += fAnalysisLabel->Data();
6254    TH1D *intFlowCovariances = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesName.Data()));
6255    if(intFlowCovariances) 
6256    {
6257     this->SetIntFlowCovariances(intFlowCovariances); 
6258    } else 
6259      {
6260       cout<<"WARNING: intFlowCovariances is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6261      } 
6262    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
6263    TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
6264    intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
6265    for(Int_t power=0;power<2;power++)
6266    {
6267     TH1D *intFlowSumOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s",intFlowSumOfEventWeightsName.Data(),powerFlag[power].Data())));
6268     if(intFlowSumOfEventWeights) 
6269     {
6270      this->SetIntFlowSumOfEventWeights(intFlowSumOfEventWeights,power);
6271     } else 
6272       {
6273        cout<<"WARNING: intFlowSumOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6274        cout<<"power = "<<power<<endl;
6275       }                                   
6276    } // end of for(Int_t power=0;power<2;power++)                                                                  
6277    // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
6278    TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
6279    intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
6280    TH1D *intFlowSumOfProductOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsName.Data()));
6281    if(intFlowSumOfProductOfEventWeights) 
6282    {
6283     this->SetIntFlowSumOfProductOfEventWeights(intFlowSumOfProductOfEventWeights);
6284    } else 
6285      {
6286       cout<<"WARNING: intFlowSumOfProductOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6287      } 
6288    // final results for integrated Q-cumulants:
6289    TString intFlowQcumulantsName = "fIntFlowQcumulants";
6290    intFlowQcumulantsName += fAnalysisLabel->Data();
6291    TH1D *intFlowQcumulants = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsName.Data()));
6292    if(intFlowQcumulants) 
6293    {
6294     this->SetIntFlowQcumulants(intFlowQcumulants);
6295    } else 
6296      {
6297       cout<<"WARNING: intFlowQcumulants is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6298      }  
6299    // final integrated flow estimates from Q-cumulants:
6300    TString intFlowName = "fIntFlow";
6301    intFlowName += fAnalysisLabel->Data();
6302    TH1D *intFlow = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowName.Data()));
6303    if(intFlow) 
6304    {
6305     this->SetIntFlow(intFlow);
6306    } else 
6307      {
6308       cout<<"WARNING: intFlow is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
6309      }   
6310   } else // to if(intFlowResults)
6311     {
6312      cout<<"WARNING: intFlowResults is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
6313     }
6314
6315 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms()
6316
6317
6318 //================================================================================================================================
6319
6320
6321 void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
6322 {
6323  // Get pointer to all objects relevant for differential flow.
6324  //  a) Define flags locally (to be improved: should I promote flags to data members?);
6325  //  b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults;
6326  //  c) Get pointer to profile fDiffFlowFlags holding all flags for differential flow;
6327  //  d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
6328  //  e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
6329  
6330  // a) Define flags locally (to be improved: should I promote flags to data members?): 
6331  TString typeFlag[2] = {"RP","POI"}; 
6332  TString ptEtaFlag[2] = {"p_{T}","#eta"};
6333  TString powerFlag[2] = {"linear","quadratic"};
6334  TString sinCosFlag[2] = {"sin","cos"};
6335  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
6336  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
6337  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
6338  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
6339  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
6340   
6341  // b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults:
6342  TList *diffFlowList = NULL;
6343  diffFlowList = dynamic_cast<TList*>(fHistList->FindObject("Differential Flow"));  
6344  if(!diffFlowList)
6345  { 
6346   cout<<"WARNING: diffFlowList is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6347   exit(0);
6348  }
6349  // list holding nested lists containing profiles:
6350  TList *diffFlowListProfiles = NULL;
6351  diffFlowListProfiles = dynamic_cast<TList*>(diffFlowList->FindObject("Profiles"));
6352  if(!diffFlowListProfiles)
6353  { 
6354   cout<<"WARNING: diffFlowListProfiles is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6355   exit(0);
6356  }
6357  // list holding nested lists containing 2D and 1D histograms with final results:
6358  TList *diffFlowListResults = NULL;
6359  diffFlowListResults = dynamic_cast<TList*>(diffFlowList->FindObject("Results"));
6360  if(!diffFlowListResults)
6361  { 
6362   cout<<"WARNING: diffFlowListResults is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6363   exit(0);
6364  }
6365  
6366  // c) Get pointer to profile holding all flags for differential flow;
6367  TString diffFlowFlagsName = "fDiffFlowFlags";
6368  diffFlowFlagsName += fAnalysisLabel->Data();
6369  TProfile *diffFlowFlags = dynamic_cast<TProfile*>(diffFlowList->FindObject(diffFlowFlagsName.Data()));
6370  Bool_t bCalculate2DFlow = kFALSE;
6371  if(diffFlowFlags)
6372  {
6373   this->SetDiffFlowFlags(diffFlowFlags);  
6374   bCalculate2DFlow = (Int_t)diffFlowFlags->GetBinContent(4);
6375   this->SetCalculate2DFlow(bCalculate2DFlow); // to be improved (shoul I call this setter somewhere else?)     
6376  }
6377   
6378  // d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
6379  // correlations:
6380  TList *diffFlowCorrelationsProList[2][2] = {{NULL}};
6381  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
6382  diffFlowCorrelationsProName += fAnalysisLabel->Data();
6383  TProfile *diffFlowCorrelationsPro[2][2][4] = {{{NULL}}};   
6384  // products of correlations:
6385  TList *diffFlowProductOfCorrelationsProList[2][2] = {{NULL}};
6386  TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
6387  diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
6388  TProfile *diffFlowProductOfCorrelationsPro[2][2][8][8] = {{{{NULL}}}};   
6389  // corrections:
6390  TList *diffFlowCorrectionsProList[2][2] = {{NULL}};
6391  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
6392  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();  
6393  TProfile *diffFlowCorrectionTermsForNUAPro[2][2][2][10] = {{{{NULL}}}};   
6394  for(Int_t t=0;t<2;t++)
6395  {
6396   for(Int_t pe=0;pe<2;pe++)
6397   {
6398    diffFlowCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6399    if(!diffFlowCorrelationsProList[t][pe])
6400    { 
6401     cout<<"WARNING: diffFlowCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6402     cout<<"t = "<<t<<endl;
6403     cout<<"pe = "<<pe<<endl;
6404     exit(0);
6405    }
6406    for(Int_t ci=0;ci<4;ci++) // correlation index
6407    {
6408     diffFlowCorrelationsPro[t][pe][ci] = dynamic_cast<TProfile*>(diffFlowCorrelationsProList[t][pe]->FindObject(Form("%s, %s, %s, %s",diffFlowCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[ci].Data())));
6409     if(diffFlowCorrelationsPro[t][pe][ci])
6410     {
6411      this->SetDiffFlowCorrelationsPro(diffFlowCorrelationsPro[t][pe][ci],t,pe,ci);
6412     } else
6413       {
6414        cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6415        cout<<"t  = "<<t<<endl;
6416        cout<<"pe = "<<pe<<endl;   
6417        cout<<"ci = "<<ci<<endl;
6418       }     
6419    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
6420    // products of correlations:    
6421    diffFlowProductOfCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()))); 
6422    if(!diffFlowProductOfCorrelationsProList[t][pe])
6423    { 
6424     cout<<"WARNING: ddiffFlowProductOfCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6425     cout<<"t = "<<t<<endl;
6426     cout<<"pe = "<<pe<<endl;
6427     exit(0);
6428    }
6429    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
6430    {
6431     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
6432     {
6433      diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = dynamic_cast<TProfile*>(diffFlowProductOfCorrelationsProList[t][pe]->FindObject(Form("%s, %s, %s, %s, %s",diffFlowProductOfCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),mixedCorrelationIndex[mci1].Data(),mixedCorrelationIndex[mci2].Data())));
6434      if(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2])
6435      {
6436       this->SetDiffFlowProductOfCorrelationsPro(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2],t,pe,mci1,mci2);
6437      } else
6438        {
6439         cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6440         cout<<"t    = "<<t<<endl;
6441         cout<<"pe   = "<<pe<<endl;   
6442         cout<<"mci1 = "<<mci1<<endl;
6443         cout<<"mci2 = "<<mci2<<endl;
6444        }
6445      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
6446     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
6447    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
6448    // corrections:
6449    diffFlowCorrectionsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6450    if(!diffFlowCorrectionsProList[t][pe])
6451    { 
6452     cout<<"WARNING: diffFlowCorrectionsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6453     cout<<"t = "<<t<<endl;
6454     cout<<"pe = "<<pe<<endl;
6455     exit(0);
6456    }
6457    // correction terms for NUA:
6458    for(Int_t sc=0;sc<2;sc++) // sin or cos
6459    {
6460     for(Int_t cti=0;cti<9;cti++) // correction term index
6461     {
6462      diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = dynamic_cast<TProfile*>(diffFlowCorrectionsProList[t][pe]->FindObject(Form("%s, %s, %s, %s, cti = %d",diffFlowCorrectionTermsForNUAProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1)));
6463      if(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti])
6464      {
6465       this->SetDiffFlowCorrectionTermsForNUAPro(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti],t,pe,sc,cti);
6466      } else
6467        {
6468         cout<<"WARNING: diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6469         cout<<"t   = "<<t<<endl;
6470         cout<<"pe  = "<<pe<<endl;   
6471         cout<<"sc  = "<<sc<<endl;
6472         cout<<"cti = "<<cti<<endl;
6473        }    
6474     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
6475    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
6476    // ...
6477   } // end of for(Int_t pe=0;pe<2;pe++)
6478  } // end of for(Int_t t=0;t<2;t++)
6479   
6480  // e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
6481  // reduced correlations:
6482  TList *diffFlowCorrelationsHistList[2][2] = {{NULL}};
6483  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
6484  diffFlowCorrelationsHistName += fAnalysisLabel->Data();  
6485  TH1D *diffFlowCorrelationsHist[2][2][4] = {{{NULL}}};
6486  // corrections for NUA:
6487  TList *diffFlowCorrectionsHistList[2][2] = {{NULL}};
6488  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
6489  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();  
6490  TH1D *diffFlowCorrectionTermsForNUAHist[2][2][2][10] = {{{{NULL}}}};
6491  // differential Q-cumulants:
6492  TList *diffFlowCumulantsHistList[2][2] = {{NULL}};
6493  TString diffFlowCumulantsName = "fDiffFlowCumulants";
6494  diffFlowCumulantsName += fAnalysisLabel->Data();  
6495  TH1D *diffFlowCumulants[2][2][4] = {{{NULL}}};
6496  // differential flow estimates from Q-cumulants:
6497  TList *diffFlowHistList[2][2] = {{NULL}};
6498  TString diffFlowName = "fDiffFlow";
6499  diffFlowName += fAnalysisLabel->Data();  
6500  TH1D *diffFlow[2][2][4] = {{{NULL}}};
6501  // differential covariances:
6502  TList *diffFlowCovariancesHistList[2][2] = {{NULL}};
6503  TString diffFlowCovariancesName = "fDiffFlowCovariances";
6504  diffFlowCovariancesName += fAnalysisLabel->Data();  
6505  TH1D *diffFlowCovariances[2][2][5] = {{{NULL}}};
6506  for(Int_t t=0;t<2;t++) // type: RP or POI
6507  { 
6508   for(Int_t pe=0;pe<2;pe++) // pt or eta
6509   {
6510    // reduced correlations:
6511    diffFlowCorrelationsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6512    if(!diffFlowCorrelationsHistList[t][pe])
6513    { 
6514     cout<<"WARNING: diffFlowCorrelationsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6515     cout<<"t = "<<t<<endl;
6516     cout<<"pe = "<<pe<<endl;
6517     exit(0);
6518    }
6519    for(Int_t index=0;index<4;index++) 
6520    {
6521     diffFlowCorrelationsHist[t][pe][index] = dynamic_cast<TH1D*>(diffFlowCorrelationsHistList[t][pe]->FindObject(Form("%s, %s, %s, %s",diffFlowCorrelationsHistName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[index].Data())));
6522     if(diffFlowCorrelationsHist[t][pe][index])
6523     {
6524      this->SetDiffFlowCorrelationsHist(diffFlowCorrelationsHist[t][pe][index],t,pe,index);
6525     } else 
6526       {
6527        cout<<"WARNING: diffFlowCorrelationsHist[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6528        cout<<"t     = "<<t<<endl;
6529        cout<<"pe    = "<<pe<<endl;
6530        cout<<"index = "<<index<<endl;
6531        exit(0);       
6532       } 
6533    } // end of for(Int_t index=0;index<4;index++)
6534    // corrections:
6535    diffFlowCorrectionsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6536    if(!diffFlowCorrectionsHistList[t][pe])
6537    { 
6538     cout<<"WARNING: diffFlowCorrectionsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6539     cout<<"t = "<<t<<endl;
6540     cout<<"pe = "<<pe<<endl;
6541     exit(0);
6542    }
6543    // correction terms for NUA:
6544    for(Int_t sc=0;sc<2;sc++) // sin or cos
6545    {
6546     for(Int_t cti=0;cti<9;cti++) // correction term index
6547     {
6548      diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = dynamic_cast<TH1D*>(diffFlowCorrectionsHistList[t][pe]->FindObject(Form("%s, %s, %s, %s, cti = %d",diffFlowCorrectionTermsForNUAHistName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1)));
6549      if(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti])
6550      {
6551       this->SetDiffFlowCorrectionTermsForNUAHist(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti],t,pe,sc,cti);
6552      } else
6553        {
6554         cout<<"WARNING: diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6555         cout<<"t   = "<<t<<endl;
6556         cout<<"pe  = "<<pe<<endl;   
6557         cout<<"sc  = "<<sc<<endl;
6558         cout<<"cti = "<<cti<<endl;
6559        }    
6560     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
6561    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
6562    // ...
6563    // differential Q-cumulants:
6564    diffFlowCumulantsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6565    if(!diffFlowCumulantsHistList[t][pe])
6566    { 
6567     cout<<"WARNING: diffFlowCumulantsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6568     cout<<"t  = "<<t<<endl;
6569     cout<<"pe = "<<pe<<endl;
6570     exit(0);
6571    }
6572    for(Int_t index=0;index<4;index++) 
6573    {
6574     diffFlowCumulants[t][pe][index] = dynamic_cast<TH1D*>(diffFlowCumulantsHistList[t][pe]->FindObject(Form("%s, %s, %s, %s",diffFlowCumulantsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialCumulantIndex[index].Data())));
6575     if(diffFlowCumulants[t][pe][index])
6576     {
6577      this->SetDiffFlowCumulants(diffFlowCumulants[t][pe][index],t,pe,index);
6578     } else 
6579       {
6580        cout<<"WARNING: diffFlowCumulants[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6581        cout<<"t     = "<<t<<endl;
6582        cout<<"pe    = "<<pe<<endl;
6583        cout<<"index = "<<index<<endl;
6584        exit(0);       
6585       } 
6586    } // end of for(Int_t index=0;index<4;index++)
6587    // differential flow estimates from Q-cumulants:
6588    diffFlowHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6589    if(!diffFlowHistList[t][pe])
6590    { 
6591     cout<<"WARNING: diffFlowHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6592     cout<<"t  = "<<t<<endl;
6593     cout<<"pe = "<<pe<<endl;
6594     exit(0);
6595    }
6596    for(Int_t index=0;index<4;index++) 
6597    {
6598     diffFlow[t][pe][index] = dynamic_cast<TH1D*>(diffFlowHistList[t][pe]->FindObject(Form("%s, %s, %s, %s",diffFlowName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialFlowIndex[index].Data())));
6599     if(diffFlow[t][pe][index])
6600     {
6601      this->SetDiffFlow(diffFlow[t][pe][index],t,pe,index);
6602     } else 
6603       {
6604        cout<<"WARNING: diffFlow[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6605        cout<<"t     = "<<t<<endl;
6606        cout<<"pe    = "<<pe<<endl;
6607        cout<<"index = "<<index<<endl;
6608        exit(0);       
6609       } 
6610    } // end of for(Int_t index=0;index<4;index++)
6611    // differential covariances:
6612    diffFlowCovariancesHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6613    if(!diffFlowCovariancesHistList[t][pe])
6614    { 
6615     cout<<"WARNING: diffFlowCovariancesHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6616     cout<<"t  = "<<t<<endl;
6617     cout<<"pe = "<<pe<<endl;
6618     exit(0);
6619    }
6620    for(Int_t covIndex=0;covIndex<5;covIndex++) 
6621    {
6622     diffFlowCovariances[t][pe][covIndex] = dynamic_cast<TH1D*>(diffFlowCovariancesHistList[t][pe]->FindObject(Form("%s, %s, %s, %s",diffFlowCovariancesName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),covarianceName[covIndex].Data())));
6623     if(diffFlowCovariances[t][pe][covIndex])
6624     {
6625      this->SetDiffFlowCovariances(diffFlowCovariances[t][pe][covIndex],t,pe,covIndex);
6626     } else 
6627       {
6628        cout<<"WARNING: diffFlowCovariances[t][pe][covIndex] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6629        cout<<"t        = "<<t<<endl;
6630        cout<<"pe       = "<<pe<<endl;
6631        cout<<"covIndex = "<<covIndex<<endl;
6632        exit(0);       
6633       } 
6634    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index    
6635   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6636  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
6637  // sum of event weights for reduced correlations:
6638  TList *diffFlowSumOfEventWeightsHistList[2][2][2] = {{{NULL}}};
6639  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
6640  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
6641  TH1D *diffFlowSumOfEventWeights[2][2][2][4] = {{{{NULL}}}};
6642  for(Int_t t=0;t<2;t++) // type is RP or POI
6643  { 
6644   for(Int_t pe=0;pe<2;pe++) // pt or eta
6645   { 
6646    for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
6647    {
6648     diffFlowSumOfEventWeightsHistList[t][pe][p] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Sum of %s event weights (%s, %s)",powerFlag[p].Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6649     if(!diffFlowSumOfEventWeightsHistList[t][pe][p])
6650     { 
6651      cout<<"WARNING: diffFlowSumOfEventWeightsHistList[t][pe][p] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6652      cout<<"t     = "<<t<<endl;
6653      cout<<"pe    = "<<pe<<endl;
6654      cout<<"power = "<<p<<endl;
6655      exit(0);
6656     }
6657     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
6658     {
6659      diffFlowSumOfEventWeights[t][pe][p][ew] = dynamic_cast<TH1D*>(diffFlowSumOfEventWeightsHistList[t][pe][p]->FindObject(Form("%s, %s, %s, %s, %s",diffFlowSumOfEventWeightsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),powerFlag[p].Data(),reducedCorrelationIndex[ew].Data())));    
6660      if(diffFlowSumOfEventWeights[t][pe][p][ew])
6661      {
6662       this->SetDiffFlowSumOfEventWeights(diffFlowSumOfEventWeights[t][pe][p][ew],t,pe,p,ew);
6663      } else 
6664        {
6665         cout<<"WARNING: diffFlowSumOfEventWeights[t][pe][p][ew] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6666         cout<<"t     = "<<t<<endl;
6667         cout<<"pe    = "<<pe<<endl;
6668         cout<<"power = "<<p<<endl;
6669         cout<<"ew    = "<<ew<<endl;
6670         exit(0);       
6671        } 
6672     }
6673    } // end of for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
6674   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6675  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
6676  //  
6677  TList *diffFlowSumOfProductOfEventWeightsHistList[2][2] = {{NULL}};
6678  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
6679  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
6680  TH1D *diffFlowSumOfProductOfEventWeights[2][2][8][8] = {{{{NULL}}}};
6681  for(Int_t t=0;t<2;t++) // type is RP or POI
6682  { 
6683   for(Int_t pe=0;pe<2;pe++) // pt or eta
6684   { 
6685    diffFlowSumOfProductOfEventWeightsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
6686    if(!diffFlowSumOfProductOfEventWeightsHistList[t][pe])
6687    { 
6688     cout<<"WARNING: diffFlowSumOfProductOfEventWeightsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6689     cout<<"t     = "<<t<<endl;
6690     cout<<"pe    = "<<pe<<endl;
6691     exit(0);
6692    }
6693    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
6694    {
6695     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
6696     {
6697      diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = dynamic_cast<TH1D*>(diffFlowSumOfProductOfEventWeightsHistList[t][pe]->FindObject(Form("%s, %s, %s, %s, %s",diffFlowSumOfProductOfEventWeightsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),mixedCorrelationIndex[mci1].Data(),mixedCorrelationIndex[mci2].Data())));    
6698       if(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2])
6699       {
6700        this->SetDiffFlowSumOfProductOfEventWeights(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2],t,pe,mci1,mci2);
6701       } else 
6702         {
6703          cout<<"WARNING: diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
6704          cout<<"t    = "<<t<<endl;
6705          cout<<"pe   = "<<pe<<endl;
6706          cout<<"mci1 = "<<mci1<<endl;
6707          cout<<"mci2 = "<<mci2<<endl;
6708          exit(0);       
6709         } 
6710      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
6711     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
6712    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
6713   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6714  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
6715
6716 } // end void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
6717
6718
6719 //================================================================================================================================
6720
6721
6722 void AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
6723 {
6724  // Book all histograms and profiles needed for differential flow.
6725  //  a) Define flags locally (to be improved: should I promote flags to data members?);
6726  //  b) Book profile to hold all flags for differential flow;
6727  //  c) Book e-b-e quantities;
6728  //  d) Book profiles;
6729  //  e) Book histograms holding final results. 
6730  
6731  // a) Define flags locally (to be improved: should I promote flags to data members?): 
6732  TString typeFlag[2] = {"RP","POI"}; 
6733  TString ptEtaFlag[2] = {"p_{T}","#eta"};
6734  TString powerFlag[2] = {"linear","quadratic"};
6735  TString sinCosFlag[2] = {"sin","cos"};
6736  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
6737  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
6738  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
6739  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
6740  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
6741  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6742  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6743  Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6744   
6745  // b) Book profile to hold all flags for differential flow:
6746  TString diffFlowFlagsName = "fDiffFlowFlags";
6747  diffFlowFlagsName += fAnalysisLabel->Data();
6748  fDiffFlowFlags = new TProfile(diffFlowFlagsName.Data(),"Flags for Differential Flow",4,0,4);
6749  fDiffFlowFlags->SetTickLength(-0.01,"Y");
6750  fDiffFlowFlags->SetMarkerStyle(25);
6751  fDiffFlowFlags->SetLabelSize(0.05);
6752  fDiffFlowFlags->SetLabelOffset(0.02,"Y");
6753  (fDiffFlowFlags->GetXaxis())->SetBinLabel(1,"Particle Weights");
6754  (fDiffFlowFlags->GetXaxis())->SetBinLabel(2,"Event Weights");
6755  (fDiffFlowFlags->GetXaxis())->SetBinLabel(3,"Corrected for NUA?");
6756  (fDiffFlowFlags->GetXaxis())->SetBinLabel(4,"Calculated 2D flow?");
6757  fDiffFlowList->Add(fDiffFlowFlags);
6758
6759  // c) Book e-b-e quantities:
6760  // Event-by-event r_{m*n,k}(pt,eta), p_{m*n,k}(pt,eta) and q_{m*n,k}(pt,eta)
6761  // Explanantion of notation:
6762  //  1.) n is harmonic, m is multiple of harmonic;
6763  //  2.) k is power of particle weight;
6764  //  3.) r_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for RPs in particular (pt,eta) bin (i-th RP is weighted with w_i^k);   
6765  //  4.) p_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for POIs in particular (pt,eta) bin 
6766  //                          (if i-th POI is also RP, than it is weighted with w_i^k);   
6767  //  5.) q_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for particles which are both RPs and POIs in particular (pt,eta) bin 
6768  //                          (i-th RP&&POI is weighted with w_i^k)            
6769   
6770  // 1D:
6771  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP && POI )
6772  { 
6773   for(Int_t pe=0;pe<2;pe++) // pt or eta
6774   {
6775    for(Int_t m=0;m<4;m++) // multiple of harmonic
6776    {
6777     for(Int_t k=0;k<9;k++) // power of particle weight
6778     {
6779      fReRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),
6780                                              Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6781      fImRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),
6782                                              Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6783     }
6784    }
6785   }
6786  } 
6787  // to be improved (add explanation of fs1dEBE[t][pe][k]):   
6788  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
6789  { 
6790   for(Int_t pe=0;pe<2;pe++) // pt or eta
6791   {
6792    for(Int_t k=0;k<9;k++) // power of particle weight
6793    {
6794     fs1dEBE[t][pe][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),
6795                                      Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6796    }
6797   }
6798  }
6799  // correction terms for nua:
6800  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
6801  { 
6802   for(Int_t pe=0;pe<2;pe++) // pt or eta
6803   {
6804    for(Int_t sc=0;sc<2;sc++) // sin or cos
6805    {
6806     for(Int_t cti=0;cti<9;cti++) // correction term index
6807     {
6808      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = new TH1D(Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),
6809                                              Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6810     }
6811    }
6812   }
6813  } 
6814  // 2D:
6815  TProfile2D styleRe("typeMultiplePowerRe","typeMultiplePowerRe",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6816  TProfile2D styleIm("typeMultiplePowerIm","typeMultiplePowerIm",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6817  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
6818  { 
6819   for(Int_t m=0;m<4;m++)
6820   {
6821    for(Int_t k=0;k<9;k++)
6822    {
6823     fReRPQ2dEBE[t][m][k] = (TProfile2D*)styleRe.Clone(Form("typeFlag%dmultiple%dpower%dRe",t,m,k)); 
6824     fImRPQ2dEBE[t][m][k] = (TProfile2D*)styleIm.Clone(Form("typeFlag%dmultiple%dpower%dIm",t,m,k));
6825    }
6826   } 
6827  } 
6828  TProfile2D styleS("typePower","typePower",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6829  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
6830  { 
6831   for(Int_t k=0;k<9;k++)
6832   {
6833    fs2dEBE[t][k] = (TProfile2D*)styleS.Clone(Form("typeFlag%dpower%d",t,k));
6834   }
6835  }
6836  // reduced correlations e-b-e:
6837  TString diffFlowCorrelationsEBEName = "fDiffFlowCorrelationsEBE";
6838  diffFlowCorrelationsEBEName += fAnalysisLabel->Data();
6839  for(Int_t t=0;t<2;t++) // type: RP or POI
6840  { 
6841   for(Int_t pe=0;pe<2;pe++) // pt or eta
6842   {
6843    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
6844    {
6845     fDiffFlowCorrelationsEBE[t][pe][rci] = new TH1D(Form("%s, %s, %s, %s",diffFlowCorrelationsEBEName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),Form("%s, %s, %s, %s",diffFlowCorrelationsEBEName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]);
6846    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
6847   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6848  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6849  // event weights for reduced correlations e-b-e:
6850  TString diffFlowEventWeightsForCorrelationsEBEName = "fDiffFlowEventWeightsForCorrelationsEBE";
6851  diffFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
6852  for(Int_t t=0;t<2;t++) // type: RP or POI
6853  { 
6854   for(Int_t pe=0;pe<2;pe++) // pt or eta
6855   {
6856    for(Int_t rci=0;rci<4;rci++) // event weight for reduced correlation index
6857    {
6858     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci] = new TH1D(Form("%s, %s, %s, eW for %s",diffFlowEventWeightsForCorrelationsEBEName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),Form("%s, %s, %s, eW for %s",diffFlowEventWeightsForCorrelationsEBEName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]);
6859    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
6860   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6861  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6862       
6863  // d) Book profiles;
6864  // reduced correlations:
6865  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
6866  diffFlowCorrelationsProName += fAnalysisLabel->Data();
6867  // corrections terms:
6868  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
6869  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
6870  for(Int_t t=0;t<2;t++) // type: RP or POI
6871  { 
6872   for(Int_t pe=0;pe<2;pe++) // pt or eta
6873   {
6874    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
6875    {
6876     // reduced correlations:
6877     fDiffFlowCorrelationsPro[t][pe][rci] = new TProfile(Form("%s, %s, %s, %s",diffFlowCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),Form("%s, %s, %s, %s",diffFlowCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[rci].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe],"s");
6878     fDiffFlowCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
6879     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
6880    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
6881   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6882  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6883  // correction terms for nua:
6884  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
6885  { 
6886   for(Int_t pe=0;pe<2;pe++) // pt or eta
6887   {
6888    for(Int_t sc=0;sc<2;sc++) // sin or cos
6889    {
6890     for(Int_t cti=0;cti<9;cti++) // correction term index
6891     {
6892      fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = new TProfile(Form("%s, %s, %s, %s, cti = %d",diffFlowCorrectionTermsForNUAProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1),Form("%s, %s, %s, %s, cti = %d",diffFlowCorrectionTermsForNUAProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6893      fDiffFlowCorrectionsProList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]);
6894     }
6895    }
6896   }
6897  } 
6898  // e) Book histograms holding final results. 
6899  // reduced correlations:
6900  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
6901  diffFlowCorrelationsHistName += fAnalysisLabel->Data();
6902  // corrections terms:
6903  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
6904  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
6905  // differential covariances:
6906  TString diffFlowCovariancesName = "fDiffFlowCovariances";
6907  diffFlowCovariancesName += fAnalysisLabel->Data();
6908  // differential Q-cumulants:
6909  TString diffFlowCumulantsName = "fDiffFlowCumulants";
6910  diffFlowCumulantsName += fAnalysisLabel->Data();
6911  // differential flow:
6912  TString diffFlowName = "fDiffFlow";
6913  diffFlowName += fAnalysisLabel->Data();
6914  for(Int_t t=0;t<2;t++) // type: RP or POI
6915  { 
6916   for(Int_t pe=0;pe<2;pe++) // pt or eta
6917   {
6918    for(Int_t index=0;index<4;index++) 
6919    {
6920     // reduced correlations:
6921     fDiffFlowCorrelationsHist[t][pe][index] = new TH1D(Form("%s, %s, %s, %s",diffFlowCorrelationsHistName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[index].Data()),Form("%s, %s, %s, %s",diffFlowCorrelationsHistName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[index].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]);
6922     fDiffFlowCorrelationsHist[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
6923     fDiffFlowCorrelationsHistList[t][pe]->Add(fDiffFlowCorrelationsHist[t][pe][index]); 
6924     // differential Q-cumulants:
6925     fDiffFlowCumulants[t][pe][index] = new TH1D(Form("%s, %s, %s, %s",diffFlowCumulantsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialCumulantIndex[index].Data()),Form("%s, %s, %s, %s",diffFlowCumulantsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialCumulantIndex[index].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]);
6926     fDiffFlowCumulants[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
6927     fDiffFlowCumulantsHistList[t][pe]->Add(fDiffFlowCumulants[t][pe][index]); 
6928     // differential flow estimates from Q-cumulants:
6929     fDiffFlow[t][pe][index] = new TH1D(Form("%s, %s, %s, %s",diffFlowName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialFlowIndex[index].Data()),Form("%s, %s, %s, %s",diffFlowName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialFlowIndex[index].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]);
6930     fDiffFlow[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
6931     fDiffFlowHistList[t][pe]->Add(fDiffFlow[t][pe][index]); 
6932    } // end of for(Int_t index=0;index<4;index++) 
6933    for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index 
6934    {
6935     // differential covariances:
6936     fDiffFlowCovariances[t][pe][covIndex] = new TH1D(Form("%s, %s, %s, %s",diffFlowCovariancesName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),covarianceName[covIndex].Data()),Form("%s, %s, %s, %s",diffFlowCovariancesName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),covarianceName[covIndex].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]);
6937     fDiffFlowCovariances[t][pe][covIndex]->SetXTitle(ptEtaFlag[pe].Data());
6938     fDiffFlowCovariancesHistList[t][pe]->Add(fDiffFlowCovariances[t][pe][covIndex]); 
6939    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index
6940    // products of both types of correlations: 
6941    TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
6942    diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
6943    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
6944    {
6945     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
6946     {
6947      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = new TProfile(Form("%s, %s, %s, %s, %s",diffFlowProductOfCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),mixedCorrelationIndex[mci1].Data(),mixedCorrelationIndex[mci2].Data()),Form("%s, %s, %s, %s #times %s",diffFlowProductOfCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),mixedCorrelationIndex[mci1].Data(),mixedCorrelationIndex[mci2].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6948      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
6949      fDiffFlowProductOfCorrelationsProList[t][pe]->Add(fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]); 
6950      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
6951     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
6952    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
6953   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6954  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6955  // sums of event weights for reduced correlations: 
6956  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
6957  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
6958  for(Int_t t=0;t<2;t++) // type is RP or POI
6959  { 
6960   for(Int_t pe=0;pe<2;pe++) // pt or eta
6961   { 
6962    for(Int_t p=0;p<2;p++) // power of weights is either 1 or 2
6963    {
6964     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
6965     {
6966      fDiffFlowSumOfEventWeights[t][pe][p][ew] = new TH1D(Form("%s, %s, %s, %s, %s",diffFlowSumOfEventWeightsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),powerFlag[p].Data(),reducedCorrelationIndex[ew].Data()),Form("%s, %s, %s, power = %s, %s",diffFlowSumOfEventWeightsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),powerFlag[p].Data(),reducedCorrelationIndex[ew].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6967      fDiffFlowSumOfEventWeights[t][pe][p][ew]->SetXTitle(ptEtaFlag[pe].Data());
6968      fDiffFlowSumOfEventWeightsHistList[t][pe][p]->Add(fDiffFlowSumOfEventWeights[t][pe][p][ew]); // to be improved (add dedicated list to hold all this)
6969     }
6970    }
6971   }
6972  } 
6973  // sum of products of event weights for both types of correlations: 
6974  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
6975  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
6976  for(Int_t t=0;t<2;t++) // type is RP or POI
6977  {
6978   for(Int_t pe=0;pe<2;pe++) // pt or eta
6979   { 
6980    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
6981    {
6982     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
6983     {
6984      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = new TH1D(Form("%s, %s, %s, %s, %s",diffFlowSumOfProductOfEventWeightsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),mixedCorrelationIndex[mci1].Data(),mixedCorrelationIndex[mci2].Data()),Form("%s, %s, %s, %s #times %s",diffFlowSumOfProductOfEventWeightsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),mixedCorrelationIndex[mci1].Data(),mixedCorrelationIndex[mci2].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
6985      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
6986      fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->Add(fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]); 
6987      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
6988     }
6989    }
6990   }
6991  } 
6992  // correction terms for nua:
6993  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
6994  { 
6995   for(Int_t pe=0;pe<2;pe++) // pt or eta
6996   {
6997    for(Int_t sc=0;sc<2;sc++) // sin or cos
6998    {
6999     for(Int_t cti=0;cti<9;cti++) // correction term index
7000     {
7001      fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = new TH1D(Form("%s, %s, %s, %s, cti = %d",diffFlowCorrectionTermsForNUAHistName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1),Form("%s, %s, %s, %s, cti = %d",diffFlowCorrectionTermsForNUAHistName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
7002      fDiffFlowCorrectionsHistList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]);
7003     }
7004    }
7005   }
7006  } 
7007           
7008 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
7009
7010
7011 //================================================================================================================================
7012
7013 /*
7014 void AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNUAForIntQcumulants() // to be improved (do I really need this method?)
7015 {
7016  // Calculate final corrections for non-uniform acceptance for Q-cumulants.
7017   
7018  // Corrections for non-uniform acceptance are stored in histogram fCorrectionsForNUA,
7019  // binning of fCorrectionsForNUA is organized as follows:
7020  //
7021  // 1st bin: correction to QC{2}
7022  // 2nd bin: correction to QC{4}
7023  // 3rd bin: correction to QC{6}
7024  // 4th bin: correction to QC{8}
7025   
7026  // shortcuts flags:
7027  Int_t pW = (Int_t)(useParticleWeights);
7028  
7029  Int_t eW = -1;
7030  
7031  if(eventWeights == "exact")
7032  {
7033   eW = 0;
7034  }
7035
7036  for(Int_t sc=0;sc<2;sc++) // sin or cos terms flag
7037  {
7038   if(!(fQCorrelations[pW][eW] && fQCorrections[pW][eW][sc] && fCorrections[pW][eW]))
7039   {
7040    cout<<"WARNING: fQCorrelations[pW][eW] && fQCorrections[pW][eW][sc] && fCorrections[pW][eW] is NULL in AFAWQC::CFCFNUAFIF() !!!!"<<endl;
7041    cout<<"pW = "<<pW<<endl;
7042    cout<<"eW = "<<eW<<endl;
7043    cout<<"sc = "<<sc<<endl;
7044    exit(0);
7045   }
7046  }  
7047
7048  // measured 2-, 4-, 6- and 8-particle azimuthal correlations (biased with non-uniform acceptance!):
7049  Double_t two = fQCorrelations[pW][eW]->GetBinContent(1); // <<2>>
7050  //Double_t four = fQCorrelations[pW][eW]->GetBinContent(11); // <<4>>
7051  //Double_t six = fQCorrelations[pW][eW]->GetBinContent(24); // <<6>>
7052  //Double_t eight = fQCorrelations[pW][eW]->GetBinContent(31); // <<8>>
7053  
7054  // correction terms to QC{2}:
7055  // <<cos(n*phi1)>>^2
7056  Double_t two1stTerm = pow(fQCorrections[pW][eW][1]->GetBinContent(1),2); 
7057  // <<sin(n*phi1)>>^2
7058  Double_t two2ndTerm = pow(fQCorrections[pW][eW][0]->GetBinContent(1),2); 
7059  // final corrections for non-uniform acceptance to QC{2}:
7060  Double_t correctionQC2 = -1.*two1stTerm-1.*two2ndTerm;
7061  fCorrections[pW][eW]->SetBinContent(1,correctionQC2); 
7062  
7063  // correction terms to QC{4}:
7064  // <<cos(n*phi1)>> <<cos(n*(phi1-phi2-phi3))>>
7065  Double_t four1stTerm = fQCorrections[pW][eW][1]->GetBinContent(1)*fQCorrections[pW][eW][1]->GetBinContent(3);  
7066  // <<sin(n*phi1)>> <<sin(n*(phi1-phi2-phi3))>>
7067  Double_t four2ndTerm = fQCorrections[pW][eW][0]->GetBinContent(1)*fQCorrections[pW][eW][0]->GetBinContent(3);  
7068  // <<cos(n*(phi1+phi2))>>^2
7069  Double_t four3rdTerm = pow(fQCorrections[pW][eW][1]->GetBinContent(2),2); 
7070  // <<sin(n*(phi1+phi2))>>^2
7071  Double_t four4thTerm = pow(fQCorrections[pW][eW][0]->GetBinContent(2),2); 
7072  // <<cos(n*(phi1+phi2))>> (<<cos(n*phi1)>>^2 - <<sin(n*phi1)>>^2)
7073  Double_t four5thTerm = fQCorrections[pW][eW][1]->GetBinContent(2)
7074                       * (pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)-pow(fQCorrections[pW][eW][0]->GetBinContent(1),2));
7075  // <<sin(n*(phi1+phi2))>> <<cos(n*phi1)>> <<sin(n*phi1)>>
7076  Double_t four6thTerm = fQCorrections[pW][eW][0]->GetBinContent(2)
7077                       * fQCorrections[pW][eW][1]->GetBinContent(1)
7078                       * fQCorrections[pW][eW][0]->GetBinContent(1);         
7079  // <<cos(n*(phi1-phi2))>> (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)
7080  Double_t four7thTerm = two*(pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)+pow(fQCorrections[pW][eW][0]->GetBinContent(1),2));  
7081  // (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)^2
7082  Double_t four8thTerm = pow(pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)+pow(fQCorrections[pW][eW][0]->GetBinContent(1),2),2);      
7083  // final correction to QC{4}:
7084  Double_t correctionQC4 = -4.*four1stTerm+4.*four2ndTerm-four3rdTerm-four4thTerm
7085                         + 4.*four5thTerm+8.*four6thTerm+8.*four7thTerm-6.*four8thTerm;                            
7086  fCorrections[pW][eW]->SetBinContent(2,correctionQC4);   
7087
7088  // ... to be improved (continued for 6th and 8th order)                                                    
7089
7090
7091 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNUAForIntQcumulants()
7092 */
7093
7094 //================================================================================================================================
7095
7096
7097 void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
7098 {
7099  // Calculate generalized Q-cumulants (cumulants corrected for non-unifom acceptance).
7100  
7101  // measured 2-, 4-, 6- and 8-particle correlations (biased by non-uniform acceptance!):
7102  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7103  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7104  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
7105  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
7106  
7107  // statistical error of measured 2-, 4-, 6- and 8-particle correlations:
7108  //Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <<2>>
7109  //Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <<4>>
7110  //Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <<6>>
7111  //Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <<8>>
7112
7113  // QC{2}:
7114  // <<cos(n*phi1)>>^2
7115  Double_t two1stTerm = pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2); 
7116  //Double_t two1stTermErrorSquared = pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(1),2); 
7117  // <<sin(n*phi1)>>^2
7118  Double_t two2ndTerm = pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2); 
7119  //Double_t two2ndTermErrorSquared = pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(1),2); 
7120  // generalized QC{2}:
7121  Double_t gQC2 = two - two1stTerm - two2ndTerm; // to be improved (terminology, notation)
7122  fIntFlowQcumulants->SetBinContent(1,gQC2); 
7123  //fIntFlowQcumulants->SetBinError(1,0.); // to be improved (propagate error) 
7124  
7125  // QC{4}:
7126  // <<cos(n*phi1)>> <<cos(n*(phi1-phi2-phi3))>>
7127  Double_t four1stTerm = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1)
7128                       * fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3);  
7129  // <<sin(n*phi1)>> <<sin(n*(phi1-phi2-phi3))>>
7130  Double_t four2ndTerm = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1)
7131                       * fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3);  
7132  // <<cos(n*(phi1+phi2))>>^2
7133  Double_t four3rdTerm = pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2),2); 
7134  // <<sin(n*(phi1+phi2))>>^2
7135  Double_t four4thTerm = pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2),2); 
7136  // <<cos(n*(phi1+phi2))>> (<<cos(n*phi1)>>^2 - <<sin(n*phi1)>>^2)
7137  Double_t four5thTerm = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2)
7138                       * (pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2)
7139                       - pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2));
7140  // <<sin(n*(phi1+phi2))>> <<cos(n*phi1)>> <<sin(n*phi1)>>
7141  Double_t four6thTerm = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2)
7142                       * fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1)
7143                       * fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1);         
7144  // <<cos(n*(phi1-phi2))>> (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)
7145  Double_t four7thTerm = two*(pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2)
7146                       + pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2));  
7147  // (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)^2
7148  Double_t four8thTerm = pow(pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2)
7149                       + pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2),2);      
7150  // generalized QC{4}:
7151  Double_t gQC4 = four-2.*pow(two,2.)-4.*four1stTerm+4.*four2ndTerm-four3rdTerm
7152                - four4thTerm+4.*four5thTerm+8.*four6thTerm+8.*four7thTerm-6.*four8thTerm;                            
7153  fIntFlowQcumulants->SetBinContent(2,gQC4);   
7154  //fIntFlowQcumulants->SetBinError(2,0.); // to be improved (propagate error) 
7155
7156  // ... to be improved (continued for 6th and 8th order)                                                    
7157     
7158 } // end of void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
7159
7160
7161 //================================================================================================================================
7162
7163
7164 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectedForNUA()
7165 {
7166  // Calculate integrated flow from generalized Q-cumulants (corrected for non-uniform acceptance).
7167  
7168  // to be improved: add protection for NULL pointers, propagate statistical errors from 
7169  // measured correlations and correction terms
7170  
7171  // generalized Q-cumulants:
7172  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
7173  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
7174  //Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
7175  //Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
7176  
7177  // integrated flow estimates:
7178  Double_t v2 = 0.; // v{2,QC}  
7179  Double_t v4 = 0.; // v{4,QC}  
7180  //Double_t v6 = 0.; // v{6,QC}  
7181  //Double_t v8 = 0.; // v{8,QC}
7182
7183  // calculate integrated flow estimates from generalized Q-cumulants: 
7184  if(qc2>=0.) v2 = pow(qc2,1./2.); 
7185  if(qc4<=0.) v4 = pow(-1.*qc4,1./4.); 
7186  //if(qc6>=0.) v6 = pow((1./4.)*qc6,1./6.); 
7187  //if(qc8<=0.) v8 = pow((-1./33.)*qc8,1./8.); 
7188
7189  // store integrated flow estimates from generalized Q-cumulants:
7190  fIntFlow->SetBinContent(1,v2);
7191  fIntFlow->SetBinContent(2,v4);
7192  //fIntFlow->SetBinContent(3,v6);
7193  //fIntFlow->SetBinContent(4,v8);
7194
7195 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectedForNUA()
7196
7197    
7198 //================================================================================================================================
7199
7200
7201 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow() 
7202 {
7203  // From profile fIntFlowCorrectionTermsForNUAPro[2] access measured corretion terms
7204  // and their spread, correctly calculate the statistical errors and store the final 
7205  // results and statistical errors for correction terms in histogram fIntFlowCorrectionTermsForNUAHist[2].
7206  //
7207  // Remark: Statistical error of correction temrs is calculated as:
7208  //
7209  //          statistical error = termA * spread * termB:
7210  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
7211  //          termB = 1/sqrt(1-termA^2)   
7212  
7213  /* // to be improved (implement protection here)
7214  for(Int_t power=0;power<2;power++)
7215  { 
7216   if(!(fIntFlowCorrelationsHist && fIntFlowCorrelationsPro && fIntFlowSumOfEventWeights[power])) 
7217   {
7218    cout<<"WARNING: fIntFlowCorrelationsHist && fIntFlowCorrelationsPro && fIntFlowSumOfEventWeights[power] is NULL in AFAWQC::FCIF() !!!!"<<endl;
7219    cout<<"power = "<<power<<endl;
7220    exit(0);
7221   }
7222  }
7223  */
7224   
7225  for(Int_t sc=0;sc<2;sc++) // sin or cos correction terms 
7226  {
7227   for(Int_t ci=1;ci<=10;ci++) // correction term index
7228   {
7229    Double_t correction = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci);
7230    //Double_t spread = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinError(ci);
7231    //Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeights[0]->GetBinContent(ci);
7232    //Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeights[1]->GetBinContent(ci);
7233    //Double_t termA = 0.;
7234    //Double_t termB = 0.;
7235    //if(sumOfLinearEventWeights)
7236    //{
7237    // termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
7238    //} else
7239    // {
7240    //  cout<<"WARNING: sumOfLinearEventWeights == 0 in AFAWQC::FCIF() !!!!"<<endl;
7241    //  cout<<"         (for "<<2*ci<<"-particle correlation)"<<endl;
7242    // }
7243    /*
7244    if(1.-pow(termA,2.) > 0.)
7245    {
7246     termB = 1./pow(1-pow(termA,2.),0.5);
7247    } else
7248      {
7249       cout<<"WARNING: 1.-pow(termA,2.) <= 0 in AFAWQC::FCIF() !!!!"<<endl;   
7250       cout<<"         (for "<<2*ci<<"-particle correlation)"<<endl;
7251      }     
7252    Double_t statisticalError = termA * spread * termB;
7253    */
7254    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinContent(ci,correction);
7255    //fIntFlowCorrectionTermsForNUAHist[sc]->SetBinError(ci,statisticalError);
7256   } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
7257  } // end of for(Int sc=0;sc<2;sc++) // sin or cos correction terms 
7258                                                                                                                                                                                                
7259 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow()
7260
7261
7262 //================================================================================================================================
7263
7264
7265 void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
7266 {
7267  // Get pointers to all objects relevant for calculations with nested loops.
7268    
7269  TList *nestedLoopsList = dynamic_cast<TList*>(fHistList->FindObject("Nested Loops"));
7270  if(nestedLoopsList) 
7271  {
7272   this->SetNestedLoopsList(nestedLoopsList);
7273  } else
7274    {
7275     cout<<"WARNING: nestedLoopsList is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
7276     exit(0);
7277    }
7278     
7279   TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
7280   TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
7281   TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
7282   TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
7283    
7284   TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
7285   evaluateNestedLoopsName += fAnalysisLabel->Data();  
7286   TProfile *evaluateNestedLoops = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(evaluateNestedLoopsName.Data()));
7287   Bool_t bEvaluateIntFlowNestedLoops = kFALSE;
7288   Bool_t bEvaluateDiffFlowNestedLoops = kFALSE;
7289   if(evaluateNestedLoops)
7290   {
7291    this->SetEvaluateNestedLoops(evaluateNestedLoops);
7292    bEvaluateIntFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(1);
7293    bEvaluateDiffFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(2);
7294   }
7295   // nested loops relevant for integrated flow:  
7296   if(bEvaluateIntFlowNestedLoops)
7297   {
7298    // correlations:
7299    TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
7300    intFlowDirectCorrelationsName += fAnalysisLabel->Data();
7301    TProfile *intFlowDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowDirectCorrelationsName.Data()));
7302    if(intFlowDirectCorrelations) 
7303    { 
7304     this->SetIntFlowDirectCorrelations(intFlowDirectCorrelations);
7305    } else
7306      {
7307       cout<<"WARNING: intFlowDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
7308       exit(0);
7309      }
7310    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
7311    {
7312     TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
7313     intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
7314     TProfile *intFlowExtraDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowExtraDirectCorrelationsName.Data()));
7315     if(intFlowExtraDirectCorrelations) 
7316     { 
7317      this->SetIntFlowExtraDirectCorrelations(intFlowExtraDirectCorrelations);
7318     } else
7319       {
7320        cout<<"WARNING: intFlowExtraDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
7321        exit(0);
7322       }       
7323    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
7324    // correction terms for non-uniform acceptance:
7325    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
7326    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
7327    TProfile *intFlowDirectCorrectionTermsForNUA[2] = {NULL};
7328    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
7329    {
7330     intFlowDirectCorrectionTermsForNUA[sc] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s: %s terms",intFlowDirectCorrectionTermsForNUAName.Data(),sinCosFlag[sc].Data())));
7331     if(intFlowDirectCorrectionTermsForNUA[sc]) 
7332     { 
7333      this->SetIntFlowDirectCorrectionTermsForNUA(intFlowDirectCorrectionTermsForNUA[sc],sc);
7334     } else
7335       {
7336        cout<<"WARNING: intFlowDirectCorrectionTermsForNUA[sc] is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
7337        cout<<"sc = "<<sc<<endl;
7338        exit(0);
7339       }
7340    } // end of for(Int_t sc=0;sc<2;sc++) 
7341   } // end of if(bEvaluateIntFlowNestedLoops)
7342     
7343   // nested loops relevant for differential flow:  
7344   if(bEvaluateDiffFlowNestedLoops)
7345   {
7346    // correlations:
7347    TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
7348    diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
7349    TProfile *diffFlowDirectCorrelations[2][2][4] = {{{NULL}}};
7350    for(Int_t t=0;t<2;t++)
7351    {
7352     for(Int_t pe=0;pe<2;pe++)
7353     {
7354      for(Int_t ci=0;ci<4;ci++) // correlation index
7355      {
7356       diffFlowDirectCorrelations[t][pe][ci] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s, %s, %s, %s",diffFlowDirectCorrelationsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedCorrelationIndex[ci].Data())));
7357       if(diffFlowDirectCorrelations[t][pe][ci])
7358       {
7359        this->SetDiffFlowDirectCorrelations(diffFlowDirectCorrelations[t][pe][ci],t,pe,ci);
7360       } else
7361         {
7362          cout<<"WARNING: diffFlowDirectCorrelations[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
7363          cout<<"t  = "<<t<<endl;
7364          cout<<"pe = "<<pe<<endl;   
7365          cout<<"ci = "<<ci<<endl;
7366         }     
7367      } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
7368     } // end of for(Int_t pe=0;pe<2;pe++)
7369    } // end of for(Int_t t=0;t<2;t++)   
7370    // correction terms for non-uniform acceptance:
7371    TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
7372    diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();  
7373    TProfile *diffFlowDirectCorrectionTermsForNUA[2][2][2][10] = {{{{NULL}}}};   
7374    for(Int_t t=0;t<2;t++)
7375    {
7376     for(Int_t pe=0;pe<2;pe++)
7377     {
7378      // correction terms for NUA:
7379      for(Int_t sc=0;sc<2;sc++) // sin or cos
7380      {
7381       for(Int_t cti=0;cti<9;cti++) // correction term index
7382       {
7383        diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s, %s, %s, %s, cti = %d",diffFlowDirectCorrectionTermsForNUAName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),cti+1)));
7384        if(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti])
7385        {
7386         this->SetDiffFlowDirectCorrectionTermsForNUA(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti],t,pe,sc,cti);
7387        } else
7388          {
7389           cout<<"WARNING: diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
7390           cout<<"t   = "<<t<<endl;
7391           cout<<"pe  = "<<pe<<endl;   
7392           cout<<"sc  = "<<sc<<endl;
7393           cout<<"cti = "<<cti<<endl;
7394          }    
7395       } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
7396      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
7397     } // end of for(Int_t pe=0;pe<2;pe++)
7398    } // end of for(Int_t t=0;t<2;t++)
7399    // number of RPs and POIs in selected pt and eta bins for cross-checkings:
7400    TString noOfParticlesInBinName = "fNoOfParticlesInBin";
7401    TH1D *noOfParticlesInBin = NULL;
7402    noOfParticlesInBin = dynamic_cast<TH1D*>(nestedLoopsList->FindObject(noOfParticlesInBinName.Data()));
7403    if(noOfParticlesInBin)
7404    {
7405     this->SetNoOfParticlesInBin(noOfParticlesInBin);
7406    } else
7407      {
7408       cout<<endl;
7409       cout<<" WARNING (QC): noOfParticlesInBin is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
7410       cout<<endl;
7411      }
7412   } // end of if(bEvaluateDiffFlowNestedLoops)
7413
7414 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
7415
7416
7417 //================================================================================================================================
7418
7419
7420 void AliFlowAnalysisWithQCumulants::StoreHarmonic()
7421 {
7422  // Store flow harmonic in common control histograms.
7423
7424  (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
7425  (fCommonHists2nd->GetHarmonic())->Fill(0.5,fHarmonic);
7426  (fCommonHists4th->GetHarmonic())->Fill(0.5,fHarmonic);
7427  (fCommonHists6th->GetHarmonic())->Fill(0.5,fHarmonic);
7428  (fCommonHists8th->GetHarmonic())->Fill(0.5,fHarmonic);
7429
7430 } // end of void AliFlowAnalysisWithQCumulants::StoreHarmonic()
7431
7432
7433 //================================================================================================================================
7434
7435
7436 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta) // type = RP or POI 
7437 {
7438  // Calculate all correlations needed for differential flow using particle weights.
7439  
7440  Int_t t = -1; // type flag 
7441  Int_t pe = -1; // ptEta flag
7442  
7443  if(type == "RP")
7444  {
7445   t = 0;
7446  } else if(type == "POI")
7447    {
7448     t = 1;
7449    }
7450
7451  if(ptOrEta == "Pt")
7452  {
7453   pe = 0;
7454  } else if(ptOrEta == "Eta")
7455    {
7456     pe = 1;
7457    }
7458     
7459  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7460  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7461  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7462  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7463
7464  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
7465  Double_t dReQ1n1k = (*fReQ)(0,1);
7466  Double_t dReQ2n2k = (*fReQ)(1,2);
7467  Double_t dReQ1n3k = (*fReQ)(0,3);
7468  //Double_t dReQ4n4k = (*fReQ)(3,4);
7469  Double_t dImQ1n1k = (*fImQ)(0,1);
7470  Double_t dImQ2n2k = (*fImQ)(1,2);
7471  Double_t dImQ1n3k = (*fImQ)(0,3);
7472  //Double_t dImQ4n4k = (*fImQ)(3,4);
7473  
7474  // S^M_{p,k} (see .h file for the definition of fSMpk):
7475  Double_t dSM1p1k = (*fSMpk)(0,1);
7476  Double_t dSM1p2k = (*fSMpk)(0,2);
7477  Double_t dSM1p3k = (*fSMpk)(0,3);
7478  Double_t dSM2p1k = (*fSMpk)(1,1);
7479  Double_t dSM3p1k = (*fSMpk)(2,1);
7480  
7481  // looping over all bins and calculating reduced correlations: 
7482  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7483  {
7484   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
7485   Double_t p1n0kRe = 0.;
7486   Double_t p1n0kIm = 0.;
7487
7488   // number of POIs in particular (pt,eta) bin):
7489   Double_t mp = 0.;
7490
7491   // real and imaginary parts of q_{m*n,k}: 
7492   // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
7493   Double_t q1n2kRe = 0.;
7494   Double_t q1n2kIm = 0.;
7495   Double_t q2n1kRe = 0.;
7496   Double_t q2n1kIm = 0.;
7497
7498   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
7499   Double_t s1p1k = 0.; 
7500   Double_t s1p2k = 0.; 
7501   Double_t s1p3k = 0.; 
7502    
7503   // M0111 from Eq. (118) in QC2c (to be improved (notation))
7504   Double_t dM0111 = 0.;
7505  
7506   if(type == "POI")
7507   {
7508    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
7509            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
7510    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
7511            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
7512             
7513    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7514     
7515    t = 1; // typeFlag = RP or POI
7516     
7517    // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
7518    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
7519            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
7520    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
7521            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));
7522    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
7523            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
7524    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
7525            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));
7526        
7527    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
7528    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
7529    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
7530    s1p3k = pow(fs1dEBE[2][pe][3]->GetBinContent(b)*fs1dEBE[2][pe][3]->GetBinEntries(b),1.); 
7531      
7532    // M0111 from Eq. (118) in QC2c (to be improved (notation)):
7533    dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
7534           - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
7535           + 2.*(s1p3k-s1p2k*dSM1p1k));
7536   }
7537    else if(type == "RP")
7538    {
7539     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
7540     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
7541             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
7542     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
7543             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
7544     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
7545             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
7546     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
7547             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
7548
7549     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
7550     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
7551     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
7552     s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
7553     
7554     // to be improved (cross-checked):
7555     p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
7556             * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
7557     p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
7558             * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
7559             
7560     mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7561      
7562     t = 0; // typeFlag = RP or POI
7563     
7564     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
7565     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
7566            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
7567            + 2.*(s1p3k-s1p2k*dSM1p1k));
7568     //...............................................................................................   
7569    }
7570    
7571    // 2'-particle correlation:
7572    Double_t two1n1nW0W1 = 0.;
7573    if(mp*dSM1p1k-s1p1k)
7574    {
7575     two1n1nW0W1 = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
7576                 / (mp*dSM1p1k-s1p1k);
7577    
7578     // fill profile to get <<2'>>     
7579     fDiffFlowCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1,mp*dSM1p1k-s1p1k);
7580     // histogram to store <2'> e-b-e (needed in some other methods):
7581     fDiffFlowCorrelationsEBE[t][pe][0]->SetBinContent(b,two1n1nW0W1);      
7582     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->SetBinContent(b,mp*dSM1p1k-s1p1k);      
7583    } // end of if(mp*dSM1p1k-s1p1k)
7584    
7585    // 4'-particle correlation:
7586    Double_t four1n1n1n1nW0W1W1W1 = 0.;
7587    if(dM0111)
7588    {
7589     four1n1n1n1nW0W1W1W1 = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
7590                          - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
7591                          - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
7592                          - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
7593                          + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
7594                          - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
7595                          - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
7596                          + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
7597                          + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
7598                          + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
7599                          + 2.*s1p1k*dSM1p2k                                      
7600                          - 6.*s1p3k)        
7601                          / dM0111; // to be improved (notation of dM0111)
7602    
7603     // fill profile to get <<4'>>     
7604     fDiffFlowCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1,dM0111);
7605     // histogram to store <4'> e-b-e (needed in some other methods):
7606     fDiffFlowCorrelationsEBE[t][pe][1]->SetBinContent(b,four1n1n1n1nW0W1W1W1);      
7607     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->SetBinContent(b,dM0111);      
7608    } // end of if(dM0111)
7609  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7610
7611 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta); // type = RP or POI 
7612
7613
7614 //================================================================================================================================
7615
7616
7617 void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
7618 {
7619  // Fill common control histograms.
7620  
7621  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
7622  fCommonHists->FillControlHistograms(anEvent); 
7623  if(nRP>1)
7624  {
7625   fCommonHists2nd->FillControlHistograms(anEvent);                                        
7626   if(nRP>3)
7627   {
7628    fCommonHists4th->FillControlHistograms(anEvent);                                        
7629    if(nRP>5)
7630    {
7631     fCommonHists6th->FillControlHistograms(anEvent);                                        
7632     if(nRP>7)
7633     {
7634      fCommonHists8th->FillControlHistograms(anEvent);                                        
7635     } // end of if(nRP>7)  
7636    } // end of if(nRP>5) 
7637   } // end of if(nRP>3)                                                                                                                      
7638  } // end of if(nRP>1) 
7639  
7640 } // end of void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
7641
7642
7643 //================================================================================================================================
7644
7645
7646 void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities()
7647 {
7648  // Reset all event by event quantities.
7649  
7650  // integrated flow:
7651  fReQ->Zero();
7652  fImQ->Zero();
7653  fSMpk->Zero();
7654  fIntFlowCorrelationsEBE->Reset();
7655  fIntFlowEventWeightsForCorrelationsEBE->Reset();
7656  fIntFlowCorrelationsAllEBE->Reset();
7657  
7658  if(fApplyCorrectionForNUA)  
7659  {
7660   for(Int_t sc=0;sc<2;sc++)
7661   {
7662    fIntFlowCorrectionTermsForNUAEBE[sc]->Reset();
7663   } 
7664  }
7665     
7666  // differential flow:
7667  // 1D:
7668  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
7669  {
7670   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
7671   {
7672    for(Int_t m=0;m<4;m++) // multiple of harmonic
7673    {
7674     for(Int_t k=0;k<9;k++) // power of weight
7675     {
7676      if(fReRPQ1dEBE[t][pe][m][k]) fReRPQ1dEBE[t][pe][m][k]->Reset();
7677      if(fImRPQ1dEBE[t][pe][m][k]) fImRPQ1dEBE[t][pe][m][k]->Reset();
7678     }   
7679    }
7680   }
7681  }
7682   
7683  for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
7684  { 
7685   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
7686   {
7687    for(Int_t k=0;k<9;k++)
7688    {
7689     if(fs1dEBE[t][pe][k]) fs1dEBE[t][pe][k]->Reset();
7690    }
7691   }
7692  }
7693
7694  // e-b-e reduced correlations:
7695  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
7696  {  
7697   for(Int_t pe=0;pe<2;pe++) // pt or eta
7698   {
7699    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
7700    {
7701     if(fDiffFlowCorrelationsEBE[t][pe][rci]) fDiffFlowCorrelationsEBE[t][pe][rci]->Reset();
7702     if(fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]) fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]->Reset();
7703    }
7704   }
7705  }
7706     
7707  // correction terms for NUA:
7708  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
7709  {  
7710   for(Int_t pe=0;pe<2;pe++) // pt or eta
7711   {
7712    for(Int_t sc=0;sc<2;sc++) // sin or cos
7713    {
7714     for(Int_t cti=0;cti<9;cti++) // correction term index
7715     {
7716      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti]->Reset();  
7717     }
7718    }
7719   }      
7720  }
7721     
7722  // 2D (pt,eta)
7723  if(fCalculate2DFlow)
7724  {
7725   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
7726   {
7727    for(Int_t m=0;m<4;m++) // multiple of harmonic
7728    {
7729     for(Int_t k=0;k<9;k++) // power of weight
7730     {
7731      if(fReRPQ2dEBE[t][m][k]) fReRPQ2dEBE[t][m][k]->Reset();
7732      if(fImRPQ2dEBE[t][m][k]) fImRPQ2dEBE[t][m][k]->Reset();
7733     }   
7734    }
7735   }
7736   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
7737   { 
7738    for(Int_t k=0;k<9;k++)
7739    {
7740     if(fs2dEBE[t][k]) fs2dEBE[t][k]->Reset();
7741    }
7742   }  
7743  } // end of if(fCalculate2DFlow) 
7744
7745 } // end of void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities();
7746
7747
7748 //================================================================================================================================
7749
7750
7751 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
7752 {
7753  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
7754  
7755  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
7756  //  0: <<sin n(psi1)>>
7757  //  1: <<sin n(psi1+phi2)>>
7758  //  2: <<sin n(psi1+phi2-phi3)>>
7759  //  3: <<sin n(psi1-phi2-phi3)>>:
7760  //  4:
7761  //  5:
7762  //  6:
7763  
7764  // multiplicity:
7765  Double_t dMult = (*fSMpk)(0,0);
7766  
7767  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
7768  Double_t dReQ1n = (*fReQ)(0,0);
7769  Double_t dReQ2n = (*fReQ)(1,0);
7770  //Double_t dReQ3n = (*fReQ)(2,0);
7771  //Double_t dReQ4n = (*fReQ)(3,0);
7772  Double_t dImQ1n = (*fImQ)(0,0);
7773  Double_t dImQ2n = (*fImQ)(1,0);
7774  //Double_t dImQ3n = (*fImQ)(2,0);
7775  //Double_t dImQ4n = (*fImQ)(3,0);
7776
7777  Int_t t = -1; // type flag 
7778  Int_t pe = -1; // ptEta flag
7779  
7780  if(type == "RP")
7781  {
7782   t = 0;
7783  } else if(type == "POI")
7784    {
7785     t = 1;
7786    }
7787
7788  if(ptOrEta == "Pt")
7789  {
7790   pe = 0;
7791  } else if(ptOrEta == "Eta")
7792    {
7793     pe = 1;
7794    }
7795     
7796  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7797  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7798  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7799  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7800
7801  // looping over all bins and calculating correction terms: 
7802  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7803  {
7804   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
7805   Double_t p1n0kRe = 0.;
7806   Double_t p1n0kIm = 0.;
7807
7808   // number of POIs in particular pt or eta bin:
7809   Double_t mp = 0.;
7810
7811   // real and imaginary parts of q_{m*n,0} (non-weighted Q-vector evaluated for particles which are both RPs and POIs in particular pt or eta bin):
7812   Double_t q1n0kRe = 0.;
7813   Double_t q1n0kIm = 0.;
7814   Double_t q2n0kRe = 0.;
7815   Double_t q2n0kIm = 0.;
7816
7817   // number of particles which are both RPs and POIs in particular pt or eta bin:
7818   Double_t mq = 0.;
7819    
7820   if(type == "POI")
7821   {
7822    // q_{m*n,0}:
7823    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
7824            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
7825    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
7826            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
7827    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
7828            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
7829    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
7830            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
7831                  
7832    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7833   } 
7834   else if(type == "RP")
7835   {
7836    // q_{m*n,0}:
7837    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
7838            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
7839    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
7840            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
7841    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
7842            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
7843    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
7844            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
7845                  
7846    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
7847   }    
7848   if(type == "POI")
7849   {
7850    // p_{m*n,0}:
7851    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
7852            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
7853    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
7854            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
7855             
7856    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7857     
7858    t = 1; // typeFlag = RP or POI
7859   }
7860   else if(type == "RP")
7861   {
7862    // p_{m*n,0} = q_{m*n,0}:
7863    p1n0kRe = q1n0kRe; 
7864    p1n0kIm = q1n0kIm; 
7865            
7866    mp = mq; 
7867    
7868    t = 0; // typeFlag = RP or POI
7869   }
7870
7871   // <<sin n(psi1)>>:
7872   Double_t sinP1nPsi = 0.;
7873   if(mp)
7874   {
7875    sinP1nPsi = p1n0kIm/mp;
7876    // fill profile for <<sin n(psi1)>>:
7877    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
7878    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
7879    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
7880   } // end of if(mp)   
7881   
7882   // <<sin n(psi1+phi2)>>:
7883   Double_t sinP1nPsiP1nPhi = 0.;
7884   if(mp*dMult-mq)
7885   {
7886    sinP1nPsiP1nPhi = (p1n0kRe*dImQ1n+p1n0kIm*dReQ1n-q2n0kIm)/(mp*dMult-mq);
7887    // fill profile for <<sin n(psi1+phi2)>>:
7888    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhi,mp*dMult-mq);
7889    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
7890    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhi);
7891   } // end of if(mp*dMult-mq)   
7892   
7893   // <<sin n(psi1+phi2-phi3)>>:
7894   Double_t sinP1nPsi1P1nPhi2MPhi3 = 0.;
7895   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
7896   {
7897    sinP1nPsi1P1nPhi2MPhi3 = (p1n0kIm*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
7898                           - 1.*(q2n0kIm*dReQ1n-q2n0kRe*dImQ1n)  
7899                           - mq*dImQ1n+2.*q1n0kIm)
7900                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
7901    // fill profile for <<sin n(psi1+phi2)>>:
7902    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
7903    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
7904    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3);
7905   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
7906   
7907   // <<sin n(psi1-phi2-phi3)>>:
7908   Double_t sinP1nPsi1M1nPhi2MPhi3 = 0.;
7909   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
7910   {
7911    sinP1nPsi1M1nPhi2MPhi3 = (p1n0kIm*(pow(dReQ1n,2.)-pow(dImQ1n,2.))-2.*p1n0kRe*dReQ1n*dImQ1n
7912                           - 1.*(p1n0kIm*dReQ2n-p1n0kRe*dImQ2n)
7913                           + 2.*mq*dImQ1n-2.*q1n0kIm)
7914                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
7915    // fill profile for <<sin n(psi1+phi2)>>:
7916    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
7917    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
7918    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3);
7919   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
7920  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7921  
7922 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
7923
7924
7925 //================================================================================================================================
7926
7927
7928 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
7929 {
7930  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms).
7931  
7932  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
7933  //  0: <<cos n(psi)>>
7934  //  1: <<cos n(psi1+phi2)>>
7935  //  2: <<cos n(psi1+phi2-phi3)>>
7936  //  3: <<cos n(psi1-phi2-phi3)>>
7937  //  4:
7938  //  5:
7939  //  6:
7940  
7941  // multiplicity:
7942  Double_t dMult = (*fSMpk)(0,0);
7943  
7944  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
7945  Double_t dReQ1n = (*fReQ)(0,0);
7946  Double_t dReQ2n = (*fReQ)(1,0);
7947  //Double_t dReQ3n = (*fReQ)(2,0);
7948  //Double_t dReQ4n = (*fReQ)(3,0);
7949  Double_t dImQ1n = (*fImQ)(0,0);
7950  Double_t dImQ2n = (*fImQ)(1,0);
7951  //Double_t dImQ3n = (*fImQ)(2,0);
7952  //Double_t dImQ4n = (*fImQ)(3,0);
7953
7954  Int_t t = -1; // type flag 
7955  Int_t pe = -1; // ptEta flag
7956  
7957  if(type == "RP")
7958  {
7959   t = 0;
7960  } else if(type == "POI")
7961    {
7962     t = 1;
7963    }
7964
7965  if(ptOrEta == "Pt")
7966  {
7967   pe = 0;
7968  } else if(ptOrEta == "Eta")
7969    {
7970     pe = 1;
7971    }
7972     
7973  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7974  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7975  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7976  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7977
7978  // looping over all bins and calculating correction terms: 
7979  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7980  {
7981   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
7982   Double_t p1n0kRe = 0.;
7983   Double_t p1n0kIm = 0.;
7984
7985   // number of POIs in particular pt or eta bin:
7986   Double_t mp = 0.;
7987
7988   // real and imaginary parts of q_{m*n,0} (non-weighted Q-vector evaluated for particles which are both RPs and POIs in particular pt or eta bin):
7989   Double_t q1n0kRe = 0.;
7990   Double_t q1n0kIm = 0.;
7991   Double_t q2n0kRe = 0.;
7992   Double_t q2n0kIm = 0.;
7993
7994   // number of particles which are both RPs and POIs in particular pt or eta bin:
7995   Double_t mq = 0.;
7996    
7997   if(type == "POI")
7998   {
7999    // q_{m*n,0}:
8000    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
8001            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
8002    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
8003            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
8004    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
8005            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
8006    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
8007            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
8008                  
8009    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
8010   } 
8011   else if(type == "RP")
8012   {
8013    // q_{m*n,0}:
8014    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
8015            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
8016    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
8017            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
8018    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
8019            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
8020    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
8021            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
8022                  
8023    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
8024   }    
8025   if(type == "POI")
8026   {
8027    // p_{m*n,0}:
8028    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
8029            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
8030    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
8031            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
8032             
8033    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
8034     
8035    t = 1; // typeFlag = RP or POI
8036   }
8037   else if(type == "RP")
8038   {
8039    // p_{m*n,0} = q_{m*n,0}:
8040    p1n0kRe = q1n0kRe; 
8041    p1n0kIm = q1n0kIm; 
8042            
8043    mp = mq; 
8044    
8045    t = 0; // typeFlag = RP or POI
8046   }
8047
8048   // <<cos n(psi1)>>:
8049   Double_t cosP1nPsi = 0.;
8050   if(mp)
8051   {
8052    cosP1nPsi = p1n0kRe/mp;
8053    
8054    // fill profile for <<cos n(psi1)>>:
8055    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
8056    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
8057    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
8058   } // end of if(mp)   
8059   
8060   // <<cos n(psi1+phi2)>>:
8061   Double_t cosP1nPsiP1nPhi = 0.;
8062   if(mp*dMult-mq)
8063   {
8064    cosP1nPsiP1nPhi = (p1n0kRe*dReQ1n-p1n0kIm*dImQ1n-q2n0kRe)/(mp*dMult-mq);
8065    // fill profile for <<sin n(psi1+phi2)>>:
8066    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhi,mp*dMult-mq);
8067    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
8068    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhi);
8069   } // end of if(mp*dMult-mq)   
8070   
8071   // <<cos n(psi1+phi2-phi3)>>:
8072   Double_t cosP1nPsi1P1nPhi2MPhi3 = 0.;
8073   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
8074   {
8075    cosP1nPsi1P1nPhi2MPhi3 = (p1n0kRe*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
8076                           - 1.*(q2n0kRe*dReQ1n+q2n0kIm*dImQ1n)  
8077                           - mq*dReQ1n+2.*q1n0kRe)
8078                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
8079    // fill profile for <<sin n(psi1+phi2)>>:
8080    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
8081    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
8082    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3);
8083   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
8084   
8085   // <<cos n(psi1-phi2-phi3)>>:
8086   Double_t cosP1nPsi1M1nPhi2MPhi3 = 0.;
8087   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
8088   {
8089    cosP1nPsi1M1nPhi2MPhi3 = (p1n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))+2.*p1n0kIm*dReQ1n*dImQ1n
8090                           - 1.*(p1n0kRe*dReQ2n+p1n0kIm*dImQ2n)  
8091                           - 2.*mq*dReQ1n+2.*q1n0kRe)
8092                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
8093    // fill profile for <<sin n(psi1+phi2)>>:
8094    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
8095    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
8096    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3);
8097   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
8098  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8099  
8100 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
8101
8102
8103 //==================================================================================================================================
8104
8105
8106 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
8107 {
8108  // Transfer prolfiles into histogams and correctly propagate the error (to be improved: description)
8109  
8110  // to be improved: debugged - I do not correctly transfer all profiles into histos (bug appears only after merging) 
8111   
8112  Int_t t = -1; // type flag 
8113  Int_t pe = -1; // ptEta flag
8114  
8115  if(type == "RP")
8116  {
8117   t = 0;
8118  } else if(type == "POI")
8119    {
8120     t = 1;
8121    }
8122
8123  if(ptOrEta == "Pt")
8124  {
8125   pe = 0;
8126  } else if(ptOrEta == "Eta")
8127    {
8128     pe = 1;
8129    }
8130     
8131  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8132  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
8133  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
8134  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
8135
8136  for(Int_t sc=0;sc<2;sc++) // sin or cos
8137  {
8138   for(Int_t cti=0;cti<9;cti++) // correction term index
8139   {
8140    for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8141    {
8142     Double_t correctionTerm = fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(b);
8143     fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]->SetBinContent(b,correctionTerm);
8144     // to be improved (propagate error correctly)
8145     // ...
8146    } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8147   } // correction term index
8148  } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
8149
8150 }// end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
8151
8152
8153 //==================================================================================================================================
8154
8155
8156 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
8157
8158  // Calculate generalized differential flow Q-cumulants (corrected for non-uniform acceptance)
8159   
8160  Int_t typeFlag = -1;
8161  Int_t ptEtaFlag = -1;
8162
8163  if(type == "RP")
8164  {
8165   typeFlag = 0;
8166  } else if(type == "POI")
8167    {
8168     typeFlag = 1;
8169    } 
8170      
8171  if(ptOrEta == "Pt")
8172  {
8173   ptEtaFlag = 0;
8174  } else if(ptOrEta == "Eta")
8175    {
8176     ptEtaFlag = 1;
8177    } 
8178   
8179  // shortcuts:
8180  Int_t t = typeFlag;
8181  Int_t pe = ptEtaFlag;
8182      
8183  // common:
8184  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8185  
8186  // 2-particle correlation:
8187  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
8188  // sin term coming from integrated flow: 
8189  Double_t sinP1nPhi = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
8190  Double_t sinP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
8191  Double_t sinP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
8192  // cos term coming from integrated flow: 
8193  Double_t cosP1nPhi = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
8194  Double_t cosP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
8195  Double_t cosP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
8196
8197  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8198  {
8199   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
8200   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
8201   Double_t sinP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][0]->GetBinContent(b); // <<sin n(Psi)>> 
8202   Double_t cosP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][0]->GetBinContent(b); // <<cos n(Psi)>> 
8203   Double_t sinP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][1]->GetBinContent(b); // <<sin n(psi1+phi2)>> 
8204   Double_t cosP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][1]->GetBinContent(b); // <<cos n(psi1+phi2)>> 
8205   Double_t sinP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][2]->GetBinContent(b); // <<sin n(psi1+phi2-phi3)>> 
8206   Double_t cosP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][2]->GetBinContent(b); // <<cos n(psi1+phi2-phi3)>> 
8207   Double_t sinP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][3]->GetBinContent(b); // <<sin n(psi1-phi2-phi3)>> 
8208   Double_t cosP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][3]->GetBinContent(b); // <<cos n(psi1-phi2-phi3)>> 
8209   // generalized QC{2'}:
8210   Double_t qc2Prime = twoPrime - sinP1nPsi*sinP1nPhi - cosP1nPsi*cosP1nPhi;
8211   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime);
8212   // generalized QC{4'}:
8213   Double_t qc4Prime = fourPrime-2.*twoPrime*two
8214                     - cosP1nPsi*cosP1nPhi1M1nPhi2M1nPhi3
8215                     + sinP1nPsi*sinP1nPhi1M1nPhi2M1nPhi3
8216                     - cosP1nPhi*cosP1nPsi1M1nPhi2M1nPhi3
8217                     + sinP1nPhi*sinP1nPsi1M1nPhi2M1nPhi3
8218                     - 2.*cosP1nPhi*cosP1nPsi1P1nPhi2M1nPhi3
8219                     - 2.*sinP1nPhi*sinP1nPsi1P1nPhi2M1nPhi3
8220                     - cosP1nPsi1P1nPhi2*cosP1nPhi1P1nPhi2
8221                     - sinP1nPsi1P1nPhi2*sinP1nPhi1P1nPhi2
8222                     + 2.*cosP1nPhi1P1nPhi2*(cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
8223                     + 2.*sinP1nPhi1P1nPhi2*(cosP1nPsi*sinP1nPhi+sinP1nPsi*cosP1nPhi)
8224                     + 4.*two*(cosP1nPsi*cosP1nPhi+sinP1nPsi*sinP1nPhi)
8225                     + 2.*cosP1nPsi1P1nPhi2*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.))
8226                     + 4.*sinP1nPsi1P1nPhi2*cosP1nPhi*sinP1nPhi
8227                     + 4.*twoPrime*(pow(cosP1nPhi,2.)+pow(sinP1nPhi,2.))
8228                     - 6.*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.)) 
8229                     * (cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
8230                     - 12.*cosP1nPhi*sinP1nPhi
8231                     * (sinP1nPsi*cosP1nPhi+cosP1nPsi*sinP1nPhi);
8232   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime);   
8233  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
8234  
8235 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
8236
8237
8238 //==================================================================================================================================
8239     
8240
8241 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
8242 {
8243  // Calculate differential flow corrected for non-uniform acceptance.
8244  
8245  // to be improved (rewritten completely)
8246  
8247  Int_t typeFlag = -1;
8248  Int_t ptEtaFlag = -1;
8249
8250  if(type == "RP")
8251  {
8252   typeFlag = 0;
8253  } else if(type == "POI")
8254    {
8255     typeFlag = 1;
8256    } 
8257      
8258  if(ptOrEta == "Pt")
8259  {
8260   ptEtaFlag = 0;
8261  } else if(ptOrEta == "Eta")
8262    {
8263     ptEtaFlag = 1;
8264    } 
8265   
8266  // shortcuts:
8267  Int_t t = typeFlag;
8268  Int_t pe = ptEtaFlag;
8269      
8270  // common:
8271  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8272    
8273  // to be improved: access here generalized QC{2} and QC{4} instead: 
8274  Double_t dV2 = fIntFlow->GetBinContent(1); 
8275  Double_t dV4 = fIntFlow->GetBinContent(2); 
8276  
8277  // loop over pt or eta bins:
8278  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8279  {
8280   // generalized QC{2'}:
8281   Double_t gQC2Prime = fDiffFlowCumulants[t][pe][0]->GetBinContent(b);
8282   // v'{2}:
8283   if(dV2>0)
8284   { 
8285    Double_t v2Prime = gQC2Prime/dV2;
8286    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
8287   }  
8288   // generalized QC{4'}:
8289   Double_t gQC4Prime = fDiffFlowCumulants[t][pe][1]->GetBinContent(b);
8290   // v'{4}:
8291   if(dV4>0)
8292   { 
8293    Double_t v4Prime = -gQC4Prime/pow(dV4,3.);
8294    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime); 
8295   }  
8296  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
8297   
8298 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta); 
8299
8300
8301 //==================================================================================================================================
8302
8303
8304 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent)
8305 {
8306  // Evaluate with nested loops multiparticle correlations for integrated flow (without using the particle weights). 
8307
8308  // Remark: Results are stored in profile fIntFlowDirectCorrelations whose binning is organized as follows:
8309  // 
8310  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
8311  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
8312  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
8313  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
8314  //  5th bin:           ----  EMPTY ----
8315  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
8316  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
8317  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
8318  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
8319  // 10th bin:           ----  EMPTY ----
8320  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
8321  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
8322  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
8323  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
8324  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
8325  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
8326  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
8327  // 18th bin:           ----  EMPTY ----
8328  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
8329  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
8330  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
8331  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
8332  // 23rd bin:           ----  EMPTY ----
8333  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
8334  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
8335  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
8336  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
8337  // 28th bin:           ----  EMPTY ----
8338  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
8339  // 30th bin:           ----  EMPTY ----
8340  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
8341  
8342  Int_t nPrim = anEvent->NumberOfTracks(); 
8343  AliFlowTrackSimple *aftsTrack = NULL; 
8344  Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.; 
8345  Int_t n = fHarmonic; 
8346  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
8347  Double_t dMult = (*fSMpk)(0,0);
8348  cout<<endl;
8349  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
8350  if(dMult<2)
8351  {
8352   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
8353  } else if (dMult>fMaxAllowedMultiplicity)
8354    {
8355     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
8356    } else 
8357      { 
8358       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
8359      } 
8360  
8361  // 2-particle correlations:       
8362  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
8363  {
8364   for(Int_t i1=0;i1<nPrim;i1++)
8365   {
8366    aftsTrack=anEvent->GetTrack(i1);
8367    if(!(aftsTrack->InRPSelection())) continue;
8368    phi1=aftsTrack->Phi(); 
8369    for(Int_t i2=0;i2<nPrim;i2++)
8370    {
8371     if(i2==i1)continue;
8372     aftsTrack=anEvent->GetTrack(i2);
8373     if(!(aftsTrack->InRPSelection())) continue;
8374     phi2=aftsTrack->Phi();
8375     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
8376     // fill the profile with 2-p correlations: 
8377     fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),1.);    // <cos(n*(phi1-phi2))>
8378     fIntFlowDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),1.); // <cos(2n*(phi1-phi2))>
8379     fIntFlowDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),1.); // <cos(3n*(phi1-phi2))>
8380     fIntFlowDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),1.); // <cos(4n*(phi1-phi2))>   
8381    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8382   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8383  } // end of if(nPrim>=2)
8384  
8385  // 3-particle correlations:         
8386  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
8387  {
8388   for(Int_t i1=0;i1<nPrim;i1++)
8389   {
8390    aftsTrack=anEvent->GetTrack(i1);
8391    if(!(aftsTrack->InRPSelection())) continue;
8392    phi1=aftsTrack->Phi();
8393    for(Int_t i2=0;i2<nPrim;i2++)
8394    {
8395     if(i2==i1)continue;
8396     aftsTrack=anEvent->GetTrack(i2);
8397     if(!(aftsTrack->InRPSelection())) continue;
8398     phi2=aftsTrack->Phi();
8399     for(Int_t i3=0;i3<nPrim;i3++)
8400     {
8401      if(i3==i1||i3==i2)continue;
8402      aftsTrack=anEvent->GetTrack(i3);
8403      if(!(aftsTrack->InRPSelection())) continue;
8404      phi3=aftsTrack->Phi();
8405      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
8406      // fill the profile with 3-p correlations:   
8407      fIntFlowDirectCorrelations->Fill(5.,cos(2.*n*phi1-n*(phi2+phi3)),1.);       //<3>_{2n|nn,n}
8408      fIntFlowDirectCorrelations->Fill(6.,cos(3.*n*phi1-2.*n*phi2-n*phi3),1.);    //<3>_{3n|2n,n}
8409      fIntFlowDirectCorrelations->Fill(7.,cos(4.*n*phi1-2.*n*phi2-2.*n*phi3),1.); //<3>_{4n|2n,2n}
8410      fIntFlowDirectCorrelations->Fill(8.,cos(4.*n*phi1-3.*n*phi2-n*phi3),1.);    //<3>_{4n|3n,n}
8411     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8412    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8413   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8414  } // end of if(nPrim>=3)
8415
8416  // 4-particle correlations:
8417  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
8418  {       
8419   for(Int_t i1=0;i1<nPrim;i1++)
8420   { 
8421    aftsTrack=anEvent->GetTrack(i1);
8422    if(!(aftsTrack->InRPSelection())) continue;
8423    phi1=aftsTrack->Phi();
8424    for(Int_t i2=0;i2<nPrim;i2++)
8425    {
8426     if(i2==i1)continue;
8427     aftsTrack=anEvent->GetTrack(i2);
8428     if(!(aftsTrack->InRPSelection())) continue;
8429     phi2=aftsTrack->Phi();
8430     for(Int_t i3=0;i3<nPrim;i3++)
8431     {
8432      if(i3==i1||i3==i2)continue;
8433      aftsTrack=anEvent->GetTrack(i3);
8434      if(!(aftsTrack->InRPSelection())) continue;
8435      phi3=aftsTrack->Phi();
8436      for(Int_t i4=0;i4<nPrim;i4++)
8437      {
8438       if(i4==i1||i4==i2||i4==i3)continue;
8439       aftsTrack=anEvent->GetTrack(i4);
8440       if(!(aftsTrack->InRPSelection())) continue;
8441       phi4=aftsTrack->Phi();
8442       if(nPrim==4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush;
8443       // fill the profile with 4-p correlations:   
8444       fIntFlowDirectCorrelations->Fill(10.,cos(n*phi1+n*phi2-n*phi3-n*phi4),1.);            // <4>_{n,n|n,n} 
8445       fIntFlowDirectCorrelations->Fill(11.,cos(2.*n*phi1+n*phi2-2.*n*phi3-n*phi4),1.);      // <4>_{2n,n|2n,n}
8446       fIntFlowDirectCorrelations->Fill(12.,cos(2.*n*phi1+2*n*phi2-2.*n*phi3-2.*n*phi4),1.); // <4>_{2n,2n|2n,2n}
8447       fIntFlowDirectCorrelations->Fill(13.,cos(3.*n*phi1-n*phi2-n*phi3-n*phi4),1.);         // <4>_{3n|n,n,n}
8448       fIntFlowDirectCorrelations->Fill(14.,cos(3.*n*phi1+n*phi2-3.*n*phi3-n*phi4),1.);      // <4>_{3n,n|3n,n}   
8449       fIntFlowDirectCorrelations->Fill(15.,cos(3.*n*phi1+n*phi2-2.*n*phi3-2.*n*phi4),1.);   // <4>_{3n,n|2n,2n}
8450       fIntFlowDirectCorrelations->Fill(16.,cos(4.*n*phi1-2.*n*phi2-n*phi3-n*phi4),1.);      // <4>_{4n|2n,n,n}     
8451      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
8452     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8453    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8454   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8455  } // end of if(nPrim>=)
8456
8457  // 5-particle correlations:      
8458  if(nPrim>=5 && nPrim<=fMaxAllowedMultiplicity)
8459  {
8460   for(Int_t i1=0;i1<nPrim;i1++)
8461   {
8462    aftsTrack=anEvent->GetTrack(i1);
8463    if(!(aftsTrack->InRPSelection())) continue;  
8464    phi1=aftsTrack->Phi();
8465    for(Int_t i2=0;i2<nPrim;i2++)
8466    {
8467     if(i2==i1)continue;
8468     aftsTrack=anEvent->GetTrack(i2);
8469     if(!(aftsTrack->InRPSelection())) continue;
8470     phi2=aftsTrack->Phi();
8471     for(Int_t i3=0;i3<nPrim;i3++)
8472     {
8473      if(i3==i1||i3==i2)continue;
8474      aftsTrack=anEvent->GetTrack(i3);
8475      if(!(aftsTrack->InRPSelection())) continue;
8476      phi3=aftsTrack->Phi();
8477      for(Int_t i4=0;i4<nPrim;i4++)
8478      {
8479       if(i4==i1||i4==i2||i4==i3)continue;
8480       aftsTrack=anEvent->GetTrack(i4);
8481       if(!(aftsTrack->InRPSelection())) continue;
8482       phi4=aftsTrack->Phi();
8483       for(Int_t i5=0;i5<nPrim;i5++)
8484       {
8485        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
8486        aftsTrack=anEvent->GetTrack(i5);
8487        if(!(aftsTrack->InRPSelection())) continue;
8488        phi5=aftsTrack->Phi();
8489        if(nPrim==5) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<"\r"<<flush;
8490        // fill the profile with 5-p correlations:   
8491        fIntFlowDirectCorrelations->Fill(18.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{2n,n|n,n,n}
8492        fIntFlowDirectCorrelations->Fill(19.,cos(2.*n*phi1+2.*n*phi2-2.*n*phi3-n*phi4-n*phi5),1.); //<5>_{2n,2n|2n,n,n}
8493        fIntFlowDirectCorrelations->Fill(20.,cos(3.*n*phi1+n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);    //<5>_{3n,n|2n,n,n}
8494        fIntFlowDirectCorrelations->Fill(21.,cos(4.*n*phi1-n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{4n|n,n,n,n}
8495       } // end of for(Int_t i5=0;i5<nPrim;i5++)
8496      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
8497     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8498    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8499   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8500  } // end of if(nPrim>=5)
8501   
8502  // 6-particle correlations:
8503  if(nPrim>=6 && nPrim<=fMaxAllowedMultiplicity)
8504  {
8505   for(Int_t i1=0;i1<nPrim;i1++)
8506   {
8507    aftsTrack=anEvent->GetTrack(i1);
8508    if(!(aftsTrack->InRPSelection())) continue;
8509    phi1=aftsTrack->Phi();
8510    for(Int_t i2=0;i2<nPrim;i2++)
8511    {
8512     if(i2==i1)continue;
8513     aftsTrack=anEvent->GetTrack(i2);
8514     if(!(aftsTrack->InRPSelection())) continue;
8515     phi2=aftsTrack->Phi();
8516     for(Int_t i3=0;i3<nPrim;i3++)
8517     {
8518      if(i3==i1||i3==i2)continue;
8519      aftsTrack=anEvent->GetTrack(i3);
8520      if(!(aftsTrack->InRPSelection())) continue;
8521      phi3=aftsTrack->Phi();
8522      for(Int_t i4=0;i4<nPrim;i4++)
8523      {
8524       if(i4==i1||i4==i2||i4==i3)continue;
8525       aftsTrack=anEvent->GetTrack(i4);
8526       if(!(aftsTrack->InRPSelection())) continue;
8527       phi4=aftsTrack->Phi();
8528       for(Int_t i5=0;i5<nPrim;i5++)
8529       {
8530        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
8531        aftsTrack=anEvent->GetTrack(i5);
8532        if(!(aftsTrack->InRPSelection())) continue;
8533        phi5=aftsTrack->Phi();
8534        for(Int_t i6=0;i6<nPrim;i6++)
8535        {
8536         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
8537         aftsTrack=anEvent->GetTrack(i6);
8538         if(!(aftsTrack->InRPSelection())) continue;
8539         phi6=aftsTrack->Phi(); 
8540         if(nPrim==6) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<"\r"<<flush;
8541         // fill the profile with 6-p correlations:   
8542         fIntFlowDirectCorrelations->Fill(23.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),1.);       //<6>_{n,n,n|n,n,n}
8543         fIntFlowDirectCorrelations->Fill(24.,cos(2.*n*phi1+n*phi2+n*phi3-2.*n*phi4-n*phi5-n*phi6),1.); //<6>_{2n,n,n|2n,n,n}
8544         fIntFlowDirectCorrelations->Fill(25.,cos(2.*n*phi1+2.*n*phi2-n*phi3-n*phi4-n*phi5-n*phi6),1.); //<6>_{2n,2n|n,n,n,n}
8545         fIntFlowDirectCorrelations->Fill(26.,cos(3.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5-n*phi6),1.);    //<6>_{3n,n|n,n,n,n}  
8546        } // end of for(Int_t i6=0;i6<nPrim;i6++)
8547       } // end of for(Int_t i5=0;i5<nPrim;i5++)
8548      } // end of for(Int_t i4=0;i4<nPrim;i4++)
8549     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8550    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8551   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8552  } // end of if(nPrim>=6)
8553   
8554  // 7-particle correlations:
8555  if(nPrim>=7 && nPrim<=fMaxAllowedMultiplicity)
8556  {
8557   for(Int_t i1=0;i1<nPrim;i1++)
8558   { 
8559    aftsTrack=anEvent->GetTrack(i1);
8560    if(!(aftsTrack->InRPSelection())) continue;
8561    phi1=aftsTrack->Phi();
8562    for(Int_t i2=0;i2<nPrim;i2++)
8563    {
8564     if(i2==i1)continue;
8565     aftsTrack=anEvent->GetTrack(i2);
8566     if(!(aftsTrack->InRPSelection())) continue;
8567     phi2=aftsTrack->Phi();
8568     for(Int_t i3=0;i3<nPrim;i3++)
8569     {
8570      if(i3==i1||i3==i2)continue;
8571      aftsTrack=anEvent->GetTrack(i3);
8572      if(!(aftsTrack->InRPSelection())) continue;
8573      phi3=aftsTrack->Phi();
8574      for(Int_t i4=0;i4<nPrim;i4++)
8575      {
8576       if(i4==i1||i4==i2||i4==i3)continue;
8577       aftsTrack=anEvent->GetTrack(i4);
8578       if(!(aftsTrack->InRPSelection())) continue;
8579       phi4=aftsTrack->Phi();
8580       for(Int_t i5=0;i5<nPrim;i5++)
8581       {
8582        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
8583        aftsTrack=anEvent->GetTrack(i5);
8584        if(!(aftsTrack->InRPSelection())) continue;
8585        phi5=aftsTrack->Phi();
8586        for(Int_t i6=0;i6<nPrim;i6++)
8587        {
8588         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
8589         aftsTrack=anEvent->GetTrack(i6);
8590         if(!(aftsTrack->InRPSelection())) continue;
8591         phi6=aftsTrack->Phi(); 
8592         for(Int_t i7=0;i7<nPrim;i7++)
8593         {
8594          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
8595          aftsTrack=anEvent->GetTrack(i7);
8596          if(!(aftsTrack->InRPSelection())) continue;
8597          phi7=aftsTrack->Phi(); 
8598          if(nPrim==7) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<"\r"<<flush;
8599          // fill the profile with 7-p correlation:   
8600          fIntFlowDirectCorrelations->Fill(28.,cos(2.*n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6-n*phi7),1.); // <7>_{2n,n,n|n,n,n,n}
8601         } // end of for(Int_t i7=0;i7<nPrim;i7++)
8602        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
8603       } // end of for(Int_t i5=0;i5<nPrim;i5++)
8604      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
8605     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8606    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8607   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8608  } // end of if(nPrim>=7)
8609  
8610  // 8-particle correlations:
8611  if(nPrim>=8 && nPrim<=fMaxAllowedMultiplicity)
8612  {
8613   for(Int_t i1=0;i1<nPrim;i1++)
8614   {
8615    aftsTrack=anEvent->GetTrack(i1);
8616    if(!(aftsTrack->InRPSelection())) continue;
8617    phi1=aftsTrack->Phi();
8618    for(Int_t i2=0;i2<nPrim;i2++)
8619    {
8620     if(i2==i1)continue;
8621     aftsTrack=anEvent->GetTrack(i2);
8622     if(!(aftsTrack->InRPSelection())) continue;
8623     phi2=aftsTrack->Phi();
8624     for(Int_t i3=0;i3<nPrim;i3++)
8625     {
8626      if(i3==i1||i3==i2)continue;
8627      aftsTrack=anEvent->GetTrack(i3);
8628      if(!(aftsTrack->InRPSelection())) continue;
8629      phi3=aftsTrack->Phi();
8630      for(Int_t i4=0;i4<nPrim;i4++)
8631      {
8632       if(i4==i1||i4==i2||i4==i3)continue;
8633       aftsTrack=anEvent->GetTrack(i4);
8634       if(!(aftsTrack->InRPSelection())) continue;
8635       phi4=aftsTrack->Phi();
8636       for(Int_t i5=0;i5<nPrim;i5++)
8637       {
8638        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
8639        aftsTrack=anEvent->GetTrack(i5);
8640        if(!(aftsTrack->InRPSelection())) continue;
8641        phi5=aftsTrack->Phi();
8642        for(Int_t i6=0;i6<nPrim;i6++)
8643        {
8644         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
8645         aftsTrack=anEvent->GetTrack(i6);
8646         if(!(aftsTrack->InRPSelection())) continue;
8647         phi6=aftsTrack->Phi();
8648         for(Int_t i7=0;i7<nPrim;i7++)
8649         {
8650          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
8651          aftsTrack=anEvent->GetTrack(i7);
8652          if(!(aftsTrack->InRPSelection())) continue;
8653          phi7=aftsTrack->Phi();
8654          for(Int_t i8=0;i8<nPrim;i8++)
8655          {
8656           if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
8657           aftsTrack=anEvent->GetTrack(i8);
8658           if(!(aftsTrack->InRPSelection())) continue;
8659           phi8=aftsTrack->Phi();
8660           cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<" "<<i8<<"\r"<<flush;
8661           // fill the profile with 8-p correlation:   
8662           fIntFlowDirectCorrelations->Fill(30.,cos(n*phi1+n*phi2+n*phi3+n*phi4-n*phi5-n*phi6-n*phi7-n*phi8),1.); // <8>_{n,n,n,n|n,n,n,n}
8663          } // end of for(Int_t i8=0;i8<nPrim;i8++)
8664         } // end of for(Int_t i7=0;i7<nPrim;i7++) 
8665        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
8666       } // end of for(Int_t i5=0;i5<nPrim;i5++)
8667      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
8668     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8669    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8670   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8671  } // end of if(nPrim>=8)
8672  
8673  cout<<endl;
8674
8675 } // end of AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent)
8676
8677
8678 //==================================================================================================================================
8679
8680
8681 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
8682 {
8683  // Cross-check results for multiparticle correlations needed for int. flow: results from Q-vectors vs results from nested loops.
8684
8685  cout<<endl;
8686  cout<<endl;
8687  cout<<"   *****************************************"<<endl;
8688  cout<<"   **** cross-checking the correlations ****"<<endl;
8689  cout<<"   ****       for integrated flow       ****"<<endl;
8690  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
8691  {
8692   cout<<"   ****   (particle weights not used)   ****"<<endl;
8693  } else
8694    {
8695     cout<<"   ****     (particle weights used)     ****"<<endl;
8696    } 
8697  cout<<"   *****************************************"<<endl;
8698  cout<<endl;
8699  cout<<endl;
8700
8701  Int_t ciMax = 32; // to be improved (removed eventually when I calculate 6th and 8th order with particle weights)
8702  
8703  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
8704  {
8705   ciMax = 11;
8706  }
8707
8708  for(Int_t ci=1;ci<=ciMax;ci++)
8709  {
8710   if(strcmp((fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
8711   cout<<(fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
8712   cout<<"from Q-vectors    = "<<fIntFlowCorrelationsAllPro->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
8713   cout<<"from nested loops = "<<fIntFlowDirectCorrelations->GetBinContent(ci)<<endl;
8714   cout<<endl;
8715  }
8716   
8717 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
8718
8719
8720 //================================================================================================================================
8721
8722
8723 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA()
8724 {
8725  // Cross-check results for corrections terms for non-uniform acceptance needed for int. flow: results from Q-vectors vs results from nested loops.
8726
8727  cout<<endl;
8728  cout<<endl;
8729  cout<<"   *********************************************"<<endl;
8730  cout<<"   **** cross-checking the correction terms ****"<<endl;
8731  cout<<"   **** for non-uniform acceptance relevant ****"<<endl;
8732  cout<<"   ****         for integrated flow         ****"<<endl;
8733  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
8734  {
8735   cout<<"   ****     (particle weights not used)     ****"<<endl;
8736  } else
8737    {
8738     cout<<"   ****       (particle weights used)       ****"<<endl;
8739    } 
8740  cout<<"   *********************************************"<<endl;
8741  cout<<endl;
8742  cout<<endl;
8743
8744  for(Int_t ci=1;ci<=10;ci++) // correction term index
8745  {
8746   for(Int_t sc=0;sc<2;sc++) // sin or cos term
8747   {
8748    if(strcmp((fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
8749    cout<<(fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
8750    cout<<"from Q-vectors    = "<<fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
8751    cout<<"from nested loops = "<<fIntFlowDirectCorrectionTermsForNUA[sc]->GetBinContent(ci)<<endl;
8752    cout<<endl;
8753   } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos term
8754  } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
8755   
8756 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA() 
8757
8758
8759 //================================================================================================================================
8760
8761
8762 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
8763 {
8764  // Evaluate with nested loops multiparticle correlations for integrated flow (using the particle weights). 
8765
8766  // Results are stored in profile fIntFlowDirectCorrelations. 
8767  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrelations is organized as follows:
8768  //
8769  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
8770  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
8771  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
8772  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
8773  //  5th bin:           ----  EMPTY ----
8774  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
8775  //  7th bin: <3>_{3n|2n,1n} = ...
8776  //  8th bin: <3>_{4n|2n,2n} = ...
8777  //  9th bin: <3>_{4n|3n,1n} = ...
8778  // 10th bin:           ----  EMPTY ----
8779  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
8780  // 12th bin: <4>_{2n,1n|2n,1n} = ...
8781  // 13th bin: <4>_{2n,2n|2n,2n} = ...
8782  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
8783  // 15th bin: <4>_{3n,1n|3n,1n} = ...
8784  // 16th bin: <4>_{3n,1n|2n,2n} = ...
8785  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
8786  // 18th bin:           ----  EMPTY ----
8787  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
8788  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
8789  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
8790  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
8791  // 23rd bin:           ----  EMPTY ----
8792  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
8793  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
8794  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
8795  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
8796  // 28th bin:           ----  EMPTY ----
8797  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
8798  // 30th bin:           ----  EMPTY ----
8799  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
8800  
8801  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
8802  // fIntFlowExtraDirectCorrelations binning of which is organized as follows:
8803  
8804  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
8805  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
8806  // ...
8807  
8808  Int_t nPrim = anEvent->NumberOfTracks(); 
8809  AliFlowTrackSimple *aftsTrack = NULL;
8810  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
8811  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
8812  Double_t phi1=0., phi2=0., phi3=0., phi4=0.;
8813  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1.;
8814  Int_t n = fHarmonic; 
8815  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
8816  Double_t dMult = (*fSMpk)(0,0);
8817  cout<<endl;
8818  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
8819  if(dMult<2)
8820  {
8821   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
8822  } else if (dMult>fMaxAllowedMultiplicity)
8823    {
8824     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
8825    } else 
8826      { 
8827       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
8828      } 
8829       
8830  // 2-particle correlations:       
8831  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
8832  {
8833   // 2 nested loops multiparticle correlations using particle weights:       
8834   for(Int_t i1=0;i1<nPrim;i1++)
8835   {
8836    aftsTrack=anEvent->GetTrack(i1);
8837    if(!(aftsTrack->InRPSelection())) continue;
8838    phi1=aftsTrack->Phi();
8839    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
8840    for(Int_t i2=0;i2<nPrim;i2++)
8841    {
8842     if(i2==i1)continue;
8843     aftsTrack=anEvent->GetTrack(i2);
8844     if(!(aftsTrack->InRPSelection())) continue;
8845     phi2=aftsTrack->Phi();
8846     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
8847     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
8848     // 2-p correlations using particle weights:
8849     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),wPhi1*wPhi2);                  // <w1   w2   cos( n*(phi1-phi2))>
8850     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),pow(wPhi1,2)*pow(wPhi2,2)); // <w1^2 w2^2 cos(2n*(phi1-phi2))>
8851     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),pow(wPhi1,3)*pow(wPhi2,3)); // <w1^3 w2^3 cos(3n*(phi1-phi2))>
8852     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),pow(wPhi1,4)*pow(wPhi2,4)); // <w1^4 w2^4 cos(4n*(phi1-phi2))> 
8853     // extra correlations: 
8854     // 2-p extra correlations (do not appear if particle weights are not used):
8855     if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),pow(wPhi1,3)*wPhi2); // <w1^3 w2 cos(n*(phi1-phi2))>
8856     // ...
8857    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8858   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8859  } // end of if(nPrim>=2)
8860
8861  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
8862  { 
8863   // 3 nested loops multiparticle correlations using particle weights:       
8864   for(Int_t i1=0;i1<nPrim;i1++)
8865   {
8866    aftsTrack=anEvent->GetTrack(i1);
8867    if(!(aftsTrack->InRPSelection())) continue;
8868    phi1=aftsTrack->Phi();
8869    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
8870    for(Int_t i2=0;i2<nPrim;i2++)
8871    {
8872     if(i2==i1)continue;
8873     aftsTrack=anEvent->GetTrack(i2);
8874     if(!(aftsTrack->InRPSelection())) continue;
8875     phi2=aftsTrack->Phi();
8876     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
8877     for(Int_t i3=0;i3<nPrim;i3++)
8878     {
8879      if(i3==i1||i3==i2)continue;
8880      aftsTrack=anEvent->GetTrack(i3);
8881      if(!(aftsTrack->InRPSelection())) continue;
8882      phi3=aftsTrack->Phi();
8883      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
8884      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
8885      // 3-p correlations using particle weights:
8886      if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(5.5,cos(2.*n*phi1-n*(phi2+phi3)),pow(wPhi1,2)*wPhi2*wPhi3); // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
8887      // ...
8888      // extra correlations: 
8889      // 2-p extra correlations (do not appear if particle weights are not used):
8890       if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(1.5,cos(n*(phi1-phi2)),wPhi1*wPhi2*pow(wPhi3,2)); // <w1 w2 w3^2 cos(n*(phi1-phi2))>
8891      // ...
8892      // 3-p extra correlations (do not appear if particle weights are not used):
8893      // ...
8894     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8895    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8896   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8897  } // end of if(nPrim>=3)
8898  
8899  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
8900  {
8901   // 4 nested loops multiparticle correlations using particle weights:       
8902   for(Int_t i1=0;i1<nPrim;i1++)
8903   {
8904    aftsTrack=anEvent->GetTrack(i1);
8905    if(!(aftsTrack->InRPSelection())) continue;
8906    phi1=aftsTrack->Phi();
8907    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
8908    for(Int_t i2=0;i2<nPrim;i2++)
8909    {
8910     if(i2==i1)continue;
8911     aftsTrack=anEvent->GetTrack(i2);
8912     if(!(aftsTrack->InRPSelection())) continue;
8913     phi2=aftsTrack->Phi();
8914     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
8915     for(Int_t i3=0;i3<nPrim;i3++)
8916     {
8917      if(i3==i1||i3==i2)continue;
8918      aftsTrack=anEvent->GetTrack(i3);
8919      if(!(aftsTrack->InRPSelection())) continue;
8920      phi3=aftsTrack->Phi();
8921      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
8922      for(Int_t i4=0;i4<nPrim;i4++)
8923      {
8924       if(i4==i1||i4==i2||i4==i3)continue;
8925       aftsTrack=anEvent->GetTrack(i4);
8926       if(!(aftsTrack->InRPSelection())) continue;
8927       phi4=aftsTrack->Phi();
8928       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
8929       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
8930       // 4-p correlations using particle weights:
8931       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
8932       // extra correlations: 
8933       // 2-p extra correlations (do not appear if particle weights are not used):
8934       // ...
8935       // 3-p extra correlations (do not appear if particle weights are not used):
8936       // ...
8937       // 4-p extra correlations (do not appear if particle weights are not used):
8938       // ...
8939      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
8940     } // end of for(Int_t i3=0;i3<nPrim;i3++)
8941    } // end of for(Int_t i2=0;i2<nPrim;i2++)
8942   } // end of for(Int_t i1=0;i1<nPrim;i1++)
8943  } // end of if(nPrim>=4)
8944
8945  cout<<endl; 
8946
8947 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
8948
8949
8950 //================================================================================================================================
8951
8952
8953 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
8954 {
8955  // Cross-check results for extra multiparticle correlations needed for int. flow 
8956  // which appear only when particle weights are used: results from Q-vectors vs results from nested loops.
8957
8958  cout<<endl;
8959  cout<<endl;
8960  cout<<"   ***********************************************"<<endl;
8961  cout<<"   **** cross-checking the extra correlations ****"<<endl;
8962  cout<<"   ****          for integrated flow          ****"<<endl;
8963  cout<<"   ***********************************************"<<endl;
8964  cout<<endl;
8965  cout<<endl;
8966  
8967  for(Int_t eci=1;eci<=2;eci++) // to be improved (increased eciMax eventually when I calculate 6th and 8th)
8968  {
8969   if(strcmp((fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci), "") == 0) continue;
8970   cout<<(fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci)<<":"<<endl;
8971   cout<<"from Q-vectors    = "<<fIntFlowExtraCorrelationsPro->GetBinContent(eci)<<endl;
8972   cout<<"from nested loops = "<<fIntFlowExtraDirectCorrelations->GetBinContent(eci)<<endl;
8973   cout<<endl;
8974  }
8975
8976 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
8977
8978
8979 //================================================================================================================================
8980
8981
8982 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoops(AliFlowEventSimple* anEvent)
8983 {
8984  // Evaluate with nested loops correction terms for non-uniform acceptance relevant for NONAME integrated flow (to be improved (name)).
8985  //
8986  // Remark: Both sin and cos correction terms are calculated in this method. Sin terms are stored in fIntFlowDirectCorrectionTermsForNUA[0],
8987  // and cos terms in fIntFlowDirectCorrectionTermsForNUA[1]. Binning of fIntFlowDirectCorrectionTermsForNUA[sc] is organized as follows 
8988  // (sc stands for either sin or cos):
8989  
8990  //  1st bin: <<sc(n*(phi1))>> 
8991  //  2nd bin: <<sc(n*(phi1+phi2))>> 
8992  //  3rd bin: <<sc(n*(phi1-phi2-phi3))>>
8993  //  4th bin: <<sc(n*(2phi1-phi2))>>
8994  
8995  Int_t nPrim = anEvent->NumberOfTracks(); 
8996  AliFlowTrackSimple *aftsTrack = NULL;
8997  Double_t phi1=0., phi2=0., phi3=0.;
8998  Int_t n = fHarmonic; 
8999  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
9000  Double_t dMult = (*fSMpk)(0,0);
9001  cout<<endl;
9002  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
9003  if(dMult<1)
9004  {
9005   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
9006  } else if (dMult>fMaxAllowedMultiplicity)
9007    {
9008     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
9009    } else 
9010      { 
9011       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
9012      }
9013  
9014  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
9015  {
9016   // 1-particle correction terms for non-uniform acceptance:       
9017   for(Int_t i1=0;i1<nPrim;i1++)
9018   {
9019    aftsTrack=anEvent->GetTrack(i1);
9020    if(!(aftsTrack->InRPSelection())) continue;
9021    phi1=aftsTrack->Phi();
9022    if(nPrim==1) cout<<i1<<"\r"<<flush;
9023    // sin terms:
9024    fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),1.); // <sin(n*phi1)>  
9025    // cos terms:
9026    fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),1.); // <cos(n*phi1)>
9027   } // end of for(Int_t i1=0;i1<nPrim;i1++)
9028  } // end of if(nPrim>=1) 
9029   
9030  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
9031  {
9032   // 2-particle correction terms for non-uniform acceptance:       
9033   for(Int_t i1=0;i1<nPrim;i1++)
9034   {
9035    aftsTrack=anEvent->GetTrack(i1);
9036    if(!(aftsTrack->InRPSelection())) continue;
9037    phi1=aftsTrack->Phi();  
9038    for(Int_t i2=0;i2<nPrim;i2++)
9039    {
9040     if(i2==i1)continue;
9041     aftsTrack=anEvent->GetTrack(i2);
9042     if(!(aftsTrack->InRPSelection())) continue;
9043     phi2=aftsTrack->Phi();
9044     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
9045     // sin terms:
9046     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),1.); // <<sin(n*(phi1+phi2))>>
9047     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(3.5,sin(n*(2*phi1-phi2)),1.); // <<sin(n*(2*phi1-phi2))>>
9048     // cos terms:
9049     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),1.); // <<cos(n*(phi1+phi2))>>
9050     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(3.5,cos(n*(2*phi1-phi2)),1.); // <<cos(n*(2*phi1-phi2))>>
9051    } // end of for(Int_t i2=0;i2<nPrim;i2++)
9052   } // end of for(Int_t i1=0;i1<nPrim;i1++)
9053  } // end of if(nPrim>=2)
9054
9055  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
9056  {
9057   // 3-particle correction terms for non-uniform acceptance:       
9058   for(Int_t i1=0;i1<nPrim;i1++)
9059   {
9060    aftsTrack=anEvent->GetTrack(i1);
9061    if(!(aftsTrack->InRPSelection())) continue;
9062    phi1=aftsTrack->Phi();
9063    for(Int_t i2=0;i2<nPrim;i2++)
9064    {
9065     if(i2==i1)continue;
9066     aftsTrack=anEvent->GetTrack(i2);
9067     if(!(aftsTrack->InRPSelection())) continue;
9068     phi2=aftsTrack->Phi();
9069     for(Int_t i3=0;i3<nPrim;i3++)
9070     {
9071      if(i3==i1||i3==i2)continue;
9072      aftsTrack=anEvent->GetTrack(i3);
9073      if(!(aftsTrack->InRPSelection())) continue;
9074      phi3=aftsTrack->Phi();
9075      if(nPrim>=3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush; // to be improved (eventually I will change this if statement)
9076      // sin terms:
9077      fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),1.); // <<sin(n*(phi1-phi2-phi3))>>
9078      // cos terms:
9079      fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),1.); // <<cos(n*(phi1-phi2-phi3))>>
9080     } // end of for(Int_t i3=0;i3<nPrim;i3++)
9081    } // end of for(Int_t i2=0;i2<nPrim;i2++)
9082   } // end of for(Int_t i1=0;i1<nPrim;i1++)
9083  } // end of if(nPrim>=3)
9084
9085  cout<<endl;
9086 }
9087 //================================================================================================================================
9088 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
9089 {
9090  // Evaluate reduced correlations with nested loops without using the particle weights.
9091  
9092  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
9093  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
9094  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
9095  // Remark 3: <2'> = <cos(n*(psi1-phi2))>
9096  //           <4'> = <cos(n*(psi1+phi2-phi3-phi4))>
9097  // ...
9098  
9099  Int_t typeFlag = -1;
9100  Int_t ptEtaFlag = -1;
9101  if(type == "RP")
9102  {
9103   typeFlag = 0;
9104  } else if(type == "POI")
9105    {
9106     typeFlag = 1;
9107    }      
9108  if(ptOrEta == "Pt")
9109  {
9110   ptEtaFlag = 0;
9111  } else if(ptOrEta == "Eta")
9112    {
9113     ptEtaFlag = 1;
9114    } 
9115  // shortcuts:
9116  Int_t t = typeFlag;
9117  Int_t pe = ptEtaFlag;
9118       
9119  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
9120  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
9121  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9122  
9123  Int_t nPrim = anEvent->NumberOfTracks(); 
9124  AliFlowTrackSimple *aftsTrack = NULL;
9125  
9126  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
9127  
9128  Int_t n = fHarmonic; 
9129   
9130  // 2'-particle correlations:
9131  for(Int_t i1=0;i1<nPrim;i1++)
9132  {
9133   aftsTrack=anEvent->GetTrack(i1);
9134   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9135   if(typeFlag==1) // this is diff flow of POIs 
9136   {
9137    if(ptOrEta == "Pt")
9138    { 
9139     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9140    } else if (ptOrEta == "Eta")
9141      {
9142       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9143      }
9144   } else // this is diff flow of RPs 
9145     {
9146      if(ptOrEta == "Pt")
9147      { 
9148       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9149      } else if (ptOrEta == "Eta")
9150        {
9151         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9152        }
9153     }
9154        
9155   psi1=aftsTrack->Phi(); 
9156   for(Int_t i2=0;i2<nPrim;i2++)
9157   {
9158    if(i2==i1)continue;
9159    aftsTrack=anEvent->GetTrack(i2);
9160    // RP condition (!(first) particle in the correlator must be RP):
9161    if(!(aftsTrack->InRPSelection()))continue;
9162    phi2=aftsTrack->Phi();   
9163    // 2'-particle correlations: 
9164    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),1.); // <cos(n*(psi1-phi2))  
9165   }//end of for(Int_t i2=0;i2<nPrim;i2++)
9166  }//end of for(Int_t i1=0;i1<nPrim;i1++)
9167  
9168  /*
9169  
9170  // 3'-particle correlations:
9171  for(Int_t i1=0;i1<nPrim;i1++)
9172  {
9173   aftsTrack=anEvent->GetTrack(i1);
9174   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9175   if(ptOrEta == "Pt")
9176   { 
9177    if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9178   } else if (ptOrEta == "Eta")
9179     {
9180      if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9181     }
9182   psi1=aftsTrack->Phi();
9183   for(Int_t i2=0;i2<nPrim;i2++)
9184   {
9185    if(i2==i1)continue;
9186    aftsTrack=anEvent->GetTrack(i2);
9187    // RP condition (!(first) particle in the correlator must be RP):
9188    if(!(aftsTrack->InRPSelection())) continue;
9189    phi2=aftsTrack->Phi();
9190    for(Int_t i3=0;i3<nPrim;i3++)
9191    {
9192     if(i3==i1||i3==i2)continue;
9193     aftsTrack=anEvent->GetTrack(i3);
9194     // RP condition (!(first) particle in the correlator must be RP):
9195     if(!(aftsTrack->InRPSelection())) continue;
9196     phi3=aftsTrack->Phi();
9197     // to be improved : where to store it? ->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(2.*phi1-phi2-phi3)),1.); // <w1 w2 w3 cos(n(2psi1-phi2-phi3))> 
9198    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
9199   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
9200  }//end of for(Int_t i1=0;i1<nPrim;i1++)
9201  
9202  */
9203  
9204  // 4'-particle correlations:
9205  for(Int_t i1=0;i1<nPrim;i1++)
9206  {
9207   aftsTrack=anEvent->GetTrack(i1);
9208   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9209   if(typeFlag==1) // this is diff flow of POIs 
9210   {
9211    if(ptOrEta == "Pt")
9212    { 
9213     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9214    } else if (ptOrEta == "Eta")
9215      {
9216       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9217      }
9218   } else // this is diff flow of RPs 
9219     {
9220      if(ptOrEta == "Pt")
9221      { 
9222       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9223      } else if (ptOrEta == "Eta")
9224        {
9225         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9226        }
9227     }
9228     
9229   psi1=aftsTrack->Phi();
9230   for(Int_t i2=0;i2<nPrim;i2++)
9231   {
9232    if(i2==i1) continue;
9233    aftsTrack=anEvent->GetTrack(i2);
9234    // RP condition (!(first) particle in the correlator must be RP): 
9235    if(!(aftsTrack->InRPSelection())) continue;
9236    phi2=aftsTrack->Phi();
9237    for(Int_t i3=0;i3<nPrim;i3++)
9238    { 
9239     if(i3==i1||i3==i2) continue;
9240     aftsTrack=anEvent->GetTrack(i3);
9241     // RP condition (!(first) particle in the correlator must be RP):
9242     if(!(aftsTrack->InRPSelection())) continue;
9243     phi3=aftsTrack->Phi();
9244     for(Int_t i4=0;i4<nPrim;i4++)
9245     {
9246      if(i4==i1||i4==i2||i4==i3) continue;
9247      aftsTrack=anEvent->GetTrack(i4);
9248      // RP condition (!(first) particle in the correlator must be RP):
9249      if(!(aftsTrack->InRPSelection())) continue;  
9250      phi4=aftsTrack->Phi();
9251      // 4'-particle correlations:
9252      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),1.); // <cos(n(psi1+phi2-phi3-phi4))>     
9253     }//end of for(Int_t i4=0;i4<nPrim;i4++)
9254    }//end of for(Int_t i3=0;i3<nPrim;i3++)
9255   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
9256  }//end of for(Int_t i1=0;i1<nPrim;i1++)
9257       
9258  // count # of RPs and POIs in selected pt and eta bins for cross-checkings:
9259  for(Int_t i=0;i<nPrim;i++)
9260  {
9261   aftsTrack=anEvent->GetTrack(i); 
9262   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9263   if(typeFlag==1) // this is diff flow of POIs 
9264   {
9265    if(ptOrEta == "Pt")
9266    { 
9267     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9268    } else if (ptOrEta == "Eta")
9269      {
9270       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9271      }
9272   } else // this is diff flow of RPs 
9273     {
9274      if(ptOrEta == "Pt")
9275      { 
9276       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9277      } else if (ptOrEta == "Eta")
9278        {
9279         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9280        }
9281     }
9282   if(t==1)t++; 
9283   fNoOfParticlesInBin->Fill(t+pe+0.5);  
9284  }
9285
9286 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
9287
9288
9289 //================================================================================================================================
9290
9291
9292 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
9293 {
9294  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
9295  
9296  Int_t typeFlag = -1;
9297  Int_t ptEtaFlag = -1;
9298  if(type == "RP")
9299  {
9300   typeFlag = 0;
9301  } else if(type == "POI")
9302    {
9303     typeFlag = 1;
9304    }      
9305  if(ptOrEta == "Pt")
9306  {
9307   ptEtaFlag = 0;
9308  } else if(ptOrEta == "Eta")
9309    {
9310     ptEtaFlag = 1;
9311    } 
9312  // shortcuts:
9313  Int_t t = typeFlag;
9314  Int_t pe = ptEtaFlag;
9315       
9316  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
9317  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
9318  TString reducedCorrelations[4] = {"<<cos(n(psi1-phi2))>>","<<cos(n(psi1+phi2-phi3-phi4))>>","",""}; // to be improved (access this from pro or hist)
9319  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
9320  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
9321  
9322  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
9323  
9324
9325  cout<<endl;
9326  cout<<"   *****************************************"<<endl;
9327  cout<<"   **** cross-checking the correlations ****"<<endl;
9328  cout<<"   ****   for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
9329  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
9330  {
9331   cout<<"   ****   (particle weights not used)   ****"<<endl;
9332  } else
9333    {
9334     cout<<"   ****    (particle weights used)      ****"<<endl;
9335    } 
9336  cout<<"   *****************************************"<<endl; 
9337  cout<<endl;
9338  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
9339  cout<<endl;
9340  
9341  for(Int_t rci=0;rci<2;rci++) // to be improved (calculate 6th and 8th order)
9342  {
9343   cout<<"      "<<reducedCorrelations[rci].Data()<<":"<<endl;
9344   cout<<"      from Q-vectors    = "<<fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
9345   cout<<"      from nested loops = "<<fDiffFlowDirectCorrelations[t][pe][rci]->GetBinContent(1)<<endl;
9346   cout<<endl;  
9347  } // end of for(Int_t rci=0;rci<4;rci++)
9348         
9349 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
9350
9351 //================================================================================================================================
9352
9353 void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
9354 {
9355  // Print on the screen number of RPs and POIs in selected pt and eta bin for cross checkings.
9356  
9357  cout<<endl;
9358  cout<<"Number of RPs in selected pt bin   = "<<fNoOfParticlesInBin->GetBinContent(1)<<endl;
9359  cout<<"Number of RPs in selected eta bin  = "<<fNoOfParticlesInBin->GetBinContent(2)<<endl;
9360  cout<<"Number of POIs in selected pt bin  = "<<fNoOfParticlesInBin->GetBinContent(3)<<endl;
9361  cout<<"Number of POIs in selected eta bin = "<<fNoOfParticlesInBin->GetBinContent(4)<<endl;
9362  
9363 } // end of void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
9364
9365 //================================================================================================================================
9366
9367 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
9368 {
9369  // Evaluate reduced correlations with nested loops without using the particle weights.
9370  
9371  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
9372  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
9373  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
9374  // Remark 3: <2'> = <w2 cos(n*(psi1-phi2))>
9375  //           <4'> = <w2 w3 w4 cos(n*(psi1+phi2-phi3-phi4))>
9376  // ...
9377   
9378  Int_t typeFlag = -1;
9379  Int_t ptEtaFlag = -1;
9380  if(type == "RP")
9381  {
9382   typeFlag = 0;
9383  } else if(type == "POI")
9384    {
9385     typeFlag = 1;
9386    }      
9387  if(ptOrEta == "Pt")
9388  {
9389   ptEtaFlag = 0;
9390  } else if(ptOrEta == "Eta")
9391    {
9392     ptEtaFlag = 1;
9393    } 
9394  // shortcuts:
9395  Int_t t = typeFlag;
9396  Int_t pe = ptEtaFlag;
9397       
9398  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
9399  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
9400  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9401  
9402  Int_t nPrim = anEvent->NumberOfTracks(); 
9403  AliFlowTrackSimple *aftsTrack = NULL;
9404  
9405  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
9406  Double_t wPhi2=1., wPhi3=1., wPhi4=1.;// wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
9407  
9408  Int_t n = fHarmonic; 
9409  
9410  // 2'-particle correlations:
9411  for(Int_t i1=0;i1<nPrim;i1++)
9412  {
9413   aftsTrack=anEvent->GetTrack(i1);
9414   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9415   if(typeFlag==1) // this is diff flow of POIs 
9416   {
9417    if(ptOrEta == "Pt")
9418    { 
9419     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9420    } else if (ptOrEta == "Eta")
9421      {
9422       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9423      }
9424   } else // this is diff flow of RPs 
9425     {
9426      if(ptOrEta == "Pt")
9427      { 
9428       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9429      } else if (ptOrEta == "Eta")
9430        {
9431         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9432        }
9433     }
9434   psi1=aftsTrack->Phi(); 
9435   for(Int_t i2=0;i2<nPrim;i2++)
9436   {
9437    if(i2==i1) continue;
9438    aftsTrack=anEvent->GetTrack(i2);
9439    // RP condition (!(first) particle in the correlator must be RP):
9440    if(!(aftsTrack->InRPSelection())) continue;
9441    phi2=aftsTrack->Phi();   
9442    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
9443    // 2'-particle correlations: 
9444    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),wPhi2); // <w2 cos(n*(psi1-phi2))  
9445   }//end of for(Int_t i2=0;i2<nPrim;i2++)
9446  }//end of for(Int_t i1=0;i1<nPrim;i1++)
9447  
9448  // 4'-particle correlations:
9449  for(Int_t i1=0;i1<nPrim;i1++)
9450  {
9451   aftsTrack=anEvent->GetTrack(i1);
9452   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9453   if(typeFlag==1) // this is diff flow of POIs 
9454   {
9455    if(ptOrEta == "Pt")
9456    { 
9457     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9458    } else if (ptOrEta == "Eta")
9459      {
9460       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9461      }
9462   } else // this is diff flow of RPs 
9463     {
9464      if(ptOrEta == "Pt")
9465      { 
9466       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9467      } else if (ptOrEta == "Eta")
9468        {
9469         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9470        }
9471     }
9472   psi1=aftsTrack->Phi();
9473   for(Int_t i2=0;i2<nPrim;i2++)
9474   {
9475    if(i2==i1) continue;
9476    aftsTrack=anEvent->GetTrack(i2);
9477    // RP condition (!(first) particle in the correlator must be RP): 
9478    if(!(aftsTrack->InRPSelection())) continue;
9479    phi2=aftsTrack->Phi();
9480    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
9481    for(Int_t i3=0;i3<nPrim;i3++)
9482    { 
9483     if(i3==i1||i3==i2) continue;
9484     aftsTrack=anEvent->GetTrack(i3);
9485     // RP condition (!(first) particle in the correlator must be RP):
9486     if(!(aftsTrack->InRPSelection())) continue;
9487     phi3=aftsTrack->Phi();
9488     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
9489     for(Int_t i4=0;i4<nPrim;i4++)
9490     {
9491      if(i4==i1||i4==i2||i4==i3) continue;
9492      aftsTrack=anEvent->GetTrack(i4);
9493      // RP condition (!(first) particle in the correlator must be RP):
9494      if(!(aftsTrack->InRPSelection())) continue;  
9495      phi4=aftsTrack->Phi();
9496      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
9497      // 4'-particle correlations <w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))>:
9498      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),wPhi2*wPhi3*wPhi4); 
9499     }//end of for(Int_t i4=0;i4<nPrim;i4++)
9500    }//end of for(Int_t i3=0;i3<nPrim;i3++)
9501   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
9502  }//end of for(Int_t i1=0;i1<nPrim;i1++)      
9503  
9504  // count # of RPs and POIs in selected pt and eta bins for cross-checkings: (to be improved - moved to dedicated method)
9505  for(Int_t i=0;i<nPrim;i++)
9506  {
9507   aftsTrack=anEvent->GetTrack(i); 
9508   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9509   if(typeFlag==1) // this is diff flow of POIs 
9510   {
9511    if(ptOrEta == "Pt")
9512    { 
9513     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9514    } else if (ptOrEta == "Eta")
9515      {
9516       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9517      }
9518   } else // this is diff flow of RPs 
9519     {
9520      if(ptOrEta == "Pt")
9521      { 
9522       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9523      } else if (ptOrEta == "Eta")
9524        {
9525         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9526        }
9527     }
9528   if(t==1)t++; 
9529   fNoOfParticlesInBin->Fill(t+pe+0.5);  
9530  }
9531  
9532 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
9533
9534
9535 //================================================================================================================================
9536
9537    
9538 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
9539 {
9540  // Evaluate with nested loops correction terms for non-uniform acceptance (both sin and cos terms) relevant for differential flow.
9541  
9542  // Remark 1: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
9543  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
9544  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
9545  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
9546  //  cti: 
9547  //    0: <<sc n(psi1)>>
9548  //    1: <<sc n(psi1+phi2)>> 
9549  //    2: <<sc n(psi1+phi2-phi3)>>
9550  //    3: <<sc n(psi1-phi2-phi3)>>
9551  //    4:
9552  //    5:
9553  //    6:
9554   
9555  Int_t typeFlag = -1;
9556  Int_t ptEtaFlag = -1;
9557  if(type == "RP")
9558  {
9559   typeFlag = 0;
9560  } else if(type == "POI")
9561    {
9562     typeFlag = 1;
9563    }      
9564  if(ptOrEta == "Pt")
9565  {
9566   ptEtaFlag = 0;
9567  } else if(ptOrEta == "Eta")
9568    {
9569     ptEtaFlag = 1;
9570    } 
9571  // shortcuts:
9572  Int_t t = typeFlag;
9573  Int_t pe = ptEtaFlag;
9574       
9575  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
9576  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
9577  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9578  
9579  Int_t nPrim = anEvent->NumberOfTracks(); 
9580  AliFlowTrackSimple *aftsTrack = NULL;
9581  
9582  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
9583  
9584  Int_t n = fHarmonic; 
9585  
9586  // 1-particle correction terms:
9587  for(Int_t i1=0;i1<nPrim;i1++)
9588  {
9589   aftsTrack=anEvent->GetTrack(i1);
9590   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9591   if(typeFlag==1) // this is diff flow of POIs 
9592   {
9593    if(ptOrEta == "Pt")
9594    { 
9595     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9596    } else if (ptOrEta == "Eta")
9597      {
9598       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9599      }
9600   } else // this is diff flow of RPs 
9601     {
9602      if(ptOrEta == "Pt")
9603      { 
9604       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9605      } else if (ptOrEta == "Eta")
9606        {
9607         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9608        }
9609     }
9610   psi1=aftsTrack->Phi(); 
9611   // sin terms: 
9612   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
9613   // cos terms: 
9614   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
9615  }//end of for(Int_t i1=0;i1<nPrim;i1++)
9616    
9617  // 2-particle correction terms:
9618  for(Int_t i1=0;i1<nPrim;i1++)
9619  {
9620   aftsTrack=anEvent->GetTrack(i1);
9621    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9622   if(typeFlag==1) // this is diff flow of POIs 
9623   {
9624    if(ptOrEta == "Pt")
9625    { 
9626     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9627    } else if (ptOrEta == "Eta")
9628      {
9629       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9630      }
9631   } else // this is diff flow of RPs 
9632     {
9633      if(ptOrEta == "Pt")
9634      { 
9635       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9636      } else if (ptOrEta == "Eta")
9637        {
9638         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9639        }
9640     }
9641   psi1=aftsTrack->Phi(); 
9642   for(Int_t i2=0;i2<nPrim;i2++)
9643   {
9644    if(i2==i1) continue;
9645    aftsTrack=anEvent->GetTrack(i2);
9646    // RP condition (!(first) particle in the correlator must be RP):
9647    if(!(aftsTrack->InRPSelection())) continue;
9648    phi2=aftsTrack->Phi();   
9649    // sin terms: 
9650    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),1.); // <<sin(n*(psi1+phi2))>>  
9651    // cos terms: 
9652    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),1.); // <<cos(n*(psi1+phi2))>>  
9653   }//end of for(Int_t i2=0;i2<nPrim;i2++)
9654  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
9655  
9656  // 3-particle correction terms:
9657  for(Int_t i1=0;i1<nPrim;i1++)
9658  {
9659   aftsTrack=anEvent->GetTrack(i1);
9660    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
9661   if(typeFlag==1) // this is diff flow of POIs 
9662   {
9663    if(ptOrEta == "Pt")
9664    { 
9665     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
9666    } else if (ptOrEta == "Eta")
9667      {
9668       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
9669      }
9670   } else // this is diff flow of RPs 
9671     {
9672      if(ptOrEta == "Pt")
9673      { 
9674       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
9675      } else if (ptOrEta == "Eta")
9676        {
9677         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
9678        }
9679     }
9680   psi1=aftsTrack->Phi();
9681   for(Int_t i2=0;i2<nPrim;i2++)
9682   {
9683    if(i2==i1) continue;
9684    aftsTrack=anEvent->GetTrack(i2);
9685    // RP condition (!(first) particle in the correlator must be RP):
9686    if(!(aftsTrack->InRPSelection())) continue;
9687    phi2=aftsTrack->Phi();
9688    for(Int_t i3=0;i3<nPrim;i3++)
9689    {
9690     if(i3==i1||i3==i2) continue;
9691     aftsTrack=anEvent->GetTrack(i3);
9692     // RP condition (!(first) particle in the correlator must be RP):
9693     if(!(aftsTrack->InRPSelection())) continue;
9694     phi3=aftsTrack->Phi();
9695     // sin terms: 
9696     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2-phi3)),1.); // <<sin(n*(psi1+phi2-phi3))>>  
9697     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1-phi2-phi3)),1.); // <<sin(n*(psi1-phi2-phi3))>>  
9698     // cos terms: 
9699     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3)),1.); // <<cos(n*(psi1+phi2-phi3))>>  
9700     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-phi2-phi3)),1.); // <<cos(n*(psi1-phi2-phi3))>>  
9701    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
9702   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
9703  }//end of for(Int_t i1=0;i1<nPrim;i1++)
9704    
9705 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
9706
9707
9708 //================================================================================================================================
9709
9710
9711 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
9712 {
9713  // Compare corrections temrs for non-uniform acceptance needed for diff. flow calculated with nested loops and those calculated from Q-vectors
9714  
9715  Int_t typeFlag = -1;
9716  Int_t ptEtaFlag = -1;
9717  if(type == "RP")
9718  {
9719   typeFlag = 0;
9720  } else if(type == "POI")
9721    {
9722     typeFlag = 1;
9723    }      
9724  if(ptOrEta == "Pt")
9725  {
9726   ptEtaFlag = 0;
9727  } else if(ptOrEta == "Eta")
9728    {
9729     ptEtaFlag = 1;
9730    } 
9731  // shortcuts:
9732  Int_t t = typeFlag;
9733  Int_t pe = ptEtaFlag;
9734       
9735  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
9736  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
9737  //TString sinCosFlag[2] = {"sin","cos"}; // to be improved (eventually promote to data member)
9738  TString reducedCorrectionSinTerms[4] = {"<<sin(n(psi1))>>","<<sin(n(psi1+phi2))>>","<<sin(n*(psi1+phi2-phi3))>>","<<sin(n*(psi1-phi2-phi3))>>"}; // to be improved (access this from pro or hist)
9739  TString reducedCorrectionCosTerms[4] = {"<<cos(n(psi1))>>","<<cos(n(psi1+phi2))>>","<<cos(n*(psi1+phi2-phi3))>>","<<cos(n*(psi1-phi2-phi3))>>"}; // to be improved (access this from pro or hist)
9740  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
9741  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
9742  
9743  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
9744  
9745  cout<<endl;
9746  cout<<"   ******************************************"<<endl;
9747  cout<<"   ****  cross-checking the correction   ****"<<endl;
9748  cout<<"   **** terms for non-uniform acceptance ****"<<endl; 
9749  cout<<"   ****    for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
9750  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
9751  {
9752   cout<<"   ****    (particle weights not used)   ****"<<endl;
9753  } else
9754    {
9755     cout<<"   ****     (particle weights used)      ****"<<endl;
9756    } 
9757  cout<<"   ******************************************"<<endl; 
9758  cout<<endl;
9759  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
9760  cout<<endl;
9761  
9762  for(Int_t cti=0;cti<4;cti++) // correction term index
9763  {
9764   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
9765   {
9766    if(sc==0) // to be improved (this can be implemented better)
9767    { 
9768     cout<<"      "<<reducedCorrectionSinTerms[cti].Data()<<":"<<endl;
9769    } else
9770      {
9771       cout<<"      "<<reducedCorrectionCosTerms[cti].Data()<<":"<<endl;     
9772      }
9773    cout<<"      from Q-vectors    = "<<fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
9774    cout<<"      from nested loops = "<<fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]->GetBinContent(1)<<endl;
9775    cout<<endl;  
9776   } 
9777  } // end of for(Int_t rci=0;rci<4;rci++)
9778
9779 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
9780
9781
9782 //================================================================================================================================
9783
9784
9785 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
9786 {
9787  // Calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (cos terms).
9788  
9789  //                                  **********************************************************************
9790  //                                  **** weighted corrections for non-uniform acceptance (cos terms): ****
9791  //                                  **********************************************************************
9792  
9793  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
9794  //
9795  // 1st bin: <<w1 cos(n*(phi1))>> = cosP1nW1
9796  // 2nd bin: <<w1 w2 cos(n*(phi1+phi2))>> = cosP1nP1nW1W1
9797  // 3rd bin: <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1nW1W1W1 
9798  // ...
9799
9800  // multiplicity (number of particles used to determine the reaction plane)
9801  Double_t dMult = (*fSMpk)(0,0);
9802  
9803  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9804  Double_t dReQ1n1k = (*fReQ)(0,1);
9805  Double_t dReQ2n2k = (*fReQ)(1,2);
9806  //Double_t dReQ3n3k = (*fReQ)(2,3);
9807  //Double_t dReQ4n4k = (*fReQ)(3,4);
9808  Double_t dReQ1n3k = (*fReQ)(0,3);
9809  Double_t dImQ1n1k = (*fImQ)(0,1);
9810  Double_t dImQ2n2k = (*fImQ)(1,2);
9811  //Double_t dImQ3n3k = (*fImQ)(2,3);
9812  //Double_t dImQ4n4k = (*fImQ)(3,4);
9813  //Double_t dImQ1n3k = (*fImQ)(0,3);
9814
9815  // dMs are variables introduced in order to simplify some Eqs. bellow:
9816  //..............................................................................................
9817  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
9818  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
9819                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
9820  //..............................................................................................
9821         \r // 1-particle:
9822  Double_t cosP1nW1 = 0.; // <<w1 cos(n*(phi1))>>
9823    
9824  if(dMult>0 && (*fSMpk)(0,1) !=0.)
9825  {
9826   cosP1nW1 = dReQ1n1k/(*fSMpk)(0,1); 
9827   
9828   // average weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
9829   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1nW1);
9830   
9831   // final average weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
9832   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1nW1,(*fSMpk)(0,1));  
9833  } 
9834  
9835  // 2-particle:
9836  Double_t cosP1nP1nW1W1 = 0.; // <<w1 w2 cos(n*(phi1+phi2))>>
9837  
9838  if(dMult>1 && dM11 !=0.)
9839  {
9840   cosP1nP1nW1W1 = (pow(dReQ1n1k,2)-pow(dImQ1n1k,2)-dReQ2n2k)/dM11; 
9841   
9842   // average weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
9843   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1nW1W1);
9844   
9845   // final average weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
9846   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1nW1W1,dM11);  
9847  } 
9848  
9849  // 3-particle:
9850  Double_t cosP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>>
9851  
9852  if(dMult>2 && dM111 !=0.)
9853  {
9854   cosP1nM1nM1nW1W1W1 = (dReQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
9855                      - dReQ1n1k*dReQ2n2k-dImQ1n1k*dImQ2n2k
9856                      - 2.*((*fSMpk)(0,2))*dReQ1n1k
9857                      + 2.*dReQ1n3k) 
9858                      / dM111; 
9859   
9860   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
9861   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1nW1W1W1);
9862   
9863   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
9864   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1nW1W1W1,dM111);  
9865  } 
9866  
9867 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
9868
9869
9870 //================================================================================================================================
9871
9872
9873 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
9874 {
9875  // calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
9876  
9877  //                                  **********************************************************************
9878  //                                  **** weighted corrections for non-uniform acceptance (sin terms): ****
9879  //                                  **********************************************************************
9880  
9881  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
9882  //
9883  // 1st bin: <<w1 sin(n*(phi1))>> = sinP1nW1
9884  // 2nd bin: <<w1 w2 sin(n*(phi1+phi2))>> = sinP1nP1nW1W1
9885  // 3rd bin: <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1nW1W1W1 
9886  // ...
9887
9888  // multiplicity (number of particles used to determine the reaction plane)
9889  Double_t dMult = (*fSMpk)(0,0);
9890  
9891  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9892  Double_t dReQ1n1k = (*fReQ)(0,1);
9893  Double_t dReQ2n2k = (*fReQ)(1,2);
9894  //Double_t dReQ3n3k = (*fReQ)(2,3);
9895  //Double_t dReQ4n4k = (*fReQ)(3,4);
9896  //Double_t dReQ1n3k = (*fReQ)(0,3);
9897  Double_t dImQ1n1k = (*fImQ)(0,1);
9898  Double_t dImQ2n2k = (*fImQ)(1,2);
9899  //Double_t dImQ3n3k = (*fImQ)(2,3);
9900  //Double_t dImQ4n4k = (*fImQ)(3,4);
9901  Double_t dImQ1n3k = (*fImQ)(0,3);
9902
9903  // dMs are variables introduced in order to simplify some Eqs. bellow:
9904  //..............................................................................................
9905  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
9906  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
9907                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
9908  //..............................................................................................
9909  
9910  // 1-particle:
9911  Double_t sinP1nW1 = 0.; // <<w1 sin(n*(phi1))>>
9912  
9913  if(dMult>0 && (*fSMpk)(0,1) !=0.)
9914  {
9915   sinP1nW1 = dImQ1n1k/((*fSMpk)(0,1)); 
9916      
9917   // average weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
9918   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1nW1);
9919   
9920   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
9921   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1nW1,(*fSMpk)(0,1));  
9922  } 
9923  
9924  // 2-particle:
9925  Double_t sinP1nP1nW1W1 = 0.; // <<w1 w2 sin(n*(phi1+phi2))>>
9926  
9927  if(dMult>1 && dM11 !=0.)
9928  {
9929   sinP1nP1nW1W1 = (2.*dReQ1n1k*dImQ1n1k-dImQ2n2k)/dM11; 
9930      
9931   // average weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
9932   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1nW1W1);
9933   
9934   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
9935   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1nW1W1,dM11);  
9936  } 
9937  
9938  // 3-particle:
9939  Double_t sinP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>>
9940  
9941  if(dMult>2 && dM111 !=0.)
9942  {
9943   sinP1nM1nM1nW1W1W1 = (-dImQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
9944                      + dReQ1n1k*dImQ2n2k-dImQ1n1k*dReQ2n2k
9945                      + 2.*((*fSMpk)(0,2))*dImQ1n1k
9946                      - 2.*dImQ1n3k)
9947                      / dM111; 
9948   
9949   // average weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
9950   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1nW1W1W1);
9951   
9952   // final average weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
9953   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1nW1W1W1,dM111);  
9954  } 
9955  
9956 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
9957
9958
9959 //================================================================================================================================
9960
9961
9962 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
9963 {
9964  // Evaluate with nested loops correction terms for non-uniform acceptance for integrated flow (using the particle weights). 
9965
9966  // Results are stored in profiles fIntFlowDirectCorrectionTermsForNUA[0] (sin terms) and
9967  // fIntFlowDirectCorrectionTermsForNUA[1] (cos terms). 
9968  
9969  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrectionTermsForNUA[sc] is 
9970  // organized as follows (sc stands for either sin or cos):
9971  //
9972  // 1st bin: <<w1 sc(n*(phi1))>> = scP1nW1
9973  // 2nd bin: <<w1 w2 sc(n*(phi1+phi2))>> = scP1nP1nW1W1
9974  // 3rd bin: <<w1 w2 w3 sc(n*(phi1-phi2-phi3))>> = scP1nM1nM1nW1W1W1 
9975  // ...
9976   
9977  Int_t nPrim = anEvent->NumberOfTracks(); 
9978  AliFlowTrackSimple *aftsTrack = NULL;
9979  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
9980  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
9981  Double_t phi1=0., phi2=0., phi3=0.;
9982  Double_t wPhi1=1., wPhi2=1., wPhi3=1.;
9983  Int_t n = fHarmonic; 
9984  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
9985  Double_t dMult = (*fSMpk)(0,0);
9986  cout<<endl;
9987  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
9988  if(dMult<1)
9989  {
9990   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
9991  } else if (dMult>fMaxAllowedMultiplicity)
9992    {
9993     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
9994    } else 
9995      { 
9996       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
9997      } 
9998       
9999  // 1-particle correction terms using particle weights:       
10000  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
10001  {
10002   for(Int_t i1=0;i1<nPrim;i1++)
10003   {
10004    aftsTrack=anEvent->GetTrack(i1);
10005    if(!(aftsTrack->InRPSelection())) continue;
10006    phi1=aftsTrack->Phi();
10007    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10008    // 1-particle correction terms using particle weights:
10009    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),wPhi1); // <w1 sin(n*phi1)>
10010    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),wPhi1); // <w1 cos(n*phi1)>
10011   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10012  } // end of if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity) 
10013  
10014  // 2-particle correction terms using particle weights:       
10015  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10016  {
10017   for(Int_t i1=0;i1<nPrim;i1++)
10018   {
10019    aftsTrack=anEvent->GetTrack(i1);
10020    if(!(aftsTrack->InRPSelection())) continue;
10021    phi1=aftsTrack->Phi();
10022    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10023    for(Int_t i2=0;i2<nPrim;i2++)
10024    {
10025     if(i2==i1)continue;
10026     aftsTrack=anEvent->GetTrack(i2);
10027     if(!(aftsTrack->InRPSelection())) continue;
10028     phi2=aftsTrack->Phi();
10029     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
10030     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10031     // 2-p correction terms using particle weights:    
10032     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 sin(n*(phi1+phi2))>
10033     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 cos(n*(phi1+phi2))>
10034    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10035   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10036  } // end of if(nPrim>=2)
10037
10038  // 3-particle correction terms using particle weights:       
10039  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10040  { 
10041   for(Int_t i1=0;i1<nPrim;i1++)
10042   {
10043    aftsTrack=anEvent->GetTrack(i1);
10044    if(!(aftsTrack->InRPSelection())) continue;
10045    phi1=aftsTrack->Phi();
10046    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10047    for(Int_t i2=0;i2<nPrim;i2++)
10048    {
10049     if(i2==i1)continue;
10050     aftsTrack=anEvent->GetTrack(i2);
10051     if(!(aftsTrack->InRPSelection())) continue;
10052     phi2=aftsTrack->Phi();
10053     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
10054     for(Int_t i3=0;i3<nPrim;i3++)
10055     {
10056      if(i3==i1||i3==i2)continue;
10057      aftsTrack=anEvent->GetTrack(i3);
10058      if(!(aftsTrack->InRPSelection())) continue;
10059      phi3=aftsTrack->Phi();
10060      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
10061      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
10062      // 3-p correction terms using particle weights:    
10063      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 sin(n*(phi1-phi2-phi3))>
10064      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n*(phi1-phi2-phi3))>
10065     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10066    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10067   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10068  } // end of if(nPrim>=3)
10069  
10070  /*
10071  
10072  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
10073  {
10074   // 4 nested loops multiparticle correlations using particle weights:       
10075   for(Int_t i1=0;i1<nPrim;i1++)
10076   {
10077    aftsTrack=anEvent->GetTrack(i1);
10078    if(!(aftsTrack->InRPSelection())) continue;
10079    phi1=aftsTrack->Phi();
10080    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10081    for(Int_t i2=0;i2<nPrim;i2++)
10082    {
10083     if(i2==i1)continue;
10084     aftsTrack=anEvent->GetTrack(i2);
10085     if(!(aftsTrack->InRPSelection())) continue;
10086     phi2=aftsTrack->Phi();
10087     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
10088     for(Int_t i3=0;i3<nPrim;i3++)
10089     {
10090      if(i3==i1||i3==i2)continue;
10091      aftsTrack=anEvent->GetTrack(i3);
10092      if(!(aftsTrack->InRPSelection())) continue;
10093      phi3=aftsTrack->Phi();
10094      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
10095      for(Int_t i4=0;i4<nPrim;i4++)
10096      {
10097       if(i4==i1||i4==i2||i4==i3)continue;
10098       aftsTrack=anEvent->GetTrack(i4);
10099       if(!(aftsTrack->InRPSelection())) continue;
10100       phi4=aftsTrack->Phi();
10101       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
10102       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
10103       // 4-p correlations using particle weights:
10104       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
10105       // extra correlations: 
10106       // 2-p extra correlations (do not appear if particle weights are not used):
10107       // ...
10108       // 3-p extra correlations (do not appear if particle weights are not used):
10109       // ...
10110       // 4-p extra correlations (do not appear if particle weights are not used):
10111       // ...
10112      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
10113     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10114    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10115   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10116  } // end of if(nPrim>=4)
10117
10118  */
10119
10120  cout<<endl; 
10121
10122 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
10123
10124
10125 //================================================================================================================================
10126
10127
10128 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
10129 {
10130  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms) using particle weights.
10131  
10132  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
10133  //
10134  //  0: <<cos n(psi)>>
10135  //  1: <<w2 cos n(psi1+phi2)>>
10136  //  2: <<w2 w3 cos n(psi1+phi2-phi3)>>
10137  //  3: <<w2 w3 cos n(psi1-phi2-phi3)>>
10138  //  4:
10139  //  5:
10140  //  6:
10141  
10142  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10143  Double_t dReQ1n1k = (*fReQ)(0,1);
10144  Double_t dReQ2n2k = (*fReQ)(1,2);
10145  //Double_t dReQ1n3k = (*fReQ)(0,3);
10146  //Double_t dReQ4n4k = (*fReQ)(3,4);
10147  Double_t dImQ1n1k = (*fImQ)(0,1);
10148  Double_t dImQ2n2k = (*fImQ)(1,2);
10149  //Double_t dImQ1n3k = (*fImQ)(0,3);
10150  //Double_t dImQ4n4k = (*fImQ)(3,4);
10151  
10152  // S^M_{p,k} (see .h file for the definition of fSMpk):
10153  Double_t dSM1p1k = (*fSMpk)(0,1);
10154  Double_t dSM1p2k = (*fSMpk)(0,2);
10155  Double_t dSM2p1k = (*fSMpk)(1,1);
10156
10157  Int_t t = -1; // type flag 
10158  Int_t pe = -1; // ptEta flag
10159  
10160  if(type == "RP")
10161  {
10162   t = 0;
10163  } else if(type == "POI")
10164    {
10165     t = 1;
10166    }
10167
10168  if(ptOrEta == "Pt")
10169  {
10170   pe = 0;
10171  } else if(ptOrEta == "Eta")
10172    {
10173     pe = 1;
10174    }
10175     
10176  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10177  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10178  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10179  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10180  
10181  // looping over all bins and calculating correction terms: 
10182  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10183  {
10184   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
10185   Double_t p1n0kRe = 0.;
10186   Double_t p1n0kIm = 0.;
10187
10188   // number of POIs in particular pt or eta bin:
10189   Double_t mp = 0.;
10190
10191   // real and imaginary parts of q_{m*n,0} (weighted Q-vector evaluated for particles which are both RPs and POIs in particular pt or eta bin):
10192   Double_t q1n2kRe = 0.;
10193   Double_t q1n2kIm = 0.;
10194   Double_t q2n1kRe = 0.;
10195   Double_t q2n1kIm = 0.;
10196     
10197   // s_{1,1}, s_{1,2} // to be improved (add explanation)  
10198   Double_t s1p1k = 0.; 
10199   Double_t s1p2k = 0.; 
10200   
10201   // number of particles which are both RPs and POIs in particular pt or eta bin:
10202   Double_t mq = 0.;
10203   
10204   // M0111 from Eq. (118) in QC2c (to be improved (notation))
10205   Double_t dM01 = 0.;
10206   Double_t dM011 = 0.;
10207   
10208   if(type == "POI")
10209   {           
10210    // q_{m*n,k}:
10211    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
10212            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
10213    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
10214            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
10215    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
10216            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
10217    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
10218            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
10219    mq = fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10220    
10221    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
10222    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
10223   }else if(type == "RP")
10224    {
10225     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
10226     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
10227             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
10228     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
10229             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
10230     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
10231             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
10232     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
10233             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
10234     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10235     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
10236     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
10237     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.);  
10238     
10239     mq = fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
10240   }    
10241   
10242   if(type == "POI")
10243   {
10244    // p_{m*n,k}:   
10245    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10246            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10247    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10248            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10249    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
10250    // M01 from Eq. (118) in QC2c (to be improved (notation)):
10251    dM01 = mp*dSM1p1k-s1p1k;
10252    dM011 = mp*(dSM2p1k-dSM1p2k)
10253          - 2.*(s1p1k*dSM1p1k-s1p2k);
10254        
10255    // typeFlag = RP (0) or POI (1):   
10256    t = 1; 
10257   } else if(type == "RP")
10258     {  
10259      // to be improved (cross-checked):
10260      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10261              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10262      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
10263              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10264      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10265      // M01 from Eq. (118) in QC2c (to be improved (notation)):
10266      dM01 = mp*dSM1p1k-s1p1k;
10267      dM011 = mp*(dSM2p1k-dSM1p2k)
10268            - 2.*(s1p1k*dSM1p1k-s1p2k); 
10269      // typeFlag = RP (0) or POI (1): 
10270      t = 0;
10271     }
10272   
10273   // <<cos n(psi1)>>:
10274   Double_t cosP1nPsi = 0.;
10275   if(mp)
10276   {
10277    cosP1nPsi = p1n0kRe/mp;
10278    
10279    // fill profile for <<cos n(psi1)>>:
10280    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
10281    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
10282    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
10283   } // end of if(mp)   
10284   
10285   // <<w2 cos n(psi1+phi2)>>:
10286   Double_t cosP1nPsiP1nPhiW2 = 0.;
10287   if(dM01)
10288   {
10289    cosP1nPsiP1nPhiW2 = (p1n0kRe*dReQ1n1k-p1n0kIm*dImQ1n1k-q2n1kRe)/(dM01);
10290    // fill profile for <<w2 cos n(psi1+phi2)>>:
10291    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhiW2,dM01);
10292    // histogram to store <w2 cos n(psi1+phi2)> e-b-e (needed in some other methods):
10293    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhiW2);
10294   } // end of if(dM01)   
10295   
10296   // <<w2 w3 cos n(psi1+phi2-phi3)>>:
10297   Double_t cosP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
10298   if(dM011)
10299   {
10300    cosP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
10301                               - p1n0kRe*dSM1p2k
10302                               - q2n1kRe*dReQ1n1k-q2n1kIm*dImQ1n1k
10303                               - s1p1k*dReQ1n1k
10304                               + 2.*q1n2kRe)
10305                               / dM011;  
10306    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
10307    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3W2W3,dM011);
10308    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
10309    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3W2W3);
10310   } // end of if(dM011)   
10311   
10312   // <<w2 w3 cos n(psi1-phi2-phi3)>>:
10313   Double_t cosP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
10314   if(dM011)
10315   {
10316    cosP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))+2.*p1n0kIm*dReQ1n1k*dImQ1n1k
10317                               - 1.*(p1n0kRe*dReQ2n2k+p1n0kIm*dImQ2n2k)  
10318                               - 2.*s1p1k*dReQ1n1k
10319                               + 2.*q1n2kRe)
10320                               / dM011;
10321    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
10322    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3W2W3,dM011);
10323    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
10324    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3W2W3);
10325   } // end of if(dM011)   
10326  
10327  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10328    
10329 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
10330
10331
10332 //================================================================================================================================
10333
10334
10335 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
10336 {
10337  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
10338   
10339  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
10340  //  0: <<sin n(psi1)>>
10341  //  1: <<w2 sin n(psi1+phi2)>>
10342  //  2: <<w2 w3 sin n(psi1+phi2-phi3)>>
10343  //  3: <<w2 w3 sin n(psi1-phi2-phi3)>>:
10344  //  4:
10345  //  5:
10346  //  6:
10347  
10348  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10349  Double_t dReQ1n1k = (*fReQ)(0,1);
10350  Double_t dReQ2n2k = (*fReQ)(1,2);
10351  //Double_t dReQ1n3k = (*fReQ)(0,3);
10352  //Double_t dReQ4n4k = (*fReQ)(3,4);
10353  Double_t dImQ1n1k = (*fImQ)(0,1);
10354  Double_t dImQ2n2k = (*fImQ)(1,2);
10355  //Double_t dImQ1n3k = (*fImQ)(0,3);
10356  //Double_t dImQ4n4k = (*fImQ)(3,4);
10357  
10358  // S^M_{p,k} (see .h file for the definition of fSMpk):
10359  Double_t dSM1p1k = (*fSMpk)(0,1);
10360  Double_t dSM1p2k = (*fSMpk)(0,2);
10361  Double_t dSM2p1k = (*fSMpk)(1,1);
10362
10363  Int_t t = -1; // type flag 
10364  Int_t pe = -1; // ptEta flag
10365  
10366  if(type == "RP")
10367  {
10368   t = 0;
10369  } else if(type == "POI")
10370    {
10371     t = 1;
10372    }
10373
10374  if(ptOrEta == "Pt")
10375  {
10376   pe = 0;
10377  } else if(ptOrEta == "Eta")
10378    {
10379     pe = 1;
10380    }
10381     
10382  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10383  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10384  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10385  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10386
10387  // looping over all bins and calculating correction terms: 
10388  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10389  {
10390   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
10391   Double_t p1n0kRe = 0.;
10392   Double_t p1n0kIm = 0.;
10393
10394   // number of POIs in particular pt or eta bin:
10395   Double_t mp = 0.;
10396
10397   // real and imaginary parts of q_{m*n,0} (weighted Q-vector evaluated for particles which are both RPs and POIs in particular pt or eta bin):
10398   Double_t q1n2kRe = 0.;
10399   Double_t q1n2kIm = 0.;
10400   Double_t q2n1kRe = 0.;
10401   Double_t q2n1kIm = 0.;
10402     
10403   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10404   Double_t s1p1k = 0.; 
10405   Double_t s1p2k = 0.; 
10406   
10407   // number of particles which are both RPs and POIs in particular pt or eta bin:
10408   Double_t mq = 0.;
10409   
10410   // M0111 from Eq. (118) in QC2c (to be improved (notation))
10411   Double_t dM01 = 0.;
10412   Double_t dM011 = 0.;
10413
10414   if(type == "POI")
10415   {    
10416    // q_{m*n,k}:
10417    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
10418            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
10419    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
10420            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
10421    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
10422            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
10423    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
10424            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
10425    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10426    
10427    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
10428    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
10429   }else if(type == "RP")
10430    {
10431     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
10432     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
10433             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
10434     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
10435             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
10436     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
10437             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
10438     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
10439             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
10440     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10441     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
10442     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
10443     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
10444   }    
10445   
10446   if(type == "POI")
10447   {
10448    // p_{m*n,k}:   
10449    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10450            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10451    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10452            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10453    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
10454    // M01 from Eq. (118) in QC2c (to be improved (notation)):
10455    dM01 = mp*dSM1p1k-s1p1k;
10456    dM011 = mp*(dSM2p1k-dSM1p2k)
10457          - 2.*(s1p1k*dSM1p1k-s1p2k);  
10458    // typeFlag = RP (0) or POI (1):   
10459    t = 1;           
10460   } else if(type == "RP")
10461     { 
10462      // to be improved (cross-checked):
10463      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10464              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10465      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
10466              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10467      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)    
10468      // M01 from Eq. (118) in QC2c (to be improved (notation)):
10469      dM01 = mp*dSM1p1k-s1p1k;
10470      dM011 = mp*(dSM2p1k-dSM1p2k)
10471            - 2.*(s1p1k*dSM1p1k-s1p2k); 
10472      // typeFlag = RP (0) or POI (1): 
10473      t = 0;
10474     }
10475   
10476   // <<sin n(psi1)>>:
10477   Double_t sinP1nPsi = 0.;
10478   if(mp)
10479   {
10480    sinP1nPsi = p1n0kIm/mp;
10481    
10482    // fill profile for <<sin n(psi1)>>:
10483    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
10484    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
10485    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
10486   } // end of if(mp)   
10487   
10488   // <<w2 sin n(psi1+phi2)>>:
10489   Double_t sinP1nPsiP1nPhiW2 = 0.;
10490   if(dM01)
10491   {
10492    sinP1nPsiP1nPhiW2 = (p1n0kRe*dImQ1n1k+p1n0kIm*dReQ1n1k-q2n1kIm)/(dM01);
10493    // fill profile for <<w2 sin n(psi1+phi2)>>:
10494    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhiW2,dM01);
10495    // histogram to store <w2 sin n(psi1+phi2)> e-b-e (needed in some other methods):
10496    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhiW2);
10497   } // end of if(mp*dMult-mq)   
10498   
10499   // <<w2 w3 sin n(psi1+phi2-phi3)>>:
10500   Double_t sinP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
10501   if(dM011)
10502   {
10503    sinP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
10504                               - p1n0kIm*dSM1p2k
10505                               + q2n1kRe*dImQ1n1k-q2n1kIm*dReQ1n1k
10506                               - s1p1k*dImQ1n1k
10507                               + 2.*q1n2kIm)
10508                               / dM011;  
10509    // fill profile for <<w2 w3 sin n(psi1+phi2-phi3)>>:
10510    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3W2W3,dM011);
10511    // histogram to store <w2 w3 sin n(psi1+phi2-phi3)> e-b-e (needed in some other methods):
10512    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3W2W3);
10513   } // end of if(dM011)   
10514   
10515   // <<w2 w3 sin n(psi1-phi2-phi3)>>:
10516   Double_t sinP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
10517   if(dM011)
10518   {
10519    sinP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))-2.*p1n0kRe*dReQ1n1k*dImQ1n1k
10520                               + 1.*(p1n0kRe*dImQ2n2k-p1n0kIm*dReQ2n2k)  
10521                               + 2.*s1p1k*dImQ1n1k
10522                               - 2.*q1n2kIm)
10523                               / dM011;
10524    // fill profile for <<w2 w3 sin n(psi1-phi2-phi3)>>:
10525    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3W2W3,dM011);
10526    // histogram to store <w2 w3 sin n(psi1-phi2-phi3)> e-b-e (needed in some other methods):
10527    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3W2W3);
10528   } // end of if(dM011)   
10529   
10530  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10531
10532 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
10533
10534
10535 //================================================================================================================================
10536
10537    
10538 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
10539 {
10540  // Evaluate with nested loops correction terms for non-uniform acceptance 
10541  // with using particle weights (both sin and cos terms) relevant for differential flow.
10542  
10543  // Remark 1: "w1" in expressions bellow is a particle weight used only for particles which were 
10544  //           flagged both as POI and RP.
10545  // Remark 2: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
10546  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
10547  // Remark 3: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
10548  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
10549  //  cti: 
10550  //    0: <<sc n(psi1)>>
10551  //    1: <<w2 sc n(psi1+phi2)>> 
10552  //    2: <<w2 w3 sc n(psi1+phi2-phi3)>>
10553  //    3: <<w2 w3 sc n(psi1-phi2-phi3)>>
10554  //    4:
10555  //    5:
10556  //    6:
10557      
10558  Int_t typeFlag = -1;
10559  Int_t ptEtaFlag = -1;
10560  if(type == "RP")
10561  {
10562   typeFlag = 0;
10563  } else if(type == "POI")
10564    {
10565     typeFlag = 1;
10566    }      
10567  if(ptOrEta == "Pt")
10568  {
10569   ptEtaFlag = 0;
10570  } else if(ptOrEta == "Eta")
10571    {
10572     ptEtaFlag = 1;
10573    } 
10574  // shortcuts:
10575  Int_t t = typeFlag;
10576  Int_t pe = ptEtaFlag;
10577       
10578  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
10579  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
10580  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10581  
10582  Int_t nPrim = anEvent->NumberOfTracks(); 
10583  AliFlowTrackSimple *aftsTrack = NULL;
10584  
10585  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
10586  Double_t wPhi2=1., wPhi3=1.;
10587  
10588  Int_t n = fHarmonic; 
10589  
10590  // 1'-particle correction terms:
10591  for(Int_t i1=0;i1<nPrim;i1++)
10592  {
10593   aftsTrack=anEvent->GetTrack(i1);
10594   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
10595   if(typeFlag==1) // this is diff flow of POIs 
10596   {
10597    if(ptOrEta == "Pt")
10598    { 
10599     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
10600    } else if (ptOrEta == "Eta")
10601      {
10602       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
10603      }
10604   } else // this is diff flow of RPs 
10605     {
10606      if(ptOrEta == "Pt")
10607      { 
10608       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
10609      } else if (ptOrEta == "Eta")
10610        {
10611         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
10612        }
10613     }
10614   psi1=aftsTrack->Phi(); 
10615   // sin terms: 
10616   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
10617   // cos terms: 
10618   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
10619  }//end of for(Int_t i1=0;i1<nPrim;i1++)
10620    
10621  // 2'-particle correction terms:
10622  for(Int_t i1=0;i1<nPrim;i1++)
10623  {
10624   aftsTrack=anEvent->GetTrack(i1);
10625   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
10626   if(typeFlag==1) // this is diff flow of POIs 
10627   {
10628    if(ptOrEta == "Pt")
10629    { 
10630     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
10631    } else if (ptOrEta == "Eta")
10632      {
10633       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
10634      }
10635   } else // this is diff flow of RPs 
10636     {
10637      if(ptOrEta == "Pt")
10638      { 
10639       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
10640      } else if (ptOrEta == "Eta")
10641        {
10642         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
10643        }
10644     }
10645   psi1=aftsTrack->Phi(); 
10646   for(Int_t i2=0;i2<nPrim;i2++)
10647   {
10648    if(i2==i1) continue;
10649    aftsTrack=anEvent->GetTrack(i2);
10650    // RP condition (!(first) particle in the correlator must be RP):
10651    if(!(aftsTrack->InRPSelection())) continue;
10652    phi2=aftsTrack->Phi();
10653    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
10654    // sin terms: 
10655    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),wPhi2); // <<w2 sin(n*(psi1+phi2))>>  
10656    // cos terms: 
10657    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),wPhi2); // <<w2 cos(n*(psi1+phi2))>>  
10658   }//end of for(Int_t i2=0;i2<nPrim;i2++)
10659  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
10660  
10661  // 3'-particle correction terms:
10662  for(Int_t i1=0;i1<nPrim;i1++)
10663  {
10664   aftsTrack=anEvent->GetTrack(i1);
10665   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
10666   if(typeFlag==1) // this is diff flow of POIs 
10667   {
10668    if(ptOrEta == "Pt")
10669    { 
10670     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
10671    } else if (ptOrEta == "Eta")
10672      {
10673       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
10674      }
10675   } else // this is diff flow of RPs 
10676     {
10677      if(ptOrEta == "Pt")
10678      { 
10679       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
10680      } else if (ptOrEta == "Eta")
10681        {
10682         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
10683        }
10684     }
10685   psi1=aftsTrack->Phi();
10686   for(Int_t i2=0;i2<nPrim;i2++)
10687   {
10688    if(i2==i1) continue;
10689    aftsTrack=anEvent->GetTrack(i2);
10690    // RP condition (!(first) particle in the correlator must be RP):
10691    if(!(aftsTrack->InRPSelection())) continue;
10692    phi2=aftsTrack->Phi();
10693    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
10694    for(Int_t i3=0;i3<nPrim;i3++)
10695    {
10696     if(i3==i1||i3==i2) continue;
10697     aftsTrack=anEvent->GetTrack(i3);
10698     // RP condition (!(first) particle in the correlator must be RP):
10699     if(!(aftsTrack->InRPSelection())) continue;
10700     phi3=aftsTrack->Phi();
10701     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));   
10702     // sin terms: 
10703     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2-phi3)),wPhi2*wPhi3); // <<wPhi2*wPhi3 sin(n*(psi1+phi2-phi3))>>  
10704     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1-phi2-phi3)),wPhi2*wPhi3); // <<wPhi2*wPhi3 sin(n*(psi1-phi2-phi3))>>  
10705     // cos terms: 
10706     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3)),wPhi2*wPhi3); // <<wPhi2*wPhi3 cos(n*(psi1+phi2-phi3))>>  
10707     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-phi2-phi3)),wPhi2*wPhi3); // <<wPhi2*wPhi3 cos(n*(psi1-phi2-phi3))>>  
10708    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
10709   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
10710  }//end of for(Int_t i1=0;i1<nPrim;i1++)
10711                
10712 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
10713
10714
10715
10716
10717