]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/FLOW/Base/AliFlowAnalysisWithQCumulants.cxx
5031b73c91f8db10afb972757208903d65e81a0c
[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(kTRUE),
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  // |Q_{3n}|^2 |Q_{n}|^2
2870  Double_t dQ3nQ1nQ3nstarQ1nstar = (pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
2871  // Re[Q_{2n}Q_{n}Q_{n}^*Q_{n}^*Q_{n}^*]
2872  Double_t reQ2nQ1nQ1nstarQ1nstarQ1nstar = (dReQ2n*dReQ1n-dImQ2n*dImQ1n)*(pow(dReQ1n,3)-3.*dReQ1n*pow(dImQ1n,2))
2873                                         + (dReQ2n*dImQ1n+dReQ1n*dImQ2n)*(3.*dImQ1n*pow(dReQ1n,2)-pow(dImQ1n,3)); 
2874  // Re[Q_{2n}Q_{2n}Q_{2n}^*Q_{n}^*Q_{n}^*]
2875  Double_t reQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2876                                         * (dReQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) + 2.*dImQ2n*dReQ1n*dImQ1n);
2877  // Re[Q_{4n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2878  Double_t reQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dReQ4n-6.*pow(dReQ1n,2.)*dReQ4n*pow(dImQ1n,2.)
2879                                             + pow(dImQ1n,4.)*dReQ4n+4.*pow(dReQ1n,3.)*dImQ1n*dImQ4n
2880                                             - 4.*pow(dImQ1n,3.)*dReQ1n*dImQ4n;
2881  // Re[Q_{3n}Q_{n}Q_{2n}^*Q_{n}^*Q_{n}^*]
2882  Double_t reQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2883                                         * (dReQ1n*dReQ2n*dReQ3n-dReQ3n*dImQ1n*dImQ2n
2884                                         + dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n);
2885  // Re[Q_{6n}Q_{n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2886  Double_t reQ6nQ3nstarQ2nstarQ1nstar = dReQ1n*dReQ2n*dReQ3n*dReQ6n-dReQ3n*dReQ6n*dImQ1n*dImQ2n
2887                                      - dReQ2n*dReQ6n*dImQ1n*dImQ3n-dReQ1n*dReQ6n*dImQ2n*dImQ3n
2888                                      + dReQ2n*dReQ3n*dImQ1n*dImQ6n+dReQ1n*dReQ3n*dImQ2n*dImQ6n 
2889                                      + dReQ1n*dReQ2n*dImQ3n*dImQ6n-dImQ1n*dImQ2n*dImQ3n*dImQ6n;
2890  // Re[Q_{3n}Q_{3n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2891  Double_t reQ3nQ3nQ3nstarQ2nstarQ1nstar = (pow(dImQ3n,2.)+pow(dReQ3n,2.))
2892                                         * (dImQ2n*dImQ3n*dReQ1n+dImQ1n*dImQ3n*dReQ2n
2893                                         - dImQ1n*dImQ2n*dReQ3n+dReQ1n*dReQ2n*dReQ3n);   
2894  // Re[Q_{3n}Q_{3n}Q_{2n}^*Q_{2n}^*Q_{2n}^*]
2895  Double_t reQ3nQ3nQ2nstarQ2nstarQ2nstar = pow(dReQ2n,3.)*pow(dReQ3n,2.) 
2896                                         - 3.*dReQ2n*pow(dReQ3n,2.)*pow(dImQ2n,2.)
2897                                         + 6.*pow(dReQ2n,2.)*dReQ3n*dImQ2n*dImQ3n 
2898                                         - 2.*dReQ3n*pow(dImQ2n,3.)*dImQ3n-pow(dReQ2n,3.)*pow(dImQ3n,2.) 
2899                                         + 3.*dReQ2n*pow(dImQ2n,2.)*pow(dImQ3n,2.);
2900  // Re[Q_{4n}Q_{2n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2901  Double_t reQ4nQ2nQ3nstarQ2nstarQ1nstar = (pow(dImQ2n,2.)+pow(dReQ2n,2.))
2902                                         * (dImQ3n*dImQ4n*dReQ1n+dImQ1n*dImQ4n*dReQ3n 
2903                                         - dImQ1n*dImQ3n*dReQ4n+dReQ1n*dReQ3n*dReQ4n);
2904  // Re[Q_{3n}Q_{2n}Q_{3n}^*Q_{n}^*Q_{n}^*]
2905  Double_t reQ3nQ2nQ3nstarQ1nstarQ1nstar = -(pow(dImQ3n,2.)+pow(dReQ3n,2.))
2906                                         * (-2.*dImQ1n*dImQ2n*dReQ1n+pow(dImQ1n,2.)*dReQ2n-pow(dReQ1n,2.)*dReQ2n);                              
2907  // Re[Q_{3n}Q_{2n}Q_{2n}^*Q_{2n}^*Q_{n}^*]
2908  Double_t reQ3nQ2nQ2nstarQ2nstarQ1nstar = (pow(dImQ2n,2.)+pow(dReQ2n,2.))
2909                                         * (dImQ2n*dImQ3n*dReQ1n+dImQ1n*dImQ3n*dReQ2n 
2910                                         - dImQ1n*dImQ2n*dReQ3n+dReQ1n*dReQ2n*dReQ3n);
2911  // Re[Q_{5n}Q_{n}Q_{3n}^*Q_{2n}^*Q_{n}^*]
2912  Double_t reQ5nQ1nQ3nstarQ2nstarQ1nstar = (pow(dImQ1n,2.)+pow(dReQ1n,2.))
2913                                         * (dImQ3n*dImQ5n*dReQ2n+dImQ2n*dImQ5n*dReQ3n 
2914                                         - dImQ2n*dImQ3n*dReQ5n+dReQ2n*dReQ3n*dReQ5n);   
2915  // Re[Q_{2n}Q_{2n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2916  Double_t reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = (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                                                * (pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2919                                                - dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n+pow(dImQ1n,2.)*dImQ2n); 
2920  // Re[Q_{3n}Q_{n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2921  Double_t reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2922                                                * (pow(dReQ1n,3.)*dReQ3n-3.*dReQ1n*dReQ3n*pow(dImQ1n,2.)
2923                                                + 3.*pow(dReQ1n,2.)*dImQ1n*dImQ3n-pow(dImQ1n,3.)*dImQ3n);
2924  // |Q_{2n}|^2 |Q_{n}|^4
2925  Double_t dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.); 
2926  // |Q_{3n}|^2 |Q_{2n}|^2 |Q_{n}|^2
2927  Double_t dQ3nQ2nQ1nQ3nstarQ2nstarQ1nstar = (pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2928                                           * (pow(dReQ1n,2.)+pow(dImQ1n,2.));
2929  // Re[Q_{2n}Q_{n}Q_{n}Q_{n}^*Q_{n}^*Q_{n}^*Q_{n}^*]
2930  Double_t reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2931                                                   * (pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2932                                                   + 2.*dReQ1n*dImQ1n*dImQ2n);                                                  
2933  // Re[Q_{6n}Q_{2n}^*Q_{2n}^*Q_{n}^*Q_{n}^*]
2934  Double_t reQ6nQ2nstarQ2nstarQ1nstarQ1nstar = pow(dReQ1n*dReQ2n,2.)*dReQ6n-pow(dReQ2n*dImQ1n,2.)*dReQ6n
2935                                             - 4.*dReQ1n*dReQ2n*dReQ6n*dImQ1n*dImQ2n 
2936                                             - pow(dReQ1n*dImQ2n,2.)*dReQ6n+pow(dImQ1n*dImQ2n,2.)*dReQ6n
2937                                             + 2.*dReQ1n*pow(dReQ2n,2.)*dImQ1n*dImQ6n
2938                                             + 2.*pow(dReQ1n,2.)*dReQ2n*dImQ2n*dImQ6n 
2939                                             - 2.*dReQ2n*pow(dImQ1n,2.)*dImQ2n*dImQ6n 
2940                                             - 2.*dReQ1n*dImQ1n*pow(dImQ2n,2.)*dImQ6n;       
2941  // Re[Q_{4n}Q_{1n}Q_{1n}Q_{3n}^*Q_{3n}^*]
2942  Double_t reQ4nQ1nQ1nQ3nstarQ3nstar = pow(dReQ1n*dReQ3n,2.)*dReQ4n-pow(dReQ3n*dImQ1n,2.)*dReQ4n  
2943                                     + 4.*dReQ1n*dReQ3n*dReQ4n*dImQ1n*dImQ3n 
2944                                     - pow(dReQ1n*dImQ3n,2.)*dReQ4n+pow(dImQ1n*dImQ3n,2.)*dReQ4n  
2945                                     - 2.*dReQ1n*pow(dReQ3n,2.)*dImQ1n*dImQ4n 
2946                                     + 2.*pow(dReQ1n,2.)*dReQ3n*dImQ3n*dImQ4n 
2947                                     - 2.*dReQ3n*pow(dImQ1n,2.)*dImQ3n*dImQ4n 
2948                                     + 2.*dReQ1n*dImQ1n*pow(dImQ3n,2.)*dImQ4n;
2949  // Re[Q_{3n}Q_{3n}Q_{2n}^*Q_{2n}^*Q_{1n}^*Q_{1n}^*]
2950  Double_t reQ3nQ3nQ2nstarQ2nstarQ1nstarQ1nstar = (dReQ1n*dReQ2n*dReQ3n-dReQ2n*dReQ3n*dImQ1n-dReQ1n*dReQ3n*dImQ2n 
2951                                                - dReQ3n*dImQ1n*dImQ2n+dReQ1n*dReQ2n*dImQ3n+dReQ2n*dImQ1n*dImQ3n 
2952                                                + dReQ1n*dImQ2n*dImQ3n-dImQ1n*dImQ2n*dImQ3n)*(dReQ1n*dReQ2n*dReQ3n 
2953                                                + dReQ2n*dReQ3n*dImQ1n+dReQ1n*dReQ3n*dImQ2n-dReQ3n*dImQ1n*dImQ2n 
2954                                                - dReQ1n*dReQ2n*dImQ3n+dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n 
2955                                                + dImQ1n*dImQ2n*dImQ3n);
2956     
2957  // Results for multiparticle azimuthal correlations:
2958  // 2-particle:
2959  Double_t two1n1n = 0.; // <cos(n(phi1-phi2))>
2960  Double_t two2n2n = 0.; // <cos(2n(phi1-phi2))>
2961  Double_t two3n3n = 0.; // <cos(3n(phi1-phi2))>
2962  Double_t two4n4n = 0.; // <cos(4n(phi1-phi2))>
2963  if(dMult>1)
2964  {
2965   two1n1n = (pow(dReQ1n,2.)+pow(dImQ1n,2.)-dMult)/(dMult*(dMult-1.)); 
2966   two2n2n = (pow(dReQ2n,2.)+pow(dImQ2n,2.)-dMult)/(dMult*(dMult-1.)); 
2967   two3n3n = (pow(dReQ3n,2.)+pow(dImQ3n,2.)-dMult)/(dMult*(dMult-1.)); 
2968   two4n4n = (pow(dReQ4n,2.)+pow(dImQ4n,2.)-dMult)/(dMult*(dMult-1.)); 
2969   // Average 2-particle correlations for single event: 
2970   fIntFlowCorrelationsAllEBE->SetBinContent(1,two1n1n);
2971   fIntFlowCorrelationsAllEBE->SetBinContent(2,two2n2n);
2972   fIntFlowCorrelationsAllEBE->SetBinContent(3,two3n3n);
2973   fIntFlowCorrelationsAllEBE->SetBinContent(4,two4n4n);         
2974   // Average 2-particle correlations for all events:      
2975   fIntFlowCorrelationsAllPro->Fill(0.5,two1n1n,dMult*(dMult-1.));
2976   fIntFlowCorrelationsAllPro->Fill(1.5,two2n2n,dMult*(dMult-1.)); 
2977   fIntFlowCorrelationsAllPro->Fill(2.5,two3n3n,dMult*(dMult-1.)); 
2978   fIntFlowCorrelationsAllPro->Fill(3.5,two4n4n,dMult*(dMult-1.)); 
2979   // Store separetately <2>:
2980   fIntFlowCorrelationsEBE->SetBinContent(1,two1n1n); // <2>  
2981   // Testing other multiplicity weights:
2982   Double_t mWeight2p = 0.;
2983   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2984   {
2985    mWeight2p = dMult*(dMult-1.);
2986   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2987     {
2988      mWeight2p = 1.;    
2989     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2990       {
2991        mWeight2p = dMult;           
2992       }          
2993   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,mWeight2p); // eW_<2>
2994   fIntFlowCorrelationsPro->Fill(0.5,two1n1n,mWeight2p);
2995   fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1n*two1n1n,mWeight2p);
2996   if(fCalculateCumulantsVsM)
2997   {
2998    fIntFlowCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n,mWeight2p);
2999    fIntFlowSquaredCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n*two1n1n,mWeight2p);
3000   } 
3001   if(fCalculateAllCorrelationsVsM)
3002   {
3003    fIntFlowCorrelationsAllVsMPro[0]->Fill(dMult+0.5,two1n1n,mWeight2p);
3004    fIntFlowCorrelationsAllVsMPro[1]->Fill(dMult+0.5,two2n2n,mWeight2p);
3005    fIntFlowCorrelationsAllVsMPro[2]->Fill(dMult+0.5,two3n3n,mWeight2p);
3006    fIntFlowCorrelationsAllVsMPro[3]->Fill(dMult+0.5,two4n4n,mWeight2p);
3007   }  
3008  } // end of if(dMult>1)
3009  
3010  // 3-particle:
3011  Double_t three2n1n1n = 0.; // <cos(n(2*phi1-phi2-phi3))>
3012  Double_t three3n2n1n = 0.; // <cos(n(3*phi1-2*phi2-phi3))>
3013  Double_t three4n2n2n = 0.; // <cos(n(4*phi1-2*phi2-2*phi3))>
3014  Double_t three4n3n1n = 0.; // <cos(n(4*phi1-3*phi2-phi3))> 
3015  if(dMult>2)
3016  {
3017   three2n1n1n = (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3018               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
3019               / (dMult*(dMult-1.)*(dMult-2.));                     
3020   three3n2n1n = (reQ3nQ2nstarQ1nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3021               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))
3022               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3023               / (dMult*(dMult-1.)*(dMult-2.));
3024   three4n2n2n = (reQ4nQ2nstarQ2nstar-2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3025               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*dMult)
3026               / (dMult*(dMult-1.)*(dMult-2.)); 
3027   three4n3n1n = (reQ4nQ3nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3028               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
3029               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3030               / (dMult*(dMult-1.)*(dMult-2.));              
3031   // Average 3-particle correlations for single event: 
3032   fIntFlowCorrelationsAllEBE->SetBinContent(6,three2n1n1n);
3033   fIntFlowCorrelationsAllEBE->SetBinContent(7,three3n2n1n);
3034   fIntFlowCorrelationsAllEBE->SetBinContent(8,three4n2n2n);
3035   fIntFlowCorrelationsAllEBE->SetBinContent(9,three4n3n1n);
3036   // Average 3-particle correlations for all events:                
3037   fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.)); 
3038   fIntFlowCorrelationsAllPro->Fill(6.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
3039   fIntFlowCorrelationsAllPro->Fill(7.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.)); 
3040   fIntFlowCorrelationsAllPro->Fill(8.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));  
3041   // Average 3-particle correlations vs M for all events:                
3042   if(fCalculateAllCorrelationsVsM)
3043   {
3044    fIntFlowCorrelationsAllVsMPro[5]->Fill(dMult+0.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.));
3045    fIntFlowCorrelationsAllVsMPro[6]->Fill(dMult+0.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
3046    fIntFlowCorrelationsAllVsMPro[7]->Fill(dMult+0.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.));
3047    fIntFlowCorrelationsAllVsMPro[8]->Fill(dMult+0.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));
3048   }    
3049  } // end of if(dMult>2)
3050  
3051  // 4-particle:
3052  Double_t four1n1n1n1n = 0.; // <cos(n(phi1+phi2-phi3-phi4))>
3053  Double_t four2n2n2n2n = 0.; // <cos(2n(phi1+phi2-phi3-phi4))>
3054  Double_t four2n1n2n1n = 0.; // <cos(n(2*phi1+phi2-2*phi3-phi4))> 
3055  Double_t four3n1n1n1n = 0.; // <cos(n(3*phi1-phi2-phi3-phi4))> 
3056  Double_t four4n2n1n1n = 0.; // <cos(n(4*phi1-2*phi2-phi3-phi4))> 
3057  Double_t four3n1n2n2n = 0.; // <cos(n(3*phi1+phi2-2*phi3-2*phi4))> 
3058  Double_t four3n1n3n1n = 0.; // <cos(n(3*phi1+phi2-3*phi3-phi4))>    
3059  if(dMult>3)
3060  {
3061   four1n1n1n1n = (2.*dMult*(dMult-3.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ1n,2.)
3062                + pow(dImQ1n,2.))-2.*reQ2nQ1nstarQ1nstar+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
3063                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));     
3064   four2n2n2n2n = (2.*dMult*(dMult-3.)+pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ2n,2.)
3065                + pow(dImQ2n,2.))-2.*reQ4nQ2nstarQ2nstar+(pow(dReQ4n,2.)+pow(dImQ4n,2.)))
3066                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));
3067   four2n1n2n1n = (dQ2nQ1nQ2nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar-2.*reQ2nQ1nstarQ1nstar)
3068                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3069                - ((dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3070                + (dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
3071                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3072                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
3073   four3n1n1n1n = (reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar-3.*reQ2nQ1nstarQ1nstar
3074                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3075                + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3076                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3077   four4n2n1n1n = (reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar)
3078                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3079                - (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3080                - 3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
3081                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3082                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
3083   four3n1n2n2n = (reQ3nQ1nQ2nstarQ2nstar-reQ4nQ2nstarQ2nstar-reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar)
3084                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3085                - (2.*reQ2nQ1nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3086                - 4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
3087                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3088                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.)); 
3089   four3n1n3n1n = ((pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3090                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar
3091                + pow(dReQ4n,2.)+pow(dImQ4n,2.)-(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3092                + pow(dReQ2n,2.)+pow(dImQ2n,2.)-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3093                + dMult*(dMult-6.))
3094                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));           
3095   // Average 4-particle correlations for single event: 
3096   fIntFlowCorrelationsAllEBE->SetBinContent(11,four1n1n1n1n);
3097   fIntFlowCorrelationsAllEBE->SetBinContent(12,four2n1n2n1n);
3098   fIntFlowCorrelationsAllEBE->SetBinContent(13,four2n2n2n2n);
3099   fIntFlowCorrelationsAllEBE->SetBinContent(14,four3n1n1n1n);
3100   fIntFlowCorrelationsAllEBE->SetBinContent(15,four3n1n3n1n);
3101   fIntFlowCorrelationsAllEBE->SetBinContent(16,four3n1n2n2n);
3102   fIntFlowCorrelationsAllEBE->SetBinContent(17,four4n2n1n1n);       
3103   // Average 4-particle correlations for all events:                
3104   fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3105   fIntFlowCorrelationsAllPro->Fill(11.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3106   fIntFlowCorrelationsAllPro->Fill(12.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3107   fIntFlowCorrelationsAllPro->Fill(13.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3108   fIntFlowCorrelationsAllPro->Fill(14.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3109   fIntFlowCorrelationsAllPro->Fill(15.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
3110   fIntFlowCorrelationsAllPro->Fill(16.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
3111   // Average 4-particle correlations vs M for all events:                
3112   if(fCalculateAllCorrelationsVsM)
3113   {
3114    fIntFlowCorrelationsAllVsMPro[10]->Fill(dMult+0.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3115    fIntFlowCorrelationsAllVsMPro[11]->Fill(dMult+0.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3116    fIntFlowCorrelationsAllVsMPro[12]->Fill(dMult+0.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3117    fIntFlowCorrelationsAllVsMPro[13]->Fill(dMult+0.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3118    fIntFlowCorrelationsAllVsMPro[14]->Fill(dMult+0.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3119    fIntFlowCorrelationsAllVsMPro[15]->Fill(dMult+0.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3120    fIntFlowCorrelationsAllVsMPro[16]->Fill(dMult+0.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3121   }       
3122   // Store separetately <4>:
3123   fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1n); // <4>
3124   // Testing other multiplicity weights:
3125   Double_t mWeight4p = 0.;
3126   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
3127   {
3128    mWeight4p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.);
3129   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
3130     {
3131      mWeight4p = 1.;    
3132     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
3133       {
3134        mWeight4p = dMult;           
3135       }      
3136   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,mWeight4p); // eW_<4>
3137   fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1n,mWeight4p);
3138   fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
3139   if(fCalculateCumulantsVsM)
3140   {
3141    fIntFlowCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n,mWeight4p);
3142    fIntFlowSquaredCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n*four1n1n1n1n,mWeight4p);
3143   }   
3144  } // end of if(dMult>3)
3145
3146  // 5-particle:
3147  Double_t five2n1n1n1n1n = 0.; // <cos(n(2*phi1+phi2-phi3-phi4-phi5))>
3148  Double_t five2n2n2n1n1n = 0.; // <cos(n(2*phi1+2*phi2-2*phi3-phi4-phi5))>
3149  Double_t five3n1n2n1n1n = 0.; // <cos(n(3*phi1+phi2-2*phi3-phi4-phi5))>
3150  Double_t five4n1n1n1n1n = 0.; // <cos(n(4*phi1-phi2-phi3-phi4-phi5))>
3151  if(dMult>4)
3152  {            
3153   five2n1n1n1n1n = (reQ2nQ1nQ1nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar+5.*reQ3nQ2nstarQ1nstar
3154                  - 3.*(dMult-5.)*reQ2nQ1nstarQ1nstar-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3155                  - 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))     
3156                  + 3.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3157                  - 3.*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3158                  + 6.*(2.*dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult*(dMult-4.))
3159                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3160   five2n2n2n1n1n = (reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ3nQ1nQ2nstarQ2nstar
3161                  + 3.*reQ4nQ2nstarQ2nstar+8.*reQ3nQ2nstarQ1nstar+2.*reQ4nQ3nstarQ1nstar
3162                  - 2.*(dMult-6.)*reQ2nQ1nstarQ1nstar
3163                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3164                  - pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)
3165                  + 2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3166                  - 4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3167                  + 4.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3168                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3169   five4n1n1n1n1n = (reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ4nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nstarQ1nstarQ1nstar
3170                  + 8.*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+12.*reQ3nQ2nstarQ1nstar+12.*reQ2nQ1nstarQ1nstar
3171                  - 6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-8.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3172                  - 12.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+24.*dMult)
3173                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3174   five3n1n2n1n1n = (reQ3nQ1nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar
3175                  - reQ3nQ1nQ2nstarQ2nstar+4.*reQ4nQ3nstarQ1nstar+reQ4nQ2nstarQ2nstar
3176                  - (2.*dMult-13.)*reQ3nQ2nstarQ1nstar+7.*reQ2nQ1nstarQ1nstar
3177                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3178                  + 2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3179                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3180                  + 2.*(dMult-6.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3181                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3182                  - pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3183                  + 2.*(3.*dMult-11.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3184                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));                 
3185   // Average 5-particle correlations for single event: 
3186   fIntFlowCorrelationsAllEBE->SetBinContent(19,five2n1n1n1n1n);
3187   fIntFlowCorrelationsAllEBE->SetBinContent(20,five2n2n2n1n1n);
3188   fIntFlowCorrelationsAllEBE->SetBinContent(21,five3n1n2n1n1n);
3189   fIntFlowCorrelationsAllEBE->SetBinContent(22,five4n1n1n1n1n);        
3190   // Average 5-particle correlations for all events:                         
3191   fIntFlowCorrelationsAllPro->Fill(18.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
3192   fIntFlowCorrelationsAllPro->Fill(19.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3193   fIntFlowCorrelationsAllPro->Fill(20.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3194   fIntFlowCorrelationsAllPro->Fill(21.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
3195   // Average 5-particle correlations vs M for all events:                
3196   if(fCalculateAllCorrelationsVsM)
3197   {
3198    fIntFlowCorrelationsAllVsMPro[18]->Fill(dMult+0.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3199    fIntFlowCorrelationsAllVsMPro[19]->Fill(dMult+0.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3200    fIntFlowCorrelationsAllVsMPro[20]->Fill(dMult+0.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3201    fIntFlowCorrelationsAllVsMPro[21]->Fill(dMult+0.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3202   }    
3203  } // end of if(dMult>4)
3204     
3205  // 6-particle:
3206  Double_t six1n1n1n1n1n1n = 0.; // <cos(n(phi1+phi2+phi3-phi4-phi5-phi6))>
3207  Double_t six2n2n1n1n1n1n = 0.; // <cos(n(2*phi1+2*phi2-phi3-phi4-phi5-phi6))>
3208  Double_t six3n1n1n1n1n1n = 0.; // <cos(n(3*phi1+phi2-phi3-phi4-phi5-phi6))>
3209  Double_t six2n1n1n2n1n1n = 0.; // <cos(n(2*phi1+phi2+phi3-2*phi4-phi5-phi6))>
3210  if(dMult>5)
3211  {
3212   six1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)-6.*reQ2nQ1nQ1nstarQ1nstarQ1nstar
3213                   + 4.*reQ3nQ1nstarQ1nstarQ1nstar-12.*reQ3nQ2nstarQ1nstar+18.*(dMult-4.)*reQ2nQ1nstarQ1nstar
3214                   + 9.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3215                   + 4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))-9.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3216                   - 9.*(dMult-4.)*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.) 
3217                   + 18.*(dMult*dMult-7.*dMult+10.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3218                   - 6.*dMult*(dMult*dMult-9.*dMult+20.))
3219                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3220   six2n1n1n2n1n1n = (dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nQ2nstarQ1nstarQ1nstar
3221                   - 4.*reQ2nQ1nQ1nstarQ1nstarQ1nstar-2.*reQ2nQ2nQ2nstarQ1nstarQ1nstar
3222                   + 4.*reQ4nQ2nstarQ1nstarQ1nstar+4.*reQ3nQ1nQ2nstarQ2nstar+4.*reQ3nQ1nstarQ1nstarQ1nstar
3223                   - 8.*reQ4nQ3nstarQ1nstar-4.*reQ4nQ2nstarQ2nstar+4.*(2.*dMult-13.)*reQ3nQ2nstarQ1nstar
3224                   + 2.*(7.*dMult-34.)*reQ2nQ1nstarQ1nstar+4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3225                   - 4.*(dMult-7.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3226                   + 4.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-4.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3227                   + pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)+(2.*dMult*dMult-27.*dMult+76.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3228                   - (dMult-12.)*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3229                   + 4.*(dMult*dMult-15.*dMult+34.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3230                   - 2.*dMult*(dMult*dMult-17.*dMult+60.))
3231                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3232   six2n2n1n1n1n1n = (reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ1nstarQ1nstarQ1nstarQ1nstar
3233                   - 8.*reQ2nQ1nQ1nstarQ1nstarQ1nstar+8.*reQ3nQ1nstarQ1nstarQ1nstar+6.*reQ4nQ2nstarQ1nstarQ1nstar
3234                   + 8.*reQ3nQ1nQ2nstarQ2nstar-40.*reQ3nQ2nstarQ1nstar-8.*reQ4nQ3nstarQ1nstar-9.*reQ4nQ2nstarQ2nstar
3235                   + 24.*(dMult-4.)*reQ2nQ1nstarQ1nstar+24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3236                   + 6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+16.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3237                   + 3.*pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-12.*(2.*dMult-7.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3238                   + 12.*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-48.*(dMult-3.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3239                   + 24.*dMult*(dMult-5.))
3240                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3241   six3n1n1n1n1n1n = (reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ3nQ1nQ2nstarQ1nstarQ1nstar+6.*reQ4nQ2nstarQ1nstarQ1nstar
3242                   - reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-4.*reQ2nQ1nQ1nstarQ1nstarQ1nstar+3.*reQ3nQ1nQ2nstarQ2nstar
3243                   - 4.*(dMult-5.)*reQ3nQ1nstarQ1nstarQ1nstar-14.*reQ4nQ3nstarQ1nstar
3244                   - 3.*reQ4nQ2nstarQ2nstar+4.*(3.*dMult-17.)*reQ3nQ2nstarQ1nstar+12.*(dMult-6.)*reQ2nQ1nstarQ1nstar
3245                   + 12.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))  
3246                   + 8.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))  
3247                   + 6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-8.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.)) 
3248                   - 12.*(dMult-5.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-48.*(dMult-3.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3249                   + 12.*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)+24.*dMult*(dMult-5.))
3250                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3251   // Average 6-particle correlations for single event: 
3252   fIntFlowCorrelationsAllEBE->SetBinContent(24,six1n1n1n1n1n1n);
3253   fIntFlowCorrelationsAllEBE->SetBinContent(25,six2n1n1n2n1n1n);
3254   fIntFlowCorrelationsAllEBE->SetBinContent(26,six2n2n1n1n1n1n);
3255   fIntFlowCorrelationsAllEBE->SetBinContent(27,six3n1n1n1n1n1n);
3256   // Average 6-particle correlations for all events:         
3257   fIntFlowCorrelationsAllPro->Fill(23.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3258   fIntFlowCorrelationsAllPro->Fill(24.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3259   fIntFlowCorrelationsAllPro->Fill(25.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3260   fIntFlowCorrelationsAllPro->Fill(26.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
3261   // Average 6-particle correlations vs M for all events:                
3262   if(fCalculateAllCorrelationsVsM)
3263   {
3264    fIntFlowCorrelationsAllVsMPro[23]->Fill(dMult+0.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3265    fIntFlowCorrelationsAllVsMPro[24]->Fill(dMult+0.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3266    fIntFlowCorrelationsAllVsMPro[25]->Fill(dMult+0.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3267    fIntFlowCorrelationsAllVsMPro[26]->Fill(dMult+0.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3268   }    
3269   // Store separetately <6>:
3270   fIntFlowCorrelationsEBE->SetBinContent(3,six1n1n1n1n1n1n); // <6>
3271   // Testing other multiplicity weights:
3272   Double_t mWeight6p = 0.;
3273   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
3274   {
3275    mWeight6p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.);
3276   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
3277     {
3278      mWeight6p = 1.;    
3279     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
3280       {
3281        mWeight6p = dMult;           
3282       }
3283   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(3,mWeight6p); // eW_<6>
3284   fIntFlowCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n,mWeight6p);
3285   fIntFlowSquaredCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
3286   if(fCalculateCumulantsVsM)
3287   {
3288    fIntFlowCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n,mWeight6p);
3289    fIntFlowSquaredCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n*six1n1n1n1n1n1n,mWeight6p);
3290   }    
3291  } // end of if(dMult>5)
3292  
3293  // 7-particle:
3294  Double_t seven2n1n1n1n1n1n1n = 0.; // <cos(n(2*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
3295  if(dMult>6)
3296  {
3297   seven2n1n1n1n1n1n1n = (reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-4.*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)
3298                       - reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-2.*reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar
3299                       + 9.*reQ2nQ2nQ2nstarQ1nstarQ1nstar+20.*reQ3nQ1nQ2nstarQ1nstarQ1nstar 
3300                       + 2.*reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-8.*(dMult-8.)*reQ2nQ1nQ1nstarQ1nstarQ1nstar
3301                       - 18.*reQ4nQ2nstarQ1nstarQ1nstar-14.*reQ3nQ1nQ2nstarQ2nstar
3302                       + 8.*(dMult-7.)*reQ3nQ1nstarQ1nstarQ1nstar+28.*reQ4nQ3nstarQ1nstar
3303                       + 12.*reQ4nQ2nstarQ2nstar-8.*(5.*dMult-31.)*reQ3nQ2nstarQ1nstar      
3304                       + 12.*(dMult*dMult-15.*dMult+46.)*reQ2nQ1nstarQ1nstar
3305                       - 16.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3306                       - 6.*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3307                       - 3.*pow(pow(dReQ2n,2.)+pow(dImQ2n,2.),2.)
3308                       + 12.*(2.*dMult-13.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3309                       - 12.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+16.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3310                       - 12.*(dMult-8.)*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3311                       + 12.*(3.*dMult-14.)*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)
3312                       - 24.*(3.*dMult-7.)*(dMult-6.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3313                       + 24.*dMult*(dMult-5.)*(dMult-6.))
3314                       / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.));   
3315   // Average 7-particle correlations for single event: 
3316   fIntFlowCorrelationsAllEBE->SetBinContent(29,seven2n1n1n1n1n1n1n);       
3317   // Average 7-particle correlations for all events:                      
3318   fIntFlowCorrelationsAllPro->Fill(28.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3319                                                                  *(dMult-4.)*(dMult-5.)*(dMult-6.));
3320   // Average 7-particle correlations vs M for all events:                
3321   if(fCalculateAllCorrelationsVsM)
3322   {
3323    fIntFlowCorrelationsAllVsMPro[28]->Fill(dMult+0.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3324                                                                               *(dMult-4.)*(dMult-5.)*(dMult-6.));
3325   }    
3326  } // end of if(dMult>6)
3327  
3328  // 8-particle:
3329  Double_t eight1n1n1n1n1n1n1n1n = 0.; // <cos(n(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
3330  if(dMult>7)
3331  {  
3332   eight1n1n1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),4.)-12.*reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar
3333                         + 16.*reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar+6.*reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar
3334                         - 12.*reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-36.*reQ2nQ2nQ2nstarQ1nstarQ1nstar
3335                         - 96.*reQ3nQ1nQ2nstarQ1nstarQ1nstar
3336                         + 72.*reQ4nQ2nstarQ1nstarQ1nstar+48.*reQ3nQ1nQ2nstarQ2nstar
3337                         - 64.*(dMult-6.)*reQ3nQ1nstarQ1nstarQ1nstar
3338                         + 96.*(dMult-6.)*reQ2nQ1nQ1nstarQ1nstarQ1nstar
3339                         - 96.*reQ4nQ3nstarQ1nstar-36.*reQ4nQ2nstarQ2nstar
3340                         + 192.*(dMult-6.)*reQ3nQ2nstarQ1nstar
3341                         - 144.*(dMult-7.)*(dMult-4.)*reQ2nQ1nstarQ1nstar
3342                         + 64.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3343                         - 144.*(dMult-6.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3344                         + 72.*(dMult-7.)*(dMult-4.)*(pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)+pow(dReQ2n,2.)+pow(dImQ2n,2.))
3345                         - 96.*(dMult-7.)*(dMult-6.)*(dMult-2.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3346                         + 36.*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3347                         + 9.*pow(pow(dReQ2n,2.)+pow(dImQ2n,2.),2.)
3348                         - 64.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3349                         + 36.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3350                         - 16.*(dMult-6.)*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)
3351                         + 24.*dMult*(dMult-7.)*(dMult-6.)*(dMult-5.))
3352                         / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));   
3353   // Average 8-particle correlations for single event: 
3354   fIntFlowCorrelationsAllEBE->SetBinContent(31,eight1n1n1n1n1n1n1n1n);      
3355   // Average 8-particle correlations for all events:                       
3356   fIntFlowCorrelationsAllPro->Fill(30.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3357                                                                    *(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
3358   // Average 8-particle correlations vs M for all events:                
3359   if(fCalculateAllCorrelationsVsM)
3360   {
3361    fIntFlowCorrelationsAllVsMPro[30]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
3362                                                                                 *(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
3363   }     
3364   // Store separetately <8>:
3365   fIntFlowCorrelationsEBE->SetBinContent(4,eight1n1n1n1n1n1n1n1n); // <8>
3366   // Testing other multiplicity weights:
3367   Double_t mWeight8p = 0.;
3368   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
3369   {
3370    mWeight8p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.);
3371   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
3372     {
3373      mWeight8p = 1.;    
3374     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
3375       {
3376        mWeight8p = dMult;           
3377       }        
3378   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(4,mWeight8p); // eW_<8>
3379   fIntFlowCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
3380   fIntFlowSquaredCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);  
3381   if(fCalculateCumulantsVsM)
3382   {
3383    fIntFlowCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n,mWeight8p);
3384    fIntFlowSquaredCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n*eight1n1n1n1n1n1n1n1n,mWeight8p);
3385   }    
3386  } // end of if(dMult>7) 
3387  
3388  // EXTRA correlations for v3{5} study:
3389  // 4-particle:
3390  Double_t four4n2n3n3n = 0.; // <cos(n(4*phi1+2*phi2-3*phi3-3*phi4))>
3391  if(dMult>3.)
3392  {
3393   four4n2n3n3n = (reQ4nQ2nQ3nstarQ3nstar-reQ6nQ4nstarQ2nstar-reQ6nQ3nstarQ3nstar
3394                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar
3395                + (pow(dReQ6n,2.)+pow(dImQ6n,2.))+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3396                + 2.*(2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3397                + (pow(dReQ1n,2.)+pow(dImQ1n,2.))-3.*dMult))
3398                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));               
3399   fIntFlowCorrelationsAllPro->Fill(32.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3400   // Average 4-particle correlations vs M for all events:                
3401   if(fCalculateAllCorrelationsVsM)
3402   {
3403    fIntFlowCorrelationsAllVsMPro[32]->Fill(dMult+0.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3404   }    
3405  } // end of if(dMult>3.)
3406  
3407  // 5-particle:
3408  Double_t five3n3n2n2n2n = 0.; // <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-2*phi5))>                                    
3409  if(dMult>4.)
3410  {
3411   five3n3n2n2n2n = (reQ3nQ3nQ2nstarQ2nstarQ2nstar-reQ6nQ2nstarQ2nstarQ2nstar-3.*reQ4nQ2nQ3nstarQ3nstar 
3412                  - 6.*reQ3nQ1nQ2nstarQ2nstar+2.*reQ6nQ3nstarQ3nstar+3.*reQ6nQ4nstarQ2nstar
3413                  + 6.*reQ4nQ3nstarQ1nstar+6.*reQ4nQ2nstarQ2nstar
3414                  + 12.*reQ3nQ2nstarQ1nstar+6.*reQ2nQ1nstarQ1nstar
3415                  - 2.*((pow(dReQ6n,2.)+pow(dImQ6n,2.)) 
3416                  + 3.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3417                  + 6.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)) 
3418                  + 9.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3419                  + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-12.*dMult))
3420                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3421   fIntFlowCorrelationsAllPro->Fill(33.5,five3n3n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3422   if(fCalculateAllCorrelationsVsM)
3423   {
3424    fIntFlowCorrelationsAllVsMPro[33]->Fill(dMult+0.5,five3n3n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3425   }     
3426  } // end of if(dMult>4.)
3427  
3428  // EXTRA correlations for Teaney-Yan study: 
3429  // 2-particle:
3430  Double_t two5n5n = 0.; // <cos(5n(phi1-phi2))>
3431  Double_t two6n6n = 0.; // <cos(6n(phi1-phi2))> 
3432  if(dMult>1)
3433  {
3434   two5n5n = (pow(dReQ5n,2.)+pow(dImQ5n,2.)-dMult)/(dMult*(dMult-1.)); 
3435   two6n6n = (pow(dReQ6n,2.)+pow(dImQ6n,2.)-dMult)/(dMult*(dMult-1.));        
3436   // Average 2-particle correlations for all events:      
3437   fIntFlowCorrelationsAllPro->Fill(34.5,two5n5n,dMult*(dMult-1.));
3438   fIntFlowCorrelationsAllPro->Fill(35.5,two6n6n,dMult*(dMult-1.)); 
3439   if(fCalculateAllCorrelationsVsM)
3440   {
3441    fIntFlowCorrelationsAllVsMPro[34]->Fill(dMult+0.5,two5n5n,dMult*(dMult-1.));
3442    fIntFlowCorrelationsAllVsMPro[35]->Fill(dMult+0.5,two6n6n,dMult*(dMult-1.));
3443   }       
3444  } // end of if(dMult>1)
3445  
3446  // 3-particle:
3447  Double_t three5n3n2n = 0.; // <cos(n(5*phi1-3*phi2-2*phi3)> 
3448  Double_t three5n4n1n = 0.; // <cos(n(5*phi1-4*phi2-1*phi3)> 
3449  Double_t three6n3n3n = 0.; // <cos(n(6*phi1-3*phi2-3*phi3)> 
3450  Double_t three6n4n2n = 0.; // <cos(n(6*phi1-4*phi2-2*phi3)> 
3451  Double_t three6n5n1n = 0.; // <cos(n(6*phi1-5*phi2-1*phi3)> 
3452  if(dMult>2)
3453  {
3454   three5n3n2n = (reQ5nQ3nstarQ2nstar-(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3455               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
3456               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
3457               / (dMult*(dMult-1.)*(dMult-2.));           
3458   three5n4n1n = (reQ5nQ4nstarQ1nstar-(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3459               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))
3460               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3461               / (dMult*(dMult-1.)*(dMult-2.));                          
3462   three6n3n3n = (reQ6nQ3nstarQ3nstar-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3463               - (pow(dReQ6n,2.)+pow(dImQ6n,2.))+2.*dMult)
3464               / (dMult*(dMult-1.)*(dMult-2.)); 
3465   three6n4n2n = (reQ6nQ4nstarQ2nstar-(pow(dReQ6n,2.)+pow(dImQ6n,2.))
3466               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))
3467               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
3468               / (dMult*(dMult-1.)*(dMult-2.));
3469   three6n5n1n = (reQ6nQ5nstarQ1nstar-(pow(dReQ6n,2.)+pow(dImQ6n,2.))
3470               - (pow(dReQ5n,2.)+pow(dImQ5n,2.))
3471               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3472               / (dMult*(dMult-1.)*(dMult-2.));            
3473   // Average 3-particle correlations for all events:      
3474   fIntFlowCorrelationsAllPro->Fill(36.5,three5n3n2n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(5*phi1-3*phi2-2*phi3)>> 
3475   fIntFlowCorrelationsAllPro->Fill(37.5,three5n4n1n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(5*phi1-4*phi2-1*phi3)>> 
3476   fIntFlowCorrelationsAllPro->Fill(38.5,three6n3n3n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(6*phi1-3*phi2-3*phi3)>> 
3477   fIntFlowCorrelationsAllPro->Fill(39.5,three6n4n2n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(6*phi1-4*phi2-2*phi3)>>
3478   fIntFlowCorrelationsAllPro->Fill(40.5,three6n5n1n,dMult*(dMult-1.)*(dMult-2.)); // <<cos(n(6*phi1-5*phi2-1*phi3)>>
3479   if(fCalculateAllCorrelationsVsM)
3480   {
3481    fIntFlowCorrelationsAllVsMPro[36]->Fill(dMult+0.5,three5n3n2n,dMult*(dMult-1.)*(dMult-2.));
3482    fIntFlowCorrelationsAllVsMPro[37]->Fill(dMult+0.5,three5n4n1n,dMult*(dMult-1.)*(dMult-2.));
3483    fIntFlowCorrelationsAllVsMPro[38]->Fill(dMult+0.5,three6n3n3n,dMult*(dMult-1.)*(dMult-2.));
3484    fIntFlowCorrelationsAllVsMPro[39]->Fill(dMult+0.5,three6n4n2n,dMult*(dMult-1.)*(dMult-2.));
3485    fIntFlowCorrelationsAllVsMPro[40]->Fill(dMult+0.5,three6n5n1n,dMult*(dMult-1.)*(dMult-2.));
3486   }       
3487  } // end of if(dMult>2)
3488  
3489  // 4-particle:
3490  Double_t four6n3n2n1n = 0.; // <cos(n(6*phi1-3*phi2-2*phi3-1*phi4)>
3491  Double_t four3n2n3n2n = 0.; // <cos(n(3*phi1+2*phi2-3*phi3-2*phi4)>
3492  Double_t four4n1n3n2n = 0.; // <cos(n(4*phi1+1*phi2-3*phi3-2*phi4)> 
3493  Double_t four3n3n3n3n = 0.; // <cos(3n(phi1+phi2-phi3-phi4))> 
3494  //Double_t four4n2n3n3n = 0.; // <cos(n(4*phi1+2*phi2-3*phi3-3*phi4)> // I already have this one above
3495  Double_t four5n1n3n3n = 0.; // <cos(n(5*phi1+1*phi2-3*phi3-3*phi4)>
3496  Double_t four4n2n4n2n = 0.; // <cos(n(4*phi1+2*phi2-4*phi3-2*phi4)> 
3497  Double_t four5n1n4n2n = 0.; // <cos(n(5*phi1+1*phi2-4*phi3-2*phi4)> 
3498  Double_t four5n3n1n1n = 0.; // <cos(n(5*phi1-3*phi2-1*phi3-1*phi4)> 
3499  Double_t four5n2n2n1n = 0.; // <cos(n(5*phi1-2*phi2-2*phi3-1*phi4)>
3500  Double_t four5n1n5n1n = 0.; // <cos(n(5*phi1+1*phi2-5*phi3-1*phi4)>
3501  Double_t four6n4n1n1n = 0.; // <cos(n(6*phi1-4*phi2-1*phi3-1*phi4)>
3502  Double_t four6n2n2n2n = 0.; // <cos(n(6*phi1-2*phi2-2*phi3-2*phi4)>
3503  if(dMult>3)
3504  {
3505   four6n3n2n1n = (reQ6nQ3nstarQ2nstarQ1nstar-reQ6nQ4nstarQ2nstar-reQ6nQ3nstarQ3nstar-reQ6nQ5nstarQ1nstar
3506                - reQ5nQ3nstarQ2nstar-reQ4nQ3nstarQ1nstar-reQ3nQ2nstarQ1nstar
3507                + 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))+pow(dReQ5n,2.)+pow(dImQ5n,2.)
3508                + pow(dReQ4n,2.)+pow(dImQ4n,2.)+3.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3509                + 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3510                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3511   four3n2n3n2n = (dQ3nQ2nQ3nstarQ2nstar-2.*reQ5nQ3nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar
3512                + pow(dReQ5n,2.)+pow(dImQ5n,2.)+pow(dReQ1n,2.)+pow(dImQ1n,2.)               
3513                -(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.)+pow(dReQ2n,2.)+pow(dImQ2n,2.))
3514                + dMult*(dMult-6.))
3515                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));     
3516   four4n1n3n2n = (reQ4nQ1nQ3nstarQ2nstar-reQ5nQ3nstarQ2nstar-reQ5nQ4nstarQ1nstar-reQ4nQ3nstarQ1nstar
3517                - reQ4nQ2nstarQ2nstar-reQ3nQ2nstarQ1nstar-reQ2nQ1nstarQ1nstar
3518                + pow(dReQ5n,2.)+pow(dImQ5n,2.)+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3519                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3520                + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult) 
3521                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));                             
3522   four3n3n3n3n = (2.*dMult*(dMult-3.)+pow((pow(dReQ3n,2.)+pow(dImQ3n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ3n,2.)
3523                + pow(dImQ3n,2.))-2.*reQ6nQ3nstarQ3nstar+(pow(dReQ6n,2.)+pow(dImQ6n,2.)))
3524                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));   
3525   //four4n2n3n3n = ; // I already have this one above
3526   four5n1n3n3n = (reQ5nQ1nQ3nstarQ3nstar-reQ6nQ5nstarQ1nstar-reQ6nQ3nstarQ3nstar-2.*reQ5nQ3nstarQ2nstar
3527                - 2.*reQ3nQ2nstarQ1nstar+pow(dReQ6n,2.)+pow(dImQ6n,2.)+2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3528                + 4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3529                + 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)                                  
3530                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));   
3531   four4n2n4n2n = (dQ4nQ2nQ4nstarQ2nstar-2.*reQ6nQ4nstarQ2nstar-2.*reQ4nQ2nstarQ2nstar)
3532                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3533                - ((dMult-5.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3534                + (dMult-4.)*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-(pow(dReQ6n,2.)+pow(dImQ6n,2.)))
3535                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3536                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.)); 
3537   four5n1n4n2n = (reQ5nQ1nQ4nstarQ2nstar-reQ6nQ5nstarQ1nstar-reQ6nQ4nstarQ2nstar-reQ5nQ4nstarQ1nstar
3538                - reQ5nQ3nstarQ2nstar-reQ4nQ3nstarQ1nstar-reQ2nQ1nstarQ1nstar+pow(dReQ6n,2.)+pow(dImQ6n,2.)
3539                + 2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3540                + pow(dReQ3n,2.)+pow(dImQ3n,2.)+2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3541                + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3542                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));     
3543   four5n3n1n1n = (reQ5nQ3nstarQ1nstarQ1nstar-2.*reQ5nQ4nstarQ1nstar-reQ5nQ3nstarQ2nstar-2.*reQ4nQ3nstarQ1nstar
3544                - reQ2nQ1nstarQ1nstar+2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3545                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+pow(dReQ2n,2.)+pow(dImQ2n,2.)
3546                + 4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult) 
3547                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));                    
3548   four5n2n2n1n = (reQ5nQ2nstarQ2nstarQ1nstar-reQ5nQ4nstarQ1nstar-2.*reQ5nQ3nstarQ2nstar-reQ4nQ2nstarQ2nstar
3549                - 2.*reQ3nQ2nstarQ1nstar+2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))+pow(dReQ4n,2.)+pow(dImQ4n,2.)
3550                + 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3551                + 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3552                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));   
3553   four5n1n5n1n = (dQ5nQ1nQ5nstarQ1nstar-2.*reQ6nQ5nstarQ1nstar-2.*reQ5nQ4nstarQ1nstar
3554                + pow(dReQ6n,2.)+pow(dImQ6n,2.)-(dMult-4.)*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3555                + pow(dReQ4n,2.)+pow(dImQ4n,2.)-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+dMult*(dMult-6.))  
3556                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));    
3557                               
3558   // TBI: Recursive formula needed:
3559   four6n4n1n1n = (reQ6nQ4nstarQ1nstarQ1nstar
3560                - dMult*(dMult-1.)*(dMult-2.)*(three2n1n1n+2.*three5n4n1n+2.*three6n5n1n+three6n4n2n)
3561                - dMult*(dMult-1.)*(2.*two1n1n+1.*two4n4n+1.*two6n6n+1.*two2n2n+2.*two5n5n)
3562                - 1.*dMult)
3563                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3564   
3565   four6n2n2n2n = (reQ6nQ2nstarQ2nstarQ2nstar-3.*reQ6nQ4nstarQ2nstar-3.*reQ4nQ2nstarQ2nstar
3566                + 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))+3.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3567                + 6.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-6.*dMult)
3568                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3569   // Average 4-particle correlations for all events:      
3570   fIntFlowCorrelationsAllPro->Fill(41.5,four6n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3571   fIntFlowCorrelationsAllPro->Fill(42.5,four3n2n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3572   fIntFlowCorrelationsAllPro->Fill(43.5,four4n1n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3573   fIntFlowCorrelationsAllPro->Fill(44.5,four3n3n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3574   //fIntFlowCorrelationsAllPro->Fill(45.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); // I already have this one above
3575   fIntFlowCorrelationsAllPro->Fill(46.5,four5n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3576   fIntFlowCorrelationsAllPro->Fill(47.5,four4n2n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3577   fIntFlowCorrelationsAllPro->Fill(48.5,four5n1n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3578   fIntFlowCorrelationsAllPro->Fill(49.5,four5n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3579   fIntFlowCorrelationsAllPro->Fill(50.5,four5n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3580   fIntFlowCorrelationsAllPro->Fill(51.5,four5n1n5n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3581   fIntFlowCorrelationsAllPro->Fill(58.5,four6n4n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3582   fIntFlowCorrelationsAllPro->Fill(59.5,four6n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3583   if(fCalculateAllCorrelationsVsM)
3584   {
3585    fIntFlowCorrelationsAllVsMPro[41]->Fill(dMult+0.5,four6n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3586    fIntFlowCorrelationsAllVsMPro[42]->Fill(dMult+0.5,four3n2n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3587    fIntFlowCorrelationsAllVsMPro[43]->Fill(dMult+0.5,four4n1n3n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3588    fIntFlowCorrelationsAllVsMPro[44]->Fill(dMult+0.5,four3n3n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3589    //fIntFlowCorrelationsAllVsMPro[45]->Fill(dMult+0.5,four4n2n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3590    fIntFlowCorrelationsAllVsMPro[46]->Fill(dMult+0.5,four5n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3591    fIntFlowCorrelationsAllVsMPro[47]->Fill(dMult+0.5,four4n2n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3592    fIntFlowCorrelationsAllVsMPro[48]->Fill(dMult+0.5,four5n1n4n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3593    fIntFlowCorrelationsAllVsMPro[49]->Fill(dMult+0.5,four5n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3594    fIntFlowCorrelationsAllVsMPro[50]->Fill(dMult+0.5,four5n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3595    fIntFlowCorrelationsAllVsMPro[51]->Fill(dMult+0.5,four5n1n5n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3596    fIntFlowCorrelationsAllVsMPro[58]->Fill(dMult+0.5,four6n4n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3597    fIntFlowCorrelationsAllVsMPro[59]->Fill(dMult+0.5,four6n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3598   }       
3599  } // end of if(dMult>3)
3600
3601  // 5-particle:
3602  Double_t five3n3n3n2n1n = 0.; // <cos(n(3*phi1+3*phi2-3*phi3-2*phi4-1*phi5)>
3603  Double_t five4n2n3n2n1n = 0.; // <cos(n(4*phi1+2*phi2-3*phi3-2*phi4-1*phi5)>
3604  Double_t five3n2n3n1n1n = 0.; // <cos(n(3*phi1+2*phi2-3*phi3-1*phi4-1*phi5)>
3605  Double_t five3n2n2n2n1n = 0.; // <cos(n(3*phi1+2*phi2-2*phi3-2*phi4-1*phi5)>
3606  Double_t five5n1n3n2n1n = 0.; // <cos(n(5*phi1+1*phi2-3*phi3-2*phi4-1*phi5)>
3607  Double_t five6n2n2n1n1n = 0.; // <cos(n(6*phi1-2*phi2-2*phi3-1*phi4-1*phi5)>
3608  Double_t five4n1n1n3n3n = 0.; // <cos(n(4*phi1+1*phi2+1*phi3-3*phi4-3*phi5)>
3609  if(dMult>4)
3610  { 
3611   five3n3n3n2n1n = (reQ3nQ3nQ3nstarQ2nstarQ1nstar-reQ6nQ3nstarQ2nstarQ1nstar-reQ5nQ1nQ3nstarQ3nstar-reQ4nQ2nQ3nstarQ3nstar
3612                  + reQ6nQ5nstarQ1nstar+reQ6nQ4nstarQ2nstar+3.*reQ6nQ3nstarQ3nstar+4.*reQ5nQ3nstarQ2nstar+4.*reQ4nQ3nstarQ1nstar
3613                  - 2.*(dMult-6.)*reQ3nQ2nstarQ1nstar-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.)) 
3614                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3615                  - 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))-2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3616                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*(3.*dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3617                  - pow((pow(dReQ3n,2.)+pow(dImQ3n,2.)),2.)+2.*(dMult-5.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3618                  + 2.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3619                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));                                  
3620   five4n2n3n2n1n = (reQ4nQ2nQ3nstarQ2nstarQ1nstar-reQ6nQ3nstarQ2nstarQ1nstar-reQ5nQ1nQ4nstarQ2nstar
3621                  - reQ4nQ2nQ3nstarQ3nstar-reQ4nQ1nQ3nstarQ2nstar-reQ4nQ2nstarQ1nstarQ1nstar
3622                  - reQ3nQ1nQ2nstarQ2nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3623                  + 3.*reQ6nQ4nstarQ2nstar+reQ6nQ5nstarQ1nstar+reQ6nQ3nstarQ3nstar+reQ5nQ4nstarQ1nstar
3624                  + 3.*reQ5nQ3nstarQ2nstar-(dMult-7.)*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+7.*reQ3nQ2nstarQ1nstar
3625                  + 4.*reQ2nQ1nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3626                  - (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3627                  - 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))-2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3628                  + (dMult-8.)*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+(dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3629                  + 2.*(dMult-7.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+(dMult-12.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3630                  - 2.*dMult*(dMult-12.))
3631                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));   
3632   five3n2n3n1n1n = (reQ3nQ2nQ3nstarQ1nstarQ1nstar-reQ5nQ3nstarQ1nstarQ1nstar-2.*reQ4nQ1nQ3nstarQ2nstar-reQ3nQ1nstarQ1nstarQ1nstar
3633                  - 2.*reQ3nQ1nQ2nstarQ2nstar+2.*reQ5nQ4nstarQ1nstar+3.*reQ5nQ3nstarQ2nstar+6.*reQ4nQ3nstarQ1nstar
3634                  + 2.*reQ4nQ2nstarQ2nstar+9.*reQ3nQ2nstarQ1nstar-(dMult-8.)*reQ2nQ1nstarQ1nstar
3635                  - (pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.)) 
3636                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.)) 
3637                  - 2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))-4.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3638                  + 2.*(dMult-6.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+(dMult-12.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3639                  + 2.*(dMult-9.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-2.*dMult*(dMult-12.))
3640                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3641   five3n2n2n2n1n = (reQ3nQ2nQ2nstarQ2nstarQ1nstar-reQ5nQ2nstarQ2nstarQ1nstar-reQ4nQ1nQ3nstarQ2nstar-reQ3nQ1nQ2nstarQ2nstar
3642                  - 2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+reQ5nQ4nstarQ1nstar
3643                  + 4.*reQ5nQ3nstarQ2nstar+reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar-2.*(dMult-6.)*reQ3nQ2nstarQ1nstar
3644                  + 4.*reQ2nQ1nstarQ1nstar-2.*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3645                  - 2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3646                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3647                  - pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)+2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3648                  + 2.*(dMult-6.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-4.*dMult*(dMult-6.))
3649                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
3650   five5n1n3n2n1n = (reQ5nQ1nQ3nstarQ2nstarQ1nstar-reQ6nQ3nstarQ2nstarQ1nstar-reQ5nQ1nQ4nstarQ2nstar-reQ5nQ1nQ3nstarQ3nstar
3651                  - reQ4nQ1nQ3nstarQ2nstar-reQ5nQ3nstarQ1nstarQ1nstar-reQ5nQ2nstarQ2nstarQ1nstar 
3652                  + 3.*reQ6nQ5nstarQ1nstar+reQ6nQ4nstarQ2nstar+reQ6nQ3nstarQ3nstar+4.*reQ5nQ4nstarQ1nstar
3653                  - (dMult-7.)*reQ5nQ3nstarQ2nstar+4.*reQ4nQ3nstarQ1nstar+reQ4nQ2nstarQ2nstar+6.*reQ3nQ2nstarQ1nstar
3654                  + 3.*reQ2nQ1nstarQ1nstar-(pow(dReQ5n,2.)+pow(dImQ5n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3655                  - (pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3656                  - (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3657                  - 2.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))+(dMult-8.)*(pow(dReQ5n,2.)+pow(dImQ5n,2.))  
3658                  - 4.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+(dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3659                  + (dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*(dMult-7.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3660                  - 2.*dMult*(dMult-12.))
3661                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));      
3662  
3663   // Peter Jochumzsen:
3664   five6n2n2n1n1n = (reQ6nQ2nstarQ2nstarQ1nstarQ1nstar
3665                  - 12.*pow(dReQ1n,2.)-12.*pow(dImQ1n,2.)
3666                  - 14.*pow(dReQ2n,2.)-14.*pow(dImQ2n,2.)
3667                  - 8.*pow(dReQ3n,2.)-8.*pow(dImQ3n,2.)
3668                  - 6.*pow(dReQ4n,2.)-6.*pow(dImQ4n,2.)
3669                  - 4.*pow(dReQ5n,2.)-4.*pow(dImQ5n,2.)
3670                  - 6.*pow(dReQ6n,2.)-6.*pow(dImQ6n,2.)
3671                  + 2.*reQ2nQ1nstarQ1nstar + 8.*reQ3nQ2nstarQ1nstar
3672                  + 5.*reQ6nQ4nstarQ2nstar - reQ6nQ4nstarQ1nstarQ1nstar
3673                  + 2.*reQ6nQ3nstarQ3nstar - reQ6nQ2nstarQ2nstarQ2nstar 
3674                  + 4.*reQ4nQ2nstarQ2nstar - 2.*reQ4nQ2nstarQ1nstarQ1nstar 
3675                  + 2.*reQ5nQ4nstarQ1nstar - 2.*reQ5nQ2nstarQ2nstarQ1nstar 
3676                  + 4.*reQ4nQ3nstarQ1nstar + 4.*reQ5nQ3nstarQ2nstar
3677                  + 4.*reQ6nQ5nstarQ1nstar - 4.*reQ6nQ3nstarQ2nstarQ1nstar + 24.*dMult)
3678                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3679   
3680   // Peter Jochumzsen:
3681   /*
3682   five4n1n1n3n3n = (reQ6nQ2nstarQ2nstarQ1nstarQ1nstar
3683                  - 12.*pow(dReQ1n,2.)-12.*pow(dImQ1n,2.)
3684                  - 14.*pow(dReQ2n,2.)-14.*pow(dImQ2n,2.)
3685                  - 8.*pow(dReQ3n,2.)-8.*pow(dImQ3n,2.)
3686                  - 6.*pow(dReQ4n,2.)-6.*pow(dImQ4n,2.)
3687                  - 4.*pow(dReQ5n,2.)-4.*pow(dImQ5n,2.)
3688                  - 6.*pow(dReQ6n,2.)-6.*pow(dImQ6n,2.)
3689                  + 2.*reQ2nQ1nstarQ1nstar + 8.*reQ3nQ2nstarQ1nstar
3690                  + 5.*reQ6nQ4nstarQ2nstar - reQ6nQ4nstarQ1nstarQ1nstar
3691                  + 2.*reQ6nQ3nstarQ3nstar - reQ6nQ2nstarQ2nstarQ2nstar
3692                  + 4.*reQ4nQ2nstarQ2nstar - 2.*reQ4nQ2nstarQ1nstarQ1nstar
3693                  + 2.*reQ5nQ4nstarQ1nstar - 2.*reQ5nQ2nstarQ2nstarQ1nstar
3694                  + 4.*reQ4nQ3nstarQ1nstar + 4.*reQ5nQ3nstarQ2nstar
3695                  + 4.*reQ6nQ5nstarQ1nstar - 4.*reQ6nQ3nstarQ2nstarQ1nstar + 24.*dMult)
3696                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3697   */
3698   
3699   // Average 5-particle correlations for all events:      
3700   fIntFlowCorrelationsAllPro->Fill(52.5,five3n3n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3701   fIntFlowCorrelationsAllPro->Fill(53.5,five4n2n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3702   fIntFlowCorrelationsAllPro->Fill(54.5,five3n2n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3703   fIntFlowCorrelationsAllPro->Fill(55.5,five3n2n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3704   fIntFlowCorrelationsAllPro->Fill(56.5,five5n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3705   fIntFlowCorrelationsAllPro->Fill(60.5,five6n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3706   fIntFlowCorrelationsAllPro->Fill(61.5,five4n1n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3707   if(fCalculateAllCorrelationsVsM)
3708   {
3709    fIntFlowCorrelationsAllVsMPro[52]->Fill(dMult+0.5,five3n3n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3710    fIntFlowCorrelationsAllVsMPro[53]->Fill(dMult+0.5,five4n2n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3711    fIntFlowCorrelationsAllVsMPro[54]->Fill(dMult+0.5,five3n2n3n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3712    fIntFlowCorrelationsAllVsMPro[55]->Fill(dMult+0.5,five3n2n2n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3713    fIntFlowCorrelationsAllVsMPro[56]->Fill(dMult+0.5,five5n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3714    fIntFlowCorrelationsAllVsMPro[60]->Fill(dMult+0.5,five6n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3715    fIntFlowCorrelationsAllVsMPro[61]->Fill(dMult+0.5,five4n1n1n3n3n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
3716   }         
3717  } // end of if(dMult>4)
3718
3719  // 6-particle:
3720  Double_t six3n2n1n3n2n1n = 0.; // <cos(n(3*phi1+2*phi2+1*phi3-3*phi4-2*phi5-1*phi6)>
3721  Double_t six3n3n2n2n1n1n = 0.; // <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-1*phi5-1*phi6)>   
3722  if(dMult>5.)
3723  { 
3724   six3n2n1n3n2n1n = (dQ3nQ2nQ1nQ3nstarQ2nstarQ1nstar-2.*reQ3nQ3nQ3nstarQ2nstarQ1nstar
3725                   - 2.*reQ3nQ2nQ2nstarQ2nstarQ1nstar-2.*reQ3nQ1nQ2nstarQ1nstarQ1nstar
3726                   - 2.*reQ3nQ2nQ3nstarQ1nstarQ1nstar-2.*reQ4nQ2nQ3nstarQ2nstarQ1nstar
3727                   - 2.*reQ5nQ1nQ3nstarQ2nstarQ1nstar+4.*reQ6nQ3nstarQ2nstarQ1nstar
3728                   + 2.*reQ5nQ1nQ4nstarQ2nstar+2.*reQ5nQ1nQ3nstarQ3nstar
3729                   + 2.*reQ4nQ2nQ3nstarQ3nstar+6.*reQ4nQ1nQ3nstarQ2nstar
3730                   + 2.*reQ5nQ3nstarQ1nstarQ1nstar+2.*reQ5nQ2nstarQ2nstarQ1nstar
3731                   + 6.*reQ3nQ1nQ2nstarQ2nstar+2.*reQ4nQ2nstarQ1nstarQ1nstar
3732                   - 4.*reQ6nQ5nstarQ1nstar-4.*reQ6nQ4nstarQ2nstar-6.*reQ5nQ4nstarQ1nstar
3733                   - 4.*reQ6nQ3nstarQ3nstar+2.*(dMult-11.)*reQ5nQ3nstarQ2nstar
3734                   + 2.*(dMult-13.)*reQ4nQ3nstarQ1nstar-8.*reQ4nQ2nstarQ2nstar
3735                   + 2.*(5.*dMult-32.)*reQ3nQ2nstarQ1nstar+2.*reQ3nQ1nstarQ1nstarQ1nstar
3736                   + 2.*(dMult-13.)*reQ2nQ1nstarQ1nstar
3737                   - (dMult-10.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3738                   + (pow(dReQ5n,2.)+pow(dImQ5n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3739                   + (pow(dReQ4n,2.)+pow(dImQ4n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3740                   - (dMult-11.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3741                   - (dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3742                   + 4.*(pow(dReQ6n,2.)+pow(dImQ6n,2.))-(dMult-12.)*(pow(dReQ5n,2.)+pow(dImQ5n,2.))
3743                   - (dMult-16.)*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+pow((pow(dReQ3n,2.)+pow(dImQ3n,2.)),2.)
3744                   + (dMult*dMult-19.*dMult+68.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3745                   + (dMult*dMult-19.*dMult+72.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3746                   + pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3747                   + (dMult*dMult-20.*dMult+80.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3748                   - dMult*(dMult-12.)*(dMult-10.))
3749                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));   
3750   
3751   // Peter Jochumzsen:
3752   six3n3n2n2n1n1n = (reQ3nQ3nQ2nstarQ2nstarQ1nstarQ1nstar
3753                   + (80.-16.*dMult)*pow(dReQ1n,2.)+(80.-16.*dMult)*pow(dImQ1n,2.)
3754                   + (78.-16.*dMult)*pow(dReQ2n,2.)+(78.-16.*dMult)*pow(dImQ2n,2.)
3755                   + (72.-16.*dMult)*pow(dReQ3n,2.)+(72.-16.*dMult)*pow(dImQ3n,2.)
3756                   + 14.*pow(dReQ4n,2.)+14.*pow(dImQ4n,2.)
3757                   + 8.*pow(dReQ5n,2.)+8.*pow(dImQ5n,2.)
3758                   + 6.*pow(dReQ6n,2.)+6.*pow(dImQ6n,2.)
3759                   + 1.*reQ6nQ2nstarQ2nstarQ2nstar - 1.*reQ6nQ2nstarQ2nstarQ1nstarQ1nstar
3760                   - 76.*reQ3nQ2nstarQ1nstar + 4.*reQ3nQ1nstarQ1nstarQ1nstar
3761                   - 8.*reQ3nQ2nstarQ1nstar + 8.*dQ2nQ1nQ2nstarQ1nstar
3762                   + 4.*reQ5nQ2nstarQ2nstarQ1nstar - 2.*reQ6nQ3nstarQ3nstar
3763                   + 4.*reQ6nQ3nstarQ2nstarQ1nstar - 4.*reQ5nQ4nstarQ1nstar
3764                   + 16.*dMult*reQ3nQ2nstarQ1nstar - 2.*reQ4nQ2nstarQ2nstar
3765                   - 4.*reQ3nQ3nQ3nstarQ2nstarQ1nstar -8.*reQ4nQ3nstarQ1nstar
3766                   - 10.*reQ4nQ2nstarQ2nstar + 4.*reQ4nQ2nstarQ1nstarQ1nstar
3767                   - 12.*reQ4nQ3nstarQ1nstar + 8.*dQ3nQ1nQ3nstarQ1nstar
3768                   + 8.*reQ3nQ1nQ2nstarQ2nstar - 4.*reQ3nQ1nQ2nstarQ1nstarQ1nstar
3769                   + 5.*reQ4nQ2nQ3nstarQ3nstar+2.*pow(pow(dReQ2n,2.)+pow(dImQ2n,2.),2.)
3770                   + 4.*reQ5nQ1nQ3nstarQ3nstar+2.*pow(pow(dReQ3n,2.)+pow(dImQ3n,2.),2.)
3771                   - 6.*reQ6nQ3nstarQ3nstar - 14.*reQ2nQ1nstarQ1nstar
3772                   - 1.*reQ3nQ3nQ2nstarQ2nstarQ2nstar-4.*reQ3nQ2nQ2nstarQ2nstarQ1nstar
3773                   - 1.*reQ4nQ1nQ1nQ3nstarQ3nstar-8.*reQ5nQ3nstarQ2nstar
3774                   + 2.*pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),2.) - 10.*reQ2nQ1nstarQ1nstar
3775                   - 4.*reQ6nQ5nstarQ1nstar-5.*reQ6nQ4nstarQ2nstar
3776                   + 1.*reQ6nQ4nstarQ1nstarQ1nstar-8.*reQ5nQ3nstarQ2nstar
3777                   + 4.*reQ4nQ1nQ3nstarQ2nstar+8.*dQ3nQ2nQ3nstarQ2nstar
3778                   - 120.*dMult + 16.*dMult*dMult)
3779                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3780
3781   // Average 6-particle correlations for all events:      
3782   fIntFlowCorrelationsAllPro->Fill(57.5,six3n2n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3783   fIntFlowCorrelationsAllPro->Fill(62.5,six3n3n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3784   if(fCalculateAllCorrelationsVsM)
3785   {
3786    fIntFlowCorrelationsAllVsMPro[57]->Fill(dMult+0.5,six3n2n1n3n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3787    fIntFlowCorrelationsAllVsMPro[62]->Fill(dMult+0.5,six3n3n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
3788   }          
3789  } // end of if(dMult>5.)
3790  
3791 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
3792
3793 //================================================================================================================================
3794
3795 void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3796 {
3797  // Store phi distribution for one event to illustrate flow.
3798  
3799  if(fPhiDistributionForOneEvent->GetEntries()>0){return;} // store only phi distribution for one event
3800  
3801  Double_t vMin = fPhiDistributionForOneEventSettings[0]; 
3802  Double_t vMax = fPhiDistributionForOneEventSettings[1]; 
3803  Double_t refMultMin = fPhiDistributionForOneEventSettings[2]; 
3804  Double_t refMultMax = fPhiDistributionForOneEventSettings[3]; 
3805  
3806  Double_t vEBE = 0.;
3807  Double_t cumulant4thEBE = fIntFlowCorrelationsEBE->GetBinContent(2)-2.*pow(fIntFlowCorrelationsEBE->GetBinContent(1),2.);
3808  if(cumulant4thEBE<0.)
3809  {
3810   vEBE = pow(-1.*cumulant4thEBE,0.25);
3811   if((vEBE>vMin && vEBE<vMax) && (fReferenceMultiplicityEBE>refMultMin && fReferenceMultiplicityEBE<refMultMax))
3812   {
3813    fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f",fHarmonic,vEBE));
3814    for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3815    {
3816     if(anEvent->GetTrack(p)->InRPSelection())
3817     {
3818      fPhiDistributionForOneEvent->Fill(anEvent->GetTrack(p)->Phi());
3819     }
3820    } // end of for(Int_t p=0;p<anEvent->NumberOfTracks();p++)
3821   } else
3822     {
3823      fPhiDistributionForOneEvent->SetTitle(Form("v_{%i} = %f, out of specified boundaries",fHarmonic,vEBE));  
3824     } 
3825    
3826  } // end of if(cumulant4thEBE<0.)
3827  
3828 } // end of void AliFlowAnalysisWithQCumulants::StorePhiDistributionForOneEvent(AliFlowEventSimple *anEvent)
3829
3830 //================================================================================================================================
3831
3832 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3833 {
3834  // Calculate averages of products of correlations for integrated flow.
3835  
3836  // multiplicity:
3837  Double_t dMult = (*fSpk)(0,0);
3838  
3839  Int_t counter = 0;
3840  
3841  for(Int_t ci1=1;ci1<4;ci1++)
3842  {
3843   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
3844   {
3845    fIntFlowProductOfCorrelationsPro->Fill(0.5+counter,
3846                                           fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3847                                           fIntFlowCorrelationsEBE->GetBinContent(ci2),
3848                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3849                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3850    // products versus multiplicity:  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]
3851    if(fCalculateCumulantsVsM)
3852    {
3853     fIntFlowProductOfCorrelationsVsMPro[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights ?
3854                                                        fIntFlowCorrelationsEBE->GetBinContent(ci1)*
3855                                                        fIntFlowCorrelationsEBE->GetBinContent(ci2),
3856                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
3857                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
3858    } // end of if(fCalculateCumulantsVsM)
3859    counter++;                                                                                                                        
3860   }
3861  }
3862  
3863 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
3864
3865
3866 //================================================================================================================================
3867
3868
3869 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3870 {
3871  // Calculate averages of products of correction terms for NUA.
3872  
3873  // a) Binning of fIntFlowProductOfCorrectionTermsForNUAPro is organized as follows:
3874  //     1st bin: <<2><cos(phi)>> 
3875  //     2nd bin: <<2><sin(phi)>>
3876  //     3rd bin: <<cos(phi)><sin(phi)>>
3877  //     4th bin: <<2><cos(phi1+phi2)>> 
3878  //     5th bin: <<2><sin(phi1+phi2)>>
3879  //     6th bin: <<2><cos(phi1-phi2-phi3)>> 
3880  //     7th bin: <<2><sin(phi1-phi2-phi3)>>
3881  //     8th bin: <<4><cos(phi1)>>
3882  //     9th bin: <<4><sin(phi1)>>
3883  //    10th bin: <<4><cos(phi1+phi2)>>
3884  //    11th bin: <<4><sin(phi1+phi2)>>
3885  //    12th bin: <<4><cos(phi1-phi2-phi3)>>
3886  //    13th bin: <<4><sin(phi1-phi2-phi3)>>
3887  //    14th bin: <<cos(phi1)><cos(phi1+phi2)>>
3888  //    15th bin: <<cos(phi1)><sin(phi1+phi2)>> 
3889  //    16th bin: <<cos(phi1)><cos(phi1-phi2-phi3)>>
3890  //    17th bin: <<cos(phi1)><sin(phi1-phi2-phi3)>> 
3891  //    18th bin: <<sin(phi1)><cos(phi1+phi2)>>
3892  //    19th bin: <<sin(phi1)><sin(phi1+phi2)>> 
3893  //    20th bin: <<sin(phi1)><cos(phi1-phi2-phi3)>>
3894  //    21st bin: <<sin(phi1)><sin(phi1-phi2-phi3)>>
3895  //    22nd bin: <<cos(phi1+phi2)><sin(phi1+phi2)>>
3896  //    23rd bin: <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>
3897  //    24th bin: <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>
3898  //    25th bin: <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>
3899  //    26th bin: <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>
3900  //    27th bin: <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>
3901  
3902  // <<2><cos(phi)>>:
3903  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(0.5,
3904                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3905                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3906                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3907  // <<2><sin(phi)>>:
3908  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(1.5,
3909                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3910                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3911                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3912  // <<cos(phi)><sin(phi)>>:
3913  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(2.5,
3914                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3915                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3916                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3917  // <<2><cos(phi1+phi2)>>:
3918  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(3.5,
3919                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3920                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3921                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3922  // <<2><sin(phi1+phi2)>>:
3923  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(4.5,
3924                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3925                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3926                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3927  // <<2><cos(phi1-phi2-phi3)>>:
3928  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(5.5,
3929                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3930                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3931                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3932  // <<2><sin(phi1-phi2-phi3)>>:
3933  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(6.5,
3934                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3935                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3936                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3937  // <<4><cos(phi1)>>:
3938  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(7.5,
3939                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3940                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3941                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3942  // <<4><sin(phi1)>>:
3943  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(8.5,
3944                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3945                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3946                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3947  // <<4><cos(phi1+phi2)>>:
3948  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(9.5,
3949                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3950                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3951                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3952  // <<4><sin(phi1+phi2)>>:
3953  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(10.5,
3954                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3955                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3956                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
3957  // <<4><cos(phi1-phi2-phi3)>>:
3958  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(11.5,
3959                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3960                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3961                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3962  // <<4><sin(phi1-phi2-phi3)>>:
3963  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(12.5,
3964                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3965                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3966                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));   
3967  // <<cos(phi1)><cos(phi1+phi2)>>:
3968  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(13.5,
3969                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3970                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3971                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3972  // <<cos(phi1)><sin(phi1+phi2)>>: 
3973  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(14.5,
3974                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3975                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3976                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3977  // <<cos(phi1)><cos(phi1-phi2-phi3)>>:
3978  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(15.5,
3979                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3980                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3981                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3982  // <<cos(phi1)><sin(phi1-phi2-phi3)>>: 
3983  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(16.5,
3984                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3985                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3986                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
3987  // <<sin(phi1)><cos(phi1+phi2)>>:
3988  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(17.5,
3989                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3990                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3991                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));  
3992  // <<sin(phi1)><sin(phi1+phi2)>>: 
3993  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(18.5,
3994                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3995                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3996                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));  
3997  // <<sin(phi1)><cos(phi1-phi2-phi3)>>:
3998  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(19.5,
3999                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
4000                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
4001                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
4002  // <<sin(phi1)><sin(phi1-phi2-phi3)>>:
4003  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(20.5,
4004                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
4005                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
4006                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
4007  // <<cos(phi1+phi2)><sin(phi1+phi2)>>:
4008  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(21.5,
4009                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
4010                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
4011                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
4012  // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>:
4013  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(22.5,
4014                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
4015                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
4016                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));   
4017  // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>:
4018  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(23.5,
4019                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
4020                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
4021                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
4022  // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>:
4023  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(24.5,
4024                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
4025                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
4026                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));    
4027  // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>:
4028  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(25.5,
4029                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
4030                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
4031                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
4032  // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>:
4033  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(26.5,
4034                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
4035                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)
4036                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
4037
4038 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
4039
4040 //================================================================================================================================
4041
4042 void AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
4043 {
4044  // a) Calculate unbiased estimators Cov(<2>,<4>), Cov(<2>,<6>), Cov(<2>,<8>), Cov(<4>,<6>), Cov(<4>,<8>) and Cov(<6>,<8>)
4045  //    for covariances V_(<2>,<4>), V_(<2>,<6>), V_(<2>,<8>), V_(<4>,<6>), V_(<4>,<8>) and V_(<6>,<8>).
4046  // b) Store in histogram fIntFlowCovariances for instance the following: 
4047  //
4048  //             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)]
4049  // 
4050  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<4>} is event weight for <4>.
4051  // c) Binning of fIntFlowCovariances is organized as follows:
4052  // 
4053  //     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)] 
4054  //     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)]
4055  //     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)]
4056  //     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)]
4057  //     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)]
4058  //     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)]
4059  //
4060     
4061  // Average 2-, 4-, 6- and 8-particle correlations for all events:
4062  Double_t correlation[4] = {0.};
4063  for(Int_t ci=0;ci<4;ci++)
4064  {
4065   correlation[ci] = fIntFlowCorrelationsPro->GetBinContent(ci+1);
4066  } 
4067  // Average products of 2-, 4-, 6- and 8-particle correlations: 
4068  Double_t productOfCorrelations[4][4] = {{0.}};
4069  Int_t productOfCorrelationsLabel = 1;
4070  // Denominators in the expressions for the unbiased estimator for covariance:
4071  Double_t denominator[4][4] = {{0.}};
4072  Int_t sumOfProductOfEventWeightsLabel1 = 1;
4073  // Weight dependent prefactor which multiply unbiased estimators for covariances:
4074  Double_t wPrefactor[4][4] = {{0.}}; 
4075  Int_t sumOfProductOfEventWeightsLabel2 = 1;
4076  for(Int_t c1=0;c1<4;c1++)
4077  {
4078   for(Int_t c2=c1+1;c2<4;c2++)
4079   {
4080    productOfCorrelations[c1][c2] = fIntFlowProductOfCorrelationsPro->GetBinContent(productOfCorrelationsLabel);
4081    if(TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1)) > 1.e-44)
4082    {
4083     denominator[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel1))
4084                         / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1) 
4085                         * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                              
4086     wPrefactor[c1][c2] = fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel2)
4087                        / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)
4088                        * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                                                       
4089    }
4090    productOfCorrelationsLabel++; // to be improved - do I need here all 3 counters?
4091    sumOfProductOfEventWeightsLabel1++;
4092    sumOfProductOfEventWeightsLabel2++;  
4093   } // end of for(Int_t c2=c1+1;c2<4;c2++)
4094  } // end of for(Int_t c1=0;c1<4;c1++)
4095  
4096  Int_t covarianceLabel = 1;
4097  for(Int_t c1=0;c1<4;c1++)
4098  {
4099   for(Int_t c2=c1+1;c2<4;c2++)
4100   {
4101    if(TMath::Abs(denominator[c1][c2]) > 1.e-44)
4102    {
4103     // Covariances:
4104     Double_t cov = (productOfCorrelations[c1][c2]-correlation[c1]*correlation[c2])/denominator[c1][c2]; 
4105     // Covariances multiplied with weight dependent prefactor:
4106     Double_t wCov = cov * wPrefactor[c1][c2];
4107     fIntFlowCovariances->SetBinContent(covarianceLabel,wCov);
4108    }
4109    covarianceLabel++;
4110   } // end of for(Int_t c2=c1+1;c2<4;c2++) 
4111  } // end of for(Int_t c1=0;c1<4;c1++)
4112  
4113  // Versus multiplicity: 
4114  if(!fCalculateCumulantsVsM){return;}
4115  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
4116  for(Int_t b=1;b<=nBins;b++)
4117  {
4118   // Average 2-, 4-, 6- and 8-particle correlations for all events:
4119   Double_t correlationVsM[4] = {0.};
4120   for(Int_t ci=0;ci<4;ci++)
4121   {
4122    correlationVsM[ci] = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
4123   } // end of for(Int_t ci=0;ci<4;ci++)
4124   // Average products of 2-, 4-, 6- and 8-particle correlations: 
4125   Double_t productOfCorrelationsVsM[4][4] = {{0.}};
4126   Int_t productOfCorrelationsLabelVsM = 1;
4127   // Denominators in the expressions for the unbiased estimator for covariance:
4128   Double_t denominatorVsM[4][4] = {{0.}};
4129   Int_t sumOfProductOfEventWeightsLabel1VsM = 1;
4130   // Weight dependent prefactor which multiply unbiased estimators for covariances:
4131   Double_t wPrefactorVsM[4][4] = {{0.}}; 
4132   Int_t sumOfProductOfEventWeightsLabel2VsM = 1;
4133   for(Int_t c1=0;c1<4;c1++)
4134   {
4135    for(Int_t c2=c1+1;c2<4;c2++)
4136    {
4137     productOfCorrelationsVsM[c1][c2] = fIntFlowProductOfCorrelationsVsMPro[productOfCorrelationsLabelVsM-1]->GetBinContent(b);
4138     if(TMath::Abs(fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b)) > 1.e-44)
4139     {
4140      denominatorVsM[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel1VsM-1]->GetBinContent(b))
4141                             / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b) 
4142                             * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                              
4143      wPrefactorVsM[c1][c2] = fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel2VsM-1]->GetBinContent(b)
4144                            / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)
4145                            * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                                                       
4146     }
4147     productOfCorrelationsLabelVsM++;
4148     sumOfProductOfEventWeightsLabel1VsM++;
4149     sumOfProductOfEventWeightsLabel2VsM++;  
4150    } // end of for(Int_t c1=0;c1<4;c1++) 
4151   } // end of for(Int_t c2=c1+1;c2<4;c2++)
4152  
4153   Int_t covarianceLabelVsM = 1;
4154   for(Int_t c1=0;c1<4;c1++)
4155   {
4156    for(Int_t c2=c1+1;c2<4;c2++)
4157    {
4158     if(TMath::Abs(denominatorVsM[c1][c2]) > 1.e-44)
4159     {
4160      // Covariances:
4161      Double_t covVsM = (productOfCorrelationsVsM[c1][c2]-correlationVsM[c1]*correlationVsM[c2])/denominatorVsM[c1][c2]; 
4162      // Covariances multiplied with weight dependent prefactor:
4163      Double_t wCovVsM = covVsM * wPrefactorVsM[c1][c2];
4164      fIntFlowCovariancesVsM[covarianceLabelVsM-1]->SetBinContent(b,wCovVsM);
4165     }
4166     covarianceLabelVsM++;
4167    } // end of for(Int_t c2=c1+1;c2<4;c2++)
4168   } // end of for(Int_t c1=0;c1<4;c1++)
4169  } // end of for(Int_t b=1;b<=nBins;b++)
4170   
4171 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
4172
4173 //================================================================================================================================
4174
4175 void AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
4176 {
4177  // a) Calculate unbiased estimators Cov(*,*) for true covariances V_(*,*) for NUA terms.
4178  // b) Store in histogram fIntFlowCovariancesNUA for instance the following: 
4179  //
4180  //             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)]
4181  // 
4182  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<cos(phi)>} is event weight for <cos(phi)>.
4183  // c) Binning of fIntFlowCovariancesNUA is organized as follows:
4184  // 
4185  //     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)] 
4186  //     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)]
4187  //     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)]
4188  // ...
4189       
4190  // Cov(<2>,<cos(phi)>):
4191  Double_t product1 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(1); // <<2><cos(phi)>> 
4192  Double_t term1st1 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4193  Double_t term2nd1 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
4194  Double_t sumOfW1st1 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4195  Double_t sumOfW2nd1 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
4196  Double_t sumOfWW1 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(1); // W_{<2>} * W_{<cos(phi)>}
4197  // numerator in the expression for the the unbiased estimator for covariance:
4198  Double_t numerator1 = product1 - term1st1*term2nd1; 
4199  // denominator in the expression for the the unbiased estimator for covariance:
4200  Double_t denominator1 = 0.;
4201  if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
4202  {
4203   denominator1 = 1.-sumOfWW1/(sumOfW1st1*sumOfW2nd1);
4204   if(TMath::Abs(denominator1)>0.)
4205   {
4206    // covariance:
4207    Double_t covariance1 = numerator1/denominator1;
4208    // weight dependent prefactor for covariance:
4209    Double_t wPrefactor1 = sumOfWW1/(sumOfW1st1*sumOfW2nd1);
4210    // finally, store "weighted" covariance:
4211    fIntFlowCovariancesNUA->SetBinContent(1,wPrefactor1*covariance1);
4212   } // end of if(TMath::Abs(denominator)>0.)
4213  } // end of if(TMath::Abs(sumOfW1st1*sumOfW2nd1)>0.)
4214  
4215  // Cov(<2>,<sin(phi)>):
4216  Double_t product2 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(2); // <<2><sin(phi)>> 
4217  Double_t term1st2 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4218  Double_t term2nd2 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
4219  Double_t sumOfW1st2 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4220  Double_t sumOfW2nd2 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
4221  Double_t sumOfWW2 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(2); // W_{<2>} * W_{<sin(phi)>}
4222  // numerator in the expression for the the unbiased estimator for covariance:
4223  Double_t numerator2 = product2 - term1st2*term2nd2;
4224  // denominator in the expression for the the unbiased estimator for covariance:
4225  Double_t denominator2 = 0.;
4226  if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
4227  {  
4228   denominator2 = 1.-sumOfWW2/(sumOfW1st2*sumOfW2nd2);
4229   if(TMath::Abs(denominator2)>0.)
4230   {
4231    // covariance:
4232    Double_t covariance2 = numerator2/denominator2;
4233    // weight dependent prefactor for covariance:
4234    Double_t wPrefactor2 = sumOfWW2/(sumOfW1st2*sumOfW2nd2);
4235    // finally, store "weighted" covariance:
4236    fIntFlowCovariancesNUA->SetBinContent(2,wPrefactor2*covariance2);
4237   } // end of if(TMath::Abs(denominator2)>0.)
4238  } // end of if(TMath::Abs(sumOfW1st2*sumOfW2nd2)>0.)
4239  
4240  // Cov(<cos(phi)>,<sin(phi)>):
4241  Double_t product3 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(3); // <<cos(phi)><sin(phi)>> 
4242  Double_t term1st3 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
4243  Double_t term2nd3 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
4244  Double_t sumOfW1st3 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
4245  Double_t sumOfW2nd3 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
4246  Double_t sumOfWW3 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(3); // W_{<cos(phi)>} * W_{<sin(phi)>}
4247  // numerator in the expression for the the unbiased estimator for covariance:
4248  Double_t numerator3 = product3 - term1st3*term2nd3; 
4249  // denominator in the expression for the the unbiased estimator for covariance:
4250  Double_t denominator3 = 0;
4251  if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
4252  { 
4253   denominator3 = 1.-sumOfWW3/(sumOfW1st3*sumOfW2nd3);
4254   if(TMath::Abs(denominator3)>0.)
4255   {
4256    // covariance:
4257    Double_t covariance3 = numerator3/denominator3;
4258    // weight dependent prefactor for covariance:
4259    Double_t wPrefactor3 = sumOfWW3/(sumOfW1st3*sumOfW2nd3);
4260    // finally, store "weighted" covariance:
4261    fIntFlowCovariancesNUA->SetBinContent(3,wPrefactor3*covariance3);
4262   } // end of if(TMath::Abs(denominator3)>0.)
4263  } // end of if(TMath::Abs(sumOfW1st3*sumOfW2nd3)>0.)
4264  
4265  // Cov(<2>,<cos(phi1+phi2)>):
4266  Double_t product4 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(4); // <<2><cos(phi1+phi2)>> 
4267  Double_t term1st4 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4268  Double_t term2nd4 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4269  Double_t sumOfW1st4 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4270  Double_t sumOfW2nd4 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4271  Double_t sumOfWW4 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(4); // W_{<2>} * W_{<cos(phi1+phi2)>}
4272  // numerator in the expression for the the unbiased estimator for covariance:
4273  Double_t numerator4 = product4 - term1st4*term2nd4; 
4274  // denominator in the expression for the the unbiased estimator for covariance:
4275  Double_t denominator4 = 0.;
4276  if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
4277  { 
4278   denominator4 = 1.-sumOfWW4/(sumOfW1st4*sumOfW2nd4);
4279   if(TMath::Abs(denominator4)>0.)
4280   {  
4281    // covariance:
4282    Double_t covariance4 = numerator4/denominator4;
4283    // weight dependent prefactor for covariance:
4284    Double_t wPrefactor4 = sumOfWW4/(sumOfW1st4*sumOfW2nd4);
4285    // finally, store "weighted" covariance:
4286    fIntFlowCovariancesNUA->SetBinContent(4,wPrefactor4*covariance4);
4287   } // end of if(TMath::Abs(denominator4)>0.)
4288  } // end of if(TMath::Abs(sumOfW1st4*sumOfW2nd4)>0.)
4289  
4290  // Cov(<2>,<sin(phi1+phi2)>):
4291  Double_t product5 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(5); // <<2><sin(phi1+phi2)>> 
4292  Double_t term1st5 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4293  Double_t term2nd5 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4294  Double_t sumOfW1st5 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4295  Double_t sumOfW2nd5 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4296  Double_t sumOfWW5 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(5); // W_{<2>} * W_{<sin(phi1+phi2)>}
4297  // numerator in the expression for the the unbiased estimator for covariance:
4298  Double_t numerator5 = product5 - term1st5*term2nd5; 
4299  // denominator in the expression for the the unbiased estimator for covariance:
4300  Double_t denominator5 = 0.;
4301  if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
4302  {  
4303   denominator5 = 1.-sumOfWW5/(sumOfW1st5*sumOfW2nd5);
4304   if(TMath::Abs(denominator5)>0.)
4305   {  
4306    // covariance:
4307    Double_t covariance5 = numerator5/denominator5;
4308    // weight dependent prefactor for covariance:
4309    Double_t wPrefactor5 = sumOfWW5/(sumOfW1st5*sumOfW2nd5);
4310    // finally, store "weighted" covariance:
4311    fIntFlowCovariancesNUA->SetBinContent(5,wPrefactor5*covariance5);
4312   } // end of if(TMath::Abs(denominator5)>0.)
4313  } // end of if(TMath::Abs(sumOfW1st5*sumOfW2nd5)>0.)
4314  
4315  // Cov(<2>,<cos(phi1-phi2-phi3)>):
4316  Double_t product6 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(6); // <<2><cos(phi1-phi2-phi3)>> 
4317  Double_t term1st6 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4318  Double_t term2nd6 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4319  Double_t sumOfW1st6 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4320  Double_t sumOfW2nd6 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4321  Double_t sumOfWW6 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(6); // W_{<2>} * W_{<cos(phi1-phi2-phi3)>}
4322  // numerator in the expression for the the unbiased estimator for covariance:
4323  Double_t numerator6 = product6 - term1st6*term2nd6; 
4324  // denominator in the expression for the the unbiased estimator for covariance:
4325  Double_t denominator6 = 0.;
4326  if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
4327  {  
4328   denominator6 = 1.-sumOfWW6/(sumOfW1st6*sumOfW2nd6);
4329   if(TMath::Abs(denominator6)>0.)
4330   {  
4331    // covariance:
4332    Double_t covariance6 = numerator6/denominator6;
4333    // weight dependent prefactor for covariance:
4334    Double_t wPrefactor6 = sumOfWW6/(sumOfW1st6*sumOfW2nd6);
4335    // finally, store "weighted" covariance:
4336    fIntFlowCovariancesNUA->SetBinContent(6,wPrefactor6*covariance6);
4337   } // end of if(TMath::Abs(denominator6)>0.)
4338  } // end of if(TMath::Abs(sumOfW1st6*sumOfW2nd6)>0.)
4339  
4340  // Cov(<2>,<sin(phi1-phi2-phi3)>):
4341  Double_t product7 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(7); // <<2><sin(phi1-phi2-phi3)>> 
4342  Double_t term1st7 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
4343  Double_t term2nd7 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4344  Double_t sumOfW1st7 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
4345  Double_t sumOfW2nd7 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4346  Double_t sumOfWW7 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(7); // W_{<2>} * W_{<sin(phi1-phi2-phi3)>}
4347  // numerator in the expression for the the unbiased estimator for covariance:
4348  Double_t numerator7 = product7 - term1st7*term2nd7; 
4349  // denominator in the expression for the the unbiased estimator for covariance:
4350  Double_t denominator7 = 0.;
4351  if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
4352  {  
4353   denominator7 = 1.-sumOfWW7/(sumOfW1st7*sumOfW2nd7);
4354   if(TMath::Abs(denominator7)>0.)
4355   {   
4356    // covariance:
4357    Double_t covariance7 = numerator7/denominator7;
4358    // weight dependent prefactor for covariance:
4359    Double_t wPrefactor7 = sumOfWW7/(sumOfW1st7*sumOfW2nd7);
4360    // finally, store "weighted" covariance:
4361    fIntFlowCovariancesNUA->SetBinContent(7,wPrefactor7*covariance7);
4362   } // end of if(TMath::Abs(denominator7)>0.)
4363  } // end of if(TMath::Abs(sumOfW1st7*sumOfW2nd7)>0.)
4364  
4365  // Cov(<4>,<cos(phi1>):
4366  Double_t product8 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(8); // <<4><cos(phi1)>> 
4367  Double_t term1st8 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4368  Double_t term2nd8 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4369  Double_t sumOfW1st8 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4370  Double_t sumOfW2nd8 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4371  Double_t sumOfWW8 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(8); // W_{<4>} * W_{<cos(phi1)>}
4372  // numerator in the expression for the the unbiased estimator for covariance:
4373  Double_t numerator8 = product8 - term1st8*term2nd8; 
4374  // denominator in the expression for the the unbiased estimator for covariance:
4375  Double_t denominator8 = 0.;
4376  if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
4377  { 
4378   denominator8 = 1.-sumOfWW8/(sumOfW1st8*sumOfW2nd8);
4379   if(TMath::Abs(denominator8)>0.)
4380   {     
4381    // covariance:
4382    Double_t covariance8 = numerator8/denominator8;
4383    // weight dependent prefactor for covariance:
4384    Double_t wPrefactor8 = sumOfWW8/(sumOfW1st8*sumOfW2nd8);
4385    // finally, store "weighted" covariance:
4386    fIntFlowCovariancesNUA->SetBinContent(8,wPrefactor8*covariance8);
4387   } // end of if(TMath::Abs(denominator8)>0.)
4388  } // end of if(TMath::Abs(sumOfW1st8*sumOfW2nd8)>0.)
4389  
4390  // Cov(<4>,<sin(phi1)>):
4391  Double_t product9 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(9); // <<4><sin(phi1)>> 
4392  Double_t term1st9 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4393  Double_t term2nd9 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4394  Double_t sumOfW1st9 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4395  Double_t sumOfW2nd9 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4396  Double_t sumOfWW9 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(9); // W_{<4>} * W_{<sin(phi1)>}
4397  // numerator in the expression for the the unbiased estimator for covariance:
4398  Double_t numerator9 = product9 - term1st9*term2nd9; 
4399  // denominator in the expression for the the unbiased estimator for covariance:
4400  Double_t denominator9 = 0.;
4401  if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
4402  {
4403   denominator9 = 1.-sumOfWW9/(sumOfW1st9*sumOfW2nd9);
4404   if(TMath::Abs(denominator9)>0.)
4405   {     
4406    // covariance:
4407    Double_t covariance9 = numerator9/denominator9;
4408    // weight dependent prefactor for covariance:
4409    Double_t wPrefactor9 = sumOfWW9/(sumOfW1st9*sumOfW2nd9);
4410    // finally, store "weighted" covariance:
4411    fIntFlowCovariancesNUA->SetBinContent(9,wPrefactor9*covariance9); 
4412   }
4413  } // end of if(TMath::Abs(sumOfW1st9*sumOfW2nd9)>0.) 
4414  
4415  // Cov(<4>,<cos(phi1+phi2)>):
4416  Double_t product10 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(10); // <<4><cos(phi1+phi2)>> 
4417  Double_t term1st10 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4418  Double_t term2nd10 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4419  Double_t sumOfW1st10 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4420  Double_t sumOfW2nd10 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4421  Double_t sumOfWW10 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(10); // W_{<4>} * W_{<cos(phi1+phi2)>}
4422  // numerator in the expression for the the unbiased estimator for covariance:
4423  Double_t numerator10 = product10 - term1st10*term2nd10; 
4424  // denominator in the expression for the the unbiased estimator for covariance:
4425  Double_t denominator10 = 0.;
4426  if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
4427  { 
4428   denominator10 = 1.-sumOfWW10/(sumOfW1st10*sumOfW2nd10);
4429   if(TMath::Abs(denominator10)>0.) 
4430   { 
4431    // covariance:
4432    Double_t covariance10 = numerator10/denominator10;
4433    // weight dependent prefactor for covariance:
4434    Double_t wPrefactor10 = sumOfWW10/(sumOfW1st10*sumOfW2nd10);
4435    // finally, store "weighted" covariance:
4436    fIntFlowCovariancesNUA->SetBinContent(10,wPrefactor10*covariance10);
4437   } // end of if(TMath::Abs(denominator10)>0.) 
4438  } // end of if(TMath::Abs(sumOfW1st10*sumOfW2nd10)>0.) 
4439  
4440  // Cov(<4>,<sin(phi1+phi2)>):
4441  Double_t product11 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(11); // <<4><sin(phi1+phi2)>> 
4442  Double_t term1st11 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4443  Double_t term2nd11 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4444  Double_t sumOfW1st11 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4445  Double_t sumOfW2nd11 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4446  Double_t sumOfWW11 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(11); // W_{<4>} * W_{<sin(phi1+phi2)>}
4447  // numerator in the expression for the the unbiased estimator for covariance:
4448  Double_t numerator11 = product11 - term1st11*term2nd11; 
4449  // denominator in the expression for the the unbiased estimator for covariance:
4450  Double_t denominator11 = 0.;
4451  if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
4452  {  
4453   denominator11 = 1.-sumOfWW11/(sumOfW1st11*sumOfW2nd11);
4454   if(TMath::Abs(denominator11)>0.) 
4455   { 
4456    // covariance:
4457    Double_t covariance11 = numerator11/denominator11;
4458    // weight dependent prefactor for covariance:
4459    Double_t wPrefactor11 = sumOfWW11/(sumOfW1st11*sumOfW2nd11);
4460    // finally, store "weighted" covariance:
4461    fIntFlowCovariancesNUA->SetBinContent(11,wPrefactor11*covariance11);
4462   } // end of if(TMath::Abs(denominator11)>0.) 
4463  } // end of if(TMath::Abs(sumOfW1st11*sumOfW2nd11)>0.) 
4464
4465  // Cov(<4>,<cos(phi1-phi2-phi3)>):
4466  Double_t product12 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(12); // <<4><cos(phi1-phi2-phi3)>> 
4467  Double_t term1st12 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4468  Double_t term2nd12 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4469  Double_t sumOfW1st12 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4470  Double_t sumOfW2nd12 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4471  Double_t sumOfWW12 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(12); // W_{<4>} * W_{<cos(phi1-phi2-phi3)>}
4472  // numerator in the expression for the the unbiased estimator for covariance:
4473  Double_t numerator12 = product12 - term1st12*term2nd12; 
4474  // denominator in the expression for the the unbiased estimator for covariance:
4475  Double_t denominator12 = 0.;
4476  if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.) 
4477  {   
4478   denominator12 = 1.-sumOfWW12/(sumOfW1st12*sumOfW2nd12);
4479   if(TMath::Abs(denominator12)>0.) 
4480   { 
4481    // covariance:
4482    Double_t covariance12 = numerator12/denominator12;
4483    // weight dependent prefactor for covariance:
4484    Double_t wPrefactor12 = sumOfWW12/(sumOfW1st12*sumOfW2nd12);
4485    // finally, store "weighted" covariance:
4486    fIntFlowCovariancesNUA->SetBinContent(12,wPrefactor12*covariance12);
4487   } // end of if(TMath::Abs(denominator12)>0.)
4488  } // end of if(TMath::Abs(sumOfW1st12*sumOfW2nd12)>0.)  
4489
4490  // Cov(<4>,<sin(phi1-phi2-phi3)>):
4491  Double_t product13 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(13); // <<4><sin(phi1-phi2-phi3)>> 
4492  Double_t term1st13 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
4493  Double_t term2nd13 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4494  Double_t sumOfW1st13 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
4495  Double_t sumOfW2nd13 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4496  Double_t sumOfWW13 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(13); // W_{<4>} * W_{<sin(phi1-phi2-phi3)>}
4497  // numerator in the expression for the the unbiased estimator for covariance:
4498  Double_t numerator13 = product13 - term1st13*term2nd13; 
4499  // denominator in the expression for the the unbiased estimator for covariance:
4500  Double_t denominator13 = 0.;
4501  if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
4502  {   
4503   denominator13 = 1.-sumOfWW13/(sumOfW1st13*sumOfW2nd13);
4504   if(TMath::Abs(denominator13)>0.) 
4505   { 
4506    // covariance:
4507    Double_t covariance13 = numerator13/denominator13;
4508    // weight dependent prefactor for covariance:
4509    Double_t wPrefactor13 = sumOfWW13/(sumOfW1st13*sumOfW2nd13);
4510    // finally, store "weighted" covariance:
4511    fIntFlowCovariancesNUA->SetBinContent(13,wPrefactor13*covariance13);
4512   } // end of if(TMath::Abs(denominator13)>0.) 
4513  } // end of if(TMath::Abs(sumOfW1st13*sumOfW2nd13)>0.) 
4514
4515  // Cov(<cos(phi1)>,<cos(phi1+phi2)>):
4516  Double_t product14 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(14); // <<cos(phi1)><cos(phi1+phi2)>> 
4517  Double_t term1st14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4518  Double_t term2nd14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4519  Double_t sumOfW1st14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4520  Double_t sumOfW2nd14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4521  Double_t sumOfWW14 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(14); // W_{<cos(phi1)>} * W_{<cos(phi1+phi2)>}
4522  // numerator in the expression for the the unbiased estimator for covariance:
4523  Double_t numerator14 = product14 - term1st14*term2nd14; 
4524  // denominator in the expression for the the unbiased estimator for covariance:
4525  Double_t denominator14 = 0.;
4526  if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
4527  {  
4528   denominator14 = 1.-sumOfWW14/(sumOfW1st14*sumOfW2nd14);
4529   if(TMath::Abs(denominator14)>0.) 
4530   { 
4531    // covariance:
4532    Double_t covariance14 = numerator14/denominator14;
4533    // weight dependent prefactor for covariance:
4534    Double_t wPrefactor14 = sumOfWW14/(sumOfW1st14*sumOfW2nd14);
4535    // finally, store "weighted" covariance:
4536    fIntFlowCovariancesNUA->SetBinContent(14,wPrefactor14*covariance14);
4537   } // end of if(TMath::Abs(denominator14)>0.) 
4538  } // end of if(TMath::Abs(sumOfW1st14*sumOfW2nd14)>0.) 
4539
4540  // Cov(<cos(phi1)>,<sin(phi1+phi2)>):
4541  Double_t product15 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(15); // <<cos(phi1)><sin(phi1+phi2)>> 
4542  Double_t term1st15 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4543  Double_t term2nd15 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4544  Double_t sumOfW1st15 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4545  Double_t sumOfW2nd15 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4546  Double_t sumOfWW15 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(15); // W_{<cos(phi1)>} * W_{<sin(phi1+phi2)>}
4547  // numerator in the expression for the the unbiased estimator for covariance:
4548  Double_t numerator15 = product15 - term1st15*term2nd15; 
4549  // denominator in the expression for the the unbiased estimator for covariance:
4550  Double_t denominator15 = 0.;
4551  if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.) 
4552  {  
4553   denominator15 = 1.-sumOfWW15/(sumOfW1st15*sumOfW2nd15);
4554   if(TMath::Abs(denominator15)>0.) 
4555   { 
4556    // covariance:
4557    Double_t covariance15 = numerator15/denominator15;
4558    // weight dependent prefactor for covariance:
4559    Double_t wPrefactor15 = sumOfWW15/(sumOfW1st15*sumOfW2nd15);
4560    // finally, store "weighted" covariance:
4561    fIntFlowCovariancesNUA->SetBinContent(15,wPrefactor15*covariance15);
4562   } // end of if(TMath::Abs(denominator15)>0.)  
4563  } // end of if(TMath::Abs(sumOfW1st15*sumOfW2nd15)>0.)  
4564  
4565  // Cov(<cos(phi1)>,<cos(phi1-phi2-phi3)>):
4566  Double_t product16 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(16); // <<cos(phi1)><cos(phi1-phi2-phi3)>> 
4567  Double_t term1st16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4568  Double_t term2nd16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4569  Double_t sumOfW1st16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4570  Double_t sumOfW2nd16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4571  Double_t sumOfWW16 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(16); // W_{<cos(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
4572  // numerator in the expression for the the unbiased estimator for covariance:
4573  Double_t numerator16 = product16 - term1st16*term2nd16; 
4574  // denominator in the expression for the the unbiased estimator for covariance:
4575  Double_t denominator16 = 0.;
4576  if(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.) 
4577  {   
4578   denominator16 = 1.-sumOfWW16/(sumOfW1st16*sumOfW2nd16);
4579   if(TMath::Abs(denominator16)>0.) 
4580   {   
4581    // covariance:
4582    Double_t covariance16 = numerator16/denominator16;
4583    // weight dependent prefactor for covariance:
4584    Double_t wPrefactor16 = sumOfWW16/(sumOfW1st16*sumOfW2nd16);
4585    // finally, store "weighted" covariance:
4586    fIntFlowCovariancesNUA->SetBinContent(16,wPrefactor16*covariance16);
4587   } // end of if(TMath::Abs(denominator16)>0.)
4588  } // end ofif(TMath::Abs(sumOfW1st16*sumOfW2nd16)>0.)  
4589  
4590  // Cov(<cos(phi1)>,<sin(phi1-phi2-phi3)>):
4591  Double_t product17 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(17); // <<cos(phi1)><sin(phi1-phi2-phi3)>> 
4592  Double_t term1st17 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
4593  Double_t term2nd17 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4594  Double_t sumOfW1st17 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
4595  Double_t sumOfW2nd17 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4596  Double_t sumOfWW17 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(17); // W_{<cos(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
4597  // numerator in the expression for the the unbiased estimator for covariance:
4598  Double_t numerator17 = product17 - term1st17*term2nd17; 
4599  // denominator in the expression for the the unbiased estimator for covariance:
4600  Double_t denominator17 = 0.;
4601  if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
4602  {
4603   denominator17 = 1.-sumOfWW17/(sumOfW1st17*sumOfW2nd17);
4604   if(TMath::Abs(denominator17)>0.) 
4605   {   
4606    // covariance:
4607    Double_t covariance17 = numerator17/denominator17;
4608    // weight dependent prefactor for covariance:
4609    Double_t wPrefactor17 = sumOfWW17/(sumOfW1st17*sumOfW2nd17);
4610     // finally, store "weighted" covariance:
4611    fIntFlowCovariancesNUA->SetBinContent(17,wPrefactor17*covariance17);
4612   } // end of if(TMath::Abs(denominator17)>0.) 
4613  } // end of if(TMath::Abs(sumOfW1st17*sumOfW2nd17)>0.) 
4614
4615  // Cov(<sin(phi1)>,<cos(phi1+phi2)>):
4616  Double_t product18 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(18); // <<sin(phi1)><cos(phi1+phi2)>> 
4617  Double_t term1st18 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4618  Double_t term2nd18 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4619  Double_t sumOfW1st18 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4620  Double_t sumOfW2nd18 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4621  Double_t sumOfWW18 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(18); // W_{<sin(phi1)>} * W_{<cos(phi1+phi2)>}
4622  // numerator in the expression for the the unbiased estimator for covariance:
4623  Double_t numerator18 = product18 - term1st18*term2nd18; 
4624  // denominator in the expression for the the unbiased estimator for covariance:
4625  Double_t denominator18 = 0.;
4626  if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
4627  { 
4628   denominator18 = 1.-sumOfWW18/(sumOfW1st18*sumOfW2nd18);
4629   if(TMath::Abs(denominator18)>0.) 
4630   {   
4631    // covariance:
4632    Double_t covariance18 = numerator18/denominator18;
4633    // weight dependent prefactor for covariance:
4634    Double_t wPrefactor18 = sumOfWW18/(sumOfW1st18*sumOfW2nd18);
4635    // finally, store "weighted" covariance:
4636    fIntFlowCovariancesNUA->SetBinContent(18,wPrefactor18*covariance18); 
4637   } // end of if(TMath::Abs(denominator18)>0.) 
4638  } // end of if(TMath::Abs(sumOfW1st18*sumOfW2nd18)>0.) 
4639
4640  // Cov(<sin(phi1)>,<sin(phi1+phi2)>):
4641  Double_t product19 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(19); // <<sin(phi1)><sin(phi1+phi2)>> 
4642  Double_t term1st19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4643  Double_t term2nd19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4644  Double_t sumOfW1st19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4645  Double_t sumOfW2nd19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4646  Double_t sumOfWW19 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(19); // W_{<sin(phi1)>} * W_{<sin(phi1+phi2)>}
4647  // numerator in the expression for the the unbiased estimator for covariance:
4648  Double_t numerator19 = product19 - term1st19*term2nd19; 
4649  // denominator in the expression for the the unbiased estimator for covariance:
4650  Double_t denominator19 = 0.;
4651  if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.) 
4652  { 
4653   denominator19 = 1.-sumOfWW19/(sumOfW1st19*sumOfW2nd19);
4654   if(TMath::Abs(denominator19)>0.) 
4655   {   
4656    // covariance:
4657    Double_t covariance19 = numerator19/denominator19;
4658    // weight dependent prefactor for covariance:
4659    Double_t wPrefactor19 = sumOfWW19/(sumOfW1st19*sumOfW2nd19);
4660    // finally, store "weighted" covariance:
4661    fIntFlowCovariancesNUA->SetBinContent(19,wPrefactor19*covariance19);
4662   } // end of if(TMath::Abs(denominator19)>0.)
4663  } // end of if(TMath::Abs(sumOfW1st19*sumOfW2nd19)>0.)
4664  
4665  // Cov(<sin(phi1)>,<cos(phi1-phi2-phi3)>):
4666  Double_t product20 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(20); // <<sin(phi1)><cos(phi1-phi2-phi3)>> 
4667  Double_t term1st20 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4668  Double_t term2nd20 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4669  Double_t sumOfW1st20 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4670  Double_t sumOfW2nd20 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4671  Double_t sumOfWW20 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(20); // W_{<sin(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
4672  // numerator in the expression for the the unbiased estimator for covariance:
4673  Double_t numerator20 = product20 - term1st20*term2nd20; 
4674  // denominator in the expression for the the unbiased estimator for covariance:
4675  Double_t denominator20 = 0.;
4676  if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
4677  { 
4678   denominator20 = 1.-sumOfWW20/(sumOfW1st20*sumOfW2nd20);
4679   if(TMath::Abs(denominator20)>0.) 
4680   { 
4681    // covariance:
4682    Double_t covariance20 = numerator20/denominator20;
4683    // weight dependent prefactor for covariance:
4684    Double_t wPrefactor20 = sumOfWW20/(sumOfW1st20*sumOfW2nd20);
4685    // finally, store "weighted" covariance:
4686    fIntFlowCovariancesNUA->SetBinContent(20,wPrefactor20*covariance20);
4687   } // end of if(TMath::Abs(denominator20)>0.) 
4688  } // end of if(TMath::Abs(sumOfW1st20*sumOfW2nd20)>0.)
4689
4690  // Cov(<sin(phi1)>,<sin(phi1-phi2-phi3)>):
4691  Double_t product21 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(21); // <<sin(phi1)><sin(phi1-phi2-phi3)>> 
4692  Double_t term1st21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
4693  Double_t term2nd21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4694  Double_t sumOfW1st21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
4695  Double_t sumOfW2nd21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4696  Double_t sumOfWW21 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(21); // W_{<sin(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
4697  // numerator in the expression for the the unbiased estimator for covariance:
4698  Double_t numerator21 = product21 - term1st21*term2nd21; 
4699  // denominator in the expression for the the unbiased estimator for covariance:
4700  Double_t denominator21 = 0.;
4701  if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
4702  { 
4703   denominator21 = 1.-sumOfWW21/(sumOfW1st21*sumOfW2nd21);
4704   if(TMath::Abs(denominator21)>0.) 
4705   {   
4706    // covariance:
4707    Double_t covariance21 = numerator21/denominator21;
4708    // weight dependent prefactor for covariance:
4709    Double_t wPrefactor21 = sumOfWW21/(sumOfW1st21*sumOfW2nd21);
4710    // finally, store "weighted" covariance:
4711    fIntFlowCovariancesNUA->SetBinContent(21,wPrefactor21*covariance21);
4712   } // end of if(TMath::Abs(denominator21)>0.)
4713  } // end of if(TMath::Abs(sumOfW1st21*sumOfW2nd21)>0.)
4714
4715  // Cov(<cos(phi1+phi2)>,<sin(phi1+phi2)>):
4716  Double_t product22 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(22); // <<cos(phi1+phi2)><sin(phi1+phi2)>> 
4717  Double_t term1st22 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4718  Double_t term2nd22 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4719  Double_t sumOfW1st22 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4720  Double_t sumOfW2nd22 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4721  Double_t sumOfWW22 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(22); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1+phi2)>}
4722  // numerator in the expression for the the unbiased estimator for covariance:
4723  Double_t numerator22 = product22 - term1st22*term2nd22; 
4724  // denominator in the expression for the the unbiased estimator for covariance:
4725  Double_t denominator22 = 0.;
4726  if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.)
4727  { 
4728   denominator22 = 1.-sumOfWW22/(sumOfW1st22*sumOfW2nd22);
4729   if(TMath::Abs(denominator22)>0.) 
4730   {   
4731    // covariance:
4732    Double_t covariance22 = numerator22/denominator22;
4733    // weight dependent prefactor for covariance:
4734    Double_t wPrefactor22 = sumOfWW22/(sumOfW1st22*sumOfW2nd22);
4735    // finally, store "weighted" covariance:
4736    fIntFlowCovariancesNUA->SetBinContent(22,wPrefactor22*covariance22);
4737   } // end of if(TMath::Abs(denominator22)>0.) 
4738  } // end of if(TMath::Abs(sumOfW1st22*sumOfW2nd22)>0.) 
4739
4740  // Cov(<cos(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
4741  Double_t product23 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(23); // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>> 
4742  Double_t term1st23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4743  Double_t term2nd23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4744  Double_t sumOfW1st23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4745  Double_t sumOfW2nd23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4746  Double_t sumOfWW23 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(23); // W_{<cos(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
4747  // numerator in the expression for the the unbiased estimator for covariance:
4748  Double_t numerator23 = product23 - term1st23*term2nd23; 
4749  // denominator in the expression for the the unbiased estimator for covariance:
4750  Double_t denominator23 = 0.;
4751  if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
4752  {  
4753   denominator23 = 1.-sumOfWW23/(sumOfW1st23*sumOfW2nd23);
4754   if(TMath::Abs(denominator23)>0.) 
4755   {   
4756    // covariance:
4757    Double_t covariance23 = numerator23/denominator23;
4758    // weight dependent prefactor for covariance:
4759    Double_t wPrefactor23 = sumOfWW23/(sumOfW1st23*sumOfW2nd23);
4760    // finally, store "weighted" covariance:
4761    fIntFlowCovariancesNUA->SetBinContent(23,wPrefactor23*covariance23);
4762   } // end of if(TMath::Abs(denominator23)>0.) 
4763  } // end of if(TMath::Abs(sumOfW1st23*sumOfW2nd23)>0.)
4764  
4765  // Cov(<cos(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4766  Double_t product24 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(24); // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4767  Double_t term1st24 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
4768  Double_t term2nd24 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4769  Double_t sumOfW1st24 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
4770  Double_t sumOfW2nd24 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4771  Double_t sumOfWW24 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(24); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4772  // numerator in the expression for the the unbiased estimator for covariance:
4773  Double_t numerator24 = product24 - term1st24*term2nd24; 
4774  // denominator in the expression for the the unbiased estimator for covariance:
4775  Double_t denominator24 = 0.;
4776  if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4777  {   
4778   denominator24 = 1.-sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4779   if(TMath::Abs(denominator24)>0.) 
4780   {   
4781    // covariance:
4782    Double_t covariance24 = numerator24/denominator24;
4783    // weight dependent prefactor for covariance:
4784    Double_t wPrefactor24 = sumOfWW24/(sumOfW1st24*sumOfW2nd24);
4785    // finally, store "weighted" covariance:
4786    fIntFlowCovariancesNUA->SetBinContent(24,wPrefactor24*covariance24);
4787   } // end of if(TMath::Abs(denominator24)>0.)  
4788  } // end of if(TMath::Abs(sumOfW1st24*sumOfW2nd24)>0.)
4789
4790  // Cov(<sin(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
4791  Double_t product25 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(25); // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>> 
4792  Double_t term1st25 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4793  Double_t term2nd25 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4794  Double_t sumOfW1st25 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4795  Double_t sumOfW2nd25 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4796  Double_t sumOfWW25 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(25); // W_{<sin(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
4797  // numerator in the expression for the the unbiased estimator for covariance:
4798  Double_t numerator25 = product25 - term1st25*term2nd25; 
4799  // denominator in the expression for the the unbiased estimator for covariance:
4800  Double_t denominator25 = 0.;
4801  if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4802  { 
4803   denominator25 = 1.-sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4804   if(TMath::Abs(denominator25)>0.) 
4805   { 
4806    // covariance:
4807    Double_t covariance25 = numerator25/denominator25;
4808    // weight dependent prefactor for covariance:
4809    Double_t wPrefactor25 = sumOfWW25/(sumOfW1st25*sumOfW2nd25);
4810    // finally, store "weighted" covariance:
4811    fIntFlowCovariancesNUA->SetBinContent(25,wPrefactor25*covariance25);
4812   } // end of if(TMath::Abs(denominator25)>0.)
4813  } // end of if(TMath::Abs(sumOfW1st25*sumOfW2nd25)>0.)
4814  
4815  // Cov(<sin(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
4816  Double_t product26 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(26); // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>> 
4817  Double_t term1st26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
4818  Double_t term2nd26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4819  Double_t sumOfW1st26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
4820  Double_t sumOfW2nd26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4821  Double_t sumOfWW26 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(26); // W_{<sin(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
4822  // numerator in the expression for the the unbiased estimator for covariance:
4823  Double_t numerator26 = product26 - term1st26*term2nd26; 
4824  // denominator in the expression for the the unbiased estimator for covariance:
4825  Double_t denominator26 = 0.;
4826  if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4827  { 
4828   denominator26 = 1.-sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4829   if(TMath::Abs(denominator26)>0.) 
4830   { 
4831    // covariance:
4832    Double_t covariance26 = numerator26/denominator26;
4833    // weight dependent prefactor for covariance:
4834    Double_t wPrefactor26 = sumOfWW26/(sumOfW1st26*sumOfW2nd26);
4835    // finally, store "weighted" covariance:
4836    fIntFlowCovariancesNUA->SetBinContent(26,wPrefactor26*covariance26);
4837   } // end of if(TMath::Abs(denominator26)>0.) 
4838  } // end of if(TMath::Abs(sumOfW1st26*sumOfW2nd26)>0.)
4839  
4840  // Cov(<cos(phi1-phi2-phi3)>,<sin(phi1-phi2-phi3)>):
4841  Double_t product27 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(27); // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>> 
4842  Double_t term1st27 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
4843  Double_t term2nd27 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
4844  Double_t sumOfW1st27 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
4845  Double_t sumOfW2nd27 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
4846  Double_t sumOfWW27 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(27); // W_{<cos(phi1-phi2-phi3)>} * W_{<sin(phi1-phi2-phi3)>}
4847  // numerator in the expression for the the unbiased estimator for covariance:
4848  Double_t numerator27 = product27 - term1st27*term2nd27; 
4849  // denominator in the expression for the the unbiased estimator for covariance:
4850  Double_t denominator27 = 0.;
4851  if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4852  { 
4853   denominator27 = 1.-sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4854   if(TMath::Abs(denominator27)>0.) 
4855   { 
4856    // covariance:
4857    Double_t covariance27 = numerator27/denominator27;
4858    // weight dependent prefactor for covariance:
4859    Double_t wPrefactor27 = sumOfWW27/(sumOfW1st27*sumOfW2nd27);
4860    // finally, store "weighted" covariance:
4861    fIntFlowCovariancesNUA->SetBinContent(27,wPrefactor27*covariance27);
4862   } // end of if(TMath::Abs(denominator27)>0.) 
4863  } // end of if(TMath::Abs(sumOfW1st27*sumOfW2nd27)>0.)
4864  
4865 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
4866
4867 //================================================================================================================================
4868
4869 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow() 
4870 {
4871  // From profile fIntFlowCorrelationsPro access measured correlations and spread, 
4872  // correctly calculate the statistical errors and store the final results and 
4873  // statistical errors for correlations in histogram fIntFlowCorrelationsHist.
4874  //
4875  // Remark: Statistical error of correlation is calculated as:
4876  //
4877  //          statistical error = termA * spread * termB:
4878  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
4879  //          termB = 1/sqrt(1-termA^2)   
4880  //
4881    
4882  for(Int_t ci=1;ci<=4;ci++) // correlation index
4883  {
4884   if(fIntFlowCorrelationsPro->GetBinEffectiveEntries(ci) < 2 || fIntFlowSquaredCorrelationsPro->GetBinEffectiveEntries(ci) < 2)
4885   {
4886    fIntFlowCorrelationsPro->SetBinError(ci,0.);
4887    fIntFlowSquaredCorrelationsPro->SetBinError(ci,0.);
4888    continue;
4889   } 
4890   Double_t correlation = fIntFlowCorrelationsPro->GetBinContent(ci);
4891   Double_t squaredCorrelation = fIntFlowSquaredCorrelationsPro->GetBinContent(ci);
4892   Double_t spread = 0.;
4893   if(squaredCorrelation-correlation*correlation >= 0.)
4894   {
4895    spread = pow(squaredCorrelation-correlation*correlation,0.5);
4896   } else
4897     {
4898      cout<<endl;
4899      cout<<Form(" WARNING: Imaginary 'spread' for %d-particle correlation!!!! ",2*ci)<<endl;
4900      cout<<endl;
4901     }
4902   Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeights[0]->GetBinContent(ci);
4903   Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeights[1]->GetBinContent(ci);
4904   Double_t termA = 0.;
4905   Double_t termB = 0.;
4906   if(TMath::Abs(sumOfLinearEventWeights) > 0.) // to be improved - shall I omitt here Abs() ?
4907   {
4908    termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
4909   } else
4910     {
4911      cout<<endl;
4912      cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;
4913      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4914      cout<<endl;
4915     }
4916   if(1.-pow(termA,2.) > 0.)
4917   {
4918    termB = 1./pow(1-pow(termA,2.),0.5);
4919   } else
4920     {
4921      cout<<endl;
4922      cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;   
4923      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
4924      cout<<endl;
4925     }     
4926   Double_t statisticalError = termA * spread * termB;
4927   fIntFlowCorrelationsHist->SetBinContent(ci,correlation);
4928   fIntFlowCorrelationsHist->SetBinError(ci,statisticalError);
4929  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index     
4930  
4931  // Versus multiplicity: 
4932  if(!fCalculateCumulantsVsM){return;}
4933  for(Int_t ci=0;ci<=3;ci++) // correlation index
4934  {
4935   Int_t nBins = fIntFlowCorrelationsVsMPro[ci]->GetNbinsX(); 
4936   for(Int_t b=1;b<=nBins;b++) // looping over multiplicity bins
4937   {
4938    if(fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2 || fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b) < 2)
4939    {
4940     fIntFlowCorrelationsVsMPro[ci]->SetBinError(b,0.);
4941     fIntFlowSquaredCorrelationsVsMPro[ci]->SetBinError(b,0.);
4942     continue;
4943    } 
4944    Double_t correlationVsM = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
4945    Double_t squaredCorrelationVsM = fIntFlowSquaredCorrelationsVsMPro[ci]->GetBinContent(b);
4946    Double_t spreadVsM = 0.;
4947    if(squaredCorrelationVsM-correlationVsM*correlationVsM >= 0.)
4948    {
4949     spreadVsM = pow(squaredCorrelationVsM-correlationVsM*correlationVsM,0.5);
4950    } else
4951      {
4952       cout<<endl;
4953       cout<<Form(" WARNING (QC): Imaginary 'spreadVsM' for ci = %d, bin = %d, entries = %f !!!!",
4954                  ci,b,fIntFlowCorrelationsVsMPro[ci]->GetBinEffectiveEntries(b))<<endl; 
4955       cout<<endl;
4956      }     
4957    Double_t sumOfLinearEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][0]->GetBinContent(b);
4958    Double_t sumOfQuadraticEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][1]->GetBinContent(b);
4959    Double_t termAVsM = 0.;
4960    Double_t termBVsM = 0.;
4961    if(sumOfLinearEventWeightsVsM > 0.) 
4962    {
4963     termAVsM = pow(sumOfQuadraticEventWeightsVsM,0.5)/sumOfLinearEventWeightsVsM;
4964    }
4965    if(1.-pow(termAVsM,2.) > 0.)
4966    {
4967     termBVsM = 1./pow(1-pow(termAVsM,2.),0.5);
4968    }     
4969    Double_t statisticalErrorVsM = termAVsM * spreadVsM * termBVsM;
4970    fIntFlowCorrelationsVsMHist[ci]->SetBinContent(b,correlationVsM);
4971    fIntFlowCorrelationsVsMHist[ci]->SetBinError(b,statisticalErrorVsM);  
4972   } // end of for(Int_t b=1;b<=nBins;b++)
4973  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index                                                        
4974                                                                                                                            
4975 } // end of AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow()
4976
4977 //================================================================================================================================
4978
4979 void AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(Int_t nRP)
4980 {
4981  // Fill profile fAverageMultiplicity to hold average multiplicities and 
4982  // number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
4983  
4984  // Binning of fAverageMultiplicity is organized as follows:
4985  //  1st bin: all events (including the empty ones)
4986  //  2nd bin: event with # of RPs greater or equal to 1
4987  //  3rd bin: event with # of RPs greater or equal to 2
4988  //  4th bin: event with # of RPs greater or equal to 3
4989  //  5th bin: event with # of RPs greater or equal to 4
4990  //  6th bin: event with # of RPs greater or equal to 5
4991  //  7th bin: event with # of RPs greater or equal to 6
4992  //  8th bin: event with # of RPs greater or equal to 7
4993  //  9th bin: event with # of RPs greater or equal to 8
4994  
4995  if(nRP<0)
4996  {
4997   cout<<endl;
4998   cout<<" WARNING (QC): nRP<0 in in AFAWQC::FAM() !!!!"<<endl;
4999   cout<<endl;
5000   exit(0);
5001  }
5002  
5003  for(Int_t i=0;i<9;i++)
5004  {
5005   if(nRP>=i){fAvMultiplicity->Fill(i+0.5,nRP,1);}
5006  }
5007  
5008 } // end of AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(nRP)
5009
5010 //================================================================================================================================
5011
5012 void AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
5013
5014  // a) Calculate Q-cumulants from the measured multiparticle correlations;
5015  // b) Propagate the statistical errors from measured multiparticle correlations to statistical errors of Q-cumulants;  
5016  // c) Remark: Q-cumulants calculated in this method are biased by non-uniform acceptance of detector !!!! 
5017  //            Method CalculateQcumulantsCorrectedForNUAIntFlow() is called afterwards to correct for this bias;
5018  // d) Store the results and statistical error of Q-cumulants in histogram fIntFlowQcumulants.
5019  //    Binning of fIntFlowQcumulants is organized as follows:
5020  //
5021  //            1st bin: QC{2}
5022  //            2nd bin: QC{4}
5023  //            3rd bin: QC{6}
5024  //            4th bin: QC{8}
5025  //
5026  
5027  // Correlations:
5028  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
5029  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
5030  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
5031  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
5032  // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
5033  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
5034  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
5035  Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
5036  Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
5037  // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
5038  Double_t wCov24 = 0.; // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
5039  Double_t wCov26 = 0.; // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
5040  Double_t wCov28 = 0.; // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
5041  Double_t wCov46 = 0.; // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
5042  Double_t wCov48 = 0.; // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
5043  Double_t wCov68 = 0.; // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>)  
5044  if(!fForgetAboutCovariances)
5045  {
5046   wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
5047   wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
5048   wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
5049   wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
5050   wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
5051   wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
5052  }
5053  // Q-cumulants: 
5054  Double_t qc2 = 0.; // QC{2}
5055  Double_t qc4 = 0.; // QC{4}
5056  Double_t qc6 = 0.; // QC{6}
5057  Double_t qc8 = 0.; // QC{8}
5058  if(TMath::Abs(two) > 0.){qc2 = two;} 
5059  if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
5060  if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
5061  if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);} 
5062  // Statistical errors of Q-cumulants:       
5063  Double_t qc2Error = 0.;
5064  Double_t qc4Error = 0.;
5065  Double_t qc6Error = 0.;
5066  Double_t qc8Error = 0.; 
5067  // Squared statistical errors of Q-cumulants:       
5068  //Double_t qc2ErrorSquared = 0.;
5069  Double_t qc4ErrorSquared = 0.;
5070  Double_t qc6ErrorSquared = 0.;
5071  Double_t qc8ErrorSquared = 0.;        
5072  // Statistical error of QC{2}:              
5073  qc2Error = twoError;                                                 
5074  // Statistical error of QC{4}:              
5075  qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
5076                  - 8.*two*wCov24;                     
5077  if(qc4ErrorSquared>0.)
5078  {
5079   qc4Error = pow(qc4ErrorSquared,0.5);
5080  } else 
5081    {
5082     cout<<" WARNING (QC): Statistical error of QC{4} is imaginary !!!!"<<endl;
5083    }                                           
5084  // Statistical error of QC{6}:              
5085  qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
5086                  + 81.*pow(two,2.)*pow(fourError,2.)
5087                  + pow(sixError,2.)
5088                  - 162.*two*(4.*pow(two,2.)-four)*wCov24
5089                  + 18.*(4.*pow(two,2.)-four)*wCov26
5090                  - 18.*two*wCov46;                     
5091  if(qc6ErrorSquared>0.)
5092  {
5093   qc6Error = pow(qc6ErrorSquared,0.5);
5094  } else 
5095    {
5096     cout<<" WARNING (QC): Statistical error of QC{6} is imaginary !!!!"<<endl;
5097    }                       
5098  // Statistical error of QC{8}:              
5099  qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
5100                  + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
5101                  + 256.*pow(two,2.)*pow(sixError,2.)
5102                  + pow(eightError,2.)
5103                  - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
5104                  + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
5105                  - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
5106                  - 1152.*two*(4.*pow(two,2.)-four)*wCov46
5107                  + 72.*(4.*pow(two,2.)-four)*wCov48
5108                  - 32.*two*wCov68;      
5109  if(qc8ErrorSquared>0.)
5110  {
5111   qc8Error = pow(qc8ErrorSquared,0.5);
5112  } else 
5113    {
5114     cout<<"WARNING (QC): Statistical error of QC{8} is imaginary !!!!"<<endl;
5115    }
5116  // Store the results and statistical errors for Q-cumulants:
5117  if(TMath::Abs(qc2)>0.)
5118  {
5119   fIntFlowQcumulants->SetBinContent(1,qc2);
5120   fIntFlowQcumulants->SetBinError(1,qc2Error);
5121  }
5122  if(TMath::Abs(qc4)>0.)
5123  {
5124   fIntFlowQcumulants->SetBinContent(2,qc4);
5125   fIntFlowQcumulants->SetBinError(2,qc4Error);
5126  }
5127  if(TMath::Abs(qc6)>0.)
5128  {
5129   fIntFlowQcumulants->SetBinContent(3,qc6);
5130   fIntFlowQcumulants->SetBinError(3,qc6Error);
5131  }
5132  if(TMath::Abs(qc8)>0.)
5133  {
5134   fIntFlowQcumulants->SetBinContent(4,qc8); 
5135   fIntFlowQcumulants->SetBinError(4,qc8Error);
5136  } 
5137  
5138  // Versus multiplicity: 
5139  if(!fCalculateCumulantsVsM){return;}
5140  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
5141  Double_t value[4] = {0.}; // QCs vs M
5142  Double_t error[4] = {0.}; // error of QCs vs M
5143  Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
5144  Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
5145  for(Int_t b=1;b<=nBins;b++)
5146  {
5147   // Correlations:
5148   two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> 
5149   four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>>  
5150   six = fIntFlowCorrelationsVsMHist[2]->GetBinContent(b); // <<6>> 
5151   eight = fIntFlowCorrelationsVsMHist[3]->GetBinContent(b); // <<8>>  
5152   // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
5153   twoError = fIntFlowCorrelationsVsMHist[0]->GetBinError(b); // statistical error of <2>  
5154   fourError = fIntFlowCorrelationsVsMHist[1]->GetBinError(b); // statistical error of <4>   
5155   sixError = fIntFlowCorrelationsVsMHist[2]->GetBinError(b); // statistical error of <6> 
5156   eightError = fIntFlowCorrelationsVsMHist[3]->GetBinError(b); // statistical error of <8> 
5157   // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
5158   if(!fForgetAboutCovariances)
5159   {
5160    wCov24 = fIntFlowCovariancesVsM[0]->GetBinContent(b); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
5161    wCov26 = fIntFlowCovariancesVsM[1]->GetBinContent(b); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
5162    wCov28 = fIntFlowCovariancesVsM[2]->GetBinContent(b); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
5163    wCov46 = fIntFlowCovariancesVsM[3]->GetBinContent(b); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
5164    wCov48 = fIntFlowCovariancesVsM[4]->GetBinContent(b); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
5165    wCov68 = fIntFlowCovariancesVsM[5]->GetBinContent(b); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
5166   }
5167   // Q-cumulants: 
5168   qc2 = 0.; // QC{2}
5169   qc4 = 0.; // QC{4}
5170   qc6 = 0.; // QC{6}
5171   qc8 = 0.; // QC{8}
5172   if(TMath::Abs(two) > 0.){qc2 = two;} 
5173   if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
5174   if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
5175   if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);}  
5176   // Statistical errors of Q-cumulants:       
5177   qc2Error = 0.;
5178   qc4Error = 0.;
5179   qc6Error = 0.;
5180   qc8Error = 0.; 
5181   // Squared statistical errors of Q-cumulants:       
5182   //Double_t qc2ErrorSquared = 0.;
5183   qc4ErrorSquared = 0.;
5184   qc6ErrorSquared = 0.;
5185   qc8ErrorSquared = 0.;    
5186   // Statistical error of QC{2}:              
5187   qc2Error = twoError;                                             
5188   // Statistical error of QC{4}:              
5189   qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
5190                   - 8.*two*wCov24;                     
5191   if(qc4ErrorSquared>0.)
5192   {
5193    qc4Error = pow(qc4ErrorSquared,0.5);
5194   } else 
5195     {
5196      // cout<<"WARNING: Statistical error of QC{4} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
5197     }                                       
5198   // Statistical error of QC{6}:              
5199   qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
5200                   + 81.*pow(two,2.)*pow(fourError,2.)
5201                   + pow(sixError,2.)
5202                   - 162.*two*(4.*pow(two,2.)-four)*wCov24
5203                   + 18.*(4.*pow(two,2.)-four)*wCov26
5204                   - 18.*two*wCov46;                     
5205   if(qc6ErrorSquared>0.)
5206   {
5207    qc6Error = pow(qc6ErrorSquared,0.5);
5208   } else 
5209     {
5210      // cout<<"WARNING: Statistical error of QC{6} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
5211     }                            
5212   // Statistical error of QC{8}:              
5213   qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
5214                   + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
5215                   + 256.*pow(two,2.)*pow(sixError,2.)
5216                   + pow(eightError,2.)
5217                   - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
5218                   + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
5219                   - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
5220                   - 1152.*two*(4.*pow(two,2.)-four)*wCov46
5221                   + 72.*(4.*pow(two,2.)-four)*wCov48
5222                   - 32.*two*wCov68;      
5223   if(qc8ErrorSquared>0.)
5224   {
5225    qc8Error = pow(qc8ErrorSquared,0.5);
5226   } else 
5227     {
5228      // cout<<"WARNING: Statistical error of QC{8} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
5229     }
5230   // Store the results and statistical errors for Q-cumulants:
5231   if(TMath::Abs(qc2)>0.)
5232   {
5233    fIntFlowQcumulantsVsM[0]->SetBinContent(b,qc2);
5234    fIntFlowQcumulantsVsM[0]->SetBinError(b,qc2Error);  
5235   }
5236   if(TMath::Abs(qc4)>0.)
5237   {
5238    fIntFlowQcumulantsVsM[1]->SetBinContent(b,qc4);  
5239    fIntFlowQcumulantsVsM[1]->SetBinError(b,qc4Error);
5240   }
5241   if(TMath::Abs(qc6)>0.)
5242   {
5243    fIntFlowQcumulantsVsM[2]->SetBinContent(b,qc6); 
5244    fIntFlowQcumulantsVsM[2]->SetBinError(b,qc6Error);
5245   }
5246   if(TMath::Abs(qc8)>0.)
5247   {  
5248    fIntFlowQcumulantsVsM[3]->SetBinContent(b,qc8);
5249    fIntFlowQcumulantsVsM[3]->SetBinError(b,qc8Error);
5250   } 
5251   // Rebin in M:
5252   for(Int_t co=0;co<4;co++)
5253   {
5254    if(fIntFlowCorrelationsVsMPro[co]->GetBinEffectiveEntries(b)<2){continue;}
5255    value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
5256    error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
5257    if(error[co]>0.)
5258    {
5259     dSum1[co]+=value[co]/(error[co]*error[co]);
5260     dSum2[co]+=1./(error[co]*error[co]);
5261    }
5262   } // end of for(Int_t co=0;co<4;co++) 
5263  } // end of for(Int_t b=1;b<=nBins;b++)
5264  // Store rebinned Q-cumulants:
5265  for(Int_t co=0;co<4;co++)
5266  {
5267   if(dSum2[co]>0.)
5268   {
5269    fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
5270    fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
5271   }
5272  } // end of for(Int_t co=0;co<4;co++)
5273  
5274 } // end of AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
5275
5276 //================================================================================================================================ 
5277
5278 void AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
5279 {
5280  // a) Calculate the final results for reference flow estimates from Q-cumulants;
5281  // b) Propagate the statistical errors to reference flow estimates from statistical error of Q-cumulants; 
5282  // c) Store the results and statistical errors of reference flow estimates in histogram fIntFlow.
5283  //    Binning of fIntFlow is organized as follows:
5284  //
5285  //            1st bin: v{2,QC}
5286  //            2nd bin: v{4,QC}
5287  //            3rd bin: v{6,QC}
5288  //            4th bin: v{8,QC}
5289  //
5290  
5291  // Reference flow estimates:
5292  Double_t v2 = 0.; // v{2,QC}  
5293  Double_t v4 = 0.; // v{4,QC}  
5294  Double_t v6 = 0.; // v{6,QC}  
5295  Double_t v8 = 0.; // v{8,QC}
5296  // Reference flow's statistical errors:
5297  Double_t v2Error = 0.; // v{2,QC} stat. error 
5298  Double_t v4Error = 0.; // v{4,QC} stat. error
5299  Double_t v6Error = 0.; // v{6,QC} stat. error
5300  Double_t v8Error = 0.; // v{8,QC} stat. error
5301   
5302  // Q-cumulants:
5303  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
5304  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
5305  Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
5306  Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
5307  // Q-cumulants's statistical errors: 
5308  Double_t qc2Error = fIntFlowQcumulants->GetBinError(1); // QC{2} stat. error  
5309  Double_t qc4Error = fIntFlowQcumulants->GetBinError(2); // QC{4} stat. error  
5310  Double_t qc6Error = fIntFlowQcumulants->GetBinError(3); // QC{6} stat. error  
5311  Double_t qc8Error = fIntFlowQcumulants->GetBinError(4); // QC{8} stat. error
5312  // Calculate reference flow estimates from Q-cumulants: 
5313  if(qc2>=0.){v2 = pow(qc2,0.5);} 
5314  if(qc4<=0.){v4 = pow(-1.*qc4,1./4.);} 
5315  if(qc6>=0.){v6 = pow((1./4.)*qc6,1./6.);}
5316  if(qc8<=0.){v8 = pow((-1./33.)*qc8,1./8.);}  
5317  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants:  
5318  if(qc2>0.){v2Error = (1./2.)*pow(qc2,-0.5)*qc2Error;} 
5319  if(qc4<0.){v4Error = (1./4.)*pow(-qc4,-3./4.)*qc4Error;} 
5320  if(qc6>0.){v6Error = (1./6.)*pow(2.,-1./3.)*pow(qc6,-5./6.)*qc6Error;}   
5321  if(qc8<0.){v8Error = (1./8.)*pow(33.,-1./8.)*pow(-qc8,-7./8.)*qc8Error;}   
5322  // Print warnings for the 'wrong sign' cumulants: 
5323  if(TMath::Abs(v2) < 1.e-44)
5324  {
5325   cout<<" WARNING: Wrong sign QC{2}, couldn't calculate v{2,QC} !!!!"<<endl;
5326  }
5327  if(TMath::Abs(v4) < 1.e-44)
5328  {
5329   cout<<" WARNING: Wrong sign QC{4}, couldn't calculate v{4,QC} !!!!"<<endl;
5330  } 
5331  if(TMath::Abs(v6) < 1.e-44)
5332  {
5333   cout<<" WARNING: Wrong sign QC{6}, couldn't calculate v{6,QC} !!!!"<<endl; 
5334  }
5335  if(TMath::Abs(v8) < 1.e-44)
5336  {
5337   cout<<" WARNING: Wrong sign QC{8}, couldn't calculate v{8,QC} !!!!"<<endl;
5338  }                       
5339  // Store the results and statistical errors of integrated flow estimates:
5340  fIntFlow->SetBinContent(1,v2);
5341  fIntFlow->SetBinError(1,v2Error);
5342  fIntFlow->SetBinContent(2,v4);
5343  fIntFlow->SetBinError(2,v4Error);
5344  fIntFlow->SetBinContent(3,v6);
5345  fIntFlow->SetBinError(3,v6Error);
5346  fIntFlow->SetBinContent(4,v8);
5347  fIntFlow->SetBinError(4,v8Error);  
5348   
5349  // Versus multiplicity: 
5350  if(!fCalculateCumulantsVsM){return;} 
5351  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
5352  for(Int_t b=1;b<=nBins;b++)
5353  {
5354   // Q-cumulants:
5355   Double_t qc2VsM = fIntFlowQcumulantsVsM[0]->GetBinContent(b); // QC{2}  
5356   Double_t qc4VsM = fIntFlowQcumulantsVsM[1]->GetBinContent(b); // QC{4}  
5357   Double_t qc6VsM = fIntFlowQcumulantsVsM[2]->GetBinContent(b); // QC{6}  
5358   Double_t qc8VsM = fIntFlowQcumulantsVsM[3]->GetBinContent(b); // QC{8}
5359   // Q-cumulants's statistical errors: 
5360   Double_t qc2ErrorVsM = fIntFlowQcumulantsVsM[0]->GetBinError(b); // QC{2} stat. error  
5361   Double_t qc4ErrorVsM = fIntFlowQcumulantsVsM[1]->GetBinError(b); // QC{4} stat. error  
5362   Double_t qc6ErrorVsM = fIntFlowQcumulantsVsM[2]->GetBinError(b); // QC{6} stat. error  
5363   Double_t qc8ErrorVsM = fIntFlowQcumulantsVsM[3]->GetBinError(b); // QC{8} stat. error
5364   // Reference flow estimates:
5365   Double_t v2VsM = 0.; // v{2,QC}  
5366   Double_t v4VsM = 0.; // v{4,QC}  
5367   Double_t v6VsM = 0.; // v{6,QC}  
5368   Double_t v8VsM = 0.; // v{8,QC}
5369   // Reference flow estimates errors:
5370   Double_t v2ErrorVsM = 0.; // v{2,QC} stat. error  
5371   Double_t v4ErrorVsM = 0.; // v{4,QC} stat. error
5372   Double_t v6ErrorVsM = 0.; // v{6,QC} stat. error  
5373   Double_t v8ErrorVsM = 0.; // v{8,QC} stat. error
5374   // Calculate reference flow estimates from Q-cumulants: 
5375   if(qc2VsM>=0.){v2VsM = pow(qc2VsM,0.5);} 
5376   if(qc4VsM<=0.){v4VsM = pow(-1.*qc4VsM,1./4.);} 
5377   if(qc6VsM>=0.){v6VsM = pow((1./4.)*qc6VsM,1./6.);}
5378   if(qc8VsM<=0.){v8VsM = pow((-1./33.)*qc8VsM,1./8.);}  
5379   // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
5380   if(qc2VsM>0.){v2ErrorVsM = (1./2.)*pow(qc2VsM,-0.5)*qc2ErrorVsM;} 
5381   if(qc4VsM<0.){v4ErrorVsM = (1./4.)*pow(-qc4VsM,-3./4.)*qc4ErrorVsM;} 
5382   if(qc6VsM>0.){v6ErrorVsM = (1./6.)*pow(2.,-1./3.)*pow(qc6VsM,-5./6.)*qc6ErrorVsM;}   
5383   if(qc8VsM<0.){v8ErrorVsM = (1./8.)*pow(33.,-1./8.)*pow(-qc8VsM,-7./8.)*qc8ErrorVsM;}                       
5384   // Store the results and statistical errors of integrated flow estimates:
5385   fIntFlowVsM[0]->SetBinContent(b,v2VsM);
5386   fIntFlowVsM[0]->SetBinError(b,v2ErrorVsM);
5387   fIntFlowVsM[1]->SetBinContent(b,v4VsM);
5388   fIntFlowVsM[1]->SetBinError(b,v4ErrorVsM);
5389   fIntFlowVsM[2]->SetBinContent(b,v6VsM);
5390   fIntFlowVsM[2]->SetBinError(b,v6ErrorVsM);
5391   fIntFlowVsM[3]->SetBinContent(b,v8VsM);
5392   fIntFlowVsM[3]->SetBinError(b,v8ErrorVsM);
5393  } // end of for(Int_t b=1;b<=nBins;b++)
5394  
5395  // 'Rebinned in M' calculation: // to be improved - this can be implemented better:   
5396  // Reference flow estimates:
5397  Double_t v2RebinnedInM = 0.; // v{2,QC}  
5398  Double_t v4RebinnedInM = 0.; // v{4,QC}  
5399  Double_t v6RebinnedInM = 0.; // v{6,QC}  
5400  Double_t v8RebinnedInM = 0.; // v{8,QC}
5401  // Reference flow's statistical errors:
5402  Double_t v2ErrorRebinnedInM = 0.; // v{2,QC} stat. error 
5403  Double_t v4ErrorRebinnedInM = 0.; // v{4,QC} stat. error
5404  Double_t v6ErrorRebinnedInM = 0.; // v{6,QC} stat. error
5405  Double_t v8ErrorRebinnedInM = 0.; // v{8,QC} stat. error
5406  // Q-cumulants:
5407  Double_t qc2RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(1); // QC{2}  
5408  Double_t qc4RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(2); // QC{4}  
5409  Double_t qc6RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(3); // QC{6}  
5410  Double_t qc8RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(4); // QC{8}
5411  // Q-cumulants's statistical errors: 
5412  Double_t qc2ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(1); // QC{2} stat. error  
5413  Double_t qc4ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(2); // QC{4} stat. error  
5414  Double_t qc6ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(3); // QC{6} stat. error  
5415  Double_t qc8ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(4); // QC{8} stat. error
5416  // Calculate reference flow estimates from Q-cumulants: 
5417  if(qc2RebinnedInM>=0.){v2RebinnedInM = pow(qc2RebinnedInM,0.5);} 
5418  if(qc4RebinnedInM<=0.){v4RebinnedInM = pow(-1.*qc4RebinnedInM,1./4.);} 
5419  if(qc6RebinnedInM>=0.){v6RebinnedInM = pow((1./4.)*qc6RebinnedInM,1./6.);}
5420  if(qc8RebinnedInM<=0.){v8RebinnedInM = pow((-1./33.)*qc8RebinnedInM,1./8.);}  
5421  // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
5422  if(qc2RebinnedInM>0.){v2ErrorRebinnedInM = (1./2.)*pow(qc2RebinnedInM,-0.5)*qc2ErrorRebinnedInM;} 
5423  if(qc4RebinnedInM<0.){v4ErrorRebinnedInM = (1./4.)*pow(-qc4RebinnedInM,-3./4.)*qc4ErrorRebinnedInM;} 
5424  if(qc6RebinnedInM>0.){v6ErrorRebinnedInM = (1./6.)*pow(2.,-1./3.)*pow(qc6RebinnedInM,-5./6.)*qc6ErrorRebinnedInM;}   
5425  if(qc8RebinnedInM<0.){v8ErrorRebinnedInM = (1./8.)*pow(33.,-1./8.)*pow(-qc8RebinnedInM,-7./8.)*qc8ErrorRebinnedInM;}   
5426  // Print warnings for the 'wrong sign' cumulants: 
5427  if(TMath::Abs(v2RebinnedInM) < 1.e-44)
5428  {
5429   cout<<" WARNING: Wrong sign QC{2} rebinned in M, couldn't calculate v{2,QC} !!!!"<<endl;
5430  }
5431  if(TMath::Abs(v4RebinnedInM) < 1.e-44)
5432  {
5433   cout<<" WARNING: Wrong sign QC{4} rebinned in M, couldn't calculate v{4,QC} !!!!"<<endl;
5434  }
5435  if(TMath::Abs(v6RebinnedInM) < 1.e-44)
5436  {
5437   cout<<" WARNING: Wrong sign QC{6} rebinned in M, couldn't calculate v{6,QC} !!!!"<<endl;
5438  }
5439  if(TMath::Abs(v8RebinnedInM) < 1.e-44)
5440  {
5441   cout<<" WARNING: Wrong sign QC{8} rebinned in M, couldn't calculate v{8,QC} !!!!"<<endl;
5442  }                       
5443  // Store the results and statistical errors of integrated flow estimates:
5444  fIntFlowRebinnedInM->SetBinContent(1,v2RebinnedInM);
5445  fIntFlowRebinnedInM->SetBinError(1,v2ErrorRebinnedInM);
5446  fIntFlowRebinnedInM->SetBinContent(2,v4RebinnedInM);
5447  fIntFlowRebinnedInM->SetBinError(2,v4ErrorRebinnedInM);
5448  fIntFlowRebinnedInM->SetBinContent(3,v6RebinnedInM);
5449  fIntFlowRebinnedInM->SetBinError(3,v6ErrorRebinnedInM);
5450  fIntFlowRebinnedInM->SetBinContent(4,v8RebinnedInM);
5451  fIntFlowRebinnedInM->SetBinError(4,v8ErrorRebinnedInM);    
5452   
5453 } // end of AliFlowAnalysisWithQCumulants::CalculateReferenceFlow()
5454
5455 //================================================================================================================================ 
5456
5457 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
5458 {
5459  // Fill in AliFlowCommonHistResults histograms relevant for reference flow.
5460  
5461  // There are two possibilities here:
5462  // a) Store minimum bias reference flow - use SetMinimumBiasReferenceFlow(kTRUE). This result is 
5463  //    biased by the interplay between nonflow correlations and multiplicity fluctuations and is 
5464  //    also stored in local histogram fIntFlow; 
5465  // b) Store reference flow obtained from flow analysis performed at fixed multiplicity and 
5466  //    rebinned only at the end of the day - use SetMinimumBiasReferenceFlow(kFALSE). This result
5467  //    is also stored in local histogram fIntFlowRebinnedInM.
5468  
5469  // Reference flow estimates:
5470  Double_t v[4] = {0.};
5471  // Statistical errors of reference flow estimates:
5472  Double_t vError[4] = {0.};
5473   
5474  for(Int_t b=0;b<4;b++)
5475  {
5476   if(fMinimumBiasReferenceFlow)
5477   { 
5478    v[b] = fIntFlow->GetBinContent(b+1);
5479    vError[b] = fIntFlow->GetBinError(b+1);
5480   } else
5481     {
5482      v[b] = fIntFlowRebinnedInM->GetBinContent(b+1);
5483      vError[b] = fIntFlowRebinnedInM->GetBinError(b+1);
5484     }
5485  } // end of for(Int_t b=0;b<4;b++)
5486   
5487  // Fill AliFlowCommonHistResults histogram:
5488  fCommonHistsResults2nd->FillIntegratedFlow(v[0],vError[0]); // to be improved (hardwired 2nd in the name)  
5489  fCommonHistsResults4th->FillIntegratedFlow(v[1],vError[1]); // to be improved (hardwired 4th in the name)
5490  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)) // to be improved (calculate also 6th and 8th order)
5491  {
5492   fCommonHistsResults6th->FillIntegratedFlow(v[2],vError[2]); // to be improved (hardwired 6th in the name)
5493   fCommonHistsResults8th->FillIntegratedFlow(v[3],vError[3]); // to be improved (hardwired 8th in the name) 
5494  }
5495  
5496 } // end of AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
5497
5498 //================================================================================================================================ 
5499
5500 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
5501 {
5502  // Calculate all correlations needed for integrated flow using particle weights.
5503   
5504  // Remark 1: When particle weights are used the binning of fIntFlowCorrelationAllPro is organized as follows:
5505  //
5506  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
5507  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
5508  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
5509  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
5510  //  5th bin:           ----  EMPTY ----
5511  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
5512  //  7th bin: <3>_{3n|2n,1n} = ...
5513  //  8th bin: <3>_{4n|2n,2n} = ...
5514  //  9th bin: <3>_{4n|3n,1n} = ...
5515  // 10th bin:           ----  EMPTY ----
5516  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
5517  // 12th bin: <4>_{2n,1n|2n,1n} = ...
5518  // 13th bin: <4>_{2n,2n|2n,2n} = ...
5519  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
5520  // 15th bin: <4>_{3n,1n|3n,1n} = ...
5521  // 16th bin: <4>_{3n,1n|2n,2n} = ...
5522  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
5523  // 18th bin:           ----  EMPTY ----
5524  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
5525  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
5526  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
5527  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
5528  // 23rd bin:           ----  EMPTY ----
5529  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
5530  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
5531  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
5532  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
5533  // 28th bin:           ----  EMPTY ----
5534  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
5535  // 30th bin:           ----  EMPTY ----
5536  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
5537  
5538  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
5539  // fIntFlowExtraCorrelationsPro binning of which is organized as follows:
5540  
5541  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
5542  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
5543  
5544  // multiplicity (number of particles used to determine the reaction plane)
5545  Double_t dMult = (*fSpk)(0,0);
5546  
5547  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5548  Double_t dReQ1n1k = (*fReQ)(0,1);
5549  Double_t dReQ2n2k = (*fReQ)(1,2);
5550  Double_t dReQ3n3k = (*fReQ)(2,3);
5551  Double_t dReQ4n4k = (*fReQ)(3,4);
5552  Double_t dReQ1n3k = (*fReQ)(0,3);
5553  Double_t dImQ1n1k = (*fImQ)(0,1);
5554  Double_t dImQ2n2k = (*fImQ)(1,2);
5555  Double_t dImQ3n3k = (*fImQ)(2,3);
5556  Double_t dImQ4n4k = (*fImQ)(3,4);
5557  Double_t dImQ1n3k = (*fImQ)(0,3);
5558
5559  // dMs are variables introduced in order to simplify some Eqs. bellow:
5560  //..............................................................................................
5561  Double_t dM11 = (*fSpk)(1,1)-(*fSpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
5562  Double_t dM22 = (*fSpk)(1,2)-(*fSpk)(0,4); // dM22 = sum_{i,j=1,i!=j}^M w_i^2 w_j^2
5563  Double_t dM33 = (*fSpk)(1,3)-(*fSpk)(0,6); // dM33 = sum_{i,j=1,i!=j}^M w_i^3 w_j^3
5564  Double_t dM44 = (*fSpk)(1,4)-(*fSpk)(0,8); // dM44 = sum_{i,j=1,i!=j}^M w_i^4 w_j^4
5565  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
5566  Double_t dM211 = (*fSpk)(0,2)*(*fSpk)(1,1)-2.*(*fSpk)(0,3)*(*fSpk)(0,1)
5567                 - (*fSpk)(1,2)+2.*(*fSpk)(0,4); // dM211 = sum_{i,j,k=1,i!=j!=k}^M w_i^2 w_j w_k
5568  Double_t dM1111 = (*fSpk)(3,1)-6.*(*fSpk)(0,2)*(*fSpk)(1,1)  
5569                  + 8.*(*fSpk)(0,3)*(*fSpk)(0,1)
5570                  + 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
5571  //..............................................................................................
5572
5573  // 2-particle correlations:
5574  Double_t two1n1nW1W1 = 0.; // <w1 w2 cos(n*(phi1-phi2))>
5575  Double_t two2n2nW2W2 = 0.; // <w1^2 w2^2 cos(2n*(phi1-phi2))>
5576  Double_t two3n3nW3W3 = 0.; // <w1^3 w2^3 cos(3n*(phi1-phi2))>
5577  Double_t two4n4nW4W4 = 0.; // <w1^4 w2^4 cos(4n*(phi1-phi2))>
5578  if(dMult>1) 
5579  { 
5580   if(dM11)
5581   {
5582    two1n1nW1W1 = (pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSpk)(0,2))/dM11;    
5583    // average correlation <w1 w2 cos(n*(phi1-phi2))> for single event: 
5584    fIntFlowCorrelationsEBE->SetBinContent(1,two1n1nW1W1);
5585    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,dM11);
5586    // average correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
5587    fIntFlowCorrelationsPro->Fill(0.5,two1n1nW1W1,dM11);  
5588    // average squared correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
5589    fIntFlowSquaredCorrelationsPro->Fill(0.5,two1n1nW1W1*two1n1nW1W1,dM11); 
5590    fIntFlowCorrelationsAllPro->Fill(0.5,two1n1nW1W1,dM11);   
5591   }
5592   if(dM22)
5593   {
5594    two2n2nW2W2 = (pow(dReQ2n2k,2)+pow(dImQ2n2k,2)-(*fSpk)(0,4))/dM22; 
5595    // ...
5596    // average correlation <w1^2 w2^2 cos(2n*(phi1-phi2))> for all events:
5597    fIntFlowCorrelationsAllPro->Fill(1.5,two2n2nW2W2,dM22);   
5598   }
5599   if(dM33)
5600   {
5601    two3n3nW3W3 = (pow(dReQ3n3k,2)+pow(dImQ3n3k,2)-(*fSpk)(0,6))/dM33;
5602    // ...
5603    // average correlation <w1^3 w2^3 cos(3n*(phi1-phi2))> for all events:
5604    fIntFlowCorrelationsAllPro->Fill(2.5,two3n3nW3W3,dM33);   
5605   }
5606   if(dM44)
5607   {
5608    two4n4nW4W4 = (pow(dReQ4n4k,2)+pow(dImQ4n4k,2)-(*fSpk)(0,8))/dM44; 
5609    // ...
5610    // average correlation <w1^4 w2^4 cos(4n*(phi1-phi2))> for all events:
5611    fIntFlowCorrelationsAllPro->Fill(3.5,two4n4nW4W4,dM44);      
5612   }
5613  } // end of if(dMult>1) 
5614
5615  // extra 2-particle correlations:
5616  Double_t two1n1nW3W1 = 0.; // <w1^3 w2 cos(n*(phi1-phi2))>
5617  Double_t two1n1nW1W1W2 = 0.; // <w1 w2 w3^2 cos(n*(phi1-phi2))> 
5618  if(dMult>1) 
5619  {    
5620   if(dM31)
5621   {
5622    two1n1nW3W1 = (dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k-(*fSpk)(0,4))/dM31; 
5623    fIntFlowExtraCorrelationsPro->Fill(0.5,two1n1nW3W1,dM31);  
5624   } 
5625   if(dM211)
5626   {
5627    two1n1nW1W1W2 = ((*fSpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSpk)(0,2))
5628                  - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k
5629                  - (*fSpk)(0,4)))/dM211;
5630    fIntFlowExtraCorrelationsPro->Fill(1.5,two1n1nW1W1W2,dM211);  
5631   }  
5632  } // end of if(dMult>1)
5633  //..............................................................................................
5634  
5635  //..............................................................................................
5636  // 3-particle correlations:
5637  Double_t three2n1n1nW2W1W1 = 0.; // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
5638  
5639  if(dMult>2) 
5640  { 
5641   if(dM211)
5642   {                                                       
5643    three2n1n1nW2W1W1 = (pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k
5644                      - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
5645                      - pow(dReQ2n2k,2)-pow(dImQ2n2k,2)
5646                      + 2.*(*fSpk)(0,4))/dM211;                                                                               
5647    fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1nW2W1W1,dM211);
5648   } 
5649  } // end of if(dMult>2) 
5650  //..............................................................................................
5651  
5652  //..............................................................................................
5653  // 4-particle correlations:
5654  Double_t four1n1n1n1nW1W1W1W1 = 0.; // <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
5655  if(dMult>3) 
5656  { 
5657   if(dM1111)
5658   {      
5659    four1n1n1n1nW1W1W1W1 = (pow(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.),2)
5660                         - 2.*(pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k)
5661                         + 8.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
5662                         + (pow(dReQ2n2k,2)+pow(dImQ2n2k,2))
5663                         - 4.*(*fSpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
5664                         - 6.*(*fSpk)(0,4)+2.*(*fSpk)(1,2))/dM1111;  
5665                           
5666    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for single event: 
5667    fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1nW1W1W1W1);
5668    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,dM1111);
5669    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
5670    fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1,dM1111);   
5671    // average squared correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
5672    fIntFlowSquaredCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1*four1n1n1n1nW1W1W1W1,dM1111);      
5673    fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1nW1W1W1W1,dM1111);   
5674   } 
5675  } // end of if(dMult>3) 
5676  //..............................................................................................
5677  
5678 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
5679
5680 //================================================================================================================================
5681
5682 void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
5683 {
5684  // Initialize all arrays used to calculate integrated flow.
5685  
5686  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5687  {
5688   fIntFlowCorrectionTermsForNUAEBE[sc] = NULL;
5689   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc] = NULL;
5690   fIntFlowCorrectionTermsForNUAPro[sc] = NULL;
5691   fIntFlowCorrectionTermsForNUAHist[sc] = NULL;
5692   for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
5693   {
5694    fIntFlowCorrectionTermsForNUAVsMPro[sc][ci] = NULL;
5695   }
5696   for(Int_t power=0;power<2;power++) // linear or quadratic 
5697   {
5698    fIntFlowSumOfEventWeightsNUA[sc][power] = NULL;
5699   }
5700  }
5701  for(Int_t power=0;power<2;power++) // linear or quadratic 
5702  {
5703   fIntFlowSumOfEventWeights[power] = NULL;    
5704  }
5705  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))
5706  {
5707   fPrintFinalResults[i] = kTRUE;
5708  }
5709  for(Int_t ci=0;ci<4;ci++) // correlation index or cumulant order
5710  {
5711   fIntFlowCorrelationsVsMPro[ci] = NULL;
5712   fIntFlowSquaredCorrelationsVsMPro[ci] = NULL;
5713   fIntFlowCorrelationsVsMHist[ci] = NULL;
5714   fIntFlowQcumulantsVsM[ci] = NULL;
5715   fIntFlowVsM[ci] = NULL;
5716   fIntFlowDetectorBiasVsM[ci] = NULL;
5717   for(Int_t lc=0;lc<2;lc++)
5718   {
5719    fIntFlowSumOfEventWeightsVsM[ci][lc] = NULL;
5720   }
5721  } 
5722  for(Int_t pi=0;pi<6;pi++) // product or covariance index
5723  {
5724   fIntFlowProductOfCorrelationsVsMPro[pi] = NULL;
5725   fIntFlowCovariancesVsM[pi] = NULL;
5726   fIntFlowSumOfProductOfEventWeightsVsM[pi] = NULL;
5727  } 
5728  for(Int_t ci=0;ci<64;ci++) // correlation index for all correlations vs M profiles (to be improved - hardwired 64)
5729  {
5730   fIntFlowCorrelationsAllVsMPro[ci] = NULL;
5731  } 
5732
5733 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
5734
5735 //================================================================================================================================
5736
5737 void AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5738 {
5739  // Initialize all arrays needed to calculate differential flow.
5740  //  a) Initialize lists holding profiles;
5741  //  b) Initialize lists holding histograms;
5742  //  c) Initialize event-by-event quantities;
5743  //  d) Initialize profiles;
5744  //  e) Initialize histograms holding final results.
5745  
5746  // a) Initialize lists holding profiles;
5747  for(Int_t t=0;t<2;t++) // type (RP, POI)
5748  {
5749   for(Int_t pe=0;pe<2;pe++) // pt or eta
5750   {
5751    fDiffFlowCorrelationsProList[t][pe] = NULL;
5752    fDiffFlowProductOfCorrelationsProList[t][pe] = NULL;
5753    fDiffFlowCorrectionsProList[t][pe] = NULL;
5754   }
5755   // 2D:
5756   f2DDiffFlowCorrelationsProList[t] = NULL;
5757  }  
5758  
5759  // b) Initialize lists holding histograms;
5760  for(Int_t t=0;t<2;t++) // type (RP, POI)
5761  {
5762   for(Int_t pe=0;pe<2;pe++) // pt or eta
5763   {
5764    fDiffFlowCorrelationsHistList[t][pe] = NULL;
5765    for(Int_t power=0;power<2;power++)
5766    {
5767     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = NULL;
5768    } // end of for(Int_t power=0;power<2;power++)  
5769    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = NULL;
5770    fDiffFlowCorrectionsHistList[t][pe] = NULL;
5771    fDiffFlowCovariancesHistList[t][pe] = NULL;
5772    fDiffFlowCumulantsHistList[t][pe] = NULL;
5773    fDiffFlowDetectorBiasHistList[t][pe] = NULL;
5774    fDiffFlowHistList[t][pe] = NULL;
5775   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5776  } // enf of for(Int_t t=0;t<2;t++) // type (RP, POI) 
5777  
5778  // c) Initialize event-by-event quantities:
5779  // 1D:
5780  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5781  {
5782   for(Int_t pe=0;pe<2;pe++) // pt or eta
5783   { 
5784    for(Int_t m=0;m<4;m++) // multiple of harmonic
5785    {
5786     for(Int_t k=0;k<9;k++) // power of weight
5787     {
5788      fReRPQ1dEBE[t][pe][m][k] = NULL;
5789      fImRPQ1dEBE[t][pe][m][k] = NULL;
5790      fs1dEBE[t][pe][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5791     }   
5792    }
5793   }
5794  }
5795  // 1D:
5796  for(Int_t t=0;t<2;t++) // type (RP or POI)
5797  {
5798   for(Int_t pe=0;pe<2;pe++) // pt or eta
5799   { 
5800    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5801    {
5802     for(Int_t cti=0;cti<9;cti++) // correction term index
5803     {
5804      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = NULL;
5805     }   
5806    }
5807   }
5808  }
5809  // 2D:  
5810  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
5811  {
5812   for(Int_t m=0;m<4;m++) // multiple of harmonic
5813   {
5814    for(Int_t k=0;k<9;k++) // power of weight
5815    {
5816     fReRPQ2dEBE[t][m][k] = NULL;
5817     fImRPQ2dEBE[t][m][k] = NULL;
5818     fs2dEBE[t][k] = NULL; // to be improved (this doesn't need to be within loop over m)
5819    }   
5820   }
5821  }
5822  
5823  // d) Initialize profiles:
5824  for(Int_t t=0;t<2;t++) // type: RP or POI
5825  { 
5826   for(Int_t pe=0;pe<2;pe++) // pt or eta
5827   {
5828    for(Int_t ci=0;ci<4;ci++) // correlation index
5829    {
5830     fDiffFlowCorrelationsPro[t][pe][ci] = NULL;
5831     fDiffFlowSquaredCorrelationsPro[t][pe][ci] = NULL;
5832    } // end of for(Int_t ci=0;ci<4;ci++)   
5833    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5834    {
5835     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5836     {
5837      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = NULL;
5838     } // end of for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5839    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index  
5840    // correction terms for nua:
5841    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5842    {
5843     for(Int_t cti=0;cti<9;cti++) // correction term index
5844     {
5845      fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = NULL;
5846     }   
5847    }
5848    // other differential correlators:
5849    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5850    {
5851     for(Int_t ci=0;ci<1;ci++) // correction term index
5852     {
5853      fOtherDiffCorrelators[t][pe][sc][ci] = NULL;
5854     }   
5855    }
5856   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5857   for(Int_t ci=0;ci<4;ci++) // correlation index
5858   {
5859    f2DDiffFlowCorrelationsPro[t][ci] = NULL;
5860   }
5861  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5862   
5863  // e) Initialize histograms holding final results.
5864  for(Int_t t=0;t<2;t++) // type: RP or POI
5865  { 
5866   for(Int_t pe=0;pe<2;pe++) // pt or eta
5867   {
5868    for(Int_t ci=0;ci<4;ci++) // correlation index
5869    {
5870     fDiffFlowCorrelationsHist[t][pe][ci] = NULL;
5871     fDiffFlowCumulants[t][pe][ci] = NULL;
5872     fDiffFlowDetectorBias[t][pe][ci] = NULL;
5873     fDiffFlow[t][pe][ci] = NULL;
5874    } // end of for(Int_t ci=0;ci<4;ci++)    
5875    for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5876    {
5877     fDiffFlowCovariances[t][pe][covarianceIndex] = NULL;     
5878    } // end of for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
5879    // correction terms for nua:
5880    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5881    {
5882     for(Int_t cti=0;cti<9;cti++) // correction term index
5883     {
5884      fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = NULL;
5885     }   
5886    }
5887   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
5888   for(Int_t ci=0;ci<4;ci++) // correlation index
5889   {
5890    f2DDiffFlowCumulants[t][ci] = NULL;
5891    f2DDiffFlow[t][ci] = NULL;
5892   }
5893  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
5894  
5895  // sum of event weights for reduced correlations:
5896  for(Int_t t=0;t<2;t++) // type = RP or POI
5897  {
5898   for(Int_t pe=0;pe<2;pe++) // pt or eta
5899   {
5900    for(Int_t p=0;p<2;p++) // power of weight is 1 or 2
5901    {
5902     for(Int_t ew=0;ew<4;ew++) // event weight index for reduced correlations
5903     {
5904      fDiffFlowSumOfEventWeights[t][pe][p][ew] = NULL;
5905     } 
5906    }   
5907   }
5908  }
5909  // product of event weights for both types of correlations:
5910  for(Int_t t=0;t<2;t++) // type = RP or POI
5911  {
5912   for(Int_t pe=0;pe<2;pe++) // pt or eta
5913   {
5914    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
5915    {
5916     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
5917     {
5918      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = NULL;
5919     } 
5920    }   
5921   }
5922  }
5923     
5924 } // end of AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5925
5926 //================================================================================================================================
5927
5928 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, TString ptOrEta)
5929 {
5930  // Calculate differential flow cumulants from measured multiparticle correlations.
5931  
5932  // REMARK: Cumulants calculated in this method are NOT corrected for non-uniform acceptance. 
5933  // This correction, if enabled via setter SetApplyCorrectionForNUA(Bool_t), is applied 
5934  // in the method CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
5935  
5936  Int_t t = 0;
5937  Int_t pe = 0;
5938
5939  if(type == "RP")
5940  {
5941   t = 0;
5942  } else if(type == "POI")
5943    {
5944     t = 1;
5945    } 
5946      
5947  if(ptOrEta == "Pt")
5948  {
5949   pe = 0;
5950  } else if(ptOrEta == "Eta")
5951    {
5952     pe = 1;
5953    } 
5954      
5955  // Common:
5956  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5957  
5958  // Correlation <<2>>: 
5959  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
5960  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
5961  
5962  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5963  {
5964   // Reduced correlations:   
5965   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
5966   Double_t twoPrimeError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b); // stat. error of <<2'>>
5967   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
5968   Double_t fourPrimeError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b); // stat. error of <<4'>>
5969   // Covariances:
5970   Double_t wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b); // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
5971   Double_t wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b); // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
5972   Double_t wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b); // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
5973   // QC{2'}:
5974   Double_t qc2Prime = twoPrime; // QC{2'}
5975   Double_t qc2PrimeError = twoPrimeError; // stat. error of QC{2'}
5976   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime); 
5977   fDiffFlowCumulants[t][pe][0]->SetBinError(b,qc2PrimeError); 
5978   // QC{4'}:
5979   Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5980   Double_t qc4PrimeError = 0.; // stat. error of QC{4'}
5981   Double_t qc4PrimeErrorSquared = 4.*pow(twoPrime,2.)*pow(twoError,2.)
5982                                 + 4.*pow(two,2.)*pow(twoPrimeError,2.)
5983                                 + pow(fourPrimeError,2.)
5984                                 + 8.*two*twoPrime*wCovTwoTwoReduced
5985                                 - 4.*twoPrime*wCovTwoFourReduced
5986                                 - 4.*two*wCovTwoReducedFourReduced;
5987   if(qc4PrimeErrorSquared>0.)
5988   {
5989    qc4PrimeError = pow(qc4PrimeErrorSquared,0.5);
5990   } 
5991   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime); 
5992   fDiffFlowCumulants[t][pe][1]->SetBinError(b,qc4PrimeError); 
5993  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5994     
5995 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, Bool_t useParticleWeights, TString eventWeights); 
5996
5997 //================================================================================================================================
5998
5999 void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCumulants(TString type)
6000 {
6001  // Calculate 2D differential cumulants.
6002  
6003  // Remark: correction for detector effects and error propagation not implemented yet for 2D differential cumulants.
6004  
6005  Int_t t = 0;
6006
6007  if(type == "RP")
6008  {
6009   t = 0;
6010  } else if(type == "POI")
6011    {
6012     t = 1;
6013    }
6014        
6015  // Reference correlation <<2>>: 
6016  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
6017  
6018  // Looping over all (pt,eta) bins and calculating differential flow cumulants: 
6019  for(Int_t p=1;p<=fnBinsPt;p++)
6020  {
6021   for(Int_t e=1;e<=fnBinsEta;e++)
6022   {
6023    // Reduced correlations:   
6024    Double_t twoPrime = f2DDiffFlowCorrelationsPro[t][0]->GetBinContent(f2DDiffFlowCorrelationsPro[t][0]->GetBin(p,e)); // <<2'>>(pt,eta)
6025    Double_t fourPrime = f2DDiffFlowCorrelationsPro[t][1]->GetBinContent(f2DDiffFlowCorrelationsPro[t][1]->GetBin(p,e)); // <<4'>>(pt,eta)
6026    // Cumulants:
6027    Double_t qc2Prime = twoPrime; // QC{2'} = <<2'>>   
6028    f2DDiffFlowCumulants[t][0]->SetBinContent(f2DDiffFlowCumulants[t][0]->GetBin(p,e),qc2Prime); 
6029    Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
6030    f2DDiffFlowCumulants[t][1]->SetBinContent(f2DDiffFlowCumulants[t][1]->GetBin(p,e),qc4Prime); 
6031   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
6032  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
6033  
6034 } // end of void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCumulants(TString type)
6035
6036 //================================================================================================================================
6037
6038 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
6039 {
6040  // Calculate final results for integrated flow of RPs and POIs. 
6041   
6042  // to be improved - check if the integrated flow calculation here is actually correct 
6043   
6044  Int_t t = 0; // RP = 0, POI = 1
6045
6046  if(type == "RP")
6047  {
6048   t = 0;
6049  } else if(type == "POI")
6050    {
6051     t = 1;
6052    }
6053      
6054  // pt yield:    
6055  TH1F *yield2ndPt = NULL;
6056  TH1F *yield4thPt = NULL;
6057  TH1F *yield6thPt = NULL;
6058  TH1F *yield8thPt = NULL;
6059  
6060  if(type == "POI")
6061  {
6062   if(fFillMultipleControlHistograms)
6063   {
6064    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtPOI())->Clone();
6065    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtPOI())->Clone();
6066    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtPOI())->Clone();
6067    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtPOI())->Clone();  
6068   } else
6069     {
6070      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
6071      yield4thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
6072      yield6thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();
6073      yield8thPt = (TH1F*)(fCommonHists->GetHistPtPOI())->Clone();     
6074     }
6075  } 
6076  else if(type == "RP")
6077  {
6078   if(fFillMultipleControlHistograms)
6079   {
6080    yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtRP())->Clone();
6081    yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtRP())->Clone();
6082    yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtRP())->Clone();
6083    yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtRP())->Clone();  
6084   } else
6085     {
6086      yield2ndPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
6087      yield4thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
6088      yield6thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();
6089      yield8thPt = (TH1F*)(fCommonHists->GetHistPtRP())->Clone();    
6090     } 
6091  } 
6092  
6093  if(!yield2ndPt){return;}
6094  if(!yield4thPt){return;}
6095  if(!yield6thPt){return;}
6096  if(!yield8thPt){return;} 
6097
6098  Int_t nBinsPt = yield2ndPt->GetNbinsX();
6099  
6100  TH1D *flow2ndPt = NULL;
6101  TH1D *flow4thPt = NULL;
6102  TH1D *flow6thPt = NULL;
6103  TH1D *flow8thPt = NULL;
6104  
6105  // to be improved (hardwired pt index)
6106  flow2ndPt = (TH1D*)fDiffFlow[t][0][0]->Clone();
6107  flow4thPt = (TH1D*)fDiffFlow[t][0][1]->Clone();
6108  flow6thPt = (TH1D*)fDiffFlow[t][0][2]->Clone();
6109  flow8thPt = (TH1D*)fDiffFlow[t][0][3]->Clone(); 
6110
6111  if(!flow2ndPt){return;}
6112  if(!flow4thPt){return;}
6113  if(!flow6thPt){return;}
6114  if(!flow8thPt){return;} 
6115    
6116  Double_t dvn2nd = 0., dvn4th = 0., dvn6th = 0., dvn8th = 0.; // differential flow
6117  Double_t dErrvn2nd = 0., dErrvn4th = 0., dErrvn6th = 0., dErrvn8th = 0.; // error on differential flow
6118  
6119  Double_t dVn2nd = 0., dVn4th = 0., dVn6th = 0., dVn8th = 0.; // integrated flow 
6120  Double_t dErrVn2nd = 0., dErrVn4th = 0., dErrVn6th = 0., dErrVn8th = 0.; // error on integrated flow
6121
6122  Double_t dYield2nd = 0., dYield4th = 0., dYield6th = 0., dYield8th = 0.; // pt yield 
6123  Double_t dSum2nd = 0., dSum4th = 0., dSum6th = 0., dSum8th = 0.; // needed for normalizing integrated flow
6124  
6125  // looping over pt bins:
6126  for(Int_t p=1;p<nBinsPt+1;p++)
6127  {
6128   dvn2nd = flow2ndPt->GetBinContent(p);
6129   dvn4th = flow4thPt->GetBinContent(p);
6130   dvn6th = flow6thPt->GetBinContent(p);
6131   dvn8th = flow8thPt->GetBinContent(p);
6132   
6133   dErrvn2nd = flow2ndPt->GetBinError(p);
6134   dErrvn4th = flow4thPt->GetBinError(p);
6135   dErrvn6th = flow6thPt->GetBinError(p);
6136   dErrvn8th = flow8thPt->GetBinError(p);
6137
6138   dYield2nd = yield2ndPt->GetBinContent(p);  
6139   dYield4th = yield4thPt->GetBinContent(p);
6140   dYield6th = yield6thPt->GetBinContent(p);
6141   dYield8th = yield8thPt->GetBinContent(p);
6142   
6143   dVn2nd += dvn2nd*dYield2nd;
6144   dVn4th += dvn4th*dYield4th;
6145   dVn6th += dvn6th*dYield6th;
6146   dVn8th += dvn8th*dYield8th;
6147   
6148   dSum2nd += dYield2nd;
6149   dSum4th += dYield4th;
6150   dSum6th += dYield6th;
6151   dSum8th += dYield8th;
6152   
6153   dErrVn2nd += dYield2nd*dYield2nd*dErrvn2nd*dErrvn2nd; // ro be improved (check this relation)
6154   dErrVn4th += dYield4th*dYield4th*dErrvn4th*dErrvn4th;
6155   dErrVn6th += dYield6th*dYield6th*dErrvn6th*dErrvn6th;
6156   dErrVn8th += dYield8th*dYield8th*dErrvn8th*dErrvn8th;
6157     
6158  } // end of for(Int_t p=1;p<nBinsPt+1;p++)
6159
6160  // normalizing the results for integrated flow:
6161  if(dSum2nd) 
6162  {
6163   dVn2nd /= dSum2nd;
6164   dErrVn2nd /= (dSum2nd*dSum2nd);
6165   dErrVn2nd = TMath::Sqrt(dErrVn2nd);
6166  } 
6167  if(dSum4th) 
6168  {
6169   dVn4th /= dSum4th;
6170   dErrVn4th /= (dSum4th*dSum4th);
6171   dErrVn4th = TMath::Sqrt(dErrVn4th);
6172  } 
6173  //if(dSum6th) dVn6th/=dSum6th;
6174  //if(dSum8th) dVn8th/=dSum8th;
6175   
6176  // storing the results for integrated flow in common histos: (to be improved: new method for this?)
6177  if(type == "POI")
6178  {
6179   fCommonHistsResults2nd->FillIntegratedFlowPOI(dVn2nd,dErrVn2nd); 
6180   fCommonHistsResults4th->FillIntegratedFlowPOI(dVn4th,dErrVn4th); 
6181   fCommonHistsResults6th->FillIntegratedFlowPOI(dVn6th,0.); // to be improved (errors)
6182   fCommonHistsResults8th->FillIntegratedFlowPOI(dVn8th,0.); // to be improved (errors)
6183  }
6184  else if (type == "RP")
6185  {
6186   fCommonHistsResults2nd->FillIntegratedFlowRP(dVn2nd,dErrVn2nd); 
6187   fCommonHistsResults4th->FillIntegratedFlowRP(dVn4th,dErrVn4th);
6188   fCommonHistsResults6th->FillIntegratedFlowRP(dVn6th,0.); // to be improved (errors)
6189   fCommonHistsResults8th->FillIntegratedFlowRP(dVn8th,0.); // to be improved (errors)
6190  }
6191  
6192  delete flow2ndPt;
6193  delete flow4thPt;
6194  //delete flow6thPt;
6195  //delete flow8thPt;
6196  
6197  delete yield2ndPt;
6198  delete yield4thPt;
6199  delete yield6thPt;
6200  delete yield8thPt;
6201            
6202 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
6203
6204 //================================================================================================================================
6205
6206 void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
6207 {
6208  // Initialize all arrays used for distributions.
6209  
6210  // a) Initialize arrays of histograms used to hold distributions of correlations; 
6211  // b) Initialize array to hold min and max values of correlations.
6212  
6213  // a) Initialize arrays of histograms used to hold distributions of correlations:
6214  for(Int_t di=0;di<4;di++) // distribution index
6215  {
6216   fDistributions[di] = NULL;
6217  }
6218  
6219  // b) Initialize default min and max values of correlations:
6220  //    (Remark: The default values bellow were chosen for v2=5% and M=500)
6221  fMinValueOfCorrelation[0] = -0.01; // <2>_min 
6222  fMaxValueOfCorrelation[0] = 0.04; // <2>_max 
6223  fMinValueOfCorrelation[1] = -0.00002; // <4>_min 
6224  fMaxValueOfCorrelation[1] = 0.00015; // <4>_max  
6225  fMinValueOfCorrelation[2] = -0.0000003; // <6>_min 
6226  fMaxValueOfCorrelation[2] = 0.0000006; // <6>_max  
6227  fMinValueOfCorrelation[3] = -0.000000006; // <8>_min 
6228  fMaxValueOfCorrelation[3] = 0.000000003; // <8>_max 
6229  
6230 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
6231
6232 //================================================================================================================================
6233
6234 void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
6235 {
6236  // Initialize all arrays used for various unclassified objects.
6237  
6238  for(Int_t p=0;p<4;p++) // [v_min,v_max,refMult_min,refMult_max]
6239  {
6240   fPhiDistributionForOneEventSettings[p] = 0.;
6241  } 
6242    
6243 } //  end of void AliFlowAnalysisWithQCumulants::InitializeArraysForVarious()
6244
6245 //================================================================================================================================
6246
6247 void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
6248 {
6249  // a) Book profile to hold all flags for distributions of correlations;
6250  // b) Book all histograms to hold distributions of correlations.
6251  
6252  TString correlationIndex[4] = {"<2>","<4>","<6>","<8>"}; // to be improved (should I promote this to data members?)
6253   
6254  // a) Book profile to hold all flags for distributions of correlations:
6255  TString distributionsFlagsName = "fDistributionsFlags";
6256  distributionsFlagsName += fAnalysisLabel->Data();
6257  fDistributionsFlags = new TProfile(distributionsFlagsName.Data(),"Flags for Distributions of Correlations",9,0,9);
6258  fDistributionsFlags->SetTickLength(-0.01,"Y");
6259  fDistributionsFlags->SetMarkerStyle(25);
6260  fDistributionsFlags->SetLabelSize(0.05);
6261  fDistributionsFlags->SetLabelOffset(0.02,"Y");
6262  fDistributionsFlags->GetXaxis()->SetBinLabel(1,"Store or not?");
6263  fDistributionsFlags->GetXaxis()->SetBinLabel(2,"<2>_{min}");
6264  fDistributionsFlags->GetXaxis()->SetBinLabel(3,"<2>_{max}");
6265  fDistributionsFlags->GetXaxis()->SetBinLabel(4,"<4>_{min}");
6266  fDistributionsFlags->GetXaxis()->SetBinLabel(5,"<4>_{max}");
6267  fDistributionsFlags->GetXaxis()->SetBinLabel(6,"<6>_{min}");
6268  fDistributionsFlags->GetXaxis()->SetBinLabel(7,"<6>_{max}");
6269  fDistributionsFlags->GetXaxis()->SetBinLabel(8,"<8>_{min}");
6270  fDistributionsFlags->GetXaxis()->SetBinLabel(9,"<8>_{max}");
6271  fDistributionsList->Add(fDistributionsFlags);
6272  
6273  // b) Book all histograms to hold distributions of correlations.
6274  if(fStoreDistributions)
6275  { 
6276   TString distributionsName = "fDistributions";
6277   distributionsName += fAnalysisLabel->Data();
6278   for(Int_t di=0;di<4;di++) // distribution index
6279   {
6280    fDistributions[di] = new TH1D(Form("Distribution of %s",correlationIndex[di].Data()),Form("Distribution of %s",correlationIndex[di].Data()),10000,fMinValueOfCorrelation[di],fMaxValueOfCorrelation[di]); 
6281    fDistributions[di]->SetXTitle(correlationIndex[di].Data());
6282    fDistributionsList->Add(fDistributions[di]);
6283   } // end of for(Int_t di=0;di<4;di++) // distribution index
6284  } // end of if(fStoreDistributions)
6285  
6286 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
6287
6288 //================================================================================================================================
6289
6290 void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6291 {
6292  // Book all objects for various unclassified quantities.
6293  
6294  if(!fStorePhiDistributionForOneEvent){return;}
6295  
6296  // a) Book histogram holding phi distribution for single event to illustrate flow.
6297  
6298  // a) Book histogram holding phi distribution for single event to illustrate flow:
6299  fPhiDistributionForOneEvent = new TH1D("fPhiDistributionForOneEvent","",360,0.,TMath::TwoPi());
6300  fPhiDistributionForOneEvent->GetXaxis()->SetTitle("#phi");
6301  fVariousList->Add(fPhiDistributionForOneEvent);
6302  
6303 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForVarious()
6304
6305 //================================================================================================================================
6306
6307 void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6308 {
6309  // Store all flags for distributiuons of correlations in profile fDistributionsFlags.
6310  
6311  if(!fDistributionsFlags)
6312  {
6313   cout<<"WARNING: fDistributionsFlags is NULL in AFAWQC::SDF() !!!!"<<endl;
6314   exit(0);
6315  } 
6316
6317  fDistributionsFlags->Fill(0.5,(Int_t)fStoreDistributions); // histos with distributions of correlations stored or not in the output file
6318  // store min and max values of correlations:
6319  for(Int_t di=0;di<4;di++) // distribution index
6320  {
6321   fDistributionsFlags->Fill(1.5+2.*(Double_t)di,fMinValueOfCorrelation[di]);
6322   fDistributionsFlags->Fill(2.5+2.*(Double_t)di,fMaxValueOfCorrelation[di]);
6323  }
6324      
6325 } // end of void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
6326
6327 //================================================================================================================================
6328
6329 void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6330 {
6331  // Store distributions of correlations.
6332  
6333  if(!(fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE))
6334  {
6335   cout<<"WARNING: fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE"<<endl; 
6336   cout<<"         is NULL in AFAWQC::SDOC() !!!!"<<endl;
6337   exit(0);
6338  }
6339
6340  for(Int_t di=0;di<4;di++) // distribution index
6341  {
6342   if(!fDistributions[di])
6343   { 
6344    cout<<"WARNING: fDistributions[di] is NULL in AFAWQC::SDOC() !!!!"<<endl;
6345    cout<<"di = "<<di<<endl;
6346    exit(0);
6347   } else 
6348     {
6349      fDistributions[di]->Fill(fIntFlowCorrelationsEBE->GetBinContent(di+1),fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(di+1)); 
6350     } 
6351  } // end of for(Int_t di=0;di<4;di++) // distribution index
6352
6353 } // end of void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
6354
6355 //================================================================================================================================
6356
6357 void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6358 {
6359  // Book and nest all lists nested in the base list fHistList.
6360  //  a) Book and nest lists for integrated flow;
6361  //  b) Book and nest lists for differential flow;
6362  //  c) Book and nest list for particle weights;
6363  //  d) Book and nest list for distributions;
6364  //  e) Book and nest list for various unclassified objects; 
6365  //  f) Book and nest list for nested loops.
6366  
6367  // a) Book and nest all lists for integrated flow:
6368  //  Base list for integrated flow:
6369  fIntFlowList = new TList();
6370  fIntFlowList->SetName("Integrated Flow");
6371  fIntFlowList->SetOwner(kTRUE);
6372  fHistList->Add(fIntFlowList);
6373  //  List holding profiles: 
6374  fIntFlowProfiles = new TList();
6375  fIntFlowProfiles->SetName("Profiles");
6376  fIntFlowProfiles->SetOwner(kTRUE);
6377  fIntFlowList->Add(fIntFlowProfiles);
6378  //  List holding all profiles with results for correlations vs M:
6379  if(fCalculateAllCorrelationsVsM)
6380  {
6381   fIntFlowAllCorrelationsVsM = new TList();
6382   fIntFlowAllCorrelationsVsM->SetName("Correlations vs M");
6383   fIntFlowAllCorrelationsVsM->SetOwner(kTRUE); 
6384   fIntFlowProfiles->Add(fIntFlowAllCorrelationsVsM);
6385  } // end of if(fCalculateAllCorrelationsVsM)
6386  //  List holding histograms with results:
6387  fIntFlowResults = new TList();
6388  fIntFlowResults->SetName("Results");
6389  fIntFlowResults->SetOwner(kTRUE);
6390  fIntFlowList->Add(fIntFlowResults);
6391  
6392  // b) Book and nest lists for differential flow:
6393  this->BookAndNestListsForDifferentialFlow();
6394  
6395  // c) Book and nest list for particle weights:
6396  fWeightsList->SetName("Weights");
6397  fWeightsList->SetOwner(kTRUE);   
6398  fHistList->Add(fWeightsList); 
6399
6400  // d) Book and nest list for distributions:
6401  fDistributionsList = new TList();
6402  fDistributionsList->SetName("Distributions");
6403  fDistributionsList->SetOwner(kTRUE);
6404  fHistList->Add(fDistributionsList);
6405  
6406  // e) Book and nest list for various unclassified objects:
6407  if(fStorePhiDistributionForOneEvent)
6408  {
6409   fVariousList = new TList();
6410   fVariousList->SetName("Various");
6411   fVariousList->SetOwner(kTRUE);
6412   fHistList->Add(fVariousList);
6413  }
6414   
6415  // f) Book and nest list for other differential correlators:
6416  fOtherDiffCorrelatorsList = new TList();
6417  fOtherDiffCorrelatorsList->SetName("Other differential correlators");
6418  fOtherDiffCorrelatorsList->SetOwner(kTRUE);
6419  if(fCalculateDiffFlow){fHistList->Add(fOtherDiffCorrelatorsList);} // TBI: Use another flag here instead of fCalculateDiffFlow 
6420   
6421  // g) Book and nest list for nested loops:
6422  fNestedLoopsList = new TList();
6423  fNestedLoopsList->SetName("Nested Loops");
6424  fNestedLoopsList->SetOwner(kTRUE);
6425  fHistList->Add(fNestedLoopsList);
6426  
6427 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6428
6429 //================================================================================================================================
6430
6431 void AliFlowAnalysisWithQCumulants::BookAndNestListsForDifferentialFlow()
6432 {
6433  // Book and nest lists for differential flow.
6434
6435  // Base list for differential flow objects:
6436  fDiffFlowList = new TList();
6437  fDiffFlowList->SetName("Differential Flow");
6438  fDiffFlowList->SetOwner(kTRUE); 
6439  fHistList->Add(fDiffFlowList);
6440  
6441  // Local flags: 
6442  TString typeFlag[2] = {"RP","POI"};  
6443  TString ptEtaFlag[2] = {"p_{T}","#eta"}; 
6444  TString powerFlag[2] = {"linear","quadratic"};   
6445
6446  // 2D:
6447  if(fCalculate2DDiffFlow)
6448  {
6449   fDiffFlow2D = new TList(); 
6450   fDiffFlow2D->SetName("2D");
6451   fDiffFlow2D->SetOwner(kTRUE);
6452   fDiffFlowList->Add(fDiffFlow2D); 
6453   for(Int_t t=0;t<2;t++)
6454   {
6455    f2DDiffFlowCorrelationsProList[t] = new TList();
6456    f2DDiffFlowCorrelationsProList[t]->SetOwner(kTRUE);
6457    f2DDiffFlowCorrelationsProList[t]->SetName(Form("Profiles with 2D correlations (%s)",typeFlag[t].Data()));
6458    fDiffFlow2D->Add(f2DDiffFlowCorrelationsProList[t]);
6459   } // end of for(Int_t t=0;t<2;t++)
6460  } // end of if(fCalculate2DDiffFlow)
6461
6462  // What follows bellow in this method is relevant only for 1D differential flow:
6463  if(!fCalculateDiffFlow){return;}
6464  
6465  // List holding profiles: 
6466  fDiffFlowProfiles = new TList(); 
6467  fDiffFlowProfiles->SetName("Profiles");
6468  fDiffFlowProfiles->SetOwner(kTRUE);
6469  fDiffFlowList->Add(fDiffFlowProfiles);
6470  // List holding histograms with results: 
6471  fDiffFlowResults = new TList();
6472  fDiffFlowResults->SetName("Results");
6473  fDiffFlowResults->SetOwner(kTRUE);
6474  fDiffFlowList->Add(fDiffFlowResults);
6475  // Flags used for naming nested lists in list fDiffFlowProfiles and fDiffFlowResults:  
6476  TList list;
6477  list.SetOwner(kTRUE);
6478  // Nested lists in fDiffFlowProfiles (~/Differential Flow/Profiles):
6479  for(Int_t t=0;t<2;t++) // type: RP or POI
6480  {
6481   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
6482   {
6483    // list holding profiles with correlations:
6484    fDiffFlowCorrelationsProList[t][pe] = (TList*)list.Clone();
6485    fDiffFlowCorrelationsProList[t][pe]->SetName(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6486    fDiffFlowProfiles->Add(fDiffFlowCorrelationsProList[t][pe]);
6487    // list holding profiles with products of correlations:
6488    fDiffFlowProductOfCorrelationsProList[t][pe] = (TList*)list.Clone();
6489    fDiffFlowProductOfCorrelationsProList[t][pe]->SetName(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6490    fDiffFlowProfiles->Add(fDiffFlowProductOfCorrelationsProList[t][pe]);
6491    // list holding profiles with corrections:
6492    fDiffFlowCorrectionsProList[t][pe] = (TList*)list.Clone();
6493    fDiffFlowCorrectionsProList[t][pe]->SetName(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6494    fDiffFlowProfiles->Add(fDiffFlowCorrectionsProList[t][pe]);   
6495   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
6496  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI   
6497  // nested lists in fDiffFlowResults (~/Differential Flow/Results):
6498  for(Int_t t=0;t<2;t++) // type: RP or POI
6499  {
6500   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
6501   {
6502    // list holding histograms with correlations:
6503    fDiffFlowCorrelationsHistList[t][pe] = (TList*)list.Clone();
6504    fDiffFlowCorrelationsHistList[t][pe]->SetName(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6505    fDiffFlowResults->Add(fDiffFlowCorrelationsHistList[t][pe]);
6506    // list holding histograms with corrections:
6507    fDiffFlowCorrectionsHistList[t][pe] = (TList*)list.Clone();
6508    fDiffFlowCorrectionsHistList[t][pe]->SetName(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6509    fDiffFlowResults->Add(fDiffFlowCorrectionsHistList[t][pe]);   
6510    for(Int_t power=0;power<2;power++)
6511    {
6512     // list holding histograms with sums of event weights:
6513     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = (TList*)list.Clone();
6514     fDiffFlowSumOfEventWeightsHistList[t][pe][power]->SetName(Form("Sum of %s event weights (%s, %s)",powerFlag[power].Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6515     fDiffFlowResults->Add(fDiffFlowSumOfEventWeightsHistList[t][pe][power]);    
6516    } // end of for(Int_t power=0;power<2;power++)
6517    // list holding histograms with sums of products of event weights:
6518    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = (TList*)list.Clone();
6519    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->SetName(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6520    fDiffFlowResults->Add(fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]);
6521    // list holding histograms with covariances of correlations:
6522    fDiffFlowCovariancesHistList[t][pe] = (TList*)list.Clone();
6523    fDiffFlowCovariancesHistList[t][pe]->SetName(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6524    fDiffFlowResults->Add(fDiffFlowCovariancesHistList[t][pe]);
6525    // list holding histograms with differential Q-cumulants:
6526    fDiffFlowCumulantsHistList[t][pe] = (TList*)list.Clone();
6527    fDiffFlowCumulantsHistList[t][pe]->SetName(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6528    fDiffFlowResults->Add(fDiffFlowCumulantsHistList[t][pe]);   
6529    // list holding histograms which quantify detector bias to differential Q-cumulants:
6530    fDiffFlowDetectorBiasHistList[t][pe] = (TList*)list.Clone();
6531    fDiffFlowDetectorBiasHistList[t][pe]->SetName(Form("Detector bias (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6532    fDiffFlowResults->Add(fDiffFlowDetectorBiasHistList[t][pe]);   
6533    // list holding histograms with differential flow estimates from Q-cumulants:
6534    fDiffFlowHistList[t][pe] = (TList*)list.Clone();
6535    fDiffFlowHistList[t][pe]->SetName(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6536    fDiffFlowResults->Add(fDiffFlowHistList[t][pe]);      
6537   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6538  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6539   
6540 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestListsForDifferentialFlow()
6541
6542 //================================================================================================================================
6543
6544 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type)
6545 {
6546  // Fill common result histograms for differential flow.
6547  
6548  Int_t t = 0; 
6549
6550  if(type == "RP")
6551  {
6552   t = 0;
6553  } else if(type == "POI")
6554    {
6555     t = 1;
6556    } 
6557   
6558  // to be improved - check all pointers used in this method
6559      
6560  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
6561  {
6562   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
6563   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
6564   exit(0);
6565  }
6566  
6567  // pt:
6568  for(Int_t p=1;p<=fnBinsPt;p++)
6569  {
6570   Double_t v2 = fDiffFlow[t][0][0]->GetBinContent(p);
6571   Double_t v4 = fDiffFlow[t][0][1]->GetBinContent(p);
6572   Double_t v6 = fDiffFlow[t][0][2]->GetBinContent(p);
6573   Double_t v8 = fDiffFlow[t][0][3]->GetBinContent(p);
6574   
6575   Double_t v2Error = fDiffFlow[t][0][0]->GetBinError(p);
6576   Double_t v4Error = fDiffFlow[t][0][1]->GetBinError(p);
6577   //Double_t v6Error = fFinalFlow1D[t][pW][nua][0][2]->GetBinError(p);
6578   //Double_t v8Error = fFinalFlow1D[t][pW][nua][0][3]->GetBinError(p);
6579  
6580   if(type == "RP")
6581   {
6582    fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,v2,v2Error);
6583    fCommonHistsResults4th->FillDifferentialFlowPtRP(p,v4,v4Error);
6584    fCommonHistsResults6th->FillDifferentialFlowPtRP(p,v6,0.);
6585    fCommonHistsResults8th->FillDifferentialFlowPtRP(p,v8,0.);
6586   } else if(type == "POI")
6587     {
6588      fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,v2,v2Error);
6589      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,v4,v4Error);
6590      fCommonHistsResults6th->FillDifferentialFlowPtPOI(p,v6,0.);
6591      fCommonHistsResults8th->FillDifferentialFlowPtPOI(p,v8,0.);
6592     }
6593  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
6594  
6595  // eta:
6596  if(!fCalculateDiffFlowVsEta){return;}
6597  for(Int_t e=1;e<=fnBinsEta;e++)
6598  {
6599   Double_t v2 = fDiffFlow[t][1][0]->GetBinContent(e);
6600   Double_t v4 = fDiffFlow[t][1][1]->GetBinContent(e);
6601   Double_t v6 = fDiffFlow[t][1][2]->GetBinContent(e);
6602   Double_t v8 = fDiffFlow[t][1][3]->GetBinContent(e);
6603   
6604   Double_t v2Error = fDiffFlow[t][1][0]->GetBinError(e);
6605   Double_t v4Error = fDiffFlow[t][1][1]->GetBinError(e);
6606   //Double_t v6Error = fDiffFlow[t][1][2]->GetBinError(e);
6607   //Double_t v8Error = fDiffFlow[t][1][3]->GetBinError(e);
6608  
6609   if(type == "RP")
6610   {
6611    fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,v2,v2Error);
6612    fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,v4,v4Error);
6613    fCommonHistsResults6th->FillDifferentialFlowEtaRP(e,v6,0.);
6614    fCommonHistsResults8th->FillDifferentialFlowEtaRP(e,v8,0.);
6615   } else if(type == "POI")
6616     {
6617      fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,v2,v2Error);
6618      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,v4,v4Error);
6619      fCommonHistsResults6th->FillDifferentialFlowEtaPOI(e,v6,0.);
6620      fCommonHistsResults8th->FillDifferentialFlowEtaPOI(e,v8,0.);
6621     }
6622  } // end of for(Int_t e=1;e<=fnBinsEta;e++)    
6623  
6624 } // end of void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
6625
6626 //================================================================================================================================
6627
6628 void AliFlowAnalysisWithQCumulants::CommonConstants(TString method)
6629 {
6630  // Access and store common constants.
6631  
6632  // a) If this method was called in Init() access common constants from AliFlowCommonConstants;
6633  // b) If this method was called in Init() book and fill TProfile to hold constants accessed in a);
6634  // c) If this method was called in Finish() access common constants from TProfile booked and filled in b).
6635
6636  if(method == "Init")
6637  {
6638   // a) If this method was called in Init() access common constants from AliFlowCommonConstants:
6639   fnBinsPhi = AliFlowCommonConstants::GetMaster()->GetNbinsPhi();
6640   fPhiMin = AliFlowCommonConstants::GetMaster()->GetPhiMin();        
6641   fPhiMax = AliFlowCommonConstants::GetMaster()->GetPhiMax();
6642   if(fnBinsPhi){fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;}  
6643   fnBinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
6644   fPtMin = AliFlowCommonConstants::GetMaster()->GetPtMin();          
6645   fPtMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
6646   if(fnBinsPt){fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;}  
6647   fnBinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
6648   fEtaMin = AliFlowCommonConstants::GetMaster()->GetEtaMin();        
6649   fEtaMax = AliFlowCommonConstants::GetMaster()->GetEtaMax();
6650   if(fnBinsEta){fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;}  
6651   
6652   // b) If this method was called in Init() book and fill TProfile to hold constants accessed in a):
6653   TString fCommonConstantsName = "fCommonConstants";
6654   fCommonConstantsName += fAnalysisLabel->Data();
6655   fCommonConstants = new TProfile(fCommonConstantsName.Data(),"Common constants",9,0.,9.);
6656   fCommonConstants->SetLabelSize(0.05);
6657   fCommonConstants->GetXaxis()->SetBinLabel(1,"nBins (#phi)");
6658   fCommonConstants->Fill(0.5,fnBinsPhi);
6659   fCommonConstants->GetXaxis()->SetBinLabel(2,"#phi_{min}");
6660   fCommonConstants->Fill(1.5,fPhiMin);
6661   fCommonConstants->GetXaxis()->SetBinLabel(3,"#phi_{max}");
6662   fCommonConstants->Fill(2.5,fPhiMax);
6663   fCommonConstants->GetXaxis()->SetBinLabel(4,"nBins (p_{t})");
6664   fCommonConstants->Fill(3.5,fnBinsPt);
6665   fCommonConstants->GetXaxis()->SetBinLabel(5,"(p_{t})_{min}");
6666   fCommonConstants->Fill(4.5,fPtMin);
6667   fCommonConstants->GetXaxis()->SetBinLabel(6,"(p_{t})_{max}");
6668   fCommonConstants->Fill(5.5,fPtMax);
6669   fCommonConstants->GetXaxis()->SetBinLabel(7,"nBins (#eta)");
6670   fCommonConstants->Fill(6.5,fnBinsEta);
6671   fCommonConstants->GetXaxis()->SetBinLabel(8,"#eta_{min}");
6672   fCommonConstants->Fill(7.5,fEtaMin);
6673   fCommonConstants->GetXaxis()->SetBinLabel(9,"#eta_{max}");
6674   fCommonConstants->Fill(8.5,fEtaMax);
6675   fHistList->Add(fCommonConstants); 
6676  } // end of if(method == "Init")
6677  else if(method == "Finish")
6678  {
6679   // c) If this method was called in Finish() access common constants from TProfile booked and filled in b):
6680   if(!fCommonConstants)
6681   {
6682    printf("\n WARNING (QC): fCommonConstants is NULL in AFAWQC::AC(\"%s\") !!!!\n\n",method.Data());
6683    exit(0);
6684   } 
6685   fnBinsPhi = (Int_t)fCommonConstants->GetBinContent(1);
6686   fPhiMin = fCommonConstants->GetBinContent(2);      
6687   fPhiMax = fCommonConstants->GetBinContent(3);
6688   if(fnBinsPhi){fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;}  
6689   fnBinsPt = (Int_t)fCommonConstants->GetBinContent(4);
6690   fPtMin = fCommonConstants->GetBinContent(5);       
6691   fPtMax = fCommonConstants->GetBinContent(6);
6692   if(fnBinsPt){fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;}  
6693   fnBinsEta = (Int_t)fCommonConstants->GetBinContent(7);
6694   fEtaMin = fCommonConstants->GetBinContent(8);      
6695   fEtaMax = fCommonConstants->GetBinContent(9);
6696   if(fnBinsEta){fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;}  
6697  } // end of else if(method == "Finish")
6698
6699 } // end of void AliFlowAnalysisWithQCumulants::CommonConstants(TString method)
6700
6701 //================================================================================================================================
6702
6703 void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6704 {
6705  // a) Cross check if the choice for multiplicity weights make sense.
6706  
6707  // a) Cross check if the choice for multiplicity weights make sense:
6708  if(strcmp(fMultiplicityWeight->Data(),"combinations") && 
6709     strcmp(fMultiplicityWeight->Data(),"unit") &&
6710     strcmp(fMultiplicityWeight->Data(),"multiplicity"))
6711  {
6712   cout<<"WARNING (QC): Multiplicity weight can be either \"combinations\", \"unit\""<<endl;
6713   cout<<"              or \"multiplicity\". Certainly not \""<<fMultiplicityWeight->Data()<<"\"."<<endl;
6714   exit(0);
6715  }   
6716  
6717 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6718
6719 //================================================================================================================================
6720
6721 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6722 {
6723  // Calculate sum of linear and quadratic event weights for correlations.
6724  
6725  // multiplicity:
6726  Double_t dMult = (*fSpk)(0,0);
6727                         
6728  for(Int_t p=0;p<2;p++) // power-1
6729  {
6730   for(Int_t ci=0;ci<4;ci++) // correlation index
6731   { 
6732    fIntFlowSumOfEventWeights[p]->Fill(ci+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); 
6733    if(fCalculateCumulantsVsM)
6734    {
6735     fIntFlowSumOfEventWeightsVsM[ci][p]->Fill(dMult+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); // to be improved: dMult => sum of weights?
6736    }
6737   }
6738  }
6739   
6740 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6741
6742 //================================================================================================================================
6743
6744 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6745 {
6746  // Calculate sum of linear and quadratic event weights for NUA terms.
6747                        
6748  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
6749  {
6750   for(Int_t p=0;p<2;p++) // power-1
6751   {
6752    for(Int_t ci=0;ci<4;ci++) // nua term index
6753    { 
6754     fIntFlowSumOfEventWeightsNUA[sc][p]->Fill(ci+0.5,pow(fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->GetBinContent(ci+1),p+1)); 
6755    }
6756   }
6757  }
6758   
6759 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6760
6761 //================================================================================================================================
6762
6763 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6764 {
6765  // Calculate sum of product of event weights for correlations.
6766   
6767  // multiplicity:
6768  Double_t dMult = (*fSpk)(0,0);
6769   
6770  Int_t counter = 0;
6771  
6772  for(Int_t ci1=1;ci1<4;ci1++)
6773  {
6774   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
6775   {
6776    fIntFlowSumOfProductOfEventWeights->Fill(0.5+counter,
6777                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6778                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6779    if(fCalculateCumulantsVsM)
6780    {                                                                                    
6781     fIntFlowSumOfProductOfEventWeightsVsM[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights?
6782                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6783                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6784    } // end of if(fCalculateCumulantsVsM)
6785    counter++;                                         
6786   }
6787  }
6788
6789 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6790
6791 //================================================================================================================================
6792
6793 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeightsNUA()
6794 {
6795  // Calculate sum of product of event weights for NUA terms.
6796   
6797  // w_{<2>} * w_{<cos(#phi)>}:
6798  fIntFlowSumOfProductOfEventWeightsNUA->Fill(0.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6799                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6800  // w_{<2>} * w_{<sin(#phi)>}:
6801  fIntFlowSumOfProductOfEventWeightsNUA->Fill(1.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6802                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6803  // w_{<cos(#phi)> * w_{<sin(#phi)>}:
6804  fIntFlowSumOfProductOfEventWeightsNUA->Fill(2.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6805                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6806  // w_{<2>} * w{<cos(phi1+phi2)>}
6807  fIntFlowSumOfProductOfEventWeightsNUA->Fill(3.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6808                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6809  // w_{<2>} * w{<sin(phi1+phi2)>}
6810  fIntFlowSumOfProductOfEventWeightsNUA->Fill(4.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6811                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6812  // w_{<2>} * w{<cos(phi1-phi2-phi3)>}
6813  fIntFlowSumOfProductOfEventWeightsNUA->Fill(5.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6814                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6815  // w_{<2>} * w{<sin(phi1-phi2-phi3)>}
6816  fIntFlowSumOfProductOfEventWeightsNUA->Fill(6.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6817                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
6818  // w_{<4>} * w{<cos(phi1)>}
6819  fIntFlowSumOfProductOfEventWeightsNUA->Fill(7.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6820                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6821  // w_{<4>} * w{<sin(phi1)>}
6822  fIntFlowSumOfProductOfEventWeightsNUA->Fill(8.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6823                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6824  // w_{<4>} * w{<cos(phi1+phi2)>}
6825  fIntFlowSumOfProductOfEventWeightsNUA->Fill(9.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6826                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6827  // w_{<4>} * w{<sin(phi1+phi2)>}
6828  fIntFlowSumOfProductOfEventWeightsNUA->Fill(10.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6829                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6830  // w_{<4>} * w{<cos(phi1-phi2-phi3)>}
6831  fIntFlowSumOfProductOfEventWeightsNUA->Fill(11.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6832                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6833  // w_{<4>} * w{<sin(phi1-phi2-phi3)>}
6834  fIntFlowSumOfProductOfEventWeightsNUA->Fill(12.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6835                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6836  // w_{<cos(phi1)>} * w{<cos(phi1+phi2)>}
6837  fIntFlowSumOfProductOfEventWeightsNUA->Fill(13.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6838                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6839  // w_{<cos(phi1)>} * w{<sin(phi1+phi2)>}
6840  fIntFlowSumOfProductOfEventWeightsNUA->Fill(14.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6841                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6842  // w_{<cos(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6843  fIntFlowSumOfProductOfEventWeightsNUA->Fill(15.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6844                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6845  // w_{<cos(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6846  fIntFlowSumOfProductOfEventWeightsNUA->Fill(16.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6847                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6848  // w_{<sin(phi1)>} * w{<cos(phi1+phi2)>}
6849  fIntFlowSumOfProductOfEventWeightsNUA->Fill(17.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6850                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6851  // w_{<sin(phi1)>} * w{<sin(phi1+phi2)>}
6852  fIntFlowSumOfProductOfEventWeightsNUA->Fill(18.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6853                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6854  // w_{<sin(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6855  fIntFlowSumOfProductOfEventWeightsNUA->Fill(19.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6856                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6857  // w_{<sin(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6858  fIntFlowSumOfProductOfEventWeightsNUA->Fill(20.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6859                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6860  // w_{<cos(phi1+phi2)>} * w{<sin(phi1+phi2))>}
6861  fIntFlowSumOfProductOfEventWeightsNUA->Fill(21.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6862                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6863  // w_{<cos(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6864  fIntFlowSumOfProductOfEventWeightsNUA->Fill(22.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6865                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6866  // w_{<cos(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6867  fIntFlowSumOfProductOfEventWeightsNUA->Fill(23.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6868                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6869  // w_{<sin(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6870  fIntFlowSumOfProductOfEventWeightsNUA->Fill(24.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6871                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6872  // w_{<sin(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6873  fIntFlowSumOfProductOfEventWeightsNUA->Fill(25.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6874                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6875  // w_{<cos(phi1-phi2-phi3)>} * w{<sin(phi1-phi2-phi3)>}
6876  fIntFlowSumOfProductOfEventWeightsNUA->Fill(26.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)*
6877                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6878
6879 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowIntFlowSumOfProductOfEventWeightsNUA()
6880
6881 //================================================================================================================================
6882
6883 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta)
6884 {
6885  // Calculate reduced correlations for RPs or POIs for all pt and eta bins.
6886
6887  // Multiplicity:
6888  Double_t dMult = (*fSpk)(0,0);
6889  
6890  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
6891  Double_t dReQ1n = (*fReQ)(0,0);
6892  Double_t dReQ2n = (*fReQ)(1,0);
6893  //Double_t dReQ3n = (*fReQ)(2,0);
6894  //Double_t dReQ4n = (*fReQ)(3,0);
6895  Double_t dImQ1n = (*fImQ)(0,0);
6896  Double_t dImQ2n = (*fImQ)(1,0);
6897  //Double_t dImQ3n = (*fImQ)(2,0);
6898  //Double_t dImQ4n = (*fImQ)(3,0);
6899
6900  // reduced correlations are stored in fDiffFlowCorrelationsPro[0=RP,1=POI][0=pt,1=eta][correlation index]. Correlation index runs as follows:
6901  // 
6902  // 0: <<2'>>
6903  // 1: <<4'>>
6904  // 2: <<6'>>
6905  // 3: <<8'>>
6906  
6907  Int_t t = 0; // type flag 
6908  Int_t pe = 0; // ptEta flag
6909  
6910  if(type == "RP")
6911  {
6912   t = 0;
6913  } else if(type == "POI")
6914    {
6915     t = 1;
6916    }
6917
6918  if(ptOrEta == "Pt")
6919  {
6920   pe = 0;
6921  } else if(ptOrEta == "Eta")
6922    {
6923     pe = 1;
6924    }
6925     
6926  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6927  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6928  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6929  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6930
6931  // looping over all bins and calculating reduced correlations: 
6932  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6933  {
6934   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
6935   Double_t p1n0kRe = 0.;
6936   Double_t p1n0kIm = 0.;
6937
6938   // number of POIs in particular pt or eta bin:
6939   Double_t mp = 0.;
6940
6941   // 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):
6942   Double_t q1n0kRe = 0.;
6943   Double_t q1n0kIm = 0.;
6944   Double_t q2n0kRe = 0.;
6945   Double_t q2n0kIm = 0.;
6946
6947   // number of particles which are both RPs and POIs in particular pt or eta bin:
6948   Double_t mq = 0.;
6949    
6950   if(type == "POI")
6951   {
6952    // q_{m*n,0}:
6953    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
6954            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
6955    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
6956            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
6957    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
6958            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
6959    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
6960            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
6961                  
6962    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6963   } 
6964   else if(type == "RP")
6965   {
6966    // q_{m*n,0}:
6967    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
6968            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
6969    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
6970            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
6971    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
6972            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
6973    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
6974            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
6975                  
6976    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
6977   }
6978       
6979    if(type == "POI")
6980    {
6981     // p_{m*n,0}:
6982     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
6983             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
6984     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
6985             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
6986             
6987     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6988     
6989     t = 1; // typeFlag = RP or POI
6990    }
6991    else if(type == "RP")
6992    {
6993     // p_{m*n,0} = q_{m*n,0}:
6994     p1n0kRe = q1n0kRe; 
6995     p1n0kIm = q1n0kIm; 
6996             
6997     mp = mq; 
6998     
6999     t = 0; // typeFlag = RP or POI
7000    }
7001       
7002    // 2'-particle correlation for particular pt or eta bin:
7003    Double_t two1n1nPtEta = 0.;
7004    Double_t mWeight2pPrime = 0.; // multiplicity weight for <2'>
7005    if(mp*dMult-mq)
7006    {
7007     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
7008                  / (mp*dMult-mq);
7009     // determine multiplicity weight:
7010     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7011     {
7012      mWeight2pPrime = mp*dMult-mq;
7013     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7014       {
7015        mWeight2pPrime = 1.;    
7016       } 
7017     if(type == "POI") // to be improved (I do not this if)
7018     { 
7019      // fill profile to get <<2'>> for POIs
7020      fDiffFlowCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);
7021      // fill profile to get <<2'>^2> for POIs
7022      fDiffFlowSquaredCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);   
7023      // histogram to store <2'> for POIs e-b-e (needed in some other methods):
7024      fDiffFlowCorrelationsEBE[1][pe][0]->SetBinContent(b,two1n1nPtEta);      
7025      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][0]->SetBinContent(b,mWeight2pPrime);      
7026     }
7027     else if(type == "RP") // to be improved (I do not this if)
7028     {
7029      // profile to get <<2'>> for RPs:
7030      fDiffFlowCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mWeight2pPrime);     
7031      // profile to get <<2'>^2> for RPs:
7032      fDiffFlowSquaredCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta*two1n1nPtEta,mWeight2pPrime);          
7033      // histogram to store <2'> for RPs e-b-e (needed in some other methods):
7034      fDiffFlowCorrelationsEBE[0][pe][0]->SetBinContent(b,two1n1nPtEta); 
7035      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][0]->SetBinContent(b,mWeight2pPrime); 
7036     }
7037    } // end of if(mp*dMult-mq)
7038   
7039    // 4'-particle correlation:
7040    Double_t four1n1n1n1nPtEta = 0.;
7041    Double_t mWeight4pPrime = 0.; // multiplicity weight for <4'>
7042    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7043        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
7044    {
7045     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
7046                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
7047                       - 2.*q2n0kIm*dReQ1n*dImQ1n
7048                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
7049                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
7050                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
7051                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
7052                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
7053                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
7054                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
7055                       + 2.*mq*dMult                      
7056                       - 6.*mq)        
7057                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7058                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
7059     // determine multiplicity weight:
7060     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7061     {
7062      mWeight4pPrime = (mp-mq)*dMult*(dMult-1.)*(dMult-2.) + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);
7063     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7064       {
7065        mWeight4pPrime = 1.;    
7066       }     
7067     if(type == "POI")
7068     {
7069      // profile to get <<4'>> for POIs:
7070      fDiffFlowCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);      
7071      // profile to get <<4'>^2> for POIs:
7072      fDiffFlowSquaredCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime); 
7073      // histogram to store <4'> for POIs e-b-e (needed in some other methods):
7074      fDiffFlowCorrelationsEBE[1][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                               
7075      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][1]->SetBinContent(b,mWeight4pPrime);                               
7076     }
7077     else if(type == "RP")
7078     {
7079      // profile to get <<4'>> for RPs:
7080      fDiffFlowCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,mWeight4pPrime);    
7081      // profile to get <<4'>^2> for RPs:
7082      fDiffFlowSquaredCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta*four1n1n1n1nPtEta,mWeight4pPrime);    
7083      // histogram to store <4'> for RPs e-b-e (needed in some other methods):
7084      fDiffFlowCorrelationsEBE[0][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                   
7085      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][1]->SetBinContent(b,mWeight4pPrime);                   
7086     }
7087    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7088      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
7089    
7090  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7091  
7092    
7093 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta);
7094
7095 //================================================================================================================================
7096
7097 void AliFlowAnalysisWithQCumulants::CalculateOtherDiffCorrelators(TString type, TString ptOrEta)
7098 {
7099  // Calculate other differential correlators for RPs or POIs for all pt and eta bins.
7100  
7101  // Multiplicity:
7102  Double_t dMult = (*fSpk)(0,0);
7103  
7104  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
7105  Double_t dReQ1n = (*fReQ)(0,0);
7106  Double_t dReQ2n = (*fReQ)(1,0);
7107  Double_t dReQ3n = (*fReQ)(2,0);
7108  //Double_t dReQ4n = (*fReQ)(3,0);
7109  Double_t dImQ1n = (*fImQ)(0,0);
7110  Double_t dImQ2n = (*fImQ)(1,0);
7111  Double_t dImQ3n = (*fImQ)(2,0);
7112  //Double_t dImQ4n = (*fImQ)(3,0);
7113
7114  // 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]
7115  // Correlation index runs as follows:
7116  // 
7117  //  0: <exp[in(psi1-3phi2+2phi3)]>
7118  
7119  Int_t t = 0; // type flag 
7120  Int_t pe = 0; // ptEta flag
7121  
7122  if(type == "RP")
7123  {
7124   t = 0;
7125  } else if(type == "POI")
7126    {
7127     t = 1;
7128    }
7129
7130  if(ptOrEta == "Pt")
7131  {
7132   pe = 0;
7133  } else if(ptOrEta == "Eta")
7134    {
7135     pe = 1;
7136    }
7137     
7138  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7139  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7140  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7141  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7142
7143  // looping over all bins and calculating reduced correlations: 
7144  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7145  {
7146   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
7147   Double_t p1n0kRe = 0.;
7148   Double_t p1n0kIm = 0.;
7149
7150   // number of POIs in particular pt or eta bin:
7151   Double_t mp = 0.;
7152
7153   // 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):
7154   Double_t q1n0kRe = 0.;
7155   Double_t q1n0kIm = 0.;
7156   Double_t q2n0kRe = 0.;
7157   Double_t q2n0kIm = 0.;
7158   Double_t q3n0kRe = 0.;
7159   Double_t q3n0kIm = 0.;
7160
7161   // number of particles which are both RPs and POIs in particular pt or eta bin:
7162   Double_t mq = 0.;
7163    
7164   if(type == "POI")
7165   {
7166    // q_{m*n,0}:
7167    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
7168            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
7169    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
7170            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
7171    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
7172            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
7173    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
7174            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));                         
7175    q3n0kRe = fReRPQ1dEBE[2][pe][2][0]->GetBinContent(fReRPQ1dEBE[2][pe][2][0]->GetBin(b))
7176            * fReRPQ1dEBE[2][pe][2][0]->GetBinEntries(fReRPQ1dEBE[2][pe][2][0]->GetBin(b));
7177    q3n0kIm = fImRPQ1dEBE[2][pe][2][0]->GetBinContent(fImRPQ1dEBE[2][pe][2][0]->GetBin(b))
7178            * fImRPQ1dEBE[2][pe][2][0]->GetBinEntries(fImRPQ1dEBE[2][pe][2][0]->GetBin(b));         
7179
7180    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7181   } 
7182   else if(type == "RP")
7183   {
7184    // q_{m*n,0}:
7185    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
7186            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
7187    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
7188            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
7189    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
7190            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
7191    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
7192            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
7193    q3n0kRe = fReRPQ1dEBE[0][pe][2][0]->GetBinContent(fReRPQ1dEBE[0][pe][2][0]->GetBin(b))
7194            * fReRPQ1dEBE[0][pe][2][0]->GetBinEntries(fReRPQ1dEBE[0][pe][2][0]->GetBin(b));
7195    q3n0kIm = fImRPQ1dEBE[0][pe][2][0]->GetBinContent(fImRPQ1dEBE[0][pe][2][0]->GetBin(b))
7196            * fImRPQ1dEBE[0][pe][2][0]->GetBinEntries(fImRPQ1dEBE[0][pe][2][0]->GetBin(b));         
7197                  
7198    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
7199   }
7200       
7201    if(type == "POI")
7202    {
7203     // p_{m*n,0}:
7204     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
7205             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
7206     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
7207             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
7208             
7209     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
7210     
7211     t = 1; // typeFlag = RP or POI
7212    }
7213    else if(type == "RP")
7214    {
7215     // p_{m*n,0} = q_{m*n,0}:
7216     p1n0kRe = q1n0kRe; 
7217     p1n0kIm = q1n0kIm; 
7218             
7219     mp = mq; 
7220     
7221     t = 0; // typeFlag = RP or POI
7222    }
7223       
7224    // 3'-particle correlators:
7225    //  Taeney-Yan correlator:
7226    Double_t dTaeneyYan = 0.;
7227    Double_t mWeightTaeneyYan = 0.; // multiplicity weight for Taeney-Yan correlator
7228    if((mp*dMult-2.*mq)*(dMult-1.) > 0.) // to be improved - is this condition fully justified?
7229    {
7230     dTaeneyYan = (dReQ3n*(p1n0kRe*dReQ2n-p1n0kIm*dImQ2n)+dImQ3n*(p1n0kIm*dReQ2n+p1n0kRe*dImQ2n)
7231                - p1n0kRe*dReQ1n - p1n0kIm*dImQ1n
7232                - q2n0kRe*dReQ2n - q2n0kIm*dImQ2n              
7233                - q3n0kRe*dReQ3n - q3n0kIm*dImQ3n
7234                + 2.*mq)
7235                / ((mp*dMult-2.*mq)*(dMult-1.));
7236     // determine multiplicity weight:
7237     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7238     {
7239      mWeightTaeneyYan = (mp*dMult-2.*mq)*(dMult-1.);
7240     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7241       {
7242        mWeightTaeneyYan = 1.;    
7243       } 
7244     // Fill profiles:
7245     fOtherDiffCorrelators[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dTaeneyYan,mWeightTaeneyYan);
7246    } // end of if((mp*dMult-2.*mq)*(dMult-1.) > 0.)  
7247    
7248  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7249  
7250 } // end of void AliFlowAnalysisWithQCumulants::CalculateOtherDiffCorrelators(TString type, TString ptOrEta)
7251
7252 //================================================================================================================================
7253
7254 void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCorrelations(TString type)
7255 {
7256  // Calculate all reduced correlations needed for 2D differential flow for each (pt,eta) bin. 
7257  
7258  // Multiplicity:
7259  Double_t dMult = (*fSpk)(0,0);
7260  // Real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
7261  Double_t dReQ1n = (*fReQ)(0,0);
7262  Double_t dReQ2n = (*fReQ)(1,0);
7263  //Double_t dReQ3n = (*fReQ)(2,0);
7264  //Double_t dReQ4n = (*fReQ)(3,0);
7265  Double_t dImQ1n = (*fImQ)(0,0);
7266  Double_t dImQ2n = (*fImQ)(1,0);
7267  //Double_t dImQ3n = (*fImQ)(2,0);
7268  //Double_t dImQ4n = (*fImQ)(3,0);
7269
7270  // 2D reduced correlations are stored in TProfile2D f2DDiffFlowCorrelationsPro[0=RP,1=POI][correlation index]. 
7271  // Correlation index runs as follows:
7272  //  0: <<2'>> 
7273  //  1: <<4'>>
7274  //  2: <<6'>>
7275  //  3: <<8'>>
7276  
7277  Int_t t = 0; // type flag  
7278  if(type == "RP")
7279  {
7280   t = 0;
7281  } else if(type == "POI")
7282    {
7283     t = 1;
7284    }
7285
7286  // Looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
7287  for(Int_t p=1;p<=fnBinsPt;p++)
7288  {
7289   for(Int_t e=1;e<=fnBinsEta;e++)
7290   {
7291    // Real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin): 
7292    Double_t p1n0kRe = 0.;
7293    Double_t p1n0kIm = 0.;
7294    // Number of POIs in particular pt or eta bin:
7295    Double_t mp = 0.;
7296    // Real and imaginary parts of q_{m*n,0} (non-weighted Q-vector evaluated for 'RP && POI particles' in particular pt or eta bin):
7297    Double_t q1n0kRe = 0.;
7298    Double_t q1n0kIm = 0.;
7299    Double_t q2n0kRe = 0.;
7300    Double_t q2n0kIm = 0.; 
7301    // Number of 'RP && POI particles' in particular pt or eta bin:
7302    Double_t mq = 0.;
7303    if(type == "POI")
7304    {
7305     // q_{m*n,0}:
7306     q1n0kRe = fReRPQ2dEBE[2][0][0]->GetBinContent(fReRPQ2dEBE[2][0][0]->GetBin(p,e))
7307             * fReRPQ2dEBE[2][0][0]->GetBinEntries(fReRPQ2dEBE[2][0][0]->GetBin(p,e));
7308     q1n0kIm = fImRPQ2dEBE[2][0][0]->GetBinContent(fImRPQ2dEBE[2][0][0]->GetBin(p,e))
7309             * fImRPQ2dEBE[2][0][0]->GetBinEntries(fImRPQ2dEBE[2][0][0]->GetBin(p,e));
7310     q2n0kRe = fReRPQ2dEBE[2][1][0]->GetBinContent(fReRPQ2dEBE[2][1][0]->GetBin(p,e))
7311             * fReRPQ2dEBE[2][1][0]->GetBinEntries(fReRPQ2dEBE[2][1][0]->GetBin(p,e));
7312     q2n0kIm = fImRPQ2dEBE[2][1][0]->GetBinContent(fImRPQ2dEBE[2][1][0]->GetBin(p,e))
7313             * fImRPQ2dEBE[2][1][0]->GetBinEntries(fImRPQ2dEBE[2][1][0]->GetBin(p,e));         
7314     // m_{q}:             
7315     mq = fReRPQ2dEBE[2][0][0]->GetBinEntries(fReRPQ2dEBE[2][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
7316    } // end of if(type == "POI")
7317    else if(type == "RP")
7318    {
7319     // q_{m*n,0}:
7320     q1n0kRe = fReRPQ2dEBE[0][0][0]->GetBinContent(fReRPQ2dEBE[0][0][0]->GetBin(p,e))
7321             * fReRPQ2dEBE[0][0][0]->GetBinEntries(fReRPQ2dEBE[0][0][0]->GetBin(p,e));
7322     q1n0kIm = fImRPQ2dEBE[0][0][0]->GetBinContent(fImRPQ2dEBE[0][0][0]->GetBin(p,e))
7323             * fImRPQ2dEBE[0][0][0]->GetBinEntries(fImRPQ2dEBE[0][0][0]->GetBin(p,e));
7324     q2n0kRe = fReRPQ2dEBE[0][1][0]->GetBinContent(fReRPQ2dEBE[0][1][0]->GetBin(p,e))
7325             * fReRPQ2dEBE[0][1][0]->GetBinEntries(fReRPQ2dEBE[0][1][0]->GetBin(p,e));
7326     q2n0kIm = fImRPQ2dEBE[0][1][0]->GetBinContent(fImRPQ2dEBE[0][1][0]->GetBin(p,e))
7327             * fImRPQ2dEBE[0][1][0]->GetBinEntries(fImRPQ2dEBE[0][1][0]->GetBin(p,e));         
7328     // m_{q}:             
7329     mq = fReRPQ2dEBE[0][0][0]->GetBinEntries(fReRPQ2dEBE[0][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)  
7330    } // end of else if(type == "RP")
7331    if(type == "POI")
7332    {
7333     // p_{m*n,0}:
7334     p1n0kRe = fReRPQ2dEBE[1][0][0]->GetBinContent(fReRPQ2dEBE[1][0][0]->GetBin(p,e))
7335             * fReRPQ2dEBE[1][0][0]->GetBinEntries(fReRPQ2dEBE[1][0][0]->GetBin(p,e));
7336     p1n0kIm = fImRPQ2dEBE[1][0][0]->GetBinContent(fImRPQ2dEBE[1][0][0]->GetBin(p,e))  
7337             * fImRPQ2dEBE[1][0][0]->GetBinEntries(fImRPQ2dEBE[1][0][0]->GetBin(p,e));
7338     // m_{p}        
7339     mp = fReRPQ2dEBE[1][0][0]->GetBinEntries(fReRPQ2dEBE[1][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
7340     
7341     t = 1; // typeFlag = RP or POI
7342    } // end of if(type == "POI")
7343    else if(type == "RP")
7344    {
7345     // p_{m*n,0} = q_{m*n,0}:
7346     p1n0kRe = q1n0kRe; 
7347     p1n0kIm = q1n0kIm; 
7348     // m_{p} = m_{q}:        
7349     mp = mq; 
7350
7351     t = 0; // typeFlag = RP or POI
7352    } // end of if(type == "RP")
7353
7354    // 2'-particle correlation for particular (pt,eta) bin:
7355    Double_t two1n1nPtEta = 0.;
7356    Double_t mWeight2pPrime = 0.; // multiplicity weight for <2'>
7357    if(mp*dMult-mq)
7358    {
7359     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
7360                  / (mp*dMult-mq);
7361     // Determine multiplicity weight:
7362     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7363     {
7364      mWeight2pPrime = mp*dMult-mq;
7365     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7366       {
7367        mWeight2pPrime = 1.;    
7368       } 
7369     // Fill 2D profile holding <<2'>>:     
7370     f2DDiffFlowCorrelationsPro[t][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mWeight2pPrime);
7371    } // end of if(mp*dMult-mq)
7372    
7373    // 4'-particle correlation:
7374    Double_t four1n1n1n1nPtEta = 0.;
7375    Double_t mWeight4pPrime = 0.; // multiplicity weight for <4'>
7376    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7377        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
7378    {
7379     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
7380                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
7381                       - 2.*q2n0kIm*dReQ1n*dImQ1n
7382                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
7383                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
7384                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
7385                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
7386                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
7387                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
7388                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
7389                       + 2.*mq*dMult                      
7390                       - 6.*mq)        
7391                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7392                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
7393     // Determine multiplicity weight:
7394     if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
7395     {
7396      mWeight4pPrime = (mp-mq)*dMult*(dMult-1.)*(dMult-2.) + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);
7397     } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
7398       {
7399        mWeight4pPrime = 1.;    
7400       }     
7401     // Fill 2D profile holding <<4'>>:
7402     f2DDiffFlowCorrelationsPro[t][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,mWeight4pPrime);      
7403    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7404      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
7405   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
7406  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
7407       
7408 } // end of AliFlowAnalysisWithQCumulants::Calculate2DDiffFlowCorrelations(TString type)
7409
7410 //================================================================================================================================
7411
7412 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights(TString type, TString ptOrEta)
7413 {
7414  // Calculate sums of various event weights for reduced correlations. 
7415  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
7416
7417  Int_t typeFlag = 0;
7418  Int_t ptEtaFlag = 0;
7419
7420  if(type == "RP")
7421  {
7422   typeFlag = 0;
7423  } else if(type == "POI")
7424    {
7425     typeFlag = 1;
7426    } 
7427      
7428  if(ptOrEta == "Pt")
7429  {
7430   ptEtaFlag = 0;
7431  } else if(ptOrEta == "Eta")
7432    {
7433     ptEtaFlag = 1;
7434    } 
7435    
7436  // shortcuts:
7437  Int_t t = typeFlag;
7438  Int_t pe = ptEtaFlag;
7439  
7440  // binning:
7441  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7442  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7443  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7444  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7445  
7446  for(Int_t rpq=0;rpq<3;rpq++)
7447  {
7448   for(Int_t m=0;m<4;m++)
7449   {
7450    for(Int_t k=0;k<9;k++)
7451    {
7452     if(!fReRPQ1dEBE[rpq][pe][m][k])
7453     {
7454      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
7455      cout<<"pe  = "<<pe<<endl;
7456      cout<<"rpq = "<<rpq<<endl;
7457      cout<<"m   = "<<m<<endl;
7458      cout<<"k   = "<<k<<endl;
7459      exit(0); 
7460     }
7461    }
7462   }
7463  }  
7464
7465  // multiplicities:
7466  Double_t dMult = (*fSpk)(0,0); // total event multiplicity
7467  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7468  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7469  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7470  
7471  // event weights for reduced correlations:
7472  Double_t dw2 = 0.; // event weight for <2'>
7473  Double_t dw4 = 0.; // event weight for <4'>
7474  //Double_t dw6 = 0.; // event weight for <6'>
7475  //Double_t dw8 = 0.; // event weight for <8'>
7476
7477  // looping over bins:
7478  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7479  {
7480   if(type == "RP")
7481   {
7482    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7483    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7484   } else if(type == "POI")
7485     {
7486      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7487      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7488     }
7489   
7490   // event weight for <2'>:
7491   dw2 = mp*dMult-mq;  
7492   fDiffFlowSumOfEventWeights[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2);
7493   fDiffFlowSumOfEventWeights[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw2,2.));
7494   
7495   // event weight for <4'>:
7496   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7497      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
7498   fDiffFlowSumOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4);
7499   fDiffFlowSumOfEventWeights[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw4,2.));
7500   
7501   // event weight for <6'>:
7502   //dw6 = ...;  
7503   //fDiffFlowSumOfEventWeights[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6);
7504   //fDiffFlowSumOfEventWeights[t][pe][t][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw6,2.));
7505   
7506   // event weight for <8'>:
7507   //dw8 = ...;  
7508   //fDiffFlowSumOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw8);
7509   //fDiffFlowSumOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw8,2.));   
7510  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++) 
7511  
7512 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights()
7513
7514
7515 //================================================================================================================================
7516
7517
7518 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
7519 {
7520  // Calculate sum of products of various event weights for both types of correlations (the ones for int. and diff. flow). 
7521  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
7522  //
7523  // Important: To fill fDiffFlowSumOfProductOfEventWeights[][][][] use bellow table (i,j) with following constraints: 
7524  // 1.) i<j  
7525  // 2.) do not store terms which DO NOT include reduced correlations;
7526  // Table:
7527  // [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'>]
7528   
7529  Int_t typeFlag = 0;
7530  Int_t ptEtaFlag = 0;
7531
7532  if(type == "RP")
7533  {
7534   typeFlag = 0;
7535  } else if(type == "POI")
7536    {
7537     typeFlag = 1;
7538    } 
7539      
7540  if(ptOrEta == "Pt")
7541  {
7542   ptEtaFlag = 0;
7543  } else if(ptOrEta == "Eta")
7544    {
7545     ptEtaFlag = 1;
7546    } 
7547      
7548  // shortcuts:
7549  Int_t t = typeFlag;
7550  Int_t pe = ptEtaFlag;
7551   
7552  // binning:
7553  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7554  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7555  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7556  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7557  
7558  // protection:
7559  for(Int_t rpq=0;rpq<3;rpq++)
7560  {
7561   for(Int_t m=0;m<4;m++)
7562   {
7563    for(Int_t k=0;k<9;k++)
7564    {
7565     if(!fReRPQ1dEBE[rpq][pe][m][k])
7566     {
7567      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
7568      cout<<"pe  = "<<pe<<endl;
7569      cout<<"rpq = "<<rpq<<endl;
7570      cout<<"m   = "<<m<<endl;
7571      cout<<"k   = "<<k<<endl;
7572      exit(0); 
7573     }
7574    }
7575   }
7576  }  
7577  
7578  // multiplicities:
7579  Double_t dMult = (*fSpk)(0,0); // total event multiplicity
7580  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7581  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7582  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7583  
7584  // event weights for correlations:
7585  Double_t dW2 = dMult*(dMult-1); // event weight for <2> 
7586  Double_t dW4 = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
7587  Double_t dW6 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
7588  Double_t dW8 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
7589
7590  // event weights for reduced correlations:
7591  Double_t dw2 = 0.; // event weight for <2'>
7592  Double_t dw4 = 0.; // event weight for <4'>
7593  //Double_t dw6 = 0.; // event weight for <6'>
7594  //Double_t dw8 = 0.; // event weight for <8'>
7595  
7596  // looping over bins:
7597  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7598  {
7599   if(type == "RP")
7600   {
7601    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7602    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7603   } else if(type == "POI")
7604     {
7605      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7606      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7607     }
7608   
7609   // event weight for <2'>:
7610   dw2 = mp*dMult-mq;  
7611   fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw2); // storing product of even weights for <2> and <2'>
7612   fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW4); // storing product of even weights for <4> and <2'>
7613   fDiffFlowSumOfProductOfEventWeights[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW6); // storing product of even weights for <6> and <2'>
7614   fDiffFlowSumOfProductOfEventWeights[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW8); // storing product of even weights for <8> and <2'>
7615   
7616   // event weight for <4'>:
7617   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7618      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
7619   fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw4); // storing product of even weights for <2> and <4'>
7620   fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw4); // storing product of even weights for <2'> and <4'>
7621   fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw4); // storing product of even weights for <4> and <4'>
7622   fDiffFlowSumOfProductOfEventWeights[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW6); // storing product of even weights for <6> and <4'> 
7623   fDiffFlowSumOfProductOfEventWeights[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW8); // storing product of even weights for <8> and <4'>
7624
7625   // event weight for <6'>:
7626   //dw6 = ...;  
7627   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw6); // storing product of even weights for <2> and <6'>
7628   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw6); // storing product of even weights for <2'> and <6'>
7629   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw6); // storing product of even weights for <4> and <6'>
7630   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw6); // storing product of even weights for <4'> and <6'> 
7631   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw6); // storing product of even weights for <6> and <6'>
7632   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dW8); // storing product of even weights for <6'> and <8>
7633   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
7634
7635   // event weight for <8'>:
7636   //dw8 = ...;  
7637   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw8); // storing product of even weights for <2> and <8'>
7638   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw8); // storing product of even weights for <2'> and <8'>
7639   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw8); // storing product of even weights for <4> and <8'>
7640   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw8); // storing product of even weights for <4'> and <8'> 
7641   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw8); // storing product of even weights for <6> and <8'>
7642   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
7643   //fDiffFlowSumOfProductOfEventWeights[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW8*dw8); // storing product of even weights for <8> and <8'>
7644   
7645   // Table:
7646   // [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'>]
7647    
7648  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7649  
7650
7651
7652 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
7653
7654 //================================================================================================================================
7655
7656 void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
7657 {
7658  // Transfer profiles into histograms and calculate statistical errors correctly.
7659
7660  Int_t t = 0; // RP or POI
7661  Int_t pe = 0; // pt or eta
7662
7663  if(type == "RP")
7664  {
7665   t = 0;
7666  } else if(type == "POI")
7667    {
7668     t = 1;
7669    } 
7670      
7671  if(ptOrEta == "Pt")
7672  {
7673   pe = 0;
7674  } else if(ptOrEta == "Eta")
7675    {
7676     pe = 1;
7677    } 
7678                
7679  for(Int_t rci=0;rci<4;rci++) // to be improved - moved into the method CheckPointersUsedInFinish()
7680  {
7681   if(!fDiffFlowCorrelationsPro[t][pe][rci])
7682   {
7683    cout<<"WARNING: fDiffFlowCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7684    cout<<"t   = "<<t<<endl; 
7685    cout<<"pe  = "<<pe<<endl; 
7686    cout<<"rci = "<<rci<<endl;
7687    exit(0); 
7688   }
7689   if(!fDiffFlowSquaredCorrelationsPro[t][pe][rci])
7690   {
7691    cout<<"WARNING: fDiffFlowSquaredCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7692    cout<<"t   = "<<t<<endl; 
7693    cout<<"pe  = "<<pe<<endl; 
7694    cout<<"rci = "<<rci<<endl;
7695    exit(0); 
7696   }
7697   for(Int_t power=0;power<2;power++)
7698   {
7699    if(!fDiffFlowSumOfEventWeights[t][pe][power][rci])
7700    {
7701     cout<<"WARNING: fDiffFlowSumOfEventWeights[t][pe][power][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
7702     cout<<"t     = "<<t<<endl; 
7703     cout<<"pe    = "<<pe<<endl;
7704     cout<<"power = "<<power<<endl; 
7705     cout<<"rci   = "<<rci<<endl;
7706     exit(0); 
7707    }   
7708   } // end of for(Int_t power=0;power<2;power++)
7709  } // end of for(Int_t rci=0;rci<4;rci++)
7710     
7711  // common:
7712  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta}; 
7713  // transfer 1D profile into 1D histogram:
7714  Double_t correlation = 0.;
7715  Double_t squaredCorrelation = 0.;
7716  Double_t spread = 0.;
7717  Double_t sumOfWeights = 0.; // sum of weights for particular reduced correlations for particular pt or eta bin
7718  Double_t sumOfSquaredWeights = 0.; // sum of squared weights for particular reduced correlations for particular pt or eta bin
7719  Double_t error = 0.; // error = termA * spread * termB
7720                       // termA = (sqrt(sumOfSquaredWeights)/sumOfWeights) 
7721                       // termB = 1/pow(1-termA^2,0.5)
7722  Double_t termA = 0.;                      
7723  Double_t termB = 0.;                      
7724  for(Int_t rci=0;rci<4;rci++) // index of reduced correlation
7725  {
7726   for(Int_t b=1;b<=nBinsPtEta[pe];b++) // number of pt or eta bins
7727   {
7728    if(fDiffFlowCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2 || 
7729       fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinEffectiveEntries(b) < 2)
7730    {
7731     fDiffFlowCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7732     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetBinError(b,0.);
7733     continue; // to be improved - should I ignore results in pt bins with one entry for reduced correlations or not?
7734    }  
7735    correlation = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7736    squaredCorrelation = fDiffFlowSquaredCorrelationsPro[t][pe][rci]->GetBinContent(b); 
7737    if(squaredCorrelation-correlation*correlation >= 0.)
7738    {
7739     spread = pow(squaredCorrelation-correlation*correlation,0.5);
7740    } else
7741      {
7742       cout<<endl;
7743       cout<<Form(" WARNING: Imaginary 'spread' for rci = %d, pe = %d, bin = %d !!!!",rci,pe,b)<<endl;
7744       cout<<endl;
7745      }
7746    sumOfWeights = fDiffFlowSumOfEventWeights[t][pe][0][rci]->GetBinContent(b);
7747    sumOfSquaredWeights = fDiffFlowSumOfEventWeights[t][pe][1][rci]->GetBinContent(b);
7748    if(TMath::Abs(sumOfWeights)>0.){termA = (pow(sumOfSquaredWeights,0.5)/sumOfWeights);}
7749    if(1.-pow(termA,2.)>0.){termB = 1./pow(1.-pow(termA,2.),0.5);} 
7750    error = termA*spread*termB; // final error (unbiased estimator for standard deviation)
7751    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinContent(b,correlation); 
7752    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinError(b,error); 
7753   } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7754  } // end of for(Int_t rci=0;rci<4;rci++)
7755  
7756 } // end of void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
7757
7758 //================================================================================================================================
7759
7760 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7761 {
7762  // store products: <2><2'>, <2><4'>, <2><6'>, <2><8'>, <2'><4>, 
7763  //                 <2'><4'>, <2'><6>, <2'><6'>, <2'><8>, <2'><8'>,
7764  //                 <4><4'>, <4><6'>, <4><8'>, <4'><6>, <4'><6'>, 
7765  //                 <4'><8>, <4'><8'>, <6><6'>, <6><8'>, <6'><8>, 
7766  //                 <6'><8'>, <8><8'>.
7767   
7768  Int_t typeFlag = 0;
7769  Int_t ptEtaFlag = 0;
7770
7771  if(type == "RP")
7772  {
7773   typeFlag = 0;
7774  } else if(type == "POI")
7775    {
7776     typeFlag = 1;
7777    } 
7778      
7779  if(ptOrEta == "Pt")
7780  {
7781   ptEtaFlag = 0;
7782  } else if(ptOrEta == "Eta")
7783    {
7784     ptEtaFlag = 1;
7785    } 
7786   
7787  // shortcuts:
7788  Int_t t = typeFlag;
7789  Int_t pe = ptEtaFlag;
7790      
7791  // common:
7792  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7793  Double_t minPtEta[2] = {fPtMin,fEtaMin};
7794  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7795    
7796  // protections // to be improved (add protection for all pointers in this method)
7797  if(!fIntFlowCorrelationsEBE)
7798  {
7799   cout<<"WARNING: fIntFlowCorrelationsEBE is NULL in AFAWQC::CDFPOC() !!!!"<<endl;
7800   exit(0);
7801  } 
7802  
7803  /*    
7804  Double_t dMult = (*fSpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
7805  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
7806  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
7807  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
7808  */
7809
7810  // e-b-e correlations:
7811  Double_t twoEBE = fIntFlowCorrelationsEBE->GetBinContent(1); // <2>
7812  Double_t fourEBE = fIntFlowCorrelationsEBE->GetBinContent(2); // <4>
7813  Double_t sixEBE = fIntFlowCorrelationsEBE->GetBinContent(3); // <6>
7814  Double_t eightEBE = fIntFlowCorrelationsEBE->GetBinContent(4); // <8>
7815  
7816  // event weights for correlations:
7817  Double_t dW2 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1); // event weight for <2> 
7818  Double_t dW4 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2); // event weight for <4> 
7819  Double_t dW6 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(3); // event weight for <6> 
7820  Double_t dW8 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(4); // event weight for <8> 
7821   
7822  // e-b-e reduced correlations:
7823  Double_t twoReducedEBE = 0.; // <2'>
7824  Double_t fourReducedEBE = 0.; // <4'>
7825  Double_t sixReducedEBE = 0.; // <6'>
7826  Double_t eightReducedEBE = 0.; // <8'> 
7827  
7828  // event weights for reduced correlations:
7829  Double_t dw2 = 0.; // event weight for <2'>
7830  Double_t dw4 = 0.; // event weight for <4'>
7831  //Double_t dw6 = 0.; // event weight for <6'>
7832  //Double_t dw8 = 0.; // event weight for <8'>
7833
7834  // looping over bins:
7835  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7836  {
7837   // e-b-e reduced correlations:
7838   twoReducedEBE = fDiffFlowCorrelationsEBE[t][pe][0]->GetBinContent(b);
7839   fourReducedEBE = fDiffFlowCorrelationsEBE[t][pe][1]->GetBinContent(b);
7840   sixReducedEBE = fDiffFlowCorrelationsEBE[t][pe][2]->GetBinContent(b);
7841   eightReducedEBE = fDiffFlowCorrelationsEBE[t][pe][3]->GetBinContent(b);
7842   
7843   /*
7844   // to be improved (I should not do this here again)
7845   if(type == "RP")
7846   {
7847    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
7848    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
7849   } else if(type == "POI")
7850     {
7851      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
7852      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
7853     }
7854   
7855   // event weights for reduced correlations:
7856   dw2 = mp*dMult-mq; // weight for <2'> 
7857   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
7858      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.); // weight for <4'>
7859   //dw6 = ...     
7860   //dw8 = ...     
7861   
7862   */
7863   
7864   dw2 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->GetBinContent(b);
7865   dw4 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->GetBinContent(b);
7866  
7867   // storing all products:
7868   fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*twoReducedEBE,dW2*dw2); // storing <2><2'>
7869   fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*twoReducedEBE,dW4*dw2); // storing <4><2'>
7870   fDiffFlowProductOfCorrelationsPro[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*twoReducedEBE,dW6*dw2); // storing <6><2'>
7871   fDiffFlowProductOfCorrelationsPro[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*twoReducedEBE,dW8*dw2); // storing <8><2'>
7872   
7873   // event weight for <4'>:
7874   fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*fourReducedEBE,dW2*dw4); // storing <2><4'>
7875   fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*fourReducedEBE,dw2*dw4); // storing <2'><4'>
7876   fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*fourReducedEBE,dW4*dw4); // storing <4><4'>
7877   fDiffFlowProductOfCorrelationsPro[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*fourReducedEBE,dW6*dw4); // storing <6><4'> 
7878   fDiffFlowProductOfCorrelationsPro[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*fourReducedEBE,dW8*dw4); // storing <8><4'>
7879
7880   // event weight for <6'>:
7881   //dw6 = ...;  
7882   //fDiffFlowProductOfCorrelationsPro[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*sixReducedEBE,dW2*dw6); // storing <2><6'>
7883   //fDiffFlowProductOfCorrelationsPro[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*sixReducedEBE,dw2*dw6); // storing <2'><6'>
7884   //fDiffFlowProductOfCorrelationsPro[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*sixReducedEBE,dW4*dw6); // storing <4><6'>
7885   //fDiffFlowProductOfCorrelationsPro[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*sixReducedEBE,dw4*dw6); // storing <4'><6'> 
7886   //fDiffFlowProductOfCorrelationsPro[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*sixReducedEBE,dW6*dw6); // storing <6><6'>
7887   //fDiffFlowProductOfCorrelationsPro[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightEBE,dw6*dW8); // storing <6'><8>
7888   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7889
7890   // event weight for <8'>:
7891   //dw8 = ...;  
7892   //fDiffFlowProductOfCorrelationsPro[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*eightReducedEBE,dW2*dw8); // storing <2><8'>
7893   //fDiffFlowProductOfCorrelationsPro[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*eightReducedEBE,dw2*dw8); // storing <2'><8'>
7894   //fDiffFlowProductOfCorrelationsPro[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*eightReducedEBE,dW4*dw8); // storing <4><8'>
7895   //fDiffFlowProductOfCorrelationsPro[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*eightReducedEBE,dw4*dw8); // storing <4'><8'> 
7896   //fDiffFlowProductOfCorrelationsPro[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*eightReducedEBE,dW6*dw8); // storing <6><8'>
7897   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7898   //fDiffFlowProductOfCorrelationsPro[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*eightReducedEBE,dW8*dw8); // storing <8><8'> 
7899  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++       
7900      
7901 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7902
7903 //================================================================================================================================
7904     
7905 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta) // to be improved (reimplemented)
7906 {
7907  // a) Calculate unbiased estimators Cov(<2>,<2'>), Cov(<2>,<4'>), Cov(<4>,<2'>), Cov(<4>,<4'>) and Cov(<2'>,<4'>)
7908  //    for covariances V(<2>,<2'>), V(<2>,<4'>), V(<4>,<2'>), V(<4>,<4'>) and V(<2'>,<4'>).  
7909  // b) Store in histogram fDiffFlowCovariances[t][pe][index] for instance the following: 
7910  //
7911  //             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)]
7912  // 
7913  //     where N is the number of events, w_{<2>} is event weight for <2> and w_{<2'>} is event weight for <2'>.
7914  // c) Binning of fDiffFlowCovariances[t][pe][index] is organized as follows:
7915  // 
7916  //     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)] 
7917  //     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)] 
7918  //     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)] 
7919  //     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)] 
7920  //     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)] 
7921  //     ...
7922   
7923  Int_t typeFlag = 0;
7924  Int_t ptEtaFlag = 0;
7925
7926  if(type == "RP")
7927  {
7928   typeFlag = 0;
7929  } else if(type == "POI")
7930    {
7931     typeFlag = 1;
7932    } 
7933      
7934  if(ptOrEta == "Pt")
7935  {
7936   ptEtaFlag = 0;
7937  } else if(ptOrEta == "Eta")
7938    {
7939     ptEtaFlag = 1;
7940    } 
7941   
7942  // shortcuts:
7943  Int_t t = typeFlag;
7944  Int_t pe = ptEtaFlag;
7945      
7946  // common:
7947  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7948  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
7949  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7950  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7951  
7952  // average correlations:
7953  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7954  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7955  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
7956  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
7957  
7958  // sum of weights for correlation:
7959  Double_t sumOfWeightsForTwo = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // sum_{i=1}^{N} w_{<2>}
7960  Double_t sumOfWeightsForFour = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // sum_{i=1}^{N} w_{<4>}
7961  //Double_t sumOfWeightsForSix = fIntFlowSumOfEventWeights[0]->GetBinContent(3); // sum_{i=1}^{N} w_{<6>}
7962  //Double_t sumOfWeightsForEight = fIntFlowSumOfEventWeights[0]->GetBinContent(4); // sum_{i=1}^{N} w_{<8>}
7963  
7964  // average reduced correlations:
7965  Double_t twoReduced = 0.; // <<2'>> 
7966  Double_t fourReduced = 0.; // <<4'>>
7967  //Double_t sixReduced = 0.; // <<6'>>
7968  //Double_t eightReduced = 0.; // <<8'>>
7969
7970  // sum of weights for reduced correlation:
7971  Double_t sumOfWeightsForTwoReduced = 0.; // sum_{i=1}^{N} w_{<2'>}
7972  Double_t sumOfWeightsForFourReduced = 0.; // sum_{i=1}^{N} w_{<4'>}
7973  //Double_t sumOfWeightsForSixReduced = 0.; // sum_{i=1}^{N} w_{<6'>}
7974  //Double_t sumOfWeightsForEightReduced = 0.; // sum_{i=1}^{N} w_{<8'>}
7975   
7976  // product of weights for reduced correlation:
7977  Double_t productOfWeightsForTwoTwoReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<2'>}
7978  Double_t productOfWeightsForTwoFourReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<4'>}
7979  Double_t productOfWeightsForFourTwoReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<2'>}
7980  Double_t productOfWeightsForFourFourReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<4'>}
7981  Double_t productOfWeightsForTwoReducedFourReduced = 0.; // sum_{i=1}^{N} w_{<2'>}w_{<4'>}
7982  // ...
7983  
7984  // products for differential flow:
7985  Double_t twoTwoReduced = 0; // <<2><2'>> 
7986  Double_t twoFourReduced = 0; // <<2><4'>> 
7987  Double_t fourTwoReduced = 0; // <<4><2'>> 
7988  Double_t fourFourReduced = 0; // <<4><4'>> 
7989  Double_t twoReducedFourReduced = 0; // <<2'><4'>> 
7990
7991  // denominators in the expressions for the unbiased estimators for covariances:
7992  // denominator = 1 - term1/(term2*term3)
7993  // prefactor = term1/(term2*term3)
7994  Double_t denominator = 0.; 
7995  Double_t prefactor = 0.;
7996  Double_t term1 = 0.; 
7997  Double_t term2 = 0.; 
7998  Double_t term3 = 0.; 
7999  
8000  // unbiased estimators for covariances for differential flow:
8001  Double_t covTwoTwoReduced = 0.; // Cov(<2>,<2'>)
8002  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(w_{<2>},w_{<2'>})
8003  Double_t covTwoFourReduced = 0.; // Cov(<2>,<4'>)
8004  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(w_{<2>},w_{<4'>})
8005  Double_t covFourTwoReduced = 0.; // Cov(<4>,<2'>)
8006  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(w_{<4>},w_{<2'>})
8007  Double_t covFourFourReduced = 0.; // Cov(<4>,<4'>)
8008  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(w_{<4>},w_{<4'>})
8009  Double_t covTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>)
8010  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(w_{<2'>},w_{<4'>})
8011  
8012  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8013  {
8014   // average reduced corelations:
8015   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
8016   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
8017   // average products:
8018   twoTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->GetBinContent(b);
8019   twoFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->GetBinContent(b);
8020   fourTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->GetBinContent(b);
8021   fourFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->GetBinContent(b);
8022   twoReducedFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->GetBinContent(b);  
8023   // sum of weights for reduced correlations:
8024   sumOfWeightsForTwoReduced = fDiffFlowSumOfEventWeights[t][pe][0][0]->GetBinContent(b);
8025   sumOfWeightsForFourReduced = fDiffFlowSumOfEventWeights[t][pe][0][1]->GetBinContent(b);
8026   // products of weights for correlations:
8027   productOfWeightsForTwoTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->GetBinContent(b); 
8028   productOfWeightsForTwoFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->GetBinContent(b);
8029   productOfWeightsForFourTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->GetBinContent(b);
8030   productOfWeightsForFourFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->GetBinContent(b);
8031   productOfWeightsForTwoReducedFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->GetBinContent(b);
8032   // denominator for the unbiased estimator for covariances: 1 - term1/(term2*term3) 
8033   // prefactor (multiplies Cov's) = term1/(term2*term3)       
8034   // <2>,<2'>:
8035   term1 = productOfWeightsForTwoTwoReduced;      
8036   term2 = sumOfWeightsForTwo;
8037   term3 = sumOfWeightsForTwoReduced;        
8038   if(term2*term3>0.)
8039   {
8040    denominator = 1.-term1/(term2*term3);
8041    prefactor = term1/(term2*term3);
8042    if(TMath::Abs(denominator)>1.e-6)
8043    {
8044     covTwoTwoReduced = (twoTwoReduced-two*twoReduced)/denominator;            
8045     wCovTwoTwoReduced = covTwoTwoReduced*prefactor; 
8046     fDiffFlowCovariances[t][pe][0]->SetBinContent(b,wCovTwoTwoReduced);
8047    }
8048   }
8049   // <2>,<4'>:
8050   term1 = productOfWeightsForTwoFourReduced;      
8051   term2 = sumOfWeightsForTwo;
8052   term3 = sumOfWeightsForFourReduced;        
8053   if(term2*term3>0.)
8054   {
8055    denominator = 1.-term1/(term2*term3);
8056    prefactor = term1/(term2*term3);
8057    if(TMath::Abs(denominator)>1.e-6)
8058    {
8059     covTwoFourReduced = (twoFourReduced-two*fourReduced)/denominator;            
8060     wCovTwoFourReduced = covTwoFourReduced*prefactor; 
8061     fDiffFlowCovariances[t][pe][1]->SetBinContent(b,wCovTwoFourReduced);
8062    }
8063   }
8064   // <4>,<2'>:
8065   term1 = productOfWeightsForFourTwoReduced;      
8066   term2 = sumOfWeightsForFour;
8067   term3 = sumOfWeightsForTwoReduced;        
8068   if(term2*term3>0.)
8069   {
8070    denominator = 1.-term1/(term2*term3);
8071    prefactor = term1/(term2*term3);
8072    if(TMath::Abs(denominator)>1.e-6)
8073    {
8074     covFourTwoReduced = (fourTwoReduced-four*twoReduced)/denominator;            
8075     wCovFourTwoReduced = covFourTwoReduced*prefactor; 
8076     fDiffFlowCovariances[t][pe][2]->SetBinContent(b,wCovFourTwoReduced);
8077    }
8078   }
8079   // <4>,<4'>:
8080   term1 = productOfWeightsForFourFourReduced;      
8081   term2 = sumOfWeightsForFour;
8082   term3 = sumOfWeightsForFourReduced;        
8083   if(term2*term3>0.)
8084   {
8085    denominator = 1.-term1/(term2*term3);
8086    prefactor = term1/(term2*term3);
8087    if(TMath::Abs(denominator)>1.e-6)
8088    {
8089     covFourFourReduced = (fourFourReduced-four*fourReduced)/denominator;            
8090     wCovFourFourReduced = covFourFourReduced*prefactor; 
8091     fDiffFlowCovariances[t][pe][3]->SetBinContent(b,wCovFourFourReduced);
8092    }
8093   }
8094   // <2'>,<4'>:
8095   term1 = productOfWeightsForTwoReducedFourReduced;      
8096   term2 = sumOfWeightsForTwoReduced;
8097   term3 = sumOfWeightsForFourReduced;        
8098   if(term2*term3>0.)
8099   {
8100    denominator = 1.-term1/(term2*term3);
8101    prefactor = term1/(term2*term3);
8102    if(TMath::Abs(denominator)>1.e-6)
8103    {
8104     covTwoReducedFourReduced = (twoReducedFourReduced-twoReduced*fourReduced)/denominator;            
8105     wCovTwoReducedFourReduced = covTwoReducedFourReduced*prefactor; 
8106     fDiffFlowCovariances[t][pe][4]->SetBinContent(b,wCovTwoReducedFourReduced);
8107    }
8108   }   
8109  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8110   
8111 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta)
8112
8113 //================================================================================================================================
8114
8115 void AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, TString ptOrEta)
8116 {
8117  // Calculate final results for differential flow.
8118  
8119  // REMARK: Differential flow calculated in this method is NOT corrected for non-uniform acceptance. 
8120  // This correction, if enabled via setter SetApplyCorrectionForNUA(Bool_t), is applied in the method 
8121  // CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
8122   
8123  Int_t t = 0; // RP or POI
8124  Int_t pe = 0; // pt or eta
8125
8126  if(type == "RP")
8127  {
8128   t = 0;
8129  } else if(type == "POI")
8130    {
8131     t = 1;
8132    } 
8133      
8134  if(ptOrEta == "Pt")
8135  {
8136   pe = 0;
8137  } else if(ptOrEta == "Eta")
8138    {
8139     pe = 1;
8140    } 
8141        
8142  // Common:
8143  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8144  // Correlations:
8145  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
8146  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>> 
8147  // Statistical errors of correlations:
8148  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
8149  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2);   
8150  // Reduced correlations:
8151  Double_t twoReduced = 0.; // <<2'>>
8152  Double_t fourReduced = 0.; // <<4'>>
8153  // Statistical errors of reduced correlations:
8154  Double_t twoReducedError = 0.; 
8155  Double_t fourReducedError = 0.; 
8156  // Covariances:
8157  Double_t wCovTwoFour = 0.; // Cov(<2>,<4>) * prefactor(<2>,<4>)
8158  if(!fForgetAboutCovariances)
8159  {
8160   wCovTwoFour = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(<2>,<4>)
8161  }
8162  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
8163  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
8164  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(<4>,<2'>)
8165  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(<4>,<4'>)
8166  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
8167  // Differential flow:
8168  Double_t v2Prime = 0.; // v'{2}                   
8169  Double_t v4Prime = 0.; // v'{4}
8170  // Statistical error of differential flow:
8171  Double_t v2PrimeError = 0.;                    
8172  Double_t v4PrimeError = 0.; 
8173  // Squared statistical error of differential flow:
8174  Double_t v2PrimeErrorSquared = 0.;                    
8175  Double_t v4PrimeErrorSquared = 0.; 
8176  // Loop over pt or eta bins:
8177  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
8178  {
8179   // Reduced correlations and statistical errors:
8180   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
8181   twoReducedError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b);
8182   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
8183   fourReducedError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b);
8184   // Covariances:
8185   if(!fForgetAboutCovariances)
8186   {
8187    wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b);
8188    wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b);
8189    wCovFourTwoReduced = fDiffFlowCovariances[t][pe][2]->GetBinContent(b);
8190    wCovFourFourReduced = fDiffFlowCovariances[t][pe][3]->GetBinContent(b);
8191    wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b);
8192   }
8193   // Differential flow:
8194   // v'{2}:
8195   if(two>0.) 
8196   {
8197    v2Prime = twoReduced/pow(two,0.5);
8198    v2PrimeErrorSquared = (1./4.)*pow(two,-3.)*(pow(twoReduced,2.)*pow(twoError,2.)
8199                        + 4.*pow(two,2.)*pow(twoReducedError,2.)
8200                        - 4.*two*twoReduced*wCovTwoTwoReduced);
8201    if(v2PrimeErrorSquared>0.){v2PrimeError = pow(v2PrimeErrorSquared,0.5);}
8202    if(TMath::Abs(v2Prime)>0.)
8203    {
8204     fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
8205     fDiffFlow[t][pe][0]->SetBinError(b,v2PrimeError);    
8206    }  
8207   } // end of if(two>0.) 
8208   // differential flow:
8209   // v'{4}
8210   if(2.*pow(two,2.)-four > 0.) 
8211   {
8212    v4Prime = (2.*two*twoReduced-fourReduced)/pow(2.*pow(two,2.)-four,3./4.);
8213    v4PrimeErrorSquared = pow(2.*pow(two,2.)-four,-7./2.)
8214                        * (pow(2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced,2.)*pow(twoError,2.)
8215                        + (9./16.)*pow(2.*two*twoReduced-fourReduced,2.)*pow(fourError,2.)
8216                        + 4.*pow(two,2.)*pow(2.*pow(two,2.)-four,2.)*pow(twoReducedError,2.)
8217                        + pow(2.*pow(two,2.)-four,2.)*pow(fourReducedError,2.)                          
8218                        - (3./2.)*(2.*two*twoReduced-fourReduced)
8219                        * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFour
8220                        - 4.*two*(2.*pow(two,2.)-four)
8221                        * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoTwoReduced
8222                        + 2.*(2.*pow(two,2.)-four)
8223                        * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFourReduced
8224                        + 3.*two*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourTwoReduced
8225                        - (3./2.)*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourFourReduced 
8226                        - 4.*two*pow(2.*pow(two,2.)-four,2.)*wCovTwoReducedFourReduced);  
8227    if(v4PrimeErrorSquared>0.){v4PrimeError = pow(v4PrimeErrorSquared,0.5);}        
8228    if(TMath::Abs(v4Prime)>0.)
8229    {
8230     fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);
8231     fDiffFlow[t][pe][1]->SetBinError(b,v4PrimeError);     
8232    }
8233   } // end of if(2.*pow(two,2.)-four > 0.)  
8234  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
8235
8236 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights)
8237
8238 //================================================================================================================================
8239
8240 void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlow(TString type)
8241 {
8242  // Calculate final results for 2D diferential flow.
8243
8244  // to be improved - check pointers used in this method
8245
8246  Int_t t = 0; // RP or POI
8247
8248  if(type == "RP")
8249  {
8250   t = 0;
8251  } else if(type == "POI")
8252    {
8253     t = 1;
8254    } 
8255  
8256  // Differential flow:
8257  Double_t v2Prime = 0.; // v'{2}                   
8258  Double_t v4Prime = 0.; // v'{4}
8259  // Differential cumulants:
8260  Double_t qc2Prime = 0.; // QC{2'}                   
8261  Double_t qc4Prime = 0.; // QC{4'}
8262  // Looping over all (pt,eta) bins and calculating differential flow: 
8263  for(Int_t p=1;p<=fnBinsPt;p++)
8264  {
8265   for(Int_t e=1;e<=fnBinsEta;e++)
8266   {
8267    // QC{2'}:
8268    qc2Prime = f2DDiffFlowCumulants[t][0]->GetBinContent(f2DDiffFlowCumulants[t][0]->GetBin(p,e));
8269    if(qc2Prime>=0.)
8270    {
8271     v2Prime = pow(qc2Prime,0.5);
8272     f2DDiffFlow[t][0]->SetBinContent(f2DDiffFlow[t][0]->GetBin(p,e),v2Prime); 
8273    } 
8274    // QC{4'}:
8275    qc4Prime = f2DDiffFlowCumulants[t][1]->GetBinContent(f2DDiffFlowCumulants[t][1]->GetBin(p,e));
8276    if(qc4Prime<=0.)
8277    {
8278     v4Prime = pow(-1.*qc4Prime,1./4.);
8279     f2DDiffFlow[t][1]->SetBinContent(f2DDiffFlow[t][1]->GetBin(p,e),v4Prime); 
8280    }   
8281   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
8282  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
8283  
8284 } // end of void AliFlowAnalysisWithQCumulants::Calculate2DDiffFlow(TString type)  
8285
8286 //================================================================================================================================
8287
8288 void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
8289 {
8290  // a) Store all flags for integrated flow in profile fIntFlowFlags.
8291  
8292  if(!fIntFlowFlags)
8293  {
8294   cout<<"WARNING: fIntFlowFlags is NULL in AFAWQC::SFFIF() !!!!"<<endl;
8295   exit(0);
8296  } 
8297
8298  // particle weights used or not:
8299  fIntFlowFlags->Fill(0.5,(Int_t)fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights);
8300  // which event weights were used:
8301  if(strcmp(fMultiplicityWeight->Data(),"combinations"))
8302  {
8303   fIntFlowFlags->Fill(1.5,0); // 0 = "combinations" (default)
8304  } else if(strcmp(fMultiplicityWeight->Data(),"unit"))
8305    {
8306     fIntFlowFlags->Fill(1.5,1); // 1 = "unit"   
8307    } else if(strcmp(fMultiplicityWeight->Data(),"multiplicity"))
8308      {
8309       fIntFlowFlags->Fill(1.5,2); // 2 = "multiplicity"        
8310      } 
8311  fIntFlowFlags->Fill(2.5,(Int_t)fApplyCorrectionForNUA);
8312  fIntFlowFlags->Fill(3.5,(Int_t)fPrintFinalResults[0]);
8313  fIntFlowFlags->Fill(4.5,(Int_t)fPrintFinalResults[1]);
8314  fIntFlowFlags->Fill(5.5,(Int_t)fPrintFinalResults[2]);
8315  fIntFlowFlags->Fill(6.5,(Int_t)fPrintFinalResults[3]);
8316  fIntFlowFlags->Fill(7.5,(Int_t)fApplyCorrectionForNUAVsM);
8317  fIntFlowFlags->Fill(8.5,(Int_t)fPropagateErrorAlsoFromNIT);
8318  fIntFlowFlags->Fill(9.5,(Int_t)fCalculateCumulantsVsM);
8319  fIntFlowFlags->Fill(10.5,(Int_t)fMinimumBiasReferenceFlow);
8320  fIntFlowFlags->Fill(11.5,(Int_t)fForgetAboutCovariances);
8321  fIntFlowFlags->Fill(12.5,(Int_t)fStorePhiDistributionForOneEvent); 
8322  fIntFlowFlags->Fill(13.5,(Int_t)fFillMultipleControlHistograms);  
8323  fIntFlowFlags->Fill(14.5,(Int_t)fCalculateAllCorrelationsVsM);  
8324 } // end of void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
8325
8326 //================================================================================================================================
8327
8328 void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
8329 {
8330  // Store all flags for differential flow in the profile fDiffFlowFlags.
8331   
8332  if(!fDiffFlowFlags)
8333  {
8334   printf("\n WARNING (QC): fDiffFlowFlags is NULL in AFAWQC::SDFF() !!!!\n\n");
8335   exit(0);
8336  } 
8337  
8338  fDiffFlowFlags->Fill(0.5,fCalculateDiffFlow); // calculate differential flow
8339  fDiffFlowFlags->Fill(1.5,fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights); // particle weights used or not?
8340  //fDiffFlowFlags->Fill(2.5,""); // which event weight was used? ("combinations", "unit" or "multiplicity") to be improved - finalized
8341  fDiffFlowFlags->Fill(3.5,fApplyCorrectionForNUA); // corrected for non-uniform acceptance or not
8342  fDiffFlowFlags->Fill(4.5,fCalculate2DDiffFlow); // calculate also 2D differential flow vs (pt,eta) 
8343  fDiffFlowFlags->Fill(5.5,fCalculateDiffFlowVsEta); // if you set kFALSE only differential flow vs pt is calculated
8344      
8345 } // end of void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
8346
8347 //================================================================================================================================
8348
8349 void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
8350 {
8351  // Access all pointers to common control and common result histograms and profiles.
8352  
8353  TString sCommonConstantsName = "fCommonConstants";
8354  sCommonConstantsName += fAnalysisLabel->Data();
8355  fCommonConstants = dynamic_cast<TProfile*>(fHistList->FindObject(sCommonConstantsName.Data()));
8356  if(!fCommonConstants)
8357  {
8358   printf("\n WARNING (QC): fCommonConstants is NULL in AFAWQC::GPFCH() !!!!\n\n");
8359   exit(0);
8360  }
8361  
8362  // to be improved - lines bellow can be implemented better.
8363  
8364  TString commonHistsName = "AliFlowCommonHistQC";
8365  commonHistsName += fAnalysisLabel->Data();
8366  AliFlowCommonHist *commonHist = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHistsName.Data()));
8367  if(commonHist) 
8368  {
8369   this->SetCommonHists(commonHist); 
8370   if(fCommonHists->GetHarmonic())
8371   {
8372    fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
8373   } 
8374  } // end of if(commonHist) 
8375  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
8376  commonHists2ndOrderName += fAnalysisLabel->Data();
8377  AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists2ndOrderName.Data()));
8378  if(commonHist2nd) this->SetCommonHists2nd(commonHist2nd);   
8379  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
8380  commonHists4thOrderName += fAnalysisLabel->Data();
8381  AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists4thOrderName.Data()));
8382  if(commonHist4th) this->SetCommonHists4th(commonHist4th);  
8383  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
8384  commonHists6thOrderName += fAnalysisLabel->Data();
8385  AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists6thOrderName.Data()));
8386  if(commonHist6th) this->SetCommonHists6th(commonHist6th);  
8387  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
8388  commonHists8thOrderName += fAnalysisLabel->Data();
8389  AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists8thOrderName.Data()));
8390  if(commonHist8th) this->SetCommonHists8th(commonHist8th); 
8391   
8392  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC"; 
8393  commonHistResults2ndOrderName += fAnalysisLabel->Data(); 
8394  AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>
8395                                               (fHistList->FindObject(commonHistResults2ndOrderName.Data()));
8396  if(commonHistRes2nd) this->SetCommonHistsResults2nd(commonHistRes2nd);   
8397  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
8398  commonHistResults4thOrderName += fAnalysisLabel->Data();
8399  AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>
8400                                               (fHistList->FindObject(commonHistResults4thOrderName.Data()));
8401  if(commonHistRes4th) this->SetCommonHistsResults4th(commonHistRes4th);  
8402  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
8403  commonHistResults6thOrderName += fAnalysisLabel->Data();
8404  AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>
8405                                               (fHistList->FindObject(commonHistResults6thOrderName.Data()));
8406  if(commonHistRes6th) this->SetCommonHistsResults6th(commonHistRes6th);  
8407  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
8408  commonHistResults8thOrderName += fAnalysisLabel->Data();
8409  AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>
8410                                               (fHistList->FindObject(commonHistResults8thOrderName.Data()));  
8411  if(commonHistRes8th) this->SetCommonHistsResults8th(commonHistRes8th);
8412        
8413 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
8414
8415 //================================================================================================================================
8416
8417 void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms() 
8418 {
8419  // Get pointers for histograms with particle weights.
8420
8421  TList *weightsList = dynamic_cast<TList*>(fHistList->FindObject("Weights"));
8422  if(!weightsList){printf("\n WARNING (QC): weightsList is NULL in AFAWQC::GPFPWH() !!!!\n");exit(0);}
8423  this->SetWeightsList(weightsList);
8424  TString fUseParticleWeightsName = "fUseParticleWeightsQC"; // to be improved (hirdwired label QC)
8425  fUseParticleWeightsName += fAnalysisLabel->Data();
8426  TProfile *useParticleWeights = dynamic_cast<TProfile*>(weightsList->FindObject(fUseParticleWeightsName.Data()));
8427  if(useParticleWeights)
8428  {
8429   this->SetUseParticleWeights(useParticleWeights);  
8430   fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
8431   fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
8432   fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3);  
8433   fUseTrackWeights = (Int_t)fUseParticleWeights->GetBinContent(4);  
8434  }
8435 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms(); 
8436
8437 //================================================================================================================================
8438
8439 void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms() 
8440 {
8441  // Get pointers for histograms and profiles relevant for integrated flow:
8442  //  a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults.
8443  //  b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow.
8444  //  c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds. 
8445  //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
8446   
8447  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data member?)
8448  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data member?)
8449  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?)
8450  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?)
8451  
8452  // a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults:
8453  TList *intFlowList = NULL;
8454  intFlowList = dynamic_cast<TList*>(fHistList->FindObject("Integrated Flow"));
8455  if(!intFlowList) 
8456  {
8457   cout<<"WARNING: intFlowList is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8458   exit(0); 
8459  }  
8460   
8461  // b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow:
8462  TString intFlowFlagsName = "fIntFlowFlags";
8463  intFlowFlagsName += fAnalysisLabel->Data();
8464  TProfile *intFlowFlags = dynamic_cast<TProfile*>(intFlowList->FindObject(intFlowFlagsName.Data()));
8465  if(intFlowFlags)
8466  {
8467   this->SetIntFlowFlags(intFlowFlags);  
8468   fApplyCorrectionForNUA = (Bool_t)intFlowFlags->GetBinContent(3); 
8469   fApplyCorrectionForNUAVsM = (Bool_t)intFlowFlags->GetBinContent(8); 
8470   fCalculateCumulantsVsM = (Bool_t)intFlowFlags->GetBinContent(10);  
8471  } else 
8472    {
8473     cout<<"WARNING: intFlowFlags is NULL in FAWQC::GPFIFH() !!!!"<<endl;
8474    }
8475   
8476   // c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds:
8477   TList *intFlowProfiles = NULL;
8478   intFlowProfiles = dynamic_cast<TList*>(intFlowList->FindObject("Profiles"));
8479   if(intFlowProfiles)  
8480   {
8481    // average multiplicities:
8482    TString avMultiplicityName = "fAvMultiplicity";
8483    avMultiplicityName += fAnalysisLabel->Data();
8484    TProfile *avMultiplicity = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(avMultiplicityName.Data()));
8485    if(avMultiplicity) 
8486    {
8487     this->SetAvMultiplicity(avMultiplicity);
8488    } else 
8489      {
8490       cout<<"WARNING: avMultiplicity is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8491      }
8492    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with wrong errors!):
8493    TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
8494    intFlowCorrelationsProName += fAnalysisLabel->Data();
8495    TProfile *intFlowCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsProName.Data()));
8496    if(intFlowCorrelationsPro) 
8497    {
8498     this->SetIntFlowCorrelationsPro(intFlowCorrelationsPro);
8499    } else 
8500      {
8501       cout<<"WARNING: intFlowCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8502      }      
8503    // average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8^2>>:
8504    TString intFlowSquaredCorrelationsProName = "fIntFlowSquaredCorrelationsPro";
8505    intFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
8506    TProfile *intFlowSquaredCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowSquaredCorrelationsProName.Data()));
8507    if(intFlowSquaredCorrelationsPro) 
8508    {
8509     this->SetIntFlowSquaredCorrelationsPro(intFlowSquaredCorrelationsPro);
8510    } else 
8511      {
8512       cout<<"WARNING: intFlowSquaredCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8513      }             
8514    if(fCalculateCumulantsVsM)
8515    {
8516     // Average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (error is wrong here):   
8517     TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
8518     intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
8519     for(Int_t ci=0;ci<4;ci++) // correlation index
8520     {
8521      TProfile *intFlowCorrelationsVsMPro = dynamic_cast<TProfile*>
8522                                         (intFlowProfiles->FindObject(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data())));
8523      if(intFlowCorrelationsVsMPro)
8524      {
8525       this->SetIntFlowCorrelationsVsMPro(intFlowCorrelationsVsMPro,ci);
8526      } else
8527        {
8528         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8529        }   
8530     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
8531     // Average squared correlations <<2>^2>, <<4>^2>, <<6>^2> and <<8>^2> versus multiplicity for all events:   
8532     TString intFlowSquaredCorrelationsVsMProName = "fIntFlowSquaredCorrelationsVsMPro";
8533     intFlowSquaredCorrelationsVsMProName += fAnalysisLabel->Data();
8534     for(Int_t ci=0;ci<4;ci++) // correlation index
8535     {
8536      TProfile *intFlowSquaredCorrelationsVsMPro = dynamic_cast<TProfile*>
8537                       (intFlowProfiles->FindObject(Form("%s, %s",intFlowSquaredCorrelationsVsMProName.Data(),squaredCorrelationFlag[ci].Data())));
8538      if(intFlowSquaredCorrelationsVsMPro)
8539      {
8540       this->SetIntFlowSquaredCorrelationsVsMPro(intFlowSquaredCorrelationsVsMPro,ci);
8541      } else
8542        {
8543         cout<<"WARNING: "<<Form("intFlowSquaredCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8544        }   
8545     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
8546    } // end of if(fCalculateCumulantsVsM)
8547    // average all correlations for integrated flow (with wrong errors!):
8548    TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
8549    intFlowCorrelationsAllProName += fAnalysisLabel->Data();
8550    TProfile *intFlowCorrelationsAllPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsAllProName.Data()));
8551    if(intFlowCorrelationsAllPro) 
8552    {
8553     this->SetIntFlowCorrelationsAllPro(intFlowCorrelationsAllPro);
8554    } else 
8555      {
8556       cout<<"WARNING: intFlowCorrelationsAllPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8557      }     
8558    // average extra correlations for integrated flow (which appear only when particle weights are used):
8559    // (to be improved: Weak point in implementation, I am assuming here that method GetPointersForParticleWeightsHistograms() was called)
8560    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
8561    {
8562     TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
8563     intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
8564     TProfile *intFlowExtraCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowExtraCorrelationsProName.Data()));
8565     if(intFlowExtraCorrelationsPro) 
8566     {
8567      this->SetIntFlowExtraCorrelationsPro(intFlowExtraCorrelationsPro);
8568     } else 
8569       {
8570        cout<<"WARNING: intFlowExtraCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8571       }
8572    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)        
8573    // average products of correlations <2>, <4>, <6> and <8>:  
8574    TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
8575    intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
8576    TProfile *intFlowProductOfCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrelationsProName.Data()));
8577    if(intFlowProductOfCorrelationsPro) 
8578    {
8579     this->SetIntFlowProductOfCorrelationsPro(intFlowProductOfCorrelationsPro);
8580    } else 
8581      {
8582       cout<<"WARNING: intFlowProductOfCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8583      }               
8584    // average product of correlations <2>, <4>, <6> and <8> versus multiplicity  
8585    // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
8586    if(fCalculateCumulantsVsM)
8587    {
8588     TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
8589     intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
8590     TString productFlag[6] = {"#LT#LT2#GT#LT4#GT#GT","#LT#LT2#GT#LT6#GT#GT","#LT#LT2#GT#LT8#GT#GT",
8591                               "#LT#LT4#GT#LT6#GT#GT","#LT#LT4#GT#LT8#GT#GT","#LT#LT6#GT#LT8#GT#GT"};
8592     for(Int_t pi=0;pi<6;pi++)
8593     { 
8594      TProfile *intFlowProductOfCorrelationsVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data())));
8595      if(intFlowProductOfCorrelationsVsMPro)
8596      {
8597       this->SetIntFlowProductOfCorrelationsVsMPro(intFlowProductOfCorrelationsVsMPro,pi);
8598      } else
8599        {
8600         cout<<"WARNING: "<<Form("intFlowProductOfCorrelationsVsMPro[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8601        }
8602     } // end of for(Int_t pi=0;pi<6;pi++)
8603    } // end of if(fCalculateCumulantsVsM)
8604    // average correction terms for non-uniform acceptance (with wrong errors!):
8605    for(Int_t sc=0;sc<2;sc++)
8606    {
8607     TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
8608     intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
8609     TProfile *intFlowCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()))));
8610     if(intFlowCorrectionTermsForNUAPro) 
8611     {
8612      this->SetIntFlowCorrectionTermsForNUAPro(intFlowCorrectionTermsForNUAPro,sc);
8613     } else 
8614       {
8615        cout<<"WARNING: intFlowCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8616        cout<<"sc = "<<sc<<endl;
8617       } 
8618     // versus multiplicity:
8619     if(fCalculateCumulantsVsM)
8620     {
8621      TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
8622      TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
8623      intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
8624      for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
8625      {
8626       TProfile *intFlowCorrectionTermsForNUAVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s: #LT#LT%s%s#GT#GT",intFlowCorrectionTermsForNUAVsMProName.Data(),sinCosFlag[sc].Data(),correctionTermFlag[ci].Data())));
8627       if(intFlowCorrectionTermsForNUAVsMPro) 
8628       {
8629        this->SetIntFlowCorrectionTermsForNUAVsMPro(intFlowCorrectionTermsForNUAVsMPro,sc,ci);
8630       } else 
8631         {
8632          cout<<"WARNING: intFlowCorrectionTermsForNUAVsMPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8633          cout<<"sc = "<<sc<<endl;
8634          cout<<"ci = "<<ci<<endl;
8635         }       
8636      } // end of for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
8637     } // end of if(fCalculateCumulantsVsM)
8638    } // end of for(Int_t sc=0;sc<2;sc++)           
8639    // average products of correction terms for NUA:  
8640    TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
8641    intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
8642    TProfile *intFlowProductOfCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrectionTermsForNUAProName.Data()));
8643    if(intFlowProductOfCorrectionTermsForNUAPro) 
8644    {
8645     this->SetIntFlowProductOfCorrectionTermsForNUAPro(intFlowProductOfCorrectionTermsForNUAPro);
8646    } else 
8647      {
8648       cout<<"WARNING: intFlowProductOfCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8649      }     
8650   } else // to if(intFlowProfiles)  
8651     {
8652      cout<<"WARNING: intFlowProfiles is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8653     }
8654    
8655   //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
8656   TList *intFlowResults = NULL;
8657   intFlowResults = dynamic_cast<TList*>(intFlowList->FindObject("Results"));
8658   if(intFlowResults)
8659   {
8660    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!):
8661    TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
8662    intFlowCorrelationsHistName += fAnalysisLabel->Data();
8663    TH1D *intFlowCorrelationsHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsHistName.Data()));
8664    if(intFlowCorrelationsHist) 
8665    {
8666     this->SetIntFlowCorrelationsHist(intFlowCorrelationsHist);
8667    } else 
8668      {
8669       cout<<"WARNING: intFlowCorrelationsHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8670      } 
8671    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!) vs M:    
8672    if(fCalculateCumulantsVsM)
8673    {
8674     TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
8675     intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
8676     for(Int_t ci=0;ci<4;ci++) // correlation index
8677     {
8678      TH1D *intFlowCorrelationsVsMHist = dynamic_cast<TH1D*>
8679                                         (intFlowResults->FindObject(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data())));
8680      if(intFlowCorrelationsVsMHist)
8681      {
8682       this->SetIntFlowCorrelationsVsMHist(intFlowCorrelationsVsMHist,ci);
8683      } else
8684        {
8685         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMHist[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8686        }   
8687     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8688    } // end of if(fCalculateCumulantsVsM)
8689    // average all correlations for integrated flow (with correct errors!):
8690    TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
8691    intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
8692    TH1D *intFlowCorrelationsAllHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsAllHistName.Data()));
8693    if(intFlowCorrelationsAllHist) 
8694    {
8695     this->SetIntFlowCorrelationsAllHist(intFlowCorrelationsAllHist);
8696    } else 
8697      {
8698       cout<<"WARNING: intFlowCorrelationsAllHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8699      }  
8700    // average correction terms for non-uniform acceptance (with correct errors!):
8701    TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
8702    intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
8703    for(Int_t sc=0;sc<2;sc++)
8704    {
8705     TH1D *intFlowCorrectionTermsForNUAHist = dynamic_cast<TH1D*>(intFlowResults->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()))));
8706     if(intFlowCorrectionTermsForNUAHist) 
8707     {
8708      this->SetIntFlowCorrectionTermsForNUAHist(intFlowCorrectionTermsForNUAHist,sc);
8709     } else 
8710       {
8711        cout<<"WARNING: intFlowCorrectionTermsForNUAHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8712        cout<<"sc = "<<sc<<endl;
8713       } 
8714    } // end of for(Int_t sc=0;sc<2;sc++)           
8715    // covariances (multiplied with weight dependent prefactor):
8716    TString intFlowCovariancesName = "fIntFlowCovariances";
8717    intFlowCovariancesName += fAnalysisLabel->Data();
8718    TH1D *intFlowCovariances = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesName.Data()));
8719    if(intFlowCovariances) 
8720    {
8721     this->SetIntFlowCovariances(intFlowCovariances); 
8722    } else 
8723      {
8724       cout<<"WARNING: intFlowCovariances is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8725      } 
8726    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
8727    TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
8728    intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
8729    for(Int_t power=0;power<2;power++)
8730    {
8731     TH1D *intFlowSumOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s",intFlowSumOfEventWeightsName.Data(),powerFlag[power].Data())));
8732     if(intFlowSumOfEventWeights) 
8733     {
8734      this->SetIntFlowSumOfEventWeights(intFlowSumOfEventWeights,power);
8735     } else 
8736       {
8737        cout<<"WARNING: intFlowSumOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8738        cout<<"power = "<<power<<endl;
8739       }                                   
8740    } // end of for(Int_t power=0;power<2;power++)                                                                  
8741    // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
8742    TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
8743    intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
8744    TH1D *intFlowSumOfProductOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsName.Data()));
8745    if(intFlowSumOfProductOfEventWeights) 
8746    {
8747     this->SetIntFlowSumOfProductOfEventWeights(intFlowSumOfProductOfEventWeights);
8748    } else 
8749      {
8750       cout<<"WARNING: intFlowSumOfProductOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8751      } 
8752    // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
8753    // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
8754    if(fCalculateCumulantsVsM)
8755    {
8756     TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
8757     intFlowCovariancesVsMName += fAnalysisLabel->Data();
8758     TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
8759     for(Int_t ci=0;ci<6;ci++)
8760     { 
8761      TH1D *intFlowCovariancesVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data())));
8762      if(intFlowCovariancesVsM)
8763      {
8764       this->SetIntFlowCovariancesVsM(intFlowCovariancesVsM,ci);
8765      } else
8766        {
8767         cout<<"WARNING: "<<Form("intFlowCovariancesVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8768        }    
8769     } // end of for(Int_t ci=0;ci<6;ci++)
8770    } // end of if(fCalculateCumulantsVsM)
8771    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
8772    // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
8773    if(fCalculateCumulantsVsM)
8774    {
8775     TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
8776     intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
8777     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>}"},
8778                              {"#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}"}};
8779     for(Int_t si=0;si<4;si++)
8780     {
8781      for(Int_t power=0;power<2;power++)
8782      {
8783       TH1D *intFlowSumOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data())));
8784       if(intFlowSumOfEventWeightsVsM)
8785       {
8786        this->SetIntFlowSumOfEventWeightsVsM(intFlowSumOfEventWeightsVsM,si,power);
8787       } else
8788         {
8789          cout<<"WARNING: "<<Form("intFlowSumOfEventWeightsVsM[%d][%d]",si,power)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8790         }    
8791      } // end of for(Int_t power=0;power<2;power++)
8792     } // end of for(Int_t si=0;si<4;si++)   
8793    } // end of if(fCalculateCumulantsVsM)
8794    // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
8795    // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
8796    //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
8797    if(fCalculateCumulantsVsM)
8798    {
8799     TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
8800     intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
8801     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>}",
8802                             "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
8803     for(Int_t pi=0;pi<6;pi++)
8804     {
8805      TH1D *intFlowSumOfProductOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data())));
8806      if(intFlowSumOfProductOfEventWeightsVsM)
8807      {
8808       this->SetIntFlowSumOfProductOfEventWeightsVsM(intFlowSumOfProductOfEventWeightsVsM,pi);
8809      } else
8810        {
8811         cout<<"WARNING: "<<Form("intFlowSumOfProductOfEventWeightsVsM[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8812        }
8813     } // end of for(Int_t pi=0;pi<6;pi++)        
8814    } // end of if(fCalculateCumulantsVsM)
8815    // covariances for NUA (multiplied with weight dependent prefactor):
8816    TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
8817    intFlowCovariancesNUAName += fAnalysisLabel->Data();
8818    TH1D *intFlowCovariancesNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesNUAName.Data()));
8819    if(intFlowCovariancesNUA) 
8820    {
8821     this->SetIntFlowCovariancesNUA(intFlowCovariancesNUA); 
8822    } else 
8823      {
8824       cout<<"WARNING: intFlowCovariancesNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8825      } 
8826    // sum of linear and quadratic event weights NUA terms:
8827    TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
8828    intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
8829    for(Int_t sc=0;sc<2;sc++)
8830    {
8831     for(Int_t power=0;power<2;power++)
8832     {
8833      TH1D *intFlowSumOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s, %s",intFlowSumOfEventWeightsNUAName.Data(),powerFlag[power].Data(),sinCosFlag[sc].Data())));
8834      if(intFlowSumOfEventWeightsNUA) 
8835      {
8836       this->SetIntFlowSumOfEventWeightsNUA(intFlowSumOfEventWeightsNUA,sc,power);
8837      } else 
8838        {
8839         cout<<"WARNING: intFlowSumOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8840         cout<<"sc    = "<<sc<<endl;
8841         cout<<"power = "<<power<<endl;
8842        }                                   
8843     } // end of for(Int_t power=0;power<2;power++)                                                                  
8844    } // end of for(Int_t sc=0;sc<2;sc++)     
8845    // sum of products of event weights for NUA terms:  
8846    TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
8847    intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
8848    TH1D *intFlowSumOfProductOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsNUAName.Data()));
8849    if(intFlowSumOfProductOfEventWeightsNUA) 
8850    {
8851     this->SetIntFlowSumOfProductOfEventWeightsNUA(intFlowSumOfProductOfEventWeightsNUA);
8852    } else 
8853      {
8854       cout<<"WARNING: intFlowSumOfProductOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8855      } 
8856    // Final results for reference Q-cumulants:
8857    TString intFlowQcumulantsName = "fIntFlowQcumulants";
8858    intFlowQcumulantsName += fAnalysisLabel->Data();
8859    TH1D *intFlowQcumulants = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsName.Data()));
8860    if(intFlowQcumulants) 
8861    {
8862     this->SetIntFlowQcumulants(intFlowQcumulants);
8863    } else 
8864      {
8865       cout<<"WARNING: intFlowQcumulants is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8866      }  
8867    // Final results for reference Q-cumulants rebinned in M:
8868    if(fCalculateCumulantsVsM)
8869    {
8870     TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
8871     intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
8872     TH1D *intFlowQcumulantsRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsRebinnedInMName.Data()));
8873     if(intFlowQcumulantsRebinnedInM) 
8874     {
8875      this->SetIntFlowQcumulantsRebinnedInM(intFlowQcumulantsRebinnedInM);
8876     } else 
8877       {
8878        cout<<"WARNING: intFlowQcumulantsRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8879       }  
8880    } // end of if(fCalculateCumulantsVsM)
8881    // Ratio between error squared: with/without non-isotropic terms:
8882    TString intFlowQcumulantsErrorSquaredRatioName = "fIntFlowQcumulantsErrorSquaredRatio";
8883    intFlowQcumulantsErrorSquaredRatioName += fAnalysisLabel->Data();
8884    TH1D *intFlowQcumulantsErrorSquaredRatio = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsErrorSquaredRatioName.Data()));
8885    if(intFlowQcumulantsErrorSquaredRatio) 
8886    {
8887     this->SetIntFlowQcumulantsErrorSquaredRatio(intFlowQcumulantsErrorSquaredRatio);
8888    } else 
8889      {
8890       cout<<" WARNING: intntFlowQcumulantsErrorSquaredRatio is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8891      }  
8892    // final results for integrated Q-cumulants versus multiplicity:
8893    TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
8894    if(fCalculateCumulantsVsM)
8895    {
8896     TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
8897     intFlowQcumulantsVsMName += fAnalysisLabel->Data();
8898     for(Int_t co=0;co<4;co++) // cumulant order
8899     {
8900      TH1D *intFlowQcumulantsVsM = dynamic_cast<TH1D*>
8901                                   (intFlowResults->FindObject(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data())));
8902      if(intFlowQcumulantsVsM)
8903      {
8904       this->SetIntFlowQcumulantsVsM(intFlowQcumulantsVsM,co);
8905      } else
8906        {
8907         cout<<"WARNING: "<<Form("intFlowQcumulantsVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8908        }
8909     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8910    } // end of if(fCalculateCumulantsVsM)
8911    // Final reference flow estimates from Q-cumulants:
8912    TString intFlowName = "fIntFlow";
8913    intFlowName += fAnalysisLabel->Data();
8914    TH1D *intFlow = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowName.Data()));
8915    if(intFlow) 
8916    {
8917     this->SetIntFlow(intFlow);
8918    } else 
8919      {
8920       cout<<"WARNING: intFlow is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8921      } 
8922    // Final reference flow estimates from Q-cumulants vs M rebinned in M:
8923    if(fCalculateCumulantsVsM)
8924    {
8925     TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
8926     intFlowRebinnedInMName += fAnalysisLabel->Data();
8927     TH1D *intFlowRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowRebinnedInMName.Data()));
8928     if(intFlowRebinnedInM) 
8929     {
8930      this->SetIntFlowRebinnedInM(intFlowRebinnedInM);
8931     } else 
8932       {
8933        cout<<"WARNING: intFlowRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8934       } 
8935    } // end of if(fCalculateCumulantsVsM)
8936    // integrated flow from Q-cumulants versus multiplicity:
8937    if(fCalculateCumulantsVsM)
8938    {
8939     TString intFlowVsMName = "fIntFlowVsM";
8940     intFlowVsMName += fAnalysisLabel->Data();
8941     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)};
8942     for(Int_t co=0;co<4;co++) // cumulant order
8943     {
8944      TH1D *intFlowVsM = dynamic_cast<TH1D*>
8945                         (intFlowResults->FindObject(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data())));            
8946      if(intFlowVsM)
8947      {
8948       this->SetIntFlowVsM(intFlowVsM,co);
8949      } else
8950        {
8951         cout<<"WARNING: "<<Form("intFlowVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8952        }
8953     } // end of for(Int_t co=0;co<4;co++) // cumulant order
8954    } // end of if(fCalculateCumulantsVsM)
8955    // quantifying detector effects effects to correlations:
8956    TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
8957    intFlowDetectorBiasName += fAnalysisLabel->Data();
8958    TH1D *intFlowDetectorBias = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowDetectorBiasName.Data()));
8959    if(intFlowDetectorBias) 
8960    {
8961     this->SetIntFlowDetectorBias(intFlowDetectorBias);
8962    } else 
8963      {
8964       cout<<"WARNING: intFlowDetectorBias is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
8965      } 
8966    // quantifying detector effects effects to correlations vs multiplicity:
8967    if(fCalculateCumulantsVsM)
8968    {
8969     TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
8970     intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
8971     for(Int_t ci=0;ci<4;ci++) // correlation index
8972     {
8973      TH1D *intFlowDetectorBiasVsM = dynamic_cast<TH1D*>
8974                                     (intFlowResults->FindObject(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data())));
8975      if(intFlowDetectorBiasVsM)
8976      {
8977       this->SetIntFlowDetectorBiasVsM(intFlowDetectorBiasVsM,ci);
8978      } else
8979        {
8980         cout<<"WARNING: "<<Form("intFlowDetectorBiasVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8981        }
8982     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8983    } // end of if(fCalculateCumulantsVsM)
8984   } else // to if(intFlowResults)
8985     {
8986      cout<<"WARNING: intFlowResults is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8987     }
8988     
8989 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms()
8990
8991 //================================================================================================================================
8992
8993 void AliFlowAnalysisWithQCumulants::GetPointersFor2DDiffFlowHistograms()
8994 {
8995  // Get pointers for 2D differential flow histograms.
8996  //  a) Check pointers used in this method;
8997  //  b) Get pointers to 2D differential flow lists;
8998  //  c) Get pointers to 2D differential flow profiles;
8999  //  d) Get pointers to 2D differential flow histograms. 
9000
9001  // a) Check pointers used in this method:
9002  if(!fDiffFlowList)
9003  { 
9004   printf("\n WARNING (QC): fDiffFlowList is NULL in AFAWQC::GPF2DDFH() !!!!\n");
9005   printf("               Call method GetPointersForDiffFlowHistograms() first.\n\n");
9006   exit(0);
9007  }
9008  if(!fDiffFlowFlags)
9009  { 
9010   printf("\n WARNING (QC): fDiffFlowFlags is NULL in AFAWQC::GPF2DDFH() !!!!\n\n");
9011   printf("               Call method GetPointersForDiffFlowHistograms() first.\n\n");
9012   exit(0);
9013  }
9014  
9015  // b) Get pointers to 2D differential flow lists:
9016  this->SetCalculate2DDiffFlow((Bool_t)fDiffFlowFlags->GetBinContent(5)); // to be improved - hardwired 5
9017  if(!fCalculate2DDiffFlow){return;}
9018  TString typeFlag[2] = {"RP","POI"}; 
9019  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
9020  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
9021  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
9022  // Base list: 
9023  TString diffFlow2DListName = "2D"; 
9024  diffFlow2DListName += fAnalysisLabel->Data();
9025  fDiffFlow2D = dynamic_cast<TList*>(fDiffFlowList->FindObject(diffFlow2DListName.Data()));
9026  if(!fDiffFlow2D)
9027  { 
9028   printf("\n WARNING (QC): fDiffFlow2D is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9029   exit(0);
9030  }
9031  // Lists holding profiles with 2D correlations: 
9032  TString s2DDiffFlowCorrelationsProListName = "Profiles with 2D correlations"; 
9033  s2DDiffFlowCorrelationsProListName += fAnalysisLabel->Data(); // to be improved
9034  for(Int_t t=0;t<2;t++)
9035  {
9036   f2DDiffFlowCorrelationsProList[t] = dynamic_cast<TList*>(fDiffFlow2D->FindObject(Form("Profiles with 2D correlations (%s)",typeFlag[t].Data())));
9037   if(!f2DDiffFlowCorrelationsProList[t])
9038   { 
9039    printf("\n WARNING (QC): f2DDiffFlowCorrelationsProList[%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t);
9040    exit(0);
9041   }
9042  } // end of for(Int_t t=0;t<2;t++) 
9043  
9044  // c) Get pointers to 2D differential flow profiles:
9045  TString s2DDiffFlowCorrelationsProName = "f2DDiffFlowCorrelationsPro";
9046  s2DDiffFlowCorrelationsProName += fAnalysisLabel->Data();
9047  for(Int_t t=0;t<2;t++) // type: RP or POI
9048  { 
9049   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9050   {
9051    f2DDiffFlowCorrelationsPro[t][rci] = dynamic_cast<TProfile2D*>(f2DDiffFlowCorrelationsProList[t]->FindObject(Form("%s, %s, %s",s2DDiffFlowCorrelationsProName.Data(),typeFlag[t].Data(),reducedCorrelationIndex[rci].Data())));
9052    if(!f2DDiffFlowCorrelationsPro[t][rci])
9053    {
9054     printf("\n WARNING (QC): f2DDiffFlowCorrelationsPro[%i][%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t,rci);
9055     exit(0);   
9056    } else
9057      {
9058       this->Set2DDiffFlowCorrelationsPro(f2DDiffFlowCorrelationsPro[t][rci],t,rci);
9059      } 
9060   } // end of for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9061  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
9062
9063  // d) Get pointers to 2D differential flow histograms: 
9064  TString s2DDiffFlowCumulantsName = "f2DDiffFlowCumulants";
9065  s2DDiffFlowCumulantsName += fAnalysisLabel->Data();
9066  TString s2DDiffFlowName = "f2DDiffFlow";
9067  s2DDiffFlowName += fAnalysisLabel->Data();
9068  for(Int_t t=0;t<2;t++) // type: RP or POI
9069  { 
9070   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9071   {
9072    // 2D differential cumulants:
9073    f2DDiffFlowCumulants[t][rci] = dynamic_cast<TH2D*>(f2DDiffFlowCorrelationsProList[t]->FindObject(Form("%s, %s, %s",s2DDiffFlowCumulantsName.Data(),typeFlag[t].Data(),differentialCumulantIndex[rci].Data())));
9074    if(!f2DDiffFlowCumulants[t][rci])
9075    {
9076     printf("\n WARNING (QC): f2DDiffFlowCumulants[%i][%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t,rci);
9077     exit(0);   
9078    } else
9079      {
9080       this->Set2DDiffFlowCumulants(f2DDiffFlowCumulants[t][rci],t,rci);
9081      } 
9082    // 2D differential flow:
9083    f2DDiffFlow[t][rci] = dynamic_cast<TH2D*>(f2DDiffFlowCorrelationsProList[t]->FindObject(Form("%s, %s, %s",s2DDiffFlowName.Data(),typeFlag[t].Data(),differentialFlowIndex[rci].Data())));
9084    if(!f2DDiffFlow[t][rci])
9085    {
9086     printf("\n WARNING (QC): f2DDiffFlow[%i][%i] is NULL in AFAWQC::GPF2DFH() !!!!\n\n",t,rci);
9087     exit(0);   
9088    } else
9089      {
9090       this->Set2DDiffFlow(f2DDiffFlow[t][rci],t,rci);
9091      } 
9092   } // end of for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9093  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
9094   
9095 } // end of void AliFlowAnalysisWithQCumulants::GetPointersFor2DDiffFlowHistograms()
9096
9097 //================================================================================================================================
9098
9099 void AliFlowAnalysisWithQCumulants::GetPointersForOtherDiffCorrelators()
9100 {
9101  // Get pointers for other differential correlators.
9102  //  a) Get pointer to list with other differential correlators;
9103  //  b) Declare local flags;
9104  //  c) Get pointers to other differential profiles.
9105
9106  if(!fCalculateDiffFlow){return;} // TBI: This must eventually be moved somewhere else 
9107
9108  // a) Get pointer to list with other differential correlators:
9109  fOtherDiffCorrelatorsList = dynamic_cast<TList*>(fHistList->FindObject("Other differential correlators"));  
9110  if(!fOtherDiffCorrelatorsList)
9111  { 
9112   printf("\n WARNING (QC): fOtherDiffCorrelatorsList is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9113   exit(0);
9114  }
9115  
9116  // b) Declare local flags: // (to be improved - promoted to data members)
9117  TString typeFlag[2] = {"RP","POI"}; 
9118  TString ptEtaFlag[2] = {"p_{T}","#eta"};
9119  TString sinCosFlag[2] = {"sin","cos"}; 
9120   
9121  // c) Get pointers to other differential profiles:
9122  TString otherDiffCorrelatorsName = "fOtherDiffCorrelators";
9123  otherDiffCorrelatorsName += fAnalysisLabel->Data();
9124  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9125  { 
9126   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9127   {
9128    for(Int_t sc=0;sc<2;sc++) // sin or cos
9129    {
9130     for(Int_t ci=0;ci<1;ci++) // correlator index
9131     {
9132      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))); 
9133      if(!fOtherDiffCorrelators[t][pe][sc][ci])
9134      {
9135       printf("\n WARNING (QC): fOtherDiffCorrelators[%i][%i][%i][%i] is NULL in AFAWQC::GPFODC() !!!!\n\n",t,pe,sc,ci);
9136       exit(0);       
9137      } else
9138        {
9139         this->SetOtherDiffCorrelators(fOtherDiffCorrelators[t][pe][sc][ci],t,pe,sc,ci);     
9140        } 
9141     } // end of for(Int_t ci=0;ci<1;ci++) // correlator index
9142    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9143   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9144  } // end of for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9145   
9146 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForOtherDiffCorrelators()
9147
9148 //================================================================================================================================
9149
9150 void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
9151 {
9152  // Get pointer to all objects relevant for differential flow.
9153  //  a) Get pointer to base list for differential flow fDiffFlowList;
9154  //  b) Get pointer to profile fDiffFlowFlags holding all flags for differential flow. Access and set some flags;
9155  //  c) Get pointers to nested lists fDiffFlowListProfiles and fDiffFlowListResults;
9156  //  d) Define flags locally (to be improved: should I promote these flags to data members?);
9157  //  e) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
9158  //  f) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
9159  
9160  // a) Get pointer to base list for differential flow fDiffFlowList:
9161  fDiffFlowList = dynamic_cast<TList*>(fHistList->FindObject("Differential Flow"));  
9162  if(!fDiffFlowList)
9163  { 
9164   printf("\n WARNING (QC): fDiffFlowList is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9165   exit(0);
9166  }
9167  
9168  // b) Get pointer to profile fDiffFlowFlags holding all flags for differential flow. Access and set some flags:
9169  TString diffFlowFlagsName = "fDiffFlowFlags";
9170  diffFlowFlagsName += fAnalysisLabel->Data();
9171  fDiffFlowFlags = dynamic_cast<TProfile*>(fDiffFlowList->FindObject(diffFlowFlagsName.Data()));
9172  if(fDiffFlowFlags)
9173  {
9174   this->SetCalculateDiffFlow((Bool_t)fDiffFlowFlags->GetBinContent(1)); // to be improved - hardwired 1
9175   this->SetCalculateDiffFlowVsEta((Bool_t)fDiffFlowFlags->GetBinContent(6)); // to be improved - hardwired 6
9176  } else
9177    {
9178     printf("\n WARNING (QC): fDiffFlowFlags is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9179     printf("\n             Flags in method Finish() are wrong.\n\n");
9180     exit(0);
9181    } 
9182    
9183  if(!fCalculateDiffFlow){return;} // IMPORTANT: do not move this anywhere above in this method (to be improved)   
9184   
9185  // c) Get pointers to nested lists fDiffFlowListProfiles and fDiffFlowListResults:
9186  //  List holding nested lists holding profiles:
9187  TList *diffFlowListProfiles = NULL;
9188  diffFlowListProfiles = dynamic_cast<TList*>(fDiffFlowList->FindObject("Profiles"));
9189  if(!diffFlowListProfiles)
9190  { 
9191   printf("\n WARNING (QC): diffFlowListProfiles is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9192   exit(0);
9193  }
9194  //  List holding nested lists holding histograms with final results:
9195  TList *diffFlowListResults = NULL;
9196  diffFlowListResults = dynamic_cast<TList*>(fDiffFlowList->FindObject("Results"));
9197  if(!diffFlowListResults)
9198  { 
9199   printf("\n WARNING (QC): diffFlowListResults is NULL in AFAWQC::GPFDFH() !!!!\n\n");
9200   exit(0);
9201  }
9202  
9203  // d) Define flags locally (to be improved: should I promote these flags to data members?):
9204  TString typeFlag[2] = {"RP","POI"}; 
9205  TString ptEtaFlag[2] = {"p_{T}","#eta"};
9206  TString powerFlag[2] = {"linear","quadratic"};
9207  TString sinCosFlag[2] = {"sin","cos"};
9208  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
9209  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
9210  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
9211  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"}; 
9212  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
9213  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
9214   
9215  // e) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold:
9216  // correlations:
9217  TList *diffFlowCorrelationsProList[2][2] = {{NULL}};
9218  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
9219  diffFlowCorrelationsProName += fAnalysisLabel->Data();
9220  TProfile *diffFlowCorrelationsPro[2][2][4] = {{{NULL}}}; 
9221  // squared correlations:  
9222  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
9223  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data(); 
9224  TProfile *diffFlowSquaredCorrelationsPro[2][2][4] = {{{NULL}}};  
9225  // products of correlations:
9226  TList *diffFlowProductOfCorrelationsProList[2][2] = {{NULL}};
9227  TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
9228  diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
9229  TProfile *diffFlowProductOfCorrelationsPro[2][2][8][8] = {{{{NULL}}}};   
9230  // corrections:
9231  TList *diffFlowCorrectionsProList[2][2] = {{NULL}};
9232  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
9233  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();  
9234  TProfile *diffFlowCorrectionTermsForNUAPro[2][2][2][10] = {{{{NULL}}}};   
9235  for(Int_t t=0;t<2;t++)
9236  {
9237   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++)
9238   {
9239    diffFlowCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9240    if(!diffFlowCorrelationsProList[t][pe])
9241    { 
9242     cout<<"WARNING: diffFlowCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9243     cout<<"t = "<<t<<endl;
9244     cout<<"pe = "<<pe<<endl;
9245     exit(0);
9246    }
9247    for(Int_t ci=0;ci<4;ci++) // correlation index
9248    {
9249     // reduced correlations:
9250     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())));
9251     if(diffFlowCorrelationsPro[t][pe][ci])
9252     {
9253      this->SetDiffFlowCorrelationsPro(diffFlowCorrelationsPro[t][pe][ci],t,pe,ci);
9254     } else
9255       {
9256        cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9257        cout<<"t  = "<<t<<endl;
9258        cout<<"pe = "<<pe<<endl;   
9259        cout<<"ci = "<<ci<<endl;
9260       }     
9261     // reduced squared correlations:
9262     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())));
9263     if(diffFlowSquaredCorrelationsPro[t][pe][ci])
9264     {
9265      this->SetDiffFlowSquaredCorrelationsPro(diffFlowSquaredCorrelationsPro[t][pe][ci],t,pe,ci);
9266     } else
9267       {
9268        cout<<"WARNING: diffFlowSquaredCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9269        cout<<"t  = "<<t<<endl;
9270        cout<<"pe = "<<pe<<endl;   
9271        cout<<"ci = "<<ci<<endl;
9272       }       
9273    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
9274    // products of correlations:    
9275    diffFlowProductOfCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()))); 
9276    if(!diffFlowProductOfCorrelationsProList[t][pe])
9277    { 
9278     cout<<"WARNING: ddiffFlowProductOfCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9279     cout<<"t = "<<t<<endl;
9280     cout<<"pe = "<<pe<<endl;
9281     exit(0);
9282    }
9283    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9284    {
9285     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9286     {
9287      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())));
9288      if(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2])
9289      {
9290       this->SetDiffFlowProductOfCorrelationsPro(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2],t,pe,mci1,mci2);
9291      } else
9292        {
9293         cout<<"WARNING: diffFlowProductOfCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9294         cout<<"t    = "<<t<<endl;
9295         cout<<"pe   = "<<pe<<endl;   
9296         cout<<"mci1 = "<<mci1<<endl;
9297         cout<<"mci2 = "<<mci2<<endl;
9298        }
9299      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9300     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9301    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
9302    // corrections:
9303    diffFlowCorrectionsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9304    if(!diffFlowCorrectionsProList[t][pe])
9305    { 
9306     cout<<"WARNING: diffFlowCorrectionsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9307     cout<<"t = "<<t<<endl;
9308     cout<<"pe = "<<pe<<endl;
9309     exit(0);
9310    }
9311    // correction terms for NUA:
9312    for(Int_t sc=0;sc<2;sc++) // sin or cos
9313    {
9314     for(Int_t cti=0;cti<9;cti++) // correction term index
9315     {
9316      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)));
9317      if(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti])
9318      {
9319       this->SetDiffFlowCorrectionTermsForNUAPro(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti],t,pe,sc,cti);
9320      } else
9321        {
9322         cout<<"WARNING: diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9323         cout<<"t   = "<<t<<endl;
9324         cout<<"pe  = "<<pe<<endl;   
9325         cout<<"sc  = "<<sc<<endl;
9326         cout<<"cti = "<<cti<<endl;
9327        }    
9328     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
9329    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9330    // ...
9331   } // end of for(Int_t pe=0;pe<2;pe++)
9332  } // end of for(Int_t t=0;t<2;t++)
9333   
9334  // f) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold:
9335  // reduced correlations:
9336  TList *diffFlowCorrelationsHistList[2][2] = {{NULL}};
9337  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
9338  diffFlowCorrelationsHistName += fAnalysisLabel->Data();  
9339  TH1D *diffFlowCorrelationsHist[2][2][4] = {{{NULL}}};
9340  // corrections for NUA:
9341  TList *diffFlowCorrectionsHistList[2][2] = {{NULL}};
9342  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
9343  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();  
9344  TH1D *diffFlowCorrectionTermsForNUAHist[2][2][2][10] = {{{{NULL}}}};
9345  // differential Q-cumulants:
9346  TList *diffFlowCumulantsHistList[2][2] = {{NULL}};
9347  TString diffFlowCumulantsName = "fDiffFlowCumulants";
9348  diffFlowCumulantsName += fAnalysisLabel->Data();  
9349  TH1D *diffFlowCumulants[2][2][4] = {{{NULL}}};
9350  // detector bias to differential Q-cumulants:
9351  TList *diffFlowDetectorBiasHistList[2][2] = {{NULL}};
9352  TString diffFlowDetectorBiasName = "fDiffFlowDetectorBias";
9353  diffFlowDetectorBiasName += fAnalysisLabel->Data();  
9354  TH1D *diffFlowDetectorBias[2][2][4] = {{{NULL}}}; 
9355  // differential flow estimates from Q-cumulants:
9356  TList *diffFlowHistList[2][2] = {{NULL}};
9357  TString diffFlowName = "fDiffFlow";
9358  diffFlowName += fAnalysisLabel->Data();  
9359  TH1D *diffFlow[2][2][4] = {{{NULL}}};
9360  // differential covariances:
9361  TList *diffFlowCovariancesHistList[2][2] = {{NULL}};
9362  TString diffFlowCovariancesName = "fDiffFlowCovariances";
9363  diffFlowCovariancesName += fAnalysisLabel->Data();  
9364  TH1D *diffFlowCovariances[2][2][5] = {{{NULL}}};
9365  for(Int_t t=0;t<2;t++) // type: RP or POI
9366  { 
9367   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9368   {
9369    // reduced correlations:
9370    diffFlowCorrelationsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9371    if(!diffFlowCorrelationsHistList[t][pe])
9372    { 
9373     cout<<"WARNING: diffFlowCorrelationsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9374     cout<<"t = "<<t<<endl;
9375     cout<<"pe = "<<pe<<endl;
9376     exit(0);
9377    }
9378    for(Int_t index=0;index<4;index++) 
9379    {
9380     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())));
9381     if(diffFlowCorrelationsHist[t][pe][index])
9382     {
9383      this->SetDiffFlowCorrelationsHist(diffFlowCorrelationsHist[t][pe][index],t,pe,index);
9384     } else 
9385       {
9386        cout<<"WARNING: diffFlowCorrelationsHist[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9387        cout<<"t     = "<<t<<endl;
9388        cout<<"pe    = "<<pe<<endl;
9389        cout<<"index = "<<index<<endl;
9390        exit(0);       
9391       } 
9392    } // end of for(Int_t index=0;index<4;index++)
9393    // corrections:
9394    diffFlowCorrectionsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9395    if(!diffFlowCorrectionsHistList[t][pe])
9396    { 
9397     cout<<"WARNING: diffFlowCorrectionsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9398     cout<<"t = "<<t<<endl;
9399     cout<<"pe = "<<pe<<endl;
9400     exit(0);
9401    }
9402    // correction terms for NUA:
9403    for(Int_t sc=0;sc<2;sc++) // sin or cos
9404    {
9405     for(Int_t cti=0;cti<9;cti++) // correction term index
9406     {
9407      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)));
9408      if(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti])
9409      {
9410       this->SetDiffFlowCorrectionTermsForNUAHist(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti],t,pe,sc,cti);
9411      } else
9412        {
9413         cout<<"WARNING: diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9414         cout<<"t   = "<<t<<endl;
9415         cout<<"pe  = "<<pe<<endl;   
9416         cout<<"sc  = "<<sc<<endl;
9417         cout<<"cti = "<<cti<<endl;
9418        }    
9419     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
9420    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9421    // ...
9422    // differential Q-cumulants:
9423    diffFlowCumulantsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9424    if(!diffFlowCumulantsHistList[t][pe])
9425    { 
9426     cout<<"WARNING: diffFlowCumulantsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9427     cout<<"t  = "<<t<<endl;
9428     cout<<"pe = "<<pe<<endl;
9429     exit(0);
9430    }
9431    for(Int_t index=0;index<4;index++) 
9432    {
9433     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())));
9434     if(diffFlowCumulants[t][pe][index])
9435     {
9436      this->SetDiffFlowCumulants(diffFlowCumulants[t][pe][index],t,pe,index);
9437     } else 
9438       {
9439        cout<<"WARNING: diffFlowCumulants[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9440        cout<<"t     = "<<t<<endl;
9441        cout<<"pe    = "<<pe<<endl;
9442        cout<<"index = "<<index<<endl;
9443        exit(0);       
9444       } 
9445    } // end of for(Int_t index=0;index<4;index++)
9446    // Detector bias to differential Q-cumulants:
9447    diffFlowDetectorBiasHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Detector bias (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9448    if(!diffFlowDetectorBiasHistList[t][pe])
9449    { 
9450     cout<<"WARNING: diffFlowDetectorBiasHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9451     cout<<"t  = "<<t<<endl;
9452     cout<<"pe = "<<pe<<endl;
9453     exit(0);
9454    }
9455    for(Int_t index=0;index<4;index++) 
9456    {
9457     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())));
9458     if(diffFlowDetectorBias[t][pe][index])
9459     {
9460      this->SetDiffFlowDetectorBias(diffFlowDetectorBias[t][pe][index],t,pe,index);
9461     } else 
9462       {
9463        cout<<"WARNING: diffFlowDetectorBias[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9464        cout<<"t     = "<<t<<endl;
9465        cout<<"pe    = "<<pe<<endl;
9466        cout<<"index = "<<index<<endl;
9467        exit(0);       
9468       } 
9469    } // end of for(Int_t index=0;index<4;index++)
9470    // differential flow estimates from Q-cumulants:
9471    diffFlowHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9472    if(!diffFlowHistList[t][pe])
9473    { 
9474     cout<<"WARNING: diffFlowHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9475     cout<<"t  = "<<t<<endl;
9476     cout<<"pe = "<<pe<<endl;
9477     exit(0);
9478    }
9479    for(Int_t index=0;index<4;index++) 
9480    {
9481     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())));
9482     if(diffFlow[t][pe][index])
9483     {
9484      this->SetDiffFlow(diffFlow[t][pe][index],t,pe,index);
9485     } else 
9486       {
9487        cout<<"WARNING: diffFlow[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9488        cout<<"t     = "<<t<<endl;
9489        cout<<"pe    = "<<pe<<endl;
9490        cout<<"index = "<<index<<endl;
9491        exit(0);       
9492       } 
9493    } // end of for(Int_t index=0;index<4;index++)
9494    // differential covariances:
9495    diffFlowCovariancesHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9496    if(!diffFlowCovariancesHistList[t][pe])
9497    { 
9498     cout<<"WARNING: diffFlowCovariancesHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9499     cout<<"t  = "<<t<<endl;
9500     cout<<"pe = "<<pe<<endl;
9501     exit(0);
9502    }
9503    for(Int_t covIndex=0;covIndex<5;covIndex++) 
9504    {
9505     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())));
9506     if(diffFlowCovariances[t][pe][covIndex])
9507     {
9508      this->SetDiffFlowCovariances(diffFlowCovariances[t][pe][covIndex],t,pe,covIndex);
9509     } else 
9510       {
9511        cout<<"WARNING: diffFlowCovariances[t][pe][covIndex] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9512        cout<<"t        = "<<t<<endl;
9513        cout<<"pe       = "<<pe<<endl;
9514        cout<<"covIndex = "<<covIndex<<endl;
9515        exit(0);       
9516       } 
9517    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index    
9518   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9519  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
9520  // sum of event weights for reduced correlations:
9521  TList *diffFlowSumOfEventWeightsHistList[2][2][2] = {{{NULL}}};
9522  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
9523  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
9524  TH1D *diffFlowSumOfEventWeights[2][2][2][4] = {{{{NULL}}}};
9525  for(Int_t t=0;t<2;t++) // type is RP or POI
9526  { 
9527   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9528   { 
9529    for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
9530    {
9531     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())));
9532     if(!diffFlowSumOfEventWeightsHistList[t][pe][p])
9533     { 
9534      cout<<"WARNING: diffFlowSumOfEventWeightsHistList[t][pe][p] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9535      cout<<"t     = "<<t<<endl;
9536      cout<<"pe    = "<<pe<<endl;
9537      cout<<"power = "<<p<<endl;
9538      exit(0);
9539     }
9540     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
9541     {
9542      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())));    
9543      if(diffFlowSumOfEventWeights[t][pe][p][ew])
9544      {
9545       this->SetDiffFlowSumOfEventWeights(diffFlowSumOfEventWeights[t][pe][p][ew],t,pe,p,ew);
9546      } else 
9547        {
9548         cout<<"WARNING: diffFlowSumOfEventWeights[t][pe][p][ew] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9549         cout<<"t     = "<<t<<endl;
9550         cout<<"pe    = "<<pe<<endl;
9551         cout<<"power = "<<p<<endl;
9552         cout<<"ew    = "<<ew<<endl;
9553         exit(0);       
9554        } 
9555     }
9556    } // end of for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
9557   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9558  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
9559  //  
9560  TList *diffFlowSumOfProductOfEventWeightsHistList[2][2] = {{NULL}};
9561  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
9562  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
9563  TH1D *diffFlowSumOfProductOfEventWeights[2][2][8][8] = {{{{NULL}}}};
9564  for(Int_t t=0;t<2;t++) // type is RP or POI
9565  { 
9566   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9567   { 
9568    diffFlowSumOfProductOfEventWeightsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
9569    if(!diffFlowSumOfProductOfEventWeightsHistList[t][pe])
9570    { 
9571     cout<<"WARNING: diffFlowSumOfProductOfEventWeightsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9572     cout<<"t     = "<<t<<endl;
9573     cout<<"pe    = "<<pe<<endl;
9574     exit(0);
9575    }
9576    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9577    {
9578     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9579     {
9580      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())));    
9581       if(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2])
9582       {
9583        this->SetDiffFlowSumOfProductOfEventWeights(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2],t,pe,mci1,mci2);
9584       } else 
9585         {
9586          cout<<"WARNING: diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9587          cout<<"t    = "<<t<<endl;
9588          cout<<"pe   = "<<pe<<endl;
9589          cout<<"mci1 = "<<mci1<<endl;
9590          cout<<"mci2 = "<<mci2<<endl;
9591          exit(0);       
9592         } 
9593      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9594     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9595    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9596   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
9597  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
9598
9599 } // end void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
9600
9601 //================================================================================================================================
9602
9603 void AliFlowAnalysisWithQCumulants::BookEverythingFor2DDifferentialFlow()
9604 {
9605  // Book all objects needed for 2D differential flow.
9606  //  a) Define flags locally (to be improved: should I promote flags to data members?);
9607  //  b) Book e-b-e quantities;
9608  //  c) Book 2D profiles;
9609  //  d) Book 2D histograms.
9610  
9611  if(!fCalculate2DDiffFlow){return;}
9612
9613  // a) Define flags locally (to be improved: should I promote flags to data members?):
9614  TString typeFlag[2] = {"RP","POI"}; 
9615  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
9616  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
9617  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
9618   
9619  // b) Book e-b-e quantities: 
9620  TProfile2D styleRe("typeMultiplePowerRe","typeMultiplePowerRe",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9621  TProfile2D styleIm("typeMultiplePowerIm","typeMultiplePowerIm",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9622  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
9623  { 
9624   for(Int_t m=0;m<4;m++)
9625   {
9626    for(Int_t k=0;k<9;k++)
9627    {
9628     fReRPQ2dEBE[t][m][k] = (TProfile2D*)styleRe.Clone(Form("typeFlag%dmultiple%dpower%dRe",t,m,k)); 
9629     fImRPQ2dEBE[t][m][k] = (TProfile2D*)styleIm.Clone(Form("typeFlag%dmultiple%dpower%dIm",t,m,k));
9630    }
9631   } 
9632  } 
9633  TProfile2D styleS("typePower","typePower",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
9634  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
9635  { 
9636   for(Int_t k=0;k<9;k++)
9637   {
9638    fs2dEBE[t][k] = (TProfile2D*)styleS.Clone(Form("typeFlag%dpower%d",t,k));
9639   }
9640  }
9641
9642  // c) Book 2D profiles:
9643  TString s2DDiffFlowCorrelationsProName = "f2DDiffFlowCorrelationsPro";
9644  s2DDiffFlowCorrelationsProName += fAnalysisLabel->Data();
9645  for(Int_t t=0;t<2;t++) // type: RP or POI
9646  { 
9647   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9648   {
9649    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,"");
9650    f2DDiffFlowCorrelationsPro[t][rci]->Sumw2();
9651    f2DDiffFlowCorrelationsPro[t][rci]->SetXTitle("p_{t}");
9652    f2DDiffFlowCorrelationsPro[t][rci]->SetYTitle("#eta");
9653    f2DDiffFlowCorrelationsProList[t]->Add(f2DDiffFlowCorrelationsPro[t][rci]); 
9654   } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9655  } // end of for(Int_t t=0;t<2;t++) // type: RP or POIs
9656
9657  // d) Book 2D histograms:
9658  TString s2DDiffFlowCumulantsName = "f2DDiffFlowCumulants";
9659  s2DDiffFlowCumulantsName += fAnalysisLabel->Data();
9660  TString s2DDiffFlowName = "f2DDiffFlow";
9661  s2DDiffFlowName += fAnalysisLabel->Data();
9662  for(Int_t t=0;t<2;t++) // type: RP or POI
9663  { 
9664   for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9665   {
9666    // 2D diferential cumulants:
9667    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);
9668    f2DDiffFlowCumulants[t][rci]->SetXTitle("p_{t}");
9669    f2DDiffFlowCumulants[t][rci]->SetYTitle("#eta");
9670    f2DDiffFlowCorrelationsProList[t]->Add(f2DDiffFlowCumulants[t][rci]); //  to be improved - moved to another list 
9671    // 2D differential flow:
9672    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);
9673    f2DDiffFlow[t][rci]->SetXTitle("p_{t}");
9674    f2DDiffFlow[t][rci]->SetYTitle("#eta");
9675    f2DDiffFlowCorrelationsProList[t]->Add(f2DDiffFlow[t][rci]); //  to be improved - moved to another list 
9676   } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9677  } // end of for(Int_t t=0;t<2;t++) // type: RP or POIs
9678
9679 } // void AliFlowAnalysisWithQCumulants::BookEverythingFor2DDifferentialFlow()
9680
9681 //================================================================================================================================
9682
9683 void AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
9684 {
9685  // Book all histograms and profiles needed for differential flow.
9686  //  a) Book profile to hold all flags for differential flow;
9687  //  b) Define flags locally (to be improved: should I promote flags to data members?);
9688  //  c) Book e-b-e quantities;
9689  //  d) Book profiles;
9690  //  e) Book histograms holding final results. 
9691  
9692  // a) Book profile to hold all flags for differential flow:
9693  TString diffFlowFlagsName = "fDiffFlowFlags";
9694  diffFlowFlagsName += fAnalysisLabel->Data();
9695  fDiffFlowFlags = new TProfile(diffFlowFlagsName.Data(),"Flags for differential flow",6,0,6);
9696  fDiffFlowFlags->SetTickLength(-0.01,"Y");
9697  fDiffFlowFlags->SetMarkerStyle(25);
9698  fDiffFlowFlags->SetLabelSize(0.04,"X");
9699  fDiffFlowFlags->SetLabelOffset(0.02,"Y");
9700  fDiffFlowFlags->GetXaxis()->SetBinLabel(1,"Calculate diff. flow"); 
9701  fDiffFlowFlags->GetXaxis()->SetBinLabel(2,"Particle weights");
9702  fDiffFlowFlags->GetXaxis()->SetBinLabel(3,"Event weights");
9703  fDiffFlowFlags->GetXaxis()->SetBinLabel(4,"Correct for NUA");
9704  fDiffFlowFlags->GetXaxis()->SetBinLabel(5,"Calculate 2D diff. flow");
9705  fDiffFlowFlags->GetXaxis()->SetBinLabel(6,"Calculate diff. flow vs eta");
9706  fDiffFlowList->Add(fDiffFlowFlags);
9707
9708  if(!fCalculateDiffFlow){return;}
9709   
9710  // b) Define flags locally (to be improved: should I promote flags to data members?): 
9711  TString typeFlag[2] = {"RP","POI"}; 
9712  TString ptEtaFlag[2] = {"p_{T}","#eta"};
9713  TString powerFlag[2] = {"linear","quadratic"};
9714  TString sinCosFlag[2] = {"sin","cos"};
9715  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
9716  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
9717  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
9718  TString reducedSquaredCorrelationIndex[4] = {"<2'>^{2}","<4'>^{2}","<6'>^{2}","<8'>^{2}"};
9719  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
9720  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
9721  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9722  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9723  Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9724    
9725  // c) Book e-b-e quantities:
9726  // Event-by-event r_{m*n,k}(pt,eta), p_{m*n,k}(pt,eta) and q_{m*n,k}(pt,eta)
9727  // Explanantion of notation:
9728  //  1.) n is harmonic, m is multiple of harmonic;
9729  //  2.) k is power of particle weight;
9730  //  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);   
9731  //  4.) p_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for POIs in particular (pt,eta) bin 
9732  //                          (if i-th POI is also RP, than it is weighted with w_i^k);   
9733  //  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 
9734  //                          (i-th RP&&POI is weighted with w_i^k)            
9735   
9736  // 1D:
9737  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP && POI )
9738  { 
9739   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9740   {
9741    for(Int_t m=0;m<4;m++) // multiple of harmonic
9742    {
9743     for(Int_t k=0;k<9;k++) // power of particle weight
9744     {
9745      fReRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),
9746                                              Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9747      fImRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),
9748                                              Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9749     }
9750    }
9751   }
9752  } 
9753  // to be improved (add explanation of fs1dEBE[t][pe][k]):   
9754  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
9755  { 
9756   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9757   {
9758    for(Int_t k=0;k<9;k++) // power of particle weight
9759    {
9760     fs1dEBE[t][pe][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),
9761                                      Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9762    }
9763   }
9764  }
9765  // correction terms for nua:
9766  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9767  { 
9768   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9769   {
9770    for(Int_t sc=0;sc<2;sc++) // sin or cos
9771    {
9772     for(Int_t cti=0;cti<9;cti++) // correction term index
9773     {
9774      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = new TH1D(Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),
9775                                              Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
9776     }
9777    }
9778   }
9779  } 
9780  // reduced correlations e-b-e:
9781  TString diffFlowCorrelationsEBEName = "fDiffFlowCorrelationsEBE";
9782  diffFlowCorrelationsEBEName += fAnalysisLabel->Data();
9783  for(Int_t t=0;t<2;t++) // type: RP or POI
9784  { 
9785   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9786   {
9787    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9788    {
9789     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]);
9790    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
9791   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9792  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9793  // event weights for reduced correlations e-b-e:
9794  TString diffFlowEventWeightsForCorrelationsEBEName = "fDiffFlowEventWeightsForCorrelationsEBE";
9795  diffFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
9796  for(Int_t t=0;t<2;t++) // type: RP or POI
9797  { 
9798   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9799   {
9800    for(Int_t rci=0;rci<4;rci++) // event weight for reduced correlation index
9801    {
9802     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]);
9803    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
9804   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9805  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9806       
9807  // d) Book profiles;
9808  // reduced correlations:
9809  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
9810  diffFlowCorrelationsProName += fAnalysisLabel->Data();
9811  // reduced squared correlations:
9812  TString diffFlowSquaredCorrelationsProName = "fDiffFlowSquaredCorrelationsPro";
9813  diffFlowSquaredCorrelationsProName += fAnalysisLabel->Data();
9814  // corrections terms:
9815  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
9816  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
9817  // reduced correlations:
9818  for(Int_t t=0;t<2;t++) // type: RP or POI
9819  { 
9820   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9821   {
9822    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9823    {
9824     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");
9825     fDiffFlowCorrelationsPro[t][pe][rci]->Sumw2();
9826     fDiffFlowCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
9827     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
9828    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9829   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9830  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9831  // reduced squared correlations:
9832  for(Int_t t=0;t<2;t++) // type: RP or POI
9833  { 
9834   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9835   {
9836    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9837    {
9838     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");
9839     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->Sumw2();
9840     fDiffFlowSquaredCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
9841     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowSquaredCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
9842    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
9843   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9844  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9845  // correction terms for nua:
9846  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9847  { 
9848   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9849   {
9850    for(Int_t sc=0;sc<2;sc++) // sin or cos
9851    {
9852     for(Int_t cti=0;cti<9;cti++) // correction term index
9853     {
9854      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]); 
9855      fDiffFlowCorrectionsProList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]);
9856     }
9857    }
9858   }
9859  } 
9860  // Other differential correlators:
9861  TString otherDiffCorrelatorsName = "fOtherDiffCorrelators";
9862  otherDiffCorrelatorsName += fAnalysisLabel->Data();
9863  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9864  { 
9865   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9866   {
9867    for(Int_t sc=0;sc<2;sc++) // sin or cos
9868    {
9869     for(Int_t ci=0;ci<1;ci++) // correlator index
9870     {
9871      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]); 
9872      fOtherDiffCorrelators[t][pe][sc][ci]->Sumw2();
9873      fOtherDiffCorrelatorsList->Add(fOtherDiffCorrelators[t][pe][sc][ci]);
9874     }
9875    }
9876   }
9877  }  
9878  // e) Book histograms holding final results. 
9879  // reduced correlations:
9880  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
9881  diffFlowCorrelationsHistName += fAnalysisLabel->Data();
9882  // corrections terms:
9883  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
9884  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
9885  // differential covariances:
9886  TString diffFlowCovariancesName = "fDiffFlowCovariances";
9887  diffFlowCovariancesName += fAnalysisLabel->Data();
9888  // differential Q-cumulants:
9889  TString diffFlowCumulantsName = "fDiffFlowCumulants";
9890  diffFlowCumulantsName += fAnalysisLabel->Data();
9891  // Detector bias to differential Q-cumulants:
9892  TString diffFlowDetectorBiasName = "fDiffFlowDetectorBias";
9893  diffFlowDetectorBiasName += fAnalysisLabel->Data();
9894  // differential flow:
9895  TString diffFlowName = "fDiffFlow";
9896  diffFlowName += fAnalysisLabel->Data();
9897  for(Int_t t=0;t<2;t++) // type: RP or POI
9898  { 
9899   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9900   {
9901    for(Int_t index=0;index<4;index++) 
9902    {
9903     // reduced correlations:
9904     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]);
9905     fDiffFlowCorrelationsHist[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9906     fDiffFlowCorrelationsHistList[t][pe]->Add(fDiffFlowCorrelationsHist[t][pe][index]); 
9907     // differential Q-cumulants:
9908     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]);
9909     fDiffFlowCumulants[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9910     fDiffFlowCumulantsHistList[t][pe]->Add(fDiffFlowCumulants[t][pe][index]); 
9911     // Detector bias to differential Q-cumulants:
9912     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]);
9913     fDiffFlowDetectorBias[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9914     fDiffFlowDetectorBias[t][pe][index]->SetTitle(Form("#frac{corrected}{measured} %s",differentialCumulantIndex[index].Data()));
9915     fDiffFlowDetectorBiasHistList[t][pe]->Add(fDiffFlowDetectorBias[t][pe][index]); 
9916     // differential flow estimates from Q-cumulants:
9917     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]);
9918     fDiffFlow[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
9919     fDiffFlowHistList[t][pe]->Add(fDiffFlow[t][pe][index]); 
9920    } // end of for(Int_t index=0;index<4;index++) 
9921    for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index 
9922    {
9923     // differential covariances:
9924     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]);
9925     fDiffFlowCovariances[t][pe][covIndex]->SetXTitle(ptEtaFlag[pe].Data());
9926     fDiffFlowCovariancesHistList[t][pe]->Add(fDiffFlowCovariances[t][pe][covIndex]); 
9927    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index
9928    // products of both types of correlations: 
9929    TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
9930    diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
9931    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9932    {
9933     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9934     {
9935      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]); 
9936      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
9937      fDiffFlowProductOfCorrelationsProList[t][pe]->Add(fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]); 
9938      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9939     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9940    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
9941   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
9942  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
9943  // sums of event weights for reduced correlations: 
9944  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
9945  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
9946  for(Int_t t=0;t<2;t++) // type is RP or POI
9947  { 
9948   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9949   { 
9950    for(Int_t p=0;p<2;p++) // power of weights is either 1 or 2
9951    {
9952     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
9953     {
9954      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]); 
9955      fDiffFlowSumOfEventWeights[t][pe][p][ew]->SetXTitle(ptEtaFlag[pe].Data());
9956      fDiffFlowSumOfEventWeightsHistList[t][pe][p]->Add(fDiffFlowSumOfEventWeights[t][pe][p][ew]); // to be improved (add dedicated list to hold all this)
9957     }
9958    }
9959   }
9960  } 
9961  // sum of products of event weights for both types of correlations: 
9962  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
9963  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
9964  for(Int_t t=0;t<2;t++) // type is RP or POI
9965  {
9966   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9967   { 
9968    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
9969    {
9970     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
9971     {
9972      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]); 
9973      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
9974      fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->Add(fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]); 
9975      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
9976     }
9977    }
9978   }
9979  } 
9980  // correction terms for nua:
9981  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
9982  { 
9983   for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
9984   {
9985    for(Int_t sc=0;sc<2;sc++) // sin or cos
9986    {
9987     for(Int_t cti=0;cti<9;cti++) // correction term index
9988     {
9989      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]); 
9990      fDiffFlowCorrectionsHistList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]);
9991     }
9992    }
9993   }
9994  } 
9995           
9996 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
9997
9998 //================================================================================================================================
9999
10000 void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
10001 {
10002  // Calculate generalized Q-cumulants (cumulants corrected for non-unifom acceptance).
10003  
10004  // Isotropic cumulants:
10005  Double_t QC2 = fIntFlowQcumulants->GetBinContent(1);
10006  Double_t QC2Error = fIntFlowQcumulants->GetBinError(1);
10007  Double_t QC4 = fIntFlowQcumulants->GetBinContent(2);
10008  Double_t QC4Error = fIntFlowQcumulants->GetBinError(2);
10009  //Double_t QC6 = fIntFlowQcumulants->GetBinContent(3);
10010  //Double_t QC6Error = fIntFlowQcumulants->GetBinError(3);
10011  //Double_t QC8 = fIntFlowQcumulants->GetBinContent(4);
10012  //Double_t QC8Error = fIntFlowQcumulants->GetBinError(4);
10013  
10014  // Measured 2-, 4-, 6- and 8-particle correlations:
10015  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
10016  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <<2>>
10017  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
10018  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <<4>>
10019  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
10020  //Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <<6>>
10021  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
10022  //Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <<8>>
10023   
10024  // Non-isotropic terms:
10025  Double_t c1 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
10026  Double_t c1Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(1); // statistical error of <<cos(n*phi1)>>
10027  Double_t c2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
10028  Double_t c2Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(2); // statistical error of <<cos(n*(phi1+phi2))>>
10029  Double_t c3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
10030  Double_t c3Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(3); // statistical error of <<cos(n*(phi1-phi2-phi3))>>
10031  Double_t s1 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
10032  Double_t s1Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(1); // statistical error of <<sin(n*phi1)>>
10033  Double_t s2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
10034  Double_t s2Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(2); // statistical error of <<sin(n*(phi1+phi2))>>
10035  Double_t s3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
10036  Double_t s3Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(3); // statistical error of <<sin(n*(phi1-phi2-phi3))>>
10037  
10038  // Shortcuts:
10039  Double_t a1 = 2.*pow(c1,2.)+2.*pow(s1,2.)-two;
10040  Double_t a2 = 6.*pow(c1,3.)-2.*c1*c2+c3+6.*c1*pow(s1,2.)-2.*s1*s2-4.*c1*two;
10041  Double_t a3 = 2.*pow(s1,2.)-2.*pow(c1,2.)+c2;
10042  Double_t a4 = 6.*pow(s1,3.)+6.*pow(c1,2.)*s1+2.*c2*s1-2.*c1*s2-s3-4.*s1*two;
10043  Double_t a5 = 4.*c1*s1-s2;
10044  
10045  // Covariances (including weight dependent prefactor):
10046  Double_t wCov1 = 0.; // w*Cov(<2>,<cos(phi)) 
10047  Double_t wCov2 = 0.; // w*Cov(<2>,<sin(phi))
10048  Double_t wCov3 = 0.; // w*Cov(<cos(phi),<sin(phi))
10049  Double_t wCov4 = 0.; // w*Cov(<2>,<4>) 
10050  Double_t wCov5 = 0.; // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
10051  Double_t wCov6 = 0.; // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10052  Double_t wCov7 = 0.; // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
10053  Double_t wCov8 = 0.; // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10054  Double_t wCov9 = 0.; // w*Cov(<4>,<cos(#phi)>
10055  Double_t wCov10 = 0.; // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
10056  Double_t wCov11 = 0.; // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10057  Double_t wCov12 = 0.; // w*Cov(<4>,<sin(#phi)>
10058  Double_t wCov13 = 0.; // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
10059  Double_t wCov14 = 0.; // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10060  Double_t wCov15 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
10061  Double_t wCov16 = 0.; // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10062  Double_t wCov17 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
10063  Double_t wCov18 = 0.; // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10064  Double_t wCov19 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10065  Double_t wCov20 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
10066  Double_t wCov21 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
10067  Double_t wCov22 = 0.; // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10068  Double_t wCov23 = 0.; // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10069  Double_t wCov24 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10070  Double_t wCov25 = 0.; // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
10071  Double_t wCov26 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
10072  Double_t wCov27 = 0.; // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10073  Double_t wCov28 = 0.; // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10074  if(!fForgetAboutCovariances)
10075  {
10076   wCov1 = fIntFlowCovariancesNUA->GetBinContent(1); // w*Cov(<2>,<cos(phi)) 
10077   wCov2 = fIntFlowCovariancesNUA->GetBinContent(2); // w*Cov(<2>,<sin(phi))
10078   wCov3 = fIntFlowCovariancesNUA->GetBinContent(3); // w*Cov(<cos(phi),<sin(phi))
10079   wCov4 = fIntFlowCovariances->GetBinContent(1); // w*Cov(<2>,<4>) 
10080   wCov5 = fIntFlowCovariancesNUA->GetBinContent(4); // w*Cov(<2>,<cos(#phi_{1}+#phi_{2})>)
10081   wCov6 = fIntFlowCovariancesNUA->GetBinContent(6); // w*Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10082   wCov7 = fIntFlowCovariancesNUA->GetBinContent(5); // w*Cov(<2>,<sin(#phi_{1}+#phi_{2})>)
10083   wCov8 = fIntFlowCovariancesNUA->GetBinContent(7); // w*Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10084   wCov9 = fIntFlowCovariancesNUA->GetBinContent(8); // w*Cov(<4>,<cos(#phi)>
10085   wCov10 = fIntFlowCovariancesNUA->GetBinContent(10); // w*Cov(<4>,<cos(#phi_{1}+#phi_{2})>)
10086   wCov11 = fIntFlowCovariancesNUA->GetBinContent(12); // w*Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10087   wCov12 = fIntFlowCovariancesNUA->GetBinContent(9); // w*Cov(<4>,<sin(#phi)>
10088   wCov13 = fIntFlowCovariancesNUA->GetBinContent(11); // w*Cov(<4>,<sin(#phi_{1}+#phi_{2})>)
10089   wCov14 = fIntFlowCovariancesNUA->GetBinContent(13); // w*Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10090   wCov15 = fIntFlowCovariancesNUA->GetBinContent(14); // w*Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)
10091   wCov16 = fIntFlowCovariancesNUA->GetBinContent(16); // w*Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10092   wCov17 = fIntFlowCovariancesNUA->GetBinContent(15); // w*Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)
10093   wCov18 = fIntFlowCovariancesNUA->GetBinContent(17); // w*Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10094   wCov19 = fIntFlowCovariancesNUA->GetBinContent(23); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10095   wCov20 = fIntFlowCovariancesNUA->GetBinContent(18); // w*Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)
10096   wCov21 = fIntFlowCovariancesNUA->GetBinContent(22); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)
10097   wCov22 = fIntFlowCovariancesNUA->GetBinContent(24); // w*Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10098   wCov23 = fIntFlowCovariancesNUA->GetBinContent(20); // w*Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10099   wCov24 = fIntFlowCovariancesNUA->GetBinContent(25); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)
10100   wCov25 = fIntFlowCovariancesNUA->GetBinContent(27); // w*Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)
10101   wCov26 = fIntFlowCovariancesNUA->GetBinContent(19); // w*Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)
10102   wCov27 = fIntFlowCovariancesNUA->GetBinContent(21); // w*Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10103   wCov28 = fIntFlowCovariancesNUA->GetBinContent(26); // w*Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)
10104  } // end of if(!fForgetAboutCovariances)
10105  
10106  // Calculating generalized QC{2}:
10107  //  Generalized QC{2}:
10108  Double_t gQC2 = two - pow(c1,2.) - pow(s1,2.);
10109  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(1,gQC2);} 
10110  //  Statistical error of generalized QC{2}:
10111  Double_t gQC2ErrorSquared = pow(twoError,2.)+4.*pow(c1,2.)*pow(c1Error,2.)
10112                            + 4.*pow(s1,2.)*pow(s1Error,2.)
10113                            - 4*c1*wCov1-4*s1*wCov2 
10114                            + 8.*c1*s1*wCov3;
10115  //  Store ratio of error squared - with/without NUA terms:
10116  Double_t ratioErrorSquaredQC2 = 0.;
10117  if(fIntFlowQcumulants->GetBinError(1)>0.)
10118  { 
10119   ratioErrorSquaredQC2 = (gQC2ErrorSquared/pow(fIntFlowQcumulants->GetBinError(1),2.));
10120   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(1,ratioErrorSquaredQC2);
10121  }
10122  //  If enabled, store error by including non-isotropic terms:                         
10123  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10124  {
10125   if(gQC2ErrorSquared>=0.)
10126   {
10127    fIntFlowQcumulants->SetBinError(1,pow(gQC2ErrorSquared,0.5));
10128   } else
10129     {
10130      fIntFlowQcumulants->SetBinError(1,0.);
10131      cout<<endl;
10132      cout<<" WARNING (QC): Statistical error of generalized QC{2} is imaginary !!!!"<<endl;
10133      cout<<endl;
10134     }   
10135  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10136  // Quantify detector bias to QC{2}:
10137  if(TMath::Abs(QC2)>0.)
10138  {
10139   fIntFlowDetectorBias->SetBinContent(1,gQC2/QC2); 
10140   if(QC2Error>0.)
10141   {
10142    Double_t errorSquared = gQC2ErrorSquared/pow(QC2,2.)+pow(gQC2,2.)*pow(QC2Error,2.)/pow(QC2,4.);
10143    if(errorSquared>0.)
10144    {
10145     fIntFlowDetectorBias->SetBinError(1,pow(errorSquared,0.5));  
10146    }
10147   }
10148  } // end of if(TMath::Abs(QC2)>0.)
10149
10150  // Calculating generalized QC{4}:
10151  //  Generalized QC{4}:
10152  Double_t gQC4 = four-2.*pow(two,2.)
10153                - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
10154                + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
10155                + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
10156  if(fApplyCorrectionForNUA){fIntFlowQcumulants->SetBinContent(2,gQC4);}   
10157  //  Statistical error of generalized QC{4}:
10158  Double_t gQC4ErrorSquared = 16.*pow(a1,2.)*pow(twoError,2.)+pow(fourError,2.)+16.*pow(a2,2.)*pow(c1Error,2.)
10159                            + 4.*pow(a3,2.)*pow(c2Error,2.)+16.*pow(c1,2.)*pow(c3Error,2.)
10160                            + 16.*pow(a4,2.)*pow(s1Error,2.)+4.*pow(a5,2.)*pow(s2Error,2.)
10161                            + 16.*pow(s1,2.)*pow(s3Error,2.)+8.*a1*wCov4-32.*a1*a2*wCov1
10162                            - 16.*a3*a1*wCov5-32.*c1*a1*wCov6-32.*a1*a4*wCov2+16.*a5*a1*wCov7
10163                            + 32.*s1*a1*wCov8-8.*a2*wCov9-4.*a3*wCov10-8.*c1*wCov11-8.*a4*wCov12
10164                            + 4.*a5*wCov13+8.*s1*wCov14+16.*a3*a2*wCov15+32.*c1*a2*wCov16+32.*a2*a4*wCov3
10165                            - 16.*a5*a2*wCov17-32.*s1*a2*wCov18+16.*c1*a3*wCov19+16.*a3*a4*wCov20
10166                            - 8.*a3*a5*wCov21-16.*s1*a3*wCov22+32.*c1*a4*wCov23-16.*c1*a5*wCov24
10167                            - 32.*c1*s1*wCov25-16.*a5*a4*wCov26-32.*s1*a4*wCov27+16.*s1*a5*wCov28;
10168  //  Store ratio of error squared - with/without NUA terms:
10169  Double_t ratioErrorSquaredQC4 = 0.;
10170  if(fIntFlowQcumulants->GetBinError(2)>0.)
10171  { 
10172   ratioErrorSquaredQC4 = (gQC4ErrorSquared/pow(fIntFlowQcumulants->GetBinError(2),2.));
10173   fIntFlowQcumulantsErrorSquaredRatio->SetBinContent(2,ratioErrorSquaredQC4);
10174  }                          
10175  if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10176  {
10177   if(gQC4ErrorSquared>=0.)
10178   {
10179    fIntFlowQcumulants->SetBinError(2,pow(gQC4ErrorSquared,0.5));
10180   } else
10181     {
10182      fIntFlowQcumulants->SetBinError(2,0.);
10183      cout<<endl;
10184      cout<<" WARNING (QC): Statistical error of generalized QC{4} is imaginary !!!!"<<endl;
10185      cout<<endl;
10186     }   
10187  } // end of if(fApplyCorrectionForNUA && fPropagateErrorAlsoFromNIT)
10188  // Quantify detector bias to QC{4}:
10189  if(TMath::Abs(QC4)>0.)
10190  {
10191   fIntFlowDetectorBias->SetBinContent(2,gQC4/QC4); 
10192   if(QC4Error>0.)
10193   {
10194    Double_t errorSquared = gQC4ErrorSquared/pow(QC4,2.)+pow(gQC4,2.)*pow(QC4Error,2.)/pow(QC4,4.);
10195    if(errorSquared>0.)
10196    {
10197     fIntFlowDetectorBias->SetBinError(2,pow(errorSquared,0.5));  
10198    }
10199   }
10200  } // end of if(TMath::Abs(QC4)>0.)
10201
10202
10203  // .... to be improved (continued for 6th and 8th order) ....            
10204  
10205      
10206  // versus multiplicity:
10207  if(fCalculateCumulantsVsM) // to be improved - propagate error for nua terms vs M
10208  { 
10209   Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
10210   Double_t value[4] = {0.}; // QCs vs M
10211   Double_t error[4] = {0.}; // error of QCs vs M
10212   Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
10213   Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
10214   for(Int_t b=1;b<=nBins;b++)
10215   {
10216    // Measured correlations:
10217    two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> vs M
10218    four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>> vs M
10219    // Isotropic cumulants:
10220    QC2 = two;
10221    QC4 = four-2.*pow(two,2.);
10222    // Non-isotropic terms:
10223    c1 = fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b); // <<cos(n*phi1)>>
10224    c2 = fIntFlowCorrectionTermsForNUAVsMPro[1][1]->GetBinContent(b); // <<cos(n*(phi1+phi2))>>
10225    c3 = fIntFlowCorrectionTermsForNUAVsMPro[1][2]->GetBinContent(b); // <<cos(n*(phi1-phi2-phi3))>>
10226    s1 = fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b); // <<sin(n*phi1)>>
10227    s2 = fIntFlowCorrectionTermsForNUAVsMPro[0][1]->GetBinContent(b); // <<sin(n*(phi1+phi2))>>
10228    s3 = fIntFlowCorrectionTermsForNUAVsMPro[0][2]->GetBinContent(b); // <<sin(n*(phi1-phi2-phi3))>>
10229    // Generalized QC{2} vs M:
10230    gQC2 = two - pow(c1,2.) - pow(s1,2.); 
10231    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[0]->SetBinContent(b,gQC2);}   
10232    // Generalized QC{4} vs M:  
10233    gQC4 = four-2.*pow(two,2.)
10234                  - 4.*c1*c3+4.*s1*s3-pow(c2,2.)-pow(s2,2.)
10235                  + 4.*c2*(pow(c1,2.)-pow(s1,2.))+8.*s2*s1*c1
10236                  + 8.*two*(pow(c1,2.)+pow(s1,2.))-6.*pow((pow(c1,2.)+pow(s1,2.)),2.);
10237    if(fApplyCorrectionForNUAVsM){fIntFlowQcumulantsVsM[1]->SetBinContent(b,gQC4);}   
10238    // Detector bias vs M:
10239    if(TMath::Abs(QC2)>0.)
10240    {
10241     fIntFlowDetectorBiasVsM[0]->SetBinContent(b,gQC2/QC2); 
10242    } // end of if(TMath::Abs(QC2)>0.)
10243    if(TMath::Abs(QC4)>0.)
10244    {
10245     fIntFlowDetectorBiasVsM[1]->SetBinContent(b,gQC4/QC4); 
10246    } // end of if(TMath::Abs(QC4)>0.)  
10247    // Rebin in M:
10248    for(Int_t co=0;co<4;co++)
10249    {
10250     value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
10251     error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
10252     if(error[co]>0.)
10253     {
10254      dSum1[co]+=value[co]/(error[co]*error[co]);
10255      dSum2[co]+=1./(error[co]*error[co]);
10256     }
10257    } // end of for(Int_t co=0;co<4;co++) 
10258   } // end of for(Int_t b=1;b<=nBins;b++)
10259   // Store rebinned Q-cumulants:
10260   if(fApplyCorrectionForNUAVsM)
10261   {
10262    for(Int_t co=0;co<4;co++)
10263    {
10264     if(dSum2[co]>0.)
10265     {
10266      fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
10267      fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
10268     }
10269    } // end of for(Int_t co=0;co<4;co++)
10270   } // end of if(fApplyCorrectionForNUAVsM)
10271  } // end of if(fCalculateCumulantsVsM) 
10272      
10273 } // end of void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
10274  
10275 //================================================================================================================================
10276
10277 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow() 
10278 {
10279  // From profile fIntFlowCorrectionTermsForNUAPro[sc] access measured correction terms for NUA
10280  // and their spread, correctly calculate the statistical errors and store the final 
10281  // results and statistical errors for correction terms for NUA in histogram fIntFlowCorrectionTermsForNUAHist[sc].
10282  //
10283  // Remark: Statistical error of correction temrs is calculated as:
10284  //
10285  //          statistical error = termA * spread * termB:
10286  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
10287  //          termB = 1/sqrt(1-termA^2)   
10288  
10289  TString sinCosFlag[2] = {"sin","cos"}; // to be improved - promore this to data member?
10290  TString nonisotropicTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
10291     
10292  for(Int_t sc=0;sc<2;sc++) // sin or cos correction terms 
10293  {
10294   for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
10295   {
10296    Double_t correction = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci);
10297    Double_t spread = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinError(ci);
10298    Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeightsNUA[sc][0]->GetBinContent(ci);
10299    Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeightsNUA[sc][1]->GetBinContent(ci);
10300    Double_t termA = 0.;
10301    Double_t termB = 0.;
10302    if(TMath::Abs(sumOfLinearEventWeights)>1.e-44)
10303    {
10304     termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
10305    } else
10306      {
10307       cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in AFAWQC::FCTFNIF() !!!!"<<endl;
10308       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
10309      }
10310    if(1.-pow(termA,2.) > 0.)
10311    {
10312     termB = 1./pow(1-pow(termA,2.),0.5);
10313    } else
10314      {
10315       cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in AFAWQC::FCTFNIF() !!!!"<<endl;   
10316       cout<<Form("               (for <<%s[%s]>> non-isotropic term)",sinCosFlag[sc].Data(),nonisotropicTermFlag[ci-1].Data())<<endl;
10317      }     
10318    Double_t statisticalError = termA * spread * termB;
10319    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinContent(ci,correction);
10320    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinError(ci,statisticalError);
10321   } // end of for(Int_t ci=1;ci<=4;ci++) // correction term index
10322  } // end of for(Int sc=0;sc<2;sc++) // sin or cos correction terms 
10323                                                                                                                                                                                                
10324 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow()
10325
10326 //================================================================================================================================
10327
10328 void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
10329 {
10330  // Get pointers to all objects relevant for calculations with nested loops.
10331    
10332  TList *nestedLoopsList = dynamic_cast<TList*>(fHistList->FindObject("Nested Loops"));
10333  if(nestedLoopsList) 
10334  {
10335   this->SetNestedLoopsList(nestedLoopsList);
10336  } else
10337    {
10338     cout<<"WARNING: nestedLoopsList is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10339     exit(0);
10340    }
10341     
10342   TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
10343   TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
10344   TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
10345   TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
10346    
10347   TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
10348   evaluateNestedLoopsName += fAnalysisLabel->Data();  
10349   TProfile *evaluateNestedLoops = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(evaluateNestedLoopsName.Data()));
10350   Bool_t bEvaluateIntFlowNestedLoops = kFALSE;
10351   Bool_t bEvaluateDiffFlowNestedLoops = kFALSE;
10352   if(evaluateNestedLoops)
10353   {
10354    this->SetEvaluateNestedLoops(evaluateNestedLoops);
10355    bEvaluateIntFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(1);
10356    bEvaluateDiffFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(2);
10357   }
10358   // nested loops relevant for integrated flow:  
10359   if(bEvaluateIntFlowNestedLoops)
10360   {
10361    // correlations:
10362    TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
10363    intFlowDirectCorrelationsName += fAnalysisLabel->Data();
10364    TProfile *intFlowDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowDirectCorrelationsName.Data()));
10365    if(intFlowDirectCorrelations) 
10366    { 
10367     this->SetIntFlowDirectCorrelations(intFlowDirectCorrelations);
10368    } else
10369      {
10370       cout<<"WARNING: intFlowDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10371       exit(0);
10372      }
10373    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)  
10374    {
10375     TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
10376     intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
10377     TProfile *intFlowExtraDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowExtraDirectCorrelationsName.Data()));
10378     if(intFlowExtraDirectCorrelations) 
10379     { 
10380      this->SetIntFlowExtraDirectCorrelations(intFlowExtraDirectCorrelations);
10381     } else
10382       {
10383        cout<<"WARNING: intFlowExtraDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10384        exit(0);
10385       }       
10386    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)  
10387    // correction terms for non-uniform acceptance:
10388    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
10389    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
10390    TProfile *intFlowDirectCorrectionTermsForNUA[2] = {NULL};
10391    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
10392    {
10393     intFlowDirectCorrectionTermsForNUA[sc] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s: %s terms",intFlowDirectCorrectionTermsForNUAName.Data(),sinCosFlag[sc].Data())));
10394     if(intFlowDirectCorrectionTermsForNUA[sc]) 
10395     { 
10396      this->SetIntFlowDirectCorrectionTermsForNUA(intFlowDirectCorrectionTermsForNUA[sc],sc);
10397     } else
10398       {
10399        cout<<"WARNING: intFlowDirectCorrectionTermsForNUA[sc] is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
10400        cout<<"sc = "<<sc<<endl;
10401        exit(0);
10402       }
10403    } // end of for(Int_t sc=0;sc<2;sc++) 
10404   } // end of if(bEvaluateIntFlowNestedLoops)
10405     
10406   // nested loops relevant for differential flow:  
10407   if(bEvaluateDiffFlowNestedLoops)
10408   {
10409    // correlations:
10410    TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
10411    diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
10412    TProfile *diffFlowDirectCorrelations[2][2][4] = {{{NULL}}};
10413    for(Int_t t=0;t<2;t++)
10414    {
10415     for(Int_t pe=0;pe<2;pe++)
10416     {
10417      for(Int_t ci=0;ci<4;ci++) // correlation index
10418      {
10419       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())));
10420       if(diffFlowDirectCorrelations[t][pe][ci])
10421       {
10422        this->SetDiffFlowDirectCorrelations(diffFlowDirectCorrelations[t][pe][ci],t,pe,ci);
10423       } else
10424         {
10425          cout<<"WARNING: diffFlowDirectCorrelations[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10426          cout<<"t  = "<<t<<endl;
10427          cout<<"pe = "<<pe<<endl;   
10428          cout<<"ci = "<<ci<<endl;
10429         }     
10430      } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
10431     } // end of for(Int_t pe=0;pe<2;pe++)
10432    } // end of for(Int_t t=0;t<2;t++)   
10433    // correction terms for non-uniform acceptance:
10434    TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
10435    diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();  
10436    TProfile *diffFlowDirectCorrectionTermsForNUA[2][2][2][10] = {{{{NULL}}}};   
10437    for(Int_t t=0;t<2;t++)
10438    {
10439     for(Int_t pe=0;pe<2;pe++)
10440     {
10441      // correction terms for NUA:
10442      for(Int_t sc=0;sc<2;sc++) // sin or cos
10443      {
10444       for(Int_t cti=0;cti<9;cti++) // correction term index
10445       {
10446        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)));
10447        if(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti])
10448        {
10449         this->SetDiffFlowDirectCorrectionTermsForNUA(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti],t,pe,sc,cti);
10450        } else
10451          {
10452           cout<<"WARNING: diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10453           cout<<"t   = "<<t<<endl;
10454           cout<<"pe  = "<<pe<<endl;   
10455           cout<<"sc  = "<<sc<<endl;
10456           cout<<"cti = "<<cti<<endl;
10457          }    
10458       } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
10459      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
10460     } // end of for(Int_t pe=0;pe<2;pe++)
10461    } // end of for(Int_t t=0;t<2;t++)
10462    // other differential correlators:
10463    TString otherDirectDiffCorrelatorsName = "fOtherDirectDiffCorrelators";
10464    otherDirectDiffCorrelatorsName += fAnalysisLabel->Data();  
10465    TProfile *otherDirectDiffCorrelators[2][2][2][1] = {{{{NULL}}}};   
10466    for(Int_t t=0;t<2;t++)
10467    {
10468     for(Int_t pe=0;pe<2;pe++)
10469     {
10470      // correction terms for NUA:
10471      for(Int_t sc=0;sc<2;sc++) // sin or cos
10472      {
10473       for(Int_t ci=0;ci<1;ci++) // correlator index
10474       {
10475        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)));
10476        if(otherDirectDiffCorrelators[t][pe][sc][ci])
10477        {
10478         this->SetOtherDirectDiffCorrelators(otherDirectDiffCorrelators[t][pe][sc][ci],t,pe,sc,ci);
10479        } else
10480          {
10481           cout<<"WARNING: otherDirectDiffCorrelators[t][pe][sc][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10482           cout<<"t   = "<<t<<endl;
10483           cout<<"pe  = "<<pe<<endl;   
10484           cout<<"sc  = "<<sc<<endl;
10485           cout<<"ci = "<<ci<<endl;
10486          }    
10487       } // end of for(Int_t ci=0;ci<9;ci++) // correction term index
10488      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
10489     } // end of for(Int_t pe=0;pe<2;pe++)
10490    } // end of for(Int_t t=0;t<2;t++)
10491    // number of RPs and POIs in selected pt and eta bins for cross-checkings:
10492    TString noOfParticlesInBinName = "fNoOfParticlesInBin";
10493    TH1D *noOfParticlesInBin = NULL;
10494    noOfParticlesInBin = dynamic_cast<TH1D*>(nestedLoopsList->FindObject(noOfParticlesInBinName.Data()));
10495    if(noOfParticlesInBin)
10496    {
10497     this->SetNoOfParticlesInBin(noOfParticlesInBin);
10498    } else
10499      {
10500       cout<<endl;
10501       cout<<" WARNING (QC): noOfParticlesInBin is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
10502       cout<<endl;
10503      }
10504   } // end of if(bEvaluateDiffFlowNestedLoops)
10505
10506 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
10507
10508 //================================================================================================================================
10509
10510 void AliFlowAnalysisWithQCumulants::StoreHarmonic()
10511 {
10512  // Store flow harmonic in common control histograms.
10513
10514  (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
10515  if(fFillMultipleControlHistograms)
10516  {
10517   (fCommonHists2nd->GetHarmonic())->Fill(0.5,fHarmonic);
10518   (fCommonHists4th->GetHarmonic())->Fill(0.5,fHarmonic);
10519   (fCommonHists6th->GetHarmonic())->Fill(0.5,fHarmonic);
10520   (fCommonHists8th->GetHarmonic())->Fill(0.5,fHarmonic);
10521  }
10522  
10523 } // end of void AliFlowAnalysisWithQCumulants::StoreHarmonic()
10524
10525 //================================================================================================================================
10526
10527 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta) // type = RP or POI 
10528 {
10529  // Calculate all correlations needed for differential flow using particle weights.
10530  
10531  Int_t t = 0; // type flag 
10532  Int_t pe = 0; // ptEta flag
10533  
10534  if(type == "RP")
10535  {
10536   t = 0;
10537  } else if(type == "POI")
10538    {
10539     t = 1;
10540    }
10541
10542  if(ptOrEta == "Pt")
10543  {
10544   pe = 0;
10545  } else if(ptOrEta == "Eta")
10546    {
10547     pe = 1;
10548    }
10549     
10550  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10551  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10552  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10553  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10554
10555  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10556  Double_t dReQ1n1k = (*fReQ)(0,1);
10557  Double_t dReQ2n2k = (*fReQ)(1,2);
10558  Double_t dReQ1n3k = (*fReQ)(0,3);
10559  //Double_t dReQ4n4k = (*fReQ)(3,4);
10560  Double_t dImQ1n1k = (*fImQ)(0,1);
10561  Double_t dImQ2n2k = (*fImQ)(1,2);
10562  Double_t dImQ1n3k = (*fImQ)(0,3);
10563  //Double_t dImQ4n4k = (*fImQ)(3,4);
10564  
10565  // S^M_{p,k} (see .h file for the definition of fSpk):
10566  Double_t dSM1p1k = (*fSpk)(0,1);
10567  Double_t dSM1p2k = (*fSpk)(0,2);
10568  Double_t dSM1p3k = (*fSpk)(0,3);
10569  Double_t dSM2p1k = (*fSpk)(1,1);
10570  Double_t dSM3p1k = (*fSpk)(2,1);
10571  
10572  // looping over all bins and calculating reduced correlations: 
10573  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10574  {
10575   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
10576   Double_t p1n0kRe = 0.;
10577   Double_t p1n0kIm = 0.;
10578
10579   // number of POIs in particular (pt,eta) bin):
10580   Double_t mp = 0.;
10581
10582   // real and imaginary parts of q_{m*n,k}: 
10583   // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
10584   Double_t q1n2kRe = 0.;
10585   Double_t q1n2kIm = 0.;
10586   Double_t q2n1kRe = 0.;
10587   Double_t q2n1kIm = 0.;
10588
10589   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10590   Double_t s1p1k = 0.; 
10591   Double_t s1p2k = 0.; 
10592   Double_t s1p3k = 0.; 
10593    
10594   // M0111 from Eq. (118) in QC2c (to be improved (notation))
10595   Double_t dM0111 = 0.;
10596  
10597   if(type == "POI")
10598   {
10599    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10600            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10601    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10602            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10603             
10604    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10605     
10606    t = 1; // typeFlag = RP or POI
10607     
10608    // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
10609    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
10610            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
10611    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
10612            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));
10613    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
10614            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
10615    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
10616            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));
10617        
10618    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10619    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
10620    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
10621    s1p3k = pow(fs1dEBE[2][pe][3]->GetBinContent(b)*fs1dEBE[2][pe][3]->GetBinEntries(b),1.); 
10622      
10623    // M0111 from Eq. (118) in QC2c (to be improved (notation)):
10624    dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
10625           - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
10626           + 2.*(s1p3k-s1p2k*dSM1p1k));
10627   }
10628    else if(type == "RP")
10629    {
10630     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
10631     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
10632             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
10633     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
10634             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
10635     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
10636             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
10637     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
10638             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
10639
10640     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
10641     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
10642     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
10643     s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
10644     
10645     // to be improved (cross-checked):
10646     p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10647             * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10648     p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
10649             * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10650             
10651     mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10652      
10653     t = 0; // typeFlag = RP or POI
10654     
10655     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
10656     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
10657            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
10658            + 2.*(s1p3k-s1p2k*dSM1p1k));
10659     //...............................................................................................   
10660    }
10661    
10662    // 2'-particle correlation:
10663    Double_t two1n1nW0W1 = 0.;
10664    if(mp*dSM1p1k-s1p1k)
10665    {
10666     two1n1nW0W1 = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
10667                 / (mp*dSM1p1k-s1p1k);
10668    
10669     // fill profile to get <<2'>>     
10670     fDiffFlowCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1,mp*dSM1p1k-s1p1k);    
10671     // fill profile to get <<2'>^2>     
10672     fDiffFlowSquaredCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1*two1n1nW0W1,mp*dSM1p1k-s1p1k);        
10673     // histogram to store <2'> e-b-e (needed in some other methods):
10674     fDiffFlowCorrelationsEBE[t][pe][0]->SetBinContent(b,two1n1nW0W1);      
10675     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->SetBinContent(b,mp*dSM1p1k-s1p1k);      
10676    } // end of if(mp*dSM1p1k-s1p1k)
10677    
10678    // 4'-particle correlation:
10679    Double_t four1n1n1n1nW0W1W1W1 = 0.;
10680    if(dM0111)
10681    {
10682     four1n1n1n1nW0W1W1W1 = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
10683                          - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
10684                          - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
10685                          - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
10686                          + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
10687                          - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
10688                          - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
10689                          + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
10690                          + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
10691                          + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
10692                          + 2.*s1p1k*dSM1p2k                                      
10693                          - 6.*s1p3k)        
10694                          / dM0111; // to be improved (notation of dM0111)
10695    
10696     // fill profile to get <<4'>>     
10697     fDiffFlowCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1,dM0111);    
10698     // fill profile to get <<4'>^2>     
10699     fDiffFlowSquaredCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1*four1n1n1n1nW0W1W1W1,dM0111);        
10700     // histogram to store <4'> e-b-e (needed in some other methods):
10701     fDiffFlowCorrelationsEBE[t][pe][1]->SetBinContent(b,four1n1n1n1nW0W1W1W1);      
10702     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->SetBinContent(b,dM0111);      
10703    } // end of if(dM0111)
10704  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10705
10706 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta); // type = RP or POI 
10707
10708 //================================================================================================================================
10709
10710 void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
10711 {
10712  // Fill common control histograms.
10713  
10714  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
10715  fCommonHists->FillControlHistograms(anEvent); 
10716  if(fFillMultipleControlHistograms)
10717  {
10718   if(nRP>1)
10719   {
10720    fCommonHists2nd->FillControlHistograms(anEvent);                                        
10721    if(nRP>3)
10722    {
10723     fCommonHists4th->FillControlHistograms(anEvent);                                        
10724     if(nRP>5)
10725     {
10726      fCommonHists6th->FillControlHistograms(anEvent);                                        
10727      if(nRP>7)
10728      {
10729       fCommonHists8th->FillControlHistograms(anEvent);                                        
10730      } // end of if(nRP>7)  
10731     } // end of if(nRP>5) 
10732    } // end of if(nRP>3)                                                                                                                      
10733   } // end of if(nRP>1) 
10734  } // end of if(fFillMultipleControlHistograms)
10735  
10736 } // end of void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
10737
10738 //================================================================================================================================
10739
10740 void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities()
10741 {
10742  // Reset all event by event quantities.
10743  
10744  // Reference flow:
10745  fReQ->Zero();
10746  fImQ->Zero();
10747  fSpk->Zero();
10748  fIntFlowCorrelationsEBE->Reset();
10749  fIntFlowEventWeightsForCorrelationsEBE->Reset();
10750  fIntFlowCorrelationsAllEBE->Reset();
10751  
10752  for(Int_t sc=0;sc<2;sc++)
10753  {
10754   fIntFlowCorrectionTermsForNUAEBE[sc]->Reset();
10755   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->Reset(); 
10756  }
10757     
10758  // Differential flow:
10759  if(fCalculateDiffFlow)
10760  {
10761   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
10762   {
10763    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // 1D in pt or eta
10764    {
10765     for(Int_t m=0;m<4;m++) // multiple of harmonic
10766     {
10767      for(Int_t k=0;k<9;k++) // power of weight
10768      {
10769       if(fReRPQ1dEBE[t][pe][m][k]) fReRPQ1dEBE[t][pe][m][k]->Reset();
10770       if(fImRPQ1dEBE[t][pe][m][k]) fImRPQ1dEBE[t][pe][m][k]->Reset();
10771      }   
10772     } 
10773    }
10774   } 
10775   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
10776   { 
10777    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // 1D in pt or eta
10778    {
10779     for(Int_t k=0;k<9;k++)
10780     {
10781      if(fs1dEBE[t][pe][k]) fs1dEBE[t][pe][k]->Reset();
10782     }
10783    }
10784   }
10785   // e-b-e reduced correlations:
10786   for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
10787   {  
10788    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
10789    {
10790     for(Int_t rci=0;rci<4;rci++) // reduced correlation index
10791     {
10792      if(fDiffFlowCorrelationsEBE[t][pe][rci]) fDiffFlowCorrelationsEBE[t][pe][rci]->Reset();
10793      if(fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]) fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]->Reset();
10794     }
10795    }
10796   }  
10797   // correction terms for NUA:
10798   for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
10799   {  
10800    for(Int_t pe=0;pe<1+(Int_t)fCalculateDiffFlowVsEta;pe++) // pt or eta
10801    {
10802     for(Int_t sc=0;sc<2;sc++) // sin or cos
10803     {
10804      for(Int_t cti=0;cti<9;cti++) // correction term index
10805      {
10806      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti]->Reset();  
10807      }
10808     }
10809    }      
10810   }
10811  } // end of if(fCalculateDiffFlow)   
10812
10813  // 2D (pt,eta)
10814  if(fCalculate2DDiffFlow)
10815  {
10816   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
10817   {
10818    for(Int_t m=0;m<4;m++) // multiple of harmonic
10819    {
10820     for(Int_t k=0;k<9;k++) // power of weight
10821     {
10822      if(fReRPQ2dEBE[t][m][k]){fReRPQ2dEBE[t][m][k]->Reset();}
10823      if(fImRPQ2dEBE[t][m][k]){fImRPQ2dEBE[t][m][k]->Reset();}
10824     }   
10825    }
10826   }
10827   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
10828   { 
10829    for(Int_t k=0;k<9;k++)
10830    {
10831     if(fs2dEBE[t][k]){fs2dEBE[t][k]->Reset();}
10832    }
10833   }  
10834  } // end of if(fCalculate2DDiffFlow) 
10835
10836 } // end of void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities();
10837
10838 //================================================================================================================================
10839
10840 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
10841 {
10842  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
10843  
10844  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
10845  //  0: <<sin n(psi1)>>
10846  //  1: <<sin n(psi1+phi2)>>
10847  //  2: <<sin n(psi1+phi2-phi3)>>
10848  //  3: <<sin n(psi1-phi2-phi3)>>:
10849  //  4:
10850  //  5:
10851  //  6:
10852  
10853  // multiplicity:
10854  Double_t dMult = (*fSpk)(0,0);
10855  
10856  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
10857  Double_t dReQ1n = (*fReQ)(0,0);
10858  Double_t dReQ2n = (*fReQ)(1,0);
10859  //Double_t dReQ3n = (*fReQ)(2,0);
10860  //Double_t dReQ4n = (*fReQ)(3,0);
10861  Double_t dImQ1n = (*fImQ)(0,0);
10862  Double_t dImQ2n = (*fImQ)(1,0);
10863  //Double_t dImQ3n = (*fImQ)(2,0);
10864  //Double_t dImQ4n = (*fImQ)(3,0);
10865
10866  Int_t t = 0; // type flag 
10867  Int_t pe = 0; // ptEta flag
10868  
10869  if(type == "RP")
10870  {
10871   t = 0;
10872  } else if(type == "POI")
10873    {
10874     t = 1;
10875    }
10876
10877  if(ptOrEta == "Pt")
10878  {
10879   pe = 0;
10880  } else if(ptOrEta == "Eta")
10881    {
10882     pe = 1;
10883    }
10884     
10885  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10886  Double_t minPtEta[2] = {fPtMin,fEtaMin};
10887  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
10888  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10889
10890  // looping over all bins and calculating correction terms: 
10891  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10892  {
10893   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
10894   Double_t p1n0kRe = 0.;
10895   Double_t p1n0kIm = 0.;
10896
10897   // number of POIs in particular pt or eta bin:
10898   Double_t mp = 0.;
10899
10900   // 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):
10901   Double_t q1n0kRe = 0.;
10902   Double_t q1n0kIm = 0.;
10903   Double_t q2n0kRe = 0.;
10904   Double_t q2n0kIm = 0.;
10905
10906   // number of particles which are both RPs and POIs in particular pt or eta bin:
10907   Double_t mq = 0.;
10908    
10909   if(type == "POI")
10910   {
10911    // q_{m*n,0}:
10912    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
10913            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
10914    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
10915            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
10916    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
10917            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
10918    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
10919            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
10920                  
10921    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10922   } 
10923   else if(type == "RP")
10924   {
10925    // q_{m*n,0}:
10926    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
10927            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
10928    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
10929            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
10930    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
10931            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
10932    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
10933            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
10934                  
10935    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
10936   }    
10937   if(type == "POI")
10938   {
10939    // p_{m*n,0}:
10940    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
10941            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
10942    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
10943            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
10944             
10945    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
10946     
10947    t = 1; // typeFlag = RP or POI
10948   }
10949   else if(type == "RP")
10950   {
10951    // p_{m*n,0} = q_{m*n,0}:
10952    p1n0kRe = q1n0kRe; 
10953    p1n0kIm = q1n0kIm; 
10954            
10955    mp = mq; 
10956    
10957    t = 0; // typeFlag = RP or POI
10958   }
10959
10960   // <<sin n(psi1)>>:
10961   Double_t sinP1nPsi = 0.;
10962   if(mp)
10963   {
10964    sinP1nPsi = p1n0kIm/mp;
10965    // fill profile for <<sin n(psi1)>>:
10966    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
10967    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
10968    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
10969   } // end of if(mp)   
10970   
10971   // <<sin n(psi1+phi2)>>:
10972   Double_t sinP1nPsiP1nPhi = 0.;
10973   if(mp*dMult-mq)
10974   {
10975    sinP1nPsiP1nPhi = (p1n0kRe*dImQ1n+p1n0kIm*dReQ1n-q2n0kIm)/(mp*dMult-mq);
10976    // fill profile for <<sin n(psi1+phi2)>>:
10977    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhi,mp*dMult-mq);
10978    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10979    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhi);
10980   } // end of if(mp*dMult-mq)   
10981   
10982   // <<sin n(psi1+phi2-phi3)>>:
10983   Double_t sinP1nPsi1P1nPhi2MPhi3 = 0.;
10984   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10985   {
10986    sinP1nPsi1P1nPhi2MPhi3 = (p1n0kIm*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
10987                           - 1.*(q2n0kIm*dReQ1n-q2n0kRe*dImQ1n)  
10988                           - mq*dImQ1n+2.*q1n0kIm)
10989                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10990    // fill profile for <<sin n(psi1+phi2)>>:
10991    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
10992    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
10993    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3);
10994   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
10995   
10996   // <<sin n(psi1-phi2-phi3)>>:
10997   Double_t sinP1nPsi1M1nPhi2MPhi3 = 0.;
10998   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
10999   {
11000    sinP1nPsi1M1nPhi2MPhi3 = (p1n0kIm*(pow(dReQ1n,2.)-pow(dImQ1n,2.))-2.*p1n0kRe*dReQ1n*dImQ1n
11001                           - 1.*(p1n0kIm*dReQ2n-p1n0kRe*dImQ2n)
11002                           + 2.*mq*dImQ1n-2.*q1n0kIm)
11003                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11004    // fill profile for <<sin n(psi1+phi2)>>:
11005    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11006    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
11007    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3);
11008   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
11009  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11010  
11011 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
11012
11013
11014 //================================================================================================================================
11015
11016
11017 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
11018 {
11019  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms).
11020  
11021  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
11022  //  0: <<cos n(psi)>>
11023  //  1: <<cos n(psi1+phi2)>>
11024  //  2: <<cos n(psi1+phi2-phi3)>>
11025  //  3: <<cos n(psi1-phi2-phi3)>>
11026  //  4:
11027  //  5:
11028  //  6:
11029  
11030  // multiplicity:
11031  Double_t dMult = (*fSpk)(0,0);
11032  
11033  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
11034  Double_t dReQ1n = (*fReQ)(0,0);
11035  Double_t dReQ2n = (*fReQ)(1,0);
11036  //Double_t dReQ3n = (*fReQ)(2,0);
11037  //Double_t dReQ4n = (*fReQ)(3,0);
11038  Double_t dImQ1n = (*fImQ)(0,0);
11039  Double_t dImQ2n = (*fImQ)(1,0);
11040  //Double_t dImQ3n = (*fImQ)(2,0);
11041  //Double_t dImQ4n = (*fImQ)(3,0);
11042
11043  Int_t t = 0; // type flag 
11044  Int_t pe = 0; // ptEta flag
11045  
11046  if(type == "RP")
11047  {
11048   t = 0;
11049  } else if(type == "POI")
11050    {
11051     t = 1;
11052    }
11053
11054  if(ptOrEta == "Pt")
11055  {
11056   pe = 0;
11057  } else if(ptOrEta == "Eta")
11058    {
11059     pe = 1;
11060    }
11061     
11062  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11063  Double_t minPtEta[2] = {fPtMin,fEtaMin};
11064  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
11065  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11066
11067  // looping over all bins and calculating correction terms: 
11068  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11069  {
11070   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
11071   Double_t p1n0kRe = 0.;
11072   Double_t p1n0kIm = 0.;
11073
11074   // number of POIs in particular pt or eta bin:
11075   Double_t mp = 0.;
11076
11077   // 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):
11078   Double_t q1n0kRe = 0.;
11079   Double_t q1n0kIm = 0.;
11080   Double_t q2n0kRe = 0.;
11081   Double_t q2n0kIm = 0.;
11082
11083   // number of particles which are both RPs and POIs in particular pt or eta bin:
11084   Double_t mq = 0.;
11085    
11086   if(type == "POI")
11087   {
11088    // q_{m*n,0}:
11089    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
11090            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
11091    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
11092            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
11093    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
11094            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
11095    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
11096            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
11097                  
11098    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
11099   } 
11100   else if(type == "RP")
11101   {
11102    // q_{m*n,0}:
11103    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
11104            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
11105    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
11106            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
11107    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
11108            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
11109    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
11110            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
11111                  
11112    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
11113   }    
11114   if(type == "POI")
11115   {
11116    // p_{m*n,0}:
11117    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
11118            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
11119    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
11120            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
11121             
11122    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
11123     
11124    t = 1; // typeFlag = RP or POI
11125   }
11126   else if(type == "RP")
11127   {
11128    // p_{m*n,0} = q_{m*n,0}:
11129    p1n0kRe = q1n0kRe; 
11130    p1n0kIm = q1n0kIm; 
11131            
11132    mp = mq; 
11133    
11134    t = 0; // typeFlag = RP or POI
11135   }
11136
11137   // <<cos n(psi1)>>:
11138   Double_t cosP1nPsi = 0.;
11139   if(mp)
11140   {
11141    cosP1nPsi = p1n0kRe/mp;
11142    
11143    // fill profile for <<cos n(psi1)>>:
11144    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
11145    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
11146    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
11147   } // end of if(mp)   
11148   
11149   // <<cos n(psi1+phi2)>>:
11150   Double_t cosP1nPsiP1nPhi = 0.;
11151   if(mp*dMult-mq)
11152   {
11153    cosP1nPsiP1nPhi = (p1n0kRe*dReQ1n-p1n0kIm*dImQ1n-q2n0kRe)/(mp*dMult-mq);
11154    // fill profile for <<sin n(psi1+phi2)>>:
11155    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhi,mp*dMult-mq);
11156    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
11157    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhi);
11158   } // end of if(mp*dMult-mq)   
11159   
11160   // <<cos n(psi1+phi2-phi3)>>:
11161   Double_t cosP1nPsi1P1nPhi2MPhi3 = 0.;
11162   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
11163   {
11164    cosP1nPsi1P1nPhi2MPhi3 = (p1n0kRe*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
11165                           - 1.*(q2n0kRe*dReQ1n+q2n0kIm*dImQ1n)  
11166                           - mq*dReQ1n+2.*q1n0kRe)
11167                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11168    // fill profile for <<sin n(psi1+phi2)>>:
11169    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11170    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
11171    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3);
11172   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
11173   
11174   // <<cos n(psi1-phi2-phi3)>>:
11175   Double_t cosP1nPsi1M1nPhi2MPhi3 = 0.;
11176   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
11177   {
11178    cosP1nPsi1M1nPhi2MPhi3 = (p1n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))+2.*p1n0kIm*dReQ1n*dImQ1n
11179                           - 1.*(p1n0kRe*dReQ2n+p1n0kIm*dImQ2n)  
11180                           - 2.*mq*dReQ1n+2.*q1n0kRe)
11181                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11182    // fill profile for <<sin n(psi1+phi2)>>:
11183    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
11184    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
11185    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3);
11186   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
11187  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11188  
11189 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
11190
11191 //==================================================================================================================================
11192
11193 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
11194 {
11195  // Transfer profiles into histogams and correctly propagate the error.
11196  
11197  Int_t t = 0; // type flag 
11198  Int_t pe = 0; // ptEta flag
11199  
11200  if(type == "RP")
11201  {
11202   t = 0;
11203  } else if(type == "POI")
11204    {
11205     t = 1;
11206    }
11207
11208  if(ptOrEta == "Pt")
11209  {
11210   pe = 0;
11211  } else if(ptOrEta == "Eta")
11212    {
11213     pe = 1;
11214    }
11215     
11216  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11217  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
11218  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
11219  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11220
11221  for(Int_t sc=0;sc<2;sc++) // sin or cos
11222  {
11223   for(Int_t cti=0;cti<9;cti++) // correction term index
11224   {
11225    for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11226    {
11227     Double_t correctionTerm = fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(b);
11228     fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]->SetBinContent(b,correctionTerm);
11229     // to be improved (propagate error correctly)
11230     // ...
11231    } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11232   } // correction term index
11233  } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
11234
11235 }// end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
11236
11237 //==================================================================================================================================
11238
11239 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
11240
11241  // Calculate generalized differential flow cumulants (corrected for non-uniform acceptance).
11242  
11243  // to be improved - propagate error also from non-isotropic terms
11244   
11245  Int_t t = 0; // RP = 0, POI = 1
11246  Int_t pe = 0; // pt = 0, eta = 1
11247
11248  if(type == "RP")
11249  {
11250   t = 0;
11251  } else if(type == "POI")
11252    {
11253     t = 1;
11254    } 
11255      
11256  if(ptOrEta == "Pt")
11257  {
11258   pe = 0;
11259  } else if(ptOrEta == "Eta")
11260    {
11261     pe = 1;
11262    } 
11263        
11264  // Common:
11265  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11266  // 2-particle correlation:
11267  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
11268  // sinus terms coming from reference flow: 
11269  Double_t sinP1nPhi = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
11270  Double_t sinP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
11271  Double_t sinP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
11272  // cosinus terms coming from reference flow: 
11273  Double_t cosP1nPhi = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
11274  Double_t cosP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
11275  Double_t cosP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
11276
11277  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11278  {
11279   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
11280   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
11281   Double_t sinP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][0]->GetBinContent(b); // <<sin n(Psi)>> 
11282   Double_t cosP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][0]->GetBinContent(b); // <<cos n(Psi)>> 
11283   Double_t sinP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][1]->GetBinContent(b); // <<sin n(psi1+phi2)>> 
11284   Double_t cosP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][1]->GetBinContent(b); // <<cos n(psi1+phi2)>> 
11285   Double_t sinP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][2]->GetBinContent(b); // <<sin n(psi1+phi2-phi3)>> 
11286   Double_t cosP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][2]->GetBinContent(b); // <<cos n(psi1+phi2-phi3)>> 
11287   Double_t sinP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][3]->GetBinContent(b); // <<sin n(psi1-phi2-phi3)>> 
11288   Double_t cosP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][3]->GetBinContent(b); // <<cos n(psi1-phi2-phi3)>> 
11289   // Generalized QC{2'}:
11290   Double_t qc2Prime = twoPrime - sinP1nPsi*sinP1nPhi - cosP1nPsi*cosP1nPhi;
11291   if(fApplyCorrectionForNUA)
11292   {
11293    fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime);
11294   }
11295   if(TMath::Abs(twoPrime)>0.)
11296   {
11297    fDiffFlowDetectorBias[t][pe][0]->SetBinContent(b,qc2Prime/twoPrime); // detector bias = generalized/isotropic cumulant.   
11298   }
11299   // Generalized QC{4'}:
11300   Double_t qc4Prime = fourPrime-2.*twoPrime*two
11301                     - cosP1nPsi*cosP1nPhi1M1nPhi2M1nPhi3
11302                     + sinP1nPsi*sinP1nPhi1M1nPhi2M1nPhi3
11303                     - cosP1nPhi*cosP1nPsi1M1nPhi2M1nPhi3
11304                     + sinP1nPhi*sinP1nPsi1M1nPhi2M1nPhi3
11305                     - 2.*cosP1nPhi*cosP1nPsi1P1nPhi2M1nPhi3
11306                     - 2.*sinP1nPhi*sinP1nPsi1P1nPhi2M1nPhi3
11307                     - cosP1nPsi1P1nPhi2*cosP1nPhi1P1nPhi2
11308                     - sinP1nPsi1P1nPhi2*sinP1nPhi1P1nPhi2
11309                     + 2.*cosP1nPhi1P1nPhi2*(cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
11310                     + 2.*sinP1nPhi1P1nPhi2*(cosP1nPsi*sinP1nPhi+sinP1nPsi*cosP1nPhi)
11311                     + 4.*two*(cosP1nPsi*cosP1nPhi+sinP1nPsi*sinP1nPhi)
11312                     + 2.*cosP1nPsi1P1nPhi2*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.))
11313                     + 4.*sinP1nPsi1P1nPhi2*cosP1nPhi*sinP1nPhi
11314                     + 4.*twoPrime*(pow(cosP1nPhi,2.)+pow(sinP1nPhi,2.))
11315                     - 6.*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.)) 
11316                     * (cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
11317                     - 12.*cosP1nPhi*sinP1nPhi
11318                     * (sinP1nPsi*cosP1nPhi+cosP1nPsi*sinP1nPhi);
11319   if(fApplyCorrectionForNUA)
11320   {
11321    fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime);   
11322   }
11323   if(TMath::Abs(fourPrime-2.*twoPrime*two)>0.)
11324   {
11325    fDiffFlowDetectorBias[t][pe][1]->SetBinContent(b,qc4Prime/(fourPrime-2.*twoPrime*two)); // detector bias = generalized/isotropic cumulant.   
11326   }
11327  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
11328  
11329 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
11330
11331 //==================================================================================================================================    
11332
11333 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
11334 {
11335  // Calculate differential flow corrected for non-uniform acceptance.
11336  
11337  // to be improved: eventually I will have to access here masured correlations and NUA terms
11338  //                 instead of cumulants in order to propagate statistical error correctly also 
11339  //                 to NUA terms (propagating errors directly from cumulants is WRONG for 
11340  //                 differential flow becuase that doesn't account at all cross-covariance terms) 
11341  
11342  // REMARK: When NUA correction is apllied error for differential flow DOES NOT get corrected,
11343  //         i.e. only value is being corrected, error is still the one relevant for isotropic
11344  //         case. This eventually will be resolved. 
11345   
11346  
11347  Int_t t = 0; // RP or POI
11348  Int_t pe = 0; // pt or eta
11349
11350  if(type == "RP")
11351  {
11352   t = 0;
11353  } else if(type == "POI")
11354    {
11355     t = 1;
11356    }     
11357  if(ptOrEta == "Pt")
11358  {
11359   pe = 0;
11360  } else if(ptOrEta == "Eta")
11361    {
11362     pe = 1;
11363    } 
11364   
11365  // Common:
11366  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11367  // Reference Q-cumulants
11368  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2} 
11369  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}
11370  // Loop over pt or eta bins:
11371  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
11372  {
11373   // Differential Q-cumulants:
11374   Double_t qc2Prime = fDiffFlowCumulants[t][pe][0]->GetBinContent(b); // QC{2'}
11375   Double_t qc4Prime = fDiffFlowCumulants[t][pe][1]->GetBinContent(b); // QC{4'}
11376   // v'{2}:
11377   if(qc2>0.)
11378   { 
11379    Double_t v2Prime = qc2Prime/pow(qc2,0.5);
11380    if(TMath::Abs(v2Prime)>0.){fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime);} 
11381   }  
11382   // v'{4}:
11383   if(qc4<0.)
11384   { 
11385    Double_t v4Prime = -qc4Prime/pow(-qc4,3./4.);
11386    if(TMath::Abs(v4Prime)>0.){fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);} 
11387   }  
11388  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
11389   
11390 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta); 
11391
11392 //==================================================================================================================================
11393
11394 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent)
11395 {
11396  // Evaluate with nested loops multiparticle correlations for integrated flow (without using the particle weights). 
11397
11398  // Remark: Results are stored in profile fIntFlowDirectCorrelations whose binning is organized as follows:
11399  // 
11400  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
11401  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
11402  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
11403  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
11404  //  5th bin:           ----  EMPTY ----
11405  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
11406  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
11407  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
11408  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
11409  // 10th bin:           ----  EMPTY ----
11410  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
11411  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
11412  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
11413  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
11414  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
11415  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
11416  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
11417  // 18th bin:           ----  EMPTY ----
11418  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
11419  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
11420  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
11421  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
11422  // 23rd bin:           ----  EMPTY ----
11423  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
11424  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
11425  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
11426  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
11427  // 28th bin:           ----  EMPTY ----
11428  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
11429  // 30th bin:           ----  EMPTY ----
11430  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
11431  // 32nd bin:           ----  EMPTY ----
11432   //  Extra correlations for 3p TY study: 
11433  // 33rd bin: <4>_{4n,2n|3n,3n}= four4n2n3n3n = <cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4))>
11434  // 34th bin: <5>_{3n,3n|2n,2n,2n} = five3n3n2n2n2n = <cos(n(3*phi1+3*phi2-2*phi3-2*phi4-2*phi5))> 
11435   //  Extra correlations for 6p TY study: 
11436  // 35th bin: <2>_{5n|5n} = two5n5n = <cos(5n*(phi1-phi2)> T
11437  // 36th bin: <2>_{6n|6n} = two6n6n = <cos(6n*(phi1-phi2)> T
11438  // 37th bin: <3>_{5n|3n,2n} = three5n3n2n = <cos(n*(5*phi1-3*phi2-2*phi3)> 
11439  // 38th bin: <3>_{5n|4n,1n} = three5n4n1n = <cos(n*(5*phi1-4*phi2-1*phi3)> 
11440  // 39th bin: <3>_{6n|3n,3n} = three6n3n3n = <cos(n*(6*phi1-3*phi2-3*phi3)> T 
11441  // 40th bin: <3>_{6n|4n,2n} = three6n4n2n = <cos(n*(6*phi1-4*phi2-2*phi3)> T
11442  // 41st bin: <3>_{6n|5n,1n} = three6n5n1n = <cos(n*(6*phi1-5*phi2-1*phi3)>
11443  // 42nd bin: <4>_{6n|3n,2n,1n} = four6n3n2n1n = <cos(n*(6*phi1-3*phi2-2*phi3-1*phi4)>
11444  // 43rd bin: <4>_{3n,2n|3n,2n} = four3n2n3n2n = <cos(n*(3*phi1+2*phi2-3*phi3-2*phi4)>
11445  // 44th bin: <4>_{4n,1n|3n,2n} = four4n1n3n2n = <cos(n*(4*phi1+1*phi2-3*phi3-2*phi4)>
11446  // 45th bin: <4>_{3n,3n|3n,3n} = four3n3n3n3n = <cos(3.*n*(phi1+phi2-phi3-phi4))> T
11447  // 46th bin: <4>_{4n,2n|3n,3n} = four4n2n3n3n = <cos(n*(4*phi1+2*phi2-3*phi3-3*phi4)>
11448  // 47th bin: <4>_{5n,1n|3n,3n} = four5n1n3n3n = <cos(n*(5*phi1+1*phi2-3*phi3-3*phi4)>
11449  // 48th bin: <4>_{4n,2n|4n,2n} = four4n2n4n2n = <cos(n*(4*phi1+2*phi2-4*phi3-2*phi4)> T
11450  // 49th bin: <4>_{5n,1n|4n,2n} = four5n1n4n2n = <cos(n*(5*phi1+1*phi2-4*phi3-2*phi4)>
11451  // 50th bin: <4>_{5n|3n,1n,1n} = four5n3n1n1n = <cos(n*(5*phi1-3*phi2-1*phi3-1*phi4)>
11452  // 51st bin: <4>_{5n|2n,2n,1n} = four5n2n2n1n = <cos(n*(5*phi1-2*phi2-2*phi3-1*phi4)>
11453  // 52nd bin: <4>_{5n,1n|5n,1n} = four5n1n5n1n = <cos(n*(5*phi1+1*phi2-5*phi3-1*phi4)>
11454  // 53rd bin: <5>_{3n,3n|3n,2n,1n} = four3n3n3n2n1n = <cos(n*(3*phi1+3*phi2-3*phi3-2*phi4-1*phi5)>
11455  // 54th bin: <5>_{4n,2n|3n,2n,1n} = four4n2n3n2n1n = <cos(n*(4*phi1+2*phi2-3*phi3-2*phi4-1*phi5)>
11456  // 55th bin: <5>_{3n,2n|3n,1n,1n} = four3n2n3n1n1n = <cos(n*(3*phi1+2*phi2-3*phi3-1*phi4-1*phi5)>
11457  // 56th bin: <5>_{3n,2n|2n,2n,1n} = four3n2n2n2n1n = <cos(n*(3*phi1+2*phi2-2*phi3-2*phi4-1*phi5)>
11458  // 57th bin: <5>_{5n,1n|3n,2n,1n} = four5n1n3n2n1n = <cos(n*(5*phi1+1*phi2-3*phi3-2*phi4-1*phi5)>
11459  // 58th bin: <6>_{3n,2n,1n|3n,2n,1n} = six3n2n1n3n2n1n = <cos(n*(3*phi1+2*phi2+1*phi3-3*phi4-2*phi5-1*phi6)>
11460   
11461  Int_t nPrim = anEvent->NumberOfTracks(); 
11462  AliFlowTrackSimple *aftsTrack = NULL; 
11463  Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.; 
11464  Int_t n = fHarmonic; 
11465  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
11466  Double_t dMult = (*fSpk)(0,0);
11467  cout<<endl;
11468  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
11469  if(dMult<2)
11470  {
11471   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
11472  } else if (dMult>fMaxAllowedMultiplicity)
11473    {
11474     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
11475    } else 
11476      { 
11477       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
11478      } 
11479  
11480  // 2-particle correlations:       
11481  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
11482  {
11483   for(Int_t i1=0;i1<nPrim;i1++)
11484   {
11485    aftsTrack=anEvent->GetTrack(i1);
11486    if(!(aftsTrack->InRPSelection())) continue;
11487    phi1=aftsTrack->Phi(); 
11488    for(Int_t i2=0;i2<nPrim;i2++)
11489    {
11490     if(i2==i1)continue;
11491     aftsTrack=anEvent->GetTrack(i2);
11492     if(!(aftsTrack->InRPSelection())) continue;
11493     phi2=aftsTrack->Phi();
11494     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
11495     // fill the profile with 2-p correlations: 
11496     fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),1.);     // <cos(n*(phi1-phi2))>
11497     fIntFlowDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),1.);  // <cos(2n*(phi1-phi2))>
11498     fIntFlowDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),1.);  // <cos(3n*(phi1-phi2))>
11499     fIntFlowDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),1.);  // <cos(4n*(phi1-phi2))>   
11500     fIntFlowDirectCorrelations->Fill(34.5,cos(5.*n*(phi1-phi2)),1.); // <cos(5n*(phi1-phi2))>
11501     fIntFlowDirectCorrelations->Fill(35.5,cos(6.*n*(phi1-phi2)),1.); // <cos(6n*(phi1-phi2))>   
11502    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11503   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11504  } // end of if(nPrim>=2)
11505  
11506  // 3-particle correlations:         
11507  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
11508  {
11509   for(Int_t i1=0;i1<nPrim;i1++)
11510   {
11511    aftsTrack=anEvent->GetTrack(i1);
11512    if(!(aftsTrack->InRPSelection())) continue;
11513    phi1=aftsTrack->Phi();
11514    for(Int_t i2=0;i2<nPrim;i2++)
11515    {
11516     if(i2==i1)continue;
11517     aftsTrack=anEvent->GetTrack(i2);
11518     if(!(aftsTrack->InRPSelection())) continue;
11519     phi2=aftsTrack->Phi();
11520     for(Int_t i3=0;i3<nPrim;i3++)
11521     {
11522      if(i3==i1||i3==i2)continue;
11523      aftsTrack=anEvent->GetTrack(i3);
11524      if(!(aftsTrack->InRPSelection())) continue;
11525      phi3=aftsTrack->Phi();
11526      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
11527      // fill the profile with 3-p correlations:   
11528      fIntFlowDirectCorrelations->Fill(5.,cos(2.*n*phi1-n*(phi2+phi3)),1.);         //<3>_{2n|nn,n}
11529      fIntFlowDirectCorrelations->Fill(6.,cos(3.*n*phi1-2.*n*phi2-n*phi3),1.);      //<3>_{3n|2n,n}
11530      fIntFlowDirectCorrelations->Fill(7.,cos(4.*n*phi1-2.*n*phi2-2.*n*phi3),1.);   //<3>_{4n|2n,2n}
11531      fIntFlowDirectCorrelations->Fill(8.,cos(4.*n*phi1-3.*n*phi2-n*phi3),1.);      //<3>_{4n|3n,n}
11532      fIntFlowDirectCorrelations->Fill(36.5,cos(5.*n*phi1-3.*n*phi2-2.*n*phi3),1.); //<3>_{5n|3n,2n}
11533      fIntFlowDirectCorrelations->Fill(37.5,cos(5.*n*phi1-4.*n*phi2-1.*n*phi3),1.); //<3>_{5n|4n,1n}
11534      fIntFlowDirectCorrelations->Fill(38.5,cos(6.*n*phi1-3.*n*phi2-3.*n*phi3),1.); //<3>_{6n|3n,3n}
11535      fIntFlowDirectCorrelations->Fill(39.5,cos(6.*n*phi1-4.*n*phi2-2.*n*phi3),1.); //<3>_{6n|4n,2n}     
11536      fIntFlowDirectCorrelations->Fill(40.5,cos(6.*n*phi1-5.*n*phi2-1.*n*phi3),1.); //<3>_{6n|5n,1n}
11537     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11538    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11539   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11540  } // end of if(nPrim>=3)
11541
11542  // 4-particle correlations:
11543  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
11544  {       
11545   for(Int_t i1=0;i1<nPrim;i1++)
11546   { 
11547    aftsTrack=anEvent->GetTrack(i1);
11548    if(!(aftsTrack->InRPSelection())) continue;
11549    phi1=aftsTrack->Phi();
11550    for(Int_t i2=0;i2<nPrim;i2++)
11551    {
11552     if(i2==i1)continue;
11553     aftsTrack=anEvent->GetTrack(i2);
11554     if(!(aftsTrack->InRPSelection())) continue;
11555     phi2=aftsTrack->Phi();
11556     for(Int_t i3=0;i3<nPrim;i3++)
11557     {
11558      if(i3==i1||i3==i2)continue;
11559      aftsTrack=anEvent->GetTrack(i3);
11560      if(!(aftsTrack->InRPSelection())) continue;
11561      phi3=aftsTrack->Phi();
11562      for(Int_t i4=0;i4<nPrim;i4++)
11563      {
11564       if(i4==i1||i4==i2||i4==i3)continue;
11565       aftsTrack=anEvent->GetTrack(i4);
11566       if(!(aftsTrack->InRPSelection())) continue;
11567       phi4=aftsTrack->Phi();
11568       if(nPrim==4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush;
11569       // fill the profile with 4-p correlations:   
11570       fIntFlowDirectCorrelations->Fill(10.,cos(n*phi1+n*phi2-n*phi3-n*phi4),1.);            // <4>_{n,n|n,n} 
11571       fIntFlowDirectCorrelations->Fill(11.,cos(2.*n*phi1+n*phi2-2.*n*phi3-n*phi4),1.);      // <4>_{2n,n|2n,n}
11572       fIntFlowDirectCorrelations->Fill(12.,cos(2.*n*phi1+2*n*phi2-2.*n*phi3-2.*n*phi4),1.); // <4>_{2n,2n|2n,2n}
11573       fIntFlowDirectCorrelations->Fill(13.,cos(3.*n*phi1-n*phi2-n*phi3-n*phi4),1.);         // <4>_{3n|n,n,n}
11574       fIntFlowDirectCorrelations->Fill(14.,cos(3.*n*phi1+n*phi2-3.*n*phi3-n*phi4),1.);      // <4>_{3n,n|3n,n}   
11575       fIntFlowDirectCorrelations->Fill(15.,cos(3.*n*phi1+n*phi2-2.*n*phi3-2.*n*phi4),1.);   // <4>_{3n,n|2n,2n}
11576       fIntFlowDirectCorrelations->Fill(16.,cos(4.*n*phi1-2.*n*phi2-n*phi3-n*phi4),1.);      // <4>_{4n|2n,n,n}     
11577       fIntFlowDirectCorrelations->Fill(32.,cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{4n,2n|3n,3n}        
11578       fIntFlowDirectCorrelations->Fill(41.5,cos(n*(6.*phi1-3.*phi2-2.*phi3-1.*phi4)),1.);    // <4>_{6n|3n,2n,1n}  
11579       fIntFlowDirectCorrelations->Fill(42.5,cos(n*(3.*phi1+2.*phi2-3.*phi3-2.*phi4)),1.);    // <4>_{3n,2n|3n,2n}  
11580       fIntFlowDirectCorrelations->Fill(43.5,cos(n*(4.*phi1+1.*phi2-3.*phi3-2.*phi4)),1.);    // <4>_{4n,1n|3n,2n}  
11581       fIntFlowDirectCorrelations->Fill(44.5,cos(n*(3.*phi1+3.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{3n,3n|3n,3n}  
11582       fIntFlowDirectCorrelations->Fill(45.5,cos(n*(4.*phi1+2.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{4n,2n|3n,3n}  
11583       fIntFlowDirectCorrelations->Fill(46.5,cos(n*(5.*phi1+1.*phi2-3.*phi3-3.*phi4)),1.);    // <4>_{5n,1n|3n,3n}  
11584       fIntFlowDirectCorrelations->Fill(47.5,cos(n*(4.*phi1+2.*phi2-4.*phi3-2.*phi4)),1.);    // <4>_{4n,2n|4n,2n}     
11585       fIntFlowDirectCorrelations->Fill(48.5,cos(n*(5.*phi1+1.*phi2-4.*phi3-2.*phi4)),1.);    // <4>_{5n,1n|4n,2n}  
11586       fIntFlowDirectCorrelations->Fill(49.5,cos(n*(5.*phi1-3.*phi2-1.*phi3-1.*phi4)),1.);    // <4>_{5n|3n,1n,1n}  
11587       fIntFlowDirectCorrelations->Fill(50.5,cos(n*(5.*phi1-2.*phi2-2.*phi3-1.*phi4)),1.);    // <4>_{5n|2n,2n,1n}  
11588       fIntFlowDirectCorrelations->Fill(51.5,cos(n*(5.*phi1+1.*phi2-5.*phi3-1.*phi4)),1.);    // <4>_{5n,1n|5n,1n}        
11589       fIntFlowDirectCorrelations->Fill(58.5,cos(n*(6.*phi1-4.*phi2-1.*phi3-1.*phi4)),1.);    // <4>_{6n|4n,1n,1n}  
11590       fIntFlowDirectCorrelations->Fill(59.5,cos(n*(6.*phi1-2.*phi2-2.*phi3-2.*phi4)),1.);    // <4>_{6n|2n,2n,2n}  
11591      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
11592     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11593    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11594   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11595  } // end of if(nPrim>=)
11596
11597  // 5-particle correlations:      
11598  if(nPrim>=5 && nPrim<=fMaxAllowedMultiplicity)
11599  {
11600   for(Int_t i1=0;i1<nPrim;i1++)
11601   {
11602    aftsTrack=anEvent->GetTrack(i1);
11603    if(!(aftsTrack->InRPSelection())) continue;  
11604    phi1=aftsTrack->Phi();
11605    for(Int_t i2=0;i2<nPrim;i2++)
11606    {
11607     if(i2==i1)continue;
11608     aftsTrack=anEvent->GetTrack(i2);
11609     if(!(aftsTrack->InRPSelection())) continue;
11610     phi2=aftsTrack->Phi();
11611     for(Int_t i3=0;i3<nPrim;i3++)
11612     {
11613      if(i3==i1||i3==i2)continue;
11614      aftsTrack=anEvent->GetTrack(i3);
11615      if(!(aftsTrack->InRPSelection())) continue;
11616      phi3=aftsTrack->Phi();
11617      for(Int_t i4=0;i4<nPrim;i4++)
11618      {
11619       if(i4==i1||i4==i2||i4==i3)continue;
11620       aftsTrack=anEvent->GetTrack(i4);
11621       if(!(aftsTrack->InRPSelection())) continue;
11622       phi4=aftsTrack->Phi();
11623       for(Int_t i5=0;i5<nPrim;i5++)
11624       {
11625        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11626        aftsTrack=anEvent->GetTrack(i5);
11627        if(!(aftsTrack->InRPSelection())) continue;
11628        phi5=aftsTrack->Phi();
11629        if(nPrim==5) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<"\r"<<flush;
11630        // fill the profile with 5-p correlations:   
11631        fIntFlowDirectCorrelations->Fill(18.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1.);              // <5>_{2n,n|n,n,n}
11632        fIntFlowDirectCorrelations->Fill(19.,cos(2.*n*phi1+2.*n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);        // <5>_{2n,2n|2n,n,n}
11633        fIntFlowDirectCorrelations->Fill(20.,cos(3.*n*phi1+n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);           // <5>_{3n,n|2n,n,n}
11634        fIntFlowDirectCorrelations->Fill(21.,cos(4.*n*phi1-n*phi2-n*phi3-n*phi4-n*phi5),1.);              // <5>_{4n|n,n,n,n}
11635        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}       
11636        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}      
11637        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}       
11638        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}
11639        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}
11640        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}              
11641        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}
11642        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}              
11643       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11644      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
11645     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11646    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11647   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11648  } // end of if(nPrim>=5)
11649   
11650  // 6-particle correlations:
11651  if(nPrim>=6 && nPrim<=fMaxAllowedMultiplicity)
11652  {
11653   for(Int_t i1=0;i1<nPrim;i1++)
11654   {
11655    aftsTrack=anEvent->GetTrack(i1);
11656    if(!(aftsTrack->InRPSelection())) continue;
11657    phi1=aftsTrack->Phi();
11658    for(Int_t i2=0;i2<nPrim;i2++)
11659    {
11660     if(i2==i1)continue;
11661     aftsTrack=anEvent->GetTrack(i2);
11662     if(!(aftsTrack->InRPSelection())) continue;
11663     phi2=aftsTrack->Phi();
11664     for(Int_t i3=0;i3<nPrim;i3++)
11665     {
11666      if(i3==i1||i3==i2)continue;
11667      aftsTrack=anEvent->GetTrack(i3);
11668      if(!(aftsTrack->InRPSelection())) continue;
11669      phi3=aftsTrack->Phi();
11670      for(Int_t i4=0;i4<nPrim;i4++)
11671      {
11672       if(i4==i1||i4==i2||i4==i3)continue;
11673       aftsTrack=anEvent->GetTrack(i4);
11674       if(!(aftsTrack->InRPSelection())) continue;
11675       phi4=aftsTrack->Phi();
11676       for(Int_t i5=0;i5<nPrim;i5++)
11677       {
11678        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11679        aftsTrack=anEvent->GetTrack(i5);
11680        if(!(aftsTrack->InRPSelection())) continue;
11681        phi5=aftsTrack->Phi();
11682        for(Int_t i6=0;i6<nPrim;i6++)
11683        {
11684         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
11685         aftsTrack=anEvent->GetTrack(i6);
11686         if(!(aftsTrack->InRPSelection())) continue;
11687         phi6=aftsTrack->Phi(); 
11688         if(nPrim==6) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<"\r"<<flush;
11689         // fill the profile with 6-p correlations:   
11690         fIntFlowDirectCorrelations->Fill(23.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),1.);                    // <6>_{1n,1n,1n|1n,1n,1n}
11691         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}
11692         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}
11693         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}  
11694         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}  
11695         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}  
11696        } // end of for(Int_t i6=0;i6<nPrim;i6++)
11697       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11698      } // end of for(Int_t i4=0;i4<nPrim;i4++)
11699     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11700    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11701   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11702  } // end of if(nPrim>=6)
11703   
11704  // 7-particle correlations:
11705  if(nPrim>=7 && nPrim<=fMaxAllowedMultiplicity)
11706  {
11707   for(Int_t i1=0;i1<nPrim;i1++)
11708   { 
11709    aftsTrack=anEvent->GetTrack(i1);
11710    if(!(aftsTrack->InRPSelection())) continue;
11711    phi1=aftsTrack->Phi();
11712    for(Int_t i2=0;i2<nPrim;i2++)
11713    {
11714     if(i2==i1)continue;
11715     aftsTrack=anEvent->GetTrack(i2);
11716     if(!(aftsTrack->InRPSelection())) continue;
11717     phi2=aftsTrack->Phi();
11718     for(Int_t i3=0;i3<nPrim;i3++)
11719     {
11720      if(i3==i1||i3==i2)continue;
11721      aftsTrack=anEvent->GetTrack(i3);
11722      if(!(aftsTrack->InRPSelection())) continue;
11723      phi3=aftsTrack->Phi();
11724      for(Int_t i4=0;i4<nPrim;i4++)
11725      {
11726       if(i4==i1||i4==i2||i4==i3)continue;
11727       aftsTrack=anEvent->GetTrack(i4);
11728       if(!(aftsTrack->InRPSelection())) continue;
11729       phi4=aftsTrack->Phi();
11730       for(Int_t i5=0;i5<nPrim;i5++)
11731       {
11732        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11733        aftsTrack=anEvent->GetTrack(i5);
11734        if(!(aftsTrack->InRPSelection())) continue;
11735        phi5=aftsTrack->Phi();
11736        for(Int_t i6=0;i6<nPrim;i6++)
11737        {
11738         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
11739         aftsTrack=anEvent->GetTrack(i6);
11740         if(!(aftsTrack->InRPSelection())) continue;
11741         phi6=aftsTrack->Phi(); 
11742         for(Int_t i7=0;i7<nPrim;i7++)
11743         {
11744          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
11745          aftsTrack=anEvent->GetTrack(i7);
11746          if(!(aftsTrack->InRPSelection())) continue;
11747          phi7=aftsTrack->Phi(); 
11748          if(nPrim==7) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<"\r"<<flush;
11749          // fill the profile with 7-p correlation:   
11750          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}
11751         } // end of for(Int_t i7=0;i7<nPrim;i7++)
11752        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
11753       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11754      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
11755     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11756    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11757   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11758  } // end of if(nPrim>=7)
11759  
11760  // 8-particle correlations:
11761  if(nPrim>=8 && nPrim<=fMaxAllowedMultiplicity)
11762  {
11763   for(Int_t i1=0;i1<nPrim;i1++)
11764   {
11765    aftsTrack=anEvent->GetTrack(i1);
11766    if(!(aftsTrack->InRPSelection())) continue;
11767    phi1=aftsTrack->Phi();
11768    for(Int_t i2=0;i2<nPrim;i2++)
11769    {
11770     if(i2==i1)continue;
11771     aftsTrack=anEvent->GetTrack(i2);
11772     if(!(aftsTrack->InRPSelection())) continue;
11773     phi2=aftsTrack->Phi();
11774     for(Int_t i3=0;i3<nPrim;i3++)
11775     {
11776      if(i3==i1||i3==i2)continue;
11777      aftsTrack=anEvent->GetTrack(i3);
11778      if(!(aftsTrack->InRPSelection())) continue;
11779      phi3=aftsTrack->Phi();
11780      for(Int_t i4=0;i4<nPrim;i4++)
11781      {
11782       if(i4==i1||i4==i2||i4==i3)continue;
11783       aftsTrack=anEvent->GetTrack(i4);
11784       if(!(aftsTrack->InRPSelection())) continue;
11785       phi4=aftsTrack->Phi();
11786       for(Int_t i5=0;i5<nPrim;i5++)
11787       {
11788        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
11789        aftsTrack=anEvent->GetTrack(i5);
11790        if(!(aftsTrack->InRPSelection())) continue;
11791        phi5=aftsTrack->Phi();
11792        for(Int_t i6=0;i6<nPrim;i6++)
11793        {
11794         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
11795         aftsTrack=anEvent->GetTrack(i6);
11796         if(!(aftsTrack->InRPSelection())) continue;
11797         phi6=aftsTrack->Phi();
11798         for(Int_t i7=0;i7<nPrim;i7++)
11799         {
11800          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
11801          aftsTrack=anEvent->GetTrack(i7);
11802          if(!(aftsTrack->InRPSelection())) continue;
11803          phi7=aftsTrack->Phi();
11804          for(Int_t i8=0;i8<nPrim;i8++)
11805          {
11806           if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
11807           aftsTrack=anEvent->GetTrack(i8);
11808           if(!(aftsTrack->InRPSelection())) continue;
11809           phi8=aftsTrack->Phi();
11810           cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<" "<<i8<<"\r"<<flush;
11811           // fill the profile with 8-p correlation:   
11812           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}
11813          } // end of for(Int_t i8=0;i8<nPrim;i8++)
11814         } // end of for(Int_t i7=0;i7<nPrim;i7++) 
11815        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
11816       } // end of for(Int_t i5=0;i5<nPrim;i5++)
11817      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
11818     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11819    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11820   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11821  } // end of if(nPrim>=8)
11822  
11823  cout<<endl;
11824
11825 } // end of AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent)
11826
11827
11828 //==================================================================================================================================
11829
11830
11831 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
11832 {
11833  // Cross-check results for multiparticle correlations needed for int. flow: results from Q-vectors vs results from nested loops.
11834
11835  cout<<endl;
11836  cout<<endl;
11837  cout<<"   *****************************************"<<endl;
11838  cout<<"   **** cross-checking the correlations ****"<<endl;
11839  cout<<"   ****       for integrated flow       ****"<<endl;
11840  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
11841  {
11842   cout<<"   ****   (particle weights not used)   ****"<<endl;
11843  } else
11844    {
11845     cout<<"   ****     (particle weights used)     ****"<<endl;
11846    } 
11847  cout<<"   *****************************************"<<endl;
11848  cout<<endl;
11849  cout<<endl;
11850
11851  Int_t ciMax = 64; // to be improved (removed eventually when I calculate 6th and 8th order with particle weights)
11852  
11853  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights)
11854  {
11855   ciMax = 11;
11856  }
11857
11858  for(Int_t ci=1;ci<=ciMax;ci++)
11859  {
11860   if(strcmp((fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
11861   cout<<(fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
11862   cout<<"from Q-vectors    = "<<fIntFlowCorrelationsAllPro->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
11863   cout<<"from nested loops = "<<fIntFlowDirectCorrelations->GetBinContent(ci)<<endl;
11864   cout<<endl;
11865  }
11866   
11867 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
11868
11869 //================================================================================================================================
11870
11871 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA()
11872 {
11873  // Cross-check results for corrections terms for non-uniform acceptance needed for int. flow: results from Q-vectors vs results from nested loops.
11874
11875  cout<<endl;
11876  cout<<endl;
11877  cout<<"   *********************************************"<<endl;
11878  cout<<"   **** cross-checking the correction terms ****"<<endl;
11879  cout<<"   **** for non-uniform acceptance relevant ****"<<endl;
11880  cout<<"   ****         for integrated flow         ****"<<endl;
11881  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
11882  {
11883   cout<<"   ****     (particle weights not used)     ****"<<endl;
11884  } else
11885    {
11886     cout<<"   ****       (particle weights used)       ****"<<endl;
11887    } 
11888  cout<<"   *********************************************"<<endl;
11889  cout<<endl;
11890  cout<<endl;
11891
11892  for(Int_t ci=1;ci<=4;ci++) // correction term index (to be improved - hardwired 4)
11893  {
11894   for(Int_t sc=0;sc<2;sc++) // sin or cos term
11895   {
11896    if(strcmp((fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
11897    cout<<(fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
11898    cout<<"from Q-vectors    = "<<fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
11899    cout<<"from nested loops = "<<fIntFlowDirectCorrectionTermsForNUA[sc]->GetBinContent(ci)<<endl;
11900    cout<<endl;
11901   } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos term
11902  } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
11903   
11904 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA() 
11905
11906 //================================================================================================================================
11907
11908 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
11909 {
11910  // Evaluate with nested loops multiparticle correlations for integrated flow (using the particle weights). 
11911
11912  // Results are stored in profile fIntFlowDirectCorrelations. 
11913  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrelations is organized as follows:
11914  //
11915  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
11916  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
11917  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
11918  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
11919  //  5th bin:           ----  EMPTY ----
11920  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
11921  //  7th bin: <3>_{3n|2n,1n} = ...
11922  //  8th bin: <3>_{4n|2n,2n} = ...
11923  //  9th bin: <3>_{4n|3n,1n} = ...
11924  // 10th bin:           ----  EMPTY ----
11925  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
11926  // 12th bin: <4>_{2n,1n|2n,1n} = ...
11927  // 13th bin: <4>_{2n,2n|2n,2n} = ...
11928  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
11929  // 15th bin: <4>_{3n,1n|3n,1n} = ...
11930  // 16th bin: <4>_{3n,1n|2n,2n} = ...
11931  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
11932  // 18th bin:           ----  EMPTY ----
11933  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
11934  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
11935  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
11936  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
11937  // 23rd bin:           ----  EMPTY ----
11938  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
11939  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
11940  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
11941  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
11942  // 28th bin:           ----  EMPTY ----
11943  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
11944  // 30th bin:           ----  EMPTY ----
11945  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
11946  
11947  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
11948  // fIntFlowExtraDirectCorrelations binning of which is organized as follows:
11949  
11950  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
11951  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
11952  // ...
11953  
11954  Int_t nPrim = anEvent->NumberOfTracks(); 
11955  AliFlowTrackSimple *aftsTrack = NULL;
11956  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
11957  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
11958  Double_t phi1=0., phi2=0., phi3=0., phi4=0.;
11959  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1.;
11960  Int_t n = fHarmonic; 
11961  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
11962  Double_t dMult = (*fSpk)(0,0);
11963  cout<<endl;
11964  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
11965  if(dMult<2)
11966  {
11967   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
11968  } else if (dMult>fMaxAllowedMultiplicity)
11969    {
11970     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
11971    } else 
11972      { 
11973       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
11974      } 
11975       
11976  // 2-particle correlations:       
11977  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
11978  {
11979   // 2 nested loops multiparticle correlations using particle weights:       
11980   for(Int_t i1=0;i1<nPrim;i1++)
11981   {
11982    aftsTrack=anEvent->GetTrack(i1);
11983    if(!(aftsTrack->InRPSelection())) continue;
11984    phi1=aftsTrack->Phi();
11985    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11986    for(Int_t i2=0;i2<nPrim;i2++)
11987    {
11988     if(i2==i1)continue;
11989     aftsTrack=anEvent->GetTrack(i2);
11990     if(!(aftsTrack->InRPSelection())) continue;
11991     phi2=aftsTrack->Phi();
11992     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
11993     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
11994     // 2-p correlations using particle weights:
11995     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),wPhi1*wPhi2);                  // <w1   w2   cos( n*(phi1-phi2))>
11996     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))>
11997     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))>
11998     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))> 
11999     // extra correlations: 
12000     // 2-p extra correlations (do not appear if particle weights are not used):
12001     if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),pow(wPhi1,3)*wPhi2); // <w1^3 w2 cos(n*(phi1-phi2))>
12002     // ...
12003    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12004   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12005  } // end of if(nPrim>=2)
12006
12007  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
12008  { 
12009   // 3 nested loops multiparticle correlations using particle weights:       
12010   for(Int_t i1=0;i1<nPrim;i1++)
12011   {
12012    aftsTrack=anEvent->GetTrack(i1);
12013    if(!(aftsTrack->InRPSelection())) continue;
12014    phi1=aftsTrack->Phi();
12015    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12016    for(Int_t i2=0;i2<nPrim;i2++)
12017    {
12018     if(i2==i1)continue;
12019     aftsTrack=anEvent->GetTrack(i2);
12020     if(!(aftsTrack->InRPSelection())) continue;
12021     phi2=aftsTrack->Phi();
12022     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12023     for(Int_t i3=0;i3<nPrim;i3++)
12024     {
12025      if(i3==i1||i3==i2)continue;
12026      aftsTrack=anEvent->GetTrack(i3);
12027      if(!(aftsTrack->InRPSelection())) continue;
12028      phi3=aftsTrack->Phi();
12029      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12030      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
12031      // 3-p correlations using particle weights:
12032      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))>
12033      // ...
12034      // extra correlations: 
12035      // 2-p extra correlations (do not appear if particle weights are not used):
12036       if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(1.5,cos(n*(phi1-phi2)),wPhi1*wPhi2*pow(wPhi3,2)); // <w1 w2 w3^2 cos(n*(phi1-phi2))>
12037      // ...
12038      // 3-p extra correlations (do not appear if particle weights are not used):
12039      // ...
12040     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12041    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12042   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12043  } // end of if(nPrim>=3)
12044  
12045  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
12046  {
12047   // 4 nested loops multiparticle correlations using particle weights:       
12048   for(Int_t i1=0;i1<nPrim;i1++)
12049   {
12050    aftsTrack=anEvent->GetTrack(i1);
12051    if(!(aftsTrack->InRPSelection())) continue;
12052    phi1=aftsTrack->Phi();
12053    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
12054    for(Int_t i2=0;i2<nPrim;i2++)
12055    {
12056     if(i2==i1)continue;
12057     aftsTrack=anEvent->GetTrack(i2);
12058     if(!(aftsTrack->InRPSelection())) continue;
12059     phi2=aftsTrack->Phi();
12060     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12061     for(Int_t i3=0;i3<nPrim;i3++)
12062     {
12063      if(i3==i1||i3==i2)continue;
12064      aftsTrack=anEvent->GetTrack(i3);
12065      if(!(aftsTrack->InRPSelection())) continue;
12066      phi3=aftsTrack->Phi();
12067      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12068      for(Int_t i4=0;i4<nPrim;i4++)
12069      {
12070       if(i4==i1||i4==i2||i4==i3)continue;
12071       aftsTrack=anEvent->GetTrack(i4);
12072       if(!(aftsTrack->InRPSelection())) continue;
12073       phi4=aftsTrack->Phi();
12074       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
12075       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
12076       // 4-p correlations using particle weights:
12077       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
12078       // extra correlations: 
12079       // 2-p extra correlations (do not appear if particle weights are not used):
12080       // ...
12081       // 3-p extra correlations (do not appear if particle weights are not used):
12082       // ...
12083       // 4-p extra correlations (do not appear if particle weights are not used):
12084       // ...
12085      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
12086     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12087    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12088   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12089  } // end of if(nPrim>=4)
12090
12091  cout<<endl; 
12092
12093 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
12094
12095 //================================================================================================================================
12096
12097 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
12098 {
12099  // Cross-check results for extra multiparticle correlations needed for int. flow 
12100  // which appear only when particle weights are used: results from Q-vectors vs results from nested loops.
12101
12102  cout<<endl;
12103  cout<<endl;
12104  cout<<"   ***********************************************"<<endl;
12105  cout<<"   **** cross-checking the extra correlations ****"<<endl;
12106  cout<<"   ****          for integrated flow          ****"<<endl;
12107  cout<<"   ***********************************************"<<endl;
12108  cout<<endl;
12109  cout<<endl;
12110  
12111  for(Int_t eci=1;eci<=2;eci++) // to be improved (increased eciMax eventually when I calculate 6th and 8th)
12112  {
12113   if(strcmp((fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci), "") == 0) continue;
12114   cout<<(fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci)<<":"<<endl;
12115   cout<<"from Q-vectors    = "<<fIntFlowExtraCorrelationsPro->GetBinContent(eci)<<endl;
12116   cout<<"from nested loops = "<<fIntFlowExtraDirectCorrelations->GetBinContent(eci)<<endl;
12117   cout<<endl;
12118  }
12119
12120 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
12121
12122 //================================================================================================================================
12123
12124 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent)
12125 {
12126  // Evaluate with nested loops correction terms for non-uniform acceptance relevant for NONAME integrated flow (to be improved (name)).
12127  //
12128  // Remark: Both sin and cos correction terms are calculated in this method. Sin terms are stored in fIntFlowDirectCorrectionTermsForNUA[0],
12129  // and cos terms in fIntFlowDirectCorrectionTermsForNUA[1]. Binning of fIntFlowDirectCorrectionTermsForNUA[sc] is organized as follows 
12130  // (sc stands for either sin or cos):
12131  
12132  //  1st bin: <<sc(n*(phi1))>> 
12133  //  2nd bin: <<sc(n*(phi1+phi2))>> 
12134  //  3rd bin: <<sc(n*(phi1-phi2-phi3))>>
12135  //  4th bin: <<sc(n*(2phi1-phi2))>>
12136  
12137  Int_t nPrim = anEvent->NumberOfTracks(); 
12138  AliFlowTrackSimple *aftsTrack = NULL;
12139  Double_t phi1=0., phi2=0., phi3=0.;
12140  Int_t n = fHarmonic; 
12141  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
12142  Double_t dMult = (*fSpk)(0,0);
12143  cout<<endl;
12144  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
12145  if(dMult<1)
12146  {
12147   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
12148  } else if (dMult>fMaxAllowedMultiplicity)
12149    {
12150     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
12151    } else 
12152      { 
12153       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
12154      }
12155  
12156  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
12157  {
12158   // 1-particle correction terms for non-uniform acceptance:       
12159   for(Int_t i1=0;i1<nPrim;i1++)
12160   {
12161    aftsTrack=anEvent->GetTrack(i1);
12162    if(!(aftsTrack->InRPSelection())) continue;
12163    phi1=aftsTrack->Phi();
12164    if(nPrim==1) cout<<i1<<"\r"<<flush;
12165    // sin terms:
12166    fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),1.); // <sin(n*phi1)>  
12167    // cos terms:
12168    fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),1.); // <cos(n*phi1)>
12169   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12170  } // end of if(nPrim>=1) 
12171   
12172  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
12173  {
12174   // 2-particle correction terms for non-uniform acceptance:       
12175   for(Int_t i1=0;i1<nPrim;i1++)
12176   {
12177    aftsTrack=anEvent->GetTrack(i1);
12178    if(!(aftsTrack->InRPSelection())) continue;
12179    phi1=aftsTrack->Phi();  
12180    for(Int_t i2=0;i2<nPrim;i2++)
12181    {
12182     if(i2==i1)continue;
12183     aftsTrack=anEvent->GetTrack(i2);
12184     if(!(aftsTrack->InRPSelection())) continue;
12185     phi2=aftsTrack->Phi();
12186     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
12187     // sin terms:
12188     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),1.); // <<sin(n*(phi1+phi2))>>
12189     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(3.5,sin(n*(2*phi1-phi2)),1.); // <<sin(n*(2*phi1-phi2))>>
12190     // cos terms:
12191     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),1.); // <<cos(n*(phi1+phi2))>>
12192     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(3.5,cos(n*(2*phi1-phi2)),1.); // <<cos(n*(2*phi1-phi2))>>
12193    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12194   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12195  } // end of if(nPrim>=2)
12196
12197  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
12198  {
12199   // 3-particle correction terms for non-uniform acceptance:       
12200   for(Int_t i1=0;i1<nPrim;i1++)
12201   {
12202    aftsTrack=anEvent->GetTrack(i1);
12203    if(!(aftsTrack->InRPSelection())) continue;
12204    phi1=aftsTrack->Phi();
12205    for(Int_t i2=0;i2<nPrim;i2++)
12206    {
12207     if(i2==i1)continue;
12208     aftsTrack=anEvent->GetTrack(i2);
12209     if(!(aftsTrack->InRPSelection())) continue;
12210     phi2=aftsTrack->Phi();
12211     for(Int_t i3=0;i3<nPrim;i3++)
12212     {
12213      if(i3==i1||i3==i2)continue;
12214      aftsTrack=anEvent->GetTrack(i3);
12215      if(!(aftsTrack->InRPSelection())) continue;
12216      phi3=aftsTrack->Phi();
12217      if(nPrim>=3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush; // to be improved (eventually I will change this if statement)
12218      // sin terms:
12219      fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),1.); // <<sin(n*(phi1-phi2-phi3))>>
12220      // cos terms:
12221      fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),1.); // <<cos(n*(phi1-phi2-phi3))>>
12222     } // end of for(Int_t i3=0;i3<nPrim;i3++)
12223    } // end of for(Int_t i2=0;i2<nPrim;i2++)
12224   } // end of for(Int_t i1=0;i1<nPrim;i1++)
12225  } // end of if(nPrim>=3)
12226
12227  cout<<endl;
12228 }
12229
12230 //================================================================================================================================
12231
12232 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12233 {
12234  // Evaluate reduced correlations with nested loops without using the particle weights.
12235  
12236  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12237  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
12238  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
12239  // Remark 3: <2'> = <cos(n*(psi1-phi2))>
12240  //           <4'> = <cos(n*(psi1+phi2-phi3-phi4))>
12241  // ...
12242  
12243  Int_t typeFlag = 0;
12244  Int_t ptEtaFlag = 0;
12245  if(type == "RP")
12246  {
12247   typeFlag = 0;
12248  } else if(type == "POI")
12249    {
12250     typeFlag = 1;
12251    }      
12252  if(ptOrEta == "Pt")
12253  {
12254   ptEtaFlag = 0;
12255  } else if(ptOrEta == "Eta")
12256    {
12257     ptEtaFlag = 1;
12258    } 
12259  // shortcuts:
12260  Int_t t = typeFlag;
12261  Int_t pe = ptEtaFlag;
12262       
12263  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12264  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12265  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12266  
12267  Int_t nPrim = anEvent->NumberOfTracks(); 
12268  AliFlowTrackSimple *aftsTrack = NULL;
12269  
12270  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12271  
12272  Int_t n = fHarmonic; 
12273   
12274  // 2'-particle correlations:
12275  for(Int_t i1=0;i1<nPrim;i1++)
12276  {
12277   aftsTrack=anEvent->GetTrack(i1);
12278   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12279   if(typeFlag==1) // this is diff flow of POIs 
12280   {
12281    if(ptOrEta == "Pt")
12282    { 
12283     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12284    } else if (ptOrEta == "Eta")
12285      {
12286       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12287      }
12288   } else // this is diff flow of RPs 
12289     {
12290      if(ptOrEta == "Pt")
12291      { 
12292       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12293      } else if (ptOrEta == "Eta")
12294        {
12295         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12296        }
12297     }
12298        
12299   psi1=aftsTrack->Phi(); 
12300   for(Int_t i2=0;i2<nPrim;i2++)
12301   {
12302    if(i2==i1)continue;
12303    aftsTrack=anEvent->GetTrack(i2);
12304    // RP condition (!(first) particle in the correlator must be RP):
12305    if(!(aftsTrack->InRPSelection()))continue;
12306    phi2=aftsTrack->Phi();   
12307    // 2'-particle correlations: 
12308    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),1.); // <cos(n*(psi1-phi2))  
12309   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12310  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12311  
12312  /*
12313  
12314  // 3'-particle correlations:
12315  for(Int_t i1=0;i1<nPrim;i1++)
12316  {
12317   aftsTrack=anEvent->GetTrack(i1);
12318   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12319   if(ptOrEta == "Pt")
12320   { 
12321    if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12322   } else if (ptOrEta == "Eta")
12323     {
12324      if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12325     }
12326   psi1=aftsTrack->Phi();
12327   for(Int_t i2=0;i2<nPrim;i2++)
12328   {
12329    if(i2==i1)continue;
12330    aftsTrack=anEvent->GetTrack(i2);
12331    // RP condition (!(first) particle in the correlator must be RP):
12332    if(!(aftsTrack->InRPSelection())) continue;
12333    phi2=aftsTrack->Phi();
12334    for(Int_t i3=0;i3<nPrim;i3++)
12335    {
12336     if(i3==i1||i3==i2)continue;
12337     aftsTrack=anEvent->GetTrack(i3);
12338     // RP condition (!(first) particle in the correlator must be RP):
12339     if(!(aftsTrack->InRPSelection())) continue;
12340     phi3=aftsTrack->Phi();
12341     // 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))> 
12342    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
12343   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
12344  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12345  
12346  */
12347  
12348  // 4'-particle correlations:
12349  for(Int_t i1=0;i1<nPrim;i1++)
12350  {
12351   aftsTrack=anEvent->GetTrack(i1);
12352   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12353   if(typeFlag==1) // this is diff flow of POIs 
12354   {
12355    if(ptOrEta == "Pt")
12356    { 
12357     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12358    } else if (ptOrEta == "Eta")
12359      {
12360       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12361      }
12362   } else // this is diff flow of RPs 
12363     {
12364      if(ptOrEta == "Pt")
12365      { 
12366       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12367      } else if (ptOrEta == "Eta")
12368        {
12369         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12370        }
12371     }
12372     
12373   psi1=aftsTrack->Phi();
12374   for(Int_t i2=0;i2<nPrim;i2++)
12375   {
12376    if(i2==i1) continue;
12377    aftsTrack=anEvent->GetTrack(i2);
12378    // RP condition (!(first) particle in the correlator must be RP): 
12379    if(!(aftsTrack->InRPSelection())) continue;
12380    phi2=aftsTrack->Phi();
12381    for(Int_t i3=0;i3<nPrim;i3++)
12382    { 
12383     if(i3==i1||i3==i2) continue;
12384     aftsTrack=anEvent->GetTrack(i3);
12385     // RP condition (!(first) particle in the correlator must be RP):
12386     if(!(aftsTrack->InRPSelection())) continue;
12387     phi3=aftsTrack->Phi();
12388     for(Int_t i4=0;i4<nPrim;i4++)
12389     {
12390      if(i4==i1||i4==i2||i4==i3) continue;
12391      aftsTrack=anEvent->GetTrack(i4);
12392      // RP condition (!(first) particle in the correlator must be RP):
12393      if(!(aftsTrack->InRPSelection())) continue;  
12394      phi4=aftsTrack->Phi();
12395      // 4'-particle correlations:
12396      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),1.); // <cos(n(psi1+phi2-phi3-phi4))>     
12397     }//end of for(Int_t i4=0;i4<nPrim;i4++)
12398    }//end of for(Int_t i3=0;i3<nPrim;i3++)
12399   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
12400  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12401       
12402  // count # of RPs and POIs in selected pt and eta bins for cross-checkings:
12403  for(Int_t i=0;i<nPrim;i++)
12404  {
12405   aftsTrack=anEvent->GetTrack(i); 
12406   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12407   if(typeFlag==1) // this is diff flow of POIs 
12408   {
12409    if(ptOrEta == "Pt")
12410    { 
12411     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12412    } else if (ptOrEta == "Eta")
12413      {
12414       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12415      }
12416   } else // this is diff flow of RPs 
12417     {
12418      if(ptOrEta == "Pt")
12419      { 
12420       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12421      } else if (ptOrEta == "Eta")
12422        {
12423         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12424        }
12425     }
12426   if(t==1)t++; 
12427   fNoOfParticlesInBin->Fill(t+pe+0.5);  
12428  }
12429
12430 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12431
12432 //================================================================================================================================
12433
12434 void AliFlowAnalysisWithQCumulants::EvaluateOtherDiffCorrelatorsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12435 {
12436  // Evaluate other differential correlators with nested loops without using the particle weights.
12437
12438  // Remark 1: Other differential correlators are evaluated in pt bin number fCrossCheckInPtBinNo 
12439  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12440  // Remark 2: Results are stored in 1 bin profiles fOtherDirectDiffCorrelators[t][pe][sc][ci], where indices runs as follows:
12441  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms][ci = correlator index] 
12442  // Remark 3: Correlator index 'ci' runs as follows:
12443  //            0: <exp(n*(psi1-3phi2+2phi3))> (Teaney-Yan correlator)
12444   
12445  Int_t typeFlag = 0;
12446  Int_t ptEtaFlag = 0;
12447  if(type == "RP")
12448  {
12449   typeFlag = 0;
12450  } else if(type == "POI")
12451    {
12452     typeFlag = 1;
12453    }      
12454  if(ptOrEta == "Pt")
12455  {
12456   ptEtaFlag = 0;
12457  } else if(ptOrEta == "Eta")
12458    {
12459     ptEtaFlag = 1;
12460    } 
12461  // shortcuts:
12462  Int_t t = typeFlag;
12463  Int_t pe = ptEtaFlag;
12464       
12465  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12466  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12467  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12468  
12469  Int_t nPrim = anEvent->NumberOfTracks(); 
12470  AliFlowTrackSimple *aftsTrack = NULL;
12471  
12472  Double_t psi1=0., phi2=0., phi3=0.;
12473  
12474  Int_t n = fHarmonic; 
12475
12476  // 3-p correlators:
12477  for(Int_t i1=0;i1<nPrim;i1++)
12478  {
12479   aftsTrack=anEvent->GetTrack(i1);
12480   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12481   if(typeFlag==1) // this is diff flow of POIs 
12482   {
12483    if(ptOrEta == "Pt")
12484    { 
12485     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12486    } else if (ptOrEta == "Eta")
12487      {
12488       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12489      }
12490   } else // this is diff flow of RPs 
12491     {
12492      if(ptOrEta == "Pt")
12493      { 
12494       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12495      } else if (ptOrEta == "Eta")
12496        {
12497         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12498        }
12499     }
12500   psi1=aftsTrack->Phi();
12501   for(Int_t i2=0;i2<nPrim;i2++)
12502   {
12503    if(i2==i1) continue;
12504    aftsTrack=anEvent->GetTrack(i2);
12505    // RP condition (!(first) particle in the correlator must be RP): 
12506    if(!(aftsTrack->InRPSelection())) continue;
12507    phi2=aftsTrack->Phi();
12508    for(Int_t i3=0;i3<nPrim;i3++)
12509    { 
12510     if(i3==i1||i3==i2) continue;
12511     aftsTrack=anEvent->GetTrack(i3);
12512     // RP condition (!(first) particle in the correlator must be RP):
12513     if(!(aftsTrack->InRPSelection())) continue;
12514     phi3=aftsTrack->Phi();
12515     // Fill 3-p correlators:
12516     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))>     
12517    }//end of for(Int_t i3=0;i3<nPrim;i3++)
12518   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
12519  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
12520 } // end of void AliFlowAnalysisWithQCumulants::EvaluateOtherDiffCorrelatorsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12521
12522 //================================================================================================================================
12523
12524 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
12525 {
12526  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
12527  
12528  Int_t typeFlag = 0;
12529  Int_t ptEtaFlag = 0;
12530  if(type == "RP")
12531  {
12532   typeFlag = 0;
12533  } else if(type == "POI")
12534    {
12535     typeFlag = 1;
12536    }      
12537  if(ptOrEta == "Pt")
12538  {
12539   ptEtaFlag = 0;
12540  } else if(ptOrEta == "Eta")
12541    {
12542     ptEtaFlag = 1;
12543    } 
12544  // shortcuts:
12545  Int_t t = typeFlag;
12546  Int_t pe = ptEtaFlag;
12547       
12548  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12549  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12550  TString reducedCorrelations[4] = {"<<cos(n(psi1-phi2))>>","<<cos(n(psi1+phi2-phi3-phi4))>>","",""}; // to be improved (access this from pro or hist)
12551  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12552  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12553  
12554  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
12555  
12556
12557  cout<<endl;
12558  cout<<"   *****************************************"<<endl;
12559  cout<<"   **** cross-checking the correlations ****"<<endl;
12560  cout<<"   ****   for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
12561  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
12562  {
12563   cout<<"   ****   (particle weights not used)   ****"<<endl;
12564  } else
12565    {
12566     cout<<"   ****    (particle weights used)      ****"<<endl;
12567    } 
12568  cout<<"   *****************************************"<<endl; 
12569  cout<<endl;
12570  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
12571  cout<<endl;
12572  
12573  for(Int_t rci=0;rci<2;rci++) // to be improved (calculate 6th and 8th order)
12574  {
12575   cout<<"      "<<reducedCorrelations[rci].Data()<<":"<<endl;
12576   cout<<"      from Q-vectors    = "<<fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
12577   cout<<"      from nested loops = "<<fDiffFlowDirectCorrelations[t][pe][rci]->GetBinContent(1)<<endl;
12578   cout<<endl;  
12579  } // end of for(Int_t rci=0;rci<4;rci++)
12580         
12581 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
12582
12583 //================================================================================================================================
12584
12585 void AliFlowAnalysisWithQCumulants::CrossCheckOtherDiffCorrelators(TString type, TString ptOrEta)
12586 {
12587  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
12588  
12589  Int_t typeFlag = 0;
12590  Int_t ptEtaFlag = 0;
12591  if(type == "RP")
12592  {
12593   typeFlag = 0;
12594  } else if(type == "POI")
12595    {
12596     typeFlag = 1;
12597    }      
12598  if(ptOrEta == "Pt")
12599  {
12600   ptEtaFlag = 0;
12601  } else if(ptOrEta == "Eta")
12602    {
12603     ptEtaFlag = 1;
12604    } 
12605  // shortcuts:
12606  Int_t t = typeFlag;
12607  Int_t pe = ptEtaFlag;
12608       
12609  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12610  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
12611  TString otherCorrelators[1] = {"<<cos(n(psi1-3phi2+2phi3))>>"}; // to be improved (access this from pro or hist)
12612  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12613  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12614  
12615  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
12616
12617  cout<<endl;
12618  cout<<"   *****************************************"<<endl;
12619  cout<<"   ****   cross-checking the other      ****"<<endl;
12620  cout<<"   ****   diff. correlators ("<<rpORpoiString[t]<<")       ****"<<endl;
12621  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
12622  {
12623   cout<<"   ****   (particle weights not used)   ****"<<endl;
12624  } else
12625    {
12626     cout<<"   ****    (particle weights used)      ****"<<endl;
12627    } 
12628  cout<<"   *****************************************"<<endl; 
12629  cout<<endl;
12630  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
12631  cout<<endl;
12632  
12633  for(Int_t ci=0;ci<1;ci++) 
12634  {
12635   cout<<"      "<<otherCorrelators[ci].Data()<<":"<<endl;
12636   cout<<"      from Q-vectors    = "<<fOtherDiffCorrelators[t][pe][1][ci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
12637   cout<<"      from nested loops = "<<fOtherDirectDiffCorrelators[t][pe][1][ci]->GetBinContent(1)<<endl;
12638   cout<<endl;  
12639  } // end of for(Int_t ci=0;ci<1;ci++)
12640         
12641 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckOtherDiffCorrelators(TString type, TString ptOrEta)
12642
12643 //================================================================================================================================
12644
12645 void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
12646 {
12647  // Print on the screen number of RPs and POIs in selected pt and eta bin for cross checkings.
12648  
12649  cout<<endl;
12650  cout<<"Number of RPs in selected pt bin   = "<<fNoOfParticlesInBin->GetBinContent(1)<<endl;
12651  cout<<"Number of RPs in selected eta bin  = "<<fNoOfParticlesInBin->GetBinContent(2)<<endl;
12652  cout<<"Number of POIs in selected pt bin  = "<<fNoOfParticlesInBin->GetBinContent(3)<<endl;
12653  cout<<"Number of POIs in selected eta bin = "<<fNoOfParticlesInBin->GetBinContent(4)<<endl;
12654  
12655 } // end of void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
12656
12657 //================================================================================================================================
12658
12659 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12660 {
12661  // Evaluate reduced correlations with nested loops without using the particle weights.
12662  
12663  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12664  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
12665  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
12666  // Remark 3: <2'> = <w2 cos(n*(psi1-phi2))>
12667  //           <4'> = <w2 w3 w4 cos(n*(psi1+phi2-phi3-phi4))>
12668  // ...
12669   
12670  Int_t typeFlag = 0;
12671  Int_t ptEtaFlag = 0;
12672  if(type == "RP")
12673  {
12674   typeFlag = 0;
12675  } else if(type == "POI")
12676    {
12677     typeFlag = 1;
12678    }      
12679  if(ptOrEta == "Pt")
12680  {
12681   ptEtaFlag = 0;
12682  } else if(ptOrEta == "Eta")
12683    {
12684     ptEtaFlag = 1;
12685    } 
12686  // shortcuts:
12687  Int_t t = typeFlag;
12688  Int_t pe = ptEtaFlag;
12689       
12690  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12691  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12692  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12693  
12694  Int_t nPrim = anEvent->NumberOfTracks(); 
12695  AliFlowTrackSimple *aftsTrack = NULL;
12696  
12697  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12698  Double_t wPhi2=1., wPhi3=1., wPhi4=1.;// wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
12699  
12700  Int_t n = fHarmonic; 
12701  
12702  // 2'-particle correlations:
12703  for(Int_t i1=0;i1<nPrim;i1++)
12704  {
12705   aftsTrack=anEvent->GetTrack(i1);
12706   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12707   if(typeFlag==1) // this is diff flow of POIs 
12708   {
12709    if(ptOrEta == "Pt")
12710    { 
12711     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12712    } else if (ptOrEta == "Eta")
12713      {
12714       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12715      }
12716   } else // this is diff flow of RPs 
12717     {
12718      if(ptOrEta == "Pt")
12719      { 
12720       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12721      } else if (ptOrEta == "Eta")
12722        {
12723         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12724        }
12725     }
12726   psi1=aftsTrack->Phi(); 
12727   for(Int_t i2=0;i2<nPrim;i2++)
12728   {
12729    if(i2==i1) continue;
12730    aftsTrack=anEvent->GetTrack(i2);
12731    // RP condition (!(first) particle in the correlator must be RP):
12732    if(!(aftsTrack->InRPSelection())) continue;
12733    phi2=aftsTrack->Phi();   
12734    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12735    // 2'-particle correlations: 
12736    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),wPhi2); // <w2 cos(n*(psi1-phi2))  
12737   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12738  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12739  
12740  // 4'-particle correlations:
12741  for(Int_t i1=0;i1<nPrim;i1++)
12742  {
12743   aftsTrack=anEvent->GetTrack(i1);
12744   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12745   if(typeFlag==1) // this is diff flow of POIs 
12746   {
12747    if(ptOrEta == "Pt")
12748    { 
12749     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12750    } else if (ptOrEta == "Eta")
12751      {
12752       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12753      }
12754   } else // this is diff flow of RPs 
12755     {
12756      if(ptOrEta == "Pt")
12757      { 
12758       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12759      } else if (ptOrEta == "Eta")
12760        {
12761         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12762        }
12763     }
12764   psi1=aftsTrack->Phi();
12765   for(Int_t i2=0;i2<nPrim;i2++)
12766   {
12767    if(i2==i1) continue;
12768    aftsTrack=anEvent->GetTrack(i2);
12769    // RP condition (!(first) particle in the correlator must be RP): 
12770    if(!(aftsTrack->InRPSelection())) continue;
12771    phi2=aftsTrack->Phi();
12772    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
12773    for(Int_t i3=0;i3<nPrim;i3++)
12774    { 
12775     if(i3==i1||i3==i2) continue;
12776     aftsTrack=anEvent->GetTrack(i3);
12777     // RP condition (!(first) particle in the correlator must be RP):
12778     if(!(aftsTrack->InRPSelection())) continue;
12779     phi3=aftsTrack->Phi();
12780     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
12781     for(Int_t i4=0;i4<nPrim;i4++)
12782     {
12783      if(i4==i1||i4==i2||i4==i3) continue;
12784      aftsTrack=anEvent->GetTrack(i4);
12785      // RP condition (!(first) particle in the correlator must be RP):
12786      if(!(aftsTrack->InRPSelection())) continue;  
12787      phi4=aftsTrack->Phi();
12788      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
12789      // 4'-particle correlations <w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))>:
12790      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),wPhi2*wPhi3*wPhi4); 
12791     }//end of for(Int_t i4=0;i4<nPrim;i4++)
12792    }//end of for(Int_t i3=0;i3<nPrim;i3++)
12793   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
12794  }//end of for(Int_t i1=0;i1<nPrim;i1++)      
12795  
12796  // count # of RPs and POIs in selected pt and eta bins for cross-checkings: (to be improved - moved to dedicated method)
12797  for(Int_t i=0;i<nPrim;i++)
12798  {
12799   aftsTrack=anEvent->GetTrack(i); 
12800   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12801   if(typeFlag==1) // this is diff flow of POIs 
12802   {
12803    if(ptOrEta == "Pt")
12804    { 
12805     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12806    } else if (ptOrEta == "Eta")
12807      {
12808       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12809      }
12810   } else // this is diff flow of RPs 
12811     {
12812      if(ptOrEta == "Pt")
12813      { 
12814       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12815      } else if (ptOrEta == "Eta")
12816        {
12817         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12818        }
12819     }
12820   if(t==1)t++; 
12821   fNoOfParticlesInBin->Fill(t+pe+0.5);  
12822  }
12823  
12824 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12825
12826 //================================================================================================================================
12827
12828 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12829 {
12830  // Evaluate with nested loops correction terms for non-uniform acceptance (both sin and cos terms) relevant for differential flow.
12831  
12832  // Remark 1: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
12833  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12834  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
12835  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
12836  //  cti: 
12837  //    0: <<sc n(psi1)>>
12838  //    1: <<sc n(psi1+phi2)>> 
12839  //    2: <<sc n(psi1+phi2-phi3)>>
12840  //    3: <<sc n(psi1-phi2-phi3)>>
12841  //    4:
12842  //    5:
12843  //    6:
12844   
12845  Int_t typeFlag = 0;
12846  Int_t ptEtaFlag = 0;
12847  if(type == "RP")
12848  {
12849   typeFlag = 0;
12850  } else if(type == "POI")
12851    {
12852     typeFlag = 1;
12853    }      
12854  if(ptOrEta == "Pt")
12855  {
12856   ptEtaFlag = 0;
12857  } else if(ptOrEta == "Eta")
12858    {
12859     ptEtaFlag = 1;
12860    } 
12861  // shortcuts:
12862  Int_t t = typeFlag;
12863  Int_t pe = ptEtaFlag;
12864       
12865  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12866  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12867  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12868  
12869  Int_t nPrim = anEvent->NumberOfTracks(); 
12870  AliFlowTrackSimple *aftsTrack = NULL;
12871  
12872  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12873  
12874  Int_t n = fHarmonic; 
12875  
12876  // 1-particle correction terms:
12877  for(Int_t i1=0;i1<nPrim;i1++)
12878  {
12879   aftsTrack=anEvent->GetTrack(i1);
12880   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12881   if(typeFlag==1) // this is diff flow of POIs 
12882   {
12883    if(ptOrEta == "Pt")
12884    { 
12885     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12886    } else if (ptOrEta == "Eta")
12887      {
12888       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12889      }
12890   } else // this is diff flow of RPs 
12891     {
12892      if(ptOrEta == "Pt")
12893      { 
12894       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12895      } else if (ptOrEta == "Eta")
12896        {
12897         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12898        }
12899     }
12900   psi1=aftsTrack->Phi(); 
12901   // sin terms: 
12902   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
12903   // cos terms: 
12904   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
12905  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12906    
12907  // 2-particle correction terms:
12908  for(Int_t i1=0;i1<nPrim;i1++)
12909  {
12910   aftsTrack=anEvent->GetTrack(i1);
12911    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12912   if(typeFlag==1) // this is diff flow of POIs 
12913   {
12914    if(ptOrEta == "Pt")
12915    { 
12916     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12917    } else if (ptOrEta == "Eta")
12918      {
12919       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12920      }
12921   } else // this is diff flow of RPs 
12922     {
12923      if(ptOrEta == "Pt")
12924      { 
12925       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12926      } else if (ptOrEta == "Eta")
12927        {
12928         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12929        }
12930     }
12931   psi1=aftsTrack->Phi(); 
12932   for(Int_t i2=0;i2<nPrim;i2++)
12933   {
12934    if(i2==i1) continue;
12935    aftsTrack=anEvent->GetTrack(i2);
12936    // RP condition (!(first) particle in the correlator must be RP):
12937    if(!(aftsTrack->InRPSelection())) continue;
12938    phi2=aftsTrack->Phi();   
12939    // sin terms: 
12940    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),1.); // <<sin(n*(psi1+phi2))>>  
12941    // cos terms: 
12942    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),1.); // <<cos(n*(psi1+phi2))>>  
12943   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12944  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
12945  
12946  // 3-particle correction terms:
12947  for(Int_t i1=0;i1<nPrim;i1++)
12948  {
12949   aftsTrack=anEvent->GetTrack(i1);
12950    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12951   if(typeFlag==1) // this is diff flow of POIs 
12952   {
12953    if(ptOrEta == "Pt")
12954    { 
12955     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12956    } else if (ptOrEta == "Eta")
12957      {
12958       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12959      }
12960   } else // this is diff flow of RPs 
12961     {
12962      if(ptOrEta == "Pt")
12963      { 
12964       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12965      } else if (ptOrEta == "Eta")
12966        {
12967         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12968        }
12969     }
12970   psi1=aftsTrack->Phi();
12971   for(Int_t i2=0;i2<nPrim;i2++)
12972   {
12973    if(i2==i1) continue;
12974    aftsTrack=anEvent->GetTrack(i2);
12975    // RP condition (!(first) particle in the correlator must be RP):
12976    if(!(aftsTrack->InRPSelection())) continue;
12977    phi2=aftsTrack->Phi();
12978    for(Int_t i3=0;i3<nPrim;i3++)
12979    {
12980     if(i3==i1||i3==i2) continue;
12981     aftsTrack=anEvent->GetTrack(i3);
12982     // RP condition (!(first) particle in the correlator must be RP):
12983     if(!(aftsTrack->InRPSelection())) continue;
12984     phi3=aftsTrack->Phi();
12985     // sin terms: 
12986     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2-phi3)),1.); // <<sin(n*(psi1+phi2-phi3))>>  
12987     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1-phi2-phi3)),1.); // <<sin(n*(psi1-phi2-phi3))>>  
12988     // cos terms: 
12989     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3)),1.); // <<cos(n*(psi1+phi2-phi3))>>  
12990     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-phi2-phi3)),1.); // <<cos(n*(psi1-phi2-phi3))>>  
12991    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
12992   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
12993  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12994    
12995 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12996
12997
12998 //================================================================================================================================
12999
13000
13001 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
13002 {
13003  // Compare corrections temrs for non-uniform acceptance needed for diff. flow calculated with nested loops and those calculated from Q-vectors
13004  
13005  Int_t typeFlag = 0;
13006  Int_t ptEtaFlag = 0;
13007  if(type == "RP")
13008  {
13009   typeFlag = 0;
13010  } else if(type == "POI")
13011    {
13012     typeFlag = 1;
13013    }      
13014  if(ptOrEta == "Pt")
13015  {
13016   ptEtaFlag = 0;
13017  } else if(ptOrEta == "Eta")
13018    {
13019     ptEtaFlag = 1;
13020    } 
13021  // shortcuts:
13022  Int_t t = typeFlag;
13023  Int_t pe = ptEtaFlag;
13024       
13025  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
13026  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
13027  //TString sinCosFlag[2] = {"sin","cos"}; // to be improved (eventually promote to data member)
13028  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)
13029  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)
13030  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
13031  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
13032  
13033  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
13034  
13035  cout<<endl;
13036  cout<<"   ******************************************"<<endl;
13037  cout<<"   ****  cross-checking the correction   ****"<<endl;
13038  cout<<"   **** terms for non-uniform acceptance ****"<<endl; 
13039  cout<<"   ****    for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
13040  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights))
13041  {
13042   cout<<"   ****    (particle weights not used)   ****"<<endl;
13043  } else
13044    {
13045     cout<<"   ****     (particle weights used)      ****"<<endl;
13046    } 
13047  cout<<"   ******************************************"<<endl; 
13048  cout<<endl;
13049  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
13050  cout<<endl;
13051  
13052  for(Int_t cti=0;cti<4;cti++) // correction term index
13053  {
13054   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
13055   {
13056    if(sc==0) // to be improved (this can be implemented better)
13057    { 
13058     cout<<"      "<<reducedCorrectionSinTerms[cti].Data()<<":"<<endl;
13059    } else
13060      {
13061       cout<<"      "<<reducedCorrectionCosTerms[cti].Data()<<":"<<endl;     
13062      }
13063    cout<<"      from Q-vectors    = "<<fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
13064    cout<<"      from nested loops = "<<fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]->GetBinContent(1)<<endl;
13065    cout<<endl;  
13066   } 
13067  } // end of for(Int_t rci=0;rci<4;rci++)
13068
13069 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
13070
13071 //================================================================================================================================
13072
13073 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
13074 {
13075  // Calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (cos terms).
13076  
13077  //                                  **********************************************************************
13078  //                                  **** weighted corrections for non-uniform acceptance (cos terms): ****
13079  //                                  **********************************************************************
13080  
13081  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
13082  //
13083  // 1st bin: <<w1 cos(n*(phi1))>> = cosP1nW1
13084  // 2nd bin: <<w1 w2 cos(n*(phi1+phi2))>> = cosP1nP1nW1W1
13085  // 3rd bin: <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1nW1W1W1 
13086  // ...
13087
13088  // multiplicity (number of particles used to determine the reaction plane)
13089  Double_t dMult = (*fSpk)(0,0);
13090  
13091  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13092  Double_t dReQ1n1k = (*fReQ)(0,1);
13093  Double_t dReQ2n2k = (*fReQ)(1,2);
13094  //Double_t dReQ3n3k = (*fReQ)(2,3);
13095  //Double_t dReQ4n4k = (*fReQ)(3,4);
13096  Double_t dReQ1n3k = (*fReQ)(0,3);
13097  Double_t dImQ1n1k = (*fImQ)(0,1);
13098  Double_t dImQ2n2k = (*fImQ)(1,2);
13099  //Double_t dImQ3n3k = (*fImQ)(2,3);
13100  //Double_t dImQ4n4k = (*fImQ)(3,4);
13101  //Double_t dImQ1n3k = (*fImQ)(0,3);
13102
13103  // dMs are variables introduced in order to simplify some Eqs. bellow:
13104  //..............................................................................................
13105  Double_t dM11 = (*fSpk)(1,1)-(*fSpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
13106  Double_t dM111 = (*fSpk)(2,1)-3.*(*fSpk)(0,2)*(*fSpk)(0,1)
13107                 + 2.*(*fSpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
13108  //..............................................................................................
13109          // 1-particle:
13110  Double_t cosP1nW1 = 0.; // <<w1 cos(n*(phi1))>>
13111    
13112  if(dMult>0 && TMath::Abs((*fSpk)(0,1))>1.e-6)
13113  {
13114   cosP1nW1 = dReQ1n1k/(*fSpk)(0,1); 
13115   
13116   // average weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
13117   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1nW1);
13118   
13119   // final average weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
13120   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1nW1,(*fSpk)(0,1));  
13121  } 
13122  
13123  // 2-particle:
13124  Double_t cosP1nP1nW1W1 = 0.; // <<w1 w2 cos(n*(phi1+phi2))>>
13125  
13126  if(dMult>1 && TMath::Abs(dM11)>1.e-6)
13127  {
13128   cosP1nP1nW1W1 = (pow(dReQ1n1k,2)-pow(dImQ1n1k,2)-dReQ2n2k)/dM11; 
13129   
13130   // average weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
13131   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1nW1W1);
13132   
13133   // final average weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
13134   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1nW1W1,dM11);  
13135  } 
13136  
13137  // 3-particle:
13138  Double_t cosP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>>
13139  
13140  if(dMult>2 && TMath::Abs(dM111)>1.e-6)
13141  {
13142   cosP1nM1nM1nW1W1W1 = (dReQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
13143                      - dReQ1n1k*dReQ2n2k-dImQ1n1k*dImQ2n2k
13144                      - 2.*((*fSpk)(0,2))*dReQ1n1k
13145                      + 2.*dReQ1n3k) 
13146                      / dM111; 
13147   
13148   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
13149   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1nW1W1W1);
13150   
13151   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
13152   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1nW1W1W1,dM111);  
13153  } 
13154  
13155 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
13156
13157
13158 //================================================================================================================================
13159
13160
13161 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
13162 {
13163  // calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
13164  
13165  //                                  **********************************************************************
13166  //                                  **** weighted corrections for non-uniform acceptance (sin terms): ****
13167  //                                  **********************************************************************
13168  
13169  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
13170  //
13171  // 1st bin: <<w1 sin(n*(phi1))>> = sinP1nW1
13172  // 2nd bin: <<w1 w2 sin(n*(phi1+phi2))>> = sinP1nP1nW1W1
13173  // 3rd bin: <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1nW1W1W1 
13174  // ...
13175
13176  // multiplicity (number of particles used to determine the reaction plane)
13177  Double_t dMult = (*fSpk)(0,0);
13178  
13179  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13180  Double_t dReQ1n1k = (*fReQ)(0,1);
13181  Double_t dReQ2n2k = (*fReQ)(1,2);
13182  //Double_t dReQ3n3k = (*fReQ)(2,3);
13183  //Double_t dReQ4n4k = (*fReQ)(3,4);
13184  //Double_t dReQ1n3k = (*fReQ)(0,3);
13185  Double_t dImQ1n1k = (*fImQ)(0,1);
13186  Double_t dImQ2n2k = (*fImQ)(1,2);
13187  //Double_t dImQ3n3k = (*fImQ)(2,3);
13188  //Double_t dImQ4n4k = (*fImQ)(3,4);
13189  Double_t dImQ1n3k = (*fImQ)(0,3);
13190
13191  // dMs are variables introduced in order to simplify some Eqs. bellow:
13192  //..............................................................................................
13193  Double_t dM11 = (*fSpk)(1,1)-(*fSpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
13194  Double_t dM111 = (*fSpk)(2,1)-3.*(*fSpk)(0,2)*(*fSpk)(0,1)
13195                 + 2.*(*fSpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
13196  //..............................................................................................
13197  
13198  // 1-particle:
13199  Double_t sinP1nW1 = 0.; // <<w1 sin(n*(phi1))>>
13200  
13201  if(dMult>0 && TMath::Abs((*fSpk)(0,1))>1.e-6)
13202  {
13203   sinP1nW1 = dImQ1n1k/((*fSpk)(0,1)); 
13204      
13205   // average weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
13206   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1nW1);
13207   
13208   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
13209   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1nW1,(*fSpk)(0,1));  
13210  } 
13211  
13212  // 2-particle:
13213  Double_t sinP1nP1nW1W1 = 0.; // <<w1 w2 sin(n*(phi1+phi2))>>
13214  
13215  if(dMult>1 && TMath::Abs(dM11)>1.e-6)
13216  {
13217   sinP1nP1nW1W1 = (2.*dReQ1n1k*dImQ1n1k-dImQ2n2k)/dM11; 
13218      
13219   // average weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
13220   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1nW1W1);
13221   
13222   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
13223   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1nW1W1,dM11);  
13224  } 
13225  
13226  // 3-particle:
13227  Double_t sinP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>>
13228  
13229  if(dMult>2 && TMath::Abs(dM111)>1.e-6)
13230  {
13231   sinP1nM1nM1nW1W1W1 = (-dImQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
13232                      + dReQ1n1k*dImQ2n2k-dImQ1n1k*dReQ2n2k
13233                      + 2.*((*fSpk)(0,2))*dImQ1n1k
13234                      - 2.*dImQ1n3k)
13235                      / dM111; 
13236   
13237   // average weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
13238   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1nW1W1W1);
13239   
13240   // final average weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
13241   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1nW1W1W1,dM111);  
13242  } 
13243  
13244 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
13245
13246 //================================================================================================================================
13247
13248 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
13249 {
13250  // Evaluate with nested loops correction terms for non-uniform acceptance for integrated flow (using the particle weights). 
13251
13252  // Results are stored in profiles fIntFlowDirectCorrectionTermsForNUA[0] (sin terms) and
13253  // fIntFlowDirectCorrectionTermsForNUA[1] (cos terms). 
13254  
13255  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrectionTermsForNUA[sc] is 
13256  // organized as follows (sc stands for either sin or cos):
13257  //
13258  // 1st bin: <<w1 sc(n*(phi1))>> = scP1nW1
13259  // 2nd bin: <<w1 w2 sc(n*(phi1+phi2))>> = scP1nP1nW1W1
13260  // 3rd bin: <<w1 w2 w3 sc(n*(phi1-phi2-phi3))>> = scP1nM1nM1nW1W1W1 
13261  // ...
13262   
13263  Int_t nPrim = anEvent->NumberOfTracks(); 
13264  AliFlowTrackSimple *aftsTrack = NULL;
13265  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
13266  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
13267  Double_t phi1=0., phi2=0., phi3=0.;
13268  Double_t wPhi1=1., wPhi2=1., wPhi3=1.;
13269  Int_t n = fHarmonic; 
13270  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
13271  Double_t dMult = (*fSpk)(0,0);
13272  cout<<endl;
13273  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
13274  if(dMult<1)
13275  {
13276   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
13277  } else if (dMult>fMaxAllowedMultiplicity)
13278    {
13279     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
13280    } else 
13281      { 
13282       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
13283      } 
13284       
13285  // 1-particle correction terms using particle weights:       
13286  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
13287  {
13288   for(Int_t i1=0;i1<nPrim;i1++)
13289   {
13290    aftsTrack=anEvent->GetTrack(i1);
13291    if(!(aftsTrack->InRPSelection())) continue;
13292    phi1=aftsTrack->Phi();
13293    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13294    // 1-particle correction terms using particle weights:
13295    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),wPhi1); // <w1 sin(n*phi1)>
13296    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),wPhi1); // <w1 cos(n*phi1)>
13297   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13298  } // end of if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity) 
13299  
13300  // 2-particle correction terms using particle weights:       
13301  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
13302  {
13303   for(Int_t i1=0;i1<nPrim;i1++)
13304   {
13305    aftsTrack=anEvent->GetTrack(i1);
13306    if(!(aftsTrack->InRPSelection())) continue;
13307    phi1=aftsTrack->Phi();
13308    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13309    for(Int_t i2=0;i2<nPrim;i2++)
13310    {
13311     if(i2==i1)continue;
13312     aftsTrack=anEvent->GetTrack(i2);
13313     if(!(aftsTrack->InRPSelection())) continue;
13314     phi2=aftsTrack->Phi();
13315     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
13316     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
13317     // 2-p correction terms using particle weights:    
13318     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 sin(n*(phi1+phi2))>
13319     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 cos(n*(phi1+phi2))>
13320    } // end of for(Int_t i2=0;i2<nPrim;i2++)
13321   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13322  } // end of if(nPrim>=2)
13323
13324  // 3-particle correction terms using particle weights:       
13325  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
13326  { 
13327   for(Int_t i1=0;i1<nPrim;i1++)
13328   {
13329    aftsTrack=anEvent->GetTrack(i1);
13330    if(!(aftsTrack->InRPSelection())) continue;
13331    phi1=aftsTrack->Phi();
13332    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13333    for(Int_t i2=0;i2<nPrim;i2++)
13334    {
13335     if(i2==i1)continue;
13336     aftsTrack=anEvent->GetTrack(i2);
13337     if(!(aftsTrack->InRPSelection())) continue;
13338     phi2=aftsTrack->Phi();
13339     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
13340     for(Int_t i3=0;i3<nPrim;i3++)
13341     {
13342      if(i3==i1||i3==i2)continue;
13343      aftsTrack=anEvent->GetTrack(i3);
13344      if(!(aftsTrack->InRPSelection())) continue;
13345      phi3=aftsTrack->Phi();
13346      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
13347      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
13348      // 3-p correction terms using particle weights:    
13349      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 sin(n*(phi1-phi2-phi3))>
13350      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n*(phi1-phi2-phi3))>
13351     } // end of for(Int_t i3=0;i3<nPrim;i3++)
13352    } // end of for(Int_t i2=0;i2<nPrim;i2++)
13353   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13354  } // end of if(nPrim>=3)
13355  
13356  /*
13357  
13358  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
13359  {
13360   // 4 nested loops multiparticle correlations using particle weights:       
13361   for(Int_t i1=0;i1<nPrim;i1++)
13362   {
13363    aftsTrack=anEvent->GetTrack(i1);
13364    if(!(aftsTrack->InRPSelection())) continue;
13365    phi1=aftsTrack->Phi();
13366    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
13367    for(Int_t i2=0;i2<nPrim;i2++)
13368    {
13369     if(i2==i1)continue;
13370     aftsTrack=anEvent->GetTrack(i2);
13371     if(!(aftsTrack->InRPSelection())) continue;
13372     phi2=aftsTrack->Phi();
13373     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
13374     for(Int_t i3=0;i3<nPrim;i3++)
13375     {
13376      if(i3==i1||i3==i2)continue;
13377      aftsTrack=anEvent->GetTrack(i3);
13378      if(!(aftsTrack->InRPSelection())) continue;
13379      phi3=aftsTrack->Phi();
13380      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
13381      for(Int_t i4=0;i4<nPrim;i4++)
13382      {
13383       if(i4==i1||i4==i2||i4==i3)continue;
13384       aftsTrack=anEvent->GetTrack(i4);
13385       if(!(aftsTrack->InRPSelection())) continue;
13386       phi4=aftsTrack->Phi();
13387       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
13388       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
13389       // 4-p correlations using particle weights:
13390       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
13391       // extra correlations: 
13392       // 2-p extra correlations (do not appear if particle weights are not used):
13393       // ...
13394       // 3-p extra correlations (do not appear if particle weights are not used):
13395       // ...
13396       // 4-p extra correlations (do not appear if particle weights are not used):
13397       // ...
13398      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
13399     } // end of for(Int_t i3=0;i3<nPrim;i3++)
13400    } // end of for(Int_t i2=0;i2<nPrim;i2++)
13401   } // end of for(Int_t i1=0;i1<nPrim;i1++)
13402  } // end of if(nPrim>=4)
13403
13404  */
13405
13406  cout<<endl; 
13407
13408 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
13409
13410 //================================================================================================================================
13411
13412 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
13413 {
13414  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms) using particle weights.
13415  
13416  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
13417  //
13418  //  0: <<cos n(psi)>>
13419  //  1: <<w2 cos n(psi1+phi2)>>
13420  //  2: <<w2 w3 cos n(psi1+phi2-phi3)>>
13421  //  3: <<w2 w3 cos n(psi1-phi2-phi3)>>
13422  //  4:
13423  //  5:
13424  //  6:
13425  
13426  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13427  Double_t dReQ1n1k = (*fReQ)(0,1);
13428  Double_t dReQ2n2k = (*fReQ)(1,2);
13429  //Double_t dReQ1n3k = (*fReQ)(0,3);
13430  //Double_t dReQ4n4k = (*fReQ)(3,4);
13431  Double_t dImQ1n1k = (*fImQ)(0,1);
13432  Double_t dImQ2n2k = (*fImQ)(1,2);
13433  //Double_t dImQ1n3k = (*fImQ)(0,3);
13434  //Double_t dImQ4n4k = (*fImQ)(3,4);
13435  
13436  // S^M_{p,k} (see .h file for the definition of fSpk):
13437  Double_t dSM1p1k = (*fSpk)(0,1);
13438  Double_t dSM1p2k = (*fSpk)(0,2);
13439  Double_t dSM2p1k = (*fSpk)(1,1);
13440
13441  Int_t t = 0; // type flag 
13442  Int_t pe = 0; // ptEta flag
13443  
13444  if(type == "RP")
13445  {
13446   t = 0;
13447  } else if(type == "POI")
13448    {
13449     t = 1;
13450    }
13451
13452  if(ptOrEta == "Pt")
13453  {
13454   pe = 0;
13455  } else if(ptOrEta == "Eta")
13456    {
13457     pe = 1;
13458    }
13459     
13460  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
13461  Double_t minPtEta[2] = {fPtMin,fEtaMin};
13462  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
13463  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
13464  
13465  // looping over all bins and calculating correction terms: 
13466  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13467  {
13468   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
13469   Double_t p1n0kRe = 0.;
13470   Double_t p1n0kIm = 0.;
13471
13472   // number of POIs in particular pt or eta bin:
13473   Double_t mp = 0.;
13474
13475   // 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):
13476   Double_t q1n2kRe = 0.;
13477   Double_t q1n2kIm = 0.;
13478   Double_t q2n1kRe = 0.;
13479   Double_t q2n1kIm = 0.;
13480     
13481   // s_{1,1}, s_{1,2} // to be improved (add explanation)  
13482   Double_t s1p1k = 0.; 
13483   Double_t s1p2k = 0.; 
13484   
13485   // number of particles which are both RPs and POIs in particular pt or eta bin:
13486   Double_t mq = 0.;
13487   
13488   // M0111 from Eq. (118) in QC2c (to be improved (notation))
13489   Double_t dM01 = 0.;
13490   Double_t dM011 = 0.;
13491   
13492   if(type == "POI")
13493   {           
13494    // q_{m*n,k}:
13495    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
13496            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
13497    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
13498            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
13499    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
13500            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
13501    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
13502            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
13503    mq = fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
13504    
13505    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
13506    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
13507   }else if(type == "RP")
13508    {
13509     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
13510     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
13511             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
13512     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
13513             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
13514     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
13515             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
13516     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
13517             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
13518     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
13519     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
13520     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
13521     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.);  
13522     
13523     mq = fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
13524   }    
13525   
13526   if(type == "POI")
13527   {
13528    // p_{m*n,k}:   
13529    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
13530            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
13531    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
13532            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
13533    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
13534    // M01 from Eq. (118) in QC2c (to be improved (notation)):
13535    dM01 = mp*dSM1p1k-s1p1k;
13536    dM011 = mp*(dSM2p1k-dSM1p2k)
13537          - 2.*(s1p1k*dSM1p1k-s1p2k);
13538        
13539    // typeFlag = RP (0) or POI (1):   
13540    t = 1; 
13541   } else if(type == "RP")
13542     {  
13543      // to be improved (cross-checked):
13544      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
13545              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
13546      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
13547              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
13548      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
13549      // M01 from Eq. (118) in QC2c (to be improved (notation)):
13550      dM01 = mp*dSM1p1k-s1p1k;
13551      dM011 = mp*(dSM2p1k-dSM1p2k)
13552            - 2.*(s1p1k*dSM1p1k-s1p2k); 
13553      // typeFlag = RP (0) or POI (1): 
13554      t = 0;
13555     }
13556   
13557   // <<cos n(psi1)>>:
13558   Double_t cosP1nPsi = 0.;
13559   if(mp)
13560   {
13561    cosP1nPsi = p1n0kRe/mp;
13562    
13563    // fill profile for <<cos n(psi1)>>:
13564    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
13565    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
13566    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
13567   } // end of if(mp)   
13568   
13569   // <<w2 cos n(psi1+phi2)>>:
13570   Double_t cosP1nPsiP1nPhiW2 = 0.;
13571   if(dM01)
13572   {
13573    cosP1nPsiP1nPhiW2 = (p1n0kRe*dReQ1n1k-p1n0kIm*dImQ1n1k-q2n1kRe)/(dM01);
13574    // fill profile for <<w2 cos n(psi1+phi2)>>:
13575    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhiW2,dM01);
13576    // histogram to store <w2 cos n(psi1+phi2)> e-b-e (needed in some other methods):
13577    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhiW2);
13578   } // end of if(dM01)   
13579   
13580   // <<w2 w3 cos n(psi1+phi2-phi3)>>:
13581   Double_t cosP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
13582   if(dM011)
13583   {
13584    cosP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
13585                               - p1n0kRe*dSM1p2k
13586                               - q2n1kRe*dReQ1n1k-q2n1kIm*dImQ1n1k
13587                               - s1p1k*dReQ1n1k
13588                               + 2.*q1n2kRe)
13589                               / dM011;  
13590    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
13591    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3W2W3,dM011);
13592    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
13593    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3W2W3);
13594   } // end of if(dM011)   
13595   
13596   // <<w2 w3 cos n(psi1-phi2-phi3)>>:
13597   Double_t cosP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
13598   if(dM011)
13599   {
13600    cosP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))+2.*p1n0kIm*dReQ1n1k*dImQ1n1k
13601                               - 1.*(p1n0kRe*dReQ2n2k+p1n0kIm*dImQ2n2k)  
13602                               - 2.*s1p1k*dReQ1n1k
13603                               + 2.*q1n2kRe)
13604                               / dM011;
13605    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
13606    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3W2W3,dM011);
13607    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
13608    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3W2W3);
13609   } // end of if(dM011)   
13610  
13611  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13612    
13613 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
13614
13615
13616 //================================================================================================================================
13617
13618
13619 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
13620 {
13621  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
13622   
13623  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
13624  //  0: <<sin n(psi1)>>
13625  //  1: <<w2 sin n(psi1+phi2)>>
13626  //  2: <<w2 w3 sin n(psi1+phi2-phi3)>>
13627  //  3: <<w2 w3 sin n(psi1-phi2-phi3)>>:
13628  //  4:
13629  //  5:
13630  //  6:
13631  
13632  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
13633  Double_t dReQ1n1k = (*fReQ)(0,1);
13634  Double_t dReQ2n2k = (*fReQ)(1,2);
13635  //Double_t dReQ1n3k = (*fReQ)(0,3);
13636  //Double_t dReQ4n4k = (*fReQ)(3,4);
13637  Double_t dImQ1n1k = (*fImQ)(0,1);
13638  Double_t dImQ2n2k = (*fImQ)(1,2);
13639  //Double_t dImQ1n3k = (*fImQ)(0,3);
13640  //Double_t dImQ4n4k = (*fImQ)(3,4);
13641  
13642  // S^M_{p,k} (see .h file for the definition of fSpk):
13643  Double_t dSM1p1k = (*fSpk)(0,1);
13644  Double_t dSM1p2k = (*fSpk)(0,2);
13645  Double_t dSM2p1k = (*fSpk)(1,1);
13646
13647  Int_t t = 0; // type flag 
13648  Int_t pe = 0; // ptEta flag
13649  
13650  if(type == "RP")
13651  {
13652   t = 0;
13653  } else if(type == "POI")
13654    {
13655     t = 1;
13656    }
13657
13658  if(ptOrEta == "Pt")
13659  {
13660   pe = 0;
13661  } else if(ptOrEta == "Eta")
13662    {
13663     pe = 1;
13664    }
13665     
13666  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
13667  Double_t minPtEta[2] = {fPtMin,fEtaMin};
13668  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
13669  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
13670
13671  // looping over all bins and calculating correction terms: 
13672  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13673  {
13674   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
13675   Double_t p1n0kRe = 0.;
13676   Double_t p1n0kIm = 0.;
13677
13678   // number of POIs in particular pt or eta bin:
13679   Double_t mp = 0.;
13680
13681   // 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):
13682   Double_t q1n2kRe = 0.;
13683   Double_t q1n2kIm = 0.;
13684   Double_t q2n1kRe = 0.;
13685   Double_t q2n1kIm = 0.;
13686     
13687   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
13688   Double_t s1p1k = 0.; 
13689   Double_t s1p2k = 0.; 
13690   
13691   // number of particles which are both RPs and POIs in particular pt or eta bin:
13692   Double_t mq = 0.;
13693   
13694   // M0111 from Eq. (118) in QC2c (to be improved (notation))
13695   Double_t dM01 = 0.;
13696   Double_t dM011 = 0.;
13697
13698   if(type == "POI")
13699   {    
13700    // q_{m*n,k}:
13701    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
13702            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
13703    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
13704            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
13705    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
13706            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
13707    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
13708            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
13709    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
13710    
13711    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
13712    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
13713   }else if(type == "RP")
13714    {
13715     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
13716     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
13717             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
13718     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
13719             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
13720     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
13721             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
13722     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
13723             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
13724     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
13725     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
13726     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
13727     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
13728   }    
13729   
13730   if(type == "POI")
13731   {
13732    // p_{m*n,k}:   
13733    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
13734            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
13735    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
13736            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
13737    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
13738    // M01 from Eq. (118) in QC2c (to be improved (notation)):
13739    dM01 = mp*dSM1p1k-s1p1k;
13740    dM011 = mp*(dSM2p1k-dSM1p2k)
13741          - 2.*(s1p1k*dSM1p1k-s1p2k);  
13742    // typeFlag = RP (0) or POI (1):   
13743    t = 1;           
13744   } else if(type == "RP")
13745     { 
13746      // to be improved (cross-checked):
13747      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
13748              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
13749      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
13750              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
13751      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)    
13752      // M01 from Eq. (118) in QC2c (to be improved (notation)):
13753      dM01 = mp*dSM1p1k-s1p1k;
13754      dM011 = mp*(dSM2p1k-dSM1p2k)
13755            - 2.*(s1p1k*dSM1p1k-s1p2k); 
13756      // typeFlag = RP (0) or POI (1): 
13757      t = 0;
13758     }
13759   
13760   // <<sin n(psi1)>>:
13761   Double_t sinP1nPsi = 0.;
13762   if(mp)
13763   {
13764    sinP1nPsi = p1n0kIm/mp;
13765    
13766    // fill profile for <<sin n(psi1)>>:
13767    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
13768    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
13769    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
13770   } // end of if(mp)   
13771   
13772   // <<w2 sin n(psi1+phi2)>>:
13773   Double_t sinP1nPsiP1nPhiW2 = 0.;
13774   if(dM01)
13775   {
13776    sinP1nPsiP1nPhiW2 = (p1n0kRe*dImQ1n1k+p1n0kIm*dReQ1n1k-q2n1kIm)/(dM01);
13777    // fill profile for <<w2 sin n(psi1+phi2)>>:
13778    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhiW2,dM01);
13779    // histogram to store <w2 sin n(psi1+phi2)> e-b-e (needed in some other methods):
13780    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhiW2);
13781   } // end of if(mp*dMult-mq)   
13782   
13783   // <<w2 w3 sin n(psi1+phi2-phi3)>>:
13784   Double_t sinP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
13785   if(dM011)
13786   {
13787    sinP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
13788                               - p1n0kIm*dSM1p2k
13789                               + q2n1kRe*dImQ1n1k-q2n1kIm*dReQ1n1k
13790                               - s1p1k*dImQ1n1k
13791                               + 2.*q1n2kIm)
13792                               / dM011;  
13793    // fill profile for <<w2 w3 sin n(psi1+phi2-phi3)>>:
13794    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3W2W3,dM011);
13795    // histogram to store <w2 w3 sin n(psi1+phi2-phi3)> e-b-e (needed in some other methods):
13796    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3W2W3);
13797   } // end of if(dM011)   
13798   
13799   // <<w2 w3 sin n(psi1-phi2-phi3)>>:
13800   Double_t sinP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
13801   if(dM011)
13802   {
13803    sinP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))-2.*p1n0kRe*dReQ1n1k*dImQ1n1k
13804                               + 1.*(p1n0kRe*dImQ2n2k-p1n0kIm*dReQ2n2k)  
13805                               + 2.*s1p1k*dImQ1n1k
13806                               - 2.*q1n2kIm)
13807                               / dM011;
13808    // fill profile for <<w2 w3 sin n(psi1-phi2-phi3)>>:
13809    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3W2W3,dM011);
13810    // histogram to store <w2 w3 sin n(psi1-phi2-phi3)> e-b-e (needed in some other methods):
13811    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3W2W3);
13812   } // end of if(dM011)   
13813   
13814  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
13815
13816 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
13817
13818 //================================================================================================================================
13819    
13820 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
13821 {
13822  // Evaluate with nested loops correction terms for non-uniform acceptance 
13823  // with using particle weights (both sin and cos terms) relevant for differential flow.
13824  
13825  // Remark 1: "w1" in expressions bellow is a particle weight used only for particles which were 
13826  //           flagged both as POI and RP.
13827  // Remark 2: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
13828  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
13829  // Remark 3: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
13830  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
13831  //  cti: 
13832  //    0: <<sc n(psi1)>>
13833  //    1: <<w2 sc n(psi1+phi2)>> 
13834  //    2: <<w2 w3 sc n(psi1+phi2-phi3)>>
13835  //    3: <<w2 w3 sc n(psi1-phi2-phi3)>>
13836  //    4:
13837  //    5:
13838  //    6:
13839      
13840  Int_t typeFlag = 0;
13841  Int_t ptEtaFlag = 0;
13842  if(type == "RP")
13843  {
13844   typeFlag = 0;
13845  } else if(type == "POI")
13846    {
13847     typeFlag = 1;
13848    }      
13849  if(ptOrEta == "Pt")
13850  {
13851   ptEtaFlag = 0;
13852  } else if(ptOrEta == "Eta")
13853    {
13854     ptEtaFlag = 1;
13855    } 
13856  // shortcuts:
13857  Int_t t = typeFlag;
13858  Int_t pe = ptEtaFlag;
13859       
13860  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
13861  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
13862  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
13863  
13864  Int_t nPrim = anEvent->NumberOfTracks(); 
13865  AliFlowTrackSimple *aftsTrack = NULL;
13866  
13867  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
13868  Double_t wPhi2=1., wPhi3=1.;
13869  
13870  Int_t n = fHarmonic; 
13871  
13872  // 1'-particle correction terms:
13873  for(Int_t i1=0;i1<nPrim;i1++)
13874  {
13875   aftsTrack=anEvent->GetTrack(i1);
13876   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
13877   if(typeFlag==1) // this is diff flow of POIs 
13878   {
13879    if(ptOrEta == "Pt")
13880    { 
13881     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
13882    } else if (ptOrEta == "Eta")
13883      {
13884       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
13885      }
13886   } else // this is diff flow of RPs 
13887     {
13888      if(ptOrEta == "Pt")
13889      { 
13890       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
13891      } else if (ptOrEta == "Eta")
13892        {
13893         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
13894        }
13895     }
13896   psi1=aftsTrack->Phi(); 
13897   // sin terms: 
13898   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
13899   // cos terms: 
13900   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
13901  }//end of for(Int_t i1=0;i1<nPrim;i1++)
13902    
13903  // 2'-particle correction terms:
13904  for(Int_t i1=0;i1<nPrim;i1++)
13905  {
13906   aftsTrack=anEvent->GetTrack(i1);
13907   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
13908   if(typeFlag==1) // this is diff flow of POIs 
13909   {
13910    if(ptOrEta == "Pt")
13911    { 
13912     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
13913    } else if (ptOrEta == "Eta")
13914      {
13915       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
13916      }
13917   } else // this is diff flow of RPs 
13918     {
13919      if(ptOrEta == "Pt")
13920      { 
13921       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
13922      } else if (ptOrEta == "Eta")
13923        {
13924         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
13925        }
13926     }
13927   psi1=aftsTrack->Phi(); 
13928   for(Int_t i2=0;i2<nPrim;i2++)
13929   {
13930    if(i2==i1) continue;
13931    aftsTrack=anEvent->GetTrack(i2);
13932    // RP condition (!(first) particle in the correlator must be RP):
13933    if(!(aftsTrack->InRPSelection())) continue;
13934    phi2=aftsTrack->Phi();
13935    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
13936    // sin terms: 
13937    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),wPhi2); // <<w2 sin(n*(psi1+phi2))>>  
13938    // cos terms: 
13939    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),wPhi2); // <<w2 cos(n*(psi1+phi2))>>  
13940   }//end of for(Int_t i2=0;i2<nPrim;i2++)
13941  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
13942  
13943  // 3'-particle correction terms:
13944  for(Int_t i1=0;i1<nPrim;i1++)
13945  {
13946   aftsTrack=anEvent->GetTrack(i1);
13947   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
13948   if(typeFlag==1) // this is diff flow of POIs 
13949   {
13950    if(ptOrEta == "Pt")
13951    { 
13952     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
13953    } else if (ptOrEta == "Eta")
13954      {
13955       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
13956      }
13957   } else // this is diff flow of RPs 
13958     {
13959      if(ptOrEta == "Pt")
13960      { 
13961       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
13962      } else if (ptOrEta == "Eta")
13963        {
13964         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
13965        }
13966     }
13967   psi1=aftsTrack->Phi();
13968   for(Int_t i2=0;i2<nPrim;i2++)
13969   {
13970    if(i2==i1) continue;
13971    aftsTrack=anEvent->GetTrack(i2);
13972    // RP condition (!(first) particle in the correlator must be RP):
13973    if(!(aftsTrack->InRPSelection())) continue;
13974    phi2=aftsTrack->Phi();
13975    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
13976    for(Int_t i3=0;i3<nPrim;i3++)
13977    {
13978     if(i3==i1||i3==i2) continue;
13979     aftsTrack=anEvent->GetTrack(i3);
13980     // RP condition (!(first) particle in the correlator must be RP):
13981     if(!(aftsTrack->InRPSelection())) continue;
13982     phi3=aftsTrack->Phi();
13983     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));   
13984     // sin terms: 
13985     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))>>  
13986     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))>>  
13987     // cos terms: 
13988     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))>>  
13989     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))>>  
13990    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
13991   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
13992  }//end of for(Int_t i1=0;i1<nPrim;i1++)
13993                
13994 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
13995
13996 //================================================================================================================================
13997
13998 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
13999 {
14000  // Check all pointers used in method Finish().
14001  
14002  if(!fAvMultiplicity)
14003  {
14004   cout<<endl;
14005   cout<<" WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14006   cout<<endl;
14007   exit(0);
14008  }
14009  if(!fIntFlowCorrelationsPro)
14010  {
14011   cout<<endl;
14012   cout<<" WARNING (QC): fIntFlowCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14013   cout<<endl;
14014   exit(0); 
14015  }
14016  if(!fIntFlowSquaredCorrelationsPro)
14017  {
14018   cout<<endl;
14019   cout<<" WARNING (QC): fIntFlowSquaredCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14020   cout<<endl;
14021   exit(0); 
14022  } 
14023  if(!fIntFlowCorrelationsHist)
14024  {
14025   cout<<endl;
14026   cout<<" WARNING (QC): fIntFlowCorrelationsHist is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14027   cout<<endl;
14028   exit(0); 
14029  }
14030  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights) && !fIntFlowExtraCorrelationsPro) 
14031  {
14032   cout<<endl;
14033   cout<<" WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14034   cout<<endl;
14035   exit(0); 
14036  } 
14037  for(Int_t power=0;power<2;power++)
14038  { 
14039   if(!fIntFlowSumOfEventWeights[power]) 
14040   {
14041    cout<<endl;
14042    cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeights[%d] is NULL in CheckPointersUsedInFinish() !!!!",power)<<endl;
14043    cout<<endl;
14044    exit(0);
14045   }
14046  } // end of for(Int_t power=0;power<2;power++)
14047  if(!fIntFlowProductOfCorrelationsPro)
14048  {
14049   cout<<endl;
14050   cout<<" WARNING (QC): fIntFlowProductOfCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14051   cout<<endl;
14052   exit(0); 
14053  } 
14054  if(!fIntFlowSumOfProductOfEventWeights)
14055  {
14056   cout<<endl;
14057   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeights is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14058   cout<<endl;
14059   exit(0); 
14060  }
14061  if(!fIntFlowCovariances)
14062  {
14063   cout<<endl;
14064   cout<<" WARNING (QC): fIntFlowCovariances is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14065   cout<<endl;
14066   exit(0); 
14067  }  
14068  if(!fIntFlowQcumulants)
14069  {
14070   cout<<endl;
14071   cout<<" WARNING (QC): fIntFlowQcumulants is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14072   cout<<endl;
14073   exit(0); 
14074  }  
14075  if(!fIntFlow)
14076  {
14077   cout<<endl;
14078   cout<<" WARNING (QC): fIntFlow is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14079   cout<<endl;
14080   exit(0); 
14081  }
14082  if(!fCommonHists)
14083  {
14084   cout<<endl;
14085   cout<<" WARNING (QC): fCommonHists is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14086   cout<<endl;
14087   exit(0); 
14088  }
14089  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
14090  {
14091   cout<<endl;
14092   cout<<" WARNING (QC): fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th"<<endl; 
14093   cout<<"               && fCommonHistsResults8th is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14094   cout<<endl;
14095   exit(0);
14096  } 
14097  
14098  // NUA stuff:
14099  for(Int_t sc=0;sc<2;sc++) // sin/cos
14100  { 
14101   if(!fIntFlowCorrectionTermsForNUAPro[sc]) 
14102   {
14103    cout<<endl;
14104    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
14105    cout<<endl;
14106    exit(0);
14107   }
14108   if(!fIntFlowCorrectionTermsForNUAHist[sc]) 
14109   {
14110    cout<<endl;
14111    cout<<Form(" WARNING (QC): fIntFlowCorrectionTermsForNUAHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",sc)<<endl;
14112    cout<<endl;
14113    exit(0);
14114   }
14115   for(Int_t lq=0;lq<2;lq++) // linear/quadratic
14116   {
14117    if(!fIntFlowSumOfEventWeightsNUA[sc][lq]) 
14118    {
14119     cout<<endl;
14120     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsNUA[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",sc,lq)<<endl;
14121     cout<<endl;
14122     exit(0);
14123    }
14124   } // end of for(Int_t lq=0;lq<2;lq++) // linear/quadratic
14125  } // end of for(Int_t power=0;power<2;power++) 
14126  if(!fIntFlowProductOfCorrectionTermsForNUAPro)
14127  {
14128   cout<<endl;
14129   cout<<" WARNING (QC): fIntFlowProductOfCorrectionTermsForNUAPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14130   cout<<endl;
14131   exit(0); 
14132  } 
14133  if(!fIntFlowSumOfProductOfEventWeightsNUA)
14134  {
14135   cout<<endl;
14136   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeightsNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14137   cout<<endl;
14138   exit(0); 
14139  } 
14140  if(!fIntFlowCovariancesNUA)
14141  {
14142   cout<<endl;
14143   cout<<" WARNING (QC): fIntFlowCovariancesNUA is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14144   cout<<endl;
14145   exit(0); 
14146  } 
14147  if(!fIntFlowQcumulantsErrorSquaredRatio)
14148  {
14149   cout<<endl;
14150   cout<<" WARNING (QC): fIntFlowQcumulantsErrorSquaredRatio is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14151   cout<<endl;
14152   exit(0); 
14153  } 
14154  if(!fIntFlowDetectorBias)
14155  {
14156   cout<<endl;
14157   cout<<" WARNING (QC): fIntFlowDetectorBias is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14158   cout<<endl;
14159   exit(0); 
14160  }
14161  
14162  // Versus multiplicity:
14163  if(!fCalculateCumulantsVsM){return;}
14164  for(Int_t co=0;co<=3;co++) // cumulant order
14165  {
14166   if(!fIntFlowQcumulantsVsM[co])
14167   {
14168    cout<<endl;
14169    cout<<Form(" WARNING (QC): fIntFlowQcumulantsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
14170    cout<<endl;
14171    exit(0); 
14172   }
14173   if(!fIntFlowVsM[co])
14174   {
14175    cout<<endl;
14176    cout<<Form(" WARNING (QC): fIntFlowVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
14177    cout<<endl;
14178    exit(0); 
14179   }
14180   if(!fIntFlowDetectorBiasVsM[co])
14181   {
14182    cout<<endl;
14183    cout<<Form(" WARNING (QC): fIntFlowDetectorBiasVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",co)<<endl;
14184    cout<<endl;
14185    exit(0); 
14186   }
14187  } // end of for(Int_t c0=0;c0<=3;c0++) // cumulant order
14188  for(Int_t ci=0;ci<=3;ci++) // correlation index
14189  {
14190   if(!fIntFlowCorrelationsVsMPro[ci])
14191   {
14192    cout<<endl;
14193    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
14194    cout<<endl;
14195    exit(0); 
14196   }
14197   if(!fIntFlowSquaredCorrelationsVsMPro[ci])
14198   {
14199    cout<<endl;
14200    cout<<Form(" WARNING (QC): fIntFlowSquaredCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
14201    cout<<endl;
14202    exit(0); 
14203   }  
14204   if(!fIntFlowCorrelationsVsMHist[ci])
14205   {
14206    cout<<endl;
14207    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
14208    cout<<endl;
14209    exit(0); 
14210   }
14211   for(Int_t power=0;power<2;power++) 
14212   {
14213    if(!fIntFlowSumOfEventWeightsVsM[ci][power])
14214    {
14215     cout<<endl;
14216     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsVsM[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",ci,power)<<endl;
14217     cout<<endl;
14218     exit(0);   
14219    }
14220   } // end of for(Int_t power=0;power<2;power++) 
14221  } // end of for(Int_t ci=0;ci<=3;ci++) // correlation index
14222  for(Int_t i=0;i<6;i++)
14223  {
14224   if(!fIntFlowProductOfCorrelationsVsMPro[i])
14225   {
14226    cout<<endl;
14227    cout<<Form(" WARNING (QC): fIntFlowProductOfCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
14228    cout<<endl;
14229    exit(0); 
14230   }
14231   if(!fIntFlowSumOfProductOfEventWeightsVsM[i])
14232   {
14233    cout<<endl;
14234    cout<<Form(" WARNING (QC): fIntFlowSumOfProductOfEventWeightsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
14235    cout<<endl;
14236    exit(0); 
14237   }
14238   if(!fIntFlowCovariancesVsM[i])
14239   {
14240    cout<<endl;
14241    cout<<Form(" WARNING (QC): fIntFlowCovariancesVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
14242    cout<<endl;
14243    exit(0); 
14244   }
14245  } // end of for(Int_t i=0;i<6;i++) 
14246  if(!fIntFlowRebinnedInM)
14247  {
14248   cout<<endl;
14249   cout<<" WARNING (QC): fIntFlowRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14250   cout<<endl;
14251   exit(0); 
14252  }
14253  if(!fIntFlowQcumulantsRebinnedInM)
14254  {
14255   cout<<endl;
14256   cout<<" WARNING (QC): fIntFlowQcumulantsRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
14257   cout<<endl;
14258   exit(0); 
14259  }  
14260  
14261 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
14262
14263 //================================================================================================================================
14264
14265 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
14266 {
14267  // Check all pointers used in method Make(). // to be improved - check other pointers as well
14268  
14269  if(!fAvMultiplicity)
14270  {
14271   printf("\n WARNING (QC): fAvMultiplicity is NULL in CheckPointersUsedInMake() !!!!\n\n");
14272   exit(0);
14273  }
14274  if((fUsePhiWeights||fUsePtWeights||fUseEtaWeights||fUseTrackWeights) && !fIntFlowExtraCorrelationsPro) 
14275  {
14276   printf("\n WARNING (QC): fIntFlowExtraCorrelationsPro is NULL in CheckPointersUsedInMake() !!!!\n\n");
14277   exit(0); 
14278  } 
14279  // 2D:
14280  if(fCalculate2DDiffFlow)
14281  {
14282   for(Int_t t=0;t<2;t++) // type = RP or POI
14283   { 
14284    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
14285    {
14286     if(!f2DDiffFlowCorrelationsPro[t][rci])
14287     {
14288      printf("\n WARNING (QC): f2DDiffFlowCorrelationsPro[%i][%i] is NULL in CheckPointersUsedInMake() !!!!\n\n",t,rci);
14289      exit(0);     
14290     } // end of if(!f2DDiffFlowCorrelationsPro[t][rci])  
14291    } // end of for(Int_t rci=0;rci<4;rci++) // reduced correlation index
14292   } // end of for(Int_t t=0;t<2;t++)
14293  } // end of if(fCalculate2DDiffFlow)  
14294
14295 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
14296  
14297