]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/FLOW/Base/AliFlowAnalysisWithQCumulants.cxx
463cc29a35059cc5368b2c42dbae2c1429b50d2d
[u/mrichter/AliRoot.git] / PWG / FLOW / Base / 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 "TMath.h"
40 #include "TArrow.h"
41 #include "TPaveLabel.h"
42 #include "TCanvas.h"
43 #include "AliFlowEventSimple.h"
44 #include "AliFlowTrackSimple.h"
45 #include "AliFlowAnalysisWithQCumulants.h"
46 #include "TArrayD.h"
47 #include "TRandom.h"
48 #include "TF1.h"
49
50 class TH1;
51 class TH2;
52 class TGraph;
53 class TPave;
54 class TLatex;
55 class TMarker;
56 class TRandom3;
57 class TObjArray;
58 class TList;
59 class TCanvas;
60 class TSystem;
61 class TROOT;
62 class AliFlowVector;
63 class TVector;
64
65 //================================================================================================================
66
67 ClassImp(AliFlowAnalysisWithQCumulants)
68
69 AliFlowAnalysisWithQCumulants::AliFlowAnalysisWithQCumulants(): 
70  // 0.) base:
71  fHistList(NULL),
72  // 1.) common:
73  fBookOnlyBasicCCH(kFALSE),
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  fCommonConstants(NULL),
96  fFillMultipleControlHistograms(kFALSE),
97  fHarmonic(2),
98  fAnalysisLabel(NULL),
99  // 2a.) particle weights:
100  fWeightsList(NULL),
101  fUsePhiWeights(kFALSE),
102  fUsePtWeights(kFALSE),
103  fUseEtaWeights(kFALSE),
104  fUseTrackWeights(kFALSE),
105  fUseParticleWeights(NULL),
106  fPhiWeights(NULL),
107  fPtWeights(NULL),
108  fEtaWeights(NULL),
109  // 2b.) event weights:
110  fMultiplicityWeight(NULL),
111  // 3.) integrated flow:
112  fIntFlowList(NULL), 
113  fIntFlowProfiles(NULL),
114  fIntFlowResults(NULL),
115  fIntFlowAllCorrelationsVsM(NULL),
116  fIntFlowFlags(NULL),
117  fApplyCorrectionForNUA(kFALSE),  
118  fApplyCorrectionForNUAVsM(kFALSE),
119  fnBinsMult(10000),
120  fMinMult(0.),  
121  fMaxMult(10000.), 
122  fPropagateErrorAlsoFromNIT(kFALSE), 
123  fCalculateCumulantsVsM(kFALSE),
124  fCalculateAllCorrelationsVsM(kFALSE), 
125  fMinimumBiasReferenceFlow(kTRUE), 
126  fForgetAboutCovariances(kFALSE), 
127  fStorePhiDistributionForOneEvent(kFALSE),
128  fReQ(NULL),
129  fImQ(NULL),
130  fSpk(NULL),
131  fIntFlowCorrelationsEBE(NULL),
132  fIntFlowEventWeightsForCorrelationsEBE(NULL),
133  fIntFlowCorrelationsAllEBE(NULL),
134  fReferenceMultiplicityEBE(0.),  
135  fAvMultiplicity(NULL),
136  fIntFlowCorrelationsPro(NULL),
137  fIntFlowSquaredCorrelationsPro(NULL),
138  fIntFlowCorrelationsAllPro(NULL),
139  fIntFlowExtraCorrelationsPro(NULL),
140  fIntFlowProductOfCorrelationsPro(NULL),
141  fIntFlowProductOfCorrectionTermsForNUAPro(NULL),
142  fIntFlowCorrelationsHist(NULL),
143  fIntFlowCorrelationsAllHist(NULL),
144  fIntFlowCovariances(NULL),
145  fIntFlowSumOfProductOfEventWeights(NULL),
146  fIntFlowCovariancesNUA(NULL),
147  fIntFlowSumOfProductOfEventWeightsNUA(NULL),
148  fIntFlowQcumulants(NULL),
149  fIntFlowQcumulantsRebinnedInM(NULL), 
150  fIntFlowQcumulantsErrorSquaredRatio(NULL), 
151  fIntFlow(NULL),
152  fIntFlowRebinnedInM(NULL),
153  fIntFlowDetectorBias(NULL),
154  // 4.) differential flow:
155  fDiffFlowList(NULL),
156  fDiffFlowProfiles(NULL),
157  fDiffFlowResults(NULL),
158  fDiffFlow2D(NULL),
159  fDiffFlowFlags(NULL),
160  fCalculateDiffFlow(kTRUE),
161  fCalculate2DDiffFlow(kFALSE),
162  fCalculateDiffFlowVsEta(kTRUE),
163  // 5.) other differential correlators:
164  fOtherDiffCorrelatorsList(NULL),
165  // 6.) distributions:
166  fDistributionsList(NULL),
167  fDistributionsFlags(NULL),
168  fStoreDistributions(kFALSE),
169  // 7.) various:
170  fVariousList(NULL),
171  fPhiDistributionForOneEvent(NULL),
172  // x.) debugging and cross-checking:
173  fNestedLoopsList(NULL),
174  fEvaluateIntFlowNestedLoops(kFALSE),
175  fEvaluateDiffFlowNestedLoops(kFALSE),
176  fMaxAllowedMultiplicity(10),
177  fEvaluateNestedLoops(NULL),
178  fIntFlowDirectCorrelations(NULL),
179  fIntFlowExtraDirectCorrelations(NULL),
180  fCrossCheckInPtBinNo(10),
181  fCrossCheckInEtaBinNo(20),
182  fNoOfParticlesInBin(NULL)
183  {
184   // constructor  
185   
186   // base list to hold all output objects:
187   fHistList = new TList();
188   fHistList->SetName("cobjQC");
189   fHistList->SetOwner(kTRUE);
190   
191   // list to hold histograms with phi, pt and eta weights:      
192   fWeightsList = new TList();
193   
194   // multiplicity weight:
195   fMultiplicityWeight = new TString("combinations");
196     
197   // analysis label;
198   fAnalysisLabel = new TString();
199       
200   // initialize all arrays:  
201   this->InitializeArraysForIntFlow();
202   this->InitializeArraysForDiffFlow();
203   this->InitializeArraysForDistributions();
204   this->InitializeArraysForVarious();
205   this->InitializeArraysForNestedLoops();
206   
207  } // end of constructor
208  
209 //================================================================================================================  
210
211 AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
212 {
213  // destructor
214  
215  delete fHistList;
216
217 } // end of AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
218
219 //================================================================================================================
220
221 void AliFlowAnalysisWithQCumulants::Init()
222 {
223  // a) Cross check if the settings make sense before starting the QC adventure;
224  // b) Access all common constants;
225  // c) Book all objects;
226  // d) Store flags for integrated and differential flow;
227  // e) Store flags for distributions of corelations;
228  // f) Store harmonic which will be estimated.
229   
230  //save old value and prevent histograms from being added to directory
231  //to avoid name clashes in case multiple analaysis objects are used
232  //in an analysis
233  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
234  TH1::AddDirectory(kFALSE);
235  
236  // a) Cross check if the settings make sense before starting the QC adventure; 
237  this->CrossCheckSettings();
238  // b) Access all common constants and book a profile to hold them:
239  this->CommonConstants("Init");
240  // c) Book all objects:
241  this->BookAndFillWeightsHistograms(); 
242  this->BookAndNestAllLists();
243  this->BookCommonHistograms();
244  this->BookEverythingForIntegratedFlow(); 
245  this->BookEverythingForDifferentialFlow(); 
246  this->BookEverythingFor2DDifferentialFlow(); 
247  this->BookEverythingForDistributions();
248  this->BookEverythingForVarious();
249  this->BookEverythingForNestedLoops();
250  // d) Store flags for integrated and differential flow:
251  this->StoreIntFlowFlags();
252  this->StoreDiffFlowFlags();
253  // e) Store flags for distributions of corelations:
254  this->StoreFlagsForDistributions();
255  // f) Store harmonic which will be estimated:
256  this->StoreHarmonic();
257  
258  TH1::AddDirectory(oldHistAddStatus);
259 } // end of void AliFlowAnalysisWithQCumulants::Init()
260
261 //================================================================================================================
262
263 void AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
264 {
265  // Running over data only in this method.
266  
267  // a) Check all pointers used in this method;
268  // b) Define local variables;
269  // c) Fill the common control histograms and call the method to fill fAvMultiplicity;
270  // d) Loop over data and calculate e-b-e quantities Q_{n,k}, S_{p,k} and s_{p,k};
271  // e) Calculate the final expressions for S_{p,k} and s_{p,k} (important !!!!); 
272  // f) Call the methods which calculate correlations for reference flow;
273  // g) Call the methods which calculate correlations for differential flow;
274  // h) Call the methods which calculate correlations for 2D differential flow;
275  // i) Call the methods which calculate other differential correlators;
276  // j) Distributions of correlations;
277  // k) Store phi distribution for one event to illustrate flow;
278  // l) Cross-check with nested loops correlators for reference flow;
279  // m) Cross-check with nested loops correlators for differential flow;
280  // n) Reset all event-by-event quantities (very important !!!!). 
281  
282  // a) Check all pointers used in this method:
283  this->CheckPointersUsedInMake();
284  
285  // b) Define local variables:
286  Double_t dPhi = 0.; // azimuthal angle in the laboratory frame
287  Double_t dPt  = 0.; // transverse momentum
288  Double_t dEta = 0.; // pseudorapidity
289  Double_t wPhi = 1.; // phi weight
290  Double_t wPt  = 1.; // pt weight
291  Double_t wEta = 1.; // eta weight
292  Double_t wTrack = 1.; // track weight
293  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of reference particles)
294  fReferenceMultiplicityEBE = anEvent->GetReferenceMultiplicity(); // reference multiplicity for current event
295  Double_t ptEta[2] = {0.,0.}; // 0 = dPt, 1 = dEta
296   
297  // c) Fill the common control histograms and call the method to fill fAvMultiplicity:
298  this->FillCommonControlHistograms(anEvent);                                                               
299  this->FillAverageMultiplicities(nRP);                                                                  
300                                                                                                                                                                                                                                                                                         
301  // d) Loop over data and calculate e-b-e quantities Q_{n,k}, S_{p,k} and s_{p,k}:
302  Int_t nPrim = anEvent->NumberOfTracks();  // nPrim = total number of primary tracks, i.e. nPrim = nRP + nPOI where:
303                                            //  nRP   = # of reference particles;
304                                            //  nPOI  = # of particles of interest.
305  AliFlowTrackSimple *aftsTrack = NULL;
306  Int_t n = fHarmonic; // shortcut for the harmonic 
307  for(Int_t i=0;i<nPrim;i++) 
308  { 
309   aftsTrack=anEvent->GetTrack(i);
310   if(aftsTrack)
311   {
312    if(!(aftsTrack->InRPSelection() || aftsTrack->InPOISelection())){continue;} // safety measure: consider only tracks which are RPs or POIs
313    if(aftsTrack->InRPSelection()) // RP condition:
314    {    
315     dPhi = aftsTrack->Phi();
316     dPt  = aftsTrack->Pt();
317     dEta = aftsTrack->Eta();
318     if(fUsePhiWeights && fPhiWeights && fnBinsPhi) // determine phi weight for this particle:
319     {
320      wPhi = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*fnBinsPhi/TMath::TwoPi())));
321     }
322     if(fUsePtWeights && fPtWeights && fnBinsPt) // determine pt weight for this particle:
323     {
324      wPt = fPtWeights->GetBinContent(1+(Int_t)(TMath::Floor((dPt-fPtMin)/fPtBinWidth))); 
325     }              
326     if(fUseEtaWeights && fEtaWeights && fEtaBinWidth) // determine eta weight for this particle: 
327     {
328      wEta = fEtaWeights->GetBinContent(1+(Int_t)(TMath::Floor((dEta-fEtaMin)/fEtaBinWidth))); 
329     }      
330     // Access track weight:
331     if(fUseTrackWeights)
332     {
333      wTrack = aftsTrack->Weight(); 
334     }
335     // Calculate Re[Q_{m*n,k}] and Im[Q_{m*n,k}] for this event (m = 1,2,...,6, k = 0,1,...,8):
336     for(Int_t m=0;m<6;m++) // to be improved - hardwired 6 
337     {
338      for(Int_t k=0;k<9;k++) // to be improved - hardwired 9
339      {
340       (*fReQ)(m,k)+=pow(wPhi*wPt*wEta*wTrack,k)*TMath::Cos((m+1)*n*dPhi); 
341       (*fImQ)(m,k)+=pow(wPhi*wPt*wEta*wTrack,k)*TMath::Sin((m+1)*n*dPhi); 
342      } 
343     }
344     // Calculate S_{p,k} for this event (Remark: final calculation of S_{p,k} follows after the loop over data bellow):
345     for(Int_t p=0;p<8;p++)
346     {
347      for(Int_t k=0;k<9;k++)
348      {     
349       (*fSpk)(p,k)+=pow(wPhi*wPt*wEta*wTrack,k);
350      }
351     } 
352     // Differential flow:
353     if(fCalculateDiffFlow || fCalculate2DDiffFlow)
354     {
355      ptEta[0] = dPt; 
356      ptEta[1] = dEta; 
357      // Calculate r_{m*n,k} and s_{p,k} (r_{m,k} is 'p-vector' for RPs): 
358      for(Int_t k=0;k<9;k++) // to be improved - hardwired 9
359      {
360       for(Int_t m=0;m<4;m++) // to be improved - hardwired 4
361       {
362        if(fCalculateDiffFlow)
363        {
364         for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
365         {
366          fReRPQ1dEBE[0][pe][m][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k)*TMath::Cos((m+1.)*n*dPhi),1.);
367          fImRPQ1dEBE[0][pe][m][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k)*TMath::Sin((m+1.)*n*dPhi),1.);          
368          if(m==0) // s_{p,k} does not depend on index m
369          {
370           fs1dEBE[0][pe][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k),1.);
371          } // end of if(m==0) // s_{p,k} does not depend on index m
372         } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
373        } // end of if(fCalculateDiffFlow) 
374        if(fCalculate2DDiffFlow)
375        {
376         fReRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k)*TMath::Cos((m+1.)*n*dPhi),1.);
377         fImRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k)*TMath::Sin((m+1.)*n*dPhi),1.);      
378         if(m==0) // s_{p,k} does not depend on index m
379         {
380          fs2dEBE[0][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k),1.);
381         } // end of if(m==0) // s_{p,k} does not depend on index m
382        } // end of if(fCalculate2DDiffFlow)
383       } // end of for(Int_t m=0;m<4;m++) // to be improved - hardwired 4
384      } // end of for(Int_t k=0;k<9;k++) // to be improved - hardwired 9
385      // Checking if RP particle is also POI particle:      
386      if(aftsTrack->InPOISelection())
387      {
388       // Calculate q_{m*n,k} and s_{p,k} ('q-vector' and 's' for RPs && POIs): 
389       for(Int_t k=0;k<9;k++) // to be improved - hardwired 9
390       {
391        for(Int_t m=0;m<4;m++) // to be improved - hardwired 4
392        {
393         if(fCalculateDiffFlow)
394         {
395          for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
396          {
397           fReRPQ1dEBE[2][pe][m][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k)*TMath::Cos((m+1.)*n*dPhi),1.);
398           fImRPQ1dEBE[2][pe][m][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k)*TMath::Sin((m+1.)*n*dPhi),1.);          
399           if(m==0) // s_{p,k} does not depend on index m
400           {
401            fs1dEBE[2][pe][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k),1.);
402           } // end of if(m==0) // s_{p,k} does not depend on index m
403          } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
404         } // end of if(fCalculateDiffFlow) 
405         if(fCalculate2DDiffFlow)
406         {
407          fReRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k)*TMath::Cos((m+1.)*n*dPhi),1.);
408          fImRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k)*TMath::Sin((m+1.)*n*dPhi),1.);      
409          if(m==0) // s_{p,k} does not depend on index m
410          {
411           fs2dEBE[2][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k),1.);
412          } // end of if(m==0) // s_{p,k} does not depend on index m
413         } // end of if(fCalculate2DDiffFlow)
414        } // end of for(Int_t m=0;m<4;m++) // to be improved - hardwired 4
415       } // end of for(Int_t k=0;k<9;k++) // to be improved - hardwired 9    
416      } // end of if(aftsTrack->InPOISelection())  
417     } // end of if(fCalculateDiffFlow || fCalculate2DDiffFlow)         
418    } // end of if(pTrack->InRPSelection())
419    if(aftsTrack->InPOISelection())
420    {
421     dPhi = aftsTrack->Phi();
422     dPt  = aftsTrack->Pt();
423     dEta = aftsTrack->Eta();
424     wPhi = 1.;
425     wPt  = 1.;
426     wEta = 1.;
427     wTrack = 1.;
428     if(fUsePhiWeights && fPhiWeights && fnBinsPhi && aftsTrack->InRPSelection()) // determine phi weight for POI && RP particle:
429     {
430      wPhi = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*fnBinsPhi/TMath::TwoPi())));
431     }
432     if(fUsePtWeights && fPtWeights && fnBinsPt && aftsTrack->InRPSelection()) // determine pt weight for POI && RP particle:
433     {
434      wPt = fPtWeights->GetBinContent(1+(Int_t)(TMath::Floor((dPt-fPtMin)/fPtBinWidth))); 
435     }              
436     if(fUseEtaWeights && fEtaWeights && fEtaBinWidth && aftsTrack->InRPSelection()) // determine eta weight for POI && RP particle: 
437     {
438      wEta = fEtaWeights->GetBinContent(1+(Int_t)(TMath::Floor((dEta-fEtaMin)/fEtaBinWidth))); 
439     }      
440     // Access track weight for POI && RP particle:
441     if(aftsTrack->InRPSelection() && fUseTrackWeights)
442     {
443      wTrack = aftsTrack->Weight(); 
444     }
445     ptEta[0] = dPt;
446     ptEta[1] = dEta;
447     // Calculate p_{m*n,k} ('p-vector' for POIs): 
448     for(Int_t k=0;k<9;k++) // to be improved - hardwired 9
449     {
450      for(Int_t m=0;m<4;m++) // to be improved - hardwired 4
451      {
452       if(fCalculateDiffFlow)
453       {
454        for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
455        {
456         fReRPQ1dEBE[1][pe][m][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k)*TMath::Cos((m+1.)*n*dPhi),1.);
457         fImRPQ1dEBE[1][pe][m][k]->Fill(ptEta[pe],pow(wPhi*wPt*wEta*wTrack,k)*TMath::Sin((m+1.)*n*dPhi),1.);          
458        } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
459       } // end of if(fCalculateDiffFlow) 
460       if(fCalculate2DDiffFlow)
461       {
462        fReRPQ2dEBE[1][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k)*TMath::Cos((m+1.)*n*dPhi),1.);
463        fImRPQ2dEBE[1][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta*wTrack,k)*TMath::Sin((m+1.)*n*dPhi),1.);      
464       } // end of if(fCalculate2DDiffFlow)
465      } // end of for(Int_t m=0;m<4;m++) // to be improved - hardwired 4
466     } // end of for(Int_t k=0;k<9;k++) // to be improved - hardwired 9    
467    } // end of if(pTrack->InPOISelection())    
468   } else // to if(aftsTrack)
469     {
470      printf("\n WARNING (QC): No particle (i.e. aftsTrack is a NULL pointer in AFAWQC::Make())!!!!\n\n");
471     }
472  } // end of for(Int_t i=0;i<nPrim;i++) 
473
474  // e) Calculate the final expressions for S_{p,k} and s_{p,k} (important !!!!):
475  for(Int_t p=0;p<8;p++)
476  {
477   for(Int_t k=0;k<9;k++)
478   {
479    (*fSpk)(p,k)=pow((*fSpk)(p,k),p+1);
480    // ... for the time being s_{p,k} dosn't need higher powers, so no need to finalize it here ...
481   } // end of for(Int_t k=0;k<9;k++)  
482  } // end of for(Int_t p=0;p<8;p++)
483  
484  // f) Call the methods which calculate correlations for reference flow:
485  if(!fEvaluateIntFlowNestedLoops)
486  {
487   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
488   {
489    if(nRP>1){this->CalculateIntFlowCorrelations();} // without using particle weights
490   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
491     {
492      if(nRP>1){this->CalculateIntFlowCorrelationsUsingParticleWeights();} // with using particle weights   
493     }        
494   // Whether or not using particle weights the following is calculated in the same way:  
495   if(nRP>3){this->CalculateIntFlowProductOfCorrelations();}
496   if(nRP>1){this->CalculateIntFlowSumOfEventWeights();}
497   if(nRP>1){this->CalculateIntFlowSumOfProductOfEventWeights();}  
498   // Non-isotropic terms:
499   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
500   {
501    if(nRP>0){this->CalculateIntFlowCorrectionsForNUASinTerms();}
502    if(nRP>0){this->CalculateIntFlowCorrectionsForNUACosTerms();}
503   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
504     {
505      if(nRP>0){this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights();}
506      if(nRP>0){this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights();}     
507     }      
508   // Whether or not using particle weights the following is calculated in the same way:  
509   if(nRP>0){this->CalculateIntFlowProductOfCorrectionTermsForNUA();}     
510   if(nRP>0){this->CalculateIntFlowSumOfEventWeightsNUA();}     
511   if(nRP>0){this->CalculateIntFlowSumOfProductOfEventWeightsNUA();}      
512  } // end of if(!fEvaluateIntFlowNestedLoops)
513
514  // g) Call the methods which calculate correlations for differential flow:
515  if(!fEvaluateDiffFlowNestedLoops && fCalculateDiffFlow)
516  {
517   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
518   {
519    // Without using particle weights:
520    this->CalculateDiffFlowCorrelations("RP","Pt"); 
521    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrelations("RP","Eta");}
522    this->CalculateDiffFlowCorrelations("POI","Pt");
523    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrelations("POI","Eta");}
524    // Non-isotropic terms:
525    this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
526    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");}
527    this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
528    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");}
529    this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
530    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");}
531    this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
532    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");}   
533   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
534     {
535      // With using particle weights:   
536      this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
537      if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta");} 
538      this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
539      if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta");} 
540      // Non-isotropic terms:
541      this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
542      if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");}
543      this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
544      if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");}
545      this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
546      if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");}
547      this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
548      if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");}   
549     }     
550   // Whether or not using particle weights the following is calculated in the same way:  
551   this->CalculateDiffFlowProductOfCorrelations("RP","Pt");
552   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowProductOfCorrelations("RP","Eta");}
553   this->CalculateDiffFlowProductOfCorrelations("POI","Pt");
554   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowProductOfCorrelations("POI","Eta");}
555   this->CalculateDiffFlowSumOfEventWeights("RP","Pt");
556   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowSumOfEventWeights("RP","Eta");}
557   this->CalculateDiffFlowSumOfEventWeights("POI","Pt");
558   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowSumOfEventWeights("POI","Eta");}
559   this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Pt");
560   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Eta");}
561   this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Pt");
562   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Eta");}   
563  } // end of if(!fEvaluateDiffFlowNestedLoops && fCalculateDiffFlow)
564
565  // h) Call the methods which calculate correlations for 2D differential flow:
566  if(!fEvaluateDiffFlowNestedLoops && fCalculate2DDiffFlow)
567  {
568   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
569   {
570    // Without using particle weights:
571    this->Calculate2DDiffFlowCorrelations("RP"); 
572    this->Calculate2DDiffFlowCorrelations("POI");
573    // Non-isotropic terms:
574    // ... to be ctd ...
575   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
576     {
577      // With using particle weights:   
578      // ... to be ctd ...  
579      // Non-isotropic terms:
580      // ... to be ctd ...
581     }     
582   // Whether or not using particle weights the following is calculated in the same way:  
583   // ... to be ctd ...   
584  } // end of if(!fEvaluateDiffFlowNestedLoops && fCalculate2DDiffFlow)
585  
586  // i) Call the methods which calculate other differential correlators:
587  if(!fEvaluateDiffFlowNestedLoops && fCalculateDiffFlow)
588  {
589   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
590   {
591    // Without using particle weights:
592    this->CalculateOtherDiffCorrelators("RP","Pt"); 
593    if(fCalculateDiffFlowVsEta){this->CalculateOtherDiffCorrelators("RP","Eta");}
594    this->CalculateOtherDiffCorrelators("POI","Pt"); 
595    if(fCalculateDiffFlowVsEta){this->CalculateOtherDiffCorrelators("POI","Eta");}     
596   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
597     {
598      // With using particle weights:   
599      // ... to be ctd ...  
600     }     
601   // Whether or not using particle weights the following is calculated in the same way:  
602   // ... to be ctd ...   
603  } // end of if(!fEvaluateDiffFlowNestedLoops)
604  
605  // j) Distributions of correlations:
606  if(fStoreDistributions){this->StoreDistributionsOfCorrelations();}
607  
608  // k) Store phi distribution for one event to illustrate flow: 
609  if(fStorePhiDistributionForOneEvent){this->StorePhiDistributionForOneEvent(anEvent);}
610    
611  // l) Cross-check with nested loops correlators for reference flow:
612  if(fEvaluateIntFlowNestedLoops){this->EvaluateIntFlowNestedLoops(anEvent);} 
613
614  // m) Cross-check with nested loops correlators for differential flow:
615  if(fEvaluateDiffFlowNestedLoops){this->EvaluateDiffFlowNestedLoops(anEvent);} 
616  
617  // n) Reset all event-by-event quantities (very important !!!!):
618  this->ResetEventByEventQuantities();
619  
620 } // end of AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
621
622 //================================================================================================================================
623
624 void AliFlowAnalysisWithQCumulants::Finish()
625 {
626  // Calculate the final results.
627  
628  // a) Check all pointers used in this method;
629  // b) Acces the constants;
630  // c) Access the flags;
631  // d) Calculate reference cumulants (not corrected for detector effects);
632  // e) Correct reference cumulants for detector effects;
633  // f) Calculate reference flow;
634  // g) Store results for reference flow in AliFlowCommonHistResults and print them on the screen;
635  // h) Calculate the final results for differential flow (without/with weights);
636  // i) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA);
637  // j) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults;
638  // k) Store results for differential flow in AliFlowCommonHistResults;
639  // l) Print the final results for integrated flow (RP/POI) on the screen; 
640  // m) Cross-checking: Results from Q-vectors vs results from nested loops.
641  
642  // a) Check all pointers used in this method:
643  this->CheckPointersUsedInFinish();
644   
645  // b) Acces the constants:
646  this->CommonConstants("Finish");          
647  
648  if(fCommonHists && fCommonHists->GetHarmonic()) // to be improved (moved somewhere else)
649  {
650   fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
651  } 
652  
653  // c) Access the flags: // to be improved (implement a method for this? should I store again the flags becose they can get modified with redoFinish?)
654  fUsePhiWeights = (Bool_t)fUseParticleWeights->GetBinContent(1); 
655  fUsePtWeights = (Bool_t)fUseParticleWeights->GetBinContent(2); 
656  fUseEtaWeights = (Bool_t)fUseParticleWeights->GetBinContent(3);  
657  fUseTrackWeights = (Bool_t)fUseParticleWeights->GetBinContent(4);  
658  fApplyCorrectionForNUA = (Bool_t)fIntFlowFlags->GetBinContent(3); 
659  fPrintFinalResults[0] = (Bool_t)fIntFlowFlags->GetBinContent(4);
660  fPrintFinalResults[1] = (Bool_t)fIntFlowFlags->GetBinContent(5);
661  fPrintFinalResults[2] = (Bool_t)fIntFlowFlags->GetBinContent(6);
662  fPrintFinalResults[3] = (Bool_t)fIntFlowFlags->GetBinContent(7);
663  fApplyCorrectionForNUAVsM = (Bool_t)fIntFlowFlags->GetBinContent(8);  
664  fPropagateErrorAlsoFromNIT = (Bool_t)fIntFlowFlags->GetBinContent(9);  
665  fCalculateCumulantsVsM = (Bool_t)fIntFlowFlags->GetBinContent(10); 
666  fMinimumBiasReferenceFlow = (Bool_t)fIntFlowFlags->GetBinContent(11); 
667  fForgetAboutCovariances = (Bool_t)fIntFlowFlags->GetBinContent(12);
668  fStorePhiDistributionForOneEvent = (Bool_t)fIntFlowFlags->GetBinContent(13);
669  fFillMultipleControlHistograms = (Bool_t)fIntFlowFlags->GetBinContent(14); 
670  fCalculateAllCorrelationsVsM = (Bool_t)fIntFlowFlags->GetBinContent(15);
671  fEvaluateIntFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(1);
672  fEvaluateDiffFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(2); 
673  fCrossCheckInPtBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(3);
674  fCrossCheckInEtaBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(4); 
675           
676  // d) Calculate reference cumulants (not corrected for detector effects):
677  this->FinalizeCorrelationsIntFlow();
678  this->CalculateCovariancesIntFlow();
679  this->CalculateCumulantsIntFlow();
680
681  // e) Correct reference cumulants for detector effects:
682  this->FinalizeCorrectionTermsForNUAIntFlow();
683  this->CalculateCovariancesNUAIntFlow(); 
684  this->CalculateQcumulantsCorrectedForNUAIntFlow();  
685
686  // f) Calculate reference flow:
687  this->CalculateReferenceFlow(); 
688   
689  // g) Store results for reference flow in AliFlowCommonHistResults and print them on the screen:
690  this->FillCommonHistResultsIntFlow();  
691  if(fPrintFinalResults[0]){this->PrintFinalResultsForIntegratedFlow("RF");}
692  if(fPrintFinalResults[3] && fCalculateCumulantsVsM){this->PrintFinalResultsForIntegratedFlow("RF, rebinned in M");}
693  
694  // h) Calculate the final results for differential flow (without/with weights):
695  if(fCalculateDiffFlow)
696  {
697   this->FinalizeReducedCorrelations("RP","Pt"); 
698   if(fCalculateDiffFlowVsEta){this->FinalizeReducedCorrelations("RP","Eta");} 
699   this->FinalizeReducedCorrelations("POI","Pt"); 
700   if(fCalculateDiffFlowVsEta){this->FinalizeReducedCorrelations("POI","Eta");}
701   this->CalculateDiffFlowCovariances("RP","Pt");
702   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCovariances("RP","Eta");}
703   this->CalculateDiffFlowCovariances("POI","Pt");
704   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCovariances("POI","Eta");}
705   this->CalculateDiffFlowCumulants("RP","Pt");
706   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCumulants("RP","Eta");}
707   this->CalculateDiffFlowCumulants("POI","Pt");
708   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCumulants("POI","Eta");}
709   this->CalculateDiffFlow("RP","Pt");
710   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlow("RP","Eta");}
711   this->CalculateDiffFlow("POI","Pt");
712   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlow("POI","Eta");}
713  } // if(fCalculateDiffFlow)
714  
715  // i) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA):
716  if(fCalculateDiffFlow)
717  {
718   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Pt");
719   if(fCalculateDiffFlowVsEta){this->FinalizeCorrectionTermsForNUADiffFlow("RP","Eta");}
720   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Pt");
721   if(fCalculateDiffFlowVsEta){this->FinalizeCorrectionTermsForNUADiffFlow("POI","Eta");}      
722   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Pt");   
723   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Eta");}   
724   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Pt");   
725   if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Eta");}  
726   if(fApplyCorrectionForNUA)
727   {
728    this->CalculateDiffFlowCorrectedForNUA("RP","Pt"); 
729    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectedForNUA("RP","Eta");} 
730    this->CalculateDiffFlowCorrectedForNUA("POI","Pt"); 
731    if(fCalculateDiffFlowVsEta){this->CalculateDiffFlowCorrectedForNUA("POI","Eta");} 
732   }
733  } // end of if(fCalculateDiffFlow && fApplyCorrectionForNUA)
734  
735  // i) Calcualate final results for 2D differential flow: 
736  if(fCalculate2DDiffFlow)
737  {
738   this->Calculate2DDiffFlowCumulants("RP");
739   this->Calculate2DDiffFlowCumulants("POI");
740   this->Calculate2DDiffFlow("RP");  
741   this->Calculate2DDiffFlow("POI");  
742  } // end of if(fCalculate2DDiffFlow)
743     
744  // j) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults:
745  if(fCalculateDiffFlow)
746  {
747   this->CalculateFinalResultsForRPandPOIIntegratedFlow("RP");
748   this->CalculateFinalResultsForRPandPOIIntegratedFlow("POI");
749  }
750  
751  // k) Store results for differential flow in AliFlowCommonHistResults:
752  if(fCalculateDiffFlow)
753  {
754   this->FillCommonHistResultsDiffFlow("RP");
755   this->FillCommonHistResultsDiffFlow("POI");
756  }
757  
758  // l) Print the final results for integrated flow (RP/POI) on the screen:
759  if(fPrintFinalResults[1] && fCalculateDiffFlow){this->PrintFinalResultsForIntegratedFlow("RP");} 
760  if(fPrintFinalResults[2] && fCalculateDiffFlow){this->PrintFinalResultsForIntegratedFlow("POI");}
761     
762  // m) Cross-checking: Results from Q-vectors vs results from nested loops:
763  //  m1) Reference flow:
764  if(fEvaluateIntFlowNestedLoops)
765  {
766   this->CrossCheckIntFlowCorrelations();
767   this->CrossCheckIntFlowCorrectionTermsForNUA(); 
768   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights){this->CrossCheckIntFlowExtraCorrelations();}     
769  } // end of if(fEvaluateIntFlowNestedLoops)  
770  //  m2) Differential flow: 
771  if(fEvaluateDiffFlowNestedLoops && fCalculateDiffFlow) 
772  {
773   // Correlations:
774   this->PrintNumberOfParticlesInSelectedBin();
775   this->CrossCheckDiffFlowCorrelations("RP","Pt");  
776   if(fCalculateDiffFlowVsEta){this->CrossCheckDiffFlowCorrelations("RP","Eta");} 
777   this->CrossCheckDiffFlowCorrelations("POI","Pt");  
778   if(fCalculateDiffFlowVsEta){this->CrossCheckDiffFlowCorrelations("POI","Eta");}
779   // Correction terms for non-uniform acceptance:
780   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Pt");      
781   if(fCalculateDiffFlowVsEta){this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Eta");}       
782   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Pt");      
783   if(fCalculateDiffFlowVsEta){this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Eta");}
784   // Other differential correlators:       
785   this->CrossCheckOtherDiffCorrelators("RP","Pt");  
786   if(fCalculateDiffFlowVsEta){this->CrossCheckOtherDiffCorrelators("RP","Eta");} 
787   this->CrossCheckOtherDiffCorrelators("POI","Pt");  
788   if(fCalculateDiffFlowVsEta){this->CrossCheckOtherDiffCorrelators("POI","Eta");}
789  } // end of if(fEvaluateDiffFlowNestedLoops)
790                                                                                                                                                                                                                                                                                                                                    
791 } // end of AliFlowAnalysisWithQCumulants::Finish()
792
793 //================================================================================================================================
794
795 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowNestedLoops(AliFlowEventSimple* anEvent)
796 {
797  // Evalauted all correlators for reference flow with nested loops.
798  
799  Int_t nPrim = anEvent->NumberOfTracks(); // nPrim = nRP + nPOI 
800  if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10 
801  {
802   // Without using particle weights:
803   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
804   {
805    // Correlations:
806    this->CalculateIntFlowCorrelations(); // from Q-vectors
807    this->EvaluateIntFlowCorrelationsWithNestedLoops(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
808    // Correction for non-uniform acceptance:
809    this->CalculateIntFlowCorrectionsForNUASinTerms(); // from Q-vectors (sin terms)
810    this->CalculateIntFlowCorrectionsForNUACosTerms(); // from Q-vectors (cos terms)
811    this->EvaluateIntFlowCorrectionsForNUAWithNestedLoops(anEvent); // from nested loops (both sin and cos terms)
812   }
813   // Using particle weights:
814   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
815   {
816    // Correlations
817    this->CalculateIntFlowCorrelationsUsingParticleWeights(); // from Q-vectors
818    this->EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
819    // Correction for non-uniform acceptance:
820    this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights(); // from Q-vectors (sin terms)
821    this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights(); // from Q-vectors (cos terms)
822    this->EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (both sin and cos terms)   
823   }
824  } else if(nPrim>fMaxAllowedMultiplicity) // to if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity)
825    {
826     cout<<endl;
827     cout<<"Skipping the event because multiplicity is "<<nPrim<<". Too high to evaluate nested loops!"<<endl;
828    } else
829      {
830       cout<<endl;
831       cout<<"Skipping the event because multiplicity is "<<nPrim<<"."<<endl;      
832      } 
833
834 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowNestedLoops(AliFlowEventSimple* anEvent)
835
836 //================================================================================================================================
837
838 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowNestedLoops(AliFlowEventSimple* anEvent)
839 {
840  // Evalauted all correlators for differential flow with nested loops.
841
842  if(!fCalculateDiffFlow){return;}
843
844  Int_t nPrim = anEvent->NumberOfTracks(); // nPrim = nRP + nPOI 
845  if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
846  {
847   // Without using particle weights:
848   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
849   {
850    // 1.) Reduced correlations:
851    //  Q-vectors:
852    this->CalculateDiffFlowCorrelations("RP","Pt");
853    this->CalculateDiffFlowCorrelations("RP","Eta");
854    this->CalculateDiffFlowCorrelations("POI","Pt");
855    this->CalculateDiffFlowCorrelations("POI","Eta");
856    //  Nested loops:
857    this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Pt"); 
858    this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Eta"); 
859    this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Pt"); 
860    this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Eta"); 
861    // 2.) Reduced corrections for non-uniform acceptance:
862    //  Q-vectors:
863    this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
864    this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");
865    this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
866    this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");
867    this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
868    this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");
869    this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
870    this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");
871    //  Nested loops:
872    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Pt");
873    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Eta");
874    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Pt"); 
875    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Eta"); 
876    // 3.) Other differential correlators:
877    //  Q-vectors:
878    this->CalculateOtherDiffCorrelators("RP","Pt");
879    this->CalculateOtherDiffCorrelators("RP","Eta");
880    this->CalculateOtherDiffCorrelators("POI","Pt");
881    this->CalculateOtherDiffCorrelators("POI","Eta");   
882    //  Nested loops:
883    this->EvaluateOtherDiffCorrelatorsWithNestedLoops(anEvent,"RP","Pt");
884    this->EvaluateOtherDiffCorrelatorsWithNestedLoops(anEvent,"RP","Eta");
885    this->EvaluateOtherDiffCorrelatorsWithNestedLoops(anEvent,"POI","Pt");
886    this->EvaluateOtherDiffCorrelatorsWithNestedLoops(anEvent,"POI","Eta");   
887   } // end of if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
888   // Using particle weights:
889   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
890   {
891    this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
892    this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta"); 
893    this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
894    this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta"); 
895    this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
896    this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");
897    this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
898    this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");
899    this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
900    this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");
901    this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
902    this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");
903    this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
904    this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta");
905    this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
906    this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta");   
907    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
908    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta"); 
909    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
910    this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta"); 
911   } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
912  } // end of if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
913
914 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowNestedLoops(AliFlowEventSimple* anEvent)
915
916 //================================================================================================================================
917
918 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
919 {
920  // Calculate correction terms for non-uniform acceptance of the detector for reference flow (cos terms).
921  
922  // multiplicity:
923  Double_t dMult = (*fSpk)(0,0);
924  
925  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
926  Double_t dReQ1n = (*fReQ)(0,0);
927  Double_t dReQ2n = (*fReQ)(1,0);
928  //Double_t dReQ3n = (*fReQ)(2,0);
929  //Double_t dReQ4n = (*fReQ)(3,0);
930  Double_t dImQ1n = (*fImQ)(0,0);
931  Double_t dImQ2n = (*fImQ)(1,0);
932  //Double_t dImQ3n = (*fImQ)(2,0);
933  //Double_t dImQ4n = (*fImQ)(3,0);
934         
935  //                                  *************************************************************
936  //                                  **** corrections for non-uniform acceptance (cos terms): ****
937  //                                  *************************************************************
938  //
939  // Remark 1: corrections for non-uniform acceptance (cos terms) calculated with non-weighted Q-vectors 
940  //           are stored in 1D profile fQCorrectionsCos.
941  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
942  // --------------------------------------------------------------------------------------------------------------------
943  // 1st bin: <<cos(n*(phi1))>> = cosP1n
944  // 2nd bin: <<cos(n*(phi1+phi2))>> = cosP1nP1n
945  // 3rd bin: <<cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1n
946  // 4th bin: <<cos(n*(2phi1-phi2))>> = cosP2nM1n
947  // --------------------------------------------------------------------------------------------------------------------
948   
949  // 1-particle:
950  Double_t cosP1n = 0.; // <<cos(n*(phi1))>>
951    
952  if(dMult>0)
953  {
954   cosP1n = dReQ1n/dMult; 
955   
956   // average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
957   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1n);
958   // event weights for NUA terms:
959   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(1,dMult);
960   
961   // final average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
962   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1n,dMult);  
963   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][0]->Fill(dMult+0.5,cosP1n,dMult);}    
964  } 
965  
966  // 2-particle:
967  Double_t cosP1nP1n = 0.; // <<cos(n*(phi1+phi2))>>
968  Double_t cosP2nM1n = 0.; // <<cos(n*(2phi1-phi2))>>
969  
970  if(dMult>1)
971  {
972   cosP1nP1n = (pow(dReQ1n,2)-pow(dImQ1n,2)-dReQ2n)/(dMult*(dMult-1)); 
973   cosP2nM1n = (dReQ2n*dReQ1n+dImQ2n*dImQ1n-dReQ1n)/(dMult*(dMult-1)); 
974   
975   // average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
976   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1n);
977   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(4,cosP2nM1n);
978   // event weights for NUA terms:
979   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(2,dMult*(dMult-1));
980   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(4,dMult*(dMult-1));
981       
982   // final average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
983   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1n,dMult*(dMult-1));  
984   fIntFlowCorrectionTermsForNUAPro[1]->Fill(3.5,cosP2nM1n,dMult*(dMult-1));
985   if(fCalculateCumulantsVsM)
986   {
987    fIntFlowCorrectionTermsForNUAVsMPro[1][1]->Fill(dMult+0.5,cosP1nP1n,dMult*(dMult-1));  
988    fIntFlowCorrectionTermsForNUAVsMPro[1][3]->Fill(dMult+0.5,cosP2nM1n,dMult*(dMult-1));
989   }
990  } 
991  
992  // 3-particle:
993  Double_t cosP1nM1nM1n = 0.; // <<cos(n*(phi1-phi2-phi3))>>
994  
995  if(dMult>2)
996  {
997   cosP1nM1nM1n = (dReQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))-dReQ1n*dReQ2n-dImQ1n*dImQ2n-2.*(dMult-1)*dReQ1n)
998                / (dMult*(dMult-1)*(dMult-2)); 
999   
1000   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
1001   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1n);
1002   // event weights for NUA terms:
1003   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
1004   
1005   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
1006   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
1007   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][2]->Fill(dMult+0.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
1008  } 
1009  
1010 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
1011
1012
1013 //================================================================================================================================
1014
1015
1016 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
1017 {
1018  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
1019  
1020  // multiplicity:
1021  Double_t dMult = (*fSpk)(0,0);
1022  
1023  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
1024  Double_t dReQ1n = (*fReQ)(0,0);
1025  Double_t dReQ2n = (*fReQ)(1,0);
1026  //Double_t dReQ3n = (*fReQ)(2,0);
1027  //Double_t dReQ4n = (*fReQ)(3,0);
1028  Double_t dImQ1n = (*fImQ)(0,0);
1029  Double_t dImQ2n = (*fImQ)(1,0);
1030  //Double_t dImQ3n = (*fImQ)(2,0);
1031  //Double_t dImQ4n = (*fImQ)(3,0);
1032         
1033  //                                  *************************************************************
1034  //                                  **** corrections for non-uniform acceptance (sin terms): ****
1035  //                                  *************************************************************
1036  //
1037  // Remark 1: corrections for non-uniform acceptance (sin terms) calculated with non-weighted Q-vectors 
1038  //           are stored in 1D profile fQCorrectionsSin.
1039  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
1040  // --------------------------------------------------------------------------------------------------------------------
1041  // 1st bin: <<sin(n*(phi1))>> = sinP1n
1042  // 2nd bin: <<sin(n*(phi1+phi2))>> = sinP1nP1n
1043  // 3rd bin: <<sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1n
1044  // 4th bin: <<sin(n*(2phi1-phi2))>> = sinP2nM1n
1045  // --------------------------------------------------------------------------------------------------------------------
1046  
1047  // 1-particle:
1048  Double_t sinP1n = 0.; // <sin(n*(phi1))>
1049  
1050  if(dMult>0)
1051  {
1052   sinP1n = dImQ1n/dMult; 
1053      
1054   // average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
1055   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1n);  
1056   // event weights for NUA terms:
1057   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(1,dMult);
1058   
1059   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
1060   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1n,dMult);  
1061   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][0]->Fill(dMult+0.5,sinP1n,dMult);} 
1062  } 
1063  
1064  // 2-particle:
1065  Double_t sinP1nP1n = 0.; // <<sin(n*(phi1+phi2))>>
1066  Double_t sinP2nM1n = 0.; // <<sin(n*(2phi1-phi2))>>
1067  if(dMult>1)
1068  {
1069   sinP1nP1n = (2.*dReQ1n*dImQ1n-dImQ2n)/(dMult*(dMult-1)); 
1070   sinP2nM1n = (dImQ2n*dReQ1n-dReQ2n*dImQ1n-dImQ1n)/(dMult*(dMult-1)); 
1071      
1072   // average non-weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
1073   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1n);
1074   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(4,sinP2nM1n);
1075   // event weights for NUA terms:
1076   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(2,dMult*(dMult-1));
1077   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(4,dMult*(dMult-1));
1078   
1079   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
1080   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1n,dMult*(dMult-1));  
1081   fIntFlowCorrectionTermsForNUAPro[0]->Fill(3.5,sinP2nM1n,dMult*(dMult-1));  
1082   if(fCalculateCumulantsVsM)
1083   {
1084    fIntFlowCorrectionTermsForNUAVsMPro[0][1]->Fill(dMult+0.5,sinP1nP1n,dMult*(dMult-1));  
1085    fIntFlowCorrectionTermsForNUAVsMPro[0][3]->Fill(dMult+0.5,sinP2nM1n,dMult*(dMult-1));    
1086   }
1087  } 
1088  
1089  // 3-particle:
1090  Double_t sinP1nM1nM1n = 0.; // <<sin(n*(phi1-phi2-phi3))>>
1091  
1092  if(dMult>2)
1093  {
1094   sinP1nM1nM1n = (-dImQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))+dReQ1n*dImQ2n-dImQ1n*dReQ2n+2.*(dMult-1)*dImQ1n)
1095                / (dMult*(dMult-1)*(dMult-2)); 
1096   
1097   // average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
1098   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1n);
1099   // event weights for NUA terms:
1100   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
1101   
1102   // final average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
1103   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
1104   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][2]->Fill(dMult+0.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
1105  } 
1106  
1107 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
1108
1109 //================================================================================================================================
1110
1111 void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1112 {
1113  // a) Get pointers for common control and common result histograms;
1114  // b) Get pointers for histograms holding particle weights;
1115  // c) Get pointers for reference flow histograms;
1116  // d) Get pointers for differential flow histograms;
1117  // e) Get pointers for 2D differential flow histograms;
1118  // f) Get pointers for other differential correlators;
1119  // g) Get pointers for nested loops' histograms.
1120  
1121  if(outputListHistos)
1122  {      
1123   this->SetHistList(outputListHistos);
1124   if(!fHistList)
1125   {
1126    printf("\n WARNING (QC): fHistList is NULL in AFAWQC::GOH() !!!!\n\n");
1127    exit(0);
1128   }
1129   this->GetPointersForCommonHistograms(); 
1130   this->GetPointersForParticleWeightsHistograms(); 
1131   this->GetPointersForIntFlowHistograms();
1132   this->GetPointersForDiffFlowHistograms(); 
1133   this->GetPointersFor2DDiffFlowHistograms(); 
1134   this->GetPointersForOtherDiffCorrelators();  
1135   this->GetPointersForNestedLoopsHistograms(); 
1136  } else 
1137    {
1138     printf("\n WARNING (QC): outputListHistos is NULL in AFAWQC::GOH() !!!!\n\n");
1139     exit(0);
1140    }
1141    
1142 } // end of void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1143
1144 //================================================================================================================================
1145
1146 TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta) const
1147 {
1148  // project 2D profile onto pt axis to get 1D profile
1149  
1150  Int_t nBinsPt   = profilePtEta->GetNbinsX();
1151  Double_t dPtMin = (profilePtEta->GetXaxis())->GetXmin();
1152  Double_t dPtMax = (profilePtEta->GetXaxis())->GetXmax();
1153  
1154  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1155  
1156  TProfile *profilePt = new TProfile("","",nBinsPt,dPtMin,dPtMax); 
1157  
1158  for(Int_t p=1;p<=nBinsPt;p++)
1159  {
1160   Double_t contentPt = 0.;
1161   Double_t entryPt = 0.;
1162   Double_t spreadPt = 0.;
1163   Double_t sum1 = 0.;
1164   Double_t sum2 = 0.;
1165   Double_t sum3 = 0.;
1166   for(Int_t e=1;e<=nBinsEta;e++)
1167   {
1168    contentPt += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1169               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1170    entryPt   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1171    
1172    sum1 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1173          * (pow(profilePtEta->GetBinError(profilePtEta->GetBin(p,e)),2.)
1174             + pow(profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)),2.)); 
1175    sum2 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1176    sum3 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1177          * (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)));            
1178   }
1179   if(sum2>0. && sum1/sum2-pow(sum3/sum2,2.) > 0.)
1180   {
1181    spreadPt = pow(sum1/sum2-pow(sum3/sum2,2.),0.5);
1182   }
1183   profilePt->SetBinContent(p,contentPt);
1184   profilePt->SetBinEntries(p,entryPt);
1185   {
1186    profilePt->SetBinError(p,spreadPt);
1187   }
1188   
1189  }
1190  
1191  return profilePt;
1192  
1193 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta)
1194
1195
1196 //================================================================================================================================
1197
1198
1199 TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta) const
1200 {
1201  // project 2D profile onto eta axis to get 1D profile
1202  
1203  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1204  Double_t dEtaMin = (profilePtEta->GetYaxis())->GetXmin();
1205  Double_t dEtaMax = (profilePtEta->GetYaxis())->GetXmax();
1206  
1207  Int_t nBinsPt = profilePtEta->GetNbinsX();
1208  
1209  TProfile *profileEta = new TProfile("","",nBinsEta,dEtaMin,dEtaMax); 
1210  
1211  for(Int_t e=1;e<=nBinsEta;e++)
1212  {
1213   Double_t contentEta = 0.;
1214   Double_t entryEta = 0.;
1215   for(Int_t p=1;p<=nBinsPt;p++)
1216   {
1217    contentEta += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1218               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1219    entryEta   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1220   }
1221   profileEta->SetBinContent(e,contentEta);
1222   profileEta->SetBinEntries(e,entryEta);
1223  }
1224  
1225  return profileEta;
1226  
1227 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta)
1228
1229 //================================================================================================================================
1230
1231 void AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type)
1232 {
1233  // Printing on the screen the final results for integrated flow (RF, POI and RP). 
1234  
1235  Int_t n = fHarmonic; 
1236  
1237  Double_t dVn[4] = {0.}; // array to hold Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1238  Double_t dVnErr[4] = {0.}; // array to hold errors of Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1239  
1240  if(type == "RF")
1241  {
1242   for(Int_t b=0;b<4;b++)
1243   {
1244    dVn[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinContent(1); 
1245    dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinError(1); 
1246    dVn[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinContent(1); 
1247    dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinError(1); 
1248    dVn[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinContent(1); 
1249    dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinError(1); 
1250    dVn[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinContent(1); 
1251    dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinError(1);    
1252   }  
1253  } else if(type == "RP")
1254    {
1255     dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinContent(1); 
1256     dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinError(1); 
1257     dVn[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinContent(1); 
1258     dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinError(1); 
1259     dVn[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinContent(1); 
1260     dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinError(1); 
1261     dVn[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinContent(1); 
1262     dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinError(1); 
1263    } else if(type == "POI")
1264      {
1265       dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinContent(1); 
1266       dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinError(1); 
1267       dVn[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinContent(1); 
1268       dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinError(1); 
1269       dVn[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinContent(1); 
1270       dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinError(1); 
1271       dVn[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinContent(1); 
1272       dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinError(1); 
1273      } else if(type == "RF, rebinned in M" && fCalculateCumulantsVsM)
1274        {
1275         for(Int_t b=0;b<4;b++)
1276         {
1277          dVn[b] = fIntFlowRebinnedInM->GetBinContent(b+1); 
1278          dVnErr[b] = fIntFlowRebinnedInM->GetBinError(b+1);
1279         }  
1280        }
1281  
1282  TString title = " flow estimates from Q-cumulants"; 
1283  TString subtitle = "    ("; 
1284  TString subtitle2 = "       (rebinned in M)"; 
1285  
1286  if(type != "RF, rebinned in M")
1287  {
1288   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
1289   {
1290    subtitle.Append(type);
1291    subtitle.Append(", without weights)");
1292   } else  
1293     {
1294      subtitle.Append(type);
1295      subtitle.Append(", with weights)");
1296     }
1297  } else
1298    {
1299     if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
1300     {
1301      subtitle.Append("RF");
1302      subtitle.Append(", without weights)");
1303     } else  
1304       {
1305        subtitle.Append("RF");
1306        subtitle.Append(", with weights)");      
1307       }
1308    } 
1309    
1310  cout<<endl;
1311  cout<<"*************************************"<<endl;
1312  cout<<"*************************************"<<endl;
1313  cout<<title.Data()<<endl; 
1314  cout<<subtitle.Data()<<endl; 
1315  if(type == "RF, rebinned in M"){cout<<subtitle2.Data()<<endl;}
1316  cout<<endl;
1317   
1318  for(Int_t i=0;i<4;i++)
1319  {
1320   cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = "<<dVn[i]<<" +/- "<<dVnErr[i]<<endl;
1321  }
1322  
1323  cout<<endl;
1324  if(type == "RF")
1325  {
1326   if(fApplyCorrectionForNUA)
1327   {
1328    cout<<" detector bias (corrected for): "<<endl;
1329   } else
1330     {
1331      cout<<" detector bias (not corrected for):"<<endl;  
1332     }
1333   cout<<"  to QC{2}: "<<fIntFlowDetectorBias->GetBinContent(1)<<" +/- "<<fIntFlowDetectorBias->GetBinError(1)<<endl;
1334   cout<<"  to QC{4}: "<<fIntFlowDetectorBias->GetBinContent(2)<<" +/- "<<fIntFlowDetectorBias->GetBinError(2)<<endl;
1335   cout<<endl;
1336  }
1337  if(type == "RF" || type == "RF, rebinned in M")
1338  {
1339   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl; 
1340  }
1341  else if (type == "RP")
1342  {
1343   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl;  
1344  } 
1345  else if (type == "POI")
1346  {
1347   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultPOI()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultPOI()->GetMean()<<endl;
1348  }  
1349  
1350  cout<<"*************************************"<<endl;
1351  cout<<"*************************************"<<endl;
1352  cout<<endl; 
1353   
1354 }// end of AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type="RF");
1355
1356 //================================================================================================================================
1357
1358 void AliFlowAnalysisWithQCumulants::WriteHistograms(TString outputFileName)
1359 {
1360  //store the final results in output .root file
1361  TFile *output = new TFile(outputFileName.Data(),"RECREATE");
1362  //output->WriteObject(fHistList, "cobjQC","SingleKey");
1363  fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
1364  delete output;
1365 }
1366
1367
1368 //================================================================================================================================
1369
1370
1371 void AliFlowAnalysisWithQCumulants::WriteHistograms(TDirectoryFile *outputFileName)
1372 {
1373  //store the final results in output .root file
1374  fHistList->SetName("cobjQC");
1375  fHistList->SetOwner(kTRUE);
1376  outputFileName->Add(fHistList);
1377  outputFileName->Write(outputFileName->GetName(), TObject::kSingleKey);
1378 }
1379
1380 //================================================================================================================================
1381
1382 void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1383 {
1384  // Book common control histograms and common histograms for final results.
1385  //  a) Book common control histograms;
1386  //  b) Book common result histograms.
1387  
1388  // a) Book common control histograms: 
1389  //  Common control histograms (all events):
1390  TString commonHistsName = "AliFlowCommonHistQC";
1391  commonHistsName += fAnalysisLabel->Data();
1392  fCommonHists = new AliFlowCommonHist(commonHistsName.Data(),commonHistsName.Data(),fBookOnlyBasicCCH);
1393  fHistList->Add(fCommonHists);  
1394  //  Common control histograms (selected events):
1395  if(fFillMultipleControlHistograms)
1396  {
1397   // Common control histogram filled for events with 2 and more reference particles:
1398   TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
1399   commonHists2ndOrderName += fAnalysisLabel->Data();
1400   fCommonHists2nd = new AliFlowCommonHist(commonHists2ndOrderName.Data(),commonHists2ndOrderName.Data(),fBookOnlyBasicCCH);
1401   fHistList->Add(fCommonHists2nd);  
1402   // Common control histogram filled for events with 2 and more reference particles:
1403   TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
1404   commonHists4thOrderName += fAnalysisLabel->Data();
1405   fCommonHists4th = new AliFlowCommonHist(commonHists4thOrderName.Data(),commonHists4thOrderName.Data(),fBookOnlyBasicCCH);
1406   fHistList->Add(fCommonHists4th);  
1407   // Common control histogram filled for events with 6 and more reference particles:
1408   TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
1409   commonHists6thOrderName += fAnalysisLabel->Data();
1410   fCommonHists6th = new AliFlowCommonHist(commonHists6thOrderName.Data(),commonHists6thOrderName.Data(),fBookOnlyBasicCCH);
1411   fHistList->Add(fCommonHists6th);  
1412   // Common control histogram filled for events with 8 and more reference particles:
1413   TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
1414   commonHists8thOrderName += fAnalysisLabel->Data();
1415   fCommonHists8th = new AliFlowCommonHist(commonHists8thOrderName.Data(),commonHists8thOrderName.Data(),fBookOnlyBasicCCH);
1416   fHistList->Add(fCommonHists8th);    
1417  } // end of if(fFillMultipleControlHistograms)
1418  
1419  // b) Book common result histograms: 
1420  //  Common result histograms for QC{2}:
1421  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC";
1422  commonHistResults2ndOrderName += fAnalysisLabel->Data();
1423  fCommonHistsResults2nd = new AliFlowCommonHistResults(commonHistResults2ndOrderName.Data(),"",fHarmonic);
1424  fHistList->Add(fCommonHistsResults2nd);  
1425  //  Common result histograms for QC{4}:
1426  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
1427  commonHistResults4thOrderName += fAnalysisLabel->Data();
1428  fCommonHistsResults4th = new AliFlowCommonHistResults(commonHistResults4thOrderName.Data(),"",fHarmonic);
1429  fHistList->Add(fCommonHistsResults4th); 
1430  //  Common result histograms for QC{6}:
1431  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
1432  commonHistResults6thOrderName += fAnalysisLabel->Data();
1433  fCommonHistsResults6th = new AliFlowCommonHistResults(commonHistResults6thOrderName.Data(),"",fHarmonic);
1434  fHistList->Add(fCommonHistsResults6th);  
1435  //  Common result histograms for QC{8}:
1436  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
1437  commonHistResults8thOrderName += fAnalysisLabel->Data();
1438  fCommonHistsResults8th = new AliFlowCommonHistResults(commonHistResults8thOrderName.Data(),"",fHarmonic);
1439  fHistList->Add(fCommonHistsResults8th); 
1440  
1441 } // end of void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1442
1443 //================================================================================================================================
1444
1445 void AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1446 {
1447  // Book and fill histograms which hold phi, pt and eta weights.
1448
1449  if(!fWeightsList)
1450  {
1451   printf("\n WARNING (QC): fWeightsList is NULL in AFAWQC::BAFWH() !!!! \n\n");
1452   exit(0);  
1453  }
1454     
1455  TString fUseParticleWeightsName = "fUseParticleWeightsQC";
1456  fUseParticleWeightsName += fAnalysisLabel->Data();
1457  fUseParticleWeights = new TProfile(fUseParticleWeightsName.Data(),"0 = particle weight not used, 1 = particle weight used ",4,0,4);
1458  fUseParticleWeights->SetLabelSize(0.06);
1459  (fUseParticleWeights->GetXaxis())->SetBinLabel(1,"w_{#phi}");
1460  (fUseParticleWeights->GetXaxis())->SetBinLabel(2,"w_{p_{T}}");
1461  (fUseParticleWeights->GetXaxis())->SetBinLabel(3,"w_{#eta}");
1462  (fUseParticleWeights->GetXaxis())->SetBinLabel(4,"w_{track}");
1463  fUseParticleWeights->Fill(0.5,(Int_t)fUsePhiWeights);
1464  fUseParticleWeights->Fill(1.5,(Int_t)fUsePtWeights);
1465  fUseParticleWeights->Fill(2.5,(Int_t)fUseEtaWeights);
1466  fUseParticleWeights->Fill(3.5,(Int_t)fUseTrackWeights);
1467  fWeightsList->Add(fUseParticleWeights); 
1468   
1469  if(fUsePhiWeights)
1470  {
1471   if(fWeightsList->FindObject("phi_weights"))
1472   {
1473    fPhiWeights = dynamic_cast<TH1F*>(fWeightsList->FindObject("phi_weights"));
1474    if(!fPhiWeights)
1475    {
1476     printf("\n WARNING (QC): fPhiWeights is NULL in AFAWQC::BAFWH() !!!!\n\n");
1477     exit(0);
1478    }
1479    if(TMath::Abs(fPhiWeights->GetBinWidth(1)-fPhiBinWidth)>pow(10.,-6.))
1480    {
1481     cout<<endl;
1482     cout<<"WARNING (QC): Inconsistent binning in histograms for phi-weights throughout the code."<<endl;
1483     cout<<endl;
1484     //exit(0);
1485    }
1486   } else 
1487     {
1488      cout<<"WARNING: fWeightsList->FindObject(\"phi_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1489      exit(0);
1490     }
1491  } // end of if(fUsePhiWeights)
1492  
1493  if(fUsePtWeights) 
1494  {
1495   if(fWeightsList->FindObject("pt_weights"))
1496   {
1497    fPtWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("pt_weights"));
1498    if(!fPtWeights)
1499    {
1500     printf("\n WARNING (QC): fPtWeights is NULL in AFAWQC::BAFWH() !!!!\n\n");
1501     exit(0);
1502    }
1503    if(TMath::Abs(fPtWeights->GetBinWidth(1)-fPtBinWidth)>pow(10.,-6.))
1504    {
1505     cout<<endl;
1506     cout<<"WARNING (QC): Inconsistent binning in histograms for pt-weights throughout the code."<<endl;
1507     cout<<endl;
1508     //exit(0);
1509    }
1510   } else 
1511     {
1512      cout<<"WARNING: fWeightsList->FindObject(\"pt_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1513      exit(0);
1514     }
1515  } // end of if(fUsePtWeights)    
1516
1517  if(fUseEtaWeights) 
1518  {
1519   if(fWeightsList->FindObject("eta_weights"))
1520   {
1521    fEtaWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("eta_weights"));
1522    if(!fEtaWeights)
1523    {
1524     printf("\n WARNING (QC): fEtaWeights is NULL in AFAWQC::BAFWH() !!!!\n\n");
1525     exit(0);
1526    }
1527    if(TMath::Abs(fEtaWeights->GetBinWidth(1)-fEtaBinWidth)>pow(10.,-6.))
1528    {
1529     cout<<endl;
1530     cout<<"WARNING (QC): Inconsistent binning in histograms for eta-weights throughout the code."<<endl;
1531     cout<<endl;
1532     //exit(0);
1533    }
1534   } else 
1535     {
1536      cout<<"WARNING: fUseEtaWeights && fWeightsList->FindObject(\"eta_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1537      exit(0);
1538     }
1539  } // end of if(fUseEtaWeights)
1540  
1541 } // end of AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1542
1543 //================================================================================================================================
1544
1545 void AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
1546 {
1547  // Book all objects for integrated flow:
1548  //  a) Book profile to hold all flags for integrated flow;
1549  //  b) Book event-by-event quantities;
1550  //  c) Book profiles; // to be improved (comment)
1551  //  d) Book histograms holding the final results.
1552  
1553  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
1554  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data members?)
1555  
1556  // a) Book profile to hold all flags for integrated flow:
1557  TString intFlowFlagsName = "fIntFlowFlags";
1558  intFlowFlagsName += fAnalysisLabel->Data();
1559  fIntFlowFlags = new TProfile(intFlowFlagsName.Data(),"Flags for Integrated Flow",15,0,15);
1560  fIntFlowFlags->SetTickLength(-0.01,"Y");
1561  fIntFlowFlags->SetMarkerStyle(25);
1562  fIntFlowFlags->SetLabelSize(0.04);
1563  fIntFlowFlags->SetLabelOffset(0.02,"Y");
1564  fIntFlowFlags->GetXaxis()->SetBinLabel(1,"Particle Weights");
1565  fIntFlowFlags->GetXaxis()->SetBinLabel(2,"Event Weights");
1566  fIntFlowFlags->GetXaxis()->SetBinLabel(3,"Corrected for NUA?");
1567  fIntFlowFlags->GetXaxis()->SetBinLabel(4,"Print RF results");
1568  fIntFlowFlags->GetXaxis()->SetBinLabel(5,"Print RP results");
1569  fIntFlowFlags->GetXaxis()->SetBinLabel(6,"Print POI results");
1570  fIntFlowFlags->GetXaxis()->SetBinLabel(7,"Print RF (rebinned in M) results");
1571  fIntFlowFlags->GetXaxis()->SetBinLabel(8,"Corrected for NUA vs M?");
1572  fIntFlowFlags->GetXaxis()->SetBinLabel(9,"Propagate errors to v_{n} from correlations?");
1573  fIntFlowFlags->GetXaxis()->SetBinLabel(10,"Calculate cumulants vs M");
1574  fIntFlowFlags->GetXaxis()->SetBinLabel(11,"fMinimumBiasReferenceFlow");
1575  fIntFlowFlags->GetXaxis()->SetBinLabel(12,"fForgetAboutCovariances");
1576  fIntFlowFlags->GetXaxis()->SetBinLabel(13,"fStorePhiDistributionForOneEvent");
1577  fIntFlowFlags->GetXaxis()->SetBinLabel(14,"fFillMultipleControlHistograms");
1578  fIntFlowFlags->GetXaxis()->SetBinLabel(15,"Calculate all correlations vs M");
1579  fIntFlowList->Add(fIntFlowFlags);
1580
1581  // b) Book event-by-event quantities:
1582  // Re[Q_{m*n,k}], Im[Q_{m*n,k}] and S_{p,k}^M: 
1583  fReQ  = new TMatrixD(6,9);
1584  fImQ  = new TMatrixD(6,9);
1585  fSpk = new TMatrixD(8,9);
1586  // average correlations <2>, <4>, <6> and <8> for single event (bining is the same as in fIntFlowCorrelationsPro and fIntFlowCorrelationsHist):
1587  TString intFlowCorrelationsEBEName = "fIntFlowCorrelationsEBE";
1588  intFlowCorrelationsEBEName += fAnalysisLabel->Data();
1589  fIntFlowCorrelationsEBE = new TH1D(intFlowCorrelationsEBEName.Data(),intFlowCorrelationsEBEName.Data(),4,0,4);
1590  // weights for average correlations <2>, <4>, <6> and <8> for single event:
1591  TString intFlowEventWeightsForCorrelationsEBEName = "fIntFlowEventWeightsForCorrelationsEBE";
1592  intFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
1593  fIntFlowEventWeightsForCorrelationsEBE = new TH1D(intFlowEventWeightsForCorrelationsEBEName.Data(),intFlowEventWeightsForCorrelationsEBEName.Data(),4,0,4);
1594  // average all correlations for single event (bining is the same as in fIntFlowCorrelationsAllPro and fIntFlowCorrelationsAllHist):
1595  TString intFlowCorrelationsAllEBEName = "fIntFlowCorrelationsAllEBE";
1596  intFlowCorrelationsAllEBEName += fAnalysisLabel->Data();
1597  fIntFlowCorrelationsAllEBE = new TH1D(intFlowCorrelationsAllEBEName.Data(),intFlowCorrelationsAllEBEName.Data(),64,0,64);
1598  // average correction terms for non-uniform acceptance for single event 
1599  // (binning is the same as in fIntFlowCorrectionTermsForNUAPro[2] and fIntFlowCorrectionTermsForNUAHist[2]):
1600  TString fIntFlowCorrectionTermsForNUAEBEName = "fIntFlowCorrectionTermsForNUAEBE";
1601  fIntFlowCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1602  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1603  {
1604   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);  
1605  }
1606  // event weights for terms for non-uniform acceptance: 
1607  TString fIntFlowEventWeightForCorrectionTermsForNUAEBEName = "fIntFlowEventWeightForCorrectionTermsForNUAEBE";
1608  fIntFlowEventWeightForCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1609  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1610  {
1611   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  
1612  }
1613  // c) Book profiles: // to be improved (comment)
1614  // profile to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8:
1615  TString avMultiplicityName = "fAvMultiplicity";
1616  avMultiplicityName += fAnalysisLabel->Data();
1617  fAvMultiplicity = new TProfile(avMultiplicityName.Data(),"Average multiplicities of reference particles (RPs)",9,0,9);
1618  fAvMultiplicity->SetTickLength(-0.01,"Y");
1619  fAvMultiplicity->SetMarkerStyle(25);
1620  fAvMultiplicity->SetLabelSize(0.05);
1621  fAvMultiplicity->SetLabelOffset(0.02,"Y");
1622  fAvMultiplicity->SetYTitle("Average multiplicity");
1623  (fAvMultiplicity->GetXaxis())->SetBinLabel(1,"all evts");
1624  (fAvMultiplicity->GetXaxis())->SetBinLabel(2,"n_{RP} #geq 1");
1625  (fAvMultiplicity->GetXaxis())->SetBinLabel(3,"n_{RP} #geq 2");
1626  (fAvMultiplicity->GetXaxis())->SetBinLabel(4,"n_{RP} #geq 3");
1627  (fAvMultiplicity->GetXaxis())->SetBinLabel(5,"n_{RP} #geq 4");
1628  (fAvMultiplicity->GetXaxis())->SetBinLabel(6,"n_{RP} #geq 5");
1629  (fAvMultiplicity->GetXaxis())->SetBinLabel(7,"n_{RP} #geq 6");
1630  (fAvMultiplicity->GetXaxis())->SetBinLabel(8,"n_{RP} #geq 7");
1631  (fAvMultiplicity->GetXaxis())->SetBinLabel(9,"n_{RP} #geq 8");
1632  fIntFlowProfiles->Add(fAvMultiplicity);
1633  // Average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with wrong errors!):
1634  TString correlationFlag[4] = {"#LT#LT2#GT#GT","#LT#LT4#GT#GT","#LT#LT6#GT#GT","#LT#LT8#GT#GT"};
1635  TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
1636  intFlowCorrelationsProName += fAnalysisLabel->Data();
1637  fIntFlowCorrelationsPro = new TProfile(intFlowCorrelationsProName.Data(),"Average correlations for all events",4,0,4,"s");
1638  fIntFlowCorrelationsPro->Sumw2();
1639  fIntFlowCorrelationsPro->SetTickLength(-0.01,"Y");
1640  fIntFlowCorrelationsPro->SetMarkerStyle(25);
1641  fIntFlowCorrelationsPro->SetLabelSize(0.06);
1642  fIntFlowCorrelationsPro->SetLabelOffset(0.01,"Y");
1643  for(Int_t b=0;b<4;b++)
1644  {
1645   (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(b+1,correlationFlag[b].Data());
1646  }
1647  fIntFlowProfiles->Add(fIntFlowCorrelationsPro);
1648  // Average correlations squared <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> for all events:
1649  TString squaredCorrelationFlag[4] = {"#LT#LT2#GT^{2}#GT","#LT#LT4#GT^{2}#GT","#LT#LT6#GT^{2}#GT","#LT#LT8#GT^{2}#GT"};
1650  TString intFlowSquaredCorrelationsProName = "fIntFlowSquaredCorrelationsPro";
1651  intFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
1652  fIntFlowSquaredCorrelationsPro = new TProfile(intFlowSquaredCorrelationsProName.Data(),"Average squared correlations for all events",4,0,4,"s");
1653  fIntFlowSquaredCorrelationsPro->Sumw2();
1654  fIntFlowSquaredCorrelationsPro->SetTickLength(-0.01,"Y");
1655  fIntFlowSquaredCorrelationsPro->SetMarkerStyle(25);
1656  fIntFlowSquaredCorrelationsPro->SetLabelSize(0.06);
1657  fIntFlowSquaredCorrelationsPro->SetLabelOffset(0.01,"Y");
1658  for(Int_t b=0;b<4;b++)
1659  {
1660   (fIntFlowSquaredCorrelationsPro->GetXaxis())->SetBinLabel(b+1,squaredCorrelationFlag[b].Data());
1661  }
1662  fIntFlowProfiles->Add(fIntFlowSquaredCorrelationsPro);
1663  if(fCalculateCumulantsVsM)
1664  {
1665   for(Int_t ci=0;ci<4;ci++) // correlation index
1666   {
1667    // average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (with wrong errors):
1668    TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
1669    intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
1670    fIntFlowCorrelationsVsMPro[ci] = new TProfile(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data()),
1671                                                  Form("%s vs multiplicity",correlationFlag[ci].Data()),
1672                                                  fnBinsMult,fMinMult,fMaxMult,"s");   
1673    fIntFlowCorrelationsVsMPro[ci]->Sumw2();                                                                                       
1674    fIntFlowCorrelationsVsMPro[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
1675    fIntFlowCorrelationsVsMPro[ci]->GetXaxis()->SetTitle("M");
1676    fIntFlowProfiles->Add(fIntFlowCorrelationsVsMPro[ci]);
1677    // average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> versus multiplicity for all events:  
1678    TString intFlowSquaredCorrelationsVsMProName = "fIntFlowSquaredCorrelationsVsMPro";
1679    intFlowSquaredCorrelationsVsMProName += fAnalysisLabel->Data();
1680    fIntFlowSquaredCorrelationsVsMPro[ci] = new TProfile(Form("%s, %s",intFlowSquaredCorrelationsVsMProName.Data(),squaredCorrelationFlag[ci].Data()),
1681                                                         Form("%s vs multiplicity",squaredCorrelationFlag[ci].Data()),
1682                                                         fnBinsMult,fMinMult,fMaxMult,"s");   
1683    fIntFlowSquaredCorrelationsVsMPro[ci]->Sumw2();                                                                                              
1684    fIntFlowSquaredCorrelationsVsMPro[ci]->GetYaxis()->SetTitle(squaredCorrelationFlag[ci].Data());
1685    fIntFlowSquaredCorrelationsVsMPro[ci]->GetXaxis()->SetTitle("M");
1686    fIntFlowProfiles->Add(fIntFlowSquaredCorrelationsVsMPro[ci]);
1687   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
1688  } // end of if(fCalculateCumulantsVsM)
1689  // averaged all correlations for all events (with wrong errors!):
1690  TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
1691  intFlowCorrelationsAllProName += fAnalysisLabel->Data();
1692  fIntFlowCorrelationsAllPro = new TProfile(intFlowCorrelationsAllProName.Data(),"Average all correlations for all events",64,0,64);
1693  fIntFlowCorrelationsAllPro->Sumw2();
1694  fIntFlowCorrelationsAllPro->SetTickLength(-0.01,"Y");
1695  fIntFlowCorrelationsAllPro->SetMarkerStyle(25);
1696  fIntFlowCorrelationsAllPro->SetLabelSize(0.03);
1697  fIntFlowCorrelationsAllPro->SetLabelOffset(0.01,"Y");
1698  // 2-p correlations:
1699  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(1,"#LT#LT2#GT#GT_{n|n}");
1700  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(2,"#LT#LT2#GT#GT_{2n|2n}");
1701  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(3,"#LT#LT2#GT#GT_{3n|3n}");
1702  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(4,"#LT#LT2#GT#GT_{4n|4n}");
1703  // 3-p correlations:
1704  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(6,"#LT#LT3#GT#GT_{2n|n,n}");
1705  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(7,"#LT#LT3#GT#GT_{3n|2n,n}");
1706  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(8,"#LT#LT3#GT#GT_{4n|2n,2n}");
1707  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(9,"#LT#LT3#GT#GT_{4n|3n,n}");
1708  // 4-p correlations:
1709  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(11,"#LT#LT4#GT#GT_{n,n|n,n}"); 
1710  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(12,"#LT#LT4#GT#GT_{2n,n|2n,n}");
1711  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(13,"#LT#LT4#GT#GT_{2n,2n|2n,2n}");
1712  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(14,"#LT#LT4#GT#GT_{3n|n,n,n}");
1713  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(15,"#LT#LT4#GT#GT_{3n,n|3n,n}");
1714  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(16,"#LT#LT4#GT#GT_{3n,n|2n,2n}"); 
1715  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(17,"#LT#LT4#GT#GT_{4n|2n,n,n}");
1716  // 5-p correlations:
1717  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(19,"#LT#LT5#GT#GT_{2n,n|n,n,n}"); 
1718  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(20,"#LT#LT5#GT#GT_{2n,2n|2n,n,n}");
1719  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(21,"#LT#LT5#GT#GT_{3n,n|2n,n,n}");
1720  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(22,"#LT#LT5#GT#GT_{4n|n,n,n,n}");
1721  // 6-p correlations:
1722  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(24,"#LT#LT6#GT#GT_{n,n,n|n,n,n}");
1723  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(25,"#LT#LT6#GT#GT_{2n,n,n|2n,n,n}");
1724  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(26,"#LT#LT6#GT#GT_{2n,2n|n,n,n,n}");
1725  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(27,"#LT#LT6#GT#GT_{3n,n|n,n,n,n}");
1726  // 7-p correlations:  
1727  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(29,"#LT#LT7#GT#GT_{2n,n,n|n,n,n,n}");
1728  // 8-p correlations:
1729  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(31,"#LT#LT8#GT#GT_{n,n,n,n|n,n,n,n}");
1730  //  EXTRA correlations for v3{5} study:
1731  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(33,"#LT#LT4#GT#GT_{4n,2n|3n,3n}");
1732  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(34,"#LT#LT5#GT#GT_{3n,3n|2n,2n,2n}");
1733  //  EXTRA correlations for Teaney-Yan study:
1734  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(35,"#LT#LT2#GT#GT_{5n|5n}");
1735  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(36,"#LT#LT2#GT#GT_{6n|6n}");
1736  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(37,"#LT#LT3#GT#GT_{5n|3n,2n}");
1737  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(38,"#LT#LT3#GT#GT_{5n|4n,1n}");
1738  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(39,"#LT#LT3#GT#GT_{6n|3n,3n}");
1739  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(40,"#LT#LT3#GT#GT_{6n|4n,2n}");
1740  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(41,"#LT#LT3#GT#GT_{6n|5n,1n}");
1741  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(42,"#LT#LT4#GT#GT_{6n|3n,2n,1n}");
1742  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(43,"#LT#LT4#GT#GT_{3n,2n|3n,2n}");
1743  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(44,"#LT#LT4#GT#GT_{4n,1n|3n,2n}");
1744  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(45,"#LT#LT4#GT#GT_{3n,3n|3n,3n}");
1745  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(46,"#LT#LT4#GT#GT_{4n,2n|3n,3n}");
1746  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(47,"#LT#LT4#GT#GT_{5n,1n|3n,3n}");
1747  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(48,"#LT#LT4#GT#GT_{4n,2n|4n,2n}");
1748  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(49,"#LT#LT4#GT#GT_{5n,1n|4n,2n}");
1749  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(50,"#LT#LT4#GT#GT_{5n|3n,1n,1n}");
1750  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(51,"#LT#LT4#GT#GT_{5n|2n,2n,1n}");
1751  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(52,"#LT#LT4#GT#GT_{5n,1n|5n,1n}");
1752  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(53,"#LT#LT5#GT#GT_{3n,3n|3n,2n,1n}");
1753  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(54,"#LT#LT5#GT#GT_{4n,2n|3n,2n,1n}");
1754  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(55,"#LT#LT5#GT#GT_{3n,2n|3n,1n,1n}");
1755  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(56,"#LT#LT5#GT#GT_{3n,2n|2n,2n,1n}");
1756  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(57,"#LT#LT5#GT#GT_{5n,1n|3n,2n,1n}");
1757  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(58,"#LT#LT6#GT#GT_{3n,2n,1n|3n,2n,1n}");
1758  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(59,"#LT#LT4#GT#GT_{6n|4n,1n,1n}");
1759  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(60,"#LT#LT4#GT#GT_{6n|2n,2n,2n}");
1760  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(61,"#LT#LT5#GT#GT_{6n|2n,2n,1n,1n}");
1761  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(62,"#LT#LT5#GT#GT_{4n,1n,1n|3n,3n}");
1762  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(63,"#LT#LT6#GT#GT_{3n,3n|2n,2n,1n,1n}");
1763  fIntFlowProfiles->Add(fIntFlowCorrelationsAllPro);
1764  // average all correlations versus multiplicity (errors via Sumw2 - to be improved):
1765  if(fCalculateAllCorrelationsVsM)
1766  {
1767   // 2-p correlations vs M:  
1768   fIntFlowCorrelationsAllVsMPro[0] = new TProfile("two1n1n","#LT#LT2#GT#GT_{n|n}",fnBinsMult,fMinMult,fMaxMult);
1769   fIntFlowCorrelationsAllVsMPro[0]->Sumw2();
1770   fIntFlowCorrelationsAllVsMPro[0]->GetXaxis()->SetTitle("M");  
1771   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[0]);  
1772   fIntFlowCorrelationsAllVsMPro[1] = new TProfile("two2n2n","#LT#LT2#GT#GT_{2n|2n}",fnBinsMult,fMinMult,fMaxMult);
1773   fIntFlowCorrelationsAllVsMPro[1]->Sumw2();
1774   fIntFlowCorrelationsAllVsMPro[1]->GetXaxis()->SetTitle("M");  
1775   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[1]);
1776   fIntFlowCorrelationsAllVsMPro[2] = new TProfile("two3n3n","#LT#LT2#GT#GT_{3n|3n}",fnBinsMult,fMinMult,fMaxMult);
1777   fIntFlowCorrelationsAllVsMPro[2]->Sumw2();
1778   fIntFlowCorrelationsAllVsMPro[2]->GetXaxis()->SetTitle("M");  
1779   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[2]);
1780   fIntFlowCorrelationsAllVsMPro[3] = new TProfile("two4n4n","#LT#LT2#GT#GT_{4n|4n}",fnBinsMult,fMinMult,fMaxMult);
1781   fIntFlowCorrelationsAllVsMPro[3]->Sumw2();
1782   fIntFlowCorrelationsAllVsMPro[3]->GetXaxis()->SetTitle("M");  
1783   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[3]);
1784   // 3-p correlations vs M:
1785   fIntFlowCorrelationsAllVsMPro[5] = new TProfile("three2n1n1n","#LT#LT3#GT#GT_{2n|n,n}",fnBinsMult,fMinMult,fMaxMult);
1786   fIntFlowCorrelationsAllVsMPro[5]->Sumw2();
1787   fIntFlowCorrelationsAllVsMPro[5]->GetXaxis()->SetTitle("M");  
1788   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[5]);
1789   fIntFlowCorrelationsAllVsMPro[6] = new TProfile("three3n2n1n","#LT#LT3#GT#GT_{3n|2n,n}",fnBinsMult,fMinMult,fMaxMult);
1790   fIntFlowCorrelationsAllVsMPro[6]->Sumw2();
1791   fIntFlowCorrelationsAllVsMPro[6]->GetXaxis()->SetTitle("M");  
1792   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[6]);
1793   fIntFlowCorrelationsAllVsMPro[7] = new TProfile("three4n2n2n","#LT#LT3#GT#GT_{4n|2n,2n}",fnBinsMult,fMinMult,fMaxMult);
1794   fIntFlowCorrelationsAllVsMPro[7]->Sumw2();
1795   fIntFlowCorrelationsAllVsMPro[7]->GetXaxis()->SetTitle("M");  
1796   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[7]);
1797   fIntFlowCorrelationsAllVsMPro[8] = new TProfile("three4n3n1n","#LT#LT3#GT#GT_{4n|3n,n}",fnBinsMult,fMinMult,fMaxMult);
1798   fIntFlowCorrelationsAllVsMPro[8]->Sumw2();
1799   fIntFlowCorrelationsAllVsMPro[8]->GetXaxis()->SetTitle("M");  
1800   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[8]);
1801   // 4-p correlations vs M:
1802   fIntFlowCorrelationsAllVsMPro[10] = new TProfile("four1n1n1n1n","#LT#LT4#GT#GT_{n,n|n,n}",fnBinsMult,fMinMult,fMaxMult);
1803   fIntFlowCorrelationsAllVsMPro[10]->Sumw2();
1804   fIntFlowCorrelationsAllVsMPro[10]->GetXaxis()->SetTitle("M");  
1805   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[10]);
1806   fIntFlowCorrelationsAllVsMPro[11] = new TProfile("four2n1n2n1n","#LT#LT4#GT#GT_{2n,n|2n,n}",fnBinsMult,fMinMult,fMaxMult);
1807   fIntFlowCorrelationsAllVsMPro[11]->Sumw2();
1808   fIntFlowCorrelationsAllVsMPro[11]->GetXaxis()->SetTitle("M");  
1809   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[11]);
1810   fIntFlowCorrelationsAllVsMPro[12] = new TProfile("four2n2n2n2n","#LT#LT4#GT#GT_{2n,2n|2n,2n}",fnBinsMult,fMinMult,fMaxMult);
1811   fIntFlowCorrelationsAllVsMPro[12]->Sumw2();
1812   fIntFlowCorrelationsAllVsMPro[12]->GetXaxis()->SetTitle("M");  
1813   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[12]);
1814   fIntFlowCorrelationsAllVsMPro[13] = new TProfile("four3n1n1n1n","#LT#LT4#GT#GT_{3n|n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1815   fIntFlowCorrelationsAllVsMPro[13]->Sumw2();
1816   fIntFlowCorrelationsAllVsMPro[13]->GetXaxis()->SetTitle("M");  
1817   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[13]);
1818   fIntFlowCorrelationsAllVsMPro[14] = new TProfile("four3n1n3n1n","#LT#LT4#GT#GT_{3n,n|3n,n}",fnBinsMult,fMinMult,fMaxMult);
1819   fIntFlowCorrelationsAllVsMPro[14]->Sumw2();
1820   fIntFlowCorrelationsAllVsMPro[14]->GetXaxis()->SetTitle("M");  
1821   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[14]);
1822   fIntFlowCorrelationsAllVsMPro[15] = new TProfile("four3n1n2n2n","#LT#LT4#GT#GT_{3n,n|2n,2n}",fnBinsMult,fMinMult,fMaxMult);
1823   fIntFlowCorrelationsAllVsMPro[15]->Sumw2();
1824   fIntFlowCorrelationsAllVsMPro[15]->GetXaxis()->SetTitle("M");  
1825   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[15]);
1826   fIntFlowCorrelationsAllVsMPro[16] = new TProfile("four4n2n1n1n","#LT#LT4#GT#GT_{4n|2n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1827   fIntFlowCorrelationsAllVsMPro[16]->Sumw2();
1828   fIntFlowCorrelationsAllVsMPro[16]->GetXaxis()->SetTitle("M");  
1829   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[16]);
1830   // 5-p correlations vs M:
1831   fIntFlowCorrelationsAllVsMPro[18] = new TProfile("five2n1n1n1n1n","#LT#LT5#GT#GT_{2n,n|n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1832   fIntFlowCorrelationsAllVsMPro[18]->Sumw2();
1833   fIntFlowCorrelationsAllVsMPro[18]->GetXaxis()->SetTitle("M");  
1834   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[18]);
1835   fIntFlowCorrelationsAllVsMPro[19] = new TProfile("five2n2n2n1n1n","#LT#LT5#GT#GT_{2n,2n|2n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1836   fIntFlowCorrelationsAllVsMPro[19]->Sumw2();
1837   fIntFlowCorrelationsAllVsMPro[19]->GetXaxis()->SetTitle("M");  
1838   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[19]);
1839   fIntFlowCorrelationsAllVsMPro[20] = new TProfile("five3n1n2n1n1n","#LT#LT5#GT#GT_{3n,n|2n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1840   fIntFlowCorrelationsAllVsMPro[20]->Sumw2();
1841   fIntFlowCorrelationsAllVsMPro[20]->GetXaxis()->SetTitle("M");  
1842   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[20]);
1843   fIntFlowCorrelationsAllVsMPro[21] = new TProfile("five4n1n1n1n1n","#LT#LT5#GT#GT_{4n|n,n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1844   fIntFlowCorrelationsAllVsMPro[21]->Sumw2();
1845   fIntFlowCorrelationsAllVsMPro[21]->GetXaxis()->SetTitle("M");  
1846   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[21]);
1847   // 6-p correlations vs M:
1848   fIntFlowCorrelationsAllVsMPro[23] = new TProfile("six1n1n1n1n1n1n","#LT#LT6#GT#GT_{n,n,n|n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1849   fIntFlowCorrelationsAllVsMPro[23]->Sumw2();
1850   fIntFlowCorrelationsAllVsMPro[23]->GetXaxis()->SetTitle("M");  
1851   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[23]);
1852   fIntFlowCorrelationsAllVsMPro[24] = new TProfile("six2n1n1n2n1n1n","#LT#LT6#GT#GT_{2n,n,n|2n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1853   fIntFlowCorrelationsAllVsMPro[24]->Sumw2();
1854   fIntFlowCorrelationsAllVsMPro[24]->GetXaxis()->SetTitle("M");  
1855   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[24]);
1856   fIntFlowCorrelationsAllVsMPro[25] = new TProfile("six2n2n1n1n1n1n","#LT#LT6#GT#GT_{2n,2n|n,n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1857   fIntFlowCorrelationsAllVsMPro[25]->Sumw2();
1858   fIntFlowCorrelationsAllVsMPro[25]->GetXaxis()->SetTitle("M");  
1859   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[25]);
1860   fIntFlowCorrelationsAllVsMPro[26] = new TProfile("six3n1n1n1n1n1n","#LT#LT6#GT#GT_{3n,n|n,n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1861   fIntFlowCorrelationsAllVsMPro[26]->Sumw2();
1862   fIntFlowCorrelationsAllVsMPro[26]->GetXaxis()->SetTitle("M");  
1863   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[26]);
1864   // 7-p correlations vs M:
1865   fIntFlowCorrelationsAllVsMPro[28] = new TProfile("seven2n1n1n1n1n1n1n","#LT#LT7#GT#GT_{2n,n,n|n,n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1866   fIntFlowCorrelationsAllVsMPro[28]->Sumw2();
1867   fIntFlowCorrelationsAllVsMPro[28]->GetXaxis()->SetTitle("M");  
1868   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[28]);
1869   // 8-p correlations vs M:
1870   fIntFlowCorrelationsAllVsMPro[30] = new TProfile("eight1n1n1n1n1n1n1n1n","#LT#LT8#GT#GT_{n,n,n,n|n,n,n,n}",fnBinsMult,fMinMult,fMaxMult);
1871   fIntFlowCorrelationsAllVsMPro[30]->Sumw2();
1872   fIntFlowCorrelationsAllVsMPro[30]->GetXaxis()->SetTitle("M");  
1873   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[30]);
1874   // EXTRA correlations vs M for v3{5} study (to be improved - put them in a right order somewhere):
1875   fIntFlowCorrelationsAllVsMPro[32] = new TProfile("four4n2n3n3n","#LT#LT4#GT#GT_{4n,2n|3n,3n}",fnBinsMult,fMinMult,fMaxMult);
1876   fIntFlowCorrelationsAllVsMPro[32]->Sumw2();
1877   fIntFlowCorrelationsAllVsMPro[32]->GetXaxis()->SetTitle("M");  
1878   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[32]);
1879   fIntFlowCorrelationsAllVsMPro[33] = new TProfile("five3n3n2n2n2n","#LT#LT5#GT#GT_{3n,3n|2n,2n,2n}",fnBinsMult,fMinMult,fMaxMult);
1880   fIntFlowCorrelationsAllVsMPro[33]->Sumw2();
1881   fIntFlowCorrelationsAllVsMPro[33]->GetXaxis()->SetTitle("M");  
1882   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[33]);
1883   // EXTRA correlations vs M for Teaney-Yan study (to be improved - put them in a right order somewhere):
1884   fIntFlowCorrelationsAllVsMPro[34] = new TProfile("two5n5n","#LT#LT2#GT#GT_{5n|5n}",fnBinsMult,fMinMult,fMaxMult);
1885   fIntFlowCorrelationsAllVsMPro[34]->Sumw2();
1886   fIntFlowCorrelationsAllVsMPro[34]->GetXaxis()->SetTitle("M");  
1887   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[34]);  
1888   fIntFlowCorrelationsAllVsMPro[35] = new TProfile("two6n6n","#LT#LT2#GT#GT_{6n|6n}",fnBinsMult,fMinMult,fMaxMult);
1889   fIntFlowCorrelationsAllVsMPro[35]->Sumw2();
1890   fIntFlowCorrelationsAllVsMPro[35]->GetXaxis()->SetTitle("M");  
1891   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[35]);  
1892   fIntFlowCorrelationsAllVsMPro[36] = new TProfile("three5n3n2n","#LT#LT3#GT#GT_{5n|3n,2n}",fnBinsMult,fMinMult,fMaxMult);
1893   fIntFlowCorrelationsAllVsMPro[36]->Sumw2();
1894   fIntFlowCorrelationsAllVsMPro[36]->GetXaxis()->SetTitle("M");  
1895   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[36]); 
1896   fIntFlowCorrelationsAllVsMPro[37] = new TProfile("three5n4n1n","#LT#LT3#GT#GT_{5n|4n,1n}",fnBinsMult,fMinMult,fMaxMult);
1897   fIntFlowCorrelationsAllVsMPro[37]->Sumw2();
1898   fIntFlowCorrelationsAllVsMPro[37]->GetXaxis()->SetTitle("M");  
1899   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[37]);
1900   fIntFlowCorrelationsAllVsMPro[38] = new TProfile("three6n3n3n","#LT#LT3#GT#GT_{6n|3n,3n}",fnBinsMult,fMinMult,fMaxMult);
1901   fIntFlowCorrelationsAllVsMPro[38]->Sumw2();
1902   fIntFlowCorrelationsAllVsMPro[38]->GetXaxis()->SetTitle("M");  
1903   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[38]);  
1904   fIntFlowCorrelationsAllVsMPro[39] = new TProfile("three6n4n2n","#LT#LT3#GT#GT_{6n|4n,2n}",fnBinsMult,fMinMult,fMaxMult);
1905   fIntFlowCorrelationsAllVsMPro[39]->Sumw2();
1906   fIntFlowCorrelationsAllVsMPro[39]->GetXaxis()->SetTitle("M");  
1907   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[39]);
1908   fIntFlowCorrelationsAllVsMPro[40] = new TProfile("three6n5n1n","#LT#LT3#GT#GT_{6n|5n,1n}",fnBinsMult,fMinMult,fMaxMult);
1909   fIntFlowCorrelationsAllVsMPro[40]->Sumw2();
1910   fIntFlowCorrelationsAllVsMPro[40]->GetXaxis()->SetTitle("M");  
1911   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[40]);
1912   fIntFlowCorrelationsAllVsMPro[41] = new TProfile("four6n3n2n1n","#LT#LT4#GT#GT_{6n|3n,2n,1n}",fnBinsMult,fMinMult,fMaxMult);
1913   fIntFlowCorrelationsAllVsMPro[41]->Sumw2();
1914   fIntFlowCorrelationsAllVsMPro[41]->GetXaxis()->SetTitle("M");  
1915   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[41]);
1916   fIntFlowCorrelationsAllVsMPro[42] = new TProfile("four3n2n3n2n","#LT#LT4#GT#GT_{3n,2n|3n,2n}",fnBinsMult,fMinMult,fMaxMult);
1917   fIntFlowCorrelationsAllVsMPro[42]->Sumw2();
1918   fIntFlowCorrelationsAllVsMPro[42]->GetXaxis()->SetTitle("M");  
1919   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[42]);
1920   fIntFlowCorrelationsAllVsMPro[43] = new TProfile("four4n1n3n2n","#LT#LT4#GT#GT_{4n,1n|3n,2n}",fnBinsMult,fMinMult,fMaxMult);
1921   fIntFlowCorrelationsAllVsMPro[43]->Sumw2();
1922   fIntFlowCorrelationsAllVsMPro[43]->GetXaxis()->SetTitle("M");  
1923   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[43]);
1924   fIntFlowCorrelationsAllVsMPro[44] = new TProfile("four3n3n3n3n","#LT#LT4#GT#GT_{3n,3n|3n,3n}",fnBinsMult,fMinMult,fMaxMult);
1925   fIntFlowCorrelationsAllVsMPro[44]->Sumw2();
1926   fIntFlowCorrelationsAllVsMPro[44]->GetXaxis()->SetTitle("M");  
1927   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[44]);
1928   fIntFlowCorrelationsAllVsMPro[45] = new TProfile("four4n2n3n3n","#LT#LT4#GT#GT_{4n,2n|3n,3n}",fnBinsMult,fMinMult,fMaxMult);
1929   fIntFlowCorrelationsAllVsMPro[45]->Sumw2();
1930   fIntFlowCorrelationsAllVsMPro[45]->GetXaxis()->SetTitle("M");  
1931   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[45]);
1932   fIntFlowCorrelationsAllVsMPro[46] = new TProfile("four5n1n3n3n","#LT#LT4#GT#GT_{5n,1n|3n,3n}",fnBinsMult,fMinMult,fMaxMult);
1933   fIntFlowCorrelationsAllVsMPro[46]->Sumw2();
1934   fIntFlowCorrelationsAllVsMPro[46]->GetXaxis()->SetTitle("M");  
1935   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[46]);
1936   fIntFlowCorrelationsAllVsMPro[47] = new TProfile("four4n2n4n2n","#LT#LT4#GT#GT_{4n,2n|4n,2n}",fnBinsMult,fMinMult,fMaxMult);
1937   fIntFlowCorrelationsAllVsMPro[47]->Sumw2();
1938   fIntFlowCorrelationsAllVsMPro[47]->GetXaxis()->SetTitle("M");  
1939   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[47]);
1940   fIntFlowCorrelationsAllVsMPro[48] = new TProfile("four5n1n4n2n","#LT#LT4#GT#GT_{5n,1n|4n,2n}",fnBinsMult,fMinMult,fMaxMult);
1941   fIntFlowCorrelationsAllVsMPro[48]->Sumw2();
1942   fIntFlowCorrelationsAllVsMPro[48]->GetXaxis()->SetTitle("M");  
1943   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[48]);
1944   fIntFlowCorrelationsAllVsMPro[49] = new TProfile("four5n3n1n1n","#LT#LT4#GT#GT_{5n|3n,1n,1n}",fnBinsMult,fMinMult,fMaxMult);
1945   fIntFlowCorrelationsAllVsMPro[49]->Sumw2();
1946   fIntFlowCorrelationsAllVsMPro[49]->GetXaxis()->SetTitle("M");  
1947   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[49]);
1948   fIntFlowCorrelationsAllVsMPro[50] = new TProfile("four5n2n2n1n","#LT#LT4#GT#GT_{5n|2n,2n,1n}",fnBinsMult,fMinMult,fMaxMult);
1949   fIntFlowCorrelationsAllVsMPro[50]->Sumw2();
1950   fIntFlowCorrelationsAllVsMPro[50]->GetXaxis()->SetTitle("M");  
1951   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[50]);
1952   fIntFlowCorrelationsAllVsMPro[51] = new TProfile("four5n1n5n1n","#LT#LT4#GT#GT_{5n,1n|5n,1n}",fnBinsMult,fMinMult,fMaxMult);
1953   fIntFlowCorrelationsAllVsMPro[51]->Sumw2();
1954   fIntFlowCorrelationsAllVsMPro[51]->GetXaxis()->SetTitle("M");  
1955   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[51]);
1956   fIntFlowCorrelationsAllVsMPro[52] = new TProfile("five3n3n3n2n1n","#LT#LT5#GT#GT_{3n,3n|3n,2n,1n}",fnBinsMult,fMinMult,fMaxMult);
1957   fIntFlowCorrelationsAllVsMPro[52]->Sumw2();
1958   fIntFlowCorrelationsAllVsMPro[52]->GetXaxis()->SetTitle("M");  
1959   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[52]);
1960   fIntFlowCorrelationsAllVsMPro[53] = new TProfile("five4n2n3n2n1n","#LT#LT5#GT#GT_{4n,2n|3n,2n,1n}",fnBinsMult,fMinMult,fMaxMult);
1961   fIntFlowCorrelationsAllVsMPro[53]->Sumw2();
1962   fIntFlowCorrelationsAllVsMPro[53]->GetXaxis()->SetTitle("M");  
1963   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[53]);
1964   fIntFlowCorrelationsAllVsMPro[54] = new TProfile("five3n2n3n1n1n","#LT#LT5#GT#GT_{3n,2n|3n,1n,1n}",fnBinsMult,fMinMult,fMaxMult);
1965   fIntFlowCorrelationsAllVsMPro[54]->Sumw2();
1966   fIntFlowCorrelationsAllVsMPro[54]->GetXaxis()->SetTitle("M");  
1967   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[54]);
1968   fIntFlowCorrelationsAllVsMPro[55] = new TProfile("five3n2n2n2n1n","#LT#LT5#GT#GT_{3n,2n|2n,2n,1n}",fnBinsMult,fMinMult,fMaxMult);
1969   fIntFlowCorrelationsAllVsMPro[55]->Sumw2();
1970   fIntFlowCorrelationsAllVsMPro[55]->GetXaxis()->SetTitle("M");  
1971   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[55]);
1972   fIntFlowCorrelationsAllVsMPro[56] = new TProfile("five5n1n3n2n1n","#LT#LT5#GT#GT_{5n,1n|3n,2n,1n}",fnBinsMult,fMinMult,fMaxMult);
1973   fIntFlowCorrelationsAllVsMPro[56]->Sumw2();
1974   fIntFlowCorrelationsAllVsMPro[56]->GetXaxis()->SetTitle("M");  
1975   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[56]);
1976   fIntFlowCorrelationsAllVsMPro[57] = new TProfile("six3n2n1n3n2n1n","#LT#LT6#GT#GT_{3n,2n,1n|3n,2n,1n}",fnBinsMult,fMinMult,fMaxMult);
1977   fIntFlowCorrelationsAllVsMPro[57]->Sumw2();
1978   fIntFlowCorrelationsAllVsMPro[57]->GetXaxis()->SetTitle("M");  
1979   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[57]);  
1980   fIntFlowCorrelationsAllVsMPro[58] = new TProfile("four6n4n1n1n","#LT#LT4#GT#GT_{6n|4n,1n,1n}",fnBinsMult,fMinMult,fMaxMult);
1981   fIntFlowCorrelationsAllVsMPro[58]->Sumw2();
1982   fIntFlowCorrelationsAllVsMPro[58]->GetXaxis()->SetTitle("M");  
1983   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[58]);
1984   fIntFlowCorrelationsAllVsMPro[59] = new TProfile("four6n2n2n2n","#LT#LT4#GT#GT_{6n|2n,2n,2n}",fnBinsMult,fMinMult,fMaxMult);
1985   fIntFlowCorrelationsAllVsMPro[59]->Sumw2();
1986   fIntFlowCorrelationsAllVsMPro[59]->GetXaxis()->SetTitle("M");  
1987   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[59]);
1988   fIntFlowCorrelationsAllVsMPro[60] = new TProfile("five6n2n2n1n1n","#LT#LT5#GT#GT_{6n|2n,2n,1n,1n}",fnBinsMult,fMinMult,fMaxMult);
1989   fIntFlowCorrelationsAllVsMPro[60]->Sumw2();
1990   fIntFlowCorrelationsAllVsMPro[60]->GetXaxis()->SetTitle("M");  
1991   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[60]);
1992   fIntFlowCorrelationsAllVsMPro[61] = new TProfile("five4n1n1n3n3n","#LT#LT5#GT#GT_{4n,1n,1n|3n,3n}",fnBinsMult,fMinMult,fMaxMult);
1993   fIntFlowCorrelationsAllVsMPro[61]->Sumw2();
1994   fIntFlowCorrelationsAllVsMPro[61]->GetXaxis()->SetTitle("M");  
1995   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[61]);
1996   fIntFlowCorrelationsAllVsMPro[62] = new TProfile("six3n3n2n2n1n1n","#LT#LT6#GT#GT_{3n,3n|2n,2n,1n,1n}",fnBinsMult,fMinMult,fMaxMult);
1997   fIntFlowCorrelationsAllVsMPro[62]->Sumw2();
1998   fIntFlowCorrelationsAllVsMPro[62]->GetXaxis()->SetTitle("M");  
1999   fIntFlowAllCorrelationsVsM->Add(fIntFlowCorrelationsAllVsMPro[62]);
2000  } // end of if(fCalculateAllCorrelationsVsM)
2001  // when particle weights are used some extra correlations appear:
2002  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights) 
2003  {
2004   TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
2005   intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
2006   fIntFlowExtraCorrelationsPro = new TProfile(intFlowExtraCorrelationsProName.Data(),"Average extra correlations for all events",100,0,100,"s");
2007   fIntFlowExtraCorrelationsPro->SetTickLength(-0.01,"Y");
2008   fIntFlowExtraCorrelationsPro->SetMarkerStyle(25);
2009   fIntFlowExtraCorrelationsPro->SetLabelSize(0.03);
2010   fIntFlowExtraCorrelationsPro->SetLabelOffset(0.01,"Y");
2011   // extra 2-p correlations:
2012   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(1,"<<w1^3 w2 cos(n*(phi1-phi2))>>");
2013   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(2,"<<w1 w2 w3^2 cos(n*(phi1-phi2))>>");
2014   fIntFlowProfiles->Add(fIntFlowExtraCorrelationsPro);
2015  } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
2016  // average product of correlations <2>, <4>, <6> and <8>:  
2017  TString productFlag[6] = {"#LT#LT2#GT#LT4#GT#GT","#LT#LT2#GT#LT6#GT#GT","#LT#LT2#GT#LT8#GT#GT",
2018                            "#LT#LT4#GT#LT6#GT#GT","#LT#LT4#GT#LT8#GT#GT","#LT#LT6#GT#LT8#GT#GT"};
2019  TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
2020  intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
2021  fIntFlowProductOfCorrelationsPro = new TProfile(intFlowProductOfCorrelationsProName.Data(),"Average products of correlations",6,0,6);
2022  fIntFlowProductOfCorrelationsPro->SetTickLength(-0.01,"Y");
2023  fIntFlowProductOfCorrelationsPro->SetMarkerStyle(25); 
2024  fIntFlowProductOfCorrelationsPro->SetLabelSize(0.05);
2025  fIntFlowProductOfCorrelationsPro->SetLabelOffset(0.01,"Y");
2026  for(Int_t b=0;b<6;b++)
2027  {
2028   (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(b+1,productFlag[b].Data());
2029  }
2030  fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsPro); 
2031  // average product of correlations <2>, <4>, <6> and <8> versus multiplicity
2032  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
2033  if(fCalculateCumulantsVsM)
2034  {
2035   TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
2036   intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
2037   for(Int_t pi=0;pi<6;pi++)
2038   { 
2039    fIntFlowProductOfCorrelationsVsMPro[pi] = new TProfile(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data()),
2040                                                           Form("%s versus multiplicity",productFlag[pi].Data()),
2041                                                           fnBinsMult,fMinMult,fMaxMult);             
2042    fIntFlowProductOfCorrelationsVsMPro[pi]->GetXaxis()->SetTitle("M");
2043    fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsVsMPro[pi]);
2044   } // end of for(Int_t pi=0;pi<6;pi++)
2045  } // end of if(fCalculateCumulantsVsM) 
2046  // average product of correction terms for NUA:  
2047  TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
2048  intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
2049  fIntFlowProductOfCorrectionTermsForNUAPro = new TProfile(intFlowProductOfCorrectionTermsForNUAProName.Data(),"Average products of correction terms for NUA",27,0,27);
2050  fIntFlowProductOfCorrectionTermsForNUAPro->SetTickLength(-0.01,"Y");
2051  fIntFlowProductOfCorrectionTermsForNUAPro->SetMarkerStyle(25); 
2052  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelSize(0.03);
2053  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelOffset(0.01,"Y");
2054  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(1,"<<2><cos(#phi)>>");
2055  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(2,"<<2><sin(#phi)>>");
2056  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(3,"<<cos(#phi)><sin(#phi)>>");
2057  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
2058  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
2059  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2060  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2061  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
2062  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
2063  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
2064  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
2065  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
2066  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
2067  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
2068  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
2069  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2070  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2071  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
2072  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
2073  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2074  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2075  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
2076  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2077  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2078  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2079  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2080  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
2081  fIntFlowProfiles->Add(fIntFlowProductOfCorrectionTermsForNUAPro);
2082  // average correction terms for non-uniform acceptance (with wrong errors!):
2083  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2084  {
2085   TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
2086   intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
2087   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");
2088   fIntFlowCorrectionTermsForNUAPro[sc]->SetTickLength(-0.01,"Y");
2089   fIntFlowCorrectionTermsForNUAPro[sc]->SetMarkerStyle(25);
2090   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelSize(0.05);
2091   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelOffset(0.01,"Y");
2092   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(1,Form("#LT#LT%s(n(#phi_{1}))#GT#GT",sinCosFlag[sc].Data()));
2093   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(2,Form("#LT#LT%s(n(#phi_{1}+#phi_{2}))#GT#GT",sinCosFlag[sc].Data()));  
2094   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(3,Form("#LT#LT%s(n(#phi_{1}-#phi_{2}-#phi_{3}))#GT#GT",sinCosFlag[sc].Data()));  
2095   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(4,Form("#LT#LT%s(n(2#phi_{1}-#phi_{2}))#GT#GT",sinCosFlag[sc].Data()));  
2096   fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAPro[sc]);
2097   // versus multiplicity:
2098   if(fCalculateCumulantsVsM)
2099   {
2100    TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
2101    for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
2102    {
2103     TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
2104     intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
2105     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");
2106     fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAVsMPro[sc][ci]);
2107    }
2108   } // end of if(fCalculateCumulantsVsM)
2109  } // end of for(Int_t sc=0;sc<2;sc++) 
2110  
2111  // d) Book histograms holding the final results:
2112  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!):
2113  TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
2114  intFlowCorrelationsHistName += fAnalysisLabel->Data();
2115  fIntFlowCorrelationsHist = new TH1D(intFlowCorrelationsHistName.Data(),"Average correlations for all events",4,0,4);
2116  fIntFlowCorrelationsHist->SetTickLength(-0.01,"Y");
2117  fIntFlowCorrelationsHist->SetMarkerStyle(25);
2118  fIntFlowCorrelationsHist->SetLabelSize(0.06);
2119  fIntFlowCorrelationsHist->SetLabelOffset(0.01,"Y");
2120  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(1,"#LT#LT2#GT#GT");
2121  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(2,"#LT#LT4#GT#GT");
2122  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(3,"#LT#LT6#GT#GT");
2123  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(4,"#LT#LT8#GT#GT");
2124  fIntFlowResults->Add(fIntFlowCorrelationsHist);
2125  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!) vs M:
2126  if(fCalculateCumulantsVsM)
2127  {
2128   for(Int_t ci=0;ci<4;ci++) // correlation index
2129   {
2130    TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
2131    intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
2132    fIntFlowCorrelationsVsMHist[ci] = new TH1D(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data()),
2133                                               Form("%s vs multiplicity",correlationFlag[ci].Data()),
2134                                               fnBinsMult,fMinMult,fMaxMult);                                            
2135    fIntFlowCorrelationsVsMHist[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
2136    fIntFlowCorrelationsVsMHist[ci]->GetXaxis()->SetTitle("M");
2137    fIntFlowResults->Add(fIntFlowCorrelationsVsMHist[ci]);
2138   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
2139  } // end of if(fCalculateCumulantsVsM) 
2140  // average all correlations for all events (with correct errors!):
2141  TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
2142  intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
2143  fIntFlowCorrelationsAllHist = new TH1D(intFlowCorrelationsAllHistName.Data(),"Average correlations for all events",34,0,34);
2144  fIntFlowCorrelationsAllHist->SetTickLength(-0.01,"Y");
2145  fIntFlowCorrelationsAllHist->SetMarkerStyle(25);
2146  fIntFlowCorrelationsAllHist->SetLabelSize(0.03);
2147  fIntFlowCorrelationsAllHist->SetLabelOffset(0.01,"Y");
2148  // 2-p correlations:
2149  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
2150  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
2151  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
2152  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
2153  // 3-p correlations:
2154  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
2155  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
2156  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
2157  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
2158  // 4-p correlations:
2159  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
2160  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
2161  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
2162  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
2163  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
2164  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
2165  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
2166  // 5-p correlations:
2167  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
2168  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
2169  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
2170  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
2171  // 6-p correlations:
2172  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
2173  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
2174  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
2175  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
2176  // 7-p correlations:  
2177  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
2178  // 8-p correlations:
2179  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
2180  fIntFlowResults->Add(fIntFlowCorrelationsAllHist);
2181  // average correction terms for non-uniform acceptance (with correct errors!):
2182  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2183  {
2184   TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
2185   intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
2186   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);
2187   fIntFlowCorrectionTermsForNUAHist[sc]->SetTickLength(-0.01,"Y");
2188   fIntFlowCorrectionTermsForNUAHist[sc]->SetMarkerStyle(25);
2189   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelSize(0.05);
2190   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelOffset(0.01,"Y");
2191   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(1,Form("#LT#LT%s(n(#phi_{1}))#GT#GT",sinCosFlag[sc].Data()));
2192   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(2,Form("#LT#LT%s(n(#phi_{1}+#phi_{2}))#GT#GT",sinCosFlag[sc].Data()));  
2193   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(3,Form("#LT#LT%s(n(#phi_{1}-#phi_{2}-#phi_{3}))#GT#GT",sinCosFlag[sc].Data()));  
2194   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(4,Form("#LT#LT%s(n(2#phi_{1}-#phi_{2}))#GT#GT",sinCosFlag[sc].Data()));   
2195   fIntFlowResults->Add(fIntFlowCorrectionTermsForNUAHist[sc]);
2196  } // end of for(Int_t sc=0;sc<2;sc++) 
2197  // covariances (multiplied with weight dependent prefactor):
2198  TString intFlowCovariancesName = "fIntFlowCovariances";
2199  intFlowCovariancesName += fAnalysisLabel->Data();
2200  fIntFlowCovariances = new TH1D(intFlowCovariancesName.Data(),"Covariances (multiplied with weight dependent prefactor)",6,0,6);
2201  fIntFlowCovariances->SetLabelSize(0.04);
2202  fIntFlowCovariances->SetMarkerStyle(25);
2203  (fIntFlowCovariances->GetXaxis())->SetBinLabel(1,"Cov(#LT2#GT,#LT4#GT)");
2204  (fIntFlowCovariances->GetXaxis())->SetBinLabel(2,"Cov(#LT2#GT,#LT6#GT)");
2205  (fIntFlowCovariances->GetXaxis())->SetBinLabel(3,"Cov(#LT2#GT,#LT8#GT)");
2206  (fIntFlowCovariances->GetXaxis())->SetBinLabel(4,"Cov(#LT4#GT,#LT6#GT)");
2207  (fIntFlowCovariances->GetXaxis())->SetBinLabel(5,"Cov(#LT4#GT,#LT8#GT)");
2208  (fIntFlowCovariances->GetXaxis())->SetBinLabel(6,"Cov(#LT6#GT,#LT8#GT)");  
2209  fIntFlowResults->Add(fIntFlowCovariances);
2210  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
2211  TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
2212  intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
2213  for(Int_t power=0;power<2;power++)
2214  {
2215   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);
2216   fIntFlowSumOfEventWeights[power]->SetLabelSize(0.04);
2217   fIntFlowSumOfEventWeights[power]->SetMarkerStyle(25);
2218   if(power == 0)
2219   {
2220    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{#LT2#GT}");
2221    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{#LT4#GT}");
2222    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{#LT6#GT}");
2223    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{#LT8#GT}");
2224   } else if (power == 1) 
2225     {
2226      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{#LT2#GT}^{2}");
2227      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{#LT4#GT}^{2}");
2228      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{#LT6#GT}^{2}");
2229      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{#LT8#GT}^{2}");
2230     }
2231   fIntFlowResults->Add(fIntFlowSumOfEventWeights[power]);
2232  } 
2233  // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
2234  TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
2235  intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
2236  fIntFlowSumOfProductOfEventWeights = new TH1D(intFlowSumOfProductOfEventWeightsName.Data(),"Sum of product of event weights for correlations",6,0,6);
2237  fIntFlowSumOfProductOfEventWeights->SetLabelSize(0.04);
2238  fIntFlowSumOfProductOfEventWeights->SetMarkerStyle(25);
2239  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LT4#GT}");
2240  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LT6#GT}");
2241  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LT8#GT}");
2242  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LT6#GT}");
2243  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(5,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LT8#GT}");
2244  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(6,"#sum_{i=1}^{N} w_{#LT6#GT} w_{#LT8#GT}");
2245  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeights);
2246  // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
2247  // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
2248  if(fCalculateCumulantsVsM)
2249  {
2250   TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
2251   intFlowCovariancesVsMName += fAnalysisLabel->Data();
2252   TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
2253   for(Int_t ci=0;ci<6;ci++)
2254   {
2255    fIntFlowCovariancesVsM[ci] = new TH1D(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data()),
2256                                          Form("%s vs multiplicity",covarianceFlag[ci].Data()),
2257                                          fnBinsMult,fMinMult,fMaxMult);
2258    fIntFlowCovariancesVsM[ci]->GetYaxis()->SetTitle(covarianceFlag[ci].Data());
2259    fIntFlowCovariancesVsM[ci]->GetXaxis()->SetTitle("M");
2260    fIntFlowResults->Add(fIntFlowCovariancesVsM[ci]);
2261   }
2262  } // end of if(fCalculateCumulantsVsM) 
2263  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
2264  // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
2265  if(fCalculateCumulantsVsM)
2266  {
2267   TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
2268   intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
2269   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>}"},
2270                            {"#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}"}};
2271   for(Int_t si=0;si<4;si++)
2272   {
2273    for(Int_t power=0;power<2;power++)
2274    {
2275     fIntFlowSumOfEventWeightsVsM[si][power] = new TH1D(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data()),
2276                                                        Form("%s vs multiplicity",sumFlag[power][si].Data()),
2277                                                        fnBinsMult,fMinMult,fMaxMult);    
2278     fIntFlowSumOfEventWeightsVsM[si][power]->GetYaxis()->SetTitle(sumFlag[power][si].Data());  
2279     fIntFlowSumOfEventWeightsVsM[si][power]->GetXaxis()->SetTitle("M");  
2280     fIntFlowResults->Add(fIntFlowSumOfEventWeightsVsM[si][power]);
2281    } // end of for(Int_t power=0;power<2;power++)
2282   } // end of for(Int_t si=0;si<4;si++)   
2283  } // end of if(fCalculateCumulantsVsM)
2284  // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
2285  // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
2286  //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
2287  if(fCalculateCumulantsVsM)
2288  {
2289   TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
2290   intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
2291   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>}",
2292                           "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
2293   for(Int_t pi=0;pi<6;pi++)
2294   {
2295    fIntFlowSumOfProductOfEventWeightsVsM[pi] = new TH1D(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data()),
2296                                                         Form("%s versus multiplicity",sopowFlag[pi].Data()),
2297                                                         fnBinsMult,fMinMult,fMaxMult); 
2298    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetXaxis()->SetTitle("M");
2299    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetYaxis()->SetTitle(sopowFlag[pi].Data()); 
2300    fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsVsM[pi]);
2301   } // end of for(Int_t pi=0;pi<6;pi++) 
2302  } // end of if(fCalculateCumulantsVsM)
2303  // covariances of NUA terms (multiplied with weight dependent prefactor):
2304  TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
2305  intFlowCovariancesNUAName += fAnalysisLabel->Data();
2306  fIntFlowCovariancesNUA = new TH1D(intFlowCovariancesNUAName.Data(),"Covariances for NUA (multiplied with weight dependent prefactor)",27,0,27);
2307  fIntFlowCovariancesNUA->SetLabelSize(0.04);
2308  fIntFlowCovariancesNUA->SetMarkerStyle(25);
2309  fIntFlowCovariancesNUA->GetXaxis()->SetLabelSize(0.02);
2310  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(1,"Cov(<2>,<cos(#phi)>");
2311  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(2,"Cov(<2>,<sin(#phi)>)");
2312  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(3,"Cov(<cos(#phi)>,<sin(#phi)>)");
2313  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
2314  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
2315  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2316  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2317  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
2318  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
2319  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
2320  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
2321  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
2322  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
2323  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
2324  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
2325  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2326  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2327  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
2328  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
2329  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2330  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2331  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
2332  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2333  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2334  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
2335  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
2336  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
2337  fIntFlowResults->Add(fIntFlowCovariancesNUA);
2338  // sum of linear and quadratic event weights for NUA terms:
2339  TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
2340  intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
2341  for(Int_t sc=0;sc<2;sc++)
2342  {
2343   for(Int_t power=0;power<2;power++)
2344   {
2345    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
2346    fIntFlowSumOfEventWeightsNUA[sc][power]->SetLabelSize(0.05);
2347    fIntFlowSumOfEventWeightsNUA[sc][power]->SetMarkerStyle(25);
2348    if(power == 0)
2349    {
2350     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}",sinCosFlag[sc].Data()));
2351     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}",sinCosFlag[sc].Data()));
2352     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}",sinCosFlag[sc].Data()));   
2353     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(4,Form("#sum_{i=1}^{N} w_{<%s(2#phi_{1}-#phi_{2})>}",sinCosFlag[sc].Data()));
2354    } else if(power == 1) 
2355      {
2356       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}^{2}",sinCosFlag[sc].Data()));
2357       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}^{2}",sinCosFlag[sc].Data()));
2358       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}^{2}",sinCosFlag[sc].Data()));
2359       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(4,Form("#sum_{i=1}^{N} w_{<%s(2#phi_{1}-#phi_{2})>}^{2}",sinCosFlag[sc].Data()));
2360      }
2361    fIntFlowResults->Add(fIntFlowSumOfEventWeightsNUA[sc][power]);
2362   }
2363  }  
2364  // sum of products of event weights for NUA terms:  
2365  TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
2366  intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
2367  fIntFlowSumOfProductOfEventWeightsNUA = new TH1D(intFlowSumOfProductOfEventWeightsNUAName.Data(),"Sum of product of event weights for NUA terms",27,0,27);
2368  fIntFlowSumOfProductOfEventWeightsNUA->SetLabelSize(0.02);
2369  fIntFlowSumOfProductOfEventWeightsNUA->SetMarkerStyle(25);
2370  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LTcos(#phi)#GT}");
2371  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LTsin(#phi)#GT}");
2372  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{#LTcos(#phi)#GT} w_{#LTsin(#phi)#GT}");
2373  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LTcos(#phi_{1}+#phi_{2})#GT}");
2374  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(5,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LTsin(#phi_{1}+#phi_{2})#GT}");
2375  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(6,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LTcos(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2376  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(7,"#sum_{i=1}^{N} w_{#LT2#GT} w_{#LTsin(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2377  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(8,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LTcos(#phi)#GT}");
2378  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(9,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LTsin(#phi)#GT}");
2379  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(10,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LTcos(#phi_{1}+#phi_{2})#GT}");
2380  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(11,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LTsin(#phi_{1}+#phi_{2})#GT}");
2381  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(12,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LTcos(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2382  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(13,"#sum_{i=1}^{N} w_{#LT4#GT} w_{#LTsin(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2383  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(14,"#sum_{i=1}^{N} w_{#LTcos(#phi)#GT} w_{#LTcos(#phi_{1}+#phi_{2})#GT}");
2384  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(15,"#sum_{i=1}^{N} w_{#LTcos(#phi)#GT} w_{#LTsin(#phi_{1}+#phi_{2})#GT}");
2385  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(16,"#sum_{i=1}^{N} w_{#LTcos(#phi)#GT} w_{#LTcos(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2386  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(17,"#sum_{i=1}^{N} w_{#LTcos(#phi)#GT} w_{#LTsin(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2387  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(18,"#sum_{i=1}^{N} w_{#LTsin(#phi)#GT} w_{#LTcos(#phi_{1}+#phi_{2})#GT}");
2388  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(19,"#sum_{i=1}^{N} w_{#LTsin(#phi)#GT} w_{#LTsin(#phi_{1}+#phi_{2})#GT}");
2389  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(20,"#sum_{i=1}^{N} w_{#LTsin(#phi)#GT} w_{#LTcos(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2390  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(21,"#sum_{i=1}^{N} w_{#LTsin(#phi)#GT} w_{#LTsin(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2391  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(22,"#sum_{i=1}^{N} w_{#LTcos(#phi_{1}+#phi_{2})#GT} w_{#LTsin(#phi_{1}+#phi_{2})#GT}");
2392  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(23,"#sum_{i=1}^{N} w_{#LTcos(#phi_{1}+#phi_{2})#GT} w_{#LTcos(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2393  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(24,"#sum_{i=1}^{N} w_{#LTcos(#phi_{1}+#phi_{2})#GT} w_{#LTsin(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2394  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(25,"#sum_{i=1}^{N} w_{#LTsin(#phi_{1}+#phi_{2})#GT} w_{#LTcos(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2395  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(26,"#sum_{i=1}^{N} w_{#LTsin(#phi_{1}+#phi_{2})#GT} w_{#LTsin(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2396  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(27,"#sum_{i=1}^{N} w_{#LTcos(#phi_{1}-#phi_{2}-#phi_{3})#GT} w_{#LTsin(#phi_{1}-#phi_{2}-#phi_{3})#GT}");
2397  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsNUA);
2398  // Final results for reference Q-cumulants:
2399  TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
2400  TString intFlowQcumulantsName = "fIntFlowQcumulants";
2401  intFlowQcumulantsName += fAnalysisLabel->Data();
2402  fIntFlowQcumulants = new TH1D(intFlowQcumulantsName.Data(),"Reference Q-cumulants",4,0,4);
2403  if(fPropagateErrorAlsoFromNIT)
2404  {
2405   fIntFlowQcumulants->SetTitle("Reference Q-cumulants (error from non-isotropic terms also propagated)");
2406  }
2407  fIntFlowQcumulants->SetLabelSize(0.05);
2408  fIntFlowQcumulants->SetMarkerStyle(25);
2409  for(Int_t b=0;b<4;b++)
2410  {
2411   (fIntFlowQcumulants->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2412  } 
2413  fIntFlowResults->Add(fIntFlowQcumulants);
2414  // Final results for reference Q-cumulants rebinned in M: 
2415  if(fCalculateCumulantsVsM)
2416  {
2417   TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
2418   intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
2419   fIntFlowQcumulantsRebinnedInM = new TH1D(intFlowQcumulantsRebinnedInMName.Data(),"Reference Q-cumulants rebinned in M",4,0,4);
2420   fIntFlowQcumulantsRebinnedInM->SetLabelSize(0.05);
2421   fIntFlowQcumulantsRebinnedInM->SetMarkerStyle(25);
2422   for(Int_t b=0;b<4;b++)
2423   {
2424    (fIntFlowQcumulantsRebinnedInM->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2425   } 
2426   fIntFlowResults->Add(fIntFlowQcumulantsRebinnedInM);
2427  } // end of if(fCalculateCumulantsVsM) 
2428  // Ratio between error squared: with/without non-isotropic terms:
2429  TString intFlowQcumulantsErrorSquaredRatioName = "fIntFlowQcumulantsErrorSquaredRatio";
2430  intFlowQcumulantsErrorSquaredRatioName += fAnalysisLabel->Data();
2431  fIntFlowQcumulantsErrorSquaredRatio = new TH1D(intFlowQcumulantsErrorSquaredRatioName.Data(),"Error squared of reference Q-cumulants: #frac{with NUA terms}{without NUA terms}",4,0,4);
2432  fIntFlowQcumulantsErrorSquaredRatio->SetLabelSize(0.05);
2433  fIntFlowQcumulantsErrorSquaredRatio->SetMarkerStyle(25);
2434  for(Int_t b=0;b<4;b++)
2435  {
2436   (fIntFlowQcumulantsErrorSquaredRatio->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2437  } 
2438  fIntFlowResults->Add(fIntFlowQcumulantsErrorSquaredRatio);
2439  // final results for integrated Q-cumulants versus multiplicity:
2440  if(fCalculateCumulantsVsM)
2441  {
2442   TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
2443   intFlowQcumulantsVsMName += fAnalysisLabel->Data();
2444   for(Int_t co=0;co<4;co++) // cumulant order
2445   {
2446    fIntFlowQcumulantsVsM[co] = new TH1D(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data()),
2447                                         Form("%s vs multipicity",cumulantFlag[co].Data()),
2448                                         fnBinsMult,fMinMult,fMaxMult);
2449    fIntFlowQcumulantsVsM[co]->GetXaxis()->SetTitle("M");                                     
2450    fIntFlowQcumulantsVsM[co]->GetYaxis()->SetTitle(cumulantFlag[co].Data());  
2451    fIntFlowResults->Add(fIntFlowQcumulantsVsM[co]);                                    
2452   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2453  } // end of if(fCalculateCumulantsVsM)
2454  // final integrated flow estimates from Q-cumulants:
2455  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)};
2456  TString intFlowName = "fIntFlow";
2457  intFlowName += fAnalysisLabel->Data();  
2458  // integrated flow from Q-cumulants:
2459  fIntFlow = new TH1D(intFlowName.Data(),"Reference flow estimates from Q-cumulants",4,0,4);
2460  fIntFlow->SetLabelSize(0.05);
2461  fIntFlow->SetMarkerStyle(25);
2462  for(Int_t b=0;b<4;b++)
2463  {
2464   (fIntFlow->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2465  }
2466  fIntFlowResults->Add(fIntFlow); 
2467  // Reference flow vs M rebinned in one huge bin:
2468  if(fCalculateCumulantsVsM)
2469  { 
2470   TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
2471   intFlowRebinnedInMName += fAnalysisLabel->Data();  
2472   fIntFlowRebinnedInM = new TH1D(intFlowRebinnedInMName.Data(),"Reference flow estimates from Q-cumulants (rebinned in M)",4,0,4);
2473   fIntFlowRebinnedInM->SetLabelSize(0.05);
2474   fIntFlowRebinnedInM->SetMarkerStyle(25);
2475   for(Int_t b=0;b<4;b++)
2476   {
2477    (fIntFlowRebinnedInM->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2478   }
2479   fIntFlowResults->Add(fIntFlowRebinnedInM); 
2480  } 
2481  // integrated flow from Q-cumulants: versus multiplicity:
2482  if(fCalculateCumulantsVsM)
2483  {
2484   TString intFlowVsMName = "fIntFlowVsM";
2485   intFlowVsMName += fAnalysisLabel->Data();
2486   for(Int_t co=0;co<4;co++) // cumulant order
2487   {
2488    fIntFlowVsM[co] = new TH1D(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data()),
2489                               Form("%s vs multipicity",flowFlag[co].Data()),
2490                               fnBinsMult,fMinMult,fMaxMult);
2491    fIntFlowVsM[co]->GetXaxis()->SetTitle("M");                                     
2492    fIntFlowVsM[co]->GetYaxis()->SetTitle(flowFlag[co].Data());  
2493    fIntFlowResults->Add(fIntFlowVsM[co]);                                    
2494   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2495  } // end of if(fCalculateCumulantsVsM)
2496  // quantifying detector effects effects to correlations:
2497  TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
2498  intFlowDetectorBiasName += fAnalysisLabel->Data();  
2499  fIntFlowDetectorBias = new TH1D(intFlowDetectorBiasName.Data(),"Quantifying detector bias",4,0,4);
2500  fIntFlowDetectorBias->SetLabelSize(0.05);
2501  fIntFlowDetectorBias->SetMarkerStyle(25);
2502  for(Int_t ci=0;ci<4;ci++)
2503  {  
2504   (fIntFlowDetectorBias->GetXaxis())->SetBinLabel(ci+1,Form("#frac{corrected}{measured} %s",cumulantFlag[ci].Data()));
2505  }
2506  fIntFlowResults->Add(fIntFlowDetectorBias); 
2507  // quantifying detector effects to correlations versus multiplicity:
2508  if(fCalculateCumulantsVsM)
2509  {
2510   TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
2511   intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
2512   for(Int_t ci=0;ci<4;ci++) // correlation index
2513   {
2514    fIntFlowDetectorBiasVsM[ci] = new TH1D(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data()),
2515                                           Form("Quantifying detector bias for %s vs multipicity",cumulantFlag[ci].Data()),
2516                                           fnBinsMult,fMinMult,fMaxMult);
2517    fIntFlowDetectorBiasVsM[ci]->GetXaxis()->SetTitle("M");                                     
2518    fIntFlowDetectorBiasVsM[ci]->GetYaxis()->SetTitle("#frac{corrected}{measured}");  
2519    fIntFlowResults->Add(fIntFlowDetectorBiasVsM[ci]);                                    
2520   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2521  } // end of if(fCalculateCumulantsVsM)
2522    
2523 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
2524
2525 //================================================================================================================================
2526
2527 void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2528 {
2529  // Initialize arrays of all objects relevant for calculations with nested loops.
2530  
2531  // integrated flow:
2532  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2533  {
2534   fIntFlowDirectCorrectionTermsForNUA[sc] = NULL;
2535  } 
2536
2537  // differential flow:  
2538  // correlations:
2539  for(Int_t t=0;t<2;t++) // type: RP or POI
2540  { 
2541   for(Int_t pe=0;pe<2;pe++) // pt or eta
2542   {
2543    for(Int_t ci=0;ci<4;ci++) // correlation index
2544    {
2545     fDiffFlowDirectCorrelations[t][pe][ci] = NULL;
2546    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
2547   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2548  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2549  // correction terms for non-uniform acceptance:
2550  for(Int_t t=0;t<2;t++) // type: RP or POI
2551  { 
2552   for(Int_t pe=0;pe<2;pe++) // pt or eta
2553   {
2554    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2555    {
2556     for(Int_t cti=0;cti<9;cti++) // correction term index
2557     {
2558      fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] = NULL;
2559     }   
2560    }
2561   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2562  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2563
2564  // other differential correlators: 
2565  for(Int_t t=0;t<2;t++) // type: RP or POI
2566  { 
2567   for(Int_t pe=0;pe<2;pe++) // pt or eta
2568   {
2569    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2570    {
2571     for(Int_t ci=0;ci<1;ci++) // correlator index
2572     {
2573      fOtherDirectDiffCorrelators[t][pe][sc][ci] = NULL;
2574     }   
2575    }
2576   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2577  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2578
2579 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2580
2581 //================================================================================================================================
2582
2583 void AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2584 {
2585  // Book all objects relevant for calculations with nested loops.
2586  
2587  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
2588  TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
2589  TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
2590  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
2591  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
2592  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
2593
2594  TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
2595  evaluateNestedLoopsName += fAnalysisLabel->Data();
2596  fEvaluateNestedLoops = new TProfile(evaluateNestedLoopsName.Data(),"Flags for nested loops",4,0,4);
2597  fEvaluateNestedLoops->SetLabelSize(0.03);
2598  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(1,"fEvaluateIntFlowNestedLoops");
2599  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(2,"fEvaluateDiffFlowNestedLoops");
2600  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(3,"fCrossCheckInPtBinNo");
2601  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(4,"fCrossCheckInEtaBinNo");
2602  fEvaluateNestedLoops->Fill(0.5,(Int_t)fEvaluateIntFlowNestedLoops);
2603  fEvaluateNestedLoops->Fill(1.5,(Int_t)fEvaluateDiffFlowNestedLoops);
2604  fEvaluateNestedLoops->Fill(2.5,fCrossCheckInPtBinNo);
2605  fEvaluateNestedLoops->Fill(3.5,fCrossCheckInEtaBinNo);
2606  fNestedLoopsList->Add(fEvaluateNestedLoops);
2607  // nested loops for integrated flow:
2608  if(fEvaluateIntFlowNestedLoops)
2609  {
2610   // correlations:
2611   TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
2612   intFlowDirectCorrelationsName += fAnalysisLabel->Data();
2613   fIntFlowDirectCorrelations = new TProfile(intFlowDirectCorrelationsName.Data(),"Multiparticle correlations calculated with nested loops (for int. flow)",64,0,64,"s");
2614   fNestedLoopsList->Add(fIntFlowDirectCorrelations);
2615   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
2616   {
2617    TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
2618    intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
2619    fIntFlowExtraDirectCorrelations = new TProfile(intFlowExtraDirectCorrelationsName.Data(),"Extra multiparticle correlations calculated with nested loops (for int. flow)",100,0,100,"s");
2620    fNestedLoopsList->Add(fIntFlowExtraDirectCorrelations);  
2621   } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
2622   // correction terms for non-uniform acceptance:
2623   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2624   {
2625    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
2626    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2627    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");
2628    fNestedLoopsList->Add(fIntFlowDirectCorrectionTermsForNUA[sc]);
2629   } // end of for(Int_t sc=0;sc<2;sc++) 
2630  } // end of if(fEvaluateIntFlowNestedLoops)
2631  
2632  // nested loops for differential flow: 
2633  if(fEvaluateDiffFlowNestedLoops)
2634  {
2635   // reduced correlations:
2636   TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
2637   diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
2638   for(Int_t t=0;t<2;t++) // type: RP or POI
2639   { 
2640    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
2641    {
2642     for(Int_t rci=0;rci<4;rci++) // reduced correlation index
2643     {
2644      // reduced correlations:
2645      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");
2646      fDiffFlowDirectCorrelations[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
2647      fNestedLoopsList->Add(fDiffFlowDirectCorrelations[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
2648     } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
2649    } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
2650   } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
2651   
2652   
2653   // correction terms for non-uniform acceptance:
2654   TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
2655   diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2656   for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
2657   { 
2658    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
2659    {
2660     for(Int_t sc=0;sc<2;sc++) // sin or cos
2661     {
2662      for(Int_t cti=0;cti<9;cti++) // correction term index
2663      {
2664       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"); 
2665       fNestedLoopsList->Add(fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]);
2666      }
2667     }
2668    }
2669   }
2670   // other differential correlators: 
2671   TString otherDirectDiffCorrelatorsName = "fOtherDirectDiffCorrelators";
2672   otherDirectDiffCorrelatorsName += fAnalysisLabel->Data();
2673   for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
2674   { 
2675    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
2676    {
2677     for(Int_t sc=0;sc<2;sc++) // sin or cos
2678     {
2679      for(Int_t ci=0;ci<1;ci++) // correlator index
2680      {
2681       fOtherDirectDiffCorrelators[t][pe][sc][ci] = new TProfile(Form("%s, %s, %s, %s, ci = %d",otherDirectDiffCorrelatorsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),ci+1),Form("%s, %s, %s, %s, ci = %d",otherDirectDiffCorrelatorsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),ci+1),1,lowerPtEtaEdge[pe],upperPtEtaEdge[pe]); 
2682       fNestedLoopsList->Add(fOtherDirectDiffCorrelators[t][pe][sc][ci]);
2683      }
2684     }
2685    }
2686   }
2687   // number of RPs and POIs in selected pt and eta bins for cross-checkings:
2688   TString noOfParticlesInBinName = "fNoOfParticlesInBin";
2689   fNoOfParticlesInBin = new TH1D(noOfParticlesInBinName.Data(),"Number of RPs and POIs in selected p_{T} and #eta bin",4,0,4);
2690   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(1,"# of RPs in p_{T} bin");
2691   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(2,"# of RPs in #eta bin");
2692   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(3,"# of POIs in p_{T} bin");
2693   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(4,"# of POIs in #eta bin");
2694   fNestedLoopsList->Add(fNoOfParticlesInBin);
2695  } // end of if(fEvaluateDiffFlowNestedLoops)
2696
2697 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2698
2699 //================================================================================================================================
2700
2701 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
2702 {
2703  // Calculate in this method all multiparticle azimuthal correlations.
2704  //
2705  // Remark 1: All multiparticle correlations are stored in TProfile fIntFlowCorrelationsAllPro;
2706  // Remark 2: There is a special TProfile fIntFlowCorrelationsPro holding results 
2707  //           only for same harmonic's correlations <<2>>, <<4>>, <<6>> and <<8>>;  
2708  // Remark 3: Binning of fIntFlowCorrelationsAllPro is organized as follows:
2709  // --------------------------------------------------------------------------------------------------------------------
2710  //  1st bin: <2>_{1n|1n} = two1n1n = cos(1n(phi1-phi2))>
2711  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n(phi1-phi2))>
2712  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n(phi1-phi2))> 
2713  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n(phi1-phi2))>
2714  //  5th bin:           ----  EMPTY ----
2715  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n(2*phi1-phi2-phi3))>
2716  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n(3*phi1-2*phi2-phi3))>
2717  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n(4*phi1-2*phi2-2*phi3))>
2718  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n(4*phi1-3*phi2-phi3))>
2719  // 10th bin:           ----  EMPTY ----
2720  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n(phi1+phi2-phi3-phi4))>
2721  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(n(2*phi1+phi2-2*phi3-phi4))>
2722  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(2n(phi1+phi2-phi3-phi4))>
2723  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n(3*phi1-phi2-phi3-phi4))> 
2724  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n(3*phi1+phi2-3*phi3-phi4))>
2725  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n(3*phi1+phi2-2*phi3-2*phi4))>
2726  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n(4*phi1-2*phi2-phi3-phi4))>
2727  // 18th bin:           ----  EMPTY ----
2728  // 19th bin: <5>_{2n,1n|1n,1n,1n} = five2n1n1n1n1n = <cos(n(2*phi1+phi2-phi3-phi4-phi5))>
2729  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n(2*phi1+2*phi2-2*phi3-phi4-phi5))>
2730  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n(3*phi1+phi2-2*phi3-phi4-phi5))>
2731  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n(4*phi1-phi2-phi3-phi4-phi5))>
2732  // 23rd bin:           ----  EMPTY ----
2733  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n(phi1+phi2+phi3-phi4-phi5-phi6))>
2734  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n(2*phi1+phi2+phi3-2*phi4-phi5-phi6))>
2735  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n(2*phi1+2*phi2-phi3-phi4-phi5-phi6))>
2736  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n(3*phi1+phi2-phi3-phi4-phi5-phi6))> 
2737  // 28th bin:           ----  EMPTY ----
2738  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n(2*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2739  // 30th bin:           ----  EMPTY ----
2740  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2741  // 32nd bin:           ----  EMPTY ----
2742  //  Extra correlations for v3{5} study: 
2743  // 33rd bin: <4>_{4n,2n|3n,3n} = four4n2n3n3n = <cos(n(4*phi1+2*phi2-3*phi3-3*phi4))>
2744  // 34th bin: <5>_{3n,3n|2n,2n,2n} = five3n3n2n2n2n = <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-2*phi5))> 
2745  //  Extra correlations for Teaney-Yan study: 
2746  // 35th bin: <2>_{5n|5n} = two5n5n = <cos(5n(phi1-phi2)> 
2747  // 36th bin: <2>_{6n|6n} = two6n6n = <cos(6n(phi1-phi2)> 
2748  // 37th bin: <3>_{5n|3n,2n} = three5n3n2n = <cos(n(5*phi1-3*phi2-2*phi3)> 
2749  // 38th bin: <3>_{5n|4n,1n} = three5n4n1n = <cos(n(5*phi1-4*phi2-1*phi3)> 
2750  // 39th bin: <3>_{6n|3n,3n} = three6n3n3n = <cos(n(6*phi1-3*phi2-3*phi3)> 
2751  // 40th bin: <3>_{6n|4n,2n} = three6n4n2n = <cos(n(6*phi1-4*phi2-2*phi3)> 
2752  // 41st bin: <3>_{6n|5n,1n} = three6n5n1n = <cos(n(6*phi1-5*phi2-1*phi3)>
2753  // 42nd bin: <4>_{6n|3n,2n,1n} = four6n3n2n1n = <cos(n(6*phi1-3*phi2-2*phi3-1*phi4)>
2754  // 43rd bin: <4>_{3n,2n|3n,2n} = four3n2n3n2n = <cos(n(3*phi1+2*phi2-3*phi3-2*phi4)>
2755  // 44th bin: <4>_{4n,1n|3n,2n} = four4n1n3n2n = <cos(n(4*phi1+1*phi2-3*phi3-2*phi4)>
2756  // 45th bin: <4>_{3n,3n|3n,3n} = four3n3n3n3n = <cos(3n*(phi1+phi2-phi3-phi4))> 
2757  // 46th bin: <4>_{4n,2n|3n,3n} = four4n2n3n3n = <cos(n(4*phi1+2*phi2-3*phi3-3*phi4)>
2758  // 47th bin: <4>_{5n,1n|3n,3n} = four5n1n3n3n = <cos(n(5*phi1+1*phi2-3*phi3-3*phi4)>
2759  // 48th bin: <4>_{4n,2n|4n,2n} = four4n2n4n2n = <cos(n(4*phi1+2*phi2-4*phi3-2*phi4)> 
2760  // 49th bin: <4>_{5n,1n|4n,2n} = four5n1n4n2n = <cos(n(5*phi1+1*phi2-4*phi3-2*phi4)>
2761  // 50th bin: <4>_{5n|3n,1n,1n} = four5n3n1n1n = <cos(n(5*phi1-3*phi2-1*phi3-1*phi4)>
2762  // 51st bin: <4>_{5n|2n,2n,1n} = four5n2n2n1n = <cos(n(5*phi1-2*phi2-2*phi3-1*phi4)>
2763  // 52nd bin: <4>_{5n,1n|5n,1n} = four5n1n5n1n = <cos(n(5*phi1+1*phi2-5*phi3-1*phi4)>
2764  // 53rd bin: <5>_{3n,3n|3n,2n,1n} = five3n3n3n2n1n = <cos(n(3*phi1+3*phi2-3*phi3-2*phi4-1*phi5)>
2765  // 54th bin: <5>_{4n,2n|3n,2n,1n} = five4n2n3n2n1n = <cos(n(4*phi1+2*phi2-3*phi3-2*phi4-1*phi5)>
2766  // 55th bin: <5>_{3n,2n|3n,1n,1n} = five3n2n3n1n1n = <cos(n(3*phi1+2*phi2-3*phi3-1*phi4-1*phi5)>
2767  // 56th bin: <5>_{3n,2n|2n,2n,1n} = five3n2n2n2n1n = <cos(n(3*phi1+2*phi2-2*phi3-2*phi4-1*phi5)>
2768  // 57th bin: <5>_{5n,1n|3n,2n,1n} = five5n1n3n2n1n = <cos(n(5*phi1+1*phi2-3*phi3-2*phi4-1*phi5)>
2769  // 58th bin: <6>_{3n,2n,1n|3n,2n,1n} = six3n2n1n3n2n1n = <cos(n(3*phi1+2*phi2+1*phi3-3*phi4-2*phi5-1*phi6)>
2770  //  Extra correlations for Teaney-Yan study (B): 
2771  // 59th bin: <4>_{6n|4n,1n,1n} = four6n4n1n1n = <cos(n(6*phi1-4*phi2-1*phi3-1*phi4)>
2772  // 60th bin: <4>_{6n|2n,2n,2n} = four6n2n2n2n = <cos(n(6*phi1-2*phi2-2*phi3-2*phi4)>
2773  // 61st bin: <5>_{6n|2n,2n,1n,1n} = five6n2n2n1n1n = <cos(n(6*phi1-2*phi2-2*phi3-1*phi4-1*phi5)>
2774  // 62nd bin: <5>_{4n,1n,1n|3n,3n} = five4n1n1n3n3n = <cos(n(4*phi1+1*phi2+1*phi3-3*phi4-3*phi5)>
2775  // 63rd bin: <6>_{3n,3n|2n,2n,1n,1n} = six3n3n2n2n1n1n = <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-1*phi5-1*phi6)>
2776  // --------------------------------------------------------------------------------------------------------------------
2777
2778  // Multiplicity of an event: 
2779  Double_t dMult = (*fSpk)(0,0);
2780  // Real parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n, 4n, 5n and 6n: 
2781  Double_t dReQ1n = (*fReQ)(0,0);
2782  Double_t dReQ2n = (*fReQ)(1,0);
2783  Double_t dReQ3n = (*fReQ)(2,0);
2784  Double_t dReQ4n = (*fReQ)(3,0);
2785  Double_t dReQ5n = (*fReQ)(4,0); 
2786  Double_t dReQ6n = (*fReQ)(5,0);
2787  // Imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n, 4n, 5n and 6n:
2788  Double_t dImQ1n = (*fImQ)(0,0);
2789  Double_t dImQ2n = (*fImQ)(1,0);
2790  Double_t dImQ3n = (*fImQ)(2,0);
2791  Double_t dImQ4n = (*fImQ)(3,0);
2792  Double_t dImQ5n = (*fImQ)(4,0); 
2793  Double_t dImQ6n = (*fImQ)(5,0);
2794   
2795  // Real parts of expressions involving various combinations of Q-vectors which appears
2796  // simultaneously in several equations for multiparticle correlations bellow: 
2797  // Re[Q_{2n}Q_{n}^*Q_{n}^*]
2798  Double_t reQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dImQ1n*dImQ2n-pow(dImQ1n,2.)*dReQ2n; 
2799  // Re[Q_{6n}Q_{3n}^*Q_{3n}^*]
2800  Double_t reQ6nQ3nstarQ3nstar = pow(dReQ3n,2.)*dReQ6n+2.*dReQ3n*dImQ3n*dImQ6n-pow(dImQ3n,2.)*dReQ6n;  
2801  // Re[Q_{4n}Q_{2n}^*Q_{2n}^*]
2802  Double_t reQ4nQ2nstarQ2nstar = pow(dReQ2n,2.)*dReQ4n+2.*dReQ2n*dImQ2n*dImQ4n-pow(dImQ2n,2.)*dReQ4n;
2803  // Re[Q_{4n}Q_{3n}^*Q_{n}^*]
2804  Double_t reQ4nQ3nstarQ1nstar = dReQ4n*(dReQ3n*dReQ1n-dImQ3n*dImQ1n)+dImQ4n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
2805  // Re[Q_{3n}Q_{2n}^*Q_{n}^*]
2806  Double_t reQ3nQ2nstarQ1nstar = dReQ3n*dReQ2n*dReQ1n-dReQ3n*dImQ2n*dImQ1n+dImQ3n*dReQ2n*dImQ1n
2807                               + dImQ3n*dImQ2n*dReQ1n; 
2808  // Re[Q_{5n}Q_{3n}^*Q_{2n}^*]
2809  Double_t reQ5nQ3nstarQ2nstar = dReQ5n*dReQ2n*dReQ3n-dReQ5n*dImQ2n*dImQ3n+dImQ5n*dReQ2n*dImQ3n
2810                               + dImQ5n*dImQ2n*dReQ3n;                             
2811  // Re[Q_{5n}Q_{4n}^*Q_{1n}^*]
2812  Double_t reQ5nQ4nstarQ1nstar = dReQ5n*dReQ4n*dReQ1n-dReQ5n*dImQ4n*dImQ1n+dImQ5n*dReQ4n*dImQ1n
2813                               + dImQ5n*dImQ4n*dReQ1n;                              
2814  // Re[Q_{6n}Q_{5n}^*Q_{1n}^*]                              
2815  Double_t reQ6nQ5nstarQ1nstar = dReQ6n*dReQ5n*dReQ1n-dReQ6n*dImQ5n*dImQ1n+dImQ6n*dReQ5n*dImQ1n
2816                               + dImQ6n*dImQ5n*dReQ1n;
2817  // Re[Q_{6n}Q_{4n}^*Q_{2n}^*]                              
2818  Double_t reQ6nQ4nstarQ2nstar = dReQ6n*dReQ4n*dReQ2n-dReQ6n*dImQ4n*dImQ2n+dImQ6n*dReQ4n*dImQ2n
2819                               + dImQ6n*dImQ4n*dReQ2n;
2820  // Re[Q_{3n}Q_{n}Q_{2n}^*Q_{2n}^*]
2821  Double_t reQ3nQ1nQ2nstarQ2nstar = (pow(dReQ2n,2.)-pow(dImQ2n,2.))*(dReQ3n*dReQ1n-dImQ3n*dImQ1n) 
2822                                  + 2.*dReQ2n*dImQ2n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);                                
2823  // Re[Q_{3n}Q_{n}^*Q_{n}^*Q_{n}^*]
2824  Double_t reQ3nQ1nstarQ1nstarQ1nstar = dReQ3n*pow(dReQ1n,3)-3.*dReQ1n*dReQ3n*pow(dImQ1n,2)
2825                                      + 3.*dImQ1n*dImQ3n*pow(dReQ1n,2)-dImQ3n*pow(dImQ1n,3);
2826  // Re[Q_{6n}Q_{2n}^*Q_{2n}^*Q_{2n}^*]
2827  Double_t reQ6nQ2nstarQ2nstarQ2nstar = dReQ6n*pow(dReQ2n,3)-3.*dReQ2n*dReQ6n*pow(dImQ2n,2)
2828                                      + 3.*dImQ2n*dImQ6n*pow(dReQ2n,2)-dImQ6n*pow(dImQ2n,3);
2829  // Re[Q_{4n}Q_{2n}^*Q_{n}^*Q_{n}^*]
2830  Double_t reQ4nQ2nstarQ1nstarQ1nstar = (dReQ4n*dReQ2n+dImQ4n*dImQ2n)*(pow(dReQ1n,2)-pow(dImQ1n,2)) 
2831                                      + 2.*dReQ1n*dImQ1n*(dImQ4n*dReQ2n-dReQ4n*dImQ2n);  
2832  // Re[Q_{4n}Q_{2n}^*Q_{3n}^*Q_{3n}^*]
2833  Double_t reQ4nQ2nQ3nstarQ3nstar = (dReQ4n*dReQ2n-dImQ4n*dImQ2n)*(dReQ3n*dReQ3n-dImQ3n*dImQ3n)
2834                                  + 2.*(dReQ4n*dImQ2n+dImQ4n*dReQ2n)*dReQ3n*dImQ3n;                    
2835  // Re[Q_{4n}Q_{n}Q_{3n}^*Q_{2n}^*]
2836  Double_t reQ4nQ1nQ3nstarQ2nstar = dImQ1n*dImQ2n*dImQ3n*dImQ4n+dImQ3n*dImQ4n*dReQ1n*dReQ2n 
2837                                  + dImQ2n*dImQ4n*dReQ1n*dReQ3n-dImQ1n*dImQ4n*dReQ2n*dReQ3n
2838                                  - dImQ2n*dImQ3n*dReQ1n*dReQ4n+dImQ1n*dImQ3n*dReQ2n*dReQ4n 
2839                                  + dImQ1n*dImQ2n*dReQ3n*dReQ4n+dReQ1n*dReQ2n*dReQ3n*dReQ4n;
2840  // Re[Q_{5n}Q_{n}Q_{4n}^*Q_{2n}^*]
2841  Double_t reQ5nQ1nQ4nstarQ2nstar = dImQ1n*dImQ2n*dImQ4n*dImQ5n+dImQ4n*dImQ5n*dReQ1n*dReQ2n 
2842                                  + dImQ2n*dImQ5n*dReQ1n*dReQ4n-dImQ1n*dImQ5n*dReQ2n*dReQ4n
2843                                  - dImQ2n*dImQ4n*dReQ1n*dReQ5n+dImQ1n*dImQ4n*dReQ2n*dReQ5n 
2844                                  + dImQ1n*dImQ2n*dReQ4n*dReQ5n+dReQ1n*dReQ2n*dReQ4n*dReQ5n;                                  
2845  // Re[Q_{5n}Q_{n}Q_{3n}^*Q_{3n}^*]                                  
2846  Double_t reQ5nQ1nQ3nstarQ3nstar = dImQ1n*pow(dImQ3n,2.)*dImQ5n+2.*dImQ3n*dImQ5n*dReQ1n*dReQ3n
2847                                  - dImQ1n*dImQ5n*pow(dReQ3n,2.)-pow(dImQ3n,2.)*dReQ1n*dReQ5n 
2848                                  + 2.*dImQ1n*dImQ3n*dReQ3n*dReQ5n+dReQ1n*pow(dReQ3n,2.)*dReQ5n;
2849  // Re[Q_{5n}Q_{3n}^*Q_{n}^*Q_{n}^*]                                  
2850  Double_t reQ5nQ3nstarQ1nstarQ1nstar = -pow(dImQ1n,2.)*dImQ3n*dImQ5n+dImQ3n*dImQ5n*pow(dReQ1n,2.)
2851                                      + 2.*dImQ1n*dImQ5n*dReQ1n*dReQ3n-2.*dImQ1n*dImQ3n*dReQ1n*dReQ5n 
2852                                      - pow(dImQ1n,2.)*dReQ3n*dReQ5n+pow(dReQ1n,2.)*dReQ3n*dReQ5n;                     
2853  // Re[Q_{5n}Q_{2n}^*Q_{2n}^*Q_{n}^*]                                  
2854  Double_t reQ5nQ2nstarQ2nstarQ1nstar = -pow(dImQ2n,2.)*dImQ1n*dImQ5n+dImQ1n*dImQ5n*pow(dReQ2n,2.)
2855                                      + 2.*dImQ2n*dImQ5n*dReQ2n*dReQ1n-2.*dImQ2n*dImQ1n*dReQ2n*dReQ5n 
2856                                      - pow(dImQ2n,2.)*dReQ1n*dReQ5n+pow(dReQ2n,2.)*dReQ1n*dReQ5n;                                     
2857  // Re[Q_{6n}Q_{4n}^*Q_{n}^*Q_{n}^*]                                  
2858  Double_t reQ6nQ4nstarQ1nstarQ1nstar = -pow(dImQ1n,2.)*dImQ4n*dImQ6n+dImQ4n*dImQ6n*pow(dReQ1n,2.) 
2859                                      +  2.*dImQ1n*dImQ6n*dReQ1n*dReQ4n-2.*dImQ1n*dImQ4n*dReQ1n*dReQ6n 
2860                                      -  pow(dImQ1n,2.)*dReQ4n*dReQ6n+pow(dReQ1n,2.)*dReQ4n*dReQ6n;
2861  // |Q_{2n}|^2 |Q_{n}|^2
2862  Double_t dQ2nQ1nQ2nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
2863  // |Q_{4n}|^2 |Q_{2n}|^2
2864  Double_t dQ4nQ2nQ4nstarQ2nstar = (pow(dReQ4n,2.)+pow(dImQ4n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.));
2865  // |Q_{3n}|^2 |Q_{2n}|^2
2866  Double_t dQ3nQ2nQ3nstarQ2nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.));
2867  // |Q_{5n}|^2 |Q_{n}|^2
2868  Double_t dQ5nQ1nQ5nstarQ1nstar = (pow(dReQ5n,2.)+pow(dImQ5n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
2869  // Re[Q_{2n}Q_{n}Q_{n}^*Q_{n}^*Q_{n}^*]
2870  Double_t reQ2nQ1nQ1nstarQ1nstarQ1nstar = (dReQ2n*dReQ1n-dImQ2n*dImQ1n)*(pow(dReQ1n,3)-3.*dReQ1n*pow(dImQ1n,2))
2871                                         + (dReQ2n*dImQ1n+dReQ1n*dImQ2n)*(3.*dImQ1n*pow(dReQ1n,2)-pow(dImQ1n,3)); 
2872  // Re[Q_{2n}Q_{2n}Q_{2n}^*Q_{n}^*Q_{n}^*]
2873  Double_t reQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2874                                         * (dReQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) + 2.*dImQ2n*dReQ1n*dImQ1n);
2875  // Re[Q_{4n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2876  Double_t reQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dReQ4n-6.*pow(dReQ1n,2.)*dReQ4n*pow(dImQ1n,2.)
2877                                             + pow(dImQ1n,4.)*dReQ4n+4.*pow(dReQ1n,3.)*dImQ1n*dImQ4n
2878                                             - 4.*pow(dImQ1n,3.)*dReQ1n*dImQ4n;
2879  // Re[Q_{3n}Q_{n}Q_{2n}^*Q_{n}^*Q_{n}^*]
2880  Double_t reQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2881                                         * (dReQ1n*dReQ2n*dReQ3n-dReQ3n*dImQ1n*dImQ2n
2882                                         + dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n);
2883  // Re[Q_{6n}Q_{n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2884  Double_t reQ6nQ3nstarQ2nstarQ1nstar = dReQ1n*dReQ2n*dReQ3n*dReQ6n-dReQ3n*dReQ6n*dImQ1n*dImQ2n
2885                                      - dReQ2n*dReQ6n*dImQ1n*dImQ3n-dReQ1n*dReQ6n*dImQ2n*dImQ3n
2886                                      + dReQ2n*dReQ3n*dImQ1n*dImQ6n+dReQ1n*dReQ3n*dImQ2n*dImQ6n 
2887                                      + dReQ1n*dReQ2n*dImQ3n*dImQ6n-dImQ1n*dImQ2n*dImQ3n*dImQ6n;
2888  // Re[Q_{3n}Q_{3n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2889  Double_t reQ3nQ3nQ3nstarQ2nstarQ1nstar = (pow(dImQ3n,2.)+pow(dReQ3n,2.))
2890                                         * (dImQ2n*dImQ3n*dReQ1n+dImQ1n*dImQ3n*dReQ2n
2891                                         - dImQ1n*dImQ2n*dReQ3n+dReQ1n*dReQ2n*dReQ3n);   
2892  // Re[Q_{3n}Q_{3n}Q_{2n}^*Q_{2n}^*Q_{2n}^*]
2893  Double_t reQ3nQ3nQ2nstarQ2nstarQ2nstar = pow(dReQ2n,3.)*pow(dReQ3n,2.) 
2894                                         - 3.*dReQ2n*pow(dReQ3n,2.)*pow(dImQ2n,2.)
2895                                         + 6.*pow(dReQ2n,2.)*dReQ3n*dImQ2n*dImQ3n 
2896                                         - 2.*dReQ3n*pow(dImQ2n,3.)*dImQ3n-pow(dReQ2n,3.)*pow(dImQ3n,2.) 
2897                                         + 3.*dReQ2n*pow(dImQ2n,2.)*pow(dImQ3n,2.);
2898  // Re[Q_{4n}Q_{2n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2899  Double_t reQ4nQ2nQ3nstarQ2nstarQ1nstar = (pow(dImQ2n,2.)+pow(dReQ2n,2.))
2900                                         * (dImQ3n*dImQ4n*dReQ1n+dImQ1n*dImQ4n*dReQ3n 
2901                                         - dImQ1n*dImQ3n*dReQ4n+dReQ1n*dReQ3n*dReQ4n);
2902  // Re[Q_{3n}Q_{2n}Q_{3n}^*Q_{n}^*Q_{n}^*]
2903  Double_t reQ3nQ2nQ3nstarQ1nstarQ1nstar = -(pow(dImQ3n,2.)+pow(dReQ3n,2.))
2904                                         * (-2.*dImQ1n*dImQ2n*dReQ1n+pow(dImQ1n,2.)*dReQ2n-pow(dReQ1n,2.)*dReQ2n);                              
2905  // Re[Q_{3n}Q_{2n}Q_{2n}^*Q_{2n}^*Q_{n}^*]
2906  Double_t reQ3nQ2nQ2nstarQ2nstarQ1nstar = (pow(dImQ2n,2.)+pow(dReQ2n,2.))
2907                                         * (dImQ2n*dImQ3n*dReQ1n+dImQ1n*dImQ3n*dReQ2n 
2908                                         - dImQ1n*dImQ2n*dReQ3n+dReQ1n*dReQ2n*dReQ3n);
2909  // Re[Q_{5n}Q_{n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2910  Double_t reQ5nQ1nQ3nstarQ2nstarQ1nstar = (pow(dImQ1n,2.)+pow(dReQ1n,2.))
2911                                         * (dImQ3n*dImQ5n*dReQ2n+dImQ2n*dImQ5n*dReQ3n 
2912                                         - dImQ2n*dImQ3n*dReQ5n+dReQ2n*dReQ3n*dReQ5n);   
2913  // Re[Q_{2n}Q_{2n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2914  Double_t reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)*dReQ2n-2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2915                                                + dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n-pow(dImQ1n,2.)*dImQ2n)
2916                                                * (pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2917                                                - dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n+pow(dImQ1n,2.)*dImQ2n); 
2918  // Re[Q_{3n}Q_{n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2919  Double_t reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2920                                                * (pow(dReQ1n,3.)*dReQ3n-3.*dReQ1n*dReQ3n*pow(dImQ1n,2.)
2921                                                + 3.*pow(dReQ1n,2.)*dImQ1n*dImQ3n-pow(dImQ1n,3.)*dImQ3n);
2922  // |Q_{2n}|^2 |Q_{n}|^4
2923  Double_t dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.); 
2924  // |Q_{3n}|^2 |Q_{2n}|^2 |Q_{n}|^2
2925  Double_t dQ3nQ2nQ1nQ3nstarQ2nstarQ1nstar = (pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2926                                           * (pow(dReQ1n,2.)+pow(dImQ1n,2.));
2927  // Re[Q_{2n}Q_{n}Q_{n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2928  Double_t reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2929                                                   * (pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2930                                                   + 2.*dReQ1n*dImQ1n*dImQ2n);
2931     
2932  // Results for multiparticle azimuthal correlations:
2933  // 2-particle:
2934  Double_t two1n1n = 0.; // <cos(n(phi1-phi2))>
2935  Double_t two2n2n = 0.; // <cos(2n(phi1-phi2))>
2936  Double_t two3n3n = 0.; // <cos(3n(phi1-phi2))>
2937  Double_t two4n4n = 0.; // <cos(4n(phi1-phi2))>
2938  if(dMult>1)
2939  {
2940   two1n1n = (pow(dReQ1n,2.)+pow(dImQ1n,2.)-dMult)/(dMult*(dMult-1.)); 
2941   two2n2n = (pow(dReQ2n,2.)+pow(dImQ2n,2.)-dMult)/(dMult*(dMult-1.)); 
2942   two3n3n = (pow(dReQ3n,2.)+pow(dImQ3n,2.)-dMult)/(dMult*(dMult-1.)); 
2943   two4n4n = (pow(dReQ4n,2.)+pow(dImQ4n,2.)-dMult)/(dMult*(dMult-1.)); 
2944   // Average 2-particle correlations for single event: 
2945   fIntFlowCorrelationsAllEBE->SetBinContent(1,two1n1n);
2946   fIntFlowCorrelationsAllEBE->SetBinContent(2,two2n2n);
2947   fIntFlowCorrelationsAllEBE->SetBinContent(3,two3n3n);
2948   fIntFlowCorrelationsAllEBE->SetBinContent(4,two4n4n);         
2949   // Average 2-particle correlations for all events:      
2950   fIntFlowCorrelationsAllPro->Fill(0.5,two1n1n,dMult*(dMult-1.));
2951   fIntFlowCorrelationsAllPro->Fill(1.5,two2n2n,dMult*(dMult-1.)); 
2952   fIntFlowCorrelationsAllPro->Fill(2.5,two3n3n,dMult*(dMult-1.)); 
2953   fIntFlowCorrelationsAllPro->Fill(3.5,two4n4n,dMult*(dMult-1.)); 
2954   // Store separetately <2>:
2955   fIntFlowCorrelationsEBE->SetBinContent(1,two1n1n); // <2>  
2956   // Testing other multiplicity weights:
2957   Double_t mWeight2p = 0.;
2958   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2959   {
2960    mWeight2p = dMult*(dMult-1.);
2961   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2962     {
2963      mWeight2p = 1.;    
2964     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2965       {
2966        mWeight2p = dMult;           
2967       }          
2968   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,mWeight2p); // eW_<2>
2969   fIntFlowCorrelationsPro->Fill(0.5,two1n1n,mWeight2p);
2970   fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1n*two1n1n,mWeight2p);
2971   if(fCalculateCumulantsVsM)
2972   {
2973    fIntFlowCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n,mWeight2p);
2974    fIntFlowSquaredCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n*two1n1n,mWeight2p);
2975   } 
2976   if(fCalculateAllCorrelationsVsM)
2977   {
2978    fIntFlowCorrelationsAllVsMPro[0]->Fill(dMult+0.5,two1n1n,mWeight2p);
2979    fIntFlowCorrelationsAllVsMPro[1]->Fill(dMult+0.5,two2n2n,mWeight2p);
2980    fIntFlowCorrelationsAllVsMPro[2]->Fill(dMult+0.5,two3n3n,mWeight2p);
2981    fIntFlowCorrelationsAllVsMPro[3]->Fill(dMult+0.5,two4n4n,mWeight2p);
2982   }  
2983  } // end of if(dMult>1)
2984  
2985  // 3-particle:
2986  Double_t three2n1n1n = 0.; // <cos(n(2*phi1-phi2-phi3))>
2987  Double_t three3n2n1n = 0.; // <cos(n(3*phi1-2*phi2-phi3))>
2988  Double_t three4n2n2n = 0.; // <cos(n(4*phi1-2*phi2-2*phi3))>
2989  Double_t three4n3n1n = 0.; // <cos(n(4*phi1-3*phi2-phi3))> 
2990  if(dMult>2)
2991  {
2992   three2n1n1n = (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2993               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
2994               / (dMult*(dMult-1.)*(dMult-2.));                     
2995   three3n2n1n = (reQ3nQ2nstarQ1nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2996               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2997               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2998               / (dMult*(dMult-1.)*(dMult-2.));
2999   three4n2n2n = (reQ4nQ2nstarQ2nstar-2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3000               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*dMult)
3001               / (dMult*(dMult-1.)*(dMult-2.)); 
3002   three4n3n1n = (reQ4nQ3nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3003               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
3004               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3005               / (dMult*(dMult-1.)*(dMult-2.));              
3006   // Average 3-particle correlations for single event: 
3007   fIntFlowCorrelationsAllEBE->SetBinContent(6,three2n1n1n);
3008   fIntFlowCorrelationsAllEBE->SetBinContent(7,three3n2n1n);
3009   fIntFlowCorrelationsAllEBE->SetBinContent(8,three4n2n2n);
3010   fIntFlowCorrelationsAllEBE->SetBinContent(9,three4n3n1n);
3011   // Average 3-particle correlations for all events:                
3012   fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.)); 
3013   fIntFlowCorrelationsAllPro->Fill(6.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
3014   fIntFlowCorrelationsAllPro->Fill(7.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.)); 
3015   fIntFlowCorrelationsAllPro->Fill(8.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));  
3016   // Average 3-particle correlations vs M for all events:                
3017   if(fCalculateAllCorrelationsVsM)
3018   {
3019    fIntFlowCorrelationsAllVsMPro[5]->Fill(dMult+0.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.));
3020    fIntFlowCorrelationsAllVsMPro[6]->Fill(dMult+0.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
3021    fIntFlowCorrelationsAllVsMPro[7]->Fill(dMult+0.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.));
3022    fIntFlowCorrelationsAllVsMPro[8]->Fill(dMult+0.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));
3023   }    
3024  } // end of if(dMult>2)
3025  
3026  // 4-particle:
3027  Double_t four1n1n1n1n = 0.; // <cos(n(phi1+phi2-phi3-phi4))>
3028  Double_t four2n2n2n2n = 0.; // <cos(2n(phi1+phi2-phi3-phi4))>
3029  Double_t four2n1n2n1n = 0.; // <cos(n(2*phi1+phi2-2*phi3-phi4))> 
3030  Double_t four3n1n1n1n = 0.; // <cos(n(3*phi1-phi2-phi3-phi4))> 
3031  Double_t four4n2n1n1n = 0.; // <cos(n(4*phi1-2*phi2-phi3-phi4))> 
3032  Double_t four3n1n2n2n = 0.; // <cos(n(3*phi1+phi2-2*phi3-2*phi4))> 
3033  Double_t four3n1n3n1n = 0.; // <cos(n(3*phi1+phi2-3*phi3-phi4))>    
3034  if(dMult>3)
3035  {
3036   four1n1n1n1n = (2.*dMult*(dMult-3.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ1n,2.)
3037                + pow(dImQ1n,2.))-2.*reQ2nQ1nstarQ1nstar+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
3038                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));     
3039   four2n2n2n2n = (2.*dMult*(dMult-3.)+pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ2n,2.)
3040                + pow(dImQ2n,2.))-2.*reQ4nQ2nstarQ2nstar+(pow(dReQ4n,2.)+pow(dImQ4n,2.)))
3041                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));
3042   four2n1n2n1n = (dQ2nQ1nQ2nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar-2.*reQ2nQ1nstarQ1nstar)
3043                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3044                - ((dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3045                + (dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
3046                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3047                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
3048   four3n1n1n1n = (reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar-3.*reQ2nQ1nstarQ1nstar
3049                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3050                + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3051                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3052   four4n2n1n1n = (reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar)
3053                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3054                - (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3055                - 3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
3056                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3057                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
3058   four3n1n2n2n = (reQ3nQ1nQ2nstarQ2nstar-reQ4nQ2nstarQ2nstar-reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar)
3059                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3060                - (2.*reQ2nQ1nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3061                - 4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
3062                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3063                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.)); 
3064   four3n1n3n1n = ((pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3065                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar
3066                + pow(dReQ4n,2.)+pow(dImQ4n,2.)-(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3067                + pow(dReQ2n,2.)+pow(dImQ2n,2.)-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3068                + dMult*(dMult-6.))
3069                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));           
3070   // Average 4-particle correlations for single event: 
3071   fIntFlowCorrelationsAllEBE->SetBinContent(11,four1n1n1n1n);
3072   fIntFlowCorrelationsAllEBE->SetBinContent(12,four2n1n2n1n);
3073   fIntFlowCorrelationsAllEBE->SetBinContent(13,four2n2n2n2n);
3074   fIntFlowCorrelationsAllEBE->SetBinContent(14,four3n1n1n1n);
3075   fIntFlowCorrelationsAllEBE->SetBinContent(15,four3n1n3n1n);
3076   fIntFlowCorrelationsAllEBE->SetBinContent(16,four3n1n2n2n);
3077   fIntFlowCorrelationsAllEBE->SetBinContent(17,four4n2n1n1n);       
3078   // Average 4-particle correlations for all events:                
3079   fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3080   fIntFlowCorrelationsAllPro->Fill(11.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3081   fIntFlowCorrelationsAllPro->Fill(12.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3082   fIntFlowCorrelationsAllPro->Fill(13.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3083   fIntFlowCorrelationsAllPro->Fill(14.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3084   fIntFlowCorrelationsAllPro->Fill(15.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
3085   fIntFlowCorrelationsAllPro->Fill(16.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
3086   // Average 4-particle correlations vs M for all events:                
3087   if(fCalculateAllCorrelationsVsM)
3088   {
3089    fIntFlowCorrelationsAllVsMPro[10]->Fill(dMult+0.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3090    fIntFlowCorrelationsAllVsMPro[11]->Fill(dMult+0.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3091    fIntFlowCorrelationsAllVsMPro[12]->Fill(dMult+0.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3092    fIntFlowCorrelationsAllVsMPro[13]->Fill(dMult+0.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3093    fIntFlowCorrelationsAllVsMPro[14]->Fill(dMult+0.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3094    fIntFlowCorrelationsAllVsMPro[15]->Fill(dMult+0.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3095    fIntFlowCorrelationsAllVsMPro[16]->Fill(dMult+0.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3096   }       
3097   // Store separetately <4>:
3098   fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1n); // <4>
3099   // Testing other multiplicity weights:
3100   Double_t mWeight4p = 0.;
3101   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
3102   {
3103    mWeight4p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.);
3104   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
3105     {
3106      mWeight4p = 1.;    
3107     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
3108       {
3109        mWeight4p = dMult;           
3110       }      
3111   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,mWeight4p); // eW_<4>
3112   fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1n,mWeight4p);
3113   fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
3114   if(fCalculateCumulantsVsM)
3115   {
3116    fIntFlowCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n,mWeight4p);
3117    fIntFlowSquaredCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
3118   }   
3119  } // end of if(dMult>3)
3120
3121  // 5-particle:
3122  Double_t five2n1n1n1n1n = 0.; // <cos(n(2*phi1+phi2-phi3-phi4-phi5))>
3123  Double_t five2n2n2n1n1n = 0.; // <cos(n(2*phi1+2*phi2-2*phi3-phi4-phi5))>
3124  Double_t five3n1n2n1n1n = 0.; // <cos(n(3*phi1+phi2-2*phi3-phi4-phi5))>
3125  Double_t five4n1n1n1n1n = 0.; // <cos(n(4*phi1-phi2-phi3-phi4-phi5))>
3126  if(dMult>4)
3127  {            
3128   five2n1n1n1n1n = (reQ2nQ1nQ1nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar+5.*reQ3nQ2nstarQ1nstar
3129                  - 3.*(dMult-5.)*reQ2nQ1nstarQ1nstar-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3130                  - 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))     
3131                  + 3.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3132                  - 3.*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3133                  + 6.*(2.*dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult*(dMult-4.))
3134                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3135   five2n2n2n1n1n = (reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ3nQ1nQ2nstarQ2nstar
3136                  + 3.*reQ4nQ2nstarQ2nstar+8.*reQ3nQ2nstarQ1nstar+2.*reQ4nQ3nstarQ1nstar
3137                  - 2.*(dMult-6.)*reQ2nQ1nstarQ1nstar
3138                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3139                  - pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)
3140                  + 2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3141                  - 4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3142                  + 4.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3143                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3144   five4n1n1n1n1n = (reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ4nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nstarQ1nstarQ1nstar
3145                  + 8.*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+12.*reQ3nQ2nstarQ1nstar+12.*reQ2nQ1nstarQ1nstar
3146                  - 6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-8.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3147                  - 12.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+24.*dMult)
3148                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3149   five3n1n2n1n1n = (reQ3nQ1nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar
3150                  - reQ3nQ1nQ2nstarQ2nstar+4.*reQ4nQ3nstarQ1nstar+reQ4nQ2nstarQ2nstar
3151                  - (2.*dMult-13.)*reQ3nQ2nstarQ1nstar+7.*reQ2nQ1nstarQ1nstar
3152                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3153                  + 2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3154                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3155                  + 2.*(dMult-6.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3156                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3157                  - pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3158                  + 2.*(3.*dMult-11.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3159                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));                 
3160   // Average 5-particle correlations for single event: 
3161   fIntFlowCorrelationsAllEBE->SetBinContent(19,five2n1n1n1n1n);
3162   fIntFlowCorrelationsAllEBE->SetBinContent(20,five2n2n2n1n1n);
3163   fIntFlowCorrelationsAllEBE->SetBinContent(21,five3n1n2n1n1n);
3164   fIntFlowCorrelationsAllEBE->SetBinContent(22,five4n1n1n1n1n);        
3165   // Average 5-particle correlations for all events:                         
3166   fIntFlowCorrelationsAllPro->Fill(18.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
3167   fIntFlowCorrelationsAllPro->Fill(19.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3168   fIntFlowCorrelationsAllPro->Fill(20.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3169   fIntFlowCorrelationsAllPro->Fill(21.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
3170   // Average 5-particle correlations vs M for all events:                
3171   if(fCalculateAllCorrelationsVsM)
3172   {
3173    fIntFlowCorrelationsAllVsMPro[18]->Fill(dMult+0.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3174    fIntFlowCorrelationsAllVsMPro[19]->Fill(dMult+0.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3175    fIntFlowCorrelationsAllVsMPro[20]->Fill(dMult+0.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3176    fIntFlowCorrelationsAllVsMPro[21]->Fill(dMult+0.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3177   }    
3178  } // end of if(dMult>4)
3179     
3180  // 6-particle:
3181  Double_t six1n1n1n1n1n1n = 0.; // <cos(n(phi1+phi2+phi3-phi4-phi5-phi6))>
3182  Double_t six2n2n1n1n1n1n = 0.; // <cos(n(2*phi1+2*phi2-phi3-phi4-phi5-phi6))>
3183  Double_t six3n1n1n1n1n1n = 0.; // <cos(n(3*phi1+phi2-phi3-phi4-phi5-phi6))>
3184  Double_t six2n1n1n2n1n1n = 0.; // <cos(n(2*phi1+phi2+phi3-2*phi4-phi5-phi6))>
3185  if(dMult>5)
3186  {
3187   six1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)-6.*reQ2nQ1nQ1nstarQ1nstarQ1nstar
3188                   + 4.*reQ3nQ1nstarQ1nstarQ1nstar-12.*reQ3nQ2nstarQ1nstar+18.*(dMult-4.)*reQ2nQ1nstarQ1nstar
3189                   + 9.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3190                   + 4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))-9.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3191                   - 9.*(dMult-4.)*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.) 
3192                   + 18.*(dMult*dMult-7.*dMult+10.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3193                   - 6.*dMult*(dMult*dMult-9.*dMult+20.))
3194                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3195   six2n1n1n2n1n1n = (dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nQ2nstarQ1nstarQ1nstar
3196                   - 4.*reQ2nQ1nQ1nstarQ1nstarQ1nstar-2.*reQ2nQ2nQ2nstarQ1nstarQ1nstar
3197                   + 4.*reQ4nQ2nstarQ1nstarQ1nstar+4.*reQ3nQ1nQ2nstarQ2nstar+4.*reQ3nQ1nstarQ1nstarQ1nstar
3198                   - 8.*reQ4nQ3nstarQ1nstar-4.*reQ4nQ2nstarQ2nstar+4.*(2.*dMult-13.)*reQ3nQ2nstarQ1nstar
3199                   + 2.*(7.*dMult-34.)*reQ2nQ1nstarQ1nstar+4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3200                   - 4.*(dMult-7.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3201                   + 4.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-4.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3202                   + pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)+(2.*dMult*dMult-27.*dMult+76.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3203                   - (dMult-12.)*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3204                   + 4.*(dMult*dMult-15.*dMult+34.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3205                   - 2.*dMult*(dMult*dMult-17.*dMult+60.))
3206                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3207   six2n2n1n1n1n1n = (reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ1nstarQ1nstarQ1nstarQ1nstar
3208                   - 8.*reQ2nQ1nQ1nstarQ1nstarQ1nstar+8.*reQ3nQ1nstarQ1nstarQ1nstar+6.*reQ4nQ2nstarQ1nstarQ1nstar
3209                   + 8.*reQ3nQ1nQ2nstarQ2nstar-40.*reQ3nQ2nstarQ1nstar-8.*reQ4nQ3nstarQ1nstar-9.*reQ4nQ2nstarQ2nstar
3210                   + 24.*(dMult-4.)*reQ2nQ1nstarQ1nstar+24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3211                   + 6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+16.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3212                   + 3.*pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-12.*(2.*dMult-7.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3213                   + 12.*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-48.*(dMult-3.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3214                   + 24.*dMult*(dMult-5.))
3215                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3216   six3n1n1n1n1n1n = (reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ3nQ1nQ2nstarQ1nstarQ1nstar+6.*reQ4nQ2nstarQ1nstarQ1nstar
3217                   - reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-4.*reQ2nQ1nQ1nstarQ1nstarQ1nstar+3.*reQ3nQ1nQ2nstarQ2nstar
3218                   - 4.*(dMult-5.)*reQ3nQ1nstarQ1nstarQ1nstar-14.*reQ4nQ3nstarQ1nstar
3219                   - 3.*reQ4nQ2nstarQ2nstar+4.*(3.*dMult-17.)*reQ3nQ2nstarQ1nstar+12.*(dMult-6.)*reQ2nQ1nstarQ1nstar
3220                   + 12.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))  
3221                   + 8.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))  
3222                   + 6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-8.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.)) 
3223                   - 12.*(dMult-5.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-48.*(dMult-3.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3224                   + 12.*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)+24.*dMult*(dMult-5.))
3225                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3226   // Average 6-particle correlations for single event: 
3227   fIntFlowCorrelationsAllEBE->SetBinContent(24,six1n1n1n1n1n1n);
3228   fIntFlowCorrelationsAllEBE->SetBinContent(25,six2n1n1n2n1n1n);
3229   fIntFlowCorrelationsAllEBE->SetBinContent(26,six2n2n1n1n1n1n);
3230   fIntFlowCorrelationsAllEBE->SetBinContent(27,six3n1n1n1n1n1n);
3231   // Average 6-particle correlations for all events:         
3232   fIntFlowCorrelationsAllPro->Fill(23.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3233   fIntFlowCorrelationsAllPro->Fill(24.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3234   fIntFlowCorrelationsAllPro->Fill(25.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3235   fIntFlowCorrelationsAllPro->Fill(26.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3236   // Average 6-particle correlations vs M for all events:                
3237   if(fCalculateAllCorrelationsVsM)
3238   {
3239    fIntFlowCorrelationsAllVsMPro[23]->Fill(dMult+0.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3240    fIntFlowCorrelationsAllVsMPro[24]->Fill(dMult+0.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3241    fIntFlowCorrelationsAllVsMPro[25]->Fill(dMult+0.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3242    fIntFlowCorrelationsAllVsMPro[26]->Fill(dMult+0.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3243   }    
3244   // Store separetately <6>:
3245   fIntFlowCorrelationsEBE->SetBinContent(3,six1n1n1n1n1n1n); // <6>
3246   // Testing other multiplicity weights:
3247   Double_t mWeight6p = 0.;
3248   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
3249   {
3250    mWeight6p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.);
3251   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
3252     {
3253      mWeight6p = 1.;    
3254     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
3255       {
3256        mWeight6p = dMult;           
3257       }
3258   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(3,mWeight6p); // eW_<6>
3259   fIntFlowCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n,mWeight6p);
3260   fIntFlowSquaredCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
3261   if(fCalculateCumulantsVsM)
3262   {
3263    fIntFlowCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n,mWeight6p);
3264    fIntFlowSquaredCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
3265   }    
3266  } // end of if(dMult>5)
3267  
3268  // 7-particle:
3269  Double_t seven2n1n1n1n1n1n1n = 0.; // <cos(n(2*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
3270  if(dMult>6)
3271  {
3272   seven2n1n1n1n1n1n1n = (reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-4.*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)
3273                       - reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-2.*reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar
3274                       + 9.*reQ2nQ2nQ2nstarQ1nstarQ1nstar+20.*reQ3nQ1nQ2nstarQ1nstarQ1nstar 
3275                       + 2.*reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-8.*(dMult-8.)*reQ2nQ1nQ1nstarQ1nstarQ1nstar
3276                       - 18.*reQ4nQ2nstarQ1nstarQ1nstar-14.*reQ3nQ1nQ2nstarQ2nstar
3277                       + 8.*(dMult-7.)*reQ3nQ1nstarQ1nstarQ1nstar+28.*reQ4nQ3nstarQ1nstar
3278                       + 12.*reQ4nQ2nstarQ2nstar-8.*(5.*dMult-31.)*reQ3nQ2nstarQ1nstar      
3279                       + 12.*(dMult*dMult-15.*dMult+46.)*reQ2nQ1nstarQ1nstar
3280                       - 16.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3281                       - 6.*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3282                       - 3.*pow(pow(dReQ2n,2.)+pow(dImQ2n,2.),2.)
3283                       + 12.*(2.*dMult-13.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3284                       - 12.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+16.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3285                       - 12.*(dMult-8.)*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3286                       + 12.*(3.*dMult-14.)*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)
3287                       - 24.*(3.*dMult-7.)*(dMult-6.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3288                       + 24.*dMult*(dMult-5.)*(dMult-6.))
3289                       / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.));   
3290   // Average 7-particle correlations for single event: 
3291   fIntFlowCorrelationsAllEBE->SetBinContent(29,seven2n1n1n1n1n1n1n);       
3292   // Average 7-particle correlations for all events:                      
3293   fIntFlowCorrelationsAllPro->Fill(28.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3294                                                                  *(dMult-4.)*(dMult-5.)*(dMult-6.));
3295   // Average 7-particle correlations vs M for all events:                
3296   if(fCalculateAllCorrelationsVsM)
3297   {
3298    fIntFlowCorrelationsAllVsMPro[28]->Fill(dMult+0.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3299                                                                               *(dMult-4.)*(dMult-5.)*(dMult-6.));
3300   }    
3301  } // end of if(dMult>6)
3302  
3303  // 8-particle:
3304  Double_t eight1n1n1n1n1n1n1n1n = 0.; // <cos(n(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
3305  if(dMult>7)
3306  {  
3307   eight1n1n1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),4.)-12.*reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar
3308                         + 16.*reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar+6.*reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar
3309                         - 12.*reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-36.*reQ2nQ2nQ2nstarQ1nstarQ1nstar
3310                         - 96.*reQ3nQ1nQ2nstarQ1nstarQ1nstar
3311                         + 72.*reQ4nQ2nstarQ1nstarQ1nstar+48.*reQ3nQ1nQ2nstarQ2nstar
3312                         - 64.*(dMult-6.)*reQ3nQ1nstarQ1nstarQ1nstar
3313                         + 96.*(dMult-6.)*reQ2nQ1nQ1nstarQ1nstarQ1nstar
3314                         - 96.*reQ4nQ3nstarQ1nstar-36.*reQ4nQ2nstarQ2nstar
3315                         + 192.*(dMult-6.)*reQ3nQ2nstarQ1nstar
3316                         - 144.*(dMult-7.)*(dMult-4.)*reQ2nQ1nstarQ1nstar
3317                         + 64.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3318                         - 144.*(dMult-6.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3319                         + 72.*(dMult-7.)*(dMult-4.)*(pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)+pow(dReQ2n,2.)+pow(dImQ2n,2.))
3320                         - 96.*(dMult-7.)*(dMult-6.)*(dMult-2.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3321                         + 36.*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3322                         + 9.*pow(pow(dReQ2n,2.)+pow(dImQ2n,2.),2.)
3323                         - 64.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3324                         + 36.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3325                         - 16.*(dMult-6.)*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)
3326                         + 24.*dMult*(dMult-7.)*(dMult-6.)*(dMult-5.))
3327                         / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));   
3328   // Average 8-particle correlations for single event: 
3329   fIntFlowCorrelationsAllEBE->SetBinContent(31,eight1n1n1n1n1n1n1n1n);      
3330   // Average 8-particle correlations for all events:                       
3331   fIntFlowCorrelationsAllPro->Fill(30.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3332                                                                    *(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
3333   // Average 8-particle correlations vs M for all events:                
3334   if(fCalculateAllCorrelationsVsM)
3335   {
3336    fIntFlowCorrelationsAllVsMPro[30]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3337                                                                                 *(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
3338   }     
3339   // Store separetately <8>:
3340   fIntFlowCorrelationsEBE->SetBinContent(4,eight1n1n1n1n1n1n1n1n); // <8>
3341   // Testing other multiplicity weights:
3342   Double_t mWeight8p = 0.;
3343   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
3344   {
3345    mWeight8p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.);
3346   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
3347     {
3348      mWeight8p = 1.;    
3349     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
3350       {
3351        mWeight8p = dMult;           
3352       }        
3353   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(4,mWeight8p); // eW_<8>
3354   fIntFlowCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
3355   fIntFlowSquaredCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);  
3356   if(fCalculateCumulantsVsM)
3357   {
3358    fIntFlowCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
3359    fIntFlowSquaredCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);
3360   }    
3361  } // end of if(dMult>7) 
3362  
3363  // EXTRA correlations for v3{5} study:
3364  // 4-particle:
3365  Double_t four4n2n3n3n = 0.; // <cos(n(4*phi1+2*phi2-3*phi3-3*phi4))>
3366  if(dMult>3.)
3367  {
3368   four4n2n3n3n = (reQ4nQ2nQ3nstarQ3nstar-reQ6nQ4nstarQ2nstar-reQ6nQ3nstarQ3nstar
3369                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar
3370                + (pow(dReQ6n,2.)+pow(dImQ6n,2.))+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3371                + 2.*(2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3372                + (pow(dReQ1n,2.)+pow(dImQ1n,2.))-3.*dMult))
3373                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));               
3374   fIntFlowCorrelationsAllPro->Fill(32.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3375   // Average 4-particle correlations vs M for all events:                
3376   if(fCalculateAllCorrelationsVsM)
3377   {
3378    fIntFlowCorrelationsAllVsMPro[32]->Fill(dMult+0.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3379   }    
3380  } // end of if(dMult>3.)
3381  
3382  // 5-particle:
3383  Double_t five3n3n2n2n2n = 0.; // <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-2*phi5))>                                    
3384  if(dMult>4.)
3385  {
3386   five3n3n2n2n2n = (reQ3nQ3nQ2nstarQ2nstarQ2nstar-reQ6nQ2nstarQ2nstarQ2nstar-3.*reQ4nQ2nQ3nstarQ3nstar 
3387                  - 6.*reQ3nQ1nQ2nstarQ2nstar+2.*reQ6nQ3nstarQ3nstar+3.*reQ6nQ4nstarQ2nstar
3388                  + 6.*reQ4nQ3nstarQ1nstar+6.*reQ4nQ2nstarQ2nstar
3389                  + 12.*reQ3nQ2nstarQ1nstar+6.*reQ2nQ1nstarQ1nstar
3390                  - 2.*((pow(dReQ6n,2.)+pow(dImQ6n,2.)) 
3391                  + 3.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3392                  + 6.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)) 
3393                  + 9.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3394                  + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-12.*dMult))
3395                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3396   fIntFlowCorrelationsAllPro->Fill(33.5,five3n3n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3397   if(fCalculateAllCorrelationsVsM)
3398   {
3399    fIntFlowCorrelationsAllVsMPro[33]->Fill(dMult+0.5,five3n3n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3400   }     
3401  } // end of if(dMult>4.)
3402  
3403  // EXTRA correlations for Teaney-Yan study: 
3404  // 2-particle:
3405  Double_t two5n5n = 0.; // <cos(5n(phi1-phi2))>
3406  Double_t two6n6n = 0.; // <cos(6n(phi1-phi2))> 
3407  if(dMult>1)
3408  {
3409   two5n5n = (pow(dReQ5n,2.)+pow(dImQ5n,2.)-dMult)/(dMult*(dMult-1.)); 
3410   two6n6n = (pow(dReQ6n,2.)+pow(dImQ6n,2.)-dMult)/(dMult*(dMult-1.));        
3411   // Average 2-particle correlations for all events:      
3412   fIntFlowCorrelationsAllPro->Fill(34.5,two5n5n,dMult*(dMult-1.));
3413   fIntFlowCorrelationsAllPro->Fill(35.5,two6n6n,dMult*(dMult-1.)); 
3414   if(fCalculateAllCorrelationsVsM)
3415   {
3416    fIntFlowCorrelationsAllVsMPro[34]->Fill(dMult+0.5,two5n5n,dMult*(dMult-1.));
3417    fIntFlowCorrelationsAllVsMPro[35]->Fill(dMult+0.5,two6n6n,dMult*(dMult-1.));
3418   }       
3419  } // end of if(dMult>1)
3420  
3421  // 3-particle:
3422  Double_t three5n3n2n = 0.; // <cos(n(5*phi1-3*phi2-2*phi3)> 
3423  Double_t three5n4n1n = 0.; // <cos(n(5*phi1-4*phi2-1*phi3)> 
3424  Double_t three6n3n3n = 0.; // <cos(n(6*phi1-3*phi2-3*phi3)> 
3425  Double_t three6n4n2n = 0.; // <cos(n(6*phi1-4*phi2-2*phi3)> 
3426  Double_t three6n5n1n = 0.; // <cos(n(6*phi1-5*phi2-1*phi3)> 
3427  if(dMult>2)
3428  {
3429   three5n3n2n = (reQ5nQ3nstarQ2nstar-(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3430               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
3431               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
3432               / (dMult*(dMult-1.)*(dMult-2.));           
3433   three5n4n1n = (reQ5nQ4nstarQ1nstar-(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3434               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))
3435               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3436               / (dMult*(dMult-1.)*(dMult-2.));                          
3437   three6n3n3n = (reQ6nQ3nstarQ3nstar-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3438               - (pow(dReQ6n,2.)+pow(dImQ6n,2.))+2.*dMult)
3439               / (dMult*(dMult-1.)*(dMult-2.)); 
3440   three6n4n2n = (reQ6nQ4nstarQ2nstar-(pow(dReQ6n,2.)+pow(dImQ6n,2.))
3441               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))
3442               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
3443               / (dMult*(dMult-1.)*(dMult-2.));
3444   three6n5n1n = (reQ6nQ5nstarQ1nstar-(pow(dReQ6n,2.)+pow(dImQ6n,2.))
3445               - (pow(dReQ5n,2.)+pow(dImQ5n,2.))
3446               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3447               / (dMult*(dMult-1.)*(dMult-2.));            
3448   // Average 3-particle correlations for all events:      
3449   fIntFlowCorrelationsAllPro->Fill(36.5,three5n3n2n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(5*phi1-3*phi2-2*phi3)>> 
3450   fIntFlowCorrelationsAllPro->Fill(37.5,three5n4n1n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(5*phi1-4*phi2-1*phi3)>> 
3451   fIntFlowCorrelationsAllPro->Fill(38.5,three6n3n3n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(6*phi1-3*phi2-3*phi3)>> 
3452   fIntFlowCorrelationsAllPro->Fill(39.5,three6n4n2n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(6*phi1-4*phi2-2*phi3)>>
3453   fIntFlowCorrelationsAllPro->Fill(40.5,three6n5n1n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(6*phi1-5*phi2-1*phi3)>>
3454   if(fCalculateAllCorrelationsVsM)
3455   {
3456    fIntFlowCorrelationsAllVsMPro[36]->Fill(dMult+0.5,three5n3n2n,dMult*(dMult-1.)*(dMult-2.));
3457    fIntFlowCorrelationsAllVsMPro[37]->Fill(dMult+0.5,three5n4n1n,dMult*(dMult-1.)*(dMult-2.));
3458    fIntFlowCorrelationsAllVsMPro[38]->Fill(dMult+0.5,three6n3n3n,dMult*(dMult-1.)*(dMult-2.));
3459    fIntFlowCorrelationsAllVsMPro[39]->Fill(dMult+0.5,three6n4n2n,dMult*(dMult-1.)*(dMult-2.));
3460    fIntFlowCorrelationsAllVsMPro[40]->Fill(dMult+0.5,three6n5n1n,dMult*(dMult-1.)*(dMult-2.));
3461   }       
3462  } // end of if(dMult>2)
3463  
3464  // 4-particle:
3465  Double_t four6n3n2n1n = 0.; // <cos(n(6*phi1-3*phi2-2*phi3-1*phi4)>
3466  Double_t four3n2n3n2n = 0.; // <cos(n(3*phi1+2*phi2-3*phi3-2*phi4)>
3467  Double_t four4n1n3n2n = 0.; // <cos(n(4*phi1+1*phi2-3*phi3-2*phi4)> 
3468  Double_t four3n3n3n3n = 0.; // <cos(3n(phi1+phi2-phi3-phi4))> 
3469  //Double_t four4n2n3n3n = 0.; // <cos(n(4*phi1+2*phi2-3*phi3-3*phi4)> // I already have this one above
3470  Double_t four5n1n3n3n = 0.; // <cos(n(5*phi1+1*phi2-3*phi3-3*phi4)>
3471  Double_t four4n2n4n2n = 0.; // <cos(n(4*phi1+2*phi2-4*phi3-2*phi4)> 
3472  Double_t four5n1n4n2n = 0.; // <cos(n(5*phi1+1*phi2-4*phi3-2*phi4)> 
3473  Double_t four5n3n1n1n = 0.; // <cos(n(5*phi1-3*phi2-1*phi3-1*phi4)> 
3474  Double_t four5n2n2n1n = 0.; // <cos(n(5*phi1-2*phi2-2*phi3-1*phi4)>
3475  Double_t four5n1n5n1n = 0.; // <cos(n(5*phi1+1*phi2-5*phi3-1*phi4)>
3476  Double_t four6n4n1n1n = 0.; // <cos(n(6*phi1-4*phi2-1*phi3-1*phi4)>
3477  Double_t four6n2n2n2n = 0.; // <cos(n(6*phi1-2*phi2-2*phi3-2*phi4)>
3478  if(dMult>3)
3479  {
3480   four6n3n2n1n = (reQ6nQ3nstarQ2nstarQ1nstar-reQ6nQ4nstarQ2nstar-reQ6nQ3nstarQ3nstar-reQ6nQ5nstarQ1nstar
3481                - reQ5nQ3nstarQ2nstar-reQ4nQ3nstarQ1nstar-reQ3nQ2nstarQ1nstar
3482                + 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))+pow(dReQ5n,2.)+pow(dImQ5n,2.)
3483                + pow(dReQ4n,2.)+pow(dImQ4n,2.)+3.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3484                + 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3485                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3486   four3n2n3n2n = (dQ3nQ2nQ3nstarQ2nstar-2.*reQ5nQ3nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar
3487                + pow(dReQ5n,2.)+pow(dImQ5n,2.)+pow(dReQ1n,2.)+pow(dImQ1n,2.)               
3488                -(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.)+pow(dReQ2n,2.)+pow(dImQ2n,2.))
3489                + dMult*(dMult-6.))
3490                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));     
3491   four4n1n3n2n = (reQ4nQ1nQ3nstarQ2nstar-reQ5nQ3nstarQ2nstar-reQ5nQ4nstarQ1nstar-reQ4nQ3nstarQ1nstar
3492                - reQ4nQ2nstarQ2nstar-reQ3nQ2nstarQ1nstar-reQ2nQ1nstarQ1nstar
3493                + pow(dReQ5n,2.)+pow(dImQ5n,2.)+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3494                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3495                + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult) 
3496                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));                             
3497   four3n3n3n3n = (2.*dMult*(dMult-3.)+pow((pow(dReQ3n,2.)+pow(dImQ3n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ3n,2.)
3498                + pow(dImQ3n,2.))-2.*reQ6nQ3nstarQ3nstar+(pow(dReQ6n,2.)+pow(dImQ6n,2.)))
3499                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));   
3500   //four4n2n3n3n = ; // I already have this one above
3501   four5n1n3n3n = (reQ5nQ1nQ3nstarQ3nstar-reQ6nQ5nstarQ1nstar-reQ6nQ3nstarQ3nstar-2.*reQ5nQ3nstarQ2nstar
3502                - 2.*reQ3nQ2nstarQ1nstar+pow(dReQ6n,2.)+pow(dImQ6n,2.)+2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3503                + 4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3504                + 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)                                  
3505                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));   
3506   four4n2n4n2n = (dQ4nQ2nQ4nstarQ2nstar-2.*reQ6nQ4nstarQ2nstar-2.*reQ4nQ2nstarQ2nstar)
3507                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3508                - ((dMult-5.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3509                + (dMult-4.)*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-(pow(dReQ6n,2.)+pow(dImQ6n,2.)))
3510                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3511                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.)); 
3512   four5n1n4n2n = (reQ5nQ1nQ4nstarQ2nstar-reQ6nQ5nstarQ1nstar-reQ6nQ4nstarQ2nstar-reQ5nQ4nstarQ1nstar
3513                - reQ5nQ3nstarQ2nstar-reQ4nQ3nstarQ1nstar-reQ2nQ1nstarQ1nstar+pow(dReQ6n,2.)+pow(dImQ6n,2.)
3514                + 2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3515                + pow(dReQ3n,2.)+pow(dImQ3n,2.)+2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3516                + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3517                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));     
3518   four5n3n1n1n = (reQ5nQ3nstarQ1nstarQ1nstar-2.*reQ5nQ4nstarQ1nstar-reQ5nQ3nstarQ2nstar-2.*reQ4nQ3nstarQ1nstar
3519                - reQ2nQ1nstarQ1nstar+2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3520                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+pow(dReQ2n,2.)+pow(dImQ2n,2.)
3521                + 4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult) 
3522                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));                    
3523   four5n2n2n1n = (reQ5nQ2nstarQ2nstarQ1nstar-reQ5nQ4nstarQ1nstar-2.*reQ5nQ3nstarQ2nstar-reQ4nQ2nstarQ2nstar
3524                - 2.*reQ3nQ2nstarQ1nstar+2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))+pow(dReQ4n,2.)+pow(dImQ4n,2.)
3525                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3526                + 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3527                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));   
3528   four5n1n5n1n = (dQ5nQ1nQ5nstarQ1nstar-2.*reQ6nQ5nstarQ1nstar-2.*reQ5nQ4nstarQ1nstar
3529                + pow(dReQ6n,2.)+pow(dImQ6n,2.)-(dMult-4.)*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3530                + pow(dReQ4n,2.)+pow(dImQ4n,2.)-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+dMult*(dMult-6.))  
3531                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));                  
3532   
3533   four6n4n1n1n = (reQ6nQ4nstarQ1nstarQ1nstar
3534                - dMult*(dMult-1.)*(dMult-2.)*(three2n1n1n+2.*three5n4n1n+2.*three6n5n1n+three6n4n2n)
3535                - dMult*(dMult-1.)*(2.*two1n1n+1.*two4n4n+1.*two6n6n+1.*two2n2n+2.*two5n5n)
3536                - 1.*dMult)
3537                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3538  
3539   four6n2n2n2n = (reQ6nQ2nstarQ2nstarQ2nstar-3.*reQ6nQ4nstarQ2nstar-3.*reQ4nQ2nstarQ2nstar
3540                + 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))+3.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3541                + 6.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-6.*dMult)
3542                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3543   // Average 4-particle correlations for all events:      
3544   fIntFlowCorrelationsAllPro->Fill(41.5,four6n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3545   fIntFlowCorrelationsAllPro->Fill(42.5,four3n2n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3546   fIntFlowCorrelationsAllPro->Fill(43.5,four4n1n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3547   fIntFlowCorrelationsAllPro->Fill(44.5,four3n3n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3548   //fIntFlowCorrelationsAllPro->Fill(45.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); // I already have this one above
3549   fIntFlowCorrelationsAllPro->Fill(46.5,four5n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3550   fIntFlowCorrelationsAllPro->Fill(47.5,four4n2n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3551   fIntFlowCorrelationsAllPro->Fill(48.5,four5n1n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3552   fIntFlowCorrelationsAllPro->Fill(49.5,four5n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3553   fIntFlowCorrelationsAllPro->Fill(50.5,four5n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3554   fIntFlowCorrelationsAllPro->Fill(51.5,four5n1n5n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3555   fIntFlowCorrelationsAllPro->Fill(58.5,four6n4n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3556   fIntFlowCorrelationsAllPro->Fill(59.5,four6n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3557   if(fCalculateAllCorrelationsVsM)
3558   {
3559    fIntFlowCorrelationsAllVsMPro[41]->Fill(dMult+0.5,four6n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3560    fIntFlowCorrelationsAllVsMPro[42]->Fill(dMult+0.5,four3n2n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3561    fIntFlowCorrelationsAllVsMPro[43]->Fill(dMult+0.5,four4n1n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3562    fIntFlowCorrelationsAllVsMPro[44]->Fill(dMult+0.5,four3n3n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3563    //fIntFlowCorrelationsAllVsMPro[45]->Fill(dMult+0.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3564    fIntFlowCorrelationsAllVsMPro[46]->Fill(dMult+0.5,four5n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3565    fIntFlowCorrelationsAllVsMPro[47]->Fill(dMult+0.5,four4n2n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3566    fIntFlowCorrelationsAllVsMPro[48]->Fill(dMult+0.5,four5n1n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3567    fIntFlowCorrelationsAllVsMPro[49]->Fill(dMult+0.5,four5n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3568    fIntFlowCorrelationsAllVsMPro[50]->Fill(dMult+0.5,four5n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3569    fIntFlowCorrelationsAllVsMPro[51]->Fill(dMult+0.5,four5n1n5n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3570    fIntFlowCorrelationsAllVsMPro[58]->Fill(dMult+0.5,four6n4n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3571    fIntFlowCorrelationsAllVsMPro[59]->Fill(dMult+0.5,four6n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3572   }       
3573  } // end of if(dMult>3)
3574
3575  // 5-particle:
3576  Double_t five3n3n3n2n1n = 0.; // <cos(n(3*phi1+3*phi2-3*phi3-2*phi4-1*phi5)>
3577  Double_t five4n2n3n2n1n = 0.; // <cos(n(4*phi1+2*phi2-3*phi3-2*phi4-1*phi5)>
3578  Double_t five3n2n3n1n1n = 0.; // <cos(n(3*phi1+2*phi2-3*phi3-1*phi4-1*phi5)>
3579  Double_t five3n2n2n2n1n = 0.; // <cos(n(3*phi1+2*phi2-2*phi3-2*phi4-1*phi5)>
3580  Double_t five5n1n3n2n1n = 0.; // <cos(n(5*phi1+1*phi2-3*phi3-2*phi4-1*phi5)>
3581  Double_t five6n2n2n1n1n = 0.; // <cos(n(6*phi1-2*phi2-2*phi3-1*phi4-1*phi5)>
3582  Double_t five4n1n1n3n3n = 0.; // <cos(n(4*phi1+1*phi2+1*phi3-3*phi4-3*phi5)>
3583  if(dMult>4)
3584  { 
3585   five3n3n3n2n1n = (reQ3nQ3nQ3nstarQ2nstarQ1nstar-reQ6nQ3nstarQ2nstarQ1nstar-reQ5nQ1nQ3nstarQ3nstar-reQ4nQ2nQ3nstarQ3nstar
3586                  + reQ6nQ5nstarQ1nstar+reQ6nQ4nstarQ2nstar+3.*reQ6nQ3nstarQ3nstar+4.*reQ5nQ3nstarQ2nstar+4.*reQ4nQ3nstarQ1nstar
3587                  - 2.*(dMult-6.)*reQ3nQ2nstarQ1nstar-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.)) 
3588                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3589                  - 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))-2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3590                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*(3.*dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3591                  - pow((pow(dReQ3n,2.)+pow(dImQ3n,2.)),2.)+2.*(dMult-5.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3592                  + 2.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3593                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));                                  
3594   five4n2n3n2n1n = (reQ4nQ2nQ3nstarQ2nstarQ1nstar-reQ6nQ3nstarQ2nstarQ1nstar-reQ5nQ1nQ4nstarQ2nstar
3595                  - reQ4nQ2nQ3nstarQ3nstar-reQ4nQ1nQ3nstarQ2nstar-reQ4nQ2nstarQ1nstarQ1nstar
3596                  - reQ3nQ1nQ2nstarQ2nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3597                  + 3.*reQ6nQ4nstarQ2nstar+reQ6nQ5nstarQ1nstar+reQ6nQ3nstarQ3nstar+reQ5nQ4nstarQ1nstar
3598                  + 3.*reQ5nQ3nstarQ2nstar-(dMult-7.)*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+7.*reQ3nQ2nstarQ1nstar
3599                  + 4.*reQ2nQ1nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3600                  - (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3601                  - 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))-2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3602                  + (dMult-8.)*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+(dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3603                  + 2.*(dMult-7.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+(dMult-12.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3604                  - 2.*dMult*(dMult-12.))
3605                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));   
3606   five3n2n3n1n1n = (reQ3nQ2nQ3nstarQ1nstarQ1nstar-reQ5nQ3nstarQ1nstarQ1nstar-2.*reQ4nQ1nQ3nstarQ2nstar-reQ3nQ1nstarQ1nstarQ1nstar
3607                  - 2.*reQ3nQ1nQ2nstarQ2nstar+2.*reQ5nQ4nstarQ1nstar+3.*reQ5nQ3nstarQ2nstar+6.*reQ4nQ3nstarQ1nstar
3608                  + 2.*reQ4nQ2nstarQ2nstar+9.*reQ3nQ2nstarQ1nstar-(dMult-8.)*reQ2nQ1nstarQ1nstar
3609                  - (pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.)) 
3610                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.)) 
3611                  - 2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))-4.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3612                  + 2.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+(dMult-12.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3613                  + 2.*(dMult-9.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-2.*dMult*(dMult-12.))
3614                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3615   five3n2n2n2n1n = (reQ3nQ2nQ2nstarQ2nstarQ1nstar-reQ5nQ2nstarQ2nstarQ1nstar-reQ4nQ1nQ3nstarQ2nstar-reQ3nQ1nQ2nstarQ2nstar
3616                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+reQ5nQ4nstarQ1nstar
3617                  + 4.*reQ5nQ3nstarQ2nstar+reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar-2.*(dMult-6.)*reQ3nQ2nstarQ1nstar
3618                  + 4.*reQ2nQ1nstarQ1nstar-2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3619                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3620                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3621                  - pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)+2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3622                  + 2.*(dMult-6.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3623                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
3624   five5n1n3n2n1n = (reQ5nQ1nQ3nstarQ2nstarQ1nstar-reQ6nQ3nstarQ2nstarQ1nstar-reQ5nQ1nQ4nstarQ2nstar-reQ5nQ1nQ3nstarQ3nstar
3625                  - reQ4nQ1nQ3nstarQ2nstar-reQ5nQ3nstarQ1nstarQ1nstar-reQ5nQ2nstarQ2nstarQ1nstar 
3626                  + 3.*reQ6nQ5nstarQ1nstar+reQ6nQ4nstarQ2nstar+reQ6nQ3nstarQ3nstar+4.*reQ5nQ4nstarQ1nstar
3627                  - (dMult-7.)*reQ5nQ3nstarQ2nstar+4.*reQ4nQ3nstarQ1nstar+reQ4nQ2nstarQ2nstar+6.*reQ3nQ2nstarQ1nstar
3628                  + 3.*reQ2nQ1nstarQ1nstar-(pow(dReQ5n,2.)+pow(dImQ5n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3629                  - (pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3630                  - (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3631                  - 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))+(dMult-8.)*(pow(dReQ5n,2.)+pow(dImQ5n,2.))  
3632                  - 4.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+(dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3633                  + (dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*(dMult-7.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3634                  - 2.*dMult*(dMult-12.))
3635                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));      
3636   
3637   // five6n2n2n1n1n = ;
3638   // five4n1n1n3n3n = ; 
3639   
3640   // Average 5-particle correlations for all events:      
3641   fIntFlowCorrelationsAllPro->Fill(52.5,five3n3n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3642   fIntFlowCorrelationsAllPro->Fill(53.5,five4n2n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3643   fIntFlowCorrelationsAllPro->Fill(54.5,five3n2n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3644   fIntFlowCorrelationsAllPro->Fill(55.5,five3n2n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3645   fIntFlowCorrelationsAllPro->Fill(56.5,five5n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3646   fIntFlowCorrelationsAllPro->Fill(60.5,five6n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3647   fIntFlowCorrelationsAllPro->Fill(61.5,five4n1n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3648   if(fCalculateAllCorrelationsVsM)
3649   {
3650    fIntFlowCorrelationsAllVsMPro[52]->Fill(dMult+0.5,five3n3n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3651    fIntFlowCorrelationsAllVsMPro[53]->Fill(dMult+0.5,five4n2n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3652    fIntFlowCorrelationsAllVsMPro[54]->Fill(dMult+0.5,five3n2n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3653    fIntFlowCorrelationsAllVsMPro[55]->Fill(dMult+0.5,five3n2n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3654    fIntFlowCorrelationsAllVsMPro[56]->Fill(dMult+0.5,five5n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3655    fIntFlowCorrelationsAllVsMPro[60]->Fill(dMult+0.5,five6n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3656    fIntFlowCorrelationsAllVsMPro[61]->Fill(dMult+0.5,five4n1n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3657   }         
3658  } // end of if(dMult>4)
3659
3660  // 6-particle:
3661  Double_t six3n2n1n3n2n1n = 0.; // <cos(n(3*phi1+2*phi2+1*phi3-3*phi4-2*phi5-1*phi6)>
3662  Double_t six3n3n2n2n1n1n = 0.; // <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-1*phi5-1*phi6)>   
3663  if(dMult>5.)
3664  { 
3665   six3n2n1n3n2n1n = (dQ3nQ2nQ1nQ3nstarQ2nstarQ1nstar-2.*reQ3nQ3nQ3nstarQ2nstarQ1nstar
3666                   - 2.*reQ3nQ2nQ2nstarQ2nstarQ1nstar-2.*reQ3nQ1nQ2nstarQ1nstarQ1nstar
3667                   - 2.*reQ3nQ2nQ3nstarQ1nstarQ1nstar-2.*reQ4nQ2nQ3nstarQ2nstarQ1nstar
3668                   - 2.*reQ5nQ1nQ3nstarQ2nstarQ1nstar+4.*reQ6nQ3nstarQ2nstarQ1nstar
3669                   + 2.*reQ5nQ1nQ4nstarQ2nstar+2.*reQ5nQ1nQ3nstarQ3nstar
3670                   + 2.*reQ4nQ2nQ3nstarQ3nstar+6.*reQ4nQ1nQ3nstarQ2nstar
3671                   + 2.*reQ5nQ3nstarQ1nstarQ1nstar+2.*reQ5nQ2nstarQ2nstarQ1nstar
3672                   + 6.*reQ3nQ1nQ2nstarQ2nstar+2.*reQ4nQ2nstarQ1nstarQ1nstar
3673                   - 4.*reQ6nQ5nstarQ1nstar-4.*reQ6nQ4nstarQ2nstar-6.*reQ5nQ4nstarQ1nstar
3674                   - 4.*reQ6nQ3nstarQ3nstar+2.*(dMult-11.)*reQ5nQ3nstarQ2nstar
3675                   + 2.*(dMult-13.)*reQ4nQ3nstarQ1nstar-8.*reQ4nQ2nstarQ2nstar
3676                   + 2.*(5.*dMult-32.)*reQ3nQ2nstarQ1nstar+2.*reQ3nQ1nstarQ1nstarQ1nstar
3677                   + 2.*(dMult-13.)*reQ2nQ1nstarQ1nstar
3678                   - (dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3679                   + (pow(dReQ5n,2.)+pow(dImQ5n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3680                   + (pow(dReQ4n,2.)+pow(dImQ4n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3681                   - (dMult-11.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3682                   - (dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3683                   + 4.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))-(dMult-12.)*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3684                   - (dMult-16.)*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+pow((pow(dReQ3n,2.)+pow(dImQ3n,2.)),2.)
3685                   + (dMult*dMult-19.*dMult+68.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3686                   + (dMult*dMult-19.*dMult+72.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3687                   + pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3688                   + (dMult*dMult-20.*dMult+80.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3689                   - dMult*(dMult-12.)*(dMult-10.))
3690                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));   
3691
3692   // six3n3n2n2n1n1n = ;
3693
3694   // Average 6-particle correlations for all events:      
3695   fIntFlowCorrelationsAllPro->Fill(57.5,six3n2n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3696   fIntFlowCorrelationsAllPro->Fill(62.5,six3n3n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3697   if(fCalculateAllCorrelationsVsM)
3698   {
3699    fIntFlowCorrelationsAllVsMPro[57]->Fill(dMult+0.5,six3n2n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3700    fIntFlowCorrelationsAllVsMPro[62]->Fill(dMult+0.5,six3n3n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3701   }          
3702  } // end of if(dMult>5.)
3703  
3704 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
3705
3706 //================================================================================================================================
3707
3708 void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3709 {
3710  // Store phi distribution for one event to illustrate flow.
3711  
3712  if(fPhiDistributionForOneEvent->GetEntries()>0){return;} // store only phi distribution for one event
3713  
3714  Double_t vMin = fPhiDistributionForOneEventSettings[0]; 
3715  Double_t vMax = fPhiDistributionForOneEventSettings[1]; 
3716  Double_t refMultMin = fPhiDistributionForOneEventSettings[2]; 
3717  Double_t refMultMax = fPhiDistributionForOneEventSettings[3]; 
3718  
3719  Double_t vEBE = 0.;
3720  Double_t cumulant4thEBE = fIntFlowCorrelationsEBE->GetBinContent(2)-2.*pow(fIntFlowCorrelationsEBE->GetBinContent(1),2.);
3721  if(cumulant4thEBE<0.)
3722  {
3723   vEBE = pow(-1.*cumulant4thEBE,0.25);
3724   if((vEBE>vMin && vEBE<vMax) && (fReferenceMultiplicityEBE>refMultMin && fReferenceMultiplicityEBE<refMultMax))
3725   {
3726    fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f",fHarmonic,vEBE));
3727    for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3728    {
3729     if(anEvent->GetTrack(p)->InRPSelection())
3730     {
3731      fPhiDistributionForOneEvent->Fill(anEvent->GetTrack(p)->Phi());
3732     }
3733    } // end of for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3734   } else
3735     {
3736      fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f, out of specified boundaries",fHarmonic,vEBE));  
3737     } 
3738    
3739  } // end of if(cumulant4thEBE<0.)
3740  
3741 } // end of void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3742
3743 //================================================================================================================================
3744
3745 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3746 {
3747  // Calculate averages of products of correlations for integrated flow.
3748  
3749  // multiplicity:
3750  Double_t dMult = (*fSpk)(0,0);
3751  
3752  Int_t counter = 0;
3753  
3754  for(Int_t ci1=1;ci1<4;ci1++)
3755  {
3756   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
3757   {
3758    fIntFlowProductOfCorrelationsPro->Fill(0.5+counter,
3759                                           fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3760                                           fIntFlowCorrelationsEBE->GetBinContent(ci2),
3761                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3762                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3763    // products versus multiplicity:  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]
3764    if(fCalculateCumulantsVsM)
3765    {
3766     fIntFlowProductOfCorrelationsVsMPro[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights ?
3767                                                        fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3768                                                        fIntFlowCorrelationsEBE->GetBinContent(ci2),
3769                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3770                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3771    } // end of if(fCalculateCumulantsVsM)
3772    counter++;                                                                                                                        
3773   }
3774  }
3775  
3776 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3777
3778
3779 //================================================================================================================================
3780
3781
3782 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3783 {
3784  // Calculate averages of products of correction terms for NUA.
3785  
3786  // a) Binning of fIntFlowProductOfCorrectionTermsForNUAPro is organized as follows:
3787  //     1st bin: <<2><cos(phi)>> 
3788  //     2nd bin: <<2><sin(phi)>>
3789  //     3rd bin: <<cos(phi)><sin(phi)>>
3790  //     4th bin: <<2><cos(phi1+phi2)>> 
3791  //     5th bin: <<2><sin(phi1+phi2)>>
3792  //     6th bin: <<2><cos(phi1-phi2-phi3)>> 
3793  //     7th bin: <<2><sin(phi1-phi2-phi3)>>
3794  //     8th bin: <<4><cos(phi1)>>
3795  //     9th bin: <<4><sin(phi1)>>
3796  //    10th bin: <<4><cos(phi1+phi2)>>
3797  //    11th bin: <<4><sin(phi1+phi2)>>
3798  //    12th bin: <<4><cos(phi1-phi2-phi3)>>
3799  //    13th bin: <<4><sin(phi1-phi2-phi3)>>
3800  //    14th bin: <<cos(phi1)><cos(phi1+phi2)>>
3801  //    15th bin: <<cos(phi1)><sin(phi1+phi2)>> 
3802  //    16th bin: <<cos(phi1)><cos(phi1-phi2-phi3)>>
3803  //    17th bin: <<cos(phi1)><sin(phi1-phi2-phi3)>> 
3804  //    18th bin: <<sin(phi1)><cos(phi1+phi2)>>
3805  //    19th bin: <<sin(phi1)><sin(phi1+phi2)>> 
3806  //    20th bin: <<sin(phi1)><cos(phi1-phi2-phi3)>>
3807  //    21st bin: <<sin(phi1)><sin(phi1-phi2-phi3)>>
3808  //    22nd bin: <<cos(phi1+phi2)><sin(phi1+phi2)>>
3809  //    23rd bin: <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>
3810  //    24th bin: <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>
3811  //    25th bin: <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>
3812  //    26th bin: <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>
3813  //    27th bin: <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>
3814  
3815  // <<2><cos(phi)>>:
3816  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(0.5,
3817                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3818                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3819                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3820  // <<2><sin(phi)>>:
3821  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(1.5,
3822                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3823                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3824                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3825  // <<cos(phi)><sin(phi)>>:
3826  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(2.5,
3827                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3828                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3829                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3830  // <<2><cos(phi1+phi2)>>:
3831  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(3.5,
3832                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3833                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3834                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3835  // <<2><sin(phi1+phi2)>>:
3836  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(4.5,
3837                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3838                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3839                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3840  // <<2><cos(phi1-phi2-phi3)>>:
3841  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(5.5,
3842                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3843                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3844                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3845  // <<2><sin(phi1-phi2-phi3)>>:
3846  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(6.5,
3847                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3848                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3849                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3850  // <<4><cos(phi1)>>:
3851  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(7.5,
3852                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3853                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3854                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3855  // <<4><sin(phi1)>>:
3856  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(8.5,
3857                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3858                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3859                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3860  // <<4><cos(phi1+phi2)>>:
3861  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(9.5,
3862                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3863                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3864                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3865  // <<4><sin(phi1+phi2)>>:
3866  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(10.5,
3867                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3868                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3869                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
3870  // <<4><cos(phi1-phi2-phi3)>>:
3871  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(11.5,
3872                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3873                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3874                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3875  // <<4><sin(phi1-phi2-phi3)>>:
3876  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(12.5,
3877                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3878                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3879                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));   
3880  // <<cos(phi1)><cos(phi1+phi2)>>:
3881  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(13.5,
3882                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3883                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3884                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3885  // <<cos(phi1)><sin(phi1+phi2)>>: 
3886  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(14.5,
3887                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3888                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3889                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3890  // <<cos(phi1)><cos(phi1-phi2-phi3)>>:
3891  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(15.5,
3892                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3893                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3894                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3895  // <<cos(phi1)><sin(phi1-phi2-phi3)>>: 
3896  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(16.5,
3897                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3898                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3899                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
3900  // <<sin(phi1)><cos(phi1+phi2)>>:
3901  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(17.5,
3902                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3903                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3904                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));  
3905  // <<sin(phi1)><sin(phi1+phi2)>>: 
3906  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(18.5,
3907                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3908                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3909                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));  
3910  // <<sin(phi1)><cos(phi1-phi2-phi3)>>:
3911  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(19.5,
3912                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3913                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3914                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3915  // <<sin(phi1)><sin(phi1-phi2-phi3)>>:
3916  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(20.5,
3917                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3918                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3919                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3920  // <<cos(phi1+phi2)><sin(phi1+phi2)>>:
3921  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(21.5,
3922                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3923                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3924                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3925  // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3926  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(22.5,
3927                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3928                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3929                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));   
3930  // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3931  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(23.5,
3932                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3933                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3934                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3935  // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3936  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(24.5,
3937                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3938                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3939                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));    
3940  // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3941  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(25.5,
3942                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3943                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3944                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3945  // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>:
3946  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(26.5,
3947                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3948                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)
3949                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3950
3951 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3952
3953 //================================================================================================================================
3954
3955 void AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
3956 {
3957  // a) Calculate unbiased estimators Cov(<2>,<4>), Cov(<2>,<6>), Cov(<2>,<8>), Cov(<4>,<6>), Cov(<4>,<8>) and Cov(<6>,<8>)
3958  //    for covariances V_(<2>,<4>), V_(<2>,<6>), V_(<2>,<8>), V_(<4>,<6>), V_(<4>,<8>) and V_(<6>,<8>).
3959  // b) Store in histogram fIntFlowCovariances for instance the following: 
3960  //
3961  //             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)]
3962  // 
3963  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<4>} is event weight for <4>.
3964  // c) Binning of fIntFlowCovariances is organized as follows:
3965  // 
3966  //     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)] 
3967  //     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)]
3968  //     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)]
3969  //     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)]
3970  //     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)]
3971  //     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)]
3972  //
3973     
3974  // Average 2-, 4-, 6- and 8-particle correlations for all events:
3975  Double_t correlation[4] = {0.};
3976  for(Int_t ci=0;ci<4;ci++)
3977  {
3978   correlation[ci] = fIntFlowCorrelationsPro->GetBinContent(ci+1);
3979  } 
3980  // Average products of 2-, 4-, 6- and 8-particle correlations: 
3981  Double_t productOfCorrelations[4][4] = {{0.}};
3982  Int_t productOfCorrelationsLabel = 1;
3983  // Denominators in the expressions for the unbiased estimator for covariance:
3984  Double_t denominator[4][4] = {{0.}};
3985  Int_t sumOfProductOfEventWeightsLabel1 = 1;
3986  // Weight dependent prefactor which multiply unbiased estimators for covariances:
3987  Double_t wPrefactor[4][4] = {{0.}}; 
3988  Int_t sumOfProductOfEventWeightsLabel2 = 1;
3989  for(Int_t c1=0;c1<4;c1++)
3990  {
3991   for(Int_t c2=c1+1;c2<4;c2++)
3992   {
3993    productOfCorrelations[c1][c2] = fIntFlowProductOfCorrelationsPro->GetBinContent(productOfCorrelationsLabel);
3994    if(TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1)) > 1.e-44)
3995    {
3996     denominator[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel1))
3997                         / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1) 
3998                         * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                              
3999     wPrefactor[c1][c2] = fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel2)
4000                        / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)
4001                        * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                                                       
4002    }
4003    productOfCorrelationsLabel++; // to be improved - do I need here all 3 counters?
4004    sumOfProductOfEventWeightsLabel1++;
4005    sumOfProductOfEventWeightsLabel2++;  
4006   } // end of for(Int_t c2=c1+1;c2<4;c2++)
4007  } // end of for(Int_t c1=0;c1<4;c1++)
4008  
4009  Int_t covarianceLabel = 1;
4010  for(Int_t c1=0;c1<4;c1++)
4011  {
4012   for(Int_t c2=c1+1;c2<4;c2++)
4013   {
4014    if(TMath::Abs(denominator[c1][c2]) > 1.e-44)
4015    {
4016     // Covariances:
4017     Double_t cov = (productOfCorrelations[c1][c2]-correlation[c1]*correlation[c2])/denominator[c1][c2]; 
4018     // Covariances multiplied with weight dependent prefactor:
4019     Double_t wCov = cov * wPrefactor[c1][c2];
4020     fIntFlowCovariances->SetBinContent(covarianceLabel,wCov);
4021    }
4022    covarianceLabel++;
4023   } // end of for(Int_t c2=c1+1;c2<4;c2++) 
4024  } // end of for(Int_t c1=0;c1<4;c1++)
4025  
4026  // Versus multiplicity: 
4027  if(!fCalculateCumulantsVsM){return;}
4028  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
4029  for(Int_t b=1;b<=nBins;b++)
4030  {
4031   // Average 2-, 4-, 6- and 8-particle correlations for all events:
4032   Double_t correlationVsM[4] = {0.};
4033   for(Int_t ci=0;ci<4;ci++)
4034   {
4035    correlationVsM[ci] = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
4036   } // end of for(Int_t ci=0;ci<4;ci++)
4037   // Average products of 2-, 4-, 6- and 8-particle correlations: 
4038   Double_t productOfCorrelationsVsM[4][4] = {{0.}};
4039   Int_t productOfCorrelationsLabelVsM = 1;
4040   // Denominators in the expressions for the unbiased estimator for covariance:
4041   Double_t denominatorVsM[4][4] = {{0.}};
4042   Int_t sumOfProductOfEventWeightsLabel1VsM = 1;
4043   // Weight dependent prefactor which multiply unbiased estimators for covariances:
4044   Double_t wPrefactorVsM[4][4] = {{0.}}; 
4045   Int_t sumOfProductOfEventWeightsLabel2VsM = 1;
4046   for(Int_t c1=0;c1<4;c1++)
4047   {
4048    for(Int_t c2=c1+1;c2<4;c2++)
4049    {
4050     productOfCorrelationsVsM[c1][c2] = fIntFlowProductOfCorrelationsVsMPro[productOfCorrelationsLabelVsM-1]->GetBinContent(b);
4051     if(TMath::Abs(fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b)) > 1.e-44)
4052     {
4053      denominatorVsM[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel1VsM-1]->GetBinContent(b))
4054                             / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b) 
4055                             * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                              
4056      wPrefactorVsM[c1][c2] = fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel2VsM-1]->GetBinContent(b)
4057                            / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)
4058                            * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                                                       
4059     }
4060     productOfCorrelationsLabelVsM++;
4061     sumOfProductOfEventWeightsLabel1VsM++;
4062     sumOfProductOfEventWeightsLabel2VsM++;  
4063    } // end of for(Int_t c1=0;c1<4;c1++) 
4064   } // end of for(Int_t c2=c1+1;c2<4;c2++)
4065  
4066   Int_t covarianceLabelVsM = 1;
4067   for(Int_t c1=0;c1<4;c1++)
4068   {
4069    for(Int_t c2=c1+1;c2<4;c2++)
4070    {
4071     if(TMath::Abs(denominatorVsM[c1][c2]) > 1.e-44)
4072     {
4073      // Covariances:
4074      Double_t covVsM = (productOfCorrelationsVsM[c1][c2]-correlationVsM[c1]*correlationVsM[c2])/denominatorVsM[c1][c2]; 
4075      // Covariances multiplied with weight dependent prefactor:
4076      Double_t wCovVsM = covVsM * wPrefactorVsM[c1][c2];
4077      fIntFlowCovariancesVsM[covarianceLabelVsM-1]->SetBinContent(b,wCovVsM);
4078     }
4079     covarianceLabelVsM++;
4080    } // end of for(Int_t c2=c1+1;c2<4;c2++)
4081   } // end of for(Int_t c1=0;c1<4;c1++)
4082  } // end of for(Int_t b=1;b<=nBins;b++)
4083   
4084 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
4085
4086 //================================================================================================================================
4087
4088 void AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
4089 {
4090  // a) Calculate unbiased estimators Cov(*,*) for true covariances V_(*,*) for NUA terms.
4091  // b) Store in histogram fIntFlowCovariancesNUA for instance the following: 
4092  //
4093  //             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)]
4094  // 
4095  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<cos(phi)>} is event weight for <cos(phi)>.
4096  // c) Binning of fIntFlowCovariancesNUA is organized as follows:
4097  // 
4098  //     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)] 
4099  //     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)]
4100  //     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)]
4101  // ...
4102       
4103  // Cov(<2>,<cos(phi)>):
4104  Double_t product1 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(1); // <<2><cos(phi)>> 
4105  Double_t term1st1 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4106  Double_t term2nd1 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
4107  Double_t sumOfW1st1 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4108  Double_t sumOfW2nd1 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
4109  Double_t sumOfWW1 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(1); // W_{<2>} * W_{<cos(phi)>}
4110  // numerator in the expression for the the unbiased estimator for covariance:
4111  Double_t numerator1 = product1 - term1st1*term2nd1; 
4112  // denominator in the expression for the the unbiased estimator for covariance:
4113  Double_t denominator1 = 0.;
4114  if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
4115  {
4116   denominator1 = 1.-sumOfWW1/(sumOfW1st1*sumOfW2nd1);
4117   if(TMath::Abs(denominator1)>0.)
4118   {
4119    // covariance:
4120    Double_t covariance1 = numerator1/denominator1;
4121    // weight dependent prefactor for covariance:
4122    Double_t wPrefactor1 = sumOfWW1/(sumOfW1st1*sumOfW2nd1);
4123    // finally, store "weighted" covariance:
4124    fIntFlowCovariancesNUA->SetBinContent(1,wPrefactor1*covariance1);
4125   } // end of if(TMath::Abs(denominator)>0.)
4126  } // end of if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
4127  
4128  // Cov(<2>,<sin(phi)>):
4129  Double_t product2 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(2); // <<2><sin(phi)>> 
4130  Double_t term1st2 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4131  Double_t term2nd2 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
4132  Double_t sumOfW1st2 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4133  Double_t sumOfW2nd2 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
4134  Double_t sumOfWW2 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(2); // W_{<2>} * W_{<sin(phi)>}
4135  // numerator in the expression for the the unbiased estimator for covariance:
4136  Double_t numerator2 = product2 - term1st2*term2nd2;
4137  // denominator in the expression for the the unbiased estimator for covariance:
4138  Double_t denominator2 = 0.;
4139  if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
4140  {  
4141   denominator2 = 1.-sumOfWW2/(sumOfW1st2*sumOfW2nd2);
4142   if(TMath::Abs(denominator2)>0.)
4143   {
4144    // covariance:
4145    Double_t covariance2 = numerator2/denominator2;
4146    // weight dependent prefactor for covariance:
4147    Double_t wPrefactor2 = sumOfWW2/(sumOfW1st2*sumOfW2nd2);
4148    // finally, store "weighted" covariance:
4149    fIntFlowCovariancesNUA->SetBinContent(2,wPrefactor2*covariance2);
4150   } // end of if(TMath::Abs(denominator2)>0.)
4151  } // end of if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
4152  
4153  // Cov(<cos(phi)>,<sin(phi)>):
4154  Double_t product3 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(3); // <<cos(phi)><sin(phi)>> 
4155  Double_t term1st3 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
4156  Double_t term2nd3 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
4157  Double_t sumOfW1st3 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
4158  Double_t sumOfW2nd3 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
4159  Double_t sumOfWW3 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(3); // W_{<cos(phi)>} * W_{<sin(phi)>}
4160  // numerator in the expression for the the unbiased estimator for covariance:
4161  Double_t numerator3 = product3 - term1st3*term2nd3; 
4162  // denominator in the expression for the the unbiased estimator for covariance:
4163  Double_t denominator3 = 0;
4164  if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
4165  { 
4166   denominator3 = 1.-sumOfWW3/(sumOfW1st3*sumOfW2nd3);
4167   if(TMath::Abs(denominator3)>0.)
4168   {
4169    // covariance:
4170    Double_t covariance3 = numerator3/denominator3;
4171    // weight dependent prefactor for covariance:
4172    Double_t wPrefactor3 = sumOfWW3/(sumOfW1st3*sumOfW2nd3);
4173    // finally, store "weighted" covariance:
4174    fIntFlowCovariancesNUA->SetBinContent(3,wPrefactor3*covariance3);
4175   } // end of if(TMath::Abs(denominator3)>0.)
4176  } // end of if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
4177  
4178  // Cov(<2>,<cos(phi1+phi2)>):
4179  Double_t product4 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(4); // <<2><cos(phi1+phi2)>> 
4180  Double_t term1st4 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4181  Double_t term2nd4 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4182  Double_t sumOfW1st4 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4183  Double_t sumOfW2nd4 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4184  Double_t sumOfWW4 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(4); // W_{<2>} * W_{<cos(phi1+phi2)>}
4185  // numerator in the expression for the the unbiased estimator for covariance:
4186  Double_t numerator4 = product4 - term1st4*term2nd4; 
4187  // denominator in the expression for the the unbiased estimator for covariance:
4188  Double_t denominator4 = 0.;
4189  if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
4190  { 
4191   denominator4 = 1.-sumOfWW4/(sumOfW1st4*sumOfW2nd4);
4192   if(TMath::Abs(denominator4)>0.)
4193   {  
4194    // covariance:
4195    Double_t covariance4 = numerator4/denominator4;
4196    // weight dependent prefactor for covariance:
4197    Double_t wPrefactor4 = sumOfWW4/(sumOfW1st4*sumOfW2nd4);
4198    // finally, store "weighted" covariance:
4199    fIntFlowCovariancesNUA->SetBinContent(4,wPrefactor4*covariance4);
4200   } // end of if(TMath::Abs(denominator4)>0.)
4201  } // end of if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
4202  
4203  // Cov(<2>,<sin(phi1+phi2)>):
4204  Double_t product5 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(5); // <<2><sin(phi1+phi2)>> 
4205  Double_t term1st5 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4206  Double_t term2nd5 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4207  Double_t sumOfW1st5 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4208  Double_t sumOfW2nd5 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4209  Double_t sumOfWW5 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(5); // W_{<2>} * W_{<sin(phi1+phi2)>}
4210  // numerator in the expression for the the unbiased estimator for covariance:
4211  Double_t numerator5 = product5 - term1st5*term2nd5; 
4212  // denominator in the expression for the the unbiased estimator for covariance:
4213  Double_t denominator5 = 0.;
4214  if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
4215  {  
4216   denominator5 = 1.-sumOfWW5/(sumOfW1st5*sumOfW2nd5);
4217   if(TMath::Abs(denominator5)>0.)
4218   {  
4219    // covariance:
4220    Double_t covariance5 = numerator5/denominator5;
4221    // weight dependent prefactor for covariance:
4222    Double_t wPrefactor5 = sumOfWW5/(sumOfW1st5*sumOfW2nd5);
4223    // finally, store "weighted" covariance:
4224    fIntFlowCovariancesNUA->SetBinContent(5,wPrefactor5*covariance5);
4225   } // end of if(TMath::Abs(denominator5)>0.)
4226  } // end of if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
4227  
4228  // Cov(<2>,<cos(phi1-phi2-phi3)>):
4229  Double_t product6 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(6); // <<2><cos(phi1-phi2-phi3)>> 
4230  Double_t term1st6 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4231  Double_t term2nd6 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4232  Double_t sumOfW1st6 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4233  Double_t sumOfW2nd6 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4234  Double_t sumOfWW6 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(6); // W_{<2>} * W_{<cos(phi1-phi2-phi3)>}
4235  // numerator in the expression for the the unbiased estimator for covariance:
4236  Double_t numerator6 = product6 - term1st6*term2nd6; 
4237  // denominator in the expression for the the unbiased estimator for covariance:
4238  Double_t denominator6 = 0.;
4239  if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
4240  {  
4241   denominator6 = 1.-sumOfWW6/(sumOfW1st6*sumOfW2nd6);
4242   if(TMath::Abs(denominator6)>0.)
4243   {  
4244    // covariance:
4245    Double_t covariance6 = numerator6/denominator6;
4246    // weight dependent prefactor for covariance:
4247    Double_t wPrefactor6 = sumOfWW6/(sumOfW1st6*sumOfW2nd6);
4248    // finally, store "weighted" covariance:
4249    fIntFlowCovariancesNUA->SetBinContent(6,wPrefactor6*covariance6);
4250   } // end of if(TMath::Abs(denominator6)>0.)
4251  } // end of if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
4252  
4253  // Cov(<2>,<sin(phi1-phi2-phi3)>):
4254  Double_t product7 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(7); // <<2><sin(phi1-phi2-phi3)>> 
4255  Double_t term1st7 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4256  Double_t term2nd7 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4257  Double_t sumOfW1st7 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4258  Double_t sumOfW2nd7 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4259  Double_t sumOfWW7 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(7); // W_{<2>} * W_{<sin(phi1-phi2-phi3)>}
4260  // numerator in the expression for the the unbiased estimator for covariance:
4261  Double_t numerator7 = product7 - term1st7*term2nd7; 
4262  // denominator in the expression for the the unbiased estimator for covariance:
4263  Double_t denominator7 = 0.;
4264  if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
4265  {  
4266   denominator7 = 1.-sumOfWW7/(sumOfW1st7*sumOfW2nd7);
4267   if(TMath::Abs(denominator7)>0.)
4268   {   
4269    // covariance:
4270    Double_t covariance7 = numerator7/denominator7;
4271    // weight dependent prefactor for covariance:
4272    Double_t wPrefactor7 = sumOfWW7/(sumOfW1st7*sumOfW2nd7);
4273    // finally, store "weighted" covariance:
4274    fIntFlowCovariancesNUA->SetBinContent(7,wPrefactor7*covariance7);
4275   } // end of if(TMath::Abs(denominator7)>0.)
4276  } // end of if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
4277  
4278  // Cov(<4>,<cos(phi1>):
4279  Double_t product8 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(8); // <<4><cos(phi1)>> 
4280  Double_t term1st8 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4281  Double_t term2nd8 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4282  Double_t sumOfW1st8 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4283  Double_t sumOfW2nd8 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4284  Double_t sumOfWW8 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(8); // W_{<4>} * W_{<cos(phi1)>}
4285  // numerator in the expression for the the unbiased estimator for covariance:
4286  Double_t numerator8 = product8 - term1st8*term2nd8; 
4287  // denominator in the expression for the the unbiased estimator for covariance:
4288  Double_t denominator8 = 0.;
4289  if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
4290  { 
4291   denominator8 = 1.-sumOfWW8/(sumOfW1st8*sumOfW2nd8);
4292   if(TMath::Abs(denominator8)>0.)
4293   {     
4294    // covariance:
4295    Double_t covariance8 = numerator8/denominator8;
4296    // weight dependent prefactor for covariance:
4297    Double_t wPrefactor8 = sumOfWW8/(sumOfW1st8*sumOfW2nd8);
4298    // finally, store "weighted" covariance:
4299    fIntFlowCovariancesNUA->SetBinContent(8,wPrefactor8*covariance8);
4300   } // end of if(TMath::Abs(denominator8)>0.)
4301  } // end of if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
4302  
4303  // Cov(<4>,<sin(phi1)>):
4304  Double_t product9 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(9); // <<4><sin(phi1)>> 
4305  Double_t term1st9 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4306  Double_t term2nd9 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4307  Double_t sumOfW1st9 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4308  Double_t sumOfW2nd9 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4309  Double_t sumOfWW9 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(9); // W_{<4>} * W_{<sin(phi1)>}
4310  // numerator in the expression for the the unbiased estimator for covariance:
4311  Double_t numerator9 = product9 - term1st9*term2nd9; 
4312  // denominator in the expression for the the unbiased estimator for covariance:
4313  Double_t denominator9 = 0.;
4314  if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
4315  {
4316   denominator9 = 1.-sumOfWW9/(sumOfW1st9*sumOfW2nd9);
4317   if(TMath::Abs(denominator9)>0.)
4318   {     
4319    // covariance:
4320    Double_t covariance9 = numerator9/denominator9;
4321    // weight dependent prefactor for covariance:
4322    Double_t wPrefactor9 = sumOfWW9/(sumOfW1st9*sumOfW2nd9);
4323    // finally, store "weighted" covariance:
4324    fIntFlowCovariancesNUA->SetBinContent(9,wPrefactor9*covariance9); 
4325   }
4326  } // end of if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
4327  
4328  // Cov(<4>,<cos(phi1+phi2)>):
4329  Double_t product10 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(10); // <<4><cos(phi1+phi2)>> 
4330  Double_t term1st10 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4331  Double_t term2nd10 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4332  Double_t sumOfW1st10 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4333  Double_t sumOfW2nd10 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4334  Double_t sumOfWW10 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(10); // W_{<4>} * W_{<cos(phi1+phi2)>}
4335  // numerator in the expression for the the unbiased estimator for covariance:
4336  Double_t numerator10 = product10 - term1st10*term2nd10; 
4337  // denominator in the expression for the the unbiased estimator for covariance:
4338  Double_t denominator10 = 0.;
4339  if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
4340  { 
4341   denominator10 = 1.-sumOfWW10/(sumOfW1st10*sumOfW2nd10);
4342   if(TMath::Abs(denominator10)>0.) 
4343   { 
4344    // covariance:
4345    Double_t covariance10 = numerator10/denominator10;
4346    // weight dependent prefactor for covariance:
4347    Double_t wPrefactor10 = sumOfWW10/(sumOfW1st10*sumOfW2nd10);
4348    // finally, store "weighted" covariance:
4349    fIntFlowCovariancesNUA->SetBinContent(10,wPrefactor10*covariance10);
4350   } // end of if(TMath::Abs(denominator10)>0.) 
4351  } // end of if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
4352  
4353  // Cov(<4>,<sin(phi1+phi2)>):
4354  Double_t product11 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(11); // <<4><sin(phi1+phi2)>> 
4355  Double_t term1st11 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4356  Double_t term2nd11 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4357  Double_t sumOfW1st11 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4358  Double_t sumOfW2nd11 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4359  Double_t sumOfWW11 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(11); // W_{<4>} * W_{<sin(phi1+phi2)>}
4360  // numerator in the expression for the the unbiased estimator for covariance:
4361  Double_t numerator11 = product11 - term1st11*term2nd11; 
4362  // denominator in the expression for the the unbiased estimator for covariance:
4363  Double_t denominator11 = 0.;
4364  if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
4365  {  
4366   denominator11 = 1.-sumOfWW11/(sumOfW1st11*sumOfW2nd11);
4367   if(TMath::Abs(denominator11)>0.) 
4368   { 
4369    // covariance:
4370    Double_t covariance11 = numerator11/denominator11;
4371    // weight dependent prefactor for covariance:
4372    Double_t wPrefactor11 = sumOfWW11/(sumOfW1st11*sumOfW2nd11);
4373    // finally, store "weighted" covariance:
4374    fIntFlowCovariancesNUA->SetBinContent(11,wPrefactor11*covariance11);
4375   } // end of if(TMath::Abs(denominator11)>0.) 
4376  } // end of if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
4377
4378  // Cov(<4>,<cos(phi1-phi2-phi3)>):
4379  Double_t product12 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(12); // <<4><cos(phi1-phi2-phi3)>> 
4380  Double_t term1st12 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4381  Double_t term2nd12 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4382  Double_t sumOfW1st12 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4383  Double_t sumOfW2nd12 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4384  Double_t sumOfWW12 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(12); // W_{<4>} * W_{<cos(phi1-phi2-phi3)>}
4385  // numerator in the expression for the the unbiased estimator for covariance:
4386  Double_t numerator12 = product12 - term1st12*term2nd12; 
4387  // denominator in the expression for the the unbiased estimator for covariance:
4388  Double_t denominator12 = 0.;
4389  if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.) 
4390  {   
4391   denominator12 = 1.-sumOfWW12/(sumOfW1st12*sumOfW2nd12);
4392   if(TMath::Abs(denominator12)>0.) 
4393   { 
4394    // covariance:
4395    Double_t covariance12 = numerator12/denominator12;
4396    // weight dependent prefactor for covariance:
4397    Double_t wPrefactor12 = sumOfWW12/(sumOfW1st12*sumOfW2nd12);
4398    // finally, store "weighted" covariance:
4399    fIntFlowCovariancesNUA->SetBinContent(12,wPrefactor12*covariance12);
4400   } // end of if(TMath::Abs(denominator12)>0.)
4401  } // end of if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.)  
4402
4403  // Cov(<4>,<sin(phi1-phi2-phi3)>):
4404  Double_t product13 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(13); // <<4><sin(phi1-phi2-phi3)>> 
4405  Double_t term1st13 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4406  Double_t term2nd13 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4407  Double_t sumOfW1st13 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4408  Double_t sumOfW2nd13 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4409  Double_t sumOfWW13 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(13); // W_{<4>} * W_{<sin(phi1-phi2-phi3)>}
4410  // numerator in the expression for the the unbiased estimator for covariance:
4411  Double_t numerator13 = product13 - term1st13*term2nd13; 
4412  // denominator in the expression for the the unbiased estimator for covariance:
4413  Double_t denominator13 = 0.;
4414  if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
4415  {   
4416   denominator13 = 1.-sumOfWW13/(sumOfW1st13*sumOfW2nd13);
4417   if(TMath::Abs(denominator13)>0.) 
4418   { 
4419    // covariance:
4420    Double_t covariance13 = numerator13/denominator13;
4421    // weight dependent prefactor for covariance:
4422    Double_t wPrefactor13 = sumOfWW13/(sumOfW1st13*sumOfW2nd13);
4423    // finally, store "weighted" covariance:
4424    fIntFlowCovariancesNUA->SetBinContent(13,wPrefactor13*covariance13);
4425   } // end of if(TMath::Abs(denominator13)>0.) 
4426  } // end of if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
4427
4428  // Cov(<cos(phi1)>,<cos(phi1+phi2)>):
4429  Double_t product14 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(14); // <<cos(phi1)><cos(phi1+phi2)>> 
4430  Double_t term1st14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4431  Double_t term2nd14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4432  Double_t sumOfW1st14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4433  Double_t sumOfW2nd14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4434  Double_t sumOfWW14 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(14); // W_{<cos(phi1)>} * W_{<cos(phi1+phi2)>}
4435  // numerator in the expression for the the unbiased estimator for covariance:
4436  Double_t numerator14 = product14 - term1st14*term2nd14; 
4437  // denominator in the expression for the the unbiased estimator for covariance:
4438  Double_t denominator14 = 0.;
4439  if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
4440  {  
4441   denominator14 = 1.-sumOfWW14/(sumOfW1st14*sumOfW2nd14);
4442   if(TMath::Abs(denominator14)>0.) 
4443   { 
4444    // covariance:
4445    Double_t covariance14 = numerator14/denominator14;
4446    // weight dependent prefactor for covariance:
4447    Double_t wPrefactor14 = sumOfWW14/(sumOfW1st14*sumOfW2nd14);
4448    // finally, store "weighted" covariance:
4449    fIntFlowCovariancesNUA->SetBinContent(14,wPrefactor14*covariance14);
4450   } // end of if(TMath::Abs(denominator14)>0.) 
4451  } // end of if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
4452
4453  // Cov(<cos(phi1)>,<sin(phi1+phi2)>):
4454  Double_t product15 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(15); // <<cos(phi1)><sin(phi1+phi2)>> 
4455  Double_t term1st15 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4456  Double_t term2nd15 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4457  Double_t sumOfW1st15 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4458  Double_t sumOfW2nd15 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4459  Double_t sumOfWW15 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(15); // W_{<cos(phi1)>} * W_{<sin(phi1+phi2)>}
4460  // numerator in the expression for the the unbiased estimator for covariance:
4461  Double_t numerator15 = product15 - term1st15*term2nd15; 
4462  // denominator in the expression for the the unbiased estimator for covariance:
4463  Double_t denominator15 = 0.;
4464  if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.) 
4465  {  
4466   denominator15 = 1.-sumOfWW15/(sumOfW1st15*sumOfW2nd15);
4467   if(TMath::Abs(denominator15)>0.) 
4468   { 
4469    // covariance:
4470    Double_t covariance15 = numerator15/denominator15;
4471    // weight dependent prefactor for covariance:
4472    Double_t wPrefactor15 = sumOfWW15/(sumOfW1st15*sumOfW2nd15);
4473    // finally, store "weighted" covariance:
4474    fIntFlowCovariancesNUA->SetBinContent(15,wPrefactor15*covariance15);
4475   } // end of if(TMath::Abs(denominator15)>0.)  
4476  } // end of if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.)  
4477  
4478  // Cov(<cos(phi1)>,<cos(phi1-phi2-phi3)>):
4479  Double_t product16 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(16); // <<cos(phi1)><cos(phi1-phi2-phi3)>> 
4480  Double_t term1st16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4481  Double_t term2nd16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4482  Double_t sumOfW1st16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4483  Double_t sumOfW2nd16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4484  Double_t sumOfWW16 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(16); // W_{<cos(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
4485  // numerator in the expression for the the unbiased estimator for covariance:
4486  Double_t numerator16 = product16 - term1st16*term2nd16; 
4487  // denominator in the expression for the the unbiased estimator for covariance:
4488  Double_t denominator16 = 0.;
4489  if(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.) 
4490  {   
4491   denominator16 = 1.-sumOfWW16/(sumOfW1st16*sumOfW2nd16);
4492   if(TMath::Abs(denominator16)>0.) 
4493   {   
4494    // covariance:
4495    Double_t covariance16 = numerator16/denominator16;
4496    // weight dependent prefactor for covariance:
4497    Double_t wPrefactor16 = sumOfWW16/(sumOfW1st16*sumOfW2nd16);
4498    // finally, store "weighted" covariance:
4499    fIntFlowCovariancesNUA->SetBinContent(16,wPrefactor16*covariance16);
4500   } // end of if(TMath::Abs(denominator16)>0.)
4501  } // end ofif(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.)  
4502  
4503  // Cov(<cos(phi1)>,<sin(phi1-phi2-phi3)>):
4504  Double_t product17 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(17); // <<cos(phi1)><sin(phi1-phi2-phi3)>> 
4505  Double_t term1st17 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4506  Double_t term2nd17 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4507  Double_t sumOfW1st17 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4508  Double_t sumOfW2nd17 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4509  Double_t sumOfWW17 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(17); // W_{<cos(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
4510  // numerator in the expression for the the unbiased estimator for covariance:
4511  Double_t numerator17 = product17 - term1st17*term2nd17; 
4512  // denominator in the expression for the the unbiased estimator for covariance:
4513  Double_t denominator17 = 0.;
4514  if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
4515  {
4516   denominator17 = 1.-sumOfWW17/(sumOfW1st17*sumOfW2nd17);
4517   if(TMath::Abs(denominator17)>0.) 
4518   {   
4519    // covariance:
4520    Double_t covariance17 = numerator17/denominator17;
4521    // weight dependent prefactor for covariance:
4522    Double_t wPrefactor17 = sumOfWW17/(sumOfW1st17*sumOfW2nd17);
4523     // finally, store "weighted" covariance:
4524    fIntFlowCovariancesNUA->SetBinContent(17,wPrefactor17*covariance17);
4525   } // end of if(TMath::Abs(denominator17)>0.) 
4526  } // end of if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
4527
4528  // Cov(<sin(phi1)>,<cos(phi1+phi2)>):
4529  Double_t product18 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(18); // <<sin(phi1)><cos(phi1+phi2)>> 
4530  Double_t term1st18 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4531  Double_t term2nd18 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4532  Double_t sumOfW1st18 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4533  Double_t sumOfW2nd18 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4534  Double_t sumOfWW18 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(18); // W_{<sin(phi1)>} * W_{<cos(phi1+phi2)>}
4535  // numerator in the expression for the the unbiased estimator for covariance:
4536  Double_t numerator18 = product18 - term1st18*term2nd18; 
4537  // denominator in the expression for the the unbiased estimator for covariance:
4538  Double_t denominator18 = 0.;
4539  if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
4540  { 
4541   denominator18 = 1.-sumOfWW18/(sumOfW1st18*sumOfW2nd18);
4542   if(TMath::Abs(denominator18)>0.) 
4543   {   
4544    // covariance:
4545    Double_t covariance18 = numerator18/denominator18;
4546    // weight dependent prefactor for covariance:
4547    Double_t wPrefactor18 = sumOfWW18/(sumOfW1st18*sumOfW2nd18);
4548    // finally, store "weighted" covariance:
4549    fIntFlowCovariancesNUA->SetBinContent(18,wPrefactor18*covariance18); 
4550   } // end of if(TMath::Abs(denominator18)>0.) 
4551  } // end of if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
4552
4553  // Cov(<sin(phi1)>,<sin(phi1+phi2)>):
4554  Double_t product19 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(19); // <<sin(phi1)><sin(phi1+phi2)>> 
4555  Double_t term1st19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4556  Double_t term2nd19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4557  Double_t sumOfW1st19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4558  Double_t sumOfW2nd19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4559  Double_t sumOfWW19 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(19); // W_{<sin(phi1)>} * W_{<sin(phi1+phi2)>}
4560  // numerator in the expression for the the unbiased estimator for covariance:
4561  Double_t numerator19 = product19 - term1st19*term2nd19; 
4562  // denominator in the expression for the the unbiased estimator for covariance:
4563  Double_t denominator19 = 0.;
4564  if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.) 
4565  { 
4566   denominator19 = 1.-sumOfWW19/(sumOfW1st19*sumOfW2nd19);
4567   if(TMath::Abs(denominator19)>0.) 
4568   {   
4569    // covariance:
4570    Double_t covariance19 = numerator19/denominator19;
4571    // weight dependent prefactor for covariance:
4572    Double_t wPrefactor19 = sumOfWW19/(sumOfW1st19*sumOfW2nd19);
4573    // finally, store "weighted" covariance:
4574    fIntFlowCovariancesNUA->SetBinContent(19,wPrefactor19*covariance19);
4575   } // end of if(TMath::Abs(denominator19)>0.)
4576  } // end of if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.)
4577  
4578  // Cov(<sin(phi1)>,<cos(phi1-phi2-phi3)>):
4579  Double_t product20 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(20); // <<sin(phi1)><cos(phi1-phi2-phi3)>> 
4580  Double_t term1st20 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4581  Double_t term2nd20 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4582  Double_t sumOfW1st20 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4583  Double_t sumOfW2nd20 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4584  Double_t sumOfWW20 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(20); // W_{<sin(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
4585  // numerator in the expression for the the unbiased estimator for covariance:
4586  Double_t numerator20 = product20 - term1st20*term2nd20; 
4587  // denominator in the expression for the the unbiased estimator for covariance:
4588  Double_t denominator20 = 0.;
4589  if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
4590  { 
4591   denominator20 = 1.-sumOfWW20/(sumOfW1st20*sumOfW2nd20);
4592   if(TMath::Abs(denominator20)>0.) 
4593   { 
4594    // covariance:
4595    Double_t covariance20 = numerator20/denominator20;
4596    // weight dependent prefactor for covariance:
4597    Double_t wPrefactor20 = sumOfWW20/(sumOfW1st20*sumOfW2nd20);
4598    // finally, store "weighted" covariance:
4599    fIntFlowCovariancesNUA->SetBinContent(20,wPrefactor20*covariance20);
4600   } // end of if(TMath::Abs(denominator20)>0.) 
4601  } // end of if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
4602
4603  // Cov(<sin(phi1)>,<sin(phi1-phi2-phi3)>):
4604  Double_t product21 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(21); // <<sin(phi1)><sin(phi1-phi2-phi3)>> 
4605  Double_t term1st21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4606  Double_t term2nd21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4607  Double_t sumOfW1st21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4608  Double_t sumOfW2nd21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4609  Double_t sumOfWW21 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(21); // W_{<sin(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
4610  // numerator in the expression for the the unbiased estimator for covariance:
4611  Double_t numerator21 = product21 - term1st21*term2nd21; 
4612  // denominator in the expression for the the unbiased estimator for covariance:
4613  Double_t denominator21 = 0.;
4614  if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
4615  { 
4616   denominator21 = 1.-sumOfWW21/(sumOfW1st21*sumOfW2nd21);
4617   if(TMath::Abs(denominator21)>0.) 
4618   {   
4619    // covariance:
4620    Double_t covariance21 = numerator21/denominator21;
4621    // weight dependent prefactor for covariance:
4622    Double_t wPrefactor21 = sumOfWW21/(sumOfW1st21*sumOfW2nd21);
4623    // finally, store "weighted" covariance:
4624    fIntFlowCovariancesNUA->SetBinContent(21,wPrefactor21*covariance21);
4625   } // end of if(TMath::Abs(denominator21)>0.)
4626  } // end of if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
4627
4628  // Cov(<cos(phi1+phi2)>,<sin(phi1+phi2)>):
4629  Double_t product22 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(22); // <<cos(phi1+phi2)><sin(phi1+phi2)>> 
4630  Double_t term1st22 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4631  Double_t term2nd22 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4632  Double_t sumOfW1st22 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4633  Double_t sumOfW2nd22 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4634  Double_t sumOfWW22 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(22); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1+phi2)>}
4635  // numerator in the expression for the the unbiased estimator for covariance:
4636  Double_t numerator22 = product22 - term1st22*term2nd22; 
4637  // denominator in the expression for the the unbiased estimator for covariance:
4638  Double_t denominator22 = 0.;
4639  if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.)
4640  { 
4641   denominator22 = 1.-sumOfWW22/(sumOfW1st22*sumOfW2nd22);
4642   if(TMath::Abs(denominator22)>0.) 
4643   {   
4644    // covariance:
4645    Double_t covariance22 = numerator22/denominator22;
4646    // weight dependent prefactor for covariance:
4647    Double_t wPrefactor22 = sumOfWW22/(sumOfW1st22*sumOfW2nd22);
4648    // finally, store "weighted" covariance:
4649    fIntFlowCovariancesNUA->SetBinContent(22,wPrefactor22*covariance22);
4650   } // end of if(TMath::Abs(denominator22)>0.) 
4651  } // end of if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.) 
4652
4653  // Cov(<cos(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
4654  Double_t product23 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(23); // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>> 
4655  Double_t term1st23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4656  Double_t term2nd23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4657  Double_t sumOfW1st23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4658  Double_t sumOfW2nd23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4659  Double_t sumOfWW23 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(23); // W_{<cos(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
4660  // numerator in the expression for the the unbiased estimator for covariance:
4661  Double_t numerator23 = product23 - term1st23*term2nd23; 
4662  // denominator in the expression for the the unbiased estimator for covariance:
4663  Double_t denominator23 = 0.;
4664  if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
4665  {  
4666   denominator23 = 1.-sumOfWW23/(sumOfW1st23*sumOfW2nd23);
4667   if(TMath::Abs(denominator23)>0.) 
4668   {   
4669    // covariance:
4670    Double_t covariance23 = numerator23/denominator23;
4671    // weight dependent prefactor for covariance:
4672    Double_t wPrefactor23 = sumOfWW23/(sumOfW1st23*sumOfW2nd23);
4673    // finally, store "weighted" covariance:
4674    fIntFlowCovariancesNUA->SetBinContent(23,wPrefactor23*covariance23);
4675   } // end of if(TMath::Abs(denominator23)>0.) 
4676  } // end of if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
4677  
4678  // Cov(<cos(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4679  Double_t product24 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(24); // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4680  Double_t term1st24 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4681  Double_t term2nd24 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4682  Double_t sumOfW1st24 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4683  Double_t sumOfW2nd24 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4684  Double_t sumOfWW24 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(24); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4685  // numerator in the expression for the the unbiased estimator for covariance:
4686  Double_t numerator24 = product24 - term1st24*term2nd24; 
4687  // denominator in the expression for the the unbiased estimator for covariance:
4688  Double_t denominator24 = 0.;
4689  if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4690  {   
4691   denominator24 = 1.-sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4692   if(TMath::Abs(denominator24)>0.) 
4693   {   
4694    // covariance:
4695    Double_t covariance24 = numerator24/denominator24;
4696    // weight dependent prefactor for covariance:
4697    Double_t wPrefactor24 = sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4698    // finally, store "weighted" covariance:
4699    fIntFlowCovariancesNUA->SetBinContent(24,wPrefactor24*covariance24);
4700   } // end of if(TMath::Abs(denominator24)>0.)  
4701  } // end of if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4702
4703  // Cov(<sin(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
4704  Double_t product25 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(25); // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>> 
4705  Double_t term1st25 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4706  Double_t term2nd25 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4707  Double_t sumOfW1st25 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4708  Double_t sumOfW2nd25 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4709  Double_t sumOfWW25 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(25); // W_{<sin(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
4710  // numerator in the expression for the the unbiased estimator for covariance:
4711  Double_t numerator25 = product25 - term1st25*term2nd25; 
4712  // denominator in the expression for the the unbiased estimator for covariance:
4713  Double_t denominator25 = 0.;
4714  if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4715  { 
4716   denominator25 = 1.-sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4717   if(TMath::Abs(denominator25)>0.) 
4718   { 
4719    // covariance:
4720    Double_t covariance25 = numerator25/denominator25;
4721    // weight dependent prefactor for covariance:
4722    Double_t wPrefactor25 = sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4723    // finally, store "weighted" covariance:
4724    fIntFlowCovariancesNUA->SetBinContent(25,wPrefactor25*covariance25);
4725   } // end of if(TMath::Abs(denominator25)>0.)
4726  } // end of if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4727  
4728  // Cov(<sin(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4729  Double_t product26 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(26); // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4730  Double_t term1st26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4731  Double_t term2nd26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4732  Double_t sumOfW1st26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4733  Double_t sumOfW2nd26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4734  Double_t sumOfWW26 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(26); // W_{<sin(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4735  // numerator in the expression for the the unbiased estimator for covariance:
4736  Double_t numerator26 = product26 - term1st26*term2nd26; 
4737  // denominator in the expression for the the unbiased estimator for covariance:
4738  Double_t denominator26 = 0.;
4739  if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4740  { 
4741   denominator26 = 1.-sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4742   if(TMath::Abs(denominator26)>0.) 
4743   { 
4744    // covariance:
4745    Double_t covariance26 = numerator26/denominator26;
4746    // weight dependent prefactor for covariance:
4747    Double_t wPrefactor26 = sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4748    // finally, store "weighted" covariance:
4749    fIntFlowCovariancesNUA->SetBinContent(26,wPrefactor26*covariance26);
4750   } // end of if(TMath::Abs(denominator26)>0.) 
4751  } // end of if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4752  
4753  // Cov(<cos(phi1-phi2-phi3)>,<sin(phi1-phi2-phi3)>):
4754  Double_t product27 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(27); // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>> 
4755  Double_t term1st27 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4756  Double_t term2nd27 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4757  Double_t sumOfW1st27 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4758  Double_t sumOfW2nd27 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4759  Double_t sumOfWW27 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(27); // W_{<cos(phi1-phi2-phi3)>} * W_{<sin(phi1-phi2-phi3)>}
4760  // numerator in the expression for the the unbiased estimator for covariance:
4761  Double_t numerator27 = product27 - term1st27*term2nd27; 
4762  // denominator in the expression for the the unbiased estimator for covariance:
4763  Double_t denominator27 = 0.;
4764  if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4765  { 
4766   denominator27 = 1.-sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4767   if(TMath::Abs(denominator27)>0.) 
4768   { 
4769    // covariance:
4770    Double_t covariance27 = numerator27/denominator27;
4771    // weight dependent prefactor for covariance:
4772    Double_t wPrefactor27 = sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4773    // finally, store "weighted" covariance:
4774    fIntFlowCovariancesNUA->SetBinContent(27,wPrefactor27*covariance27);
4775   } // end of if(TMath::Abs(denominator27)>0.) 
4776  } // end of if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4777  
4778 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
4779
4780 //================================================================================================================================
4781
4782 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow() 
4783 {
4784  // From profile fIntFlowCorrelationsPro access measured correlations and spread, 
4785  // correctly calculate the statistical errors and store the final results and 
4786  // statistical errors for correlations in histogram fIntFlowCorrelationsHist.
4787  //
4788  // Remark: Statistical error of correlation is calculated as:
4789  //
4790  //          statistical error = termA * spread * termB:
4791  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
4792  //          termB = 1/sqrt(1-termA^2)   
4793  //
4794    
4795  for(Int_t ci=1;ci<=4;ci++) // correlation index
4796  {
4797   if(fIntFlowCorrelationsPro->GetBinEffectiveEntries(ci) < 2 || fIntFlowSquaredCorrelationsPro->GetBinEffectiveEntries(ci) < 2)
4798   {
4799    fIntFlowCorrelationsPro->SetBinError(ci,0.);
4800    fIntFlowSquaredCorrelationsPro->SetBinError(ci,0.);
4801    continue;
4802   } 
4803   Double_t correlation = fIntFlowCorrelationsPro->GetBinContent(ci);
4804   Double_t squaredCorrelation = fIntFlowSquaredCorrelationsPro->GetBinContent(ci);
4805   Double_t spread = 0.;
4806   if(squaredCorrelation-correlation*correlation >= 0.)
4807   {
4808    spread = pow(squaredCorrelation-correlation*correlation,0.5);
4809   } else
4810     {
4811      cout<<endl;
4812      cout<<Form(" WARNING: Imaginary 'spread' for %d-particle correlation!!!! ",2*ci)<<endl;
4813      cout<<endl;
4814     }
4815   Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeights[0]->GetBinContent(ci);
4816   Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeights[1]->GetBinContent(ci);
4817   Double_t termA = 0.;
4818   Double_t termB = 0.;
4819   if(TMath::Abs(sumOfLinearEventWeights) > 0.) // to be improved - shall I omitt here Abs() ?
4820   {
4821    termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
4822   } else
4823     {
4824      cout<<endl;
4825      cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;
4826      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4827      cout<<endl;
4828     }
4829   if(1.-pow(termA,2.) > 0.)
4830   {
4831    termB = 1./pow(1-pow(termA,2.),0.5);
4832   } else
4833     {
4834      cout<<endl;
4835      cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;   
4836      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4837      cout<<endl;
4838     }     
4839   Double_t statisticalError = termA * spread * termB;
4840   fIntFlowCorrelationsHist->SetBinContent(ci,correlation);
4841   fIntFlowCorrelationsHist->SetBinError(ci,statisticalError);
4842  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index     
4843  
4844  // Versus multiplicity: 
4845  if(!fCalculateCumulantsVsM){return;}
4846  for(Int_t ci=0;ci<=3;ci++) // correlation index
4847  {
4848   Int_t nBins = fIntFlowCorrelationsVsMPro[ci]->GetNbinsX(); 
4849   for(Int_t b=1;b<=nBins;b++) // looping over multiplicity bins
4850   {
4851    if(fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2 || fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2)
4852    {
4853     fIntFlowCorrelationsVsMPro[ci]->SetBinError(b,0.);
4854     fIntFlowSquaredCorrelationsVsMPro[ci]->SetBinError(b,0.);
4855     continue;
4856    } 
4857    Double_t correlationVsM = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
4858    Double_t squaredCorrelationVsM = fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinContent(b);
4859    Double_t spreadVsM = 0.;
4860    if(squaredCorrelationVsM-correlationVsM*correlationVsM >= 0.)
4861    {
4862     spreadVsM = pow(squaredCorrelationVsM-correlationVsM*correlationVsM,0.5);
4863    } else
4864      {
4865       cout<<endl;
4866       cout<<Form(" WARNING (QC): Imaginary 'spreadVsM' for ci = %d, bin = %d, entries = %f !!!!",
4867                  ci,b,fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b))<<endl; 
4868       cout<<endl;
4869      }     
4870    Double_t sumOfLinearEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][0]->GetBinContent(b);
4871    Double_t sumOfQuadraticEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][1]->GetBinContent(b);
4872    Double_t termAVsM = 0.;
4873    Double_t termBVsM = 0.;
4874    if(sumOfLinearEventWeightsVsM > 0.) 
4875    {
4876     termAVsM = pow(sumOfQuadraticEventWeightsVsM,0.5)/sumOfLinearEventWeightsVsM;
4877    }
4878    if(1.-pow(termAVsM,2.) > 0.)
4879    {
4880     termBVsM = 1./pow(1-pow(termAVsM,2.),0.5);
4881    }     
4882    Double_t statisticalErrorVsM = termAVsM * spreadVsM * termBVsM;
4883    fIntFlowCorrelationsVsMHist[ci]->SetBinContent(b,correlationVsM);
4884    fIntFlowCorrelationsVsMHist[ci]->SetBinError(b,statisticalErrorVsM);  
4885   } // end of for(Int_t b=1;b<=nBins;b++)
4886  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index                                                        
4887                                                                                                                            
4888 } // end of AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow()
4889
4890 //================================================================================================================================
4891
4892 void AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(Int_t nRP)
4893 {
4894  // Fill profile fAverageMultiplicity to hold average multiplicities and 
4895  // number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
4896  
4897  // Binning of fAverageMultiplicity is organized as follows:
4898  //  1st bin: all events (including the empty ones)
4899  //  2nd bin: event with # of RPs greater or equal to 1
4900  //  3rd bin: event with # of RPs greater or equal to 2
4901  //  4th bin: event with # of RPs greater or equal to 3
4902  //  5th bin: event with # of RPs greater or equal to 4
4903  //  6th bin: event with # of RPs greater or equal to 5
4904  //  7th bin: event with # of RPs greater or equal to 6
4905  //  8th bin: event with # of RPs greater or equal to 7
4906  //  9th bin: event with # of RPs greater or equal to 8
4907  
4908  if(nRP<0)
4909  {
4910   cout<<endl;
4911   cout<<" WARNING (QC): nRP<0 in in AFAWQC::FAM() !!!!"<<endl;
4912   cout<<endl;
4913   exit(0);
4914  }
4915  
4916  for(Int_t i=0;i<9;i++)
4917  {
4918   if(nRP>=i){fAvMultiplicity->Fill(i+0.5,nRP,1);}
4919  }
4920  
4921 } // end of AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(nRP)
4922
4923 //================================================================================================================================
4924
4925 void AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
4926
4927  // a) Calculate Q-cumulants from the measured multiparticle correlations;
4928  // b) Propagate the statistical errors from measured multiparticle correlations to statistical errors of Q-cumulants;  
4929  // c) Remark: Q-cumulants calculated in this method are biased by non-uniform acceptance of detector !!!! 
4930  //            Method CalculateQcumulantsCorrectedForNUAIntFlow() is called afterwards to correct for this bias;
4931  // d) Store the results and statistical error of Q-cumulants in histogram fIntFlowQcumulants.
4932  //    Binning of fIntFlowQcumulants is organized as follows:
4933  //
4934  //            1st bin: QC{2}
4935  //            2nd bin: QC{4}
4936  //            3rd bin: QC{6}
4937  //            4th bin: QC{8}
4938  //
4939  
4940  // Correlations:
4941  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
4942  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
4943  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
4944  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
4945  // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
4946  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
4947  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
4948  Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
4949  Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
4950  // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
4951  Double_t wCov24 = 0.; // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4952  Double_t wCov26 = 0.; // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4953  Double_t wCov28 = 0.; // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4954  Double_t wCov46 = 0.; // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4955  Double_t wCov48 = 0.; // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4956  Double_t wCov68 = 0.; // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>)  
4957  if(!fForgetAboutCovariances)
4958  {
4959   wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4960   wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4961   wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4962   wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4963   wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4964   wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
4965  }
4966  // Q-cumulants: 
4967  Double_t qc2 = 0.; // QC{2}
4968  Double_t qc4 = 0.; // QC{4}
4969  Double_t qc6 = 0.; // QC{6}
4970  Double_t qc8 = 0.; // QC{8}
4971  if(TMath::Abs(two) > 0.){qc2 = two;} 
4972  if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
4973  if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
4974  if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);} 
4975  // Statistical errors of Q-cumulants:       
4976  Double_t qc2Error = 0.;
4977  Double_t qc4Error = 0.;
4978  Double_t qc6Error = 0.;
4979  Double_t qc8Error = 0.; 
4980  // Squared statistical errors of Q-cumulants:       
4981  //Double_t qc2ErrorSquared = 0.;
4982  Double_t qc4ErrorSquared = 0.;
4983  Double_t qc6ErrorSquared = 0.;
4984  Double_t qc8ErrorSquared = 0.;        
4985  // Statistical error of QC{2}:              
4986  qc2Error = twoError;                                                 
4987  // Statistical error of QC{4}:              
4988  qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
4989                  - 8.*two*wCov24;                     
4990  if(qc4ErrorSquared>0.)
4991  {
4992   qc4Error = pow(qc4ErrorSquared,0.5);
4993  } else 
4994    {
4995     cout<<" WARNING (QC): Statistical error of QC{4} is imaginary !!!!"<<endl;
4996    }                                           
4997  // Statistical error of QC{6}:              
4998  qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
4999                  + 81.*pow(two,2.)*pow(fourError,2.)
5000                  + pow(sixError,2.)
5001                  - 162.*two*(4.*pow(two,2.)-four)*wCov24
5002                  + 18.*(4.*pow(two,2.)-four)*wCov26
5003                  - 18.*two*wCov46;                     
5004  if(qc6ErrorSquared>0.)
5005  {
5006   qc6Error = pow(qc6ErrorSquared,0.5);
5007  } else 
5008    {
5009     cout<<" WARNING (QC): Statistical error of QC{6} is imaginary !!!!"<<endl;
5010    }                       
5011  // Statistical error of QC{8}:              
5012  qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
5013                  + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
5014                  + 256.*pow(two,2.)*pow(sixError,2.)
5015                  + pow(eightError,2.)
5016                  - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
5017                  + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
5018                  - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
5019                  - 1152.*two*(4.*pow(two,2.)-four)*wCov46
5020                  + 72.*(4.*pow(two,2.)-four)*wCov48
5021                  - 32.*two*wCov68;      
5022  if(qc8ErrorSquared>0.)
5023  {
5024   qc8Error = pow(qc8ErrorSquared,0.5);
5025  } else 
5026    {
5027     cout<<"WARNING (QC): Statistical error of QC{8} is imaginary !!!!"<<endl;
5028    }
5029  // Store the results and statistical errors for Q-cumulants:
5030  if(TMath::Abs(qc2)>0.)
5031  {
5032   fIntFlowQcumulants->SetBinContent(1,qc2);
5033   fIntFlowQcumulants->SetBinError(1,qc2Error);
5034  }
5035  if(TMath::Abs(qc4)>0.)
5036  {
5037   fIntFlowQcumulants->SetBinContent(2,qc4);
5038   fIntFlowQcumulants->SetBinError(2,qc4Error);
5039  }
5040  if(TMath::Abs(qc6)>0.)
5041  {
5042   fIntFlowQcumulants->SetBinContent(3,qc6);
5043   fIntFlowQcumulants->SetBinError(3,qc6Error);
5044  }
5045  if(TMath::Abs(qc8)>0.)
5046  {
5047   fIntFlowQcumulants->SetBinContent(4,qc8); 
5048   fIntFlowQcumulants->SetBinError(4,qc8Error);
5049  } 
5050  
5051  // Versus multiplicity: 
5052  if(!fCalculateCumulantsVsM){return;}
5053  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
5054  Double_t value[4] = {0.}; // QCs vs M
5055  Double_t error[4] = {0.}; // error of QCs vs M
5056  Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
5057  Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
5058  for(Int_t b=1;b<=nBins;b++)
5059  {
5060   // Correlations:
5061   two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> 
5062   four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>>  
5063   six = fIntFlowCorrelationsVsMHist[2]->GetBinContent(b); // <<6>> 
5064   eight = fIntFlowCorrelationsVsMHist[3]->GetBinContent(b); // <<8>>  
5065   // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
5066   twoError = fIntFlowCorrelationsVsMHist[0]->GetBinError(b); // statistical error of <2>  
5067   fourError = fIntFlowCorrelationsVsMHist[1]->GetBinError(b); // statistical error of <4>   
5068   sixError = fIntFlowCorrelationsVsMHist[2]->GetBinError(b); // statistical error of <6> 
5069   eightError = fIntFlowCorrelationsVsMHist[3]->GetBinError(b); // statistical error of <8> 
5070   // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
5071   if(!fForgetAboutCovariances)
5072   {
5073    wCov24 = fIntFlowCovariancesVsM[0]->GetBinContent(b); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
5074    wCov26 = fIntFlowCovariancesVsM[1]->GetBinContent(b); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
5075    wCov28 = fIntFlowCovariancesVsM[2]->GetBinContent(b); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
5076    wCov46 = fIntFlowCovariancesVsM[3]->GetBinContent(b); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
5077    wCov48 = fIntFlowCovariancesVsM[4]->GetBinContent(b); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
5078    wCov68 = fIntFlowCovariancesVsM[5]->GetBinContent(b); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
5079   }
5080   // Q-cumulants: 
5081   qc2 = 0.; // QC{2}
5082   qc4 = 0.; // QC{4}
5083   qc6 = 0.; // QC{6}
5084   qc8 = 0.; // QC{8}
5085   if(TMath::Abs(two) > 0.){qc2 = two;} 
5086   if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
5087   if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
5088   if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);}  
5089   // Statistical errors of Q-cumulants:       
5090   qc2Error = 0.;
5091   qc4Error = 0.;
5092   qc6Error = 0.;
5093   qc8Error = 0.; 
5094   // Squared statistical errors of Q-cumulants:       
5095   //Double_t qc2ErrorSquared = 0.;
5096   qc4ErrorSquared = 0.;
5097   qc6ErrorSquared = 0.;
5098   qc8ErrorSquared = 0.;    
5099   // Statistical error of QC{2}:              
5100   qc2Error = twoError;                                             
5101   // Statistical error of QC{4}:              
5102   qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
5103                   - 8.*two*wCov24;                     
5104   if(qc4ErrorSquared>0.)
5105   {
5106    qc4Error = pow(qc4ErrorSquared,0.5);
5107   } else 
5108     {
5109      // cout<<"WARNING: Statistical error of QC{4} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
5110     }                                       
5111   // Statistical error of QC{6}:              
5112   qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
5113                   + 81.*pow(two,2.)*pow(fourError,2.)
5114                   + pow(sixError,2.)
5115                   - 162.*two*(4.*pow(two,2.)-four)*wCov24
5116                   + 18.*(4.*pow(two,2.)-four)*wCov26
5117                   - 18.*two*wCov46;                     
5118   if(qc6ErrorSquared>0.)
5119   {
5120    qc6Error = pow(qc6ErrorSquared,0.5);
5121   } else 
5122     {
5123      // cout<<"WARNING: Statistical error of QC{6} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
5124     }                            
5125   // Statistical error of QC{8}:              
5126   qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
5127                   + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
5128                   + 256.*pow(two,2.)*pow(sixError,2.)
5129                   + pow(eightError,2.)
5130                   - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
5131                   + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
5132                   - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
5133                   - 1152.*two*(4.*pow(two,2.)-four)*wCov46
5134                   + 72.*(4.*pow(two,2.)-four)*wCov48
5135                   - 32.*two*wCov68;      
5136   if(qc8ErrorSquared>0.)
5137   {
5138    qc8Error = pow(qc8ErrorSquared,0.5);
5139   } else 
5140     {
5141      // cout<<"WARNING: Statistical error of QC{8} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
5142     }
5143   // Store the results and statistical errors for Q-cumulants:
5144   if(TMath::Abs(qc2)>0.)
5145   {
5146    fIntFlowQcumulantsVsM[0]->SetBinContent(b,qc2);
5147    fIntFlowQcumulantsVsM[0]->SetBinError(b,qc2Error);  
5148   }
5149   if(TMath::Abs(qc4)>0.)
5150   {
5151    fIntFlowQcumulantsVsM[1]->SetBinContent(b,qc4);  
5152    fIntFlowQcumulantsVsM[1]->SetBinError(b,qc4Error);
5153   }
5154   if(TMath::Abs(qc6)>0.)
5155   {
5156    fIntFlowQcumulantsVsM[2]->SetBinContent(b,qc6); 
5157    fIntFlowQcumulantsVsM[2]->SetBinError(b,qc6Error);
5158   }
5159   if(TMath::Abs(qc8)>0.)
5160   {  
5161    fIntFlowQcumulantsVsM[3]->SetBinContent(b,qc8);
5162    fIntFlowQcumulantsVsM[3]->SetBinError(b,qc8Error);
5163   } 
5164   // Rebin in M:
5165   for(Int_t co=0;co<4;co++)
5166   {
5167    if(fIntFlowCorrelationsVsMPro[co]->GetBinEffectiveEntries(b)<2){continue;}
5168    value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
5169    error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
5170    if(error[co]>0.)
5171    {
5172     dSum1[co]+=value[co]/(error[co]*error[co]);
5173     dSum2[co]+=1./(error[co]*error[co]);
5174    }
5175   } // end of for(Int_t co=0;co<4;co++) 
5176  } // end of for(Int_t b=1;b<=nBins;b++)
5177  // Store rebinned Q-cumulants:
5178  for(Int_t co=0;co<4;co++)
5179  {
5180   if(dSum2[co]>0.)
5181   {
5182    fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
5183    fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
5184   }
5185  } // end of for(Int_t co=0;co<4;co++)
5186  
5187 } // end of AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
5188
5189 //================================================================================================================================ 
5190
5191 void AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
5192 {
5193  // a) Calculate the final results for reference flow estimates from Q-cumulants;
5194  // b) Propagate the statistical errors to reference flow estimates from statistical error of Q-cumulants; 
5195  // c) Store the results and statistical errors of reference flow estimates in histogram fIntFlow.
5196  //    Binning of fIntFlow is organized as follows:
5197  //
5198  //            1st bin: v{2,QC}
5199  //            2nd bin: v{4,QC}
5200  //            3rd bin: v{6,QC}
5201  //            4th bin: v{8,QC}
5202  //
5203  
5204  // Reference flow estimates:
5205  Double_t v2 = 0.; // v{2,QC}  
5206  Double_t v4 = 0.; // v{4,QC}  
5207  Double_t v6 = 0.; // v{6,QC}  
5208  Double_t v8 = 0.; // v{8,QC}
5209  // Reference flow's statistical errors:
5210  Double_t v2Error = 0.; // v{2,QC} stat. error 
5211  Double_t v4Error = 0.; // v{4,QC} stat. error
5212  Double_t v6Error = 0.; // v{6,QC} stat. error
5213  Double_t v8Error = 0.; // v{8,QC} stat. error
5214   
5215  // Q-cumulants:
5216  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
5217  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
5218  Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
5219  Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
5220  // Q-cumulants's statistical errors: 
5221  Double_t qc2Error = fIntFlowQcumulants->GetBinError(1); // QC{2} stat. error  
5222  Double_t qc4Error = fIntFlowQcumulants->GetBinError(2); // QC{4} stat. error  
5223  Double_t qc6Error = fIntFlowQcumulants->GetBinError(3); // QC{6} stat. error  
5224  Double_t qc8Error = fIntFlowQcumulants->GetBinError(4); // QC{8} stat. error
5225  // Calculate reference flow estimates from Q-cumulants: 
5226  if(qc2>=0.){v2 = pow(qc2,0.5);} 
5227  if(qc4<=0.){v4 = pow(-1.*qc4,1./4.);} 
5228  if(qc6>=0.){v6 = pow((1./4.)*qc6,1./6.);}
5229  if(qc8<=0.){v8 = pow((-1./33.)*qc8,1./8.);}  
5230  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants:  
5231  if(qc2>0.){v2Error = (1./2.)*pow(qc2,-0.5)*qc2Error;} 
5232  if(qc4<0.){v4Error = (1./4.)*pow(-qc4,-3./4.)*qc4Error;} 
5233  if(qc6>0.){v6Error = (1./6.)*pow(2.,-1./3.)*pow(qc6,-5./6.)*qc6Error;}   
5234  if(qc8<0.){v8Error = (1./8.)*pow(33.,-1./8.)*pow(-qc8,-7./8.)*qc8Error;}   
5235  // Print warnings for the 'wrong sign' cumulants: 
5236  if(TMath::Abs(v2) < 1.e-44)
5237  {
5238   cout<<" WARNING: Wrong sign QC{2}, couldn't calculate v{2,QC} !!!!"<<endl;
5239  }
5240  if(TMath::Abs(v4) < 1.e-44)
5241  {
5242   cout<<" WARNING: Wrong sign QC{4}, couldn't calculate v{4,QC} !!!!"<<endl;
5243  } 
5244  if(TMath::Abs(v6) < 1.e-44)
5245  {
5246   cout<<" WARNING: Wrong sign QC{6}, couldn't calculate v{6,QC} !!!!"<<endl; 
5247  }
5248  if(TMath::Abs(v8) < 1.e-44)
5249  {
5250   cout<<" WARNING: Wrong sign QC{8}, couldn't calculate v{8,QC} !!!!"<<endl;
5251  }                       
5252  // Store the results and statistical errors of integrated flow estimates:
5253  fIntFlow->SetBinContent(1,v2);
5254  fIntFlow->SetBinError(1,v2Error);
5255  fIntFlow->SetBinContent(2,v4);
5256  fIntFlow->SetBinError(2,v4Error);
5257  fIntFlow->SetBinContent(3,v6);
5258  fIntFlow->SetBinError(3,v6Error);
5259  fIntFlow->SetBinContent(4,v8);
5260  fIntFlow->SetBinError(4,v8Error);  
5261   
5262  // Versus multiplicity: 
5263  if(!fCalculateCumulantsVsM){return;} 
5264  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
5265  for(Int_t b=1;b<=nBins;b++)
5266  {
5267   // Q-cumulants:
5268   Double_t qc2VsM = fIntFlowQcumulantsVsM[0]->GetBinContent(b); // QC{2}  
5269   Double_t qc4VsM = fIntFlowQcumulantsVsM[1]->GetBinContent(b); // QC{4}  
5270   Double_t qc6VsM = fIntFlowQcumulantsVsM[2]->GetBinContent(b); // QC{6}  
5271   Double_t qc8VsM = fIntFlowQcumulantsVsM[3]->GetBinContent(b); // QC{8}
5272   // Q-cumulants's statistical errors: 
5273   Double_t qc2ErrorVsM = fIntFlowQcumulantsVsM[0]->GetBinError(b); // QC{2} stat. error  
5274   Double_t qc4ErrorVsM = fIntFlowQcumulantsVsM[1]->GetBinError(b); // QC{4} stat. error  
5275   Double_t qc6ErrorVsM = fIntFlowQcumulantsVsM[2]->GetBinError(b); // QC{6} stat. error  
5276   Double_t qc8ErrorVsM = fIntFlowQcumulantsVsM[3]->GetBinError(b); // QC{8} stat. error
5277   // Reference flow estimates:
5278   Double_t v2VsM = 0.; // v{2,QC}  
5279   Double_t v4VsM = 0.; // v{4,QC}  
5280   Double_t v6VsM = 0.; // v{6,QC}  
5281   Double_t v8VsM = 0.; // v{8,QC}
5282   // Reference flow estimates errors:
5283   Double_t v2ErrorVsM = 0.; // v{2,QC} stat. error  
5284   Double_t v4ErrorVsM = 0.; // v{4,QC} stat. error
5285   Double_t v6ErrorVsM = 0.; // v{6,QC} stat. error  
5286   Double_t v8ErrorVsM = 0.; // v{8,QC} stat. error
5287   // Calculate reference flow estimates from Q-cumulants: 
5288   if(qc2VsM>=0.){v2VsM = pow(qc2VsM,0.5);} 
5289   if(qc4VsM<=0.){v4VsM = pow(-1.*qc4VsM,1./4.);} 
5290   if(qc6VsM>=0.){v6VsM = pow((1./4.)*qc6VsM,1./6.);}
5291   if(qc8VsM<=0.){v8VsM = pow((-1./33.)*qc8VsM,1./8.);}  
5292   // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
5293   if(qc2VsM>0.){v2ErrorVsM = (1./2.)*pow(qc2VsM,-0.5)*qc2ErrorVsM;} 
5294   if(qc4VsM<0.){v4ErrorVsM = (1./4.)*pow(-qc4VsM,-3./4.)*qc4ErrorVsM;} 
5295   if(qc6VsM>0.){v6ErrorVsM = (1./6.)*pow(2.,-1./3.)*pow(qc6VsM,-5./6.)*qc6ErrorVsM;}   
5296   if(qc8VsM<0.){v8ErrorVsM = (1./8.)*pow(33.,-1./8.)*pow(-qc8VsM,-7./8.)*qc8ErrorVsM;}                       
5297   // Store the results and statistical errors of integrated flow estimates:
5298   fIntFlowVsM[0]->SetBinContent(b,v2VsM);
5299   fIntFlowVsM[0]->SetBinError(b,v2ErrorVsM);
5300   fIntFlowVsM[1]->SetBinContent(b,v4VsM);
5301   fIntFlowVsM[1]->SetBinError(b,v4ErrorVsM);
5302   fIntFlowVsM[2]->SetBinContent(b,v6VsM);
5303   fIntFlowVsM[2]->SetBinError(b,v6ErrorVsM);
5304   fIntFlowVsM[3]->SetBinContent(b,v8VsM);
5305   fIntFlowVsM[3]->SetBinError(b,v8ErrorVsM);
5306  } // end of for(Int_t b=1;b<=nBins;b++)
5307  
5308  // 'Rebinned in M' calculation: // to be improved - this can be implemented better:   
5309  // Reference flow estimates:
5310  Double_t v2RebinnedInM = 0.; // v{2,QC}  
5311  Double_t v4RebinnedInM = 0.; // v{4,QC}  
5312  Double_t v6RebinnedInM = 0.; // v{6,QC}  
5313  Double_t v8RebinnedInM = 0.; // v{8,QC}
5314  // Reference flow's statistical errors:
5315  Double_t v2ErrorRebinnedInM = 0.; // v{2,QC} stat. error 
5316  Double_t v4ErrorRebinnedInM = 0.; // v{4,QC} stat. error
5317  Double_t v6ErrorRebinnedInM = 0.; // v{6,QC} stat. error
5318  Double_t v8ErrorRebinnedInM = 0.; // v{8,QC} stat. error
5319  // Q-cumulants:
5320  Double_t qc2RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(1); // QC{2}  
5321  Double_t qc4RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(2); // QC{4}  
5322  Double_t qc6RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(3); // QC{6}  
5323  Double_t qc8RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(4); // QC{8}
5324  // Q-cumulants's statistical errors: 
5325  Double_t qc2ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(1); // QC{2} stat. error  
5326  Double_t qc4ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(2); // QC{4} stat. error  
5327  Double_t qc6ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(3); // QC{6} stat. error  
5328  Double_t qc8ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(4); // QC{8} stat. error
5329  // Calculate reference flow estimates from Q-cumulants: 
5330  if(qc2RebinnedInM>=0.){v2RebinnedInM = pow(qc2RebinnedInM,0.5);} 
5331  if(qc4RebinnedInM<=0.){v4RebinnedInM = pow(-1.*qc4RebinnedInM,1./4.);} 
5332  if(qc6RebinnedInM>=0.){v6RebinnedInM = pow((1./4.)*qc6RebinnedInM,1./6.);}
5333  if(qc8RebinnedInM<=0.){v8RebinnedInM = pow((-1./33.)*qc8RebinnedInM,1./8.);}  
5334  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
5335  if(qc2RebinnedInM>0.){v2ErrorRebinnedInM = (1./2.)*pow(qc2RebinnedInM,-0.5)*qc2ErrorRebinnedInM;} 
5336  if(qc4RebinnedInM<0.){v4ErrorRebinnedInM = (1./4.)*pow(-qc4RebinnedInM,-3./4.)*qc4ErrorRebinnedInM;} 
5337  if(qc6RebinnedInM>0.){v6ErrorRebinnedInM = (1./6.)*pow(2.,-1./3.)*pow(qc6RebinnedInM,-5./6.)*qc6ErrorRebinnedInM;}   
5338  if(qc8RebinnedInM<0.){v8ErrorRebinnedInM = (1./8.)*pow(33.,-1./8.)*pow(-qc8RebinnedInM,-7./8.)*qc8ErrorRebinnedInM;}   
5339  // Print warnings for the 'wrong sign' cumulants: 
5340  if(TMath::Abs(v2RebinnedInM) < 1.e-44)
5341  {
5342   cout<<" WARNING: Wrong sign QC{2} rebinned in M, couldn't calculate v{2,QC} !!!!"<<endl;
5343  }
5344  if(TMath::Abs(v4RebinnedInM) < 1.e-44)
5345  {
5346   cout<<" WARNING: Wrong sign QC{4} rebinned in M, couldn't calculate v{4,QC} !!!!"<<endl;
5347  }
5348  if(TMath::Abs(v6RebinnedInM) < 1.e-44)
5349  {
5350   cout<<" WARNING: Wrong sign QC{6} rebinned in M, couldn't calculate v{6,QC} !!!!"<<endl;
5351  }
5352  if(TMath::Abs(v8RebinnedInM) < 1.e-44)
5353  {
5354   cout<<" WARNING: Wrong sign QC{8} rebinned in M, couldn't calculate v{8,QC} !!!!"<<endl;
5355  }                       
5356  // Store the results and statistical errors of integrated flow estimates:
5357  fIntFlowRebinnedInM->SetBinContent(1,v2RebinnedInM);
5358  fIntFlowRebinnedInM->SetBinError(1,v2ErrorRebinnedInM);
5359  fIntFlowRebinnedInM->SetBinContent(2,v4RebinnedInM);
5360  fIntFlowRebinnedInM->SetBinError(2,v4ErrorRebinnedInM);
5361  fIntFlowRebinnedInM->SetBinContent(3,v6RebinnedInM);
5362  fIntFlowRebinnedInM->SetBinError(3,v6ErrorRebinnedInM);
5363  fIntFlowRebinnedInM->SetBinContent(4,v8RebinnedInM);
5364  fIntFlowRebinnedInM->SetBinError(4,v8ErrorRebinnedInM);    
5365   
5366 } // end of AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
5367
5368 //================================================================================================================================ 
5369
5370 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
5371 {
5372  // Fill in AliFlowCommonHistResults histograms relevant for reference flow.
5373  
5374  // There are two possibilities here:
5375  // a) Store minimum bias reference flow - use SetMinimumBiasReferenceFlow(kTRUE). This result is 
5376  //    biased by the interplay between nonflow correlations and multiplicity fluctuations and is 
5377  //    also stored in local histogram fIntFlow; 
5378  // b) Store reference flow obtained from flow analysis performed at fixed multiplicity and 
5379  //    rebinned only at the end of the day - use SetMinimumBiasReferenceFlow(kFALSE). This result
5380  //    is also stored in local histogram fIntFlowRebinnedInM.
5381  
5382  // Reference flow estimates:
5383  Double_t v[4] = {0.};
5384  // Statistical errors of reference flow estimates:
5385  Double_t vError[4] = {0.};
5386   
5387  for(Int_t b=0;b<4;b++)
5388  {
5389   if(fMinimumBiasReferenceFlow)
5390   { 
5391    v[b] = fIntFlow->GetBinContent(b+1);
5392    vError[b] = fIntFlow->GetBinError(b+1);
5393   } else
5394     {
5395      v[b] = fIntFlowRebinnedInM->GetBinContent(b+1);
5396      vError[b] = fIntFlowRebinnedInM->GetBinError(b+1);
5397     }
5398  } // end of for(Int_t b=0;b<4;b++)
5399   
5400  // Fill AliFlowCommonHistResults histogram:
5401  fCommonHistsResults2nd->FillIntegratedFlow(v[0],vError[0]); // to be improved (hardwired 2nd in the name)  
5402  fCommonHistsResults4th->FillIntegratedFlow(v[1],vError[1]); // to be improved (hardwired 4th in the name)
5403  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)) // to be improved (calculate also 6th and 8th order)
5404  {
5405   fCommonHistsResults6th->FillIntegratedFlow(v[2],vError[2]); // to be improved (hardwired 6th in the name)
5406   fCommonHistsResults8th->FillIntegratedFlow(v[3],vError[3]); // to be improved (hardwired 8th in the name) 
5407  }
5408  
5409 } // end of AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
5410
5411 //================================================================================================================================ 
5412
5413 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
5414 {
5415  // Calculate all correlations needed for integrated flow using particle weights.
5416   
5417  // Remark 1: When particle weights are used the binning of fIntFlowCorrelationAllPro is organized as follows:
5418  //
5419  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
5420  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
5421  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
5422  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
5423  //  5th bin:           ----  EMPTY ----
5424  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
5425  //  7th bin: <3>_{3n|2n,1n} = ...
5426  //  8th bin: <3>_{4n|2n,2n} = ...
5427  //  9th bin: <3>_{4n|3n,1n} = ...
5428  // 10th bin:           ----  EMPTY ----
5429  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
5430  // 12th bin: <4>_{2n,1n|2n,1n} = ...
5431  // 13th bin: <4>_{2n,2n|2n,2n} = ...
5432  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
5433  // 15th bin: <4>_{3n,1n|3n,1n} = ...
5434  // 16th bin: <4>_{3n,1n|2n,2n} = ...
5435  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
5436  // 18th bin:           ----  EMPTY ----
5437  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
5438  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
5439  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
5440  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
5441  // 23rd bin:           ----  EMPTY ----
5442  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
5443  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
5444  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
5445  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
5446  // 28th bin:           ----  EMPTY ----
5447  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
5448  // 30th bin:           ----  EMPTY ----
5449  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
5450  
5451  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
5452  // fIntFlowExtraCorrelationsPro binning of which is organized as follows:
5453  
5454  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
5455  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
5456  
5457  // multiplicity (number of particles used to determine the reaction plane)
5458  Double_t dMult = (*fSpk)(0,0);
5459  
5460  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5461  Double_t dReQ1n1k = (*fReQ)(0,1);
5462  Double_t dReQ2n2k = (*fReQ)(1,2);
5463  Double_t dReQ3n3k = (*fReQ)(2,3);
5464  Double_t dReQ4n4k = (*fReQ)(3,4);
5465  Double_t dReQ1n3k = (*fReQ)(0,3);
5466  Double_t dImQ1n1k = (*fImQ)(0,1);
5467  Double_t dImQ2n2k = (*fImQ)(1,2);
5468  Double_t dImQ3n3k = (*fImQ)(2,3);
5469  Double_t dImQ4n4k = (*fImQ)(3,4);
5470  Double_t dImQ1n3k = (*fImQ)(0,3);
5471
5472  // dMs are variables introduced in order to simplify some Eqs. bellow:
5473  //..............................................................................................
5474  Double_t dM11 = (*fSpk)(1,1)-(*fSpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
5475  Double_t dM22 = (*fSpk)(1,2)-(*fSpk)(0,4); // dM22 = sum_{i,j=1,i!=j}^M w_i^2 w_j^2
5476  Double_t dM33 = (*fSpk)(1,3)-(*fSpk)(0,6); // dM33 = sum_{i,j=1,i!=j}^M w_i^3 w_j^3
5477  Double_t dM44 = (*fSpk)(1,4)-(*fSpk)(0,8); // dM44 = sum_{i,j=1,i!=j}^M w_i^4 w_j^4
5478  Double_t dM31 = (*fSpk)(0,3)*(*fSpk)(0,1)-(*fSpk)(0,4); // dM31 = sum_{i,j=1,i!=j}^M w_i^3 w_j
5479  Double_t dM211 = (*fSpk)(0,2)*(*fSpk)(1,1)-2.*(*fSpk)(0,3)*(*fSpk)(0,1)
5480                 - (*fSpk)(1,2)+2.*(*fSpk)(0,4); // dM211 = sum_{i,j,k=1,i!=j!=k}^M w_i^2 w_j w_k
5481  Double_t dM1111 = (*fSpk)(3,1)-6.*(*fSpk)(0,2)*(*fSpk)(1,1)  
5482                  + 8.*(*fSpk)(0,3)*(*fSpk)(0,1)
5483                  + 3.*(*fSpk)(1,2)-6.*(*fSpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
5484  //..............................................................................................
5485
5486  // 2-particle correlations:
5487  Double_t two1n1nW1W1 = 0.; // <w1 w2 cos(n*(phi1-phi2))>
5488  Double_t two2n2nW2W2 = 0.; // <w1^2 w2^2 cos(2n*(phi1-phi2))>
5489  Double_t two3n3nW3W3 = 0.; // <w1^3 w2^3 cos(3n*(phi1-phi2))>
5490  Double_t two4n4nW4W4 = 0.; // <w1^4 w2^4 cos(4n*(phi1-phi2))>
5491  if(dMult>1) 
5492  { 
5493   if(dM11)
5494   {
5495    two1n1nW1W1 = (pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSpk)(0,2))/dM11;    
5496    // average correlation <w1 w2 cos(n*(phi1-phi2))> for single event: 
5497    fIntFlowCorrelationsEBE->SetBinContent(1,two1n1nW1W1);
5498    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,dM11);
5499    // average correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
5500    fIntFlowCorrelationsPro->Fill(0.5,two1n1nW1W1,dM11);  
5501    // average squared correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
5502    fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1nW1W1*two1n1nW1W1,dM11); 
5503    fIntFlowCorrelationsAllPro->Fill(0.5,two1n1nW1W1,dM11);   
5504   }
5505   if(dM22)
5506   {
5507    two2n2nW2W2 = (pow(dReQ2n2k,2)+pow(dImQ2n2k,2)-(*fSpk)(0,4))/dM22; 
5508    // ...
5509    // average correlation <w1^2 w2^2 cos(2n*(phi1-phi2))> for all events:
5510    fIntFlowCorrelationsAllPro->Fill(1.5,two2n2nW2W2,dM22);   
5511   }
5512   if(dM33)
5513   {
5514    two3n3nW3W3 = (pow(dReQ3n3k,2)+pow(dImQ3n3k,2)-(*fSpk)(0,6))/dM33;
5515    // ...
5516    // average correlation <w1^3 w2^3 cos(3n*(phi1-phi2))> for all events:
5517    fIntFlowCorrelationsAllPro->Fill(2.5,two3n3nW3W3,dM33);   
5518   }
5519   if(dM44)
5520   {
5521    two4n4nW4W4 = (pow(dReQ4n4k,2)+pow(dImQ4n4k,2)-(*fSpk)(0,8))/dM44; 
5522    // ...
5523    // average correlation <w1^4 w2^4 cos(4n*(phi1-phi2))> for all events:
5524    fIntFlowCorrelationsAllPro->Fill(3.5,two4n4nW4W4,dM44);      
5525   }
5526  } // end of if(dMult>1) 
5527
5528  // extra 2-particle correlations:
5529  Double_t two1n1nW3W1 = 0.; // <w1^3 w2 cos(n*(phi1-phi2))>
5530  Double_t two1n1nW1W1W2 = 0.; // <w1 w2 w3^2 cos(n*(phi1-phi2))> 
5531  if(dMult>1) 
5532  {    
5533   if(dM31)
5534   {
5535    two1n1nW3W1 = (dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k-(*fSpk)(0,4))/dM31; 
5536    fIntFlowExtraCorrelationsPro->Fill(0.5,two1n1nW3W1,dM31);  
5537   } 
5538   if(dM211)
5539   {
5540    two1n1nW1W1W2 = ((*fSpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSpk)(0,2))
5541                  - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k
5542                  - (*fSpk)(0,4)))/dM211;
5543    fIntFlowExtraCorrelationsPro->Fill(1.5,two1n1nW1W1W2,dM211);  
5544   }  
5545  } // end of if(dMult>1)
5546  //..............................................................................................
5547  
5548  //..............................................................................................
5549  // 3-particle correlations:
5550  Double_t three2n1n1nW2W1W1 = 0.; // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
5551  
5552  if(dMult>2) 
5553  { 
5554   if(dM211)
5555   {                                                       
5556    three2n1n1nW2W1W1 = (pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k
5557                      - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
5558                      - pow(dReQ2n2k,2)-pow(dImQ2n2k,2)
5559                      + 2.*(*fSpk)(0,4))/dM211;                                                                               
5560    fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1nW2W1W1,dM211);
5561   } 
5562  } // end of if(dMult>2) 
5563  //..............................................................................................
5564  
5565  //..............................................................................................
5566  // 4-particle correlations:
5567  Double_t four1n1n1n1nW1W1W1W1 = 0.; // <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
5568  if(dMult>3) 
5569  { 
5570   if(dM1111)
5571   {      
5572    four1n1n1n1nW1W1W1W1 = (pow(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.),2)
5573                         - 2.*(pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k)
5574                         + 8.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
5575                         + (pow(dReQ2n2k,2)+pow(dImQ2n2k,2))
5576                         - 4.*(*fSpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
5577                         - 6.*(*fSpk)(0,4)+2.*(*fSpk)(1,2))/dM1111;  
5578                           
5579    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for single event: 
5580    fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1nW1W1W1W1);
5581    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,dM1111);
5582    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
5583    fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1,dM1111);   
5584    // average squared correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
5585    fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1*four1n1n1n1nW1W1W1W1,dM1111);      
5586    fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1nW1W1W1W1,dM1111);   
5587   } 
5588  } // end of if(dMult>3) 
5589  //..............................................................................................
5590  
5591 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
5592
5593 //================================================================================================================================
5594
5595 void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
5596 {
5597  // Initialize all arrays used to calculate integrated flow.
5598  
5599  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5600  {
5601   fIntFlowCorrectionTermsForNUAEBE[sc] = NULL;
5602   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc] = NULL;
5603   fIntFlowCorrectionTermsForNUAPro[sc] = NULL;
5604   fIntFlowCorrectionTermsForNUAHist[sc] = NULL;
5605   for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
5606   {
5607    fIntFlowCorrectionTermsForNUAVsMPro[sc][ci] = NULL;
5608   }
5609   for(Int_t power=0;power<2;power++) // linear or quadratic 
5610   {
5611    fIntFlowSumOfEventWeightsNUA[sc][power] = NULL;
5612   }
5613  }
5614  for(Int_t power=0;power<2;power++) // linear or quadratic 
5615  {
5616   fIntFlowSumOfEventWeights[power] = NULL;    
5617  }
5618  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))
5619  {
5620   fPrintFinalResults[i] = kTRUE;
5621  }
5622  for(Int_t ci=0;ci<4;ci++) // correlation index or cumulant order
5623  {
5624   fIntFlowCorrelationsVsMPro[ci] = NULL;
5625   fIntFlowSquaredCorrelationsVsMPro[ci] = NULL;
5626   fIntFlowCorrelationsVsMHist[ci] = NULL;
5627   fIntFlowQcumulantsVsM[ci] = NULL;
5628   fIntFlowVsM[ci] = NULL;
5629   fIntFlowDetectorBiasVsM[ci] = NULL;
5630   for(Int_t lc=0;lc<2;lc++)
5631   {
5632    fIntFlowSumOfEventWeightsVsM[ci][lc] = NULL;
5633   }
5634  } 
5635  for(Int_t pi=0;pi<6;pi++) // product or covariance index
5636  {
5637   fIntFlowProductOfCorrelationsVsMPro[pi] = NULL;
5638   fIntFlowCovariancesVsM[pi] = NULL;
5639   fIntFlowSumOfProductOfEventWeightsVsM[pi] = NULL;
5640  } 
5641  for(Int_t ci=0;ci<64;ci++) // correlation index for all correlations vs M profiles (to be improved - hardwired 64)
5642  {
5643   fIntFlowCorrelationsAllVsMPro[ci] = NULL;
5644  } 
5645
5646 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
5647
5648 //================================================================================================================================
5649
5650 void AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5651 {
5652  // Initialize all arrays needed to calculate differential flow.
5653  //  a) Initialize lists holding profiles;
5654  //  b) Initialize lists holding histograms;
5655  //  c) Initialize event-by-event quantities;
5656  //  d) Initialize profiles;
5657  //  e) Initialize histograms holding final results.
5658  
5659  // a) Initialize lists holding profiles;
5660  for(Int_t t=0;t<2;t++) // type (RP, POI)
5661  {
5662   for(Int_t pe=0;pe<2;pe++) // pt or eta
5663   {
5664    fDiffFlowCorrelationsProList[t][pe] = NULL;
5665    fDiffFlowProductOfCorrelationsProList[t][pe] = NULL;
5666    fDiffFlowCorrectionsProList[t][pe] = NULL;
5667   }
5668   // 2D:
5669   f2DDiffFlowCorrelationsProList[t] = NULL;
5670  }  
5671  
5672  // b) Initialize lists holding histograms;
5673  for(Int_t t=0;t<2;t++) // type (RP, POI)
5674  {
5675   for(Int_t pe=0;pe<2;pe++) // pt or eta
5676   {
5677    fDiffFlowCorrelationsHistList[t][pe] = NULL;
5678    for(Int_t power=0;power<2;power++)
5679    {
5680     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = NULL;
5681    } // end of for(Int_t power=0;power<2;power++)  
5682    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = NULL;
5683    fDiffFlowCorrectionsHistList[t][pe] = NULL;
5684    fDiffFlowCovariancesHistList[t][pe] = NULL;
5685    fDiffFlowCumulantsHistList[t][pe] = NULL;
5686    fDiffFlowDetectorBiasHistList[t][pe] = NULL;
5687    fDiffFlowHistList[t][pe] = NULL;
5688   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5689  } // enf of for(Int_t t=0;t<2;t++) // type (RP, POI) 
5690  
5691  // c) Initialize event-by-event quantities:
5692  // 1D:
5693  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5694  {
5695   for(Int_t pe=0;pe<2;pe++) // pt or eta
5696   { 
5697    for(Int_t m=0;m<4;m++) // multiple of harmonic
5698    {
5699     for(Int_t k=0;k<9;k++) // power of weight
5700     {
5701      fReRPQ1dEBE[t][pe][m][k] = NULL;
5702      fImRPQ1dEBE[t][pe][m][k] = NULL;
5703      fs1dEBE[t][pe][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5704     }   
5705    }
5706   }
5707  }
5708  // 1D:
5709  for(Int_t t=0;t<2;t++) // type (RP or POI)
5710  {
5711   for(Int_t pe=0;pe<2;pe++) // pt or eta
5712   { 
5713    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5714    {
5715     for(Int_t cti=0;cti<9;cti++) // correction term index
5716     {
5717      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = NULL;
5718     }   
5719    }
5720   }
5721  }
5722  // 2D:  
5723  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5724  {
5725   for(Int_t m=0;m<4;m++) // multiple of harmonic
5726   {
5727    for(Int_t k=0;k<9;k++) // power of weight
5728    {
5729     fReRPQ2dEBE[t][m][k] = NULL;
5730     fImRPQ2dEBE[t][m][k] = NULL;
5731     fs2dEBE[t][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5732    }   
5733   }
5734  }
5735  
5736  // d) Initialize profiles:
5737  for(Int_t t=0;t<2;t++) // type: RP or POI
5738  { 
5739   for(Int_t pe=0;pe<2;pe++) // pt or eta
5740   {
5741    for(Int_t ci=0;ci<4;ci++) // correlation index
5742    {
5743     fDiffFlowCorrelationsPro[t][pe][ci] = NULL;
5744     fDiffFlowSquaredCorrelationsPro[t][pe][ci] = NULL;
5745    } // end of for(Int_t ci=0;ci<4;ci++)   
5746    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5747    {
5748     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5749     {
5750      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = NULL;
5751     } // end of for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5752    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index  
5753    // correction terms for nua:
5754    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5755    {
5756     for(Int_t cti=0;cti<9;cti++) // correction term index
5757     {
5758      fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = NULL;
5759     }   
5760    }
5761    // other differential correlators:
5762    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5763    {
5764     for(Int_t ci=0;ci<1;ci++) // correction term index
5765     {
5766      fOtherDiffCorrelators[t][pe][sc][ci] = NULL;
5767     }   
5768    }
5769   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5770   for(Int_t ci=0;ci<4;ci++) // correlation index
5771   {
5772    f2DDiffFlowCorrelationsPro[t][ci] = NULL;
5773   }
5774  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5775   
5776  // e) Initialize histograms holding final results.
5777  for(Int_t t=0;t<2;t++) // type: RP or POI
5778  { 
5779   for(Int_t pe=0;pe<2;pe++) // pt or eta
5780   {
5781    for(Int_t ci=0;ci<4;ci++) // correlation index
5782    {
5783     fDiffFlowCorrelationsHist[t][pe][ci] = NULL;
5784     fDiffFlowCumulants[t][pe][ci] = NULL;
5785     fDiffFlowDetectorBias[t][pe][ci] = NULL;
5786     fDiffFlow[t][pe][ci] = NULL;
5787    } // end of for(Int_t ci=0;ci<4;ci++)    
5788    for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5789    {
5790     fDiffFlowCovariances[t][pe][covarianceIndex] = NULL;     
5791    } // end of for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5792    // correction terms for nua:
5793    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5794    {
5795     for(Int_t cti=0;cti<9;cti++) // correction term index
5796     {
5797      fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = NULL;
5798     }   
5799    }
5800   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5801   for(Int_t ci=0;ci<4;ci++) // correlation index
5802   {
5803    f2DDiffFlowCumulants[t][ci] = NULL;
5804    f2DDiffFlow[t][ci] = NULL;
5805   }
5806  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5807  
5808  // sum of event weights for reduced correlations:
5809  for(Int_t t=0;t<2;t++) // type = RP or POI
5810  {
5811   for(Int_t pe=0;pe<2;pe++) // pt or eta
5812   {
5813    for(Int_t p=0;p<2;p++) // power of weight is 1 or 2
5814    {
5815     for(Int_t ew=0;ew<4;ew++) // event weight index for reduced correlations
5816     {
5817      fDiffFlowSumOfEventWeights[t][pe][p][ew] = NULL;
5818     } 
5819    }   
5820   }
5821  }
5822  // product of event weights for both types of correlations:
5823  for(Int_t t=0;t<2;t++) // type = RP or POI
5824  {
5825   for(Int_t pe=0;pe<2;pe++) // pt or eta
5826   {
5827    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5828    {
5829     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5830     {
5831      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = NULL;
5832     } 
5833    }   
5834   }
5835  }
5836     
5837 } // end of AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5838
5839 //================================================================================================================================
5840
5841 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, TString ptOrEta)
5842 {
5843  // Calculate differential flow cumulants from measured multiparticle correlations.
5844  
5845  // REMARK: Cumulants calculated in this method are NOT corrected for non-uniform acceptance. 
5846  // This correction, if enabled via setter SetApplyCorrectionForNUA(Bool_t), is applied 
5847  // in the method CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
5848  
5849  Int_t t = 0;
5850  Int_t pe = 0;
5851
5852  if(type == "RP")
5853  {
5854   t = 0;
5855  } else if(type == "POI")
5856    {
5857     t = 1;
5858    } 
5859      
5860  if(ptOrEta == "Pt")
5861  {
5862   pe = 0;
5863  } else if(ptOrEta == "Eta")
5864    {
5865     pe = 1;
5866    } 
5867      
5868  // Common:
5869  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5870  
5871  // Correlation <<2>>: 
5872  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
5873  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
5874  
5875  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5876  {
5877   // Reduced correlations:   
5878   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
5879   Double_t twoPrimeError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b); // stat. error of <<2'>>
5880   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
5881   Double_t fourPrimeError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b); // stat. error of <<4'>>
5882   // Covariances:
5883   Double_t wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b); // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
5884   Double_t wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b); // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
5885   Double_t wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b); // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
5886   // QC{2'}:
5887   Double_t qc2Prime = twoPrime; // QC{2'}
5888   Double_t qc2PrimeError = twoPrimeError; // stat. error of QC{2'}
5889   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime); 
5890   fDiffFlowCumulants[t][pe][0]->SetBinError(b,qc2PrimeError); 
5891   // QC{4'}:
5892   Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5893   Double_t qc4PrimeError = 0.; // stat. error of QC{4'}
5894   Double_t qc4PrimeErrorSquared = 4.*pow(twoPrime,2.)*pow(twoError,2.)
5895                                 + 4.*pow(two,2.)*pow(twoPrimeError,2.)
5896                                 + pow(fourPrimeError,2.)
5897                                 + 8.*two*twoPrime*wCovTwoTwoReduced
5898                                 - 4.*twoPrime*wCovTwoFourReduced
5899                                 - 4.*two*wCovTwoReducedFourReduced;
5900   if(qc4PrimeErrorSquared>0.)
5901   {
5902    qc4PrimeError = pow(qc4PrimeErrorSquared,0.5);
5903   } 
5904   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime); 
5905   fDiffFlowCumulants[t][pe][1]->SetBinError(b,qc4PrimeError); 
5906  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5907     
5908 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, Bool_t useParticleWeights, TString eventWeights); 
5909
5910 //================================================================================================================================
5911
5912 void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCumulants(TString type)
5913 {
5914  // Calculate 2D differential cumulants.
5915  
5916  // Remark: correction for detector effects and error propagation not implemented yet for 2D differential cumulants.
5917  
5918  Int_t t = 0;
5919
5920  if(type == "RP")
5921  {
5922   t = 0;
5923  } else if(type == "POI")
5924    {
5925     t = 1;
5926    }
5927        
5928  // Reference correlation <<2>>: 
5929  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
5930  
5931  // Looping over all (pt,eta) bins and calculating differential flow cumulants: 
5932  for(Int_t p=1;p<=fnBinsPt;p++)
5933  {
5934   for(Int_t e=1;e<=fnBinsEta;e++)
5935   {
5936    // Reduced correlations:   
5937    Double_t twoPrime = f2DDiffFlowCorrelationsPro[t][0]->GetBinContent(f2DDiffFlowCorrelationsPro[t][0]->GetBin(p,e)); // <<2'>>(pt,eta)
5938    Double_t fourPrime = f2DDiffFlowCorrelationsPro[t][1]->GetBinContent(f2DDiffFlowCorrelationsPro[t][1]->GetBin(p,e)); // <<4'>>(pt,eta)
5939    // Cumulants:
5940    Double_t qc2Prime = twoPrime; // QC{2'} = <<2'>>   
5941    f2DDiffFlowCumulants[t][0]->SetBinContent(f2DDiffFlowCumulants[t][0]->GetBin(p,e),qc2Prime); 
5942    Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5943    f2DDiffFlowCumulants[t][1]->SetBinContent(f2DDiffFlowCumulants[t][1]->GetBin(p,e),qc4Prime); 
5944   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5945  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5946  
5947 } // end of void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCumulants(TString type)
5948
5949 //================================================================================================================================
5950
5951 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
5952 {
5953  // Calculate final results for integrated flow of RPs and POIs. 
5954   
5955  // to be improved - check if the integrated flow calculation here is actually correct 
5956   
5957  Int_t t = 0; // RP = 0, POI = 1
5958
5959  if(type == "RP")
5960  {
5961   t = 0;
5962  } else if(type == "POI")
5963    {
5964     t = 1;
5965    }
5966      
5967  // pt yield:    
5968  TH1F *yield2ndPt = NULL;
5969  TH1F *yield4thPt = NULL;
5970  TH1F *yield6thPt = NULL;
5971  TH1F *yield8thPt = NULL;
5972  
5973  if(type == "POI")
5974  {
5975   if(fFillMultipleControlHistograms)
5976   {
5977    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtPOI())->Clone();
5978    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtPOI())->Clone();
5979    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtPOI())->Clone();
5980    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtPOI())->Clone();  
5981   } else
5982     {
5983      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5984      yield4thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5985      yield6thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
5986      yield8thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();     
5987     }
5988  } 
5989  else if(type == "RP")
5990  {
5991   if(fFillMultipleControlHistograms)
5992   {
5993    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtRP())->Clone();
5994    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtRP())->Clone();
5995    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtRP())->Clone();
5996    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtRP())->Clone();  
5997   } else
5998     {
5999      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
6000      yield4thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
6001      yield6thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
6002      yield8thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();    
6003     } 
6004  } 
6005  
6006  if(!yield2ndPt){return;}
6007  if(!yield4thPt){return;}
6008  if(!yield6thPt){return;}
6009  if(!yield8thPt){return;} 
6010
6011  Int_t nBinsPt = yield2ndPt->GetNbinsX();
6012  
6013  TH1D *flow2ndPt = NULL;
6014  TH1D *flow4thPt = NULL;
6015  TH1D *flow6thPt = NULL;
6016  TH1D *flow8thPt = NULL;
6017  
6018  // to be improved (hardwired pt index)
6019  flow2ndPt = (TH1D*)fDiffFlow[t][0][0]->Clone();
6020  flow4thPt = (TH1D*)fDiffFlow[t][0][1]->Clone();
6021  flow6thPt = (TH1D*)fDiffFlow[t][0][2]->Clone();
6022  flow8thPt = (TH1D*)fDiffFlow[t][0][3]->Clone(); 
6023
6024  if(!flow2ndPt){return;}
6025  if(!flow4thPt){return;}
6026  if(!flow6thPt){return;}
6027  if(!flow8thPt){return;} 
6028    
6029  Double_t dvn2nd = 0., dvn4th = 0., dvn6th = 0., dvn8th = 0.; // differential flow
6030  Double_t dErrvn2nd = 0., dErrvn4th = 0., dErrvn6th = 0., dErrvn8th = 0.; // error on differential flow
6031  
6032  Double_t dVn2nd = 0., dVn4th = 0., dVn6th = 0., dVn8th = 0.; // integrated flow 
6033  Double_t dErrVn2nd = 0., dErrVn4th = 0., dErrVn6th = 0., dErrVn8th = 0.; // error on integrated flow
6034
6035  Double_t dYield2nd = 0., dYield4th = 0., dYield6th = 0., dYield8th = 0.; // pt yield 
6036  Double_t dSum2nd = 0., dSum4th = 0., dSum6th = 0., dSum8th = 0.; // needed for normalizing integrated flow
6037  
6038  // looping over pt bins:
6039  for(Int_t p=1;p<nBinsPt+1;p++)
6040  {
6041   dvn2nd = flow2ndPt->GetBinContent(p);
6042   dvn4th = flow4thPt->GetBinContent(p);
6043   dvn6th = flow6thPt->GetBinContent(p);
6044   dvn8th = flow8thPt->GetBinContent(p);
6045   
6046   dErrvn2nd = flow2ndPt->GetBinError(p);
6047   dErrvn4th = flow4thPt->GetBinError(p);
6048   dErrvn6th = flow6thPt->GetBinError(p);
6049   dErrvn8th = flow8thPt->GetBinError(p);
6050
6051   dYield2nd = yield2ndPt->GetBinContent(p);  
6052   dYield4th = yield4thPt->GetBinContent(p);
6053   dYield6th = yield6thPt->GetBinContent(p);
6054   dYield8th = yield8thPt->GetBinContent(p);
6055   
6056   dVn2nd += dvn2nd*dYield2nd;
6057   dVn4th += dvn4th*dYield4th;
6058   dVn6th += dvn6th*dYield6th;
6059   dVn8th += dvn8th*dYield8th;
6060   
6061   dSum2nd += dYield2nd;
6062   dSum4th += dYield4th;
6063   dSum6th += dYield6th;
6064   dSum8th += dYield8th;
6065   
6066   dErrVn2nd += dYield2nd*dYield2nd*dErrvn2nd*dErrvn2nd; // ro be improved (check this relation)
6067   dErrVn4th += dYield4th*dYield4th*dErrvn4th*dErrvn4th;
6068   dErrVn6th += dYield6th*dYield6th*dErrvn6th*dErrvn6th;
6069   dErrVn8th += dYield8th*dYield8th*dErrvn8th*dErrvn8th;
6070     
6071  } // end of for(Int_t p=1;p<nBinsPt+1;p++)
6072
6073  // normalizing the results for integrated flow:
6074  if(dSum2nd) 
6075  {
6076   dVn2nd /= dSum2nd;
6077   dErrVn2nd /= (dSum2nd*dSum2nd);
6078   dErrVn2nd = TMath::Sqrt(dErrVn2nd);
6079  } 
6080  if(dSum4th) 
6081  {
6082   dVn4th /= dSum4th;
6083   dErrVn4th /= (dSum4th*dSum4th);
6084   dErrVn4th = TMath::Sqrt(dErrVn4th);
6085  } 
6086  //if(dSum6th) dVn6th/=dSum6th;
6087  //if(dSum8th) dVn8th/=dSum8th;
6088   
6089  // storing the results for integrated flow in common histos: (to be improved: new method for this?)
6090  if(type == "POI")
6091  {
6092   fCommonHistsResults2nd->FillIntegratedFlowPOI(dVn2nd,dErrVn2nd); 
6093   fCommonHistsResults4th->FillIntegratedFlowPOI(dVn4th,dErrVn4th); 
6094   fCommonHistsResults6th->FillIntegratedFlowPOI(dVn6th,0.); // to be improved (errors)
6095   fCommonHistsResults8th->FillIntegratedFlowPOI(dVn8th,0.); // to be improved (errors)
6096  }
6097  else if (type == "RP")
6098  {
6099   fCommonHistsResults2nd->FillIntegratedFlowRP(dVn2nd,dErrVn2nd); 
6100   fCommonHistsResults4th->FillIntegratedFlowRP(dVn4th,dErrVn4th);
6101   fCommonHistsResults6th->FillIntegratedFlowRP(dVn6th,0.); // to be improved (errors)
6102   fCommonHistsResults8th->FillIntegratedFlowRP(dVn8th,0.); // to be improved (errors)
6103  }
6104  
6105  delete flow2ndPt;
6106  delete flow4thPt;
6107  //delete flow6thPt;
6108  //delete flow8thPt;
6109  
6110  delete yield2ndPt;
6111  delete yield4thPt;
6112  delete yield6thPt;
6113  delete yield8thPt;
6114            
6115 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
6116
6117 //================================================================================================================================
6118
6119 void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
6120 {
6121  // Initialize all arrays used for distributions.
6122  
6123  // a) Initialize arrays of histograms used to hold distributions of correlations; 
6124  // b) Initialize array to hold min and max values of correlations.
6125  
6126  // a) Initialize arrays of histograms used to hold distributions of correlations:
6127  for(Int_t di=0;di<4;di++) // distribution index
6128  {
6129   fDistributions[di] = NULL;
6130  }
6131  
6132  // b) Initialize default min and max values of correlations:
6133  //    (Remark: The default values bellow were chosen for v2=5% and M=500)
6134  fMinValueOfCorrelation[0] = -0.01; // <2>_min 
6135  fMaxValueOfCorrelation[0] = 0.04; // <2>_max 
6136  fMinValueOfCorrelation[1] = -0.00002; // <4>_min 
6137  fMaxValueOfCorrelation[1] = 0.00015; // <4>_max  
6138  fMinValueOfCorrelation[2] = -0.0000003; // <6>_min 
6139  fMaxValueOfCorrelation[2] = 0.0000006; // <6>_max  
6140  fMinValueOfCorrelation[3] = -0.000000006; // <8>_min 
6141  fMaxValueOfCorrelation[3] = 0.000000003; // <8>_max 
6142  
6143 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
6144
6145 //================================================================================================================================
6146
6147 void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
6148 {
6149  // Initialize all arrays used for various unclassified objects.
6150  
6151  for(Int_t p=0;p<4;p++) // [v_min,v_max,refMult_min,refMult_max]
6152  {
6153   fPhiDistributionForOneEventSettings[p] = 0.;
6154  } 
6155    
6156 } //  end of void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
6157
6158 //================================================================================================================================
6159
6160 void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
6161 {
6162  // a) Book profile to hold all flags for distributions of correlations;
6163  // b) Book all histograms to hold distributions of correlations.
6164  
6165  TString correlationIndex[4] = {"<2>","<4>","<6>","<8>"}; // to be improved (should I promote this to data members?)
6166   
6167  // a) Book profile to hold all flags for distributions of correlations:
6168  TString distributionsFlagsName = "fDistributionsFlags";
6169  distributionsFlagsName += fAnalysisLabel->Data();
6170  fDistributionsFlags = new TProfile(distributionsFlagsName.Data(),"Flags for Distributions of Correlations",9,0,9);
6171  fDistributionsFlags->SetTickLength(-0.01,"Y");
6172  fDistributionsFlags->SetMarkerStyle(25);
6173  fDistributionsFlags->SetLabelSize(0.05);
6174  fDistributionsFlags->SetLabelOffset(0.02,"Y");
6175  fDistributionsFlags->GetXaxis()->SetBinLabel(1,"Store or not?");
6176  fDistributionsFlags->GetXaxis()->SetBinLabel(2,"<2>_{min}");
6177  fDistributionsFlags->GetXaxis()->SetBinLabel(3,"<2>_{max}");
6178  fDistributionsFlags->GetXaxis()->SetBinLabel(4,"<4>_{min}");
6179  fDistributionsFlags->GetXaxis()->SetBinLabel(5,"<4>_{max}");
6180  fDistributionsFlags->GetXaxis()->SetBinLabel(6,"<6>_{min}");
6181  fDistributionsFlags->GetXaxis()->SetBinLabel(7,"<6>_{max}");
6182  fDistributionsFlags->GetXaxis()->SetBinLabel(8,"<8>_{min}");
6183  fDistributionsFlags->GetXaxis()->SetBinLabel(9,"<8>_{max}");
6184  fDistributionsList->Add(fDistributionsFlags);
6185  
6186  // b) Book all histograms to hold distributions of correlations.
6187  if(fStoreDistributions)
6188  { 
6189   TString distributionsName = "fDistributions";
6190   distributionsName += fAnalysisLabel->Data();
6191   for(Int_t di=0;di<4;di++) // distribution index
6192   {
6193    fDistributions[di] = new TH1D(Form("Distribution of %s",correlationIndex[di].Data()),Form("Distribution of %s",correlationIndex[di].Data()),10000,fMinValueOfCorrelation[di],fMaxValueOfCorrelation[di]); 
6194    fDistributions[di]->SetXTitle(correlationIndex[di].Data());
6195    fDistributionsList->Add(fDistributions[di]);
6196   } // end of for(Int_t di=0;di<4;di++) // distribution index
6197  } // end of if(fStoreDistributions)
6198  
6199 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
6200
6201 //================================================================================================================================
6202
6203 void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6204 {
6205  // Book all objects for various unclassified quantities.
6206  
6207  if(!fStorePhiDistributionForOneEvent){return;}
6208  
6209  // a) Book histogram holding phi distribution for single event to illustrate flow.
6210  
6211  // a) Book histogram holding phi distribution for single event to illustrate flow:
6212  fPhiDistributionForOneEvent = new TH1D("fPhiDistributionForOneEvent","",360,0.,TMath::TwoPi());
6213  fPhiDistributionForOneEvent->GetXaxis()->SetTitle("#phi");
6214  fVariousList->Add(fPhiDistributionForOneEvent);
6215  
6216 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6217
6218 //================================================================================================================================
6219
6220 void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6221 {
6222  // Store all flags for distributiuons of correlations in profile fDistributionsFlags.
6223  
6224  if(!fDistributionsFlags)
6225  {
6226   cout<<"WARNING: fDistributionsFlags is NULL in AFAWQC::SDF() !!!!"<<endl;
6227   exit(0);
6228  } 
6229
6230  fDistributionsFlags->Fill(0.5,(Int_t)fStoreDistributions); // histos with distributions of correlations stored or not in the output file
6231  // store min and max values of correlations:
6232  for(Int_t di=0;di<4;di++) // distribution index
6233  {
6234   fDistributionsFlags->Fill(1.5+2.*(Double_t)di,fMinValueOfCorrelation[di]);
6235   fDistributionsFlags->Fill(2.5+2.*(Double_t)di,fMaxValueOfCorrelation[di]);
6236  }
6237      
6238 } // end of void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6239
6240 //================================================================================================================================
6241
6242 void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6243 {
6244  // Store distributions of correlations.
6245  
6246  if(!(fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE))
6247  {
6248   cout<<"WARNING: fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE"<<endl; 
6249   cout<<"         is NULL in AFAWQC::SDOC() !!!!"<<endl;
6250   exit(0);
6251  }
6252
6253  for(Int_t di=0;di<4;di++) // distribution index
6254  {
6255   if(!fDistributions[di])
6256   { 
6257    cout<<"WARNING: fDistributions[di] is NULL in AFAWQC::SDOC() !!!!"<<endl;
6258    cout<<"di = "<<di<<endl;
6259    exit(0);
6260   } else 
6261     {
6262      fDistributions[di]->Fill(fIntFlowCorrelationsEBE->GetBinContent(di+1),fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(di+1)); 
6263     } 
6264  } // end of for(Int_t di=0;di<4;di++) // distribution index
6265
6266 } // end of void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6267
6268 //================================================================================================================================
6269
6270 void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6271 {
6272  // Book and nest all lists nested in the base list fHistList.
6273  //  a) Book and nest lists for integrated flow;
6274  //  b) Book and nest lists for differential flow;
6275  //  c) Book and nest list for particle weights;
6276  //  d) Book and nest list for distributions;
6277  //  e) Book and nest list for various unclassified objects; 
6278  //  f) Book and nest list for nested loops.
6279  
6280  // a) Book and nest all lists for integrated flow:
6281  //  Base list for integrated flow:
6282  fIntFlowList = new TList();
6283  fIntFlowList->SetName("Integrated Flow");
6284  fIntFlowList->SetOwner(kTRUE);
6285  fHistList->Add(fIntFlowList);
6286  //  List holding profiles: 
6287  fIntFlowProfiles = new TList();
6288  fIntFlowProfiles->SetName("Profiles");
6289  fIntFlowProfiles->SetOwner(kTRUE);
6290  fIntFlowList->Add(fIntFlowProfiles);
6291  //  List holding all profiles with results for correlations vs M:
6292  if(fCalculateAllCorrelationsVsM)
6293  {
6294   fIntFlowAllCorrelationsVsM = new TList();
6295   fIntFlowAllCorrelationsVsM->SetName("Correlations vs M");
6296   fIntFlowAllCorrelationsVsM->SetOwner(kTRUE); 
6297   fIntFlowProfiles->Add(fIntFlowAllCorrelationsVsM);
6298  } // end of if(fCalculateAllCorrelationsVsM)
6299  //  List holding histograms with results:
6300  fIntFlowResults = new TList();
6301  fIntFlowResults->SetName("Results");
6302  fIntFlowResults->SetOwner(kTRUE);
6303  fIntFlowList->Add(fIntFlowResults);
6304  
6305  // b) Book and nest lists for differential flow:
6306  this->BookAndNestListsForDifferentialFlow();
6307  
6308  // c) Book and nest list for particle weights:
6309  fWeightsList->SetName("Weights");
6310  fWeightsList->SetOwner(kTRUE);   
6311  fHistList->Add(fWeightsList); 
6312
6313  // d) Book and nest list for distributions:
6314  fDistributionsList = new TList();
6315  fDistributionsList->SetName("Distributions");
6316  fDistributionsList->SetOwner(kTRUE);
6317  fHistList->Add(fDistributionsList);
6318  
6319  // e) Book and nest list for various unclassified objects:
6320  if(fStorePhiDistributionForOneEvent)
6321  {
6322   fVariousList = new TList();
6323   fVariousList->SetName("Various");
6324   fVariousList->SetOwner(kTRUE);
6325   fHistList->Add(fVariousList);
6326  }
6327   
6328  // f) Book and nest list for other differential correlators:
6329  fOtherDiffCorrelatorsList = new TList();
6330  fOtherDiffCorrelatorsList->SetName("Other differential correlators");
6331  fOtherDiffCorrelatorsList->SetOwner(kTRUE);
6332  if(fCalculateDiffFlow){fHistList->Add(fOtherDiffCorrelatorsList);} // TBI: Use another flag here instead of fCalculateDiffFlow 
6333   
6334  // g) Book and nest list for nested loops:
6335  fNestedLoopsList = new TList();
6336  fNestedLoopsList->SetName("Nested Loops");
6337  fNestedLoopsList->SetOwner(kTRUE);
6338  fHistList->Add(fNestedLoopsList);
6339  
6340 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6341
6342 //================================================================================================================================
6343
6344 void AliFlowAnalysisWithQCumulants::BookAndNestListsForDifferentialFlow()
6345 {
6346  // Book and nest lists for differential flow.
6347
6348  // Base list for differential flow objects:
6349  fDiffFlowList = new TList();
6350  fDiffFlowList->SetName("Differential Flow");
6351  fDiffFlowList->SetOwner(kTRUE); 
6352  fHistList->Add(fDiffFlowList);
6353  
6354  // Local flags: 
6355  TString typeFlag[2] = {"RP","POI"};  
6356  TString ptEtaFlag[2] = {"p_{T}","#eta"}; 
6357  TString powerFlag[2] = {"linear","quadratic"};   
6358
6359  // 2D:
6360  if(fCalculate2DDiffFlow)
6361  {
6362   fDiffFlow2D = new TList(); 
6363   fDiffFlow2D->SetName("2D");
6364   fDiffFlow2D->SetOwner(kTRUE);
6365   fDiffFlowList->Add(fDiffFlow2D); 
6366   for(Int_t t=0;t<2;t++)
6367   {
6368    f2DDiffFlowCorrelationsProList[t] = new TList();
6369    f2DDiffFlowCorrelationsProList[t]->SetOwner(kTRUE);
6370    f2DDiffFlowCorrelationsProList[t]->SetName(Form("Profiles with 2D correlations (%s)",typeFlag[t].Data()));
6371    fDiffFlow2D->Add(f2DDiffFlowCorrelationsProList[t]);
6372   } // end of for(Int_t t=0;t<2;t++)
6373  } // end of if(fCalculate2DDiffFlow)
6374
6375  // What follows bellow in this method is relevant only for 1D differential flow:
6376  if(!fCalculateDiffFlow){return;}
6377  
6378  // List holding profiles: 
6379  fDiffFlowProfiles = new TList(); 
6380  fDiffFlowProfiles->SetName("Profiles");
6381  fDiffFlowProfiles->SetOwner(kTRUE);
6382  fDiffFlowList->Add(fDiffFlowProfiles);
6383  // List holding histograms with results: 
6384  fDiffFlowResults = new TList();
6385  fDiffFlowResults->SetName("Results");
6386  fDiffFlowResults->SetOwner(kTRUE);
6387  fDiffFlowList->Add(fDiffFlowResults);
6388  // Flags used for naming nested lists in list fDiffFlowProfiles and fDiffFlowResults:  
6389  TList list;
6390  list.SetOwner(kTRUE);
6391  // Nested lists in fDiffFlowProfiles (~/Differential Flow/Profiles):
6392  for(Int_t t=0;t<2;t++) // type: RP or POI
6393  {
6394   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
6395   {
6396    // list holding profiles with correlations:
6397    fDiffFlowCorrelationsProList[t][pe] = (TList*)list.Clone();
6398    fDiffFlowCorrelationsProList[t][pe]->SetName(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6399    fDiffFlowProfiles->Add(fDiffFlowCorrelationsProList[t][pe]);
6400    // list holding profiles with products of correlations:
6401    fDiffFlowProductOfCorrelationsProList[t][pe] = (TList*)list.Clone();
6402    fDiffFlowProductOfCorrelationsProList[t][pe]->SetName(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6403    fDiffFlowProfiles->Add(fDiffFlowProductOfCorrelationsProList[t][pe]);
6404    // list holding profiles with corrections:
6405    fDiffFlowCorrectionsProList[t][pe] = (TList*)list.Clone();
6406    fDiffFlowCorrectionsProList[t][pe]->SetName(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6407    fDiffFlowProfiles->Add(fDiffFlowCorrectionsProList[t][pe]);   
6408   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6409  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI   
6410  // nested lists in fDiffFlowResults (~/Differential Flow/Results):
6411  for(Int_t t=0;t<2;t++) // type: RP or POI
6412  {
6413   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
6414   {
6415    // list holding histograms with correlations:
6416    fDiffFlowCorrelationsHistList[t][pe] = (TList*)list.Clone();
6417    fDiffFlowCorrelationsHistList[t][pe]->SetName(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6418    fDiffFlowResults->Add(fDiffFlowCorrelationsHistList[t][pe]);
6419    // list holding histograms with corrections:
6420    fDiffFlowCorrectionsHistList[t][pe] = (TList*)list.Clone();
6421    fDiffFlowCorrectionsHistList[t][pe]->SetName(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6422    fDiffFlowResults->Add(fDiffFlowCorrectionsHistList[t][pe]);   
6423    for(Int_t power=0;power<2;power++)
6424    {
6425     // list holding histograms with sums of event weights:
6426     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = (TList*)list.Clone();
6427     fDiffFlowSumOfEventWeightsHistList[t][pe][power]->SetName(Form("Sum of %s event weights (%s, %s)",powerFlag[power].Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6428     fDiffFlowResults->Add(fDiffFlowSumOfEventWeightsHistList[t][pe][power]);    
6429    } // end of for(Int_t power=0;power<2;power++)
6430    // list holding histograms with sums of products of event weights:
6431    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = (TList*)list.Clone();
6432    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->SetName(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6433    fDiffFlowResults->Add(fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]);
6434    // list holding histograms with covariances of correlations:
6435    fDiffFlowCovariancesHistList[t][pe] = (TList*)list.Clone();
6436    fDiffFlowCovariancesHistList[t][pe]->SetName(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6437    fDiffFlowResults->Add(fDiffFlowCovariancesHistList[t][pe]);
6438    // list holding histograms with differential Q-cumulants:
6439    fDiffFlowCumulantsHistList[t][pe] = (TList*)list.Clone();
6440    fDiffFlowCumulantsHistList[t][pe]->SetName(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6441    fDiffFlowResults->Add(fDiffFlowCumulantsHistList[t][pe]);   
6442    // list holding histograms which quantify detector bias to differential Q-cumulants:
6443    fDiffFlowDetectorBiasHistList[t][pe] = (TList*)list.Clone();
6444    fDiffFlowDetectorBiasHistList[t][pe]->SetName(Form("Detector bias (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6445    fDiffFlowResults->Add(fDiffFlowDetectorBiasHistList[t][pe]);   
6446    // list holding histograms with differential flow estimates from Q-cumulants:
6447    fDiffFlowHistList[t][pe] = (TList*)list.Clone();
6448    fDiffFlowHistList[t][pe]->SetName(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6449    fDiffFlowResults->Add(fDiffFlowHistList[t][pe]);      
6450   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6451  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6452   
6453 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestListsForDifferentialFlow()
6454
6455 //================================================================================================================================
6456
6457 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type)
6458 {
6459  // Fill common result histograms for differential flow.
6460  
6461  Int_t t = 0; 
6462
6463  if(type == "RP")
6464  {
6465   t = 0;
6466  } else if(type == "POI")
6467    {
6468     t = 1;
6469    } 
6470   
6471  // to be improved - check all pointers used in this method
6472      
6473  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
6474  {
6475   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
6476   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
6477   exit(0);
6478  }
6479  
6480  // pt:
6481  for(Int_t p=1;p<=fnBinsPt;p++)
6482  {
6483   Double_t v2 = fDiffFlow[t][0][0]->GetBinContent(p);
6484   Double_t v4 = fDiffFlow[t][0][1]->GetBinContent(p);
6485   Double_t v6 = fDiffFlow[t][0][2]->GetBinContent(p);
6486   Double_t v8 = fDiffFlow[t][0][3]->GetBinContent(p);
6487   
6488   Double_t v2Error = fDiffFlow[t][0][0]->GetBinError(p);
6489   Double_t v4Error = fDiffFlow[t][0][1]->GetBinError(p);
6490   //Double_t v6Error = fFinalFlow1D[t][pW][nua][0][2]->GetBinError(p);
6491   //Double_t v8Error = fFinalFlow1D[t][pW][nua][0][3]->GetBinError(p);
6492  
6493   if(type == "RP")
6494   {
6495    fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,v2,v2Error);
6496    fCommonHistsResults4th->FillDifferentialFlowPtRP(p,v4,v4Error);
6497    fCommonHistsResults6th->FillDifferentialFlowPtRP(p,v6,0.);
6498    fCommonHistsResults8th->FillDifferentialFlowPtRP(p,v8,0.);
6499   } else if(type == "POI")
6500     {
6501      fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,v2,v2Error);
6502      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,v4,v4Error);
6503      fCommonHistsResults6th->FillDifferentialFlowPtPOI(p,v6,0.);
6504      fCommonHistsResults8th->FillDifferentialFlowPtPOI(p,v8,0.);
6505     }
6506  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
6507  
6508  // eta:
6509  if(!fCalculateDiffFlowVsEta){return;}
6510  for(Int_t e=1;e<=fnBinsEta;e++)
6511  {
6512   Double_t v2 = fDiffFlow[t][1][0]->GetBinContent(e);
6513   Double_t v4 = fDiffFlow[t][1][1]->GetBinContent(e);
6514   Double_t v6 = fDiffFlow[t][1][2]->GetBinContent(e);
6515   Double_t v8 = fDiffFlow[t][1][3]->GetBinContent(e);
6516   
6517   Double_t v2Error = fDiffFlow[t][1][0]->GetBinError(e);
6518   Double_t v4Error = fDiffFlow[t][1][1]->GetBinError(e);
6519   //Double_t v6Error = fDiffFlow[t][1][2]->GetBinError(e);
6520   //Double_t v8Error = fDiffFlow[t][1][3]->GetBinError(e);
6521  
6522   if(type == "RP")
6523   {
6524    fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,v2,v2Error);
6525    fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,v4,v4Error);
6526    fCommonHistsResults6th->FillDifferentialFlowEtaRP(e,v6,0.);
6527    fCommonHistsResults8th->FillDifferentialFlowEtaRP(e,v8,0.);
6528   } else if(type == "POI")
6529     {
6530      fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,v2,v2Error);
6531      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,v4,v4Error);
6532      fCommonHistsResults6th->FillDifferentialFlowEtaPOI(e,v6,0.);
6533      fCommonHistsResults8th->FillDifferentialFlowEtaPOI(e,v8,0.);
6534     }
6535  } // end of for(Int_t e=1;e<=fnBinsEta;e++)    
6536  
6537 } // end of void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
6538
6539 //================================================================================================================================
6540
6541 void AliFlowAnalysisWithQCumulants::CommonConstants(TString method)
6542 {
6543  // Access and store common constants.
6544  
6545  // a) If this method was called in Init() access common constants from AliFlowCommonConstants;
6546  // b) If this method was called in Init() book and fill TProfile to hold constants accessed in a);
6547  // c) If this method was called in Finish() access common constants from TProfile booked and filled in b).
6548
6549  if(method == "Init")
6550  {
6551   // a) If this method was called in Init() access common constants from AliFlowCommonConstants:
6552   fnBinsPhi = AliFlowCommonConstants::GetMaster()->GetNbinsPhi();
6553   fPhiMin = AliFlowCommonConstants::GetMaster()->GetPhiMin();        
6554   fPhiMax = AliFlowCommonConstants::GetMaster()->GetPhiMax();
6555   if(fnBinsPhi){fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;}  
6556   fnBinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
6557   fPtMin = AliFlowCommonConstants::GetMaster()->GetPtMin();          
6558   fPtMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
6559   if(fnBinsPt){fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;}  
6560   fnBinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
6561   fEtaMin = AliFlowCommonConstants::GetMaster()->GetEtaMin();        
6562   fEtaMax = AliFlowCommonConstants::GetMaster()->GetEtaMax();
6563   if(fnBinsEta){fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;}  
6564   
6565   // b) If this method was called in Init() book and fill TProfile to hold constants accessed in a):
6566   TString fCommonConstantsName = "fCommonConstants";
6567   fCommonConstantsName += fAnalysisLabel->Data();
6568   fCommonConstants = new TProfile(fCommonConstantsName.Data(),"Common constants",9,0.,9.);
6569   fCommonConstants->SetLabelSize(0.05);
6570   fCommonConstants->GetXaxis()->SetBinLabel(1,"nBins (#phi)");
6571   fCommonConstants->Fill(0.5,fnBinsPhi);
6572   fCommonConstants->GetXaxis()->SetBinLabel(2,"#phi_{min}");
6573   fCommonConstants->Fill(1.5,fPhiMin);
6574   fCommonConstants->GetXaxis()->SetBinLabel(3,"#phi_{max}");
6575   fCommonConstants->Fill(2.5,fPhiMax);
6576   fCommonConstants->GetXaxis()->SetBinLabel(4,"nBins (p_{t})");
6577   fCommonConstants->Fill(3.5,fnBinsPt);
6578   fCommonConstants->GetXaxis()->SetBinLabel(5,"(p_{t})_{min}");
6579   fCommonConstants->Fill(4.5,fPtMin);
6580   fCommonConstants->GetXaxis()->SetBinLabel(6,"(p_{t})_{max}");
6581   fCommonConstants->Fill(5.5,fPtMax);
6582   fCommonConstants->GetXaxis()->SetBinLabel(7,"nBins (#eta)");
6583   fCommonConstants->Fill(6.5,fnBinsEta);
6584   fCommonConstants->GetXaxis()->SetBinLabel(8,"#eta_{min}");
6585   fCommonConstants->Fill(7.5,fEtaMin);
6586   fCommonConstants->GetXaxis()->SetBinLabel(9,"#eta_{max}");
6587   fCommonConstants->Fill(8.5,fEtaMax);
6588   fHistList->Add(fCommonConstants); 
6589  } // end of if(method == "Init")
6590  else if(method == "Finish")
6591  {
6592   // c) If this method was called in Finish() access common constants from TProfile booked and filled in b):
6593   if(!fCommonConstants)
6594   {
6595    printf("\n WARNING (QC): fCommonConstants is NULL in AFAWQC::AC(\"%s\") !!!!\n\n",method.Data());
6596    exit(0);
6597   } 
6598   fnBinsPhi = (Int_t)fCommonConstants->GetBinContent(1);
6599   fPhiMin = fCommonConstants->GetBinContent(2);      
6600   fPhiMax = fCommonConstants->GetBinContent(3);
6601   if(fnBinsPhi){fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;}  
6602   fnBinsPt = (Int_t)fCommonConstants->GetBinContent(4);
6603   fPtMin = fCommonConstants->GetBinContent(5);       
6604   fPtMax = fCommonConstants->GetBinContent(6);
6605   if(fnBinsPt){fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;}  
6606   fnBinsEta = (Int_t)fCommonConstants->GetBinContent(7);
6607   fEtaMin = fCommonConstants->GetBinContent(8);      
6608   fEtaMax = fCommonConstants->GetBinContent(9);
6609   if(fnBinsEta){fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;}  
6610  } // end of else if(method == "Finish")
6611
6612 } // end of void AliFlowAnalysisWithQCumulants::CommonConstants(TString method)
6613
6614 //================================================================================================================================
6615
6616 void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6617 {
6618  // a) Cross check if the choice for multiplicity weights make sense.
6619  
6620  // a) Cross check if the choice for multiplicity weights make sense:
6621  if(strcmp(fMultiplicityWeight->Data(),"combinations") && 
6622     strcmp(fMultiplicityWeight->Data(),"unit") &&
6623     strcmp(fMultiplicityWeight->Data(),"multiplicity"))
6624  {
6625   cout<<"WARNING (QC): Multiplicity weight can be either \"combinations\", \"unit\""<<endl;
6626   cout<<"              or \"multiplicity\". Certainly not \""<<fMultiplicityWeight->Data()<<"\"."<<endl;
6627   exit(0);
6628  }   
6629  
6630 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6631
6632 //================================================================================================================================
6633
6634 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6635 {
6636  // Calculate sum of linear and quadratic event weights for correlations.
6637  
6638  // multiplicity:
6639  Double_t dMult = (*fSpk)(0,0);
6640                         
6641  for(Int_t p=0;p<2;p++) // power-1
6642  {
6643   for(Int_t ci=0;ci<4;ci++) // correlation index
6644   { 
6645    fIntFlowSumOfEventWeights[p]->Fill(ci+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); 
6646    if(fCalculateCumulantsVsM)
6647    {
6648     fIntFlowSumOfEventWeightsVsM[ci][p]->Fill(dMult+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); // to be improved: dMult => sum of weights?
6649    }
6650   }
6651  }
6652   
6653 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6654
6655 //================================================================================================================================
6656
6657 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6658 {
6659  // Calculate sum of linear and quadratic event weights for NUA terms.
6660                        
6661  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
6662  {
6663   for(Int_t p=0;p<2;p++) // power-1
6664   {
6665    for(Int_t ci=0;ci<4;ci++) // nua term index
6666    { 
6667     fIntFlowSumOfEventWeightsNUA[sc][p]->Fill(ci+0.5,pow(fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->GetBinContent(ci+1),p+1)); 
6668    }
6669   }
6670  }
6671   
6672 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6673
6674 //================================================================================================================================
6675
6676 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6677 {
6678  // Calculate sum of product of event weights for correlations.
6679   
6680  // multiplicity:
6681  Double_t dMult = (*fSpk)(0,0);
6682   
6683  Int_t counter = 0;
6684  
6685  for(Int_t ci1=1;ci1<4;ci1++)
6686  {
6687   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
6688   {
6689    fIntFlowSumOfProductOfEventWeights->Fill(0.5+counter,
6690                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6691                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6692    if(fCalculateCumulantsVsM)
6693    {                                                                                    
6694     fIntFlowSumOfProductOfEventWeightsVsM[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights?
6695                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6696                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6697    } // end of if(fCalculateCumulantsVsM)
6698    counter++;                                         
6699   }
6700  }
6701
6702 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6703
6704 //================================================================================================================================
6705
6706 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeightsNUA()
6707 {
6708  // Calculate sum of product of event weights for NUA terms.
6709   
6710  // w_{<2>} * w_{<cos(#phi)>}:
6711  fIntFlowSumOfProductOfEventWeightsNUA->Fill(0.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6712                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6713  // w_{<2>} * w_{<sin(#phi)>}:
6714  fIntFlowSumOfProductOfEventWeightsNUA->Fill(1.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6715                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6716  // w_{<cos(#phi)> * w_{<sin(#phi)>}:
6717  fIntFlowSumOfProductOfEventWeightsNUA->Fill(2.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6718                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6719  // w_{<2>} * w{<cos(phi1+phi2)>}
6720  fIntFlowSumOfProductOfEventWeightsNUA->Fill(3.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6721                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6722  // w_{<2>} * w{<sin(phi1+phi2)>}
6723  fIntFlowSumOfProductOfEventWeightsNUA->Fill(4.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6724                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6725  // w_{<2>} * w{<cos(phi1-phi2-phi3)>}
6726  fIntFlowSumOfProductOfEventWeightsNUA->Fill(5.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6727                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6728  // w_{<2>} * w{<sin(phi1-phi2-phi3)>}
6729  fIntFlowSumOfProductOfEventWeightsNUA->Fill(6.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6730                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
6731  // w_{<4>} * w{<cos(phi1)>}
6732  fIntFlowSumOfProductOfEventWeightsNUA->Fill(7.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6733                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6734  // w_{<4>} * w{<sin(phi1)>}
6735  fIntFlowSumOfProductOfEventWeightsNUA->Fill(8.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6736                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6737  // w_{<4>} * w{<cos(phi1+phi2)>}
6738  fIntFlowSumOfProductOfEventWeightsNUA->Fill(9.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6739                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6740  // w_{<4>} * w{<sin(phi1+phi2)>}
6741  fIntFlowSumOfProductOfEventWeightsNUA->Fill(10.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6742                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6743  // w_{<4>} * w{<cos(phi1-phi2-phi3)>}
6744  fIntFlowSumOfProductOfEventWeightsNUA->Fill(11.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6745                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6746  // w_{<4>} * w{<sin(phi1-phi2-phi3)>}
6747  fIntFlowSumOfProductOfEventWeightsNUA->Fill(12.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6748                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6749  // w_{<cos(phi1)>} * w{<cos(phi1+phi2)>}
6750  fIntFlowSumOfProductOfEventWeightsNUA->Fill(13.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6751                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6752  // w_{<cos(phi1)>} * w{<sin(phi1+phi2)>}
6753  fIntFlowSumOfProductOfEventWeightsNUA->Fill(14.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6754                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6755  // w_{<cos(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6756  fIntFlowSumOfProductOfEventWeightsNUA->Fill(15.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6757                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6758  // w_{<cos(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6759  fIntFlowSumOfProductOfEventWeightsNUA->Fill(16.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6760                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6761  // w_{<sin(phi1)>} * w{<cos(phi1+phi2)>}
6762  fIntFlowSumOfProductOfEventWeightsNUA->Fill(17.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6763                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6764  // w_{<sin(phi1)>} * w{<sin(phi1+phi2)>}
6765  fIntFlowSumOfProductOfEventWeightsNUA->Fill(18.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6766                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6767  // w_{<sin(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6768  fIntFlowSumOfProductOfEventWeightsNUA->Fill(19.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6769                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6770  // w_{<sin(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6771  fIntFlowSumOfProductOfEventWeightsNUA->Fill(20.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6772                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6773  // w_{<cos(phi1+phi2)>} * w{<sin(phi1+phi2))>}
6774  fIntFlowSumOfProductOfEventWeightsNUA->Fill(21.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6775                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6776  // w_{<cos(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6777  fIntFlowSumOfProductOfEventWeightsNUA->Fill(22.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6778                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6779  // w_{<cos(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6780  fIntFlowSumOfProductOfEventWeightsNUA->Fill(23.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6781                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6782  // w_{<sin(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6783  fIntFlowSumOfProductOfEventWeightsNUA->Fill(24.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6784                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6785  // w_{<sin(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6786  fIntFlowSumOfProductOfEventWeightsNUA->Fill(25.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6787                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6788  // w_{<cos(phi1-phi2-phi3)>} * w{<sin(phi1-phi2-phi3)>}
6789  fIntFlowSumOfProductOfEventWeightsNUA->Fill(26.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)*
6790                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6791
6792 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowIntFlowSumOfProductOfEventWeightsNUA()
6793
6794 //================================================================================================================================
6795
6796 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta)
6797 {
6798  // Calculate reduced correlations for RPs or POIs for all pt and eta bins.
6799
6800  // Multiplicity:
6801  Double_t dMult = (*fSpk)(0,0);
6802  
6803  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
6804  Double_t dReQ1n = (*fReQ)(0,0);
6805  Double_t dReQ2n = (*fReQ)(1,0);
6806  //Double_t dReQ3n = (*fReQ)(2,0);
6807  //Double_t dReQ4n = (*fReQ)(3,0);
6808  Double_t dImQ1n = (*fImQ)(0,0);
6809  Double_t dImQ2n = (*fImQ)(1,0);
6810  //Double_t dImQ3n = (*fImQ)(2,0);
6811  //Double_t dImQ4n = (*fImQ)(3,0);
6812
6813  // reduced correlations are stored in fDiffFlowCorrelationsPro[0=RP,1=POI][0=pt,1=eta][correlation index]. Correlation index runs as follows:
6814  // 
6815  // 0: <<2'>>
6816  // 1: <<4'>>
6817  // 2: <<6'>>
6818  // 3: <<8'>>
6819  
6820  Int_t t = 0; // type flag 
6821  Int_t pe = 0; // ptEta flag
6822  
6823  if(type == "RP")
6824  {
6825   t = 0;
6826  } else if(type == "POI")
6827    {
6828     t = 1;
6829    }
6830
6831  if(ptOrEta == "Pt")
6832  {
6833   pe = 0;
6834  } else if(ptOrEta == "Eta")
6835    {
6836     pe = 1;
6837    }
6838     
6839  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6840  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6841  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6842  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6843
6844  // looping over all bins and calculating reduced correlations: 
6845  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6846  {
6847   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
6848   Double_t p1n0kRe = 0.;
6849   Double_t p1n0kIm = 0.;
6850
6851   // number of POIs in particular pt or eta bin:
6852   Double_t mp = 0.;
6853
6854   // 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):
6855   Double_t q1n0kRe = 0.;
6856   Double_t q1n0kIm = 0.;
6857   Double_t q2n0kRe = 0.;
6858   Double_t q2n0kIm = 0.;
6859
6860   // number of particles which are both RPs and POIs in particular pt or eta bin:
6861   Double_t mq = 0.;
6862    
6863   if(type == "POI")
6864   {
6865    // q_{m*n,0}:
6866    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
6867            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
6868    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
6869            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
6870    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
6871            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
6872    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
6873            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
6874                  
6875    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6876   } 
6877   else if(type == "RP")
6878   {
6879    // q_{m*n,0}:
6880    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
6881            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
6882    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
6883            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
6884    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
6885            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
6886    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
6887            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
6888                  
6889    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
6890   }
6891       
6892    if(type == "POI")
6893    {
6894     // p_{m*n,0}:
6895     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
6896             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
6897     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
6898             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
6899             
6900     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6901     
6902     t = 1; // typeFlag = RP or POI
6903    }
6904    else if(type == "RP")
6905    {
6906     // p_{m*n,0} = q_{m*n,0}:
6907     p1n0kRe = q1n0kRe; 
6908     p1n0kIm = q1n0kIm; 
6909             
6910     mp = mq; 
6911     
6912     t = 0; // typeFlag = RP or POI
6913    }
6914       
6915    // 2'-particle correlation for particular pt or eta bin:
6916    Double_t two1n1nPtEta = 0.;
6917    Double_t mWeight2pPrime = 0.; // multiplicity weight for <2'>
6918    if(mp*dMult-mq)
6919    {
6920     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
6921                  / (mp*dMult-mq);
6922     // determine multiplicity weight:
6923     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
6924     {
6925      mWeight2pPrime = mp*dMult-mq;
6926     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
6927       {
6928        mWeight2pPrime = 1.;    
6929       } 
6930     if(type == "POI") // to be improved (I do not this if)
6931     { 
6932      // fill profile to get <<2'>> for POIs
6933      fDiffFlowCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);
6934      // fill profile to get <<2'>^2> for POIs
6935      fDiffFlowSquaredCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);   
6936      // histogram to store <2'> for POIs e-b-e (needed in some other methods):
6937      fDiffFlowCorrelationsEBE[1][pe][0]->SetBinContent(b,two1n1nPtEta);      
6938      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][0]->SetBinContent(b,mWeight2pPrime);      
6939     }
6940     else if(type == "RP") // to be improved (I do not this if)
6941     {
6942      // profile to get <<2'>> for RPs:
6943      fDiffFlowCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);     
6944      // profile to get <<2'>^2> for RPs:
6945      fDiffFlowSquaredCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);          
6946      // histogram to store <2'> for RPs e-b-e (needed in some other methods):
6947      fDiffFlowCorrelationsEBE[0][pe][0]->SetBinContent(b,two1n1nPtEta); 
6948      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][0]->SetBinContent(b,mWeight2pPrime); 
6949     }
6950    } // end of if(mp*dMult-mq)
6951   
6952    // 4'-particle correlation:
6953    Double_t four1n1n1n1nPtEta = 0.;
6954    Double_t mWeight4pPrime = 0.; // multiplicity weight for <4'>
6955    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6956        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
6957    {
6958     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6959                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
6960                       - 2.*q2n0kIm*dReQ1n*dImQ1n
6961                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
6962                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
6963                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6964                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
6965                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
6966                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
6967                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
6968                       + 2.*mq*dMult                      
6969                       - 6.*mq)        
6970                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6971                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
6972     // determine multiplicity weight:
6973     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
6974     {
6975      mWeight4pPrime = (mp-mq)*dMult*(dMult-1.)*(dMult-2.) + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);
6976     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
6977       {
6978        mWeight4pPrime = 1.;    
6979       }     
6980     if(type == "POI")
6981     {
6982      // profile to get <<4'>> for POIs:
6983      fDiffFlowCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);      
6984      // profile to get <<4'>^2> for POIs:
6985      fDiffFlowSquaredCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime); 
6986      // histogram to store <4'> for POIs e-b-e (needed in some other methods):
6987      fDiffFlowCorrelationsEBE[1][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                               
6988      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][1]->SetBinContent(b,mWeight4pPrime);                               
6989     }
6990     else if(type == "RP")
6991     {
6992      // profile to get <<4'>> for RPs:
6993      fDiffFlowCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);    
6994      // profile to get <<4'>^2> for RPs:
6995      fDiffFlowSquaredCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime);    
6996      // histogram to store <4'> for RPs e-b-e (needed in some other methods):
6997      fDiffFlowCorrelationsEBE[0][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                   
6998      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][1]->SetBinContent(b,mWeight4pPrime);                   
6999     }
7000    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7001      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
7002    
7003  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7004  
7005    
7006 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta);
7007
7008 //================================================================================================================================
7009
7010 void AliFlowAnalysisWithQCumulants::CalculateOtherDiffCorrelators(TString type, TString ptOrEta)
7011 {
7012  // Calculate other differential correlators for RPs or POIs for all pt and eta bins.
7013  
7014  // Multiplicity:
7015  Double_t dMult = (*fSpk)(0,0);
7016  
7017  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
7018  Double_t dReQ1n = (*fReQ)(0,0);
7019  Double_t dReQ2n = (*fReQ)(1,0);
7020  Double_t dReQ3n = (*fReQ)(2,0);
7021  //Double_t dReQ4n = (*fReQ)(3,0);
7022  Double_t dImQ1n = (*fImQ)(0,0);
7023  Double_t dImQ2n = (*fImQ)(1,0);
7024  Double_t dImQ3n = (*fImQ)(2,0);
7025  //Double_t dImQ4n = (*fImQ)(3,0);
7026
7027  // Other correlations are stored in fOtherDiffCorrelators[2][2][2][1], [0=RP,1=POI][0=pt,1=eta][0=sin terms,1=cos terms][correlator index]
7028  // Correlation index runs as follows:
7029  // 
7030  //  0: <exp[in(psi1-3phi2+2phi3)]>
7031  
7032  Int_t t = 0; // type flag 
7033  Int_t pe = 0; // ptEta flag
7034  
7035  if(type == "RP")
7036  {
7037   t = 0;
7038  } else if(type == "POI")
7039    {
7040     t = 1;
7041    }
7042
7043  if(ptOrEta == "Pt")
7044  {
7045   pe = 0;
7046  } else if(ptOrEta == "Eta")
7047    {
7048     pe = 1;
7049    }
7050     
7051  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7052  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7053  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7054  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7055
7056  // looping over all bins and calculating reduced correlations: 
7057  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7058  {
7059   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
7060   Double_t p1n0kRe = 0.;
7061   Double_t p1n0kIm = 0.;
7062
7063   // number of POIs in particular pt or eta bin:
7064   Double_t mp = 0.;
7065
7066   // 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):
7067   Double_t q1n0kRe = 0.;
7068   Double_t q1n0kIm = 0.;
7069   Double_t q2n0kRe = 0.;
7070   Double_t q2n0kIm = 0.;
7071   Double_t q3n0kRe = 0.;
7072   Double_t q3n0kIm = 0.;
7073
7074   // number of particles which are both RPs and POIs in particular pt or eta bin:
7075   Double_t mq = 0.;
7076    
7077   if(type == "POI")
7078   {
7079    // q_{m*n,0}:
7080    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
7081            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
7082    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
7083            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
7084    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
7085            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
7086    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
7087            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));                         
7088    q3n0kRe = fReRPQ1dEBE[2][pe][2][0]->GetBinContent(fReRPQ1dEBE[2][pe][2][0]->GetBin(b))
7089            * fReRPQ1dEBE[2][pe][2][0]->GetBinEntries(fReRPQ1dEBE[2][pe][2][0]->GetBin(b));
7090    q3n0kIm = fImRPQ1dEBE[2][pe][2][0]->GetBinContent(fImRPQ1dEBE[2][pe][2][0]->GetBin(b))
7091            * fImRPQ1dEBE[2][pe][2][0]->GetBinEntries(fImRPQ1dEBE[2][pe][2][0]->GetBin(b));         
7092
7093    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7094   } 
7095   else if(type == "RP")
7096   {
7097    // q_{m*n,0}:
7098    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
7099            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
7100    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
7101            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
7102    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
7103            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
7104    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
7105            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
7106    q3n0kRe = fReRPQ1dEBE[0][pe][2][0]->GetBinContent(fReRPQ1dEBE[0][pe][2][0]->GetBin(b))
7107            * fReRPQ1dEBE[0][pe][2][0]->GetBinEntries(fReRPQ1dEBE[0][pe][2][0]->GetBin(b));
7108    q3n0kIm = fImRPQ1dEBE[0][pe][2][0]->GetBinContent(fImRPQ1dEBE[0][pe][2][0]->GetBin(b))
7109            * fImRPQ1dEBE[0][pe][2][0]->GetBinEntries(fImRPQ1dEBE[0][pe][2][0]->GetBin(b));         
7110                  
7111    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
7112   }
7113       
7114    if(type == "POI")
7115    {
7116     // p_{m*n,0}:
7117     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
7118             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
7119     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
7120             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
7121             
7122     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7123     
7124     t = 1; // typeFlag = RP or POI
7125    }
7126    else if(type == "RP")
7127    {
7128     // p_{m*n,0} = q_{m*n,0}:
7129     p1n0kRe = q1n0kRe; 
7130     p1n0kIm = q1n0kIm; 
7131             
7132     mp = mq; 
7133     
7134     t = 0; // typeFlag = RP or POI
7135    }
7136       
7137    // 3'-particle correlators:
7138    //  Taeney-Yan correlator:
7139    Double_t dTaeneyYan = 0.;
7140    Double_t mWeightTaeneyYan = 0.; // multiplicity weight for Taeney-Yan correlator
7141    if((mp*dMult-2.*mq)*(dMult-1.) > 0.) // to be improved - is this condition fully justified?
7142    {
7143     dTaeneyYan = (dReQ3n*(p1n0kRe*dReQ2n-p1n0kIm*dImQ2n)+dImQ3n*(p1n0kIm*dReQ2n+p1n0kRe*dImQ2n)
7144                - p1n0kRe*dReQ1n - p1n0kIm*dImQ1n
7145                - q2n0kRe*dReQ2n - q2n0kIm*dImQ2n              
7146                - q3n0kRe*dReQ3n - q3n0kIm*dImQ3n
7147                + 2.*mq)
7148                / ((mp*dMult-2.*mq)*(dMult-1.));
7149     // determine multiplicity weight:
7150     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7151     {
7152      mWeightTaeneyYan = (mp*dMult-2.*mq)*(dMult-1.);
7153     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7154       {
7155        mWeightTaeneyYan = 1.;    
7156       } 
7157     // Fill profiles:
7158     fOtherDiffCorrelators[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dTaeneyYan,mWeightTaeneyYan);
7159    } // end of if((mp*dMult-2.*mq)*(dMult-1.) > 0.)  
7160    
7161  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7162  
7163 } // end of void AliFlowAnalysisWithQCumulants::CalculateOtherDiffCorrelators(TString type, TString ptOrEta)
7164
7165 //================================================================================================================================
7166
7167 void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCorrelations(TString type)
7168 {
7169  // Calculate all reduced correlations needed for 2D differential flow for each (pt,eta) bin. 
7170  
7171  // Multiplicity:
7172  Double_t dMult = (*fSpk)(0,0);
7173  // Real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
7174  Double_t dReQ1n = (*fReQ)(0,0);
7175  Double_t dReQ2n = (*fReQ)(1,0);
7176  //Double_t dReQ3n = (*fReQ)(2,0);
7177  //Double_t dReQ4n = (*fReQ)(3,0);
7178  Double_t dImQ1n = (*fImQ)(0,0);
7179  Double_t dImQ2n = (*fImQ)(1,0);
7180  //Double_t dImQ3n = (*fImQ)(2,0);
7181  //Double_t dImQ4n = (*fImQ)(3,0);
7182
7183  // 2D reduced correlations are stored in TProfile2D f2DDiffFlowCorrelationsPro[0=RP,1=POI][correlation index]. 
7184  // Correlation index runs as follows:
7185  //  0: <<2'>> 
7186  //  1: <<4'>>
7187  //  2: <<6'>>
7188  //  3: <<8'>>
7189  
7190  Int_t t = 0; // type flag  
7191  if(type == "RP")
7192  {
7193   t = 0;
7194  } else if(type == "POI")
7195    {
7196     t = 1;
7197    }
7198
7199  // Looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
7200  for(Int_t p=1;p<=fnBinsPt;p++)
7201  {
7202   for(Int_t e=1;e<=fnBinsEta;e++)
7203   {
7204    // Real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin): 
7205    Double_t p1n0kRe = 0.;
7206    Double_t p1n0kIm = 0.;
7207    // Number of POIs in particular pt or eta bin:
7208    Double_t mp = 0.;
7209    // Real and imaginary parts of q_{m*n,0} (non-weighted Q-vector evaluated for 'RP && POI particles' in particular pt or eta bin):
7210    Double_t q1n0kRe = 0.;
7211    Double_t q1n0kIm = 0.;
7212    Double_t q2n0kRe = 0.;
7213    Double_t q2n0kIm = 0.; 
7214    // Number of 'RP && POI particles' in particular pt or eta bin:
7215    Double_t mq = 0.;
7216    if(type == "POI")
7217    {
7218     // q_{m*n,0}:
7219     q1n0kRe = fReRPQ2dEBE[2][0][0]->GetBinContent(fReRPQ2dEBE[2][0][0]->GetBin(p,e))
7220             * fReRPQ2dEBE[2][0][0]->GetBinEntries(fReRPQ2dEBE[2][0][0]->GetBin(p,e));
7221     q1n0kIm = fImRPQ2dEBE[2][0][0]->GetBinContent(fImRPQ2dEBE[2][0][0]->GetBin(p,e))
7222             * fImRPQ2dEBE[2][0][0]->GetBinEntries(fImRPQ2dEBE[2][0][0]->GetBin(p,e));
7223     q2n0kRe = fReRPQ2dEBE[2][1][0]->GetBinContent(fReRPQ2dEBE[2][1][0]->GetBin(p,e))
7224             * fReRPQ2dEBE[2][1][0]->GetBinEntries(fReRPQ2dEBE[2][1][0]->GetBin(p,e));
7225     q2n0kIm = fImRPQ2dEBE[2][1][0]->GetBinContent(fImRPQ2dEBE[2][1][0]->GetBin(p,e))
7226             * fImRPQ2dEBE[2][1][0]->GetBinEntries(fImRPQ2dEBE[2][1][0]->GetBin(p,e));         
7227     // m_{q}:             
7228     mq = fReRPQ2dEBE[2][0][0]->GetBinEntries(fReRPQ2dEBE[2][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
7229    } // end of if(type == "POI")
7230    else if(type == "RP")
7231    {
7232     // q_{m*n,0}:
7233     q1n0kRe = fReRPQ2dEBE[0][0][0]->GetBinContent(fReRPQ2dEBE[0][0][0]->GetBin(p,e))
7234             * fReRPQ2dEBE[0][0][0]->GetBinEntries(fReRPQ2dEBE[0][0][0]->GetBin(p,e));
7235     q1n0kIm = fImRPQ2dEBE[0][0][0]->GetBinContent(fImRPQ2dEBE[0][0][0]->GetBin(p,e))
7236             * fImRPQ2dEBE[0][0][0]->GetBinEntries(fImRPQ2dEBE[0][0][0]->GetBin(p,e));
7237     q2n0kRe = fReRPQ2dEBE[0][1][0]->GetBinContent(fReRPQ2dEBE[0][1][0]->GetBin(p,e))
7238             * fReRPQ2dEBE[0][1][0]->GetBinEntries(fReRPQ2dEBE[0][1][0]->GetBin(p,e));
7239     q2n0kIm = fImRPQ2dEBE[0][1][0]->GetBinContent(fImRPQ2dEBE[0][1][0]->GetBin(p,e))
7240             * fImRPQ2dEBE[0][1][0]->GetBinEntries(fImRPQ2dEBE[0][1][0]->GetBin(p,e));         
7241     // m_{q}:             
7242     mq = fReRPQ2dEBE[0][0][0]->GetBinEntries(fReRPQ2dEBE[0][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)  
7243    } // end of else if(type == "RP")
7244    if(type == "POI")
7245    {
7246     // p_{m*n,0}:
7247     p1n0kRe = fReRPQ2dEBE[1][0][0]->GetBinContent(fReRPQ2dEBE[1][0][0]->GetBin(p,e))
7248             * fReRPQ2dEBE[1][0][0]->GetBinEntries(fReRPQ2dEBE[1][0][0]->GetBin(p,e));
7249     p1n0kIm = fImRPQ2dEBE[1][0][0]->GetBinContent(fImRPQ2dEBE[1][0][0]->GetBin(p,e))  
7250             * fImRPQ2dEBE[1][0][0]->GetBinEntries(fImRPQ2dEBE[1][0][0]->GetBin(p,e));
7251     // m_{p}        
7252     mp = fReRPQ2dEBE[1][0][0]->GetBinEntries(fReRPQ2dEBE[1][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
7253     
7254     t = 1; // typeFlag = RP or POI
7255    } // end of if(type == "POI")
7256    else if(type == "RP")
7257    {
7258     // p_{m*n,0} = q_{m*n,0}:
7259     p1n0kRe = q1n0kRe; 
7260     p1n0kIm = q1n0kIm; 
7261     // m_{p} = m_{q}:        
7262     mp = mq; 
7263
7264     t = 0; // typeFlag = RP or POI
7265    } // end of if(type == "RP")
7266
7267    // 2'-particle correlation for particular (pt,eta) bin:
7268    Double_t two1n1nPtEta = 0.;
7269    Double_t mWeight2pPrime = 0.; // multiplicity weight for <2'>
7270    if(mp*dMult-mq)
7271    {
7272     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
7273                  / (mp*dMult-mq);
7274     // Determine multiplicity weight:
7275     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7276     {
7277      mWeight2pPrime = mp*dMult-mq;
7278     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7279       {
7280        mWeight2pPrime = 1.;    
7281       } 
7282     // Fill 2D profile holding <<2'>>:     
7283     f2DDiffFlowCorrelationsPro[t][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mWeight2pPrime);
7284    } // end of if(mp*dMult-mq)
7285    
7286    // 4'-particle correlation:
7287    Double_t four1n1n1n1nPtEta = 0.;
7288    Double_t mWeight4pPrime = 0.; // multiplicity weight for <4'>
7289    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7290        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
7291    {
7292     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
7293                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
7294                       - 2.*q2n0kIm*dReQ1n*dImQ1n
7295                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
7296                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
7297                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
7298                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
7299                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
7300                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
7301                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
7302                       + 2.*mq*dMult                      
7303                       - 6.*mq)        
7304                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7305                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
7306     // Determine multiplicity weight:
7307     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7308     {
7309      mWeight4pPrime = (mp-mq)*dMult*(dMult-1.)*(dMult-2.) + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);
7310     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7311       {
7312        mWeight4pPrime = 1.;    
7313       }     
7314     // Fill 2D profile holding <<4'>>:
7315     f2DDiffFlowCorrelationsPro[t][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,mWeight4pPrime);      
7316    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7317      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
7318   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
7319  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
7320       
7321 } // end of AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCorrelations(TString type)
7322
7323 //================================================================================================================================
7324
7325 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights(TString type, TString ptOrEta)
7326 {
7327  // Calculate sums of various event weights for reduced correlations. 
7328  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
7329
7330  Int_t typeFlag = 0;
7331  Int_t ptEtaFlag = 0;
7332
7333  if(type == "RP")
7334  {
7335   typeFlag = 0;
7336  } else if(type == "POI")
7337    {
7338     typeFlag = 1;
7339    } 
7340      
7341  if(ptOrEta == "Pt")
7342  {
7343   ptEtaFlag = 0;
7344  } else if(ptOrEta == "Eta")
7345    {
7346     ptEtaFlag = 1;
7347    } 
7348    
7349  // shortcuts:
7350  Int_t t = typeFlag;
7351  Int_t pe = ptEtaFlag;
7352  
7353  // binning:
7354  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7355  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7356  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7357  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7358  
7359  for(Int_t rpq=0;rpq<3;rpq++)
7360  {
7361   for(Int_t m=0;m<4;m++)
7362   {
7363    for(Int_t k=0;k<9;k++)
7364    {
7365     if(!fReRPQ1dEBE[rpq][pe][m][k])
7366     {
7367      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
7368      cout<<"pe  = "<<pe<<endl;
7369      cout<<"rpq = "<<rpq<<endl;
7370      cout<<"m   = "<<m<<endl;
7371      cout<<"k   = "<<k<<endl;
7372      exit(0); 
7373     }
7374    }
7375   }
7376  }  
7377
7378  // multiplicities:
7379  Double_t dMult = (*fSpk)(0,0); // total event multiplicity
7380  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7381  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7382  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7383  
7384  // event weights for reduced correlations:
7385  Double_t dw2 = 0.; // event weight for <2'>
7386  Double_t dw4 = 0.; // event weight for <4'>
7387  //Double_t dw6 = 0.; // event weight for <6'>
7388  //Double_t dw8 = 0.; // event weight for <8'>
7389
7390  // looping over bins:
7391  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7392  {
7393   if(type == "RP")
7394   {
7395    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7396    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7397   } else if(type == "POI")
7398     {
7399      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7400      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7401     }
7402   
7403   // event weight for <2'>:
7404   dw2 = mp*dMult-mq;  
7405   fDiffFlowSumOfEventWeights[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2);
7406   fDiffFlowSumOfEventWeights[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw2,2.));
7407   
7408   // event weight for <4'>:
7409   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7410      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
7411   fDiffFlowSumOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4);
7412   fDiffFlowSumOfEventWeights[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw4,2.));
7413   
7414   // event weight for <6'>:
7415   //dw6 = ...;  
7416   //fDiffFlowSumOfEventWeights[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6);
7417   //fDiffFlowSumOfEventWeights[t][pe][t][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw6,2.));
7418   
7419   // event weight for <8'>:
7420   //dw8 = ...;  
7421   //fDiffFlowSumOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw8);
7422   //fDiffFlowSumOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw8,2.));   
7423  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++) 
7424  
7425 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights()
7426
7427
7428 //================================================================================================================================
7429
7430
7431 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
7432 {
7433  // Calculate sum of products of various event weights for both types of correlations (the ones for int. and diff. flow). 
7434  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
7435  //
7436  // Important: To fill fDiffFlowSumOfProductOfEventWeights[][][][] use bellow table (i,j) with following constraints: 
7437  // 1.) i<j  
7438  // 2.) do not store terms which DO NOT include reduced correlations;
7439  // Table:
7440  // [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'>]
7441   
7442  Int_t typeFlag = 0;
7443  Int_t ptEtaFlag = 0;
7444
7445  if(type == "RP")
7446  {
7447   typeFlag = 0;
7448  } else if(type == "POI")
7449    {
7450     typeFlag = 1;
7451    } 
7452      
7453  if(ptOrEta == "Pt")
7454  {
7455   ptEtaFlag = 0;
7456  } else if(ptOrEta == "Eta")
7457    {
7458     ptEtaFlag = 1;
7459    } 
7460      
7461  // shortcuts:
7462  Int_t t = typeFlag;
7463  Int_t pe = ptEtaFlag;
7464   
7465  // binning:
7466  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7467  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7468  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7469  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7470  
7471  // protection:
7472  for(Int_t rpq=0;rpq<3;rpq++)
7473  {
7474   for(Int_t m=0;m<4;m++)
7475   {
7476    for(Int_t k=0;k<9;k++)
7477    {
7478     if(!fReRPQ1dEBE[rpq][pe][m][k])
7479     {
7480      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
7481      cout<<"pe  = "<<pe<<endl;
7482      cout<<"rpq = "<<rpq<<endl;
7483      cout<<"m   = "<<m<<endl;
7484      cout<<"k   = "<<k<<endl;
7485      exit(0); 
7486     }
7487    }
7488   }
7489  }  
7490  
7491  // multiplicities:
7492  Double_t dMult = (*fSpk)(0,0); // total event multiplicity
7493  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7494  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7495  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7496  
7497  // event weights for correlations:
7498  Double_t dW2 = dMult*(dMult-1); // event weight for <2> 
7499  Double_t dW4 = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
7500  Double_t dW6 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
7501  Double_t dW8 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
7502
7503  // event weights for reduced correlations:
7504  Double_t dw2 = 0.; // event weight for <2'>
7505  Double_t dw4 = 0.; // event weight for <4'>
7506  //Double_t dw6 = 0.; // event weight for <6'>
7507  //Double_t dw8 = 0.; // event weight for <8'>
7508  
7509  // looping over bins:
7510  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7511  {
7512   if(type == "RP")
7513   {
7514    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7515    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7516   } else if(type == "POI")
7517     {
7518      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7519      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7520     }
7521   
7522   // event weight for <2'>:
7523   dw2 = mp*dMult-mq;  
7524   fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw2); // storing product of even weights for <2> and <2'>
7525   fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW4); // storing product of even weights for <4> and <2'>
7526   fDiffFlowSumOfProductOfEventWeights[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW6); // storing product of even weights for <6> and <2'>
7527   fDiffFlowSumOfProductOfEventWeights[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW8); // storing product of even weights for <8> and <2'>
7528   
7529   // event weight for <4'>:
7530   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7531      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
7532   fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw4); // storing product of even weights for <2> and <4'>
7533   fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw4); // storing product of even weights for <2'> and <4'>
7534   fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw4); // storing product of even weights for <4> and <4'>
7535   fDiffFlowSumOfProductOfEventWeights[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW6); // storing product of even weights for <6> and <4'> 
7536   fDiffFlowSumOfProductOfEventWeights[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW8); // storing product of even weights for <8> and <4'>
7537
7538   // event weight for <6'>:
7539   //dw6 = ...;  
7540   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw6); // storing product of even weights for <2> and <6'>
7541   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw6); // storing product of even weights for <2'> and <6'>
7542   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw6); // storing product of even weights for <4> and <6'>
7543   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw6); // storing product of even weights for <4'> and <6'> 
7544   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw6); // storing product of even weights for <6> and <6'>
7545   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dW8); // storing product of even weights for <6'> and <8>
7546   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
7547
7548   // event weight for <8'>:
7549   //dw8 = ...;  
7550   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw8); // storing product of even weights for <2> and <8'>
7551   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw8); // storing product of even weights for <2'> and <8'>
7552   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw8); // storing product of even weights for <4> and <8'>
7553   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw8); // storing product of even weights for <4'> and <8'> 
7554   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw8); // storing product of even weights for <6> and <8'>
7555   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
7556   //fDiffFlowSumOfProductOfEventWeights[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW8*dw8); // storing product of even weights for <8> and <8'>
7557   
7558   // Table:
7559   // [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'>]
7560    
7561  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7562  
7563
7564
7565 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
7566
7567 //================================================================================================================================
7568
7569 void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
7570 {
7571  // Transfer profiles into histograms and calculate statistical errors correctly.
7572
7573  Int_t t = 0; // RP or POI
7574  Int_t pe = 0; // pt or eta
7575
7576  if(type == "RP")
7577  {
7578   t = 0;
7579  } else if(type == "POI")
7580    {
7581     t = 1;
7582    } 
7583      
7584  if(ptOrEta == "Pt")
7585  {
7586   pe = 0;
7587  } else if(ptOrEta == "Eta")
7588    {
7589     pe = 1;
7590    } 
7591                
7592  for(Int_t rci=0;rci<4;rci++) // to be improved - moved into the method CheckPointersUsedInFinish()
7593  {
7594   if(!fDiffFlowCorrelationsPro[t][pe][rci])
7595   {
7596    cout<<"WARNING: fDiffFlowCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7597    cout<<"t   = "<<t<<endl; 
7598    cout<<"pe  = "<<pe<<endl; 
7599    cout<<"rci = "<<rci<<endl;
7600    exit(0); 
7601   }
7602   if(!fDiffFlowSquaredCorrelationsPro[t][pe][rci])
7603   {
7604    cout<<"WARNING: fDiffFlowSquaredCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7605    cout<<"t   = "<<t<<endl; 
7606    cout<<"pe  = "<<pe<<endl; 
7607    cout<<"rci = "<<rci<<endl;
7608    exit(0); 
7609   }
7610   for(Int_t power=0;power<2;power++)
7611   {
7612    if(!fDiffFlowSumOfEventWeights[t][pe][power][rci])
7613    {
7614     cout<<"WARNING: fDiffFlowSumOfEventWeights[t][pe][power][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7615     cout<<"t     = "<<t<<endl; 
7616     cout<<"pe    = "<<pe<<endl;
7617     cout<<"power = "<<power<<endl; 
7618     cout<<"rci   = "<<rci<<endl;
7619     exit(0); 
7620    }   
7621   } // end of for(Int_t power=0;power<2;power++)
7622  } // end of for(Int_t rci=0;rci<4;rci++)
7623     
7624  // common:
7625  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta}; 
7626  // transfer 1D profile into 1D histogram:
7627  Double_t correlation = 0.;
7628  Double_t squaredCorrelation = 0.;
7629  Double_t spread = 0.;
7630  Double_t sumOfWeights = 0.; // sum of weights for particular reduced correlations for particular pt or eta bin
7631  Double_t sumOfSquaredWeights = 0.; // sum of squared weights for particular reduced correlations for particular pt or eta bin
7632  Double_t error = 0.; // error = termA * spread * termB
7633                       // termA = (sqrt(sumOfSquaredWeights)/sumOfWeights) 
7634                       // termB = 1/pow(1-termA^2,0.5)
7635  Double_t termA = 0.;                      
7636  Double_t termB = 0.;                      
7637  for(Int_t rci=0;rci<4;rci++) // index of reduced correlation
7638  {
7639   for(Int_t b=1;b<=nBinsPtEta[pe];b++) // number of pt or eta bins
7640   {
7641    if(fDiffFlowCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2 || 
7642       fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2)
7643    {
7644     fDiffFlowCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7645     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7646     continue; // to be improved - should I ignore results in pt bins with one entry for reduced correlations or not?
7647    }  
7648    correlation = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7649    squaredCorrelation = fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7650    if(squaredCorrelation-correlation*correlation >= 0.)
7651    {
7652     spread = pow(squaredCorrelation-correlation*correlation,0.5);
7653    } else
7654      {
7655       cout<<endl;
7656       cout<<Form(" WARNING: Imaginary 'spread' for rci = %d, pe = %d, bin = %d !!!!",rci,pe,b)<<endl;
7657       cout<<endl;
7658      }
7659    sumOfWeights = fDiffFlowSumOfEventWeights[t][pe][0][rci]->GetBinContent(b);
7660    sumOfSquaredWeights = fDiffFlowSumOfEventWeights[t][pe][1][rci]->GetBinContent(b);
7661    if(TMath::Abs(sumOfWeights)>0.){termA = (pow(sumOfSquaredWeights,0.5)/sumOfWeights);}
7662    if(1.-pow(termA,2.)>0.){termB = 1./pow(1.-pow(termA,2.),0.5);} 
7663    error = termA*spread*termB; // final error (unbiased estimator for standard deviation)
7664    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinContent(b,correlation); 
7665    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinError(b,error); 
7666   } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7667  } // end of for(Int_t rci=0;rci<4;rci++)
7668  
7669 } // end of void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
7670
7671 //================================================================================================================================
7672
7673 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7674 {
7675  // store products: <2><2'>, <2><4'>, <2><6'>, <2><8'>, <2'><4>, 
7676  //                 <2'><4'>, <2'><6>, <2'><6'>, <2'><8>, <2'><8'>,
7677  //                 <4><4'>, <4><6'>, <4><8'>, <4'><6>, <4'><6'>, 
7678  //                 <4'><8>, <4'><8'>, <6><6'>, <6><8'>, <6'><8>, 
7679  //                 <6'><8'>, <8><8'>.
7680   
7681  Int_t typeFlag = 0;
7682  Int_t ptEtaFlag = 0;
7683
7684  if(type == "RP")
7685  {
7686   typeFlag = 0;
7687  } else if(type == "POI")
7688    {
7689     typeFlag = 1;
7690    } 
7691      
7692  if(ptOrEta == "Pt")
7693  {
7694   ptEtaFlag = 0;
7695  } else if(ptOrEta == "Eta")
7696    {
7697     ptEtaFlag = 1;
7698    } 
7699   
7700  // shortcuts:
7701  Int_t t = typeFlag;
7702  Int_t pe = ptEtaFlag;
7703      
7704  // common:
7705  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7706  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7707  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7708    
7709  // protections // to be improved (add protection for all pointers in this method)
7710  if(!fIntFlowCorrelationsEBE)
7711  {
7712   cout<<"WARNING: fIntFlowCorrelationsEBE is NULL in AFAWQC::CDFPOC() !!!!"<<endl;
7713   exit(0);
7714  } 
7715  
7716  /*    
7717  Double_t dMult = (*fSpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
7718  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7719  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7720  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7721  */
7722
7723  // e-b-e correlations:
7724  Double_t twoEBE = fIntFlowCorrelationsEBE->GetBinContent(1); // <2>
7725  Double_t fourEBE = fIntFlowCorrelationsEBE->GetBinContent(2); // <4>
7726  Double_t sixEBE = fIntFlowCorrelationsEBE->GetBinContent(3); // <6>
7727  Double_t eightEBE = fIntFlowCorrelationsEBE->GetBinContent(4); // <8>
7728  
7729  // event weights for correlations:
7730  Double_t dW2 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1); // event weight for <2> 
7731  Double_t dW4 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2); // event weight for <4> 
7732  Double_t dW6 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(3); // event weight for <6> 
7733  Double_t dW8 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(4); // event weight for <8> 
7734   
7735  // e-b-e reduced correlations:
7736  Double_t twoReducedEBE = 0.; // <2'>
7737  Double_t fourReducedEBE = 0.; // <4'>
7738  Double_t sixReducedEBE = 0.; // <6'>
7739  Double_t eightReducedEBE = 0.; // <8'> 
7740  
7741  // event weights for reduced correlations:
7742  Double_t dw2 = 0.; // event weight for <2'>
7743  Double_t dw4 = 0.; // event weight for <4'>
7744  //Double_t dw6 = 0.; // event weight for <6'>
7745  //Double_t dw8 = 0.; // event weight for <8'>
7746
7747  // looping over bins:
7748  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7749  {
7750   // e-b-e reduced correlations:
7751   twoReducedEBE = fDiffFlowCorrelationsEBE[t][pe][0]->GetBinContent(b);
7752   fourReducedEBE = fDiffFlowCorrelationsEBE[t][pe][1]->GetBinContent(b);
7753   sixReducedEBE = fDiffFlowCorrelationsEBE[t][pe][2]->GetBinContent(b);
7754   eightReducedEBE = fDiffFlowCorrelationsEBE[t][pe][3]->GetBinContent(b);
7755   
7756   /*
7757   // to be improved (I should not do this here again)
7758   if(type == "RP")
7759   {
7760    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7761    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7762   } else if(type == "POI")
7763     {
7764      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7765      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7766     }
7767   
7768   // event weights for reduced correlations:
7769   dw2 = mp*dMult-mq; // weight for <2'> 
7770   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7771      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.); // weight for <4'>
7772   //dw6 = ...     
7773   //dw8 = ...     
7774   
7775   */
7776   
7777   dw2 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->GetBinContent(b);
7778   dw4 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->GetBinContent(b);
7779  
7780   // storing all products:
7781   fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*twoReducedEBE,dW2*dw2); // storing <2><2'>
7782   fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*twoReducedEBE,dW4*dw2); // storing <4><2'>
7783   fDiffFlowProductOfCorrelationsPro[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*twoReducedEBE,dW6*dw2); // storing <6><2'>
7784   fDiffFlowProductOfCorrelationsPro[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*twoReducedEBE,dW8*dw2); // storing <8><2'>
7785   
7786   // event weight for <4'>:
7787   fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*fourReducedEBE,dW2*dw4); // storing <2><4'>
7788   fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*fourReducedEBE,dw2*dw4); // storing <2'><4'>
7789   fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*fourReducedEBE,dW4*dw4); // storing <4><4'>
7790   fDiffFlowProductOfCorrelationsPro[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*fourReducedEBE,dW6*dw4); // storing <6><4'> 
7791   fDiffFlowProductOfCorrelationsPro[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*fourReducedEBE,dW8*dw4); // storing <8><4'>
7792
7793   // event weight for <6'>:
7794   //dw6 = ...;  
7795   //fDiffFlowProductOfCorrelationsPro[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*sixReducedEBE,dW2*dw6); // storing <2><6'>
7796   //fDiffFlowProductOfCorrelationsPro[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*sixReducedEBE,dw2*dw6); // storing <2'><6'>
7797   //fDiffFlowProductOfCorrelationsPro[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*sixReducedEBE,dW4*dw6); // storing <4><6'>
7798   //fDiffFlowProductOfCorrelationsPro[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*sixReducedEBE,dw4*dw6); // storing <4'><6'> 
7799   //fDiffFlowProductOfCorrelationsPro[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*sixReducedEBE,dW6*dw6); // storing <6><6'>
7800   //fDiffFlowProductOfCorrelationsPro[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightEBE,dw6*dW8); // storing <6'><8>
7801   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7802
7803   // event weight for <8'>:
7804   //dw8 = ...;  
7805   //fDiffFlowProductOfCorrelationsPro[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*eightReducedEBE,dW2*dw8); // storing <2><8'>
7806   //fDiffFlowProductOfCorrelationsPro[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*eightReducedEBE,dw2*dw8); // storing <2'><8'>
7807   //fDiffFlowProductOfCorrelationsPro[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*eightReducedEBE,dW4*dw8); // storing <4><8'>
7808   //fDiffFlowProductOfCorrelationsPro[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*eightReducedEBE,dw4*dw8); // storing <4'><8'> 
7809   //fDiffFlowProductOfCorrelationsPro[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*eightReducedEBE,dW6*dw8); // storing <6><8'>
7810   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7811   //fDiffFlowProductOfCorrelationsPro[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*eightReducedEBE,dW8*dw8); // storing <8><8'> 
7812  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++       
7813      
7814 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7815
7816 //================================================================================================================================
7817     
7818 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta) // to be improved (reimplemented)
7819 {
7820  // a) Calculate unbiased estimators Cov(<2>,<2'>), Cov(<2>,<4'>), Cov(<4>,<2'>), Cov(<4>,<4'>) and Cov(<2'>,<4'>)
7821  //    for covariances V(<2>,<2'>), V(<2>,<4'>), V(<4>,<2'>), V(<4>,<4'>) and V(<2'>,<4'>).  
7822  // b) Store in histogram fDiffFlowCovariances[t][pe][index] for instance the following: 
7823  //
7824  //             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)]
7825  // 
7826  //     where N is the number of events, w_{<2>} is event weight for <2> and w_{<2'>} is event weight for <2'>.
7827  // c) Binning of fDiffFlowCovariances[t][pe][index] is organized as follows:
7828  // 
7829  //     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)] 
7830  //     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)] 
7831  //     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)] 
7832  //     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)] 
7833  //     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)] 
7834  //     ...
7835   
7836  Int_t typeFlag = 0;
7837  Int_t ptEtaFlag = 0;
7838
7839  if(type == "RP")
7840  {
7841   typeFlag = 0;
7842  } else if(type == "POI")
7843    {
7844     typeFlag = 1;
7845    } 
7846      
7847  if(ptOrEta == "Pt")
7848  {
7849   ptEtaFlag = 0;
7850  } else if(ptOrEta == "Eta")
7851    {
7852     ptEtaFlag = 1;
7853    } 
7854   
7855  // shortcuts:
7856  Int_t t = typeFlag;
7857  Int_t pe = ptEtaFlag;
7858      
7859  // common:
7860  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7861  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
7862  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7863  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7864  
7865  // average correlations:
7866  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7867  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7868  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
7869  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
7870  
7871  // sum of weights for correlation:
7872  Double_t sumOfWeightsForTwo = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // sum_{i=1}^{N} w_{<2>}
7873  Double_t sumOfWeightsForFour = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // sum_{i=1}^{N} w_{<4>}
7874  //Double_t sumOfWeightsForSix = fIntFlowSumOfEventWeights[0]->GetBinContent(3); // sum_{i=1}^{N} w_{<6>}
7875  //Double_t sumOfWeightsForEight = fIntFlowSumOfEventWeights[0]->GetBinContent(4); // sum_{i=1}^{N} w_{<8>}
7876  
7877  // average reduced correlations:
7878  Double_t twoReduced = 0.; // <<2'>> 
7879  Double_t fourReduced = 0.; // <<4'>>
7880  //Double_t sixReduced = 0.; // <<6'>>
7881  //Double_t eightReduced = 0.; // <<8'>>
7882
7883  // sum of weights for reduced correlation:
7884  Double_t sumOfWeightsForTwoReduced = 0.; // sum_{i=1}^{N} w_{<2'>}
7885  Double_t sumOfWeightsForFourReduced = 0.; // sum_{i=1}^{N} w_{<4'>}
7886  //Double_t sumOfWeightsForSixReduced = 0.; // sum_{i=1}^{N} w_{<6'>}
7887  //Double_t sumOfWeightsForEightReduced = 0.; // sum_{i=1}^{N} w_{<8'>}
7888   
7889  // product of weights for reduced correlation:
7890  Double_t productOfWeightsForTwoTwoReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<2'>}
7891  Double_t productOfWeightsForTwoFourReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<4'>}
7892  Double_t productOfWeightsForFourTwoReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<2'>}
7893  Double_t productOfWeightsForFourFourReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<4'>}
7894  Double_t productOfWeightsForTwoReducedFourReduced = 0.; // sum_{i=1}^{N} w_{<2'>}w_{<4'>}
7895  // ...
7896  
7897  // products for differential flow:
7898  Double_t twoTwoReduced = 0; // <<2><2'>> 
7899  Double_t twoFourReduced = 0; // <<2><4'>> 
7900  Double_t fourTwoReduced = 0; // <<4><2'>> 
7901  Double_t fourFourReduced = 0; // <<4><4'>> 
7902  Double_t twoReducedFourReduced = 0; // <<2'><4'>> 
7903
7904  // denominators in the expressions for the unbiased estimators for covariances:
7905  // denominator = 1 - term1/(term2*term3)
7906  // prefactor = term1/(term2*term3)
7907  Double_t denominator = 0.; 
7908  Double_t prefactor = 0.;
7909  Double_t term1 = 0.; 
7910  Double_t term2 = 0.; 
7911  Double_t term3 = 0.; 
7912  
7913  // unbiased estimators for covariances for differential flow:
7914  Double_t covTwoTwoReduced = 0.; // Cov(<2>,<2'>)
7915  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(w_{<2>},w_{<2'>})
7916  Double_t covTwoFourReduced = 0.; // Cov(<2>,<4'>)
7917  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(w_{<2>},w_{<4'>})
7918  Double_t covFourTwoReduced = 0.; // Cov(<4>,<2'>)
7919  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(w_{<4>},w_{<2'>})
7920  Double_t covFourFourReduced = 0.; // Cov(<4>,<4'>)
7921  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(w_{<4>},w_{<4'>})
7922  Double_t covTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>)
7923  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(w_{<2'>},w_{<4'>})
7924  
7925  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7926  {
7927   // average reduced corelations:
7928   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
7929   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
7930   // average products:
7931   twoTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->GetBinContent(b);
7932   twoFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->GetBinContent(b);
7933   fourTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->GetBinContent(b);
7934   fourFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->GetBinContent(b);
7935   twoReducedFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->GetBinContent(b);  
7936   // sum of weights for reduced correlations:
7937   sumOfWeightsForTwoReduced = fDiffFlowSumOfEventWeights[t][pe][0][0]->GetBinContent(b);
7938   sumOfWeightsForFourReduced = fDiffFlowSumOfEventWeights[t][pe][0][1]->GetBinContent(b);
7939   // products of weights for correlations:
7940   productOfWeightsForTwoTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->GetBinContent(b); 
7941   productOfWeightsForTwoFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->GetBinContent(b);
7942   productOfWeightsForFourTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->GetBinContent(b);
7943   productOfWeightsForFourFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->GetBinContent(b);
7944   productOfWeightsForTwoReducedFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->GetBinContent(b);
7945   // denominator for the unbiased estimator for covariances: 1 - term1/(term2*term3) 
7946   // prefactor (multiplies Cov's) = term1/(term2*term3)       
7947   // <2>,<2'>:
7948   term1 = productOfWeightsForTwoTwoReduced;      
7949   term2 = sumOfWeightsForTwo;
7950   term3 = sumOfWeightsForTwoReduced;        
7951   if(term2*term3>0.)
7952   {
7953    denominator = 1.-term1/(term2*term3);
7954    prefactor = term1/(term2*term3);
7955    if(TMath::Abs(denominator)>1.e-6)
7956    {
7957     covTwoTwoReduced = (twoTwoReduced-two*twoReduced)/denominator;            
7958     wCovTwoTwoReduced = covTwoTwoReduced*prefactor; 
7959     fDiffFlowCovariances[t][pe][0]->SetBinContent(b,wCovTwoTwoReduced);
7960    }
7961   }
7962   // <2>,<4'>:
7963   term1 = productOfWeightsForTwoFourReduced;      
7964   term2 = sumOfWeightsForTwo;
7965   term3 = sumOfWeightsForFourReduced;        
7966   if(term2*term3>0.)
7967   {
7968    denominator = 1.-term1/(term2*term3);
7969    prefactor = term1/(term2*term3);
7970    if(TMath::Abs(denominator)>1.e-6)
7971    {
7972     covTwoFourReduced = (twoFourReduced-two*fourReduced)/denominator;            
7973     wCovTwoFourReduced = covTwoFourReduced*prefactor; 
7974     fDiffFlowCovariances[t][pe][1]->SetBinContent(b,wCovTwoFourReduced);
7975    }
7976   }
7977   // <4>,<2'>:
7978   term1 = productOfWeightsForFourTwoReduced;      
7979   term2 = sumOfWeightsForFour;
7980   term3 = sumOfWeightsForTwoReduced;        
7981   if(term2*term3>0.)
7982   {
7983    denominator = 1.-term1/(term2*term3);
7984    prefactor = term1/(term2*term3);
7985    if(TMath::Abs(denominator)>1.e-6)
7986    {
7987     covFourTwoReduced = (fourTwoReduced-four*twoReduced)/denominator;            
7988     wCovFourTwoReduced = covFourTwoReduced*prefactor; 
7989     fDiffFlowCovariances[t][pe][2]->SetBinContent(b,wCovFourTwoReduced);
7990    }
7991   }
7992   // <4>,<4'>:
7993   term1 = productOfWeightsForFourFourReduced;      
7994   term2 = sumOfWeightsForFour;
7995   term3 = sumOfWeightsForFourReduced;        
7996   if(term2*term3>0.)
7997   {
7998    denominator = 1.-term1/(term2*term3);
7999    prefactor = term1/(term2*term3);
8000    if(TMath::Abs(denominator)>1.e-6)
8001    {
8002     covFourFourReduced = (fourFourReduced-four*fourReduced)/denominator;            
8003     wCovFourFourReduced = covFourFourReduced*prefactor; 
8004     fDiffFlowCovariances[t][pe][3]->SetBinContent(b,wCovFourFourReduced);
8005    }
8006   }
8007   // <2'>,<4'>:
8008   term1 = productOfWeightsForTwoReducedFourReduced;      
8009   term2 = sumOfWeightsForTwoReduced;
8010   term3 = sumOfWeightsForFourReduced;        
8011   if(term2*term3>0.)
8012   {
8013    denominator = 1.-term1/(term2*term3);
8014    prefactor = term1/(term2*term3);
8015    if(TMath::Abs(denominator)>1.e-6)
8016    {
8017     covTwoReducedFourReduced = (twoReducedFourReduced-twoReduced*fourReduced)/denominator;            
8018     wCovTwoReducedFourReduced = covTwoReducedFourReduced*prefactor; 
8019     fDiffFlowCovariances[t][pe][4]->SetBinContent(b,wCovTwoReducedFourReduced);
8020    }
8021   }   
8022  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8023   
8024 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta)
8025
8026 //================================================================================================================================
8027
8028 void AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, TString ptOrEta)
8029 {
8030  // Calculate final results for differential flow.
8031  
8032  // REMARK: Differential flow calculated in this method is NOT corrected for non-uniform acceptance. 
8033  // This correction, if enabled via setter SetApplyCorrectionForNUA(Bool_t), is applied in the method 
8034  // CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
8035   
8036  Int_t t = 0; // RP or POI
8037  Int_t pe = 0; // pt or eta
8038
8039  if(type == "RP")
8040  {
8041   t = 0;
8042  } else if(type == "POI")
8043    {
8044     t = 1;
8045    } 
8046      
8047  if(ptOrEta == "Pt")
8048  {
8049   pe = 0;
8050  } else if(ptOrEta == "Eta")
8051    {
8052     pe = 1;
8053    } 
8054        
8055  // Common:
8056  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8057  // Correlations:
8058  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
8059  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>> 
8060  // Statistical errors of correlations:
8061  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
8062  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2);   
8063  // Reduced correlations:
8064  Double_t twoReduced = 0.; // <<2'>>
8065  Double_t fourReduced = 0.; // <<4'>>
8066  // Statistical errors of reduced correlations:
8067  Double_t twoReducedError = 0.; 
8068  Double_t fourReducedError = 0.; 
8069  // Covariances:
8070  Double_t wCovTwoFour = 0.; // Cov(<2>,<4>) * prefactor(<2>,<4>)
8071  if(!fForgetAboutCovariances)
8072  {
8073   wCovTwoFour = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(<2>,<4>)
8074  }
8075  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
8076  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
8077  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(<4>,<2'>)
8078  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(<4>,<4'>)
8079  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
8080  // Differential flow:
8081  Double_t v2Prime = 0.; // v'{2}                   
8082  Double_t v4Prime = 0.; // v'{4}
8083  // Statistical error of differential flow:
8084  Double_t v2PrimeError = 0.;                    
8085  Double_t v4PrimeError = 0.; 
8086  // Squared statistical error of differential flow:
8087  Double_t v2PrimeErrorSquared = 0.;                    
8088  Double_t v4PrimeErrorSquared = 0.; 
8089  // Loop over pt or eta bins:
8090  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8091  {
8092   // Reduced correlations and statistical errors:
8093   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
8094   twoReducedError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b);
8095   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
8096   fourReducedError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b);
8097   // Covariances:
8098   if(!fForgetAboutCovariances)
8099   {
8100    wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b);
8101    wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b);
8102    wCovFourTwoReduced = fDiffFlowCovariances[t][pe][2]->GetBinContent(b);
8103    wCovFourFourReduced = fDiffFlowCovariances[t][pe][3]->GetBinContent(b);
8104    wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b);
8105   }
8106   // Differential flow:
8107   // v'{2}:
8108   if(two>0.) 
8109   {
8110    v2Prime = twoReduced/pow(two,0.5);
8111    v2PrimeErrorSquared = (1./4.)*pow(two,-3.)*(pow(twoReduced,2.)*pow(twoError,2.)
8112                        + 4.*pow(two,2.)*pow(twoReducedError,2.)
8113                        - 4.*two*twoReduced*wCovTwoTwoReduced);
8114    if(v2PrimeErrorSquared>0.){v2PrimeError = pow(v2PrimeErrorSquared,0.5);}
8115    if(TMath::Abs(v2Prime)>0.)
8116    {
8117     fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
8118     fDiffFlow[t][pe][0]->SetBinError(b,v2PrimeError);    
8119    }  
8120   } // end of if(two>0.) 
8121   // differential flow:
8122   // v'{4}
8123   if(2.*pow(two,2.)-four > 0.) 
8124   {
8125    v4Prime = (2.*two*twoReduced-fourReduced)/pow(2.*pow(two,2.)-four,3./4.);
8126    v4PrimeErrorSquared = pow(2.*pow(two,2.)-four,-7./2.)
8127                        * (pow(2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced,2.)*pow(twoError,2.)
8128                        + (9./16.)*pow(2.*two*twoReduced-fourReduced,2.)*pow(fourError,2.)
8129                        + 4.*pow(two,2.)*pow(2.*pow(two,2.)-four,2.)*pow(twoReducedError,2.)
8130                        + pow(2.*pow(two,2.)-four,2.)*pow(fourReducedError,2.)                          
8131                        - (3./2.)*(2.*two*twoReduced-fourReduced)
8132                        * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFour
8133                        - 4.*two*(2.*pow(two,2.)-four)
8134                        * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoTwoReduced
8135                        + 2.*(2.*pow(two,2.)-four)
8136                        * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFourReduced
8137                        + 3.*two*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourTwoReduced
8138                        - (3./2.)*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourFourReduced 
8139                        - 4.*two*pow(2.*pow(two,2.)-four,2.)*wCovTwoReducedFourReduced);  
8140    if(v4PrimeErrorSquared>0.){v4PrimeError = pow(v4PrimeErrorSquared,0.5);}        
8141    if(TMath::Abs(v4Prime)>0.)
8142    {
8143     fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);
8144     fDiffFlow[t][pe][1]->SetBinError(b,v4PrimeError);     
8145    }
8146   } // end of if(2.*pow(two,2.)-four > 0.)  
8147  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
8148
8149 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights)
8150
8151 //================================================================================================================================
8152
8153 void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlow(TString type)
8154 {
8155  // Calculate final results for 2D diferential flow.
8156
8157  // to be improved - check pointers used in this method
8158
8159  Int_t t = 0; // RP or POI
8160
8161  if(type == "RP")
8162  {
8163   t = 0;
8164  } else if(type == "POI")
8165    {
8166     t = 1;
8167    } 
8168  
8169  // Differential flow:
8170  Double_t v2Prime = 0.; // v'{2}                   
8171  Double_t v4Prime = 0.; // v'{4}
8172  // Differential cumulants:
8173  Double_t qc2Prime = 0.; // QC{2'}                   
8174  Double_t qc4Prime = 0.; // QC{4'}
8175  // Looping over all (pt,eta) bins and calculating differential flow: 
8176  for(Int_t p=1;p<=fnBinsPt;p++)
8177  {
8178   for(Int_t e=1;e<=fnBinsEta;e++)
8179   {
8180    // QC{2'}:
8181    qc2Prime = f2DDiffFlowCumulants[t][0]->GetBinContent(f2DDiffFlowCumulants[t][0]->GetBin(p,e));
8182    if(qc2Prime>=0.)
8183    {
8184     v2Prime = pow(qc2Prime,0.5);
8185     f2DDiffFlow[t][0]->SetBinContent(f2DDiffFlow[t][0]->GetBin(p,e),v2Prime); 
8186    } 
8187    // QC{4'}:
8188    qc4Prime = f2DDiffFlowCumulants[t][1]->GetBinContent(f2DDiffFlowCumulants[t][1]->GetBin(p,e));
8189    if(qc4Prime<=0.)
8190    {
8191     v4Prime = pow(-1.*qc4Prime,1./4.);
8192     f2DDiffFlow[t][1]->SetBinContent(f2DDiffFlow[t][1]->GetBin(p,e),v4Prime); 
8193    }   
8194   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
8195  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
8196  
8197 } // end of void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlow(TString type)  
8198
8199 //================================================================================================================================
8200
8201 void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
8202 {
8203  // a) Store all flags for integrated flow in profile fIntFlowFlags.
8204  
8205  if(!fIntFlowFlags)
8206  {
8207   cout<<"WARNING: fIntFlowFlags is NULL in AFAWQC::SFFIF() !!!!"<<endl;
8208   exit(0);
8209  } 
8210
8211  // particle weights used or not:
8212  fIntFlowFlags->Fill(0.5,(Int_t)fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights);
8213  // which event weights were used:
8214  if(strcmp(fMultiplicityWeight->Data(),"combinations"))
8215  {
8216   fIntFlowFlags->Fill(1.5,0); // 0 = "combinations" (default)
8217  } else if(strcmp(fMultiplicityWeight->Data(),"unit"))
8218    {
8219     fIntFlowFlags->Fill(1.5,1); // 1 = "unit"   
8220    } else if(strcmp(fMultiplicityWeight->Data(),"multiplicity"))
8221      {
8222       fIntFlowFlags->Fill(1.5,2); // 2 = "multiplicity"        
8223      } 
8224  fIntFlowFlags->Fill(2.5,(Int_t)fApplyCorrectionForNUA);
8225  fIntFlowFlags->Fill(3.5,(Int_t)fPrintFinalResults[0]);
8226  fIntFlowFlags->Fill(4.5,(Int_t)fPrintFinalResults[1]);
8227  fIntFlowFlags->Fill(5.5,(Int_t)fPrintFinalResults[2]);
8228  fIntFlowFlags->Fill(6.5,(Int_t)fPrintFinalResults[3]);
8229  fIntFlowFlags->Fill(7.5,(Int_t)fApplyCorrectionForNUAVsM);
8230  fIntFlowFlags->Fill(8.5,(Int_t)fPropagateErrorAlsoFromNIT);
8231  fIntFlowFlags->Fill(9.5,(Int_t)fCalculateCumulantsVsM);
8232  fIntFlowFlags->Fill(10.5,(Int_t)fMinimumBiasReferenceFlow);
8233  fIntFlowFlags->Fill(11.5,(Int_t)fForgetAboutCovariances);
8234  fIntFlowFlags->Fill(12.5,(Int_t)fStorePhiDistributionForOneEvent); 
8235  fIntFlowFlags->Fill(13.5,(Int_t)fFillMultipleControlHistograms);  
8236  fIntFlowFlags->Fill(14.5,(Int_t)fCalculateAllCorrelationsVsM);  
8237 } // end of void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
8238
8239 //================================================================================================================================
8240
8241 void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
8242 {
8243  // Store all flags for differential flow in the profile fDiffFlowFlags.
8244   
8245  if(!fDiffFlowFlags)
8246  {
8247   printf("\n WARNING (QC): fDiffFlowFlags is NULL in AFAWQC::SDFF() !!!!\n\n");
8248   exit(0);
8249  } 
8250  
8251  fDiffFlowFlags->Fill(0.5,fCalculateDiffFlow); // calculate differential flow
8252  fDiffFlowFlags->Fill(1.5,fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights); // particle weights used or not?
8253  //fDiffFlowFlags->Fill(2.5,""); // which event weight was used? ("combinations", "unit" or "multiplicity") to be improved - finalized
8254  fDiffFlowFlags->Fill(3.5,fApplyCorrectionForNUA); // corrected for non-uniform acceptance or not
8255  fDiffFlowFlags->Fill(4.5,fCalculate2DDiffFlow); // calculate also 2D differential flow vs (pt,eta) 
8256  fDiffFlowFlags->Fill(5.5,fCalculateDiffFlowVsEta); // if you set kFALSE only differential flow vs pt is calculated
8257      
8258 } // end of void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
8259
8260 //================================================================================================================================
8261
8262 void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
8263 {
8264  // Access all pointers to common control and common result histograms and profiles.
8265  
8266  TString sCommonConstantsName = "fCommonConstants";
8267  sCommonConstantsName += fAnalysisLabel->Data();
8268  fCommonConstants = dynamic_cast<TProfile*>(fHistList->FindObject(sCommonConstantsName.Data()));
8269  if(!fCommonConstants)
8270  {
8271   printf("\n WARNING (QC): fCommonConstants is NULL in AFAWQC::GPFCH() !!!!\n\n");
8272   exit(0);
8273  }
8274  
8275  // to be improved - lines bellow can be implemented better.
8276  
8277  TString commonHistsName = "AliFlowCommonHistQC";
8278  commonHistsName += fAnalysisLabel->Data();
8279  AliFlowCommonHist *commonHist = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHistsName.Data()));
8280  if(commonHist) 
8281  {
8282   this->SetCommonHists(commonHist); 
8283   if(fCommonHists->GetHarmonic())
8284   {
8285    fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
8286   } 
8287  } // end of if(commonHist) 
8288  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
8289  commonHists2ndOrderName += fAnalysisLabel->Data();
8290  AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists2ndOrderName.Data()));
8291  if(commonHist2nd) this->SetCommonHists2nd(commonHist2nd);   
8292  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
8293  commonHists4thOrderName += fAnalysisLabel->Data();
8294  AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists4thOrderName.Data()));
8295  if(commonHist4th) this->SetCommonHists4th(commonHist4th);  
8296  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
8297  commonHists6thOrderName += fAnalysisLabel->Data();
8298  AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists6thOrderName.Data()));
8299  if(commonHist6th) this->SetCommonHists6th(commonHist6th);  
8300  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
8301  commonHists8thOrderName += fAnalysisLabel->Data();
8302  AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists8thOrderName.Data()));
8303  if(commonHist8th) this->SetCommonHists8th(commonHist8th); 
8304   
8305  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC"; 
8306  commonHistResults2ndOrderName += fAnalysisLabel->Data(); 
8307  AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>
8308                                               (fHistList->FindObject(commonHistResults2ndOrderName.Data()));
8309  if(commonHistRes2nd) this->SetCommonHistsResults2nd(commonHistRes2nd);   
8310  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
8311  commonHistResults4thOrderName += fAnalysisLabel->Data();
8312  AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>
8313                                               (fHistList->FindObject(commonHistResults4thOrderName.Data()));
8314  if(commonHistRes4th) this->SetCommonHistsResults4th(commonHistRes4th);  
8315  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
8316  commonHistResults6thOrderName += fAnalysisLabel->Data();
8317  AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>
8318                                               (fHistList->FindObject(commonHistResults6thOrderName.Data()));
8319  if(commonHistRes6th) this->SetCommonHistsResults6th(commonHistRes6th);  
8320  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
8321  commonHistResults8thOrderName += fAnalysisLabel->Data();
8322  AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>
8323                                               (fHistList->FindObject(commonHistResults8thOrderName.Data()));  
8324  if(commonHistRes8th) this->SetCommonHistsResults8th(commonHistRes8th);
8325        
8326 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
8327
8328 //================================================================================================================================
8329
8330 void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms() 
8331 {
8332  // Get pointers for histograms with particle weights.
8333
8334  TList *weightsList = dynamic_cast<TList*>(fHistList->FindObject("Weights"));
8335  if(!weightsList){printf("\n WARNING (QC): weightsList is NULL in AFAWQC::GPFPWH() !!!!\n");exit(0);}
8336  this->SetWeightsList(weightsList);
8337  TString fUseParticleWeightsName = "fUseParticleWeightsQC"; // to be improved (hirdwired label QC)
8338  fUseParticleWeightsName += fAnalysisLabel->Data();
8339  TProfile *useParticleWeights = dynamic_cast<TProfile*>(weightsList->FindObject(fUseParticleWeightsName.Data()));
8340  if(useParticleWeights)
8341  {
8342   this->SetUseParticleWeights(useParticleWeights);  
8343   fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
8344   fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
8345   fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3);  
8346   fUseTrackWeights = (Int_t)fUseParticleWeights->GetBinContent(4);  
8347  }
8348 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms(); 
8349
8350 //================================================================================================================================
8351
8352 void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms() 
8353 {
8354  // Get pointers for histograms and profiles relevant for integrated flow:
8355  //  a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults.
8356  //  b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow.
8357  //  c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds. 
8358  //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
8359   
8360  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data member?)
8361  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data member?)
8362  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?)
8363  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?)
8364  
8365  // a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults:
8366  TList *intFlowList = NULL;
8367  intFlowList = dynamic_cast<TList*>(fHistList->FindObject("Integrated Flow"));
8368  if(!intFlowList) 
8369  {
8370   cout<<"WARNING: intFlowList is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8371   exit(0); 
8372  }  
8373   
8374  // b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow:
8375  TString intFlowFlagsName = "fIntFlowFlags";
8376  intFlowFlagsName += fAnalysisLabel->Data();
8377  TProfile *intFlowFlags = dynamic_cast<TProfile*>(intFlowList->FindObject(intFlowFlagsName.Data()));
8378  if(intFlowFlags)
8379  {
8380   this->SetIntFlowFlags(intFlowFlags);  
8381   fApplyCorrectionForNUA = (Bool_t)intFlowFlags->GetBinContent(3); 
8382   fApplyCorrectionForNUAVsM = (Bool_t)intFlowFlags->GetBinContent(8); 
8383   fCalculateCumulantsVsM = (Bool_t)intFlowFlags->GetBinContent(10);  
8384  } else 
8385    {
8386     cout<<"WARNING: intFlowFlags is NULL in FAWQC::GPFIFH() !!!!"<<endl;
8387    }
8388   
8389   // c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds:
8390   TList *intFlowProfiles = NULL;
8391   intFlowProfiles = dynamic_cast<TList*>(intFlowList->FindObject("Profiles"));
8392   if(intFlowProfiles)  
8393   {
8394    // average multiplicities:
8395    TString avMultiplicityName = "fAvMultiplicity";
8396    avMultiplicityName += fAnalysisLabel->Data();
8397    TProfile *avMultiplicity = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(avMultiplicityName.Data()));
8398    if(avMultiplicity) 
8399    {
8400     this->SetAvMultiplicity(avMultiplicity);
8401    } else 
8402      {
8403       cout<<"WARNING: avMultiplicity is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8404      }
8405    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with wrong errors!):
8406    TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
8407    intFlowCorrelationsProName += fAnalysisLabel->Data();
8408    TProfile *intFlowCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsProName.Data()));
8409    if(intFlowCorrelationsPro) 
8410    {
8411     this->SetIntFlowCorrelationsPro(intFlowCorrelationsPro);
8412    } else 
8413      {
8414       cout<<"WARNING: intFlowCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8415      }      
8416    // average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8^2>>:
8417    TString intFlowSquaredCorrelationsProName = "fIntFlowSquaredCorrelationsPro";
8418    intFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
8419    TProfile *intFlowSquaredCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowSquaredCorrelationsProName.Data()));
8420    if(intFlowSquaredCorrelationsPro) 
8421    {
8422     this->SetIntFlowSquaredCorrelationsPro(intFlowSquaredCorrelationsPro);
8423    } else 
8424      {
8425       cout<<"WARNING: intFlowSquaredCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8426      }             
8427    if(fCalculateCumulantsVsM)
8428    {
8429     // Average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (error is wrong here):   
8430     TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
8431     intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
8432     for(Int_t ci=0;ci<4;ci++) // correlation index
8433     {
8434      TProfile *intFlowCorrelationsVsMPro = dynamic_cast<TProfile*>
8435                                         (intFlowProfiles->FindObject(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data())));
8436      if(intFlowCorrelationsVsMPro)
8437      {
8438       this->SetIntFlowCorrelationsVsMPro(intFlowCorrelationsVsMPro,ci);
8439      } else
8440        {
8441         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8442        }   
8443     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
8444     // Average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> versus multiplicity for all events:   
8445     TString intFlowSquaredCorrelationsVsMProName = "fIntFlowSquaredCorrelationsVsMPro";
8446     intFlowSquaredCorrelationsVsMProName += fAnalysisLabel->Data();
8447     for(Int_t ci=0;ci<4;ci++) // correlation index
8448     {
8449      TProfile *intFlowSquaredCorrelationsVsMPro = dynamic_cast<TProfile*>
8450                       (intFlowProfiles->FindObject(Form("%s, %s",intFlowSquaredCorrelationsVsMProName.Data(),squaredCorrelationFlag[ci].Data())));
8451      if(intFlowSquaredCorrelationsVsMPro)
8452      {
8453       this->SetIntFlowSquaredCorrelationsVsMPro(intFlowSquaredCorrelationsVsMPro,ci);
8454      } else
8455        {
8456         cout<<"WARNING: "<<Form("intFlowSquaredCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8457        }   
8458     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
8459    } // end of if(fCalculateCumulantsVsM)
8460    // average all correlations for integrated flow (with wrong errors!):
8461    TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
8462    intFlowCorrelationsAllProName += fAnalysisLabel->Data();
8463    TProfile *intFlowCorrelationsAllPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsAllProName.Data()));
8464    if(intFlowCorrelationsAllPro) 
8465    {
8466     this->SetIntFlowCorrelationsAllPro(intFlowCorrelationsAllPro);
8467    } else 
8468      {
8469       cout<<"WARNING: intFlowCorrelationsAllPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8470      }     
8471    // average extra correlations for integrated flow (which appear only when particle weights are used):
8472    // (to be improved: Weak point in implementation, I am assuming here that method GetPointersForParticleWeightsHistograms() was called)
8473    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
8474    {
8475     TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
8476     intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
8477     TProfile *intFlowExtraCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowExtraCorrelationsProName.Data()));
8478     if(intFlowExtraCorrelationsPro) 
8479     {
8480      this->SetIntFlowExtraCorrelationsPro(intFlowExtraCorrelationsPro);
8481     } else 
8482       {
8483        cout<<"WARNING: intFlowExtraCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8484       }
8485    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)        
8486    // average products of correlations <2>, <4>, <6> and <8>:  
8487    TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
8488    intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
8489    TProfile *intFlowProductOfCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrelationsProName.Data()));
8490    if(intFlowProductOfCorrelationsPro) 
8491    {
8492     this->SetIntFlowProductOfCorrelationsPro(intFlowProductOfCorrelationsPro);
8493    } else 
8494      {
8495       cout<<"WARNING: intFlowProductOfCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8496      }               
8497    // average product of correlations <2>, <4>, <6> and <8> versus multiplicity  
8498    // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
8499    if(fCalculateCumulantsVsM)
8500    {
8501     TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
8502     intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
8503     TString productFlag[6] = {"#LT#LT2#GT#LT4#GT#GT","#LT#LT2#GT#LT6#GT#GT","#LT#LT2#GT#LT8#GT#GT",
8504                               "#LT#LT4#GT#LT6#GT#GT","#LT#LT4#GT#LT8#GT#GT","#LT#LT6#GT#LT8#GT#GT"};
8505     for(Int_t pi=0;pi<6;pi++)
8506     { 
8507      TProfile *intFlowProductOfCorrelationsVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data())));
8508      if(intFlowProductOfCorrelationsVsMPro)
8509      {
8510       this->SetIntFlowProductOfCorrelationsVsMPro(intFlowProductOfCorrelationsVsMPro,pi);
8511      } else
8512        {
8513         cout<<"WARNING: "<<Form("intFlowProductOfCorrelationsVsMPro[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8514        }
8515     } // end of for(Int_t pi=0;pi<6;pi++)
8516    } // end of if(fCalculateCumulantsVsM)
8517    // average correction terms for non-uniform acceptance (with wrong errors!):
8518    for(Int_t sc=0;sc<2;sc++)
8519    {
8520     TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
8521     intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
8522     TProfile *intFlowCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()))));
8523     if(intFlowCorrectionTermsForNUAPro) 
8524     {
8525      this->SetIntFlowCorrectionTermsForNUAPro(intFlowCorrectionTermsForNUAPro,sc);
8526     } else 
8527       {
8528        cout<<"WARNING: intFlowCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8529        cout<<"sc = "<<sc<<endl;
8530       } 
8531     // versus multiplicity:
8532     if(fCalculateCumulantsVsM)
8533     {
8534      TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
8535      TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
8536      intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
8537      for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
8538      {
8539       TProfile *intFlowCorrectionTermsForNUAVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s: #LT#LT%s%s#GT#GT",intFlowCorrectionTermsForNUAVsMProName.Data(),sinCosFlag[sc].Data(),correctionTermFlag[ci].Data())));
8540       if(intFlowCorrectionTermsForNUAVsMPro) 
8541       {
8542        this->SetIntFlowCorrectionTermsForNUAVsMPro(intFlowCorrectionTermsForNUAVsMPro,sc,ci);
8543       } else 
8544         {
8545          cout<<"WARNING: intFlowCorrectionTermsForNUAVsMPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8546          cout<<"sc = "<<sc<<endl;
8547          cout<<"ci = "<<ci<<endl;
8548         }       
8549      } // end of for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
8550     } // end of if(fCalculateCumulantsVsM)
8551    } // end of for(Int_t sc=0;sc<2;sc++)           
8552    // average products of correction terms for NUA:  
8553    TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
8554    intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
8555    TProfile *intFlowProductOfCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrectionTermsForNUAProName.Data()));
8556    if(intFlowProductOfCorrectionTermsForNUAPro) 
8557    {
8558     this->SetIntFlowProductOfCorrectionTermsForNUAPro(intFlowProductOfCorrectionTermsForNUAPro);
8559    } else 
8560      {
8561       cout<<"WARNING: intFlowProductOfCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8562      }     
8563   } else // to if(intFlowProfiles)  
8564     {
8565      cout<<"WARNING: intFlowProfiles is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8566     }
8567    
8568   //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
8569   TList *intFlowResults = NULL;
8570   intFlowResults = dynamic_cast<TList*>(intFlowList->FindObject("Results"));
8571   if(intFlowResults)
8572   {
8573    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!):
8574    TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
8575    intFlowCorrelationsHistName += fAnalysisLabel->Data();
8576    TH1D *intFlowCorrelationsHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsHistName.Data()));
8577    if(intFlowCorrelationsHist) 
8578    {
8579     this->SetIntFlowCorrelationsHist(intFlowCorrelationsHist);
8580    } else 
8581      {
8582       cout<<"WARNING: intFlowCorrelationsHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8583      } 
8584    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!) vs M:    
8585    if(fCalculateCumulantsVsM)
8586    {
8587     TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
8588     intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
8589     for(Int_t ci=0;ci<4;ci++) // correlation index
8590     {
8591      TH1D *intFlowCorrelationsVsMHist = dynamic_cast<TH1D*>
8592                                         (intFlowResults->FindObject(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data())));
8593      if(intFlowCorrelationsVsMHist)
8594      {
8595       this->SetIntFlowCorrelationsVsMHist(intFlowCorrelationsVsMHist,ci);
8596      } else
8597        {
8598         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMHist[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8599        }   
8600     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8601    } // end of if(fCalculateCumulantsVsM)
8602    // average all correlations for integrated flow (with correct errors!):
8603    TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
8604    intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
8605    TH1D *intFlowCorrelationsAllHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsAllHistName.Data()));
8606    if(intFlowCorrelationsAllHist) 
8607    {
8608     this->SetIntFlowCorrelationsAllHist(intFlowCorrelationsAllHist);
8609    } else 
8610      {
8611       cout<<"WARNING: intFlowCorrelationsAllHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8612      }  
8613    // average correction terms for non-uniform acceptance (with correct errors!):
8614    TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
8615    intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
8616    for(Int_t sc=0;sc<2;sc++)
8617    {
8618     TH1D *intFlowCorrectionTermsForNUAHist = dynamic_cast<TH1D*>(intFlowResults->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()))));
8619     if(intFlowCorrectionTermsForNUAHist) 
8620     {
8621      this->SetIntFlowCorrectionTermsForNUAHist(intFlowCorrectionTermsForNUAHist,sc);
8622     } else 
8623       {
8624        cout<<"WARNING: intFlowCorrectionTermsForNUAHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8625        cout<<"sc = "<<sc<<endl;
8626       } 
8627    } // end of for(Int_t sc=0;sc<2;sc++)           
8628    // covariances (multiplied with weight dependent prefactor):
8629    TString intFlowCovariancesName = "fIntFlowCovariances";
8630    intFlowCovariancesName += fAnalysisLabel->Data();
8631    TH1D *intFlowCovariances = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesName.Data()));
8632    if(intFlowCovariances) 
8633    {
8634     this->SetIntFlowCovariances(intFlowCovariances); 
8635    } else 
8636      {
8637       cout<<"WARNING: intFlowCovariances is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8638      } 
8639    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
8640    TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
8641    intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
8642    for(Int_t power=0;power<2;power++)
8643    {
8644     TH1D *intFlowSumOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s",intFlowSumOfEventWeightsName.Data(),powerFlag[power].Data())));
8645     if(intFlowSumOfEventWeights) 
8646     {
8647      this->SetIntFlowSumOfEventWeights(intFlowSumOfEventWeights,power);
8648     } else 
8649       {
8650        cout<<"WARNING: intFlowSumOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8651        cout<<"power = "<<power<<endl;
8652       }                                   
8653    } // end of for(Int_t power=0;power<2;power++)                                                                  
8654    // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
8655    TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
8656    intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
8657    TH1D *intFlowSumOfProductOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsName.Data()));
8658    if(intFlowSumOfProductOfEventWeights) 
8659    {
8660     this->SetIntFlowSumOfProductOfEventWeights(intFlowSumOfProductOfEventWeights);
8661    } else 
8662      {
8663       cout<<"WARNING: intFlowSumOfProductOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8664      } 
8665    // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
8666    // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
8667    if(fCalculateCumulantsVsM)
8668    {
8669     TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
8670     intFlowCovariancesVsMName += fAnalysisLabel->Data();
8671     TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
8672     for(Int_t ci=0;ci<6;ci++)
8673     { 
8674      TH1D *intFlowCovariancesVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data())));
8675      if(intFlowCovariancesVsM)
8676      {
8677       this->SetIntFlowCovariancesVsM(intFlowCovariancesVsM,ci);
8678      } else
8679        {
8680         cout<<"WARNING: "<<Form("intFlowCovariancesVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8681        }    
8682     } // end of for(Int_t ci=0;ci<6;ci++)
8683    } // end of if(fCalculateCumulantsVsM)
8684    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
8685    // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
8686    if(fCalculateCumulantsVsM)
8687    {
8688     TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
8689     intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
8690     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>}"},
8691                              {"#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}"}};
8692     for(Int_t si=0;si<4;si++)
8693     {
8694      for(Int_t power=0;power<2;power++)
8695      {
8696       TH1D *intFlowSumOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data())));
8697       if(intFlowSumOfEventWeightsVsM)
8698       {
8699        this->SetIntFlowSumOfEventWeightsVsM(intFlowSumOfEventWeightsVsM,si,power);
8700       } else
8701         {
8702          cout<<"WARNING: "<<Form("intFlowSumOfEventWeightsVsM[%d][%d]",si,power)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8703         }    
8704      } // end of for(Int_t power=0;power<2;power++)
8705     } // end of for(Int_t si=0;si<4;si++)   
8706    } // end of if(fCalculateCumulantsVsM)
8707    // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
8708    // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
8709    //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
8710    if(fCalculateCumulantsVsM)
8711    {
8712     TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
8713     intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
8714     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>}",
8715                             "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
8716     for(Int_t pi=0;pi<6;pi++)
8717     {
8718      TH1D *intFlowSumOfProductOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data())));
8719      if(intFlowSumOfProductOfEventWeightsVsM)
8720      {
8721       this->SetIntFlowSumOfProductOfEventWeightsVsM(intFlowSumOfProductOfEventWeightsVsM,pi);
8722      } else
8723        {
8724         cout<<"WARNING: "<<Form("intFlowSumOfProductOfEventWeightsVsM[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8725        }
8726     } // end of for(Int_t pi=0;pi<6;pi++)        
8727    } // end of if(fCalculateCumulantsVsM)
8728    // covariances for NUA (multiplied with weight dependent prefactor):
8729    TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
8730    intFlowCovariancesNUAName += fAnalysisLabel->Data();
8731    TH1D *intFlowCovariancesNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesNUAName.Data()));
8732    if(intFlowCovariancesNUA) 
8733    {
8734     this->SetIntFlowCovariancesNUA(intFlowCovariancesNUA); 
8735    } else 
8736      {
8737       cout<<"WARNING: intFlowCovariancesNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8738      } 
8739    // sum of linear and quadratic event weights NUA terms:
8740    TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
8741    intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
8742    for(Int_t sc=0;sc<2;sc++)
8743    {
8744     for(Int_t power=0;power<2;power++)
8745     {
8746      TH1D *intFlowSumOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s, %s",intFlowSumOfEventWeightsNUAName.Data(),powerFlag[power].Data(),sinCosFlag[sc].Data())));
8747      if(intFlowSumOfEventWeightsNUA) 
8748      {
8749       this->SetIntFlowSumOfEventWeightsNUA(intFlowSumOfEventWeightsNUA,sc,power);
8750      } else 
8751        {
8752         cout<<"WARNING: intFlowSumOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8753         cout<<"sc    = "<<sc<<endl;
8754         cout<<"power = "<<power<<endl;
8755        }                                   
8756     } // end of for(Int_t power=0;power<2;power++)                                                                  
8757    } // end of for(Int_t sc=0;sc<2;sc++)     
8758    // sum of products of event weights for NUA terms:  
8759    TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
8760    intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
8761    TH1D *intFlowSumOfProductOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsNUAName.Data()));
8762    if(intFlowSumOfProductOfEventWeightsNUA) 
8763    {
8764     this->SetIntFlowSumOfProductOfEventWeightsNUA(intFlowSumOfProductOfEventWeightsNUA);
8765    } else 
8766      {
8767       cout<<"WARNING: intFlowSumOfProductOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8768      } 
8769    // Final results for reference Q-cumulants:
8770    TString intFlowQcumulantsName = "fIntFlowQcumulants";
8771    intFlowQcumulantsName += fAnalysisLabel->Data();
8772    TH1D *intFlowQcumulants = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsName.Data()));
8773    if(intFlowQcumulants) 
8774    {
8775     this->SetIntFlowQcumulants(intFlowQcumulants);
8776    } else 
8777      {
8778       cout<<"WARNING: intFlowQcumulants is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8779      }  
8780    // Final results for reference Q-cumulants rebinned in M:
8781    if(fCalculateCumulantsVsM)
8782    {
8783     TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
8784     intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
8785     TH1D *intFlowQcumulantsRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsRebinnedInMName.Data()));
8786     if(intFlowQcumulantsRebinnedInM) 
8787     {
8788      this->SetIntFlowQcumulantsRebinnedInM(intFlowQcumulantsRebinnedInM);
8789     } else 
8790       {
8791        cout<<"WARNING: intFlowQcumulantsRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8792       }  
8793    } // end of if(fCalculateCumulantsVsM)
8794    // Ratio between error squared: with/without non-isotropic terms:
8795    TString intFlowQcumulantsErrorSquaredRatioName = "fIntFlowQcumulantsErrorSquaredRatio";
8796    intFlowQcumulantsErrorSquaredRatioName += fAnalysisLabel->Data();
8797    TH1D *intFlowQcumulantsErrorSquaredRatio = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsErrorSquaredRatioName.Data()));
8798    if(intFlowQcumulantsErrorSquaredRatio) 
8799    {
8800     this->SetIntFlowQcumulantsErrorSquaredRatio(intFlowQcumulantsErrorSquaredRatio);
8801    } else 
8802      {
8803       cout<<" WARNING: intntFlowQcumulantsErrorSquaredRatio is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8804      }  
8805    // final results for integrated Q-cumulants versus multiplicity:
8806    TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
8807    if(fCalculateCumulantsVsM)
8808    {
8809     TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
8810     intFlowQcumulantsVsMName += fAnalysisLabel->Data();
8811     for(Int_t co=0;co<4;co++) // cumulant order
8812     {
8813      TH1D *intFlowQcumulantsVsM = dynamic_cast<TH1D*>
8814                                   (intFlowResults->FindObject(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data())));
8815      if(intFlowQcumulantsVsM)
8816      {
8817       this->SetIntFlowQcumulantsVsM(intFlowQcumulantsVsM,co);
8818      } else
8819        {
8820         cout<<"WARNING: "<<Form("intFlowQcumulantsVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8821        }
8822     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8823    } // end of if(fCalculateCumulantsVsM)
8824    // Final reference flow estimates from Q-cumulants:
8825    TString intFlowName = "fIntFlow";
8826    intFlowName += fAnalysisLabel->Data();
8827    TH1D *intFlow = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowName.Data()));
8828    if(intFlow) 
8829    {
8830     this->SetIntFlow(intFlow);
8831    } else 
8832      {
8833       cout<<"WARNING: intFlow is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8834      } 
8835    // Final reference flow estimates from Q-cumulants vs M rebinned in M:
8836    if(fCalculateCumulantsVsM)
8837    {
8838     TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
8839     intFlowRebinnedInMName += fAnalysisLabel->Data();
8840     TH1D *intFlowRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowRebinnedInMName.Data()));
8841     if(intFlowRebinnedInM) 
8842     {
8843      this->SetIntFlowRebinnedInM(intFlowRebinnedInM);
8844     } else 
8845       {
8846        cout<<"WARNING: intFlowRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8847       } 
8848    } // end of if(fCalculateCumulantsVsM)
8849    // integrated flow from Q-cumulants versus multiplicity:
8850    if(fCalculateCumulantsVsM)
8851    {
8852     TString intFlowVsMName = "fIntFlowVsM";
8853     intFlowVsMName += fAnalysisLabel->Data();
8854     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)};
8855     for(Int_t co=0;co<4;co++) // cumulant order
8856     {
8857      TH1D *intFlowVsM = dynamic_cast<TH1D*>
8858                         (intFlowResults->FindObject(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data())));            
8859      if(intFlowVsM)
8860      {
8861       this->SetIntFlowVsM(intFlowVsM,co);
8862      } else
8863        {
8864         cout<<"WARNING: "<<Form("intFlowVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8865        }
8866     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8867    } // end of if(fCalculateCumulantsVsM)
8868    // quantifying detector effects effects to correlations:
8869    TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
8870    intFlowDetectorBiasName += fAnalysisLabel->Data();
8871    TH1D *intFlowDetectorBias = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowDetectorBiasName.Data()));
8872    if(intFlowDetectorBias) 
8873    {
8874     this->SetIntFlowDetectorBias(intFlowDetectorBias);
8875    } else 
8876      {
8877       cout<<"WARNING: intFlowDetectorBias is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8878      } 
8879    // quantifying detector effects effects to correlations vs multiplicity:
8880    if(fCalculateCumulantsVsM)
8881    {
8882     TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
8883     intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
8884     for(Int_t ci=0;ci<4;ci++) // correlation index
8885     {
8886      TH1D *intFlowDetectorBiasVsM = dynamic_cast<TH1D*>
8887                                     (intFlowResults->FindObject(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data())));
8888      if(intFlowDetectorBiasVsM)
8889      {
8890       this->SetIntFlowDetectorBiasVsM(intFlowDetectorBiasVsM,ci);
8891      } else
8892        {
8893         cout<<"WARNING: "<<Form("intFlowDetectorBiasVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8894        }
8895     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8896    } // end of if(fCalculateCumulantsVsM)
8897   } else // to if(intFlowResults)
8898     {
8899      cout<<"WARNING: intFlowResults is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8900     }
8901     
8902 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms()
8903
8904 //================================================================================================================================
8905
8906 void AliFlowAnalysisWithQCumulants::GetPointersFor2DDiffFlowHistograms()
8907 {
8908  // Get pointers for 2D differential flow histograms.
8909  //  a) Check pointers used in this method;
8910  //  b) Get pointers to 2D differential flow lists;
8911  //  c) Get pointers to 2D differential flow profiles;
8912  //  d) Get pointers to 2D differential flow histograms. 
8913
8914  // a) Check pointers used in this method:
8915  if(!fDiffFlowList)
8916  { 
8917   printf("\n WARNING (QC): fDiffFlowList is NULL in AFAWQC::GPF2DDFH() !!!!\n");
8918   printf("               Call method GetPointersForDiffFlowHistograms() first.\n\n");
8919   exit(0);
8920  }
8921  if(!fDiffFlowFlags)
8922  { 
8923   printf("\n WARNING (QC): fDiffFlowFlags is NULL in AFAWQC::GPF2DDFH() !!!!\n\n");
8924   printf("               Call method GetPointersForDiffFlowHistograms() first.\n\n");
8925   exit(0);
8926  }
8927  
8928  // b) Get pointers to 2D differential flow lists:
8929  this->SetCalculate2DDiffFlow((Bool_t)fDiffFlowFlags->GetBinContent(5)); // to be improved - hardwired 5
8930  if(!fCalculate2DDiffFlow){return;}
8931  TString typeFlag[2] = {"RP","POI"}; 
8932  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
8933  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
8934  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
8935  // Base list: 
8936  TString diffFlow2DListName = "2D"; 
8937  diffFlow2DListName += fAnalysisLabel->Data();
8938  fDiffFlow2D = dynamic_cast<TList*>(fDiffFlowList->FindObject(diffFlow2DListName.Data()));
8939  if(!fDiffFlow2D)
8940  { 
8941   printf("\n WARNING (QC): fDiffFlow2D is NULL in AFAWQC::GPFDFH() !!!!\n\n");
8942   exit(0);
8943  }
8944  // Lists holding profiles with 2D correlations: 
8945  TString s2DDiffFlowCorrelationsProListName = "Profiles with 2D correlations"; 
8946  s2DDiffFlowCorrelationsProListName += fAnalysisLabel->Data(); // to be improved
8947  for(Int_t t=0;t<2;t++)
8948  {
8949   f2DDiffFlowCorrelationsProList[t] = dynamic_cast<TList*>(fDiffFlow2D->FindObject(Form("Profiles with 2D correlations (%s)",typeFlag[t].Data())));
8950   if(!f2DDiffFlowCorrelationsProList[t])
8951   { 
8952    printf("\n WARNING (QC): f2DDiffFlowCorrelationsProList[%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t);
8953    exit(0);
8954   }
8955  } // end of for(Int_t t=0;t<2;t++) 
8956  
8957  // c) Get pointers to 2D differential flow profiles:
8958  TString s2DDiffFlowCorrelationsProName = "f2DDiffFlowCorrelationsPro";
8959  s2DDiffFlowCorrelationsProName += fAnalysisLabel->Data();
8960  for(Int_t t=0;t<2;t++) // type: RP or POI
8961  { 
8962   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8963   {
8964    f2DDiffFlowCorrelationsPro[t][rci] = dynamic_cast<TProfile2D*>(f2DDiffFlowCorrelationsProList[t]->FindObject(Form("%s, %s, %s",s2DDiffFlowCorrelationsProName.Data(),typeFlag[t].Data(),reducedCorrelationIndex[rci].Data())));
8965    if(!f2DDiffFlowCorrelationsPro[t][rci])
8966    {
8967     printf("\n WARNING (QC): f2DDiffFlowCorrelationsPro[%i][%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t,rci);
8968     exit(0);   
8969    } else
8970      {
8971       this->Set2DDiffFlowCorrelationsPro(f2DDiffFlowCorrelationsPro[t][rci],t,rci);
8972      } 
8973   } // end of for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8974  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
8975
8976  // d) Get pointers to 2D differential flow histograms: 
8977  TString s2DDiffFlowCumulantsName = "f2DDiffFlowCumulants";
8978  s2DDiffFlowCumulantsName += fAnalysisLabel->Data();
8979  TString s2DDiffFlowName = "f2DDiffFlow";
8980  s2DDiffFlowName += fAnalysisLabel->Data();
8981  for(Int_t t=0;t<2;t++) // type: RP or POI
8982  { 
8983   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8984   {
8985    // 2D differential cumulants:
8986    f2DDiffFlowCumulants[t][rci] = dynamic_cast<TH2D*>(f2DDiffFlowCorrelationsProList[t]->FindObject(Form("%s, %s, %s",s2DDiffFlowCumulantsName.Data(),typeFlag[t].Data(),differentialCumulantIndex[rci].Data())));
8987    if(!f2DDiffFlowCumulants[t][rci])
8988    {
8989     printf("\n WARNING (QC): f2DDiffFlowCumulants[%i][%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t,rci);
8990     exit(0);   
8991    } else
8992      {
8993       this->Set2DDiffFlowCumulants(f2DDiffFlowCumulants[t][rci],t,rci);
8994      } 
8995    // 2D differential flow:
8996    f2DDiffFlow[t][rci] = dynamic_cast<TH2D*>(f2DDiffFlowCorrelationsProList[t]->FindObject(Form("%s, %s, %s",s2DDiffFlowName.Data(),typeFlag[t].Data(),differentialFlowIndex[rci].Data())));
8997    if(!f2DDiffFlow[t][rci])
8998    {
8999     printf("\n WARNING (QC): f2DDiffFlow[%i][%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t,rci);
9000     exit(0);   
9001    } else
9002      {
9003       this->Set2DDiffFlow(f2DDiffFlow[t][rci],t,rci);
9004      } 
9005   } // end of for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9006  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
9007   
9008 } // end of void AliFlowAnalysisWithQCumulants::GetPointersFor2DDiffFlowHistograms()
9009
9010 //================================================================================================================================
9011
9012 void AliFlowAnalysisWithQCumulants::GetPointersForOtherDiffCorrelators()
9013 {
9014  // Get pointers for other differential correlators.
9015  //  a) Get pointer to list with other differential correlators;
9016  //  b) Declare local flags;
9017  //  c) Get pointers to other differential profiles.
9018
9019  if(!fCalculateDiffFlow){return;} // TBI: This must eventually be moved somewhere else 
9020
9021  // a) Get pointer to list with other differential correlators:
9022  fOtherDiffCorrelatorsList = dynamic_cast<TList*>(fHistList->FindObject("Other differential correlators"));  
9023  if(!fOtherDiffCorrelatorsList)
9024  { 
9025   printf("\n WARNING (QC): fOtherDiffCorrelatorsList is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9026   exit(0);
9027  }
9028  
9029  // b) Declare local flags: // (to be improved - promoted to data members)
9030  TString typeFlag[2] = {"RP","POI"}; 
9031  TString ptEtaFlag[2] = {"p_{T}","#eta"};
9032  TString sinCosFlag[2] = {"sin","cos"}; 
9033   
9034  // c) Get pointers to other differential profiles:
9035  TString otherDiffCorrelatorsName = "fOtherDiffCorrelators";
9036  otherDiffCorrelatorsName += fAnalysisLabel->Data();
9037  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9038  { 
9039   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9040   {
9041    for(Int_t sc=0;sc<2;sc++) // sin or cos
9042    {
9043     for(Int_t ci=0;ci<1;ci++) // correlator index
9044     {
9045      fOtherDiffCorrelators[t][pe][sc][ci] = dynamic_cast<TProfile*>(fOtherDiffCorrelatorsList->FindObject(Form("%s, %s, %s, %s, ci = %d",otherDiffCorrelatorsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),ci+1))); 
9046      if(!fOtherDiffCorrelators[t][pe][sc][ci])
9047      {
9048       printf("\n WARNING (QC): fOtherDiffCorrelators[%i][%i][%i][%i] is NULL in AFAWQC::GPFODC() !!!!\n\n",t,pe,sc,ci);
9049       exit(0);       
9050      } else
9051        {
9052         this->SetOtherDiffCorrelators(fOtherDiffCorrelators[t][pe][sc][ci],t,pe,sc,ci);     
9053        } 
9054     } // end of for(Int_t ci=0;ci<1;ci++) // correlator index
9055    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9056   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9057  } // end of for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9058   
9059 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForOtherDiffCorrelators()
9060
9061 //================================================================================================================================
9062
9063 void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
9064 {
9065  // Get pointer to all objects relevant for differential flow.
9066  //  a) Get pointer to base list for differential flow fDiffFlowList;
9067  //  b) Get pointer to profile fDiffFlowFlags holding all flags for differential flow. Access and set some flags;
9068  //  c) Get pointers to nested lists fDiffFlowListProfiles and fDiffFlowListResults;
9069  //  d) Define flags locally (to be improved: should I promote these flags to data members?);
9070  //  e) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
9071  //  f) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
9072  
9073  // a) Get pointer to base list for differential flow fDiffFlowList:
9074  fDiffFlowList = dynamic_cast<TList*>(fHistList->FindObject("Differential Flow"));  
9075  if(!fDiffFlowList)
9076  { 
9077   printf("\n WARNING (QC): fDiffFlowList is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9078   exit(0);
9079  }
9080  
9081  // b) Get pointer to profile fDiffFlowFlags holding all flags for differential flow. Access and set some flags:
9082  TString diffFlowFlagsName = "fDiffFlowFlags";
9083  diffFlowFlagsName += fAnalysisLabel->Data();
9084  fDiffFlowFlags = dynamic_cast<TProfile*>(fDiffFlowList->FindObject(diffFlowFlagsName.Data()));
9085  if(fDiffFlowFlags)
9086  {
9087   this->SetCalculateDiffFlow((Bool_t)fDiffFlowFlags->GetBinContent(1)); // to be improved - hardwired 1
9088   this->SetCalculateDiffFlowVsEta((Bool_t)fDiffFlowFlags->GetBinContent(6)); // to be improved - hardwired 6
9089  } else
9090    {
9091     printf("\n WARNING (QC): fDiffFlowFlags is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9092     printf("\n             Flags in method Finish() are wrong.\n\n");
9093     exit(0);
9094    } 
9095    
9096  if(!fCalculateDiffFlow){return;} // IMPORTANT: do not move this anywhere above in this method (to be improved)   
9097   
9098  // c) Get pointers to nested lists fDiffFlowListProfiles and fDiffFlowListResults:
9099  //  List holding nested lists holding profiles:
9100  TList *diffFlowListProfiles = NULL;
9101  diffFlowListProfiles = dynamic_cast<TList*>(fDiffFlowList->FindObject("Profiles"));
9102  if(!diffFlowListProfiles)
9103  { 
9104   printf("\n WARNING (QC): diffFlowListProfiles is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9105   exit(0);
9106  }
9107  //  List holding nested lists holding histograms with final results:
9108  TList *diffFlowListResults = NULL;
9109  diffFlowListResults = dynamic_cast<TList*>(fDiffFlowList->FindObject("Results"));
9110  if(!diffFlowListResults)
9111  { 
9112   printf("\n WARNING (QC): diffFlowListResults is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9113   exit(0);
9114  }
9115  
9116  // d) Define flags locally (to be improved: should I promote these flags to data members?):
9117  TString typeFlag[2] = {"RP","POI"}; 
9118  TString ptEtaFlag[2] = {"p_{T}","#eta"};
9119  TString powerFlag[2] = {"linear","quadratic"};
9120  TString sinCosFlag[2] = {"sin","cos"};
9121  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
9122  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
9123  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
9124  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"}; 
9125  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
9126  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
9127   
9128  // e) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold:
9129  // correlations:
9130  TList *diffFlowCorrelationsProList[2][2] = {{NULL}};
9131  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
9132  diffFlowCorrelationsProName += fAnalysisLabel->Data();
9133  TProfile *diffFlowCorrelationsPro[2][2][4] = {{{NULL}}}; 
9134  // squared correlations:  
9135  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
9136  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data(); 
9137  TProfile *diffFlowSquaredCorrelationsPro[2][2][4] = {{{NULL}}};  
9138  // products of correlations:
9139  TList *diffFlowProductOfCorrelationsProList[2][2] = {{NULL}};
9140  TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
9141  diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
9142  TProfile *diffFlowProductOfCorrelationsPro[2][2][8][8] = {{{{NULL}}}};   
9143  // corrections:
9144  TList *diffFlowCorrectionsProList[2][2] = {{NULL}};
9145  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
9146  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();  
9147  TProfile *diffFlowCorrectionTermsForNUAPro[2][2][2][10] = {{{{NULL}}}};   
9148  for(Int_t t=0;t<2;t++)
9149  {
9150   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++)
9151   {
9152    diffFlowCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9153    if(!diffFlowCorrelationsProList[t][pe])
9154    { 
9155     cout<<"WARNING: diffFlowCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9156     cout<<"t = "<<t<<endl;
9157     cout<<"pe = "<<pe<<endl;
9158     exit(0);
9159    }
9160    for(Int_t ci=0;ci<4;ci++) // correlation index
9161    {
9162     // reduced correlations:
9163     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())));
9164     if(diffFlowCorrelationsPro[t][pe][ci])
9165     {
9166      this->SetDiffFlowCorrelationsPro(diffFlowCorrelationsPro[t][pe][ci],t,pe,ci);
9167     } else
9168       {
9169        cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9170        cout<<"t  = "<<t<<endl;
9171        cout<<"pe = "<<pe<<endl;   
9172        cout<<"ci = "<<ci<<endl;
9173       }     
9174     // reduced squared correlations:
9175     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())));
9176     if(diffFlowSquaredCorrelationsPro[t][pe][ci])
9177     {
9178      this->SetDiffFlowSquaredCorrelationsPro(diffFlowSquaredCorrelationsPro[t][pe][ci],t,pe,ci);
9179     } else
9180       {
9181        cout<<"WARNING: diffFlowSquaredCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9182        cout<<"t  = "<<t<<endl;
9183        cout<<"pe = "<<pe<<endl;   
9184        cout<<"ci = "<<ci<<endl;
9185       }       
9186    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
9187    // products of correlations:    
9188    diffFlowProductOfCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()))); 
9189    if(!diffFlowProductOfCorrelationsProList[t][pe])
9190    { 
9191     cout<<"WARNING: ddiffFlowProductOfCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9192     cout<<"t = "<<t<<endl;
9193     cout<<"pe = "<<pe<<endl;
9194     exit(0);
9195    }
9196    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9197    {
9198     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9199     {
9200      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())));
9201      if(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2])
9202      {
9203       this->SetDiffFlowProductOfCorrelationsPro(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2],t,pe,mci1,mci2);
9204      } else
9205        {
9206         cout<<"WARNING: diffFlowProductOfCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9207         cout<<"t    = "<<t<<endl;
9208         cout<<"pe   = "<<pe<<endl;   
9209         cout<<"mci1 = "<<mci1<<endl;
9210         cout<<"mci2 = "<<mci2<<endl;
9211        }
9212      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9213     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9214    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
9215    // corrections:
9216    diffFlowCorrectionsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9217    if(!diffFlowCorrectionsProList[t][pe])
9218    { 
9219     cout<<"WARNING: diffFlowCorrectionsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9220     cout<<"t = "<<t<<endl;
9221     cout<<"pe = "<<pe<<endl;
9222     exit(0);
9223    }
9224    // correction terms for NUA:
9225    for(Int_t sc=0;sc<2;sc++) // sin or cos
9226    {
9227     for(Int_t cti=0;cti<9;cti++) // correction term index
9228     {
9229      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)));
9230      if(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti])
9231      {
9232       this->SetDiffFlowCorrectionTermsForNUAPro(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti],t,pe,sc,cti);
9233      } else
9234        {
9235         cout<<"WARNING: diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9236         cout<<"t   = "<<t<<endl;
9237         cout<<"pe  = "<<pe<<endl;   
9238         cout<<"sc  = "<<sc<<endl;
9239         cout<<"cti = "<<cti<<endl;
9240        }    
9241     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
9242    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9243    // ...
9244   } // end of for(Int_t pe=0;pe<2;pe++)
9245  } // end of for(Int_t t=0;t<2;t++)
9246   
9247  // f) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold:
9248  // reduced correlations:
9249  TList *diffFlowCorrelationsHistList[2][2] = {{NULL}};
9250  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
9251  diffFlowCorrelationsHistName += fAnalysisLabel->Data();  
9252  TH1D *diffFlowCorrelationsHist[2][2][4] = {{{NULL}}};
9253  // corrections for NUA:
9254  TList *diffFlowCorrectionsHistList[2][2] = {{NULL}};
9255  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
9256  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();  
9257  TH1D *diffFlowCorrectionTermsForNUAHist[2][2][2][10] = {{{{NULL}}}};
9258  // differential Q-cumulants:
9259  TList *diffFlowCumulantsHistList[2][2] = {{NULL}};
9260  TString diffFlowCumulantsName = "fDiffFlowCumulants";
9261  diffFlowCumulantsName += fAnalysisLabel->Data();  
9262  TH1D *diffFlowCumulants[2][2][4] = {{{NULL}}};
9263  // detector bias to differential Q-cumulants:
9264  TList *diffFlowDetectorBiasHistList[2][2] = {{NULL}};
9265  TString diffFlowDetectorBiasName = "fDiffFlowDetectorBias";
9266  diffFlowDetectorBiasName += fAnalysisLabel->Data();  
9267  TH1D *diffFlowDetectorBias[2][2][4] = {{{NULL}}}; 
9268  // differential flow estimates from Q-cumulants:
9269  TList *diffFlowHistList[2][2] = {{NULL}};
9270  TString diffFlowName = "fDiffFlow";
9271  diffFlowName += fAnalysisLabel->Data();  
9272  TH1D *diffFlow[2][2][4] = {{{NULL}}};
9273  // differential covariances:
9274  TList *diffFlowCovariancesHistList[2][2] = {{NULL}};
9275  TString diffFlowCovariancesName = "fDiffFlowCovariances";
9276  diffFlowCovariancesName += fAnalysisLabel->Data();  
9277  TH1D *diffFlowCovariances[2][2][5] = {{{NULL}}};
9278  for(Int_t t=0;t<2;t++) // type: RP or POI
9279  { 
9280   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9281   {
9282    // reduced correlations:
9283    diffFlowCorrelationsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9284    if(!diffFlowCorrelationsHistList[t][pe])
9285    { 
9286     cout<<"WARNING: diffFlowCorrelationsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9287     cout<<"t = "<<t<<endl;
9288     cout<<"pe = "<<pe<<endl;
9289     exit(0);
9290    }
9291    for(Int_t index=0;index<4;index++) 
9292    {
9293     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())));
9294     if(diffFlowCorrelationsHist[t][pe][index])
9295     {
9296      this->SetDiffFlowCorrelationsHist(diffFlowCorrelationsHist[t][pe][index],t,pe,index);
9297     } else 
9298       {
9299        cout<<"WARNING: diffFlowCorrelationsHist[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9300        cout<<"t     = "<<t<<endl;
9301        cout<<"pe    = "<<pe<<endl;
9302        cout<<"index = "<<index<<endl;
9303        exit(0);       
9304       } 
9305    } // end of for(Int_t index=0;index<4;index++)
9306    // corrections:
9307    diffFlowCorrectionsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9308    if(!diffFlowCorrectionsHistList[t][pe])
9309    { 
9310     cout<<"WARNING: diffFlowCorrectionsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9311     cout<<"t = "<<t<<endl;
9312     cout<<"pe = "<<pe<<endl;
9313     exit(0);
9314    }
9315    // correction terms for NUA:
9316    for(Int_t sc=0;sc<2;sc++) // sin or cos
9317    {
9318     for(Int_t cti=0;cti<9;cti++) // correction term index
9319     {
9320      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)));
9321      if(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti])
9322      {
9323       this->SetDiffFlowCorrectionTermsForNUAHist(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti],t,pe,sc,cti);
9324      } else
9325        {
9326         cout<<"WARNING: diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9327         cout<<"t   = "<<t<<endl;
9328         cout<<"pe  = "<<pe<<endl;   
9329         cout<<"sc  = "<<sc<<endl;
9330         cout<<"cti = "<<cti<<endl;
9331        }    
9332     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
9333    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9334    // ...
9335    // differential Q-cumulants:
9336    diffFlowCumulantsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9337    if(!diffFlowCumulantsHistList[t][pe])
9338    { 
9339     cout<<"WARNING: diffFlowCumulantsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9340     cout<<"t  = "<<t<<endl;
9341     cout<<"pe = "<<pe<<endl;
9342     exit(0);
9343    }
9344    for(Int_t index=0;index<4;index++) 
9345    {
9346     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())));
9347     if(diffFlowCumulants[t][pe][index])
9348     {
9349      this->SetDiffFlowCumulants(diffFlowCumulants[t][pe][index],t,pe,index);
9350     } else 
9351       {
9352        cout<<"WARNING: diffFlowCumulants[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9353        cout<<"t     = "<<t<<endl;
9354        cout<<"pe    = "<<pe<<endl;
9355        cout<<"index = "<<index<<endl;
9356        exit(0);       
9357       } 
9358    } // end of for(Int_t index=0;index<4;index++)
9359    // Detector bias to differential Q-cumulants:
9360    diffFlowDetectorBiasHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Detector bias (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9361    if(!diffFlowDetectorBiasHistList[t][pe])
9362    { 
9363     cout<<"WARNING: diffFlowDetectorBiasHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9364     cout<<"t  = "<<t<<endl;
9365     cout<<"pe = "<<pe<<endl;
9366     exit(0);
9367    }
9368    for(Int_t index=0;index<4;index++) 
9369    {
9370     diffFlowDetectorBias[t][pe][index] = dynamic_cast<TH1D*>(diffFlowDetectorBiasHistList[t][pe]->FindObject(Form("%s, %s, %s, %s",diffFlowDetectorBiasName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialCumulantIndex[index].Data())));
9371     if(diffFlowDetectorBias[t][pe][index])
9372     {
9373      this->SetDiffFlowDetectorBias(diffFlowDetectorBias[t][pe][index],t,pe,index);
9374     } else 
9375       {
9376        cout<<"WARNING: diffFlowDetectorBias[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9377        cout<<"t     = "<<t<<endl;
9378        cout<<"pe    = "<<pe<<endl;
9379        cout<<"index = "<<index<<endl;
9380        exit(0);       
9381       } 
9382    } // end of for(Int_t index=0;index<4;index++)
9383    // differential flow estimates from Q-cumulants:
9384    diffFlowHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9385    if(!diffFlowHistList[t][pe])
9386    { 
9387     cout<<"WARNING: diffFlowHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9388     cout<<"t  = "<<t<<endl;
9389     cout<<"pe = "<<pe<<endl;
9390     exit(0);
9391    }
9392    for(Int_t index=0;index<4;index++) 
9393    {
9394     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())));
9395     if(diffFlow[t][pe][index])
9396     {
9397      this->SetDiffFlow(diffFlow[t][pe][index],t,pe,index);
9398     } else 
9399       {
9400        cout<<"WARNING: diffFlow[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9401        cout<<"t     = "<<t<<endl;
9402        cout<<"pe    = "<<pe<<endl;
9403        cout<<"index = "<<index<<endl;
9404        exit(0);       
9405       } 
9406    } // end of for(Int_t index=0;index<4;index++)
9407    // differential covariances:
9408    diffFlowCovariancesHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9409    if(!diffFlowCovariancesHistList[t][pe])
9410    { 
9411     cout<<"WARNING: diffFlowCovariancesHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9412     cout<<"t  = "<<t<<endl;
9413     cout<<"pe = "<<pe<<endl;
9414     exit(0);
9415    }
9416    for(Int_t covIndex=0;covIndex<5;covIndex++) 
9417    {
9418     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())));
9419     if(diffFlowCovariances[t][pe][covIndex])
9420     {
9421      this->SetDiffFlowCovariances(diffFlowCovariances[t][pe][covIndex],t,pe,covIndex);
9422     } else 
9423       {
9424        cout<<"WARNING: diffFlowCovariances[t][pe][covIndex] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9425        cout<<"t        = "<<t<<endl;
9426        cout<<"pe       = "<<pe<<endl;
9427        cout<<"covIndex = "<<covIndex<<endl;
9428        exit(0);       
9429       } 
9430    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index    
9431   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9432  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
9433  // sum of event weights for reduced correlations:
9434  TList *diffFlowSumOfEventWeightsHistList[2][2][2] = {{{NULL}}};
9435  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
9436  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
9437  TH1D *diffFlowSumOfEventWeights[2][2][2][4] = {{{{NULL}}}};
9438  for(Int_t t=0;t<2;t++) // type is RP or POI
9439  { 
9440   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9441   { 
9442    for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
9443    {
9444     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())));
9445     if(!diffFlowSumOfEventWeightsHistList[t][pe][p])
9446     { 
9447      cout<<"WARNING: diffFlowSumOfEventWeightsHistList[t][pe][p] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9448      cout<<"t     = "<<t<<endl;
9449      cout<<"pe    = "<<pe<<endl;
9450      cout<<"power = "<<p<<endl;
9451      exit(0);
9452     }
9453     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
9454     {
9455      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())));    
9456      if(diffFlowSumOfEventWeights[t][pe][p][ew])
9457      {
9458       this->SetDiffFlowSumOfEventWeights(diffFlowSumOfEventWeights[t][pe][p][ew],t,pe,p,ew);
9459      } else 
9460        {
9461         cout<<"WARNING: diffFlowSumOfEventWeights[t][pe][p][ew] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9462         cout<<"t     = "<<t<<endl;
9463         cout<<"pe    = "<<pe<<endl;
9464         cout<<"power = "<<p<<endl;
9465         cout<<"ew    = "<<ew<<endl;
9466         exit(0);       
9467        } 
9468     }
9469    } // end of for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
9470   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9471  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
9472  //  
9473  TList *diffFlowSumOfProductOfEventWeightsHistList[2][2] = {{NULL}};
9474  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
9475  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
9476  TH1D *diffFlowSumOfProductOfEventWeights[2][2][8][8] = {{{{NULL}}}};
9477  for(Int_t t=0;t<2;t++) // type is RP or POI
9478  { 
9479   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9480   { 
9481    diffFlowSumOfProductOfEventWeightsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9482    if(!diffFlowSumOfProductOfEventWeightsHistList[t][pe])
9483    { 
9484     cout<<"WARNING: diffFlowSumOfProductOfEventWeightsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9485     cout<<"t     = "<<t<<endl;
9486     cout<<"pe    = "<<pe<<endl;
9487     exit(0);
9488    }
9489    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9490    {
9491     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9492     {
9493      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())));    
9494       if(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2])
9495       {
9496        this->SetDiffFlowSumOfProductOfEventWeights(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2],t,pe,mci1,mci2);
9497       } else 
9498         {
9499          cout<<"WARNING: diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9500          cout<<"t    = "<<t<<endl;
9501          cout<<"pe   = "<<pe<<endl;
9502          cout<<"mci1 = "<<mci1<<endl;
9503          cout<<"mci2 = "<<mci2<<endl;
9504          exit(0);       
9505         } 
9506      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9507     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9508    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9509   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9510  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
9511
9512 } // end void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
9513
9514 //================================================================================================================================
9515
9516 void AliFlowAnalysisWithQCumulants::BookEverythingFor2DDifferentialFlow()
9517 {
9518  // Book all objects needed for 2D differential flow.
9519  //  a) Define flags locally (to be improved: should I promote flags to data members?);
9520  //  b) Book e-b-e quantities;
9521  //  c) Book 2D profiles;
9522  //  d) Book 2D histograms.
9523  
9524  if(!fCalculate2DDiffFlow){return;}
9525
9526  // a) Define flags locally (to be improved: should I promote flags to data members?):
9527  TString typeFlag[2] = {"RP","POI"}; 
9528  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
9529  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
9530  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
9531   
9532  // b) Book e-b-e quantities: 
9533  TProfile2D styleRe("typeMultiplePowerRe","typeMultiplePowerRe",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9534  TProfile2D styleIm("typeMultiplePowerIm","typeMultiplePowerIm",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9535  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
9536  { 
9537   for(Int_t m=0;m<4;m++)
9538   {
9539    for(Int_t k=0;k<9;k++)
9540    {
9541     fReRPQ2dEBE[t][m][k] = (TProfile2D*)styleRe.Clone(Form("typeFlag%dmultiple%dpower%dRe",t,m,k)); 
9542     fImRPQ2dEBE[t][m][k] = (TProfile2D*)styleIm.Clone(Form("typeFlag%dmultiple%dpower%dIm",t,m,k));
9543    }
9544   } 
9545  } 
9546  TProfile2D styleS("typePower","typePower",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9547  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
9548  { 
9549   for(Int_t k=0;k<9;k++)
9550   {
9551    fs2dEBE[t][k] = (TProfile2D*)styleS.Clone(Form("typeFlag%dpower%d",t,k));
9552   }
9553  }
9554
9555  // c) Book 2D profiles:
9556  TString s2DDiffFlowCorrelationsProName = "f2DDiffFlowCorrelationsPro";
9557  s2DDiffFlowCorrelationsProName += fAnalysisLabel->Data();
9558  for(Int_t t=0;t<2;t++) // type: RP or POI
9559  { 
9560   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9561   {
9562    f2DDiffFlowCorrelationsPro[t][rci] = new TProfile2D(Form("%s, %s, %s",s2DDiffFlowCorrelationsProName.Data(),typeFlag[t].Data(),reducedCorrelationIndex[rci].Data()),Form("%s, %s, %s",s2DDiffFlowCorrelationsProName.Data(),typeFlag[t].Data(),reducedCorrelationIndex[rci].Data()),fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax,"");
9563    f2DDiffFlowCorrelationsPro[t][rci]->Sumw2();
9564    f2DDiffFlowCorrelationsPro[t][rci]->SetXTitle("p_{t}");
9565    f2DDiffFlowCorrelationsPro[t][rci]->SetYTitle("#eta");
9566    f2DDiffFlowCorrelationsProList[t]->Add(f2DDiffFlowCorrelationsPro[t][rci]); 
9567   } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9568  } // end of for(Int_t t=0;t<2;t++) // type: RP or POIs
9569
9570  // d) Book 2D histograms:
9571  TString s2DDiffFlowCumulantsName = "f2DDiffFlowCumulants";
9572  s2DDiffFlowCumulantsName += fAnalysisLabel->Data();
9573  TString s2DDiffFlowName = "f2DDiffFlow";
9574  s2DDiffFlowName += fAnalysisLabel->Data();
9575  for(Int_t t=0;t<2;t++) // type: RP or POI
9576  { 
9577   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9578   {
9579    // 2D diferential cumulants:
9580    f2DDiffFlowCumulants[t][rci] = new TH2D(Form("%s, %s, %s",s2DDiffFlowCumulantsName.Data(),typeFlag[t].Data(),differentialCumulantIndex[rci].Data()),Form("%s, %s, %s",s2DDiffFlowCumulantsName.Data(),typeFlag[t].Data(),differentialCumulantIndex[rci].Data()),fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9581    f2DDiffFlowCumulants[t][rci]->SetXTitle("p_{t}");
9582    f2DDiffFlowCumulants[t][rci]->SetYTitle("#eta");
9583    f2DDiffFlowCorrelationsProList[t]->Add(f2DDiffFlowCumulants[t][rci]); //  to be improved - moved to another list 
9584    // 2D differential flow:
9585    f2DDiffFlow[t][rci] = new TH2D(Form("%s, %s, %s",s2DDiffFlowName.Data(),typeFlag[t].Data(),differentialFlowIndex[rci].Data()),Form("%s, %s, %s",s2DDiffFlowName.Data(),typeFlag[t].Data(),differentialFlowIndex[rci].Data()),fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9586    f2DDiffFlow[t][rci]->SetXTitle("p_{t}");
9587    f2DDiffFlow[t][rci]->SetYTitle("#eta");
9588    f2DDiffFlowCorrelationsProList[t]->Add(f2DDiffFlow[t][rci]); //  to be improved - moved to another list 
9589   } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9590  } // end of for(Int_t t=0;t<2;t++) // type: RP or POIs
9591
9592 } // void AliFlowAnalysisWithQCumulants::BookEverythingFor2DDifferentialFlow()
9593
9594 //================================================================================================================================
9595
9596 void AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
9597 {
9598  // Book all histograms and profiles needed for differential flow.
9599  //  a) Book profile to hold all flags for differential flow;
9600  //  b) Define flags locally (to be improved: should I promote flags to data members?);
9601  //  c) Book e-b-e quantities;
9602  //  d) Book profiles;
9603  //  e) Book histograms holding final results. 
9604  
9605  // a) Book profile to hold all flags for differential flow:
9606  TString diffFlowFlagsName = "fDiffFlowFlags";
9607  diffFlowFlagsName += fAnalysisLabel->Data();
9608  fDiffFlowFlags = new TProfile(diffFlowFlagsName.Data(),"Flags for differential flow",6,0,6);
9609  fDiffFlowFlags->SetTickLength(-0.01,"Y");
9610  fDiffFlowFlags->SetMarkerStyle(25);
9611  fDiffFlowFlags->SetLabelSize(0.04,"X");
9612  fDiffFlowFlags->SetLabelOffset(0.02,"Y");
9613  fDiffFlowFlags->GetXaxis()->SetBinLabel(1,"Calculate diff. flow"); 
9614  fDiffFlowFlags->GetXaxis()->SetBinLabel(2,"Particle weights");
9615  fDiffFlowFlags->GetXaxis()->SetBinLabel(3,"Event weights");
9616  fDiffFlowFlags->GetXaxis()->SetBinLabel(4,"Correct for NUA");
9617  fDiffFlowFlags->GetXaxis()->SetBinLabel(5,"Calculate 2D diff. flow");
9618  fDiffFlowFlags->GetXaxis()->SetBinLabel(6,"Calculate diff. flow vs eta");
9619  fDiffFlowList->Add(fDiffFlowFlags);
9620
9621  if(!fCalculateDiffFlow){return;}
9622   
9623  // b) Define flags locally (to be improved: should I promote flags to data members?): 
9624  TString typeFlag[2] = {"RP","POI"}; 
9625  TString ptEtaFlag[2] = {"p_{T}","#eta"};
9626  TString powerFlag[2] = {"linear","quadratic"};
9627  TString sinCosFlag[2] = {"sin","cos"};
9628  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
9629  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
9630  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
9631  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"};
9632  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
9633  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
9634  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9635  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9636  Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9637    
9638  // c) Book e-b-e quantities:
9639  // Event-by-event r_{m*n,k}(pt,eta), p_{m*n,k}(pt,eta) and q_{m*n,k}(pt,eta)
9640  // Explanantion of notation:
9641  //  1.) n is harmonic, m is multiple of harmonic;
9642  //  2.) k is power of particle weight;
9643  //  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);   
9644  //  4.) p_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for POIs in particular (pt,eta) bin 
9645  //                          (if i-th POI is also RP, than it is weighted with w_i^k);   
9646  //  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 
9647  //                          (i-th RP&&POI is weighted with w_i^k)            
9648   
9649  // 1D:
9650  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP && POI )
9651  { 
9652   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9653   {
9654    for(Int_t m=0;m<4;m++) // multiple of harmonic
9655    {
9656     for(Int_t k=0;k<9;k++) // power of particle weight
9657     {
9658      fReRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),
9659                                              Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9660      fImRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),
9661                                              Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9662     }
9663    }
9664   }
9665  } 
9666  // to be improved (add explanation of fs1dEBE[t][pe][k]):   
9667  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
9668  { 
9669   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9670   {
9671    for(Int_t k=0;k<9;k++) // power of particle weight
9672    {
9673     fs1dEBE[t][pe][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),
9674                                      Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9675    }
9676   }
9677  }
9678  // correction terms for nua:
9679  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9680  { 
9681   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9682   {
9683    for(Int_t sc=0;sc<2;sc++) // sin or cos
9684    {
9685     for(Int_t cti=0;cti<9;cti++) // correction term index
9686     {
9687      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = new TH1D(Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),
9688                                              Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9689     }
9690    }
9691   }
9692  } 
9693  // reduced correlations e-b-e:
9694  TString diffFlowCorrelationsEBEName = "fDiffFlowCorrelationsEBE";
9695  diffFlowCorrelationsEBEName += fAnalysisLabel->Data();
9696  for(Int_t t=0;t<2;t++) // type: RP or POI
9697  { 
9698   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9699   {
9700    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9701    {
9702     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]);
9703    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
9704   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9705  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9706  // event weights for reduced correlations e-b-e:
9707  TString diffFlowEventWeightsForCorrelationsEBEName = "fDiffFlowEventWeightsForCorrelationsEBE";
9708  diffFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
9709  for(Int_t t=0;t<2;t++) // type: RP or POI
9710  { 
9711   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9712   {
9713    for(Int_t rci=0;rci<4;rci++) // event weight for reduced correlation index
9714    {
9715     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]);
9716    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
9717   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9718  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9719       
9720  // d) Book profiles;
9721  // reduced correlations:
9722  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
9723  diffFlowCorrelationsProName += fAnalysisLabel->Data();
9724  // reduced squared correlations:
9725  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
9726  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
9727  // corrections terms:
9728  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
9729  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
9730  // reduced correlations:
9731  for(Int_t t=0;t<2;t++) // type: RP or POI
9732  { 
9733   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9734   {
9735    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9736    {
9737     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");
9738     fDiffFlowCorrelationsPro[t][pe][rci]->Sumw2();
9739     fDiffFlowCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
9740     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
9741    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9742   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9743  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9744  // reduced squared correlations:
9745  for(Int_t t=0;t<2;t++) // type: RP or POI
9746  { 
9747   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9748   {
9749    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9750    {
9751     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");
9752     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->Sumw2();
9753     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
9754     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowSquaredCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
9755    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9756   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9757  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9758  // correction terms for nua:
9759  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9760  { 
9761   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9762   {
9763    for(Int_t sc=0;sc<2;sc++) // sin or cos
9764    {
9765     for(Int_t cti=0;cti<9;cti++) // correction term index
9766     {
9767      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]); 
9768      fDiffFlowCorrectionsProList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]);
9769     }
9770    }
9771   }
9772  } 
9773  // Other differential correlators:
9774  TString otherDiffCorrelatorsName = "fOtherDiffCorrelators";
9775  otherDiffCorrelatorsName += fAnalysisLabel->Data();
9776  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9777  { 
9778   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9779   {
9780    for(Int_t sc=0;sc<2;sc++) // sin or cos
9781    {
9782     for(Int_t ci=0;ci<1;ci++) // correlator index
9783     {
9784      fOtherDiffCorrelators[t][pe][sc][ci] = new TProfile(Form("%s, %s, %s, %s, ci = %d",otherDiffCorrelatorsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),ci+1),Form("%s, %s, %s, %s, ci = %d",otherDiffCorrelatorsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),ci+1),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9785      fOtherDiffCorrelators[t][pe][sc][ci]->Sumw2();
9786      fOtherDiffCorrelatorsList->Add(fOtherDiffCorrelators[t][pe][sc][ci]);
9787     }
9788    }
9789   }
9790  }  
9791  // e) Book histograms holding final results. 
9792  // reduced correlations:
9793  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
9794  diffFlowCorrelationsHistName += fAnalysisLabel->Data();
9795  // corrections terms:
9796  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
9797  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
9798  // differential covariances:
9799  TString diffFlowCovariancesName = "fDiffFlowCovariances";
9800  diffFlowCovariancesName += fAnalysisLabel->Data();
9801  // differential Q-cumulants:
9802  TString diffFlowCumulantsName = "fDiffFlowCumulants";
9803  diffFlowCumulantsName += fAnalysisLabel->Data();
9804  // Detector bias to differential Q-cumulants:
9805  TString diffFlowDetectorBiasName = "fDiffFlowDetectorBias";
9806  diffFlowDetectorBiasName += fAnalysisLabel->Data();
9807  // differential flow:
9808  TString diffFlowName = "fDiffFlow";
9809  diffFlowName += fAnalysisLabel->Data();
9810  for(Int_t t=0;t<2;t++) // type: RP or POI
9811  { 
9812   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9813   {
9814    for(Int_t index=0;index<4;index++) 
9815    {
9816     // reduced correlations:
9817     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]);
9818     fDiffFlowCorrelationsHist[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9819     fDiffFlowCorrelationsHistList[t][pe]->Add(fDiffFlowCorrelationsHist[t][pe][index]); 
9820     // differential Q-cumulants:
9821     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]);
9822     fDiffFlowCumulants[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9823     fDiffFlowCumulantsHistList[t][pe]->Add(fDiffFlowCumulants[t][pe][index]); 
9824     // Detector bias to differential Q-cumulants:
9825     fDiffFlowDetectorBias[t][pe][index] = new TH1D(Form("%s, %s, %s, %s",diffFlowDetectorBiasName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialCumulantIndex[index].Data()),Form("%s, %s, %s, %s",diffFlowDetectorBiasName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),differentialCumulantIndex[index].Data()),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]);
9826     fDiffFlowDetectorBias[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9827     fDiffFlowDetectorBias[t][pe][index]->SetTitle(Form("#frac{corrected}{measured} %s",differentialCumulantIndex[index].Data()));
9828     fDiffFlowDetectorBiasHistList[t][pe]->Add(fDiffFlowDetectorBias[t][pe][index]); 
9829     // differential flow estimates from Q-cumulants:
9830     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]);
9831     fDiffFlow[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9832     fDiffFlowHistList[t][pe]->Add(fDiffFlow[t][pe][index]); 
9833    } // end of for(Int_t index=0;index<4;index++) 
9834    for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index 
9835    {
9836     // differential covariances:
9837     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]);
9838     fDiffFlowCovariances[t][pe][covIndex]->SetXTitle(ptEtaFlag[pe].Data());
9839     fDiffFlowCovariancesHistList[t][pe]->Add(fDiffFlowCovariances[t][pe][covIndex]); 
9840    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index
9841    // products of both types of correlations: 
9842    TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
9843    diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
9844    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9845    {
9846     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9847     {
9848      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]); 
9849      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
9850      fDiffFlowProductOfCorrelationsProList[t][pe]->Add(fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]); 
9851      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9852     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9853    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
9854   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9855  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9856  // sums of event weights for reduced correlations: 
9857  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
9858  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
9859  for(Int_t t=0;t<2;t++) // type is RP or POI
9860  { 
9861   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9862   { 
9863    for(Int_t p=0;p<2;p++) // power of weights is either 1 or 2
9864    {
9865     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
9866     {
9867      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]); 
9868      fDiffFlowSumOfEventWeights[t][pe][p][ew]->SetXTitle(ptEtaFlag[pe].Data());
9869      fDiffFlowSumOfEventWeightsHistList[t][pe][p]->Add(fDiffFlowSumOfEventWeights[t][pe][p][ew]); // to be improved (add dedicated list to hold all this)
9870     }
9871    }
9872   }
9873  } 
9874  // sum of products of event weights for both types of correlations: 
9875  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
9876  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
9877  for(Int_t t=0;t<2;t++) // type is RP or POI
9878  {
9879   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9880   { 
9881    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9882    {
9883     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9884     {
9885      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]); 
9886      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
9887      fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->Add(fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]); 
9888      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9889     }
9890    }
9891   }
9892  } 
9893  // correction terms for nua:
9894  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9895  { 
9896   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9897   {
9898    for(Int_t sc=0;sc<2;sc++) // sin or cos
9899    {
9900     for(Int_t cti=0;cti<9;cti++) // correction term index
9901     {
9902      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]); 
9903      fDiffFlowCorrectionsHistList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]);
9904     }
9905    }
9906   }
9907  } 
9908           
9909 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
9910
9911 //================================================================================================================================
9912
9913 void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
9914 {
9915  // Calculate generalized Q-cumulants (cumulants corrected for non-unifom acceptance).
9916  
9917  // Isotropic cumulants:
9918  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1);
9919  Double_t qc2Error = fIntFlowQcumulants->GetBinError(1);
9920  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2);
9921  Double_t qc4Error = fIntFlowQcumulants->GetBinError(2);
9922  //Double_t qc6 = fIntFlowQcumulants->GetBinContent(3);
9923  //Double_t qc6Error = fIntFlowQcumulants->GetBinError(3);
9924  //Double_t qc8 = fIntFlowQcumulants->GetBinContent(4);
9925  //Double_t qc8Error = fIntFlowQcumulants->GetBinError(4);
9926  
9927  // Measured 2-, 4-, 6- and 8-particle correlations:
9928  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
9929  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <<2>>
9930  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
9931  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <<4>>
9932  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
9933  //Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <<6>>
9934  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
9935  //Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <<8>>
9936   
9937  // Non-isotropic terms:
9938  Double_t c1 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
9939  Double_t c1Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(1); // statistical error of <<cos(n*phi1)>>
9940  Double_t c2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
9941  Double_t c2Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(2); // statistical error of <<cos(n*(phi1+phi2))>>
9942  Double_t c3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
9943  Double_t c3Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(3); // statistical error of <<cos(n*(phi1-phi2-phi3))>>
9944  Double_t s1 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
9945  Double_t s1Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(1); // statistical error of <<sin(n*phi1)>>
9946  Double_t s2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
9947  Double_t s2Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(2); // statistical error of <<sin(n*(phi1+phi2))>>
9948  Double_t s3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
9949  Double_t s3Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(3); // statistical error of <<sin(n*(phi1-phi2-phi3))>>
9950  
9951  // Shortcuts:
9952  Double_t a1 = 2.*pow(c1,2.)+2.*pow(s1,2.)-two;
9953  Double_t a2 = 6.*pow(c1,3.)-2.*c1*c2+c3+6.*c1*pow(s1,2.)-2.*s1*s2-4.*c1*two;
9954  Double_t a3 = 2.*pow(s1,2.)-2.*pow(c1,2.)+c2;
9955  Double_t a4 = 6.*pow(s1,3.)+6.*pow(c1,2.)*s1+2.*c2*s1-2.*c1*s2-s3-4.*s1*two;
9956  Double_t a5 = 4.*c1*s1-s2;
9957  
9958  // Covariances (including weight dependent prefactor):
9959  Double_t wCov1 = 0.; // w*Cov(<2>,<cos(phi)) 
9960  Double_t wCov2 = 0.; // w*Cov(<2>,<sin(phi))
9961  Double_t wCov3 = 0.; // w*Cov(<cos(phi),<sin(phi))
9962  Double_t wCov4 = 0.; // w*Cov(<2>,<4>) 
9963  Double_t wCov5 = 0.; // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
9964  Double_t wCov6 = 0.; // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9965  Double_t wCov7 = 0.; // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
9966  Double_t wCov8 = 0.; // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9967  Double_t wCov9 = 0.; // w*Cov(<4>,<cos(#phi)>
9968  Double_t wCov10 = 0.; // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
9969  Double_t wCov11 = 0.; // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9970  Double_t wCov12 = 0.; // w*Cov(<4>,<sin(#phi)>
9971  Double_t wCov13 = 0.; // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
9972  Double_t wCov14 = 0.; // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9973  Double_t wCov15 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9974  Double_t wCov16 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9975  Double_t wCov17 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9976  Double_t wCov18 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9977  Double_t wCov19 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9978  Double_t wCov20 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
9979  Double_t wCov21 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
9980  Double_t wCov22 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9981  Double_t wCov23 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9982  Double_t wCov24 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9983  Double_t wCov25 = 0.; // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
9984  Double_t wCov26 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
9985  Double_t wCov27 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9986  Double_t wCov28 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9987  if(!fForgetAboutCovariances)
9988  {
9989   wCov1 = fIntFlowCovariancesNUA->GetBinContent(1); // w*Cov(<2>,<cos(phi)) 
9990   wCov2 = fIntFlowCovariancesNUA->GetBinContent(2); // w*Cov(<2>,<sin(phi))
9991   wCov3 = fIntFlowCovariancesNUA->GetBinContent(3); // w*Cov(<cos(phi),<sin(phi))
9992   wCov4 = fIntFlowCovariances->GetBinContent(1); // w*Cov(<2>,<4>) 
9993   wCov5 = fIntFlowCovariancesNUA->GetBinContent(4); // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
9994   wCov6 = fIntFlowCovariancesNUA->GetBinContent(6); // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
9995   wCov7 = fIntFlowCovariancesNUA->GetBinContent(5); // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
9996   wCov8 = fIntFlowCovariancesNUA->GetBinContent(7); // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
9997   wCov9 = fIntFlowCovariancesNUA->GetBinContent(8); // w*Cov(<4>,<cos(#phi)>
9998   wCov10 = fIntFlowCovariancesNUA->GetBinContent(10); // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
9999   wCov11 = fIntFlowCovariancesNUA->GetBinContent(12); // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10000   wCov12 = fIntFlowCovariancesNUA->GetBinContent(9); // w*Cov(<4>,<sin(#phi)>
10001   wCov13 = fIntFlowCovariancesNUA->GetBinContent(11); // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
10002   wCov14 = fIntFlowCovariancesNUA->GetBinContent(13); // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10003   wCov15 = fIntFlowCovariancesNUA->GetBinContent(14); // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
10004   wCov16 = fIntFlowCovariancesNUA->GetBinContent(16); // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10005   wCov17 = fIntFlowCovariancesNUA->GetBinContent(15); // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
10006   wCov18 = fIntFlowCovariancesNUA->GetBinContent(17); // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10007   wCov19 = fIntFlowCovariancesNUA->GetBinContent(23); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10008   wCov20 = fIntFlowCovariancesNUA->GetBinContent(18); // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
10009   wCov21 = fIntFlowCovariancesNUA->GetBinContent(22); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
10010   wCov22 = fIntFlowCovariancesNUA->GetBinContent(24); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10011   wCov23 = fIntFlowCovariancesNUA->GetBinContent(20); // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10012   wCov24 = fIntFlowCovariancesNUA->GetBinContent(25); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10013   wCov25 = fIntFlowCovariancesNUA->GetBinContent(27); // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
10014   wCov26 = fIntFlowCovariancesNUA->GetBinContent(19); // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
10015   wCov27 = fIntFlowCovariancesNUA->GetBinContent(21); // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10016   wCov28 = fIntFlowCovariancesNUA->GetBinContent(26); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10017  } // end of if(!fForgetAboutCovariances)
10018  
10019  // Calculating generalized QC{2}:
10020  //  Generalized QC{2}:
10021  Double_t gQC2 = two - pow(c1,2.) - pow(s1,2.);
10022  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(1,gQC2);} 
10023  //  Statistical error of generalized QC{2}:
10024  Double_t gQC2ErrorSquared = pow(twoError,2.)+4.*pow(c1,2.)*pow(c1Error,2.)
10025                            + 4.*pow(s1,2.)*pow(s1Error,2.)
10026                            - 4*c1*wCov1-4*s1*wCov2 
10027                            + 8.*c1*s1*wCov3;
10028  //  Store ratio of error squared - with/without NUA terms:
10029  Double_t ratioErrorSquaredQC2 = 0.;
10030  if(fIntFlowQcumulants->GetBinError(1)>0.)
10031  { 
10032   ratioErrorSquaredQC2 = (gQC2ErrorSquared/pow(fIntFlowQcumulants->GetBinError(1),2.));
10033   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(1,ratioErrorSquaredQC2);
10034  }
10035  //  If enabled, store error by including non-isotropic terms:                         
10036  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10037  {
10038   if(gQC2ErrorSquared>=0.)
10039   {
10040    fIntFlowQcumulants->SetBinError(1,pow(gQC2ErrorSquared,0.5));
10041   } else
10042     {
10043      fIntFlowQcumulants->SetBinError(1,0.);
10044      cout<<endl;
10045      cout<<" WARNING (QC): Statistical error of generalized QC{2} is imaginary !!!!"<<endl;
10046      cout<<endl;
10047     }   
10048  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10049  // Quantify detector bias to QC{2}:
10050  if(TMath::Abs(qc2)>0.)
10051  {
10052   fIntFlowDetectorBias->SetBinContent(1,gQC2/qc2); 
10053   if(qc2Error>0.)
10054   {
10055    Double_t errorSquared = gQC2ErrorSquared/pow(qc2,2.)+pow(gQC2,2.)*pow(qc2Error,2.)/pow(qc2,4.);
10056    if(errorSquared>0.)
10057    {
10058     fIntFlowDetectorBias->SetBinError(1,pow(errorSquared,0.5));  
10059    }
10060   }
10061  } // end of if(TMath::Abs(qc2)>0.)
10062
10063  // Calculating generalized QC{4}:
10064  //  Generalized QC{4}:
10065  Double_t gQC4 = four-2.*pow(two,2.)
10066                - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
10067                + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
10068                + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
10069  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(2,gQC4);}   
10070  //  Statistical error of generalized QC{4}:
10071  Double_t gQC4ErrorSquared = 16.*pow(a1,2.)*pow(twoError,2.)+pow(fourError,2.)+16.*pow(a2,2.)*pow(c1Error,2.)
10072                            + 4.*pow(a3,2.)*pow(c2Error,2.)+16.*pow(c1,2.)*pow(c3Error,2.)
10073                            + 16.*pow(a4,2.)*pow(s1Error,2.)+4.*pow(a5,2.)*pow(s2Error,2.)
10074                            + 16.*pow(s1,2.)*pow(s3Error,2.)+8.*a1*wCov4-32.*a1*a2*wCov1
10075                            - 16.*a3*a1*wCov5-32.*c1*a1*wCov6-32.*a1*a4*wCov2+16.*a5*a1*wCov7
10076                            + 32.*s1*a1*wCov8-8.*a2*wCov9-4.*a3*wCov10-8.*c1*wCov11-8.*a4*wCov12
10077                            + 4.*a5*wCov13+8.*s1*wCov14+16.*a3*a2*wCov15+32.*c1*a2*wCov16+32.*a2*a4*wCov3
10078                            - 16.*a5*a2*wCov17-32.*s1*a2*wCov18+16.*c1*a3*wCov19+16.*a3*a4*wCov20
10079                            - 8.*a3*a5*wCov21-16.*s1*a3*wCov22+32.*c1*a4*wCov23-16.*c1*a5*wCov24
10080                            - 32.*c1*s1*wCov25-16.*a5*a4*wCov26-32.*s1*a4*wCov27+16.*s1*a5*wCov28;
10081  //  Store ratio of error squared - with/without NUA terms:
10082  Double_t ratioErrorSquaredQC4 = 0.;
10083  if(fIntFlowQcumulants->GetBinError(2)>0.)
10084  { 
10085   ratioErrorSquaredQC4 = (gQC4ErrorSquared/pow(fIntFlowQcumulants->GetBinError(2),2.));
10086   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(2,ratioErrorSquaredQC4);
10087  }                          
10088  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10089  {
10090   if(gQC4ErrorSquared>=0.)
10091   {
10092    fIntFlowQcumulants->SetBinError(2,pow(gQC4ErrorSquared,0.5));
10093   } else
10094     {
10095      fIntFlowQcumulants->SetBinError(2,0.);
10096      cout<<endl;
10097      cout<<" WARNING (QC): Statistical error of generalized QC{4} is imaginary !!!!"<<endl;
10098      cout<<endl;
10099     }   
10100  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10101  // Quantify detector bias to QC{4}:
10102  if(TMath::Abs(qc4)>0.)
10103  {
10104   fIntFlowDetectorBias->SetBinContent(2,gQC4/qc4); 
10105   if(qc4Error>0.)
10106   {
10107    Double_t errorSquared = gQC4ErrorSquared/pow(qc4,2.)+pow(gQC4,2.)*pow(qc4Error,2.)/pow(qc4,4.);
10108    if(errorSquared>0.)
10109    {
10110     fIntFlowDetectorBias->SetBinError(2,pow(errorSquared,0.5));  
10111    }
10112   }
10113  } // end of if(TMath::Abs(qc4)>0.)
10114
10115
10116  // .... to be improved (continued for 6th and 8th order) ....            
10117  
10118      
10119  // versus multiplicity:
10120  if(fCalculateCumulantsVsM) // to be improved - propagate error for nua terms vs M
10121  { 
10122   Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
10123   Double_t value[4] = {0.}; // QCs vs M
10124   Double_t error[4] = {0.}; // error of QCs vs M
10125   Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
10126   Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
10127   for(Int_t b=1;b<=nBins;b++)
10128   {
10129    // Measured correlations:
10130    two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> vs M
10131    four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>> vs M
10132    // Isotropic cumulants:
10133    qc2 = two;
10134    qc4 = four-2.*pow(two,2.);
10135    // Non-isotropic terms:
10136    c1 = fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b); // <<cos(n*phi1)>>
10137    c2 = fIntFlowCorrectionTermsForNUAVsMPro[1][1]->GetBinContent(b); // <<cos(n*(phi1+phi2))>>
10138    c3 = fIntFlowCorrectionTermsForNUAVsMPro[1][2]->GetBinContent(b); // <<cos(n*(phi1-phi2-phi3))>>
10139    s1 = fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b); // <<sin(n*phi1)>>
10140    s2 = fIntFlowCorrectionTermsForNUAVsMPro[0][1]->GetBinContent(b); // <<sin(n*(phi1+phi2))>>
10141    s3 = fIntFlowCorrectionTermsForNUAVsMPro[0][2]->GetBinContent(b); // <<sin(n*(phi1-phi2-phi3))>>
10142    // Generalized QC{2} vs M:
10143    gQC2 = two - pow(c1,2.) - pow(s1,2.); 
10144    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[0]->SetBinContent(b,gQC2);}   
10145    // Generalized QC{4} vs M:  
10146    gQC4 = four-2.*pow(two,2.)
10147                  - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
10148                  + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
10149                  + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
10150    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[1]->SetBinContent(b,gQC4);}   
10151    // Detector bias vs M:
10152    if(TMath::Abs(qc2)>0.)
10153    {
10154     fIntFlowDetectorBiasVsM[0]->SetBinContent(b,gQC2/qc2); 
10155    } // end of if(TMath::Abs(qc2)>0.)
10156    if(TMath::Abs(qc4)>0.)
10157    {
10158     fIntFlowDetectorBiasVsM[1]->SetBinContent(b,gQC4/qc4); 
10159    } // end of if(TMath::Abs(qc4)>0.)  
10160    // Rebin in M:
10161    for(Int_t co=0;co<4;co++)
10162    {
10163     value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
10164     error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
10165     if(error[co]>0.)
10166     {
10167      dSum1[co]+=value[co]/(error[co]*error[co]);
10168      dSum2[co]+=1./(error[co]*error[co]);
10169     }
10170    } // end of for(Int_t co=0;co<4;co++) 
10171   } // end of for(Int_t b=1;b<=nBins;b++)
10172   // Store rebinned Q-cumulants:
10173   if(fApplyCorrectionForNUAVsM)
10174   {
10175    for(Int_t co=0;co<4;co++)
10176    {
10177     if(dSum2[co]>0.)
10178     {
10179      fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
10180      fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
10181     }
10182    } // end of for(Int_t co=0;co<4;co++)
10183   } // end of if(fApplyCorrectionForNUAVsM)
10184  } // end of if(fCalculateCumulantsVsM) 
10185      
10186 } // end of void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
10187  
10188 //================================================================================================================================
10189
10190 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow() 
10191 {
10192  // From profile fIntFlowCorrectionTermsForNUAPro[sc] access measured correction terms for NUA
10193  // and their spread, correctly calculate the statistical errors and store the final 
10194  // results and statistical errors for correction terms for NUA in histogram fIntFlowCorrectionTermsForNUAHist[sc].
10195  //
10196  // Remark: Statistical error of correction temrs is calculated as:
10197  //
10198  //          statistical error = termA * spread * termB:
10199  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
10200  //          termB = 1/sqrt(1-termA^2)   
10201  
10202  TString sinCosFlag[2] = {"sin","cos"}; // to be improved - promore this to data member?
10203  TString nonisotropicTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
10204     
10205  for(Int_t sc=0;sc<2;sc++) // sin or cos correction terms 
10206  {
10207   for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
10208   {
10209    Double_t correction = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci);
10210    Double_t spread = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinError(ci);
10211    Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeightsNUA[sc][0]->GetBinContent(ci);
10212    Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeightsNUA[sc][1]->GetBinContent(ci);
10213    Double_t termA = 0.;
10214    Double_t termB = 0.;
10215    if(TMath::Abs(sumOfLinearEventWeights)>1.e-44)
10216    {
10217     termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
10218    } else
10219      {
10220       cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in AFAWQC::FCTFNIF() !!!!"<<endl;
10221       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
10222      }
10223    if(1.-pow(termA,2.) > 0.)
10224    {
10225     termB = 1./pow(1-pow(termA,2.),0.5);
10226    } else
10227      {
10228       cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in AFAWQC::FCTFNIF() !!!!"<<endl;   
10229       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
10230      }     
10231    Double_t statisticalError = termA * spread * termB;
10232    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinContent(ci,correction);
10233    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinError(ci,statisticalError);
10234   } // end of for(Int_t ci=1;ci<=4;ci++) // correction term index
10235  } // end of for(Int sc=0;sc<2;sc++) // sin or cos correction terms 
10236                                                                                                                                                                                                
10237 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow()
10238
10239 //================================================================================================================================
10240
10241 void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
10242 {
10243  // Get pointers to all objects relevant for calculations with nested loops.
10244    
10245  TList *nestedLoopsList = dynamic_cast<TList*>(fHistList->FindObject("Nested Loops"));
10246  if(nestedLoopsList) 
10247  {
10248   this->SetNestedLoopsList(nestedLoopsList);
10249  } else
10250    {
10251     cout<<"WARNING: nestedLoopsList is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10252     exit(0);
10253    }
10254     
10255   TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
10256   TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
10257   TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
10258   TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
10259    
10260   TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
10261   evaluateNestedLoopsName += fAnalysisLabel->Data();  
10262   TProfile *evaluateNestedLoops = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(evaluateNestedLoopsName.Data()));
10263   Bool_t bEvaluateIntFlowNestedLoops = kFALSE;
10264   Bool_t bEvaluateDiffFlowNestedLoops = kFALSE;
10265   if(evaluateNestedLoops)
10266   {
10267    this->SetEvaluateNestedLoops(evaluateNestedLoops);
10268    bEvaluateIntFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(1);
10269    bEvaluateDiffFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(2);
10270   }
10271   // nested loops relevant for integrated flow:  
10272   if(bEvaluateIntFlowNestedLoops)
10273   {
10274    // correlations:
10275    TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
10276    intFlowDirectCorrelationsName += fAnalysisLabel->Data();
10277    TProfile *intFlowDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowDirectCorrelationsName.Data()));
10278    if(intFlowDirectCorrelations) 
10279    { 
10280     this->SetIntFlowDirectCorrelations(intFlowDirectCorrelations);
10281    } else
10282      {
10283       cout<<"WARNING: intFlowDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10284       exit(0);
10285      }
10286    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)  
10287    {
10288     TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
10289     intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
10290     TProfile *intFlowExtraDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowExtraDirectCorrelationsName.Data()));
10291     if(intFlowExtraDirectCorrelations) 
10292     { 
10293      this->SetIntFlowExtraDirectCorrelations(intFlowExtraDirectCorrelations);
10294     } else
10295       {
10296        cout<<"WARNING: intFlowExtraDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10297        exit(0);
10298       }       
10299    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)  
10300    // correction terms for non-uniform acceptance:
10301    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
10302    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
10303    TProfile *intFlowDirectCorrectionTermsForNUA[2] = {NULL};
10304    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
10305    {
10306     intFlowDirectCorrectionTermsForNUA[sc] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s: %s terms",intFlowDirectCorrectionTermsForNUAName.Data(),sinCosFlag[sc].Data())));
10307     if(intFlowDirectCorrectionTermsForNUA[sc]) 
10308     { 
10309      this->SetIntFlowDirectCorrectionTermsForNUA(intFlowDirectCorrectionTermsForNUA[sc],sc);
10310     } else
10311       {
10312        cout<<"WARNING: intFlowDirectCorrectionTermsForNUA[sc] is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10313        cout<<"sc = "<<sc<<endl;
10314        exit(0);
10315       }
10316    } // end of for(Int_t sc=0;sc<2;sc++) 
10317   } // end of if(bEvaluateIntFlowNestedLoops)
10318     
10319   // nested loops relevant for differential flow:  
10320   if(bEvaluateDiffFlowNestedLoops)
10321   {
10322    // correlations:
10323    TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
10324    diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
10325    TProfile *diffFlowDirectCorrelations[2][2][4] = {{{NULL}}};
10326    for(Int_t t=0;t<2;t++)
10327    {
10328     for(Int_t pe=0;pe<2;pe++)
10329     {
10330      for(Int_t ci=0;ci<4;ci++) // correlation index
10331      {
10332       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())));
10333       if(diffFlowDirectCorrelations[t][pe][ci])
10334       {
10335        this->SetDiffFlowDirectCorrelations(diffFlowDirectCorrelations[t][pe][ci],t,pe,ci);
10336       } else
10337         {
10338          cout<<"WARNING: diffFlowDirectCorrelations[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10339          cout<<"t  = "<<t<<endl;
10340          cout<<"pe = "<<pe<<endl;   
10341          cout<<"ci = "<<ci<<endl;
10342         }     
10343      } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
10344     } // end of for(Int_t pe=0;pe<2;pe++)
10345    } // end of for(Int_t t=0;t<2;t++)   
10346    // correction terms for non-uniform acceptance:
10347    TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
10348    diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();  
10349    TProfile *diffFlowDirectCorrectionTermsForNUA[2][2][2][10] = {{{{NULL}}}};   
10350    for(Int_t t=0;t<2;t++)
10351    {
10352     for(Int_t pe=0;pe<2;pe++)
10353     {
10354      // correction terms for NUA:
10355      for(Int_t sc=0;sc<2;sc++) // sin or cos
10356      {
10357       for(Int_t cti=0;cti<9;cti++) // correction term index
10358       {
10359        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)));
10360        if(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti])
10361        {
10362         this->SetDiffFlowDirectCorrectionTermsForNUA(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti],t,pe,sc,cti);
10363        } else
10364          {
10365           cout<<"WARNING: diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10366           cout<<"t   = "<<t<<endl;
10367           cout<<"pe  = "<<pe<<endl;   
10368           cout<<"sc  = "<<sc<<endl;
10369           cout<<"cti = "<<cti<<endl;
10370          }    
10371       } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
10372      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
10373     } // end of for(Int_t pe=0;pe<2;pe++)
10374    } // end of for(Int_t t=0;t<2;t++)
10375    // other differential correlators:
10376    TString otherDirectDiffCorrelatorsName = "fOtherDirectDiffCorrelators";
10377    otherDirectDiffCorrelatorsName += fAnalysisLabel->Data();  
10378    TProfile *otherDirectDiffCorrelators[2][2][2][1] = {{{{NULL}}}};   
10379    for(Int_t t=0;t<2;t++)
10380    {
10381     for(Int_t pe=0;pe<2;pe++)
10382     {
10383      // correction terms for NUA:
10384      for(Int_t sc=0;sc<2;sc++) // sin or cos
10385      {
10386       for(Int_t ci=0;ci<1;ci++) // correlator index
10387       {
10388        otherDirectDiffCorrelators[t][pe][sc][ci] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s, %s, %s, %s, ci = %d",otherDirectDiffCorrelatorsName.Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data(),sinCosFlag[sc].Data(),ci+1)));
10389        if(otherDirectDiffCorrelators[t][pe][sc][ci])
10390        {
10391         this->SetOtherDirectDiffCorrelators(otherDirectDiffCorrelators[t][pe][sc][ci],t,pe,sc,ci);
10392        } else
10393          {
10394           cout<<"WARNING: otherDirectDiffCorrelators[t][pe][sc][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10395           cout<<"t   = "<<t<<endl;
10396           cout<<"pe  = "<<pe<<endl;   
10397           cout<<"sc  = "<<sc<<endl;
10398           cout<<"ci = "<<ci<<endl;
10399          }    
10400       } // end of for(Int_t ci=0;ci<9;ci++) // correction term index
10401      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
10402     } // end of for(Int_t pe=0;pe<2;pe++)
10403    } // end of for(Int_t t=0;t<2;t++)
10404    // number of RPs and POIs in selected pt and eta bins for cross-checkings:
10405    TString noOfParticlesInBinName = "fNoOfParticlesInBin";
10406    TH1D *noOfParticlesInBin = NULL;
10407    noOfParticlesInBin = dynamic_cast<TH1D*>(nestedLoopsList->FindObject(noOfParticlesInBinName.Data()));
10408    if(noOfParticlesInBin)
10409    {
10410     this->SetNoOfParticlesInBin(noOfParticlesInBin);
10411    } else
10412      {
10413       cout<<endl;
10414       cout<<" WARNING (QC): noOfParticlesInBin is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10415       cout<<endl;
10416      }
10417   } // end of if(bEvaluateDiffFlowNestedLoops)
10418
10419 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
10420
10421 //================================================================================================================================
10422
10423 void AliFlowAnalysisWithQCumulants::StoreHarmonic()
10424 {
10425  // Store flow harmonic in common control histograms.
10426
10427  (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
10428  if(fFillMultipleControlHistograms)
10429  {
10430   (fCommonHists2nd->GetHarmonic())->Fill(0.5,fHarmonic);
10431   (fCommonHists4th->GetHarmonic())->Fill(0.5,fHarmonic);
10432   (fCommonHists6th->GetHarmonic())->Fill(0.5,fHarmonic);
10433   (fCommonHists8th->GetHarmonic())->Fill(0.5,fHarmonic);
10434  }
10435  
10436 } // end of void AliFlowAnalysisWithQCumulants::StoreHarmonic()
10437
10438 //================================================================================================================================
10439
10440 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta) // type = RP or POI 
10441 {
10442  // Calculate all correlations needed for differential flow using particle weights.
10443  
10444  Int_t t = 0; // type flag 
10445  Int_t pe = 0; // ptEta flag
10446  
10447  if(type == "RP")
10448  {
10449   t = 0;
10450  } else if(type == "POI")
10451    {
10452     t = 1;
10453    }
10454
10455  if(ptOrEta == "Pt")
10456  {
10457   pe = 0;
10458  } else if(ptOrEta == "Eta")
10459    {
10460     pe = 1;
10461    }
10462     
10463  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10464  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10465  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10466  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10467
10468  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10469  Double_t dReQ1n1k = (*fReQ)(0,1);
10470  Double_t dReQ2n2k = (*fReQ)(1,2);
10471  Double_t dReQ1n3k = (*fReQ)(0,3);
10472  //Double_t dReQ4n4k = (*fReQ)(3,4);
10473  Double_t dImQ1n1k = (*fImQ)(0,1);
10474  Double_t dImQ2n2k = (*fImQ)(1,2);
10475  Double_t dImQ1n3k = (*fImQ)(0,3);
10476  //Double_t dImQ4n4k = (*fImQ)(3,4);
10477  
10478  // S^M_{p,k} (see .h file for the definition of fSpk):
10479  Double_t dSM1p1k = (*fSpk)(0,1);
10480  Double_t dSM1p2k = (*fSpk)(0,2);
10481  Double_t dSM1p3k = (*fSpk)(0,3);
10482  Double_t dSM2p1k = (*fSpk)(1,1);
10483  Double_t dSM3p1k = (*fSpk)(2,1);
10484  
10485  // looping over all bins and calculating reduced correlations: 
10486  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10487  {
10488   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
10489   Double_t p1n0kRe = 0.;
10490   Double_t p1n0kIm = 0.;
10491
10492   // number of POIs in particular (pt,eta) bin):
10493   Double_t mp = 0.;
10494
10495   // real and imaginary parts of q_{m*n,k}: 
10496   // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
10497   Double_t q1n2kRe = 0.;
10498   Double_t q1n2kIm = 0.;
10499   Double_t q2n1kRe = 0.;
10500   Double_t q2n1kIm = 0.;
10501
10502   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10503   Double_t s1p1k = 0.; 
10504   Double_t s1p2k = 0.; 
10505   Double_t s1p3k = 0.; 
10506    
10507   // M0111 from Eq. (118) in QC2c (to be improved (notation))
10508   Double_t dM0111 = 0.;
10509  
10510   if(type == "POI")
10511   {
10512    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10513            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10514    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10515            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10516             
10517    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10518     
10519    t = 1; // typeFlag = RP or POI
10520     
10521    // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
10522    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
10523            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
10524    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
10525            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));
10526    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
10527            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
10528    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
10529            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));
10530        
10531    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10532    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
10533    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
10534    s1p3k = pow(fs1dEBE[2][pe][3]->GetBinContent(b)*fs1dEBE[2][pe][3]->GetBinEntries(b),1.); 
10535      
10536    // M0111 from Eq. (118) in QC2c (to be improved (notation)):
10537    dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
10538           - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
10539           + 2.*(s1p3k-s1p2k*dSM1p1k));
10540   }
10541    else if(type == "RP")
10542    {
10543     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
10544     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
10545             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
10546     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
10547             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
10548     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
10549             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
10550     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
10551             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
10552
10553     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10554     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
10555     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
10556     s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
10557     
10558     // to be improved (cross-checked):
10559     p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10560             * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10561     p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
10562             * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10563             
10564     mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10565      
10566     t = 0; // typeFlag = RP or POI
10567     
10568     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
10569     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
10570            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
10571            + 2.*(s1p3k-s1p2k*dSM1p1k));
10572     //...............................................................................................   
10573    }
10574    
10575    // 2'-particle correlation:
10576    Double_t two1n1nW0W1 = 0.;
10577    if(mp*dSM1p1k-s1p1k)
10578    {
10579     two1n1nW0W1 = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
10580                 / (mp*dSM1p1k-s1p1k);
10581    
10582     // fill profile to get <<2'>>     
10583     fDiffFlowCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1,mp*dSM1p1k-s1p1k);    
10584     // fill profile to get <<2'>^2>     
10585     fDiffFlowSquaredCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1*two1n1nW0W1,mp*dSM1p1k-s1p1k);        
10586     // histogram to store <2'> e-b-e (needed in some other methods):
10587     fDiffFlowCorrelationsEBE[t][pe][0]->SetBinContent(b,two1n1nW0W1);      
10588     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->SetBinContent(b,mp*dSM1p1k-s1p1k);      
10589    } // end of if(mp*dSM1p1k-s1p1k)
10590    
10591    // 4'-particle correlation:
10592    Double_t four1n1n1n1nW0W1W1W1 = 0.;
10593    if(dM0111)
10594    {
10595     four1n1n1n1nW0W1W1W1 = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
10596                          - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
10597                          - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
10598                          - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
10599                          + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
10600                          - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
10601                          - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
10602                          + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
10603                          + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
10604                          + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
10605                          + 2.*s1p1k*dSM1p2k                                      
10606                          - 6.*s1p3k)        
10607                          / dM0111; // to be improved (notation of dM0111)
10608    
10609     // fill profile to get <<4'>>     
10610     fDiffFlowCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1,dM0111);    
10611     // fill profile to get <<4'>^2>     
10612     fDiffFlowSquaredCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1*four1n1n1n1nW0W1W1W1,dM0111);        
10613     // histogram to store <4'> e-b-e (needed in some other methods):
10614     fDiffFlowCorrelationsEBE[t][pe][1]->SetBinContent(b,four1n1n1n1nW0W1W1W1);      
10615     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->SetBinContent(b,dM0111);      
10616    } // end of if(dM0111)
10617  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10618
10619 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta); // type = RP or POI 
10620
10621 //================================================================================================================================
10622
10623 void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
10624 {
10625  // Fill common control histograms.
10626  
10627  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
10628  fCommonHists->FillControlHistograms(anEvent); 
10629  if(fFillMultipleControlHistograms)
10630  {
10631   if(nRP>1)
10632   {
10633    fCommonHists2nd->FillControlHistograms(anEvent);                                        
10634    if(nRP>3)
10635    {
10636     fCommonHists4th->FillControlHistograms(anEvent);                                        
10637     if(nRP>5)
10638     {
10639      fCommonHists6th->FillControlHistograms(anEvent);                                        
10640      if(nRP>7)
10641      {
10642       fCommonHists8th->FillControlHistograms(anEvent);                                        
10643      } // end of if(nRP>7)  
10644     } // end of if(nRP>5) 
10645    } // end of if(nRP>3)                                                                                                                      
10646   } // end of if(nRP>1) 
10647  } // end of if(fFillMultipleControlHistograms)
10648  
10649 } // end of void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
10650
10651 //================================================================================================================================
10652
10653 void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities()
10654 {
10655  // Reset all event by event quantities.
10656  
10657  // Reference flow:
10658  fReQ->Zero();
10659  fImQ->Zero();
10660  fSpk->Zero();
10661  fIntFlowCorrelationsEBE->Reset();
10662  fIntFlowEventWeightsForCorrelationsEBE->Reset();
10663  fIntFlowCorrelationsAllEBE->Reset();
10664  
10665  for(Int_t sc=0;sc<2;sc++)
10666  {
10667   fIntFlowCorrectionTermsForNUAEBE[sc]->Reset();
10668   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->Reset(); 
10669  }
10670     
10671  // Differential flow:
10672  if(fCalculateDiffFlow)
10673  {
10674   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
10675   {
10676    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // 1D in pt or eta
10677    {
10678     for(Int_t m=0;m<4;m++) // multiple of harmonic
10679     {
10680      for(Int_t k=0;k<9;k++) // power of weight
10681      {
10682       if(fReRPQ1dEBE[t][pe][m][k]) fReRPQ1dEBE[t][pe][m][k]->Reset();
10683       if(fImRPQ1dEBE[t][pe][m][k]) fImRPQ1dEBE[t][pe][m][k]->Reset();
10684      }   
10685     } 
10686    }
10687   } 
10688   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
10689   { 
10690    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // 1D in pt or eta
10691    {
10692     for(Int_t k=0;k<9;k++)
10693     {
10694      if(fs1dEBE[t][pe][k]) fs1dEBE[t][pe][k]->Reset();
10695     }
10696    }
10697   }
10698   // e-b-e reduced correlations:
10699   for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
10700   {  
10701    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
10702    {
10703     for(Int_t rci=0;rci<4;rci++) // reduced correlation index
10704     {
10705      if(fDiffFlowCorrelationsEBE[t][pe][rci]) fDiffFlowCorrelationsEBE[t][pe][rci]->Reset();
10706      if(fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]) fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]->Reset();
10707     }
10708    }
10709   }  
10710   // correction terms for NUA:
10711   for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
10712   {  
10713    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
10714    {
10715     for(Int_t sc=0;sc<2;sc++) // sin or cos
10716     {
10717      for(Int_t cti=0;cti<9;cti++) // correction term index
10718      {
10719      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti]->Reset();  
10720      }
10721     }
10722    }      
10723   }
10724  } // end of if(fCalculateDiffFlow)   
10725
10726  // 2D (pt,eta)
10727  if(fCalculate2DDiffFlow)
10728  {
10729   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
10730   {
10731    for(Int_t m=0;m<4;m++) // multiple of harmonic
10732    {
10733     for(Int_t k=0;k<9;k++) // power of weight
10734     {
10735      if(fReRPQ2dEBE[t][m][k]){fReRPQ2dEBE[t][m][k]->Reset();}
10736      if(fImRPQ2dEBE[t][m][k]){fImRPQ2dEBE[t][m][k]->Reset();}
10737     }   
10738    }
10739   }
10740   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
10741   { 
10742    for(Int_t k=0;k<9;k++)
10743    {
10744     if(fs2dEBE[t][k]){fs2dEBE[t][k]->Reset();}
10745    }
10746   }  
10747  } // end of if(fCalculate2DDiffFlow) 
10748
10749 } // end of void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities();
10750
10751 //================================================================================================================================
10752
10753 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
10754 {
10755  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
10756  
10757  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
10758  //  0: <<sin n(psi1)>>
10759  //  1: <<sin n(psi1+phi2)>>
10760  //  2: <<sin n(psi1+phi2-phi3)>>
10761  //  3: <<sin n(psi1-phi2-phi3)>>:
10762  //  4:
10763  //  5:
10764  //  6:
10765  
10766  // multiplicity:
10767  Double_t dMult = (*fSpk)(0,0);
10768  
10769  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10770  Double_t dReQ1n = (*fReQ)(0,0);
10771  Double_t dReQ2n = (*fReQ)(1,0);
10772  //Double_t dReQ3n = (*fReQ)(2,0);
10773  //Double_t dReQ4n = (*fReQ)(3,0);
10774  Double_t dImQ1n = (*fImQ)(0,0);
10775  Double_t dImQ2n = (*fImQ)(1,0);
10776  //Double_t dImQ3n = (*fImQ)(2,0);
10777  //Double_t dImQ4n = (*fImQ)(3,0);
10778
10779  Int_t t = 0; // type flag 
10780  Int_t pe = 0; // ptEta flag
10781  
10782  if(type == "RP")
10783  {
10784   t = 0;
10785  } else if(type == "POI")
10786    {
10787     t = 1;
10788    }
10789
10790  if(ptOrEta == "Pt")
10791  {
10792   pe = 0;
10793  } else if(ptOrEta == "Eta")
10794    {
10795     pe = 1;
10796    }
10797     
10798  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10799  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10800  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10801  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10802
10803  // looping over all bins and calculating correction terms: 
10804  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10805  {
10806   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
10807   Double_t p1n0kRe = 0.;
10808   Double_t p1n0kIm = 0.;
10809
10810   // number of POIs in particular pt or eta bin:
10811   Double_t mp = 0.;
10812
10813   // 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):
10814   Double_t q1n0kRe = 0.;
10815   Double_t q1n0kIm = 0.;
10816   Double_t q2n0kRe = 0.;
10817   Double_t q2n0kIm = 0.;
10818
10819   // number of particles which are both RPs and POIs in particular pt or eta bin:
10820   Double_t mq = 0.;
10821    
10822   if(type == "POI")
10823   {
10824    // q_{m*n,0}:
10825    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
10826            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
10827    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
10828            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
10829    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
10830            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
10831    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
10832            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
10833                  
10834    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10835   } 
10836   else if(type == "RP")
10837   {
10838    // q_{m*n,0}:
10839    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10840            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10841    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
10842            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10843    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
10844            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
10845    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
10846            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
10847                  
10848    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
10849   }    
10850   if(type == "POI")
10851   {
10852    // p_{m*n,0}:
10853    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10854            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10855    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10856            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10857             
10858    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10859     
10860    t = 1; // typeFlag = RP or POI
10861   }
10862   else if(type == "RP")
10863   {
10864    // p_{m*n,0} = q_{m*n,0}:
10865    p1n0kRe = q1n0kRe; 
10866    p1n0kIm = q1n0kIm; 
10867            
10868    mp = mq; 
10869    
10870    t = 0; // typeFlag = RP or POI
10871   }
10872
10873   // <<sin n(psi1)>>:
10874   Double_t sinP1nPsi = 0.;
10875   if(mp)
10876   {
10877    sinP1nPsi = p1n0kIm/mp;
10878    // fill profile for <<sin n(psi1)>>:
10879    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
10880    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
10881    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
10882   } // end of if(mp)   
10883   
10884   // <<sin n(psi1+phi2)>>:
10885   Double_t sinP1nPsiP1nPhi = 0.;
10886   if(mp*dMult-mq)
10887   {
10888    sinP1nPsiP1nPhi = (p1n0kRe*dImQ1n+p1n0kIm*dReQ1n-q2n0kIm)/(mp*dMult-mq);
10889    // fill profile for <<sin n(psi1+phi2)>>:
10890    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhi,mp*dMult-mq);
10891    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10892    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhi);
10893   } // end of if(mp*dMult-mq)   
10894   
10895   // <<sin n(psi1+phi2-phi3)>>:
10896   Double_t sinP1nPsi1P1nPhi2MPhi3 = 0.;
10897   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10898   {
10899    sinP1nPsi1P1nPhi2MPhi3 = (p1n0kIm*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
10900                           - 1.*(q2n0kIm*dReQ1n-q2n0kRe*dImQ1n)  
10901                           - mq*dImQ1n+2.*q1n0kIm)
10902                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10903    // fill profile for <<sin n(psi1+phi2)>>:
10904    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10905    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10906    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3);
10907   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10908   
10909   // <<sin n(psi1-phi2-phi3)>>:
10910   Double_t sinP1nPsi1M1nPhi2MPhi3 = 0.;
10911   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10912   {
10913    sinP1nPsi1M1nPhi2MPhi3 = (p1n0kIm*(pow(dReQ1n,2.)-pow(dImQ1n,2.))-2.*p1n0kRe*dReQ1n*dImQ1n
10914                           - 1.*(p1n0kIm*dReQ2n-p1n0kRe*dImQ2n)
10915                           + 2.*mq*dImQ1n-2.*q1n0kIm)
10916                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10917    // fill profile for <<sin n(psi1+phi2)>>:
10918    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10919    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10920    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3);
10921   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10922  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10923  
10924 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
10925
10926
10927 //================================================================================================================================
10928
10929
10930 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
10931 {
10932  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms).
10933  
10934  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
10935  //  0: <<cos n(psi)>>
10936  //  1: <<cos n(psi1+phi2)>>
10937  //  2: <<cos n(psi1+phi2-phi3)>>
10938  //  3: <<cos n(psi1-phi2-phi3)>>
10939  //  4:
10940  //  5:
10941  //  6:
10942  
10943  // multiplicity:
10944  Double_t dMult = (*fSpk)(0,0);
10945  
10946  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10947  Double_t dReQ1n = (*fReQ)(0,0);
10948  Double_t dReQ2n = (*fReQ)(1,0);
10949  //Double_t dReQ3n = (*fReQ)(2,0);
10950  //Double_t dReQ4n = (*fReQ)(3,0);
10951  Double_t dImQ1n = (*fImQ)(0,0);
10952  Double_t dImQ2n = (*fImQ)(1,0);
10953  //Double_t dImQ3n = (*fImQ)(2,0);
10954  //Double_t dImQ4n = (*fImQ)(3,0);
10955
10956  Int_t t = 0; // type flag 
10957  Int_t pe = 0; // ptEta flag
10958  
10959  if(type == "RP")
10960  {
10961   t = 0;
10962  } else if(type == "POI")
10963    {
10964     t = 1;
10965    }
10966
10967  if(ptOrEta == "Pt")
10968  {
10969   pe = 0;
10970  } else if(ptOrEta == "Eta")
10971    {
10972     pe = 1;
10973    }
10974     
10975  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10976  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10977  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10978  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10979
10980  // looping over all bins and calculating correction terms: 
10981  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10982  {
10983   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
10984   Double_t p1n0kRe = 0.;
10985   Double_t p1n0kIm = 0.;
10986
10987   // number of POIs in particular pt or eta bin:
10988   Double_t mp = 0.;
10989
10990   // 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):
10991   Double_t q1n0kRe = 0.;
10992   Double_t q1n0kIm = 0.;
10993   Double_t q2n0kRe = 0.;
10994   Double_t q2n0kIm = 0.;
10995
10996   // number of particles which are both RPs and POIs in particular pt or eta bin:
10997   Double_t mq = 0.;
10998    
10999   if(type == "POI")
11000   {
11001    // q_{m*n,0}:
11002    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
11003            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
11004    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
11005            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
11006    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
11007            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
11008    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
11009            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
11010                  
11011    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
11012   } 
11013   else if(type == "RP")
11014   {
11015    // q_{m*n,0}:
11016    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
11017            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
11018    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
11019            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
11020    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
11021            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
11022    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
11023            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
11024                  
11025    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
11026   }    
11027   if(type == "POI")
11028   {
11029    // p_{m*n,0}:
11030    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
11031            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
11032    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
11033            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
11034             
11035    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
11036     
11037    t = 1; // typeFlag = RP or POI
11038   }
11039   else if(type == "RP")
11040   {
11041    // p_{m*n,0} = q_{m*n,0}:
11042    p1n0kRe = q1n0kRe; 
11043    p1n0kIm = q1n0kIm; 
11044            
11045    mp = mq; 
11046    
11047    t = 0; // typeFlag = RP or POI
11048   }
11049
11050   // <<cos n(psi1)>>:
11051   Double_t cosP1nPsi = 0.;
11052   if(mp)
11053   {
11054    cosP1nPsi = p1n0kRe/mp;
11055    
11056    // fill profile for <<cos n(psi1)>>:
11057    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
11058    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
11059    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
11060   } // end of if(mp)   
11061   
11062   // <<cos n(psi1+phi2)>>:
11063   Double_t cosP1nPsiP1nPhi = 0.;
11064   if(mp*dMult-mq)
11065   {
11066    cosP1nPsiP1nPhi = (p1n0kRe*dReQ1n-p1n0kIm*dImQ1n-q2n0kRe)/(mp*dMult-mq);
11067    // fill profile for <<sin n(psi1+phi2)>>:
11068    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhi,mp*dMult-mq);
11069    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
11070    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhi);
11071   } // end of if(mp*dMult-mq)   
11072   
11073   // <<cos n(psi1+phi2-phi3)>>:
11074   Double_t cosP1nPsi1P1nPhi2MPhi3 = 0.;
11075   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
11076   {
11077    cosP1nPsi1P1nPhi2MPhi3 = (p1n0kRe*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
11078                           - 1.*(q2n0kRe*dReQ1n+q2n0kIm*dImQ1n)  
11079                           - mq*dReQ1n+2.*q1n0kRe)
11080                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11081    // fill profile for <<sin n(psi1+phi2)>>:
11082    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11083    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
11084    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3);
11085   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
11086   
11087   // <<cos n(psi1-phi2-phi3)>>:
11088   Double_t cosP1nPsi1M1nPhi2MPhi3 = 0.;
11089   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
11090   {
11091    cosP1nPsi1M1nPhi2MPhi3 = (p1n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))+2.*p1n0kIm*dReQ1n*dImQ1n
11092                           - 1.*(p1n0kRe*dReQ2n+p1n0kIm*dImQ2n)  
11093                           - 2.*mq*dReQ1n+2.*q1n0kRe)
11094                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11095    // fill profile for <<sin n(psi1+phi2)>>:
11096    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11097    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
11098    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3);
11099   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
11100  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11101  
11102 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
11103
11104 //==================================================================================================================================
11105
11106 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
11107 {
11108  // Transfer profiles into histogams and correctly propagate the error.
11109  
11110  Int_t t = 0; // type flag 
11111  Int_t pe = 0; // ptEta flag
11112  
11113  if(type == "RP")
11114  {
11115   t = 0;
11116  } else if(type == "POI")
11117    {
11118     t = 1;
11119    }
11120
11121  if(ptOrEta == "Pt")
11122  {
11123   pe = 0;
11124  } else if(ptOrEta == "Eta")
11125    {
11126     pe = 1;
11127    }
11128     
11129  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11130  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
11131  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
11132  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11133
11134  for(Int_t sc=0;sc<2;sc++) // sin or cos
11135  {
11136   for(Int_t cti=0;cti<9;cti++) // correction term index
11137   {
11138    for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11139    {
11140     Double_t correctionTerm = fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(b);
11141     fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]->SetBinContent(b,correctionTerm);
11142     // to be improved (propagate error correctly)
11143     // ...
11144    } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11145   } // correction term index
11146  } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
11147
11148 }// end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
11149
11150 //==================================================================================================================================
11151
11152 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
11153
11154  // Calculate generalized differential flow cumulants (corrected for non-uniform acceptance).
11155  
11156  // to be improved - propagate error also from non-isotropic terms
11157   
11158  Int_t t = 0; // RP = 0, POI = 1
11159  Int_t pe = 0; // pt = 0, eta = 1
11160
11161  if(type == "RP")
11162  {
11163   t = 0;
11164  } else if(type == "POI")
11165    {
11166     t = 1;
11167    } 
11168      
11169  if(ptOrEta == "Pt")
11170  {
11171   pe = 0;
11172  } else if(ptOrEta == "Eta")
11173    {
11174     pe = 1;
11175    } 
11176        
11177  // Common:
11178  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11179  // 2-particle correlation:
11180  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
11181  // sinus terms coming from reference flow: 
11182  Double_t sinP1nPhi = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
11183  Double_t sinP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
11184  Double_t sinP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
11185  // cosinus terms coming from reference flow: 
11186  Double_t cosP1nPhi = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
11187  Double_t cosP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
11188  Double_t cosP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
11189
11190  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11191  {
11192   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
11193   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
11194   Double_t sinP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][0]->GetBinContent(b); // <<sin n(Psi)>> 
11195   Double_t cosP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][0]->GetBinContent(b); // <<cos n(Psi)>> 
11196   Double_t sinP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][1]->GetBinContent(b); // <<sin n(psi1+phi2)>> 
11197   Double_t cosP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][1]->GetBinContent(b); // <<cos n(psi1+phi2)>> 
11198   Double_t sinP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][2]->GetBinContent(b); // <<sin n(psi1+phi2-phi3)>> 
11199   Double_t cosP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][2]->GetBinContent(b); // <<cos n(psi1+phi2-phi3)>> 
11200   Double_t sinP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][3]->GetBinContent(b); // <<sin n(psi1-phi2-phi3)>> 
11201   Double_t cosP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][3]->GetBinContent(b); // <<cos n(psi1-phi2-phi3)>> 
11202   // Generalized QC{2'}:
11203   Double_t qc2Prime = twoPrime - sinP1nPsi*sinP1nPhi - cosP1nPsi*cosP1nPhi;
11204   if(fApplyCorrectionForNUA)
11205   {
11206    fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime);
11207   }
11208   if(TMath::Abs(twoPrime)>0.)
11209   {
11210    fDiffFlowDetectorBias[t][pe][0]->SetBinContent(b,qc2Prime/twoPrime); // detector bias = generalized/isotropic cumulant.   
11211   }
11212   // Generalized QC{4'}:
11213   Double_t qc4Prime = fourPrime-2.*twoPrime*two
11214                     - cosP1nPsi*cosP1nPhi1M1nPhi2M1nPhi3
11215                     + sinP1nPsi*sinP1nPhi1M1nPhi2M1nPhi3
11216                     - cosP1nPhi*cosP1nPsi1M1nPhi2M1nPhi3
11217                     + sinP1nPhi*sinP1nPsi1M1nPhi2M1nPhi3
11218                     - 2.*cosP1nPhi*cosP1nPsi1P1nPhi2M1nPhi3
11219                     - 2.*sinP1nPhi*sinP1nPsi1P1nPhi2M1nPhi3
11220                     - cosP1nPsi1P1nPhi2*cosP1nPhi1P1nPhi2
11221                     - sinP1nPsi1P1nPhi2*sinP1nPhi1P1nPhi2
11222                     + 2.*cosP1nPhi1P1nPhi2*(cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
11223                     + 2.*sinP1nPhi1P1nPhi2*(cosP1nPsi*sinP1nPhi+sinP1nPsi*cosP1nPhi)
11224                     + 4.*two*(cosP1nPsi*cosP1nPhi+sinP1nPsi*sinP1nPhi)
11225                     + 2.*cosP1nPsi1P1nPhi2*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.))
11226                     + 4.*sinP1nPsi1P1nPhi2*cosP1nPhi*sinP1nPhi
11227                     + 4.*twoPrime*(pow(cosP1nPhi,2.)+pow(sinP1nPhi,2.))
11228                     - 6.*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.)) 
11229                     * (cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
11230                     - 12.*cosP1nPhi*sinP1nPhi
11231                     * (sinP1nPsi*cosP1nPhi+cosP1nPsi*sinP1nPhi);
11232   if(fApplyCorrectionForNUA)
11233   {
11234    fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime);   
11235   }
11236   if(TMath::Abs(fourPrime-2.*twoPrime*two)>0.)
11237   {
11238    fDiffFlowDetectorBias[t][pe][1]->SetBinContent(b,qc4Prime/(fourPrime-2.*twoPrime*two)); // detector bias = generalized/isotropic cumulant.   
11239   }
11240  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
11241  
11242 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
11243
11244 //==================================================================================================================================    
11245
11246 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
11247 {
11248  // Calculate differential flow corrected for non-uniform acceptance.
11249  
11250  // to be improved: eventually I will have to access here masured correlations and NUA terms
11251  //                 instead of cumulants in order to propagate statistical error correctly also 
11252  //                 to NUA terms (propagating errors directly from cumulants is WRONG for 
11253  //                 differential flow becuase that doesn't account at all cross-covariance terms) 
11254  
11255  // REMARK: When NUA correction is apllied error for differential flow DOES NOT get corrected,
11256  //         i.e. only value is being corrected, error is still the one relevant for isotropic
11257  //         case. This eventually will be resolved. 
11258   
11259  
11260  Int_t t = 0; // RP or POI
11261  Int_t pe = 0; // pt or eta
11262
11263  if(type == "RP")
11264  {
11265   t = 0;
11266  } else if(type == "POI")
11267    {
11268     t = 1;
11269    }     
11270  if(ptOrEta == "Pt")
11271  {
11272   pe = 0;
11273  } else if(ptOrEta == "Eta")
11274    {
11275     pe = 1;
11276    } 
11277   
11278  // Common:
11279  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11280  // Reference Q-cumulants
11281  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2} 
11282  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}
11283  // Loop over pt or eta bins:
11284  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11285  {
11286   // Differential Q-cumulants:
11287   Double_t qc2Prime = fDiffFlowCumulants[t][pe][0]->GetBinContent(b); // QC{2'}
11288   Double_t qc4Prime = fDiffFlowCumulants[t][pe][1]->GetBinContent(b); // QC{4'}
11289   // v'{2}:
11290   if(qc2>0.)
11291   { 
11292    Double_t v2Prime = qc2Prime/pow(qc2,0.5);
11293    if(TMath::Abs(v2Prime)>0.){fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime);} 
11294   }  
11295   // v'{4}:
11296   if(qc4<0.)
11297   { 
11298    Double_t v4Prime = -qc4Prime/pow(-qc4,3./4.);
11299    if(TMath::Abs(v4Prime)>0.){fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);} 
11300   }  
11301  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
11302   
11303 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta); 
11304
11305 //==================================================================================================================================
11306
11307 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent)
11308 {
11309  // Evaluate with nested loops multiparticle correlations for integrated flow (without using the particle weights). 
11310
11311  // Remark: Results are stored in profile fIntFlowDirectCorrelations whose binning is organized as follows:
11312  // 
11313  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
11314  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
11315  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
11316  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
11317  //  5th bin:           ----  EMPTY ----
11318  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
11319  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
11320  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
11321  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
11322  // 10th bin:           ----  EMPTY ----
11323  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
11324  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
11325  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
11326  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
11327  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
11328  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
11329  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
11330  // 18th bin:           ----  EMPTY ----
11331  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
11332  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
11333  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
11334  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
11335  // 23rd bin:           ----  EMPTY ----
11336  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
11337  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
11338  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
11339  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
11340  // 28th bin:           ----  EMPTY ----
11341  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
11342  // 30th bin:           ----  EMPTY ----
11343  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
11344  // 32nd bin:           ----  EMPTY ----
11345   //  Extra correlations for 3p TY study: 
11346  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
11347  // 34th bin: <5>_{3n,3n|2n,2n,2n} = five3n3n2n2n2n = <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-2*phi5))> 
11348   //  Extra correlations for 6p TY study: 
11349  // 35th bin: <2>_{5n|5n} = two5n5n = <cos(5n*(phi1-phi2)> T
11350  // 36th bin: <2>_{6n|6n} = two6n6n = <cos(6n*(phi1-phi2)> T
11351  // 37th bin: <3>_{5n|3n,2n} = three5n3n2n = <cos(n*(5*phi1-3*phi2-2*phi3)> 
11352  // 38th bin: <3>_{5n|4n,1n} = three5n4n1n = <cos(n*(5*phi1-4*phi2-1*phi3)> 
11353  // 39th bin: <3>_{6n|3n,3n} = three6n3n3n = <cos(n*(6*phi1-3*phi2-3*phi3)> T 
11354  // 40th bin: <3>_{6n|4n,2n} = three6n4n2n = <cos(n*(6*phi1-4*phi2-2*phi3)> T
11355  // 41st bin: <3>_{6n|5n,1n} = three6n5n1n = <cos(n*(6*phi1-5*phi2-1*phi3)>
11356  // 42nd bin: <4>_{6n|3n,2n,1n} = four6n3n2n1n = <cos(n*(6*phi1-3*phi2-2*phi3-1*phi4)>
11357  // 43rd bin: <4>_{3n,2n|3n,2n} = four3n2n3n2n = <cos(n*(3*phi1+2*phi2-3*phi3-2*phi4)>
11358  // 44th bin: <4>_{4n,1n|3n,2n} = four4n1n3n2n = <cos(n*(4*phi1+1*phi2-3*phi3-2*phi4)>
11359  // 45th bin: <4>_{3n,3n|3n,3n} = four3n3n3n3n = <cos(3.*n*(phi1+phi2-phi3-phi4))> T
11360  // 46th bin: <4>_{4n,2n|3n,3n} = four4n2n3n3n = <cos(n*(4*phi1+2*phi2-3*phi3-3*phi4)>
11361  // 47th bin: <4>_{5n,1n|3n,3n} = four5n1n3n3n = <cos(n*(5*phi1+1*phi2-3*phi3-3*phi4)>
11362  // 48th bin: <4>_{4n,2n|4n,2n} = four4n2n4n2n = <cos(n*(4*phi1+2*phi2-4*phi3-2*phi4)> T
11363  // 49th bin: <4>_{5n,1n|4n,2n} = four5n1n4n2n = <cos(n*(5*phi1+1*phi2-4*phi3-2*phi4)>
11364  // 50th bin: <4>_{5n|3n,1n,1n} = four5n3n1n1n = <cos(n*(5*phi1-3*phi2-1*phi3-1*phi4)>
11365  // 51st bin: <4>_{5n|2n,2n,1n} = four5n2n2n1n = <cos(n*(5*phi1-2*phi2-2*phi3-1*phi4)>
11366  // 52nd bin: <4>_{5n,1n|5n,1n} = four5n1n5n1n = <cos(n*(5*phi1+1*phi2-5*phi3-1*phi4)>
11367  // 53rd bin: <5>_{3n,3n|3n,2n,1n} = four3n3n3n2n1n = <cos(n*(3*phi1+3*phi2-3*phi3-2*phi4-1*phi5)>
11368  // 54th bin: <5>_{4n,2n|3n,2n,1n} = four4n2n3n2n1n = <cos(n*(4*phi1+2*phi2-3*phi3-2*phi4-1*phi5)>
11369  // 55th bin: <5>_{3n,2n|3n,1n,1n} = four3n2n3n1n1n = <cos(n*(3*phi1+2*phi2-3*phi3-1*phi4-1*phi5)>
11370  // 56th bin: <5>_{3n,2n|2n,2n,1n} = four3n2n2n2n1n = <cos(n*(3*phi1+2*phi2-2*phi3-2*phi4-1*phi5)>
11371  // 57th bin: <5>_{5n,1n|3n,2n,1n} = four5n1n3n2n1n = <cos(n*(5*phi1+1*phi2-3*phi3-2*phi4-1*phi5)>
11372  // 58th bin: <6>_{3n,2n,1n|3n,2n,1n} = six3n2n1n3n2n1n = <cos(n*(3*phi1+2*phi2+1*phi3-3*phi4-2*phi5-1*phi6)>
11373   
11374  Int_t nPrim = anEvent->NumberOfTracks(); 
11375  AliFlowTrackSimple *aftsTrack = NULL; 
11376  Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.; 
11377  Int_t n = fHarmonic; 
11378  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
11379  Double_t dMult = (*fSpk)(0,0);
11380  cout<<endl;
11381  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
11382  if(dMult<2)
11383  {
11384   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
11385  } else if (dMult>fMaxAllowedMultiplicity)
11386    {
11387     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
11388    } else 
11389      { 
11390       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
11391      } 
11392  
11393  // 2-particle correlations:       
11394  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
11395  {
11396   for(Int_t i1=0;i1<nPrim;i1++)
11397   {
11398    aftsTrack=anEvent->GetTrack(i1);
11399    if(!(aftsTrack->InRPSelection())) continue;
11400    phi1=aftsTrack->Phi(); 
11401    for(Int_t i2=0;i2<nPrim;i2++)
11402    {
11403     if(i2==i1)continue;
11404     aftsTrack=anEvent->GetTrack(i2);
11405     if(!(aftsTrack->InRPSelection())) continue;
11406     phi2=aftsTrack->Phi();
11407     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
11408     // fill the profile with 2-p correlations: 
11409     fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),1.);     // <cos(n*(phi1-phi2))>
11410     fIntFlowDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),1.);  // <cos(2n*(phi1-phi2))>
11411     fIntFlowDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),1.);  // <cos(3n*(phi1-phi2))>
11412     fIntFlowDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),1.);  // <cos(4n*(phi1-phi2))>   
11413     fIntFlowDirectCorrelations->Fill(34.5,cos(5.*n*(phi1-phi2)),1.); // <cos(5n*(phi1-phi2))>
11414     fIntFlowDirectCorrelations->Fill(35.5,cos(6.*n*(phi1-phi2)),1.); // <cos(6n*(phi1-phi2))>   
11415    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11416   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11417  } // end of if(nPrim>=2)
11418  
11419  // 3-particle correlations:         
11420  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
11421  {
11422   for(Int_t i1=0;i1<nPrim;i1++)
11423   {
11424    aftsTrack=anEvent->GetTrack(i1);
11425    if(!(aftsTrack->InRPSelection())) continue;
11426    phi1=aftsTrack->Phi();
11427    for(Int_t i2=0;i2<nPrim;i2++)
11428    {
11429     if(i2==i1)continue;
11430     aftsTrack=anEvent->GetTrack(i2);
11431     if(!(aftsTrack->InRPSelection())) continue;
11432     phi2=aftsTrack->Phi();
11433     for(Int_t i3=0;i3<nPrim;i3++)
11434     {
11435      if(i3==i1||i3==i2)continue;
11436      aftsTrack=anEvent->GetTrack(i3);
11437      if(!(aftsTrack->InRPSelection())) continue;
11438      phi3=aftsTrack->Phi();
11439      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
11440      // fill the profile with 3-p correlations:   
11441      fIntFlowDirectCorrelations->Fill(5.,cos(2.*n*phi1-n*(phi2+phi3)),1.);         //<3>_{2n|nn,n}
11442      fIntFlowDirectCorrelations->Fill(6.,cos(3.*n*phi1-2.*n*phi2-n*phi3),1.);      //<3>_{3n|2n,n}
11443      fIntFlowDirectCorrelations->Fill(7.,cos(4.*n*phi1-2.*n*phi2-2.*n*phi3),1.);   //<3>_{4n|2n,2n}
11444      fIntFlowDirectCorrelations->Fill(8.,cos(4.*n*phi1-3.*n*phi2-n*phi3),1.);      //<3>_{4n|3n,n}
11445      fIntFlowDirectCorrelations->Fill(36.5,cos(5.*n*phi1-3.*n*phi2-2.*n*phi3),1.); //<3>_{5n|3n,2n}
11446      fIntFlowDirectCorrelations->Fill(37.5,cos(5.*n*phi1-4.*n*phi2-1.*n*phi3),1.); //<3>_{5n|4n,1n}
11447      fIntFlowDirectCorrelations->Fill(38.5,cos(6.*n*phi1-3.*n*phi2-3.*n*phi3),1.); //<3>_{6n|3n,3n}
11448      fIntFlowDirectCorrelations->Fill(39.5,cos(6.*n*phi1-4.*n*phi2-2.*n*phi3),1.); //<3>_{6n|4n,2n}     
11449      fIntFlowDirectCorrelations->Fill(40.5,cos(6.*n*phi1-5.*n*phi2-1.*n*phi3),1.); //<3>_{6n|5n,1n}
11450     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11451    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11452   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11453  } // end of if(nPrim>=3)
11454
11455  // 4-particle correlations:
11456  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
11457  {       
11458   for(Int_t i1=0;i1<nPrim;i1++)
11459   { 
11460    aftsTrack=anEvent->GetTrack(i1);
11461    if(!(aftsTrack->InRPSelection())) continue;
11462    phi1=aftsTrack->Phi();
11463    for(Int_t i2=0;i2<nPrim;i2++)
11464    {
11465     if(i2==i1)continue;
11466     aftsTrack=anEvent->GetTrack(i2);
11467     if(!(aftsTrack->InRPSelection())) continue;
11468     phi2=aftsTrack->Phi();
11469     for(Int_t i3=0;i3<nPrim;i3++)
11470     {
11471      if(i3==i1||i3==i2)continue;
11472      aftsTrack=anEvent->GetTrack(i3);
11473      if(!(aftsTrack->InRPSelection())) continue;
11474      phi3=aftsTrack->Phi();
11475      for(Int_t i4=0;i4<nPrim;i4++)
11476      {
11477       if(i4==i1||i4==i2||i4==i3)continue;
11478       aftsTrack=anEvent->GetTrack(i4);
11479       if(!(aftsTrack->InRPSelection())) continue;
11480       phi4=aftsTrack->Phi();
11481       if(nPrim==4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush;
11482       // fill the profile with 4-p correlations:   
11483       fIntFlowDirectCorrelations->Fill(10.,cos(n*phi1+n*phi2-n*phi3-n*phi4),1.);            // <4>_{n,n|n,n} 
11484       fIntFlowDirectCorrelations->Fill(11.,cos(2.*n*phi1+n*phi2-2.*n*phi3-n*phi4),1.);      // <4>_{2n,n|2n,n}
11485       fIntFlowDirectCorrelations->Fill(12.,cos(2.*n*phi1+2*n*phi2-2.*n*phi3-2.*n*phi4),1.); // <4>_{2n,2n|2n,2n}
11486       fIntFlowDirectCorrelations->Fill(13.,cos(3.*n*phi1-n*phi2-n*phi3-n*phi4),1.);         // <4>_{3n|n,n,n}
11487       fIntFlowDirectCorrelations->Fill(14.,cos(3.*n*phi1+n*phi2-3.*n*phi3-n*phi4),1.);      // <4>_{3n,n|3n,n}   
11488       fIntFlowDirectCorrelations->Fill(15.,cos(3.*n*phi1+n*phi2-2.*n*phi3-2.*n*phi4),1.);   // <4>_{3n,n|2n,2n}
11489       fIntFlowDirectCorrelations->Fill(16.,cos(4.*n*phi1-2.*n*phi2-n*phi3-n*phi4),1.);      // <4>_{4n|2n,n,n}     
11490       fIntFlowDirectCorrelations->Fill(32.,cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{4n,2n|3n,3n}        
11491       fIntFlowDirectCorrelations->Fill(41.5,cos(n*(6.*phi1-3.*phi2-2.*phi3-1.*phi4)),1.);    // <4>_{6n|3n,2n,1n}  
11492       fIntFlowDirectCorrelations->Fill(42.5,cos(n*(3.*phi1+2.*phi2-3.*phi3-2.*phi4)),1.);    // <4>_{3n,2n|3n,2n}  
11493       fIntFlowDirectCorrelations->Fill(43.5,cos(n*(4.*phi1+1.*phi2-3.*phi3-2.*phi4)),1.);    // <4>_{4n,1n|3n,2n}  
11494       fIntFlowDirectCorrelations->Fill(44.5,cos(n*(3.*phi1+3.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{3n,3n|3n,3n}  
11495       fIntFlowDirectCorrelations->Fill(45.5,cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{4n,2n|3n,3n}  
11496       fIntFlowDirectCorrelations->Fill(46.5,cos(n*(5.*phi1+1.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{5n,1n|3n,3n}  
11497       fIntFlowDirectCorrelations->Fill(47.5,cos(n*(4.*phi1+2.*phi2-4.*phi3-2.*phi4)),1.);    // <4>_{4n,2n|4n,2n}     
11498       fIntFlowDirectCorrelations->Fill(48.5,cos(n*(5.*phi1+1.*phi2-4.*phi3-2.*phi4)),1.);    // <4>_{5n,1n|4n,2n}  
11499       fIntFlowDirectCorrelations->Fill(49.5,cos(n*(5.*phi1-3.*phi2-1.*phi3-1.*phi4)),1.);    // <4>_{5n|3n,1n,1n}  
11500       fIntFlowDirectCorrelations->Fill(50.5,cos(n*(5.*phi1-2.*phi2-2.*phi3-1.*phi4)),1.);    // <4>_{5n|2n,2n,1n}  
11501       fIntFlowDirectCorrelations->Fill(51.5,cos(n*(5.*phi1+1.*phi2-5.*phi3-1.*phi4)),1.);    // <4>_{5n,1n|5n,1n}        
11502       fIntFlowDirectCorrelations->Fill(58.5,cos(n*(6.*phi1-4.*phi2-1.*phi3-1.*phi4)),1.);    // <4>_{6n|4n,1n,1n}  
11503       fIntFlowDirectCorrelations->Fill(59.5,cos(n*(6.*phi1-2.*phi2-2.*phi3-2.*phi4)),1.);    // <4>_{6n|2n,2n,2n}  
11504      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
11505     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11506    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11507   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11508  } // end of if(nPrim>=)
11509
11510  // 5-particle correlations:      
11511  if(nPrim>=5 && nPrim<=fMaxAllowedMultiplicity)
11512  {
11513   for(Int_t i1=0;i1<nPrim;i1++)
11514   {
11515    aftsTrack=anEvent->GetTrack(i1);
11516    if(!(aftsTrack->InRPSelection())) continue;  
11517    phi1=aftsTrack->Phi();
11518    for(Int_t i2=0;i2<nPrim;i2++)
11519    {
11520     if(i2==i1)continue;
11521     aftsTrack=anEvent->GetTrack(i2);
11522     if(!(aftsTrack->InRPSelection())) continue;
11523     phi2=aftsTrack->Phi();
11524     for(Int_t i3=0;i3<nPrim;i3++)
11525     {
11526      if(i3==i1||i3==i2)continue;
11527      aftsTrack=anEvent->GetTrack(i3);
11528      if(!(aftsTrack->InRPSelection())) continue;
11529      phi3=aftsTrack->Phi();
11530      for(Int_t i4=0;i4<nPrim;i4++)
11531      {
11532       if(i4==i1||i4==i2||i4==i3)continue;
11533       aftsTrack=anEvent->GetTrack(i4);
11534       if(!(aftsTrack->InRPSelection())) continue;
11535       phi4=aftsTrack->Phi();
11536       for(Int_t i5=0;i5<nPrim;i5++)
11537       {
11538        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11539        aftsTrack=anEvent->GetTrack(i5);
11540        if(!(aftsTrack->InRPSelection())) continue;
11541        phi5=aftsTrack->Phi();
11542        if(nPrim==5) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<"\r"<<flush;
11543        // fill the profile with 5-p correlations:   
11544        fIntFlowDirectCorrelations->Fill(18.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1.);              // <5>_{2n,n|n,n,n}
11545        fIntFlowDirectCorrelations->Fill(19.,cos(2.*n*phi1+2.*n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);        // <5>_{2n,2n|2n,n,n}
11546        fIntFlowDirectCorrelations->Fill(20.,cos(3.*n*phi1+n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);           // <5>_{3n,n|2n,n,n}
11547        fIntFlowDirectCorrelations->Fill(21.,cos(4.*n*phi1-n*phi2-n*phi3-n*phi4-n*phi5),1.);              // <5>_{4n|n,n,n,n}
11548        fIntFlowDirectCorrelations->Fill(33.,cos(3.*n*phi1+3.*n*phi2-2.*n*phi3-2.*n*phi4-2.*n*phi5),1.);  // <5>_{3n,3n|2n,2n,2n}       
11549        fIntFlowDirectCorrelations->Fill(52.5,cos(3.*n*phi1+3.*n*phi2-3.*n*phi3-2.*n*phi4-1.*n*phi5),1.); // <5>_{3n,3n|3n,2n,1n}      
11550        fIntFlowDirectCorrelations->Fill(53.5,cos(4.*n*phi1+2.*n*phi2-3.*n*phi3-2.*n*phi4-1.*n*phi5),1.); // <5>_{4n,2n|3n,2n,1n}       
11551        fIntFlowDirectCorrelations->Fill(54.5,cos(3.*n*phi1+2.*n*phi2-3.*n*phi3-1.*n*phi4-1.*n*phi5),1.); // <5>_{3n,2n|3n,1n,1n}
11552        fIntFlowDirectCorrelations->Fill(55.5,cos(3.*n*phi1+2.*n*phi2-2.*n*phi3-2.*n*phi4-1.*n*phi5),1.); // <5>_{3n,2n|2n,2n,1n}
11553        fIntFlowDirectCorrelations->Fill(56.5,cos(5.*n*phi1+1.*n*phi2-3.*n*phi3-2.*n*phi4-1.*n*phi5),1.); // <5>_{5n,1n|3n,2n,1n}              
11554        fIntFlowDirectCorrelations->Fill(60.5,cos(6.*n*phi1-2.*n*phi2-2.*n*phi3-1.*n*phi4-1.*n*phi5),1.); // <5>_{6n|2n,2n,1n,1n}
11555        fIntFlowDirectCorrelations->Fill(61.5,cos(4.*n*phi1+1.*n*phi2+1.*n*phi3-3.*n*phi4-3.*n*phi5),1.); // <5>_{4n,1n,1n|3n,3n}              
11556       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11557      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
11558     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11559    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11560   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11561  } // end of if(nPrim>=5)
11562   
11563  // 6-particle correlations:
11564  if(nPrim>=6 && nPrim<=fMaxAllowedMultiplicity)
11565  {
11566   for(Int_t i1=0;i1<nPrim;i1++)
11567   {
11568    aftsTrack=anEvent->GetTrack(i1);
11569    if(!(aftsTrack->InRPSelection())) continue;
11570    phi1=aftsTrack->Phi();
11571    for(Int_t i2=0;i2<nPrim;i2++)
11572    {
11573     if(i2==i1)continue;
11574     aftsTrack=anEvent->GetTrack(i2);
11575     if(!(aftsTrack->InRPSelection())) continue;
11576     phi2=aftsTrack->Phi();
11577     for(Int_t i3=0;i3<nPrim;i3++)
11578     {
11579      if(i3==i1||i3==i2)continue;
11580      aftsTrack=anEvent->GetTrack(i3);
11581      if(!(aftsTrack->InRPSelection())) continue;
11582      phi3=aftsTrack->Phi();
11583      for(Int_t i4=0;i4<nPrim;i4++)
11584      {
11585       if(i4==i1||i4==i2||i4==i3)continue;
11586       aftsTrack=anEvent->GetTrack(i4);
11587       if(!(aftsTrack->InRPSelection())) continue;
11588       phi4=aftsTrack->Phi();
11589       for(Int_t i5=0;i5<nPrim;i5++)
11590       {
11591        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11592        aftsTrack=anEvent->GetTrack(i5);
11593        if(!(aftsTrack->InRPSelection())) continue;
11594        phi5=aftsTrack->Phi();
11595        for(Int_t i6=0;i6<nPrim;i6++)
11596        {
11597         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
11598         aftsTrack=anEvent->GetTrack(i6);
11599         if(!(aftsTrack->InRPSelection())) continue;
11600         phi6=aftsTrack->Phi(); 
11601         if(nPrim==6) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<"\r"<<flush;
11602         // fill the profile with 6-p correlations:   
11603         fIntFlowDirectCorrelations->Fill(23.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),1.);                    // <6>_{1n,1n,1n|1n,1n,1n}
11604         fIntFlowDirectCorrelations->Fill(24.,cos(2.*n*phi1+n*phi2+n*phi3-2.*n*phi4-n*phi5-n*phi6),1.);              // <6>_{2n,1n,1n|2n,1n,1n}
11605         fIntFlowDirectCorrelations->Fill(25.,cos(2.*n*phi1+2.*n*phi2-n*phi3-n*phi4-n*phi5-n*phi6),1.);              // <6>_{2n,2n|1n,1n,1n,1n}
11606         fIntFlowDirectCorrelations->Fill(26.,cos(3.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5-n*phi6),1.);                 // <6>_{3n,1n|1n,1n,1n,1n}  
11607         fIntFlowDirectCorrelations->Fill(57.5,cos(3.*n*phi1+2.*n*phi2+1.*n*phi3-3.*n*phi4-2.*n*phi5-1.*n*phi6),1.); // <6>_{3n,2n,1n|3n,2n,1n}  
11608         fIntFlowDirectCorrelations->Fill(62.5,cos(3.*n*phi1+3.*n*phi2-2.*n*phi3-2.*n*phi4-1.*n*phi5-1.*n*phi6),1.); // <6>_{3n,3n|2n,2n,1n,1n}  
11609        } // end of for(Int_t i6=0;i6<nPrim;i6++)
11610       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11611      } // end of for(Int_t i4=0;i4<nPrim;i4++)
11612     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11613    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11614   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11615  } // end of if(nPrim>=6)
11616   
11617  // 7-particle correlations:
11618  if(nPrim>=7 && nPrim<=fMaxAllowedMultiplicity)
11619  {
11620   for(Int_t i1=0;i1<nPrim;i1++)
11621   { 
11622    aftsTrack=anEvent->GetTrack(i1);
11623    if(!(aftsTrack->InRPSelection())) continue;
11624    phi1=aftsTrack->Phi();
11625    for(Int_t i2=0;i2<nPrim;i2++)
11626    {
11627     if(i2==i1)continue;
11628     aftsTrack=anEvent->GetTrack(i2);
11629     if(!(aftsTrack->InRPSelection())) continue;
11630     phi2=aftsTrack->Phi();
11631     for(Int_t i3=0;i3<nPrim;i3++)
11632     {
11633      if(i3==i1||i3==i2)continue;
11634      aftsTrack=anEvent->GetTrack(i3);
11635      if(!(aftsTrack->InRPSelection())) continue;
11636      phi3=aftsTrack->Phi();
11637      for(Int_t i4=0;i4<nPrim;i4++)
11638      {
11639       if(i4==i1||i4==i2||i4==i3)continue;
11640       aftsTrack=anEvent->GetTrack(i4);
11641       if(!(aftsTrack->InRPSelection())) continue;
11642       phi4=aftsTrack->Phi();
11643       for(Int_t i5=0;i5<nPrim;i5++)
11644       {
11645        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11646        aftsTrack=anEvent->GetTrack(i5);
11647        if(!(aftsTrack->InRPSelection())) continue;
11648        phi5=aftsTrack->Phi();
11649        for(Int_t i6=0;i6<nPrim;i6++)
11650        {
11651         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
11652         aftsTrack=anEvent->GetTrack(i6);
11653         if(!(aftsTrack->InRPSelection())) continue;
11654         phi6=aftsTrack->Phi(); 
11655         for(Int_t i7=0;i7<nPrim;i7++)
11656         {
11657          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
11658          aftsTrack=anEvent->GetTrack(i7);
11659          if(!(aftsTrack->InRPSelection())) continue;
11660          phi7=aftsTrack->Phi(); 
11661          if(nPrim==7) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<"\r"<<flush;
11662          // fill the profile with 7-p correlation:   
11663          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}
11664         } // end of for(Int_t i7=0;i7<nPrim;i7++)
11665        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
11666       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11667      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
11668     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11669    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11670   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11671  } // end of if(nPrim>=7)
11672  
11673  // 8-particle correlations:
11674  if(nPrim>=8 && nPrim<=fMaxAllowedMultiplicity)
11675  {
11676   for(Int_t i1=0;i1<nPrim;i1++)
11677   {
11678    aftsTrack=anEvent->GetTrack(i1);
11679    if(!(aftsTrack->InRPSelection())) continue;
11680    phi1=aftsTrack->Phi();
11681    for(Int_t i2=0;i2<nPrim;i2++)
11682    {
11683     if(i2==i1)continue;
11684     aftsTrack=anEvent->GetTrack(i2);
11685     if(!(aftsTrack->InRPSelection())) continue;
11686     phi2=aftsTrack->Phi();
11687     for(Int_t i3=0;i3<nPrim;i3++)
11688     {
11689      if(i3==i1||i3==i2)continue;
11690      aftsTrack=anEvent->GetTrack(i3);
11691      if(!(aftsTrack->InRPSelection())) continue;
11692      phi3=aftsTrack->Phi();
11693      for(Int_t i4=0;i4<nPrim;i4++)
11694      {
11695       if(i4==i1||i4==i2||i4==i3)continue;
11696       aftsTrack=anEvent->GetTrack(i4);
11697       if(!(aftsTrack->InRPSelection())) continue;
11698       phi4=aftsTrack->Phi();
11699       for(Int_t i5=0;i5<nPrim;i5++)
11700       {
11701        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11702        aftsTrack=anEvent->GetTrack(i5);
11703        if(!(aftsTrack->InRPSelection())) continue;
11704        phi5=aftsTrack->Phi();
11705        for(Int_t i6=0;i6<nPrim;i6++)
11706        {
11707         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
11708         aftsTrack=anEvent->GetTrack(i6);
11709         if(!(aftsTrack->InRPSelection())) continue;
11710         phi6=aftsTrack->Phi();
11711         for(Int_t i7=0;i7<nPrim;i7++)
11712         {
11713          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
11714          aftsTrack=anEvent->GetTrack(i7);
11715          if(!(aftsTrack->InRPSelection())) continue;
11716          phi7=aftsTrack->Phi();
11717          for(Int_t i8=0;i8<nPrim;i8++)
11718          {
11719           if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
11720           aftsTrack=anEvent->GetTrack(i8);
11721           if(!(aftsTrack->InRPSelection())) continue;
11722           phi8=aftsTrack->Phi();
11723           cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<" "<<i8<<"\r"<<flush;
11724           // fill the profile with 8-p correlation:   
11725           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}
11726          } // end of for(Int_t i8=0;i8<nPrim;i8++)
11727         } // end of for(Int_t i7=0;i7<nPrim;i7++) 
11728        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
11729       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11730      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
11731     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11732    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11733   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11734  } // end of if(nPrim>=8)
11735  
11736  cout<<endl;
11737
11738 } // end of AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent)
11739
11740
11741 //==================================================================================================================================
11742
11743
11744 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
11745 {
11746  // Cross-check results for multiparticle correlations needed for int. flow: results from Q-vectors vs results from nested loops.
11747
11748  cout<<endl;
11749  cout<<endl;
11750  cout<<"   *****************************************"<<endl;
11751  cout<<"   **** cross-checking the correlations ****"<<endl;
11752  cout<<"   ****       for integrated flow       ****"<<endl;
11753  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
11754  {
11755   cout<<"   ****   (particle weights not used)   ****"<<endl;
11756  } else
11757    {
11758     cout<<"   ****     (particle weights used)     ****"<<endl;
11759    } 
11760  cout<<"   *****************************************"<<endl;
11761  cout<<endl;
11762  cout<<endl;
11763
11764  Int_t ciMax = 64; // to be improved (removed eventually when I calculate 6th and 8th order with particle weights)
11765  
11766  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
11767  {
11768   ciMax = 11;
11769  }
11770
11771  for(Int_t ci=1;ci<=ciMax;ci++)
11772  {
11773   if(strcmp((fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
11774   cout<<(fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
11775   cout<<"from Q-vectors    = "<<fIntFlowCorrelationsAllPro->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
11776   cout<<"from nested loops = "<<fIntFlowDirectCorrelations->GetBinContent(ci)<<endl;
11777   cout<<endl;
11778  }
11779   
11780 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
11781
11782 //================================================================================================================================
11783
11784 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA()
11785 {
11786  // Cross-check results for corrections terms for non-uniform acceptance needed for int. flow: results from Q-vectors vs results from nested loops.
11787
11788  cout<<endl;
11789  cout<<endl;
11790  cout<<"   *********************************************"<<endl;
11791  cout<<"   **** cross-checking the correction terms ****"<<endl;
11792  cout<<"   **** for non-uniform acceptance relevant ****"<<endl;
11793  cout<<"   ****         for integrated flow         ****"<<endl;
11794  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
11795  {
11796   cout<<"   ****     (particle weights not used)     ****"<<endl;
11797  } else
11798    {
11799     cout<<"   ****       (particle weights used)       ****"<<endl;
11800    } 
11801  cout<<"   *********************************************"<<endl;
11802  cout<<endl;
11803  cout<<endl;
11804
11805  for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
11806  {
11807   for(Int_t sc=0;sc<2;sc++) // sin or cos term
11808   {
11809    if(strcmp((fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
11810    cout<<(fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
11811    cout<<"from Q-vectors    = "<<fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
11812    cout<<"from nested loops = "<<fIntFlowDirectCorrectionTermsForNUA[sc]->GetBinContent(ci)<<endl;
11813    cout<<endl;
11814   } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos term
11815  } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
11816   
11817 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA() 
11818
11819 //================================================================================================================================
11820
11821 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
11822 {
11823  // Evaluate with nested loops multiparticle correlations for integrated flow (using the particle weights). 
11824
11825  // Results are stored in profile fIntFlowDirectCorrelations. 
11826  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrelations is organized as follows:
11827  //
11828  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
11829  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
11830  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
11831  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
11832  //  5th bin:           ----  EMPTY ----
11833  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
11834  //  7th bin: <3>_{3n|2n,1n} = ...
11835  //  8th bin: <3>_{4n|2n,2n} = ...
11836  //  9th bin: <3>_{4n|3n,1n} = ...
11837  // 10th bin:           ----  EMPTY ----
11838  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
11839  // 12th bin: <4>_{2n,1n|2n,1n} = ...
11840  // 13th bin: <4>_{2n,2n|2n,2n} = ...
11841  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
11842  // 15th bin: <4>_{3n,1n|3n,1n} = ...
11843  // 16th bin: <4>_{3n,1n|2n,2n} = ...
11844  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
11845  // 18th bin:           ----  EMPTY ----
11846  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
11847  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
11848  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
11849  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
11850  // 23rd bin:           ----  EMPTY ----
11851  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
11852  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
11853  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
11854  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
11855  // 28th bin:           ----  EMPTY ----
11856  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
11857  // 30th bin:           ----  EMPTY ----
11858  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
11859  
11860  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
11861  // fIntFlowExtraDirectCorrelations binning of which is organized as follows:
11862  
11863  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
11864  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
11865  // ...
11866  
11867  Int_t nPrim = anEvent->NumberOfTracks(); 
11868  AliFlowTrackSimple *aftsTrack = NULL;
11869  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
11870  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
11871  Double_t phi1=0., phi2=0., phi3=0., phi4=0.;
11872  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1.;
11873  Int_t n = fHarmonic; 
11874  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
11875  Double_t dMult = (*fSpk)(0,0);
11876  cout<<endl;
11877  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
11878  if(dMult<2)
11879  {
11880   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
11881  } else if (dMult>fMaxAllowedMultiplicity)
11882    {
11883     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
11884    } else 
11885      { 
11886       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
11887      } 
11888       
11889  // 2-particle correlations:       
11890  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
11891  {
11892   // 2 nested loops multiparticle correlations using particle weights:       
11893   for(Int_t i1=0;i1<nPrim;i1++)
11894   {
11895    aftsTrack=anEvent->GetTrack(i1);
11896    if(!(aftsTrack->InRPSelection())) continue;
11897    phi1=aftsTrack->Phi();
11898    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11899    for(Int_t i2=0;i2<nPrim;i2++)
11900    {
11901     if(i2==i1)continue;
11902     aftsTrack=anEvent->GetTrack(i2);
11903     if(!(aftsTrack->InRPSelection())) continue;
11904     phi2=aftsTrack->Phi();
11905     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
11906     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
11907     // 2-p correlations using particle weights:
11908     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),wPhi1*wPhi2);                  // <w1   w2   cos( n*(phi1-phi2))>
11909     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))>
11910     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))>
11911     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))> 
11912     // extra correlations: 
11913     // 2-p extra correlations (do not appear if particle weights are not used):
11914     if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),pow(wPhi1,3)*wPhi2); // <w1^3 w2 cos(n*(phi1-phi2))>
11915     // ...
11916    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11917   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11918  } // end of if(nPrim>=2)
11919
11920  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
11921  { 
11922   // 3 nested loops multiparticle correlations using particle weights:       
11923   for(Int_t i1=0;i1<nPrim;i1++)
11924   {
11925    aftsTrack=anEvent->GetTrack(i1);
11926    if(!(aftsTrack->InRPSelection())) continue;
11927    phi1=aftsTrack->Phi();
11928    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11929    for(Int_t i2=0;i2<nPrim;i2++)
11930    {
11931     if(i2==i1)continue;
11932     aftsTrack=anEvent->GetTrack(i2);
11933     if(!(aftsTrack->InRPSelection())) continue;
11934     phi2=aftsTrack->Phi();
11935     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11936     for(Int_t i3=0;i3<nPrim;i3++)
11937     {
11938      if(i3==i1||i3==i2)continue;
11939      aftsTrack=anEvent->GetTrack(i3);
11940      if(!(aftsTrack->InRPSelection())) continue;
11941      phi3=aftsTrack->Phi();
11942      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11943      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
11944      // 3-p correlations using particle weights:
11945      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))>
11946      // ...
11947      // extra correlations: 
11948      // 2-p extra correlations (do not appear if particle weights are not used):
11949       if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(1.5,cos(n*(phi1-phi2)),wPhi1*wPhi2*pow(wPhi3,2)); // <w1 w2 w3^2 cos(n*(phi1-phi2))>
11950      // ...
11951      // 3-p extra correlations (do not appear if particle weights are not used):
11952      // ...
11953     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11954    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11955   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11956  } // end of if(nPrim>=3)
11957  
11958  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
11959  {
11960   // 4 nested loops multiparticle correlations using particle weights:       
11961   for(Int_t i1=0;i1<nPrim;i1++)
11962   {
11963    aftsTrack=anEvent->GetTrack(i1);
11964    if(!(aftsTrack->InRPSelection())) continue;
11965    phi1=aftsTrack->Phi();
11966    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11967    for(Int_t i2=0;i2<nPrim;i2++)
11968    {
11969     if(i2==i1)continue;
11970     aftsTrack=anEvent->GetTrack(i2);
11971     if(!(aftsTrack->InRPSelection())) continue;
11972     phi2=aftsTrack->Phi();
11973     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11974     for(Int_t i3=0;i3<nPrim;i3++)
11975     {
11976      if(i3==i1||i3==i2)continue;
11977      aftsTrack=anEvent->GetTrack(i3);
11978      if(!(aftsTrack->InRPSelection())) continue;
11979      phi3=aftsTrack->Phi();
11980      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11981      for(Int_t i4=0;i4<nPrim;i4++)
11982      {
11983       if(i4==i1||i4==i2||i4==i3)continue;
11984       aftsTrack=anEvent->GetTrack(i4);
11985       if(!(aftsTrack->InRPSelection())) continue;
11986       phi4=aftsTrack->Phi();
11987       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
11988       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
11989       // 4-p correlations using particle weights:
11990       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
11991       // extra correlations: 
11992       // 2-p extra correlations (do not appear if particle weights are not used):
11993       // ...
11994       // 3-p extra correlations (do not appear if particle weights are not used):
11995       // ...
11996       // 4-p extra correlations (do not appear if particle weights are not used):
11997       // ...
11998      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
11999     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12000    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12001   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12002  } // end of if(nPrim>=4)
12003
12004  cout<<endl; 
12005
12006 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
12007
12008 //================================================================================================================================
12009
12010 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
12011 {
12012  // Cross-check results for extra multiparticle correlations needed for int. flow 
12013  // which appear only when particle weights are used: results from Q-vectors vs results from nested loops.
12014
12015  cout<<endl;
12016  cout<<endl;
12017  cout<<"   ***********************************************"<<endl;
12018  cout<<"   **** cross-checking the extra correlations ****"<<endl;
12019  cout<<"   ****          for integrated flow          ****"<<endl;
12020  cout<<"   ***********************************************"<<endl;
12021  cout<<endl;
12022  cout<<endl;
12023  
12024  for(Int_t eci=1;eci<=2;eci++) // to be improved (increased eciMax eventually when I calculate 6th and 8th)
12025  {
12026   if(strcmp((fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci), "") == 0) continue;
12027   cout<<(fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci)<<":"<<endl;
12028   cout<<"from Q-vectors    = "<<fIntFlowExtraCorrelationsPro->GetBinContent(eci)<<endl;
12029   cout<<"from nested loops = "<<fIntFlowExtraDirectCorrelations->GetBinContent(eci)<<endl;
12030   cout<<endl;
12031  }
12032
12033 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
12034
12035 //================================================================================================================================
12036
12037 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent)
12038 {
12039  // Evaluate with nested loops correction terms for non-uniform acceptance relevant for NONAME integrated flow (to be improved (name)).
12040  //
12041  // Remark: Both sin and cos correction terms are calculated in this method. Sin terms are stored in fIntFlowDirectCorrectionTermsForNUA[0],
12042  // and cos terms in fIntFlowDirectCorrectionTermsForNUA[1]. Binning of fIntFlowDirectCorrectionTermsForNUA[sc] is organized as follows 
12043  // (sc stands for either sin or cos):
12044  
12045  //  1st bin: <<sc(n*(phi1))>> 
12046  //  2nd bin: <<sc(n*(phi1+phi2))>> 
12047  //  3rd bin: <<sc(n*(phi1-phi2-phi3))>>
12048  //  4th bin: <<sc(n*(2phi1-phi2))>>
12049  
12050  Int_t nPrim = anEvent->NumberOfTracks(); 
12051  AliFlowTrackSimple *aftsTrack = NULL;
12052  Double_t phi1=0., phi2=0., phi3=0.;
12053  Int_t n = fHarmonic; 
12054  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
12055  Double_t dMult = (*fSpk)(0,0);
12056  cout<<endl;
12057  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
12058  if(dMult<1)
12059  {
12060   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
12061  } else if (dMult>fMaxAllowedMultiplicity)
12062    {
12063     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
12064    } else 
12065      { 
12066       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
12067      }
12068  
12069  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
12070  {
12071   // 1-particle correction terms for non-uniform acceptance:       
12072   for(Int_t i1=0;i1<nPrim;i1++)
12073   {
12074    aftsTrack=anEvent->GetTrack(i1);
12075    if(!(aftsTrack->InRPSelection())) continue;
12076    phi1=aftsTrack->Phi();
12077    if(nPrim==1) cout<<i1<<"\r"<<flush;
12078    // sin terms:
12079    fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),1.); // <sin(n*phi1)>  
12080    // cos terms:
12081    fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),1.); // <cos(n*phi1)>
12082   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12083  } // end of if(nPrim>=1) 
12084   
12085  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
12086  {
12087   // 2-particle correction terms for non-uniform acceptance:       
12088   for(Int_t i1=0;i1<nPrim;i1++)
12089   {
12090    aftsTrack=anEvent->GetTrack(i1);
12091    if(!(aftsTrack->InRPSelection())) continue;
12092    phi1=aftsTrack->Phi();  
12093    for(Int_t i2=0;i2<nPrim;i2++)
12094    {
12095     if(i2==i1)continue;
12096     aftsTrack=anEvent->GetTrack(i2);
12097     if(!(aftsTrack->InRPSelection())) continue;
12098     phi2=aftsTrack->Phi();
12099     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
12100     // sin terms:
12101     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),1.); // <<sin(n*(phi1+phi2))>>
12102     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(3.5,sin(n*(2*phi1-phi2)),1.); // <<sin(n*(2*phi1-phi2))>>
12103     // cos terms:
12104     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),1.); // <<cos(n*(phi1+phi2))>>
12105     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(3.5,cos(n*(2*phi1-phi2)),1.); // <<cos(n*(2*phi1-phi2))>>
12106    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12107   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12108  } // end of if(nPrim>=2)
12109
12110  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
12111  {
12112   // 3-particle correction terms for non-uniform acceptance:       
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    for(Int_t i2=0;i2<nPrim;i2++)
12119    {
12120     if(i2==i1)continue;
12121     aftsTrack=anEvent->GetTrack(i2);
12122     if(!(aftsTrack->InRPSelection())) continue;
12123     phi2=aftsTrack->Phi();
12124     for(Int_t i3=0;i3<nPrim;i3++)
12125     {
12126      if(i3==i1||i3==i2)continue;
12127      aftsTrack=anEvent->GetTrack(i3);
12128      if(!(aftsTrack->InRPSelection())) continue;
12129      phi3=aftsTrack->Phi();
12130      if(nPrim>=3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush; // to be improved (eventually I will change this if statement)
12131      // sin terms:
12132      fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),1.); // <<sin(n*(phi1-phi2-phi3))>>
12133      // cos terms:
12134      fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),1.); // <<cos(n*(phi1-phi2-phi3))>>
12135     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12136    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12137   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12138  } // end of if(nPrim>=3)
12139
12140  cout<<endl;
12141 }
12142
12143 //================================================================================================================================
12144
12145 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12146 {
12147  // Evaluate reduced correlations with nested loops without using the particle weights.
12148  
12149  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12150  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
12151  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
12152  // Remark 3: <2'> = <cos(n*(psi1-phi2))>
12153  //           <4'> = <cos(n*(psi1+phi2-phi3-phi4))>
12154  // ...
12155  
12156  Int_t typeFlag = 0;
12157  Int_t ptEtaFlag = 0;
12158  if(type == "RP")
12159  {
12160   typeFlag = 0;
12161  } else if(type == "POI")
12162    {
12163     typeFlag = 1;
12164    }      
12165  if(ptOrEta == "Pt")
12166  {
12167   ptEtaFlag = 0;
12168  } else if(ptOrEta == "Eta")
12169    {
12170     ptEtaFlag = 1;
12171    } 
12172  // shortcuts:
12173  Int_t t = typeFlag;
12174  Int_t pe = ptEtaFlag;
12175       
12176  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12177  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12178  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12179  
12180  Int_t nPrim = anEvent->NumberOfTracks(); 
12181  AliFlowTrackSimple *aftsTrack = NULL;
12182  
12183  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12184  
12185  Int_t n = fHarmonic; 
12186   
12187  // 2'-particle correlations:
12188  for(Int_t i1=0;i1<nPrim;i1++)
12189  {
12190   aftsTrack=anEvent->GetTrack(i1);
12191   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12192   if(typeFlag==1) // this is diff flow of POIs 
12193   {
12194    if(ptOrEta == "Pt")
12195    { 
12196     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12197    } else if (ptOrEta == "Eta")
12198      {
12199       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12200      }
12201   } else // this is diff flow of RPs 
12202     {
12203      if(ptOrEta == "Pt")
12204      { 
12205       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12206      } else if (ptOrEta == "Eta")
12207        {
12208         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12209        }
12210     }
12211        
12212   psi1=aftsTrack->Phi(); 
12213   for(Int_t i2=0;i2<nPrim;i2++)
12214   {
12215    if(i2==i1)continue;
12216    aftsTrack=anEvent->GetTrack(i2);
12217    // RP condition (!(first) particle in the correlator must be RP):
12218    if(!(aftsTrack->InRPSelection()))continue;
12219    phi2=aftsTrack->Phi();   
12220    // 2'-particle correlations: 
12221    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),1.); // <cos(n*(psi1-phi2))  
12222   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12223  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12224  
12225  /*
12226  
12227  // 3'-particle correlations:
12228  for(Int_t i1=0;i1<nPrim;i1++)
12229  {
12230   aftsTrack=anEvent->GetTrack(i1);
12231   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12232   if(ptOrEta == "Pt")
12233   { 
12234    if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12235   } else if (ptOrEta == "Eta")
12236     {
12237      if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12238     }
12239   psi1=aftsTrack->Phi();
12240   for(Int_t i2=0;i2<nPrim;i2++)
12241   {
12242    if(i2==i1)continue;
12243    aftsTrack=anEvent->GetTrack(i2);
12244    // RP condition (!(first) particle in the correlator must be RP):
12245    if(!(aftsTrack->InRPSelection())) continue;
12246    phi2=aftsTrack->Phi();
12247    for(Int_t i3=0;i3<nPrim;i3++)
12248    {
12249     if(i3==i1||i3==i2)continue;
12250     aftsTrack=anEvent->GetTrack(i3);
12251     // RP condition (!(first) particle in the correlator must be RP):
12252     if(!(aftsTrack->InRPSelection())) continue;
12253     phi3=aftsTrack->Phi();
12254     // 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))> 
12255    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
12256   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
12257  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12258  
12259  */
12260  
12261  // 4'-particle correlations:
12262  for(Int_t i1=0;i1<nPrim;i1++)
12263  {
12264   aftsTrack=anEvent->GetTrack(i1);
12265   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12266   if(typeFlag==1) // this is diff flow of POIs 
12267   {
12268    if(ptOrEta == "Pt")
12269    { 
12270     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12271    } else if (ptOrEta == "Eta")
12272      {
12273       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12274      }
12275   } else // this is diff flow of RPs 
12276     {
12277      if(ptOrEta == "Pt")
12278      { 
12279       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12280      } else if (ptOrEta == "Eta")
12281        {
12282         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12283        }
12284     }
12285     
12286   psi1=aftsTrack->Phi();
12287   for(Int_t i2=0;i2<nPrim;i2++)
12288   {
12289    if(i2==i1) continue;
12290    aftsTrack=anEvent->GetTrack(i2);
12291    // RP condition (!(first) particle in the correlator must be RP): 
12292    if(!(aftsTrack->InRPSelection())) continue;
12293    phi2=aftsTrack->Phi();
12294    for(Int_t i3=0;i3<nPrim;i3++)
12295    { 
12296     if(i3==i1||i3==i2) continue;
12297     aftsTrack=anEvent->GetTrack(i3);
12298     // RP condition (!(first) particle in the correlator must be RP):
12299     if(!(aftsTrack->InRPSelection())) continue;
12300     phi3=aftsTrack->Phi();
12301     for(Int_t i4=0;i4<nPrim;i4++)
12302     {
12303      if(i4==i1||i4==i2||i4==i3) continue;
12304      aftsTrack=anEvent->GetTrack(i4);
12305      // RP condition (!(first) particle in the correlator must be RP):
12306      if(!(aftsTrack->InRPSelection())) continue;  
12307      phi4=aftsTrack->Phi();
12308      // 4'-particle correlations:
12309      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),1.); // <cos(n(psi1+phi2-phi3-phi4))>     
12310     }//end of for(Int_t i4=0;i4<nPrim;i4++)
12311    }//end of for(Int_t i3=0;i3<nPrim;i3++)
12312   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
12313  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12314       
12315  // count # of RPs and POIs in selected pt and eta bins for cross-checkings:
12316  for(Int_t i=0;i<nPrim;i++)
12317  {
12318   aftsTrack=anEvent->GetTrack(i); 
12319   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12320   if(typeFlag==1) // this is diff flow of POIs 
12321   {
12322    if(ptOrEta == "Pt")
12323    { 
12324     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12325    } else if (ptOrEta == "Eta")
12326      {
12327       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12328      }
12329   } else // this is diff flow of RPs 
12330     {
12331      if(ptOrEta == "Pt")
12332      { 
12333       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12334      } else if (ptOrEta == "Eta")
12335        {
12336         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12337        }
12338     }
12339   if(t==1)t++; 
12340   fNoOfParticlesInBin->Fill(t+pe+0.5);  
12341  }
12342
12343 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12344
12345 //================================================================================================================================
12346
12347 void AliFlowAnalysisWithQCumulants::EvaluateOtherDiffCorrelatorsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12348 {
12349  // Evaluate other differential correlators with nested loops without using the particle weights.
12350
12351  // Remark 1: Other differential correlators are evaluated in pt bin number fCrossCheckInPtBinNo 
12352  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12353  // Remark 2: Results are stored in 1 bin profiles fOtherDirectDiffCorrelators[t][pe][sc][ci], where indices runs as follows:
12354  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms][ci = correlator index] 
12355  // Remark 3: Correlator index 'ci' runs as follows:
12356  //            0: <exp(n*(psi1-3phi2+2phi3))> (Teaney-Yan correlator)
12357   
12358  Int_t typeFlag = 0;
12359  Int_t ptEtaFlag = 0;
12360  if(type == "RP")
12361  {
12362   typeFlag = 0;
12363  } else if(type == "POI")
12364    {
12365     typeFlag = 1;
12366    }      
12367  if(ptOrEta == "Pt")
12368  {
12369   ptEtaFlag = 0;
12370  } else if(ptOrEta == "Eta")
12371    {
12372     ptEtaFlag = 1;
12373    } 
12374  // shortcuts:
12375  Int_t t = typeFlag;
12376  Int_t pe = ptEtaFlag;
12377       
12378  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12379  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12380  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12381  
12382  Int_t nPrim = anEvent->NumberOfTracks(); 
12383  AliFlowTrackSimple *aftsTrack = NULL;
12384  
12385  Double_t psi1=0., phi2=0., phi3=0.;
12386  
12387  Int_t n = fHarmonic; 
12388
12389  // 3-p correlators:
12390  for(Int_t i1=0;i1<nPrim;i1++)
12391  {
12392   aftsTrack=anEvent->GetTrack(i1);
12393   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12394   if(typeFlag==1) // this is diff flow of POIs 
12395   {
12396    if(ptOrEta == "Pt")
12397    { 
12398     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12399    } else if (ptOrEta == "Eta")
12400      {
12401       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12402      }
12403   } else // this is diff flow of RPs 
12404     {
12405      if(ptOrEta == "Pt")
12406      { 
12407       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12408      } else if (ptOrEta == "Eta")
12409        {
12410         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12411        }
12412     }
12413   psi1=aftsTrack->Phi();
12414   for(Int_t i2=0;i2<nPrim;i2++)
12415   {
12416    if(i2==i1) continue;
12417    aftsTrack=anEvent->GetTrack(i2);
12418    // RP condition (!(first) particle in the correlator must be RP): 
12419    if(!(aftsTrack->InRPSelection())) continue;
12420    phi2=aftsTrack->Phi();
12421    for(Int_t i3=0;i3<nPrim;i3++)
12422    { 
12423     if(i3==i1||i3==i2) continue;
12424     aftsTrack=anEvent->GetTrack(i3);
12425     // RP condition (!(first) particle in the correlator must be RP):
12426     if(!(aftsTrack->InRPSelection())) continue;
12427     phi3=aftsTrack->Phi();
12428     // Fill 3-p correlators:
12429     fOtherDirectDiffCorrelators[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-3.*phi2+2.*phi3)),1.); // <cos(n(psi1-3.*phi2+2.*phi3))>     
12430    }//end of for(Int_t i3=0;i3<nPrim;i3++)
12431   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
12432  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
12433 } // end of void AliFlowAnalysisWithQCumulants::EvaluateOtherDiffCorrelatorsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12434
12435 //================================================================================================================================
12436
12437 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
12438 {
12439  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
12440  
12441  Int_t typeFlag = 0;
12442  Int_t ptEtaFlag = 0;
12443  if(type == "RP")
12444  {
12445   typeFlag = 0;
12446  } else if(type == "POI")
12447    {
12448     typeFlag = 1;
12449    }      
12450  if(ptOrEta == "Pt")
12451  {
12452   ptEtaFlag = 0;
12453  } else if(ptOrEta == "Eta")
12454    {
12455     ptEtaFlag = 1;
12456    } 
12457  // shortcuts:
12458  Int_t t = typeFlag;
12459  Int_t pe = ptEtaFlag;
12460       
12461  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12462  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12463  TString reducedCorrelations[4] = {"<<cos(n(psi1-phi2))>>","<<cos(n(psi1+phi2-phi3-phi4))>>","",""}; // to be improved (access this from pro or hist)
12464  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12465  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12466  
12467  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
12468  
12469
12470  cout<<endl;
12471  cout<<"   *****************************************"<<endl;
12472  cout<<"   **** cross-checking the correlations ****"<<endl;
12473  cout<<"   ****   for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
12474  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
12475  {
12476   cout<<"   ****   (particle weights not used)   ****"<<endl;
12477  } else
12478    {
12479     cout<<"   ****    (particle weights used)      ****"<<endl;
12480    } 
12481  cout<<"   *****************************************"<<endl; 
12482  cout<<endl;
12483  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
12484  cout<<endl;
12485  
12486  for(Int_t rci=0;rci<2;rci++) // to be improved (calculate 6th and 8th order)
12487  {
12488   cout<<"      "<<reducedCorrelations[rci].Data()<<":"<<endl;
12489   cout<<"      from Q-vectors    = "<<fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
12490   cout<<"      from nested loops = "<<fDiffFlowDirectCorrelations[t][pe][rci]->GetBinContent(1)<<endl;
12491   cout<<endl;  
12492  } // end of for(Int_t rci=0;rci<4;rci++)
12493         
12494 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
12495
12496 //================================================================================================================================
12497
12498 void AliFlowAnalysisWithQCumulants::CrossCheckOtherDiffCorrelators(TString type, TString ptOrEta)
12499 {
12500  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
12501  
12502  Int_t typeFlag = 0;
12503  Int_t ptEtaFlag = 0;
12504  if(type == "RP")
12505  {
12506   typeFlag = 0;
12507  } else if(type == "POI")
12508    {
12509     typeFlag = 1;
12510    }      
12511  if(ptOrEta == "Pt")
12512  {
12513   ptEtaFlag = 0;
12514  } else if(ptOrEta == "Eta")
12515    {
12516     ptEtaFlag = 1;
12517    } 
12518  // shortcuts:
12519  Int_t t = typeFlag;
12520  Int_t pe = ptEtaFlag;
12521       
12522  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12523  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12524  TString otherCorrelators[1] = {"<<cos(n(psi1-3phi2+2phi3))>>"}; // to be improved (access this from pro or hist)
12525  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12526  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12527  
12528  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
12529
12530  cout<<endl;
12531  cout<<"   *****************************************"<<endl;
12532  cout<<"   ****   cross-checking the other      ****"<<endl;
12533  cout<<"   ****   diff. correlators ("<<rpORpoiString[t]<<")       ****"<<endl;
12534  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
12535  {
12536   cout<<"   ****   (particle weights not used)   ****"<<endl;
12537  } else
12538    {
12539     cout<<"   ****    (particle weights used)      ****"<<endl;
12540    } 
12541  cout<<"   *****************************************"<<endl; 
12542  cout<<endl;
12543  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
12544  cout<<endl;
12545  
12546  for(Int_t ci=0;ci<1;ci++) 
12547  {
12548   cout<<"      "<<otherCorrelators[ci].Data()<<":"<<endl;
12549   cout<<"      from Q-vectors    = "<<fOtherDiffCorrelators[t][pe][1][ci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
12550   cout<<"      from nested loops = "<<fOtherDirectDiffCorrelators[t][pe][1][ci]->GetBinContent(1)<<endl;
12551   cout<<endl;  
12552  } // end of for(Int_t ci=0;ci<1;ci++)
12553         
12554 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckOtherDiffCorrelators(TString type, TString ptOrEta)
12555
12556 //================================================================================================================================
12557
12558 void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
12559 {
12560  // Print on the screen number of RPs and POIs in selected pt and eta bin for cross checkings.
12561  
12562  cout<<endl;
12563  cout<<"Number of RPs in selected pt bin   = "<<fNoOfParticlesInBin->GetBinContent(1)<<endl;
12564  cout<<"Number of RPs in selected eta bin  = "<<fNoOfParticlesInBin->GetBinContent(2)<<endl;
12565  cout<<"Number of POIs in selected pt bin  = "<<fNoOfParticlesInBin->GetBinContent(3)<<endl;
12566  cout<<"Number of POIs in selected eta bin = "<<fNoOfParticlesInBin->GetBinContent(4)<<endl;
12567  
12568 } // end of void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
12569
12570 //================================================================================================================================
12571
12572 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12573 {
12574  // Evaluate reduced correlations with nested loops without using the particle weights.
12575  
12576  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12577  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
12578  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
12579  // Remark 3: <2'> = <w2 cos(n*(psi1-phi2))>
12580  //           <4'> = <w2 w3 w4 cos(n*(psi1+phi2-phi3-phi4))>
12581  // ...
12582   
12583  Int_t typeFlag = 0;
12584  Int_t ptEtaFlag = 0;
12585  if(type == "RP")
12586  {
12587   typeFlag = 0;
12588  } else if(type == "POI")
12589    {
12590     typeFlag = 1;
12591    }      
12592  if(ptOrEta == "Pt")
12593  {
12594   ptEtaFlag = 0;
12595  } else if(ptOrEta == "Eta")
12596    {
12597     ptEtaFlag = 1;
12598    } 
12599  // shortcuts:
12600  Int_t t = typeFlag;
12601  Int_t pe = ptEtaFlag;
12602       
12603  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12604  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12605  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12606  
12607  Int_t nPrim = anEvent->NumberOfTracks(); 
12608  AliFlowTrackSimple *aftsTrack = NULL;
12609  
12610  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12611  Double_t wPhi2=1., wPhi3=1., wPhi4=1.;// wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
12612  
12613  Int_t n = fHarmonic; 
12614  
12615  // 2'-particle correlations:
12616  for(Int_t i1=0;i1<nPrim;i1++)
12617  {
12618   aftsTrack=anEvent->GetTrack(i1);
12619   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12620   if(typeFlag==1) // this is diff flow of POIs 
12621   {
12622    if(ptOrEta == "Pt")
12623    { 
12624     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12625    } else if (ptOrEta == "Eta")
12626      {
12627       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12628      }
12629   } else // this is diff flow of RPs 
12630     {
12631      if(ptOrEta == "Pt")
12632      { 
12633       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12634      } else if (ptOrEta == "Eta")
12635        {
12636         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12637        }
12638     }
12639   psi1=aftsTrack->Phi(); 
12640   for(Int_t i2=0;i2<nPrim;i2++)
12641   {
12642    if(i2==i1) continue;
12643    aftsTrack=anEvent->GetTrack(i2);
12644    // RP condition (!(first) particle in the correlator must be RP):
12645    if(!(aftsTrack->InRPSelection())) continue;
12646    phi2=aftsTrack->Phi();   
12647    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12648    // 2'-particle correlations: 
12649    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),wPhi2); // <w2 cos(n*(psi1-phi2))  
12650   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12651  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12652  
12653  // 4'-particle correlations:
12654  for(Int_t i1=0;i1<nPrim;i1++)
12655  {
12656   aftsTrack=anEvent->GetTrack(i1);
12657   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12658   if(typeFlag==1) // this is diff flow of POIs 
12659   {
12660    if(ptOrEta == "Pt")
12661    { 
12662     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12663    } else if (ptOrEta == "Eta")
12664      {
12665       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12666      }
12667   } else // this is diff flow of RPs 
12668     {
12669      if(ptOrEta == "Pt")
12670      { 
12671       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12672      } else if (ptOrEta == "Eta")
12673        {
12674         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12675        }
12676     }
12677   psi1=aftsTrack->Phi();
12678   for(Int_t i2=0;i2<nPrim;i2++)
12679   {
12680    if(i2==i1) continue;
12681    aftsTrack=anEvent->GetTrack(i2);
12682    // RP condition (!(first) particle in the correlator must be RP): 
12683    if(!(aftsTrack->InRPSelection())) continue;
12684    phi2=aftsTrack->Phi();
12685    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12686    for(Int_t i3=0;i3<nPrim;i3++)
12687    { 
12688     if(i3==i1||i3==i2) continue;
12689     aftsTrack=anEvent->GetTrack(i3);
12690     // RP condition (!(first) particle in the correlator must be RP):
12691     if(!(aftsTrack->InRPSelection())) continue;
12692     phi3=aftsTrack->Phi();
12693     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12694     for(Int_t i4=0;i4<nPrim;i4++)
12695     {
12696      if(i4==i1||i4==i2||i4==i3) continue;
12697      aftsTrack=anEvent->GetTrack(i4);
12698      // RP condition (!(first) particle in the correlator must be RP):
12699      if(!(aftsTrack->InRPSelection())) continue;  
12700      phi4=aftsTrack->Phi();
12701      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
12702      // 4'-particle correlations <w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))>:
12703      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),wPhi2*wPhi3*wPhi4); 
12704     }//end of for(Int_t i4=0;i4<nPrim;i4++)
12705    }//end of for(Int_t i3=0;i3<nPrim;i3++)
12706   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
12707  }//end of for(Int_t i1=0;i1<nPrim;i1++)      
12708  
12709  // count # of RPs and POIs in selected pt and eta bins for cross-checkings: (to be improved - moved to dedicated method)
12710  for(Int_t i=0;i<nPrim;i++)
12711  {
12712   aftsTrack=anEvent->GetTrack(i); 
12713   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12714   if(typeFlag==1) // this is diff flow of POIs 
12715   {
12716    if(ptOrEta == "Pt")
12717    { 
12718     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12719    } else if (ptOrEta == "Eta")
12720      {
12721       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12722      }
12723   } else // this is diff flow of RPs 
12724     {
12725      if(ptOrEta == "Pt")
12726      { 
12727       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12728      } else if (ptOrEta == "Eta")
12729        {
12730         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12731        }
12732     }
12733   if(t==1)t++; 
12734   fNoOfParticlesInBin->Fill(t+pe+0.5);  
12735  }
12736  
12737 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12738
12739 //================================================================================================================================
12740
12741 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12742 {
12743  // Evaluate with nested loops correction terms for non-uniform acceptance (both sin and cos terms) relevant for differential flow.
12744  
12745  // Remark 1: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
12746  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12747  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
12748  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
12749  //  cti: 
12750  //    0: <<sc n(psi1)>>
12751  //    1: <<sc n(psi1+phi2)>> 
12752  //    2: <<sc n(psi1+phi2-phi3)>>
12753  //    3: <<sc n(psi1-phi2-phi3)>>
12754  //    4:
12755  //    5:
12756  //    6:
12757   
12758  Int_t typeFlag = 0;
12759  Int_t ptEtaFlag = 0;
12760  if(type == "RP")
12761  {
12762   typeFlag = 0;
12763  } else if(type == "POI")
12764    {
12765     typeFlag = 1;
12766    }      
12767  if(ptOrEta == "Pt")
12768  {
12769   ptEtaFlag = 0;
12770  } else if(ptOrEta == "Eta")
12771    {
12772     ptEtaFlag = 1;
12773    } 
12774  // shortcuts:
12775  Int_t t = typeFlag;
12776  Int_t pe = ptEtaFlag;
12777       
12778  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12779  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12780  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12781  
12782  Int_t nPrim = anEvent->NumberOfTracks(); 
12783  AliFlowTrackSimple *aftsTrack = NULL;
12784  
12785  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12786  
12787  Int_t n = fHarmonic; 
12788  
12789  // 1-particle correction terms:
12790  for(Int_t i1=0;i1<nPrim;i1++)
12791  {
12792   aftsTrack=anEvent->GetTrack(i1);
12793   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12794   if(typeFlag==1) // this is diff flow of POIs 
12795   {
12796    if(ptOrEta == "Pt")
12797    { 
12798     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12799    } else if (ptOrEta == "Eta")
12800      {
12801       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12802      }
12803   } else // this is diff flow of RPs 
12804     {
12805      if(ptOrEta == "Pt")
12806      { 
12807       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12808      } else if (ptOrEta == "Eta")
12809        {
12810         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12811        }
12812     }
12813   psi1=aftsTrack->Phi(); 
12814   // sin terms: 
12815   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
12816   // cos terms: 
12817   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
12818  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12819    
12820  // 2-particle correction terms:
12821  for(Int_t i1=0;i1<nPrim;i1++)
12822  {
12823   aftsTrack=anEvent->GetTrack(i1);
12824    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12825   if(typeFlag==1) // this is diff flow of POIs 
12826   {
12827    if(ptOrEta == "Pt")
12828    { 
12829     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12830    } else if (ptOrEta == "Eta")
12831      {
12832       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12833      }
12834   } else // this is diff flow of RPs 
12835     {
12836      if(ptOrEta == "Pt")
12837      { 
12838       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12839      } else if (ptOrEta == "Eta")
12840        {
12841         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12842        }
12843     }
12844   psi1=aftsTrack->Phi(); 
12845   for(Int_t i2=0;i2<nPrim;i2++)
12846   {
12847    if(i2==i1) continue;
12848    aftsTrack=anEvent->GetTrack(i2);
12849    // RP condition (!(first) particle in the correlator must be RP):
12850    if(!(aftsTrack->InRPSelection())) continue;
12851    phi2=aftsTrack->Phi();   
12852    // sin terms: 
12853    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),1.); // <<sin(n*(psi1+phi2))>>  
12854    // cos terms: 
12855    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),1.); // <<cos(n*(psi1+phi2))>>  
12856   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12857  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
12858  
12859  // 3-particle correction terms:
12860  for(Int_t i1=0;i1<nPrim;i1++)
12861  {
12862   aftsTrack=anEvent->GetTrack(i1);
12863    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12864   if(typeFlag==1) // this is diff flow of POIs 
12865   {
12866    if(ptOrEta == "Pt")
12867    { 
12868     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12869    } else if (ptOrEta == "Eta")
12870      {
12871       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12872      }
12873   } else // this is diff flow of RPs 
12874     {
12875      if(ptOrEta == "Pt")
12876      { 
12877       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12878      } else if (ptOrEta == "Eta")
12879        {
12880         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12881        }
12882     }
12883   psi1=aftsTrack->Phi();
12884   for(Int_t i2=0;i2<nPrim;i2++)
12885   {
12886    if(i2==i1) continue;
12887    aftsTrack=anEvent->GetTrack(i2);
12888    // RP condition (!(first) particle in the correlator must be RP):
12889    if(!(aftsTrack->InRPSelection())) continue;
12890    phi2=aftsTrack->Phi();
12891    for(Int_t i3=0;i3<nPrim;i3++)
12892    {
12893     if(i3==i1||i3==i2) continue;
12894     aftsTrack=anEvent->GetTrack(i3);
12895     // RP condition (!(first) particle in the correlator must be RP):
12896     if(!(aftsTrack->InRPSelection())) continue;
12897     phi3=aftsTrack->Phi();
12898     // sin terms: 
12899     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2-phi3)),1.); // <<sin(n*(psi1+phi2-phi3))>>  
12900     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1-phi2-phi3)),1.); // <<sin(n*(psi1-phi2-phi3))>>  
12901     // cos terms: 
12902     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3)),1.); // <<cos(n*(psi1+phi2-phi3))>>  
12903     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-phi2-phi3)),1.); // <<cos(n*(psi1-phi2-phi3))>>  
12904    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
12905   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
12906  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12907    
12908 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12909
12910
12911 //================================================================================================================================
12912
12913
12914 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
12915 {
12916  // Compare corrections temrs for non-uniform acceptance needed for diff. flow calculated with nested loops and those calculated from Q-vectors
12917  
12918  Int_t typeFlag = 0;
12919  Int_t ptEtaFlag = 0;
12920  if(type == "RP")
12921  {
12922   typeFlag = 0;
12923  } else if(type == "POI")
12924    {
12925     typeFlag = 1;
12926    }      
12927  if(ptOrEta == "Pt")
12928  {
12929   ptEtaFlag = 0;
12930  } else if(ptOrEta == "Eta")
12931    {
12932     ptEtaFlag = 1;
12933    } 
12934  // shortcuts:
12935  Int_t t = typeFlag;
12936  Int_t pe = ptEtaFlag;
12937       
12938  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12939  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12940  //TString sinCosFlag[2] = {"sin","cos"}; // to be improved (eventually promote to data member)
12941  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)
12942  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)
12943  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12944  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12945  
12946  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
12947  
12948  cout<<endl;
12949  cout<<"   ******************************************"<<endl;
12950  cout<<"   ****  cross-checking the correction   ****"<<endl;
12951  cout<<"   **** terms for non-uniform acceptance ****"<<endl; 
12952  cout<<"   ****    for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
12953  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
12954  {
12955   cout<<"   ****    (particle weights not used)   ****"<<endl;
12956  } else
12957    {
12958     cout<<"   ****     (particle weights used)      ****"<<endl;
12959    } 
12960  cout<<"   ******************************************"<<endl; 
12961  cout<<endl;
12962  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
12963  cout<<endl;
12964  
12965  for(Int_t cti=0;cti<4;cti++) // correction term index
12966  {
12967   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
12968   {
12969    if(sc==0) // to be improved (this can be implemented better)
12970    { 
12971     cout<<"      "<<reducedCorrectionSinTerms[cti].Data()<<":"<<endl;
12972    } else
12973      {
12974       cout<<"      "<<reducedCorrectionCosTerms[cti].Data()<<":"<<endl;     
12975      }
12976    cout<<"      from Q-vectors    = "<<fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
12977    cout<<"      from nested loops = "<<fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]->GetBinContent(1)<<endl;
12978    cout<<endl;  
12979   } 
12980  } // end of for(Int_t rci=0;rci<4;rci++)
12981
12982 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
12983
12984 //================================================================================================================================
12985
12986 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
12987 {
12988  // Calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (cos terms).
12989  
12990  //                                  **********************************************************************
12991  //                                  **** weighted corrections for non-uniform acceptance (cos terms): ****
12992  //                                  **********************************************************************
12993  
12994  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
12995  //
12996  // 1st bin: <<w1 cos(n*(phi1))>> = cosP1nW1
12997  // 2nd bin: <<w1 w2 cos(n*(phi1+phi2))>> = cosP1nP1nW1W1
12998  // 3rd bin: <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1nW1W1W1 
12999  // ...
13000
13001  // multiplicity (number of particles used to determine the reaction plane)
13002  Double_t dMult = (*fSpk)(0,0);
13003  
13004  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13005  Double_t dReQ1n1k = (*fReQ)(0,1);
13006  Double_t dReQ2n2k = (*fReQ)(1,2);
13007  //Double_t dReQ3n3k = (*fReQ)(2,3);
13008  //Double_t dReQ4n4k = (*fReQ)(3,4);
13009  Double_t dReQ1n3k = (*fReQ)(0,3);
13010  Double_t dImQ1n1k = (*fImQ)(0,1);
13011  Double_t dImQ2n2k = (*fImQ)(1,2);
13012  //Double_t dImQ3n3k = (*fImQ)(2,3);
13013  //Double_t dImQ4n4k = (*fImQ)(3,4);
13014  //Double_t dImQ1n3k = (*fImQ)(0,3);
13015
13016  // dMs are variables introduced in order to simplify some Eqs. bellow:
13017  //..............................................................................................
13018  Double_t dM11 = (*fSpk)(1,1)-(*fSpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
13019  Double_t dM111 = (*fSpk)(2,1)-3.*(*fSpk)(0,2)*(*fSpk)(0,1)
13020                 + 2.*(*fSpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
13021  //..............................................................................................
13022          // 1-particle:
13023  Double_t cosP1nW1 = 0.; // <<w1 cos(n*(phi1))>>
13024    
13025  if(dMult>0 && TMath::Abs((*fSpk)(0,1))>1.e-6)
13026  {
13027   cosP1nW1 = dReQ1n1k/(*fSpk)(0,1); 
13028   
13029   // average weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
13030   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1nW1);
13031   
13032   // final average weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
13033   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1nW1,(*fSpk)(0,1));  
13034  } 
13035  
13036  // 2-particle:
13037  Double_t cosP1nP1nW1W1 = 0.; // <<w1 w2 cos(n*(phi1+phi2))>>
13038  
13039  if(dMult>1 && TMath::Abs(dM11)>1.e-6)
13040  {
13041   cosP1nP1nW1W1 = (pow(dReQ1n1k,2)-pow(dImQ1n1k,2)-dReQ2n2k)/dM11; 
13042   
13043   // average weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
13044   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1nW1W1);
13045   
13046   // final average weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
13047   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1nW1W1,dM11);  
13048  } 
13049  
13050  // 3-particle:
13051  Double_t cosP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>>
13052  
13053  if(dMult>2 && TMath::Abs(dM111)>1.e-6)
13054  {
13055   cosP1nM1nM1nW1W1W1 = (dReQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
13056                      - dReQ1n1k*dReQ2n2k-dImQ1n1k*dImQ2n2k
13057                      - 2.*((*fSpk)(0,2))*dReQ1n1k
13058                      + 2.*dReQ1n3k) 
13059                      / dM111; 
13060   
13061   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
13062   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1nW1W1W1);
13063   
13064   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
13065   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1nW1W1W1,dM111);  
13066  } 
13067  
13068 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
13069
13070
13071 //================================================================================================================================
13072
13073
13074 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
13075 {
13076  // calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
13077  
13078  //                                  **********************************************************************
13079  //                                  **** weighted corrections for non-uniform acceptance (sin terms): ****
13080  //                                  **********************************************************************
13081  
13082  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
13083  //
13084  // 1st bin: <<w1 sin(n*(phi1))>> = sinP1nW1
13085  // 2nd bin: <<w1 w2 sin(n*(phi1+phi2))>> = sinP1nP1nW1W1
13086  // 3rd bin: <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1nW1W1W1 
13087  // ...
13088
13089  // multiplicity (number of particles used to determine the reaction plane)
13090  Double_t dMult = (*fSpk)(0,0);
13091  
13092  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13093  Double_t dReQ1n1k = (*fReQ)(0,1);
13094  Double_t dReQ2n2k = (*fReQ)(1,2);
13095  //Double_t dReQ3n3k = (*fReQ)(2,3);
13096  //Double_t dReQ4n4k = (*fReQ)(3,4);
13097  //Double_t dReQ1n3k = (*fReQ)(0,3);
13098  Double_t dImQ1n1k = (*fImQ)(0,1);
13099  Double_t dImQ2n2k = (*fImQ)(1,2);
13100  //Double_t dImQ3n3k = (*fImQ)(2,3);
13101  //Double_t dImQ4n4k = (*fImQ)(3,4);
13102  Double_t dImQ1n3k = (*fImQ)(0,3);
13103
13104  // dMs are variables introduced in order to simplify some Eqs. bellow:
13105  //..............................................................................................
13106  Double_t dM11 = (*fSpk)(1,1)-(*fSpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
13107  Double_t dM111 = (*fSpk)(2,1)-3.*(*fSpk)(0,2)*(*fSpk)(0,1)
13108                 + 2.*(*fSpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
13109  //..............................................................................................
13110  
13111  // 1-particle:
13112  Double_t sinP1nW1 = 0.; // <<w1 sin(n*(phi1))>>
13113  
13114  if(dMult>0 && TMath::Abs((*fSpk)(0,1))>1.e-6)
13115  {
13116   sinP1nW1 = dImQ1n1k/((*fSpk)(0,1)); 
13117      
13118   // average weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
13119   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1nW1);
13120   
13121   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
13122   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1nW1,(*fSpk)(0,1));  
13123  } 
13124  
13125  // 2-particle:
13126  Double_t sinP1nP1nW1W1 = 0.; // <<w1 w2 sin(n*(phi1+phi2))>>
13127  
13128  if(dMult>1 && TMath::Abs(dM11)>1.e-6)
13129  {
13130   sinP1nP1nW1W1 = (2.*dReQ1n1k*dImQ1n1k-dImQ2n2k)/dM11; 
13131      
13132   // average weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
13133   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1nW1W1);
13134   
13135   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
13136   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1nW1W1,dM11);  
13137  } 
13138  
13139  // 3-particle:
13140  Double_t sinP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>>
13141  
13142  if(dMult>2 && TMath::Abs(dM111)>1.e-6)
13143  {
13144   sinP1nM1nM1nW1W1W1 = (-dImQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
13145                      + dReQ1n1k*dImQ2n2k-dImQ1n1k*dReQ2n2k
13146                      + 2.*((*fSpk)(0,2))*dImQ1n1k
13147                      - 2.*dImQ1n3k)
13148                      / dM111; 
13149   
13150   // average weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
13151   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1nW1W1W1);
13152   
13153   // final average weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
13154   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1nW1W1W1,dM111);  
13155  } 
13156  
13157 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
13158
13159 //================================================================================================================================
13160
13161 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
13162 {
13163  // Evaluate with nested loops correction terms for non-uniform acceptance for integrated flow (using the particle weights). 
13164
13165  // Results are stored in profiles fIntFlowDirectCorrectionTermsForNUA[0] (sin terms) and
13166  // fIntFlowDirectCorrectionTermsForNUA[1] (cos terms). 
13167  
13168  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrectionTermsForNUA[sc] is 
13169  // organized as follows (sc stands for either sin or cos):
13170  //
13171  // 1st bin: <<w1 sc(n*(phi1))>> = scP1nW1
13172  // 2nd bin: <<w1 w2 sc(n*(phi1+phi2))>> = scP1nP1nW1W1
13173  // 3rd bin: <<w1 w2 w3 sc(n*(phi1-phi2-phi3))>> = scP1nM1nM1nW1W1W1 
13174  // ...
13175   
13176  Int_t nPrim = anEvent->NumberOfTracks(); 
13177  AliFlowTrackSimple *aftsTrack = NULL;
13178  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
13179  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
13180  Double_t phi1=0., phi2=0., phi3=0.;
13181  Double_t wPhi1=1., wPhi2=1., wPhi3=1.;
13182  Int_t n = fHarmonic; 
13183  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
13184  Double_t dMult = (*fSpk)(0,0);
13185  cout<<endl;
13186  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
13187  if(dMult<1)
13188  {
13189   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
13190  } else if (dMult>fMaxAllowedMultiplicity)
13191    {
13192     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
13193    } else 
13194      { 
13195       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
13196      } 
13197       
13198  // 1-particle correction terms using particle weights:       
13199  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
13200  {
13201   for(Int_t i1=0;i1<nPrim;i1++)
13202   {
13203    aftsTrack=anEvent->GetTrack(i1);
13204    if(!(aftsTrack->InRPSelection())) continue;
13205    phi1=aftsTrack->Phi();
13206    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13207    // 1-particle correction terms using particle weights:
13208    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),wPhi1); // <w1 sin(n*phi1)>
13209    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),wPhi1); // <w1 cos(n*phi1)>
13210   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13211  } // end of if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity) 
13212  
13213  // 2-particle correction terms using particle weights:       
13214  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
13215  {
13216   for(Int_t i1=0;i1<nPrim;i1++)
13217   {
13218    aftsTrack=anEvent->GetTrack(i1);
13219    if(!(aftsTrack->InRPSelection())) continue;
13220    phi1=aftsTrack->Phi();
13221    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13222    for(Int_t i2=0;i2<nPrim;i2++)
13223    {
13224     if(i2==i1)continue;
13225     aftsTrack=anEvent->GetTrack(i2);
13226     if(!(aftsTrack->InRPSelection())) continue;
13227     phi2=aftsTrack->Phi();
13228     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
13229     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
13230     // 2-p correction terms using particle weights:    
13231     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 sin(n*(phi1+phi2))>
13232     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 cos(n*(phi1+phi2))>
13233    } // end of for(Int_t i2=0;i2<nPrim;i2++)
13234   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13235  } // end of if(nPrim>=2)
13236
13237  // 3-particle correction terms using particle weights:       
13238  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
13239  { 
13240   for(Int_t i1=0;i1<nPrim;i1++)
13241   {
13242    aftsTrack=anEvent->GetTrack(i1);
13243    if(!(aftsTrack->InRPSelection())) continue;
13244    phi1=aftsTrack->Phi();
13245    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13246    for(Int_t i2=0;i2<nPrim;i2++)
13247    {
13248     if(i2==i1)continue;
13249     aftsTrack=anEvent->GetTrack(i2);
13250     if(!(aftsTrack->InRPSelection())) continue;
13251     phi2=aftsTrack->Phi();
13252     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
13253     for(Int_t i3=0;i3<nPrim;i3++)
13254     {
13255      if(i3==i1||i3==i2)continue;
13256      aftsTrack=anEvent->GetTrack(i3);
13257      if(!(aftsTrack->InRPSelection())) continue;
13258      phi3=aftsTrack->Phi();
13259      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
13260      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
13261      // 3-p correction terms using particle weights:    
13262      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 sin(n*(phi1-phi2-phi3))>
13263      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n*(phi1-phi2-phi3))>
13264     } // end of for(Int_t i3=0;i3<nPrim;i3++)
13265    } // end of for(Int_t i2=0;i2<nPrim;i2++)
13266   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13267  } // end of if(nPrim>=3)
13268  
13269  /*
13270  
13271  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
13272  {
13273   // 4 nested loops multiparticle correlations using particle weights:       
13274   for(Int_t i1=0;i1<nPrim;i1++)
13275   {
13276    aftsTrack=anEvent->GetTrack(i1);
13277    if(!(aftsTrack->InRPSelection())) continue;
13278    phi1=aftsTrack->Phi();
13279    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13280    for(Int_t i2=0;i2<nPrim;i2++)
13281    {
13282     if(i2==i1)continue;
13283     aftsTrack=anEvent->GetTrack(i2);
13284     if(!(aftsTrack->InRPSelection())) continue;
13285     phi2=aftsTrack->Phi();
13286     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
13287     for(Int_t i3=0;i3<nPrim;i3++)
13288     {
13289      if(i3==i1||i3==i2)continue;
13290      aftsTrack=anEvent->GetTrack(i3);
13291      if(!(aftsTrack->InRPSelection())) continue;
13292      phi3=aftsTrack->Phi();
13293      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
13294      for(Int_t i4=0;i4<nPrim;i4++)
13295      {
13296       if(i4==i1||i4==i2||i4==i3)continue;
13297       aftsTrack=anEvent->GetTrack(i4);
13298       if(!(aftsTrack->InRPSelection())) continue;
13299       phi4=aftsTrack->Phi();
13300       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
13301       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
13302       // 4-p correlations using particle weights:
13303       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
13304       // extra correlations: 
13305       // 2-p extra correlations (do not appear if particle weights are not used):
13306       // ...
13307       // 3-p extra correlations (do not appear if particle weights are not used):
13308       // ...
13309       // 4-p extra correlations (do not appear if particle weights are not used):
13310       // ...
13311      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
13312     } // end of for(Int_t i3=0;i3<nPrim;i3++)
13313    } // end of for(Int_t i2=0;i2<nPrim;i2++)
13314   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13315  } // end of if(nPrim>=4)
13316
13317  */
13318
13319  cout<<endl; 
13320
13321 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
13322
13323 //================================================================================================================================
13324
13325 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
13326 {
13327  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms) using particle weights.
13328  
13329  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
13330  //
13331  //  0: <<cos n(psi)>>
13332  //  1: <<w2 cos n(psi1+phi2)>>
13333  //  2: <<w2 w3 cos n(psi1+phi2-phi3)>>
13334  //  3: <<w2 w3 cos n(psi1-phi2-phi3)>>
13335  //  4:
13336  //  5:
13337  //  6:
13338  
13339  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13340  Double_t dReQ1n1k = (*fReQ)(0,1);
13341  Double_t dReQ2n2k = (*fReQ)(1,2);
13342  //Double_t dReQ1n3k = (*fReQ)(0,3);
13343  //Double_t dReQ4n4k = (*fReQ)(3,4);
13344  Double_t dImQ1n1k = (*fImQ)(0,1);
13345  Double_t dImQ2n2k = (*fImQ)(1,2);
13346  //Double_t dImQ1n3k = (*fImQ)(0,3);
13347  //Double_t dImQ4n4k = (*fImQ)(3,4);
13348  
13349  // S^M_{p,k} (see .h file for the definition of fSpk):
13350  Double_t dSM1p1k = (*fSpk)(0,1);
13351  Double_t dSM1p2k = (*fSpk)(0,2);
13352  Double_t dSM2p1k = (*fSpk)(1,1);
13353
13354  Int_t t = 0; // type flag 
13355  Int_t pe = 0; // ptEta flag
13356  
13357  if(type == "RP")
13358  {
13359   t = 0;
13360  } else if(type == "POI")
13361    {
13362     t = 1;
13363    }
13364
13365  if(ptOrEta == "Pt")
13366  {
13367   pe = 0;
13368  } else if(ptOrEta == "Eta")
13369    {
13370     pe = 1;
13371    }
13372     
13373  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
13374  Double_t minPtEta[2] = {fPtMin,fEtaMin};
13375  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
13376  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
13377  
13378  // looping over all bins and calculating correction terms: 
13379  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13380  {
13381   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
13382   Double_t p1n0kRe = 0.;
13383   Double_t p1n0kIm = 0.;
13384
13385   // number of POIs in particular pt or eta bin:
13386   Double_t mp = 0.;
13387
13388   // 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):
13389   Double_t q1n2kRe = 0.;
13390   Double_t q1n2kIm = 0.;
13391   Double_t q2n1kRe = 0.;
13392   Double_t q2n1kIm = 0.;
13393     
13394   // s_{1,1}, s_{1,2} // to be improved (add explanation)  
13395   Double_t s1p1k = 0.; 
13396   Double_t s1p2k = 0.; 
13397   
13398   // number of particles which are both RPs and POIs in particular pt or eta bin:
13399   Double_t mq = 0.;
13400   
13401   // M0111 from Eq. (118) in QC2c (to be improved (notation))
13402   Double_t dM01 = 0.;
13403   Double_t dM011 = 0.;
13404   
13405   if(type == "POI")
13406   {           
13407    // q_{m*n,k}:
13408    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
13409            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
13410    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
13411            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
13412    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
13413            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
13414    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
13415            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
13416    mq = fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
13417    
13418    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
13419    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
13420   }else if(type == "RP")
13421    {
13422     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
13423     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
13424             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
13425     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
13426             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
13427     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
13428             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
13429     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
13430             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
13431     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
13432     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
13433     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
13434     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.);  
13435     
13436     mq = fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
13437   }    
13438   
13439   if(type == "POI")
13440   {
13441    // p_{m*n,k}:   
13442    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
13443            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
13444    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
13445            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
13446    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
13447    // M01 from Eq. (118) in QC2c (to be improved (notation)):
13448    dM01 = mp*dSM1p1k-s1p1k;
13449    dM011 = mp*(dSM2p1k-dSM1p2k)
13450          - 2.*(s1p1k*dSM1p1k-s1p2k);
13451        
13452    // typeFlag = RP (0) or POI (1):   
13453    t = 1; 
13454   } else if(type == "RP")
13455     {  
13456      // to be improved (cross-checked):
13457      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
13458              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
13459      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
13460              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
13461      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
13462      // M01 from Eq. (118) in QC2c (to be improved (notation)):
13463      dM01 = mp*dSM1p1k-s1p1k;
13464      dM011 = mp*(dSM2p1k-dSM1p2k)
13465            - 2.*(s1p1k*dSM1p1k-s1p2k); 
13466      // typeFlag = RP (0) or POI (1): 
13467      t = 0;
13468     }
13469   
13470   // <<cos n(psi1)>>:
13471   Double_t cosP1nPsi = 0.;
13472   if(mp)
13473   {
13474    cosP1nPsi = p1n0kRe/mp;
13475    
13476    // fill profile for <<cos n(psi1)>>:
13477    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
13478    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
13479    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
13480   } // end of if(mp)   
13481   
13482   // <<w2 cos n(psi1+phi2)>>:
13483   Double_t cosP1nPsiP1nPhiW2 = 0.;
13484   if(dM01)
13485   {
13486    cosP1nPsiP1nPhiW2 = (p1n0kRe*dReQ1n1k-p1n0kIm*dImQ1n1k-q2n1kRe)/(dM01);
13487    // fill profile for <<w2 cos n(psi1+phi2)>>:
13488    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhiW2,dM01);
13489    // histogram to store <w2 cos n(psi1+phi2)> e-b-e (needed in some other methods):
13490    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhiW2);
13491   } // end of if(dM01)   
13492   
13493   // <<w2 w3 cos n(psi1+phi2-phi3)>>:
13494   Double_t cosP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
13495   if(dM011)
13496   {
13497    cosP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
13498                               - p1n0kRe*dSM1p2k
13499                               - q2n1kRe*dReQ1n1k-q2n1kIm*dImQ1n1k
13500                               - s1p1k*dReQ1n1k
13501                               + 2.*q1n2kRe)
13502                               / dM011;  
13503    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
13504    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3W2W3,dM011);
13505    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
13506    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3W2W3);
13507   } // end of if(dM011)   
13508   
13509   // <<w2 w3 cos n(psi1-phi2-phi3)>>:
13510   Double_t cosP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
13511   if(dM011)
13512   {
13513    cosP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))+2.*p1n0kIm*dReQ1n1k*dImQ1n1k
13514                               - 1.*(p1n0kRe*dReQ2n2k+p1n0kIm*dImQ2n2k)  
13515                               - 2.*s1p1k*dReQ1n1k
13516                               + 2.*q1n2kRe)
13517                               / dM011;
13518    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
13519    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3W2W3,dM011);
13520    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
13521    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3W2W3);
13522   } // end of if(dM011)   
13523  
13524  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13525    
13526 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
13527
13528
13529 //================================================================================================================================
13530
13531
13532 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
13533 {
13534  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
13535   
13536  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
13537  //  0: <<sin n(psi1)>>
13538  //  1: <<w2 sin n(psi1+phi2)>>
13539  //  2: <<w2 w3 sin n(psi1+phi2-phi3)>>
13540  //  3: <<w2 w3 sin n(psi1-phi2-phi3)>>:
13541  //  4:
13542  //  5:
13543  //  6:
13544  
13545  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13546  Double_t dReQ1n1k = (*fReQ)(0,1);
13547  Double_t dReQ2n2k = (*fReQ)(1,2);
13548  //Double_t dReQ1n3k = (*fReQ)(0,3);
13549  //Double_t dReQ4n4k = (*fReQ)(3,4);
13550  Double_t dImQ1n1k = (*fImQ)(0,1);
13551  Double_t dImQ2n2k = (*fImQ)(1,2);
13552  //Double_t dImQ1n3k = (*fImQ)(0,3);
13553  //Double_t dImQ4n4k = (*fImQ)(3,4);
13554  
13555  // S^M_{p,k} (see .h file for the definition of fSpk):
13556  Double_t dSM1p1k = (*fSpk)(0,1);
13557  Double_t dSM1p2k = (*fSpk)(0,2);
13558  Double_t dSM2p1k = (*fSpk)(1,1);
13559
13560  Int_t t = 0; // type flag 
13561  Int_t pe = 0; // ptEta flag
13562  
13563  if(type == "RP")
13564  {
13565   t = 0;
13566  } else if(type == "POI")
13567    {
13568     t = 1;
13569    }
13570
13571  if(ptOrEta == "Pt")
13572  {
13573   pe = 0;
13574  } else if(ptOrEta == "Eta")
13575    {
13576     pe = 1;
13577    }
13578     
13579  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
13580  Double_t minPtEta[2] = {fPtMin,fEtaMin};
13581  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
13582  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
13583
13584  // looping over all bins and calculating correction terms: 
13585  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13586  {
13587   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
13588   Double_t p1n0kRe = 0.;
13589   Double_t p1n0kIm = 0.;
13590
13591   // number of POIs in particular pt or eta bin:
13592   Double_t mp = 0.;
13593
13594   // 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):
13595   Double_t q1n2kRe = 0.;
13596   Double_t q1n2kIm = 0.;
13597   Double_t q2n1kRe = 0.;
13598   Double_t q2n1kIm = 0.;
13599     
13600   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
13601   Double_t s1p1k = 0.; 
13602   Double_t s1p2k = 0.; 
13603   
13604   // number of particles which are both RPs and POIs in particular pt or eta bin:
13605   Double_t mq = 0.;
13606   
13607   // M0111 from Eq. (118) in QC2c (to be improved (notation))
13608   Double_t dM01 = 0.;
13609   Double_t dM011 = 0.;
13610
13611   if(type == "POI")
13612   {    
13613    // q_{m*n,k}:
13614    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
13615            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
13616    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
13617            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
13618    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
13619            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
13620    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
13621            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
13622    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
13623    
13624    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
13625    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
13626   }else if(type == "RP")
13627    {
13628     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
13629     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
13630             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
13631     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
13632             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
13633     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
13634             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
13635     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
13636             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
13637     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
13638     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
13639     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
13640     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
13641   }    
13642   
13643   if(type == "POI")
13644   {
13645    // p_{m*n,k}:   
13646    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
13647            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
13648    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
13649            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
13650    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
13651    // M01 from Eq. (118) in QC2c (to be improved (notation)):
13652    dM01 = mp*dSM1p1k-s1p1k;
13653    dM011 = mp*(dSM2p1k-dSM1p2k)
13654          - 2.*(s1p1k*dSM1p1k-s1p2k);  
13655    // typeFlag = RP (0) or POI (1):   
13656    t = 1;           
13657   } else if(type == "RP")
13658     { 
13659      // to be improved (cross-checked):
13660      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
13661              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
13662      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
13663              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
13664      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)    
13665      // M01 from Eq. (118) in QC2c (to be improved (notation)):
13666      dM01 = mp*dSM1p1k-s1p1k;
13667      dM011 = mp*(dSM2p1k-dSM1p2k)
13668            - 2.*(s1p1k*dSM1p1k-s1p2k); 
13669      // typeFlag = RP (0) or POI (1): 
13670      t = 0;
13671     }
13672   
13673   // <<sin n(psi1)>>:
13674   Double_t sinP1nPsi = 0.;
13675   if(mp)
13676   {
13677    sinP1nPsi = p1n0kIm/mp;
13678    
13679    // fill profile for <<sin n(psi1)>>:
13680    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
13681    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
13682    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
13683   } // end of if(mp)   
13684   
13685   // <<w2 sin n(psi1+phi2)>>:
13686   Double_t sinP1nPsiP1nPhiW2 = 0.;
13687   if(dM01)
13688   {
13689    sinP1nPsiP1nPhiW2 = (p1n0kRe*dImQ1n1k+p1n0kIm*dReQ1n1k-q2n1kIm)/(dM01);
13690    // fill profile for <<w2 sin n(psi1+phi2)>>:
13691    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhiW2,dM01);
13692    // histogram to store <w2 sin n(psi1+phi2)> e-b-e (needed in some other methods):
13693    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhiW2);
13694   } // end of if(mp*dMult-mq)   
13695   
13696   // <<w2 w3 sin n(psi1+phi2-phi3)>>:
13697   Double_t sinP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
13698   if(dM011)
13699   {
13700    sinP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
13701                               - p1n0kIm*dSM1p2k
13702                               + q2n1kRe*dImQ1n1k-q2n1kIm*dReQ1n1k
13703                               - s1p1k*dImQ1n1k
13704                               + 2.*q1n2kIm)
13705                               / dM011;  
13706    // fill profile for <<w2 w3 sin n(psi1+phi2-phi3)>>:
13707    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3W2W3,dM011);
13708    // histogram to store <w2 w3 sin n(psi1+phi2-phi3)> e-b-e (needed in some other methods):
13709    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3W2W3);
13710   } // end of if(dM011)   
13711   
13712   // <<w2 w3 sin n(psi1-phi2-phi3)>>:
13713   Double_t sinP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
13714   if(dM011)
13715   {
13716    sinP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))-2.*p1n0kRe*dReQ1n1k*dImQ1n1k
13717                               + 1.*(p1n0kRe*dImQ2n2k-p1n0kIm*dReQ2n2k)  
13718                               + 2.*s1p1k*dImQ1n1k
13719                               - 2.*q1n2kIm)
13720                               / dM011;
13721    // fill profile for <<w2 w3 sin n(psi1-phi2-phi3)>>:
13722    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3W2W3,dM011);
13723    // histogram to store <w2 w3 sin n(psi1-phi2-phi3)> e-b-e (needed in some other methods):
13724    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3W2W3);
13725   } // end of if(dM011)   
13726   
13727  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13728
13729 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
13730
13731 //================================================================================================================================
13732    
13733 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
13734 {
13735  // Evaluate with nested loops correction terms for non-uniform acceptance 
13736  // with using particle weights (both sin and cos terms) relevant for differential flow.
13737  
13738  // Remark 1: "w1" in expressions bellow is a particle weight used only for particles which were 
13739  //           flagged both as POI and RP.
13740  // Remark 2: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
13741  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
13742  // Remark 3: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
13743  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
13744  //  cti: 
13745  //    0: <<sc n(psi1)>>
13746  //    1: <<w2 sc n(psi1+phi2)>> 
13747  //    2: <<w2 w3 sc n(psi1+phi2-phi3)>>
13748  //    3: <<w2 w3 sc n(psi1-phi2-phi3)>>
13749  //    4:
13750  //    5:
13751  //    6:
13752      
13753  Int_t typeFlag = 0;
13754  Int_t ptEtaFlag = 0;
13755  if(type == "RP")
13756  {
13757   typeFlag = 0;
13758  } else if(type == "POI")
13759    {
13760     typeFlag = 1;
13761    }      
13762  if(ptOrEta == "Pt")
13763  {
13764   ptEtaFlag = 0;
13765  } else if(ptOrEta == "Eta")
13766    {
13767     ptEtaFlag = 1;
13768    } 
13769  // shortcuts:
13770  Int_t t = typeFlag;
13771  Int_t pe = ptEtaFlag;
13772       
13773  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
13774  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
13775  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
13776  
13777  Int_t nPrim = anEvent->NumberOfTracks(); 
13778  AliFlowTrackSimple *aftsTrack = NULL;
13779  
13780  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
13781  Double_t wPhi2=1., wPhi3=1.;
13782  
13783  Int_t n = fHarmonic; 
13784  
13785  // 1'-particle correction terms:
13786  for(Int_t i1=0;i1<nPrim;i1++)
13787  {
13788   aftsTrack=anEvent->GetTrack(i1);
13789   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
13790   if(typeFlag==1) // this is diff flow of POIs 
13791   {
13792    if(ptOrEta == "Pt")
13793    { 
13794     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
13795    } else if (ptOrEta == "Eta")
13796      {
13797       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
13798      }
13799   } else // this is diff flow of RPs 
13800     {
13801      if(ptOrEta == "Pt")
13802      { 
13803       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
13804      } else if (ptOrEta == "Eta")
13805        {
13806         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
13807        }
13808     }
13809   psi1=aftsTrack->Phi(); 
13810   // sin terms: 
13811   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
13812   // cos terms: 
13813   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
13814  }//end of for(Int_t i1=0;i1<nPrim;i1++)
13815    
13816  // 2'-particle correction terms:
13817  for(Int_t i1=0;i1<nPrim;i1++)
13818  {
13819   aftsTrack=anEvent->GetTrack(i1);
13820   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
13821   if(typeFlag==1) // this is diff flow of POIs 
13822   {
13823    if(ptOrEta == "Pt")
13824    { 
13825     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
13826    } else if (ptOrEta == "Eta")
13827      {
13828       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
13829      }
13830   } else // this is diff flow of RPs 
13831     {
13832      if(ptOrEta == "Pt")
13833      { 
13834       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
13835      } else if (ptOrEta == "Eta")
13836        {
13837         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
13838        }
13839     }
13840   psi1=aftsTrack->Phi(); 
13841   for(Int_t i2=0;i2<nPrim;i2++)
13842   {
13843    if(i2==i1) continue;
13844    aftsTrack=anEvent->GetTrack(i2);
13845    // RP condition (!(first) particle in the correlator must be RP):
13846    if(!(aftsTrack->InRPSelection())) continue;
13847    phi2=aftsTrack->Phi();
13848    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
13849    // sin terms: 
13850    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),wPhi2); // <<w2 sin(n*(psi1+phi2))>>  
13851    // cos terms: 
13852    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),wPhi2); // <<w2 cos(n*(psi1+phi2))>>  
13853   }//end of for(Int_t i2=0;i2<nPrim;i2++)
13854  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
13855  
13856  // 3'-particle correction terms:
13857  for(Int_t i1=0;i1<nPrim;i1++)
13858  {
13859   aftsTrack=anEvent->GetTrack(i1);
13860   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
13861   if(typeFlag==1) // this is diff flow of POIs 
13862   {
13863    if(ptOrEta == "Pt")
13864    { 
13865     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
13866    } else if (ptOrEta == "Eta")
13867      {
13868       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
13869      }
13870   } else // this is diff flow of RPs 
13871     {
13872      if(ptOrEta == "Pt")
13873      { 
13874       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
13875      } else if (ptOrEta == "Eta")
13876        {
13877         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
13878        }
13879     }
13880   psi1=aftsTrack->Phi();
13881   for(Int_t i2=0;i2<nPrim;i2++)
13882   {
13883    if(i2==i1) continue;
13884    aftsTrack=anEvent->GetTrack(i2);
13885    // RP condition (!(first) particle in the correlator must be RP):
13886    if(!(aftsTrack->InRPSelection())) continue;
13887    phi2=aftsTrack->Phi();
13888    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
13889    for(Int_t i3=0;i3<nPrim;i3++)
13890    {
13891     if(i3==i1||i3==i2) continue;
13892     aftsTrack=anEvent->GetTrack(i3);
13893     // RP condition (!(first) particle in the correlator must be RP):
13894     if(!(aftsTrack->InRPSelection())) continue;
13895     phi3=aftsTrack->Phi();
13896     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));   
13897     // sin terms: 
13898     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))>>  
13899     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))>>  
13900     // cos terms: 
13901     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))>>  
13902     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))>>  
13903    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
13904   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
13905  }//end of for(Int_t i1=0;i1<nPrim;i1++)
13906                
13907 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
13908
13909 //================================================================================================================================
13910
13911 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
13912 {
13913  // Check all pointers used in method Finish().
13914  
13915  if(!fAvMultiplicity)
13916  {
13917   cout<<endl;
13918   cout<<" WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13919   cout<<endl;
13920   exit(0);
13921  }
13922  if(!fIntFlowCorrelationsPro)
13923  {
13924   cout<<endl;
13925   cout<<" WARNING (QC): fIntFlowCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13926   cout<<endl;
13927   exit(0); 
13928  }
13929  if(!fIntFlowSquaredCorrelationsPro)
13930  {
13931   cout<<endl;
13932   cout<<" WARNING (QC): fIntFlowSquaredCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13933   cout<<endl;
13934   exit(0); 
13935  } 
13936  if(!fIntFlowCorrelationsHist)
13937  {
13938   cout<<endl;
13939   cout<<" WARNING (QC): fIntFlowCorrelationsHist is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13940   cout<<endl;
13941   exit(0); 
13942  }
13943  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights) && !fIntFlowExtraCorrelationsPro) 
13944  {
13945   cout<<endl;
13946   cout<<" WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13947   cout<<endl;
13948   exit(0); 
13949  } 
13950  for(Int_t power=0;power<2;power++)
13951  { 
13952   if(!fIntFlowSumOfEventWeights[power]) 
13953   {
13954    cout<<endl;
13955    cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeights[%d] is NULL in CheckPointersUsedInFinish() !!!!",power)<<endl;
13956    cout<<endl;
13957    exit(0);
13958   }
13959  } // end of for(Int_t power=0;power<2;power++)
13960  if(!fIntFlowProductOfCorrelationsPro)
13961  {
13962   cout<<endl;
13963   cout<<" WARNING (QC): fIntFlowProductOfCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13964   cout<<endl;
13965   exit(0); 
13966  } 
13967  if(!fIntFlowSumOfProductOfEventWeights)
13968  {
13969   cout<<endl;
13970   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeights is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13971   cout<<endl;
13972   exit(0); 
13973  }
13974  if(!fIntFlowCovariances)
13975  {
13976   cout<<endl;
13977   cout<<" WARNING (QC): fIntFlowCovariances is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13978   cout<<endl;
13979   exit(0); 
13980  }  
13981  if(!fIntFlowQcumulants)
13982  {
13983   cout<<endl;
13984   cout<<" WARNING (QC): fIntFlowQcumulants is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13985   cout<<endl;
13986   exit(0); 
13987  }  
13988  if(!fIntFlow)
13989  {
13990   cout<<endl;
13991   cout<<" WARNING (QC): fIntFlow is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13992   cout<<endl;
13993   exit(0); 
13994  }
13995  if(!fCommonHists)
13996  {
13997   cout<<endl;
13998   cout<<" WARNING (QC): fCommonHists is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
13999   cout<<endl;
14000   exit(0); 
14001  }
14002  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
14003  {
14004   cout<<endl;
14005   cout<<" WARNING (QC): fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th"<<endl; 
14006   cout<<"               && fCommonHistsResults8th is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14007   cout<<endl;
14008   exit(0);
14009  } 
14010  
14011  // NUA stuff:
14012  for(Int_t sc=0;sc<2;sc++) // sin/cos
14013  { 
14014   if(!fIntFlowCorrectionTermsForNUAPro[sc]) 
14015   {
14016    cout<<endl;
14017    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
14018    cout<<endl;
14019    exit(0);
14020   }
14021   if(!fIntFlowCorrectionTermsForNUAHist[sc]) 
14022   {
14023    cout<<endl;
14024    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
14025    cout<<endl;
14026    exit(0);
14027   }
14028   for(Int_t lq=0;lq<2;lq++) // linear/quadratic
14029   {
14030    if(!fIntFlowSumOfEventWeightsNUA[sc][lq]) 
14031    {
14032     cout<<endl;
14033     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsNUA[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",sc,lq)<<endl;
14034     cout<<endl;
14035     exit(0);
14036    }
14037   } // end of for(Int_t lq=0;lq<2;lq++) // linear/quadratic
14038  } // end of for(Int_t power=0;power<2;power++) 
14039  if(!fIntFlowProductOfCorrectionTermsForNUAPro)
14040  {
14041   cout<<endl;
14042   cout<<" WARNING (QC): fIntFlowProductOfCorrectionTermsForNUAPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14043   cout<<endl;
14044   exit(0); 
14045  } 
14046  if(!fIntFlowSumOfProductOfEventWeightsNUA)
14047  {
14048   cout<<endl;
14049   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeightsNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14050   cout<<endl;
14051   exit(0); 
14052  } 
14053  if(!fIntFlowCovariancesNUA)
14054  {
14055   cout<<endl;
14056   cout<<" WARNING (QC): fIntFlowCovariancesNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14057   cout<<endl;
14058   exit(0); 
14059  } 
14060  if(!fIntFlowQcumulantsErrorSquaredRatio)
14061  {
14062   cout<<endl;
14063   cout<<" WARNING (QC): fIntFlowQcumulantsErrorSquaredRatio is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14064   cout<<endl;
14065   exit(0); 
14066  } 
14067  if(!fIntFlowDetectorBias)
14068  {
14069   cout<<endl;
14070   cout<<" WARNING (QC): fIntFlowDetectorBias is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14071   cout<<endl;
14072   exit(0); 
14073  }
14074  
14075  // Versus multiplicity:
14076  if(!fCalculateCumulantsVsM){return;}
14077  for(Int_t co=0;co<=3;co++) // cumulant order
14078  {
14079   if(!fIntFlowQcumulantsVsM[co])
14080   {
14081    cout<<endl;
14082    cout<<Form(" WARNING (QC): fIntFlowQcumulantsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
14083    cout<<endl;
14084    exit(0); 
14085   }
14086   if(!fIntFlowVsM[co])
14087   {
14088    cout<<endl;
14089    cout<<Form(" WARNING (QC): fIntFlowVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
14090    cout<<endl;
14091    exit(0); 
14092   }
14093   if(!fIntFlowDetectorBiasVsM[co])
14094   {
14095    cout<<endl;
14096    cout<<Form(" WARNING (QC): fIntFlowDetectorBiasVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
14097    cout<<endl;
14098    exit(0); 
14099   }
14100  } // end of for(Int_t c0=0;c0<=3;c0++) // cumulant order
14101  for(Int_t ci=0;ci<=3;ci++) // correlation index
14102  {
14103   if(!fIntFlowCorrelationsVsMPro[ci])
14104   {
14105    cout<<endl;
14106    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
14107    cout<<endl;
14108    exit(0); 
14109   }
14110   if(!fIntFlowSquaredCorrelationsVsMPro[ci])
14111   {
14112    cout<<endl;
14113    cout<<Form(" WARNING (QC): fIntFlowSquaredCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
14114    cout<<endl;
14115    exit(0); 
14116   }  
14117   if(!fIntFlowCorrelationsVsMHist[ci])
14118   {
14119    cout<<endl;
14120    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
14121    cout<<endl;
14122    exit(0); 
14123   }
14124   for(Int_t power=0;power<2;power++) 
14125   {
14126    if(!fIntFlowSumOfEventWeightsVsM[ci][power])
14127    {
14128     cout<<endl;
14129     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsVsM[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",ci,power)<<endl;
14130     cout<<endl;
14131     exit(0);   
14132    }
14133   } // end of for(Int_t power=0;power<2;power++) 
14134  } // end of for(Int_t ci=0;ci<=3;ci++) // correlation index
14135  for(Int_t i=0;i<6;i++)
14136  {
14137   if(!fIntFlowProductOfCorrelationsVsMPro[i])
14138   {
14139    cout<<endl;
14140    cout<<Form(" WARNING (QC): fIntFlowProductOfCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
14141    cout<<endl;
14142    exit(0); 
14143   }
14144   if(!fIntFlowSumOfProductOfEventWeightsVsM[i])
14145   {
14146    cout<<endl;
14147    cout<<Form(" WARNING (QC): fIntFlowSumOfProductOfEventWeightsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
14148    cout<<endl;
14149    exit(0); 
14150   }
14151   if(!fIntFlowCovariancesVsM[i])
14152   {
14153    cout<<endl;
14154    cout<<Form(" WARNING (QC): fIntFlowCovariancesVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
14155    cout<<endl;
14156    exit(0); 
14157   }
14158  } // end of for(Int_t i=0;i<6;i++) 
14159  if(!fIntFlowRebinnedInM)
14160  {
14161   cout<<endl;
14162   cout<<" WARNING (QC): fIntFlowRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14163   cout<<endl;
14164   exit(0); 
14165  }
14166  if(!fIntFlowQcumulantsRebinnedInM)
14167  {
14168   cout<<endl;
14169   cout<<" WARNING (QC): fIntFlowQcumulantsRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14170   cout<<endl;
14171   exit(0); 
14172  }  
14173  
14174 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
14175
14176 //================================================================================================================================
14177
14178 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
14179 {
14180  // Check all pointers used in method Make(). // to be improved - check other pointers as well
14181  
14182  if(!fAvMultiplicity)
14183  {
14184   printf("\n WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInMake() !!!!\n\n");
14185   exit(0);
14186  }
14187  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights) && !fIntFlowExtraCorrelationsPro) 
14188  {
14189   printf("\n WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInMake() !!!!\n\n");
14190   exit(0); 
14191  } 
14192  // 2D:
14193  if(fCalculate2DDiffFlow)
14194  {
14195   for(Int_t t=0;t<2;t++) // type = RP or POI
14196   { 
14197    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
14198    {
14199     if(!f2DDiffFlowCorrelationsPro[t][rci])
14200     {
14201      printf("\n WARNING (QC): f2DDiffFlowCorrelationsPro[%i][%i] is NULL in CheckPointersUsedInMake() !!!!\n\n",t,rci);
14202      exit(0);     
14203     } // end of if(!f2DDiffFlowCorrelationsPro[t][rci])  
14204    } // end of for(Int_t rci=0;rci<4;rci++) // reduced correlation index
14205   } // end of for(Int_t t=0;t<2;t++)
14206  } // end of if(fCalculate2DDiffFlow)  
14207
14208 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
14209  
14210