]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx
fixes warnings
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowCommon / AliFlowAnalysisWithQCumulants.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  * 
14 **************************************************************************/
15
16 /********************************** 
17  * flow analysis with Q-cumulants * 
18  *                                * 
19  * author: Ante Bilandzic         * 
20  *        (abilandzic@gmail.com)  *
21  *********************************/ 
22
23 #define AliFlowAnalysisWithQCumulants_cxx
24
25 #include "Riostream.h"
26 #include "AliFlowCommonConstants.h"
27 #include "AliFlowCommonHist.h"
28 #include "AliFlowCommonHistResults.h"
29 #include "TChain.h"
30
31 #include "TFile.h"
32 #include "TList.h"
33 #include "TGraph.h"
34 #include "TParticle.h"
35 #include "TRandom3.h"
36 #include "TStyle.h"
37 #include "TProfile.h"
38 #include "TProfile2D.h" 
39 #include "TProfile3D.h"
40 #include "TMath.h"
41 #include "TArrow.h"
42 #include "TPaveLabel.h"
43 #include "TCanvas.h"
44 #include "AliFlowEventSimple.h"
45 #include "AliFlowTrackSimple.h"
46 #include "AliFlowAnalysisWithQCumulants.h"
47 #include "TArrayD.h"
48 #include "TRandom.h"
49 #include "TF1.h"
50
51 class TH1;
52 class TH2;
53 class TGraph;
54 class TPave;
55 class TLatex;
56 class TMarker;
57 class TRandom3;
58 class TObjArray;
59 class TList;
60 class TCanvas;
61 class TSystem;
62 class TROOT;
63 class AliFlowVector;
64 class TVector;
65
66
67 //================================================================================================================
68
69
70 ClassImp(AliFlowAnalysisWithQCumulants)
71
72 AliFlowAnalysisWithQCumulants::AliFlowAnalysisWithQCumulants(): 
73  // 0.) base:
74  fHistList(NULL),
75  // 1.) common:
76  fCommonHists(NULL),
77  fCommonHists2nd(NULL), 
78  fCommonHists4th(NULL),
79  fCommonHists6th(NULL),
80  fCommonHists8th(NULL),
81  fCommonHistsResults2nd(NULL),
82  fCommonHistsResults4th(NULL),
83  fCommonHistsResults6th(NULL),
84  fCommonHistsResults8th(NULL),
85  fnBinsPhi(0),
86  fPhiMin(0),
87  fPhiMax(0),
88  fPhiBinWidth(0),
89  fnBinsPt(0),
90  fPtMin(0),
91  fPtMax(0),
92  fPtBinWidth(0),
93  fnBinsEta(0),
94  fEtaMin(0),
95  fEtaMax(0),
96  fEtaBinWidth(0),
97  fHarmonic(2),
98  fAnalysisLabel(NULL),
99  // 2a.) particle weights:
100  fWeightsList(NULL),
101  fUsePhiWeights(kFALSE),
102  fUsePtWeights(kFALSE),
103  fUseEtaWeights(kFALSE),
104  fUseParticleWeights(NULL),
105  fPhiWeights(NULL),
106  fPtWeights(NULL),
107  fEtaWeights(NULL),
108  // 2b.) event weights:
109  fMultiplicityWeight(NULL),
110  // 3.) integrated flow:
111  fIntFlowList(NULL), 
112  fIntFlowProfiles(NULL),
113  fIntFlowResults(NULL),
114  fIntFlowFlags(NULL),
115  fApplyCorrectionForNUA(kTRUE),  
116  fApplyCorrectionForNUAVsM(kFALSE),
117  fnBinsMult(10000),
118  fMinMult(0.),  
119  fMaxMult(10000.), 
120  fPropagateErrorFromCorrelations(kFALSE), 
121  fCalculateCumulantsVsM(kTRUE), 
122  fMinimumBiasReferenceFlow(kTRUE), 
123  fReQ(NULL),
124  fImQ(NULL),
125  fSMpk(NULL),
126  fIntFlowCorrelationsEBE(NULL),
127  fIntFlowEventWeightsForCorrelationsEBE(NULL),
128  fIntFlowCorrelationsAllEBE(NULL),
129  fAvMultiplicity(NULL),
130  fIntFlowCorrelationsPro(NULL),
131  fIntFlowCorrelationsAllPro(NULL),
132  fIntFlowExtraCorrelationsPro(NULL),
133  fIntFlowProductOfCorrelationsPro(NULL),
134  fIntFlowProductOfCorrectionTermsForNUAPro(NULL),
135  fIntFlowCorrelationsHist(NULL),
136  fIntFlowCorrelationsAllHist(NULL),
137  fIntFlowCovariances(NULL),
138  fIntFlowSumOfProductOfEventWeights(NULL),
139  fIntFlowCovariancesNUA(NULL),
140  fIntFlowSumOfProductOfEventWeightsNUA(NULL),
141  fIntFlowQcumulants(NULL),
142  fIntFlowQcumulantsRebinnedInM(NULL),
143  fIntFlow(NULL),
144  fIntFlowRebinnedInM(NULL),
145  fIntFlowDetectorBias(NULL),
146  // 4.) differential flow:
147  fDiffFlowList(NULL),
148  fDiffFlowProfiles(NULL),
149  fDiffFlowResults(NULL),
150  fDiffFlowFlags(NULL),
151  fCalculate2DFlow(kFALSE),
152  // 5.) distributions:
153  fDistributionsList(NULL),
154  fDistributionsFlags(NULL),
155  fStoreDistributions(kFALSE),
156  // x.) debugging and cross-checking:
157  fNestedLoopsList(NULL),
158  fEvaluateIntFlowNestedLoops(kFALSE),
159  fEvaluateDiffFlowNestedLoops(kFALSE),
160  fMaxAllowedMultiplicity(10),
161  fEvaluateNestedLoops(NULL),
162  fIntFlowDirectCorrelations(NULL),
163  fIntFlowExtraDirectCorrelations(NULL),
164  fCrossCheckInPtBinNo(10),
165  fCrossCheckInEtaBinNo(20),
166  fNoOfParticlesInBin(NULL)
167  {
168   // constructor  
169   
170   // base list to hold all output objects:
171   fHistList = new TList();
172   fHistList->SetName("cobjQC");
173   fHistList->SetOwner(kTRUE);
174   
175   // list to hold histograms with phi, pt and eta weights:      
176   fWeightsList = new TList();
177   
178   // multiplicity weight:
179   fMultiplicityWeight = new TString("combinations");
180     
181   // analysis label;
182   fAnalysisLabel = new TString();
183       
184   // initialize all arrays:  
185   this->InitializeArraysForIntFlow();
186   this->InitializeArraysForDiffFlow();
187   this->InitializeArraysForDistributions();
188   this->InitializeArraysForNestedLoops();
189   
190  } // end of constructor
191  
192
193 //================================================================================================================  
194
195
196 AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
197 {
198  // destructor
199  
200  delete fHistList;
201
202 } // end of AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
203
204
205 //================================================================================================================
206
207
208 void AliFlowAnalysisWithQCumulants::Init()
209 {
210  // a) Cross check if the settings make sense before starting the QC adventure;
211  // b) Access all common constants;
212  // c) Book all objects;
213  // d) Store flags for integrated and differential flow;
214  // e) Store flags for distributions of corelations;
215  // f) Store harmonic which will be estimated.
216   
217  //save old value and prevent histograms from being added to directory
218  //to avoid name clashes in case multiple analaysis objects are used
219  //in an analysis
220  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
221  TH1::AddDirectory(kFALSE);
222  
223  // a) Cross check if the settings make sense before starting the QC adventure; 
224  this->CrossCheckSettings();
225  // b) Access all common constants:
226  this->AccessConstants();
227  // c) Book all objects:
228  this->BookAndFillWeightsHistograms();
229  this->BookAndNestAllLists();
230  this->BookCommonHistograms();
231  this->BookEverythingForIntegratedFlow(); 
232  this->BookEverythingForDifferentialFlow(); 
233  this->BookEverythingForDistributions();
234  this->BookEverythingForNestedLoops();
235  // d) Store flags for integrated and differential flow:
236  this->StoreIntFlowFlags();
237  this->StoreDiffFlowFlags();
238  // e) Store flags for distributions of corelations:
239  this->StoreFlagsForDistributions();
240  // f) Store harmonic which will be estimated:
241  this->StoreHarmonic();
242  
243  TH1::AddDirectory(oldHistAddStatus);
244 } // end of void AliFlowAnalysisWithQCumulants::Init()
245
246
247 //================================================================================================================
248
249
250 void AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
251 {
252  // Running over data only in this method.
253  
254  // a) Check all pointers used in this method;
255  // b) Define local variables;
256  // c) Fill the common control histograms and call the method to fill fAvMultiplicity;
257  // d) Loop over data and calculate e-b-e quantities;
258  // e) Call all the methods which calculate correlations for reference flow;
259  // f) Call all the methods which calculate correlations for differential flow;
260  // g) Distributions of correlations;
261  // h) Debugging and cross-checking (evaluate nested loops);
262  // i) Reset all event-by-event quantities. 
263  
264  // a) Check all pointers used in this method:
265  this->CheckPointersUsedInMake();
266  
267  // b) Define local variables:
268  Double_t dPhi = 0.; // azimuthal angle in the laboratory frame
269  Double_t dPt  = 0.; // transverse momentum
270  Double_t dEta = 0.; // pseudorapidity
271  Double_t wPhi = 1.; // phi weight
272  Double_t wPt  = 1.; // pt weight
273  Double_t wEta = 1.; // eta weight
274  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
275   
276  // c) Fill the common control histograms and call the method to fill fAvMultiplicity:
277  this->FillCommonControlHistograms(anEvent);                                                               
278  this->FillAverageMultiplicities(nRP);                                                                  
279                                                                                                                                                                                                                                                                                         
280  // d) Loop over data and calculate e-b-e quantities:
281  Int_t nPrim = anEvent->NumberOfTracks();  // nPrim = total number of primary tracks, i.e. nPrim = nRP + nPOI where:
282                                            // nRP   = # of particles used to determine the reaction plane;
283                                            // nPOI  = # of particles of interest for a detailed flow analysis;
284  
285  AliFlowTrackSimple *aftsTrack = NULL;
286  
287  for(Int_t i=0;i<nPrim;i++) 
288  { 
289   aftsTrack=anEvent->GetTrack(i);
290   if(aftsTrack)
291   {
292    if(!(aftsTrack->InRPSelection() || aftsTrack->InPOISelection())) continue; // consider only tracks which are RPs or POIs
293    Int_t n = fHarmonic; // shortcut for the harmonic
294    if(aftsTrack->InRPSelection()) // RP condition:
295    {    
296     dPhi = aftsTrack->Phi();
297     dPt  = aftsTrack->Pt();
298     dEta = aftsTrack->Eta();
299     if(fUsePhiWeights && fPhiWeights && fnBinsPhi) // determine phi weight for this particle:
300     {
301      wPhi = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*fnBinsPhi/TMath::TwoPi())));
302     }
303     if(fUsePtWeights && fPtWeights && fnBinsPt) // determine pt weight for this particle:
304     {
305      wPt = fPtWeights->GetBinContent(1+(Int_t)(TMath::Floor((dPt-fPtMin)/fPtBinWidth))); 
306     }              
307     if(fUseEtaWeights && fEtaWeights && fEtaBinWidth) // determine eta weight for this particle: 
308     {
309      wEta = fEtaWeights->GetBinContent(1+(Int_t)(TMath::Floor((dEta-fEtaMin)/fEtaBinWidth))); 
310     } 
311       
312     // integrated flow: 
313     // calculate Re[Q_{m*n,k}] and Im[Q_{m*n,k}], m = 1,2,3,4, for this event:
314     for(Int_t m=0;m<4;m++)
315     {
316      for(Int_t k=0;k<9;k++)
317      {
318       (*fReQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1)*n*dPhi); 
319       (*fImQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1)*n*dPhi); 
320      } 
321     }
322     // calculate S^{M}_{p,k} for this event 
323     // Remark: final calculation of S^{M}_{p,k} follows after the loop over data bellow:
324     for(Int_t p=0;p<8;p++)
325     {
326      for(Int_t k=0;k<9;k++)
327      {     
328       (*fSMpk)(p,k)+=pow(wPhi*wPt*wEta,k);
329      }
330     } 
331     
332     // differential flow:
333     // 1D (pt):
334     // (r_{m*m,k}(pt)): 
335     for(Int_t m=0;m<4;m++)
336     {
337      for(Int_t k=0;k<9;k++)
338      {
339       fReRPQ1dEBE[0][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
340       fImRPQ1dEBE[0][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
341      }
342     }
343            
344     // s_{k}(pt) for RPs // to be improved (clarified)
345     // Remark: final calculation of s_{p,k}(pt) follows after the loop over data bellow:
346     for(Int_t k=0;k<9;k++)
347     {
348      fs1dEBE[0][0][k]->Fill(dPt,pow(wPhi*wPt*wEta,k),1.);
349     }
350     // 1D (eta):
351     // (r_{m*m,k}(eta)): 
352     for(Int_t m=0;m<4;m++)
353     {
354      for(Int_t k=0;k<9;k++)
355      {
356       fReRPQ1dEBE[0][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
357       fImRPQ1dEBE[0][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
358      }
359     }   
360     // s_{k}(eta) for RPs // to be improved (clarified)
361     // Remark: final calculation of s_{p,k}(eta) follows after the loop over data bellow:
362     for(Int_t k=0;k<9;k++)
363     {
364      fs1dEBE[0][1][k]->Fill(dEta,pow(wPhi*wPt*wEta,k),1.);
365     }
366     
367     
368     
369     /*
370     // 2D (pt,eta):
371     if(fCalculate2DFlow)
372     {
373      // (r_{m*m,k}(pt,eta)): 
374      for(Int_t m=0;m<4;m++)
375      {
376       for(Int_t k=0;k<9;k++)
377       {
378        fReRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
379        fImRPQ2dEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
380       }
381      }    
382      // s_{k}(pt,eta) for RPs // to be improved (clarified)
383      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
384      for(Int_t k=0;k<9;k++)
385      {
386       fs2dEBE[0][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
387      }
388     } // end of if(fCalculate2DFlow)  
389     */ 
390     
391       
392      
393     if(aftsTrack->InPOISelection())
394     {
395      // 1D (pt): 
396      // (q_{m*m,k}(pt)): 
397      for(Int_t m=0;m<4;m++)
398      {
399       for(Int_t k=0;k<9;k++)
400       {
401        fReRPQ1dEBE[2][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
402        fImRPQ1dEBE[2][0][m][k]->Fill(dPt,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
403       }
404      } 
405      // s_{k}(pt) for RP&&POIs // to be improved (clarified)
406      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
407      for(Int_t k=0;k<9;k++)
408      {
409       fs1dEBE[2][0][k]->Fill(dPt,pow(wPhi*wPt*wEta,k),1.);
410      }
411      // 1D (eta): 
412      // (q_{m*m,k}(eta)): 
413      for(Int_t m=0;m<4;m++)
414      {
415       for(Int_t k=0;k<9;k++)
416       {
417        fReRPQ1dEBE[2][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
418        fImRPQ1dEBE[2][1][m][k]->Fill(dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
419       }
420      } 
421      // s_{k}(eta) for RP&&POIs // to be improved (clarified)
422      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
423      for(Int_t k=0;k<9;k++)
424      {
425       fs1dEBE[2][1][k]->Fill(dEta,pow(wPhi*wPt*wEta,k),1.);
426      }
427      
428      /*
429      // 2D (pt,eta) 
430      if(fCalculate2DFlow)
431      {
432       // (q_{m*m,k}(pt,eta)): 
433       for(Int_t m=0;m<4;m++)
434       {
435        for(Int_t k=0;k<9;k++)
436        {
437         fReRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
438         fImRPQ2dEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
439        }
440       } 
441       // s_{k}(pt,eta) for RP&&POIs // to be improved (clarified)
442       // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
443       for(Int_t k=0;k<9;k++)
444       {
445        fs2dEBE[2][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
446       }
447      } // end of if(fCalculate2DFlow) 
448      */
449       
450     } // end of if(aftsTrack->InPOISelection())
451     
452
453      
454    } // end of if(pTrack->InRPSelection())
455
456   
457   
458    if(aftsTrack->InPOISelection())
459    {
460     dPhi = aftsTrack->Phi();
461     dPt  = aftsTrack->Pt();
462     dEta = aftsTrack->Eta();
463     
464     // 1D (pt)
465     // p_n(m*n,0):   
466     for(Int_t m=0;m<4;m++)
467     {
468      fReRPQ1dEBE[1][0][m][0]->Fill(dPt,TMath::Cos((m+1.)*n*dPhi),1.);
469      fImRPQ1dEBE[1][0][m][0]->Fill(dPt,TMath::Sin((m+1.)*n*dPhi),1.);
470     }
471     // 1D (eta)
472     // p_n(m*n,0):   
473     for(Int_t m=0;m<4;m++)
474     {
475      fReRPQ1dEBE[1][1][m][0]->Fill(dEta,TMath::Cos((m+1.)*n*dPhi),1.);
476      fImRPQ1dEBE[1][1][m][0]->Fill(dEta,TMath::Sin((m+1.)*n*dPhi),1.);
477     }
478     
479     
480     /*
481     // 2D (pt,eta):
482     if(fCalculate2DFlow)
483     {      
484      // p_n(m*n,0):   
485      for(Int_t m=0;m<4;m++)
486      {
487       fReRPQ2dEBE[1][m][0]->Fill(dPt,dEta,TMath::Cos((m+1.)*n*dPhi),1.);
488       fImRPQ2dEBE[1][m][0]->Fill(dPt,dEta,TMath::Sin((m+1.)*n*dPhi),1.);
489      }
490     } // end of if(fCalculate2DFlow)  
491     */
492     
493     
494    } // end of if(pTrack->InPOISelection() )   
495  
496   
497   } else // to if(aftsTrack)
498     {
499      cout<<endl;
500      cout<<" WARNING: no particle! (i.e. aftsTrack is a NULL pointer in AFAWQC::Make().)"<<endl;
501      cout<<endl;       
502     }
503  } // end of for(Int_t i=0;i<nPrim;i++) 
504
505  // calculate the final expressions for S^{M}_{p,k}:
506  for(Int_t p=0;p<8;p++)
507  {
508   for(Int_t k=0;k<9;k++)
509   {
510    (*fSMpk)(p,k)=pow((*fSMpk)(p,k),p+1);
511   }  
512  } 
513  
514  // e) Call all the methods which calculate correlations for reference flow:
515  if(!fEvaluateIntFlowNestedLoops)
516  {
517   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
518   {
519    if(nRP>1) this->CalculateIntFlowCorrelations(); // without using particle weights
520   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
521     {
522      if(nRP>1) this->CalculateIntFlowCorrelationsUsingParticleWeights(); // with using particle weights   
523     } 
524        
525   if(nRP>3) this->CalculateIntFlowProductOfCorrelations();
526   if(nRP>1) this->CalculateIntFlowSumOfEventWeights();
527   if(nRP>1) this->CalculateIntFlowSumOfProductOfEventWeights();
528   if(fApplyCorrectionForNUA)
529   {
530    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
531    {
532     if(nRP>0) this->CalculateIntFlowCorrectionsForNUASinTerms();
533     if(nRP>0) this->CalculateIntFlowCorrectionsForNUACosTerms();
534    } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
535      {
536       if(nRP>0) this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights();
537       if(nRP>0) this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights();     
538      }  
539      
540    if(nRP>0) this->CalculateIntFlowProductOfCorrectionTermsForNUA();     
541    if(nRP>0) this->CalculateIntFlowSumOfEventWeightsNUA();     
542    if(nRP>0) this->CalculateIntFlowSumOfProductOfEventWeightsNUA();     
543   } // end of if(fApplyCorrectionForNUA)
544  } // end of if(!fEvaluateIntFlowNestedLoops)
545
546  // f) Call all the methods which calculate correlations for differential flow:
547  if(!fEvaluateDiffFlowNestedLoops)
548  {
549   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
550   {
551    // without using particle weights:
552    this->CalculateDiffFlowCorrelations("RP","Pt"); 
553    this->CalculateDiffFlowCorrelations("RP","Eta");
554    this->CalculateDiffFlowCorrelations("POI","Pt");
555    this->CalculateDiffFlowCorrelations("POI","Eta");
556    if(fApplyCorrectionForNUA)
557    {
558     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
559     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");
560     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
561     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");
562     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
563     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");
564     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
565     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");   
566    } // end of if(fApplyCorrectionForNUA)  
567   } else // to if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
568     {
569      // with using particle weights:   
570      this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
571      this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta"); 
572      this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
573      this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta"); 
574      if(fApplyCorrectionForNUA)
575      {
576       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
577       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");
578       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
579       this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");
580       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
581       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");
582       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
583       this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");   
584      } // end of if(fApplyCorrectionForNUA)  
585     } 
586     
587   // whether or not using particle weights the following is calculated in the same way:  
588   this->CalculateDiffFlowProductOfCorrelations("RP","Pt");
589   this->CalculateDiffFlowProductOfCorrelations("RP","Eta");
590   this->CalculateDiffFlowProductOfCorrelations("POI","Pt");
591   this->CalculateDiffFlowProductOfCorrelations("POI","Eta");
592   this->CalculateDiffFlowSumOfEventWeights("RP","Pt");
593   this->CalculateDiffFlowSumOfEventWeights("RP","Eta");
594   this->CalculateDiffFlowSumOfEventWeights("POI","Pt");
595   this->CalculateDiffFlowSumOfEventWeights("POI","Eta");
596   this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Pt");
597   this->CalculateDiffFlowSumOfProductOfEventWeights("RP","Eta");
598   this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Pt");
599   this->CalculateDiffFlowSumOfProductOfEventWeights("POI","Eta");   
600  } // end of if(!fEvaluateDiffFlowNestedLoops)
601
602
603    
604   // with weights:
605   // ... 
606   
607   /*
608   // 2D differential flow
609   if(fCalculate2DFlow)
610   {
611    // without weights:
612    if(nRP>1) this->CalculateCorrelationsForDifferentialFlow2D("RP");
613    if(nRP>1) this->CalculateCorrelationsForDifferentialFlow2D("POI");
614   
615    // with weights:
616    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
617    {
618     if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow2D("RP");
619     if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow2D("POI");
620    } 
621   } // end of if(fCalculate2DFlow)
622   */
623   
624  // g) Distributions of correlations;
625  if(fStoreDistributions)
626  {
627   this->StoreDistributionsOfCorrelations();
628  }
629   
630  // h) Debugging and cross-checking (evaluate nested loops):
631  //  h1) cross-checking results for integrated flow:
632  if(fEvaluateIntFlowNestedLoops)
633  {
634   if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10 
635   {
636    // without using particle weights:
637    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
638    {
639     // correlations:
640     this->CalculateIntFlowCorrelations(); // from Q-vectors
641     this->EvaluateIntFlowCorrelationsWithNestedLoops(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
642     // correction for non-uniform acceptance:
643     this->CalculateIntFlowCorrectionsForNUASinTerms(); // from Q-vectors (sin terms)
644     this->CalculateIntFlowCorrectionsForNUACosTerms(); // from Q-vectors (cos terms)
645     this->EvaluateIntFlowCorrectionsForNUAWithNestedLoops(anEvent); // from nested loops (both sin and cos terms)
646    }
647    // using particle weights:
648    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
649    {
650     // correlations:
651     this->CalculateIntFlowCorrelationsUsingParticleWeights(); // from Q-vectors
652     this->EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (to be improved: do I have to pass here anEvent or not?)
653     // correction for non-uniform acceptance:
654     this->CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights(); // from Q-vectors (sin terms)
655     this->CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights(); // from Q-vectors (cos terms)
656     this->EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(anEvent); // from nested loops (both sin and cos terms)   
657    }
658   } else if (nPrim>fMaxAllowedMultiplicity) // to if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity)
659     {
660      cout<<endl;
661      cout<<"Skipping the event because multiplicity is "<<nPrim<<". Too high to evaluate nested loops!"<<endl;
662     } else
663       {
664        cout<<endl;
665        cout<<"Skipping the event because multiplicity is "<<nPrim<<"."<<endl;      
666       } 
667  } // end of if(fEvaluateIntFlowNestedLoops) 
668  
669  //  h2) cross-checking results for differential flow:
670  if(fEvaluateDiffFlowNestedLoops)
671  {
672   if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
673   {
674    // without using particle weights:
675    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
676    {
677     // reduced correlations:
678     // Q-vectors:
679     this->CalculateDiffFlowCorrelations("RP","Pt");
680     this->CalculateDiffFlowCorrelations("RP","Eta");
681     this->CalculateDiffFlowCorrelations("POI","Pt");
682     this->CalculateDiffFlowCorrelations("POI","Eta");
683     // nested loops:
684     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Pt"); 
685     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"RP","Eta"); 
686     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Pt"); 
687     this->EvaluateDiffFlowCorrelationsWithNestedLoops(anEvent,"POI","Eta"); 
688     // reduced corrections for non-uniform acceptance:
689     // Q-vectors:
690     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Pt");
691     this->CalculateDiffFlowCorrectionsForNUASinTerms("RP","Eta");
692     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Pt");
693     this->CalculateDiffFlowCorrectionsForNUASinTerms("POI","Eta");
694     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Pt");
695     this->CalculateDiffFlowCorrectionsForNUACosTerms("RP","Eta");
696     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Pt");
697     this->CalculateDiffFlowCorrectionsForNUACosTerms("POI","Eta");
698     // nested loops:
699     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Pt");
700     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"RP","Eta");
701     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Pt"); 
702     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(anEvent,"POI","Eta"); 
703    } // end of if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
704    // using particle weights:
705    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
706    {
707     this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Pt"); 
708     this->CalculateDiffFlowCorrelationsUsingParticleWeights("RP","Eta"); 
709     this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Pt"); 
710     this->CalculateDiffFlowCorrelationsUsingParticleWeights("POI","Eta"); 
711     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Pt");
712     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("RP","Eta");
713     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Pt");
714     this->CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights("POI","Eta");
715     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Pt");
716     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("RP","Eta");
717     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Pt");
718     this->CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights("POI","Eta");
719     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
720     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta");
721     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
722     this->EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta");   
723     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Pt"); 
724     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"RP","Eta"); 
725     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Pt"); 
726     this->EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(anEvent,"POI","Eta"); 
727    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
728   } // end of if(nPrim>0 && nPrim<=fMaxAllowedMultiplicity) // by default fMaxAllowedMultiplicity = 10
729  } // end of if(fEvaluateDiffFlowNestedLoops) 
730  
731  // i) Reset all event-by-event quantities. 
732  this->ResetEventByEventQuantities();
733  
734 } // end of AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
735
736 //================================================================================================================================
737
738 void AliFlowAnalysisWithQCumulants::Finish()
739 {
740  // Calculate the final results.
741  
742  // a) Check all pointers used in this method;
743  // b) Acces the constants;
744  // c) Access the flags;
745  // d) Calculate the final results for reference flow (without/with weights);
746  // e) Correct the results for reference flow (without/with weights) for effects of non-uniform acceptance (NUA);
747  // f) Store results for reference flow in AliFlowCommonHistResults and print them on the screen;
748  // g) Calculate the final results for differential flow (without/with weights);
749  // h) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA);
750  // i) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults;
751  // j) Store results for differential flow in AliFlowCommonHistResults;
752  // k) Print the final results for integrated flow (RP/POI) on the screen; 
753  // l) Cross-checking: Results from Q-vectors vs results from nested loops.
754  
755  // a) Check all pointers used in this method:
756  this->CheckPointersUsedInFinish();
757   
758  // b) Acces the constants:
759  this->AccessConstants();          
760  
761  if(fCommonHists && fCommonHists->GetHarmonic()) // to be improved (moved somewhere else)
762  {
763   fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1);
764  } 
765  
766  // c) Access the flags: // to be improved (implement a method for this)
767  fUsePhiWeights = (Bool_t)fUseParticleWeights->GetBinContent(1); 
768  fUsePtWeights = (Bool_t)fUseParticleWeights->GetBinContent(2); 
769  fUseEtaWeights = (Bool_t)fUseParticleWeights->GetBinContent(3);  
770  fApplyCorrectionForNUA = (Bool_t)fIntFlowFlags->GetBinContent(3); 
771  fPrintFinalResults[0] = (Bool_t)fIntFlowFlags->GetBinContent(4);
772  fPrintFinalResults[1] = (Bool_t)fIntFlowFlags->GetBinContent(5);
773  fPrintFinalResults[2] = (Bool_t)fIntFlowFlags->GetBinContent(6);
774  fPrintFinalResults[3] = (Bool_t)fIntFlowFlags->GetBinContent(7);
775  fApplyCorrectionForNUAVsM = (Bool_t)fIntFlowFlags->GetBinContent(8);  
776  fPropagateErrorFromCorrelations = (Bool_t)fIntFlowFlags->GetBinContent(9);  
777  fCalculateCumulantsVsM = (Bool_t)fIntFlowFlags->GetBinContent(10); 
778  fMinimumBiasReferenceFlow = (Bool_t)fIntFlowFlags->GetBinContent(11); 
779  fEvaluateIntFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(1);
780  fEvaluateDiffFlowNestedLoops = (Bool_t)fEvaluateNestedLoops->GetBinContent(2); 
781  fCrossCheckInPtBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(3);
782  fCrossCheckInEtaBinNo = (Int_t)fEvaluateNestedLoops->GetBinContent(4); 
783     
784  // d) Calculate the final results for reference flow (without/with weights):
785  this->FinalizeCorrelationsIntFlow();
786  this->CalculateCovariancesIntFlow();
787  this->CalculateCumulantsIntFlow();
788  this->CalculateIntFlow(); 
789
790  // e) Correct the results for reference flow (without/with weights) for effects of non-uniform acceptance (NUA):
791  if(fApplyCorrectionForNUA) 
792  {
793   this->FinalizeCorrectionTermsForNUAIntFlow();
794   // this->CalculateCovariancesNUAIntFlow(); // to be improved (enabled eventually)
795   this->CalculateQcumulantsCorrectedForNUAIntFlow();   
796   this->CalculateIntFlowCorrectedForNUA(); 
797   this->CalculateDetectorEffectsForTrueCorrelations();
798  }
799   
800  // f) Store results for reference flow in AliFlowCommonHistResults and print them on the screen:
801  this->FillCommonHistResultsIntFlow();  
802  if(fPrintFinalResults[0]){this->PrintFinalResultsForIntegratedFlow("RF");}
803  if(fPrintFinalResults[3] && fCalculateCumulantsVsM){this->PrintFinalResultsForIntegratedFlow("RF, rebinned in M");}
804  
805  // g) Calculate the final results for differential flow (without/with weights):
806  this->FinalizeReducedCorrelations("RP","Pt"); 
807  this->FinalizeReducedCorrelations("RP","Eta"); 
808  this->FinalizeReducedCorrelations("POI","Pt"); 
809  this->FinalizeReducedCorrelations("POI","Eta");
810  this->CalculateDiffFlowCovariances("RP","Pt");
811  this->CalculateDiffFlowCovariances("RP","Eta");
812  this->CalculateDiffFlowCovariances("POI","Pt");
813  this->CalculateDiffFlowCovariances("POI","Eta");
814  this->CalculateDiffFlowCumulants("RP","Pt");
815  this->CalculateDiffFlowCumulants("RP","Eta");
816  this->CalculateDiffFlowCumulants("POI","Pt");
817  this->CalculateDiffFlowCumulants("POI","Eta");
818  this->CalculateDiffFlow("RP","Pt");
819  this->CalculateDiffFlow("RP","Eta");
820  this->CalculateDiffFlow("POI","Pt");
821  this->CalculateDiffFlow("POI","Eta");
822  
823  // h) Correct the results for differential flow (without/with weights) for effects of non-uniform acceptance (NUA):
824  if(fApplyCorrectionForNUA)
825  {
826   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Pt");
827   this->FinalizeCorrectionTermsForNUADiffFlow("RP","Eta");
828   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Pt");
829   this->FinalizeCorrectionTermsForNUADiffFlow("POI","Eta");      
830   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Pt");   
831   this->CalculateDiffFlowCumulantsCorrectedForNUA("RP","Eta");   
832   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Pt");   
833   this->CalculateDiffFlowCumulantsCorrectedForNUA("POI","Eta");  
834   this->CalculateDiffFlowCorrectedForNUA("RP","Pt"); 
835   this->CalculateDiffFlowCorrectedForNUA("RP","Eta"); 
836   this->CalculateDiffFlowCorrectedForNUA("POI","Pt"); 
837   this->CalculateDiffFlowCorrectedForNUA("POI","Eta"); 
838  }
839  
840  // i) Calculate the final results for integrated flow (RP/POI) and store in AliFlowCommonHistResults:
841  this->CalculateFinalResultsForRPandPOIIntegratedFlow("RP");
842  this->CalculateFinalResultsForRPandPOIIntegratedFlow("POI");
843
844  // j) Store results for differential flow in AliFlowCommonHistResults:
845  this->FillCommonHistResultsDiffFlow("RP");
846  this->FillCommonHistResultsDiffFlow("POI");
847
848  // k) Print the final results for integrated flow (RP/POI) on the screen:
849  if(fPrintFinalResults[1]){this->PrintFinalResultsForIntegratedFlow("RP");} 
850  if(fPrintFinalResults[2]){this->PrintFinalResultsForIntegratedFlow("POI");}
851   
852  // l) Cross-checking: Results from Q-vectors vs results from nested loops:
853  //  l1) Reference flow:
854  if(fEvaluateIntFlowNestedLoops)
855  {
856   this->CrossCheckIntFlowCorrelations();
857   this->CrossCheckIntFlowCorrectionTermsForNUA(); 
858   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) this->CrossCheckIntFlowExtraCorrelations();     
859  } // end of if(fEvaluateIntFlowNestedLoops)  
860  
861  //  l2) Differential flow: 
862  if(fEvaluateDiffFlowNestedLoops) 
863  {
864   // Correlations:
865   this->PrintNumberOfParticlesInSelectedBin();
866   this->CrossCheckDiffFlowCorrelations("RP","Pt");  
867   this->CrossCheckDiffFlowCorrelations("RP","Eta"); 
868   this->CrossCheckDiffFlowCorrelations("POI","Pt");  
869   this->CrossCheckDiffFlowCorrelations("POI","Eta");
870   // Correction terms for non-uniform acceptance:
871   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Pt");      
872   this->CrossCheckDiffFlowCorrectionTermsForNUA("RP","Eta");       
873   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Pt");      
874   this->CrossCheckDiffFlowCorrectionTermsForNUA("POI","Eta");       
875  } // end of if(fEvaluateDiffFlowNestedLoops)
876                                                                                                                                                                                                                                                                                                                                    
877 } // end of AliFlowAnalysisWithQCumulants::Finish()
878
879 //================================================================================================================================
880
881 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
882 {
883  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (cos terms)
884  
885  // multiplicity:
886  Double_t dMult = (*fSMpk)(0,0);
887  
888  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
889  Double_t dReQ1n = (*fReQ)(0,0);
890  Double_t dReQ2n = (*fReQ)(1,0);
891  //Double_t dReQ3n = (*fReQ)(2,0);
892  //Double_t dReQ4n = (*fReQ)(3,0);
893  Double_t dImQ1n = (*fImQ)(0,0);
894  Double_t dImQ2n = (*fImQ)(1,0);
895  //Double_t dImQ3n = (*fImQ)(2,0);
896  //Double_t dImQ4n = (*fImQ)(3,0);
897         
898  //                                  *************************************************************
899  //                                  **** corrections for non-uniform acceptance (cos terms): ****
900  //                                  *************************************************************
901  //
902  // Remark 1: corrections for non-uniform acceptance (cos terms) calculated with non-weighted Q-vectors 
903  //           are stored in 1D profile fQCorrectionsCos.
904  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
905  // --------------------------------------------------------------------------------------------------------------------
906  // 1st bin: <<cos(n*(phi1))>> = cosP1n
907  // 2nd bin: <<cos(n*(phi1+phi2))>> = cosP1nP1n
908  // 3rd bin: <<cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1n
909  // 4th bin: <<cos(n*(2phi1-phi2))>> = cosP2nM1n
910  // --------------------------------------------------------------------------------------------------------------------
911   
912  // 1-particle:
913  Double_t cosP1n = 0.; // <<cos(n*(phi1))>>
914    
915  if(dMult>0)
916  {
917   cosP1n = dReQ1n/dMult; 
918   
919   // average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
920   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1n);
921   // event weights for NUA terms:
922   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(1,dMult);
923   
924   // final average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
925   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1n,dMult);  
926   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][0]->Fill(dMult+0.5,cosP1n,dMult);}    
927  } 
928  
929  // 2-particle:
930  Double_t cosP1nP1n = 0.; // <<cos(n*(phi1+phi2))>>
931  Double_t cosP2nM1n = 0.; // <<cos(n*(2phi1-phi2))>>
932  
933  if(dMult>1)
934  {
935   cosP1nP1n = (pow(dReQ1n,2)-pow(dImQ1n,2)-dReQ2n)/(dMult*(dMult-1)); 
936   cosP2nM1n = (dReQ2n*dReQ1n+dImQ2n*dImQ1n-dReQ1n)/(dMult*(dMult-1)); 
937   
938   // average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
939   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1n);
940   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(4,cosP2nM1n);
941   // event weights for NUA terms:
942   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(2,dMult*(dMult-1));
943   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(4,dMult*(dMult-1));
944       
945   // final average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
946   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1n,dMult*(dMult-1));  
947   fIntFlowCorrectionTermsForNUAPro[1]->Fill(3.5,cosP2nM1n,dMult*(dMult-1));
948   if(fCalculateCumulantsVsM)
949   {
950    fIntFlowCorrectionTermsForNUAVsMPro[1][1]->Fill(dMult+0.5,cosP1nP1n,dMult*(dMult-1));  
951    fIntFlowCorrectionTermsForNUAVsMPro[1][3]->Fill(dMult+0.5,cosP2nM1n,dMult*(dMult-1));
952   }
953  } 
954  
955  // 3-particle:
956  Double_t cosP1nM1nM1n = 0.; // <<cos(n*(phi1-phi2-phi3))>>
957  
958  if(dMult>2)
959  {
960   cosP1nM1nM1n = (dReQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))-dReQ1n*dReQ2n-dImQ1n*dImQ2n-2.*(dMult-1)*dReQ1n)
961                / (dMult*(dMult-1)*(dMult-2)); 
962   
963   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
964   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1n);
965   // event weights for NUA terms:
966   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
967   
968   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
969   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
970   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[1][2]->Fill(dMult+0.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
971  } 
972  
973 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTerms()
974
975
976 //================================================================================================================================
977
978
979 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
980 {
981  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
982  
983  // multiplicity:
984  Double_t dMult = (*fSMpk)(0,0);
985  
986  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
987  Double_t dReQ1n = (*fReQ)(0,0);
988  Double_t dReQ2n = (*fReQ)(1,0);
989  //Double_t dReQ3n = (*fReQ)(2,0);
990  //Double_t dReQ4n = (*fReQ)(3,0);
991  Double_t dImQ1n = (*fImQ)(0,0);
992  Double_t dImQ2n = (*fImQ)(1,0);
993  //Double_t dImQ3n = (*fImQ)(2,0);
994  //Double_t dImQ4n = (*fImQ)(3,0);
995         
996  //                                  *************************************************************
997  //                                  **** corrections for non-uniform acceptance (sin terms): ****
998  //                                  *************************************************************
999  //
1000  // Remark 1: corrections for non-uniform acceptance (sin terms) calculated with non-weighted Q-vectors 
1001  //           are stored in 1D profile fQCorrectionsSin.
1002  // Remark 2: binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
1003  // --------------------------------------------------------------------------------------------------------------------
1004  // 1st bin: <<sin(n*(phi1))>> = sinP1n
1005  // 2nd bin: <<sin(n*(phi1+phi2))>> = sinP1nP1n
1006  // 3rd bin: <<sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1n
1007  // 4th bin: <<sin(n*(2phi1-phi2))>> = sinP2nM1n
1008  // --------------------------------------------------------------------------------------------------------------------
1009  
1010  // 1-particle:
1011  Double_t sinP1n = 0.; // <sin(n*(phi1))>
1012  
1013  if(dMult>0)
1014  {
1015   sinP1n = dImQ1n/dMult; 
1016      
1017   // average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
1018   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1n);  
1019   // event weights for NUA terms:
1020   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(1,dMult);
1021   
1022   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
1023   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1n,dMult);  
1024   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][0]->Fill(dMult+0.5,sinP1n,dMult);} 
1025  } 
1026  
1027  // 2-particle:
1028  Double_t sinP1nP1n = 0.; // <<sin(n*(phi1+phi2))>>
1029  Double_t sinP2nM1n = 0.; // <<sin(n*(2phi1-phi2))>>
1030  if(dMult>1)
1031  {
1032   sinP1nP1n = (2.*dReQ1n*dImQ1n-dImQ2n)/(dMult*(dMult-1)); 
1033   sinP2nM1n = (dImQ2n*dReQ1n-dReQ2n*dImQ1n-dImQ1n)/(dMult*(dMult-1)); 
1034      
1035   // average non-weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
1036   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1n);
1037   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(4,sinP2nM1n);
1038   // event weights for NUA terms:
1039   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(2,dMult*(dMult-1));
1040   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(4,dMult*(dMult-1));
1041   
1042   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
1043   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1n,dMult*(dMult-1));  
1044   fIntFlowCorrectionTermsForNUAPro[0]->Fill(3.5,sinP2nM1n,dMult*(dMult-1));  
1045   if(fCalculateCumulantsVsM)
1046   {
1047    fIntFlowCorrectionTermsForNUAVsMPro[0][1]->Fill(dMult+0.5,sinP1nP1n,dMult*(dMult-1));  
1048    fIntFlowCorrectionTermsForNUAVsMPro[0][3]->Fill(dMult+0.5,sinP2nM1n,dMult*(dMult-1));    
1049   }
1050  } 
1051  
1052  // 3-particle:
1053  Double_t sinP1nM1nM1n = 0.; // <<sin(n*(phi1-phi2-phi3))>>
1054  
1055  if(dMult>2)
1056  {
1057   sinP1nM1nM1n = (-dImQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))+dReQ1n*dImQ2n-dImQ1n*dReQ2n+2.*(dMult-1)*dImQ1n)
1058                / (dMult*(dMult-1)*(dMult-2)); 
1059   
1060   // average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
1061   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1n);
1062   // event weights for NUA terms:
1063   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->SetBinContent(3,dMult*(dMult-1)*(dMult-2));
1064   
1065   // final average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
1066   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));
1067   if(fCalculateCumulantsVsM){fIntFlowCorrectionTermsForNUAVsMPro[0][2]->Fill(dMult+0.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));}  
1068  } 
1069  
1070 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTerms()
1071
1072
1073 //================================================================================================================================
1074
1075
1076 void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1077 {
1078  // a) Get pointers for common control and common result histograms and profiles.
1079  // b) Get pointers for histograms with particle weights.
1080  // c) Get pointers for histograms and profiles relevant for integrated flow.
1081  // d) Get pointers for histograms and profiles relevant for differental flow.
1082  // e) Get pointers for histograms and profiles holding results obtained with nested loops.
1083  
1084  if(outputListHistos)
1085  {      
1086   this->SetHistList(outputListHistos);
1087   if(!fHistList)
1088   {
1089    cout<<endl;
1090    cout<<" WARNING (QC): fHistList is NULL in AFAWQC::GOH() !!!!"<<endl;
1091    cout<<endl;
1092    exit(0);
1093   }
1094   this->GetPointersForCommonHistograms(); 
1095   this->GetPointersForParticleWeightsHistograms(); 
1096   this->GetPointersForIntFlowHistograms();
1097   this->GetPointersForDiffFlowHistograms(); 
1098   this->GetPointersForNestedLoopsHistograms(); 
1099  } else 
1100    {
1101     cout<<endl;
1102     cout<<" WARNING (QC): outputListHistos is NULL in AFAWQC::GOH() !!!!"<<endl;
1103     cout<<endl;
1104     exit(0);
1105    }
1106    
1107 } // end of void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1108
1109
1110 //================================================================================================================================
1111
1112
1113 TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta) const
1114 {
1115  // project 2D profile onto pt axis to get 1D profile
1116  
1117  Int_t nBinsPt   = profilePtEta->GetNbinsX();
1118  Double_t dPtMin = (profilePtEta->GetXaxis())->GetXmin();
1119  Double_t dPtMax = (profilePtEta->GetXaxis())->GetXmax();
1120  
1121  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1122  
1123  TProfile *profilePt = new TProfile("","",nBinsPt,dPtMin,dPtMax); 
1124  
1125  for(Int_t p=1;p<=nBinsPt;p++)
1126  {
1127   Double_t contentPt = 0.;
1128   Double_t entryPt = 0.;
1129   Double_t spreadPt = 0.;
1130   Double_t sum1 = 0.;
1131   Double_t sum2 = 0.;
1132   Double_t sum3 = 0.;
1133   for(Int_t e=1;e<=nBinsEta;e++)
1134   {
1135    contentPt += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1136               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1137    entryPt   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1138    
1139    sum1 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1140          * (pow(profilePtEta->GetBinError(profilePtEta->GetBin(p,e)),2.)
1141             + pow(profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)),2.)); 
1142    sum2 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1143    sum3 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
1144          * (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)));            
1145   }
1146   if(sum2>0. && sum1/sum2-pow(sum3/sum2,2.) > 0.)
1147   {
1148    spreadPt = pow(sum1/sum2-pow(sum3/sum2,2.),0.5);
1149   }
1150   profilePt->SetBinContent(p,contentPt);
1151   profilePt->SetBinEntries(p,entryPt);
1152   {
1153    profilePt->SetBinError(p,spreadPt);
1154   }
1155   
1156  }
1157  
1158  return profilePt;
1159  
1160 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta)
1161
1162
1163 //================================================================================================================================
1164
1165
1166 TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta) const
1167 {
1168  // project 2D profile onto eta axis to get 1D profile
1169  
1170  Int_t nBinsEta   = profilePtEta->GetNbinsY();
1171  Double_t dEtaMin = (profilePtEta->GetYaxis())->GetXmin();
1172  Double_t dEtaMax = (profilePtEta->GetYaxis())->GetXmax();
1173  
1174  Int_t nBinsPt = profilePtEta->GetNbinsX();
1175  
1176  TProfile *profileEta = new TProfile("","",nBinsEta,dEtaMin,dEtaMax); 
1177  
1178  for(Int_t e=1;e<=nBinsEta;e++)
1179  {
1180   Double_t contentEta = 0.;
1181   Double_t entryEta = 0.;
1182   for(Int_t p=1;p<=nBinsPt;p++)
1183   {
1184    contentEta += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
1185               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1186    entryEta   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
1187   }
1188   profileEta->SetBinContent(e,contentEta);
1189   profileEta->SetBinEntries(e,entryEta);
1190  }
1191  
1192  return profileEta;
1193  
1194 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta)
1195
1196 //================================================================================================================================
1197
1198 void AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type)
1199 {
1200  // Printing on the screen the final results for integrated flow (RF, POI and RP). 
1201  
1202  Int_t n = fHarmonic; 
1203  
1204  Double_t dVn[4] = {0.}; // array to hold Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1205  Double_t dVnErr[4] = {0.}; // array to hold errors of Vn{2}, Vn{4}, Vn{6} and Vn{8}   
1206  
1207  if(type == "RF")
1208  {
1209   for(Int_t b=0;b<4;b++)
1210   {
1211    dVn[b] = fIntFlow->GetBinContent(b+1); 
1212    dVnErr[b] = fIntFlow->GetBinError(b+1);
1213   }  
1214  } else if(type == "RP")
1215    {
1216     dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinContent(1); 
1217     dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinError(1); 
1218     dVn[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinContent(1); 
1219     dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinError(1); 
1220     dVn[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinContent(1); 
1221     dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinError(1); 
1222     dVn[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinContent(1); 
1223     dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinError(1); 
1224    } else if(type == "POI")
1225      {
1226       dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinContent(1); 
1227       dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinError(1); 
1228       dVn[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinContent(1); 
1229       dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinError(1); 
1230       dVn[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinContent(1); 
1231       dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinError(1); 
1232       dVn[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinContent(1); 
1233       dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinError(1); 
1234      } else if(type == "RF, rebinned in M")
1235        {
1236         for(Int_t b=0;b<4;b++)
1237         {
1238          dVn[b] = fIntFlowRebinnedInM->GetBinContent(b+1); 
1239          dVnErr[b] = fIntFlowRebinnedInM->GetBinError(b+1);
1240         }  
1241        }
1242  
1243  TString title = " flow estimates from Q-cumulants"; 
1244  TString subtitle = "    ("; 
1245  TString subtitle2 = "       (rebinned in M)"; 
1246  
1247  if(type != "RF, rebinned in M")
1248  {
1249   if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
1250   {
1251    subtitle.Append(type);
1252    subtitle.Append(", without weights)");
1253   } else  
1254     {
1255      subtitle.Append(type);
1256      subtitle.Append(", with weights)");
1257     }
1258  } else
1259    {
1260     if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
1261     {
1262      subtitle.Append("RF");
1263      subtitle.Append(", without weights)");
1264     } else  
1265       {
1266        subtitle.Append("RF");
1267        subtitle.Append(", with weights)");      
1268       }
1269    } 
1270    
1271  cout<<endl;
1272  cout<<"*************************************"<<endl;
1273  cout<<"*************************************"<<endl;
1274  cout<<title.Data()<<endl; 
1275  cout<<subtitle.Data()<<endl; 
1276  if(type == "RF, rebinned in M"){cout<<subtitle2.Data()<<endl;}
1277  cout<<endl;
1278   
1279  for(Int_t i=0;i<4;i++)
1280  {
1281   cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = "<<dVn[i]<<" +/- "<<dVnErr[i]<<endl;
1282  }
1283  
1284  cout<<endl;
1285  
1286  if(type == "RF" || type == "RF, rebinned in M")
1287  {
1288   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl; 
1289  }
1290  else if (type == "RP")
1291  {
1292   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultRP()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultRP()->GetMean()<<endl;  
1293  } 
1294  else if (type == "POI")
1295  {
1296   cout<<"     nEvts = "<<(Int_t)fCommonHists->GetHistMultPOI()->GetEntries()<<", <M> = "<<(Double_t)fCommonHists->GetHistMultPOI()->GetMean()<<endl;
1297  }  
1298  
1299  cout<<"*************************************"<<endl;
1300  cout<<"*************************************"<<endl;
1301  cout<<endl; 
1302   
1303 }// end of AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type="RF");
1304
1305 //================================================================================================================================
1306
1307 void AliFlowAnalysisWithQCumulants::WriteHistograms(TString outputFileName)
1308 {
1309  //store the final results in output .root file
1310  TFile *output = new TFile(outputFileName.Data(),"RECREATE");
1311  //output->WriteObject(fHistList, "cobjQC","SingleKey");
1312  fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
1313  delete output;
1314 }
1315
1316
1317 //================================================================================================================================
1318
1319
1320 void AliFlowAnalysisWithQCumulants::WriteHistograms(TDirectoryFile *outputFileName)
1321 {
1322  //store the final results in output .root file
1323  fHistList->SetName("cobjQC");
1324  fHistList->SetOwner(kTRUE);
1325  outputFileName->Add(fHistList);
1326  outputFileName->Write(outputFileName->GetName(), TObject::kSingleKey);
1327 }
1328
1329
1330 //================================================================================================================================
1331
1332
1333 void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1334 {
1335  // Book common control histograms and common histograms for final results.
1336  // common control histogram (ALL events)
1337  TString commonHistsName = "AliFlowCommonHistQC";
1338  commonHistsName += fAnalysisLabel->Data();
1339  fCommonHists = new AliFlowCommonHist(commonHistsName.Data());
1340  fHistList->Add(fCommonHists);  
1341  // common control histogram (for events with 2 and more particles)
1342  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
1343  commonHists2ndOrderName += fAnalysisLabel->Data();
1344  fCommonHists2nd = new AliFlowCommonHist(commonHists2ndOrderName.Data());
1345  fHistList->Add(fCommonHists2nd);  
1346  // common control histogram (for events with 4 and more particles)
1347  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
1348  commonHists4thOrderName += fAnalysisLabel->Data();
1349  fCommonHists4th = new AliFlowCommonHist(commonHists4thOrderName.Data());
1350  fHistList->Add(fCommonHists4th);  
1351  // common control histogram (for events with 6 and more particles)
1352  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
1353  commonHists6thOrderName += fAnalysisLabel->Data();
1354  fCommonHists6th = new AliFlowCommonHist(commonHists6thOrderName.Data());
1355  fHistList->Add(fCommonHists6th);  
1356  // common control histogram (for events with 8 and more particles)
1357  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
1358  commonHists8thOrderName += fAnalysisLabel->Data();
1359  fCommonHists8th = new AliFlowCommonHist(commonHists8thOrderName.Data());
1360  fHistList->Add(fCommonHists8th);    
1361  // common histograms for final results (calculated for events with 2 and more particles)
1362  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC";
1363  commonHistResults2ndOrderName += fAnalysisLabel->Data();
1364  fCommonHistsResults2nd = new AliFlowCommonHistResults(commonHistResults2ndOrderName.Data());
1365  fHistList->Add(fCommonHistsResults2nd);  
1366  // common histograms for final results (calculated for events with 4 and more particles)
1367  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
1368  commonHistResults4thOrderName += fAnalysisLabel->Data();
1369  fCommonHistsResults4th = new AliFlowCommonHistResults(commonHistResults4thOrderName.Data());
1370  fHistList->Add(fCommonHistsResults4th); 
1371  // common histograms for final results (calculated for events with 6 and more particles)
1372  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
1373  commonHistResults6thOrderName += fAnalysisLabel->Data();
1374  fCommonHistsResults6th = new AliFlowCommonHistResults(commonHistResults6thOrderName.Data());
1375  fHistList->Add(fCommonHistsResults6th);  
1376  // common histograms for final results (calculated for events with 8 and more particles)
1377  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
1378  commonHistResults8thOrderName += fAnalysisLabel->Data();
1379  fCommonHistsResults8th = new AliFlowCommonHistResults(commonHistResults8thOrderName.Data());
1380  fHistList->Add(fCommonHistsResults8th); 
1381  
1382 } // end of void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
1383
1384
1385 //================================================================================================================================
1386
1387
1388 void AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1389 {
1390  // book and fill histograms which hold phi, pt and eta weights
1391
1392  if(!fWeightsList)
1393  {
1394   cout<<"WARNING: fWeightsList is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1395   exit(0);  
1396  }
1397     
1398  TString fUseParticleWeightsName = "fUseParticleWeightsQC";
1399  fUseParticleWeightsName += fAnalysisLabel->Data();
1400  fUseParticleWeights = new TProfile(fUseParticleWeightsName.Data(),"0 = particle weight not used, 1 = particle weight used ",3,0,3);
1401  fUseParticleWeights->SetLabelSize(0.06);
1402  (fUseParticleWeights->GetXaxis())->SetBinLabel(1,"w_{#phi}");
1403  (fUseParticleWeights->GetXaxis())->SetBinLabel(2,"w_{p_{T}}");
1404  (fUseParticleWeights->GetXaxis())->SetBinLabel(3,"w_{#eta}");
1405  fUseParticleWeights->Fill(0.5,(Int_t)fUsePhiWeights);
1406  fUseParticleWeights->Fill(1.5,(Int_t)fUsePtWeights);
1407  fUseParticleWeights->Fill(2.5,(Int_t)fUseEtaWeights);
1408  fWeightsList->Add(fUseParticleWeights); 
1409   
1410  if(fUsePhiWeights)
1411  {
1412   if(fWeightsList->FindObject("phi_weights"))
1413   {
1414    fPhiWeights = dynamic_cast<TH1F*>(fWeightsList->FindObject("phi_weights"));
1415    if(TMath::Abs(fPhiWeights->GetBinWidth(1)-fPhiBinWidth)>pow(10.,-6.))
1416    {
1417     cout<<endl;
1418     cout<<"WARNING (QC): Inconsistent binning in histograms for phi-weights throughout the code."<<endl;
1419     cout<<endl;
1420     //exit(0);
1421    }
1422   } else 
1423     {
1424      cout<<"WARNING: fWeightsList->FindObject(\"phi_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1425      exit(0);
1426     }
1427  } // end of if(fUsePhiWeights)
1428  
1429  if(fUsePtWeights) 
1430  {
1431   if(fWeightsList->FindObject("pt_weights"))
1432   {
1433    fPtWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("pt_weights"));
1434    if(TMath::Abs(fPtWeights->GetBinWidth(1)-fPtBinWidth)>pow(10.,-6.))
1435    {
1436     cout<<endl;
1437     cout<<"WARNING (QC): Inconsistent binning in histograms for pt-weights throughout the code."<<endl;
1438     cout<<endl;
1439     //exit(0);
1440    }
1441   } else 
1442     {
1443      cout<<"WARNING: fWeightsList->FindObject(\"pt_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1444      exit(0);
1445     }
1446  } // end of if(fUsePtWeights)    
1447
1448  if(fUseEtaWeights) 
1449  {
1450   if(fWeightsList->FindObject("eta_weights"))
1451   {
1452    fEtaWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("eta_weights"));
1453    if(TMath::Abs(fEtaWeights->GetBinWidth(1)-fEtaBinWidth)>pow(10.,-6.))
1454    {
1455     cout<<endl;
1456     cout<<"WARNING (QC): Inconsistent binning in histograms for eta-weights throughout the code."<<endl;
1457     cout<<endl;
1458     //exit(0);
1459    }
1460   } else 
1461     {
1462      cout<<"WARNING: fUseEtaWeights && fWeightsList->FindObject(\"eta_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
1463      exit(0);
1464     }
1465  } // end of if(fUseEtaWeights)
1466  
1467 } // end of AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
1468
1469
1470 //================================================================================================================================
1471
1472
1473 void AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
1474 {
1475  // Book all objects for integrated flow:
1476  //  a) Book profile to hold all flags for integrated flow.
1477  //  b) Book event-by-event quantities.
1478  //  c) Book profiles. // to be improved (comment)
1479  //  d) Book histograms holding the final results.
1480  
1481  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
1482  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data members?)
1483  
1484  // a) Book profile to hold all flags for integrated flow:
1485  TString intFlowFlagsName = "fIntFlowFlags";
1486  intFlowFlagsName += fAnalysisLabel->Data();
1487  fIntFlowFlags = new TProfile(intFlowFlagsName.Data(),"Flags for Integrated Flow",11,0,11);
1488  fIntFlowFlags->SetTickLength(-0.01,"Y");
1489  fIntFlowFlags->SetMarkerStyle(25);
1490  fIntFlowFlags->SetLabelSize(0.05);
1491  fIntFlowFlags->SetLabelOffset(0.02,"Y");
1492  fIntFlowFlags->GetXaxis()->SetBinLabel(1,"Particle Weights");
1493  fIntFlowFlags->GetXaxis()->SetBinLabel(2,"Event Weights");
1494  fIntFlowFlags->GetXaxis()->SetBinLabel(3,"Corrected for NUA?");
1495  fIntFlowFlags->GetXaxis()->SetBinLabel(4,"Print RF results");
1496  fIntFlowFlags->GetXaxis()->SetBinLabel(5,"Print RP results");
1497  fIntFlowFlags->GetXaxis()->SetBinLabel(6,"Print POI results");
1498  fIntFlowFlags->GetXaxis()->SetBinLabel(7,"Print RF (rebinned in M) results");
1499  fIntFlowFlags->GetXaxis()->SetBinLabel(8,"Corrected for NUA vs M?");
1500  fIntFlowFlags->GetXaxis()->SetBinLabel(9,"Propagate errors to v_{n} from correlations?");
1501  fIntFlowFlags->GetXaxis()->SetBinLabel(10,"Calculate cumulants vs M");
1502  fIntFlowFlags->GetXaxis()->SetBinLabel(11,"fMinimumBiasReferenceFlow");
1503  fIntFlowList->Add(fIntFlowFlags);
1504
1505  // b) Book event-by-event quantities:
1506  // Re[Q_{m*n,k}], Im[Q_{m*n,k}] and S_{p,k}^M: 
1507  fReQ  = new TMatrixD(4,9);
1508  fImQ  = new TMatrixD(4,9);
1509  fSMpk = new TMatrixD(8,9);
1510  // average correlations <2>, <4>, <6> and <8> for single event (bining is the same as in fIntFlowCorrelationsPro and fIntFlowCorrelationsHist):
1511  TString intFlowCorrelationsEBEName = "fIntFlowCorrelationsEBE";
1512  intFlowCorrelationsEBEName += fAnalysisLabel->Data();
1513  fIntFlowCorrelationsEBE = new TH1D(intFlowCorrelationsEBEName.Data(),intFlowCorrelationsEBEName.Data(),4,0,4);
1514  // weights for average correlations <2>, <4>, <6> and <8> for single event:
1515  TString intFlowEventWeightsForCorrelationsEBEName = "fIntFlowEventWeightsForCorrelationsEBE";
1516  intFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
1517  fIntFlowEventWeightsForCorrelationsEBE = new TH1D(intFlowEventWeightsForCorrelationsEBEName.Data(),intFlowEventWeightsForCorrelationsEBEName.Data(),4,0,4);
1518  // average all correlations for single event (bining is the same as in fIntFlowCorrelationsAllPro and fIntFlowCorrelationsAllHist):
1519  TString intFlowCorrelationsAllEBEName = "fIntFlowCorrelationsAllEBE";
1520  intFlowCorrelationsAllEBEName += fAnalysisLabel->Data();
1521  fIntFlowCorrelationsAllEBE = new TH1D(intFlowCorrelationsAllEBEName.Data(),intFlowCorrelationsAllEBEName.Data(),32,0,32);
1522  // average correction terms for non-uniform acceptance for single event 
1523  // (binning is the same as in fIntFlowCorrectionTermsForNUAPro[2] and fIntFlowCorrectionTermsForNUAHist[2]):
1524  TString fIntFlowCorrectionTermsForNUAEBEName = "fIntFlowCorrectionTermsForNUAEBE";
1525  fIntFlowCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1526  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1527  {
1528   fIntFlowCorrectionTermsForNUAEBE[sc] = new TH1D(Form("%s: %s terms",fIntFlowCorrectionTermsForNUAEBEName.Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),10,0,10);  
1529  }
1530  // event weights for terms for non-uniform acceptance: 
1531  TString fIntFlowEventWeightForCorrectionTermsForNUAEBEName = "fIntFlowEventWeightForCorrectionTermsForNUAEBE";
1532  fIntFlowEventWeightForCorrectionTermsForNUAEBEName += fAnalysisLabel->Data();
1533  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1534  {
1535   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()),10,0,10);  
1536  }
1537  // c) Book profiles: // to be improved (comment)
1538  // profile to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8:
1539  TString avMultiplicityName = "fAvMultiplicity";
1540  avMultiplicityName += fAnalysisLabel->Data();
1541  fAvMultiplicity = new TProfile(avMultiplicityName.Data(),"Average Multiplicities of RPs",9,0,9);
1542  fAvMultiplicity->SetTickLength(-0.01,"Y");
1543  fAvMultiplicity->SetMarkerStyle(25);
1544  fAvMultiplicity->SetLabelSize(0.05);
1545  fAvMultiplicity->SetLabelOffset(0.02,"Y");
1546  fAvMultiplicity->SetYTitle("Average Multiplicity");
1547  (fAvMultiplicity->GetXaxis())->SetBinLabel(1,"all evts");
1548  (fAvMultiplicity->GetXaxis())->SetBinLabel(2,"n_{RP} #geq 1");
1549  (fAvMultiplicity->GetXaxis())->SetBinLabel(3,"n_{RP} #geq 2");
1550  (fAvMultiplicity->GetXaxis())->SetBinLabel(4,"n_{RP} #geq 3");
1551  (fAvMultiplicity->GetXaxis())->SetBinLabel(5,"n_{RP} #geq 4");
1552  (fAvMultiplicity->GetXaxis())->SetBinLabel(6,"n_{RP} #geq 5");
1553  (fAvMultiplicity->GetXaxis())->SetBinLabel(7,"n_{RP} #geq 6");
1554  (fAvMultiplicity->GetXaxis())->SetBinLabel(8,"n_{RP} #geq 7");
1555  (fAvMultiplicity->GetXaxis())->SetBinLabel(9,"n_{RP} #geq 8");
1556  fIntFlowProfiles->Add(fAvMultiplicity);
1557  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with wrong errors!):
1558  TString correlationFlag[4] = {"<<2>>","<<4>>","<<6>>","<<8>>"};
1559  TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
1560  intFlowCorrelationsProName += fAnalysisLabel->Data();
1561  fIntFlowCorrelationsPro = new TProfile(intFlowCorrelationsProName.Data(),"Average correlations for all events",4,0,4,"s");
1562  fIntFlowCorrelationsPro->SetTickLength(-0.01,"Y");
1563  fIntFlowCorrelationsPro->SetMarkerStyle(25);
1564  fIntFlowCorrelationsPro->SetLabelSize(0.06);
1565  fIntFlowCorrelationsPro->SetLabelOffset(0.01,"Y");
1566  for(Int_t b=0;b<4;b++)
1567  {
1568   (fIntFlowCorrelationsPro->GetXaxis())->SetBinLabel(b+1,correlationFlag[b].Data());
1569  }
1570  fIntFlowProfiles->Add(fIntFlowCorrelationsPro);
1571  // average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (with wrong errors):
1572  if(fCalculateCumulantsVsM)
1573  {
1574   for(Int_t ci=0;ci<4;ci++) // correlation index
1575   {
1576    TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
1577    intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
1578    fIntFlowCorrelationsVsMPro[ci] = new TProfile(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data()),
1579                                                  Form("%s vs multiplicity",correlationFlag[ci].Data()),
1580                                                  fnBinsMult,fMinMult,fMaxMult,"s");                                            
1581    fIntFlowCorrelationsVsMPro[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
1582    fIntFlowCorrelationsVsMPro[ci]->GetXaxis()->SetTitle("M");
1583    fIntFlowProfiles->Add(fIntFlowCorrelationsVsMPro[ci]);
1584   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
1585  } // end of if(fCalculateCumulantsVsM)
1586  // averaged all correlations for all events (with wrong errors!):
1587  TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
1588  intFlowCorrelationsAllProName += fAnalysisLabel->Data();
1589  fIntFlowCorrelationsAllPro = new TProfile(intFlowCorrelationsAllProName.Data(),"Average correlations for all events",32,0,32,"s");
1590  fIntFlowCorrelationsAllPro->SetTickLength(-0.01,"Y");
1591  fIntFlowCorrelationsAllPro->SetMarkerStyle(25);
1592  fIntFlowCorrelationsAllPro->SetLabelSize(0.03);
1593  fIntFlowCorrelationsAllPro->SetLabelOffset(0.01,"Y");
1594  // 2-p correlations:
1595  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1596  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1597  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1598  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1599  // 3-p correlations:
1600  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1601  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1602  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1603  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1604  // 4-p correlations:
1605  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1606  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1607  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1608  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1609  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1610  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1611  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1612  // 5-p correlations:
1613  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1614  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1615  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1616  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1617  // 6-p correlations:
1618  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1619  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1620  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1621  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1622  // 7-p correlations:  
1623  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1624  // 8-p correlations:
1625  (fIntFlowCorrelationsAllPro->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1626  fIntFlowProfiles->Add(fIntFlowCorrelationsAllPro);
1627  // when particle weights are used some extra correlations appear:
1628  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights) 
1629  {
1630   TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
1631   intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
1632   fIntFlowExtraCorrelationsPro = new TProfile(intFlowExtraCorrelationsProName.Data(),"Average extra correlations for all events",100,0,100,"s");
1633   fIntFlowExtraCorrelationsPro->SetTickLength(-0.01,"Y");
1634   fIntFlowExtraCorrelationsPro->SetMarkerStyle(25);
1635   fIntFlowExtraCorrelationsPro->SetLabelSize(0.03);
1636   fIntFlowExtraCorrelationsPro->SetLabelOffset(0.01,"Y");
1637   // extra 2-p correlations:
1638   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(1,"<<w1^3 w2 cos(n*(phi1-phi2))>>");
1639   (fIntFlowExtraCorrelationsPro->GetXaxis())->SetBinLabel(2,"<<w1 w2 w3^2 cos(n*(phi1-phi2))>>");
1640   fIntFlowProfiles->Add(fIntFlowExtraCorrelationsPro);
1641  } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
1642  // average product of correlations <2>, <4>, <6> and <8>:  
1643  TString productFlag[6] = {"<<2><4>>","<<2><6>>","<<2><8>>","<<4><6>>","<<4><8>>","<<6><8>>"};
1644  TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
1645  intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
1646  fIntFlowProductOfCorrelationsPro = new TProfile(intFlowProductOfCorrelationsProName.Data(),"Average products of correlations",6,0,6);
1647  fIntFlowProductOfCorrelationsPro->SetTickLength(-0.01,"Y");
1648  fIntFlowProductOfCorrelationsPro->SetMarkerStyle(25); 
1649  fIntFlowProductOfCorrelationsPro->SetLabelSize(0.05);
1650  fIntFlowProductOfCorrelationsPro->SetLabelOffset(0.01,"Y");
1651  for(Int_t b=0;b<6;b++)
1652  {
1653   (fIntFlowProductOfCorrelationsPro->GetXaxis())->SetBinLabel(b+1,productFlag[b].Data());
1654  }
1655  fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsPro); 
1656  // average product of correlations <2>, <4>, <6> and <8> versus multiplicity
1657  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
1658  if(fCalculateCumulantsVsM)
1659  {
1660   TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
1661   intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
1662   for(Int_t pi=0;pi<6;pi++)
1663   { 
1664    fIntFlowProductOfCorrelationsVsMPro[pi] = new TProfile(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data()),
1665                                                           Form("%s versus multiplicity",productFlag[pi].Data()),
1666                                                           fnBinsMult,fMinMult,fMaxMult);             
1667    fIntFlowProductOfCorrelationsVsMPro[pi]->GetXaxis()->SetTitle("M");
1668    fIntFlowProfiles->Add(fIntFlowProductOfCorrelationsVsMPro[pi]);
1669   } // end of for(Int_t pi=0;pi<6;pi++)
1670  } // end of if(fCalculateCumulantsVsM) 
1671  // average product of correction terms for NUA:  
1672  TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
1673  intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
1674  fIntFlowProductOfCorrectionTermsForNUAPro = new TProfile(intFlowProductOfCorrectionTermsForNUAProName.Data(),"Average products of correction terms for NUA",27,0,27);
1675  fIntFlowProductOfCorrectionTermsForNUAPro->SetTickLength(-0.01,"Y");
1676  fIntFlowProductOfCorrectionTermsForNUAPro->SetMarkerStyle(25); 
1677  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelSize(0.05);
1678  fIntFlowProductOfCorrectionTermsForNUAPro->SetLabelOffset(0.01,"Y");
1679  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(1,"<<2><cos(#phi)>>");
1680  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(2,"<<2><sin(#phi)>>");
1681  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(3,"<<cos(#phi)><sin(#phi)>>");
1682  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
1683  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
1684  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1685  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1686  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
1687  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
1688  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
1689  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
1690  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1691  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1692  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
1693  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1694  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1695  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1696  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
1697  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1698  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1699  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1700  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
1701  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1702  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1703  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1704  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1705  (fIntFlowProductOfCorrectionTermsForNUAPro->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
1706  fIntFlowProfiles->Add(fIntFlowProductOfCorrectionTermsForNUAPro);
1707  // average correction terms for non-uniform acceptance (with wrong errors!):
1708  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1709  {
1710   TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
1711   intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
1712   fIntFlowCorrectionTermsForNUAPro[sc] = new TProfile(Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),10,0,10,"s");
1713   fIntFlowCorrectionTermsForNUAPro[sc]->SetTickLength(-0.01,"Y");
1714   fIntFlowCorrectionTermsForNUAPro[sc]->SetMarkerStyle(25);
1715   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelSize(0.03);
1716   fIntFlowCorrectionTermsForNUAPro[sc]->SetLabelOffset(0.01,"Y");
1717   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(1,Form("<<%s(n(phi1))>>",sinCosFlag[sc].Data()));
1718   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(2,Form("<<%s(n(phi1+phi2))>>",sinCosFlag[sc].Data()));  
1719   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(3,Form("<<%s(n(phi1-phi2-phi3))>>",sinCosFlag[sc].Data()));  
1720   (fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->SetBinLabel(4,Form("<<%s(n(2phi1-phi2))>>",sinCosFlag[sc].Data()));  
1721   fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAPro[sc]);
1722   // versus multiplicity:
1723   if(fCalculateCumulantsVsM)
1724   {
1725    TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
1726    for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
1727    {
1728     TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
1729     intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
1730     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");
1731     fIntFlowProfiles->Add(fIntFlowCorrectionTermsForNUAVsMPro[sc][ci]);
1732    }
1733   } // end of if(fCalculateCumulantsVsM)
1734  } // end of for(Int_t sc=0;sc<2;sc++) 
1735  
1736  // d) Book histograms holding the final results:
1737  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!):
1738  TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
1739  intFlowCorrelationsHistName += fAnalysisLabel->Data();
1740  fIntFlowCorrelationsHist = new TH1D(intFlowCorrelationsHistName.Data(),"Average correlations for all events",4,0,4);
1741  fIntFlowCorrelationsHist->SetTickLength(-0.01,"Y");
1742  fIntFlowCorrelationsHist->SetMarkerStyle(25);
1743  fIntFlowCorrelationsHist->SetLabelSize(0.06);
1744  fIntFlowCorrelationsHist->SetLabelOffset(0.01,"Y");
1745  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(1,"<<2>>");
1746  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(2,"<<4>>");
1747  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(3,"<<6>>");
1748  (fIntFlowCorrelationsHist->GetXaxis())->SetBinLabel(4,"<<8>>");
1749  fIntFlowResults->Add(fIntFlowCorrelationsHist);
1750  // average correlations <<2>>, <<4>>, <<6>> and <<8>> for all events (with correct errors!) vs M:
1751  if(fCalculateCumulantsVsM)
1752  {
1753   for(Int_t ci=0;ci<4;ci++) // correlation index
1754   {
1755    TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
1756    intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
1757    fIntFlowCorrelationsVsMHist[ci] = new TH1D(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data()),
1758                                               Form("%s vs multiplicity",correlationFlag[ci].Data()),
1759                                               fnBinsMult,fMinMult,fMaxMult);                                            
1760    fIntFlowCorrelationsVsMHist[ci]->GetYaxis()->SetTitle(correlationFlag[ci].Data());
1761    fIntFlowCorrelationsVsMHist[ci]->GetXaxis()->SetTitle("M");
1762    fIntFlowResults->Add(fIntFlowCorrelationsVsMHist[ci]);
1763   } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
1764  } // end of if(fCalculateCumulantsVsM) 
1765  // average all correlations for all events (with correct errors!):
1766  TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
1767  intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
1768  fIntFlowCorrelationsAllHist = new TH1D(intFlowCorrelationsAllHistName.Data(),"Average correlations for all events",32,0,32);
1769  fIntFlowCorrelationsAllHist->SetTickLength(-0.01,"Y");
1770  fIntFlowCorrelationsAllHist->SetMarkerStyle(25);
1771  fIntFlowCorrelationsAllHist->SetLabelSize(0.03);
1772  fIntFlowCorrelationsAllHist->SetLabelOffset(0.01,"Y");
1773  // 2-p correlations:
1774  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
1775  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
1776  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
1777  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
1778  // 3-p correlations:
1779  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
1780  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
1781  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
1782  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
1783  // 4-p correlations:
1784  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
1785  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
1786  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
1787  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
1788  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
1789  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
1790  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
1791  // 5-p correlations:
1792  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
1793  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
1794  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
1795  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
1796  // 6-p correlations:
1797  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
1798  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
1799  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
1800  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
1801  // 7-p correlations:  
1802  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
1803  // 8-p correlations:
1804  (fIntFlowCorrelationsAllHist->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
1805  fIntFlowResults->Add(fIntFlowCorrelationsAllHist);
1806  // average correction terms for non-uniform acceptance (with correct errors!):
1807  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
1808  {
1809   TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
1810   intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
1811   fIntFlowCorrectionTermsForNUAHist[sc] = new TH1D(Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s terms)",sinCosFlag[sc].Data()),10,0,10);
1812   fIntFlowCorrectionTermsForNUAHist[sc]->SetTickLength(-0.01,"Y");
1813   fIntFlowCorrectionTermsForNUAHist[sc]->SetMarkerStyle(25);
1814   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelSize(0.03);
1815   fIntFlowCorrectionTermsForNUAHist[sc]->SetLabelOffset(0.01,"Y");
1816   // ......................................................................... 
1817   // 1-p terms:
1818   (fIntFlowCorrectionTermsForNUAHist[sc]->GetXaxis())->SetBinLabel(1,Form("%s(n(#phi_{1}))>",sinCosFlag[sc].Data()));
1819   // 2-p terms:
1820   // 3-p terms:
1821   // ...
1822   // ......................................................................... 
1823   fIntFlowResults->Add(fIntFlowCorrectionTermsForNUAHist[sc]);
1824  } // end of for(Int_t sc=0;sc<2;sc++) 
1825  // covariances (multiplied with weight dependent prefactor):
1826  TString intFlowCovariancesName = "fIntFlowCovariances";
1827  intFlowCovariancesName += fAnalysisLabel->Data();
1828  fIntFlowCovariances = new TH1D(intFlowCovariancesName.Data(),"Covariances (multiplied with weight dependent prefactor)",6,0,6);
1829  fIntFlowCovariances->SetLabelSize(0.04);
1830  fIntFlowCovariances->SetMarkerStyle(25);
1831  (fIntFlowCovariances->GetXaxis())->SetBinLabel(1,"Cov(<2>,<4>)");
1832  (fIntFlowCovariances->GetXaxis())->SetBinLabel(2,"Cov(<2>,<6>)");
1833  (fIntFlowCovariances->GetXaxis())->SetBinLabel(3,"Cov(<2>,<8>)");
1834  (fIntFlowCovariances->GetXaxis())->SetBinLabel(4,"Cov(<4>,<6>)");
1835  (fIntFlowCovariances->GetXaxis())->SetBinLabel(5,"Cov(<4>,<8>)");
1836  (fIntFlowCovariances->GetXaxis())->SetBinLabel(6,"Cov(<6>,<8>)");  
1837  fIntFlowResults->Add(fIntFlowCovariances);
1838  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
1839  TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
1840  intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
1841  for(Int_t power=0;power<2;power++)
1842  {
1843   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);
1844   fIntFlowSumOfEventWeights[power]->SetLabelSize(0.05);
1845   fIntFlowSumOfEventWeights[power]->SetMarkerStyle(25);
1846   if(power == 0)
1847   {
1848    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}");
1849    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}");
1850    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}");
1851    (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}");
1852   } else if (power == 1) 
1853     {
1854      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}^{2}");
1855      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}^{2}");
1856      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}^{2}");
1857      (fIntFlowSumOfEventWeights[power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}^{2}");
1858     }
1859   fIntFlowResults->Add(fIntFlowSumOfEventWeights[power]);
1860  } 
1861  // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
1862  TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
1863  intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
1864  fIntFlowSumOfProductOfEventWeights = new TH1D(intFlowSumOfProductOfEventWeightsName.Data(),"Sum of product of event weights for correlations",6,0,6);
1865  fIntFlowSumOfProductOfEventWeights->SetLabelSize(0.05);
1866  fIntFlowSumOfProductOfEventWeights->SetMarkerStyle(25);
1867  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<4>}");
1868  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<6>}");
1869  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<2>} w_{<8>}");
1870  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<4>} w_{<6>}");
1871  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(5,"#sum_{i=1}^{N} w_{<4>} w_{<8>}");
1872  (fIntFlowSumOfProductOfEventWeights->GetXaxis())->SetBinLabel(6,"#sum_{i=1}^{N} w_{<6>} w_{<8>}");
1873  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeights);
1874  // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
1875  // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
1876  if(fCalculateCumulantsVsM)
1877  {
1878   TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
1879   intFlowCovariancesVsMName += fAnalysisLabel->Data();
1880   TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
1881   for(Int_t ci=0;ci<6;ci++)
1882   {
1883    fIntFlowCovariancesVsM[ci] = new TH1D(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data()),
1884                                          Form("%s vs multiplicity",covarianceFlag[ci].Data()),
1885                                          fnBinsMult,fMinMult,fMaxMult);
1886    fIntFlowCovariancesVsM[ci]->GetYaxis()->SetTitle(covarianceFlag[ci].Data());
1887    fIntFlowCovariancesVsM[ci]->GetXaxis()->SetTitle("M");
1888    fIntFlowResults->Add(fIntFlowCovariancesVsM[ci]);
1889   }
1890  } // end of if(fCalculateCumulantsVsM) 
1891  // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
1892  // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
1893  if(fCalculateCumulantsVsM)
1894  {
1895   TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
1896   intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
1897   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>}"},
1898                            {"#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}"}};
1899   for(Int_t si=0;si<4;si++)
1900   {
1901    for(Int_t power=0;power<2;power++)
1902    {
1903     fIntFlowSumOfEventWeightsVsM[si][power] = new TH1D(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data()),
1904                                                        Form("%s vs multiplicity",sumFlag[power][si].Data()),
1905                                                        fnBinsMult,fMinMult,fMaxMult);    
1906     fIntFlowSumOfEventWeightsVsM[si][power]->GetYaxis()->SetTitle(sumFlag[power][si].Data());  
1907     fIntFlowSumOfEventWeightsVsM[si][power]->GetXaxis()->SetTitle("M");  
1908     fIntFlowResults->Add(fIntFlowSumOfEventWeightsVsM[si][power]);
1909    } // end of for(Int_t power=0;power<2;power++)
1910   } // end of for(Int_t si=0;si<4;si++)   
1911  } // end of if(fCalculateCumulantsVsM)
1912  // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
1913  // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
1914  //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
1915  if(fCalculateCumulantsVsM)
1916  {
1917   TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
1918   intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
1919   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>}",
1920                           "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
1921   for(Int_t pi=0;pi<6;pi++)
1922   {
1923    fIntFlowSumOfProductOfEventWeightsVsM[pi] = new TH1D(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data()),
1924                                                         Form("%s versus multiplicity",sopowFlag[pi].Data()),
1925                                                         fnBinsMult,fMinMult,fMaxMult); 
1926    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetXaxis()->SetTitle("M");
1927    fIntFlowSumOfProductOfEventWeightsVsM[pi]->GetYaxis()->SetTitle(sopowFlag[pi].Data()); 
1928    fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsVsM[pi]);
1929   } // end of for(Int_t pi=0;pi<6;pi++) 
1930  } // end of if(fCalculateCumulantsVsM)
1931  // covariances of NUA terms (multiplied with weight dependent prefactor):
1932  TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
1933  intFlowCovariancesNUAName += fAnalysisLabel->Data();
1934  fIntFlowCovariancesNUA = new TH1D(intFlowCovariancesNUAName.Data(),"Covariances for NUA (multiplied with weight dependent prefactor)",27,0,27);
1935  fIntFlowCovariancesNUA->SetLabelSize(0.04);
1936  fIntFlowCovariancesNUA->SetMarkerStyle(25);
1937  fIntFlowCovariancesNUA->GetXaxis()->SetLabelSize(0.02);
1938  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(1,"Cov(<2>,<cos(#phi)>");
1939  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(2,"Cov(<2>,<sin(#phi)>)");
1940  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(3,"Cov(<cos(#phi)>,<sin(#phi)>)");
1941  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(4,"Cov(<2>,<cos(#phi_{1}+#phi_{2})>)");
1942  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(5,"Cov(<2>,<sin(#phi_{1}+#phi_{2})>)");
1943  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(6,"Cov(<2>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1944  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(7,"Cov(<2>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1945  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(8,"Cov(<4>,<cos(#phi)>)");
1946  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(9,"Cov(<4>,<sin(#phi)>)");
1947  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(10,"Cov(<4>,<cos(#phi_{1}+#phi_{2})>)");
1948  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(11,"Cov(<4>,<sin(#phi_{1}+#phi_{2})>)");
1949  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(12,"Cov(<4>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1950  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(13,"Cov(<4>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>>)");
1951  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(14,"Cov(<cos(#phi)>,<cos(#phi_{1}+#phi_{2})>)"); 
1952  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(15,"Cov(<cos(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1953  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(16,"Cov(<cos(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1954  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(17,"Cov(<cos(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1955  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(18,"Cov(<sin(#phi)>,<cos(#phi_{1}+#phi_{2})>)");
1956  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(19,"Cov(<sin(#phi)>,<sin(#phi_{1}+#phi_{2})>)");
1957  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(20,"Cov(<sin(#phi)>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1958  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(21,"Cov(<sin(#phi)>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1959  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(22,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}+#phi_{2})>)");
1960  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(23,"Cov(<cos(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1961  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(24,"Cov(<cos(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1962  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(25,"Cov(<sin(#phi_{1}+#phi_{2})>,<cos(#phi_{1}-#phi_{2}-#phi_{3})>)");
1963  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(26,"Cov(<sin(#phi_{1}+#phi_{2})>,<sin(#phi_{1}-#phi_{2}-#phi_{3})>)");
1964  (fIntFlowCovariancesNUA->GetXaxis())->SetBinLabel(27,"Cov(<cos(#phi_{1}-#phi_{2}-#phi_{3}>,<sin(#phi_{1}-#phi_{2}-#phi_{3}>)");
1965  fIntFlowResults->Add(fIntFlowCovariancesNUA);
1966  // sum of linear and quadratic event weights for NUA terms:
1967  TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
1968  intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
1969  for(Int_t sc=0;sc<2;sc++)
1970  {
1971   for(Int_t power=0;power<2;power++)
1972   {
1973    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()),3,0,3);
1974    fIntFlowSumOfEventWeightsNUA[sc][power]->SetLabelSize(0.05);
1975    fIntFlowSumOfEventWeightsNUA[sc][power]->SetMarkerStyle(25);
1976    if(power == 0)
1977    {
1978     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}",sinCosFlag[sc].Data()));
1979     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}",sinCosFlag[sc].Data()));
1980     (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}",sinCosFlag[sc].Data()));
1981    } else if(power == 1) 
1982      {
1983       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(1,Form("#sum_{i=1}^{N} w_{<%s(#phi)>}^{2}",sinCosFlag[sc].Data()));
1984       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(2,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}+#phi_{2})>}^{2}",sinCosFlag[sc].Data()));
1985       (fIntFlowSumOfEventWeightsNUA[sc][power]->GetXaxis())->SetBinLabel(3,Form("#sum_{i=1}^{N} w_{<%s(#phi_{1}-#phi_{2}-#phi_{3})>}^{2}",sinCosFlag[sc].Data()));
1986      }
1987    fIntFlowResults->Add(fIntFlowSumOfEventWeightsNUA[sc][power]);
1988   }
1989  }  
1990  // sum of products of event weights for NUA terms:  
1991  TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
1992  intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
1993  fIntFlowSumOfProductOfEventWeightsNUA = new TH1D(intFlowSumOfProductOfEventWeightsNUAName.Data(),"Sum of product of event weights for NUA terms",27,0,27);
1994  fIntFlowSumOfProductOfEventWeightsNUA->SetLabelSize(0.05);
1995  fIntFlowSumOfProductOfEventWeightsNUA->SetMarkerStyle(25);
1996  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<cos(#phi)>}");
1997  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<sin(#phi)>}");
1998  (fIntFlowSumOfProductOfEventWeightsNUA->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<cos(#phi)>} w_{<sin(#phi)>}");
1999  // ....
2000  // to be improved - add labels for remaining bins
2001  // ....
2002  fIntFlowResults->Add(fIntFlowSumOfProductOfEventWeightsNUA);
2003  // Final results for reference Q-cumulants:
2004  TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
2005  TString intFlowQcumulantsName = "fIntFlowQcumulants";
2006  intFlowQcumulantsName += fAnalysisLabel->Data();
2007  fIntFlowQcumulants = new TH1D(intFlowQcumulantsName.Data(),"Integrated Q-cumulants",4,0,4);
2008  fIntFlowQcumulants->SetLabelSize(0.05);
2009  fIntFlowQcumulants->SetMarkerStyle(25);
2010  for(Int_t b=0;b<4;b++)
2011  {
2012   (fIntFlowQcumulants->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2013  } 
2014  fIntFlowResults->Add(fIntFlowQcumulants);
2015  // Final results for reference Q-cumulants rebinned in M: 
2016  if(fCalculateCumulantsVsM)
2017  {
2018   TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
2019   intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
2020   fIntFlowQcumulantsRebinnedInM = new TH1D(intFlowQcumulantsRebinnedInMName.Data(),"Reference Q-cumulants rebinned in M",4,0,4);
2021   fIntFlowQcumulantsRebinnedInM->SetLabelSize(0.05);
2022   fIntFlowQcumulantsRebinnedInM->SetMarkerStyle(25);
2023   for(Int_t b=0;b<4;b++)
2024   {
2025    (fIntFlowQcumulantsRebinnedInM->GetXaxis())->SetBinLabel(b+1,cumulantFlag[b].Data());
2026   } 
2027   fIntFlowResults->Add(fIntFlowQcumulantsRebinnedInM);
2028  } // end of if(fCalculateCumulantsVsM) 
2029  // final results for integrated Q-cumulants versus multiplicity:
2030  if(fCalculateCumulantsVsM)
2031  {
2032   TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
2033   intFlowQcumulantsVsMName += fAnalysisLabel->Data();
2034   for(Int_t co=0;co<4;co++) // cumulant order
2035   {
2036    fIntFlowQcumulantsVsM[co] = new TH1D(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data()),
2037                                         Form("%s vs multipicity",cumulantFlag[co].Data()),
2038                                         fnBinsMult,fMinMult,fMaxMult);
2039    fIntFlowQcumulantsVsM[co]->GetXaxis()->SetTitle("M");                                     
2040    fIntFlowQcumulantsVsM[co]->GetYaxis()->SetTitle(cumulantFlag[co].Data());  
2041    fIntFlowResults->Add(fIntFlowQcumulantsVsM[co]);                                    
2042   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2043  } // end of if(fCalculateCumulantsVsM)
2044  // final integrated flow estimates from Q-cumulants:
2045  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)};
2046  TString intFlowName = "fIntFlow";
2047  intFlowName += fAnalysisLabel->Data();  
2048  // integrated flow from Q-cumulants:
2049  fIntFlow = new TH1D(intFlowName.Data(),"Reference flow estimates from Q-cumulants",4,0,4);
2050  fIntFlow->SetLabelSize(0.05);
2051  fIntFlow->SetMarkerStyle(25);
2052  for(Int_t b=0;b<4;b++)
2053  {
2054   (fIntFlow->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2055  }
2056  fIntFlowResults->Add(fIntFlow); 
2057  // Reference flow vs M rebinned in one huge bin:
2058  if(fCalculateCumulantsVsM)
2059  { 
2060   TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
2061   intFlowRebinnedInMName += fAnalysisLabel->Data();  
2062   fIntFlowRebinnedInM = new TH1D(intFlowRebinnedInMName.Data(),"Reference flow estimates from Q-cumulants (rebinned in M)",4,0,4);
2063   fIntFlowRebinnedInM->SetLabelSize(0.05);
2064   fIntFlowRebinnedInM->SetMarkerStyle(25);
2065   for(Int_t b=0;b<4;b++)
2066   {
2067    (fIntFlowRebinnedInM->GetXaxis())->SetBinLabel(b+1,flowFlag[b].Data()); 
2068   }
2069   fIntFlowResults->Add(fIntFlowRebinnedInM); 
2070  } 
2071  // integrated flow from Q-cumulants: versus multiplicity:
2072  if(fCalculateCumulantsVsM)
2073  {
2074   TString intFlowVsMName = "fIntFlowVsM";
2075   intFlowVsMName += fAnalysisLabel->Data();
2076   for(Int_t co=0;co<4;co++) // cumulant order
2077   {
2078    fIntFlowVsM[co] = new TH1D(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data()),
2079                               Form("%s vs multipicity",flowFlag[co].Data()),
2080                               fnBinsMult,fMinMult,fMaxMult);
2081    fIntFlowVsM[co]->GetXaxis()->SetTitle("M");                                     
2082    fIntFlowVsM[co]->GetYaxis()->SetTitle(flowFlag[co].Data());  
2083    fIntFlowResults->Add(fIntFlowVsM[co]);                                    
2084   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2085  } // end of if(fCalculateCumulantsVsM)
2086  // quantifying detector effects effects to correlations:
2087  TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
2088  intFlowDetectorBiasName += fAnalysisLabel->Data();  
2089  fIntFlowDetectorBias = new TH1D(intFlowDetectorBiasName.Data(),"Quantifying detector bias",4,0,4);
2090  fIntFlowDetectorBias->SetLabelSize(0.05);
2091  fIntFlowDetectorBias->SetMarkerStyle(25);
2092  for(Int_t ci=0;ci<4;ci++)
2093  {  
2094   (fIntFlowDetectorBias->GetXaxis())->SetBinLabel(ci+1,Form("#frac{corrected}{measured} %s",cumulantFlag[ci].Data()));
2095  }
2096  fIntFlowResults->Add(fIntFlowDetectorBias); 
2097  // quantifying detector effects to correlations versus multiplicity:
2098  if(fCalculateCumulantsVsM)
2099  {
2100   TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
2101   intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
2102   for(Int_t ci=0;ci<4;ci++) // correlation index
2103   {
2104    fIntFlowDetectorBiasVsM[ci] = new TH1D(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data()),
2105                                           Form("Quantifying detector bias for %s vs multipicity",cumulantFlag[ci].Data()),
2106                                           fnBinsMult,fMinMult,fMaxMult);
2107    fIntFlowDetectorBiasVsM[ci]->GetXaxis()->SetTitle("M");                                     
2108    fIntFlowDetectorBiasVsM[ci]->GetYaxis()->SetTitle("#frac{corrected}{measured}");  
2109    if(fApplyCorrectionForNUAVsM){fIntFlowResults->Add(fIntFlowDetectorBiasVsM[ci]);}                                    
2110   } // end of for(Int_t co=0;co<4;co++) // cumulant order
2111  } // end of if(fCalculateCumulantsVsM)
2112  
2113  /* // to be improved (removed):
2114   // final average weighted multi-particle correlations for all events calculated from Q-vectors
2115   fQCorrelations[1] = new TProfile("Weighted correlations","final average multi-particle correlations from weighted Q-vectors",200,0,200,"s");
2116   fQCorrelations[1]->SetTickLength(-0.01,"Y");
2117   fQCorrelations[1]->SetMarkerStyle(25);
2118   fQCorrelations[1]->SetLabelSize(0.03);
2119   fQCorrelations[1]->SetLabelOffset(0.01,"Y");
2120   // 2-particle correlations:
2121   (fQCorrelations[1]->GetXaxis())->SetBinLabel(1,"<w_{1}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
2122   (fQCorrelations[1]->GetXaxis())->SetBinLabel(2,"<w_{1}^{2}w_{2}^{2}cos(2n(#phi_{1}-#phi_{2}))>");
2123   (fQCorrelations[1]->GetXaxis())->SetBinLabel(3,"<w_{1}^{3}w_{2}^{3}cos(3n(#phi_{1}-#phi_{2}))>");
2124   (fQCorrelations[1]->GetXaxis())->SetBinLabel(4,"<w_{1}^{4}w_{2}^{4}cos(4n(#phi_{1}-#phi_{2}))>");
2125   (fQCorrelations[1]->GetXaxis())->SetBinLabel(5,"<w_{1}^{3}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
2126   (fQCorrelations[1]->GetXaxis())->SetBinLabel(6,"<w_{1}^{2}w_{2}w_{3}cos(n(#phi_{1}-#phi_{2}))>");
2127   // 3-particle correlations:
2128   (fQCorrelations[1]->GetXaxis())->SetBinLabel(21,"<w_{1}w_{2}w_{3}^{2}cos(n(2#phi_{1}-#phi_{2}-#phi_{3}))>");
2129   // 4-particle correlations:
2130   (fQCorrelations[1]->GetXaxis())->SetBinLabel(41,"<w_{1}w_{2}w_{3}w_{4}cos(n(#phi_{1}+#phi_{2}-#phi_{3}-#phi_{4}))>");
2131   // add fQCorrelations[1] to the list fIntFlowList:
2132   fIntFlowList->Add(fQCorrelations[1]); 
2133  */
2134   
2135 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
2136
2137
2138 //================================================================================================================================
2139
2140
2141 void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2142 {
2143  // Initialize arrays of all objects relevant for calculations with nested loops.
2144  
2145  // integrated flow:
2146  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2147  {
2148   fIntFlowDirectCorrectionTermsForNUA[sc] = NULL;
2149  } 
2150
2151  // differential flow:  
2152  // correlations:
2153  for(Int_t t=0;t<2;t++) // type: RP or POI
2154  { 
2155   for(Int_t pe=0;pe<2;pe++) // pt or eta
2156   {
2157    for(Int_t ci=0;ci<4;ci++) // correlation index
2158    {
2159     fDiffFlowDirectCorrelations[t][pe][ci] = NULL;
2160    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
2161   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2162  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2163  // correction terms for non-uniform acceptance:
2164  for(Int_t t=0;t<2;t++) // type: RP or POI
2165  { 
2166   for(Int_t pe=0;pe<2;pe++) // pt or eta
2167   {
2168    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2169    {
2170     for(Int_t cti=0;cti<9;cti++) // correction term index
2171     {
2172      fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] = NULL;
2173     }   
2174    }
2175   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
2176  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
2177
2178
2179 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForNestedLoops()
2180
2181
2182 //================================================================================================================================
2183
2184
2185 void AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2186 {
2187  // Book all objects relevant for calculations with nested loops.
2188  
2189  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
2190  TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
2191  TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
2192  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
2193  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
2194  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
2195
2196  TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
2197  evaluateNestedLoopsName += fAnalysisLabel->Data();
2198  fEvaluateNestedLoops = new TProfile(evaluateNestedLoopsName.Data(),"Flags for nested loops",4,0,4);
2199  fEvaluateNestedLoops->SetLabelSize(0.03);
2200  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(1,"fEvaluateIntFlowNestedLoops");
2201  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(2,"fEvaluateDiffFlowNestedLoops");
2202  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(3,"fCrossCheckInPtBinNo");
2203  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(4,"fCrossCheckInEtaBinNo");
2204  fEvaluateNestedLoops->Fill(0.5,(Int_t)fEvaluateIntFlowNestedLoops);
2205  fEvaluateNestedLoops->Fill(1.5,(Int_t)fEvaluateDiffFlowNestedLoops);
2206  fEvaluateNestedLoops->Fill(2.5,fCrossCheckInPtBinNo);
2207  fEvaluateNestedLoops->Fill(3.5,fCrossCheckInEtaBinNo);
2208  fNestedLoopsList->Add(fEvaluateNestedLoops);
2209  // nested loops for integrated flow:
2210  if(fEvaluateIntFlowNestedLoops)
2211  {
2212   // correlations:
2213   TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
2214   intFlowDirectCorrelationsName += fAnalysisLabel->Data();
2215   fIntFlowDirectCorrelations = new TProfile(intFlowDirectCorrelationsName.Data(),"Multiparticle correlations calculated with nested loops (for int. flow)",32,0,32,"s");
2216   fNestedLoopsList->Add(fIntFlowDirectCorrelations);
2217   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
2218   {
2219    TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
2220    intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
2221    fIntFlowExtraDirectCorrelations = new TProfile(intFlowExtraDirectCorrelationsName.Data(),"Extra multiparticle correlations calculated with nested loops (for int. flow)",100,0,100,"s");
2222    fNestedLoopsList->Add(fIntFlowExtraDirectCorrelations);  
2223   } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
2224   // correction terms for non-uniform acceptance:
2225   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
2226   {
2227    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
2228    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2229    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");
2230    fNestedLoopsList->Add(fIntFlowDirectCorrectionTermsForNUA[sc]);
2231   } // end of for(Int_t sc=0;sc<2;sc++) 
2232  } // end of if(fEvaluateIntFlowNestedLoops)
2233  
2234  // nested loops for differential flow: 
2235  if(fEvaluateDiffFlowNestedLoops)
2236  {
2237   // reduced correlations:
2238   TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
2239   diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
2240   for(Int_t t=0;t<2;t++) // type: RP or POI
2241   { 
2242    for(Int_t pe=0;pe<2;pe++) // pt or eta
2243    {
2244     for(Int_t rci=0;rci<4;rci++) // reduced correlation index
2245     {
2246      // reduced correlations:
2247      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");
2248      fDiffFlowDirectCorrelations[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
2249      fNestedLoopsList->Add(fDiffFlowDirectCorrelations[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
2250     } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
2251    } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
2252   } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
2253   // correction terms for non-uniform acceptance:
2254   TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
2255   diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
2256   for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
2257   { 
2258    for(Int_t pe=0;pe<2;pe++) // pt or eta
2259    {
2260     for(Int_t sc=0;sc<2;sc++) // sin or cos
2261     {
2262      for(Int_t cti=0;cti<9;cti++) // correction term index
2263      {
2264       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"); 
2265       fNestedLoopsList->Add(fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]);
2266      }
2267     }
2268    }
2269   } 
2270   // number of RPs and POIs in selected pt and eta bins for cross-checkings:
2271   TString noOfParticlesInBinName = "fNoOfParticlesInBin";
2272   fNoOfParticlesInBin = new TH1D(noOfParticlesInBinName.Data(),"Number of RPs and POIs in selected p_{T} and #eta bin",4,0,4);
2273   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(1,"# of RPs in p_{T} bin");
2274   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(2,"# of RPs in #eta bin");
2275   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(3,"# of POIs in p_{T} bin");
2276   fNoOfParticlesInBin->GetXaxis()->SetBinLabel(4,"# of POIs in #eta bin");
2277   fNestedLoopsList->Add(fNoOfParticlesInBin);
2278  } // end of if(fEvaluateDiffFlowNestedLoops)
2279
2280 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
2281
2282
2283 //================================================================================================================================
2284
2285
2286 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
2287 {
2288  // calculate all correlations needed for integrated flow
2289  
2290  // multiplicity:
2291  Double_t dMult = (*fSMpk)(0,0);
2292  
2293  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
2294  Double_t dReQ1n = (*fReQ)(0,0);
2295  Double_t dReQ2n = (*fReQ)(1,0);
2296  Double_t dReQ3n = (*fReQ)(2,0);
2297  Double_t dReQ4n = (*fReQ)(3,0);
2298  Double_t dImQ1n = (*fImQ)(0,0);
2299  Double_t dImQ2n = (*fImQ)(1,0);
2300  Double_t dImQ3n = (*fImQ)(2,0);
2301  Double_t dImQ4n = (*fImQ)(3,0);
2302   
2303  // real and imaginary parts of some expressions involving various combinations of Q-vectors evaluated in harmonics n, 2n, 3n and 4n:
2304  // (these expression appear in the Eqs. for the multi-particle correlations bellow)
2305  
2306  // Re[Q_{2n} Q_{n}^* Q_{n}^*]
2307  Double_t reQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dReQ2n + 2.*dReQ1n*dImQ1n*dImQ2n - pow(dImQ1n,2.)*dReQ2n; 
2308  
2309  // Im[Q_{2n} Q_{n}^* Q_{n}^*]
2310  //Double_t imQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dImQ2n-2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n; 
2311  
2312  // Re[Q_{n} Q_{n} Q_{2n}^*] = Re[Q_{2n} Q_{n}^* Q_{n}^*]
2313  Double_t reQ1nQ1nQ2nstar = reQ2nQ1nstarQ1nstar; 
2314  
2315  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
2316  Double_t reQ3nQ1nQ2nstarQ2nstar = (pow(dReQ2n,2.)-pow(dImQ2n,2.))*(dReQ3n*dReQ1n-dImQ3n*dImQ1n) 
2317                                  + 2.*dReQ2n*dImQ2n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
2318
2319  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]                                                                  
2320  //Double_t imQ3nQ1nQ2nstarQ2nstar = calculate and implement this (deleteMe)
2321   
2322  // Re[Q_{2n} Q_{2n} Q_{3n}^* Q_{1n}^*] = Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
2323  Double_t reQ2nQ2nQ3nstarQ1nstar = reQ3nQ1nQ2nstarQ2nstar;
2324   
2325  // Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
2326  Double_t reQ4nQ2nstarQ2nstar = pow(dReQ2n,2.)*dReQ4n+2.*dReQ2n*dImQ2n*dImQ4n-pow(dImQ2n,2.)*dReQ4n;
2327
2328  // Im[Q_{4n} Q_{2n}^* Q_{2n}^*]
2329  //Double_t imQ4nQ2nstarQ2nstar = calculate and implement this (deleteMe)
2330  
2331  // Re[Q_{2n} Q_{2n} Q_{4n}^*] =  Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
2332  Double_t reQ2nQ2nQ4nstar = reQ4nQ2nstarQ2nstar;
2333  
2334  // Re[Q_{4n} Q_{3n}^* Q_{n}^*]
2335  Double_t reQ4nQ3nstarQ1nstar = dReQ4n*(dReQ3n*dReQ1n-dImQ3n*dImQ1n)+dImQ4n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
2336  
2337  // Re[Q_{3n} Q_{n} Q_{4n}^*] = Re[Q_{4n} Q_{3n}^* Q_{n}^*]
2338  Double_t reQ3nQ1nQ4nstar = reQ4nQ3nstarQ1nstar;
2339  
2340  // Im[Q_{4n} Q_{3n}^* Q_{n}^*]
2341  //Double_t imQ4nQ3nstarQ1nstar = calculate and implement this (deleteMe)
2342
2343  // Re[Q_{3n} Q_{2n}^* Q_{n}^*]
2344  Double_t reQ3nQ2nstarQ1nstar = dReQ3n*dReQ2n*dReQ1n-dReQ3n*dImQ2n*dImQ1n+dImQ3n*dReQ2n*dImQ1n
2345                               + dImQ3n*dImQ2n*dReQ1n;
2346                               
2347  // Re[Q_{2n} Q_{n} Q_{3n}^*] = Re[Q_{3n} Q_{2n}^* Q_{n}^*]
2348  Double_t reQ2nQ1nQ3nstar = reQ3nQ2nstarQ1nstar;
2349  
2350  // Im[Q_{3n} Q_{2n}^* Q_{n}^*]
2351  //Double_t imQ3nQ2nstarQ1nstar; //calculate and implement this (deleteMe)
2352  
2353  // Re[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2354  Double_t reQ3nQ1nstarQ1nstarQ1nstar = dReQ3n*pow(dReQ1n,3)-3.*dReQ1n*dReQ3n*pow(dImQ1n,2)
2355                                      + 3.*dImQ1n*dImQ3n*pow(dReQ1n,2)-dImQ3n*pow(dImQ1n,3);
2356
2357  // Im[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
2358  //Double_t imQ3nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2359  
2360  // |Q_{2n}|^2 |Q_{n}|^2
2361  Double_t dQ2nQ1nQ2nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
2362  
2363  // Re[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2364  Double_t reQ4nQ2nstarQ1nstarQ1nstar = (dReQ4n*dReQ2n+dImQ4n*dImQ2n)*(pow(dReQ1n,2)-pow(dImQ1n,2))
2365                                      + 2.*dReQ1n*dImQ1n*(dImQ4n*dReQ2n-dReQ4n*dImQ2n); 
2366  
2367  // Im[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2368  //Double_t imQ4nQ2nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2369  
2370  // Re[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*]
2371  Double_t reQ2nQ1nQ1nstarQ1nstarQ1nstar = (dReQ2n*dReQ1n-dImQ2n*dImQ1n)*(pow(dReQ1n,3)-3.*dReQ1n*pow(dImQ1n,2))
2372                                         + (dReQ2n*dImQ1n+dReQ1n*dImQ2n)*(3.*dImQ1n*pow(dReQ1n,2)-pow(dImQ1n,3));
2373
2374  // Im[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*] 
2375  //Double_t imQ2nQ1nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
2376  
2377  // Re[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2378  Double_t reQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2379                                         * (dReQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) + 2.*dImQ2n*dReQ1n*dImQ1n);
2380
2381  // Im[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2382  //Double_t imQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2383  //                                       * (dImQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) - 2.*dReQ2n*dReQ1n*dImQ1n);
2384  
2385  // Re[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2386  Double_t reQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dReQ4n-6.*pow(dReQ1n,2.)*dReQ4n*pow(dImQ1n,2.)
2387                                             + pow(dImQ1n,4.)*dReQ4n+4.*pow(dReQ1n,3.)*dImQ1n*dImQ4n
2388                                             - 4.*pow(dImQ1n,3.)*dReQ1n*dImQ4n;
2389                                             
2390  // Im[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2391  //Double_t imQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dImQ4n-6.*pow(dReQ1n,2.)*dImQ4n*pow(dImQ1n,2.)
2392  //                                           + pow(dImQ1n,4.)*dImQ4n+4.*pow(dImQ1n,3.)*dReQ1n*dReQ4n
2393  //                                           - 4.*pow(dReQ1n,3.)*dImQ1n*dReQ4n;
2394  
2395  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2396  Double_t reQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2397                                         * (dReQ1n*dReQ2n*dReQ3n-dReQ3n*dImQ1n*dImQ2n+dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n);
2398  
2399  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
2400  //Double_t imQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2401  //                                       * (-dReQ2n*dReQ3n*dImQ1n-dReQ1n*dReQ3n*dImQ2n+dReQ1n*dReQ2n*dImQ3n-dImQ1n*dImQ2n*dImQ3n);
2402  
2403  
2404  // Re[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2405  Double_t reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)*dReQ2n-2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2406                                                + dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n-pow(dImQ1n,2.)*dImQ2n)
2407                                                * (pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
2408                                                - dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n+pow(dImQ1n,2.)*dImQ2n);
2409  
2410  // Im[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2411  //Double_t imQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = 2.*(pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2412  //                                              + 2.*dReQ1n*dImQ1n*dImQ2n)*(pow(dReQ1n,2.)*dImQ2n
2413  //                                              - 2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n);
2414  
2415  // Re[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2416  Double_t reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2417                                                * (pow(dReQ1n,3.)*dReQ3n-3.*dReQ1n*dReQ3n*pow(dImQ1n,2.)
2418                                                + 3.*pow(dReQ1n,2.)*dImQ1n*dImQ3n-pow(dImQ1n,3.)*dImQ3n);
2419   
2420  // Im[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                                                           
2421  //Double_t imQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
2422  //                                              * (pow(dImQ1n,3.)*dReQ3n-3.*dImQ1n*dReQ3n*pow(dReQ1n,2.)
2423  //                                              - 3.*pow(dImQ1n,2.)*dReQ1n*dImQ3n+pow(dReQ1n,3.)*dImQ3n);
2424  
2425  // |Q_{2n}|^2 |Q_{n}|^4
2426  Double_t dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.);
2427  
2428  // Re[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
2429  Double_t reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2430                                                   * (pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
2431                                                   + 2.*dReQ1n*dImQ1n*dImQ2n);
2432                                                   
2433  // Im[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                  
2434  //Double_t imQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2435  //                                                 * (pow(dReQ1n,2.)*dImQ2n-dImQ2n*pow(dImQ1n,2.)
2436  //                                                 - 2.*dReQ1n*dReQ2n*dImQ1n);
2437  
2438   
2439  
2440        
2441  //                                        **************************************
2442  //                                        **** multi-particle correlations: ****
2443  //                                        **************************************
2444  //
2445  // Remark 1: multi-particle correlations calculated with non-weighted Q-vectors are stored in 1D profile fQCorrelations[0]. // to be improved (wrong profiles)
2446  // Remark 2: binning of fQCorrelations[0] is organized as follows: // to be improved (wrong profiles)
2447  // --------------------------------------------------------------------------------------------------------------------
2448  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
2449  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
2450  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
2451  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
2452  //  5th bin:           ----  EMPTY ----
2453  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
2454  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
2455  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2456  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
2457  // 10th bin:           ----  EMPTY ----
2458  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
2459  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
2460  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
2461  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2462  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
2463  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
2464  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
2465  // 18th bin:           ----  EMPTY ----
2466  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2467  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2468  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2469  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2470  // 23rd bin:           ----  EMPTY ----
2471  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2472  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2473  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2474  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2475  // 28th bin:           ----  EMPTY ----
2476  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2477  // 30th bin:           ----  EMPTY ----
2478  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2479  // --------------------------------------------------------------------------------------------------------------------
2480     
2481  // 2-particle:
2482  Double_t two1n1n = 0.; // <cos(n*(phi1-phi2))>
2483  Double_t two2n2n = 0.; // <cos(2n*(phi1-phi2))>
2484  Double_t two3n3n = 0.; // <cos(3n*(phi1-phi2))>
2485  Double_t two4n4n = 0.; // <cos(4n*(phi1-phi2))>
2486  
2487  if(dMult>1)
2488  {
2489   two1n1n = (pow(dReQ1n,2.)+pow(dImQ1n,2.)-dMult)/(dMult*(dMult-1.)); 
2490   two2n2n = (pow(dReQ2n,2.)+pow(dImQ2n,2.)-dMult)/(dMult*(dMult-1.)); 
2491   two3n3n = (pow(dReQ3n,2.)+pow(dImQ3n,2.)-dMult)/(dMult*(dMult-1.)); 
2492   two4n4n = (pow(dReQ4n,2.)+pow(dImQ4n,2.)-dMult)/(dMult*(dMult-1.)); 
2493   
2494   // average 2-particle correlations for single event: 
2495   fIntFlowCorrelationsAllEBE->SetBinContent(1,two1n1n);
2496   fIntFlowCorrelationsAllEBE->SetBinContent(2,two2n2n);
2497   fIntFlowCorrelationsAllEBE->SetBinContent(3,two3n3n);
2498   fIntFlowCorrelationsAllEBE->SetBinContent(4,two4n4n);
2499           
2500   // average 2-particle correlations for all events:      
2501   fIntFlowCorrelationsAllPro->Fill(0.5,two1n1n,dMult*(dMult-1.));  
2502   fIntFlowCorrelationsAllPro->Fill(1.5,two2n2n,dMult*(dMult-1.)); 
2503   fIntFlowCorrelationsAllPro->Fill(2.5,two3n3n,dMult*(dMult-1.)); 
2504   fIntFlowCorrelationsAllPro->Fill(3.5,two4n4n,dMult*(dMult-1.)); 
2505   
2506   // store separetately <2> (to be improved: do I really need this?)
2507   fIntFlowCorrelationsEBE->SetBinContent(1,two1n1n); // <2>
2508   
2509   // to be improved (this can be implemented better):
2510   Double_t mWeight2p = 0.;
2511   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2512   {
2513    mWeight2p = dMult*(dMult-1.);
2514   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2515     {
2516      mWeight2p = 1.;    
2517     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2518       {
2519        mWeight2p = dMult;           
2520       }
2521             
2522   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,mWeight2p); // eW_<2>
2523   fIntFlowCorrelationsPro->Fill(0.5,two1n1n,mWeight2p);
2524   if(fCalculateCumulantsVsM){fIntFlowCorrelationsVsMPro[0]->Fill(dMult+0.5,two1n1n,mWeight2p);} 
2525     
2526   // distribution of <cos(n*(phi1-phi2))>:
2527   //f2pDistribution->Fill(two1n1n,dMult*(dMult-1.)); 
2528  } // end of if(dMult>1)
2529  
2530  // 3-particle:
2531  Double_t three2n1n1n = 0.; // <cos(n*(2.*phi1-phi2-phi3))>
2532  Double_t three3n2n1n = 0.; // <cos(n*(3.*phi1-2.*phi2-phi3))>
2533  Double_t three4n2n2n = 0.; // <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
2534  Double_t three4n3n1n = 0.; // <cos(n*(4.*phi1-3.*phi2-phi3))>
2535  
2536  if(dMult>2)
2537  {
2538   three2n1n1n = (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2539               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
2540               / (dMult*(dMult-1.)*(dMult-2.));                     
2541   three3n2n1n = (reQ3nQ2nstarQ1nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2542               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))
2543               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2544               / (dMult*(dMult-1.)*(dMult-2.));
2545   three4n2n2n = (reQ4nQ2nstarQ2nstar-2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2546               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*dMult)
2547               / (dMult*(dMult-1.)*(dMult-2.)); 
2548   three4n3n1n = (reQ4nQ3nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2549               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
2550               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
2551               / (dMult*(dMult-1.)*(dMult-2.)); 
2552               
2553   // average 3-particle correlations for single event: 
2554   fIntFlowCorrelationsAllEBE->SetBinContent(6,three2n1n1n);
2555   fIntFlowCorrelationsAllEBE->SetBinContent(7,three3n2n1n);
2556   fIntFlowCorrelationsAllEBE->SetBinContent(8,three4n2n2n);
2557   fIntFlowCorrelationsAllEBE->SetBinContent(9,three4n3n1n);
2558         
2559   // average 3-particle correlations for all events:                
2560   fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.)); 
2561   fIntFlowCorrelationsAllPro->Fill(6.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
2562   fIntFlowCorrelationsAllPro->Fill(7.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.)); 
2563   fIntFlowCorrelationsAllPro->Fill(8.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));    
2564  } // end of if(dMult>2)
2565  
2566  // 4-particle:
2567  Double_t four1n1n1n1n = 0.; // <cos(n*(phi1+phi2-phi3-phi4))>
2568  Double_t four2n2n2n2n = 0.; // <cos(2.*n*(phi1+phi2-phi3-phi4))>
2569  Double_t four2n1n2n1n = 0.; // <cos(n*(2.*phi1+phi2-2.*phi3-phi4))> 
2570  Double_t four3n1n1n1n = 0.; // <cos(n*(3.*phi1-phi2-phi3-phi4))> 
2571  Double_t four4n2n1n1n = 0.; // <cos(n*(4.*phi1-2.*phi2-phi3-phi4))> 
2572  Double_t four3n1n2n2n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))> 
2573  Double_t four3n1n3n1n = 0.; // <cos(n*(3.*phi1+phi2-3.*phi3-phi4))>   
2574  
2575  if(dMult>3)
2576  {
2577   four1n1n1n1n = (2.*dMult*(dMult-3.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ1n,2.)
2578                + pow(dImQ1n,2.))-2.*reQ2nQ1nstarQ1nstar+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2579                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));     
2580   four2n2n2n2n = (2.*dMult*(dMult-3.)+pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ2n,2.)
2581                + pow(dImQ2n,2.))-2.*reQ4nQ2nstarQ2nstar+(pow(dReQ4n,2.)+pow(dImQ4n,2.)))
2582                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));
2583   four2n1n2n1n = (dQ2nQ1nQ2nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar-2.*reQ2nQ1nstarQ1nstar)
2584                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2585                - ((dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2586                + (dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2587                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2588                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2589   four3n1n1n1n = (reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar-3.*reQ2nQ1nstarQ1nstar)
2590                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2591                + (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2592                + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
2593                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2594   four4n2n1n1n = (reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar)
2595                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2596                - (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2597                - 3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2598                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2599                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2600   four3n1n2n2n = (reQ3nQ1nQ2nstarQ2nstar-reQ4nQ2nstarQ2nstar-reQ3nQ1nQ4nstar-2.*reQ3nQ2nstarQ1nstar)
2601                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2602                - (2.*reQ1nQ1nQ2nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2603                - 4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2604                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2605                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.)); 
2606   four3n1n3n1n = ((pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2607                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar)
2608                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2609                + ((pow(dReQ4n,2.)+pow(dImQ4n,2.))-(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2610                + (pow(dReQ2n,2.)+pow(dImQ2n,2.))-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2611                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
2612                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
2613                
2614   // average 4-particle correlations for single event: 
2615   fIntFlowCorrelationsAllEBE->SetBinContent(11,four1n1n1n1n);
2616   fIntFlowCorrelationsAllEBE->SetBinContent(12,four2n1n2n1n);
2617   fIntFlowCorrelationsAllEBE->SetBinContent(13,four2n2n2n2n);
2618   fIntFlowCorrelationsAllEBE->SetBinContent(14,four3n1n1n1n);
2619   fIntFlowCorrelationsAllEBE->SetBinContent(15,four3n1n3n1n);
2620   fIntFlowCorrelationsAllEBE->SetBinContent(16,four3n1n2n2n);
2621   fIntFlowCorrelationsAllEBE->SetBinContent(17,four4n2n1n1n);
2622         
2623   // average 4-particle correlations for all events:                
2624   fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2625   fIntFlowCorrelationsAllPro->Fill(11.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2626   fIntFlowCorrelationsAllPro->Fill(12.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2627   fIntFlowCorrelationsAllPro->Fill(13.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2628   fIntFlowCorrelationsAllPro->Fill(14.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2629   fIntFlowCorrelationsAllPro->Fill(15.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
2630   fIntFlowCorrelationsAllPro->Fill(16.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
2631   
2632   // store separetately <4> (to be improved: do I really need this?)
2633   fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1n); // <4>
2634   
2635   // to be improved (this can be implemented better):
2636   Double_t mWeight4p = 0.;
2637   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2638   {
2639    mWeight4p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.);
2640   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2641     {
2642      mWeight4p = 1.;    
2643     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2644       {
2645        mWeight4p = dMult;           
2646       }
2647       
2648   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,mWeight4p); // eW_<4>
2649   fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1n,mWeight4p);
2650   if(fCalculateCumulantsVsM){fIntFlowCorrelationsVsMPro[1]->Fill(dMult+0.5,four1n1n1n1n,mWeight4p);} 
2651   
2652   // distribution of <cos(n*(phi1+phi2-phi3-phi4))>
2653   //f4pDistribution->Fill(four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
2654   
2655  } // end of if(dMult>3)
2656
2657  // 5-particle:
2658  Double_t five2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
2659  Double_t five2n2n2n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
2660  Double_t five3n1n2n1n1n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
2661  Double_t five4n1n1n1n1n = 0.; // <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
2662  
2663  if(dMult>4)
2664  {
2665   five2n1n1n1n1n = (reQ2nQ1nQ1nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar+6.*reQ3nQ2nstarQ1nstar)
2666                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2667                  - (reQ2nQ1nQ3nstar+3.*(dMult-6.)*reQ2nQ1nstarQ1nstar+3.*reQ1nQ1nQ2nstar)
2668                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2669                  - (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2670                  + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))     
2671                  - 3.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2672                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2673                  - 3.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2674                  - 2.*(2*dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult*(dMult-4.))
2675                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2676                  
2677   five2n2n2n1n1n = (reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ2nQ2nQ3nstarQ1nstar)
2678                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2679                  + 2.*(reQ4nQ2nstarQ2nstar+4.*reQ3nQ2nstarQ1nstar+reQ3nQ1nQ4nstar)
2680                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2681                  + (reQ2nQ2nQ4nstar-2.*(dMult-5.)*reQ2nQ1nstarQ1nstar+2.*reQ1nQ1nQ2nstar)
2682                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2683                  - (2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2684                  + 1.*pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)
2685                  - 2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2686                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2687                  - (4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2688                  - 4.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+4.*dMult*(dMult-6.))
2689                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2690
2691   five4n1n1n1n1n = (reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ4nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nstarQ1nstarQ1nstar)
2692                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2693                  + (8.*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+12.*reQ3nQ2nstarQ1nstar+12.*reQ2nQ1nstarQ1nstar)
2694                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2695                  - (6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+8.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
2696                  + 12.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-24.*dMult)
2697                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2698   
2699   five3n1n2n1n1n = (reQ3nQ1nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar)
2700                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2701                  - (reQ3nQ1nQ2nstarQ2nstar-3.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar)
2702                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2703                  - ((2.*dMult-13.)*reQ3nQ2nstarQ1nstar-reQ3nQ1nQ4nstar-9.*reQ2nQ1nstarQ1nstar)
2704                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2705                  - (2.*reQ1nQ1nQ2nstar+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
2706                  - 2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+2.*(pow(dReQ3n,2.)
2707                  + pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2708                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2709                  + (2.*(dMult-6.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
2710                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
2711                  - pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
2712                  + 2.*(3.*dMult-11.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2713                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
2714                  - 4.*(dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2715                  
2716   // average 5-particle correlations for single event: 
2717   fIntFlowCorrelationsAllEBE->SetBinContent(19,five2n1n1n1n1n);
2718   fIntFlowCorrelationsAllEBE->SetBinContent(20,five2n2n2n1n1n);
2719   fIntFlowCorrelationsAllEBE->SetBinContent(21,five3n1n2n1n1n);
2720   fIntFlowCorrelationsAllEBE->SetBinContent(22,five4n1n1n1n1n);
2721         
2722   // average 5-particle correlations for all events:                         
2723   fIntFlowCorrelationsAllPro->Fill(18.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
2724   fIntFlowCorrelationsAllPro->Fill(19.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2725   fIntFlowCorrelationsAllPro->Fill(20.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2726   fIntFlowCorrelationsAllPro->Fill(21.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
2727  } // end of if(dMult>4)
2728     
2729  // 6-particle:
2730  Double_t six1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2731  Double_t six2n2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
2732  Double_t six3n1n1n1n1n1n = 0.; // <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
2733  Double_t six2n1n1n2n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
2734  
2735  if(dMult>5)
2736  {
2737   six1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)+9.*dQ2nQ1nQ2nstarQ1nstar-6.*reQ2nQ1nQ1nstarQ1nstarQ1nstar)
2738                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2739                   + 4.*(reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar)
2740                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2741                   + 2.*(9.*(dMult-4.)*reQ2nQ1nstarQ1nstar+2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
2742                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
2743                   - 9.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
2744                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-5.))
2745                   + (18.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
2746                   / (dMult*(dMult-1)*(dMult-3)*(dMult-4))
2747                   - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
2748                   
2749   six2n1n1n2n1n1n = (dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2750                   * (2.*five2n2n2n1n1n+4.*five2n1n1n1n1n+4.*five3n1n2n1n1n+4.*four2n1n2n1n+1.*four1n1n1n1n)
2751                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four1n1n1n1n+4.*two1n1n
2752                   + 2.*three2n1n1n+2.*three2n1n1n+4.*four3n1n1n1n+8.*three2n1n1n+2.*four4n2n1n1n
2753                   + 4.*four2n1n2n1n+2.*two2n2n+8.*four2n1n2n1n+4.*four3n1n3n1n+8.*three3n2n1n
2754                   + 4.*four3n1n2n2n+4.*four1n1n1n1n+4.*four2n1n2n1n+1.*four2n2n2n2n)
2755                   - dMult*(dMult-1.)*(dMult-2.)*(2.*three2n1n1n+8.*two1n1n+4.*two1n1n+2.
2756                   + 4.*two1n1n+4.*three2n1n1n+2.*two2n2n+4.*three2n1n1n+8.*three3n2n1n
2757                   + 8.*two2n2n+4.*three4n3n1n+4.*two3n3n+4.*three3n2n1n+4.*two1n1n
2758                   + 8.*three2n1n1n+4.*two1n1n+4.*three3n2n1n+4.*three2n1n1n+2.*two2n2n
2759                   + 4.*three3n2n1n+2.*three4n2n2n)-dMult*(dMult-1.)
2760                   * (4.*two1n1n+4.+4.*two1n1n+2.*two2n2n+1.+4.*two1n1n+4.*two2n2n+4.*two3n3n
2761                   + 1.+2.*two2n2n+1.*two4n4n)-dMult)
2762                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2763  
2764   six2n2n1n1n1n1n = (reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2765                   * (five4n1n1n1n1n+8.*five2n1n1n1n1n+6.*five2n2n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2766                   * (4.*four3n1n1n1n+6.*four4n2n1n1n+12.*three2n1n1n+12.*four1n1n1n1n+24.*four2n1n2n1n
2767                   + 4.*four3n1n2n2n+3.*four2n2n2n2n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n
2768                   + 4.*three4n3n1n+3.*three4n2n2n+8.*three2n1n1n+24.*two1n1n+12.*two2n2n+12.*three2n1n1n+8.*three3n2n1n
2769                   + 1.*three4n2n2n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+2.*two2n2n+8.*two1n1n+6.)-dMult)
2770                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2771    
2772   six3n1n1n1n1n1n = (reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
2773                   * (five4n1n1n1n1n+4.*five2n1n1n1n1n+6.*five3n1n2n1n1n+4.*four3n1n1n1n)
2774                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+6.*four1n1n1n1n
2775                   + 12.*three2n1n1n+12.*four2n1n2n1n+6.*four3n1n1n1n+12.*three3n2n1n+4.*four3n1n3n1n+3.*four3n1n2n2n)
2776                   - dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n+4.*three4n3n1n+3.*three4n2n2n+4.*two1n1n
2777                   + 12.*two1n1n+6.*three2n1n1n+12.*three2n1n1n+4.*three3n2n1n+12.*two2n2n+4.*three3n2n1n+4.*two3n3n+1.*three4n3n1n
2778                   + 6.*three3n2n1n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+1.*two1n1n+4.+6.*two1n1n+4.*two2n2n
2779                   + 1.*two3n3n)-dMult)/(dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
2780                                  
2781   // average 6-particle correlations for single event: 
2782   fIntFlowCorrelationsAllEBE->SetBinContent(24,six1n1n1n1n1n1n);
2783   fIntFlowCorrelationsAllEBE->SetBinContent(25,six2n1n1n2n1n1n);
2784   fIntFlowCorrelationsAllEBE->SetBinContent(26,six2n2n1n1n1n1n);
2785   fIntFlowCorrelationsAllEBE->SetBinContent(27,six3n1n1n1n1n1n);
2786         
2787   // average 6-particle correlations for all events:         
2788   fIntFlowCorrelationsAllPro->Fill(23.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2789   fIntFlowCorrelationsAllPro->Fill(24.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2790   fIntFlowCorrelationsAllPro->Fill(25.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
2791   fIntFlowCorrelationsAllPro->Fill(26.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2792
2793   // store separetately <6> (to be improved: do I really need this?)
2794   fIntFlowCorrelationsEBE->SetBinContent(3,six1n1n1n1n1n1n); // <6>
2795   
2796   // to be improved (this can be implemented better):
2797   Double_t mWeight6p = 0.;
2798   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2799   {
2800    mWeight6p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.);
2801   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2802     {
2803      mWeight6p = 1.;    
2804     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2805       {
2806        mWeight6p = dMult;           
2807       }
2808       
2809   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(3,mWeight6p); // eW_<6>
2810   fIntFlowCorrelationsPro->Fill(2.5,six1n1n1n1n1n1n,mWeight6p);
2811   if(fCalculateCumulantsVsM){fIntFlowCorrelationsVsMPro[2]->Fill(dMult+0.5,six1n1n1n1n1n1n,mWeight6p);}   
2812  
2813   // distribution of <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
2814   //f6pDistribution->Fill(six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
2815  } // end of if(dMult>5)
2816  
2817  // 7-particle:
2818  Double_t seven2n1n1n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
2819  
2820  if(dMult>6)
2821  {
2822   seven2n1n1n1n1n1n1n = (reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2823                       * (2.*six3n1n1n1n1n1n+4.*six1n1n1n1n1n1n+1.*six2n2n1n1n1n1n+6.*six2n1n1n2n1n1n+8.*five2n1n1n1n1n)
2824                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(1.*five4n1n1n1n1n +8.*five2n1n1n1n1n+8.*four3n1n1n1n
2825                       + 12.*five3n1n2n1n1n+4.*five2n1n1n1n1n+3.*five2n2n2n1n1n+6.*five2n2n2n1n1n+6.*four1n1n1n1n+24.*four1n1n1n1n
2826                       + 12.*five2n1n1n1n1n+12.*five2n1n1n1n1n+12.*three2n1n1n+24.*four2n1n2n1n+4.*five3n1n2n1n1n+4.*five2n1n1n1n1n)
2827                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+12.*four1n1n1n1n+24.*three2n1n1n
2828                       + 24.*four2n1n2n1n+12.*four3n1n1n1n+24.*three3n2n1n+8.*four3n1n3n1n+6.*four3n1n2n2n+6.*three2n1n1n+12.*four1n1n1n1n
2829                       + 12.*four2n1n2n1n+6.*three2n1n1n+12.*four2n1n2n1n+4.*four3n1n2n2n+3.*four2n2n2n2n+4.*four1n1n1n1n+6.*three2n1n1n
2830                       + 24.*two1n1n+24.*four1n1n1n1n+4.*four3n1n1n1n+24.*two1n1n+24.*three2n1n1n+12.*two2n2n+24.*three2n1n1n+12.*four2n1n2n1n
2831                       + 8.*three3n2n1n+8.*four2n1n2n1n+1.*four4n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+1.*three2n1n1n+8.*two1n1n
2832                       + 12.*three3n2n1n+24.*two1n1n+12.*three2n1n1n+4.*three2n1n1n+8.*two1n1n+4.*three4n3n1n+24.*three2n1n1n+8.*three3n2n1n
2833                       + 12.*two1n1n+12.*two1n1n+3.*three4n2n2n+24.*two2n2n+6.*two2n2n+12.+12.*three3n2n1n+8.*two3n3n+12.*three2n1n1n+24.*two1n1n
2834                       + 4.*three3n2n1n+8.*three3n2n1n+2.*three4n3n1n+12.*two1n1n+8.*three2n1n1n+4.*three2n1n1n+2.*three3n2n1n+6.*two2n2n+8.*two2n2n
2835                       + 1.*three4n2n2n+4.*three3n2n1n+6.*three2n1n1n)-dMult*(dMult-1.)*(4.*two1n1n+2.*two1n1n+6.*two2n2n+8.+1.*two2n2n+4.*two3n3n
2836                       + 12.*two1n1n+4.*two1n1n+1.*two4n4n+8.*two2n2n+6.+2.*two3n3n+4.*two1n1n+1.*two2n2n)-dMult)
2837                       / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)); // to be improved (direct formula needed)
2838         
2839   // average 7-particle correlations for single event: 
2840   fIntFlowCorrelationsAllEBE->SetBinContent(29,seven2n1n1n1n1n1n1n);
2841        
2842   // average 7-particle correlations for all events:                      
2843   fIntFlowCorrelationsAllPro->Fill(28.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.));
2844  } // end of if(dMult>6)
2845  
2846  // 8-particle:
2847  Double_t eight1n1n1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2848  if(dMult>7)
2849  {
2850   eight1n1n1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),4.)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)
2851                         * (12.*seven2n1n1n1n1n1n1n+16.*six1n1n1n1n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
2852                         * (8.*six3n1n1n1n1n1n+48.*six1n1n1n1n1n1n+6.*six2n2n1n1n1n1n+96.*five2n1n1n1n1n+72.*four1n1n1n1n+36.*six2n1n1n2n1n1n)
2853                         - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(2.*five4n1n1n1n1n+32.*five2n1n1n1n1n+36.*four1n1n1n1n
2854                         + 32.*four3n1n1n1n+48.*five2n1n1n1n1n+48.*five3n1n2n1n1n+144.*five2n1n1n1n1n+288.*four1n1n1n1n+36.*five2n2n2n1n1n
2855                         + 144.*three2n1n1n+96.*two1n1n+144.*four2n1n2n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
2856                         * (8.*four3n1n1n1n+48.*four1n1n1n1n+12.*four4n2n1n1n+96.*four2n1n2n1n+96.*three2n1n1n+72.*three2n1n1n+144.*two1n1n
2857                         + 16.*four3n1n3n1n+48.*four3n1n1n1n+144.*four1n1n1n1n+72.*four1n1n1n1n+96.*three3n2n1n+24.*four3n1n2n2n+144.*four2n1n2n1n
2858                         + 288.*two1n1n+288.*three2n1n1n+9.*four2n2n2n2n+72.*two2n2n+24.)-dMult*(dMult-1.)*(dMult-2.)*(12.*three2n1n1n+16.*two1n1n
2859                         + 24.*three3n2n1n+48.*three2n1n1n+96.*two1n1n+8.*three4n3n1n+32.*three3n2n1n+96.*three2n1n1n+144.*two1n1n+6.*three4n2n2n
2860                         + 96.*two2n2n+36.*two2n2n+72.+48.*three3n2n1n+16.*two3n3n+72.*three2n1n1n+144.*two1n1n)-dMult*(dMult-1.)*(8.*two1n1n
2861                         + 12.*two2n2n+16.+8.*two3n3n+48.*two1n1n+1.*two4n4n+16.*two2n2n+18.)-dMult)
2862                         / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.)); // to be improved (direct formula needed)
2863   
2864   // average 8-particle correlations for single event: 
2865   fIntFlowCorrelationsAllEBE->SetBinContent(31,eight1n1n1n1n1n1n1n1n);
2866        
2867   // average 8-particle correlations for all events:                       
2868   fIntFlowCorrelationsAllPro->Fill(30.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2869  
2870   // store separetately <8> (to be improved: do I really need this?)
2871   fIntFlowCorrelationsEBE->SetBinContent(4,eight1n1n1n1n1n1n1n1n); // <8>
2872   
2873   // to be improved (this can be implemented better):
2874   Double_t mWeight8p = 0.;
2875   if(!strcmp(fMultiplicityWeight->Data(),"combinations"))
2876   {
2877    mWeight8p = dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.);
2878   } else if(!strcmp(fMultiplicityWeight->Data(),"unit"))
2879     {
2880      mWeight8p = 1.;    
2881     } else if(!strcmp(fMultiplicityWeight->Data(),"multiplicity"))
2882       {
2883        mWeight8p = dMult;           
2884       }
2885         
2886   fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(4,mWeight8p); // eW_<8>
2887   fIntFlowCorrelationsPro->Fill(3.5,eight1n1n1n1n1n1n1n1n,mWeight8p);  
2888   if(fCalculateCumulantsVsM){fIntFlowCorrelationsVsMPro[3]->Fill(dMult+0.5,eight1n1n1n1n1n1n1n1n,mWeight8p);}    
2889   
2890   // distribution of <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
2891   //f8pDistribution->Fill(eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
2892  } // end of if(dMult>7) 
2893  
2894 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelations()
2895
2896
2897 //================================================================================================================================
2898
2899
2900 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
2901 {
2902  // Calculate averages of products of correlations for integrated flow.
2903  
2904  // multiplicity:
2905  Double_t dMult = (*fSMpk)(0,0);
2906  
2907  Int_t counter = 0;
2908  
2909  for(Int_t ci1=1;ci1<4;ci1++)
2910  {
2911   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
2912   {
2913    fIntFlowProductOfCorrelationsPro->Fill(0.5+counter,
2914                                           fIntFlowCorrelationsEBE->GetBinContent(ci1)*
2915                                           fIntFlowCorrelationsEBE->GetBinContent(ci2),
2916                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
2917                                           fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
2918    // products versus multiplicity:  // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]
2919    if(fCalculateCumulantsVsM)
2920    {
2921     fIntFlowProductOfCorrelationsVsMPro[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights ?
2922                                                        fIntFlowCorrelationsEBE->GetBinContent(ci1)*
2923                                                        fIntFlowCorrelationsEBE->GetBinContent(ci2),
2924                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
2925                                                        fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
2926    } // end of if(fCalculateCumulantsVsM)
2927    counter++;                                                                                                                        
2928   }
2929  }
2930  
2931 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrelations()
2932
2933
2934 //================================================================================================================================
2935
2936
2937 void AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
2938 {
2939  // Calculate averages of products of correction terms for NUA.
2940  
2941  // a) Binning of fIntFlowProductOfCorrectionTermsForNUAPro is organized as follows:
2942  //     1st bin: <<2><cos(phi)>> 
2943  //     2nd bin: <<2><sin(phi)>>
2944  //     3rd bin: <<cos(phi)><sin(phi)>>
2945  //     4th bin: <<2><cos(phi1+phi2)>> 
2946  //     5th bin: <<2><sin(phi1+phi2)>>
2947  //     6th bin: <<2><cos(phi1-phi2-phi3)>> 
2948  //     7th bin: <<2><sin(phi1-phi2-phi3)>>
2949  //     8th bin: <<4><cos(phi1)>>
2950  //     9th bin: <<4><sin(phi1)>>
2951  //    10th bin: <<4><cos(phi1+phi2)>>
2952  //    11th bin: <<4><sin(phi1+phi2)>>
2953  //    12th bin: <<4><cos(phi1-phi2-phi3)>>
2954  //    13th bin: <<4><sin(phi1-phi2-phi3)>>
2955  //    14th bin: <<cos(phi1)><cos(phi1+phi2)>>
2956  //    15th bin: <<cos(phi1)><sin(phi1+phi2)>> 
2957  //    16th bin: <<cos(phi1)><cos(phi1-phi2-phi3)>>
2958  //    17th bin: <<cos(phi1)><sin(phi1-phi2-phi3)>> 
2959  //    18th bin: <<sin(phi1)><cos(phi1+phi2)>>
2960  //    19th bin: <<sin(phi1)><sin(phi1+phi2)>> 
2961  //    20th bin: <<sin(phi1)><cos(phi1-phi2-phi3)>>
2962  //    21st bin: <<sin(phi1)><sin(phi1-phi2-phi3)>>
2963  //    22nd bin: <<cos(phi1+phi2)><sin(phi1+phi2)>>
2964  //    23rd bin: <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>
2965  //    24th bin: <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>
2966  //    25th bin: <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>
2967  //    26th bin: <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>
2968  //    27th bin: <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>
2969  
2970  // <<2><cos(phi)>>:
2971  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(0.5,
2972                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
2973                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
2974                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
2975  // <<2><sin(phi)>>:
2976  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(1.5,
2977                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
2978                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
2979                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
2980  // <<cos(phi)><sin(phi)>>:
2981  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(2.5,
2982                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
2983                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
2984                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
2985  // <<2><cos(phi1+phi2)>>:
2986  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(3.5,
2987                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
2988                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
2989                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
2990  // <<2><sin(phi1+phi2)>>:
2991  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(4.5,
2992                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
2993                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
2994                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
2995  // <<2><cos(phi1-phi2-phi3)>>:
2996  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(5.5,
2997                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
2998                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
2999                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3000  // <<2><sin(phi1-phi2-phi3)>>:
3001  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(6.5,
3002                                                  fIntFlowCorrelationsEBE->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3003                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)
3004                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3005  // <<4><cos(phi1)>>:
3006  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(7.5,
3007                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1),
3008                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3009                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
3010  // <<4><sin(phi1)>>:
3011  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(8.5,
3012                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1),
3013                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3014                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
3015  // <<4><cos(phi1+phi2)>>:
3016  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(9.5,
3017                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3018                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3019                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3020  // <<4><sin(phi1+phi2)>>:
3021  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(10.5,
3022                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3023                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3024                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
3025  // <<4><cos(phi1-phi2-phi3)>>:
3026  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(11.5,
3027                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3028                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3029                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3030  // <<4><sin(phi1-phi2-phi3)>>:
3031  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(12.5,
3032                                                  fIntFlowCorrelationsEBE->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3033                                                  fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)
3034                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));   
3035  // <<cos(phi1)><cos(phi1+phi2)>>:
3036  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(13.5,
3037                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3038                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3039                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
3040  // <<cos(phi1)><sin(phi1+phi2)>>: 
3041  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(14.5,
3042                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3043                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3044                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3045  // <<cos(phi1)><cos(phi1-phi2-phi3)>>:
3046  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(15.5,
3047                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3048                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3049                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3050  // <<cos(phi1)><sin(phi1-phi2-phi3)>>: 
3051  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(16.5,
3052                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3053                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)
3054                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
3055  // <<sin(phi1)><cos(phi1+phi2)>>:
3056  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(17.5,
3057                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2),
3058                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3059                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));  
3060  // <<sin(phi1)><sin(phi1+phi2)>>: 
3061  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(18.5,
3062                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3063                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3064                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));  
3065  // <<sin(phi1)><cos(phi1-phi2-phi3)>>:
3066  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(19.5,
3067                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3068                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3069                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
3070  // <<sin(phi1)><sin(phi1-phi2-phi3)>>:
3071  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(20.5,
3072                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(1)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3073                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)
3074                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
3075  // <<cos(phi1+phi2)><sin(phi1+phi2)>>:
3076  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(21.5,
3077                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2),
3078                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3079                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
3080  // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3081  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(22.5,
3082                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3083                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3084                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));   
3085  // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3086  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(23.5,
3087                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3088                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)
3089                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3090  // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>>:
3091  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(24.5,
3092                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3),
3093                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3094                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));    
3095  // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>>:
3096  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(25.5,
3097                                                  fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(2)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3098                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)
3099                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3100  // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>>:
3101  fIntFlowProductOfCorrectionTermsForNUAPro->Fill(26.5,
3102                                                  fIntFlowCorrectionTermsForNUAEBE[1]->GetBinContent(3)*fIntFlowCorrectionTermsForNUAEBE[0]->GetBinContent(3),
3103                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)
3104                                                  *fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));    
3105
3106 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowProductOfCorrectionTermsForNUA()
3107
3108 //================================================================================================================================
3109
3110 void AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
3111 {
3112  // a) Calculate unbiased estimators Cov(<2>,<4>), Cov(<2>,<6>), Cov(<2>,<8>), Cov(<4>,<6>), Cov(<4>,<8>) and Cov(<6>,<8>)
3113  //    for covariances V_(<2>,<4>), V_(<2>,<6>), V_(<2>,<8>), V_(<4>,<6>), V_(<4>,<8>) and V_(<6>,<8>).
3114  // b) Store in histogram fIntFlowCovariances for instance the following: 
3115  //
3116  //             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)]
3117  // 
3118  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<4>} is event weight for <4>.
3119  // c) Binning of fIntFlowCovariances is organized as follows:
3120  // 
3121  //     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)] 
3122  //     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)]
3123  //     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)]
3124  //     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)]
3125  //     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)]
3126  //     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)]
3127  //
3128     
3129  // Average 2-, 4-, 6- and 8-particle correlations for all events:
3130  Double_t correlation[4] = {0.};
3131  for(Int_t ci=0;ci<4;ci++)
3132  {
3133   correlation[ci] = fIntFlowCorrelationsPro->GetBinContent(ci+1);
3134  } 
3135  // Average products of 2-, 4-, 6- and 8-particle correlations: 
3136  Double_t productOfCorrelations[4][4] = {{0.}};
3137  Int_t productOfCorrelationsLabel = 1;
3138  // Denominators in the expressions for the unbiased estimator for covariance:
3139  Double_t denominator[4][4] = {{0.}};
3140  Int_t sumOfProductOfEventWeightsLabel1 = 1;
3141  // Weight dependent prefactor which multiply unbiased estimators for covariances:
3142  Double_t wPrefactor[4][4] = {{0.}}; 
3143  Int_t sumOfProductOfEventWeightsLabel2 = 1;
3144  for(Int_t c1=0;c1<4;c1++)
3145  {
3146   for(Int_t c2=c1+1;c2<4;c2++)
3147   {
3148    productOfCorrelations[c1][c2] = fIntFlowProductOfCorrelationsPro->GetBinContent(productOfCorrelationsLabel);
3149    if(TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1)) > 1.e-44)
3150    {
3151     denominator[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel1))
3152                         / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1) 
3153                         * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                              
3154     wPrefactor[c1][c2] = fIntFlowSumOfProductOfEventWeights->GetBinContent(sumOfProductOfEventWeightsLabel2)
3155                        / (fIntFlowSumOfEventWeights[0]->GetBinContent(c1+1)
3156                        * fIntFlowSumOfEventWeights[0]->GetBinContent(c2+1));                                                       
3157    }
3158    productOfCorrelationsLabel++; // to be improved - do I need here all 3 counters?
3159    sumOfProductOfEventWeightsLabel1++;
3160    sumOfProductOfEventWeightsLabel2++;  
3161   } // end of for(Int_t c2=c1+1;c2<4;c2++)
3162  } // end of for(Int_t c1=0;c1<4;c1++)
3163  
3164  Int_t covarianceLabel = 1;
3165  for(Int_t c1=0;c1<4;c1++)
3166  {
3167   for(Int_t c2=c1+1;c2<4;c2++)
3168   {
3169    if(TMath::Abs(denominator[c1][c2]) > 1.e-44)
3170    {
3171     // Covariances:
3172     Double_t cov = (productOfCorrelations[c1][c2]-correlation[c1]*correlation[c2])/denominator[c1][c2]; 
3173     // Covariances multiplied with weight dependent prefactor:
3174     Double_t wCov = cov * wPrefactor[c1][c2];
3175     fIntFlowCovariances->SetBinContent(covarianceLabel,wCov);
3176    }
3177    covarianceLabel++;
3178   } // end of for(Int_t c2=c1+1;c2<4;c2++) 
3179  } // end of for(Int_t c1=0;c1<4;c1++)
3180  
3181  // Versus multiplicity: 
3182  if(!fCalculateCumulantsVsM){return;}
3183  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
3184  for(Int_t b=1;b<=nBins;b++)
3185  {
3186   // Average 2-, 4-, 6- and 8-particle correlations for all events:
3187   Double_t correlationVsM[4] = {0.};
3188   for(Int_t ci=0;ci<4;ci++)
3189   {
3190    correlationVsM[ci] = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
3191   } // end of for(Int_t ci=0;ci<4;ci++)
3192   // Average products of 2-, 4-, 6- and 8-particle correlations: 
3193   Double_t productOfCorrelationsVsM[4][4] = {{0.}};
3194   Int_t productOfCorrelationsLabelVsM = 1;
3195   // Denominators in the expressions for the unbiased estimator for covariance:
3196   Double_t denominatorVsM[4][4] = {{0.}};
3197   Int_t sumOfProductOfEventWeightsLabel1VsM = 1;
3198   // Weight dependent prefactor which multiply unbiased estimators for covariances:
3199   Double_t wPrefactorVsM[4][4] = {{0.}}; 
3200   Int_t sumOfProductOfEventWeightsLabel2VsM = 1;
3201   for(Int_t c1=0;c1<4;c1++)
3202   {
3203    for(Int_t c2=c1+1;c2<4;c2++)
3204    {
3205     productOfCorrelationsVsM[c1][c2] = fIntFlowProductOfCorrelationsVsMPro[productOfCorrelationsLabelVsM-1]->GetBinContent(b);
3206     if(TMath::Abs(fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)) > 1.e-44 && TMath::Abs(fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b)) > 1.e-44)
3207     {
3208      denominatorVsM[c1][c2] = 1.-(fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel1VsM-1]->GetBinContent(b))
3209                             / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b) 
3210                             * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                              
3211      wPrefactorVsM[c1][c2] = fIntFlowSumOfProductOfEventWeightsVsM[sumOfProductOfEventWeightsLabel2VsM-1]->GetBinContent(b)
3212                            / (fIntFlowSumOfEventWeightsVsM[c1][0]->GetBinContent(b)
3213                            * fIntFlowSumOfEventWeightsVsM[c2][0]->GetBinContent(b));                                                       
3214     }
3215     productOfCorrelationsLabelVsM++;
3216     sumOfProductOfEventWeightsLabel1VsM++;
3217     sumOfProductOfEventWeightsLabel2VsM++;  
3218    } // end of for(Int_t c1=0;c1<4;c1++) 
3219   } // end of for(Int_t c2=c1+1;c2<4;c2++)
3220  
3221   Int_t covarianceLabelVsM = 1;
3222   for(Int_t c1=0;c1<4;c1++)
3223   {
3224    for(Int_t c2=c1+1;c2<4;c2++)
3225    {
3226     if(TMath::Abs(denominatorVsM[c1][c2]) > 1.e-44)
3227     {
3228      // Covariances:
3229      Double_t covVsM = (productOfCorrelationsVsM[c1][c2]-correlationVsM[c1]*correlationVsM[c2])/denominatorVsM[c1][c2]; 
3230      // Covariances multiplied with weight dependent prefactor:
3231      Double_t wCovVsM = covVsM * wPrefactorVsM[c1][c2];
3232      fIntFlowCovariancesVsM[covarianceLabelVsM-1]->SetBinContent(b,wCovVsM);
3233     }
3234     covarianceLabelVsM++;
3235    } // end of for(Int_t c2=c1+1;c2<4;c2++)
3236   } // end of for(Int_t c1=0;c1<4;c1++)
3237  } // end of for(Int_t b=1;b<=nBins;b++)
3238   
3239 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesIntFlow()
3240
3241 //================================================================================================================================
3242
3243 void AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
3244 {
3245  // a) Calculate unbiased estimators Cov(*,*) for true covariances V_(*,*) for NUA terms.
3246  // b) Store in histogram fIntFlowCovariancesNUA for instance the following: 
3247  //
3248  //             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)]
3249  // 
3250  //    where N is the number of events, w_{<2>} is event weight for <2> and w_{<cos(phi)>} is event weight for <cos(phi)>.
3251  // c) Binning of fIntFlowCovariancesNUA is organized as follows:
3252  // 
3253  //     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)] 
3254  //     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)]
3255  //     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)]
3256  // ...
3257       
3258  // Cov(<2>,<cos(phi)>):
3259  Double_t product1 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(1); // <<2><cos(phi)>> 
3260  Double_t term1st1 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3261  Double_t term2nd1 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
3262  Double_t sumOfW1st1 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3263  Double_t sumOfW2nd1 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
3264  Double_t sumOfWW1 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(1); // W_{<2>} * W_{<cos(phi)>}
3265  // numerator in the expression for the the unbiased estimator for covariance:
3266  Double_t numerator1 = product1 - term1st1*term2nd1; 
3267  // denominator in the expression for the the unbiased estimator for covariance:
3268  Double_t denominator1 = 1.-sumOfWW1/(sumOfW1st1*sumOfW2nd1);
3269  // covariance:
3270  Double_t covariance1 = numerator1/denominator1;
3271  // weight dependent prefactor for covariance:
3272  Double_t wPrefactor1 = sumOfWW1/(sumOfW1st1*sumOfW2nd1);
3273  // finally, store "weighted" covariance:
3274  fIntFlowCovariancesNUA->SetBinContent(1,wPrefactor1*covariance1);
3275   
3276  // Cov(<2>,<sin(phi)>):
3277  Double_t product2 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(2); // <<2><sin(phi)>> 
3278  Double_t term1st2 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3279  Double_t term2nd2 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
3280  Double_t sumOfW1st2 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3281  Double_t sumOfW2nd2 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
3282  Double_t sumOfWW2 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(2); // W_{<2>} * W_{<sin(phi)>}
3283  // numerator in the expression for the the unbiased estimator for covariance:
3284  Double_t numerator2 = product2 - term1st2*term2nd2; 
3285  // denominator in the expression for the the unbiased estimator for covariance:
3286  Double_t denominator2 = 1.-sumOfWW2/(sumOfW1st2*sumOfW2nd2);
3287  // covariance:
3288  Double_t covariance2 = numerator2/denominator2;
3289  // weight dependent prefactor for covariance:
3290  Double_t wPrefactor2 = sumOfWW2/(sumOfW1st2*sumOfW2nd2);
3291  // finally, store "weighted" covariance:
3292  fIntFlowCovariancesNUA->SetBinContent(2,wPrefactor2*covariance2);
3293  
3294  // Cov(<cos(phi)>,<sin(phi)>):
3295  Double_t product3 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(3); // <<cos(phi)><sin(phi)>> 
3296  Double_t term1st3 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi)>>
3297  Double_t term2nd3 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi)>>
3298  Double_t sumOfW1st3 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi)>}
3299  Double_t sumOfW2nd3 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi)>}
3300  Double_t sumOfWW3 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(3); // W_{<cos(phi)>} * W_{<sin(phi)>}
3301  // numerator in the expression for the the unbiased estimator for covariance:
3302  Double_t numerator3 = product3 - term1st3*term2nd3; 
3303  // denominator in the expression for the the unbiased estimator for covariance:
3304  Double_t denominator3 = 1.-sumOfWW3/(sumOfW1st3*sumOfW2nd3);
3305  // covariance:
3306  Double_t covariance3 = numerator3/denominator3;
3307  // weight dependent prefactor for covariance:
3308  Double_t wPrefactor3 = sumOfWW3/(sumOfW1st3*sumOfW2nd3);
3309  // finally, store "weighted" covariance:
3310  fIntFlowCovariancesNUA->SetBinContent(3,wPrefactor3*covariance3);
3311  
3312  // Cov(<2>,<cos(phi1+phi2)>):
3313  Double_t product4 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(4); // <<2><cos(phi1+phi2)>> 
3314  Double_t term1st4 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3315  Double_t term2nd4 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3316  Double_t sumOfW1st4 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3317  Double_t sumOfW2nd4 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3318  Double_t sumOfWW4 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(4); // W_{<2>} * W_{<cos(phi1+phi2)>}
3319  // numerator in the expression for the the unbiased estimator for covariance:
3320  Double_t numerator4 = product4 - term1st4*term2nd4; 
3321  // denominator in the expression for the the unbiased estimator for covariance:
3322  Double_t denominator4 = 1.-sumOfWW4/(sumOfW1st4*sumOfW2nd4);
3323  // covariance:
3324  Double_t covariance4 = numerator4/denominator4;
3325  // weight dependent prefactor for covariance:
3326  Double_t wPrefactor4 = sumOfWW4/(sumOfW1st4*sumOfW2nd4);
3327  // finally, store "weighted" covariance:
3328  fIntFlowCovariancesNUA->SetBinContent(4,wPrefactor4*covariance4);
3329
3330  // Cov(<2>,<sin(phi1+phi2)>):
3331  Double_t product5 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(5); // <<2><sin(phi1+phi2)>> 
3332  Double_t term1st5 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3333  Double_t term2nd5 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3334  Double_t sumOfW1st5 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3335  Double_t sumOfW2nd5 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3336  Double_t sumOfWW5 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(5); // W_{<2>} * W_{<sin(phi1+phi2)>}
3337  // numerator in the expression for the the unbiased estimator for covariance:
3338  Double_t numerator5 = product5 - term1st5*term2nd5; 
3339  // denominator in the expression for the the unbiased estimator for covariance:
3340  Double_t denominator5 = 1.-sumOfWW5/(sumOfW1st5*sumOfW2nd5);
3341  // covariance:
3342  Double_t covariance5 = numerator5/denominator5;
3343  // weight dependent prefactor for covariance:
3344  Double_t wPrefactor5 = sumOfWW5/(sumOfW1st5*sumOfW2nd5);
3345  // finally, store "weighted" covariance:
3346  fIntFlowCovariancesNUA->SetBinContent(5,wPrefactor5*covariance5);
3347
3348  // Cov(<2>,<cos(phi1-phi2-phi3)>):
3349  Double_t product6 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(6); // <<2><cos(phi1-phi2-phi3)>> 
3350  Double_t term1st6 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3351  Double_t term2nd6 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3352  Double_t sumOfW1st6 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3353  Double_t sumOfW2nd6 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3354  Double_t sumOfWW6 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(6); // W_{<2>} * W_{<cos(phi1-phi2-phi3)>}
3355  // numerator in the expression for the the unbiased estimator for covariance:
3356  Double_t numerator6 = product6 - term1st6*term2nd6; 
3357  // denominator in the expression for the the unbiased estimator for covariance:
3358  Double_t denominator6 = 1.-sumOfWW6/(sumOfW1st6*sumOfW2nd6);
3359  // covariance:
3360  Double_t covariance6 = numerator6/denominator6;
3361  // weight dependent prefactor for covariance:
3362  Double_t wPrefactor6 = sumOfWW6/(sumOfW1st6*sumOfW2nd6);
3363  // finally, store "weighted" covariance:
3364  fIntFlowCovariancesNUA->SetBinContent(6,wPrefactor6*covariance6);
3365
3366  // Cov(<2>,<sin(phi1-phi2-phi3)>):
3367  Double_t product7 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(7); // <<2><sin(phi1-phi2-phi3)>> 
3368  Double_t term1st7 = fIntFlowCorrelationsPro->GetBinContent(1); // <<2>>
3369  Double_t term2nd7 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3370  Double_t sumOfW1st7 = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // W_{<2>}
3371  Double_t sumOfW2nd7 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3372  Double_t sumOfWW7 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(7); // W_{<2>} * W_{<sin(phi1-phi2-phi3)>}
3373  // numerator in the expression for the the unbiased estimator for covariance:
3374  Double_t numerator7 = product7 - term1st7*term2nd7; 
3375  // denominator in the expression for the the unbiased estimator for covariance:
3376  Double_t denominator7 = 1.-sumOfWW7/(sumOfW1st7*sumOfW2nd7);
3377  // covariance:
3378  Double_t covariance7 = numerator7/denominator7;
3379  // weight dependent prefactor for covariance:
3380  Double_t wPrefactor7 = sumOfWW7/(sumOfW1st7*sumOfW2nd7);
3381  // finally, store "weighted" covariance:
3382  fIntFlowCovariancesNUA->SetBinContent(7,wPrefactor7*covariance7);
3383
3384  // Cov(<4>,<cos(phi1>):
3385  Double_t product8 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(8); // <<4><cos(phi1)>> 
3386  Double_t term1st8 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3387  Double_t term2nd8 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3388  Double_t sumOfW1st8 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3389  Double_t sumOfW2nd8 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3390  Double_t sumOfWW8 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(8); // W_{<4>} * W_{<cos(phi1)>}
3391  // numerator in the expression for the the unbiased estimator for covariance:
3392  Double_t numerator8 = product8 - term1st8*term2nd8; 
3393  // denominator in the expression for the the unbiased estimator for covariance:
3394  Double_t denominator8 = 1.-sumOfWW8/(sumOfW1st8*sumOfW2nd8);
3395  // covariance:
3396  Double_t covariance8 = numerator8/denominator8;
3397  // weight dependent prefactor for covariance:
3398  Double_t wPrefactor8 = sumOfWW8/(sumOfW1st8*sumOfW2nd8);
3399  // finally, store "weighted" covariance:
3400  fIntFlowCovariancesNUA->SetBinContent(8,wPrefactor8*covariance8);
3401
3402  // Cov(<4>,<sin(phi1)>):
3403  Double_t product9 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(9); // <<4><sin(phi1)>> 
3404  Double_t term1st9 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3405  Double_t term2nd9 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3406  Double_t sumOfW1st9 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3407  Double_t sumOfW2nd9 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3408  Double_t sumOfWW9 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(9); // W_{<4>} * W_{<sin(phi1)>}
3409  // numerator in the expression for the the unbiased estimator for covariance:
3410  Double_t numerator9 = product9 - term1st9*term2nd9; 
3411  // denominator in the expression for the the unbiased estimator for covariance:
3412  Double_t denominator9 = 1.-sumOfWW9/(sumOfW1st9*sumOfW2nd9);
3413  // covariance:
3414  Double_t covariance9 = numerator9/denominator9;
3415  // weight dependent prefactor for covariance:
3416  Double_t wPrefactor9 = sumOfWW9/(sumOfW1st9*sumOfW2nd9);
3417  // finally, store "weighted" covariance:
3418  fIntFlowCovariancesNUA->SetBinContent(9,wPrefactor9*covariance9);
3419
3420  // Cov(<4>,<cos(phi1+phi2)>):
3421  Double_t product10 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(10); // <<4><cos(phi1+phi2)>> 
3422  Double_t term1st10 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3423  Double_t term2nd10 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3424  Double_t sumOfW1st10 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3425  Double_t sumOfW2nd10 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3426  Double_t sumOfWW10 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(10); // W_{<4>} * W_{<cos(phi1+phi2)>}
3427  // numerator in the expression for the the unbiased estimator for covariance:
3428  Double_t numerator10 = product10 - term1st10*term2nd10; 
3429  // denominator in the expression for the the unbiased estimator for covariance:
3430  Double_t denominator10 = 1.-sumOfWW10/(sumOfW1st10*sumOfW2nd10);
3431  // covariance:
3432  Double_t covariance10 = numerator10/denominator10;
3433  // weight dependent prefactor for covariance:
3434  Double_t wPrefactor10 = sumOfWW10/(sumOfW1st10*sumOfW2nd10);
3435  // finally, store "weighted" covariance:
3436  fIntFlowCovariancesNUA->SetBinContent(10,wPrefactor10*covariance10);
3437
3438  // Cov(<4>,<sin(phi1+phi2)>):
3439  Double_t product11 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(11); // <<4><sin(phi1+phi2)>> 
3440  Double_t term1st11 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3441  Double_t term2nd11 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3442  Double_t sumOfW1st11 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3443  Double_t sumOfW2nd11 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3444  Double_t sumOfWW11 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(11); // W_{<4>} * W_{<sin(phi1+phi2)>}
3445  // numerator in the expression for the the unbiased estimator for covariance:
3446  Double_t numerator11 = product11 - term1st11*term2nd11; 
3447  // denominator in the expression for the the unbiased estimator for covariance:
3448  Double_t denominator11 = 1.-sumOfWW11/(sumOfW1st11*sumOfW2nd11);
3449  // covariance:
3450  Double_t covariance11 = numerator11/denominator11;
3451  // weight dependent prefactor for covariance:
3452  Double_t wPrefactor11 = sumOfWW11/(sumOfW1st11*sumOfW2nd11);
3453  // finally, store "weighted" covariance:
3454  fIntFlowCovariancesNUA->SetBinContent(11,wPrefactor11*covariance11);
3455
3456  // Cov(<4>,<cos(phi1-phi2-phi3)>):
3457  Double_t product12 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(12); // <<4><cos(phi1-phi2-phi3)>> 
3458  Double_t term1st12 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3459  Double_t term2nd12 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3460  Double_t sumOfW1st12 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3461  Double_t sumOfW2nd12 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3462  Double_t sumOfWW12 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(12); // W_{<4>} * W_{<cos(phi1-phi2-phi3)>}
3463  // numerator in the expression for the the unbiased estimator for covariance:
3464  Double_t numerator12 = product12 - term1st12*term2nd12; 
3465  // denominator in the expression for the the unbiased estimator for covariance:
3466  Double_t denominator12 = 1.-sumOfWW12/(sumOfW1st12*sumOfW2nd12);
3467  // covariance:
3468  Double_t covariance12 = numerator12/denominator12;
3469  // weight dependent prefactor for covariance:
3470  Double_t wPrefactor12 = sumOfWW12/(sumOfW1st12*sumOfW2nd12);
3471  // finally, store "weighted" covariance:
3472  fIntFlowCovariancesNUA->SetBinContent(12,wPrefactor12*covariance12);
3473
3474  // Cov(<4>,<sin(phi1-phi2-phi3)>):
3475  Double_t product13 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(13); // <<4><sin(phi1-phi2-phi3)>> 
3476  Double_t term1st13 = fIntFlowCorrelationsPro->GetBinContent(2); // <<4>>
3477  Double_t term2nd13 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3478  Double_t sumOfW1st13 = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // W_{<4>}
3479  Double_t sumOfW2nd13 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3480  Double_t sumOfWW13 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(13); // W_{<4>} * W_{<sin(phi1-phi2-phi3)>}
3481  // numerator in the expression for the the unbiased estimator for covariance:
3482  Double_t numerator13 = product13 - term1st13*term2nd13; 
3483  // denominator in the expression for the the unbiased estimator for covariance:
3484  Double_t denominator13 = 1.-sumOfWW13/(sumOfW1st13*sumOfW2nd13);
3485  // covariance:
3486  Double_t covariance13 = numerator13/denominator13;
3487  // weight dependent prefactor for covariance:
3488  Double_t wPrefactor13 = sumOfWW13/(sumOfW1st13*sumOfW2nd13);
3489  // finally, store "weighted" covariance:
3490  fIntFlowCovariancesNUA->SetBinContent(13,wPrefactor13*covariance13);
3491
3492  // Cov(<cos(phi1)>,<cos(phi1+phi2)>):
3493  Double_t product14 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(14); // <<cos(phi1)><cos(phi1+phi2)>> 
3494  Double_t term1st14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3495  Double_t term2nd14 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3496  Double_t sumOfW1st14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3497  Double_t sumOfW2nd14 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3498  Double_t sumOfWW14 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(14); // W_{<cos(phi1)>} * W_{<cos(phi1+phi2)>}
3499  // numerator in the expression for the the unbiased estimator for covariance:
3500  Double_t numerator14 = product14 - term1st14*term2nd14; 
3501  // denominator in the expression for the the unbiased estimator for covariance:
3502  Double_t denominator14 = 1.-sumOfWW14/(sumOfW1st14*sumOfW2nd14);
3503  // covariance:
3504  Double_t covariance14 = numerator14/denominator14;
3505  // weight dependent prefactor for covariance:
3506  Double_t wPrefactor14 = sumOfWW14/(sumOfW1st14*sumOfW2nd14);
3507  // finally, store "weighted" covariance:
3508  fIntFlowCovariancesNUA->SetBinContent(14,wPrefactor14*covariance14);
3509
3510  // Cov(<cos(phi1)>,<sin(phi1+phi2)>):
3511  Double_t product15 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(15); // <<cos(phi1)><sin(phi1+phi2)>> 
3512  Double_t term1st15 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3513  Double_t term2nd15 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3514  Double_t sumOfW1st15 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3515  Double_t sumOfW2nd15 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3516  Double_t sumOfWW15 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(15); // W_{<cos(phi1)>} * W_{<sin(phi1+phi2)>}
3517  // numerator in the expression for the the unbiased estimator for covariance:
3518  Double_t numerator15 = product15 - term1st15*term2nd15; 
3519  // denominator in the expression for the the unbiased estimator for covariance:
3520  Double_t denominator15 = 1.-sumOfWW15/(sumOfW1st15*sumOfW2nd15);
3521  // covariance:
3522  Double_t covariance15 = numerator15/denominator15;
3523  // weight dependent prefactor for covariance:
3524  Double_t wPrefactor15 = sumOfWW15/(sumOfW1st15*sumOfW2nd15);
3525  // finally, store "weighted" covariance:
3526  fIntFlowCovariancesNUA->SetBinContent(15,wPrefactor15*covariance15);
3527
3528  // Cov(<cos(phi1)>,<cos(phi1-phi2-phi3)>):
3529  Double_t product16 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(16); // <<cos(phi1)><cos(phi1-phi2-phi3)>> 
3530  Double_t term1st16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3531  Double_t term2nd16 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3532  Double_t sumOfW1st16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3533  Double_t sumOfW2nd16 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3534  Double_t sumOfWW16 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(16); // W_{<cos(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
3535  // numerator in the expression for the the unbiased estimator for covariance:
3536  Double_t numerator16 = product16 - term1st16*term2nd16; 
3537  // denominator in the expression for the the unbiased estimator for covariance:
3538  Double_t denominator16 = 1.-sumOfWW16/(sumOfW1st16*sumOfW2nd16);
3539  // covariance:
3540  Double_t covariance16 = numerator16/denominator16;
3541  // weight dependent prefactor for covariance:
3542  Double_t wPrefactor16 = sumOfWW16/(sumOfW1st16*sumOfW2nd16);
3543  // finally, store "weighted" covariance:
3544  fIntFlowCovariancesNUA->SetBinContent(16,wPrefactor16*covariance16);
3545
3546  // Cov(<cos(phi1)>,<sin(phi1-phi2-phi3)>):
3547  Double_t product17 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(17); // <<cos(phi1)><sin(phi1-phi2-phi3)>> 
3548  Double_t term1st17 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(1); // <<cos(phi1)>>
3549  Double_t term2nd17 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3550  Double_t sumOfW1st17 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(1); // W_{<cos(phi1)>}
3551  Double_t sumOfW2nd17 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3552  Double_t sumOfWW17 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(17); // W_{<cos(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
3553  // numerator in the expression for the the unbiased estimator for covariance:
3554  Double_t numerator17 = product17 - term1st17*term2nd17; 
3555  // denominator in the expression for the the unbiased estimator for covariance:
3556  Double_t denominator17 = 1.-sumOfWW17/(sumOfW1st17*sumOfW2nd17);
3557  // covariance:
3558  Double_t covariance17 = numerator17/denominator17;
3559  // weight dependent prefactor for covariance:
3560  Double_t wPrefactor17 = sumOfWW17/(sumOfW1st17*sumOfW2nd17);
3561  // finally, store "weighted" covariance:
3562  fIntFlowCovariancesNUA->SetBinContent(17,wPrefactor17*covariance17);
3563
3564  // Cov(<sin(phi1)>,<cos(phi1+phi2)>):
3565  Double_t product18 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(18); // <<sin(phi1)><cos(phi1+phi2)>> 
3566  Double_t term1st18 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3567  Double_t term2nd18 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3568  Double_t sumOfW1st18 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3569  Double_t sumOfW2nd18 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3570  Double_t sumOfWW18 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(18); // W_{<sin(phi1)>} * W_{<cos(phi1+phi2)>}
3571  // numerator in the expression for the the unbiased estimator for covariance:
3572  Double_t numerator18 = product18 - term1st18*term2nd18; 
3573  // denominator in the expression for the the unbiased estimator for covariance:
3574  Double_t denominator18 = 1.-sumOfWW18/(sumOfW1st18*sumOfW2nd18);
3575  // covariance:
3576  Double_t covariance18 = numerator18/denominator18;
3577  // weight dependent prefactor for covariance:
3578  Double_t wPrefactor18 = sumOfWW18/(sumOfW1st18*sumOfW2nd18);
3579  // finally, store "weighted" covariance:
3580  fIntFlowCovariancesNUA->SetBinContent(18,wPrefactor18*covariance18);
3581
3582  // Cov(<sin(phi1)>,<sin(phi1+phi2)>):
3583  Double_t product19 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(19); // <<sin(phi1)><sin(phi1+phi2)>> 
3584  Double_t term1st19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3585  Double_t term2nd19 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3586  Double_t sumOfW1st19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3587  Double_t sumOfW2nd19 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3588  Double_t sumOfWW19 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(19); // W_{<sin(phi1)>} * W_{<sin(phi1+phi2)>}
3589  // numerator in the expression for the the unbiased estimator for covariance:
3590  Double_t numerator19 = product19 - term1st19*term2nd19; 
3591  // denominator in the expression for the the unbiased estimator for covariance:
3592  Double_t denominator19 = 1.-sumOfWW19/(sumOfW1st19*sumOfW2nd19);
3593  // covariance:
3594  Double_t covariance19 = numerator19/denominator19;
3595  // weight dependent prefactor for covariance:
3596  Double_t wPrefactor19 = sumOfWW19/(sumOfW1st19*sumOfW2nd19);
3597  // finally, store "weighted" covariance:
3598  fIntFlowCovariancesNUA->SetBinContent(19,wPrefactor19*covariance19);
3599
3600  // Cov(<sin(phi1)>,<cos(phi1-phi2-phi3)>):
3601  Double_t product20 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(20); // <<sin(phi1)><cos(phi1-phi2-phi3)>> 
3602  Double_t term1st20 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3603  Double_t term2nd20 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3604  Double_t sumOfW1st20 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3605  Double_t sumOfW2nd20 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3606  Double_t sumOfWW20 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(20); // W_{<sin(phi1)>} * W_{<cos(phi1-phi2-phi3)>}
3607  // numerator in the expression for the the unbiased estimator for covariance:
3608  Double_t numerator20 = product20 - term1st20*term2nd20; 
3609  // denominator in the expression for the the unbiased estimator for covariance:
3610  Double_t denominator20 = 1.-sumOfWW20/(sumOfW1st20*sumOfW2nd20);
3611  // covariance:
3612  Double_t covariance20 = numerator20/denominator20;
3613  // weight dependent prefactor for covariance:
3614  Double_t wPrefactor20 = sumOfWW20/(sumOfW1st20*sumOfW2nd20);
3615  // finally, store "weighted" covariance:
3616  fIntFlowCovariancesNUA->SetBinContent(20,wPrefactor20*covariance20);
3617
3618  // Cov(<sin(phi1)>,<sin(phi1-phi2-phi3)>):
3619  Double_t product21 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(21); // <<sin(phi1)><sin(phi1-phi2-phi3)>> 
3620  Double_t term1st21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(1); // <<sin(phi1)>>
3621  Double_t term2nd21 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3622  Double_t sumOfW1st21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(1); // W_{<sin(phi1)>}
3623  Double_t sumOfW2nd21 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3624  Double_t sumOfWW21 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(21); // W_{<sin(phi1)>} * W_{<sin(phi1-phi2-phi3)>}
3625  // numerator in the expression for the the unbiased estimator for covariance:
3626  Double_t numerator21 = product21 - term1st21*term2nd21; 
3627  // denominator in the expression for the the unbiased estimator for covariance:
3628  Double_t denominator21 = 1.-sumOfWW21/(sumOfW1st21*sumOfW2nd21);
3629  // covariance:
3630  Double_t covariance21 = numerator21/denominator21;
3631  // weight dependent prefactor for covariance:
3632  Double_t wPrefactor21 = sumOfWW21/(sumOfW1st21*sumOfW2nd21);
3633  // finally, store "weighted" covariance:
3634  fIntFlowCovariancesNUA->SetBinContent(21,wPrefactor21*covariance21);
3635
3636  // Cov(<cos(phi1+phi2)>,<sin(phi1+phi2)>):
3637  Double_t product22 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(22); // <<cos(phi1+phi2)><sin(phi1+phi2)>> 
3638  Double_t term1st22 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3639  Double_t term2nd22 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3640  Double_t sumOfW1st22 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3641  Double_t sumOfW2nd22 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3642  Double_t sumOfWW22 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(22); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1+phi2)>}
3643  // numerator in the expression for the the unbiased estimator for covariance:
3644  Double_t numerator22 = product22 - term1st22*term2nd22; 
3645  // denominator in the expression for the the unbiased estimator for covariance:
3646  Double_t denominator22 = 1.-sumOfWW22/(sumOfW1st22*sumOfW2nd22);
3647  // covariance:
3648  Double_t covariance22 = numerator22/denominator22;
3649  // weight dependent prefactor for covariance:
3650  Double_t wPrefactor22 = sumOfWW22/(sumOfW1st22*sumOfW2nd22);
3651  // finally, store "weighted" covariance:
3652  fIntFlowCovariancesNUA->SetBinContent(22,wPrefactor22*covariance22);
3653
3654  // Cov(<cos(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
3655  Double_t product23 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(23); // <<cos(phi1+phi2)><cos(phi1-phi2-phi3)>> 
3656  Double_t term1st23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3657  Double_t term2nd23 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3658  Double_t sumOfW1st23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3659  Double_t sumOfW2nd23 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3660  Double_t sumOfWW23 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(23); // W_{<cos(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
3661  // numerator in the expression for the the unbiased estimator for covariance:
3662  Double_t numerator23 = product23 - term1st23*term2nd23; 
3663  // denominator in the expression for the the unbiased estimator for covariance:
3664  Double_t denominator23 = 1.-sumOfWW23/(sumOfW1st23*sumOfW2nd23);
3665  // covariance:
3666  Double_t covariance23 = numerator23/denominator23;
3667  // weight dependent prefactor for covariance:
3668  Double_t wPrefactor23 = sumOfWW23/(sumOfW1st23*sumOfW2nd23);
3669  // finally, store "weighted" covariance:
3670  fIntFlowCovariancesNUA->SetBinContent(23,wPrefactor23*covariance23);
3671
3672  // Cov(<cos(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
3673  Double_t product24 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(24); // <<cos(phi1+phi2)><sin(phi1-phi2-phi3)>> 
3674  Double_t term1st24 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
3675  Double_t term2nd24 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3676  Double_t sumOfW1st24 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1+phi2)>}
3677  Double_t sumOfW2nd24 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3678  Double_t sumOfWW24 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(24); // W_{<cos(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
3679  // numerator in the expression for the the unbiased estimator for covariance:
3680  Double_t numerator24 = product24 - term1st24*term2nd24; 
3681  // denominator in the expression for the the unbiased estimator for covariance:
3682  Double_t denominator24 = 1.-sumOfWW24/(sumOfW1st24*sumOfW2nd24);
3683  // covariance:
3684  Double_t covariance24 = numerator24/denominator24;
3685  // weight dependent prefactor for covariance:
3686  Double_t wPrefactor24 = sumOfWW24/(sumOfW1st24*sumOfW2nd24);
3687  // finally, store "weighted" covariance:
3688  fIntFlowCovariancesNUA->SetBinContent(24,wPrefactor24*covariance24);
3689
3690  // Cov(<sin(phi1+phi2)>,<cos(phi1-phi2-phi3)>):
3691  Double_t product25 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(25); // <<sin(phi1+phi2)><cos(phi1-phi2-phi3)>> 
3692  Double_t term1st25 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3693  Double_t term2nd25 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
3694  Double_t sumOfW1st25 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3695  Double_t sumOfW2nd25 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(3); // W_{<cos(phi1-phi2-phi3)>}
3696  Double_t sumOfWW25 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(25); // W_{<sin(phi1+phi2)>} * W_{<cos(phi1-phi2-phi3)>}
3697  // numerator in the expression for the the unbiased estimator for covariance:
3698  Double_t numerator25 = product25 - term1st25*term2nd25; 
3699  // denominator in the expression for the the unbiased estimator for covariance:
3700  Double_t denominator25 = 1.-sumOfWW25/(sumOfW1st25*sumOfW2nd25);
3701  // covariance:
3702  Double_t covariance25 = numerator25/denominator25;
3703  // weight dependent prefactor for covariance:
3704  Double_t wPrefactor25 = sumOfWW25/(sumOfW1st25*sumOfW2nd25);
3705  // finally, store "weighted" covariance:
3706  fIntFlowCovariancesNUA->SetBinContent(25,wPrefactor25*covariance25);
3707
3708  // Cov(<sin(phi1+phi2)>,<sin(phi1-phi2-phi3)>):
3709  Double_t product26 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(26); // <<sin(phi1+phi2)><sin(phi1-phi2-phi3)>> 
3710  Double_t term1st26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
3711  Double_t term2nd26 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3712  Double_t sumOfW1st26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(2); // W_{<sin(phi1+phi2)>}
3713  Double_t sumOfW2nd26 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3714  Double_t sumOfWW26 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(26); // W_{<sin(phi1+phi2)>} * W_{<sin(phi1-phi2-phi3)>}
3715  // numerator in the expression for the the unbiased estimator for covariance:
3716  Double_t numerator26 = product26 - term1st26*term2nd26; 
3717  // denominator in the expression for the the unbiased estimator for covariance:
3718  Double_t denominator26 = 1.-sumOfWW26/(sumOfW1st26*sumOfW2nd26);
3719  // covariance:
3720  Double_t covariance26 = numerator26/denominator26;
3721  // weight dependent prefactor for covariance:
3722  Double_t wPrefactor26 = sumOfWW26/(sumOfW1st26*sumOfW2nd26);
3723  // finally, store "weighted" covariance:
3724  fIntFlowCovariancesNUA->SetBinContent(26,wPrefactor26*covariance26);
3725
3726  // Cov(<cos(phi1-phi2-phi3)>,<sin(phi1-phi2-phi3)>):
3727  Double_t product27 = fIntFlowProductOfCorrectionTermsForNUAPro->GetBinContent(27); // <<cos(phi1-phi2-phi3)><sin(phi1-phi2-phi3)>> 
3728  Double_t term1st27 = fIntFlowCorrectionTermsForNUAPro[1]->GetBinContent(2); // <<cos(phi1-phi2-phi3)>>
3729  Double_t term2nd27 = fIntFlowCorrectionTermsForNUAPro[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
3730  Double_t sumOfW1st27 = fIntFlowSumOfEventWeightsNUA[1][0]->GetBinContent(2); // W_{<cos(phi1-phi2-phi3)>}
3731  Double_t sumOfW2nd27 = fIntFlowSumOfEventWeightsNUA[0][0]->GetBinContent(3); // W_{<sin(phi1-phi2-phi3)>}
3732  Double_t sumOfWW27 = fIntFlowSumOfProductOfEventWeightsNUA->GetBinContent(27); // W_{<cos(phi1-phi2-phi3)>} * W_{<sin(phi1-phi2-phi3)>}
3733  // numerator in the expression for the the unbiased estimator for covariance:
3734  Double_t numerator27 = product27 - term1st27*term2nd27; 
3735  // denominator in the expression for the the unbiased estimator for covariance:
3736  Double_t denominator27 = 1.-sumOfWW27/(sumOfW1st27*sumOfW2nd27);
3737  // covariance:
3738  Double_t covariance27 = numerator27/denominator27;
3739  // weight dependent prefactor for covariance:
3740  Double_t wPrefactor27 = sumOfWW27/(sumOfW1st27*sumOfW2nd27);
3741  // finally, store "weighted" covariance:
3742  fIntFlowCovariancesNUA->SetBinContent(27,wPrefactor27*covariance27);
3743
3744 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesNUAIntFlow()
3745
3746
3747 //================================================================================================================================
3748
3749
3750 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow() 
3751 {
3752  // From profile fIntFlowCorrelationsPro access measured correlations and spread, 
3753  // correctly calculate the statistical errors and store the final results and 
3754  // statistical errors for correlations in histogram fIntFlowCorrelationsHist.
3755  //
3756  // Remark: Statistical error of correlation is calculated as:
3757  //
3758  //          statistical error = termA * spread * termB:
3759  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
3760  //          termB = 1/sqrt(1-termA^2)   
3761  //
3762    
3763  for(Int_t ci=1;ci<=4;ci++) // correlation index
3764  {
3765   Double_t correlation = fIntFlowCorrelationsPro->GetBinContent(ci);
3766   Double_t spread = fIntFlowCorrelationsPro->GetBinError(ci);
3767   Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeights[0]->GetBinContent(ci);
3768   Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeights[1]->GetBinContent(ci);
3769   Double_t termA = 0.;
3770   Double_t termB = 0.;
3771   if(TMath::Abs(sumOfLinearEventWeights) > 0.) // to be improved - shall I omitt here Abs() ?
3772   {
3773    termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
3774   } else
3775     {
3776      cout<<endl;
3777      cout<<" WARNING (QC): sumOfLinearEventWeights == 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;
3778      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
3779      cout<<endl;
3780     }
3781   if(1.-pow(termA,2.) > 0.)
3782   {
3783    termB = 1./pow(1-pow(termA,2.),0.5);
3784   } else
3785     {
3786      cout<<endl;
3787      cout<<" WARNING (QC): 1.-pow(termA,2.) <= 0 in method FinalizeCorrelationsIntFlow() !!!!"<<endl;   
3788      cout<<"               (for "<<2*ci<<"-particle correlation)"<<endl;
3789      cout<<endl;
3790     }     
3791   Double_t statisticalError = termA * spread * termB;
3792   fIntFlowCorrelationsHist->SetBinContent(ci,correlation);
3793   fIntFlowCorrelationsHist->SetBinError(ci,statisticalError);
3794  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index     
3795  
3796  // Versus multiplicity: 
3797  if(!fCalculateCumulantsVsM){return;}
3798  for(Int_t ci=0;ci<=3;ci++) // correlation index
3799  {
3800   Int_t nBins = fIntFlowCorrelationsVsMPro[ci]->GetNbinsX(); 
3801   for(Int_t b=1;b<=nBins;b++) // looping over multiplicity bins
3802   {
3803    Double_t correlationVsM = fIntFlowCorrelationsVsMPro[ci]->GetBinContent(b);
3804    Double_t spreadVsM = fIntFlowCorrelationsVsMPro[ci]->GetBinError(b);
3805    Double_t sumOfLinearEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][0]->GetBinContent(b);
3806    Double_t sumOfQuadraticEventWeightsVsM = fIntFlowSumOfEventWeightsVsM[ci][1]->GetBinContent(b);
3807    Double_t termAVsM = 0.;
3808    Double_t termBVsM = 0.;
3809    if(TMath::Abs(sumOfLinearEventWeightsVsM) > 0.) // to be improved - shall I omitt here Abs() ?
3810    {
3811     termAVsM = pow(sumOfQuadraticEventWeightsVsM,0.5)/sumOfLinearEventWeightsVsM;
3812    }
3813    if(1.-pow(termAVsM,2.) > 0.)
3814    {
3815     termBVsM = 1./pow(1-pow(termAVsM,2.),0.5);
3816    }     
3817    Double_t statisticalErrorVsM = termAVsM * spreadVsM * termBVsM;
3818    fIntFlowCorrelationsVsMHist[ci]->SetBinContent(b,correlationVsM);
3819    fIntFlowCorrelationsVsMHist[ci]->SetBinError(b,statisticalErrorVsM);  
3820   } // end of for(Int_t b=1;b<=nBins;b++)
3821  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index                                                        
3822                                                                                                                            
3823 } // end of AliFlowAnalysisWithQCumulants::FinalizeCorrelationsIntFlow()
3824
3825 //================================================================================================================================
3826
3827 void AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(Int_t nRP)
3828 {
3829  // Fill profile fAverageMultiplicity to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
3830  
3831  // Binning of fAverageMultiplicity is organized as follows:
3832  //  1st bin: all events (including the empty ones)
3833  //  2nd bin: event with # of RPs greater or equal to 1
3834  //  3rd bin: event with # of RPs greater or equal to 2
3835  //  4th bin: event with # of RPs greater or equal to 3
3836  //  5th bin: event with # of RPs greater or equal to 4
3837  //  6th bin: event with # of RPs greater or equal to 5
3838  //  7th bin: event with # of RPs greater or equal to 6
3839  //  8th bin: event with # of RPs greater or equal to 7
3840  //  9th bin: event with # of RPs greater or equal to 8
3841  
3842  if(!fAvMultiplicity)
3843  {
3844   cout<<"WARNING: fAvMultiplicity is NULL in AFAWQC::FAM() !!!!"<<endl;
3845   exit(0);
3846  }
3847  
3848  if(nRP<0)
3849  {
3850   cout<<"WARNING: nRP<0 in in AFAWQC::FAM() !!!!"<<endl;
3851   exit(0);
3852  }
3853  
3854  for(Int_t i=0;i<9;i++)
3855  {
3856   if(nRP>=i) fAvMultiplicity->Fill(i+0.5,nRP,1);
3857  }
3858  
3859 } // end of AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(nRP)
3860
3861
3862 //================================================================================================================================
3863
3864
3865 void AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
3866
3867  // a) Calculate Q-cumulants from the measured multiparticle correlations.
3868  // b) Propagate the statistical errors of measured multiparticle correlations to statistical errors of Q-cumulants.  
3869  // c) REMARK: Q-cumulants calculated in this method are biased by non-uniform acceptance of detector !!!! 
3870  //            Method ApplyCorrectionForNonUniformAcceptance* (to be improved: finalize the name here)
3871  //            is called afterwards to correct for this bias.   
3872  // d) Store the results and statistical error of Q-cumulants in histogram fCumulants.
3873  //    Binning of fCumulants is organized as follows:
3874  //
3875  //            1st bin: QC{2}
3876  //            2nd bin: QC{4}
3877  //            3rd bin: QC{6}
3878  //            4th bin: QC{8}
3879  //
3880  
3881  // to be improved: revise the names and check the pointers used in this method
3882  
3883  // Correlations:
3884  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
3885  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
3886  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
3887  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
3888  // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
3889  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
3890  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
3891  Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
3892  Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
3893  // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
3894  Double_t wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
3895  Double_t wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
3896  Double_t wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
3897  Double_t wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
3898  Double_t wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
3899  Double_t wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
3900  // Q-cumulants: 
3901  Double_t qc2 = 0.; // QC{2}
3902  Double_t qc4 = 0.; // QC{4}
3903  Double_t qc6 = 0.; // QC{6}
3904  Double_t qc8 = 0.; // QC{8}
3905  if(TMath::Abs(two) > 0.){qc2 = two;} 
3906  if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
3907  if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
3908  if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);} 
3909  // Statistical errors of Q-cumulants:       
3910  Double_t qc2Error = 0.;
3911  Double_t qc4Error = 0.;
3912  Double_t qc6Error = 0.;
3913  Double_t qc8Error = 0.; 
3914  // Squared statistical errors of Q-cumulants:       
3915  //Double_t qc2ErrorSquared = 0.;
3916  Double_t qc4ErrorSquared = 0.;
3917  Double_t qc6ErrorSquared = 0.;
3918  Double_t qc8ErrorSquared = 0.;        
3919  // Statistical error of QC{2}:              
3920  qc2Error = twoError;                                                 
3921  // Statistical error of QC{4}:              
3922  qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
3923                  - 8.*two*wCov24;                     
3924  if(qc4ErrorSquared>0.)
3925  {
3926   qc4Error = pow(qc4ErrorSquared,0.5);
3927  } else 
3928    {
3929     cout<<" WARNING (QC): Statistical error of QC{4} is imaginary !!!!"<<endl;
3930    }                                           
3931  // Statistical error of QC{6}:              
3932  qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
3933                  + 81.*pow(two,2.)*pow(fourError,2.)
3934                  + pow(sixError,2.)
3935                  - 162.*two*(4.*pow(two,2.)-four)*wCov24
3936                  + 18.*(4.*pow(two,2.)-four)*wCov26
3937                  - 18.*two*wCov46;                     
3938  if(qc6ErrorSquared>0.)
3939  {
3940   qc6Error = pow(qc6ErrorSquared,0.5);
3941  } else 
3942    {
3943     cout<<" WARNING (QC): Statistical error of QC{6} is imaginary !!!!"<<endl;
3944    }                       
3945  // Statistical error of QC{8}:              
3946  qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
3947                  + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
3948                  + 256.*pow(two,2.)*pow(sixError,2.)
3949                  + pow(eightError,2.)
3950                  - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
3951                  + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
3952                  - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
3953                  - 1152.*two*(4.*pow(two,2.)-four)*wCov46
3954                  + 72.*(4.*pow(two,2.)-four)*wCov48
3955                  - 32.*two*wCov68;      
3956  if(qc8ErrorSquared>0.)
3957  {
3958   qc8Error = pow(qc8ErrorSquared,0.5);
3959  } else 
3960    {
3961     cout<<"WARNING (QC): Statistical error of QC{8} is imaginary !!!!"<<endl;
3962    }
3963  // Store the results and statistical errors for Q-cumulants:
3964  if(TMath::Abs(qc2)>0.)
3965  {
3966   fIntFlowQcumulants->SetBinContent(1,qc2);
3967   fIntFlowQcumulants->SetBinError(1,qc2Error);
3968  }
3969  if(TMath::Abs(qc4)>0.)
3970  {
3971   fIntFlowQcumulants->SetBinContent(2,qc4);
3972   fIntFlowQcumulants->SetBinError(2,qc4Error);
3973  }
3974  if(TMath::Abs(qc6)>0.)
3975  {
3976   fIntFlowQcumulants->SetBinContent(3,qc6);
3977   fIntFlowQcumulants->SetBinError(3,qc6Error);
3978  }
3979  if(TMath::Abs(qc8)>0.)
3980  {
3981   fIntFlowQcumulants->SetBinContent(4,qc8); 
3982   fIntFlowQcumulants->SetBinError(4,qc8Error);
3983  } 
3984  
3985  // Versus multiplicity: 
3986  if(!fCalculateCumulantsVsM){return;}
3987  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
3988  Double_t value[4] = {0.}; // QCs vs M
3989  Double_t error[4] = {0.}; // error of QCs vs M
3990  Double_t dSum1[4] = {0.}; // sum value_i/(error_i)^2
3991  Double_t dSum2[4] = {0.}; // sum 1/(error_i)^2
3992  for(Int_t b=1;b<=nBins;b++)
3993  {
3994   // Correlations:
3995   two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> 
3996   four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>>  
3997   six = fIntFlowCorrelationsVsMHist[2]->GetBinContent(b); // <<6>> 
3998   eight = fIntFlowCorrelationsVsMHist[3]->GetBinContent(b); // <<8>>  
3999   // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
4000   twoError = fIntFlowCorrelationsVsMHist[0]->GetBinError(b); // statistical error of <2>  
4001   fourError = fIntFlowCorrelationsVsMHist[1]->GetBinError(b); // statistical error of <4>   
4002   sixError = fIntFlowCorrelationsVsMHist[2]->GetBinError(b); // statistical error of <6> 
4003   eightError = fIntFlowCorrelationsVsMHist[3]->GetBinError(b); // statistical error of <8> 
4004   // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
4005   wCov24 = fIntFlowCovariancesVsM[0]->GetBinContent(b); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4006   wCov26 = fIntFlowCovariancesVsM[1]->GetBinContent(b); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4007   wCov28 = fIntFlowCovariancesVsM[2]->GetBinContent(b); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4008   wCov46 = fIntFlowCovariancesVsM[3]->GetBinContent(b); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4009   wCov48 = fIntFlowCovariancesVsM[4]->GetBinContent(b); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4010   wCov68 = fIntFlowCovariancesVsM[5]->GetBinContent(b); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>) 
4011   // Q-cumulants: 
4012   qc2 = 0.; // QC{2}
4013   qc4 = 0.; // QC{4}
4014   qc6 = 0.; // QC{6}
4015   qc8 = 0.; // QC{8}
4016   if(TMath::Abs(two) > 0.){qc2 = two;} 
4017   if(TMath::Abs(four) > 0.){qc4 = four-2.*pow(two,2.);} 
4018   if(TMath::Abs(six) > 0.){qc6 = six-9.*two*four+12.*pow(two,3.);} 
4019   if(TMath::Abs(eight) > 0.){qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);}  
4020   // Statistical errors of Q-cumulants:       
4021   qc2Error = 0.;
4022   qc4Error = 0.;
4023   qc6Error = 0.;
4024   qc8Error = 0.; 
4025   // Squared statistical errors of Q-cumulants:       
4026   //Double_t qc2ErrorSquared = 0.;
4027   qc4ErrorSquared = 0.;
4028   qc6ErrorSquared = 0.;
4029   qc8ErrorSquared = 0.;    
4030   // Statistical error of QC{2}:              
4031   qc2Error = twoError;                                             
4032   // Statistical error of QC{4}:              
4033   qc4ErrorSquared = 16.*pow(two,2.)*pow(twoError,2)+pow(fourError,2.)
4034                   - 8.*two*wCov24;                     
4035   if(qc4ErrorSquared>0.)
4036   {
4037    qc4Error = pow(qc4ErrorSquared,0.5);
4038   } else 
4039     {
4040      // cout<<"WARNING: Statistical error of QC{4} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4041     }                                       
4042   // Statistical error of QC{6}:              
4043   qc6ErrorSquared = 81.*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.)
4044                   + 81.*pow(two,2.)*pow(fourError,2.)
4045                   + pow(sixError,2.)
4046                   - 162.*two*(4.*pow(two,2.)-four)*wCov24
4047                   + 18.*(4.*pow(two,2.)-four)*wCov26
4048                   - 18.*two*wCov46;                     
4049   if(qc6ErrorSquared>0.)
4050   {
4051    qc6Error = pow(qc6ErrorSquared,0.5);
4052   } else 
4053     {
4054      // cout<<"WARNING: Statistical error of QC{6} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4055     }                            
4056   // Statistical error of QC{8}:              
4057   qc8ErrorSquared = 256.*pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
4058                   + 1296.*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
4059                   + 256.*pow(two,2.)*pow(sixError,2.)
4060                   + pow(eightError,2.)
4061                   - 1152.*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
4062                   + 512.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
4063                   - 32.*(36.*pow(two,3.)-18.*four*two+six)*wCov28
4064                   - 1152.*two*(4.*pow(two,2.)-four)*wCov46
4065                   + 72.*(4.*pow(two,2.)-four)*wCov48
4066                   - 32.*two*wCov68;      
4067   if(qc8ErrorSquared>0.)
4068   {
4069    qc8Error = pow(qc8ErrorSquared,0.5);
4070   } else 
4071     {
4072      // cout<<"WARNING: Statistical error of QC{8} is imaginary in multiplicity bin "<<b<<" !!!!"<<endl;
4073     }
4074   // Store the results and statistical errors for Q-cumulants:
4075   if(TMath::Abs(qc2)>0.)
4076   {
4077    fIntFlowQcumulantsVsM[0]->SetBinContent(b,qc2);
4078    fIntFlowQcumulantsVsM[0]->SetBinError(b,qc2Error);  
4079   }
4080   if(TMath::Abs(qc4)>0.)
4081   {
4082    fIntFlowQcumulantsVsM[1]->SetBinContent(b,qc4);  
4083    fIntFlowQcumulantsVsM[1]->SetBinError(b,qc4Error);
4084   }
4085   if(TMath::Abs(qc6)>0.)
4086   {
4087    fIntFlowQcumulantsVsM[2]->SetBinContent(b,qc6); 
4088    fIntFlowQcumulantsVsM[2]->SetBinError(b,qc6Error);
4089   }
4090   if(TMath::Abs(qc8)>0.)
4091   {  
4092    fIntFlowQcumulantsVsM[3]->SetBinContent(b,qc8);
4093    fIntFlowQcumulantsVsM[3]->SetBinError(b,qc8Error);
4094   } 
4095   // Rebin in M:
4096   for(Int_t co=0;co<4;co++)
4097   {
4098    value[co] = fIntFlowQcumulantsVsM[co]->GetBinContent(b);
4099    error[co] = fIntFlowQcumulantsVsM[co]->GetBinError(b);
4100    if(error[co]>0.)
4101    {
4102     dSum1[co]+=value[co]/(error[co]*error[co]);
4103     dSum2[co]+=1./(error[co]*error[co]);
4104    }
4105   } // end of for(Int_t co=0;co<4;co++) 
4106  } // end of for(Int_t b=1;b<=nBins;b++)
4107  // Store rebinned Q-cumulants:
4108  for(Int_t co=0;co<4;co++)
4109  {
4110   if(dSum2[co]>0.)
4111   {
4112    fIntFlowQcumulantsRebinnedInM->SetBinContent(co+1,dSum1[co]/dSum2[co]);
4113    fIntFlowQcumulantsRebinnedInM->SetBinError(co+1,pow(1./dSum2[co],0.5));
4114   }
4115  } // end of for(Int_t co=0;co<4;co++)
4116  
4117 } // end of AliFlowAnalysisWithQCumulants::CalculateCumulantsIntFlow()
4118
4119 //================================================================================================================================ 
4120
4121 void AliFlowAnalysisWithQCumulants::CalculateIntFlow()
4122 {
4123  // a) Calculate the final results for reference flow estimates from Q-cumulants.
4124  // b) Propagate the statistical errors to reference flow estimates from 
4125  //    - measured multiparticle correlations (set kTRUE for fPropagateErrorFromCorrelations), or
4126  //    - cumulants (set kFALSE for fPropagateErrorFromCorrelations). 
4127  // c) Store the results and statistical errors of reference flow estimates in histogram fIntFlow.
4128  //    Binning of fIntFlow is organized as follows:
4129  //
4130  //            1st bin: v{2,QC}
4131  //            2nd bin: v{4,QC}
4132  //            3rd bin: v{6,QC}
4133  //            4th bin: v{8,QC}
4134  //
4135  
4136  // to be improved: revise the names and check the pointers used in this method, add something about calculation vs M
4137   
4138  if(!(fIntFlowCorrelationsHist && fIntFlowCovariances && fIntFlowQcumulants && fIntFlow))
4139  {
4140   cout<<"WARNING: fIntFlowCorrelationsHist && fIntFlowCovariances && fIntFlowQcumulants && fIntFlow is NULL in AFAWQC::CCIF() !!!!"<<endl;
4141   exit(0);
4142  }
4143    
4144  // Reference flow estimates:
4145  Double_t v2 = 0.; // v{2,QC}  
4146  Double_t v4 = 0.; // v{4,QC}  
4147  Double_t v6 = 0.; // v{6,QC}  
4148  Double_t v8 = 0.; // v{8,QC}
4149  // Reference flow's statistical errors:
4150  Double_t v2Error = 0.; // v{2,QC} stat. error 
4151  Double_t v4Error = 0.; // v{4,QC} stat. error
4152  Double_t v6Error = 0.; // v{6,QC} stat. error
4153  Double_t v8Error = 0.; // v{8,QC} stat. error
4154   
4155  if(!fPropagateErrorFromCorrelations) 
4156  {
4157   // Q-cumulants:
4158   Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
4159   Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
4160   Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
4161   Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
4162   // Q-cumulants's statistical errors: 
4163   Double_t qc2Error = fIntFlowQcumulants->GetBinError(1); // QC{2} stat. error  
4164   Double_t qc4Error = fIntFlowQcumulants->GetBinError(2); // QC{4} stat. error  
4165   Double_t qc6Error = fIntFlowQcumulants->GetBinError(3); // QC{6} stat. error  
4166   Double_t qc8Error = fIntFlowQcumulants->GetBinError(4); // QC{8} stat. error
4167   // Calculate reference flow estimates from Q-cumulants: 
4168   if(qc2>=0.){v2 = pow(qc2,1./2.);} 
4169   if(qc4<=0.){v4 = pow(-1.*qc4,1./4.);} 
4170   if(qc6>=0.){v6 = pow((1./4.)*qc6,1./6.);}
4171   if(qc8<=0.){v8 = pow((-1./33.)*qc8,1./8.);}  
4172   // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
4173   if(qc2>0.){v2Error = (1./2.)*pow(qc2,-1./2.)*qc2Error;} 
4174   if(qc4<0.){v4Error = (1./4.)*pow(-qc4,-3./4.)*qc4Error;} 
4175   if(qc6>0.){v6Error = (1./6.)*pow(2.,-1./3.)*pow(qc6,-5./6.)*qc6Error;}   
4176   if(qc8<0.){v8Error = (1./8.)*pow(33.,-1./8.)*pow(-qc8,-7./8.)*qc8Error;}   
4177   // Print warnings for the 'wrong sign' cumulants: 
4178   if(TMath::Abs(v2) < 1.e-44)
4179   {
4180    cout<<" WARNING: Wrong sign QC{2}, couldn't calculate v{2,QC} !!!!"<<endl;
4181   }
4182   if(TMath::Abs(v4) < 1.e-44)
4183   {
4184    cout<<" WARNING: Wrong sign QC{4}, couldn't calculate v{4,QC} !!!!"<<endl;
4185   }
4186   if(TMath::Abs(v6) < 1.e-44)
4187   {
4188    cout<<" WARNING: Wrong sign QC{6}, couldn't calculate v{6,QC} !!!!"<<endl;
4189   }
4190   if(TMath::Abs(v8) < 1.e-44)
4191   {
4192    cout<<" WARNING: Wrong sign QC{8}, couldn't calculate v{8,QC} !!!!"<<endl;
4193   }                       
4194   // Store the results and statistical errors of integrated flow estimates:
4195   fIntFlow->SetBinContent(1,v2);
4196   fIntFlow->SetBinError(1,v2Error);
4197   fIntFlow->SetBinContent(2,v4);
4198   fIntFlow->SetBinError(2,v4Error);
4199   fIntFlow->SetBinContent(3,v6);
4200   fIntFlow->SetBinError(3,v6Error);
4201   fIntFlow->SetBinContent(4,v8);
4202   fIntFlow->SetBinError(4,v8Error);  
4203   
4204   // Versus multiplicity: 
4205   if(!fCalculateCumulantsVsM){return;} // to be improved - not compatible with if(fPropagateErrorFromCorrelations) bellow
4206   Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
4207   for(Int_t b=1;b<=nBins;b++)
4208   {
4209    // Q-cumulants:
4210    Double_t qc2VsM = fIntFlowQcumulantsVsM[0]->GetBinContent(b); // QC{2}  
4211    Double_t qc4VsM = fIntFlowQcumulantsVsM[1]->GetBinContent(b); // QC{4}  
4212    Double_t qc6VsM = fIntFlowQcumulantsVsM[2]->GetBinContent(b); // QC{6}  
4213    Double_t qc8VsM = fIntFlowQcumulantsVsM[3]->GetBinContent(b); // QC{8}
4214    // Q-cumulants's statistical errors: 
4215    Double_t qc2ErrorVsM = fIntFlowQcumulantsVsM[0]->GetBinError(b); // QC{2} stat. error  
4216    Double_t qc4ErrorVsM = fIntFlowQcumulantsVsM[1]->GetBinError(b); // QC{4} stat. error  
4217    Double_t qc6ErrorVsM = fIntFlowQcumulantsVsM[2]->GetBinError(b); // QC{6} stat. error  
4218    Double_t qc8ErrorVsM = fIntFlowQcumulantsVsM[3]->GetBinError(b); // QC{8} stat. error
4219    // Reference flow estimates:
4220    Double_t v2VsM = 0.; // v{2,QC}  
4221    Double_t v4VsM = 0.; // v{4,QC}  
4222    Double_t v6VsM = 0.; // v{6,QC}  
4223    Double_t v8VsM = 0.; // v{8,QC}
4224    // Reference flow estimates errors:
4225    Double_t v2ErrorVsM = 0.; // v{2,QC} stat. error  
4226    Double_t v4ErrorVsM = 0.; // v{4,QC} stat. error
4227    Double_t v6ErrorVsM = 0.; // v{6,QC} stat. error  
4228    Double_t v8ErrorVsM = 0.; // v{8,QC} stat. error
4229    // Calculate reference flow estimates from Q-cumulants: 
4230    if(qc2VsM>=0.){v2VsM = pow(qc2VsM,1./2.);} 
4231    if(qc4VsM<=0.){v4VsM = pow(-1.*qc4VsM,1./4.);} 
4232    if(qc6VsM>=0.){v6VsM = pow((1./4.)*qc6VsM,1./6.);}
4233    if(qc8VsM<=0.){v8VsM = pow((-1./33.)*qc8VsM,1./8.);}  
4234    // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
4235    if(qc2VsM>0.){v2ErrorVsM = (1./2.)*pow(qc2VsM,-1./2.)*qc2ErrorVsM;} 
4236    if(qc4VsM<0.){v4ErrorVsM = (1./4.)*pow(-qc4VsM,-3./4.)*qc4ErrorVsM;} 
4237    if(qc6VsM>0.){v6ErrorVsM = (1./6.)*pow(2.,-1./3.)*pow(qc6VsM,-5./6.)*qc6ErrorVsM;}   
4238    if(qc8VsM<0.){v8ErrorVsM = (1./8.)*pow(33.,-1./8.)*pow(-qc8VsM,-7./8.)*qc8ErrorVsM;}                       
4239    // Store the results and statistical errors of integrated flow estimates:
4240    fIntFlowVsM[0]->SetBinContent(b,v2VsM);
4241    fIntFlowVsM[0]->SetBinError(b,v2ErrorVsM);
4242    fIntFlowVsM[1]->SetBinContent(b,v4VsM);
4243    fIntFlowVsM[1]->SetBinError(b,v4ErrorVsM);
4244    fIntFlowVsM[2]->SetBinContent(b,v6VsM);
4245    fIntFlowVsM[2]->SetBinError(b,v6ErrorVsM);
4246    fIntFlowVsM[3]->SetBinContent(b,v8VsM);
4247    fIntFlowVsM[3]->SetBinError(b,v8ErrorVsM);
4248   } // end of for(Int_t b=1;b<=nBins;b++)
4249  
4250   // 'Rebinned in M' calculation: // to be improved - this can be implemented better:   
4251   // Reference flow estimates:
4252   Double_t v2RebinnedInM = 0.; // v{2,QC}  
4253   Double_t v4RebinnedInM = 0.; // v{4,QC}  
4254   Double_t v6RebinnedInM = 0.; // v{6,QC}  
4255   Double_t v8RebinnedInM = 0.; // v{8,QC}
4256   // Reference flow's statistical errors:
4257   Double_t v2ErrorRebinnedInM = 0.; // v{2,QC} stat. error 
4258   Double_t v4ErrorRebinnedInM = 0.; // v{4,QC} stat. error
4259   Double_t v6ErrorRebinnedInM = 0.; // v{6,QC} stat. error
4260   Double_t v8ErrorRebinnedInM = 0.; // v{8,QC} stat. error
4261   // Q-cumulants:
4262   Double_t qc2RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(1); // QC{2}  
4263   Double_t qc4RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(2); // QC{4}  
4264   Double_t qc6RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(3); // QC{6}  
4265   Double_t qc8RebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinContent(4); // QC{8}
4266   // Q-cumulants's statistical errors: 
4267   Double_t qc2ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(1); // QC{2} stat. error  
4268   Double_t qc4ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(2); // QC{4} stat. error  
4269   Double_t qc6ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(3); // QC{6} stat. error  
4270   Double_t qc8ErrorRebinnedInM = fIntFlowQcumulantsRebinnedInM->GetBinError(4); // QC{8} stat. error
4271   // Calculate reference flow estimates from Q-cumulants: 
4272   if(qc2RebinnedInM>=0.){v2RebinnedInM = pow(qc2RebinnedInM,1./2.);} 
4273   if(qc4RebinnedInM<=0.){v4RebinnedInM = pow(-1.*qc4RebinnedInM,1./4.);} 
4274   if(qc6RebinnedInM>=0.){v6RebinnedInM = pow((1./4.)*qc6RebinnedInM,1./6.);}
4275   if(qc8RebinnedInM<=0.){v8RebinnedInM = pow((-1./33.)*qc8RebinnedInM,1./8.);}  
4276   // Calculate stat. error for reference flow estimates from stat. error of Q-cumulants: 
4277   if(qc2RebinnedInM>0.){v2ErrorRebinnedInM = (1./2.)*pow(qc2RebinnedInM,-1./2.)*qc2ErrorRebinnedInM;} 
4278   if(qc4RebinnedInM<0.){v4ErrorRebinnedInM = (1./4.)*pow(-qc4RebinnedInM,-3./4.)*qc4ErrorRebinnedInM;} 
4279   if(qc6RebinnedInM>0.){v6ErrorRebinnedInM = (1./6.)*pow(2.,-1./3.)*pow(qc6RebinnedInM,-5./6.)*qc6ErrorRebinnedInM;}   
4280   if(qc8RebinnedInM<0.){v8ErrorRebinnedInM = (1./8.)*pow(33.,-1./8.)*pow(-qc8RebinnedInM,-7./8.)*qc8ErrorRebinnedInM;}   
4281   // Print warnings for the 'wrong sign' cumulants: 
4282   if(TMath::Abs(v2RebinnedInM) < 1.e-44)
4283   {
4284    cout<<" WARNING: Wrong sign QC{2} rebinned in M, couldn't calculate v{2,QC} !!!!"<<endl;
4285   }
4286   if(TMath::Abs(v4RebinnedInM) < 1.e-44)
4287   {
4288    cout<<" WARNING: Wrong sign QC{4} rebinned in M, couldn't calculate v{4,QC} !!!!"<<endl;
4289   }
4290   if(TMath::Abs(v6RebinnedInM) < 1.e-44)
4291   {
4292    cout<<" WARNING: Wrong sign QC{6} rebinned in M, couldn't calculate v{6,QC} !!!!"<<endl;
4293   }
4294   if(TMath::Abs(v8RebinnedInM) < 1.e-44)
4295   {
4296    cout<<" WARNING: Wrong sign QC{8} rebinned in M, couldn't calculate v{8,QC} !!!!"<<endl;
4297   }                       
4298   // Store the results and statistical errors of integrated flow estimates:
4299   fIntFlowRebinnedInM->SetBinContent(1,v2RebinnedInM);
4300   fIntFlowRebinnedInM->SetBinError(1,v2ErrorRebinnedInM);
4301   fIntFlowRebinnedInM->SetBinContent(2,v4RebinnedInM);
4302   fIntFlowRebinnedInM->SetBinError(2,v4ErrorRebinnedInM);
4303   fIntFlowRebinnedInM->SetBinContent(3,v6RebinnedInM);
4304   fIntFlowRebinnedInM->SetBinError(3,v6ErrorRebinnedInM);
4305   fIntFlowRebinnedInM->SetBinContent(4,v8RebinnedInM);
4306   fIntFlowRebinnedInM->SetBinError(4,v8ErrorRebinnedInM);    
4307  } // end of if(!fPropagateErrorFromCorrelations) 
4308   
4309  // Used only for debugging/cross-checking:
4310  if(fPropagateErrorFromCorrelations)
4311  {
4312   // Measured azimuthal correlations:
4313   Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
4314   Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
4315   Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
4316   Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
4317   // Statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
4318   Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
4319   Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
4320   Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
4321   Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
4322   // Covariances (multiplied by prefactor depending on weights - see comments in CalculateCovariancesIntFlow()):
4323   Double_t wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
4324   Double_t wCov26 = fIntFlowCovariances->GetBinContent(2); // Cov(<2>,<6>) * prefactor(w_<2>,w_<6>)
4325   Double_t wCov28 = fIntFlowCovariances->GetBinContent(3); // Cov(<2>,<8>) * prefactor(w_<2>,w_<8>)
4326   Double_t wCov46 = fIntFlowCovariances->GetBinContent(4); // Cov(<4>,<6>) * prefactor(w_<4>,w_<6>)
4327   Double_t wCov48 = fIntFlowCovariances->GetBinContent(5); // Cov(<4>,<8>) * prefactor(w_<4>,w_<8>)
4328   Double_t wCov68 = fIntFlowCovariances->GetBinContent(6); // Cov(<6>,<8>) * prefactor(w_<6>,w_<8>)   
4329   // Calculate reference flow estimates: 
4330   if(two>=0.){v2 = pow(two,1./2.);} 
4331   if(TMath::Abs(four)>0. && four-2.*pow(two,2.) < 0.){v4 = pow(-1.*(four-2.*pow(two,2.)),1./4.);} 
4332   if(TMath::Abs(six)>0. && six-9.*two*four+12.*pow(two,3.) > 0.){v6 = pow((1./4.)*(six-9.*two*four+12.*pow(two,3.)),1./6.);} 
4333   if(TMath::Abs(eight)>0. && eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.) < 0.) 
4334     {v8 = pow((-1./33.)*(eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.)),1./8.);} 
4335   // Squares of statistical errors of reference flow estimates:
4336   Double_t v2ErrorSquared = 0.; // squared statistical error of v{2,QC} 
4337   Double_t v4ErrorSquared = 0.; // squared statistical error of v{4,QC}   
4338   Double_t v6ErrorSquared = 0.; // squared statistical error of v{6,QC}   
4339   Double_t v8ErrorSquared = 0.; // squared statistical error of v{8,QC} 
4340   // Calculate squared statistical errors of reference flow estimates:
4341   if(two > 0.) 
4342   { 
4343    v2ErrorSquared = (1./(4.*two))*pow(twoError,2.);
4344   } 
4345   if(2.*pow(two,2.)-four > 0.)
4346   {
4347    v4ErrorSquared = (1./pow(2.*pow(two,2.)-four,3./2.))
4348                   * (pow(two,2.)*pow(twoError,2.)+(1./16.)*pow(fourError,2.)-(1./2.)*two*wCov24);
4349   }
4350   if(six-9.*four*two+12.*pow(two,3.) > 0.) 
4351   {
4352    v6ErrorSquared = ((1./2.)*(1./pow(2.,2./3.))*(1./pow(six-9.*four*two+12.*pow(two,3.),5./3.)))
4353                   * ((9./2.)*pow(4.*pow(two,2.)-four,2.)*pow(twoError,2.) 
4354                   + (9./2.)*pow(two,2.)*pow(fourError,2.)+(1./18.)*pow(sixError,2.)
4355                   - 9.*two*(4.*pow(two,2.)-four)*wCov24+(4.*pow(two,2.)-four)*wCov26-two*wCov46); 
4356   }
4357   if(-1.*eight+16.*six*two+18.*pow(four,2.)-144.*four*pow(two,2.)+144.*pow(two,4.) > 0.) 
4358   {
4359    v8ErrorSquared = (4./pow(33,1./4.))
4360                   * (1./pow(-1.*eight+16.*six*two+18.*pow(four,2.)-144.*four*pow(two,2.)+144.*pow(two,4.),7./4.))
4361                   * (pow(36.*pow(two,3.)-18.*four*two+six,2.)*pow(twoError,2.)
4362                   + (81./16.)*pow(4.*pow(two,2.)-four,2.)*pow(fourError,2.)
4363                   + pow(two,2.)*pow(sixError,2.)
4364                   + (1./256.)*pow(eightError,2.)
4365                   - (9./2.)*(36.*pow(two,3.)-18.*four*two+six)*(4.*pow(two,2.)-four)*wCov24
4366                   + 2.*two*(36.*pow(two,3.)-18.*four*two+six)*wCov26
4367                   - (1./8.)*(36.*pow(two,3.)-18.*four*two+six)*wCov28                    
4368                   - (9./2.)*two*(4.*pow(two,2.)-four)*wCov46                   
4369                   + (9./32.)*(4.*pow(two,2.)-four)*wCov48                    
4370                   - (1./8.)*two*wCov68);
4371   } 
4372   // Calculate statistical errors of reference flow estimates: 
4373   if(v2ErrorSquared > 0.)
4374   {
4375    v2Error = pow(v2ErrorSquared,0.5);
4376   }    
4377   if(v4ErrorSquared > 0.)
4378   {
4379    v4Error = pow(v4ErrorSquared,0.5);
4380   }    
4381   if(v6ErrorSquared > 0.)
4382   {
4383    v6Error = pow(v6ErrorSquared,0.5);
4384   }     
4385   if(v8ErrorSquared > 0.)
4386   {
4387    v8Error = pow(v8ErrorSquared,0.5);
4388   }    
4389   // Store the results and statistical errors of integrated flow estimates:
4390   fIntFlow->SetBinContent(1,v2);
4391   fIntFlow->SetBinError(1,v2Error);
4392   fIntFlow->SetBinContent(2,v4);
4393   fIntFlow->SetBinError(2,v4Error);
4394   fIntFlow->SetBinContent(3,v6);
4395   fIntFlow->SetBinError(3,v6Error);
4396   fIntFlow->SetBinContent(4,v8);
4397   fIntFlow->SetBinError(4,v8Error); 
4398  } // end of if(fPropagateErrorFromCorrelations) 
4399  
4400 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlow()
4401
4402 //================================================================================================================================ 
4403
4404 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
4405 {
4406  // Fill in AliFlowCommonHistResults histograms relevant for reference flow.
4407  
4408  // There are two possibilities here:
4409  // a) Store minimum bias reference flow - use SetMinimumBiasReferenceFlow(kTRUE). This result is 
4410  //    biased by the interplay between nonflow correlations and multiplicity fluctuations and is 
4411  //    also stored in local histogram fIntFlow; 
4412  // b) Store reference flow obtained from flow analysis performed at fixed multiplicity and 
4413  //    rebinned only at the end of the day - use SetMinimumBiasReferenceFlow(kFALSE). This result
4414  //    is also stored in local histogram fIntFlowRebinnedInM.
4415  
4416  // Reference flow estimates:
4417  Double_t v[4] = {0.};
4418  // Statistical errors of reference flow estimates:
4419  Double_t vError[4] = {0.};
4420   
4421  for(Int_t b=0;b<4;b++)
4422  {
4423   if(fMinimumBiasReferenceFlow)
4424   { 
4425    v[b] = fIntFlow->GetBinContent(b+1);
4426    vError[b] = fIntFlow->GetBinError(b+1);
4427   } else
4428     {
4429      v[b] = fIntFlowRebinnedInM->GetBinContent(b+1);
4430      vError[b] = fIntFlowRebinnedInM->GetBinError(b+1);
4431     }
4432  } // end of for(Int_t b=0;b<4;b++)
4433   
4434  // Fill AliFlowCommonHistResults histogram:
4435  fCommonHistsResults2nd->FillIntegratedFlow(v[0],vError[0]); // to be improved (hardwired 2nd in the name)  
4436  fCommonHistsResults4th->FillIntegratedFlow(v[1],vError[1]); // to be improved (hardwired 4th in the name)
4437  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)) // to be improved (calculate also 6th and 8th order)
4438  {
4439   fCommonHistsResults6th->FillIntegratedFlow(v[2],vError[2]); // to be improved (hardwired 6th in the name)
4440   fCommonHistsResults8th->FillIntegratedFlow(v[3],vError[3]); // to be improved (hardwired 8th in the name) 
4441  }
4442  
4443 } // end of AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow()
4444
4445 //================================================================================================================================ 
4446
4447 /*
4448 void AliFlowAnalysisWithQCumulants::ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
4449 {
4450  // apply correction for non-uniform acceptance to cumulants for integrated flow 
4451  // (Remark: non-corrected cumulants are accessed from fCumulants[pW][0], corrected cumulants are stored in fCumulants[pW][1])
4452  
4453  // shortcuts for the flags:
4454  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not used, 1=pWeights used
4455  Int_t eW = -1;
4456  
4457  if(eventWeights == "exact")
4458  {
4459   eW = 0;
4460  }
4461  
4462  if(!(fCumulants[pW][eW][0] && fCumulants[pW][eW][1] && fCorrections[pW][eW]))
4463  {
4464   cout<<"WARNING: fCumulants[pW][eW][0] && fCumulants[pW][eW][1] && fCorrections[pW][eW] is NULL in AFAWQC::ACFNUATCFIF() !!!!"<<endl;
4465   cout<<"pW = "<<pW<<endl;
4466   cout<<"eW = "<<eW<<endl;
4467   exit(0);
4468  } 
4469   
4470  // non-corrected cumulants:
4471  Double_t qc2 = fCumulants[pW][eW][0]->GetBinContent(1); 
4472  Double_t qc4 = fCumulants[pW][eW][0]->GetBinContent(2); 
4473  Double_t qc6 = fCumulants[pW][eW][0]->GetBinContent(3); 
4474  Double_t qc8 = fCumulants[pW][eW][0]->GetBinContent(4); 
4475  // statistical error of non-corrected cumulants:  
4476  Double_t qc2Error = fCumulants[pW][eW][0]->GetBinError(1); 
4477  Double_t qc4Error = fCumulants[pW][eW][0]->GetBinError(2); 
4478  Double_t qc6Error = fCumulants[pW][eW][0]->GetBinError(3); 
4479  Double_t qc8Error = fCumulants[pW][eW][0]->GetBinError(4); 
4480  // corrections for non-uniform acceptance:
4481  Double_t qc2Correction = fCorrections[pW][eW]->GetBinContent(1); 
4482  Double_t qc4Correction = fCorrections[pW][eW]->GetBinContent(2); 
4483  Double_t qc6Correction = fCorrections[pW][eW]->GetBinContent(3); 
4484  Double_t qc8Correction = fCorrections[pW][eW]->GetBinContent(4); 
4485  // corrected cumulants:
4486  Double_t qc2Corrected = qc2 + qc2Correction;
4487  Double_t qc4Corrected = qc4 + qc4Correction;
4488  Double_t qc6Corrected = qc6 + qc6Correction;
4489  Double_t qc8Corrected = qc8 + qc8Correction;
4490   
4491  // ... to be improved (I need here also to correct error of QCs for NUA. 
4492  // For simplicity sake I assume at the moment that this correction is negliglible, but it will be added eventually...)
4493  
4494  // store corrected results and statistical errors for cumulants:   
4495  fCumulants[pW][eW][1]->SetBinContent(1,qc2Corrected);
4496  fCumulants[pW][eW][1]->SetBinContent(2,qc4Corrected);
4497  fCumulants[pW][eW][1]->SetBinContent(3,qc6Corrected);
4498  fCumulants[pW][eW][1]->SetBinContent(4,qc8Corrected);
4499  fCumulants[pW][eW][1]->SetBinError(1,qc2Error); // to be improved (correct also qc2Error for NUA)
4500  fCumulants[pW][eW][1]->SetBinError(2,qc4Error); // to be improved (correct also qc4Error for NUA)
4501  fCumulants[pW][eW][1]->SetBinError(3,qc6Error); // to be improved (correct also qc6Error for NUA)
4502  fCumulants[pW][eW][1]->SetBinError(4,qc8Error); // to be improved (correct also qc8Error for NUA)  
4503   
4504 } // end of AliFlowAnalysisWithQCumulants::ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
4505 */
4506
4507
4508 //================================================================================================================================
4509
4510
4511 /*  
4512 void AliFlowAnalysisWithQCumulants::PrintQuantifyingCorrectionsForNonUniformAcceptance(Bool_t useParticleWeights, TString eventWeights)
4513 {
4514  // print on the screen QC{n,biased}/QC{n,corrected}
4515  
4516  // shortcuts for the flags:
4517  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not used, 1=pWeights used
4518  
4519  Int_t eW = -1;
4520  
4521  if(eventWeights == "exact")
4522  {
4523   eW = 0;
4524  } 
4525  
4526  if(!(fCumulants[pW][eW][0] && fCumulants[pW][eW][1]))
4527  {
4528   cout<<"WARNING: fCumulants[pW][eW][0] && fCumulants[pW][eW][1] is NULL in AFAWQC::PQCFNUA() !!!!"<<endl;
4529   cout<<"pW = "<<pW<<endl;
4530   cout<<"eW = "<<eW<<endl;
4531   exit(0);
4532  }
4533    
4534  cout<<endl;
4535  cout<<" Quantifying the bias to Q-cumulants from"<<endl;
4536  cout<<"  non-uniform acceptance of the detector:"<<endl;
4537  cout<<endl;
4538   
4539  if(fCumulants[pW][eW][1]->GetBinContent(1)) 
4540  { 
4541   cout<<"  QC{2,biased}/QC{2,corrected} = "<<(fCumulants[pW][eW][0]->GetBinContent(1))/(fCumulants[pW][eW][1]->GetBinContent(1))<<endl;   
4542  }
4543  if(fCumulants[pW][eW][1]->GetBinContent(2)) 
4544  { 
4545   cout<<"  QC{4,biased}/QC{4,corrected} = "<<fCumulants[pW][eW][0]->GetBinContent(2)/fCumulants[pW][eW][1]->GetBinContent(2)<<endl;   
4546  }
4547  
4548  cout<<endl;
4549             
4550 } // end of AliFlowAnalysisWithQCumulants::PrintQuantifyingCorrectionsForNonUniformAcceptance(Bool_t useParticleWeights, TString eventWeights)
4551 */
4552
4553
4554 //================================================================================================================================
4555
4556
4557 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
4558 {
4559  // Calculate all correlations needed for integrated flow using particle weights.
4560   
4561  // Remark 1: When particle weights are used the binning of fIntFlowCorrelationAllPro is organized as follows:
4562  //
4563  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
4564  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
4565  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
4566  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
4567  //  5th bin:           ----  EMPTY ----
4568  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
4569  //  7th bin: <3>_{3n|2n,1n} = ...
4570  //  8th bin: <3>_{4n|2n,2n} = ...
4571  //  9th bin: <3>_{4n|3n,1n} = ...
4572  // 10th bin:           ----  EMPTY ----
4573  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
4574  // 12th bin: <4>_{2n,1n|2n,1n} = ...
4575  // 13th bin: <4>_{2n,2n|2n,2n} = ...
4576  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
4577  // 15th bin: <4>_{3n,1n|3n,1n} = ...
4578  // 16th bin: <4>_{3n,1n|2n,2n} = ...
4579  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
4580  // 18th bin:           ----  EMPTY ----
4581  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
4582  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
4583  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
4584  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
4585  // 23rd bin:           ----  EMPTY ----
4586  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
4587  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
4588  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
4589  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
4590  // 28th bin:           ----  EMPTY ----
4591  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
4592  // 30th bin:           ----  EMPTY ----
4593  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
4594  
4595  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
4596  // fIntFlowExtraCorrelationsPro binning of which is organized as follows:
4597  
4598  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
4599  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
4600  
4601  // multiplicity (number of particles used to determine the reaction plane)
4602  Double_t dMult = (*fSMpk)(0,0);
4603  
4604  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
4605  Double_t dReQ1n1k = (*fReQ)(0,1);
4606  Double_t dReQ2n2k = (*fReQ)(1,2);
4607  Double_t dReQ3n3k = (*fReQ)(2,3);
4608  Double_t dReQ4n4k = (*fReQ)(3,4);
4609  Double_t dReQ1n3k = (*fReQ)(0,3);
4610  Double_t dImQ1n1k = (*fImQ)(0,1);
4611  Double_t dImQ2n2k = (*fImQ)(1,2);
4612  Double_t dImQ3n3k = (*fImQ)(2,3);
4613  Double_t dImQ4n4k = (*fImQ)(3,4);
4614  Double_t dImQ1n3k = (*fImQ)(0,3);
4615
4616  // dMs are variables introduced in order to simplify some Eqs. bellow:
4617  //..............................................................................................
4618  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
4619  Double_t dM22 = (*fSMpk)(1,2)-(*fSMpk)(0,4); // dM22 = sum_{i,j=1,i!=j}^M w_i^2 w_j^2
4620  Double_t dM33 = (*fSMpk)(1,3)-(*fSMpk)(0,6); // dM33 = sum_{i,j=1,i!=j}^M w_i^3 w_j^3
4621  Double_t dM44 = (*fSMpk)(1,4)-(*fSMpk)(0,8); // dM44 = sum_{i,j=1,i!=j}^M w_i^4 w_j^4
4622  Double_t dM31 = (*fSMpk)(0,3)*(*fSMpk)(0,1)-(*fSMpk)(0,4); // dM31 = sum_{i,j=1,i!=j}^M w_i^3 w_j
4623  Double_t dM211 = (*fSMpk)(0,2)*(*fSMpk)(1,1)-2.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4624                 - (*fSMpk)(1,2)+2.*(*fSMpk)(0,4); // dM211 = sum_{i,j,k=1,i!=j!=k}^M w_i^2 w_j w_k
4625  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
4626                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4627                  + 3.*(*fSMpk)(1,2)-6.*(*fSMpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
4628  //..............................................................................................
4629
4630  // 2-particle correlations:
4631  Double_t two1n1nW1W1 = 0.; // <w1 w2 cos(n*(phi1-phi2))>
4632  Double_t two2n2nW2W2 = 0.; // <w1^2 w2^2 cos(2n*(phi1-phi2))>
4633  Double_t two3n3nW3W3 = 0.; // <w1^3 w2^3 cos(3n*(phi1-phi2))>
4634  Double_t two4n4nW4W4 = 0.; // <w1^4 w2^4 cos(4n*(phi1-phi2))>
4635  if(dMult>1) 
4636  { 
4637   if(dM11)
4638   {
4639    two1n1nW1W1 = (pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))/dM11;    
4640    // average correlation <w1 w2 cos(n*(phi1-phi2))> for single event: 
4641    fIntFlowCorrelationsEBE->SetBinContent(1,two1n1nW1W1);
4642    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(1,dM11);
4643    // average correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
4644    fIntFlowCorrelationsPro->Fill(0.5,two1n1nW1W1,dM11);   
4645    fIntFlowCorrelationsAllPro->Fill(0.5,two1n1nW1W1,dM11);   
4646   }
4647   if(dM22)
4648   {
4649    two2n2nW2W2 = (pow(dReQ2n2k,2)+pow(dImQ2n2k,2)-(*fSMpk)(0,4))/dM22; 
4650    // ...
4651    // average correlation <w1^2 w2^2 cos(2n*(phi1-phi2))> for all events:
4652    fIntFlowCorrelationsAllPro->Fill(1.5,two2n2nW2W2,dM22);   
4653   }
4654   if(dM33)
4655   {
4656    two3n3nW3W3 = (pow(dReQ3n3k,2)+pow(dImQ3n3k,2)-(*fSMpk)(0,6))/dM33;
4657    // ...
4658    // average correlation <w1^3 w2^3 cos(3n*(phi1-phi2))> for all events:
4659    fIntFlowCorrelationsAllPro->Fill(2.5,two3n3nW3W3,dM33);   
4660   }
4661   if(dM44)
4662   {
4663    two4n4nW4W4 = (pow(dReQ4n4k,2)+pow(dImQ4n4k,2)-(*fSMpk)(0,8))/dM44; 
4664    // ...
4665    // average correlation <w1^4 w2^4 cos(4n*(phi1-phi2))> for all events:
4666    fIntFlowCorrelationsAllPro->Fill(3.5,two4n4nW4W4,dM44);      
4667   }
4668  } // end of if(dMult>1) 
4669
4670  // extra 2-particle correlations:
4671  Double_t two1n1nW3W1 = 0.; // <w1^3 w2 cos(n*(phi1-phi2))>
4672  Double_t two1n1nW1W1W2 = 0.; // <w1 w2 w3^2 cos(n*(phi1-phi2))> 
4673  if(dMult>1) 
4674  {    
4675   if(dM31)
4676   {
4677    two1n1nW3W1 = (dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k-(*fSMpk)(0,4))/dM31; 
4678    fIntFlowExtraCorrelationsPro->Fill(0.5,two1n1nW3W1,dM31);  
4679   } 
4680   if(dM211)
4681   {
4682    two1n1nW1W1W2 = ((*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))
4683                  - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k
4684                  - (*fSMpk)(0,4)))/dM211;
4685    fIntFlowExtraCorrelationsPro->Fill(1.5,two1n1nW1W1W2,dM211);  
4686   }  
4687  } // end of if(dMult>1)
4688  //..............................................................................................
4689  
4690  //..............................................................................................
4691  // 3-particle correlations:
4692  Double_t three2n1n1nW2W1W1 = 0.; // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
4693  
4694  if(dMult>2) 
4695  { 
4696   if(dM211)
4697   {                                                       
4698    three2n1n1nW2W1W1 = (pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k
4699                      - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
4700                      - pow(dReQ2n2k,2)-pow(dImQ2n2k,2)
4701                      + 2.*(*fSMpk)(0,4))/dM211;                                                                               
4702    fIntFlowCorrelationsAllPro->Fill(5.5,three2n1n1nW2W1W1,dM211);
4703   } 
4704  } // end of if(dMult>2) 
4705  //..............................................................................................
4706  
4707  //..............................................................................................
4708  // 4-particle correlations:
4709  Double_t four1n1n1n1nW1W1W1W1 = 0.; // <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
4710  if(dMult>3) 
4711  { 
4712   if(dM1111)
4713   {      
4714    four1n1n1n1nW1W1W1W1 = (pow(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.),2)
4715                         - 2.*(pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k)
4716                         + 8.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
4717                         + (pow(dReQ2n2k,2)+pow(dImQ2n2k,2))
4718                         - 4.*(*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
4719                         - 6.*(*fSMpk)(0,4)+2.*(*fSMpk)(1,2))/dM1111;  
4720                           
4721    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for single event: 
4722    fIntFlowCorrelationsEBE->SetBinContent(2,four1n1n1n1nW1W1W1W1);
4723    fIntFlowEventWeightsForCorrelationsEBE->SetBinContent(2,dM1111);
4724    // average correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:
4725    fIntFlowCorrelationsPro->Fill(1.5,four1n1n1n1nW1W1W1W1,dM1111);   
4726    fIntFlowCorrelationsAllPro->Fill(10.5,four1n1n1n1nW1W1W1W1,dM1111);   
4727   } 
4728  } // end of if(dMult>3) 
4729  //..............................................................................................
4730  
4731 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrelationsUsingParticleWeights()
4732
4733
4734 //================================================================================================================================
4735
4736
4737 void AliFlowAnalysisWithQCumulants::CalculateWeightedQProductsForIntFlow() // to be improved (completed)
4738 {
4739  // calculate averages like <<2><4>>, <<2><6>>, <<4><6>>, etc. which are needed to calculate covariances 
4740  // Remark: here we take weighted correlations!
4741  
4742  /*
4743  
4744  // binning of fQProductsW is organized as follows:
4745  // 
4746  // 1st bin: <2><4> 
4747  // 2nd bin: <2><6>
4748  // 3rd bin: <2><8>
4749  // 4th bin: <4><6>
4750  // 5th bin: <4><8>
4751  // 6th bin: <6><8>
4752  
4753  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
4754
4755  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
4756  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
4757                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
4758                  + 3.*(*fSMpk)(1,2)-6.*(*fSMpk)(0,4); // dM1111 = sum_{i,j,k,l=1,i!=j!=k!=l}^M w_i w_j w_k w_l
4759
4760  Double_t twoEBEW = 0.; // <2>
4761  Double_t fourEBEW = 0.; // <4>
4762  
4763  twoEBEW = fQCorrelationsEBE[1]->GetBinContent(1);
4764  fourEBEW = fQCorrelationsEBE[1]->GetBinContent(11);
4765  
4766  // <2><4>
4767  if(dMult>3)
4768  {
4769   fQProducts[1][0]->Fill(0.5,twoEBEW*fourEBEW,dM11*dM1111);
4770  }
4771  
4772  */
4773  
4774 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedQProductsForIntFlow()  
4775
4776
4777 //================================================================================================================================
4778
4779
4780 void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
4781 {
4782  // Initialize all arrays used to calculate integrated flow.
4783  
4784  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
4785  {
4786   fIntFlowCorrectionTermsForNUAEBE[sc] = NULL;
4787   fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc] = NULL;
4788   fIntFlowCorrectionTermsForNUAPro[sc] = NULL;
4789   fIntFlowCorrectionTermsForNUAHist[sc] = NULL;
4790   for(Int_t ci=0;ci<4;ci++) // correction term index
4791   {
4792    fIntFlowCorrectionTermsForNUAVsMPro[sc][ci] = NULL;
4793   }
4794   for(Int_t power=0;power<2;power++) // linear or quadratic 
4795   {
4796    fIntFlowSumOfEventWeightsNUA[sc][power] = NULL;
4797   }
4798  }
4799  for(Int_t power=0;power<2;power++) // linear or quadratic 
4800  {
4801   fIntFlowSumOfEventWeights[power] = NULL;    
4802  }
4803  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))
4804  {
4805   fPrintFinalResults[i] = kTRUE;
4806  }
4807  for(Int_t ci=0;ci<4;ci++) // correlation index or cumulant order
4808  {
4809   fIntFlowCorrelationsVsMPro[ci] = NULL;
4810   fIntFlowCorrelationsVsMHist[ci] = NULL;
4811   fIntFlowQcumulantsVsM[ci] = NULL;
4812   fIntFlowVsM[ci] = NULL;
4813   fIntFlowDetectorBiasVsM[ci] = NULL;
4814   for(Int_t lc=0;lc<2;lc++)
4815   {
4816    fIntFlowSumOfEventWeightsVsM[ci][lc] = NULL;
4817   }
4818  } 
4819  for(Int_t pi=0;pi<6;pi++) // product or covariance index
4820  {
4821   fIntFlowProductOfCorrelationsVsMPro[pi] = NULL;
4822   fIntFlowCovariancesVsM[pi] = NULL;
4823   fIntFlowSumOfProductOfEventWeightsVsM[pi] = NULL;
4824  } 
4825   
4826 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
4827
4828 //================================================================================================================================
4829
4830 void AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
4831 {
4832  // Initialize all arrays needed to calculate differential flow.
4833  //  a) Initialize lists holding profiles;
4834  //  b) Initialize lists holding histograms;
4835  //  c) Initialize event-by-event quantities;
4836  //  d) Initialize profiles;
4837  //  e) Initialize histograms holding final results.
4838  
4839  // a) Initialize lists holding profiles;
4840  for(Int_t t=0;t<2;t++) // type (RP, POI)
4841  {
4842   for(Int_t pe=0;pe<2;pe++) // pt or eta
4843   {
4844    fDiffFlowCorrelationsProList[t][pe] = NULL;
4845    fDiffFlowProductOfCorrelationsProList[t][pe] = NULL;
4846    fDiffFlowCorrectionsProList[t][pe] = NULL;
4847   }
4848  }  
4849  
4850  // b) Initialize lists holding histograms;
4851  for(Int_t t=0;t<2;t++) // type (RP, POI)
4852  {
4853   for(Int_t pe=0;pe<2;pe++) // pt or eta
4854   {
4855    fDiffFlowCorrelationsHistList[t][pe] = NULL;
4856    for(Int_t power=0;power<2;power++)
4857    {
4858     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = NULL;
4859    } // end of for(Int_t power=0;power<2;power++)  
4860    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = NULL;
4861    fDiffFlowCorrectionsHistList[t][pe] = NULL;
4862    fDiffFlowCovariancesHistList[t][pe] = NULL;
4863    fDiffFlowCumulantsHistList[t][pe] = NULL;
4864    fDiffFlowHistList[t][pe] = NULL;
4865   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
4866  } // enf of for(Int_t t=0;t<2;t++) // type (RP, POI) 
4867  
4868  // c) Initialize event-by-event quantities:
4869  // 1D:
4870  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
4871  {
4872   for(Int_t pe=0;pe<2;pe++) // pt or eta
4873   { 
4874    for(Int_t m=0;m<4;m++) // multiple of harmonic
4875    {
4876     for(Int_t k=0;k<9;k++) // power of weight
4877     {
4878      fReRPQ1dEBE[t][pe][m][k] = NULL;
4879      fImRPQ1dEBE[t][pe][m][k] = NULL;
4880      fs1dEBE[t][pe][k] = NULL; // to be improved (this doesn't need to be within loop over m)
4881     }   
4882    }
4883   }
4884  }
4885  // 1D:
4886  for(Int_t t=0;t<2;t++) // type (RP or POI)
4887  {
4888   for(Int_t pe=0;pe<2;pe++) // pt or eta
4889   { 
4890    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
4891    {
4892     for(Int_t cti=0;cti<9;cti++) // correction term index
4893     {
4894      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = NULL;
4895     }   
4896    }
4897   }
4898  }
4899  // 2D:  
4900  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
4901  {
4902   for(Int_t m=0;m<4;m++) // multiple of harmonic
4903   {
4904    for(Int_t k=0;k<9;k++) // power of weight
4905    {
4906     fReRPQ2dEBE[t][m][k] = NULL;
4907     fImRPQ2dEBE[t][m][k] = NULL;
4908     fs2dEBE[t][k] = NULL; // to be improved (this doesn't need to be within loop over m)
4909    }   
4910   }
4911  }
4912  
4913  // d) Initialize profiles:
4914  for(Int_t t=0;t<2;t++) // type: RP or POI
4915  { 
4916   for(Int_t pe=0;pe<2;pe++) // pt or eta
4917   {
4918    for(Int_t ci=0;ci<4;ci++) // correlation index
4919    {
4920     fDiffFlowCorrelationsPro[t][pe][ci] = NULL;
4921    } // end of for(Int_t ci=0;ci<4;ci++)   
4922    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
4923    {
4924     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
4925     {
4926      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2] = NULL;
4927     } // end of for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
4928    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index  
4929    // correction terms for nua:
4930    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
4931    {
4932     for(Int_t cti=0;cti<9;cti++) // correction term index
4933     {
4934      fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] = NULL;
4935     }   
4936    }
4937   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
4938  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
4939   
4940  // e) Initialize histograms holding final results.
4941  for(Int_t t=0;t<2;t++) // type: RP or POI
4942  { 
4943   for(Int_t pe=0;pe<2;pe++) // pt or eta
4944   {
4945    for(Int_t ci=0;ci<4;ci++) // correlation index
4946    {
4947     fDiffFlowCorrelationsHist[t][pe][ci] = NULL;
4948     fDiffFlowCumulants[t][pe][ci] = NULL;
4949     fDiffFlow[t][pe][ci] = NULL;
4950    } // end of for(Int_t ci=0;ci<4;ci++)    
4951    for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
4952    {
4953     fDiffFlowCovariances[t][pe][covarianceIndex] = NULL;     
4954    } // end of for(Int_t covarianceIndex=0;covarianceIndex<5;covarianceIndex++) 
4955    // correction terms for nua:
4956    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
4957    {
4958     for(Int_t cti=0;cti<9;cti++) // correction term index
4959     {
4960      fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] = NULL;
4961     }   
4962    }
4963   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
4964  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
4965  
4966  // sum of event weights for reduced correlations:
4967  for(Int_t t=0;t<2;t++) // type = RP or POI
4968  {
4969   for(Int_t pe=0;pe<2;pe++) // pt or eta
4970   {
4971    for(Int_t p=0;p<2;p++) // power of weight is 1 or 2
4972    {
4973     for(Int_t ew=0;ew<4;ew++) // event weight index for reduced correlations
4974     {
4975      fDiffFlowSumOfEventWeights[t][pe][p][ew] = NULL;
4976     } 
4977    }   
4978   }
4979  }
4980  // product of event weights for both types of correlations:
4981  for(Int_t t=0;t<2;t++) // type = RP or POI
4982  {
4983   for(Int_t pe=0;pe<2;pe++) // pt or eta
4984   {
4985    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
4986    {
4987     for(Int_t mci2=0;mci2<8;mci2++) // mixed correlation index
4988     {
4989      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] = NULL;
4990     } 
4991    }   
4992   }
4993  }
4994
4995  
4996  
4997  
4998  /*
4999  
5000  // nested lists in fDiffFlowProfiles:
5001  for(Int_t t=0;t<2;t++)
5002  {
5003   fDFPType[t] = NULL;
5004   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
5005   {
5006    fDFPParticleWeights[t][pW] = NULL;
5007    for(Int_t eW=0;eW<2;eW++)
5008    {   
5009     fDFPEventWeights[t][pW][eW] = NULL;
5010     fDiffFlowCorrelations[t][pW][eW] = NULL;
5011     fDiffFlowProductsOfCorrelations[t][pW][eW] = NULL;
5012     for(Int_t sc=0;sc<2;sc++)
5013     {
5014      fDiffFlowCorrectionTerms[t][pW][eW][sc] = NULL;
5015     }
5016    } 
5017   }
5018  }  
5019  
5020  
5021  */
5022  
5023   
5024   
5025   /*
5026   for(Int_t pW=0;pW<2;pW++) // particle weights not used (0) or used (1)
5027   {
5028    for(Int_t eW=0;eW<2;eW++)
5029    {
5030     // correlations:
5031     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
5032     {
5033      fCorrelationsPro[t][pW][eW][correlationIndex] = NULL;
5034     }
5035     // products of correlations:
5036     for(Int_t productOfCorrelationsIndex=0;productOfCorrelationsIndex<6;productOfCorrelationsIndex++)
5037     {
5038      fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] = NULL;
5039     }
5040     // correction terms:
5041     for(Int_t sc=0;sc<2;sc++)
5042     {
5043      for(Int_t correctionsIndex=0;correctionsIndex<2;correctionsIndex++)
5044      {
5045       fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex] = NULL;
5046      } 
5047     } 
5048    }
5049   } 
5050   */
5051     
5052 } // end of AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5053
5054
5055 //================================================================================================================================
5056  /*
5057
5058
5059 void AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D(TString type)
5060 {
5061  // calculate all reduced correlations needed for differential flow for each (pt,eta) bin: 
5062  
5063  if(type == "RP") // to be improved (removed)
5064  {
5065   cout<<endl;
5066  }
5067  // ... 
5068  
5069  
5070  Int_t typeFlag = -1; 
5071   
5072  // reduced correlations ares stored in fCorrelationsPro[t][pW][index] and are indexed as follows:
5073  // index:
5074  // 0: <2'>
5075  // 1: <4'>
5076
5077  // multiplicity:
5078  Double_t dMult = (*fSMpk)(0,0);
5079  
5080  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5081  Double_t dReQ1n = (*fReQ)(0,0);
5082  Double_t dReQ2n = (*fReQ)(1,0);
5083  //Double_t dReQ3n = (*fReQ)(2,0);
5084  //Double_t dReQ4n = (*fReQ)(3,0);
5085  Double_t dImQ1n = (*fImQ)(0,0);
5086  Double_t dImQ2n = (*fImQ)(1,0);
5087  //Double_t dImQ3n = (*fImQ)(2,0);
5088  //Double_t dImQ4n = (*fImQ)(3,0);
5089
5090  // looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
5091  for(Int_t p=1;p<=fnBinsPt;p++)
5092  {
5093   for(Int_t e=1;e<=fnBinsEta;e++)
5094   {
5095    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin): 
5096    Double_t p1n0kRe = 0.;
5097    Double_t p1n0kIm = 0.;
5098
5099    // number of POIs in particular (pt,eta) bin:
5100    Double_t mp = 0.;
5101
5102    // real and imaginary parts of q_{m*n,0} (non-weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin):
5103    Double_t q1n0kRe = 0.;
5104    Double_t q1n0kIm = 0.;
5105    Double_t q2n0kRe = 0.;
5106    Double_t q2n0kIm = 0.;
5107
5108    // number of particles which are both RPs and POIs in particular (pt,eta) bin:
5109    Double_t mq = 0.;
5110    
5111    // q_{m*n,0}:
5112    q1n0kRe = fReEBE2D[2][0][0]->GetBinContent(fReEBE2D[2][0][0]->GetBin(p,e))
5113            * fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e));
5114    q1n0kIm = fImEBE2D[2][0][0]->GetBinContent(fImEBE2D[2][0][0]->GetBin(p,e))
5115            * fImEBE2D[2][0][0]->GetBinEntries(fImEBE2D[2][0][0]->GetBin(p,e));
5116    q2n0kRe = fReEBE2D[2][1][0]->GetBinContent(fReEBE2D[2][1][0]->GetBin(p,e))
5117            * fReEBE2D[2][1][0]->GetBinEntries(fReEBE2D[2][1][0]->GetBin(p,e));
5118    q2n0kIm = fImEBE2D[2][1][0]->GetBinContent(fImEBE2D[2][1][0]->GetBin(p,e))
5119            * fImEBE2D[2][1][0]->GetBinEntries(fImEBE2D[2][1][0]->GetBin(p,e));
5120            
5121    mq = fReEBE2D[2][0][0]->GetBinEntries(fReEBE2D[2][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
5122    
5123    if(type == "POI")
5124    {
5125     // p_{m*n,0}:
5126     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
5127             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5128     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))  
5129             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e));
5130             
5131     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
5132     
5133     typeFlag = 1;
5134    }
5135    else if(type == "RP")
5136    {
5137     // p_{m*n,0} = q_{m*n,0}:
5138     p1n0kRe = q1n0kRe; 
5139     p1n0kIm = q1n0kIm; 
5140     mp = mq; 
5141     
5142     typeFlag = 0;
5143    }
5144    
5145    // count events with non-empty (pt,eta) bin:
5146    if(mp>0)
5147    {
5148     fNonEmptyBins2D[typeFlag]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,1);
5149    }
5150    
5151    // 2'-particle correlation for particular (pt,eta) bin:
5152    Double_t two1n1nPtEta = 0.;
5153    if(mp*dMult-mq)
5154    {
5155     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
5156                  / (mp*dMult-mq);
5157    
5158     // fill the 2D profile to get the average correlation for each (pt,eta) bin:
5159     if(type == "POI")
5160     { 
5161      //f2pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5162      
5163      fCorrelationsPro[1][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5164     }
5165     else if(type == "RP")
5166     {
5167      //f2pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);   
5168      fCorrelationsPro[0][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
5169     }
5170    } // end of if(mp*dMult-mq)
5171   
5172    // 4'-particle correlation:
5173    Double_t four1n1n1n1nPtEta = 0.;
5174    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5175        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
5176    {
5177     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5178                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
5179                       - 2.*q2n0kIm*dReQ1n*dImQ1n
5180                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
5181                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
5182                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
5183                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
5184                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
5185                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
5186                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
5187                       + 2.*mq*dMult                      
5188                       - 6.*mq)        
5189                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5190                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
5191     
5192     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5193     if(type == "POI")
5194     {
5195      //f4pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5196      //                  (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5197      //                   + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
5198      
5199      fCorrelationsPro[1][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5200                                      (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5201                                      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
5202     }
5203     else if(type == "RP")
5204     {
5205      //f4pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5206      //                 (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5207      //                  + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));   
5208                        
5209      fCorrelationsPro[0][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
5210                                        (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5211                                        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
5212     }
5213    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
5214      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
5215    
5216   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5217  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5218
5219  
5220    
5221     
5222       
5223 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow2D()
5224
5225
5226
5227  
5228  
5229
5230 //================================================================================================================================
5231
5232
5233 void AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
5234 {
5235  // calculate all weighted correlations needed for differential flow 
5236  
5237   if(type == "RP") // to be improved (removed)
5238  {
5239   cout<<endl;
5240  }
5241  // ... 
5242  
5243  
5244  
5245  
5246  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5247  Double_t dReQ1n1k = (*fReQ)(0,1);
5248  Double_t dReQ2n2k = (*fReQ)(1,2);
5249  Double_t dReQ1n3k = (*fReQ)(0,3);
5250  //Double_t dReQ4n4k = (*fReQ)(3,4);
5251  Double_t dImQ1n1k = (*fImQ)(0,1);
5252  Double_t dImQ2n2k = (*fImQ)(1,2);
5253  Double_t dImQ1n3k = (*fImQ)(0,3);
5254  //Double_t dImQ4n4k = (*fImQ)(3,4);
5255  
5256  // S^M_{p,k} (see .h file for the definition of fSMpk):
5257  Double_t dSM1p1k = (*fSMpk)(0,1);
5258  Double_t dSM1p2k = (*fSMpk)(0,2);
5259  Double_t dSM1p3k = (*fSMpk)(0,3);
5260  Double_t dSM2p1k = (*fSMpk)(1,1);
5261  Double_t dSM3p1k = (*fSMpk)(2,1);
5262  
5263  // looping over all (pt,eta) bins and calculating weighted correlations needed for differential flow: 
5264  for(Int_t p=1;p<=fnBinsPt;p++)
5265  {
5266   for(Int_t e=1;e<=fnBinsEta;e++)
5267   {
5268    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
5269    Double_t p1n0kRe = 0.;
5270    Double_t p1n0kIm = 0.;
5271
5272    // number of POIs in particular (pt,eta) bin):
5273    Double_t mp = 0.;
5274
5275    // real and imaginary parts of q_{m*n,k}: 
5276    // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
5277    Double_t q1n2kRe = 0.;
5278    Double_t q1n2kIm = 0.;
5279    Double_t q2n1kRe = 0.;
5280    Double_t q2n1kIm = 0.;
5281
5282    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5283    Double_t s1p1k = 0.; 
5284    Double_t s1p2k = 0.; 
5285    Double_t s1p3k = 0.; 
5286    
5287    // M0111 from Eq. (118) in QC2c (to be improved (notation))
5288    Double_t dM0111 = 0.;
5289  
5290    if(type == "POI")
5291    {
5292     // p_{m*n,0}:
5293     p1n0kRe = fReEBE2D[1][0][0]->GetBinContent(fReEBE2D[1][0][0]->GetBin(p,e))
5294             * fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5295     p1n0kIm = fImEBE2D[1][0][0]->GetBinContent(fImEBE2D[1][0][0]->GetBin(p,e))
5296             * fImEBE2D[1][0][0]->GetBinEntries(fImEBE2D[1][0][0]->GetBin(p,e)); 
5297             
5298     mp = fReEBE2D[1][0][0]->GetBinEntries(fReEBE2D[1][0][0]->GetBin(p,e));
5299     
5300     // q_{m*n,k}: 
5301     q1n2kRe = fReEBE2D[2][0][2]->GetBinContent(fReEBE2D[2][0][2]->GetBin(p,e))
5302             * fReEBE2D[2][0][2]->GetBinEntries(fReEBE2D[2][0][2]->GetBin(p,e));
5303     q1n2kIm = fImEBE2D[2][0][2]->GetBinContent(fImEBE2D[2][0][2]->GetBin(p,e))
5304             * fImEBE2D[2][0][2]->GetBinEntries(fImEBE2D[2][0][2]->GetBin(p,e));
5305     q2n1kRe = fReEBE2D[2][1][1]->GetBinContent(fReEBE2D[2][1][1]->GetBin(p,e))
5306             * fReEBE2D[2][1][1]->GetBinEntries(fReEBE2D[2][1][1]->GetBin(p,e)); 
5307     q2n1kIm = fImEBE2D[2][1][1]->GetBinContent(fImEBE2D[2][1][1]->GetBin(p,e))
5308             * fImEBE2D[2][1][1]->GetBinEntries(fImEBE2D[2][1][1]->GetBin(p,e));
5309        
5310     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5311     s1p1k = pow(fs2D[2][1]->GetBinContent(fs2D[2][1]->GetBin(p,e)),1.); 
5312     s1p2k = pow(fs2D[2][2]->GetBinContent(fs2D[2][2]->GetBin(p,e)),1.); 
5313     s1p3k = pow(fs2D[2][3]->GetBinContent(fs2D[2][3]->GetBin(p,e)),1.); 
5314    
5315     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
5316     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
5317            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
5318            + 2.*(s1p3k-s1p2k*dSM1p1k));
5319    }
5320    else if(type == "RP")
5321    {
5322     p1n0kRe = fReEBE2D[0][0][0]->GetBinContent(fReEBE2D[0][0][0]->GetBin(p,e))
5323             * fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
5324     p1n0kIm = fImEBE2D[0][0][0]->GetBinContent(fImEBE2D[0][0][0]->GetBin(p,e))
5325             * fImEBE2D[0][0][0]->GetBinEntries(fImEBE2D[0][0][0]->GetBin(p,e));
5326             
5327     mp = fReEBE2D[0][0][0]->GetBinEntries(fReEBE2D[0][0][0]->GetBin(p,e));
5328     
5329     // q_{m*n,k}: 
5330     q1n2kRe = fReEBE2D[0][0][2]->GetBinContent(fReEBE2D[0][0][2]->GetBin(p,e))
5331             * fReEBE2D[0][0][2]->GetBinEntries(fReEBE2D[0][0][2]->GetBin(p,e));
5332     q1n2kIm = fImEBE2D[0][0][2]->GetBinContent(fImEBE2D[0][0][2]->GetBin(p,e))
5333             * fImEBE2D[0][0][2]->GetBinEntries(fImEBE2D[0][0][2]->GetBin(p,e));
5334     q2n1kRe = fReEBE2D[0][1][1]->GetBinContent(fReEBE2D[0][1][1]->GetBin(p,e))
5335             * fReEBE2D[0][1][1]->GetBinEntries(fReEBE2D[0][1][1]->GetBin(p,e));
5336     q2n1kIm = fImEBE2D[0][1][1]->GetBinContent(fImEBE2D[0][1][1]->GetBin(p,e))
5337             * fImEBE2D[0][1][1]->GetBinEntries(fImEBE2D[0][1][1]->GetBin(p,e));
5338    
5339     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
5340     s1p1k = pow(fs2D[0][1]->GetBinContent(fs2D[0][1]->GetBin(p,e)),1.); 
5341     s1p2k = pow(fs2D[0][2]->GetBinContent(fs2D[0][2]->GetBin(p,e)),1.); 
5342     s1p3k = pow(fs2D[0][3]->GetBinContent(fs2D[0][3]->GetBin(p,e)),1.); 
5343    
5344     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
5345     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
5346            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
5347            + 2.*(s1p3k-s1p2k*dSM1p1k));
5348     //...............................................................................................   
5349    }
5350    
5351    // 2'-particle correlation:
5352    Double_t two1n1nW0W1PtEta = 0.;
5353    if(mp*dSM1p1k-s1p1k)
5354    {
5355     two1n1nW0W1PtEta = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
5356                  / (mp*dSM1p1k-s1p1k);
5357    
5358     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5359     if(type == "POI")
5360     {
5361      //f2pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
5362      //                   mp*dSM1p1k-s1p1k);
5363      fCorrelationsPro[1][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);
5364     }
5365     else if(type == "RP")
5366     {
5367      //f2pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
5368      //                  mp*dSM1p1k-s1p1k); 
5369      fCorrelationsPro[0][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);  
5370     }
5371    } // end of if(mp*dMult-dmPrimePrimePtEta)
5372    
5373    // 4'-particle correlation:
5374    Double_t four1n1n1n1nW0W1W1W1PtEta = 0.;
5375    if(dM0111)
5376    {
5377     four1n1n1n1nW0W1W1W1PtEta = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
5378                       - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
5379                       - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
5380                       - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
5381                       + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
5382                       - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
5383                       - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
5384                       + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
5385                       + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
5386                       + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
5387                       + 2.*s1p1k*dSM1p2k                                      
5388                       - 6.*s1p3k)        
5389                       / dM0111; // to be imropoved (notation of dM0111)
5390    
5391     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
5392     if(type == "POI")
5393     {
5394      //f4pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
5395      fCorrelationsPro[1][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
5396     }
5397     else if(type == "RP")
5398     {
5399      //f4pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
5400      fCorrelationsPro[0][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
5401     }
5402    } // end of if(dM0111)
5403   
5404   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5405  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5406  
5407   
5408     
5409       
5410 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow2D(TString type)
5411
5412
5413 //================================================================================================================================
5414
5415  */  
5416
5417 /*
5418 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
5419 {
5420  // 1.) Access average for 2D correlations from profiles and store them in 2D final results histograms;
5421  // 2.) Access spread for 2D correlations from profiles, calculate error and store it in 2D final results histograms;
5422  // 3.) Make projections along pt and eta axis and store results and errors in 1D final results histograms. 
5423  
5424  Int_t typeFlag = -1;
5425  Int_t pWeightsFlag = -1;
5426  Int_t eWeightsFlag = -1;
5427
5428  if(type == "RP")
5429  {
5430   typeFlag = 0;
5431  } else if(type == "POI")
5432    {
5433     typeFlag = 1;
5434    } else 
5435      {
5436       cout<<"WARNING: type must be either RP or POI in AFAWQC::FCFDF() !!!!"<<endl;
5437       exit(0);
5438      }
5439      
5440  if(!useParticleWeights)
5441  {
5442   pWeightsFlag = 0;
5443  } else 
5444    {
5445     pWeightsFlag = 1;   
5446    }   
5447    
5448  if(eventWeights == "exact")
5449  {
5450   eWeightsFlag = 0;
5451  }          
5452   
5453  // shortcuts:
5454  Int_t t = typeFlag;
5455  Int_t pW = pWeightsFlag;
5456  Int_t eW = eWeightsFlag;
5457  
5458  // from 2D histogram fNonEmptyBins2D make two 1D histograms fNonEmptyBins1D in pt and eta (to be improved (i.e. moved somewhere else))  
5459  // pt:
5460  for(Int_t p=1;p<fnBinsPt;p++)
5461  {
5462   Double_t contentPt = 0.;
5463   for(Int_t e=1;e<=fnBinsEta;e++)
5464   {
5465    contentPt += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
5466   }
5467   fNonEmptyBins1D[t][0]->SetBinContent(p,contentPt);
5468  }
5469  // eta:
5470  for(Int_t e=1;e<fnBinsEta;e++)
5471  {
5472   Double_t contentEta = 0.;
5473   for(Int_t p=1;p<=fnBinsPt;p++)
5474   {
5475    contentEta += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
5476   }
5477   fNonEmptyBins1D[t][1]->SetBinContent(e,contentEta);
5478  }
5479  
5480  // from 2D profile in (pt,eta) make two 1D profiles in (pt) and (eta):
5481  TProfile *profile[2][4]; // [0=pt,1=eta][correlation index] // to be improved (do not hardwire the correlation index)
5482  
5483  for(Int_t pe=0;pe<2;pe++) // pt or eta
5484  {
5485   for(Int_t ci=0;ci<4;ci++) // correlation index
5486   {
5487    if(pe==0) profile[pe][ci] = this->MakePtProjection(fCorrelationsPro[t][pW][eW][ci]);
5488    if(pe==1) profile[pe][ci] = this->MakeEtaProjection(fCorrelationsPro[t][pW][eW][ci]);
5489   }
5490  }
5491   
5492  // transfer 2D profile into 2D histogram:
5493  // to be improved (see in documentation if there is a method to transfer values from 2D profile into 2D histogram)    
5494  for(Int_t ci=0;ci<4;ci++)
5495  {
5496   for(Int_t p=1;p<=fnBinsPt;p++)
5497   {
5498    for(Int_t e=1;e<=fnBinsEta;e++)
5499    {
5500     Double_t correlation = fCorrelationsPro[t][pW][eW][ci]->GetBinContent(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e)); 
5501     Double_t spread = fCorrelationsPro[t][pW][eW][ci]->GetBinError(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e));
5502     Double_t nEvts = fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e));
5503     Double_t error = 0.;
5504     fFinalCorrelations2D[t][pW][eW][ci]->SetBinContent(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),correlation);          
5505     if(nEvts>0)
5506     {
5507      error = spread/pow(nEvts,0.5);
5508      fFinalCorrelations2D[t][pW][eW][ci]->SetBinError(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),error);
5509     }
5510    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5511   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5512  } // end of for(Int_t ci=0;ci<4;ci++)
5513  
5514  // transfer 1D profile into 1D histogram (pt):
5515  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
5516  for(Int_t ci=0;ci<4;ci++)
5517  {
5518   for(Int_t p=1;p<=fnBinsPt;p++)
5519   {
5520    if(profile[0][ci])
5521    {
5522     Double_t correlation = profile[0][ci]->GetBinContent(p); 
5523     Double_t spread = profile[0][ci]->GetBinError(p);
5524     Double_t nEvts = fNonEmptyBins1D[t][0]->GetBinContent(p);
5525     Double_t error = 0.;
5526     fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinContent(p,correlation); 
5527     if(nEvts>0)
5528     {
5529      error = spread/pow(nEvts,0.5);
5530      fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinError(p,error);
5531     }  
5532    }   
5533   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5534  } // end of for(Int_t ci=0;ci<4;ci++)
5535  
5536  // transfer 1D profile into 1D histogram (eta):
5537  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
5538  for(Int_t ci=0;ci<4;ci++)
5539  {
5540   for(Int_t e=1;e<=fnBinsEta;e++)
5541   {
5542    if(profile[1][ci])
5543    {
5544     Double_t correlation = profile[1][ci]->GetBinContent(e); 
5545     fFinalCorrelations1D[t][pW][eW][1][ci]->SetBinContent(e,correlation);      
5546    }    
5547   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5548  } // end of for(Int_t ci=0;ci<4;ci++)
5549         
5550 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
5551 */
5552
5553
5554 //================================================================================================================================
5555
5556
5557 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, TString ptOrEta)
5558 {
5559  // calcualate cumulants for differential flow from measured correlations
5560  // Remark: cumulants calculated here are NOT corrected for non-uniform acceptance. This correction is applied in the method ...
5561  // to be improved (description) 
5562  
5563  Int_t typeFlag = -1;
5564  Int_t ptEtaFlag = -1;
5565
5566  if(type == "RP")
5567  {
5568   typeFlag = 0;
5569  } else if(type == "POI")
5570    {
5571     typeFlag = 1;
5572    } 
5573      
5574  if(ptOrEta == "Pt")
5575  {
5576   ptEtaFlag = 0;
5577  } else if(ptOrEta == "Eta")
5578    {
5579     ptEtaFlag = 1;
5580    } 
5581   
5582  // shortcuts:
5583  Int_t t = typeFlag;
5584  Int_t pe = ptEtaFlag;
5585      
5586  // common:
5587  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
5588  
5589  // correlation <<2>>: 
5590  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1);
5591  
5592  // 1D:
5593  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
5594  {
5595   // reduced correlations:   
5596   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>(pt)
5597   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>(pt)
5598   // final statistical error of reduced correlations:
5599   //Double_t twoPrimeError = fFinalCorrelations1D[t][pW][eW][0][0]->GetBinError(p); 
5600   // QC{2'}:
5601   Double_t qc2Prime = twoPrime; // QC{2'}
5602   //Double_t qc2PrimeError = twoPrimeError; // final stat. error of QC{2'}
5603   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime); 
5604   //fFinalCumulantsPt[t][pW][eW][nua][0]->SetBinError(p,qc2PrimeError);   
5605   // QC{4'}:
5606   Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5607   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime); 
5608  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5609  
5610     
5611  /* 
5612  // 2D (pt,eta):
5613  // to be improved (see documentation if I can do all this without looping)
5614  for(Int_t p=1;p<=fnBinsPt;p++)
5615  {
5616   for(Int_t e=1;e<=fnBinsEta;e++) 
5617   {  
5618    // reduced correlations:   
5619    Double_t twoPrime = fFinalCorrelations2D[t][pW][eW][0]->GetBinContent(fFinalCorrelations2D[t][pW][eW][0]->GetBin(p,e)); // <<2'>>(pt,eta)
5620    Double_t fourPrime = fFinalCorrelations2D[t][pW][eW][1]->GetBinContent(fFinalCorrelations2D[t][pW][eW][1]->GetBin(p,e)); // <<4'>>(pt,eta)
5621    for(Int_t nua=0;nua<2;nua++)
5622    {
5623     // QC{2'}:
5624     Double_t qc2Prime = twoPrime; // QC{2'} = <<2'>>
5625     fFinalCumulants2D[t][pW][eW][nua][0]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e),qc2Prime);    
5626     // QC{4'}:
5627     Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
5628     fFinalCumulants2D[t][pW][eW][nua][1]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e),qc4Prime);   
5629    } // end of for(Int_t nua=0;nua<2;nua++)   
5630   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
5631  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
5632  */
5633    
5634 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulants(TString type, Bool_t useParticleWeights, TString eventWeights); 
5635
5636
5637 //================================================================================================================================
5638
5639
5640 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
5641 {
5642  // calculate final results for integrated flow of RPs and POIs 
5643   
5644  Int_t typeFlag = -1;
5645
5646  if(type == "RP")
5647  {
5648   typeFlag = 0;
5649  } else if(type == "POI")
5650    {
5651     typeFlag = 1;
5652    } else 
5653      {
5654       cout<<"WARNING: type must be either RP or POI in AFAWQC::CDF() !!!!"<<endl;
5655       exit(0);
5656      }
5657      
5658  // shortcuts:
5659  Int_t t = typeFlag;
5660   
5661  // pt yield:    
5662  TH1F *yield2ndPt = NULL;
5663  TH1F *yield4thPt = NULL;
5664  TH1F *yield6thPt = NULL;
5665  TH1F *yield8thPt = NULL;
5666  
5667  if(type == "POI")
5668  {
5669   yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtPOI())->Clone();
5670   yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtPOI())->Clone();
5671   yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtPOI())->Clone();
5672   yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtPOI())->Clone();  
5673  } 
5674  else if(type == "RP")
5675  {
5676   yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtRP())->Clone();
5677   yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtRP())->Clone();
5678   yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtRP())->Clone();
5679   yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtRP())->Clone();  
5680  } 
5681  
5682  Int_t nBinsPt = yield2ndPt->GetNbinsX();
5683  
5684  TH1D *flow2ndPt = NULL;
5685  TH1D *flow4thPt = NULL;
5686  TH1D *flow6thPt = NULL;
5687  TH1D *flow8thPt = NULL;
5688  
5689  // to be improved (hardwired pt index)
5690  flow2ndPt = (TH1D*)fDiffFlow[t][0][0]->Clone();
5691  flow4thPt = (TH1D*)fDiffFlow[t][0][1]->Clone();
5692  flow6thPt = (TH1D*)fDiffFlow[t][0][2]->Clone();
5693  flow8thPt = (TH1D*)fDiffFlow[t][0][3]->Clone(); 
5694    
5695  Double_t dvn2nd = 0., dvn4th = 0., dvn6th = 0., dvn8th = 0.; // differential flow
5696  Double_t dErrvn2nd = 0., dErrvn4th = 0., dErrvn6th = 0., dErrvn8th = 0.; // error on differential flow
5697  
5698  Double_t dVn2nd = 0., dVn4th = 0., dVn6th = 0., dVn8th = 0.; // integrated flow 
5699  Double_t dErrVn2nd = 0., dErrVn4th = 0., dErrVn6th = 0., dErrVn8th = 0.; // error on integrated flow
5700
5701  Double_t dYield2nd = 0., dYield4th = 0., dYield6th = 0., dYield8th = 0.; // pt yield 
5702  Double_t dSum2nd = 0., dSum4th = 0., dSum6th = 0., dSum8th = 0.; // needed for normalizing integrated flow
5703  
5704  // looping over pt bins:
5705  for(Int_t p=1;p<nBinsPt+1;p++)
5706  {
5707   dvn2nd = flow2ndPt->GetBinContent(p);
5708   dvn4th = flow4thPt->GetBinContent(p);
5709   dvn6th = flow6thPt->GetBinContent(p);
5710   dvn8th = flow8thPt->GetBinContent(p);
5711   
5712   dErrvn2nd = flow2ndPt->GetBinError(p);
5713   dErrvn4th = flow4thPt->GetBinError(p);
5714   dErrvn6th = flow6thPt->GetBinError(p);
5715   dErrvn8th = flow8thPt->GetBinError(p);
5716
5717   dYield2nd = yield2ndPt->GetBinContent(p);  
5718   dYield4th = yield4thPt->GetBinContent(p);
5719   dYield6th = yield6thPt->GetBinContent(p);
5720   dYield8th = yield8thPt->GetBinContent(p);
5721   
5722   dVn2nd += dvn2nd*dYield2nd;
5723   dVn4th += dvn4th*dYield4th;
5724   dVn6th += dvn6th*dYield6th;
5725   dVn8th += dvn8th*dYield8th;
5726   
5727   dSum2nd += dYield2nd;
5728   dSum4th += dYield4th;
5729   dSum6th += dYield6th;
5730   dSum8th += dYield8th;
5731   
5732   dErrVn2nd += dYield2nd*dYield2nd*dErrvn2nd*dErrvn2nd; // ro be improved (check this relation)
5733   dErrVn4th += dYield4th*dYield4th*dErrvn4th*dErrvn4th;
5734   dErrVn6th += dYield6th*dYield6th*dErrvn6th*dErrvn6th;
5735   dErrVn8th += dYield8th*dYield8th*dErrvn8th*dErrvn8th;
5736     
5737  } // end of for(Int_t p=1;p<nBinsPt+1;p++)
5738
5739  // normalizing the results for integrated flow:
5740  if(dSum2nd) 
5741  {
5742   dVn2nd /= dSum2nd;
5743   dErrVn2nd /= (dSum2nd*dSum2nd);
5744   dErrVn2nd = TMath::Sqrt(dErrVn2nd);
5745  } 
5746  if(dSum4th) 
5747  {
5748   dVn4th /= dSum4th;
5749   dErrVn4th /= (dSum4th*dSum4th);
5750   dErrVn4th = TMath::Sqrt(dErrVn4th);
5751  } 
5752  //if(dSum6th) dVn6th/=dSum6th;
5753  //if(dSum8th) dVn8th/=dSum8th;
5754   
5755  // storing the results for integrated flow in common histos: (to be improved: new method for this?)
5756  if(type == "POI")
5757  {
5758   fCommonHistsResults2nd->FillIntegratedFlowPOI(dVn2nd,dErrVn2nd); 
5759   fCommonHistsResults4th->FillIntegratedFlowPOI(dVn4th,dErrVn4th); 
5760   fCommonHistsResults6th->FillIntegratedFlowPOI(dVn6th,0.); // to be improved (errors)
5761   fCommonHistsResults8th->FillIntegratedFlowPOI(dVn8th,0.); // to be improved (errors)
5762  }
5763  else if (type == "RP")
5764  {
5765   fCommonHistsResults2nd->FillIntegratedFlowRP(dVn2nd,dErrVn2nd); 
5766   fCommonHistsResults4th->FillIntegratedFlowRP(dVn4th,dErrVn4th);
5767   fCommonHistsResults6th->FillIntegratedFlowRP(dVn6th,0.); // to be improved (errors)
5768   fCommonHistsResults8th->FillIntegratedFlowRP(dVn8th,0.); // to be improved (errors)
5769  }
5770  
5771  delete flow2ndPt;
5772  delete flow4thPt;
5773  //delete flow6thPt;
5774  //delete flow8thPt;
5775  
5776  delete yield2ndPt;
5777  delete yield4thPt;
5778  delete yield6thPt;
5779  delete yield8thPt;
5780            
5781 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type)
5782
5783
5784 //================================================================================================================================
5785
5786
5787 void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
5788 {
5789  // Initialize all arrays used for distributions.
5790  
5791  // a) Initialize arrays of histograms used to hold distributions of correlations; 
5792  // b) Initialize array to hold min and max values of correlations.
5793  
5794  // a) Initialize arrays of histograms used to hold distributions of correlations:
5795  for(Int_t di=0;di<4;di++) // distribution index
5796  {
5797   fDistributions[di] = NULL;
5798  }
5799  
5800  // b) Initialize default min and max values of correlations:
5801  //    (Remark: The default values bellow were chosen for v2=5% and M=500)
5802  fMinValueOfCorrelation[0] = -0.01; // <2>_min 
5803  fMaxValueOfCorrelation[0] = 0.04; // <2>_max 
5804  fMinValueOfCorrelation[1] = -0.00002; // <4>_min 
5805  fMaxValueOfCorrelation[1] = 0.00015; // <4>_max  
5806  fMinValueOfCorrelation[2] = -0.0000003; // <6>_min 
5807  fMaxValueOfCorrelation[2] = 0.0000006; // <6>_max  
5808  fMinValueOfCorrelation[3] = -0.000000006; // <8>_min 
5809  fMaxValueOfCorrelation[3] = 0.000000003; // <8>_max 
5810  
5811 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
5812
5813
5814 //================================================================================================================================
5815
5816
5817 void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
5818 {
5819  // a) Book profile to hold all flags for distributions of correlations;
5820  // b) Book all histograms to hold distributions of correlations.
5821  
5822  TString correlationIndex[4] = {"<2>","<4>","<6>","<8>"}; // to be improved (should I promote this to data members?)
5823   
5824  // a) Book profile to hold all flags for distributions of correlations:
5825  TString distributionsFlagsName = "fDistributionsFlags";
5826  distributionsFlagsName += fAnalysisLabel->Data();
5827  fDistributionsFlags = new TProfile(distributionsFlagsName.Data(),"Flags for Distributions of Correlations",9,0,9);
5828  fDistributionsFlags->SetTickLength(-0.01,"Y");
5829  fDistributionsFlags->SetMarkerStyle(25);
5830  fDistributionsFlags->SetLabelSize(0.05);
5831  fDistributionsFlags->SetLabelOffset(0.02,"Y");
5832  fDistributionsFlags->GetXaxis()->SetBinLabel(1,"Store or not?");
5833  fDistributionsFlags->GetXaxis()->SetBinLabel(2,"<2>_{min}");
5834  fDistributionsFlags->GetXaxis()->SetBinLabel(3,"<2>_{max}");
5835  fDistributionsFlags->GetXaxis()->SetBinLabel(4,"<4>_{min}");
5836  fDistributionsFlags->GetXaxis()->SetBinLabel(5,"<4>_{max}");
5837  fDistributionsFlags->GetXaxis()->SetBinLabel(6,"<6>_{min}");
5838  fDistributionsFlags->GetXaxis()->SetBinLabel(7,"<6>_{max}");
5839  fDistributionsFlags->GetXaxis()->SetBinLabel(8,"<8>_{min}");
5840  fDistributionsFlags->GetXaxis()->SetBinLabel(9,"<8>_{max}");
5841  fDistributionsList->Add(fDistributionsFlags);
5842  
5843  // b) Book all histograms to hold distributions of correlations.
5844  if(fStoreDistributions)
5845  { 
5846   TString distributionsName = "fDistributions";
5847   distributionsName += fAnalysisLabel->Data();
5848   for(Int_t di=0;di<4;di++) // distribution index
5849   {
5850    fDistributions[di] = new TH1D(Form("Distribution of %s",correlationIndex[di].Data()),Form("Distribution of %s",correlationIndex[di].Data()),10000,fMinValueOfCorrelation[di],fMaxValueOfCorrelation[di]); 
5851    fDistributions[di]->SetXTitle(correlationIndex[di].Data());
5852    fDistributionsList->Add(fDistributions[di]);
5853   } // end of for(Int_t di=0;di<4;di++) // distribution index
5854  } // end of if(fStoreDistributions)
5855  
5856 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
5857
5858
5859 //================================================================================================================================
5860
5861
5862 void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
5863 {
5864  // Store all flags for distributiuons of correlations in profile fDistributionsFlags.
5865  
5866  if(!fDistributionsFlags)
5867  {
5868   cout<<"WARNING: fDistributionsFlags is NULL in AFAWQC::SDF() !!!!"<<endl;
5869   exit(0);
5870  } 
5871
5872  fDistributionsFlags->Fill(0.5,(Int_t)fStoreDistributions); // histos with distributions of correlations stored or not in the output file
5873  // store min and max values of correlations:
5874  for(Int_t di=0;di<4;di++) // distribution index
5875  {
5876   fDistributionsFlags->Fill(1.5+2.*(Double_t)di,fMinValueOfCorrelation[di]);
5877   fDistributionsFlags->Fill(2.5+2.*(Double_t)di,fMaxValueOfCorrelation[di]);
5878  }
5879      
5880 } // end of void AliFlowAnalysisWithQCumulants::StoreFlagsForDistributions()
5881
5882
5883 //================================================================================================================================
5884
5885
5886 void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
5887 {
5888  // Store distributions of correlations.
5889  
5890  if(!(fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE))
5891  {
5892   cout<<"WARNING: fIntFlowCorrelationsEBE && fIntFlowEventWeightsForCorrelationsEBE"<<endl; 
5893   cout<<"         is NULL in AFAWQC::SDOC() !!!!"<<endl;
5894   exit(0);
5895  }
5896
5897  for(Int_t di=0;di<4;di++) // distribution index
5898  {
5899   if(!fDistributions[di])
5900   { 
5901    cout<<"WARNING: fDistributions[di] is NULL in AFAWQC::SDOC() !!!!"<<endl;
5902    cout<<"di = "<<di<<endl;
5903    exit(0);
5904   } else 
5905     {
5906      fDistributions[di]->Fill(fIntFlowCorrelationsEBE->GetBinContent(di+1),fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(di+1)); 
5907     } 
5908  } // end of for(Int_t di=0;di<4;di++) // distribution index
5909
5910 } // end of void AliFlowAnalysisWithQCumulants::StoreDistributionsOfCorrelations()
5911
5912
5913 //================================================================================================================================
5914
5915
5916 void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
5917 {
5918  // Book and nest all lists nested in the base list fHistList.
5919  //  a) Book and nest lists for integrated flow;
5920  //  b) Book and nest lists for differential flow;
5921  //  c) Book and nest list for particle weights;
5922  //  d) Book and nest list for distributions;
5923  //  e) Book and nest list for nested loops;
5924  
5925  // a) Book and nest all lists for integrated flow:
5926  // base list for integrated flow:
5927  fIntFlowList = new TList();
5928  fIntFlowList->SetName("Integrated Flow");
5929  fIntFlowList->SetOwner(kTRUE);
5930  fHistList->Add(fIntFlowList);
5931  // list holding profiles: 
5932  fIntFlowProfiles = new TList();
5933  fIntFlowProfiles->SetName("Profiles");
5934  fIntFlowProfiles->SetOwner(kTRUE);
5935  fIntFlowList->Add(fIntFlowProfiles);
5936  // list holding histograms with results:
5937  fIntFlowResults = new TList();
5938  fIntFlowResults->SetName("Results");
5939  fIntFlowResults->SetOwner(kTRUE);
5940  fIntFlowList->Add(fIntFlowResults);
5941  
5942  // b) Book and nest lists for differential flow;
5943  fDiffFlowList = new TList();
5944  fDiffFlowList->SetName("Differential Flow");
5945  fDiffFlowList->SetOwner(kTRUE); 
5946  fHistList->Add(fDiffFlowList);
5947  // list holding profiles: 
5948  fDiffFlowProfiles = new TList(); 
5949  fDiffFlowProfiles->SetName("Profiles");
5950  fDiffFlowProfiles->SetOwner(kTRUE);
5951  fDiffFlowList->Add(fDiffFlowProfiles);
5952  // list holding histograms with results: 
5953  fDiffFlowResults = new TList();
5954  fDiffFlowResults->SetName("Results");
5955  fDiffFlowResults->SetOwner(kTRUE);
5956  fDiffFlowList->Add(fDiffFlowResults);
5957  // flags used for naming nested lists in list fDiffFlowProfiles and fDiffFlowResults:  
5958  TList list;
5959  list.SetOwner(kTRUE);
5960  TString typeFlag[2] = {"RP","POI"};  
5961  TString ptEtaFlag[2] = {"p_{T}","#eta"}; 
5962  TString powerFlag[2] = {"linear","quadratic"};   
5963  // nested lists in fDiffFlowProfiles (~/Differential Flow/Profiles):
5964  for(Int_t t=0;t<2;t++) // type: RP or POI
5965  {
5966   for(Int_t pe=0;pe<2;pe++) // pt or eta
5967   {
5968    // list holding profiles with correlations:
5969    fDiffFlowCorrelationsProList[t][pe] = (TList*)list.Clone();
5970    fDiffFlowCorrelationsProList[t][pe]->SetName(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
5971    fDiffFlowProfiles->Add(fDiffFlowCorrelationsProList[t][pe]);
5972    // list holding profiles with products of correlations:
5973    fDiffFlowProductOfCorrelationsProList[t][pe] = (TList*)list.Clone();
5974    fDiffFlowProductOfCorrelationsProList[t][pe]->SetName(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
5975    fDiffFlowProfiles->Add(fDiffFlowProductOfCorrelationsProList[t][pe]);
5976    // list holding profiles with corrections:
5977    fDiffFlowCorrectionsProList[t][pe] = (TList*)list.Clone();
5978    fDiffFlowCorrectionsProList[t][pe]->SetName(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
5979    fDiffFlowProfiles->Add(fDiffFlowCorrectionsProList[t][pe]);   
5980   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
5981  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI   
5982  // nested lists in fDiffFlowResults (~/Differential Flow/Results):
5983  for(Int_t t=0;t<2;t++) // type: RP or POI
5984  {
5985   for(Int_t pe=0;pe<2;pe++) // pt or eta
5986   {
5987    // list holding histograms with correlations:
5988    fDiffFlowCorrelationsHistList[t][pe] = (TList*)list.Clone();
5989    fDiffFlowCorrelationsHistList[t][pe]->SetName(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
5990    fDiffFlowResults->Add(fDiffFlowCorrelationsHistList[t][pe]);
5991    // list holding histograms with corrections:
5992    fDiffFlowCorrectionsHistList[t][pe] = (TList*)list.Clone();
5993    fDiffFlowCorrectionsHistList[t][pe]->SetName(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
5994    fDiffFlowResults->Add(fDiffFlowCorrectionsHistList[t][pe]);   
5995    for(Int_t power=0;power<2;power++)
5996    {
5997     // list holding histograms with sums of event weights:
5998     fDiffFlowSumOfEventWeightsHistList[t][pe][power] = (TList*)list.Clone();
5999     fDiffFlowSumOfEventWeightsHistList[t][pe][power]->SetName(Form("Sum of %s event weights (%s, %s)",powerFlag[power].Data(),typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6000     fDiffFlowResults->Add(fDiffFlowSumOfEventWeightsHistList[t][pe][power]);    
6001    } // end of for(Int_t power=0;power<2;power++)
6002    // list holding histograms with sums of products of event weights:
6003    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe] = (TList*)list.Clone();
6004    fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->SetName(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6005    fDiffFlowResults->Add(fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]);
6006    // list holding histograms with covariances of correlations:
6007    fDiffFlowCovariancesHistList[t][pe] = (TList*)list.Clone();
6008    fDiffFlowCovariancesHistList[t][pe]->SetName(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6009    fDiffFlowResults->Add(fDiffFlowCovariancesHistList[t][pe]);
6010    // list holding histograms with differential Q-cumulants:
6011    fDiffFlowCumulantsHistList[t][pe] = (TList*)list.Clone();
6012    fDiffFlowCumulantsHistList[t][pe]->SetName(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6013    fDiffFlowResults->Add(fDiffFlowCumulantsHistList[t][pe]);   
6014    // list holding histograms with differential flow estimates from Q-cumulants:
6015    fDiffFlowHistList[t][pe] = (TList*)list.Clone();
6016    fDiffFlowHistList[t][pe]->SetName(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()));
6017    fDiffFlowResults->Add(fDiffFlowHistList[t][pe]);      
6018   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
6019  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
6020   
6021  // c) Book and nest list for particle weights:
6022  fWeightsList->SetName("Weights");
6023  fWeightsList->SetOwner(kTRUE);   
6024  fHistList->Add(fWeightsList); 
6025
6026  // d) Book and nest list for distributions:
6027  fDistributionsList = new TList();
6028  fDistributionsList->SetName("Distributions");
6029  fDistributionsList->SetOwner(kTRUE);
6030  fHistList->Add(fDistributionsList);
6031  
6032  // e) Book and nest list for nested loops:
6033  fNestedLoopsList = new TList();
6034  fNestedLoopsList->SetName("Nested Loops");
6035  fNestedLoopsList->SetOwner(kTRUE);
6036  fHistList->Add(fNestedLoopsList);
6037  
6038 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
6039
6040
6041 //================================================================================================================================
6042
6043
6044 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type)
6045 {
6046  // fill common result histograms for differential flow
6047  
6048  Int_t typeFlag = -1;
6049  //Int_t ptEtaFlag = -1;
6050
6051  if(type == "RP")
6052  {
6053   typeFlag = 0;
6054  } else if(type == "POI")
6055    {
6056     typeFlag = 1;
6057    } 
6058   
6059  // shortcuts:
6060  Int_t t = typeFlag;
6061  //Int_t pe = ptEtaFlag;
6062
6063  // to be improved (implement protection here)
6064      
6065  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
6066  {
6067   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
6068   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
6069   exit(0);
6070  }
6071  
6072  // pt:
6073  for(Int_t p=1;p<=fnBinsPt;p++)
6074  {
6075   Double_t v2 = fDiffFlow[t][0][0]->GetBinContent(p);
6076   Double_t v4 = fDiffFlow[t][0][1]->GetBinContent(p);
6077   Double_t v6 = fDiffFlow[t][0][2]->GetBinContent(p);
6078   Double_t v8 = fDiffFlow[t][0][3]->GetBinContent(p);
6079   
6080   Double_t v2Error = fDiffFlow[t][0][0]->GetBinError(p);
6081   Double_t v4Error = fDiffFlow[t][0][1]->GetBinError(p);
6082   //Double_t v6Error = fFinalFlow1D[t][pW][nua][0][2]->GetBinError(p);
6083   //Double_t v8Error = fFinalFlow1D[t][pW][nua][0][3]->GetBinError(p);
6084  
6085   if(type == "RP")
6086   {
6087    fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,v2,v2Error);
6088    fCommonHistsResults4th->FillDifferentialFlowPtRP(p,v4,v4Error);
6089    fCommonHistsResults6th->FillDifferentialFlowPtRP(p,v6,0.);
6090    fCommonHistsResults8th->FillDifferentialFlowPtRP(p,v8,0.);
6091   } else if(type == "POI")
6092     {
6093      fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,v2,v2Error);
6094      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,v4,v4Error);
6095      fCommonHistsResults6th->FillDifferentialFlowPtPOI(p,v6,0.);
6096      fCommonHistsResults8th->FillDifferentialFlowPtPOI(p,v8,0.);
6097     }
6098  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
6099  
6100  // eta:
6101  for(Int_t e=1;e<=fnBinsEta;e++)
6102  {
6103   Double_t v2 = fDiffFlow[t][1][0]->GetBinContent(e);
6104   Double_t v4 = fDiffFlow[t][1][1]->GetBinContent(e);
6105   Double_t v6 = fDiffFlow[t][1][2]->GetBinContent(e);
6106   Double_t v8 = fDiffFlow[t][1][3]->GetBinContent(e);
6107   
6108   Double_t v2Error = fDiffFlow[t][1][0]->GetBinError(e);
6109   Double_t v4Error = fDiffFlow[t][1][1]->GetBinError(e);
6110   //Double_t v6Error = fDiffFlow[t][1][2]->GetBinError(e);
6111   //Double_t v8Error = fDiffFlow[t][1][3]->GetBinError(e);
6112  
6113   if(type == "RP")
6114   {
6115    fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,v2,v2Error);
6116    fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,v4,v4Error);
6117    fCommonHistsResults6th->FillDifferentialFlowEtaRP(e,v6,0.);
6118    fCommonHistsResults8th->FillDifferentialFlowEtaRP(e,v8,0.);
6119   } else if(type == "POI")
6120     {
6121      fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,v2,v2Error);
6122      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,v4,v4Error);
6123      fCommonHistsResults6th->FillDifferentialFlowEtaPOI(e,v6,0.);
6124      fCommonHistsResults8th->FillDifferentialFlowEtaPOI(e,v8,0.);
6125     }
6126  } // end of for(Int_t e=1;e<=fnBinsEta;e++)    
6127  
6128 } // end of void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
6129
6130 //================================================================================================================================
6131
6132 void AliFlowAnalysisWithQCumulants::AccessConstants()
6133 {
6134  // Access needed common constants from AliFlowCommonConstants.
6135  
6136  fnBinsPhi = AliFlowCommonConstants::GetMaster()->GetNbinsPhi();
6137  fPhiMin = AliFlowCommonConstants::GetMaster()->GetPhiMin();         
6138  fPhiMax = AliFlowCommonConstants::GetMaster()->GetPhiMax();
6139  if(fnBinsPhi) fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;  
6140  fnBinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
6141  fPtMin = AliFlowCommonConstants::GetMaster()->GetPtMin();           
6142  fPtMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
6143  if(fnBinsPt) fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;  
6144  fnBinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
6145  fEtaMin = AliFlowCommonConstants::GetMaster()->GetEtaMin();         
6146  fEtaMax = AliFlowCommonConstants::GetMaster()->GetEtaMax();
6147  if(fnBinsEta) fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;  
6148  
6149 } // end of void AliFlowAnalysisWithQCumulants::AccessConstants()
6150
6151 //================================================================================================================================
6152
6153 void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6154 {
6155  // a) Cross check if the choice for multiplicity weights make sense;
6156  
6157  // a) Cross check if the choice for multiplicity weights make sense:
6158  if(strcmp(fMultiplicityWeight->Data(),"combinations") && 
6159     strcmp(fMultiplicityWeight->Data(),"unit") &&
6160     strcmp(fMultiplicityWeight->Data(),"multiplicity"))
6161  {
6162   cout<<"WARNING (QC): Multiplicity weight can be either \"combinations\", \"unit\""<<endl;
6163   cout<<"              or \"multiplicity\". Certainly not \""<<fMultiplicityWeight->Data()<<"\"."<<endl;
6164   exit(0);
6165  }   
6166  
6167 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckSettings()
6168
6169 //================================================================================================================================
6170
6171 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6172 {
6173  // Calculate sum of linear and quadratic event weights for correlations.
6174  
6175  // multiplicity:
6176  Double_t dMult = (*fSMpk)(0,0);
6177                         
6178  for(Int_t p=0;p<2;p++) // power-1
6179  {
6180   for(Int_t ci=0;ci<4;ci++) // correlation index
6181   { 
6182    fIntFlowSumOfEventWeights[p]->Fill(ci+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); 
6183    if(fCalculateCumulantsVsM)
6184    {
6185     fIntFlowSumOfEventWeightsVsM[ci][p]->Fill(dMult+0.5,pow(fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci+1),p+1)); // to be improved: dMult => sum of weights?
6186    }
6187   }
6188  }
6189   
6190 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeights()
6191
6192 //================================================================================================================================
6193
6194 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6195 {
6196  // Calculate sum of linear and quadratic event weights for NUA terms.
6197                        
6198  for(Int_t sc=0;sc<2;sc++) // sin or cos terms
6199  {
6200   for(Int_t p=0;p<2;p++) // power-1
6201   {
6202    for(Int_t ci=0;ci<3;ci++) // nua term index
6203    { 
6204     fIntFlowSumOfEventWeightsNUA[sc][p]->Fill(ci+0.5,pow(fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->GetBinContent(ci+1),p+1)); 
6205    }
6206   }
6207  }
6208   
6209 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfEventWeightsNUA()
6210
6211 //================================================================================================================================
6212
6213 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6214 {
6215  // Calculate sum of product of event weights for correlations.
6216   
6217  // multiplicity:
6218  Double_t dMult = (*fSMpk)(0,0);
6219   
6220  Int_t counter = 0;
6221  
6222  for(Int_t ci1=1;ci1<4;ci1++)
6223  {
6224   for(Int_t ci2=ci1+1;ci2<=4;ci2++)
6225   {
6226    fIntFlowSumOfProductOfEventWeights->Fill(0.5+counter,
6227                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6228                                             fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6229    if(fCalculateCumulantsVsM)
6230    {                                                                                    
6231     fIntFlowSumOfProductOfEventWeightsVsM[counter]->Fill(dMult+0.5, // to be improved: dMult => sum of weights?
6232                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci1)*
6233                                                          fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(ci2));
6234    } // end of if(fCalculateCumulantsVsM)
6235    counter++;                                         
6236   }
6237  }
6238
6239 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeights()
6240
6241 //================================================================================================================================
6242
6243 void AliFlowAnalysisWithQCumulants::CalculateIntFlowSumOfProductOfEventWeightsNUA()
6244 {
6245  // Calculate sum of product of event weights for NUA terms.
6246   
6247  // w_{<2>} * w_{<cos(#phi)>}:
6248  fIntFlowSumOfProductOfEventWeightsNUA->Fill(0.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6249                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6250  // w_{<2>} * w_{<sin(#phi)>}:
6251  fIntFlowSumOfProductOfEventWeightsNUA->Fill(1.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6252                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6253  // w_{<cos(#phi)> * w_{<sin(#phi)>}:
6254  fIntFlowSumOfProductOfEventWeightsNUA->Fill(2.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6255                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6256  // w_{<2>} * w{<cos(phi1+phi2)>}
6257  fIntFlowSumOfProductOfEventWeightsNUA->Fill(3.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6258                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6259  // w_{<2>} * w{<sin(phi1+phi2)>}
6260  fIntFlowSumOfProductOfEventWeightsNUA->Fill(4.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6261                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6262  // w_{<2>} * w{<cos(phi1-phi2-phi3)>}
6263  fIntFlowSumOfProductOfEventWeightsNUA->Fill(5.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6264                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6265  // w_{<2>} * w{<sin(phi1-phi2-phi3)>}
6266  fIntFlowSumOfProductOfEventWeightsNUA->Fill(6.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1)*
6267                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));  
6268  // w_{<4>} * w{<cos(phi1)>}
6269  fIntFlowSumOfProductOfEventWeightsNUA->Fill(7.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6270                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1));
6271  // w_{<4>} * w{<sin(phi1)>}
6272  fIntFlowSumOfProductOfEventWeightsNUA->Fill(8.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6273                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1));
6274  // w_{<4>} * w{<cos(phi1+phi2)>}
6275  fIntFlowSumOfProductOfEventWeightsNUA->Fill(9.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6276                                                  fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)); 
6277  // w_{<4>} * w{<sin(phi1+phi2)>}
6278  fIntFlowSumOfProductOfEventWeightsNUA->Fill(10.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6279                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6280  // w_{<4>} * w{<cos(phi1-phi2-phi3)>}
6281  fIntFlowSumOfProductOfEventWeightsNUA->Fill(11.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6282                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6283  // w_{<4>} * w{<sin(phi1-phi2-phi3)>}
6284  fIntFlowSumOfProductOfEventWeightsNUA->Fill(12.5,fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2)*
6285                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6286  // w_{<cos(phi1)>} * w{<cos(phi1+phi2)>}
6287  fIntFlowSumOfProductOfEventWeightsNUA->Fill(13.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6288                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6289  // w_{<cos(phi1)>} * w{<sin(phi1+phi2)>}
6290  fIntFlowSumOfProductOfEventWeightsNUA->Fill(14.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6291                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6292  // w_{<cos(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6293  fIntFlowSumOfProductOfEventWeightsNUA->Fill(15.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6294                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6295  // w_{<cos(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6296  fIntFlowSumOfProductOfEventWeightsNUA->Fill(16.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(1)*
6297                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6298  // w_{<sin(phi1)>} * w{<cos(phi1+phi2)>}
6299  fIntFlowSumOfProductOfEventWeightsNUA->Fill(17.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6300                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2));
6301  // w_{<sin(phi1)>} * w{<sin(phi1+phi2)>}
6302  fIntFlowSumOfProductOfEventWeightsNUA->Fill(18.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6303                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2));
6304  // w_{<sin(phi1)>} * w{<cos(phi1-phi2-phi3)>}
6305  fIntFlowSumOfProductOfEventWeightsNUA->Fill(19.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6306                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3));
6307  // w_{<sin(phi1)>} * w{<sin(phi1-phi2-phi3)>}
6308  fIntFlowSumOfProductOfEventWeightsNUA->Fill(20.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(1)*
6309                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6310  // w_{<cos(phi1+phi2)>} * w{<sin(phi1+phi2))>}
6311  fIntFlowSumOfProductOfEventWeightsNUA->Fill(21.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6312                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)); 
6313  // w_{<cos(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6314  fIntFlowSumOfProductOfEventWeightsNUA->Fill(22.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6315                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6316  // w_{<cos(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6317  fIntFlowSumOfProductOfEventWeightsNUA->Fill(23.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(2)*
6318                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6319  // w_{<sin(phi1+phi2)>} * w{<cos(phi1-phi2-phi3)>}
6320  fIntFlowSumOfProductOfEventWeightsNUA->Fill(24.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6321                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)); 
6322  // w_{<sin(phi1+phi2)>} * w{<sin(phi1-phi2-phi3)>}
6323  fIntFlowSumOfProductOfEventWeightsNUA->Fill(25.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(2)*
6324                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3)); 
6325  // w_{<cos(phi1-phi2-phi3)>} * w{<sin(phi1-phi2-phi3)>}
6326  fIntFlowSumOfProductOfEventWeightsNUA->Fill(26.5,fIntFlowEventWeightForCorrectionTermsForNUAEBE[1]->GetBinContent(3)*
6327                                                   fIntFlowEventWeightForCorrectionTermsForNUAEBE[0]->GetBinContent(3));
6328
6329 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowIntFlowSumOfProductOfEventWeightsNUA()
6330
6331
6332 //================================================================================================================================
6333
6334
6335 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta)
6336 {
6337  // calculate reduced correlations for RPs or POIs in pt or eta bins
6338
6339  // multiplicity:
6340  Double_t dMult = (*fSMpk)(0,0);
6341  
6342  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
6343  Double_t dReQ1n = (*fReQ)(0,0);
6344  Double_t dReQ2n = (*fReQ)(1,0);
6345  //Double_t dReQ3n = (*fReQ)(2,0);
6346  //Double_t dReQ4n = (*fReQ)(3,0);
6347  Double_t dImQ1n = (*fImQ)(0,0);
6348  Double_t dImQ2n = (*fImQ)(1,0);
6349  //Double_t dImQ3n = (*fImQ)(2,0);
6350  //Double_t dImQ4n = (*fImQ)(3,0);
6351
6352  // reduced correlations are stored in fDiffFlowCorrelationsPro[0=RP,1=POI][0=pt,1=eta][correlation index]. Correlation index runs as follows:
6353  // 
6354  // 0: <<2'>>
6355  // 1: <<4'>>
6356  // 2: <<6'>>
6357  // 3: <<8'>>
6358  
6359  Int_t t = -1; // type flag 
6360  Int_t pe = -1; // ptEta flag
6361  
6362  if(type == "RP")
6363  {
6364   t = 0;
6365  } else if(type == "POI")
6366    {
6367     t = 1;
6368    }
6369
6370  if(ptOrEta == "Pt")
6371  {
6372   pe = 0;
6373  } else if(ptOrEta == "Eta")
6374    {
6375     pe = 1;
6376    }
6377     
6378  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6379  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6380  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6381  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6382
6383  // looping over all bins and calculating reduced correlations: 
6384  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6385  {
6386   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
6387   Double_t p1n0kRe = 0.;
6388   Double_t p1n0kIm = 0.;
6389
6390   // number of POIs in particular pt or eta bin:
6391   Double_t mp = 0.;
6392
6393   // 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):
6394   Double_t q1n0kRe = 0.;
6395   Double_t q1n0kIm = 0.;
6396   Double_t q2n0kRe = 0.;
6397   Double_t q2n0kIm = 0.;
6398
6399   // number of particles which are both RPs and POIs in particular pt or eta bin:
6400   Double_t mq = 0.;
6401    
6402   if(type == "POI")
6403   {
6404    // q_{m*n,0}:
6405    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
6406            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
6407    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
6408            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
6409    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
6410            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
6411    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
6412            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
6413                  
6414    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6415   } 
6416   else if(type == "RP")
6417   {
6418    // q_{m*n,0}:
6419    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
6420            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
6421    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
6422            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
6423    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
6424            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
6425    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
6426            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
6427                  
6428    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
6429   }
6430       
6431    if(type == "POI")
6432    {
6433     // p_{m*n,0}:
6434     p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
6435             * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
6436     p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
6437             * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
6438             
6439     mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
6440     
6441     t = 1; // typeFlag = RP or POI
6442    }
6443    else if(type == "RP")
6444    {
6445     // p_{m*n,0} = q_{m*n,0}:
6446     p1n0kRe = q1n0kRe; 
6447     p1n0kIm = q1n0kIm; 
6448             
6449     mp = mq; 
6450     
6451     t = 0; // typeFlag = RP or POI
6452    }
6453       
6454    // 2'-particle correlation for particular (pt,eta) bin:
6455    Double_t two1n1nPtEta = 0.;
6456    if(mp*dMult-mq)
6457    {
6458     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
6459                  / (mp*dMult-mq);
6460    
6461     if(type == "POI") // to be improved (I do not this if)
6462     { 
6463      // fill profile to get <<2'>> for POIs
6464      fDiffFlowCorrelationsPro[1][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mp*dMult-mq);
6465      // histogram to store <2'> for POIs e-b-e (needed in some other methods):
6466      fDiffFlowCorrelationsEBE[1][pe][0]->SetBinContent(b,two1n1nPtEta);      
6467      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][0]->SetBinContent(b,mp*dMult-mq);      
6468     }
6469     else if(type == "RP") // to be improved (I do not this if)
6470     {
6471      // profile to get <<2'>> for RPs:
6472      fDiffFlowCorrelationsPro[0][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nPtEta,mp*dMult-mq);
6473      // histogram to store <2'> for RPs e-b-e (needed in some other methods):
6474      fDiffFlowCorrelationsEBE[0][pe][0]->SetBinContent(b,two1n1nPtEta); 
6475      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][0]->SetBinContent(b,mp*dMult-mq); 
6476     }
6477    } // end of if(mp*dMult-mq)
6478   
6479    // 4'-particle correlation:
6480    Double_t four1n1n1n1nPtEta = 0.;
6481    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6482        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
6483    {
6484     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6485                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
6486                       - 2.*q2n0kIm*dReQ1n*dImQ1n
6487                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
6488                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
6489                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6490                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
6491                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
6492                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
6493                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
6494                       + 2.*mq*dMult                      
6495                       - 6.*mq)        
6496                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6497                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
6498     
6499     if(type == "POI")
6500     {
6501      // profile to get <<4'>> for POIs:
6502      fDiffFlowCorrelationsPro[1][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,
6503                                      (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6504                                      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
6505      // histogram to store <4'> for POIs e-b-e (needed in some other methods):
6506      fDiffFlowCorrelationsEBE[1][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                               
6507      fDiffFlowEventWeightsForCorrelationsEBE[1][pe][1]->SetBinContent(b,(mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6508                                                                         + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                               
6509     }
6510     else if(type == "RP")
6511     {
6512      // profile to get <<4'>> for RPs:
6513      fDiffFlowCorrelationsPro[0][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nPtEta,
6514                                        (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6515                                        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
6516      // histogram to store <4'> for RPs e-b-e (needed in some other methods):
6517      fDiffFlowCorrelationsEBE[0][pe][1]->SetBinContent(b,four1n1n1n1nPtEta);                   
6518      fDiffFlowEventWeightsForCorrelationsEBE[0][pe][1]->SetBinContent(b,(mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6519                                                                         + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
6520     }
6521    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6522      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
6523    
6524  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6525  
6526    
6527 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelations(TString type, TString ptOrEta);
6528
6529
6530 //================================================================================================================================
6531
6532
6533 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights(TString type, TString ptOrEta)
6534 {
6535  // Calculate sums of various event weights for reduced correlations. 
6536  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
6537
6538  Int_t typeFlag = -1;
6539  Int_t ptEtaFlag = -1;
6540
6541  if(type == "RP")
6542  {
6543   typeFlag = 0;
6544  } else if(type == "POI")
6545    {
6546     typeFlag = 1;
6547    } 
6548      
6549  if(ptOrEta == "Pt")
6550  {
6551   ptEtaFlag = 0;
6552  } else if(ptOrEta == "Eta")
6553    {
6554     ptEtaFlag = 1;
6555    } 
6556    
6557  // shortcuts:
6558  Int_t t = typeFlag;
6559  Int_t pe = ptEtaFlag;
6560  
6561  // binning:
6562  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6563  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6564  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6565  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6566  
6567  for(Int_t rpq=0;rpq<3;rpq++)
6568  {
6569   for(Int_t m=0;m<4;m++)
6570   {
6571    for(Int_t k=0;k<9;k++)
6572    {
6573     if(!fReRPQ1dEBE[rpq][pe][m][k])
6574     {
6575      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
6576      cout<<"pe  = "<<pe<<endl;
6577      cout<<"rpq = "<<rpq<<endl;
6578      cout<<"m   = "<<m<<endl;
6579      cout<<"k   = "<<k<<endl;
6580      exit(0); 
6581     }
6582    }
6583   }
6584  }  
6585
6586  // multiplicities:
6587  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
6588  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
6589  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
6590  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
6591  
6592  // event weights for reduced correlations:
6593  Double_t dw2 = 0.; // event weight for <2'>
6594  Double_t dw4 = 0.; // event weight for <4'>
6595  //Double_t dw6 = 0.; // event weight for <6'>
6596  //Double_t dw8 = 0.; // event weight for <8'>
6597
6598  // looping over bins:
6599  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6600  {
6601   if(type == "RP")
6602   {
6603    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
6604    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
6605   } else if(type == "POI")
6606     {
6607      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
6608      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
6609     }
6610   
6611   // event weight for <2'>:
6612   dw2 = mp*dMult-mq;  
6613   fDiffFlowSumOfEventWeights[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2);
6614   fDiffFlowSumOfEventWeights[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw2,2.));
6615   
6616   // event weight for <4'>:
6617   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6618      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
6619   fDiffFlowSumOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4);
6620   fDiffFlowSumOfEventWeights[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw4,2.));
6621   
6622   // event weight for <6'>:
6623   //dw6 = ...;  
6624   //fDiffFlowSumOfEventWeights[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6);
6625   //fDiffFlowSumOfEventWeights[t][pe][t][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw6,2.));
6626   
6627   // event weight for <8'>:
6628   //dw8 = ...;  
6629   //fDiffFlowSumOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw8);
6630   //fDiffFlowSumOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],pow(dw8,2.));   
6631  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++) 
6632  
6633 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfEventWeights()
6634
6635
6636 //================================================================================================================================
6637
6638
6639 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
6640 {
6641  // Calculate sum of products of various event weights for both types of correlations (the ones for int. and diff. flow). 
6642  // (These quantitites are needed in expressions for unbiased estimators relevant for the statistical errors.)
6643  //
6644  // Important: To fill fDiffFlowSumOfProductOfEventWeights[][][][] use bellow table (i,j) with following constraints: 
6645  // 1.) i<j  
6646  // 2.) do not store terms which DO NOT include reduced correlations;
6647  // Table:
6648  // [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'>]
6649   
6650  Int_t typeFlag = -1;
6651  Int_t ptEtaFlag = -1;
6652
6653  if(type == "RP")
6654  {
6655   typeFlag = 0;
6656  } else if(type == "POI")
6657    {
6658     typeFlag = 1;
6659    } 
6660      
6661  if(ptOrEta == "Pt")
6662  {
6663   ptEtaFlag = 0;
6664  } else if(ptOrEta == "Eta")
6665    {
6666     ptEtaFlag = 1;
6667    } 
6668      
6669  // shortcuts:
6670  Int_t t = typeFlag;
6671  Int_t pe = ptEtaFlag;
6672   
6673  // binning:
6674  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6675  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6676  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
6677  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6678  
6679  // protection:
6680  for(Int_t rpq=0;rpq<3;rpq++)
6681  {
6682   for(Int_t m=0;m<4;m++)
6683   {
6684    for(Int_t k=0;k<9;k++)
6685    {
6686     if(!fReRPQ1dEBE[rpq][pe][m][k])
6687     {
6688      cout<<"WARNING: fReRPQ1dEBE[rpq][pe][m][k] is NULL in AFAWQC::CSAPOEWFDF() !!!!"<<endl;
6689      cout<<"pe  = "<<pe<<endl;
6690      cout<<"rpq = "<<rpq<<endl;
6691      cout<<"m   = "<<m<<endl;
6692      cout<<"k   = "<<k<<endl;
6693      exit(0); 
6694     }
6695    }
6696   }
6697  }  
6698  
6699  // multiplicities:
6700  Double_t dMult = (*fSMpk)(0,0); // total event multiplicity
6701  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
6702  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
6703  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
6704  
6705  // event weights for correlations:
6706  Double_t dW2 = dMult*(dMult-1); // event weight for <2> 
6707  Double_t dW4 = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
6708  Double_t dW6 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
6709  Double_t dW8 = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
6710
6711  // event weights for reduced correlations:
6712  Double_t dw2 = 0.; // event weight for <2'>
6713  Double_t dw4 = 0.; // event weight for <4'>
6714  //Double_t dw6 = 0.; // event weight for <6'>
6715  //Double_t dw8 = 0.; // event weight for <8'>
6716  
6717  // looping over bins:
6718  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6719  {
6720   if(type == "RP")
6721   {
6722    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
6723    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
6724   } else if(type == "POI")
6725     {
6726      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
6727      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
6728     }
6729   
6730   // event weight for <2'>:
6731   dw2 = mp*dMult-mq;  
6732   fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw2); // storing product of even weights for <2> and <2'>
6733   fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW4); // storing product of even weights for <4> and <2'>
6734   fDiffFlowSumOfProductOfEventWeights[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW6); // storing product of even weights for <6> and <2'>
6735   fDiffFlowSumOfProductOfEventWeights[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dW8); // storing product of even weights for <8> and <2'>
6736   
6737   // event weight for <4'>:
6738   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6739      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.);  
6740   fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw4); // storing product of even weights for <2> and <4'>
6741   fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw4); // storing product of even weights for <2'> and <4'>
6742   fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw4); // storing product of even weights for <4> and <4'>
6743   fDiffFlowSumOfProductOfEventWeights[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW6); // storing product of even weights for <6> and <4'> 
6744   fDiffFlowSumOfProductOfEventWeights[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dW8); // storing product of even weights for <8> and <4'>
6745
6746   // event weight for <6'>:
6747   //dw6 = ...;  
6748   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw6); // storing product of even weights for <2> and <6'>
6749   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw6); // storing product of even weights for <2'> and <6'>
6750   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw6); // storing product of even weights for <4> and <6'>
6751   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw6); // storing product of even weights for <4'> and <6'> 
6752   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw6); // storing product of even weights for <6> and <6'>
6753   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dW8); // storing product of even weights for <6'> and <8>
6754   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
6755
6756   // event weight for <8'>:
6757   //dw8 = ...;  
6758   //fDiffFlowSumOfProductOfEventWeights[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW2*dw8); // storing product of even weights for <2> and <8'>
6759   //fDiffFlowSumOfProductOfEventWeights[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw2*dw8); // storing product of even weights for <2'> and <8'>
6760   //fDiffFlowSumOfProductOfEventWeights[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW4*dw8); // storing product of even weights for <4> and <8'>
6761   //fDiffFlowSumOfProductOfEventWeights[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw4*dw8); // storing product of even weights for <4'> and <8'> 
6762   //fDiffFlowSumOfProductOfEventWeights[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW6*dw8); // storing product of even weights for <6> and <8'>
6763   //fDiffFlowSumOfProductOfEventWeights[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dw6*dw8); // storing product of even weights for <6'> and <8'>
6764   //fDiffFlowSumOfProductOfEventWeights[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],dW8*dw8); // storing product of even weights for <8> and <8'>
6765   
6766   // Table:
6767   // [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'>]
6768    
6769  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6770  
6771
6772
6773 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowSumOfProductOfEventWeights(TString type, TString ptOrEta)
6774
6775
6776 //================================================================================================================================
6777
6778
6779 void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
6780 {
6781  // Transfer profiles into histograms and calculate statistical errors correctly.
6782
6783  Int_t typeFlag = -1;
6784  Int_t ptEtaFlag = -1;
6785
6786  if(type == "RP")
6787  {
6788   typeFlag = 0;
6789  } else if(type == "POI")
6790    {
6791     typeFlag = 1;
6792    } 
6793      
6794  if(ptOrEta == "Pt")
6795  {
6796   ptEtaFlag = 0;
6797  } else if(ptOrEta == "Eta")
6798    {
6799     ptEtaFlag = 1;
6800    } 
6801   
6802  // shortcuts:
6803  Int_t t = typeFlag;
6804  Int_t pe = ptEtaFlag;
6805              
6806  for(Int_t rci=0;rci<4;rci++)
6807  {
6808   if(!fDiffFlowCorrelationsPro[t][pe][rci])
6809   {
6810    cout<<"WARNING: fDiffFlowCorrelationsPro[t][pe][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
6811    cout<<"t   = "<<t<<endl; 
6812    cout<<"pe  = "<<pe<<endl; 
6813    cout<<"rci = "<<rci<<endl;
6814    exit(0); 
6815   }
6816   for(Int_t power=0;power<2;power++)
6817   {
6818    if(!fDiffFlowSumOfEventWeights[t][pe][power][rci])
6819    {
6820     cout<<"WARNING: fDiffFlowSumOfEventWeights[t][pe][power][rci] is NULL in AFAWQC::FRC() !!!!"<<endl;
6821     cout<<"t     = "<<t<<endl; 
6822     cout<<"pe    = "<<pe<<endl;
6823     cout<<"power = "<<power<<endl; 
6824     cout<<"rci   = "<<rci<<endl;
6825     exit(0); 
6826    }   
6827   } // end of for(Int_t power=0;power<2;power++)
6828  } // end of for(Int_t rci=0;rci<4;rci++)
6829     
6830  // common:
6831  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6832  
6833  // transfer 1D profile into 1D histogram:
6834  Double_t correlation = 0.;
6835  Double_t spread = 0.;
6836  Double_t sumOfWeights = 0.; // sum of weights for particular reduced correlations for particular pt or eta bin
6837  Double_t sumOfSquaredWeights = 0.; // sum of squared weights for particular reduced correlations for particular pt or eta bin
6838  Double_t error = 0.; // error = termA * spread * termB
6839                       // termA = (sqrt(sumOfSquaredWeights)/sumOfWeights) 
6840                       // termB = 1/pow(1-termA^2,0.5)
6841  Double_t termA = 0.;                      
6842  Double_t termB = 0.;                      
6843  for(Int_t rci=0;rci<4;rci++) // index of reduced correlation
6844  {
6845   for(Int_t b=1;b<=nBinsPtEta[pe];b++) // number of pt or eta bins
6846   {
6847    correlation = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(b); 
6848    spread = fDiffFlowCorrelationsPro[t][pe][rci]->GetBinError(b);
6849    sumOfWeights = fDiffFlowSumOfEventWeights[t][pe][0][rci]->GetBinContent(b);
6850    sumOfSquaredWeights = fDiffFlowSumOfEventWeights[t][pe][1][rci]->GetBinContent(b);
6851    if(sumOfWeights) termA = (pow(sumOfSquaredWeights,0.5)/sumOfWeights);
6852    if(1.-pow(termA,2.)>0.) termB = 1./pow(1.-pow(termA,2.),0.5); 
6853    error = termA*spread*termB; // final error (unbiased estimator for standard deviation)
6854    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinContent(b,correlation); 
6855    fDiffFlowCorrelationsHist[t][pe][rci]->SetBinError(b,error); 
6856   } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6857  } // end of for(Int_t rci=0;rci<4;rci++)
6858  
6859 } // end of void AliFlowAnalysisWithQCumulants::FinalizeReducedCorrelations(TString type, TString ptOrEta)
6860
6861
6862 //================================================================================================================================
6863
6864
6865 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
6866 {
6867  // store products: <2><2'>, <2><4'>, <2><6'>, <2><8'>, <2'><4>, 
6868  //                 <2'><4'>, <2'><6>, <2'><6'>, <2'><8>, <2'><8'>,
6869  //                 <4><4'>, <4><6'>, <4><8'>, <4'><6>, <4'><6'>, 
6870  //                 <4'><8>, <4'><8'>, <6><6'>, <6><8'>, <6'><8>, 
6871  //                 <6'><8'>, <8><8'>.
6872   
6873  Int_t typeFlag = -1;
6874  Int_t ptEtaFlag = -1;
6875
6876  if(type == "RP")
6877  {
6878   typeFlag = 0;
6879  } else if(type == "POI")
6880    {
6881     typeFlag = 1;
6882    } 
6883      
6884  if(ptOrEta == "Pt")
6885  {
6886   ptEtaFlag = 0;
6887  } else if(ptOrEta == "Eta")
6888    {
6889     ptEtaFlag = 1;
6890    } 
6891   
6892  // shortcuts:
6893  Int_t t = typeFlag;
6894  Int_t pe = ptEtaFlag;
6895      
6896  // common:
6897  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
6898  Double_t minPtEta[2] = {fPtMin,fEtaMin};
6899  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
6900    
6901  // protections // to be improved (add protection for all pointers in this method)
6902  if(!fIntFlowCorrelationsEBE)
6903  {
6904   cout<<"WARNING: fIntFlowCorrelationsEBE is NULL in AFAWQC::CDFPOC() !!!!"<<endl;
6905   exit(0);
6906  } 
6907  
6908  /*    
6909  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
6910  //Double_t mr = 0.; // number of RPs in particular pt or eta bin
6911  Double_t mp = 0.; // number of POIs in particular pt or eta bin 
6912  Double_t mq = 0.; // number of particles which are both RPs and POIs in particular pt or eta bin
6913  */
6914
6915  // e-b-e correlations:
6916  Double_t twoEBE = fIntFlowCorrelationsEBE->GetBinContent(1); // <2>
6917  Double_t fourEBE = fIntFlowCorrelationsEBE->GetBinContent(2); // <4>
6918  Double_t sixEBE = fIntFlowCorrelationsEBE->GetBinContent(3); // <6>
6919  Double_t eightEBE = fIntFlowCorrelationsEBE->GetBinContent(4); // <8>
6920  
6921  // event weights for correlations:
6922  Double_t dW2 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(1); // event weight for <2> 
6923  Double_t dW4 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(2); // event weight for <4> 
6924  Double_t dW6 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(3); // event weight for <6> 
6925  Double_t dW8 = fIntFlowEventWeightsForCorrelationsEBE->GetBinContent(4); // event weight for <8> 
6926   
6927  // e-b-e reduced correlations:
6928  Double_t twoReducedEBE = 0.; // <2'>
6929  Double_t fourReducedEBE = 0.; // <4'>
6930  Double_t sixReducedEBE = 0.; // <6'>
6931  Double_t eightReducedEBE = 0.; // <8'> 
6932  
6933  // event weights for reduced correlations:
6934  Double_t dw2 = 0.; // event weight for <2'>
6935  Double_t dw4 = 0.; // event weight for <4'>
6936  //Double_t dw6 = 0.; // event weight for <6'>
6937  //Double_t dw8 = 0.; // event weight for <8'>
6938
6939  // looping over bins:
6940  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
6941  {
6942   // e-b-e reduced correlations:
6943   twoReducedEBE = fDiffFlowCorrelationsEBE[t][pe][0]->GetBinContent(b);
6944   fourReducedEBE = fDiffFlowCorrelationsEBE[t][pe][1]->GetBinContent(b);
6945   sixReducedEBE = fDiffFlowCorrelationsEBE[t][pe][2]->GetBinContent(b);
6946   eightReducedEBE = fDiffFlowCorrelationsEBE[t][pe][3]->GetBinContent(b);
6947   
6948   /*
6949   // to be improved (I should not do this here again)
6950   if(type == "RP")
6951   {
6952    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(b);
6953    mp = mq; // trick to use the very same Eqs. bellow both for RP's and POI's diff. flow
6954   } else if(type == "POI")
6955     {
6956      mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(b);
6957      mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(b);    
6958     }
6959   
6960   // event weights for reduced correlations:
6961   dw2 = mp*dMult-mq; // weight for <2'> 
6962   dw4 = (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6963      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.); // weight for <4'>
6964   //dw6 = ...     
6965   //dw8 = ...     
6966   
6967   */
6968   
6969   dw2 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->GetBinContent(b);
6970   dw4 = fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->GetBinContent(b);
6971  
6972   // storing all products:
6973   fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*twoReducedEBE,dW2*dw2); // storing <2><2'>
6974   fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*twoReducedEBE,dW4*dw2); // storing <4><2'>
6975   fDiffFlowProductOfCorrelationsPro[t][pe][1][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*twoReducedEBE,dW6*dw2); // storing <6><2'>
6976   fDiffFlowProductOfCorrelationsPro[t][pe][1][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*twoReducedEBE,dW8*dw2); // storing <8><2'>
6977   
6978   // event weight for <4'>:
6979   fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*fourReducedEBE,dW2*dw4); // storing <2><4'>
6980   fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*fourReducedEBE,dw2*dw4); // storing <2'><4'>
6981   fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*fourReducedEBE,dW4*dw4); // storing <4><4'>
6982   fDiffFlowProductOfCorrelationsPro[t][pe][3][4]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*fourReducedEBE,dW6*dw4); // storing <6><4'> 
6983   fDiffFlowProductOfCorrelationsPro[t][pe][3][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*fourReducedEBE,dW8*dw4); // storing <8><4'>
6984
6985   // event weight for <6'>:
6986   //dw6 = ...;  
6987   //fDiffFlowProductOfCorrelationsPro[t][pe][0][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*sixReducedEBE,dW2*dw6); // storing <2><6'>
6988   //fDiffFlowProductOfCorrelationsPro[t][pe][1][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*sixReducedEBE,dw2*dw6); // storing <2'><6'>
6989   //fDiffFlowProductOfCorrelationsPro[t][pe][2][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*sixReducedEBE,dW4*dw6); // storing <4><6'>
6990   //fDiffFlowProductOfCorrelationsPro[t][pe][3][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*sixReducedEBE,dw4*dw6); // storing <4'><6'> 
6991   //fDiffFlowProductOfCorrelationsPro[t][pe][4][5]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*sixReducedEBE,dW6*dw6); // storing <6><6'>
6992   //fDiffFlowProductOfCorrelationsPro[t][pe][5][6]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightEBE,dw6*dW8); // storing <6'><8>
6993   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
6994
6995   // event weight for <8'>:
6996   //dw8 = ...;  
6997   //fDiffFlowProductOfCorrelationsPro[t][pe][0][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoEBE*eightReducedEBE,dW2*dw8); // storing <2><8'>
6998   //fDiffFlowProductOfCorrelationsPro[t][pe][1][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],twoReducedEBE*eightReducedEBE,dw2*dw8); // storing <2'><8'>
6999   //fDiffFlowProductOfCorrelationsPro[t][pe][2][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourEBE*eightReducedEBE,dW4*dw8); // storing <4><8'>
7000   //fDiffFlowProductOfCorrelationsPro[t][pe][3][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],fourReducedEBE*eightReducedEBE,dw4*dw8); // storing <4'><8'> 
7001   //fDiffFlowProductOfCorrelationsPro[t][pe][4][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixEBE*eightReducedEBE,dW6*dw8); // storing <6><8'>
7002   //fDiffFlowProductOfCorrelationsPro[t][pe][5][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sixReducedEBE*eightReducedEBE,dw6*dw8); // storing <6'><8'>
7003   //fDiffFlowProductOfCorrelationsPro[t][pe][6][7]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],eightEBE*eightReducedEBE,dW8*dw8); // storing <8><8'> 
7004  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++       
7005      
7006 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowProductOfCorrelations(TString type, TString ptOrEta)
7007
7008
7009 //================================================================================================================================
7010     
7011     
7012 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta) // to be improved (reimplemented)
7013 {
7014  // a) Calculate unbiased estimators Cov(<2>,<2'>), Cov(<2>,<4'>), Cov(<4>,<2'>), Cov(<4>,<4'>) and Cov(<2'>,<4'>)
7015  //    for covariances V(<2>,<2'>), V(<2>,<4'>), V(<4>,<2'>), V(<4>,<4'>) and V(<2'>,<4'>).  
7016  // b) Store in histogram fDiffFlowCovariances[t][pe][index] for instance the following: 
7017  //
7018  //             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)]
7019  // 
7020  //     where N is the number of events, w_{<2>} is event weight for <2> and w_{<2'>} is event weight for <2'>.
7021  // c) Binning of fDiffFlowCovariances[t][pe][index] is organized as follows:
7022  // 
7023  //     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)] 
7024  //     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)] 
7025  //     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)] 
7026  //     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)] 
7027  //     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)] 
7028  //     ...
7029   
7030  Int_t typeFlag = -1;
7031  Int_t ptEtaFlag = -1;
7032
7033  if(type == "RP")
7034  {
7035   typeFlag = 0;
7036  } else if(type == "POI")
7037    {
7038     typeFlag = 1;
7039    } 
7040      
7041  if(ptOrEta == "Pt")
7042  {
7043   ptEtaFlag = 0;
7044  } else if(ptOrEta == "Eta")
7045    {
7046     ptEtaFlag = 1;
7047    } 
7048   
7049  // shortcuts:
7050  Int_t t = typeFlag;
7051  Int_t pe = ptEtaFlag;
7052      
7053  // common:
7054  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7055  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
7056  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
7057  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
7058  
7059  // average correlations:
7060  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7061  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7062  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
7063  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
7064  
7065  // sum of weights for correlation:
7066  Double_t sumOfWeightsForTwo = fIntFlowSumOfEventWeights[0]->GetBinContent(1); // sum_{i=1}^{N} w_{<2>}
7067  Double_t sumOfWeightsForFour = fIntFlowSumOfEventWeights[0]->GetBinContent(2); // sum_{i=1}^{N} w_{<4>}
7068  //Double_t sumOfWeightsForSix = fIntFlowSumOfEventWeights[0]->GetBinContent(3); // sum_{i=1}^{N} w_{<6>}
7069  //Double_t sumOfWeightsForEight = fIntFlowSumOfEventWeights[0]->GetBinContent(4); // sum_{i=1}^{N} w_{<8>}
7070  
7071  // average reduced correlations:
7072  Double_t twoReduced = 0.; // <<2'>> 
7073  Double_t fourReduced = 0.; // <<4'>>
7074  //Double_t sixReduced = 0.; // <<6'>>
7075  //Double_t eightReduced = 0.; // <<8'>>
7076
7077  // sum of weights for reduced correlation:
7078  Double_t sumOfWeightsForTwoReduced = 0.; // sum_{i=1}^{N} w_{<2'>}
7079  Double_t sumOfWeightsForFourReduced = 0.; // sum_{i=1}^{N} w_{<4'>}
7080  //Double_t sumOfWeightsForSixReduced = 0.; // sum_{i=1}^{N} w_{<6'>}
7081  //Double_t sumOfWeightsForEightReduced = 0.; // sum_{i=1}^{N} w_{<8'>}
7082   
7083  // product of weights for reduced correlation:
7084  Double_t productOfWeightsForTwoTwoReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<2'>}
7085  Double_t productOfWeightsForTwoFourReduced = 0.; // sum_{i=1}^{N} w_{<2>}w_{<4'>}
7086  Double_t productOfWeightsForFourTwoReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<2'>}
7087  Double_t productOfWeightsForFourFourReduced = 0.; // sum_{i=1}^{N} w_{<4>}w_{<4'>}
7088  Double_t productOfWeightsForTwoReducedFourReduced = 0.; // sum_{i=1}^{N} w_{<2'>}w_{<4'>}
7089  // ...
7090  
7091  // products for differential flow:
7092  Double_t twoTwoReduced = 0; // <<2><2'>> 
7093  Double_t twoFourReduced = 0; // <<2><4'>> 
7094  Double_t fourTwoReduced = 0; // <<4><2'>> 
7095  Double_t fourFourReduced = 0; // <<4><4'>> 
7096  Double_t twoReducedFourReduced = 0; // <<2'><4'>> 
7097
7098  // denominators in the expressions for the unbiased estimators for covariances:
7099  // denominator = 1 - term1/(term2*term3)
7100  // prefactor = term1/(term2*term3)
7101  Double_t denominator = 0.; 
7102  Double_t prefactor = 0.;
7103  Double_t term1 = 0.; 
7104  Double_t term2 = 0.; 
7105  Double_t term3 = 0.; 
7106  
7107  // unbiased estimators for covariances for differential flow:
7108  Double_t covTwoTwoReduced = 0.; // Cov(<2>,<2'>)
7109  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(w_{<2>},w_{<2'>})
7110  Double_t covTwoFourReduced = 0.; // Cov(<2>,<4'>)
7111  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(w_{<2>},w_{<4'>})
7112  Double_t covFourTwoReduced = 0.; // Cov(<4>,<2'>)
7113  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(w_{<4>},w_{<2'>})
7114  Double_t covFourFourReduced = 0.; // Cov(<4>,<4'>)
7115  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(w_{<4>},w_{<4'>})
7116  Double_t covTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>)
7117  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(w_{<2'>},w_{<4'>})
7118  
7119  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7120  {
7121   // average reduced corelations:
7122   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
7123   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
7124   // average products:
7125   twoTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][1]->GetBinContent(b);
7126   twoFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][0][3]->GetBinContent(b);
7127   fourTwoReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][2]->GetBinContent(b);
7128   fourFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][2][3]->GetBinContent(b);
7129   twoReducedFourReduced = fDiffFlowProductOfCorrelationsPro[t][pe][1][3]->GetBinContent(b);  
7130   // sum of weights for reduced correlations:
7131   sumOfWeightsForTwoReduced = fDiffFlowSumOfEventWeights[t][pe][0][0]->GetBinContent(b);
7132   sumOfWeightsForFourReduced = fDiffFlowSumOfEventWeights[t][pe][0][1]->GetBinContent(b);
7133   // products of weights for correlations:
7134   productOfWeightsForTwoTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][1]->GetBinContent(b); 
7135   productOfWeightsForTwoFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][0][3]->GetBinContent(b);
7136   productOfWeightsForFourTwoReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][2]->GetBinContent(b);
7137   productOfWeightsForFourFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][2][3]->GetBinContent(b);
7138   productOfWeightsForTwoReducedFourReduced = fDiffFlowSumOfProductOfEventWeights[t][pe][1][3]->GetBinContent(b);
7139   // denominator for the unbiased estimator for covariances: 1 - term1/(term2*term3) 
7140   // prefactor (multiplies Cov's) = term1/(term2*term3)       
7141   // <2>,<2'>:
7142   term1 = productOfWeightsForTwoTwoReduced;      
7143   term2 = sumOfWeightsForTwo;
7144   term3 = sumOfWeightsForTwoReduced;        
7145   if(term2*term3>0.)
7146   {
7147    denominator = 1.-term1/(term2*term3);
7148    prefactor = term1/(term2*term3);
7149    if(TMath::Abs(denominator)>1e-6)
7150    {
7151     covTwoTwoReduced = (twoTwoReduced-two*twoReduced)/denominator;            
7152     wCovTwoTwoReduced = covTwoTwoReduced*prefactor; 
7153     fDiffFlowCovariances[t][pe][0]->SetBinContent(b,wCovTwoTwoReduced);
7154    }
7155   }
7156   // <2>,<4'>:
7157   term1 = productOfWeightsForTwoFourReduced;      
7158   term2 = sumOfWeightsForTwo;
7159   term3 = sumOfWeightsForFourReduced;        
7160   if(term2*term3>0.)
7161   {
7162    denominator = 1.-term1/(term2*term3);
7163    prefactor = term1/(term2*term3);
7164    if(TMath::Abs(denominator)>1e-6)
7165    {
7166     covTwoFourReduced = (twoFourReduced-two*fourReduced)/denominator;            
7167     wCovTwoFourReduced = covTwoFourReduced*prefactor; 
7168     fDiffFlowCovariances[t][pe][1]->SetBinContent(b,wCovTwoFourReduced);
7169    }
7170   }
7171   // <4>,<2'>:
7172   term1 = productOfWeightsForFourTwoReduced;      
7173   term2 = sumOfWeightsForFour;
7174   term3 = sumOfWeightsForTwoReduced;        
7175   if(term2*term3>0.)
7176   {
7177    denominator = 1.-term1/(term2*term3);
7178    prefactor = term1/(term2*term3);
7179    if(TMath::Abs(denominator)>1e-6)
7180    {
7181     covFourTwoReduced = (fourTwoReduced-four*twoReduced)/denominator;            
7182     wCovFourTwoReduced = covFourTwoReduced*prefactor; 
7183     fDiffFlowCovariances[t][pe][2]->SetBinContent(b,wCovFourTwoReduced);
7184    }
7185   }
7186   // <4>,<4'>:
7187   term1 = productOfWeightsForFourFourReduced;      
7188   term2 = sumOfWeightsForFour;
7189   term3 = sumOfWeightsForFourReduced;        
7190   if(term2*term3>0.)
7191   {
7192    denominator = 1.-term1/(term2*term3);
7193    prefactor = term1/(term2*term3);
7194    if(TMath::Abs(denominator)>1e-6)
7195    {
7196     covFourFourReduced = (fourFourReduced-four*fourReduced)/denominator;            
7197     wCovFourFourReduced = covFourFourReduced*prefactor; 
7198     fDiffFlowCovariances[t][pe][3]->SetBinContent(b,wCovFourFourReduced);
7199    }
7200   }
7201   // <2'>,<4'>:
7202   term1 = productOfWeightsForTwoReducedFourReduced;      
7203   term2 = sumOfWeightsForTwoReduced;
7204   term3 = sumOfWeightsForFourReduced;        
7205   if(term2*term3>0.)
7206   {
7207    denominator = 1.-term1/(term2*term3);
7208    prefactor = term1/(term2*term3);
7209    if(TMath::Abs(denominator)>1e-6)
7210    {
7211     covTwoReducedFourReduced = (twoReducedFourReduced-twoReduced*fourReduced)/denominator;            
7212     wCovTwoReducedFourReduced = covTwoReducedFourReduced*prefactor; 
7213     fDiffFlowCovariances[t][pe][4]->SetBinContent(b,wCovTwoReducedFourReduced);
7214    }
7215   }   
7216  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7217   
7218 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCovariances(TString type, TString ptOrEta)
7219
7220
7221 //================================================================================================================================
7222
7223
7224 void AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, TString ptOrEta)
7225 {
7226  // calculate differential flow from differential cumulants and previously obtained integrated flow: (to be improved: description)
7227  
7228  Int_t typeFlag = -1;
7229  Int_t ptEtaFlag = -1;
7230
7231  if(type == "RP")
7232  {
7233   typeFlag = 0;
7234  } else if(type == "POI")
7235    {
7236     typeFlag = 1;
7237    } 
7238      
7239  if(ptOrEta == "Pt")
7240  {
7241   ptEtaFlag = 0;
7242  } else if(ptOrEta == "Eta")
7243    {
7244     ptEtaFlag = 1;
7245    } 
7246   
7247  // shortcuts:
7248  Int_t t = typeFlag;
7249  Int_t pe = ptEtaFlag;
7250      
7251  // common:
7252  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
7253    
7254  // correlations:
7255  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
7256  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
7257  
7258  // statistical errors of correlations:
7259  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1);
7260  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2);   
7261     
7262  // reduced correlations:
7263  Double_t twoReduced = 0.; // <<2'>>
7264  Double_t fourReduced = 0.; // <<4'>>
7265  
7266  // statistical errors of reduced correlations:
7267  Double_t twoReducedError = 0.; 
7268  Double_t fourReducedError = 0.; 
7269
7270  // covariances:
7271  Double_t wCovTwoFour = fIntFlowCovariances->GetBinContent(1);// // Cov(<2>,<4>) * prefactor(<2>,<4>)
7272  Double_t wCovTwoTwoReduced = 0.; // Cov(<2>,<2'>) * prefactor(<2>,<2'>)
7273  Double_t wCovTwoFourReduced = 0.; // Cov(<2>,<4'>) * prefactor(<2>,<4'>)
7274  Double_t wCovFourTwoReduced = 0.; // Cov(<4>,<2'>) * prefactor(<4>,<2'>)
7275  Double_t wCovFourFourReduced = 0.; // Cov(<4>,<4'>) * prefactor(<4>,<4'>)
7276  Double_t wCovTwoReducedFourReduced = 0.; // Cov(<2'>,<4'>) * prefactor(<2'>,<4'>)
7277  
7278  // differential flow:
7279  Double_t v2Prime = 0.; // v'{2}                   
7280  Double_t v4Prime = 0.; // v'{4}
7281  
7282  // statistical error of differential flow:
7283  Double_t v2PrimeError = 0.;                    
7284  Double_t v4PrimeError = 0.; 
7285  
7286  // squared statistical error of differential flow:
7287  Double_t v2PrimeErrorSquared = 0.;                    
7288  Double_t v4PrimeErrorSquared = 0.; 
7289  
7290  // loop over pt or eta bins:
7291  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
7292  {
7293   // reduced correlations and statistical errors:
7294   twoReduced = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b);
7295   twoReducedError = fDiffFlowCorrelationsHist[t][pe][0]->GetBinError(b);
7296   fourReduced = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b);
7297   fourReducedError = fDiffFlowCorrelationsHist[t][pe][1]->GetBinError(b);
7298   // covariances:
7299   wCovTwoTwoReduced = fDiffFlowCovariances[t][pe][0]->GetBinContent(b);
7300   wCovTwoFourReduced = fDiffFlowCovariances[t][pe][1]->GetBinContent(b);
7301   wCovFourTwoReduced = fDiffFlowCovariances[t][pe][2]->GetBinContent(b);
7302   wCovFourFourReduced = fDiffFlowCovariances[t][pe][3]->GetBinContent(b);
7303   wCovTwoReducedFourReduced = fDiffFlowCovariances[t][pe][4]->GetBinContent(b);
7304   // differential flow:
7305   // v'{2}:
7306   if(two>0.) 
7307   {
7308    v2Prime = twoReduced/pow(two,0.5);
7309    v2PrimeErrorSquared = (1./4.)*pow(two,-3.)*
7310                          (pow(twoReduced,2.)*pow(twoError,2.)
7311                           + 4.*pow(two,2.)*pow(twoReducedError,2.)
7312                           - 4.*two*twoReduced*wCovTwoTwoReduced);
7313      
7314                                                             
7315    if(v2PrimeErrorSquared>0.) v2PrimeError = pow(v2PrimeErrorSquared,0.5);
7316    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
7317    if(TMath::Abs(v2Prime)>1.e-44)fDiffFlow[t][pe][0]->SetBinError(b,v2PrimeError);     
7318   }
7319   // differential flow:
7320   // v'{4}
7321   if(2.*pow(two,2.)-four > 0.) 
7322   {
7323    v4Prime = (2.*two*twoReduced-fourReduced)/pow(2.*pow(two,2.)-four,3./4.);
7324    v4PrimeErrorSquared = pow(2.*pow(two,2.)-four,-7./2.)*
7325                          (pow(2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced,2.)*pow(twoError,2.)
7326                           + (9./16.)*pow(2.*two*twoReduced-fourReduced,2.)*pow(fourError,2.)
7327                           + 4.*pow(two,2.)*pow(2.*pow(two,2.)-four,2.)*pow(twoReducedError,2.)
7328                           + pow(2.*pow(two,2.)-four,2.)*pow(fourReducedError,2.)                          
7329                           - (3./2.)*(2.*two*twoReduced-fourReduced)
7330                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFour
7331                           - 4.*two*(2.*pow(two,2.)-four)
7332                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoTwoReduced
7333                           + 2.*(2.*pow(two,2.)-four)
7334                           * (2.*pow(two,2.)*twoReduced-3.*two*fourReduced+2.*four*twoReduced)*wCovTwoFourReduced
7335                           + 3.*two*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourTwoReduced
7336                           - (3./2.)*(2.*pow(two,2.)-four)*(2.*two*twoReduced-fourReduced)*wCovFourFourReduced 
7337                           - 4.*two*pow(2.*pow(two,2.)-four,2.)*wCovTwoReducedFourReduced);  
7338    if(v4PrimeErrorSquared>0.) v4PrimeError = pow(v4PrimeErrorSquared,0.5);        
7339    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime);
7340    if(TMath::Abs(v4Prime)>1.e-44)fDiffFlow[t][pe][1]->SetBinError(b,v4PrimeError);     
7341   }
7342   
7343  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
7344  
7345    
7346  
7347  
7348  /*
7349  // 2D:
7350  for(Int_t nua=0;nua<2;nua++)
7351  {
7352   for(Int_t p=1;p<=fnBinsPt;p++)
7353   {
7354    for(Int_t e=1;e<=fnBinsEta;e++) 
7355    { 
7356     // differential cumulants:
7357     Double_t qc2Prime = fFinalCumulants2D[t][pW][eW][nua][0]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e)); // QC{2'}                    
7358     Double_t qc4Prime = fFinalCumulants2D[t][pW][eW][nua][1]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e)); // QC{4'}
7359     // differential flow:
7360     Double_t v2Prime = 0.;                    
7361     Double_t v4Prime = 0.; 
7362     if(v2) 
7363     {
7364      v2Prime = qc2Prime/v2;
7365      fFinalFlow2D[t][pW][eW][nua][0]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][0]->GetBin(p,e),v2Prime);  
7366     }                   
7367     if(v4)
7368     {
7369      v4Prime = -qc4Prime/pow(v4,3.); 
7370      fFinalFlow2D[t][pW][eW][nua][1]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][1]->GetBin(p,e),v4Prime);  
7371     }                    
7372    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
7373   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
7374  } // end of for(Int_t nua=0;nua<2;nua++)
7375  */
7376
7377 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights)
7378
7379 //================================================================================================================================
7380
7381 void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
7382 {
7383  // a) Store all flags for integrated flow in profile fIntFlowFlags.
7384  
7385  if(!fIntFlowFlags)
7386  {
7387   cout<<"WARNING: fIntFlowFlags is NULL in AFAWQC::SFFIF() !!!!"<<endl;
7388   exit(0);
7389  } 
7390
7391  // particle weights used or not:
7392  fIntFlowFlags->Fill(0.5,(Int_t)fUsePhiWeights||fUsePtWeights||fUseEtaWeights);
7393  // which event weights were used:
7394  if(strcmp(fMultiplicityWeight->Data(),"combinations"))
7395  {
7396   fIntFlowFlags->Fill(1.5,0); // 0 = "combinations" (default)
7397  } else if(strcmp(fMultiplicityWeight->Data(),"unit"))
7398    {
7399     fIntFlowFlags->Fill(1.5,1); // 1 = "unit"   
7400    } else if(strcmp(fMultiplicityWeight->Data(),"multiplicity"))
7401      {
7402       fIntFlowFlags->Fill(1.5,2); // 2 = "multiplicity"        
7403      } 
7404  // corrected for non-uniform acceptance or not:
7405  fIntFlowFlags->Fill(2.5,(Int_t)fApplyCorrectionForNUA);
7406  fIntFlowFlags->Fill(3.5,(Int_t)fPrintFinalResults[0]);
7407  fIntFlowFlags->Fill(4.5,(Int_t)fPrintFinalResults[1]);
7408  fIntFlowFlags->Fill(5.5,(Int_t)fPrintFinalResults[2]);
7409  fIntFlowFlags->Fill(6.5,(Int_t)fPrintFinalResults[3]);
7410  fIntFlowFlags->Fill(7.5,(Int_t)fApplyCorrectionForNUAVsM);
7411  fIntFlowFlags->Fill(8.5,(Int_t)fPropagateErrorFromCorrelations);
7412  fIntFlowFlags->Fill(9.5,(Int_t)fCalculateCumulantsVsM);
7413  fIntFlowFlags->Fill(10.5,(Int_t)fMinimumBiasReferenceFlow);
7414  
7415 } // end of void AliFlowAnalysisWithQCumulants::StoreIntFlowFlags()
7416
7417 //================================================================================================================================
7418
7419 void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
7420 {
7421  // Store all flags for differential flow in the profile fDiffFlowFlags.
7422   
7423  if(!fDiffFlowFlags)
7424  {
7425   cout<<"WARNING: fDiffFlowFlags is NULL in AFAWQC::SFFDF() !!!!"<<endl;
7426   exit(0);
7427  } 
7428  
7429  fDiffFlowFlags->Fill(0.5,fUsePhiWeights||fUsePtWeights||fUseEtaWeights); // particle weights used or not
7430  //fDiffFlowFlags->Fill(1.5,""); // which event weight was used? // to be improved
7431  fDiffFlowFlags->Fill(2.5,fApplyCorrectionForNUA); // corrected for non-uniform acceptance or not
7432  fDiffFlowFlags->Fill(3.5,fCalculate2DFlow); // calculate also 2D differential flow in (pt,eta) or not
7433     
7434 } // end of void AliFlowAnalysisWithQCumulants::StoreDiffFlowFlags()
7435
7436
7437 //================================================================================================================================
7438
7439
7440 void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
7441 {
7442  // Access all pointers to common control and common result histograms and profiles.
7443  
7444  TString commonHistsName = "AliFlowCommonHistQC";
7445  commonHistsName += fAnalysisLabel->Data();
7446  AliFlowCommonHist *commonHist = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHistsName.Data()));
7447  if(commonHist) this->SetCommonHists(commonHist); 
7448  TString commonHists2ndOrderName = "AliFlowCommonHist2ndOrderQC";
7449  commonHists2ndOrderName += fAnalysisLabel->Data();
7450  AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists2ndOrderName.Data()));
7451  if(commonHist2nd) this->SetCommonHists2nd(commonHist2nd);   
7452  TString commonHists4thOrderName = "AliFlowCommonHist4thOrderQC";
7453  commonHists4thOrderName += fAnalysisLabel->Data();
7454  AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists4thOrderName.Data()));
7455  if(commonHist4th) this->SetCommonHists4th(commonHist4th);  
7456  TString commonHists6thOrderName = "AliFlowCommonHist6thOrderQC";
7457  commonHists6thOrderName += fAnalysisLabel->Data();
7458  AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists6thOrderName.Data()));
7459  if(commonHist6th) this->SetCommonHists6th(commonHist6th);  
7460  TString commonHists8thOrderName = "AliFlowCommonHist8thOrderQC";
7461  commonHists8thOrderName += fAnalysisLabel->Data();
7462  AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(fHistList->FindObject(commonHists8thOrderName.Data()));
7463  if(commonHist8th) this->SetCommonHists8th(commonHist8th);  
7464  TString commonHistResults2ndOrderName = "AliFlowCommonHistResults2ndOrderQC"; 
7465  commonHistResults2ndOrderName += fAnalysisLabel->Data(); 
7466  AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>                                              (fHistList->FindObject(commonHistResults2ndOrderName.Data()));
7467  if(commonHistRes2nd) this->SetCommonHistsResults2nd(commonHistRes2nd);   
7468  TString commonHistResults4thOrderName = "AliFlowCommonHistResults4thOrderQC";
7469  commonHistResults4thOrderName += fAnalysisLabel->Data();
7470  AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>
7471                                               (fHistList->FindObject(commonHistResults4thOrderName.Data()));
7472  if(commonHistRes4th) this->SetCommonHistsResults4th(commonHistRes4th);  
7473  TString commonHistResults6thOrderName = "AliFlowCommonHistResults6thOrderQC";
7474  commonHistResults6thOrderName += fAnalysisLabel->Data();
7475  AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>
7476                                               (fHistList->FindObject(commonHistResults6thOrderName.Data()));
7477  if(commonHistRes6th) this->SetCommonHistsResults6th(commonHistRes6th);  
7478  TString commonHistResults8thOrderName = "AliFlowCommonHistResults8thOrderQC";
7479  commonHistResults8thOrderName += fAnalysisLabel->Data();
7480  AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>
7481                                               (fHistList->FindObject(commonHistResults8thOrderName.Data()));  
7482  if(commonHistRes8th) this->SetCommonHistsResults8th(commonHistRes8th);
7483        
7484 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForCommonHistograms() 
7485
7486
7487 //================================================================================================================================
7488
7489
7490 void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms() 
7491 {
7492  // Get pointers for histograms with particle weights.
7493
7494  TList *weightsList = dynamic_cast<TList*>(fHistList->FindObject("Weights"));
7495  if(weightsList) this->SetWeightsList(weightsList);
7496  TString fUseParticleWeightsName = "fUseParticleWeightsQC"; // to be improved (hirdwired label QC)
7497  fUseParticleWeightsName += fAnalysisLabel->Data();
7498  TProfile *useParticleWeights = dynamic_cast<TProfile*>(weightsList->FindObject(fUseParticleWeightsName.Data()));
7499  if(useParticleWeights)
7500  {
7501   this->SetUseParticleWeights(useParticleWeights);  
7502   fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
7503   fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
7504   fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3);  
7505  }
7506 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForParticleWeightsHistograms(); 
7507
7508
7509 //================================================================================================================================
7510
7511
7512 void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms() 
7513 {
7514  // Get pointers for histograms and profiles relevant for integrated flow:
7515  //  a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults.
7516  //  b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow.
7517  //  c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds. 
7518  //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
7519   
7520  TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data member?)
7521  TString powerFlag[2] = {"linear","quadratic"}; // to be improved (should I promote this to data member?)
7522  TString correlationFlag[4] = {"<<2>>","<<4>>","<<6>>","<<8>>"}; // to be improved (should I promote this to data member?)
7523  
7524  // a) Get pointer to base list for integrated flow holding profile fIntFlowFlags and lists fIntFlowProfiles and fIntFlowResults:
7525  TList *intFlowList = NULL;
7526  intFlowList = dynamic_cast<TList*>(fHistList->FindObject("Integrated Flow"));
7527  if(!intFlowList) 
7528  {
7529   cout<<"WARNING: intFlowList is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7530   exit(0); 
7531  }  
7532   
7533   // b) Get pointer to profile fIntFlowFlags holding all flags for integrated flow:
7534   TString intFlowFlagsName = "fIntFlowFlags";
7535   intFlowFlagsName += fAnalysisLabel->Data();
7536   TProfile *intFlowFlags = dynamic_cast<TProfile*>(intFlowList->FindObject(intFlowFlagsName.Data()));
7537   if(intFlowFlags)
7538   {
7539    this->SetIntFlowFlags(intFlowFlags);  
7540    fApplyCorrectionForNUA = (Bool_t)intFlowFlags->GetBinContent(3); // to be improved (hardwired 3)
7541    fCalculateCumulantsVsM = (Bool_t)intFlowFlags->GetBinContent(10); // to be improved (hardwired 9)  
7542   } else 
7543     {
7544      cout<<"WARNING: intFlowFlags is NULL in FAWQC::GPFIFH() !!!!"<<endl;
7545     }
7546   
7547   // c) Get pointer to list fIntFlowProfiles and pointers to all objects that she holds:
7548   TList *intFlowProfiles = NULL;
7549   intFlowProfiles = dynamic_cast<TList*>(intFlowList->FindObject("Profiles"));
7550   if(intFlowProfiles)  
7551   {
7552    // average multiplicities:
7553    TString avMultiplicityName = "fAvMultiplicity";
7554    avMultiplicityName += fAnalysisLabel->Data();
7555    TProfile *avMultiplicity = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(avMultiplicityName.Data()));
7556    if(avMultiplicity) 
7557    {
7558     this->SetAvMultiplicity(avMultiplicity);
7559    } else 
7560      {
7561       cout<<"WARNING: avMultiplicity is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7562      }
7563    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with wrong errors!):
7564    TString intFlowCorrelationsProName = "fIntFlowCorrelationsPro";
7565    intFlowCorrelationsProName += fAnalysisLabel->Data();
7566    TProfile *intFlowCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsProName.Data()));
7567    if(intFlowCorrelationsPro) 
7568    {
7569     this->SetIntFlowCorrelationsPro(intFlowCorrelationsPro);
7570    } else 
7571      {
7572       cout<<"WARNING: intFlowCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7573      }      
7574    // average correlations <<2>>, <<4>>, <<6>> and <<8>> versus multiplicity for all events (error is wrong here):
7575    if(fCalculateCumulantsVsM)
7576    {
7577     TString intFlowCorrelationsVsMProName = "fIntFlowCorrelationsVsMPro";
7578     intFlowCorrelationsVsMProName += fAnalysisLabel->Data();
7579     for(Int_t ci=0;ci<4;ci++) // correlation index
7580     {
7581      TProfile *intFlowCorrelationsVsMPro = dynamic_cast<TProfile*>
7582                                         (intFlowProfiles->FindObject(Form("%s, %s",intFlowCorrelationsVsMProName.Data(),correlationFlag[ci].Data())));
7583      if(intFlowCorrelationsVsMPro)
7584      {
7585       this->SetIntFlowCorrelationsVsMPro(intFlowCorrelationsVsMPro,ci);
7586      } else
7587        {
7588         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMPro[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7589        }   
7590     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index 
7591    } // end of if(fCalculateCumulantsVsM)
7592    // average all correlations for integrated flow (with wrong errors!):
7593    TString intFlowCorrelationsAllProName = "fIntFlowCorrelationsAllPro";
7594    intFlowCorrelationsAllProName += fAnalysisLabel->Data();
7595    TProfile *intFlowCorrelationsAllPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowCorrelationsAllProName.Data()));
7596    if(intFlowCorrelationsAllPro) 
7597    {
7598     this->SetIntFlowCorrelationsAllPro(intFlowCorrelationsAllPro);
7599    } else 
7600      {
7601       cout<<"WARNING: intFlowCorrelationsAllPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7602      }     
7603    // average extra correlations for integrated flow (which appear only when particle weights are used):
7604    // (to be improved: Weak point in implementation, I am assuming here that method GetPointersForParticleWeightsHistograms() was called)
7605    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
7606    {
7607     TString intFlowExtraCorrelationsProName = "fIntFlowExtraCorrelationsPro";
7608     intFlowExtraCorrelationsProName += fAnalysisLabel->Data();
7609     TProfile *intFlowExtraCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowExtraCorrelationsProName.Data()));
7610     if(intFlowExtraCorrelationsPro) 
7611     {
7612      this->SetIntFlowExtraCorrelationsPro(intFlowExtraCorrelationsPro);
7613     } else 
7614       {
7615        cout<<"WARNING: intFlowExtraCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7616       }
7617    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)        
7618    // average products of correlations <2>, <4>, <6> and <8>:  
7619    TString intFlowProductOfCorrelationsProName = "fIntFlowProductOfCorrelationsPro";
7620    intFlowProductOfCorrelationsProName += fAnalysisLabel->Data();
7621    TProfile *intFlowProductOfCorrelationsPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrelationsProName.Data()));
7622    if(intFlowProductOfCorrelationsPro) 
7623    {
7624     this->SetIntFlowProductOfCorrelationsPro(intFlowProductOfCorrelationsPro);
7625    } else 
7626      {
7627       cout<<"WARNING: intFlowProductOfCorrelationsPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7628      }               
7629    // average product of correlations <2>, <4>, <6> and <8> versus multiplicity  
7630    // [0=<<2><4>>,1=<<2><6>>,2=<<2><8>>,3=<<4><6>>,4=<<4><8>>,5=<<6><8>>]  
7631    if(fCalculateCumulantsVsM)
7632    {
7633     TString intFlowProductOfCorrelationsVsMProName = "fIntFlowProductOfCorrelationsVsMPro";
7634     intFlowProductOfCorrelationsVsMProName += fAnalysisLabel->Data();
7635     TString productFlag[6] = {"<<2><4>>","<<2><6>>","<<2><8>>","<<4><6>>","<<4><8>>","<<6><8>>"};
7636     for(Int_t pi=0;pi<6;pi++)
7637     { 
7638      TProfile *intFlowProductOfCorrelationsVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s, %s",intFlowProductOfCorrelationsVsMProName.Data(),productFlag[pi].Data())));
7639      if(intFlowProductOfCorrelationsVsMPro)
7640      {
7641       this->SetIntFlowProductOfCorrelationsVsMPro(intFlowProductOfCorrelationsVsMPro,pi);
7642      } else
7643        {
7644         cout<<"WARNING: "<<Form("intFlowProductOfCorrelationsVsMPro[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7645        }
7646     } // end of for(Int_t pi=0;pi<6;pi++)
7647    } // end of if(fCalculateCumulantsVsM)
7648    // average correction terms for non-uniform acceptance (with wrong errors!):
7649    for(Int_t sc=0;sc<2;sc++)
7650    {
7651     TString intFlowCorrectionTermsForNUAProName = "fIntFlowCorrectionTermsForNUAPro";
7652     intFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
7653     TProfile *intFlowCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAProName.Data(),sinCosFlag[sc].Data()))));
7654     if(intFlowCorrectionTermsForNUAPro) 
7655     {
7656      this->SetIntFlowCorrectionTermsForNUAPro(intFlowCorrectionTermsForNUAPro,sc);
7657     } else 
7658       {
7659        cout<<"WARNING: intFlowCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7660        cout<<"sc = "<<sc<<endl;
7661       } 
7662     // versus multiplicity:
7663     if(fCalculateCumulantsVsM)
7664     {
7665      TString correctionTermFlag[4] = {"(n(phi1))","(n(phi1+phi2))","(n(phi1-phi2-phi3))","(n(2phi1-phi2))"}; // to be improved - hardwired 4
7666      TString intFlowCorrectionTermsForNUAVsMProName = "fIntFlowCorrectionTermsForNUAVsMPro";
7667      intFlowCorrectionTermsForNUAVsMProName += fAnalysisLabel->Data();
7668      for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
7669      {
7670       TProfile *intFlowCorrectionTermsForNUAVsMPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("%s: #LT#LT%s%s#GT#GT",intFlowCorrectionTermsForNUAVsMProName.Data(),sinCosFlag[sc].Data(),correctionTermFlag[ci].Data())));
7671       if(intFlowCorrectionTermsForNUAVsMPro) 
7672       {
7673        this->SetIntFlowCorrectionTermsForNUAVsMPro(intFlowCorrectionTermsForNUAVsMPro,sc,ci);
7674       } else 
7675         {
7676          cout<<"WARNING: intFlowCorrectionTermsForNUAVsMPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7677          cout<<"sc = "<<sc<<endl;
7678          cout<<"ci = "<<ci<<endl;
7679         }       
7680      } // end of for(Int_t ci=0;ci<4;ci++) // correction term index (to be improved - hardwired 4)
7681     } // end of if(fCalculateCumulantsVsM)
7682    } // end of for(Int_t sc=0;sc<2;sc++)           
7683    // average products of correction terms for NUA:  
7684    TString intFlowProductOfCorrectionTermsForNUAProName = "fIntFlowProductOfCorrectionTermsForNUAPro";
7685    intFlowProductOfCorrectionTermsForNUAProName += fAnalysisLabel->Data();
7686    TProfile *intFlowProductOfCorrectionTermsForNUAPro = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(intFlowProductOfCorrectionTermsForNUAProName.Data()));
7687    if(intFlowProductOfCorrectionTermsForNUAPro) 
7688    {
7689     this->SetIntFlowProductOfCorrectionTermsForNUAPro(intFlowProductOfCorrectionTermsForNUAPro);
7690    } else 
7691      {
7692       cout<<"WARNING: intFlowProductOfCorrectionTermsForNUAPro is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7693      }     
7694   } else // to if(intFlowProfiles)  
7695     {
7696      cout<<"WARNING: intFlowProfiles is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7697     }
7698    
7699   //  d) Get pointer to list fIntFlowResults and pointers to all objects that she holds. 
7700   TList *intFlowResults = NULL;
7701   intFlowResults = dynamic_cast<TList*>(intFlowList->FindObject("Results"));
7702   if(intFlowResults)
7703   {
7704    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!):
7705    TString intFlowCorrelationsHistName = "fIntFlowCorrelationsHist";
7706    intFlowCorrelationsHistName += fAnalysisLabel->Data();
7707    TH1D *intFlowCorrelationsHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsHistName.Data()));
7708    if(intFlowCorrelationsHist) 
7709    {
7710     this->SetIntFlowCorrelationsHist(intFlowCorrelationsHist);
7711    } else 
7712      {
7713       cout<<"WARNING: intFlowCorrelationsHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7714      } 
7715    // average correlations <<2>>, <<4>>, <<6>> and <<8>> (with correct errors!) vs M:    
7716    if(fCalculateCumulantsVsM)
7717    {
7718     TString intFlowCorrelationsVsMHistName = "fIntFlowCorrelationsVsMHist";
7719     intFlowCorrelationsVsMHistName += fAnalysisLabel->Data();
7720     for(Int_t ci=0;ci<4;ci++) // correlation index
7721     {
7722      TH1D *intFlowCorrelationsVsMHist = dynamic_cast<TH1D*>
7723                                         (intFlowResults->FindObject(Form("%s, %s",intFlowCorrelationsVsMHistName.Data(),correlationFlag[ci].Data())));
7724      if(intFlowCorrelationsVsMHist)
7725      {
7726       this->SetIntFlowCorrelationsVsMHist(intFlowCorrelationsVsMHist,ci);
7727      } else
7728        {
7729         cout<<"WARNING: "<<Form("intFlowCorrelationsVsMHist[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7730        }   
7731     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
7732    } // end of if(fCalculateCumulantsVsM)
7733    // average all correlations for integrated flow (with correct errors!):
7734    TString intFlowCorrelationsAllHistName = "fIntFlowCorrelationsAllHist";
7735    intFlowCorrelationsAllHistName += fAnalysisLabel->Data();
7736    TH1D *intFlowCorrelationsAllHist = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCorrelationsAllHistName.Data()));
7737    if(intFlowCorrelationsAllHist) 
7738    {
7739     this->SetIntFlowCorrelationsAllHist(intFlowCorrelationsAllHist);
7740    } else 
7741      {
7742       cout<<"WARNING: intFlowCorrelationsAllHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7743      }  
7744    // average correction terms for non-uniform acceptance (with correct errors!):
7745    TString intFlowCorrectionTermsForNUAHistName = "fIntFlowCorrectionTermsForNUAHist";
7746    intFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
7747    for(Int_t sc=0;sc<2;sc++)
7748    {
7749     TH1D *intFlowCorrectionTermsForNUAHist = dynamic_cast<TH1D*>(intFlowResults->FindObject((Form("%s: %s terms",intFlowCorrectionTermsForNUAHistName.Data(),sinCosFlag[sc].Data()))));
7750     if(intFlowCorrectionTermsForNUAHist) 
7751     {
7752      this->SetIntFlowCorrectionTermsForNUAHist(intFlowCorrectionTermsForNUAHist,sc);
7753     } else 
7754       {
7755        cout<<"WARNING: intFlowCorrectionTermsForNUAHist is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7756        cout<<"sc = "<<sc<<endl;
7757       } 
7758    } // end of for(Int_t sc=0;sc<2;sc++)           
7759    // covariances (multiplied with weight dependent prefactor):
7760    TString intFlowCovariancesName = "fIntFlowCovariances";
7761    intFlowCovariancesName += fAnalysisLabel->Data();
7762    TH1D *intFlowCovariances = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesName.Data()));
7763    if(intFlowCovariances) 
7764    {
7765     this->SetIntFlowCovariances(intFlowCovariances); 
7766    } else 
7767      {
7768       cout<<"WARNING: intFlowCovariances is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7769      } 
7770    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8>:
7771    TString intFlowSumOfEventWeightsName = "fIntFlowSumOfEventWeights";
7772    intFlowSumOfEventWeightsName += fAnalysisLabel->Data();
7773    for(Int_t power=0;power<2;power++)
7774    {
7775     TH1D *intFlowSumOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s",intFlowSumOfEventWeightsName.Data(),powerFlag[power].Data())));
7776     if(intFlowSumOfEventWeights) 
7777     {
7778      this->SetIntFlowSumOfEventWeights(intFlowSumOfEventWeights,power);
7779     } else 
7780       {
7781        cout<<"WARNING: intFlowSumOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7782        cout<<"power = "<<power<<endl;
7783       }                                   
7784    } // end of for(Int_t power=0;power<2;power++)                                                                  
7785    // sum of products of event weights for correlations <2>, <4>, <6> and <8>:  
7786    TString intFlowSumOfProductOfEventWeightsName = "fIntFlowSumOfProductOfEventWeights";
7787    intFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();
7788    TH1D *intFlowSumOfProductOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsName.Data()));
7789    if(intFlowSumOfProductOfEventWeights) 
7790    {
7791     this->SetIntFlowSumOfProductOfEventWeights(intFlowSumOfProductOfEventWeights);
7792    } else 
7793      {
7794       cout<<"WARNING: intFlowSumOfProductOfEventWeights is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7795      } 
7796    // final result for covariances of correlations (multiplied with weight dependent prefactor) versus M
7797    // [0=Cov(2,4),1=Cov(2,6),2=Cov(2,8),3=Cov(4,6),4=Cov(4,8),5=Cov(6,8)]:
7798    if(fCalculateCumulantsVsM)
7799    {
7800     TString intFlowCovariancesVsMName = "fIntFlowCovariancesVsM";
7801     intFlowCovariancesVsMName += fAnalysisLabel->Data();
7802     TString covarianceFlag[6] = {"Cov(<2>,<4>)","Cov(<2>,<6>)","Cov(<2>,<8>)","Cov(<4>,<6>)","Cov(<4>,<8>)","Cov(<6>,<8>)"};
7803     for(Int_t ci=0;ci<6;ci++)
7804     { 
7805      TH1D *intFlowCovariancesVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowCovariancesVsMName.Data(),covarianceFlag[ci].Data())));
7806      if(intFlowCovariancesVsM)
7807      {
7808       this->SetIntFlowCovariancesVsM(intFlowCovariancesVsM,ci);
7809      } else
7810        {
7811         cout<<"WARNING: "<<Form("intFlowCovariancesVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7812        }    
7813     } // end of for(Int_t ci=0;ci<6;ci++)
7814    } // end of if(fCalculateCumulantsVsM)
7815    // sum of linear and quadratic event weights for <2>, <4>, <6> and <8> versus multiplicity
7816    // [0=sum{w_{<2>}},1=sum{w_{<4>}},2=sum{w_{<6>}},3=sum{w_{<8>}}][0=linear 1,1=quadratic]:
7817    if(fCalculateCumulantsVsM)
7818    {
7819     TString intFlowSumOfEventWeightsVsMName = "fIntFlowSumOfEventWeightsVsM";
7820     intFlowSumOfEventWeightsVsMName += fAnalysisLabel->Data();
7821     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>}"},
7822                              {"#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}"}};
7823     for(Int_t si=0;si<4;si++)
7824     {
7825      for(Int_t power=0;power<2;power++)
7826      {
7827       TH1D *intFlowSumOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfEventWeightsVsMName.Data(),sumFlag[power][si].Data())));
7828       if(intFlowSumOfEventWeightsVsM)
7829       {
7830        this->SetIntFlowSumOfEventWeightsVsM(intFlowSumOfEventWeightsVsM,si,power);
7831       } else
7832         {
7833          cout<<"WARNING: "<<Form("intFlowSumOfEventWeightsVsM[%d][%d]",si,power)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7834         }    
7835      } // end of for(Int_t power=0;power<2;power++)
7836     } // end of for(Int_t si=0;si<4;si++)   
7837    } // end of if(fCalculateCumulantsVsM)
7838    // sum of products of event weights for correlations <2>, <4>, <6> and <8> vs M
7839    // [0=sum{w_{<2>}w_{<4>}},1=sum{w_{<2>}w_{<6>}},2=sum{w_{<2>}w_{<8>}},
7840    //  3=sum{w_{<4>}w_{<6>}},4=sum{w_{<4>}w_{<8>}},5=sum{w_{<6>}w_{<8>}}]:  
7841    if(fCalculateCumulantsVsM)
7842    {
7843     TString intFlowSumOfProductOfEventWeightsVsMName = "fIntFlowSumOfProductOfEventWeightsVsM";
7844     intFlowSumOfProductOfEventWeightsVsMName += fAnalysisLabel->Data();
7845     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>}",
7846                             "#sum_{i=1}^{N} w_{<4>} w_{<6>}","#sum_{i=1}^{N} w_{<4>} w_{<8>}","#sum_{i=1}^{N} w_{<6>} w_{<8>}"}; 
7847     for(Int_t pi=0;pi<6;pi++)
7848     {
7849      TH1D *intFlowSumOfProductOfEventWeightsVsM = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s, %s",intFlowSumOfProductOfEventWeightsVsMName.Data(),sopowFlag[pi].Data())));
7850      if(intFlowSumOfProductOfEventWeightsVsM)
7851      {
7852       this->SetIntFlowSumOfProductOfEventWeightsVsM(intFlowSumOfProductOfEventWeightsVsM,pi);
7853      } else
7854        {
7855         cout<<"WARNING: "<<Form("intFlowSumOfProductOfEventWeightsVsM[%d]",pi)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7856        }
7857     } // end of for(Int_t pi=0;pi<6;pi++)        
7858    } // end of if(fCalculateCumulantsVsM)
7859    // covariances for NUA (multiplied with weight dependent prefactor):
7860    TString intFlowCovariancesNUAName = "fIntFlowCovariancesNUA";
7861    intFlowCovariancesNUAName += fAnalysisLabel->Data();
7862    TH1D *intFlowCovariancesNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowCovariancesNUAName.Data()));
7863    if(intFlowCovariancesNUA) 
7864    {
7865     this->SetIntFlowCovariancesNUA(intFlowCovariancesNUA); 
7866    } else 
7867      {
7868       cout<<"WARNING: intFlowCovariancesNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7869      } 
7870    // sum of linear and quadratic event weights NUA terms:
7871    TString intFlowSumOfEventWeightsNUAName = "fIntFlowSumOfEventWeightsNUA";
7872    intFlowSumOfEventWeightsNUAName += fAnalysisLabel->Data();
7873    for(Int_t sc=0;sc<2;sc++)
7874    {
7875     for(Int_t power=0;power<2;power++)
7876     {
7877      TH1D *intFlowSumOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("%s: %s, %s",intFlowSumOfEventWeightsNUAName.Data(),powerFlag[power].Data(),sinCosFlag[sc].Data())));
7878      if(intFlowSumOfEventWeightsNUA) 
7879      {
7880       this->SetIntFlowSumOfEventWeightsNUA(intFlowSumOfEventWeightsNUA,sc,power);
7881      } else 
7882        {
7883         cout<<"WARNING: intFlowSumOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7884         cout<<"sc    = "<<sc<<endl;
7885         cout<<"power = "<<power<<endl;
7886        }                                   
7887     } // end of for(Int_t power=0;power<2;power++)                                                                  
7888    } // end of for(Int_t sc=0;sc<2;sc++)     
7889    // sum of products of event weights for NUA terms:  
7890    TString intFlowSumOfProductOfEventWeightsNUAName = "fIntFlowSumOfProductOfEventWeightsNUA";
7891    intFlowSumOfProductOfEventWeightsNUAName += fAnalysisLabel->Data();
7892    TH1D *intFlowSumOfProductOfEventWeightsNUA = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowSumOfProductOfEventWeightsNUAName.Data()));
7893    if(intFlowSumOfProductOfEventWeightsNUA) 
7894    {
7895     this->SetIntFlowSumOfProductOfEventWeightsNUA(intFlowSumOfProductOfEventWeightsNUA);
7896    } else 
7897      {
7898       cout<<"WARNING: intFlowSumOfProductOfEventWeightsNUA is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7899      } 
7900    // Final results for reference Q-cumulants:
7901    TString intFlowQcumulantsName = "fIntFlowQcumulants";
7902    intFlowQcumulantsName += fAnalysisLabel->Data();
7903    TH1D *intFlowQcumulants = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsName.Data()));
7904    if(intFlowQcumulants) 
7905    {
7906     this->SetIntFlowQcumulants(intFlowQcumulants);
7907    } else 
7908      {
7909       cout<<"WARNING: intFlowQcumulants is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7910      }  
7911    // Final results for reference Q-cumulants rebinned in M:
7912    if(fCalculateCumulantsVsM)
7913    {
7914     TString intFlowQcumulantsRebinnedInMName = "fIntFlowQcumulantsRebinnedInM";
7915     intFlowQcumulantsRebinnedInMName += fAnalysisLabel->Data();
7916     TH1D *intFlowQcumulantsRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowQcumulantsRebinnedInMName.Data()));
7917     if(intFlowQcumulantsRebinnedInM) 
7918     {
7919      this->SetIntFlowQcumulantsRebinnedInM(intFlowQcumulantsRebinnedInM);
7920     } else 
7921       {
7922        cout<<"WARNING: intFlowQcumulantsRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7923       }  
7924    } // end of if(fCalculateCumulantsVsM)
7925    // final results for integrated Q-cumulants versus multiplicity:
7926    TString cumulantFlag[4] = {"QC{2}","QC{4}","QC{6}","QC{8}"};
7927    if(fCalculateCumulantsVsM)
7928    {
7929     TString intFlowQcumulantsVsMName = "fIntFlowQcumulantsVsM";
7930     intFlowQcumulantsVsMName += fAnalysisLabel->Data();
7931     for(Int_t co=0;co<4;co++) // cumulant order
7932     {
7933      TH1D *intFlowQcumulantsVsM = dynamic_cast<TH1D*>
7934                                   (intFlowResults->FindObject(Form("%s, %s",intFlowQcumulantsVsMName.Data(),cumulantFlag[co].Data())));
7935      if(intFlowQcumulantsVsM)
7936      {
7937       this->SetIntFlowQcumulantsVsM(intFlowQcumulantsVsM,co);
7938      } else
7939        {
7940         cout<<"WARNING: "<<Form("intFlowQcumulantsVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
7941        }
7942     } // end of for(Int_t co=0;co<4;co++) // cumulant order
7943    } // end of if(fCalculateCumulantsVsM)
7944    // Final reference flow estimates from Q-cumulants:
7945    TString intFlowName = "fIntFlow";
7946    intFlowName += fAnalysisLabel->Data();
7947    TH1D *intFlow = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowName.Data()));
7948    if(intFlow) 
7949    {
7950     this->SetIntFlow(intFlow);
7951    } else 
7952      {
7953       cout<<"WARNING: intFlow is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
7954      } 
7955    // Final reference flow estimates from Q-cumulants vs M rebinned in M:
7956    if(fCalculateCumulantsVsM)
7957    {
7958     TString intFlowRebinnedInMName = "fIntFlowRebinnedInM";
7959     intFlowRebinnedInMName += fAnalysisLabel->Data();
7960     TH1D *intFlowRebinnedInM = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowRebinnedInMName.Data()));
7961     if(intFlowRebinnedInM) 
7962     {
7963      this->SetIntFlowRebinnedInM(intFlowRebinnedInM);
7964     } else 
7965       {
7966        cout<<"WARNING: intFlowRebinnedInM is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
7967       } 
7968    } // end of if(fCalculateCumulantsVsM)
7969    // integrated flow from Q-cumulants versus multiplicity:
7970    if(fCalculateCumulantsVsM)
7971    {
7972     TString intFlowVsMName = "fIntFlowVsM";
7973     intFlowVsMName += fAnalysisLabel->Data();
7974     TString flowFlag[4] = {"v_{2}{2,QC}","v_{2}{4,QC}","v_{2}{6,QC}","v_{2}{8,QC}"}; // to be improved (harwired harmonic)
7975     for(Int_t co=0;co<4;co++) // cumulant order
7976     {
7977      TH1D *intFlowVsM = dynamic_cast<TH1D*>
7978                         (intFlowResults->FindObject(Form("%s, %s",intFlowVsMName.Data(),flowFlag[co].Data())));
7979      if(intFlowVsM)
7980      {
7981       this->SetIntFlowVsM(intFlowVsM,co);
7982      } else
7983        {
7984         cout<<"WARNING: "<<Form("intFlowVsM[%d]",co)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
7985        }
7986     } // end of for(Int_t co=0;co<4;co++) // cumulant order
7987    } // end of if(fCalculateCumulantsVsM)
7988    // quantifying detector effects effects to correlations:
7989    TString intFlowDetectorBiasName = "fIntFlowDetectorBias";
7990    intFlowDetectorBiasName += fAnalysisLabel->Data();
7991    TH1D *intFlowDetectorBias = dynamic_cast<TH1D*>(intFlowResults->FindObject(intFlowDetectorBiasName.Data()));
7992    if(intFlowDetectorBias) 
7993    {
7994     this->SetIntFlowDetectorBias(intFlowDetectorBias);
7995    } else 
7996      {
7997       cout<<"WARNING: intFlowDetectorBias is NULL in AFAWQC::GPFIFH() !!!!"<<endl; 
7998      } 
7999    // quantifying detector effects effects to correlations vs multiplicity:
8000    if(fApplyCorrectionForNUAVsM && fCalculateCumulantsVsM)
8001    {
8002     TString intFlowDetectorBiasVsMName = "fIntFlowDetectorBiasVsM";
8003     intFlowDetectorBiasVsMName += fAnalysisLabel->Data();
8004     for(Int_t ci=0;ci<4;ci++) // correlation index
8005     {
8006      TH1D *intFlowDetectorBiasVsM = dynamic_cast<TH1D*>
8007                                     (intFlowResults->FindObject(Form("%s for %s",intFlowDetectorBiasVsMName.Data(),cumulantFlag[ci].Data())));
8008      if(intFlowDetectorBiasVsM)
8009      {
8010       this->SetIntFlowDetectorBiasVsM(intFlowDetectorBiasVsM,ci);
8011      } else
8012        {
8013         cout<<"WARNING: "<<Form("intFlowDetectorBiasVsM[%d]",ci)<<" is NULL in AFAWQC::GPFIFH() !!!!"<<endl;      
8014        }
8015     } // end of for(Int_t ci=0;ci<4;ci++) // correlation index   
8016    } // end of if(ApplyCorrectionForNUAVsM)
8017   } else // to if(intFlowResults)
8018     {
8019      cout<<"WARNING: intFlowResults is NULL in AFAWQC::GPFIFH() !!!!"<<endl;
8020     }
8021     
8022 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForIntFlowHistograms()
8023
8024 //================================================================================================================================
8025
8026 void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
8027 {
8028  // Get pointer to all objects relevant for differential flow.
8029  //  a) Define flags locally (to be improved: should I promote flags to data members?);
8030  //  b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults;
8031  //  c) Get pointer to profile fDiffFlowFlags holding all flags for differential flow;
8032  //  d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
8033  //  e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
8034  
8035  // a) Define flags locally (to be improved: should I promote flags to data members?): 
8036  TString typeFlag[2] = {"RP","POI"}; 
8037  TString ptEtaFlag[2] = {"p_{T}","#eta"};
8038  TString powerFlag[2] = {"linear","quadratic"};
8039  TString sinCosFlag[2] = {"sin","cos"};
8040  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
8041  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
8042  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
8043  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
8044  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
8045   
8046  // b) Get pointer to base list for differential flow fDiffFlowList and nested lists fDiffFlowListProfiles and fDiffFlowListResults:
8047  TList *diffFlowList = NULL;
8048  diffFlowList = dynamic_cast<TList*>(fHistList->FindObject("Differential Flow"));  
8049  if(!diffFlowList)
8050  { 
8051   cout<<"WARNING: diffFlowList is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8052   exit(0);
8053  }
8054  // list holding nested lists containing profiles:
8055  TList *diffFlowListProfiles = NULL;
8056  diffFlowListProfiles = dynamic_cast<TList*>(diffFlowList->FindObject("Profiles"));
8057  if(!diffFlowListProfiles)
8058  { 
8059   cout<<"WARNING: diffFlowListProfiles is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8060   exit(0);
8061  }
8062  // list holding nested lists containing 2D and 1D histograms with final results:
8063  TList *diffFlowListResults = NULL;
8064  diffFlowListResults = dynamic_cast<TList*>(diffFlowList->FindObject("Results"));
8065  if(!diffFlowListResults)
8066  { 
8067   cout<<"WARNING: diffFlowListResults is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8068   exit(0);
8069  }
8070  
8071  // c) Get pointer to profile holding all flags for differential flow;
8072  TString diffFlowFlagsName = "fDiffFlowFlags";
8073  diffFlowFlagsName += fAnalysisLabel->Data();
8074  TProfile *diffFlowFlags = dynamic_cast<TProfile*>(diffFlowList->FindObject(diffFlowFlagsName.Data()));
8075  Bool_t bCalculate2DFlow = kFALSE;
8076  if(diffFlowFlags)
8077  {
8078   this->SetDiffFlowFlags(diffFlowFlags);  
8079   bCalculate2DFlow = (Int_t)diffFlowFlags->GetBinContent(4);
8080   this->SetCalculate2DFlow(bCalculate2DFlow); // to be improved (shoul I call this setter somewhere else?)     
8081  }
8082   
8083  // d) Get pointers to all nested lists in fDiffFlowListProfiles and to profiles which they hold;
8084  // correlations:
8085  TList *diffFlowCorrelationsProList[2][2] = {{NULL}};
8086  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
8087  diffFlowCorrelationsProName += fAnalysisLabel->Data();
8088  TProfile *diffFlowCorrelationsPro[2][2][4] = {{{NULL}}};   
8089  // products of correlations:
8090  TList *diffFlowProductOfCorrelationsProList[2][2] = {{NULL}};
8091  TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
8092  diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
8093  TProfile *diffFlowProductOfCorrelationsPro[2][2][8][8] = {{{{NULL}}}};   
8094  // corrections:
8095  TList *diffFlowCorrectionsProList[2][2] = {{NULL}};
8096  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
8097  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();  
8098  TProfile *diffFlowCorrectionTermsForNUAPro[2][2][2][10] = {{{{NULL}}}};   
8099  for(Int_t t=0;t<2;t++)
8100  {
8101   for(Int_t pe=0;pe<2;pe++)
8102   {
8103    diffFlowCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8104    if(!diffFlowCorrelationsProList[t][pe])
8105    { 
8106     cout<<"WARNING: diffFlowCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8107     cout<<"t = "<<t<<endl;
8108     cout<<"pe = "<<pe<<endl;
8109     exit(0);
8110    }
8111    for(Int_t ci=0;ci<4;ci++) // correlation index
8112    {
8113     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())));
8114     if(diffFlowCorrelationsPro[t][pe][ci])
8115     {
8116      this->SetDiffFlowCorrelationsPro(diffFlowCorrelationsPro[t][pe][ci],t,pe,ci);
8117     } else
8118       {
8119        cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8120        cout<<"t  = "<<t<<endl;
8121        cout<<"pe = "<<pe<<endl;   
8122        cout<<"ci = "<<ci<<endl;
8123       }     
8124    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
8125    // products of correlations:    
8126    diffFlowProductOfCorrelationsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with products of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data()))); 
8127    if(!diffFlowProductOfCorrelationsProList[t][pe])
8128    { 
8129     cout<<"WARNING: ddiffFlowProductOfCorrelationsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8130     cout<<"t = "<<t<<endl;
8131     cout<<"pe = "<<pe<<endl;
8132     exit(0);
8133    }
8134    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8135    {
8136     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8137     {
8138      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())));
8139      if(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2])
8140      {
8141       this->SetDiffFlowProductOfCorrelationsPro(diffFlowProductOfCorrelationsPro[t][pe][mci1][mci2],t,pe,mci1,mci2);
8142      } else
8143        {
8144         cout<<"WARNING: diffFlowCorrelationsPro[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8145         cout<<"t    = "<<t<<endl;
8146         cout<<"pe   = "<<pe<<endl;   
8147         cout<<"mci1 = "<<mci1<<endl;
8148         cout<<"mci2 = "<<mci2<<endl;
8149        }
8150      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8151     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8152    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
8153    // corrections:
8154    diffFlowCorrectionsProList[t][pe] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(Form("Profiles with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8155    if(!diffFlowCorrectionsProList[t][pe])
8156    { 
8157     cout<<"WARNING: diffFlowCorrectionsProList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8158     cout<<"t = "<<t<<endl;
8159     cout<<"pe = "<<pe<<endl;
8160     exit(0);
8161    }
8162    // correction terms for NUA:
8163    for(Int_t sc=0;sc<2;sc++) // sin or cos
8164    {
8165     for(Int_t cti=0;cti<9;cti++) // correction term index
8166     {
8167      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)));
8168      if(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti])
8169      {
8170       this->SetDiffFlowCorrectionTermsForNUAPro(diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti],t,pe,sc,cti);
8171      } else
8172        {
8173         cout<<"WARNING: diffFlowCorrectionTermsForNUAPro[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8174         cout<<"t   = "<<t<<endl;
8175         cout<<"pe  = "<<pe<<endl;   
8176         cout<<"sc  = "<<sc<<endl;
8177         cout<<"cti = "<<cti<<endl;
8178        }    
8179     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
8180    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
8181    // ...
8182   } // end of for(Int_t pe=0;pe<2;pe++)
8183  } // end of for(Int_t t=0;t<2;t++)
8184   
8185  // e) Get pointers to all nested lists in fDiffFlowListResults and to histograms which they hold.
8186  // reduced correlations:
8187  TList *diffFlowCorrelationsHistList[2][2] = {{NULL}};
8188  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
8189  diffFlowCorrelationsHistName += fAnalysisLabel->Data();  
8190  TH1D *diffFlowCorrelationsHist[2][2][4] = {{{NULL}}};
8191  // corrections for NUA:
8192  TList *diffFlowCorrectionsHistList[2][2] = {{NULL}};
8193  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
8194  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();  
8195  TH1D *diffFlowCorrectionTermsForNUAHist[2][2][2][10] = {{{{NULL}}}};
8196  // differential Q-cumulants:
8197  TList *diffFlowCumulantsHistList[2][2] = {{NULL}};
8198  TString diffFlowCumulantsName = "fDiffFlowCumulants";
8199  diffFlowCumulantsName += fAnalysisLabel->Data();  
8200  TH1D *diffFlowCumulants[2][2][4] = {{{NULL}}};
8201  // differential flow estimates from Q-cumulants:
8202  TList *diffFlowHistList[2][2] = {{NULL}};
8203  TString diffFlowName = "fDiffFlow";
8204  diffFlowName += fAnalysisLabel->Data();  
8205  TH1D *diffFlow[2][2][4] = {{{NULL}}};
8206  // differential covariances:
8207  TList *diffFlowCovariancesHistList[2][2] = {{NULL}};
8208  TString diffFlowCovariancesName = "fDiffFlowCovariances";
8209  diffFlowCovariancesName += fAnalysisLabel->Data();  
8210  TH1D *diffFlowCovariances[2][2][5] = {{{NULL}}};
8211  for(Int_t t=0;t<2;t++) // type: RP or POI
8212  { 
8213   for(Int_t pe=0;pe<2;pe++) // pt or eta
8214   {
8215    // reduced correlations:
8216    diffFlowCorrelationsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8217    if(!diffFlowCorrelationsHistList[t][pe])
8218    { 
8219     cout<<"WARNING: diffFlowCorrelationsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8220     cout<<"t = "<<t<<endl;
8221     cout<<"pe = "<<pe<<endl;
8222     exit(0);
8223    }
8224    for(Int_t index=0;index<4;index++) 
8225    {
8226     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())));
8227     if(diffFlowCorrelationsHist[t][pe][index])
8228     {
8229      this->SetDiffFlowCorrelationsHist(diffFlowCorrelationsHist[t][pe][index],t,pe,index);
8230     } else 
8231       {
8232        cout<<"WARNING: diffFlowCorrelationsHist[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8233        cout<<"t     = "<<t<<endl;
8234        cout<<"pe    = "<<pe<<endl;
8235        cout<<"index = "<<index<<endl;
8236        exit(0);       
8237       } 
8238    } // end of for(Int_t index=0;index<4;index++)
8239    // corrections:
8240    diffFlowCorrectionsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Histograms with correction terms for NUA (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8241    if(!diffFlowCorrectionsHistList[t][pe])
8242    { 
8243     cout<<"WARNING: diffFlowCorrectionsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8244     cout<<"t = "<<t<<endl;
8245     cout<<"pe = "<<pe<<endl;
8246     exit(0);
8247    }
8248    // correction terms for NUA:
8249    for(Int_t sc=0;sc<2;sc++) // sin or cos
8250    {
8251     for(Int_t cti=0;cti<9;cti++) // correction term index
8252     {
8253      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)));
8254      if(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti])
8255      {
8256       this->SetDiffFlowCorrectionTermsForNUAHist(diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti],t,pe,sc,cti);
8257      } else
8258        {
8259         cout<<"WARNING: diffFlowCorrectionTermsForNUAHist[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8260         cout<<"t   = "<<t<<endl;
8261         cout<<"pe  = "<<pe<<endl;   
8262         cout<<"sc  = "<<sc<<endl;
8263         cout<<"cti = "<<cti<<endl;
8264        }    
8265     } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
8266    } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
8267    // ...
8268    // differential Q-cumulants:
8269    diffFlowCumulantsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential Q-cumulants (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8270    if(!diffFlowCumulantsHistList[t][pe])
8271    { 
8272     cout<<"WARNING: diffFlowCumulantsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8273     cout<<"t  = "<<t<<endl;
8274     cout<<"pe = "<<pe<<endl;
8275     exit(0);
8276    }
8277    for(Int_t index=0;index<4;index++) 
8278    {
8279     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())));
8280     if(diffFlowCumulants[t][pe][index])
8281     {
8282      this->SetDiffFlowCumulants(diffFlowCumulants[t][pe][index],t,pe,index);
8283     } else 
8284       {
8285        cout<<"WARNING: diffFlowCumulants[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8286        cout<<"t     = "<<t<<endl;
8287        cout<<"pe    = "<<pe<<endl;
8288        cout<<"index = "<<index<<endl;
8289        exit(0);       
8290       } 
8291    } // end of for(Int_t index=0;index<4;index++)
8292    // differential flow estimates from Q-cumulants:
8293    diffFlowHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Differential flow (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8294    if(!diffFlowHistList[t][pe])
8295    { 
8296     cout<<"WARNING: diffFlowHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8297     cout<<"t  = "<<t<<endl;
8298     cout<<"pe = "<<pe<<endl;
8299     exit(0);
8300    }
8301    for(Int_t index=0;index<4;index++) 
8302    {
8303     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())));
8304     if(diffFlow[t][pe][index])
8305     {
8306      this->SetDiffFlow(diffFlow[t][pe][index],t,pe,index);
8307     } else 
8308       {
8309        cout<<"WARNING: diffFlow[t][pe][index] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8310        cout<<"t     = "<<t<<endl;
8311        cout<<"pe    = "<<pe<<endl;
8312        cout<<"index = "<<index<<endl;
8313        exit(0);       
8314       } 
8315    } // end of for(Int_t index=0;index<4;index++)
8316    // differential covariances:
8317    diffFlowCovariancesHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Covariances of correlations (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8318    if(!diffFlowCovariancesHistList[t][pe])
8319    { 
8320     cout<<"WARNING: diffFlowCovariancesHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8321     cout<<"t  = "<<t<<endl;
8322     cout<<"pe = "<<pe<<endl;
8323     exit(0);
8324    }
8325    for(Int_t covIndex=0;covIndex<5;covIndex++) 
8326    {
8327     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())));
8328     if(diffFlowCovariances[t][pe][covIndex])
8329     {
8330      this->SetDiffFlowCovariances(diffFlowCovariances[t][pe][covIndex],t,pe,covIndex);
8331     } else 
8332       {
8333        cout<<"WARNING: diffFlowCovariances[t][pe][covIndex] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8334        cout<<"t        = "<<t<<endl;
8335        cout<<"pe       = "<<pe<<endl;
8336        cout<<"covIndex = "<<covIndex<<endl;
8337        exit(0);       
8338       } 
8339    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index    
8340   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8341  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI 
8342  // sum of event weights for reduced correlations:
8343  TList *diffFlowSumOfEventWeightsHistList[2][2][2] = {{{NULL}}};
8344  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
8345  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
8346  TH1D *diffFlowSumOfEventWeights[2][2][2][4] = {{{{NULL}}}};
8347  for(Int_t t=0;t<2;t++) // type is RP or POI
8348  { 
8349   for(Int_t pe=0;pe<2;pe++) // pt or eta
8350   { 
8351    for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
8352    {
8353     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())));
8354     if(!diffFlowSumOfEventWeightsHistList[t][pe][p])
8355     { 
8356      cout<<"WARNING: diffFlowSumOfEventWeightsHistList[t][pe][p] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8357      cout<<"t     = "<<t<<endl;
8358      cout<<"pe    = "<<pe<<endl;
8359      cout<<"power = "<<p<<endl;
8360      exit(0);
8361     }
8362     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
8363     {
8364      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())));    
8365      if(diffFlowSumOfEventWeights[t][pe][p][ew])
8366      {
8367       this->SetDiffFlowSumOfEventWeights(diffFlowSumOfEventWeights[t][pe][p][ew],t,pe,p,ew);
8368      } else 
8369        {
8370         cout<<"WARNING: diffFlowSumOfEventWeights[t][pe][p][ew] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8371         cout<<"t     = "<<t<<endl;
8372         cout<<"pe    = "<<pe<<endl;
8373         cout<<"power = "<<p<<endl;
8374         cout<<"ew    = "<<ew<<endl;
8375         exit(0);       
8376        } 
8377     }
8378    } // end of for(Int_t p=0;p<2;p++) // power of event weights is either 1 or 2
8379   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8380  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
8381  //  
8382  TList *diffFlowSumOfProductOfEventWeightsHistList[2][2] = {{NULL}};
8383  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
8384  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
8385  TH1D *diffFlowSumOfProductOfEventWeights[2][2][8][8] = {{{{NULL}}}};
8386  for(Int_t t=0;t<2;t++) // type is RP or POI
8387  { 
8388   for(Int_t pe=0;pe<2;pe++) // pt or eta
8389   { 
8390    diffFlowSumOfProductOfEventWeightsHistList[t][pe] = dynamic_cast<TList*>(diffFlowListResults->FindObject(Form("Sum of products of event weights (%s, %s)",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
8391    if(!diffFlowSumOfProductOfEventWeightsHistList[t][pe])
8392    { 
8393     cout<<"WARNING: diffFlowSumOfProductOfEventWeightsHistList[t][pe] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8394     cout<<"t     = "<<t<<endl;
8395     cout<<"pe    = "<<pe<<endl;
8396     exit(0);
8397    }
8398    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8399    {
8400     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8401     {
8402      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())));    
8403       if(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2])
8404       {
8405        this->SetDiffFlowSumOfProductOfEventWeights(diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2],t,pe,mci1,mci2);
8406       } else 
8407         {
8408          cout<<"WARNING: diffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
8409          cout<<"t    = "<<t<<endl;
8410          cout<<"pe   = "<<pe<<endl;
8411          cout<<"mci1 = "<<mci1<<endl;
8412          cout<<"mci2 = "<<mci2<<endl;
8413          exit(0);       
8414         } 
8415      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8416     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8417    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8418   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta
8419  } // end of for(Int_t t=0;t<2;t++) // type is RP or POI
8420
8421 } // end void AliFlowAnalysisWithQCumulants::GetPointersForDiffFlowHistograms()
8422
8423
8424 //================================================================================================================================
8425
8426
8427 void AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
8428 {
8429  // Book all histograms and profiles needed for differential flow.
8430  //  a) Define flags locally (to be improved: should I promote flags to data members?);
8431  //  b) Book profile to hold all flags for differential flow;
8432  //  c) Book e-b-e quantities;
8433  //  d) Book profiles;
8434  //  e) Book histograms holding final results. 
8435  
8436  // a) Define flags locally (to be improved: should I promote flags to data members?): 
8437  TString typeFlag[2] = {"RP","POI"}; 
8438  TString ptEtaFlag[2] = {"p_{T}","#eta"};
8439  TString powerFlag[2] = {"linear","quadratic"};
8440  TString sinCosFlag[2] = {"sin","cos"};
8441  TString differentialCumulantIndex[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};  
8442  TString differentialFlowIndex[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"};  
8443  TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"};
8444  TString mixedCorrelationIndex[8] = {"<2>","<2'>","<4>","<4'>","<6>","<6'>","<8>","<8'>"};
8445  TString covarianceName[5] = {"Cov(<2>,<2'>)","Cov(<2>,<4'>)","Cov(<4>,<2'>)","Cov(<4>,<4'>)","Cov(<2'>,<4'>)"}; 
8446  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
8447  Double_t minPtEta[2] = {fPtMin,fEtaMin};
8448  Double_t maxPtEta[2] = {fPtMax,fEtaMax};
8449   
8450  // b) Book profile to hold all flags for differential flow:
8451  TString diffFlowFlagsName = "fDiffFlowFlags";
8452  diffFlowFlagsName += fAnalysisLabel->Data();
8453  fDiffFlowFlags = new TProfile(diffFlowFlagsName.Data(),"Flags for Differential Flow",4,0,4);
8454  fDiffFlowFlags->SetTickLength(-0.01,"Y");
8455  fDiffFlowFlags->SetMarkerStyle(25);
8456  fDiffFlowFlags->SetLabelSize(0.05);
8457  fDiffFlowFlags->SetLabelOffset(0.02,"Y");
8458  (fDiffFlowFlags->GetXaxis())->SetBinLabel(1,"Particle Weights");
8459  (fDiffFlowFlags->GetXaxis())->SetBinLabel(2,"Event Weights");
8460  (fDiffFlowFlags->GetXaxis())->SetBinLabel(3,"Corrected for NUA?");
8461  (fDiffFlowFlags->GetXaxis())->SetBinLabel(4,"Calculated 2D flow?");
8462  fDiffFlowList->Add(fDiffFlowFlags);
8463
8464  // c) Book e-b-e quantities:
8465  // Event-by-event r_{m*n,k}(pt,eta), p_{m*n,k}(pt,eta) and q_{m*n,k}(pt,eta)
8466  // Explanantion of notation:
8467  //  1.) n is harmonic, m is multiple of harmonic;
8468  //  2.) k is power of particle weight;
8469  //  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);   
8470  //  4.) p_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for POIs in particular (pt,eta) bin 
8471  //                          (if i-th POI is also RP, than it is weighted with w_i^k);   
8472  //  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 
8473  //                          (i-th RP&&POI is weighted with w_i^k)            
8474   
8475  // 1D:
8476  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP && POI )
8477  { 
8478   for(Int_t pe=0;pe<2;pe++) // pt or eta
8479   {
8480    for(Int_t m=0;m<4;m++) // multiple of harmonic
8481    {
8482     for(Int_t k=0;k<9;k++) // power of particle weight
8483     {
8484      fReRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),
8485                                              Form("TypeFlag%dpteta%dmultiple%dpower%dRe",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8486      fImRPQ1dEBE[t][pe][m][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),
8487                                              Form("TypeFlag%dpteta%dmultiple%dpower%dIm",t,pe,m,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8488     }
8489    }
8490   }
8491  } 
8492  // to be improved (add explanation of fs1dEBE[t][pe][k]):   
8493  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8494  { 
8495   for(Int_t pe=0;pe<2;pe++) // pt or eta
8496   {
8497    for(Int_t k=0;k<9;k++) // power of particle weight
8498    {
8499     fs1dEBE[t][pe][k] = new TProfile(Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),
8500                                      Form("TypeFlag%dpteta%dmultiple%d",t,pe,k),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8501    }
8502   }
8503  }
8504  // correction terms for nua:
8505  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
8506  { 
8507   for(Int_t pe=0;pe<2;pe++) // pt or eta
8508   {
8509    for(Int_t sc=0;sc<2;sc++) // sin or cos
8510    {
8511     for(Int_t cti=0;cti<9;cti++) // correction term index
8512     {
8513      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti] = new TH1D(Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),
8514                                              Form("typeFlag%d pteta%d sincos%d cti%d",t,pe,sc,cti),nBinsPtEta[pe],minPtEta[pe],maxPtEta[pe]); 
8515     }
8516    }
8517   }
8518  } 
8519  // 2D:
8520  TProfile2D styleRe("typeMultiplePowerRe","typeMultiplePowerRe",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8521  TProfile2D styleIm("typeMultiplePowerIm","typeMultiplePowerIm",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8522  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8523  { 
8524   for(Int_t m=0;m<4;m++)
8525   {
8526    for(Int_t k=0;k<9;k++)
8527    {
8528     fReRPQ2dEBE[t][m][k] = (TProfile2D*)styleRe.Clone(Form("typeFlag%dmultiple%dpower%dRe",t,m,k)); 
8529     fImRPQ2dEBE[t][m][k] = (TProfile2D*)styleIm.Clone(Form("typeFlag%dmultiple%dpower%dIm",t,m,k));
8530    }
8531   } 
8532  } 
8533  TProfile2D styleS("typePower","typePower",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
8534  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
8535  { 
8536   for(Int_t k=0;k<9;k++)
8537   {
8538    fs2dEBE[t][k] = (TProfile2D*)styleS.Clone(Form("typeFlag%dpower%d",t,k));
8539   }
8540  }
8541  // reduced correlations e-b-e:
8542  TString diffFlowCorrelationsEBEName = "fDiffFlowCorrelationsEBE";
8543  diffFlowCorrelationsEBEName += fAnalysisLabel->Data();
8544  for(Int_t t=0;t<2;t++) // type: RP or POI
8545  { 
8546   for(Int_t pe=0;pe<2;pe++) // pt or eta
8547   {
8548    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8549    {
8550     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]);
8551    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
8552   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8553  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8554  // event weights for reduced correlations e-b-e:
8555  TString diffFlowEventWeightsForCorrelationsEBEName = "fDiffFlowEventWeightsForCorrelationsEBE";
8556  diffFlowEventWeightsForCorrelationsEBEName += fAnalysisLabel->Data();
8557  for(Int_t t=0;t<2;t++) // type: RP or POI
8558  { 
8559   for(Int_t pe=0;pe<2;pe++) // pt or eta
8560   {
8561    for(Int_t rci=0;rci<4;rci++) // event weight for reduced correlation index
8562    {
8563     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]);
8564    } // end of for(Int_t ci=0;ci<4;ci++) // correlation index
8565   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8566  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8567       
8568  // d) Book profiles;
8569  // reduced correlations:
8570  TString diffFlowCorrelationsProName = "fDiffFlowCorrelationsPro";
8571  diffFlowCorrelationsProName += fAnalysisLabel->Data();
8572  // corrections terms:
8573  TString diffFlowCorrectionTermsForNUAProName = "fDiffFlowCorrectionTermsForNUAPro";
8574  diffFlowCorrectionTermsForNUAProName += fAnalysisLabel->Data();
8575  for(Int_t t=0;t<2;t++) // type: RP or POI
8576  { 
8577   for(Int_t pe=0;pe<2;pe++) // pt or eta
8578   {
8579    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
8580    {
8581     // reduced correlations:
8582     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");
8583     fDiffFlowCorrelationsPro[t][pe][rci]->SetXTitle(ptEtaFlag[pe].Data());
8584     fDiffFlowCorrelationsProList[t][pe]->Add(fDiffFlowCorrelationsPro[t][pe][rci]); // to be improved (add dedicated list to hold reduced correlations)
8585    } // end of for(Int_t rci=0;rci<4;rci++) // correlation index
8586   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8587  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8588  // correction terms for nua:
8589  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
8590  { 
8591   for(Int_t pe=0;pe<2;pe++) // pt or eta
8592   {
8593    for(Int_t sc=0;sc<2;sc++) // sin or cos
8594    {
8595     for(Int_t cti=0;cti<9;cti++) // correction term index
8596     {
8597      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]); 
8598      fDiffFlowCorrectionsProList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]);
8599     }
8600    }
8601   }
8602  } 
8603  // e) Book histograms holding final results. 
8604  // reduced correlations:
8605  TString diffFlowCorrelationsHistName = "fDiffFlowCorrelationsHist";
8606  diffFlowCorrelationsHistName += fAnalysisLabel->Data();
8607  // corrections terms:
8608  TString diffFlowCorrectionTermsForNUAHistName = "fDiffFlowCorrectionTermsForNUAHist";
8609  diffFlowCorrectionTermsForNUAHistName += fAnalysisLabel->Data();
8610  // differential covariances:
8611  TString diffFlowCovariancesName = "fDiffFlowCovariances";
8612  diffFlowCovariancesName += fAnalysisLabel->Data();
8613  // differential Q-cumulants:
8614  TString diffFlowCumulantsName = "fDiffFlowCumulants";
8615  diffFlowCumulantsName += fAnalysisLabel->Data();
8616  // differential flow:
8617  TString diffFlowName = "fDiffFlow";
8618  diffFlowName += fAnalysisLabel->Data();
8619  for(Int_t t=0;t<2;t++) // type: RP or POI
8620  { 
8621   for(Int_t pe=0;pe<2;pe++) // pt or eta
8622   {
8623    for(Int_t index=0;index<4;index++) 
8624    {
8625     // reduced correlations:
8626     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]);
8627     fDiffFlowCorrelationsHist[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8628     fDiffFlowCorrelationsHistList[t][pe]->Add(fDiffFlowCorrelationsHist[t][pe][index]); 
8629     // differential Q-cumulants:
8630     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]);
8631     fDiffFlowCumulants[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8632     fDiffFlowCumulantsHistList[t][pe]->Add(fDiffFlowCumulants[t][pe][index]); 
8633     // differential flow estimates from Q-cumulants:
8634     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]);
8635     fDiffFlow[t][pe][index]->SetXTitle(ptEtaFlag[pe].Data());
8636     fDiffFlowHistList[t][pe]->Add(fDiffFlow[t][pe][index]); 
8637    } // end of for(Int_t index=0;index<4;index++) 
8638    for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index 
8639    {
8640     // differential covariances:
8641     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]);
8642     fDiffFlowCovariances[t][pe][covIndex]->SetXTitle(ptEtaFlag[pe].Data());
8643     fDiffFlowCovariancesHistList[t][pe]->Add(fDiffFlowCovariances[t][pe][covIndex]); 
8644    } // end of for(Int_t covIndex=0;covIndex<5;covIndex++) // covariance index
8645    // products of both types of correlations: 
8646    TString diffFlowProductOfCorrelationsProName = "fDiffFlowProductOfCorrelationsPro";
8647    diffFlowProductOfCorrelationsProName += fAnalysisLabel->Data();  
8648    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8649    {
8650     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8651     {
8652      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]); 
8653      fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
8654      fDiffFlowProductOfCorrelationsProList[t][pe]->Add(fDiffFlowProductOfCorrelationsPro[t][pe][mci1][mci2]); 
8655      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8656     } // end of for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8657    } // end of for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index    
8658   } // end of for(Int_t pe=0;pe<2;pe++) // pt or eta 
8659  } // end of for(Int_t t=0;t<2;t++) // type: RP or POI
8660  // sums of event weights for reduced correlations: 
8661  TString diffFlowSumOfEventWeightsName = "fDiffFlowSumOfEventWeights";
8662  diffFlowSumOfEventWeightsName += fAnalysisLabel->Data();  
8663  for(Int_t t=0;t<2;t++) // type is RP or POI
8664  { 
8665   for(Int_t pe=0;pe<2;pe++) // pt or eta
8666   { 
8667    for(Int_t p=0;p<2;p++) // power of weights is either 1 or 2
8668    {
8669     for(Int_t ew=0;ew<4;ew++) // index of reduced correlation
8670     {
8671      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]); 
8672      fDiffFlowSumOfEventWeights[t][pe][p][ew]->SetXTitle(ptEtaFlag[pe].Data());
8673      fDiffFlowSumOfEventWeightsHistList[t][pe][p]->Add(fDiffFlowSumOfEventWeights[t][pe][p][ew]); // to be improved (add dedicated list to hold all this)
8674     }
8675    }
8676   }
8677  } 
8678  // sum of products of event weights for both types of correlations: 
8679  TString diffFlowSumOfProductOfEventWeightsName = "fDiffFlowSumOfProductOfEventWeights";
8680  diffFlowSumOfProductOfEventWeightsName += fAnalysisLabel->Data();  
8681  for(Int_t t=0;t<2;t++) // type is RP or POI
8682  {
8683   for(Int_t pe=0;pe<2;pe++) // pt or eta
8684   { 
8685    for(Int_t mci1=0;mci1<8;mci1++) // mixed correlation index
8686    {
8687     for(Int_t mci2=mci1+1;mci2<8;mci2++) // mixed correlation index
8688     {
8689      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]); 
8690      fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]->SetXTitle(ptEtaFlag[pe].Data());
8691      fDiffFlowSumOfProductOfEventWeightsHistList[t][pe]->Add(fDiffFlowSumOfProductOfEventWeights[t][pe][mci1][mci2]); 
8692      if(mci1%2 == 0) mci2++; // products which DO NOT include reduced correlations are not stored here
8693     }
8694    }
8695   }
8696  } 
8697  // correction terms for nua:
8698  for(Int_t t=0;t<2;t++) // typeFlag (0 = RP, 1 = POI)
8699  { 
8700   for(Int_t pe=0;pe<2;pe++) // pt or eta
8701   {
8702    for(Int_t sc=0;sc<2;sc++) // sin or cos
8703    {
8704     for(Int_t cti=0;cti<9;cti++) // correction term index
8705     {
8706      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]); 
8707      fDiffFlowCorrectionsHistList[t][pe]->Add(fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]);
8708     }
8709    }
8710   }
8711  } 
8712           
8713 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
8714
8715
8716 //================================================================================================================================
8717
8718 /*
8719 void AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNUAForIntQcumulants() // to be improved (do I really need this method?)
8720 {
8721  // Calculate final corrections for non-uniform acceptance for Q-cumulants.
8722   
8723  // Corrections for non-uniform acceptance are stored in histogram fCorrectionsForNUA,
8724  // binning of fCorrectionsForNUA is organized as follows:
8725  //
8726  // 1st bin: correction to QC{2}
8727  // 2nd bin: correction to QC{4}
8728  // 3rd bin: correction to QC{6}
8729  // 4th bin: correction to QC{8}
8730   
8731  // shortcuts flags:
8732  Int_t pW = (Int_t)(useParticleWeights);
8733  
8734  Int_t eW = -1;
8735  
8736  if(eventWeights == "exact")
8737  {
8738   eW = 0;
8739  }
8740
8741  for(Int_t sc=0;sc<2;sc++) // sin or cos terms flag
8742  {
8743   if(!(fQCorrelations[pW][eW] && fQCorrections[pW][eW][sc] && fCorrections[pW][eW]))
8744   {
8745    cout<<"WARNING: fQCorrelations[pW][eW] && fQCorrections[pW][eW][sc] && fCorrections[pW][eW] is NULL in AFAWQC::CFCFNUAFIF() !!!!"<<endl;
8746    cout<<"pW = "<<pW<<endl;
8747    cout<<"eW = "<<eW<<endl;
8748    cout<<"sc = "<<sc<<endl;
8749    exit(0);
8750   }
8751  }  
8752
8753  // measured 2-, 4-, 6- and 8-particle azimuthal correlations (biased with non-uniform acceptance!):
8754  Double_t two = fQCorrelations[pW][eW]->GetBinContent(1); // <<2>>
8755  //Double_t four = fQCorrelations[pW][eW]->GetBinContent(11); // <<4>>
8756  //Double_t six = fQCorrelations[pW][eW]->GetBinContent(24); // <<6>>
8757  //Double_t eight = fQCorrelations[pW][eW]->GetBinContent(31); // <<8>>
8758  
8759  // correction terms to QC{2}:
8760  // <<cos(n*phi1)>>^2
8761  Double_t two1stTerm = pow(fQCorrections[pW][eW][1]->GetBinContent(1),2); 
8762  // <<sin(n*phi1)>>^2
8763  Double_t two2ndTerm = pow(fQCorrections[pW][eW][0]->GetBinContent(1),2); 
8764  // final corrections for non-uniform acceptance to QC{2}:
8765  Double_t correctionQC2 = -1.*two1stTerm-1.*two2ndTerm;
8766  fCorrections[pW][eW]->SetBinContent(1,correctionQC2); 
8767  
8768  // correction terms to QC{4}:
8769  // <<cos(n*phi1)>> <<cos(n*(phi1-phi2-phi3))>>
8770  Double_t four1stTerm = fQCorrections[pW][eW][1]->GetBinContent(1)*fQCorrections[pW][eW][1]->GetBinContent(3);  
8771  // <<sin(n*phi1)>> <<sin(n*(phi1-phi2-phi3))>>
8772  Double_t four2ndTerm = fQCorrections[pW][eW][0]->GetBinContent(1)*fQCorrections[pW][eW][0]->GetBinContent(3);  
8773  // <<cos(n*(phi1+phi2))>>^2
8774  Double_t four3rdTerm = pow(fQCorrections[pW][eW][1]->GetBinContent(2),2); 
8775  // <<sin(n*(phi1+phi2))>>^2
8776  Double_t four4thTerm = pow(fQCorrections[pW][eW][0]->GetBinContent(2),2); 
8777  // <<cos(n*(phi1+phi2))>> (<<cos(n*phi1)>>^2 - <<sin(n*phi1)>>^2)
8778  Double_t four5thTerm = fQCorrections[pW][eW][1]->GetBinContent(2)
8779                       * (pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)-pow(fQCorrections[pW][eW][0]->GetBinContent(1),2));
8780  // <<sin(n*(phi1+phi2))>> <<cos(n*phi1)>> <<sin(n*phi1)>>
8781  Double_t four6thTerm = fQCorrections[pW][eW][0]->GetBinContent(2)
8782                       * fQCorrections[pW][eW][1]->GetBinContent(1)
8783                       * fQCorrections[pW][eW][0]->GetBinContent(1);         
8784  // <<cos(n*(phi1-phi2))>> (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)
8785  Double_t four7thTerm = two*(pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)+pow(fQCorrections[pW][eW][0]->GetBinContent(1),2));  
8786  // (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)^2
8787  Double_t four8thTerm = pow(pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)+pow(fQCorrections[pW][eW][0]->GetBinContent(1),2),2);      
8788  // final correction to QC{4}:
8789  Double_t correctionQC4 = -4.*four1stTerm+4.*four2ndTerm-four3rdTerm-four4thTerm
8790                         + 4.*four5thTerm+8.*four6thTerm+8.*four7thTerm-6.*four8thTerm;                            
8791  fCorrections[pW][eW]->SetBinContent(2,correctionQC4);   
8792
8793  // ... to be improved (continued for 6th and 8th order)                                                    
8794
8795
8796 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNUAForIntQcumulants()
8797 */
8798
8799 //================================================================================================================================
8800
8801
8802 void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
8803 {
8804  // Calculate generalized Q-cumulants (cumulants corrected for non-unifom acceptance).
8805  
8806  // measured 2-, 4-, 6- and 8-particle correlations (biased by non-uniform acceptance!):
8807  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
8808  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>
8809  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>>
8810  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>
8811  
8812  // statistical error of measured 2-, 4-, 6- and 8-particle correlations:
8813  //Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <<2>>
8814  //Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <<4>>
8815  //Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <<6>>
8816  //Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <<8>>
8817
8818  // QC{2}:
8819  // <<cos(n*phi1)>>^2
8820  Double_t two1stTerm = pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2); 
8821  //Double_t two1stTermErrorSquared = pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(1),2); 
8822  // <<sin(n*phi1)>>^2
8823  Double_t two2ndTerm = pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2); 
8824  //Double_t two2ndTermErrorSquared = pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(1),2); 
8825  // generalized QC{2}:
8826  Double_t gQC2 = two - two1stTerm - two2ndTerm; // to be improved (terminology, notation)
8827  fIntFlowQcumulants->SetBinContent(1,gQC2); 
8828  //fIntFlowQcumulants->SetBinError(1,0.); // to be improved (propagate error) 
8829  
8830  // QC{4}:
8831  // <<cos(n*phi1)>> <<cos(n*(phi1-phi2-phi3))>>
8832  Double_t four1stTerm = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1)
8833                       * fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3);  
8834  // <<sin(n*phi1)>> <<sin(n*(phi1-phi2-phi3))>>
8835  Double_t four2ndTerm = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1)
8836                       * fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3);  
8837  // <<cos(n*(phi1+phi2))>>^2
8838  Double_t four3rdTerm = pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2),2); 
8839  // <<sin(n*(phi1+phi2))>>^2
8840  Double_t four4thTerm = pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2),2); 
8841  // <<cos(n*(phi1+phi2))>> (<<cos(n*phi1)>>^2 - <<sin(n*phi1)>>^2)
8842  Double_t four5thTerm = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2)
8843                       * (pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2)
8844                       - pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2));
8845  // <<sin(n*(phi1+phi2))>> <<cos(n*phi1)>> <<sin(n*phi1)>>
8846  Double_t four6thTerm = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2)
8847                       * fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1)
8848                       * fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1);         
8849  // <<cos(n*(phi1-phi2))>> (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)
8850  Double_t four7thTerm = two*(pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2)
8851                       + pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2));  
8852  // (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)^2
8853  Double_t four8thTerm = pow(pow(fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1),2)
8854                       + pow(fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1),2),2);      
8855  // generalized QC{4}:
8856  Double_t gQC4 = four-2.*pow(two,2.)-4.*four1stTerm+4.*four2ndTerm-four3rdTerm
8857                - four4thTerm+4.*four5thTerm+8.*four6thTerm+8.*four7thTerm-6.*four8thTerm;                            
8858  fIntFlowQcumulants->SetBinContent(2,gQC4);   
8859  //fIntFlowQcumulants->SetBinError(2,0.); // to be improved (propagate error) 
8860
8861  // ... to be improved (continued for 6th and 8th order)                                                    
8862     
8863  // versus multiplicity:
8864  if(fApplyCorrectionForNUAVsM && fCalculateCumulantsVsM) 
8865  { 
8866   Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
8867   for(Int_t b=1;b<=nBins;b++)
8868   {
8869    two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> vs M
8870    four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>> vs M
8871    // generalized QC{2} vs M:
8872    two1stTerm = pow(fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b),2); // <<cos(n*phi1)>>^2 vs M
8873    two2ndTerm = pow(fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b),2); // <<sin(n*phi1)>>^2 vs M
8874    gQC2 = two - two1stTerm - two2ndTerm; 
8875    fIntFlowQcumulantsVsM[0]->SetBinContent(b,gQC2);   
8876    // generalized QC{4} vs M:  
8877    four1stTerm = fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b)
8878                * fIntFlowCorrectionTermsForNUAVsMPro[1][2]->GetBinContent(b); // <<cos(n*phi1)>> <<cos(n*(phi1-phi2-phi3))>> vs M
8879    four2ndTerm = fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b)
8880                * fIntFlowCorrectionTermsForNUAVsMPro[0][2]->GetBinContent(b); // <<sin(n*phi1)>> <<sin(n*(phi1-phi2-phi3))>> vs M
8881    four3rdTerm = pow(fIntFlowCorrectionTermsForNUAVsMPro[1][1]->GetBinContent(b),2); // <<cos(n*(phi1+phi2))>>^2 vs M
8882    four4thTerm = pow(fIntFlowCorrectionTermsForNUAVsMPro[0][1]->GetBinContent(b),2); // <<sin(n*(phi1+phi2))>>^2 vs M
8883    four5thTerm = fIntFlowCorrectionTermsForNUAVsMPro[1][1]->GetBinContent(b)
8884                * (pow(fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b),2)
8885                - pow(fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b),2)); //<<cos(n*(phi1+phi2))>> (<<cos(n*phi1)>>^2-<<sin(n*phi1)>>^2) vs M
8886    four6thTerm = fIntFlowCorrectionTermsForNUAVsMPro[0][1]->GetBinContent(b)
8887                * fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b)
8888                * fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b); // <<sin(n*(phi1+phi2))>> <<cos(n*phi1)>> <<sin(n*phi1)>> vs M
8889    four7thTerm = two*(pow(fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b),2)
8890                + pow(fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b),2)); // <<cos(n*(phi1-phi2))>> (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2) vs M 
8891    four8thTerm = pow(pow(fIntFlowCorrectionTermsForNUAVsMPro[1][0]->GetBinContent(b),2)
8892                + pow(fIntFlowCorrectionTermsForNUAVsMPro[0][0]->GetBinContent(b),2),2); // (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)^2
8893    gQC4 = four-2.*pow(two,2.)-4.*four1stTerm+4.*four2ndTerm-four3rdTerm
8894         - four4thTerm+4.*four5thTerm+8.*four6thTerm+8.*four7thTerm-6.*four8thTerm;                            
8895    fIntFlowQcumulantsVsM[1]->SetBinContent(b,gQC4);   
8896   } // end of for(Int_t b=1;b<=nBins;b++)    
8897  } // end of if(fApplyCorrectionForNUAVsM && fCalculateCumulantsVsM) 
8898      
8899 } // end of void AliFlowAnalysisWithQCumulants::CalculateQcumulantsCorrectedForNUAIntFlow()
8900
8901 //================================================================================================================================
8902
8903 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectedForNUA()
8904 {
8905  // Calculate integrated flow from generalized Q-cumulants (corrected for non-uniform acceptance).
8906  
8907  // to be improved: add protection for NULL pointers, propagate statistical errors from 
8908  // measured correlations and correction terms
8909  
8910  // generalized Q-cumulants:
8911  Double_t qc2 = fIntFlowQcumulants->GetBinContent(1); // QC{2}  
8912  Double_t qc4 = fIntFlowQcumulants->GetBinContent(2); // QC{4}  
8913  //Double_t qc6 = fIntFlowQcumulants->GetBinContent(3); // QC{6}  
8914  //Double_t qc8 = fIntFlowQcumulants->GetBinContent(4); // QC{8}
8915  
8916  // integrated flow estimates:
8917  Double_t v2 = 0.; // v{2,QC}  
8918  Double_t v4 = 0.; // v{4,QC}  
8919  //Double_t v6 = 0.; // v{6,QC}  
8920  //Double_t v8 = 0.; // v{8,QC}
8921
8922  // calculate integrated flow estimates from generalized Q-cumulants: 
8923  if(qc2>=0.) v2 = pow(qc2,1./2.); 
8924  if(qc4<=0.) v4 = pow(-1.*qc4,1./4.); 
8925  //if(qc6>=0.) v6 = pow((1./4.)*qc6,1./6.); 
8926  //if(qc8<=0.) v8 = pow((-1./33.)*qc8,1./8.); 
8927
8928  // store integrated flow estimates from generalized Q-cumulants:
8929  fIntFlow->SetBinContent(1,v2);
8930  fIntFlow->SetBinContent(2,v4);
8931  //fIntFlow->SetBinContent(3,v6);
8932  //fIntFlow->SetBinContent(4,v8);
8933  
8934  /*
8935  // propagate correctly error by including non-isotropic terms (to be improved - moved somewhere else):
8936  // correlations:
8937  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
8938  //Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
8939  //Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
8940  //Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
8941  // statistical errors of average 2-, 4-, 6- and 8-particle azimuthal correlations:
8942  Double_t twoError = fIntFlowCorrelationsHist->GetBinError(1); // statistical error of <2>  
8943  Double_t fourError = fIntFlowCorrelationsHist->GetBinError(2); // statistical error of <4>   
8944  //Double_t sixError = fIntFlowCorrelationsHist->GetBinError(3); // statistical error of <6> 
8945  //Double_t eightError = fIntFlowCorrelationsHist->GetBinError(4); // statistical error of <8> 
8946  // nua terms: 
8947  Double_t c1 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(phi1)>>
8948  Double_t c2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(phi1+phi2)>>
8949  Double_t c3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(phi1-phi2-phi3)>>
8950  Double_t s1 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(phi1)>>
8951  Double_t s2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(phi1+phi2)>>
8952  Double_t s3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(phi1-phi2-phi3)>>
8953  // statistical errors of nua terms:
8954  Double_t c1Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(1); // statistical error of <cos(phi1)>
8955  Double_t c2Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(2); // statistical error of <cos(phi1+phi2)>
8956  Double_t c3Error = fIntFlowCorrectionTermsForNUAHist[1]->GetBinError(3); // statistical error of <cos(phi1-phi2-phi3)>
8957  Double_t s1Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(1); // statistical error of <sin(phi1)>
8958  Double_t s2Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(2); // statistical error of <sin(phi1+phi2)>
8959  Double_t s3Error = fIntFlowCorrectionTermsForNUAHist[0]->GetBinError(3); // statistical error of <sin(phi1-phi2-phi3)>
8960  
8961  // covariances for nua:
8962  Double_t wCov24 = fIntFlowCovariances->GetBinContent(1); // Cov(<2>,<4>) * prefactor(w_<2>,w_<4>)
8963  Double_t wCov2c1 = fIntFlowCovariancesNUA->GetBinContent(1);
8964  Double_t wCov2s1 = fIntFlowCovariancesNUA->GetBinContent(2);
8965  Double_t wCovc1s1 = fIntFlowCovariancesNUA->GetBinContent(3);
8966  Double_t wCov2c2 = fIntFlowCovariancesNUA->GetBinContent(4);
8967  Double_t wCov2s2 = fIntFlowCovariancesNUA->GetBinContent(5); 
8968  Double_t wCov2c3 = fIntFlowCovariancesNUA->GetBinContent(6); 
8969  Double_t wCov2s3 = fIntFlowCovariancesNUA->GetBinContent(7); 
8970  Double_t wCov4c1 = fIntFlowCovariancesNUA->GetBinContent(8);  
8971  Double_t wCov4s1 = fIntFlowCovariancesNUA->GetBinContent(9); 
8972  Double_t wCov4c2 = fIntFlowCovariancesNUA->GetBinContent(10); 
8973  Double_t wCov4s2 = fIntFlowCovariancesNUA->GetBinContent(11); 
8974  Double_t wCov4c3 = fIntFlowCovariancesNUA->GetBinContent(12);
8975  Double_t wCov4s3 = fIntFlowCovariancesNUA->GetBinContent(13);
8976  Double_t wCovc1c2 = fIntFlowCovariancesNUA->GetBinContent(14);
8977  Double_t wCovc1s2 = fIntFlowCovariancesNUA->GetBinContent(15);
8978  Double_t wCovc1c3 = fIntFlowCovariancesNUA->GetBinContent(16);
8979  Double_t wCovc1s3 = fIntFlowCovariancesNUA->GetBinContent(17);
8980  Double_t wCovs1c2 = fIntFlowCovariancesNUA->GetBinContent(18);
8981  Double_t wCovs1s2 = fIntFlowCovariancesNUA->GetBinContent(19); 
8982  Double_t wCovs1c3 = fIntFlowCovariancesNUA->GetBinContent(20);
8983  Double_t wCovs1s3 = fIntFlowCovariancesNUA->GetBinContent(21); 
8984  Double_t wCovc2s2 = fIntFlowCovariancesNUA->GetBinContent(22);  
8985  Double_t wCovc2c3 = fIntFlowCovariancesNUA->GetBinContent(23);  
8986  Double_t wCovc2s3 = fIntFlowCovariancesNUA->GetBinContent(24); 
8987  Double_t wCovs2c3 = fIntFlowCovariancesNUA->GetBinContent(25); 
8988  Double_t wCovs2s3 = fIntFlowCovariancesNUA->GetBinContent(26);
8989  Double_t wCovc3s3 = fIntFlowCovariancesNUA->GetBinContent(27); 
8990  */
8991  
8992  /*
8993  // 2nd order:
8994  Double_t err2ndSquared = (1./(4.*pow(v2,2.)))
8995                         * (pow(twoError,2.)+4.*pow(s1*s1Error,2.)+4.*pow(c1*c1Error,2.)
8996                         // to be improved (add eventually also covariance terms)
8997                         //- 4.*c1*wCov2c1-4.*s1*wCov2s1+8.*c1*s1*wCovc1s1 
8998                         );
8999  if(err2ndSquared>=0.) 
9000  {
9001   fIntFlow->SetBinError(1,pow(err2ndSquared,0.5)); // to be improved (enabled eventually)
9002  } else
9003    {
9004     cout<<"WARNING: Statistical error of v{2,QC} (with non-isotropic terms included) is imaginary !!!! "<<endl;
9005    }
9006  // 4th order:
9007  Double_t err4thSquared = (1./(16.*pow(v4,6.)))
9008                         * (pow(4.*pow(two,2.)-8.*(pow(c1,2.)+pow(s1,2.)),2.)*pow(twoError,2.)
9009                         + pow(fourError,2.)
9010                         + 16.*pow(6.*pow(c1,3.)-2.*c1*c2+c3+6.*c1*pow(s1,2.)-2.*s1*s2-4.*c1*two,2.)*pow(c1Error,2.)
9011                         + 16.*pow(6.*pow(c1,2.)*s1+2.*c2*s1+6.*pow(s1,3.)-2.*c1*s2-s3-4.*s1*two,2.)*pow(s1Error,2.)
9012                         + 4.*pow(c2-2.*(pow(c1,2.)-pow(s1,2.)),2.)*pow(c2Error,2.)
9013                         + 4.*pow(4*c1*s1-s2,2.)*pow(s2Error,2.)
9014                         + 16.*pow(c1,2.)*pow(c3Error,2.)
9015                         + 16.*pow(s1,2.)*pow(s3Error,2.)
9016                         // to be improved (add eventually also covariance terms)
9017                         // ...
9018                         );
9019  if(err4thSquared>=0.) 
9020  {
9021   fIntFlow->SetBinError(2,pow(err4thSquared,0.5)); // to be improved (enabled eventually)
9022  } else
9023    {
9024     cout<<"WARNING: Statistical error of v{4,QC} (with non-isotropic terms included) is imaginary !!!! "<<endl;
9025    }
9026  */
9027  
9028 } // end of void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectedForNUA()
9029
9030    
9031 //================================================================================================================================
9032
9033
9034 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow() 
9035 {
9036  // From profile fIntFlowCorrectionTermsForNUAPro[sc] access measured correction terms for NUA
9037  // and their spread, correctly calculate the statistical errors and store the final 
9038  // results and statistical errors for correction terms for NUA in histogram fIntFlowCorrectionTermsForNUAHist[sc].
9039  //
9040  // Remark: Statistical error of correction temrs is calculated as:
9041  //
9042  //          statistical error = termA * spread * termB:
9043  //          termA = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
9044  //          termB = 1/sqrt(1-termA^2)   
9045  
9046  for(Int_t sc=0;sc<2;sc++) // sin or cos correction terms 
9047  {
9048   for(Int_t ci=1;ci<=3;ci++) // correction term index
9049   {
9050    Double_t correction = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci);
9051    Double_t spread = fIntFlowCorrectionTermsForNUAPro[sc]->GetBinError(ci);
9052    Double_t sumOfLinearEventWeights = fIntFlowSumOfEventWeightsNUA[sc][0]->GetBinContent(ci);
9053    Double_t sumOfQuadraticEventWeights = fIntFlowSumOfEventWeightsNUA[sc][1]->GetBinContent(ci);
9054    Double_t termA = 0.;
9055    Double_t termB = 0.;
9056    if(sumOfLinearEventWeights)
9057    {
9058     termA = pow(sumOfQuadraticEventWeights,0.5)/sumOfLinearEventWeights;
9059    } else
9060      {
9061       cout<<"WARNING: sumOfLinearEventWeights == 0 in AFAWQC::FCTFNIF() !!!!"<<endl;
9062       cout<<"         (for "<<ci<<"-th correction term)"<<endl;
9063      }
9064    if(1.-pow(termA,2.) > 0.)
9065    {
9066     termB = 1./pow(1-pow(termA,2.),0.5);
9067    } else
9068      {
9069       cout<<"WARNING: 1.-pow(termA,2.) <= 0 in AFAWQC::FCTFNIF() !!!!"<<endl;   
9070       cout<<"         (for "<<ci<<"-th correction term)"<<endl;
9071      }     
9072    Double_t statisticalError = termA * spread * termB;
9073    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinContent(ci,correction);
9074    fIntFlowCorrectionTermsForNUAHist[sc]->SetBinError(ci,statisticalError);
9075   } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
9076  } // end of for(Int sc=0;sc<2;sc++) // sin or cos correction terms 
9077                                                                                                                                                                                                
9078 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUAIntFlow()
9079
9080
9081 //================================================================================================================================
9082
9083
9084 void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
9085 {
9086  // Get pointers to all objects relevant for calculations with nested loops.
9087    
9088  TList *nestedLoopsList = dynamic_cast<TList*>(fHistList->FindObject("Nested Loops"));
9089  if(nestedLoopsList) 
9090  {
9091   this->SetNestedLoopsList(nestedLoopsList);
9092  } else
9093    {
9094     cout<<"WARNING: nestedLoopsList is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9095     exit(0);
9096    }
9097     
9098   TString sinCosFlag[2] = {"sin","cos"}; // to be improved (should I promote this to data members?)
9099   TString typeFlag[2] = {"RP","POI"}; // to be improved (should I promote this to data members?)
9100   TString ptEtaFlag[2] = {"p_{T}","#eta"}; // to be improved (should I promote this to data members?)
9101   TString reducedCorrelationIndex[4] = {"<2'>","<4'>","<6'>","<8'>"}; // to be improved (should I promote this to data members?)
9102    
9103   TString evaluateNestedLoopsName = "fEvaluateNestedLoops";
9104   evaluateNestedLoopsName += fAnalysisLabel->Data();  
9105   TProfile *evaluateNestedLoops = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(evaluateNestedLoopsName.Data()));
9106   Bool_t bEvaluateIntFlowNestedLoops = kFALSE;
9107   Bool_t bEvaluateDiffFlowNestedLoops = kFALSE;
9108   if(evaluateNestedLoops)
9109   {
9110    this->SetEvaluateNestedLoops(evaluateNestedLoops);
9111    bEvaluateIntFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(1);
9112    bEvaluateDiffFlowNestedLoops = (Int_t)evaluateNestedLoops->GetBinContent(2);
9113   }
9114   // nested loops relevant for integrated flow:  
9115   if(bEvaluateIntFlowNestedLoops)
9116   {
9117    // correlations:
9118    TString intFlowDirectCorrelationsName = "fIntFlowDirectCorrelations";
9119    intFlowDirectCorrelationsName += fAnalysisLabel->Data();
9120    TProfile *intFlowDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowDirectCorrelationsName.Data()));
9121    if(intFlowDirectCorrelations) 
9122    { 
9123     this->SetIntFlowDirectCorrelations(intFlowDirectCorrelations);
9124    } else
9125      {
9126       cout<<"WARNING: intFlowDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9127       exit(0);
9128      }
9129    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
9130    {
9131     TString intFlowExtraDirectCorrelationsName = "fIntFlowExtraDirectCorrelations";
9132     intFlowExtraDirectCorrelationsName += fAnalysisLabel->Data();
9133     TProfile *intFlowExtraDirectCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(intFlowExtraDirectCorrelationsName.Data()));
9134     if(intFlowExtraDirectCorrelations) 
9135     { 
9136      this->SetIntFlowExtraDirectCorrelations(intFlowExtraDirectCorrelations);
9137     } else
9138       {
9139        cout<<"WARNING: intFlowExtraDirectCorrelations is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9140        exit(0);
9141       }       
9142    } // end of if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)  
9143    // correction terms for non-uniform acceptance:
9144    TString intFlowDirectCorrectionTermsForNUAName = "fIntFlowDirectCorrectionTermsForNUA";
9145    intFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();
9146    TProfile *intFlowDirectCorrectionTermsForNUA[2] = {NULL};
9147    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
9148    {
9149     intFlowDirectCorrectionTermsForNUA[sc] = dynamic_cast<TProfile*>(nestedLoopsList->FindObject(Form("%s: %s terms",intFlowDirectCorrectionTermsForNUAName.Data(),sinCosFlag[sc].Data())));
9150     if(intFlowDirectCorrectionTermsForNUA[sc]) 
9151     { 
9152      this->SetIntFlowDirectCorrectionTermsForNUA(intFlowDirectCorrectionTermsForNUA[sc],sc);
9153     } else
9154       {
9155        cout<<"WARNING: intFlowDirectCorrectionTermsForNUA[sc] is NULL in AFAWQC::GPFNLH() !!!!"<<endl;
9156        cout<<"sc = "<<sc<<endl;
9157        exit(0);
9158       }
9159    } // end of for(Int_t sc=0;sc<2;sc++) 
9160   } // end of if(bEvaluateIntFlowNestedLoops)
9161     
9162   // nested loops relevant for differential flow:  
9163   if(bEvaluateDiffFlowNestedLoops)
9164   {
9165    // correlations:
9166    TString diffFlowDirectCorrelationsName = "fDiffFlowDirectCorrelations";
9167    diffFlowDirectCorrelationsName += fAnalysisLabel->Data();
9168    TProfile *diffFlowDirectCorrelations[2][2][4] = {{{NULL}}};
9169    for(Int_t t=0;t<2;t++)
9170    {
9171     for(Int_t pe=0;pe<2;pe++)
9172     {
9173      for(Int_t ci=0;ci<4;ci++) // correlation index
9174      {
9175       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())));
9176       if(diffFlowDirectCorrelations[t][pe][ci])
9177       {
9178        this->SetDiffFlowDirectCorrelations(diffFlowDirectCorrelations[t][pe][ci],t,pe,ci);
9179       } else
9180         {
9181          cout<<"WARNING: diffFlowDirectCorrelations[t][pe][ci] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9182          cout<<"t  = "<<t<<endl;
9183          cout<<"pe = "<<pe<<endl;   
9184          cout<<"ci = "<<ci<<endl;
9185         }     
9186      } // end of for(Int_t ci=0;ci<4;ci++) // correlation index  
9187     } // end of for(Int_t pe=0;pe<2;pe++)
9188    } // end of for(Int_t t=0;t<2;t++)   
9189    // correction terms for non-uniform acceptance:
9190    TString diffFlowDirectCorrectionTermsForNUAName = "fDiffFlowDirectCorrectionTermsForNUA";
9191    diffFlowDirectCorrectionTermsForNUAName += fAnalysisLabel->Data();  
9192    TProfile *diffFlowDirectCorrectionTermsForNUA[2][2][2][10] = {{{{NULL}}}};   
9193    for(Int_t t=0;t<2;t++)
9194    {
9195     for(Int_t pe=0;pe<2;pe++)
9196     {
9197      // correction terms for NUA:
9198      for(Int_t sc=0;sc<2;sc++) // sin or cos
9199      {
9200       for(Int_t cti=0;cti<9;cti++) // correction term index
9201       {
9202        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)));
9203        if(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti])
9204        {
9205         this->SetDiffFlowDirectCorrectionTermsForNUA(diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti],t,pe,sc,cti);
9206        } else
9207          {
9208           cout<<"WARNING: diffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti] is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9209           cout<<"t   = "<<t<<endl;
9210           cout<<"pe  = "<<pe<<endl;   
9211           cout<<"sc  = "<<sc<<endl;
9212           cout<<"cti = "<<cti<<endl;
9213          }    
9214       } // end of for(Int_t cti=0;cti<9;cti++) // correction term index
9215      } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9216     } // end of for(Int_t pe=0;pe<2;pe++)
9217    } // end of for(Int_t t=0;t<2;t++)
9218    // number of RPs and POIs in selected pt and eta bins for cross-checkings:
9219    TString noOfParticlesInBinName = "fNoOfParticlesInBin";
9220    TH1D *noOfParticlesInBin = NULL;
9221    noOfParticlesInBin = dynamic_cast<TH1D*>(nestedLoopsList->FindObject(noOfParticlesInBinName.Data()));
9222    if(noOfParticlesInBin)
9223    {
9224     this->SetNoOfParticlesInBin(noOfParticlesInBin);
9225    } else
9226      {
9227       cout<<endl;
9228       cout<<" WARNING (QC): noOfParticlesInBin is NULL in AFAWQC::GPFDFH() !!!!"<<endl;
9229       cout<<endl;
9230      }
9231   } // end of if(bEvaluateDiffFlowNestedLoops)
9232
9233 } // end of void AliFlowAnalysisWithQCumulants::GetPointersForNestedLoopsHistograms()
9234
9235
9236 //================================================================================================================================
9237
9238
9239 void AliFlowAnalysisWithQCumulants::StoreHarmonic()
9240 {
9241  // Store flow harmonic in common control histograms.
9242
9243  (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
9244  (fCommonHists2nd->GetHarmonic())->Fill(0.5,fHarmonic);
9245  (fCommonHists4th->GetHarmonic())->Fill(0.5,fHarmonic);
9246  (fCommonHists6th->GetHarmonic())->Fill(0.5,fHarmonic);
9247  (fCommonHists8th->GetHarmonic())->Fill(0.5,fHarmonic);
9248
9249 } // end of void AliFlowAnalysisWithQCumulants::StoreHarmonic()
9250
9251
9252 //================================================================================================================================
9253
9254
9255 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta) // type = RP or POI 
9256 {
9257  // Calculate all correlations needed for differential flow using particle weights.
9258  
9259  Int_t t = -1; // type flag 
9260  Int_t pe = -1; // ptEta flag
9261  
9262  if(type == "RP")
9263  {
9264   t = 0;
9265  } else if(type == "POI")
9266    {
9267     t = 1;
9268    }
9269
9270  if(ptOrEta == "Pt")
9271  {
9272   pe = 0;
9273  } else if(ptOrEta == "Eta")
9274    {
9275     pe = 1;
9276    }
9277     
9278  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9279  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9280  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9281  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9282
9283  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9284  Double_t dReQ1n1k = (*fReQ)(0,1);
9285  Double_t dReQ2n2k = (*fReQ)(1,2);
9286  Double_t dReQ1n3k = (*fReQ)(0,3);
9287  //Double_t dReQ4n4k = (*fReQ)(3,4);
9288  Double_t dImQ1n1k = (*fImQ)(0,1);
9289  Double_t dImQ2n2k = (*fImQ)(1,2);
9290  Double_t dImQ1n3k = (*fImQ)(0,3);
9291  //Double_t dImQ4n4k = (*fImQ)(3,4);
9292  
9293  // S^M_{p,k} (see .h file for the definition of fSMpk):
9294  Double_t dSM1p1k = (*fSMpk)(0,1);
9295  Double_t dSM1p2k = (*fSMpk)(0,2);
9296  Double_t dSM1p3k = (*fSMpk)(0,3);
9297  Double_t dSM2p1k = (*fSMpk)(1,1);
9298  Double_t dSM3p1k = (*fSMpk)(2,1);
9299  
9300  // looping over all bins and calculating reduced correlations: 
9301  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9302  {
9303   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
9304   Double_t p1n0kRe = 0.;
9305   Double_t p1n0kIm = 0.;
9306
9307   // number of POIs in particular (pt,eta) bin):
9308   Double_t mp = 0.;
9309
9310   // real and imaginary parts of q_{m*n,k}: 
9311   // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
9312   Double_t q1n2kRe = 0.;
9313   Double_t q1n2kIm = 0.;
9314   Double_t q2n1kRe = 0.;
9315   Double_t q2n1kIm = 0.;
9316
9317   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9318   Double_t s1p1k = 0.; 
9319   Double_t s1p2k = 0.; 
9320   Double_t s1p3k = 0.; 
9321    
9322   // M0111 from Eq. (118) in QC2c (to be improved (notation))
9323   Double_t dM0111 = 0.;
9324  
9325   if(type == "POI")
9326   {
9327    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
9328            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
9329    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
9330            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
9331             
9332    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9333     
9334    t = 1; // typeFlag = RP or POI
9335     
9336    // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
9337    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
9338            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
9339    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
9340            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));
9341    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
9342            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
9343    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
9344            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));
9345        
9346    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9347    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
9348    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
9349    s1p3k = pow(fs1dEBE[2][pe][3]->GetBinContent(b)*fs1dEBE[2][pe][3]->GetBinEntries(b),1.); 
9350      
9351    // M0111 from Eq. (118) in QC2c (to be improved (notation)):
9352    dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
9353           - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
9354           + 2.*(s1p3k-s1p2k*dSM1p1k));
9355   }
9356    else if(type == "RP")
9357    {
9358     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
9359     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
9360             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
9361     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
9362             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
9363     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
9364             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
9365     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
9366             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
9367
9368     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
9369     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
9370     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
9371     s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
9372     
9373     // to be improved (cross-checked):
9374     p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
9375             * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
9376     p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
9377             * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
9378             
9379     mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9380      
9381     t = 0; // typeFlag = RP or POI
9382     
9383     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
9384     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
9385            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
9386            + 2.*(s1p3k-s1p2k*dSM1p1k));
9387     //...............................................................................................   
9388    }
9389    
9390    // 2'-particle correlation:
9391    Double_t two1n1nW0W1 = 0.;
9392    if(mp*dSM1p1k-s1p1k)
9393    {
9394     two1n1nW0W1 = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
9395                 / (mp*dSM1p1k-s1p1k);
9396    
9397     // fill profile to get <<2'>>     
9398     fDiffFlowCorrelationsPro[t][pe][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],two1n1nW0W1,mp*dSM1p1k-s1p1k);
9399     // histogram to store <2'> e-b-e (needed in some other methods):
9400     fDiffFlowCorrelationsEBE[t][pe][0]->SetBinContent(b,two1n1nW0W1);      
9401     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][0]->SetBinContent(b,mp*dSM1p1k-s1p1k);      
9402    } // end of if(mp*dSM1p1k-s1p1k)
9403    
9404    // 4'-particle correlation:
9405    Double_t four1n1n1n1nW0W1W1W1 = 0.;
9406    if(dM0111)
9407    {
9408     four1n1n1n1nW0W1W1W1 = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
9409                          - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
9410                          - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
9411                          - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
9412                          + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
9413                          - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
9414                          - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
9415                          + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
9416                          + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
9417                          + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
9418                          + 2.*s1p1k*dSM1p2k                                      
9419                          - 6.*s1p3k)        
9420                          / dM0111; // to be improved (notation of dM0111)
9421    
9422     // fill profile to get <<4'>>     
9423     fDiffFlowCorrelationsPro[t][pe][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],four1n1n1n1nW0W1W1W1,dM0111);
9424     // histogram to store <4'> e-b-e (needed in some other methods):
9425     fDiffFlowCorrelationsEBE[t][pe][1]->SetBinContent(b,four1n1n1n1nW0W1W1W1);      
9426     fDiffFlowEventWeightsForCorrelationsEBE[t][pe][1]->SetBinContent(b,dM0111);      
9427    } // end of if(dM0111)
9428  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9429
9430 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrelationsUsingParticleWeights(TString type, TString ptOrEta); // type = RP or POI 
9431
9432
9433 //================================================================================================================================
9434
9435
9436 void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
9437 {
9438  // Fill common control histograms.
9439  
9440  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
9441  fCommonHists->FillControlHistograms(anEvent); 
9442  if(nRP>1)
9443  {
9444   fCommonHists2nd->FillControlHistograms(anEvent);                                        
9445   if(nRP>3)
9446   {
9447    fCommonHists4th->FillControlHistograms(anEvent);                                        
9448    if(nRP>5)
9449    {
9450     fCommonHists6th->FillControlHistograms(anEvent);                                        
9451     if(nRP>7)
9452     {
9453      fCommonHists8th->FillControlHistograms(anEvent);                                        
9454     } // end of if(nRP>7)  
9455    } // end of if(nRP>5) 
9456   } // end of if(nRP>3)                                                                                                                      
9457  } // end of if(nRP>1) 
9458  
9459 } // end of void AliFlowAnalysisWithQCumulants::FillCommonControlHistograms(AliFlowEventSimple *anEvent)
9460
9461
9462 //================================================================================================================================
9463
9464
9465 void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities()
9466 {
9467  // Reset all event by event quantities.
9468  
9469  // integrated flow:
9470  fReQ->Zero();
9471  fImQ->Zero();
9472  fSMpk->Zero();
9473  fIntFlowCorrelationsEBE->Reset();
9474  fIntFlowEventWeightsForCorrelationsEBE->Reset();
9475  fIntFlowCorrelationsAllEBE->Reset();
9476  
9477  if(fApplyCorrectionForNUA)  
9478  {
9479   for(Int_t sc=0;sc<2;sc++)
9480   {
9481    fIntFlowCorrectionTermsForNUAEBE[sc]->Reset();
9482    fIntFlowEventWeightForCorrectionTermsForNUAEBE[sc]->Reset();
9483   } 
9484  }
9485     
9486  // differential flow:
9487  // 1D:
9488  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
9489  {
9490   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
9491   {
9492    for(Int_t m=0;m<4;m++) // multiple of harmonic
9493    {
9494     for(Int_t k=0;k<9;k++) // power of weight
9495     {
9496      if(fReRPQ1dEBE[t][pe][m][k]) fReRPQ1dEBE[t][pe][m][k]->Reset();
9497      if(fImRPQ1dEBE[t][pe][m][k]) fImRPQ1dEBE[t][pe][m][k]->Reset();
9498     }   
9499    }
9500   }
9501  }
9502   
9503  for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
9504  { 
9505   for(Int_t pe=0;pe<2;pe++) // 1D in pt or eta
9506   {
9507    for(Int_t k=0;k<9;k++)
9508    {
9509     if(fs1dEBE[t][pe][k]) fs1dEBE[t][pe][k]->Reset();
9510    }
9511   }
9512  }
9513
9514  // e-b-e reduced correlations:
9515  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
9516  {  
9517   for(Int_t pe=0;pe<2;pe++) // pt or eta
9518   {
9519    for(Int_t rci=0;rci<4;rci++) // reduced correlation index
9520    {
9521     if(fDiffFlowCorrelationsEBE[t][pe][rci]) fDiffFlowCorrelationsEBE[t][pe][rci]->Reset();
9522     if(fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]) fDiffFlowEventWeightsForCorrelationsEBE[t][pe][rci]->Reset();
9523    }
9524   }
9525  }
9526     
9527  // correction terms for NUA:
9528  for(Int_t t=0;t<2;t++) // type (0 = RP, 1 = POI)
9529  {  
9530   for(Int_t pe=0;pe<2;pe++) // pt or eta
9531   {
9532    for(Int_t sc=0;sc<2;sc++) // sin or cos
9533    {
9534     for(Int_t cti=0;cti<9;cti++) // correction term index
9535     {
9536      fDiffFlowCorrectionTermsForNUAEBE[t][pe][sc][cti]->Reset();  
9537     }
9538    }
9539   }      
9540  }
9541     
9542  // 2D (pt,eta)
9543  if(fCalculate2DFlow)
9544  {
9545   for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
9546   {
9547    for(Int_t m=0;m<4;m++) // multiple of harmonic
9548    {
9549     for(Int_t k=0;k<9;k++) // power of weight
9550     {
9551      if(fReRPQ2dEBE[t][m][k]) fReRPQ2dEBE[t][m][k]->Reset();
9552      if(fImRPQ2dEBE[t][m][k]) fImRPQ2dEBE[t][m][k]->Reset();
9553     }   
9554    }
9555   }
9556   for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
9557   { 
9558    for(Int_t k=0;k<9;k++)
9559    {
9560     if(fs2dEBE[t][k]) fs2dEBE[t][k]->Reset();
9561    }
9562   }  
9563  } // end of if(fCalculate2DFlow) 
9564
9565 } // end of void AliFlowAnalysisWithQCumulants::ResetEventByEventQuantities();
9566
9567
9568 //================================================================================================================================
9569
9570
9571 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
9572 {
9573  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
9574  
9575  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
9576  //  0: <<sin n(psi1)>>
9577  //  1: <<sin n(psi1+phi2)>>
9578  //  2: <<sin n(psi1+phi2-phi3)>>
9579  //  3: <<sin n(psi1-phi2-phi3)>>:
9580  //  4:
9581  //  5:
9582  //  6:
9583  
9584  // multiplicity:
9585  Double_t dMult = (*fSMpk)(0,0);
9586  
9587  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9588  Double_t dReQ1n = (*fReQ)(0,0);
9589  Double_t dReQ2n = (*fReQ)(1,0);
9590  //Double_t dReQ3n = (*fReQ)(2,0);
9591  //Double_t dReQ4n = (*fReQ)(3,0);
9592  Double_t dImQ1n = (*fImQ)(0,0);
9593  Double_t dImQ2n = (*fImQ)(1,0);
9594  //Double_t dImQ3n = (*fImQ)(2,0);
9595  //Double_t dImQ4n = (*fImQ)(3,0);
9596
9597  Int_t t = -1; // type flag 
9598  Int_t pe = -1; // ptEta flag
9599  
9600  if(type == "RP")
9601  {
9602   t = 0;
9603  } else if(type == "POI")
9604    {
9605     t = 1;
9606    }
9607
9608  if(ptOrEta == "Pt")
9609  {
9610   pe = 0;
9611  } else if(ptOrEta == "Eta")
9612    {
9613     pe = 1;
9614    }
9615     
9616  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9617  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9618  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9619  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9620
9621  // looping over all bins and calculating correction terms: 
9622  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9623  {
9624   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
9625   Double_t p1n0kRe = 0.;
9626   Double_t p1n0kIm = 0.;
9627
9628   // number of POIs in particular pt or eta bin:
9629   Double_t mp = 0.;
9630
9631   // 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):
9632   Double_t q1n0kRe = 0.;
9633   Double_t q1n0kIm = 0.;
9634   Double_t q2n0kRe = 0.;
9635   Double_t q2n0kIm = 0.;
9636
9637   // number of particles which are both RPs and POIs in particular pt or eta bin:
9638   Double_t mq = 0.;
9639    
9640   if(type == "POI")
9641   {
9642    // q_{m*n,0}:
9643    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
9644            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
9645    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
9646            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
9647    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
9648            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
9649    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
9650            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
9651                  
9652    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9653   } 
9654   else if(type == "RP")
9655   {
9656    // q_{m*n,0}:
9657    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
9658            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
9659    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
9660            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
9661    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
9662            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
9663    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
9664            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
9665                  
9666    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
9667   }    
9668   if(type == "POI")
9669   {
9670    // p_{m*n,0}:
9671    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
9672            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
9673    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
9674            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
9675             
9676    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9677     
9678    t = 1; // typeFlag = RP or POI
9679   }
9680   else if(type == "RP")
9681   {
9682    // p_{m*n,0} = q_{m*n,0}:
9683    p1n0kRe = q1n0kRe; 
9684    p1n0kIm = q1n0kIm; 
9685            
9686    mp = mq; 
9687    
9688    t = 0; // typeFlag = RP or POI
9689   }
9690
9691   // <<sin n(psi1)>>:
9692   Double_t sinP1nPsi = 0.;
9693   if(mp)
9694   {
9695    sinP1nPsi = p1n0kIm/mp;
9696    // fill profile for <<sin n(psi1)>>:
9697    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
9698    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
9699    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
9700   } // end of if(mp)   
9701   
9702   // <<sin n(psi1+phi2)>>:
9703   Double_t sinP1nPsiP1nPhi = 0.;
9704   if(mp*dMult-mq)
9705   {
9706    sinP1nPsiP1nPhi = (p1n0kRe*dImQ1n+p1n0kIm*dReQ1n-q2n0kIm)/(mp*dMult-mq);
9707    // fill profile for <<sin n(psi1+phi2)>>:
9708    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhi,mp*dMult-mq);
9709    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
9710    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhi);
9711   } // end of if(mp*dMult-mq)   
9712   
9713   // <<sin n(psi1+phi2-phi3)>>:
9714   Double_t sinP1nPsi1P1nPhi2MPhi3 = 0.;
9715   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
9716   {
9717    sinP1nPsi1P1nPhi2MPhi3 = (p1n0kIm*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
9718                           - 1.*(q2n0kIm*dReQ1n-q2n0kRe*dImQ1n)  
9719                           - mq*dImQ1n+2.*q1n0kIm)
9720                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9721    // fill profile for <<sin n(psi1+phi2)>>:
9722    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9723    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
9724    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3);
9725   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
9726   
9727   // <<sin n(psi1-phi2-phi3)>>:
9728   Double_t sinP1nPsi1M1nPhi2MPhi3 = 0.;
9729   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
9730   {
9731    sinP1nPsi1M1nPhi2MPhi3 = (p1n0kIm*(pow(dReQ1n,2.)-pow(dImQ1n,2.))-2.*p1n0kRe*dReQ1n*dImQ1n
9732                           - 1.*(p1n0kIm*dReQ2n-p1n0kRe*dImQ2n)
9733                           + 2.*mq*dImQ1n-2.*q1n0kIm)
9734                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9735    // fill profile for <<sin n(psi1+phi2)>>:
9736    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9737    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
9738    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3);
9739   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
9740  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9741  
9742 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTerms(TString type, TString ptOrEta)
9743
9744
9745 //================================================================================================================================
9746
9747
9748 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
9749 {
9750  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms).
9751  
9752  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
9753  //  0: <<cos n(psi)>>
9754  //  1: <<cos n(psi1+phi2)>>
9755  //  2: <<cos n(psi1+phi2-phi3)>>
9756  //  3: <<cos n(psi1-phi2-phi3)>>
9757  //  4:
9758  //  5:
9759  //  6:
9760  
9761  // multiplicity:
9762  Double_t dMult = (*fSMpk)(0,0);
9763  
9764  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
9765  Double_t dReQ1n = (*fReQ)(0,0);
9766  Double_t dReQ2n = (*fReQ)(1,0);
9767  //Double_t dReQ3n = (*fReQ)(2,0);
9768  //Double_t dReQ4n = (*fReQ)(3,0);
9769  Double_t dImQ1n = (*fImQ)(0,0);
9770  Double_t dImQ2n = (*fImQ)(1,0);
9771  //Double_t dImQ3n = (*fImQ)(2,0);
9772  //Double_t dImQ4n = (*fImQ)(3,0);
9773
9774  Int_t t = -1; // type flag 
9775  Int_t pe = -1; // ptEta flag
9776  
9777  if(type == "RP")
9778  {
9779   t = 0;
9780  } else if(type == "POI")
9781    {
9782     t = 1;
9783    }
9784
9785  if(ptOrEta == "Pt")
9786  {
9787   pe = 0;
9788  } else if(ptOrEta == "Eta")
9789    {
9790     pe = 1;
9791    }
9792     
9793  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9794  Double_t minPtEta[2] = {fPtMin,fEtaMin};
9795  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9796  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9797
9798  // looping over all bins and calculating correction terms: 
9799  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9800  {
9801   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
9802   Double_t p1n0kRe = 0.;
9803   Double_t p1n0kIm = 0.;
9804
9805   // number of POIs in particular pt or eta bin:
9806   Double_t mp = 0.;
9807
9808   // 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):
9809   Double_t q1n0kRe = 0.;
9810   Double_t q1n0kIm = 0.;
9811   Double_t q2n0kRe = 0.;
9812   Double_t q2n0kIm = 0.;
9813
9814   // number of particles which are both RPs and POIs in particular pt or eta bin:
9815   Double_t mq = 0.;
9816    
9817   if(type == "POI")
9818   {
9819    // q_{m*n,0}:
9820    q1n0kRe = fReRPQ1dEBE[2][pe][0][0]->GetBinContent(fReRPQ1dEBE[2][pe][0][0]->GetBin(b))
9821            * fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b));
9822    q1n0kIm = fImRPQ1dEBE[2][pe][0][0]->GetBinContent(fImRPQ1dEBE[2][pe][0][0]->GetBin(b))
9823            * fImRPQ1dEBE[2][pe][0][0]->GetBinEntries(fImRPQ1dEBE[2][pe][0][0]->GetBin(b));
9824    q2n0kRe = fReRPQ1dEBE[2][pe][1][0]->GetBinContent(fReRPQ1dEBE[2][pe][1][0]->GetBin(b))
9825            * fReRPQ1dEBE[2][pe][1][0]->GetBinEntries(fReRPQ1dEBE[2][pe][1][0]->GetBin(b));
9826    q2n0kIm = fImRPQ1dEBE[2][pe][1][0]->GetBinContent(fImRPQ1dEBE[2][pe][1][0]->GetBin(b))
9827            * fImRPQ1dEBE[2][pe][1][0]->GetBinEntries(fImRPQ1dEBE[2][pe][1][0]->GetBin(b));         
9828                  
9829    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9830   } 
9831   else if(type == "RP")
9832   {
9833    // q_{m*n,0}:
9834    q1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
9835            * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
9836    q1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))
9837            * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
9838    q2n0kRe = fReRPQ1dEBE[0][pe][1][0]->GetBinContent(fReRPQ1dEBE[0][pe][1][0]->GetBin(b))
9839            * fReRPQ1dEBE[0][pe][1][0]->GetBinEntries(fReRPQ1dEBE[0][pe][1][0]->GetBin(b));
9840    q2n0kIm = fImRPQ1dEBE[0][pe][1][0]->GetBinContent(fImRPQ1dEBE[0][pe][1][0]->GetBin(b))
9841            * fImRPQ1dEBE[0][pe][1][0]->GetBinEntries(fImRPQ1dEBE[0][pe][1][0]->GetBin(b));         
9842                  
9843    mq = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)  
9844   }    
9845   if(type == "POI")
9846   {
9847    // p_{m*n,0}:
9848    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
9849            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
9850    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
9851            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
9852             
9853    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
9854     
9855    t = 1; // typeFlag = RP or POI
9856   }
9857   else if(type == "RP")
9858   {
9859    // p_{m*n,0} = q_{m*n,0}:
9860    p1n0kRe = q1n0kRe; 
9861    p1n0kIm = q1n0kIm; 
9862            
9863    mp = mq; 
9864    
9865    t = 0; // typeFlag = RP or POI
9866   }
9867
9868   // <<cos n(psi1)>>:
9869   Double_t cosP1nPsi = 0.;
9870   if(mp)
9871   {
9872    cosP1nPsi = p1n0kRe/mp;
9873    
9874    // fill profile for <<cos n(psi1)>>:
9875    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
9876    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
9877    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
9878   } // end of if(mp)   
9879   
9880   // <<cos n(psi1+phi2)>>:
9881   Double_t cosP1nPsiP1nPhi = 0.;
9882   if(mp*dMult-mq)
9883   {
9884    cosP1nPsiP1nPhi = (p1n0kRe*dReQ1n-p1n0kIm*dImQ1n-q2n0kRe)/(mp*dMult-mq);
9885    // fill profile for <<sin n(psi1+phi2)>>:
9886    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhi,mp*dMult-mq);
9887    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
9888    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhi);
9889   } // end of if(mp*dMult-mq)   
9890   
9891   // <<cos n(psi1+phi2-phi3)>>:
9892   Double_t cosP1nPsi1P1nPhi2MPhi3 = 0.;
9893   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
9894   {
9895    cosP1nPsi1P1nPhi2MPhi3 = (p1n0kRe*(pow(dImQ1n,2.)+pow(dReQ1n,2.)-dMult)
9896                           - 1.*(q2n0kRe*dReQ1n+q2n0kIm*dImQ1n)  
9897                           - mq*dReQ1n+2.*q1n0kRe)
9898                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9899    // fill profile for <<sin n(psi1+phi2)>>:
9900    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9901    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
9902    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3);
9903   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
9904   
9905   // <<cos n(psi1-phi2-phi3)>>:
9906   Double_t cosP1nPsi1M1nPhi2MPhi3 = 0.;
9907   if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))
9908   {
9909    cosP1nPsi1M1nPhi2MPhi3 = (p1n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))+2.*p1n0kIm*dReQ1n*dImQ1n
9910                           - 1.*(p1n0kRe*dReQ2n+p1n0kIm*dImQ2n)  
9911                           - 2.*mq*dReQ1n+2.*q1n0kRe)
9912                           / (mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9913    // fill profile for <<sin n(psi1+phi2)>>:
9914    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3,mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.));
9915    // histogram to store <sin n(psi1+phi2)> e-b-e (needed in some other methods):
9916    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3);
9917   } // end of if(mq*(dMult-1.)*(dMult-2.)+(mp-mq)*dMult*(dMult-1.))   
9918  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9919  
9920 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTerms(TString type, TString ptOrEta)
9921
9922
9923 //==================================================================================================================================
9924
9925
9926 void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
9927 {
9928  // Transfer prolfiles into histogams and correctly propagate the error (to be improved: description)
9929  
9930  // to be improved: debugged - I do not correctly transfer all profiles into histos (bug appears only after merging) 
9931   
9932  Int_t t = -1; // type flag 
9933  Int_t pe = -1; // ptEta flag
9934  
9935  if(type == "RP")
9936  {
9937   t = 0;
9938  } else if(type == "POI")
9939    {
9940     t = 1;
9941    }
9942
9943  if(ptOrEta == "Pt")
9944  {
9945   pe = 0;
9946  } else if(ptOrEta == "Eta")
9947    {
9948     pe = 1;
9949    }
9950     
9951  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
9952  //Double_t minPtEta[2] = {fPtMin,fEtaMin};
9953  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
9954  //Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
9955
9956  for(Int_t sc=0;sc<2;sc++) // sin or cos
9957  {
9958   for(Int_t cti=0;cti<9;cti++) // correction term index
9959   {
9960    for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9961    {
9962     Double_t correctionTerm = fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(b);
9963     fDiffFlowCorrectionTermsForNUAHist[t][pe][sc][cti]->SetBinContent(b,correctionTerm);
9964     // to be improved (propagate error correctly)
9965     // ...
9966    } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
9967   } // correction term index
9968  } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos
9969
9970 }// end of void AliFlowAnalysisWithQCumulants::FinalizeCorrectionTermsForNUADiffFlow(TString type, TString ptOrEta)
9971
9972
9973 //==================================================================================================================================
9974
9975
9976 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
9977
9978  // Calculate generalized differential flow Q-cumulants (corrected for non-uniform acceptance)
9979   
9980  Int_t typeFlag = -1;
9981  Int_t ptEtaFlag = -1;
9982
9983  if(type == "RP")
9984  {
9985   typeFlag = 0;
9986  } else if(type == "POI")
9987    {
9988     typeFlag = 1;
9989    } 
9990      
9991  if(ptOrEta == "Pt")
9992  {
9993   ptEtaFlag = 0;
9994  } else if(ptOrEta == "Eta")
9995    {
9996     ptEtaFlag = 1;
9997    } 
9998   
9999  // shortcuts:
10000  Int_t t = typeFlag;
10001  Int_t pe = ptEtaFlag;
10002      
10003  // common:
10004  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10005  
10006  // 2-particle correlation:
10007  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>>
10008  // sin term coming from integrated flow: 
10009  Double_t sinP1nPhi = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(1); // <<sin(n*phi1)>>
10010  Double_t sinP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(2); // <<sin(n*(phi1+phi2))>>
10011  Double_t sinP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[0]->GetBinContent(3); // <<sin(n*(phi1-phi2-phi3))>>
10012  // cos term coming from integrated flow: 
10013  Double_t cosP1nPhi = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(1); // <<cos(n*phi1)>>
10014  Double_t cosP1nPhi1P1nPhi2 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(2); // <<cos(n*(phi1+phi2))>>
10015  Double_t cosP1nPhi1M1nPhi2M1nPhi3 = fIntFlowCorrectionTermsForNUAHist[1]->GetBinContent(3); // <<cos(n*(phi1-phi2-phi3))>>
10016
10017  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10018  {
10019   Double_t twoPrime = fDiffFlowCorrelationsHist[t][pe][0]->GetBinContent(b); // <<2'>>
10020   Double_t fourPrime = fDiffFlowCorrelationsHist[t][pe][1]->GetBinContent(b); // <<4'>>
10021   Double_t sinP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][0]->GetBinContent(b); // <<sin n(Psi)>> 
10022   Double_t cosP1nPsi = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][0]->GetBinContent(b); // <<cos n(Psi)>> 
10023   Double_t sinP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][1]->GetBinContent(b); // <<sin n(psi1+phi2)>> 
10024   Double_t cosP1nPsi1P1nPhi2 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][1]->GetBinContent(b); // <<cos n(psi1+phi2)>> 
10025   Double_t sinP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][2]->GetBinContent(b); // <<sin n(psi1+phi2-phi3)>> 
10026   Double_t cosP1nPsi1P1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][2]->GetBinContent(b); // <<cos n(psi1+phi2-phi3)>> 
10027   Double_t sinP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][0][3]->GetBinContent(b); // <<sin n(psi1-phi2-phi3)>> 
10028   Double_t cosP1nPsi1M1nPhi2M1nPhi3 = fDiffFlowCorrectionTermsForNUAHist[t][pe][1][3]->GetBinContent(b); // <<cos n(psi1-phi2-phi3)>> 
10029   // generalized QC{2'}:
10030   Double_t qc2Prime = twoPrime - sinP1nPsi*sinP1nPhi - cosP1nPsi*cosP1nPhi;
10031   fDiffFlowCumulants[t][pe][0]->SetBinContent(b,qc2Prime);
10032   // generalized QC{4'}:
10033   Double_t qc4Prime = fourPrime-2.*twoPrime*two
10034                     - cosP1nPsi*cosP1nPhi1M1nPhi2M1nPhi3
10035                     + sinP1nPsi*sinP1nPhi1M1nPhi2M1nPhi3
10036                     - cosP1nPhi*cosP1nPsi1M1nPhi2M1nPhi3
10037                     + sinP1nPhi*sinP1nPsi1M1nPhi2M1nPhi3
10038                     - 2.*cosP1nPhi*cosP1nPsi1P1nPhi2M1nPhi3
10039                     - 2.*sinP1nPhi*sinP1nPsi1P1nPhi2M1nPhi3
10040                     - cosP1nPsi1P1nPhi2*cosP1nPhi1P1nPhi2
10041                     - sinP1nPsi1P1nPhi2*sinP1nPhi1P1nPhi2
10042                     + 2.*cosP1nPhi1P1nPhi2*(cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
10043                     + 2.*sinP1nPhi1P1nPhi2*(cosP1nPsi*sinP1nPhi+sinP1nPsi*cosP1nPhi)
10044                     + 4.*two*(cosP1nPsi*cosP1nPhi+sinP1nPsi*sinP1nPhi)
10045                     + 2.*cosP1nPsi1P1nPhi2*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.))
10046                     + 4.*sinP1nPsi1P1nPhi2*cosP1nPhi*sinP1nPhi
10047                     + 4.*twoPrime*(pow(cosP1nPhi,2.)+pow(sinP1nPhi,2.))
10048                     - 6.*(pow(cosP1nPhi,2.)-pow(sinP1nPhi,2.)) 
10049                     * (cosP1nPsi*cosP1nPhi-sinP1nPsi*sinP1nPhi)
10050                     - 12.*cosP1nPhi*sinP1nPhi
10051                     * (sinP1nPsi*cosP1nPhi+cosP1nPsi*sinP1nPhi);
10052   fDiffFlowCumulants[t][pe][1]->SetBinContent(b,qc4Prime);   
10053  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
10054  
10055 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCumulantsCorrectedForNUA(TString type, TString ptOrEta)
10056
10057
10058 //==================================================================================================================================
10059     
10060
10061 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta)
10062 {
10063  // Calculate differential flow corrected for non-uniform acceptance.
10064  
10065  // to be improved (rewritten completely)
10066  
10067  Int_t typeFlag = -1;
10068  Int_t ptEtaFlag = -1;
10069
10070  if(type == "RP")
10071  {
10072   typeFlag = 0;
10073  } else if(type == "POI")
10074    {
10075     typeFlag = 1;
10076    } 
10077      
10078  if(ptOrEta == "Pt")
10079  {
10080   ptEtaFlag = 0;
10081  } else if(ptOrEta == "Eta")
10082    {
10083     ptEtaFlag = 1;
10084    } 
10085   
10086  // shortcuts:
10087  Int_t t = typeFlag;
10088  Int_t pe = ptEtaFlag;
10089      
10090  // common:
10091  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
10092    
10093  // to be improved: access here generalized QC{2} and QC{4} instead: 
10094  Double_t dV2 = fIntFlow->GetBinContent(1); 
10095  Double_t dV4 = fIntFlow->GetBinContent(2); 
10096  
10097  // loop over pt or eta bins:
10098  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
10099  {
10100   // generalized QC{2'}:
10101   Double_t gQC2Prime = fDiffFlowCumulants[t][pe][0]->GetBinContent(b);
10102   // v'{2}:
10103   if(dV2>0)
10104   { 
10105    Double_t v2Prime = gQC2Prime/dV2;
10106    fDiffFlow[t][pe][0]->SetBinContent(b,v2Prime); 
10107   }  
10108   // generalized QC{4'}:
10109   Double_t gQC4Prime = fDiffFlowCumulants[t][pe][1]->GetBinContent(b);
10110   // v'{4}:
10111   if(dV4>0)
10112   { 
10113    Double_t v4Prime = -gQC4Prime/pow(dV4,3.);
10114    fDiffFlow[t][pe][1]->SetBinContent(b,v4Prime); 
10115   }  
10116  } // end of for(Int_t b=1;b<=fnBinsPtEta[pe];b++)
10117   
10118 } // end of void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectedForNUA(TString type, TString ptOrEta); 
10119
10120
10121 //==================================================================================================================================
10122
10123
10124 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent)
10125 {
10126  // Evaluate with nested loops multiparticle correlations for integrated flow (without using the particle weights). 
10127
10128  // Remark: Results are stored in profile fIntFlowDirectCorrelations whose binning is organized as follows:
10129  // 
10130  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
10131  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
10132  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
10133  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
10134  //  5th bin:           ----  EMPTY ----
10135  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
10136  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
10137  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
10138  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
10139  // 10th bin:           ----  EMPTY ----
10140  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
10141  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
10142  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
10143  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
10144  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
10145  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
10146  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
10147  // 18th bin:           ----  EMPTY ----
10148  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
10149  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
10150  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
10151  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
10152  // 23rd bin:           ----  EMPTY ----
10153  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
10154  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
10155  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
10156  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
10157  // 28th bin:           ----  EMPTY ----
10158  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
10159  // 30th bin:           ----  EMPTY ----
10160  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
10161  
10162  Int_t nPrim = anEvent->NumberOfTracks(); 
10163  AliFlowTrackSimple *aftsTrack = NULL; 
10164  Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.; 
10165  Int_t n = fHarmonic; 
10166  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
10167  Double_t dMult = (*fSMpk)(0,0);
10168  cout<<endl;
10169  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
10170  if(dMult<2)
10171  {
10172   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
10173  } else if (dMult>fMaxAllowedMultiplicity)
10174    {
10175     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
10176    } else 
10177      { 
10178       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
10179      } 
10180  
10181  // 2-particle correlations:       
10182  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10183  {
10184   for(Int_t i1=0;i1<nPrim;i1++)
10185   {
10186    aftsTrack=anEvent->GetTrack(i1);
10187    if(!(aftsTrack->InRPSelection())) continue;
10188    phi1=aftsTrack->Phi(); 
10189    for(Int_t i2=0;i2<nPrim;i2++)
10190    {
10191     if(i2==i1)continue;
10192     aftsTrack=anEvent->GetTrack(i2);
10193     if(!(aftsTrack->InRPSelection())) continue;
10194     phi2=aftsTrack->Phi();
10195     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10196     // fill the profile with 2-p correlations: 
10197     fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),1.);    // <cos(n*(phi1-phi2))>
10198     fIntFlowDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),1.); // <cos(2n*(phi1-phi2))>
10199     fIntFlowDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),1.); // <cos(3n*(phi1-phi2))>
10200     fIntFlowDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),1.); // <cos(4n*(phi1-phi2))>   
10201    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10202   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10203  } // end of if(nPrim>=2)
10204  
10205  // 3-particle correlations:         
10206  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10207  {
10208   for(Int_t i1=0;i1<nPrim;i1++)
10209   {
10210    aftsTrack=anEvent->GetTrack(i1);
10211    if(!(aftsTrack->InRPSelection())) continue;
10212    phi1=aftsTrack->Phi();
10213    for(Int_t i2=0;i2<nPrim;i2++)
10214    {
10215     if(i2==i1)continue;
10216     aftsTrack=anEvent->GetTrack(i2);
10217     if(!(aftsTrack->InRPSelection())) continue;
10218     phi2=aftsTrack->Phi();
10219     for(Int_t i3=0;i3<nPrim;i3++)
10220     {
10221      if(i3==i1||i3==i2)continue;
10222      aftsTrack=anEvent->GetTrack(i3);
10223      if(!(aftsTrack->InRPSelection())) continue;
10224      phi3=aftsTrack->Phi();
10225      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
10226      // fill the profile with 3-p correlations:   
10227      fIntFlowDirectCorrelations->Fill(5.,cos(2.*n*phi1-n*(phi2+phi3)),1.);       //<3>_{2n|nn,n}
10228      fIntFlowDirectCorrelations->Fill(6.,cos(3.*n*phi1-2.*n*phi2-n*phi3),1.);    //<3>_{3n|2n,n}
10229      fIntFlowDirectCorrelations->Fill(7.,cos(4.*n*phi1-2.*n*phi2-2.*n*phi3),1.); //<3>_{4n|2n,2n}
10230      fIntFlowDirectCorrelations->Fill(8.,cos(4.*n*phi1-3.*n*phi2-n*phi3),1.);    //<3>_{4n|3n,n}
10231     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10232    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10233   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10234  } // end of if(nPrim>=3)
10235
10236  // 4-particle correlations:
10237  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
10238  {       
10239   for(Int_t i1=0;i1<nPrim;i1++)
10240   { 
10241    aftsTrack=anEvent->GetTrack(i1);
10242    if(!(aftsTrack->InRPSelection())) continue;
10243    phi1=aftsTrack->Phi();
10244    for(Int_t i2=0;i2<nPrim;i2++)
10245    {
10246     if(i2==i1)continue;
10247     aftsTrack=anEvent->GetTrack(i2);
10248     if(!(aftsTrack->InRPSelection())) continue;
10249     phi2=aftsTrack->Phi();
10250     for(Int_t i3=0;i3<nPrim;i3++)
10251     {
10252      if(i3==i1||i3==i2)continue;
10253      aftsTrack=anEvent->GetTrack(i3);
10254      if(!(aftsTrack->InRPSelection())) continue;
10255      phi3=aftsTrack->Phi();
10256      for(Int_t i4=0;i4<nPrim;i4++)
10257      {
10258       if(i4==i1||i4==i2||i4==i3)continue;
10259       aftsTrack=anEvent->GetTrack(i4);
10260       if(!(aftsTrack->InRPSelection())) continue;
10261       phi4=aftsTrack->Phi();
10262       if(nPrim==4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush;
10263       // fill the profile with 4-p correlations:   
10264       fIntFlowDirectCorrelations->Fill(10.,cos(n*phi1+n*phi2-n*phi3-n*phi4),1.);            // <4>_{n,n|n,n} 
10265       fIntFlowDirectCorrelations->Fill(11.,cos(2.*n*phi1+n*phi2-2.*n*phi3-n*phi4),1.);      // <4>_{2n,n|2n,n}
10266       fIntFlowDirectCorrelations->Fill(12.,cos(2.*n*phi1+2*n*phi2-2.*n*phi3-2.*n*phi4),1.); // <4>_{2n,2n|2n,2n}
10267       fIntFlowDirectCorrelations->Fill(13.,cos(3.*n*phi1-n*phi2-n*phi3-n*phi4),1.);         // <4>_{3n|n,n,n}
10268       fIntFlowDirectCorrelations->Fill(14.,cos(3.*n*phi1+n*phi2-3.*n*phi3-n*phi4),1.);      // <4>_{3n,n|3n,n}   
10269       fIntFlowDirectCorrelations->Fill(15.,cos(3.*n*phi1+n*phi2-2.*n*phi3-2.*n*phi4),1.);   // <4>_{3n,n|2n,2n}
10270       fIntFlowDirectCorrelations->Fill(16.,cos(4.*n*phi1-2.*n*phi2-n*phi3-n*phi4),1.);      // <4>_{4n|2n,n,n}     
10271      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
10272     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10273    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10274   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10275  } // end of if(nPrim>=)
10276
10277  // 5-particle correlations:      
10278  if(nPrim>=5 && nPrim<=fMaxAllowedMultiplicity)
10279  {
10280   for(Int_t i1=0;i1<nPrim;i1++)
10281   {
10282    aftsTrack=anEvent->GetTrack(i1);
10283    if(!(aftsTrack->InRPSelection())) continue;  
10284    phi1=aftsTrack->Phi();
10285    for(Int_t i2=0;i2<nPrim;i2++)
10286    {
10287     if(i2==i1)continue;
10288     aftsTrack=anEvent->GetTrack(i2);
10289     if(!(aftsTrack->InRPSelection())) continue;
10290     phi2=aftsTrack->Phi();
10291     for(Int_t i3=0;i3<nPrim;i3++)
10292     {
10293      if(i3==i1||i3==i2)continue;
10294      aftsTrack=anEvent->GetTrack(i3);
10295      if(!(aftsTrack->InRPSelection())) continue;
10296      phi3=aftsTrack->Phi();
10297      for(Int_t i4=0;i4<nPrim;i4++)
10298      {
10299       if(i4==i1||i4==i2||i4==i3)continue;
10300       aftsTrack=anEvent->GetTrack(i4);
10301       if(!(aftsTrack->InRPSelection())) continue;
10302       phi4=aftsTrack->Phi();
10303       for(Int_t i5=0;i5<nPrim;i5++)
10304       {
10305        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10306        aftsTrack=anEvent->GetTrack(i5);
10307        if(!(aftsTrack->InRPSelection())) continue;
10308        phi5=aftsTrack->Phi();
10309        if(nPrim==5) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<"\r"<<flush;
10310        // fill the profile with 5-p correlations:   
10311        fIntFlowDirectCorrelations->Fill(18.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{2n,n|n,n,n}
10312        fIntFlowDirectCorrelations->Fill(19.,cos(2.*n*phi1+2.*n*phi2-2.*n*phi3-n*phi4-n*phi5),1.); //<5>_{2n,2n|2n,n,n}
10313        fIntFlowDirectCorrelations->Fill(20.,cos(3.*n*phi1+n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);    //<5>_{3n,n|2n,n,n}
10314        fIntFlowDirectCorrelations->Fill(21.,cos(4.*n*phi1-n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{4n|n,n,n,n}
10315       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10316      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10317     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10318    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10319   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10320  } // end of if(nPrim>=5)
10321   
10322  // 6-particle correlations:
10323  if(nPrim>=6 && nPrim<=fMaxAllowedMultiplicity)
10324  {
10325   for(Int_t i1=0;i1<nPrim;i1++)
10326   {
10327    aftsTrack=anEvent->GetTrack(i1);
10328    if(!(aftsTrack->InRPSelection())) continue;
10329    phi1=aftsTrack->Phi();
10330    for(Int_t i2=0;i2<nPrim;i2++)
10331    {
10332     if(i2==i1)continue;
10333     aftsTrack=anEvent->GetTrack(i2);
10334     if(!(aftsTrack->InRPSelection())) continue;
10335     phi2=aftsTrack->Phi();
10336     for(Int_t i3=0;i3<nPrim;i3++)
10337     {
10338      if(i3==i1||i3==i2)continue;
10339      aftsTrack=anEvent->GetTrack(i3);
10340      if(!(aftsTrack->InRPSelection())) continue;
10341      phi3=aftsTrack->Phi();
10342      for(Int_t i4=0;i4<nPrim;i4++)
10343      {
10344       if(i4==i1||i4==i2||i4==i3)continue;
10345       aftsTrack=anEvent->GetTrack(i4);
10346       if(!(aftsTrack->InRPSelection())) continue;
10347       phi4=aftsTrack->Phi();
10348       for(Int_t i5=0;i5<nPrim;i5++)
10349       {
10350        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10351        aftsTrack=anEvent->GetTrack(i5);
10352        if(!(aftsTrack->InRPSelection())) continue;
10353        phi5=aftsTrack->Phi();
10354        for(Int_t i6=0;i6<nPrim;i6++)
10355        {
10356         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10357         aftsTrack=anEvent->GetTrack(i6);
10358         if(!(aftsTrack->InRPSelection())) continue;
10359         phi6=aftsTrack->Phi(); 
10360         if(nPrim==6) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<"\r"<<flush;
10361         // fill the profile with 6-p correlations:   
10362         fIntFlowDirectCorrelations->Fill(23.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),1.);       //<6>_{n,n,n|n,n,n}
10363         fIntFlowDirectCorrelations->Fill(24.,cos(2.*n*phi1+n*phi2+n*phi3-2.*n*phi4-n*phi5-n*phi6),1.); //<6>_{2n,n,n|2n,n,n}
10364         fIntFlowDirectCorrelations->Fill(25.,cos(2.*n*phi1+2.*n*phi2-n*phi3-n*phi4-n*phi5-n*phi6),1.); //<6>_{2n,2n|n,n,n,n}
10365         fIntFlowDirectCorrelations->Fill(26.,cos(3.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5-n*phi6),1.);    //<6>_{3n,n|n,n,n,n}  
10366        } // end of for(Int_t i6=0;i6<nPrim;i6++)
10367       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10368      } // end of for(Int_t i4=0;i4<nPrim;i4++)
10369     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10370    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10371   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10372  } // end of if(nPrim>=6)
10373   
10374  // 7-particle correlations:
10375  if(nPrim>=7 && nPrim<=fMaxAllowedMultiplicity)
10376  {
10377   for(Int_t i1=0;i1<nPrim;i1++)
10378   { 
10379    aftsTrack=anEvent->GetTrack(i1);
10380    if(!(aftsTrack->InRPSelection())) continue;
10381    phi1=aftsTrack->Phi();
10382    for(Int_t i2=0;i2<nPrim;i2++)
10383    {
10384     if(i2==i1)continue;
10385     aftsTrack=anEvent->GetTrack(i2);
10386     if(!(aftsTrack->InRPSelection())) continue;
10387     phi2=aftsTrack->Phi();
10388     for(Int_t i3=0;i3<nPrim;i3++)
10389     {
10390      if(i3==i1||i3==i2)continue;
10391      aftsTrack=anEvent->GetTrack(i3);
10392      if(!(aftsTrack->InRPSelection())) continue;
10393      phi3=aftsTrack->Phi();
10394      for(Int_t i4=0;i4<nPrim;i4++)
10395      {
10396       if(i4==i1||i4==i2||i4==i3)continue;
10397       aftsTrack=anEvent->GetTrack(i4);
10398       if(!(aftsTrack->InRPSelection())) continue;
10399       phi4=aftsTrack->Phi();
10400       for(Int_t i5=0;i5<nPrim;i5++)
10401       {
10402        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10403        aftsTrack=anEvent->GetTrack(i5);
10404        if(!(aftsTrack->InRPSelection())) continue;
10405        phi5=aftsTrack->Phi();
10406        for(Int_t i6=0;i6<nPrim;i6++)
10407        {
10408         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10409         aftsTrack=anEvent->GetTrack(i6);
10410         if(!(aftsTrack->InRPSelection())) continue;
10411         phi6=aftsTrack->Phi(); 
10412         for(Int_t i7=0;i7<nPrim;i7++)
10413         {
10414          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
10415          aftsTrack=anEvent->GetTrack(i7);
10416          if(!(aftsTrack->InRPSelection())) continue;
10417          phi7=aftsTrack->Phi(); 
10418          if(nPrim==7) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<"\r"<<flush;
10419          // fill the profile with 7-p correlation:   
10420          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}
10421         } // end of for(Int_t i7=0;i7<nPrim;i7++)
10422        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
10423       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10424      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10425     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10426    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10427   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10428  } // end of if(nPrim>=7)
10429  
10430  // 8-particle correlations:
10431  if(nPrim>=8 && nPrim<=fMaxAllowedMultiplicity)
10432  {
10433   for(Int_t i1=0;i1<nPrim;i1++)
10434   {
10435    aftsTrack=anEvent->GetTrack(i1);
10436    if(!(aftsTrack->InRPSelection())) continue;
10437    phi1=aftsTrack->Phi();
10438    for(Int_t i2=0;i2<nPrim;i2++)
10439    {
10440     if(i2==i1)continue;
10441     aftsTrack=anEvent->GetTrack(i2);
10442     if(!(aftsTrack->InRPSelection())) continue;
10443     phi2=aftsTrack->Phi();
10444     for(Int_t i3=0;i3<nPrim;i3++)
10445     {
10446      if(i3==i1||i3==i2)continue;
10447      aftsTrack=anEvent->GetTrack(i3);
10448      if(!(aftsTrack->InRPSelection())) continue;
10449      phi3=aftsTrack->Phi();
10450      for(Int_t i4=0;i4<nPrim;i4++)
10451      {
10452       if(i4==i1||i4==i2||i4==i3)continue;
10453       aftsTrack=anEvent->GetTrack(i4);
10454       if(!(aftsTrack->InRPSelection())) continue;
10455       phi4=aftsTrack->Phi();
10456       for(Int_t i5=0;i5<nPrim;i5++)
10457       {
10458        if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
10459        aftsTrack=anEvent->GetTrack(i5);
10460        if(!(aftsTrack->InRPSelection())) continue;
10461        phi5=aftsTrack->Phi();
10462        for(Int_t i6=0;i6<nPrim;i6++)
10463        {
10464         if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
10465         aftsTrack=anEvent->GetTrack(i6);
10466         if(!(aftsTrack->InRPSelection())) continue;
10467         phi6=aftsTrack->Phi();
10468         for(Int_t i7=0;i7<nPrim;i7++)
10469         {
10470          if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
10471          aftsTrack=anEvent->GetTrack(i7);
10472          if(!(aftsTrack->InRPSelection())) continue;
10473          phi7=aftsTrack->Phi();
10474          for(Int_t i8=0;i8<nPrim;i8++)
10475          {
10476           if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
10477           aftsTrack=anEvent->GetTrack(i8);
10478           if(!(aftsTrack->InRPSelection())) continue;
10479           phi8=aftsTrack->Phi();
10480           cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<" "<<i5<<" "<<i6<<" "<<i7<<" "<<i8<<"\r"<<flush;
10481           // fill the profile with 8-p correlation:   
10482           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}
10483          } // end of for(Int_t i8=0;i8<nPrim;i8++)
10484         } // end of for(Int_t i7=0;i7<nPrim;i7++) 
10485        } // end of for(Int_t i6=0;i6<nPrim;i6++) 
10486       } // end of for(Int_t i5=0;i5<nPrim;i5++)
10487      } // end of for(Int_t i4=0;i4<nPrim;i4++)  
10488     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10489    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10490   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10491  } // end of if(nPrim>=8)
10492  
10493  cout<<endl;
10494
10495 } // end of AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent)
10496
10497
10498 //==================================================================================================================================
10499
10500
10501 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
10502 {
10503  // Cross-check results for multiparticle correlations needed for int. flow: results from Q-vectors vs results from nested loops.
10504
10505  cout<<endl;
10506  cout<<endl;
10507  cout<<"   *****************************************"<<endl;
10508  cout<<"   **** cross-checking the correlations ****"<<endl;
10509  cout<<"   ****       for integrated flow       ****"<<endl;
10510  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
10511  {
10512   cout<<"   ****   (particle weights not used)   ****"<<endl;
10513  } else
10514    {
10515     cout<<"   ****     (particle weights used)     ****"<<endl;
10516    } 
10517  cout<<"   *****************************************"<<endl;
10518  cout<<endl;
10519  cout<<endl;
10520
10521  Int_t ciMax = 32; // to be improved (removed eventually when I calculate 6th and 8th order with particle weights)
10522  
10523  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
10524  {
10525   ciMax = 11;
10526  }
10527
10528  for(Int_t ci=1;ci<=ciMax;ci++)
10529  {
10530   if(strcmp((fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
10531   cout<<(fIntFlowCorrelationsAllPro->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
10532   cout<<"from Q-vectors    = "<<fIntFlowCorrelationsAllPro->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
10533   cout<<"from nested loops = "<<fIntFlowDirectCorrelations->GetBinContent(ci)<<endl;
10534   cout<<endl;
10535  }
10536   
10537 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrelations()
10538
10539
10540 //================================================================================================================================
10541
10542
10543 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA()
10544 {
10545  // Cross-check results for corrections terms for non-uniform acceptance needed for int. flow: results from Q-vectors vs results from nested loops.
10546
10547  cout<<endl;
10548  cout<<endl;
10549  cout<<"   *********************************************"<<endl;
10550  cout<<"   **** cross-checking the correction terms ****"<<endl;
10551  cout<<"   **** for non-uniform acceptance relevant ****"<<endl;
10552  cout<<"   ****         for integrated flow         ****"<<endl;
10553  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
10554  {
10555   cout<<"   ****     (particle weights not used)     ****"<<endl;
10556  } else
10557    {
10558     cout<<"   ****       (particle weights used)       ****"<<endl;
10559    } 
10560  cout<<"   *********************************************"<<endl;
10561  cout<<endl;
10562  cout<<endl;
10563
10564  for(Int_t ci=1;ci<=10;ci++) // correction term index
10565  {
10566   for(Int_t sc=0;sc<2;sc++) // sin or cos term
10567   {
10568    if(strcmp((fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci), "") == 0) continue; // to be improved (access finalized histogram here)
10569    cout<<(fIntFlowCorrectionTermsForNUAPro[sc]->GetXaxis())->GetBinLabel(ci)<<":"<<endl; // to be improved (access finalized histogram here)
10570    cout<<"from Q-vectors    = "<<fIntFlowCorrectionTermsForNUAPro[sc]->GetBinContent(ci)<<endl; // to be improved (access finalized histogram here)
10571    cout<<"from nested loops = "<<fIntFlowDirectCorrectionTermsForNUA[sc]->GetBinContent(ci)<<endl;
10572    cout<<endl;
10573   } // end of for(Int_t sc=0;sc<2;sc++) // sin or cos term
10574  } // end of for(Int_t ci=1;ci<=10;ci++) // correction term index
10575   
10576 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowCorrectionTermsForNUA() 
10577
10578
10579 //================================================================================================================================
10580
10581
10582 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
10583 {
10584  // Evaluate with nested loops multiparticle correlations for integrated flow (using the particle weights). 
10585
10586  // Results are stored in profile fIntFlowDirectCorrelations. 
10587  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrelations is organized as follows:
10588  //
10589  //  1st bin: <2>_{1n|1n} = two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
10590  //  2nd bin: <2>_{2n|2n} = two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
10591  //  3rd bin: <2>_{3n|3n} = two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))> 
10592  //  4th bin: <2>_{4n|4n} = two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
10593  //  5th bin:           ----  EMPTY ----
10594  //  6th bin: <3>_{2n|1n,1n} = three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
10595  //  7th bin: <3>_{3n|2n,1n} = ...
10596  //  8th bin: <3>_{4n|2n,2n} = ...
10597  //  9th bin: <3>_{4n|3n,1n} = ...
10598  // 10th bin:           ----  EMPTY ----
10599  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
10600  // 12th bin: <4>_{2n,1n|2n,1n} = ...
10601  // 13th bin: <4>_{2n,2n|2n,2n} = ...
10602  // 14th bin: <4>_{3n|1n,1n,1n} = ... 
10603  // 15th bin: <4>_{3n,1n|3n,1n} = ...
10604  // 16th bin: <4>_{3n,1n|2n,2n} = ...
10605  // 17th bin: <4>_{4n|2n,1n,1n} = ... 
10606  // 18th bin:           ----  EMPTY ----
10607  // 19th bin: <5>_{2n|1n,1n,1n,1n} = ...
10608  // 20th bin: <5>_{2n,2n|2n,1n,1n} = ...
10609  // 21st bin: <5>_{3n,1n|2n,1n,1n} = ...
10610  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = ...
10611  // 23rd bin:           ----  EMPTY ----
10612  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = ...
10613  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = ...
10614  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = ...
10615  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = ...
10616  // 28th bin:           ----  EMPTY ----
10617  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = ...
10618  // 30th bin:           ----  EMPTY ----
10619  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = ...
10620  
10621  // Remark 2: When particle weights are used there are some extra correlations. They are stored in 
10622  // fIntFlowExtraDirectCorrelations binning of which is organized as follows:
10623  
10624  // 1st bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
10625  // 2nd bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
10626  // ...
10627  
10628  Int_t nPrim = anEvent->NumberOfTracks(); 
10629  AliFlowTrackSimple *aftsTrack = NULL;
10630  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
10631  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
10632  Double_t phi1=0., phi2=0., phi3=0., phi4=0.;
10633  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1.;
10634  Int_t n = fHarmonic; 
10635  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
10636  Double_t dMult = (*fSMpk)(0,0);
10637  cout<<endl;
10638  cout<<"Multiparticle correlations: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
10639  if(dMult<2)
10640  {
10641   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
10642  } else if (dMult>fMaxAllowedMultiplicity)
10643    {
10644     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
10645    } else 
10646      { 
10647       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
10648      } 
10649       
10650  // 2-particle correlations:       
10651  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10652  {
10653   // 2 nested loops multiparticle correlations using particle weights:       
10654   for(Int_t i1=0;i1<nPrim;i1++)
10655   {
10656    aftsTrack=anEvent->GetTrack(i1);
10657    if(!(aftsTrack->InRPSelection())) continue;
10658    phi1=aftsTrack->Phi();
10659    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10660    for(Int_t i2=0;i2<nPrim;i2++)
10661    {
10662     if(i2==i1)continue;
10663     aftsTrack=anEvent->GetTrack(i2);
10664     if(!(aftsTrack->InRPSelection())) continue;
10665     phi2=aftsTrack->Phi();
10666     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
10667     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10668     // 2-p correlations using particle weights:
10669     if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),wPhi1*wPhi2);                  // <w1   w2   cos( n*(phi1-phi2))>
10670     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))>
10671     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))>
10672     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))> 
10673     // extra correlations: 
10674     // 2-p extra correlations (do not appear if particle weights are not used):
10675     if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),pow(wPhi1,3)*wPhi2); // <w1^3 w2 cos(n*(phi1-phi2))>
10676     // ...
10677    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10678   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10679  } // end of if(nPrim>=2)
10680
10681  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10682  { 
10683   // 3 nested loops multiparticle correlations using particle weights:       
10684   for(Int_t i1=0;i1<nPrim;i1++)
10685   {
10686    aftsTrack=anEvent->GetTrack(i1);
10687    if(!(aftsTrack->InRPSelection())) continue;
10688    phi1=aftsTrack->Phi();
10689    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10690    for(Int_t i2=0;i2<nPrim;i2++)
10691    {
10692     if(i2==i1)continue;
10693     aftsTrack=anEvent->GetTrack(i2);
10694     if(!(aftsTrack->InRPSelection())) continue;
10695     phi2=aftsTrack->Phi();
10696     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
10697     for(Int_t i3=0;i3<nPrim;i3++)
10698     {
10699      if(i3==i1||i3==i2)continue;
10700      aftsTrack=anEvent->GetTrack(i3);
10701      if(!(aftsTrack->InRPSelection())) continue;
10702      phi3=aftsTrack->Phi();
10703      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
10704      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
10705      // 3-p correlations using particle weights:
10706      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))>
10707      // ...
10708      // extra correlations: 
10709      // 2-p extra correlations (do not appear if particle weights are not used):
10710       if(fUsePhiWeights) fIntFlowExtraDirectCorrelations->Fill(1.5,cos(n*(phi1-phi2)),wPhi1*wPhi2*pow(wPhi3,2)); // <w1 w2 w3^2 cos(n*(phi1-phi2))>
10711      // ...
10712      // 3-p extra correlations (do not appear if particle weights are not used):
10713      // ...
10714     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10715    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10716   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10717  } // end of if(nPrim>=3)
10718  
10719  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
10720  {
10721   // 4 nested loops multiparticle correlations using particle weights:       
10722   for(Int_t i1=0;i1<nPrim;i1++)
10723   {
10724    aftsTrack=anEvent->GetTrack(i1);
10725    if(!(aftsTrack->InRPSelection())) continue;
10726    phi1=aftsTrack->Phi();
10727    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
10728    for(Int_t i2=0;i2<nPrim;i2++)
10729    {
10730     if(i2==i1)continue;
10731     aftsTrack=anEvent->GetTrack(i2);
10732     if(!(aftsTrack->InRPSelection())) continue;
10733     phi2=aftsTrack->Phi();
10734     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
10735     for(Int_t i3=0;i3<nPrim;i3++)
10736     {
10737      if(i3==i1||i3==i2)continue;
10738      aftsTrack=anEvent->GetTrack(i3);
10739      if(!(aftsTrack->InRPSelection())) continue;
10740      phi3=aftsTrack->Phi();
10741      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
10742      for(Int_t i4=0;i4<nPrim;i4++)
10743      {
10744       if(i4==i1||i4==i2||i4==i3)continue;
10745       aftsTrack=anEvent->GetTrack(i4);
10746       if(!(aftsTrack->InRPSelection())) continue;
10747       phi4=aftsTrack->Phi();
10748       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
10749       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
10750       // 4-p correlations using particle weights:
10751       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
10752       // extra correlations: 
10753       // 2-p extra correlations (do not appear if particle weights are not used):
10754       // ...
10755       // 3-p extra correlations (do not appear if particle weights are not used):
10756       // ...
10757       // 4-p extra correlations (do not appear if particle weights are not used):
10758       // ...
10759      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
10760     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10761    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10762   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10763  } // end of if(nPrim>=4)
10764
10765  cout<<endl; 
10766
10767 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
10768
10769
10770 //================================================================================================================================
10771
10772
10773 void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
10774 {
10775  // Cross-check results for extra multiparticle correlations needed for int. flow 
10776  // which appear only when particle weights are used: results from Q-vectors vs results from nested loops.
10777
10778  cout<<endl;
10779  cout<<endl;
10780  cout<<"   ***********************************************"<<endl;
10781  cout<<"   **** cross-checking the extra correlations ****"<<endl;
10782  cout<<"   ****          for integrated flow          ****"<<endl;
10783  cout<<"   ***********************************************"<<endl;
10784  cout<<endl;
10785  cout<<endl;
10786  
10787  for(Int_t eci=1;eci<=2;eci++) // to be improved (increased eciMax eventually when I calculate 6th and 8th)
10788  {
10789   if(strcmp((fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci), "") == 0) continue;
10790   cout<<(fIntFlowExtraCorrelationsPro->GetXaxis())->GetBinLabel(eci)<<":"<<endl;
10791   cout<<"from Q-vectors    = "<<fIntFlowExtraCorrelationsPro->GetBinContent(eci)<<endl;
10792   cout<<"from nested loops = "<<fIntFlowExtraDirectCorrelations->GetBinContent(eci)<<endl;
10793   cout<<endl;
10794  }
10795
10796 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckIntFlowExtraCorrelations()
10797
10798
10799 //================================================================================================================================
10800
10801
10802 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent)
10803 {
10804  // Evaluate with nested loops correction terms for non-uniform acceptance relevant for NONAME integrated flow (to be improved (name)).
10805  //
10806  // Remark: Both sin and cos correction terms are calculated in this method. Sin terms are stored in fIntFlowDirectCorrectionTermsForNUA[0],
10807  // and cos terms in fIntFlowDirectCorrectionTermsForNUA[1]. Binning of fIntFlowDirectCorrectionTermsForNUA[sc] is organized as follows 
10808  // (sc stands for either sin or cos):
10809  
10810  //  1st bin: <<sc(n*(phi1))>> 
10811  //  2nd bin: <<sc(n*(phi1+phi2))>> 
10812  //  3rd bin: <<sc(n*(phi1-phi2-phi3))>>
10813  //  4th bin: <<sc(n*(2phi1-phi2))>>
10814  
10815  Int_t nPrim = anEvent->NumberOfTracks(); 
10816  AliFlowTrackSimple *aftsTrack = NULL;
10817  Double_t phi1=0., phi2=0., phi3=0.;
10818  Int_t n = fHarmonic; 
10819  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
10820  Double_t dMult = (*fSMpk)(0,0);
10821  cout<<endl;
10822  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
10823  if(dMult<1)
10824  {
10825   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
10826  } else if (dMult>fMaxAllowedMultiplicity)
10827    {
10828     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
10829    } else 
10830      { 
10831       cout<<"... evaluating nested loops (without using particle weights)..."<<endl;
10832      }
10833  
10834  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
10835  {
10836   // 1-particle correction terms for non-uniform acceptance:       
10837   for(Int_t i1=0;i1<nPrim;i1++)
10838   {
10839    aftsTrack=anEvent->GetTrack(i1);
10840    if(!(aftsTrack->InRPSelection())) continue;
10841    phi1=aftsTrack->Phi();
10842    if(nPrim==1) cout<<i1<<"\r"<<flush;
10843    // sin terms:
10844    fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),1.); // <sin(n*phi1)>  
10845    // cos terms:
10846    fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),1.); // <cos(n*phi1)>
10847   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10848  } // end of if(nPrim>=1) 
10849   
10850  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
10851  {
10852   // 2-particle correction terms for non-uniform acceptance:       
10853   for(Int_t i1=0;i1<nPrim;i1++)
10854   {
10855    aftsTrack=anEvent->GetTrack(i1);
10856    if(!(aftsTrack->InRPSelection())) continue;
10857    phi1=aftsTrack->Phi();  
10858    for(Int_t i2=0;i2<nPrim;i2++)
10859    {
10860     if(i2==i1)continue;
10861     aftsTrack=anEvent->GetTrack(i2);
10862     if(!(aftsTrack->InRPSelection())) continue;
10863     phi2=aftsTrack->Phi();
10864     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
10865     // sin terms:
10866     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),1.); // <<sin(n*(phi1+phi2))>>
10867     fIntFlowDirectCorrectionTermsForNUA[0]->Fill(3.5,sin(n*(2*phi1-phi2)),1.); // <<sin(n*(2*phi1-phi2))>>
10868     // cos terms:
10869     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),1.); // <<cos(n*(phi1+phi2))>>
10870     fIntFlowDirectCorrectionTermsForNUA[1]->Fill(3.5,cos(n*(2*phi1-phi2)),1.); // <<cos(n*(2*phi1-phi2))>>
10871    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10872   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10873  } // end of if(nPrim>=2)
10874
10875  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
10876  {
10877   // 3-particle correction terms for non-uniform acceptance:       
10878   for(Int_t i1=0;i1<nPrim;i1++)
10879   {
10880    aftsTrack=anEvent->GetTrack(i1);
10881    if(!(aftsTrack->InRPSelection())) continue;
10882    phi1=aftsTrack->Phi();
10883    for(Int_t i2=0;i2<nPrim;i2++)
10884    {
10885     if(i2==i1)continue;
10886     aftsTrack=anEvent->GetTrack(i2);
10887     if(!(aftsTrack->InRPSelection())) continue;
10888     phi2=aftsTrack->Phi();
10889     for(Int_t i3=0;i3<nPrim;i3++)
10890     {
10891      if(i3==i1||i3==i2)continue;
10892      aftsTrack=anEvent->GetTrack(i3);
10893      if(!(aftsTrack->InRPSelection())) continue;
10894      phi3=aftsTrack->Phi();
10895      if(nPrim>=3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush; // to be improved (eventually I will change this if statement)
10896      // sin terms:
10897      fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),1.); // <<sin(n*(phi1-phi2-phi3))>>
10898      // cos terms:
10899      fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),1.); // <<cos(n*(phi1-phi2-phi3))>>
10900     } // end of for(Int_t i3=0;i3<nPrim;i3++)
10901    } // end of for(Int_t i2=0;i2<nPrim;i2++)
10902   } // end of for(Int_t i1=0;i1<nPrim;i1++)
10903  } // end of if(nPrim>=3)
10904
10905  cout<<endl;
10906 }
10907 //================================================================================================================================
10908 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
10909 {
10910  // Evaluate reduced correlations with nested loops without using the particle weights.
10911  
10912  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
10913  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
10914  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
10915  // Remark 3: <2'> = <cos(n*(psi1-phi2))>
10916  //           <4'> = <cos(n*(psi1+phi2-phi3-phi4))>
10917  // ...
10918  
10919  Int_t typeFlag = -1;
10920  Int_t ptEtaFlag = -1;
10921  if(type == "RP")
10922  {
10923   typeFlag = 0;
10924  } else if(type == "POI")
10925    {
10926     typeFlag = 1;
10927    }      
10928  if(ptOrEta == "Pt")
10929  {
10930   ptEtaFlag = 0;
10931  } else if(ptOrEta == "Eta")
10932    {
10933     ptEtaFlag = 1;
10934    } 
10935  // shortcuts:
10936  Int_t t = typeFlag;
10937  Int_t pe = ptEtaFlag;
10938       
10939  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
10940  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
10941  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
10942  
10943  Int_t nPrim = anEvent->NumberOfTracks(); 
10944  AliFlowTrackSimple *aftsTrack = NULL;
10945  
10946  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
10947  
10948  Int_t n = fHarmonic; 
10949   
10950  // 2'-particle correlations:
10951  for(Int_t i1=0;i1<nPrim;i1++)
10952  {
10953   aftsTrack=anEvent->GetTrack(i1);
10954   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
10955   if(typeFlag==1) // this is diff flow of POIs 
10956   {
10957    if(ptOrEta == "Pt")
10958    { 
10959     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
10960    } else if (ptOrEta == "Eta")
10961      {
10962       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
10963      }
10964   } else // this is diff flow of RPs 
10965     {
10966      if(ptOrEta == "Pt")
10967      { 
10968       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
10969      } else if (ptOrEta == "Eta")
10970        {
10971         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
10972        }
10973     }
10974        
10975   psi1=aftsTrack->Phi(); 
10976   for(Int_t i2=0;i2<nPrim;i2++)
10977   {
10978    if(i2==i1)continue;
10979    aftsTrack=anEvent->GetTrack(i2);
10980    // RP condition (!(first) particle in the correlator must be RP):
10981    if(!(aftsTrack->InRPSelection()))continue;
10982    phi2=aftsTrack->Phi();   
10983    // 2'-particle correlations: 
10984    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),1.); // <cos(n*(psi1-phi2))  
10985   }//end of for(Int_t i2=0;i2<nPrim;i2++)
10986  }//end of for(Int_t i1=0;i1<nPrim;i1++)
10987  
10988  /*
10989  
10990  // 3'-particle correlations:
10991  for(Int_t i1=0;i1<nPrim;i1++)
10992  {
10993   aftsTrack=anEvent->GetTrack(i1);
10994   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
10995   if(ptOrEta == "Pt")
10996   { 
10997    if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
10998   } else if (ptOrEta == "Eta")
10999     {
11000      if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11001     }
11002   psi1=aftsTrack->Phi();
11003   for(Int_t i2=0;i2<nPrim;i2++)
11004   {
11005    if(i2==i1)continue;
11006    aftsTrack=anEvent->GetTrack(i2);
11007    // RP condition (!(first) particle in the correlator must be RP):
11008    if(!(aftsTrack->InRPSelection())) continue;
11009    phi2=aftsTrack->Phi();
11010    for(Int_t i3=0;i3<nPrim;i3++)
11011    {
11012     if(i3==i1||i3==i2)continue;
11013     aftsTrack=anEvent->GetTrack(i3);
11014     // RP condition (!(first) particle in the correlator must be RP):
11015     if(!(aftsTrack->InRPSelection())) continue;
11016     phi3=aftsTrack->Phi();
11017     // 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))> 
11018    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
11019   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
11020  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11021  
11022  */
11023  
11024  // 4'-particle correlations:
11025  for(Int_t i1=0;i1<nPrim;i1++)
11026  {
11027   aftsTrack=anEvent->GetTrack(i1);
11028   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11029   if(typeFlag==1) // this is diff flow of POIs 
11030   {
11031    if(ptOrEta == "Pt")
11032    { 
11033     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11034    } else if (ptOrEta == "Eta")
11035      {
11036       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11037      }
11038   } else // this is diff flow of RPs 
11039     {
11040      if(ptOrEta == "Pt")
11041      { 
11042       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11043      } else if (ptOrEta == "Eta")
11044        {
11045         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11046        }
11047     }
11048     
11049   psi1=aftsTrack->Phi();
11050   for(Int_t i2=0;i2<nPrim;i2++)
11051   {
11052    if(i2==i1) continue;
11053    aftsTrack=anEvent->GetTrack(i2);
11054    // RP condition (!(first) particle in the correlator must be RP): 
11055    if(!(aftsTrack->InRPSelection())) continue;
11056    phi2=aftsTrack->Phi();
11057    for(Int_t i3=0;i3<nPrim;i3++)
11058    { 
11059     if(i3==i1||i3==i2) continue;
11060     aftsTrack=anEvent->GetTrack(i3);
11061     // RP condition (!(first) particle in the correlator must be RP):
11062     if(!(aftsTrack->InRPSelection())) continue;
11063     phi3=aftsTrack->Phi();
11064     for(Int_t i4=0;i4<nPrim;i4++)
11065     {
11066      if(i4==i1||i4==i2||i4==i3) continue;
11067      aftsTrack=anEvent->GetTrack(i4);
11068      // RP condition (!(first) particle in the correlator must be RP):
11069      if(!(aftsTrack->InRPSelection())) continue;  
11070      phi4=aftsTrack->Phi();
11071      // 4'-particle correlations:
11072      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),1.); // <cos(n(psi1+phi2-phi3-phi4))>     
11073     }//end of for(Int_t i4=0;i4<nPrim;i4++)
11074    }//end of for(Int_t i3=0;i3<nPrim;i3++)
11075   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
11076  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11077       
11078  // count # of RPs and POIs in selected pt and eta bins for cross-checkings:
11079  for(Int_t i=0;i<nPrim;i++)
11080  {
11081   aftsTrack=anEvent->GetTrack(i); 
11082   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11083   if(typeFlag==1) // this is diff flow of POIs 
11084   {
11085    if(ptOrEta == "Pt")
11086    { 
11087     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11088    } else if (ptOrEta == "Eta")
11089      {
11090       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11091      }
11092   } else // this is diff flow of RPs 
11093     {
11094      if(ptOrEta == "Pt")
11095      { 
11096       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11097      } else if (ptOrEta == "Eta")
11098        {
11099         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11100        }
11101     }
11102   if(t==1)t++; 
11103   fNoOfParticlesInBin->Fill(t+pe+0.5);  
11104  }
11105
11106 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11107
11108
11109 //================================================================================================================================
11110
11111
11112 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
11113 {
11114  // Compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
11115  
11116  Int_t typeFlag = -1;
11117  Int_t ptEtaFlag = -1;
11118  if(type == "RP")
11119  {
11120   typeFlag = 0;
11121  } else if(type == "POI")
11122    {
11123     typeFlag = 1;
11124    }      
11125  if(ptOrEta == "Pt")
11126  {
11127   ptEtaFlag = 0;
11128  } else if(ptOrEta == "Eta")
11129    {
11130     ptEtaFlag = 1;
11131    } 
11132  // shortcuts:
11133  Int_t t = typeFlag;
11134  Int_t pe = ptEtaFlag;
11135       
11136  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11137  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11138  TString reducedCorrelations[4] = {"<<cos(n(psi1-phi2))>>","<<cos(n(psi1+phi2-phi3-phi4))>>","",""}; // to be improved (access this from pro or hist)
11139  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11140  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11141  
11142  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
11143  
11144
11145  cout<<endl;
11146  cout<<"   *****************************************"<<endl;
11147  cout<<"   **** cross-checking the correlations ****"<<endl;
11148  cout<<"   ****   for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
11149  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
11150  {
11151   cout<<"   ****   (particle weights not used)   ****"<<endl;
11152  } else
11153    {
11154     cout<<"   ****    (particle weights used)      ****"<<endl;
11155    } 
11156  cout<<"   *****************************************"<<endl; 
11157  cout<<endl;
11158  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
11159  cout<<endl;
11160  
11161  for(Int_t rci=0;rci<2;rci++) // to be improved (calculate 6th and 8th order)
11162  {
11163   cout<<"      "<<reducedCorrelations[rci].Data()<<":"<<endl;
11164   cout<<"      from Q-vectors    = "<<fDiffFlowCorrelationsPro[t][pe][rci]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
11165   cout<<"      from nested loops = "<<fDiffFlowDirectCorrelations[t][pe][rci]->GetBinContent(1)<<endl;
11166   cout<<endl;  
11167  } // end of for(Int_t rci=0;rci<4;rci++)
11168         
11169 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrelations(TString type, TString ptOrEta)
11170
11171 //================================================================================================================================
11172
11173 void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
11174 {
11175  // Print on the screen number of RPs and POIs in selected pt and eta bin for cross checkings.
11176  
11177  cout<<endl;
11178  cout<<"Number of RPs in selected pt bin   = "<<fNoOfParticlesInBin->GetBinContent(1)<<endl;
11179  cout<<"Number of RPs in selected eta bin  = "<<fNoOfParticlesInBin->GetBinContent(2)<<endl;
11180  cout<<"Number of POIs in selected pt bin  = "<<fNoOfParticlesInBin->GetBinContent(3)<<endl;
11181  cout<<"Number of POIs in selected eta bin = "<<fNoOfParticlesInBin->GetBinContent(4)<<endl;
11182  
11183 } // end of void AliFlowAnalysisWithQCumulants::PrintNumberOfParticlesInSelectedBin()
11184
11185 //================================================================================================================================
11186
11187 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11188 {
11189  // Evaluate reduced correlations with nested loops without using the particle weights.
11190  
11191  // Remark 1: Reduced correlations are evaluated in pt bin number fCrossCheckInPtBinNo and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11192  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrelations[t][pe][ci], where indices runs as follows:
11193  //           [0=RP,1=POI][0=Pt,1=Eta][0=<2'>,1=<4'>,2=<6'>,3=<8'>] 
11194  // Remark 3: <2'> = <w2 cos(n*(psi1-phi2))>
11195  //           <4'> = <w2 w3 w4 cos(n*(psi1+phi2-phi3-phi4))>
11196  // ...
11197   
11198  Int_t typeFlag = -1;
11199  Int_t ptEtaFlag = -1;
11200  if(type == "RP")
11201  {
11202   typeFlag = 0;
11203  } else if(type == "POI")
11204    {
11205     typeFlag = 1;
11206    }      
11207  if(ptOrEta == "Pt")
11208  {
11209   ptEtaFlag = 0;
11210  } else if(ptOrEta == "Eta")
11211    {
11212     ptEtaFlag = 1;
11213    } 
11214  // shortcuts:
11215  Int_t t = typeFlag;
11216  Int_t pe = ptEtaFlag;
11217       
11218  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11219  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11220  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11221  
11222  Int_t nPrim = anEvent->NumberOfTracks(); 
11223  AliFlowTrackSimple *aftsTrack = NULL;
11224  
11225  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11226  Double_t wPhi2=1., wPhi3=1., wPhi4=1.;// wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
11227  
11228  Int_t n = fHarmonic; 
11229  
11230  // 2'-particle correlations:
11231  for(Int_t i1=0;i1<nPrim;i1++)
11232  {
11233   aftsTrack=anEvent->GetTrack(i1);
11234   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11235   if(typeFlag==1) // this is diff flow of POIs 
11236   {
11237    if(ptOrEta == "Pt")
11238    { 
11239     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11240    } else if (ptOrEta == "Eta")
11241      {
11242       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11243      }
11244   } else // this is diff flow of RPs 
11245     {
11246      if(ptOrEta == "Pt")
11247      { 
11248       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11249      } else if (ptOrEta == "Eta")
11250        {
11251         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11252        }
11253     }
11254   psi1=aftsTrack->Phi(); 
11255   for(Int_t i2=0;i2<nPrim;i2++)
11256   {
11257    if(i2==i1) continue;
11258    aftsTrack=anEvent->GetTrack(i2);
11259    // RP condition (!(first) particle in the correlator must be RP):
11260    if(!(aftsTrack->InRPSelection())) continue;
11261    phi2=aftsTrack->Phi();   
11262    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11263    // 2'-particle correlations: 
11264    fDiffFlowDirectCorrelations[t][pe][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(1.*n*(psi1-phi2)),wPhi2); // <w2 cos(n*(psi1-phi2))  
11265   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11266  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11267  
11268  // 4'-particle correlations:
11269  for(Int_t i1=0;i1<nPrim;i1++)
11270  {
11271   aftsTrack=anEvent->GetTrack(i1);
11272   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11273   if(typeFlag==1) // this is diff flow of POIs 
11274   {
11275    if(ptOrEta == "Pt")
11276    { 
11277     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11278    } else if (ptOrEta == "Eta")
11279      {
11280       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11281      }
11282   } else // this is diff flow of RPs 
11283     {
11284      if(ptOrEta == "Pt")
11285      { 
11286       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11287      } else if (ptOrEta == "Eta")
11288        {
11289         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11290        }
11291     }
11292   psi1=aftsTrack->Phi();
11293   for(Int_t i2=0;i2<nPrim;i2++)
11294   {
11295    if(i2==i1) continue;
11296    aftsTrack=anEvent->GetTrack(i2);
11297    // RP condition (!(first) particle in the correlator must be RP): 
11298    if(!(aftsTrack->InRPSelection())) continue;
11299    phi2=aftsTrack->Phi();
11300    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11301    for(Int_t i3=0;i3<nPrim;i3++)
11302    { 
11303     if(i3==i1||i3==i2) continue;
11304     aftsTrack=anEvent->GetTrack(i3);
11305     // RP condition (!(first) particle in the correlator must be RP):
11306     if(!(aftsTrack->InRPSelection())) continue;
11307     phi3=aftsTrack->Phi();
11308     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11309     for(Int_t i4=0;i4<nPrim;i4++)
11310     {
11311      if(i4==i1||i4==i2||i4==i3) continue;
11312      aftsTrack=anEvent->GetTrack(i4);
11313      // RP condition (!(first) particle in the correlator must be RP):
11314      if(!(aftsTrack->InRPSelection())) continue;  
11315      phi4=aftsTrack->Phi();
11316      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
11317      // 4'-particle correlations <w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))>:
11318      fDiffFlowDirectCorrelations[t][pe][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3-phi4)),wPhi2*wPhi3*wPhi4); 
11319     }//end of for(Int_t i4=0;i4<nPrim;i4++)
11320    }//end of for(Int_t i3=0;i3<nPrim;i3++)
11321   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
11322  }//end of for(Int_t i1=0;i1<nPrim;i1++)      
11323  
11324  // count # of RPs and POIs in selected pt and eta bins for cross-checkings: (to be improved - moved to dedicated method)
11325  for(Int_t i=0;i<nPrim;i++)
11326  {
11327   aftsTrack=anEvent->GetTrack(i); 
11328   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11329   if(typeFlag==1) // this is diff flow of POIs 
11330   {
11331    if(ptOrEta == "Pt")
11332    { 
11333     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11334    } else if (ptOrEta == "Eta")
11335      {
11336       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11337      }
11338   } else // this is diff flow of RPs 
11339     {
11340      if(ptOrEta == "Pt")
11341      { 
11342       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11343      } else if (ptOrEta == "Eta")
11344        {
11345         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11346        }
11347     }
11348   if(t==1)t++; 
11349   fNoOfParticlesInBin->Fill(t+pe+0.5);  
11350  }
11351  
11352 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrelationsWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11353
11354
11355 //================================================================================================================================
11356
11357    
11358 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
11359 {
11360  // Evaluate with nested loops correction terms for non-uniform acceptance (both sin and cos terms) relevant for differential flow.
11361  
11362  // Remark 1: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
11363  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
11364  // Remark 2: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
11365  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
11366  //  cti: 
11367  //    0: <<sc n(psi1)>>
11368  //    1: <<sc n(psi1+phi2)>> 
11369  //    2: <<sc n(psi1+phi2-phi3)>>
11370  //    3: <<sc n(psi1-phi2-phi3)>>
11371  //    4:
11372  //    5:
11373  //    6:
11374   
11375  Int_t typeFlag = -1;
11376  Int_t ptEtaFlag = -1;
11377  if(type == "RP")
11378  {
11379   typeFlag = 0;
11380  } else if(type == "POI")
11381    {
11382     typeFlag = 1;
11383    }      
11384  if(ptOrEta == "Pt")
11385  {
11386   ptEtaFlag = 0;
11387  } else if(ptOrEta == "Eta")
11388    {
11389     ptEtaFlag = 1;
11390    } 
11391  // shortcuts:
11392  Int_t t = typeFlag;
11393  Int_t pe = ptEtaFlag;
11394       
11395  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11396  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11397  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
11398  
11399  Int_t nPrim = anEvent->NumberOfTracks(); 
11400  AliFlowTrackSimple *aftsTrack = NULL;
11401  
11402  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
11403  
11404  Int_t n = fHarmonic; 
11405  
11406  // 1-particle correction terms:
11407  for(Int_t i1=0;i1<nPrim;i1++)
11408  {
11409   aftsTrack=anEvent->GetTrack(i1);
11410   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11411   if(typeFlag==1) // this is diff flow of POIs 
11412   {
11413    if(ptOrEta == "Pt")
11414    { 
11415     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11416    } else if (ptOrEta == "Eta")
11417      {
11418       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11419      }
11420   } else // this is diff flow of RPs 
11421     {
11422      if(ptOrEta == "Pt")
11423      { 
11424       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11425      } else if (ptOrEta == "Eta")
11426        {
11427         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11428        }
11429     }
11430   psi1=aftsTrack->Phi(); 
11431   // sin terms: 
11432   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
11433   // cos terms: 
11434   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
11435  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11436    
11437  // 2-particle correction terms:
11438  for(Int_t i1=0;i1<nPrim;i1++)
11439  {
11440   aftsTrack=anEvent->GetTrack(i1);
11441    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11442   if(typeFlag==1) // this is diff flow of POIs 
11443   {
11444    if(ptOrEta == "Pt")
11445    { 
11446     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11447    } else if (ptOrEta == "Eta")
11448      {
11449       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11450      }
11451   } else // this is diff flow of RPs 
11452     {
11453      if(ptOrEta == "Pt")
11454      { 
11455       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11456      } else if (ptOrEta == "Eta")
11457        {
11458         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11459        }
11460     }
11461   psi1=aftsTrack->Phi(); 
11462   for(Int_t i2=0;i2<nPrim;i2++)
11463   {
11464    if(i2==i1) continue;
11465    aftsTrack=anEvent->GetTrack(i2);
11466    // RP condition (!(first) particle in the correlator must be RP):
11467    if(!(aftsTrack->InRPSelection())) continue;
11468    phi2=aftsTrack->Phi();   
11469    // sin terms: 
11470    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),1.); // <<sin(n*(psi1+phi2))>>  
11471    // cos terms: 
11472    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),1.); // <<cos(n*(psi1+phi2))>>  
11473   }//end of for(Int_t i2=0;i2<nPrim;i2++)
11474  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
11475  
11476  // 3-particle correction terms:
11477  for(Int_t i1=0;i1<nPrim;i1++)
11478  {
11479   aftsTrack=anEvent->GetTrack(i1);
11480    // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
11481   if(typeFlag==1) // this is diff flow of POIs 
11482   {
11483    if(ptOrEta == "Pt")
11484    { 
11485     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
11486    } else if (ptOrEta == "Eta")
11487      {
11488       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
11489      }
11490   } else // this is diff flow of RPs 
11491     {
11492      if(ptOrEta == "Pt")
11493      { 
11494       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
11495      } else if (ptOrEta == "Eta")
11496        {
11497         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
11498        }
11499     }
11500   psi1=aftsTrack->Phi();
11501   for(Int_t i2=0;i2<nPrim;i2++)
11502   {
11503    if(i2==i1) continue;
11504    aftsTrack=anEvent->GetTrack(i2);
11505    // RP condition (!(first) particle in the correlator must be RP):
11506    if(!(aftsTrack->InRPSelection())) continue;
11507    phi2=aftsTrack->Phi();
11508    for(Int_t i3=0;i3<nPrim;i3++)
11509    {
11510     if(i3==i1||i3==i2) continue;
11511     aftsTrack=anEvent->GetTrack(i3);
11512     // RP condition (!(first) particle in the correlator must be RP):
11513     if(!(aftsTrack->InRPSelection())) continue;
11514     phi3=aftsTrack->Phi();
11515     // sin terms: 
11516     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2-phi3)),1.); // <<sin(n*(psi1+phi2-phi3))>>  
11517     fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1-phi2-phi3)),1.); // <<sin(n*(psi1-phi2-phi3))>>  
11518     // cos terms: 
11519     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][2]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2-phi3)),1.); // <<cos(n*(psi1+phi2-phi3))>>  
11520     fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][3]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1-phi2-phi3)),1.); // <<cos(n*(psi1-phi2-phi3))>>  
11521    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
11522   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
11523  }//end of for(Int_t i1=0;i1<nPrim;i1++)
11524    
11525 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoops(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
11526
11527
11528 //================================================================================================================================
11529
11530
11531 void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
11532 {
11533  // Compare corrections temrs for non-uniform acceptance needed for diff. flow calculated with nested loops and those calculated from Q-vectors
11534  
11535  Int_t typeFlag = -1;
11536  Int_t ptEtaFlag = -1;
11537  if(type == "RP")
11538  {
11539   typeFlag = 0;
11540  } else if(type == "POI")
11541    {
11542     typeFlag = 1;
11543    }      
11544  if(ptOrEta == "Pt")
11545  {
11546   ptEtaFlag = 0;
11547  } else if(ptOrEta == "Eta")
11548    {
11549     ptEtaFlag = 1;
11550    } 
11551  // shortcuts:
11552  Int_t t = typeFlag;
11553  Int_t pe = ptEtaFlag;
11554       
11555  TString rpORpoiString[2] = {"RP ","POI"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11556  TString ptORetaString[2] = {"pt","eta"}; // to be improved (name in the same way as in the other methods, eventually promote to data member) 
11557  //TString sinCosFlag[2] = {"sin","cos"}; // to be improved (eventually promote to data member)
11558  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)
11559  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)
11560  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
11561  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
11562  
11563  Int_t crossCheckInPtEtaBinNo[2] = {fCrossCheckInPtBinNo,fCrossCheckInEtaBinNo};
11564  
11565  cout<<endl;
11566  cout<<"   ******************************************"<<endl;
11567  cout<<"   ****  cross-checking the correction   ****"<<endl;
11568  cout<<"   **** terms for non-uniform acceptance ****"<<endl; 
11569  cout<<"   ****    for differential flow ("<<rpORpoiString[t]<<")   ****"<<endl;
11570  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
11571  {
11572   cout<<"   ****    (particle weights not used)   ****"<<endl;
11573  } else
11574    {
11575     cout<<"   ****     (particle weights used)      ****"<<endl;
11576    } 
11577  cout<<"   ******************************************"<<endl; 
11578  cout<<endl;
11579  cout<<"           "<<ptORetaString[pe]<<" bin: "<<lowerPtEtaEdge[pe]<<" <= "<<ptORetaString[pe]<<" < "<<upperPtEtaEdge[pe]<<endl;
11580  cout<<endl;
11581  
11582  for(Int_t cti=0;cti<4;cti++) // correction term index
11583  {
11584   for(Int_t sc=0;sc<2;sc++) // sin or cos terms
11585   {
11586    if(sc==0) // to be improved (this can be implemented better)
11587    { 
11588     cout<<"      "<<reducedCorrectionSinTerms[cti].Data()<<":"<<endl;
11589    } else
11590      {
11591       cout<<"      "<<reducedCorrectionCosTerms[cti].Data()<<":"<<endl;     
11592      }
11593    cout<<"      from Q-vectors    = "<<fDiffFlowCorrectionTermsForNUAPro[t][pe][sc][cti]->GetBinContent(crossCheckInPtEtaBinNo[pe])<<endl;
11594    cout<<"      from nested loops = "<<fDiffFlowDirectCorrectionTermsForNUA[t][pe][sc][cti]->GetBinContent(1)<<endl;
11595    cout<<endl;  
11596   } 
11597  } // end of for(Int_t rci=0;rci<4;rci++)
11598
11599 } // end of void AliFlowAnalysisWithQCumulants::CrossCheckDiffFlowCorrectionTermsForNUA(TString type, TString ptOrEta)
11600
11601
11602 //================================================================================================================================
11603
11604
11605 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
11606 {
11607  // Calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (cos terms).
11608  
11609  //                                  **********************************************************************
11610  //                                  **** weighted corrections for non-uniform acceptance (cos terms): ****
11611  //                                  **********************************************************************
11612  
11613  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[1] is organized as follows:
11614  //
11615  // 1st bin: <<w1 cos(n*(phi1))>> = cosP1nW1
11616  // 2nd bin: <<w1 w2 cos(n*(phi1+phi2))>> = cosP1nP1nW1W1
11617  // 3rd bin: <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1nW1W1W1 
11618  // ...
11619
11620  // multiplicity (number of particles used to determine the reaction plane)
11621  Double_t dMult = (*fSMpk)(0,0);
11622  
11623  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
11624  Double_t dReQ1n1k = (*fReQ)(0,1);
11625  Double_t dReQ2n2k = (*fReQ)(1,2);
11626  //Double_t dReQ3n3k = (*fReQ)(2,3);
11627  //Double_t dReQ4n4k = (*fReQ)(3,4);
11628  Double_t dReQ1n3k = (*fReQ)(0,3);
11629  Double_t dImQ1n1k = (*fImQ)(0,1);
11630  Double_t dImQ2n2k = (*fImQ)(1,2);
11631  //Double_t dImQ3n3k = (*fImQ)(2,3);
11632  //Double_t dImQ4n4k = (*fImQ)(3,4);
11633  //Double_t dImQ1n3k = (*fImQ)(0,3);
11634
11635  // dMs are variables introduced in order to simplify some Eqs. bellow:
11636  //..............................................................................................
11637  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
11638  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
11639                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
11640  //..............................................................................................
11641          // 1-particle:
11642  Double_t cosP1nW1 = 0.; // <<w1 cos(n*(phi1))>>
11643    
11644  if(dMult>0 && TMath::Abs((*fSMpk)(0,1))>1e-6)
11645  {
11646   cosP1nW1 = dReQ1n1k/(*fSMpk)(0,1); 
11647   
11648   // average weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
11649   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(1,cosP1nW1);
11650   
11651   // final average weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
11652   fIntFlowCorrectionTermsForNUAPro[1]->Fill(0.5,cosP1nW1,(*fSMpk)(0,1));  
11653  } 
11654  
11655  // 2-particle:
11656  Double_t cosP1nP1nW1W1 = 0.; // <<w1 w2 cos(n*(phi1+phi2))>>
11657  
11658  if(dMult>1 && TMath::Abs(dM11)>1e-6)
11659  {
11660   cosP1nP1nW1W1 = (pow(dReQ1n1k,2)-pow(dImQ1n1k,2)-dReQ2n2k)/dM11; 
11661   
11662   // average weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
11663   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(2,cosP1nP1nW1W1);
11664   
11665   // final average weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
11666   fIntFlowCorrectionTermsForNUAPro[1]->Fill(1.5,cosP1nP1nW1W1,dM11);  
11667  } 
11668  
11669  // 3-particle:
11670  Double_t cosP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 cos(n*(phi1-phi2-phi3))>>
11671  
11672  if(dMult>2 && TMath::Abs(dM111)>1e-6)
11673  {
11674   cosP1nM1nM1nW1W1W1 = (dReQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
11675                      - dReQ1n1k*dReQ2n2k-dImQ1n1k*dImQ2n2k
11676                      - 2.*((*fSMpk)(0,2))*dReQ1n1k
11677                      + 2.*dReQ1n3k) 
11678                      / dM111; 
11679   
11680   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
11681   fIntFlowCorrectionTermsForNUAEBE[1]->SetBinContent(3,cosP1nM1nM1nW1W1W1);
11682   
11683   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
11684   fIntFlowCorrectionTermsForNUAPro[1]->Fill(2.5,cosP1nM1nM1nW1W1W1,dM111);  
11685  } 
11686  
11687 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUACosTermsUsingParticleWeights()
11688
11689
11690 //================================================================================================================================
11691
11692
11693 void AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
11694 {
11695  // calculate corrections using particle weights for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
11696  
11697  //                                  **********************************************************************
11698  //                                  **** weighted corrections for non-uniform acceptance (sin terms): ****
11699  //                                  **********************************************************************
11700  
11701  // Remark 1: When particle weights are used the binning of fIntFlowCorrectionTermsForNUAPro[0] is organized as follows:
11702  //
11703  // 1st bin: <<w1 sin(n*(phi1))>> = sinP1nW1
11704  // 2nd bin: <<w1 w2 sin(n*(phi1+phi2))>> = sinP1nP1nW1W1
11705  // 3rd bin: <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1nW1W1W1 
11706  // ...
11707
11708  // multiplicity (number of particles used to determine the reaction plane)
11709  Double_t dMult = (*fSMpk)(0,0);
11710  
11711  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
11712  Double_t dReQ1n1k = (*fReQ)(0,1);
11713  Double_t dReQ2n2k = (*fReQ)(1,2);
11714  //Double_t dReQ3n3k = (*fReQ)(2,3);
11715  //Double_t dReQ4n4k = (*fReQ)(3,4);
11716  //Double_t dReQ1n3k = (*fReQ)(0,3);
11717  Double_t dImQ1n1k = (*fImQ)(0,1);
11718  Double_t dImQ2n2k = (*fImQ)(1,2);
11719  //Double_t dImQ3n3k = (*fImQ)(2,3);
11720  //Double_t dImQ4n4k = (*fImQ)(3,4);
11721  Double_t dImQ1n3k = (*fImQ)(0,3);
11722
11723  // dMs are variables introduced in order to simplify some Eqs. bellow:
11724  //..............................................................................................
11725  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
11726  Double_t dM111 = (*fSMpk)(2,1)-3.*(*fSMpk)(0,2)*(*fSMpk)(0,1)
11727                 + 2.*(*fSMpk)(0,3); // dM111 = sum_{i,j,k=1,i!=j!=k}^M w_i w_j w_k
11728  //..............................................................................................
11729  
11730  // 1-particle:
11731  Double_t sinP1nW1 = 0.; // <<w1 sin(n*(phi1))>>
11732  
11733  if(dMult>0 && TMath::Abs((*fSMpk)(0,1))>1e-6)
11734  {
11735   sinP1nW1 = dImQ1n1k/((*fSMpk)(0,1)); 
11736      
11737   // average weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
11738   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(1,sinP1nW1);
11739   
11740   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
11741   fIntFlowCorrectionTermsForNUAPro[0]->Fill(0.5,sinP1nW1,(*fSMpk)(0,1));  
11742  } 
11743  
11744  // 2-particle:
11745  Double_t sinP1nP1nW1W1 = 0.; // <<w1 w2 sin(n*(phi1+phi2))>>
11746  
11747  if(dMult>1 && TMath::Abs(dM11)>1e-6)
11748  {
11749   sinP1nP1nW1W1 = (2.*dReQ1n1k*dImQ1n1k-dImQ2n2k)/dM11; 
11750      
11751   // average weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
11752   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(2,sinP1nP1nW1W1);
11753   
11754   // final average weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
11755   fIntFlowCorrectionTermsForNUAPro[0]->Fill(1.5,sinP1nP1nW1W1,dM11);  
11756  } 
11757  
11758  // 3-particle:
11759  Double_t sinP1nM1nM1nW1W1W1 = 0.; // <<w1 w2 w3 sin(n*(phi1-phi2-phi3))>>
11760  
11761  if(dMult>2 && TMath::Abs(dM111)>1e-6)
11762  {
11763   sinP1nM1nM1nW1W1W1 = (-dImQ1n1k*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
11764                      + dReQ1n1k*dImQ2n2k-dImQ1n1k*dReQ2n2k
11765                      + 2.*((*fSMpk)(0,2))*dImQ1n1k
11766                      - 2.*dImQ1n3k)
11767                      / dM111; 
11768   
11769   // average weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
11770   fIntFlowCorrectionTermsForNUAEBE[0]->SetBinContent(3,sinP1nM1nM1nW1W1W1);
11771   
11772   // final average weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
11773   fIntFlowCorrectionTermsForNUAPro[0]->Fill(2.5,sinP1nM1nM1nW1W1W1,dM111);  
11774  } 
11775  
11776 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlowCorrectionsForNUASinTermsUsingParticleWeights()
11777
11778
11779 //================================================================================================================================
11780
11781
11782 void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent)
11783 {
11784  // Evaluate with nested loops correction terms for non-uniform acceptance for integrated flow (using the particle weights). 
11785
11786  // Results are stored in profiles fIntFlowDirectCorrectionTermsForNUA[0] (sin terms) and
11787  // fIntFlowDirectCorrectionTermsForNUA[1] (cos terms). 
11788  
11789  // Remark 1: When particle weights are used the binning of fIntFlowDirectCorrectionTermsForNUA[sc] is 
11790  // organized as follows (sc stands for either sin or cos):
11791  //
11792  // 1st bin: <<w1 sc(n*(phi1))>> = scP1nW1
11793  // 2nd bin: <<w1 w2 sc(n*(phi1+phi2))>> = scP1nP1nW1W1
11794  // 3rd bin: <<w1 w2 w3 sc(n*(phi1-phi2-phi3))>> = scP1nM1nM1nW1W1W1 
11795  // ...
11796   
11797  Int_t nPrim = anEvent->NumberOfTracks(); 
11798  AliFlowTrackSimple *aftsTrack = NULL;
11799  //Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
11800  //Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
11801  Double_t phi1=0., phi2=0., phi3=0.;
11802  Double_t wPhi1=1., wPhi2=1., wPhi3=1.;
11803  Int_t n = fHarmonic; 
11804  Int_t eventNo = (Int_t)fAvMultiplicity->GetBinEntries(1); // to be improved (is this casting safe in general?)
11805  Double_t dMult = (*fSMpk)(0,0);
11806  cout<<endl;
11807  cout<<"Correction terms for non-uniform acceptance: Event number: "<<eventNo<<", multiplicity is "<<dMult<<endl;
11808  if(dMult<1)
11809  {
11810   cout<<"... skipping this event (multiplicity too low) ..."<<endl;
11811  } else if (dMult>fMaxAllowedMultiplicity)
11812    {
11813     cout<<"... skipping this event (multiplicity too high) ..."<<endl;
11814    } else 
11815      { 
11816       cout<<"... evaluating nested loops (using particle weights) ..."<<endl;
11817      } 
11818       
11819  // 1-particle correction terms using particle weights:       
11820  if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity)
11821  {
11822   for(Int_t i1=0;i1<nPrim;i1++)
11823   {
11824    aftsTrack=anEvent->GetTrack(i1);
11825    if(!(aftsTrack->InRPSelection())) continue;
11826    phi1=aftsTrack->Phi();
11827    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11828    // 1-particle correction terms using particle weights:
11829    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(0.5,sin(n*phi1),wPhi1); // <w1 sin(n*phi1)>
11830    if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(0.5,cos(n*phi1),wPhi1); // <w1 cos(n*phi1)>
11831   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11832  } // end of if(nPrim>=1 && nPrim<=fMaxAllowedMultiplicity) 
11833  
11834  // 2-particle correction terms using particle weights:       
11835  if(nPrim>=2 && nPrim<=fMaxAllowedMultiplicity)
11836  {
11837   for(Int_t i1=0;i1<nPrim;i1++)
11838   {
11839    aftsTrack=anEvent->GetTrack(i1);
11840    if(!(aftsTrack->InRPSelection())) continue;
11841    phi1=aftsTrack->Phi();
11842    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11843    for(Int_t i2=0;i2<nPrim;i2++)
11844    {
11845     if(i2==i1)continue;
11846     aftsTrack=anEvent->GetTrack(i2);
11847     if(!(aftsTrack->InRPSelection())) continue;
11848     phi2=aftsTrack->Phi();
11849     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
11850     if(nPrim==2) cout<<i1<<" "<<i2<<"\r"<<flush;
11851     // 2-p correction terms using particle weights:    
11852     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(1.5,sin(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 sin(n*(phi1+phi2))>
11853     if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(1.5,cos(n*(phi1+phi2)),wPhi1*wPhi2); // <w1 w2 cos(n*(phi1+phi2))>
11854    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11855   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11856  } // end of if(nPrim>=2)
11857
11858  // 3-particle correction terms using particle weights:       
11859  if(nPrim>=3 && nPrim<=fMaxAllowedMultiplicity)
11860  { 
11861   for(Int_t i1=0;i1<nPrim;i1++)
11862   {
11863    aftsTrack=anEvent->GetTrack(i1);
11864    if(!(aftsTrack->InRPSelection())) continue;
11865    phi1=aftsTrack->Phi();
11866    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11867    for(Int_t i2=0;i2<nPrim;i2++)
11868    {
11869     if(i2==i1)continue;
11870     aftsTrack=anEvent->GetTrack(i2);
11871     if(!(aftsTrack->InRPSelection())) continue;
11872     phi2=aftsTrack->Phi();
11873     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11874     for(Int_t i3=0;i3<nPrim;i3++)
11875     {
11876      if(i3==i1||i3==i2)continue;
11877      aftsTrack=anEvent->GetTrack(i3);
11878      if(!(aftsTrack->InRPSelection())) continue;
11879      phi3=aftsTrack->Phi();
11880      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11881      if(nPrim==3) cout<<i1<<" "<<i2<<" "<<i3<<"\r"<<flush;
11882      // 3-p correction terms using particle weights:    
11883      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[0]->Fill(2.5,sin(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 sin(n*(phi1-phi2-phi3))>
11884      if(fUsePhiWeights) fIntFlowDirectCorrectionTermsForNUA[1]->Fill(2.5,cos(n*(phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n*(phi1-phi2-phi3))>
11885     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11886    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11887   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11888  } // end of if(nPrim>=3)
11889  
11890  /*
11891  
11892  if(nPrim>=4 && nPrim<=fMaxAllowedMultiplicity)
11893  {
11894   // 4 nested loops multiparticle correlations using particle weights:       
11895   for(Int_t i1=0;i1<nPrim;i1++)
11896   {
11897    aftsTrack=anEvent->GetTrack(i1);
11898    if(!(aftsTrack->InRPSelection())) continue;
11899    phi1=aftsTrack->Phi();
11900    if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
11901    for(Int_t i2=0;i2<nPrim;i2++)
11902    {
11903     if(i2==i1)continue;
11904     aftsTrack=anEvent->GetTrack(i2);
11905     if(!(aftsTrack->InRPSelection())) continue;
11906     phi2=aftsTrack->Phi();
11907     if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
11908     for(Int_t i3=0;i3<nPrim;i3++)
11909     {
11910      if(i3==i1||i3==i2)continue;
11911      aftsTrack=anEvent->GetTrack(i3);
11912      if(!(aftsTrack->InRPSelection())) continue;
11913      phi3=aftsTrack->Phi();
11914      if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
11915      for(Int_t i4=0;i4<nPrim;i4++)
11916      {
11917       if(i4==i1||i4==i2||i4==i3)continue;
11918       aftsTrack=anEvent->GetTrack(i4);
11919       if(!(aftsTrack->InRPSelection())) continue;
11920       phi4=aftsTrack->Phi();
11921       if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
11922       if(nPrim>=4) cout<<i1<<" "<<i2<<" "<<i3<<" "<<i4<<"\r"<<flush; // to be improved (replace eventually this if statement with if(nPrim==4))
11923       // 4-p correlations using particle weights:
11924       if(fUsePhiWeights) fIntFlowDirectCorrelations->Fill(10.5,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
11925       // extra correlations: 
11926       // 2-p extra correlations (do not appear if particle weights are not used):
11927       // ...
11928       // 3-p extra correlations (do not appear if particle weights are not used):
11929       // ...
11930       // 4-p extra correlations (do not appear if particle weights are not used):
11931       // ...
11932      } // end of for(Int_t i4=0;i4<nPrim;i4++) 
11933     } // end of for(Int_t i3=0;i3<nPrim;i3++)
11934    } // end of for(Int_t i2=0;i2<nPrim;i2++)
11935   } // end of for(Int_t i1=0;i1<nPrim;i1++)
11936  } // end of if(nPrim>=4)
11937
11938  */
11939
11940  cout<<endl; 
11941
11942 } // end of void AliFlowAnalysisWithQCumulants::EvaluateIntFlowCorrectionsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent)
11943
11944
11945 //================================================================================================================================
11946
11947
11948 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
11949 {
11950  // Calculate correction terms for non-uniform acceptance for differential flow (cos terms) using particle weights.
11951  
11952  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][1][cti], where cti runs as follows:
11953  //
11954  //  0: <<cos n(psi)>>
11955  //  1: <<w2 cos n(psi1+phi2)>>
11956  //  2: <<w2 w3 cos n(psi1+phi2-phi3)>>
11957  //  3: <<w2 w3 cos n(psi1-phi2-phi3)>>
11958  //  4:
11959  //  5:
11960  //  6:
11961  
11962  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
11963  Double_t dReQ1n1k = (*fReQ)(0,1);
11964  Double_t dReQ2n2k = (*fReQ)(1,2);
11965  //Double_t dReQ1n3k = (*fReQ)(0,3);
11966  //Double_t dReQ4n4k = (*fReQ)(3,4);
11967  Double_t dImQ1n1k = (*fImQ)(0,1);
11968  Double_t dImQ2n2k = (*fImQ)(1,2);
11969  //Double_t dImQ1n3k = (*fImQ)(0,3);
11970  //Double_t dImQ4n4k = (*fImQ)(3,4);
11971  
11972  // S^M_{p,k} (see .h file for the definition of fSMpk):
11973  Double_t dSM1p1k = (*fSMpk)(0,1);
11974  Double_t dSM1p2k = (*fSMpk)(0,2);
11975  Double_t dSM2p1k = (*fSMpk)(1,1);
11976
11977  Int_t t = -1; // type flag 
11978  Int_t pe = -1; // ptEta flag
11979  
11980  if(type == "RP")
11981  {
11982   t = 0;
11983  } else if(type == "POI")
11984    {
11985     t = 1;
11986    }
11987
11988  if(ptOrEta == "Pt")
11989  {
11990   pe = 0;
11991  } else if(ptOrEta == "Eta")
11992    {
11993     pe = 1;
11994    }
11995     
11996  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
11997  Double_t minPtEta[2] = {fPtMin,fEtaMin};
11998  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
11999  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12000  
12001  // looping over all bins and calculating correction terms: 
12002  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12003  {
12004   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
12005   Double_t p1n0kRe = 0.;
12006   Double_t p1n0kIm = 0.;
12007
12008   // number of POIs in particular pt or eta bin:
12009   Double_t mp = 0.;
12010
12011   // 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):
12012   Double_t q1n2kRe = 0.;
12013   Double_t q1n2kIm = 0.;
12014   Double_t q2n1kRe = 0.;
12015   Double_t q2n1kIm = 0.;
12016     
12017   // s_{1,1}, s_{1,2} // to be improved (add explanation)  
12018   Double_t s1p1k = 0.; 
12019   Double_t s1p2k = 0.; 
12020   
12021   // number of particles which are both RPs and POIs in particular pt or eta bin:
12022   Double_t mq = 0.;
12023   
12024   // M0111 from Eq. (118) in QC2c (to be improved (notation))
12025   Double_t dM01 = 0.;
12026   Double_t dM011 = 0.;
12027   
12028   if(type == "POI")
12029   {           
12030    // q_{m*n,k}:
12031    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
12032            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
12033    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
12034            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
12035    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
12036            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
12037    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
12038            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
12039    mq = fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12040    
12041    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
12042    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
12043   }else if(type == "RP")
12044    {
12045     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
12046     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
12047             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
12048     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
12049             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
12050     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
12051             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
12052     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
12053             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
12054     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12055     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
12056     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
12057     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.);  
12058     
12059     mq = fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12060   }    
12061   
12062   if(type == "POI")
12063   {
12064    // p_{m*n,k}:   
12065    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
12066            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
12067    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
12068            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
12069    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12070    // M01 from Eq. (118) in QC2c (to be improved (notation)):
12071    dM01 = mp*dSM1p1k-s1p1k;
12072    dM011 = mp*(dSM2p1k-dSM1p2k)
12073          - 2.*(s1p1k*dSM1p1k-s1p2k);
12074        
12075    // typeFlag = RP (0) or POI (1):   
12076    t = 1; 
12077   } else if(type == "RP")
12078     {  
12079      // to be improved (cross-checked):
12080      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
12081              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
12082      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
12083              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
12084      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12085      // M01 from Eq. (118) in QC2c (to be improved (notation)):
12086      dM01 = mp*dSM1p1k-s1p1k;
12087      dM011 = mp*(dSM2p1k-dSM1p2k)
12088            - 2.*(s1p1k*dSM1p1k-s1p2k); 
12089      // typeFlag = RP (0) or POI (1): 
12090      t = 0;
12091     }
12092   
12093   // <<cos n(psi1)>>:
12094   Double_t cosP1nPsi = 0.;
12095   if(mp)
12096   {
12097    cosP1nPsi = p1n0kRe/mp;
12098    
12099    // fill profile for <<cos n(psi1)>>:
12100    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi,mp);
12101    // histogram to store <cos n(psi1)> e-b-e (needed in some other methods):
12102    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][0]->SetBinContent(b,cosP1nPsi);
12103   } // end of if(mp)   
12104   
12105   // <<w2 cos n(psi1+phi2)>>:
12106   Double_t cosP1nPsiP1nPhiW2 = 0.;
12107   if(dM01)
12108   {
12109    cosP1nPsiP1nPhiW2 = (p1n0kRe*dReQ1n1k-p1n0kIm*dImQ1n1k-q2n1kRe)/(dM01);
12110    // fill profile for <<w2 cos n(psi1+phi2)>>:
12111    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsiP1nPhiW2,dM01);
12112    // histogram to store <w2 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12113    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][1]->SetBinContent(b,cosP1nPsiP1nPhiW2);
12114   } // end of if(dM01)   
12115   
12116   // <<w2 w3 cos n(psi1+phi2-phi3)>>:
12117   Double_t cosP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
12118   if(dM011)
12119   {
12120    cosP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
12121                               - p1n0kRe*dSM1p2k
12122                               - q2n1kRe*dReQ1n1k-q2n1kIm*dImQ1n1k
12123                               - s1p1k*dReQ1n1k
12124                               + 2.*q1n2kRe)
12125                               / dM011;  
12126    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
12127    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1P1nPhi2MPhi3W2W3,dM011);
12128    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12129    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][2]->SetBinContent(b,cosP1nPsi1P1nPhi2MPhi3W2W3);
12130   } // end of if(dM011)   
12131   
12132   // <<w2 w3 cos n(psi1-phi2-phi3)>>:
12133   Double_t cosP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
12134   if(dM011)
12135   {
12136    cosP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))+2.*p1n0kIm*dReQ1n1k*dImQ1n1k
12137                               - 1.*(p1n0kRe*dReQ2n2k+p1n0kIm*dImQ2n2k)  
12138                               - 2.*s1p1k*dReQ1n1k
12139                               + 2.*q1n2kRe)
12140                               / dM011;
12141    // fill profile for <<w1 w2 w3 cos n(psi1+phi2)>>:
12142    fDiffFlowCorrectionTermsForNUAPro[t][pe][1][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],cosP1nPsi1M1nPhi2MPhi3W2W3,dM011);
12143    // histogram to store <w1 w2 w3 cos n(psi1+phi2)> e-b-e (needed in some other methods):
12144    fDiffFlowCorrectionTermsForNUAEBE[t][pe][1][3]->SetBinContent(b,cosP1nPsi1M1nPhi2MPhi3W2W3);
12145   } // end of if(dM011)   
12146  
12147  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12148    
12149 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUACosTermsUsingParticleWeights(TString type, TString ptOrEta)
12150
12151
12152 //================================================================================================================================
12153
12154
12155 void AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
12156 {
12157  // Calculate correction terms for non-uniform acceptance for differential flow (sin terms).
12158   
12159  // Results are stored in fDiffFlowCorrectionTermsForNUAPro[t][pe][0][cti], where cti runs as follows:
12160  //  0: <<sin n(psi1)>>
12161  //  1: <<w2 sin n(psi1+phi2)>>
12162  //  2: <<w2 w3 sin n(psi1+phi2-phi3)>>
12163  //  3: <<w2 w3 sin n(psi1-phi2-phi3)>>:
12164  //  4:
12165  //  5:
12166  //  6:
12167  
12168  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
12169  Double_t dReQ1n1k = (*fReQ)(0,1);
12170  Double_t dReQ2n2k = (*fReQ)(1,2);
12171  //Double_t dReQ1n3k = (*fReQ)(0,3);
12172  //Double_t dReQ4n4k = (*fReQ)(3,4);
12173  Double_t dImQ1n1k = (*fImQ)(0,1);
12174  Double_t dImQ2n2k = (*fImQ)(1,2);
12175  //Double_t dImQ1n3k = (*fImQ)(0,3);
12176  //Double_t dImQ4n4k = (*fImQ)(3,4);
12177  
12178  // S^M_{p,k} (see .h file for the definition of fSMpk):
12179  Double_t dSM1p1k = (*fSMpk)(0,1);
12180  Double_t dSM1p2k = (*fSMpk)(0,2);
12181  Double_t dSM2p1k = (*fSMpk)(1,1);
12182
12183  Int_t t = -1; // type flag 
12184  Int_t pe = -1; // ptEta flag
12185  
12186  if(type == "RP")
12187  {
12188   t = 0;
12189  } else if(type == "POI")
12190    {
12191     t = 1;
12192    }
12193
12194  if(ptOrEta == "Pt")
12195  {
12196   pe = 0;
12197  } else if(ptOrEta == "Eta")
12198    {
12199     pe = 1;
12200    }
12201     
12202  Int_t nBinsPtEta[2] = {fnBinsPt,fnBinsEta};
12203  Double_t minPtEta[2] = {fPtMin,fEtaMin};
12204  //Double_t maxPtEta[2] = {fPtMax,fEtaMax};
12205  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12206
12207  // looping over all bins and calculating correction terms: 
12208  for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12209  {
12210   // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular pt or eta bin): 
12211   Double_t p1n0kRe = 0.;
12212   Double_t p1n0kIm = 0.;
12213
12214   // number of POIs in particular pt or eta bin:
12215   Double_t mp = 0.;
12216
12217   // 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):
12218   Double_t q1n2kRe = 0.;
12219   Double_t q1n2kIm = 0.;
12220   Double_t q2n1kRe = 0.;
12221   Double_t q2n1kIm = 0.;
12222     
12223   // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12224   Double_t s1p1k = 0.; 
12225   Double_t s1p2k = 0.; 
12226   
12227   // number of particles which are both RPs and POIs in particular pt or eta bin:
12228   Double_t mq = 0.;
12229   
12230   // M0111 from Eq. (118) in QC2c (to be improved (notation))
12231   Double_t dM01 = 0.;
12232   Double_t dM011 = 0.;
12233
12234   if(type == "POI")
12235   {    
12236    // q_{m*n,k}:
12237    q1n2kRe = fReRPQ1dEBE[2][pe][0][2]->GetBinContent(fReRPQ1dEBE[2][pe][0][2]->GetBin(b))
12238            * fReRPQ1dEBE[2][pe][0][2]->GetBinEntries(fReRPQ1dEBE[2][pe][0][2]->GetBin(b));
12239    q1n2kIm = fImRPQ1dEBE[2][pe][0][2]->GetBinContent(fImRPQ1dEBE[2][pe][0][2]->GetBin(b))
12240            * fImRPQ1dEBE[2][pe][0][2]->GetBinEntries(fImRPQ1dEBE[2][pe][0][2]->GetBin(b));         
12241    q2n1kRe = fReRPQ1dEBE[2][pe][1][1]->GetBinContent(fReRPQ1dEBE[2][pe][1][1]->GetBin(b))
12242            * fReRPQ1dEBE[2][pe][1][1]->GetBinEntries(fReRPQ1dEBE[2][pe][1][1]->GetBin(b));
12243    q2n1kIm = fImRPQ1dEBE[2][pe][1][1]->GetBinContent(fImRPQ1dEBE[2][pe][1][1]->GetBin(b))
12244            * fImRPQ1dEBE[2][pe][1][1]->GetBinEntries(fImRPQ1dEBE[2][pe][1][1]->GetBin(b));         
12245    mq = fReRPQ1dEBE[2][pe][0][0]->GetBinEntries(fReRPQ1dEBE[2][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)
12246    
12247    s1p1k = pow(fs1dEBE[2][pe][1]->GetBinContent(b)*fs1dEBE[2][pe][1]->GetBinEntries(b),1.); 
12248    s1p2k = pow(fs1dEBE[2][pe][2]->GetBinContent(b)*fs1dEBE[2][pe][2]->GetBinEntries(b),1.); 
12249   }else if(type == "RP")
12250    {
12251     // q_{m*n,k}: (Remark: m=1 is 0, k=0 iz zero (to be improved!)) 
12252     q1n2kRe = fReRPQ1dEBE[0][pe][0][2]->GetBinContent(fReRPQ1dEBE[0][pe][0][2]->GetBin(b))
12253             * fReRPQ1dEBE[0][pe][0][2]->GetBinEntries(fReRPQ1dEBE[0][pe][0][2]->GetBin(b));
12254     q1n2kIm = fImRPQ1dEBE[0][pe][0][2]->GetBinContent(fImRPQ1dEBE[0][pe][0][2]->GetBin(b))
12255             * fImRPQ1dEBE[0][pe][0][2]->GetBinEntries(fImRPQ1dEBE[0][pe][0][2]->GetBin(b));
12256     q2n1kRe = fReRPQ1dEBE[0][pe][1][1]->GetBinContent(fReRPQ1dEBE[0][pe][1][1]->GetBin(b))
12257             * fReRPQ1dEBE[0][pe][1][1]->GetBinEntries(fReRPQ1dEBE[0][pe][1][1]->GetBin(b));
12258     q2n1kIm = fImRPQ1dEBE[0][pe][1][1]->GetBinContent(fImRPQ1dEBE[0][pe][1][1]->GetBin(b))
12259             * fImRPQ1dEBE[0][pe][1][1]->GetBinEntries(fImRPQ1dEBE[0][pe][1][1]->GetBin(b));
12260     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
12261     s1p1k = pow(fs1dEBE[0][pe][1]->GetBinContent(b)*fs1dEBE[0][pe][1]->GetBinEntries(b),1.); 
12262     s1p2k = pow(fs1dEBE[0][pe][2]->GetBinContent(b)*fs1dEBE[0][pe][2]->GetBinEntries(b),1.); 
12263     //s1p3k = pow(fs1dEBE[0][pe][3]->GetBinContent(b)*fs1dEBE[0][pe][3]->GetBinEntries(b),1.); 
12264   }    
12265   
12266   if(type == "POI")
12267   {
12268    // p_{m*n,k}:   
12269    p1n0kRe = fReRPQ1dEBE[1][pe][0][0]->GetBinContent(fReRPQ1dEBE[1][pe][0][0]->GetBin(b))
12270            * fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b));
12271    p1n0kIm = fImRPQ1dEBE[1][pe][0][0]->GetBinContent(fImRPQ1dEBE[1][pe][0][0]->GetBin(b))  
12272            * fImRPQ1dEBE[1][pe][0][0]->GetBinEntries(fImRPQ1dEBE[1][pe][0][0]->GetBin(b));
12273    mp = fReRPQ1dEBE[1][pe][0][0]->GetBinEntries(fReRPQ1dEBE[1][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here) 
12274    // M01 from Eq. (118) in QC2c (to be improved (notation)):
12275    dM01 = mp*dSM1p1k-s1p1k;
12276    dM011 = mp*(dSM2p1k-dSM1p2k)
12277          - 2.*(s1p1k*dSM1p1k-s1p2k);  
12278    // typeFlag = RP (0) or POI (1):   
12279    t = 1;           
12280   } else if(type == "RP")
12281     { 
12282      // to be improved (cross-checked):
12283      p1n0kRe = fReRPQ1dEBE[0][pe][0][0]->GetBinContent(fReRPQ1dEBE[0][pe][0][0]->GetBin(b))
12284              * fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b));
12285      p1n0kIm = fImRPQ1dEBE[0][pe][0][0]->GetBinContent(fImRPQ1dEBE[0][pe][0][0]->GetBin(b))  
12286              * fImRPQ1dEBE[0][pe][0][0]->GetBinEntries(fImRPQ1dEBE[0][pe][0][0]->GetBin(b));
12287      mp = fReRPQ1dEBE[0][pe][0][0]->GetBinEntries(fReRPQ1dEBE[0][pe][0][0]->GetBin(b)); // to be improved (cross-checked by accessing other profiles here)    
12288      // M01 from Eq. (118) in QC2c (to be improved (notation)):
12289      dM01 = mp*dSM1p1k-s1p1k;
12290      dM011 = mp*(dSM2p1k-dSM1p2k)
12291            - 2.*(s1p1k*dSM1p1k-s1p2k); 
12292      // typeFlag = RP (0) or POI (1): 
12293      t = 0;
12294     }
12295   
12296   // <<sin n(psi1)>>:
12297   Double_t sinP1nPsi = 0.;
12298   if(mp)
12299   {
12300    sinP1nPsi = p1n0kIm/mp;
12301    
12302    // fill profile for <<sin n(psi1)>>:
12303    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][0]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi,mp);
12304    // histogram to store <sin n(psi1)> e-b-e (needed in some other methods):
12305    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][0]->SetBinContent(b,sinP1nPsi);
12306   } // end of if(mp)   
12307   
12308   // <<w2 sin n(psi1+phi2)>>:
12309   Double_t sinP1nPsiP1nPhiW2 = 0.;
12310   if(dM01)
12311   {
12312    sinP1nPsiP1nPhiW2 = (p1n0kRe*dImQ1n1k+p1n0kIm*dReQ1n1k-q2n1kIm)/(dM01);
12313    // fill profile for <<w2 sin n(psi1+phi2)>>:
12314    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][1]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsiP1nPhiW2,dM01);
12315    // histogram to store <w2 sin n(psi1+phi2)> e-b-e (needed in some other methods):
12316    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][1]->SetBinContent(b,sinP1nPsiP1nPhiW2);
12317   } // end of if(mp*dMult-mq)   
12318   
12319   // <<w2 w3 sin n(psi1+phi2-phi3)>>:
12320   Double_t sinP1nPsi1P1nPhi2MPhi3W2W3 = 0.;
12321   if(dM011)
12322   {
12323    sinP1nPsi1P1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dImQ1n1k,2.)+pow(dReQ1n1k,2.))
12324                               - p1n0kIm*dSM1p2k
12325                               + q2n1kRe*dImQ1n1k-q2n1kIm*dReQ1n1k
12326                               - s1p1k*dImQ1n1k
12327                               + 2.*q1n2kIm)
12328                               / dM011;  
12329    // fill profile for <<w2 w3 sin n(psi1+phi2-phi3)>>:
12330    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][2]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1P1nPhi2MPhi3W2W3,dM011);
12331    // histogram to store <w2 w3 sin n(psi1+phi2-phi3)> e-b-e (needed in some other methods):
12332    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][2]->SetBinContent(b,sinP1nPsi1P1nPhi2MPhi3W2W3);
12333   } // end of if(dM011)   
12334   
12335   // <<w2 w3 sin n(psi1-phi2-phi3)>>:
12336   Double_t sinP1nPsi1M1nPhi2MPhi3W2W3 = 0.;
12337   if(dM011)
12338   {
12339    sinP1nPsi1M1nPhi2MPhi3W2W3 = (p1n0kIm*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))-2.*p1n0kRe*dReQ1n1k*dImQ1n1k
12340                               + 1.*(p1n0kRe*dImQ2n2k-p1n0kIm*dReQ2n2k)  
12341                               + 2.*s1p1k*dImQ1n1k
12342                               - 2.*q1n2kIm)
12343                               / dM011;
12344    // fill profile for <<w2 w3 sin n(psi1-phi2-phi3)>>:
12345    fDiffFlowCorrectionTermsForNUAPro[t][pe][0][3]->Fill(minPtEta[pe]+(b-1)*binWidthPtEta[pe],sinP1nPsi1M1nPhi2MPhi3W2W3,dM011);
12346    // histogram to store <w2 w3 sin n(psi1-phi2-phi3)> e-b-e (needed in some other methods):
12347    fDiffFlowCorrectionTermsForNUAEBE[t][pe][0][3]->SetBinContent(b,sinP1nPsi1M1nPhi2MPhi3W2W3);
12348   } // end of if(dM011)   
12349   
12350  } // end of for(Int_t b=1;b<=nBinsPtEta[pe];b++)
12351
12352 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlowCorrectionsForNUASinTermsUsingParticleWeights(TString type, TString ptOrEta)
12353
12354
12355 //================================================================================================================================
12356
12357    
12358 void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple * const anEvent, TString type, TString ptOrEta)
12359 {
12360  // Evaluate with nested loops correction terms for non-uniform acceptance 
12361  // with using particle weights (both sin and cos terms) relevant for differential flow.
12362  
12363  // Remark 1: "w1" in expressions bellow is a particle weight used only for particles which were 
12364  //           flagged both as POI and RP.
12365  // Remark 2: Reduced correction terms for non-uniform acceptance are evaluated in pt bin number fCrossCheckInPtBinNo 
12366  //           and eta bin number fCrossCheckInEtaBinNo both for RPs and POIs.
12367  // Remark 3: Results are stored in 1 bin profiles fDiffFlowDirectCorrections[t][pe][sc][cti], where first three indices runs as: 
12368  //           [0=RP,1=POI][0=Pt,1=Eta][0=sin terms,1=cos terms], whilst the cti (correction term index) runs as follows: 
12369  //  cti: 
12370  //    0: <<sc n(psi1)>>
12371  //    1: <<w2 sc n(psi1+phi2)>> 
12372  //    2: <<w2 w3 sc n(psi1+phi2-phi3)>>
12373  //    3: <<w2 w3 sc n(psi1-phi2-phi3)>>
12374  //    4:
12375  //    5:
12376  //    6:
12377      
12378  Int_t typeFlag = -1;
12379  Int_t ptEtaFlag = -1;
12380  if(type == "RP")
12381  {
12382   typeFlag = 0;
12383  } else if(type == "POI")
12384    {
12385     typeFlag = 1;
12386    }      
12387  if(ptOrEta == "Pt")
12388  {
12389   ptEtaFlag = 0;
12390  } else if(ptOrEta == "Eta")
12391    {
12392     ptEtaFlag = 1;
12393    } 
12394  // shortcuts:
12395  Int_t t = typeFlag;
12396  Int_t pe = ptEtaFlag;
12397       
12398  Double_t lowerPtEtaEdge[2] = {fPtMin+(fCrossCheckInPtBinNo-1)*fPtBinWidth,fEtaMin+(fCrossCheckInEtaBinNo-1)*fEtaBinWidth};
12399  Double_t upperPtEtaEdge[2] = {fPtMin+fCrossCheckInPtBinNo*fPtBinWidth,fEtaMin+fCrossCheckInEtaBinNo*fEtaBinWidth};
12400  Double_t binWidthPtEta[2] = {fPtBinWidth,fEtaBinWidth};
12401  
12402  Int_t nPrim = anEvent->NumberOfTracks(); 
12403  AliFlowTrackSimple *aftsTrack = NULL;
12404  
12405  Double_t psi1=0., phi2=0., phi3=0.;// phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
12406  Double_t wPhi2=1., wPhi3=1.;
12407  
12408  Int_t n = fHarmonic; 
12409  
12410  // 1'-particle correction terms:
12411  for(Int_t i1=0;i1<nPrim;i1++)
12412  {
12413   aftsTrack=anEvent->GetTrack(i1);
12414   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12415   if(typeFlag==1) // this is diff flow of POIs 
12416   {
12417    if(ptOrEta == "Pt")
12418    { 
12419     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12420    } else if (ptOrEta == "Eta")
12421      {
12422       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12423      }
12424   } else // this is diff flow of RPs 
12425     {
12426      if(ptOrEta == "Pt")
12427      { 
12428       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12429      } else if (ptOrEta == "Eta")
12430        {
12431         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12432        }
12433     }
12434   psi1=aftsTrack->Phi(); 
12435   // sin terms: 
12436   fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*psi1),1.); // <<sin(n*(psi1))>>  
12437   // cos terms: 
12438   fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][0]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*psi1),1.); // <<cos(n*(psi1))>>  
12439  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12440    
12441  // 2'-particle correction terms:
12442  for(Int_t i1=0;i1<nPrim;i1++)
12443  {
12444   aftsTrack=anEvent->GetTrack(i1);
12445   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12446   if(typeFlag==1) // this is diff flow of POIs 
12447   {
12448    if(ptOrEta == "Pt")
12449    { 
12450     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12451    } else if (ptOrEta == "Eta")
12452      {
12453       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12454      }
12455   } else // this is diff flow of RPs 
12456     {
12457      if(ptOrEta == "Pt")
12458      { 
12459       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12460      } else if (ptOrEta == "Eta")
12461        {
12462         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12463        }
12464     }
12465   psi1=aftsTrack->Phi(); 
12466   for(Int_t i2=0;i2<nPrim;i2++)
12467   {
12468    if(i2==i1) continue;
12469    aftsTrack=anEvent->GetTrack(i2);
12470    // RP condition (!(first) particle in the correlator must be RP):
12471    if(!(aftsTrack->InRPSelection())) continue;
12472    phi2=aftsTrack->Phi();
12473    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12474    // sin terms: 
12475    fDiffFlowDirectCorrectionTermsForNUA[t][pe][0][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,sin(n*(psi1+phi2)),wPhi2); // <<w2 sin(n*(psi1+phi2))>>  
12476    // cos terms: 
12477    fDiffFlowDirectCorrectionTermsForNUA[t][pe][1][1]->Fill(lowerPtEtaEdge[pe]+binWidthPtEta[pe]/2.,cos(n*(psi1+phi2)),wPhi2); // <<w2 cos(n*(psi1+phi2))>>  
12478   }//end of for(Int_t i2=0;i2<nPrim;i2++)
12479  }//end of for(Int_t i1=0;i1<nPrim;i1++)   
12480  
12481  // 3'-particle correction terms:
12482  for(Int_t i1=0;i1<nPrim;i1++)
12483  {
12484   aftsTrack=anEvent->GetTrack(i1);
12485   // POI condition (first particle in the correlator must be POI): // to be improved (this can be implemented much better)
12486   if(typeFlag==1) // this is diff flow of POIs 
12487   {
12488    if(ptOrEta == "Pt")
12489    { 
12490     if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;
12491    } else if (ptOrEta == "Eta")
12492      {
12493       if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InPOISelection())))continue;    
12494      }
12495   } else // this is diff flow of RPs 
12496     {
12497      if(ptOrEta == "Pt")
12498      { 
12499       if(!((aftsTrack->Pt()>=lowerPtEtaEdge[pe] && aftsTrack->Pt()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;
12500      } else if (ptOrEta == "Eta")
12501        {
12502         if(!((aftsTrack->Eta()>=lowerPtEtaEdge[pe] && aftsTrack->Eta()<upperPtEtaEdge[pe]) && (aftsTrack->InRPSelection())))continue;    
12503        }
12504     }
12505   psi1=aftsTrack->Phi();
12506   for(Int_t i2=0;i2<nPrim;i2++)
12507   {
12508    if(i2==i1) continue;
12509    aftsTrack=anEvent->GetTrack(i2);
12510    // RP condition (!(first) particle in the correlator must be RP):
12511    if(!(aftsTrack->InRPSelection())) continue;
12512    phi2=aftsTrack->Phi();
12513    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));   
12514    for(Int_t i3=0;i3<nPrim;i3++)
12515    {
12516     if(i3==i1||i3==i2) continue;
12517     aftsTrack=anEvent->GetTrack(i3);
12518     // RP condition (!(first) particle in the correlator must be RP):
12519     if(!(aftsTrack->InRPSelection())) continue;
12520     phi3=aftsTrack->Phi();
12521     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));   
12522     // sin terms: 
12523     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))>>  
12524     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))>>  
12525     // cos terms: 
12526     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))>>  
12527     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))>>  
12528    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
12529   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
12530  }//end of for(Int_t i1=0;i1<nPrim;i1++)
12531                
12532 } // end of void AliFlowAnalysisWithQCumulants::EvaluateDiffFlowCorrectionTermsForNUAWithNestedLoopsUsingParticleWeights(AliFlowEventSimple* anEvent, TString type, TString ptOrEta)
12533
12534 //================================================================================================================================
12535
12536 void AliFlowAnalysisWithQCumulants::CalculateDetectorEffectsForTrueCorrelations()
12537 {
12538  // Quantify detector effects for true correlations.
12539  
12540  // to be improved: add protection for the pointers used in this method
12541  
12542  Double_t measured[4] = {0.}; // measured true correlation (a.k.a. cumulant)
12543  Double_t corrected[4] = {0.}; // true correlation corrected for detector effects (a.k.a. generalized cumulant)
12544  
12545  // measured correlations:
12546  Double_t two = fIntFlowCorrelationsHist->GetBinContent(1); // <<2>> 
12547  Double_t four = fIntFlowCorrelationsHist->GetBinContent(2); // <<4>>  
12548  Double_t six = fIntFlowCorrelationsHist->GetBinContent(3); // <<6>> 
12549  Double_t eight = fIntFlowCorrelationsHist->GetBinContent(4); // <<8>>  
12550  // measured true correlations (a.k.a. cumulants):
12551  if(two) measured[0] = two; 
12552  if(four) measured[1] = four-2.*pow(two,2.); 
12553  if(six) measured[2] = six-9.*two*four+12.*pow(two,3.); 
12554  if(eight) measured[3] = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.); 
12555  
12556  for(Int_t ci=0;ci<=1;ci++) // correlation index // to be improved (enabled also for QC{6} and QC{8} eventually)
12557  {
12558   corrected[ci] = fIntFlowQcumulants->GetBinContent(ci+1);
12559   if(TMath::Abs(measured[ci])>1.e-44)
12560   {
12561    fIntFlowDetectorBias->SetBinContent(ci+1,corrected[ci]/measured[ci]);
12562   }
12563  } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index 
12564  
12565  // Versus multiplicity:
12566  if(!fCalculateCumulantsVsM){return;}
12567  if(!fApplyCorrectionForNUAVsM){return;}
12568  Int_t nBins = fIntFlowCorrelationsVsMPro[0]->GetNbinsX(); // to be improved (hardwired 0) 
12569  for(Int_t b=1;b<=nBins;b++)
12570  {
12571   // measured correlations vs M:
12572   two = fIntFlowCorrelationsVsMHist[0]->GetBinContent(b); // <<2>> 
12573   four = fIntFlowCorrelationsVsMHist[1]->GetBinContent(b); // <<4>>  
12574   six = fIntFlowCorrelationsVsMHist[2]->GetBinContent(b); // <<6>> 
12575   eight = fIntFlowCorrelationsVsMHist[3]->GetBinContent(b); // <<8>>  
12576   // measured true correlations (a.k.a. cumulants) vs M: 
12577   measured[0] = 0.; // QC{2} vs M
12578   measured[1] = 0.; // QC{4} vs M
12579   measured[2] = 0.; // QC{6} vs M
12580   measured[3] = 0.; // QC{8} vs M
12581   if(two) measured[0] = two; 
12582   if(four) measured[1] = four-2.*pow(two,2.); 
12583   if(six) measured[2] = six-9.*two*four+12.*pow(two,3.); 
12584   if(eight) measured[3] = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.);
12585   corrected[0] = 0.; // generalized QC{2} vs M
12586   corrected[1] = 0.; // generalized QC{4} vs M
12587   corrected[2] = 0.; // generalized QC{6} vs M
12588   corrected[3] = 0.; // generalized QC{8} vs M 
12589   for(Int_t ci=0;ci<=1;ci++) // correlation index // to be improved (enabled also for QC{6} and QC{8} eventually)
12590   {
12591    corrected[ci] = fIntFlowQcumulantsVsM[ci]->GetBinContent(b);
12592    if(TMath::Abs(measured[ci])>1.e-44)
12593    {
12594     fIntFlowDetectorBiasVsM[ci]->SetBinContent(b,corrected[ci]/measured[ci]);
12595    }
12596   } // end of for(Int_t ci=1;ci<=4;ci++) // correlation index    
12597  } // end of for(Int_t b=1;b<=nBins;b++)
12598
12599 } // end of AliFlowAnalysisWithQCumulants::CalculateDetectorEffectsForTrueCorrelations()
12600
12601 //================================================================================================================================
12602
12603 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
12604 {
12605  // Check all pointers used in method Finish().
12606  
12607  if(!fIntFlowCorrelationsPro)
12608  {
12609   cout<<endl;
12610   cout<<" WARNING (QC): fIntFlowCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12611   cout<<endl;
12612   exit(0); 
12613  }
12614  if(!fIntFlowCorrelationsHist)
12615  {
12616   cout<<endl;
12617   cout<<" WARNING (QC): fIntFlowCorrelationsHist is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12618   cout<<endl;
12619   exit(0); 
12620  }
12621  for(Int_t power=0;power<2;power++)
12622  { 
12623   if(!fIntFlowSumOfEventWeights[power]) 
12624   {
12625    cout<<endl;
12626    cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeights[%d] is NULL in CheckPointersUsedInFinish() !!!!",power)<<endl;
12627    cout<<endl;
12628    exit(0);
12629   }
12630  } // end of for(Int_t power=0;power<2;power++)
12631  if(!fIntFlowProductOfCorrelationsPro)
12632  {
12633   cout<<endl;
12634   cout<<" WARNING (QC): fIntFlowProductOfCorrelationsPro is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12635   cout<<endl;
12636   exit(0); 
12637  } 
12638  if(!fIntFlowSumOfProductOfEventWeights)
12639  {
12640   cout<<endl;
12641   cout<<" WARNING (QC): fIntFlowSumOfProductOfEventWeights is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12642   cout<<endl;
12643   exit(0); 
12644  }
12645  if(!fIntFlowCovariances)
12646  {
12647   cout<<endl;
12648   cout<<" WARNING (QC): fIntFlowCovariances is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12649   cout<<endl;
12650   exit(0); 
12651  }  
12652  if(!fIntFlowQcumulants)
12653  {
12654   cout<<endl;
12655   cout<<" WARNING (QC): fIntFlowQcumulants is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12656   cout<<endl;
12657   exit(0); 
12658  }  
12659  if(!fIntFlow)
12660  {
12661   cout<<endl;
12662   cout<<" WARNING (QC): fIntFlow is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12663   cout<<endl;
12664   exit(0); 
12665  }
12666  if(!fCommonHists)
12667  {
12668   cout<<endl;
12669   cout<<" WARNING (QC): fCommonHists is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12670   cout<<endl;
12671   exit(0); 
12672  }
12673  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
12674  {
12675   cout<<endl;
12676   cout<<" WARNING (QC): fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th"<<endl; 
12677   cout<<"               && fCommonHistsResults8th is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12678   cout<<endl;
12679   exit(0);
12680  } 
12681  
12682  // Versus multiplicity:
12683  if(!fCalculateCumulantsVsM){return;}
12684  for(Int_t ci=0;ci<=3;ci++) // correlation index
12685  {
12686   if(!fIntFlowCorrelationsVsMPro[ci])
12687   {
12688    cout<<endl;
12689    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
12690    cout<<endl;
12691    exit(0); 
12692   }
12693   if(!fIntFlowCorrelationsVsMHist[ci])
12694   {
12695    cout<<endl;
12696    cout<<Form(" WARNING (QC): fIntFlowCorrelationsVsMHist[%d] is NULL in CheckPointersUsedInFinish() !!!!",ci)<<endl;
12697    cout<<endl;
12698    exit(0); 
12699   }
12700   for(Int_t power=0;power<2;power++) 
12701   {
12702    if(!fIntFlowSumOfEventWeightsVsM[ci][power])
12703    {
12704     cout<<endl;
12705     cout<<Form(" WARNING (QC): fIntFlowSumOfEventWeightsVsM[%d][%d] is NULL in CheckPointersUsedInFinish() !!!!",ci,power)<<endl;
12706     cout<<endl;
12707     exit(0);   
12708    }
12709   } // end of for(Int_t power=0;power<2;power++) 
12710  } // end of for(Int_t ci=0;ci<=3;ci++) // correlation index
12711  for(Int_t i=0;i<6;i++)
12712  {
12713   if(!fIntFlowProductOfCorrelationsVsMPro[i])
12714   {
12715    cout<<endl;
12716    cout<<Form(" WARNING (QC): fIntFlowProductOfCorrelationsVsMPro[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
12717    cout<<endl;
12718    exit(0); 
12719   }
12720   if(!fIntFlowSumOfProductOfEventWeightsVsM[i])
12721   {
12722    cout<<endl;
12723    cout<<Form(" WARNING (QC): fIntFlowSumOfProductOfEventWeightsVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
12724    cout<<endl;
12725    exit(0); 
12726   }
12727   if(!fIntFlowCovariancesVsM[i])
12728   {
12729    cout<<endl;
12730    cout<<Form(" WARNING (QC): fIntFlowCovariancesVsM[%d] is NULL in CheckPointersUsedInFinish() !!!!",i)<<endl;
12731    cout<<endl;
12732    exit(0); 
12733   }
12734  } // end of for(Int_t i=0;i<6;i++) 
12735  if(!fIntFlowRebinnedInM)
12736  {
12737   cout<<endl;
12738   cout<<" WARNING (QC): fIntFlowRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12739   cout<<endl;
12740   exit(0); 
12741  }
12742  if(!fIntFlowQcumulantsRebinnedInM)
12743  {
12744   cout<<endl;
12745   cout<<" WARNING (QC): fIntFlowQcumulantsRebinnedInM is NULL in CheckPointersUsedInFinish() !!!!"<<endl;
12746   cout<<endl;
12747   exit(0); 
12748  }  
12749  
12750 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInFinish()
12751
12752 //================================================================================================================================
12753
12754 void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
12755 {
12756  // Check all pointers used in method Make().
12757  
12758
12759 } // end of void AliFlowAnalysisWithQCumulants::CheckPointersUsedInMake()
12760  
12761