]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx
9b7f042cb29174eafa095ca88d5065ca60f554b0
[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  *        (abilandzic@gmail.com)  *
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 ClassImp(AliFlowAnalysisWithQCumulants)
69
70 AliFlowAnalysisWithQCumulants::AliFlowAnalysisWithQCumulants(): 
71  // 0.) base:
72  fHistList(NULL),
73  // 1.) common:
74  fCommonHists(NULL),
75  fCommonHists2nd(NULL), 
76  fCommonHists4th(NULL),
77  fCommonHists6th(NULL),
78  fCommonHists8th(NULL),
79  fCommonHistsResults2nd(NULL),
80  fCommonHistsResults4th(NULL),
81  fCommonHistsResults6th(NULL),
82  fCommonHistsResults8th(NULL),
83  fnBinsPhi(0),
84  fPhiMin(0),
85  fPhiMax(0),
86  fPhiBinWidth(0),
87  fnBinsPt(0),
88  fPtMin(0),
89  fPtMax(0),
90  fPtBinWidth(0),
91  fnBinsEta(0),
92  fEtaMin(0),
93  fEtaMax(0),
94  fEtaBinWidth(0),
95  fFillMultipleControlHistograms(kFALSE),
96  fHarmonic(2),
97  fAnalysisLabel(NULL),
98  // 2a.) particle weights:
99  fWeightsList(NULL),
100  fUsePhiWeights(kFALSE),
101  fUsePtWeights(kFALSE),
102  fUseEtaWeights(kFALSE),
103  fUseParticleWeights(NULL),
104  fPhiWeights(NULL),
105  fPtWeights(NULL),
106  fEtaWeights(NULL),
107  // 2b.) event weights:
108  fMultiplicityWeight(NULL),
109  // 3.) integrated flow:
110  fIntFlowList(NULL), 
111  fIntFlowProfiles(NULL),
112  fIntFlowResults(NULL),
113  fIntFlowFlags(NULL),
114  fApplyCorrectionForNUA(kFALSE),  
115  fApplyCorrectionForNUAVsM(kFALSE),
116  fnBinsMult(10000),
117  fMinMult(0.),  
118  fMaxMult(10000.), 
119  fPropagateErrorAlsoFromNIT(kFALSE), 
120  fCalculateCumulantsVsM(kFALSE),
121  fMinimumBiasReferenceFlow(kTRUE), 
122  fForgetAboutCovariances(kFALSE), 
123  fStorePhiDistributionForOneEvent(kFALSE),
124  fReQ(NULL),
125  fImQ(NULL),
126  fSMpk(NULL),
127  fIntFlowCorrelationsEBE(NULL),
128  fIntFlowEventWeightsForCorrelationsEBE(NULL),
129  fIntFlowCorrelationsAllEBE(NULL),
130  fReferenceMultiplicityEBE(0.),  
131  fAvMultiplicity(NULL),
132  fIntFlowCorrelationsPro(NULL),
133  fIntFlowSquaredCorrelationsPro(NULL),
134  fIntFlowCorrelationsAllPro(NULL),
135  fIntFlowExtraCorrelationsPro(NULL),
136  fIntFlowProductOfCorrelationsPro(NULL),
137  fIntFlowProductOfCorrectionTermsForNUAPro(NULL),
138  fIntFlowCorrelationsHist(NULL),
139  fIntFlowCorrelationsAllHist(NULL),
140  fIntFlowCovariances(NULL),
141  fIntFlowSumOfProductOfEventWeights(NULL),
142  fIntFlowCovariancesNUA(NULL),
143  fIntFlowSumOfProductOfEventWeightsNUA(NULL),
144  fIntFlowQcumulants(NULL),
145  fIntFlowQcumulantsRebinnedInM(NULL), 
146  fIntFlowQcumulantsErrorSquaredRatio(NULL), 
147  fIntFlow(NULL),
148  fIntFlowRebinnedInM(NULL),
149  fIntFlowDetectorBias(NULL),
150  // 4.) differential flow:
151  fDiffFlowList(NULL),
152  fDiffFlowProfiles(NULL),
153  fDiffFlowResults(NULL),
154  fDiffFlowFlags(NULL),
155  fCalculate2DFlow(kFALSE),
156  // 5.) distributions:
157  fDistributionsList(NULL),
158  fDistributionsFlags(NULL),
159  fStoreDistributions(kFALSE),
160  // 6.) various:
161  fVariousList(NULL),
162  fPhiDistributionForOneEvent(NULL),
163  // x.) debugging and cross-checking:
164  fNestedLoopsList(NULL),
165  fEvaluateIntFlowNestedLoops(kFALSE),
166  fEvaluateDiffFlowNestedLoops(kFALSE),
167  fMaxAllowedMultiplicity(10),
168  fEvaluateNestedLoops(NULL),
169  fIntFlowDirectCorrelations(NULL),
170  fIntFlowExtraDirectCorrelations(NULL),
171  fCrossCheckInPtBinNo(10),
172  fCrossCheckInEtaBinNo(20),
173  fNoOfParticlesInBin(NULL)
174  {
175   // constructor  
176   
177   // base list to hold all output objects:
178   fHistList = new TList();
179   fHistList->SetName("cobjQC");
180   fHistList->SetOwner(kTRUE);
181   
182   // list to hold histograms with phi, pt and eta weights:      
183   fWeightsList = new TList();
184   
185   // multiplicity weight:
186   fMultiplicityWeight = new TString("combinations");
187     
188   // analysis label;
189   fAnalysisLabel = new TString();
190       
191   // initialize all arrays:  
192   this->InitializeArraysForIntFlow();
193   this->InitializeArraysForDiffFlow();
194   this->InitializeArraysForDistributions();
195   this->InitializeArraysForVarious();
196   this->InitializeArraysForNestedLoops();
197   
198  } // end of constructor
199  
200
201 //================================================================================================================  
202
203
204 AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
205 {
206  // destructor
207  
208  delete fHistList;
209
210 } // end of AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
211
212
213 //================================================================================================================
214
215
216 void AliFlowAnalysisWithQCumulants::Init()
217 {
218  // a) Cross check if the settings make sense before starting the QC adventure;
219  // b) Access all common constants;
220  // c) Book all objects;
221  // d) Store flags for integrated and differential flow;
222  // e) Store flags for distributions of corelations;
223  // f) Store harmonic which will be estimated.
224   
225  //save old value and prevent histograms from being added to directory
226  //to avoid name clashes in case multiple analaysis objects are used
227  //in an analysis
228  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
229  TH1::AddDirectory(kFALSE);
230  
231  // a) Cross check if the settings make sense before starting the QC adventure; 
232  this->CrossCheckSettings();
233  // b) Access all common constants:
234  this->AccessConstants();
235  // c) Book all objects:
236  this->BookAndFillWeightsHistograms();
237  this->BookAndNestAllLists();
238  this->BookCommonHistograms();
239  this->BookEverythingForIntegratedFlow(); 
240  this->BookEverythingForDifferentialFlow(); 
241  this->BookEverythingForDistributions();
242  this->BookEverythingForVarious();
243  this->BookEverythingForNestedLoops();
244  // d) Store flags for integrated and differential flow:
245  this->StoreIntFlowFlags();
246  this->StoreDiffFlowFlags();
247  // e) Store flags for distributions of corelations:
248  this->StoreFlagsForDistributions();
249  // f) Store harmonic which will be estimated:
250  this->StoreHarmonic();
251  
252  TH1::AddDirectory(oldHistAddStatus);
253 } // end of void AliFlowAnalysisWithQCumulants::Init()
254
255
256 //================================================================================================================
257
258
259 void AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
260 {
261  // Running over data only in this method.
262  
263  // a) Check all pointers used in this method;
264  // b) Define local variables;
265  // c) Fill the common control histograms and call the method to fill fAvMultiplicity;
266  // d) Loop over data and calculate e-b-e quantities;
267  // e) Call all the methods which calculate correlations for reference flow;
268  // f) Call all the methods which calculate correlations for differential flow;
269  // g) Distributions of correlations;
270  // h) Store phi distribution for one event to illustrate flow;
271  // i) Debugging and cross-checking (evaluate nested loops);
272  // j) Reset all event-by-event quantities. 
273  
274  // a) Check all pointers used in this method:
275  this->CheckPointersUsedInMake();
276  
277  // b) Define local variables:
278  Double_t dPhi = 0.; // azimuthal angle in the laboratory frame
279  Double_t dPt  = 0.; // transverse momentum
280  Double_t dEta = 0.; // pseudorapidity
281  Double_t wPhi = 1.; // phi weight
282  Double_t wPt  = 1.; // pt weight
283  Double_t wEta = 1.; // eta weight
284  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
285  fReferenceMultiplicityEBE = anEvent->GetReferenceMultiplicity(); // reference multiplicity for current event
286   
287  // c) Fill the common control histograms and call the method to fill fAvMultiplicity:
288  this->FillCommonControlHistograms(anEvent);                                                               
289  this->FillAverageMultiplicities(nRP);                                                                  
290                                                                                                                                                                                                                                                                                         
291  // d) Loop over data and calculate e-b-e quantities:
292  Int_t nPrim = anEvent->NumberOfTracks();  // nPrim = total number of primary tracks, i.e. nPrim = nRP + nPOI where:
293                                            // nRP   = # of particles used to determine the reaction plane;
294                                            // nPOI  = # of particles of interest for a detailed flow analysis;
295  
296  AliFlowTrackSimple *aftsTrack = NULL;
297  
298  for(Int_t i=0;i<nPrim;i++) 
299  { 
300   aftsTrack=anEvent->GetTrack(i);
301   if(aftsTrack)
302   {
303    if(!(aftsTrack->InRPSelection() || aftsTrack->InPOISelection())) continue; // consider only tracks which are RPs or POIs
304    Int_t n = fHarmonic; // shortcut for the harmonic
305    if(aftsTrack->InRPSelection()) // RP condition:
306    {    
307     dPhi = aftsTrack->Phi();
308     dPt  = aftsTrack->Pt();
309     dEta = aftsTrack->Eta();
310     if(fUsePhiWeights && fPhiWeights && fnBinsPhi) // determine phi weight for this particle:
311     {
312      wPhi = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*fnBinsPhi/TMath::TwoPi())));
313     }
314     if(fUsePtWeights && fPtWeights && fnBinsPt) // determine pt weight for this particle:
315     {
316      wPt = fPtWeights->GetBinContent(1+(Int_t)(TMath::Floor((dPt-fPtMin)/fPtBinWidth))); 
317     }              
318     if(fUseEtaWeights && fEtaWeights && fEtaBinWidth) // determine eta weight for this particle: 
319     {
320      wEta = fEtaWeights->GetBinContent(1+(Int_t)(TMath::Floor((dEta-fEtaMin)/fEtaBinWidth))); 
321     } 
322       
323     // integrated flow: 
324     // calculate Re[Q_{m*n,k}] and Im[Q_{m*n,k}], m = 1,2,3,4,5,6 for this event:
325     for(Int_t m=0;m<6;m++)
326     {
327      for(Int_t k=0;k<9;k++)
328      {
329       (*fReQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1)*n*dPhi); 
330       (*fImQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1)*n*dPhi); 
331      } 
332     }
333     // calculate S^{M}_{p,k} for this event 
334     // Remark: final calculation of S^{M}_{p,k} follows after the loop over data bellow:
335     for(Int_t p=0;p<8;p++)
336     {
337      for(Int_t k=0;k<9;k++)
338      {     
339       (*fSMpk)(p,k)+=pow(wPhi*wPt*wEta,k);
340      }
341     } 
342     
343     // differential flow:
344     // 1D (pt):
345     // (r_{m*m,k}(pt)): 
346     for(Int_t m=0;m<4;m++)
347     {
348      for(Int_t k=0;k<9;k++)
349      {
350       fReRPQ1dEBE[0][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
351       fImRPQ1dEBE[0][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
352      }
353     }
354            
355     // s_{k}(pt) for RPs // to be improved (clarified)
356     // Remark: final calculation of s_{p,k}(pt) follows after the loop over data bellow:
357     for(Int_t k=0;k<9;k++)
358     {
359      fs1dEBE[0][0][k]->Fill(dPt,pow(wPhi*wPt*wEta,k),1.);
360     }
361     // 1D (eta):
362     // (r_{m*m,k}(eta)): 
363     for(Int_t m=0;m<4;m++)
364     {
365      for(Int_t k=0;k<9;k++)
366      {
367       fReRPQ1dEBE[0][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
368       fImRPQ1dEBE[0][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
369      }
370     }   
371     // s_{k}(eta) for RPs // to be improved (clarified)
372     // Remark: final calculation of s_{p,k}(eta) follows after the loop over data bellow:
373     for(Int_t k=0;k<9;k++)
374     {
375      fs1dEBE[0][1][k]->Fill(dEta,pow(wPhi*wPt*wEta,k),1.);
376     }
377     // 2D (pt,eta):
378     if(fCalculate2DFlow)
379     {
380      // (r_{m*m,k}(pt,eta)): 
381      for(Int_t m=0;m<4;m++)
382      {
383       for(Int_t k=0;k<9;k++)
384       {
385        fReRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
386        fImRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
387       }
388      }    
389      // s_{k}(pt,eta) for RPs // to be improved (clarified)
390      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
391      for(Int_t k=0;k<9;k++)
392      {
393       fs2dEBE[0][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
394      }
395     } // end of if(fCalculate2DFlow)  
396      
397     if(aftsTrack->InPOISelection())
398     {
399      // 1D (pt): 
400      // (q_{m*m,k}(pt)): 
401      for(Int_t m=0;m<4;m++)
402      {
403       for(Int_t k=0;k<9;k++)
404       {
405        fReRPQ1dEBE[2][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
406        fImRPQ1dEBE[2][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
407       }
408      } 
409      // s_{k}(pt) for RP&&POIs // to be improved (clarified)
410      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
411      for(Int_t k=0;k<9;k++)
412      {
413       fs1dEBE[2][0][k]->Fill(dPt,pow(wPhi*wPt*wEta,k),1.);
414      }
415      // 1D (eta): 
416      // (q_{m*m,k}(eta)): 
417      for(Int_t m=0;m<4;m++)
418      {
419       for(Int_t k=0;k<9;k++)
420       {
421        fReRPQ1dEBE[2][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
422        fImRPQ1dEBE[2][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
423       }
424      } 
425      // s_{k}(eta) for RP&&POIs // to be improved (clarified)
426      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
427      for(Int_t k=0;k<9;k++)
428      {
429       fs1dEBE[2][1][k]->Fill(dEta,pow(wPhi*wPt*wEta,k),1.);
430      }  
431      // 2D (pt,eta) 
432      if(fCalculate2DFlow)
433      {
434       // (q_{m*m,k}(pt,eta)): 
435       for(Int_t m=0;m<4;m++)
436       {
437        for(Int_t k=0;k<9;k++)
438        {
439         fReRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
440         fImRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
441        }
442       } 
443       // s_{k}(pt,eta) for RP&&POIs // to be improved (clarified)
444       // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
445       for(Int_t k=0;k<9;k++)
446       {
447        fs2dEBE[2][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
448       }
449      } // end of if(fCalculate2DFlow) 
450       
451     } // end of if(aftsTrack->InPOISelection())  
452    } // end of if(pTrack->InRPSelection())
453
454    if(aftsTrack->InPOISelection())
455    {
456     dPhi = aftsTrack->Phi();
457     dPt  = aftsTrack->Pt();
458     dEta = aftsTrack->Eta();
459     
460     // 1D (pt)
461     // p_n(m*n,0):   
462     for(Int_t m=0;m<4;m++)
463     {
464      fReRPQ1dEBE[1][0][m][0]->Fill(dPt,TMath::Cos((m+1.)*n*dPhi),1.);
465      fImRPQ1dEBE[1][0][m][0]->Fill(dPt,TMath::Sin((m+1.)*n*dPhi),1.);
466     }
467     // 1D (eta)
468     // p_n(m*n,0):   
469     for(Int_t m=0;m<4;m++)
470     {
471      fReRPQ1dEBE[1][1][m][0]->Fill(dEta,TMath::Cos((m+1.)*n*dPhi),1.);
472      fImRPQ1dEBE[1][1][m][0]->Fill(dEta,TMath::Sin((m+1.)*n*dPhi),1.);
473     }
474     // 2D (pt,eta):
475     if(fCalculate2DFlow)
476     {      
477      // p_n(m*n,0):   
478      for(Int_t m=0;m<4;m++)
479      {
480       fReRPQ2dEBE[1][m][0]->Fill(dPt,dEta,TMath::Cos((m+1.)*n*dPhi),1.);
481       fImRPQ2dEBE[1][m][0]->Fill(dPt,dEta,TMath::Sin((m+1.)*n*dPhi),1.);
482      }
483     } // end of if(fCalculate2DFlow)  
484    } // end of if(pTrack->InPOISelection())    
485    
486   } else // to if(aftsTrack)
487     {
488      cout<<endl;
489      cout<<" WARNING: no particle! (i.e. aftsTrack is a NULL pointer in AFAWQC::Make().)"<<endl;
490      cout<<endl;       
491     }
492  } // end of for(Int_t i=0;i<nPrim;i++) 
493
494  // calculate the final expressions for S^{M}_{p,k}:
495  for(Int_t p=0;p<8;p++)
496  {
497   for(Int_t k=0;k<9;k++)
498   {
499    (*fSMpk)(p,k)=pow((*fSMpk)(p,k),p+1);
500   }  
501  } 
502  
503  // e) Call all the methods which calculate correlations for reference flow:
504  if(!fEvaluateIntFlowNestedLoops)
505  {
506   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
507   {
508    if(nRP>1) this->CalculateIntFlowCorrelations(); // without using particle weights
509   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
510     {
511      if(nRP>1) this->CalculateIntFlowCorrelationsUsingParticleWeights(); // with using particle weights   
512     } 
513        
514   if(nRP>3) this->CalculateIntFlowProductOfCorrelations();
515   if(nRP>1) this->CalculateIntFlowSumOfEventWeights();
516   if(nRP>1) this->CalculateIntFlowSumOfProductOfEventWeights();
517   
518   // non-isotropic terms:
519   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
520   {
521    if(nRP>0) this->CalculateIntFlowCorrectionsForNUASinTerms();
522    if(nRP>0) this->CalculateIntFlowCorrectionsForNUACosTerms();
523   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
524     {
525      if(nRP>0) this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights();
526      if(nRP>0) this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights();     
527     }  
528      
529   if(nRP>0) this->CalculateIntFlowProductOfCorrectionTermsForNUA();     
530   if(nRP>0) this->CalculateIntFlowSumOfEventWeightsNUA();     
531   if(nRP>0) this->CalculateIntFlowSumOfProductOfEventWeightsNUA();     
532  } // end of if(!fEvaluateIntFlowNestedLoops)
533
534  // f) Call all the methods which calculate correlations for differential flow:
535  if(!fEvaluateDiffFlowNestedLoops)
536  {
537   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
538   {
539    // without using particle weights:
540    this->CalculateDiffFlowCorrelations("RP","Pt"); 
541    this->CalculateDiffFlowCorrelations("RP","Eta");
542    this->CalculateDiffFlowCorrelations("POI","Pt");
543    this->CalculateDiffFlowCorrelations("POI","Eta");
544    // non-isotropic terms:
545    this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
546    this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");
547    this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
548    this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");
549    this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
550    this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");
551    this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
552    this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");   
553   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
554     {
555      // with using particle weights:   
556      this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
557      this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta"); 
558      this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
559      this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta"); 
560      // non-isotropic terms:
561      this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
562      this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");
563      this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
564      this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");
565      this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
566      this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");
567      this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
568      this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");   
569     } 
570     
571   // whether or not using particle weights the following is calculated in the same way:  
572   this->CalculateDiffFlowProductOfCorrelations("RP","Pt");
573   this->CalculateDiffFlowProductOfCorrelations("RP","Eta");
574   this->CalculateDiffFlowProductOfCorrelations("POI","Pt");
575   this->CalculateDiffFlowProductOfCorrelations("POI","Eta");
576   this->CalculateDiffFlowSumOfEventWeights("RP","Pt");
577   this->CalculateDiffFlowSumOfEventWeights("RP","Eta");
578   this->CalculateDiffFlowSumOfEventWeights("POI","Pt");
579   this->CalculateDiffFlowSumOfEventWeights("POI","Eta");
580   this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Pt");
581   this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Eta");
582   this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Pt");
583   this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Eta");   
584  } // end of if(!fEvaluateDiffFlowNestedLoops)
585
586
587    
588   // with weights:
589   // ... 
590   
591   /*
592   // 2D differential flow
593   if(fCalculate2DFlow)
594   {
595    // without weights:
596    if(nRP>1) this->CalculateCorrelationsForDifferentialFlow2D("RP");
597    if(nRP>1) this->CalculateCorrelationsForDifferentialFlow2D("POI");
598   
599    // with weights:
600    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
601    {
602     if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow2D("RP");
603     if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow2D("POI");
604    } 
605   } // end of if(fCalculate2DFlow)
606   */
607   
608  // g) Distributions of correlations:
609  if(fStoreDistributions){this->StoreDistributionsOfCorrelations();}
610  
611  // h) Store phi distribution for one event to illustrate flow: 
612  if(fStorePhiDistributionForOneEvent){this->StorePhiDistributionForOneEvent(anEvent);}
613   
614  // h) Debugging and cross-checking (evaluate nested loops):
615  //  h1) cross-checking results for integrated flow:
616  if(fEvaluateIntFlowNestedLoops)
617  {
618   if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10 
619   {
620    // without using particle weights:
621    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
622    {
623     // correlations:
624     this->CalculateIntFlowCorrelations(); // from Q-vectors
625     this->EvaluateIntFlowCorrelationsWithNestedLoops(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
626     // correction for non-uniform acceptance:
627     this->CalculateIntFlowCorrectionsForNUASinTerms(); // from Q-vectors (sin terms)
628     this->CalculateIntFlowCorrectionsForNUACosTerms(); // from Q-vectors (cos terms)
629     this->EvaluateIntFlowCorrectionsForNUAWithNestedLoops(anEvent); // from nested loops (both sin and cos terms)
630    }
631    // using particle weights:
632    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
633    {
634     // correlations:
635     this->CalculateIntFlowCorrelationsUsingParticleWeights(); // from Q-vectors
636     this->EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
637     // correction for non-uniform acceptance:
638     this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights(); // from Q-vectors (sin terms)
639     this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights(); // from Q-vectors (cos terms)
640     this->EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (both sin and cos terms)   
641    }
642   } else if (nPrim>fMaxAllowedMultiplicity) // to if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity)
643     {
644      cout<<endl;
645      cout<<"Skipping the event because multiplicity is "<<nPrim<<". Too high to evaluate nested loops!"<<endl;
646     } else
647       {
648        cout<<endl;
649        cout<<"Skipping the event because multiplicity is "<<nPrim<<"."<<endl;      
650       } 
651  } // end of if(fEvaluateIntFlowNestedLoops) 
652  
653  //  h2) cross-checking results for differential flow:
654  if(fEvaluateDiffFlowNestedLoops)
655  {
656   if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
657   {
658    // without using particle weights:
659    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
660    {
661     // reduced correlations:
662     // Q-vectors:
663     this->CalculateDiffFlowCorrelations("RP","Pt");
664     this->CalculateDiffFlowCorrelations("RP","Eta");
665     this->CalculateDiffFlowCorrelations("POI","Pt");
666     this->CalculateDiffFlowCorrelations("POI","Eta");
667     // nested loops:
668     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Pt"); 
669     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Eta"); 
670     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Pt"); 
671     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Eta"); 
672     // reduced corrections for non-uniform acceptance:
673     // Q-vectors:
674     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
675     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");
676     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
677     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");
678     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
679     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");
680     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
681     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");
682     // nested loops:
683     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Pt");
684     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Eta");
685     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Pt"); 
686     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Eta"); 
687    } // end of if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
688    // using particle weights:
689    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
690    {
691     this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
692     this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta"); 
693     this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
694     this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta"); 
695     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
696     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");
697     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
698     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");
699     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
700     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");
701     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
702     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");
703     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
704     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta");
705     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
706     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta");   
707     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
708     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta"); 
709     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
710     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta"); 
711    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
712   } // end of if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
713  } // end of if(fEvaluateDiffFlowNestedLoops) 
714  
715  // i) Reset all event-by-event quantities. 
716  this->ResetEventByEventQuantities();
717  
718 } // end of AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
719
720 //================================================================================================================================
721
722 void AliFlowAnalysisWithQCumulants::Finish()
723 {
724  // Calculate the final results.
725  
726  // a) Check all pointers used in this method;
727  // b) Acces the constants;
728  // c) Access the flags;
729  // d) Calculate reference cumulants (not corrected for detector effects);
730  // e) Correct reference cumulants for detector effects;
731  // f) Calculate reference flow;
732  // g) Store results for reference flow in AliFlowCommonHistResults and print them on the screen;
733  
734  
735  
736  // h) Calculate the final results for differential flow (without/with weights);
737  // i) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA);
738  // j) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults;
739  // k) Store results for differential flow in AliFlowCommonHistResults;
740  // l) Print the final results for integrated flow (RP/POI) on the screen; 
741  // m) Cross-checking: Results from Q-vectors vs results from nested loops.
742  
743  // a) Check all pointers used in this method:
744  this->CheckPointersUsedInFinish();
745   
746  // b) Acces the constants:
747  this->AccessConstants();          
748  
749  if(fCommonHists && fCommonHists->GetHarmonic()) // to be improved (moved somewhere else)
750  {
751   fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
752  } 
753  
754  // c) Access the flags: // to be improved (implement a method for this)
755  fUsePhiWeights = (Bool_t)fUseParticleWeights->GetBinContent(1); 
756  fUsePtWeights = (Bool_t)fUseParticleWeights->GetBinContent(2); 
757  fUseEtaWeights = (Bool_t)fUseParticleWeights->GetBinContent(3);  
758  fApplyCorrectionForNUA = (Bool_t)fIntFlowFlags->GetBinContent(3); 
759  fPrintFinalResults[0] = (Bool_t)fIntFlowFlags->GetBinContent(4);
760  fPrintFinalResults[1] = (Bool_t)fIntFlowFlags->GetBinContent(5);
761  fPrintFinalResults[2] = (Bool_t)fIntFlowFlags->GetBinContent(6);
762  fPrintFinalResults[3] = (Bool_t)fIntFlowFlags->GetBinContent(7);
763  fApplyCorrectionForNUAVsM = (Bool_t)fIntFlowFlags->GetBinContent(8);  
764  fPropagateErrorAlsoFromNIT = (Bool_t)fIntFlowFlags->GetBinContent(9);  
765  fCalculateCumulantsVsM = (Bool_t)fIntFlowFlags->GetBinContent(10); 
766  fMinimumBiasReferenceFlow = (Bool_t)fIntFlowFlags->GetBinContent(11); 
767  fForgetAboutCovariances = (Bool_t)fIntFlowFlags->GetBinContent(12);
768  fStorePhiDistributionForOneEvent = (Bool_t)fIntFlowFlags->GetBinContent(13);
769  fFillMultipleControlHistograms = (Bool_t)fIntFlowFlags->GetBinContent(14);
770  fEvaluateIntFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(1);
771  fEvaluateDiffFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(2); 
772  fCrossCheckInPtBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(3);
773  fCrossCheckInEtaBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(4); 
774      
775  // d) Calculate reference cumulants (not corrected for detector effects):
776  this->FinalizeCorrelationsIntFlow();
777  this->CalculateCovariancesIntFlow();
778  this->CalculateCumulantsIntFlow();
779
780  // e) Correct reference cumulants for detector effects:
781  this->FinalizeCorrectionTermsForNUAIntFlow();
782  this->CalculateCovariancesNUAIntFlow(); 
783  this->CalculateQcumulantsCorrectedForNUAIntFlow();  
784
785  // f) Calculate reference flow:
786  this->CalculateReferenceFlow(); 
787   
788  // g) Store results for reference flow in AliFlowCommonHistResults and print them on the screen:
789  this->FillCommonHistResultsIntFlow();  
790  if(fPrintFinalResults[0]){this->PrintFinalResultsForIntegratedFlow("RF");}
791  if(fPrintFinalResults[3] && fCalculateCumulantsVsM){this->PrintFinalResultsForIntegratedFlow("RF, rebinned in M");}
792  
793  
794  
795  
796  
797  
798  
799  
800  
801  // g) Calculate the final results for differential flow (without/with weights):
802  this->FinalizeReducedCorrelations("RP","Pt"); 
803  this->FinalizeReducedCorrelations("RP","Eta"); 
804  this->FinalizeReducedCorrelations("POI","Pt"); 
805  this->FinalizeReducedCorrelations("POI","Eta");
806  this->CalculateDiffFlowCovariances("RP","Pt");
807  this->CalculateDiffFlowCovariances("RP","Eta");
808  this->CalculateDiffFlowCovariances("POI","Pt");
809  this->CalculateDiffFlowCovariances("POI","Eta");
810  this->CalculateDiffFlowCumulants("RP","Pt");
811  this->CalculateDiffFlowCumulants("RP","Eta");
812  this->CalculateDiffFlowCumulants("POI","Pt");
813  this->CalculateDiffFlowCumulants("POI","Eta");
814  this->CalculateDiffFlow("RP","Pt");
815  this->CalculateDiffFlow("RP","Eta");
816  this->CalculateDiffFlow("POI","Pt");
817  this->CalculateDiffFlow("POI","Eta");
818  
819  // h) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA):
820  if(fApplyCorrectionForNUA)
821  {
822   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Pt");
823   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Eta");
824   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Pt");
825   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Eta");      
826   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Pt");   
827   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Eta");   
828   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Pt");   
829   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Eta");  
830   this->CalculateDiffFlowCorrectedForNUA("RP","Pt"); 
831   this->CalculateDiffFlowCorrectedForNUA("RP","Eta"); 
832   this->CalculateDiffFlowCorrectedForNUA("POI","Pt"); 
833   this->CalculateDiffFlowCorrectedForNUA("POI","Eta"); 
834  }
835  
836  // i) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults:
837  this->CalculateFinalResultsForRPandPOIIntegratedFlow("RP");
838  this->CalculateFinalResultsForRPandPOIIntegratedFlow("POI");
839
840  // j) Store results for differential flow in AliFlowCommonHistResults:
841  this->FillCommonHistResultsDiffFlow("RP");
842  this->FillCommonHistResultsDiffFlow("POI");
843
844  // k) Print the final results for integrated flow (RP/POI) on the screen:
845  if(fPrintFinalResults[1]){this->PrintFinalResultsForIntegratedFlow("RP");} 
846  if(fPrintFinalResults[2]){this->PrintFinalResultsForIntegratedFlow("POI");}
847   
848  // l) Cross-checking: Results from Q-vectors vs results from nested loops:
849  //  l1) Reference flow:
850  if(fEvaluateIntFlowNestedLoops)
851  {
852   this->CrossCheckIntFlowCorrelations();
853   this->CrossCheckIntFlowCorrectionTermsForNUA(); 
854   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) this->CrossCheckIntFlowExtraCorrelations();     
855  } // end of if(fEvaluateIntFlowNestedLoops)  
856  
857  //  l2) Differential flow: 
858  if(fEvaluateDiffFlowNestedLoops) 
859  {
860   // Correlations:
861   this->PrintNumberOfParticlesInSelectedBin();
862   this->CrossCheckDiffFlowCorrelations("RP","Pt");  
863   this->CrossCheckDiffFlowCorrelations("RP","Eta"); 
864   this->CrossCheckDiffFlowCorrelations("POI","Pt");  
865   this->CrossCheckDiffFlowCorrelations("POI","Eta");
866   // Correction terms for non-uniform acceptance:
867   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Pt");      
868   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Eta");       
869   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Pt");      
870   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Eta");       
871  } // end of if(fEvaluateDiffFlowNestedLoops)
872                                                                                                                                                                                                                                                                                                                                    
873 } // end of AliFlowAnalysisWithQCumulants::Finish()
874
875 //================================================================================================================================
876
877 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
878 {
879  // Calculate correction terms for non-uniform acceptance of the detector for reference flow (cos terms).
880  
881  // multiplicity:
882  Double_t dMult = (*fSMpk)(0,0);
883  
884  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
885  Double_t dReQ1n = (*fReQ)(0,0);
886  Double_t dReQ2n = (*fReQ)(1,0);
887  //Double_t dReQ3n = (*fReQ)(2,0);
888  //Double_t dReQ4n = (*fReQ)(3,0);
889  Double_t dImQ1n = (*fImQ)(0,0);
890  Double_t dImQ2n = (*fImQ)(1,0);
891  //Double_t dImQ3n = (*fImQ)(2,0);
892  //Double_t dImQ4n = (*fImQ)(3,0);
893         
894  //                                  *************************************************************
895  //                                  **** corrections for non-uniform acceptance (cos terms): ****
896  //                                  *************************************************************
897  //
898  // Remark 1: corrections for non-uniform acceptance (cos terms) calculated with non-weighted Q-vectors 
899  //           are stored in 1D profile fQCorrectionsCos.
900  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
901  // --------------------------------------------------------------------------------------------------------------------
902  // 1st bin: <<cos(n*(phi1))>> = cosP1n
903  // 2nd bin: <<cos(n*(phi1+phi2))>> = cosP1nP1n
904  // 3rd bin: <<cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1n
905  // 4th bin: <<cos(n*(2phi1-phi2))>> = cosP2nM1n
906  // --------------------------------------------------------------------------------------------------------------------
907   
908  // 1-particle:
909  Double_t cosP1n = 0.; // <<cos(n*(phi1))>>
910    
911  if(dMult>0)
912  {
913   cosP1n = dReQ1n/dMult; 
914   
915   // average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
916   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1n);
917   // event weights for NUA terms:
918   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(1,dMult);
919   
920   // final average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
921   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1n,dMult);  
922   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][0]->Fill(dMult+0.5,cosP1n,dMult);}    
923  } 
924  
925  // 2-particle:
926  Double_t cosP1nP1n = 0.; // <<cos(n*(phi1+phi2))>>
927  Double_t cosP2nM1n = 0.; // <<cos(n*(2phi1-phi2))>>
928  
929  if(dMult>1)
930  {
931   cosP1nP1n = (pow(dReQ1n,2)-pow(dImQ1n,2)-dReQ2n)/(dMult*(dMult-1)); 
932   cosP2nM1n = (dReQ2n*dReQ1n+dImQ2n*dImQ1n-dReQ1n)/(dMult*(dMult-1)); 
933   
934   // average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
935   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1n);
936   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(4,cosP2nM1n);
937   // event weights for NUA terms:
938   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(2,dMult*(dMult-1));
939   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(4,dMult*(dMult-1));
940       
941   // final average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
942   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1n,dMult*(dMult-1));  
943   fIntFlowCorrectionTermsForNUAPro[1]->Fill(3.5,cosP2nM1n,dMult*(dMult-1));
944   if(fCalculateCumulantsVsM)
945   {
946    fIntFlowCorrectionTermsForNUAVsMPro[1][1]->Fill(dMult+0.5,cosP1nP1n,dMult*(dMult-1));  
947    fIntFlowCorrectionTermsForNUAVsMPro[1][3]->Fill(dMult+0.5,cosP2nM1n,dMult*(dMult-1));
948   }
949  } 
950  
951  // 3-particle:
952  Double_t cosP1nM1nM1n = 0.; // <<cos(n*(phi1-phi2-phi3))>>
953  
954  if(dMult>2)
955  {
956   cosP1nM1nM1n = (dReQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))-dReQ1n*dReQ2n-dImQ1n*dImQ2n-2.*(dMult-1)*dReQ1n)
957                / (dMult*(dMult-1)*(dMult-2)); 
958   
959   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
960   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1n);
961   // event weights for NUA terms:
962   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
963   
964   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
965   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
966   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][2]->Fill(dMult+0.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
967  } 
968  
969 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
970
971
972 //================================================================================================================================
973
974
975 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
976 {
977  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
978  
979  // multiplicity:
980  Double_t dMult = (*fSMpk)(0,0);
981  
982  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
983  Double_t dReQ1n = (*fReQ)(0,0);
984  Double_t dReQ2n = (*fReQ)(1,0);
985  //Double_t dReQ3n = (*fReQ)(2,0);
986  //Double_t dReQ4n = (*fReQ)(3,0);
987  Double_t dImQ1n = (*fImQ)(0,0);
988  Double_t dImQ2n = (*fImQ)(1,0);
989  //Double_t dImQ3n = (*fImQ)(2,0);
990  //Double_t dImQ4n = (*fImQ)(3,0);
991         
992  //                                  *************************************************************
993  //                                  **** corrections for non-uniform acceptance (sin terms): ****
994  //                                  *************************************************************
995  //
996  // Remark 1: corrections for non-uniform acceptance (sin terms) calculated with non-weighted Q-vectors 
997  //           are stored in 1D profile fQCorrectionsSin.
998  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
999  // --------------------------------------------------------------------------------------------------------------------
1000  // 1st bin: <<sin(n*(phi1))>> = sinP1n
1001  // 2nd bin: <<sin(n*(phi1+phi2))>> = sinP1nP1n
1002  // 3rd bin: <<sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1n
1003  // 4th bin: <<sin(n*(2phi1-phi2))>> = sinP2nM1n
1004  // --------------------------------------------------------------------------------------------------------------------
1005  
1006  // 1-particle:
1007  Double_t sinP1n = 0.; // <sin(n*(phi1))>
1008  
1009  if(dMult>0)
1010  {
1011   sinP1n = dImQ1n/dMult; 
1012      
1013   // average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
1014   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1n);  
1015   // event weights for NUA terms:
1016   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(1,dMult);
1017   
1018   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
1019   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1n,dMult);  
1020   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][0]->Fill(dMult+0.5,sinP1n,dMult);} 
1021  } 
1022  
1023  // 2-particle:
1024  Double_t sinP1nP1n = 0.; // <<sin(n*(phi1+phi2))>>
1025  Double_t sinP2nM1n = 0.; // <<sin(n*(2phi1-phi2))>>
1026  if(dMult>1)
1027  {
1028   sinP1nP1n = (2.*dReQ1n*dImQ1n-dImQ2n)/(dMult*(dMult-1)); 
1029   sinP2nM1n = (dImQ2n*dReQ1n-dReQ2n*dImQ1n-dImQ1n)/(dMult*(dMult-1)); 
1030      
1031   // average non-weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
1032   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1n);
1033   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(4,sinP2nM1n);
1034   // event weights for NUA terms:
1035   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(2,dMult*(dMult-1));
1036   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(4,dMult*(dMult-1));
1037   
1038   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
1039   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1n,dMult*(dMult-1));  
1040   fIntFlowCorrectionTermsForNUAPro[0]->Fill(3.5,sinP2nM1n,dMult*(dMult-1));  
1041   if(fCalculateCumulantsVsM)
1042   {
1043    fIntFlowCorrectionTermsForNUAVsMPro[0][1]->Fill(dMult+0.5,sinP1nP1n,dMult*(dMult-1));  
1044    fIntFlowCorrectionTermsForNUAVsMPro[0][3]->Fill(dMult+0.5,sinP2nM1n,dMult*(dMult-1));    
1045   }
1046  } 
1047  
1048  // 3-particle:
1049  Double_t sinP1nM1nM1n = 0.; // <<sin(n*(phi1-phi2-phi3))>>
1050  
1051  if(dMult>2)
1052  {
1053   sinP1nM1nM1n = (-dImQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))+dReQ1n*dImQ2n-dImQ1n*dReQ2n+2.*(dMult-1)*dImQ1n)
1054                / (dMult*(dMult-1)*(dMult-2)); 
1055   
1056   // average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
1057   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1n);
1058   // event weights for NUA terms:
1059   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
1060   
1061   // final average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
1062   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
1063   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][2]->Fill(dMult+0.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
1064  } 
1065  
1066 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
1067
1068 //================================================================================================================================
1069
1070 void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1071 {
1072  // a) Get pointers for common control and common result histograms and profiles.
1073  // b) Get pointers for histograms with particle weights.
1074  // c) Get pointers for histograms and profiles relevant for integrated flow.
1075  // d) Get pointers for histograms and profiles relevant for differental flow.
1076  // e) Get pointers for histograms and profiles holding results obtained with nested loops.
1077  
1078  if(outputListHistos)
1079  {      
1080   this->SetHistList(outputListHistos);
1081   if(!fHistList)
1082   {
1083    cout<<endl;
1084    cout<<" WARNING (QC): fHistList is NULL in AFAWQC::GOH() !!!!"<<endl;
1085    cout<<endl;
1086    exit(0);
1087   }
1088   this->GetPointersForCommonHistograms(); 
1089   this->GetPointersForParticleWeightsHistograms(); 
1090   this->GetPointersForIntFlowHistograms();
1091   this->GetPointersForDiffFlowHistograms(); 
1092   this->GetPointersForNestedLoopsHistograms(); 
1093  } else 
1094    {
1095     cout<<endl;
1096     cout<<" WARNING (QC): outputListHistos is NULL in AFAWQC::GOH() !!!!"<<endl;
1097     cout<<endl;
1098     exit(0);
1099    }
1100    
1101 } // end of void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1102
1103 //================================================================================================================================
1104
1105 TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta) const
1106 {
1107  // project 2D profile onto pt axis to get 1D profile
1108  
1109  Int_t nBinsPt   = profilePtEta->GetNbinsX();
1110  Double_t dPtMin = (profilePtEta->GetXaxis())->GetXmin();
1111  Double_t dPtMax = (profilePtEta->GetXaxis())->GetXmax();
1112  
1113  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1114  
1115  TProfile *profilePt = new TProfile("","",nBinsPt,dPtMin,dPtMax); 
1116  
1117  for(Int_t p=1;p<=nBinsPt;p++)
1118  {
1119   Double_t contentPt = 0.;
1120   Double_t entryPt = 0.;
1121   Double_t spreadPt = 0.;
1122   Double_t sum1 = 0.;
1123   Double_t sum2 = 0.;
1124   Double_t sum3 = 0.;
1125   for(Int_t e=1;e<=nBinsEta;e++)
1126   {
1127    contentPt += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1128               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1129    entryPt   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1130    
1131    sum1 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1132          * (pow(profilePtEta->GetBinError(profilePtEta->GetBin(p,e)),2.)
1133             + pow(profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)),2.)); 
1134    sum2 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1135    sum3 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1136          * (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)));            
1137   }
1138   if(sum2>0. && sum1/sum2-pow(sum3/sum2,2.) > 0.)
1139   {
1140    spreadPt = pow(sum1/sum2-pow(sum3/sum2,2.),0.5);
1141   }
1142   profilePt->SetBinContent(p,contentPt);
1143   profilePt->SetBinEntries(p,entryPt);
1144   {
1145    profilePt->SetBinError(p,spreadPt);
1146   }
1147   
1148  }
1149  
1150  return profilePt;
1151  
1152 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta)
1153
1154
1155 //================================================================================================================================
1156
1157
1158 TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta) const
1159 {
1160  // project 2D profile onto eta axis to get 1D profile
1161  
1162  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1163  Double_t dEtaMin = (profilePtEta->GetYaxis())->GetXmin();
1164  Double_t dEtaMax = (profilePtEta->GetYaxis())->GetXmax();
1165  
1166  Int_t nBinsPt = profilePtEta->GetNbinsX();
1167  
1168  TProfile *profileEta = new TProfile("","",nBinsEta,dEtaMin,dEtaMax); 
1169  
1170  for(Int_t e=1;e<=nBinsEta;e++)
1171  {
1172   Double_t contentEta = 0.;
1173   Double_t entryEta = 0.;
1174   for(Int_t p=1;p<=nBinsPt;p++)
1175   {
1176    contentEta += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1177               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1178    entryEta   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1179   }
1180   profileEta->SetBinContent(e,contentEta);
1181   profileEta->SetBinEntries(e,entryEta);
1182  }
1183  
1184  return profileEta;
1185  
1186 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta)
1187
1188 //================================================================================================================================
1189
1190 void AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type)
1191 {
1192  // Printing on the screen the final results for integrated flow (RF, POI and RP). 
1193  
1194  Int_t n = fHarmonic; 
1195  
1196  Double_t dVn[4] = {0.}; // array to hold Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1197  Double_t dVnErr[4] = {0.}; // array to hold errors of Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1198  
1199  if(type == "RF")
1200  {
1201   for(Int_t b=0;b<4;b++)
1202   {
1203    dVn[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinContent(1); 
1204    dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinError(1); 
1205    dVn[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinContent(1); 
1206    dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinError(1); 
1207    dVn[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinContent(1); 
1208    dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinError(1); 
1209    dVn[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinContent(1); 
1210    dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinError(1);    
1211   }  
1212  } else if(type == "RP")
1213    {
1214     dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinContent(1); 
1215     dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinError(1); 
1216     dVn[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinContent(1); 
1217     dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinError(1); 
1218     dVn[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinContent(1); 
1219     dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinError(1); 
1220     dVn[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinContent(1); 
1221     dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinError(1); 
1222    } else if(type == "POI")
1223      {
1224       dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinContent(1); 
1225       dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinError(1); 
1226       dVn[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinContent(1); 
1227       dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinError(1); 
1228       dVn[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinContent(1); 
1229       dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinError(1); 
1230       dVn[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinContent(1); 
1231       dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinError(1); 
1232      } else if(type == "RF, rebinned in M" && fCalculateCumulantsVsM)
1233        {
1234         for(Int_t b=0;b<4;b++)
1235         {
1236          dVn[b] = fIntFlowRebinnedInM->GetBinContent(b+1); 
1237          dVnErr[b] = fIntFlowRebinnedInM->GetBinError(b+1);
1238         }  
1239        }
1240  
1241  TString title = " flow estimates from Q-cumulants"; 
1242  TString subtitle = "    ("; 
1243  TString subtitle2 = "       (rebinned in M)"; 
1244  
1245  if(type != "RF, rebinned in M")
1246  {
1247   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
1248   {
1249    subtitle.Append(type);
1250    subtitle.Append(", without weights)");
1251   } else  
1252     {
1253      subtitle.Append(type);
1254      subtitle.Append(", with weights)");
1255     }
1256  } else
1257    {
1258     if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
1259     {
1260      subtitle.Append("RF");
1261      subtitle.Append(", without weights)");
1262     } else  
1263       {
1264        subtitle.Append("RF");
1265        subtitle.Append(", with weights)");      
1266       }
1267    } 
1268    
1269  cout<<endl;
1270  cout<<"*************************************"<<endl;
1271  cout<<"*************************************"<<endl;
1272  cout<<title.Data()<<endl; 
1273  cout<<subtitle.Data()<<endl; 
1274  if(type == "RF, rebinned in M"){cout<<subtitle2.Data()<<endl;}
1275  cout<<endl;
1276   
1277  for(Int_t i=0;i<4;i++)
1278  {
1279   cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = "<<dVn[i]<<" +/- "<<dVnErr[i]<<endl;
1280  }
1281  
1282  cout<<endl;
1283  if(type == "RF")
1284  {
1285   if(fApplyCorrectionForNUA)
1286   {
1287    cout<<" detector bias (corrected for): "<<endl;
1288   } else
1289     {
1290      cout<<" detector bias (not corrected for):"<<endl;  
1291     }
1292   cout<<"  to QC{2}: "<<fIntFlowDetectorBias->GetBinContent(1)<<" +/- "<<fIntFlowDetectorBias->GetBinError(1)<<endl;
1293   cout<<"  to QC{4}: "<<fIntFlowDetectorBias->GetBinContent(2)<<" +/- "<<fIntFlowDetectorBias->GetBinError(2)<<endl;
1294   cout<<endl;
1295  }
1296  if(type == "RF" || type == "RF, rebinned in M")
1297  {
1298   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl; 
1299  }
1300  else if (type == "RP")
1301  {
1302   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl;  
1303  } 
1304  else if (type == "POI")
1305  {
1306   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultPOI()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultPOI()->GetMean()<<endl;
1307  }  
1308  
1309  cout<<"*************************************"<<endl;
1310  cout<<"*************************************"<<endl;
1311  cout<<endl; 
1312   
1313 }// end of AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type="RF");
1314
1315 //================================================================================================================================
1316
1317 void AliFlowAnalysisWithQCumulants::WriteHistograms(TString outputFileName)
1318 {
1319  //store the final results in output .root file
1320  TFile *output = new TFile(outputFileName.Data(),"RECREATE");
1321  //output->WriteObject(fHistList, "cobjQC","SingleKey");
1322  fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
1323  delete output;
1324 }
1325
1326
1327 //================================================================================================================================
1328
1329
1330 void AliFlowAnalysisWithQCumulants::WriteHistograms(TDirectoryFile *outputFileName)
1331 {
1332  //store the final results in output .root file
1333  fHistList->SetName("cobjQC");
1334  fHistList->SetOwner(kTRUE);
1335  outputFileName->Add(fHistList);
1336  outputFileName->Write(outputFileName->GetName(), TObject::kSingleKey);
1337 }
1338
1339 //================================================================================================================================
1340
1341 void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1342 {
1343  // Book common control histograms and common histograms for final results.
1344  // common control histogram (ALL events)
1345  TString commonHistsName = "AliFlowCommonHistQC";
1346  commonHistsName += fAnalysisLabel->Data();
1347  fCommonHists = new AliFlowCommonHist(commonHistsName.Data());
1348  fHistList->Add(fCommonHists);  
1349  if(fFillMultipleControlHistograms)
1350  {
1351   // common control histogram (for events with 2 and more particles)
1352   TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
1353   commonHists2ndOrderName += fAnalysisLabel->Data();
1354   fCommonHists2nd = new AliFlowCommonHist(commonHists2ndOrderName.Data());
1355   fHistList->Add(fCommonHists2nd);  
1356   // common control histogram (for events with 4 and more particles)
1357   TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
1358   commonHists4thOrderName += fAnalysisLabel->Data();
1359   fCommonHists4th = new AliFlowCommonHist(commonHists4thOrderName.Data());
1360   fHistList->Add(fCommonHists4th);  
1361   // common control histogram (for events with 6 and more particles)
1362   TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
1363   commonHists6thOrderName += fAnalysisLabel->Data();
1364   fCommonHists6th = new AliFlowCommonHist(commonHists6thOrderName.Data());
1365   fHistList->Add(fCommonHists6th);  
1366   // common control histogram (for events with 8 and more particles)
1367   TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
1368   commonHists8thOrderName += fAnalysisLabel->Data();
1369   fCommonHists8th = new AliFlowCommonHist(commonHists8thOrderName.Data());
1370   fHistList->Add(fCommonHists8th);    
1371  } // end of if(fFillMultipleControlHistograms)
1372  
1373  // common histograms for final results for QC{2}:
1374  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC";
1375  commonHistResults2ndOrderName += fAnalysisLabel->Data();
1376  fCommonHistsResults2nd = new AliFlowCommonHistResults(commonHistResults2ndOrderName.Data());
1377  fHistList->Add(fCommonHistsResults2nd);  
1378  // common histograms for final results for QC{4}:
1379  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
1380  commonHistResults4thOrderName += fAnalysisLabel->Data();
1381  fCommonHistsResults4th = new AliFlowCommonHistResults(commonHistResults4thOrderName.Data());
1382  fHistList->Add(fCommonHistsResults4th); 
1383  // common histograms for final results for QC{6}:
1384  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
1385  commonHistResults6thOrderName += fAnalysisLabel->Data();
1386  fCommonHistsResults6th = new AliFlowCommonHistResults(commonHistResults6thOrderName.Data());
1387  fHistList->Add(fCommonHistsResults6th);  
1388  // common histograms for final results for QC{8}:
1389  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
1390  commonHistResults8thOrderName += fAnalysisLabel->Data();
1391  fCommonHistsResults8th = new AliFlowCommonHistResults(commonHistResults8thOrderName.Data());
1392  fHistList->Add(fCommonHistsResults8th); 
1393  
1394 } // end of void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1395
1396
1397 //================================================================================================================================
1398
1399
1400 void AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1401 {
1402  // book and fill histograms which hold phi, pt and eta weights
1403
1404  if(!fWeightsList)
1405  {
1406   cout<<"WARNING: fWeightsList is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1407   exit(0);  
1408  }
1409     
1410  TString fUseParticleWeightsName = "fUseParticleWeightsQC";
1411  fUseParticleWeightsName += fAnalysisLabel->Data();
1412  fUseParticleWeights = new TProfile(fUseParticleWeightsName.Data(),"0 = particle weight not used, 1 = particle weight used ",3,0,3);
1413  fUseParticleWeights->SetLabelSize(0.06);
1414  (fUseParticleWeights->GetXaxis())->SetBinLabel(1,"w_{#phi}");
1415  (fUseParticleWeights->GetXaxis())->SetBinLabel(2,"w_{p_{T}}");
1416  (fUseParticleWeights->GetXaxis())->SetBinLabel(3,"w_{#eta}");
1417  fUseParticleWeights->Fill(0.5,(Int_t)fUsePhiWeights);
1418  fUseParticleWeights->Fill(1.5,(Int_t)fUsePtWeights);
1419  fUseParticleWeights->Fill(2.5,(Int_t)fUseEtaWeights);
1420  fWeightsList->Add(fUseParticleWeights); 
1421   
1422  if(fUsePhiWeights)
1423  {
1424   if(fWeightsList->FindObject("phi_weights"))
1425   {
1426    fPhiWeights = dynamic_cast<TH1F*>(fWeightsList->FindObject("phi_weights"));
1427    if(TMath::Abs(fPhiWeights->GetBinWidth(1)-fPhiBinWidth)>pow(10.,-6.))
1428    {
1429     cout<<endl;
1430     cout<<"WARNING (QC): Inconsistent binning in histograms for phi-weights throughout the code."<<endl;
1431     cout<<endl;
1432     //exit(0);
1433    }
1434   } else 
1435     {
1436      cout<<"WARNING: fWeightsList->FindObject(\"phi_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1437      exit(0);
1438     }
1439  } // end of if(fUsePhiWeights)
1440  
1441  if(fUsePtWeights) 
1442  {
1443   if(fWeightsList->FindObject("pt_weights"))
1444   {
1445    fPtWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("pt_weights"));
1446    if(TMath::Abs(fPtWeights->GetBinWidth(1)-fPtBinWidth)>pow(10.,-6.))
1447    {
1448     cout<<endl;
1449     cout<<"WARNING (QC): Inconsistent binning in histograms for pt-weights throughout the code."<<endl;
1450     cout<<endl;
1451     //exit(0);
1452    }
1453   } else 
1454     {
1455      cout<<"WARNING: fWeightsList->FindObject(\"pt_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1456      exit(0);
1457     }
1458  } // end of if(fUsePtWeights)    
1459
1460  if(fUseEtaWeights) 
1461  {
1462   if(fWeightsList->FindObject("eta_weights"))
1463   {
1464    fEtaWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("eta_weights"));
1465    if(TMath::Abs(fEtaWeights->GetBinWidth(1)-fEtaBinWidth)>pow(10.,-6.))
1466    {
1467     cout<<endl;
1468     cout<<"WARNING (QC): Inconsistent binning in histograms for eta-weights throughout the code."<<endl;
1469     cout<<endl;
1470     //exit(0);
1471    }
1472   } else 
1473     {
1474      cout<<"WARNING: fUseEtaWeights && fWeightsList->FindObject(\"eta_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1475      exit(0);
1476     }
1477  } // end of if(fUseEtaWeights)
1478  
1479 } // end of AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1480
1481
1482 //================================================================================================================================
1483
1484
1485 void AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
1486 {
1487  // Book all objects for integrated flow:
1488  //  a) Book profile to hold all flags for integrated flow;
1489  //  b) Book event-by-event quantities;
1490  //  c) Book profiles; // to be improved (comment)
1491  //  d) Book histograms holding the final results.
1492  
1493  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
1494  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data members?)
1495  
1496  // a) Book profile to hold all flags for integrated flow:
1497  TString intFlowFlagsName = "fIntFlowFlags";
1498  intFlowFlagsName += fAnalysisLabel->Data();
1499  fIntFlowFlags = new TProfile(intFlowFlagsName.Data(),"Flags for Integrated Flow",14,0,14);
1500  fIntFlowFlags->SetTickLength(-0.01,"Y");
1501  fIntFlowFlags->SetMarkerStyle(25);
1502  fIntFlowFlags->SetLabelSize(0.05);
1503  fIntFlowFlags->SetLabelOffset(0.02,"Y");
1504  fIntFlowFlags->GetXaxis()->SetBinLabel(1,"Particle Weights");
1505  fIntFlowFlags->GetXaxis()->SetBinLabel(2,"Event Weights");
1506  fIntFlowFlags->GetXaxis()->SetBinLabel(3,"Corrected for NUA?");
1507  fIntFlowFlags->GetXaxis()->SetBinLabel(4,"Print RF results");
1508  fIntFlowFlags->GetXaxis()->SetBinLabel(5,"Print RP results");
1509  fIntFlowFlags->GetXaxis()->SetBinLabel(6,"Print POI results");
1510  fIntFlowFlags->GetXaxis()->SetBinLabel(7,"Print RF (rebinned in M) results");
1511  fIntFlowFlags->GetXaxis()->SetBinLabel(8,"Corrected for NUA vs M?");
1512  fIntFlowFlags->GetXaxis()->SetBinLabel(9,"Propagate errors to v_{n} from correlations?");
1513  fIntFlowFlags->GetXaxis()->SetBinLabel(10,"Calculate cumulants vs M");
1514  fIntFlowFlags->GetXaxis()->SetBinLabel(11,"fMinimumBiasReferenceFlow");
1515  fIntFlowFlags->GetXaxis()->SetBinLabel(12,"fForgetAboutCovariances");
1516  fIntFlowFlags->GetXaxis()->SetBinLabel(13,"fStorePhiDistributionForOneEvent");
1517  fIntFlowFlags->GetXaxis()->SetBinLabel(14,"fFillMultipleControlHistograms");
1518  fIntFlowList->Add(fIntFlowFlags);
1519
1520  // b) Book event-by-event quantities:
1521  // Re[Q_{m*n,k}], Im[Q_{m*n,k}] and S_{p,k}^M: 
1522  fReQ  = new TMatrixD(6,9);
1523  fImQ  = new TMatrixD(6,9);
1524  fSMpk = new TMatrixD(8,9);
1525  // average correlations <2>, <4>, <6> and <8> for single event (bining is the same as in fIntFlowCorrelationsPro and fIntFlowCorrelationsHist):
1526  TString intFlowCorrelationsEBEName = "fIntFlowCorrelationsEBE";
1527  intFlowCorrelationsEBEName += fAnalysisLabel->Data();
1528  fIntFlowCorrelationsEBE = new TH1D(intFlowCorrelationsEBEName.Data(),intFlowCorrelationsEBEName.Data(),4,0,4);
1529  // weights for average correlations <2>, <4>, <6> and <8> for single event:
1530  TString intFlowEventWeightsForCorrelationsEBEName = "fIntFlowEventWeightsForCorrelationsEBE";
1531  intFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
1532  fIntFlowEventWeightsForCorrelationsEBE = new TH1D(intFlowEventWeightsForCorrelationsEBEName.Data(),intFlowEventWeightsForCorrelationsEBEName.Data(),4,0,4);
1533  // average all correlations for single event (bining is the same as in fIntFlowCorrelationsAllPro and fIntFlowCorrelationsAllHist):
1534  TString intFlowCorrelationsAllEBEName = "fIntFlowCorrelationsAllEBE";
1535  intFlowCorrelationsAllEBEName += fAnalysisLabel->Data();
1536  fIntFlowCorrelationsAllEBE = new TH1D(intFlowCorrelationsAllEBEName.Data(),intFlowCorrelationsAllEBEName.Data(),34,0,34);
1537  // average correction terms for non-uniform acceptance for single event 
1538  // (binning is the same as in fIntFlowCorrectionTermsForNUAPro[2] and fIntFlowCorrectionTermsForNUAHist[2]):
1539  TString fIntFlowCorrectionTermsForNUAEBEName = "fIntFlowCorrectionTermsForNUAEBE";
1540  fIntFlowCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1541  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1542  {
1543   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()),4,0,4);  
1544  }
1545  // event weights for terms for non-uniform acceptance: 
1546  TString fIntFlowEventWeightForCorrectionTermsForNUAEBEName = "fIntFlowEventWeightForCorrectionTermsForNUAEBE";
1547  fIntFlowEventWeightForCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1548  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1549  {
1550   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc] = new TH1D(Form("%s: %s terms",fIntFlowEventWeightForCorrectionTermsForNUAEBEName.Data(),sinCosFlag[sc].Data()),Form("Event weights for terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),4,0,4); // to be improved - 4  
1551  }
1552  // c) Book profiles: // to be improved (comment)
1553  // profile to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8:
1554  TString avMultiplicityName = "fAvMultiplicity";
1555  avMultiplicityName += fAnalysisLabel->Data();
1556  fAvMultiplicity = new TProfile(avMultiplicityName.Data(),"Average Multiplicities of RPs",9,0,9);
1557  fAvMultiplicity->SetTickLength(-0.01,"Y");
1558  fAvMultiplicity->SetMarkerStyle(25);
1559  fAvMultiplicity->SetLabelSize(0.05);
1560  fAvMultiplicity->SetLabelOffset(0.02,"Y");
1561  fAvMultiplicity->SetYTitle("Average Multiplicity");
1562  (fAvMultiplicity->GetXaxis())->SetBinLabel(1,"all evts");
1563  (fAvMultiplicity->GetXaxis())->SetBinLabel(2,"n_{RP} #geq 1");
1564  (fAvMultiplicity->GetXaxis())->SetBinLabel(3,"n_{RP} #geq 2");
1565  (fAvMultiplicity->GetXaxis())->SetBinLabel(4,"n_{RP} #geq 3");
1566  (fAvMultiplicity->GetXaxis())->SetBinLabel(5,"n_{RP} #geq 4");
1567  (fAvMultiplicity->GetXaxis())->SetBinLabel(6,"n_{RP} #geq 5");
1568  (fAvMultiplicity->GetXaxis())->SetBinLabel(7,"n_{RP} #geq 6");
1569  (fAvMultiplicity->GetXaxis())->SetBinLabel(8,"n_{RP} #geq 7");
1570  (fAvMultiplicity->GetXaxis())->SetBinLabel(9,"n_{RP} #geq 8");
1571  fIntFlowProfiles->Add(fAvMultiplicity);
1572  // Average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with wrong errors!):
1573  TString correlationFlag[4] = {"#LT#LT2#GT#GT","#LT#LT4#GT#GT","#LT#LT6#GT#GT","#LT#LT8#GT#GT"};
1574  TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
1575  intFlowCorrelationsProName += fAnalysisLabel->Data();
1576  fIntFlowCorrelationsPro = new TProfile(intFlowCorrelationsProName.Data(),"Average correlations for all events",4,0,4,"s");
1577  fIntFlowCorrelationsPro->Sumw2();
1578  fIntFlowCorrelationsPro->SetTickLength(-0.01,"Y");
1579  fIntFlowCorrelationsPro->SetMarkerStyle(25);
1580  fIntFlowCorrelationsPro->SetLabelSize(0.06);
1581  fIntFlowCorrelationsPro->SetLabelOffset(0.01,"Y");
1582  for(Int_t b=0;b<4;b++)
1583  {
1584   (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(b+1,correlationFlag[b].Data());
1585  }
1586  fIntFlowProfiles->Add(fIntFlowCorrelationsPro);
1587  // Average correlations squared <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> for all events:
1588  TString squaredCorrelationFlag[4] = {"#LT#LT2#GT^{2}#GT","#LT#LT4#GT^{2}#GT","#LT#LT6#GT^{2}#GT","#LT#LT8#GT^{2}#GT"};
1589  TString intFlowSquaredCorrelationsProName = "fIntFlowSquaredCorrelationsPro";
1590  intFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
1591  fIntFlowSquaredCorrelationsPro = new TProfile(intFlowSquaredCorrelationsProName.Data(),"Average squared correlations for all events",4,0,4,"s");
1592  fIntFlowSquaredCorrelationsPro->Sumw2();
1593  fIntFlowSquaredCorrelationsPro->SetTickLength(-0.01,"Y");
1594  fIntFlowSquaredCorrelationsPro->SetMarkerStyle(25);
1595  fIntFlowSquaredCorrelationsPro->SetLabelSize(0.06);
1596  fIntFlowSquaredCorrelationsPro->SetLabelOffset(0.01,"Y");
1597  for(Int_t b=0;b<4;b++)
1598  {
1599   (fIntFlowSquaredCorrelationsPro->GetXaxis())->SetBinLabel(b+1,squaredCorrelationFlag[b].Data());
1600  }
1601  fIntFlowProfiles->Add(fIntFlowSquaredCorrelationsPro);
1602  if(fCalculateCumulantsVsM)
1603  {
1604   for(Int_t ci=0;ci<4;ci++) // correlation index
1605   {
1606    // average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (with wrong errors):
1607    TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
1608    intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
1609    fIntFlowCorrelationsVsMPro[ci] = new TProfile(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data()),
1610                                                  Form("%s vs multiplicity",correlationFlag[ci].Data()),
1611                                                  fnBinsMult,fMinMult,fMaxMult,"s");   
1612    fIntFlowCorrelationsVsMPro[ci]->Sumw2();                                                                                       
1613    fIntFlowCorrelationsVsMPro[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
1614    fIntFlowCorrelationsVsMPro[ci]->GetXaxis()->SetTitle("M");
1615    fIntFlowProfiles->Add(fIntFlowCorrelationsVsMPro[ci]);
1616    // average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> versus multiplicity for all events:  
1617    TString intFlowSquaredCorrelationsVsMProName = "fIntFlowSquaredCorrelationsVsMPro";
1618    intFlowSquaredCorrelationsVsMProName += fAnalysisLabel->Data();
1619    fIntFlowSquaredCorrelationsVsMPro[ci] = new TProfile(Form("%s, %s",intFlowSquaredCorrelationsVsMProName.Data(),squaredCorrelationFlag[ci].Data()),
1620                                                         Form("%s vs multiplicity",squaredCorrelationFlag[ci].Data()),
1621                                                         fnBinsMult,fMinMult,fMaxMult,"s");   
1622    fIntFlowSquaredCorrelationsVsMPro[ci]->Sumw2();                                                                                              
1623    fIntFlowSquaredCorrelationsVsMPro[ci]->GetYaxis()->SetTitle(squaredCorrelationFlag[ci].Data());
1624    fIntFlowSquaredCorrelationsVsMPro[ci]->GetXaxis()->SetTitle("M");
1625    fIntFlowProfiles->Add(fIntFlowSquaredCorrelationsVsMPro[ci]);
1626   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
1627  } // end of if(fCalculateCumulantsVsM)
1628  // averaged all correlations for all events (with wrong errors!):
1629  TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
1630  intFlowCorrelationsAllProName += fAnalysisLabel->Data();
1631  fIntFlowCorrelationsAllPro = new TProfile(intFlowCorrelationsAllProName.Data(),"Average correlations for all events",34,0,34,"s");
1632  fIntFlowCorrelationsAllPro->SetTickLength(-0.01,"Y");
1633  fIntFlowCorrelationsAllPro->SetMarkerStyle(25);
1634  fIntFlowCorrelationsAllPro->SetLabelSize(0.03);
1635  fIntFlowCorrelationsAllPro->SetLabelOffset(0.01,"Y");
1636  // 2-p correlations:
1637  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1638  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1639  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1640  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1641  // 3-p correlations:
1642  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1643  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1644  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1645  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1646  // 4-p correlations:
1647  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1648  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1649  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1650  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1651  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1652  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1653  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1654  // 5-p correlations:
1655  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1656  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1657  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1658  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1659  // 6-p correlations:
1660  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1661  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1662  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1663  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1664  // 7-p correlations:  
1665  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1666  // 8-p correlations:
1667  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1668  // EXTRA correlations:
1669  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(33,"<<4>>_{4n,2n|3n,3n}");
1670  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(34,"<<5>>_{2n,2n,2n|3n,3n}");
1671  fIntFlowProfiles->Add(fIntFlowCorrelationsAllPro);
1672  // when particle weights are used some extra correlations appear:
1673  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) 
1674  {
1675   TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
1676   intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
1677   fIntFlowExtraCorrelationsPro = new TProfile(intFlowExtraCorrelationsProName.Data(),"Average extra correlations for all events",100,0,100,"s");
1678   fIntFlowExtraCorrelationsPro->SetTickLength(-0.01,"Y");
1679   fIntFlowExtraCorrelationsPro->SetMarkerStyle(25);
1680   fIntFlowExtraCorrelationsPro->SetLabelSize(0.03);
1681   fIntFlowExtraCorrelationsPro->SetLabelOffset(0.01,"Y");
1682   // extra 2-p correlations:
1683   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(1,"<<w1^3 w2 cos(n*(phi1-phi2))>>");
1684   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(2,"<<w1 w2 w3^2 cos(n*(phi1-phi2))>>");
1685   fIntFlowProfiles->Add(fIntFlowExtraCorrelationsPro);
1686  } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
1687  // average product of correlations <2>, <4>, <6> and <8>:  
1688  TString productFlag[6] = {"<<2><4>>","<<2><6>>","<<2><8>>","<<4><6>>","<<4><8>>","<<6><8>>"};
1689  TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
1690  intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
1691  fIntFlowProductOfCorrelationsPro = new TProfile(intFlowProductOfCorrelationsProName.Data(),"Average products of correlations",6,0,6);
1692  fIntFlowProductOfCorrelationsPro->SetTickLength(-0.01,"Y");
1693  fIntFlowProductOfCorrelationsPro->SetMarkerStyle(25); 
1694  fIntFlowProductOfCorrelationsPro->SetLabelSize(0.05);
1695  fIntFlowProductOfCorrelationsPro->SetLabelOffset(0.01,"Y");
1696  for(Int_t b=0;b<6;b++)
1697  {
1698   (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(b+1,productFlag[b].Data());
1699  }
1700  fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsPro); 
1701  // average product of correlations <2>, <4>, <6> and <8> versus multiplicity
1702  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
1703  if(fCalculateCumulantsVsM)
1704  {
1705   TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
1706   intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
1707   for(Int_t pi=0;pi<6;pi++)
1708   { 
1709    fIntFlowProductOfCorrelationsVsMPro[pi] = new TProfile(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data()),
1710                                                           Form("%s versus multiplicity",productFlag[pi].Data()),
1711                                                           fnBinsMult,fMinMult,fMaxMult);             
1712    fIntFlowProductOfCorrelationsVsMPro[pi]->GetXaxis()->SetTitle("M");
1713    fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsVsMPro[pi]);
1714   } // end of for(Int_t pi=0;pi<6;pi++)
1715  } // end of if(fCalculateCumulantsVsM) 
1716  // average product of correction terms for NUA:  
1717  TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
1718  intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
1719  fIntFlowProductOfCorrectionTermsForNUAPro = new TProfile(intFlowProductOfCorrectionTermsForNUAProName.Data(),"Average products of correction terms for NUA",27,0,27);
1720  fIntFlowProductOfCorrectionTermsForNUAPro->SetTickLength(-0.01,"Y");
1721  fIntFlowProductOfCorrectionTermsForNUAPro->SetMarkerStyle(25); 
1722  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelSize(0.05);
1723  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelOffset(0.01,"Y");
1724  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(1,"<<2><cos(#phi)>>");
1725  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(2,"<<2><sin(#phi)>>");
1726  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(3,"<<cos(#phi)><sin(#phi)>>");
1727  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
1728  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
1729  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1730  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1731  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
1732  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
1733  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
1734  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
1735  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1736  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1737  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
1738  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1739  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1740  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1741  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
1742  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1743  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1744  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1745  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
1746  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1747  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1748  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1749  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1750  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
1751  fIntFlowProfiles->Add(fIntFlowProductOfCorrectionTermsForNUAPro);
1752  // average correction terms for non-uniform acceptance (with wrong errors!):
1753  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1754  {
1755   TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
1756   intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
1757   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()),4,0,4,"s");
1758   fIntFlowCorrectionTermsForNUAPro[sc]->SetTickLength(-0.01,"Y");
1759   fIntFlowCorrectionTermsForNUAPro[sc]->SetMarkerStyle(25);
1760   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelSize(0.03);
1761   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelOffset(0.01,"Y");
1762   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(1,Form("#LT#LT%s(n(phi1))#GT#GT",sinCosFlag[sc].Data()));
1763   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(2,Form("#LT#LT%s(n(phi1+phi2))#GT#GT",sinCosFlag[sc].Data()));  
1764   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(3,Form("#LT#LT%s(n(phi1-phi2-phi3))#GT#GT",sinCosFlag[sc].Data()));  
1765   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(4,Form("#LT#LT%s(n(2phi1-phi2))#GT#GT",sinCosFlag[sc].Data()));  
1766   fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAPro[sc]);
1767   // versus multiplicity:
1768   if(fCalculateCumulantsVsM)
1769   {
1770    TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
1771    for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
1772    {
1773     TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
1774     intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
1775     fIntFlowCorrectionTermsForNUAVsMPro[sc][ci] = new TProfile(Form("%s: #LT#LT%s%s#GT#GT",intFlowCorrectionTermsForNUAVsMProName.Data(),sinCosFlag[sc].Data(),correctionTermFlag[ci].Data()),Form("#LT#LT%s%s#GT#GT vs M",sinCosFlag[sc].Data(),correctionTermFlag[ci].Data()),fnBinsMult,fMinMult,fMaxMult,"s");
1776     fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAVsMPro[sc][ci]);
1777    }
1778   } // end of if(fCalculateCumulantsVsM)
1779  } // end of for(Int_t sc=0;sc<2;sc++) 
1780  
1781  // d) Book histograms holding the final results:
1782  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!):
1783  TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
1784  intFlowCorrelationsHistName += fAnalysisLabel->Data();
1785  fIntFlowCorrelationsHist = new TH1D(intFlowCorrelationsHistName.Data(),"Average correlations for all events",4,0,4);
1786  fIntFlowCorrelationsHist->SetTickLength(-0.01,"Y");
1787  fIntFlowCorrelationsHist->SetMarkerStyle(25);
1788  fIntFlowCorrelationsHist->SetLabelSize(0.06);
1789  fIntFlowCorrelationsHist->SetLabelOffset(0.01,"Y");
1790  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(1,"<<2>>");
1791  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(2,"<<4>>");
1792  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(3,"<<6>>");
1793  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(4,"<<8>>");
1794  fIntFlowResults->Add(fIntFlowCorrelationsHist);
1795  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!) vs M:
1796  if(fCalculateCumulantsVsM)
1797  {
1798   for(Int_t ci=0;ci<4;ci++) // correlation index
1799   {
1800    TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
1801    intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
1802    fIntFlowCorrelationsVsMHist[ci] = new TH1D(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data()),
1803                                               Form("%s vs multiplicity",correlationFlag[ci].Data()),
1804                                               fnBinsMult,fMinMult,fMaxMult);                                            
1805    fIntFlowCorrelationsVsMHist[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
1806    fIntFlowCorrelationsVsMHist[ci]->GetXaxis()->SetTitle("M");
1807    fIntFlowResults->Add(fIntFlowCorrelationsVsMHist[ci]);
1808   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
1809  } // end of if(fCalculateCumulantsVsM) 
1810  // average all correlations for all events (with correct errors!):
1811  TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
1812  intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
1813  fIntFlowCorrelationsAllHist = new TH1D(intFlowCorrelationsAllHistName.Data(),"Average correlations for all events",34,0,34);
1814  fIntFlowCorrelationsAllHist->SetTickLength(-0.01,"Y");
1815  fIntFlowCorrelationsAllHist->SetMarkerStyle(25);
1816  fIntFlowCorrelationsAllHist->SetLabelSize(0.03);
1817  fIntFlowCorrelationsAllHist->SetLabelOffset(0.01,"Y");
1818  // 2-p correlations:
1819  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1820  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1821  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1822  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1823  // 3-p correlations:
1824  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1825  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1826  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1827  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1828  // 4-p correlations:
1829  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1830  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1831  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1832  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1833  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1834  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1835  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1836  // 5-p correlations:
1837  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1838  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1839  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1840  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1841  // 6-p correlations:
1842  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1843  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1844  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1845  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1846  // 7-p correlations:  
1847  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1848  // 8-p correlations:
1849  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1850  fIntFlowResults->Add(fIntFlowCorrelationsAllHist);
1851  // average correction terms for non-uniform acceptance (with correct errors!):
1852  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1853  {
1854   TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
1855   intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
1856   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()),4,0,4);
1857   fIntFlowCorrectionTermsForNUAHist[sc]->SetTickLength(-0.01,"Y");
1858   fIntFlowCorrectionTermsForNUAHist[sc]->SetMarkerStyle(25);
1859   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelSize(0.03);
1860   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelOffset(0.01,"Y");
1861   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(1,Form("#LT#LT%s(n(#phi_{1}))#GT#GT",sinCosFlag[sc].Data()));
1862   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(2,Form("#LT#LT%s(n(phi1+phi2))#GT#GT",sinCosFlag[sc].Data()));  
1863   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(3,Form("#LT#LT%s(n(phi1-phi2-phi3))#GT#GT",sinCosFlag[sc].Data()));  
1864   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(4,Form("#LT#LT%s(n(2phi1-phi2))#GT#GT",sinCosFlag[sc].Data()));   
1865   fIntFlowResults->Add(fIntFlowCorrectionTermsForNUAHist[sc]);
1866  } // end of for(Int_t sc=0;sc<2;sc++) 
1867  // covariances (multiplied with weight dependent prefactor):
1868  TString intFlowCovariancesName = "fIntFlowCovariances";
1869  intFlowCovariancesName += fAnalysisLabel->Data();
1870  fIntFlowCovariances = new TH1D(intFlowCovariancesName.Data(),"Covariances (multiplied with weight dependent prefactor)",6,0,6);
1871  fIntFlowCovariances->SetLabelSize(0.04);
1872  fIntFlowCovariances->SetMarkerStyle(25);
1873  (fIntFlowCovariances->GetXaxis())->SetBinLabel(1,"Cov(<2>,<4>)");
1874  (fIntFlowCovariances->GetXaxis())->SetBinLabel(2,"Cov(<2>,<6>)");
1875  (fIntFlowCovariances->GetXaxis())->SetBinLabel(3,"Cov(<2>,<8>)");
1876  (fIntFlowCovariances->GetXaxis())->SetBinLabel(4,"Cov(<4>,<6>)");
1877  (fIntFlowCovariances->GetXaxis())->SetBinLabel(5,"Cov(<4>,<8>)");
1878  (fIntFlowCovariances->GetXaxis())->SetBinLabel(6,"Cov(<6>,<8>)");  
1879  fIntFlowResults->Add(fIntFlowCovariances);
1880  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
1881  TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
1882  intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
1883  for(Int_t power=0;power<2;power++)
1884  {
1885   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);
1886   fIntFlowSumOfEventWeights[power]->SetLabelSize(0.05);
1887   fIntFlowSumOfEventWeights[power]->SetMarkerStyle(25);
1888   if(power == 0)
1889   {
1890    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}");
1891    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}");
1892    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}");
1893    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}");
1894   } else if (power == 1) 
1895     {
1896      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}^{2}");
1897      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}^{2}");
1898      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}^{2}");
1899      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}^{2}");
1900     }
1901   fIntFlowResults->Add(fIntFlowSumOfEventWeights[power]);
1902  } 
1903  // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
1904  TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
1905  intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
1906  fIntFlowSumOfProductOfEventWeights = new TH1D(intFlowSumOfProductOfEventWeightsName.Data(),"Sum of product of event weights for correlations",6,0,6);
1907  fIntFlowSumOfProductOfEventWeights->SetLabelSize(0.05);
1908  fIntFlowSumOfProductOfEventWeights->SetMarkerStyle(25);
1909  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<4>}");
1910  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<6>}");
1911  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<2>} w_{<8>}");
1912  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<4>} w_{<6>}");
1913  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(5,"#sum_{i=1}^{N} w_{<4>} w_{<8>}");
1914  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(6,"#sum_{i=1}^{N} w_{<6>} w_{<8>}");
1915  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeights);
1916  // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
1917  // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
1918  if(fCalculateCumulantsVsM)
1919  {
1920   TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
1921   intFlowCovariancesVsMName += fAnalysisLabel->Data();
1922   TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
1923   for(Int_t ci=0;ci<6;ci++)
1924   {
1925    fIntFlowCovariancesVsM[ci] = new TH1D(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data()),
1926                                          Form("%s vs multiplicity",covarianceFlag[ci].Data()),
1927                                          fnBinsMult,fMinMult,fMaxMult);
1928    fIntFlowCovariancesVsM[ci]->GetYaxis()->SetTitle(covarianceFlag[ci].Data());
1929    fIntFlowCovariancesVsM[ci]->GetXaxis()->SetTitle("M");
1930    fIntFlowResults->Add(fIntFlowCovariancesVsM[ci]);
1931   }
1932  } // end of if(fCalculateCumulantsVsM) 
1933  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
1934  // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
1935  if(fCalculateCumulantsVsM)
1936  {
1937   TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
1938   intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
1939   TString sumFlag[2][4] = {{"#sum_{i=1}^{N} w_{<2>}","#sum_{i=1}^{N} w_{<4>}","#sum_{i=1}^{N} w_{<6>}","#sum_{i=1}^{N} w_{<8>}"},
1940                            {"#sum_{i=1}^{N} w_{<2>}^{2}","#sum_{i=1}^{N} w_{<4>}^{2}","#sum_{i=1}^{N} w_{<6>}^{2}","#sum_{i=1}^{N} w_{<8>}^{2}"}};
1941   for(Int_t si=0;si<4;si++)
1942   {
1943    for(Int_t power=0;power<2;power++)
1944    {
1945     fIntFlowSumOfEventWeightsVsM[si][power] = new TH1D(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data()),
1946                                                        Form("%s vs multiplicity",sumFlag[power][si].Data()),
1947                                                        fnBinsMult,fMinMult,fMaxMult);    
1948     fIntFlowSumOfEventWeightsVsM[si][power]->GetYaxis()->SetTitle(sumFlag[power][si].Data());  
1949     fIntFlowSumOfEventWeightsVsM[si][power]->GetXaxis()->SetTitle("M");  
1950     fIntFlowResults->Add(fIntFlowSumOfEventWeightsVsM[si][power]);
1951    } // end of for(Int_t power=0;power<2;power++)
1952   } // end of for(Int_t si=0;si<4;si++)   
1953  } // end of if(fCalculateCumulantsVsM)
1954  // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
1955  // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
1956  //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
1957  if(fCalculateCumulantsVsM)
1958  {
1959   TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
1960   intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
1961   TString sopowFlag[6] = {"#sum_{i=1}^{N} w_{<2>} w_{<4>}","#sum_{i=1}^{N} w_{<2>} w_{<6>}","#sum_{i=1}^{N} w_{<2>} w_{<8>}",
1962                           "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
1963   for(Int_t pi=0;pi<6;pi++)
1964   {
1965    fIntFlowSumOfProductOfEventWeightsVsM[pi] = new TH1D(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data()),
1966                                                         Form("%s versus multiplicity",sopowFlag[pi].Data()),
1967                                                         fnBinsMult,fMinMult,fMaxMult); 
1968    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetXaxis()->SetTitle("M");
1969    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetYaxis()->SetTitle(sopowFlag[pi].Data()); 
1970    fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsVsM[pi]);
1971   } // end of for(Int_t pi=0;pi<6;pi++) 
1972  } // end of if(fCalculateCumulantsVsM)
1973  // covariances of NUA terms (multiplied with weight dependent prefactor):
1974  TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
1975  intFlowCovariancesNUAName += fAnalysisLabel->Data();
1976  fIntFlowCovariancesNUA = new TH1D(intFlowCovariancesNUAName.Data(),"Covariances for NUA (multiplied with weight dependent prefactor)",27,0,27);
1977  fIntFlowCovariancesNUA->SetLabelSize(0.04);
1978  fIntFlowCovariancesNUA->SetMarkerStyle(25);
1979  fIntFlowCovariancesNUA->GetXaxis()->SetLabelSize(0.02);
1980  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(1,"Cov(<2>,<cos(#phi)>");
1981  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(2,"Cov(<2>,<sin(#phi)>)");
1982  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(3,"Cov(<cos(#phi)>,<sin(#phi)>)");
1983  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
1984  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
1985  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1986  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1987  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
1988  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
1989  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
1990  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
1991  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1992  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1993  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
1994  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1995  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1996  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1997  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
1998  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1999  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2000  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2001  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
2002  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2003  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2004  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2005  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2006  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
2007  fIntFlowResults->Add(fIntFlowCovariancesNUA);
2008  // sum of linear and quadratic event weights for NUA terms:
2009  TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
2010  intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
2011  for(Int_t sc=0;sc<2;sc++)
2012  {
2013   for(Int_t power=0;power<2;power++)
2014   {
2015    fIntFlowSumOfEventWeightsNUA[sc][power] = new TH1D(Form("%s: %s, %s",intFlowSumOfEventWeightsNUAName.Data(),powerFlag[power].Data(),sinCosFlag[sc].Data()),Form("Sum of %s event weights for NUA %s terms",powerFlag[power].Data(),sinCosFlag[sc].Data()),4,0,4); // to be improved - 4
2016    fIntFlowSumOfEventWeightsNUA[sc][power]->SetLabelSize(0.05);
2017    fIntFlowSumOfEventWeightsNUA[sc][power]->SetMarkerStyle(25);
2018    if(power == 0)
2019    {
2020     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}",sinCosFlag[sc].Data()));
2021     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}",sinCosFlag[sc].Data()));
2022     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}",sinCosFlag[sc].Data()));   
2023     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(4,Form("#sum_{i=1}^{N} w_{<%s(2#phi_{1}-#phi_{2})>}",sinCosFlag[sc].Data()));
2024    } else if(power == 1) 
2025      {
2026       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}^{2}",sinCosFlag[sc].Data()));
2027       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}^{2}",sinCosFlag[sc].Data()));
2028       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}^{2}",sinCosFlag[sc].Data()));
2029       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(4,Form("#sum_{i=1}^{N} w_{<%s(2#phi_{1}-#phi_{2})>}^{2}",sinCosFlag[sc].Data()));
2030      }
2031    fIntFlowResults->Add(fIntFlowSumOfEventWeightsNUA[sc][power]);
2032   }
2033  }  
2034  // sum of products of event weights for NUA terms:  
2035  TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
2036  intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
2037  fIntFlowSumOfProductOfEventWeightsNUA = new TH1D(intFlowSumOfProductOfEventWeightsNUAName.Data(),"Sum of product of event weights for NUA terms",27,0,27);
2038  fIntFlowSumOfProductOfEventWeightsNUA->SetLabelSize(0.05);
2039  fIntFlowSumOfProductOfEventWeightsNUA->SetMarkerStyle(25);
2040  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<cos(#phi)>}");
2041  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<sin(#phi)>}");
2042  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<cos(#phi)>} w_{<sin(#phi)>}");
2043  // ....
2044  // to be improved - add labels for remaining bins
2045  // ....
2046  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsNUA);
2047  // Final results for reference Q-cumulants:
2048  TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
2049  TString intFlowQcumulantsName = "fIntFlowQcumulants";
2050  intFlowQcumulantsName += fAnalysisLabel->Data();
2051  fIntFlowQcumulants = new TH1D(intFlowQcumulantsName.Data(),"Reference Q-cumulants",4,0,4);
2052  if(fPropagateErrorAlsoFromNIT)
2053  {
2054   fIntFlowQcumulants->SetTitle("Reference Q-cumulants (error from non-isotropic terms also propagated)");
2055  }
2056  fIntFlowQcumulants->SetLabelSize(0.05);
2057  fIntFlowQcumulants->SetMarkerStyle(25);
2058  for(Int_t b=0;b<4;b++)
2059  {
2060   (fIntFlowQcumulants->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2061  } 
2062  fIntFlowResults->Add(fIntFlowQcumulants);
2063  // Final results for reference Q-cumulants rebinned in M: 
2064  if(fCalculateCumulantsVsM)
2065  {
2066   TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
2067   intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
2068   fIntFlowQcumulantsRebinnedInM = new TH1D(intFlowQcumulantsRebinnedInMName.Data(),"Reference Q-cumulants rebinned in M",4,0,4);
2069   fIntFlowQcumulantsRebinnedInM->SetLabelSize(0.05);
2070   fIntFlowQcumulantsRebinnedInM->SetMarkerStyle(25);
2071   for(Int_t b=0;b<4;b++)
2072   {
2073    (fIntFlowQcumulantsRebinnedInM->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2074   } 
2075   fIntFlowResults->Add(fIntFlowQcumulantsRebinnedInM);
2076  } // end of if(fCalculateCumulantsVsM) 
2077  // Ratio between error squared: with/without non-isotropic terms:
2078  TString intFlowQcumulantsErrorSquaredRatioName = "fIntFlowQcumulantsErrorSquaredRatio";
2079  intFlowQcumulantsErrorSquaredRatioName += fAnalysisLabel->Data();
2080  fIntFlowQcumulantsErrorSquaredRatio = new TH1D(intFlowQcumulantsErrorSquaredRatioName.Data(),"Error squared of reference Q-cumulants: #frac{with NUA terms}{without NUA terms}",4,0,4);
2081  fIntFlowQcumulantsErrorSquaredRatio->SetLabelSize(0.05);
2082  fIntFlowQcumulantsErrorSquaredRatio->SetMarkerStyle(25);
2083  for(Int_t b=0;b<4;b++)
2084  {
2085   (fIntFlowQcumulantsErrorSquaredRatio->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2086  } 
2087  fIntFlowResults->Add(fIntFlowQcumulantsErrorSquaredRatio);
2088  // final results for integrated Q-cumulants versus multiplicity:
2089  if(fCalculateCumulantsVsM)
2090  {
2091   TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
2092   intFlowQcumulantsVsMName += fAnalysisLabel->Data();
2093   for(Int_t co=0;co<4;co++) // cumulant order
2094   {
2095    fIntFlowQcumulantsVsM[co] = new TH1D(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data()),
2096                                         Form("%s vs multipicity",cumulantFlag[co].Data()),
2097                                         fnBinsMult,fMinMult,fMaxMult);
2098    fIntFlowQcumulantsVsM[co]->GetXaxis()->SetTitle("M");                                     
2099    fIntFlowQcumulantsVsM[co]->GetYaxis()->SetTitle(cumulantFlag[co].Data());  
2100    fIntFlowResults->Add(fIntFlowQcumulantsVsM[co]);                                    
2101   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2102  } // end of if(fCalculateCumulantsVsM)
2103  // final integrated flow estimates from Q-cumulants:
2104  TString flowFlag[4] = {Form("v_{%d}{2,QC}",fHarmonic),Form("v_{%d}{4,QC}",fHarmonic),Form("v_{%d}{6,QC}",fHarmonic),Form("v_{%d}{8,QC}",fHarmonic)};
2105  TString intFlowName = "fIntFlow";
2106  intFlowName += fAnalysisLabel->Data();  
2107  // integrated flow from Q-cumulants:
2108  fIntFlow = new TH1D(intFlowName.Data(),"Reference flow estimates from Q-cumulants",4,0,4);
2109  fIntFlow->SetLabelSize(0.05);
2110  fIntFlow->SetMarkerStyle(25);
2111  for(Int_t b=0;b<4;b++)
2112  {
2113   (fIntFlow->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2114  }
2115  fIntFlowResults->Add(fIntFlow); 
2116  // Reference flow vs M rebinned in one huge bin:
2117  if(fCalculateCumulantsVsM)
2118  { 
2119   TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
2120   intFlowRebinnedInMName += fAnalysisLabel->Data();  
2121   fIntFlowRebinnedInM = new TH1D(intFlowRebinnedInMName.Data(),"Reference flow estimates from Q-cumulants (rebinned in M)",4,0,4);
2122   fIntFlowRebinnedInM->SetLabelSize(0.05);
2123   fIntFlowRebinnedInM->SetMarkerStyle(25);
2124   for(Int_t b=0;b<4;b++)
2125   {
2126    (fIntFlowRebinnedInM->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2127   }
2128   fIntFlowResults->Add(fIntFlowRebinnedInM); 
2129  } 
2130  // integrated flow from Q-cumulants: versus multiplicity:
2131  if(fCalculateCumulantsVsM)
2132  {
2133   TString intFlowVsMName = "fIntFlowVsM";
2134   intFlowVsMName += fAnalysisLabel->Data();
2135   for(Int_t co=0;co<4;co++) // cumulant order
2136   {
2137    fIntFlowVsM[co] = new TH1D(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data()),
2138                               Form("%s vs multipicity",flowFlag[co].Data()),
2139                               fnBinsMult,fMinMult,fMaxMult);
2140    fIntFlowVsM[co]->GetXaxis()->SetTitle("M");                                     
2141    fIntFlowVsM[co]->GetYaxis()->SetTitle(flowFlag[co].Data());  
2142    fIntFlowResults->Add(fIntFlowVsM[co]);                                    
2143   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2144  } // end of if(fCalculateCumulantsVsM)
2145  // quantifying detector effects effects to correlations:
2146  TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
2147  intFlowDetectorBiasName += fAnalysisLabel->Data();  
2148  fIntFlowDetectorBias = new TH1D(intFlowDetectorBiasName.Data(),"Quantifying detector bias",4,0,4);
2149  fIntFlowDetectorBias->SetLabelSize(0.05);
2150  fIntFlowDetectorBias->SetMarkerStyle(25);
2151  for(Int_t ci=0;ci<4;ci++)
2152  {  
2153   (fIntFlowDetectorBias->GetXaxis())->SetBinLabel(ci+1,Form("#frac{corrected}{measured} %s",cumulantFlag[ci].Data()));
2154  }
2155  fIntFlowResults->Add(fIntFlowDetectorBias); 
2156  // quantifying detector effects to correlations versus multiplicity:
2157  if(fCalculateCumulantsVsM)
2158  {
2159   TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
2160   intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
2161   for(Int_t ci=0;ci<4;ci++) // correlation index
2162   {
2163    fIntFlowDetectorBiasVsM[ci] = new TH1D(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data()),
2164                                           Form("Quantifying detector bias for %s vs multipicity",cumulantFlag[ci].Data()),
2165                                           fnBinsMult,fMinMult,fMaxMult);
2166    fIntFlowDetectorBiasVsM[ci]->GetXaxis()->SetTitle("M");                                     
2167    fIntFlowDetectorBiasVsM[ci]->GetYaxis()->SetTitle("#frac{corrected}{measured}");  
2168    fIntFlowResults->Add(fIntFlowDetectorBiasVsM[ci]);                                    
2169   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2170  } // end of if(fCalculateCumulantsVsM)
2171  
2172  /* // to be improved (removed):
2173   // final average weighted multi-particle correlations for all events calculated from Q-vectors
2174   fQCorrelations[1] = new TProfile("Weighted correlations","final average multi-particle correlations from weighted Q-vectors",200,0,200,"s");
2175   fQCorrelations[1]->SetTickLength(-0.01,"Y");
2176   fQCorrelations[1]->SetMarkerStyle(25);
2177   fQCorrelations[1]->SetLabelSize(0.03);
2178   fQCorrelations[1]->SetLabelOffset(0.01,"Y");
2179   // 2-particle correlations:
2180   (fQCorrelations[1]->GetXaxis())->SetBinLabel(1,"<w_{1}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
2181   (fQCorrelations[1]->GetXaxis())->SetBinLabel(2,"<w_{1}^{2}w_{2}^{2}cos(2n(#phi_{1}-#phi_{2}))>");
2182   (fQCorrelations[1]->GetXaxis())->SetBinLabel(3,"<w_{1}^{3}w_{2}^{3}cos(3n(#phi_{1}-#phi_{2}))>");
2183   (fQCorrelations[1]->GetXaxis())->SetBinLabel(4,"<w_{1}^{4}w_{2}^{4}cos(4n(#phi_{1}-#phi_{2}))>");
2184   (fQCorrelations[1]->GetXaxis())->SetBinLabel(5,"<w_{1}^{3}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
2185   (fQCorrelations[1]->GetXaxis())->SetBinLabel(6,"<w_{1}^{2}w_{2}w_{3}cos(n(#phi_{1}-#phi_{2}))>");
2186   // 3-particle correlations:
2187   (fQCorrelations[1]->GetXaxis())->SetBinLabel(21,"<w_{1}w_{2}w_{3}^{2}cos(n(2#phi_{1}-#phi_{2}-#phi_{3}))>");
2188   // 4-particle correlations:
2189   (fQCorrelations[1]->GetXaxis())->SetBinLabel(41,"<w_{1}w_{2}w_{3}w_{4}cos(n(#phi_{1}+#phi_{2}-#phi_{3}-#phi_{4}))>");
2190   // add fQCorrelations[1] to the list fIntFlowList:
2191   fIntFlowList->Add(fQCorrelations[1]); 
2192  */
2193   
2194 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
2195
2196
2197 //================================================================================================================================
2198
2199
2200 void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2201 {
2202  // Initialize arrays of all objects relevant for calculations with nested loops.
2203  
2204  // integrated flow:
2205  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2206  {
2207   fIntFlowDirectCorrectionTermsForNUA[sc] = NULL;
2208  } 
2209
2210  // differential flow:  
2211  // correlations:
2212  for(Int_t t=0;t<2;t++) // type: RP or POI
2213  { 
2214   for(Int_t pe=0;pe<2;pe++) // pt or eta
2215   {
2216    for(Int_t ci=0;ci<4;ci++) // correlation index
2217    {
2218     fDiffFlowDirectCorrelations[t][pe][ci] = NULL;
2219    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
2220   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2221  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2222  // correction terms for non-uniform acceptance:
2223  for(Int_t t=0;t<2;t++) // type: RP or POI
2224  { 
2225   for(Int_t pe=0;pe<2;pe++) // pt or eta
2226   {
2227    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2228    {
2229     for(Int_t cti=0;cti<9;cti++) // correction term index
2230     {
2231      fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] = NULL;
2232     }   
2233    }
2234   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2235  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2236
2237
2238 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2239
2240
2241 //================================================================================================================================
2242
2243
2244 void AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2245 {
2246  // Book all objects relevant for calculations with nested loops.
2247  
2248  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
2249  TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
2250  TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
2251  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
2252  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
2253  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
2254
2255  TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
2256  evaluateNestedLoopsName += fAnalysisLabel->Data();
2257  fEvaluateNestedLoops = new TProfile(evaluateNestedLoopsName.Data(),"Flags for nested loops",4,0,4);
2258  fEvaluateNestedLoops->SetLabelSize(0.03);
2259  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(1,"fEvaluateIntFlowNestedLoops");
2260  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(2,"fEvaluateDiffFlowNestedLoops");
2261  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(3,"fCrossCheckInPtBinNo");
2262  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(4,"fCrossCheckInEtaBinNo");
2263  fEvaluateNestedLoops->Fill(0.5,(Int_t)fEvaluateIntFlowNestedLoops);
2264  fEvaluateNestedLoops->Fill(1.5,(Int_t)fEvaluateDiffFlowNestedLoops);
2265  fEvaluateNestedLoops->Fill(2.5,fCrossCheckInPtBinNo);
2266  fEvaluateNestedLoops->Fill(3.5,fCrossCheckInEtaBinNo);
2267  fNestedLoopsList->Add(fEvaluateNestedLoops);
2268  // nested loops for integrated flow:
2269  if(fEvaluateIntFlowNestedLoops)
2270  {
2271   // correlations:
2272   TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
2273   intFlowDirectCorrelationsName += fAnalysisLabel->Data();
2274   fIntFlowDirectCorrelations = new TProfile(intFlowDirectCorrelationsName.Data(),"Multiparticle correlations calculated with nested loops (for int. flow)",34,0,34,"s");
2275   fNestedLoopsList->Add(fIntFlowDirectCorrelations);
2276   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
2277   {
2278    TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
2279    intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
2280    fIntFlowExtraDirectCorrelations = new TProfile(intFlowExtraDirectCorrelationsName.Data(),"Extra multiparticle correlations calculated with nested loops (for int. flow)",100,0,100,"s");
2281    fNestedLoopsList->Add(fIntFlowExtraDirectCorrelations);  
2282   } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
2283   // correction terms for non-uniform acceptance:
2284   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2285   {
2286    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
2287    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2288    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");
2289    fNestedLoopsList->Add(fIntFlowDirectCorrectionTermsForNUA[sc]);
2290   } // end of for(Int_t sc=0;sc<2;sc++) 
2291  } // end of if(fEvaluateIntFlowNestedLoops)
2292  
2293  // nested loops for differential flow: 
2294  if(fEvaluateDiffFlowNestedLoops)
2295  {
2296   // reduced correlations:
2297   TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
2298   diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
2299   for(Int_t t=0;t<2;t++) // type: RP or POI
2300   { 
2301    for(Int_t pe=0;pe<2;pe++) // pt or eta
2302    {
2303     for(Int_t rci=0;rci<4;rci++) // reduced correlation index
2304     {
2305      // reduced correlations:
2306      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");
2307      fDiffFlowDirectCorrelations[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
2308      fNestedLoopsList->Add(fDiffFlowDirectCorrelations[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
2309     } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
2310    } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
2311   } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
2312   // correction terms for non-uniform acceptance:
2313   TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
2314   diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2315   for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
2316   { 
2317    for(Int_t pe=0;pe<2;pe++) // pt or eta
2318    {
2319     for(Int_t sc=0;sc<2;sc++) // sin or cos
2320     {
2321      for(Int_t cti=0;cti<9;cti++) // correction term index
2322      {
2323       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"); 
2324       fNestedLoopsList->Add(fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]);
2325      }
2326     }
2327    }
2328   } 
2329   // number of RPs and POIs in selected pt and eta bins for cross-checkings:
2330   TString noOfParticlesInBinName = "fNoOfParticlesInBin";
2331   fNoOfParticlesInBin = new TH1D(noOfParticlesInBinName.Data(),"Number of RPs and POIs in selected p_{T} and #eta bin",4,0,4);
2332   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(1,"# of RPs in p_{T} bin");
2333   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(2,"# of RPs in #eta bin");
2334   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(3,"# of POIs in p_{T} bin");
2335   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(4,"# of POIs in #eta bin");
2336   fNestedLoopsList->Add(fNoOfParticlesInBin);
2337  } // end of if(fEvaluateDiffFlowNestedLoops)
2338
2339 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2340
2341
2342 //================================================================================================================================
2343
2344
2345 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
2346 {
2347  // calculate all correlations needed for integrated flow
2348  
2349  // multiplicity:
2350  Double_t dMult = (*fSMpk)(0,0);
2351  
2352  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
2353  Double_t dReQ1n = (*fReQ)(0,0);
2354  Double_t dReQ2n = (*fReQ)(1,0);
2355  Double_t dReQ3n = (*fReQ)(2,0);
2356  Double_t dReQ4n = (*fReQ)(3,0);
2357  //Double_t dReQ5n = (*fReQ)(4,0);
2358  Double_t dReQ6n = (*fReQ)(5,0);
2359  Double_t dImQ1n = (*fImQ)(0,0);
2360  Double_t dImQ2n = (*fImQ)(1,0);
2361  Double_t dImQ3n = (*fImQ)(2,0);
2362  Double_t dImQ4n = (*fImQ)(3,0);
2363  //Double_t dImQ5n = (*fImQ)(4,0);
2364  Double_t dImQ6n = (*fImQ)(5,0);
2365   
2366  // real and imaginary parts of some expressions involving various combinations of Q-vectors evaluated in harmonics n, 2n, 3n and 4n:
2367  // (these expression appear in the Eqs. for the multi-particle correlations bellow)
2368  
2369  // Re[Q_{2n} Q_{n}^* Q_{n}^*]
2370  Double_t reQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dReQ2n + 2.*dReQ1n*dImQ1n*dImQ2n - pow(dImQ1n,2.)*dReQ2n; 
2371  
2372  // Im[Q_{2n} Q_{n}^* Q_{n}^*]
2373  //Double_t imQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dImQ2n-2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n; 
2374  
2375  // Re[Q_{n} Q_{n} Q_{2n}^*] = Re[Q_{2n} Q_{n}^* Q_{n}^*]
2376  Double_t reQ1nQ1nQ2nstar = reQ2nQ1nstarQ1nstar; 
2377  
2378  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
2379  Double_t reQ3nQ1nQ2nstarQ2nstar = (pow(dReQ2n,2.)-pow(dImQ2n,2.))*(dReQ3n*dReQ1n-dImQ3n*dImQ1n) 
2380                                  + 2.*dReQ2n*dImQ2n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
2381
2382  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]                                                                  
2383  //Double_t imQ3nQ1nQ2nstarQ2nstar = calculate and implement this (deleteMe)
2384   
2385  // Re[Q_{2n} Q_{2n} Q_{3n}^* Q_{1n}^*] = Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
2386  Double_t reQ2nQ2nQ3nstarQ1nstar = reQ3nQ1nQ2nstarQ2nstar;
2387   
2388  // Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
2389  Double_t reQ4nQ2nstarQ2nstar = pow(dReQ2n,2.)*dReQ4n+2.*dReQ2n*dImQ2n*dImQ4n-pow(dImQ2n,2.)*dReQ4n;
2390
2391  // Im[Q_{4n} Q_{2n}^* Q_{2n}^*]
2392  //Double_t imQ4nQ2nstarQ2nstar = calculate and implement this (deleteMe)
2393  
2394  // Re[Q_{2n} Q_{2n} Q_{4n}^*] =  Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
2395  Double_t reQ2nQ2nQ4nstar = reQ4nQ2nstarQ2nstar;
2396  
2397  // Re[Q_{4n} Q_{3n}^* Q_{n}^*]
2398  Double_t reQ4nQ3nstarQ1nstar = dReQ4n*(dReQ3n*dReQ1n-dImQ3n*dImQ1n)+dImQ4n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
2399  
2400  // Re[Q_{3n} Q_{n} Q_{4n}^*] = Re[Q_{4n} Q_{3n}^* Q_{n}^*]
2401  Double_t reQ3nQ1nQ4nstar = reQ4nQ3nstarQ1nstar;
2402  
2403  // Im[Q_{4n} Q_{3n}^* Q_{n}^*]
2404  //Double_t imQ4nQ3nstarQ1nstar = calculate and implement this (deleteMe)
2405
2406  // Re[Q_{3n} Q_{2n}^* Q_{n}^*]
2407  Double_t reQ3nQ2nstarQ1nstar = dReQ3n*dReQ2n*dReQ1n-dReQ3n*dImQ2n*dImQ1n+dImQ3n*dReQ2n*dImQ1n
2408                               + dImQ3n*dImQ2n*dReQ1n;
2409                               
2410  // Re[Q_{2n} Q_{n} Q_{3n}^*] = Re[Q_{3n} Q_{2n}^* Q_{n}^*]
2411  Double_t reQ2nQ1nQ3nstar = reQ3nQ2nstarQ1nstar;
2412  
2413  // Im[Q_{3n} Q_{2n}^* Q_{n}^*]
2414  //Double_t imQ3nQ2nstarQ1nstar; //calculate and implement this (deleteMe)
2415  
2416  // Re[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2417  Double_t reQ3nQ1nstarQ1nstarQ1nstar = dReQ3n*pow(dReQ1n,3)-3.*dReQ1n*dReQ3n*pow(dImQ1n,2)
2418                                      + 3.*dImQ1n*dImQ3n*pow(dReQ1n,2)-dImQ3n*pow(dImQ1n,3);
2419
2420  // Im[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2421  //Double_t imQ3nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2422  
2423  // |Q_{2n}|^2 |Q_{n}|^2
2424  Double_t dQ2nQ1nQ2nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
2425  
2426  // Re[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2427  Double_t reQ4nQ2nstarQ1nstarQ1nstar = (dReQ4n*dReQ2n+dImQ4n*dImQ2n)*(pow(dReQ1n,2)-pow(dImQ1n,2))
2428                                      + 2.*dReQ1n*dImQ1n*(dImQ4n*dReQ2n-dReQ4n*dImQ2n); 
2429  
2430  // Im[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2431  //Double_t imQ4nQ2nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2432  
2433  // Re[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*]
2434  Double_t reQ2nQ1nQ1nstarQ1nstarQ1nstar = (dReQ2n*dReQ1n-dImQ2n*dImQ1n)*(pow(dReQ1n,3)-3.*dReQ1n*pow(dImQ1n,2))
2435                                         + (dReQ2n*dImQ1n+dReQ1n*dImQ2n)*(3.*dImQ1n*pow(dReQ1n,2)-pow(dImQ1n,3));
2436
2437  // Im[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*] 
2438  //Double_t imQ2nQ1nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2439  
2440  // Re[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2441  Double_t reQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2442                                         * (dReQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) + 2.*dImQ2n*dReQ1n*dImQ1n);
2443
2444  // Im[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2445  //Double_t imQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2446  //                                       * (dImQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) - 2.*dReQ2n*dReQ1n*dImQ1n);
2447  
2448  // Re[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2449  Double_t reQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dReQ4n-6.*pow(dReQ1n,2.)*dReQ4n*pow(dImQ1n,2.)
2450                                             + pow(dImQ1n,4.)*dReQ4n+4.*pow(dReQ1n,3.)*dImQ1n*dImQ4n
2451                                             - 4.*pow(dImQ1n,3.)*dReQ1n*dImQ4n;
2452                                             
2453  // Im[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2454  //Double_t imQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dImQ4n-6.*pow(dReQ1n,2.)*dImQ4n*pow(dImQ1n,2.)
2455  //                                           + pow(dImQ1n,4.)*dImQ4n+4.*pow(dImQ1n,3.)*dReQ1n*dReQ4n
2456  //                                           - 4.*pow(dReQ1n,3.)*dImQ1n*dReQ4n;
2457  
2458  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2459  Double_t reQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2460                                         * (dReQ1n*dReQ2n*dReQ3n-dReQ3n*dImQ1n*dImQ2n+dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n);
2461  
2462  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2463  //Double_t imQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2464  //                                       * (-dReQ2n*dReQ3n*dImQ1n-dReQ1n*dReQ3n*dImQ2n+dReQ1n*dReQ2n*dImQ3n-dImQ1n*dImQ2n*dImQ3n);
2465  
2466  
2467  // Re[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2468  Double_t reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)*dReQ2n-2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2469                                                + dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n-pow(dImQ1n,2.)*dImQ2n)
2470                                                * (pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2471                                                - dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n+pow(dImQ1n,2.)*dImQ2n);
2472  
2473  // Im[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2474  //Double_t imQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = 2.*(pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2475  //                                              + 2.*dReQ1n*dImQ1n*dImQ2n)*(pow(dReQ1n,2.)*dImQ2n
2476  //                                              - 2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n);
2477  
2478  // Re[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2479  Double_t reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2480                                                * (pow(dReQ1n,3.)*dReQ3n-3.*dReQ1n*dReQ3n*pow(dImQ1n,2.)
2481                                                + 3.*pow(dReQ1n,2.)*dImQ1n*dImQ3n-pow(dImQ1n,3.)*dImQ3n);
2482   
2483  // Im[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                                                           
2484  //Double_t imQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2485  //                                              * (pow(dImQ1n,3.)*dReQ3n-3.*dImQ1n*dReQ3n*pow(dReQ1n,2.)
2486  //                                              - 3.*pow(dImQ1n,2.)*dReQ1n*dImQ3n+pow(dReQ1n,3.)*dImQ3n);
2487  
2488  // |Q_{2n}|^2 |Q_{n}|^4
2489  Double_t dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.);
2490  
2491  // Re[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2492  Double_t reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2493                                                   * (pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2494                                                   + 2.*dReQ1n*dImQ1n*dImQ2n);
2495                                                   
2496  // Im[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                  
2497  //Double_t imQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2498  //                                                 * (pow(dReQ1n,2.)*dImQ2n-dImQ2n*pow(dImQ1n,2.)
2499  //                                                 - 2.*dReQ1n*dReQ2n*dImQ1n);
2500  
2501   
2502  
2503        
2504  //                                        **************************************
2505  //                                        **** multi-particle correlations: ****
2506  //                                        **************************************
2507  //
2508  // Remark 1: All multi-particle correlations calculated with non-weighted Q-vectors are stored in 1D profile fIntFlowCorrelationsAllPro;
2509  // Remark 2: There is a special profile fIntFlowCorrelationsPro holding results ONLY for same harmonic's <<2>>, <<4>>, <<6>> and <<8>>;  
2510  // Remark 3: Binning of fIntFlowCorrelationsAllPro is organized as follows:
2511  // --------------------------------------------------------------------------------------------------------------------
2512  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
2513  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
2514  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
2515  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
2516  //  5th bin:           ----  EMPTY ----
2517  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
2518  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
2519  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2520  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
2521  // 10th bin:           ----  EMPTY ----
2522  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
2523  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
2524  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
2525  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2526  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
2527  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
2528  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
2529  // 18th bin:           ----  EMPTY ----
2530  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2531  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2532  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2533  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2534  // 23rd bin:           ----  EMPTY ----
2535  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2536  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2537  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2538  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2539  // 28th bin:           ----  EMPTY ----
2540  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2541  // 30th bin:           ----  EMPTY ----
2542  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2543  // 32nd bin:           ----  EMPTY ----
2544  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
2545  // 34th bin: <5>_{2n,2n,2n|3n,3n} = five2n2n2n3n3n = <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))> 
2546  // --------------------------------------------------------------------------------------------------------------------
2547     
2548  // 2-particle:
2549  Double_t two1n1n = 0.; // <cos(n*(phi1-phi2))>
2550  Double_t two2n2n = 0.; // <cos(2n*(phi1-phi2))>
2551  Double_t two3n3n = 0.; // <cos(3n*(phi1-phi2))>
2552  Double_t two4n4n = 0.; // <cos(4n*(phi1-phi2))>
2553  
2554  if(dMult>1)
2555  {
2556   two1n1n = (pow(dReQ1n,2.)+pow(dImQ1n,2.)-dMult)/(dMult*(dMult-1.)); 
2557   two2n2n = (pow(dReQ2n,2.)+pow(dImQ2n,2.)-dMult)/(dMult*(dMult-1.)); 
2558   two3n3n = (pow(dReQ3n,2.)+pow(dImQ3n,2.)-dMult)/(dMult*(dMult-1.)); 
2559   two4n4n = (pow(dReQ4n,2.)+pow(dImQ4n,2.)-dMult)/(dMult*(dMult-1.)); 
2560   
2561   // average 2-particle correlations for single event: 
2562   fIntFlowCorrelationsAllEBE->SetBinContent(1,two1n1n);
2563   fIntFlowCorrelationsAllEBE->SetBinContent(2,two2n2n);
2564   fIntFlowCorrelationsAllEBE->SetBinContent(3,two3n3n);
2565   fIntFlowCorrelationsAllEBE->SetBinContent(4,two4n4n);
2566           
2567   // average 2-particle correlations for all events:      
2568   fIntFlowCorrelationsAllPro->Fill(0.5,two1n1n,dMult*(dMult-1.));  
2569   fIntFlowCorrelationsAllPro->Fill(1.5,two2n2n,dMult*(dMult-1.)); 
2570   fIntFlowCorrelationsAllPro->Fill(2.5,two3n3n,dMult*(dMult-1.)); 
2571   fIntFlowCorrelationsAllPro->Fill(3.5,two4n4n,dMult*(dMult-1.)); 
2572   
2573   // store separetately <2> (to be improved: do I really need this?)
2574   fIntFlowCorrelationsEBE->SetBinContent(1,two1n1n); // <2>
2575   
2576   // to be improved (this can be implemented better):
2577   Double_t mWeight2p = 0.;
2578   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2579   {
2580    mWeight2p = dMult*(dMult-1.);
2581   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2582     {
2583      mWeight2p = 1.;    
2584     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2585       {
2586        mWeight2p = dMult;           
2587       }
2588             
2589   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,mWeight2p); // eW_<2>
2590   fIntFlowCorrelationsPro->Fill(0.5,two1n1n,mWeight2p);
2591   fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1n*two1n1n,mWeight2p);
2592   if(fCalculateCumulantsVsM)
2593   {
2594    fIntFlowCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n,mWeight2p);
2595    fIntFlowSquaredCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n*two1n1n,mWeight2p);
2596   } 
2597   // distribution of <cos(n*(phi1-phi2))>:
2598   //f2pDistribution->Fill(two1n1n,dMult*(dMult-1.)); 
2599  } // end of if(dMult>1)
2600  
2601  // 3-particle:
2602  Double_t three2n1n1n = 0.; // <cos(n*(2.*phi1-phi2-phi3))>
2603  Double_t three3n2n1n = 0.; // <cos(n*(3.*phi1-2.*phi2-phi3))>
2604  Double_t three4n2n2n = 0.; // <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2605  Double_t three4n3n1n = 0.; // <cos(n*(4.*phi1-3.*phi2-phi3))>
2606  
2607  if(dMult>2)
2608  {
2609   three2n1n1n = (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2610               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
2611               / (dMult*(dMult-1.)*(dMult-2.));                     
2612   three3n2n1n = (reQ3nQ2nstarQ1nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2613               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2614               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2615               / (dMult*(dMult-1.)*(dMult-2.));
2616   three4n2n2n = (reQ4nQ2nstarQ2nstar-2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2617               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*dMult)
2618               / (dMult*(dMult-1.)*(dMult-2.)); 
2619   three4n3n1n = (reQ4nQ3nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2620               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
2621               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2622               / (dMult*(dMult-1.)*(dMult-2.)); 
2623               
2624   // average 3-particle correlations for single event: 
2625   fIntFlowCorrelationsAllEBE->SetBinContent(6,three2n1n1n);
2626   fIntFlowCorrelationsAllEBE->SetBinContent(7,three3n2n1n);
2627   fIntFlowCorrelationsAllEBE->SetBinContent(8,three4n2n2n);
2628   fIntFlowCorrelationsAllEBE->SetBinContent(9,three4n3n1n);
2629         
2630   // average 3-particle correlations for all events:                
2631   fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.)); 
2632   fIntFlowCorrelationsAllPro->Fill(6.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
2633   fIntFlowCorrelationsAllPro->Fill(7.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.)); 
2634   fIntFlowCorrelationsAllPro->Fill(8.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));    
2635  } // end of if(dMult>2)
2636  
2637  // 4-particle:
2638  Double_t four1n1n1n1n = 0.; // <cos(n*(phi1+phi2-phi3-phi4))>
2639  Double_t four2n2n2n2n = 0.; // <cos(2.*n*(phi1+phi2-phi3-phi4))>
2640  Double_t four2n1n2n1n = 0.; // <cos(n*(2.*phi1+phi2-2.*phi3-phi4))> 
2641  Double_t four3n1n1n1n = 0.; // <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2642  Double_t four4n2n1n1n = 0.; // <cos(n*(4.*phi1-2.*phi2-phi3-phi4))> 
2643  Double_t four3n1n2n2n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))> 
2644  Double_t four3n1n3n1n = 0.; // <cos(n*(3.*phi1+phi2-3.*phi3-phi4))>   
2645  
2646  if(dMult>3)
2647  {
2648   four1n1n1n1n = (2.*dMult*(dMult-3.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ1n,2.)
2649                + pow(dImQ1n,2.))-2.*reQ2nQ1nstarQ1nstar+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2650                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));     
2651   four2n2n2n2n = (2.*dMult*(dMult-3.)+pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ2n,2.)
2652                + pow(dImQ2n,2.))-2.*reQ4nQ2nstarQ2nstar+(pow(dReQ4n,2.)+pow(dImQ4n,2.)))
2653                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));
2654   four2n1n2n1n = (dQ2nQ1nQ2nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar-2.*reQ2nQ1nstarQ1nstar)
2655                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2656                - ((dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2657                + (dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2658                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2659                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2660   four3n1n1n1n = (reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar-3.*reQ2nQ1nstarQ1nstar)
2661                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2662                + (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2663                + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
2664                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2665   four4n2n1n1n = (reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar)
2666                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2667                - (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2668                - 3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2669                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2670                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2671   four3n1n2n2n = (reQ3nQ1nQ2nstarQ2nstar-reQ4nQ2nstarQ2nstar-reQ3nQ1nQ4nstar-2.*reQ3nQ2nstarQ1nstar)
2672                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2673                - (2.*reQ1nQ1nQ2nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2674                - 4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2675                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2676                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.)); 
2677   four3n1n3n1n = ((pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2678                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar)
2679                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2680                + ((pow(dReQ4n,2.)+pow(dImQ4n,2.))-(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2681                + (pow(dReQ2n,2.)+pow(dImQ2n,2.))-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2682                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2683                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2684                
2685   // average 4-particle correlations for single event: 
2686   fIntFlowCorrelationsAllEBE->SetBinContent(11,four1n1n1n1n);
2687   fIntFlowCorrelationsAllEBE->SetBinContent(12,four2n1n2n1n);
2688   fIntFlowCorrelationsAllEBE->SetBinContent(13,four2n2n2n2n);
2689   fIntFlowCorrelationsAllEBE->SetBinContent(14,four3n1n1n1n);
2690   fIntFlowCorrelationsAllEBE->SetBinContent(15,four3n1n3n1n);
2691   fIntFlowCorrelationsAllEBE->SetBinContent(16,four3n1n2n2n);
2692   fIntFlowCorrelationsAllEBE->SetBinContent(17,four4n2n1n1n);
2693         
2694   // average 4-particle correlations for all events:                
2695   fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2696   fIntFlowCorrelationsAllPro->Fill(11.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2697   fIntFlowCorrelationsAllPro->Fill(12.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2698   fIntFlowCorrelationsAllPro->Fill(13.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2699   fIntFlowCorrelationsAllPro->Fill(14.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2700   fIntFlowCorrelationsAllPro->Fill(15.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
2701   fIntFlowCorrelationsAllPro->Fill(16.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
2702   
2703   // store separetately <4> (to be improved: do I really need this?)
2704   fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1n); // <4>
2705   
2706   // to be improved (this can be implemented better):
2707   Double_t mWeight4p = 0.;
2708   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2709   {
2710    mWeight4p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.);
2711   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2712     {
2713      mWeight4p = 1.;    
2714     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2715       {
2716        mWeight4p = dMult;           
2717       }
2718       
2719   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,mWeight4p); // eW_<4>
2720   fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1n,mWeight4p);
2721   fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
2722   if(fCalculateCumulantsVsM)
2723   {
2724    fIntFlowCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n,mWeight4p);
2725    fIntFlowSquaredCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
2726   }   
2727   // distribution of <cos(n*(phi1+phi2-phi3-phi4))>
2728   //f4pDistribution->Fill(four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2729   
2730  } // end of if(dMult>3)
2731
2732  // 5-particle:
2733  Double_t five2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2734  Double_t five2n2n2n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2735  Double_t five3n1n2n1n1n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2736  Double_t five4n1n1n1n1n = 0.; // <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2737  
2738  if(dMult>4)
2739  {
2740   five2n1n1n1n1n = (reQ2nQ1nQ1nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar+6.*reQ3nQ2nstarQ1nstar)
2741                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2742                  - (reQ2nQ1nQ3nstar+3.*(dMult-6.)*reQ2nQ1nstarQ1nstar+3.*reQ1nQ1nQ2nstar)
2743                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2744                  - (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2745                  + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))     
2746                  - 3.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2747                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2748                  - 3.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2749                  - 2.*(2*dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult*(dMult-4.))
2750                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2751                  
2752   five2n2n2n1n1n = (reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ2nQ2nQ3nstarQ1nstar)
2753                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2754                  + 2.*(reQ4nQ2nstarQ2nstar+4.*reQ3nQ2nstarQ1nstar+reQ3nQ1nQ4nstar)
2755                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2756                  + (reQ2nQ2nQ4nstar-2.*(dMult-5.)*reQ2nQ1nstarQ1nstar+2.*reQ1nQ1nQ2nstar)
2757                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2758                  - (2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2759                  + 1.*pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)
2760                  - 2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2761                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2762                  - (4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2763                  - 4.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+4.*dMult*(dMult-6.))
2764                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2765
2766   five4n1n1n1n1n = (reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ4nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nstarQ1nstarQ1nstar)
2767                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2768                  + (8.*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+12.*reQ3nQ2nstarQ1nstar+12.*reQ2nQ1nstarQ1nstar)
2769                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2770                  - (6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+8.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2771                  + 12.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-24.*dMult)
2772                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2773   
2774   five3n1n2n1n1n = (reQ3nQ1nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar)
2775                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2776                  - (reQ3nQ1nQ2nstarQ2nstar-3.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar)
2777                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2778                  - ((2.*dMult-13.)*reQ3nQ2nstarQ1nstar-reQ3nQ1nQ4nstar-9.*reQ2nQ1nstarQ1nstar)
2779                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2780                  - (2.*reQ1nQ1nQ2nstar+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2781                  - 2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+2.*(pow(dReQ3n,2.)
2782                  + pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2783                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2784                  + (2.*(dMult-6.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2785                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2786                  - pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2787                  + 2.*(3.*dMult-11.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2788                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2789                  - 4.*(dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2790                  
2791   // average 5-particle correlations for single event: 
2792   fIntFlowCorrelationsAllEBE->SetBinContent(19,five2n1n1n1n1n);
2793   fIntFlowCorrelationsAllEBE->SetBinContent(20,five2n2n2n1n1n);
2794   fIntFlowCorrelationsAllEBE->SetBinContent(21,five3n1n2n1n1n);
2795   fIntFlowCorrelationsAllEBE->SetBinContent(22,five4n1n1n1n1n);
2796         
2797   // average 5-particle correlations for all events:                         
2798   fIntFlowCorrelationsAllPro->Fill(18.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2799   fIntFlowCorrelationsAllPro->Fill(19.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2800   fIntFlowCorrelationsAllPro->Fill(20.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2801   fIntFlowCorrelationsAllPro->Fill(21.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2802  } // end of if(dMult>4)
2803     
2804  // 6-particle:
2805  Double_t six1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2806  Double_t six2n2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2807  Double_t six3n1n1n1n1n1n = 0.; // <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2808  Double_t six2n1n1n2n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2809  
2810  if(dMult>5)
2811  {
2812   six1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)+9.*dQ2nQ1nQ2nstarQ1nstar-6.*reQ2nQ1nQ1nstarQ1nstarQ1nstar)
2813                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2814                   + 4.*(reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar)
2815                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2816                   + 2.*(9.*(dMult-4.)*reQ2nQ1nstarQ1nstar+2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2817                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2818                   - 9.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2819                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-5.))
2820                   + (18.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2821                   / (dMult*(dMult-1)*(dMult-3)*(dMult-4))
2822                   - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2823                   
2824   six2n1n1n2n1n1n = (dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2825                   * (2.*five2n2n2n1n1n+4.*five2n1n1n1n1n+4.*five3n1n2n1n1n+4.*four2n1n2n1n+1.*four1n1n1n1n)
2826                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four1n1n1n1n+4.*two1n1n
2827                   + 2.*three2n1n1n+2.*three2n1n1n+4.*four3n1n1n1n+8.*three2n1n1n+2.*four4n2n1n1n
2828                   + 4.*four2n1n2n1n+2.*two2n2n+8.*four2n1n2n1n+4.*four3n1n3n1n+8.*three3n2n1n
2829                   + 4.*four3n1n2n2n+4.*four1n1n1n1n+4.*four2n1n2n1n+1.*four2n2n2n2n)
2830                   - dMult*(dMult-1.)*(dMult-2.)*(2.*three2n1n1n+8.*two1n1n+4.*two1n1n+2.
2831                   + 4.*two1n1n+4.*three2n1n1n+2.*two2n2n+4.*three2n1n1n+8.*three3n2n1n
2832                   + 8.*two2n2n+4.*three4n3n1n+4.*two3n3n+4.*three3n2n1n+4.*two1n1n
2833                   + 8.*three2n1n1n+4.*two1n1n+4.*three3n2n1n+4.*three2n1n1n+2.*two2n2n
2834                   + 4.*three3n2n1n+2.*three4n2n2n)-dMult*(dMult-1.)
2835                   * (4.*two1n1n+4.+4.*two1n1n+2.*two2n2n+1.+4.*two1n1n+4.*two2n2n+4.*two3n3n
2836                   + 1.+2.*two2n2n+1.*two4n4n)-dMult)
2837                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2838  
2839   six2n2n1n1n1n1n = (reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2840                   * (five4n1n1n1n1n+8.*five2n1n1n1n1n+6.*five2n2n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2841                   * (4.*four3n1n1n1n+6.*four4n2n1n1n+12.*three2n1n1n+12.*four1n1n1n1n+24.*four2n1n2n1n
2842                   + 4.*four3n1n2n2n+3.*four2n2n2n2n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n
2843                   + 4.*three4n3n1n+3.*three4n2n2n+8.*three2n1n1n+24.*two1n1n+12.*two2n2n+12.*three2n1n1n+8.*three3n2n1n
2844                   + 1.*three4n2n2n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+2.*two2n2n+8.*two1n1n+6.)-dMult)
2845                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2846    
2847   six3n1n1n1n1n1n = (reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2848                   * (five4n1n1n1n1n+4.*five2n1n1n1n1n+6.*five3n1n2n1n1n+4.*four3n1n1n1n)
2849                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+6.*four1n1n1n1n
2850                   + 12.*three2n1n1n+12.*four2n1n2n1n+6.*four3n1n1n1n+12.*three3n2n1n+4.*four3n1n3n1n+3.*four3n1n2n2n)
2851                   - dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n+4.*three4n3n1n+3.*three4n2n2n+4.*two1n1n
2852                   + 12.*two1n1n+6.*three2n1n1n+12.*three2n1n1n+4.*three3n2n1n+12.*two2n2n+4.*three3n2n1n+4.*two3n3n+1.*three4n3n1n
2853                   + 6.*three3n2n1n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+1.*two1n1n+4.+6.*two1n1n+4.*two2n2n
2854                   + 1.*two3n3n)-dMult)/(dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2855                                  
2856   // average 6-particle correlations for single event: 
2857   fIntFlowCorrelationsAllEBE->SetBinContent(24,six1n1n1n1n1n1n);
2858   fIntFlowCorrelationsAllEBE->SetBinContent(25,six2n1n1n2n1n1n);
2859   fIntFlowCorrelationsAllEBE->SetBinContent(26,six2n2n1n1n1n1n);
2860   fIntFlowCorrelationsAllEBE->SetBinContent(27,six3n1n1n1n1n1n);
2861         
2862   // average 6-particle correlations for all events:         
2863   fIntFlowCorrelationsAllPro->Fill(23.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2864   fIntFlowCorrelationsAllPro->Fill(24.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2865   fIntFlowCorrelationsAllPro->Fill(25.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
2866   fIntFlowCorrelationsAllPro->Fill(26.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2867
2868   // store separetately <6> (to be improved: do I really need this?)
2869   fIntFlowCorrelationsEBE->SetBinContent(3,six1n1n1n1n1n1n); // <6>
2870   
2871   // to be improved (this can be implemented better):
2872   Double_t mWeight6p = 0.;
2873   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2874   {
2875    mWeight6p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.);
2876   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2877     {
2878      mWeight6p = 1.;    
2879     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2880       {
2881        mWeight6p = dMult;           
2882       }
2883       
2884   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(3,mWeight6p); // eW_<6>
2885   fIntFlowCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n,mWeight6p);
2886   fIntFlowSquaredCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
2887   if(fCalculateCumulantsVsM)
2888   {
2889    fIntFlowCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n,mWeight6p);
2890    fIntFlowSquaredCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
2891   }    
2892   // distribution of <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2893   //f6pDistribution->Fill(six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2894  } // end of if(dMult>5)
2895  
2896  // 7-particle:
2897  Double_t seven2n1n1n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2898  
2899  if(dMult>6)
2900  {
2901   seven2n1n1n1n1n1n1n = (reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2902                       * (2.*six3n1n1n1n1n1n+4.*six1n1n1n1n1n1n+1.*six2n2n1n1n1n1n+6.*six2n1n1n2n1n1n+8.*five2n1n1n1n1n)
2903                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(1.*five4n1n1n1n1n +8.*five2n1n1n1n1n+8.*four3n1n1n1n
2904                       + 12.*five3n1n2n1n1n+4.*five2n1n1n1n1n+3.*five2n2n2n1n1n+6.*five2n2n2n1n1n+6.*four1n1n1n1n+24.*four1n1n1n1n
2905                       + 12.*five2n1n1n1n1n+12.*five2n1n1n1n1n+12.*three2n1n1n+24.*four2n1n2n1n+4.*five3n1n2n1n1n+4.*five2n1n1n1n1n)
2906                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+12.*four1n1n1n1n+24.*three2n1n1n
2907                       + 24.*four2n1n2n1n+12.*four3n1n1n1n+24.*three3n2n1n+8.*four3n1n3n1n+6.*four3n1n2n2n+6.*three2n1n1n+12.*four1n1n1n1n
2908                       + 12.*four2n1n2n1n+6.*three2n1n1n+12.*four2n1n2n1n+4.*four3n1n2n2n+3.*four2n2n2n2n+4.*four1n1n1n1n+6.*three2n1n1n
2909                       + 24.*two1n1n+24.*four1n1n1n1n+4.*four3n1n1n1n+24.*two1n1n+24.*three2n1n1n+12.*two2n2n+24.*three2n1n1n+12.*four2n1n2n1n
2910                       + 8.*three3n2n1n+8.*four2n1n2n1n+1.*four4n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+1.*three2n1n1n+8.*two1n1n
2911                       + 12.*three3n2n1n+24.*two1n1n+12.*three2n1n1n+4.*three2n1n1n+8.*two1n1n+4.*three4n3n1n+24.*three2n1n1n+8.*three3n2n1n
2912                       + 12.*two1n1n+12.*two1n1n+3.*three4n2n2n+24.*two2n2n+6.*two2n2n+12.+12.*three3n2n1n+8.*two3n3n+12.*three2n1n1n+24.*two1n1n
2913                       + 4.*three3n2n1n+8.*three3n2n1n+2.*three4n3n1n+12.*two1n1n+8.*three2n1n1n+4.*three2n1n1n+2.*three3n2n1n+6.*two2n2n+8.*two2n2n
2914                       + 1.*three4n2n2n+4.*three3n2n1n+6.*three2n1n1n)-dMult*(dMult-1.)*(4.*two1n1n+2.*two1n1n+6.*two2n2n+8.+1.*two2n2n+4.*two3n3n
2915                       + 12.*two1n1n+4.*two1n1n+1.*two4n4n+8.*two2n2n+6.+2.*two3n3n+4.*two1n1n+1.*two2n2n)-dMult)
2916                       / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)); // to be improved (direct formula needed)
2917         
2918   // average 7-particle correlations for single event: 
2919   fIntFlowCorrelationsAllEBE->SetBinContent(29,seven2n1n1n1n1n1n1n);
2920        
2921   // average 7-particle correlations for all events:                      
2922   fIntFlowCorrelationsAllPro->Fill(28.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.));
2923  } // end of if(dMult>6)
2924  
2925  // 8-particle:
2926  Double_t eight1n1n1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2927  if(dMult>7)
2928  {
2929   eight1n1n1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),4.)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)
2930                         * (12.*seven2n1n1n1n1n1n1n+16.*six1n1n1n1n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2931                         * (8.*six3n1n1n1n1n1n+48.*six1n1n1n1n1n1n+6.*six2n2n1n1n1n1n+96.*five2n1n1n1n1n+72.*four1n1n1n1n+36.*six2n1n1n2n1n1n)
2932                         - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(2.*five4n1n1n1n1n+32.*five2n1n1n1n1n+36.*four1n1n1n1n
2933                         + 32.*four3n1n1n1n+48.*five2n1n1n1n1n+48.*five3n1n2n1n1n+144.*five2n1n1n1n1n+288.*four1n1n1n1n+36.*five2n2n2n1n1n
2934                         + 144.*three2n1n1n+96.*two1n1n+144.*four2n1n2n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2935                         * (8.*four3n1n1n1n+48.*four1n1n1n1n+12.*four4n2n1n1n+96.*four2n1n2n1n+96.*three2n1n1n+72.*three2n1n1n+144.*two1n1n
2936                         + 16.*four3n1n3n1n+48.*four3n1n1n1n+144.*four1n1n1n1n+72.*four1n1n1n1n+96.*three3n2n1n+24.*four3n1n2n2n+144.*four2n1n2n1n
2937                         + 288.*two1n1n+288.*three2n1n1n+9.*four2n2n2n2n+72.*two2n2n+24.)-dMult*(dMult-1.)*(dMult-2.)*(12.*three2n1n1n+16.*two1n1n
2938                         + 24.*three3n2n1n+48.*three2n1n1n+96.*two1n1n+8.*three4n3n1n+32.*three3n2n1n+96.*three2n1n1n+144.*two1n1n+6.*three4n2n2n
2939                         + 96.*two2n2n+36.*two2n2n+72.+48.*three3n2n1n+16.*two3n3n+72.*three2n1n1n+144.*two1n1n)-dMult*(dMult-1.)*(8.*two1n1n
2940                         + 12.*two2n2n+16.+8.*two3n3n+48.*two1n1n+1.*two4n4n+16.*two2n2n+18.)-dMult)
2941                         / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.)); // to be improved (direct formula needed)
2942   
2943   // average 8-particle correlations for single event: 
2944   fIntFlowCorrelationsAllEBE->SetBinContent(31,eight1n1n1n1n1n1n1n1n);
2945        
2946   // average 8-particle correlations for all events:                       
2947   fIntFlowCorrelationsAllPro->Fill(30.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2948  
2949   // store separetately <8> (to be improved: do I really need this?)
2950   fIntFlowCorrelationsEBE->SetBinContent(4,eight1n1n1n1n1n1n1n1n); // <8>
2951   
2952   // to be improved (this can be implemented better):
2953   Double_t mWeight8p = 0.;
2954   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2955   {
2956    mWeight8p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.);
2957   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2958     {
2959      mWeight8p = 1.;    
2960     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2961       {
2962        mWeight8p = dMult;           
2963       }
2964         
2965   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(4,mWeight8p); // eW_<8>
2966   fIntFlowCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
2967   fIntFlowSquaredCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);  
2968   if(fCalculateCumulantsVsM)
2969   {
2970    fIntFlowCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
2971    fIntFlowSquaredCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);
2972   }    
2973   // distribution of <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2974   //f8pDistribution->Fill(eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2975  } // end of if(dMult>7) 
2976  
2977  // EXTRA:
2978
2979  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
2980  // 34th bin: <5>_{2n,2n,2n|3n,3n} = five2n2n2n3n3n = <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))> 
2981  
2982  // 4-particle:
2983  Double_t four4n2n3n3n = 0.; // <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
2984  Double_t reQ4nQ2nQ3nstarQ3nstar = (dReQ4n*dReQ2n-dImQ4n*dImQ2n)*(dReQ3n*dReQ3n-dImQ3n*dImQ3n)
2985                                  + 2.*(dReQ4n*dImQ2n+dImQ4n*dReQ2n)*dReQ3n*dImQ3n;
2986  Double_t three1n2n3n = three3n2n1n;
2987  // <3>_{6n|3n,3n}:
2988  Double_t reQ6nQ3nstarQ3nstar = pow(dReQ3n,2.)*dReQ6n + 2.*dReQ3n*dImQ3n*dImQ6n - pow(dImQ3n,2.)*dReQ6n; 
2989  Double_t three6n3n3n = 0.;
2990  if(dMult>2.)
2991  {
2992   three6n3n3n = (reQ6nQ3nstarQ3nstar-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2993               - (pow(dReQ6n,2.)+pow(dImQ6n,2.))+2.*dMult)
2994               / (dMult*(dMult-1.)*(dMult-2.));          
2995  }
2996  
2997  // <3>_{4n,2n|6n}:
2998  Double_t reQ6nQ4nstarQ2nstar = dReQ6n*dReQ4n*dReQ2n-dReQ6n*dImQ4n*dImQ2n+dImQ6n*dReQ4n*dImQ2n
2999                               + dImQ6n*dImQ4n*dReQ2n;
3000  Double_t three4n2n6n = 0.;
3001  if(dMult>2.)
3002  {
3003   three4n2n6n = (reQ6nQ4nstarQ2nstar-(pow(dReQ6n,2.)+pow(dImQ6n,2.))
3004               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))
3005               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
3006               / (dMult*(dMult-1.)*(dMult-2.)); 
3007  }
3008  Double_t two6n6n = 0.;
3009  if(dMult>1.)
3010  {
3011   two6n6n = (pow(dReQ6n,2.)+pow(dImQ6n,2.)-dMult)/(dMult*(dMult-1.)); 
3012  }
3013  if(dMult>3.)
3014  {
3015   four4n2n3n3n = reQ4nQ2nQ3nstarQ3nstar/(dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3016                - (2.*three1n2n3n+three6n3n3n+2.*three4n3n1n+three4n2n6n)/(dMult-3.)
3017                - (2.*two3n3n+two2n2n+two4n4n+two6n6n+2.*two1n1n)/((dMult-2.)*(dMult-3.)) 
3018                - 1./((dMult-1.)*(dMult-2.)*(dMult-3.));
3019   fIntFlowCorrelationsAllPro->Fill(32.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3020  } // end of if(dMult>3)
3021  
3022  // 5-particle:
3023  Double_t five2n2n2n3n3n = 0.; // <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))>
3024  Double_t reQ2nQ2nQ2nQ3nstarQ3nstar = pow(dReQ2n,3.)*pow(dReQ3n,2.) 
3025                                     - 3.*dReQ2n*pow(dReQ3n,2.)*pow(dImQ2n,2.) + 6.*pow(dReQ2n,2.)*dReQ3n*dImQ2n*dImQ3n 
3026                                     - 2.*dReQ3n*pow(dImQ2n,3.)*dImQ3n - pow(dReQ2n,3.)*pow(dImQ3n,2.) + 3.*dReQ2n*pow(dImQ2n,2.)*pow(dImQ3n,2.);
3027  //Double_t reQ2nQ2nQ2nQ3nstarQ3nstar = (pow(dReQ2n,3.)-3.*dReQ2n*dImQ2n*dImQ2n)*(dReQ3n*dReQ3n-dImQ3n*dImQ3n)
3028  //                                   + 2.*dReQ3n*dImQ3n*(3.*dReQ2n*dReQ2n*dImQ2n-pow(dImQ3n,3.));
3029  Double_t four2n2n1n3n = four3n1n2n2n;
3030  // <4>_{2n,2n,2n|6n}:
3031  Double_t reQ6nQ2nstarQ2nstarQ2nstar = dReQ6n*pow(dReQ2n,3)-3.*dReQ2n*dReQ6n*pow(dImQ2n,2)
3032                                      + 3.*dImQ2n*dImQ6n*pow(dReQ2n,2)-dImQ6n*pow(dImQ2n,3);
3033  Double_t four2n2n2n6n = 0.;
3034  if(dMult>3.)
3035  {
3036   four2n2n2n6n = (reQ6nQ2nstarQ2nstarQ2nstar-3.*reQ6nQ4nstarQ2nstar-3.*reQ4nQ2nstarQ2nstar)
3037                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3038                + (2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))+3.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3039                + 6.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-6.*dMult)
3040                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
3041  }
3042  Double_t three2n2n4n = three4n2n2n;
3043  Double_t three4n1n3n = three4n3n1n;                       
3044  
3045  if(dMult>4.)
3046  {
3047   five2n2n2n3n3n = reQ2nQ2nQ2nQ3nstarQ3nstar
3048                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
3049                  - (6.*four2n2n1n3n+3.*four4n2n3n3n+1.*four2n2n2n6n)/(dMult-4.)
3050                  - (3.*three2n2n4n+6.*three1n2n3n+1.*three6n3n3n+3.*three4n2n6n+6.*three2n1n1n+6.*three4n1n3n)/((dMult-3.)*(dMult-4.))
3051                  - (2.*two3n3n+3.*two2n2n+1.*two6n6n+6.*two1n1n+3.*two4n4n)/((dMult-2.)*(dMult-3.)*(dMult-4.))
3052                  - 1./((dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3053   fIntFlowCorrelationsAllPro->Fill(33.5,five2n2n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3054  } // end of if(dMult>4)
3055  
3056 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
3057
3058 //================================================================================================================================
3059
3060 void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3061 {
3062  // Store phi distribution for one event to illustrate flow.
3063  
3064  if(fPhiDistributionForOneEvent->GetEntries()>0){return;} // store only phi distribution for one event
3065  
3066  Double_t vMin = fPhiDistributionForOneEventSettings[0]; 
3067  Double_t vMax = fPhiDistributionForOneEventSettings[1]; 
3068  Double_t refMultMin = fPhiDistributionForOneEventSettings[2]; 
3069  Double_t refMultMax = fPhiDistributionForOneEventSettings[3]; 
3070  
3071  Double_t vEBE = 0.;
3072  Double_t cumulant4thEBE = fIntFlowCorrelationsEBE->GetBinContent(2)-2.*pow(fIntFlowCorrelationsEBE->GetBinContent(1),2.);
3073  if(cumulant4thEBE<0.)
3074  {
3075   vEBE = pow(-1.*cumulant4thEBE,0.25);
3076   if((vEBE>vMin && vEBE<vMax) && (fReferenceMultiplicityEBE>refMultMin && fReferenceMultiplicityEBE<refMultMax))
3077   {
3078    fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f",fHarmonic,vEBE));
3079    for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3080    {
3081     if(anEvent->GetTrack(p)->InRPSelection())
3082     {
3083      fPhiDistributionForOneEvent->Fill(anEvent->GetTrack(p)->Phi());
3084     }
3085    } // end of for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3086   } else
3087     {
3088      fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f, out of specified boundaries",fHarmonic,vEBE));  
3089     } 
3090    
3091  } // end of if(cumulant4thEBE<0.)
3092  
3093 } // end of void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3094
3095 //================================================================================================================================
3096
3097 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3098 {
3099  // Calculate averages of products of correlations for integrated flow.
3100  
3101  // multiplicity:
3102  Double_t dMult = (*fSMpk)(0,0);
3103  
3104  Int_t counter = 0;
3105  
3106  for(Int_t ci1=1;ci1<4;ci1++)
3107  {
3108   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
3109   {
3110    fIntFlowProductOfCorrelationsPro->Fill(0.5+counter,
3111                                           fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3112                                           fIntFlowCorrelationsEBE->GetBinContent(ci2),
3113                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3114                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3115    // products versus multiplicity:  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]
3116    if(fCalculateCumulantsVsM)
3117    {
3118     fIntFlowProductOfCorrelationsVsMPro[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights ?
3119                                                        fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3120                                                        fIntFlowCorrelationsEBE->GetBinContent(ci2),
3121                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3122                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3123    } // end of if(fCalculateCumulantsVsM)
3124    counter++;                                                                                                                        
3125   }
3126  }
3127  
3128 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3129
3130
3131 //================================================================================================================================
3132
3133
3134 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3135 {
3136  // Calculate averages of products of correction terms for NUA.
3137  
3138  // a) Binning of fIntFlowProductOfCorrectionTermsForNUAPro is organized as follows:
3139  //     1st bin: <<2><cos(phi)>> 
3140  //     2nd bin: <<2><sin(phi)>>
3141  //     3rd bin: <<cos(phi)><sin(phi)>>
3142  //     4th bin: <<2><cos(phi1+phi2)>> 
3143  //     5th bin: <<2><sin(phi1+phi2)>>
3144  //     6th bin: <<2><cos(phi1-phi2-phi3)>> 
3145  //     7th bin: <<2><sin(phi1-phi2-phi3)>>
3146  //     8th bin: <<4><cos(phi1)>>
3147  //     9th bin: <<4><sin(phi1)>>
3148  //    10th bin: <<4><cos(phi1+phi2)>>
3149  //    11th bin: <<4><sin(phi1+phi2)>>
3150  //    12th bin: <<4><cos(phi1-phi2-phi3)>>
3151  //    13th bin: <<4><sin(phi1-phi2-phi3)>>
3152  //    14th bin: <<cos(phi1)><cos(phi1+phi2)>>
3153  //    15th bin: <<cos(phi1)><sin(phi1+phi2)>> 
3154  //    16th bin: <<cos(phi1)><cos(phi1-phi2-phi3)>>
3155  //    17th bin: <<cos(phi1)><sin(phi1-phi2-phi3)>> 
3156  //    18th bin: <<sin(phi1)><cos(phi1+phi2)>>
3157  //    19th bin: <<sin(phi1)><sin(phi1+phi2)>> 
3158  //    20th bin: <<sin(phi1)><cos(phi1-phi2-phi3)>>
3159  //    21st bin: <<sin(phi1)><sin(phi1-phi2-phi3)>>
3160  //    22nd bin: <<cos(phi1+phi2)><sin(phi1+phi2)>>
3161  //    23rd bin: <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>
3162  //    24th bin: <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>
3163  //    25th bin: <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>
3164  //    26th bin: <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>
3165  //    27th bin: <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>
3166  
3167  // <<2><cos(phi)>>:
3168  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(0.5,
3169                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3170                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3171                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3172  // <<2><sin(phi)>>:
3173  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(1.5,
3174                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3175                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3176                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3177  // <<cos(phi)><sin(phi)>>:
3178  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(2.5,
3179                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3180                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3181                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3182  // <<2><cos(phi1+phi2)>>:
3183  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(3.5,
3184                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3185                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3186                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3187  // <<2><sin(phi1+phi2)>>:
3188  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(4.5,
3189                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3190                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3191                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3192  // <<2><cos(phi1-phi2-phi3)>>:
3193  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(5.5,
3194                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3195                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3196                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3197  // <<2><sin(phi1-phi2-phi3)>>:
3198  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(6.5,
3199                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3200                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3201                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3202  // <<4><cos(phi1)>>:
3203  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(7.5,
3204                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3205                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3206                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3207  // <<4><sin(phi1)>>:
3208  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(8.5,
3209                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3210                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3211                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3212  // <<4><cos(phi1+phi2)>>:
3213  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(9.5,
3214                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3215                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3216                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3217  // <<4><sin(phi1+phi2)>>:
3218  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(10.5,
3219                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3220                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3221                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
3222  // <<4><cos(phi1-phi2-phi3)>>:
3223  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(11.5,
3224                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3225                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3226                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3227  // <<4><sin(phi1-phi2-phi3)>>:
3228  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(12.5,
3229                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3230                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3231                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));   
3232  // <<cos(phi1)><cos(phi1+phi2)>>:
3233  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(13.5,
3234                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3235                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3236                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3237  // <<cos(phi1)><sin(phi1+phi2)>>: 
3238  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(14.5,
3239                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3240                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3241                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3242  // <<cos(phi1)><cos(phi1-phi2-phi3)>>:
3243  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(15.5,
3244                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3245                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3246                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3247  // <<cos(phi1)><sin(phi1-phi2-phi3)>>: 
3248  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(16.5,
3249                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3250                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3251                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
3252  // <<sin(phi1)><cos(phi1+phi2)>>:
3253  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(17.5,
3254                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3255                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3256                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));  
3257  // <<sin(phi1)><sin(phi1+phi2)>>: 
3258  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(18.5,
3259                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3260                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3261                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));  
3262  // <<sin(phi1)><cos(phi1-phi2-phi3)>>:
3263  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(19.5,
3264                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3265                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3266                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3267  // <<sin(phi1)><sin(phi1-phi2-phi3)>>:
3268  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(20.5,
3269                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3270                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3271                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3272  // <<cos(phi1+phi2)><sin(phi1+phi2)>>:
3273  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(21.5,
3274                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3275                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3276                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3277  // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3278  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(22.5,
3279                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3280                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3281                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));   
3282  // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3283  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(23.5,
3284                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3285                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3286                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3287  // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3288  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(24.5,
3289                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3290                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3291                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));    
3292  // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3293  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(25.5,
3294                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3295                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3296                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3297  // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>:
3298  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(26.5,
3299                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3300                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)
3301                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3302
3303 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3304
3305 //================================================================================================================================
3306
3307 void AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
3308 {
3309  // a) Calculate unbiased estimators Cov(<2>,<4>), Cov(<2>,<6>), Cov(<2>,<8>), Cov(<4>,<6>), Cov(<4>,<8>) and Cov(<6>,<8>)
3310  //    for covariances V_(<2>,<4>), V_(<2>,<6>), V_(<2>,<8>), V_(<4>,<6>), V_(<4>,<8>) and V_(<6>,<8>).
3311  // b) Store in histogram fIntFlowCovariances for instance the following: 
3312  //
3313  //             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)]
3314  // 
3315  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<4>} is event weight for <4>.
3316  // c) Binning of fIntFlowCovariances is organized as follows:
3317  // 
3318  //     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)] 
3319  //     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)]
3320  //     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)]
3321  //     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)]
3322  //     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)]
3323  //     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)]
3324  //
3325     
3326  // Average 2-, 4-, 6- and 8-particle correlations for all events:
3327  Double_t correlation[4] = {0.};
3328  for(Int_t ci=0;ci<4;ci++)
3329  {
3330   correlation[ci] = fIntFlowCorrelationsPro->GetBinContent(ci+1);
3331  } 
3332  // Average products of 2-, 4-, 6- and 8-particle correlations: 
3333  Double_t productOfCorrelations[4][4] = {{0.}};
3334  Int_t productOfCorrelationsLabel = 1;
3335  // Denominators in the expressions for the unbiased estimator for covariance:
3336  Double_t denominator[4][4] = {{0.}};
3337  Int_t sumOfProductOfEventWeightsLabel1 = 1;
3338  // Weight dependent prefactor which multiply unbiased estimators for covariances:
3339  Double_t wPrefactor[4][4] = {{0.}}; 
3340  Int_t sumOfProductOfEventWeightsLabel2 = 1;
3341  for(Int_t c1=0;c1<4;c1++)
3342  {
3343   for(Int_t c2=c1+1;c2<4;c2++)
3344   {
3345    productOfCorrelations[c1][c2] = fIntFlowProductOfCorrelationsPro->GetBinContent(productOfCorrelationsLabel);
3346    if(TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1)) > 1.e-44)
3347    {
3348     denominator[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel1))
3349                         / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1) 
3350                         * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                              
3351     wPrefactor[c1][c2] = fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel2)
3352                        / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)
3353                        * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                                                       
3354    }
3355    productOfCorrelationsLabel++; // to be improved - do I need here all 3 counters?
3356    sumOfProductOfEventWeightsLabel1++;
3357    sumOfProductOfEventWeightsLabel2++;  
3358   } // end of for(Int_t c2=c1+1;c2<4;c2++)
3359  } // end of for(Int_t c1=0;c1<4;c1++)
3360  
3361  Int_t covarianceLabel = 1;
3362  for(Int_t c1=0;c1<4;c1++)
3363  {
3364   for(Int_t c2=c1+1;c2<4;c2++)
3365   {
3366    if(TMath::Abs(denominator[c1][c2]) > 1.e-44)
3367    {
3368     // Covariances:
3369     Double_t cov = (productOfCorrelations[c1][c2]-correlation[c1]*correlation[c2])/denominator[c1][c2]; 
3370     // Covariances multiplied with weight dependent prefactor:
3371     Double_t wCov = cov * wPrefactor[c1][c2];
3372     fIntFlowCovariances->SetBinContent(covarianceLabel,wCov);
3373    }
3374    covarianceLabel++;
3375   } // end of for(Int_t c2=c1+1;c2<4;c2++) 
3376  } // end of for(Int_t c1=0;c1<4;c1++)
3377  
3378  // Versus multiplicity: 
3379  if(!fCalculateCumulantsVsM){return;}
3380  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
3381  for(Int_t b=1;b<=nBins;b++)
3382  {
3383   // Average 2-, 4-, 6- and 8-particle correlations for all events:
3384   Double_t correlationVsM[4] = {0.};
3385   for(Int_t ci=0;ci<4;ci++)
3386   {
3387    correlationVsM[ci] = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
3388   } // end of for(Int_t ci=0;ci<4;ci++)
3389   // Average products of 2-, 4-, 6- and 8-particle correlations: 
3390   Double_t productOfCorrelationsVsM[4][4] = {{0.}};
3391   Int_t productOfCorrelationsLabelVsM = 1;
3392   // Denominators in the expressions for the unbiased estimator for covariance:
3393   Double_t denominatorVsM[4][4] = {{0.}};
3394   Int_t sumOfProductOfEventWeightsLabel1VsM = 1;
3395   // Weight dependent prefactor which multiply unbiased estimators for covariances:
3396   Double_t wPrefactorVsM[4][4] = {{0.}}; 
3397   Int_t sumOfProductOfEventWeightsLabel2VsM = 1;
3398   for(Int_t c1=0;c1<4;c1++)
3399   {
3400    for(Int_t c2=c1+1;c2<4;c2++)
3401    {
3402     productOfCorrelationsVsM[c1][c2] = fIntFlowProductOfCorrelationsVsMPro[productOfCorrelationsLabelVsM-1]->GetBinContent(b);
3403     if(TMath::Abs(fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b)) > 1.e-44)
3404     {
3405      denominatorVsM[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel1VsM-1]->GetBinContent(b))
3406                             / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b) 
3407                             * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                              
3408      wPrefactorVsM[c1][c2] = fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel2VsM-1]->GetBinContent(b)
3409                            / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)
3410                            * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                                                       
3411     }
3412     productOfCorrelationsLabelVsM++;
3413     sumOfProductOfEventWeightsLabel1VsM++;
3414     sumOfProductOfEventWeightsLabel2VsM++;  
3415    } // end of for(Int_t c1=0;c1<4;c1++) 
3416   } // end of for(Int_t c2=c1+1;c2<4;c2++)
3417  
3418   Int_t covarianceLabelVsM = 1;
3419   for(Int_t c1=0;c1<4;c1++)
3420   {
3421    for(Int_t c2=c1+1;c2<4;c2++)
3422    {
3423     if(TMath::Abs(denominatorVsM[c1][c2]) > 1.e-44)
3424     {
3425      // Covariances:
3426      Double_t covVsM = (productOfCorrelationsVsM[c1][c2]-correlationVsM[c1]*correlationVsM[c2])/denominatorVsM[c1][c2]; 
3427      // Covariances multiplied with weight dependent prefactor:
3428      Double_t wCovVsM = covVsM * wPrefactorVsM[c1][c2];
3429      fIntFlowCovariancesVsM[covarianceLabelVsM-1]->SetBinContent(b,wCovVsM);
3430     }
3431     covarianceLabelVsM++;
3432    } // end of for(Int_t c2=c1+1;c2<4;c2++)
3433   } // end of for(Int_t c1=0;c1<4;c1++)
3434  } // end of for(Int_t b=1;b<=nBins;b++)
3435   
3436 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
3437
3438 //================================================================================================================================
3439
3440 void AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
3441 {
3442  // a) Calculate unbiased estimators Cov(*,*) for true covariances V_(*,*) for NUA terms.
3443  // b) Store in histogram fIntFlowCovariancesNUA for instance the following: 
3444  //
3445  //             Cov(<2>,<cos(phi)>) * (sum_{i=1}^{N} w_{<2>}_i w_{<cos(phi)>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<cos(phi)>}_j)]
3446  // 
3447  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<cos(phi)>} is event weight for <cos(phi)>.
3448  // c) Binning of fIntFlowCovariancesNUA is organized as follows:
3449  // 
3450  //     1st bin: Cov(<2>,<cos(phi)>) * (sum_{i=1}^{N} w_{<2>}_i w_{<cos(phi)>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<cos(phi)>}_j)] 
3451  //     2nd bin: Cov(<2>,<sin(phi)>) * (sum_{i=1}^{N} w_{<2>}_i w_{<sin(phi)>}_i )/[(sum_{i=1}^{N} w_{<2>}_i) * (sum_{j=1}^{N} w_{<sin(phi)>}_j)]
3452  //     3rd bin: Cov(<cos(phi)>,<sin(phi)>) * (sum_{i=1}^{N} w_{<cos(phi)>}_i w_{<sin(phi)>}_i )/[(sum_{i=1}^{N} w_{<cos(phi)>}_i) * (sum_{j=1}^{N} w_{<sin(phi)>}_j)]
3453  // ...
3454       
3455  // Cov(<2>,<cos(phi)>):
3456  Double_t product1 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(1); // <<2><cos(phi)>> 
3457  Double_t term1st1 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3458  Double_t term2nd1 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
3459  Double_t sumOfW1st1 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3460  Double_t sumOfW2nd1 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
3461  Double_t sumOfWW1 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(1); // W_{<2>} * W_{<cos(phi)>}
3462  // numerator in the expression for the the unbiased estimator for covariance:
3463  Double_t numerator1 = product1 - term1st1*term2nd1; 
3464  // denominator in the expression for the the unbiased estimator for covariance:
3465  Double_t denominator1 = 0.;
3466  if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
3467  {
3468   denominator1 = 1.-sumOfWW1/(sumOfW1st1*sumOfW2nd1);
3469   if(TMath::Abs(denominator1)>0.)
3470   {
3471    // covariance:
3472    Double_t covariance1 = numerator1/denominator1;
3473    // weight dependent prefactor for covariance:
3474    Double_t wPrefactor1 = sumOfWW1/(sumOfW1st1*sumOfW2nd1);
3475    // finally, store "weighted" covariance:
3476    fIntFlowCovariancesNUA->SetBinContent(1,wPrefactor1*covariance1);
3477   } // end of if(TMath::Abs(denominator)>0.)
3478  } // end of if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
3479  
3480  // Cov(<2>,<sin(phi)>):
3481  Double_t product2 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(2); // <<2><sin(phi)>> 
3482  Double_t term1st2 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3483  Double_t term2nd2 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
3484  Double_t sumOfW1st2 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3485  Double_t sumOfW2nd2 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
3486  Double_t sumOfWW2 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(2); // W_{<2>} * W_{<sin(phi)>}
3487  // numerator in the expression for the the unbiased estimator for covariance:
3488  Double_t numerator2 = product2 - term1st2*term2nd2;
3489  // denominator in the expression for the the unbiased estimator for covariance:
3490  Double_t denominator2 = 0.;
3491  if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
3492  {  
3493   denominator2 = 1.-sumOfWW2/(sumOfW1st2*sumOfW2nd2);
3494   if(TMath::Abs(denominator2)>0.)
3495   {
3496    // covariance:
3497    Double_t covariance2 = numerator2/denominator2;
3498    // weight dependent prefactor for covariance:
3499    Double_t wPrefactor2 = sumOfWW2/(sumOfW1st2*sumOfW2nd2);
3500    // finally, store "weighted" covariance:
3501    fIntFlowCovariancesNUA->SetBinContent(2,wPrefactor2*covariance2);
3502   } // end of if(TMath::Abs(denominator2)>0.)
3503  } // end of if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
3504  
3505  // Cov(<cos(phi)>,<sin(phi)>):
3506  Double_t product3 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(3); // <<cos(phi)><sin(phi)>> 
3507  Double_t term1st3 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
3508  Double_t term2nd3 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
3509  Double_t sumOfW1st3 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
3510  Double_t sumOfW2nd3 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
3511  Double_t sumOfWW3 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(3); // W_{<cos(phi)>} * W_{<sin(phi)>}
3512  // numerator in the expression for the the unbiased estimator for covariance:
3513  Double_t numerator3 = product3 - term1st3*term2nd3; 
3514  // denominator in the expression for the the unbiased estimator for covariance:
3515  Double_t denominator3 = 0;
3516  if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
3517  { 
3518   denominator3 = 1.-sumOfWW3/(sumOfW1st3*sumOfW2nd3);
3519   if(TMath::Abs(denominator3)>0.)
3520   {
3521    // covariance:
3522    Double_t covariance3 = numerator3/denominator3;
3523    // weight dependent prefactor for covariance:
3524    Double_t wPrefactor3 = sumOfWW3/(sumOfW1st3*sumOfW2nd3);
3525    // finally, store "weighted" covariance:
3526    fIntFlowCovariancesNUA->SetBinContent(3,wPrefactor3*covariance3);
3527   } // end of if(TMath::Abs(denominator3)>0.)
3528  } // end of if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
3529  
3530  // Cov(<2>,<cos(phi1+phi2)>):
3531  Double_t product4 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(4); // <<2><cos(phi1+phi2)>> 
3532  Double_t term1st4 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3533  Double_t term2nd4 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3534  Double_t sumOfW1st4 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3535  Double_t sumOfW2nd4 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3536  Double_t sumOfWW4 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(4); // W_{<2>} * W_{<cos(phi1+phi2)>}
3537  // numerator in the expression for the the unbiased estimator for covariance:
3538  Double_t numerator4 = product4 - term1st4*term2nd4; 
3539  // denominator in the expression for the the unbiased estimator for covariance:
3540  Double_t denominator4 = 0.;
3541  if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
3542  { 
3543   denominator4 = 1.-sumOfWW4/(sumOfW1st4*sumOfW2nd4);
3544   if(TMath::Abs(denominator4)>0.)
3545   {  
3546    // covariance:
3547    Double_t covariance4 = numerator4/denominator4;
3548    // weight dependent prefactor for covariance:
3549    Double_t wPrefactor4 = sumOfWW4/(sumOfW1st4*sumOfW2nd4);
3550    // finally, store "weighted" covariance:
3551    fIntFlowCovariancesNUA->SetBinContent(4,wPrefactor4*covariance4);
3552   } // end of if(TMath::Abs(denominator4)>0.)
3553  } // end of if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
3554  
3555  // Cov(<2>,<sin(phi1+phi2)>):
3556  Double_t product5 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(5); // <<2><sin(phi1+phi2)>> 
3557  Double_t term1st5 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3558  Double_t term2nd5 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3559  Double_t sumOfW1st5 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3560  Double_t sumOfW2nd5 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3561  Double_t sumOfWW5 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(5); // W_{<2>} * W_{<sin(phi1+phi2)>}
3562  // numerator in the expression for the the unbiased estimator for covariance:
3563  Double_t numerator5 = product5 - term1st5*term2nd5; 
3564  // denominator in the expression for the the unbiased estimator for covariance:
3565  Double_t denominator5 = 0.;
3566  if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
3567  {  
3568   denominator5 = 1.-sumOfWW5/(sumOfW1st5*sumOfW2nd5);
3569   if(TMath::Abs(denominator5)>0.)
3570   {  
3571    // covariance:
3572    Double_t covariance5 = numerator5/denominator5;
3573    // weight dependent prefactor for covariance:
3574    Double_t wPrefactor5 = sumOfWW5/(sumOfW1st5*sumOfW2nd5);
3575    // finally, store "weighted" covariance:
3576    fIntFlowCovariancesNUA->SetBinContent(5,wPrefactor5*covariance5);
3577   } // end of if(TMath::Abs(denominator5)>0.)
3578  } // end of if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
3579  
3580  // Cov(<2>,<cos(phi1-phi2-phi3)>):
3581  Double_t product6 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(6); // <<2><cos(phi1-phi2-phi3)>> 
3582  Double_t term1st6 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3583  Double_t term2nd6 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3584  Double_t sumOfW1st6 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3585  Double_t sumOfW2nd6 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3586  Double_t sumOfWW6 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(6); // W_{<2>} * W_{<cos(phi1-phi2-phi3)>}
3587  // numerator in the expression for the the unbiased estimator for covariance:
3588  Double_t numerator6 = product6 - term1st6*term2nd6; 
3589  // denominator in the expression for the the unbiased estimator for covariance:
3590  Double_t denominator6 = 0.;
3591  if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
3592  {  
3593   denominator6 = 1.-sumOfWW6/(sumOfW1st6*sumOfW2nd6);
3594   if(TMath::Abs(denominator6)>0.)
3595   {  
3596    // covariance:
3597    Double_t covariance6 = numerator6/denominator6;
3598    // weight dependent prefactor for covariance:
3599    Double_t wPrefactor6 = sumOfWW6/(sumOfW1st6*sumOfW2nd6);
3600    // finally, store "weighted" covariance:
3601    fIntFlowCovariancesNUA->SetBinContent(6,wPrefactor6*covariance6);
3602   } // end of if(TMath::Abs(denominator6)>0.)
3603  } // end of if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
3604  
3605  // Cov(<2>,<sin(phi1-phi2-phi3)>):
3606  Double_t product7 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(7); // <<2><sin(phi1-phi2-phi3)>> 
3607  Double_t term1st7 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3608  Double_t term2nd7 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3609  Double_t sumOfW1st7 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3610  Double_t sumOfW2nd7 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3611  Double_t sumOfWW7 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(7); // W_{<2>} * W_{<sin(phi1-phi2-phi3)>}
3612  // numerator in the expression for the the unbiased estimator for covariance:
3613  Double_t numerator7 = product7 - term1st7*term2nd7; 
3614  // denominator in the expression for the the unbiased estimator for covariance:
3615  Double_t denominator7 = 0.;
3616  if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
3617  {  
3618   denominator7 = 1.-sumOfWW7/(sumOfW1st7*sumOfW2nd7);
3619   if(TMath::Abs(denominator7)>0.)
3620   {   
3621    // covariance:
3622    Double_t covariance7 = numerator7/denominator7;
3623    // weight dependent prefactor for covariance:
3624    Double_t wPrefactor7 = sumOfWW7/(sumOfW1st7*sumOfW2nd7);
3625    // finally, store "weighted" covariance:
3626    fIntFlowCovariancesNUA->SetBinContent(7,wPrefactor7*covariance7);
3627   } // end of if(TMath::Abs(denominator7)>0.)
3628  } // end of if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
3629  
3630  // Cov(<4>,<cos(phi1>):
3631  Double_t product8 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(8); // <<4><cos(phi1)>> 
3632  Double_t term1st8 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3633  Double_t term2nd8 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3634  Double_t sumOfW1st8 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3635  Double_t sumOfW2nd8 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3636  Double_t sumOfWW8 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(8); // W_{<4>} * W_{<cos(phi1)>}
3637  // numerator in the expression for the the unbiased estimator for covariance:
3638  Double_t numerator8 = product8 - term1st8*term2nd8; 
3639  // denominator in the expression for the the unbiased estimator for covariance:
3640  Double_t denominator8 = 0.;
3641  if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
3642  { 
3643   denominator8 = 1.-sumOfWW8/(sumOfW1st8*sumOfW2nd8);
3644   if(TMath::Abs(denominator8)>0.)
3645   {     
3646    // covariance:
3647    Double_t covariance8 = numerator8/denominator8;
3648    // weight dependent prefactor for covariance:
3649    Double_t wPrefactor8 = sumOfWW8/(sumOfW1st8*sumOfW2nd8);
3650    // finally, store "weighted" covariance:
3651    fIntFlowCovariancesNUA->SetBinContent(8,wPrefactor8*covariance8);
3652   } // end of if(TMath::Abs(denominator8)>0.)
3653  } // end of if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
3654  
3655  // Cov(<4>,<sin(phi1)>):
3656  Double_t product9 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(9); // <<4><sin(phi1)>> 
3657  Double_t term1st9 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3658  Double_t term2nd9 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3659  Double_t sumOfW1st9 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3660  Double_t sumOfW2nd9 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3661  Double_t sumOfWW9 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(9); // W_{<4>} * W_{<sin(phi1)>}
3662  // numerator in the expression for the the unbiased estimator for covariance:
3663  Double_t numerator9 = product9 - term1st9*term2nd9; 
3664  // denominator in the expression for the the unbiased estimator for covariance:
3665  Double_t denominator9 = 0.;
3666  if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
3667  {
3668   denominator9 = 1.-sumOfWW9/(sumOfW1st9*sumOfW2nd9);
3669   if(TMath::Abs(denominator9)>0.)
3670   {     
3671    // covariance:
3672    Double_t covariance9 = numerator9/denominator9;
3673    // weight dependent prefactor for covariance:
3674    Double_t wPrefactor9 = sumOfWW9/(sumOfW1st9*sumOfW2nd9);
3675    // finally, store "weighted" covariance:
3676    fIntFlowCovariancesNUA->SetBinContent(9,wPrefactor9*covariance9); 
3677   }
3678  } // end of if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
3679  
3680  // Cov(<4>,<cos(phi1+phi2)>):
3681  Double_t product10 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(10); // <<4><cos(phi1+phi2)>> 
3682  Double_t term1st10 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3683  Double_t term2nd10 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3684  Double_t sumOfW1st10 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3685  Double_t sumOfW2nd10 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3686  Double_t sumOfWW10 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(10); // W_{<4>} * W_{<cos(phi1+phi2)>}
3687  // numerator in the expression for the the unbiased estimator for covariance:
3688  Double_t numerator10 = product10 - term1st10*term2nd10; 
3689  // denominator in the expression for the the unbiased estimator for covariance:
3690  Double_t denominator10 = 0.;
3691  if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
3692  { 
3693   denominator10 = 1.-sumOfWW10/(sumOfW1st10*sumOfW2nd10);
3694   if(TMath::Abs(denominator10)>0.) 
3695   { 
3696    // covariance:
3697    Double_t covariance10 = numerator10/denominator10;
3698    // weight dependent prefactor for covariance:
3699    Double_t wPrefactor10 = sumOfWW10/(sumOfW1st10*sumOfW2nd10);
3700    // finally, store "weighted" covariance:
3701    fIntFlowCovariancesNUA->SetBinContent(10,wPrefactor10*covariance10);
3702   } // end of if(TMath::Abs(denominator10)>0.) 
3703  } // end of if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
3704  
3705  // Cov(<4>,<sin(phi1+phi2)>):
3706  Double_t product11 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(11); // <<4><sin(phi1+phi2)>> 
3707  Double_t term1st11 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3708  Double_t term2nd11 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3709  Double_t sumOfW1st11 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3710  Double_t sumOfW2nd11 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3711  Double_t sumOfWW11 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(11); // W_{<4>} * W_{<sin(phi1+phi2)>}
3712  // numerator in the expression for the the unbiased estimator for covariance:
3713  Double_t numerator11 = product11 - term1st11*term2nd11; 
3714  // denominator in the expression for the the unbiased estimator for covariance:
3715  Double_t denominator11 = 0.;
3716  if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
3717  {  
3718   denominator11 = 1.-sumOfWW11/(sumOfW1st11*sumOfW2nd11);
3719   if(TMath::Abs(denominator11)>0.) 
3720   { 
3721    // covariance:
3722    Double_t covariance11 = numerator11/denominator11;
3723    // weight dependent prefactor for covariance:
3724    Double_t wPrefactor11 = sumOfWW11/(sumOfW1st11*sumOfW2nd11);
3725    // finally, store "weighted" covariance:
3726    fIntFlowCovariancesNUA->SetBinContent(11,wPrefactor11*covariance11);
3727   } // end of if(TMath::Abs(denominator11)>0.) 
3728  } // end of if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
3729
3730  // Cov(<4>,<cos(phi1-phi2-phi3)>):
3731  Double_t product12 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(12); // <<4><cos(phi1-phi2-phi3)>> 
3732  Double_t term1st12 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3733  Double_t term2nd12 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3734  Double_t sumOfW1st12 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3735  Double_t sumOfW2nd12 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3736  Double_t sumOfWW12 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(12); // W_{<4>} * W_{<cos(phi1-phi2-phi3)>}
3737  // numerator in the expression for the the unbiased estimator for covariance:
3738  Double_t numerator12 = product12 - term1st12*term2nd12; 
3739  // denominator in the expression for the the unbiased estimator for covariance:
3740  Double_t denominator12 = 0.;
3741  if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.) 
3742  {   
3743   denominator12 = 1.-sumOfWW12/(sumOfW1st12*sumOfW2nd12);
3744   if(TMath::Abs(denominator12)>0.) 
3745   { 
3746    // covariance:
3747    Double_t covariance12 = numerator12/denominator12;
3748    // weight dependent prefactor for covariance:
3749    Double_t wPrefactor12 = sumOfWW12/(sumOfW1st12*sumOfW2nd12);
3750    // finally, store "weighted" covariance:
3751    fIntFlowCovariancesNUA->SetBinContent(12,wPrefactor12*covariance12);
3752   } // end of if(TMath::Abs(denominator12)>0.)
3753  } // end of if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.)  
3754
3755  // Cov(<4>,<sin(phi1-phi2-phi3)>):
3756  Double_t product13 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(13); // <<4><sin(phi1-phi2-phi3)>> 
3757  Double_t term1st13 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3758  Double_t term2nd13 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3759  Double_t sumOfW1st13 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3760  Double_t sumOfW2nd13 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3761  Double_t sumOfWW13 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(13); // W_{<4>} * W_{<sin(phi1-phi2-phi3)>}
3762  // numerator in the expression for the the unbiased estimator for covariance:
3763  Double_t numerator13 = product13 - term1st13*term2nd13; 
3764  // denominator in the expression for the the unbiased estimator for covariance:
3765  Double_t denominator13 = 0.;
3766  if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
3767  {   
3768   denominator13 = 1.-sumOfWW13/(sumOfW1st13*sumOfW2nd13);
3769   if(TMath::Abs(denominator13)>0.) 
3770   { 
3771    // covariance:
3772    Double_t covariance13 = numerator13/denominator13;
3773    // weight dependent prefactor for covariance:
3774    Double_t wPrefactor13 = sumOfWW13/(sumOfW1st13*sumOfW2nd13);
3775    // finally, store "weighted" covariance:
3776    fIntFlowCovariancesNUA->SetBinContent(13,wPrefactor13*covariance13);
3777   } // end of if(TMath::Abs(denominator13)>0.) 
3778  } // end of if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
3779
3780  // Cov(<cos(phi1)>,<cos(phi1+phi2)>):
3781  Double_t product14 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(14); // <<cos(phi1)><cos(phi1+phi2)>> 
3782  Double_t term1st14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3783  Double_t term2nd14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3784  Double_t sumOfW1st14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3785  Double_t sumOfW2nd14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3786  Double_t sumOfWW14 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(14); // W_{<cos(phi1)>} * W_{<cos(phi1+phi2)>}
3787  // numerator in the expression for the the unbiased estimator for covariance:
3788  Double_t numerator14 = product14 - term1st14*term2nd14; 
3789  // denominator in the expression for the the unbiased estimator for covariance:
3790  Double_t denominator14 = 0.;
3791  if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
3792  {  
3793   denominator14 = 1.-sumOfWW14/(sumOfW1st14*sumOfW2nd14);
3794   if(TMath::Abs(denominator14)>0.) 
3795   { 
3796    // covariance:
3797    Double_t covariance14 = numerator14/denominator14;
3798    // weight dependent prefactor for covariance:
3799    Double_t wPrefactor14 = sumOfWW14/(sumOfW1st14*sumOfW2nd14);
3800    // finally, store "weighted" covariance:
3801    fIntFlowCovariancesNUA->SetBinContent(14,wPrefactor14*covariance14);
3802   } // end of if(TMath::Abs(denominator14)>0.) 
3803  } // end of if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
3804
3805  // Cov(<cos(phi1)>,<sin(phi1+phi2)>):
3806  Double_t product15 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(15); // <<cos(phi1)><sin(phi1+phi2)>> 
3807  Double_t term1st15 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3808  Double_t term2nd15 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3809  Double_t sumOfW1st15 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3810  Double_t sumOfW2nd15 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3811  Double_t sumOfWW15 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(15); // W_{<cos(phi1)>} * W_{<sin(phi1+phi2)>}
3812  // numerator in the expression for the the unbiased estimator for covariance:
3813  Double_t numerator15 = product15 - term1st15*term2nd15; 
3814  // denominator in the expression for the the unbiased estimator for covariance:
3815  Double_t denominator15 = 0.;
3816  if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.) 
3817  {  
3818   denominator15 = 1.-sumOfWW15/(sumOfW1st15*sumOfW2nd15);
3819   if(TMath::Abs(denominator15)>0.) 
3820   { 
3821    // covariance:
3822    Double_t covariance15 = numerator15/denominator15;
3823    // weight dependent prefactor for covariance:
3824    Double_t wPrefactor15 = sumOfWW15/(sumOfW1st15*sumOfW2nd15);
3825    // finally, store "weighted" covariance:
3826    fIntFlowCovariancesNUA->SetBinContent(15,wPrefactor15*covariance15);
3827   } // end of if(TMath::Abs(denominator15)>0.)  
3828  } // end of if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.)  
3829  
3830  // Cov(<cos(phi1)>,<cos(phi1-phi2-phi3)>):
3831  Double_t product16 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(16); // <<cos(phi1)><cos(phi1-phi2-phi3)>> 
3832  Double_t term1st16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3833  Double_t term2nd16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3834  Double_t sumOfW1st16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3835  Double_t sumOfW2nd16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3836  Double_t sumOfWW16 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(16); // W_{<cos(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
3837  // numerator in the expression for the the unbiased estimator for covariance:
3838  Double_t numerator16 = product16 - term1st16*term2nd16; 
3839  // denominator in the expression for the the unbiased estimator for covariance:
3840  Double_t denominator16 = 0.;
3841  if(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.) 
3842  {   
3843   denominator16 = 1.-sumOfWW16/(sumOfW1st16*sumOfW2nd16);
3844   if(TMath::Abs(denominator16)>0.) 
3845   {   
3846    // covariance:
3847    Double_t covariance16 = numerator16/denominator16;
3848    // weight dependent prefactor for covariance:
3849    Double_t wPrefactor16 = sumOfWW16/(sumOfW1st16*sumOfW2nd16);
3850    // finally, store "weighted" covariance:
3851    fIntFlowCovariancesNUA->SetBinContent(16,wPrefactor16*covariance16);
3852   } // end of if(TMath::Abs(denominator16)>0.)
3853  } // end ofif(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.)  
3854  
3855  // Cov(<cos(phi1)>,<sin(phi1-phi2-phi3)>):
3856  Double_t product17 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(17); // <<cos(phi1)><sin(phi1-phi2-phi3)>> 
3857  Double_t term1st17 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3858  Double_t term2nd17 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3859  Double_t sumOfW1st17 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3860  Double_t sumOfW2nd17 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3861  Double_t sumOfWW17 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(17); // W_{<cos(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
3862  // numerator in the expression for the the unbiased estimator for covariance:
3863  Double_t numerator17 = product17 - term1st17*term2nd17; 
3864  // denominator in the expression for the the unbiased estimator for covariance:
3865  Double_t denominator17 = 0.;
3866  if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
3867  {
3868   denominator17 = 1.-sumOfWW17/(sumOfW1st17*sumOfW2nd17);
3869   if(TMath::Abs(denominator17)>0.) 
3870   {   
3871    // covariance:
3872    Double_t covariance17 = numerator17/denominator17;
3873    // weight dependent prefactor for covariance:
3874    Double_t wPrefactor17 = sumOfWW17/(sumOfW1st17*sumOfW2nd17);
3875     // finally, store "weighted" covariance:
3876    fIntFlowCovariancesNUA->SetBinContent(17,wPrefactor17*covariance17);
3877   } // end of if(TMath::Abs(denominator17)>0.) 
3878  } // end of if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
3879
3880  // Cov(<sin(phi1)>,<cos(phi1+phi2)>):
3881  Double_t product18 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(18); // <<sin(phi1)><cos(phi1+phi2)>> 
3882  Double_t term1st18 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3883  Double_t term2nd18 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3884  Double_t sumOfW1st18 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3885  Double_t sumOfW2nd18 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3886  Double_t sumOfWW18 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(18); // W_{<sin(phi1)>} * W_{<cos(phi1+phi2)>}
3887  // numerator in the expression for the the unbiased estimator for covariance:
3888  Double_t numerator18 = product18 - term1st18*term2nd18; 
3889  // denominator in the expression for the the unbiased estimator for covariance:
3890  Double_t denominator18 = 0.;
3891  if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
3892  { 
3893   denominator18 = 1.-sumOfWW18/(sumOfW1st18*sumOfW2nd18);
3894   if(TMath::Abs(denominator18)>0.) 
3895   {   
3896    // covariance:
3897    Double_t covariance18 = numerator18/denominator18;
3898    // weight dependent prefactor for covariance:
3899    Double_t wPrefactor18 = sumOfWW18/(sumOfW1st18*sumOfW2nd18);
3900    // finally, store "weighted" covariance:
3901    fIntFlowCovariancesNUA->SetBinContent(18,wPrefactor18*covariance18); 
3902   } // end of if(TMath::Abs(denominator18)>0.) 
3903  } // end of if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
3904
3905  // Cov(<sin(phi1)>,<sin(phi1+phi2)>):
3906  Double_t product19 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(19); // <<sin(phi1)><sin(phi1+phi2)>> 
3907  Double_t term1st19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3908  Double_t term2nd19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3909  Double_t sumOfW1st19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3910  Double_t sumOfW2nd19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3911  Double_t sumOfWW19 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(19); // W_{<sin(phi1)>} * W_{<sin(phi1+phi2)>}
3912  // numerator in the expression for the the unbiased estimator for covariance:
3913  Double_t numerator19 = product19 - term1st19*term2nd19; 
3914  // denominator in the expression for the the unbiased estimator for covariance:
3915  Double_t denominator19 = 0.;
3916  if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.) 
3917  { 
3918   denominator19 = 1.-sumOfWW19/(sumOfW1st19*sumOfW2nd19);
3919   if(TMath::Abs(denominator19)>0.) 
3920   {   
3921    // covariance:
3922    Double_t covariance19 = numerator19/denominator19;
3923    // weight dependent prefactor for covariance:
3924    Double_t wPrefactor19 = sumOfWW19/(sumOfW1st19*sumOfW2nd19);
3925    // finally, store "weighted" covariance:
3926    fIntFlowCovariancesNUA->SetBinContent(19,wPrefactor19*covariance19);
3927   } // end of if(TMath::Abs(denominator19)>0.)
3928  } // end of if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.)
3929  
3930  // Cov(<sin(phi1)>,<cos(phi1-phi2-phi3)>):
3931  Double_t product20 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(20); // <<sin(phi1)><cos(phi1-phi2-phi3)>> 
3932  Double_t term1st20 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3933  Double_t term2nd20 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3934  Double_t sumOfW1st20 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3935  Double_t sumOfW2nd20 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3936  Double_t sumOfWW20 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(20); // W_{<sin(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
3937  // numerator in the expression for the the unbiased estimator for covariance:
3938  Double_t numerator20 = product20 - term1st20*term2nd20; 
3939  // denominator in the expression for the the unbiased estimator for covariance:
3940  Double_t denominator20 = 0.;
3941  if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
3942  { 
3943   denominator20 = 1.-sumOfWW20/(sumOfW1st20*sumOfW2nd20);
3944   if(TMath::Abs(denominator20)>0.) 
3945   { 
3946    // covariance:
3947    Double_t covariance20 = numerator20/denominator20;
3948    // weight dependent prefactor for covariance:
3949    Double_t wPrefactor20 = sumOfWW20/(sumOfW1st20*sumOfW2nd20);
3950    // finally, store "weighted" covariance:
3951    fIntFlowCovariancesNUA->SetBinContent(20,wPrefactor20*covariance20);
3952   } // end of if(TMath::Abs(denominator20)>0.) 
3953  } // end of if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
3954
3955  // Cov(<sin(phi1)>,<sin(phi1-phi2-phi3)>):
3956  Double_t product21 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(21); // <<sin(phi1)><sin(phi1-phi2-phi3)>> 
3957  Double_t term1st21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3958  Double_t term2nd21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3959  Double_t sumOfW1st21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3960  Double_t sumOfW2nd21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3961  Double_t sumOfWW21 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(21); // W_{<sin(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
3962  // numerator in the expression for the the unbiased estimator for covariance:
3963  Double_t numerator21 = product21 - term1st21*term2nd21; 
3964  // denominator in the expression for the the unbiased estimator for covariance:
3965  Double_t denominator21 = 0.;
3966  if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
3967  { 
3968   denominator21 = 1.-sumOfWW21/(sumOfW1st21*sumOfW2nd21);
3969   if(TMath::Abs(denominator21)>0.) 
3970   {   
3971    // covariance:
3972    Double_t covariance21 = numerator21/denominator21;
3973    // weight dependent prefactor for covariance:
3974    Double_t wPrefactor21 = sumOfWW21/(sumOfW1st21*sumOfW2nd21);
3975    // finally, store "weighted" covariance:
3976    fIntFlowCovariancesNUA->SetBinContent(21,wPrefactor21*covariance21);
3977   } // end of if(TMath::Abs(denominator21)>0.)
3978  } // end of if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
3979
3980  // Cov(<cos(phi1+phi2)>,<sin(phi1+phi2)>):
3981  Double_t product22 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(22); // <<cos(phi1+phi2)><sin(phi1+phi2)>> 
3982  Double_t term1st22 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3983  Double_t term2nd22 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3984  Double_t sumOfW1st22 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3985  Double_t sumOfW2nd22 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3986  Double_t sumOfWW22 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(22); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1+phi2)>}
3987  // numerator in the expression for the the unbiased estimator for covariance:
3988  Double_t numerator22 = product22 - term1st22*term2nd22; 
3989  // denominator in the expression for the the unbiased estimator for covariance:
3990  Double_t denominator22 = 0.;
3991  if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.)
3992  { 
3993   denominator22 = 1.-sumOfWW22/(sumOfW1st22*sumOfW2nd22);
3994   if(TMath::Abs(denominator22)>0.) 
3995   {   
3996    // covariance:
3997    Double_t covariance22 = numerator22/denominator22;
3998    // weight dependent prefactor for covariance:
3999    Double_t wPrefactor22 = sumOfWW22/(sumOfW1st22*sumOfW2nd22);
4000    // finally, store "weighted" covariance:
4001    fIntFlowCovariancesNUA->SetBinContent(22,wPrefactor22*covariance22);
4002   } // end of if(TMath::Abs(denominator22)>0.) 
4003  } // end of if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.) 
4004
4005  // Cov(<cos(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
4006  Double_t product23 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(23); // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>> 
4007  Double_t term1st23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4008  Double_t term2nd23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4009  Double_t sumOfW1st23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4010  Double_t sumOfW2nd23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4011  Double_t sumOfWW23 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(23); // W_{<cos(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
4012  // numerator in the expression for the the unbiased estimator for covariance:
4013  Double_t numerator23 = product23 - term1st23*term2nd23; 
4014  // denominator in the expression for the the unbiased estimator for covariance:
4015  Double_t denominator23 = 0.;
4016  if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
4017  {  
4018   denominator23 = 1.-sumOfWW23/(sumOfW1st23*sumOfW2nd23);
4019   if(TMath::Abs(denominator23)>0.) 
4020   {   
4021    // covariance:
4022    Double_t covariance23 = numerator23/denominator23;
4023    // weight dependent prefactor for covariance:
4024    Double_t wPrefactor23 = sumOfWW23/(sumOfW1st23*sumOfW2nd23);
4025    // finally, store "weighted" covariance:
4026    fIntFlowCovariancesNUA->SetBinContent(23,wPrefactor23*covariance23);
4027   } // end of if(TMath::Abs(denominator23)>0.) 
4028  } // end of if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
4029  
4030  // Cov(<cos(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4031  Double_t product24 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(24); // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4032  Double_t term1st24 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4033  Double_t term2nd24 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4034  Double_t sumOfW1st24 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4035  Double_t sumOfW2nd24 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4036  Double_t sumOfWW24 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(24); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4037  // numerator in the expression for the the unbiased estimator for covariance:
4038  Double_t numerator24 = product24 - term1st24*term2nd24; 
4039  // denominator in the expression for the the unbiased estimator for covariance:
4040  Double_t denominator24 = 0.;
4041  if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4042  {   
4043   denominator24 = 1.-sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4044   if(TMath::Abs(denominator24)>0.) 
4045   {   
4046    // covariance:
4047    Double_t covariance24 = numerator24/denominator24;
4048    // weight dependent prefactor for covariance:
4049    Double_t wPrefactor24 = sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4050    // finally, store "weighted" covariance:
4051    fIntFlowCovariancesNUA->SetBinContent(24,wPrefactor24*covariance24);
4052   } // end of if(TMath::Abs(denominator24)>0.)  
4053  } // end of if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4054
4055  // Cov(<sin(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
4056  Double_t product25 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(25); // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>> 
4057  Double_t term1st25 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4058  Double_t term2nd25 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4059  Double_t sumOfW1st25 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4060  Double_t sumOfW2nd25 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4061  Double_t sumOfWW25 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(25); // W_{<sin(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
4062  // numerator in the expression for the the unbiased estimator for covariance:
4063  Double_t numerator25 = product25 - term1st25*term2nd25; 
4064  // denominator in the expression for the the unbiased estimator for covariance:
4065  Double_t denominator25 = 0.;
4066  if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4067  { 
4068   denominator25 = 1.-sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4069   if(TMath::Abs(denominator25)>0.) 
4070   { 
4071    // covariance:
4072    Double_t covariance25 = numerator25/denominator25;
4073    // weight dependent prefactor for covariance:
4074    Double_t wPrefactor25 = sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4075    // finally, store "weighted" covariance:
4076    fIntFlowCovariancesNUA->SetBinContent(25,wPrefactor25*covariance25);
4077   } // end of if(TMath::Abs(denominator25)>0.)
4078  } // end of if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4079  
4080  // Cov(<sin(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4081  Double_t product26 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(26); // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4082  Double_t term1st26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4083  Double_t term2nd26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4084  Double_t sumOfW1st26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4085  Double_t sumOfW2nd26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4086  Double_t sumOfWW26 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(26); // W_{<sin(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4087  // numerator in the expression for the the unbiased estimator for covariance:
4088  Double_t numerator26 = product26 - term1st26*term2nd26; 
4089  // denominator in the expression for the the unbiased estimator for covariance:
4090  Double_t denominator26 = 0.;
4091  if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4092  { 
4093   denominator26 = 1.-sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4094   if(TMath::Abs(denominator26)>0.) 
4095   { 
4096    // covariance:
4097    Double_t covariance26 = numerator26/denominator26;
4098    // weight dependent prefactor for covariance:
4099    Double_t wPrefactor26 = sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4100    // finally, store "weighted" covariance:
4101    fIntFlowCovariancesNUA->SetBinContent(26,wPrefactor26*covariance26);
4102   } // end of if(TMath::Abs(denominator26)>0.) 
4103  } // end of if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4104  
4105  // Cov(<cos(phi1-phi2-phi3)>,<sin(phi1-phi2-phi3)>):
4106  Double_t product27 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(27); // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>> 
4107  Double_t term1st27 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4108  Double_t term2nd27 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4109  Double_t sumOfW1st27 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4110  Double_t sumOfW2nd27 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4111  Double_t sumOfWW27 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(27); // W_{<cos(phi1-phi2-phi3)>} * W_{<sin(phi1-phi2-phi3)>}
4112  // numerator in the expression for the the unbiased estimator for covariance:
4113  Double_t numerator27 = product27 - term1st27*term2nd27; 
4114  // denominator in the expression for the the unbiased estimator for covariance:
4115  Double_t denominator27 = 0.;
4116  if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4117  { 
4118   denominator27 = 1.-sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4119   if(TMath::Abs(denominator27)>0.) 
4120   { 
4121    // covariance:
4122    Double_t covariance27 = numerator27/denominator27;
4123    // weight dependent prefactor for covariance:
4124    Double_t wPrefactor27 = sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4125    // finally, store "weighted" covariance:
4126    fIntFlowCovariancesNUA->SetBinContent(27,wPrefactor27*covariance27);
4127   } // end of if(TMath::Abs(denominator27)>0.) 
4128  } // end of if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4129  
4130 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
4131
4132 //================================================================================================================================
4133
4134 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow() 
4135 {
4136  // From profile fIntFlowCorrelationsPro access measured correlations and spread, 
4137  // correctly calculate the statistical errors and store the final results and 
4138  // statistical errors for correlations in histogram fIntFlowCorrelationsHist.
4139  //
4140  // Remark: Statistical error of correlation is calculated as:
4141  //
4142  //          statistical error = termA * spread * termB:
4143  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
4144  //          termB = 1/sqrt(1-termA^2)   
4145  //
4146    
4147  for(Int_t ci=1;ci<=4;ci++) // correlation index
4148  {
4149   if(fIntFlowCorrelationsPro->GetBinEffectiveEntries(ci) < 2 || fIntFlowSquaredCorrelationsPro->GetBinEffectiveEntries(ci) < 2)
4150   {
4151    fIntFlowCorrelationsPro->SetBinError(ci,0.);
4152    fIntFlowSquaredCorrelationsPro->SetBinError(ci,0.);
4153    continue;
4154   } 
4155   Double_t correlation = fIntFlowCorrelationsPro->GetBinContent(ci);
4156   Double_t squaredCorrelation = fIntFlowSquaredCorrelationsPro->GetBinContent(ci);
4157   Double_t spread = 0.;
4158   if(squaredCorrelation-correlation*correlation >= 0.)
4159   {
4160    spread = pow(squaredCorrelation-correlation*correlation,0.5);
4161   } else
4162     {
4163      cout<<endl;
4164      cout<<Form(" WARNING: Imaginary 'spread' for %d-particle correlation!!!! ",2*ci)<<endl;
4165      cout<<endl;
4166     }
4167   Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeights[0]->GetBinContent(ci);
4168   Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeights[1]->GetBinContent(ci);
4169   Double_t termA = 0.;
4170   Double_t termB = 0.;
4171   if(TMath::Abs(sumOfLinearEventWeights) > 0.) // to be improved - shall I omitt here Abs() ?
4172   {
4173    termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
4174   } else
4175     {
4176      cout<<endl;
4177      cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;
4178      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4179      cout<<endl;
4180     }
4181   if(1.-pow(termA,2.) > 0.)
4182   {
4183    termB = 1./pow(1-pow(termA,2.),0.5);
4184   } else
4185     {
4186      cout<<endl;
4187      cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;   
4188      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4189      cout<<endl;
4190     }     
4191   Double_t statisticalError = termA * spread * termB;
4192   fIntFlowCorrelationsHist->SetBinContent(ci,correlation);
4193   fIntFlowCorrelationsHist->SetBinError(ci,statisticalError);
4194  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index     
4195  
4196  // Versus multiplicity: 
4197  if(!fCalculateCumulantsVsM){return;}
4198  for(Int_t ci=0;ci<=3;ci++) // correlation index
4199  {
4200   Int_t nBins = fIntFlowCorrelationsVsMPro[ci]->GetNbinsX(); 
4201   for(Int_t b=1;b<=nBins;b++) // looping over multiplicity bins
4202   {
4203    if(fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2 || fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2)
4204    {
4205     fIntFlowCorrelationsVsMPro[ci]->SetBinError(b,0.);
4206     fIntFlowSquaredCorrelationsVsMPro[ci]->SetBinError(b,0.);
4207     continue;
4208    } 
4209    Double_t correlationVsM = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
4210    Double_t squaredCorrelationVsM = fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinContent(b);
4211    Double_t spreadVsM = 0.;
4212    if(squaredCorrelationVsM-correlationVsM*correlationVsM >= 0.)
4213    {
4214     spreadVsM = pow(squaredCorrelationVsM-correlationVsM*correlationVsM,0.5);
4215    } else
4216      {
4217       cout<<endl;
4218       cout<<Form(" WARNING (QC): Imaginary 'spreadVsM' for ci = %d, bin = %d, entries = %f !!!!",
4219                  ci,b,fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b))<<endl; 
4220       cout<<endl;
4221      }     
4222    Double_t sumOfLinearEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][0]->GetBinContent(b);
4223    Double_t sumOfQuadraticEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][1]->GetBinContent(b);
4224    Double_t termAVsM = 0.;
4225    Double_t termBVsM = 0.;
4226    if(sumOfLinearEventWeightsVsM > 0.) 
4227    {
4228     termAVsM = pow(sumOfQuadraticEventWeightsVsM,0.5)/sumOfLinearEventWeightsVsM;
4229    }
4230    if(1.-pow(termAVsM,2.) > 0.)
4231    {
4232     termBVsM = 1./pow(1-pow(termAVsM,2.),0.5);
4233    }     
4234    Double_t statisticalErrorVsM = termAVsM * spreadVsM * termBVsM;
4235    fIntFlowCorrelationsVsMHist[ci]->SetBinContent(b,correlationVsM);
4236    fIntFlowCorrelationsVsMHist[ci]->SetBinError(b,statisticalErrorVsM);  
4237   } // end of for(Int_t b=1;b<=nBins;b++)
4238  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index                                                        
4239                                                                                                                            
4240 } // end of AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow()
4241
4242 //================================================================================================================================
4243
4244 void AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(Int_t nRP)
4245 {
4246  // Fill profile fAverageMultiplicity to hold average multiplicities and 
4247  // number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
4248  
4249  // Binning of fAverageMultiplicity is organized as follows:
4250  //  1st bin: all events (including the empty ones)
4251  //  2nd bin: event with # of RPs greater or equal to 1
4252  //  3rd bin: event with # of RPs greater or equal to 2
4253  //  4th bin: event with # of RPs greater or equal to 3
4254  //  5th bin: event with # of RPs greater or equal to 4
4255  //  6th bin: event with # of RPs greater or equal to 5
4256  //  7th bin: event with # of RPs greater or equal to 6
4257  //  8th bin: event with # of RPs greater or equal to 7
4258  //  9th bin: event with # of RPs greater or equal to 8
4259  
4260  if(nRP<0)
4261  {
4262   cout<<endl;
4263   cout<<" WARNING (QC): nRP<0 in in AFAWQC::FAM() !!!!"<<endl;
4264   cout<<endl;
4265   exit(0);
4266  }
4267  
4268  for(Int_t i=0;i<9;i++)
4269  {
4270   if(nRP>=i){fAvMultiplicity->Fill(i+0.5,nRP,1);}
4271  }
4272  
4273 } // end of AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(nRP)
4274
4275 //================================================================================================================================
4276
4277 void AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
4278
4279  // a) Calculate Q-cumulants from the measured multiparticle correlations;
4280  // b) Propagate the statistical errors from measured multiparticle correlations to statistical errors of Q-cumulants;  
4281  // c) Remark: Q-cumulants calculated in this method are biased by non-uniform acceptance of detector !!!! 
4282  //            Method CalculateQcumulantsCorrectedForNUAIntFlow() is called afterwards to correct for this bias;
4283  // d) Store the results and statistical error of Q-cumulants in histogram fIntFlowQcumulants.
4284  //    Binning of fIntFlowQcumulants is organized as follows:
4285  //
4286  //            1st bin: QC{2}
4287  //            2nd bin: QC{4}
4288  //            3rd bin: QC{6}
4289  //            4th bin: QC{8}
4290  //
4291  
4292  // Correlations:
4293  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
4294  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
4295  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
4296  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
4297  // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
4298  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
4299  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
4300  Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
4301  Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
4302  // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
4303  Double_t wCov24 = 0.; // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4304  Double_t wCov26 = 0.; // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4305  Double_t wCov28 = 0.; // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4306  Double_t wCov46 = 0.; // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4307  Double_t wCov48 = 0.; // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4308  Double_t wCov68 = 0.; // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>)  
4309  if(!fForgetAboutCovariances)
4310  {
4311   wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4312   wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4313   wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4314   wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4315   wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4316   wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
4317  }
4318  // Q-cumulants: 
4319  Double_t qc2 = 0.; // QC{2}
4320  Double_t qc4 = 0.; // QC{4}
4321  Double_t qc6 = 0.; // QC{6}
4322  Double_t qc8 = 0.; // QC{8}
4323  if(TMath::Abs(two) > 0.){qc2 = two;} 
4324  if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
4325  if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
4326  if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);} 
4327  // Statistical errors of Q-cumulants:       
4328  Double_t qc2Error = 0.;
4329  Double_t qc4Error = 0.;
4330  Double_t qc6Error = 0.;
4331  Double_t qc8Error = 0.; 
4332  // Squared statistical errors of Q-cumulants:       
4333  //Double_t qc2ErrorSquared = 0.;
4334  Double_t qc4ErrorSquared = 0.;
4335  Double_t qc6ErrorSquared = 0.;
4336  Double_t qc8ErrorSquared = 0.;        
4337  // Statistical error of QC{2}:              
4338  qc2Error = twoError;                                                 
4339  // Statistical error of QC{4}:              
4340  qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
4341                  - 8.*two*wCov24;                     
4342  if(qc4ErrorSquared>0.)
4343  {
4344   qc4Error = pow(qc4ErrorSquared,0.5);
4345  } else 
4346    {
4347     cout<<" WARNING (QC): Statistical error of QC{4} is imaginary !!!!"<<endl;
4348    }                                           
4349  // Statistical error of QC{6}:              
4350  qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
4351                  + 81.*pow(two,2.)*pow(fourError,2.)
4352                  + pow(sixError,2.)
4353                  - 162.*two*(4.*pow(two,2.)-four)*wCov24
4354                  + 18.*(4.*pow(two,2.)-four)*wCov26
4355                  - 18.*two*wCov46;                     
4356  if(qc6ErrorSquared>0.)
4357  {
4358   qc6Error = pow(qc6ErrorSquared,0.5);
4359  } else 
4360    {
4361     cout<<" WARNING (QC): Statistical error of QC{6} is imaginary !!!!"<<endl;
4362    }                       
4363  // Statistical error of QC{8}:              
4364  qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
4365                  + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
4366                  + 256.*pow(two,2.)*pow(sixError,2.)
4367                  + pow(eightError,2.)
4368                  - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
4369                  + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
4370                  - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
4371                  - 1152.*two*(4.*pow(two,2.)-four)*wCov46
4372                  + 72.*(4.*pow(two,2.)-four)*wCov48
4373                  - 32.*two*wCov68;      
4374  if(qc8ErrorSquared>0.)
4375  {
4376   qc8Error = pow(qc8ErrorSquared,0.5);
4377  } else 
4378    {
4379     cout<<"WARNING (QC): Statistical error of QC{8} is imaginary !!!!"<<endl;
4380    }
4381  // Store the results and statistical errors for Q-cumulants:
4382  if(TMath::Abs(qc2)>0.)
4383  {
4384   fIntFlowQcumulants->SetBinContent(1,qc2);
4385   fIntFlowQcumulants->SetBinError(1,qc2Error);
4386  }
4387  if(TMath::Abs(qc4)>0.)
4388  {
4389   fIntFlowQcumulants->SetBinContent(2,qc4);
4390   fIntFlowQcumulants->SetBinError(2,qc4Error);
4391  }
4392  if(TMath::Abs(qc6)>0.)
4393  {
4394   fIntFlowQcumulants->SetBinContent(3,qc6);
4395   fIntFlowQcumulants->SetBinError(3,qc6Error);
4396  }
4397  if(TMath::Abs(qc8)>0.)
4398  {
4399   fIntFlowQcumulants->SetBinContent(4,qc8); 
4400   fIntFlowQcumulants->SetBinError(4,qc8Error);
4401  } 
4402  
4403  // Versus multiplicity: 
4404  if(!fCalculateCumulantsVsM){return;}
4405  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
4406  Double_t value[4] = {0.}; // QCs vs M
4407  Double_t error[4] = {0.}; // error of QCs vs M
4408  Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
4409  Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
4410  for(Int_t b=1;b<=nBins;b++)
4411  {
4412   // Correlations:
4413   two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> 
4414   four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>>  
4415   six = fIntFlowCorrelationsVsMHist[2]->GetBinContent(b); // <<6>> 
4416   eight = fIntFlowCorrelationsVsMHist[3]->GetBinContent(b); // <<8>>  
4417   // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
4418   twoError = fIntFlowCorrelationsVsMHist[0]->GetBinError(b); // statistical error of <2>  
4419   fourError = fIntFlowCorrelationsVsMHist[1]->GetBinError(b); // statistical error of <4>   
4420   sixError = fIntFlowCorrelationsVsMHist[2]->GetBinError(b); // statistical error of <6> 
4421   eightError = fIntFlowCorrelationsVsMHist[3]->GetBinError(b); // statistical error of <8> 
4422   // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
4423   if(!fForgetAboutCovariances)
4424   {
4425    wCov24 = fIntFlowCovariancesVsM[0]->GetBinContent(b); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4426    wCov26 = fIntFlowCovariancesVsM[1]->GetBinContent(b); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4427    wCov28 = fIntFlowCovariancesVsM[2]->GetBinContent(b); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4428    wCov46 = fIntFlowCovariancesVsM[3]->GetBinContent(b); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4429    wCov48 = fIntFlowCovariancesVsM[4]->GetBinContent(b); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4430    wCov68 = fIntFlowCovariancesVsM[5]->GetBinContent(b); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
4431   }
4432   // Q-cumulants: 
4433   qc2 = 0.; // QC{2}
4434   qc4 = 0.; // QC{4}
4435   qc6 = 0.; // QC{6}
4436   qc8 = 0.; // QC{8}
4437   if(TMath::Abs(two) > 0.){qc2 = two;} 
4438   if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
4439   if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
4440   if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);}  
4441   // Statistical errors of Q-cumulants:       
4442   qc2Error = 0.;
4443   qc4Error = 0.;
4444   qc6Error = 0.;
4445   qc8Error = 0.; 
4446   // Squared statistical errors of Q-cumulants:       
4447   //Double_t qc2ErrorSquared = 0.;
4448   qc4ErrorSquared = 0.;
4449   qc6ErrorSquared = 0.;
4450   qc8ErrorSquared = 0.;    
4451   // Statistical error of QC{2}:              
4452   qc2Error = twoError;                                             
4453   // Statistical error of QC{4}:              
4454   qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
4455                   - 8.*two*wCov24;                     
4456   if(qc4ErrorSquared>0.)
4457   {
4458    qc4Error = pow(qc4ErrorSquared,0.5);
4459   } else 
4460     {
4461      // cout<<"WARNING: Statistical error of QC{4} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4462     }                                       
4463   // Statistical error of QC{6}:              
4464   qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
4465                   + 81.*pow(two,2.)*pow(fourError,2.)
4466                   + pow(sixError,2.)
4467                   - 162.*two*(4.*pow(two,2.)-four)*wCov24
4468                   + 18.*(4.*pow(two,2.)-four)*wCov26
4469                   - 18.*two*wCov46;                     
4470   if(qc6ErrorSquared>0.)
4471   {
4472    qc6Error = pow(qc6ErrorSquared,0.5);
4473   } else 
4474     {
4475      // cout<<"WARNING: Statistical error of QC{6} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4476     }                            
4477   // Statistical error of QC{8}:              
4478   qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
4479                   + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
4480                   + 256.*pow(two,2.)*pow(sixError,2.)
4481                   + pow(eightError,2.)
4482                   - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
4483                   + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
4484                   - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
4485                   - 1152.*two*(4.*pow(two,2.)-four)*wCov46
4486                   + 72.*(4.*pow(two,2.)-four)*wCov48
4487                   - 32.*two*wCov68;      
4488   if(qc8ErrorSquared>0.)
4489   {
4490    qc8Error = pow(qc8ErrorSquared,0.5);
4491   } else 
4492     {
4493      // cout<<"WARNING: Statistical error of QC{8} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4494     }
4495   // Store the results and statistical errors for Q-cumulants:
4496   if(TMath::Abs(qc2)>0.)
4497   {
4498    fIntFlowQcumulantsVsM[0]->SetBinContent(b,qc2);
4499    fIntFlowQcumulantsVsM[0]->SetBinError(b,qc2Error);  
4500   }
4501   if(TMath::Abs(qc4)>0.)
4502   {
4503    fIntFlowQcumulantsVsM[1]->SetBinContent(b,qc4);  
4504    fIntFlowQcumulantsVsM[1]->SetBinError(b,qc4Error);
4505   }
4506   if(TMath::Abs(qc6)>0.)
4507   {
4508    fIntFlowQcumulantsVsM[2]->SetBinContent(b,qc6); 
4509    fIntFlowQcumulantsVsM[2]->SetBinError(b,qc6Error);
4510   }
4511   if(TMath::Abs(qc8)>0.)
4512   {  
4513    fIntFlowQcumulantsVsM[3]->SetBinContent(b,qc8);
4514    fIntFlowQcumulantsVsM[3]->SetBinError(b,qc8Error);
4515   } 
4516   // Rebin in M:
4517   for(Int_t co=0;co<4;co++)
4518   {
4519    if(fIntFlowCorrelationsVsMPro[co]->GetBinEffectiveEntries(b)<2){continue;}
4520    value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
4521    error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
4522    if(error[co]>0.)
4523    {
4524     dSum1[co]+=value[co]/(error[co]*error[co]);
4525     dSum2[co]+=1./(error[co]*error[co]);
4526    }
4527   } // end of for(Int_t co=0;co<4;co++) 
4528  } // end of for(Int_t b=1;b<=nBins;b++)
4529  // Store rebinned Q-cumulants:
4530  for(Int_t co=0;co<4;co++)
4531  {
4532   if(dSum2[co]>0.)
4533   {
4534    fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
4535    fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
4536   }
4537  } // end of for(Int_t co=0;co<4;co++)
4538  
4539 } // end of AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
4540
4541 //================================================================================================================================ 
4542
4543 void AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
4544 {
4545  // a) Calculate the final results for reference flow estimates from Q-cumulants;
4546  // b) Propagate the statistical errors to reference flow estimates from statistical error of Q-cumulants; 
4547  // c) Store the results and statistical errors of reference flow estimates in histogram fIntFlow.
4548  //    Binning of fIntFlow is organized as follows:
4549  //
4550  //            1st bin: v{2,QC}
4551  //            2nd bin: v{4,QC}
4552  //            3rd bin: v{6,QC}
4553  //            4th bin: v{8,QC}
4554  //
4555  
4556  // Reference flow estimates:
4557  Double_t v2 = 0.; // v{2,QC}  
4558  Double_t v4 = 0.; // v{4,QC}  
4559  Double_t v6 = 0.; // v{6,QC}  
4560  Double_t v8 = 0.; // v{8,QC}
4561  // Reference flow's statistical errors:
4562  Double_t v2Error = 0.; // v{2,QC} stat. error 
4563  Double_t v4Error = 0.; // v{4,QC} stat. error
4564  Double_t v6Error = 0.; // v{6,QC} stat. error
4565  Double_t v8Error = 0.; // v{8,QC} stat. error
4566   
4567  // Q-cumulants:
4568  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
4569  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
4570  Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
4571  Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
4572  // Q-cumulants's statistical errors: 
4573  Double_t qc2Error = fIntFlowQcumulants->GetBinError(1); // QC{2} stat. error  
4574  Double_t qc4Error = fIntFlowQcumulants->GetBinError(2); // QC{4} stat. error  
4575  Double_t qc6Error = fIntFlowQcumulants->GetBinError(3); // QC{6} stat. error  
4576  Double_t qc8Error = fIntFlowQcumulants->GetBinError(4); // QC{8} stat. error
4577  // Calculate reference flow estimates from Q-cumulants: 
4578  if(qc2>=0.){v2 = pow(qc2,1./2.);} 
4579  if(qc4<=0.){v4 = pow(-1.*qc4,1./4.);} 
4580  if(qc6>=0.){v6 = pow((1./4.)*qc6,1./6.);}
4581  if(qc8<=0.){v8 = pow((-1./33.)*qc8,1./8.);}  
4582  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants:  
4583  if(qc2>0.){v2Error = (1./2.)*pow(qc2,-1./2.)*qc2Error;} 
4584  if(qc4<0.){v4Error = (1./4.)*pow(-qc4,-3./4.)*qc4Error;} 
4585  if(qc6>0.){v6Error = (1./6.)*pow(2.,-1./3.)*pow(qc6,-5./6.)*qc6Error;}   
4586  if(qc8<0.){v8Error = (1./8.)*pow(33.,-1./8.)*pow(-qc8,-7./8.)*qc8Error;}   
4587  // Print warnings for the 'wrong sign' cumulants: 
4588  if(TMath::Abs(v2) < 1.e-44)
4589  {
4590   cout<<" WARNING: Wrong sign QC{2}, couldn't calculate v{2,QC} !!!!"<<endl;
4591  }
4592  if(TMath::Abs(v4) < 1.e-44)
4593  {
4594   cout<<" WARNING: Wrong sign QC{4}, couldn't calculate v{4,QC} !!!!"<<endl;
4595  } 
4596  if(TMath::Abs(v6) < 1.e-44)
4597  {
4598   cout<<" WARNING: Wrong sign QC{6}, couldn't calculate v{6,QC} !!!!"<<endl; 
4599  }
4600  if(TMath::Abs(v8) < 1.e-44)
4601  {
4602   cout<<" WARNING: Wrong sign QC{8}, couldn't calculate v{8,QC} !!!!"<<endl;
4603  }                       
4604  // Store the results and statistical errors of integrated flow estimates:
4605  fIntFlow->SetBinContent(1,v2);
4606  fIntFlow->SetBinError(1,v2Error);
4607  fIntFlow->SetBinContent(2,v4);
4608  fIntFlow->SetBinError(2,v4Error);
4609  fIntFlow->SetBinContent(3,v6);
4610  fIntFlow->SetBinError(3,v6Error);
4611  fIntFlow->SetBinContent(4,v8);
4612  fIntFlow->SetBinError(4,v8Error);  
4613   
4614  // Versus multiplicity: 
4615  if(!fCalculateCumulantsVsM){return;} 
4616  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
4617  for(Int_t b=1;b<=nBins;b++)
4618  {
4619   // Q-cumulants:
4620   Double_t qc2VsM = fIntFlowQcumulantsVsM[0]->GetBinContent(b); // QC{2}  
4621   Double_t qc4VsM = fIntFlowQcumulantsVsM[1]->GetBinContent(b); // QC{4}  
4622   Double_t qc6VsM = fIntFlowQcumulantsVsM[2]->GetBinContent(b); // QC{6}  
4623   Double_t qc8VsM = fIntFlowQcumulantsVsM[3]->GetBinContent(b); // QC{8}
4624   // Q-cumulants's statistical errors: 
4625   Double_t qc2ErrorVsM = fIntFlowQcumulantsVsM[0]->GetBinError(b); // QC{2} stat. error  
4626   Double_t qc4ErrorVsM = fIntFlowQcumulantsVsM[1]->GetBinError(b); // QC{4} stat. error  
4627   Double_t qc6ErrorVsM = fIntFlowQcumulantsVsM[2]->GetBinError(b); // QC{6} stat. error  
4628   Double_t qc8ErrorVsM = fIntFlowQcumulantsVsM[3]->GetBinError(b); // QC{8} stat. error
4629   // Reference flow estimates:
4630   Double_t v2VsM = 0.; // v{2,QC}  
4631   Double_t v4VsM = 0.; // v{4,QC}  
4632   Double_t v6VsM = 0.; // v{6,QC}  
4633   Double_t v8VsM = 0.; // v{8,QC}
4634   // Reference flow estimates errors:
4635   Double_t v2ErrorVsM = 0.; // v{2,QC} stat. error  
4636   Double_t v4ErrorVsM = 0.; // v{4,QC} stat. error
4637   Double_t v6ErrorVsM = 0.; // v{6,QC} stat. error  
4638   Double_t v8ErrorVsM = 0.; // v{8,QC} stat. error
4639   // Calculate reference flow estimates from Q-cumulants: 
4640   if(qc2VsM>=0.){v2VsM = pow(qc2VsM,1./2.);} 
4641   if(qc4VsM<=0.){v4VsM = pow(-1.*qc4VsM,1./4.);} 
4642   if(qc6VsM>=0.){v6VsM = pow((1./4.)*qc6VsM,1./6.);}
4643   if(qc8VsM<=0.){v8VsM = pow((-1./33.)*qc8VsM,1./8.);}  
4644   // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
4645   if(qc2VsM>0.){v2ErrorVsM = (1./2.)*pow(qc2VsM,-1./2.)*qc2ErrorVsM;} 
4646   if(qc4VsM<0.){v4ErrorVsM = (1./4.)*pow(-qc4VsM,-3./4.)*qc4ErrorVsM;} 
4647   if(qc6VsM>0.){v6ErrorVsM = (1./6.)*pow(2.,-1./3.)*pow(qc6VsM,-5./6.)*qc6ErrorVsM;}   
4648   if(qc8VsM<0.){v8ErrorVsM = (1./8.)*pow(33.,-1./8.)*pow(-qc8VsM,-7./8.)*qc8ErrorVsM;}                       
4649   // Store the results and statistical errors of integrated flow estimates:
4650   fIntFlowVsM[0]->SetBinContent(b,v2VsM);
4651   fIntFlowVsM[0]->SetBinError(b,v2ErrorVsM);
4652   fIntFlowVsM[1]->SetBinContent(b,v4VsM);
4653   fIntFlowVsM[1]->SetBinError(b,v4ErrorVsM);
4654   fIntFlowVsM[2]->SetBinContent(b,v6VsM);
4655   fIntFlowVsM[2]->SetBinError(b,v6ErrorVsM);
4656   fIntFlowVsM[3]->SetBinContent(b,v8VsM);
4657   fIntFlowVsM[3]->SetBinError(b,v8ErrorVsM);
4658  } // end of for(Int_t b=1;b<=nBins;b++)
4659  
4660  // 'Rebinned in M' calculation: // to be improved - this can be implemented better:   
4661  // Reference flow estimates:
4662  Double_t v2RebinnedInM = 0.; // v{2,QC}  
4663  Double_t v4RebinnedInM = 0.; // v{4,QC}  
4664  Double_t v6RebinnedInM = 0.; // v{6,QC}  
4665  Double_t v8RebinnedInM = 0.; // v{8,QC}
4666  // Reference flow's statistical errors:
4667  Double_t v2ErrorRebinnedInM = 0.; // v{2,QC} stat. error 
4668  Double_t v4ErrorRebinnedInM = 0.; // v{4,QC} stat. error
4669  Double_t v6ErrorRebinnedInM = 0.; // v{6,QC} stat. error
4670  Double_t v8ErrorRebinnedInM = 0.; // v{8,QC} stat. error
4671  // Q-cumulants:
4672  Double_t qc2RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(1); // QC{2}  
4673  Double_t qc4RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(2); // QC{4}  
4674  Double_t qc6RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(3); // QC{6}  
4675  Double_t qc8RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(4); // QC{8}
4676  // Q-cumulants's statistical errors: 
4677  Double_t qc2ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(1); // QC{2} stat. error  
4678  Double_t qc4ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(2); // QC{4} stat. error  
4679  Double_t qc6ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(3); // QC{6} stat. error  
4680  Double_t qc8ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(4); // QC{8} stat. error
4681  // Calculate reference flow estimates from Q-cumulants: 
4682  if(qc2RebinnedInM>=0.){v2RebinnedInM = pow(qc2RebinnedInM,1./2.);} 
4683  if(qc4RebinnedInM<=0.){v4RebinnedInM = pow(-1.*qc4RebinnedInM,1./4.);} 
4684  if(qc6RebinnedInM>=0.){v6RebinnedInM = pow((1./4.)*qc6RebinnedInM,1./6.);}
4685  if(qc8RebinnedInM<=0.){v8RebinnedInM = pow((-1./33.)*qc8RebinnedInM,1./8.);}  
4686  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
4687  if(qc2RebinnedInM>0.){v2ErrorRebinnedInM = (1./2.)*pow(qc2RebinnedInM,-1./2.)*qc2ErrorRebinnedInM;} 
4688  if(qc4RebinnedInM<0.){v4ErrorRebinnedInM = (1./4.)*pow(-qc4RebinnedInM,-3./4.)*qc4ErrorRebinnedInM;} 
4689  if(qc6RebinnedInM>0.){v6ErrorRebinnedInM = (1./6.)*pow(2.,-1./3.)*pow(qc6RebinnedInM,-5./6.)*qc6ErrorRebinnedInM;}   
4690  if(qc8RebinnedInM<0.){v8ErrorRebinnedInM = (1./8.)*pow(33.,-1./8.)*pow(-qc8RebinnedInM,-7./8.)*qc8ErrorRebinnedInM;}   
4691  // Print warnings for the 'wrong sign' cumulants: 
4692  if(TMath::Abs(v2RebinnedInM) < 1.e-44)
4693  {
4694   cout<<" WARNING: Wrong sign QC{2} rebinned in M, couldn't calculate v{2,QC} !!!!"<<endl;
4695  }
4696  if(TMath::Abs(v4RebinnedInM) < 1.e-44)
4697  {
4698   cout<<" WARNING: Wrong sign QC{4} rebinned in M, couldn't calculate v{4,QC} !!!!"<<endl;
4699  }
4700  if(TMath::Abs(v6RebinnedInM) < 1.e-44)
4701  {
4702   cout<<" WARNING: Wrong sign QC{6} rebinned in M, couldn't calculate v{6,QC} !!!!"<<endl;
4703  }
4704  if(TMath::Abs(v8RebinnedInM) < 1.e-44)
4705  {
4706   cout<<" WARNING: Wrong sign QC{8} rebinned in M, couldn't calculate v{8,QC} !!!!"<<endl;
4707  }                       
4708  // Store the results and statistical errors of integrated flow estimates:
4709  fIntFlowRebinnedInM->SetBinContent(1,v2RebinnedInM);
4710  fIntFlowRebinnedInM->SetBinError(1,v2ErrorRebinnedInM);
4711  fIntFlowRebinnedInM->SetBinContent(2,v4RebinnedInM);
4712  fIntFlowRebinnedInM->SetBinError(2,v4ErrorRebinnedInM);
4713  fIntFlowRebinnedInM->SetBinContent(3,v6RebinnedInM);
4714  fIntFlowRebinnedInM->SetBinError(3,v6ErrorRebinnedInM);
4715  fIntFlowRebinnedInM->SetBinContent(4,v8RebinnedInM);
4716  fIntFlowRebinnedInM->SetBinError(4,v8ErrorRebinnedInM);    
4717   
4718 } // end of AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
4719
4720 //================================================================================================================================ 
4721
4722 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
4723 {
4724  // Fill in AliFlowCommonHistResults histograms relevant for reference flow.
4725  
4726  // There are two possibilities here:
4727  // a) Store minimum bias reference flow - use SetMinimumBiasReferenceFlow(kTRUE). This result is 
4728  //    biased by the interplay between nonflow correlations and multiplicity fluctuations and is 
4729  //    also stored in local histogram fIntFlow; 
4730  // b) Store reference flow obtained from flow analysis performed at fixed multiplicity and 
4731  //    rebinned only at the end of the day - use SetMinimumBiasReferenceFlow(kFALSE). This result
4732  //    is also stored in local histogram fIntFlowRebinnedInM.
4733  
4734  // Reference flow estimates:
4735  Double_t v[4] = {0.};
4736  // Statistical errors of reference flow estimates:
4737  Double_t vError[4] = {0.};
4738   
4739  for(Int_t b=0;b<4;b++)
4740  {
4741   if(fMinimumBiasReferenceFlow)
4742   { 
4743    v[b] = fIntFlow->GetBinContent(b+1);
4744    vError[b] = fIntFlow->GetBinError(b+1);
4745   } else
4746     {
4747      v[b] = fIntFlowRebinnedInM->GetBinContent(b+1);
4748      vError[b] = fIntFlowRebinnedInM->GetBinError(b+1);
4749     }
4750  } // end of for(Int_t b=0;b<4;b++)
4751   
4752  // Fill AliFlowCommonHistResults histogram:
4753  fCommonHistsResults2nd->FillIntegratedFlow(v[0],vError[0]); // to be improved (hardwired 2nd in the name)  
4754  fCommonHistsResults4th->FillIntegratedFlow(v[1],vError[1]); // to be improved (hardwired 4th in the name)
4755  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)) // to be improved (calculate also 6th and 8th order)
4756  {
4757   fCommonHistsResults6th->FillIntegratedFlow(v[2],vError[2]); // to be improved (hardwired 6th in the name)
4758   fCommonHistsResults8th->FillIntegratedFlow(v[3],vError[3]); // to be improved (hardwired 8th in the name) 
4759  }
4760  
4761 } // end of AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
4762
4763 //================================================================================================================================ 
4764
4765 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
4766 {
4767  // Calculate all correlations needed for integrated flow using particle weights.
4768   
4769  // Remark 1: When particle weights are used the binning of fIntFlowCorrelationAllPro is organized as follows:
4770  //
4771  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
4772  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
4773  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
4774  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
4775  //  5th bin:           ----  EMPTY ----
4776  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
4777  //  7th bin: <3>_{3n|2n,1n} = ...
4778  //  8th bin: <3>_{4n|2n,2n} = ...
4779  //  9th bin: <3>_{4n|3n,1n} = ...
4780  // 10th bin:           ----  EMPTY ----
4781  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
4782  // 12th bin: <4>_{2n,1n|2n,1n} = ...
4783  // 13th bin: <4>_{2n,2n|2n,2n} = ...
4784  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
4785  // 15th bin: <4>_{3n,1n|3n,1n} = ...
4786  // 16th bin: <4>_{3n,1n|2n,2n} = ...
4787  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
4788  // 18th bin:           ----  EMPTY ----
4789  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
4790  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
4791  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
4792  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
4793  // 23rd bin:           ----  EMPTY ----
4794  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
4795  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
4796  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
4797  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
4798  // 28th bin:           ----  EMPTY ----
4799  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
4800  // 30th bin:           ----  EMPTY ----
4801  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
4802  
4803  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
4804  // fIntFlowExtraCorrelationsPro binning of which is organized as follows:
4805  
4806  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
4807  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
4808  
4809  // multiplicity (number of particles used to determine the reaction plane)
4810  Double_t dMult = (*fSMpk)(0,0);
4811  
4812  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
4813  Double_t dReQ1n1k = (*fReQ)(0,1);
4814  Double_t dReQ2n2k = (*fReQ)(1,2);
4815  Double_t dReQ3n3k = (*fReQ)(2,3);
4816  Double_t dReQ4n4k = (*fReQ)(3,4);
4817  Double_t dReQ1n3k = (*fReQ)(0,3);
4818  Double_t dImQ1n1k = (*fImQ)(0,1);
4819  Double_t dImQ2n2k = (*fImQ)(1,2);
4820  Double_t dImQ3n3k = (*fImQ)(2,3);
4821  Double_t dImQ4n4k = (*fImQ)(3,4);
4822  Double_t dImQ1n3k = (*fImQ)(0,3);
4823
4824  // dMs are variables introduced in order to simplify some Eqs. bellow:
4825  //..............................................................................................
4826  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
4827  Double_t dM22 = (*fSMpk)(1,2)-(*fSMpk)(0,4); // dM22 = sum_{i,j=1,i!=j}^M w_i^2 w_j^2
4828  Double_t dM33 = (*fSMpk)(1,3)-(*fSMpk)(0,6); // dM33 = sum_{i,j=1,i!=j}^M w_i^3 w_j^3
4829  Double_t dM44 = (*fSMpk)(1,4)-(*fSMpk)(0,8); // dM44 = sum_{i,j=1,i!=j}^M w_i^4 w_j^4
4830  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
4831  Double_t dM211 = (*fSMpk)(0,2)*(*fSMpk)(1,1)-2.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4832                 - (*fSMpk)(1,2)+2.*(*fSMpk)(0,4); // dM211 = sum_{i,j,k=1,i!=j!=k}^M w_i^2 w_j w_k
4833  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
4834                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4835                  + 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
4836  //..............................................................................................
4837
4838  // 2-particle correlations:
4839  Double_t two1n1nW1W1 = 0.; // <w1 w2 cos(n*(phi1-phi2))>
4840  Double_t two2n2nW2W2 = 0.; // <w1^2 w2^2 cos(2n*(phi1-phi2))>
4841  Double_t two3n3nW3W3 = 0.; // <w1^3 w2^3 cos(3n*(phi1-phi2))>
4842  Double_t two4n4nW4W4 = 0.; // <w1^4 w2^4 cos(4n*(phi1-phi2))>
4843  if(dMult>1) 
4844  { 
4845   if(dM11)
4846   {
4847    two1n1nW1W1 = (pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))/dM11;    
4848    // average correlation <w1 w2 cos(n*(phi1-phi2))> for single event: 
4849    fIntFlowCorrelationsEBE->SetBinContent(1,two1n1nW1W1);
4850    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,dM11);
4851    // average correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
4852    fIntFlowCorrelationsPro->Fill(0.5,two1n1nW1W1,dM11);  
4853    // average squared correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
4854    fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1nW1W1*two1n1nW1W1,dM11); 
4855    fIntFlowCorrelationsAllPro->Fill(0.5,two1n1nW1W1,dM11);   
4856   }
4857   if(dM22)
4858   {
4859    two2n2nW2W2 = (pow(dReQ2n2k,2)+pow(dImQ2n2k,2)-(*fSMpk)(0,4))/dM22; 
4860    // ...
4861    // average correlation <w1^2 w2^2 cos(2n*(phi1-phi2))> for all events:
4862    fIntFlowCorrelationsAllPro->Fill(1.5,two2n2nW2W2,dM22);   
4863   }
4864   if(dM33)
4865   {
4866    two3n3nW3W3 = (pow(dReQ3n3k,2)+pow(dImQ3n3k,2)-(*fSMpk)(0,6))/dM33;
4867    // ...
4868    // average correlation <w1^3 w2^3 cos(3n*(phi1-phi2))> for all events:
4869    fIntFlowCorrelationsAllPro->Fill(2.5,two3n3nW3W3,dM33);   
4870   }
4871   if(dM44)
4872   {
4873    two4n4nW4W4 = (pow(dReQ4n4k,2)+pow(dImQ4n4k,2)-(*fSMpk)(0,8))/dM44; 
4874    // ...
4875    // average correlation <w1^4 w2^4 cos(4n*(phi1-phi2))> for all events:
4876    fIntFlowCorrelationsAllPro->Fill(3.5,two4n4nW4W4,dM44);      
4877   }
4878  } // end of if(dMult>1) 
4879
4880  // extra 2-particle correlations:
4881  Double_t two1n1nW3W1 = 0.; // <w1^3 w2 cos(n*(phi1-phi2))>
4882  Double_t two1n1nW1W1W2 = 0.; // <w1 w2 w3^2 cos(n*(phi1-phi2))> 
4883  if(dMult>1) 
4884  {    
4885   if(dM31)
4886   {
4887    two1n1nW3W1 = (dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k-(*fSMpk)(0,4))/dM31; 
4888    fIntFlowExtraCorrelationsPro->Fill(0.5,two1n1nW3W1,dM31);  
4889   } 
4890   if(dM211)
4891   {
4892    two1n1nW1W1W2 = ((*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))
4893                  - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k
4894                  - (*fSMpk)(0,4)))/dM211;
4895    fIntFlowExtraCorrelationsPro->Fill(1.5,two1n1nW1W1W2,dM211);  
4896   }  
4897  } // end of if(dMult>1)
4898  //..............................................................................................
4899  
4900  //..............................................................................................
4901  // 3-particle correlations:
4902  Double_t three2n1n1nW2W1W1 = 0.; // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
4903  
4904  if(dMult>2) 
4905  { 
4906   if(dM211)
4907   {                                                       
4908    three2n1n1nW2W1W1 = (pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k
4909                      - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
4910                      - pow(dReQ2n2k,2)-pow(dImQ2n2k,2)
4911                      + 2.*(*fSMpk)(0,4))/dM211;                                                                               
4912    fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1nW2W1W1,dM211);
4913   } 
4914  } // end of if(dMult>2) 
4915  //..............................................................................................
4916  
4917  //..............................................................................................
4918  // 4-particle correlations:
4919  Double_t four1n1n1n1nW1W1W1W1 = 0.; // <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
4920  if(dMult>3) 
4921  { 
4922   if(dM1111)
4923   {      
4924    four1n1n1n1nW1W1W1W1 = (pow(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.),2)
4925                         - 2.*(pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k)
4926                         + 8.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
4927                         + (pow(dReQ2n2k,2)+pow(dImQ2n2k,2))
4928                         - 4.*(*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
4929                         - 6.*(*fSMpk)(0,4)+2.*(*fSMpk)(1,2))/dM1111;  
4930                           
4931    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for single event: 
4932    fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1nW1W1W1W1);
4933    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,dM1111);
4934    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
4935    fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1,dM1111);   
4936    // average squared correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
4937    fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1*four1n1n1n1nW1W1W1W1,dM1111);      
4938    fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1nW1W1W1W1,dM1111);   
4939   } 
4940  } // end of if(dMult>3) 
4941  //..............................................................................................
4942  
4943 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
4944
4945 //================================================================================================================================
4946
4947 void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
4948 {
4949  // Initialize all arrays used to calculate integrated flow.
4950  
4951  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
4952  {
4953   fIntFlowCorrectionTermsForNUAEBE[sc] = NULL;
4954   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc] = NULL;
4955   fIntFlowCorrectionTermsForNUAPro[sc] = NULL;
4956   fIntFlowCorrectionTermsForNUAHist[sc] = NULL;
4957   for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
4958   {
4959    fIntFlowCorrectionTermsForNUAVsMPro[sc][ci] = NULL;
4960   }
4961   for(Int_t power=0;power<2;power++) // linear or quadratic 
4962   {
4963    fIntFlowSumOfEventWeightsNUA[sc][power] = NULL;
4964   }
4965  }
4966  for(Int_t power=0;power<2;power++) // linear or quadratic 
4967  {
4968   fIntFlowSumOfEventWeights[power] = NULL;    
4969  }
4970  for(Int_t i=0;i<4;i++) // print on the screen the final results (0=RF, 1=RP, 2=POI, 3=RF (rebbined in M))
4971  {
4972   fPrintFinalResults[i] = kTRUE;
4973  }
4974  for(Int_t ci=0;ci<4;ci++) // correlation index or cumulant order
4975  {
4976   fIntFlowCorrelationsVsMPro[ci] = NULL;
4977   fIntFlowSquaredCorrelationsVsMPro[ci] = NULL;
4978   fIntFlowCorrelationsVsMHist[ci] = NULL;
4979   fIntFlowQcumulantsVsM[ci] = NULL;
4980   fIntFlowVsM[ci] = NULL;
4981   fIntFlowDetectorBiasVsM[ci] = NULL;
4982   for(Int_t lc=0;lc<2;lc++)
4983   {
4984    fIntFlowSumOfEventWeightsVsM[ci][lc] = NULL;
4985   }
4986  } 
4987  for(Int_t pi=0;pi<6;pi++) // product or covariance index
4988  {
4989   fIntFlowProductOfCorrelationsVsMPro[pi] = NULL;
4990   fIntFlowCovariancesVsM[pi] = NULL;
4991   fIntFlowSumOfProductOfEventWeightsVsM[pi] = NULL;
4992  } 
4993  
4994 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
4995
4996 //================================================================================================================================
4997
4998 void AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
4999 {
5000  // Initialize all arrays needed to calculate differential flow.
5001  //  a) Initialize lists holding profiles;
5002  //  b) Initialize lists holding histograms;
5003  //  c) Initialize event-by-event quantities;
5004  //  d) Initialize profiles;
5005  //  e) Initialize histograms holding final results.
5006  
5007  // a) Initialize lists holding profiles;
5008  for(Int_t t=0;t<2;t++) // type (RP, POI)
5009  {
5010   for(Int_t pe=0;pe<2;pe++) // pt or eta
5011   {
5012    fDiffFlowCorrelationsProList[t][pe] = NULL;
5013    fDiffFlowProductOfCorrelationsProList[t][pe] = NULL;
5014    fDiffFlowCorrectionsProList[t][pe] = NULL;
5015   }
5016  }  
5017  
5018  // b) Initialize lists holding histograms;
5019  for(Int_t t=0;t<2;t++) // type (RP, POI)
5020  {
5021   for(Int_t pe=0;pe<2;pe++) // pt or eta
5022   {
5023    fDiffFlowCorrelationsHistList[t][pe] = NULL;
5024    for(Int_t power=0;power<2;power++)
5025    {
5026     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = NULL;
5027    } // end of for(Int_t power=0;power<2;power++)  
5028    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = NULL;
5029    fDiffFlowCorrectionsHistList[t][pe] = NULL;
5030    fDiffFlowCovariancesHistList[t][pe] = NULL;
5031    fDiffFlowCumulantsHistList[t][pe] = NULL;
5032    fDiffFlowHistList[t][pe] = NULL;
5033   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5034  } // enf of for(Int_t t=0;t<2;t++) // type (RP, POI) 
5035  
5036  // c) Initialize event-by-event quantities:
5037  // 1D:
5038  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5039  {
5040   for(Int_t pe=0;pe<2;pe++) // pt or eta
5041   { 
5042    for(Int_t m=0;m<4;m++) // multiple of harmonic
5043    {
5044     for(Int_t k=0;k<9;k++) // power of weight
5045     {
5046      fReRPQ1dEBE[t][pe][m][k] = NULL;
5047      fImRPQ1dEBE[t][pe][m][k] = NULL;
5048      fs1dEBE[t][pe][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5049     }   
5050    }
5051   }
5052  }
5053  // 1D:
5054  for(Int_t t=0;t<2;t++) // type (RP or POI)
5055  {
5056   for(Int_t pe=0;pe<2;pe++) // pt or eta
5057   { 
5058    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5059    {
5060     for(Int_t cti=0;cti<9;cti++) // correction term index
5061     {
5062      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = NULL;
5063     }   
5064    }
5065   }
5066  }
5067  // 2D:  
5068  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5069  {
5070   for(Int_t m=0;m<4;m++) // multiple of harmonic
5071   {
5072    for(Int_t k=0;k<9;k++) // power of weight
5073    {
5074     fReRPQ2dEBE[t][m][k] = NULL;
5075     fImRPQ2dEBE[t][m][k] = NULL;
5076     fs2dEBE[t][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5077    }   
5078   }
5079  }
5080  
5081  // d) Initialize profiles:
5082  for(Int_t t=0;t<2;t++) // type: RP or POI
5083  { 
5084   for(Int_t pe=0;pe<2;pe++) // pt or eta
5085   {
5086    for(Int_t ci=0;ci<4;ci++) // correlation index
5087    {
5088     fDiffFlowCorrelationsPro[t][pe][ci] = NULL;
5089     fDiffFlowSquaredCorrelationsPro[t][pe][ci] = NULL;
5090    } // end of for(Int_t ci=0;ci<4;ci++)   
5091    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5092    {
5093     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5094     {
5095      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = NULL;
5096     } // end of for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5097    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index  
5098    // correction terms for nua:
5099    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5100    {
5101     for(Int_t cti=0;cti<9;cti++) // correction term index
5102     {
5103      fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = NULL;
5104     }   
5105    }
5106   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5107  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5108   
5109  // e) Initialize histograms holding final results.
5110  for(Int_t t=0;t<2;t++) // type: RP or POI
5111  { 
5112   for(Int_t pe=0;pe<2;pe++) // pt or eta
5113   {
5114    for(Int_t ci=0;ci<4;ci++) // correlation index
5115    {
5116     fDiffFlowCorrelationsHist[t][pe][ci] = NULL;
5117     fDiffFlowCumulants[t][pe][ci] = NULL;
5118     fDiffFlow[t][pe][ci] = NULL;
5119    } // end of for(Int_t ci=0;ci<4;ci++)    
5120    for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5121    {
5122     fDiffFlowCovariances[t][pe][covarianceIndex] = NULL;     
5123    } // end of for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5124    // correction terms for nua:
5125    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5126    {
5127     for(Int_t cti=0;cti<9;cti++) // correction term index
5128     {
5129      fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = NULL;
5130     }   
5131    }
5132   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5133  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5134  
5135  // sum of event weights for reduced correlations:
5136  for(Int_t t=0;t<2;t++) // type = RP or POI
5137  {
5138   for(Int_t pe=0;pe<2;pe++) // pt or eta
5139   {
5140    for(Int_t p=0;p<2;p++) // power of weight is 1 or 2
5141    {
5142     for(Int_t ew=0;ew<4;ew++) // event weight index for reduced correlations
5143     {
5144      fDiffFlowSumOfEventWeights[t][pe][p][ew] = NULL;
5145     } 
5146    }   
5147   }
5148  }
5149  // product of event weights for both types of correlations:
5150  for(Int_t t=0;t<2;t++) // type = RP or POI
5151  {
5152   for(Int_t pe=0;pe<2;pe++) // pt or eta
5153   {
5154    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5155    {
5156     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5157     {
5158      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = NULL;
5159     } 
5160    }   
5161   }
5162  }
5163
5164  
5165  
5166  
5167  /*
5168  
5169  // nested lists in fDiffFlowProfiles:
5170  for(Int_t t=0;t<2;t++)
5171  {
5172   fDFPType[t] = NULL;
5173   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
5174   {
5175    fDFPParticleWeights[t][pW] = NULL;
5176    for(Int_t eW=0;eW<2;eW++)
5177    {   
5178     fDFPEventWeights[t][pW][eW] = NULL;
5179     fDiffFlowCorrelations[t][pW][eW] = NULL;
5180     fDiffFlowProductsOfCorrelations[t][pW][eW] = NULL;
5181     for(Int_t sc=0;sc<2;sc++)
5182     {
5183      fDiffFlowCorrectionTerms[t][pW][eW][sc] = NULL;
5184     }
5185    } 
5186   }
5187  }  
5188  
5189  
5190  */
5191  
5192   
5193   
5194   /*
5195   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
5196   {
5197    for(Int_t eW=0;eW<2;eW++)
5198    {
5199     // correlations:
5200     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
5201     {
5202      fCorrelationsPro[t][pW][eW][correlationIndex] = NULL;
5203     }
5204     // products of correlations:
5205     for(Int_t productOfCorrelationsIndex=0;productOfCorrelationsIndex<6;productOfCorrelationsIndex++)
5206     {
5207      fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] = NULL;
5208     }
5209     // correction terms:
5210     for(Int_t sc=0;sc<2;sc++)
5211     {
5212      for(Int_t correctionsIndex=0;correctionsIndex<2;correctionsIndex++)
5213      {
5214       fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex] = NULL;
5215      } 
5216     } 
5217    }
5218   } 
5219   */
5220     
5221 } // end of AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5222
5223
5224 //================================================================================================================================
5225  /*
5226
5227
5228 void AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D(TString type)
5229 {
5230  // calculate all reduced correlations needed for differential flow for each (pt,eta) bin: 
5231  
5232  if(type == "RP") // to be improved (removed)
5233  {
5234   cout<<endl;
5235  }
5236  // ... 
5237  
5238  
5239  Int_t typeFlag = -1; 
5240   
5241  // reduced correlations ares stored in fCorrelationsPro[t][pW][index] and are indexed as follows:
5242  // index:
5243  // 0: <2'>
5244  // 1: <4'>
5245
5246  // multiplicity:
5247  Double_t dMult = (*fSMpk)(0,0);
5248  
5249  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5250  Double_t dReQ1n = (*fReQ)(0,0);
5251  Double_t dReQ2n = (*fReQ)(1,0);
5252  //Double_t dReQ3n = (*fReQ)(2,0);
5253  //Double_t dReQ4n = (*fReQ)(3,0);
5254  Double_t dImQ1n = (*fImQ)(0,0);
5255  Double_t dImQ2n = (*fImQ)(1,0);
5256  //Double_t dImQ3n = (*fImQ)(2,0);
5257  //Double_t dImQ4n = (*fImQ)(3,0);
5258
5259  // looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
5260  for(Int_t p=1;p<=fnBinsPt;p++)
5261  {
5262   for(Int_t e=1;e<=fnBinsEta;e++)
5263   {
5264    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin): 
5265    Double_t p1n0kRe = 0.;
5266    Double_t p1n0kIm = 0.;
5267
5268    // number of POIs in particular (pt,eta) bin:
5269    Double_t mp = 0.;
5270
5271    // 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):
5272    Double_t q1n0kRe = 0.;
5273    Double_t q1n0kIm = 0.;
5274    Double_t q2n0kRe = 0.;
5275    Double_t q2n0kIm = 0.;
5276
5277    // number of particles which are both RPs and POIs in particular (pt,eta) bin:
5278    Double_t mq = 0.;
5279    
5280    // q_{m*n,0}:
5281    q1n0kRe = fReEBE2D[2][0][0]->GetBinContent(fReEBE2D[2][0][0]->GetBin(p,e))
5282            * fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e));
5283    q1n0kIm = fImEBE2D[2][0][0]->GetBinContent(fImEBE2D[2][0][0]->GetBin(p,e))
5284            * fImEBE2D[2][0][0]->GetBinEntries(fImEBE2D[2][0][0]->GetBin(p,e));
5285    q2n0kRe = fReEBE2D[2][1][0]->GetBinContent(fReEBE2D[2][1][0]->GetBin(p,e))
5286            * fReEBE2D[2][1][0]->GetBinEntries(fReEBE2D[2][1][0]->GetBin(p,e));
5287    q2n0kIm = fImEBE2D[2][1][0]->GetBinContent(fImEBE2D[2][1][0]->GetBin(p,e))
5288            * fImEBE2D[2][1][0]->GetBinEntries(fImEBE2D[2][1][0]->GetBin(p,e));
5289            
5290    mq = fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
5291    
5292    if(type == "POI")
5293    {
5294     // p_{m*n,0}:
5295     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
5296             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5297     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))  
5298             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e));
5299             
5300     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
5301     
5302     typeFlag = 1;
5303    }
5304    else if(type == "RP")
5305    {
5306     // p_{m*n,0} = q_{m*n,0}:
5307     p1n0kRe = q1n0kRe; 
5308     p1n0kIm = q1n0kIm; 
5309     mp = mq; 
5310     
5311     typeFlag = 0;
5312    }
5313    
5314    // count events with non-empty (pt,eta) bin:
5315    if(mp>0)
5316    {
5317     fNonEmptyBins2D[typeFlag]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,1);
5318    }
5319    
5320    // 2'-particle correlation for particular (pt,eta) bin:
5321    Double_t two1n1nPtEta = 0.;
5322    if(mp*dMult-mq)
5323    {
5324     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
5325                  / (mp*dMult-mq);
5326    
5327     // fill the 2D profile to get the average correlation for each (pt,eta) bin:
5328     if(type == "POI")
5329     { 
5330      //f2pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5331      
5332      fCorrelationsPro[1][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5333     }
5334     else if(type == "RP")
5335     {
5336      //f2pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);   
5337      fCorrelationsPro[0][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5338     }
5339    } // end of if(mp*dMult-mq)
5340   
5341    // 4'-particle correlation:
5342    Double_t four1n1n1n1nPtEta = 0.;
5343    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5344        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
5345    {
5346     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5347                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
5348                       - 2.*q2n0kIm*dReQ1n*dImQ1n
5349                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
5350                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
5351                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5352                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
5353                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
5354                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
5355                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
5356                       + 2.*mq*dMult                      
5357                       - 6.*mq)        
5358                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5359                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
5360     
5361     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5362     if(type == "POI")
5363     {
5364      //f4pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5365      //                  (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5366      //                   + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
5367      
5368      fCorrelationsPro[1][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5369                                      (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5370                                      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
5371     }
5372     else if(type == "RP")
5373     {
5374      //f4pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5375      //                 (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5376      //                  + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));   
5377                        
5378      fCorrelationsPro[0][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5379                                        (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5380                                        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
5381     }
5382    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5383      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
5384    
5385   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5386  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5387
5388  
5389    
5390     
5391       
5392 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D()
5393
5394
5395
5396  
5397  
5398
5399 //================================================================================================================================
5400
5401
5402 void AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
5403 {
5404  // calculate all weighted correlations needed for differential flow 
5405  
5406   if(type == "RP") // to be improved (removed)
5407  {
5408   cout<<endl;
5409  }
5410  // ... 
5411  
5412  
5413  
5414  
5415  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5416  Double_t dReQ1n1k = (*fReQ)(0,1);
5417  Double_t dReQ2n2k = (*fReQ)(1,2);
5418  Double_t dReQ1n3k = (*fReQ)(0,3);
5419  //Double_t dReQ4n4k = (*fReQ)(3,4);
5420  Double_t dImQ1n1k = (*fImQ)(0,1);
5421  Double_t dImQ2n2k = (*fImQ)(1,2);
5422  Double_t dImQ1n3k = (*fImQ)(0,3);
5423  //Double_t dImQ4n4k = (*fImQ)(3,4);
5424  
5425  // S^M_{p,k} (see .h file for the definition of fSMpk):
5426  Double_t dSM1p1k = (*fSMpk)(0,1);
5427  Double_t dSM1p2k = (*fSMpk)(0,2);
5428  Double_t dSM1p3k = (*fSMpk)(0,3);
5429  Double_t dSM2p1k = (*fSMpk)(1,1);
5430  Double_t dSM3p1k = (*fSMpk)(2,1);
5431  
5432  // looping over all (pt,eta) bins and calculating weighted correlations needed for differential flow: 
5433  for(Int_t p=1;p<=fnBinsPt;p++)
5434  {
5435   for(Int_t e=1;e<=fnBinsEta;e++)
5436   {
5437    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
5438    Double_t p1n0kRe = 0.;
5439    Double_t p1n0kIm = 0.;
5440
5441    // number of POIs in particular (pt,eta) bin):
5442    Double_t mp = 0.;
5443
5444    // real and imaginary parts of q_{m*n,k}: 
5445    // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
5446    Double_t q1n2kRe = 0.;
5447    Double_t q1n2kIm = 0.;
5448    Double_t q2n1kRe = 0.;
5449    Double_t q2n1kIm = 0.;
5450
5451    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5452    Double_t s1p1k = 0.; 
5453    Double_t s1p2k = 0.; 
5454    Double_t s1p3k = 0.; 
5455    
5456    // M0111 from Eq. (118) in QC2c (to be improved (notation))
5457    Double_t dM0111 = 0.;
5458  
5459    if(type == "POI")
5460    {
5461     // p_{m*n,0}:
5462     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
5463             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5464     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))
5465             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e)); 
5466             
5467     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5468     
5469     // q_{m*n,k}: 
5470     q1n2kRe = fReEBE2D[2][0][2]->GetBinContent(fReEBE2D[2][0][2]->GetBin(p,e))
5471             * fReEBE2D[2][0][2]->GetBinEntries(fReEBE2D[2][0][2]->GetBin(p,e));
5472     q1n2kIm = fImEBE2D[2][0][2]->GetBinContent(fImEBE2D[2][0][2]->GetBin(p,e))
5473             * fImEBE2D[2][0][2]->GetBinEntries(fImEBE2D[2][0][2]->GetBin(p,e));
5474     q2n1kRe = fReEBE2D[2][1][1]->GetBinContent(fReEBE2D[2][1][1]->GetBin(p,e))
5475             * fReEBE2D[2][1][1]->GetBinEntries(fReEBE2D[2][1][1]->GetBin(p,e)); 
5476     q2n1kIm = fImEBE2D[2][1][1]->GetBinContent(fImEBE2D[2][1][1]->GetBin(p,e))
5477             * fImEBE2D[2][1][1]->GetBinEntries(fImEBE2D[2][1][1]->GetBin(p,e));
5478        
5479     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5480     s1p1k = pow(fs2D[2][1]->GetBinContent(fs2D[2][1]->GetBin(p,e)),1.); 
5481     s1p2k = pow(fs2D[2][2]->GetBinContent(fs2D[2][2]->GetBin(p,e)),1.); 
5482     s1p3k = pow(fs2D[2][3]->GetBinContent(fs2D[2][3]->GetBin(p,e)),1.); 
5483    
5484     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
5485     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
5486            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
5487            + 2.*(s1p3k-s1p2k*dSM1p1k));
5488    }
5489    else if(type == "RP")
5490    {
5491     p1n0kRe = fReEBE2D[0][0][0]->GetBinContent(fReEBE2D[0][0][0]->GetBin(p,e))
5492             * fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
5493     p1n0kIm = fImEBE2D[0][0][0]->GetBinContent(fImEBE2D[0][0][0]->GetBin(p,e))
5494             * fImEBE2D[0][0][0]->GetBinEntries(fImEBE2D[0][0][0]->GetBin(p,e));
5495             
5496     mp = fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
5497     
5498     // q_{m*n,k}: 
5499     q1n2kRe = fReEBE2D[0][0][2]->GetBinContent(fReEBE2D[0][0][2]->GetBin(p,e))
5500             * fReEBE2D[0][0][2]->GetBinEntries(fReEBE2D[0][0][2]->GetBin(p,e));
5501     q1n2kIm = fImEBE2D[0][0][2]->GetBinContent(fImEBE2D[0][0][2]->GetBin(p,e))
5502             * fImEBE2D[0][0][2]->GetBinEntries(fImEBE2D[0][0][2]->GetBin(p,e));
5503     q2n1kRe = fReEBE2D[0][1][1]->GetBinContent(fReEBE2D[0][1][1]->GetBin(p,e))
5504             * fReEBE2D[0][1][1]->GetBinEntries(fReEBE2D[0][1][1]->GetBin(p,e));
5505     q2n1kIm = fImEBE2D[0][1][1]->GetBinContent(fImEBE2D[0][1][1]->GetBin(p,e))
5506             * fImEBE2D[0][1][1]->GetBinEntries(fImEBE2D[0][1][1]->GetBin(p,e));
5507    
5508     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5509     s1p1k = pow(fs2D[0][1]->GetBinContent(fs2D[0][1]->GetBin(p,e)),1.); 
5510     s1p2k = pow(fs2D[0][2]->GetBinContent(fs2D[0][2]->GetBin(p,e)),1.); 
5511     s1p3k = pow(fs2D[0][3]->GetBinContent(fs2D[0][3]->GetBin(p,e)),1.); 
5512    
5513     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
5514     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
5515            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
5516            + 2.*(s1p3k-s1p2k*dSM1p1k));
5517     //...............................................................................................   
5518    }
5519    
5520    // 2'-particle correlation:
5521    Double_t two1n1nW0W1PtEta = 0.;
5522    if(mp*dSM1p1k-s1p1k)
5523    {
5524     two1n1nW0W1PtEta = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
5525                  / (mp*dSM1p1k-s1p1k);
5526    
5527     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5528     if(type == "POI")
5529     {
5530      //f2pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
5531      //                   mp*dSM1p1k-s1p1k);
5532      fCorrelationsPro[1][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);
5533     }
5534     else if(type == "RP")
5535     {
5536      //f2pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
5537      //                  mp*dSM1p1k-s1p1k); 
5538      fCorrelationsPro[0][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);  
5539     }
5540    } // end of if(mp*dMult-dmPrimePrimePtEta)
5541    
5542    // 4'-particle correlation:
5543    Double_t four1n1n1n1nW0W1W1W1PtEta = 0.;
5544    if(dM0111)
5545    {
5546     four1n1n1n1nW0W1W1W1PtEta = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
5547                       - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
5548                       - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
5549                       - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
5550                       + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
5551                       - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
5552                       - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
5553                       + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
5554                       + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
5555                       + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
5556                       + 2.*s1p1k*dSM1p2k                                      
5557                       - 6.*s1p3k)        
5558                       / dM0111; // to be imropoved (notation of dM0111)
5559    
5560     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5561     if(type == "POI")
5562     {
5563      //f4pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
5564      fCorrelationsPro[1][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
5565     }
5566     else if(type == "RP")
5567     {
5568      //f4pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
5569      fCorrelationsPro[0][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
5570     }
5571    } // end of if(dM0111)
5572   
5573   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5574  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5575  
5576   
5577     
5578       
5579 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
5580
5581
5582 //================================================================================================================================
5583
5584  */  
5585
5586 /*
5587 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
5588 {
5589  // 1.) Access average for 2D correlations from profiles and store them in 2D final results histograms;
5590  // 2.) Access spread for 2D correlations from profiles, calculate error and store it in 2D final results histograms;
5591  // 3.) Make projections along pt and eta axis and store results and errors in 1D final results histograms. 
5592  
5593  Int_t typeFlag = -1;
5594  Int_t pWeightsFlag = -1;
5595  Int_t eWeightsFlag = -1;
5596
5597  if(type == "RP")
5598  {
5599   typeFlag = 0;
5600  } else if(type == "POI")
5601    {
5602     typeFlag = 1;
5603    } else 
5604      {
5605       cout<<"WARNING: type must be either RP or POI in AFAWQC::FCFDF() !!!!"<<endl;
5606       exit(0);
5607      }
5608      
5609  if(!useParticleWeights)
5610  {
5611   pWeightsFlag = 0;
5612  } else 
5613    {
5614     pWeightsFlag = 1;   
5615    }   
5616    
5617  if(eventWeights == "exact")
5618  {
5619   eWeightsFlag = 0;
5620  }          
5621   
5622  // shortcuts:
5623  Int_t t = typeFlag;
5624  Int_t pW = pWeightsFlag;
5625  Int_t eW = eWeightsFlag;
5626  
5627  // from 2D histogram fNonEmptyBins2D make two 1D histograms fNonEmptyBins1D in pt and eta (to be improved (i.e. moved somewhere else))  
5628  // pt:
5629  for(Int_t p=1;p<fnBinsPt;p++)
5630  {
5631   Double_t contentPt = 0.;
5632   for(Int_t e=1;e<=fnBinsEta;e++)
5633   {
5634    contentPt += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
5635   }
5636   fNonEmptyBins1D[t][0]->SetBinContent(p,contentPt);
5637  }
5638  // eta:
5639  for(Int_t e=1;e<fnBinsEta;e++)
5640  {
5641   Double_t contentEta = 0.;
5642   for(Int_t p=1;p<=fnBinsPt;p++)
5643   {
5644    contentEta += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
5645   }
5646   fNonEmptyBins1D[t][1]->SetBinContent(e,contentEta);
5647  }
5648  
5649  // from 2D profile in (pt,eta) make two 1D profiles in (pt) and (eta):
5650  TProfile *profile[2][4]; // [0=pt,1=eta][correlation index] // to be improved (do not hardwire the correlation index)
5651  
5652  for(Int_t pe=0;pe<2;pe++) // pt or eta
5653  {
5654   for(Int_t ci=0;ci<4;ci++) // correlation index
5655   {
5656    if(pe==0) profile[pe][ci] = this->MakePtProjection(fCorrelationsPro[t][pW][eW][ci]);
5657    if(pe==1) profile[pe][ci] = this->MakeEtaProjection(fCorrelationsPro[t][pW][eW][ci]);
5658   }
5659  }
5660   
5661  // transfer 2D profile into 2D histogram:
5662  // to be improved (see in documentation if there is a method to transfer values from 2D profile into 2D histogram)    
5663  for(Int_t ci=0;ci<4;ci++)
5664  {
5665   for(Int_t p=1;p<=fnBinsPt;p++)
5666   {
5667    for(Int_t e=1;e<=fnBinsEta;e++)
5668    {
5669     Double_t correlation = fCorrelationsPro[t][pW][eW][ci]->GetBinContent(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e)); 
5670     Double_t spread = fCorrelationsPro[t][pW][eW][ci]->GetBinError(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e));
5671     Double_t nEvts = fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e));
5672     Double_t error = 0.;
5673     fFinalCorrelations2D[t][pW][eW][ci]->SetBinContent(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),correlation);          
5674     if(nEvts>0)
5675     {
5676      error = spread/pow(nEvts,0.5);
5677      fFinalCorrelations2D[t][pW][eW][ci]->SetBinError(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),error);
5678     }
5679    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5680   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5681  } // end of for(Int_t ci=0;ci<4;ci++)
5682  
5683  // transfer 1D profile into 1D histogram (pt):
5684  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
5685  for(Int_t ci=0;ci<4;ci++)
5686  {
5687   for(Int_t p=1;p<=fnBinsPt;p++)
5688   {
5689    if(profile[0][ci])
5690    {
5691     Double_t correlation = profile[0][ci]->GetBinContent(p); 
5692     Double_t spread = profile[0][ci]->GetBinError(p);
5693     Double_t nEvts = fNonEmptyBins1D[t][0]->GetBinContent(p);
5694     Double_t error = 0.;
5695     fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinContent(p,correlation); 
5696     if(nEvts>0)
5697     {
5698      error = spread/pow(nEvts,0.5);
5699      fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinError(p,error);
5700     }  
5701    }   
5702   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5703  } // end of for(Int_t ci=0;ci<4;ci++)
5704  
5705  // transfer 1D profile into 1D histogram (eta):
5706  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
5707  for(Int_t ci=0;ci<4;ci++)
5708  {
5709   for(Int_t e=1;e<=fnBinsEta;e++)
5710   {
5711    if(profile[1][ci])
5712    {
5713     Double_t correlation = profile[1][ci]->GetBinContent(e); 
5714     fFinalCorrelations1D[t][pW][eW][1][ci]->SetBinContent(e,correlation);      
5715    }    
5716   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5717  } // end of for(Int_t ci=0;ci<4;ci++)
5718         
5719 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
5720 */
5721
5722
5723 //================================================================================================================================
5724
5725
5726 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, TString ptOrEta)
5727 {
5728  // calcualate cumulants for differential flow from measured correlations
5729  // Remark: cumulants calculated here are NOT corrected for non-uniform acceptance. This correction is applied in the method ...
5730  // to be improved (description) 
5731  
5732  Int_t typeFlag = 0;
5733  Int_t ptEtaFlag = 0;
5734
5735  if(type == "RP")
5736  {
5737   typeFlag = 0;
5738  } else if(type == "POI")
5739    {
5740     typeFlag = 1;
5741    } 
5742      
5743  if(ptOrEta == "Pt")
5744  {
5745   ptEtaFlag = 0;
5746  } else if(ptOrEta == "Eta")
5747    {
5748     ptEtaFlag = 1;
5749    } 
5750   
5751  // shortcuts:
5752  Int_t t = typeFlag;
5753  Int_t pe = ptEtaFlag;
5754      
5755  // common:
5756  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5757  
5758  // correlation <<2>>: 
5759  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
5760  
5761  // 1D:
5762  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5763  {
5764   // reduced correlations:   
5765   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>(pt)
5766   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>(pt)
5767   // final statistical error of reduced correlations:
5768   //Double_t twoPrimeError = fFinalCorrelations1D[t][pW][eW][0][0]->GetBinError(p); 
5769   // QC{2'}:
5770   Double_t qc2Prime = twoPrime; // QC{2'}
5771   //Double_t qc2PrimeError = twoPrimeError; // final stat. error of QC{2'}
5772   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime); 
5773   //fFinalCumulantsPt[t][pW][eW][nua][0]->SetBinError(p,qc2PrimeError);   
5774   // QC{4'}:
5775   Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5776   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime); 
5777  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5778  
5779     
5780  /* 
5781  // 2D (pt,eta):
5782  // to be improved (see documentation if I can do all this without looping)
5783  for(Int_t p=1;p<=fnBinsPt;p++)
5784  {
5785   for(Int_t e=1;e<=fnBinsEta;e++) 
5786   {  
5787    // reduced correlations:   
5788    Double_t twoPrime = fFinalCorrelations2D[t][pW][eW][0]->GetBinContent(fFinalCorrelations2D[t][pW][eW][0]->GetBin(p,e)); // <<2'>>(pt,eta)
5789    Double_t fourPrime = fFinalCorrelations2D[t][pW][eW][1]->GetBinContent(fFinalCorrelations2D[t][pW][eW][1]->GetBin(p,e)); // <<4'>>(pt,eta)
5790    for(Int_t nua=0;nua<2;nua++)
5791    {
5792     // QC{2'}:
5793     Double_t qc2Prime = twoPrime; // QC{2'} = <<2'>>
5794     fFinalCumulants2D[t][pW][eW][nua][0]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e),qc2Prime);    
5795     // QC{4'}:
5796     Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5797     fFinalCumulants2D[t][pW][eW][nua][1]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e),qc4Prime);   
5798    } // end of for(Int_t nua=0;nua<2;nua++)   
5799   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5800  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5801  */
5802    
5803 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, Bool_t useParticleWeights, TString eventWeights); 
5804
5805 //================================================================================================================================
5806
5807 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
5808 {
5809  // calculate final results for integrated flow of RPs and POIs 
5810   
5811  Int_t typeFlag = 0;
5812
5813  if(type == "RP")
5814  {
5815   typeFlag = 0;
5816  } else if(type == "POI")
5817    {
5818     typeFlag = 1;
5819    } else 
5820      {
5821       cout<<"WARNING: type must be either RP or POI in AFAWQC::CDF() !!!!"<<endl;
5822       exit(0);
5823      }
5824      
5825  // shortcuts:
5826  Int_t t = typeFlag;
5827   
5828  // pt yield:    
5829  TH1F *yield2ndPt = NULL;
5830  TH1F *yield4thPt = NULL;
5831  TH1F *yield6thPt = NULL;
5832  TH1F *yield8thPt = NULL;
5833  
5834  if(type == "POI")
5835  {
5836   if(fFillMultipleControlHistograms)
5837   {
5838    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtPOI())->Clone();
5839    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtPOI())->Clone();
5840    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtPOI())->Clone();
5841    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtPOI())->Clone();  
5842   } else
5843     {
5844      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5845      yield4thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5846      yield6thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5847      yield8thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();     
5848     }
5849  } 
5850  else if(type == "RP")
5851  {
5852   if(fFillMultipleControlHistograms)
5853   {
5854    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtRP())->Clone();
5855    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtRP())->Clone();
5856    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtRP())->Clone();
5857    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtRP())->Clone();  
5858   } else
5859     {
5860      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
5861      yield4thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
5862      yield6thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
5863      yield8thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();    
5864     } 
5865  } 
5866  
5867  Int_t nBinsPt = yield2ndPt->GetNbinsX();
5868  
5869  TH1D *flow2ndPt = NULL;
5870  TH1D *flow4thPt = NULL;
5871  TH1D *flow6thPt = NULL;
5872  TH1D *flow8thPt = NULL;
5873  
5874  // to be improved (hardwired pt index)
5875  flow2ndPt = (TH1D*)fDiffFlow[t][0][0]->Clone();
5876  flow4thPt = (TH1D*)fDiffFlow[t][0][1]->Clone();
5877  flow6thPt = (TH1D*)fDiffFlow[t][0][2]->Clone();
5878  flow8thPt = (TH1D*)fDiffFlow[t][0][3]->Clone(); 
5879    
5880  Double_t dvn2nd = 0., dvn4th = 0., dvn6th = 0., dvn8th = 0.; // differential flow
5881  Double_t dErrvn2nd = 0., dErrvn4th = 0., dErrvn6th = 0., dErrvn8th = 0.; // error on differential flow
5882  
5883  Double_t dVn2nd = 0., dVn4th = 0., dVn6th = 0., dVn8th = 0.; // integrated flow 
5884  Double_t dErrVn2nd = 0., dErrVn4th = 0., dErrVn6th = 0., dErrVn8th = 0.; // error on integrated flow
5885
5886  Double_t dYield2nd = 0., dYield4th = 0., dYield6th = 0., dYield8th = 0.; // pt yield 
5887  Double_t dSum2nd = 0., dSum4th = 0., dSum6th = 0., dSum8th = 0.; // needed for normalizing integrated flow
5888  
5889  // looping over pt bins:
5890  for(Int_t p=1;p<nBinsPt+1;p++)
5891  {
5892   dvn2nd = flow2ndPt->GetBinContent(p);
5893   dvn4th = flow4thPt->GetBinContent(p);
5894   dvn6th = flow6thPt->GetBinContent(p);
5895   dvn8th = flow8thPt->GetBinContent(p);
5896   
5897   dErrvn2nd = flow2ndPt->GetBinError(p);
5898   dErrvn4th = flow4thPt->GetBinError(p);
5899   dErrvn6th = flow6thPt->GetBinError(p);
5900   dErrvn8th = flow8thPt->GetBinError(p);
5901
5902   dYield2nd = yield2ndPt->GetBinContent(p);  
5903   dYield4th = yield4thPt->GetBinContent(p);
5904   dYield6th = yield6thPt->GetBinContent(p);
5905   dYield8th = yield8thPt->GetBinContent(p);
5906   
5907   dVn2nd += dvn2nd*dYield2nd;
5908   dVn4th += dvn4th*dYield4th;
5909   dVn6th += dvn6th*dYield6th;
5910   dVn8th += dvn8th*dYield8th;
5911   
5912   dSum2nd += dYield2nd;
5913   dSum4th += dYield4th;
5914   dSum6th += dYield6th;
5915   dSum8th += dYield8th;
5916   
5917   dErrVn2nd += dYield2nd*dYield2nd*dErrvn2nd*dErrvn2nd; // ro be improved (check this relation)
5918   dErrVn4th += dYield4th*dYield4th*dErrvn4th*dErrvn4th;
5919   dErrVn6th += dYield6th*dYield6th*dErrvn6th*dErrvn6th;
5920   dErrVn8th += dYield8th*dYield8th*dErrvn8th*dErrvn8th;
5921     
5922  } // end of for(Int_t p=1;p<nBinsPt+1;p++)
5923
5924  // normalizing the results for integrated flow:
5925  if(dSum2nd) 
5926  {
5927   dVn2nd /= dSum2nd;
5928   dErrVn2nd /= (dSum2nd*dSum2nd);
5929   dErrVn2nd = TMath::Sqrt(dErrVn2nd);
5930  } 
5931  if(dSum4th) 
5932  {
5933   dVn4th /= dSum4th;
5934   dErrVn4th /= (dSum4th*dSum4th);
5935   dErrVn4th = TMath::Sqrt(dErrVn4th);
5936  } 
5937  //if(dSum6th) dVn6th/=dSum6th;
5938  //if(dSum8th) dVn8th/=dSum8th;
5939   
5940  // storing the results for integrated flow in common histos: (to be improved: new method for this?)
5941  if(type == "POI")
5942  {
5943   fCommonHistsResults2nd->FillIntegratedFlowPOI(dVn2nd,dErrVn2nd); 
5944   fCommonHistsResults4th->FillIntegratedFlowPOI(dVn4th,dErrVn4th); 
5945   fCommonHistsResults6th->FillIntegratedFlowPOI(dVn6th,0.); // to be improved (errors)
5946   fCommonHistsResults8th->FillIntegratedFlowPOI(dVn8th,0.); // to be improved (errors)
5947  }
5948  else if (type == "RP")
5949  {
5950   fCommonHistsResults2nd->FillIntegratedFlowRP(dVn2nd,dErrVn2nd); 
5951   fCommonHistsResults4th->FillIntegratedFlowRP(dVn4th,dErrVn4th);
5952   fCommonHistsResults6th->FillIntegratedFlowRP(dVn6th,0.); // to be improved (errors)
5953   fCommonHistsResults8th->FillIntegratedFlowRP(dVn8th,0.); // to be improved (errors)
5954  }
5955  
5956  delete flow2ndPt;
5957  delete flow4thPt;
5958  //delete flow6thPt;
5959  //delete flow8thPt;
5960  
5961  delete yield2ndPt;
5962  delete yield4thPt;
5963  delete yield6thPt;
5964  delete yield8thPt;
5965            
5966 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
5967
5968 //================================================================================================================================
5969
5970 void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
5971 {
5972  // Initialize all arrays used for distributions.
5973  
5974  // a) Initialize arrays of histograms used to hold distributions of correlations; 
5975  // b) Initialize array to hold min and max values of correlations.
5976  
5977  // a) Initialize arrays of histograms used to hold distributions of correlations:
5978  for(Int_t di=0;di<4;di++) // distribution index
5979  {
5980   fDistributions[di] = NULL;
5981  }
5982  
5983  // b) Initialize default min and max values of correlations:
5984  //    (Remark: The default values bellow were chosen for v2=5% and M=500)
5985  fMinValueOfCorrelation[0] = -0.01; // <2>_min 
5986  fMaxValueOfCorrelation[0] = 0.04; // <2>_max 
5987  fMinValueOfCorrelation[1] = -0.00002; // <4>_min 
5988  fMaxValueOfCorrelation[1] = 0.00015; // <4>_max  
5989  fMinValueOfCorrelation[2] = -0.0000003; // <6>_min 
5990  fMaxValueOfCorrelation[2] = 0.0000006; // <6>_max  
5991  fMinValueOfCorrelation[3] = -0.000000006; // <8>_min 
5992  fMaxValueOfCorrelation[3] = 0.000000003; // <8>_max 
5993  
5994 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
5995
5996 //================================================================================================================================
5997
5998 void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
5999 {
6000  // Initialize all arrays used for various unclassified objects.
6001  
6002  for(Int_t p=0;p<4;p++) // [v_min,v_max,refMult_min,refMult_max]
6003  {
6004   fPhiDistributionForOneEventSettings[p] = 0.;
6005  } 
6006    
6007 } //  end of void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
6008
6009 //================================================================================================================================
6010
6011 void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
6012 {
6013  // a) Book profile to hold all flags for distributions of correlations;
6014  // b) Book all histograms to hold distributions of correlations.
6015  
6016  TString correlationIndex[4] = {"<2>","<4>","<6>","<8>"}; // to be improved (should I promote this to data members?)
6017   
6018  // a) Book profile to hold all flags for distributions of correlations:
6019  TString distributionsFlagsName = "fDistributionsFlags";
6020  distributionsFlagsName += fAnalysisLabel->Data();
6021  fDistributionsFlags = new TProfile(distributionsFlagsName.Data(),"Flags for Distributions of Correlations",9,0,9);
6022  fDistributionsFlags->SetTickLength(-0.01,"Y");
6023  fDistributionsFlags->SetMarkerStyle(25);
6024  fDistributionsFlags->SetLabelSize(0.05);
6025  fDistributionsFlags->SetLabelOffset(0.02,"Y");
6026  fDistributionsFlags->GetXaxis()->SetBinLabel(1,"Store or not?");
6027  fDistributionsFlags->GetXaxis()->SetBinLabel(2,"<2>_{min}");
6028  fDistributionsFlags->GetXaxis()->SetBinLabel(3,"<2>_{max}");
6029  fDistributionsFlags->GetXaxis()->SetBinLabel(4,"<4>_{min}");
6030  fDistributionsFlags->GetXaxis()->SetBinLabel(5,"<4>_{max}");
6031  fDistributionsFlags->GetXaxis()->SetBinLabel(6,"<6>_{min}");
6032  fDistributionsFlags->GetXaxis()->SetBinLabel(7,"<6>_{max}");
6033  fDistributionsFlags->GetXaxis()->SetBinLabel(8,"<8>_{min}");
6034  fDistributionsFlags->GetXaxis()->SetBinLabel(9,"<8>_{max}");
6035  fDistributionsList->Add(fDistributionsFlags);
6036  
6037  // b) Book all histograms to hold distributions of correlations.
6038  if(fStoreDistributions)
6039  { 
6040   TString distributionsName = "fDistributions";
6041   distributionsName += fAnalysisLabel->Data();
6042   for(Int_t di=0;di<4;di++) // distribution index
6043   {
6044    fDistributions[di] = new TH1D(Form("Distribution of %s",correlationIndex[di].Data()),Form("Distribution of %s",correlationIndex[di].Data()),10000,fMinValueOfCorrelation[di],fMaxValueOfCorrelation[di]); 
6045    fDistributions[di]->SetXTitle(correlationIndex[di].Data());
6046    fDistributionsList->Add(fDistributions[di]);
6047   } // end of for(Int_t di=0;di<4;di++) // distribution index
6048  } // end of if(fStoreDistributions)
6049  
6050 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
6051
6052 //================================================================================================================================
6053
6054 void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6055 {
6056  // Book all objects for various unclassified quantities.
6057  
6058  if(!fStorePhiDistributionForOneEvent){return;}
6059  
6060  // a) Book histogram holding phi distribution for single event to illustrate flow.
6061  
6062  // a) Book histogram holding phi distribution for single event to illustrate flow:
6063  fPhiDistributionForOneEvent = new TH1D("fPhiDistributionForOneEvent","",360,0.,TMath::TwoPi());
6064  fPhiDistributionForOneEvent->GetXaxis()->SetTitle("#phi");
6065  fVariousList->Add(fPhiDistributionForOneEvent);
6066  
6067 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6068
6069 //================================================================================================================================
6070
6071 void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6072 {
6073  // Store all flags for distributiuons of correlations in profile fDistributionsFlags.
6074  
6075  if(!fDistributionsFlags)
6076  {
6077   cout<<"WARNING: fDistributionsFlags is NULL in AFAWQC::SDF() !!!!"<<endl;
6078   exit(0);
6079  } 
6080
6081  fDistributionsFlags->Fill(0.5,(Int_t)fStoreDistributions); // histos with distributions of correlations stored or not in the output file
6082  // store min and max values of correlations:
6083  for(Int_t di=0;di<4;di++) // distribution index
6084  {
6085   fDistributionsFlags->Fill(1.5+2.*(Double_t)di,fMinValueOfCorrelation[di]);
6086   fDistributionsFlags->Fill(2.5+2.*(Double_t)di,fMaxValueOfCorrelation[di]);
6087  }
6088      
6089 } // end of void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6090
6091
6092 //================================================================================================================================
6093
6094
6095 void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6096 {
6097  // Store distributions of correlations.
6098  
6099  if(!(fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE))
6100  {
6101   cout<<"WARNING: fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE"<<endl; 
6102   cout<<"         is NULL in AFAWQC::SDOC() !!!!"<<endl;
6103   exit(0);
6104  }
6105
6106  for(Int_t di=0;di<4;di++) // distribution index
6107  {
6108   if(!fDistributions[di])
6109   { 
6110    cout<<"WARNING: fDistributions[di] is NULL in AFAWQC::SDOC() !!!!"<<endl;
6111    cout<<"di = "<<di<<endl;
6112    exit(0);
6113   } else 
6114     {
6115      fDistributions[di]->Fill(fIntFlowCorrelationsEBE->GetBinContent(di+1),fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(di+1)); 
6116     } 
6117  } // end of for(Int_t di=0;di<4;di++) // distribution index
6118
6119 } // end of void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6120
6121 //================================================================================================================================
6122
6123 void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6124 {
6125  // Book and nest all lists nested in the base list fHistList.
6126  //  a) Book and nest lists for integrated flow;
6127  //  b) Book and nest lists for differential flow;
6128  //  c) Book and nest list for particle weights;
6129  //  d) Book and nest list for distributions;
6130  //  e) Book and nest list for various unclassified objects; 
6131  //  f) Book and nest list for nested loops.
6132  
6133  // a) Book and nest all lists for integrated flow:
6134  // base list for integrated flow:
6135  fIntFlowList = new TList();
6136  fIntFlowList->SetName("Integrated Flow");
6137  fIntFlowList->SetOwner(kTRUE);
6138  fHistList->Add(fIntFlowList);
6139  // list holding profiles: 
6140  fIntFlowProfiles = new TList();
6141  fIntFlowProfiles->SetName("Profiles");
6142  fIntFlowProfiles->SetOwner(kTRUE);
6143  fIntFlowList->Add(fIntFlowProfiles);
6144  // list holding histograms with results:
6145  fIntFlowResults = new TList();
6146  fIntFlowResults->SetName("Results");
6147  fIntFlowResults->SetOwner(kTRUE);
6148  fIntFlowList->Add(fIntFlowResults);
6149  
6150  // b) Book and nest lists for differential flow;
6151  fDiffFlowList = new TList();
6152  fDiffFlowList->SetName("Differential Flow");
6153  fDiffFlowList->SetOwner(kTRUE); 
6154  fHistList->Add(fDiffFlowList);
6155  // list holding profiles: 
6156  fDiffFlowProfiles = new TList(); 
6157  fDiffFlowProfiles->SetName("Profiles");
6158  fDiffFlowProfiles->SetOwner(kTRUE);
6159  fDiffFlowList->Add(fDiffFlowProfiles);
6160  // list holding histograms with results: 
6161  fDiffFlowResults = new TList();
6162  fDiffFlowResults->SetName("Results");
6163  fDiffFlowResults->SetOwner(kTRUE);
6164  fDiffFlowList->Add(fDiffFlowResults);
6165  // flags used for naming nested lists in list fDiffFlowProfiles and fDiffFlowResults:  
6166  TList list;
6167  list.SetOwner(kTRUE);
6168  TString typeFlag[2] = {"RP","POI"};  
6169  TString ptEtaFlag[2] = {"p_{T}","#eta"}; 
6170  TString powerFlag[2] = {"linear","quadratic"};   
6171  // nested lists in fDiffFlowProfiles (~/Differential Flow/Profiles):
6172  for(Int_t t=0;t<2;t++) // type: RP or POI
6173  {
6174   for(Int_t pe=0;pe<2;pe++) // pt or eta
6175   {
6176    // list holding profiles with correlations:
6177    fDiffFlowCorrelationsProList[t][pe] = (TList*)list.Clone();
6178    fDiffFlowCorrelationsProList[t][pe]->SetName(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6179    fDiffFlowProfiles->Add(fDiffFlowCorrelationsProList[t][pe]);
6180    // list holding profiles with products of correlations:
6181    fDiffFlowProductOfCorrelationsProList[t][pe] = (TList*)list.Clone();
6182    fDiffFlowProductOfCorrelationsProList[t][pe]->SetName(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6183    fDiffFlowProfiles->Add(fDiffFlowProductOfCorrelationsProList[t][pe]);
6184    // list holding profiles with corrections:
6185    fDiffFlowCorrectionsProList[t][pe] = (TList*)list.Clone();
6186    fDiffFlowCorrectionsProList[t][pe]->SetName(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6187    fDiffFlowProfiles->Add(fDiffFlowCorrectionsProList[t][pe]);   
6188   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6189  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI   
6190  // nested lists in fDiffFlowResults (~/Differential Flow/Results):
6191  for(Int_t t=0;t<2;t++) // type: RP or POI
6192  {
6193   for(Int_t pe=0;pe<2;pe++) // pt or eta
6194   {
6195    // list holding histograms with correlations:
6196    fDiffFlowCorrelationsHistList[t][pe] = (TList*)list.Clone();
6197    fDiffFlowCorrelationsHistList[t][pe]->SetName(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6198    fDiffFlowResults->Add(fDiffFlowCorrelationsHistList[t][pe]);
6199    // list holding histograms with corrections:
6200    fDiffFlowCorrectionsHistList[t][pe] = (TList*)list.Clone();
6201    fDiffFlowCorrectionsHistList[t][pe]->SetName(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6202    fDiffFlowResults->Add(fDiffFlowCorrectionsHistList[t][pe]);   
6203    for(Int_t power=0;power<2;power++)
6204    {
6205     // list holding histograms with sums of event weights:
6206     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = (TList*)list.Clone();
6207     fDiffFlowSumOfEventWeightsHistList[t][pe][power]->SetName(Form("Sum of %s event weights (%s, %s)",powerFlag[power].Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6208     fDiffFlowResults->Add(fDiffFlowSumOfEventWeightsHistList[t][pe][power]);    
6209    } // end of for(Int_t power=0;power<2;power++)
6210    // list holding histograms with sums of products of event weights:
6211    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = (TList*)list.Clone();
6212    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->SetName(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6213    fDiffFlowResults->Add(fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]);
6214    // list holding histograms with covariances of correlations:
6215    fDiffFlowCovariancesHistList[t][pe] = (TList*)list.Clone();
6216    fDiffFlowCovariancesHistList[t][pe]->SetName(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6217    fDiffFlowResults->Add(fDiffFlowCovariancesHistList[t][pe]);
6218    // list holding histograms with differential Q-cumulants:
6219    fDiffFlowCumulantsHistList[t][pe] = (TList*)list.Clone();
6220    fDiffFlowCumulantsHistList[t][pe]->SetName(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6221    fDiffFlowResults->Add(fDiffFlowCumulantsHistList[t][pe]);   
6222    // list holding histograms with differential flow estimates from Q-cumulants:
6223    fDiffFlowHistList[t][pe] = (TList*)list.Clone();
6224    fDiffFlowHistList[t][pe]->SetName(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6225    fDiffFlowResults->Add(fDiffFlowHistList[t][pe]);      
6226   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6227  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6228   
6229  // c) Book and nest list for particle weights:
6230  fWeightsList->SetName("Weights");
6231  fWeightsList->SetOwner(kTRUE);   
6232  fHistList->Add(fWeightsList); 
6233
6234  // d) Book and nest list for distributions:
6235  fDistributionsList = new TList();
6236  fDistributionsList->SetName("Distributions");
6237  fDistributionsList->SetOwner(kTRUE);
6238  fHistList->Add(fDistributionsList);
6239  
6240  // e) Book and nest list for various unclassified objects:
6241  if(fStorePhiDistributionForOneEvent)
6242  {
6243   fVariousList = new TList();
6244   fVariousList->SetName("Various");
6245   fVariousList->SetOwner(kTRUE);
6246   fHistList->Add(fVariousList);
6247  }
6248   
6249  // f) Book and nest list for nested loops:
6250  fNestedLoopsList = new TList();
6251  fNestedLoopsList->SetName("Nested Loops");
6252  fNestedLoopsList->SetOwner(kTRUE);
6253  fHistList->Add(fNestedLoopsList);
6254  
6255 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6256
6257
6258 //================================================================================================================================
6259
6260
6261 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type)
6262 {
6263  // fill common result histograms for differential flow
6264  
6265  Int_t typeFlag = 0;
6266  //Int_t ptEtaFlag = 0;
6267
6268  if(type == "RP")
6269  {
6270   typeFlag = 0;
6271  } else if(type == "POI")
6272    {
6273     typeFlag = 1;
6274    } 
6275   
6276  // shortcuts:
6277  Int_t t = typeFlag;
6278  //Int_t pe = ptEtaFlag;
6279
6280  // to be improved (implement protection here)
6281      
6282  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
6283  {
6284   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
6285   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
6286   exit(0);
6287  }
6288  
6289  // pt:
6290  for(Int_t p=1;p<=fnBinsPt;p++)
6291  {
6292   Double_t v2 = fDiffFlow[t][0][0]->GetBinContent(p);
6293   Double_t v4 = fDiffFlow[t][0][1]->GetBinContent(p);
6294   Double_t v6 = fDiffFlow[t][0][2]->GetBinContent(p);
6295   Double_t v8 = fDiffFlow[t][0][3]->GetBinContent(p);
6296   
6297   Double_t v2Error = fDiffFlow[t][0][0]->GetBinError(p);
6298   Double_t v4Error = fDiffFlow[t][0][1]->GetBinError(p);
6299   //Double_t v6Error = fFinalFlow1D[t][pW][nua][0][2]->GetBinError(p);
6300   //Double_t v8Error = fFinalFlow1D[t][pW][nua][0][3]->GetBinError(p);
6301  
6302   if(type == "RP")
6303   {
6304    fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,v2,v2Error);
6305    fCommonHistsResults4th->FillDifferentialFlowPtRP(p,v4,v4Error);
6306    fCommonHistsResults6th->FillDifferentialFlowPtRP(p,v6,0.);
6307    fCommonHistsResults8th->FillDifferentialFlowPtRP(p,v8,0.);
6308   } else if(type == "POI")
6309     {
6310      fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,v2,v2Error);
6311      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,v4,v4Error);
6312      fCommonHistsResults6th->FillDifferentialFlowPtPOI(p,v6,0.);
6313      fCommonHistsResults8th->FillDifferentialFlowPtPOI(p,v8,0.);
6314     }
6315  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
6316  
6317  // eta:
6318  for(Int_t e=1;e<=fnBinsEta;e++)
6319  {
6320   Double_t v2 = fDiffFlow[t][1][0]->GetBinContent(e);
6321   Double_t v4 = fDiffFlow[t][1][1]->GetBinContent(e);
6322   Double_t v6 = fDiffFlow[t][1][2]->GetBinContent(e);
6323   Double_t v8 = fDiffFlow[t][1][3]->GetBinContent(e);
6324   
6325   Double_t v2Error = fDiffFlow[t][1][0]->GetBinError(e);
6326   Double_t v4Error = fDiffFlow[t][1][1]->GetBinError(e);
6327   //Double_t v6Error = fDiffFlow[t][1][2]->GetBinError(e);
6328   //Double_t v8Error = fDiffFlow[t][1][3]->GetBinError(e);
6329  
6330   if(type == "RP")
6331   {
6332    fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,v2,v2Error);
6333    fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,v4,v4Error);
6334    fCommonHistsResults6th->FillDifferentialFlowEtaRP(e,v6,0.);
6335    fCommonHistsResults8th->FillDifferentialFlowEtaRP(e,v8,0.);
6336   } else if(type == "POI")
6337     {
6338      fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,v2,v2Error);
6339      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,v4,v4Error);
6340      fCommonHistsResults6th->FillDifferentialFlowEtaPOI(e,v6,0.);
6341      fCommonHistsResults8th->FillDifferentialFlowEtaPOI(e,v8,0.);
6342     }
6343  } // end of for(Int_t e=1;e<=fnBinsEta;e++)    
6344  
6345 } // end of void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
6346
6347 //================================================================================================================================
6348
6349 void AliFlowAnalysisWithQCumulants::AccessConstants()
6350 {
6351  // Access needed common constants from AliFlowCommonConstants.
6352  
6353  fnBinsPhi = AliFlowCommonConstants::GetMaster()->GetNbinsPhi();
6354  fPhiMin = AliFlowCommonConstants::GetMaster()->GetPhiMin();         
6355  fPhiMax = AliFlowCommonConstants::GetMaster()->GetPhiMax();
6356  if(fnBinsPhi) fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;  
6357  fnBinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
6358  fPtMin = AliFlowCommonConstants::GetMaster()->GetPtMin();           
6359  fPtMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
6360  if(fnBinsPt) fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;  
6361  fnBinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
6362  fEtaMin = AliFlowCommonConstants::GetMaster()->GetEtaMin();         
6363  fEtaMax = AliFlowCommonConstants::GetMaster()->GetEtaMax();
6364  if(fnBinsEta) fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;  
6365  
6366 } // end of void AliFlowAnalysisWithQCumulants::AccessConstants()
6367
6368 //================================================================================================================================
6369
6370 void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6371 {
6372  // a) Cross check if the choice for multiplicity weights make sense;
6373  
6374  // a) Cross check if the choice for multiplicity weights make sense:
6375  if(strcmp(fMultiplicityWeight->Data(),"combinations") && 
6376     strcmp(fMultiplicityWeight->Data(),"unit") &&
6377     strcmp(fMultiplicityWeight->Data(),"multiplicity"))
6378  {
6379   cout<<"WARNING (QC): Multiplicity weight can be either \"combinations\", \"unit\""<<endl;
6380   cout<<"              or \"multiplicity\". Certainly not \""<<fMultiplicityWeight->Data()<<"\"."<<endl;
6381   exit(0);
6382  }   
6383  
6384 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6385
6386 //================================================================================================================================
6387
6388 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6389 {
6390  // Calculate sum of linear and quadratic event weights for correlations.
6391  
6392  // multiplicity:
6393  Double_t dMult = (*fSMpk)(0,0);
6394                         
6395  for(Int_t p=0;p<2;p++) // power-1
6396  {
6397   for(Int_t ci=0;ci<4;ci++) // correlation index
6398   { 
6399    fIntFlowSumOfEventWeights[p]->Fill(ci+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); 
6400    if(fCalculateCumulantsVsM)
6401    {
6402     fIntFlowSumOfEventWeightsVsM[ci][p]->Fill(dMult+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); // to be improved: dMult => sum of weights?
6403    }
6404   }
6405  }
6406   
6407 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6408
6409 //================================================================================================================================
6410
6411 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6412 {
6413  // Calculate sum of linear and quadratic event weights for NUA terms.
6414                        
6415  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
6416  {
6417   for(Int_t p=0;p<2;p++) // power-1
6418   {
6419    for(Int_t ci=0;ci<4;ci++) // nua term index
6420    { 
6421     fIntFlowSumOfEventWeightsNUA[sc][p]->Fill(ci+0.5,pow(fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->GetBinContent(ci+1),p+1)); 
6422    }
6423   }
6424  }
6425   
6426 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6427
6428 //================================================================================================================================
6429
6430 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6431 {
6432  // Calculate sum of product of event weights for correlations.
6433   
6434  // multiplicity:
6435  Double_t dMult = (*fSMpk)(0,0);
6436   
6437  Int_t counter = 0;
6438  
6439  for(Int_t ci1=1;ci1<4;ci1++)
6440  {
6441   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
6442   {
6443    fIntFlowSumOfProductOfEventWeights->Fill(0.5+counter,
6444                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6445                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6446    if(fCalculateCumulantsVsM)
6447    {                                                                                    
6448     fIntFlowSumOfProductOfEventWeightsVsM[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights?
6449                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6450                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6451    } // end of if(fCalculateCumulantsVsM)
6452    counter++;                                         
6453   }
6454  }
6455
6456 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6457
6458 //================================================================================================================================
6459
6460 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeightsNUA()
6461 {
6462  // Calculate sum of product of event weights for NUA terms.
6463   
6464  // w_{<2>} * w_{<cos(#phi)>}:
6465  fIntFlowSumOfProductOfEventWeightsNUA->Fill(0.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6466                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6467  // w_{<2>} * w_{<sin(#phi)>}:
6468  fIntFlowSumOfProductOfEventWeightsNUA->Fill(1.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6469                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6470  // w_{<cos(#phi)> * w_{<sin(#phi)>}:
6471  fIntFlowSumOfProductOfEventWeightsNUA->Fill(2.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6472                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6473  // w_{<2>} * w{<cos(phi1+phi2)>}
6474  fIntFlowSumOfProductOfEventWeightsNUA->Fill(3.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6475                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6476  // w_{<2>} * w{<sin(phi1+phi2)>}
6477  fIntFlowSumOfProductOfEventWeightsNUA->Fill(4.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6478                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6479  // w_{<2>} * w{<cos(phi1-phi2-phi3)>}
6480  fIntFlowSumOfProductOfEventWeightsNUA->Fill(5.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6481                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6482  // w_{<2>} * w{<sin(phi1-phi2-phi3)>}
6483  fIntFlowSumOfProductOfEventWeightsNUA->Fill(6.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6484                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
6485  // w_{<4>} * w{<cos(phi1)>}
6486  fIntFlowSumOfProductOfEventWeightsNUA->Fill(7.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6487                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6488  // w_{<4>} * w{<sin(phi1)>}
6489  fIntFlowSumOfProductOfEventWeightsNUA->Fill(8.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6490                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6491  // w_{<4>} * w{<cos(phi1+phi2)>}
6492  fIntFlowSumOfProductOfEventWeightsNUA->Fill(9.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6493                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6494  // w_{<4>} * w{<sin(phi1+phi2)>}
6495  fIntFlowSumOfProductOfEventWeightsNUA->Fill(10.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6496                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6497  // w_{<4>} * w{<cos(phi1-phi2-phi3)>}
6498  fIntFlowSumOfProductOfEventWeightsNUA->Fill(11.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6499                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6500  // w_{<4>} * w{<sin(phi1-phi2-phi3)>}
6501  fIntFlowSumOfProductOfEventWeightsNUA->Fill(12.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6502                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6503  // w_{<cos(phi1)>} * w{<cos(phi1+phi2)>}
6504  fIntFlowSumOfProductOfEventWeightsNUA->Fill(13.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6505                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6506  // w_{<cos(phi1)>} * w{<sin(phi1+phi2)>}
6507  fIntFlowSumOfProductOfEventWeightsNUA->Fill(14.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6508                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6509  // w_{<cos(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6510  fIntFlowSumOfProductOfEventWeightsNUA->Fill(15.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6511                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6512  // w_{<cos(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6513  fIntFlowSumOfProductOfEventWeightsNUA->Fill(16.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6514                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6515  // w_{<sin(phi1)>} * w{<cos(phi1+phi2)>}
6516  fIntFlowSumOfProductOfEventWeightsNUA->Fill(17.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6517                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6518  // w_{<sin(phi1)>} * w{<sin(phi1+phi2)>}
6519  fIntFlowSumOfProductOfEventWeightsNUA->Fill(18.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6520                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6521  // w_{<sin(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6522  fIntFlowSumOfProductOfEventWeightsNUA->Fill(19.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6523                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6524  // w_{<sin(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6525  fIntFlowSumOfProductOfEventWeightsNUA->Fill(20.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6526                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6527  // w_{<cos(phi1+phi2)>} * w{<sin(phi1+phi2))>}
6528  fIntFlowSumOfProductOfEventWeightsNUA->Fill(21.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6529                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6530  // w_{<cos(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6531  fIntFlowSumOfProductOfEventWeightsNUA->Fill(22.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6532                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6533  // w_{<cos(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6534  fIntFlowSumOfProductOfEventWeightsNUA->Fill(23.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6535                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6536  // w_{<sin(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6537  fIntFlowSumOfProductOfEventWeightsNUA->Fill(24.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6538                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6539  // w_{<sin(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6540  fIntFlowSumOfProductOfEventWeightsNUA->Fill(25.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6541                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6542  // w_{<cos(phi1-phi2-phi3)>} * w{<sin(phi1-phi2-phi3)>}
6543  fIntFlowSumOfProductOfEventWeightsNUA->Fill(26.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)*
6544                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6545
6546 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowIntFlowSumOfProductOfEventWeightsNUA()
6547
6548
6549 //================================================================================================================================
6550
6551
6552 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta)
6553 {
6554  // calculate reduced correlations for RPs or POIs in pt or eta bins
6555
6556  // multiplicity:
6557  Double_t dMult = (*fSMpk)(0,0);
6558  
6559  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
6560  Double_t dReQ1n = (*fReQ)(0,0);
6561  Double_t dReQ2n = (*fReQ)(1,0);
6562  //Double_t dReQ3n = (*fReQ)(2,0);
6563  //Double_t dReQ4n = (*fReQ)(3,0);
6564  Double_t dImQ1n = (*fImQ)(0,0);
6565  Double_t dImQ2n = (*fImQ)(1,0);
6566  //Double_t dImQ3n = (*fImQ)(2,0);
6567  //Double_t dImQ4n = (*fImQ)(3,0);
6568
6569  // reduced correlations are stored in fDiffFlowCorrelationsPro[0=RP,1=POI][0=pt,1=eta][correlation index]. Correlation index runs as follows:
6570  // 
6571  // 0: <<2'>>
6572  // 1: <<4'>>
6573  // 2: <<6'>>
6574  // 3: <<8'>>
6575  
6576  Int_t t = 0; // type flag 
6577  Int_t pe = 0; // ptEta flag
6578  
6579  if(type == "RP")
6580  {
6581   t = 0;
6582  } else if(type == "POI")
6583    {
6584     t = 1;
6585    }
6586
6587  if(ptOrEta == "Pt")
6588  {
6589   pe = 0;
6590  } else if(ptOrEta == "Eta")
6591    {
6592     pe = 1;
6593    }
6594     
6595  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6596  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6597  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6598  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6599
6600  // looping over all bins and calculating reduced correlations: 
6601  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6602  {
6603   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
6604   Double_t p1n0kRe = 0.;
6605   Double_t p1n0kIm = 0.;
6606
6607   // number of POIs in particular pt or eta bin:
6608   Double_t mp = 0.;
6609
6610   // 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):
6611   Double_t q1n0kRe = 0.;
6612   Double_t q1n0kIm = 0.;
6613   Double_t q2n0kRe = 0.;
6614   Double_t q2n0kIm = 0.;
6615
6616   // number of particles which are both RPs and POIs in particular pt or eta bin:
6617   Double_t mq = 0.;
6618    
6619   if(type == "POI")
6620   {
6621    // q_{m*n,0}:
6622    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
6623            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
6624    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
6625            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
6626    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
6627            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
6628    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
6629            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
6630                  
6631    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6632   } 
6633   else if(type == "RP")
6634   {
6635    // q_{m*n,0}:
6636    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
6637            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
6638    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
6639            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
6640    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
6641            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
6642    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
6643            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
6644                  
6645    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
6646   }
6647       
6648    if(type == "POI")
6649    {
6650     // p_{m*n,0}:
6651     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
6652             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
6653     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
6654             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
6655             
6656     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6657     
6658     t = 1; // typeFlag = RP or POI
6659    }
6660    else if(type == "RP")
6661    {
6662     // p_{m*n,0} = q_{m*n,0}:
6663     p1n0kRe = q1n0kRe; 
6664     p1n0kIm = q1n0kIm; 
6665             
6666     mp = mq; 
6667     
6668     t = 0; // typeFlag = RP or POI
6669    }
6670       
6671    // 2'-particle correlation for particular (pt,eta) bin:
6672    Double_t two1n1nPtEta = 0.;
6673    Double_t mWeight2pPrime = 0.; // multiplicity weight for <2'>
6674    if(mp*dMult-mq)
6675    {
6676     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
6677                  / (mp*dMult-mq);
6678     // determine multiplicity weight:
6679     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
6680     {
6681      mWeight2pPrime = mp*dMult-mq;
6682     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
6683       {
6684        mWeight2pPrime = 1.;    
6685       } 
6686     if(type == "POI") // to be improved (I do not this if)
6687     { 
6688      // fill profile to get <<2'>> for POIs
6689      fDiffFlowCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);
6690      // fill profile to get <<2'>^2> for POIs
6691      fDiffFlowSquaredCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);   
6692      // histogram to store <2'> for POIs e-b-e (needed in some other methods):
6693      fDiffFlowCorrelationsEBE[1][pe][0]->SetBinContent(b,two1n1nPtEta);      
6694      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][0]->SetBinContent(b,mWeight2pPrime);      
6695     }
6696     else if(type == "RP") // to be improved (I do not this if)
6697     {
6698      // profile to get <<2'>> for RPs:
6699      fDiffFlowCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);     
6700      // profile to get <<2'>^2> for RPs:
6701      fDiffFlowSquaredCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);          
6702      // histogram to store <2'> for RPs e-b-e (needed in some other methods):
6703      fDiffFlowCorrelationsEBE[0][pe][0]->SetBinContent(b,two1n1nPtEta); 
6704      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][0]->SetBinContent(b,mWeight2pPrime); 
6705     }
6706    } // end of if(mp*dMult-mq)
6707   
6708    // 4'-particle correlation:
6709    Double_t four1n1n1n1nPtEta = 0.;
6710    Double_t mWeight4pPrime = 0.; // multiplicity weight for <4'>
6711    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6712        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
6713    {
6714     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6715                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
6716                       - 2.*q2n0kIm*dReQ1n*dImQ1n
6717                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
6718                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
6719                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6720                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
6721                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
6722                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
6723                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
6724                       + 2.*mq*dMult                      
6725                       - 6.*mq)        
6726                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6727                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
6728     // determine multiplicity weight:
6729     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
6730     {
6731      mWeight4pPrime = (mp-mq)*dMult*(dMult-1.)*(dMult-2.) + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);
6732     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
6733       {
6734        mWeight4pPrime = 1.;    
6735       }     
6736     if(type == "POI")
6737     {
6738      // profile to get <<4'>> for POIs:
6739      fDiffFlowCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);      
6740      // profile to get <<4'>^2> for POIs:
6741      fDiffFlowSquaredCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime); 
6742      // histogram to store <4'> for POIs e-b-e (needed in some other methods):
6743      fDiffFlowCorrelationsEBE[1][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                               
6744      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][1]->SetBinContent(b,mWeight4pPrime);                               
6745     }
6746     else if(type == "RP")
6747     {
6748      // profile to get <<4'>> for RPs:
6749      fDiffFlowCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);    
6750      // profile to get <<4'>^2> for RPs:
6751      fDiffFlowSquaredCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime);    
6752      // histogram to store <4'> for RPs e-b-e (needed in some other methods):
6753      fDiffFlowCorrelationsEBE[0][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                   
6754      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][1]->SetBinContent(b,mWeight4pPrime);                   
6755     }
6756    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6757      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
6758    
6759  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6760  
6761    
6762 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta);
6763
6764 //================================================================================================================================
6765
6766 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights(TString type, TString ptOrEta)
6767 {
6768  // Calculate sums of various event weights for reduced correlations. 
6769  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
6770
6771  Int_t typeFlag = 0;
6772  Int_t ptEtaFlag = 0;
6773
6774  if(type == "RP")
6775  {
6776   typeFlag = 0;
6777  } else if(type == "POI")
6778    {
6779     typeFlag = 1;
6780    } 
6781      
6782  if(ptOrEta == "Pt")
6783  {
6784   ptEtaFlag = 0;
6785  } else if(ptOrEta == "Eta")
6786    {
6787     ptEtaFlag = 1;
6788    } 
6789    
6790  // shortcuts:
6791  Int_t t = typeFlag;
6792  Int_t pe = ptEtaFlag;
6793  
6794  // binning:
6795  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6796  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6797  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6798  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6799  
6800  for(Int_t rpq=0;rpq<3;rpq++)
6801  {
6802   for(Int_t m=0;m<4;m++)
6803   {
6804    for(Int_t k=0;k<9;k++)
6805    {
6806     if(!fReRPQ1dEBE[rpq][pe][m][k])
6807     {
6808      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
6809      cout<<"pe  = "<<pe<<endl;
6810      cout<<"rpq = "<<rpq<<endl;
6811      cout<<"m   = "<<m<<endl;
6812      cout<<"k   = "<<k<<endl;
6813      exit(0); 
6814     }
6815    }
6816   }
6817  }  
6818
6819  // multiplicities:
6820  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
6821  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
6822  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
6823  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
6824  
6825  // event weights for reduced correlations:
6826  Double_t dw2 = 0.; // event weight for <2'>
6827  Double_t dw4 = 0.; // event weight for <4'>
6828  //Double_t dw6 = 0.; // event weight for <6'>
6829  //Double_t dw8 = 0.; // event weight for <8'>
6830
6831  // looping over bins:
6832  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6833  {
6834   if(type == "RP")
6835   {
6836    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
6837    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
6838   } else if(type == "POI")
6839     {
6840      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
6841      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
6842     }
6843   
6844   // event weight for <2'>:
6845   dw2 = mp*dMult-mq;  
6846   fDiffFlowSumOfEventWeights[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2);
6847   fDiffFlowSumOfEventWeights[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw2,2.));
6848   
6849   // event weight for <4'>:
6850   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6851      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
6852   fDiffFlowSumOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4);
6853   fDiffFlowSumOfEventWeights[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw4,2.));
6854   
6855   // event weight for <6'>:
6856   //dw6 = ...;  
6857   //fDiffFlowSumOfEventWeights[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6);
6858   //fDiffFlowSumOfEventWeights[t][pe][t][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw6,2.));
6859   
6860   // event weight for <8'>:
6861   //dw8 = ...;  
6862   //fDiffFlowSumOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw8);
6863   //fDiffFlowSumOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw8,2.));   
6864  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++) 
6865  
6866 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights()
6867
6868
6869 //================================================================================================================================
6870
6871
6872 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
6873 {
6874  // Calculate sum of products of various event weights for both types of correlations (the ones for int. and diff. flow). 
6875  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
6876  //
6877  // Important: To fill fDiffFlowSumOfProductOfEventWeights[][][][] use bellow table (i,j) with following constraints: 
6878  // 1.) i<j  
6879  // 2.) do not store terms which DO NOT include reduced correlations;
6880  // Table:
6881  // [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'>]
6882   
6883  Int_t typeFlag = 0;
6884  Int_t ptEtaFlag = 0;
6885
6886  if(type == "RP")
6887  {
6888   typeFlag = 0;
6889  } else if(type == "POI")
6890    {
6891     typeFlag = 1;
6892    } 
6893      
6894  if(ptOrEta == "Pt")
6895  {
6896   ptEtaFlag = 0;
6897  } else if(ptOrEta == "Eta")
6898    {
6899     ptEtaFlag = 1;
6900    } 
6901      
6902  // shortcuts:
6903  Int_t t = typeFlag;
6904  Int_t pe = ptEtaFlag;
6905   
6906  // binning:
6907  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6908  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6909  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6910  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6911  
6912  // protection:
6913  for(Int_t rpq=0;rpq<3;rpq++)
6914  {
6915   for(Int_t m=0;m<4;m++)
6916   {
6917    for(Int_t k=0;k<9;k++)
6918    {
6919     if(!fReRPQ1dEBE[rpq][pe][m][k])
6920     {
6921      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
6922      cout<<"pe  = "<<pe<<endl;
6923      cout<<"rpq = "<<rpq<<endl;
6924      cout<<"m   = "<<m<<endl;
6925      cout<<"k   = "<<k<<endl;
6926      exit(0); 
6927     }
6928    }
6929   }
6930  }  
6931  
6932  // multiplicities:
6933  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
6934  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
6935  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
6936  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
6937  
6938  // event weights for correlations:
6939  Double_t dW2 = dMult*(dMult-1); // event weight for <2> 
6940  Double_t dW4 = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
6941  Double_t dW6 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
6942  Double_t dW8 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
6943
6944  // event weights for reduced correlations:
6945  Double_t dw2 = 0.; // event weight for <2'>
6946  Double_t dw4 = 0.; // event weight for <4'>
6947  //Double_t dw6 = 0.; // event weight for <6'>
6948  //Double_t dw8 = 0.; // event weight for <8'>
6949  
6950  // looping over bins:
6951  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6952  {
6953   if(type == "RP")
6954   {
6955    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
6956    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
6957   } else if(type == "POI")
6958     {
6959      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
6960      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
6961     }
6962   
6963   // event weight for <2'>:
6964   dw2 = mp*dMult-mq;  
6965   fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw2); // storing product of even weights for <2> and <2'>
6966   fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW4); // storing product of even weights for <4> and <2'>
6967   fDiffFlowSumOfProductOfEventWeights[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW6); // storing product of even weights for <6> and <2'>
6968   fDiffFlowSumOfProductOfEventWeights[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW8); // storing product of even weights for <8> and <2'>
6969   
6970   // event weight for <4'>:
6971   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6972      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
6973   fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw4); // storing product of even weights for <2> and <4'>
6974   fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw4); // storing product of even weights for <2'> and <4'>
6975   fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw4); // storing product of even weights for <4> and <4'>
6976   fDiffFlowSumOfProductOfEventWeights[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW6); // storing product of even weights for <6> and <4'> 
6977   fDiffFlowSumOfProductOfEventWeights[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW8); // storing product of even weights for <8> and <4'>
6978
6979   // event weight for <6'>:
6980   //dw6 = ...;  
6981   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw6); // storing product of even weights for <2> and <6'>
6982   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw6); // storing product of even weights for <2'> and <6'>
6983   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw6); // storing product of even weights for <4> and <6'>
6984   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw6); // storing product of even weights for <4'> and <6'> 
6985   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw6); // storing product of even weights for <6> and <6'>
6986   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dW8); // storing product of even weights for <6'> and <8>
6987   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
6988
6989   // event weight for <8'>:
6990   //dw8 = ...;  
6991   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw8); // storing product of even weights for <2> and <8'>
6992   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw8); // storing product of even weights for <2'> and <8'>
6993   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw8); // storing product of even weights for <4> and <8'>
6994   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw8); // storing product of even weights for <4'> and <8'> 
6995   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw8); // storing product of even weights for <6> and <8'>
6996   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
6997   //fDiffFlowSumOfProductOfEventWeights[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW8*dw8); // storing product of even weights for <8> and <8'>
6998   
6999   // Table:
7000   // [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'>]
7001    
7002  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7003  
7004
7005
7006 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
7007
7008
7009 //================================================================================================================================
7010
7011
7012 void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
7013 {
7014  // Transfer profiles into histograms and calculate statistical errors correctly.
7015
7016  Int_t typeFlag = 0;
7017  Int_t ptEtaFlag = 0;
7018
7019  if(type == "RP")
7020  {
7021   typeFlag = 0;
7022  } else if(type == "POI")
7023    {
7024     typeFlag = 1;
7025    } 
7026      
7027  if(ptOrEta == "Pt")
7028  {
7029   ptEtaFlag = 0;
7030  } else if(ptOrEta == "Eta")
7031    {
7032     ptEtaFlag = 1;
7033    } 
7034   
7035  // shortcuts:
7036  Int_t t = typeFlag;
7037  Int_t pe = ptEtaFlag;
7038              
7039  for(Int_t rci=0;rci<4;rci++)
7040  {
7041   if(!fDiffFlowCorrelationsPro[t][pe][rci])
7042   {
7043    cout<<"WARNING: fDiffFlowCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7044    cout<<"t   = "<<t<<endl; 
7045    cout<<"pe  = "<<pe<<endl; 
7046    cout<<"rci = "<<rci<<endl;
7047    exit(0); 
7048   }
7049   if(!fDiffFlowSquaredCorrelationsPro[t][pe][rci])
7050   {
7051    cout<<"WARNING: fDiffFlowSquaredCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7052    cout<<"t   = "<<t<<endl; 
7053    cout<<"pe  = "<<pe<<endl; 
7054    cout<<"rci = "<<rci<<endl;
7055    exit(0); 
7056   }
7057   for(Int_t power=0;power<2;power++)
7058   {
7059    if(!fDiffFlowSumOfEventWeights[t][pe][power][rci])
7060    {
7061     cout<<"WARNING: fDiffFlowSumOfEventWeights[t][pe][power][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7062     cout<<"t     = "<<t<<endl; 
7063     cout<<"pe    = "<<pe<<endl;
7064     cout<<"power = "<<power<<endl; 
7065     cout<<"rci   = "<<rci<<endl;
7066     exit(0); 
7067    }   
7068   } // end of for(Int_t power=0;power<2;power++)
7069  } // end of for(Int_t rci=0;rci<4;rci++)
7070     
7071  // common:
7072  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta}; 
7073  // transfer 1D profile into 1D histogram:
7074  Double_t correlation = 0.;
7075  Double_t squaredCorrelation = 0.;
7076  Double_t spread = 0.;
7077  Double_t sumOfWeights = 0.; // sum of weights for particular reduced correlations for particular pt or eta bin
7078  Double_t sumOfSquaredWeights = 0.; // sum of squared weights for particular reduced correlations for particular pt or eta bin
7079  Double_t error = 0.; // error = termA * spread * termB
7080                       // termA = (sqrt(sumOfSquaredWeights)/sumOfWeights) 
7081                       // termB = 1/pow(1-termA^2,0.5)
7082  Double_t termA = 0.;                      
7083  Double_t termB = 0.;                      
7084  for(Int_t rci=0;rci<4;rci++) // index of reduced correlation
7085  {
7086   for(Int_t b=1;b<=nBinsPtEta[pe];b++) // number of pt or eta bins
7087   {
7088    if(fDiffFlowCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2 || 
7089       fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2)
7090    {
7091     fDiffFlowCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7092     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7093     continue; // to be improved - should I ignore results in pt bins with one entry for reduced correlations or not?
7094    }  
7095    correlation = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7096    squaredCorrelation = fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7097    if(squaredCorrelation-correlation*correlation >= 0.)
7098    {
7099     spread = pow(squaredCorrelation-correlation*correlation,0.5);
7100    } else
7101      {
7102       cout<<endl;
7103       cout<<Form(" WARNING: Imaginary 'spread' for rci = %d, pe = %d, bin = %d !!!!",rci,pe,b)<<endl;
7104       cout<<endl;
7105      }
7106    sumOfWeights = fDiffFlowSumOfEventWeights[t][pe][0][rci]->GetBinContent(b);
7107    sumOfSquaredWeights = fDiffFlowSumOfEventWeights[t][pe][1][rci]->GetBinContent(b);
7108    if(sumOfWeights) termA = (pow(sumOfSquaredWeights,0.5)/sumOfWeights);
7109    if(1.-pow(termA,2.)>0.) termB = 1./pow(1.-pow(termA,2.),0.5); 
7110    error = termA*spread*termB; // final error (unbiased estimator for standard deviation)
7111    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinContent(b,correlation); 
7112    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinError(b,error); 
7113   } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7114  } // end of for(Int_t rci=0;rci<4;rci++)
7115  
7116 } // end of void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
7117
7118
7119 //================================================================================================================================
7120
7121
7122 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7123 {
7124  // store products: <2><2'>, <2><4'>, <2><6'>, <2><8'>, <2'><4>, 
7125  //                 <2'><4'>, <2'><6>, <2'><6'>, <2'><8>, <2'><8'>,
7126  //                 <4><4'>, <4><6'>, <4><8'>, <4'><6>, <4'><6'>, 
7127  //                 <4'><8>, <4'><8'>, <6><6'>, <6><8'>, <6'><8>, 
7128  //                 <6'><8'>, <8><8'>.
7129   
7130  Int_t typeFlag = 0;
7131  Int_t ptEtaFlag = 0;
7132
7133  if(type == "RP")
7134  {
7135   typeFlag = 0;
7136  } else if(type == "POI")
7137    {
7138     typeFlag = 1;
7139    } 
7140      
7141  if(ptOrEta == "Pt")
7142  {
7143   ptEtaFlag = 0;
7144  } else if(ptOrEta == "Eta")
7145    {
7146     ptEtaFlag = 1;
7147    } 
7148   
7149  // shortcuts:
7150  Int_t t = typeFlag;
7151  Int_t pe = ptEtaFlag;
7152      
7153  // common:
7154  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7155  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7156  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7157    
7158  // protections // to be improved (add protection for all pointers in this method)
7159  if(!fIntFlowCorrelationsEBE)
7160  {
7161   cout<<"WARNING: fIntFlowCorrelationsEBE is NULL in AFAWQC::CDFPOC() !!!!"<<endl;
7162   exit(0);
7163  } 
7164  
7165  /*    
7166  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
7167  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7168  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7169  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7170  */
7171
7172  // e-b-e correlations:
7173  Double_t twoEBE = fIntFlowCorrelationsEBE->GetBinContent(1); // <2>
7174  Double_t fourEBE = fIntFlowCorrelationsEBE->GetBinContent(2); // <4>
7175  Double_t sixEBE = fIntFlowCorrelationsEBE->GetBinContent(3); // <6>
7176  Double_t eightEBE = fIntFlowCorrelationsEBE->GetBinContent(4); // <8>
7177  
7178  // event weights for correlations:
7179  Double_t dW2 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1); // event weight for <2> 
7180  Double_t dW4 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2); // event weight for <4> 
7181  Double_t dW6 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(3); // event weight for <6> 
7182  Double_t dW8 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(4); // event weight for <8> 
7183   
7184  // e-b-e reduced correlations:
7185  Double_t twoReducedEBE = 0.; // <2'>
7186  Double_t fourReducedEBE = 0.; // <4'>
7187  Double_t sixReducedEBE = 0.; // <6'>
7188  Double_t eightReducedEBE = 0.; // <8'> 
7189  
7190  // event weights for reduced correlations:
7191  Double_t dw2 = 0.; // event weight for <2'>
7192  Double_t dw4 = 0.; // event weight for <4'>
7193  //Double_t dw6 = 0.; // event weight for <6'>
7194  //Double_t dw8 = 0.; // event weight for <8'>
7195
7196  // looping over bins:
7197  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7198  {
7199   // e-b-e reduced correlations:
7200   twoReducedEBE = fDiffFlowCorrelationsEBE[t][pe][0]->GetBinContent(b);
7201   fourReducedEBE = fDiffFlowCorrelationsEBE[t][pe][1]->GetBinContent(b);
7202   sixReducedEBE = fDiffFlowCorrelationsEBE[t][pe][2]->GetBinContent(b);
7203   eightReducedEBE = fDiffFlowCorrelationsEBE[t][pe][3]->GetBinContent(b);
7204   
7205   /*
7206   // to be improved (I should not do this here again)
7207   if(type == "RP")
7208   {
7209    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7210    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7211   } else if(type == "POI")
7212     {
7213      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7214      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7215     }
7216   
7217   // event weights for reduced correlations:
7218   dw2 = mp*dMult-mq; // weight for <2'> 
7219   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7220      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.); // weight for <4'>
7221   //dw6 = ...     
7222   //dw8 = ...     
7223   
7224   */
7225   
7226   dw2 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->GetBinContent(b);
7227   dw4 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->GetBinContent(b);
7228  
7229   // storing all products:
7230   fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*twoReducedEBE,dW2*dw2); // storing <2><2'>
7231   fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*twoReducedEBE,dW4*dw2); // storing <4><2'>
7232   fDiffFlowProductOfCorrelationsPro[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*twoReducedEBE,dW6*dw2); // storing <6><2'>
7233   fDiffFlowProductOfCorrelationsPro[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*twoReducedEBE,dW8*dw2); // storing <8><2'>
7234   
7235   // event weight for <4'>:
7236   fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*fourReducedEBE,dW2*dw4); // storing <2><4'>
7237   fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*fourReducedEBE,dw2*dw4); // storing <2'><4'>
7238   fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*fourReducedEBE,dW4*dw4); // storing <4><4'>
7239   fDiffFlowProductOfCorrelationsPro[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*fourReducedEBE,dW6*dw4); // storing <6><4'> 
7240   fDiffFlowProductOfCorrelationsPro[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*fourReducedEBE,dW8*dw4); // storing <8><4'>
7241
7242   // event weight for <6'>:
7243   //dw6 = ...;  
7244   //fDiffFlowProductOfCorrelationsPro[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*sixReducedEBE,dW2*dw6); // storing <2><6'>
7245   //fDiffFlowProductOfCorrelationsPro[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*sixReducedEBE,dw2*dw6); // storing <2'><6'>
7246   //fDiffFlowProductOfCorrelationsPro[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*sixReducedEBE,dW4*dw6); // storing <4><6'>
7247   //fDiffFlowProductOfCorrelationsPro[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*sixReducedEBE,dw4*dw6); // storing <4'><6'> 
7248   //fDiffFlowProductOfCorrelationsPro[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*sixReducedEBE,dW6*dw6); // storing <6><6'>
7249   //fDiffFlowProductOfCorrelationsPro[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightEBE,dw6*dW8); // storing <6'><8>
7250   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7251
7252   // event weight for <8'>:
7253   //dw8 = ...;  
7254   //fDiffFlowProductOfCorrelationsPro[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*eightReducedEBE,dW2*dw8); // storing <2><8'>
7255   //fDiffFlowProductOfCorrelationsPro[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*eightReducedEBE,dw2*dw8); // storing <2'><8'>
7256   //fDiffFlowProductOfCorrelationsPro[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*eightReducedEBE,dW4*dw8); // storing <4><8'>
7257   //fDiffFlowProductOfCorrelationsPro[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*eightReducedEBE,dw4*dw8); // storing <4'><8'> 
7258   //fDiffFlowProductOfCorrelationsPro[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*eightReducedEBE,dW6*dw8); // storing <6><8'>
7259   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7260   //fDiffFlowProductOfCorrelationsPro[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*eightReducedEBE,dW8*dw8); // storing <8><8'> 
7261  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++       
7262      
7263 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7264
7265
7266 //================================================================================================================================
7267     
7268     
7269 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta) // to be improved (reimplemented)
7270 {
7271  // a) Calculate unbiased estimators Cov(<2>,<2'>), Cov(<2>,<4'>), Cov(<4>,<2'>), Cov(<4>,<4'>) and Cov(<2'>,<4'>)
7272  //    for covariances V(<2>,<2'>), V(<2>,<4'>), V(<4>,<2'>), V(<4>,<4'>) and V(<2'>,<4'>).  
7273  // b) Store in histogram fDiffFlowCovariances[t][pe][index] for instance the following: 
7274  //
7275  //             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)]
7276  // 
7277  //     where N is the number of events, w_{<2>} is event weight for <2> and w_{<2'>} is event weight for <2'>.
7278  // c) Binning of fDiffFlowCovariances[t][pe][index] is organized as follows:
7279  // 
7280  //     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)] 
7281  //     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)] 
7282  //     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)] 
7283  //     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)] 
7284  //     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)] 
7285  //     ...
7286   
7287  Int_t typeFlag = 0;
7288  Int_t ptEtaFlag = 0;
7289
7290  if(type == "RP")
7291  {
7292   typeFlag = 0;
7293  } else if(type == "POI")
7294    {
7295     typeFlag = 1;
7296    } 
7297      
7298  if(ptOrEta == "Pt")
7299  {
7300   ptEtaFlag = 0;
7301  } else if(ptOrEta == "Eta")
7302    {
7303     ptEtaFlag = 1;
7304    } 
7305   
7306  // shortcuts:
7307  Int_t t = typeFlag;
7308  Int_t pe = ptEtaFlag;
7309      
7310  // common:
7311  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7312  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
7313  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7314  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7315  
7316  // average correlations:
7317  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7318  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7319  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
7320  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
7321  
7322  // sum of weights for correlation:
7323  Double_t sumOfWeightsForTwo = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // sum_{i=1}^{N} w_{<2>}
7324  Double_t sumOfWeightsForFour = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // sum_{i=1}^{N} w_{<4>}
7325  //Double_t sumOfWeightsForSix = fIntFlowSumOfEventWeights[0]->GetBinContent(3); // sum_{i=1}^{N} w_{<6>}
7326  //Double_t sumOfWeightsForEight = fIntFlowSumOfEventWeights[0]->GetBinContent(4); // sum_{i=1}^{N} w_{<8>}
7327  
7328  // average reduced correlations:
7329  Double_t twoReduced = 0.; // <<2'>> 
7330  Double_t fourReduced = 0.; // <<4'>>
7331  //Double_t sixReduced = 0.; // <<6'>>
7332  //Double_t eightReduced = 0.; // <<8'>>
7333
7334  // sum of weights for reduced correlation:
7335  Double_t sumOfWeightsForTwoReduced = 0.; // sum_{i=1}^{N} w_{<2'>}
7336  Double_t sumOfWeightsForFourReduced = 0.; // sum_{i=1}^{N} w_{<4'>}
7337  //Double_t sumOfWeightsForSixReduced = 0.; // sum_{i=1}^{N} w_{<6'>}
7338  //Double_t sumOfWeightsForEightReduced = 0.; // sum_{i=1}^{N} w_{<8'>}
7339   
7340  // product of weights for reduced correlation:
7341  Double_t productOfWeightsForTwoTwoReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<2'>}
7342  Double_t productOfWeightsForTwoFourReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<4'>}
7343  Double_t productOfWeightsForFourTwoReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<2'>}
7344  Double_t productOfWeightsForFourFourReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<4'>}
7345  Double_t productOfWeightsForTwoReducedFourReduced = 0.; // sum_{i=1}^{N} w_{<2'>}w_{<4'>}
7346  // ...
7347  
7348  // products for differential flow:
7349  Double_t twoTwoReduced = 0; // <<2><2'>> 
7350  Double_t twoFourReduced = 0; // <<2><4'>> 
7351  Double_t fourTwoReduced = 0; // <<4><2'>> 
7352  Double_t fourFourReduced = 0; // <<4><4'>> 
7353  Double_t twoReducedFourReduced = 0; // <<2'><4'>> 
7354
7355  // denominators in the expressions for the unbiased estimators for covariances:
7356  // denominator = 1 - term1/(term2*term3)
7357  // prefactor = term1/(term2*term3)
7358  Double_t denominator = 0.; 
7359  Double_t prefactor = 0.;
7360  Double_t term1 = 0.; 
7361  Double_t term2 = 0.; 
7362  Double_t term3 = 0.; 
7363  
7364  // unbiased estimators for covariances for differential flow:
7365  Double_t covTwoTwoReduced = 0.; // Cov(<2>,<2'>)
7366  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(w_{<2>},w_{<2'>})
7367  Double_t covTwoFourReduced = 0.; // Cov(<2>,<4'>)
7368  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(w_{<2>},w_{<4'>})
7369  Double_t covFourTwoReduced = 0.; // Cov(<4>,<2'>)
7370  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(w_{<4>},w_{<2'>})
7371  Double_t covFourFourReduced = 0.; // Cov(<4>,<4'>)
7372  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(w_{<4>},w_{<4'>})
7373  Double_t covTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>)
7374  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(w_{<2'>},w_{<4'>})
7375  
7376  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7377  {
7378   // average reduced corelations:
7379   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
7380   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
7381   // average products:
7382   twoTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->GetBinContent(b);
7383   twoFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->GetBinContent(b);
7384   fourTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->GetBinContent(b);
7385   fourFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->GetBinContent(b);
7386   twoReducedFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->GetBinContent(b);  
7387   // sum of weights for reduced correlations:
7388   sumOfWeightsForTwoReduced = fDiffFlowSumOfEventWeights[t][pe][0][0]->GetBinContent(b);
7389   sumOfWeightsForFourReduced = fDiffFlowSumOfEventWeights[t][pe][0][1]->GetBinContent(b);
7390   // products of weights for correlations:
7391   productOfWeightsForTwoTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->GetBinContent(b); 
7392   productOfWeightsForTwoFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->GetBinContent(b);
7393   productOfWeightsForFourTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->GetBinContent(b);
7394   productOfWeightsForFourFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->GetBinContent(b);
7395   productOfWeightsForTwoReducedFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->GetBinContent(b);
7396   // denominator for the unbiased estimator for covariances: 1 - term1/(term2*term3) 
7397   // prefactor (multiplies Cov's) = term1/(term2*term3)       
7398   // <2>,<2'>:
7399   term1 = productOfWeightsForTwoTwoReduced;      
7400   term2 = sumOfWeightsForTwo;
7401   term3 = sumOfWeightsForTwoReduced;        
7402   if(term2*term3>0.)
7403   {
7404    denominator = 1.-term1/(term2*term3);
7405    prefactor = term1/(term2*term3);
7406    if(TMath::Abs(denominator)>1e-6)
7407    {
7408     covTwoTwoReduced = (twoTwoReduced-two*twoReduced)/denominator;            
7409     wCovTwoTwoReduced = covTwoTwoReduced*prefactor; 
7410     fDiffFlowCovariances[t][pe][0]->SetBinContent(b,wCovTwoTwoReduced);
7411    }
7412   }
7413   // <2>,<4'>:
7414   term1 = productOfWeightsForTwoFourReduced;      
7415   term2 = sumOfWeightsForTwo;
7416   term3 = sumOfWeightsForFourReduced;        
7417   if(term2*term3>0.)
7418   {
7419    denominator = 1.-term1/(term2*term3);
7420    prefactor = term1/(term2*term3);
7421    if(TMath::Abs(denominator)>1e-6)
7422    {
7423     covTwoFourReduced = (twoFourReduced-two*fourReduced)/denominator;            
7424     wCovTwoFourReduced = covTwoFourReduced*prefactor; 
7425     fDiffFlowCovariances[t][pe][1]->SetBinContent(b,wCovTwoFourReduced);
7426    }
7427   }
7428   // <4>,<2'>:
7429   term1 = productOfWeightsForFourTwoReduced;      
7430   term2 = sumOfWeightsForFour;
7431   term3 = sumOfWeightsForTwoReduced;        
7432   if(term2*term3>0.)
7433   {
7434    denominator = 1.-term1/(term2*term3);
7435    prefactor = term1/(term2*term3);
7436    if(TMath::Abs(denominator)>1e-6)
7437    {
7438     covFourTwoReduced = (fourTwoReduced-four*twoReduced)/denominator;            
7439     wCovFourTwoReduced = covFourTwoReduced*prefactor; 
7440     fDiffFlowCovariances[t][pe][2]->SetBinContent(b,wCovFourTwoReduced);
7441    }
7442   }
7443   // <4>,<4'>:
7444   term1 = productOfWeightsForFourFourReduced;      
7445   term2 = sumOfWeightsForFour;
7446   term3 = sumOfWeightsForFourReduced;        
7447   if(term2*term3>0.)
7448   {
7449    denominator = 1.-term1/(term2*term3);
7450    prefactor = term1/(term2*term3);
7451    if(TMath::Abs(denominator)>1e-6)
7452    {
7453     covFourFourReduced = (fourFourReduced-four*fourReduced)/denominator;            
7454     wCovFourFourReduced = covFourFourReduced*prefactor; 
7455     fDiffFlowCovariances[t][pe][3]->SetBinContent(b,wCovFourFourReduced);
7456    }
7457   }
7458   // <2'>,<4'>:
7459   term1 = productOfWeightsForTwoReducedFourReduced;      
7460   term2 = sumOfWeightsForTwoReduced;
7461   term3 = sumOfWeightsForFourReduced;        
7462   if(term2*term3>0.)
7463   {
7464    denominator = 1.-term1/(term2*term3);
7465    prefactor = term1/(term2*term3);
7466    if(TMath::Abs(denominator)>1e-6)
7467    {
7468     covTwoReducedFourReduced = (twoReducedFourReduced-twoReduced*fourReduced)/denominator;            
7469     wCovTwoReducedFourReduced = covTwoReducedFourReduced*prefactor; 
7470     fDiffFlowCovariances[t][pe][4]->SetBinContent(b,wCovTwoReducedFourReduced);
7471    }
7472   }   
7473  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7474   
7475 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta)
7476
7477
7478 //================================================================================================================================
7479
7480
7481 void AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, TString ptOrEta)
7482 {
7483  // calculate differential flow from differential cumulants and previously obtained integrated flow: (to be improved: description)
7484  
7485  Int_t typeFlag = 0;
7486  Int_t ptEtaFlag = 0;
7487
7488  if(type == "RP")
7489  {
7490   typeFlag = 0;
7491  } else if(type == "POI")
7492    {
7493     typeFlag = 1;
7494    } 
7495      
7496  if(ptOrEta == "Pt")
7497  {
7498   ptEtaFlag = 0;
7499  } else if(ptOrEta == "Eta")
7500    {
7501     ptEtaFlag = 1;
7502    } 
7503   
7504  // shortcuts:
7505  Int_t t = typeFlag;
7506  Int_t pe = ptEtaFlag;
7507      
7508  // common:
7509  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7510    
7511  // correlations:
7512  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7513  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7514  
7515  // statistical errors of correlations:
7516  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
7517  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2);   
7518     
7519  // reduced correlations:
7520  Double_t twoReduced = 0.; // <<2'>>
7521  Double_t fourReduced = 0.; // <<4'>>
7522  
7523  // statistical errors of reduced correlations:
7524  Double_t twoReducedError = 0.; 
7525  Double_t fourReducedError = 0.; 
7526
7527  // covariances:
7528  Double_t wCovTwoFour = 0.; // Cov(<2>,<4>) * prefactor(<2>,<4>)
7529  if(!fForgetAboutCovariances)
7530  {
7531   wCovTwoFour = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(<2>,<4>)
7532  }
7533  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
7534  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
7535  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(<4>,<2'>)
7536  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(<4>,<4'>)
7537  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
7538  
7539  // differential flow:
7540  Double_t v2Prime = 0.; // v'{2}                   
7541  Double_t v4Prime = 0.; // v'{4}
7542  
7543  // statistical error of differential flow:
7544  Double_t v2PrimeError = 0.;                    
7545  Double_t v4PrimeError = 0.; 
7546  
7547  // squared statistical error of differential flow:
7548  Double_t v2PrimeErrorSquared = 0.;                    
7549  Double_t v4PrimeErrorSquared = 0.; 
7550  
7551  // loop over pt or eta bins:
7552  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7553  {
7554   // reduced correlations and statistical errors:
7555   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
7556   twoReducedError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b);
7557   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
7558   fourReducedError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b);
7559   // covariances:
7560   if(!fForgetAboutCovariances)
7561   {
7562    wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b);
7563    wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b);
7564    wCovFourTwoReduced = fDiffFlowCovariances[t][pe][2]->GetBinContent(b);
7565    wCovFourFourReduced = fDiffFlowCovariances[t][pe][3]->GetBinContent(b);
7566    wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b);
7567   }
7568   // differential flow:
7569   // v'{2}:
7570   if(two>0.) 
7571   {
7572    v2Prime = twoReduced/pow(two,0.5);
7573    v2PrimeErrorSquared = (1./4.)*pow(two,-3.)*
7574                          (pow(twoReduced,2.)*pow(twoError,2.)
7575                           + 4.*pow(two,2.)*pow(twoReducedError,2.)
7576                           - 4.*two*twoReduced*wCovTwoTwoReduced);
7577      
7578                                                             
7579    if(v2PrimeErrorSquared>0.) v2PrimeError = pow(v2PrimeErrorSquared,0.5);
7580    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
7581    if(TMath::Abs(v2Prime)>1.e-44)fDiffFlow[t][pe][0]->SetBinError(b,v2PrimeError);     
7582   }
7583   // differential flow:
7584   // v'{4}
7585   if(2.*pow(two,2.)-four > 0.) 
7586   {
7587    v4Prime = (2.*two*twoReduced-fourReduced)/pow(2.*pow(two,2.)-four,3./4.);
7588    v4PrimeErrorSquared = pow(2.*pow(two,2.)-four,-7./2.)*
7589                          (pow(2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced,2.)*pow(twoError,2.)
7590                           + (9./16.)*pow(2.*two*twoReduced-fourReduced,2.)*pow(fourError,2.)
7591                           + 4.*pow(two,2.)*pow(2.*pow(two,2.)-four,2.)*pow(twoReducedError,2.)
7592                           + pow(2.*pow(two,2.)-four,2.)*pow(fourReducedError,2.)                          
7593                           - (3./2.)*(2.*two*twoReduced-fourReduced)
7594                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFour
7595                           - 4.*two*(2.*pow(two,2.)-four)
7596                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoTwoReduced
7597                           + 2.*(2.*pow(two,2.)-four)
7598                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFourReduced
7599                           + 3.*two*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourTwoReduced
7600                           - (3./2.)*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourFourReduced 
7601                           - 4.*two*pow(2.*pow(two,2.)-four,2.)*wCovTwoReducedFourReduced);  
7602    if(v4PrimeErrorSquared>0.) v4PrimeError = pow(v4PrimeErrorSquared,0.5);        
7603    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);
7604    if(TMath::Abs(v4Prime)>1.e-44)fDiffFlow[t][pe][1]->SetBinError(b,v4PrimeError);     
7605   }
7606   
7607  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
7608  
7609    
7610  
7611  
7612  /*
7613  // 2D:
7614  for(Int_t nua=0;nua<2;nua++)
7615  {
7616   for(Int_t p=1;p<=fnBinsPt;p++)
7617   {
7618    for(Int_t e=1;e<=fnBinsEta;e++) 
7619    { 
7620     // differential cumulants:
7621     Double_t qc2Prime = fFinalCumulants2D[t][pW][eW][nua][0]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e)); // QC{2'}                    
7622     Double_t qc4Prime = fFinalCumulants2D[t][pW][eW][nua][1]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e)); // QC{4'}
7623     // differential flow:
7624     Double_t v2Prime = 0.;                    
7625     Double_t v4Prime = 0.; 
7626     if(v2) 
7627     {
7628      v2Prime = qc2Prime/v2;
7629      fFinalFlow2D[t][pW][eW][nua][0]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][0]->GetBin(p,e),v2Prime);  
7630     }                   
7631     if(v4)
7632     {
7633      v4Prime = -qc4Prime/pow(v4,3.); 
7634      fFinalFlow2D[t][pW][eW][nua][1]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][1]->GetBin(p,e),v4Prime);  
7635     }                    
7636    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
7637   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
7638  } // end of for(Int_t nua=0;nua<2;nua++)
7639  */
7640
7641 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights)
7642
7643 //================================================================================================================================
7644
7645 void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
7646 {
7647  // a) Store all flags for integrated flow in profile fIntFlowFlags.
7648  
7649  if(!fIntFlowFlags)
7650  {
7651   cout<<"WARNING: fIntFlowFlags is NULL in AFAWQC::SFFIF() !!!!"<<endl;
7652   exit(0);
7653  } 
7654
7655  // particle weights used or not:
7656  fIntFlowFlags->Fill(0.5,(Int_t)fUsePhiWeights||fUsePtWeights||fUseEtaWeights);
7657  // which event weights were used:
7658  if(strcmp(fMultiplicityWeight->Data(),"combinations"))
7659  {
7660   fIntFlowFlags->Fill(1.5,0); // 0 = "combinations" (default)
7661  } else if(strcmp(fMultiplicityWeight->Data(),"unit"))
7662    {
7663     fIntFlowFlags->Fill(1.5,1); // 1 = "unit"   
7664    } else if(strcmp(fMultiplicityWeight->Data(),"multiplicity"))
7665      {
7666       fIntFlowFlags->Fill(1.5,2); // 2 = "multiplicity"        
7667      } 
7668  fIntFlowFlags->Fill(2.5,(Int_t)fApplyCorrectionForNUA);
7669  fIntFlowFlags->Fill(3.5,(Int_t)fPrintFinalResults[0]);
7670  fIntFlowFlags->Fill(4.5,(Int_t)fPrintFinalResults[1]);
7671  fIntFlowFlags->Fill(5.5,(Int_t)fPrintFinalResults[2]);
7672  fIntFlowFlags->Fill(6.5,(Int_t)fPrintFinalResults[3]);
7673  fIntFlowFlags->Fill(7.5,(Int_t)fApplyCorrectionForNUAVsM);
7674  fIntFlowFlags->Fill(8.5,(Int_t)fPropagateErrorAlsoFromNIT);
7675  fIntFlowFlags->Fill(9.5,(Int_t)fCalculateCumulantsVsM);
7676  fIntFlowFlags->Fill(10.5,(Int_t)fMinimumBiasReferenceFlow);
7677  fIntFlowFlags->Fill(11.5,(Int_t)fForgetAboutCovariances);
7678  fIntFlowFlags->Fill(12.5,(Int_t)fStorePhiDistributionForOneEvent); 
7679  fIntFlowFlags->Fill(13.5,(Int_t)fFillMultipleControlHistograms);  
7680 } // end of void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
7681
7682 //================================================================================================================================
7683
7684 void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
7685 {
7686  // Store all flags for differential flow in the profile fDiffFlowFlags.
7687   
7688  if(!fDiffFlowFlags)
7689  {
7690   cout<<"WARNING: fDiffFlowFlags is NULL in AFAWQC::SFFDF() !!!!"<<endl;
7691   exit(0);
7692  } 
7693  
7694  fDiffFlowFlags->Fill(0.5,fUsePhiWeights||fUsePtWeights||fUseEtaWeights); // particle weights used or not
7695  //fDiffFlowFlags->Fill(1.5,""); // which event weight was used? // to be improved
7696  fDiffFlowFlags->Fill(2.5,fApplyCorrectionForNUA); // corrected for non-uniform acceptance or not
7697  fDiffFlowFlags->Fill(3.5,fCalculate2DFlow); // calculate also 2D differential flow in (pt,eta) or not
7698     
7699 } // end of void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
7700
7701 //================================================================================================================================
7702
7703 void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
7704 {
7705  // Access all pointers to common control and common result histograms and profiles.
7706  
7707  TString commonHistsName = "AliFlowCommonHistQC";
7708  commonHistsName += fAnalysisLabel->Data();
7709  AliFlowCommonHist *commonHist = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHistsName.Data()));
7710  if(commonHist) 
7711  {
7712   this->SetCommonHists(commonHist); 
7713   if(fCommonHists->GetHarmonic())
7714   {
7715    fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
7716   } 
7717  } // end of if(commonHist) 
7718  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
7719  commonHists2ndOrderName += fAnalysisLabel->Data();
7720  AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists2ndOrderName.Data()));
7721  if(commonHist2nd) this->SetCommonHists2nd(commonHist2nd);   
7722  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
7723  commonHists4thOrderName += fAnalysisLabel->Data();
7724  AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists4thOrderName.Data()));
7725  if(commonHist4th) this->SetCommonHists4th(commonHist4th);  
7726  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
7727  commonHists6thOrderName += fAnalysisLabel->Data();
7728  AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists6thOrderName.Data()));
7729  if(commonHist6th) this->SetCommonHists6th(commonHist6th);  
7730  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
7731  commonHists8thOrderName += fAnalysisLabel->Data();
7732  AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists8thOrderName.Data()));
7733  if(commonHist8th) this->SetCommonHists8th(commonHist8th); 
7734   
7735  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC"; 
7736  commonHistResults2ndOrderName += fAnalysisLabel->Data(); 
7737  AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>
7738                                               (fHistList->FindObject(commonHistResults2ndOrderName.Data()));
7739  if(commonHistRes2nd) this->SetCommonHistsResults2nd(commonHistRes2nd);   
7740  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
7741  commonHistResults4thOrderName += fAnalysisLabel->Data();
7742  AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>
7743                                               (fHistList->FindObject(commonHistResults4thOrderName.Data()));
7744  if(commonHistRes4th) this->SetCommonHistsResults4th(commonHistRes4th);  
7745  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
7746  commonHistResults6thOrderName += fAnalysisLabel->Data();
7747  AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>
7748                                               (fHistList->FindObject(commonHistResults6thOrderName.Data()));
7749  if(commonHistRes6th) this->SetCommonHistsResults6th(commonHistRes6th);  
7750  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
7751  commonHistResults8thOrderName += fAnalysisLabel->Data();
7752  AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>
7753                                               (fHistList->FindObject(commonHistResults8thOrderName.Data()));  
7754  if(commonHistRes8th) this->SetCommonHistsResults8th(commonHistRes8th);
7755        
7756 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
7757
7758
7759 //================================================================================================================================
7760
7761
7762 void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms() 
7763 {
7764  // Get pointers for histograms with particle weights.
7765
7766  TList *weightsList = dynamic_cast<TList*>(fHistList->FindObject("Weights"));
7767  if(weightsList) this->SetWeightsList(weightsList);
7768  TString fUseParticleWeightsName = "fUseParticleWeightsQC"; // to be improved (hirdwired label QC)
7769  fUseParticleWeightsName += fAnalysisLabel->Data();
7770  TProfile *useParticleWeights = dynamic_cast<TProfile*>(weightsList->FindObject(fUseParticleWeightsName.Data()));
7771  if(useParticleWeights)
7772  {
7773   this->SetUseParticleWeights(useParticleWeights);  
7774   fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
7775   fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
7776   fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3);  
7777  }
7778 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms(); 
7779
7780
7781 //================================================================================================================================
7782
7783
7784 void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms() 
7785 {
7786  // Get pointers for histograms and profiles relevant for integrated flow:
7787  //  a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults.
7788  //  b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow.
7789  //  c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds. 
7790  //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
7791   
7792  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data member?)
7793  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data member?)
7794  TString correlationFlag[4] = {"#LT#LT2#GT#GT","#LT#LT4#GT#GT","#LT#LT6#GT#GT","#LT#LT8#GT#GT"}; // to be improved (should I promote this to data member?)
7795  TString squaredCorrelationFlag[4] = {"#LT#LT2#GT^{2}#GT","#LT#LT4#GT^{2}#GT","#LT#LT6#GT^{2}#GT","#LT#LT8#GT^{2}#GT"}; // to be improved (should I promote this to data member?)
7796  
7797  // a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults:
7798  TList *intFlowList = NULL;
7799  intFlowList = dynamic_cast<TList*>(fHistList->FindObject("Integrated Flow"));
7800  if(!intFlowList) 
7801  {
7802   cout<<"WARNING: intFlowList is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7803   exit(0); 
7804  }  
7805   
7806  // b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow:
7807  TString intFlowFlagsName = "fIntFlowFlags";
7808  intFlowFlagsName += fAnalysisLabel->Data();
7809  TProfile *intFlowFlags = dynamic_cast<TProfile*>(intFlowList->FindObject(intFlowFlagsName.Data()));
7810  if(intFlowFlags)
7811  {
7812   this->SetIntFlowFlags(intFlowFlags);  
7813   fApplyCorrectionForNUA = (Bool_t)intFlowFlags->GetBinContent(3); 
7814   fApplyCorrectionForNUAVsM = (Bool_t)intFlowFlags->GetBinContent(8); 
7815   fCalculateCumulantsVsM = (Bool_t)intFlowFlags->GetBinContent(10);  
7816  } else 
7817    {
7818     cout<<"WARNING: intFlowFlags is NULL in FAWQC::GPFIFH() !!!!"<<endl;
7819    }
7820   
7821   // c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds:
7822   TList *intFlowProfiles = NULL;
7823   intFlowProfiles = dynamic_cast<TList*>(intFlowList->FindObject("Profiles"));
7824   if(intFlowProfiles)  
7825   {
7826    // average multiplicities:
7827    TString avMultiplicityName = "fAvMultiplicity";
7828    avMultiplicityName += fAnalysisLabel->Data();
7829    TProfile *avMultiplicity = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(avMultiplicityName.Data()));
7830    if(avMultiplicity) 
7831    {
7832     this->SetAvMultiplicity(avMultiplicity);
7833    } else 
7834      {
7835       cout<<"WARNING: avMultiplicity is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7836      }
7837    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with wrong errors!):
7838    TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
7839    intFlowCorrelationsProName += fAnalysisLabel->Data();
7840    TProfile *intFlowCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsProName.Data()));
7841    if(intFlowCorrelationsPro) 
7842    {
7843     this->SetIntFlowCorrelationsPro(intFlowCorrelationsPro);
7844    } else 
7845      {
7846       cout<<"WARNING: intFlowCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7847      }      
7848    // average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8^2>>:
7849    TString intFlowSquaredCorrelationsProName = "fIntFlowSquaredCorrelationsPro";
7850    intFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
7851    TProfile *intFlowSquaredCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowSquaredCorrelationsProName.Data()));
7852    if(intFlowSquaredCorrelationsPro) 
7853    {
7854     this->SetIntFlowSquaredCorrelationsPro(intFlowSquaredCorrelationsPro);
7855    } else 
7856      {
7857       cout<<"WARNING: intFlowSquaredCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7858      }             
7859    if(fCalculateCumulantsVsM)
7860    {
7861     // Average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (error is wrong here):   
7862     TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
7863     intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
7864     for(Int_t ci=0;ci<4;ci++) // correlation index
7865     {
7866      TProfile *intFlowCorrelationsVsMPro = dynamic_cast<TProfile*>
7867                                         (intFlowProfiles->FindObject(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data())));
7868      if(intFlowCorrelationsVsMPro)
7869      {
7870       this->SetIntFlowCorrelationsVsMPro(intFlowCorrelationsVsMPro,ci);
7871      } else
7872        {
7873         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7874        }   
7875     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
7876     // Average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> versus multiplicity for all events:   
7877     TString intFlowSquaredCorrelationsVsMProName = "fIntFlowSquaredCorrelationsVsMPro";
7878     intFlowSquaredCorrelationsVsMProName += fAnalysisLabel->Data();
7879     for(Int_t ci=0;ci<4;ci++) // correlation index
7880     {
7881      TProfile *intFlowSquaredCorrelationsVsMPro = dynamic_cast<TProfile*>
7882                       (intFlowProfiles->FindObject(Form("%s, %s",intFlowSquaredCorrelationsVsMProName.Data(),squaredCorrelationFlag[ci].Data())));
7883      if(intFlowSquaredCorrelationsVsMPro)
7884      {
7885       this->SetIntFlowSquaredCorrelationsVsMPro(intFlowSquaredCorrelationsVsMPro,ci);
7886      } else
7887        {
7888         cout<<"WARNING: "<<Form("intFlowSquaredCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7889        }   
7890     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
7891    } // end of if(fCalculateCumulantsVsM)
7892    // average all correlations for integrated flow (with wrong errors!):
7893    TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
7894    intFlowCorrelationsAllProName += fAnalysisLabel->Data();
7895    TProfile *intFlowCorrelationsAllPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsAllProName.Data()));
7896    if(intFlowCorrelationsAllPro) 
7897    {
7898     this->SetIntFlowCorrelationsAllPro(intFlowCorrelationsAllPro);
7899    } else 
7900      {
7901       cout<<"WARNING: intFlowCorrelationsAllPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7902      }     
7903    // average extra correlations for integrated flow (which appear only when particle weights are used):
7904    // (to be improved: Weak point in implementation, I am assuming here that method GetPointersForParticleWeightsHistograms() was called)
7905    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
7906    {
7907     TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
7908     intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
7909     TProfile *intFlowExtraCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowExtraCorrelationsProName.Data()));
7910     if(intFlowExtraCorrelationsPro) 
7911     {
7912      this->SetIntFlowExtraCorrelationsPro(intFlowExtraCorrelationsPro);
7913     } else 
7914       {
7915        cout<<"WARNING: intFlowExtraCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7916       }
7917    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)        
7918    // average products of correlations <2>, <4>, <6> and <8>:  
7919    TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
7920    intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
7921    TProfile *intFlowProductOfCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrelationsProName.Data()));
7922    if(intFlowProductOfCorrelationsPro) 
7923    {
7924     this->SetIntFlowProductOfCorrelationsPro(intFlowProductOfCorrelationsPro);
7925    } else 
7926      {
7927       cout<<"WARNING: intFlowProductOfCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7928      }               
7929    // average product of correlations <2>, <4>, <6> and <8> versus multiplicity  
7930    // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
7931    if(fCalculateCumulantsVsM)
7932    {
7933     TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
7934     intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
7935     TString productFlag[6] = {"<<2><4>>","<<2><6>>","<<2><8>>","<<4><6>>","<<4><8>>","<<6><8>>"};
7936     for(Int_t pi=0;pi<6;pi++)
7937     { 
7938      TProfile *intFlowProductOfCorrelationsVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data())));
7939      if(intFlowProductOfCorrelationsVsMPro)
7940      {
7941       this->SetIntFlowProductOfCorrelationsVsMPro(intFlowProductOfCorrelationsVsMPro,pi);
7942      } else
7943        {
7944         cout<<"WARNING: "<<Form("intFlowProductOfCorrelationsVsMPro[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7945        }
7946     } // end of for(Int_t pi=0;pi<6;pi++)
7947    } // end of if(fCalculateCumulantsVsM)
7948    // average correction terms for non-uniform acceptance (with wrong errors!):
7949    for(Int_t sc=0;sc<2;sc++)
7950    {
7951     TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
7952     intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
7953     TProfile *intFlowCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()))));
7954     if(intFlowCorrectionTermsForNUAPro) 
7955     {
7956      this->SetIntFlowCorrectionTermsForNUAPro(intFlowCorrectionTermsForNUAPro,sc);
7957     } else 
7958       {
7959        cout<<"WARNING: intFlowCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7960        cout<<"sc = "<<sc<<endl;
7961       } 
7962     // versus multiplicity:
7963     if(fCalculateCumulantsVsM)
7964     {
7965      TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
7966      TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
7967      intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
7968      for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
7969      {
7970       TProfile *intFlowCorrectionTermsForNUAVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s: #LT#LT%s%s#GT#GT",intFlowCorrectionTermsForNUAVsMProName.Data(),sinCosFlag[sc].Data(),correctionTermFlag[ci].Data())));
7971       if(intFlowCorrectionTermsForNUAVsMPro) 
7972       {
7973        this->SetIntFlowCorrectionTermsForNUAVsMPro(intFlowCorrectionTermsForNUAVsMPro,sc,ci);
7974       } else 
7975         {
7976          cout<<"WARNING: intFlowCorrectionTermsForNUAVsMPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7977          cout<<"sc = "<<sc<<endl;
7978          cout<<"ci = "<<ci<<endl;
7979         }       
7980      } // end of for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
7981     } // end of if(fCalculateCumulantsVsM)
7982    } // end of for(Int_t sc=0;sc<2;sc++)           
7983    // average products of correction terms for NUA:  
7984    TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
7985    intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
7986    TProfile *intFlowProductOfCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrectionTermsForNUAProName.Data()));
7987    if(intFlowProductOfCorrectionTermsForNUAPro) 
7988    {
7989     this->SetIntFlowProductOfCorrectionTermsForNUAPro(intFlowProductOfCorrectionTermsForNUAPro);
7990    } else 
7991      {
7992       cout<<"WARNING: intFlowProductOfCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7993      }     
7994   } else // to if(intFlowProfiles)  
7995     {
7996      cout<<"WARNING: intFlowProfiles is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7997     }
7998    
7999   //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
8000   TList *intFlowResults = NULL;
8001   intFlowResults = dynamic_cast<TList*>(intFlowList->FindObject("Results"));
8002   if(intFlowResults)
8003   {
8004    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!):
8005    TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
8006    intFlowCorrelationsHistName += fAnalysisLabel->Data();
8007    TH1D *intFlowCorrelationsHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsHistName.Data()));
8008    if(intFlowCorrelationsHist) 
8009    {
8010     this->SetIntFlowCorrelationsHist(intFlowCorrelationsHist);
8011    } else 
8012      {
8013       cout<<"WARNING: intFlowCorrelationsHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8014      } 
8015    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!) vs M:    
8016    if(fCalculateCumulantsVsM)
8017    {
8018     TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
8019     intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
8020     for(Int_t ci=0;ci<4;ci++) // correlation index
8021     {
8022      TH1D *intFlowCorrelationsVsMHist = dynamic_cast<TH1D*>
8023                                         (intFlowResults->FindObject(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data())));
8024      if(intFlowCorrelationsVsMHist)
8025      {
8026       this->SetIntFlowCorrelationsVsMHist(intFlowCorrelationsVsMHist,ci);
8027      } else
8028        {
8029         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMHist[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8030        }   
8031     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8032    } // end of if(fCalculateCumulantsVsM)
8033    // average all correlations for integrated flow (with correct errors!):
8034    TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
8035    intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
8036    TH1D *intFlowCorrelationsAllHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsAllHistName.Data()));
8037    if(intFlowCorrelationsAllHist) 
8038    {
8039     this->SetIntFlowCorrelationsAllHist(intFlowCorrelationsAllHist);
8040    } else 
8041      {
8042       cout<<"WARNING: intFlowCorrelationsAllHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8043      }  
8044    // average correction terms for non-uniform acceptance (with correct errors!):
8045    TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
8046    intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
8047    for(Int_t sc=0;sc<2;sc++)
8048    {
8049     TH1D *intFlowCorrectionTermsForNUAHist = dynamic_cast<TH1D*>(intFlowResults->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()))));
8050     if(intFlowCorrectionTermsForNUAHist) 
8051     {
8052      this->SetIntFlowCorrectionTermsForNUAHist(intFlowCorrectionTermsForNUAHist,sc);
8053     } else 
8054       {
8055        cout<<"WARNING: intFlowCorrectionTermsForNUAHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8056        cout<<"sc = "<<sc<<endl;
8057       } 
8058    } // end of for(Int_t sc=0;sc<2;sc++)           
8059    // covariances (multiplied with weight dependent prefactor):
8060    TString intFlowCovariancesName = "fIntFlowCovariances";
8061    intFlowCovariancesName += fAnalysisLabel->Data();
8062    TH1D *intFlowCovariances = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesName.Data()));
8063    if(intFlowCovariances) 
8064    {
8065     this->SetIntFlowCovariances(intFlowCovariances); 
8066    } else 
8067      {
8068       cout<<"WARNING: intFlowCovariances is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8069      } 
8070    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
8071    TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
8072    intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
8073    for(Int_t power=0;power<2;power++)
8074    {
8075     TH1D *intFlowSumOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s",intFlowSumOfEventWeightsName.Data(),powerFlag[power].Data())));
8076     if(intFlowSumOfEventWeights) 
8077     {
8078      this->SetIntFlowSumOfEventWeights(intFlowSumOfEventWeights,power);
8079     } else 
8080       {
8081        cout<<"WARNING: intFlowSumOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8082        cout<<"power = "<<power<<endl;
8083       }                                   
8084    } // end of for(Int_t power=0;power<2;power++)                                                                  
8085    // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
8086    TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
8087    intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
8088    TH1D *intFlowSumOfProductOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsName.Data()));
8089    if(intFlowSumOfProductOfEventWeights) 
8090    {
8091     this->SetIntFlowSumOfProductOfEventWeights(intFlowSumOfProductOfEventWeights);
8092    } else 
8093      {
8094       cout<<"WARNING: intFlowSumOfProductOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8095      } 
8096    // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
8097    // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
8098    if(fCalculateCumulantsVsM)
8099    {
8100     TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
8101     intFlowCovariancesVsMName += fAnalysisLabel->Data();
8102     TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
8103     for(Int_t ci=0;ci<6;ci++)
8104     { 
8105      TH1D *intFlowCovariancesVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data())));
8106      if(intFlowCovariancesVsM)
8107      {
8108       this->SetIntFlowCovariancesVsM(intFlowCovariancesVsM,ci);
8109      } else
8110        {
8111         cout<<"WARNING: "<<Form("intFlowCovariancesVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8112        }    
8113     } // end of for(Int_t ci=0;ci<6;ci++)
8114    } // end of if(fCalculateCumulantsVsM)
8115    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
8116    // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
8117    if(fCalculateCumulantsVsM)
8118    {
8119     TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
8120     intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
8121     TString sumFlag[2][4] = {{"#sum_{i=1}^{N} w_{<2>}","#sum_{i=1}^{N} w_{<4>}","#sum_{i=1}^{N} w_{<6>}","#sum_{i=1}^{N} w_{<8>}"},
8122                              {"#sum_{i=1}^{N} w_{<2>}^{2}","#sum_{i=1}^{N} w_{<4>}^{2}","#sum_{i=1}^{N} w_{<6>}^{2}","#sum_{i=1}^{N} w_{<8>}^{2}"}};
8123     for(Int_t si=0;si<4;si++)
8124     {
8125      for(Int_t power=0;power<2;power++)
8126      {
8127       TH1D *intFlowSumOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data())));
8128       if(intFlowSumOfEventWeightsVsM)
8129       {
8130        this->SetIntFlowSumOfEventWeightsVsM(intFlowSumOfEventWeightsVsM,si,power);
8131       } else
8132         {
8133          cout<<"WARNING: "<<Form("intFlowSumOfEventWeightsVsM[%d][%d]",si,power)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8134         }    
8135      } // end of for(Int_t power=0;power<2;power++)
8136     } // end of for(Int_t si=0;si<4;si++)   
8137    } // end of if(fCalculateCumulantsVsM)
8138    // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
8139    // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
8140    //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
8141    if(fCalculateCumulantsVsM)
8142    {
8143     TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
8144     intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
8145     TString sopowFlag[6] = {"#sum_{i=1}^{N} w_{<2>} w_{<4>}","#sum_{i=1}^{N} w_{<2>} w_{<6>}","#sum_{i=1}^{N} w_{<2>} w_{<8>}",
8146                             "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
8147     for(Int_t pi=0;pi<6;pi++)
8148     {
8149      TH1D *intFlowSumOfProductOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data())));
8150      if(intFlowSumOfProductOfEventWeightsVsM)
8151      {
8152       this->SetIntFlowSumOfProductOfEventWeightsVsM(intFlowSumOfProductOfEventWeightsVsM,pi);
8153      } else
8154        {
8155         cout<<"WARNING: "<<Form("intFlowSumOfProductOfEventWeightsVsM[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8156        }
8157     } // end of for(Int_t pi=0;pi<6;pi++)        
8158    } // end of if(fCalculateCumulantsVsM)
8159    // covariances for NUA (multiplied with weight dependent prefactor):
8160    TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
8161    intFlowCovariancesNUAName += fAnalysisLabel->Data();
8162    TH1D *intFlowCovariancesNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesNUAName.Data()));
8163    if(intFlowCovariancesNUA) 
8164    {
8165     this->SetIntFlowCovariancesNUA(intFlowCovariancesNUA); 
8166    } else 
8167      {
8168       cout<<"WARNING: intFlowCovariancesNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8169      } 
8170    // sum of linear and quadratic event weights NUA terms:
8171    TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
8172    intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
8173    for(Int_t sc=0;sc<2;sc++)
8174    {
8175     for(Int_t power=0;power<2;power++)
8176     {
8177      TH1D *intFlowSumOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s, %s",intFlowSumOfEventWeightsNUAName.Data(),powerFlag[power].Data(),sinCosFlag[sc].Data())));
8178      if(intFlowSumOfEventWeightsNUA) 
8179      {
8180       this->SetIntFlowSumOfEventWeightsNUA(intFlowSumOfEventWeightsNUA,sc,power);
8181      } else 
8182        {
8183         cout<<"WARNING: intFlowSumOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8184         cout<<"sc    = "<<sc<<endl;
8185         cout<<"power = "<<power<<endl;
8186        }                                   
8187     } // end of for(Int_t power=0;power<2;power++)                                                                  
8188    } // end of for(Int_t sc=0;sc<2;sc++)     
8189    // sum of products of event weights for NUA terms:  
8190    TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
8191    intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
8192    TH1D *intFlowSumOfProductOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsNUAName.Data()));
8193    if(intFlowSumOfProductOfEventWeightsNUA) 
8194    {
8195     this->SetIntFlowSumOfProductOfEventWeightsNUA(intFlowSumOfProductOfEventWeightsNUA);
8196    } else 
8197      {
8198       cout<<"WARNING: intFlowSumOfProductOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8199      } 
8200    // Final results for reference Q-cumulants:
8201    TString intFlowQcumulantsName = "fIntFlowQcumulants";
8202    intFlowQcumulantsName += fAnalysisLabel->Data();
8203    TH1D *intFlowQcumulants = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsName.Data()));
8204    if(intFlowQcumulants) 
8205    {
8206     this->SetIntFlowQcumulants(intFlowQcumulants);
8207    } else 
8208      {
8209       cout<<"WARNING: intFlowQcumulants is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8210      }  
8211    // Final results for reference Q-cumulants rebinned in M:
8212    if(fCalculateCumulantsVsM)
8213    {
8214     TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
8215     intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
8216     TH1D *intFlowQcumulantsRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsRebinnedInMName.Data()));
8217     if(intFlowQcumulantsRebinnedInM) 
8218     {
8219      this->SetIntFlowQcumulantsRebinnedInM(intFlowQcumulantsRebinnedInM);
8220     } else 
8221       {
8222        cout<<"WARNING: intFlowQcumulantsRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8223       }  
8224    } // end of if(fCalculateCumulantsVsM)
8225    // Ratio between error squared: with/without non-isotropic terms:
8226    TString intFlowQcumulantsErrorSquaredRatioName = "fIntFlowQcumulantsErrorSquaredRatio";
8227    intFlowQcumulantsErrorSquaredRatioName += fAnalysisLabel->Data();
8228    TH1D *intFlowQcumulantsErrorSquaredRatio = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsErrorSquaredRatioName.Data()));
8229    if(intFlowQcumulantsErrorSquaredRatio) 
8230    {
8231     this->SetIntFlowQcumulantsErrorSquaredRatio(intFlowQcumulantsErrorSquaredRatio);
8232    } else 
8233      {
8234       cout<<" WARNING: intntFlowQcumulantsErrorSquaredRatio is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8235      }  
8236    // final results for integrated Q-cumulants versus multiplicity:
8237    TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
8238    if(fCalculateCumulantsVsM)
8239    {
8240     TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
8241     intFlowQcumulantsVsMName += fAnalysisLabel->Data();
8242     for(Int_t co=0;co<4;co++) // cumulant order
8243     {
8244      TH1D *intFlowQcumulantsVsM = dynamic_cast<TH1D*>
8245                                   (intFlowResults->FindObject(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data())));
8246      if(intFlowQcumulantsVsM)
8247      {
8248       this->SetIntFlowQcumulantsVsM(intFlowQcumulantsVsM,co);
8249      } else
8250        {
8251         cout<<"WARNING: "<<Form("intFlowQcumulantsVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8252        }
8253     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8254    } // end of if(fCalculateCumulantsVsM)
8255    // Final reference flow estimates from Q-cumulants:
8256    TString intFlowName = "fIntFlow";
8257    intFlowName += fAnalysisLabel->Data();
8258    TH1D *intFlow = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowName.Data()));
8259    if(intFlow) 
8260    {
8261     this->SetIntFlow(intFlow);
8262    } else 
8263      {
8264       cout<<"WARNING: intFlow is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8265      } 
8266    // Final reference flow estimates from Q-cumulants vs M rebinned in M:
8267    if(fCalculateCumulantsVsM)
8268    {
8269     TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
8270     intFlowRebinnedInMName += fAnalysisLabel->Data();
8271     TH1D *intFlowRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowRebinnedInMName.Data()));
8272     if(intFlowRebinnedInM) 
8273     {
8274      this->SetIntFlowRebinnedInM(intFlowRebinnedInM);
8275     } else 
8276       {
8277        cout<<"WARNING: intFlowRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8278       } 
8279    } // end of if(fCalculateCumulantsVsM)
8280    // integrated flow from Q-cumulants versus multiplicity:
8281    if(fCalculateCumulantsVsM)
8282    {
8283     TString intFlowVsMName = "fIntFlowVsM";
8284     intFlowVsMName += fAnalysisLabel->Data();
8285     TString flowFlag[4] = {Form("v_{%d}{2,QC}",fHarmonic),Form("v_{%d}{4,QC}",fHarmonic),Form("v_{%d}{6,QC}",fHarmonic),Form("v_{%d}{8,QC}",fHarmonic)};
8286     for(Int_t co=0;co<4;co++) // cumulant order
8287     {
8288      TH1D *intFlowVsM = dynamic_cast<TH1D*>
8289                         (intFlowResults->FindObject(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data())));            
8290      if(intFlowVsM)
8291      {
8292       this->SetIntFlowVsM(intFlowVsM,co);
8293      } else
8294        {
8295         cout<<"WARNING: "<<Form("intFlowVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8296        }
8297     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8298    } // end of if(fCalculateCumulantsVsM)
8299    // quantifying detector effects effects to correlations:
8300    TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
8301    intFlowDetectorBiasName += fAnalysisLabel->Data();
8302    TH1D *intFlowDetectorBias = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowDetectorBiasName.Data()));
8303    if(intFlowDetectorBias) 
8304    {
8305     this->SetIntFlowDetectorBias(intFlowDetectorBias);
8306    } else 
8307      {
8308       cout<<"WARNING: intFlowDetectorBias is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8309      } 
8310    // quantifying detector effects effects to correlations vs multiplicity:
8311    if(fCalculateCumulantsVsM)
8312    {
8313     TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
8314     intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
8315     for(Int_t ci=0;ci<4;ci++) // correlation index
8316     {
8317      TH1D *intFlowDetectorBiasVsM = dynamic_cast<TH1D*>
8318                                     (intFlowResults->FindObject(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data())));
8319      if(intFlowDetectorBiasVsM)
8320      {
8321       this->SetIntFlowDetectorBiasVsM(intFlowDetectorBiasVsM,ci);
8322      } else
8323        {
8324         cout<<"WARNING: "<<Form("intFlowDetectorBiasVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8325        }
8326     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8327    } // end of if(fCalculateCumulantsVsM)
8328   } else // to if(intFlowResults)
8329     {
8330      cout<<"WARNING: intFlowResults is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8331     }
8332     
8333 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms()
8334
8335 //================================================================================================================================
8336
8337 void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
8338 {
8339  // Get pointer to all objects relevant for differential flow.
8340  //  a) Define flags locally (to be improved: should I promote flags to data members?);
8341  //  b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults;
8342  //  c) Get pointer to profile fDiffFlowFlags holding all flags for differential flow;
8343  //  d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
8344  //  e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
8345  
8346  // a) Define flags locally (to be improved: should I promote flags to data members?): 
8347  TString typeFlag[2] = {"RP","POI"}; 
8348  TString ptEtaFlag[2] = {"p_{T}","#eta"};
8349  TString powerFlag[2] = {"linear","quadratic"};
8350  TString sinCosFlag[2] = {"sin","cos"};
8351  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
8352  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
8353  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
8354  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"}; 
8355  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
8356  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
8357   
8358  // b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults:
8359  TList *diffFlowList = NULL;
8360  diffFlowList = dynamic_cast<TList*>(fHistList->FindObject("Differential Flow"));  
8361  if(!diffFlowList)
8362  { 
8363   cout<<"WARNING: diffFlowList is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8364   exit(0);
8365  }
8366  // list holding nested lists containing profiles:
8367  TList *diffFlowListProfiles = NULL;
8368  diffFlowListProfiles = dynamic_cast<TList*>(diffFlowList->FindObject("Profiles"));
8369  if(!diffFlowListProfiles)
8370  { 
8371   cout<<"WARNING: diffFlowListProfiles is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8372   exit(0);
8373  }
8374  // list holding nested lists containing 2D and 1D histograms with final results:
8375  TList *diffFlowListResults = NULL;
8376  diffFlowListResults = dynamic_cast<TList*>(diffFlowList->FindObject("Results"));
8377  if(!diffFlowListResults)
8378  { 
8379   cout<<"WARNING: diffFlowListResults is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8380   exit(0);
8381  }
8382  
8383  // c) Get pointer to profile holding all flags for differential flow;
8384  TString diffFlowFlagsName = "fDiffFlowFlags";
8385  diffFlowFlagsName += fAnalysisLabel->Data();
8386  TProfile *diffFlowFlags = dynamic_cast<TProfile*>(diffFlowList->FindObject(diffFlowFlagsName.Data()));
8387  Bool_t bCalculate2DFlow = kFALSE;
8388  if(diffFlowFlags)
8389  {
8390   this->SetDiffFlowFlags(diffFlowFlags);  
8391   bCalculate2DFlow = (Int_t)diffFlowFlags->GetBinContent(4);
8392   this->SetCalculate2DFlow(bCalculate2DFlow); // to be improved (shoul I call this setter somewhere else?)     
8393  }
8394   
8395  // d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
8396  // correlations:
8397  TList *diffFlowCorrelationsProList[2][2] = {{NULL}};
8398  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
8399  diffFlowCorrelationsProName += fAnalysisLabel->Data();
8400  TProfile *diffFlowCorrelationsPro[2][2][4] = {{{NULL}}}; 
8401  // squared correlations:  
8402  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
8403  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data(); 
8404  TProfile *diffFlowSquaredCorrelationsPro[2][2][4] = {{{NULL}}};  
8405  // products of correlations:
8406  TList *diffFlowProductOfCorrelationsProList[2][2] = {{NULL}};
8407  TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
8408  diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
8409  TProfile *diffFlowProductOfCorrelationsPro[2][2][8][8] = {{{{NULL}}}};   
8410  // corrections:
8411  TList *diffFlowCorrectionsProList[2][2] = {{NULL}};
8412  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
8413  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();  
8414  TProfile *diffFlowCorrectionTermsForNUAPro[2][2][2][10] = {{{{NULL}}}};   
8415  for(Int_t t=0;t<2;t++)
8416  {
8417   for(Int_t pe=0;pe<2;pe++)
8418   {
8419    diffFlowCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8420    if(!diffFlowCorrelationsProList[t][pe])
8421    { 
8422     cout<<"WARNING: diffFlowCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8423     cout<<"t = "<<t<<endl;
8424     cout<<"pe = "<<pe<<endl;
8425     exit(0);
8426    }
8427    for(Int_t ci=0;ci<4;ci++) // correlation index
8428    {
8429     // reduced correlations:
8430     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())));
8431     if(diffFlowCorrelationsPro[t][pe][ci])
8432     {
8433      this->SetDiffFlowCorrelationsPro(diffFlowCorrelationsPro[t][pe][ci],t,pe,ci);
8434     } else
8435       {
8436        cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8437        cout<<"t  = "<<t<<endl;
8438        cout<<"pe = "<<pe<<endl;   
8439        cout<<"ci = "<<ci<<endl;
8440       }     
8441     // reduced squared correlations:
8442     diffFlowSquaredCorrelationsPro[t][pe][ci] = dynamic_cast<TProfile*>(diffFlowCorrelationsProList[t][pe]->FindObject(Form("%s, %s, %s, %s",diffFlowSquaredCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedSquaredCorrelationIndex[ci].Data())));
8443     if(diffFlowSquaredCorrelationsPro[t][pe][ci])
8444     {
8445      this->SetDiffFlowSquaredCorrelationsPro(diffFlowSquaredCorrelationsPro[t][pe][ci],t,pe,ci);
8446     } else
8447       {
8448        cout<<"WARNING: diffFlowSquaredCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8449        cout<<"t  = "<<t<<endl;
8450        cout<<"pe = "<<pe<<endl;   
8451        cout<<"ci = "<<ci<<endl;
8452       }       
8453    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
8454    // products of correlations:    
8455    diffFlowProductOfCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()))); 
8456    if(!diffFlowProductOfCorrelationsProList[t][pe])
8457    { 
8458     cout<<"WARNING: ddiffFlowProductOfCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8459     cout<<"t = "<<t<<endl;
8460     cout<<"pe = "<<pe<<endl;
8461     exit(0);
8462    }
8463    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8464    {
8465     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8466     {
8467      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())));
8468      if(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2])
8469      {
8470       this->SetDiffFlowProductOfCorrelationsPro(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2],t,pe,mci1,mci2);
8471      } else
8472        {
8473         cout<<"WARNING: diffFlowProductOfCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8474         cout<<"t    = "<<t<<endl;
8475         cout<<"pe   = "<<pe<<endl;   
8476         cout<<"mci1 = "<<mci1<<endl;
8477         cout<<"mci2 = "<<mci2<<endl;
8478        }
8479      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8480     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8481    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
8482    // corrections:
8483    diffFlowCorrectionsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8484    if(!diffFlowCorrectionsProList[t][pe])
8485    { 
8486     cout<<"WARNING: diffFlowCorrectionsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8487     cout<<"t = "<<t<<endl;
8488     cout<<"pe = "<<pe<<endl;
8489     exit(0);
8490    }
8491    // correction terms for NUA:
8492    for(Int_t sc=0;sc<2;sc++) // sin or cos
8493    {
8494     for(Int_t cti=0;cti<9;cti++) // correction term index
8495     {
8496      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)));
8497      if(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti])
8498      {
8499       this->SetDiffFlowCorrectionTermsForNUAPro(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti],t,pe,sc,cti);
8500      } else
8501        {
8502         cout<<"WARNING: diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8503         cout<<"t   = "<<t<<endl;
8504         cout<<"pe  = "<<pe<<endl;   
8505         cout<<"sc  = "<<sc<<endl;
8506         cout<<"cti = "<<cti<<endl;
8507        }    
8508     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
8509    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
8510    // ...
8511   } // end of for(Int_t pe=0;pe<2;pe++)
8512  } // end of for(Int_t t=0;t<2;t++)
8513   
8514  // e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
8515  // reduced correlations:
8516  TList *diffFlowCorrelationsHistList[2][2] = {{NULL}};
8517  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
8518  diffFlowCorrelationsHistName += fAnalysisLabel->Data();  
8519  TH1D *diffFlowCorrelationsHist[2][2][4] = {{{NULL}}};
8520  // corrections for NUA:
8521  TList *diffFlowCorrectionsHistList[2][2] = {{NULL}};
8522  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
8523  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();  
8524  TH1D *diffFlowCorrectionTermsForNUAHist[2][2][2][10] = {{{{NULL}}}};
8525  // differential Q-cumulants:
8526  TList *diffFlowCumulantsHistList[2][2] = {{NULL}};
8527  TString diffFlowCumulantsName = "fDiffFlowCumulants";
8528  diffFlowCumulantsName += fAnalysisLabel->Data();  
8529  TH1D *diffFlowCumulants[2][2][4] = {{{NULL}}};
8530  // differential flow estimates from Q-cumulants:
8531  TList *diffFlowHistList[2][2] = {{NULL}};
8532  TString diffFlowName = "fDiffFlow";
8533  diffFlowName += fAnalysisLabel->Data();  
8534  TH1D *diffFlow[2][2][4] = {{{NULL}}};
8535  // differential covariances:
8536  TList *diffFlowCovariancesHistList[2][2] = {{NULL}};
8537  TString diffFlowCovariancesName = "fDiffFlowCovariances";
8538  diffFlowCovariancesName += fAnalysisLabel->Data();  
8539  TH1D *diffFlowCovariances[2][2][5] = {{{NULL}}};
8540  for(Int_t t=0;t<2;t++) // type: RP or POI
8541  { 
8542   for(Int_t pe=0;pe<2;pe++) // pt or eta
8543   {
8544    // reduced correlations:
8545    diffFlowCorrelationsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8546    if(!diffFlowCorrelationsHistList[t][pe])
8547    { 
8548     cout<<"WARNING: diffFlowCorrelationsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8549     cout<<"t = "<<t<<endl;
8550     cout<<"pe = "<<pe<<endl;
8551     exit(0);
8552    }
8553    for(Int_t index=0;index<4;index++) 
8554    {
8555     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())));
8556     if(diffFlowCorrelationsHist[t][pe][index])
8557     {
8558      this->SetDiffFlowCorrelationsHist(diffFlowCorrelationsHist[t][pe][index],t,pe,index);
8559     } else 
8560       {
8561        cout<<"WARNING: diffFlowCorrelationsHist[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8562        cout<<"t     = "<<t<<endl;
8563        cout<<"pe    = "<<pe<<endl;
8564        cout<<"index = "<<index<<endl;
8565        exit(0);       
8566       } 
8567    } // end of for(Int_t index=0;index<4;index++)
8568    // corrections:
8569    diffFlowCorrectionsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8570    if(!diffFlowCorrectionsHistList[t][pe])
8571    { 
8572     cout<<"WARNING: diffFlowCorrectionsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8573     cout<<"t = "<<t<<endl;
8574     cout<<"pe = "<<pe<<endl;
8575     exit(0);
8576    }
8577    // correction terms for NUA:
8578    for(Int_t sc=0;sc<2;sc++) // sin or cos
8579    {
8580     for(Int_t cti=0;cti<9;cti++) // correction term index
8581     {
8582      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)));
8583      if(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti])
8584      {
8585       this->SetDiffFlowCorrectionTermsForNUAHist(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti],t,pe,sc,cti);
8586      } else
8587        {
8588         cout<<"WARNING: diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8589         cout<<"t   = "<<t<<endl;
8590         cout<<"pe  = "<<pe<<endl;   
8591         cout<<"sc  = "<<sc<<endl;
8592         cout<<"cti = "<<cti<<endl;
8593        }    
8594     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
8595    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
8596    // ...
8597    // differential Q-cumulants:
8598    diffFlowCumulantsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8599    if(!diffFlowCumulantsHistList[t][pe])
8600    { 
8601     cout<<"WARNING: diffFlowCumulantsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8602     cout<<"t  = "<<t<<endl;
8603     cout<<"pe = "<<pe<<endl;
8604     exit(0);
8605    }
8606    for(Int_t index=0;index<4;index++) 
8607    {
8608     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())));
8609     if(diffFlowCumulants[t][pe][index])
8610     {
8611      this->SetDiffFlowCumulants(diffFlowCumulants[t][pe][index],t,pe,index);
8612     } else 
8613       {
8614        cout<<"WARNING: diffFlowCumulants[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8615        cout<<"t     = "<<t<<endl;
8616        cout<<"pe    = "<<pe<<endl;
8617        cout<<"index = "<<index<<endl;
8618        exit(0);       
8619       } 
8620    } // end of for(Int_t index=0;index<4;index++)
8621    // differential flow estimates from Q-cumulants:
8622    diffFlowHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8623    if(!diffFlowHistList[t][pe])
8624    { 
8625     cout<<"WARNING: diffFlowHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8626     cout<<"t  = "<<t<<endl;
8627     cout<<"pe = "<<pe<<endl;
8628     exit(0);
8629    }
8630    for(Int_t index=0;index<4;index++) 
8631    {
8632     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())));
8633     if(diffFlow[t][pe][index])
8634     {
8635      this->SetDiffFlow(diffFlow[t][pe][index],t,pe,index);
8636     } else 
8637       {
8638        cout<<"WARNING: diffFlow[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8639        cout<<"t     = "<<t<<endl;
8640        cout<<"pe    = "<<pe<<endl;
8641        cout<<"index = "<<index<<endl;
8642        exit(0);       
8643       } 
8644    } // end of for(Int_t index=0;index<4;index++)
8645    // differential covariances:
8646    diffFlowCovariancesHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8647    if(!diffFlowCovariancesHistList[t][pe])
8648    { 
8649     cout<<"WARNING: diffFlowCovariancesHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8650     cout<<"t  = "<<t<<endl;
8651     cout<<"pe = "<<pe<<endl;
8652     exit(0);
8653    }
8654    for(Int_t covIndex=0;covIndex<5;covIndex++) 
8655    {
8656     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())));
8657     if(diffFlowCovariances[t][pe][covIndex])
8658     {
8659      this->SetDiffFlowCovariances(diffFlowCovariances[t][pe][covIndex],t,pe,covIndex);
8660     } else 
8661       {
8662        cout<<"WARNING: diffFlowCovariances[t][pe][covIndex] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8663        cout<<"t        = "<<t<<endl;
8664        cout<<"pe       = "<<pe<<endl;
8665        cout<<"covIndex = "<<covIndex<<endl;
8666        exit(0);       
8667       } 
8668    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index    
8669   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8670  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
8671  // sum of event weights for reduced correlations:
8672  TList *diffFlowSumOfEventWeightsHistList[2][2][2] = {{{NULL}}};
8673  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
8674  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
8675  TH1D *diffFlowSumOfEventWeights[2][2][2][4] = {{{{NULL}}}};
8676  for(Int_t t=0;t<2;t++) // type is RP or POI
8677  { 
8678   for(Int_t pe=0;pe<2;pe++) // pt or eta
8679   { 
8680    for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
8681    {
8682     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())));
8683     if(!diffFlowSumOfEventWeightsHistList[t][pe][p])
8684     { 
8685      cout<<"WARNING: diffFlowSumOfEventWeightsHistList[t][pe][p] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8686      cout<<"t     = "<<t<<endl;
8687      cout<<"pe    = "<<pe<<endl;
8688      cout<<"power = "<<p<<endl;
8689      exit(0);
8690     }
8691     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
8692     {
8693      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())));    
8694      if(diffFlowSumOfEventWeights[t][pe][p][ew])
8695      {
8696       this->SetDiffFlowSumOfEventWeights(diffFlowSumOfEventWeights[t][pe][p][ew],t,pe,p,ew);
8697      } else 
8698        {
8699         cout<<"WARNING: diffFlowSumOfEventWeights[t][pe][p][ew] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8700         cout<<"t     = "<<t<<endl;
8701         cout<<"pe    = "<<pe<<endl;
8702         cout<<"power = "<<p<<endl;
8703         cout<<"ew    = "<<ew<<endl;
8704         exit(0);       
8705        } 
8706     }
8707    } // end of for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
8708   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8709  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
8710  //  
8711  TList *diffFlowSumOfProductOfEventWeightsHistList[2][2] = {{NULL}};
8712  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
8713  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
8714  TH1D *diffFlowSumOfProductOfEventWeights[2][2][8][8] = {{{{NULL}}}};
8715  for(Int_t t=0;t<2;t++) // type is RP or POI
8716  { 
8717   for(Int_t pe=0;pe<2;pe++) // pt or eta
8718   { 
8719    diffFlowSumOfProductOfEventWeightsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8720    if(!diffFlowSumOfProductOfEventWeightsHistList[t][pe])
8721    { 
8722     cout<<"WARNING: diffFlowSumOfProductOfEventWeightsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8723     cout<<"t     = "<<t<<endl;
8724     cout<<"pe    = "<<pe<<endl;
8725     exit(0);
8726    }
8727    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8728    {
8729     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8730     {
8731      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())));    
8732       if(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2])
8733       {
8734        this->SetDiffFlowSumOfProductOfEventWeights(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2],t,pe,mci1,mci2);
8735       } else 
8736         {
8737          cout<<"WARNING: diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8738          cout<<"t    = "<<t<<endl;
8739          cout<<"pe   = "<<pe<<endl;
8740          cout<<"mci1 = "<<mci1<<endl;
8741          cout<<"mci2 = "<<mci2<<endl;
8742          exit(0);       
8743         } 
8744      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8745     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8746    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8747   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8748  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
8749
8750 } // end void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
8751
8752
8753 //================================================================================================================================
8754
8755
8756 void AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
8757 {
8758  // Book all histograms and profiles needed for differential flow.
8759  //  a) Define flags locally (to be improved: should I promote flags to data members?);
8760  //  b) Book profile to hold all flags for differential flow;
8761  //  c) Book e-b-e quantities;
8762  //  d) Book profiles;
8763  //  e) Book histograms holding final results. 
8764  
8765  // a) Define flags locally (to be improved: should I promote flags to data members?): 
8766  TString typeFlag[2] = {"RP","POI"}; 
8767  TString ptEtaFlag[2] = {"p_{T}","#eta"};
8768  TString powerFlag[2] = {"linear","quadratic"};
8769  TString sinCosFlag[2] = {"sin","cos"};
8770  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
8771  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
8772  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
8773  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"};
8774  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
8775  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
8776  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8777  Double_t minPtEta[2] = {fPtMin,fEtaMin};
8778  Double_t maxPtEta[2] = {fPtMax,fEtaMax};
8779   
8780  // b) Book profile to hold all flags for differential flow:
8781  TString diffFlowFlagsName = "fDiffFlowFlags";
8782  diffFlowFlagsName += fAnalysisLabel->Data();
8783  fDiffFlowFlags = new TProfile(diffFlowFlagsName.Data(),"Flags for Differential Flow",4,0,4);
8784  fDiffFlowFlags->SetTickLength(-0.01,"Y");
8785  fDiffFlowFlags->SetMarkerStyle(25);
8786  fDiffFlowFlags->SetLabelSize(0.05);
8787  fDiffFlowFlags->SetLabelOffset(0.02,"Y");
8788  (fDiffFlowFlags->GetXaxis())->SetBinLabel(1,"Particle Weights");
8789  (fDiffFlowFlags->GetXaxis())->SetBinLabel(2,"Event Weights");
8790  (fDiffFlowFlags->GetXaxis())->SetBinLabel(3,"Corrected for NUA?");
8791  (fDiffFlowFlags->GetXaxis())->SetBinLabel(4,"Calculated 2D flow?");
8792  fDiffFlowList->Add(fDiffFlowFlags);
8793
8794  // c) Book e-b-e quantities:
8795  // Event-by-event r_{m*n,k}(pt,eta), p_{m*n,k}(pt,eta) and q_{m*n,k}(pt,eta)
8796  // Explanantion of notation:
8797  //  1.) n is harmonic, m is multiple of harmonic;
8798  //  2.) k is power of particle weight;
8799  //  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);   
8800  //  4.) p_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for POIs in particular (pt,eta) bin 
8801  //                          (if i-th POI is also RP, than it is weighted with w_i^k);   
8802  //  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 
8803  //                          (i-th RP&&POI is weighted with w_i^k)            
8804   
8805  // 1D:
8806  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP && POI )
8807  { 
8808   for(Int_t pe=0;pe<2;pe++) // pt or eta
8809   {
8810    for(Int_t m=0;m<4;m++) // multiple of harmonic
8811    {
8812     for(Int_t k=0;k<9;k++) // power of particle weight
8813     {
8814      fReRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),
8815                                              Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8816      fImRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),
8817                                              Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8818     }
8819    }
8820   }
8821  } 
8822  // to be improved (add explanation of fs1dEBE[t][pe][k]):   
8823  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8824  { 
8825   for(Int_t pe=0;pe<2;pe++) // pt or eta
8826   {
8827    for(Int_t k=0;k<9;k++) // power of particle weight
8828    {
8829     fs1dEBE[t][pe][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),
8830                                      Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8831    }
8832   }
8833  }
8834  // correction terms for nua:
8835  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
8836  { 
8837   for(Int_t pe=0;pe<2;pe++) // pt or eta
8838   {
8839    for(Int_t sc=0;sc<2;sc++) // sin or cos
8840    {
8841     for(Int_t cti=0;cti<9;cti++) // correction term index
8842     {
8843      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = new TH1D(Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),
8844                                              Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8845     }
8846    }
8847   }
8848  } 
8849  // 2D:
8850  if(fCalculate2DFlow)
8851  {
8852   TProfile2D styleRe("typeMultiplePowerRe","typeMultiplePowerRe",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8853   TProfile2D styleIm("typeMultiplePowerIm","typeMultiplePowerIm",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8854   for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8855   { 
8856    for(Int_t m=0;m<4;m++)
8857    {
8858     for(Int_t k=0;k<9;k++)
8859     {
8860      fReRPQ2dEBE[t][m][k] = (TProfile2D*)styleRe.Clone(Form("typeFlag%dmultiple%dpower%dRe",t,m,k)); 
8861      fImRPQ2dEBE[t][m][k] = (TProfile2D*)styleIm.Clone(Form("typeFlag%dmultiple%dpower%dIm",t,m,k));
8862     }
8863    } 
8864   } 
8865   TProfile2D styleS("typePower","typePower",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8866   for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8867   { 
8868    for(Int_t k=0;k<9;k++)
8869    {
8870     fs2dEBE[t][k] = (TProfile2D*)styleS.Clone(Form("typeFlag%dpower%d",t,k));
8871    }
8872   }
8873  } // end of if(fCalculate2DFlow)
8874  // reduced correlations e-b-e:
8875  TString diffFlowCorrelationsEBEName = "fDiffFlowCorrelationsEBE";
8876  diffFlowCorrelationsEBEName += fAnalysisLabel->Data();
8877  for(Int_t t=0;t<2;t++) // type: RP or POI
8878  { 
8879   for(Int_t pe=0;pe<2;pe++) // pt or eta
8880   {
8881    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8882    {
8883     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]);
8884    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
8885   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8886  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8887  // event weights for reduced correlations e-b-e:
8888  TString diffFlowEventWeightsForCorrelationsEBEName = "fDiffFlowEventWeightsForCorrelationsEBE";
8889  diffFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
8890  for(Int_t t=0;t<2;t++) // type: RP or POI
8891  { 
8892   for(Int_t pe=0;pe<2;pe++) // pt or eta
8893   {
8894    for(Int_t rci=0;rci<4;rci++) // event weight for reduced correlation index
8895    {
8896     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]);
8897    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
8898   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8899  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8900       
8901  // d) Book profiles;
8902  // reduced correlations:
8903  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
8904  diffFlowCorrelationsProName += fAnalysisLabel->Data();
8905  // reduced squared correlations:
8906  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
8907  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
8908  // corrections terms:
8909  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
8910  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
8911  // reduced correlations:
8912  for(Int_t t=0;t<2;t++) // type: RP or POI
8913  { 
8914   for(Int_t pe=0;pe<2;pe++) // pt or eta
8915   {
8916    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8917    {
8918     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");
8919     fDiffFlowCorrelationsPro[t][pe][rci]->Sumw2();
8920     fDiffFlowCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
8921     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
8922    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
8923   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8924  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8925  // reduced squared correlations:
8926  for(Int_t t=0;t<2;t++) // type: RP or POI
8927  { 
8928   for(Int_t pe=0;pe<2;pe++) // pt or eta
8929   {
8930    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8931    {
8932     fDiffFlowSquaredCorrelationsPro[t][pe][rci] = new TProfile(Form("%s, %s, %s, %s",diffFlowSquaredCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedSquaredCorrelationIndex[rci].Data()),Form("%s, %s, %s, %s",diffFlowSquaredCorrelationsProName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),reducedSquaredCorrelationIndex[rci].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe],"s");
8933     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->Sumw2();
8934     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
8935     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowSquaredCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
8936    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
8937   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8938  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8939  // correction terms for nua:
8940  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
8941  { 
8942   for(Int_t pe=0;pe<2;pe++) // pt or eta
8943   {
8944    for(Int_t sc=0;sc<2;sc++) // sin or cos
8945    {
8946     for(Int_t cti=0;cti<9;cti++) // correction term index
8947     {
8948      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]); 
8949      fDiffFlowCorrectionsProList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]);
8950     }
8951    }
8952   }
8953  } 
8954  // e) Book histograms holding final results. 
8955  // reduced correlations:
8956  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
8957  diffFlowCorrelationsHistName += fAnalysisLabel->Data();
8958  // corrections terms:
8959  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
8960  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
8961  // differential covariances:
8962  TString diffFlowCovariancesName = "fDiffFlowCovariances";
8963  diffFlowCovariancesName += fAnalysisLabel->Data();
8964  // differential Q-cumulants:
8965  TString diffFlowCumulantsName = "fDiffFlowCumulants";
8966  diffFlowCumulantsName += fAnalysisLabel->Data();
8967  // differential flow:
8968  TString diffFlowName = "fDiffFlow";
8969  diffFlowName += fAnalysisLabel->Data();
8970  for(Int_t t=0;t<2;t++) // type: RP or POI
8971  { 
8972   for(Int_t pe=0;pe<2;pe++) // pt or eta
8973   {
8974    for(Int_t index=0;index<4;index++) 
8975    {
8976     // reduced correlations:
8977     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]);
8978     fDiffFlowCorrelationsHist[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8979     fDiffFlowCorrelationsHistList[t][pe]->Add(fDiffFlowCorrelationsHist[t][pe][index]); 
8980     // differential Q-cumulants:
8981     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]);
8982     fDiffFlowCumulants[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8983     fDiffFlowCumulantsHistList[t][pe]->Add(fDiffFlowCumulants[t][pe][index]); 
8984     // differential flow estimates from Q-cumulants:
8985     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]);
8986     fDiffFlow[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8987     fDiffFlowHistList[t][pe]->Add(fDiffFlow[t][pe][index]); 
8988    } // end of for(Int_t index=0;index<4;index++) 
8989    for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index 
8990    {
8991     // differential covariances:
8992     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]);
8993     fDiffFlowCovariances[t][pe][covIndex]->SetXTitle(ptEtaFlag[pe].Data());
8994     fDiffFlowCovariancesHistList[t][pe]->Add(fDiffFlowCovariances[t][pe][covIndex]); 
8995    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index
8996    // products of both types of correlations: 
8997    TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
8998    diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
8999    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9000    {
9001     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9002     {
9003      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]); 
9004      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
9005      fDiffFlowProductOfCorrelationsProList[t][pe]->Add(fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]); 
9006      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9007     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9008    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
9009   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9010  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9011  // sums of event weights for reduced correlations: 
9012  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
9013  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
9014  for(Int_t t=0;t<2;t++) // type is RP or POI
9015  { 
9016   for(Int_t pe=0;pe<2;pe++) // pt or eta
9017   { 
9018    for(Int_t p=0;p<2;p++) // power of weights is either 1 or 2
9019    {
9020     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
9021     {
9022      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]); 
9023      fDiffFlowSumOfEventWeights[t][pe][p][ew]->SetXTitle(ptEtaFlag[pe].Data());
9024      fDiffFlowSumOfEventWeightsHistList[t][pe][p]->Add(fDiffFlowSumOfEventWeights[t][pe][p][ew]); // to be improved (add dedicated list to hold all this)
9025     }
9026    }
9027   }
9028  } 
9029  // sum of products of event weights for both types of correlations: 
9030  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
9031  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
9032  for(Int_t t=0;t<2;t++) // type is RP or POI
9033  {
9034   for(Int_t pe=0;pe<2;pe++) // pt or eta
9035   { 
9036    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9037    {
9038     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9039     {
9040      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]); 
9041      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
9042      fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->Add(fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]); 
9043      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9044     }
9045    }
9046   }
9047  } 
9048  // correction terms for nua:
9049  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9050  { 
9051   for(Int_t pe=0;pe<2;pe++) // pt or eta
9052   {
9053    for(Int_t sc=0;sc<2;sc++) // sin or cos
9054    {
9055     for(Int_t cti=0;cti<9;cti++) // correction term index
9056     {
9057      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]); 
9058      fDiffFlowCorrectionsHistList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]);
9059     }
9060    }
9061   }
9062  } 
9063           
9064 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
9065
9066 //================================================================================================================================
9067
9068 void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
9069 {
9070  // Calculate generalized Q-cumulants (cumulants corrected for non-unifom acceptance).
9071  
9072  // Isotropic cumulants:
9073  Double_t QC2 = fIntFlowQcumulants->GetBinContent(1);
9074  Double_t QC2Error = fIntFlowQcumulants->GetBinError(1);
9075  Double_t QC4 = fIntFlowQcumulants->GetBinContent(2);
9076  Double_t QC4Error = fIntFlowQcumulants->GetBinError(2);
9077  //Double_t QC6 = fIntFlowQcumulants->GetBinContent(3);
9078  //Double_t QC6Error = fIntFlowQcumulants->GetBinError(3);
9079  //Double_t QC8 = fIntFlowQcumulants->GetBinContent(4);
9080  //Double_t QC8Error = fIntFlowQcumulants->GetBinError(4);
9081  
9082  // Measured 2-, 4-, 6- and 8-particle correlations:
9083  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
9084  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <<2>>
9085  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
9086  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <<4>>
9087  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
9088  //Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <<6>>
9089  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
9090  //Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <<8>>
9091   
9092  // Non-isotropic terms:
9093  Double_t c1 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
9094  Double_t c1Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(1); // statistical error of <<cos(n*phi1)>>
9095  Double_t c2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
9096  Double_t c2Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(2); // statistical error of <<cos(n*(phi1+phi2))>>
9097  Double_t c3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
9098  Double_t c3Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(3); // statistical error of <<cos(n*(phi1-phi2-phi3))>>
9099  Double_t s1 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
9100  Double_t s1Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(1); // statistical error of <<sin(n*phi1)>>
9101  Double_t s2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
9102  Double_t s2Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(2); // statistical error of <<sin(n*(phi1+phi2))>>
9103  Double_t s3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
9104  Double_t s3Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(3); // statistical error of <<sin(n*(phi1-phi2-phi3))>>
9105  
9106  // Shortcuts:
9107  Double_t a1 = 2.*pow(c1,2.)+2.*pow(s1,2.)-two;
9108  Double_t a2 = 6.*pow(c1,3.)-2.*c1*c2+c3+6.*c1*pow(s1,2.)-2.*s1*s2-4.*c1*two;
9109  Double_t a3 = 2.*pow(s1,2.)-2.*pow(c1,2.)+c2;
9110  Double_t a4 = 6.*pow(s1,3.)+6.*pow(c1,2.)*s1+2.*c2*s1-2.*c1*s2-s3-4.*s1*two;
9111  Double_t a5 = 4.*c1*s1-s2;
9112  
9113  // Covariances (including weight dependent prefactor):
9114  Double_t wCov1 = 0.; // w*Cov(<2>,<cos(phi)) 
9115  Double_t wCov2 = 0.; // w*Cov(<2>,<sin(phi))
9116  Double_t wCov3 = 0.; // w*Cov(<cos(phi),<sin(phi))
9117  Double_t wCov4 = 0.; // w*Cov(<2>,<4>) 
9118  Double_t wCov5 = 0.; // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
9119  Double_t wCov6 = 0.; // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9120  Double_t wCov7 = 0.; // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
9121  Double_t wCov8 = 0.; // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9122  Double_t wCov9 = 0.; // w*Cov(<4>,<cos(#phi)>
9123  Double_t wCov10 = 0.; // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
9124  Double_t wCov11 = 0.; // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9125  Double_t wCov12 = 0.; // w*Cov(<4>,<sin(#phi)>
9126  Double_t wCov13 = 0.; // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
9127  Double_t wCov14 = 0.; // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9128  Double_t wCov15 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9129  Double_t wCov16 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9130  Double_t wCov17 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9131  Double_t wCov18 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9132  Double_t wCov19 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9133  Double_t wCov20 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9134  Double_t wCov21 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
9135  Double_t wCov22 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9136  Double_t wCov23 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9137  Double_t wCov24 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9138  Double_t wCov25 = 0.; // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
9139  Double_t wCov26 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9140  Double_t wCov27 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9141  Double_t wCov28 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9142  if(!fForgetAboutCovariances)
9143  {
9144   wCov1 = fIntFlowCovariancesNUA->GetBinContent(1); // w*Cov(<2>,<cos(phi)) 
9145   wCov2 = fIntFlowCovariancesNUA->GetBinContent(2); // w*Cov(<2>,<sin(phi))
9146   wCov3 = fIntFlowCovariancesNUA->GetBinContent(3); // w*Cov(<cos(phi),<sin(phi))
9147   wCov4 = fIntFlowCovariances->GetBinContent(1); // w*Cov(<2>,<4>) 
9148   wCov5 = fIntFlowCovariancesNUA->GetBinContent(4); // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
9149   wCov6 = fIntFlowCovariancesNUA->GetBinContent(6); // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9150   wCov7 = fIntFlowCovariancesNUA->GetBinContent(5); // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
9151   wCov8 = fIntFlowCovariancesNUA->GetBinContent(7); // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9152   wCov9 = fIntFlowCovariancesNUA->GetBinContent(8); // w*Cov(<4>,<cos(#phi)>
9153   wCov10 = fIntFlowCovariancesNUA->GetBinContent(10); // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
9154   wCov11 = fIntFlowCovariancesNUA->GetBinContent(12); // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9155   wCov12 = fIntFlowCovariancesNUA->GetBinContent(9); // w*Cov(<4>,<sin(#phi)>
9156   wCov13 = fIntFlowCovariancesNUA->GetBinContent(11); // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
9157   wCov14 = fIntFlowCovariancesNUA->GetBinContent(13); // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9158   wCov15 = fIntFlowCovariancesNUA->GetBinContent(14); // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9159   wCov16 = fIntFlowCovariancesNUA->GetBinContent(16); // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9160   wCov17 = fIntFlowCovariancesNUA->GetBinContent(15); // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9161   wCov18 = fIntFlowCovariancesNUA->GetBinContent(17); // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9162   wCov19 = fIntFlowCovariancesNUA->GetBinContent(23); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9163   wCov20 = fIntFlowCovariancesNUA->GetBinContent(18); // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9164   wCov21 = fIntFlowCovariancesNUA->GetBinContent(22); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
9165   wCov22 = fIntFlowCovariancesNUA->GetBinContent(24); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9166   wCov23 = fIntFlowCovariancesNUA->GetBinContent(20); // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9167   wCov24 = fIntFlowCovariancesNUA->GetBinContent(25); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9168   wCov25 = fIntFlowCovariancesNUA->GetBinContent(27); // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
9169   wCov26 = fIntFlowCovariancesNUA->GetBinContent(19); // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9170   wCov27 = fIntFlowCovariancesNUA->GetBinContent(21); // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9171   wCov28 = fIntFlowCovariancesNUA->GetBinContent(26); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9172  } // end of if(!fForgetAboutCovariances)
9173  
9174  // Calculating generalized QC{2}:
9175  //  Generalized QC{2}:
9176  Double_t gQC2 = two - pow(c1,2.) - pow(s1,2.);
9177  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(1,gQC2);} 
9178  //  Statistical error of generalized QC{2}:
9179  Double_t gQC2ErrorSquared = pow(twoError,2.)+4.*pow(c1,2.)*pow(c1Error,2.)
9180                            + 4.*pow(s1,2.)*pow(s1Error,2.)
9181                            - 4*c1*wCov1-4*s1*wCov2 
9182                            + 8.*c1*s1*wCov3;
9183  //  Store ratio of error squared - with/without NUA terms:
9184  Double_t ratioErrorSquaredQC2 = 0.;
9185  if(fIntFlowQcumulants->GetBinError(1)>0.)
9186  { 
9187   ratioErrorSquaredQC2 = (gQC2ErrorSquared/pow(fIntFlowQcumulants->GetBinError(1),2.));
9188   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(1,ratioErrorSquaredQC2);
9189  }
9190  //  If enabled, store error by including non-isotropic terms:                         
9191  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9192  {
9193   if(gQC2ErrorSquared>=0.)
9194   {
9195    fIntFlowQcumulants->SetBinError(1,pow(gQC2ErrorSquared,0.5));
9196   } else
9197     {
9198      fIntFlowQcumulants->SetBinError(1,0.);
9199      cout<<endl;
9200      cout<<" WARNING (QC): Statistical error of generalized QC{2} is imaginary !!!!"<<endl;
9201      cout<<endl;
9202     }   
9203  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9204  // Quantify detector bias to QC{2}:
9205  if(TMath::Abs(QC2)>0.)
9206  {
9207   fIntFlowDetectorBias->SetBinContent(1,gQC2/QC2); 
9208   if(QC2Error>0.)
9209   {
9210    Double_t errorSquared = gQC2ErrorSquared/pow(QC2,2.)+pow(gQC2,2.)*pow(QC2Error,2.)/pow(QC2,4.);
9211    if(errorSquared>0.)
9212    {
9213     fIntFlowDetectorBias->SetBinError(1,pow(errorSquared,0.5));  
9214    }
9215   }
9216  } // end of if(TMath::Abs(QC2)>0.)
9217
9218  // Calculating generalized QC{4}:
9219  //  Generalized QC{4}:
9220  Double_t gQC4 = four-2.*pow(two,2.)
9221                - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
9222                + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
9223                + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
9224  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(2,gQC4);}   
9225  //  Statistical error of generalized QC{4}:
9226  Double_t gQC4ErrorSquared = 16.*pow(a1,2.)*pow(twoError,2.)+pow(fourError,2.)+16.*pow(a2,2.)*pow(c1Error,2.)
9227                            + 4.*pow(a3,2.)*pow(c2Error,2.)+16.*pow(c1,2.)*pow(c3Error,2.)
9228                            + 16.*pow(a4,2.)*pow(s1Error,2.)+4.*pow(a5,2.)*pow(s2Error,2.)
9229                            + 16.*pow(s1,2.)*pow(s3Error,2.)+8.*a1*wCov4-32.*a1*a2*wCov1
9230                            - 16.*a3*a1*wCov5-32.*c1*a1*wCov6-32.*a1*a4*wCov2+16.*a5*a1*wCov7
9231                            + 32.*s1*a1*wCov8-8.*a2*wCov9-4.*a3*wCov10-8.*c1*wCov11-8.*a4*wCov12
9232                            + 4.*a5*wCov13+8.*s1*wCov14+16.*a3*a2*wCov15+32.*c1*a2*wCov16+32.*a2*a4*wCov3
9233                            - 16.*a5*a2*wCov17-32.*s1*a2*wCov18+16.*c1*a3*wCov19+16.*a3*a4*wCov20
9234                            - 8.*a3*a5*wCov21-16.*s1*a3*wCov22+32.*c1*a4*wCov23-16.*c1*a5*wCov24
9235                            - 32.*c1*s1*wCov25-16.*a5*a4*wCov26-32.*s1*a4*wCov27+16.*s1*a5*wCov28;
9236  //  Store ratio of error squared - with/without NUA terms:
9237  Double_t ratioErrorSquaredQC4 = 0.;
9238  if(fIntFlowQcumulants->GetBinError(2)>0.)
9239  { 
9240   ratioErrorSquaredQC4 = (gQC4ErrorSquared/pow(fIntFlowQcumulants->GetBinError(2),2.));
9241   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(2,ratioErrorSquaredQC4);
9242  }                          
9243  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9244  {
9245   if(gQC4ErrorSquared>=0.)
9246   {
9247    fIntFlowQcumulants->SetBinError(2,pow(gQC4ErrorSquared,0.5));
9248   } else
9249     {
9250      fIntFlowQcumulants->SetBinError(2,0.);
9251      cout<<endl;
9252      cout<<" WARNING (QC): Statistical error of generalized QC{4} is imaginary !!!!"<<endl;
9253      cout<<endl;
9254     }   
9255  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9256  // Quantify detector bias to QC{4}:
9257  if(TMath::Abs(QC4)>0.)
9258  {
9259   fIntFlowDetectorBias->SetBinContent(2,gQC4/QC4); 
9260   if(QC4Error>0.)
9261   {
9262    Double_t errorSquared = gQC4ErrorSquared/pow(QC4,2.)+pow(gQC4,2.)*pow(QC4Error,2.)/pow(QC4,4.);
9263    if(errorSquared>0.)
9264    {
9265     fIntFlowDetectorBias->SetBinError(2,pow(errorSquared,0.5));  
9266    }
9267   }
9268  } // end of if(TMath::Abs(QC4)>0.)
9269
9270
9271  // .... to be improved (continued for 6th and 8th order) ....            
9272  
9273      
9274  // versus multiplicity:
9275  if(fCalculateCumulantsVsM) // to be improved - propagate error for nua terms vs M
9276  { 
9277   Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
9278   Double_t value[4] = {0.}; // QCs vs M
9279   Double_t error[4] = {0.}; // error of QCs vs M
9280   Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
9281   Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
9282   for(Int_t b=1;b<=nBins;b++)
9283   {
9284    // Measured correlations:
9285    two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> vs M
9286    four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>> vs M
9287    // Isotropic cumulants:
9288    QC2 = two;
9289    QC4 = four-2.*pow(two,2.);
9290    // Non-isotropic terms:
9291    c1 = fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b); // <<cos(n*phi1)>>
9292    c2 = fIntFlowCorrectionTermsForNUAVsMPro[1][1]->GetBinContent(b); // <<cos(n*(phi1+phi2))>>
9293    c3 = fIntFlowCorrectionTermsForNUAVsMPro[1][2]->GetBinContent(b); // <<cos(n*(phi1-phi2-phi3))>>
9294    s1 = fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b); // <<sin(n*phi1)>>
9295    s2 = fIntFlowCorrectionTermsForNUAVsMPro[0][1]->GetBinContent(b); // <<sin(n*(phi1+phi2))>>
9296    s3 = fIntFlowCorrectionTermsForNUAVsMPro[0][2]->GetBinContent(b); // <<sin(n*(phi1-phi2-phi3))>>
9297    // Generalized QC{2} vs M:
9298    gQC2 = two - pow(c1,2.) - pow(s1,2.); 
9299    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[0]->SetBinContent(b,gQC2);}   
9300    // Generalized QC{4} vs M:  
9301    gQC4 = four-2.*pow(two,2.)
9302                  - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
9303                  + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
9304                  + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
9305    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[1]->SetBinContent(b,gQC4);}   
9306    // Detector bias vs M:
9307    if(TMath::Abs(QC2)>0.)
9308    {
9309     fIntFlowDetectorBiasVsM[0]->SetBinContent(b,gQC2/QC2); 
9310    } // end of if(TMath::Abs(QC2)>0.)
9311    if(TMath::Abs(QC4)>0.)
9312    {
9313     fIntFlowDetectorBiasVsM[1]->SetBinContent(b,gQC4/QC4); 
9314    } // end of if(TMath::Abs(QC4)>0.)  
9315    // Rebin in M:
9316    for(Int_t co=0;co<4;co++)
9317    {
9318     value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
9319     error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
9320     if(error[co]>0.)
9321     {
9322      dSum1[co]+=value[co]/(error[co]*error[co]);
9323      dSum2[co]+=1./(error[co]*error[co]);
9324     }
9325    } // end of for(Int_t co=0;co<4;co++) 
9326   } // end of for(Int_t b=1;b<=nBins;b++)
9327   // Store rebinned Q-cumulants:
9328   if(fApplyCorrectionForNUAVsM)
9329   {
9330    for(Int_t co=0;co<4;co++)
9331    {
9332     if(dSum2[co]>0.)
9333     {
9334      fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
9335      fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
9336     }
9337    } // end of for(Int_t co=0;co<4;co++)
9338   } // end of if(fApplyCorrectionForNUAVsM)
9339  } // end of if(fCalculateCumulantsVsM) 
9340      
9341 } // end of void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
9342  
9343 //================================================================================================================================
9344
9345 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow() 
9346 {
9347  // From profile fIntFlowCorrectionTermsForNUAPro[sc] access measured correction terms for NUA
9348  // and their spread, correctly calculate the statistical errors and store the final 
9349  // results and statistical errors for correction terms for NUA in histogram fIntFlowCorrectionTermsForNUAHist[sc].
9350  //
9351  // Remark: Statistical error of correction temrs is calculated as:
9352  //
9353  //          statistical error = termA * spread * termB:
9354  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
9355  //          termB = 1/sqrt(1-termA^2)   
9356  
9357  TString sinCosFlag[2] = {"sin","cos"}; // to be improved - promore this to data member?
9358  TString nonisotropicTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
9359     
9360  for(Int_t sc=0;sc<2;sc++) // sin or cos correction terms 
9361  {
9362   for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
9363   {
9364    Double_t correction = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci);
9365    Double_t spread = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinError(ci);
9366    Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeightsNUA[sc][0]->GetBinContent(ci);
9367    Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeightsNUA[sc][1]->GetBinContent(ci);
9368    Double_t termA = 0.;
9369    Double_t termB = 0.;
9370    if(TMath::Abs(sumOfLinearEventWeights)>1.e-44)
9371    {
9372     termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
9373    } else
9374      {
9375       cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in AFAWQC::FCTFNIF() !!!!"<<endl;
9376       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
9377      }
9378    if(1.-pow(termA,2.) > 0.)
9379    {
9380     termB = 1./pow(1-pow(termA,2.),0.5);
9381    } else
9382      {
9383       cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in AFAWQC::FCTFNIF() !!!!"<<endl;   
9384       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
9385      }     
9386    Double_t statisticalError = termA * spread * termB;
9387    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinContent(ci,correction);
9388    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinError(ci,statisticalError);
9389   } // end of for(Int_t ci=1;ci<=4;ci++) // correction term index
9390  } // end of for(Int sc=0;sc<2;sc++) // sin or cos correction terms 
9391                                                                                                                                                                                                
9392 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow()
9393
9394 //================================================================================================================================
9395
9396 void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
9397 {
9398  // Get pointers to all objects relevant for calculations with nested loops.
9399    
9400  TList *nestedLoopsList = dynamic_cast<TList*>(fHistList->FindObject("Nested Loops"));
9401  if(nestedLoopsList) 
9402  {
9403   this->SetNestedLoopsList(nestedLoopsList);
9404  } else
9405    {
9406     cout<<"WARNING: nestedLoopsList is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9407     exit(0);
9408    }
9409     
9410   TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
9411   TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
9412   TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
9413   TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
9414    
9415   TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
9416   evaluateNestedLoopsName += fAnalysisLabel->Data();  
9417   TProfile *evaluateNestedLoops = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(evaluateNestedLoopsName.Data()));
9418   Bool_t bEvaluateIntFlowNestedLoops = kFALSE;
9419   Bool_t bEvaluateDiffFlowNestedLoops = kFALSE;
9420   if(evaluateNestedLoops)
9421   {
9422    this->SetEvaluateNestedLoops(evaluateNestedLoops);
9423    bEvaluateIntFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(1);
9424    bEvaluateDiffFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(2);
9425   }
9426   // nested loops relevant for integrated flow:  
9427   if(bEvaluateIntFlowNestedLoops)
9428   {
9429    // correlations:
9430    TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
9431    intFlowDirectCorrelationsName += fAnalysisLabel->Data();
9432    TProfile *intFlowDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowDirectCorrelationsName.Data()));
9433    if(intFlowDirectCorrelations) 
9434    { 
9435     this->SetIntFlowDirectCorrelations(intFlowDirectCorrelations);
9436    } else
9437      {
9438       cout<<"WARNING: intFlowDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9439       exit(0);
9440      }
9441    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
9442    {
9443     TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
9444     intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
9445     TProfile *intFlowExtraDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowExtraDirectCorrelationsName.Data()));
9446     if(intFlowExtraDirectCorrelations) 
9447     { 
9448      this->SetIntFlowExtraDirectCorrelations(intFlowExtraDirectCorrelations);
9449     } else
9450       {
9451        cout<<"WARNING: intFlowExtraDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9452        exit(0);
9453       }       
9454    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
9455    // correction terms for non-uniform acceptance:
9456    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
9457    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
9458    TProfile *intFlowDirectCorrectionTermsForNUA[2] = {NULL};
9459    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
9460    {
9461     intFlowDirectCorrectionTermsForNUA[sc] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s: %s terms",intFlowDirectCorrectionTermsForNUAName.Data(),sinCosFlag[sc].Data())));
9462     if(intFlowDirectCorrectionTermsForNUA[sc]) 
9463     { 
9464      this->SetIntFlowDirectCorrectionTermsForNUA(intFlowDirectCorrectionTermsForNUA[sc],sc);
9465     } else
9466       {
9467        cout<<"WARNING: intFlowDirectCorrectionTermsForNUA[sc] is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9468        cout<<"sc = "<<sc<<endl;
9469        exit(0);
9470       }
9471    } // end of for(Int_t sc=0;sc<2;sc++) 
9472   } // end of if(bEvaluateIntFlowNestedLoops)
9473     
9474   // nested loops relevant for differential flow:  
9475   if(bEvaluateDiffFlowNestedLoops)
9476   {
9477    // correlations:
9478    TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
9479    diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
9480    TProfile *diffFlowDirectCorrelations[2][2][4] = {{{NULL}}};
9481    for(Int_t t=0;t<2;t++)
9482    {
9483     for(Int_t pe=0;pe<2;pe++)
9484     {
9485      for(Int_t ci=0;ci<4;ci++) // correlation index
9486      {
9487       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())));
9488       if(diffFlowDirectCorrelations[t][pe][ci])
9489       {
9490        this->SetDiffFlowDirectCorrelations(diffFlowDirectCorrelations[t][pe][ci],t,pe,ci);
9491       } else
9492         {
9493          cout<<"WARNING: diffFlowDirectCorrelations[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9494          cout<<"t  = "<<t<<endl;
9495          cout<<"pe = "<<pe<<endl;   
9496          cout<<"ci = "<<ci<<endl;
9497         }     
9498      } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
9499     } // end of for(Int_t pe=0;pe<2;pe++)
9500    } // end of for(Int_t t=0;t<2;t++)   
9501    // correction terms for non-uniform acceptance:
9502    TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
9503    diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();  
9504    TProfile *diffFlowDirectCorrectionTermsForNUA[2][2][2][10] = {{{{NULL}}}};   
9505    for(Int_t t=0;t<2;t++)
9506    {
9507     for(Int_t pe=0;pe<2;pe++)
9508     {
9509      // correction terms for NUA:
9510      for(Int_t sc=0;sc<2;sc++) // sin or cos
9511      {
9512       for(Int_t cti=0;cti<9;cti++) // correction term index
9513       {
9514        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)));
9515        if(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti])
9516        {
9517         this->SetDiffFlowDirectCorrectionTermsForNUA(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti],t,pe,sc,cti);
9518        } else
9519          {
9520           cout<<"WARNING: diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9521           cout<<"t   = "<<t<<endl;
9522           cout<<"pe  = "<<pe<<endl;   
9523           cout<<"sc  = "<<sc<<endl;
9524           cout<<"cti = "<<cti<<endl;
9525          }    
9526       } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
9527      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9528     } // end of for(Int_t pe=0;pe<2;pe++)
9529    } // end of for(Int_t t=0;t<2;t++)
9530    // number of RPs and POIs in selected pt and eta bins for cross-checkings:
9531    TString noOfParticlesInBinName = "fNoOfParticlesInBin";
9532    TH1D *noOfParticlesInBin = NULL;
9533    noOfParticlesInBin = dynamic_cast<TH1D*>(nestedLoopsList->FindObject(noOfParticlesInBinName.Data()));
9534    if(noOfParticlesInBin)
9535    {
9536     this->SetNoOfParticlesInBin(noOfParticlesInBin);
9537    } else
9538      {
9539       cout<<endl;
9540       cout<<" WARNING (QC): noOfParticlesInBin is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9541       cout<<endl;
9542      }
9543   } // end of if(bEvaluateDiffFlowNestedLoops)
9544
9545 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
9546
9547 //================================================================================================================================
9548
9549 void AliFlowAnalysisWithQCumulants::StoreHarmonic()
9550 {
9551  // Store flow harmonic in common control histograms.
9552
9553  (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
9554  if(fFillMultipleControlHistograms)
9555  {
9556   (fCommonHists2nd->GetHarmonic())->Fill(0.5,fHarmonic);
9557   (fCommonHists4th->GetHarmonic())->Fill(0.5,fHarmonic);
9558   (fCommonHists6th->GetHarmonic())->Fill(0.5,fHarmonic);
9559   (fCommonHists8th->GetHarmonic())->Fill(0.5,fHarmonic);
9560  }
9561  
9562 } // end of void AliFlowAnalysisWithQCumulants::StoreHarmonic()
9563
9564 //================================================================================================================================
9565
9566 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta) // type = RP or POI 
9567 {
9568  // Calculate all correlations needed for differential flow using particle weights.
9569  
9570  Int_t t = 0; // type flag 
9571  Int_t pe = 0; // ptEta flag
9572  
9573  if(type == "RP")
9574  {
9575   t = 0;
9576  } else if(type == "POI")
9577    {
9578     t = 1;
9579    }
9580
9581  if(ptOrEta == "Pt")
9582  {
9583   pe = 0;
9584  } else if(ptOrEta == "Eta")
9585    {
9586     pe = 1;
9587    }
9588     
9589  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9590  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9591  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9592  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9593
9594  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9595  Double_t dReQ1n1k = (*fReQ)(0,1);
9596  Double_t dReQ2n2k = (*fReQ)(1,2);
9597  Double_t dReQ1n3k = (*fReQ)(0,3);
9598  //Double_t dReQ4n4k = (*fReQ)(3,4);
9599  Double_t dImQ1n1k = (*fImQ)(0,1);
9600  Double_t dImQ2n2k = (*fImQ)(1,2);
9601  Double_t dImQ1n3k = (*fImQ)(0,3);
9602  //Double_t dImQ4n4k = (*fImQ)(3,4);
9603  
9604  // S^M_{p,k} (see .h file for the definition of fSMpk):
9605  Double_t dSM1p1k = (*fSMpk)(0,1);
9606  Double_t dSM1p2k = (*fSMpk)(0,2);
9607  Double_t dSM1p3k = (*fSMpk)(0,3);
9608  Double_t dSM2p1k = (*fSMpk)(1,1);
9609  Double_t dSM3p1k = (*fSMpk)(2,1);
9610  
9611  // looping over all bins and calculating reduced correlations: 
9612  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9613  {
9614   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
9615   Double_t p1n0kRe = 0.;
9616   Double_t p1n0kIm = 0.;
9617
9618   // number of POIs in particular (pt,eta) bin):
9619   Double_t mp = 0.;
9620
9621   // real and imaginary parts of q_{m*n,k}: 
9622   // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
9623   Double_t q1n2kRe = 0.;
9624   Double_t q1n2kIm = 0.;
9625   Double_t q2n1kRe = 0.;
9626   Double_t q2n1kIm = 0.;
9627
9628   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9629   Double_t s1p1k = 0.; 
9630   Double_t s1p2k = 0.; 
9631   Double_t s1p3k = 0.; 
9632    
9633   // M0111 from Eq. (118) in QC2c (to be improved (notation))
9634   Double_t dM0111 = 0.;
9635  
9636   if(type == "POI")
9637   {
9638    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
9639            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
9640    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
9641            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
9642             
9643    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9644     
9645    t = 1; // typeFlag = RP or POI
9646     
9647    // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
9648    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
9649            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
9650    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
9651            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));
9652    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
9653            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
9654    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
9655            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));
9656        
9657    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9658    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
9659    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
9660    s1p3k = pow(fs1dEBE[2][pe][3]->GetBinContent(b)*fs1dEBE[2][pe][3]->GetBinEntries(b),1.); 
9661      
9662    // M0111 from Eq. (118) in QC2c (to be improved (notation)):
9663    dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
9664           - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
9665           + 2.*(s1p3k-s1p2k*dSM1p1k));
9666   }
9667    else if(type == "RP")
9668    {
9669     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
9670     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
9671             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
9672     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
9673             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
9674     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
9675             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
9676     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
9677             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
9678
9679     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9680     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
9681     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
9682     s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
9683     
9684     // to be improved (cross-checked):
9685     p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
9686             * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
9687     p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
9688             * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
9689             
9690     mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9691      
9692     t = 0; // typeFlag = RP or POI
9693     
9694     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
9695     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
9696            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
9697            + 2.*(s1p3k-s1p2k*dSM1p1k));
9698     //...............................................................................................   
9699    }
9700    
9701    // 2'-particle correlation:
9702    Double_t two1n1nW0W1 = 0.;
9703    if(mp*dSM1p1k-s1p1k)
9704    {
9705     two1n1nW0W1 = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
9706                 / (mp*dSM1p1k-s1p1k);
9707    
9708     // fill profile to get <<2'>>     
9709     fDiffFlowCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1,mp*dSM1p1k-s1p1k);    
9710     // fill profile to get <<2'>^2>     
9711     fDiffFlowSquaredCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1*two1n1nW0W1,mp*dSM1p1k-s1p1k);        
9712     // histogram to store <2'> e-b-e (needed in some other methods):
9713     fDiffFlowCorrelationsEBE[t][pe][0]->SetBinContent(b,two1n1nW0W1);      
9714     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->SetBinContent(b,mp*dSM1p1k-s1p1k);      
9715    } // end of if(mp*dSM1p1k-s1p1k)
9716    
9717    // 4'-particle correlation:
9718    Double_t four1n1n1n1nW0W1W1W1 = 0.;
9719    if(dM0111)
9720    {
9721     four1n1n1n1nW0W1W1W1 = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
9722                          - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
9723                          - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
9724                          - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
9725                          + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
9726                          - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
9727                          - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
9728                          + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
9729                          + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
9730                          + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
9731                          + 2.*s1p1k*dSM1p2k                                      
9732                          - 6.*s1p3k)        
9733                          / dM0111; // to be improved (notation of dM0111)
9734    
9735     // fill profile to get <<4'>>     
9736     fDiffFlowCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1,dM0111);    
9737     // fill profile to get <<4'>^2>     
9738     fDiffFlowSquaredCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1*four1n1n1n1nW0W1W1W1,dM0111);        
9739     // histogram to store <4'> e-b-e (needed in some other methods):
9740     fDiffFlowCorrelationsEBE[t][pe][1]->SetBinContent(b,four1n1n1n1nW0W1W1W1);      
9741     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->SetBinContent(b,dM0111);      
9742    } // end of if(dM0111)
9743  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9744
9745 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta); // type = RP or POI 
9746
9747 //================================================================================================================================
9748
9749 void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
9750 {
9751  // Fill common control histograms.
9752  
9753  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
9754  fCommonHists->FillControlHistograms(anEvent); 
9755  if(fFillMultipleControlHistograms)
9756  {
9757   if(nRP>1)
9758   {
9759    fCommonHists2nd->FillControlHistograms(anEvent);                                        
9760    if(nRP>3)
9761    {
9762     fCommonHists4th->FillControlHistograms(anEvent);                                        
9763     if(nRP>5)
9764     {
9765      fCommonHists6th->FillControlHistograms(anEvent);                                        
9766      if(nRP>7)
9767      {
9768       fCommonHists8th->FillControlHistograms(anEvent);                                        
9769      } // end of if(nRP>7)  
9770     } // end of if(nRP>5) 
9771    } // end of if(nRP>3)                                                                                                                      
9772   } // end of if(nRP>1) 
9773  } // end of if(fFillMultipleControlHistograms)
9774  
9775 } // end of void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
9776
9777 //================================================================================================================================
9778
9779 void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities()
9780 {
9781  // Reset all event by event quantities.
9782  
9783  // integrated flow:
9784  fReQ->Zero();
9785  fImQ->Zero();
9786  fSMpk->Zero();
9787  fIntFlowCorrelationsEBE->Reset();
9788  fIntFlowEventWeightsForCorrelationsEBE->Reset();
9789  fIntFlowCorrelationsAllEBE->Reset();
9790  
9791  for(Int_t sc=0;sc<2;sc++)
9792  {
9793   fIntFlowCorrectionTermsForNUAEBE[sc]->Reset();
9794   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->Reset(); 
9795  }
9796     
9797  // differential flow:
9798  // 1D:
9799  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
9800  {
9801   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
9802   {
9803    for(Int_t m=0;m<4;m++) // multiple of harmonic
9804    {
9805     for(Int_t k=0;k<9;k++) // power of weight
9806     {
9807      if(fReRPQ1dEBE[t][pe][m][k]) fReRPQ1dEBE[t][pe][m][k]->Reset();
9808      if(fImRPQ1dEBE[t][pe][m][k]) fImRPQ1dEBE[t][pe][m][k]->Reset();
9809     }   
9810    }
9811   }
9812  }
9813   
9814  for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
9815  { 
9816   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
9817   {
9818    for(Int_t k=0;k<9;k++)
9819    {
9820     if(fs1dEBE[t][pe][k]) fs1dEBE[t][pe][k]->Reset();
9821    }
9822   }
9823  }
9824
9825  // e-b-e reduced correlations:
9826  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
9827  {  
9828   for(Int_t pe=0;pe<2;pe++) // pt or eta
9829   {
9830    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9831    {
9832     if(fDiffFlowCorrelationsEBE[t][pe][rci]) fDiffFlowCorrelationsEBE[t][pe][rci]->Reset();
9833     if(fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]) fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]->Reset();
9834    }
9835   }
9836  }
9837     
9838  // correction terms for NUA:
9839  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
9840  {  
9841   for(Int_t pe=0;pe<2;pe++) // pt or eta
9842   {
9843    for(Int_t sc=0;sc<2;sc++) // sin or cos
9844    {
9845     for(Int_t cti=0;cti<9;cti++) // correction term index
9846     {
9847      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti]->Reset();  
9848     }
9849    }
9850   }      
9851  }
9852     
9853  // 2D (pt,eta)
9854  if(fCalculate2DFlow)
9855  {
9856   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
9857   {
9858    for(Int_t m=0;m<4;m++) // multiple of harmonic
9859    {
9860     for(Int_t k=0;k<9;k++) // power of weight
9861     {
9862      if(fReRPQ2dEBE[t][m][k]){fReRPQ2dEBE[t][m][k]->Reset();}
9863      if(fImRPQ2dEBE[t][m][k]){fImRPQ2dEBE[t][m][k]->Reset();}
9864     }   
9865    }
9866   }
9867   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
9868   { 
9869    for(Int_t k=0;k<9;k++)
9870    {
9871     if(fs2dEBE[t][k]){fs2dEBE[t][k]->Reset();}
9872    }
9873   }  
9874  } // end of if(fCalculate2DFlow) 
9875
9876 } // end of void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities();
9877
9878
9879 //================================================================================================================================
9880
9881
9882 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
9883 {
9884  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
9885  
9886  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
9887  //  0: <<sin n(psi1)>>
9888  //  1: <<sin n(psi1+phi2)>>
9889  //  2: <<sin n(psi1+phi2-phi3)>>
9890  //  3: <<sin n(psi1-phi2-phi3)>>:
9891  //  4:
9892  //  5:
9893  //  6:
9894  
9895  // multiplicity:
9896  Double_t dMult = (*fSMpk)(0,0);
9897  
9898  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9899  Double_t dReQ1n = (*fReQ)(0,0);
9900  Double_t dReQ2n = (*fReQ)(1,0);
9901  //Double_t dReQ3n = (*fReQ)(2,0);
9902  //Double_t dReQ4n = (*fReQ)(3,0);
9903  Double_t dImQ1n = (*fImQ)(0,0);
9904  Double_t dImQ2n = (*fImQ)(1,0);
9905  //Double_t dImQ3n = (*fImQ)(2,0);
9906  //Double_t dImQ4n = (*fImQ)(3,0);
9907
9908  Int_t t = 0; // type flag 
9909  Int_t pe = 0; // ptEta flag
9910  
9911  if(type == "RP")
9912  {
9913   t = 0;
9914  } else if(type == "POI")
9915    {
9916     t = 1;
9917    }
9918
9919  if(ptOrEta == "Pt")
9920  {
9921   pe = 0;
9922  } else if(ptOrEta == "Eta")
9923    {
9924     pe = 1;
9925    }
9926     
9927  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9928  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9929  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9930  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9931
9932  // looping over all bins and calculating correction terms: 
9933  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9934  {
9935   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
9936   Double_t p1n0kRe = 0.;
9937   Double_t p1n0kIm = 0.;
9938
9939   // number of POIs in particular pt or eta bin:
9940   Double_t mp = 0.;
9941
9942   // 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):
9943   Double_t q1n0kRe = 0.;
9944   Double_t q1n0kIm = 0.;
9945   Double_t q2n0kRe = 0.;
9946   Double_t q2n0kIm = 0.;
9947
9948   // number of particles which are both RPs and POIs in particular pt or eta bin:
9949   Double_t mq = 0.;
9950    
9951   if(type == "POI")
9952   {
9953    // q_{m*n,0}:
9954    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
9955            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
9956    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
9957            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
9958    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
9959            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
9960    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
9961            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
9962                  
9963    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9964   } 
9965   else if(type == "RP")
9966   {
9967    // q_{m*n,0}:
9968    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
9969            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
9970    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
9971            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
9972    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
9973            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
9974    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
9975            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
9976                  
9977    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
9978   }    
9979   if(type == "POI")
9980   {
9981    // p_{m*n,0}:
9982    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
9983            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
9984    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
9985            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
9986             
9987    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9988     
9989    t = 1; // typeFlag = RP or POI
9990   }
9991   else if(type == "RP")
9992   {
9993    // p_{m*n,0} = q_{m*n,0}:
9994    p1n0kRe = q1n0kRe; 
9995    p1n0kIm = q1n0kIm; 
9996            
9997    mp = mq; 
9998    
9999    t = 0; // typeFlag = RP or POI
10000   }
10001
10002   // <<sin n(psi1)>>:
10003   Double_t sinP1nPsi = 0.;
10004   if(mp)
10005   {
10006    sinP1nPsi = p1n0kIm/mp;
10007    // fill profile for <<sin n(psi1)>>:
10008    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
10009    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
10010    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
10011   } // end of if(mp)   
10012   
10013   // <<sin n(psi1+phi2)>>:
10014   Double_t sinP1nPsiP1nPhi = 0.;
10015   if(mp*dMult-mq)
10016   {
10017    sinP1nPsiP1nPhi = (p1n0kRe*dImQ1n+p1n0kIm*dReQ1n-q2n0kIm)/(mp*dMult-mq);
10018    // fill profile for <<sin n(psi1+phi2)>>:
10019    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhi,mp*dMult-mq);
10020    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10021    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhi);
10022   } // end of if(mp*dMult-mq)   
10023   
10024   // <<sin n(psi1+phi2-phi3)>>:
10025   Double_t sinP1nPsi1P1nPhi2MPhi3 = 0.;
10026   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10027   {
10028    sinP1nPsi1P1nPhi2MPhi3 = (p1n0kIm*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
10029                           - 1.*(q2n0kIm*dReQ1n-q2n0kRe*dImQ1n)  
10030                           - mq*dImQ1n+2.*q1n0kIm)
10031                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10032    // fill profile for <<sin n(psi1+phi2)>>:
10033    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10034    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10035    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3);
10036   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10037   
10038   // <<sin n(psi1-phi2-phi3)>>:
10039   Double_t sinP1nPsi1M1nPhi2MPhi3 = 0.;
10040   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10041   {
10042    sinP1nPsi1M1nPhi2MPhi3 = (p1n0kIm*(pow(dReQ1n,2.)-pow(dImQ1n,2.))-2.*p1n0kRe*dReQ1n*dImQ1n
10043                           - 1.*(p1n0kIm*dReQ2n-p1n0kRe*dImQ2n)
10044                           + 2.*mq*dImQ1n-2.*q1n0kIm)
10045                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10046    // fill profile for <<sin n(psi1+phi2)>>:
10047    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10048    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10049    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3);
10050   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10051  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10052  
10053 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
10054
10055
10056 //================================================================================================================================
10057
10058
10059 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
10060 {
10061  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms).
10062  
10063  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
10064  //  0: <<cos n(psi)>>
10065  //  1: <<cos n(psi1+phi2)>>
10066  //  2: <<cos n(psi1+phi2-phi3)>>
10067  //  3: <<cos n(psi1-phi2-phi3)>>
10068  //  4:
10069  //  5:
10070  //  6:
10071  
10072  // multiplicity:
10073  Double_t dMult = (*fSMpk)(0,0);
10074  
10075  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10076  Double_t dReQ1n = (*fReQ)(0,0);
10077  Double_t dReQ2n = (*fReQ)(1,0);
10078  //Double_t dReQ3n = (*fReQ)(2,0);
10079  //Double_t dReQ4n = (*fReQ)(3,0);
10080  Double_t dImQ1n = (*fImQ)(0,0);
10081  Double_t dImQ2n = (*fImQ)(1,0);
10082  //Double_t dImQ3n = (*fImQ)(2,0);
10083  //Double_t dImQ4n = (*fImQ)(3,0);
10084
10085  Int_t t = 0; // type flag 
10086  Int_t pe = 0; // ptEta flag
10087  
10088  if(type == "RP")
10089  {
10090   t = 0;
10091  } else if(type == "POI")
10092    {
10093     t = 1;
10094    }
10095
10096  if(ptOrEta == "Pt")
10097  {
10098   pe = 0;
10099  } else if(ptOrEta == "Eta")
10100    {
10101     pe = 1;
10102    }
10103     
10104  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10105  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10106  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10107  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10108
10109  // looping over all bins and calculating correction terms: 
10110  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10111  {
10112   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
10113   Double_t p1n0kRe = 0.;
10114   Double_t p1n0kIm = 0.;
10115
10116   // number of POIs in particular pt or eta bin:
10117   Double_t mp = 0.;
10118
10119   // 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):
10120   Double_t q1n0kRe = 0.;
10121   Double_t q1n0kIm = 0.;
10122   Double_t q2n0kRe = 0.;
10123   Double_t q2n0kIm = 0.;
10124
10125   // number of particles which are both RPs and POIs in particular pt or eta bin:
10126   Double_t mq = 0.;
10127    
10128   if(type == "POI")
10129   {
10130    // q_{m*n,0}:
10131    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
10132            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
10133    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
10134            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
10135    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
10136            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
10137    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
10138            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
10139                  
10140    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10141   } 
10142   else if(type == "RP")
10143   {
10144    // q_{m*n,0}:
10145    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10146            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10147    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
10148            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10149    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
10150            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
10151    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
10152            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
10153                  
10154    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
10155   }    
10156   if(type == "POI")
10157   {
10158    // p_{m*n,0}:
10159    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10160            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10161    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10162            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10163             
10164    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10165     
10166    t = 1; // typeFlag = RP or POI
10167   }
10168   else if(type == "RP")
10169   {
10170    // p_{m*n,0} = q_{m*n,0}:
10171    p1n0kRe = q1n0kRe; 
10172    p1n0kIm = q1n0kIm; 
10173            
10174    mp = mq; 
10175    
10176    t = 0; // typeFlag = RP or POI
10177   }
10178
10179   // <<cos n(psi1)>>:
10180   Double_t cosP1nPsi = 0.;
10181   if(mp)
10182   {
10183    cosP1nPsi = p1n0kRe/mp;
10184    
10185    // fill profile for <<cos n(psi1)>>:
10186    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
10187    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
10188    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
10189   } // end of if(mp)   
10190   
10191   // <<cos n(psi1+phi2)>>:
10192   Double_t cosP1nPsiP1nPhi = 0.;
10193   if(mp*dMult-mq)
10194   {
10195    cosP1nPsiP1nPhi = (p1n0kRe*dReQ1n-p1n0kIm*dImQ1n-q2n0kRe)/(mp*dMult-mq);
10196    // fill profile for <<sin n(psi1+phi2)>>:
10197    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhi,mp*dMult-mq);
10198    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10199    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhi);
10200   } // end of if(mp*dMult-mq)   
10201   
10202   // <<cos n(psi1+phi2-phi3)>>:
10203   Double_t cosP1nPsi1P1nPhi2MPhi3 = 0.;
10204   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10205   {
10206    cosP1nPsi1P1nPhi2MPhi3 = (p1n0kRe*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
10207                           - 1.*(q2n0kRe*dReQ1n+q2n0kIm*dImQ1n)  
10208                           - mq*dReQ1n+2.*q1n0kRe)
10209                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10210    // fill profile for <<sin n(psi1+phi2)>>:
10211    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10212    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10213    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3);
10214   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10215   
10216   // <<cos n(psi1-phi2-phi3)>>:
10217   Double_t cosP1nPsi1M1nPhi2MPhi3 = 0.;
10218   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10219   {
10220    cosP1nPsi1M1nPhi2MPhi3 = (p1n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))+2.*p1n0kIm*dReQ1n*dImQ1n
10221                           - 1.*(p1n0kRe*dReQ2n+p1n0kIm*dImQ2n)  
10222                           - 2.*mq*dReQ1n+2.*q1n0kRe)
10223                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10224    // fill profile for <<sin n(psi1+phi2)>>:
10225    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10226    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10227    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3);
10228   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10229  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10230  
10231 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
10232
10233
10234 //==================================================================================================================================
10235
10236
10237 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
10238 {
10239  // Transfer prolfiles into histogams and correctly propagate the error (to be improved: description)
10240  
10241  // to be improved: debugged - I do not correctly transfer all profiles into histos (bug appears only after merging) 
10242   
10243  Int_t t = 0; // type flag 
10244  Int_t pe = 0; // ptEta flag
10245  
10246  if(type == "RP")
10247  {
10248   t = 0;
10249  } else if(type == "POI")
10250    {
10251     t = 1;
10252    }
10253
10254  if(ptOrEta == "Pt")
10255  {
10256   pe = 0;
10257  } else if(ptOrEta == "Eta")
10258    {
10259     pe = 1;
10260    }
10261     
10262  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10263  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
10264  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10265  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10266
10267  for(Int_t sc=0;sc<2;sc++) // sin or cos
10268  {
10269   for(Int_t cti=0;cti<9;cti++) // correction term index
10270   {
10271    for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10272    {
10273     Double_t correctionTerm = fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(b);
10274     fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]->SetBinContent(b,correctionTerm);
10275     // to be improved (propagate error correctly)
10276     // ...
10277    } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10278   } // correction term index
10279  } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
10280
10281 }// end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
10282
10283
10284 //==================================================================================================================================
10285
10286
10287 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
10288
10289  // Calculate generalized differential flow Q-cumulants (corrected for non-uniform acceptance)
10290   
10291  Int_t typeFlag = 0;
10292  Int_t ptEtaFlag = 0;
10293
10294  if(type == "RP")
10295  {
10296   typeFlag = 0;
10297  } else if(type == "POI")
10298    {
10299     typeFlag = 1;
10300    } 
10301      
10302  if(ptOrEta == "Pt")
10303  {
10304   ptEtaFlag = 0;
10305  } else if(ptOrEta == "Eta")
10306    {
10307     ptEtaFlag = 1;
10308    } 
10309   
10310  // shortcuts:
10311  Int_t t = typeFlag;
10312  Int_t pe = ptEtaFlag;
10313      
10314  // common:
10315  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10316  
10317  // 2-particle correlation:
10318  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
10319  // sin term coming from integrated flow: 
10320  Double_t sinP1nPhi = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
10321  Double_t sinP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
10322  Double_t sinP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
10323  // cos term coming from integrated flow: 
10324  Double_t cosP1nPhi = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
10325  Double_t cosP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
10326  Double_t cosP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
10327
10328  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10329  {
10330   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
10331   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
10332   Double_t sinP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][0]->GetBinContent(b); // <<sin n(Psi)>> 
10333   Double_t cosP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][0]->GetBinContent(b); // <<cos n(Psi)>> 
10334   Double_t sinP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][1]->GetBinContent(b); // <<sin n(psi1+phi2)>> 
10335   Double_t cosP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][1]->GetBinContent(b); // <<cos n(psi1+phi2)>> 
10336   Double_t sinP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][2]->GetBinContent(b); // <<sin n(psi1+phi2-phi3)>> 
10337   Double_t cosP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][2]->GetBinContent(b); // <<cos n(psi1+phi2-phi3)>> 
10338   Double_t sinP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][3]->GetBinContent(b); // <<sin n(psi1-phi2-phi3)>> 
10339   Double_t cosP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][3]->GetBinContent(b); // <<cos n(psi1-phi2-phi3)>> 
10340   // generalized QC{2'}:
10341   Double_t qc2Prime = twoPrime - sinP1nPsi*sinP1nPhi - cosP1nPsi*cosP1nPhi;
10342   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime);
10343   // generalized QC{4'}:
10344   Double_t qc4Prime = fourPrime-2.*twoPrime*two
10345                     - cosP1nPsi*cosP1nPhi1M1nPhi2M1nPhi3
10346                     + sinP1nPsi*sinP1nPhi1M1nPhi2M1nPhi3
10347                     - cosP1nPhi*cosP1nPsi1M1nPhi2M1nPhi3
10348                     + sinP1nPhi*sinP1nPsi1M1nPhi2M1nPhi3
10349                     - 2.*cosP1nPhi*cosP1nPsi1P1nPhi2M1nPhi3
10350                     - 2.*sinP1nPhi*sinP1nPsi1P1nPhi2M1nPhi3
10351                     - cosP1nPsi1P1nPhi2*cosP1nPhi1P1nPhi2
10352                     - sinP1nPsi1P1nPhi2*sinP1nPhi1P1nPhi2
10353                     + 2.*cosP1nPhi1P1nPhi2*(cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
10354                     + 2.*sinP1nPhi1P1nPhi2*(cosP1nPsi*sinP1nPhi+sinP1nPsi*cosP1nPhi)
10355                     + 4.*two*(cosP1nPsi*cosP1nPhi+sinP1nPsi*sinP1nPhi)
10356                     + 2.*cosP1nPsi1P1nPhi2*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.))
10357                     + 4.*sinP1nPsi1P1nPhi2*cosP1nPhi*sinP1nPhi
10358                     + 4.*twoPrime*(pow(cosP1nPhi,2.)+pow(sinP1nPhi,2.))
10359                     - 6.*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.)) 
10360                     * (cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
10361                     - 12.*cosP1nPhi*sinP1nPhi
10362                     * (sinP1nPsi*cosP1nPhi+cosP1nPsi*sinP1nPhi);
10363   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime);   
10364  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
10365  
10366 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
10367
10368
10369 //==================================================================================================================================
10370     
10371
10372 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
10373 {
10374  // Calculate differential flow corrected for non-uniform acceptance.
10375  
10376  // to be improved (rewritten completely)
10377  
10378  Int_t typeFlag = 0;
10379  Int_t ptEtaFlag = 0;
10380
10381  if(type == "RP")
10382  {
10383   typeFlag = 0;
10384  } else if(type == "POI")
10385    {
10386     typeFlag = 1;
10387    } 
10388      
10389  if(ptOrEta == "Pt")
10390  {
10391   ptEtaFlag = 0;
10392  } else if(ptOrEta == "Eta")
10393    {
10394     ptEtaFlag = 1;
10395    } 
10396   
10397  // shortcuts:
10398  Int_t t = typeFlag;
10399  Int_t pe = ptEtaFlag;
10400      
10401  // common:
10402  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10403    
10404  // to be improved: access here generalized QC{2} and QC{4} instead: 
10405  Double_t dV2 = fIntFlow->GetBinContent(1); 
10406  Double_t dV4 = fIntFlow->GetBinContent(2); 
10407  
10408  // loop over pt or eta bins:
10409  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10410  {
10411   // generalized QC{2'}:
10412   Double_t gQC2Prime = fDiffFlowCumulants[t][pe][0]->GetBinContent(b);
10413   // v'{2}:
10414   if(dV2>0)
10415   { 
10416    Double_t v2Prime = gQC2Prime/dV2;
10417    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
10418   }  
10419   // generalized QC{4'}:
10420   Double_t gQC4Prime = fDiffFlowCumulants[t][pe][1]->GetBinContent(b);
10421   // v'{4}:
10422   if(dV4>0)
10423   { 
10424    Double_t v4Prime = -gQC4Prime/pow(dV4,3.);
10425    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime); 
10426   }  
10427  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
10428   
10429 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta); 
10430
10431
10432 //==================================================================================================================================
10433
10434
10435 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent)
10436 {
10437  // Evaluate with nested loops multiparticle correlations for integrated flow (without using the particle weights). 
10438
10439  // Remark: Results are stored in profile fIntFlowDirectCorrelations whose binning is organized as follows:
10440  // 
10441  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
10442  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
10443  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
10444  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
10445  //  5th bin:           ----  EMPTY ----
10446  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
10447  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
10448  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
10449  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
10450  // 10th bin:           ----  EMPTY ----
10451  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
10452  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
10453  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
10454  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
10455  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
10456  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
10457  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
10458  // 18th bin:           ----  EMPTY ----
10459  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
10460  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
10461  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
10462  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
10463  // 23rd bin:           ----  EMPTY ----
10464  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
10465  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
10466  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
10467  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
10468  // 28th bin:           ----  EMPTY ----
10469  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
10470  // 30th bin:           ----  EMPTY ----
10471  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
10472  // 32nd bin:           ----  EMPTY ----
10473  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
10474  // 34th bin: <5>_{2n,2n,2n|3n,3n} = five2n2n2n3n3n = <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))> 
10475   
10476  Int_t nPrim = anEvent->NumberOfTracks(); 
10477  AliFlowTrackSimple *aftsTrack = NULL; 
10478  Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.; 
10479  Int_t n = fHarmonic; 
10480  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
10481  Double_t dMult = (*fSMpk)(0,0);
10482  cout<<endl;
10483  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
10484  if(dMult<2)
10485  {
10486   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
10487  } else if (dMult>fMaxAllowedMultiplicity)
10488    {
10489     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
10490    } else 
10491      { 
10492       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
10493      } 
10494  
10495  // 2-particle correlations:       
10496  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10497  {
10498   for(Int_t i1=0;i1<nPrim;i1++)
10499   {
10500    aftsTrack=anEvent->GetTrack(i1);
10501    if(!(aftsTrack->InRPSelection())) continue;
10502    phi1=aftsTrack->Phi(); 
10503    for(Int_t i2=0;i2<nPrim;i2++)
10504    {
10505     if(i2==i1)continue;
10506     aftsTrack=anEvent->GetTrack(i2);
10507     if(!(aftsTrack->InRPSelection())) continue;
10508     phi2=aftsTrack->Phi();
10509     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10510     // fill the profile with 2-p correlations: 
10511     fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),1.);    // <cos(n*(phi1-phi2))>
10512     fIntFlowDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),1.); // <cos(2n*(phi1-phi2))>
10513     fIntFlowDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),1.); // <cos(3n*(phi1-phi2))>
10514     fIntFlowDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),1.); // <cos(4n*(phi1-phi2))>   
10515    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10516   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10517  } // end of if(nPrim>=2)
10518  
10519  // 3-particle correlations:         
10520  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10521  {
10522   for(Int_t i1=0;i1<nPrim;i1++)
10523   {
10524    aftsTrack=anEvent->GetTrack(i1);
10525    if(!(aftsTrack->InRPSelection())) continue;
10526    phi1=aftsTrack->Phi();
10527    for(Int_t i2=0;i2<nPrim;i2++)
10528    {
10529     if(i2==i1)continue;
10530     aftsTrack=anEvent->GetTrack(i2);
10531     if(!(aftsTrack->InRPSelection())) continue;
10532     phi2=aftsTrack->Phi();
10533     for(Int_t i3=0;i3<nPrim;i3++)
10534     {
10535      if(i3==i1||i3==i2)continue;
10536      aftsTrack=anEvent->GetTrack(i3);
10537      if(!(aftsTrack->InRPSelection())) continue;
10538      phi3=aftsTrack->Phi();
10539      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
10540      // fill the profile with 3-p correlations:   
10541      fIntFlowDirectCorrelations->Fill(5.,cos(2.*n*phi1-n*(phi2+phi3)),1.);       //<3>_{2n|nn,n}
10542      fIntFlowDirectCorrelations->Fill(6.,cos(3.*n*phi1-2.*n*phi2-n*phi3),1.);    //<3>_{3n|2n,n}
10543      fIntFlowDirectCorrelations->Fill(7.,cos(4.*n*phi1-2.*n*phi2-2.*n*phi3),1.); //<3>_{4n|2n,2n}
10544      fIntFlowDirectCorrelations->Fill(8.,cos(4.*n*phi1-3.*n*phi2-n*phi3),1.);    //<3>_{4n|3n,n}
10545     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10546    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10547   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10548  } // end of if(nPrim>=3)
10549
10550  // 4-particle correlations:
10551  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
10552  {       
10553   for(Int_t i1=0;i1<nPrim;i1++)
10554   { 
10555    aftsTrack=anEvent->GetTrack(i1);
10556    if(!(aftsTrack->InRPSelection())) continue;
10557    phi1=aftsTrack->Phi();
10558    for(Int_t i2=0;i2<nPrim;i2++)
10559    {
10560     if(i2==i1)continue;
10561     aftsTrack=anEvent->GetTrack(i2);
10562     if(!(aftsTrack->InRPSelection())) continue;
10563     phi2=aftsTrack->Phi();
10564     for(Int_t i3=0;i3<nPrim;i3++)
10565     {
10566      if(i3==i1||i3==i2)continue;
10567      aftsTrack=anEvent->GetTrack(i3);
10568      if(!(aftsTrack->InRPSelection())) continue;
10569      phi3=aftsTrack->Phi();
10570      for(Int_t i4=0;i4<nPrim;i4++)
10571      {
10572       if(i4==i1||i4==i2||i4==i3)continue;
10573       aftsTrack=anEvent->GetTrack(i4);
10574       if(!(aftsTrack->InRPSelection())) continue;
10575       phi4=aftsTrack->Phi();
10576       if(nPrim==4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush;
10577       // fill the profile with 4-p correlations:   
10578       fIntFlowDirectCorrelations->Fill(10.,cos(n*phi1+n*phi2-n*phi3-n*phi4),1.);            // <4>_{n,n|n,n} 
10579       fIntFlowDirectCorrelations->Fill(11.,cos(2.*n*phi1+n*phi2-2.*n*phi3-n*phi4),1.);      // <4>_{2n,n|2n,n}
10580       fIntFlowDirectCorrelations->Fill(12.,cos(2.*n*phi1+2*n*phi2-2.*n*phi3-2.*n*phi4),1.); // <4>_{2n,2n|2n,2n}
10581       fIntFlowDirectCorrelations->Fill(13.,cos(3.*n*phi1-n*phi2-n*phi3-n*phi4),1.);         // <4>_{3n|n,n,n}
10582       fIntFlowDirectCorrelations->Fill(14.,cos(3.*n*phi1+n*phi2-3.*n*phi3-n*phi4),1.);      // <4>_{3n,n|3n,n}   
10583       fIntFlowDirectCorrelations->Fill(15.,cos(3.*n*phi1+n*phi2-2.*n*phi3-2.*n*phi4),1.);   // <4>_{3n,n|2n,2n}
10584       fIntFlowDirectCorrelations->Fill(16.,cos(4.*n*phi1-2.*n*phi2-n*phi3-n*phi4),1.);      // <4>_{4n|2n,n,n}     
10585       fIntFlowDirectCorrelations->Fill(32.,cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{4n,2n|3n,3n}      
10586      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
10587     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10588    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10589   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10590  } // end of if(nPrim>=)
10591
10592  // 5-particle correlations:      
10593  if(nPrim>=5 && nPrim<=fMaxAllowedMultiplicity)
10594  {
10595   for(Int_t i1=0;i1<nPrim;i1++)
10596   {
10597    aftsTrack=anEvent->GetTrack(i1);
10598    if(!(aftsTrack->InRPSelection())) continue;  
10599    phi1=aftsTrack->Phi();
10600    for(Int_t i2=0;i2<nPrim;i2++)
10601    {
10602     if(i2==i1)continue;
10603     aftsTrack=anEvent->GetTrack(i2);
10604     if(!(aftsTrack->InRPSelection())) continue;
10605     phi2=aftsTrack->Phi();
10606     for(Int_t i3=0;i3<nPrim;i3++)
10607     {
10608      if(i3==i1||i3==i2)continue;
10609      aftsTrack=anEvent->GetTrack(i3);
10610      if(!(aftsTrack->InRPSelection())) continue;
10611      phi3=aftsTrack->Phi();
10612      for(Int_t i4=0;i4<nPrim;i4++)
10613      {
10614       if(i4==i1||i4==i2||i4==i3)continue;
10615       aftsTrack=anEvent->GetTrack(i4);
10616       if(!(aftsTrack->InRPSelection())) continue;
10617       phi4=aftsTrack->Phi();
10618       for(Int_t i5=0;i5<nPrim;i5++)
10619       {
10620        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10621        aftsTrack=anEvent->GetTrack(i5);
10622        if(!(aftsTrack->InRPSelection())) continue;
10623        phi5=aftsTrack->Phi();
10624        if(nPrim==5) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<"\r"<<flush;
10625        // fill the profile with 5-p correlations:   
10626        fIntFlowDirectCorrelations->Fill(18.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{2n,n|n,n,n}
10627        fIntFlowDirectCorrelations->Fill(19.,cos(2.*n*phi1+2.*n*phi2-2.*n*phi3-n*phi4-n*phi5),1.); //<5>_{2n,2n|2n,n,n}
10628        fIntFlowDirectCorrelations->Fill(20.,cos(3.*n*phi1+n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);    //<5>_{3n,n|2n,n,n}
10629        fIntFlowDirectCorrelations->Fill(21.,cos(4.*n*phi1-n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{4n|n,n,n,n}
10630        fIntFlowDirectCorrelations->Fill(33.,cos(2.*n*phi1+2.*n*phi2+2.*n*phi3-3.*n*phi4-3.*n*phi5),1.);       
10631       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10632      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10633     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10634    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10635   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10636  } // end of if(nPrim>=5)
10637   
10638  // 6-particle correlations:
10639  if(nPrim>=6 && nPrim<=fMaxAllowedMultiplicity)
10640  {
10641   for(Int_t i1=0;i1<nPrim;i1++)
10642   {
10643    aftsTrack=anEvent->GetTrack(i1);
10644    if(!(aftsTrack->InRPSelection())) continue;
10645    phi1=aftsTrack->Phi();
10646    for(Int_t i2=0;i2<nPrim;i2++)
10647    {
10648     if(i2==i1)continue;
10649     aftsTrack=anEvent->GetTrack(i2);
10650     if(!(aftsTrack->InRPSelection())) continue;
10651     phi2=aftsTrack->Phi();
10652     for(Int_t i3=0;i3<nPrim;i3++)
10653     {
10654      if(i3==i1||i3==i2)continue;
10655      aftsTrack=anEvent->GetTrack(i3);
10656      if(!(aftsTrack->InRPSelection())) continue;
10657      phi3=aftsTrack->Phi();
10658      for(Int_t i4=0;i4<nPrim;i4++)
10659      {
10660       if(i4==i1||i4==i2||i4==i3)continue;
10661       aftsTrack=anEvent->GetTrack(i4);
10662       if(!(aftsTrack->InRPSelection())) continue;
10663       phi4=aftsTrack->Phi();
10664       for(Int_t i5=0;i5<nPrim;i5++)
10665       {
10666        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10667        aftsTrack=anEvent->GetTrack(i5);
10668        if(!(aftsTrack->InRPSelection())) continue;
10669        phi5=aftsTrack->Phi();
10670        for(Int_t i6=0;i6<nPrim;i6++)
10671        {
10672         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10673         aftsTrack=anEvent->GetTrack(i6);
10674         if(!(aftsTrack->InRPSelection())) continue;
10675         phi6=aftsTrack->Phi(); 
10676         if(nPrim==6) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<"\r"<<flush;
10677         // fill the profile with 6-p correlations:   
10678         fIntFlowDirectCorrelations->Fill(23.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),1.);       //<6>_{n,n,n|n,n,n}
10679         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}
10680         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}
10681         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}  
10682        } // end of for(Int_t i6=0;i6<nPrim;i6++)
10683       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10684      } // end of for(Int_t i4=0;i4<nPrim;i4++)
10685     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10686    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10687   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10688  } // end of if(nPrim>=6)
10689   
10690  // 7-particle correlations:
10691  if(nPrim>=7 && nPrim<=fMaxAllowedMultiplicity)
10692  {
10693   for(Int_t i1=0;i1<nPrim;i1++)
10694   { 
10695    aftsTrack=anEvent->GetTrack(i1);
10696    if(!(aftsTrack->InRPSelection())) continue;
10697    phi1=aftsTrack->Phi();
10698    for(Int_t i2=0;i2<nPrim;i2++)
10699    {
10700     if(i2==i1)continue;
10701     aftsTrack=anEvent->GetTrack(i2);
10702     if(!(aftsTrack->InRPSelection())) continue;
10703     phi2=aftsTrack->Phi();
10704     for(Int_t i3=0;i3<nPrim;i3++)
10705     {
10706      if(i3==i1||i3==i2)continue;
10707      aftsTrack=anEvent->GetTrack(i3);
10708      if(!(aftsTrack->InRPSelection())) continue;
10709      phi3=aftsTrack->Phi();
10710      for(Int_t i4=0;i4<nPrim;i4++)
10711      {
10712       if(i4==i1||i4==i2||i4==i3)continue;
10713       aftsTrack=anEvent->GetTrack(i4);
10714       if(!(aftsTrack->InRPSelection())) continue;
10715       phi4=aftsTrack->Phi();
10716       for(Int_t i5=0;i5<nPrim;i5++)
10717       {
10718        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10719        aftsTrack=anEvent->GetTrack(i5);
10720        if(!(aftsTrack->InRPSelection())) continue;
10721        phi5=aftsTrack->Phi();
10722        for(Int_t i6=0;i6<nPrim;i6++)
10723        {
10724         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10725         aftsTrack=anEvent->GetTrack(i6);
10726         if(!(aftsTrack->InRPSelection())) continue;
10727         phi6=aftsTrack->Phi(); 
10728         for(Int_t i7=0;i7<nPrim;i7++)
10729         {
10730          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
10731          aftsTrack=anEvent->GetTrack(i7);
10732          if(!(aftsTrack->InRPSelection())) continue;
10733          phi7=aftsTrack->Phi(); 
10734          if(nPrim==7) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<"\r"<<flush;
10735          // fill the profile with 7-p correlation:   
10736          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}
10737         } // end of for(Int_t i7=0;i7<nPrim;i7++)
10738        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
10739       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10740      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10741     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10742    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10743   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10744  } // end of if(nPrim>=7)
10745  
10746  // 8-particle correlations:
10747  if(nPrim>=8 && nPrim<=fMaxAllowedMultiplicity)
10748  {
10749   for(Int_t i1=0;i1<nPrim;i1++)
10750   {
10751    aftsTrack=anEvent->GetTrack(i1);
10752    if(!(aftsTrack->InRPSelection())) continue;
10753    phi1=aftsTrack->Phi();
10754    for(Int_t i2=0;i2<nPrim;i2++)
10755    {
10756     if(i2==i1)continue;
10757     aftsTrack=anEvent->GetTrack(i2);
10758     if(!(aftsTrack->InRPSelection())) continue;
10759     phi2=aftsTrack->Phi();
10760     for(Int_t i3=0;i3<nPrim;i3++)
10761     {
10762      if(i3==i1||i3==i2)continue;
10763      aftsTrack=anEvent->GetTrack(i3);
10764      if(!(aftsTrack->InRPSelection())) continue;
10765      phi3=aftsTrack->Phi();
10766      for(Int_t i4=0;i4<nPrim;i4++)
10767      {
10768       if(i4==i1||i4==i2||i4==i3)continue;
10769       aftsTrack=anEvent->GetTrack(i4);
10770       if(!(aftsTrack->InRPSelection())) continue;
10771       phi4=aftsTrack->Phi();
10772       for(Int_t i5=0;i5<nPrim;i5++)
10773       {
10774        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10775        aftsTrack=anEvent->GetTrack(i5);
10776        if(!(aftsTrack->InRPSelection())) continue;
10777        phi5=aftsTrack->Phi();
10778        for(Int_t i6=0;i6<nPrim;i6++)
10779        {
10780         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10781         aftsTrack=anEvent->GetTrack(i6);
10782         if(!(aftsTrack->InRPSelection())) continue;
10783         phi6=aftsTrack->Phi();
10784         for(Int_t i7=0;i7<nPrim;i7++)
10785         {
10786          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
10787          aftsTrack=anEvent->GetTrack(i7);
10788          if(!(aftsTrack->InRPSelection())) continue;
10789          phi7=aftsTrack->Phi();
10790          for(Int_t i8=0;i8<nPrim;i8++)
10791          {
10792           if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
10793           aftsTrack=anEvent->GetTrack(i8);
10794           if(!(aftsTrack->InRPSelection())) continue;
10795           phi8=aftsTrack->Phi();
10796           cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<" "<<i8<<"\r"<<flush;
10797           // fill the profile with 8-p correlation:   
10798           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}
10799          } // end of for(Int_t i8=0;i8<nPrim;i8++)
10800         } // end of for(Int_t i7=0;i7<nPrim;i7++) 
10801        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
10802       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10803      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10804     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10805    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10806   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10807  } // end of if(nPrim>=8)
10808  
10809  cout<<endl;
10810
10811 } // end of AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent)
10812
10813
10814 //==================================================================================================================================
10815
10816
10817 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
10818 {
10819  // Cross-check results for multiparticle correlations needed for int. flow: results from Q-vectors vs results from nested loops.
10820
10821  cout<<endl;
10822  cout<<endl;
10823  cout<<"   *****************************************"<<endl;
10824  cout<<"   **** cross-checking the correlations ****"<<endl;
10825  cout<<"   ****       for integrated flow       ****"<<endl;
10826  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
10827  {
10828   cout<<"   ****   (particle weights not used)   ****"<<endl;
10829  } else
10830    {
10831     cout<<"   ****     (particle weights used)     ****"<<endl;
10832    } 
10833  cout<<"   *****************************************"<<endl;
10834  cout<<endl;
10835  cout<<endl;
10836
10837  Int_t ciMax = 34; // to be improved (removed eventually when I calculate 6th and 8th order with particle weights)
10838  
10839  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
10840  {
10841   ciMax = 11;
10842  }
10843
10844  for(Int_t ci=1;ci<=ciMax;ci++)
10845  {
10846   if(strcmp((fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
10847   cout<<(fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
10848   cout<<"from Q-vectors    = "<<fIntFlowCorrelationsAllPro->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
10849   cout<<"from nested loops = "<<fIntFlowDirectCorrelations->GetBinContent(ci)<<endl;
10850   cout<<endl;
10851  }
10852   
10853 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
10854
10855
10856 //================================================================================================================================
10857
10858
10859 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA()
10860 {
10861  // Cross-check results for corrections terms for non-uniform acceptance needed for int. flow: results from Q-vectors vs results from nested loops.
10862
10863  cout<<endl;
10864  cout<<endl;
10865  cout<<"   *********************************************"<<endl;
10866  cout<<"   **** cross-checking the correction terms ****"<<endl;
10867  cout<<"   **** for non-uniform acceptance relevant ****"<<endl;
10868  cout<<"   ****         for integrated flow         ****"<<endl;
10869  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
10870  {
10871   cout<<"   ****     (particle weights not used)     ****"<<endl;
10872  } else
10873    {
10874     cout<<"   ****       (particle weights used)       ****"<<endl;
10875    } 
10876  cout<<"   *********************************************"<<endl;
10877  cout<<endl;
10878  cout<<endl;
10879
10880  for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
10881  {
10882   for(Int_t sc=0;sc<2;sc++) // sin or cos term
10883   {
10884    if(strcmp((fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
10885    cout<<(fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
10886    cout<<"from Q-vectors    = "<<fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
10887    cout<<"from nested loops = "<<fIntFlowDirectCorrectionTermsForNUA[sc]->GetBinContent(ci)<<endl;
10888    cout<<endl;
10889   } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos term
10890  } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
10891   
10892 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA() 
10893
10894
10895 //================================================================================================================================
10896
10897
10898 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
10899 {
10900  // Evaluate with nested loops multiparticle correlations for integrated flow (using the particle weights). 
10901
10902  // Results are stored in profile fIntFlowDirectCorrelations. 
10903  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrelations is organized as follows:
10904  //
10905  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
10906  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
10907  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
10908  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
10909  //  5th bin:           ----  EMPTY ----
10910  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
10911  //  7th bin: <3>_{3n|2n,1n} = ...
10912  //  8th bin: <3>_{4n|2n,2n} = ...
10913  //  9th bin: <3>_{4n|3n,1n} = ...
10914  // 10th bin:           ----  EMPTY ----
10915  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
10916  // 12th bin: <4>_{2n,1n|2n,1n} = ...
10917  // 13th bin: <4>_{2n,2n|2n,2n} = ...
10918  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
10919  // 15th bin: <4>_{3n,1n|3n,1n} = ...
10920  // 16th bin: <4>_{3n,1n|2n,2n} = ...
10921  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
10922  // 18th bin:           ----  EMPTY ----
10923  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
10924  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
10925  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
10926  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
10927  // 23rd bin:           ----  EMPTY ----
10928  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
10929  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
10930  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
10931  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
10932  // 28th bin:           ----  EMPTY ----
10933  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
10934  // 30th bin:           ----  EMPTY ----
10935  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
10936  
10937  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
10938  // fIntFlowExtraDirectCorrelations binning of which is organized as follows:
10939  
10940  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
10941  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
10942  // ...
10943  
10944  Int_t nPrim = anEvent->NumberOfTracks(); 
10945  AliFlowTrackSimple *aftsTrack = NULL;
10946  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
10947  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
10948  Double_t phi1=0., phi2=0., phi3=0., phi4=0.;
10949  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1.;
10950  Int_t n = fHarmonic; 
10951  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
10952  Double_t dMult = (*fSMpk)(0,0);
10953  cout<<endl;
10954  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
10955  if(dMult<2)
10956  {
10957   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
10958  } else if (dMult>fMaxAllowedMultiplicity)
10959    {
10960     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
10961    } else 
10962      { 
10963       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
10964      } 
10965       
10966  // 2-particle correlations:       
10967  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10968  {
10969   // 2 nested loops multiparticle correlations using particle weights:       
10970   for(Int_t i1=0;i1<nPrim;i1++)
10971   {
10972    aftsTrack=anEvent->GetTrack(i1);
10973    if(!(aftsTrack->InRPSelection())) continue;
10974    phi1=aftsTrack->Phi();
10975    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10976    for(Int_t i2=0;i2<nPrim;i2++)
10977    {
10978     if(i2==i1)continue;
10979     aftsTrack=anEvent->GetTrack(i2);
10980     if(!(aftsTrack->InRPSelection())) continue;
10981     phi2=aftsTrack->Phi();
10982     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
10983     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10984     // 2-p correlations using particle weights:
10985     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),wPhi1*wPhi2);                  // <w1   w2   cos( n*(phi1-phi2))>
10986     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))>
10987     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))>
10988     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))> 
10989     // extra correlations: 
10990     // 2-p extra correlations (do not appear if particle weights are not used):
10991     if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),pow(wPhi1,3)*wPhi2); // <w1^3 w2 cos(n*(phi1-phi2))>
10992     // ...
10993    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10994   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10995  } // end of if(nPrim>=2)
10996
10997  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10998  { 
10999   // 3 nested loops multiparticle correlations using particle weights:       
11000   for(Int_t i1=0;i1<nPrim;i1++)
11001   {
11002    aftsTrack=anEvent->GetTrack(i1);
11003    if(!(aftsTrack->InRPSelection())) continue;
11004    phi1=aftsTrack->Phi();
11005    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11006    for(Int_t i2=0;i2<nPrim;i2++)
11007    {
11008     if(i2==i1)continue;
11009     aftsTrack=anEvent->GetTrack(i2);
11010     if(!(aftsTrack->InRPSelection())) continue;
11011     phi2=aftsTrack->Phi();
11012     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11013     for(Int_t i3=0;i3<nPrim;i3++)
11014     {
11015      if(i3==i1||i3==i2)continue;
11016      aftsTrack=anEvent->GetTrack(i3);
11017      if(!(aftsTrack->InRPSelection())) continue;
11018      phi3=aftsTrack->Phi();
11019      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11020      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
11021      // 3-p correlations using particle weights:
11022      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))>
11023      // ...
11024      // extra correlations: 
11025      // 2-p extra correlations (do not appear if particle weights are not used):
11026       if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(1.5,cos(n*(phi1-phi2)),wPhi1*wPhi2*pow(wPhi3,2)); // <w1 w2 w3^2 cos(n*(phi1-phi2))>
11027      // ...
11028      // 3-p extra correlations (do not appear if particle weights are not used):
11029      // ...
11030     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11031    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11032   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11033  } // end of if(nPrim>=3)
11034  
11035  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
11036  {
11037   // 4 nested loops multiparticle correlations using particle weights:       
11038   for(Int_t i1=0;i1<nPrim;i1++)
11039   {
11040    aftsTrack=anEvent->GetTrack(i1);
11041    if(!(aftsTrack->InRPSelection())) continue;
11042    phi1=aftsTrack->Phi();
11043    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11044    for(Int_t i2=0;i2<nPrim;i2++)
11045    {
11046     if(i2==i1)continue;
11047     aftsTrack=anEvent->GetTrack(i2);
11048     if(!(aftsTrack->InRPSelection())) continue;
11049     phi2=aftsTrack->Phi();
11050     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11051     for(Int_t i3=0;i3<nPrim;i3++)
11052     {
11053      if(i3==i1||i3==i2)continue;
11054      aftsTrack=anEvent->GetTrack(i3);
11055      if(!(aftsTrack->InRPSelection())) continue;
11056      phi3=aftsTrack->Phi();
11057      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11058      for(Int_t i4=0;i4<nPrim;i4++)
11059      {
11060       if(i4==i1||i4==i2||i4==i3)continue;
11061       aftsTrack=anEvent->GetTrack(i4);
11062       if(!(aftsTrack->InRPSelection())) continue;
11063       phi4=aftsTrack->Phi();
11064       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
11065       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
11066       // 4-p correlations using particle weights:
11067       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
11068       // extra correlations: 
11069       // 2-p extra correlations (do not appear if particle weights are not used):
11070       // ...
11071       // 3-p extra correlations (do not appear if particle weights are not used):
11072       // ...
11073       // 4-p extra correlations (do not appear if particle weights are not used):
11074       // ...
11075      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
11076     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11077    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11078   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11079  } // end of if(nPrim>=4)
11080
11081  cout<<endl; 
11082
11083 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
11084
11085
11086 //================================================================================================================================
11087
11088
11089 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
11090 {
11091  // Cross-check results for extra multiparticle correlations needed for int. flow 
11092  // which appear only when particle weights are used: results from Q-vectors vs results from nested loops.
11093
11094  cout<<endl;
11095  cout<<endl;
11096  cout<<"   ***********************************************"<<endl;
11097  cout<<"   **** cross-checking the extra correlations ****"<<endl;
11098  cout<<"   ****          for integrated flow          ****"<<endl;
11099  cout<<"   ***********************************************"<<endl;
11100  cout<<endl;
11101  cout<<endl;
11102  
11103  for(Int_t eci=1;eci<=2;eci++) // to be improved (increased eciMax eventually when I calculate 6th and 8th)
11104  {
11105   if(strcmp((fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci), "") == 0) continue;
11106   cout<<(fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci)<<":"<<endl;
11107   cout<<"from Q-vectors    = "<<fIntFlowExtraCorrelationsPro->GetBinContent(eci)<<endl;
11108   cout<<"from nested loops = "<<fIntFlowExtraDirectCorrelations->GetBinContent(eci)<<endl;
11109   cout<<endl;
11110  }
11111
11112 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
11113
11114
11115 //================================================================================================================================
11116
11117
11118 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent)
11119 {
11120  // Evaluate with nested loops correction terms for non-uniform acceptance relevant for NONAME integrated flow (to be improved (name)).
11121  //
11122  // Remark: Both sin and cos correction terms are calculated in this method. Sin terms are stored in fIntFlowDirectCorrectionTermsForNUA[0],
11123  // and cos terms in fIntFlowDirectCorrectionTermsForNUA[1]. Binning of fIntFlowDirectCorrectionTermsForNUA[sc] is organized as follows 
11124  // (sc stands for either sin or cos):
11125  
11126  //  1st bin: <<sc(n*(phi1))>> 
11127  //  2nd bin: <<sc(n*(phi1+phi2))>> 
11128  //  3rd bin: <<sc(n*(phi1-phi2-phi3))>>
11129  //  4th bin: <<sc(n*(2phi1-phi2))>>
11130  
11131  Int_t nPrim = anEvent->NumberOfTracks(); 
11132  AliFlowTrackSimple *aftsTrack = NULL;
11133  Double_t phi1=0., phi2=0., phi3=0.;
11134  Int_t n = fHarmonic; 
11135  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
11136  Double_t dMult = (*fSMpk)(0,0);
11137  cout<<endl;
11138  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
11139  if(dMult<1)
11140  {
11141   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
11142  } else if (dMult>fMaxAllowedMultiplicity)
11143    {
11144     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
11145    } else 
11146      { 
11147       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
11148      }
11149  
11150  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
11151  {
11152   // 1-particle correction terms for non-uniform acceptance:       
11153   for(Int_t i1=0;i1<nPrim;i1++)
11154   {
11155    aftsTrack=anEvent->GetTrack(i1);
11156    if(!(aftsTrack->InRPSelection())) continue;
11157    phi1=aftsTrack->Phi();
11158    if(nPrim==1) cout<<i1<<"\r"<<flush;
11159    // sin terms:
11160    fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),1.); // <sin(n*phi1)>  
11161    // cos terms:
11162    fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),1.); // <cos(n*phi1)>
11163   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11164  } // end of if(nPrim>=1) 
11165   
11166  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
11167  {
11168   // 2-particle correction terms for non-uniform acceptance:       
11169   for(Int_t i1=0;i1<nPrim;i1++)
11170   {
11171    aftsTrack=anEvent->GetTrack(i1);
11172    if(!(aftsTrack->InRPSelection())) continue;
11173    phi1=aftsTrack->Phi();  
11174    for(Int_t i2=0;i2<nPrim;i2++)
11175    {
11176     if(i2==i1)continue;
11177     aftsTrack=anEvent->GetTrack(i2);
11178     if(!(aftsTrack->InRPSelection())) continue;
11179     phi2=aftsTrack->Phi();
11180     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
11181     // sin terms:
11182     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),1.); // <<sin(n*(phi1+phi2))>>
11183     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(3.5,sin(n*(2*phi1-phi2)),1.); // <<sin(n*(2*phi1-phi2))>>
11184     // cos terms:
11185     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),1.); // <<cos(n*(phi1+phi2))>>
11186     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(3.5,cos(n*(2*phi1-phi2)),1.); // <<cos(n*(2*phi1-phi2))>>
11187    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11188   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11189  } // end of if(nPrim>=2)
11190
11191  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
11192  {
11193   // 3-particle correction terms for non-uniform acceptance:       
11194   for(Int_t i1=0;i1<nPrim;i1++)
11195   {
11196    aftsTrack=anEvent->GetTrack(i1);
11197    if(!(aftsTrack->InRPSelection())) continue;
11198    phi1=aftsTrack->Phi();
11199    for(Int_t i2=0;i2<nPrim;i2++)
11200    {
11201     if(i2==i1)continue;
11202     aftsTrack=anEvent->GetTrack(i2);
11203     if(!(aftsTrack->InRPSelection())) continue;
11204     phi2=aftsTrack->Phi();
11205     for(Int_t i3=0;i3<nPrim;i3++)
11206     {
11207      if(i3==i1||i3==i2)continue;
11208      aftsTrack=anEvent->GetTrack(i3);
11209      if(!(aftsTrack->InRPSelection())) continue;
11210      phi3=aftsTrack->Phi();
11211      if(nPrim>=3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush; // to be improved (eventually I will change this if statement)
11212      // sin terms:
11213      fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),1.); // <<sin(n*(phi1-phi2-phi3))>>
11214      // cos terms:
11215      fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),1.); // <<cos(n*(phi1-phi2-phi3))>>
11216     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11217    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11218   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11219  } // end of if(nPrim>=3)
11220
11221  cout<<endl;
11222 }
11223 //================================================================================================================================
11224 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11225 {
11226  // Evaluate reduced correlations with nested loops without using the particle weights.
11227  
11228  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11229  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
11230  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
11231  // Remark 3: <2'> = <cos(n*(psi1-phi2))>
11232  //           <4'> = <cos(n*(psi1+phi2-phi3-phi4))>
11233  // ...
11234  
11235  Int_t typeFlag = 0;
11236  Int_t ptEtaFlag = 0;
11237  if(type == "RP")
11238  {
11239   typeFlag = 0;
11240  } else if(type == "POI")
11241    {
11242     typeFlag = 1;
11243    }      
11244  if(ptOrEta == "Pt")
11245  {
11246   ptEtaFlag = 0;
11247  } else if(ptOrEta == "Eta")
11248    {
11249     ptEtaFlag = 1;
11250    } 
11251  // shortcuts:
11252  Int_t t = typeFlag;
11253  Int_t pe = ptEtaFlag;
11254       
11255  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11256  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11257  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11258  
11259  Int_t nPrim = anEvent->NumberOfTracks(); 
11260  AliFlowTrackSimple *aftsTrack = NULL;
11261  
11262  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11263  
11264  Int_t n = fHarmonic; 
11265   
11266  // 2'-particle correlations:
11267  for(Int_t i1=0;i1<nPrim;i1++)
11268  {
11269   aftsTrack=anEvent->GetTrack(i1);
11270   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11271   if(typeFlag==1) // this is diff flow of POIs 
11272   {
11273    if(ptOrEta == "Pt")
11274    { 
11275     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11276    } else if (ptOrEta == "Eta")
11277      {
11278       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11279      }
11280   } else // this is diff flow of RPs 
11281     {
11282      if(ptOrEta == "Pt")
11283      { 
11284       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11285      } else if (ptOrEta == "Eta")
11286        {
11287         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11288        }
11289     }
11290        
11291   psi1=aftsTrack->Phi(); 
11292   for(Int_t i2=0;i2<nPrim;i2++)
11293   {
11294    if(i2==i1)continue;
11295    aftsTrack=anEvent->GetTrack(i2);
11296    // RP condition (!(first) particle in the correlator must be RP):
11297    if(!(aftsTrack->InRPSelection()))continue;
11298    phi2=aftsTrack->Phi();   
11299    // 2'-particle correlations: 
11300    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),1.); // <cos(n*(psi1-phi2))  
11301   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11302  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11303  
11304  /*
11305  
11306  // 3'-particle correlations:
11307  for(Int_t i1=0;i1<nPrim;i1++)
11308  {
11309   aftsTrack=anEvent->GetTrack(i1);
11310   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11311   if(ptOrEta == "Pt")
11312   { 
11313    if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11314   } else if (ptOrEta == "Eta")
11315     {
11316      if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11317     }
11318   psi1=aftsTrack->Phi();
11319   for(Int_t i2=0;i2<nPrim;i2++)
11320   {
11321    if(i2==i1)continue;
11322    aftsTrack=anEvent->GetTrack(i2);
11323    // RP condition (!(first) particle in the correlator must be RP):
11324    if(!(aftsTrack->InRPSelection())) continue;
11325    phi2=aftsTrack->Phi();
11326    for(Int_t i3=0;i3<nPrim;i3++)
11327    {
11328     if(i3==i1||i3==i2)continue;
11329     aftsTrack=anEvent->GetTrack(i3);
11330     // RP condition (!(first) particle in the correlator must be RP):
11331     if(!(aftsTrack->InRPSelection())) continue;
11332     phi3=aftsTrack->Phi();
11333     // 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))> 
11334    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
11335   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
11336  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11337  
11338  */
11339  
11340  // 4'-particle correlations:
11341  for(Int_t i1=0;i1<nPrim;i1++)
11342  {
11343   aftsTrack=anEvent->GetTrack(i1);
11344   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11345   if(typeFlag==1) // this is diff flow of POIs 
11346   {
11347    if(ptOrEta == "Pt")
11348    { 
11349     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11350    } else if (ptOrEta == "Eta")
11351      {
11352       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11353      }
11354   } else // this is diff flow of RPs 
11355     {
11356      if(ptOrEta == "Pt")
11357      { 
11358       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11359      } else if (ptOrEta == "Eta")
11360        {
11361         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11362        }
11363     }
11364     
11365   psi1=aftsTrack->Phi();
11366   for(Int_t i2=0;i2<nPrim;i2++)
11367   {
11368    if(i2==i1) continue;
11369    aftsTrack=anEvent->GetTrack(i2);
11370    // RP condition (!(first) particle in the correlator must be RP): 
11371    if(!(aftsTrack->InRPSelection())) continue;
11372    phi2=aftsTrack->Phi();
11373    for(Int_t i3=0;i3<nPrim;i3++)
11374    { 
11375     if(i3==i1||i3==i2) continue;
11376     aftsTrack=anEvent->GetTrack(i3);
11377     // RP condition (!(first) particle in the correlator must be RP):
11378     if(!(aftsTrack->InRPSelection())) continue;
11379     phi3=aftsTrack->Phi();
11380     for(Int_t i4=0;i4<nPrim;i4++)
11381     {
11382      if(i4==i1||i4==i2||i4==i3) continue;
11383      aftsTrack=anEvent->GetTrack(i4);
11384      // RP condition (!(first) particle in the correlator must be RP):
11385      if(!(aftsTrack->InRPSelection())) continue;  
11386      phi4=aftsTrack->Phi();
11387      // 4'-particle correlations:
11388      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),1.); // <cos(n(psi1+phi2-phi3-phi4))>     
11389     }//end of for(Int_t i4=0;i4<nPrim;i4++)
11390    }//end of for(Int_t i3=0;i3<nPrim;i3++)
11391   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
11392  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11393       
11394  // count # of RPs and POIs in selected pt and eta bins for cross-checkings:
11395  for(Int_t i=0;i<nPrim;i++)
11396  {
11397   aftsTrack=anEvent->GetTrack(i); 
11398   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11399   if(typeFlag==1) // this is diff flow of POIs 
11400   {
11401    if(ptOrEta == "Pt")
11402    { 
11403     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11404    } else if (ptOrEta == "Eta")
11405      {
11406       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11407      }
11408   } else // this is diff flow of RPs 
11409     {
11410      if(ptOrEta == "Pt")
11411      { 
11412       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11413      } else if (ptOrEta == "Eta")
11414        {
11415         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11416        }
11417     }
11418   if(t==1)t++; 
11419   fNoOfParticlesInBin->Fill(t+pe+0.5);  
11420  }
11421
11422 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11423
11424
11425 //================================================================================================================================
11426
11427
11428 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
11429 {
11430  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
11431  
11432  Int_t typeFlag = 0;
11433  Int_t ptEtaFlag = 0;
11434  if(type == "RP")
11435  {
11436   typeFlag = 0;
11437  } else if(type == "POI")
11438    {
11439     typeFlag = 1;
11440    }      
11441  if(ptOrEta == "Pt")
11442  {
11443   ptEtaFlag = 0;
11444  } else if(ptOrEta == "Eta")
11445    {
11446     ptEtaFlag = 1;
11447    } 
11448  // shortcuts:
11449  Int_t t = typeFlag;
11450  Int_t pe = ptEtaFlag;
11451       
11452  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11453  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11454  TString reducedCorrelations[4] = {"<<cos(n(psi1-phi2))>>","<<cos(n(psi1+phi2-phi3-phi4))>>","",""}; // to be improved (access this from pro or hist)
11455  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11456  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11457  
11458  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
11459  
11460
11461  cout<<endl;
11462  cout<<"   *****************************************"<<endl;
11463  cout<<"   **** cross-checking the correlations ****"<<endl;
11464  cout<<"   ****   for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
11465  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
11466  {
11467   cout<<"   ****   (particle weights not used)   ****"<<endl;
11468  } else
11469    {
11470     cout<<"   ****    (particle weights used)      ****"<<endl;
11471    } 
11472  cout<<"   *****************************************"<<endl; 
11473  cout<<endl;
11474  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
11475  cout<<endl;
11476  
11477  for(Int_t rci=0;rci<2;rci++) // to be improved (calculate 6th and 8th order)
11478  {
11479   cout<<"      "<<reducedCorrelations[rci].Data()<<":"<<endl;
11480   cout<<"      from Q-vectors    = "<<fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
11481   cout<<"      from nested loops = "<<fDiffFlowDirectCorrelations[t][pe][rci]->GetBinContent(1)<<endl;
11482   cout<<endl;  
11483  } // end of for(Int_t rci=0;rci<4;rci++)
11484         
11485 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
11486
11487 //================================================================================================================================
11488
11489 void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
11490 {
11491  // Print on the screen number of RPs and POIs in selected pt and eta bin for cross checkings.
11492  
11493  cout<<endl;
11494  cout<<"Number of RPs in selected pt bin   = "<<fNoOfParticlesInBin->GetBinContent(1)<<endl;
11495  cout<<"Number of RPs in selected eta bin  = "<<fNoOfParticlesInBin->GetBinContent(2)<<endl;
11496  cout<<"Number of POIs in selected pt bin  = "<<fNoOfParticlesInBin->GetBinContent(3)<<endl;
11497  cout<<"Number of POIs in selected eta bin = "<<fNoOfParticlesInBin->GetBinContent(4)<<endl;
11498  
11499 } // end of void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
11500
11501 //================================================================================================================================
11502
11503 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11504 {
11505  // Evaluate reduced correlations with nested loops without using the particle weights.
11506  
11507  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11508  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
11509  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
11510  // Remark 3: <2'> = <w2 cos(n*(psi1-phi2))>
11511  //           <4'> = <w2 w3 w4 cos(n*(psi1+phi2-phi3-phi4))>
11512  // ...
11513   
11514  Int_t typeFlag = 0;
11515  Int_t ptEtaFlag = 0;
11516  if(type == "RP")
11517  {
11518   typeFlag = 0;
11519  } else if(type == "POI")
11520    {
11521     typeFlag = 1;
11522    }      
11523  if(ptOrEta == "Pt")
11524  {
11525   ptEtaFlag = 0;
11526  } else if(ptOrEta == "Eta")
11527    {
11528     ptEtaFlag = 1;
11529    } 
11530  // shortcuts:
11531  Int_t t = typeFlag;
11532  Int_t pe = ptEtaFlag;
11533       
11534  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11535  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11536  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11537  
11538  Int_t nPrim = anEvent->NumberOfTracks(); 
11539  AliFlowTrackSimple *aftsTrack = NULL;
11540  
11541  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11542  Double_t wPhi2=1., wPhi3=1., wPhi4=1.;// wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
11543  
11544  Int_t n = fHarmonic; 
11545  
11546  // 2'-particle correlations:
11547  for(Int_t i1=0;i1<nPrim;i1++)
11548  {
11549   aftsTrack=anEvent->GetTrack(i1);
11550   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11551   if(typeFlag==1) // this is diff flow of POIs 
11552   {
11553    if(ptOrEta == "Pt")
11554    { 
11555     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11556    } else if (ptOrEta == "Eta")
11557      {
11558       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11559      }
11560   } else // this is diff flow of RPs 
11561     {
11562      if(ptOrEta == "Pt")
11563      { 
11564       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11565      } else if (ptOrEta == "Eta")
11566        {
11567         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11568        }
11569     }
11570   psi1=aftsTrack->Phi(); 
11571   for(Int_t i2=0;i2<nPrim;i2++)
11572   {
11573    if(i2==i1) continue;
11574    aftsTrack=anEvent->GetTrack(i2);
11575    // RP condition (!(first) particle in the correlator must be RP):
11576    if(!(aftsTrack->InRPSelection())) continue;
11577    phi2=aftsTrack->Phi();   
11578    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11579    // 2'-particle correlations: 
11580    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),wPhi2); // <w2 cos(n*(psi1-phi2))  
11581   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11582  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11583  
11584  // 4'-particle correlations:
11585  for(Int_t i1=0;i1<nPrim;i1++)
11586  {
11587   aftsTrack=anEvent->GetTrack(i1);
11588   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11589   if(typeFlag==1) // this is diff flow of POIs 
11590   {
11591    if(ptOrEta == "Pt")
11592    { 
11593     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11594    } else if (ptOrEta == "Eta")
11595      {
11596       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11597      }
11598   } else // this is diff flow of RPs 
11599     {
11600      if(ptOrEta == "Pt")
11601      { 
11602       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11603      } else if (ptOrEta == "Eta")
11604        {
11605         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11606        }
11607     }
11608   psi1=aftsTrack->Phi();
11609   for(Int_t i2=0;i2<nPrim;i2++)
11610   {
11611    if(i2==i1) continue;
11612    aftsTrack=anEvent->GetTrack(i2);
11613    // RP condition (!(first) particle in the correlator must be RP): 
11614    if(!(aftsTrack->InRPSelection())) continue;
11615    phi2=aftsTrack->Phi();
11616    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11617    for(Int_t i3=0;i3<nPrim;i3++)
11618    { 
11619     if(i3==i1||i3==i2) continue;
11620     aftsTrack=anEvent->GetTrack(i3);
11621     // RP condition (!(first) particle in the correlator must be RP):
11622     if(!(aftsTrack->InRPSelection())) continue;
11623     phi3=aftsTrack->Phi();
11624     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11625     for(Int_t i4=0;i4<nPrim;i4++)
11626     {
11627      if(i4==i1||i4==i2||i4==i3) continue;
11628      aftsTrack=anEvent->GetTrack(i4);
11629      // RP condition (!(first) particle in the correlator must be RP):
11630      if(!(aftsTrack->InRPSelection())) continue;  
11631      phi4=aftsTrack->Phi();
11632      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
11633      // 4'-particle correlations <w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))>:
11634      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),wPhi2*wPhi3*wPhi4); 
11635     }//end of for(Int_t i4=0;i4<nPrim;i4++)
11636    }//end of for(Int_t i3=0;i3<nPrim;i3++)
11637   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
11638  }//end of for(Int_t i1=0;i1<nPrim;i1++)      
11639  
11640  // count # of RPs and POIs in selected pt and eta bins for cross-checkings: (to be improved - moved to dedicated method)
11641  for(Int_t i=0;i<nPrim;i++)
11642  {
11643   aftsTrack=anEvent->GetTrack(i); 
11644   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11645   if(typeFlag==1) // this is diff flow of POIs 
11646   {
11647    if(ptOrEta == "Pt")
11648    { 
11649     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11650    } else if (ptOrEta == "Eta")
11651      {
11652       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11653      }
11654   } else // this is diff flow of RPs 
11655     {
11656      if(ptOrEta == "Pt")
11657      { 
11658       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11659      } else if (ptOrEta == "Eta")
11660        {
11661         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11662        }
11663     }
11664   if(t==1)t++; 
11665   fNoOfParticlesInBin->Fill(t+pe+0.5);  
11666  }
11667  
11668 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11669
11670
11671 //================================================================================================================================
11672
11673    
11674 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11675 {
11676  // Evaluate with nested loops correction terms for non-uniform acceptance (both sin and cos terms) relevant for differential flow.
11677  
11678  // Remark 1: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
11679  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11680  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
11681  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
11682  //  cti: 
11683  //    0: <<sc n(psi1)>>
11684  //    1: <<sc n(psi1+phi2)>> 
11685  //    2: <<sc n(psi1+phi2-phi3)>>
11686  //    3: <<sc n(psi1-phi2-phi3)>>
11687  //    4:
11688  //    5:
11689  //    6:
11690   
11691  Int_t typeFlag = 0;
11692  Int_t ptEtaFlag = 0;
11693  if(type == "RP")
11694  {
11695   typeFlag = 0;
11696  } else if(type == "POI")
11697    {
11698     typeFlag = 1;
11699    }      
11700  if(ptOrEta == "Pt")
11701  {
11702   ptEtaFlag = 0;
11703  } else if(ptOrEta == "Eta")
11704    {
11705     ptEtaFlag = 1;
11706    } 
11707  // shortcuts:
11708  Int_t t = typeFlag;
11709  Int_t pe = ptEtaFlag;
11710       
11711  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11712  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11713  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11714  
11715  Int_t nPrim = anEvent->NumberOfTracks(); 
11716  AliFlowTrackSimple *aftsTrack = NULL;
11717  
11718  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11719  
11720  Int_t n = fHarmonic; 
11721  
11722  // 1-particle correction terms:
11723  for(Int_t i1=0;i1<nPrim;i1++)
11724  {
11725   aftsTrack=anEvent->GetTrack(i1);
11726   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11727   if(typeFlag==1) // this is diff flow of POIs 
11728   {
11729    if(ptOrEta == "Pt")
11730    { 
11731     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11732    } else if (ptOrEta == "Eta")
11733      {
11734       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11735      }
11736   } else // this is diff flow of RPs 
11737     {
11738      if(ptOrEta == "Pt")
11739      { 
11740       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11741      } else if (ptOrEta == "Eta")
11742        {
11743         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11744        }
11745     }
11746   psi1=aftsTrack->Phi(); 
11747   // sin terms: 
11748   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
11749   // cos terms: 
11750   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
11751  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11752    
11753  // 2-particle correction terms:
11754  for(Int_t i1=0;i1<nPrim;i1++)
11755  {
11756   aftsTrack=anEvent->GetTrack(i1);
11757    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11758   if(typeFlag==1) // this is diff flow of POIs 
11759   {
11760    if(ptOrEta == "Pt")
11761    { 
11762     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11763    } else if (ptOrEta == "Eta")
11764      {
11765       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11766      }
11767   } else // this is diff flow of RPs 
11768     {
11769      if(ptOrEta == "Pt")
11770      { 
11771       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11772      } else if (ptOrEta == "Eta")
11773        {
11774         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11775        }
11776     }
11777   psi1=aftsTrack->Phi(); 
11778   for(Int_t i2=0;i2<nPrim;i2++)
11779   {
11780    if(i2==i1) continue;
11781    aftsTrack=anEvent->GetTrack(i2);
11782    // RP condition (!(first) particle in the correlator must be RP):
11783    if(!(aftsTrack->InRPSelection())) continue;
11784    phi2=aftsTrack->Phi();   
11785    // sin terms: 
11786    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),1.); // <<sin(n*(psi1+phi2))>>  
11787    // cos terms: 
11788    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),1.); // <<cos(n*(psi1+phi2))>>  
11789   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11790  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
11791  
11792  // 3-particle correction terms:
11793  for(Int_t i1=0;i1<nPrim;i1++)
11794  {
11795   aftsTrack=anEvent->GetTrack(i1);
11796    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11797   if(typeFlag==1) // this is diff flow of POIs 
11798   {
11799    if(ptOrEta == "Pt")
11800    { 
11801     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11802    } else if (ptOrEta == "Eta")
11803      {
11804       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11805      }
11806   } else // this is diff flow of RPs 
11807     {
11808      if(ptOrEta == "Pt")
11809      { 
11810       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11811      } else if (ptOrEta == "Eta")
11812        {
11813         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11814        }
11815     }
11816   psi1=aftsTrack->Phi();
11817   for(Int_t i2=0;i2<nPrim;i2++)
11818   {
11819    if(i2==i1) continue;
11820    aftsTrack=anEvent->GetTrack(i2);
11821    // RP condition (!(first) particle in the correlator must be RP):
11822    if(!(aftsTrack->InRPSelection())) continue;
11823    phi2=aftsTrack->Phi();
11824    for(Int_t i3=0;i3<nPrim;i3++)
11825    {
11826     if(i3==i1||i3==i2) continue;
11827     aftsTrack=anEvent->GetTrack(i3);
11828     // RP condition (!(first) particle in the correlator must be RP):
11829     if(!(aftsTrack->InRPSelection())) continue;
11830     phi3=aftsTrack->Phi();
11831     // sin terms: 
11832     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2-phi3)),1.); // <<sin(n*(psi1+phi2-phi3))>>  
11833     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1-phi2-phi3)),1.); // <<sin(n*(psi1-phi2-phi3))>>  
11834     // cos terms: 
11835     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3)),1.); // <<cos(n*(psi1+phi2-phi3))>>  
11836     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-phi2-phi3)),1.); // <<cos(n*(psi1-phi2-phi3))>>  
11837    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
11838   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
11839  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11840    
11841 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11842
11843
11844 //================================================================================================================================
11845
11846
11847 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
11848 {
11849  // Compare corrections temrs for non-uniform acceptance needed for diff. flow calculated with nested loops and those calculated from Q-vectors
11850  
11851  Int_t typeFlag = 0;
11852  Int_t ptEtaFlag = 0;
11853  if(type == "RP")
11854  {
11855   typeFlag = 0;
11856  } else if(type == "POI")
11857    {
11858     typeFlag = 1;
11859    }      
11860  if(ptOrEta == "Pt")
11861  {
11862   ptEtaFlag = 0;
11863  } else if(ptOrEta == "Eta")
11864    {
11865     ptEtaFlag = 1;
11866    } 
11867  // shortcuts:
11868  Int_t t = typeFlag;
11869  Int_t pe = ptEtaFlag;
11870       
11871  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11872  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11873  //TString sinCosFlag[2] = {"sin","cos"}; // to be improved (eventually promote to data member)
11874  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)
11875  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)
11876  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11877  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11878  
11879  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
11880  
11881  cout<<endl;
11882  cout<<"   ******************************************"<<endl;
11883  cout<<"   ****  cross-checking the correction   ****"<<endl;
11884  cout<<"   **** terms for non-uniform acceptance ****"<<endl; 
11885  cout<<"   ****    for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
11886  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
11887  {
11888   cout<<"   ****    (particle weights not used)   ****"<<endl;
11889  } else
11890    {
11891     cout<<"   ****     (particle weights used)      ****"<<endl;
11892    } 
11893  cout<<"   ******************************************"<<endl; 
11894  cout<<endl;
11895  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
11896  cout<<endl;
11897  
11898  for(Int_t cti=0;cti<4;cti++) // correction term index
11899  {
11900   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
11901   {
11902    if(sc==0) // to be improved (this can be implemented better)
11903    { 
11904     cout<<"      "<<reducedCorrectionSinTerms[cti].Data()<<":"<<endl;
11905    } else
11906      {
11907       cout<<"      "<<reducedCorrectionCosTerms[cti].Data()<<":"<<endl;     
11908      }
11909    cout<<"      from Q-vectors    = "<<fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
11910    cout<<"      from nested loops = "<<fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]->GetBinContent(1)<<endl;
11911    cout<<endl;  
11912   } 
11913  } // end of for(Int_t rci=0;rci<4;rci++)
11914
11915 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
11916
11917
11918 //================================================================================================================================
11919
11920
11921 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
11922 {
11923  // Calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (cos terms).
11924  
11925  //                                  **********************************************************************
11926  //                                  **** weighted corrections for non-uniform acceptance (cos terms): ****
11927  //                                  **********************************************************************
11928  
11929  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
11930  //
11931  // 1st bin: <<w1 cos(n*(phi1))>> = cosP1nW1
11932  // 2nd bin: <<w1 w2 cos(n*(phi1+phi2))>> = cosP1nP1nW1W1
11933  // 3rd bin: <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1nW1W1W1 
11934  // ...
11935
11936  // multiplicity (number of particles used to determine the reaction plane)
11937  Double_t dMult = (*fSMpk)(0,0);
11938  
11939  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
11940  Double_t dReQ1n1k = (*fReQ)(0,1);
11941  Double_t dReQ2n2k = (*fReQ)(1,2);
11942  //Double_t dReQ3n3k = (*fReQ)(2,3);
11943  //Double_t dReQ4n4k = (*fReQ)(3,4);
11944  Double_t dReQ1n3k = (*fReQ)(0,3);
11945  Double_t dImQ1n1k = (*fImQ)(0,1);
11946  Double_t dImQ2n2k = (*fImQ)(1,2);
11947  //Double_t dImQ3n3k = (*fImQ)(2,3);
11948  //Double_t dImQ4n4k = (*fImQ)(3,4);
11949  //Double_t dImQ1n3k = (*fImQ)(0,3);
11950
11951  // dMs are variables introduced in order to simplify some Eqs. bellow:
11952  //..............................................................................................
11953  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
11954  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
11955                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
11956  //..............................................................................................
11957          // 1-particle:
11958  Double_t cosP1nW1 = 0.; // <<w1 cos(n*(phi1))>>
11959    
11960  if(dMult>0 && TMath::Abs((*fSMpk)(0,1))>1e-6)
11961  {
11962   cosP1nW1 = dReQ1n1k/(*fSMpk)(0,1); 
11963   
11964   // average weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
11965   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1nW1);
11966   
11967   // final average weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
11968   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1nW1,(*fSMpk)(0,1));  
11969  } 
11970  
11971  // 2-particle:
11972  Double_t cosP1nP1nW1W1 = 0.; // <<w1 w2 cos(n*(phi1+phi2))>>
11973  
11974  if(dMult>1 && TMath::Abs(dM11)>1e-6)
11975  {
11976   cosP1nP1nW1W1 = (pow(dReQ1n1k,2)-pow(dImQ1n1k,2)-dReQ2n2k)/dM11; 
11977   
11978   // average weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
11979   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1nW1W1);
11980   
11981   // final average weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
11982   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1nW1W1,dM11);  
11983  } 
11984  
11985  // 3-particle:
11986  Double_t cosP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>>
11987  
11988  if(dMult>2 && TMath::Abs(dM111)>1e-6)
11989  {
11990   cosP1nM1nM1nW1W1W1 = (dReQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
11991                      - dReQ1n1k*dReQ2n2k-dImQ1n1k*dImQ2n2k
11992                      - 2.*((*fSMpk)(0,2))*dReQ1n1k
11993                      + 2.*dReQ1n3k) 
11994                      / dM111; 
11995   
11996   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
11997   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1nW1W1W1);
11998   
11999   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
12000   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1nW1W1W1,dM111);  
12001  } 
12002  
12003 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
12004
12005
12006 //================================================================================================================================
12007
12008
12009 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
12010 {
12011  // calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
12012  
12013  //                                  **********************************************************************
12014  //                                  **** weighted corrections for non-uniform acceptance (sin terms): ****
12015  //                                  **********************************************************************
12016  
12017  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
12018  //
12019  // 1st bin: <<w1 sin(n*(phi1))>> = sinP1nW1
12020  // 2nd bin: <<w1 w2 sin(n*(phi1+phi2))>> = sinP1nP1nW1W1
12021  // 3rd bin: <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1nW1W1W1 
12022  // ...
12023
12024  // multiplicity (number of particles used to determine the reaction plane)
12025  Double_t dMult = (*fSMpk)(0,0);
12026  
12027  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
12028  Double_t dReQ1n1k = (*fReQ)(0,1);
12029  Double_t dReQ2n2k = (*fReQ)(1,2);
12030  //Double_t dReQ3n3k = (*fReQ)(2,3);
12031  //Double_t dReQ4n4k = (*fReQ)(3,4);
12032  //Double_t dReQ1n3k = (*fReQ)(0,3);
12033  Double_t dImQ1n1k = (*fImQ)(0,1);
12034  Double_t dImQ2n2k = (*fImQ)(1,2);
12035  //Double_t dImQ3n3k = (*fImQ)(2,3);
12036  //Double_t dImQ4n4k = (*fImQ)(3,4);
12037  Double_t dImQ1n3k = (*fImQ)(0,3);
12038
12039  // dMs are variables introduced in order to simplify some Eqs. bellow:
12040  //..............................................................................................
12041  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
12042  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
12043                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
12044  //..............................................................................................
12045  
12046  // 1-particle:
12047  Double_t sinP1nW1 = 0.; // <<w1 sin(n*(phi1))>>
12048  
12049  if(dMult>0 && TMath::Abs((*fSMpk)(0,1))>1e-6)
12050  {
12051   sinP1nW1 = dImQ1n1k/((*fSMpk)(0,1)); 
12052      
12053   // average weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
12054   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1nW1);
12055   
12056   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
12057   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1nW1,(*fSMpk)(0,1));  
12058  } 
12059  
12060  // 2-particle:
12061  Double_t sinP1nP1nW1W1 = 0.; // <<w1 w2 sin(n*(phi1+phi2))>>
12062  
12063  if(dMult>1 && TMath::Abs(dM11)>1e-6)
12064  {
12065   sinP1nP1nW1W1 = (2.*dReQ1n1k*dImQ1n1k-dImQ2n2k)/dM11; 
12066      
12067   // average weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
12068   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1nW1W1);
12069   
12070   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
12071   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1nW1W1,dM11);  
12072  } 
12073  
12074  // 3-particle:
12075  Double_t sinP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>>
12076  
12077  if(dMult>2 && TMath::Abs(dM111)>1e-6)
12078  {
12079   sinP1nM1nM1nW1W1W1 = (-dImQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
12080                      + dReQ1n1k*dImQ2n2k-dImQ1n1k*dReQ2n2k
12081                      + 2.*((*fSMpk)(0,2))*dImQ1n1k
12082                      - 2.*dImQ1n3k)
12083                      / dM111; 
12084   
12085   // average weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
12086   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1nW1W1W1);
12087   
12088   // final average weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
12089   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1nW1W1W1,dM111);  
12090  } 
12091  
12092 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
12093
12094
12095 //================================================================================================================================
12096
12097
12098 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
12099 {
12100  // Evaluate with nested loops correction terms for non-uniform acceptance for integrated flow (using the particle weights). 
12101
12102  // Results are stored in profiles fIntFlowDirectCorrectionTermsForNUA[0] (sin terms) and
12103  // fIntFlowDirectCorrectionTermsForNUA[1] (cos terms). 
12104  
12105  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrectionTermsForNUA[sc] is 
12106  // organized as follows (sc stands for either sin or cos):
12107  //
12108  // 1st bin: <<w1 sc(n*(phi1))>> = scP1nW1
12109  // 2nd bin: <<w1 w2 sc(n*(phi1+phi2))>> = scP1nP1nW1W1
12110  // 3rd bin: <<w1 w2 w3 sc(n*(phi1-phi2-phi3))>> = scP1nM1nM1nW1W1W1 
12111  // ...
12112   
12113  Int_t nPrim = anEvent->NumberOfTracks(); 
12114  AliFlowTrackSimple *aftsTrack = NULL;
12115  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
12116  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
12117  Double_t phi1=0., phi2=0., phi3=0.;
12118  Double_t wPhi1=1., wPhi2=1., wPhi3=1.;
12119  Int_t n = fHarmonic; 
12120  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
12121  Double_t dMult = (*fSMpk)(0,0);
12122  cout<<endl;
12123  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
12124  if(dMult<1)
12125  {
12126   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
12127  } else if (dMult>fMaxAllowedMultiplicity)
12128    {
12129     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
12130    } else 
12131      { 
12132       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
12133      } 
12134       
12135  // 1-particle correction terms using particle weights:       
12136  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
12137  {
12138   for(Int_t i1=0;i1<nPrim;i1++)
12139   {
12140    aftsTrack=anEvent->GetTrack(i1);
12141    if(!(aftsTrack->InRPSelection())) continue;
12142    phi1=aftsTrack->Phi();
12143    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12144    // 1-particle correction terms using particle weights:
12145    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),wPhi1); // <w1 sin(n*phi1)>
12146    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),wPhi1); // <w1 cos(n*phi1)>
12147   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12148  } // end of if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity) 
12149  
12150  // 2-particle correction terms using particle weights:       
12151  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
12152  {
12153   for(Int_t i1=0;i1<nPrim;i1++)
12154   {
12155    aftsTrack=anEvent->GetTrack(i1);
12156    if(!(aftsTrack->InRPSelection())) continue;
12157    phi1=aftsTrack->Phi();
12158    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12159    for(Int_t i2=0;i2<nPrim;i2++)
12160    {
12161     if(i2==i1)continue;
12162     aftsTrack=anEvent->GetTrack(i2);
12163     if(!(aftsTrack->InRPSelection())) continue;
12164     phi2=aftsTrack->Phi();
12165     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12166     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
12167     // 2-p correction terms using particle weights:    
12168     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 sin(n*(phi1+phi2))>
12169     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 cos(n*(phi1+phi2))>
12170    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12171   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12172  } // end of if(nPrim>=2)
12173
12174  // 3-particle correction terms using particle weights:       
12175  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
12176  { 
12177   for(Int_t i1=0;i1<nPrim;i1++)
12178   {
12179    aftsTrack=anEvent->GetTrack(i1);
12180    if(!(aftsTrack->InRPSelection())) continue;
12181    phi1=aftsTrack->Phi();
12182    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12183    for(Int_t i2=0;i2<nPrim;i2++)
12184    {
12185     if(i2==i1)continue;
12186     aftsTrack=anEvent->GetTrack(i2);
12187     if(!(aftsTrack->InRPSelection())) continue;
12188     phi2=aftsTrack->Phi();
12189     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12190     for(Int_t i3=0;i3<nPrim;i3++)
12191     {
12192      if(i3==i1||i3==i2)continue;
12193      aftsTrack=anEvent->GetTrack(i3);
12194      if(!(aftsTrack->InRPSelection())) continue;
12195      phi3=aftsTrack->Phi();
12196      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12197      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
12198      // 3-p correction terms using particle weights:    
12199      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 sin(n*(phi1-phi2-phi3))>
12200      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n*(phi1-phi2-phi3))>
12201     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12202    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12203   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12204  } // end of if(nPrim>=3)
12205  
12206  /*
12207  
12208  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
12209  {
12210   // 4 nested loops multiparticle correlations using particle weights:       
12211   for(Int_t i1=0;i1<nPrim;i1++)
12212   {
12213    aftsTrack=anEvent->GetTrack(i1);
12214    if(!(aftsTrack->InRPSelection())) continue;
12215    phi1=aftsTrack->Phi();
12216    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12217    for(Int_t i2=0;i2<nPrim;i2++)
12218    {
12219     if(i2==i1)continue;
12220     aftsTrack=anEvent->GetTrack(i2);
12221     if(!(aftsTrack->InRPSelection())) continue;
12222     phi2=aftsTrack->Phi();
12223     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12224     for(Int_t i3=0;i3<nPrim;i3++)
12225     {
12226      if(i3==i1||i3==i2)continue;
12227      aftsTrack=anEvent->GetTrack(i3);
12228      if(!(aftsTrack->InRPSelection())) continue;
12229      phi3=aftsTrack->Phi();
12230      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12231      for(Int_t i4=0;i4<nPrim;i4++)
12232      {
12233       if(i4==i1||i4==i2||i4==i3)continue;
12234       aftsTrack=anEvent->GetTrack(i4);
12235       if(!(aftsTrack->InRPSelection())) continue;
12236       phi4=aftsTrack->Phi();
12237       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
12238       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
12239       // 4-p correlations using particle weights:
12240       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
12241       // extra correlations: 
12242       // 2-p extra correlations (do not appear if particle weights are not used):
12243       // ...
12244       // 3-p extra correlations (do not appear if particle weights are not used):
12245       // ...
12246       // 4-p extra correlations (do not appear if particle weights are not used):
12247       // ...
12248      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
12249     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12250    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12251   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12252  } // end of if(nPrim>=4)
12253
12254  */
12255
12256  cout<<endl; 
12257
12258 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
12259
12260
12261 //================================================================================================================================
12262
12263
12264 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
12265 {
12266  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms) using particle weights.
12267  
12268  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
12269  //
12270  //  0: <<cos n(psi)>>
12271  //  1: <<w2 cos n(psi1+phi2)>>
12272  //  2: <<w2 w3 cos n(psi1+phi2-phi3)>>
12273  //  3: <<w2 w3 cos n(psi1-phi2-phi3)>>
12274  //  4:
12275  //  5:
12276  //  6:
12277  
12278  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
12279  Double_t dReQ1n1k = (*fReQ)(0,1);
12280  Double_t dReQ2n2k = (*fReQ)(1,2);
12281  //Double_t dReQ1n3k = (*fReQ)(0,3);
12282  //Double_t dReQ4n4k = (*fReQ)(3,4);
12283  Double_t dImQ1n1k = (*fImQ)(0,1);
12284  Double_t dImQ2n2k = (*fImQ)(1,2);
12285  //Double_t dImQ1n3k = (*fImQ)(0,3);
12286  //Double_t dImQ4n4k = (*fImQ)(3,4);
12287  
12288  // S^M_{p,k} (see .h file for the definition of fSMpk):
12289  Double_t dSM1p1k = (*fSMpk)(0,1);
12290  Double_t dSM1p2k = (*fSMpk)(0,2);
12291  Double_t dSM2p1k = (*fSMpk)(1,1);
12292
12293  Int_t t = 0; // type flag 
12294  Int_t pe = 0; // ptEta flag
12295  
12296  if(type == "RP")
12297  {
12298   t = 0;
12299  } else if(type == "POI")
12300    {
12301     t = 1;
12302    }
12303
12304  if(ptOrEta == "Pt")
12305  {
12306   pe = 0;
12307  } else if(ptOrEta == "Eta")
12308    {
12309     pe = 1;
12310    }
12311     
12312  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
12313  Double_t minPtEta[2] = {fPtMin,fEtaMin};
12314  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
12315  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12316  
12317  // looping over all bins and calculating correction terms: 
12318  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12319  {
12320   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
12321   Double_t p1n0kRe = 0.;
12322   Double_t p1n0kIm = 0.;
12323
12324   // number of POIs in particular pt or eta bin:
12325   Double_t mp = 0.;
12326
12327   // 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):
12328   Double_t q1n2kRe = 0.;
12329   Double_t q1n2kIm = 0.;
12330   Double_t q2n1kRe = 0.;
12331   Double_t q2n1kIm = 0.;
12332     
12333   // s_{1,1}, s_{1,2} // to be improved (add explanation)  
12334   Double_t s1p1k = 0.; 
12335   Double_t s1p2k = 0.; 
12336   
12337   // number of particles which are both RPs and POIs in particular pt or eta bin:
12338   Double_t mq = 0.;
12339   
12340   // M0111 from Eq. (118) in QC2c (to be improved (notation))
12341   Double_t dM01 = 0.;
12342   Double_t dM011 = 0.;
12343   
12344   if(type == "POI")
12345   {           
12346    // q_{m*n,k}:
12347    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
12348            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
12349    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
12350            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
12351    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
12352            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
12353    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
12354            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
12355    mq = fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12356    
12357    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
12358    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
12359   }else if(type == "RP")
12360    {
12361     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
12362     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
12363             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
12364     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
12365             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
12366     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
12367             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
12368     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
12369             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
12370     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12371     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
12372     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
12373     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.);  
12374     
12375     mq = fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12376   }    
12377   
12378   if(type == "POI")
12379   {
12380    // p_{m*n,k}:   
12381    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
12382            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
12383    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
12384            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
12385    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12386    // M01 from Eq. (118) in QC2c (to be improved (notation)):
12387    dM01 = mp*dSM1p1k-s1p1k;
12388    dM011 = mp*(dSM2p1k-dSM1p2k)
12389          - 2.*(s1p1k*dSM1p1k-s1p2k);
12390        
12391    // typeFlag = RP (0) or POI (1):   
12392    t = 1; 
12393   } else if(type == "RP")
12394     {  
12395      // to be improved (cross-checked):
12396      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
12397              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
12398      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
12399              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
12400      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12401      // M01 from Eq. (118) in QC2c (to be improved (notation)):
12402      dM01 = mp*dSM1p1k-s1p1k;
12403      dM011 = mp*(dSM2p1k-dSM1p2k)
12404            - 2.*(s1p1k*dSM1p1k-s1p2k); 
12405      // typeFlag = RP (0) or POI (1): 
12406      t = 0;
12407     }
12408   
12409   // <<cos n(psi1)>>:
12410   Double_t cosP1nPsi = 0.;
12411   if(mp)
12412   {
12413    cosP1nPsi = p1n0kRe/mp;
12414    
12415    // fill profile for <<cos n(psi1)>>:
12416    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
12417    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
12418    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
12419   } // end of if(mp)   
12420   
12421   // <<w2 cos n(psi1+phi2)>>:
12422   Double_t cosP1nPsiP1nPhiW2 = 0.;
12423   if(dM01)
12424   {
12425    cosP1nPsiP1nPhiW2 = (p1n0kRe*dReQ1n1k-p1n0kIm*dImQ1n1k-q2n1kRe)/(dM01);
12426    // fill profile for <<w2 cos n(psi1+phi2)>>:
12427    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhiW2,dM01);
12428    // histogram to store <w2 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12429    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhiW2);
12430   } // end of if(dM01)   
12431   
12432   // <<w2 w3 cos n(psi1+phi2-phi3)>>:
12433   Double_t cosP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
12434   if(dM011)
12435   {
12436    cosP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
12437                               - p1n0kRe*dSM1p2k
12438                               - q2n1kRe*dReQ1n1k-q2n1kIm*dImQ1n1k
12439                               - s1p1k*dReQ1n1k
12440                               + 2.*q1n2kRe)
12441                               / dM011;  
12442    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
12443    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3W2W3,dM011);
12444    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12445    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3W2W3);
12446   } // end of if(dM011)   
12447   
12448   // <<w2 w3 cos n(psi1-phi2-phi3)>>:
12449   Double_t cosP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
12450   if(dM011)
12451   {
12452    cosP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))+2.*p1n0kIm*dReQ1n1k*dImQ1n1k
12453                               - 1.*(p1n0kRe*dReQ2n2k+p1n0kIm*dImQ2n2k)  
12454                               - 2.*s1p1k*dReQ1n1k
12455                               + 2.*q1n2kRe)
12456                               / dM011;
12457    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
12458    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3W2W3,dM011);
12459    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12460    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3W2W3);
12461   } // end of if(dM011)   
12462  
12463  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12464    
12465 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
12466
12467
12468 //================================================================================================================================
12469
12470
12471 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
12472 {
12473  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
12474   
12475  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
12476  //  0: <<sin n(psi1)>>
12477  //  1: <<w2 sin n(psi1+phi2)>>
12478  //  2: <<w2 w3 sin n(psi1+phi2-phi3)>>
12479  //  3: <<w2 w3 sin n(psi1-phi2-phi3)>>:
12480  //  4:
12481  //  5:
12482  //  6:
12483  
12484  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
12485  Double_t dReQ1n1k = (*fReQ)(0,1);
12486  Double_t dReQ2n2k = (*fReQ)(1,2);
12487  //Double_t dReQ1n3k = (*fReQ)(0,3);
12488  //Double_t dReQ4n4k = (*fReQ)(3,4);
12489  Double_t dImQ1n1k = (*fImQ)(0,1);
12490  Double_t dImQ2n2k = (*fImQ)(1,2);
12491  //Double_t dImQ1n3k = (*fImQ)(0,3);
12492  //Double_t dImQ4n4k = (*fImQ)(3,4);
12493  
12494  // S^M_{p,k} (see .h file for the definition of fSMpk):
12495  Double_t dSM1p1k = (*fSMpk)(0,1);
12496  Double_t dSM1p2k = (*fSMpk)(0,2);
12497  Double_t dSM2p1k = (*fSMpk)(1,1);
12498
12499  Int_t t = 0; // type flag 
12500  Int_t pe = 0; // ptEta flag
12501  
12502  if(type == "RP")
12503  {
12504   t = 0;
12505  } else if(type == "POI")
12506    {
12507     t = 1;
12508    }
12509
12510  if(ptOrEta == "Pt")
12511  {
12512   pe = 0;
12513  } else if(ptOrEta == "Eta")
12514    {
12515     pe = 1;
12516    }
12517     
12518  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
12519  Double_t minPtEta[2] = {fPtMin,fEtaMin};
12520  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
12521  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12522
12523  // looping over all bins and calculating correction terms: 
12524  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12525  {
12526   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
12527   Double_t p1n0kRe = 0.;
12528   Double_t p1n0kIm = 0.;
12529
12530   // number of POIs in particular pt or eta bin:
12531   Double_t mp = 0.;
12532
12533   // 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):
12534   Double_t q1n2kRe = 0.;
12535   Double_t q1n2kIm = 0.;
12536   Double_t q2n1kRe = 0.;
12537   Double_t q2n1kIm = 0.;
12538     
12539   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12540   Double_t s1p1k = 0.; 
12541   Double_t s1p2k = 0.; 
12542   
12543   // number of particles which are both RPs and POIs in particular pt or eta bin:
12544   Double_t mq = 0.;
12545   
12546   // M0111 from Eq. (118) in QC2c (to be improved (notation))
12547   Double_t dM01 = 0.;
12548   Double_t dM011 = 0.;
12549
12550   if(type == "POI")
12551   {    
12552    // q_{m*n,k}:
12553    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
12554            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
12555    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
12556            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
12557    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
12558            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
12559    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
12560            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
12561    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12562    
12563    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
12564    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
12565   }else if(type == "RP")
12566    {
12567     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
12568     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
12569             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
12570     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
12571             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
12572     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
12573             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
12574     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
12575             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
12576     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12577     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
12578     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
12579     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
12580   }    
12581   
12582   if(type == "POI")
12583   {
12584    // p_{m*n,k}:   
12585    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
12586            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
12587    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
12588            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
12589    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12590    // M01 from Eq. (118) in QC2c (to be improved (notation)):
12591    dM01 = mp*dSM1p1k-s1p1k;
12592    dM011 = mp*(dSM2p1k-dSM1p2k)
12593          - 2.*(s1p1k*dSM1p1k-s1p2k);  
12594    // typeFlag = RP (0) or POI (1):   
12595    t = 1;           
12596   } else if(type == "RP")
12597     { 
12598      // to be improved (cross-checked):
12599      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
12600              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
12601      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
12602              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
12603      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)    
12604      // M01 from Eq. (118) in QC2c (to be improved (notation)):
12605      dM01 = mp*dSM1p1k-s1p1k;
12606      dM011 = mp*(dSM2p1k-dSM1p2k)
12607            - 2.*(s1p1k*dSM1p1k-s1p2k); 
12608      // typeFlag = RP (0) or POI (1): 
12609      t = 0;
12610     }
12611   
12612   // <<sin n(psi1)>>:
12613   Double_t sinP1nPsi = 0.;
12614   if(mp)
12615   {
12616    sinP1nPsi = p1n0kIm/mp;
12617    
12618    // fill profile for <<sin n(psi1)>>:
12619    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
12620    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
12621    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
12622   } // end of if(mp)   
12623   
12624   // <<w2 sin n(psi1+phi2)>>:
12625   Double_t sinP1nPsiP1nPhiW2 = 0.;
12626   if(dM01)
12627   {
12628    sinP1nPsiP1nPhiW2 = (p1n0kRe*dImQ1n1k+p1n0kIm*dReQ1n1k-q2n1kIm)/(dM01);
12629    // fill profile for <<w2 sin n(psi1+phi2)>>:
12630    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhiW2,dM01);
12631    // histogram to store <w2 sin n(psi1+phi2)> e-b-e (needed in some other methods):
12632    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhiW2);
12633   } // end of if(mp*dMult-mq)   
12634   
12635   // <<w2 w3 sin n(psi1+phi2-phi3)>>:
12636   Double_t sinP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
12637   if(dM011)
12638   {
12639    sinP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
12640                               - p1n0kIm*dSM1p2k
12641                               + q2n1kRe*dImQ1n1k-q2n1kIm*dReQ1n1k
12642                               - s1p1k*dImQ1n1k
12643                               + 2.*q1n2kIm)
12644                               / dM011;  
12645    // fill profile for <<w2 w3 sin n(psi1+phi2-phi3)>>:
12646    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3W2W3,dM011);
12647    // histogram to store <w2 w3 sin n(psi1+phi2-phi3)> e-b-e (needed in some other methods):
12648    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3W2W3);
12649   } // end of if(dM011)   
12650   
12651   // <<w2 w3 sin n(psi1-phi2-phi3)>>:
12652   Double_t sinP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
12653   if(dM011)
12654   {
12655    sinP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))-2.*p1n0kRe*dReQ1n1k*dImQ1n1k
12656                               + 1.*(p1n0kRe*dImQ2n2k-p1n0kIm*dReQ2n2k)  
12657                               + 2.*s1p1k*dImQ1n1k
12658                               - 2.*q1n2kIm)
12659                               / dM011;
12660    // fill profile for <<w2 w3 sin n(psi1-phi2-phi3)>>:
12661    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3W2W3,dM011);
12662    // histogram to store <w2 w3 sin n(psi1-phi2-phi3)> e-b-e (needed in some other methods):
12663    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3W2W3);
12664   } // end of if(dM011)   
12665   
12666  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12667
12668 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
12669
12670
12671 //================================================================================================================================
12672
12673    
12674 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12675 {
12676  // Evaluate with nested loops correction terms for non-uniform acceptance 
12677  // with using particle weights (both sin and cos terms) relevant for differential flow.
12678  
12679  // Remark 1: "w1" in expressions bellow is a particle weight used only for particles which were 
12680  //           flagged both as POI and RP.
12681  // Remark 2: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
12682  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12683  // Remark 3: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
12684  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
12685  //  cti: 
12686  //    0: <<sc n(psi1)>>
12687  //    1: <<w2 sc n(psi1+phi2)>> 
12688  //    2: <<w2 w3 sc n(psi1+phi2-phi3)>>
12689  //    3: <<w2 w3 sc n(psi1-phi2-phi3)>>
12690  //    4:
12691  //    5:
12692  //    6:
12693      
12694  Int_t typeFlag = 0;
12695  Int_t ptEtaFlag = 0;
12696  if(type == "RP")
12697  {
12698   typeFlag = 0;
12699  } else if(type == "POI")
12700    {
12701     typeFlag = 1;
12702    }      
12703  if(ptOrEta == "Pt")
12704  {
12705   ptEtaFlag = 0;
12706  } else if(ptOrEta == "Eta")
12707    {
12708     ptEtaFlag = 1;
12709    } 
12710  // shortcuts:
12711  Int_t t = typeFlag;
12712  Int_t pe = ptEtaFlag;
12713       
12714  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12715  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12716  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12717  
12718  Int_t nPrim = anEvent->NumberOfTracks(); 
12719  AliFlowTrackSimple *aftsTrack = NULL;
12720  
12721  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12722  Double_t wPhi2=1., wPhi3=1.;
12723  
12724  Int_t n = fHarmonic; 
12725  
12726  // 1'-particle correction terms:
12727  for(Int_t i1=0;i1<nPrim;i1++)
12728  {
12729   aftsTrack=anEvent->GetTrack(i1);
12730   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12731   if(typeFlag==1) // this is diff flow of POIs 
12732   {
12733    if(ptOrEta == "Pt")
12734    { 
12735     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12736    } else if (ptOrEta == "Eta")
12737      {
12738       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12739      }
12740   } else // this is diff flow of RPs 
12741     {
12742      if(ptOrEta == "Pt")
12743      { 
12744       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12745      } else if (ptOrEta == "Eta")
12746        {
12747         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12748        }
12749     }
12750   psi1=aftsTrack->Phi(); 
12751   // sin terms: 
12752   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
12753   // cos terms: 
12754   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
12755  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12756    
12757  // 2'-particle correction terms:
12758  for(Int_t i1=0;i1<nPrim;i1++)
12759  {
12760   aftsTrack=anEvent->GetTrack(i1);
12761   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12762   if(typeFlag==1) // this is diff flow of POIs 
12763   {
12764    if(ptOrEta == "Pt")
12765    { 
12766     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12767    } else if (ptOrEta == "Eta")
12768      {
12769       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12770      }
12771   } else // this is diff flow of RPs 
12772     {
12773      if(ptOrEta == "Pt")
12774      { 
12775       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12776      } else if (ptOrEta == "Eta")
12777        {
12778         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12779        }
12780     }
12781   psi1=aftsTrack->Phi(); 
12782   for(Int_t i2=0;i2<nPrim;i2++)
12783   {
12784    if(i2==i1) continue;
12785    aftsTrack=anEvent->GetTrack(i2);
12786    // RP condition (!(first) particle in the correlator must be RP):
12787    if(!(aftsTrack->InRPSelection())) continue;
12788    phi2=aftsTrack->Phi();
12789    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12790    // sin terms: 
12791    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),wPhi2); // <<w2 sin(n*(psi1+phi2))>>  
12792    // cos terms: 
12793    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),wPhi2); // <<w2 cos(n*(psi1+phi2))>>  
12794   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12795  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
12796  
12797  // 3'-particle correction terms:
12798  for(Int_t i1=0;i1<nPrim;i1++)
12799  {
12800   aftsTrack=anEvent->GetTrack(i1);
12801   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12802   if(typeFlag==1) // this is diff flow of POIs 
12803   {
12804    if(ptOrEta == "Pt")
12805    { 
12806     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12807    } else if (ptOrEta == "Eta")
12808      {
12809       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12810      }
12811   } else // this is diff flow of RPs 
12812     {
12813      if(ptOrEta == "Pt")
12814      { 
12815       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12816      } else if (ptOrEta == "Eta")
12817        {
12818         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12819        }
12820     }
12821   psi1=aftsTrack->Phi();
12822   for(Int_t i2=0;i2<nPrim;i2++)
12823   {
12824    if(i2==i1) continue;
12825    aftsTrack=anEvent->GetTrack(i2);
12826    // RP condition (!(first) particle in the correlator must be RP):
12827    if(!(aftsTrack->InRPSelection())) continue;
12828    phi2=aftsTrack->Phi();
12829    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12830    for(Int_t i3=0;i3<nPrim;i3++)
12831    {
12832     if(i3==i1||i3==i2) continue;
12833     aftsTrack=anEvent->GetTrack(i3);
12834     // RP condition (!(first) particle in the correlator must be RP):
12835     if(!(aftsTrack->InRPSelection())) continue;
12836     phi3=aftsTrack->Phi();
12837     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));   
12838     // sin terms: 
12839     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))>>  
12840     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))>>  
12841     // cos terms: 
12842     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))>>  
12843     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))>>  
12844    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
12845   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
12846  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12847                
12848 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12849
12850 //================================================================================================================================
12851
12852 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
12853 {
12854  // Check all pointers used in method Finish().
12855  
12856  if(!fAvMultiplicity)
12857  {
12858   cout<<endl;
12859   cout<<" WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12860   cout<<endl;
12861   exit(0);
12862  }
12863  if(!fIntFlowCorrelationsPro)
12864  {
12865   cout<<endl;
12866   cout<<" WARNING (QC): fIntFlowCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12867   cout<<endl;
12868   exit(0); 
12869  }
12870  if(!fIntFlowSquaredCorrelationsPro)
12871  {
12872   cout<<endl;
12873   cout<<" WARNING (QC): fIntFlowSquaredCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12874   cout<<endl;
12875   exit(0); 
12876  } 
12877  if(!fIntFlowCorrelationsHist)
12878  {
12879   cout<<endl;
12880   cout<<" WARNING (QC): fIntFlowCorrelationsHist is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12881   cout<<endl;
12882   exit(0); 
12883  }
12884  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights) && !fIntFlowExtraCorrelationsPro) 
12885  {
12886   cout<<endl;
12887   cout<<" WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12888   cout<<endl;
12889   exit(0); 
12890  } 
12891  for(Int_t power=0;power<2;power++)
12892  { 
12893   if(!fIntFlowSumOfEventWeights[power]) 
12894   {
12895    cout<<endl;
12896    cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeights[%d] is NULL in CheckPointersUsedInFinish() !!!!",power)<<endl;
12897    cout<<endl;
12898    exit(0);
12899   }
12900  } // end of for(Int_t power=0;power<2;power++)
12901  if(!fIntFlowProductOfCorrelationsPro)
12902  {
12903   cout<<endl;
12904   cout<<" WARNING (QC): fIntFlowProductOfCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12905   cout<<endl;
12906   exit(0); 
12907  } 
12908  if(!fIntFlowSumOfProductOfEventWeights)
12909  {
12910   cout<<endl;
12911   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeights is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12912   cout<<endl;
12913   exit(0); 
12914  }
12915  if(!fIntFlowCovariances)
12916  {
12917   cout<<endl;
12918   cout<<" WARNING (QC): fIntFlowCovariances is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12919   cout<<endl;
12920   exit(0); 
12921  }  
12922  if(!fIntFlowQcumulants)
12923  {
12924   cout<<endl;
12925   cout<<" WARNING (QC): fIntFlowQcumulants is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12926   cout<<endl;
12927   exit(0); 
12928  }  
12929  if(!fIntFlow)
12930  {
12931   cout<<endl;
12932   cout<<" WARNING (QC): fIntFlow is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12933   cout<<endl;
12934   exit(0); 
12935  }
12936  if(!fCommonHists)
12937  {
12938   cout<<endl;
12939   cout<<" WARNING (QC): fCommonHists is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12940   cout<<endl;
12941   exit(0); 
12942  }
12943  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
12944  {
12945   cout<<endl;
12946   cout<<" WARNING (QC): fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th"<<endl; 
12947   cout<<"               && fCommonHistsResults8th is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12948   cout<<endl;
12949   exit(0);
12950  } 
12951  
12952  // NUA stuff:
12953  for(Int_t sc=0;sc<2;sc++) // sin/cos
12954  { 
12955   if(!fIntFlowCorrectionTermsForNUAPro[sc]) 
12956   {
12957    cout<<endl;
12958    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
12959    cout<<endl;
12960    exit(0);
12961   }
12962   if(!fIntFlowCorrectionTermsForNUAHist[sc]) 
12963   {
12964    cout<<endl;
12965    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
12966    cout<<endl;
12967    exit(0);
12968   }
12969   for(Int_t lq=0;lq<2;lq++) // linear/quadratic
12970   {
12971    if(!fIntFlowSumOfEventWeightsNUA[sc][lq]) 
12972    {
12973     cout<<endl;
12974     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsNUA[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",sc,lq)<<endl;
12975     cout<<endl;
12976     exit(0);
12977    }
12978   } // end of for(Int_t lq=0;lq<2;lq++) // linear/quadratic
12979  } // end of for(Int_t power=0;power<2;power++) 
12980  if(!fIntFlowProductOfCorrectionTermsForNUAPro)
12981  {
12982   cout<<endl;
12983   cout<<" WARNING (QC): fIntFlowProductOfCorrectionTermsForNUAPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12984   cout<<endl;
12985   exit(0); 
12986  } 
12987  if(!fIntFlowSumOfProductOfEventWeightsNUA)
12988  {
12989   cout<<endl;
12990   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeightsNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12991   cout<<endl;
12992   exit(0); 
12993  } 
12994  if(!fIntFlowCovariancesNUA)
12995  {
12996   cout<<endl;
12997   cout<<" WARNING (QC): fIntFlowCovariancesNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12998   cout<<endl;
12999   exit(0); 
13000  } 
13001  if(!fIntFlowQcumulantsErrorSquaredRatio)
13002  {
13003   cout<<endl;
13004   cout<<" WARNING (QC): fIntFlowQcumulantsErrorSquaredRatio is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13005   cout<<endl;
13006   exit(0); 
13007  } 
13008  if(!fIntFlowDetectorBias)
13009  {
13010   cout<<endl;
13011   cout<<" WARNING (QC): fIntFlowDetectorBias is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13012   cout<<endl;
13013   exit(0); 
13014  }
13015  
13016  // Versus multiplicity:
13017  if(!fCalculateCumulantsVsM){return;}
13018  for(Int_t co=0;co<=3;co++) // cumulant order
13019  {
13020   if(!fIntFlowQcumulantsVsM[co])
13021   {
13022    cout<<endl;
13023    cout<<Form(" WARNING (QC): fIntFlowQcumulantsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
13024    cout<<endl;
13025    exit(0); 
13026   }
13027   if(!fIntFlowVsM[co])
13028   {
13029    cout<<endl;
13030    cout<<Form(" WARNING (QC): fIntFlowVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
13031    cout<<endl;
13032    exit(0); 
13033   }
13034   if(!fIntFlowDetectorBiasVsM[co])
13035   {
13036    cout<<endl;
13037    cout<<Form(" WARNING (QC): fIntFlowDetectorBiasVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
13038    cout<<endl;
13039    exit(0); 
13040   }
13041  } // end of for(Int_t c0=0;c0<=3;c0++) // cumulant order
13042  for(Int_t ci=0;ci<=3;ci++) // correlation index
13043  {
13044   if(!fIntFlowCorrelationsVsMPro[ci])
13045   {
13046    cout<<endl;
13047    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
13048    cout<<endl;
13049    exit(0); 
13050   }
13051   if(!fIntFlowSquaredCorrelationsVsMPro[ci])
13052   {
13053    cout<<endl;
13054    cout<<Form(" WARNING (QC): fIntFlowSquaredCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
13055    cout<<endl;
13056    exit(0); 
13057   }  
13058   if(!fIntFlowCorrelationsVsMHist[ci])
13059   {
13060    cout<<endl;
13061    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
13062    cout<<endl;
13063    exit(0); 
13064   }
13065   for(Int_t power=0;power<2;power++) 
13066   {
13067    if(!fIntFlowSumOfEventWeightsVsM[ci][power])
13068    {
13069     cout<<endl;
13070     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsVsM[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",ci,power)<<endl;
13071     cout<<endl;
13072     exit(0);   
13073    }
13074   } // end of for(Int_t power=0;power<2;power++) 
13075  } // end of for(Int_t ci=0;ci<=3;ci++) // correlation index
13076  for(Int_t i=0;i<6;i++)
13077  {
13078   if(!fIntFlowProductOfCorrelationsVsMPro[i])
13079   {
13080    cout<<endl;
13081    cout<<Form(" WARNING (QC): fIntFlowProductOfCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
13082    cout<<endl;
13083    exit(0); 
13084   }
13085   if(!fIntFlowSumOfProductOfEventWeightsVsM[i])
13086   {
13087    cout<<endl;
13088    cout<<Form(" WARNING (QC): fIntFlowSumOfProductOfEventWeightsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
13089    cout<<endl;
13090    exit(0); 
13091   }
13092   if(!fIntFlowCovariancesVsM[i])
13093   {
13094    cout<<endl;
13095    cout<<Form(" WARNING (QC): fIntFlowCovariancesVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
13096    cout<<endl;
13097    exit(0); 
13098   }
13099  } // end of for(Int_t i=0;i<6;i++) 
13100  if(!fIntFlowRebinnedInM)
13101  {
13102   cout<<endl;
13103   cout<<" WARNING (QC): fIntFlowRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13104   cout<<endl;
13105   exit(0); 
13106  }
13107  if(!fIntFlowQcumulantsRebinnedInM)
13108  {
13109   cout<<endl;
13110   cout<<" WARNING (QC): fIntFlowQcumulantsRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13111   cout<<endl;
13112   exit(0); 
13113  }  
13114  
13115 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
13116
13117 //================================================================================================================================
13118
13119 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
13120 {
13121  // Check all pointers used in method Make().
13122  
13123  if(!fAvMultiplicity)
13124  {
13125   cout<<endl;
13126   cout<<" WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInMake() !!!!"<<endl;
13127   cout<<endl;
13128   exit(0);
13129  }
13130  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights) && !fIntFlowExtraCorrelationsPro) 
13131  {
13132   cout<<endl;
13133   cout<<" WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInMake() !!!!"<<endl;
13134   cout<<endl;
13135   exit(0); 
13136  } 
13137
13138 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
13139  
13140