]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx
added 5particle correlator
[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  
737  // h) Calculate the final results for differential flow (without/with weights);
738  // i) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA);
739  // j) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults;
740  // k) Store results for differential flow in AliFlowCommonHistResults;
741  // l) Print the final results for integrated flow (RP/POI) on the screen; 
742  // m) Cross-checking: Results from Q-vectors vs results from nested loops.
743  
744  // a) Check all pointers used in this method:
745  this->CheckPointersUsedInFinish();
746   
747  // b) Acces the constants:
748  this->AccessConstants();          
749  
750  if(fCommonHists && fCommonHists->GetHarmonic()) // to be improved (moved somewhere else)
751  {
752   fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
753  } 
754  
755  // c) Access the flags: // to be improved (implement a method for this)
756  fUsePhiWeights = (Bool_t)fUseParticleWeights->GetBinContent(1); 
757  fUsePtWeights = (Bool_t)fUseParticleWeights->GetBinContent(2); 
758  fUseEtaWeights = (Bool_t)fUseParticleWeights->GetBinContent(3);  
759  fApplyCorrectionForNUA = (Bool_t)fIntFlowFlags->GetBinContent(3); 
760  fPrintFinalResults[0] = (Bool_t)fIntFlowFlags->GetBinContent(4);
761  fPrintFinalResults[1] = (Bool_t)fIntFlowFlags->GetBinContent(5);
762  fPrintFinalResults[2] = (Bool_t)fIntFlowFlags->GetBinContent(6);
763  fPrintFinalResults[3] = (Bool_t)fIntFlowFlags->GetBinContent(7);
764  fApplyCorrectionForNUAVsM = (Bool_t)fIntFlowFlags->GetBinContent(8);  
765  fPropagateErrorAlsoFromNIT = (Bool_t)fIntFlowFlags->GetBinContent(9);  
766  fCalculateCumulantsVsM = (Bool_t)fIntFlowFlags->GetBinContent(10); 
767  fMinimumBiasReferenceFlow = (Bool_t)fIntFlowFlags->GetBinContent(11); 
768  fForgetAboutCovariances = (Bool_t)fIntFlowFlags->GetBinContent(12);
769  fStorePhiDistributionForOneEvent = (Bool_t)fIntFlowFlags->GetBinContent(13);
770  fFillMultipleControlHistograms = (Bool_t)fIntFlowFlags->GetBinContent(14);
771  fEvaluateIntFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(1);
772  fEvaluateDiffFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(2); 
773  fCrossCheckInPtBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(3);
774  fCrossCheckInEtaBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(4); 
775      
776  // d) Calculate reference cumulants (not corrected for detector effects):
777  this->FinalizeCorrelationsIntFlow();
778  this->CalculateCovariancesIntFlow();
779  this->CalculateCumulantsIntFlow();
780
781  // e) Correct reference cumulants for detector effects:
782  this->FinalizeCorrectionTermsForNUAIntFlow();
783  this->CalculateCovariancesNUAIntFlow(); 
784  this->CalculateQcumulantsCorrectedForNUAIntFlow();  
785
786  // f) Calculate reference flow:
787  this->CalculateReferenceFlow(); 
788   
789  // g) Store results for reference flow in AliFlowCommonHistResults and print them on the screen:
790  this->FillCommonHistResultsIntFlow();  
791  if(fPrintFinalResults[0]){this->PrintFinalResultsForIntegratedFlow("RF");}
792  if(fPrintFinalResults[3] && fCalculateCumulantsVsM){this->PrintFinalResultsForIntegratedFlow("RF, rebinned in M");}
793  
794  
795  
796  
797  
798  
799  
800  
801  
802  // g) Calculate the final results for differential flow (without/with weights):
803  this->FinalizeReducedCorrelations("RP","Pt"); 
804  this->FinalizeReducedCorrelations("RP","Eta"); 
805  this->FinalizeReducedCorrelations("POI","Pt"); 
806  this->FinalizeReducedCorrelations("POI","Eta");
807  this->CalculateDiffFlowCovariances("RP","Pt");
808  this->CalculateDiffFlowCovariances("RP","Eta");
809  this->CalculateDiffFlowCovariances("POI","Pt");
810  this->CalculateDiffFlowCovariances("POI","Eta");
811  this->CalculateDiffFlowCumulants("RP","Pt");
812  this->CalculateDiffFlowCumulants("RP","Eta");
813  this->CalculateDiffFlowCumulants("POI","Pt");
814  this->CalculateDiffFlowCumulants("POI","Eta");
815  this->CalculateDiffFlow("RP","Pt");
816  this->CalculateDiffFlow("RP","Eta");
817  this->CalculateDiffFlow("POI","Pt");
818  this->CalculateDiffFlow("POI","Eta");
819  
820  // h) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA):
821  if(fApplyCorrectionForNUA)
822  {
823   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Pt");
824   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Eta");
825   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Pt");
826   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Eta");      
827   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Pt");   
828   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Eta");   
829   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Pt");   
830   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Eta");  
831   this->CalculateDiffFlowCorrectedForNUA("RP","Pt"); 
832   this->CalculateDiffFlowCorrectedForNUA("RP","Eta"); 
833   this->CalculateDiffFlowCorrectedForNUA("POI","Pt"); 
834   this->CalculateDiffFlowCorrectedForNUA("POI","Eta"); 
835  }
836  
837  // i) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults:
838  this->CalculateFinalResultsForRPandPOIIntegratedFlow("RP");
839  this->CalculateFinalResultsForRPandPOIIntegratedFlow("POI");
840
841  // j) Store results for differential flow in AliFlowCommonHistResults:
842  this->FillCommonHistResultsDiffFlow("RP");
843  this->FillCommonHistResultsDiffFlow("POI");
844
845  // k) Print the final results for integrated flow (RP/POI) on the screen:
846  if(fPrintFinalResults[1]){this->PrintFinalResultsForIntegratedFlow("RP");} 
847  if(fPrintFinalResults[2]){this->PrintFinalResultsForIntegratedFlow("POI");}
848   
849  // l) Cross-checking: Results from Q-vectors vs results from nested loops:
850  //  l1) Reference flow:
851  if(fEvaluateIntFlowNestedLoops)
852  {
853   this->CrossCheckIntFlowCorrelations();
854   this->CrossCheckIntFlowCorrectionTermsForNUA(); 
855   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) this->CrossCheckIntFlowExtraCorrelations();     
856  } // end of if(fEvaluateIntFlowNestedLoops)  
857  
858  //  l2) Differential flow: 
859  if(fEvaluateDiffFlowNestedLoops) 
860  {
861   // Correlations:
862   this->PrintNumberOfParticlesInSelectedBin();
863   this->CrossCheckDiffFlowCorrelations("RP","Pt");  
864   this->CrossCheckDiffFlowCorrelations("RP","Eta"); 
865   this->CrossCheckDiffFlowCorrelations("POI","Pt");  
866   this->CrossCheckDiffFlowCorrelations("POI","Eta");
867   // Correction terms for non-uniform acceptance:
868   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Pt");      
869   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Eta");       
870   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Pt");      
871   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Eta");       
872  } // end of if(fEvaluateDiffFlowNestedLoops)
873                                                                                                                                                                                                                                                                                                                                    
874 } // end of AliFlowAnalysisWithQCumulants::Finish()
875
876 //================================================================================================================================
877
878 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
879 {
880  // Calculate correction terms for non-uniform acceptance of the detector for reference flow (cos terms).
881  
882  // multiplicity:
883  Double_t dMult = (*fSMpk)(0,0);
884  
885  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
886  Double_t dReQ1n = (*fReQ)(0,0);
887  Double_t dReQ2n = (*fReQ)(1,0);
888  //Double_t dReQ3n = (*fReQ)(2,0);
889  //Double_t dReQ4n = (*fReQ)(3,0);
890  Double_t dImQ1n = (*fImQ)(0,0);
891  Double_t dImQ2n = (*fImQ)(1,0);
892  //Double_t dImQ3n = (*fImQ)(2,0);
893  //Double_t dImQ4n = (*fImQ)(3,0);
894         
895  //                                  *************************************************************
896  //                                  **** corrections for non-uniform acceptance (cos terms): ****
897  //                                  *************************************************************
898  //
899  // Remark 1: corrections for non-uniform acceptance (cos terms) calculated with non-weighted Q-vectors 
900  //           are stored in 1D profile fQCorrectionsCos.
901  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
902  // --------------------------------------------------------------------------------------------------------------------
903  // 1st bin: <<cos(n*(phi1))>> = cosP1n
904  // 2nd bin: <<cos(n*(phi1+phi2))>> = cosP1nP1n
905  // 3rd bin: <<cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1n
906  // 4th bin: <<cos(n*(2phi1-phi2))>> = cosP2nM1n
907  // --------------------------------------------------------------------------------------------------------------------
908   
909  // 1-particle:
910  Double_t cosP1n = 0.; // <<cos(n*(phi1))>>
911    
912  if(dMult>0)
913  {
914   cosP1n = dReQ1n/dMult; 
915   
916   // average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
917   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1n);
918   // event weights for NUA terms:
919   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(1,dMult);
920   
921   // final average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
922   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1n,dMult);  
923   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][0]->Fill(dMult+0.5,cosP1n,dMult);}    
924  } 
925  
926  // 2-particle:
927  Double_t cosP1nP1n = 0.; // <<cos(n*(phi1+phi2))>>
928  Double_t cosP2nM1n = 0.; // <<cos(n*(2phi1-phi2))>>
929  
930  if(dMult>1)
931  {
932   cosP1nP1n = (pow(dReQ1n,2)-pow(dImQ1n,2)-dReQ2n)/(dMult*(dMult-1)); 
933   cosP2nM1n = (dReQ2n*dReQ1n+dImQ2n*dImQ1n-dReQ1n)/(dMult*(dMult-1)); 
934   
935   // average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
936   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1n);
937   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(4,cosP2nM1n);
938   // event weights for NUA terms:
939   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(2,dMult*(dMult-1));
940   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(4,dMult*(dMult-1));
941       
942   // final average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
943   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1n,dMult*(dMult-1));  
944   fIntFlowCorrectionTermsForNUAPro[1]->Fill(3.5,cosP2nM1n,dMult*(dMult-1));
945   if(fCalculateCumulantsVsM)
946   {
947    fIntFlowCorrectionTermsForNUAVsMPro[1][1]->Fill(dMult+0.5,cosP1nP1n,dMult*(dMult-1));  
948    fIntFlowCorrectionTermsForNUAVsMPro[1][3]->Fill(dMult+0.5,cosP2nM1n,dMult*(dMult-1));
949   }
950  } 
951  
952  // 3-particle:
953  Double_t cosP1nM1nM1n = 0.; // <<cos(n*(phi1-phi2-phi3))>>
954  
955  if(dMult>2)
956  {
957   cosP1nM1nM1n = (dReQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))-dReQ1n*dReQ2n-dImQ1n*dImQ2n-2.*(dMult-1)*dReQ1n)
958                / (dMult*(dMult-1)*(dMult-2)); 
959   
960   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
961   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1n);
962   // event weights for NUA terms:
963   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
964   
965   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
966   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
967   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][2]->Fill(dMult+0.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
968  } 
969  
970 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
971
972
973 //================================================================================================================================
974
975
976 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
977 {
978  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
979  
980  // multiplicity:
981  Double_t dMult = (*fSMpk)(0,0);
982  
983  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
984  Double_t dReQ1n = (*fReQ)(0,0);
985  Double_t dReQ2n = (*fReQ)(1,0);
986  //Double_t dReQ3n = (*fReQ)(2,0);
987  //Double_t dReQ4n = (*fReQ)(3,0);
988  Double_t dImQ1n = (*fImQ)(0,0);
989  Double_t dImQ2n = (*fImQ)(1,0);
990  //Double_t dImQ3n = (*fImQ)(2,0);
991  //Double_t dImQ4n = (*fImQ)(3,0);
992         
993  //                                  *************************************************************
994  //                                  **** corrections for non-uniform acceptance (sin terms): ****
995  //                                  *************************************************************
996  //
997  // Remark 1: corrections for non-uniform acceptance (sin terms) calculated with non-weighted Q-vectors 
998  //           are stored in 1D profile fQCorrectionsSin.
999  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
1000  // --------------------------------------------------------------------------------------------------------------------
1001  // 1st bin: <<sin(n*(phi1))>> = sinP1n
1002  // 2nd bin: <<sin(n*(phi1+phi2))>> = sinP1nP1n
1003  // 3rd bin: <<sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1n
1004  // 4th bin: <<sin(n*(2phi1-phi2))>> = sinP2nM1n
1005  // --------------------------------------------------------------------------------------------------------------------
1006  
1007  // 1-particle:
1008  Double_t sinP1n = 0.; // <sin(n*(phi1))>
1009  
1010  if(dMult>0)
1011  {
1012   sinP1n = dImQ1n/dMult; 
1013      
1014   // average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
1015   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1n);  
1016   // event weights for NUA terms:
1017   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(1,dMult);
1018   
1019   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
1020   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1n,dMult);  
1021   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][0]->Fill(dMult+0.5,sinP1n,dMult);} 
1022  } 
1023  
1024  // 2-particle:
1025  Double_t sinP1nP1n = 0.; // <<sin(n*(phi1+phi2))>>
1026  Double_t sinP2nM1n = 0.; // <<sin(n*(2phi1-phi2))>>
1027  if(dMult>1)
1028  {
1029   sinP1nP1n = (2.*dReQ1n*dImQ1n-dImQ2n)/(dMult*(dMult-1)); 
1030   sinP2nM1n = (dImQ2n*dReQ1n-dReQ2n*dImQ1n-dImQ1n)/(dMult*(dMult-1)); 
1031      
1032   // average non-weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
1033   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1n);
1034   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(4,sinP2nM1n);
1035   // event weights for NUA terms:
1036   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(2,dMult*(dMult-1));
1037   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(4,dMult*(dMult-1));
1038   
1039   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
1040   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1n,dMult*(dMult-1));  
1041   fIntFlowCorrectionTermsForNUAPro[0]->Fill(3.5,sinP2nM1n,dMult*(dMult-1));  
1042   if(fCalculateCumulantsVsM)
1043   {
1044    fIntFlowCorrectionTermsForNUAVsMPro[0][1]->Fill(dMult+0.5,sinP1nP1n,dMult*(dMult-1));  
1045    fIntFlowCorrectionTermsForNUAVsMPro[0][3]->Fill(dMult+0.5,sinP2nM1n,dMult*(dMult-1));    
1046   }
1047  } 
1048  
1049  // 3-particle:
1050  Double_t sinP1nM1nM1n = 0.; // <<sin(n*(phi1-phi2-phi3))>>
1051  
1052  if(dMult>2)
1053  {
1054   sinP1nM1nM1n = (-dImQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))+dReQ1n*dImQ2n-dImQ1n*dReQ2n+2.*(dMult-1)*dImQ1n)
1055                / (dMult*(dMult-1)*(dMult-2)); 
1056   
1057   // average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
1058   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1n);
1059   // event weights for NUA terms:
1060   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
1061   
1062   // final average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
1063   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
1064   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][2]->Fill(dMult+0.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
1065  } 
1066  
1067 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
1068
1069 //================================================================================================================================
1070
1071 void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1072 {
1073  // a) Get pointers for common control and common result histograms and profiles.
1074  // b) Get pointers for histograms with particle weights.
1075  // c) Get pointers for histograms and profiles relevant for integrated flow.
1076  // d) Get pointers for histograms and profiles relevant for differental flow.
1077  // e) Get pointers for histograms and profiles holding results obtained with nested loops.
1078  
1079  if(outputListHistos)
1080  {      
1081   this->SetHistList(outputListHistos);
1082   if(!fHistList)
1083   {
1084    cout<<endl;
1085    cout<<" WARNING (QC): fHistList is NULL in AFAWQC::GOH() !!!!"<<endl;
1086    cout<<endl;
1087    exit(0);
1088   }
1089   this->GetPointersForCommonHistograms(); 
1090   this->GetPointersForParticleWeightsHistograms(); 
1091   this->GetPointersForIntFlowHistograms();
1092   this->GetPointersForDiffFlowHistograms(); 
1093   this->GetPointersForNestedLoopsHistograms(); 
1094  } else 
1095    {
1096     cout<<endl;
1097     cout<<" WARNING (QC): outputListHistos is NULL in AFAWQC::GOH() !!!!"<<endl;
1098     cout<<endl;
1099     exit(0);
1100    }
1101    
1102 } // end of void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1103
1104 //================================================================================================================================
1105
1106 TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta) const
1107 {
1108  // project 2D profile onto pt axis to get 1D profile
1109  
1110  Int_t nBinsPt   = profilePtEta->GetNbinsX();
1111  Double_t dPtMin = (profilePtEta->GetXaxis())->GetXmin();
1112  Double_t dPtMax = (profilePtEta->GetXaxis())->GetXmax();
1113  
1114  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1115  
1116  TProfile *profilePt = new TProfile("","",nBinsPt,dPtMin,dPtMax); 
1117  
1118  for(Int_t p=1;p<=nBinsPt;p++)
1119  {
1120   Double_t contentPt = 0.;
1121   Double_t entryPt = 0.;
1122   Double_t spreadPt = 0.;
1123   Double_t sum1 = 0.;
1124   Double_t sum2 = 0.;
1125   Double_t sum3 = 0.;
1126   for(Int_t e=1;e<=nBinsEta;e++)
1127   {
1128    contentPt += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1129               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1130    entryPt   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1131    
1132    sum1 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1133          * (pow(profilePtEta->GetBinError(profilePtEta->GetBin(p,e)),2.)
1134             + pow(profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)),2.)); 
1135    sum2 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1136    sum3 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1137          * (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)));            
1138   }
1139   if(sum2>0. && sum1/sum2-pow(sum3/sum2,2.) > 0.)
1140   {
1141    spreadPt = pow(sum1/sum2-pow(sum3/sum2,2.),0.5);
1142   }
1143   profilePt->SetBinContent(p,contentPt);
1144   profilePt->SetBinEntries(p,entryPt);
1145   {
1146    profilePt->SetBinError(p,spreadPt);
1147   }
1148   
1149  }
1150  
1151  return profilePt;
1152  
1153 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta)
1154
1155
1156 //================================================================================================================================
1157
1158
1159 TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta) const
1160 {
1161  // project 2D profile onto eta axis to get 1D profile
1162  
1163  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1164  Double_t dEtaMin = (profilePtEta->GetYaxis())->GetXmin();
1165  Double_t dEtaMax = (profilePtEta->GetYaxis())->GetXmax();
1166  
1167  Int_t nBinsPt = profilePtEta->GetNbinsX();
1168  
1169  TProfile *profileEta = new TProfile("","",nBinsEta,dEtaMin,dEtaMax); 
1170  
1171  for(Int_t e=1;e<=nBinsEta;e++)
1172  {
1173   Double_t contentEta = 0.;
1174   Double_t entryEta = 0.;
1175   for(Int_t p=1;p<=nBinsPt;p++)
1176   {
1177    contentEta += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1178               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1179    entryEta   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1180   }
1181   profileEta->SetBinContent(e,contentEta);
1182   profileEta->SetBinEntries(e,entryEta);
1183  }
1184  
1185  return profileEta;
1186  
1187 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta)
1188
1189 //================================================================================================================================
1190
1191 void AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type)
1192 {
1193  // Printing on the screen the final results for integrated flow (RF, POI and RP). 
1194  
1195  Int_t n = fHarmonic; 
1196  
1197  Double_t dVn[4] = {0.}; // array to hold Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1198  Double_t dVnErr[4] = {0.}; // array to hold errors of Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1199  
1200  if(type == "RF")
1201  {
1202   for(Int_t b=0;b<4;b++)
1203   {
1204    dVn[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinContent(1); 
1205    dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinError(1); 
1206    dVn[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinContent(1); 
1207    dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinError(1); 
1208    dVn[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinContent(1); 
1209    dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinError(1); 
1210    dVn[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinContent(1); 
1211    dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinError(1);    
1212   }  
1213  } else if(type == "RP")
1214    {
1215     dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinContent(1); 
1216     dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinError(1); 
1217     dVn[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinContent(1); 
1218     dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinError(1); 
1219     dVn[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinContent(1); 
1220     dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinError(1); 
1221     dVn[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinContent(1); 
1222     dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinError(1); 
1223    } else if(type == "POI")
1224      {
1225       dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinContent(1); 
1226       dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinError(1); 
1227       dVn[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinContent(1); 
1228       dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinError(1); 
1229       dVn[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinContent(1); 
1230       dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinError(1); 
1231       dVn[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinContent(1); 
1232       dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinError(1); 
1233      } else if(type == "RF, rebinned in M" && fCalculateCumulantsVsM)
1234        {
1235         for(Int_t b=0;b<4;b++)
1236         {
1237          dVn[b] = fIntFlowRebinnedInM->GetBinContent(b+1); 
1238          dVnErr[b] = fIntFlowRebinnedInM->GetBinError(b+1);
1239         }  
1240        }
1241  
1242  TString title = " flow estimates from Q-cumulants"; 
1243  TString subtitle = "    ("; 
1244  TString subtitle2 = "       (rebinned in M)"; 
1245  
1246  if(type != "RF, rebinned in M")
1247  {
1248   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
1249   {
1250    subtitle.Append(type);
1251    subtitle.Append(", without weights)");
1252   } else  
1253     {
1254      subtitle.Append(type);
1255      subtitle.Append(", with weights)");
1256     }
1257  } else
1258    {
1259     if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
1260     {
1261      subtitle.Append("RF");
1262      subtitle.Append(", without weights)");
1263     } else  
1264       {
1265        subtitle.Append("RF");
1266        subtitle.Append(", with weights)");      
1267       }
1268    } 
1269    
1270  cout<<endl;
1271  cout<<"*************************************"<<endl;
1272  cout<<"*************************************"<<endl;
1273  cout<<title.Data()<<endl; 
1274  cout<<subtitle.Data()<<endl; 
1275  if(type == "RF, rebinned in M"){cout<<subtitle2.Data()<<endl;}
1276  cout<<endl;
1277   
1278  for(Int_t i=0;i<4;i++)
1279  {
1280   cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = "<<dVn[i]<<" +/- "<<dVnErr[i]<<endl;
1281  }
1282  
1283  cout<<endl;
1284  if(type == "RF")
1285  {
1286   if(fApplyCorrectionForNUA)
1287   {
1288    cout<<" detector bias (corrected for): "<<endl;
1289   } else
1290     {
1291      cout<<" detector bias (not corrected for):"<<endl;  
1292     }
1293   cout<<"  to QC{2}: "<<fIntFlowDetectorBias->GetBinContent(1)<<" +/- "<<fIntFlowDetectorBias->GetBinError(1)<<endl;
1294   cout<<"  to QC{4}: "<<fIntFlowDetectorBias->GetBinContent(2)<<" +/- "<<fIntFlowDetectorBias->GetBinError(2)<<endl;
1295   cout<<endl;
1296  }
1297  if(type == "RF" || type == "RF, rebinned in M")
1298  {
1299   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl; 
1300  }
1301  else if (type == "RP")
1302  {
1303   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl;  
1304  } 
1305  else if (type == "POI")
1306  {
1307   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultPOI()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultPOI()->GetMean()<<endl;
1308  }  
1309  
1310  cout<<"*************************************"<<endl;
1311  cout<<"*************************************"<<endl;
1312  cout<<endl; 
1313   
1314 }// end of AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type="RF");
1315
1316 //================================================================================================================================
1317
1318 void AliFlowAnalysisWithQCumulants::WriteHistograms(TString outputFileName)
1319 {
1320  //store the final results in output .root file
1321  TFile *output = new TFile(outputFileName.Data(),"RECREATE");
1322  //output->WriteObject(fHistList, "cobjQC","SingleKey");
1323  fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
1324  delete output;
1325 }
1326
1327
1328 //================================================================================================================================
1329
1330
1331 void AliFlowAnalysisWithQCumulants::WriteHistograms(TDirectoryFile *outputFileName)
1332 {
1333  //store the final results in output .root file
1334  fHistList->SetName("cobjQC");
1335  fHistList->SetOwner(kTRUE);
1336  outputFileName->Add(fHistList);
1337  outputFileName->Write(outputFileName->GetName(), TObject::kSingleKey);
1338 }
1339
1340 //================================================================================================================================
1341
1342 void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1343 {
1344  // Book common control histograms and common histograms for final results.
1345  // common control histogram (ALL events)
1346  TString commonHistsName = "AliFlowCommonHistQC";
1347  commonHistsName += fAnalysisLabel->Data();
1348  fCommonHists = new AliFlowCommonHist(commonHistsName.Data());
1349  fHistList->Add(fCommonHists);  
1350  if(fFillMultipleControlHistograms)
1351  {
1352   // common control histogram (for events with 2 and more particles)
1353   TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
1354   commonHists2ndOrderName += fAnalysisLabel->Data();
1355   fCommonHists2nd = new AliFlowCommonHist(commonHists2ndOrderName.Data());
1356   fHistList->Add(fCommonHists2nd);  
1357   // common control histogram (for events with 4 and more particles)
1358   TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
1359   commonHists4thOrderName += fAnalysisLabel->Data();
1360   fCommonHists4th = new AliFlowCommonHist(commonHists4thOrderName.Data());
1361   fHistList->Add(fCommonHists4th);  
1362   // common control histogram (for events with 6 and more particles)
1363   TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
1364   commonHists6thOrderName += fAnalysisLabel->Data();
1365   fCommonHists6th = new AliFlowCommonHist(commonHists6thOrderName.Data());
1366   fHistList->Add(fCommonHists6th);  
1367   // common control histogram (for events with 8 and more particles)
1368   TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
1369   commonHists8thOrderName += fAnalysisLabel->Data();
1370   fCommonHists8th = new AliFlowCommonHist(commonHists8thOrderName.Data());
1371   fHistList->Add(fCommonHists8th);    
1372  } // end of if(fFillMultipleControlHistograms)
1373  
1374  // common histograms for final results for QC{2}:
1375  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC";
1376  commonHistResults2ndOrderName += fAnalysisLabel->Data();
1377  fCommonHistsResults2nd = new AliFlowCommonHistResults(commonHistResults2ndOrderName.Data());
1378  fHistList->Add(fCommonHistsResults2nd);  
1379  // common histograms for final results for QC{4}:
1380  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
1381  commonHistResults4thOrderName += fAnalysisLabel->Data();
1382  fCommonHistsResults4th = new AliFlowCommonHistResults(commonHistResults4thOrderName.Data());
1383  fHistList->Add(fCommonHistsResults4th); 
1384  // common histograms for final results for QC{6}:
1385  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
1386  commonHistResults6thOrderName += fAnalysisLabel->Data();
1387  fCommonHistsResults6th = new AliFlowCommonHistResults(commonHistResults6thOrderName.Data());
1388  fHistList->Add(fCommonHistsResults6th);  
1389  // common histograms for final results for QC{8}:
1390  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
1391  commonHistResults8thOrderName += fAnalysisLabel->Data();
1392  fCommonHistsResults8th = new AliFlowCommonHistResults(commonHistResults8thOrderName.Data());
1393  fHistList->Add(fCommonHistsResults8th); 
1394  
1395 } // end of void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1396
1397
1398 //================================================================================================================================
1399
1400
1401 void AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1402 {
1403  // book and fill histograms which hold phi, pt and eta weights
1404
1405  if(!fWeightsList)
1406  {
1407   cout<<"WARNING: fWeightsList is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1408   exit(0);  
1409  }
1410     
1411  TString fUseParticleWeightsName = "fUseParticleWeightsQC";
1412  fUseParticleWeightsName += fAnalysisLabel->Data();
1413  fUseParticleWeights = new TProfile(fUseParticleWeightsName.Data(),"0 = particle weight not used, 1 = particle weight used ",3,0,3);
1414  fUseParticleWeights->SetLabelSize(0.06);
1415  (fUseParticleWeights->GetXaxis())->SetBinLabel(1,"w_{#phi}");
1416  (fUseParticleWeights->GetXaxis())->SetBinLabel(2,"w_{p_{T}}");
1417  (fUseParticleWeights->GetXaxis())->SetBinLabel(3,"w_{#eta}");
1418  fUseParticleWeights->Fill(0.5,(Int_t)fUsePhiWeights);
1419  fUseParticleWeights->Fill(1.5,(Int_t)fUsePtWeights);
1420  fUseParticleWeights->Fill(2.5,(Int_t)fUseEtaWeights);
1421  fWeightsList->Add(fUseParticleWeights); 
1422   
1423  if(fUsePhiWeights)
1424  {
1425   if(fWeightsList->FindObject("phi_weights"))
1426   {
1427    fPhiWeights = dynamic_cast<TH1F*>(fWeightsList->FindObject("phi_weights"));
1428    if(TMath::Abs(fPhiWeights->GetBinWidth(1)-fPhiBinWidth)>pow(10.,-6.))
1429    {
1430     cout<<endl;
1431     cout<<"WARNING (QC): Inconsistent binning in histograms for phi-weights throughout the code."<<endl;
1432     cout<<endl;
1433     //exit(0);
1434    }
1435   } else 
1436     {
1437      cout<<"WARNING: fWeightsList->FindObject(\"phi_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1438      exit(0);
1439     }
1440  } // end of if(fUsePhiWeights)
1441  
1442  if(fUsePtWeights) 
1443  {
1444   if(fWeightsList->FindObject("pt_weights"))
1445   {
1446    fPtWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("pt_weights"));
1447    if(TMath::Abs(fPtWeights->GetBinWidth(1)-fPtBinWidth)>pow(10.,-6.))
1448    {
1449     cout<<endl;
1450     cout<<"WARNING (QC): Inconsistent binning in histograms for pt-weights throughout the code."<<endl;
1451     cout<<endl;
1452     //exit(0);
1453    }
1454   } else 
1455     {
1456      cout<<"WARNING: fWeightsList->FindObject(\"pt_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1457      exit(0);
1458     }
1459  } // end of if(fUsePtWeights)    
1460
1461  if(fUseEtaWeights) 
1462  {
1463   if(fWeightsList->FindObject("eta_weights"))
1464   {
1465    fEtaWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("eta_weights"));
1466    if(TMath::Abs(fEtaWeights->GetBinWidth(1)-fEtaBinWidth)>pow(10.,-6.))
1467    {
1468     cout<<endl;
1469     cout<<"WARNING (QC): Inconsistent binning in histograms for eta-weights throughout the code."<<endl;
1470     cout<<endl;
1471     //exit(0);
1472    }
1473   } else 
1474     {
1475      cout<<"WARNING: fUseEtaWeights && fWeightsList->FindObject(\"eta_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1476      exit(0);
1477     }
1478  } // end of if(fUseEtaWeights)
1479  
1480 } // end of AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1481
1482
1483 //================================================================================================================================
1484
1485
1486 void AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
1487 {
1488  // Book all objects for integrated flow:
1489  //  a) Book profile to hold all flags for integrated flow;
1490  //  b) Book event-by-event quantities;
1491  //  c) Book profiles; // to be improved (comment)
1492  //  d) Book histograms holding the final results.
1493  
1494  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
1495  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data members?)
1496  
1497  // a) Book profile to hold all flags for integrated flow:
1498  TString intFlowFlagsName = "fIntFlowFlags";
1499  intFlowFlagsName += fAnalysisLabel->Data();
1500  fIntFlowFlags = new TProfile(intFlowFlagsName.Data(),"Flags for Integrated Flow",14,0,14);
1501  fIntFlowFlags->SetTickLength(-0.01,"Y");
1502  fIntFlowFlags->SetMarkerStyle(25);
1503  fIntFlowFlags->SetLabelSize(0.05);
1504  fIntFlowFlags->SetLabelOffset(0.02,"Y");
1505  fIntFlowFlags->GetXaxis()->SetBinLabel(1,"Particle Weights");
1506  fIntFlowFlags->GetXaxis()->SetBinLabel(2,"Event Weights");
1507  fIntFlowFlags->GetXaxis()->SetBinLabel(3,"Corrected for NUA?");
1508  fIntFlowFlags->GetXaxis()->SetBinLabel(4,"Print RF results");
1509  fIntFlowFlags->GetXaxis()->SetBinLabel(5,"Print RP results");
1510  fIntFlowFlags->GetXaxis()->SetBinLabel(6,"Print POI results");
1511  fIntFlowFlags->GetXaxis()->SetBinLabel(7,"Print RF (rebinned in M) results");
1512  fIntFlowFlags->GetXaxis()->SetBinLabel(8,"Corrected for NUA vs M?");
1513  fIntFlowFlags->GetXaxis()->SetBinLabel(9,"Propagate errors to v_{n} from correlations?");
1514  fIntFlowFlags->GetXaxis()->SetBinLabel(10,"Calculate cumulants vs M");
1515  fIntFlowFlags->GetXaxis()->SetBinLabel(11,"fMinimumBiasReferenceFlow");
1516  fIntFlowFlags->GetXaxis()->SetBinLabel(12,"fForgetAboutCovariances");
1517  fIntFlowFlags->GetXaxis()->SetBinLabel(13,"fStorePhiDistributionForOneEvent");
1518  fIntFlowFlags->GetXaxis()->SetBinLabel(14,"fFillMultipleControlHistograms");
1519  fIntFlowList->Add(fIntFlowFlags);
1520
1521  // b) Book event-by-event quantities:
1522  // Re[Q_{m*n,k}], Im[Q_{m*n,k}] and S_{p,k}^M: 
1523  fReQ  = new TMatrixD(6,9);
1524  fImQ  = new TMatrixD(6,9);
1525  fSMpk = new TMatrixD(8,9);
1526  // average correlations <2>, <4>, <6> and <8> for single event (bining is the same as in fIntFlowCorrelationsPro and fIntFlowCorrelationsHist):
1527  TString intFlowCorrelationsEBEName = "fIntFlowCorrelationsEBE";
1528  intFlowCorrelationsEBEName += fAnalysisLabel->Data();
1529  fIntFlowCorrelationsEBE = new TH1D(intFlowCorrelationsEBEName.Data(),intFlowCorrelationsEBEName.Data(),4,0,4);
1530  // weights for average correlations <2>, <4>, <6> and <8> for single event:
1531  TString intFlowEventWeightsForCorrelationsEBEName = "fIntFlowEventWeightsForCorrelationsEBE";
1532  intFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
1533  fIntFlowEventWeightsForCorrelationsEBE = new TH1D(intFlowEventWeightsForCorrelationsEBEName.Data(),intFlowEventWeightsForCorrelationsEBEName.Data(),4,0,4);
1534  // average all correlations for single event (bining is the same as in fIntFlowCorrelationsAllPro and fIntFlowCorrelationsAllHist):
1535  TString intFlowCorrelationsAllEBEName = "fIntFlowCorrelationsAllEBE";
1536  intFlowCorrelationsAllEBEName += fAnalysisLabel->Data();
1537  fIntFlowCorrelationsAllEBE = new TH1D(intFlowCorrelationsAllEBEName.Data(),intFlowCorrelationsAllEBEName.Data(),34,0,34);
1538  // average correction terms for non-uniform acceptance for single event 
1539  // (binning is the same as in fIntFlowCorrectionTermsForNUAPro[2] and fIntFlowCorrectionTermsForNUAHist[2]):
1540  TString fIntFlowCorrectionTermsForNUAEBEName = "fIntFlowCorrectionTermsForNUAEBE";
1541  fIntFlowCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1542  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1543  {
1544   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);  
1545  }
1546  // event weights for terms for non-uniform acceptance: 
1547  TString fIntFlowEventWeightForCorrectionTermsForNUAEBEName = "fIntFlowEventWeightForCorrectionTermsForNUAEBE";
1548  fIntFlowEventWeightForCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1549  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1550  {
1551   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  
1552  }
1553  // c) Book profiles: // to be improved (comment)
1554  // profile to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8:
1555  TString avMultiplicityName = "fAvMultiplicity";
1556  avMultiplicityName += fAnalysisLabel->Data();
1557  fAvMultiplicity = new TProfile(avMultiplicityName.Data(),"Average Multiplicities of RPs",9,0,9);
1558  fAvMultiplicity->SetTickLength(-0.01,"Y");
1559  fAvMultiplicity->SetMarkerStyle(25);
1560  fAvMultiplicity->SetLabelSize(0.05);
1561  fAvMultiplicity->SetLabelOffset(0.02,"Y");
1562  fAvMultiplicity->SetYTitle("Average Multiplicity");
1563  (fAvMultiplicity->GetXaxis())->SetBinLabel(1,"all evts");
1564  (fAvMultiplicity->GetXaxis())->SetBinLabel(2,"n_{RP} #geq 1");
1565  (fAvMultiplicity->GetXaxis())->SetBinLabel(3,"n_{RP} #geq 2");
1566  (fAvMultiplicity->GetXaxis())->SetBinLabel(4,"n_{RP} #geq 3");
1567  (fAvMultiplicity->GetXaxis())->SetBinLabel(5,"n_{RP} #geq 4");
1568  (fAvMultiplicity->GetXaxis())->SetBinLabel(6,"n_{RP} #geq 5");
1569  (fAvMultiplicity->GetXaxis())->SetBinLabel(7,"n_{RP} #geq 6");
1570  (fAvMultiplicity->GetXaxis())->SetBinLabel(8,"n_{RP} #geq 7");
1571  (fAvMultiplicity->GetXaxis())->SetBinLabel(9,"n_{RP} #geq 8");
1572  fIntFlowProfiles->Add(fAvMultiplicity);
1573  // Average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with wrong errors!):
1574  TString correlationFlag[4] = {"#LT#LT2#GT#GT","#LT#LT4#GT#GT","#LT#LT6#GT#GT","#LT#LT8#GT#GT"};
1575  TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
1576  intFlowCorrelationsProName += fAnalysisLabel->Data();
1577  fIntFlowCorrelationsPro = new TProfile(intFlowCorrelationsProName.Data(),"Average correlations for all events",4,0,4,"s");
1578  fIntFlowCorrelationsPro->Sumw2();
1579  fIntFlowCorrelationsPro->SetTickLength(-0.01,"Y");
1580  fIntFlowCorrelationsPro->SetMarkerStyle(25);
1581  fIntFlowCorrelationsPro->SetLabelSize(0.06);
1582  fIntFlowCorrelationsPro->SetLabelOffset(0.01,"Y");
1583  for(Int_t b=0;b<4;b++)
1584  {
1585   (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(b+1,correlationFlag[b].Data());
1586  }
1587  fIntFlowProfiles->Add(fIntFlowCorrelationsPro);
1588  // Average correlations squared <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> for all events:
1589  TString squaredCorrelationFlag[4] = {"#LT#LT2#GT^{2}#GT","#LT#LT4#GT^{2}#GT","#LT#LT6#GT^{2}#GT","#LT#LT8#GT^{2}#GT"};
1590  TString intFlowSquaredCorrelationsProName = "fIntFlowSquaredCorrelationsPro";
1591  intFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
1592  fIntFlowSquaredCorrelationsPro = new TProfile(intFlowSquaredCorrelationsProName.Data(),"Average squared correlations for all events",4,0,4,"s");
1593  fIntFlowSquaredCorrelationsPro->Sumw2();
1594  fIntFlowSquaredCorrelationsPro->SetTickLength(-0.01,"Y");
1595  fIntFlowSquaredCorrelationsPro->SetMarkerStyle(25);
1596  fIntFlowSquaredCorrelationsPro->SetLabelSize(0.06);
1597  fIntFlowSquaredCorrelationsPro->SetLabelOffset(0.01,"Y");
1598  for(Int_t b=0;b<4;b++)
1599  {
1600   (fIntFlowSquaredCorrelationsPro->GetXaxis())->SetBinLabel(b+1,squaredCorrelationFlag[b].Data());
1601  }
1602  fIntFlowProfiles->Add(fIntFlowSquaredCorrelationsPro);
1603  if(fCalculateCumulantsVsM)
1604  {
1605   for(Int_t ci=0;ci<4;ci++) // correlation index
1606   {
1607    // average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (with wrong errors):
1608    TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
1609    intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
1610    fIntFlowCorrelationsVsMPro[ci] = new TProfile(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data()),
1611                                                  Form("%s vs multiplicity",correlationFlag[ci].Data()),
1612                                                  fnBinsMult,fMinMult,fMaxMult,"s");   
1613    fIntFlowCorrelationsVsMPro[ci]->Sumw2();                                                                                       
1614    fIntFlowCorrelationsVsMPro[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
1615    fIntFlowCorrelationsVsMPro[ci]->GetXaxis()->SetTitle("M");
1616    fIntFlowProfiles->Add(fIntFlowCorrelationsVsMPro[ci]);
1617    // average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> versus multiplicity for all events:  
1618    TString intFlowSquaredCorrelationsVsMProName = "fIntFlowSquaredCorrelationsVsMPro";
1619    intFlowSquaredCorrelationsVsMProName += fAnalysisLabel->Data();
1620    fIntFlowSquaredCorrelationsVsMPro[ci] = new TProfile(Form("%s, %s",intFlowSquaredCorrelationsVsMProName.Data(),squaredCorrelationFlag[ci].Data()),
1621                                                         Form("%s vs multiplicity",squaredCorrelationFlag[ci].Data()),
1622                                                         fnBinsMult,fMinMult,fMaxMult,"s");   
1623    fIntFlowSquaredCorrelationsVsMPro[ci]->Sumw2();                                                                                              
1624    fIntFlowSquaredCorrelationsVsMPro[ci]->GetYaxis()->SetTitle(squaredCorrelationFlag[ci].Data());
1625    fIntFlowSquaredCorrelationsVsMPro[ci]->GetXaxis()->SetTitle("M");
1626    fIntFlowProfiles->Add(fIntFlowSquaredCorrelationsVsMPro[ci]);
1627   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
1628  } // end of if(fCalculateCumulantsVsM)
1629  // averaged all correlations for all events (with wrong errors!):
1630  TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
1631  intFlowCorrelationsAllProName += fAnalysisLabel->Data();
1632  fIntFlowCorrelationsAllPro = new TProfile(intFlowCorrelationsAllProName.Data(),"Average correlations for all events",34,0,34,"s");
1633  fIntFlowCorrelationsAllPro->SetTickLength(-0.01,"Y");
1634  fIntFlowCorrelationsAllPro->SetMarkerStyle(25);
1635  fIntFlowCorrelationsAllPro->SetLabelSize(0.03);
1636  fIntFlowCorrelationsAllPro->SetLabelOffset(0.01,"Y");
1637  // 2-p correlations:
1638  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1639  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1640  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1641  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1642  // 3-p correlations:
1643  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1644  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1645  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1646  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1647  // 4-p correlations:
1648  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1649  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1650  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1651  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1652  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1653  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1654  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1655  // 5-p correlations:
1656  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1657  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1658  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1659  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1660  // 6-p correlations:
1661  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1662  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1663  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1664  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1665  // 7-p correlations:  
1666  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1667  // 8-p correlations:
1668  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1669  // EXTRA correlations:
1670  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(33,"<<4>>_{4n,2n|3n,3n}");
1671  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(34,"<<5>>_{2n,2n,2n|3n,3n}");
1672  fIntFlowProfiles->Add(fIntFlowCorrelationsAllPro);
1673  // when particle weights are used some extra correlations appear:
1674  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) 
1675  {
1676   TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
1677   intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
1678   fIntFlowExtraCorrelationsPro = new TProfile(intFlowExtraCorrelationsProName.Data(),"Average extra correlations for all events",100,0,100,"s");
1679   fIntFlowExtraCorrelationsPro->SetTickLength(-0.01,"Y");
1680   fIntFlowExtraCorrelationsPro->SetMarkerStyle(25);
1681   fIntFlowExtraCorrelationsPro->SetLabelSize(0.03);
1682   fIntFlowExtraCorrelationsPro->SetLabelOffset(0.01,"Y");
1683   // extra 2-p correlations:
1684   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(1,"<<w1^3 w2 cos(n*(phi1-phi2))>>");
1685   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(2,"<<w1 w2 w3^2 cos(n*(phi1-phi2))>>");
1686   fIntFlowProfiles->Add(fIntFlowExtraCorrelationsPro);
1687  } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
1688  // average product of correlations <2>, <4>, <6> and <8>:  
1689  TString productFlag[6] = {"<<2><4>>","<<2><6>>","<<2><8>>","<<4><6>>","<<4><8>>","<<6><8>>"};
1690  TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
1691  intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
1692  fIntFlowProductOfCorrelationsPro = new TProfile(intFlowProductOfCorrelationsProName.Data(),"Average products of correlations",6,0,6);
1693  fIntFlowProductOfCorrelationsPro->SetTickLength(-0.01,"Y");
1694  fIntFlowProductOfCorrelationsPro->SetMarkerStyle(25); 
1695  fIntFlowProductOfCorrelationsPro->SetLabelSize(0.05);
1696  fIntFlowProductOfCorrelationsPro->SetLabelOffset(0.01,"Y");
1697  for(Int_t b=0;b<6;b++)
1698  {
1699   (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(b+1,productFlag[b].Data());
1700  }
1701  fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsPro); 
1702  // average product of correlations <2>, <4>, <6> and <8> versus multiplicity
1703  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
1704  if(fCalculateCumulantsVsM)
1705  {
1706   TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
1707   intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
1708   for(Int_t pi=0;pi<6;pi++)
1709   { 
1710    fIntFlowProductOfCorrelationsVsMPro[pi] = new TProfile(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data()),
1711                                                           Form("%s versus multiplicity",productFlag[pi].Data()),
1712                                                           fnBinsMult,fMinMult,fMaxMult);             
1713    fIntFlowProductOfCorrelationsVsMPro[pi]->GetXaxis()->SetTitle("M");
1714    fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsVsMPro[pi]);
1715   } // end of for(Int_t pi=0;pi<6;pi++)
1716  } // end of if(fCalculateCumulantsVsM) 
1717  // average product of correction terms for NUA:  
1718  TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
1719  intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
1720  fIntFlowProductOfCorrectionTermsForNUAPro = new TProfile(intFlowProductOfCorrectionTermsForNUAProName.Data(),"Average products of correction terms for NUA",27,0,27);
1721  fIntFlowProductOfCorrectionTermsForNUAPro->SetTickLength(-0.01,"Y");
1722  fIntFlowProductOfCorrectionTermsForNUAPro->SetMarkerStyle(25); 
1723  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelSize(0.05);
1724  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelOffset(0.01,"Y");
1725  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(1,"<<2><cos(#phi)>>");
1726  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(2,"<<2><sin(#phi)>>");
1727  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(3,"<<cos(#phi)><sin(#phi)>>");
1728  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
1729  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
1730  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1731  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1732  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
1733  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
1734  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
1735  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
1736  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1737  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1738  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
1739  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1740  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1741  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1742  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
1743  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1744  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1745  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1746  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
1747  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1748  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1749  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1750  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1751  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
1752  fIntFlowProfiles->Add(fIntFlowProductOfCorrectionTermsForNUAPro);
1753  // average correction terms for non-uniform acceptance (with wrong errors!):
1754  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1755  {
1756   TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
1757   intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
1758   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");
1759   fIntFlowCorrectionTermsForNUAPro[sc]->SetTickLength(-0.01,"Y");
1760   fIntFlowCorrectionTermsForNUAPro[sc]->SetMarkerStyle(25);
1761   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelSize(0.03);
1762   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelOffset(0.01,"Y");
1763   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(1,Form("#LT#LT%s(n(phi1))#GT#GT",sinCosFlag[sc].Data()));
1764   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(2,Form("#LT#LT%s(n(phi1+phi2))#GT#GT",sinCosFlag[sc].Data()));  
1765   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(3,Form("#LT#LT%s(n(phi1-phi2-phi3))#GT#GT",sinCosFlag[sc].Data()));  
1766   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(4,Form("#LT#LT%s(n(2phi1-phi2))#GT#GT",sinCosFlag[sc].Data()));  
1767   fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAPro[sc]);
1768   // versus multiplicity:
1769   if(fCalculateCumulantsVsM)
1770   {
1771    TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
1772    for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
1773    {
1774     TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
1775     intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
1776     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");
1777     fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAVsMPro[sc][ci]);
1778    }
1779   } // end of if(fCalculateCumulantsVsM)
1780  } // end of for(Int_t sc=0;sc<2;sc++) 
1781  
1782  // d) Book histograms holding the final results:
1783  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!):
1784  TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
1785  intFlowCorrelationsHistName += fAnalysisLabel->Data();
1786  fIntFlowCorrelationsHist = new TH1D(intFlowCorrelationsHistName.Data(),"Average correlations for all events",4,0,4);
1787  fIntFlowCorrelationsHist->SetTickLength(-0.01,"Y");
1788  fIntFlowCorrelationsHist->SetMarkerStyle(25);
1789  fIntFlowCorrelationsHist->SetLabelSize(0.06);
1790  fIntFlowCorrelationsHist->SetLabelOffset(0.01,"Y");
1791  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(1,"<<2>>");
1792  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(2,"<<4>>");
1793  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(3,"<<6>>");
1794  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(4,"<<8>>");
1795  fIntFlowResults->Add(fIntFlowCorrelationsHist);
1796  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!) vs M:
1797  if(fCalculateCumulantsVsM)
1798  {
1799   for(Int_t ci=0;ci<4;ci++) // correlation index
1800   {
1801    TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
1802    intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
1803    fIntFlowCorrelationsVsMHist[ci] = new TH1D(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data()),
1804                                               Form("%s vs multiplicity",correlationFlag[ci].Data()),
1805                                               fnBinsMult,fMinMult,fMaxMult);                                            
1806    fIntFlowCorrelationsVsMHist[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
1807    fIntFlowCorrelationsVsMHist[ci]->GetXaxis()->SetTitle("M");
1808    fIntFlowResults->Add(fIntFlowCorrelationsVsMHist[ci]);
1809   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
1810  } // end of if(fCalculateCumulantsVsM) 
1811  // average all correlations for all events (with correct errors!):
1812  TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
1813  intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
1814  fIntFlowCorrelationsAllHist = new TH1D(intFlowCorrelationsAllHistName.Data(),"Average correlations for all events",34,0,34);
1815  fIntFlowCorrelationsAllHist->SetTickLength(-0.01,"Y");
1816  fIntFlowCorrelationsAllHist->SetMarkerStyle(25);
1817  fIntFlowCorrelationsAllHist->SetLabelSize(0.03);
1818  fIntFlowCorrelationsAllHist->SetLabelOffset(0.01,"Y");
1819  // 2-p correlations:
1820  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1821  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1822  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1823  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1824  // 3-p correlations:
1825  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1826  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1827  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1828  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1829  // 4-p correlations:
1830  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1831  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1832  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1833  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1834  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1835  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1836  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1837  // 5-p correlations:
1838  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1839  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1840  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1841  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1842  // 6-p correlations:
1843  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1844  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1845  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1846  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1847  // 7-p correlations:  
1848  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1849  // 8-p correlations:
1850  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1851  fIntFlowResults->Add(fIntFlowCorrelationsAllHist);
1852  // average correction terms for non-uniform acceptance (with correct errors!):
1853  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1854  {
1855   TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
1856   intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
1857   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);
1858   fIntFlowCorrectionTermsForNUAHist[sc]->SetTickLength(-0.01,"Y");
1859   fIntFlowCorrectionTermsForNUAHist[sc]->SetMarkerStyle(25);
1860   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelSize(0.03);
1861   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelOffset(0.01,"Y");
1862   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(1,Form("#LT#LT%s(n(#phi_{1}))#GT#GT",sinCosFlag[sc].Data()));
1863   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(2,Form("#LT#LT%s(n(phi1+phi2))#GT#GT",sinCosFlag[sc].Data()));  
1864   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(3,Form("#LT#LT%s(n(phi1-phi2-phi3))#GT#GT",sinCosFlag[sc].Data()));  
1865   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(4,Form("#LT#LT%s(n(2phi1-phi2))#GT#GT",sinCosFlag[sc].Data()));   
1866   fIntFlowResults->Add(fIntFlowCorrectionTermsForNUAHist[sc]);
1867  } // end of for(Int_t sc=0;sc<2;sc++) 
1868  // covariances (multiplied with weight dependent prefactor):
1869  TString intFlowCovariancesName = "fIntFlowCovariances";
1870  intFlowCovariancesName += fAnalysisLabel->Data();
1871  fIntFlowCovariances = new TH1D(intFlowCovariancesName.Data(),"Covariances (multiplied with weight dependent prefactor)",6,0,6);
1872  fIntFlowCovariances->SetLabelSize(0.04);
1873  fIntFlowCovariances->SetMarkerStyle(25);
1874  (fIntFlowCovariances->GetXaxis())->SetBinLabel(1,"Cov(<2>,<4>)");
1875  (fIntFlowCovariances->GetXaxis())->SetBinLabel(2,"Cov(<2>,<6>)");
1876  (fIntFlowCovariances->GetXaxis())->SetBinLabel(3,"Cov(<2>,<8>)");
1877  (fIntFlowCovariances->GetXaxis())->SetBinLabel(4,"Cov(<4>,<6>)");
1878  (fIntFlowCovariances->GetXaxis())->SetBinLabel(5,"Cov(<4>,<8>)");
1879  (fIntFlowCovariances->GetXaxis())->SetBinLabel(6,"Cov(<6>,<8>)");  
1880  fIntFlowResults->Add(fIntFlowCovariances);
1881  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
1882  TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
1883  intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
1884  for(Int_t power=0;power<2;power++)
1885  {
1886   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);
1887   fIntFlowSumOfEventWeights[power]->SetLabelSize(0.05);
1888   fIntFlowSumOfEventWeights[power]->SetMarkerStyle(25);
1889   if(power == 0)
1890   {
1891    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}");
1892    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}");
1893    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}");
1894    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}");
1895   } else if (power == 1) 
1896     {
1897      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}^{2}");
1898      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}^{2}");
1899      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}^{2}");
1900      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}^{2}");
1901     }
1902   fIntFlowResults->Add(fIntFlowSumOfEventWeights[power]);
1903  } 
1904  // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
1905  TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
1906  intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
1907  fIntFlowSumOfProductOfEventWeights = new TH1D(intFlowSumOfProductOfEventWeightsName.Data(),"Sum of product of event weights for correlations",6,0,6);
1908  fIntFlowSumOfProductOfEventWeights->SetLabelSize(0.05);
1909  fIntFlowSumOfProductOfEventWeights->SetMarkerStyle(25);
1910  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<4>}");
1911  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<6>}");
1912  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<2>} w_{<8>}");
1913  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<4>} w_{<6>}");
1914  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(5,"#sum_{i=1}^{N} w_{<4>} w_{<8>}");
1915  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(6,"#sum_{i=1}^{N} w_{<6>} w_{<8>}");
1916  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeights);
1917  // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
1918  // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
1919  if(fCalculateCumulantsVsM)
1920  {
1921   TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
1922   intFlowCovariancesVsMName += fAnalysisLabel->Data();
1923   TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
1924   for(Int_t ci=0;ci<6;ci++)
1925   {
1926    fIntFlowCovariancesVsM[ci] = new TH1D(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data()),
1927                                          Form("%s vs multiplicity",covarianceFlag[ci].Data()),
1928                                          fnBinsMult,fMinMult,fMaxMult);
1929    fIntFlowCovariancesVsM[ci]->GetYaxis()->SetTitle(covarianceFlag[ci].Data());
1930    fIntFlowCovariancesVsM[ci]->GetXaxis()->SetTitle("M");
1931    fIntFlowResults->Add(fIntFlowCovariancesVsM[ci]);
1932   }
1933  } // end of if(fCalculateCumulantsVsM) 
1934  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
1935  // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
1936  if(fCalculateCumulantsVsM)
1937  {
1938   TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
1939   intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
1940   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>}"},
1941                            {"#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}"}};
1942   for(Int_t si=0;si<4;si++)
1943   {
1944    for(Int_t power=0;power<2;power++)
1945    {
1946     fIntFlowSumOfEventWeightsVsM[si][power] = new TH1D(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data()),
1947                                                        Form("%s vs multiplicity",sumFlag[power][si].Data()),
1948                                                        fnBinsMult,fMinMult,fMaxMult);    
1949     fIntFlowSumOfEventWeightsVsM[si][power]->GetYaxis()->SetTitle(sumFlag[power][si].Data());  
1950     fIntFlowSumOfEventWeightsVsM[si][power]->GetXaxis()->SetTitle("M");  
1951     fIntFlowResults->Add(fIntFlowSumOfEventWeightsVsM[si][power]);
1952    } // end of for(Int_t power=0;power<2;power++)
1953   } // end of for(Int_t si=0;si<4;si++)   
1954  } // end of if(fCalculateCumulantsVsM)
1955  // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
1956  // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
1957  //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
1958  if(fCalculateCumulantsVsM)
1959  {
1960   TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
1961   intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
1962   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>}",
1963                           "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
1964   for(Int_t pi=0;pi<6;pi++)
1965   {
1966    fIntFlowSumOfProductOfEventWeightsVsM[pi] = new TH1D(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data()),
1967                                                         Form("%s versus multiplicity",sopowFlag[pi].Data()),
1968                                                         fnBinsMult,fMinMult,fMaxMult); 
1969    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetXaxis()->SetTitle("M");
1970    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetYaxis()->SetTitle(sopowFlag[pi].Data()); 
1971    fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsVsM[pi]);
1972   } // end of for(Int_t pi=0;pi<6;pi++) 
1973  } // end of if(fCalculateCumulantsVsM)
1974  // covariances of NUA terms (multiplied with weight dependent prefactor):
1975  TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
1976  intFlowCovariancesNUAName += fAnalysisLabel->Data();
1977  fIntFlowCovariancesNUA = new TH1D(intFlowCovariancesNUAName.Data(),"Covariances for NUA (multiplied with weight dependent prefactor)",27,0,27);
1978  fIntFlowCovariancesNUA->SetLabelSize(0.04);
1979  fIntFlowCovariancesNUA->SetMarkerStyle(25);
1980  fIntFlowCovariancesNUA->GetXaxis()->SetLabelSize(0.02);
1981  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(1,"Cov(<2>,<cos(#phi)>");
1982  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(2,"Cov(<2>,<sin(#phi)>)");
1983  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(3,"Cov(<cos(#phi)>,<sin(#phi)>)");
1984  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
1985  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
1986  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1987  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1988  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
1989  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
1990  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
1991  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
1992  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1993  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1994  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
1995  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1996  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1997  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1998  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
1999  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
2000  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2001  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2002  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
2003  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2004  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2005  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2006  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2007  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
2008  fIntFlowResults->Add(fIntFlowCovariancesNUA);
2009  // sum of linear and quadratic event weights for NUA terms:
2010  TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
2011  intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
2012  for(Int_t sc=0;sc<2;sc++)
2013  {
2014   for(Int_t power=0;power<2;power++)
2015   {
2016    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
2017    fIntFlowSumOfEventWeightsNUA[sc][power]->SetLabelSize(0.05);
2018    fIntFlowSumOfEventWeightsNUA[sc][power]->SetMarkerStyle(25);
2019    if(power == 0)
2020    {
2021     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}",sinCosFlag[sc].Data()));
2022     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}",sinCosFlag[sc].Data()));
2023     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}",sinCosFlag[sc].Data()));   
2024     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(4,Form("#sum_{i=1}^{N} w_{<%s(2#phi_{1}-#phi_{2})>}",sinCosFlag[sc].Data()));
2025    } else if(power == 1) 
2026      {
2027       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}^{2}",sinCosFlag[sc].Data()));
2028       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}^{2}",sinCosFlag[sc].Data()));
2029       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}^{2}",sinCosFlag[sc].Data()));
2030       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(4,Form("#sum_{i=1}^{N} w_{<%s(2#phi_{1}-#phi_{2})>}^{2}",sinCosFlag[sc].Data()));
2031      }
2032    fIntFlowResults->Add(fIntFlowSumOfEventWeightsNUA[sc][power]);
2033   }
2034  }  
2035  // sum of products of event weights for NUA terms:  
2036  TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
2037  intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
2038  fIntFlowSumOfProductOfEventWeightsNUA = new TH1D(intFlowSumOfProductOfEventWeightsNUAName.Data(),"Sum of product of event weights for NUA terms",27,0,27);
2039  fIntFlowSumOfProductOfEventWeightsNUA->SetLabelSize(0.05);
2040  fIntFlowSumOfProductOfEventWeightsNUA->SetMarkerStyle(25);
2041  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<cos(#phi)>}");
2042  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<sin(#phi)>}");
2043  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<cos(#phi)>} w_{<sin(#phi)>}");
2044  // ....
2045  // to be improved - add labels for remaining bins
2046  // ....
2047  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsNUA);
2048  // Final results for reference Q-cumulants:
2049  TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
2050  TString intFlowQcumulantsName = "fIntFlowQcumulants";
2051  intFlowQcumulantsName += fAnalysisLabel->Data();
2052  fIntFlowQcumulants = new TH1D(intFlowQcumulantsName.Data(),"Reference Q-cumulants",4,0,4);
2053  if(fPropagateErrorAlsoFromNIT)
2054  {
2055   fIntFlowQcumulants->SetTitle("Reference Q-cumulants (error from non-isotropic terms also propagated)");
2056  }
2057  fIntFlowQcumulants->SetLabelSize(0.05);
2058  fIntFlowQcumulants->SetMarkerStyle(25);
2059  for(Int_t b=0;b<4;b++)
2060  {
2061   (fIntFlowQcumulants->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2062  } 
2063  fIntFlowResults->Add(fIntFlowQcumulants);
2064  // Final results for reference Q-cumulants rebinned in M: 
2065  if(fCalculateCumulantsVsM)
2066  {
2067   TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
2068   intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
2069   fIntFlowQcumulantsRebinnedInM = new TH1D(intFlowQcumulantsRebinnedInMName.Data(),"Reference Q-cumulants rebinned in M",4,0,4);
2070   fIntFlowQcumulantsRebinnedInM->SetLabelSize(0.05);
2071   fIntFlowQcumulantsRebinnedInM->SetMarkerStyle(25);
2072   for(Int_t b=0;b<4;b++)
2073   {
2074    (fIntFlowQcumulantsRebinnedInM->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2075   } 
2076   fIntFlowResults->Add(fIntFlowQcumulantsRebinnedInM);
2077  } // end of if(fCalculateCumulantsVsM) 
2078  // Ratio between error squared: with/without non-isotropic terms:
2079  TString intFlowQcumulantsErrorSquaredRatioName = "fIntFlowQcumulantsErrorSquaredRatio";
2080  intFlowQcumulantsErrorSquaredRatioName += fAnalysisLabel->Data();
2081  fIntFlowQcumulantsErrorSquaredRatio = new TH1D(intFlowQcumulantsErrorSquaredRatioName.Data(),"Error squared of reference Q-cumulants: #frac{with NUA terms}{without NUA terms}",4,0,4);
2082  fIntFlowQcumulantsErrorSquaredRatio->SetLabelSize(0.05);
2083  fIntFlowQcumulantsErrorSquaredRatio->SetMarkerStyle(25);
2084  for(Int_t b=0;b<4;b++)
2085  {
2086   (fIntFlowQcumulantsErrorSquaredRatio->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2087  } 
2088  fIntFlowResults->Add(fIntFlowQcumulantsErrorSquaredRatio);
2089  // final results for integrated Q-cumulants versus multiplicity:
2090  if(fCalculateCumulantsVsM)
2091  {
2092   TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
2093   intFlowQcumulantsVsMName += fAnalysisLabel->Data();
2094   for(Int_t co=0;co<4;co++) // cumulant order
2095   {
2096    fIntFlowQcumulantsVsM[co] = new TH1D(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data()),
2097                                         Form("%s vs multipicity",cumulantFlag[co].Data()),
2098                                         fnBinsMult,fMinMult,fMaxMult);
2099    fIntFlowQcumulantsVsM[co]->GetXaxis()->SetTitle("M");                                     
2100    fIntFlowQcumulantsVsM[co]->GetYaxis()->SetTitle(cumulantFlag[co].Data());  
2101    fIntFlowResults->Add(fIntFlowQcumulantsVsM[co]);                                    
2102   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2103  } // end of if(fCalculateCumulantsVsM)
2104  // final integrated flow estimates from Q-cumulants:
2105  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)};
2106  TString intFlowName = "fIntFlow";
2107  intFlowName += fAnalysisLabel->Data();  
2108  // integrated flow from Q-cumulants:
2109  fIntFlow = new TH1D(intFlowName.Data(),"Reference flow estimates from Q-cumulants",4,0,4);
2110  fIntFlow->SetLabelSize(0.05);
2111  fIntFlow->SetMarkerStyle(25);
2112  for(Int_t b=0;b<4;b++)
2113  {
2114   (fIntFlow->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2115  }
2116  fIntFlowResults->Add(fIntFlow); 
2117  // Reference flow vs M rebinned in one huge bin:
2118  if(fCalculateCumulantsVsM)
2119  { 
2120   TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
2121   intFlowRebinnedInMName += fAnalysisLabel->Data();  
2122   fIntFlowRebinnedInM = new TH1D(intFlowRebinnedInMName.Data(),"Reference flow estimates from Q-cumulants (rebinned in M)",4,0,4);
2123   fIntFlowRebinnedInM->SetLabelSize(0.05);
2124   fIntFlowRebinnedInM->SetMarkerStyle(25);
2125   for(Int_t b=0;b<4;b++)
2126   {
2127    (fIntFlowRebinnedInM->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2128   }
2129   fIntFlowResults->Add(fIntFlowRebinnedInM); 
2130  } 
2131  // integrated flow from Q-cumulants: versus multiplicity:
2132  if(fCalculateCumulantsVsM)
2133  {
2134   TString intFlowVsMName = "fIntFlowVsM";
2135   intFlowVsMName += fAnalysisLabel->Data();
2136   for(Int_t co=0;co<4;co++) // cumulant order
2137   {
2138    fIntFlowVsM[co] = new TH1D(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data()),
2139                               Form("%s vs multipicity",flowFlag[co].Data()),
2140                               fnBinsMult,fMinMult,fMaxMult);
2141    fIntFlowVsM[co]->GetXaxis()->SetTitle("M");                                     
2142    fIntFlowVsM[co]->GetYaxis()->SetTitle(flowFlag[co].Data());  
2143    fIntFlowResults->Add(fIntFlowVsM[co]);                                    
2144   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2145  } // end of if(fCalculateCumulantsVsM)
2146  // quantifying detector effects effects to correlations:
2147  TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
2148  intFlowDetectorBiasName += fAnalysisLabel->Data();  
2149  fIntFlowDetectorBias = new TH1D(intFlowDetectorBiasName.Data(),"Quantifying detector bias",4,0,4);
2150  fIntFlowDetectorBias->SetLabelSize(0.05);
2151  fIntFlowDetectorBias->SetMarkerStyle(25);
2152  for(Int_t ci=0;ci<4;ci++)
2153  {  
2154   (fIntFlowDetectorBias->GetXaxis())->SetBinLabel(ci+1,Form("#frac{corrected}{measured} %s",cumulantFlag[ci].Data()));
2155  }
2156  fIntFlowResults->Add(fIntFlowDetectorBias); 
2157  // quantifying detector effects to correlations versus multiplicity:
2158  if(fCalculateCumulantsVsM)
2159  {
2160   TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
2161   intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
2162   for(Int_t ci=0;ci<4;ci++) // correlation index
2163   {
2164    fIntFlowDetectorBiasVsM[ci] = new TH1D(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data()),
2165                                           Form("Quantifying detector bias for %s vs multipicity",cumulantFlag[ci].Data()),
2166                                           fnBinsMult,fMinMult,fMaxMult);
2167    fIntFlowDetectorBiasVsM[ci]->GetXaxis()->SetTitle("M");                                     
2168    fIntFlowDetectorBiasVsM[ci]->GetYaxis()->SetTitle("#frac{corrected}{measured}");  
2169    fIntFlowResults->Add(fIntFlowDetectorBiasVsM[ci]);                                    
2170   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2171  } // end of if(fCalculateCumulantsVsM)
2172  
2173  /* // to be improved (removed):
2174   // final average weighted multi-particle correlations for all events calculated from Q-vectors
2175   fQCorrelations[1] = new TProfile("Weighted correlations","final average multi-particle correlations from weighted Q-vectors",200,0,200,"s");
2176   fQCorrelations[1]->SetTickLength(-0.01,"Y");
2177   fQCorrelations[1]->SetMarkerStyle(25);
2178   fQCorrelations[1]->SetLabelSize(0.03);
2179   fQCorrelations[1]->SetLabelOffset(0.01,"Y");
2180   // 2-particle correlations:
2181   (fQCorrelations[1]->GetXaxis())->SetBinLabel(1,"<w_{1}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
2182   (fQCorrelations[1]->GetXaxis())->SetBinLabel(2,"<w_{1}^{2}w_{2}^{2}cos(2n(#phi_{1}-#phi_{2}))>");
2183   (fQCorrelations[1]->GetXaxis())->SetBinLabel(3,"<w_{1}^{3}w_{2}^{3}cos(3n(#phi_{1}-#phi_{2}))>");
2184   (fQCorrelations[1]->GetXaxis())->SetBinLabel(4,"<w_{1}^{4}w_{2}^{4}cos(4n(#phi_{1}-#phi_{2}))>");
2185   (fQCorrelations[1]->GetXaxis())->SetBinLabel(5,"<w_{1}^{3}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
2186   (fQCorrelations[1]->GetXaxis())->SetBinLabel(6,"<w_{1}^{2}w_{2}w_{3}cos(n(#phi_{1}-#phi_{2}))>");
2187   // 3-particle correlations:
2188   (fQCorrelations[1]->GetXaxis())->SetBinLabel(21,"<w_{1}w_{2}w_{3}^{2}cos(n(2#phi_{1}-#phi_{2}-#phi_{3}))>");
2189   // 4-particle correlations:
2190   (fQCorrelations[1]->GetXaxis())->SetBinLabel(41,"<w_{1}w_{2}w_{3}w_{4}cos(n(#phi_{1}+#phi_{2}-#phi_{3}-#phi_{4}))>");
2191   // add fQCorrelations[1] to the list fIntFlowList:
2192   fIntFlowList->Add(fQCorrelations[1]); 
2193  */
2194   
2195 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
2196
2197
2198 //================================================================================================================================
2199
2200
2201 void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2202 {
2203  // Initialize arrays of all objects relevant for calculations with nested loops.
2204  
2205  // integrated flow:
2206  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2207  {
2208   fIntFlowDirectCorrectionTermsForNUA[sc] = NULL;
2209  } 
2210
2211  // differential flow:  
2212  // correlations:
2213  for(Int_t t=0;t<2;t++) // type: RP or POI
2214  { 
2215   for(Int_t pe=0;pe<2;pe++) // pt or eta
2216   {
2217    for(Int_t ci=0;ci<4;ci++) // correlation index
2218    {
2219     fDiffFlowDirectCorrelations[t][pe][ci] = NULL;
2220    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
2221   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2222  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2223  // correction terms for non-uniform acceptance:
2224  for(Int_t t=0;t<2;t++) // type: RP or POI
2225  { 
2226   for(Int_t pe=0;pe<2;pe++) // pt or eta
2227   {
2228    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2229    {
2230     for(Int_t cti=0;cti<9;cti++) // correction term index
2231     {
2232      fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] = NULL;
2233     }   
2234    }
2235   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2236  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2237
2238
2239 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2240
2241
2242 //================================================================================================================================
2243
2244
2245 void AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2246 {
2247  // Book all objects relevant for calculations with nested loops.
2248  
2249  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
2250  TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
2251  TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
2252  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
2253  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
2254  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
2255
2256  TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
2257  evaluateNestedLoopsName += fAnalysisLabel->Data();
2258  fEvaluateNestedLoops = new TProfile(evaluateNestedLoopsName.Data(),"Flags for nested loops",4,0,4);
2259  fEvaluateNestedLoops->SetLabelSize(0.03);
2260  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(1,"fEvaluateIntFlowNestedLoops");
2261  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(2,"fEvaluateDiffFlowNestedLoops");
2262  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(3,"fCrossCheckInPtBinNo");
2263  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(4,"fCrossCheckInEtaBinNo");
2264  fEvaluateNestedLoops->Fill(0.5,(Int_t)fEvaluateIntFlowNestedLoops);
2265  fEvaluateNestedLoops->Fill(1.5,(Int_t)fEvaluateDiffFlowNestedLoops);
2266  fEvaluateNestedLoops->Fill(2.5,fCrossCheckInPtBinNo);
2267  fEvaluateNestedLoops->Fill(3.5,fCrossCheckInEtaBinNo);
2268  fNestedLoopsList->Add(fEvaluateNestedLoops);
2269  // nested loops for integrated flow:
2270  if(fEvaluateIntFlowNestedLoops)
2271  {
2272   // correlations:
2273   TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
2274   intFlowDirectCorrelationsName += fAnalysisLabel->Data();
2275   fIntFlowDirectCorrelations = new TProfile(intFlowDirectCorrelationsName.Data(),"Multiparticle correlations calculated with nested loops (for int. flow)",34,0,34,"s");
2276   fNestedLoopsList->Add(fIntFlowDirectCorrelations);
2277   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
2278   {
2279    TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
2280    intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
2281    fIntFlowExtraDirectCorrelations = new TProfile(intFlowExtraDirectCorrelationsName.Data(),"Extra multiparticle correlations calculated with nested loops (for int. flow)",100,0,100,"s");
2282    fNestedLoopsList->Add(fIntFlowExtraDirectCorrelations);  
2283   } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
2284   // correction terms for non-uniform acceptance:
2285   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2286   {
2287    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
2288    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2289    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");
2290    fNestedLoopsList->Add(fIntFlowDirectCorrectionTermsForNUA[sc]);
2291   } // end of for(Int_t sc=0;sc<2;sc++) 
2292  } // end of if(fEvaluateIntFlowNestedLoops)
2293  
2294  // nested loops for differential flow: 
2295  if(fEvaluateDiffFlowNestedLoops)
2296  {
2297   // reduced correlations:
2298   TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
2299   diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
2300   for(Int_t t=0;t<2;t++) // type: RP or POI
2301   { 
2302    for(Int_t pe=0;pe<2;pe++) // pt or eta
2303    {
2304     for(Int_t rci=0;rci<4;rci++) // reduced correlation index
2305     {
2306      // reduced correlations:
2307      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");
2308      fDiffFlowDirectCorrelations[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
2309      fNestedLoopsList->Add(fDiffFlowDirectCorrelations[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
2310     } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
2311    } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
2312   } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
2313   // correction terms for non-uniform acceptance:
2314   TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
2315   diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2316   for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
2317   { 
2318    for(Int_t pe=0;pe<2;pe++) // pt or eta
2319    {
2320     for(Int_t sc=0;sc<2;sc++) // sin or cos
2321     {
2322      for(Int_t cti=0;cti<9;cti++) // correction term index
2323      {
2324       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"); 
2325       fNestedLoopsList->Add(fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]);
2326      }
2327     }
2328    }
2329   } 
2330   // number of RPs and POIs in selected pt and eta bins for cross-checkings:
2331   TString noOfParticlesInBinName = "fNoOfParticlesInBin";
2332   fNoOfParticlesInBin = new TH1D(noOfParticlesInBinName.Data(),"Number of RPs and POIs in selected p_{T} and #eta bin",4,0,4);
2333   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(1,"# of RPs in p_{T} bin");
2334   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(2,"# of RPs in #eta bin");
2335   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(3,"# of POIs in p_{T} bin");
2336   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(4,"# of POIs in #eta bin");
2337   fNestedLoopsList->Add(fNoOfParticlesInBin);
2338  } // end of if(fEvaluateDiffFlowNestedLoops)
2339
2340 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2341
2342
2343 //================================================================================================================================
2344
2345
2346 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
2347 {
2348  // calculate all correlations needed for integrated flow
2349  
2350  // multiplicity:
2351  Double_t dMult = (*fSMpk)(0,0);
2352  
2353  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
2354  Double_t dReQ1n = (*fReQ)(0,0);
2355  Double_t dReQ2n = (*fReQ)(1,0);
2356  Double_t dReQ3n = (*fReQ)(2,0);
2357  Double_t dReQ4n = (*fReQ)(3,0);
2358  //Double_t dReQ5n = (*fReQ)(4,0);
2359  Double_t dReQ6n = (*fReQ)(5,0);
2360  Double_t dImQ1n = (*fImQ)(0,0);
2361  Double_t dImQ2n = (*fImQ)(1,0);
2362  Double_t dImQ3n = (*fImQ)(2,0);
2363  Double_t dImQ4n = (*fImQ)(3,0);
2364  //Double_t dImQ5n = (*fImQ)(4,0);
2365  Double_t dImQ6n = (*fImQ)(5,0);
2366   
2367  // real and imaginary parts of some expressions involving various combinations of Q-vectors evaluated in harmonics n, 2n, 3n and 4n:
2368  // (these expression appear in the Eqs. for the multi-particle correlations bellow)
2369  
2370  // Re[Q_{2n} Q_{n}^* Q_{n}^*]
2371  Double_t reQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dReQ2n + 2.*dReQ1n*dImQ1n*dImQ2n - pow(dImQ1n,2.)*dReQ2n; 
2372  
2373  // Im[Q_{2n} Q_{n}^* Q_{n}^*]
2374  //Double_t imQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dImQ2n-2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n; 
2375  
2376  // Re[Q_{n} Q_{n} Q_{2n}^*] = Re[Q_{2n} Q_{n}^* Q_{n}^*]
2377  Double_t reQ1nQ1nQ2nstar = reQ2nQ1nstarQ1nstar; 
2378  
2379  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
2380  Double_t reQ3nQ1nQ2nstarQ2nstar = (pow(dReQ2n,2.)-pow(dImQ2n,2.))*(dReQ3n*dReQ1n-dImQ3n*dImQ1n) 
2381                                  + 2.*dReQ2n*dImQ2n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
2382
2383  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]                                                                  
2384  //Double_t imQ3nQ1nQ2nstarQ2nstar = calculate and implement this (deleteMe)
2385   
2386  // Re[Q_{2n} Q_{2n} Q_{3n}^* Q_{1n}^*] = Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
2387  Double_t reQ2nQ2nQ3nstarQ1nstar = reQ3nQ1nQ2nstarQ2nstar;
2388   
2389  // Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
2390  Double_t reQ4nQ2nstarQ2nstar = pow(dReQ2n,2.)*dReQ4n+2.*dReQ2n*dImQ2n*dImQ4n-pow(dImQ2n,2.)*dReQ4n;
2391
2392  // Im[Q_{4n} Q_{2n}^* Q_{2n}^*]
2393  //Double_t imQ4nQ2nstarQ2nstar = calculate and implement this (deleteMe)
2394  
2395  // Re[Q_{2n} Q_{2n} Q_{4n}^*] =  Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
2396  Double_t reQ2nQ2nQ4nstar = reQ4nQ2nstarQ2nstar;
2397  
2398  // Re[Q_{4n} Q_{3n}^* Q_{n}^*]
2399  Double_t reQ4nQ3nstarQ1nstar = dReQ4n*(dReQ3n*dReQ1n-dImQ3n*dImQ1n)+dImQ4n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
2400  
2401  // Re[Q_{3n} Q_{n} Q_{4n}^*] = Re[Q_{4n} Q_{3n}^* Q_{n}^*]
2402  Double_t reQ3nQ1nQ4nstar = reQ4nQ3nstarQ1nstar;
2403  
2404  // Im[Q_{4n} Q_{3n}^* Q_{n}^*]
2405  //Double_t imQ4nQ3nstarQ1nstar = calculate and implement this (deleteMe)
2406
2407  // Re[Q_{3n} Q_{2n}^* Q_{n}^*]
2408  Double_t reQ3nQ2nstarQ1nstar = dReQ3n*dReQ2n*dReQ1n-dReQ3n*dImQ2n*dImQ1n+dImQ3n*dReQ2n*dImQ1n
2409                               + dImQ3n*dImQ2n*dReQ1n;
2410                               
2411  // Re[Q_{2n} Q_{n} Q_{3n}^*] = Re[Q_{3n} Q_{2n}^* Q_{n}^*]
2412  Double_t reQ2nQ1nQ3nstar = reQ3nQ2nstarQ1nstar;
2413  
2414  // Im[Q_{3n} Q_{2n}^* Q_{n}^*]
2415  //Double_t imQ3nQ2nstarQ1nstar; //calculate and implement this (deleteMe)
2416  
2417  // Re[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2418  Double_t reQ3nQ1nstarQ1nstarQ1nstar = dReQ3n*pow(dReQ1n,3)-3.*dReQ1n*dReQ3n*pow(dImQ1n,2)
2419                                      + 3.*dImQ1n*dImQ3n*pow(dReQ1n,2)-dImQ3n*pow(dImQ1n,3);
2420
2421  // Im[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2422  //Double_t imQ3nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2423  
2424  // |Q_{2n}|^2 |Q_{n}|^2
2425  Double_t dQ2nQ1nQ2nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
2426  
2427  // Re[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2428  Double_t reQ4nQ2nstarQ1nstarQ1nstar = (dReQ4n*dReQ2n+dImQ4n*dImQ2n)*(pow(dReQ1n,2)-pow(dImQ1n,2))
2429                                      + 2.*dReQ1n*dImQ1n*(dImQ4n*dReQ2n-dReQ4n*dImQ2n); 
2430  
2431  // Im[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2432  //Double_t imQ4nQ2nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2433  
2434  // Re[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*]
2435  Double_t reQ2nQ1nQ1nstarQ1nstarQ1nstar = (dReQ2n*dReQ1n-dImQ2n*dImQ1n)*(pow(dReQ1n,3)-3.*dReQ1n*pow(dImQ1n,2))
2436                                         + (dReQ2n*dImQ1n+dReQ1n*dImQ2n)*(3.*dImQ1n*pow(dReQ1n,2)-pow(dImQ1n,3));
2437
2438  // Im[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*] 
2439  //Double_t imQ2nQ1nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2440  
2441  // Re[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2442  Double_t reQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2443                                         * (dReQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) + 2.*dImQ2n*dReQ1n*dImQ1n);
2444
2445  // Im[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2446  //Double_t imQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2447  //                                       * (dImQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) - 2.*dReQ2n*dReQ1n*dImQ1n);
2448  
2449  // Re[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2450  Double_t reQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dReQ4n-6.*pow(dReQ1n,2.)*dReQ4n*pow(dImQ1n,2.)
2451                                             + pow(dImQ1n,4.)*dReQ4n+4.*pow(dReQ1n,3.)*dImQ1n*dImQ4n
2452                                             - 4.*pow(dImQ1n,3.)*dReQ1n*dImQ4n;
2453                                             
2454  // Im[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2455  //Double_t imQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dImQ4n-6.*pow(dReQ1n,2.)*dImQ4n*pow(dImQ1n,2.)
2456  //                                           + pow(dImQ1n,4.)*dImQ4n+4.*pow(dImQ1n,3.)*dReQ1n*dReQ4n
2457  //                                           - 4.*pow(dReQ1n,3.)*dImQ1n*dReQ4n;
2458  
2459  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2460  Double_t reQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2461                                         * (dReQ1n*dReQ2n*dReQ3n-dReQ3n*dImQ1n*dImQ2n+dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n);
2462  
2463  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2464  //Double_t imQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2465  //                                       * (-dReQ2n*dReQ3n*dImQ1n-dReQ1n*dReQ3n*dImQ2n+dReQ1n*dReQ2n*dImQ3n-dImQ1n*dImQ2n*dImQ3n);
2466  
2467  
2468  // Re[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2469  Double_t reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)*dReQ2n-2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2470                                                + dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n-pow(dImQ1n,2.)*dImQ2n)
2471                                                * (pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2472                                                - dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n+pow(dImQ1n,2.)*dImQ2n);
2473  
2474  // Im[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2475  //Double_t imQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = 2.*(pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2476  //                                              + 2.*dReQ1n*dImQ1n*dImQ2n)*(pow(dReQ1n,2.)*dImQ2n
2477  //                                              - 2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n);
2478  
2479  // Re[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2480  Double_t reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2481                                                * (pow(dReQ1n,3.)*dReQ3n-3.*dReQ1n*dReQ3n*pow(dImQ1n,2.)
2482                                                + 3.*pow(dReQ1n,2.)*dImQ1n*dImQ3n-pow(dImQ1n,3.)*dImQ3n);
2483   
2484  // Im[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                                                           
2485  //Double_t imQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2486  //                                              * (pow(dImQ1n,3.)*dReQ3n-3.*dImQ1n*dReQ3n*pow(dReQ1n,2.)
2487  //                                              - 3.*pow(dImQ1n,2.)*dReQ1n*dImQ3n+pow(dReQ1n,3.)*dImQ3n);
2488  
2489  // |Q_{2n}|^2 |Q_{n}|^4
2490  Double_t dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.);
2491  
2492  // Re[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2493  Double_t reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2494                                                   * (pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2495                                                   + 2.*dReQ1n*dImQ1n*dImQ2n);
2496                                                   
2497  // Im[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                  
2498  //Double_t imQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2499  //                                                 * (pow(dReQ1n,2.)*dImQ2n-dImQ2n*pow(dImQ1n,2.)
2500  //                                                 - 2.*dReQ1n*dReQ2n*dImQ1n);
2501  
2502   
2503  
2504        
2505  //                                        **************************************
2506  //                                        **** multi-particle correlations: ****
2507  //                                        **************************************
2508  //
2509  // Remark 1: All multi-particle correlations calculated with non-weighted Q-vectors are stored in 1D profile fIntFlowCorrelationsAllPro;
2510  // Remark 2: There is a special profile fIntFlowCorrelationsPro holding results ONLY for same harmonic's <<2>>, <<4>>, <<6>> and <<8>>;  
2511  // Remark 3: Binning of fIntFlowCorrelationsAllPro is organized as follows:
2512  // --------------------------------------------------------------------------------------------------------------------
2513  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
2514  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
2515  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
2516  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
2517  //  5th bin:           ----  EMPTY ----
2518  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
2519  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
2520  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2521  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
2522  // 10th bin:           ----  EMPTY ----
2523  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
2524  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
2525  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
2526  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2527  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
2528  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
2529  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
2530  // 18th bin:           ----  EMPTY ----
2531  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2532  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2533  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2534  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2535  // 23rd bin:           ----  EMPTY ----
2536  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2537  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2538  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2539  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2540  // 28th bin:           ----  EMPTY ----
2541  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2542  // 30th bin:           ----  EMPTY ----
2543  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2544  // 32nd bin:           ----  EMPTY ----
2545  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
2546  // 34th bin: <5>_{2n,2n,2n|3n,3n} = five2n2n2n3n3n = <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))> 
2547  // --------------------------------------------------------------------------------------------------------------------
2548     
2549  // 2-particle:
2550  Double_t two1n1n = 0.; // <cos(n*(phi1-phi2))>
2551  Double_t two2n2n = 0.; // <cos(2n*(phi1-phi2))>
2552  Double_t two3n3n = 0.; // <cos(3n*(phi1-phi2))>
2553  Double_t two4n4n = 0.; // <cos(4n*(phi1-phi2))>
2554  
2555  if(dMult>1)
2556  {
2557   two1n1n = (pow(dReQ1n,2.)+pow(dImQ1n,2.)-dMult)/(dMult*(dMult-1.)); 
2558   two2n2n = (pow(dReQ2n,2.)+pow(dImQ2n,2.)-dMult)/(dMult*(dMult-1.)); 
2559   two3n3n = (pow(dReQ3n,2.)+pow(dImQ3n,2.)-dMult)/(dMult*(dMult-1.)); 
2560   two4n4n = (pow(dReQ4n,2.)+pow(dImQ4n,2.)-dMult)/(dMult*(dMult-1.)); 
2561   
2562   // average 2-particle correlations for single event: 
2563   fIntFlowCorrelationsAllEBE->SetBinContent(1,two1n1n);
2564   fIntFlowCorrelationsAllEBE->SetBinContent(2,two2n2n);
2565   fIntFlowCorrelationsAllEBE->SetBinContent(3,two3n3n);
2566   fIntFlowCorrelationsAllEBE->SetBinContent(4,two4n4n);
2567           
2568   // average 2-particle correlations for all events:      
2569   fIntFlowCorrelationsAllPro->Fill(0.5,two1n1n,dMult*(dMult-1.));  
2570   fIntFlowCorrelationsAllPro->Fill(1.5,two2n2n,dMult*(dMult-1.)); 
2571   fIntFlowCorrelationsAllPro->Fill(2.5,two3n3n,dMult*(dMult-1.)); 
2572   fIntFlowCorrelationsAllPro->Fill(3.5,two4n4n,dMult*(dMult-1.)); 
2573   
2574   // store separetately <2> (to be improved: do I really need this?)
2575   fIntFlowCorrelationsEBE->SetBinContent(1,two1n1n); // <2>
2576   
2577   // to be improved (this can be implemented better):
2578   Double_t mWeight2p = 0.;
2579   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2580   {
2581    mWeight2p = dMult*(dMult-1.);
2582   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2583     {
2584      mWeight2p = 1.;    
2585     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2586       {
2587        mWeight2p = dMult;           
2588       }
2589             
2590   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,mWeight2p); // eW_<2>
2591   fIntFlowCorrelationsPro->Fill(0.5,two1n1n,mWeight2p);
2592   fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1n*two1n1n,mWeight2p);
2593   if(fCalculateCumulantsVsM)
2594   {
2595    fIntFlowCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n,mWeight2p);
2596    fIntFlowSquaredCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n*two1n1n,mWeight2p);
2597   } 
2598   // distribution of <cos(n*(phi1-phi2))>:
2599   //f2pDistribution->Fill(two1n1n,dMult*(dMult-1.)); 
2600  } // end of if(dMult>1)
2601  
2602  // 3-particle:
2603  Double_t three2n1n1n = 0.; // <cos(n*(2.*phi1-phi2-phi3))>
2604  Double_t three3n2n1n = 0.; // <cos(n*(3.*phi1-2.*phi2-phi3))>
2605  Double_t three4n2n2n = 0.; // <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2606  Double_t three4n3n1n = 0.; // <cos(n*(4.*phi1-3.*phi2-phi3))>
2607  
2608  if(dMult>2)
2609  {
2610   three2n1n1n = (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2611               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
2612               / (dMult*(dMult-1.)*(dMult-2.));                     
2613   three3n2n1n = (reQ3nQ2nstarQ1nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2614               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2615               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2616               / (dMult*(dMult-1.)*(dMult-2.));
2617   three4n2n2n = (reQ4nQ2nstarQ2nstar-2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2618               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*dMult)
2619               / (dMult*(dMult-1.)*(dMult-2.)); 
2620   three4n3n1n = (reQ4nQ3nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2621               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
2622               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2623               / (dMult*(dMult-1.)*(dMult-2.)); 
2624               
2625   // average 3-particle correlations for single event: 
2626   fIntFlowCorrelationsAllEBE->SetBinContent(6,three2n1n1n);
2627   fIntFlowCorrelationsAllEBE->SetBinContent(7,three3n2n1n);
2628   fIntFlowCorrelationsAllEBE->SetBinContent(8,three4n2n2n);
2629   fIntFlowCorrelationsAllEBE->SetBinContent(9,three4n3n1n);
2630         
2631   // average 3-particle correlations for all events:                
2632   fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.)); 
2633   fIntFlowCorrelationsAllPro->Fill(6.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
2634   fIntFlowCorrelationsAllPro->Fill(7.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.)); 
2635   fIntFlowCorrelationsAllPro->Fill(8.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));    
2636  } // end of if(dMult>2)
2637  
2638  // 4-particle:
2639  Double_t four1n1n1n1n = 0.; // <cos(n*(phi1+phi2-phi3-phi4))>
2640  Double_t four2n2n2n2n = 0.; // <cos(2.*n*(phi1+phi2-phi3-phi4))>
2641  Double_t four2n1n2n1n = 0.; // <cos(n*(2.*phi1+phi2-2.*phi3-phi4))> 
2642  Double_t four3n1n1n1n = 0.; // <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2643  Double_t four4n2n1n1n = 0.; // <cos(n*(4.*phi1-2.*phi2-phi3-phi4))> 
2644  Double_t four3n1n2n2n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))> 
2645  Double_t four3n1n3n1n = 0.; // <cos(n*(3.*phi1+phi2-3.*phi3-phi4))>   
2646  
2647  if(dMult>3)
2648  {
2649   four1n1n1n1n = (2.*dMult*(dMult-3.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ1n,2.)
2650                + pow(dImQ1n,2.))-2.*reQ2nQ1nstarQ1nstar+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2651                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));     
2652   four2n2n2n2n = (2.*dMult*(dMult-3.)+pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ2n,2.)
2653                + pow(dImQ2n,2.))-2.*reQ4nQ2nstarQ2nstar+(pow(dReQ4n,2.)+pow(dImQ4n,2.)))
2654                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));
2655   four2n1n2n1n = (dQ2nQ1nQ2nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar-2.*reQ2nQ1nstarQ1nstar)
2656                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2657                - ((dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2658                + (dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2659                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2660                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2661   four3n1n1n1n = (reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar-3.*reQ2nQ1nstarQ1nstar)
2662                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2663                + (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2664                + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
2665                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2666   four4n2n1n1n = (reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar)
2667                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2668                - (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2669                - 3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2670                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2671                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2672   four3n1n2n2n = (reQ3nQ1nQ2nstarQ2nstar-reQ4nQ2nstarQ2nstar-reQ3nQ1nQ4nstar-2.*reQ3nQ2nstarQ1nstar)
2673                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2674                - (2.*reQ1nQ1nQ2nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2675                - 4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2676                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2677                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.)); 
2678   four3n1n3n1n = ((pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2679                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar)
2680                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2681                + ((pow(dReQ4n,2.)+pow(dImQ4n,2.))-(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2682                + (pow(dReQ2n,2.)+pow(dImQ2n,2.))-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2683                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2684                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2685                
2686   // average 4-particle correlations for single event: 
2687   fIntFlowCorrelationsAllEBE->SetBinContent(11,four1n1n1n1n);
2688   fIntFlowCorrelationsAllEBE->SetBinContent(12,four2n1n2n1n);
2689   fIntFlowCorrelationsAllEBE->SetBinContent(13,four2n2n2n2n);
2690   fIntFlowCorrelationsAllEBE->SetBinContent(14,four3n1n1n1n);
2691   fIntFlowCorrelationsAllEBE->SetBinContent(15,four3n1n3n1n);
2692   fIntFlowCorrelationsAllEBE->SetBinContent(16,four3n1n2n2n);
2693   fIntFlowCorrelationsAllEBE->SetBinContent(17,four4n2n1n1n);
2694         
2695   // average 4-particle correlations for all events:                
2696   fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2697   fIntFlowCorrelationsAllPro->Fill(11.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2698   fIntFlowCorrelationsAllPro->Fill(12.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2699   fIntFlowCorrelationsAllPro->Fill(13.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2700   fIntFlowCorrelationsAllPro->Fill(14.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2701   fIntFlowCorrelationsAllPro->Fill(15.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
2702   fIntFlowCorrelationsAllPro->Fill(16.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
2703   
2704   // store separetately <4> (to be improved: do I really need this?)
2705   fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1n); // <4>
2706   
2707   // to be improved (this can be implemented better):
2708   Double_t mWeight4p = 0.;
2709   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2710   {
2711    mWeight4p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.);
2712   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2713     {
2714      mWeight4p = 1.;    
2715     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2716       {
2717        mWeight4p = dMult;           
2718       }
2719       
2720   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,mWeight4p); // eW_<4>
2721   fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1n,mWeight4p);
2722   fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
2723   if(fCalculateCumulantsVsM)
2724   {
2725    fIntFlowCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n,mWeight4p);
2726    fIntFlowSquaredCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
2727   }   
2728   // distribution of <cos(n*(phi1+phi2-phi3-phi4))>
2729   //f4pDistribution->Fill(four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2730   
2731  } // end of if(dMult>3)
2732
2733  // 5-particle:
2734  Double_t five2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2735  Double_t five2n2n2n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2736  Double_t five3n1n2n1n1n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2737  Double_t five4n1n1n1n1n = 0.; // <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2738  
2739  if(dMult>4)
2740  {
2741   five2n1n1n1n1n = (reQ2nQ1nQ1nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar+6.*reQ3nQ2nstarQ1nstar)
2742                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2743                  - (reQ2nQ1nQ3nstar+3.*(dMult-6.)*reQ2nQ1nstarQ1nstar+3.*reQ1nQ1nQ2nstar)
2744                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2745                  - (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2746                  + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))     
2747                  - 3.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2748                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2749                  - 3.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2750                  - 2.*(2*dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult*(dMult-4.))
2751                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2752                  
2753   five2n2n2n1n1n = (reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ2nQ2nQ3nstarQ1nstar)
2754                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2755                  + 2.*(reQ4nQ2nstarQ2nstar+4.*reQ3nQ2nstarQ1nstar+reQ3nQ1nQ4nstar)
2756                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2757                  + (reQ2nQ2nQ4nstar-2.*(dMult-5.)*reQ2nQ1nstarQ1nstar+2.*reQ1nQ1nQ2nstar)
2758                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2759                  - (2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2760                  + 1.*pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)
2761                  - 2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2762                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2763                  - (4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2764                  - 4.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+4.*dMult*(dMult-6.))
2765                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2766
2767   five4n1n1n1n1n = (reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ4nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nstarQ1nstarQ1nstar)
2768                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2769                  + (8.*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+12.*reQ3nQ2nstarQ1nstar+12.*reQ2nQ1nstarQ1nstar)
2770                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2771                  - (6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+8.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2772                  + 12.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-24.*dMult)
2773                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2774   
2775   five3n1n2n1n1n = (reQ3nQ1nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar)
2776                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2777                  - (reQ3nQ1nQ2nstarQ2nstar-3.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar)
2778                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2779                  - ((2.*dMult-13.)*reQ3nQ2nstarQ1nstar-reQ3nQ1nQ4nstar-9.*reQ2nQ1nstarQ1nstar)
2780                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2781                  - (2.*reQ1nQ1nQ2nstar+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2782                  - 2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+2.*(pow(dReQ3n,2.)
2783                  + pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2784                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2785                  + (2.*(dMult-6.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2786                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2787                  - pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2788                  + 2.*(3.*dMult-11.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2789                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2790                  - 4.*(dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2791                  
2792   // average 5-particle correlations for single event: 
2793   fIntFlowCorrelationsAllEBE->SetBinContent(19,five2n1n1n1n1n);
2794   fIntFlowCorrelationsAllEBE->SetBinContent(20,five2n2n2n1n1n);
2795   fIntFlowCorrelationsAllEBE->SetBinContent(21,five3n1n2n1n1n);
2796   fIntFlowCorrelationsAllEBE->SetBinContent(22,five4n1n1n1n1n);
2797         
2798   // average 5-particle correlations for all events:                         
2799   fIntFlowCorrelationsAllPro->Fill(18.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2800   fIntFlowCorrelationsAllPro->Fill(19.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2801   fIntFlowCorrelationsAllPro->Fill(20.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2802   fIntFlowCorrelationsAllPro->Fill(21.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2803  } // end of if(dMult>4)
2804     
2805  // 6-particle:
2806  Double_t six1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2807  Double_t six2n2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2808  Double_t six3n1n1n1n1n1n = 0.; // <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2809  Double_t six2n1n1n2n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2810  
2811  if(dMult>5)
2812  {
2813   six1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)+9.*dQ2nQ1nQ2nstarQ1nstar-6.*reQ2nQ1nQ1nstarQ1nstarQ1nstar)
2814                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2815                   + 4.*(reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar)
2816                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2817                   + 2.*(9.*(dMult-4.)*reQ2nQ1nstarQ1nstar+2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2818                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2819                   - 9.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2820                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-5.))
2821                   + (18.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2822                   / (dMult*(dMult-1)*(dMult-3)*(dMult-4))
2823                   - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2824                   
2825   six2n1n1n2n1n1n = (dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2826                   * (2.*five2n2n2n1n1n+4.*five2n1n1n1n1n+4.*five3n1n2n1n1n+4.*four2n1n2n1n+1.*four1n1n1n1n)
2827                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four1n1n1n1n+4.*two1n1n
2828                   + 2.*three2n1n1n+2.*three2n1n1n+4.*four3n1n1n1n+8.*three2n1n1n+2.*four4n2n1n1n
2829                   + 4.*four2n1n2n1n+2.*two2n2n+8.*four2n1n2n1n+4.*four3n1n3n1n+8.*three3n2n1n
2830                   + 4.*four3n1n2n2n+4.*four1n1n1n1n+4.*four2n1n2n1n+1.*four2n2n2n2n)
2831                   - dMult*(dMult-1.)*(dMult-2.)*(2.*three2n1n1n+8.*two1n1n+4.*two1n1n+2.
2832                   + 4.*two1n1n+4.*three2n1n1n+2.*two2n2n+4.*three2n1n1n+8.*three3n2n1n
2833                   + 8.*two2n2n+4.*three4n3n1n+4.*two3n3n+4.*three3n2n1n+4.*two1n1n
2834                   + 8.*three2n1n1n+4.*two1n1n+4.*three3n2n1n+4.*three2n1n1n+2.*two2n2n
2835                   + 4.*three3n2n1n+2.*three4n2n2n)-dMult*(dMult-1.)
2836                   * (4.*two1n1n+4.+4.*two1n1n+2.*two2n2n+1.+4.*two1n1n+4.*two2n2n+4.*two3n3n
2837                   + 1.+2.*two2n2n+1.*two4n4n)-dMult)
2838                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2839  
2840   six2n2n1n1n1n1n = (reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2841                   * (five4n1n1n1n1n+8.*five2n1n1n1n1n+6.*five2n2n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2842                   * (4.*four3n1n1n1n+6.*four4n2n1n1n+12.*three2n1n1n+12.*four1n1n1n1n+24.*four2n1n2n1n
2843                   + 4.*four3n1n2n2n+3.*four2n2n2n2n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n
2844                   + 4.*three4n3n1n+3.*three4n2n2n+8.*three2n1n1n+24.*two1n1n+12.*two2n2n+12.*three2n1n1n+8.*three3n2n1n
2845                   + 1.*three4n2n2n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+2.*two2n2n+8.*two1n1n+6.)-dMult)
2846                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2847    
2848   six3n1n1n1n1n1n = (reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2849                   * (five4n1n1n1n1n+4.*five2n1n1n1n1n+6.*five3n1n2n1n1n+4.*four3n1n1n1n)
2850                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+6.*four1n1n1n1n
2851                   + 12.*three2n1n1n+12.*four2n1n2n1n+6.*four3n1n1n1n+12.*three3n2n1n+4.*four3n1n3n1n+3.*four3n1n2n2n)
2852                   - dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n+4.*three4n3n1n+3.*three4n2n2n+4.*two1n1n
2853                   + 12.*two1n1n+6.*three2n1n1n+12.*three2n1n1n+4.*three3n2n1n+12.*two2n2n+4.*three3n2n1n+4.*two3n3n+1.*three4n3n1n
2854                   + 6.*three3n2n1n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+1.*two1n1n+4.+6.*two1n1n+4.*two2n2n
2855                   + 1.*two3n3n)-dMult)/(dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2856                                  
2857   // average 6-particle correlations for single event: 
2858   fIntFlowCorrelationsAllEBE->SetBinContent(24,six1n1n1n1n1n1n);
2859   fIntFlowCorrelationsAllEBE->SetBinContent(25,six2n1n1n2n1n1n);
2860   fIntFlowCorrelationsAllEBE->SetBinContent(26,six2n2n1n1n1n1n);
2861   fIntFlowCorrelationsAllEBE->SetBinContent(27,six3n1n1n1n1n1n);
2862         
2863   // average 6-particle correlations for all events:         
2864   fIntFlowCorrelationsAllPro->Fill(23.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2865   fIntFlowCorrelationsAllPro->Fill(24.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2866   fIntFlowCorrelationsAllPro->Fill(25.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
2867   fIntFlowCorrelationsAllPro->Fill(26.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2868
2869   // store separetately <6> (to be improved: do I really need this?)
2870   fIntFlowCorrelationsEBE->SetBinContent(3,six1n1n1n1n1n1n); // <6>
2871   
2872   // to be improved (this can be implemented better):
2873   Double_t mWeight6p = 0.;
2874   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2875   {
2876    mWeight6p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.);
2877   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2878     {
2879      mWeight6p = 1.;    
2880     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2881       {
2882        mWeight6p = dMult;           
2883       }
2884       
2885   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(3,mWeight6p); // eW_<6>
2886   fIntFlowCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n,mWeight6p);
2887   fIntFlowSquaredCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
2888   if(fCalculateCumulantsVsM)
2889   {
2890    fIntFlowCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n,mWeight6p);
2891    fIntFlowSquaredCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
2892   }    
2893   // distribution of <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2894   //f6pDistribution->Fill(six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2895  } // end of if(dMult>5)
2896  
2897  // 7-particle:
2898  Double_t seven2n1n1n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2899  
2900  if(dMult>6)
2901  {
2902   seven2n1n1n1n1n1n1n = (reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2903                       * (2.*six3n1n1n1n1n1n+4.*six1n1n1n1n1n1n+1.*six2n2n1n1n1n1n+6.*six2n1n1n2n1n1n+8.*five2n1n1n1n1n)
2904                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(1.*five4n1n1n1n1n +8.*five2n1n1n1n1n+8.*four3n1n1n1n
2905                       + 12.*five3n1n2n1n1n+4.*five2n1n1n1n1n+3.*five2n2n2n1n1n+6.*five2n2n2n1n1n+6.*four1n1n1n1n+24.*four1n1n1n1n
2906                       + 12.*five2n1n1n1n1n+12.*five2n1n1n1n1n+12.*three2n1n1n+24.*four2n1n2n1n+4.*five3n1n2n1n1n+4.*five2n1n1n1n1n)
2907                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+12.*four1n1n1n1n+24.*three2n1n1n
2908                       + 24.*four2n1n2n1n+12.*four3n1n1n1n+24.*three3n2n1n+8.*four3n1n3n1n+6.*four3n1n2n2n+6.*three2n1n1n+12.*four1n1n1n1n
2909                       + 12.*four2n1n2n1n+6.*three2n1n1n+12.*four2n1n2n1n+4.*four3n1n2n2n+3.*four2n2n2n2n+4.*four1n1n1n1n+6.*three2n1n1n
2910                       + 24.*two1n1n+24.*four1n1n1n1n+4.*four3n1n1n1n+24.*two1n1n+24.*three2n1n1n+12.*two2n2n+24.*three2n1n1n+12.*four2n1n2n1n
2911                       + 8.*three3n2n1n+8.*four2n1n2n1n+1.*four4n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+1.*three2n1n1n+8.*two1n1n
2912                       + 12.*three3n2n1n+24.*two1n1n+12.*three2n1n1n+4.*three2n1n1n+8.*two1n1n+4.*three4n3n1n+24.*three2n1n1n+8.*three3n2n1n
2913                       + 12.*two1n1n+12.*two1n1n+3.*three4n2n2n+24.*two2n2n+6.*two2n2n+12.+12.*three3n2n1n+8.*two3n3n+12.*three2n1n1n+24.*two1n1n
2914                       + 4.*three3n2n1n+8.*three3n2n1n+2.*three4n3n1n+12.*two1n1n+8.*three2n1n1n+4.*three2n1n1n+2.*three3n2n1n+6.*two2n2n+8.*two2n2n
2915                       + 1.*three4n2n2n+4.*three3n2n1n+6.*three2n1n1n)-dMult*(dMult-1.)*(4.*two1n1n+2.*two1n1n+6.*two2n2n+8.+1.*two2n2n+4.*two3n3n
2916                       + 12.*two1n1n+4.*two1n1n+1.*two4n4n+8.*two2n2n+6.+2.*two3n3n+4.*two1n1n+1.*two2n2n)-dMult)
2917                       / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)); // to be improved (direct formula needed)
2918         
2919   // average 7-particle correlations for single event: 
2920   fIntFlowCorrelationsAllEBE->SetBinContent(29,seven2n1n1n1n1n1n1n);
2921        
2922   // average 7-particle correlations for all events:                      
2923   fIntFlowCorrelationsAllPro->Fill(28.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.));
2924  } // end of if(dMult>6)
2925  
2926  // 8-particle:
2927  Double_t eight1n1n1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2928  if(dMult>7)
2929  {
2930   eight1n1n1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),4.)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)
2931                         * (12.*seven2n1n1n1n1n1n1n+16.*six1n1n1n1n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2932                         * (8.*six3n1n1n1n1n1n+48.*six1n1n1n1n1n1n+6.*six2n2n1n1n1n1n+96.*five2n1n1n1n1n+72.*four1n1n1n1n+36.*six2n1n1n2n1n1n)
2933                         - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(2.*five4n1n1n1n1n+32.*five2n1n1n1n1n+36.*four1n1n1n1n
2934                         + 32.*four3n1n1n1n+48.*five2n1n1n1n1n+48.*five3n1n2n1n1n+144.*five2n1n1n1n1n+288.*four1n1n1n1n+36.*five2n2n2n1n1n
2935                         + 144.*three2n1n1n+96.*two1n1n+144.*four2n1n2n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2936                         * (8.*four3n1n1n1n+48.*four1n1n1n1n+12.*four4n2n1n1n+96.*four2n1n2n1n+96.*three2n1n1n+72.*three2n1n1n+144.*two1n1n
2937                         + 16.*four3n1n3n1n+48.*four3n1n1n1n+144.*four1n1n1n1n+72.*four1n1n1n1n+96.*three3n2n1n+24.*four3n1n2n2n+144.*four2n1n2n1n
2938                         + 288.*two1n1n+288.*three2n1n1n+9.*four2n2n2n2n+72.*two2n2n+24.)-dMult*(dMult-1.)*(dMult-2.)*(12.*three2n1n1n+16.*two1n1n
2939                         + 24.*three3n2n1n+48.*three2n1n1n+96.*two1n1n+8.*three4n3n1n+32.*three3n2n1n+96.*three2n1n1n+144.*two1n1n+6.*three4n2n2n
2940                         + 96.*two2n2n+36.*two2n2n+72.+48.*three3n2n1n+16.*two3n3n+72.*three2n1n1n+144.*two1n1n)-dMult*(dMult-1.)*(8.*two1n1n
2941                         + 12.*two2n2n+16.+8.*two3n3n+48.*two1n1n+1.*two4n4n+16.*two2n2n+18.)-dMult)
2942                         / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.)); // to be improved (direct formula needed)
2943   
2944   // average 8-particle correlations for single event: 
2945   fIntFlowCorrelationsAllEBE->SetBinContent(31,eight1n1n1n1n1n1n1n1n);
2946        
2947   // average 8-particle correlations for all events:                       
2948   fIntFlowCorrelationsAllPro->Fill(30.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2949  
2950   // store separetately <8> (to be improved: do I really need this?)
2951   fIntFlowCorrelationsEBE->SetBinContent(4,eight1n1n1n1n1n1n1n1n); // <8>
2952   
2953   // to be improved (this can be implemented better):
2954   Double_t mWeight8p = 0.;
2955   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2956   {
2957    mWeight8p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.);
2958   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2959     {
2960      mWeight8p = 1.;    
2961     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2962       {
2963        mWeight8p = dMult;           
2964       }
2965         
2966   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(4,mWeight8p); // eW_<8>
2967   fIntFlowCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
2968   fIntFlowSquaredCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);  
2969   if(fCalculateCumulantsVsM)
2970   {
2971    fIntFlowCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
2972    fIntFlowSquaredCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);
2973   }    
2974   // distribution of <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2975   //f8pDistribution->Fill(eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2976  } // end of if(dMult>7) 
2977  
2978  // EXTRA: // to be improved (reorganized)
2979
2980  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
2981  // 34th bin: <5>_{2n,2n,2n|3n,3n} = five2n2n2n3n3n = <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))> 
2982  
2983  // 4-particle:
2984  Double_t four4n2n3n3n = 0.; // <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
2985  Double_t reQ4nQ2nQ3nstarQ3nstar = (dReQ4n*dReQ2n-dImQ4n*dImQ2n)*(dReQ3n*dReQ3n-dImQ3n*dImQ3n)
2986                                  + 2.*(dReQ4n*dImQ2n+dImQ4n*dReQ2n)*dReQ3n*dImQ3n;
2987  Double_t reQ6nQ4nstarQ2nstar = dReQ6n*dReQ4n*dReQ2n-dReQ6n*dImQ4n*dImQ2n+dImQ6n*dReQ4n*dImQ2n
2988                               + dImQ6n*dImQ4n*dReQ2n;
2989  Double_t reQ6nQ3nstarQ3nstar = pow(dReQ3n,2.)*dReQ6n + 2.*dReQ3n*dImQ3n*dImQ6n 
2990                               - pow(dImQ3n,2.)*dReQ6n; 
2991  if(dMult>3.)
2992  {
2993   four4n2n3n3n = (reQ4nQ2nQ3nstarQ3nstar-reQ6nQ4nstarQ2nstar-reQ6nQ3nstarQ3nstar
2994                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar
2995                + (pow(dReQ6n,2.)+pow(dImQ6n,2.))+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2996                + 2.*(2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2997                + (pow(dReQ1n,2.)+pow(dImQ1n,2.))-3.*dMult))
2998                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2999                
3000   fIntFlowCorrelationsAllPro->Fill(32.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3001  } // end of if(dMult>3.)
3002  
3003  // 5-particle:
3004  Double_t five2n2n2n3n3n = 0.; // <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))>
3005  Double_t reQ2nQ2nQ2nQ3nstarQ3nstar = pow(dReQ2n,3.)*pow(dReQ3n,2.) 
3006                                     - 3.*dReQ2n*pow(dReQ3n,2.)*pow(dImQ2n,2.)
3007                                     + 6.*pow(dReQ2n,2.)*dReQ3n*dImQ2n*dImQ3n 
3008                                     - 2.*dReQ3n*pow(dImQ2n,3.)*dImQ3n-pow(dReQ2n,3.)*pow(dImQ3n,2.) 
3009                                     + 3.*dReQ2n*pow(dImQ2n,2.)*pow(dImQ3n,2.);
3010  Double_t reQ2nQ2nQ2nQ6nstar = dReQ6n*pow(dReQ2n,3)-3.*dReQ2n*dReQ6n*pow(dImQ2n,2)
3011                              + 3.*dImQ2n*dImQ6n*pow(dReQ2n,2)-dImQ6n*pow(dImQ2n,3);                                     
3012  Double_t reQ2nQ2nQ1nstarQ3nstar = reQ3nQ1nQ2nstarQ2nstar;
3013  Double_t reQ4nQ2nQ6nstar = reQ6nQ4nstarQ2nstar;
3014  Double_t reQ4nQ1nstarQ3nstar = reQ3nQ1nQ4nstar;
3015  if(dMult>4.)
3016  {
3017   five2n2n2n3n3n = (reQ2nQ2nQ2nQ3nstarQ3nstar-reQ2nQ2nQ2nQ6nstar-3.*reQ4nQ2nQ3nstarQ3nstar 
3018                  - 6.*reQ2nQ2nQ1nstarQ3nstar+2.*reQ6nQ3nstarQ3nstar+3.*reQ4nQ2nQ6nstar
3019                  + 6.*reQ4nQ1nstarQ3nstar+6.*reQ2nQ2nQ4nstar
3020                  + 12.*reQ2nQ1nQ3nstar+6.*reQ2nQ1nstarQ1nstar
3021                  - 2.*((pow(dReQ6n,2.)+pow(dImQ6n,2.)) 
3022                  + 3.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3023                  + 6.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)) 
3024                  + 9.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3025                  + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-12.*dMult))
3026                  /(dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3027   
3028   fIntFlowCorrelationsAllPro->Fill(33.5,five2n2n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3029  } // end of if(dMult>4.)
3030  
3031 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
3032
3033 //================================================================================================================================
3034
3035 void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3036 {
3037  // Store phi distribution for one event to illustrate flow.
3038  
3039  if(fPhiDistributionForOneEvent->GetEntries()>0){return;} // store only phi distribution for one event
3040  
3041  Double_t vMin = fPhiDistributionForOneEventSettings[0]; 
3042  Double_t vMax = fPhiDistributionForOneEventSettings[1]; 
3043  Double_t refMultMin = fPhiDistributionForOneEventSettings[2]; 
3044  Double_t refMultMax = fPhiDistributionForOneEventSettings[3]; 
3045  
3046  Double_t vEBE = 0.;
3047  Double_t cumulant4thEBE = fIntFlowCorrelationsEBE->GetBinContent(2)-2.*pow(fIntFlowCorrelationsEBE->GetBinContent(1),2.);
3048  if(cumulant4thEBE<0.)
3049  {
3050   vEBE = pow(-1.*cumulant4thEBE,0.25);
3051   if((vEBE>vMin && vEBE<vMax) && (fReferenceMultiplicityEBE>refMultMin && fReferenceMultiplicityEBE<refMultMax))
3052   {
3053    fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f",fHarmonic,vEBE));
3054    for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3055    {
3056     if(anEvent->GetTrack(p)->InRPSelection())
3057     {
3058      fPhiDistributionForOneEvent->Fill(anEvent->GetTrack(p)->Phi());
3059     }
3060    } // end of for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3061   } else
3062     {
3063      fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f, out of specified boundaries",fHarmonic,vEBE));  
3064     } 
3065    
3066  } // end of if(cumulant4thEBE<0.)
3067  
3068 } // end of void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3069
3070 //================================================================================================================================
3071
3072 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3073 {
3074  // Calculate averages of products of correlations for integrated flow.
3075  
3076  // multiplicity:
3077  Double_t dMult = (*fSMpk)(0,0);
3078  
3079  Int_t counter = 0;
3080  
3081  for(Int_t ci1=1;ci1<4;ci1++)
3082  {
3083   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
3084   {
3085    fIntFlowProductOfCorrelationsPro->Fill(0.5+counter,
3086                                           fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3087                                           fIntFlowCorrelationsEBE->GetBinContent(ci2),
3088                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3089                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3090    // products versus multiplicity:  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]
3091    if(fCalculateCumulantsVsM)
3092    {
3093     fIntFlowProductOfCorrelationsVsMPro[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights ?
3094                                                        fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3095                                                        fIntFlowCorrelationsEBE->GetBinContent(ci2),
3096                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3097                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3098    } // end of if(fCalculateCumulantsVsM)
3099    counter++;                                                                                                                        
3100   }
3101  }
3102  
3103 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3104
3105
3106 //================================================================================================================================
3107
3108
3109 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3110 {
3111  // Calculate averages of products of correction terms for NUA.
3112  
3113  // a) Binning of fIntFlowProductOfCorrectionTermsForNUAPro is organized as follows:
3114  //     1st bin: <<2><cos(phi)>> 
3115  //     2nd bin: <<2><sin(phi)>>
3116  //     3rd bin: <<cos(phi)><sin(phi)>>
3117  //     4th bin: <<2><cos(phi1+phi2)>> 
3118  //     5th bin: <<2><sin(phi1+phi2)>>
3119  //     6th bin: <<2><cos(phi1-phi2-phi3)>> 
3120  //     7th bin: <<2><sin(phi1-phi2-phi3)>>
3121  //     8th bin: <<4><cos(phi1)>>
3122  //     9th bin: <<4><sin(phi1)>>
3123  //    10th bin: <<4><cos(phi1+phi2)>>
3124  //    11th bin: <<4><sin(phi1+phi2)>>
3125  //    12th bin: <<4><cos(phi1-phi2-phi3)>>
3126  //    13th bin: <<4><sin(phi1-phi2-phi3)>>
3127  //    14th bin: <<cos(phi1)><cos(phi1+phi2)>>
3128  //    15th bin: <<cos(phi1)><sin(phi1+phi2)>> 
3129  //    16th bin: <<cos(phi1)><cos(phi1-phi2-phi3)>>
3130  //    17th bin: <<cos(phi1)><sin(phi1-phi2-phi3)>> 
3131  //    18th bin: <<sin(phi1)><cos(phi1+phi2)>>
3132  //    19th bin: <<sin(phi1)><sin(phi1+phi2)>> 
3133  //    20th bin: <<sin(phi1)><cos(phi1-phi2-phi3)>>
3134  //    21st bin: <<sin(phi1)><sin(phi1-phi2-phi3)>>
3135  //    22nd bin: <<cos(phi1+phi2)><sin(phi1+phi2)>>
3136  //    23rd bin: <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>
3137  //    24th bin: <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>
3138  //    25th bin: <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>
3139  //    26th bin: <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>
3140  //    27th bin: <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>
3141  
3142  // <<2><cos(phi)>>:
3143  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(0.5,
3144                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3145                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3146                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3147  // <<2><sin(phi)>>:
3148  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(1.5,
3149                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3150                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3151                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3152  // <<cos(phi)><sin(phi)>>:
3153  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(2.5,
3154                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3155                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3156                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3157  // <<2><cos(phi1+phi2)>>:
3158  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(3.5,
3159                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3160                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3161                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3162  // <<2><sin(phi1+phi2)>>:
3163  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(4.5,
3164                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3165                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3166                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3167  // <<2><cos(phi1-phi2-phi3)>>:
3168  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(5.5,
3169                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3170                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3171                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3172  // <<2><sin(phi1-phi2-phi3)>>:
3173  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(6.5,
3174                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3175                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3176                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3177  // <<4><cos(phi1)>>:
3178  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(7.5,
3179                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3180                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3181                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3182  // <<4><sin(phi1)>>:
3183  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(8.5,
3184                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3185                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3186                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3187  // <<4><cos(phi1+phi2)>>:
3188  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(9.5,
3189                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3190                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3191                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3192  // <<4><sin(phi1+phi2)>>:
3193  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(10.5,
3194                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3195                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3196                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
3197  // <<4><cos(phi1-phi2-phi3)>>:
3198  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(11.5,
3199                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3200                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3201                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3202  // <<4><sin(phi1-phi2-phi3)>>:
3203  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(12.5,
3204                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3205                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3206                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));   
3207  // <<cos(phi1)><cos(phi1+phi2)>>:
3208  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(13.5,
3209                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3210                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3211                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3212  // <<cos(phi1)><sin(phi1+phi2)>>: 
3213  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(14.5,
3214                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3215                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3216                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3217  // <<cos(phi1)><cos(phi1-phi2-phi3)>>:
3218  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(15.5,
3219                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3220                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3221                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3222  // <<cos(phi1)><sin(phi1-phi2-phi3)>>: 
3223  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(16.5,
3224                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3225                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3226                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
3227  // <<sin(phi1)><cos(phi1+phi2)>>:
3228  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(17.5,
3229                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3230                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3231                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));  
3232  // <<sin(phi1)><sin(phi1+phi2)>>: 
3233  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(18.5,
3234                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3235                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3236                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));  
3237  // <<sin(phi1)><cos(phi1-phi2-phi3)>>:
3238  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(19.5,
3239                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3240                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3241                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3242  // <<sin(phi1)><sin(phi1-phi2-phi3)>>:
3243  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(20.5,
3244                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3245                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3246                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3247  // <<cos(phi1+phi2)><sin(phi1+phi2)>>:
3248  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(21.5,
3249                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3250                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3251                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3252  // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3253  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(22.5,
3254                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3255                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3256                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));   
3257  // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3258  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(23.5,
3259                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3260                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3261                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3262  // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3263  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(24.5,
3264                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3265                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3266                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));    
3267  // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3268  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(25.5,
3269                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3270                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3271                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3272  // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>:
3273  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(26.5,
3274                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3275                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)
3276                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3277
3278 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3279
3280 //================================================================================================================================
3281
3282 void AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
3283 {
3284  // a) Calculate unbiased estimators Cov(<2>,<4>), Cov(<2>,<6>), Cov(<2>,<8>), Cov(<4>,<6>), Cov(<4>,<8>) and Cov(<6>,<8>)
3285  //    for covariances V_(<2>,<4>), V_(<2>,<6>), V_(<2>,<8>), V_(<4>,<6>), V_(<4>,<8>) and V_(<6>,<8>).
3286  // b) Store in histogram fIntFlowCovariances for instance the following: 
3287  //
3288  //             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)]
3289  // 
3290  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<4>} is event weight for <4>.
3291  // c) Binning of fIntFlowCovariances is organized as follows:
3292  // 
3293  //     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)] 
3294  //     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)]
3295  //     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)]
3296  //     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)]
3297  //     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)]
3298  //     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)]
3299  //
3300     
3301  // Average 2-, 4-, 6- and 8-particle correlations for all events:
3302  Double_t correlation[4] = {0.};
3303  for(Int_t ci=0;ci<4;ci++)
3304  {
3305   correlation[ci] = fIntFlowCorrelationsPro->GetBinContent(ci+1);
3306  } 
3307  // Average products of 2-, 4-, 6- and 8-particle correlations: 
3308  Double_t productOfCorrelations[4][4] = {{0.}};
3309  Int_t productOfCorrelationsLabel = 1;
3310  // Denominators in the expressions for the unbiased estimator for covariance:
3311  Double_t denominator[4][4] = {{0.}};
3312  Int_t sumOfProductOfEventWeightsLabel1 = 1;
3313  // Weight dependent prefactor which multiply unbiased estimators for covariances:
3314  Double_t wPrefactor[4][4] = {{0.}}; 
3315  Int_t sumOfProductOfEventWeightsLabel2 = 1;
3316  for(Int_t c1=0;c1<4;c1++)
3317  {
3318   for(Int_t c2=c1+1;c2<4;c2++)
3319   {
3320    productOfCorrelations[c1][c2] = fIntFlowProductOfCorrelationsPro->GetBinContent(productOfCorrelationsLabel);
3321    if(TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1)) > 1.e-44)
3322    {
3323     denominator[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel1))
3324                         / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1) 
3325                         * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                              
3326     wPrefactor[c1][c2] = fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel2)
3327                        / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)
3328                        * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                                                       
3329    }
3330    productOfCorrelationsLabel++; // to be improved - do I need here all 3 counters?
3331    sumOfProductOfEventWeightsLabel1++;
3332    sumOfProductOfEventWeightsLabel2++;  
3333   } // end of for(Int_t c2=c1+1;c2<4;c2++)
3334  } // end of for(Int_t c1=0;c1<4;c1++)
3335  
3336  Int_t covarianceLabel = 1;
3337  for(Int_t c1=0;c1<4;c1++)
3338  {
3339   for(Int_t c2=c1+1;c2<4;c2++)
3340   {
3341    if(TMath::Abs(denominator[c1][c2]) > 1.e-44)
3342    {
3343     // Covariances:
3344     Double_t cov = (productOfCorrelations[c1][c2]-correlation[c1]*correlation[c2])/denominator[c1][c2]; 
3345     // Covariances multiplied with weight dependent prefactor:
3346     Double_t wCov = cov * wPrefactor[c1][c2];
3347     fIntFlowCovariances->SetBinContent(covarianceLabel,wCov);
3348    }
3349    covarianceLabel++;
3350   } // end of for(Int_t c2=c1+1;c2<4;c2++) 
3351  } // end of for(Int_t c1=0;c1<4;c1++)
3352  
3353  // Versus multiplicity: 
3354  if(!fCalculateCumulantsVsM){return;}
3355  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
3356  for(Int_t b=1;b<=nBins;b++)
3357  {
3358   // Average 2-, 4-, 6- and 8-particle correlations for all events:
3359   Double_t correlationVsM[4] = {0.};
3360   for(Int_t ci=0;ci<4;ci++)
3361   {
3362    correlationVsM[ci] = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
3363   } // end of for(Int_t ci=0;ci<4;ci++)
3364   // Average products of 2-, 4-, 6- and 8-particle correlations: 
3365   Double_t productOfCorrelationsVsM[4][4] = {{0.}};
3366   Int_t productOfCorrelationsLabelVsM = 1;
3367   // Denominators in the expressions for the unbiased estimator for covariance:
3368   Double_t denominatorVsM[4][4] = {{0.}};
3369   Int_t sumOfProductOfEventWeightsLabel1VsM = 1;
3370   // Weight dependent prefactor which multiply unbiased estimators for covariances:
3371   Double_t wPrefactorVsM[4][4] = {{0.}}; 
3372   Int_t sumOfProductOfEventWeightsLabel2VsM = 1;
3373   for(Int_t c1=0;c1<4;c1++)
3374   {
3375    for(Int_t c2=c1+1;c2<4;c2++)
3376    {
3377     productOfCorrelationsVsM[c1][c2] = fIntFlowProductOfCorrelationsVsMPro[productOfCorrelationsLabelVsM-1]->GetBinContent(b);
3378     if(TMath::Abs(fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b)) > 1.e-44)
3379     {
3380      denominatorVsM[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel1VsM-1]->GetBinContent(b))
3381                             / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b) 
3382                             * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                              
3383      wPrefactorVsM[c1][c2] = fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel2VsM-1]->GetBinContent(b)
3384                            / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)
3385                            * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                                                       
3386     }
3387     productOfCorrelationsLabelVsM++;
3388     sumOfProductOfEventWeightsLabel1VsM++;
3389     sumOfProductOfEventWeightsLabel2VsM++;  
3390    } // end of for(Int_t c1=0;c1<4;c1++) 
3391   } // end of for(Int_t c2=c1+1;c2<4;c2++)
3392  
3393   Int_t covarianceLabelVsM = 1;
3394   for(Int_t c1=0;c1<4;c1++)
3395   {
3396    for(Int_t c2=c1+1;c2<4;c2++)
3397    {
3398     if(TMath::Abs(denominatorVsM[c1][c2]) > 1.e-44)
3399     {
3400      // Covariances:
3401      Double_t covVsM = (productOfCorrelationsVsM[c1][c2]-correlationVsM[c1]*correlationVsM[c2])/denominatorVsM[c1][c2]; 
3402      // Covariances multiplied with weight dependent prefactor:
3403      Double_t wCovVsM = covVsM * wPrefactorVsM[c1][c2];
3404      fIntFlowCovariancesVsM[covarianceLabelVsM-1]->SetBinContent(b,wCovVsM);
3405     }
3406     covarianceLabelVsM++;
3407    } // end of for(Int_t c2=c1+1;c2<4;c2++)
3408   } // end of for(Int_t c1=0;c1<4;c1++)
3409  } // end of for(Int_t b=1;b<=nBins;b++)
3410   
3411 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
3412
3413 //================================================================================================================================
3414
3415 void AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
3416 {
3417  // a) Calculate unbiased estimators Cov(*,*) for true covariances V_(*,*) for NUA terms.
3418  // b) Store in histogram fIntFlowCovariancesNUA for instance the following: 
3419  //
3420  //             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)]
3421  // 
3422  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<cos(phi)>} is event weight for <cos(phi)>.
3423  // c) Binning of fIntFlowCovariancesNUA is organized as follows:
3424  // 
3425  //     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)] 
3426  //     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)]
3427  //     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)]
3428  // ...
3429       
3430  // Cov(<2>,<cos(phi)>):
3431  Double_t product1 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(1); // <<2><cos(phi)>> 
3432  Double_t term1st1 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3433  Double_t term2nd1 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
3434  Double_t sumOfW1st1 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3435  Double_t sumOfW2nd1 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
3436  Double_t sumOfWW1 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(1); // W_{<2>} * W_{<cos(phi)>}
3437  // numerator in the expression for the the unbiased estimator for covariance:
3438  Double_t numerator1 = product1 - term1st1*term2nd1; 
3439  // denominator in the expression for the the unbiased estimator for covariance:
3440  Double_t denominator1 = 0.;
3441  if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
3442  {
3443   denominator1 = 1.-sumOfWW1/(sumOfW1st1*sumOfW2nd1);
3444   if(TMath::Abs(denominator1)>0.)
3445   {
3446    // covariance:
3447    Double_t covariance1 = numerator1/denominator1;
3448    // weight dependent prefactor for covariance:
3449    Double_t wPrefactor1 = sumOfWW1/(sumOfW1st1*sumOfW2nd1);
3450    // finally, store "weighted" covariance:
3451    fIntFlowCovariancesNUA->SetBinContent(1,wPrefactor1*covariance1);
3452   } // end of if(TMath::Abs(denominator)>0.)
3453  } // end of if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
3454  
3455  // Cov(<2>,<sin(phi)>):
3456  Double_t product2 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(2); // <<2><sin(phi)>> 
3457  Double_t term1st2 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3458  Double_t term2nd2 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
3459  Double_t sumOfW1st2 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3460  Double_t sumOfW2nd2 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
3461  Double_t sumOfWW2 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(2); // W_{<2>} * W_{<sin(phi)>}
3462  // numerator in the expression for the the unbiased estimator for covariance:
3463  Double_t numerator2 = product2 - term1st2*term2nd2;
3464  // denominator in the expression for the the unbiased estimator for covariance:
3465  Double_t denominator2 = 0.;
3466  if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
3467  {  
3468   denominator2 = 1.-sumOfWW2/(sumOfW1st2*sumOfW2nd2);
3469   if(TMath::Abs(denominator2)>0.)
3470   {
3471    // covariance:
3472    Double_t covariance2 = numerator2/denominator2;
3473    // weight dependent prefactor for covariance:
3474    Double_t wPrefactor2 = sumOfWW2/(sumOfW1st2*sumOfW2nd2);
3475    // finally, store "weighted" covariance:
3476    fIntFlowCovariancesNUA->SetBinContent(2,wPrefactor2*covariance2);
3477   } // end of if(TMath::Abs(denominator2)>0.)
3478  } // end of if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
3479  
3480  // Cov(<cos(phi)>,<sin(phi)>):
3481  Double_t product3 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(3); // <<cos(phi)><sin(phi)>> 
3482  Double_t term1st3 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
3483  Double_t term2nd3 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
3484  Double_t sumOfW1st3 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
3485  Double_t sumOfW2nd3 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
3486  Double_t sumOfWW3 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(3); // W_{<cos(phi)>} * W_{<sin(phi)>}
3487  // numerator in the expression for the the unbiased estimator for covariance:
3488  Double_t numerator3 = product3 - term1st3*term2nd3; 
3489  // denominator in the expression for the the unbiased estimator for covariance:
3490  Double_t denominator3 = 0;
3491  if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
3492  { 
3493   denominator3 = 1.-sumOfWW3/(sumOfW1st3*sumOfW2nd3);
3494   if(TMath::Abs(denominator3)>0.)
3495   {
3496    // covariance:
3497    Double_t covariance3 = numerator3/denominator3;
3498    // weight dependent prefactor for covariance:
3499    Double_t wPrefactor3 = sumOfWW3/(sumOfW1st3*sumOfW2nd3);
3500    // finally, store "weighted" covariance:
3501    fIntFlowCovariancesNUA->SetBinContent(3,wPrefactor3*covariance3);
3502   } // end of if(TMath::Abs(denominator3)>0.)
3503  } // end of if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
3504  
3505  // Cov(<2>,<cos(phi1+phi2)>):
3506  Double_t product4 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(4); // <<2><cos(phi1+phi2)>> 
3507  Double_t term1st4 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3508  Double_t term2nd4 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3509  Double_t sumOfW1st4 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3510  Double_t sumOfW2nd4 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3511  Double_t sumOfWW4 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(4); // W_{<2>} * W_{<cos(phi1+phi2)>}
3512  // numerator in the expression for the the unbiased estimator for covariance:
3513  Double_t numerator4 = product4 - term1st4*term2nd4; 
3514  // denominator in the expression for the the unbiased estimator for covariance:
3515  Double_t denominator4 = 0.;
3516  if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
3517  { 
3518   denominator4 = 1.-sumOfWW4/(sumOfW1st4*sumOfW2nd4);
3519   if(TMath::Abs(denominator4)>0.)
3520   {  
3521    // covariance:
3522    Double_t covariance4 = numerator4/denominator4;
3523    // weight dependent prefactor for covariance:
3524    Double_t wPrefactor4 = sumOfWW4/(sumOfW1st4*sumOfW2nd4);
3525    // finally, store "weighted" covariance:
3526    fIntFlowCovariancesNUA->SetBinContent(4,wPrefactor4*covariance4);
3527   } // end of if(TMath::Abs(denominator4)>0.)
3528  } // end of if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
3529  
3530  // Cov(<2>,<sin(phi1+phi2)>):
3531  Double_t product5 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(5); // <<2><sin(phi1+phi2)>> 
3532  Double_t term1st5 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3533  Double_t term2nd5 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3534  Double_t sumOfW1st5 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3535  Double_t sumOfW2nd5 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3536  Double_t sumOfWW5 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(5); // W_{<2>} * W_{<sin(phi1+phi2)>}
3537  // numerator in the expression for the the unbiased estimator for covariance:
3538  Double_t numerator5 = product5 - term1st5*term2nd5; 
3539  // denominator in the expression for the the unbiased estimator for covariance:
3540  Double_t denominator5 = 0.;
3541  if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
3542  {  
3543   denominator5 = 1.-sumOfWW5/(sumOfW1st5*sumOfW2nd5);
3544   if(TMath::Abs(denominator5)>0.)
3545   {  
3546    // covariance:
3547    Double_t covariance5 = numerator5/denominator5;
3548    // weight dependent prefactor for covariance:
3549    Double_t wPrefactor5 = sumOfWW5/(sumOfW1st5*sumOfW2nd5);
3550    // finally, store "weighted" covariance:
3551    fIntFlowCovariancesNUA->SetBinContent(5,wPrefactor5*covariance5);
3552   } // end of if(TMath::Abs(denominator5)>0.)
3553  } // end of if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
3554  
3555  // Cov(<2>,<cos(phi1-phi2-phi3)>):
3556  Double_t product6 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(6); // <<2><cos(phi1-phi2-phi3)>> 
3557  Double_t term1st6 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3558  Double_t term2nd6 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3559  Double_t sumOfW1st6 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3560  Double_t sumOfW2nd6 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3561  Double_t sumOfWW6 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(6); // W_{<2>} * W_{<cos(phi1-phi2-phi3)>}
3562  // numerator in the expression for the the unbiased estimator for covariance:
3563  Double_t numerator6 = product6 - term1st6*term2nd6; 
3564  // denominator in the expression for the the unbiased estimator for covariance:
3565  Double_t denominator6 = 0.;
3566  if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
3567  {  
3568   denominator6 = 1.-sumOfWW6/(sumOfW1st6*sumOfW2nd6);
3569   if(TMath::Abs(denominator6)>0.)
3570   {  
3571    // covariance:
3572    Double_t covariance6 = numerator6/denominator6;
3573    // weight dependent prefactor for covariance:
3574    Double_t wPrefactor6 = sumOfWW6/(sumOfW1st6*sumOfW2nd6);
3575    // finally, store "weighted" covariance:
3576    fIntFlowCovariancesNUA->SetBinContent(6,wPrefactor6*covariance6);
3577   } // end of if(TMath::Abs(denominator6)>0.)
3578  } // end of if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
3579  
3580  // Cov(<2>,<sin(phi1-phi2-phi3)>):
3581  Double_t product7 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(7); // <<2><sin(phi1-phi2-phi3)>> 
3582  Double_t term1st7 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3583  Double_t term2nd7 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3584  Double_t sumOfW1st7 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3585  Double_t sumOfW2nd7 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3586  Double_t sumOfWW7 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(7); // W_{<2>} * W_{<sin(phi1-phi2-phi3)>}
3587  // numerator in the expression for the the unbiased estimator for covariance:
3588  Double_t numerator7 = product7 - term1st7*term2nd7; 
3589  // denominator in the expression for the the unbiased estimator for covariance:
3590  Double_t denominator7 = 0.;
3591  if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
3592  {  
3593   denominator7 = 1.-sumOfWW7/(sumOfW1st7*sumOfW2nd7);
3594   if(TMath::Abs(denominator7)>0.)
3595   {   
3596    // covariance:
3597    Double_t covariance7 = numerator7/denominator7;
3598    // weight dependent prefactor for covariance:
3599    Double_t wPrefactor7 = sumOfWW7/(sumOfW1st7*sumOfW2nd7);
3600    // finally, store "weighted" covariance:
3601    fIntFlowCovariancesNUA->SetBinContent(7,wPrefactor7*covariance7);
3602   } // end of if(TMath::Abs(denominator7)>0.)
3603  } // end of if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
3604  
3605  // Cov(<4>,<cos(phi1>):
3606  Double_t product8 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(8); // <<4><cos(phi1)>> 
3607  Double_t term1st8 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3608  Double_t term2nd8 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3609  Double_t sumOfW1st8 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3610  Double_t sumOfW2nd8 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3611  Double_t sumOfWW8 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(8); // W_{<4>} * W_{<cos(phi1)>}
3612  // numerator in the expression for the the unbiased estimator for covariance:
3613  Double_t numerator8 = product8 - term1st8*term2nd8; 
3614  // denominator in the expression for the the unbiased estimator for covariance:
3615  Double_t denominator8 = 0.;
3616  if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
3617  { 
3618   denominator8 = 1.-sumOfWW8/(sumOfW1st8*sumOfW2nd8);
3619   if(TMath::Abs(denominator8)>0.)
3620   {     
3621    // covariance:
3622    Double_t covariance8 = numerator8/denominator8;
3623    // weight dependent prefactor for covariance:
3624    Double_t wPrefactor8 = sumOfWW8/(sumOfW1st8*sumOfW2nd8);
3625    // finally, store "weighted" covariance:
3626    fIntFlowCovariancesNUA->SetBinContent(8,wPrefactor8*covariance8);
3627   } // end of if(TMath::Abs(denominator8)>0.)
3628  } // end of if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
3629  
3630  // Cov(<4>,<sin(phi1)>):
3631  Double_t product9 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(9); // <<4><sin(phi1)>> 
3632  Double_t term1st9 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3633  Double_t term2nd9 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3634  Double_t sumOfW1st9 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3635  Double_t sumOfW2nd9 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3636  Double_t sumOfWW9 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(9); // W_{<4>} * W_{<sin(phi1)>}
3637  // numerator in the expression for the the unbiased estimator for covariance:
3638  Double_t numerator9 = product9 - term1st9*term2nd9; 
3639  // denominator in the expression for the the unbiased estimator for covariance:
3640  Double_t denominator9 = 0.;
3641  if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
3642  {
3643   denominator9 = 1.-sumOfWW9/(sumOfW1st9*sumOfW2nd9);
3644   if(TMath::Abs(denominator9)>0.)
3645   {     
3646    // covariance:
3647    Double_t covariance9 = numerator9/denominator9;
3648    // weight dependent prefactor for covariance:
3649    Double_t wPrefactor9 = sumOfWW9/(sumOfW1st9*sumOfW2nd9);
3650    // finally, store "weighted" covariance:
3651    fIntFlowCovariancesNUA->SetBinContent(9,wPrefactor9*covariance9); 
3652   }
3653  } // end of if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
3654  
3655  // Cov(<4>,<cos(phi1+phi2)>):
3656  Double_t product10 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(10); // <<4><cos(phi1+phi2)>> 
3657  Double_t term1st10 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3658  Double_t term2nd10 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3659  Double_t sumOfW1st10 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3660  Double_t sumOfW2nd10 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3661  Double_t sumOfWW10 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(10); // W_{<4>} * W_{<cos(phi1+phi2)>}
3662  // numerator in the expression for the the unbiased estimator for covariance:
3663  Double_t numerator10 = product10 - term1st10*term2nd10; 
3664  // denominator in the expression for the the unbiased estimator for covariance:
3665  Double_t denominator10 = 0.;
3666  if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
3667  { 
3668   denominator10 = 1.-sumOfWW10/(sumOfW1st10*sumOfW2nd10);
3669   if(TMath::Abs(denominator10)>0.) 
3670   { 
3671    // covariance:
3672    Double_t covariance10 = numerator10/denominator10;
3673    // weight dependent prefactor for covariance:
3674    Double_t wPrefactor10 = sumOfWW10/(sumOfW1st10*sumOfW2nd10);
3675    // finally, store "weighted" covariance:
3676    fIntFlowCovariancesNUA->SetBinContent(10,wPrefactor10*covariance10);
3677   } // end of if(TMath::Abs(denominator10)>0.) 
3678  } // end of if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
3679  
3680  // Cov(<4>,<sin(phi1+phi2)>):
3681  Double_t product11 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(11); // <<4><sin(phi1+phi2)>> 
3682  Double_t term1st11 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3683  Double_t term2nd11 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3684  Double_t sumOfW1st11 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3685  Double_t sumOfW2nd11 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3686  Double_t sumOfWW11 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(11); // W_{<4>} * W_{<sin(phi1+phi2)>}
3687  // numerator in the expression for the the unbiased estimator for covariance:
3688  Double_t numerator11 = product11 - term1st11*term2nd11; 
3689  // denominator in the expression for the the unbiased estimator for covariance:
3690  Double_t denominator11 = 0.;
3691  if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
3692  {  
3693   denominator11 = 1.-sumOfWW11/(sumOfW1st11*sumOfW2nd11);
3694   if(TMath::Abs(denominator11)>0.) 
3695   { 
3696    // covariance:
3697    Double_t covariance11 = numerator11/denominator11;
3698    // weight dependent prefactor for covariance:
3699    Double_t wPrefactor11 = sumOfWW11/(sumOfW1st11*sumOfW2nd11);
3700    // finally, store "weighted" covariance:
3701    fIntFlowCovariancesNUA->SetBinContent(11,wPrefactor11*covariance11);
3702   } // end of if(TMath::Abs(denominator11)>0.) 
3703  } // end of if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
3704
3705  // Cov(<4>,<cos(phi1-phi2-phi3)>):
3706  Double_t product12 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(12); // <<4><cos(phi1-phi2-phi3)>> 
3707  Double_t term1st12 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3708  Double_t term2nd12 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3709  Double_t sumOfW1st12 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3710  Double_t sumOfW2nd12 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3711  Double_t sumOfWW12 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(12); // W_{<4>} * W_{<cos(phi1-phi2-phi3)>}
3712  // numerator in the expression for the the unbiased estimator for covariance:
3713  Double_t numerator12 = product12 - term1st12*term2nd12; 
3714  // denominator in the expression for the the unbiased estimator for covariance:
3715  Double_t denominator12 = 0.;
3716  if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.) 
3717  {   
3718   denominator12 = 1.-sumOfWW12/(sumOfW1st12*sumOfW2nd12);
3719   if(TMath::Abs(denominator12)>0.) 
3720   { 
3721    // covariance:
3722    Double_t covariance12 = numerator12/denominator12;
3723    // weight dependent prefactor for covariance:
3724    Double_t wPrefactor12 = sumOfWW12/(sumOfW1st12*sumOfW2nd12);
3725    // finally, store "weighted" covariance:
3726    fIntFlowCovariancesNUA->SetBinContent(12,wPrefactor12*covariance12);
3727   } // end of if(TMath::Abs(denominator12)>0.)
3728  } // end of if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.)  
3729
3730  // Cov(<4>,<sin(phi1-phi2-phi3)>):
3731  Double_t product13 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(13); // <<4><sin(phi1-phi2-phi3)>> 
3732  Double_t term1st13 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3733  Double_t term2nd13 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3734  Double_t sumOfW1st13 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3735  Double_t sumOfW2nd13 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3736  Double_t sumOfWW13 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(13); // W_{<4>} * W_{<sin(phi1-phi2-phi3)>}
3737  // numerator in the expression for the the unbiased estimator for covariance:
3738  Double_t numerator13 = product13 - term1st13*term2nd13; 
3739  // denominator in the expression for the the unbiased estimator for covariance:
3740  Double_t denominator13 = 0.;
3741  if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
3742  {   
3743   denominator13 = 1.-sumOfWW13/(sumOfW1st13*sumOfW2nd13);
3744   if(TMath::Abs(denominator13)>0.) 
3745   { 
3746    // covariance:
3747    Double_t covariance13 = numerator13/denominator13;
3748    // weight dependent prefactor for covariance:
3749    Double_t wPrefactor13 = sumOfWW13/(sumOfW1st13*sumOfW2nd13);
3750    // finally, store "weighted" covariance:
3751    fIntFlowCovariancesNUA->SetBinContent(13,wPrefactor13*covariance13);
3752   } // end of if(TMath::Abs(denominator13)>0.) 
3753  } // end of if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
3754
3755  // Cov(<cos(phi1)>,<cos(phi1+phi2)>):
3756  Double_t product14 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(14); // <<cos(phi1)><cos(phi1+phi2)>> 
3757  Double_t term1st14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3758  Double_t term2nd14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3759  Double_t sumOfW1st14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3760  Double_t sumOfW2nd14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3761  Double_t sumOfWW14 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(14); // W_{<cos(phi1)>} * W_{<cos(phi1+phi2)>}
3762  // numerator in the expression for the the unbiased estimator for covariance:
3763  Double_t numerator14 = product14 - term1st14*term2nd14; 
3764  // denominator in the expression for the the unbiased estimator for covariance:
3765  Double_t denominator14 = 0.;
3766  if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
3767  {  
3768   denominator14 = 1.-sumOfWW14/(sumOfW1st14*sumOfW2nd14);
3769   if(TMath::Abs(denominator14)>0.) 
3770   { 
3771    // covariance:
3772    Double_t covariance14 = numerator14/denominator14;
3773    // weight dependent prefactor for covariance:
3774    Double_t wPrefactor14 = sumOfWW14/(sumOfW1st14*sumOfW2nd14);
3775    // finally, store "weighted" covariance:
3776    fIntFlowCovariancesNUA->SetBinContent(14,wPrefactor14*covariance14);
3777   } // end of if(TMath::Abs(denominator14)>0.) 
3778  } // end of if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
3779
3780  // Cov(<cos(phi1)>,<sin(phi1+phi2)>):
3781  Double_t product15 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(15); // <<cos(phi1)><sin(phi1+phi2)>> 
3782  Double_t term1st15 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3783  Double_t term2nd15 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3784  Double_t sumOfW1st15 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3785  Double_t sumOfW2nd15 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3786  Double_t sumOfWW15 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(15); // W_{<cos(phi1)>} * W_{<sin(phi1+phi2)>}
3787  // numerator in the expression for the the unbiased estimator for covariance:
3788  Double_t numerator15 = product15 - term1st15*term2nd15; 
3789  // denominator in the expression for the the unbiased estimator for covariance:
3790  Double_t denominator15 = 0.;
3791  if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.) 
3792  {  
3793   denominator15 = 1.-sumOfWW15/(sumOfW1st15*sumOfW2nd15);
3794   if(TMath::Abs(denominator15)>0.) 
3795   { 
3796    // covariance:
3797    Double_t covariance15 = numerator15/denominator15;
3798    // weight dependent prefactor for covariance:
3799    Double_t wPrefactor15 = sumOfWW15/(sumOfW1st15*sumOfW2nd15);
3800    // finally, store "weighted" covariance:
3801    fIntFlowCovariancesNUA->SetBinContent(15,wPrefactor15*covariance15);
3802   } // end of if(TMath::Abs(denominator15)>0.)  
3803  } // end of if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.)  
3804  
3805  // Cov(<cos(phi1)>,<cos(phi1-phi2-phi3)>):
3806  Double_t product16 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(16); // <<cos(phi1)><cos(phi1-phi2-phi3)>> 
3807  Double_t term1st16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3808  Double_t term2nd16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3809  Double_t sumOfW1st16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3810  Double_t sumOfW2nd16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3811  Double_t sumOfWW16 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(16); // W_{<cos(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
3812  // numerator in the expression for the the unbiased estimator for covariance:
3813  Double_t numerator16 = product16 - term1st16*term2nd16; 
3814  // denominator in the expression for the the unbiased estimator for covariance:
3815  Double_t denominator16 = 0.;
3816  if(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.) 
3817  {   
3818   denominator16 = 1.-sumOfWW16/(sumOfW1st16*sumOfW2nd16);
3819   if(TMath::Abs(denominator16)>0.) 
3820   {   
3821    // covariance:
3822    Double_t covariance16 = numerator16/denominator16;
3823    // weight dependent prefactor for covariance:
3824    Double_t wPrefactor16 = sumOfWW16/(sumOfW1st16*sumOfW2nd16);
3825    // finally, store "weighted" covariance:
3826    fIntFlowCovariancesNUA->SetBinContent(16,wPrefactor16*covariance16);
3827   } // end of if(TMath::Abs(denominator16)>0.)
3828  } // end ofif(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.)  
3829  
3830  // Cov(<cos(phi1)>,<sin(phi1-phi2-phi3)>):
3831  Double_t product17 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(17); // <<cos(phi1)><sin(phi1-phi2-phi3)>> 
3832  Double_t term1st17 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3833  Double_t term2nd17 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3834  Double_t sumOfW1st17 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3835  Double_t sumOfW2nd17 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3836  Double_t sumOfWW17 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(17); // W_{<cos(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
3837  // numerator in the expression for the the unbiased estimator for covariance:
3838  Double_t numerator17 = product17 - term1st17*term2nd17; 
3839  // denominator in the expression for the the unbiased estimator for covariance:
3840  Double_t denominator17 = 0.;
3841  if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
3842  {
3843   denominator17 = 1.-sumOfWW17/(sumOfW1st17*sumOfW2nd17);
3844   if(TMath::Abs(denominator17)>0.) 
3845   {   
3846    // covariance:
3847    Double_t covariance17 = numerator17/denominator17;
3848    // weight dependent prefactor for covariance:
3849    Double_t wPrefactor17 = sumOfWW17/(sumOfW1st17*sumOfW2nd17);
3850     // finally, store "weighted" covariance:
3851    fIntFlowCovariancesNUA->SetBinContent(17,wPrefactor17*covariance17);
3852   } // end of if(TMath::Abs(denominator17)>0.) 
3853  } // end of if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
3854
3855  // Cov(<sin(phi1)>,<cos(phi1+phi2)>):
3856  Double_t product18 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(18); // <<sin(phi1)><cos(phi1+phi2)>> 
3857  Double_t term1st18 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3858  Double_t term2nd18 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3859  Double_t sumOfW1st18 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3860  Double_t sumOfW2nd18 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3861  Double_t sumOfWW18 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(18); // W_{<sin(phi1)>} * W_{<cos(phi1+phi2)>}
3862  // numerator in the expression for the the unbiased estimator for covariance:
3863  Double_t numerator18 = product18 - term1st18*term2nd18; 
3864  // denominator in the expression for the the unbiased estimator for covariance:
3865  Double_t denominator18 = 0.;
3866  if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
3867  { 
3868   denominator18 = 1.-sumOfWW18/(sumOfW1st18*sumOfW2nd18);
3869   if(TMath::Abs(denominator18)>0.) 
3870   {   
3871    // covariance:
3872    Double_t covariance18 = numerator18/denominator18;
3873    // weight dependent prefactor for covariance:
3874    Double_t wPrefactor18 = sumOfWW18/(sumOfW1st18*sumOfW2nd18);
3875    // finally, store "weighted" covariance:
3876    fIntFlowCovariancesNUA->SetBinContent(18,wPrefactor18*covariance18); 
3877   } // end of if(TMath::Abs(denominator18)>0.) 
3878  } // end of if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
3879
3880  // Cov(<sin(phi1)>,<sin(phi1+phi2)>):
3881  Double_t product19 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(19); // <<sin(phi1)><sin(phi1+phi2)>> 
3882  Double_t term1st19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3883  Double_t term2nd19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3884  Double_t sumOfW1st19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3885  Double_t sumOfW2nd19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3886  Double_t sumOfWW19 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(19); // W_{<sin(phi1)>} * W_{<sin(phi1+phi2)>}
3887  // numerator in the expression for the the unbiased estimator for covariance:
3888  Double_t numerator19 = product19 - term1st19*term2nd19; 
3889  // denominator in the expression for the the unbiased estimator for covariance:
3890  Double_t denominator19 = 0.;
3891  if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.) 
3892  { 
3893   denominator19 = 1.-sumOfWW19/(sumOfW1st19*sumOfW2nd19);
3894   if(TMath::Abs(denominator19)>0.) 
3895   {   
3896    // covariance:
3897    Double_t covariance19 = numerator19/denominator19;
3898    // weight dependent prefactor for covariance:
3899    Double_t wPrefactor19 = sumOfWW19/(sumOfW1st19*sumOfW2nd19);
3900    // finally, store "weighted" covariance:
3901    fIntFlowCovariancesNUA->SetBinContent(19,wPrefactor19*covariance19);
3902   } // end of if(TMath::Abs(denominator19)>0.)
3903  } // end of if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.)
3904  
3905  // Cov(<sin(phi1)>,<cos(phi1-phi2-phi3)>):
3906  Double_t product20 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(20); // <<sin(phi1)><cos(phi1-phi2-phi3)>> 
3907  Double_t term1st20 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3908  Double_t term2nd20 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3909  Double_t sumOfW1st20 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3910  Double_t sumOfW2nd20 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3911  Double_t sumOfWW20 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(20); // W_{<sin(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
3912  // numerator in the expression for the the unbiased estimator for covariance:
3913  Double_t numerator20 = product20 - term1st20*term2nd20; 
3914  // denominator in the expression for the the unbiased estimator for covariance:
3915  Double_t denominator20 = 0.;
3916  if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
3917  { 
3918   denominator20 = 1.-sumOfWW20/(sumOfW1st20*sumOfW2nd20);
3919   if(TMath::Abs(denominator20)>0.) 
3920   { 
3921    // covariance:
3922    Double_t covariance20 = numerator20/denominator20;
3923    // weight dependent prefactor for covariance:
3924    Double_t wPrefactor20 = sumOfWW20/(sumOfW1st20*sumOfW2nd20);
3925    // finally, store "weighted" covariance:
3926    fIntFlowCovariancesNUA->SetBinContent(20,wPrefactor20*covariance20);
3927   } // end of if(TMath::Abs(denominator20)>0.) 
3928  } // end of if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
3929
3930  // Cov(<sin(phi1)>,<sin(phi1-phi2-phi3)>):
3931  Double_t product21 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(21); // <<sin(phi1)><sin(phi1-phi2-phi3)>> 
3932  Double_t term1st21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3933  Double_t term2nd21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3934  Double_t sumOfW1st21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3935  Double_t sumOfW2nd21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3936  Double_t sumOfWW21 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(21); // W_{<sin(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
3937  // numerator in the expression for the the unbiased estimator for covariance:
3938  Double_t numerator21 = product21 - term1st21*term2nd21; 
3939  // denominator in the expression for the the unbiased estimator for covariance:
3940  Double_t denominator21 = 0.;
3941  if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
3942  { 
3943   denominator21 = 1.-sumOfWW21/(sumOfW1st21*sumOfW2nd21);
3944   if(TMath::Abs(denominator21)>0.) 
3945   {   
3946    // covariance:
3947    Double_t covariance21 = numerator21/denominator21;
3948    // weight dependent prefactor for covariance:
3949    Double_t wPrefactor21 = sumOfWW21/(sumOfW1st21*sumOfW2nd21);
3950    // finally, store "weighted" covariance:
3951    fIntFlowCovariancesNUA->SetBinContent(21,wPrefactor21*covariance21);
3952   } // end of if(TMath::Abs(denominator21)>0.)
3953  } // end of if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
3954
3955  // Cov(<cos(phi1+phi2)>,<sin(phi1+phi2)>):
3956  Double_t product22 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(22); // <<cos(phi1+phi2)><sin(phi1+phi2)>> 
3957  Double_t term1st22 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3958  Double_t term2nd22 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3959  Double_t sumOfW1st22 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3960  Double_t sumOfW2nd22 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3961  Double_t sumOfWW22 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(22); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1+phi2)>}
3962  // numerator in the expression for the the unbiased estimator for covariance:
3963  Double_t numerator22 = product22 - term1st22*term2nd22; 
3964  // denominator in the expression for the the unbiased estimator for covariance:
3965  Double_t denominator22 = 0.;
3966  if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.)
3967  { 
3968   denominator22 = 1.-sumOfWW22/(sumOfW1st22*sumOfW2nd22);
3969   if(TMath::Abs(denominator22)>0.) 
3970   {   
3971    // covariance:
3972    Double_t covariance22 = numerator22/denominator22;
3973    // weight dependent prefactor for covariance:
3974    Double_t wPrefactor22 = sumOfWW22/(sumOfW1st22*sumOfW2nd22);
3975    // finally, store "weighted" covariance:
3976    fIntFlowCovariancesNUA->SetBinContent(22,wPrefactor22*covariance22);
3977   } // end of if(TMath::Abs(denominator22)>0.) 
3978  } // end of if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.) 
3979
3980  // Cov(<cos(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
3981  Double_t product23 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(23); // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>> 
3982  Double_t term1st23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3983  Double_t term2nd23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3984  Double_t sumOfW1st23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3985  Double_t sumOfW2nd23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3986  Double_t sumOfWW23 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(23); // W_{<cos(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
3987  // numerator in the expression for the the unbiased estimator for covariance:
3988  Double_t numerator23 = product23 - term1st23*term2nd23; 
3989  // denominator in the expression for the the unbiased estimator for covariance:
3990  Double_t denominator23 = 0.;
3991  if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
3992  {  
3993   denominator23 = 1.-sumOfWW23/(sumOfW1st23*sumOfW2nd23);
3994   if(TMath::Abs(denominator23)>0.) 
3995   {   
3996    // covariance:
3997    Double_t covariance23 = numerator23/denominator23;
3998    // weight dependent prefactor for covariance:
3999    Double_t wPrefactor23 = sumOfWW23/(sumOfW1st23*sumOfW2nd23);
4000    // finally, store "weighted" covariance:
4001    fIntFlowCovariancesNUA->SetBinContent(23,wPrefactor23*covariance23);
4002   } // end of if(TMath::Abs(denominator23)>0.) 
4003  } // end of if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
4004  
4005  // Cov(<cos(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4006  Double_t product24 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(24); // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4007  Double_t term1st24 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4008  Double_t term2nd24 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4009  Double_t sumOfW1st24 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4010  Double_t sumOfW2nd24 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4011  Double_t sumOfWW24 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(24); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4012  // numerator in the expression for the the unbiased estimator for covariance:
4013  Double_t numerator24 = product24 - term1st24*term2nd24; 
4014  // denominator in the expression for the the unbiased estimator for covariance:
4015  Double_t denominator24 = 0.;
4016  if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4017  {   
4018   denominator24 = 1.-sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4019   if(TMath::Abs(denominator24)>0.) 
4020   {   
4021    // covariance:
4022    Double_t covariance24 = numerator24/denominator24;
4023    // weight dependent prefactor for covariance:
4024    Double_t wPrefactor24 = sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4025    // finally, store "weighted" covariance:
4026    fIntFlowCovariancesNUA->SetBinContent(24,wPrefactor24*covariance24);
4027   } // end of if(TMath::Abs(denominator24)>0.)  
4028  } // end of if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4029
4030  // Cov(<sin(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
4031  Double_t product25 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(25); // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>> 
4032  Double_t term1st25 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4033  Double_t term2nd25 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4034  Double_t sumOfW1st25 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4035  Double_t sumOfW2nd25 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4036  Double_t sumOfWW25 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(25); // W_{<sin(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
4037  // numerator in the expression for the the unbiased estimator for covariance:
4038  Double_t numerator25 = product25 - term1st25*term2nd25; 
4039  // denominator in the expression for the the unbiased estimator for covariance:
4040  Double_t denominator25 = 0.;
4041  if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4042  { 
4043   denominator25 = 1.-sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4044   if(TMath::Abs(denominator25)>0.) 
4045   { 
4046    // covariance:
4047    Double_t covariance25 = numerator25/denominator25;
4048    // weight dependent prefactor for covariance:
4049    Double_t wPrefactor25 = sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4050    // finally, store "weighted" covariance:
4051    fIntFlowCovariancesNUA->SetBinContent(25,wPrefactor25*covariance25);
4052   } // end of if(TMath::Abs(denominator25)>0.)
4053  } // end of if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4054  
4055  // Cov(<sin(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4056  Double_t product26 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(26); // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4057  Double_t term1st26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4058  Double_t term2nd26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4059  Double_t sumOfW1st26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4060  Double_t sumOfW2nd26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4061  Double_t sumOfWW26 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(26); // W_{<sin(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4062  // numerator in the expression for the the unbiased estimator for covariance:
4063  Double_t numerator26 = product26 - term1st26*term2nd26; 
4064  // denominator in the expression for the the unbiased estimator for covariance:
4065  Double_t denominator26 = 0.;
4066  if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4067  { 
4068   denominator26 = 1.-sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4069   if(TMath::Abs(denominator26)>0.) 
4070   { 
4071    // covariance:
4072    Double_t covariance26 = numerator26/denominator26;
4073    // weight dependent prefactor for covariance:
4074    Double_t wPrefactor26 = sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4075    // finally, store "weighted" covariance:
4076    fIntFlowCovariancesNUA->SetBinContent(26,wPrefactor26*covariance26);
4077   } // end of if(TMath::Abs(denominator26)>0.) 
4078  } // end of if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4079  
4080  // Cov(<cos(phi1-phi2-phi3)>,<sin(phi1-phi2-phi3)>):
4081  Double_t product27 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(27); // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>> 
4082  Double_t term1st27 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4083  Double_t term2nd27 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4084  Double_t sumOfW1st27 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4085  Double_t sumOfW2nd27 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4086  Double_t sumOfWW27 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(27); // W_{<cos(phi1-phi2-phi3)>} * W_{<sin(phi1-phi2-phi3)>}
4087  // numerator in the expression for the the unbiased estimator for covariance:
4088  Double_t numerator27 = product27 - term1st27*term2nd27; 
4089  // denominator in the expression for the the unbiased estimator for covariance:
4090  Double_t denominator27 = 0.;
4091  if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4092  { 
4093   denominator27 = 1.-sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4094   if(TMath::Abs(denominator27)>0.) 
4095   { 
4096    // covariance:
4097    Double_t covariance27 = numerator27/denominator27;
4098    // weight dependent prefactor for covariance:
4099    Double_t wPrefactor27 = sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4100    // finally, store "weighted" covariance:
4101    fIntFlowCovariancesNUA->SetBinContent(27,wPrefactor27*covariance27);
4102   } // end of if(TMath::Abs(denominator27)>0.) 
4103  } // end of if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4104  
4105 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
4106
4107 //================================================================================================================================
4108
4109 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow() 
4110 {
4111  // From profile fIntFlowCorrelationsPro access measured correlations and spread, 
4112  // correctly calculate the statistical errors and store the final results and 
4113  // statistical errors for correlations in histogram fIntFlowCorrelationsHist.
4114  //
4115  // Remark: Statistical error of correlation is calculated as:
4116  //
4117  //          statistical error = termA * spread * termB:
4118  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
4119  //          termB = 1/sqrt(1-termA^2)   
4120  //
4121    
4122  for(Int_t ci=1;ci<=4;ci++) // correlation index
4123  {
4124   if(fIntFlowCorrelationsPro->GetBinEffectiveEntries(ci) < 2 || fIntFlowSquaredCorrelationsPro->GetBinEffectiveEntries(ci) < 2)
4125   {
4126    fIntFlowCorrelationsPro->SetBinError(ci,0.);
4127    fIntFlowSquaredCorrelationsPro->SetBinError(ci,0.);
4128    continue;
4129   } 
4130   Double_t correlation = fIntFlowCorrelationsPro->GetBinContent(ci);
4131   Double_t squaredCorrelation = fIntFlowSquaredCorrelationsPro->GetBinContent(ci);
4132   Double_t spread = 0.;
4133   if(squaredCorrelation-correlation*correlation >= 0.)
4134   {
4135    spread = pow(squaredCorrelation-correlation*correlation,0.5);
4136   } else
4137     {
4138      cout<<endl;
4139      cout<<Form(" WARNING: Imaginary 'spread' for %d-particle correlation!!!! ",2*ci)<<endl;
4140      cout<<endl;
4141     }
4142   Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeights[0]->GetBinContent(ci);
4143   Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeights[1]->GetBinContent(ci);
4144   Double_t termA = 0.;
4145   Double_t termB = 0.;
4146   if(TMath::Abs(sumOfLinearEventWeights) > 0.) // to be improved - shall I omitt here Abs() ?
4147   {
4148    termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
4149   } else
4150     {
4151      cout<<endl;
4152      cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;
4153      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4154      cout<<endl;
4155     }
4156   if(1.-pow(termA,2.) > 0.)
4157   {
4158    termB = 1./pow(1-pow(termA,2.),0.5);
4159   } else
4160     {
4161      cout<<endl;
4162      cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;   
4163      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4164      cout<<endl;
4165     }     
4166   Double_t statisticalError = termA * spread * termB;
4167   fIntFlowCorrelationsHist->SetBinContent(ci,correlation);
4168   fIntFlowCorrelationsHist->SetBinError(ci,statisticalError);
4169  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index     
4170  
4171  // Versus multiplicity: 
4172  if(!fCalculateCumulantsVsM){return;}
4173  for(Int_t ci=0;ci<=3;ci++) // correlation index
4174  {
4175   Int_t nBins = fIntFlowCorrelationsVsMPro[ci]->GetNbinsX(); 
4176   for(Int_t b=1;b<=nBins;b++) // looping over multiplicity bins
4177   {
4178    if(fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2 || fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2)
4179    {
4180     fIntFlowCorrelationsVsMPro[ci]->SetBinError(b,0.);
4181     fIntFlowSquaredCorrelationsVsMPro[ci]->SetBinError(b,0.);
4182     continue;
4183    } 
4184    Double_t correlationVsM = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
4185    Double_t squaredCorrelationVsM = fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinContent(b);
4186    Double_t spreadVsM = 0.;
4187    if(squaredCorrelationVsM-correlationVsM*correlationVsM >= 0.)
4188    {
4189     spreadVsM = pow(squaredCorrelationVsM-correlationVsM*correlationVsM,0.5);
4190    } else
4191      {
4192       cout<<endl;
4193       cout<<Form(" WARNING (QC): Imaginary 'spreadVsM' for ci = %d, bin = %d, entries = %f !!!!",
4194                  ci,b,fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b))<<endl; 
4195       cout<<endl;
4196      }     
4197    Double_t sumOfLinearEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][0]->GetBinContent(b);
4198    Double_t sumOfQuadraticEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][1]->GetBinContent(b);
4199    Double_t termAVsM = 0.;
4200    Double_t termBVsM = 0.;
4201    if(sumOfLinearEventWeightsVsM > 0.) 
4202    {
4203     termAVsM = pow(sumOfQuadraticEventWeightsVsM,0.5)/sumOfLinearEventWeightsVsM;
4204    }
4205    if(1.-pow(termAVsM,2.) > 0.)
4206    {
4207     termBVsM = 1./pow(1-pow(termAVsM,2.),0.5);
4208    }     
4209    Double_t statisticalErrorVsM = termAVsM * spreadVsM * termBVsM;
4210    fIntFlowCorrelationsVsMHist[ci]->SetBinContent(b,correlationVsM);
4211    fIntFlowCorrelationsVsMHist[ci]->SetBinError(b,statisticalErrorVsM);  
4212   } // end of for(Int_t b=1;b<=nBins;b++)
4213  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index                                                        
4214                                                                                                                            
4215 } // end of AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow()
4216
4217 //================================================================================================================================
4218
4219 void AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(Int_t nRP)
4220 {
4221  // Fill profile fAverageMultiplicity to hold average multiplicities and 
4222  // number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
4223  
4224  // Binning of fAverageMultiplicity is organized as follows:
4225  //  1st bin: all events (including the empty ones)
4226  //  2nd bin: event with # of RPs greater or equal to 1
4227  //  3rd bin: event with # of RPs greater or equal to 2
4228  //  4th bin: event with # of RPs greater or equal to 3
4229  //  5th bin: event with # of RPs greater or equal to 4
4230  //  6th bin: event with # of RPs greater or equal to 5
4231  //  7th bin: event with # of RPs greater or equal to 6
4232  //  8th bin: event with # of RPs greater or equal to 7
4233  //  9th bin: event with # of RPs greater or equal to 8
4234  
4235  if(nRP<0)
4236  {
4237   cout<<endl;
4238   cout<<" WARNING (QC): nRP<0 in in AFAWQC::FAM() !!!!"<<endl;
4239   cout<<endl;
4240   exit(0);
4241  }
4242  
4243  for(Int_t i=0;i<9;i++)
4244  {
4245   if(nRP>=i){fAvMultiplicity->Fill(i+0.5,nRP,1);}
4246  }
4247  
4248 } // end of AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(nRP)
4249
4250 //================================================================================================================================
4251
4252 void AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
4253
4254  // a) Calculate Q-cumulants from the measured multiparticle correlations;
4255  // b) Propagate the statistical errors from measured multiparticle correlations to statistical errors of Q-cumulants;  
4256  // c) Remark: Q-cumulants calculated in this method are biased by non-uniform acceptance of detector !!!! 
4257  //            Method CalculateQcumulantsCorrectedForNUAIntFlow() is called afterwards to correct for this bias;
4258  // d) Store the results and statistical error of Q-cumulants in histogram fIntFlowQcumulants.
4259  //    Binning of fIntFlowQcumulants is organized as follows:
4260  //
4261  //            1st bin: QC{2}
4262  //            2nd bin: QC{4}
4263  //            3rd bin: QC{6}
4264  //            4th bin: QC{8}
4265  //
4266  
4267  // Correlations:
4268  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
4269  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
4270  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
4271  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
4272  // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
4273  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
4274  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
4275  Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
4276  Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
4277  // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
4278  Double_t wCov24 = 0.; // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4279  Double_t wCov26 = 0.; // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4280  Double_t wCov28 = 0.; // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4281  Double_t wCov46 = 0.; // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4282  Double_t wCov48 = 0.; // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4283  Double_t wCov68 = 0.; // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>)  
4284  if(!fForgetAboutCovariances)
4285  {
4286   wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4287   wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4288   wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4289   wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4290   wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4291   wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
4292  }
4293  // Q-cumulants: 
4294  Double_t qc2 = 0.; // QC{2}
4295  Double_t qc4 = 0.; // QC{4}
4296  Double_t qc6 = 0.; // QC{6}
4297  Double_t qc8 = 0.; // QC{8}
4298  if(TMath::Abs(two) > 0.){qc2 = two;} 
4299  if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
4300  if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
4301  if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);} 
4302  // Statistical errors of Q-cumulants:       
4303  Double_t qc2Error = 0.;
4304  Double_t qc4Error = 0.;
4305  Double_t qc6Error = 0.;
4306  Double_t qc8Error = 0.; 
4307  // Squared statistical errors of Q-cumulants:       
4308  //Double_t qc2ErrorSquared = 0.;
4309  Double_t qc4ErrorSquared = 0.;
4310  Double_t qc6ErrorSquared = 0.;
4311  Double_t qc8ErrorSquared = 0.;        
4312  // Statistical error of QC{2}:              
4313  qc2Error = twoError;                                                 
4314  // Statistical error of QC{4}:              
4315  qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
4316                  - 8.*two*wCov24;                     
4317  if(qc4ErrorSquared>0.)
4318  {
4319   qc4Error = pow(qc4ErrorSquared,0.5);
4320  } else 
4321    {
4322     cout<<" WARNING (QC): Statistical error of QC{4} is imaginary !!!!"<<endl;
4323    }                                           
4324  // Statistical error of QC{6}:              
4325  qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
4326                  + 81.*pow(two,2.)*pow(fourError,2.)
4327                  + pow(sixError,2.)
4328                  - 162.*two*(4.*pow(two,2.)-four)*wCov24
4329                  + 18.*(4.*pow(two,2.)-four)*wCov26
4330                  - 18.*two*wCov46;                     
4331  if(qc6ErrorSquared>0.)
4332  {
4333   qc6Error = pow(qc6ErrorSquared,0.5);
4334  } else 
4335    {
4336     cout<<" WARNING (QC): Statistical error of QC{6} is imaginary !!!!"<<endl;
4337    }                       
4338  // Statistical error of QC{8}:              
4339  qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
4340                  + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
4341                  + 256.*pow(two,2.)*pow(sixError,2.)
4342                  + pow(eightError,2.)
4343                  - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
4344                  + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
4345                  - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
4346                  - 1152.*two*(4.*pow(two,2.)-four)*wCov46
4347                  + 72.*(4.*pow(two,2.)-four)*wCov48
4348                  - 32.*two*wCov68;      
4349  if(qc8ErrorSquared>0.)
4350  {
4351   qc8Error = pow(qc8ErrorSquared,0.5);
4352  } else 
4353    {
4354     cout<<"WARNING (QC): Statistical error of QC{8} is imaginary !!!!"<<endl;
4355    }
4356  // Store the results and statistical errors for Q-cumulants:
4357  if(TMath::Abs(qc2)>0.)
4358  {
4359   fIntFlowQcumulants->SetBinContent(1,qc2);
4360   fIntFlowQcumulants->SetBinError(1,qc2Error);
4361  }
4362  if(TMath::Abs(qc4)>0.)
4363  {
4364   fIntFlowQcumulants->SetBinContent(2,qc4);
4365   fIntFlowQcumulants->SetBinError(2,qc4Error);
4366  }
4367  if(TMath::Abs(qc6)>0.)
4368  {
4369   fIntFlowQcumulants->SetBinContent(3,qc6);
4370   fIntFlowQcumulants->SetBinError(3,qc6Error);
4371  }
4372  if(TMath::Abs(qc8)>0.)
4373  {
4374   fIntFlowQcumulants->SetBinContent(4,qc8); 
4375   fIntFlowQcumulants->SetBinError(4,qc8Error);
4376  } 
4377  
4378  // Versus multiplicity: 
4379  if(!fCalculateCumulantsVsM){return;}
4380  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
4381  Double_t value[4] = {0.}; // QCs vs M
4382  Double_t error[4] = {0.}; // error of QCs vs M
4383  Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
4384  Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
4385  for(Int_t b=1;b<=nBins;b++)
4386  {
4387   // Correlations:
4388   two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> 
4389   four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>>  
4390   six = fIntFlowCorrelationsVsMHist[2]->GetBinContent(b); // <<6>> 
4391   eight = fIntFlowCorrelationsVsMHist[3]->GetBinContent(b); // <<8>>  
4392   // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
4393   twoError = fIntFlowCorrelationsVsMHist[0]->GetBinError(b); // statistical error of <2>  
4394   fourError = fIntFlowCorrelationsVsMHist[1]->GetBinError(b); // statistical error of <4>   
4395   sixError = fIntFlowCorrelationsVsMHist[2]->GetBinError(b); // statistical error of <6> 
4396   eightError = fIntFlowCorrelationsVsMHist[3]->GetBinError(b); // statistical error of <8> 
4397   // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
4398   if(!fForgetAboutCovariances)
4399   {
4400    wCov24 = fIntFlowCovariancesVsM[0]->GetBinContent(b); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4401    wCov26 = fIntFlowCovariancesVsM[1]->GetBinContent(b); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4402    wCov28 = fIntFlowCovariancesVsM[2]->GetBinContent(b); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4403    wCov46 = fIntFlowCovariancesVsM[3]->GetBinContent(b); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4404    wCov48 = fIntFlowCovariancesVsM[4]->GetBinContent(b); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4405    wCov68 = fIntFlowCovariancesVsM[5]->GetBinContent(b); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
4406   }
4407   // Q-cumulants: 
4408   qc2 = 0.; // QC{2}
4409   qc4 = 0.; // QC{4}
4410   qc6 = 0.; // QC{6}
4411   qc8 = 0.; // QC{8}
4412   if(TMath::Abs(two) > 0.){qc2 = two;} 
4413   if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
4414   if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
4415   if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);}  
4416   // Statistical errors of Q-cumulants:       
4417   qc2Error = 0.;
4418   qc4Error = 0.;
4419   qc6Error = 0.;
4420   qc8Error = 0.; 
4421   // Squared statistical errors of Q-cumulants:       
4422   //Double_t qc2ErrorSquared = 0.;
4423   qc4ErrorSquared = 0.;
4424   qc6ErrorSquared = 0.;
4425   qc8ErrorSquared = 0.;    
4426   // Statistical error of QC{2}:              
4427   qc2Error = twoError;                                             
4428   // Statistical error of QC{4}:              
4429   qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
4430                   - 8.*two*wCov24;                     
4431   if(qc4ErrorSquared>0.)
4432   {
4433    qc4Error = pow(qc4ErrorSquared,0.5);
4434   } else 
4435     {
4436      // cout<<"WARNING: Statistical error of QC{4} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4437     }                                       
4438   // Statistical error of QC{6}:              
4439   qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
4440                   + 81.*pow(two,2.)*pow(fourError,2.)
4441                   + pow(sixError,2.)
4442                   - 162.*two*(4.*pow(two,2.)-four)*wCov24
4443                   + 18.*(4.*pow(two,2.)-four)*wCov26
4444                   - 18.*two*wCov46;                     
4445   if(qc6ErrorSquared>0.)
4446   {
4447    qc6Error = pow(qc6ErrorSquared,0.5);
4448   } else 
4449     {
4450      // cout<<"WARNING: Statistical error of QC{6} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4451     }                            
4452   // Statistical error of QC{8}:              
4453   qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
4454                   + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
4455                   + 256.*pow(two,2.)*pow(sixError,2.)
4456                   + pow(eightError,2.)
4457                   - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
4458                   + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
4459                   - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
4460                   - 1152.*two*(4.*pow(two,2.)-four)*wCov46
4461                   + 72.*(4.*pow(two,2.)-four)*wCov48
4462                   - 32.*two*wCov68;      
4463   if(qc8ErrorSquared>0.)
4464   {
4465    qc8Error = pow(qc8ErrorSquared,0.5);
4466   } else 
4467     {
4468      // cout<<"WARNING: Statistical error of QC{8} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4469     }
4470   // Store the results and statistical errors for Q-cumulants:
4471   if(TMath::Abs(qc2)>0.)
4472   {
4473    fIntFlowQcumulantsVsM[0]->SetBinContent(b,qc2);
4474    fIntFlowQcumulantsVsM[0]->SetBinError(b,qc2Error);  
4475   }
4476   if(TMath::Abs(qc4)>0.)
4477   {
4478    fIntFlowQcumulantsVsM[1]->SetBinContent(b,qc4);  
4479    fIntFlowQcumulantsVsM[1]->SetBinError(b,qc4Error);
4480   }
4481   if(TMath::Abs(qc6)>0.)
4482   {
4483    fIntFlowQcumulantsVsM[2]->SetBinContent(b,qc6); 
4484    fIntFlowQcumulantsVsM[2]->SetBinError(b,qc6Error);
4485   }
4486   if(TMath::Abs(qc8)>0.)
4487   {  
4488    fIntFlowQcumulantsVsM[3]->SetBinContent(b,qc8);
4489    fIntFlowQcumulantsVsM[3]->SetBinError(b,qc8Error);
4490   } 
4491   // Rebin in M:
4492   for(Int_t co=0;co<4;co++)
4493   {
4494    if(fIntFlowCorrelationsVsMPro[co]->GetBinEffectiveEntries(b)<2){continue;}
4495    value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
4496    error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
4497    if(error[co]>0.)
4498    {
4499     dSum1[co]+=value[co]/(error[co]*error[co]);
4500     dSum2[co]+=1./(error[co]*error[co]);
4501    }
4502   } // end of for(Int_t co=0;co<4;co++) 
4503  } // end of for(Int_t b=1;b<=nBins;b++)
4504  // Store rebinned Q-cumulants:
4505  for(Int_t co=0;co<4;co++)
4506  {
4507   if(dSum2[co]>0.)
4508   {
4509    fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
4510    fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
4511   }
4512  } // end of for(Int_t co=0;co<4;co++)
4513  
4514 } // end of AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
4515
4516 //================================================================================================================================ 
4517
4518 void AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
4519 {
4520  // a) Calculate the final results for reference flow estimates from Q-cumulants;
4521  // b) Propagate the statistical errors to reference flow estimates from statistical error of Q-cumulants; 
4522  // c) Store the results and statistical errors of reference flow estimates in histogram fIntFlow.
4523  //    Binning of fIntFlow is organized as follows:
4524  //
4525  //            1st bin: v{2,QC}
4526  //            2nd bin: v{4,QC}
4527  //            3rd bin: v{6,QC}
4528  //            4th bin: v{8,QC}
4529  //
4530  
4531  // Reference flow estimates:
4532  Double_t v2 = 0.; // v{2,QC}  
4533  Double_t v4 = 0.; // v{4,QC}  
4534  Double_t v6 = 0.; // v{6,QC}  
4535  Double_t v8 = 0.; // v{8,QC}
4536  // Reference flow's statistical errors:
4537  Double_t v2Error = 0.; // v{2,QC} stat. error 
4538  Double_t v4Error = 0.; // v{4,QC} stat. error
4539  Double_t v6Error = 0.; // v{6,QC} stat. error
4540  Double_t v8Error = 0.; // v{8,QC} stat. error
4541   
4542  // Q-cumulants:
4543  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
4544  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
4545  Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
4546  Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
4547  // Q-cumulants's statistical errors: 
4548  Double_t qc2Error = fIntFlowQcumulants->GetBinError(1); // QC{2} stat. error  
4549  Double_t qc4Error = fIntFlowQcumulants->GetBinError(2); // QC{4} stat. error  
4550  Double_t qc6Error = fIntFlowQcumulants->GetBinError(3); // QC{6} stat. error  
4551  Double_t qc8Error = fIntFlowQcumulants->GetBinError(4); // QC{8} stat. error
4552  // Calculate reference flow estimates from Q-cumulants: 
4553  if(qc2>=0.){v2 = pow(qc2,1./2.);} 
4554  if(qc4<=0.){v4 = pow(-1.*qc4,1./4.);} 
4555  if(qc6>=0.){v6 = pow((1./4.)*qc6,1./6.);}
4556  if(qc8<=0.){v8 = pow((-1./33.)*qc8,1./8.);}  
4557  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants:  
4558  if(qc2>0.){v2Error = (1./2.)*pow(qc2,-1./2.)*qc2Error;} 
4559  if(qc4<0.){v4Error = (1./4.)*pow(-qc4,-3./4.)*qc4Error;} 
4560  if(qc6>0.){v6Error = (1./6.)*pow(2.,-1./3.)*pow(qc6,-5./6.)*qc6Error;}   
4561  if(qc8<0.){v8Error = (1./8.)*pow(33.,-1./8.)*pow(-qc8,-7./8.)*qc8Error;}   
4562  // Print warnings for the 'wrong sign' cumulants: 
4563  if(TMath::Abs(v2) < 1.e-44)
4564  {
4565   cout<<" WARNING: Wrong sign QC{2}, couldn't calculate v{2,QC} !!!!"<<endl;
4566  }
4567  if(TMath::Abs(v4) < 1.e-44)
4568  {
4569   cout<<" WARNING: Wrong sign QC{4}, couldn't calculate v{4,QC} !!!!"<<endl;
4570  } 
4571  if(TMath::Abs(v6) < 1.e-44)
4572  {
4573   cout<<" WARNING: Wrong sign QC{6}, couldn't calculate v{6,QC} !!!!"<<endl; 
4574  }
4575  if(TMath::Abs(v8) < 1.e-44)
4576  {
4577   cout<<" WARNING: Wrong sign QC{8}, couldn't calculate v{8,QC} !!!!"<<endl;
4578  }                       
4579  // Store the results and statistical errors of integrated flow estimates:
4580  fIntFlow->SetBinContent(1,v2);
4581  fIntFlow->SetBinError(1,v2Error);
4582  fIntFlow->SetBinContent(2,v4);
4583  fIntFlow->SetBinError(2,v4Error);
4584  fIntFlow->SetBinContent(3,v6);
4585  fIntFlow->SetBinError(3,v6Error);
4586  fIntFlow->SetBinContent(4,v8);
4587  fIntFlow->SetBinError(4,v8Error);  
4588   
4589  // Versus multiplicity: 
4590  if(!fCalculateCumulantsVsM){return;} 
4591  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
4592  for(Int_t b=1;b<=nBins;b++)
4593  {
4594   // Q-cumulants:
4595   Double_t qc2VsM = fIntFlowQcumulantsVsM[0]->GetBinContent(b); // QC{2}  
4596   Double_t qc4VsM = fIntFlowQcumulantsVsM[1]->GetBinContent(b); // QC{4}  
4597   Double_t qc6VsM = fIntFlowQcumulantsVsM[2]->GetBinContent(b); // QC{6}  
4598   Double_t qc8VsM = fIntFlowQcumulantsVsM[3]->GetBinContent(b); // QC{8}
4599   // Q-cumulants's statistical errors: 
4600   Double_t qc2ErrorVsM = fIntFlowQcumulantsVsM[0]->GetBinError(b); // QC{2} stat. error  
4601   Double_t qc4ErrorVsM = fIntFlowQcumulantsVsM[1]->GetBinError(b); // QC{4} stat. error  
4602   Double_t qc6ErrorVsM = fIntFlowQcumulantsVsM[2]->GetBinError(b); // QC{6} stat. error  
4603   Double_t qc8ErrorVsM = fIntFlowQcumulantsVsM[3]->GetBinError(b); // QC{8} stat. error
4604   // Reference flow estimates:
4605   Double_t v2VsM = 0.; // v{2,QC}  
4606   Double_t v4VsM = 0.; // v{4,QC}  
4607   Double_t v6VsM = 0.; // v{6,QC}  
4608   Double_t v8VsM = 0.; // v{8,QC}
4609   // Reference flow estimates errors:
4610   Double_t v2ErrorVsM = 0.; // v{2,QC} stat. error  
4611   Double_t v4ErrorVsM = 0.; // v{4,QC} stat. error
4612   Double_t v6ErrorVsM = 0.; // v{6,QC} stat. error  
4613   Double_t v8ErrorVsM = 0.; // v{8,QC} stat. error
4614   // Calculate reference flow estimates from Q-cumulants: 
4615   if(qc2VsM>=0.){v2VsM = pow(qc2VsM,1./2.);} 
4616   if(qc4VsM<=0.){v4VsM = pow(-1.*qc4VsM,1./4.);} 
4617   if(qc6VsM>=0.){v6VsM = pow((1./4.)*qc6VsM,1./6.);}
4618   if(qc8VsM<=0.){v8VsM = pow((-1./33.)*qc8VsM,1./8.);}  
4619   // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
4620   if(qc2VsM>0.){v2ErrorVsM = (1./2.)*pow(qc2VsM,-1./2.)*qc2ErrorVsM;} 
4621   if(qc4VsM<0.){v4ErrorVsM = (1./4.)*pow(-qc4VsM,-3./4.)*qc4ErrorVsM;} 
4622   if(qc6VsM>0.){v6ErrorVsM = (1./6.)*pow(2.,-1./3.)*pow(qc6VsM,-5./6.)*qc6ErrorVsM;}   
4623   if(qc8VsM<0.){v8ErrorVsM = (1./8.)*pow(33.,-1./8.)*pow(-qc8VsM,-7./8.)*qc8ErrorVsM;}                       
4624   // Store the results and statistical errors of integrated flow estimates:
4625   fIntFlowVsM[0]->SetBinContent(b,v2VsM);
4626   fIntFlowVsM[0]->SetBinError(b,v2ErrorVsM);
4627   fIntFlowVsM[1]->SetBinContent(b,v4VsM);
4628   fIntFlowVsM[1]->SetBinError(b,v4ErrorVsM);
4629   fIntFlowVsM[2]->SetBinContent(b,v6VsM);
4630   fIntFlowVsM[2]->SetBinError(b,v6ErrorVsM);
4631   fIntFlowVsM[3]->SetBinContent(b,v8VsM);
4632   fIntFlowVsM[3]->SetBinError(b,v8ErrorVsM);
4633  } // end of for(Int_t b=1;b<=nBins;b++)
4634  
4635  // 'Rebinned in M' calculation: // to be improved - this can be implemented better:   
4636  // Reference flow estimates:
4637  Double_t v2RebinnedInM = 0.; // v{2,QC}  
4638  Double_t v4RebinnedInM = 0.; // v{4,QC}  
4639  Double_t v6RebinnedInM = 0.; // v{6,QC}  
4640  Double_t v8RebinnedInM = 0.; // v{8,QC}
4641  // Reference flow's statistical errors:
4642  Double_t v2ErrorRebinnedInM = 0.; // v{2,QC} stat. error 
4643  Double_t v4ErrorRebinnedInM = 0.; // v{4,QC} stat. error
4644  Double_t v6ErrorRebinnedInM = 0.; // v{6,QC} stat. error
4645  Double_t v8ErrorRebinnedInM = 0.; // v{8,QC} stat. error
4646  // Q-cumulants:
4647  Double_t qc2RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(1); // QC{2}  
4648  Double_t qc4RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(2); // QC{4}  
4649  Double_t qc6RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(3); // QC{6}  
4650  Double_t qc8RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(4); // QC{8}
4651  // Q-cumulants's statistical errors: 
4652  Double_t qc2ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(1); // QC{2} stat. error  
4653  Double_t qc4ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(2); // QC{4} stat. error  
4654  Double_t qc6ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(3); // QC{6} stat. error  
4655  Double_t qc8ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(4); // QC{8} stat. error
4656  // Calculate reference flow estimates from Q-cumulants: 
4657  if(qc2RebinnedInM>=0.){v2RebinnedInM = pow(qc2RebinnedInM,1./2.);} 
4658  if(qc4RebinnedInM<=0.){v4RebinnedInM = pow(-1.*qc4RebinnedInM,1./4.);} 
4659  if(qc6RebinnedInM>=0.){v6RebinnedInM = pow((1./4.)*qc6RebinnedInM,1./6.);}
4660  if(qc8RebinnedInM<=0.){v8RebinnedInM = pow((-1./33.)*qc8RebinnedInM,1./8.);}  
4661  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
4662  if(qc2RebinnedInM>0.){v2ErrorRebinnedInM = (1./2.)*pow(qc2RebinnedInM,-1./2.)*qc2ErrorRebinnedInM;} 
4663  if(qc4RebinnedInM<0.){v4ErrorRebinnedInM = (1./4.)*pow(-qc4RebinnedInM,-3./4.)*qc4ErrorRebinnedInM;} 
4664  if(qc6RebinnedInM>0.){v6ErrorRebinnedInM = (1./6.)*pow(2.,-1./3.)*pow(qc6RebinnedInM,-5./6.)*qc6ErrorRebinnedInM;}   
4665  if(qc8RebinnedInM<0.){v8ErrorRebinnedInM = (1./8.)*pow(33.,-1./8.)*pow(-qc8RebinnedInM,-7./8.)*qc8ErrorRebinnedInM;}   
4666  // Print warnings for the 'wrong sign' cumulants: 
4667  if(TMath::Abs(v2RebinnedInM) < 1.e-44)
4668  {
4669   cout<<" WARNING: Wrong sign QC{2} rebinned in M, couldn't calculate v{2,QC} !!!!"<<endl;
4670  }
4671  if(TMath::Abs(v4RebinnedInM) < 1.e-44)
4672  {
4673   cout<<" WARNING: Wrong sign QC{4} rebinned in M, couldn't calculate v{4,QC} !!!!"<<endl;
4674  }
4675  if(TMath::Abs(v6RebinnedInM) < 1.e-44)
4676  {
4677   cout<<" WARNING: Wrong sign QC{6} rebinned in M, couldn't calculate v{6,QC} !!!!"<<endl;
4678  }
4679  if(TMath::Abs(v8RebinnedInM) < 1.e-44)
4680  {
4681   cout<<" WARNING: Wrong sign QC{8} rebinned in M, couldn't calculate v{8,QC} !!!!"<<endl;
4682  }                       
4683  // Store the results and statistical errors of integrated flow estimates:
4684  fIntFlowRebinnedInM->SetBinContent(1,v2RebinnedInM);
4685  fIntFlowRebinnedInM->SetBinError(1,v2ErrorRebinnedInM);
4686  fIntFlowRebinnedInM->SetBinContent(2,v4RebinnedInM);
4687  fIntFlowRebinnedInM->SetBinError(2,v4ErrorRebinnedInM);
4688  fIntFlowRebinnedInM->SetBinContent(3,v6RebinnedInM);
4689  fIntFlowRebinnedInM->SetBinError(3,v6ErrorRebinnedInM);
4690  fIntFlowRebinnedInM->SetBinContent(4,v8RebinnedInM);
4691  fIntFlowRebinnedInM->SetBinError(4,v8ErrorRebinnedInM);    
4692   
4693 } // end of AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
4694
4695 //================================================================================================================================ 
4696
4697 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
4698 {
4699  // Fill in AliFlowCommonHistResults histograms relevant for reference flow.
4700  
4701  // There are two possibilities here:
4702  // a) Store minimum bias reference flow - use SetMinimumBiasReferenceFlow(kTRUE). This result is 
4703  //    biased by the interplay between nonflow correlations and multiplicity fluctuations and is 
4704  //    also stored in local histogram fIntFlow; 
4705  // b) Store reference flow obtained from flow analysis performed at fixed multiplicity and 
4706  //    rebinned only at the end of the day - use SetMinimumBiasReferenceFlow(kFALSE). This result
4707  //    is also stored in local histogram fIntFlowRebinnedInM.
4708  
4709  // Reference flow estimates:
4710  Double_t v[4] = {0.};
4711  // Statistical errors of reference flow estimates:
4712  Double_t vError[4] = {0.};
4713   
4714  for(Int_t b=0;b<4;b++)
4715  {
4716   if(fMinimumBiasReferenceFlow)
4717   { 
4718    v[b] = fIntFlow->GetBinContent(b+1);
4719    vError[b] = fIntFlow->GetBinError(b+1);
4720   } else
4721     {
4722      v[b] = fIntFlowRebinnedInM->GetBinContent(b+1);
4723      vError[b] = fIntFlowRebinnedInM->GetBinError(b+1);
4724     }
4725  } // end of for(Int_t b=0;b<4;b++)
4726   
4727  // Fill AliFlowCommonHistResults histogram:
4728  fCommonHistsResults2nd->FillIntegratedFlow(v[0],vError[0]); // to be improved (hardwired 2nd in the name)  
4729  fCommonHistsResults4th->FillIntegratedFlow(v[1],vError[1]); // to be improved (hardwired 4th in the name)
4730  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)) // to be improved (calculate also 6th and 8th order)
4731  {
4732   fCommonHistsResults6th->FillIntegratedFlow(v[2],vError[2]); // to be improved (hardwired 6th in the name)
4733   fCommonHistsResults8th->FillIntegratedFlow(v[3],vError[3]); // to be improved (hardwired 8th in the name) 
4734  }
4735  
4736 } // end of AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
4737
4738 //================================================================================================================================ 
4739
4740 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
4741 {
4742  // Calculate all correlations needed for integrated flow using particle weights.
4743   
4744  // Remark 1: When particle weights are used the binning of fIntFlowCorrelationAllPro is organized as follows:
4745  //
4746  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
4747  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
4748  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
4749  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
4750  //  5th bin:           ----  EMPTY ----
4751  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
4752  //  7th bin: <3>_{3n|2n,1n} = ...
4753  //  8th bin: <3>_{4n|2n,2n} = ...
4754  //  9th bin: <3>_{4n|3n,1n} = ...
4755  // 10th bin:           ----  EMPTY ----
4756  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
4757  // 12th bin: <4>_{2n,1n|2n,1n} = ...
4758  // 13th bin: <4>_{2n,2n|2n,2n} = ...
4759  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
4760  // 15th bin: <4>_{3n,1n|3n,1n} = ...
4761  // 16th bin: <4>_{3n,1n|2n,2n} = ...
4762  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
4763  // 18th bin:           ----  EMPTY ----
4764  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
4765  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
4766  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
4767  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
4768  // 23rd bin:           ----  EMPTY ----
4769  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
4770  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
4771  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
4772  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
4773  // 28th bin:           ----  EMPTY ----
4774  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
4775  // 30th bin:           ----  EMPTY ----
4776  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
4777  
4778  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
4779  // fIntFlowExtraCorrelationsPro binning of which is organized as follows:
4780  
4781  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
4782  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
4783  
4784  // multiplicity (number of particles used to determine the reaction plane)
4785  Double_t dMult = (*fSMpk)(0,0);
4786  
4787  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
4788  Double_t dReQ1n1k = (*fReQ)(0,1);
4789  Double_t dReQ2n2k = (*fReQ)(1,2);
4790  Double_t dReQ3n3k = (*fReQ)(2,3);
4791  Double_t dReQ4n4k = (*fReQ)(3,4);
4792  Double_t dReQ1n3k = (*fReQ)(0,3);
4793  Double_t dImQ1n1k = (*fImQ)(0,1);
4794  Double_t dImQ2n2k = (*fImQ)(1,2);
4795  Double_t dImQ3n3k = (*fImQ)(2,3);
4796  Double_t dImQ4n4k = (*fImQ)(3,4);
4797  Double_t dImQ1n3k = (*fImQ)(0,3);
4798
4799  // dMs are variables introduced in order to simplify some Eqs. bellow:
4800  //..............................................................................................
4801  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
4802  Double_t dM22 = (*fSMpk)(1,2)-(*fSMpk)(0,4); // dM22 = sum_{i,j=1,i!=j}^M w_i^2 w_j^2
4803  Double_t dM33 = (*fSMpk)(1,3)-(*fSMpk)(0,6); // dM33 = sum_{i,j=1,i!=j}^M w_i^3 w_j^3
4804  Double_t dM44 = (*fSMpk)(1,4)-(*fSMpk)(0,8); // dM44 = sum_{i,j=1,i!=j}^M w_i^4 w_j^4
4805  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
4806  Double_t dM211 = (*fSMpk)(0,2)*(*fSMpk)(1,1)-2.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4807                 - (*fSMpk)(1,2)+2.*(*fSMpk)(0,4); // dM211 = sum_{i,j,k=1,i!=j!=k}^M w_i^2 w_j w_k
4808  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
4809                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4810                  + 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
4811  //..............................................................................................
4812
4813  // 2-particle correlations:
4814  Double_t two1n1nW1W1 = 0.; // <w1 w2 cos(n*(phi1-phi2))>
4815  Double_t two2n2nW2W2 = 0.; // <w1^2 w2^2 cos(2n*(phi1-phi2))>
4816  Double_t two3n3nW3W3 = 0.; // <w1^3 w2^3 cos(3n*(phi1-phi2))>
4817  Double_t two4n4nW4W4 = 0.; // <w1^4 w2^4 cos(4n*(phi1-phi2))>
4818  if(dMult>1) 
4819  { 
4820   if(dM11)
4821   {
4822    two1n1nW1W1 = (pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))/dM11;    
4823    // average correlation <w1 w2 cos(n*(phi1-phi2))> for single event: 
4824    fIntFlowCorrelationsEBE->SetBinContent(1,two1n1nW1W1);
4825    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,dM11);
4826    // average correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
4827    fIntFlowCorrelationsPro->Fill(0.5,two1n1nW1W1,dM11);  
4828    // average squared correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
4829    fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1nW1W1*two1n1nW1W1,dM11); 
4830    fIntFlowCorrelationsAllPro->Fill(0.5,two1n1nW1W1,dM11);   
4831   }
4832   if(dM22)
4833   {
4834    two2n2nW2W2 = (pow(dReQ2n2k,2)+pow(dImQ2n2k,2)-(*fSMpk)(0,4))/dM22; 
4835    // ...
4836    // average correlation <w1^2 w2^2 cos(2n*(phi1-phi2))> for all events:
4837    fIntFlowCorrelationsAllPro->Fill(1.5,two2n2nW2W2,dM22);   
4838   }
4839   if(dM33)
4840   {
4841    two3n3nW3W3 = (pow(dReQ3n3k,2)+pow(dImQ3n3k,2)-(*fSMpk)(0,6))/dM33;
4842    // ...
4843    // average correlation <w1^3 w2^3 cos(3n*(phi1-phi2))> for all events:
4844    fIntFlowCorrelationsAllPro->Fill(2.5,two3n3nW3W3,dM33);   
4845   }
4846   if(dM44)
4847   {
4848    two4n4nW4W4 = (pow(dReQ4n4k,2)+pow(dImQ4n4k,2)-(*fSMpk)(0,8))/dM44; 
4849    // ...
4850    // average correlation <w1^4 w2^4 cos(4n*(phi1-phi2))> for all events:
4851    fIntFlowCorrelationsAllPro->Fill(3.5,two4n4nW4W4,dM44);      
4852   }
4853  } // end of if(dMult>1) 
4854
4855  // extra 2-particle correlations:
4856  Double_t two1n1nW3W1 = 0.; // <w1^3 w2 cos(n*(phi1-phi2))>
4857  Double_t two1n1nW1W1W2 = 0.; // <w1 w2 w3^2 cos(n*(phi1-phi2))> 
4858  if(dMult>1) 
4859  {    
4860   if(dM31)
4861   {
4862    two1n1nW3W1 = (dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k-(*fSMpk)(0,4))/dM31; 
4863    fIntFlowExtraCorrelationsPro->Fill(0.5,two1n1nW3W1,dM31);  
4864   } 
4865   if(dM211)
4866   {
4867    two1n1nW1W1W2 = ((*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))
4868                  - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k
4869                  - (*fSMpk)(0,4)))/dM211;
4870    fIntFlowExtraCorrelationsPro->Fill(1.5,two1n1nW1W1W2,dM211);  
4871   }  
4872  } // end of if(dMult>1)
4873  //..............................................................................................
4874  
4875  //..............................................................................................
4876  // 3-particle correlations:
4877  Double_t three2n1n1nW2W1W1 = 0.; // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
4878  
4879  if(dMult>2) 
4880  { 
4881   if(dM211)
4882   {                                                       
4883    three2n1n1nW2W1W1 = (pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k
4884                      - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
4885                      - pow(dReQ2n2k,2)-pow(dImQ2n2k,2)
4886                      + 2.*(*fSMpk)(0,4))/dM211;                                                                               
4887    fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1nW2W1W1,dM211);
4888   } 
4889  } // end of if(dMult>2) 
4890  //..............................................................................................
4891  
4892  //..............................................................................................
4893  // 4-particle correlations:
4894  Double_t four1n1n1n1nW1W1W1W1 = 0.; // <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
4895  if(dMult>3) 
4896  { 
4897   if(dM1111)
4898   {      
4899    four1n1n1n1nW1W1W1W1 = (pow(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.),2)
4900                         - 2.*(pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k)
4901                         + 8.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
4902                         + (pow(dReQ2n2k,2)+pow(dImQ2n2k,2))
4903                         - 4.*(*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
4904                         - 6.*(*fSMpk)(0,4)+2.*(*fSMpk)(1,2))/dM1111;  
4905                           
4906    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for single event: 
4907    fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1nW1W1W1W1);
4908    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,dM1111);
4909    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
4910    fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1,dM1111);   
4911    // average squared correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
4912    fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1*four1n1n1n1nW1W1W1W1,dM1111);      
4913    fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1nW1W1W1W1,dM1111);   
4914   } 
4915  } // end of if(dMult>3) 
4916  //..............................................................................................
4917  
4918 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
4919
4920 //================================================================================================================================
4921
4922 void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
4923 {
4924  // Initialize all arrays used to calculate integrated flow.
4925  
4926  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
4927  {
4928   fIntFlowCorrectionTermsForNUAEBE[sc] = NULL;
4929   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc] = NULL;
4930   fIntFlowCorrectionTermsForNUAPro[sc] = NULL;
4931   fIntFlowCorrectionTermsForNUAHist[sc] = NULL;
4932   for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
4933   {
4934    fIntFlowCorrectionTermsForNUAVsMPro[sc][ci] = NULL;
4935   }
4936   for(Int_t power=0;power<2;power++) // linear or quadratic 
4937   {
4938    fIntFlowSumOfEventWeightsNUA[sc][power] = NULL;
4939   }
4940  }
4941  for(Int_t power=0;power<2;power++) // linear or quadratic 
4942  {
4943   fIntFlowSumOfEventWeights[power] = NULL;    
4944  }
4945  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))
4946  {
4947   fPrintFinalResults[i] = kTRUE;
4948  }
4949  for(Int_t ci=0;ci<4;ci++) // correlation index or cumulant order
4950  {
4951   fIntFlowCorrelationsVsMPro[ci] = NULL;
4952   fIntFlowSquaredCorrelationsVsMPro[ci] = NULL;
4953   fIntFlowCorrelationsVsMHist[ci] = NULL;
4954   fIntFlowQcumulantsVsM[ci] = NULL;
4955   fIntFlowVsM[ci] = NULL;
4956   fIntFlowDetectorBiasVsM[ci] = NULL;
4957   for(Int_t lc=0;lc<2;lc++)
4958   {
4959    fIntFlowSumOfEventWeightsVsM[ci][lc] = NULL;
4960   }
4961  } 
4962  for(Int_t pi=0;pi<6;pi++) // product or covariance index
4963  {
4964   fIntFlowProductOfCorrelationsVsMPro[pi] = NULL;
4965   fIntFlowCovariancesVsM[pi] = NULL;
4966   fIntFlowSumOfProductOfEventWeightsVsM[pi] = NULL;
4967  } 
4968  
4969 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
4970
4971 //================================================================================================================================
4972
4973 void AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
4974 {
4975  // Initialize all arrays needed to calculate differential flow.
4976  //  a) Initialize lists holding profiles;
4977  //  b) Initialize lists holding histograms;
4978  //  c) Initialize event-by-event quantities;
4979  //  d) Initialize profiles;
4980  //  e) Initialize histograms holding final results.
4981  
4982  // a) Initialize lists holding profiles;
4983  for(Int_t t=0;t<2;t++) // type (RP, POI)
4984  {
4985   for(Int_t pe=0;pe<2;pe++) // pt or eta
4986   {
4987    fDiffFlowCorrelationsProList[t][pe] = NULL;
4988    fDiffFlowProductOfCorrelationsProList[t][pe] = NULL;
4989    fDiffFlowCorrectionsProList[t][pe] = NULL;
4990   }
4991  }  
4992  
4993  // b) Initialize lists holding histograms;
4994  for(Int_t t=0;t<2;t++) // type (RP, POI)
4995  {
4996   for(Int_t pe=0;pe<2;pe++) // pt or eta
4997   {
4998    fDiffFlowCorrelationsHistList[t][pe] = NULL;
4999    for(Int_t power=0;power<2;power++)
5000    {
5001     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = NULL;
5002    } // end of for(Int_t power=0;power<2;power++)  
5003    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = NULL;
5004    fDiffFlowCorrectionsHistList[t][pe] = NULL;
5005    fDiffFlowCovariancesHistList[t][pe] = NULL;
5006    fDiffFlowCumulantsHistList[t][pe] = NULL;
5007    fDiffFlowHistList[t][pe] = NULL;
5008   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5009  } // enf of for(Int_t t=0;t<2;t++) // type (RP, POI) 
5010  
5011  // c) Initialize event-by-event quantities:
5012  // 1D:
5013  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5014  {
5015   for(Int_t pe=0;pe<2;pe++) // pt or eta
5016   { 
5017    for(Int_t m=0;m<4;m++) // multiple of harmonic
5018    {
5019     for(Int_t k=0;k<9;k++) // power of weight
5020     {
5021      fReRPQ1dEBE[t][pe][m][k] = NULL;
5022      fImRPQ1dEBE[t][pe][m][k] = NULL;
5023      fs1dEBE[t][pe][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5024     }   
5025    }
5026   }
5027  }
5028  // 1D:
5029  for(Int_t t=0;t<2;t++) // type (RP or POI)
5030  {
5031   for(Int_t pe=0;pe<2;pe++) // pt or eta
5032   { 
5033    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5034    {
5035     for(Int_t cti=0;cti<9;cti++) // correction term index
5036     {
5037      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = NULL;
5038     }   
5039    }
5040   }
5041  }
5042  // 2D:  
5043  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5044  {
5045   for(Int_t m=0;m<4;m++) // multiple of harmonic
5046   {
5047    for(Int_t k=0;k<9;k++) // power of weight
5048    {
5049     fReRPQ2dEBE[t][m][k] = NULL;
5050     fImRPQ2dEBE[t][m][k] = NULL;
5051     fs2dEBE[t][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5052    }   
5053   }
5054  }
5055  
5056  // d) Initialize profiles:
5057  for(Int_t t=0;t<2;t++) // type: RP or POI
5058  { 
5059   for(Int_t pe=0;pe<2;pe++) // pt or eta
5060   {
5061    for(Int_t ci=0;ci<4;ci++) // correlation index
5062    {
5063     fDiffFlowCorrelationsPro[t][pe][ci] = NULL;
5064     fDiffFlowSquaredCorrelationsPro[t][pe][ci] = NULL;
5065    } // end of for(Int_t ci=0;ci<4;ci++)   
5066    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5067    {
5068     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5069     {
5070      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = NULL;
5071     } // end of for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5072    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index  
5073    // correction terms for nua:
5074    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5075    {
5076     for(Int_t cti=0;cti<9;cti++) // correction term index
5077     {
5078      fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = NULL;
5079     }   
5080    }
5081   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5082  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5083   
5084  // e) Initialize histograms holding final results.
5085  for(Int_t t=0;t<2;t++) // type: RP or POI
5086  { 
5087   for(Int_t pe=0;pe<2;pe++) // pt or eta
5088   {
5089    for(Int_t ci=0;ci<4;ci++) // correlation index
5090    {
5091     fDiffFlowCorrelationsHist[t][pe][ci] = NULL;
5092     fDiffFlowCumulants[t][pe][ci] = NULL;
5093     fDiffFlow[t][pe][ci] = NULL;
5094    } // end of for(Int_t ci=0;ci<4;ci++)    
5095    for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5096    {
5097     fDiffFlowCovariances[t][pe][covarianceIndex] = NULL;     
5098    } // end of for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5099    // correction terms for nua:
5100    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5101    {
5102     for(Int_t cti=0;cti<9;cti++) // correction term index
5103     {
5104      fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = NULL;
5105     }   
5106    }
5107   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5108  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5109  
5110  // sum of event weights for reduced correlations:
5111  for(Int_t t=0;t<2;t++) // type = RP or POI
5112  {
5113   for(Int_t pe=0;pe<2;pe++) // pt or eta
5114   {
5115    for(Int_t p=0;p<2;p++) // power of weight is 1 or 2
5116    {
5117     for(Int_t ew=0;ew<4;ew++) // event weight index for reduced correlations
5118     {
5119      fDiffFlowSumOfEventWeights[t][pe][p][ew] = NULL;
5120     } 
5121    }   
5122   }
5123  }
5124  // product of event weights for both types of correlations:
5125  for(Int_t t=0;t<2;t++) // type = RP or POI
5126  {
5127   for(Int_t pe=0;pe<2;pe++) // pt or eta
5128   {
5129    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5130    {
5131     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5132     {
5133      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = NULL;
5134     } 
5135    }   
5136   }
5137  }
5138
5139  
5140  
5141  
5142  /*
5143  
5144  // nested lists in fDiffFlowProfiles:
5145  for(Int_t t=0;t<2;t++)
5146  {
5147   fDFPType[t] = NULL;
5148   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
5149   {
5150    fDFPParticleWeights[t][pW] = NULL;
5151    for(Int_t eW=0;eW<2;eW++)
5152    {   
5153     fDFPEventWeights[t][pW][eW] = NULL;
5154     fDiffFlowCorrelations[t][pW][eW] = NULL;
5155     fDiffFlowProductsOfCorrelations[t][pW][eW] = NULL;
5156     for(Int_t sc=0;sc<2;sc++)
5157     {
5158      fDiffFlowCorrectionTerms[t][pW][eW][sc] = NULL;
5159     }
5160    } 
5161   }
5162  }  
5163  
5164  
5165  */
5166  
5167   
5168   
5169   /*
5170   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
5171   {
5172    for(Int_t eW=0;eW<2;eW++)
5173    {
5174     // correlations:
5175     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
5176     {
5177      fCorrelationsPro[t][pW][eW][correlationIndex] = NULL;
5178     }
5179     // products of correlations:
5180     for(Int_t productOfCorrelationsIndex=0;productOfCorrelationsIndex<6;productOfCorrelationsIndex++)
5181     {
5182      fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] = NULL;
5183     }
5184     // correction terms:
5185     for(Int_t sc=0;sc<2;sc++)
5186     {
5187      for(Int_t correctionsIndex=0;correctionsIndex<2;correctionsIndex++)
5188      {
5189       fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex] = NULL;
5190      } 
5191     } 
5192    }
5193   } 
5194   */
5195     
5196 } // end of AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5197
5198
5199 //================================================================================================================================
5200  /*
5201
5202
5203 void AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D(TString type)
5204 {
5205  // calculate all reduced correlations needed for differential flow for each (pt,eta) bin: 
5206  
5207  if(type == "RP") // to be improved (removed)
5208  {
5209   cout<<endl;
5210  }
5211  // ... 
5212  
5213  
5214  Int_t typeFlag = -1; 
5215   
5216  // reduced correlations ares stored in fCorrelationsPro[t][pW][index] and are indexed as follows:
5217  // index:
5218  // 0: <2'>
5219  // 1: <4'>
5220
5221  // multiplicity:
5222  Double_t dMult = (*fSMpk)(0,0);
5223  
5224  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5225  Double_t dReQ1n = (*fReQ)(0,0);
5226  Double_t dReQ2n = (*fReQ)(1,0);
5227  //Double_t dReQ3n = (*fReQ)(2,0);
5228  //Double_t dReQ4n = (*fReQ)(3,0);
5229  Double_t dImQ1n = (*fImQ)(0,0);
5230  Double_t dImQ2n = (*fImQ)(1,0);
5231  //Double_t dImQ3n = (*fImQ)(2,0);
5232  //Double_t dImQ4n = (*fImQ)(3,0);
5233
5234  // looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
5235  for(Int_t p=1;p<=fnBinsPt;p++)
5236  {
5237   for(Int_t e=1;e<=fnBinsEta;e++)
5238   {
5239    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin): 
5240    Double_t p1n0kRe = 0.;
5241    Double_t p1n0kIm = 0.;
5242
5243    // number of POIs in particular (pt,eta) bin:
5244    Double_t mp = 0.;
5245
5246    // 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):
5247    Double_t q1n0kRe = 0.;
5248    Double_t q1n0kIm = 0.;
5249    Double_t q2n0kRe = 0.;
5250    Double_t q2n0kIm = 0.;
5251
5252    // number of particles which are both RPs and POIs in particular (pt,eta) bin:
5253    Double_t mq = 0.;
5254    
5255    // q_{m*n,0}:
5256    q1n0kRe = fReEBE2D[2][0][0]->GetBinContent(fReEBE2D[2][0][0]->GetBin(p,e))
5257            * fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e));
5258    q1n0kIm = fImEBE2D[2][0][0]->GetBinContent(fImEBE2D[2][0][0]->GetBin(p,e))
5259            * fImEBE2D[2][0][0]->GetBinEntries(fImEBE2D[2][0][0]->GetBin(p,e));
5260    q2n0kRe = fReEBE2D[2][1][0]->GetBinContent(fReEBE2D[2][1][0]->GetBin(p,e))
5261            * fReEBE2D[2][1][0]->GetBinEntries(fReEBE2D[2][1][0]->GetBin(p,e));
5262    q2n0kIm = fImEBE2D[2][1][0]->GetBinContent(fImEBE2D[2][1][0]->GetBin(p,e))
5263            * fImEBE2D[2][1][0]->GetBinEntries(fImEBE2D[2][1][0]->GetBin(p,e));
5264            
5265    mq = fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
5266    
5267    if(type == "POI")
5268    {
5269     // p_{m*n,0}:
5270     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
5271             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5272     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))  
5273             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e));
5274             
5275     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
5276     
5277     typeFlag = 1;
5278    }
5279    else if(type == "RP")
5280    {
5281     // p_{m*n,0} = q_{m*n,0}:
5282     p1n0kRe = q1n0kRe; 
5283     p1n0kIm = q1n0kIm; 
5284     mp = mq; 
5285     
5286     typeFlag = 0;
5287    }
5288    
5289    // count events with non-empty (pt,eta) bin:
5290    if(mp>0)
5291    {
5292     fNonEmptyBins2D[typeFlag]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,1);
5293    }
5294    
5295    // 2'-particle correlation for particular (pt,eta) bin:
5296    Double_t two1n1nPtEta = 0.;
5297    if(mp*dMult-mq)
5298    {
5299     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
5300                  / (mp*dMult-mq);
5301    
5302     // fill the 2D profile to get the average correlation for each (pt,eta) bin:
5303     if(type == "POI")
5304     { 
5305      //f2pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5306      
5307      fCorrelationsPro[1][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5308     }
5309     else if(type == "RP")
5310     {
5311      //f2pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);   
5312      fCorrelationsPro[0][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5313     }
5314    } // end of if(mp*dMult-mq)
5315   
5316    // 4'-particle correlation:
5317    Double_t four1n1n1n1nPtEta = 0.;
5318    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5319        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
5320    {
5321     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5322                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
5323                       - 2.*q2n0kIm*dReQ1n*dImQ1n
5324                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
5325                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
5326                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5327                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
5328                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
5329                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
5330                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
5331                       + 2.*mq*dMult                      
5332                       - 6.*mq)        
5333                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5334                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
5335     
5336     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5337     if(type == "POI")
5338     {
5339      //f4pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5340      //                  (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5341      //                   + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
5342      
5343      fCorrelationsPro[1][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5344                                      (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5345                                      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
5346     }
5347     else if(type == "RP")
5348     {
5349      //f4pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5350      //                 (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5351      //                  + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));   
5352                        
5353      fCorrelationsPro[0][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5354                                        (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5355                                        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
5356     }
5357    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5358      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
5359    
5360   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5361  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5362
5363  
5364    
5365     
5366       
5367 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D()
5368
5369
5370
5371  
5372  
5373
5374 //================================================================================================================================
5375
5376
5377 void AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
5378 {
5379  // calculate all weighted correlations needed for differential flow 
5380  
5381   if(type == "RP") // to be improved (removed)
5382  {
5383   cout<<endl;
5384  }
5385  // ... 
5386  
5387  
5388  
5389  
5390  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5391  Double_t dReQ1n1k = (*fReQ)(0,1);
5392  Double_t dReQ2n2k = (*fReQ)(1,2);
5393  Double_t dReQ1n3k = (*fReQ)(0,3);
5394  //Double_t dReQ4n4k = (*fReQ)(3,4);
5395  Double_t dImQ1n1k = (*fImQ)(0,1);
5396  Double_t dImQ2n2k = (*fImQ)(1,2);
5397  Double_t dImQ1n3k = (*fImQ)(0,3);
5398  //Double_t dImQ4n4k = (*fImQ)(3,4);
5399  
5400  // S^M_{p,k} (see .h file for the definition of fSMpk):
5401  Double_t dSM1p1k = (*fSMpk)(0,1);
5402  Double_t dSM1p2k = (*fSMpk)(0,2);
5403  Double_t dSM1p3k = (*fSMpk)(0,3);
5404  Double_t dSM2p1k = (*fSMpk)(1,1);
5405  Double_t dSM3p1k = (*fSMpk)(2,1);
5406  
5407  // looping over all (pt,eta) bins and calculating weighted correlations needed for differential flow: 
5408  for(Int_t p=1;p<=fnBinsPt;p++)
5409  {
5410   for(Int_t e=1;e<=fnBinsEta;e++)
5411   {
5412    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
5413    Double_t p1n0kRe = 0.;
5414    Double_t p1n0kIm = 0.;
5415
5416    // number of POIs in particular (pt,eta) bin):
5417    Double_t mp = 0.;
5418
5419    // real and imaginary parts of q_{m*n,k}: 
5420    // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
5421    Double_t q1n2kRe = 0.;
5422    Double_t q1n2kIm = 0.;
5423    Double_t q2n1kRe = 0.;
5424    Double_t q2n1kIm = 0.;
5425
5426    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5427    Double_t s1p1k = 0.; 
5428    Double_t s1p2k = 0.; 
5429    Double_t s1p3k = 0.; 
5430    
5431    // M0111 from Eq. (118) in QC2c (to be improved (notation))
5432    Double_t dM0111 = 0.;
5433  
5434    if(type == "POI")
5435    {
5436     // p_{m*n,0}:
5437     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
5438             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5439     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))
5440             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e)); 
5441             
5442     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5443     
5444     // q_{m*n,k}: 
5445     q1n2kRe = fReEBE2D[2][0][2]->GetBinContent(fReEBE2D[2][0][2]->GetBin(p,e))
5446             * fReEBE2D[2][0][2]->GetBinEntries(fReEBE2D[2][0][2]->GetBin(p,e));
5447     q1n2kIm = fImEBE2D[2][0][2]->GetBinContent(fImEBE2D[2][0][2]->GetBin(p,e))
5448             * fImEBE2D[2][0][2]->GetBinEntries(fImEBE2D[2][0][2]->GetBin(p,e));
5449     q2n1kRe = fReEBE2D[2][1][1]->GetBinContent(fReEBE2D[2][1][1]->GetBin(p,e))
5450             * fReEBE2D[2][1][1]->GetBinEntries(fReEBE2D[2][1][1]->GetBin(p,e)); 
5451     q2n1kIm = fImEBE2D[2][1][1]->GetBinContent(fImEBE2D[2][1][1]->GetBin(p,e))
5452             * fImEBE2D[2][1][1]->GetBinEntries(fImEBE2D[2][1][1]->GetBin(p,e));
5453        
5454     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5455     s1p1k = pow(fs2D[2][1]->GetBinContent(fs2D[2][1]->GetBin(p,e)),1.); 
5456     s1p2k = pow(fs2D[2][2]->GetBinContent(fs2D[2][2]->GetBin(p,e)),1.); 
5457     s1p3k = pow(fs2D[2][3]->GetBinContent(fs2D[2][3]->GetBin(p,e)),1.); 
5458    
5459     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
5460     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
5461            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
5462            + 2.*(s1p3k-s1p2k*dSM1p1k));
5463    }
5464    else if(type == "RP")
5465    {
5466     p1n0kRe = fReEBE2D[0][0][0]->GetBinContent(fReEBE2D[0][0][0]->GetBin(p,e))
5467             * fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
5468     p1n0kIm = fImEBE2D[0][0][0]->GetBinContent(fImEBE2D[0][0][0]->GetBin(p,e))
5469             * fImEBE2D[0][0][0]->GetBinEntries(fImEBE2D[0][0][0]->GetBin(p,e));
5470             
5471     mp = fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
5472     
5473     // q_{m*n,k}: 
5474     q1n2kRe = fReEBE2D[0][0][2]->GetBinContent(fReEBE2D[0][0][2]->GetBin(p,e))
5475             * fReEBE2D[0][0][2]->GetBinEntries(fReEBE2D[0][0][2]->GetBin(p,e));
5476     q1n2kIm = fImEBE2D[0][0][2]->GetBinContent(fImEBE2D[0][0][2]->GetBin(p,e))
5477             * fImEBE2D[0][0][2]->GetBinEntries(fImEBE2D[0][0][2]->GetBin(p,e));
5478     q2n1kRe = fReEBE2D[0][1][1]->GetBinContent(fReEBE2D[0][1][1]->GetBin(p,e))
5479             * fReEBE2D[0][1][1]->GetBinEntries(fReEBE2D[0][1][1]->GetBin(p,e));
5480     q2n1kIm = fImEBE2D[0][1][1]->GetBinContent(fImEBE2D[0][1][1]->GetBin(p,e))
5481             * fImEBE2D[0][1][1]->GetBinEntries(fImEBE2D[0][1][1]->GetBin(p,e));
5482    
5483     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5484     s1p1k = pow(fs2D[0][1]->GetBinContent(fs2D[0][1]->GetBin(p,e)),1.); 
5485     s1p2k = pow(fs2D[0][2]->GetBinContent(fs2D[0][2]->GetBin(p,e)),1.); 
5486     s1p3k = pow(fs2D[0][3]->GetBinContent(fs2D[0][3]->GetBin(p,e)),1.); 
5487    
5488     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
5489     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
5490            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
5491            + 2.*(s1p3k-s1p2k*dSM1p1k));
5492     //...............................................................................................   
5493    }
5494    
5495    // 2'-particle correlation:
5496    Double_t two1n1nW0W1PtEta = 0.;
5497    if(mp*dSM1p1k-s1p1k)
5498    {
5499     two1n1nW0W1PtEta = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
5500                  / (mp*dSM1p1k-s1p1k);
5501    
5502     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5503     if(type == "POI")
5504     {
5505      //f2pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
5506      //                   mp*dSM1p1k-s1p1k);
5507      fCorrelationsPro[1][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);
5508     }
5509     else if(type == "RP")
5510     {
5511      //f2pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
5512      //                  mp*dSM1p1k-s1p1k); 
5513      fCorrelationsPro[0][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);  
5514     }
5515    } // end of if(mp*dMult-dmPrimePrimePtEta)
5516    
5517    // 4'-particle correlation:
5518    Double_t four1n1n1n1nW0W1W1W1PtEta = 0.;
5519    if(dM0111)
5520    {
5521     four1n1n1n1nW0W1W1W1PtEta = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
5522                       - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
5523                       - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
5524                       - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
5525                       + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
5526                       - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
5527                       - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
5528                       + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
5529                       + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
5530                       + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
5531                       + 2.*s1p1k*dSM1p2k                                      
5532                       - 6.*s1p3k)        
5533                       / dM0111; // to be imropoved (notation of dM0111)
5534    
5535     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5536     if(type == "POI")
5537     {
5538      //f4pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
5539      fCorrelationsPro[1][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
5540     }
5541     else if(type == "RP")
5542     {
5543      //f4pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
5544      fCorrelationsPro[0][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
5545     }
5546    } // end of if(dM0111)
5547   
5548   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5549  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5550  
5551   
5552     
5553       
5554 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
5555
5556
5557 //================================================================================================================================
5558
5559  */  
5560
5561 /*
5562 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
5563 {
5564  // 1.) Access average for 2D correlations from profiles and store them in 2D final results histograms;
5565  // 2.) Access spread for 2D correlations from profiles, calculate error and store it in 2D final results histograms;
5566  // 3.) Make projections along pt and eta axis and store results and errors in 1D final results histograms. 
5567  
5568  Int_t typeFlag = -1;
5569  Int_t pWeightsFlag = -1;
5570  Int_t eWeightsFlag = -1;
5571
5572  if(type == "RP")
5573  {
5574   typeFlag = 0;
5575  } else if(type == "POI")
5576    {
5577     typeFlag = 1;
5578    } else 
5579      {
5580       cout<<"WARNING: type must be either RP or POI in AFAWQC::FCFDF() !!!!"<<endl;
5581       exit(0);
5582      }
5583      
5584  if(!useParticleWeights)
5585  {
5586   pWeightsFlag = 0;
5587  } else 
5588    {
5589     pWeightsFlag = 1;   
5590    }   
5591    
5592  if(eventWeights == "exact")
5593  {
5594   eWeightsFlag = 0;
5595  }          
5596   
5597  // shortcuts:
5598  Int_t t = typeFlag;
5599  Int_t pW = pWeightsFlag;
5600  Int_t eW = eWeightsFlag;
5601  
5602  // from 2D histogram fNonEmptyBins2D make two 1D histograms fNonEmptyBins1D in pt and eta (to be improved (i.e. moved somewhere else))  
5603  // pt:
5604  for(Int_t p=1;p<fnBinsPt;p++)
5605  {
5606   Double_t contentPt = 0.;
5607   for(Int_t e=1;e<=fnBinsEta;e++)
5608   {
5609    contentPt += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
5610   }
5611   fNonEmptyBins1D[t][0]->SetBinContent(p,contentPt);
5612  }
5613  // eta:
5614  for(Int_t e=1;e<fnBinsEta;e++)
5615  {
5616   Double_t contentEta = 0.;
5617   for(Int_t p=1;p<=fnBinsPt;p++)
5618   {
5619    contentEta += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
5620   }
5621   fNonEmptyBins1D[t][1]->SetBinContent(e,contentEta);
5622  }
5623  
5624  // from 2D profile in (pt,eta) make two 1D profiles in (pt) and (eta):
5625  TProfile *profile[2][4]; // [0=pt,1=eta][correlation index] // to be improved (do not hardwire the correlation index)
5626  
5627  for(Int_t pe=0;pe<2;pe++) // pt or eta
5628  {
5629   for(Int_t ci=0;ci<4;ci++) // correlation index
5630   {
5631    if(pe==0) profile[pe][ci] = this->MakePtProjection(fCorrelationsPro[t][pW][eW][ci]);
5632    if(pe==1) profile[pe][ci] = this->MakeEtaProjection(fCorrelationsPro[t][pW][eW][ci]);
5633   }
5634  }
5635   
5636  // transfer 2D profile into 2D histogram:
5637  // to be improved (see in documentation if there is a method to transfer values from 2D profile into 2D histogram)    
5638  for(Int_t ci=0;ci<4;ci++)
5639  {
5640   for(Int_t p=1;p<=fnBinsPt;p++)
5641   {
5642    for(Int_t e=1;e<=fnBinsEta;e++)
5643    {
5644     Double_t correlation = fCorrelationsPro[t][pW][eW][ci]->GetBinContent(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e)); 
5645     Double_t spread = fCorrelationsPro[t][pW][eW][ci]->GetBinError(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e));
5646     Double_t nEvts = fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e));
5647     Double_t error = 0.;
5648     fFinalCorrelations2D[t][pW][eW][ci]->SetBinContent(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),correlation);          
5649     if(nEvts>0)
5650     {
5651      error = spread/pow(nEvts,0.5);
5652      fFinalCorrelations2D[t][pW][eW][ci]->SetBinError(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),error);
5653     }
5654    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5655   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5656  } // end of for(Int_t ci=0;ci<4;ci++)
5657  
5658  // transfer 1D profile into 1D histogram (pt):
5659  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
5660  for(Int_t ci=0;ci<4;ci++)
5661  {
5662   for(Int_t p=1;p<=fnBinsPt;p++)
5663   {
5664    if(profile[0][ci])
5665    {
5666     Double_t correlation = profile[0][ci]->GetBinContent(p); 
5667     Double_t spread = profile[0][ci]->GetBinError(p);
5668     Double_t nEvts = fNonEmptyBins1D[t][0]->GetBinContent(p);
5669     Double_t error = 0.;
5670     fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinContent(p,correlation); 
5671     if(nEvts>0)
5672     {
5673      error = spread/pow(nEvts,0.5);
5674      fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinError(p,error);
5675     }  
5676    }   
5677   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5678  } // end of for(Int_t ci=0;ci<4;ci++)
5679  
5680  // transfer 1D profile into 1D histogram (eta):
5681  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
5682  for(Int_t ci=0;ci<4;ci++)
5683  {
5684   for(Int_t e=1;e<=fnBinsEta;e++)
5685   {
5686    if(profile[1][ci])
5687    {
5688     Double_t correlation = profile[1][ci]->GetBinContent(e); 
5689     fFinalCorrelations1D[t][pW][eW][1][ci]->SetBinContent(e,correlation);      
5690    }    
5691   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5692  } // end of for(Int_t ci=0;ci<4;ci++)
5693         
5694 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
5695 */
5696
5697
5698 //================================================================================================================================
5699
5700
5701 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, TString ptOrEta)
5702 {
5703  // calcualate cumulants for differential flow from measured correlations
5704  // Remark: cumulants calculated here are NOT corrected for non-uniform acceptance. This correction is applied in the method ...
5705  // to be improved (description) 
5706  
5707  Int_t typeFlag = 0;
5708  Int_t ptEtaFlag = 0;
5709
5710  if(type == "RP")
5711  {
5712   typeFlag = 0;
5713  } else if(type == "POI")
5714    {
5715     typeFlag = 1;
5716    } 
5717      
5718  if(ptOrEta == "Pt")
5719  {
5720   ptEtaFlag = 0;
5721  } else if(ptOrEta == "Eta")
5722    {
5723     ptEtaFlag = 1;
5724    } 
5725   
5726  // shortcuts:
5727  Int_t t = typeFlag;
5728  Int_t pe = ptEtaFlag;
5729      
5730  // common:
5731  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5732  
5733  // correlation <<2>>: 
5734  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
5735  
5736  // 1D:
5737  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5738  {
5739   // reduced correlations:   
5740   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>(pt)
5741   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>(pt)
5742   // final statistical error of reduced correlations:
5743   //Double_t twoPrimeError = fFinalCorrelations1D[t][pW][eW][0][0]->GetBinError(p); 
5744   // QC{2'}:
5745   Double_t qc2Prime = twoPrime; // QC{2'}
5746   //Double_t qc2PrimeError = twoPrimeError; // final stat. error of QC{2'}
5747   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime); 
5748   //fFinalCumulantsPt[t][pW][eW][nua][0]->SetBinError(p,qc2PrimeError);   
5749   // QC{4'}:
5750   Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5751   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime); 
5752  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5753  
5754     
5755  /* 
5756  // 2D (pt,eta):
5757  // to be improved (see documentation if I can do all this without looping)
5758  for(Int_t p=1;p<=fnBinsPt;p++)
5759  {
5760   for(Int_t e=1;e<=fnBinsEta;e++) 
5761   {  
5762    // reduced correlations:   
5763    Double_t twoPrime = fFinalCorrelations2D[t][pW][eW][0]->GetBinContent(fFinalCorrelations2D[t][pW][eW][0]->GetBin(p,e)); // <<2'>>(pt,eta)
5764    Double_t fourPrime = fFinalCorrelations2D[t][pW][eW][1]->GetBinContent(fFinalCorrelations2D[t][pW][eW][1]->GetBin(p,e)); // <<4'>>(pt,eta)
5765    for(Int_t nua=0;nua<2;nua++)
5766    {
5767     // QC{2'}:
5768     Double_t qc2Prime = twoPrime; // QC{2'} = <<2'>>
5769     fFinalCumulants2D[t][pW][eW][nua][0]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e),qc2Prime);    
5770     // QC{4'}:
5771     Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5772     fFinalCumulants2D[t][pW][eW][nua][1]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e),qc4Prime);   
5773    } // end of for(Int_t nua=0;nua<2;nua++)   
5774   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5775  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5776  */
5777    
5778 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, Bool_t useParticleWeights, TString eventWeights); 
5779
5780 //================================================================================================================================
5781
5782 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
5783 {
5784  // calculate final results for integrated flow of RPs and POIs 
5785   
5786  Int_t typeFlag = 0;
5787
5788  if(type == "RP")
5789  {
5790   typeFlag = 0;
5791  } else if(type == "POI")
5792    {
5793     typeFlag = 1;
5794    } else 
5795      {
5796       cout<<"WARNING: type must be either RP or POI in AFAWQC::CDF() !!!!"<<endl;
5797       exit(0);
5798      }
5799      
5800  // shortcuts:
5801  Int_t t = typeFlag;
5802   
5803  // pt yield:    
5804  TH1F *yield2ndPt = NULL;
5805  TH1F *yield4thPt = NULL;
5806  TH1F *yield6thPt = NULL;
5807  TH1F *yield8thPt = NULL;
5808  
5809  if(type == "POI")
5810  {
5811   if(fFillMultipleControlHistograms)
5812   {
5813    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtPOI())->Clone();
5814    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtPOI())->Clone();
5815    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtPOI())->Clone();
5816    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtPOI())->Clone();  
5817   } else
5818     {
5819      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5820      yield4thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5821      yield6thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5822      yield8thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();     
5823     }
5824  } 
5825  else if(type == "RP")
5826  {
5827   if(fFillMultipleControlHistograms)
5828   {
5829    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtRP())->Clone();
5830    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtRP())->Clone();
5831    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtRP())->Clone();
5832    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtRP())->Clone();  
5833   } else
5834     {
5835      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
5836      yield4thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
5837      yield6thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
5838      yield8thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();    
5839     } 
5840  } 
5841  
5842  Int_t nBinsPt = yield2ndPt->GetNbinsX();
5843  
5844  TH1D *flow2ndPt = NULL;
5845  TH1D *flow4thPt = NULL;
5846  TH1D *flow6thPt = NULL;
5847  TH1D *flow8thPt = NULL;
5848  
5849  // to be improved (hardwired pt index)
5850  flow2ndPt = (TH1D*)fDiffFlow[t][0][0]->Clone();
5851  flow4thPt = (TH1D*)fDiffFlow[t][0][1]->Clone();
5852  flow6thPt = (TH1D*)fDiffFlow[t][0][2]->Clone();
5853  flow8thPt = (TH1D*)fDiffFlow[t][0][3]->Clone(); 
5854    
5855  Double_t dvn2nd = 0., dvn4th = 0., dvn6th = 0., dvn8th = 0.; // differential flow
5856  Double_t dErrvn2nd = 0., dErrvn4th = 0., dErrvn6th = 0., dErrvn8th = 0.; // error on differential flow
5857  
5858  Double_t dVn2nd = 0., dVn4th = 0., dVn6th = 0., dVn8th = 0.; // integrated flow 
5859  Double_t dErrVn2nd = 0., dErrVn4th = 0., dErrVn6th = 0., dErrVn8th = 0.; // error on integrated flow
5860
5861  Double_t dYield2nd = 0., dYield4th = 0., dYield6th = 0., dYield8th = 0.; // pt yield 
5862  Double_t dSum2nd = 0., dSum4th = 0., dSum6th = 0., dSum8th = 0.; // needed for normalizing integrated flow
5863  
5864  // looping over pt bins:
5865  for(Int_t p=1;p<nBinsPt+1;p++)
5866  {
5867   dvn2nd = flow2ndPt->GetBinContent(p);
5868   dvn4th = flow4thPt->GetBinContent(p);
5869   dvn6th = flow6thPt->GetBinContent(p);
5870   dvn8th = flow8thPt->GetBinContent(p);
5871   
5872   dErrvn2nd = flow2ndPt->GetBinError(p);
5873   dErrvn4th = flow4thPt->GetBinError(p);
5874   dErrvn6th = flow6thPt->GetBinError(p);
5875   dErrvn8th = flow8thPt->GetBinError(p);
5876
5877   dYield2nd = yield2ndPt->GetBinContent(p);  
5878   dYield4th = yield4thPt->GetBinContent(p);
5879   dYield6th = yield6thPt->GetBinContent(p);
5880   dYield8th = yield8thPt->GetBinContent(p);
5881   
5882   dVn2nd += dvn2nd*dYield2nd;
5883   dVn4th += dvn4th*dYield4th;
5884   dVn6th += dvn6th*dYield6th;
5885   dVn8th += dvn8th*dYield8th;
5886   
5887   dSum2nd += dYield2nd;
5888   dSum4th += dYield4th;
5889   dSum6th += dYield6th;
5890   dSum8th += dYield8th;
5891   
5892   dErrVn2nd += dYield2nd*dYield2nd*dErrvn2nd*dErrvn2nd; // ro be improved (check this relation)
5893   dErrVn4th += dYield4th*dYield4th*dErrvn4th*dErrvn4th;
5894   dErrVn6th += dYield6th*dYield6th*dErrvn6th*dErrvn6th;
5895   dErrVn8th += dYield8th*dYield8th*dErrvn8th*dErrvn8th;
5896     
5897  } // end of for(Int_t p=1;p<nBinsPt+1;p++)
5898
5899  // normalizing the results for integrated flow:
5900  if(dSum2nd) 
5901  {
5902   dVn2nd /= dSum2nd;
5903   dErrVn2nd /= (dSum2nd*dSum2nd);
5904   dErrVn2nd = TMath::Sqrt(dErrVn2nd);
5905  } 
5906  if(dSum4th) 
5907  {
5908   dVn4th /= dSum4th;
5909   dErrVn4th /= (dSum4th*dSum4th);
5910   dErrVn4th = TMath::Sqrt(dErrVn4th);
5911  } 
5912  //if(dSum6th) dVn6th/=dSum6th;
5913  //if(dSum8th) dVn8th/=dSum8th;
5914   
5915  // storing the results for integrated flow in common histos: (to be improved: new method for this?)
5916  if(type == "POI")
5917  {
5918   fCommonHistsResults2nd->FillIntegratedFlowPOI(dVn2nd,dErrVn2nd); 
5919   fCommonHistsResults4th->FillIntegratedFlowPOI(dVn4th,dErrVn4th); 
5920   fCommonHistsResults6th->FillIntegratedFlowPOI(dVn6th,0.); // to be improved (errors)
5921   fCommonHistsResults8th->FillIntegratedFlowPOI(dVn8th,0.); // to be improved (errors)
5922  }
5923  else if (type == "RP")
5924  {
5925   fCommonHistsResults2nd->FillIntegratedFlowRP(dVn2nd,dErrVn2nd); 
5926   fCommonHistsResults4th->FillIntegratedFlowRP(dVn4th,dErrVn4th);
5927   fCommonHistsResults6th->FillIntegratedFlowRP(dVn6th,0.); // to be improved (errors)
5928   fCommonHistsResults8th->FillIntegratedFlowRP(dVn8th,0.); // to be improved (errors)
5929  }
5930  
5931  delete flow2ndPt;
5932  delete flow4thPt;
5933  //delete flow6thPt;
5934  //delete flow8thPt;
5935  
5936  delete yield2ndPt;
5937  delete yield4thPt;
5938  delete yield6thPt;
5939  delete yield8thPt;
5940            
5941 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
5942
5943 //================================================================================================================================
5944
5945 void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
5946 {
5947  // Initialize all arrays used for distributions.
5948  
5949  // a) Initialize arrays of histograms used to hold distributions of correlations; 
5950  // b) Initialize array to hold min and max values of correlations.
5951  
5952  // a) Initialize arrays of histograms used to hold distributions of correlations:
5953  for(Int_t di=0;di<4;di++) // distribution index
5954  {
5955   fDistributions[di] = NULL;
5956  }
5957  
5958  // b) Initialize default min and max values of correlations:
5959  //    (Remark: The default values bellow were chosen for v2=5% and M=500)
5960  fMinValueOfCorrelation[0] = -0.01; // <2>_min 
5961  fMaxValueOfCorrelation[0] = 0.04; // <2>_max 
5962  fMinValueOfCorrelation[1] = -0.00002; // <4>_min 
5963  fMaxValueOfCorrelation[1] = 0.00015; // <4>_max  
5964  fMinValueOfCorrelation[2] = -0.0000003; // <6>_min 
5965  fMaxValueOfCorrelation[2] = 0.0000006; // <6>_max  
5966  fMinValueOfCorrelation[3] = -0.000000006; // <8>_min 
5967  fMaxValueOfCorrelation[3] = 0.000000003; // <8>_max 
5968  
5969 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
5970
5971 //================================================================================================================================
5972
5973 void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
5974 {
5975  // Initialize all arrays used for various unclassified objects.
5976  
5977  for(Int_t p=0;p<4;p++) // [v_min,v_max,refMult_min,refMult_max]
5978  {
5979   fPhiDistributionForOneEventSettings[p] = 0.;
5980  } 
5981    
5982 } //  end of void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
5983
5984 //================================================================================================================================
5985
5986 void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
5987 {
5988  // a) Book profile to hold all flags for distributions of correlations;
5989  // b) Book all histograms to hold distributions of correlations.
5990  
5991  TString correlationIndex[4] = {"<2>","<4>","<6>","<8>"}; // to be improved (should I promote this to data members?)
5992   
5993  // a) Book profile to hold all flags for distributions of correlations:
5994  TString distributionsFlagsName = "fDistributionsFlags";
5995  distributionsFlagsName += fAnalysisLabel->Data();
5996  fDistributionsFlags = new TProfile(distributionsFlagsName.Data(),"Flags for Distributions of Correlations",9,0,9);
5997  fDistributionsFlags->SetTickLength(-0.01,"Y");
5998  fDistributionsFlags->SetMarkerStyle(25);
5999  fDistributionsFlags->SetLabelSize(0.05);
6000  fDistributionsFlags->SetLabelOffset(0.02,"Y");
6001  fDistributionsFlags->GetXaxis()->SetBinLabel(1,"Store or not?");
6002  fDistributionsFlags->GetXaxis()->SetBinLabel(2,"<2>_{min}");
6003  fDistributionsFlags->GetXaxis()->SetBinLabel(3,"<2>_{max}");
6004  fDistributionsFlags->GetXaxis()->SetBinLabel(4,"<4>_{min}");
6005  fDistributionsFlags->GetXaxis()->SetBinLabel(5,"<4>_{max}");
6006  fDistributionsFlags->GetXaxis()->SetBinLabel(6,"<6>_{min}");
6007  fDistributionsFlags->GetXaxis()->SetBinLabel(7,"<6>_{max}");
6008  fDistributionsFlags->GetXaxis()->SetBinLabel(8,"<8>_{min}");
6009  fDistributionsFlags->GetXaxis()->SetBinLabel(9,"<8>_{max}");
6010  fDistributionsList->Add(fDistributionsFlags);
6011  
6012  // b) Book all histograms to hold distributions of correlations.
6013  if(fStoreDistributions)
6014  { 
6015   TString distributionsName = "fDistributions";
6016   distributionsName += fAnalysisLabel->Data();
6017   for(Int_t di=0;di<4;di++) // distribution index
6018   {
6019    fDistributions[di] = new TH1D(Form("Distribution of %s",correlationIndex[di].Data()),Form("Distribution of %s",correlationIndex[di].Data()),10000,fMinValueOfCorrelation[di],fMaxValueOfCorrelation[di]); 
6020    fDistributions[di]->SetXTitle(correlationIndex[di].Data());
6021    fDistributionsList->Add(fDistributions[di]);
6022   } // end of for(Int_t di=0;di<4;di++) // distribution index
6023  } // end of if(fStoreDistributions)
6024  
6025 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
6026
6027 //================================================================================================================================
6028
6029 void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6030 {
6031  // Book all objects for various unclassified quantities.
6032  
6033  if(!fStorePhiDistributionForOneEvent){return;}
6034  
6035  // a) Book histogram holding phi distribution for single event to illustrate flow.
6036  
6037  // a) Book histogram holding phi distribution for single event to illustrate flow:
6038  fPhiDistributionForOneEvent = new TH1D("fPhiDistributionForOneEvent","",360,0.,TMath::TwoPi());
6039  fPhiDistributionForOneEvent->GetXaxis()->SetTitle("#phi");
6040  fVariousList->Add(fPhiDistributionForOneEvent);
6041  
6042 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6043
6044 //================================================================================================================================
6045
6046 void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6047 {
6048  // Store all flags for distributiuons of correlations in profile fDistributionsFlags.
6049  
6050  if(!fDistributionsFlags)
6051  {
6052   cout<<"WARNING: fDistributionsFlags is NULL in AFAWQC::SDF() !!!!"<<endl;
6053   exit(0);
6054  } 
6055
6056  fDistributionsFlags->Fill(0.5,(Int_t)fStoreDistributions); // histos with distributions of correlations stored or not in the output file
6057  // store min and max values of correlations:
6058  for(Int_t di=0;di<4;di++) // distribution index
6059  {
6060   fDistributionsFlags->Fill(1.5+2.*(Double_t)di,fMinValueOfCorrelation[di]);
6061   fDistributionsFlags->Fill(2.5+2.*(Double_t)di,fMaxValueOfCorrelation[di]);
6062  }
6063      
6064 } // end of void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6065
6066
6067 //================================================================================================================================
6068
6069
6070 void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6071 {
6072  // Store distributions of correlations.
6073  
6074  if(!(fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE))
6075  {
6076   cout<<"WARNING: fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE"<<endl; 
6077   cout<<"         is NULL in AFAWQC::SDOC() !!!!"<<endl;
6078   exit(0);
6079  }
6080
6081  for(Int_t di=0;di<4;di++) // distribution index
6082  {
6083   if(!fDistributions[di])
6084   { 
6085    cout<<"WARNING: fDistributions[di] is NULL in AFAWQC::SDOC() !!!!"<<endl;
6086    cout<<"di = "<<di<<endl;
6087    exit(0);
6088   } else 
6089     {
6090      fDistributions[di]->Fill(fIntFlowCorrelationsEBE->GetBinContent(di+1),fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(di+1)); 
6091     } 
6092  } // end of for(Int_t di=0;di<4;di++) // distribution index
6093
6094 } // end of void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6095
6096 //================================================================================================================================
6097
6098 void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6099 {
6100  // Book and nest all lists nested in the base list fHistList.
6101  //  a) Book and nest lists for integrated flow;
6102  //  b) Book and nest lists for differential flow;
6103  //  c) Book and nest list for particle weights;
6104  //  d) Book and nest list for distributions;
6105  //  e) Book and nest list for various unclassified objects; 
6106  //  f) Book and nest list for nested loops.
6107  
6108  // a) Book and nest all lists for integrated flow:
6109  // base list for integrated flow:
6110  fIntFlowList = new TList();
6111  fIntFlowList->SetName("Integrated Flow");
6112  fIntFlowList->SetOwner(kTRUE);
6113  fHistList->Add(fIntFlowList);
6114  // list holding profiles: 
6115  fIntFlowProfiles = new TList();
6116  fIntFlowProfiles->SetName("Profiles");
6117  fIntFlowProfiles->SetOwner(kTRUE);
6118  fIntFlowList->Add(fIntFlowProfiles);
6119  // list holding histograms with results:
6120  fIntFlowResults = new TList();
6121  fIntFlowResults->SetName("Results");
6122  fIntFlowResults->SetOwner(kTRUE);
6123  fIntFlowList->Add(fIntFlowResults);
6124  
6125  // b) Book and nest lists for differential flow;
6126  fDiffFlowList = new TList();
6127  fDiffFlowList->SetName("Differential Flow");
6128  fDiffFlowList->SetOwner(kTRUE); 
6129  fHistList->Add(fDiffFlowList);
6130  // list holding profiles: 
6131  fDiffFlowProfiles = new TList(); 
6132  fDiffFlowProfiles->SetName("Profiles");
6133  fDiffFlowProfiles->SetOwner(kTRUE);
6134  fDiffFlowList->Add(fDiffFlowProfiles);
6135  // list holding histograms with results: 
6136  fDiffFlowResults = new TList();
6137  fDiffFlowResults->SetName("Results");
6138  fDiffFlowResults->SetOwner(kTRUE);
6139  fDiffFlowList->Add(fDiffFlowResults);
6140  // flags used for naming nested lists in list fDiffFlowProfiles and fDiffFlowResults:  
6141  TList list;
6142  list.SetOwner(kTRUE);
6143  TString typeFlag[2] = {"RP","POI"};  
6144  TString ptEtaFlag[2] = {"p_{T}","#eta"}; 
6145  TString powerFlag[2] = {"linear","quadratic"};   
6146  // nested lists in fDiffFlowProfiles (~/Differential Flow/Profiles):
6147  for(Int_t t=0;t<2;t++) // type: RP or POI
6148  {
6149   for(Int_t pe=0;pe<2;pe++) // pt or eta
6150   {
6151    // list holding profiles with correlations:
6152    fDiffFlowCorrelationsProList[t][pe] = (TList*)list.Clone();
6153    fDiffFlowCorrelationsProList[t][pe]->SetName(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6154    fDiffFlowProfiles->Add(fDiffFlowCorrelationsProList[t][pe]);
6155    // list holding profiles with products of correlations:
6156    fDiffFlowProductOfCorrelationsProList[t][pe] = (TList*)list.Clone();
6157    fDiffFlowProductOfCorrelationsProList[t][pe]->SetName(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6158    fDiffFlowProfiles->Add(fDiffFlowProductOfCorrelationsProList[t][pe]);
6159    // list holding profiles with corrections:
6160    fDiffFlowCorrectionsProList[t][pe] = (TList*)list.Clone();
6161    fDiffFlowCorrectionsProList[t][pe]->SetName(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6162    fDiffFlowProfiles->Add(fDiffFlowCorrectionsProList[t][pe]);   
6163   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6164  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI   
6165  // nested lists in fDiffFlowResults (~/Differential Flow/Results):
6166  for(Int_t t=0;t<2;t++) // type: RP or POI
6167  {
6168   for(Int_t pe=0;pe<2;pe++) // pt or eta
6169   {
6170    // list holding histograms with correlations:
6171    fDiffFlowCorrelationsHistList[t][pe] = (TList*)list.Clone();
6172    fDiffFlowCorrelationsHistList[t][pe]->SetName(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6173    fDiffFlowResults->Add(fDiffFlowCorrelationsHistList[t][pe]);
6174    // list holding histograms with corrections:
6175    fDiffFlowCorrectionsHistList[t][pe] = (TList*)list.Clone();
6176    fDiffFlowCorrectionsHistList[t][pe]->SetName(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6177    fDiffFlowResults->Add(fDiffFlowCorrectionsHistList[t][pe]);   
6178    for(Int_t power=0;power<2;power++)
6179    {
6180     // list holding histograms with sums of event weights:
6181     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = (TList*)list.Clone();
6182     fDiffFlowSumOfEventWeightsHistList[t][pe][power]->SetName(Form("Sum of %s event weights (%s, %s)",powerFlag[power].Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6183     fDiffFlowResults->Add(fDiffFlowSumOfEventWeightsHistList[t][pe][power]);    
6184    } // end of for(Int_t power=0;power<2;power++)
6185    // list holding histograms with sums of products of event weights:
6186    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = (TList*)list.Clone();
6187    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->SetName(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6188    fDiffFlowResults->Add(fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]);
6189    // list holding histograms with covariances of correlations:
6190    fDiffFlowCovariancesHistList[t][pe] = (TList*)list.Clone();
6191    fDiffFlowCovariancesHistList[t][pe]->SetName(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6192    fDiffFlowResults->Add(fDiffFlowCovariancesHistList[t][pe]);
6193    // list holding histograms with differential Q-cumulants:
6194    fDiffFlowCumulantsHistList[t][pe] = (TList*)list.Clone();
6195    fDiffFlowCumulantsHistList[t][pe]->SetName(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6196    fDiffFlowResults->Add(fDiffFlowCumulantsHistList[t][pe]);   
6197    // list holding histograms with differential flow estimates from Q-cumulants:
6198    fDiffFlowHistList[t][pe] = (TList*)list.Clone();
6199    fDiffFlowHistList[t][pe]->SetName(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6200    fDiffFlowResults->Add(fDiffFlowHistList[t][pe]);      
6201   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6202  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6203   
6204  // c) Book and nest list for particle weights:
6205  fWeightsList->SetName("Weights");
6206  fWeightsList->SetOwner(kTRUE);   
6207  fHistList->Add(fWeightsList); 
6208
6209  // d) Book and nest list for distributions:
6210  fDistributionsList = new TList();
6211  fDistributionsList->SetName("Distributions");
6212  fDistributionsList->SetOwner(kTRUE);
6213  fHistList->Add(fDistributionsList);
6214  
6215  // e) Book and nest list for various unclassified objects:
6216  if(fStorePhiDistributionForOneEvent)
6217  {
6218   fVariousList = new TList();
6219   fVariousList->SetName("Various");
6220   fVariousList->SetOwner(kTRUE);
6221   fHistList->Add(fVariousList);
6222  }
6223   
6224  // f) Book and nest list for nested loops:
6225  fNestedLoopsList = new TList();
6226  fNestedLoopsList->SetName("Nested Loops");
6227  fNestedLoopsList->SetOwner(kTRUE);
6228  fHistList->Add(fNestedLoopsList);
6229  
6230 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6231
6232
6233 //================================================================================================================================
6234
6235
6236 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type)
6237 {
6238  // fill common result histograms for differential flow
6239  
6240  Int_t typeFlag = 0;
6241  //Int_t ptEtaFlag = 0;
6242
6243  if(type == "RP")
6244  {
6245   typeFlag = 0;
6246  } else if(type == "POI")
6247    {
6248     typeFlag = 1;
6249    } 
6250   
6251  // shortcuts:
6252  Int_t t = typeFlag;
6253  //Int_t pe = ptEtaFlag;
6254
6255  // to be improved (implement protection here)
6256      
6257  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
6258  {
6259   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
6260   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
6261   exit(0);
6262  }
6263  
6264  // pt:
6265  for(Int_t p=1;p<=fnBinsPt;p++)
6266  {
6267   Double_t v2 = fDiffFlow[t][0][0]->GetBinContent(p);
6268   Double_t v4 = fDiffFlow[t][0][1]->GetBinContent(p);
6269   Double_t v6 = fDiffFlow[t][0][2]->GetBinContent(p);
6270   Double_t v8 = fDiffFlow[t][0][3]->GetBinContent(p);
6271   
6272   Double_t v2Error = fDiffFlow[t][0][0]->GetBinError(p);
6273   Double_t v4Error = fDiffFlow[t][0][1]->GetBinError(p);
6274   //Double_t v6Error = fFinalFlow1D[t][pW][nua][0][2]->GetBinError(p);
6275   //Double_t v8Error = fFinalFlow1D[t][pW][nua][0][3]->GetBinError(p);
6276  
6277   if(type == "RP")
6278   {
6279    fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,v2,v2Error);
6280    fCommonHistsResults4th->FillDifferentialFlowPtRP(p,v4,v4Error);
6281    fCommonHistsResults6th->FillDifferentialFlowPtRP(p,v6,0.);
6282    fCommonHistsResults8th->FillDifferentialFlowPtRP(p,v8,0.);
6283   } else if(type == "POI")
6284     {
6285      fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,v2,v2Error);
6286      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,v4,v4Error);
6287      fCommonHistsResults6th->FillDifferentialFlowPtPOI(p,v6,0.);
6288      fCommonHistsResults8th->FillDifferentialFlowPtPOI(p,v8,0.);
6289     }
6290  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
6291  
6292  // eta:
6293  for(Int_t e=1;e<=fnBinsEta;e++)
6294  {
6295   Double_t v2 = fDiffFlow[t][1][0]->GetBinContent(e);
6296   Double_t v4 = fDiffFlow[t][1][1]->GetBinContent(e);
6297   Double_t v6 = fDiffFlow[t][1][2]->GetBinContent(e);
6298   Double_t v8 = fDiffFlow[t][1][3]->GetBinContent(e);
6299   
6300   Double_t v2Error = fDiffFlow[t][1][0]->GetBinError(e);
6301   Double_t v4Error = fDiffFlow[t][1][1]->GetBinError(e);
6302   //Double_t v6Error = fDiffFlow[t][1][2]->GetBinError(e);
6303   //Double_t v8Error = fDiffFlow[t][1][3]->GetBinError(e);
6304  
6305   if(type == "RP")
6306   {
6307    fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,v2,v2Error);
6308    fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,v4,v4Error);
6309    fCommonHistsResults6th->FillDifferentialFlowEtaRP(e,v6,0.);
6310    fCommonHistsResults8th->FillDifferentialFlowEtaRP(e,v8,0.);
6311   } else if(type == "POI")
6312     {
6313      fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,v2,v2Error);
6314      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,v4,v4Error);
6315      fCommonHistsResults6th->FillDifferentialFlowEtaPOI(e,v6,0.);
6316      fCommonHistsResults8th->FillDifferentialFlowEtaPOI(e,v8,0.);
6317     }
6318  } // end of for(Int_t e=1;e<=fnBinsEta;e++)    
6319  
6320 } // end of void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
6321
6322 //================================================================================================================================
6323
6324 void AliFlowAnalysisWithQCumulants::AccessConstants()
6325 {
6326  // Access needed common constants from AliFlowCommonConstants.
6327  
6328  fnBinsPhi = AliFlowCommonConstants::GetMaster()->GetNbinsPhi();
6329  fPhiMin = AliFlowCommonConstants::GetMaster()->GetPhiMin();         
6330  fPhiMax = AliFlowCommonConstants::GetMaster()->GetPhiMax();
6331  if(fnBinsPhi) fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;  
6332  fnBinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
6333  fPtMin = AliFlowCommonConstants::GetMaster()->GetPtMin();           
6334  fPtMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
6335  if(fnBinsPt) fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;  
6336  fnBinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
6337  fEtaMin = AliFlowCommonConstants::GetMaster()->GetEtaMin();         
6338  fEtaMax = AliFlowCommonConstants::GetMaster()->GetEtaMax();
6339  if(fnBinsEta) fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;  
6340  
6341 } // end of void AliFlowAnalysisWithQCumulants::AccessConstants()
6342
6343 //================================================================================================================================
6344
6345 void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6346 {
6347  // a) Cross check if the choice for multiplicity weights make sense;
6348  
6349  // a) Cross check if the choice for multiplicity weights make sense:
6350  if(strcmp(fMultiplicityWeight->Data(),"combinations") && 
6351     strcmp(fMultiplicityWeight->Data(),"unit") &&
6352     strcmp(fMultiplicityWeight->Data(),"multiplicity"))
6353  {
6354   cout<<"WARNING (QC): Multiplicity weight can be either \"combinations\", \"unit\""<<endl;
6355   cout<<"              or \"multiplicity\". Certainly not \""<<fMultiplicityWeight->Data()<<"\"."<<endl;
6356   exit(0);
6357  }   
6358  
6359 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6360
6361 //================================================================================================================================
6362
6363 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6364 {
6365  // Calculate sum of linear and quadratic event weights for correlations.
6366  
6367  // multiplicity:
6368  Double_t dMult = (*fSMpk)(0,0);
6369                         
6370  for(Int_t p=0;p<2;p++) // power-1
6371  {
6372   for(Int_t ci=0;ci<4;ci++) // correlation index
6373   { 
6374    fIntFlowSumOfEventWeights[p]->Fill(ci+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); 
6375    if(fCalculateCumulantsVsM)
6376    {
6377     fIntFlowSumOfEventWeightsVsM[ci][p]->Fill(dMult+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); // to be improved: dMult => sum of weights?
6378    }
6379   }
6380  }
6381   
6382 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6383
6384 //================================================================================================================================
6385
6386 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6387 {
6388  // Calculate sum of linear and quadratic event weights for NUA terms.
6389                        
6390  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
6391  {
6392   for(Int_t p=0;p<2;p++) // power-1
6393   {
6394    for(Int_t ci=0;ci<4;ci++) // nua term index
6395    { 
6396     fIntFlowSumOfEventWeightsNUA[sc][p]->Fill(ci+0.5,pow(fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->GetBinContent(ci+1),p+1)); 
6397    }
6398   }
6399  }
6400   
6401 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6402
6403 //================================================================================================================================
6404
6405 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6406 {
6407  // Calculate sum of product of event weights for correlations.
6408   
6409  // multiplicity:
6410  Double_t dMult = (*fSMpk)(0,0);
6411   
6412  Int_t counter = 0;
6413  
6414  for(Int_t ci1=1;ci1<4;ci1++)
6415  {
6416   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
6417   {
6418    fIntFlowSumOfProductOfEventWeights->Fill(0.5+counter,
6419                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6420                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6421    if(fCalculateCumulantsVsM)
6422    {                                                                                    
6423     fIntFlowSumOfProductOfEventWeightsVsM[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights?
6424                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6425                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6426    } // end of if(fCalculateCumulantsVsM)
6427    counter++;                                         
6428   }
6429  }
6430
6431 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6432
6433 //================================================================================================================================
6434
6435 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeightsNUA()
6436 {
6437  // Calculate sum of product of event weights for NUA terms.
6438   
6439  // w_{<2>} * w_{<cos(#phi)>}:
6440  fIntFlowSumOfProductOfEventWeightsNUA->Fill(0.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6441                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6442  // w_{<2>} * w_{<sin(#phi)>}:
6443  fIntFlowSumOfProductOfEventWeightsNUA->Fill(1.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6444                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6445  // w_{<cos(#phi)> * w_{<sin(#phi)>}:
6446  fIntFlowSumOfProductOfEventWeightsNUA->Fill(2.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6447                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6448  // w_{<2>} * w{<cos(phi1+phi2)>}
6449  fIntFlowSumOfProductOfEventWeightsNUA->Fill(3.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6450                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6451  // w_{<2>} * w{<sin(phi1+phi2)>}
6452  fIntFlowSumOfProductOfEventWeightsNUA->Fill(4.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6453                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6454  // w_{<2>} * w{<cos(phi1-phi2-phi3)>}
6455  fIntFlowSumOfProductOfEventWeightsNUA->Fill(5.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6456                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6457  // w_{<2>} * w{<sin(phi1-phi2-phi3)>}
6458  fIntFlowSumOfProductOfEventWeightsNUA->Fill(6.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6459                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
6460  // w_{<4>} * w{<cos(phi1)>}
6461  fIntFlowSumOfProductOfEventWeightsNUA->Fill(7.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6462                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6463  // w_{<4>} * w{<sin(phi1)>}
6464  fIntFlowSumOfProductOfEventWeightsNUA->Fill(8.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6465                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6466  // w_{<4>} * w{<cos(phi1+phi2)>}
6467  fIntFlowSumOfProductOfEventWeightsNUA->Fill(9.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6468                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6469  // w_{<4>} * w{<sin(phi1+phi2)>}
6470  fIntFlowSumOfProductOfEventWeightsNUA->Fill(10.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6471                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6472  // w_{<4>} * w{<cos(phi1-phi2-phi3)>}
6473  fIntFlowSumOfProductOfEventWeightsNUA->Fill(11.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6474                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6475  // w_{<4>} * w{<sin(phi1-phi2-phi3)>}
6476  fIntFlowSumOfProductOfEventWeightsNUA->Fill(12.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6477                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6478  // w_{<cos(phi1)>} * w{<cos(phi1+phi2)>}
6479  fIntFlowSumOfProductOfEventWeightsNUA->Fill(13.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6480                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6481  // w_{<cos(phi1)>} * w{<sin(phi1+phi2)>}
6482  fIntFlowSumOfProductOfEventWeightsNUA->Fill(14.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6483                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6484  // w_{<cos(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6485  fIntFlowSumOfProductOfEventWeightsNUA->Fill(15.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6486                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6487  // w_{<cos(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6488  fIntFlowSumOfProductOfEventWeightsNUA->Fill(16.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6489                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6490  // w_{<sin(phi1)>} * w{<cos(phi1+phi2)>}
6491  fIntFlowSumOfProductOfEventWeightsNUA->Fill(17.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6492                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6493  // w_{<sin(phi1)>} * w{<sin(phi1+phi2)>}
6494  fIntFlowSumOfProductOfEventWeightsNUA->Fill(18.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6495                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6496  // w_{<sin(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6497  fIntFlowSumOfProductOfEventWeightsNUA->Fill(19.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6498                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6499  // w_{<sin(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6500  fIntFlowSumOfProductOfEventWeightsNUA->Fill(20.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6501                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6502  // w_{<cos(phi1+phi2)>} * w{<sin(phi1+phi2))>}
6503  fIntFlowSumOfProductOfEventWeightsNUA->Fill(21.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6504                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6505  // w_{<cos(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6506  fIntFlowSumOfProductOfEventWeightsNUA->Fill(22.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6507                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6508  // w_{<cos(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6509  fIntFlowSumOfProductOfEventWeightsNUA->Fill(23.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6510                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6511  // w_{<sin(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6512  fIntFlowSumOfProductOfEventWeightsNUA->Fill(24.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6513                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6514  // w_{<sin(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6515  fIntFlowSumOfProductOfEventWeightsNUA->Fill(25.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6516                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6517  // w_{<cos(phi1-phi2-phi3)>} * w{<sin(phi1-phi2-phi3)>}
6518  fIntFlowSumOfProductOfEventWeightsNUA->Fill(26.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)*
6519                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6520
6521 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowIntFlowSumOfProductOfEventWeightsNUA()
6522
6523
6524 //================================================================================================================================
6525
6526
6527 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta)
6528 {
6529  // calculate reduced correlations for RPs or POIs in pt or eta bins
6530
6531  // multiplicity:
6532  Double_t dMult = (*fSMpk)(0,0);
6533  
6534  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
6535  Double_t dReQ1n = (*fReQ)(0,0);
6536  Double_t dReQ2n = (*fReQ)(1,0);
6537  //Double_t dReQ3n = (*fReQ)(2,0);
6538  //Double_t dReQ4n = (*fReQ)(3,0);
6539  Double_t dImQ1n = (*fImQ)(0,0);
6540  Double_t dImQ2n = (*fImQ)(1,0);
6541  //Double_t dImQ3n = (*fImQ)(2,0);
6542  //Double_t dImQ4n = (*fImQ)(3,0);
6543
6544  // reduced correlations are stored in fDiffFlowCorrelationsPro[0=RP,1=POI][0=pt,1=eta][correlation index]. Correlation index runs as follows:
6545  // 
6546  // 0: <<2'>>
6547  // 1: <<4'>>
6548  // 2: <<6'>>
6549  // 3: <<8'>>
6550  
6551  Int_t t = 0; // type flag 
6552  Int_t pe = 0; // ptEta flag
6553  
6554  if(type == "RP")
6555  {
6556   t = 0;
6557  } else if(type == "POI")
6558    {
6559     t = 1;
6560    }
6561
6562  if(ptOrEta == "Pt")
6563  {
6564   pe = 0;
6565  } else if(ptOrEta == "Eta")
6566    {
6567     pe = 1;
6568    }
6569     
6570  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6571  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6572  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6573  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6574
6575  // looping over all bins and calculating reduced correlations: 
6576  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6577  {
6578   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
6579   Double_t p1n0kRe = 0.;
6580   Double_t p1n0kIm = 0.;
6581
6582   // number of POIs in particular pt or eta bin:
6583   Double_t mp = 0.;
6584
6585   // 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):
6586   Double_t q1n0kRe = 0.;
6587   Double_t q1n0kIm = 0.;
6588   Double_t q2n0kRe = 0.;
6589   Double_t q2n0kIm = 0.;
6590
6591   // number of particles which are both RPs and POIs in particular pt or eta bin:
6592   Double_t mq = 0.;
6593    
6594   if(type == "POI")
6595   {
6596    // q_{m*n,0}:
6597    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
6598            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
6599    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
6600            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
6601    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
6602            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
6603    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
6604            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
6605                  
6606    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6607   } 
6608   else if(type == "RP")
6609   {
6610    // q_{m*n,0}:
6611    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
6612            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
6613    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
6614            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
6615    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
6616            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
6617    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
6618            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
6619                  
6620    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
6621   }
6622       
6623    if(type == "POI")
6624    {
6625     // p_{m*n,0}:
6626     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
6627             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
6628     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
6629             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
6630             
6631     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6632     
6633     t = 1; // typeFlag = RP or POI
6634    }
6635    else if(type == "RP")
6636    {
6637     // p_{m*n,0} = q_{m*n,0}:
6638     p1n0kRe = q1n0kRe; 
6639     p1n0kIm = q1n0kIm; 
6640             
6641     mp = mq; 
6642     
6643     t = 0; // typeFlag = RP or POI
6644    }
6645       
6646    // 2'-particle correlation for particular (pt,eta) bin:
6647    Double_t two1n1nPtEta = 0.;
6648    Double_t mWeight2pPrime = 0.; // multiplicity weight for <2'>
6649    if(mp*dMult-mq)
6650    {
6651     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
6652                  / (mp*dMult-mq);
6653     // determine multiplicity weight:
6654     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
6655     {
6656      mWeight2pPrime = mp*dMult-mq;
6657     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
6658       {
6659        mWeight2pPrime = 1.;    
6660       } 
6661     if(type == "POI") // to be improved (I do not this if)
6662     { 
6663      // fill profile to get <<2'>> for POIs
6664      fDiffFlowCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);
6665      // fill profile to get <<2'>^2> for POIs
6666      fDiffFlowSquaredCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);   
6667      // histogram to store <2'> for POIs e-b-e (needed in some other methods):
6668      fDiffFlowCorrelationsEBE[1][pe][0]->SetBinContent(b,two1n1nPtEta);      
6669      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][0]->SetBinContent(b,mWeight2pPrime);      
6670     }
6671     else if(type == "RP") // to be improved (I do not this if)
6672     {
6673      // profile to get <<2'>> for RPs:
6674      fDiffFlowCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);     
6675      // profile to get <<2'>^2> for RPs:
6676      fDiffFlowSquaredCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);          
6677      // histogram to store <2'> for RPs e-b-e (needed in some other methods):
6678      fDiffFlowCorrelationsEBE[0][pe][0]->SetBinContent(b,two1n1nPtEta); 
6679      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][0]->SetBinContent(b,mWeight2pPrime); 
6680     }
6681    } // end of if(mp*dMult-mq)
6682   
6683    // 4'-particle correlation:
6684    Double_t four1n1n1n1nPtEta = 0.;
6685    Double_t mWeight4pPrime = 0.; // multiplicity weight for <4'>
6686    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6687        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
6688    {
6689     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6690                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
6691                       - 2.*q2n0kIm*dReQ1n*dImQ1n
6692                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
6693                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
6694                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6695                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
6696                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
6697                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
6698                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
6699                       + 2.*mq*dMult                      
6700                       - 6.*mq)        
6701                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6702                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
6703     // determine multiplicity weight:
6704     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
6705     {
6706      mWeight4pPrime = (mp-mq)*dMult*(dMult-1.)*(dMult-2.) + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);
6707     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
6708       {
6709        mWeight4pPrime = 1.;    
6710       }     
6711     if(type == "POI")
6712     {
6713      // profile to get <<4'>> for POIs:
6714      fDiffFlowCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);      
6715      // profile to get <<4'>^2> for POIs:
6716      fDiffFlowSquaredCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime); 
6717      // histogram to store <4'> for POIs e-b-e (needed in some other methods):
6718      fDiffFlowCorrelationsEBE[1][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                               
6719      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][1]->SetBinContent(b,mWeight4pPrime);                               
6720     }
6721     else if(type == "RP")
6722     {
6723      // profile to get <<4'>> for RPs:
6724      fDiffFlowCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);    
6725      // profile to get <<4'>^2> for RPs:
6726      fDiffFlowSquaredCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime);    
6727      // histogram to store <4'> for RPs e-b-e (needed in some other methods):
6728      fDiffFlowCorrelationsEBE[0][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                   
6729      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][1]->SetBinContent(b,mWeight4pPrime);                   
6730     }
6731    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6732      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
6733    
6734  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6735  
6736    
6737 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta);
6738
6739 //================================================================================================================================
6740
6741 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights(TString type, TString ptOrEta)
6742 {
6743  // Calculate sums of various event weights for reduced correlations. 
6744  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
6745
6746  Int_t typeFlag = 0;
6747  Int_t ptEtaFlag = 0;
6748
6749  if(type == "RP")
6750  {
6751   typeFlag = 0;
6752  } else if(type == "POI")
6753    {
6754     typeFlag = 1;
6755    } 
6756      
6757  if(ptOrEta == "Pt")
6758  {
6759   ptEtaFlag = 0;
6760  } else if(ptOrEta == "Eta")
6761    {
6762     ptEtaFlag = 1;
6763    } 
6764    
6765  // shortcuts:
6766  Int_t t = typeFlag;
6767  Int_t pe = ptEtaFlag;
6768  
6769  // binning:
6770  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6771  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6772  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6773  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6774  
6775  for(Int_t rpq=0;rpq<3;rpq++)
6776  {
6777   for(Int_t m=0;m<4;m++)
6778   {
6779    for(Int_t k=0;k<9;k++)
6780    {
6781     if(!fReRPQ1dEBE[rpq][pe][m][k])
6782     {
6783      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
6784      cout<<"pe  = "<<pe<<endl;
6785      cout<<"rpq = "<<rpq<<endl;
6786      cout<<"m   = "<<m<<endl;
6787      cout<<"k   = "<<k<<endl;
6788      exit(0); 
6789     }
6790    }
6791   }
6792  }  
6793
6794  // multiplicities:
6795  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
6796  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
6797  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
6798  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
6799  
6800  // event weights for reduced correlations:
6801  Double_t dw2 = 0.; // event weight for <2'>
6802  Double_t dw4 = 0.; // event weight for <4'>
6803  //Double_t dw6 = 0.; // event weight for <6'>
6804  //Double_t dw8 = 0.; // event weight for <8'>
6805
6806  // looping over bins:
6807  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6808  {
6809   if(type == "RP")
6810   {
6811    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
6812    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
6813   } else if(type == "POI")
6814     {
6815      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
6816      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
6817     }
6818   
6819   // event weight for <2'>:
6820   dw2 = mp*dMult-mq;  
6821   fDiffFlowSumOfEventWeights[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2);
6822   fDiffFlowSumOfEventWeights[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw2,2.));
6823   
6824   // event weight for <4'>:
6825   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6826      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
6827   fDiffFlowSumOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4);
6828   fDiffFlowSumOfEventWeights[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw4,2.));
6829   
6830   // event weight for <6'>:
6831   //dw6 = ...;  
6832   //fDiffFlowSumOfEventWeights[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6);
6833   //fDiffFlowSumOfEventWeights[t][pe][t][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw6,2.));
6834   
6835   // event weight for <8'>:
6836   //dw8 = ...;  
6837   //fDiffFlowSumOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw8);
6838   //fDiffFlowSumOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw8,2.));   
6839  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++) 
6840  
6841 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights()
6842
6843
6844 //================================================================================================================================
6845
6846
6847 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
6848 {
6849  // Calculate sum of products of various event weights for both types of correlations (the ones for int. and diff. flow). 
6850  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
6851  //
6852  // Important: To fill fDiffFlowSumOfProductOfEventWeights[][][][] use bellow table (i,j) with following constraints: 
6853  // 1.) i<j  
6854  // 2.) do not store terms which DO NOT include reduced correlations;
6855  // Table:
6856  // [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'>]
6857   
6858  Int_t typeFlag = 0;
6859  Int_t ptEtaFlag = 0;
6860
6861  if(type == "RP")
6862  {
6863   typeFlag = 0;
6864  } else if(type == "POI")
6865    {
6866     typeFlag = 1;
6867    } 
6868      
6869  if(ptOrEta == "Pt")
6870  {
6871   ptEtaFlag = 0;
6872  } else if(ptOrEta == "Eta")
6873    {
6874     ptEtaFlag = 1;
6875    } 
6876      
6877  // shortcuts:
6878  Int_t t = typeFlag;
6879  Int_t pe = ptEtaFlag;
6880   
6881  // binning:
6882  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6883  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6884  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6885  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6886  
6887  // protection:
6888  for(Int_t rpq=0;rpq<3;rpq++)
6889  {
6890   for(Int_t m=0;m<4;m++)
6891   {
6892    for(Int_t k=0;k<9;k++)
6893    {
6894     if(!fReRPQ1dEBE[rpq][pe][m][k])
6895     {
6896      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
6897      cout<<"pe  = "<<pe<<endl;
6898      cout<<"rpq = "<<rpq<<endl;
6899      cout<<"m   = "<<m<<endl;
6900      cout<<"k   = "<<k<<endl;
6901      exit(0); 
6902     }
6903    }
6904   }
6905  }  
6906  
6907  // multiplicities:
6908  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
6909  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
6910  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
6911  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
6912  
6913  // event weights for correlations:
6914  Double_t dW2 = dMult*(dMult-1); // event weight for <2> 
6915  Double_t dW4 = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
6916  Double_t dW6 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
6917  Double_t dW8 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
6918
6919  // event weights for reduced correlations:
6920  Double_t dw2 = 0.; // event weight for <2'>
6921  Double_t dw4 = 0.; // event weight for <4'>
6922  //Double_t dw6 = 0.; // event weight for <6'>
6923  //Double_t dw8 = 0.; // event weight for <8'>
6924  
6925  // looping over bins:
6926  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6927  {
6928   if(type == "RP")
6929   {
6930    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
6931    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
6932   } else if(type == "POI")
6933     {
6934      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
6935      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
6936     }
6937   
6938   // event weight for <2'>:
6939   dw2 = mp*dMult-mq;  
6940   fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw2); // storing product of even weights for <2> and <2'>
6941   fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW4); // storing product of even weights for <4> and <2'>
6942   fDiffFlowSumOfProductOfEventWeights[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW6); // storing product of even weights for <6> and <2'>
6943   fDiffFlowSumOfProductOfEventWeights[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW8); // storing product of even weights for <8> and <2'>
6944   
6945   // event weight for <4'>:
6946   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6947      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
6948   fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw4); // storing product of even weights for <2> and <4'>
6949   fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw4); // storing product of even weights for <2'> and <4'>
6950   fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw4); // storing product of even weights for <4> and <4'>
6951   fDiffFlowSumOfProductOfEventWeights[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW6); // storing product of even weights for <6> and <4'> 
6952   fDiffFlowSumOfProductOfEventWeights[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW8); // storing product of even weights for <8> and <4'>
6953
6954   // event weight for <6'>:
6955   //dw6 = ...;  
6956   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw6); // storing product of even weights for <2> and <6'>
6957   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw6); // storing product of even weights for <2'> and <6'>
6958   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw6); // storing product of even weights for <4> and <6'>
6959   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw6); // storing product of even weights for <4'> and <6'> 
6960   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw6); // storing product of even weights for <6> and <6'>
6961   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dW8); // storing product of even weights for <6'> and <8>
6962   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
6963
6964   // event weight for <8'>:
6965   //dw8 = ...;  
6966   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw8); // storing product of even weights for <2> and <8'>
6967   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw8); // storing product of even weights for <2'> and <8'>
6968   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw8); // storing product of even weights for <4> and <8'>
6969   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw8); // storing product of even weights for <4'> and <8'> 
6970   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw8); // storing product of even weights for <6> and <8'>
6971   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
6972   //fDiffFlowSumOfProductOfEventWeights[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW8*dw8); // storing product of even weights for <8> and <8'>
6973   
6974   // Table:
6975   // [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'>]
6976    
6977  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6978  
6979
6980
6981 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
6982
6983
6984 //================================================================================================================================
6985
6986
6987 void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
6988 {
6989  // Transfer profiles into histograms and calculate statistical errors correctly.
6990
6991  Int_t typeFlag = 0;
6992  Int_t ptEtaFlag = 0;
6993
6994  if(type == "RP")
6995  {
6996   typeFlag = 0;
6997  } else if(type == "POI")
6998    {
6999     typeFlag = 1;
7000    } 
7001      
7002  if(ptOrEta == "Pt")
7003  {
7004   ptEtaFlag = 0;
7005  } else if(ptOrEta == "Eta")
7006    {
7007     ptEtaFlag = 1;
7008    } 
7009   
7010  // shortcuts:
7011  Int_t t = typeFlag;
7012  Int_t pe = ptEtaFlag;
7013              
7014  for(Int_t rci=0;rci<4;rci++)
7015  {
7016   if(!fDiffFlowCorrelationsPro[t][pe][rci])
7017   {
7018    cout<<"WARNING: fDiffFlowCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7019    cout<<"t   = "<<t<<endl; 
7020    cout<<"pe  = "<<pe<<endl; 
7021    cout<<"rci = "<<rci<<endl;
7022    exit(0); 
7023   }
7024   if(!fDiffFlowSquaredCorrelationsPro[t][pe][rci])
7025   {
7026    cout<<"WARNING: fDiffFlowSquaredCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7027    cout<<"t   = "<<t<<endl; 
7028    cout<<"pe  = "<<pe<<endl; 
7029    cout<<"rci = "<<rci<<endl;
7030    exit(0); 
7031   }
7032   for(Int_t power=0;power<2;power++)
7033   {
7034    if(!fDiffFlowSumOfEventWeights[t][pe][power][rci])
7035    {
7036     cout<<"WARNING: fDiffFlowSumOfEventWeights[t][pe][power][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7037     cout<<"t     = "<<t<<endl; 
7038     cout<<"pe    = "<<pe<<endl;
7039     cout<<"power = "<<power<<endl; 
7040     cout<<"rci   = "<<rci<<endl;
7041     exit(0); 
7042    }   
7043   } // end of for(Int_t power=0;power<2;power++)
7044  } // end of for(Int_t rci=0;rci<4;rci++)
7045     
7046  // common:
7047  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta}; 
7048  // transfer 1D profile into 1D histogram:
7049  Double_t correlation = 0.;
7050  Double_t squaredCorrelation = 0.;
7051  Double_t spread = 0.;
7052  Double_t sumOfWeights = 0.; // sum of weights for particular reduced correlations for particular pt or eta bin
7053  Double_t sumOfSquaredWeights = 0.; // sum of squared weights for particular reduced correlations for particular pt or eta bin
7054  Double_t error = 0.; // error = termA * spread * termB
7055                       // termA = (sqrt(sumOfSquaredWeights)/sumOfWeights) 
7056                       // termB = 1/pow(1-termA^2,0.5)
7057  Double_t termA = 0.;                      
7058  Double_t termB = 0.;                      
7059  for(Int_t rci=0;rci<4;rci++) // index of reduced correlation
7060  {
7061   for(Int_t b=1;b<=nBinsPtEta[pe];b++) // number of pt or eta bins
7062   {
7063    if(fDiffFlowCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2 || 
7064       fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2)
7065    {
7066     fDiffFlowCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7067     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7068     continue; // to be improved - should I ignore results in pt bins with one entry for reduced correlations or not?
7069    }  
7070    correlation = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7071    squaredCorrelation = fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7072    if(squaredCorrelation-correlation*correlation >= 0.)
7073    {
7074     spread = pow(squaredCorrelation-correlation*correlation,0.5);
7075    } else
7076      {
7077       cout<<endl;
7078       cout<<Form(" WARNING: Imaginary 'spread' for rci = %d, pe = %d, bin = %d !!!!",rci,pe,b)<<endl;
7079       cout<<endl;
7080      }
7081    sumOfWeights = fDiffFlowSumOfEventWeights[t][pe][0][rci]->GetBinContent(b);
7082    sumOfSquaredWeights = fDiffFlowSumOfEventWeights[t][pe][1][rci]->GetBinContent(b);
7083    if(sumOfWeights) termA = (pow(sumOfSquaredWeights,0.5)/sumOfWeights);
7084    if(1.-pow(termA,2.)>0.) termB = 1./pow(1.-pow(termA,2.),0.5); 
7085    error = termA*spread*termB; // final error (unbiased estimator for standard deviation)
7086    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinContent(b,correlation); 
7087    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinError(b,error); 
7088   } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7089  } // end of for(Int_t rci=0;rci<4;rci++)
7090  
7091 } // end of void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
7092
7093
7094 //================================================================================================================================
7095
7096
7097 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7098 {
7099  // store products: <2><2'>, <2><4'>, <2><6'>, <2><8'>, <2'><4>, 
7100  //                 <2'><4'>, <2'><6>, <2'><6'>, <2'><8>, <2'><8'>,
7101  //                 <4><4'>, <4><6'>, <4><8'>, <4'><6>, <4'><6'>, 
7102  //                 <4'><8>, <4'><8'>, <6><6'>, <6><8'>, <6'><8>, 
7103  //                 <6'><8'>, <8><8'>.
7104   
7105  Int_t typeFlag = 0;
7106  Int_t ptEtaFlag = 0;
7107
7108  if(type == "RP")
7109  {
7110   typeFlag = 0;
7111  } else if(type == "POI")
7112    {
7113     typeFlag = 1;
7114    } 
7115      
7116  if(ptOrEta == "Pt")
7117  {
7118   ptEtaFlag = 0;
7119  } else if(ptOrEta == "Eta")
7120    {
7121     ptEtaFlag = 1;
7122    } 
7123   
7124  // shortcuts:
7125  Int_t t = typeFlag;
7126  Int_t pe = ptEtaFlag;
7127      
7128  // common:
7129  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7130  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7131  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7132    
7133  // protections // to be improved (add protection for all pointers in this method)
7134  if(!fIntFlowCorrelationsEBE)
7135  {
7136   cout<<"WARNING: fIntFlowCorrelationsEBE is NULL in AFAWQC::CDFPOC() !!!!"<<endl;
7137   exit(0);
7138  } 
7139  
7140  /*    
7141  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
7142  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7143  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7144  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7145  */
7146
7147  // e-b-e correlations:
7148  Double_t twoEBE = fIntFlowCorrelationsEBE->GetBinContent(1); // <2>
7149  Double_t fourEBE = fIntFlowCorrelationsEBE->GetBinContent(2); // <4>
7150  Double_t sixEBE = fIntFlowCorrelationsEBE->GetBinContent(3); // <6>
7151  Double_t eightEBE = fIntFlowCorrelationsEBE->GetBinContent(4); // <8>
7152  
7153  // event weights for correlations:
7154  Double_t dW2 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1); // event weight for <2> 
7155  Double_t dW4 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2); // event weight for <4> 
7156  Double_t dW6 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(3); // event weight for <6> 
7157  Double_t dW8 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(4); // event weight for <8> 
7158   
7159  // e-b-e reduced correlations:
7160  Double_t twoReducedEBE = 0.; // <2'>
7161  Double_t fourReducedEBE = 0.; // <4'>
7162  Double_t sixReducedEBE = 0.; // <6'>
7163  Double_t eightReducedEBE = 0.; // <8'> 
7164  
7165  // event weights for reduced correlations:
7166  Double_t dw2 = 0.; // event weight for <2'>
7167  Double_t dw4 = 0.; // event weight for <4'>
7168  //Double_t dw6 = 0.; // event weight for <6'>
7169  //Double_t dw8 = 0.; // event weight for <8'>
7170
7171  // looping over bins:
7172  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7173  {
7174   // e-b-e reduced correlations:
7175   twoReducedEBE = fDiffFlowCorrelationsEBE[t][pe][0]->GetBinContent(b);
7176   fourReducedEBE = fDiffFlowCorrelationsEBE[t][pe][1]->GetBinContent(b);
7177   sixReducedEBE = fDiffFlowCorrelationsEBE[t][pe][2]->GetBinContent(b);
7178   eightReducedEBE = fDiffFlowCorrelationsEBE[t][pe][3]->GetBinContent(b);
7179   
7180   /*
7181   // to be improved (I should not do this here again)
7182   if(type == "RP")
7183   {
7184    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7185    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7186   } else if(type == "POI")
7187     {
7188      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7189      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7190     }
7191   
7192   // event weights for reduced correlations:
7193   dw2 = mp*dMult-mq; // weight for <2'> 
7194   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7195      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.); // weight for <4'>
7196   //dw6 = ...     
7197   //dw8 = ...     
7198   
7199   */
7200   
7201   dw2 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->GetBinContent(b);
7202   dw4 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->GetBinContent(b);
7203  
7204   // storing all products:
7205   fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*twoReducedEBE,dW2*dw2); // storing <2><2'>
7206   fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*twoReducedEBE,dW4*dw2); // storing <4><2'>
7207   fDiffFlowProductOfCorrelationsPro[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*twoReducedEBE,dW6*dw2); // storing <6><2'>
7208   fDiffFlowProductOfCorrelationsPro[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*twoReducedEBE,dW8*dw2); // storing <8><2'>
7209   
7210   // event weight for <4'>:
7211   fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*fourReducedEBE,dW2*dw4); // storing <2><4'>
7212   fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*fourReducedEBE,dw2*dw4); // storing <2'><4'>
7213   fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*fourReducedEBE,dW4*dw4); // storing <4><4'>
7214   fDiffFlowProductOfCorrelationsPro[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*fourReducedEBE,dW6*dw4); // storing <6><4'> 
7215   fDiffFlowProductOfCorrelationsPro[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*fourReducedEBE,dW8*dw4); // storing <8><4'>
7216
7217   // event weight for <6'>:
7218   //dw6 = ...;  
7219   //fDiffFlowProductOfCorrelationsPro[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*sixReducedEBE,dW2*dw6); // storing <2><6'>
7220   //fDiffFlowProductOfCorrelationsPro[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*sixReducedEBE,dw2*dw6); // storing <2'><6'>
7221   //fDiffFlowProductOfCorrelationsPro[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*sixReducedEBE,dW4*dw6); // storing <4><6'>
7222   //fDiffFlowProductOfCorrelationsPro[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*sixReducedEBE,dw4*dw6); // storing <4'><6'> 
7223   //fDiffFlowProductOfCorrelationsPro[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*sixReducedEBE,dW6*dw6); // storing <6><6'>
7224   //fDiffFlowProductOfCorrelationsPro[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightEBE,dw6*dW8); // storing <6'><8>
7225   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7226
7227   // event weight for <8'>:
7228   //dw8 = ...;  
7229   //fDiffFlowProductOfCorrelationsPro[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*eightReducedEBE,dW2*dw8); // storing <2><8'>
7230   //fDiffFlowProductOfCorrelationsPro[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*eightReducedEBE,dw2*dw8); // storing <2'><8'>
7231   //fDiffFlowProductOfCorrelationsPro[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*eightReducedEBE,dW4*dw8); // storing <4><8'>
7232   //fDiffFlowProductOfCorrelationsPro[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*eightReducedEBE,dw4*dw8); // storing <4'><8'> 
7233   //fDiffFlowProductOfCorrelationsPro[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*eightReducedEBE,dW6*dw8); // storing <6><8'>
7234   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7235   //fDiffFlowProductOfCorrelationsPro[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*eightReducedEBE,dW8*dw8); // storing <8><8'> 
7236  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++       
7237      
7238 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7239
7240
7241 //================================================================================================================================
7242     
7243     
7244 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta) // to be improved (reimplemented)
7245 {
7246  // a) Calculate unbiased estimators Cov(<2>,<2'>), Cov(<2>,<4'>), Cov(<4>,<2'>), Cov(<4>,<4'>) and Cov(<2'>,<4'>)
7247  //    for covariances V(<2>,<2'>), V(<2>,<4'>), V(<4>,<2'>), V(<4>,<4'>) and V(<2'>,<4'>).  
7248  // b) Store in histogram fDiffFlowCovariances[t][pe][index] for instance the following: 
7249  //
7250  //             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)]
7251  // 
7252  //     where N is the number of events, w_{<2>} is event weight for <2> and w_{<2'>} is event weight for <2'>.
7253  // c) Binning of fDiffFlowCovariances[t][pe][index] is organized as follows:
7254  // 
7255  //     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)] 
7256  //     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)] 
7257  //     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)] 
7258  //     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)] 
7259  //     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)] 
7260  //     ...
7261   
7262  Int_t typeFlag = 0;
7263  Int_t ptEtaFlag = 0;
7264
7265  if(type == "RP")
7266  {
7267   typeFlag = 0;
7268  } else if(type == "POI")
7269    {
7270     typeFlag = 1;
7271    } 
7272      
7273  if(ptOrEta == "Pt")
7274  {
7275   ptEtaFlag = 0;
7276  } else if(ptOrEta == "Eta")
7277    {
7278     ptEtaFlag = 1;
7279    } 
7280   
7281  // shortcuts:
7282  Int_t t = typeFlag;
7283  Int_t pe = ptEtaFlag;
7284      
7285  // common:
7286  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7287  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
7288  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7289  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7290  
7291  // average correlations:
7292  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7293  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7294  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
7295  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
7296  
7297  // sum of weights for correlation:
7298  Double_t sumOfWeightsForTwo = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // sum_{i=1}^{N} w_{<2>}
7299  Double_t sumOfWeightsForFour = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // sum_{i=1}^{N} w_{<4>}
7300  //Double_t sumOfWeightsForSix = fIntFlowSumOfEventWeights[0]->GetBinContent(3); // sum_{i=1}^{N} w_{<6>}
7301  //Double_t sumOfWeightsForEight = fIntFlowSumOfEventWeights[0]->GetBinContent(4); // sum_{i=1}^{N} w_{<8>}
7302  
7303  // average reduced correlations:
7304  Double_t twoReduced = 0.; // <<2'>> 
7305  Double_t fourReduced = 0.; // <<4'>>
7306  //Double_t sixReduced = 0.; // <<6'>>
7307  //Double_t eightReduced = 0.; // <<8'>>
7308
7309  // sum of weights for reduced correlation:
7310  Double_t sumOfWeightsForTwoReduced = 0.; // sum_{i=1}^{N} w_{<2'>}
7311  Double_t sumOfWeightsForFourReduced = 0.; // sum_{i=1}^{N} w_{<4'>}
7312  //Double_t sumOfWeightsForSixReduced = 0.; // sum_{i=1}^{N} w_{<6'>}
7313  //Double_t sumOfWeightsForEightReduced = 0.; // sum_{i=1}^{N} w_{<8'>}
7314   
7315  // product of weights for reduced correlation:
7316  Double_t productOfWeightsForTwoTwoReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<2'>}
7317  Double_t productOfWeightsForTwoFourReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<4'>}
7318  Double_t productOfWeightsForFourTwoReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<2'>}
7319  Double_t productOfWeightsForFourFourReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<4'>}
7320  Double_t productOfWeightsForTwoReducedFourReduced = 0.; // sum_{i=1}^{N} w_{<2'>}w_{<4'>}
7321  // ...
7322  
7323  // products for differential flow:
7324  Double_t twoTwoReduced = 0; // <<2><2'>> 
7325  Double_t twoFourReduced = 0; // <<2><4'>> 
7326  Double_t fourTwoReduced = 0; // <<4><2'>> 
7327  Double_t fourFourReduced = 0; // <<4><4'>> 
7328  Double_t twoReducedFourReduced = 0; // <<2'><4'>> 
7329
7330  // denominators in the expressions for the unbiased estimators for covariances:
7331  // denominator = 1 - term1/(term2*term3)
7332  // prefactor = term1/(term2*term3)
7333  Double_t denominator = 0.; 
7334  Double_t prefactor = 0.;
7335  Double_t term1 = 0.; 
7336  Double_t term2 = 0.; 
7337  Double_t term3 = 0.; 
7338  
7339  // unbiased estimators for covariances for differential flow:
7340  Double_t covTwoTwoReduced = 0.; // Cov(<2>,<2'>)
7341  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(w_{<2>},w_{<2'>})
7342  Double_t covTwoFourReduced = 0.; // Cov(<2>,<4'>)
7343  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(w_{<2>},w_{<4'>})
7344  Double_t covFourTwoReduced = 0.; // Cov(<4>,<2'>)
7345  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(w_{<4>},w_{<2'>})
7346  Double_t covFourFourReduced = 0.; // Cov(<4>,<4'>)
7347  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(w_{<4>},w_{<4'>})
7348  Double_t covTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>)
7349  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(w_{<2'>},w_{<4'>})
7350  
7351  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7352  {
7353   // average reduced corelations:
7354   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
7355   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
7356   // average products:
7357   twoTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->GetBinContent(b);
7358   twoFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->GetBinContent(b);
7359   fourTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->GetBinContent(b);
7360   fourFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->GetBinContent(b);
7361   twoReducedFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->GetBinContent(b);  
7362   // sum of weights for reduced correlations:
7363   sumOfWeightsForTwoReduced = fDiffFlowSumOfEventWeights[t][pe][0][0]->GetBinContent(b);
7364   sumOfWeightsForFourReduced = fDiffFlowSumOfEventWeights[t][pe][0][1]->GetBinContent(b);
7365   // products of weights for correlations:
7366   productOfWeightsForTwoTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->GetBinContent(b); 
7367   productOfWeightsForTwoFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->GetBinContent(b);
7368   productOfWeightsForFourTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->GetBinContent(b);
7369   productOfWeightsForFourFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->GetBinContent(b);
7370   productOfWeightsForTwoReducedFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->GetBinContent(b);
7371   // denominator for the unbiased estimator for covariances: 1 - term1/(term2*term3) 
7372   // prefactor (multiplies Cov's) = term1/(term2*term3)       
7373   // <2>,<2'>:
7374   term1 = productOfWeightsForTwoTwoReduced;      
7375   term2 = sumOfWeightsForTwo;
7376   term3 = sumOfWeightsForTwoReduced;        
7377   if(term2*term3>0.)
7378   {
7379    denominator = 1.-term1/(term2*term3);
7380    prefactor = term1/(term2*term3);
7381    if(TMath::Abs(denominator)>1e-6)
7382    {
7383     covTwoTwoReduced = (twoTwoReduced-two*twoReduced)/denominator;            
7384     wCovTwoTwoReduced = covTwoTwoReduced*prefactor; 
7385     fDiffFlowCovariances[t][pe][0]->SetBinContent(b,wCovTwoTwoReduced);
7386    }
7387   }
7388   // <2>,<4'>:
7389   term1 = productOfWeightsForTwoFourReduced;      
7390   term2 = sumOfWeightsForTwo;
7391   term3 = sumOfWeightsForFourReduced;        
7392   if(term2*term3>0.)
7393   {
7394    denominator = 1.-term1/(term2*term3);
7395    prefactor = term1/(term2*term3);
7396    if(TMath::Abs(denominator)>1e-6)
7397    {
7398     covTwoFourReduced = (twoFourReduced-two*fourReduced)/denominator;            
7399     wCovTwoFourReduced = covTwoFourReduced*prefactor; 
7400     fDiffFlowCovariances[t][pe][1]->SetBinContent(b,wCovTwoFourReduced);
7401    }
7402   }
7403   // <4>,<2'>:
7404   term1 = productOfWeightsForFourTwoReduced;      
7405   term2 = sumOfWeightsForFour;
7406   term3 = sumOfWeightsForTwoReduced;        
7407   if(term2*term3>0.)
7408   {
7409    denominator = 1.-term1/(term2*term3);
7410    prefactor = term1/(term2*term3);
7411    if(TMath::Abs(denominator)>1e-6)
7412    {
7413     covFourTwoReduced = (fourTwoReduced-four*twoReduced)/denominator;            
7414     wCovFourTwoReduced = covFourTwoReduced*prefactor; 
7415     fDiffFlowCovariances[t][pe][2]->SetBinContent(b,wCovFourTwoReduced);
7416    }
7417   }
7418   // <4>,<4'>:
7419   term1 = productOfWeightsForFourFourReduced;      
7420   term2 = sumOfWeightsForFour;
7421   term3 = sumOfWeightsForFourReduced;        
7422   if(term2*term3>0.)
7423   {
7424    denominator = 1.-term1/(term2*term3);
7425    prefactor = term1/(term2*term3);
7426    if(TMath::Abs(denominator)>1e-6)
7427    {
7428     covFourFourReduced = (fourFourReduced-four*fourReduced)/denominator;            
7429     wCovFourFourReduced = covFourFourReduced*prefactor; 
7430     fDiffFlowCovariances[t][pe][3]->SetBinContent(b,wCovFourFourReduced);
7431    }
7432   }
7433   // <2'>,<4'>:
7434   term1 = productOfWeightsForTwoReducedFourReduced;      
7435   term2 = sumOfWeightsForTwoReduced;
7436   term3 = sumOfWeightsForFourReduced;        
7437   if(term2*term3>0.)
7438   {
7439    denominator = 1.-term1/(term2*term3);
7440    prefactor = term1/(term2*term3);
7441    if(TMath::Abs(denominator)>1e-6)
7442    {
7443     covTwoReducedFourReduced = (twoReducedFourReduced-twoReduced*fourReduced)/denominator;            
7444     wCovTwoReducedFourReduced = covTwoReducedFourReduced*prefactor; 
7445     fDiffFlowCovariances[t][pe][4]->SetBinContent(b,wCovTwoReducedFourReduced);
7446    }
7447   }   
7448  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7449   
7450 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta)
7451
7452
7453 //================================================================================================================================
7454
7455
7456 void AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, TString ptOrEta)
7457 {
7458  // calculate differential flow from differential cumulants and previously obtained integrated flow: (to be improved: description)
7459  
7460  Int_t typeFlag = 0;
7461  Int_t ptEtaFlag = 0;
7462
7463  if(type == "RP")
7464  {
7465   typeFlag = 0;
7466  } else if(type == "POI")
7467    {
7468     typeFlag = 1;
7469    } 
7470      
7471  if(ptOrEta == "Pt")
7472  {
7473   ptEtaFlag = 0;
7474  } else if(ptOrEta == "Eta")
7475    {
7476     ptEtaFlag = 1;
7477    } 
7478   
7479  // shortcuts:
7480  Int_t t = typeFlag;
7481  Int_t pe = ptEtaFlag;
7482      
7483  // common:
7484  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7485    
7486  // correlations:
7487  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7488  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7489  
7490  // statistical errors of correlations:
7491  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
7492  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2);   
7493     
7494  // reduced correlations:
7495  Double_t twoReduced = 0.; // <<2'>>
7496  Double_t fourReduced = 0.; // <<4'>>
7497  
7498  // statistical errors of reduced correlations:
7499  Double_t twoReducedError = 0.; 
7500  Double_t fourReducedError = 0.; 
7501
7502  // covariances:
7503  Double_t wCovTwoFour = 0.; // Cov(<2>,<4>) * prefactor(<2>,<4>)
7504  if(!fForgetAboutCovariances)
7505  {
7506   wCovTwoFour = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(<2>,<4>)
7507  }
7508  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
7509  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
7510  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(<4>,<2'>)
7511  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(<4>,<4'>)
7512  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
7513  
7514  // differential flow:
7515  Double_t v2Prime = 0.; // v'{2}                   
7516  Double_t v4Prime = 0.; // v'{4}
7517  
7518  // statistical error of differential flow:
7519  Double_t v2PrimeError = 0.;                    
7520  Double_t v4PrimeError = 0.; 
7521  
7522  // squared statistical error of differential flow:
7523  Double_t v2PrimeErrorSquared = 0.;                    
7524  Double_t v4PrimeErrorSquared = 0.; 
7525  
7526  // loop over pt or eta bins:
7527  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7528  {
7529   // reduced correlations and statistical errors:
7530   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
7531   twoReducedError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b);
7532   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
7533   fourReducedError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b);
7534   // covariances:
7535   if(!fForgetAboutCovariances)
7536   {
7537    wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b);
7538    wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b);
7539    wCovFourTwoReduced = fDiffFlowCovariances[t][pe][2]->GetBinContent(b);
7540    wCovFourFourReduced = fDiffFlowCovariances[t][pe][3]->GetBinContent(b);
7541    wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b);
7542   }
7543   // differential flow:
7544   // v'{2}:
7545   if(two>0.) 
7546   {
7547    v2Prime = twoReduced/pow(two,0.5);
7548    v2PrimeErrorSquared = (1./4.)*pow(two,-3.)*
7549                          (pow(twoReduced,2.)*pow(twoError,2.)
7550                           + 4.*pow(two,2.)*pow(twoReducedError,2.)
7551                           - 4.*two*twoReduced*wCovTwoTwoReduced);
7552      
7553                                                             
7554    if(v2PrimeErrorSquared>0.) v2PrimeError = pow(v2PrimeErrorSquared,0.5);
7555    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
7556    if(TMath::Abs(v2Prime)>1.e-44)fDiffFlow[t][pe][0]->SetBinError(b,v2PrimeError);     
7557   }
7558   // differential flow:
7559   // v'{4}
7560   if(2.*pow(two,2.)-four > 0.) 
7561   {
7562    v4Prime = (2.*two*twoReduced-fourReduced)/pow(2.*pow(two,2.)-four,3./4.);
7563    v4PrimeErrorSquared = pow(2.*pow(two,2.)-four,-7./2.)*
7564                          (pow(2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced,2.)*pow(twoError,2.)
7565                           + (9./16.)*pow(2.*two*twoReduced-fourReduced,2.)*pow(fourError,2.)
7566                           + 4.*pow(two,2.)*pow(2.*pow(two,2.)-four,2.)*pow(twoReducedError,2.)
7567                           + pow(2.*pow(two,2.)-four,2.)*pow(fourReducedError,2.)                          
7568                           - (3./2.)*(2.*two*twoReduced-fourReduced)
7569                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFour
7570                           - 4.*two*(2.*pow(two,2.)-four)
7571                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoTwoReduced
7572                           + 2.*(2.*pow(two,2.)-four)
7573                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFourReduced
7574                           + 3.*two*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourTwoReduced
7575                           - (3./2.)*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourFourReduced 
7576                           - 4.*two*pow(2.*pow(two,2.)-four,2.)*wCovTwoReducedFourReduced);  
7577    if(v4PrimeErrorSquared>0.) v4PrimeError = pow(v4PrimeErrorSquared,0.5);        
7578    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);
7579    if(TMath::Abs(v4Prime)>1.e-44)fDiffFlow[t][pe][1]->SetBinError(b,v4PrimeError);     
7580   }
7581   
7582  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
7583  
7584    
7585  
7586  
7587  /*
7588  // 2D:
7589  for(Int_t nua=0;nua<2;nua++)
7590  {
7591   for(Int_t p=1;p<=fnBinsPt;p++)
7592   {
7593    for(Int_t e=1;e<=fnBinsEta;e++) 
7594    { 
7595     // differential cumulants:
7596     Double_t qc2Prime = fFinalCumulants2D[t][pW][eW][nua][0]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e)); // QC{2'}                    
7597     Double_t qc4Prime = fFinalCumulants2D[t][pW][eW][nua][1]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e)); // QC{4'}
7598     // differential flow:
7599     Double_t v2Prime = 0.;                    
7600     Double_t v4Prime = 0.; 
7601     if(v2) 
7602     {
7603      v2Prime = qc2Prime/v2;
7604      fFinalFlow2D[t][pW][eW][nua][0]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][0]->GetBin(p,e),v2Prime);  
7605     }                   
7606     if(v4)
7607     {
7608      v4Prime = -qc4Prime/pow(v4,3.); 
7609      fFinalFlow2D[t][pW][eW][nua][1]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][1]->GetBin(p,e),v4Prime);  
7610     }                    
7611    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
7612   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
7613  } // end of for(Int_t nua=0;nua<2;nua++)
7614  */
7615
7616 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights)
7617
7618 //================================================================================================================================
7619
7620 void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
7621 {
7622  // a) Store all flags for integrated flow in profile fIntFlowFlags.
7623  
7624  if(!fIntFlowFlags)
7625  {
7626   cout<<"WARNING: fIntFlowFlags is NULL in AFAWQC::SFFIF() !!!!"<<endl;
7627   exit(0);
7628  } 
7629
7630  // particle weights used or not:
7631  fIntFlowFlags->Fill(0.5,(Int_t)fUsePhiWeights||fUsePtWeights||fUseEtaWeights);
7632  // which event weights were used:
7633  if(strcmp(fMultiplicityWeight->Data(),"combinations"))
7634  {
7635   fIntFlowFlags->Fill(1.5,0); // 0 = "combinations" (default)
7636  } else if(strcmp(fMultiplicityWeight->Data(),"unit"))
7637    {
7638     fIntFlowFlags->Fill(1.5,1); // 1 = "unit"   
7639    } else if(strcmp(fMultiplicityWeight->Data(),"multiplicity"))
7640      {
7641       fIntFlowFlags->Fill(1.5,2); // 2 = "multiplicity"        
7642      } 
7643  fIntFlowFlags->Fill(2.5,(Int_t)fApplyCorrectionForNUA);
7644  fIntFlowFlags->Fill(3.5,(Int_t)fPrintFinalResults[0]);
7645  fIntFlowFlags->Fill(4.5,(Int_t)fPrintFinalResults[1]);
7646  fIntFlowFlags->Fill(5.5,(Int_t)fPrintFinalResults[2]);
7647  fIntFlowFlags->Fill(6.5,(Int_t)fPrintFinalResults[3]);
7648  fIntFlowFlags->Fill(7.5,(Int_t)fApplyCorrectionForNUAVsM);
7649  fIntFlowFlags->Fill(8.5,(Int_t)fPropagateErrorAlsoFromNIT);
7650  fIntFlowFlags->Fill(9.5,(Int_t)fCalculateCumulantsVsM);
7651  fIntFlowFlags->Fill(10.5,(Int_t)fMinimumBiasReferenceFlow);
7652  fIntFlowFlags->Fill(11.5,(Int_t)fForgetAboutCovariances);
7653  fIntFlowFlags->Fill(12.5,(Int_t)fStorePhiDistributionForOneEvent); 
7654  fIntFlowFlags->Fill(13.5,(Int_t)fFillMultipleControlHistograms);  
7655 } // end of void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
7656
7657 //================================================================================================================================
7658
7659 void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
7660 {
7661  // Store all flags for differential flow in the profile fDiffFlowFlags.
7662   
7663  if(!fDiffFlowFlags)
7664  {
7665   cout<<"WARNING: fDiffFlowFlags is NULL in AFAWQC::SFFDF() !!!!"<<endl;
7666   exit(0);
7667  } 
7668  
7669  fDiffFlowFlags->Fill(0.5,fUsePhiWeights||fUsePtWeights||fUseEtaWeights); // particle weights used or not
7670  //fDiffFlowFlags->Fill(1.5,""); // which event weight was used? // to be improved
7671  fDiffFlowFlags->Fill(2.5,fApplyCorrectionForNUA); // corrected for non-uniform acceptance or not
7672  fDiffFlowFlags->Fill(3.5,fCalculate2DFlow); // calculate also 2D differential flow in (pt,eta) or not
7673     
7674 } // end of void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
7675
7676 //================================================================================================================================
7677
7678 void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
7679 {
7680  // Access all pointers to common control and common result histograms and profiles.
7681  
7682  TString commonHistsName = "AliFlowCommonHistQC";
7683  commonHistsName += fAnalysisLabel->Data();
7684  AliFlowCommonHist *commonHist = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHistsName.Data()));
7685  if(commonHist) 
7686  {
7687   this->SetCommonHists(commonHist); 
7688   if(fCommonHists->GetHarmonic())
7689   {
7690    fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
7691   } 
7692  } // end of if(commonHist) 
7693  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
7694  commonHists2ndOrderName += fAnalysisLabel->Data();
7695  AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists2ndOrderName.Data()));
7696  if(commonHist2nd) this->SetCommonHists2nd(commonHist2nd);   
7697  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
7698  commonHists4thOrderName += fAnalysisLabel->Data();
7699  AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists4thOrderName.Data()));
7700  if(commonHist4th) this->SetCommonHists4th(commonHist4th);  
7701  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
7702  commonHists6thOrderName += fAnalysisLabel->Data();
7703  AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists6thOrderName.Data()));
7704  if(commonHist6th) this->SetCommonHists6th(commonHist6th);  
7705  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
7706  commonHists8thOrderName += fAnalysisLabel->Data();
7707  AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists8thOrderName.Data()));
7708  if(commonHist8th) this->SetCommonHists8th(commonHist8th); 
7709   
7710  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC"; 
7711  commonHistResults2ndOrderName += fAnalysisLabel->Data(); 
7712  AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>
7713                                               (fHistList->FindObject(commonHistResults2ndOrderName.Data()));
7714  if(commonHistRes2nd) this->SetCommonHistsResults2nd(commonHistRes2nd);   
7715  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
7716  commonHistResults4thOrderName += fAnalysisLabel->Data();
7717  AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>
7718                                               (fHistList->FindObject(commonHistResults4thOrderName.Data()));
7719  if(commonHistRes4th) this->SetCommonHistsResults4th(commonHistRes4th);  
7720  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
7721  commonHistResults6thOrderName += fAnalysisLabel->Data();
7722  AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>
7723                                               (fHistList->FindObject(commonHistResults6thOrderName.Data()));
7724  if(commonHistRes6th) this->SetCommonHistsResults6th(commonHistRes6th);  
7725  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
7726  commonHistResults8thOrderName += fAnalysisLabel->Data();
7727  AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>
7728                                               (fHistList->FindObject(commonHistResults8thOrderName.Data()));  
7729  if(commonHistRes8th) this->SetCommonHistsResults8th(commonHistRes8th);
7730        
7731 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
7732
7733
7734 //================================================================================================================================
7735
7736
7737 void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms() 
7738 {
7739  // Get pointers for histograms with particle weights.
7740
7741  TList *weightsList = dynamic_cast<TList*>(fHistList->FindObject("Weights"));
7742  if(weightsList) this->SetWeightsList(weightsList);
7743  TString fUseParticleWeightsName = "fUseParticleWeightsQC"; // to be improved (hirdwired label QC)
7744  fUseParticleWeightsName += fAnalysisLabel->Data();
7745  TProfile *useParticleWeights = dynamic_cast<TProfile*>(weightsList->FindObject(fUseParticleWeightsName.Data()));
7746  if(useParticleWeights)
7747  {
7748   this->SetUseParticleWeights(useParticleWeights);  
7749   fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
7750   fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
7751   fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3);  
7752  }
7753 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms(); 
7754
7755
7756 //================================================================================================================================
7757
7758
7759 void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms() 
7760 {
7761  // Get pointers for histograms and profiles relevant for integrated flow:
7762  //  a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults.
7763  //  b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow.
7764  //  c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds. 
7765  //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
7766   
7767  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data member?)
7768  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data member?)
7769  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?)
7770  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?)
7771  
7772  // a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults:
7773  TList *intFlowList = NULL;
7774  intFlowList = dynamic_cast<TList*>(fHistList->FindObject("Integrated Flow"));
7775  if(!intFlowList) 
7776  {
7777   cout<<"WARNING: intFlowList is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7778   exit(0); 
7779  }  
7780   
7781  // b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow:
7782  TString intFlowFlagsName = "fIntFlowFlags";
7783  intFlowFlagsName += fAnalysisLabel->Data();
7784  TProfile *intFlowFlags = dynamic_cast<TProfile*>(intFlowList->FindObject(intFlowFlagsName.Data()));
7785  if(intFlowFlags)
7786  {
7787   this->SetIntFlowFlags(intFlowFlags);  
7788   fApplyCorrectionForNUA = (Bool_t)intFlowFlags->GetBinContent(3); 
7789   fApplyCorrectionForNUAVsM = (Bool_t)intFlowFlags->GetBinContent(8); 
7790   fCalculateCumulantsVsM = (Bool_t)intFlowFlags->GetBinContent(10);  
7791  } else 
7792    {
7793     cout<<"WARNING: intFlowFlags is NULL in FAWQC::GPFIFH() !!!!"<<endl;
7794    }
7795   
7796   // c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds:
7797   TList *intFlowProfiles = NULL;
7798   intFlowProfiles = dynamic_cast<TList*>(intFlowList->FindObject("Profiles"));
7799   if(intFlowProfiles)  
7800   {
7801    // average multiplicities:
7802    TString avMultiplicityName = "fAvMultiplicity";
7803    avMultiplicityName += fAnalysisLabel->Data();
7804    TProfile *avMultiplicity = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(avMultiplicityName.Data()));
7805    if(avMultiplicity) 
7806    {
7807     this->SetAvMultiplicity(avMultiplicity);
7808    } else 
7809      {
7810       cout<<"WARNING: avMultiplicity is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7811      }
7812    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with wrong errors!):
7813    TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
7814    intFlowCorrelationsProName += fAnalysisLabel->Data();
7815    TProfile *intFlowCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsProName.Data()));
7816    if(intFlowCorrelationsPro) 
7817    {
7818     this->SetIntFlowCorrelationsPro(intFlowCorrelationsPro);
7819    } else 
7820      {
7821       cout<<"WARNING: intFlowCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7822      }      
7823    // average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8^2>>:
7824    TString intFlowSquaredCorrelationsProName = "fIntFlowSquaredCorrelationsPro";
7825    intFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
7826    TProfile *intFlowSquaredCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowSquaredCorrelationsProName.Data()));
7827    if(intFlowSquaredCorrelationsPro) 
7828    {
7829     this->SetIntFlowSquaredCorrelationsPro(intFlowSquaredCorrelationsPro);
7830    } else 
7831      {
7832       cout<<"WARNING: intFlowSquaredCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7833      }             
7834    if(fCalculateCumulantsVsM)
7835    {
7836     // Average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (error is wrong here):   
7837     TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
7838     intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
7839     for(Int_t ci=0;ci<4;ci++) // correlation index
7840     {
7841      TProfile *intFlowCorrelationsVsMPro = dynamic_cast<TProfile*>
7842                                         (intFlowProfiles->FindObject(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data())));
7843      if(intFlowCorrelationsVsMPro)
7844      {
7845       this->SetIntFlowCorrelationsVsMPro(intFlowCorrelationsVsMPro,ci);
7846      } else
7847        {
7848         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7849        }   
7850     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
7851     // Average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> versus multiplicity for all events:   
7852     TString intFlowSquaredCorrelationsVsMProName = "fIntFlowSquaredCorrelationsVsMPro";
7853     intFlowSquaredCorrelationsVsMProName += fAnalysisLabel->Data();
7854     for(Int_t ci=0;ci<4;ci++) // correlation index
7855     {
7856      TProfile *intFlowSquaredCorrelationsVsMPro = dynamic_cast<TProfile*>
7857                       (intFlowProfiles->FindObject(Form("%s, %s",intFlowSquaredCorrelationsVsMProName.Data(),squaredCorrelationFlag[ci].Data())));
7858      if(intFlowSquaredCorrelationsVsMPro)
7859      {
7860       this->SetIntFlowSquaredCorrelationsVsMPro(intFlowSquaredCorrelationsVsMPro,ci);
7861      } else
7862        {
7863         cout<<"WARNING: "<<Form("intFlowSquaredCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7864        }   
7865     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
7866    } // end of if(fCalculateCumulantsVsM)
7867    // average all correlations for integrated flow (with wrong errors!):
7868    TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
7869    intFlowCorrelationsAllProName += fAnalysisLabel->Data();
7870    TProfile *intFlowCorrelationsAllPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsAllProName.Data()));
7871    if(intFlowCorrelationsAllPro) 
7872    {
7873     this->SetIntFlowCorrelationsAllPro(intFlowCorrelationsAllPro);
7874    } else 
7875      {
7876       cout<<"WARNING: intFlowCorrelationsAllPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7877      }     
7878    // average extra correlations for integrated flow (which appear only when particle weights are used):
7879    // (to be improved: Weak point in implementation, I am assuming here that method GetPointersForParticleWeightsHistograms() was called)
7880    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
7881    {
7882     TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
7883     intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
7884     TProfile *intFlowExtraCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowExtraCorrelationsProName.Data()));
7885     if(intFlowExtraCorrelationsPro) 
7886     {
7887      this->SetIntFlowExtraCorrelationsPro(intFlowExtraCorrelationsPro);
7888     } else 
7889       {
7890        cout<<"WARNING: intFlowExtraCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7891       }
7892    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)        
7893    // average products of correlations <2>, <4>, <6> and <8>:  
7894    TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
7895    intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
7896    TProfile *intFlowProductOfCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrelationsProName.Data()));
7897    if(intFlowProductOfCorrelationsPro) 
7898    {
7899     this->SetIntFlowProductOfCorrelationsPro(intFlowProductOfCorrelationsPro);
7900    } else 
7901      {
7902       cout<<"WARNING: intFlowProductOfCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7903      }               
7904    // average product of correlations <2>, <4>, <6> and <8> versus multiplicity  
7905    // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
7906    if(fCalculateCumulantsVsM)
7907    {
7908     TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
7909     intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
7910     TString productFlag[6] = {"<<2><4>>","<<2><6>>","<<2><8>>","<<4><6>>","<<4><8>>","<<6><8>>"};
7911     for(Int_t pi=0;pi<6;pi++)
7912     { 
7913      TProfile *intFlowProductOfCorrelationsVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data())));
7914      if(intFlowProductOfCorrelationsVsMPro)
7915      {
7916       this->SetIntFlowProductOfCorrelationsVsMPro(intFlowProductOfCorrelationsVsMPro,pi);
7917      } else
7918        {
7919         cout<<"WARNING: "<<Form("intFlowProductOfCorrelationsVsMPro[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7920        }
7921     } // end of for(Int_t pi=0;pi<6;pi++)
7922    } // end of if(fCalculateCumulantsVsM)
7923    // average correction terms for non-uniform acceptance (with wrong errors!):
7924    for(Int_t sc=0;sc<2;sc++)
7925    {
7926     TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
7927     intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
7928     TProfile *intFlowCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()))));
7929     if(intFlowCorrectionTermsForNUAPro) 
7930     {
7931      this->SetIntFlowCorrectionTermsForNUAPro(intFlowCorrectionTermsForNUAPro,sc);
7932     } else 
7933       {
7934        cout<<"WARNING: intFlowCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7935        cout<<"sc = "<<sc<<endl;
7936       } 
7937     // versus multiplicity:
7938     if(fCalculateCumulantsVsM)
7939     {
7940      TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
7941      TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
7942      intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
7943      for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
7944      {
7945       TProfile *intFlowCorrectionTermsForNUAVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s: #LT#LT%s%s#GT#GT",intFlowCorrectionTermsForNUAVsMProName.Data(),sinCosFlag[sc].Data(),correctionTermFlag[ci].Data())));
7946       if(intFlowCorrectionTermsForNUAVsMPro) 
7947       {
7948        this->SetIntFlowCorrectionTermsForNUAVsMPro(intFlowCorrectionTermsForNUAVsMPro,sc,ci);
7949       } else 
7950         {
7951          cout<<"WARNING: intFlowCorrectionTermsForNUAVsMPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7952          cout<<"sc = "<<sc<<endl;
7953          cout<<"ci = "<<ci<<endl;
7954         }       
7955      } // end of for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
7956     } // end of if(fCalculateCumulantsVsM)
7957    } // end of for(Int_t sc=0;sc<2;sc++)           
7958    // average products of correction terms for NUA:  
7959    TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
7960    intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
7961    TProfile *intFlowProductOfCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrectionTermsForNUAProName.Data()));
7962    if(intFlowProductOfCorrectionTermsForNUAPro) 
7963    {
7964     this->SetIntFlowProductOfCorrectionTermsForNUAPro(intFlowProductOfCorrectionTermsForNUAPro);
7965    } else 
7966      {
7967       cout<<"WARNING: intFlowProductOfCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7968      }     
7969   } else // to if(intFlowProfiles)  
7970     {
7971      cout<<"WARNING: intFlowProfiles is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7972     }
7973    
7974   //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
7975   TList *intFlowResults = NULL;
7976   intFlowResults = dynamic_cast<TList*>(intFlowList->FindObject("Results"));
7977   if(intFlowResults)
7978   {
7979    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!):
7980    TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
7981    intFlowCorrelationsHistName += fAnalysisLabel->Data();
7982    TH1D *intFlowCorrelationsHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsHistName.Data()));
7983    if(intFlowCorrelationsHist) 
7984    {
7985     this->SetIntFlowCorrelationsHist(intFlowCorrelationsHist);
7986    } else 
7987      {
7988       cout<<"WARNING: intFlowCorrelationsHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7989      } 
7990    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!) vs M:    
7991    if(fCalculateCumulantsVsM)
7992    {
7993     TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
7994     intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
7995     for(Int_t ci=0;ci<4;ci++) // correlation index
7996     {
7997      TH1D *intFlowCorrelationsVsMHist = dynamic_cast<TH1D*>
7998                                         (intFlowResults->FindObject(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data())));
7999      if(intFlowCorrelationsVsMHist)
8000      {
8001       this->SetIntFlowCorrelationsVsMHist(intFlowCorrelationsVsMHist,ci);
8002      } else
8003        {
8004         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMHist[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8005        }   
8006     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8007    } // end of if(fCalculateCumulantsVsM)
8008    // average all correlations for integrated flow (with correct errors!):
8009    TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
8010    intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
8011    TH1D *intFlowCorrelationsAllHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsAllHistName.Data()));
8012    if(intFlowCorrelationsAllHist) 
8013    {
8014     this->SetIntFlowCorrelationsAllHist(intFlowCorrelationsAllHist);
8015    } else 
8016      {
8017       cout<<"WARNING: intFlowCorrelationsAllHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8018      }  
8019    // average correction terms for non-uniform acceptance (with correct errors!):
8020    TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
8021    intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
8022    for(Int_t sc=0;sc<2;sc++)
8023    {
8024     TH1D *intFlowCorrectionTermsForNUAHist = dynamic_cast<TH1D*>(intFlowResults->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()))));
8025     if(intFlowCorrectionTermsForNUAHist) 
8026     {
8027      this->SetIntFlowCorrectionTermsForNUAHist(intFlowCorrectionTermsForNUAHist,sc);
8028     } else 
8029       {
8030        cout<<"WARNING: intFlowCorrectionTermsForNUAHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8031        cout<<"sc = "<<sc<<endl;
8032       } 
8033    } // end of for(Int_t sc=0;sc<2;sc++)           
8034    // covariances (multiplied with weight dependent prefactor):
8035    TString intFlowCovariancesName = "fIntFlowCovariances";
8036    intFlowCovariancesName += fAnalysisLabel->Data();
8037    TH1D *intFlowCovariances = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesName.Data()));
8038    if(intFlowCovariances) 
8039    {
8040     this->SetIntFlowCovariances(intFlowCovariances); 
8041    } else 
8042      {
8043       cout<<"WARNING: intFlowCovariances is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8044      } 
8045    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
8046    TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
8047    intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
8048    for(Int_t power=0;power<2;power++)
8049    {
8050     TH1D *intFlowSumOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s",intFlowSumOfEventWeightsName.Data(),powerFlag[power].Data())));
8051     if(intFlowSumOfEventWeights) 
8052     {
8053      this->SetIntFlowSumOfEventWeights(intFlowSumOfEventWeights,power);
8054     } else 
8055       {
8056        cout<<"WARNING: intFlowSumOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8057        cout<<"power = "<<power<<endl;
8058       }                                   
8059    } // end of for(Int_t power=0;power<2;power++)                                                                  
8060    // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
8061    TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
8062    intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
8063    TH1D *intFlowSumOfProductOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsName.Data()));
8064    if(intFlowSumOfProductOfEventWeights) 
8065    {
8066     this->SetIntFlowSumOfProductOfEventWeights(intFlowSumOfProductOfEventWeights);
8067    } else 
8068      {
8069       cout<<"WARNING: intFlowSumOfProductOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8070      } 
8071    // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
8072    // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
8073    if(fCalculateCumulantsVsM)
8074    {
8075     TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
8076     intFlowCovariancesVsMName += fAnalysisLabel->Data();
8077     TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
8078     for(Int_t ci=0;ci<6;ci++)
8079     { 
8080      TH1D *intFlowCovariancesVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data())));
8081      if(intFlowCovariancesVsM)
8082      {
8083       this->SetIntFlowCovariancesVsM(intFlowCovariancesVsM,ci);
8084      } else
8085        {
8086         cout<<"WARNING: "<<Form("intFlowCovariancesVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8087        }    
8088     } // end of for(Int_t ci=0;ci<6;ci++)
8089    } // end of if(fCalculateCumulantsVsM)
8090    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
8091    // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
8092    if(fCalculateCumulantsVsM)
8093    {
8094     TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
8095     intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
8096     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>}"},
8097                              {"#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}"}};
8098     for(Int_t si=0;si<4;si++)
8099     {
8100      for(Int_t power=0;power<2;power++)
8101      {
8102       TH1D *intFlowSumOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data())));
8103       if(intFlowSumOfEventWeightsVsM)
8104       {
8105        this->SetIntFlowSumOfEventWeightsVsM(intFlowSumOfEventWeightsVsM,si,power);
8106       } else
8107         {
8108          cout<<"WARNING: "<<Form("intFlowSumOfEventWeightsVsM[%d][%d]",si,power)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8109         }    
8110      } // end of for(Int_t power=0;power<2;power++)
8111     } // end of for(Int_t si=0;si<4;si++)   
8112    } // end of if(fCalculateCumulantsVsM)
8113    // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
8114    // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
8115    //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
8116    if(fCalculateCumulantsVsM)
8117    {
8118     TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
8119     intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
8120     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>}",
8121                             "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
8122     for(Int_t pi=0;pi<6;pi++)
8123     {
8124      TH1D *intFlowSumOfProductOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data())));
8125      if(intFlowSumOfProductOfEventWeightsVsM)
8126      {
8127       this->SetIntFlowSumOfProductOfEventWeightsVsM(intFlowSumOfProductOfEventWeightsVsM,pi);
8128      } else
8129        {
8130         cout<<"WARNING: "<<Form("intFlowSumOfProductOfEventWeightsVsM[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8131        }
8132     } // end of for(Int_t pi=0;pi<6;pi++)        
8133    } // end of if(fCalculateCumulantsVsM)
8134    // covariances for NUA (multiplied with weight dependent prefactor):
8135    TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
8136    intFlowCovariancesNUAName += fAnalysisLabel->Data();
8137    TH1D *intFlowCovariancesNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesNUAName.Data()));
8138    if(intFlowCovariancesNUA) 
8139    {
8140     this->SetIntFlowCovariancesNUA(intFlowCovariancesNUA); 
8141    } else 
8142      {
8143       cout<<"WARNING: intFlowCovariancesNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8144      } 
8145    // sum of linear and quadratic event weights NUA terms:
8146    TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
8147    intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
8148    for(Int_t sc=0;sc<2;sc++)
8149    {
8150     for(Int_t power=0;power<2;power++)
8151     {
8152      TH1D *intFlowSumOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s, %s",intFlowSumOfEventWeightsNUAName.Data(),powerFlag[power].Data(),sinCosFlag[sc].Data())));
8153      if(intFlowSumOfEventWeightsNUA) 
8154      {
8155       this->SetIntFlowSumOfEventWeightsNUA(intFlowSumOfEventWeightsNUA,sc,power);
8156      } else 
8157        {
8158         cout<<"WARNING: intFlowSumOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8159         cout<<"sc    = "<<sc<<endl;
8160         cout<<"power = "<<power<<endl;
8161        }                                   
8162     } // end of for(Int_t power=0;power<2;power++)                                                                  
8163    } // end of for(Int_t sc=0;sc<2;sc++)     
8164    // sum of products of event weights for NUA terms:  
8165    TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
8166    intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
8167    TH1D *intFlowSumOfProductOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsNUAName.Data()));
8168    if(intFlowSumOfProductOfEventWeightsNUA) 
8169    {
8170     this->SetIntFlowSumOfProductOfEventWeightsNUA(intFlowSumOfProductOfEventWeightsNUA);
8171    } else 
8172      {
8173       cout<<"WARNING: intFlowSumOfProductOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8174      } 
8175    // Final results for reference Q-cumulants:
8176    TString intFlowQcumulantsName = "fIntFlowQcumulants";
8177    intFlowQcumulantsName += fAnalysisLabel->Data();
8178    TH1D *intFlowQcumulants = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsName.Data()));
8179    if(intFlowQcumulants) 
8180    {
8181     this->SetIntFlowQcumulants(intFlowQcumulants);
8182    } else 
8183      {
8184       cout<<"WARNING: intFlowQcumulants is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8185      }  
8186    // Final results for reference Q-cumulants rebinned in M:
8187    if(fCalculateCumulantsVsM)
8188    {
8189     TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
8190     intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
8191     TH1D *intFlowQcumulantsRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsRebinnedInMName.Data()));
8192     if(intFlowQcumulantsRebinnedInM) 
8193     {
8194      this->SetIntFlowQcumulantsRebinnedInM(intFlowQcumulantsRebinnedInM);
8195     } else 
8196       {
8197        cout<<"WARNING: intFlowQcumulantsRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8198       }  
8199    } // end of if(fCalculateCumulantsVsM)
8200    // Ratio between error squared: with/without non-isotropic terms:
8201    TString intFlowQcumulantsErrorSquaredRatioName = "fIntFlowQcumulantsErrorSquaredRatio";
8202    intFlowQcumulantsErrorSquaredRatioName += fAnalysisLabel->Data();
8203    TH1D *intFlowQcumulantsErrorSquaredRatio = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsErrorSquaredRatioName.Data()));
8204    if(intFlowQcumulantsErrorSquaredRatio) 
8205    {
8206     this->SetIntFlowQcumulantsErrorSquaredRatio(intFlowQcumulantsErrorSquaredRatio);
8207    } else 
8208      {
8209       cout<<" WARNING: intntFlowQcumulantsErrorSquaredRatio is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8210      }  
8211    // final results for integrated Q-cumulants versus multiplicity:
8212    TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
8213    if(fCalculateCumulantsVsM)
8214    {
8215     TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
8216     intFlowQcumulantsVsMName += fAnalysisLabel->Data();
8217     for(Int_t co=0;co<4;co++) // cumulant order
8218     {
8219      TH1D *intFlowQcumulantsVsM = dynamic_cast<TH1D*>
8220                                   (intFlowResults->FindObject(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data())));
8221      if(intFlowQcumulantsVsM)
8222      {
8223       this->SetIntFlowQcumulantsVsM(intFlowQcumulantsVsM,co);
8224      } else
8225        {
8226         cout<<"WARNING: "<<Form("intFlowQcumulantsVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8227        }
8228     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8229    } // end of if(fCalculateCumulantsVsM)
8230    // Final reference flow estimates from Q-cumulants:
8231    TString intFlowName = "fIntFlow";
8232    intFlowName += fAnalysisLabel->Data();
8233    TH1D *intFlow = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowName.Data()));
8234    if(intFlow) 
8235    {
8236     this->SetIntFlow(intFlow);
8237    } else 
8238      {
8239       cout<<"WARNING: intFlow is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8240      } 
8241    // Final reference flow estimates from Q-cumulants vs M rebinned in M:
8242    if(fCalculateCumulantsVsM)
8243    {
8244     TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
8245     intFlowRebinnedInMName += fAnalysisLabel->Data();
8246     TH1D *intFlowRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowRebinnedInMName.Data()));
8247     if(intFlowRebinnedInM) 
8248     {
8249      this->SetIntFlowRebinnedInM(intFlowRebinnedInM);
8250     } else 
8251       {
8252        cout<<"WARNING: intFlowRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8253       } 
8254    } // end of if(fCalculateCumulantsVsM)
8255    // integrated flow from Q-cumulants versus multiplicity:
8256    if(fCalculateCumulantsVsM)
8257    {
8258     TString intFlowVsMName = "fIntFlowVsM";
8259     intFlowVsMName += fAnalysisLabel->Data();
8260     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)};
8261     for(Int_t co=0;co<4;co++) // cumulant order
8262     {
8263      TH1D *intFlowVsM = dynamic_cast<TH1D*>
8264                         (intFlowResults->FindObject(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data())));            
8265      if(intFlowVsM)
8266      {
8267       this->SetIntFlowVsM(intFlowVsM,co);
8268      } else
8269        {
8270         cout<<"WARNING: "<<Form("intFlowVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8271        }
8272     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8273    } // end of if(fCalculateCumulantsVsM)
8274    // quantifying detector effects effects to correlations:
8275    TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
8276    intFlowDetectorBiasName += fAnalysisLabel->Data();
8277    TH1D *intFlowDetectorBias = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowDetectorBiasName.Data()));
8278    if(intFlowDetectorBias) 
8279    {
8280     this->SetIntFlowDetectorBias(intFlowDetectorBias);
8281    } else 
8282      {
8283       cout<<"WARNING: intFlowDetectorBias is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8284      } 
8285    // quantifying detector effects effects to correlations vs multiplicity:
8286    if(fCalculateCumulantsVsM)
8287    {
8288     TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
8289     intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
8290     for(Int_t ci=0;ci<4;ci++) // correlation index
8291     {
8292      TH1D *intFlowDetectorBiasVsM = dynamic_cast<TH1D*>
8293                                     (intFlowResults->FindObject(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data())));
8294      if(intFlowDetectorBiasVsM)
8295      {
8296       this->SetIntFlowDetectorBiasVsM(intFlowDetectorBiasVsM,ci);
8297      } else
8298        {
8299         cout<<"WARNING: "<<Form("intFlowDetectorBiasVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8300        }
8301     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8302    } // end of if(fCalculateCumulantsVsM)
8303   } else // to if(intFlowResults)
8304     {
8305      cout<<"WARNING: intFlowResults is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8306     }
8307     
8308 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms()
8309
8310 //================================================================================================================================
8311
8312 void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
8313 {
8314  // Get pointer to all objects relevant for differential flow.
8315  //  a) Define flags locally (to be improved: should I promote flags to data members?);
8316  //  b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults;
8317  //  c) Get pointer to profile fDiffFlowFlags holding all flags for differential flow;
8318  //  d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
8319  //  e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
8320  
8321  // a) Define flags locally (to be improved: should I promote flags to data members?): 
8322  TString typeFlag[2] = {"RP","POI"}; 
8323  TString ptEtaFlag[2] = {"p_{T}","#eta"};
8324  TString powerFlag[2] = {"linear","quadratic"};
8325  TString sinCosFlag[2] = {"sin","cos"};
8326  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
8327  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
8328  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
8329  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"}; 
8330  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
8331  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
8332   
8333  // b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults:
8334  TList *diffFlowList = NULL;
8335  diffFlowList = dynamic_cast<TList*>(fHistList->FindObject("Differential Flow"));  
8336  if(!diffFlowList)
8337  { 
8338   cout<<"WARNING: diffFlowList is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8339   exit(0);
8340  }
8341  // list holding nested lists containing profiles:
8342  TList *diffFlowListProfiles = NULL;
8343  diffFlowListProfiles = dynamic_cast<TList*>(diffFlowList->FindObject("Profiles"));
8344  if(!diffFlowListProfiles)
8345  { 
8346   cout<<"WARNING: diffFlowListProfiles is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8347   exit(0);
8348  }
8349  // list holding nested lists containing 2D and 1D histograms with final results:
8350  TList *diffFlowListResults = NULL;
8351  diffFlowListResults = dynamic_cast<TList*>(diffFlowList->FindObject("Results"));
8352  if(!diffFlowListResults)
8353  { 
8354   cout<<"WARNING: diffFlowListResults is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8355   exit(0);
8356  }
8357  
8358  // c) Get pointer to profile holding all flags for differential flow;
8359  TString diffFlowFlagsName = "fDiffFlowFlags";
8360  diffFlowFlagsName += fAnalysisLabel->Data();
8361  TProfile *diffFlowFlags = dynamic_cast<TProfile*>(diffFlowList->FindObject(diffFlowFlagsName.Data()));
8362  Bool_t bCalculate2DFlow = kFALSE;
8363  if(diffFlowFlags)
8364  {
8365   this->SetDiffFlowFlags(diffFlowFlags);  
8366   bCalculate2DFlow = (Int_t)diffFlowFlags->GetBinContent(4);
8367   this->SetCalculate2DFlow(bCalculate2DFlow); // to be improved (shoul I call this setter somewhere else?)     
8368  }
8369   
8370  // d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
8371  // correlations:
8372  TList *diffFlowCorrelationsProList[2][2] = {{NULL}};
8373  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
8374  diffFlowCorrelationsProName += fAnalysisLabel->Data();
8375  TProfile *diffFlowCorrelationsPro[2][2][4] = {{{NULL}}}; 
8376  // squared correlations:  
8377  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
8378  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data(); 
8379  TProfile *diffFlowSquaredCorrelationsPro[2][2][4] = {{{NULL}}};  
8380  // products of correlations:
8381  TList *diffFlowProductOfCorrelationsProList[2][2] = {{NULL}};
8382  TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
8383  diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
8384  TProfile *diffFlowProductOfCorrelationsPro[2][2][8][8] = {{{{NULL}}}};   
8385  // corrections:
8386  TList *diffFlowCorrectionsProList[2][2] = {{NULL}};
8387  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
8388  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();  
8389  TProfile *diffFlowCorrectionTermsForNUAPro[2][2][2][10] = {{{{NULL}}}};   
8390  for(Int_t t=0;t<2;t++)
8391  {
8392   for(Int_t pe=0;pe<2;pe++)
8393   {
8394    diffFlowCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8395    if(!diffFlowCorrelationsProList[t][pe])
8396    { 
8397     cout<<"WARNING: diffFlowCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8398     cout<<"t = "<<t<<endl;
8399     cout<<"pe = "<<pe<<endl;
8400     exit(0);
8401    }
8402    for(Int_t ci=0;ci<4;ci++) // correlation index
8403    {
8404     // reduced correlations:
8405     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())));
8406     if(diffFlowCorrelationsPro[t][pe][ci])
8407     {
8408      this->SetDiffFlowCorrelationsPro(diffFlowCorrelationsPro[t][pe][ci],t,pe,ci);
8409     } else
8410       {
8411        cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8412        cout<<"t  = "<<t<<endl;
8413        cout<<"pe = "<<pe<<endl;   
8414        cout<<"ci = "<<ci<<endl;
8415       }     
8416     // reduced squared correlations:
8417     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())));
8418     if(diffFlowSquaredCorrelationsPro[t][pe][ci])
8419     {
8420      this->SetDiffFlowSquaredCorrelationsPro(diffFlowSquaredCorrelationsPro[t][pe][ci],t,pe,ci);
8421     } else
8422       {
8423        cout<<"WARNING: diffFlowSquaredCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8424        cout<<"t  = "<<t<<endl;
8425        cout<<"pe = "<<pe<<endl;   
8426        cout<<"ci = "<<ci<<endl;
8427       }       
8428    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
8429    // products of correlations:    
8430    diffFlowProductOfCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()))); 
8431    if(!diffFlowProductOfCorrelationsProList[t][pe])
8432    { 
8433     cout<<"WARNING: ddiffFlowProductOfCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8434     cout<<"t = "<<t<<endl;
8435     cout<<"pe = "<<pe<<endl;
8436     exit(0);
8437    }
8438    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8439    {
8440     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8441     {
8442      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())));
8443      if(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2])
8444      {
8445       this->SetDiffFlowProductOfCorrelationsPro(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2],t,pe,mci1,mci2);
8446      } else
8447        {
8448         cout<<"WARNING: diffFlowProductOfCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8449         cout<<"t    = "<<t<<endl;
8450         cout<<"pe   = "<<pe<<endl;   
8451         cout<<"mci1 = "<<mci1<<endl;
8452         cout<<"mci2 = "<<mci2<<endl;
8453        }
8454      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8455     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8456    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
8457    // corrections:
8458    diffFlowCorrectionsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8459    if(!diffFlowCorrectionsProList[t][pe])
8460    { 
8461     cout<<"WARNING: diffFlowCorrectionsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8462     cout<<"t = "<<t<<endl;
8463     cout<<"pe = "<<pe<<endl;
8464     exit(0);
8465    }
8466    // correction terms for NUA:
8467    for(Int_t sc=0;sc<2;sc++) // sin or cos
8468    {
8469     for(Int_t cti=0;cti<9;cti++) // correction term index
8470     {
8471      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)));
8472      if(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti])
8473      {
8474       this->SetDiffFlowCorrectionTermsForNUAPro(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti],t,pe,sc,cti);
8475      } else
8476        {
8477         cout<<"WARNING: diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8478         cout<<"t   = "<<t<<endl;
8479         cout<<"pe  = "<<pe<<endl;   
8480         cout<<"sc  = "<<sc<<endl;
8481         cout<<"cti = "<<cti<<endl;
8482        }    
8483     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
8484    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
8485    // ...
8486   } // end of for(Int_t pe=0;pe<2;pe++)
8487  } // end of for(Int_t t=0;t<2;t++)
8488   
8489  // e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
8490  // reduced correlations:
8491  TList *diffFlowCorrelationsHistList[2][2] = {{NULL}};
8492  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
8493  diffFlowCorrelationsHistName += fAnalysisLabel->Data();  
8494  TH1D *diffFlowCorrelationsHist[2][2][4] = {{{NULL}}};
8495  // corrections for NUA:
8496  TList *diffFlowCorrectionsHistList[2][2] = {{NULL}};
8497  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
8498  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();  
8499  TH1D *diffFlowCorrectionTermsForNUAHist[2][2][2][10] = {{{{NULL}}}};
8500  // differential Q-cumulants:
8501  TList *diffFlowCumulantsHistList[2][2] = {{NULL}};
8502  TString diffFlowCumulantsName = "fDiffFlowCumulants";
8503  diffFlowCumulantsName += fAnalysisLabel->Data();  
8504  TH1D *diffFlowCumulants[2][2][4] = {{{NULL}}};
8505  // differential flow estimates from Q-cumulants:
8506  TList *diffFlowHistList[2][2] = {{NULL}};
8507  TString diffFlowName = "fDiffFlow";
8508  diffFlowName += fAnalysisLabel->Data();  
8509  TH1D *diffFlow[2][2][4] = {{{NULL}}};
8510  // differential covariances:
8511  TList *diffFlowCovariancesHistList[2][2] = {{NULL}};
8512  TString diffFlowCovariancesName = "fDiffFlowCovariances";
8513  diffFlowCovariancesName += fAnalysisLabel->Data();  
8514  TH1D *diffFlowCovariances[2][2][5] = {{{NULL}}};
8515  for(Int_t t=0;t<2;t++) // type: RP or POI
8516  { 
8517   for(Int_t pe=0;pe<2;pe++) // pt or eta
8518   {
8519    // reduced correlations:
8520    diffFlowCorrelationsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8521    if(!diffFlowCorrelationsHistList[t][pe])
8522    { 
8523     cout<<"WARNING: diffFlowCorrelationsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8524     cout<<"t = "<<t<<endl;
8525     cout<<"pe = "<<pe<<endl;
8526     exit(0);
8527    }
8528    for(Int_t index=0;index<4;index++) 
8529    {
8530     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())));
8531     if(diffFlowCorrelationsHist[t][pe][index])
8532     {
8533      this->SetDiffFlowCorrelationsHist(diffFlowCorrelationsHist[t][pe][index],t,pe,index);
8534     } else 
8535       {
8536        cout<<"WARNING: diffFlowCorrelationsHist[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8537        cout<<"t     = "<<t<<endl;
8538        cout<<"pe    = "<<pe<<endl;
8539        cout<<"index = "<<index<<endl;
8540        exit(0);       
8541       } 
8542    } // end of for(Int_t index=0;index<4;index++)
8543    // corrections:
8544    diffFlowCorrectionsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8545    if(!diffFlowCorrectionsHistList[t][pe])
8546    { 
8547     cout<<"WARNING: diffFlowCorrectionsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8548     cout<<"t = "<<t<<endl;
8549     cout<<"pe = "<<pe<<endl;
8550     exit(0);
8551    }
8552    // correction terms for NUA:
8553    for(Int_t sc=0;sc<2;sc++) // sin or cos
8554    {
8555     for(Int_t cti=0;cti<9;cti++) // correction term index
8556     {
8557      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)));
8558      if(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti])
8559      {
8560       this->SetDiffFlowCorrectionTermsForNUAHist(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti],t,pe,sc,cti);
8561      } else
8562        {
8563         cout<<"WARNING: diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8564         cout<<"t   = "<<t<<endl;
8565         cout<<"pe  = "<<pe<<endl;   
8566         cout<<"sc  = "<<sc<<endl;
8567         cout<<"cti = "<<cti<<endl;
8568        }    
8569     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
8570    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
8571    // ...
8572    // differential Q-cumulants:
8573    diffFlowCumulantsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8574    if(!diffFlowCumulantsHistList[t][pe])
8575    { 
8576     cout<<"WARNING: diffFlowCumulantsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8577     cout<<"t  = "<<t<<endl;
8578     cout<<"pe = "<<pe<<endl;
8579     exit(0);
8580    }
8581    for(Int_t index=0;index<4;index++) 
8582    {
8583     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())));
8584     if(diffFlowCumulants[t][pe][index])
8585     {
8586      this->SetDiffFlowCumulants(diffFlowCumulants[t][pe][index],t,pe,index);
8587     } else 
8588       {
8589        cout<<"WARNING: diffFlowCumulants[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8590        cout<<"t     = "<<t<<endl;
8591        cout<<"pe    = "<<pe<<endl;
8592        cout<<"index = "<<index<<endl;
8593        exit(0);       
8594       } 
8595    } // end of for(Int_t index=0;index<4;index++)
8596    // differential flow estimates from Q-cumulants:
8597    diffFlowHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8598    if(!diffFlowHistList[t][pe])
8599    { 
8600     cout<<"WARNING: diffFlowHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8601     cout<<"t  = "<<t<<endl;
8602     cout<<"pe = "<<pe<<endl;
8603     exit(0);
8604    }
8605    for(Int_t index=0;index<4;index++) 
8606    {
8607     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())));
8608     if(diffFlow[t][pe][index])
8609     {
8610      this->SetDiffFlow(diffFlow[t][pe][index],t,pe,index);
8611     } else 
8612       {
8613        cout<<"WARNING: diffFlow[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8614        cout<<"t     = "<<t<<endl;
8615        cout<<"pe    = "<<pe<<endl;
8616        cout<<"index = "<<index<<endl;
8617        exit(0);       
8618       } 
8619    } // end of for(Int_t index=0;index<4;index++)
8620    // differential covariances:
8621    diffFlowCovariancesHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8622    if(!diffFlowCovariancesHistList[t][pe])
8623    { 
8624     cout<<"WARNING: diffFlowCovariancesHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8625     cout<<"t  = "<<t<<endl;
8626     cout<<"pe = "<<pe<<endl;
8627     exit(0);
8628    }
8629    for(Int_t covIndex=0;covIndex<5;covIndex++) 
8630    {
8631     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())));
8632     if(diffFlowCovariances[t][pe][covIndex])
8633     {
8634      this->SetDiffFlowCovariances(diffFlowCovariances[t][pe][covIndex],t,pe,covIndex);
8635     } else 
8636       {
8637        cout<<"WARNING: diffFlowCovariances[t][pe][covIndex] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8638        cout<<"t        = "<<t<<endl;
8639        cout<<"pe       = "<<pe<<endl;
8640        cout<<"covIndex = "<<covIndex<<endl;
8641        exit(0);       
8642       } 
8643    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index    
8644   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8645  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
8646  // sum of event weights for reduced correlations:
8647  TList *diffFlowSumOfEventWeightsHistList[2][2][2] = {{{NULL}}};
8648  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
8649  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
8650  TH1D *diffFlowSumOfEventWeights[2][2][2][4] = {{{{NULL}}}};
8651  for(Int_t t=0;t<2;t++) // type is RP or POI
8652  { 
8653   for(Int_t pe=0;pe<2;pe++) // pt or eta
8654   { 
8655    for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
8656    {
8657     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())));
8658     if(!diffFlowSumOfEventWeightsHistList[t][pe][p])
8659     { 
8660      cout<<"WARNING: diffFlowSumOfEventWeightsHistList[t][pe][p] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8661      cout<<"t     = "<<t<<endl;
8662      cout<<"pe    = "<<pe<<endl;
8663      cout<<"power = "<<p<<endl;
8664      exit(0);
8665     }
8666     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
8667     {
8668      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())));    
8669      if(diffFlowSumOfEventWeights[t][pe][p][ew])
8670      {
8671       this->SetDiffFlowSumOfEventWeights(diffFlowSumOfEventWeights[t][pe][p][ew],t,pe,p,ew);
8672      } else 
8673        {
8674         cout<<"WARNING: diffFlowSumOfEventWeights[t][pe][p][ew] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8675         cout<<"t     = "<<t<<endl;
8676         cout<<"pe    = "<<pe<<endl;
8677         cout<<"power = "<<p<<endl;
8678         cout<<"ew    = "<<ew<<endl;
8679         exit(0);       
8680        } 
8681     }
8682    } // end of for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
8683   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8684  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
8685  //  
8686  TList *diffFlowSumOfProductOfEventWeightsHistList[2][2] = {{NULL}};
8687  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
8688  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
8689  TH1D *diffFlowSumOfProductOfEventWeights[2][2][8][8] = {{{{NULL}}}};
8690  for(Int_t t=0;t<2;t++) // type is RP or POI
8691  { 
8692   for(Int_t pe=0;pe<2;pe++) // pt or eta
8693   { 
8694    diffFlowSumOfProductOfEventWeightsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8695    if(!diffFlowSumOfProductOfEventWeightsHistList[t][pe])
8696    { 
8697     cout<<"WARNING: diffFlowSumOfProductOfEventWeightsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8698     cout<<"t     = "<<t<<endl;
8699     cout<<"pe    = "<<pe<<endl;
8700     exit(0);
8701    }
8702    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8703    {
8704     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8705     {
8706      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())));    
8707       if(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2])
8708       {
8709        this->SetDiffFlowSumOfProductOfEventWeights(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2],t,pe,mci1,mci2);
8710       } else 
8711         {
8712          cout<<"WARNING: diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8713          cout<<"t    = "<<t<<endl;
8714          cout<<"pe   = "<<pe<<endl;
8715          cout<<"mci1 = "<<mci1<<endl;
8716          cout<<"mci2 = "<<mci2<<endl;
8717          exit(0);       
8718         } 
8719      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8720     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8721    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8722   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8723  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
8724
8725 } // end void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
8726
8727
8728 //================================================================================================================================
8729
8730
8731 void AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
8732 {
8733  // Book all histograms and profiles needed for differential flow.
8734  //  a) Define flags locally (to be improved: should I promote flags to data members?);
8735  //  b) Book profile to hold all flags for differential flow;
8736  //  c) Book e-b-e quantities;
8737  //  d) Book profiles;
8738  //  e) Book histograms holding final results. 
8739  
8740  // a) Define flags locally (to be improved: should I promote flags to data members?): 
8741  TString typeFlag[2] = {"RP","POI"}; 
8742  TString ptEtaFlag[2] = {"p_{T}","#eta"};
8743  TString powerFlag[2] = {"linear","quadratic"};
8744  TString sinCosFlag[2] = {"sin","cos"};
8745  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
8746  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
8747  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
8748  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"};
8749  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
8750  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
8751  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8752  Double_t minPtEta[2] = {fPtMin,fEtaMin};
8753  Double_t maxPtEta[2] = {fPtMax,fEtaMax};
8754   
8755  // b) Book profile to hold all flags for differential flow:
8756  TString diffFlowFlagsName = "fDiffFlowFlags";
8757  diffFlowFlagsName += fAnalysisLabel->Data();
8758  fDiffFlowFlags = new TProfile(diffFlowFlagsName.Data(),"Flags for Differential Flow",4,0,4);
8759  fDiffFlowFlags->SetTickLength(-0.01,"Y");
8760  fDiffFlowFlags->SetMarkerStyle(25);
8761  fDiffFlowFlags->SetLabelSize(0.05);
8762  fDiffFlowFlags->SetLabelOffset(0.02,"Y");
8763  (fDiffFlowFlags->GetXaxis())->SetBinLabel(1,"Particle Weights");
8764  (fDiffFlowFlags->GetXaxis())->SetBinLabel(2,"Event Weights");
8765  (fDiffFlowFlags->GetXaxis())->SetBinLabel(3,"Corrected for NUA?");
8766  (fDiffFlowFlags->GetXaxis())->SetBinLabel(4,"Calculated 2D flow?");
8767  fDiffFlowList->Add(fDiffFlowFlags);
8768
8769  // c) Book e-b-e quantities:
8770  // Event-by-event r_{m*n,k}(pt,eta), p_{m*n,k}(pt,eta) and q_{m*n,k}(pt,eta)
8771  // Explanantion of notation:
8772  //  1.) n is harmonic, m is multiple of harmonic;
8773  //  2.) k is power of particle weight;
8774  //  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);   
8775  //  4.) p_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for POIs in particular (pt,eta) bin 
8776  //                          (if i-th POI is also RP, than it is weighted with w_i^k);   
8777  //  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 
8778  //                          (i-th RP&&POI is weighted with w_i^k)            
8779   
8780  // 1D:
8781  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP && POI )
8782  { 
8783   for(Int_t pe=0;pe<2;pe++) // pt or eta
8784   {
8785    for(Int_t m=0;m<4;m++) // multiple of harmonic
8786    {
8787     for(Int_t k=0;k<9;k++) // power of particle weight
8788     {
8789      fReRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),
8790                                              Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8791      fImRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),
8792                                              Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8793     }
8794    }
8795   }
8796  } 
8797  // to be improved (add explanation of fs1dEBE[t][pe][k]):   
8798  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8799  { 
8800   for(Int_t pe=0;pe<2;pe++) // pt or eta
8801   {
8802    for(Int_t k=0;k<9;k++) // power of particle weight
8803    {
8804     fs1dEBE[t][pe][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),
8805                                      Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8806    }
8807   }
8808  }
8809  // correction terms for nua:
8810  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
8811  { 
8812   for(Int_t pe=0;pe<2;pe++) // pt or eta
8813   {
8814    for(Int_t sc=0;sc<2;sc++) // sin or cos
8815    {
8816     for(Int_t cti=0;cti<9;cti++) // correction term index
8817     {
8818      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = new TH1D(Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),
8819                                              Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8820     }
8821    }
8822   }
8823  } 
8824  // 2D:
8825  if(fCalculate2DFlow)
8826  {
8827   TProfile2D styleRe("typeMultiplePowerRe","typeMultiplePowerRe",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8828   TProfile2D styleIm("typeMultiplePowerIm","typeMultiplePowerIm",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8829   for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8830   { 
8831    for(Int_t m=0;m<4;m++)
8832    {
8833     for(Int_t k=0;k<9;k++)
8834     {
8835      fReRPQ2dEBE[t][m][k] = (TProfile2D*)styleRe.Clone(Form("typeFlag%dmultiple%dpower%dRe",t,m,k)); 
8836      fImRPQ2dEBE[t][m][k] = (TProfile2D*)styleIm.Clone(Form("typeFlag%dmultiple%dpower%dIm",t,m,k));
8837     }
8838    } 
8839   } 
8840   TProfile2D styleS("typePower","typePower",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8841   for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8842   { 
8843    for(Int_t k=0;k<9;k++)
8844    {
8845     fs2dEBE[t][k] = (TProfile2D*)styleS.Clone(Form("typeFlag%dpower%d",t,k));
8846    }
8847   }
8848  } // end of if(fCalculate2DFlow)
8849  // reduced correlations e-b-e:
8850  TString diffFlowCorrelationsEBEName = "fDiffFlowCorrelationsEBE";
8851  diffFlowCorrelationsEBEName += fAnalysisLabel->Data();
8852  for(Int_t t=0;t<2;t++) // type: RP or POI
8853  { 
8854   for(Int_t pe=0;pe<2;pe++) // pt or eta
8855   {
8856    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8857    {
8858     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]);
8859    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
8860   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8861  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8862  // event weights for reduced correlations e-b-e:
8863  TString diffFlowEventWeightsForCorrelationsEBEName = "fDiffFlowEventWeightsForCorrelationsEBE";
8864  diffFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
8865  for(Int_t t=0;t<2;t++) // type: RP or POI
8866  { 
8867   for(Int_t pe=0;pe<2;pe++) // pt or eta
8868   {
8869    for(Int_t rci=0;rci<4;rci++) // event weight for reduced correlation index
8870    {
8871     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]);
8872    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
8873   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8874  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8875       
8876  // d) Book profiles;
8877  // reduced correlations:
8878  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
8879  diffFlowCorrelationsProName += fAnalysisLabel->Data();
8880  // reduced squared correlations:
8881  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
8882  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
8883  // corrections terms:
8884  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
8885  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
8886  // reduced correlations:
8887  for(Int_t t=0;t<2;t++) // type: RP or POI
8888  { 
8889   for(Int_t pe=0;pe<2;pe++) // pt or eta
8890   {
8891    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8892    {
8893     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");
8894     fDiffFlowCorrelationsPro[t][pe][rci]->Sumw2();
8895     fDiffFlowCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
8896     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
8897    } // end of for(Int_t rci=0;rci<4;rci++) // 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  // reduced squared correlations:
8901  for(Int_t t=0;t<2;t++) // type: RP or POI
8902  { 
8903   for(Int_t pe=0;pe<2;pe++) // pt or eta
8904   {
8905    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8906    {
8907     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");
8908     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->Sumw2();
8909     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
8910     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowSquaredCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
8911    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
8912   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8913  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8914  // correction terms for nua:
8915  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
8916  { 
8917   for(Int_t pe=0;pe<2;pe++) // pt or eta
8918   {
8919    for(Int_t sc=0;sc<2;sc++) // sin or cos
8920    {
8921     for(Int_t cti=0;cti<9;cti++) // correction term index
8922     {
8923      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]); 
8924      fDiffFlowCorrectionsProList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]);
8925     }
8926    }
8927   }
8928  } 
8929  // e) Book histograms holding final results. 
8930  // reduced correlations:
8931  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
8932  diffFlowCorrelationsHistName += fAnalysisLabel->Data();
8933  // corrections terms:
8934  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
8935  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
8936  // differential covariances:
8937  TString diffFlowCovariancesName = "fDiffFlowCovariances";
8938  diffFlowCovariancesName += fAnalysisLabel->Data();
8939  // differential Q-cumulants:
8940  TString diffFlowCumulantsName = "fDiffFlowCumulants";
8941  diffFlowCumulantsName += fAnalysisLabel->Data();
8942  // differential flow:
8943  TString diffFlowName = "fDiffFlow";
8944  diffFlowName += fAnalysisLabel->Data();
8945  for(Int_t t=0;t<2;t++) // type: RP or POI
8946  { 
8947   for(Int_t pe=0;pe<2;pe++) // pt or eta
8948   {
8949    for(Int_t index=0;index<4;index++) 
8950    {
8951     // reduced correlations:
8952     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]);
8953     fDiffFlowCorrelationsHist[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8954     fDiffFlowCorrelationsHistList[t][pe]->Add(fDiffFlowCorrelationsHist[t][pe][index]); 
8955     // differential Q-cumulants:
8956     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]);
8957     fDiffFlowCumulants[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8958     fDiffFlowCumulantsHistList[t][pe]->Add(fDiffFlowCumulants[t][pe][index]); 
8959     // differential flow estimates from Q-cumulants:
8960     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]);
8961     fDiffFlow[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8962     fDiffFlowHistList[t][pe]->Add(fDiffFlow[t][pe][index]); 
8963    } // end of for(Int_t index=0;index<4;index++) 
8964    for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index 
8965    {
8966     // differential covariances:
8967     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]);
8968     fDiffFlowCovariances[t][pe][covIndex]->SetXTitle(ptEtaFlag[pe].Data());
8969     fDiffFlowCovariancesHistList[t][pe]->Add(fDiffFlowCovariances[t][pe][covIndex]); 
8970    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index
8971    // products of both types of correlations: 
8972    TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
8973    diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
8974    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8975    {
8976     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8977     {
8978      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]); 
8979      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
8980      fDiffFlowProductOfCorrelationsProList[t][pe]->Add(fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]); 
8981      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8982     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8983    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
8984   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8985  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8986  // sums of event weights for reduced correlations: 
8987  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
8988  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
8989  for(Int_t t=0;t<2;t++) // type is RP or POI
8990  { 
8991   for(Int_t pe=0;pe<2;pe++) // pt or eta
8992   { 
8993    for(Int_t p=0;p<2;p++) // power of weights is either 1 or 2
8994    {
8995     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
8996     {
8997      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]); 
8998      fDiffFlowSumOfEventWeights[t][pe][p][ew]->SetXTitle(ptEtaFlag[pe].Data());
8999      fDiffFlowSumOfEventWeightsHistList[t][pe][p]->Add(fDiffFlowSumOfEventWeights[t][pe][p][ew]); // to be improved (add dedicated list to hold all this)
9000     }
9001    }
9002   }
9003  } 
9004  // sum of products of event weights for both types of correlations: 
9005  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
9006  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
9007  for(Int_t t=0;t<2;t++) // type is RP or POI
9008  {
9009   for(Int_t pe=0;pe<2;pe++) // pt or eta
9010   { 
9011    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9012    {
9013     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9014     {
9015      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]); 
9016      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
9017      fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->Add(fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]); 
9018      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9019     }
9020    }
9021   }
9022  } 
9023  // correction terms for nua:
9024  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9025  { 
9026   for(Int_t pe=0;pe<2;pe++) // pt or eta
9027   {
9028    for(Int_t sc=0;sc<2;sc++) // sin or cos
9029    {
9030     for(Int_t cti=0;cti<9;cti++) // correction term index
9031     {
9032      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]); 
9033      fDiffFlowCorrectionsHistList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]);
9034     }
9035    }
9036   }
9037  } 
9038           
9039 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
9040
9041 //================================================================================================================================
9042
9043 void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
9044 {
9045  // Calculate generalized Q-cumulants (cumulants corrected for non-unifom acceptance).
9046  
9047  // Isotropic cumulants:
9048  Double_t QC2 = fIntFlowQcumulants->GetBinContent(1);
9049  Double_t QC2Error = fIntFlowQcumulants->GetBinError(1);
9050  Double_t QC4 = fIntFlowQcumulants->GetBinContent(2);
9051  Double_t QC4Error = fIntFlowQcumulants->GetBinError(2);
9052  //Double_t QC6 = fIntFlowQcumulants->GetBinContent(3);
9053  //Double_t QC6Error = fIntFlowQcumulants->GetBinError(3);
9054  //Double_t QC8 = fIntFlowQcumulants->GetBinContent(4);
9055  //Double_t QC8Error = fIntFlowQcumulants->GetBinError(4);
9056  
9057  // Measured 2-, 4-, 6- and 8-particle correlations:
9058  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
9059  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <<2>>
9060  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
9061  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <<4>>
9062  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
9063  //Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <<6>>
9064  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
9065  //Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <<8>>
9066   
9067  // Non-isotropic terms:
9068  Double_t c1 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
9069  Double_t c1Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(1); // statistical error of <<cos(n*phi1)>>
9070  Double_t c2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
9071  Double_t c2Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(2); // statistical error of <<cos(n*(phi1+phi2))>>
9072  Double_t c3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
9073  Double_t c3Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(3); // statistical error of <<cos(n*(phi1-phi2-phi3))>>
9074  Double_t s1 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
9075  Double_t s1Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(1); // statistical error of <<sin(n*phi1)>>
9076  Double_t s2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
9077  Double_t s2Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(2); // statistical error of <<sin(n*(phi1+phi2))>>
9078  Double_t s3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
9079  Double_t s3Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(3); // statistical error of <<sin(n*(phi1-phi2-phi3))>>
9080  
9081  // Shortcuts:
9082  Double_t a1 = 2.*pow(c1,2.)+2.*pow(s1,2.)-two;
9083  Double_t a2 = 6.*pow(c1,3.)-2.*c1*c2+c3+6.*c1*pow(s1,2.)-2.*s1*s2-4.*c1*two;
9084  Double_t a3 = 2.*pow(s1,2.)-2.*pow(c1,2.)+c2;
9085  Double_t a4 = 6.*pow(s1,3.)+6.*pow(c1,2.)*s1+2.*c2*s1-2.*c1*s2-s3-4.*s1*two;
9086  Double_t a5 = 4.*c1*s1-s2;
9087  
9088  // Covariances (including weight dependent prefactor):
9089  Double_t wCov1 = 0.; // w*Cov(<2>,<cos(phi)) 
9090  Double_t wCov2 = 0.; // w*Cov(<2>,<sin(phi))
9091  Double_t wCov3 = 0.; // w*Cov(<cos(phi),<sin(phi))
9092  Double_t wCov4 = 0.; // w*Cov(<2>,<4>) 
9093  Double_t wCov5 = 0.; // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
9094  Double_t wCov6 = 0.; // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9095  Double_t wCov7 = 0.; // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
9096  Double_t wCov8 = 0.; // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9097  Double_t wCov9 = 0.; // w*Cov(<4>,<cos(#phi)>
9098  Double_t wCov10 = 0.; // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
9099  Double_t wCov11 = 0.; // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9100  Double_t wCov12 = 0.; // w*Cov(<4>,<sin(#phi)>
9101  Double_t wCov13 = 0.; // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
9102  Double_t wCov14 = 0.; // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9103  Double_t wCov15 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9104  Double_t wCov16 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9105  Double_t wCov17 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9106  Double_t wCov18 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9107  Double_t wCov19 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9108  Double_t wCov20 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9109  Double_t wCov21 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
9110  Double_t wCov22 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9111  Double_t wCov23 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9112  Double_t wCov24 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9113  Double_t wCov25 = 0.; // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
9114  Double_t wCov26 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9115  Double_t wCov27 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9116  Double_t wCov28 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9117  if(!fForgetAboutCovariances)
9118  {
9119   wCov1 = fIntFlowCovariancesNUA->GetBinContent(1); // w*Cov(<2>,<cos(phi)) 
9120   wCov2 = fIntFlowCovariancesNUA->GetBinContent(2); // w*Cov(<2>,<sin(phi))
9121   wCov3 = fIntFlowCovariancesNUA->GetBinContent(3); // w*Cov(<cos(phi),<sin(phi))
9122   wCov4 = fIntFlowCovariances->GetBinContent(1); // w*Cov(<2>,<4>) 
9123   wCov5 = fIntFlowCovariancesNUA->GetBinContent(4); // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
9124   wCov6 = fIntFlowCovariancesNUA->GetBinContent(6); // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9125   wCov7 = fIntFlowCovariancesNUA->GetBinContent(5); // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
9126   wCov8 = fIntFlowCovariancesNUA->GetBinContent(7); // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9127   wCov9 = fIntFlowCovariancesNUA->GetBinContent(8); // w*Cov(<4>,<cos(#phi)>
9128   wCov10 = fIntFlowCovariancesNUA->GetBinContent(10); // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
9129   wCov11 = fIntFlowCovariancesNUA->GetBinContent(12); // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9130   wCov12 = fIntFlowCovariancesNUA->GetBinContent(9); // w*Cov(<4>,<sin(#phi)>
9131   wCov13 = fIntFlowCovariancesNUA->GetBinContent(11); // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
9132   wCov14 = fIntFlowCovariancesNUA->GetBinContent(13); // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9133   wCov15 = fIntFlowCovariancesNUA->GetBinContent(14); // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9134   wCov16 = fIntFlowCovariancesNUA->GetBinContent(16); // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9135   wCov17 = fIntFlowCovariancesNUA->GetBinContent(15); // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9136   wCov18 = fIntFlowCovariancesNUA->GetBinContent(17); // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9137   wCov19 = fIntFlowCovariancesNUA->GetBinContent(23); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9138   wCov20 = fIntFlowCovariancesNUA->GetBinContent(18); // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9139   wCov21 = fIntFlowCovariancesNUA->GetBinContent(22); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
9140   wCov22 = fIntFlowCovariancesNUA->GetBinContent(24); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9141   wCov23 = fIntFlowCovariancesNUA->GetBinContent(20); // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9142   wCov24 = fIntFlowCovariancesNUA->GetBinContent(25); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9143   wCov25 = fIntFlowCovariancesNUA->GetBinContent(27); // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
9144   wCov26 = fIntFlowCovariancesNUA->GetBinContent(19); // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9145   wCov27 = fIntFlowCovariancesNUA->GetBinContent(21); // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9146   wCov28 = fIntFlowCovariancesNUA->GetBinContent(26); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9147  } // end of if(!fForgetAboutCovariances)
9148  
9149  // Calculating generalized QC{2}:
9150  //  Generalized QC{2}:
9151  Double_t gQC2 = two - pow(c1,2.) - pow(s1,2.);
9152  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(1,gQC2);} 
9153  //  Statistical error of generalized QC{2}:
9154  Double_t gQC2ErrorSquared = pow(twoError,2.)+4.*pow(c1,2.)*pow(c1Error,2.)
9155                            + 4.*pow(s1,2.)*pow(s1Error,2.)
9156                            - 4*c1*wCov1-4*s1*wCov2 
9157                            + 8.*c1*s1*wCov3;
9158  //  Store ratio of error squared - with/without NUA terms:
9159  Double_t ratioErrorSquaredQC2 = 0.;
9160  if(fIntFlowQcumulants->GetBinError(1)>0.)
9161  { 
9162   ratioErrorSquaredQC2 = (gQC2ErrorSquared/pow(fIntFlowQcumulants->GetBinError(1),2.));
9163   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(1,ratioErrorSquaredQC2);
9164  }
9165  //  If enabled, store error by including non-isotropic terms:                         
9166  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9167  {
9168   if(gQC2ErrorSquared>=0.)
9169   {
9170    fIntFlowQcumulants->SetBinError(1,pow(gQC2ErrorSquared,0.5));
9171   } else
9172     {
9173      fIntFlowQcumulants->SetBinError(1,0.);
9174      cout<<endl;
9175      cout<<" WARNING (QC): Statistical error of generalized QC{2} is imaginary !!!!"<<endl;
9176      cout<<endl;
9177     }   
9178  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9179  // Quantify detector bias to QC{2}:
9180  if(TMath::Abs(QC2)>0.)
9181  {
9182   fIntFlowDetectorBias->SetBinContent(1,gQC2/QC2); 
9183   if(QC2Error>0.)
9184   {
9185    Double_t errorSquared = gQC2ErrorSquared/pow(QC2,2.)+pow(gQC2,2.)*pow(QC2Error,2.)/pow(QC2,4.);
9186    if(errorSquared>0.)
9187    {
9188     fIntFlowDetectorBias->SetBinError(1,pow(errorSquared,0.5));  
9189    }
9190   }
9191  } // end of if(TMath::Abs(QC2)>0.)
9192
9193  // Calculating generalized QC{4}:
9194  //  Generalized QC{4}:
9195  Double_t gQC4 = four-2.*pow(two,2.)
9196                - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
9197                + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
9198                + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
9199  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(2,gQC4);}   
9200  //  Statistical error of generalized QC{4}:
9201  Double_t gQC4ErrorSquared = 16.*pow(a1,2.)*pow(twoError,2.)+pow(fourError,2.)+16.*pow(a2,2.)*pow(c1Error,2.)
9202                            + 4.*pow(a3,2.)*pow(c2Error,2.)+16.*pow(c1,2.)*pow(c3Error,2.)
9203                            + 16.*pow(a4,2.)*pow(s1Error,2.)+4.*pow(a5,2.)*pow(s2Error,2.)
9204                            + 16.*pow(s1,2.)*pow(s3Error,2.)+8.*a1*wCov4-32.*a1*a2*wCov1
9205                            - 16.*a3*a1*wCov5-32.*c1*a1*wCov6-32.*a1*a4*wCov2+16.*a5*a1*wCov7
9206                            + 32.*s1*a1*wCov8-8.*a2*wCov9-4.*a3*wCov10-8.*c1*wCov11-8.*a4*wCov12
9207                            + 4.*a5*wCov13+8.*s1*wCov14+16.*a3*a2*wCov15+32.*c1*a2*wCov16+32.*a2*a4*wCov3
9208                            - 16.*a5*a2*wCov17-32.*s1*a2*wCov18+16.*c1*a3*wCov19+16.*a3*a4*wCov20
9209                            - 8.*a3*a5*wCov21-16.*s1*a3*wCov22+32.*c1*a4*wCov23-16.*c1*a5*wCov24
9210                            - 32.*c1*s1*wCov25-16.*a5*a4*wCov26-32.*s1*a4*wCov27+16.*s1*a5*wCov28;
9211  //  Store ratio of error squared - with/without NUA terms:
9212  Double_t ratioErrorSquaredQC4 = 0.;
9213  if(fIntFlowQcumulants->GetBinError(2)>0.)
9214  { 
9215   ratioErrorSquaredQC4 = (gQC4ErrorSquared/pow(fIntFlowQcumulants->GetBinError(2),2.));
9216   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(2,ratioErrorSquaredQC4);
9217  }                          
9218  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9219  {
9220   if(gQC4ErrorSquared>=0.)
9221   {
9222    fIntFlowQcumulants->SetBinError(2,pow(gQC4ErrorSquared,0.5));
9223   } else
9224     {
9225      fIntFlowQcumulants->SetBinError(2,0.);
9226      cout<<endl;
9227      cout<<" WARNING (QC): Statistical error of generalized QC{4} is imaginary !!!!"<<endl;
9228      cout<<endl;
9229     }   
9230  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
9231  // Quantify detector bias to QC{4}:
9232  if(TMath::Abs(QC4)>0.)
9233  {
9234   fIntFlowDetectorBias->SetBinContent(2,gQC4/QC4); 
9235   if(QC4Error>0.)
9236   {
9237    Double_t errorSquared = gQC4ErrorSquared/pow(QC4,2.)+pow(gQC4,2.)*pow(QC4Error,2.)/pow(QC4,4.);
9238    if(errorSquared>0.)
9239    {
9240     fIntFlowDetectorBias->SetBinError(2,pow(errorSquared,0.5));  
9241    }
9242   }
9243  } // end of if(TMath::Abs(QC4)>0.)
9244
9245
9246  // .... to be improved (continued for 6th and 8th order) ....            
9247  
9248      
9249  // versus multiplicity:
9250  if(fCalculateCumulantsVsM) // to be improved - propagate error for nua terms vs M
9251  { 
9252   Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
9253   Double_t value[4] = {0.}; // QCs vs M
9254   Double_t error[4] = {0.}; // error of QCs vs M
9255   Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
9256   Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
9257   for(Int_t b=1;b<=nBins;b++)
9258   {
9259    // Measured correlations:
9260    two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> vs M
9261    four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>> vs M
9262    // Isotropic cumulants:
9263    QC2 = two;
9264    QC4 = four-2.*pow(two,2.);
9265    // Non-isotropic terms:
9266    c1 = fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b); // <<cos(n*phi1)>>
9267    c2 = fIntFlowCorrectionTermsForNUAVsMPro[1][1]->GetBinContent(b); // <<cos(n*(phi1+phi2))>>
9268    c3 = fIntFlowCorrectionTermsForNUAVsMPro[1][2]->GetBinContent(b); // <<cos(n*(phi1-phi2-phi3))>>
9269    s1 = fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b); // <<sin(n*phi1)>>
9270    s2 = fIntFlowCorrectionTermsForNUAVsMPro[0][1]->GetBinContent(b); // <<sin(n*(phi1+phi2))>>
9271    s3 = fIntFlowCorrectionTermsForNUAVsMPro[0][2]->GetBinContent(b); // <<sin(n*(phi1-phi2-phi3))>>
9272    // Generalized QC{2} vs M:
9273    gQC2 = two - pow(c1,2.) - pow(s1,2.); 
9274    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[0]->SetBinContent(b,gQC2);}   
9275    // Generalized QC{4} vs M:  
9276    gQC4 = four-2.*pow(two,2.)
9277                  - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
9278                  + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
9279                  + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
9280    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[1]->SetBinContent(b,gQC4);}   
9281    // Detector bias vs M:
9282    if(TMath::Abs(QC2)>0.)
9283    {
9284     fIntFlowDetectorBiasVsM[0]->SetBinContent(b,gQC2/QC2); 
9285    } // end of if(TMath::Abs(QC2)>0.)
9286    if(TMath::Abs(QC4)>0.)
9287    {
9288     fIntFlowDetectorBiasVsM[1]->SetBinContent(b,gQC4/QC4); 
9289    } // end of if(TMath::Abs(QC4)>0.)  
9290    // Rebin in M:
9291    for(Int_t co=0;co<4;co++)
9292    {
9293     value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
9294     error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
9295     if(error[co]>0.)
9296     {
9297      dSum1[co]+=value[co]/(error[co]*error[co]);
9298      dSum2[co]+=1./(error[co]*error[co]);
9299     }
9300    } // end of for(Int_t co=0;co<4;co++) 
9301   } // end of for(Int_t b=1;b<=nBins;b++)
9302   // Store rebinned Q-cumulants:
9303   if(fApplyCorrectionForNUAVsM)
9304   {
9305    for(Int_t co=0;co<4;co++)
9306    {
9307     if(dSum2[co]>0.)
9308     {
9309      fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
9310      fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
9311     }
9312    } // end of for(Int_t co=0;co<4;co++)
9313   } // end of if(fApplyCorrectionForNUAVsM)
9314  } // end of if(fCalculateCumulantsVsM) 
9315      
9316 } // end of void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
9317  
9318 //================================================================================================================================
9319
9320 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow() 
9321 {
9322  // From profile fIntFlowCorrectionTermsForNUAPro[sc] access measured correction terms for NUA
9323  // and their spread, correctly calculate the statistical errors and store the final 
9324  // results and statistical errors for correction terms for NUA in histogram fIntFlowCorrectionTermsForNUAHist[sc].
9325  //
9326  // Remark: Statistical error of correction temrs is calculated as:
9327  //
9328  //          statistical error = termA * spread * termB:
9329  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
9330  //          termB = 1/sqrt(1-termA^2)   
9331  
9332  TString sinCosFlag[2] = {"sin","cos"}; // to be improved - promore this to data member?
9333  TString nonisotropicTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
9334     
9335  for(Int_t sc=0;sc<2;sc++) // sin or cos correction terms 
9336  {
9337   for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
9338   {
9339    Double_t correction = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci);
9340    Double_t spread = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinError(ci);
9341    Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeightsNUA[sc][0]->GetBinContent(ci);
9342    Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeightsNUA[sc][1]->GetBinContent(ci);
9343    Double_t termA = 0.;
9344    Double_t termB = 0.;
9345    if(TMath::Abs(sumOfLinearEventWeights)>1.e-44)
9346    {
9347     termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
9348    } else
9349      {
9350       cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in AFAWQC::FCTFNIF() !!!!"<<endl;
9351       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
9352      }
9353    if(1.-pow(termA,2.) > 0.)
9354    {
9355     termB = 1./pow(1-pow(termA,2.),0.5);
9356    } else
9357      {
9358       cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in AFAWQC::FCTFNIF() !!!!"<<endl;   
9359       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
9360      }     
9361    Double_t statisticalError = termA * spread * termB;
9362    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinContent(ci,correction);
9363    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinError(ci,statisticalError);
9364   } // end of for(Int_t ci=1;ci<=4;ci++) // correction term index
9365  } // end of for(Int sc=0;sc<2;sc++) // sin or cos correction terms 
9366                                                                                                                                                                                                
9367 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow()
9368
9369 //================================================================================================================================
9370
9371 void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
9372 {
9373  // Get pointers to all objects relevant for calculations with nested loops.
9374    
9375  TList *nestedLoopsList = dynamic_cast<TList*>(fHistList->FindObject("Nested Loops"));
9376  if(nestedLoopsList) 
9377  {
9378   this->SetNestedLoopsList(nestedLoopsList);
9379  } else
9380    {
9381     cout<<"WARNING: nestedLoopsList is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9382     exit(0);
9383    }
9384     
9385   TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
9386   TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
9387   TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
9388   TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
9389    
9390   TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
9391   evaluateNestedLoopsName += fAnalysisLabel->Data();  
9392   TProfile *evaluateNestedLoops = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(evaluateNestedLoopsName.Data()));
9393   Bool_t bEvaluateIntFlowNestedLoops = kFALSE;
9394   Bool_t bEvaluateDiffFlowNestedLoops = kFALSE;
9395   if(evaluateNestedLoops)
9396   {
9397    this->SetEvaluateNestedLoops(evaluateNestedLoops);
9398    bEvaluateIntFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(1);
9399    bEvaluateDiffFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(2);
9400   }
9401   // nested loops relevant for integrated flow:  
9402   if(bEvaluateIntFlowNestedLoops)
9403   {
9404    // correlations:
9405    TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
9406    intFlowDirectCorrelationsName += fAnalysisLabel->Data();
9407    TProfile *intFlowDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowDirectCorrelationsName.Data()));
9408    if(intFlowDirectCorrelations) 
9409    { 
9410     this->SetIntFlowDirectCorrelations(intFlowDirectCorrelations);
9411    } else
9412      {
9413       cout<<"WARNING: intFlowDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9414       exit(0);
9415      }
9416    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
9417    {
9418     TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
9419     intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
9420     TProfile *intFlowExtraDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowExtraDirectCorrelationsName.Data()));
9421     if(intFlowExtraDirectCorrelations) 
9422     { 
9423      this->SetIntFlowExtraDirectCorrelations(intFlowExtraDirectCorrelations);
9424     } else
9425       {
9426        cout<<"WARNING: intFlowExtraDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9427        exit(0);
9428       }       
9429    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
9430    // correction terms for non-uniform acceptance:
9431    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
9432    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
9433    TProfile *intFlowDirectCorrectionTermsForNUA[2] = {NULL};
9434    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
9435    {
9436     intFlowDirectCorrectionTermsForNUA[sc] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s: %s terms",intFlowDirectCorrectionTermsForNUAName.Data(),sinCosFlag[sc].Data())));
9437     if(intFlowDirectCorrectionTermsForNUA[sc]) 
9438     { 
9439      this->SetIntFlowDirectCorrectionTermsForNUA(intFlowDirectCorrectionTermsForNUA[sc],sc);
9440     } else
9441       {
9442        cout<<"WARNING: intFlowDirectCorrectionTermsForNUA[sc] is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9443        cout<<"sc = "<<sc<<endl;
9444        exit(0);
9445       }
9446    } // end of for(Int_t sc=0;sc<2;sc++) 
9447   } // end of if(bEvaluateIntFlowNestedLoops)
9448     
9449   // nested loops relevant for differential flow:  
9450   if(bEvaluateDiffFlowNestedLoops)
9451   {
9452    // correlations:
9453    TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
9454    diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
9455    TProfile *diffFlowDirectCorrelations[2][2][4] = {{{NULL}}};
9456    for(Int_t t=0;t<2;t++)
9457    {
9458     for(Int_t pe=0;pe<2;pe++)
9459     {
9460      for(Int_t ci=0;ci<4;ci++) // correlation index
9461      {
9462       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())));
9463       if(diffFlowDirectCorrelations[t][pe][ci])
9464       {
9465        this->SetDiffFlowDirectCorrelations(diffFlowDirectCorrelations[t][pe][ci],t,pe,ci);
9466       } else
9467         {
9468          cout<<"WARNING: diffFlowDirectCorrelations[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9469          cout<<"t  = "<<t<<endl;
9470          cout<<"pe = "<<pe<<endl;   
9471          cout<<"ci = "<<ci<<endl;
9472         }     
9473      } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
9474     } // end of for(Int_t pe=0;pe<2;pe++)
9475    } // end of for(Int_t t=0;t<2;t++)   
9476    // correction terms for non-uniform acceptance:
9477    TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
9478    diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();  
9479    TProfile *diffFlowDirectCorrectionTermsForNUA[2][2][2][10] = {{{{NULL}}}};   
9480    for(Int_t t=0;t<2;t++)
9481    {
9482     for(Int_t pe=0;pe<2;pe++)
9483     {
9484      // correction terms for NUA:
9485      for(Int_t sc=0;sc<2;sc++) // sin or cos
9486      {
9487       for(Int_t cti=0;cti<9;cti++) // correction term index
9488       {
9489        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)));
9490        if(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti])
9491        {
9492         this->SetDiffFlowDirectCorrectionTermsForNUA(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti],t,pe,sc,cti);
9493        } else
9494          {
9495           cout<<"WARNING: diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9496           cout<<"t   = "<<t<<endl;
9497           cout<<"pe  = "<<pe<<endl;   
9498           cout<<"sc  = "<<sc<<endl;
9499           cout<<"cti = "<<cti<<endl;
9500          }    
9501       } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
9502      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9503     } // end of for(Int_t pe=0;pe<2;pe++)
9504    } // end of for(Int_t t=0;t<2;t++)
9505    // number of RPs and POIs in selected pt and eta bins for cross-checkings:
9506    TString noOfParticlesInBinName = "fNoOfParticlesInBin";
9507    TH1D *noOfParticlesInBin = NULL;
9508    noOfParticlesInBin = dynamic_cast<TH1D*>(nestedLoopsList->FindObject(noOfParticlesInBinName.Data()));
9509    if(noOfParticlesInBin)
9510    {
9511     this->SetNoOfParticlesInBin(noOfParticlesInBin);
9512    } else
9513      {
9514       cout<<endl;
9515       cout<<" WARNING (QC): noOfParticlesInBin is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9516       cout<<endl;
9517      }
9518   } // end of if(bEvaluateDiffFlowNestedLoops)
9519
9520 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
9521
9522 //================================================================================================================================
9523
9524 void AliFlowAnalysisWithQCumulants::StoreHarmonic()
9525 {
9526  // Store flow harmonic in common control histograms.
9527
9528  (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
9529  if(fFillMultipleControlHistograms)
9530  {
9531   (fCommonHists2nd->GetHarmonic())->Fill(0.5,fHarmonic);
9532   (fCommonHists4th->GetHarmonic())->Fill(0.5,fHarmonic);
9533   (fCommonHists6th->GetHarmonic())->Fill(0.5,fHarmonic);
9534   (fCommonHists8th->GetHarmonic())->Fill(0.5,fHarmonic);
9535  }
9536  
9537 } // end of void AliFlowAnalysisWithQCumulants::StoreHarmonic()
9538
9539 //================================================================================================================================
9540
9541 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta) // type = RP or POI 
9542 {
9543  // Calculate all correlations needed for differential flow using particle weights.
9544  
9545  Int_t t = 0; // type flag 
9546  Int_t pe = 0; // ptEta flag
9547  
9548  if(type == "RP")
9549  {
9550   t = 0;
9551  } else if(type == "POI")
9552    {
9553     t = 1;
9554    }
9555
9556  if(ptOrEta == "Pt")
9557  {
9558   pe = 0;
9559  } else if(ptOrEta == "Eta")
9560    {
9561     pe = 1;
9562    }
9563     
9564  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9565  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9566  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9567  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9568
9569  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9570  Double_t dReQ1n1k = (*fReQ)(0,1);
9571  Double_t dReQ2n2k = (*fReQ)(1,2);
9572  Double_t dReQ1n3k = (*fReQ)(0,3);
9573  //Double_t dReQ4n4k = (*fReQ)(3,4);
9574  Double_t dImQ1n1k = (*fImQ)(0,1);
9575  Double_t dImQ2n2k = (*fImQ)(1,2);
9576  Double_t dImQ1n3k = (*fImQ)(0,3);
9577  //Double_t dImQ4n4k = (*fImQ)(3,4);
9578  
9579  // S^M_{p,k} (see .h file for the definition of fSMpk):
9580  Double_t dSM1p1k = (*fSMpk)(0,1);
9581  Double_t dSM1p2k = (*fSMpk)(0,2);
9582  Double_t dSM1p3k = (*fSMpk)(0,3);
9583  Double_t dSM2p1k = (*fSMpk)(1,1);
9584  Double_t dSM3p1k = (*fSMpk)(2,1);
9585  
9586  // looping over all bins and calculating reduced correlations: 
9587  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9588  {
9589   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
9590   Double_t p1n0kRe = 0.;
9591   Double_t p1n0kIm = 0.;
9592
9593   // number of POIs in particular (pt,eta) bin):
9594   Double_t mp = 0.;
9595
9596   // real and imaginary parts of q_{m*n,k}: 
9597   // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
9598   Double_t q1n2kRe = 0.;
9599   Double_t q1n2kIm = 0.;
9600   Double_t q2n1kRe = 0.;
9601   Double_t q2n1kIm = 0.;
9602
9603   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9604   Double_t s1p1k = 0.; 
9605   Double_t s1p2k = 0.; 
9606   Double_t s1p3k = 0.; 
9607    
9608   // M0111 from Eq. (118) in QC2c (to be improved (notation))
9609   Double_t dM0111 = 0.;
9610  
9611   if(type == "POI")
9612   {
9613    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
9614            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
9615    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
9616            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
9617             
9618    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9619     
9620    t = 1; // typeFlag = RP or POI
9621     
9622    // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
9623    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
9624            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
9625    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
9626            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));
9627    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
9628            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
9629    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
9630            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));
9631        
9632    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9633    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
9634    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
9635    s1p3k = pow(fs1dEBE[2][pe][3]->GetBinContent(b)*fs1dEBE[2][pe][3]->GetBinEntries(b),1.); 
9636      
9637    // M0111 from Eq. (118) in QC2c (to be improved (notation)):
9638    dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
9639           - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
9640           + 2.*(s1p3k-s1p2k*dSM1p1k));
9641   }
9642    else if(type == "RP")
9643    {
9644     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
9645     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
9646             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
9647     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
9648             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
9649     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
9650             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
9651     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
9652             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
9653
9654     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9655     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
9656     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
9657     s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
9658     
9659     // to be improved (cross-checked):
9660     p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
9661             * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
9662     p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
9663             * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
9664             
9665     mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9666      
9667     t = 0; // typeFlag = RP or POI
9668     
9669     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
9670     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
9671            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
9672            + 2.*(s1p3k-s1p2k*dSM1p1k));
9673     //...............................................................................................   
9674    }
9675    
9676    // 2'-particle correlation:
9677    Double_t two1n1nW0W1 = 0.;
9678    if(mp*dSM1p1k-s1p1k)
9679    {
9680     two1n1nW0W1 = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
9681                 / (mp*dSM1p1k-s1p1k);
9682    
9683     // fill profile to get <<2'>>     
9684     fDiffFlowCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1,mp*dSM1p1k-s1p1k);    
9685     // fill profile to get <<2'>^2>     
9686     fDiffFlowSquaredCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1*two1n1nW0W1,mp*dSM1p1k-s1p1k);        
9687     // histogram to store <2'> e-b-e (needed in some other methods):
9688     fDiffFlowCorrelationsEBE[t][pe][0]->SetBinContent(b,two1n1nW0W1);      
9689     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->SetBinContent(b,mp*dSM1p1k-s1p1k);      
9690    } // end of if(mp*dSM1p1k-s1p1k)
9691    
9692    // 4'-particle correlation:
9693    Double_t four1n1n1n1nW0W1W1W1 = 0.;
9694    if(dM0111)
9695    {
9696     four1n1n1n1nW0W1W1W1 = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
9697                          - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
9698                          - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
9699                          - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
9700                          + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
9701                          - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
9702                          - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
9703                          + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
9704                          + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
9705                          + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
9706                          + 2.*s1p1k*dSM1p2k                                      
9707                          - 6.*s1p3k)        
9708                          / dM0111; // to be improved (notation of dM0111)
9709    
9710     // fill profile to get <<4'>>     
9711     fDiffFlowCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1,dM0111);    
9712     // fill profile to get <<4'>^2>     
9713     fDiffFlowSquaredCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1*four1n1n1n1nW0W1W1W1,dM0111);        
9714     // histogram to store <4'> e-b-e (needed in some other methods):
9715     fDiffFlowCorrelationsEBE[t][pe][1]->SetBinContent(b,four1n1n1n1nW0W1W1W1);      
9716     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->SetBinContent(b,dM0111);      
9717    } // end of if(dM0111)
9718  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9719
9720 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta); // type = RP or POI 
9721
9722 //================================================================================================================================
9723
9724 void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
9725 {
9726  // Fill common control histograms.
9727  
9728  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
9729  fCommonHists->FillControlHistograms(anEvent); 
9730  if(fFillMultipleControlHistograms)
9731  {
9732   if(nRP>1)
9733   {
9734    fCommonHists2nd->FillControlHistograms(anEvent);                                        
9735    if(nRP>3)
9736    {
9737     fCommonHists4th->FillControlHistograms(anEvent);                                        
9738     if(nRP>5)
9739     {
9740      fCommonHists6th->FillControlHistograms(anEvent);                                        
9741      if(nRP>7)
9742      {
9743       fCommonHists8th->FillControlHistograms(anEvent);                                        
9744      } // end of if(nRP>7)  
9745     } // end of if(nRP>5) 
9746    } // end of if(nRP>3)                                                                                                                      
9747   } // end of if(nRP>1) 
9748  } // end of if(fFillMultipleControlHistograms)
9749  
9750 } // end of void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
9751
9752 //================================================================================================================================
9753
9754 void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities()
9755 {
9756  // Reset all event by event quantities.
9757  
9758  // integrated flow:
9759  fReQ->Zero();
9760  fImQ->Zero();
9761  fSMpk->Zero();
9762  fIntFlowCorrelationsEBE->Reset();
9763  fIntFlowEventWeightsForCorrelationsEBE->Reset();
9764  fIntFlowCorrelationsAllEBE->Reset();
9765  
9766  for(Int_t sc=0;sc<2;sc++)
9767  {
9768   fIntFlowCorrectionTermsForNUAEBE[sc]->Reset();
9769   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->Reset(); 
9770  }
9771     
9772  // differential flow:
9773  // 1D:
9774  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
9775  {
9776   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
9777   {
9778    for(Int_t m=0;m<4;m++) // multiple of harmonic
9779    {
9780     for(Int_t k=0;k<9;k++) // power of weight
9781     {
9782      if(fReRPQ1dEBE[t][pe][m][k]) fReRPQ1dEBE[t][pe][m][k]->Reset();
9783      if(fImRPQ1dEBE[t][pe][m][k]) fImRPQ1dEBE[t][pe][m][k]->Reset();
9784     }   
9785    }
9786   }
9787  }
9788   
9789  for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
9790  { 
9791   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
9792   {
9793    for(Int_t k=0;k<9;k++)
9794    {
9795     if(fs1dEBE[t][pe][k]) fs1dEBE[t][pe][k]->Reset();
9796    }
9797   }
9798  }
9799
9800  // e-b-e reduced correlations:
9801  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
9802  {  
9803   for(Int_t pe=0;pe<2;pe++) // pt or eta
9804   {
9805    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9806    {
9807     if(fDiffFlowCorrelationsEBE[t][pe][rci]) fDiffFlowCorrelationsEBE[t][pe][rci]->Reset();
9808     if(fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]) fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]->Reset();
9809    }
9810   }
9811  }
9812     
9813  // correction terms for NUA:
9814  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
9815  {  
9816   for(Int_t pe=0;pe<2;pe++) // pt or eta
9817   {
9818    for(Int_t sc=0;sc<2;sc++) // sin or cos
9819    {
9820     for(Int_t cti=0;cti<9;cti++) // correction term index
9821     {
9822      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti]->Reset();  
9823     }
9824    }
9825   }      
9826  }
9827     
9828  // 2D (pt,eta)
9829  if(fCalculate2DFlow)
9830  {
9831   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
9832   {
9833    for(Int_t m=0;m<4;m++) // multiple of harmonic
9834    {
9835     for(Int_t k=0;k<9;k++) // power of weight
9836     {
9837      if(fReRPQ2dEBE[t][m][k]){fReRPQ2dEBE[t][m][k]->Reset();}
9838      if(fImRPQ2dEBE[t][m][k]){fImRPQ2dEBE[t][m][k]->Reset();}
9839     }   
9840    }
9841   }
9842   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
9843   { 
9844    for(Int_t k=0;k<9;k++)
9845    {
9846     if(fs2dEBE[t][k]){fs2dEBE[t][k]->Reset();}
9847    }
9848   }  
9849  } // end of if(fCalculate2DFlow) 
9850
9851 } // end of void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities();
9852
9853
9854 //================================================================================================================================
9855
9856
9857 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
9858 {
9859  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
9860  
9861  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
9862  //  0: <<sin n(psi1)>>
9863  //  1: <<sin n(psi1+phi2)>>
9864  //  2: <<sin n(psi1+phi2-phi3)>>
9865  //  3: <<sin n(psi1-phi2-phi3)>>:
9866  //  4:
9867  //  5:
9868  //  6:
9869  
9870  // multiplicity:
9871  Double_t dMult = (*fSMpk)(0,0);
9872  
9873  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9874  Double_t dReQ1n = (*fReQ)(0,0);
9875  Double_t dReQ2n = (*fReQ)(1,0);
9876  //Double_t dReQ3n = (*fReQ)(2,0);
9877  //Double_t dReQ4n = (*fReQ)(3,0);
9878  Double_t dImQ1n = (*fImQ)(0,0);
9879  Double_t dImQ2n = (*fImQ)(1,0);
9880  //Double_t dImQ3n = (*fImQ)(2,0);
9881  //Double_t dImQ4n = (*fImQ)(3,0);
9882
9883  Int_t t = 0; // type flag 
9884  Int_t pe = 0; // ptEta flag
9885  
9886  if(type == "RP")
9887  {
9888   t = 0;
9889  } else if(type == "POI")
9890    {
9891     t = 1;
9892    }
9893
9894  if(ptOrEta == "Pt")
9895  {
9896   pe = 0;
9897  } else if(ptOrEta == "Eta")
9898    {
9899     pe = 1;
9900    }
9901     
9902  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9903  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9904  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9905  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9906
9907  // looping over all bins and calculating correction terms: 
9908  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9909  {
9910   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
9911   Double_t p1n0kRe = 0.;
9912   Double_t p1n0kIm = 0.;
9913
9914   // number of POIs in particular pt or eta bin:
9915   Double_t mp = 0.;
9916
9917   // 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):
9918   Double_t q1n0kRe = 0.;
9919   Double_t q1n0kIm = 0.;
9920   Double_t q2n0kRe = 0.;
9921   Double_t q2n0kIm = 0.;
9922
9923   // number of particles which are both RPs and POIs in particular pt or eta bin:
9924   Double_t mq = 0.;
9925    
9926   if(type == "POI")
9927   {
9928    // q_{m*n,0}:
9929    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
9930            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
9931    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
9932            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
9933    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
9934            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
9935    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
9936            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
9937                  
9938    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9939   } 
9940   else if(type == "RP")
9941   {
9942    // q_{m*n,0}:
9943    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
9944            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
9945    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
9946            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
9947    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
9948            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
9949    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
9950            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
9951                  
9952    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
9953   }    
9954   if(type == "POI")
9955   {
9956    // p_{m*n,0}:
9957    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
9958            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
9959    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
9960            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
9961             
9962    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9963     
9964    t = 1; // typeFlag = RP or POI
9965   }
9966   else if(type == "RP")
9967   {
9968    // p_{m*n,0} = q_{m*n,0}:
9969    p1n0kRe = q1n0kRe; 
9970    p1n0kIm = q1n0kIm; 
9971            
9972    mp = mq; 
9973    
9974    t = 0; // typeFlag = RP or POI
9975   }
9976
9977   // <<sin n(psi1)>>:
9978   Double_t sinP1nPsi = 0.;
9979   if(mp)
9980   {
9981    sinP1nPsi = p1n0kIm/mp;
9982    // fill profile for <<sin n(psi1)>>:
9983    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
9984    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
9985    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
9986   } // end of if(mp)   
9987   
9988   // <<sin n(psi1+phi2)>>:
9989   Double_t sinP1nPsiP1nPhi = 0.;
9990   if(mp*dMult-mq)
9991   {
9992    sinP1nPsiP1nPhi = (p1n0kRe*dImQ1n+p1n0kIm*dReQ1n-q2n0kIm)/(mp*dMult-mq);
9993    // fill profile for <<sin n(psi1+phi2)>>:
9994    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhi,mp*dMult-mq);
9995    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
9996    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhi);
9997   } // end of if(mp*dMult-mq)   
9998   
9999   // <<sin n(psi1+phi2-phi3)>>:
10000   Double_t sinP1nPsi1P1nPhi2MPhi3 = 0.;
10001   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10002   {
10003    sinP1nPsi1P1nPhi2MPhi3 = (p1n0kIm*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
10004                           - 1.*(q2n0kIm*dReQ1n-q2n0kRe*dImQ1n)  
10005                           - mq*dImQ1n+2.*q1n0kIm)
10006                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10007    // fill profile for <<sin n(psi1+phi2)>>:
10008    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10009    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10010    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3);
10011   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10012   
10013   // <<sin n(psi1-phi2-phi3)>>:
10014   Double_t sinP1nPsi1M1nPhi2MPhi3 = 0.;
10015   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10016   {
10017    sinP1nPsi1M1nPhi2MPhi3 = (p1n0kIm*(pow(dReQ1n,2.)-pow(dImQ1n,2.))-2.*p1n0kRe*dReQ1n*dImQ1n
10018                           - 1.*(p1n0kIm*dReQ2n-p1n0kRe*dImQ2n)
10019                           + 2.*mq*dImQ1n-2.*q1n0kIm)
10020                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10021    // fill profile for <<sin n(psi1+phi2)>>:
10022    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10023    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10024    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3);
10025   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10026  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10027  
10028 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
10029
10030
10031 //================================================================================================================================
10032
10033
10034 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
10035 {
10036  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms).
10037  
10038  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
10039  //  0: <<cos n(psi)>>
10040  //  1: <<cos n(psi1+phi2)>>
10041  //  2: <<cos n(psi1+phi2-phi3)>>
10042  //  3: <<cos n(psi1-phi2-phi3)>>
10043  //  4:
10044  //  5:
10045  //  6:
10046  
10047  // multiplicity:
10048  Double_t dMult = (*fSMpk)(0,0);
10049  
10050  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10051  Double_t dReQ1n = (*fReQ)(0,0);
10052  Double_t dReQ2n = (*fReQ)(1,0);
10053  //Double_t dReQ3n = (*fReQ)(2,0);
10054  //Double_t dReQ4n = (*fReQ)(3,0);
10055  Double_t dImQ1n = (*fImQ)(0,0);
10056  Double_t dImQ2n = (*fImQ)(1,0);
10057  //Double_t dImQ3n = (*fImQ)(2,0);
10058  //Double_t dImQ4n = (*fImQ)(3,0);
10059
10060  Int_t t = 0; // type flag 
10061  Int_t pe = 0; // ptEta flag
10062  
10063  if(type == "RP")
10064  {
10065   t = 0;
10066  } else if(type == "POI")
10067    {
10068     t = 1;
10069    }
10070
10071  if(ptOrEta == "Pt")
10072  {
10073   pe = 0;
10074  } else if(ptOrEta == "Eta")
10075    {
10076     pe = 1;
10077    }
10078     
10079  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10080  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10081  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10082  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10083
10084  // looping over all bins and calculating correction terms: 
10085  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10086  {
10087   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
10088   Double_t p1n0kRe = 0.;
10089   Double_t p1n0kIm = 0.;
10090
10091   // number of POIs in particular pt or eta bin:
10092   Double_t mp = 0.;
10093
10094   // 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):
10095   Double_t q1n0kRe = 0.;
10096   Double_t q1n0kIm = 0.;
10097   Double_t q2n0kRe = 0.;
10098   Double_t q2n0kIm = 0.;
10099
10100   // number of particles which are both RPs and POIs in particular pt or eta bin:
10101   Double_t mq = 0.;
10102    
10103   if(type == "POI")
10104   {
10105    // q_{m*n,0}:
10106    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
10107            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
10108    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
10109            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
10110    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
10111            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
10112    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
10113            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
10114                  
10115    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10116   } 
10117   else if(type == "RP")
10118   {
10119    // q_{m*n,0}:
10120    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10121            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10122    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
10123            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10124    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
10125            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
10126    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
10127            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
10128                  
10129    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
10130   }    
10131   if(type == "POI")
10132   {
10133    // p_{m*n,0}:
10134    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10135            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10136    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10137            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10138             
10139    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10140     
10141    t = 1; // typeFlag = RP or POI
10142   }
10143   else if(type == "RP")
10144   {
10145    // p_{m*n,0} = q_{m*n,0}:
10146    p1n0kRe = q1n0kRe; 
10147    p1n0kIm = q1n0kIm; 
10148            
10149    mp = mq; 
10150    
10151    t = 0; // typeFlag = RP or POI
10152   }
10153
10154   // <<cos n(psi1)>>:
10155   Double_t cosP1nPsi = 0.;
10156   if(mp)
10157   {
10158    cosP1nPsi = p1n0kRe/mp;
10159    
10160    // fill profile for <<cos n(psi1)>>:
10161    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
10162    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
10163    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
10164   } // end of if(mp)   
10165   
10166   // <<cos n(psi1+phi2)>>:
10167   Double_t cosP1nPsiP1nPhi = 0.;
10168   if(mp*dMult-mq)
10169   {
10170    cosP1nPsiP1nPhi = (p1n0kRe*dReQ1n-p1n0kIm*dImQ1n-q2n0kRe)/(mp*dMult-mq);
10171    // fill profile for <<sin n(psi1+phi2)>>:
10172    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhi,mp*dMult-mq);
10173    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10174    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhi);
10175   } // end of if(mp*dMult-mq)   
10176   
10177   // <<cos n(psi1+phi2-phi3)>>:
10178   Double_t cosP1nPsi1P1nPhi2MPhi3 = 0.;
10179   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10180   {
10181    cosP1nPsi1P1nPhi2MPhi3 = (p1n0kRe*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
10182                           - 1.*(q2n0kRe*dReQ1n+q2n0kIm*dImQ1n)  
10183                           - mq*dReQ1n+2.*q1n0kRe)
10184                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10185    // fill profile for <<sin n(psi1+phi2)>>:
10186    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10187    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10188    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3);
10189   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10190   
10191   // <<cos n(psi1-phi2-phi3)>>:
10192   Double_t cosP1nPsi1M1nPhi2MPhi3 = 0.;
10193   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10194   {
10195    cosP1nPsi1M1nPhi2MPhi3 = (p1n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))+2.*p1n0kIm*dReQ1n*dImQ1n
10196                           - 1.*(p1n0kRe*dReQ2n+p1n0kIm*dImQ2n)  
10197                           - 2.*mq*dReQ1n+2.*q1n0kRe)
10198                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10199    // fill profile for <<sin n(psi1+phi2)>>:
10200    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10201    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10202    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3);
10203   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10204  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10205  
10206 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
10207
10208
10209 //==================================================================================================================================
10210
10211
10212 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
10213 {
10214  // Transfer prolfiles into histogams and correctly propagate the error (to be improved: description)
10215  
10216  // to be improved: debugged - I do not correctly transfer all profiles into histos (bug appears only after merging) 
10217   
10218  Int_t t = 0; // type flag 
10219  Int_t pe = 0; // ptEta flag
10220  
10221  if(type == "RP")
10222  {
10223   t = 0;
10224  } else if(type == "POI")
10225    {
10226     t = 1;
10227    }
10228
10229  if(ptOrEta == "Pt")
10230  {
10231   pe = 0;
10232  } else if(ptOrEta == "Eta")
10233    {
10234     pe = 1;
10235    }
10236     
10237  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10238  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
10239  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10240  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10241
10242  for(Int_t sc=0;sc<2;sc++) // sin or cos
10243  {
10244   for(Int_t cti=0;cti<9;cti++) // correction term index
10245   {
10246    for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10247    {
10248     Double_t correctionTerm = fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(b);
10249     fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]->SetBinContent(b,correctionTerm);
10250     // to be improved (propagate error correctly)
10251     // ...
10252    } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10253   } // correction term index
10254  } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
10255
10256 }// end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
10257
10258
10259 //==================================================================================================================================
10260
10261
10262 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
10263
10264  // Calculate generalized differential flow Q-cumulants (corrected for non-uniform acceptance)
10265   
10266  Int_t typeFlag = 0;
10267  Int_t ptEtaFlag = 0;
10268
10269  if(type == "RP")
10270  {
10271   typeFlag = 0;
10272  } else if(type == "POI")
10273    {
10274     typeFlag = 1;
10275    } 
10276      
10277  if(ptOrEta == "Pt")
10278  {
10279   ptEtaFlag = 0;
10280  } else if(ptOrEta == "Eta")
10281    {
10282     ptEtaFlag = 1;
10283    } 
10284   
10285  // shortcuts:
10286  Int_t t = typeFlag;
10287  Int_t pe = ptEtaFlag;
10288      
10289  // common:
10290  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10291  
10292  // 2-particle correlation:
10293  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
10294  // sin term coming from integrated flow: 
10295  Double_t sinP1nPhi = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
10296  Double_t sinP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
10297  Double_t sinP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
10298  // cos term coming from integrated flow: 
10299  Double_t cosP1nPhi = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
10300  Double_t cosP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
10301  Double_t cosP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
10302
10303  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10304  {
10305   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
10306   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
10307   Double_t sinP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][0]->GetBinContent(b); // <<sin n(Psi)>> 
10308   Double_t cosP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][0]->GetBinContent(b); // <<cos n(Psi)>> 
10309   Double_t sinP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][1]->GetBinContent(b); // <<sin n(psi1+phi2)>> 
10310   Double_t cosP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][1]->GetBinContent(b); // <<cos n(psi1+phi2)>> 
10311   Double_t sinP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][2]->GetBinContent(b); // <<sin n(psi1+phi2-phi3)>> 
10312   Double_t cosP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][2]->GetBinContent(b); // <<cos n(psi1+phi2-phi3)>> 
10313   Double_t sinP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][3]->GetBinContent(b); // <<sin n(psi1-phi2-phi3)>> 
10314   Double_t cosP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][3]->GetBinContent(b); // <<cos n(psi1-phi2-phi3)>> 
10315   // generalized QC{2'}:
10316   Double_t qc2Prime = twoPrime - sinP1nPsi*sinP1nPhi - cosP1nPsi*cosP1nPhi;
10317   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime);
10318   // generalized QC{4'}:
10319   Double_t qc4Prime = fourPrime-2.*twoPrime*two
10320                     - cosP1nPsi*cosP1nPhi1M1nPhi2M1nPhi3
10321                     + sinP1nPsi*sinP1nPhi1M1nPhi2M1nPhi3
10322                     - cosP1nPhi*cosP1nPsi1M1nPhi2M1nPhi3
10323                     + sinP1nPhi*sinP1nPsi1M1nPhi2M1nPhi3
10324                     - 2.*cosP1nPhi*cosP1nPsi1P1nPhi2M1nPhi3
10325                     - 2.*sinP1nPhi*sinP1nPsi1P1nPhi2M1nPhi3
10326                     - cosP1nPsi1P1nPhi2*cosP1nPhi1P1nPhi2
10327                     - sinP1nPsi1P1nPhi2*sinP1nPhi1P1nPhi2
10328                     + 2.*cosP1nPhi1P1nPhi2*(cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
10329                     + 2.*sinP1nPhi1P1nPhi2*(cosP1nPsi*sinP1nPhi+sinP1nPsi*cosP1nPhi)
10330                     + 4.*two*(cosP1nPsi*cosP1nPhi+sinP1nPsi*sinP1nPhi)
10331                     + 2.*cosP1nPsi1P1nPhi2*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.))
10332                     + 4.*sinP1nPsi1P1nPhi2*cosP1nPhi*sinP1nPhi
10333                     + 4.*twoPrime*(pow(cosP1nPhi,2.)+pow(sinP1nPhi,2.))
10334                     - 6.*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.)) 
10335                     * (cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
10336                     - 12.*cosP1nPhi*sinP1nPhi
10337                     * (sinP1nPsi*cosP1nPhi+cosP1nPsi*sinP1nPhi);
10338   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime);   
10339  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
10340  
10341 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
10342
10343
10344 //==================================================================================================================================
10345     
10346
10347 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
10348 {
10349  // Calculate differential flow corrected for non-uniform acceptance.
10350  
10351  // to be improved (rewritten completely)
10352  
10353  Int_t typeFlag = 0;
10354  Int_t ptEtaFlag = 0;
10355
10356  if(type == "RP")
10357  {
10358   typeFlag = 0;
10359  } else if(type == "POI")
10360    {
10361     typeFlag = 1;
10362    } 
10363      
10364  if(ptOrEta == "Pt")
10365  {
10366   ptEtaFlag = 0;
10367  } else if(ptOrEta == "Eta")
10368    {
10369     ptEtaFlag = 1;
10370    } 
10371   
10372  // shortcuts:
10373  Int_t t = typeFlag;
10374  Int_t pe = ptEtaFlag;
10375      
10376  // common:
10377  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10378    
10379  // to be improved: access here generalized QC{2} and QC{4} instead: 
10380  Double_t dV2 = fIntFlow->GetBinContent(1); 
10381  Double_t dV4 = fIntFlow->GetBinContent(2); 
10382  
10383  // loop over pt or eta bins:
10384  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10385  {
10386   // generalized QC{2'}:
10387   Double_t gQC2Prime = fDiffFlowCumulants[t][pe][0]->GetBinContent(b);
10388   // v'{2}:
10389   if(dV2>0)
10390   { 
10391    Double_t v2Prime = gQC2Prime/dV2;
10392    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
10393   }  
10394   // generalized QC{4'}:
10395   Double_t gQC4Prime = fDiffFlowCumulants[t][pe][1]->GetBinContent(b);
10396   // v'{4}:
10397   if(dV4>0)
10398   { 
10399    Double_t v4Prime = -gQC4Prime/pow(dV4,3.);
10400    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime); 
10401   }  
10402  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
10403   
10404 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta); 
10405
10406
10407 //==================================================================================================================================
10408
10409
10410 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent)
10411 {
10412  // Evaluate with nested loops multiparticle correlations for integrated flow (without using the particle weights). 
10413
10414  // Remark: Results are stored in profile fIntFlowDirectCorrelations whose binning is organized as follows:
10415  // 
10416  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
10417  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
10418  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
10419  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
10420  //  5th bin:           ----  EMPTY ----
10421  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
10422  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
10423  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
10424  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
10425  // 10th bin:           ----  EMPTY ----
10426  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
10427  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
10428  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
10429  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
10430  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
10431  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
10432  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
10433  // 18th bin:           ----  EMPTY ----
10434  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
10435  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
10436  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
10437  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
10438  // 23rd bin:           ----  EMPTY ----
10439  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
10440  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
10441  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
10442  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
10443  // 28th bin:           ----  EMPTY ----
10444  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
10445  // 30th bin:           ----  EMPTY ----
10446  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
10447  // 32nd bin:           ----  EMPTY ----
10448  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
10449  // 34th bin: <5>_{2n,2n,2n|3n,3n} = five2n2n2n3n3n = <cos(n*(2.*phi1+2.*phi2+2.*phi3-3.*phi4-3.*phi5))> 
10450   
10451  Int_t nPrim = anEvent->NumberOfTracks(); 
10452  AliFlowTrackSimple *aftsTrack = NULL; 
10453  Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.; 
10454  Int_t n = fHarmonic; 
10455  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
10456  Double_t dMult = (*fSMpk)(0,0);
10457  cout<<endl;
10458  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
10459  if(dMult<2)
10460  {
10461   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
10462  } else if (dMult>fMaxAllowedMultiplicity)
10463    {
10464     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
10465    } else 
10466      { 
10467       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
10468      } 
10469  
10470  // 2-particle correlations:       
10471  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10472  {
10473   for(Int_t i1=0;i1<nPrim;i1++)
10474   {
10475    aftsTrack=anEvent->GetTrack(i1);
10476    if(!(aftsTrack->InRPSelection())) continue;
10477    phi1=aftsTrack->Phi(); 
10478    for(Int_t i2=0;i2<nPrim;i2++)
10479    {
10480     if(i2==i1)continue;
10481     aftsTrack=anEvent->GetTrack(i2);
10482     if(!(aftsTrack->InRPSelection())) continue;
10483     phi2=aftsTrack->Phi();
10484     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10485     // fill the profile with 2-p correlations: 
10486     fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),1.);    // <cos(n*(phi1-phi2))>
10487     fIntFlowDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),1.); // <cos(2n*(phi1-phi2))>
10488     fIntFlowDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),1.); // <cos(3n*(phi1-phi2))>
10489     fIntFlowDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),1.); // <cos(4n*(phi1-phi2))>   
10490    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10491   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10492  } // end of if(nPrim>=2)
10493  
10494  // 3-particle correlations:         
10495  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10496  {
10497   for(Int_t i1=0;i1<nPrim;i1++)
10498   {
10499    aftsTrack=anEvent->GetTrack(i1);
10500    if(!(aftsTrack->InRPSelection())) continue;
10501    phi1=aftsTrack->Phi();
10502    for(Int_t i2=0;i2<nPrim;i2++)
10503    {
10504     if(i2==i1)continue;
10505     aftsTrack=anEvent->GetTrack(i2);
10506     if(!(aftsTrack->InRPSelection())) continue;
10507     phi2=aftsTrack->Phi();
10508     for(Int_t i3=0;i3<nPrim;i3++)
10509     {
10510      if(i3==i1||i3==i2)continue;
10511      aftsTrack=anEvent->GetTrack(i3);
10512      if(!(aftsTrack->InRPSelection())) continue;
10513      phi3=aftsTrack->Phi();
10514      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
10515      // fill the profile with 3-p correlations:   
10516      fIntFlowDirectCorrelations->Fill(5.,cos(2.*n*phi1-n*(phi2+phi3)),1.);       //<3>_{2n|nn,n}
10517      fIntFlowDirectCorrelations->Fill(6.,cos(3.*n*phi1-2.*n*phi2-n*phi3),1.);    //<3>_{3n|2n,n}
10518      fIntFlowDirectCorrelations->Fill(7.,cos(4.*n*phi1-2.*n*phi2-2.*n*phi3),1.); //<3>_{4n|2n,2n}
10519      fIntFlowDirectCorrelations->Fill(8.,cos(4.*n*phi1-3.*n*phi2-n*phi3),1.);    //<3>_{4n|3n,n}
10520     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10521    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10522   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10523  } // end of if(nPrim>=3)
10524
10525  // 4-particle correlations:
10526  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
10527  {       
10528   for(Int_t i1=0;i1<nPrim;i1++)
10529   { 
10530    aftsTrack=anEvent->GetTrack(i1);
10531    if(!(aftsTrack->InRPSelection())) continue;
10532    phi1=aftsTrack->Phi();
10533    for(Int_t i2=0;i2<nPrim;i2++)
10534    {
10535     if(i2==i1)continue;
10536     aftsTrack=anEvent->GetTrack(i2);
10537     if(!(aftsTrack->InRPSelection())) continue;
10538     phi2=aftsTrack->Phi();
10539     for(Int_t i3=0;i3<nPrim;i3++)
10540     {
10541      if(i3==i1||i3==i2)continue;
10542      aftsTrack=anEvent->GetTrack(i3);
10543      if(!(aftsTrack->InRPSelection())) continue;
10544      phi3=aftsTrack->Phi();
10545      for(Int_t i4=0;i4<nPrim;i4++)
10546      {
10547       if(i4==i1||i4==i2||i4==i3)continue;
10548       aftsTrack=anEvent->GetTrack(i4);
10549       if(!(aftsTrack->InRPSelection())) continue;
10550       phi4=aftsTrack->Phi();
10551       if(nPrim==4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush;
10552       // fill the profile with 4-p correlations:   
10553       fIntFlowDirectCorrelations->Fill(10.,cos(n*phi1+n*phi2-n*phi3-n*phi4),1.);            // <4>_{n,n|n,n} 
10554       fIntFlowDirectCorrelations->Fill(11.,cos(2.*n*phi1+n*phi2-2.*n*phi3-n*phi4),1.);      // <4>_{2n,n|2n,n}
10555       fIntFlowDirectCorrelations->Fill(12.,cos(2.*n*phi1+2*n*phi2-2.*n*phi3-2.*n*phi4),1.); // <4>_{2n,2n|2n,2n}
10556       fIntFlowDirectCorrelations->Fill(13.,cos(3.*n*phi1-n*phi2-n*phi3-n*phi4),1.);         // <4>_{3n|n,n,n}
10557       fIntFlowDirectCorrelations->Fill(14.,cos(3.*n*phi1+n*phi2-3.*n*phi3-n*phi4),1.);      // <4>_{3n,n|3n,n}   
10558       fIntFlowDirectCorrelations->Fill(15.,cos(3.*n*phi1+n*phi2-2.*n*phi3-2.*n*phi4),1.);   // <4>_{3n,n|2n,2n}
10559       fIntFlowDirectCorrelations->Fill(16.,cos(4.*n*phi1-2.*n*phi2-n*phi3-n*phi4),1.);      // <4>_{4n|2n,n,n}     
10560       fIntFlowDirectCorrelations->Fill(32.,cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{4n,2n|3n,3n}      
10561      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
10562     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10563    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10564   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10565  } // end of if(nPrim>=)
10566
10567  // 5-particle correlations:      
10568  if(nPrim>=5 && nPrim<=fMaxAllowedMultiplicity)
10569  {
10570   for(Int_t i1=0;i1<nPrim;i1++)
10571   {
10572    aftsTrack=anEvent->GetTrack(i1);
10573    if(!(aftsTrack->InRPSelection())) continue;  
10574    phi1=aftsTrack->Phi();
10575    for(Int_t i2=0;i2<nPrim;i2++)
10576    {
10577     if(i2==i1)continue;
10578     aftsTrack=anEvent->GetTrack(i2);
10579     if(!(aftsTrack->InRPSelection())) continue;
10580     phi2=aftsTrack->Phi();
10581     for(Int_t i3=0;i3<nPrim;i3++)
10582     {
10583      if(i3==i1||i3==i2)continue;
10584      aftsTrack=anEvent->GetTrack(i3);
10585      if(!(aftsTrack->InRPSelection())) continue;
10586      phi3=aftsTrack->Phi();
10587      for(Int_t i4=0;i4<nPrim;i4++)
10588      {
10589       if(i4==i1||i4==i2||i4==i3)continue;
10590       aftsTrack=anEvent->GetTrack(i4);
10591       if(!(aftsTrack->InRPSelection())) continue;
10592       phi4=aftsTrack->Phi();
10593       for(Int_t i5=0;i5<nPrim;i5++)
10594       {
10595        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10596        aftsTrack=anEvent->GetTrack(i5);
10597        if(!(aftsTrack->InRPSelection())) continue;
10598        phi5=aftsTrack->Phi();
10599        if(nPrim==5) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<"\r"<<flush;
10600        // fill the profile with 5-p correlations:   
10601        fIntFlowDirectCorrelations->Fill(18.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{2n,n|n,n,n}
10602        fIntFlowDirectCorrelations->Fill(19.,cos(2.*n*phi1+2.*n*phi2-2.*n*phi3-n*phi4-n*phi5),1.); //<5>_{2n,2n|2n,n,n}
10603        fIntFlowDirectCorrelations->Fill(20.,cos(3.*n*phi1+n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);    //<5>_{3n,n|2n,n,n}
10604        fIntFlowDirectCorrelations->Fill(21.,cos(4.*n*phi1-n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{4n|n,n,n,n}
10605        fIntFlowDirectCorrelations->Fill(33.,cos(2.*n*phi1+2.*n*phi2+2.*n*phi3-3.*n*phi4-3.*n*phi5),1.);       
10606       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10607      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10608     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10609    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10610   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10611  } // end of if(nPrim>=5)
10612   
10613  // 6-particle correlations:
10614  if(nPrim>=6 && nPrim<=fMaxAllowedMultiplicity)
10615  {
10616   for(Int_t i1=0;i1<nPrim;i1++)
10617   {
10618    aftsTrack=anEvent->GetTrack(i1);
10619    if(!(aftsTrack->InRPSelection())) continue;
10620    phi1=aftsTrack->Phi();
10621    for(Int_t i2=0;i2<nPrim;i2++)
10622    {
10623     if(i2==i1)continue;
10624     aftsTrack=anEvent->GetTrack(i2);
10625     if(!(aftsTrack->InRPSelection())) continue;
10626     phi2=aftsTrack->Phi();
10627     for(Int_t i3=0;i3<nPrim;i3++)
10628     {
10629      if(i3==i1||i3==i2)continue;
10630      aftsTrack=anEvent->GetTrack(i3);
10631      if(!(aftsTrack->InRPSelection())) continue;
10632      phi3=aftsTrack->Phi();
10633      for(Int_t i4=0;i4<nPrim;i4++)
10634      {
10635       if(i4==i1||i4==i2||i4==i3)continue;
10636       aftsTrack=anEvent->GetTrack(i4);
10637       if(!(aftsTrack->InRPSelection())) continue;
10638       phi4=aftsTrack->Phi();
10639       for(Int_t i5=0;i5<nPrim;i5++)
10640       {
10641        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10642        aftsTrack=anEvent->GetTrack(i5);
10643        if(!(aftsTrack->InRPSelection())) continue;
10644        phi5=aftsTrack->Phi();
10645        for(Int_t i6=0;i6<nPrim;i6++)
10646        {
10647         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10648         aftsTrack=anEvent->GetTrack(i6);
10649         if(!(aftsTrack->InRPSelection())) continue;
10650         phi6=aftsTrack->Phi(); 
10651         if(nPrim==6) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<"\r"<<flush;
10652         // fill the profile with 6-p correlations:   
10653         fIntFlowDirectCorrelations->Fill(23.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),1.);       //<6>_{n,n,n|n,n,n}
10654         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}
10655         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}
10656         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}  
10657        } // end of for(Int_t i6=0;i6<nPrim;i6++)
10658       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10659      } // end of for(Int_t i4=0;i4<nPrim;i4++)
10660     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10661    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10662   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10663  } // end of if(nPrim>=6)
10664   
10665  // 7-particle correlations:
10666  if(nPrim>=7 && nPrim<=fMaxAllowedMultiplicity)
10667  {
10668   for(Int_t i1=0;i1<nPrim;i1++)
10669   { 
10670    aftsTrack=anEvent->GetTrack(i1);
10671    if(!(aftsTrack->InRPSelection())) continue;
10672    phi1=aftsTrack->Phi();
10673    for(Int_t i2=0;i2<nPrim;i2++)
10674    {
10675     if(i2==i1)continue;
10676     aftsTrack=anEvent->GetTrack(i2);
10677     if(!(aftsTrack->InRPSelection())) continue;
10678     phi2=aftsTrack->Phi();
10679     for(Int_t i3=0;i3<nPrim;i3++)
10680     {
10681      if(i3==i1||i3==i2)continue;
10682      aftsTrack=anEvent->GetTrack(i3);
10683      if(!(aftsTrack->InRPSelection())) continue;
10684      phi3=aftsTrack->Phi();
10685      for(Int_t i4=0;i4<nPrim;i4++)
10686      {
10687       if(i4==i1||i4==i2||i4==i3)continue;
10688       aftsTrack=anEvent->GetTrack(i4);
10689       if(!(aftsTrack->InRPSelection())) continue;
10690       phi4=aftsTrack->Phi();
10691       for(Int_t i5=0;i5<nPrim;i5++)
10692       {
10693        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10694        aftsTrack=anEvent->GetTrack(i5);
10695        if(!(aftsTrack->InRPSelection())) continue;
10696        phi5=aftsTrack->Phi();
10697        for(Int_t i6=0;i6<nPrim;i6++)
10698        {
10699         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10700         aftsTrack=anEvent->GetTrack(i6);
10701         if(!(aftsTrack->InRPSelection())) continue;
10702         phi6=aftsTrack->Phi(); 
10703         for(Int_t i7=0;i7<nPrim;i7++)
10704         {
10705          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
10706          aftsTrack=anEvent->GetTrack(i7);
10707          if(!(aftsTrack->InRPSelection())) continue;
10708          phi7=aftsTrack->Phi(); 
10709          if(nPrim==7) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<"\r"<<flush;
10710          // fill the profile with 7-p correlation:   
10711          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}
10712         } // end of for(Int_t i7=0;i7<nPrim;i7++)
10713        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
10714       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10715      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10716     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10717    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10718   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10719  } // end of if(nPrim>=7)
10720  
10721  // 8-particle correlations:
10722  if(nPrim>=8 && nPrim<=fMaxAllowedMultiplicity)
10723  {
10724   for(Int_t i1=0;i1<nPrim;i1++)
10725   {
10726    aftsTrack=anEvent->GetTrack(i1);
10727    if(!(aftsTrack->InRPSelection())) continue;
10728    phi1=aftsTrack->Phi();
10729    for(Int_t i2=0;i2<nPrim;i2++)
10730    {
10731     if(i2==i1)continue;
10732     aftsTrack=anEvent->GetTrack(i2);
10733     if(!(aftsTrack->InRPSelection())) continue;
10734     phi2=aftsTrack->Phi();
10735     for(Int_t i3=0;i3<nPrim;i3++)
10736     {
10737      if(i3==i1||i3==i2)continue;
10738      aftsTrack=anEvent->GetTrack(i3);
10739      if(!(aftsTrack->InRPSelection())) continue;
10740      phi3=aftsTrack->Phi();
10741      for(Int_t i4=0;i4<nPrim;i4++)
10742      {
10743       if(i4==i1||i4==i2||i4==i3)continue;
10744       aftsTrack=anEvent->GetTrack(i4);
10745       if(!(aftsTrack->InRPSelection())) continue;
10746       phi4=aftsTrack->Phi();
10747       for(Int_t i5=0;i5<nPrim;i5++)
10748       {
10749        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10750        aftsTrack=anEvent->GetTrack(i5);
10751        if(!(aftsTrack->InRPSelection())) continue;
10752        phi5=aftsTrack->Phi();
10753        for(Int_t i6=0;i6<nPrim;i6++)
10754        {
10755         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10756         aftsTrack=anEvent->GetTrack(i6);
10757         if(!(aftsTrack->InRPSelection())) continue;
10758         phi6=aftsTrack->Phi();
10759         for(Int_t i7=0;i7<nPrim;i7++)
10760         {
10761          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
10762          aftsTrack=anEvent->GetTrack(i7);
10763          if(!(aftsTrack->InRPSelection())) continue;
10764          phi7=aftsTrack->Phi();
10765          for(Int_t i8=0;i8<nPrim;i8++)
10766          {
10767           if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
10768           aftsTrack=anEvent->GetTrack(i8);
10769           if(!(aftsTrack->InRPSelection())) continue;
10770           phi8=aftsTrack->Phi();
10771           cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<" "<<i8<<"\r"<<flush;
10772           // fill the profile with 8-p correlation:   
10773           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}
10774          } // end of for(Int_t i8=0;i8<nPrim;i8++)
10775         } // end of for(Int_t i7=0;i7<nPrim;i7++) 
10776        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
10777       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10778      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10779     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10780    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10781   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10782  } // end of if(nPrim>=8)
10783  
10784  cout<<endl;
10785
10786 } // end of AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent)
10787
10788
10789 //==================================================================================================================================
10790
10791
10792 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
10793 {
10794  // Cross-check results for multiparticle correlations needed for int. flow: results from Q-vectors vs results from nested loops.
10795
10796  cout<<endl;
10797  cout<<endl;
10798  cout<<"   *****************************************"<<endl;
10799  cout<<"   **** cross-checking the correlations ****"<<endl;
10800  cout<<"   ****       for integrated flow       ****"<<endl;
10801  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
10802  {
10803   cout<<"   ****   (particle weights not used)   ****"<<endl;
10804  } else
10805    {
10806     cout<<"   ****     (particle weights used)     ****"<<endl;
10807    } 
10808  cout<<"   *****************************************"<<endl;
10809  cout<<endl;
10810  cout<<endl;
10811
10812  Int_t ciMax = 34; // to be improved (removed eventually when I calculate 6th and 8th order with particle weights)
10813  
10814  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
10815  {
10816   ciMax = 11;
10817  }
10818
10819  for(Int_t ci=1;ci<=ciMax;ci++)
10820  {
10821   if(strcmp((fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
10822   cout<<(fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
10823   cout<<"from Q-vectors    = "<<fIntFlowCorrelationsAllPro->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
10824   cout<<"from nested loops = "<<fIntFlowDirectCorrelations->GetBinContent(ci)<<endl;
10825   cout<<endl;
10826  }
10827   
10828 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
10829
10830
10831 //================================================================================================================================
10832
10833
10834 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA()
10835 {
10836  // Cross-check results for corrections terms for non-uniform acceptance needed for int. flow: results from Q-vectors vs results from nested loops.
10837
10838  cout<<endl;
10839  cout<<endl;
10840  cout<<"   *********************************************"<<endl;
10841  cout<<"   **** cross-checking the correction terms ****"<<endl;
10842  cout<<"   **** for non-uniform acceptance relevant ****"<<endl;
10843  cout<<"   ****         for integrated flow         ****"<<endl;
10844  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
10845  {
10846   cout<<"   ****     (particle weights not used)     ****"<<endl;
10847  } else
10848    {
10849     cout<<"   ****       (particle weights used)       ****"<<endl;
10850    } 
10851  cout<<"   *********************************************"<<endl;
10852  cout<<endl;
10853  cout<<endl;
10854
10855  for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
10856  {
10857   for(Int_t sc=0;sc<2;sc++) // sin or cos term
10858   {
10859    if(strcmp((fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
10860    cout<<(fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
10861    cout<<"from Q-vectors    = "<<fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
10862    cout<<"from nested loops = "<<fIntFlowDirectCorrectionTermsForNUA[sc]->GetBinContent(ci)<<endl;
10863    cout<<endl;
10864   } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos term
10865  } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
10866   
10867 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA() 
10868
10869
10870 //================================================================================================================================
10871
10872
10873 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
10874 {
10875  // Evaluate with nested loops multiparticle correlations for integrated flow (using the particle weights). 
10876
10877  // Results are stored in profile fIntFlowDirectCorrelations. 
10878  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrelations is organized as follows:
10879  //
10880  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
10881  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
10882  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
10883  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
10884  //  5th bin:           ----  EMPTY ----
10885  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
10886  //  7th bin: <3>_{3n|2n,1n} = ...
10887  //  8th bin: <3>_{4n|2n,2n} = ...
10888  //  9th bin: <3>_{4n|3n,1n} = ...
10889  // 10th bin:           ----  EMPTY ----
10890  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
10891  // 12th bin: <4>_{2n,1n|2n,1n} = ...
10892  // 13th bin: <4>_{2n,2n|2n,2n} = ...
10893  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
10894  // 15th bin: <4>_{3n,1n|3n,1n} = ...
10895  // 16th bin: <4>_{3n,1n|2n,2n} = ...
10896  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
10897  // 18th bin:           ----  EMPTY ----
10898  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
10899  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
10900  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
10901  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
10902  // 23rd bin:           ----  EMPTY ----
10903  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
10904  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
10905  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
10906  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
10907  // 28th bin:           ----  EMPTY ----
10908  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
10909  // 30th bin:           ----  EMPTY ----
10910  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
10911  
10912  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
10913  // fIntFlowExtraDirectCorrelations binning of which is organized as follows:
10914  
10915  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
10916  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
10917  // ...
10918  
10919  Int_t nPrim = anEvent->NumberOfTracks(); 
10920  AliFlowTrackSimple *aftsTrack = NULL;
10921  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
10922  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
10923  Double_t phi1=0., phi2=0., phi3=0., phi4=0.;
10924  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1.;
10925  Int_t n = fHarmonic; 
10926  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
10927  Double_t dMult = (*fSMpk)(0,0);
10928  cout<<endl;
10929  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
10930  if(dMult<2)
10931  {
10932   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
10933  } else if (dMult>fMaxAllowedMultiplicity)
10934    {
10935     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
10936    } else 
10937      { 
10938       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
10939      } 
10940       
10941  // 2-particle correlations:       
10942  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10943  {
10944   // 2 nested loops multiparticle correlations using particle weights:       
10945   for(Int_t i1=0;i1<nPrim;i1++)
10946   {
10947    aftsTrack=anEvent->GetTrack(i1);
10948    if(!(aftsTrack->InRPSelection())) continue;
10949    phi1=aftsTrack->Phi();
10950    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10951    for(Int_t i2=0;i2<nPrim;i2++)
10952    {
10953     if(i2==i1)continue;
10954     aftsTrack=anEvent->GetTrack(i2);
10955     if(!(aftsTrack->InRPSelection())) continue;
10956     phi2=aftsTrack->Phi();
10957     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
10958     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10959     // 2-p correlations using particle weights:
10960     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),wPhi1*wPhi2);                  // <w1   w2   cos( n*(phi1-phi2))>
10961     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))>
10962     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))>
10963     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))> 
10964     // extra correlations: 
10965     // 2-p extra correlations (do not appear if particle weights are not used):
10966     if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),pow(wPhi1,3)*wPhi2); // <w1^3 w2 cos(n*(phi1-phi2))>
10967     // ...
10968    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10969   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10970  } // end of if(nPrim>=2)
10971
10972  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10973  { 
10974   // 3 nested loops multiparticle correlations using particle weights:       
10975   for(Int_t i1=0;i1<nPrim;i1++)
10976   {
10977    aftsTrack=anEvent->GetTrack(i1);
10978    if(!(aftsTrack->InRPSelection())) continue;
10979    phi1=aftsTrack->Phi();
10980    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10981    for(Int_t i2=0;i2<nPrim;i2++)
10982    {
10983     if(i2==i1)continue;
10984     aftsTrack=anEvent->GetTrack(i2);
10985     if(!(aftsTrack->InRPSelection())) continue;
10986     phi2=aftsTrack->Phi();
10987     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
10988     for(Int_t i3=0;i3<nPrim;i3++)
10989     {
10990      if(i3==i1||i3==i2)continue;
10991      aftsTrack=anEvent->GetTrack(i3);
10992      if(!(aftsTrack->InRPSelection())) continue;
10993      phi3=aftsTrack->Phi();
10994      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
10995      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
10996      // 3-p correlations using particle weights:
10997      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))>
10998      // ...
10999      // extra correlations: 
11000      // 2-p extra correlations (do not appear if particle weights are not used):
11001       if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(1.5,cos(n*(phi1-phi2)),wPhi1*wPhi2*pow(wPhi3,2)); // <w1 w2 w3^2 cos(n*(phi1-phi2))>
11002      // ...
11003      // 3-p extra correlations (do not appear if particle weights are not used):
11004      // ...
11005     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11006    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11007   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11008  } // end of if(nPrim>=3)
11009  
11010  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
11011  {
11012   // 4 nested loops multiparticle correlations using particle weights:       
11013   for(Int_t i1=0;i1<nPrim;i1++)
11014   {
11015    aftsTrack=anEvent->GetTrack(i1);
11016    if(!(aftsTrack->InRPSelection())) continue;
11017    phi1=aftsTrack->Phi();
11018    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11019    for(Int_t i2=0;i2<nPrim;i2++)
11020    {
11021     if(i2==i1)continue;
11022     aftsTrack=anEvent->GetTrack(i2);
11023     if(!(aftsTrack->InRPSelection())) continue;
11024     phi2=aftsTrack->Phi();
11025     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11026     for(Int_t i3=0;i3<nPrim;i3++)
11027     {
11028      if(i3==i1||i3==i2)continue;
11029      aftsTrack=anEvent->GetTrack(i3);
11030      if(!(aftsTrack->InRPSelection())) continue;
11031      phi3=aftsTrack->Phi();
11032      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11033      for(Int_t i4=0;i4<nPrim;i4++)
11034      {
11035       if(i4==i1||i4==i2||i4==i3)continue;
11036       aftsTrack=anEvent->GetTrack(i4);
11037       if(!(aftsTrack->InRPSelection())) continue;
11038       phi4=aftsTrack->Phi();
11039       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
11040       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
11041       // 4-p correlations using particle weights:
11042       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
11043       // extra correlations: 
11044       // 2-p extra correlations (do not appear if particle weights are not used):
11045       // ...
11046       // 3-p extra correlations (do not appear if particle weights are not used):
11047       // ...
11048       // 4-p extra correlations (do not appear if particle weights are not used):
11049       // ...
11050      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
11051     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11052    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11053   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11054  } // end of if(nPrim>=4)
11055
11056  cout<<endl; 
11057
11058 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
11059
11060
11061 //================================================================================================================================
11062
11063
11064 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
11065 {
11066  // Cross-check results for extra multiparticle correlations needed for int. flow 
11067  // which appear only when particle weights are used: results from Q-vectors vs results from nested loops.
11068
11069  cout<<endl;
11070  cout<<endl;
11071  cout<<"   ***********************************************"<<endl;
11072  cout<<"   **** cross-checking the extra correlations ****"<<endl;
11073  cout<<"   ****          for integrated flow          ****"<<endl;
11074  cout<<"   ***********************************************"<<endl;
11075  cout<<endl;
11076  cout<<endl;
11077  
11078  for(Int_t eci=1;eci<=2;eci++) // to be improved (increased eciMax eventually when I calculate 6th and 8th)
11079  {
11080   if(strcmp((fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci), "") == 0) continue;
11081   cout<<(fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci)<<":"<<endl;
11082   cout<<"from Q-vectors    = "<<fIntFlowExtraCorrelationsPro->GetBinContent(eci)<<endl;
11083   cout<<"from nested loops = "<<fIntFlowExtraDirectCorrelations->GetBinContent(eci)<<endl;
11084   cout<<endl;
11085  }
11086
11087 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
11088
11089
11090 //================================================================================================================================
11091
11092
11093 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent)
11094 {
11095  // Evaluate with nested loops correction terms for non-uniform acceptance relevant for NONAME integrated flow (to be improved (name)).
11096  //
11097  // Remark: Both sin and cos correction terms are calculated in this method. Sin terms are stored in fIntFlowDirectCorrectionTermsForNUA[0],
11098  // and cos terms in fIntFlowDirectCorrectionTermsForNUA[1]. Binning of fIntFlowDirectCorrectionTermsForNUA[sc] is organized as follows 
11099  // (sc stands for either sin or cos):
11100  
11101  //  1st bin: <<sc(n*(phi1))>> 
11102  //  2nd bin: <<sc(n*(phi1+phi2))>> 
11103  //  3rd bin: <<sc(n*(phi1-phi2-phi3))>>
11104  //  4th bin: <<sc(n*(2phi1-phi2))>>
11105  
11106  Int_t nPrim = anEvent->NumberOfTracks(); 
11107  AliFlowTrackSimple *aftsTrack = NULL;
11108  Double_t phi1=0., phi2=0., phi3=0.;
11109  Int_t n = fHarmonic; 
11110  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
11111  Double_t dMult = (*fSMpk)(0,0);
11112  cout<<endl;
11113  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
11114  if(dMult<1)
11115  {
11116   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
11117  } else if (dMult>fMaxAllowedMultiplicity)
11118    {
11119     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
11120    } else 
11121      { 
11122       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
11123      }
11124  
11125  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
11126  {
11127   // 1-particle correction terms for non-uniform acceptance:       
11128   for(Int_t i1=0;i1<nPrim;i1++)
11129   {
11130    aftsTrack=anEvent->GetTrack(i1);
11131    if(!(aftsTrack->InRPSelection())) continue;
11132    phi1=aftsTrack->Phi();
11133    if(nPrim==1) cout<<i1<<"\r"<<flush;
11134    // sin terms:
11135    fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),1.); // <sin(n*phi1)>  
11136    // cos terms:
11137    fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),1.); // <cos(n*phi1)>
11138   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11139  } // end of if(nPrim>=1) 
11140   
11141  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
11142  {
11143   // 2-particle correction terms for non-uniform acceptance:       
11144   for(Int_t i1=0;i1<nPrim;i1++)
11145   {
11146    aftsTrack=anEvent->GetTrack(i1);
11147    if(!(aftsTrack->InRPSelection())) continue;
11148    phi1=aftsTrack->Phi();  
11149    for(Int_t i2=0;i2<nPrim;i2++)
11150    {
11151     if(i2==i1)continue;
11152     aftsTrack=anEvent->GetTrack(i2);
11153     if(!(aftsTrack->InRPSelection())) continue;
11154     phi2=aftsTrack->Phi();
11155     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
11156     // sin terms:
11157     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),1.); // <<sin(n*(phi1+phi2))>>
11158     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(3.5,sin(n*(2*phi1-phi2)),1.); // <<sin(n*(2*phi1-phi2))>>
11159     // cos terms:
11160     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),1.); // <<cos(n*(phi1+phi2))>>
11161     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(3.5,cos(n*(2*phi1-phi2)),1.); // <<cos(n*(2*phi1-phi2))>>
11162    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11163   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11164  } // end of if(nPrim>=2)
11165
11166  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
11167  {
11168   // 3-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     for(Int_t i3=0;i3<nPrim;i3++)
11181     {
11182      if(i3==i1||i3==i2)continue;
11183      aftsTrack=anEvent->GetTrack(i3);
11184      if(!(aftsTrack->InRPSelection())) continue;
11185      phi3=aftsTrack->Phi();
11186      if(nPrim>=3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush; // to be improved (eventually I will change this if statement)
11187      // sin terms:
11188      fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),1.); // <<sin(n*(phi1-phi2-phi3))>>
11189      // cos terms:
11190      fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),1.); // <<cos(n*(phi1-phi2-phi3))>>
11191     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11192    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11193   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11194  } // end of if(nPrim>=3)
11195
11196  cout<<endl;
11197 }
11198 //================================================================================================================================
11199 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11200 {
11201  // Evaluate reduced correlations with nested loops without using the particle weights.
11202  
11203  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11204  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
11205  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
11206  // Remark 3: <2'> = <cos(n*(psi1-phi2))>
11207  //           <4'> = <cos(n*(psi1+phi2-phi3-phi4))>
11208  // ...
11209  
11210  Int_t typeFlag = 0;
11211  Int_t ptEtaFlag = 0;
11212  if(type == "RP")
11213  {
11214   typeFlag = 0;
11215  } else if(type == "POI")
11216    {
11217     typeFlag = 1;
11218    }      
11219  if(ptOrEta == "Pt")
11220  {
11221   ptEtaFlag = 0;
11222  } else if(ptOrEta == "Eta")
11223    {
11224     ptEtaFlag = 1;
11225    } 
11226  // shortcuts:
11227  Int_t t = typeFlag;
11228  Int_t pe = ptEtaFlag;
11229       
11230  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11231  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11232  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11233  
11234  Int_t nPrim = anEvent->NumberOfTracks(); 
11235  AliFlowTrackSimple *aftsTrack = NULL;
11236  
11237  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11238  
11239  Int_t n = fHarmonic; 
11240   
11241  // 2'-particle correlations:
11242  for(Int_t i1=0;i1<nPrim;i1++)
11243  {
11244   aftsTrack=anEvent->GetTrack(i1);
11245   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11246   if(typeFlag==1) // this is diff flow of POIs 
11247   {
11248    if(ptOrEta == "Pt")
11249    { 
11250     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11251    } else if (ptOrEta == "Eta")
11252      {
11253       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11254      }
11255   } else // this is diff flow of RPs 
11256     {
11257      if(ptOrEta == "Pt")
11258      { 
11259       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11260      } else if (ptOrEta == "Eta")
11261        {
11262         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11263        }
11264     }
11265        
11266   psi1=aftsTrack->Phi(); 
11267   for(Int_t i2=0;i2<nPrim;i2++)
11268   {
11269    if(i2==i1)continue;
11270    aftsTrack=anEvent->GetTrack(i2);
11271    // RP condition (!(first) particle in the correlator must be RP):
11272    if(!(aftsTrack->InRPSelection()))continue;
11273    phi2=aftsTrack->Phi();   
11274    // 2'-particle correlations: 
11275    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),1.); // <cos(n*(psi1-phi2))  
11276   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11277  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11278  
11279  /*
11280  
11281  // 3'-particle correlations:
11282  for(Int_t i1=0;i1<nPrim;i1++)
11283  {
11284   aftsTrack=anEvent->GetTrack(i1);
11285   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11286   if(ptOrEta == "Pt")
11287   { 
11288    if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11289   } else if (ptOrEta == "Eta")
11290     {
11291      if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11292     }
11293   psi1=aftsTrack->Phi();
11294   for(Int_t i2=0;i2<nPrim;i2++)
11295   {
11296    if(i2==i1)continue;
11297    aftsTrack=anEvent->GetTrack(i2);
11298    // RP condition (!(first) particle in the correlator must be RP):
11299    if(!(aftsTrack->InRPSelection())) continue;
11300    phi2=aftsTrack->Phi();
11301    for(Int_t i3=0;i3<nPrim;i3++)
11302    {
11303     if(i3==i1||i3==i2)continue;
11304     aftsTrack=anEvent->GetTrack(i3);
11305     // RP condition (!(first) particle in the correlator must be RP):
11306     if(!(aftsTrack->InRPSelection())) continue;
11307     phi3=aftsTrack->Phi();
11308     // 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))> 
11309    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
11310   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
11311  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11312  
11313  */
11314  
11315  // 4'-particle correlations:
11316  for(Int_t i1=0;i1<nPrim;i1++)
11317  {
11318   aftsTrack=anEvent->GetTrack(i1);
11319   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11320   if(typeFlag==1) // this is diff flow of POIs 
11321   {
11322    if(ptOrEta == "Pt")
11323    { 
11324     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11325    } else if (ptOrEta == "Eta")
11326      {
11327       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11328      }
11329   } else // this is diff flow of RPs 
11330     {
11331      if(ptOrEta == "Pt")
11332      { 
11333       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11334      } else if (ptOrEta == "Eta")
11335        {
11336         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11337        }
11338     }
11339     
11340   psi1=aftsTrack->Phi();
11341   for(Int_t i2=0;i2<nPrim;i2++)
11342   {
11343    if(i2==i1) continue;
11344    aftsTrack=anEvent->GetTrack(i2);
11345    // RP condition (!(first) particle in the correlator must be RP): 
11346    if(!(aftsTrack->InRPSelection())) continue;
11347    phi2=aftsTrack->Phi();
11348    for(Int_t i3=0;i3<nPrim;i3++)
11349    { 
11350     if(i3==i1||i3==i2) continue;
11351     aftsTrack=anEvent->GetTrack(i3);
11352     // RP condition (!(first) particle in the correlator must be RP):
11353     if(!(aftsTrack->InRPSelection())) continue;
11354     phi3=aftsTrack->Phi();
11355     for(Int_t i4=0;i4<nPrim;i4++)
11356     {
11357      if(i4==i1||i4==i2||i4==i3) continue;
11358      aftsTrack=anEvent->GetTrack(i4);
11359      // RP condition (!(first) particle in the correlator must be RP):
11360      if(!(aftsTrack->InRPSelection())) continue;  
11361      phi4=aftsTrack->Phi();
11362      // 4'-particle correlations:
11363      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),1.); // <cos(n(psi1+phi2-phi3-phi4))>     
11364     }//end of for(Int_t i4=0;i4<nPrim;i4++)
11365    }//end of for(Int_t i3=0;i3<nPrim;i3++)
11366   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
11367  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11368       
11369  // count # of RPs and POIs in selected pt and eta bins for cross-checkings:
11370  for(Int_t i=0;i<nPrim;i++)
11371  {
11372   aftsTrack=anEvent->GetTrack(i); 
11373   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11374   if(typeFlag==1) // this is diff flow of POIs 
11375   {
11376    if(ptOrEta == "Pt")
11377    { 
11378     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11379    } else if (ptOrEta == "Eta")
11380      {
11381       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11382      }
11383   } else // this is diff flow of RPs 
11384     {
11385      if(ptOrEta == "Pt")
11386      { 
11387       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11388      } else if (ptOrEta == "Eta")
11389        {
11390         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11391        }
11392     }
11393   if(t==1)t++; 
11394   fNoOfParticlesInBin->Fill(t+pe+0.5);  
11395  }
11396
11397 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11398
11399
11400 //================================================================================================================================
11401
11402
11403 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
11404 {
11405  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
11406  
11407  Int_t typeFlag = 0;
11408  Int_t ptEtaFlag = 0;
11409  if(type == "RP")
11410  {
11411   typeFlag = 0;
11412  } else if(type == "POI")
11413    {
11414     typeFlag = 1;
11415    }      
11416  if(ptOrEta == "Pt")
11417  {
11418   ptEtaFlag = 0;
11419  } else if(ptOrEta == "Eta")
11420    {
11421     ptEtaFlag = 1;
11422    } 
11423  // shortcuts:
11424  Int_t t = typeFlag;
11425  Int_t pe = ptEtaFlag;
11426       
11427  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11428  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11429  TString reducedCorrelations[4] = {"<<cos(n(psi1-phi2))>>","<<cos(n(psi1+phi2-phi3-phi4))>>","",""}; // to be improved (access this from pro or hist)
11430  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11431  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11432  
11433  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
11434  
11435
11436  cout<<endl;
11437  cout<<"   *****************************************"<<endl;
11438  cout<<"   **** cross-checking the correlations ****"<<endl;
11439  cout<<"   ****   for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
11440  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
11441  {
11442   cout<<"   ****   (particle weights not used)   ****"<<endl;
11443  } else
11444    {
11445     cout<<"   ****    (particle weights used)      ****"<<endl;
11446    } 
11447  cout<<"   *****************************************"<<endl; 
11448  cout<<endl;
11449  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
11450  cout<<endl;
11451  
11452  for(Int_t rci=0;rci<2;rci++) // to be improved (calculate 6th and 8th order)
11453  {
11454   cout<<"      "<<reducedCorrelations[rci].Data()<<":"<<endl;
11455   cout<<"      from Q-vectors    = "<<fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
11456   cout<<"      from nested loops = "<<fDiffFlowDirectCorrelations[t][pe][rci]->GetBinContent(1)<<endl;
11457   cout<<endl;  
11458  } // end of for(Int_t rci=0;rci<4;rci++)
11459         
11460 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
11461
11462 //================================================================================================================================
11463
11464 void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
11465 {
11466  // Print on the screen number of RPs and POIs in selected pt and eta bin for cross checkings.
11467  
11468  cout<<endl;
11469  cout<<"Number of RPs in selected pt bin   = "<<fNoOfParticlesInBin->GetBinContent(1)<<endl;
11470  cout<<"Number of RPs in selected eta bin  = "<<fNoOfParticlesInBin->GetBinContent(2)<<endl;
11471  cout<<"Number of POIs in selected pt bin  = "<<fNoOfParticlesInBin->GetBinContent(3)<<endl;
11472  cout<<"Number of POIs in selected eta bin = "<<fNoOfParticlesInBin->GetBinContent(4)<<endl;
11473  
11474 } // end of void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
11475
11476 //================================================================================================================================
11477
11478 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11479 {
11480  // Evaluate reduced correlations with nested loops without using the particle weights.
11481  
11482  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11483  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
11484  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
11485  // Remark 3: <2'> = <w2 cos(n*(psi1-phi2))>
11486  //           <4'> = <w2 w3 w4 cos(n*(psi1+phi2-phi3-phi4))>
11487  // ...
11488   
11489  Int_t typeFlag = 0;
11490  Int_t ptEtaFlag = 0;
11491  if(type == "RP")
11492  {
11493   typeFlag = 0;
11494  } else if(type == "POI")
11495    {
11496     typeFlag = 1;
11497    }      
11498  if(ptOrEta == "Pt")
11499  {
11500   ptEtaFlag = 0;
11501  } else if(ptOrEta == "Eta")
11502    {
11503     ptEtaFlag = 1;
11504    } 
11505  // shortcuts:
11506  Int_t t = typeFlag;
11507  Int_t pe = ptEtaFlag;
11508       
11509  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11510  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11511  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11512  
11513  Int_t nPrim = anEvent->NumberOfTracks(); 
11514  AliFlowTrackSimple *aftsTrack = NULL;
11515  
11516  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11517  Double_t wPhi2=1., wPhi3=1., wPhi4=1.;// wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
11518  
11519  Int_t n = fHarmonic; 
11520  
11521  // 2'-particle correlations:
11522  for(Int_t i1=0;i1<nPrim;i1++)
11523  {
11524   aftsTrack=anEvent->GetTrack(i1);
11525   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11526   if(typeFlag==1) // this is diff flow of POIs 
11527   {
11528    if(ptOrEta == "Pt")
11529    { 
11530     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11531    } else if (ptOrEta == "Eta")
11532      {
11533       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11534      }
11535   } else // this is diff flow of RPs 
11536     {
11537      if(ptOrEta == "Pt")
11538      { 
11539       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11540      } else if (ptOrEta == "Eta")
11541        {
11542         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11543        }
11544     }
11545   psi1=aftsTrack->Phi(); 
11546   for(Int_t i2=0;i2<nPrim;i2++)
11547   {
11548    if(i2==i1) continue;
11549    aftsTrack=anEvent->GetTrack(i2);
11550    // RP condition (!(first) particle in the correlator must be RP):
11551    if(!(aftsTrack->InRPSelection())) continue;
11552    phi2=aftsTrack->Phi();   
11553    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11554    // 2'-particle correlations: 
11555    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),wPhi2); // <w2 cos(n*(psi1-phi2))  
11556   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11557  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11558  
11559  // 4'-particle correlations:
11560  for(Int_t i1=0;i1<nPrim;i1++)
11561  {
11562   aftsTrack=anEvent->GetTrack(i1);
11563   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11564   if(typeFlag==1) // this is diff flow of POIs 
11565   {
11566    if(ptOrEta == "Pt")
11567    { 
11568     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11569    } else if (ptOrEta == "Eta")
11570      {
11571       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11572      }
11573   } else // this is diff flow of RPs 
11574     {
11575      if(ptOrEta == "Pt")
11576      { 
11577       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11578      } else if (ptOrEta == "Eta")
11579        {
11580         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11581        }
11582     }
11583   psi1=aftsTrack->Phi();
11584   for(Int_t i2=0;i2<nPrim;i2++)
11585   {
11586    if(i2==i1) continue;
11587    aftsTrack=anEvent->GetTrack(i2);
11588    // RP condition (!(first) particle in the correlator must be RP): 
11589    if(!(aftsTrack->InRPSelection())) continue;
11590    phi2=aftsTrack->Phi();
11591    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11592    for(Int_t i3=0;i3<nPrim;i3++)
11593    { 
11594     if(i3==i1||i3==i2) continue;
11595     aftsTrack=anEvent->GetTrack(i3);
11596     // RP condition (!(first) particle in the correlator must be RP):
11597     if(!(aftsTrack->InRPSelection())) continue;
11598     phi3=aftsTrack->Phi();
11599     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11600     for(Int_t i4=0;i4<nPrim;i4++)
11601     {
11602      if(i4==i1||i4==i2||i4==i3) continue;
11603      aftsTrack=anEvent->GetTrack(i4);
11604      // RP condition (!(first) particle in the correlator must be RP):
11605      if(!(aftsTrack->InRPSelection())) continue;  
11606      phi4=aftsTrack->Phi();
11607      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
11608      // 4'-particle correlations <w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))>:
11609      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),wPhi2*wPhi3*wPhi4); 
11610     }//end of for(Int_t i4=0;i4<nPrim;i4++)
11611    }//end of for(Int_t i3=0;i3<nPrim;i3++)
11612   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
11613  }//end of for(Int_t i1=0;i1<nPrim;i1++)      
11614  
11615  // count # of RPs and POIs in selected pt and eta bins for cross-checkings: (to be improved - moved to dedicated method)
11616  for(Int_t i=0;i<nPrim;i++)
11617  {
11618   aftsTrack=anEvent->GetTrack(i); 
11619   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11620   if(typeFlag==1) // this is diff flow of POIs 
11621   {
11622    if(ptOrEta == "Pt")
11623    { 
11624     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11625    } else if (ptOrEta == "Eta")
11626      {
11627       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11628      }
11629   } else // this is diff flow of RPs 
11630     {
11631      if(ptOrEta == "Pt")
11632      { 
11633       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11634      } else if (ptOrEta == "Eta")
11635        {
11636         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11637        }
11638     }
11639   if(t==1)t++; 
11640   fNoOfParticlesInBin->Fill(t+pe+0.5);  
11641  }
11642  
11643 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11644
11645
11646 //================================================================================================================================
11647
11648    
11649 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11650 {
11651  // Evaluate with nested loops correction terms for non-uniform acceptance (both sin and cos terms) relevant for differential flow.
11652  
11653  // Remark 1: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
11654  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11655  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
11656  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
11657  //  cti: 
11658  //    0: <<sc n(psi1)>>
11659  //    1: <<sc n(psi1+phi2)>> 
11660  //    2: <<sc n(psi1+phi2-phi3)>>
11661  //    3: <<sc n(psi1-phi2-phi3)>>
11662  //    4:
11663  //    5:
11664  //    6:
11665   
11666  Int_t typeFlag = 0;
11667  Int_t ptEtaFlag = 0;
11668  if(type == "RP")
11669  {
11670   typeFlag = 0;
11671  } else if(type == "POI")
11672    {
11673     typeFlag = 1;
11674    }      
11675  if(ptOrEta == "Pt")
11676  {
11677   ptEtaFlag = 0;
11678  } else if(ptOrEta == "Eta")
11679    {
11680     ptEtaFlag = 1;
11681    } 
11682  // shortcuts:
11683  Int_t t = typeFlag;
11684  Int_t pe = ptEtaFlag;
11685       
11686  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11687  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11688  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11689  
11690  Int_t nPrim = anEvent->NumberOfTracks(); 
11691  AliFlowTrackSimple *aftsTrack = NULL;
11692  
11693  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11694  
11695  Int_t n = fHarmonic; 
11696  
11697  // 1-particle correction terms:
11698  for(Int_t i1=0;i1<nPrim;i1++)
11699  {
11700   aftsTrack=anEvent->GetTrack(i1);
11701   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11702   if(typeFlag==1) // this is diff flow of POIs 
11703   {
11704    if(ptOrEta == "Pt")
11705    { 
11706     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11707    } else if (ptOrEta == "Eta")
11708      {
11709       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11710      }
11711   } else // this is diff flow of RPs 
11712     {
11713      if(ptOrEta == "Pt")
11714      { 
11715       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11716      } else if (ptOrEta == "Eta")
11717        {
11718         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11719        }
11720     }
11721   psi1=aftsTrack->Phi(); 
11722   // sin terms: 
11723   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
11724   // cos terms: 
11725   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
11726  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11727    
11728  // 2-particle correction terms:
11729  for(Int_t i1=0;i1<nPrim;i1++)
11730  {
11731   aftsTrack=anEvent->GetTrack(i1);
11732    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11733   if(typeFlag==1) // this is diff flow of POIs 
11734   {
11735    if(ptOrEta == "Pt")
11736    { 
11737     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11738    } else if (ptOrEta == "Eta")
11739      {
11740       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11741      }
11742   } else // this is diff flow of RPs 
11743     {
11744      if(ptOrEta == "Pt")
11745      { 
11746       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11747      } else if (ptOrEta == "Eta")
11748        {
11749         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11750        }
11751     }
11752   psi1=aftsTrack->Phi(); 
11753   for(Int_t i2=0;i2<nPrim;i2++)
11754   {
11755    if(i2==i1) continue;
11756    aftsTrack=anEvent->GetTrack(i2);
11757    // RP condition (!(first) particle in the correlator must be RP):
11758    if(!(aftsTrack->InRPSelection())) continue;
11759    phi2=aftsTrack->Phi();   
11760    // sin terms: 
11761    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),1.); // <<sin(n*(psi1+phi2))>>  
11762    // cos terms: 
11763    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),1.); // <<cos(n*(psi1+phi2))>>  
11764   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11765  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
11766  
11767  // 3-particle correction terms:
11768  for(Int_t i1=0;i1<nPrim;i1++)
11769  {
11770   aftsTrack=anEvent->GetTrack(i1);
11771    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11772   if(typeFlag==1) // this is diff flow of POIs 
11773   {
11774    if(ptOrEta == "Pt")
11775    { 
11776     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11777    } else if (ptOrEta == "Eta")
11778      {
11779       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11780      }
11781   } else // this is diff flow of RPs 
11782     {
11783      if(ptOrEta == "Pt")
11784      { 
11785       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11786      } else if (ptOrEta == "Eta")
11787        {
11788         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11789        }
11790     }
11791   psi1=aftsTrack->Phi();
11792   for(Int_t i2=0;i2<nPrim;i2++)
11793   {
11794    if(i2==i1) continue;
11795    aftsTrack=anEvent->GetTrack(i2);
11796    // RP condition (!(first) particle in the correlator must be RP):
11797    if(!(aftsTrack->InRPSelection())) continue;
11798    phi2=aftsTrack->Phi();
11799    for(Int_t i3=0;i3<nPrim;i3++)
11800    {
11801     if(i3==i1||i3==i2) continue;
11802     aftsTrack=anEvent->GetTrack(i3);
11803     // RP condition (!(first) particle in the correlator must be RP):
11804     if(!(aftsTrack->InRPSelection())) continue;
11805     phi3=aftsTrack->Phi();
11806     // sin terms: 
11807     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2-phi3)),1.); // <<sin(n*(psi1+phi2-phi3))>>  
11808     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1-phi2-phi3)),1.); // <<sin(n*(psi1-phi2-phi3))>>  
11809     // cos terms: 
11810     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3)),1.); // <<cos(n*(psi1+phi2-phi3))>>  
11811     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-phi2-phi3)),1.); // <<cos(n*(psi1-phi2-phi3))>>  
11812    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
11813   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
11814  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11815    
11816 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11817
11818
11819 //================================================================================================================================
11820
11821
11822 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
11823 {
11824  // Compare corrections temrs for non-uniform acceptance needed for diff. flow calculated with nested loops and those calculated from Q-vectors
11825  
11826  Int_t typeFlag = 0;
11827  Int_t ptEtaFlag = 0;
11828  if(type == "RP")
11829  {
11830   typeFlag = 0;
11831  } else if(type == "POI")
11832    {
11833     typeFlag = 1;
11834    }      
11835  if(ptOrEta == "Pt")
11836  {
11837   ptEtaFlag = 0;
11838  } else if(ptOrEta == "Eta")
11839    {
11840     ptEtaFlag = 1;
11841    } 
11842  // shortcuts:
11843  Int_t t = typeFlag;
11844  Int_t pe = ptEtaFlag;
11845       
11846  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11847  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11848  //TString sinCosFlag[2] = {"sin","cos"}; // to be improved (eventually promote to data member)
11849  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)
11850  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)
11851  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11852  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11853  
11854  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
11855  
11856  cout<<endl;
11857  cout<<"   ******************************************"<<endl;
11858  cout<<"   ****  cross-checking the correction   ****"<<endl;
11859  cout<<"   **** terms for non-uniform acceptance ****"<<endl; 
11860  cout<<"   ****    for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
11861  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
11862  {
11863   cout<<"   ****    (particle weights not used)   ****"<<endl;
11864  } else
11865    {
11866     cout<<"   ****     (particle weights used)      ****"<<endl;
11867    } 
11868  cout<<"   ******************************************"<<endl; 
11869  cout<<endl;
11870  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
11871  cout<<endl;
11872  
11873  for(Int_t cti=0;cti<4;cti++) // correction term index
11874  {
11875   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
11876   {
11877    if(sc==0) // to be improved (this can be implemented better)
11878    { 
11879     cout<<"      "<<reducedCorrectionSinTerms[cti].Data()<<":"<<endl;
11880    } else
11881      {
11882       cout<<"      "<<reducedCorrectionCosTerms[cti].Data()<<":"<<endl;     
11883      }
11884    cout<<"      from Q-vectors    = "<<fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
11885    cout<<"      from nested loops = "<<fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]->GetBinContent(1)<<endl;
11886    cout<<endl;  
11887   } 
11888  } // end of for(Int_t rci=0;rci<4;rci++)
11889
11890 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
11891
11892
11893 //================================================================================================================================
11894
11895
11896 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
11897 {
11898  // Calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (cos terms).
11899  
11900  //                                  **********************************************************************
11901  //                                  **** weighted corrections for non-uniform acceptance (cos terms): ****
11902  //                                  **********************************************************************
11903  
11904  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
11905  //
11906  // 1st bin: <<w1 cos(n*(phi1))>> = cosP1nW1
11907  // 2nd bin: <<w1 w2 cos(n*(phi1+phi2))>> = cosP1nP1nW1W1
11908  // 3rd bin: <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1nW1W1W1 
11909  // ...
11910
11911  // multiplicity (number of particles used to determine the reaction plane)
11912  Double_t dMult = (*fSMpk)(0,0);
11913  
11914  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
11915  Double_t dReQ1n1k = (*fReQ)(0,1);
11916  Double_t dReQ2n2k = (*fReQ)(1,2);
11917  //Double_t dReQ3n3k = (*fReQ)(2,3);
11918  //Double_t dReQ4n4k = (*fReQ)(3,4);
11919  Double_t dReQ1n3k = (*fReQ)(0,3);
11920  Double_t dImQ1n1k = (*fImQ)(0,1);
11921  Double_t dImQ2n2k = (*fImQ)(1,2);
11922  //Double_t dImQ3n3k = (*fImQ)(2,3);
11923  //Double_t dImQ4n4k = (*fImQ)(3,4);
11924  //Double_t dImQ1n3k = (*fImQ)(0,3);
11925
11926  // dMs are variables introduced in order to simplify some Eqs. bellow:
11927  //..............................................................................................
11928  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
11929  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
11930                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
11931  //..............................................................................................
11932          // 1-particle:
11933  Double_t cosP1nW1 = 0.; // <<w1 cos(n*(phi1))>>
11934    
11935  if(dMult>0 && TMath::Abs((*fSMpk)(0,1))>1e-6)
11936  {
11937   cosP1nW1 = dReQ1n1k/(*fSMpk)(0,1); 
11938   
11939   // average weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
11940   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1nW1);
11941   
11942   // final average weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
11943   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1nW1,(*fSMpk)(0,1));  
11944  } 
11945  
11946  // 2-particle:
11947  Double_t cosP1nP1nW1W1 = 0.; // <<w1 w2 cos(n*(phi1+phi2))>>
11948  
11949  if(dMult>1 && TMath::Abs(dM11)>1e-6)
11950  {
11951   cosP1nP1nW1W1 = (pow(dReQ1n1k,2)-pow(dImQ1n1k,2)-dReQ2n2k)/dM11; 
11952   
11953   // average weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
11954   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1nW1W1);
11955   
11956   // final average weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
11957   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1nW1W1,dM11);  
11958  } 
11959  
11960  // 3-particle:
11961  Double_t cosP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>>
11962  
11963  if(dMult>2 && TMath::Abs(dM111)>1e-6)
11964  {
11965   cosP1nM1nM1nW1W1W1 = (dReQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
11966                      - dReQ1n1k*dReQ2n2k-dImQ1n1k*dImQ2n2k
11967                      - 2.*((*fSMpk)(0,2))*dReQ1n1k
11968                      + 2.*dReQ1n3k) 
11969                      / dM111; 
11970   
11971   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
11972   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1nW1W1W1);
11973   
11974   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
11975   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1nW1W1W1,dM111);  
11976  } 
11977  
11978 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
11979
11980
11981 //================================================================================================================================
11982
11983
11984 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
11985 {
11986  // calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
11987  
11988  //                                  **********************************************************************
11989  //                                  **** weighted corrections for non-uniform acceptance (sin terms): ****
11990  //                                  **********************************************************************
11991  
11992  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
11993  //
11994  // 1st bin: <<w1 sin(n*(phi1))>> = sinP1nW1
11995  // 2nd bin: <<w1 w2 sin(n*(phi1+phi2))>> = sinP1nP1nW1W1
11996  // 3rd bin: <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1nW1W1W1 
11997  // ...
11998
11999  // multiplicity (number of particles used to determine the reaction plane)
12000  Double_t dMult = (*fSMpk)(0,0);
12001  
12002  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
12003  Double_t dReQ1n1k = (*fReQ)(0,1);
12004  Double_t dReQ2n2k = (*fReQ)(1,2);
12005  //Double_t dReQ3n3k = (*fReQ)(2,3);
12006  //Double_t dReQ4n4k = (*fReQ)(3,4);
12007  //Double_t dReQ1n3k = (*fReQ)(0,3);
12008  Double_t dImQ1n1k = (*fImQ)(0,1);
12009  Double_t dImQ2n2k = (*fImQ)(1,2);
12010  //Double_t dImQ3n3k = (*fImQ)(2,3);
12011  //Double_t dImQ4n4k = (*fImQ)(3,4);
12012  Double_t dImQ1n3k = (*fImQ)(0,3);
12013
12014  // dMs are variables introduced in order to simplify some Eqs. bellow:
12015  //..............................................................................................
12016  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
12017  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
12018                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
12019  //..............................................................................................
12020  
12021  // 1-particle:
12022  Double_t sinP1nW1 = 0.; // <<w1 sin(n*(phi1))>>
12023  
12024  if(dMult>0 && TMath::Abs((*fSMpk)(0,1))>1e-6)
12025  {
12026   sinP1nW1 = dImQ1n1k/((*fSMpk)(0,1)); 
12027      
12028   // average weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
12029   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1nW1);
12030   
12031   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
12032   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1nW1,(*fSMpk)(0,1));  
12033  } 
12034  
12035  // 2-particle:
12036  Double_t sinP1nP1nW1W1 = 0.; // <<w1 w2 sin(n*(phi1+phi2))>>
12037  
12038  if(dMult>1 && TMath::Abs(dM11)>1e-6)
12039  {
12040   sinP1nP1nW1W1 = (2.*dReQ1n1k*dImQ1n1k-dImQ2n2k)/dM11; 
12041      
12042   // average weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
12043   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1nW1W1);
12044   
12045   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
12046   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1nW1W1,dM11);  
12047  } 
12048  
12049  // 3-particle:
12050  Double_t sinP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>>
12051  
12052  if(dMult>2 && TMath::Abs(dM111)>1e-6)
12053  {
12054   sinP1nM1nM1nW1W1W1 = (-dImQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
12055                      + dReQ1n1k*dImQ2n2k-dImQ1n1k*dReQ2n2k
12056                      + 2.*((*fSMpk)(0,2))*dImQ1n1k
12057                      - 2.*dImQ1n3k)
12058                      / dM111; 
12059   
12060   // average weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
12061   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1nW1W1W1);
12062   
12063   // final average weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
12064   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1nW1W1W1,dM111);  
12065  } 
12066  
12067 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
12068
12069
12070 //================================================================================================================================
12071
12072
12073 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
12074 {
12075  // Evaluate with nested loops correction terms for non-uniform acceptance for integrated flow (using the particle weights). 
12076
12077  // Results are stored in profiles fIntFlowDirectCorrectionTermsForNUA[0] (sin terms) and
12078  // fIntFlowDirectCorrectionTermsForNUA[1] (cos terms). 
12079  
12080  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrectionTermsForNUA[sc] is 
12081  // organized as follows (sc stands for either sin or cos):
12082  //
12083  // 1st bin: <<w1 sc(n*(phi1))>> = scP1nW1
12084  // 2nd bin: <<w1 w2 sc(n*(phi1+phi2))>> = scP1nP1nW1W1
12085  // 3rd bin: <<w1 w2 w3 sc(n*(phi1-phi2-phi3))>> = scP1nM1nM1nW1W1W1 
12086  // ...
12087   
12088  Int_t nPrim = anEvent->NumberOfTracks(); 
12089  AliFlowTrackSimple *aftsTrack = NULL;
12090  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
12091  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
12092  Double_t phi1=0., phi2=0., phi3=0.;
12093  Double_t wPhi1=1., wPhi2=1., wPhi3=1.;
12094  Int_t n = fHarmonic; 
12095  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
12096  Double_t dMult = (*fSMpk)(0,0);
12097  cout<<endl;
12098  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
12099  if(dMult<1)
12100  {
12101   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
12102  } else if (dMult>fMaxAllowedMultiplicity)
12103    {
12104     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
12105    } else 
12106      { 
12107       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
12108      } 
12109       
12110  // 1-particle correction terms using particle weights:       
12111  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
12112  {
12113   for(Int_t i1=0;i1<nPrim;i1++)
12114   {
12115    aftsTrack=anEvent->GetTrack(i1);
12116    if(!(aftsTrack->InRPSelection())) continue;
12117    phi1=aftsTrack->Phi();
12118    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12119    // 1-particle correction terms using particle weights:
12120    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),wPhi1); // <w1 sin(n*phi1)>
12121    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),wPhi1); // <w1 cos(n*phi1)>
12122   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12123  } // end of if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity) 
12124  
12125  // 2-particle correction terms using particle weights:       
12126  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
12127  {
12128   for(Int_t i1=0;i1<nPrim;i1++)
12129   {
12130    aftsTrack=anEvent->GetTrack(i1);
12131    if(!(aftsTrack->InRPSelection())) continue;
12132    phi1=aftsTrack->Phi();
12133    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12134    for(Int_t i2=0;i2<nPrim;i2++)
12135    {
12136     if(i2==i1)continue;
12137     aftsTrack=anEvent->GetTrack(i2);
12138     if(!(aftsTrack->InRPSelection())) continue;
12139     phi2=aftsTrack->Phi();
12140     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12141     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
12142     // 2-p correction terms using particle weights:    
12143     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 sin(n*(phi1+phi2))>
12144     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 cos(n*(phi1+phi2))>
12145    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12146   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12147  } // end of if(nPrim>=2)
12148
12149  // 3-particle correction terms using particle weights:       
12150  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
12151  { 
12152   for(Int_t i1=0;i1<nPrim;i1++)
12153   {
12154    aftsTrack=anEvent->GetTrack(i1);
12155    if(!(aftsTrack->InRPSelection())) continue;
12156    phi1=aftsTrack->Phi();
12157    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12158    for(Int_t i2=0;i2<nPrim;i2++)
12159    {
12160     if(i2==i1)continue;
12161     aftsTrack=anEvent->GetTrack(i2);
12162     if(!(aftsTrack->InRPSelection())) continue;
12163     phi2=aftsTrack->Phi();
12164     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12165     for(Int_t i3=0;i3<nPrim;i3++)
12166     {
12167      if(i3==i1||i3==i2)continue;
12168      aftsTrack=anEvent->GetTrack(i3);
12169      if(!(aftsTrack->InRPSelection())) continue;
12170      phi3=aftsTrack->Phi();
12171      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12172      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
12173      // 3-p correction terms using particle weights:    
12174      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 sin(n*(phi1-phi2-phi3))>
12175      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n*(phi1-phi2-phi3))>
12176     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12177    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12178   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12179  } // end of if(nPrim>=3)
12180  
12181  /*
12182  
12183  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
12184  {
12185   // 4 nested loops multiparticle correlations using particle weights:       
12186   for(Int_t i1=0;i1<nPrim;i1++)
12187   {
12188    aftsTrack=anEvent->GetTrack(i1);
12189    if(!(aftsTrack->InRPSelection())) continue;
12190    phi1=aftsTrack->Phi();
12191    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12192    for(Int_t i2=0;i2<nPrim;i2++)
12193    {
12194     if(i2==i1)continue;
12195     aftsTrack=anEvent->GetTrack(i2);
12196     if(!(aftsTrack->InRPSelection())) continue;
12197     phi2=aftsTrack->Phi();
12198     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12199     for(Int_t i3=0;i3<nPrim;i3++)
12200     {
12201      if(i3==i1||i3==i2)continue;
12202      aftsTrack=anEvent->GetTrack(i3);
12203      if(!(aftsTrack->InRPSelection())) continue;
12204      phi3=aftsTrack->Phi();
12205      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12206      for(Int_t i4=0;i4<nPrim;i4++)
12207      {
12208       if(i4==i1||i4==i2||i4==i3)continue;
12209       aftsTrack=anEvent->GetTrack(i4);
12210       if(!(aftsTrack->InRPSelection())) continue;
12211       phi4=aftsTrack->Phi();
12212       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
12213       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
12214       // 4-p correlations using particle weights:
12215       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
12216       // extra correlations: 
12217       // 2-p extra correlations (do not appear if particle weights are not used):
12218       // ...
12219       // 3-p extra correlations (do not appear if particle weights are not used):
12220       // ...
12221       // 4-p extra correlations (do not appear if particle weights are not used):
12222       // ...
12223      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
12224     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12225    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12226   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12227  } // end of if(nPrim>=4)
12228
12229  */
12230
12231  cout<<endl; 
12232
12233 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
12234
12235
12236 //================================================================================================================================
12237
12238
12239 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
12240 {
12241  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms) using particle weights.
12242  
12243  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
12244  //
12245  //  0: <<cos n(psi)>>
12246  //  1: <<w2 cos n(psi1+phi2)>>
12247  //  2: <<w2 w3 cos n(psi1+phi2-phi3)>>
12248  //  3: <<w2 w3 cos n(psi1-phi2-phi3)>>
12249  //  4:
12250  //  5:
12251  //  6:
12252  
12253  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
12254  Double_t dReQ1n1k = (*fReQ)(0,1);
12255  Double_t dReQ2n2k = (*fReQ)(1,2);
12256  //Double_t dReQ1n3k = (*fReQ)(0,3);
12257  //Double_t dReQ4n4k = (*fReQ)(3,4);
12258  Double_t dImQ1n1k = (*fImQ)(0,1);
12259  Double_t dImQ2n2k = (*fImQ)(1,2);
12260  //Double_t dImQ1n3k = (*fImQ)(0,3);
12261  //Double_t dImQ4n4k = (*fImQ)(3,4);
12262  
12263  // S^M_{p,k} (see .h file for the definition of fSMpk):
12264  Double_t dSM1p1k = (*fSMpk)(0,1);
12265  Double_t dSM1p2k = (*fSMpk)(0,2);
12266  Double_t dSM2p1k = (*fSMpk)(1,1);
12267
12268  Int_t t = 0; // type flag 
12269  Int_t pe = 0; // ptEta flag
12270  
12271  if(type == "RP")
12272  {
12273   t = 0;
12274  } else if(type == "POI")
12275    {
12276     t = 1;
12277    }
12278
12279  if(ptOrEta == "Pt")
12280  {
12281   pe = 0;
12282  } else if(ptOrEta == "Eta")
12283    {
12284     pe = 1;
12285    }
12286     
12287  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
12288  Double_t minPtEta[2] = {fPtMin,fEtaMin};
12289  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
12290  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12291  
12292  // looping over all bins and calculating correction terms: 
12293  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12294  {
12295   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
12296   Double_t p1n0kRe = 0.;
12297   Double_t p1n0kIm = 0.;
12298
12299   // number of POIs in particular pt or eta bin:
12300   Double_t mp = 0.;
12301
12302   // 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):
12303   Double_t q1n2kRe = 0.;
12304   Double_t q1n2kIm = 0.;
12305   Double_t q2n1kRe = 0.;
12306   Double_t q2n1kIm = 0.;
12307     
12308   // s_{1,1}, s_{1,2} // to be improved (add explanation)  
12309   Double_t s1p1k = 0.; 
12310   Double_t s1p2k = 0.; 
12311   
12312   // number of particles which are both RPs and POIs in particular pt or eta bin:
12313   Double_t mq = 0.;
12314   
12315   // M0111 from Eq. (118) in QC2c (to be improved (notation))
12316   Double_t dM01 = 0.;
12317   Double_t dM011 = 0.;
12318   
12319   if(type == "POI")
12320   {           
12321    // q_{m*n,k}:
12322    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
12323            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
12324    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
12325            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
12326    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
12327            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
12328    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
12329            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
12330    mq = fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12331    
12332    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
12333    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
12334   }else if(type == "RP")
12335    {
12336     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
12337     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
12338             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
12339     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
12340             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
12341     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
12342             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
12343     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
12344             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
12345     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12346     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
12347     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
12348     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.);  
12349     
12350     mq = fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12351   }    
12352   
12353   if(type == "POI")
12354   {
12355    // p_{m*n,k}:   
12356    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
12357            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
12358    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
12359            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
12360    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12361    // M01 from Eq. (118) in QC2c (to be improved (notation)):
12362    dM01 = mp*dSM1p1k-s1p1k;
12363    dM011 = mp*(dSM2p1k-dSM1p2k)
12364          - 2.*(s1p1k*dSM1p1k-s1p2k);
12365        
12366    // typeFlag = RP (0) or POI (1):   
12367    t = 1; 
12368   } else if(type == "RP")
12369     {  
12370      // to be improved (cross-checked):
12371      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
12372              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
12373      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
12374              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
12375      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12376      // M01 from Eq. (118) in QC2c (to be improved (notation)):
12377      dM01 = mp*dSM1p1k-s1p1k;
12378      dM011 = mp*(dSM2p1k-dSM1p2k)
12379            - 2.*(s1p1k*dSM1p1k-s1p2k); 
12380      // typeFlag = RP (0) or POI (1): 
12381      t = 0;
12382     }
12383   
12384   // <<cos n(psi1)>>:
12385   Double_t cosP1nPsi = 0.;
12386   if(mp)
12387   {
12388    cosP1nPsi = p1n0kRe/mp;
12389    
12390    // fill profile for <<cos n(psi1)>>:
12391    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
12392    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
12393    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
12394   } // end of if(mp)   
12395   
12396   // <<w2 cos n(psi1+phi2)>>:
12397   Double_t cosP1nPsiP1nPhiW2 = 0.;
12398   if(dM01)
12399   {
12400    cosP1nPsiP1nPhiW2 = (p1n0kRe*dReQ1n1k-p1n0kIm*dImQ1n1k-q2n1kRe)/(dM01);
12401    // fill profile for <<w2 cos n(psi1+phi2)>>:
12402    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhiW2,dM01);
12403    // histogram to store <w2 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12404    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhiW2);
12405   } // end of if(dM01)   
12406   
12407   // <<w2 w3 cos n(psi1+phi2-phi3)>>:
12408   Double_t cosP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
12409   if(dM011)
12410   {
12411    cosP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
12412                               - p1n0kRe*dSM1p2k
12413                               - q2n1kRe*dReQ1n1k-q2n1kIm*dImQ1n1k
12414                               - s1p1k*dReQ1n1k
12415                               + 2.*q1n2kRe)
12416                               / dM011;  
12417    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
12418    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3W2W3,dM011);
12419    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12420    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3W2W3);
12421   } // end of if(dM011)   
12422   
12423   // <<w2 w3 cos n(psi1-phi2-phi3)>>:
12424   Double_t cosP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
12425   if(dM011)
12426   {
12427    cosP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))+2.*p1n0kIm*dReQ1n1k*dImQ1n1k
12428                               - 1.*(p1n0kRe*dReQ2n2k+p1n0kIm*dImQ2n2k)  
12429                               - 2.*s1p1k*dReQ1n1k
12430                               + 2.*q1n2kRe)
12431                               / dM011;
12432    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
12433    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3W2W3,dM011);
12434    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12435    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3W2W3);
12436   } // end of if(dM011)   
12437  
12438  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12439    
12440 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
12441
12442
12443 //================================================================================================================================
12444
12445
12446 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
12447 {
12448  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
12449   
12450  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
12451  //  0: <<sin n(psi1)>>
12452  //  1: <<w2 sin n(psi1+phi2)>>
12453  //  2: <<w2 w3 sin n(psi1+phi2-phi3)>>
12454  //  3: <<w2 w3 sin n(psi1-phi2-phi3)>>:
12455  //  4:
12456  //  5:
12457  //  6:
12458  
12459  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
12460  Double_t dReQ1n1k = (*fReQ)(0,1);
12461  Double_t dReQ2n2k = (*fReQ)(1,2);
12462  //Double_t dReQ1n3k = (*fReQ)(0,3);
12463  //Double_t dReQ4n4k = (*fReQ)(3,4);
12464  Double_t dImQ1n1k = (*fImQ)(0,1);
12465  Double_t dImQ2n2k = (*fImQ)(1,2);
12466  //Double_t dImQ1n3k = (*fImQ)(0,3);
12467  //Double_t dImQ4n4k = (*fImQ)(3,4);
12468  
12469  // S^M_{p,k} (see .h file for the definition of fSMpk):
12470  Double_t dSM1p1k = (*fSMpk)(0,1);
12471  Double_t dSM1p2k = (*fSMpk)(0,2);
12472  Double_t dSM2p1k = (*fSMpk)(1,1);
12473
12474  Int_t t = 0; // type flag 
12475  Int_t pe = 0; // ptEta flag
12476  
12477  if(type == "RP")
12478  {
12479   t = 0;
12480  } else if(type == "POI")
12481    {
12482     t = 1;
12483    }
12484
12485  if(ptOrEta == "Pt")
12486  {
12487   pe = 0;
12488  } else if(ptOrEta == "Eta")
12489    {
12490     pe = 1;
12491    }
12492     
12493  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
12494  Double_t minPtEta[2] = {fPtMin,fEtaMin};
12495  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
12496  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12497
12498  // looping over all bins and calculating correction terms: 
12499  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12500  {
12501   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
12502   Double_t p1n0kRe = 0.;
12503   Double_t p1n0kIm = 0.;
12504
12505   // number of POIs in particular pt or eta bin:
12506   Double_t mp = 0.;
12507
12508   // 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):
12509   Double_t q1n2kRe = 0.;
12510   Double_t q1n2kIm = 0.;
12511   Double_t q2n1kRe = 0.;
12512   Double_t q2n1kIm = 0.;
12513     
12514   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12515   Double_t s1p1k = 0.; 
12516   Double_t s1p2k = 0.; 
12517   
12518   // number of particles which are both RPs and POIs in particular pt or eta bin:
12519   Double_t mq = 0.;
12520   
12521   // M0111 from Eq. (118) in QC2c (to be improved (notation))
12522   Double_t dM01 = 0.;
12523   Double_t dM011 = 0.;
12524
12525   if(type == "POI")
12526   {    
12527    // q_{m*n,k}:
12528    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
12529            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
12530    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
12531            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
12532    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
12533            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
12534    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
12535            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
12536    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12537    
12538    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
12539    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
12540   }else if(type == "RP")
12541    {
12542     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
12543     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
12544             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
12545     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
12546             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
12547     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
12548             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
12549     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
12550             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
12551     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12552     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
12553     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
12554     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
12555   }    
12556   
12557   if(type == "POI")
12558   {
12559    // p_{m*n,k}:   
12560    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
12561            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
12562    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
12563            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
12564    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12565    // M01 from Eq. (118) in QC2c (to be improved (notation)):
12566    dM01 = mp*dSM1p1k-s1p1k;
12567    dM011 = mp*(dSM2p1k-dSM1p2k)
12568          - 2.*(s1p1k*dSM1p1k-s1p2k);  
12569    // typeFlag = RP (0) or POI (1):   
12570    t = 1;           
12571   } else if(type == "RP")
12572     { 
12573      // to be improved (cross-checked):
12574      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
12575              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
12576      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
12577              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
12578      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)    
12579      // M01 from Eq. (118) in QC2c (to be improved (notation)):
12580      dM01 = mp*dSM1p1k-s1p1k;
12581      dM011 = mp*(dSM2p1k-dSM1p2k)
12582            - 2.*(s1p1k*dSM1p1k-s1p2k); 
12583      // typeFlag = RP (0) or POI (1): 
12584      t = 0;
12585     }
12586   
12587   // <<sin n(psi1)>>:
12588   Double_t sinP1nPsi = 0.;
12589   if(mp)
12590   {
12591    sinP1nPsi = p1n0kIm/mp;
12592    
12593    // fill profile for <<sin n(psi1)>>:
12594    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
12595    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
12596    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
12597   } // end of if(mp)   
12598   
12599   // <<w2 sin n(psi1+phi2)>>:
12600   Double_t sinP1nPsiP1nPhiW2 = 0.;
12601   if(dM01)
12602   {
12603    sinP1nPsiP1nPhiW2 = (p1n0kRe*dImQ1n1k+p1n0kIm*dReQ1n1k-q2n1kIm)/(dM01);
12604    // fill profile for <<w2 sin n(psi1+phi2)>>:
12605    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhiW2,dM01);
12606    // histogram to store <w2 sin n(psi1+phi2)> e-b-e (needed in some other methods):
12607    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhiW2);
12608   } // end of if(mp*dMult-mq)   
12609   
12610   // <<w2 w3 sin n(psi1+phi2-phi3)>>:
12611   Double_t sinP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
12612   if(dM011)
12613   {
12614    sinP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
12615                               - p1n0kIm*dSM1p2k
12616                               + q2n1kRe*dImQ1n1k-q2n1kIm*dReQ1n1k
12617                               - s1p1k*dImQ1n1k
12618                               + 2.*q1n2kIm)
12619                               / dM011;  
12620    // fill profile for <<w2 w3 sin n(psi1+phi2-phi3)>>:
12621    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3W2W3,dM011);
12622    // histogram to store <w2 w3 sin n(psi1+phi2-phi3)> e-b-e (needed in some other methods):
12623    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3W2W3);
12624   } // end of if(dM011)   
12625   
12626   // <<w2 w3 sin n(psi1-phi2-phi3)>>:
12627   Double_t sinP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
12628   if(dM011)
12629   {
12630    sinP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))-2.*p1n0kRe*dReQ1n1k*dImQ1n1k
12631                               + 1.*(p1n0kRe*dImQ2n2k-p1n0kIm*dReQ2n2k)  
12632                               + 2.*s1p1k*dImQ1n1k
12633                               - 2.*q1n2kIm)
12634                               / dM011;
12635    // fill profile for <<w2 w3 sin n(psi1-phi2-phi3)>>:
12636    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3W2W3,dM011);
12637    // histogram to store <w2 w3 sin n(psi1-phi2-phi3)> e-b-e (needed in some other methods):
12638    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3W2W3);
12639   } // end of if(dM011)   
12640   
12641  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12642
12643 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
12644
12645
12646 //================================================================================================================================
12647
12648    
12649 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12650 {
12651  // Evaluate with nested loops correction terms for non-uniform acceptance 
12652  // with using particle weights (both sin and cos terms) relevant for differential flow.
12653  
12654  // Remark 1: "w1" in expressions bellow is a particle weight used only for particles which were 
12655  //           flagged both as POI and RP.
12656  // Remark 2: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
12657  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12658  // Remark 3: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
12659  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
12660  //  cti: 
12661  //    0: <<sc n(psi1)>>
12662  //    1: <<w2 sc n(psi1+phi2)>> 
12663  //    2: <<w2 w3 sc n(psi1+phi2-phi3)>>
12664  //    3: <<w2 w3 sc n(psi1-phi2-phi3)>>
12665  //    4:
12666  //    5:
12667  //    6:
12668      
12669  Int_t typeFlag = 0;
12670  Int_t ptEtaFlag = 0;
12671  if(type == "RP")
12672  {
12673   typeFlag = 0;
12674  } else if(type == "POI")
12675    {
12676     typeFlag = 1;
12677    }      
12678  if(ptOrEta == "Pt")
12679  {
12680   ptEtaFlag = 0;
12681  } else if(ptOrEta == "Eta")
12682    {
12683     ptEtaFlag = 1;
12684    } 
12685  // shortcuts:
12686  Int_t t = typeFlag;
12687  Int_t pe = ptEtaFlag;
12688       
12689  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12690  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12691  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12692  
12693  Int_t nPrim = anEvent->NumberOfTracks(); 
12694  AliFlowTrackSimple *aftsTrack = NULL;
12695  
12696  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12697  Double_t wPhi2=1., wPhi3=1.;
12698  
12699  Int_t n = fHarmonic; 
12700  
12701  // 1'-particle correction terms:
12702  for(Int_t i1=0;i1<nPrim;i1++)
12703  {
12704   aftsTrack=anEvent->GetTrack(i1);
12705   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12706   if(typeFlag==1) // this is diff flow of POIs 
12707   {
12708    if(ptOrEta == "Pt")
12709    { 
12710     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12711    } else if (ptOrEta == "Eta")
12712      {
12713       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12714      }
12715   } else // this is diff flow of RPs 
12716     {
12717      if(ptOrEta == "Pt")
12718      { 
12719       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12720      } else if (ptOrEta == "Eta")
12721        {
12722         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12723        }
12724     }
12725   psi1=aftsTrack->Phi(); 
12726   // sin terms: 
12727   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
12728   // cos terms: 
12729   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
12730  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12731    
12732  // 2'-particle correction terms:
12733  for(Int_t i1=0;i1<nPrim;i1++)
12734  {
12735   aftsTrack=anEvent->GetTrack(i1);
12736   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12737   if(typeFlag==1) // this is diff flow of POIs 
12738   {
12739    if(ptOrEta == "Pt")
12740    { 
12741     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12742    } else if (ptOrEta == "Eta")
12743      {
12744       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12745      }
12746   } else // this is diff flow of RPs 
12747     {
12748      if(ptOrEta == "Pt")
12749      { 
12750       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12751      } else if (ptOrEta == "Eta")
12752        {
12753         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12754        }
12755     }
12756   psi1=aftsTrack->Phi(); 
12757   for(Int_t i2=0;i2<nPrim;i2++)
12758   {
12759    if(i2==i1) continue;
12760    aftsTrack=anEvent->GetTrack(i2);
12761    // RP condition (!(first) particle in the correlator must be RP):
12762    if(!(aftsTrack->InRPSelection())) continue;
12763    phi2=aftsTrack->Phi();
12764    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12765    // sin terms: 
12766    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),wPhi2); // <<w2 sin(n*(psi1+phi2))>>  
12767    // cos terms: 
12768    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),wPhi2); // <<w2 cos(n*(psi1+phi2))>>  
12769   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12770  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
12771  
12772  // 3'-particle correction terms:
12773  for(Int_t i1=0;i1<nPrim;i1++)
12774  {
12775   aftsTrack=anEvent->GetTrack(i1);
12776   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12777   if(typeFlag==1) // this is diff flow of POIs 
12778   {
12779    if(ptOrEta == "Pt")
12780    { 
12781     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12782    } else if (ptOrEta == "Eta")
12783      {
12784       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12785      }
12786   } else // this is diff flow of RPs 
12787     {
12788      if(ptOrEta == "Pt")
12789      { 
12790       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12791      } else if (ptOrEta == "Eta")
12792        {
12793         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12794        }
12795     }
12796   psi1=aftsTrack->Phi();
12797   for(Int_t i2=0;i2<nPrim;i2++)
12798   {
12799    if(i2==i1) continue;
12800    aftsTrack=anEvent->GetTrack(i2);
12801    // RP condition (!(first) particle in the correlator must be RP):
12802    if(!(aftsTrack->InRPSelection())) continue;
12803    phi2=aftsTrack->Phi();
12804    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12805    for(Int_t i3=0;i3<nPrim;i3++)
12806    {
12807     if(i3==i1||i3==i2) continue;
12808     aftsTrack=anEvent->GetTrack(i3);
12809     // RP condition (!(first) particle in the correlator must be RP):
12810     if(!(aftsTrack->InRPSelection())) continue;
12811     phi3=aftsTrack->Phi();
12812     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));   
12813     // sin terms: 
12814     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))>>  
12815     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))>>  
12816     // cos terms: 
12817     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))>>  
12818     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))>>  
12819    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
12820   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
12821  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12822                
12823 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12824
12825 //================================================================================================================================
12826
12827 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
12828 {
12829  // Check all pointers used in method Finish().
12830  
12831  if(!fAvMultiplicity)
12832  {
12833   cout<<endl;
12834   cout<<" WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12835   cout<<endl;
12836   exit(0);
12837  }
12838  if(!fIntFlowCorrelationsPro)
12839  {
12840   cout<<endl;
12841   cout<<" WARNING (QC): fIntFlowCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12842   cout<<endl;
12843   exit(0); 
12844  }
12845  if(!fIntFlowSquaredCorrelationsPro)
12846  {
12847   cout<<endl;
12848   cout<<" WARNING (QC): fIntFlowSquaredCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12849   cout<<endl;
12850   exit(0); 
12851  } 
12852  if(!fIntFlowCorrelationsHist)
12853  {
12854   cout<<endl;
12855   cout<<" WARNING (QC): fIntFlowCorrelationsHist is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12856   cout<<endl;
12857   exit(0); 
12858  }
12859  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights) && !fIntFlowExtraCorrelationsPro) 
12860  {
12861   cout<<endl;
12862   cout<<" WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12863   cout<<endl;
12864   exit(0); 
12865  } 
12866  for(Int_t power=0;power<2;power++)
12867  { 
12868   if(!fIntFlowSumOfEventWeights[power]) 
12869   {
12870    cout<<endl;
12871    cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeights[%d] is NULL in CheckPointersUsedInFinish() !!!!",power)<<endl;
12872    cout<<endl;
12873    exit(0);
12874   }
12875  } // end of for(Int_t power=0;power<2;power++)
12876  if(!fIntFlowProductOfCorrelationsPro)
12877  {
12878   cout<<endl;
12879   cout<<" WARNING (QC): fIntFlowProductOfCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12880   cout<<endl;
12881   exit(0); 
12882  } 
12883  if(!fIntFlowSumOfProductOfEventWeights)
12884  {
12885   cout<<endl;
12886   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeights is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12887   cout<<endl;
12888   exit(0); 
12889  }
12890  if(!fIntFlowCovariances)
12891  {
12892   cout<<endl;
12893   cout<<" WARNING (QC): fIntFlowCovariances is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12894   cout<<endl;
12895   exit(0); 
12896  }  
12897  if(!fIntFlowQcumulants)
12898  {
12899   cout<<endl;
12900   cout<<" WARNING (QC): fIntFlowQcumulants is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12901   cout<<endl;
12902   exit(0); 
12903  }  
12904  if(!fIntFlow)
12905  {
12906   cout<<endl;
12907   cout<<" WARNING (QC): fIntFlow is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12908   cout<<endl;
12909   exit(0); 
12910  }
12911  if(!fCommonHists)
12912  {
12913   cout<<endl;
12914   cout<<" WARNING (QC): fCommonHists is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12915   cout<<endl;
12916   exit(0); 
12917  }
12918  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
12919  {
12920   cout<<endl;
12921   cout<<" WARNING (QC): fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th"<<endl; 
12922   cout<<"               && fCommonHistsResults8th is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12923   cout<<endl;
12924   exit(0);
12925  } 
12926  
12927  // NUA stuff:
12928  for(Int_t sc=0;sc<2;sc++) // sin/cos
12929  { 
12930   if(!fIntFlowCorrectionTermsForNUAPro[sc]) 
12931   {
12932    cout<<endl;
12933    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
12934    cout<<endl;
12935    exit(0);
12936   }
12937   if(!fIntFlowCorrectionTermsForNUAHist[sc]) 
12938   {
12939    cout<<endl;
12940    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
12941    cout<<endl;
12942    exit(0);
12943   }
12944   for(Int_t lq=0;lq<2;lq++) // linear/quadratic
12945   {
12946    if(!fIntFlowSumOfEventWeightsNUA[sc][lq]) 
12947    {
12948     cout<<endl;
12949     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsNUA[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",sc,lq)<<endl;
12950     cout<<endl;
12951     exit(0);
12952    }
12953   } // end of for(Int_t lq=0;lq<2;lq++) // linear/quadratic
12954  } // end of for(Int_t power=0;power<2;power++) 
12955  if(!fIntFlowProductOfCorrectionTermsForNUAPro)
12956  {
12957   cout<<endl;
12958   cout<<" WARNING (QC): fIntFlowProductOfCorrectionTermsForNUAPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12959   cout<<endl;
12960   exit(0); 
12961  } 
12962  if(!fIntFlowSumOfProductOfEventWeightsNUA)
12963  {
12964   cout<<endl;
12965   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeightsNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12966   cout<<endl;
12967   exit(0); 
12968  } 
12969  if(!fIntFlowCovariancesNUA)
12970  {
12971   cout<<endl;
12972   cout<<" WARNING (QC): fIntFlowCovariancesNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12973   cout<<endl;
12974   exit(0); 
12975  } 
12976  if(!fIntFlowQcumulantsErrorSquaredRatio)
12977  {
12978   cout<<endl;
12979   cout<<" WARNING (QC): fIntFlowQcumulantsErrorSquaredRatio is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12980   cout<<endl;
12981   exit(0); 
12982  } 
12983  if(!fIntFlowDetectorBias)
12984  {
12985   cout<<endl;
12986   cout<<" WARNING (QC): fIntFlowDetectorBias is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12987   cout<<endl;
12988   exit(0); 
12989  }
12990  
12991  // Versus multiplicity:
12992  if(!fCalculateCumulantsVsM){return;}
12993  for(Int_t co=0;co<=3;co++) // cumulant order
12994  {
12995   if(!fIntFlowQcumulantsVsM[co])
12996   {
12997    cout<<endl;
12998    cout<<Form(" WARNING (QC): fIntFlowQcumulantsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
12999    cout<<endl;
13000    exit(0); 
13001   }
13002   if(!fIntFlowVsM[co])
13003   {
13004    cout<<endl;
13005    cout<<Form(" WARNING (QC): fIntFlowVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
13006    cout<<endl;
13007    exit(0); 
13008   }
13009   if(!fIntFlowDetectorBiasVsM[co])
13010   {
13011    cout<<endl;
13012    cout<<Form(" WARNING (QC): fIntFlowDetectorBiasVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
13013    cout<<endl;
13014    exit(0); 
13015   }
13016  } // end of for(Int_t c0=0;c0<=3;c0++) // cumulant order
13017  for(Int_t ci=0;ci<=3;ci++) // correlation index
13018  {
13019   if(!fIntFlowCorrelationsVsMPro[ci])
13020   {
13021    cout<<endl;
13022    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
13023    cout<<endl;
13024    exit(0); 
13025   }
13026   if(!fIntFlowSquaredCorrelationsVsMPro[ci])
13027   {
13028    cout<<endl;
13029    cout<<Form(" WARNING (QC): fIntFlowSquaredCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
13030    cout<<endl;
13031    exit(0); 
13032   }  
13033   if(!fIntFlowCorrelationsVsMHist[ci])
13034   {
13035    cout<<endl;
13036    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
13037    cout<<endl;
13038    exit(0); 
13039   }
13040   for(Int_t power=0;power<2;power++) 
13041   {
13042    if(!fIntFlowSumOfEventWeightsVsM[ci][power])
13043    {
13044     cout<<endl;
13045     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsVsM[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",ci,power)<<endl;
13046     cout<<endl;
13047     exit(0);   
13048    }
13049   } // end of for(Int_t power=0;power<2;power++) 
13050  } // end of for(Int_t ci=0;ci<=3;ci++) // correlation index
13051  for(Int_t i=0;i<6;i++)
13052  {
13053   if(!fIntFlowProductOfCorrelationsVsMPro[i])
13054   {
13055    cout<<endl;
13056    cout<<Form(" WARNING (QC): fIntFlowProductOfCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
13057    cout<<endl;
13058    exit(0); 
13059   }
13060   if(!fIntFlowSumOfProductOfEventWeightsVsM[i])
13061   {
13062    cout<<endl;
13063    cout<<Form(" WARNING (QC): fIntFlowSumOfProductOfEventWeightsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
13064    cout<<endl;
13065    exit(0); 
13066   }
13067   if(!fIntFlowCovariancesVsM[i])
13068   {
13069    cout<<endl;
13070    cout<<Form(" WARNING (QC): fIntFlowCovariancesVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
13071    cout<<endl;
13072    exit(0); 
13073   }
13074  } // end of for(Int_t i=0;i<6;i++) 
13075  if(!fIntFlowRebinnedInM)
13076  {
13077   cout<<endl;
13078   cout<<" WARNING (QC): fIntFlowRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13079   cout<<endl;
13080   exit(0); 
13081  }
13082  if(!fIntFlowQcumulantsRebinnedInM)
13083  {
13084   cout<<endl;
13085   cout<<" WARNING (QC): fIntFlowQcumulantsRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13086   cout<<endl;
13087   exit(0); 
13088  }  
13089  
13090 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
13091
13092 //================================================================================================================================
13093
13094 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
13095 {
13096  // Check all pointers used in method Make().
13097  
13098  if(!fAvMultiplicity)
13099  {
13100   cout<<endl;
13101   cout<<" WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInMake() !!!!"<<endl;
13102   cout<<endl;
13103   exit(0);
13104  }
13105  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights) && !fIntFlowExtraCorrelationsPro) 
13106  {
13107   cout<<endl;
13108   cout<<" WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInMake() !!!!"<<endl;
13109   cout<<endl;
13110   exit(0); 
13111  } 
13112
13113 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
13114  
13115