]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx
have unique histogram names when using multiple instances of this method
[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  *           (anteb@nikhef.nl)    *
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 #include "TFile.h"
31 #include "TList.h"
32 #include "TGraph.h"
33 #include "TParticle.h"
34 #include "TRandom3.h"
35 #include "TStyle.h"
36 #include "TProfile.h"
37 #include "TProfile2D.h" 
38 #include "TProfile3D.h"
39 #include "TMath.h"
40 #include "TArrow.h"
41 #include "TPaveLabel.h"
42 #include "TCanvas.h"
43 #include "AliFlowEventSimple.h"
44 #include "AliFlowTrackSimple.h"
45 #include "AliFlowAnalysisWithQCumulants.h"
46 #include "TArrayD.h"
47 #include "TRandom.h"
48 #include "TF1.h"
49
50 class TH1;
51 class TH2;
52 class TGraph;
53 class TPave;
54 class TLatex;
55 class TMarker;
56 class TRandom3;
57 class TObjArray;
58 class TList;
59 class TCanvas;
60 class TSystem;
61 class TROOT;
62 class AliFlowVector;
63 class TVector;
64
65
66 //================================================================================================================
67
68
69 ClassImp(AliFlowAnalysisWithQCumulants)
70
71 AliFlowAnalysisWithQCumulants::AliFlowAnalysisWithQCumulants(): 
72  // 0.) base:
73  fHistList(NULL),
74  // 1.) common:
75  fCommonHists(NULL),
76  fCommonHists2nd(NULL), 
77  fCommonHists4th(NULL),
78  fCommonHists6th(NULL),
79  fCommonHists8th(NULL),
80  fCommonHistsResults2nd(NULL),
81  fCommonHistsResults4th(NULL),
82  fCommonHistsResults6th(NULL),
83  fCommonHistsResults8th(NULL),
84  fnBinsPhi(0),
85  fPhiMin(0),
86  fPhiMax(0),
87  fPhiBinWidth(0),
88  fnBinsPt(0),
89  fPtMin(0),
90  fPtMax(0),
91  fPtBinWidth(0),
92  fnBinsEta(0),
93  fEtaMin(0),
94  fEtaMax(0),
95  fEtaBinWidth(0),
96  fHarmonic(2),
97  fAnalysisLabel(NULL),
98  // 2.) weights:
99  fWeightsList(NULL),
100  fUsePhiWeights(kFALSE),
101  fUsePtWeights(kFALSE),
102  fUseEtaWeights(kFALSE),
103  fUseParticleWeights(NULL),
104  fPhiWeights(NULL),
105  fPtWeights(NULL),
106  fEtaWeights(NULL),
107  // 3.) integrated flow:
108  fIntFlowList(NULL), 
109  fIntFlowProfiles(NULL),
110  fIntFlowResults(NULL),
111  fReQ(NULL),
112  fImQ(NULL),
113  fSMpk(NULL),
114  fAvMultiplicity(NULL),
115  // 4.) differential flow:
116  fDiffFlowList(NULL),
117  fDiffFlowProfiles(NULL),
118  fDiffFlowResults(NULL),
119  // 5.) distributions:
120  fDistributionsList(NULL),
121  // x.) debugging and cross-checking:
122  fNestedLoopsList(NULL),
123  fEvaluateNestedLoopsForIntFlow(kFALSE),
124  fEvaluateNestedLoopsForDiffFlow(kFALSE),  
125  fEvaluateNestedLoops(NULL),
126  fDirectCorrelations(NULL),
127  fDirectCorrectionsCos(NULL),
128  fDirectCorrectionsSin(NULL),
129  fDirectCorrelationsDiffFlow(NULL),
130  fDirectCorrectionsDiffFlowCos(NULL),
131  fDirectCorrectionsDiffFlowSin(NULL),
132  fDirectCorrelationsW(NULL),
133  fDirectCorrectionsCosW(NULL),
134  fDirectCorrectionsSinW(NULL),
135  fDirectCorrelationsDiffFlowW(NULL),
136  fDirectCorrectionsDiffFlowCosW(NULL),
137  fDirectCorrectionsDiffFlowSinW(NULL)
138  {
139   // constructor  
140   
141   // base list to hold all output objects:
142   fHistList = new TList();
143   fHistList->SetName("cobjQC");
144   fHistList->SetOwner(kTRUE);
145   
146   // list to hold histograms with phi, pt and eta weights:      
147   fWeightsList = new TList();
148   fWeightsList->SetName("Weights");
149   fWeightsList->SetOwner(kTRUE);
150     
151   // analysis label;
152   fAnalysisLabel = new TString();
153       
154   // initialize all arrays:  
155   this->InitializeArraysForIntFlow();
156   this->InitializeArraysForDiffFlow();
157   this->InitializeArraysForDistributions();
158   
159  } // end of constructor
160  
161
162 //================================================================================================================  
163
164
165 AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
166 {
167  // destructor
168  
169  delete fHistList;
170
171 } // end of AliFlowAnalysisWithQCumulants::~AliFlowAnalysisWithQCumulants()
172
173
174 //================================================================================================================
175
176
177 void AliFlowAnalysisWithQCumulants::Init()
178 {
179  // initialize all constants and book everything
180  
181  // access constants:
182  this->AccessConstants();
183  
184  // booking:
185  this->BookAndNestAllLists();
186  this->BookCommonHistograms();
187  this->BookAndFillWeightsHistograms(); 
188  this->BookEverythingForIntegratedFlow(); 
189  this->BookEverythingForDifferentialFlow(); 
190  this->BookEverythingForDistributions();
191  this->BookEverythingForNestedLoops();
192  
193  // set harmonic in common control histograms (to be improved (should I do this somewhere else?)):
194  (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
195  (fCommonHists2nd->GetHarmonic())->Fill(0.5,fHarmonic);
196  (fCommonHists4th->GetHarmonic())->Fill(0.5,fHarmonic);
197  (fCommonHists6th->GetHarmonic())->Fill(0.5,fHarmonic);
198  (fCommonHists8th->GetHarmonic())->Fill(0.5,fHarmonic);
199  
200 } // end of void AliFlowAnalysisWithQCumulants::Init()
201
202
203 //================================================================================================================
204
205
206 void AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
207 {
208  // running over data only in this method
209  
210  // a) fill the common control histograms and call method to fill fAvMultiplicity;
211  // b) loop over data to calculate e-b-e quantities;
212  // c) call the methods;
213  // d) debugging and cross-checking (evaluate nested loops);
214  // e) reset e-b-e quantities.
215  
216  Double_t dPhi = 0.; // azimuthal angle in the laboratory frame
217  Double_t dPt  = 0.; // transverse momentum
218  Double_t dEta = 0.; // pseudorapidity
219
220  Double_t wPhi = 1.; // phi weight
221  Double_t wPt  = 1.; // pt weight
222  Double_t wEta = 1.; // eta weight
223                                                                                                                                 
224  // ********************************************
225  // **** FILL THE COMMON CONTROL HISTOGRAMS ****
226  // ********************************************
227                                          
228  Int_t nRP = anEvent->GetEventNSelTracksRP(); // number of RPs (i.e. number of particles used to determine the reaction plane)
229
230  fCommonHists->FillControlHistograms(anEvent); 
231  
232  if(nRP>1)
233  {
234   fCommonHists2nd->FillControlHistograms(anEvent);                                        
235   if(nRP>3)
236   {
237    fCommonHists4th->FillControlHistograms(anEvent);                                        
238    if(nRP>5)
239    {
240     fCommonHists6th->FillControlHistograms(anEvent);                                        
241     if(nRP>7)
242     {
243      fCommonHists8th->FillControlHistograms(anEvent);                                        
244     } // end of if(nRP>7)  
245    } // end of if(nRP>5) 
246   } // end of if(nRP>3)                                                                                                                      
247  } // end of if(nRP>1) 
248                              
249  this->FillAverageMultiplicities(nRP);                                                                  
250                                                                                                                                             
251  // *******************************************************
252  // **** LOOP OVER DATA AND CALCULATE E-B-E QUANTITIES ****
253  // *******************************************************
254  
255  Int_t nPrim = anEvent->NumberOfTracks();  // nPrim = total number of primary tracks, i.e. nPrim = nRP + nPOI + rest, where:
256                                            // nRP   = # of particles used to determine the reaction plane;
257                                            // nPOI  = # of particles of interest for a detailed flow analysis;
258                                            // rest  = # of particles which are not niether RPs nor POIs.  
259  
260  AliFlowTrackSimple *aftsTrack = NULL;
261  
262  for(Int_t i=0;i<nPrim;i++) 
263  { 
264   aftsTrack=anEvent->GetTrack(i);
265   if(aftsTrack)
266   {
267    if(!(aftsTrack->InRPSelection() || aftsTrack->InPOISelection())) continue; // consider only tracks which are RPs or POIs
268    
269    Int_t n = fHarmonic; // shortcut for the harmonic
270  
271    if(aftsTrack->InRPSelection()) // RP condition:
272    {    
273     dPhi = aftsTrack->Phi();
274     dPt  = aftsTrack->Pt();
275     dEta = aftsTrack->Eta();
276   
277     if(fUsePhiWeights && fPhiWeights && fnBinsPhi) // determine phi weight for this particle:
278     {
279      wPhi = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*fnBinsPhi/TMath::TwoPi())));
280     }
281     if(fUsePtWeights && fPtWeights && fnBinsPt) // determine pt weight for this particle:
282     {
283      wPt = fPtWeights->GetBinContent(1+(Int_t)(TMath::Floor((dPt-fPtMin)/fPtBinWidth))); 
284     }            
285     if(fUseEtaWeights && fEtaWeights && fEtaBinWidth) // determine eta weight for this particle: 
286     {
287      wEta = fEtaWeights->GetBinContent(1+(Int_t)(TMath::Floor((dEta-fEtaMin)/fEtaBinWidth))); 
288     } 
289     
290     // integrated flow: 
291     // calculate Re[Q_{m*n,k}] and Im[Q_{m*n,k}], m = 1,2,3,4, for this event:
292     for(Int_t m=0;m<4;m++)
293     {
294      for(Int_t k=0;k<9;k++)
295      {
296       (*fReQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1)*n*dPhi); 
297       (*fImQ)(m,k)+=pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1)*n*dPhi); 
298      } 
299     }
300     // calculate S^{M}_{p,k} for this event 
301     // Remark: final calculation of S^{M}_{p,k} follows after the loop over data bellow:
302     for(Int_t p=0;p<8;p++)
303     {
304      for(Int_t k=0;k<9;k++)
305      {     
306       (*fSMpk)(p,k)+=pow(wPhi*wPt*wEta,k);
307      }
308     } 
309
310     // differential flow:
311     // (r_{m*m,k}(pt,eta)): 
312     for(Int_t m=0;m<4;m++)
313     {
314      for(Int_t k=0;k<9;k++)
315      {
316       fReEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
317       fImEBE[0][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
318      }
319     } 
320     // s_{k}(pt,eta) for RPs // to be improved (clarified)
321     // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
322     for(Int_t k=0;k<9;k++)
323     {
324      fs[0][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
325     } 
326      
327     if(aftsTrack->InPOISelection())
328     {
329      // (q_{m*m,k}(pt,eta)): 
330      for(Int_t m=0;m<4;m++)
331      {
332       for(Int_t k=0;k<9;k++)
333       {
334        fReEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Cos((m+1.)*n*dPhi),1.);
335        fImEBE[2][m][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k)*TMath::Sin((m+1.)*n*dPhi),1.);
336       }
337      } 
338      // s_{k}(pt,eta) for RP&&POIs // to be improved (clarified)
339      // Remark: final calculation of s_{p,k}(pt,eta) follows after the loop over data bellow:
340      for(Int_t k=0;k<9;k++)
341      {
342       fs[2][k]->Fill(dPt,dEta,pow(wPhi*wPt*wEta,k),1.);
343      }
344       
345     } // end of if(aftsTrack->InPOISelection())
346    } // end of if(pTrack->InRPSelection())
347
348    if(aftsTrack->InPOISelection())
349    {
350     dPhi = aftsTrack->Phi();
351     dPt  = aftsTrack->Pt();
352     dEta = aftsTrack->Eta();
353        
354     // p_n(m*n,0):   
355     for(Int_t m=0;m<4;m++)
356     {
357      fReEBE[1][m][0]->Fill(dPt,dEta,TMath::Cos((m+1.)*n*dPhi),1.);
358      fImEBE[1][m][0]->Fill(dPt,dEta,TMath::Sin((m+1.)*n*dPhi),1.);
359     } 
360     
361    } // end of if(pTrack->InPOISelection() )   
362  
363   } else // to if(aftsTrack)
364     {
365      cout<<endl;
366      cout<<" WARNING: no particle! (i.e. aftsTrack is a NULL pointer in AFAWQC::Make().)"<<endl;
367      cout<<endl;       
368     }
369  } // end of for(Int_t i=0;i<nPrim;i++) 
370
371  // calculate the final expressions for S^{M}_{p,k}:
372  for(Int_t p=0;p<8;p++)
373  {
374   for(Int_t k=0;k<9;k++)
375   {
376    (*fSMpk)(p,k)=pow((*fSMpk)(p,k),p+1);
377   }  
378  } 
379  
380  // *****************************
381  // **** CALL THE METHODS *******
382  // *****************************
383
384  if(!fEvaluateNestedLoopsForIntFlow)
385  {
386   // without weights:
387   if(nRP>1) this->CalculateCorrelationsForIntegratedFlow();
388   if(nRP>0) this->CalculateCorrectionsForNonUniformAcceptanceForIntFlowCosTerms();
389   if(nRP>0) this->CalculateCorrectionsForNonUniformAcceptanceForIntFlowSinTerms();
390   if(nRP>3) this->CalculateQProductsForIntFlow();
391   if(nRP>1) this->CalculateSumAndProductOfEventWeights();
392   // with weights:
393   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
394   {
395    if(nRP>1) this->CalculateWeightedCorrelationsForIntegratedFlow();
396    if(nRP>3) this->CalculateWeightedQProductsForIntFlow();
397   } 
398  }
399
400  if(!fEvaluateNestedLoopsForDiffFlow)
401  {
402   // without weights:
403   if(nRP>1) this->CalculateCorrelationsForDifferentialFlow("RP");
404   if(nRP>1) this->CalculateCorrelationsForDifferentialFlow("POI");
405   
406   // with weights:
407   if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
408   {
409    if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow("RP");
410    if(nRP>1) this->CalculateWeightedCorrelationsForDifferentialFlow("POI");
411   } 
412  }
413  
414  // **************************************************************
415  // **** DEBUGGING AND CROSS-CHECKING (EVALUATE NESTED LOOPS) ****
416  // **************************************************************
417
418  if(fEvaluateNestedLoopsForIntFlow)
419  {
420   if(nPrim>0 && nPrim<15) // only for these multiplicities it is feasible to evaluate 8 nested loops in short time 
421   {
422    // without weights:
423    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
424    {
425     this->CalculateCorrelationsForIntegratedFlow();
426     this->CalculateCorrectionsForNonUniformAcceptanceForIntFlowCosTerms();
427     this->CalculateCorrectionsForNonUniformAcceptanceForIntFlowSinTerms();
428    }
429    // with weights:
430    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
431    {
432     this->CalculateWeightedCorrelationsForIntegratedFlow();
433    }
434     
435    this->EvaluateNestedLoopsForIntegratedFlow(anEvent);  
436   }
437  } 
438  
439  if(fEvaluateNestedLoopsForDiffFlow)
440  {
441   if(nPrim>0 && nPrim<15) // only for these multiplicities it is feasible to evaluate 8 nested loops in short time 
442   {
443    // without weights:
444    if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
445    {
446     this->CalculateCorrelationsForDifferentialFlow("RP");
447     this->CalculateCorrelationsForDifferentialFlow("POI");
448    }
449    // with weights:
450    if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
451    {
452     this->CalculateWeightedCorrelationsForDifferentialFlow("RP");
453     this->CalculateWeightedCorrelationsForDifferentialFlow("POI");
454    }
455     
456    this->EvaluateNestedLoopsForDifferentialFlow(anEvent);  
457   }
458  } 
459  
460  // ********************************
461  // **** RESET E-B-E QUANTITIES ****
462  // ********************************
463  
464  // integrated flow:
465  fReQ->Zero();
466  fImQ->Zero();
467  fSMpk->Zero();
468  for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++)
469  {
470   fQCorrelationsEBE[pW]->Reset();
471   for(Int_t sc=0;sc<2;sc++)
472   {
473     fQCorrectionsEBE[pW][sc]->Reset();
474   } 
475  }  
476  
477  // differential flow:
478  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
479  {
480   for(Int_t m=0;m<4;m++) // multiple of harmonic
481   {
482    for(Int_t k=0;k<9;k++) // power of weight
483    {
484     if(fReEBE[t][m][k]) fReEBE[t][m][k]->Reset();
485     if(fImEBE[t][m][k]) fImEBE[t][m][k]->Reset();
486    }   
487   }
488  }
489  
490  for(Int_t t=0;t<3;t++) // type (0 = RP, 1 = POI, 2 = RP&&POI )
491  { 
492   for(Int_t k=0;k<9;k++)
493   {
494    if(fs[t][k]) fs[t][k]->Reset();
495   }
496  }
497  
498 } // end of AliFlowAnalysisWithQCumulants::Make(AliFlowEventSimple* anEvent)
499
500
501 //================================================================================================================================
502
503
504 void AliFlowAnalysisWithQCumulants::Finish()
505 {
506  // calculate the final results
507
508  // a) acces the constants;
509  // b) access the flags;
510  // c) calculate the final results for integrated flow (without and with weights);
511  // d) store in AliFlowCommonHistResults and print the final results for integrated flow;
512  // e) calculate the final results for differential flow (without and with weights);
513  // f) print the final results for integrated flow obtained from differential flow (to be improved (terminology));
514  // g) COMPARE RESULTS FROM NESTED LOOPS vs RESULTS FROM Q-VECTORS FOR INTEGRATED FLOW
515  
516  // ******************************
517  // **** ACCESS THE CONSTANTS ****
518  // ******************************
519  
520  this->AccessConstants();          
521  
522  // **************************
523  // **** ACCESS THE FLAGS ****
524  // **************************    
525
526  fUsePhiWeights = (Int_t)fUseParticleWeights->GetBinContent(1); 
527  fUsePtWeights = (Int_t)fUseParticleWeights->GetBinContent(2); 
528  fUseEtaWeights = (Int_t)fUseParticleWeights->GetBinContent(3); 
529  fEvaluateNestedLoopsForIntFlow = (Int_t)fEvaluateNestedLoops->GetBinContent(1);
530  fEvaluateNestedLoopsForDiffFlow = (Int_t)fEvaluateNestedLoops->GetBinContent(2); 
531     
532  // *********************************************************
533  // **** CALCULATE THE FINAL RESULTS FOR INTEGRATED FLOW ****
534  // *********************************************************    
535  
536  // without weights:
537  this->FinalizeCorrelationsForIntFlow(kFALSE,"exact");
538  this->CalculateFinalCorrectionsForNonUniformAcceptanceForCumulantsForIntFlow(kFALSE,"exact");
539  this->CalculateCovariancesForIntFlow(kFALSE,"exact");
540  this->CalculateCumulantsForIntFlow(kFALSE,"exact");
541  this->ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(kFALSE,"exact");
542  this->CalculateIntFlow(kFALSE,"exact",kFALSE); // pW = 0, eW = 0, not corrected for non-uniform acceptance
543  this->CalculateIntFlow(kFALSE,"exact",kTRUE); // pW = 0, eW = 0, corrected for non-uniform acceptance
544  
545  // with weights:
546  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
547  {
548   this->FinalizeCorrelationsForIntFlow(kTRUE,"exact"); 
549   // this->CalculateFinalCorrectionsForNonUniformAcceptanceForCumulantsForIntFlow(kTRUE,"exact");
550   this->CalculateCovariancesForIntFlow(kTRUE,"exact");
551   this->CalculateCumulantsForIntFlow(kTRUE,"exact");
552   // this->ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(kTRUE,"exact");
553   this->CalculateIntFlow(kTRUE,"exact",kFALSE); // weighted and not corrected for non-uniform acceptance
554   // this->CalculateIntFlow(kTRUE,"exact",kTRUE); // weighted and corrected for non-uniform acceptance
555  }
556  
557  // ***************************************************************
558  // **** STORE AND PRINT THE FINAL RESULTS FOR INTEGRATED FLOW ****
559  // ***************************************************************
560  
561  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
562  {        
563   this->FillCommonHistResultsIntFlow(kTRUE,"exact",kFALSE); // weighted and not corrected for non-uniform acceptance       
564   // this->FillCommonHistResultsIntFlow(kTRUE,kTRUE); // weighted and corrected for non-uniform acceptance (to be improved (enabled))    
565   // this->PrintQuantifyingCorrectionsForNonUniformAcceptance(kTRUE,"exact"); // (to be improved (enabled))
566  } else 
567    {
568     this->FillCommonHistResultsIntFlow(kFALSE,"exact",kTRUE); // non-weighted and corrected for non-uniform acceptance 
569     this->PrintQuantifyingCorrectionsForNonUniformAcceptance(kFALSE,"exact"); 
570    }
571  
572  this->PrintFinalResultsForIntegratedFlow("NONAME"); // to be improved (name)
573  
574  // ***********************************************************
575  // **** CALCULATE THE FINAL RESULTS FOR DIFFERENTIAL FLOW ****
576  // ***********************************************************    
577  
578  // without weights:
579  this->FinalizeCorrelationsForDiffFlow("RP",kFALSE,"exact");
580  this->FinalizeCorrelationsForDiffFlow("POI",kFALSE,"exact");
581  this->CalculateCumulantsForDiffFlow("RP",kFALSE,"exact");
582  this->CalculateCumulantsForDiffFlow("POI",kFALSE,"exact");
583  this->CalculateDiffFlow("RP",kFALSE,"exact");
584  this->CalculateDiffFlow("POI",kFALSE,"exact");
585  this->CalculateFinalResultsForRPandPOIIntegratedFlow("RP",kFALSE,"exact");
586  this->CalculateFinalResultsForRPandPOIIntegratedFlow("POI",kFALSE,"exact");
587  
588  // with weights:
589  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
590  {
591   this->FinalizeCorrelationsForDiffFlow("RP",kTRUE,"exact");
592   this->FinalizeCorrelationsForDiffFlow("POI",kTRUE,"exact");
593   this->CalculateCumulantsForDiffFlow("RP",kTRUE,"exact");
594   this->CalculateCumulantsForDiffFlow("POI",kTRUE,"exact");
595   this->CalculateDiffFlow("RP",kTRUE,"exact");
596   this->CalculateDiffFlow("POI",kTRUE,"exact");
597   this->CalculateFinalResultsForRPandPOIIntegratedFlow("RP",kTRUE,"exact");
598   this->CalculateFinalResultsForRPandPOIIntegratedFlow("POI",kTRUE,"exact");
599  }
600  
601    
602   //this->CalculateFinalCorrectionsForNonUniformAcceptanceForDifferentialFlow(kFALSE,"POI"); // to be improved (to calculate also when weights are used) 
603   //this->CalculateFinalCorrectionsForNonUniformAcceptanceForDifferentialFlow(kFALSE,"RP"); // to be improved (to calculate also when weights are used)
604
605  
606  // *****************************************************************
607  // **** STORE AND PRINT THE FINAL RESULTS FOR DIFFERENTIAL FLOW ****
608  // *****************************************************************
609  if(fUsePhiWeights||fUsePtWeights||fUseEtaWeights)
610  {
611   this->FillCommonHistResultsDiffFlow("RP",kTRUE,"exact",kFALSE);
612   this->FillCommonHistResultsDiffFlow("POI",kTRUE,"exact",kFALSE);
613  } else
614    {
615     this->FillCommonHistResultsDiffFlow("RP",kFALSE,"exact",kFALSE);
616     this->FillCommonHistResultsDiffFlow("POI",kFALSE,"exact",kFALSE);
617    }
618  
619  this->PrintFinalResultsForIntegratedFlow("RP"); 
620  this->PrintFinalResultsForIntegratedFlow("POI"); 
621   
622  // *****************************************************************************************
623  // **** COMPARE RESULTS FROM NESTED LOOPS vs RESULTS FROM Q-VECTORS FOR INTEGRATED FLOW ****
624  // *****************************************************************************************    
625  
626  if(fEvaluateNestedLoopsForIntFlow) 
627  {
628   this->CompareResultsFromNestedLoopsAndFromQVectorsForIntFlow(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);
629  } 
630  
631  if(fEvaluateNestedLoopsForDiffFlow) 
632  {
633   this->CompareResultsFromNestedLoopsAndFromQVectorsForDiffFlow(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);
634  } 
635                                                                                                                                                                                                                                                                                                                                    
636 } // end of AliFlowAnalysisWithQCumulants::Finish()
637
638
639 //================================================================================================================================
640
641
642 void AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForIntFlowCosTerms()
643 {
644  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (cos terms)
645  
646  // multiplicity:
647  Double_t dMult = (*fSMpk)(0,0);
648  
649  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
650  Double_t dReQ1n = (*fReQ)(0,0);
651  Double_t dReQ2n = (*fReQ)(1,0);
652  //Double_t dReQ3n = (*fReQ)(2,0);
653  //Double_t dReQ4n = (*fReQ)(3,0);
654  Double_t dImQ1n = (*fImQ)(0,0);
655  Double_t dImQ2n = (*fImQ)(1,0);
656  //Double_t dImQ3n = (*fImQ)(2,0);
657  //Double_t dImQ4n = (*fImQ)(3,0);
658         
659  //                                  *************************************************************
660  //                                  **** corrections for non-uniform acceptance (cos terms): ****
661  //                                  *************************************************************
662  //
663  // Remark 1: corrections for non-uniform acceptance (cos terms) calculated with non-weighted Q-vectors 
664  //           are stored in 1D profile fQCorrectionsCos.
665  // Remark 2: binning of fQCorrectionsCos is organized as follows:
666  // --------------------------------------------------------------------------------------------------------------------
667  // 1st bin: <<cos(n*(phi1))>> = cosP1n
668  // 2nd bin: <<cos(n*(phi1+phi2))>> = cosP1nP1n
669  // 3rd bin: <<cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1n
670  // ...
671  // --------------------------------------------------------------------------------------------------------------------
672   
673  // 1-particle:
674  Double_t cosP1n = 0.; // <<cos(n*(phi1))>>
675    
676  if(dMult>0)
677  {
678   cosP1n = dReQ1n/dMult; 
679   
680   // average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for single event:
681   fQCorrectionsEBE[0][1]->SetBinContent(1,cosP1n);
682   
683   // final average non-weighted 1-particle correction (cos terms) for non-uniform acceptance for all events:
684   fQCorrections[0][0][1]->Fill(0.5,cosP1n,dMult);  
685  } 
686  
687  // 2-particle:
688  Double_t cosP1nP1n = 0.; // <<cos(n*(phi1+phi2))>>
689  
690  if(dMult>1)
691  {
692   cosP1nP1n = (pow(dReQ1n,2)-pow(dImQ1n,2)-dReQ2n)/(dMult*(dMult-1)); 
693   
694   // average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for single event:
695   fQCorrectionsEBE[0][1]->SetBinContent(2,cosP1nP1n);
696   
697   // final average non-weighted 2-particle correction (cos terms) for non-uniform acceptance for all events:
698   fQCorrections[0][0][1]->Fill(1.5,cosP1nP1n,dMult*(dMult-1));  
699  } 
700  
701  // 3-particle:
702  Double_t cosP1nM1nM1n = 0.; // <<cos(n*(phi1-phi2-phi3))>>
703  
704  if(dMult>2)
705  {
706   cosP1nM1nM1n = (dReQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))-dReQ1n*dReQ2n-dImQ1n*dImQ2n-2.*(dMult-1)*dReQ1n)
707                / (dMult*(dMult-1)*(dMult-2)); 
708   
709   // average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for single event:
710   fQCorrectionsEBE[0][1]->SetBinContent(3,cosP1nM1nM1n);
711   
712   // final average non-weighted 3-particle correction (cos terms) for non-uniform acceptance for all events:
713   fQCorrections[0][0][1]->Fill(2.5,cosP1nM1nM1n,dMult*(dMult-1)*(dMult-2));  
714  } 
715  
716 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForIntFlowCosTerms()
717
718
719 //================================================================================================================================
720
721
722 void AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForIntFlowSinTerms()
723 {
724  // calculate corrections for non-uniform acceptance of the detector for no-name integrated flow (sin terms)
725  
726  // multiplicity:
727  Double_t dMult = (*fSMpk)(0,0);
728  
729  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
730  Double_t dReQ1n = (*fReQ)(0,0);
731  Double_t dReQ2n = (*fReQ)(1,0);
732  //Double_t dReQ3n = (*fReQ)(2,0);
733  //Double_t dReQ4n = (*fReQ)(3,0);
734  Double_t dImQ1n = (*fImQ)(0,0);
735  Double_t dImQ2n = (*fImQ)(1,0);
736  //Double_t dImQ3n = (*fImQ)(2,0);
737  //Double_t dImQ4n = (*fImQ)(3,0);
738         
739  //                                  *************************************************************
740  //                                  **** corrections for non-uniform acceptance (sin terms): ****
741  //                                  *************************************************************
742  //
743  // Remark 1: corrections for non-uniform acceptance (sin terms) calculated with non-weighted Q-vectors 
744  //           are stored in 1D profile fQCorrectionsSin.
745  // Remark 2: binning of fQCorrectionsSin is organized as follows:
746  // --------------------------------------------------------------------------------------------------------------------
747  // 1st bin: <<sin(n*(phi1))>> = sinP1n
748  // 2nd bin: <<sin(n*(phi1+phi2))>> = sinP1nP1n
749  // 3rd bin: <<sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1n
750  // ...
751  // --------------------------------------------------------------------------------------------------------------------
752  
753  // 1-particle:
754  Double_t sinP1n = 0.; // <sin(n*(phi1))>
755  
756  if(dMult>0)
757  {
758   sinP1n = dImQ1n/dMult; 
759      
760   // average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for single event:
761   fQCorrectionsEBE[0][0]->SetBinContent(1,sinP1n);
762   
763   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:   
764   fQCorrections[0][0][0]->Fill(0.5,sinP1n,dMult);  
765  } 
766  
767  // 2-particle:
768  Double_t sinP1nP1n = 0.; // <<sin(n*(phi1+phi2))>>
769  
770  if(dMult>1)
771  {
772   sinP1nP1n = (2.*dReQ1n*dImQ1n-dImQ2n)/(dMult*(dMult-1)); 
773      
774   // average non-weighted 2-particle correction (sin terms) for non-uniform acceptance for single event:
775   fQCorrectionsEBE[0][0]->SetBinContent(2,sinP1nP1n);
776   
777   // final average non-weighted 1-particle correction (sin terms) for non-uniform acceptance for all events:      
778   fQCorrections[0][0][0]->Fill(1.5,sinP1nP1n,dMult*(dMult-1));  
779  } 
780  
781  // 3-particle:
782  Double_t sinP1nM1nM1n = 0.; // <<sin(n*(phi1-phi2-phi3))>>
783  
784  if(dMult>2)
785  {
786   sinP1nM1nM1n = (-dImQ1n*(pow(dReQ1n,2)+pow(dImQ1n,2))+dReQ1n*dImQ2n-dImQ1n*dReQ2n+2.*(dMult-1)*dImQ1n)
787                / (dMult*(dMult-1)*(dMult-2)); 
788   
789   // average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for single event:
790   fQCorrectionsEBE[0][0]->SetBinContent(3,sinP1nM1nM1n);
791   
792   // final average non-weighted 3-particle correction (sin terms) for non-uniform acceptance for all events:  
793   fQCorrections[0][0][0]->Fill(2.5,sinP1nM1nM1n,dMult*(dMult-1)*(dMult-2));  
794  } 
795  
796 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForIntFlowSinTerms()
797
798
799 //================================================================================================================================
800
801
802 void AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForDifferentialFlowCosTerms(TString type)
803 {
804  // calculate corrections for non-uniform acceptance of the detector for differential flow (cos terms)
805  
806  // multiplicity:
807  //Double_t dMult = (*fSMpk)(0,0);
808  
809  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
810  //Double_t dReQ1n = (*fReQ)(0,0);
811  //Double_t dReQ2n = (*fReQ)(1,0);
812  //Double_t dReQ3n = (*fReQ)(2,0);
813  //Double_t dReQ4n = (*fReQ)(3,0);
814  //Double_t dImQ1n = (*fImQ)(0,0);
815  //Double_t dImQ2n = (*fImQ)(1,0);
816  //Double_t dImQ3n = (*fImQ)(2,0);
817  //Double_t dImQ4n = (*fImQ)(3,0);
818
819  // looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
820  for(Int_t p=1;p<=fnBinsPt;p++)
821  {
822   for(Int_t e=1;e<=fnBinsEta;e++)
823   {
824    // real and imaginary parts of q_n (non-weighted Q-vector evaluated only for POIs in harmonic n for each (pt,eta) bin): 
825    //Double_t dReqnPtEta = 0.;
826    //Double_t dImqnPtEta = 0.;
827
828    // number of POIs in each (pt,eta) bin:
829    Double_t dmPtEta = 0.;
830
831    // real and imaginary parts of q''_{n}, q''_{2n}, ... 
832    // (non-weighted Q-vectors evaluated only for particles which are both RPs and POIs in harmonic n, 2n, ... for each (pt,eta) bin): 
833    //Double_t dReqPrimePrime1nPtEta = 0.;
834    //Double_t dImqPrimePrime1nPtEta = 0.;
835    //Double_t dReqPrimePrime2nPtEta = 0.;
836    //Double_t dImqPrimePrime2nPtEta = 0.;
837
838    // number of particles which are both RPs and POIs in each (pt,eta) bin:
839    //Double_t dmPrimePrimePtEta = 0.;
840    
841    if(type == "POI")
842    {
843     // q''_{n}, q''_{2n}:
844     //...............................................................................................
845     //dReqPrimePrime1nPtEta = fReqPrimePrime1nPtEta->GetBinContent(fReqPrimePrime1nPtEta->GetBin(p,e));
846     //dImqPrimePrime1nPtEta = fImqPrimePrime1nPtEta->GetBinContent(fImqPrimePrime1nPtEta->GetBin(p,e));
847     //dReqPrimePrime2nPtEta = fReqPrimePrime2nPtEta->GetBinContent(fReqPrimePrime2nPtEta->GetBin(p,e));
848     //dImqPrimePrime2nPtEta = fImqPrimePrime2nPtEta->GetBinContent(fImqPrimePrime2nPtEta->GetBin(p,e));
849     //...............................................................................................
850    
851     // m'':
852     //dmPrimePrimePtEta = fmPrimePrimePtEta->GetBinContent(fmPrimePrimePtEta->GetBin(p,e));
853    
854     // q'_{n}: 
855     //dReqnPtEta = fReqnPtEta->GetBinContent(fReqnPtEta->GetBin(p,e));
856     //dImqnPtEta = fImqnPtEta->GetBinContent(fImqnPtEta->GetBin(p,e));
857     //dmPtEta    = fmPtEta->GetBinContent(fmPtEta->GetBin(p,e));
858    }
859    else if(type == "RP")
860    {
861     // q_RP{n}, q_RP{2n}:
862     //...............................................................................................
863     //dReqPrimePrime1nPtEta = fReqRP1nPtEta->GetBinContent(fReqRP1nPtEta->GetBin(p,e));
864     //dImqPrimePrime1nPtEta = fImqRP1nPtEta->GetBinContent(fImqRP1nPtEta->GetBin(p,e));
865     //dReqPrimePrime2nPtEta = fReqRP2nPtEta->GetBinContent(fReqRP2nPtEta->GetBin(p,e));
866     //dImqPrimePrime2nPtEta = fImqRP2nPtEta->GetBinContent(fImqRP2nPtEta->GetBin(p,e));
867     //...............................................................................................
868    
869     // m'':
870     //dmPrimePrimePtEta = fmRPPtEta->GetBinContent(fmRPPtEta->GetBin(p,e));
871    
872     //dReqnPtEta = fReqRP1nPtEta->GetBinContent(fReqRP1nPtEta->GetBin(p,e)); // not a bug ;-)
873     //dImqnPtEta = fImqRP1nPtEta->GetBinContent(fImqRP1nPtEta->GetBin(p,e)); // not a bug ;-)
874     //dmPtEta    = fmRPPtEta->GetBinContent(fmRPPtEta->GetBin(p,e));         // not a bug ;-) 
875    }
876    
877    // 1'-p correction:
878    //Double_t oneCosP1nPsiPtEta = 0.;
879    
880    if(dmPtEta)
881    {
882     //oneCosP1nPsiPtEta = dReqnPtEta/dmPtEta;
883    
884     // fill the 2D profile to get the average 1'-p correction for each (pt, eta) bin:
885     if(type == "POI")
886     { 
887      //fCorrectionsCosP1nPsiPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,
888      //                                    oneCosP1nPsiPtEta,dmPtEta);
889     }
890     else if(type == "RP")
891     {
892      //fCorrectionsCosP1nPsiPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,
893      //                                    oneCosP1nPsiPtEta,dmPtEta);
894     }
895    } // end of if(dmPtEta*dMult-dmPrimePrimePtEta)
896    
897    /*
898    
899    // 4'-particle correlation:
900    Double_t four1n1n1n1nPtEta = 0.;
901    if((dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
902        + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
903    {
904     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(dReqnPtEta*dReQ1n+dImqnPtEta*dImQ1n)
905                       - dReqPrimePrime2nPtEta*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
906                       - 2.*dImqPrimePrime2nPtEta*dReQ1n*dImQ1n
907                       - dReqnPtEta*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
908                       + dImqnPtEta*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
909                       - 2.*dMult*(dReqnPtEta*dReQ1n+dImqnPtEta*dImQ1n)
910                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*dmPrimePrimePtEta                      
911                       + 6.*(dReqPrimePrime1nPtEta*dReQ1n+dImqPrimePrime1nPtEta*dImQ1n)                                            
912                       + 1.*(dReqPrimePrime2nPtEta*dReQ2n+dImqPrimePrime2nPtEta*dImQ2n)                      
913                       + 2.*(dReqnPtEta*dReQ1n+dImqnPtEta*dImQ1n)                       
914                       + 2.*dmPrimePrimePtEta*dMult                      
915                       - 6.*dmPrimePrimePtEta)        
916                       / ((dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
917                           + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
918     
919     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
920     if(type == "POI")
921     {
922      f4pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
923                        (dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
924                         + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.));
925     }
926     else if(type == "RP")
927     {
928      f4pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
929                       (dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
930                        + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.));   
931     }
932    } // end of if((dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
933      //            +dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.))
934    
935   */
936    
937   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
938  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
939  
940 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForDifferentialFlowCosTerms(TString type)
941
942
943 //================================================================================================================================
944
945
946 void AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForDifferentialFlowSinTerms(TString type)
947 {
948  // calculate corrections for non-uniform acceptance of the detector for differential flow (sin terms)
949  
950  // multiplicity:
951  //Double_t dMult = (*fSMpk)(0,0);
952  
953  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
954  //Double_t dReQ1n = (*fReQ)(0,0);
955  //Double_t dReQ2n = (*fReQ)(1,0);
956  //Double_t dReQ3n = (*fReQ)(2,0);
957  //Double_t dReQ4n = (*fReQ)(3,0);
958  //Double_t dImQ1n = (*fImQ)(0,0);
959  //Double_t dImQ2n = (*fImQ)(1,0);
960  //Double_t dImQ3n = (*fImQ)(2,0);
961  //Double_t dImQ4n = (*fImQ)(3,0);
962
963  // looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
964  for(Int_t p=1;p<=fnBinsPt;p++)
965  {
966   for(Int_t e=1;e<=fnBinsEta;e++)
967   {
968    // real and imaginary parts of q_n (non-weighted Q-vector evaluated only for POIs in harmonic n for each (pt,eta) bin): 
969    //Double_t dReqnPtEta = 0.;
970    //Double_t dImqnPtEta = 0.;
971
972    // number of POIs in each (pt,eta) bin:
973    Double_t dmPtEta = 0.;
974
975    // real and imaginary parts of q''_{n}, q''_{2n}, ... 
976    // (non-weighted Q-vectors evaluated only for particles which are both RPs and POIs in harmonic n, 2n, ... for each (pt,eta) bin): 
977    //Double_t dReqPrimePrime1nPtEta = 0.;
978    //Double_t dImqPrimePrime1nPtEta = 0.;
979    //Double_t dReqPrimePrime2nPtEta = 0.;
980    //Double_t dImqPrimePrime2nPtEta = 0.;
981
982    // number of particles which are both RPs and POIs in each (pt,eta) bin:
983    //Double_t dmPrimePrimePtEta = 0.;
984    
985    if(type == "POI")
986    {
987     // q''_{n}, q''_{2n}:
988     //...............................................................................................
989     //dReqPrimePrime1nPtEta = fReqPrimePrime1nPtEta->GetBinContent(fReqPrimePrime1nPtEta->GetBin(p,e));
990     //dImqPrimePrime1nPtEta = fImqPrimePrime1nPtEta->GetBinContent(fImqPrimePrime1nPtEta->GetBin(p,e));
991     //dReqPrimePrime2nPtEta = fReqPrimePrime2nPtEta->GetBinContent(fReqPrimePrime2nPtEta->GetBin(p,e));
992     //dImqPrimePrime2nPtEta = fImqPrimePrime2nPtEta->GetBinContent(fImqPrimePrime2nPtEta->GetBin(p,e));
993     //...............................................................................................
994    
995     // m'':
996     //dmPrimePrimePtEta = fmPrimePrimePtEta->GetBinContent(fmPrimePrimePtEta->GetBin(p,e));
997    
998     // q'_{n}: 
999     //dReqnPtEta = fReqnPtEta->GetBinContent(fReqnPtEta->GetBin(p,e));
1000     //dImqnPtEta = fImqnPtEta->GetBinContent(fImqnPtEta->GetBin(p,e));
1001     //dmPtEta    = fmPtEta->GetBinContent(fmPtEta->GetBin(p,e));
1002    }
1003    else if(type == "RP")
1004    {
1005     // q_RP{n}, q_RP{2n}:
1006     //...............................................................................................
1007     //dReqPrimePrime1nPtEta = fReqRP1nPtEta->GetBinContent(fReqRP1nPtEta->GetBin(p,e));
1008     //dImqPrimePrime1nPtEta = fImqRP1nPtEta->GetBinContent(fImqRP1nPtEta->GetBin(p,e));
1009     //dReqPrimePrime2nPtEta = fReqRP2nPtEta->GetBinContent(fReqRP2nPtEta->GetBin(p,e));
1010     //dImqPrimePrime2nPtEta = fImqRP2nPtEta->GetBinContent(fImqRP2nPtEta->GetBin(p,e));
1011     //...............................................................................................
1012    
1013     // m'':
1014     //dmPrimePrimePtEta = fmRPPtEta->GetBinContent(fmRPPtEta->GetBin(p,e));
1015    
1016     //dReqnPtEta = fReqRP1nPtEta->GetBinContent(fReqRP1nPtEta->GetBin(p,e)); // not a bug ;-)
1017     //dImqnPtEta = fImqRP1nPtEta->GetBinContent(fImqRP1nPtEta->GetBin(p,e)); // not a bug ;-)
1018     //dmPtEta    = fmRPPtEta->GetBinContent(fmRPPtEta->GetBin(p,e));         // not a bug ;-) 
1019    }
1020    
1021    // 1'-p correction:
1022    //Double_t oneSinP1nPsiPtEta = 0.;
1023    
1024    if(dmPtEta)
1025    {
1026     //oneSinP1nPsiPtEta = dImqnPtEta/dmPtEta;
1027    
1028     // fill the 2D profile to get the average 1'-p correction for each (pt, eta) bin:
1029     if(type == "POI")
1030     { 
1031      //fCorrectionsSinP1nPsiPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,
1032      //                                    oneSinP1nPsiPtEta,dmPtEta);
1033     }
1034     else if(type == "RP")
1035     {
1036      //fCorrectionsSinP1nPsiPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,
1037      //                                    oneSinP1nPsiPtEta,dmPtEta);
1038     }
1039    } // end of if(dmPtEta*dMult-dmPrimePrimePtEta)
1040    
1041    /*
1042    
1043    // 4'-particle correlation:
1044    Double_t four1n1n1n1nPtEta = 0.;
1045    if((dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
1046        + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
1047    {
1048     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(dReqnPtEta*dReQ1n+dImqnPtEta*dImQ1n)
1049                       - dReqPrimePrime2nPtEta*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
1050                       - 2.*dImqPrimePrime2nPtEta*dReQ1n*dImQ1n
1051                       - dReqnPtEta*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
1052                       + dImqnPtEta*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
1053                       - 2.*dMult*(dReqnPtEta*dReQ1n+dImqnPtEta*dImQ1n)
1054                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*dmPrimePrimePtEta                      
1055                       + 6.*(dReqPrimePrime1nPtEta*dReQ1n+dImqPrimePrime1nPtEta*dImQ1n)                                            
1056                       + 1.*(dReqPrimePrime2nPtEta*dReQ2n+dImqPrimePrime2nPtEta*dImQ2n)                      
1057                       + 2.*(dReqnPtEta*dReQ1n+dImqnPtEta*dImQ1n)                       
1058                       + 2.*dmPrimePrimePtEta*dMult                      
1059                       - 6.*dmPrimePrimePtEta)        
1060                       / ((dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
1061                           + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
1062     
1063     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
1064     if(type == "POI")
1065     {
1066      f4pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
1067                        (dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
1068                         + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.));
1069     }
1070     else if(type == "RP")
1071     {
1072      f4pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
1073                       (dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
1074                        + dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.));   
1075     }
1076    } // end of if((dmPtEta-dmPrimePrimePtEta)*dMult*(dMult-1.)*(dMult-2.)
1077      //            +dmPrimePrimePtEta*(dMult-1.)*(dMult-2.)*(dMult-3.))
1078    
1079   */
1080    
1081   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
1082  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
1083  
1084 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrectionsForNonUniformAcceptanceForDifferentialFlowSinTerms(TString type)
1085
1086
1087 //================================================================================================================================
1088
1089
1090 void AliFlowAnalysisWithQCumulants::EvaluateNestedLoopsForDifferentialFlow(AliFlowEventSimple* anEvent)
1091 {
1092  // evaluate the nested loops relevant for differential flow (needed for cross-checking the results)
1093  
1094  Int_t nPrim = anEvent->NumberOfTracks(); 
1095  AliFlowTrackSimple *aftsTrack = NULL;
1096  
1097  Double_t psi1=0., phi2=0., phi3=0., phi4=0.;// phi5=0., phi6=0., phi7=0., phi8=0.;
1098  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1.;// wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
1099  
1100  Int_t n = fHarmonic; // to be improved
1101  
1102  //                                          ********************************************
1103  //                                          **** NESTED LOOPS FOR DIFFERENTIAL FLOW ****
1104  //                                          ******************************************** 
1105  
1106  // Remark 1: (pt,eta) bin in which the cross-checking will be performed is given by 1.1 < pt < 1.2 GeV and -0.55 < eta < -0.525 
1107  
1108  // Remark 2: multi-particle correlations needed for diff. flow calculated with nested loops without weights are stored in 1D profile  
1109  //           fDirectCorrelationsDiffFlow
1110  
1111  // Remark 3: multi-particle correlations needed for diff. flow calculated with nested loops with weights are stored in 1D profile  
1112  //           fDirectCorrelationsDiffFlowW;
1113  
1114  // Remark 4: binning of fDirectCorrelationsDiffFlow is organized as follows:
1115  //......................................................................................
1116  //       ---- bins 1-20: 2-particle correlations ----
1117  //  1st bin: <2'>_{1n|1n} = twoPrime1n1n = <cos(n*(psi1-phi2))>
1118  //       ---- bins 21-40: 3-particle correlations ----
1119  //       ---- bins 41-60: 4-particle correlations ----
1120  // 41st bin: <4'>_{1n,1n|1n,1n} = fourPrime1n1n1n1n  = <cos(n*(psi1+phi2-phi3-phi4))>
1121  //......................................................................................
1122  
1123  // Remark 5: binning of fDirectCorrelationsDiffFlow is organized as follows:
1124  //......................................................................................
1125  //       ---- bins 1-20: 2-particle correlations ----
1126  //  1st bin: twoPrime1n1nW0W1 = <w2 cos(n*(psi1-phi2))>
1127  //       ---- bins 21-40: 3-particle correlations ----
1128  //       ---- bins 41-60: 4-particle correlations ----
1129  // 41st bin: fourPrime1n1n1n1nW0W1W1W1 = <w2 w3 w4 cos(n*(psi1+phi2-phi3-phi4))>
1130  //......................................................................................
1131  
1132  // 2'-particle:
1133  for(Int_t i1=0;i1<nPrim;i1++)
1134  {
1135   aftsTrack=anEvent->GetTrack(i1);
1136   // POI condition (first particle in the correlator must be POI): 
1137   if(!((aftsTrack->Pt()>=1.1 && aftsTrack->Pt()<1.2) && (aftsTrack->Eta()>=-0.55 && aftsTrack->Eta()<-0.525) && (aftsTrack->InPOISelection())))continue;
1138   psi1=aftsTrack->Phi(); 
1139   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(psi1*fnBinsPhi/TMath::TwoPi())));
1140   
1141   fDirectCorrectionsDiffFlowCos->Fill(0.,cos(1.*n*(psi1)),1.); // <<cos(n*(psi1))>>
1142   fDirectCorrectionsDiffFlowSin->Fill(0.,sin(1.*n*(psi1)),1.); // <<sin(n*(psi1))>>
1143   
1144   for(Int_t i2=0;i2<nPrim;i2++)
1145   {
1146    if(i2==i1)continue;
1147    aftsTrack=anEvent->GetTrack(i2);
1148    // RP condition (!(first) particle in the correlator must be RP):
1149    if(!(aftsTrack->InRPSelection()))continue;
1150    phi2=aftsTrack->Phi();
1151    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
1152     
1153    // non-weighted: 
1154    //.....................................................................................  
1155    fDirectCorrelationsDiffFlow->Fill(0.,cos(1.*n*(psi1-phi2)),1.); // <cos(n*(psi1-phi2))>
1156    //.....................................................................................  
1157    // weighted:
1158    //.....................................................................................   
1159    if(fUsePhiWeights) fDirectCorrelationsDiffFlowW->Fill(0.,cos(1.*n*(psi1-phi2)),wPhi2); // <w2 cos(n*(psi1-phi2))>
1160    //.....................................................................................  
1161    
1162    //fDirectCorrelations->Fill(103.,cos(1.*n*(phi1-phi2)),pow(wPhi1,2)*wPhi2);//<2'>_{n,n}
1163    //fDirectCorrelations->Fill(104.,cos(2.*n*(phi1-phi2)),wPhi1*pow(wPhi2,2));//<2'>_{n,n}
1164    //fDirectCorrelations->Fill(105.,cos(1.*n*(phi1-phi2)),pow(wPhi2,3));//<2'>_{n,n}  
1165    //fDirectCorrelations->Fill(41.,cos(2.*n*(phi1-phi2)),1);//<2'>_{2n,2n}
1166    //fDirectCorrelations->Fill(42.,cos(3.*n*(phi1-phi2)),1);//<2'>_{3n,3n}
1167    //fDirectCorrelations->Fill(43.,cos(4.*n*(phi1-phi2)),1);//<2'>_{4n,4n}   
1168     
1169   }//end of for(Int_t i2=0;i2<nPrim;i2++)
1170  }//end of for(Int_t i1=0;i1<nPrim;i1++)
1171  
1172  
1173  
1174  /*
1175  
1176  //<3'>_{2n|n,n}
1177  for(Int_t i1=0;i1<nPrim;i1++)
1178  {
1179   aftsTrack=anEvent->GetTrack(i1);
1180   if(!((aftsTrack->Pt()>=0.5&&aftsTrack->Pt()<0.6)&&(aftsTrack->InPOISelection())))continue;//POI condition
1181   psi1=aftsTrack->Phi();
1182   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(psi1*fnBinsPhi/TMath::TwoPi())));
1183   for(Int_t i2=0;i2<nPrim;i2++)
1184   {
1185    if(i2==i1)continue;
1186    aftsTrack=anEvent->GetTrack(i2);
1187    if(!(aftsTrack->InRPSelection()))continue;//RP condition
1188    phi2=aftsTrack->Phi();
1189    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
1190    for(Int_t i3=0;i3<nPrim;i3++)
1191    {
1192     if(i3==i1||i3==i2)continue;
1193     aftsTrack=anEvent->GetTrack(i3);
1194     if(!(aftsTrack->InRPSelection()))continue;//RP condition
1195     phi3=aftsTrack->Phi();
1196     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
1197     //fill the fDirectCorrelations:     
1198     
1199     // 2-p
1200     //fDirectCorrelations->Fill(101.,cos(n*(phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n(phi2-phi3))>
1201     //fDirectCorrelations->Fill(102.,cos(n*(phi1-phi3)),pow(wPhi2,2.)*wPhi3); // <w2^2 w3 cos(n(psi1-phi2))>
1202     
1203     // 3-p            
1204     //fDirectCorrelations->Fill(110.,cos(n*(2.*phi1-phi2-phi3)),wPhi1*wPhi2*wPhi3); // <w1 w2 w3 cos(n(2psi1-phi2-phi3))>
1205     //fDirectCorrelations->Fill(111.,cos(n*(phi1+phi2-2.*phi3)),wPhi2*pow(wPhi3,2.)); // <w2 w3^2 cos(n(psi1+phi2-2.*phi3))>
1206     
1207     
1208     //fDirectCorrelations->Fill(46.,cos(n*(phi1+phi2-2.*phi3)),1);//<3'>_{n,n|2n}    
1209    }//end of for(Int_t i3=0;i3<nPrim;i3++)  
1210   }//end of for(Int_t i2=0;i2<nPrim;i2++)  
1211  }//end of for(Int_t i1=0;i1<nPrim;i1++)
1212  */
1213  
1214  // 4'-particle:
1215  for(Int_t i1=0;i1<nPrim;i1++)
1216  {
1217   aftsTrack=anEvent->GetTrack(i1);
1218   // POI condition (first particle in the correlator must be POI): 
1219   if(!((aftsTrack->Pt()>=1.1 && aftsTrack->Pt()<1.2) && (aftsTrack->Eta()>=-0.55 && aftsTrack->Eta()<-0.525) && (aftsTrack->InPOISelection())))continue;
1220   psi1=aftsTrack->Phi();
1221   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(psi1*fnBinsPhi/TMath::TwoPi())));
1222   for(Int_t i2=0;i2<nPrim;i2++)
1223   {
1224    if(i2==i1)continue;
1225    aftsTrack=anEvent->GetTrack(i2);
1226    // RP condition (!(first) particle in the correlator must be RP): 
1227    if(!(aftsTrack->InRPSelection()))continue;
1228    phi2=aftsTrack->Phi();
1229    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
1230    for(Int_t i3=0;i3<nPrim;i3++)
1231    { 
1232     if(i3==i1||i3==i2)continue;
1233     aftsTrack=anEvent->GetTrack(i3);
1234     // RP condition (!(first) particle in the correlator must be RP):
1235     if(!(aftsTrack->InRPSelection()))continue;
1236     phi3=aftsTrack->Phi();
1237     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
1238     for(Int_t i4=0;i4<nPrim;i4++)
1239     {
1240      if(i4==i1||i4==i2||i4==i3)continue;
1241      aftsTrack=anEvent->GetTrack(i4);
1242      // RP condition (!(first) particle in the correlator must be RP):
1243      if(!(aftsTrack->InRPSelection()))continue;  
1244      phi4=aftsTrack->Phi();
1245      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
1246      
1247      // non-weighted:
1248      //.........................................................................................................................
1249      fDirectCorrelationsDiffFlow->Fill(40.,cos(n*(psi1+phi2-phi3-phi4)),1.); // <cos(n(psi1+phi1-phi2-phi3))> 
1250      //.........................................................................................................................     
1251      // weighted:
1252      //...............................................................................................................................
1253      if(fUsePhiWeights) fDirectCorrelationsDiffFlowW->Fill(40.,cos(n*(psi1+phi2-phi3-phi4)),wPhi2*wPhi3*wPhi4); // <w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))> 
1254      //...............................................................................................................................     
1255           
1256     }//end of for(Int_t i4=0;i4<nPrim;i4++)
1257    }//end of for(Int_t i3=0;i3<nPrim;i3++)
1258   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
1259  }//end of for(Int_t i1=0;i1<nPrim;i1++)
1260  
1261  /*                
1262  //<5'>_{2n,n|n,n,n}
1263  for(Int_t i1=0;i1<nPrim;i1++)
1264  {
1265   aftsTrack=anEvent->GetTrack(i1);
1266   if(!((aftsTrack->Pt()>=0.5&&aftsTrack->Pt()<0.6)&&(aftsTrack->InPOISelection())))continue;//POI condition
1267   phi1=aftsTrack->Phi();
1268   for(Int_t i2=0;i2<nPrim;i2++)
1269   {
1270    if(i2==i1)continue;
1271    aftsTrack=anEvent->GetTrack(i2);
1272    if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1273    phi2=aftsTrack->Phi();
1274    for(Int_t i3=0;i3<nPrim;i3++)
1275    { 
1276     if(i3==i1||i3==i2)continue;
1277     aftsTrack=anEvent->GetTrack(i3);
1278     if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1279     phi3=aftsTrack->Phi();
1280     for(Int_t i4=0;i4<nPrim;i4++)
1281     {
1282      if(i4==i1||i4==i2||i4==i3)continue;
1283      aftsTrack=anEvent->GetTrack(i4);
1284      if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1285      phi4=aftsTrack->Phi();//
1286      for(Int_t i5=0;i5<nPrim;i5++)
1287      {
1288       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
1289       aftsTrack=anEvent->GetTrack(i5);
1290       if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1291       phi5=aftsTrack->Phi();    
1292       //fill the fDirectCorrelations:if(bNestedLoops)
1293       //fDirectCorrelations->Fill(55.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1);//<5'>_{2n,n|n,n,n}
1294      }//end of for(Int_t i5=0;i5<nPrim;i5++)  
1295     }//end of for(Int_t i4=0;i4<nPrim;i4++)
1296    }//end of for(Int_t i3=0;i3<nPrim;i3++)
1297   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
1298  }//end of for(Int_t i1=0;i1<nPrim;i1++)
1299  
1300
1301   
1302  */
1303  /*
1304  
1305  
1306  
1307  //<6'>_{n,n,n|n,n,n}
1308  for(Int_t i1=0;i1<nPrim;i1++)
1309  {
1310   aftsTrack=anEvent->GetTrack(i1);
1311   if(!((aftsTrack->Pt()>=0.5&&aftsTrack->Pt()<0.6)&&(aftsTrack->InPOISelection())))continue;//POI condition
1312   phi1=aftsTrack->Phi();
1313   for(Int_t i2=0;i2<nPrim;i2++)
1314   {
1315    if(i2==i1)continue;
1316    aftsTrack=anEvent->GetTrack(i2);
1317    if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1318    phi2=aftsTrack->Phi();
1319    for(Int_t i3=0;i3<nPrim;i3++)
1320    { 
1321     if(i3==i1||i3==i2)continue;
1322     aftsTrack=anEvent->GetTrack(i3);
1323     if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1324     phi3=aftsTrack->Phi();
1325     for(Int_t i4=0;i4<nPrim;i4++)
1326     {
1327      if(i4==i1||i4==i2||i4==i3)continue;
1328      aftsTrack=anEvent->GetTrack(i4);
1329      if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1330      phi4=aftsTrack->Phi();
1331      for(Int_t i5=0;i5<nPrim;i5++)
1332      {
1333       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
1334       aftsTrack=anEvent->GetTrack(i5);
1335       if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1336       phi5=aftsTrack->Phi();    
1337       for(Int_t i6=0;i6<nPrim;i6++)
1338       {
1339        if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
1340        aftsTrack=anEvent->GetTrack(i6);
1341        if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1342        phi6=aftsTrack->Phi();  
1343        //fill the fDirectCorrelations:
1344        //fDirectCorrelations->Fill(60.,cos(n*(phi1+phi2+phi3-phi4-phi5-phi6)),1);//<6'>_{n,n,n|n,n,n}
1345       }//end of for(Int_t i6=0;i6<nPrim;i6++)   
1346      }//end of for(Int_t i5=0;i5<nPrim;i5++)  
1347     }//end of for(Int_t i4=0;i4<nPrim;i4++)
1348    }//end of for(Int_t i3=0;i3<nPrim;i3++)
1349   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
1350  }//end of for(Int_t i1=0;i1<nPrim;i1++)
1351
1352  
1353  */
1354  /* 
1355    
1356      
1357  //<7'>_{2n,n,n|n,n,n,n}
1358  for(Int_t i1=0;i1<nPrim;i1++)
1359  {
1360   aftsTrack=anEvent->GetTrack(i1);
1361   if(!((aftsTrack->Pt()>=0.5&&aftsTrack->Pt()<0.6)&&(aftsTrack->InPOISelection())))continue;//POI condition
1362   phi1=aftsTrack->Phi();
1363   for(Int_t i2=0;i2<nPrim;i2++)
1364   {
1365    if(i2==i1)continue;
1366    aftsTrack=anEvent->GetTrack(i2);
1367    if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1368    phi2=aftsTrack->Phi();
1369    for(Int_t i3=0;i3<nPrim;i3++)
1370    { 
1371     if(i3==i1||i3==i2)continue;
1372     aftsTrack=anEvent->GetTrack(i3);
1373     if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1374     phi3=aftsTrack->Phi();
1375     for(Int_t i4=0;i4<nPrim;i4++)
1376     {
1377      if(i4==i1||i4==i2||i4==i3)continue;
1378      aftsTrack=anEvent->GetTrack(i4);
1379      if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1380      phi4=aftsTrack->Phi();
1381      for(Int_t i5=0;i5<nPrim;i5++)
1382      {
1383       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
1384       aftsTrack=anEvent->GetTrack(i5);
1385       if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1386       phi5=aftsTrack->Phi();    
1387       for(Int_t i6=0;i6<nPrim;i6++)
1388       {
1389        if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
1390        aftsTrack=anEvent->GetTrack(i6);
1391        if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1392        phi6=aftsTrack->Phi();
1393        for(Int_t i7=0;i7<nPrim;i7++)
1394        {
1395         if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
1396         aftsTrack=anEvent->GetTrack(i7);
1397         if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1398         phi7=aftsTrack->Phi();   
1399         //fill the fDirectCorrelations:
1400         //fDirectCorrelations->Fill(65.,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}
1401        }//end of for(Int_t i7=0;i7<nPrim;i7++)  
1402       }//end of for(Int_t i6=0;i6<nPrim;i6++)   
1403      }//end of for(Int_t i5=0;i5<nPrim;i5++)  
1404     }//end of for(Int_t i4=0;i4<nPrim;i4++)
1405    }//end of for(Int_t i3=0;i3<nPrim;i3++)
1406   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
1407  }//end of for(Int_t i1=0;i1<nPrim;i1++)
1408
1409  
1410   
1411  */
1412  /*  
1413     
1414      
1415        
1416  //<8'>_{n,n,n,n|n,n,n,n}
1417  for(Int_t i1=0;i1<nPrim;i1++)
1418  {
1419   aftsTrack=anEvent->GetTrack(i1);
1420   if(!((aftsTrack->Pt()>=0.5&&aftsTrack->Pt()<0.6)&&(aftsTrack->InPOISelection())))continue;//POI condition
1421   phi1=aftsTrack->Phi();
1422   for(Int_t i2=0;i2<nPrim;i2++)
1423   {
1424    if(i2==i1)continue;
1425    aftsTrack=anEvent->GetTrack(i2);
1426    if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1427    phi2=aftsTrack->Phi();
1428    for(Int_t i3=0;i3<nPrim;i3++)
1429    { 
1430     if(i3==i1||i3==i2)continue;
1431     aftsTrack=anEvent->GetTrack(i3);
1432     if(!(aftsTrack->InRPSelection()))continue;//RP condition   
1433     phi3=aftsTrack->Phi();
1434     for(Int_t i4=0;i4<nPrim;i4++)
1435     {
1436      if(i4==i1||i4==i2||i4==i3)continue;
1437      aftsTrack=anEvent->GetTrack(i4);
1438      if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1439      phi4=aftsTrack->Phi();
1440      for(Int_t i5=0;i5<nPrim;i5++)
1441      {
1442       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
1443       aftsTrack=anEvent->GetTrack(i5);
1444       if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1445       phi5=aftsTrack->Phi();    
1446       for(Int_t i6=0;i6<nPrim;i6++)
1447       {
1448        if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
1449        aftsTrack=anEvent->GetTrack(i6);
1450        if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1451        phi6=aftsTrack->Phi();
1452        for(Int_t i7=0;i7<nPrim;i7++)
1453        {
1454         if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
1455         aftsTrack=anEvent->GetTrack(i7);
1456         if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1457         phi7=aftsTrack->Phi();
1458         for(Int_t i8=0;i8<nPrim;i8++)
1459         {
1460          if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
1461          aftsTrack=anEvent->GetTrack(i8);
1462          if(!(aftsTrack->InRPSelection()))continue;//RP condition  
1463          phi8=aftsTrack->Phi();           
1464          //fill the fDirectCorrelations:
1465          //fDirectCorrelations->Fill(70.,cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8)),1);//<8'>_{n,n,n,n|n,n,n,n}
1466         }//end of for(Int_t i8=0;i8<nPrim;i8++) 
1467        }//end of for(Int_t i7=0;i7<nPrim;i7++)  
1468       }//end of for(Int_t i6=0;i6<nPrim;i6++)   
1469      }//end of for(Int_t i5=0;i5<nPrim;i5++)  
1470     }//end of for(Int_t i4=0;i4<nPrim;i4++)
1471    }//end of for(Int_t i3=0;i3<nPrim;i3++)
1472   }//end of for(Int_t i2=0;i2<nPrim;i2++) 
1473  }//end of for(Int_t i1=0;i1<nPrim;i1++)
1474  
1475  
1476  
1477  */ 
1478  
1479  
1480  
1481  
1482 } // end of AliFlowAnalysisWithQCumulants::EvaluateNestedLoopsForDifferentialFlow(AliFlowEventSimple* anEvent)
1483
1484
1485 //================================================================================================================================
1486
1487
1488 void AliFlowAnalysisWithQCumulants::GetOutputHistograms(TList *outputListHistos)
1489 {
1490  // get pointers to all output histograms (called before Finish())
1491  if(outputListHistos)
1492  {      
1493   // 1.) common control histograms and common histograms for final results:
1494   AliFlowCommonHist *commonHist = dynamic_cast<AliFlowCommonHist*>(outputListHistos->FindObject("AliFlowCommonHistQC"));
1495   if(commonHist) this->SetCommonHists(commonHist); 
1496   AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(outputListHistos->FindObject("AliFlowCommonHist2ndOrderQC"));
1497   if(commonHist2nd) this->SetCommonHists2nd(commonHist2nd); 
1498   AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(outputListHistos->FindObject("AliFlowCommonHist4thOrderQC"));
1499   if(commonHist4th) this->SetCommonHists4th(commonHist4th);
1500   AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(outputListHistos->FindObject("AliFlowCommonHist6thOrderQC"));
1501   if(commonHist6th) this->SetCommonHists6th(commonHist6th);
1502   AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(outputListHistos->FindObject("AliFlowCommonHist8thOrderQC"));
1503   if(commonHist8th) this->SetCommonHists8th(commonHist8th);
1504   AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>
1505                                                (outputListHistos->FindObject("AliFlowCommonHistResults2ndOrderQC"));
1506   if(commonHistRes2nd) this->SetCommonHistsResults2nd(commonHistRes2nd); 
1507   AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>
1508                                                (outputListHistos->FindObject("AliFlowCommonHistResults4thOrderQC"));
1509   if(commonHistRes4th) this->SetCommonHistsResults4th(commonHistRes4th);
1510   AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>
1511                                                (outputListHistos->FindObject("AliFlowCommonHistResults6thOrderQC"));
1512   if(commonHistRes6th) this->SetCommonHistsResults6th(commonHistRes6th);
1513   AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>
1514                                                (outputListHistos->FindObject("AliFlowCommonHistResults8thOrderQC"));  
1515   if(commonHistRes8th) this->SetCommonHistsResults8th(commonHistRes8th);
1516  
1517   // 2.) weights: 
1518   TList *weightsList = dynamic_cast<TList*>(outputListHistos->FindObject("Weights"));
1519   if(weightsList) this->SetWeightsList(weightsList);
1520   Bool_t bUsePhiWeights = kFALSE;
1521   Bool_t bUsePtWeights = kFALSE;
1522   Bool_t bUseEtaWeights = kFALSE;
1523   TProfile *useParticleWeights = dynamic_cast<TProfile*>(weightsList->FindObject("fUseParticleWeights"));
1524   if(useParticleWeights)
1525   {
1526    this->SetUseParticleWeights(useParticleWeights);  
1527    bUsePhiWeights = (Int_t)useParticleWeights->GetBinContent(1);
1528    bUsePtWeights = (Int_t)useParticleWeights->GetBinContent(2);
1529    bUseEtaWeights = (Int_t)useParticleWeights->GetBinContent(3);
1530   }
1531   
1532   // 3.) integrated flow:
1533   TList *intFlowList = NULL;
1534   TList *intFlowProfiles = NULL;
1535   TList *intFlowResults = NULL;
1536    
1537   intFlowList = dynamic_cast<TList*>(outputListHistos->FindObject("Integrated Flow"));
1538   if(intFlowList) 
1539   {
1540    intFlowProfiles = dynamic_cast<TList*>(intFlowList->FindObject("Profiles"));
1541    intFlowResults = dynamic_cast<TList*>(intFlowList->FindObject("Results"));
1542   } else
1543     {
1544      cout<<"WARNING: intFlowList is NULL in AFAWQC::GOH() !!!!"<<endl;
1545     }  
1546    
1547   // profiles:   
1548   if(intFlowProfiles)  
1549   {
1550    // average multiplicities:
1551    TProfile *avMultiplicity = dynamic_cast<TProfile*>(intFlowProfiles->FindObject("fAvMultiplicity"));
1552    if(avMultiplicity) 
1553    {
1554     this->SetAvMultiplicity(avMultiplicity);
1555    } else 
1556      {
1557       cout<<"WARNING: avMultiplicity is NULL in AFAWQC::GOH() !!!!"<<endl;
1558      }
1559    
1560    // flags: (to be improved (united with other flags in this method))
1561    TString pWeightsFlag[2] = {"pWeights not used","pWeights used"};
1562    TString eWeightsFlag[2] = {"exact eWeights","non-exact eWeights"};
1563    //TString nuaFlag[2] = {"not corrected","corrected"};
1564    TString sinCosFlag[2] = {"sin","cos"};
1565     
1566    for(Int_t pW=0;pW<1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights);pW++)
1567    {
1568     for(Int_t eW=0;eW<1;eW++)
1569     {
1570      // correlations (profiles):
1571      TProfile *qCorrelations = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("fQCorrelations: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1572      if(qCorrelations) 
1573      {
1574       this->SetQCorrelations(qCorrelations,pW,eW);
1575      } else 
1576        {
1577         cout<<"WARNING: qCorrelations is NULL in AFAWQC::GOH() !!!!"<<endl;
1578         cout<<"pW = "<<pW<<endl;
1579         cout<<"eW = "<<eW<<endl;
1580        } 
1581      // products (profiles):  
1582      TProfile *qProducts = dynamic_cast<TProfile*>(intFlowProfiles->FindObject(Form("fQProducts: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1583      if(qProducts) 
1584      {
1585       this->SetQProducts(qProducts,pW,eW);
1586      } else 
1587        {
1588         cout<<"WARNING: qProducts is NULL in AFAWQC::GOH() !!!!"<<endl;
1589         cout<<"pW = "<<pW<<endl;
1590         cout<<"eW = "<<eW<<endl;
1591        }     
1592      // corrections (profiles):
1593      for(Int_t sc=0;sc<2;sc++)
1594      {
1595       TProfile *qCorrections = dynamic_cast<TProfile*>(intFlowProfiles->FindObject((Form("fQCorrections: %s, %s, %s terms",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),sinCosFlag[sc].Data()))));
1596       if(qCorrections) 
1597       {
1598        this->SetQCorrections(qCorrections,pW,eW,sc);
1599       } else 
1600         {
1601          cout<<"WARNING: qCorrections is NULL in AFAWQC::GOH() !!!!"<<endl;
1602          cout<<"pW = "<<pW<<endl;
1603          cout<<"eW = "<<eW<<endl;
1604          cout<<"sc = "<<sc<<endl;
1605         } 
1606      } // end of for(Int_t sc=0;sc<2;sc++)           
1607     } // end of for(Int_t eW=0;eW<1;eW++)
1608    } // end of for(Int_t pW=0;pW<1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights);pW++)
1609   } else // to if(intFlowProfiles)  
1610     {
1611      cout<<"WARNING: intFlowProfiles is NULL in AFAWQC::GOH() !!!!"<<endl;
1612     }
1613    
1614   // results:   
1615   if(intFlowResults)  
1616   {
1617    for(Int_t pW=0;pW<1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights);pW++)
1618    {
1619     for(Int_t eW=0;eW<2;eW++)
1620     {
1621      // flags: (to be improved (united with other flags in this method))
1622      TString pWeightsFlag[2] = {"pWeights not used","pWeights used"};
1623      TString eWeightsFlag[2] = {"exact eWeights","non-exact eWeights"};
1624      TString nuaFlag[2] = {"not corrected","corrected"};
1625      TString powerFlag[2] = {"linear","quadratic"};
1626      //TString sinCosFlag[2] = {"sin","cos"};     
1627      // correlations (results):
1628      TH1D *correlations = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("fCorrelations: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1629      if(correlations) 
1630      {
1631       this->SetCorrelations(correlations,pW,eW);
1632      } else 
1633        {
1634         cout<<"WARNING: correlations is NULL in AFAWQC::GOH() !!!!"<<endl;
1635         cout<<"pW = "<<pW<<endl;
1636         cout<<"eW = "<<eW<<endl;
1637        }     
1638      // corrections (results):
1639      TH1D *corrections = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("fCorrections: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1640      if(corrections) 
1641      {
1642       this->SetCorrections(corrections,pW,eW);
1643      } else 
1644        {
1645         cout<<"WARNING: corrections is NULL in AFAWQC::GOH() !!!!"<<endl;
1646         cout<<"pW = "<<pW<<endl;
1647         cout<<"eW = "<<eW<<endl;
1648        }
1649      // covariances (results):
1650      TH1D *covariances = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("fCovariances: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1651      if(covariances) 
1652      {
1653       this->SetCovariances(covariances,pW,eW);
1654      } else 
1655        {
1656         cout<<"WARNING: covariances is NULL in AFAWQC::GOH() !!!!"<<endl;
1657         cout<<"pW = "<<pW<<endl;
1658         cout<<"eW = "<<eW<<endl;
1659        } 
1660      // sum of linear and quadratic event weights (results):
1661      for(Int_t power=0;power<2;power++)
1662      {
1663       TH1D *sumOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("fSumOfEventWeights: %s, %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),powerFlag[power].Data())));
1664       if(sumOfEventWeights) 
1665       {
1666        this->SetSumOfEventWeights(sumOfEventWeights,pW,eW,power);
1667       } else 
1668         {
1669          cout<<"WARNING: sumOfEventWeights is NULL in AFAWQC::GOH() !!!!"<<endl;
1670          cout<<"pW    = "<<pW<<endl;
1671          cout<<"eW    = "<<eW<<endl;
1672          cout<<"power = "<<power<<endl;
1673         }                                   
1674      } // end of for(Int_t power=0;power<2;power++)                                                                  
1675      // products of event weights (results):
1676      TH1D *productOfEventWeights = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("fProductOfEventWeights: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1677      if(productOfEventWeights) 
1678      {
1679       this->SetProductOfEventWeights(productOfEventWeights,pW,eW);
1680      } else 
1681        {
1682         cout<<"WARNING: productOfEventWeights is NULL in AFAWQC::GOH() !!!!"<<endl;
1683         cout<<"pW = "<<pW<<endl;
1684         cout<<"eW = "<<eW<<endl;
1685        } 
1686        
1687      for(Int_t nua=0;nua<2;nua++)
1688      {
1689       // integrated Q-cumulants:
1690       TH1D *cumulants = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("fCumulants: %s, %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())));
1691       if(cumulants) 
1692       {
1693        this->SetCumulants(cumulants,pW,eW,nua);
1694       } else 
1695         {
1696          cout<<"WARNING: cumulants is NULL in AFAWQC::GOH() !!!!"<<endl;
1697          cout<<"pW = "<<pW<<endl;
1698          cout<<"eW = "<<eW<<endl;
1699          cout<<"nua = "<<nua<<endl;
1700         }  
1701       // integrated flow estimates from Q-cumulants:
1702       TH1D *intFlow = dynamic_cast<TH1D*>(intFlowResults->FindObject(Form("fIntFlow: %s, %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())));
1703       if(intFlow) 
1704       {
1705        this->SetIntFlow(intFlow,pW,eW,nua);
1706       } else 
1707         {
1708          cout<<"WARNING: intFlow is NULL in AFAWQC::GOH() !!!!"<<endl;
1709          cout<<"pW = "<<pW<<endl;
1710          cout<<"eW = "<<eW<<endl;
1711          cout<<"nua = "<<nua<<endl;
1712         }   
1713      } // end of for(Int_t nua=0;nua<2;nua++)  
1714     } // end of for(Int_t eW=0;eW<1;eW++) 
1715    } // end of for(Int_t pW=0;pW<1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights);pW++)  
1716   } else // to if(intFlowResults)
1717     {
1718      cout<<"WARNING: intFlowResults is NULL in AFAWQC::GOH() !!!!"<<endl;
1719     }
1720           
1721   // differential flow:
1722   TString typeFlag[2] = {"RP","POI"}; 
1723   TString pWeightsFlag[2] = {"not used","used"};
1724   TString eWeightsFlag[2] = {"exact","non-exact"}; 
1725   TString sinCosFlag[2] = {"sin","cos"};
1726   TString nuaFlag[2] = {"not corrected","corrected"}; // nua = non-uniform acceptance
1727   TString ptEtaFlag[2] = {"p_{t}","#eta"};
1728   // base list fDiffFlowList "Differential Flow":
1729   TList *diffFlowList = NULL;
1730   diffFlowList = dynamic_cast<TList*>(outputListHistos->FindObject("Differential Flow"));  
1731   // list holding nested lists containing profiles:
1732   TList *diffFlowListProfiles = NULL;
1733   // list holding nested lists containing 2D and 1D histograms with final results:
1734   TList *diffFlowListResults = NULL;
1735   if(diffFlowList)
1736   {  
1737    diffFlowListProfiles = dynamic_cast<TList*>(diffFlowList->FindObject("Profiles"));
1738    diffFlowListResults = dynamic_cast<TList*>(diffFlowList->FindObject("Results"));
1739   } else
1740     {
1741      cout<<"WARNING: diffFlowList is NULL in AFAWQC::GOH() !!!!"<<endl;
1742     }      
1743   
1744   // nested list in the list of profiles fDiffFlowListProfiles "Profiles":
1745   TList *dfpType[2] = {NULL};
1746   TList *dfpParticleWeights[2][2] = {{NULL}};
1747   TList *dfpEventWeights[2][2][2] = {{{NULL}}};
1748   TList *diffFlowCorrelations[2][2][2] = {{{NULL}}};
1749   TList *diffFlowProductsOfCorrelations[2][2][2] = {{{NULL}}};
1750   TList *diffFlowCorrectionTerms[2][2][2][2] = {{{{NULL}}}};
1751   
1752   if(diffFlowListProfiles)
1753   {
1754    for(Int_t t=0;t<2;t++)
1755    {
1756     dfpType[t] = dynamic_cast<TList*>(diffFlowListProfiles->FindObject(typeFlag[t].Data()));
1757     if(dfpType[t])
1758     {
1759      for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++)
1760      {
1761       dfpParticleWeights[t][pW] = dynamic_cast<TList*>(dfpType[t]->FindObject(Form("%s, pWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data())));
1762       if(dfpParticleWeights[t][pW])
1763       {
1764        for(Int_t eW=0;eW<2;eW++)
1765        {
1766         dfpEventWeights[t][pW][eW] = dynamic_cast<TList*>(dfpParticleWeights[t][pW]->FindObject(Form("%s, pWeights %s, eWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1767         if(dfpEventWeights[t][pW][eW])
1768         {
1769          // correlations: 
1770          diffFlowCorrelations[t][pW][eW] = dynamic_cast<TList*>(dfpEventWeights[t][pW][eW]->FindObject(Form("Correlations (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1771          // products of correlations:
1772          diffFlowProductsOfCorrelations[t][pW][eW] = dynamic_cast<TList*>(dfpEventWeights[t][pW][eW]->FindObject(Form("Products of correlations (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1773          // correction terms:
1774          for(Int_t sc=0;sc<2;sc++)
1775          {
1776           diffFlowCorrectionTerms[t][pW][eW][sc] = dynamic_cast<TList*>(dfpEventWeights[t][pW][eW]->FindObject(Form("Corrections for NUA (%s, pWeights %s, eWeights %s, %s terms)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),sinCosFlag[sc].Data())));
1777           //this->SetDiffFlowCorrectionTerms(diffFlowCorrectionTerms[t][pW][sc],t,pW,sc);   
1778          }
1779         } else // to if(dfpEventWeights[t][pW][eW])
1780           {
1781            cout<<"WARNING: dfpEventWeights[t][pW][eW] is NULL in AFAWQC::GOH() !!!!"<<endl;
1782            cout<<"t = "<<t<<endl;
1783            cout<<"pW = "<<pW<<endl;
1784            cout<<"eW = "<<eW<<endl;
1785           }
1786        } // end of for(Int_t eW=0;eW<2;eW++)   
1787       } else // to if(dfpParticleWeights[t][pW])
1788         {
1789          cout<<"WARNING: dfpParticleWeights[t][pW] is NULL in AFAWQC::GOH() !!!!"<<endl;
1790          cout<<"t = "<<t<<endl;
1791          cout<<"pW = "<<pW<<endl;
1792         }
1793      } // end of for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++) 
1794      } else // if(dfpType[t]) 
1795       {
1796        cout<<"WARNING: dfpType[t] is NULL in AFAWQC::GOH() !!!!"<<endl;
1797        cout<<"t = "<<t<<endl;
1798       }
1799    } // end of for(Int_t t=0;t<2;t++)
1800   } else // to if(diffFlowListProfiles)
1801     {
1802      cout<<"WARNING: diffFlowListProfiles is NULL in AFAWQC::GOH() !!!!"<<endl;
1803     }  
1804   
1805   TProfile2D *correlationsPro[2][2][2][4] = {{{{NULL}}}};
1806   TProfile2D *productsOfCorrelationsPro[2][2][2][5] = {{{{NULL}}}};
1807   TProfile2D *correctionTermsPro[2][2][2][2][2] = {{{{{NULL}}}}};
1808   
1809   TString correlationName[4] = {"<2'>","<4'>","<6'>","<8'>"};
1810   TString cumulantName[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};
1811   TString productOfCorrelationsName[5] = {"<2><2'>","<2><4'>","<4><2'>","<4><4'>","<2'><4'>"};
1812   TString correctionsSinTermsName[2] = {"sin(1)","sin(2)"};
1813   TString correctionsCosTermsName[2] = {"cos(1)","cos(2)"};
1814   TString correctionName[4] = {"corr. to QC{2'}","corr. to QC{4'}","corr. to QC{6'}","corr. to QC{8'}"};
1815   TString covarianceName[4] = {"Cov(2,2')","Cov(2,4')","Cov(2',4')","Cov(4,2')"}; // to be improved (reorganized)
1816   TString flowName[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"}; 
1817   
1818   for(Int_t t=0;t<2;t++)
1819   {
1820    for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++)
1821    {
1822     for(Int_t eW=0;eW<2;eW++)
1823     {
1824      // correlations:
1825      if(diffFlowCorrelations[t][pW][eW])
1826      {
1827       for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
1828       {
1829        correlationsPro[t][pW][eW][correlationIndex] = dynamic_cast<TProfile2D*>(diffFlowCorrelations[t][pW][eW]->FindObject(correlationName[correlationIndex].Data()));
1830        if(correlationsPro[t][pW][eW][correlationIndex])
1831        {
1832         this->SetCorrelationsPro(correlationsPro[t][pW][eW][correlationIndex],t,pW,eW,correlationIndex);
1833        } else // to if(correlationsPro[t][pW][ew][correlationIndex])
1834          {
1835           cout<<"WARNING: correlationsPro[t][pW][eW][correlationIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
1836           cout<<"t = "<<t<<endl;
1837           cout<<"pW = "<<pW<<endl;
1838           cout<<"eW = "<<eW<<endl;
1839           cout<<"ci = "<<correlationIndex<<endl;
1840          } 
1841       }
1842      } else // to if(diffFlowCorrelations[t][pW][eW])
1843        {
1844         cout<<"WARNING: diffFlowCorrelations[t][pW][eW] is NULL in AFAWQC::GOH() !!!!"<<endl;
1845         cout<<"t = "<<t<<endl;
1846         cout<<"pW = "<<pW<<endl;
1847         cout<<"eW = "<<eW<<endl;
1848        } 
1849      // products of correlations:
1850      if(diffFlowProductsOfCorrelations[t][pW][eW])
1851      {
1852       for(Int_t productOfCorrelationsIndex=0;productOfCorrelationsIndex<5;productOfCorrelationsIndex++)
1853       {
1854        productsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] = dynamic_cast<TProfile2D*>(diffFlowProductsOfCorrelations[t][pW][eW]->FindObject(productOfCorrelationsName[productOfCorrelationsIndex].Data()));
1855        if(productsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex])
1856        {
1857         this->SetProductsOfCorrelationsPro(productsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex],t,pW,eW,productOfCorrelationsIndex);
1858        } else // to if(productsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex])
1859          {
1860           cout<<"WARNING: productsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
1861           cout<<"t = "<<t<<endl;
1862           cout<<"pW = "<<pW<<endl;
1863           cout<<"eW = "<<eW<<endl;
1864           cout<<"ci = "<<productOfCorrelationsIndex<<endl;
1865          } 
1866       }
1867      } else // to if(diffFlowProductsOfCorrelations[t][pW][eW])
1868        {
1869         cout<<"WARNING: diffFlowProductsOfCorrelations[t][pW][eW] is NULL in AFAWQC::GOH() !!!!"<<endl;
1870         cout<<"t = "<<t<<endl;
1871         cout<<"pW = "<<pW<<endl;
1872         cout<<"eW = "<<eW<<endl;
1873        }
1874      // correction terms:
1875      for(Int_t sc=0;sc<2;sc++)
1876      {
1877       if(diffFlowCorrectionTerms[t][pW][eW][sc])
1878       {
1879        for(Int_t correctionIndex=0;correctionIndex<2;correctionIndex++)
1880        {
1881         if(sc==0)
1882         {
1883          correctionTermsPro[t][pW][eW][sc][correctionIndex] = dynamic_cast<TProfile2D*>(diffFlowCorrectionTerms[t][pW][eW][sc]->FindObject(correctionsSinTermsName[correctionIndex].Data())); 
1884          if(correctionTermsPro[t][pW][eW][sc][correctionIndex])
1885          {
1886           this->SetCorrectionTermsPro(correctionTermsPro[t][pW][eW][sc][correctionIndex],t,pW,eW,sc,correctionIndex);
1887          } else 
1888            {
1889             cout<<"WARNING: correctionTermsPro[t][pW][eW][sc][correctionIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
1890             cout<<"t = "<<t<<endl;
1891             cout<<"pW = "<<pW<<endl;
1892             cout<<"eW = "<<eW<<endl;
1893             cout<<"sc = "<<sc<<endl;
1894             cout<<"ci = "<<correctionIndex<<endl;
1895            }
1896         } 
1897         if(sc==1)
1898         {
1899          correctionTermsPro[t][pW][eW][sc][correctionIndex] = dynamic_cast<TProfile2D*>(diffFlowCorrectionTerms[t][pW][eW][sc]->FindObject(correctionsCosTermsName[correctionIndex].Data())); 
1900          if(correctionTermsPro[t][pW][eW][sc][correctionIndex])
1901          {
1902           this->SetCorrectionTermsPro(correctionTermsPro[t][pW][eW][sc][correctionIndex],t,pW,eW,sc,correctionIndex);
1903          } else 
1904            {
1905             cout<<"WARNING: correctionTermsPro[t][pW][eW][sc][correctionIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
1906             cout<<"t = "<<t<<endl;
1907             cout<<"pW = "<<pW<<endl;
1908             cout<<"eW = "<<eW<<endl;
1909             cout<<"sc = "<<sc<<endl;
1910             cout<<"ci = "<<correctionIndex<<endl;
1911            }         
1912         }  
1913        } // end of for(Int_t correctionIndex=0;correctionIndex<2;correctionIndex++)
1914       } else // to if(diffFlowCorrectionTerms[t][pW][eW][sc])
1915         {
1916          cout<<"WARNING: diffFlowCorrectionTerms[t][pW][eW][sc] is NULL in AFAWQC::GOH() !!!!"<<endl;
1917          cout<<"t = "<<t<<endl;
1918          cout<<"pW = "<<pW<<endl;
1919          cout<<"eW = "<<eW<<endl;
1920          cout<<"sc = "<<sc<<endl;
1921         }
1922      } // end of for(Int_t sc=0;sc<2;sc++)  
1923     } // end of for(Int_t eW=0;eW<2;eW++)
1924    }  // end of for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++)
1925   } // end of for(Int_t t=0;t<2;t++)
1926   
1927   // nested list in the list of results fDiffFlowListResults "Results":
1928   TList *dfrType[2] = {NULL};
1929   TList *dfrParticleWeights[2][2] = {{NULL}};
1930   TList *dfrEventWeights[2][2][2] = {{{NULL}}};
1931   TList *dfrCorrections[2][2][2][2] = {{{{NULL}}}}; 
1932   TList *diffFlowFinalCorrelations[2][2][2] = {{{NULL}}}; 
1933   TList *diffFlowFinalCorrections[2][2][2] = {{{NULL}}}; 
1934   TList *diffFlowFinalCovariances[2][2][2] = {{{NULL}}};   
1935   TList *diffFlowFinalCumulants[2][2][2][2] = {{{{NULL}}}};  
1936   TList *diffFlowFinalFlow[2][2][2][2] = {{{{NULL}}}}; 
1937  
1938   if(diffFlowListResults)
1939   {
1940    for(Int_t t=0;t<2;t++)
1941    {
1942     dfrType[t] = dynamic_cast<TList*>(diffFlowListResults->FindObject(typeFlag[t].Data()));
1943     if(dfrType[t])
1944     {
1945      for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++)
1946      {
1947       dfrParticleWeights[t][pW] = dynamic_cast<TList*>(dfrType[t]->FindObject(Form("%s, pWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data())));
1948       if(dfrParticleWeights[t][pW])
1949       {
1950        for(Int_t eW=0;eW<2;eW++)
1951        {
1952         dfrEventWeights[t][pW][eW] = dynamic_cast<TList*>(dfrParticleWeights[t][pW]->FindObject(Form("%s, pWeights %s, eWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1953         if(dfrEventWeights[t][pW][eW])
1954         {
1955          diffFlowFinalCorrelations[t][pW][eW] = dynamic_cast<TList*>(dfrEventWeights[t][pW][eW]->FindObject(Form("Correlations (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1956          diffFlowFinalCorrections[t][pW][eW] = dynamic_cast<TList*>(dfrEventWeights[t][pW][eW]->FindObject(Form("Corrections (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));
1957          diffFlowFinalCovariances[t][pW][eW] = dynamic_cast<TList*>(dfrEventWeights[t][pW][eW]->FindObject(Form("Covariances (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())));      
1958          for(Int_t nua=0;nua<2;nua++)
1959          {
1960           dfrCorrections[t][pW][eW][nua] = dynamic_cast<TList*>(dfrEventWeights[t][pW][eW]->FindObject(Form("%s, pWeights %s, eWeights %s, %s for NUA",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())));
1961           if(dfrCorrections[t][pW][eW][nua])
1962           {
1963            diffFlowFinalCumulants[t][pW][eW][nua] = dynamic_cast<TList*>(dfrCorrections[t][pW][eW][nua]->FindObject(Form("Cumulants (%s, pWeights %s, eWeights %s, %s for NUA)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())));
1964            diffFlowFinalFlow[t][pW][eW][nua] = dynamic_cast<TList*>(dfrCorrections[t][pW][eW][nua]->FindObject(Form("Differential Flow (%s, pWeights %s, eWeights %s, %s for NUA)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())));
1965           } else // to if(dfrCorrections[t][pW][eW][nua])
1966             {
1967              cout<<"WARNING: dfrCorrections[t][pW][eW][nua] is NULL in AFAWQC::GOH() !!!!"<<endl;
1968              cout<<"t = "<<t<<endl;
1969              cout<<"pW = "<<pW<<endl;
1970              cout<<"eW = "<<eW<<endl;
1971              cout<<"nua = "<<nua<<endl;
1972             }
1973          } // end of for(Int_t nua=0;nua<2;nua++)
1974         } else // to if(dfrEventWeights[t][pW][eW])
1975           {
1976            cout<<"WARNING: dfrEventWeights[t][pW][eW] is NULL in AFAWQC::GOH() !!!!"<<endl;
1977            cout<<"t = "<<t<<endl;
1978            cout<<"pW = "<<pW<<endl;
1979            cout<<"eW = "<<eW<<endl;
1980           }
1981        } // end of for(Int_t eW=0;eW<2;eW++)
1982       } else // to if(dfrParticleWeights[t][pW])
1983         {
1984          cout<<"WARNING: dfrParticleWeights[t][pW] is NULL in AFAWQC::GOH() !!!!"<<endl;
1985          cout<<"t = "<<t<<endl;
1986          cout<<"pW = "<<pW<<endl;
1987         }
1988      } // end of for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++)
1989     } else // to if(dfrType[t])
1990       {
1991        cout<<"WARNING: dfrType[t] is NULL in AFAWQC::GOH() !!!!"<<endl;
1992        cout<<"t = "<<t<<endl;
1993       }
1994    } // end of for(Int_t t=0;t<2;t++)
1995   } else // to if(diffFlowListResults)
1996     {
1997      cout<<"WARNING: diffFlowListResults is NULL in AFAWQC::GOH() !!!!"<<endl;
1998     }
1999  
2000  TH2D *finalCorrelations2D[2][2][2][4] = {{{{NULL}}}};
2001  TH1D *finalCorrelations1D[2][2][2][2][4] = {{{{{NULL}}}}}; 
2002  TH2D *finalCumulants2D[2][2][2][2][4] = {{{{{NULL}}}}};
2003  TH1D *finalCumulantsPt[2][2][2][2][4] = {{{{{NULL}}}}}; 
2004  TH1D *finalCumulantsEta[2][2][2][2][4] = {{{{{NULL}}}}}; 
2005  TH2D *finalCorrections2D[2][2][2][4] = {{{{NULL}}}};
2006  TH1D *finalCorrections1D[2][2][2][2][4] = {{{{{NULL}}}}}; 
2007  TH2D *finalCovariances2D[2][2][2][4] = {{{{NULL}}}};
2008  TH1D *finalCovariances1D[2][2][2][2][4] = {{{{{NULL}}}}}; 
2009  TH2D *finalFlow2D[2][2][2][2][4] = {{{{{NULL}}}}};
2010  TH1D *finalFlowPt[2][2][2][2][4] = {{{{{NULL}}}}}; 
2011  TH1D *finalFlowEta[2][2][2][2][4] = {{{{{NULL}}}}}; 
2012  TH2D *nonEmptyBins2D[2] = {NULL};
2013  TH1D *nonEmptyBins1D[2][2] = {{NULL}};
2014  
2015  for(Int_t t=0;t<2;t++)
2016  {
2017   // 2D:
2018   nonEmptyBins2D[t] = dynamic_cast<TH2D*>(dfrType[t]->FindObject(Form("%s, (p_{t},#eta)",typeFlag[t].Data())));
2019   if(nonEmptyBins2D[t])
2020   {
2021    this->SetNonEmptyBins2D(nonEmptyBins2D[t],t);
2022   } else
2023     { 
2024      cout<<"WARNING: nonEmptyBins2D[t] is NULL in AFAWQC::GOH() !!!!"<<endl;
2025      cout<<"t = "<<t<<endl;
2026     }
2027   // 1D:
2028   for(Int_t pe=0;pe<2;pe++)
2029   {
2030    nonEmptyBins1D[t][pe] = dynamic_cast<TH1D*>(dfrType[t]->FindObject(Form("%s, %s",typeFlag[t].Data(),ptEtaFlag[pe].Data())));
2031    if(nonEmptyBins1D[t][pe])
2032    {
2033     this->SetNonEmptyBins1D(nonEmptyBins1D[t][pe],t,pe);
2034    } else
2035      { 
2036       cout<<"WARNING: nonEmptyBins1D[t][pe] is NULL in AFAWQC::GOH() !!!!"<<endl;
2037       cout<<"t = "<<t<<endl;
2038       cout<<"pe = "<<pe<<endl;
2039      }
2040   }  
2041   
2042   for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++)
2043   {
2044    for(Int_t eW=0;eW<2;eW++)
2045    {
2046     // correlations:
2047     if(diffFlowFinalCorrelations[t][pW][eW])
2048     {
2049      for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
2050      {
2051       // 2D:
2052       finalCorrelations2D[t][pW][eW][correlationIndex] = dynamic_cast<TH2D*>(diffFlowFinalCorrelations[t][pW][eW]->FindObject(Form("%s, (p_{t},#eta)",correlationName[correlationIndex].Data())));
2053       if(finalCorrelations2D[t][pW][eW][correlationIndex])
2054       {
2055        this->SetFinalCorrelations2D(finalCorrelations2D[t][pW][eW][correlationIndex],t,pW,eW,correlationIndex);
2056       } else
2057         {
2058          cout<<"WARNING: finalCorrelations2D[t][pW][eW][correlationIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2059          cout<<"t = "<<t<<endl;
2060          cout<<"pW = "<<pW<<endl;
2061          cout<<"eW = "<<eW<<endl;
2062          cout<<"ci = "<<correlationIndex<<endl;
2063         }
2064        // 1D
2065        for(Int_t pe=0;pe<2;pe++)
2066        {
2067         if(pe==0)
2068         {
2069          finalCorrelations1D[t][pW][eW][pe][correlationIndex] = dynamic_cast<TH1D*>(diffFlowFinalCorrelations[t][pW][eW]->FindObject(Form("%s, (p_{t})",correlationName[correlationIndex].Data())));
2070         }
2071         if(pe==1)
2072         {
2073          finalCorrelations1D[t][pW][eW][pe][correlationIndex] = dynamic_cast<TH1D*>(diffFlowFinalCorrelations[t][pW][eW]->FindObject(Form("%s, (#eta)",correlationName[correlationIndex].Data())));
2074         }          
2075         if(finalCorrelations1D[t][pW][eW][pe][correlationIndex])
2076         {
2077          this->SetFinalCorrelations1D(finalCorrelations1D[t][pW][eW][pe][correlationIndex],t,pW,eW,pe,correlationIndex);
2078         } else
2079           {
2080            cout<<"WARNING: finalCorrelations1D[t][pW][eW][pe][correlationIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2081            cout<<"t = "<<t<<endl;
2082            cout<<"pW = "<<pW<<endl;
2083            cout<<"eW = "<<eW<<endl;
2084            cout<<"pe = "<<pe<<endl;
2085            cout<<"ci = "<<correlationIndex<<endl;
2086           }   
2087        } // end of for(Int_t pe=0;pe<2;pe++)  
2088      } // end of for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
2089     } else // to if(diffFlowFinalCorrelations[t][pW][eW])
2090       { 
2091        cout<<"WARNING: diffFlowFinalCorrelations[t][pW] is NULL in AFAWQC::GOH() !!!!"<<endl;
2092        cout<<"t = "<<t<<endl;
2093        cout<<"pW = "<<pW<<endl;
2094        cout<<"eW = "<<eW<<endl;
2095       }
2096     // corrections:
2097     if(diffFlowFinalCorrections[t][pW][eW])
2098     {
2099      for(Int_t correctionIndex=0;correctionIndex<4;correctionIndex++)
2100      {
2101       // 2D:
2102       finalCorrections2D[t][pW][eW][correctionIndex] = dynamic_cast<TH2D*>(diffFlowFinalCorrections[t][pW][eW]->FindObject(Form("%s, (p_{t},#eta)",correctionName[correctionIndex].Data())));
2103       if(finalCorrections2D[t][pW][eW][correctionIndex])
2104       {
2105        this->SetFinalCorrections2D(finalCorrections2D[t][pW][eW][correctionIndex],t,pW,eW,correctionIndex);
2106       } else
2107         {
2108          cout<<"WARNING: finalCorrections2D[t][pW][eW][correctionIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2109          cout<<"t = "<<t<<endl;
2110          cout<<"pW = "<<pW<<endl;
2111          cout<<"eW = "<<eW<<endl;
2112          cout<<"ci = "<<correctionIndex<<endl;
2113         }
2114       // 1D
2115       for(Int_t pe=0;pe<2;pe++)
2116       {
2117        if(pe==0)
2118        {
2119         finalCorrections1D[t][pW][eW][pe][correctionIndex] = dynamic_cast<TH1D*>(diffFlowFinalCorrections[t][pW][eW]->FindObject(Form("%s, (p_{t})",correctionName[correctionIndex].Data())));
2120        }
2121        if(pe==1)
2122        {
2123         finalCorrections1D[t][pW][eW][pe][correctionIndex] = dynamic_cast<TH1D*>(diffFlowFinalCorrections[t][pW][eW]->FindObject(Form("%s, (#eta)",correctionName[correctionIndex].Data())));
2124        }          
2125        if(finalCorrections1D[t][pW][eW][pe][correctionIndex])
2126        {
2127         this->SetFinalCorrections1D(finalCorrections1D[t][pW][eW][pe][correctionIndex],t,pW,eW,pe,correctionIndex);
2128        } else
2129          {
2130           cout<<"WARNING: finalCorrections1D[t][pW][eW][pe][correctionIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2131           cout<<"t = "<<t<<endl;
2132           cout<<"pW = "<<pW<<endl;
2133           cout<<"eW = "<<eW<<endl;
2134           cout<<"pe = "<<pe<<endl;
2135           cout<<"ci = "<<correctionIndex<<endl;
2136          }   
2137       } // end of for(Int_t pe=0;pe<2;pe++)  
2138      } // end of for(Int_t correctionIndex=0;correctionIndex<4;correctionIndex++)
2139     } else // to if(diffFlowFinalCorrections[t][pW][eW])
2140       { 
2141        cout<<"WARNING: diffFlowFinalCorrections[t][pW][eW] is NULL in AFAWQC::GOH() !!!!"<<endl;
2142        cout<<"t = "<<t<<endl;
2143        cout<<"pW = "<<pW<<endl;
2144        cout<<"eW = "<<eW<<endl;
2145       }     
2146     // covariances:
2147     if(diffFlowFinalCovariances[t][pW][eW])
2148     {
2149      for(Int_t covarianceIndex=0;covarianceIndex<4;covarianceIndex++)
2150      {
2151       // 2D:
2152       finalCovariances2D[t][pW][eW][covarianceIndex] = dynamic_cast<TH2D*>(diffFlowFinalCovariances[t][pW][eW]->FindObject(Form("%s, (p_{t},#eta)",covarianceName[covarianceIndex].Data())));
2153       if(finalCovariances2D[t][pW][eW][covarianceIndex])
2154       {
2155        this->SetFinalCovariances2D(finalCovariances2D[t][pW][eW][covarianceIndex],t,pW,eW,covarianceIndex);
2156       } else
2157         {
2158          cout<<"WARNING: finalCovariances2D[t][pW][eW][nua][covarianceIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2159          cout<<"t = "<<t<<endl;
2160          cout<<"pW = "<<pW<<endl;
2161          cout<<"eW = "<<eW<<endl;
2162          cout<<"ci = "<<covarianceIndex<<endl;
2163         }
2164       // 1D:
2165       for(Int_t pe=0;pe<2;pe++)
2166       {
2167        if(pe==0)
2168        {
2169         finalCovariances1D[t][pW][eW][pe][covarianceIndex] = dynamic_cast<TH1D*>(diffFlowFinalCovariances[t][pW][eW]->FindObject(Form("%s, (p_{t})",covarianceName[covarianceIndex].Data())));
2170        }
2171        if(pe==1)
2172        {
2173         finalCovariances1D[t][pW][eW][pe][covarianceIndex] = dynamic_cast<TH1D*>(diffFlowFinalCovariances[t][pW][eW]->FindObject(Form("%s, (#eta)",covarianceName[covarianceIndex].Data())));
2174        }          
2175        if(finalCovariances1D[t][pW][eW][pe][covarianceIndex])
2176        {
2177         this->SetFinalCovariances1D(finalCovariances1D[t][pW][eW][pe][covarianceIndex],t,pW,eW,pe,covarianceIndex);
2178        } else
2179          {
2180           cout<<"WARNING: finalCovariances1D[t][pW][eW][pe][covarianceIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2181           cout<<"t = "<<t<<endl;
2182           cout<<"pW = "<<pW<<endl;
2183           cout<<"eW = "<<eW<<endl;
2184           cout<<"pe = "<<pe<<endl;
2185           cout<<"ci = "<<covarianceIndex<<endl;
2186          }   
2187       } // end of for(Int_t pe=0;pe<2;pe++)  
2188      } // end of for(Int_t covarianceIndex=0;covarianceIndex<4;covarianceIndex++)
2189     } else // to if(diffFlowFinalCovariances[t][pW][eW])
2190       { 
2191        cout<<"WARNING: diffFlowFinalCovariances[t][pW][eW] is NULL in AFAWQC::GOH() !!!!"<<endl;
2192        cout<<"t = "<<t<<endl;
2193        cout<<"pW = "<<pW<<endl;
2194        cout<<"eW = "<<eW<<endl;
2195       }        
2196        
2197     for(Int_t nua=0;nua<2;nua++)
2198     {  
2199      // cumulants:
2200      if(diffFlowFinalCumulants[t][pW][eW][nua])
2201      {
2202       for(Int_t cumulantIndex=0;cumulantIndex<4;cumulantIndex++)
2203       {
2204        // 2D:
2205        finalCumulants2D[t][pW][eW][nua][cumulantIndex] = dynamic_cast<TH2D*>(diffFlowFinalCumulants[t][pW][eW][nua]->FindObject(Form("%s, (p_{t},#eta)",cumulantName[cumulantIndex].Data())));
2206        if(finalCumulants2D[t][pW][eW][nua][cumulantIndex])
2207        {
2208         this->SetFinalCumulants2D(finalCumulants2D[t][pW][eW][nua][cumulantIndex],t,pW,eW,nua,cumulantIndex);
2209        } else
2210          {
2211           cout<<"WARNING: finalCumulants2D[t][pW][eW][nua][cumulantIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2212           cout<<"t = "<<t<<endl;
2213           cout<<"pW = "<<pW<<endl;
2214           cout<<"eW = "<<eW<<endl;
2215           cout<<"nua = "<<nua<<endl;
2216           cout<<"ci = "<<cumulantIndex<<endl;
2217          }
2218        // pt:  
2219        finalCumulantsPt[t][pW][eW][nua][cumulantIndex] = dynamic_cast<TH1D*>(diffFlowFinalCumulants[t][pW][eW][nua]->FindObject(Form("%s, (p_{t})",cumulantName[cumulantIndex].Data())));
2220        if(finalCumulantsPt[t][pW][eW][nua][cumulantIndex])
2221        {
2222         this->SetFinalCumulantsPt(finalCumulantsPt[t][pW][eW][nua][cumulantIndex],t,pW,eW,nua,cumulantIndex);
2223        } else
2224          {
2225           cout<<"WARNING: finalCumulantsPt[t][pW][eW][nua][cumulantIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2226           cout<<"t = "<<t<<endl;
2227           cout<<"pW = "<<pW<<endl;
2228           cout<<"eW = "<<eW<<endl;
2229           cout<<"nua = "<<nua<<endl;
2230           cout<<"ci = "<<cumulantIndex<<endl;
2231          } 
2232        // eta:
2233        finalCumulantsEta[t][pW][eW][nua][cumulantIndex] = dynamic_cast<TH1D*>(diffFlowFinalCumulants[t][pW][eW][nua]->FindObject(Form("%s, (#eta)",cumulantName[cumulantIndex].Data())));
2234        if(finalCumulantsEta[t][pW][eW][nua][cumulantIndex])
2235        {
2236         this->SetFinalCumulantsEta(finalCumulantsEta[t][pW][eW][nua][cumulantIndex],t,pW,eW,nua,cumulantIndex);
2237        } else
2238          {
2239           cout<<"WARNING: finalCumulantsEta[t][pW][eW][nua][cumulantIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2240           cout<<"t = "<<t<<endl;
2241           cout<<"pW = "<<pW<<endl;
2242           cout<<"eW = "<<eW<<endl;
2243           cout<<"nua = "<<nua<<endl;
2244           cout<<"ci = "<<cumulantIndex<<endl;
2245          }   
2246       } // end of for(Int_t cumulantIndex=0;cumulantIndex<4;cumulantIndex++)
2247      } else // to if(diffFlowFinalCumulants[t][pW][eW][nua])
2248        { 
2249         cout<<"WARNING: diffFlowFinalCumulants[t][pW][eW][nua] is NULL in AFAWQC::GOH() !!!!"<<endl;
2250         cout<<"t = "<<t<<endl;
2251         cout<<"pW = "<<pW<<endl;
2252         cout<<"eW = "<<eW<<endl;
2253         cout<<"nua = "<<nua<<endl;
2254        }      
2255      // flow:
2256      if(diffFlowFinalFlow[t][pW][eW][nua])
2257      {
2258       for(Int_t flowIndex=0;flowIndex<4;flowIndex++)
2259       {
2260        // 2D:
2261        finalFlow2D[t][pW][eW][nua][flowIndex] = dynamic_cast<TH2D*>(diffFlowFinalFlow[t][pW][eW][nua]->FindObject(Form("%s, (p_{t},#eta)",flowName[flowIndex].Data())));
2262        if(finalFlow2D[t][pW][eW][nua][flowIndex])
2263        {
2264         this->SetFinalFlow2D(finalFlow2D[t][pW][eW][nua][flowIndex],t,pW,eW,nua,flowIndex);
2265        } else
2266          {
2267           cout<<"WARNING: finalFlow2D[t][pW][eW][nua][flowIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2268           cout<<"t = "<<t<<endl;
2269           cout<<"pW = "<<pW<<endl;
2270           cout<<"eW = "<<eW<<endl;
2271           cout<<"nua = "<<nua<<endl;
2272           cout<<"ci = "<<flowIndex<<endl;
2273          }
2274        // pt:
2275        finalFlowPt[t][pW][eW][nua][flowIndex] = dynamic_cast<TH1D*>(diffFlowFinalFlow[t][pW][eW][nua]->FindObject(Form("%s, (p_{t})",flowName[flowIndex].Data())));
2276        if(finalFlowPt[t][pW][eW][nua][flowIndex])
2277        {
2278         this->SetFinalFlowPt(finalFlowPt[t][pW][eW][nua][flowIndex],t,pW,eW,nua,flowIndex);
2279        } else
2280          {
2281           cout<<"WARNING: finalFlow1D[t][pW][nua][flowIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2282           cout<<"t = "<<t<<endl;
2283           cout<<"pW = "<<pW<<endl;
2284           cout<<"eW = "<<eW<<endl;
2285           cout<<"nua = "<<nua<<endl;
2286           cout<<"ci = "<<flowIndex<<endl;
2287          }   
2288        // eta: 
2289        finalFlowEta[t][pW][eW][nua][flowIndex] = dynamic_cast<TH1D*>(diffFlowFinalFlow[t][pW][eW][nua]->FindObject(Form("%s, (#eta)",flowName[flowIndex].Data())));          
2290        if(finalFlowEta[t][pW][eW][nua][flowIndex])
2291        {
2292         this->SetFinalFlowEta(finalFlowEta[t][pW][eW][nua][flowIndex],t,pW,eW,nua,flowIndex);
2293        } else
2294          {
2295           cout<<"WARNING: finalFlow1D[t][pW][nua][flowIndex] is NULL in AFAWQC::GOH() !!!!"<<endl;
2296           cout<<"t = "<<t<<endl;
2297           cout<<"pW = "<<pW<<endl;
2298           cout<<"eW = "<<eW<<endl;
2299           cout<<"nua = "<<nua<<endl;
2300           cout<<"ci = "<<flowIndex<<endl;
2301          }   
2302       } // end of for(Int_t flowIndex=0;flowIndex<4;flowIndex++)
2303      } else // to if(diffFlowFinalFlow[t][pW][eW][nua])
2304        { 
2305         cout<<"WARNING: diffFlowFinalFlow[t][pW][eW][nua] is NULL in AFAWQC::GOH() !!!!"<<endl;
2306         cout<<"t = "<<t<<endl;
2307         cout<<"pW = "<<pW<<endl;
2308         cout<<"eW = "<<eW<<endl;
2309         cout<<"nua = "<<nua<<endl;
2310        }               
2311     } // end of for(Int_t nua=0;nua<2;nua++)
2312    } // end of for(Int_t eW=0;eW<2;eW++) 
2313   } // end of for(Int_t pW=0;pW<(1+(Int_t)(bUsePhiWeights||bUsePtWeights||bUseEtaWeights));pW++)
2314  } // end of for(Int_t t=0;t<2;t++)
2315  
2316   // x.) nested loops:
2317   TList *nestedLoopsList = dynamic_cast<TList*>(outputListHistos->FindObject("Nested Loops"));
2318   if(nestedLoopsList) this->SetNestedLoopsList(nestedLoopsList);
2319   TProfile *evaluateNestedLoops = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fEvaluateNestedLoops"));
2320   Bool_t bEvaluateNestedLoopsForIntFlow = kFALSE;
2321   Bool_t bEvaluateNestedLoopsForDiffFlow = kFALSE;
2322   if(evaluateNestedLoops)
2323   {
2324    this->SetEvaluateNestedLoops(evaluateNestedLoops);
2325    bEvaluateNestedLoopsForIntFlow = (Int_t)evaluateNestedLoops->GetBinContent(1);
2326    bEvaluateNestedLoopsForDiffFlow = (Int_t)evaluateNestedLoops->GetBinContent(2);
2327   }
2328   
2329   if(bEvaluateNestedLoopsForIntFlow)
2330   {
2331    TProfile *directCorrelations = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrelation"));
2332    if(directCorrelations) this->SetDirectCorrelations(directCorrelations);
2333    TProfile *directCorrectionsCos = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsCos"));
2334    if(directCorrectionsCos) this->SetDirectCorrectionsCos(directCorrectionsCos);
2335    TProfile *directCorrectionsSin = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsSin"));
2336    if(directCorrectionsSin) this->SetDirectCorrectionsSin(directCorrectionsSin);
2337    if(bUsePhiWeights||bUsePtWeights||bUseEtaWeights)
2338    {
2339     TProfile *directCorrelationsW = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrelationW"));
2340     if(directCorrelationsW) this->SetDirectCorrelationsW(directCorrelationsW);
2341     TProfile *directCorrectionsCosW = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsCosW"));
2342     if(directCorrectionsCosW) this->SetDirectCorrectionsCosW(directCorrectionsCosW);
2343     TProfile *directCorrectionsSinW = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsSinW")); 
2344     if(directCorrectionsSinW) this->SetDirectCorrectionsSinW(directCorrectionsSinW);
2345    }
2346   }
2347   
2348   if(bEvaluateNestedLoopsForDiffFlow)
2349   {
2350    TProfile *directCorrelationsDiffFlow = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrelationsDiffFlow"));
2351    if(directCorrelationsDiffFlow) this->SetDirectCorrelationsDiffFlow(directCorrelationsDiffFlow);
2352    TProfile *directCorrectionsDiffFlowCos = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsDiffFlowCos"));
2353    if(directCorrectionsDiffFlowCos) this->SetDirectCorrectionsDiffFlowCos(directCorrectionsDiffFlowCos);
2354    TProfile *directCorrectionsDiffFlowSin = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsDiffFlowSin"));
2355    if(directCorrectionsDiffFlowSin) this->SetDirectCorrectionsDiffFlowSin(directCorrectionsDiffFlowSin);
2356    if(bUsePhiWeights||bUsePtWeights||bUseEtaWeights)
2357    {
2358     TProfile *directCorrelationsDiffFlowW = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrelationsDiffFlowW")); 
2359     if(directCorrelationsDiffFlowW) this->SetDirectCorrelationsDiffFlowW(directCorrelationsDiffFlowW);
2360     TProfile *directCorrectionsDiffFlowCosW = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsDiffFlowCosW"));
2361     if(directCorrectionsDiffFlowCosW) this->SetDirectCorrectionsDiffFlowCosW(directCorrectionsDiffFlowCosW);
2362     TProfile *directCorrectionsDiffFlowSinW = dynamic_cast<TProfile*>(nestedLoopsList->FindObject("fDirectCorrectionsDiffFlowSinW"));
2363     if(directCorrectionsDiffFlowSinW) this->SetDirectCorrectionsDiffFlowSinW(directCorrectionsDiffFlowSinW);
2364    }
2365   }
2366   
2367  } 
2368 }
2369
2370
2371 //================================================================================================================================
2372
2373
2374 TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta) const
2375 {
2376  // project 2D profile onto pt axis to get 1D profile
2377  
2378  Int_t nBinsPt   = profilePtEta->GetNbinsX();
2379  Double_t dPtMin = (profilePtEta->GetXaxis())->GetXmin();
2380  Double_t dPtMax = (profilePtEta->GetXaxis())->GetXmax();
2381  
2382  Int_t nBinsEta   = profilePtEta->GetNbinsY();
2383  
2384  TProfile *profilePt = new TProfile("","",nBinsPt,dPtMin,dPtMax); 
2385  
2386  for(Int_t p=1;p<=nBinsPt;p++)
2387  {
2388   Double_t contentPt = 0.;
2389   Double_t entryPt = 0.;
2390   Double_t spreadPt = 0.;
2391   Double_t sum1 = 0.;
2392   Double_t sum2 = 0.;
2393   Double_t sum3 = 0.;
2394   for(Int_t e=1;e<=nBinsEta;e++)
2395   {
2396    contentPt += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
2397               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
2398    entryPt   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
2399    
2400    sum1 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
2401          * (pow(profilePtEta->GetBinError(profilePtEta->GetBin(p,e)),2.)
2402             + pow(profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)),2.)); 
2403    sum2 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
2404    sum3 += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)))
2405          * (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)));            
2406   }
2407   if(sum2>0. && sum1/sum2-pow(sum3/sum2,2.) > 0.)
2408   {
2409    spreadPt = pow(sum1/sum2-pow(sum3/sum2,2.),0.5);
2410   }
2411   profilePt->SetBinContent(p,contentPt);
2412   profilePt->SetBinEntries(p,entryPt);
2413   {
2414    profilePt->SetBinError(p,spreadPt);
2415   }
2416   
2417  }
2418  
2419  return profilePt;
2420  
2421 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakePtProjection(TProfile2D *profilePtEta)
2422
2423
2424 //================================================================================================================================
2425
2426
2427 TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta) const
2428 {
2429  // project 2D profile onto eta axis to get 1D profile
2430  
2431  Int_t nBinsEta   = profilePtEta->GetNbinsY();
2432  Double_t dEtaMin = (profilePtEta->GetYaxis())->GetXmin();
2433  Double_t dEtaMax = (profilePtEta->GetYaxis())->GetXmax();
2434  
2435  Int_t nBinsPt = profilePtEta->GetNbinsX();
2436  
2437  TProfile *profileEta = new TProfile("","",nBinsEta,dEtaMin,dEtaMax); 
2438  
2439  for(Int_t e=1;e<=nBinsEta;e++)
2440  {
2441   Double_t contentEta = 0.;
2442   Double_t entryEta = 0.;
2443   for(Int_t p=1;p<=nBinsPt;p++)
2444   {
2445    contentEta += (profilePtEta->GetBinContent(profilePtEta->GetBin(p,e)))
2446               * (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
2447    entryEta   += (profilePtEta->GetBinEntries(profilePtEta->GetBin(p,e)));
2448   }
2449   profileEta->SetBinContent(e,contentEta);
2450   profileEta->SetBinEntries(e,entryEta);
2451  }
2452  
2453  return profileEta;
2454  
2455 } // end of TProfile* AliFlowAnalysisWithQCumulants::MakeEtaProjection(TProfile2D *profilePtEta)
2456
2457
2458 //================================================================================================================================
2459
2460
2461 void AliFlowAnalysisWithQCumulants::CalculateFinalCorrectionsForNonUniformAcceptanceForCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
2462 {
2463  // calculate final corrections for non-uniform acceptance for QC{2}, QC{4}, QC{6} and QC{8}
2464  
2465  // corrections for non-uniform acceptance (NUA) are stored in histogram fCorrectionsForNUA,
2466  // binning of fCorrectionsForNUA is organized as follows:
2467  //
2468  // 1st bin: correction to QC{2}
2469  // 2nd bin: correction to QC{4}
2470  // 3rd bin: correction to QC{6}
2471  // 4th bin: correction to QC{8}
2472  
2473  // shortcuts flags:
2474  Int_t pW = (Int_t)(useParticleWeights);
2475  
2476  Int_t eW = -1;
2477  
2478  if(eventWeights == "exact")
2479  {
2480   eW = 0;
2481  }
2482
2483  for(Int_t sc=0;sc<2;sc++) // sin or cos terms flag
2484  {
2485   if(!(fQCorrelations[pW][eW] && fQCorrections[pW][eW][sc] && fCorrections[pW][eW]))
2486   {
2487    cout<<"WARNING: fQCorrelations[pW][eW] && fQCorrections[pW][eW][sc] && fCorrections[pW][eW] is NULL in AFAWQC::CFCFNUAFIF() !!!!"<<endl;
2488    cout<<"pW = "<<pW<<endl;
2489    cout<<"eW = "<<eW<<endl;
2490    cout<<"sc = "<<sc<<endl;
2491    exit(0);
2492   }
2493  }  
2494
2495  // measured 2-, 4-, 6- and 8-particle azimuthal correlations (biased with non-uniform acceptance!):
2496  Double_t two = fQCorrelations[pW][eW]->GetBinContent(1); // <<2>>
2497  //Double_t four = fQCorrelations[pW][eW]->GetBinContent(11); // <<4>>
2498  //Double_t six = fQCorrelations[pW][eW]->GetBinContent(24); // <<6>>
2499  //Double_t eight = fQCorrelations[pW][eW]->GetBinContent(31); // <<8>>
2500  
2501  // correction terms to QC{2}:
2502  // <<cos(n*phi1)>>^2
2503  Double_t two1stTerm = pow(fQCorrections[pW][eW][1]->GetBinContent(1),2); 
2504  // <<sin(n*phi1)>>^2
2505  Double_t two2ndTerm = pow(fQCorrections[pW][eW][0]->GetBinContent(1),2); 
2506  // final corrections for non-uniform acceptance to QC{2}:
2507  Double_t correctionQC2 = -1.*two1stTerm-1.*two2ndTerm;
2508  fCorrections[pW][eW]->SetBinContent(1,correctionQC2); 
2509  
2510  // correction terms to QC{4}:
2511  // <<cos(n*phi1)>> <<cos(n*(phi1-phi2-phi3))>>
2512  Double_t four1stTerm = fQCorrections[pW][eW][1]->GetBinContent(1)*fQCorrections[pW][eW][1]->GetBinContent(3);  
2513  // <<sin(n*phi1)>> <<sin(n*(phi1-phi2-phi3))>>
2514  Double_t four2ndTerm = fQCorrections[pW][eW][0]->GetBinContent(1)*fQCorrections[pW][eW][0]->GetBinContent(3);  
2515  // <<cos(n*(phi1+phi2))>>^2
2516  Double_t four3rdTerm = pow(fQCorrections[pW][eW][1]->GetBinContent(2),2); 
2517  // <<sin(n*(phi1+phi2))>>^2
2518  Double_t four4thTerm = pow(fQCorrections[pW][eW][0]->GetBinContent(2),2); 
2519  // <<cos(n*(phi1+phi2))>> (<<cos(n*phi1)>>^2 - <<sin(n*phi1)>>^2)
2520  Double_t four5thTerm = fQCorrections[pW][eW][1]->GetBinContent(2)
2521                       * (pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)-pow(fQCorrections[pW][eW][0]->GetBinContent(1),2));
2522  // <<sin(n*(phi1+phi2))>> <<cos(n*phi1)>> <<sin(n*phi1)>>
2523  Double_t four6thTerm = fQCorrections[pW][eW][0]->GetBinContent(2)
2524                       * fQCorrections[pW][eW][1]->GetBinContent(1)
2525                       * fQCorrections[pW][eW][0]->GetBinContent(1);         
2526  // <<cos(n*(phi1-phi2))>> (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)
2527  Double_t four7thTerm = two*(pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)+pow(fQCorrections[pW][eW][0]->GetBinContent(1),2));  
2528  // (<<cos(n*phi1)>>^2 + <<sin(n*phi1)>>^2)^2
2529  Double_t four8thTerm = pow(pow(fQCorrections[pW][eW][1]->GetBinContent(1),2)+pow(fQCorrections[pW][eW][0]->GetBinContent(1),2),2);      
2530  // final correction to QC{4}:
2531  Double_t correctionQC4 = -4.*four1stTerm+4.*four2ndTerm-four3rdTerm-four4thTerm
2532                         + 4.*four5thTerm+8.*four6thTerm+8.*four7thTerm-6.*four8thTerm;                            
2533  fCorrections[pW][eW]->SetBinContent(2,correctionQC4);   
2534
2535  // ... to be improved (continued for 6th and 8th order)                                                    
2536
2537 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalCorrectionsForNonUniformAcceptanceForCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
2538
2539
2540 //================================================================================================================================
2541
2542
2543 void AliFlowAnalysisWithQCumulants::CalculateFinalCorrectionsForNonUniformAcceptanceForDifferentialFlow(Bool_t useParticleWeights,TString type)
2544 {
2545  
2546  useParticleWeights=kFALSE;
2547  type="ac";
2548   
2549  // calculate final corrections due to non-uniform acceptance of the detector to reduced multi-particle correlations
2550  /*
2551  if(!(useParticleWeights))
2552  {
2553   if(type == "POI")
2554   { 
2555    // **** corrections for non-uniform acceptance for 2nd order QC' for POI's ****
2556    
2557    // 1st term: <<cos(n*psi)>><<cos(n*phi)>>:
2558    if(fCorrectionsCosP1nPsiPtEtaPOI && fQCorrectionsCos)
2559    {
2560     // pt,eta: 
2561     if(f2pFinalCorrectionsForNUAPtEtaPOI) f2pFinalCorrectionsForNUAPtEtaPOI->Reset(); // to be improved
2562     TH2D *correctionPtEta1stTerm = new TH2D(*(fCorrectionsCosP1nPsiPtEtaPOI->ProjectionXY("","e")));
2563     correctionPtEta1stTerm->Scale(fQCorrectionsCos->GetBinContent(1)); // to be improved: are errors propagated correctly here?   
2564     if(f2pFinalCorrectionsForNUAPtEtaPOI) f2pFinalCorrectionsForNUAPtEtaPOI->Add(correctionPtEta1stTerm); // to be improved (if condition goes somewhere else)
2565     delete correctionPtEta1stTerm;
2566     // pt:
2567     if(f2pFinalCorrectionsForNUAPtPOI) f2pFinalCorrectionsForNUAPtPOI->Reset(); // to be improved
2568     TH1D *correctionPt1stTerm = new TH1D(*((this->MakePtProjection(fCorrectionsCosP1nPsiPtEtaPOI))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2569     correctionPt1stTerm->Scale(fQCorrectionsCos->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2570     if(f2pFinalCorrectionsForNUAPtPOI) f2pFinalCorrectionsForNUAPtPOI->Add(correctionPt1stTerm); // to be improved (if condition goes somewhere else)
2571     delete correctionPt1stTerm;
2572     // eta:
2573     if(f2pFinalCorrectionsForNUAEtaPOI) f2pFinalCorrectionsForNUAEtaPOI->Reset(); // to be improved    
2574     TH1D *correctionEta1stTerm = new TH1D(*((this->MakeEtaProjection(fCorrectionsCosP1nPsiPtEtaPOI))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2575     correctionEta1stTerm->Scale(fQCorrectionsCos->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2576     if(f2pFinalCorrectionsForNUAEtaPOI) f2pFinalCorrectionsForNUAEtaPOI->Add(correctionEta1stTerm); // to be improved (if condition goes somewhere else)
2577     delete correctionEta1stTerm;    
2578    } else
2579      { 
2580       cout<<"WARNING: (fCorrectionsCosP1nPsiPtEtaPOI && fQCorrectionsCos && f2pFinalCorrectionsForNUAPtEtaPOI) is NULL in QC::CFCFNUAFDF() !!!!  "<<endl;
2581       cout<<"         Corrections for non-uniform acceptance for differential flow are not correct."<<endl;
2582      } 
2583      
2584    // 2nd term: <<sin(n*psi)>><<sin(n*phi)>>:  
2585    if(fCorrectionsSinP1nPsiPtEtaPOI && fQCorrectionsSin)
2586    {
2587     // pt,eta:
2588     TH2D *correctionPtEta2ndTerm = new TH2D(*(fCorrectionsSinP1nPsiPtEtaPOI->ProjectionXY("","e")));
2589     correctionPtEta2ndTerm->Scale(fQCorrectionsSin->GetBinContent(1)); // to be improved: are errors propagated correctly here?    
2590     if(f2pFinalCorrectionsForNUAPtEtaPOI) f2pFinalCorrectionsForNUAPtEtaPOI->Add(correctionPtEta2ndTerm); // to be improved (if condition goes somewhere else)
2591     delete correctionPtEta2ndTerm;
2592     // pt:
2593     TH1D *correctionPt2ndTerm = new TH1D(*((this->MakePtProjection(fCorrectionsSinP1nPsiPtEtaPOI))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2594     correctionPt2ndTerm->Scale(fQCorrectionsSin->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2595     if(f2pFinalCorrectionsForNUAPtPOI) f2pFinalCorrectionsForNUAPtPOI->Add(correctionPt2ndTerm); // to be improved (if condition goes somewhere else)
2596     delete correctionPt2ndTerm;
2597     // eta:
2598     TH1D *correctionEta2ndTerm = new TH1D(*((this->MakeEtaProjection(fCorrectionsSinP1nPsiPtEtaPOI))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2599     correctionEta2ndTerm->Scale(fQCorrectionsSin->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2600     if(f2pFinalCorrectionsForNUAEtaPOI) f2pFinalCorrectionsForNUAEtaPOI->Add(correctionEta2ndTerm); // to be improved (if condition goes somewhere else)
2601     delete correctionEta2ndTerm; 
2602    } else
2603      { 
2604       cout<<"WARNING: (fCorrectionsSinP1nPsiPtEtaPOI && fQCorrectionsSin) is NULL in QC::CFCFNUAFDF() !!!!  "<<endl;
2605       cout<<"         Corrections for non-uniform acceptance for differential flow are not correct."<<endl;
2606      } 
2607   } else if(type == "RP")
2608     {
2609      // **** corrections for non-uniform acceptance for 2nd order QC' for RP's ****
2610    
2611      // 1st term: <<cos(n*psi)>><<cos(n*phi)>>:
2612      if(fCorrectionsCosP1nPsiPtEtaRP && fQCorrectionsCos)
2613      {
2614       // pt,eta: 
2615       if(f2pFinalCorrectionsForNUAPtEtaRP) f2pFinalCorrectionsForNUAPtEtaRP->Reset(); // to be improved
2616       TH2D *correctionPtEta1stTerm = new TH2D(*(fCorrectionsCosP1nPsiPtEtaRP->ProjectionXY("","e")));
2617       correctionPtEta1stTerm->Scale(fQCorrectionsCos->GetBinContent(1)); // to be improved: are errors propagated correctly here?    
2618       if(f2pFinalCorrectionsForNUAPtEtaRP) f2pFinalCorrectionsForNUAPtEtaRP->Add(correctionPtEta1stTerm); // to be improved (if condition goes somewhere else)
2619       delete correctionPtEta1stTerm;
2620       // pt:
2621       if(f2pFinalCorrectionsForNUAPtRP) f2pFinalCorrectionsForNUAPtRP->Reset(); // to be improved
2622       TH1D *correctionPt1stTerm = new TH1D(*((this->MakePtProjection(fCorrectionsCosP1nPsiPtEtaRP))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2623       correctionPt1stTerm->Scale(fQCorrectionsCos->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2624       if(f2pFinalCorrectionsForNUAPtRP) f2pFinalCorrectionsForNUAPtRP->Add(correctionPt1stTerm); // to be improved (if condition goes somewhere else)
2625       delete correctionPt1stTerm;
2626       // eta:
2627       if(f2pFinalCorrectionsForNUAEtaRP) f2pFinalCorrectionsForNUAEtaRP->Reset(); // to be improved
2628       TH1D *correctionEta1stTerm = new TH1D(*((this->MakeEtaProjection(fCorrectionsCosP1nPsiPtEtaRP))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2629       correctionEta1stTerm->Scale(fQCorrectionsCos->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2630       if(f2pFinalCorrectionsForNUAEtaRP) f2pFinalCorrectionsForNUAEtaRP->Add(correctionEta1stTerm); // to be improved (if condition goes somewhere else)
2631       delete correctionEta1stTerm;    
2632      } else
2633        { 
2634         cout<<"WARNING: (fCorrectionsCosP1nPsiPtEtaRP && fQCorrectionsCos) is NULL in QC::CFCFNUAFDF() !!!!  "<<endl;
2635         cout<<"         Corrections for non-uniform acceptance for differential flow are not correct."<<endl;
2636        } 
2637      // 2nd term: <<sin(n*psi)>><<sin(n*phi)>>:  
2638      if(fCorrectionsSinP1nPsiPtEtaRP && fQCorrectionsSin)
2639      {
2640       // pt,eta: 
2641       TH2D *correctionPtEta2ndTerm = new TH2D(*(fCorrectionsSinP1nPsiPtEtaRP->ProjectionXY("","e")));
2642       correctionPtEta2ndTerm->Scale(fQCorrectionsSin->GetBinContent(1)); // to be improved: are errors propagated correctly here?    
2643       if(f2pFinalCorrectionsForNUAPtEtaRP) f2pFinalCorrectionsForNUAPtEtaRP->Add(correctionPtEta2ndTerm); // to be improved (if condition goes somewhere else)
2644       delete correctionPtEta2ndTerm;
2645       // pt:
2646       TH1D *correctionPt2ndTerm = new TH1D(*((this->MakePtProjection(fCorrectionsSinP1nPsiPtEtaRP))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2647       correctionPt2ndTerm->Scale(fQCorrectionsSin->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2648       if(f2pFinalCorrectionsForNUAPtRP) f2pFinalCorrectionsForNUAPtRP->Add(correctionPt2ndTerm); // to be improved (if condition goes somewhere else)
2649       delete correctionPt2ndTerm;
2650       // eta:
2651       TH1D *correctionEta2ndTerm = new TH1D(*((this->MakeEtaProjection(fCorrectionsSinP1nPsiPtEtaRP))->ProjectionX("","e"))); // to be improved: are errors propagated correctly here? 
2652       correctionEta2ndTerm->Scale(fQCorrectionsSin->GetBinContent(1)); // to be improved: are errors propagated correctly here? 
2653       if(f2pFinalCorrectionsForNUAEtaRP) f2pFinalCorrectionsForNUAEtaRP->Add(correctionEta2ndTerm); // to be improved (if condition goes somewhere else)
2654       delete correctionEta2ndTerm; 
2655      } else
2656        { 
2657         cout<<"WARNING: (fCorrectionsSinP1nPsiPtEtaRP && fQCorrectionsSin) is NULL in QC::CFCFNUAFDF() !!!!  "<<endl;
2658         cout<<"         Corrections for non-uniform acceptance for differential flow are not correct."<<endl;
2659        }              
2660     } else // to else if(type == "RP")
2661       {
2662        cout<<"WARNING: Type must be either POI or RP in QC::CFCFNUAFDF() !!!!                           "<<endl;
2663        cout<<"         Corrections for non-uniform acceptance for differential flow were not calculated."<<endl;
2664       }  
2665  } else // to if(!(useParticleWeights))
2666    {
2667     // ...
2668    }
2669  */
2670 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalCorrectionsForNonUniformAcceptanceForDifferentialFlow(Bool_t useParticleWeights,TString type)
2671
2672
2673 //==================================================================================================================================
2674
2675 /*
2676 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForDifferentialFlow(
2677                                                         TH2D *flowPtEta, TH1D *flowPt, TH1D *flowEta, 
2678                                                         TProfile2D *profile2ndPtEta, TProfile2D *profile4thPtEta, 
2679                                                         TProfile2D *profile6thPtEta, TProfile2D *profile8thPtEta)
2680 {
2681  // calculate and store the final results for integrated flow
2682  
2683  TString *namePtEta = new TString();
2684  TString *type = new TString();
2685  TString *order2nd = new TString();
2686  TString *order4th = new TString();
2687  TString *order6th = new TString();
2688  TString *order8th = new TString(); 
2689  TString *pW = new TString();
2690
2691  if(profile2ndPtEta) *namePtEta = profile2ndPtEta->GetName();
2692  if(namePtEta->Contains("POI")) *type = "POI";
2693  if(namePtEta->Contains("RP")) *type  = "RP";
2694  if(namePtEta->Contains("W")) *pW      = "W";
2695  if(namePtEta->Contains("2")) *order2nd  = "2";
2696  if(profile4thPtEta) *namePtEta = profile4thPtEta->GetName();
2697  if(namePtEta->Contains("4")) *order4th = "4";
2698
2699  if(profile6thPtEta) *namePtEta = profile6thPtEta->GetName();
2700  if(namePtEta->Contains("6")) *order6th = "6";
2701  
2702  if(profile8thPtEta) *namePtEta = profile8thPtEta->GetName();
2703  if(namePtEta->Contains("8")) *order8th = "8";
2704
2705  TProfile *profile2ndPt = NULL;
2706  TProfile *profile4thPt = NULL;
2707  TProfile *profile6thPt = NULL;
2708  TProfile *profile8thPt = NULL;
2709
2710  TProfile *profile2ndEta = NULL;
2711  TProfile *profile4thEta = NULL;
2712  TProfile *profile6thEta = NULL;
2713  TProfile *profile8thEta = NULL;
2714   
2715  if(*order2nd == "2")
2716  {
2717   profile2ndPt  = new TProfile(*(this->MakePtProjection(profile2ndPtEta))); 
2718   profile2ndEta = new TProfile(*(this->MakeEtaProjection(profile2ndPtEta))); 
2719   if(*order4th == "4")
2720   {
2721    profile4thPt  = new TProfile(*(this->MakePtProjection(profile4thPtEta))); 
2722    profile4thEta = new TProfile(*(this->MakeEtaProjection(profile4thPtEta))); 
2723    if(*order6th == "6")
2724    {
2725     profile6thPt  = new TProfile(*(this->MakePtProjection(profile6thPtEta))); 
2726     profile6thEta = new TProfile(*(this->MakeEtaProjection(profile6thPtEta))); 
2727     if(*order8th == "8")
2728     {
2729      profile8thPt  = new TProfile(*(this->MakePtProjection(profile8thPtEta))); 
2730      profile8thEta = new TProfile(*(this->MakeEtaProjection(profile8thPtEta))); 
2731     }     
2732    }    
2733   } 
2734  }
2735  
2736  Int_t nBinsPt  = profile2ndPt->GetNbinsX();
2737  Int_t nBinsEta = profile2ndEta->GetNbinsX();
2738  
2739  Double_t dV2 = 0.;
2740  Double_t dV4 = 0.;
2741  Double_t dV6 = 0.;
2742  Double_t dV8 = 0.; 
2743  
2744  if(!(*pW == "W"))
2745  {
2746   dV2 = fIntFlowResultsQC->GetBinContent(1); 
2747   dV4 = fIntFlowResultsQC->GetBinContent(2); 
2748   dV6 = fIntFlowResultsQC->GetBinContent(3); 
2749   dV8 = fIntFlowResultsQC->GetBinContent(4); 
2750  } 
2751  else if(*pW == "W")
2752  {
2753   dV2 = fIntFlowResultsQCW->GetBinContent(1);  
2754   dV4 = fIntFlowResultsQCW->GetBinContent(2); 
2755   dV6 = fIntFlowResultsQCW->GetBinContent(3); 
2756   dV8 = fIntFlowResultsQCW->GetBinContent(4); 
2757  }    
2758  
2759  // 3D (pt,eta): 
2760  Double_t twoPrimePtEta   = 0.; // <<2'>> (pt,eta) 
2761  Double_t fourPrimePtEta  = 0.; // <<4'>> (pt,eta)  
2762  //Double_t sixPrimePtEta   = 0.; // <<6'>> (pt,eta) 
2763  //Double_t eightPrimePtEta = 0.; // <<8'>> (pt,eta) 
2764  Double_t secondOrderDiffFlowCumulantPtEta = 0.; // d_n{2,Q} (pt,eta)
2765  Double_t fourthOrderDiffFlowCumulantPtEta = 0.; // d_n{4,Q} (pt,eta) 
2766  //Double_t sixthOrderDiffFlowCumulantPtEta = 0.; // d_n{6,Q} (pt,eta)
2767  //Double_t eightOrderDiffFlowCumulantPtEta = 0.; // d_n{8,Q} (pt,eta)2nd
2768  Double_t dv2PtEta = 0.; // v'_n{2} (pt,eta) 
2769  Double_t dv4PtEta = 0.; // v'_n{4} (pt,eta) 
2770  //Double_t dv6PtEta = 0.; // v'_n{6} (pt,eta) 
2771  //Double_t dv8PtEta = 0.; // v'_n{8} (pt,eta)  
2772
2773  // 2D (pt):   
2774  Double_t twoPrimePt   = 0.; // <<2'>> (pt)  
2775  Double_t fourPrimePt  = 0.; // <<4'>> (pt) 
2776  //Double_t sixPrimePt   = 0.; // <<6'>> (pt) 
2777  //Double_t eightPrimePt = 0.; // <<8'>> (pt)          
2778  Double_t secondOrderDiffFlowCumulantPt = 0.; // d_n{2,Q} (pt) 
2779  Double_t fourthOrderDiffFlowCumulantPt = 0.; // d_n{4,Q} (pt)  
2780  //Double_t sixthOrderDiffFlowCumulantPt = 0.; // d_n{6,Q} (pt)
2781  //Double_t eightOrderDiffFlowCumulantPt = 0.; // d_n{8,Q} (pt)
2782  Double_t dv2Pt = 0.; // v'_n{2} (pt)
2783  Double_t dv4Pt = 0.; // v'_n{4} (pt)
2784  //Double_t dv6Pt = 0.; // v'_n{6} (pt) 
2785  //Double_t dv8Pt = 0.; // v'_n{8} (pt)  
2786
2787  // 2D (eta):           
2788  Double_t twoPrimeEta   = 0.; // <<2'>> (eta)  
2789  Double_t fourPrimeEta  = 0.; // <<4>> (eta) 
2790  //Double_t sixPrimeEta   = 0.; // <<6>> (eta) 
2791  //Double_t eightPrimeEta = 0.; // <<8'>> (eta)  
2792  Double_t secondOrderDiffFlowCumulantEta = 0.; // d_n{2,Q} (eta)
2793  Double_t fourthOrderDiffFlowCumulantEta = 0.; // d_n{4,Q} (eta) 
2794  //Double_t sixthOrderDiffFlowCumulantEta = 0.; // d_n{6,Q} (eta) 
2795  //Double_t eightOrderDiffFlowCumulantEta = 0.; // d_n{8,Q} (eta) 
2796  Double_t dv2Eta = 0.; // v'_n{2} (eta)
2797  Double_t dv4Eta = 0.; // v'_n{4} (eta)
2798  //Double_t dv6Eta = 0.; // v'_n{6} (eta) 
2799  //Double_t dv8Eta = 0.; // v'_n{8} (eta)
2800  
2801
2802  // looping over (pt,eta) bins to calculate v'(pt,eta) 
2803  for(Int_t p=1;p<nBinsPt+1;p++)
2804  {
2805   for(Int_t e=1;e<nBinsEta+1;e++)
2806   {
2807   
2808    // 2nd order: 
2809    twoPrimePtEta = profile2ndPtEta->GetBinContent(profile2ndPtEta->GetBin(p,e));
2810    secondOrderDiffFlowCumulantPtEta = twoPrimePtEta;
2811    
2812
2813    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2814    // to be improved (applying correction for NUA):
2815    if(namePtEta->Contains("POI"))
2816    {
2817     if(f2pFinalCorrectionsForNUAPtEtaPOI) secondOrderDiffFlowCumulantPtEta = twoPrimePtEta 
2818                                      - f2pFinalCorrectionsForNUAPtEtaPOI->GetBinContent(f2pFinalCorrectionsForNUAPtEtaPOI->GetBin(p,e)) ;
2819    } else if (namePtEta->Contains("RP"))
2820      {  
2821       if(f2pFinalCorrectionsForNUAPtEtaRP) secondOrderDiffFlowCumulantPtEta = twoPrimePtEta 
2822                                        - f2pFinalCorrectionsForNUAPtEtaRP->GetBinContent(f2pFinalCorrectionsForNUAPtEtaRP->GetBin(p,e));
2823      }
2824    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2825    
2826    
2827    if(dV2)
2828    {
2829     dv2PtEta = secondOrderDiffFlowCumulantPtEta/dV2;
2830     if(*order2nd == "2") 
2831     {
2832      flowPtEta->SetBinContent(p,e,dv2PtEta);   
2833     } 
2834    }
2835    
2836    // 4th order: 
2837    if(*order4th == "4" || *order6th == "6" || *order8th == "8")
2838    {
2839     fourPrimePtEta = profile4thPtEta->GetBinContent(profile4thPtEta->GetBin(p,e));
2840     fourthOrderDiffFlowCumulantPtEta = fourPrimePtEta - 2.*twoPrimePtEta*pow(dV2,2.); // to be improved (correlations instead of pow(dV2,2.))
2841     if(dV4)
2842     {
2843      dv4PtEta = -fourthOrderDiffFlowCumulantPtEta/pow(dV4,3);
2844      if(*order4th == "4")
2845      {
2846       flowPtEta->SetBinContent(p,e,dv4PtEta);
2847      } 
2848     }
2849    }    
2850    
2851   } // end of for(Int_t e=1;e<nBinsEta+1;e++)
2852  } // end of for(Int_t p=1;p<nBinsPt+1;p++) 
2853    
2854    
2855  // looping over (pt) bins to calcualate v'(pt)
2856  for(Int_t p=1;p<nBinsPt+1;p++)
2857  {
2858  
2859   // 2nd order: 
2860   twoPrimePt = profile2ndPt->GetBinContent(p);
2861   secondOrderDiffFlowCumulantPt = twoPrimePt;
2862   
2863   
2864   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2865   // to be improved (applying correction for NUA):
2866   if(namePtEta->Contains("POI"))
2867   {
2868    if(f2pFinalCorrectionsForNUAPtPOI) secondOrderDiffFlowCumulantPt = twoPrimePt
2869                                     - f2pFinalCorrectionsForNUAPtPOI->GetBinContent(p) ;
2870   } else if (namePtEta->Contains("RP"))
2871     {
2872      if(f2pFinalCorrectionsForNUAPtRP) secondOrderDiffFlowCumulantPt = twoPrimePt
2873                                       - f2pFinalCorrectionsForNUAPtRP->GetBinContent(p);
2874     }
2875   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2876   
2877   
2878   if(dV2)
2879   {
2880    dv2Pt = secondOrderDiffFlowCumulantPt/dV2;
2881    if(*order2nd == "2") 
2882    {
2883     flowPt->SetBinContent(p,dv2Pt);
2884    }
2885    
2886    // common control histos: (to be improved fill only once. now they are filled first without weights and then with weights):
2887    if(namePtEta->Contains("POI") && *order2nd == "2")
2888    {
2889     fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,dv2Pt,0.); //to be improved (errors && bb or bb+1 ?)
2890    } 
2891    else if(namePtEta->Contains("RP") && *order2nd == "2")
2892    {
2893     fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,dv2Pt,0.); //to be improved (errors && bb or bb+1 ?)
2894    }
2895    
2896   }
2897   
2898   // 4th order: 
2899   if(*order4th == "4" || *order6th == "6" || *order8th == "8")
2900   {
2901    fourPrimePt = profile4thPt->GetBinContent(profile4thPt->GetBin(p));
2902    fourthOrderDiffFlowCumulantPt = fourPrimePt - 2.*twoPrimePt*pow(dV2,2.); // to be improved (correlations instead of pow(dV2,2.))
2903    if(dV4)
2904    {
2905     dv4Pt = -fourthOrderDiffFlowCumulantPt/pow(dV4,3);
2906     if(*order4th == "4") 
2907     {
2908      flowPt->SetBinContent(p,dv4Pt);
2909     }
2910     
2911     // common control histos: (to be improved):
2912     if(namePtEta->Contains("POI") && *order4th == "4")
2913     {
2914      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,dv4Pt,0.); //to be improved (errors && bb or bb+1 ?)
2915     } 
2916     else if(namePtEta->Contains("RP") && *order4th == "4" )
2917     {
2918      fCommonHistsResults4th->FillDifferentialFlowPtRP(p,dv4Pt,0.); //to be improved (errors && bb or bb+1 ?)
2919     }
2920         
2921    }
2922   }    
2923   
2924  } // end of for(Int_t p=1;p<nBinsPt+1;p++)  
2925  
2926  
2927  // looping over (eta) bins to calcualate v'(eta)
2928  for(Int_t e=1;e<nBinsEta+1;e++)
2929  {
2930  
2931   // 2nd order: 
2932   twoPrimeEta = profile2ndEta->GetBinContent(e);
2933   secondOrderDiffFlowCumulantEta = twoPrimeEta;
2934   
2935   
2936   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2937   // to be improved (applying correction for NUA):
2938   if(namePtEta->Contains("POI"))
2939   {
2940    if(f2pFinalCorrectionsForNUAEtaPOI) secondOrderDiffFlowCumulantEta = twoPrimeEta
2941                                     - f2pFinalCorrectionsForNUAEtaPOI->GetBinContent(e) ;
2942   } else if (namePtEta->Contains("RP"))
2943     {
2944      if(f2pFinalCorrectionsForNUAEtaRP) secondOrderDiffFlowCumulantEta = twoPrimeEta
2945                                       - f2pFinalCorrectionsForNUAEtaRP->GetBinContent(e);
2946     }
2947   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2948   
2949   
2950   if(dV2)
2951   {
2952    dv2Eta = secondOrderDiffFlowCumulantEta/dV2;
2953    if(*order2nd == "2") 
2954    {
2955     flowEta->SetBinContent(e,dv2Eta);
2956    }
2957    
2958    // common control histos: (to be improved):
2959    if(namePtEta->Contains("POI") && *order2nd == "2")
2960    {
2961     fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,dv2Eta,0.); //to be improved (errors && bb or bb+1 ?)
2962    } 
2963    else if(namePtEta->Contains("RP") && *order2nd == "2")
2964    {
2965     fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,dv2Eta,0.); //to be improved (errors && bb or bb+1 ?)
2966    }
2967      
2968
2969   }
2970   
2971   // 4th order: 
2972   if(*order4th == "4" || *order6th == "6" || *order8th == "8")
2973   {
2974    fourPrimeEta = profile4thEta->GetBinContent(profile4thEta->GetBin(e));
2975    fourthOrderDiffFlowCumulantEta = fourPrimeEta - 2.*twoPrimeEta*pow(dV2,2.); // to be improved (correlations instead of pow(dV2,2.))
2976    if(dV4)
2977    {
2978     dv4Eta = -fourthOrderDiffFlowCumulantEta/pow(dV4,3);
2979     if(*order4th == "4")
2980     {
2981      flowEta->SetBinContent(e,dv4Eta);
2982     }
2983     
2984     // common control histos: (to be improved):
2985     if(namePtEta->Contains("POI") && *order4th == "4")
2986     {
2987      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,dv4Eta,0.); //to be improved (errors && bb or bb+1 ?)
2988     } 
2989     else if(namePtEta->Contains("RP") && *order4th == "4")
2990     {
2991      fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,dv4Eta,0.); //to be improved (errors && bb or bb+1 ?)
2992     }
2993    
2994    }
2995   }    
2996   
2997  } // end of for(Int_t e=1;e<nBinsEta+1;e++)    
2998     
2999  delete namePtEta;
3000  delete type;
3001  delete order2nd;
3002  delete order4th;
3003  delete order6th;
3004  delete order8th;
3005  delete pW;
3006  delete profile2ndPt;
3007  delete profile4thPt;
3008  delete profile6thPt;
3009  delete profile8thPt;
3010  delete profile2ndEta;
3011  delete profile4thEta;
3012  delete profile6thEta;
3013  delete profile8thEta;
3014
3015 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForDifferentialFlow(Bool_t useParticleWeights, TString type)
3016 */
3017
3018 //================================================================================================================================
3019
3020
3021 void AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type)
3022 {
3023  // printing on the screen the final results for integrated flow (NONAME, POI and RP) // to be improved (NONAME) 
3024  
3025  Int_t n = fHarmonic; 
3026  
3027  if(type == "NONAME" || type == "RP" || type == "POI")
3028  {
3029   if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
3030   {
3031    cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl;
3032    cout<<"         is NULL in AFAWQC::PFRFIF() !!!!"<<endl;
3033   }
3034  } else
3035    {
3036     cout<<"WARNING: type in not from {NONAME, RP, POI} in AFAWQC::PFRFIF() !!!!"<<endl;
3037     exit(0);
3038    }
3039  
3040  Double_t dVn[4] = {0.}; // array to hold Vn{2}, Vn{4}, Vn{6} and Vn{8}   
3041  Double_t dVnErr[4] = {0.}; // array to hold errors of Vn{2}, Vn{4}, Vn{6} and Vn{8}   
3042  
3043  if(type == "NONAME")
3044  {
3045   dVn[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinContent(1); 
3046   dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlow())->GetBinError(1); 
3047   dVn[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinContent(1); 
3048   dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlow())->GetBinError(1); 
3049   dVn[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinContent(1); 
3050   dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlow())->GetBinError(1); 
3051   dVn[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinContent(1); 
3052   dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlow())->GetBinError(1); 
3053  } else if(type == "RP")
3054    {
3055     dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinContent(1); 
3056     dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowRP())->GetBinError(1); 
3057     dVn[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinContent(1); 
3058     dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowRP())->GetBinError(1); 
3059     dVn[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinContent(1); 
3060     dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowRP())->GetBinError(1); 
3061     dVn[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinContent(1); 
3062     dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowRP())->GetBinError(1); 
3063    } else if(type == "POI")
3064      {
3065       dVn[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinContent(1); 
3066       dVnErr[0] = (fCommonHistsResults2nd->GetHistIntFlowPOI())->GetBinError(1); 
3067       dVn[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinContent(1); 
3068       dVnErr[1] = (fCommonHistsResults4th->GetHistIntFlowPOI())->GetBinError(1); 
3069       dVn[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinContent(1); 
3070       dVnErr[2] = (fCommonHistsResults6th->GetHistIntFlowPOI())->GetBinError(1); 
3071       dVn[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinContent(1); 
3072       dVnErr[3] = (fCommonHistsResults8th->GetHistIntFlowPOI())->GetBinError(1); 
3073      }
3074  
3075  TString title = " flow estimates from Q-cumulants"; 
3076  TString subtitle = "    ("; 
3077  
3078  if(!(fUsePhiWeights||fUsePtWeights||fUseEtaWeights))
3079  {
3080   subtitle.Append(type);
3081   subtitle.Append(", without weights)");
3082  } else  
3083    {
3084     subtitle.Append(type);
3085     subtitle.Append(", with weights)");
3086    }
3087   
3088  cout<<endl;
3089  cout<<"*************************************"<<endl;
3090  cout<<"*************************************"<<endl;
3091  cout<<title.Data()<<endl; 
3092  cout<<subtitle.Data()<<endl; 
3093  cout<<endl;
3094   
3095  for(Int_t i=0;i<4;i++)
3096  {
3097   if(dVn[i]>=0.)
3098   {
3099    cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = "<<dVn[i]<<" +/- "<<dVnErr[i]<<endl;
3100   }
3101   else
3102   {
3103    cout<<"  v_"<<n<<"{"<<2*(i+1)<<"} = Im"<<endl;
3104   }  
3105  }
3106
3107  cout<<endl;
3108  /*
3109  if(type == "NONAME")
3110  {
3111   cout<<"     nEvts = "<<nEvtsNoName<<", AvM = "<<dMultNoName<<endl; // to be improved
3112  }
3113  else if (type == "RP")
3114  {
3115   cout<<"     nEvts = "<<nEvtsRP<<", AvM = "<<dMultRP<<endl; // to be improved  
3116  } 
3117  else if (type == "POI")
3118  {
3119   cout<<"     nEvts = "<<nEvtsPOI<<", AvM = "<<dMultPOI<<endl; // to be improved  
3120  } 
3121  */
3122  cout<<"*************************************"<<endl;
3123  cout<<"*************************************"<<endl;
3124  cout<<endl; 
3125   
3126 }// end of AliFlowAnalysisWithQCumulants::PrintFinalResultsForIntegratedFlow(TString type="NONAME");
3127
3128
3129 //================================================================================================================================
3130
3131
3132 void AliFlowAnalysisWithQCumulants::CompareResultsFromNestedLoopsAndFromQVectorsForDiffFlow(Bool_t useParticleWeights)
3133 {
3134  // compare correlations needed for diff. flow calculated with nested loops and those calculated from Q-vectors
3135
3136  cout<<endl;
3137  cout<<"   *************************************"<<endl;
3138  cout<<"   **** cross-checking the formulas ****"<<endl;
3139  cout<<"   ****    for differential flow    ****"<<endl;
3140  cout<<"   ****                             ****"<<endl;
3141  cout<<"   ****        (pt,eta) bin:        ****"<<endl; 
3142  cout<<"   ****    1.1  < pt  <  1.2  GeV   ****"<<endl;  
3143  cout<<"   ****   -0.55 < eta < -0.525      ****"<<endl; 
3144  cout<<"   *************************************"<<endl;                             
3145  cout<<endl;
3146  
3147  if(!useParticleWeights)
3148  {                                        
3149   cout<<"<cos(n(psi1-phi2))> from Q-vectors    = "<<fCorrelationsPro[0][0][0][0]->GetBinContent(fCorrelationsPro[0][0][0][0]->GetBin(12,19))<<endl;
3150   cout<<"<cos(n(psi1-phi2))> from nested loops = "<<fDirectCorrelationsDiffFlow->GetBinContent(1)<<endl;
3151   cout<<endl;  
3152   cout<<"<cos(n(psi1+phi2-phi3-phi4))> from Q-vectors    = "<<fCorrelationsPro[0][0][0][1]->GetBinContent(fCorrelationsPro[0][0][0][1]->GetBin(12,19))<<endl;
3153   cout<<"<cos(n(psi1+phi2-phi3-phi4))> from nested loops = "<<fDirectCorrelationsDiffFlow->GetBinContent(41)<<endl;
3154   cout<<endl;   
3155   cout<<"****************************************************"<<endl;
3156   cout<<"****************************************************"<<endl;
3157   cout<<endl;
3158   /*
3159   cout<<"<cos(n(psi1))> from Q-vectors    = "<<fCorrectionsCosP1nPsiPtEtaPOI->GetBinContent(fCorrectionsCosP1nPsiPtEtaPOI->GetBin(12,19))<<endl;
3160   cout<<"<cos(n(psi1))> from nested loops = "<<fDirectCorrectionsDiffFlowCos->GetBinContent(1)<<endl;
3161   cout<<endl;  
3162   cout<<"<sin(n(psi1))> from Q-vectors    = "<<fCorrectionsSinP1nPsiPtEtaPOI->GetBinContent(fCorrectionsSinP1nPsiPtEtaPOI->GetBin(12,19))<<endl;
3163   cout<<"<sin(n(psi1))> from nested loops = "<<fDirectCorrectionsDiffFlowSin->GetBinContent(1)<<endl;
3164   cout<<endl;
3165   */
3166  }
3167  
3168  if(useParticleWeights)
3169  {
3170   cout<<"<w2 cos(n(psi1-phi2))> from Q-vectors (RP)   = "<<fCorrelationsPro[0][1][0][0]->GetBinContent(fCorrelationsPro[0][1][0][0]->GetBin(12,19))<<endl;
3171   cout<<"<w2 cos(n(psi1-phi2))> from Q-vectors (POI)  = "<<fCorrelationsPro[1][1][0][0]->GetBinContent(fCorrelationsPro[1][1][0][0]->GetBin(12,19))<<endl;
3172   cout<<"<w2 cos(n(psi1-phi2))> from nested loops     = "<<fDirectCorrelationsDiffFlowW->GetBinContent(1)<<endl;
3173   cout<<endl;  
3174   cout<<"<w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))> from Q-vectors (RP)  = "<<fCorrelationsPro[0][1][0][1]->GetBinContent(fCorrelationsPro[0][1][0][1]->GetBin(12,19))<<endl;
3175   cout<<"<w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))> from Q-vectors (POI) = "<<fCorrelationsPro[1][1][0][1]->GetBinContent(fCorrelationsPro[1][1][0][1]->GetBin(12,19))<<endl;
3176   cout<<"<w2 w3 w4 cos(n(psi1+phi2-phi3-phi4))> from nested loops    = "<<fDirectCorrelationsDiffFlowW->GetBinContent(41)<<endl;
3177   cout<<endl;  
3178  }
3179  
3180 } // end of void AliFlowAnalysisWithQCumulants::CompareResultsFromNestedLoopsAndFromQVectorsForDiffFlow()
3181
3182
3183 //================================================================================================================================
3184
3185
3186 void AliFlowAnalysisWithQCumulants::WriteHistograms(TString outputFileName)
3187 {
3188  //store the final results in output .root file
3189  TFile *output = new TFile(outputFileName.Data(),"RECREATE");
3190  //output->WriteObject(fHistList, "cobjQC","SingleKey");
3191  fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
3192  delete output;
3193 }
3194
3195
3196 //================================================================================================================================
3197
3198
3199 void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
3200 {
3201  // book common control histograms and common histograms for final results
3202  
3203  // common control histogram (ALL events)
3204  fCommonHists = new AliFlowCommonHist("AliFlowCommonHistQC");
3205  fHistList->Add(fCommonHists);  
3206  
3207  // common control histogram (for events with 2 and more particles)
3208  fCommonHists2nd = new AliFlowCommonHist("AliFlowCommonHist2ndOrderQC");
3209  fHistList->Add(fCommonHists2nd);  
3210  
3211  // common control histogram (for events with 4 and more particles)
3212  fCommonHists4th = new AliFlowCommonHist("AliFlowCommonHist4thOrderQC");
3213  fHistList->Add(fCommonHists4th);  
3214  
3215  // common control histogram (for events with 6 and more particles)
3216  fCommonHists6th = new AliFlowCommonHist("AliFlowCommonHist6thOrderQC");
3217  fHistList->Add(fCommonHists6th);  
3218  
3219  // common control histogram (for events with 8 and more particles)
3220  fCommonHists8th = new AliFlowCommonHist("AliFlowCommonHist8thOrderQC");
3221  fHistList->Add(fCommonHists8th);  
3222   
3223  // common histograms for final results (calculated for events with 2 and more particles)
3224  fCommonHistsResults2nd = new AliFlowCommonHistResults("AliFlowCommonHistResults2ndOrderQC");
3225  fHistList->Add(fCommonHistsResults2nd); 
3226  
3227  // common histograms for final results (calculated for events with 4 and more particles)
3228  fCommonHistsResults4th = new AliFlowCommonHistResults("AliFlowCommonHistResults4thOrderQC");
3229  fHistList->Add(fCommonHistsResults4th);
3230  
3231  // common histograms for final results (calculated for events with 6 and more particles)
3232  fCommonHistsResults6th = new AliFlowCommonHistResults("AliFlowCommonHistResults6thOrderQC");
3233  fHistList->Add(fCommonHistsResults6th); 
3234  
3235  // common histograms for final results (calculated for events with 8 and more particles)
3236  fCommonHistsResults8th = new AliFlowCommonHistResults("AliFlowCommonHistResults8thOrderQC");
3237  fHistList->Add(fCommonHistsResults8th); 
3238  
3239 } // end of void AliFlowAnalysisWithQCumulants::BookCommonHistograms()
3240
3241
3242 //================================================================================================================================
3243
3244
3245 void AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
3246 {
3247  // book and fill histograms which hold phi, pt and eta weights
3248
3249  if(!fWeightsList)
3250  {
3251   cout<<"WARNING: fWeightsList is NULL in AFAWQC::BAFWH() !!!!"<<endl;
3252   exit(0);  
3253  }
3254     
3255  fUseParticleWeights = new TProfile("fUseParticleWeights","1 = weight used, 0 = weight not used",3,0,3);
3256  fUseParticleWeights->SetLabelSize(0.06);
3257  (fUseParticleWeights->GetXaxis())->SetBinLabel(1,"w_{#phi}");
3258  (fUseParticleWeights->GetXaxis())->SetBinLabel(2,"w_{p_{T}}");
3259  (fUseParticleWeights->GetXaxis())->SetBinLabel(3,"w_{#eta}");
3260  fUseParticleWeights->Fill(0.5,(Int_t)fUsePhiWeights);
3261  fUseParticleWeights->Fill(1.5,(Int_t)fUsePtWeights);
3262  fUseParticleWeights->Fill(2.5,(Int_t)fUseEtaWeights);
3263  fWeightsList->Add(fUseParticleWeights); 
3264   
3265  if(fUsePhiWeights)
3266  {
3267   if(fWeightsList->FindObject("phi_weights"))
3268   {
3269    fPhiWeights = dynamic_cast<TH1F*>(fWeightsList->FindObject("phi_weights"));
3270    if(fPhiWeights->GetBinWidth(1) != fPhiBinWidth)
3271    {
3272     cout<<"WARNING: fPhiWeights->GetBinWidth(1) != fPhiBinWidth in AFAWQC::BAFWH() !!!!        "<<endl;
3273     cout<<"         This indicates inconsistent binning in phi histograms throughout the code."<<endl;
3274     exit(0);
3275    }
3276   } else 
3277     {
3278      cout<<"WARNING: fWeightsList->FindObject(\"phi_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
3279      exit(0);
3280     }
3281  } // end of if(fUsePhiWeights)
3282  
3283  if(fUsePtWeights) 
3284  {
3285   if(fWeightsList->FindObject("pt_weights"))
3286   {
3287    fPtWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("pt_weights"));
3288    if(fPtWeights->GetBinWidth(1) != fPtBinWidth)
3289    {
3290     cout<<"WARNING: fPtWeights->GetBinWidth(1) != fPtBinWidth in AFAWQC::BAFWH() !!!!         "<<endl;
3291     cout<<"         This indicates insconsistent binning in pt histograms throughout the code."<<endl;
3292     exit(0);
3293    }
3294   } else 
3295     {
3296      cout<<"WARNING: fWeightsList->FindObject(\"pt_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
3297      exit(0);
3298     }
3299  } // end of if(fUsePtWeights)    
3300
3301  if(fUseEtaWeights) 
3302  {
3303   if(fWeightsList->FindObject("eta_weights"))
3304   {
3305    fEtaWeights = dynamic_cast<TH1D*>(fWeightsList->FindObject("eta_weights"));
3306    if(fEtaWeights->GetBinWidth(1) != fEtaBinWidth)
3307    {
3308     cout<<"WARNING: fEtaWeights->GetBinWidth(1) != fEtaBinWidth in AFAWQC::BAFWH() !!!!        "<<endl;
3309     cout<<"         This indicates insconsistent binning in eta histograms throughout the code."<<endl;
3310     exit(0);
3311    }
3312   } else 
3313     {
3314      cout<<"WARNING: fUseEtaWeights && fWeightsList->FindObject(\"eta_weights\") is NULL in AFAWQC::BAFWH() !!!!"<<endl;
3315      exit(0);
3316     }
3317  } // end of if(fUseEtaWeights)
3318  
3319 } // end of AliFlowAnalysisWithQCumulants::BookAndFillWeightsHistograms()
3320
3321
3322 //================================================================================================================================
3323
3324
3325 void AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
3326 {
3327  // book all objects for integrated flow 
3328  
3329  // a) common;
3330  // b) profiles;
3331  // c) results;
3332  
3333  // ****************
3334  // **** COMMON ****
3335  // **************** 
3336
3337  // Re[Q_{m*n,k}], Im[Q_{m*n,k}] and S_{p,k}^M: 
3338  fReQ  = new TMatrixD(4,9);
3339  fImQ  = new TMatrixD(4,9);
3340  fSMpk = new TMatrixD(8,9);
3341  
3342  // profile to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
3343  fAvMultiplicity = new TProfile("fAvMultiplicity","Average Multiplicities of RPs",9,0,9);
3344  fAvMultiplicity->SetTickLength(-0.01,"Y");
3345  fAvMultiplicity->SetMarkerStyle(25);
3346  fAvMultiplicity->SetLabelSize(0.05);
3347  fAvMultiplicity->SetLabelOffset(0.02,"Y");
3348  fAvMultiplicity->SetYTitle("Average Multiplicity");
3349  (fAvMultiplicity->GetXaxis())->SetBinLabel(1,"all evts");
3350  (fAvMultiplicity->GetXaxis())->SetBinLabel(2,"n_{RP} #geq 1");
3351  (fAvMultiplicity->GetXaxis())->SetBinLabel(3,"n_{RP} #geq 2");
3352  (fAvMultiplicity->GetXaxis())->SetBinLabel(4,"n_{RP} #geq 3");
3353  (fAvMultiplicity->GetXaxis())->SetBinLabel(5,"n_{RP} #geq 4");
3354  (fAvMultiplicity->GetXaxis())->SetBinLabel(6,"n_{RP} #geq 5");
3355  (fAvMultiplicity->GetXaxis())->SetBinLabel(7,"n_{RP} #geq 6");
3356  (fAvMultiplicity->GetXaxis())->SetBinLabel(8,"n_{RP} #geq 7");
3357  (fAvMultiplicity->GetXaxis())->SetBinLabel(9,"n_{RP} #geq 8");
3358  fIntFlowProfiles->Add(fAvMultiplicity);
3359   
3360  TString pWeightsFlag[2] = {"pWeights not used","pWeights used"};
3361  TString eWeightsFlag[2] = {"exact eWeights","non-exact eWeights"};
3362  TString nuaFlag[2] = {"not corrected","corrected"};
3363  TString sinCosFlag[2] = {"sin","cos"};
3364  TString powerFlag[2] = {"linear","quadratic"};
3365   
3366  for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++)
3367  {
3368   // ***************
3369   // **** E-B-E ****
3370   // ***************
3371   
3372   // average multiparticle correlations for single event calculated from Q-vectors
3373   // (Remark: binning is organized in the same way as in fQCorrelations[pW][eW] bellow):   
3374   fQCorrelationsEBE[pW] = new TH1D(Form("fQCorrelationsEBE: %s",pWeightsFlag[pW].Data()),Form("Average multi-particle correlations for single event calculated from Q-vectors (%s)",pWeightsFlag[pW].Data()),32,0,32);
3375   
3376   for(Int_t sc=0;sc<2;sc++)
3377   {
3378    // correction terms for non-uniform acceptance for single event calculated from Q-vectors
3379    // (Remark: binning is organized in the same way as in fQCorrections[pW][sc]):
3380    fQCorrectionsEBE[pW][sc] = new TH1D(Form("fQCorrectionsEBE: %s, %s terms",pWeightsFlag[pW].Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance for single event (%s, %s terms)",pWeightsFlag[pW].Data(),sinCosFlag[sc].Data()),10,0,10);  
3381   }
3382   
3383   for(Int_t eW=0;eW<2;eW++)
3384   {
3385    // ******************
3386    // **** PROFILES ****
3387    // ******************
3388   
3389    // final average multiparticle correlations for all events calculated from Q-vectors:
3390    fQCorrelations[pW][eW] = new TProfile(Form("fQCorrelations: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),Form("Final average multi-particle correlations calculated from Q-vectors (%s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),32,0,32,"s");
3391    fQCorrelations[pW][eW]->SetTickLength(-0.01,"Y");
3392    fQCorrelations[pW][eW]->SetMarkerStyle(25);
3393    fQCorrelations[pW][eW]->SetLabelSize(0.03);
3394    fQCorrelations[pW][eW]->SetLabelOffset(0.01,"Y");
3395    // 2-p correlations:
3396    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
3397    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
3398    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
3399    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
3400    // 3-p correlations:
3401    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
3402    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
3403    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
3404    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
3405    // 4-p correlations:
3406    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
3407    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
3408    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
3409    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
3410    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
3411    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
3412    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
3413    // 5-p correlations:
3414    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
3415    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
3416    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
3417    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
3418    // 6-p correlations:
3419    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
3420    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
3421    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
3422    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
3423    // 7-p correlations:
3424    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
3425    // 8-p correlations:
3426    (fQCorrelations[pW][eW]->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
3427    // add fQCorrelations[0] to the list fIntFlowList:
3428    fIntFlowProfiles->Add(fQCorrelations[pW][eW]);
3429   
3430    // averages <<2><4>>, <<2><6>>, <<4><6>>, etc,  needed to calculate covariances:
3431    fQProducts[pW][eW] = new TProfile(Form("fQProducts: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),Form("Averages of products (%s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),6,0,6);
3432    fQProducts[pW][eW]->SetTickLength(-0.01,"Y");
3433    fQProducts[pW][eW]->SetMarkerStyle(25);
3434    fQProducts[pW][eW]->SetLabelSize(0.05);
3435    fQProducts[pW][eW]->SetLabelOffset(0.01,"Y");
3436    (fQProducts[pW][eW]->GetXaxis())->SetBinLabel(1,"<<2><4>>");
3437    (fQProducts[pW][eW]->GetXaxis())->SetBinLabel(2,"<<2><6>>");
3438    (fQProducts[pW][eW]->GetXaxis())->SetBinLabel(3,"<<2><8>>");
3439    (fQProducts[pW][eW]->GetXaxis())->SetBinLabel(4,"<<4><6>>");
3440    (fQProducts[pW][eW]->GetXaxis())->SetBinLabel(5,"<<4><8>>");
3441    (fQProducts[pW][eW]->GetXaxis())->SetBinLabel(6,"<<6><8>>");
3442    fIntFlowProfiles->Add(fQProducts[pW][eW]);
3443  
3444    for(Int_t sc=0;sc<2;sc++)
3445    {
3446     // final average correction terms for non-uniform acceptance calculated from Q-vectors: 
3447     fQCorrections[pW][eW][sc] = new TProfile(Form("fQCorrections: %s, %s, %s terms",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),sinCosFlag[sc].Data()),Form("Correction terms for non-uniform acceptance (%s, %s, %s terms)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),sinCosFlag[sc].Data()),10,0,10,"s");
3448     fQCorrections[pW][eW][sc]->SetTickLength(-0.01,"Y");
3449     fQCorrections[pW][eW][sc]->SetMarkerStyle(25);
3450     fQCorrections[pW][eW][sc]->SetLabelSize(0.03);
3451     fQCorrections[pW][eW][sc]->SetLabelOffset(0.01,"Y");
3452     // ......................................................................... 
3453     // 1-p terms:
3454     (fQCorrections[pW][eW][sc]->GetXaxis())->SetBinLabel(1,Form("%s(n(#phi_{1}))>",sinCosFlag[sc].Data()));
3455     // 2-p terms:
3456     // 3-p terms:
3457     // ...
3458     // ......................................................................... 
3459     // add fQCorrectionsCos to the list fIntFlowList:
3460     fIntFlowProfiles->Add(fQCorrections[pW][eW][sc]);
3461    } // end of for(Int_t sc=0;sc<2;sc++) 
3462   
3463    // *****************
3464    // **** RESULTS ****
3465    // *****************
3466   
3467    // final results for average multi-particle correlations with correct statistical errors:
3468    fCorrelations[pW][eW] = new TH1D(Form("fCorrelations: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),Form("Average multi-particle correlations (%s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),32,0,32);
3469    fCorrelations[pW][eW]->SetTickLength(-0.01,"Y");
3470    fCorrelations[pW][eW]->SetMarkerStyle(25);
3471    fCorrelations[pW][eW]->SetLabelSize(0.03);
3472    fCorrelations[pW][eW]->SetLabelOffset(0.01,"Y");
3473    // 2-p correlations:
3474    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(1,"<<2>>_{n|n}");
3475    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(2,"<<2>>_{2n|2n}");
3476    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(3,"<<2>>_{3n|3n}");
3477    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(4,"<<2>>_{4n|4n}");
3478    // 3-p correlations:
3479    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(6,"<<3>>_{2n|n,n}");
3480    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(7,"<<3>>_{3n|2n,n}");
3481    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(8,"<<3>>_{4n|2n,2n}");
3482    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(9,"<<3>>_{4n|3n,n}");
3483    // 4-p correlations:
3484    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(11,"<<4>>_{n,n|n,n}"); 
3485    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(12,"<<4>>_{2n,n|2n,n}");
3486    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(13,"<<4>>_{2n,2n|2n,2n}");
3487    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(14,"<<4>>_{3n|n,n,n}");
3488    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(15,"<<4>>_{3n,n|3n,n}");
3489    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(16,"<<4>>_{3n,n|2n,2n}"); 
3490    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(17,"<<4>>_{4n|2n,n,n}");
3491    // 5-p correlations:
3492    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(19,"<<5>>_{2n|n,n,n,n}"); 
3493    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(20,"<<5>>_{2n,2n|2n,n,n}");
3494    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(21,"<<5>>_{3n,n|2n,n,n}");
3495    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(22,"<<5>>_{4n|n,n,n,n}");
3496    // 6-p correlations:
3497    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(24,"<<6>>_{n,n,n|n,n,n}");
3498    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(25,"<<6>>_{2n,n,n|2n,n,n}");
3499    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(26,"<<6>>_{2n,2n|n,n,n,n}");
3500    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(27,"<<6>>_{3n,n|n,n,n,n}");
3501    // 7-p correlations:
3502    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(29,"<<7>>_{2n,n,n|n,n,n,n}");
3503    // 8-p correlations:
3504    (fCorrelations[pW][eW]->GetXaxis())->SetBinLabel(31,"<<8>>_{n,n,n,n|n,n,n,n}");
3505    // add fCorrelations to the list fIntFlowList:
3506    fIntFlowResults->Add(fCorrelations[pW][eW]);
3507  
3508    // final corrections for non-uniform acceptance for QC{2}, QC{4}, QC{6} and QC{8}:
3509    fCorrections[pW][eW] = new TH1D(Form("fCorrections: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),Form("Corrections for non-uniform acceptance for Q-cumulants (%s, %s)",eWeightsFlag[eW].Data()),4,0,4);
3510    fCorrections[pW][eW]->SetLabelSize(0.05);
3511    fCorrections[pW][eW]->SetMarkerStyle(25);
3512    (fCorrections[pW][eW]->GetXaxis())->SetBinLabel(1,"corr. for QC{2}");
3513    (fCorrections[pW][eW]->GetXaxis())->SetBinLabel(2,"corr. for QC{4}");
3514    (fCorrections[pW][eW]->GetXaxis())->SetBinLabel(3,"corr. for QC{6}");
3515    (fCorrections[pW][eW]->GetXaxis())->SetBinLabel(4,"corr. for QC{8}");
3516    // add fCorrections[pW] to list fIntFlowResults: 
3517    fIntFlowResults->Add(fCorrections[pW][eW]);
3518   
3519    // final results for covariances:
3520    fCovariances[pW][eW] = new TH1D(Form("fCovariances: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),Form("Covariances (%s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),6,0,6);
3521    fCovariances[pW][eW]->SetLabelSize(0.05);
3522    fCovariances[pW][eW]->SetMarkerStyle(25);
3523    (fCovariances[pW][eW]->GetXaxis())->SetBinLabel(1,"Cov(2,4)");
3524    (fCovariances[pW][eW]->GetXaxis())->SetBinLabel(2,"Cov(2,6)");
3525    (fCovariances[pW][eW]->GetXaxis())->SetBinLabel(3,"Cov(2,8)");
3526    (fCovariances[pW][eW]->GetXaxis())->SetBinLabel(4,"Cov(4,6)");
3527    (fCovariances[pW][eW]->GetXaxis())->SetBinLabel(5,"Cov(4,8)");
3528    (fCovariances[pW][eW]->GetXaxis())->SetBinLabel(6,"Cov(6,8)");
3529    // add fCovariances[pW][eW] to list fIntFlowResults: 
3530    fIntFlowResults->Add(fCovariances[pW][eW]);
3531   
3532    // final results for sum of event weights:
3533    for(Int_t power=0;power<2;power++)
3534    {
3535     fSumOfEventWeights[pW][eW][power] = new TH1D(Form("fSumOfEventWeights: %s, %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),powerFlag[power].Data()),Form("SumOfEventWeights (%s, %s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),powerFlag[power].Data()),4,0,4);
3536     fSumOfEventWeights[pW][eW][power]->SetLabelSize(0.05);
3537     fSumOfEventWeights[pW][eW][power]->SetMarkerStyle(25);
3538     (fSumOfEventWeights[pW][eW][power]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>}");
3539     (fSumOfEventWeights[pW][eW][power]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<4>}");
3540     (fSumOfEventWeights[pW][eW][power]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<6>}");
3541     (fSumOfEventWeights[pW][eW][power]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<8>}");
3542     // add fSumOfEventWeights[pW][eW] to list fIntFlowResults: 
3543     fIntFlowResults->Add(fSumOfEventWeights[pW][eW][power]);
3544    } 
3545    
3546    // final results for sum of product of event weights:
3547    fProductOfEventWeights[pW][eW] = new TH1D(Form("fProductOfEventWeights: %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),Form("ProductOfEventWeights (%s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()),6,0,6);
3548    fProductOfEventWeights[pW][eW]->SetLabelSize(0.05);
3549    fProductOfEventWeights[pW][eW]->SetMarkerStyle(25);
3550    (fProductOfEventWeights[pW][eW]->GetXaxis())->SetBinLabel(1,"#sum_{i=1}^{N} w_{<2>} w_{<4>}");
3551    (fProductOfEventWeights[pW][eW]->GetXaxis())->SetBinLabel(2,"#sum_{i=1}^{N} w_{<2>} w_{<6>}");
3552    (fProductOfEventWeights[pW][eW]->GetXaxis())->SetBinLabel(3,"#sum_{i=1}^{N} w_{<2>} w_{<8>}");
3553    (fProductOfEventWeights[pW][eW]->GetXaxis())->SetBinLabel(4,"#sum_{i=1}^{N} w_{<4>} w_{<6>}");
3554    (fProductOfEventWeights[pW][eW]->GetXaxis())->SetBinLabel(5,"#sum_{i=1}^{N} w_{<4>} w_{<8>}");
3555    (fProductOfEventWeights[pW][eW]->GetXaxis())->SetBinLabel(6,"#sum_{i=1}^{N} w_{<6>} w_{<8>}");
3556    // add fProductOfEventWeights[pW][eW] to list fIntFlowResults: 
3557    fIntFlowResults->Add(fProductOfEventWeights[pW][eW]);
3558
3559    for(Int_t nua=0;nua<2;nua++)
3560    {
3561     // integrated Q-cumulants:
3562     fCumulants[pW][eW][nua] = new TH1D(Form("fCumulants: %s, %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data()),Form("Q-cumulants (%s, %s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data()),4,0,4);
3563     fCumulants[pW][eW][nua]->SetLabelSize(0.05);
3564     fCumulants[pW][eW][nua]->SetMarkerStyle(25);
3565     (fCumulants[pW][eW][nua]->GetXaxis())->SetBinLabel(1,"QC{2}");
3566     (fCumulants[pW][eW][nua]->GetXaxis())->SetBinLabel(2,"QC{4}");
3567     (fCumulants[pW][eW][nua]->GetXaxis())->SetBinLabel(3,"QC{6}");
3568     (fCumulants[pW][eW][nua]->GetXaxis())->SetBinLabel(4,"QC{8}");
3569     // add fCumulants[pW][nua] to list fIntFlowResults: 
3570     fIntFlowResults->Add(fCumulants[pW][eW][nua]);
3571    
3572     // integrated flow from Q-cumulants:
3573     fIntFlow[pW][eW][nua] = new TH1D(Form("fIntFlow: %s, %s, %s",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data()),Form("Integrated flow from Q-cumulants (%s, %s, %s)",pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data()),4,0,4);
3574     fIntFlow[pW][eW][nua]->SetLabelSize(0.05);
3575     fIntFlow[pW][eW][nua]->SetMarkerStyle(25);
3576     (fIntFlow[pW][eW][nua]->GetXaxis())->SetBinLabel(1,"v_{2}{2,QC}");
3577     (fIntFlow[pW][eW][nua]->GetXaxis())->SetBinLabel(2,"v_{2}{4,QC}");
3578     (fIntFlow[pW][eW][nua]->GetXaxis())->SetBinLabel(3,"v_{2}{6,QC}");
3579     (fIntFlow[pW][eW][nua]->GetXaxis())->SetBinLabel(4,"v_{2}{8,QC}");
3580     // add fIntFlow[pW][nua] to list fIntFlowResults: 
3581     fIntFlowResults->Add(fIntFlow[pW][eW][nua]);
3582    
3583    } // end of for(Int_t nua=0;nua<2;nua++)
3584   } // end of for(Int_t eW=0;eW<2;eW++)
3585  } // end of for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++)
3586   
3587
3588
3589  /*
3590   // final average weighted multi-particle correlations for all events calculated from Q-vectors
3591   fQCorrelations[1] = new TProfile("Weighted correlations","final average multi-particle correlations from weighted Q-vectors",200,0,200,"s");
3592   fQCorrelations[1]->SetTickLength(-0.01,"Y");
3593   fQCorrelations[1]->SetMarkerStyle(25);
3594   fQCorrelations[1]->SetLabelSize(0.03);
3595   fQCorrelations[1]->SetLabelOffset(0.01,"Y");
3596   // 2-particle correlations:
3597   (fQCorrelations[1]->GetXaxis())->SetBinLabel(1,"<w_{1}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
3598   (fQCorrelations[1]->GetXaxis())->SetBinLabel(2,"<w_{1}^{2}w_{2}^{2}cos(2n(#phi_{1}-#phi_{2}))>");
3599   (fQCorrelations[1]->GetXaxis())->SetBinLabel(3,"<w_{1}^{3}w_{2}^{3}cos(3n(#phi_{1}-#phi_{2}))>");
3600   (fQCorrelations[1]->GetXaxis())->SetBinLabel(4,"<w_{1}^{4}w_{2}^{4}cos(4n(#phi_{1}-#phi_{2}))>");
3601   (fQCorrelations[1]->GetXaxis())->SetBinLabel(5,"<w_{1}^{3}w_{2}cos(n(#phi_{1}-#phi_{2}))>");
3602   (fQCorrelations[1]->GetXaxis())->SetBinLabel(6,"<w_{1}^{2}w_{2}w_{3}cos(n(#phi_{1}-#phi_{2}))>");
3603   // 3-particle correlations:
3604   (fQCorrelations[1]->GetXaxis())->SetBinLabel(21,"<w_{1}w_{2}w_{3}^{2}cos(n(2#phi_{1}-#phi_{2}-#phi_{3}))>");
3605   // 4-particle correlations:
3606   (fQCorrelations[1]->GetXaxis())->SetBinLabel(41,"<w_{1}w_{2}w_{3}w_{4}cos(n(#phi_{1}+#phi_{2}-#phi_{3}-#phi_{4}))>");
3607   // add fQCorrelations[1] to the list fIntFlowList:
3608   fIntFlowList->Add(fQCorrelations[1]); 
3609  */
3610   
3611  
3612 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForIntegratedFlow()
3613
3614
3615 //================================================================================================================================
3616
3617
3618 void AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
3619 {
3620  // book all profiles relevant for calculations with nested loops
3621  
3622  fEvaluateNestedLoops = new TProfile("fEvaluateNestedLoops","1 = evaluate, 0 = do not evaluate",2,0,2);
3623  fEvaluateNestedLoops->SetLabelSize(0.05);
3624  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(1,"Nested Loops (Int. Flow)");
3625  (fEvaluateNestedLoops->GetXaxis())->SetBinLabel(2,"Nested Loops (Diff. Flow)");
3626  fEvaluateNestedLoops->Fill(0.5,(Int_t)fEvaluateNestedLoopsForIntFlow);
3627  fEvaluateNestedLoops->Fill(1.5,(Int_t)fEvaluateNestedLoopsForDiffFlow);
3628  // add fEvaluateNestedLoops to the list fNestedLoopsList:
3629  fNestedLoopsList->Add(fEvaluateNestedLoops);
3630  
3631  if(fEvaluateNestedLoopsForIntFlow)
3632  {
3633   fDirectCorrelations = new TProfile("fDirectCorrelations","multi-particle correlations with nested loops",100,0,100,"s");
3634   fNestedLoopsList->Add(fDirectCorrelations);
3635   fDirectCorrectionsCos = new TProfile("fDirectCorrectionsCos"," corrections for non-uniform acceptance (cos terms)",100,0,100,"s");
3636   fNestedLoopsList->Add(fDirectCorrectionsCos);
3637   fDirectCorrectionsSin = new TProfile("fDirectCorrectionsSin"," corrections for non-uniform acceptance (sin terms)",100,0,100,"s");
3638   fNestedLoopsList->Add(fDirectCorrectionsSin); 
3639   if(fUsePhiWeights) // Remark: cross-checking performed only with phi-weights (this is sufficient)
3640   {
3641    fDirectCorrelationsW = new TProfile("fDirectCorrelationsW","multi-particle correlations with nested loops",200,0,200,"s"); 
3642    fNestedLoopsList->Add(fDirectCorrelationsW);
3643    fDirectCorrectionsCosW = new TProfile("fDirectCorrectionsCosW"," corrections for non-uniform acceptance (cos terms)",100,0,100,"s");
3644    fNestedLoopsList->Add(fDirectCorrectionsCosW);
3645    fDirectCorrectionsSinW = new TProfile("fDirectCorrectionsSinW"," corrections for non-uniform acceptance (sin terms)",100,0,100,"s");
3646    fNestedLoopsList->Add(fDirectCorrectionsSinW); 
3647   }
3648  }
3649  
3650  if(fEvaluateNestedLoopsForDiffFlow)
3651  {
3652   fDirectCorrelationsDiffFlow = new TProfile("fDirectCorrelationsDiffFlow","multi-particle correlations with nested loops",200,0,200,"s");
3653   fNestedLoopsList->Add(fDirectCorrelationsDiffFlow); 
3654   fDirectCorrectionsDiffFlowCos = new TProfile("fDirectCorrectionsDiffFlowCos",
3655                                                "corrections for non-uniform acceptance (cos terms) with nested loops",200,0,200,"s");
3656   fNestedLoopsList->Add(fDirectCorrectionsDiffFlowCos);   
3657   fDirectCorrectionsDiffFlowSin = new TProfile("fDirectCorrectionsDiffFlowSin",
3658                                                "corrections for non-uniform acceptance (sin terms) with nested loops",200,0,200,"s");
3659   fNestedLoopsList->Add(fDirectCorrectionsDiffFlowSin);           
3660   if(fUsePhiWeights) // Remark: cross-checking performed only with phi-weights (this is sufficient)
3661   {
3662    fDirectCorrelationsDiffFlowW = new TProfile("fDirectCorrelationsDiffFlowW","multi-particle correlations with nested loops",200,0,200,"s");
3663    fNestedLoopsList->Add(fDirectCorrelationsDiffFlowW);
3664    fDirectCorrectionsDiffFlowCosW = new TProfile("fDirectCorrectionsDiffFlowCosW",
3665                                                "corrections for non-uniform acceptance (cos terms) with nested loops",200,0,200,"s");
3666    fNestedLoopsList->Add(fDirectCorrectionsDiffFlowCosW);   
3667    fDirectCorrectionsDiffFlowSinW = new TProfile("fDirectCorrectionsDiffFlowSinW",
3668                                                "corrections for non-uniform acceptance (sin terms) with nested loops",200,0,200,"s");
3669    fNestedLoopsList->Add(fDirectCorrectionsDiffFlowSinW);   
3670   }
3671  }
3672  
3673 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForNestedLoops()
3674
3675
3676 //================================================================================================================================
3677
3678
3679 void AliFlowAnalysisWithQCumulants::CalculateCorrelationsForIntegratedFlow()
3680 {
3681  // calculate all correlations needed for integrated flow
3682  
3683  // multiplicity:
3684  Double_t dMult = (*fSMpk)(0,0);
3685  
3686  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
3687  Double_t dReQ1n = (*fReQ)(0,0);
3688  Double_t dReQ2n = (*fReQ)(1,0);
3689  Double_t dReQ3n = (*fReQ)(2,0);
3690  Double_t dReQ4n = (*fReQ)(3,0);
3691  Double_t dImQ1n = (*fImQ)(0,0);
3692  Double_t dImQ2n = (*fImQ)(1,0);
3693  Double_t dImQ3n = (*fImQ)(2,0);
3694  Double_t dImQ4n = (*fImQ)(3,0);
3695   
3696  // real and imaginary parts of some expressions involving various combinations of Q-vectors evaluated in harmonics n, 2n, 3n and 4n:
3697  // (these expression appear in the Eqs. for the multi-particle correlations bellow)
3698  
3699  // Re[Q_{2n} Q_{n}^* Q_{n}^*]
3700  Double_t reQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dReQ2n + 2.*dReQ1n*dImQ1n*dImQ2n - pow(dImQ1n,2.)*dReQ2n; 
3701  
3702  // Im[Q_{2n} Q_{n}^* Q_{n}^*]
3703  //Double_t imQ2nQ1nstarQ1nstar = pow(dReQ1n,2.)*dImQ2n-2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n; 
3704  
3705  // Re[Q_{n} Q_{n} Q_{2n}^*] = Re[Q_{2n} Q_{n}^* Q_{n}^*]
3706  Double_t reQ1nQ1nQ2nstar = reQ2nQ1nstarQ1nstar; 
3707  
3708  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
3709  Double_t reQ3nQ1nQ2nstarQ2nstar = (pow(dReQ2n,2.)-pow(dImQ2n,2.))*(dReQ3n*dReQ1n-dImQ3n*dImQ1n) 
3710                                  + 2.*dReQ2n*dImQ2n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
3711
3712  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]                                                                  
3713  //Double_t imQ3nQ1nQ2nstarQ2nstar = calculate and implement this (deleteMe)
3714   
3715  // Re[Q_{2n} Q_{2n} Q_{3n}^* Q_{1n}^*] = Re[Q_{3n} Q_{n} Q_{2n}^* Q_{2n}^*]
3716  Double_t reQ2nQ2nQ3nstarQ1nstar = reQ3nQ1nQ2nstarQ2nstar;
3717   
3718  // Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
3719  Double_t reQ4nQ2nstarQ2nstar = pow(dReQ2n,2.)*dReQ4n+2.*dReQ2n*dImQ2n*dImQ4n-pow(dImQ2n,2.)*dReQ4n;
3720
3721  // Im[Q_{4n} Q_{2n}^* Q_{2n}^*]
3722  //Double_t imQ4nQ2nstarQ2nstar = calculate and implement this (deleteMe)
3723  
3724  // Re[Q_{2n} Q_{2n} Q_{4n}^*] =  Re[Q_{4n} Q_{2n}^* Q_{2n}^*]
3725  Double_t reQ2nQ2nQ4nstar = reQ4nQ2nstarQ2nstar;
3726  
3727  // Re[Q_{4n} Q_{3n}^* Q_{n}^*]
3728  Double_t reQ4nQ3nstarQ1nstar = dReQ4n*(dReQ3n*dReQ1n-dImQ3n*dImQ1n)+dImQ4n*(dReQ3n*dImQ1n+dImQ3n*dReQ1n);
3729  
3730  // Re[Q_{3n} Q_{n} Q_{4n}^*] = Re[Q_{4n} Q_{3n}^* Q_{n}^*]
3731  Double_t reQ3nQ1nQ4nstar = reQ4nQ3nstarQ1nstar;
3732  
3733  // Im[Q_{4n} Q_{3n}^* Q_{n}^*]
3734  //Double_t imQ4nQ3nstarQ1nstar = calculate and implement this (deleteMe)
3735
3736  // Re[Q_{3n} Q_{2n}^* Q_{n}^*]
3737  Double_t reQ3nQ2nstarQ1nstar = dReQ3n*dReQ2n*dReQ1n-dReQ3n*dImQ2n*dImQ1n+dImQ3n*dReQ2n*dImQ1n
3738                               + dImQ3n*dImQ2n*dReQ1n;
3739                               
3740  // Re[Q_{2n} Q_{n} Q_{3n}^*] = Re[Q_{3n} Q_{2n}^* Q_{n}^*]
3741  Double_t reQ2nQ1nQ3nstar = reQ3nQ2nstarQ1nstar;
3742  
3743  // Im[Q_{3n} Q_{2n}^* Q_{n}^*]
3744  //Double_t imQ3nQ2nstarQ1nstar; //calculate and implement this (deleteMe)
3745  
3746  // Re[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
3747  Double_t reQ3nQ1nstarQ1nstarQ1nstar = dReQ3n*pow(dReQ1n,3)-3.*dReQ1n*dReQ3n*pow(dImQ1n,2)
3748                                      + 3.*dImQ1n*dImQ3n*pow(dReQ1n,2)-dImQ3n*pow(dImQ1n,3);
3749
3750  // Im[Q_{3n} Q_{n}^* Q_{n}^* Q_{n}^*]
3751  //Double_t imQ3nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
3752  
3753  // |Q_{2n}|^2 |Q_{n}|^2
3754  Double_t dQ2nQ1nQ2nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.));
3755  
3756  // Re[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
3757  Double_t reQ4nQ2nstarQ1nstarQ1nstar = (dReQ4n*dReQ2n+dImQ4n*dImQ2n)*(pow(dReQ1n,2)-pow(dImQ1n,2))
3758                                      + 2.*dReQ1n*dImQ1n*(dImQ4n*dReQ2n-dReQ4n*dImQ2n); 
3759  
3760  // Im[Q_{4n} Q_{2n}^* Q_{n}^* Q_{n}^*]
3761  //Double_t imQ4nQ2nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
3762  
3763  // Re[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*]
3764  Double_t reQ2nQ1nQ1nstarQ1nstarQ1nstar = (dReQ2n*dReQ1n-dImQ2n*dImQ1n)*(pow(dReQ1n,3)-3.*dReQ1n*pow(dImQ1n,2))
3765                                         + (dReQ2n*dImQ1n+dReQ1n*dImQ2n)*(3.*dImQ1n*pow(dReQ1n,2)-pow(dImQ1n,3));
3766
3767  // Im[Q_{2n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^*] 
3768  //Double_t imQ2nQ1nQ1nstarQ1nstarQ1nstar; //calculate and implement this (deleteMe)
3769  
3770  // Re[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
3771  Double_t reQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
3772                                         * (dReQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) + 2.*dImQ2n*dReQ1n*dImQ1n);
3773
3774  // Im[Q_{2n} Q_{2n} Q_{2n}^* Q_{n}^* Q_{n}^*]
3775  //Double_t imQ2nQ2nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))
3776  //                                       * (dImQ2n*(pow(dReQ1n,2.)-pow(dImQ1n,2.)) - 2.*dReQ2n*dReQ1n*dImQ1n);
3777  
3778  // Re[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
3779  Double_t reQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dReQ4n-6.*pow(dReQ1n,2.)*dReQ4n*pow(dImQ1n,2.)
3780                                             + pow(dImQ1n,4.)*dReQ4n+4.*pow(dReQ1n,3.)*dImQ1n*dImQ4n
3781                                             - 4.*pow(dImQ1n,3.)*dReQ1n*dImQ4n;
3782                                             
3783  // Im[Q_{4n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
3784  //Double_t imQ4nQ1nstarQ1nstarQ1nstarQ1nstar = pow(dReQ1n,4.)*dImQ4n-6.*pow(dReQ1n,2.)*dImQ4n*pow(dImQ1n,2.)
3785  //                                           + pow(dImQ1n,4.)*dImQ4n+4.*pow(dImQ1n,3.)*dReQ1n*dReQ4n
3786  //                                           - 4.*pow(dReQ1n,3.)*dImQ1n*dReQ4n;
3787  
3788  // Re[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
3789  Double_t reQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
3790                                         * (dReQ1n*dReQ2n*dReQ3n-dReQ3n*dImQ1n*dImQ2n+dReQ2n*dImQ1n*dImQ3n+dReQ1n*dImQ2n*dImQ3n);
3791  
3792  // Im[Q_{3n} Q_{n} Q_{2n}^* Q_{n}^* Q_{n}^*]
3793  //Double_t imQ3nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
3794  //                                       * (-dReQ2n*dReQ3n*dImQ1n-dReQ1n*dReQ3n*dImQ2n+dReQ1n*dReQ2n*dImQ3n-dImQ1n*dImQ2n*dImQ3n);
3795  
3796  
3797  // Re[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
3798  Double_t reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)*dReQ2n-2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
3799                                                + dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n-pow(dImQ1n,2.)*dImQ2n)
3800                                                * (pow(dReQ1n,2.)*dReQ2n+2.*dReQ1n*dReQ2n*dImQ1n-dReQ2n*pow(dImQ1n,2.)
3801                                                - dImQ2n*pow(dReQ1n,2.)+2.*dReQ1n*dImQ1n*dImQ2n+pow(dImQ1n,2.)*dImQ2n);
3802  
3803  // Im[Q_{2n} Q_{2n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
3804  //Double_t imQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar = 2.*(pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
3805  //                                              + 2.*dReQ1n*dImQ1n*dImQ2n)*(pow(dReQ1n,2.)*dImQ2n
3806  //                                              - 2.*dReQ1n*dImQ1n*dReQ2n-pow(dImQ1n,2.)*dImQ2n);
3807  
3808  // Re[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
3809  Double_t reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
3810                                                * (pow(dReQ1n,3.)*dReQ3n-3.*dReQ1n*dReQ3n*pow(dImQ1n,2.)
3811                                                + 3.*pow(dReQ1n,2.)*dImQ1n*dImQ3n-pow(dImQ1n,3.)*dImQ3n);
3812   
3813  // Im[Q_{3n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                                                           
3814  //Double_t imQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = (pow(dReQ1n,2.)+pow(dImQ1n,2.))
3815  //                                              * (pow(dImQ1n,3.)*dReQ3n-3.*dImQ1n*dReQ3n*pow(dReQ1n,2.)
3816  //                                              - 3.*pow(dImQ1n,2.)*dReQ1n*dImQ3n+pow(dReQ1n,3.)*dImQ3n);
3817  
3818  // |Q_{2n}|^2 |Q_{n}|^4
3819  Double_t dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar = (pow(dReQ2n,2.)+pow(dImQ2n,2.))*pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.);
3820  
3821  // Re[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]
3822  Double_t reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3823                                                   * (pow(dReQ1n,2.)*dReQ2n-dReQ2n*pow(dImQ1n,2.)
3824                                                   + 2.*dReQ1n*dImQ1n*dImQ2n);
3825                                                   
3826  // Im[Q_{2n} Q_{n} Q_{n} Q_{n}^* Q_{n}^* Q_{n}^* Q_{n}^*]                                                  
3827  //Double_t imQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar = pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
3828  //                                                 * (pow(dReQ1n,2.)*dImQ2n-dImQ2n*pow(dImQ1n,2.)
3829  //                                                 - 2.*dReQ1n*dReQ2n*dImQ1n);
3830  
3831   
3832  
3833        
3834  //                                        **************************************
3835  //                                        **** multi-particle correlations: ****
3836  //                                        **************************************
3837  //
3838  // Remark 1: multi-particle correlations calculated with non-weighted Q-vectors are stored in 1D profile fQCorrelations[0].
3839  // Remark 2: binning of fQCorrelations[0] is organized as follows:
3840  // --------------------------------------------------------------------------------------------------------------------
3841  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
3842  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
3843  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
3844  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
3845  //  5th bin:           ----  EMPTY ----
3846  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
3847  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
3848  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
3849  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
3850  // 10th bin:           ----  EMPTY ----
3851  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
3852  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
3853  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
3854  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
3855  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
3856  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
3857  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
3858  // 18th bin:           ----  EMPTY ----
3859  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
3860  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
3861  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
3862  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
3863  // 23rd bin:           ----  EMPTY ----
3864  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
3865  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
3866  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
3867  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
3868  // 28th bin:           ----  EMPTY ----
3869  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
3870  // 30th bin:           ----  EMPTY ----
3871  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
3872  // --------------------------------------------------------------------------------------------------------------------
3873     
3874  // 2-particle:
3875  Double_t two1n1n = 0.; // <cos(n*(phi1-phi2))>
3876  Double_t two2n2n = 0.; // <cos(2n*(phi1-phi2))>
3877  Double_t two3n3n = 0.; // <cos(3n*(phi1-phi2))>
3878  Double_t two4n4n = 0.; // <cos(4n*(phi1-phi2))>
3879  
3880  if(dMult>1)
3881  {
3882   two1n1n = (pow(dReQ1n,2.)+pow(dImQ1n,2.)-dMult)/(dMult*(dMult-1.)); 
3883   two2n2n = (pow(dReQ2n,2.)+pow(dImQ2n,2.)-dMult)/(dMult*(dMult-1.)); 
3884   two3n3n = (pow(dReQ3n,2.)+pow(dImQ3n,2.)-dMult)/(dMult*(dMult-1.)); 
3885   two4n4n = (pow(dReQ4n,2.)+pow(dImQ4n,2.)-dMult)/(dMult*(dMult-1.)); 
3886   
3887   // average non-weighted 2-particle correlations for single event: 
3888   fQCorrelationsEBE[0]->SetBinContent(1,two1n1n);
3889   fQCorrelationsEBE[0]->SetBinContent(2,two2n2n);
3890   fQCorrelationsEBE[0]->SetBinContent(3,two3n3n);
3891   fQCorrelationsEBE[0]->SetBinContent(4,two4n4n);
3892         
3893   // final average non-weighted 2-particle correlations for all events:      
3894   fQCorrelations[0][0]->Fill(0.5,two1n1n,dMult*(dMult-1.));  
3895   fQCorrelations[0][0]->Fill(1.5,two2n2n,dMult*(dMult-1.)); 
3896   fQCorrelations[0][0]->Fill(2.5,two3n3n,dMult*(dMult-1.)); 
3897   fQCorrelations[0][0]->Fill(3.5,two4n4n,dMult*(dMult-1.)); 
3898   
3899   // distribution of <cos(n*(phi1-phi2))>:
3900   //f2pDistribution->Fill(two1n1n,dMult*(dMult-1.)); 
3901  } // end of if(dMult>1)
3902  
3903  // 3-particle:
3904  Double_t three2n1n1n = 0.; // <cos(n*(2.*phi1-phi2-phi3))>
3905  Double_t three3n2n1n = 0.; // <cos(n*(3.*phi1-2.*phi2-phi3))>
3906  Double_t three4n2n2n = 0.; // <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
3907  Double_t three4n3n1n = 0.; // <cos(n*(4.*phi1-3.*phi2-phi3))>
3908  
3909  if(dMult>2)
3910  {
3911   three2n1n1n = (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3912               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))+2.*dMult)
3913               / (dMult*(dMult-1.)*(dMult-2.));              
3914   three3n2n1n = (reQ3nQ2nstarQ1nstar-(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3915               - (pow(dReQ2n,2.)+pow(dImQ2n,2.))
3916               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3917               / (dMult*(dMult-1.)*(dMult-2.));
3918   three4n2n2n = (reQ4nQ2nstarQ2nstar-2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3919               - (pow(dReQ4n,2.)+pow(dImQ4n,2.))+2.*dMult)
3920               / (dMult*(dMult-1.)*(dMult-2.)); 
3921   three4n3n1n = (reQ4nQ3nstarQ1nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))
3922               - (pow(dReQ3n,2.)+pow(dImQ3n,2.))
3923               - (pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult)
3924               / (dMult*(dMult-1.)*(dMult-2.)); 
3925               
3926   // average non-weighted 3-particle correlations for single event: 
3927   fQCorrelationsEBE[0]->SetBinContent(6,three2n1n1n);
3928   fQCorrelationsEBE[0]->SetBinContent(7,three3n2n1n);
3929   fQCorrelationsEBE[0]->SetBinContent(8,three4n2n2n);
3930   fQCorrelationsEBE[0]->SetBinContent(9,three4n3n1n);
3931         
3932   // final average non-weighted 3-particle correlations for all events:                
3933   fQCorrelations[0][0]->Fill(5.5,three2n1n1n,dMult*(dMult-1.)*(dMult-2.)); 
3934   fQCorrelations[0][0]->Fill(6.5,three3n2n1n,dMult*(dMult-1.)*(dMult-2.));
3935   fQCorrelations[0][0]->Fill(7.5,three4n2n2n,dMult*(dMult-1.)*(dMult-2.)); 
3936   fQCorrelations[0][0]->Fill(8.5,three4n3n1n,dMult*(dMult-1.)*(dMult-2.));    
3937  } // end of if(dMult>2)
3938  
3939  // 4-particle:
3940  Double_t four1n1n1n1n = 0.; // <cos(n*(phi1+phi2-phi3-phi4))>
3941  Double_t four2n2n2n2n = 0.; // <cos(2.*n*(phi1+phi2-phi3-phi4))>
3942  Double_t four2n1n2n1n = 0.; // <cos(n*(2.*phi1+phi2-2.*phi3-phi4))> 
3943  Double_t four3n1n1n1n = 0.; // <cos(n*(3.*phi1-phi2-phi3-phi4))> 
3944  Double_t four4n2n1n1n = 0.; // <cos(n*(4.*phi1-2.*phi2-phi3-phi4))> 
3945  Double_t four3n1n2n2n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))> 
3946  Double_t four3n1n3n1n = 0.; // <cos(n*(3.*phi1+phi2-3.*phi3-phi4))>   
3947  
3948  if(dMult>3)
3949  {
3950   four1n1n1n1n = (2.*dMult*(dMult-3.)+pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ1n,2.)
3951                + pow(dImQ1n,2.))-2.*reQ2nQ1nstarQ1nstar+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
3952                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));     
3953   four2n2n2n2n = (2.*dMult*(dMult-3.)+pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)-4.*(dMult-2.)*(pow(dReQ2n,2.)
3954                + pow(dImQ2n,2.))-2.*reQ4nQ2nstarQ2nstar+(pow(dReQ4n,2.)+pow(dImQ4n,2.)))
3955                / (dMult*(dMult-1)*(dMult-2.)*(dMult-3.));
3956   four2n1n2n1n = (dQ2nQ1nQ2nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar-2.*reQ2nQ1nstarQ1nstar)
3957                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3958                - ((dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3959                + (dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
3960                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3961                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
3962   four3n1n1n1n = (reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar-3.*reQ2nQ1nstarQ1nstar)
3963                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3964                + (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
3965                + 6.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-6.*dMult)
3966                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3967   four4n2n1n1n = (reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar-2.*reQ3nQ2nstarQ1nstar)
3968                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3969                - (reQ2nQ1nstarQ1nstar-2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3970                - 3.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
3971                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3972                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
3973   four3n1n2n2n = (reQ3nQ1nQ2nstarQ2nstar-reQ4nQ2nstarQ2nstar-reQ3nQ1nQ4nstar-2.*reQ3nQ2nstarQ1nstar)
3974                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3975                - (2.*reQ1nQ1nQ2nstar-(pow(dReQ4n,2.)+pow(dImQ4n,2.))-2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3976                - 4.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))-4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
3977                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3978                - 6./((dMult-1.)*(dMult-2.)*(dMult-3.)); 
3979   four3n1n3n1n = ((pow(dReQ3n,2.)+pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
3980                - 2.*reQ4nQ3nstarQ1nstar-2.*reQ3nQ2nstarQ1nstar)
3981                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3982                + ((pow(dReQ4n,2.)+pow(dImQ4n,2.))-(dMult-4.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
3983                + (pow(dReQ2n,2.)+pow(dImQ2n,2.))-(dMult-4.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
3984                / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.))
3985                + (dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.));
3986                
3987   // average non-weighted 4-particle correlations for single event: 
3988   fQCorrelationsEBE[0]->SetBinContent(11,four1n1n1n1n);
3989   fQCorrelationsEBE[0]->SetBinContent(12,four2n1n2n1n);
3990   fQCorrelationsEBE[0]->SetBinContent(13,four2n2n2n2n);
3991   fQCorrelationsEBE[0]->SetBinContent(14,four3n1n1n1n);
3992   fQCorrelationsEBE[0]->SetBinContent(15,four3n1n3n1n);
3993   fQCorrelationsEBE[0]->SetBinContent(16,four3n1n2n2n);
3994   fQCorrelationsEBE[0]->SetBinContent(17,four4n2n1n1n);
3995         
3996   // final average non-weighted 4-particle correlations for all events:                
3997   fQCorrelations[0][0]->Fill(10.5,four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3998   fQCorrelations[0][0]->Fill(11.5,four2n1n2n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
3999   fQCorrelations[0][0]->Fill(12.5,four2n2n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
4000   fQCorrelations[0][0]->Fill(13.5,four3n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
4001   fQCorrelations[0][0]->Fill(14.5,four3n1n3n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
4002   fQCorrelations[0][0]->Fill(15.5,four3n1n2n2n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));  
4003   fQCorrelations[0][0]->Fill(16.5,four4n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
4004   
4005   // distribution of <cos(n*(phi1+phi2-phi3-phi4))>
4006   //f4pDistribution->Fill(four1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.));
4007   
4008  } // end of if(dMult>3)
4009
4010  // 5-particle:
4011  Double_t five2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
4012  Double_t five2n2n2n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
4013  Double_t five3n1n2n1n1n = 0.; // <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
4014  Double_t five4n1n1n1n1n = 0.; // <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
4015  
4016  if(dMult>4)
4017  {
4018   five2n1n1n1n1n = (reQ2nQ1nQ1nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar+6.*reQ3nQ2nstarQ1nstar)
4019                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4020                  - (reQ2nQ1nQ3nstar+3.*(dMult-6.)*reQ2nQ1nstarQ1nstar+3.*reQ1nQ1nQ2nstar)
4021                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4022                  - (2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
4023                  + 3.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))     
4024                  - 3.*(dMult-4.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
4025                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4026                  - 3.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
4027                  - 2.*(2*dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+2.*dMult*(dMult-4.))
4028                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
4029                  
4030   five2n2n2n1n1n = (reQ2nQ2nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-2.*reQ2nQ2nQ3nstarQ1nstar)
4031                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4032                  + 2.*(reQ4nQ2nstarQ2nstar+4.*reQ3nQ2nstarQ1nstar+reQ3nQ1nQ4nstar)
4033                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4034                  + (reQ2nQ2nQ4nstar-2.*(dMult-5.)*reQ2nQ1nstarQ1nstar+2.*reQ1nQ1nQ2nstar)
4035                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4036                  - (2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+4.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
4037                  + 1.*pow((pow(dReQ2n,2.)+pow(dImQ2n,2.)),2.)
4038                  - 2.*(3.*dMult-10.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
4039                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4040                  - (4.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
4041                  - 4.*(dMult-5.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.))+4.*dMult*(dMult-6.))
4042                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
4043
4044   five4n1n1n1n1n = (reQ4nQ1nstarQ1nstarQ1nstarQ1nstar-6.*reQ4nQ2nstarQ1nstarQ1nstar-4.*reQ3nQ1nstarQ1nstarQ1nstar)
4045                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4046                  + (8.*reQ4nQ3nstarQ1nstar+3.*reQ4nQ2nstarQ2nstar+12.*reQ3nQ2nstarQ1nstar+12.*reQ2nQ1nstarQ1nstar)
4047                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4048                  - (6.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))+8.*(pow(dReQ3n,2.)+pow(dImQ3n,2.))
4049                  + 12.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))+24.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))-24.*dMult)
4050                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
4051   
4052   five3n1n2n1n1n = (reQ3nQ1nQ2nstarQ1nstarQ1nstar-reQ4nQ2nstarQ1nstarQ1nstar-reQ3nQ1nstarQ1nstarQ1nstar)
4053                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4054                  - (reQ3nQ1nQ2nstarQ2nstar-3.*reQ4nQ3nstarQ1nstar-reQ4nQ2nstarQ2nstar)
4055                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4056                  - ((2.*dMult-13.)*reQ3nQ2nstarQ1nstar-reQ3nQ1nQ4nstar-9.*reQ2nQ1nstarQ1nstar)
4057                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4058                  - (2.*reQ1nQ1nQ2nstar+2.*(pow(dReQ4n,2.)+pow(dImQ4n,2.))
4059                  - 2.*(dMult-5.)*(pow(dReQ3n,2.)+pow(dImQ3n,2.))+2.*(pow(dReQ3n,2.)
4060                  + pow(dImQ3n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
4061                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4062                  + (2.*(dMult-6.)*(pow(dReQ2n,2.)+pow(dImQ2n,2.))
4063                  - 2.*(pow(dReQ2n,2.)+pow(dImQ2n,2.))*(pow(dReQ1n,2.)+pow(dImQ1n,2.))
4064                  - pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)
4065                  + 2.*(3.*dMult-11.)*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
4066                  / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.))
4067                  - 4.*(dMult-6.)/((dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
4068                  
4069   // average non-weighted 5-particle correlations for single event: 
4070   fQCorrelationsEBE[0]->SetBinContent(19,five2n1n1n1n1n);
4071   fQCorrelationsEBE[0]->SetBinContent(20,five2n2n2n1n1n);
4072   fQCorrelationsEBE[0]->SetBinContent(21,five3n1n2n1n1n);
4073   fQCorrelationsEBE[0]->SetBinContent(22,five4n1n1n1n1n);
4074         
4075   // final average non-weighted 5-particle correlations for all events:                         
4076   fQCorrelations[0][0]->Fill(18.5,five2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)); 
4077   fQCorrelations[0][0]->Fill(19.5,five2n2n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
4078   fQCorrelations[0][0]->Fill(20.5,five3n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
4079   fQCorrelations[0][0]->Fill(21.5,five4n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.));
4080  } // end of if(dMult>4)
4081     
4082  // 6-particle:
4083  Double_t six1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
4084  Double_t six2n2n1n1n1n1n = 0.; // <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
4085  Double_t six3n1n1n1n1n1n = 0.; // <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
4086  Double_t six2n1n1n2n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
4087  
4088  if(dMult>5)
4089  {
4090   six1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),3.)+9.*dQ2nQ1nQ2nstarQ1nstar-6.*reQ2nQ1nQ1nstarQ1nstarQ1nstar)
4091                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
4092                   + 4.*(reQ3nQ1nstarQ1nstarQ1nstar-3.*reQ3nQ2nstarQ1nstar)
4093                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
4094                   + 2.*(9.*(dMult-4.)*reQ2nQ1nstarQ1nstar+2.*(pow(dReQ3n,2.)+pow(dImQ3n,2.)))
4095                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.))
4096                   - 9.*(pow((pow(dReQ1n,2.)+pow(dImQ1n,2.)),2.)+(pow(dReQ2n,2.)+pow(dImQ2n,2.)))
4097                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-5.))
4098                   + (18.*(pow(dReQ1n,2.)+pow(dImQ1n,2.)))
4099                   / (dMult*(dMult-1)*(dMult-3)*(dMult-4))
4100                   - 6./((dMult-1.)*(dMult-2.)*(dMult-3.));
4101                   
4102   six2n1n1n2n1n1n = (dQ2nQ1nQ1nQ2nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
4103                   * (2.*five2n2n2n1n1n+4.*five2n1n1n1n1n+4.*five3n1n2n1n1n+4.*four2n1n2n1n+1.*four1n1n1n1n)
4104                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four1n1n1n1n+4.*two1n1n
4105                   + 2.*three2n1n1n+2.*three2n1n1n+4.*four3n1n1n1n+8.*three2n1n1n+2.*four4n2n1n1n
4106                   + 4.*four2n1n2n1n+2.*two2n2n+8.*four2n1n2n1n+4.*four3n1n3n1n+8.*three3n2n1n
4107                   + 4.*four3n1n2n2n+4.*four1n1n1n1n+4.*four2n1n2n1n+1.*four2n2n2n2n)
4108                   - dMult*(dMult-1.)*(dMult-2.)*(2.*three2n1n1n+8.*two1n1n+4.*two1n1n+2.
4109                   + 4.*two1n1n+4.*three2n1n1n+2.*two2n2n+4.*three2n1n1n+8.*three3n2n1n
4110                   + 8.*two2n2n+4.*three4n3n1n+4.*two3n3n+4.*three3n2n1n+4.*two1n1n
4111                   + 8.*three2n1n1n+4.*two1n1n+4.*three3n2n1n+4.*three2n1n1n+2.*two2n2n
4112                   + 4.*three3n2n1n+2.*three4n2n2n)-dMult*(dMult-1.)
4113                   * (4.*two1n1n+4.+4.*two1n1n+2.*two2n2n+1.+4.*two1n1n+4.*two2n2n+4.*two3n3n
4114                   + 1.+2.*two2n2n+1.*two4n4n)-dMult)
4115                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
4116  
4117   six2n2n1n1n1n1n = (reQ2nQ2nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
4118                   * (five4n1n1n1n1n+8.*five2n1n1n1n1n+6.*five2n2n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
4119                   * (4.*four3n1n1n1n+6.*four4n2n1n1n+12.*three2n1n1n+12.*four1n1n1n1n+24.*four2n1n2n1n
4120                   + 4.*four3n1n2n2n+3.*four2n2n2n2n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n
4121                   + 4.*three4n3n1n+3.*three4n2n2n+8.*three2n1n1n+24.*two1n1n+12.*two2n2n+12.*three2n1n1n+8.*three3n2n1n
4122                   + 1.*three4n2n2n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+2.*two2n2n+8.*two1n1n+6.)-dMult)
4123                   / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
4124    
4125   six3n1n1n1n1n1n = (reQ3nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)
4126                   * (five4n1n1n1n1n+4.*five2n1n1n1n1n+6.*five3n1n2n1n1n+4.*four3n1n1n1n)
4127                   - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+6.*four1n1n1n1n
4128                   + 12.*three2n1n1n+12.*four2n1n2n1n+6.*four3n1n1n1n+12.*three3n2n1n+4.*four3n1n3n1n+3.*four3n1n2n2n)
4129                   - dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+12.*three3n2n1n+4.*three4n3n1n+3.*three4n2n2n+4.*two1n1n
4130                   + 12.*two1n1n+6.*three2n1n1n+12.*three2n1n1n+4.*three3n2n1n+12.*two2n2n+4.*three3n2n1n+4.*two3n3n+1.*three4n3n1n
4131                   + 6.*three3n2n1n)-dMult*(dMult-1.)*(4.*two1n1n+6.*two2n2n+4.*two3n3n+1.*two4n4n+1.*two1n1n+4.+6.*two1n1n+4.*two2n2n
4132                   + 1.*two3n3n)-dMult)/(dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); // to be improved (direct formula needed)
4133                                  
4134   // average non-weighted 6-particle correlations for single event: 
4135   fQCorrelationsEBE[0]->SetBinContent(24,six1n1n1n1n1n1n);
4136   fQCorrelationsEBE[0]->SetBinContent(25,six2n1n1n2n1n1n);
4137   fQCorrelationsEBE[0]->SetBinContent(26,six2n2n1n1n1n1n);
4138   fQCorrelationsEBE[0]->SetBinContent(27,six3n1n1n1n1n1n);
4139         
4140   // final average non-weighted 6-particle correlations for all events:         
4141   fQCorrelations[0][0]->Fill(23.5,six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
4142   fQCorrelations[0][0]->Fill(24.5,six2n1n1n2n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
4143   fQCorrelations[0][0]->Fill(25.5,six2n2n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.));
4144   fQCorrelations[0][0]->Fill(26.5,six3n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
4145
4146   // distribution of <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
4147   //f6pDistribution->Fill(six1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)); 
4148  } // end of if(dMult>5)
4149  
4150  // 7-particle:
4151  Double_t seven2n1n1n1n1n1n1n = 0.; // <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
4152  
4153  if(dMult>6)
4154  {
4155   seven2n1n1n1n1n1n1n = (reQ2nQ1nQ1nQ1nstarQ1nstarQ1nstarQ1nstar-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
4156                       * (2.*six3n1n1n1n1n1n+4.*six1n1n1n1n1n1n+1.*six2n2n1n1n1n1n+6.*six2n1n1n2n1n1n+8.*five2n1n1n1n1n)
4157                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(1.*five4n1n1n1n1n +8.*five2n1n1n1n1n+8.*four3n1n1n1n
4158                       + 12.*five3n1n2n1n1n+4.*five2n1n1n1n1n+3.*five2n2n2n1n1n+6.*five2n2n2n1n1n+6.*four1n1n1n1n+24.*four1n1n1n1n
4159                       + 12.*five2n1n1n1n1n+12.*five2n1n1n1n1n+12.*three2n1n1n+24.*four2n1n2n1n+4.*five3n1n2n1n1n+4.*five2n1n1n1n1n)
4160                       - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(4.*four3n1n1n1n+6.*four4n2n1n1n+12.*four1n1n1n1n+24.*three2n1n1n
4161                       + 24.*four2n1n2n1n+12.*four3n1n1n1n+24.*three3n2n1n+8.*four3n1n3n1n+6.*four3n1n2n2n+6.*three2n1n1n+12.*four1n1n1n1n
4162                       + 12.*four2n1n2n1n+6.*three2n1n1n+12.*four2n1n2n1n+4.*four3n1n2n2n+3.*four2n2n2n2n+4.*four1n1n1n1n+6.*three2n1n1n
4163                       + 24.*two1n1n+24.*four1n1n1n1n+4.*four3n1n1n1n+24.*two1n1n+24.*three2n1n1n+12.*two2n2n+24.*three2n1n1n+12.*four2n1n2n1n
4164                       + 8.*three3n2n1n+8.*four2n1n2n1n+1.*four4n2n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(6.*three2n1n1n+1.*three2n1n1n+8.*two1n1n
4165                       + 12.*three3n2n1n+24.*two1n1n+12.*three2n1n1n+4.*three2n1n1n+8.*two1n1n+4.*three4n3n1n+24.*three2n1n1n+8.*three3n2n1n
4166                       + 12.*two1n1n+12.*two1n1n+3.*three4n2n2n+24.*two2n2n+6.*two2n2n+12.+12.*three3n2n1n+8.*two3n3n+12.*three2n1n1n+24.*two1n1n
4167                       + 4.*three3n2n1n+8.*three3n2n1n+2.*three4n3n1n+12.*two1n1n+8.*three2n1n1n+4.*three2n1n1n+2.*three3n2n1n+6.*two2n2n+8.*two2n2n
4168                       + 1.*three4n2n2n+4.*three3n2n1n+6.*three2n1n1n)-dMult*(dMult-1.)*(4.*two1n1n+2.*two1n1n+6.*two2n2n+8.+1.*two2n2n+4.*two3n3n
4169                       + 12.*two1n1n+4.*two1n1n+1.*two4n4n+8.*two2n2n+6.+2.*two3n3n+4.*two1n1n+1.*two2n2n)-dMult)
4170                       / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)); // to be improved (direct formula needed)
4171         
4172   // average non-weighted 7-particle correlations for single event: 
4173   fQCorrelationsEBE[0]->SetBinContent(29,seven2n1n1n1n1n1n1n);
4174        
4175   // final average non-weighted 7-particle correlations for all events:                      
4176   fQCorrelations[0][0]->Fill(28.5,seven2n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.));
4177  } // end of if(dMult>6)
4178  
4179  // 8-particle:
4180  Double_t eight1n1n1n1n1n1n1n1n = 0.; // <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
4181  if(dMult>7)
4182  {
4183   eight1n1n1n1n1n1n1n1n = (pow(pow(dReQ1n,2.)+pow(dImQ1n,2.),4.)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)
4184                         * (12.*seven2n1n1n1n1n1n1n+16.*six1n1n1n1n1n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)
4185                         * (8.*six3n1n1n1n1n1n+48.*six1n1n1n1n1n1n+6.*six2n2n1n1n1n1n+96.*five2n1n1n1n1n+72.*four1n1n1n1n+36.*six2n1n1n2n1n1n)
4186                         - dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(2.*five4n1n1n1n1n+32.*five2n1n1n1n1n+36.*four1n1n1n1n
4187                         + 32.*four3n1n1n1n+48.*five2n1n1n1n1n+48.*five3n1n2n1n1n+144.*five2n1n1n1n1n+288.*four1n1n1n1n+36.*five2n2n2n1n1n
4188                         + 144.*three2n1n1n+96.*two1n1n+144.*four2n1n2n1n)-dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)
4189                         * (8.*four3n1n1n1n+48.*four1n1n1n1n+12.*four4n2n1n1n+96.*four2n1n2n1n+96.*three2n1n1n+72.*three2n1n1n+144.*two1n1n
4190                         + 16.*four3n1n3n1n+48.*four3n1n1n1n+144.*four1n1n1n1n+72.*four1n1n1n1n+96.*three3n2n1n+24.*four3n1n2n2n+144.*four2n1n2n1n
4191                         + 288.*two1n1n+288.*three2n1n1n+9.*four2n2n2n2n+72.*two2n2n+24.)-dMult*(dMult-1.)*(dMult-2.)*(12.*three2n1n1n+16.*two1n1n
4192                         + 24.*three3n2n1n+48.*three2n1n1n+96.*two1n1n+8.*three4n3n1n+32.*three3n2n1n+96.*three2n1n1n+144.*two1n1n+6.*three4n2n2n
4193                         + 96.*two2n2n+36.*two2n2n+72.+48.*three3n2n1n+16.*two3n3n+72.*three2n1n1n+144.*two1n1n)-dMult*(dMult-1.)*(8.*two1n1n
4194                         + 12.*two2n2n+16.+8.*two3n3n+48.*two1n1n+1.*two4n4n+16.*two2n2n+18.)-dMult)
4195                         / (dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.)); // to be improved (direct formula needed)
4196   
4197   // average non-weighted 8-particle correlations for single event: 
4198   fQCorrelationsEBE[0]->SetBinContent(31,eight1n1n1n1n1n1n1n1n);
4199        
4200   // final average non-weighted 8-particle correlations for all events:                       
4201   fQCorrelations[0][0]->Fill(30.5,eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
4202  
4203   // distribution of <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
4204   //f8pDistribution->Fill(eight1n1n1n1n1n1n1n1n,dMult*(dMult-1.)*(dMult-2.)*(dMult-3.)*(dMult-4.)*(dMult-5.)*(dMult-6.)*(dMult-7.));
4205  } // end of if(dMult>7) 
4206  
4207 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrelationsForIntegratedFlow()
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251 //================================================================================================================================
4252
4253
4254 void AliFlowAnalysisWithQCumulants::EvaluateNestedLoopsForIntegratedFlow(AliFlowEventSimple* anEvent)
4255 {
4256  // 1.) Evaluate with nested loops the relevant correlations for integrated flow without and with using the particle weights. 
4257  //     Results are stored in profiles fDirectCorrelations and fDirectCorrelationsW, respectively.
4258  
4259  // 2.) Evaluate with nested loops corrections for non-uniform acceptance relevant for integrated flow, 
4260  //     without and with using the particle weights.
4261  //     Without weights: cos terms are stored in profile fDirectCorrectionsCos, and sin terms in profile fDirectCorrectionsSin.
4262  //     With weights: cos terms are stored in profile fDirectCorrectionsCosW, and sin terms in profile fDirectCorrectionsSinW.
4263  
4264  // 3.) Binning of fDirectCorrelations is organized as follows:
4265  // 
4266  //  1st bin: <2>_{1n|1n} = two1n1n = cos(n*(phi1-phi2))>
4267  //  2nd bin: <2>_{2n|2n} = two2n2n = cos(2n*(phi1-phi2))>
4268  //  3rd bin: <2>_{3n|3n} = two3n3n = cos(3n*(phi1-phi2))> 
4269  //  4th bin: <2>_{4n|4n} = two4n4n = cos(4n*(phi1-phi2))>
4270  //  5th bin:           ----  EMPTY ----
4271  //  6th bin: <3>_{2n|1n,1n} = three2n1n1n = <cos(n*(2.*phi1-phi2-phi3))>
4272  //  7th bin: <3>_{3n|2n,1n} = three3n2n1n = <cos(n*(3.*phi1-2.*phi2-phi3))>
4273  //  8th bin: <3>_{4n|2n,2n} = three4n2n2n = <cos(n*(4.*phi1-2.*phi2-2.*phi3))>
4274  //  9th bin: <3>_{4n|3n,1n} = three4n3n1n = <cos(n*(4.*phi1-3.*phi2-phi3))>
4275  // 10th bin:           ----  EMPTY ----
4276  // 11th bin: <4>_{1n,1n|1n,1n} = four1n1n1n1n = <cos(n*(phi1+phi2-phi3-phi4))>
4277  // 12th bin: <4>_{2n,1n|2n,1n} = four2n1n2n1n = <cos(2.*n*(phi1+phi2-phi3-phi4))>
4278  // 13th bin: <4>_{2n,2n|2n,2n} = four2n2n2n2n = <cos(n*(2.*phi1+phi2-2.*phi3-phi4))>
4279  // 14th bin: <4>_{3n|1n,1n,1n} = four3n1n1n1n = <cos(n*(3.*phi1-phi2-phi3-phi4))> 
4280  // 15th bin: <4>_{3n,1n|3n,1n} = four3n1n3n1n = <cos(n*(4.*phi1-2.*phi2-phi3-phi4))>
4281  // 16th bin: <4>_{3n,1n|2n,2n} = four3n1n2n2n = <cos(n*(3.*phi1+phi2-2.*phi3-2.*phi4))>
4282  // 17th bin: <4>_{4n|2n,1n,1n} = four4n2n1n1n = <cos(n*(3.*phi1+phi2-3.*phi3-phi4))> 
4283  // 18th bin:           ----  EMPTY ----
4284  // 19th bin: <5>_{2n|1n,1n,1n,1n} = five2n1n1n1n1n = <cos(n*(2.*phi1+phi2-phi3-phi4-phi5))>
4285  // 20th bin: <5>_{2n,2n|2n,1n,1n} = five2n2n2n1n1n = <cos(n*(2.*phi1+2.*phi2-2.*phi3-phi4-phi5))>
4286  // 21st bin: <5>_{3n,1n|2n,1n,1n} = five3n1n2n1n1n = <cos(n*(3.*phi1+phi2-2.*phi3-phi4-phi5))>
4287  // 22nd bin: <5>_{4n|1n,1n,1n,1n} = five4n1n1n1n1n = <cos(n*(4.*phi1-phi2-phi3-phi4-phi5))>
4288  // 23rd bin:           ----  EMPTY ----
4289  // 24th bin: <6>_{1n,1n,1n|1n,1n,1n} = six1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3-phi4-phi5-phi6))>
4290  // 25th bin: <6>_{2n,1n,1n|2n,1n,1n} = six2n1n1n2n1n1n = <cos(n*(2.*phi1+2.*phi2-phi3-phi4-phi5-phi6))>
4291  // 26th bin: <6>_{2n,2n|1n,1n,1n,1n} = six2n2n1n1n1n1n = <cos(n*(3.*phi1+phi2-phi3-phi4-phi5-phi6))>
4292  // 27th bin: <6>_{3n,1n|1n,1n,1n,1n} = six3n1n1n1n1n1n = <cos(n*(2.*phi1+phi2+phi3-2.*phi4-phi5-phi6))>
4293  // 28th bin:           ----  EMPTY ----
4294  // 29th bin: <7>_{2n,1n,1n|1n,1n,1n,1n} = seven2n1n1n1n1n1n1n =  <cos(n*(2.*phi1+phi2+phi3-phi4-phi5-phi6-phi7))>
4295  // 30th bin:           ----  EMPTY ----
4296  // 31st bin: <8>_{1n,1n,1n,1n|1n,1n,1n,1n} = eight1n1n1n1n1n1n1n1n = <cos(n*(phi1+phi2+phi3+phi4-phi5-phi6-phi7-phi8))>
4297  
4298  // 4.) Binning of fDirectCorrelationsW is organized as follows:
4299  // ..............................................................................................
4300  //       ---- bins 1-20: 2-particle correlations ----
4301  // 1st bin: two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
4302  // 2nd bin: two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
4303  // 3rd bin: two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))>
4304  // 4th bin: two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
4305  // 5th bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
4306  // 6th bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
4307  //       ---- bins 21-40: 3-particle correlations ----
4308  // 21st bin: three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))> 
4309  //       ---- bins 41-60: 4-particle correlations ----
4310  // 41st bin: four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
4311  //       ---- bins 61-80: 5-particle correlations ---- 
4312  //       ---- bins 81-100: 6-particle correlations ----
4313  //       ---- bins 101-120: 7-particle correlations ----
4314  //       ---- bins 121-140: 8-particle correlations ----
4315  // ..............................................................................................
4316  
4317  // 5.) Binning of fDirectCorrectionsCos is organized as follows:
4318  // ..............................................................................................
4319  // 1st bin: <<cos(n*(phi1))>> = cosP1n
4320  // 2nd bin: <<cos(n*(phi1+phi2))>> = cosP1nP1n
4321  // 3rd bin: <<cos(n*(phi1-phi2-phi3))>> = cosP1nM1nM1n
4322  // ...
4323  // ..............................................................................................
4324               
4325  // 6.) Binning of fDirectCorrectionsSin is organized as follows:
4326  // ..............................................................................................
4327  // 1st bin: <<sin(n*(phi1))>> = sinP1n
4328  // 2nd bin: <<sin(n*(phi1+phi2))>> = sinP1nP1n
4329  // 3rd bin: <<sin(n*(phi1-phi2-phi3))>> = sinP1nM1nM1n
4330  // ...
4331  // ..............................................................................................
4332        
4333  // 7.) Binning of fDirectCorrectionsCosW is organized as follows:
4334  // ..............................................................................................     
4335  // ...
4336  // ..............................................................................................     
4337  
4338  // 8.) Binning of fDirectCorrectionsSinW is organized as follows:
4339  // ..............................................................................................     
4340  // ...
4341  // ..............................................................................................     
4342  
4343  Int_t nPrim = anEvent->NumberOfTracks(); 
4344  AliFlowTrackSimple *aftsTrack = NULL;
4345  
4346  Double_t phi1=0., phi2=0., phi3=0., phi4=0., phi5=0., phi6=0., phi7=0., phi8=0.;
4347  Double_t wPhi1=1., wPhi2=1., wPhi3=1., wPhi4=1., wPhi5=1., wPhi6=1., wPhi7=1., wPhi8=1.;
4348  
4349  Int_t n = fHarmonic; 
4350  
4351  // 2-particle correlations and 1- and 2-particle correction terms:       
4352  for(Int_t i1=0;i1<nPrim;i1++)
4353  {
4354   aftsTrack=anEvent->GetTrack(i1);
4355   if(!(aftsTrack->InRPSelection())) continue;
4356   phi1=aftsTrack->Phi();
4357   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
4358   
4359   // corrections for non-uniform acceptance:
4360   // non-weighted: 
4361   fDirectCorrectionsCos->Fill(0.5,cos(n*phi1),1.); // <cos(n*phi1)>
4362   fDirectCorrectionsSin->Fill(0.5,sin(n*phi1),1.); // <sin(n*phi1)>  
4363   // weighted:
4364   // fDirectCorrectionsCosW->Fill(0.5,???,1); // to be improved (continued)
4365   // fDirectCorrectionsSinW->Fill(0.5,???,1); // to be improved (continued)
4366   
4367   for(Int_t i2=0;i2<nPrim;i2++)
4368   {
4369    if(i2==i1)continue;
4370    aftsTrack=anEvent->GetTrack(i2);
4371    if(!(aftsTrack->InRPSelection())) continue;
4372    phi2=aftsTrack->Phi();
4373    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
4374     
4375    // non-weighted correlations: 
4376    fDirectCorrelations->Fill(0.5,cos(n*(phi1-phi2)),1.);    // <cos(n*(phi1-phi2))>
4377    fDirectCorrelations->Fill(1.5,cos(2.*n*(phi1-phi2)),1.); // <cos(2n*(phi1-phi2))>
4378    fDirectCorrelations->Fill(2.5,cos(3.*n*(phi1-phi2)),1.); // <cos(3n*(phi1-phi2))>
4379    fDirectCorrelations->Fill(3.5,cos(4.*n*(phi1-phi2)),1.); // <cos(4n*(phi1-phi2))> 
4380    
4381    // weighted correlations:
4382    // ................................................................................................................
4383    if(fUsePhiWeights) fDirectCorrelationsW->Fill(0.5,cos(n*(phi1-phi2)),wPhi1*wPhi2);                  // <w1   w2   cos( n*(phi1-phi2))>
4384    if(fUsePhiWeights) fDirectCorrelationsW->Fill(1.5,cos(2.*n*(phi1-phi2)),pow(wPhi1,2)*pow(wPhi2,2)); // <w1^2 w2^2 cos(2n*(phi1-phi2))>
4385    if(fUsePhiWeights) fDirectCorrelationsW->Fill(2.5,cos(3.*n*(phi1-phi2)),pow(wPhi1,3)*pow(wPhi2,3)); // <w1^3 w2^3 cos(3n*(phi1-phi2))>
4386    if(fUsePhiWeights) fDirectCorrelationsW->Fill(3.5,cos(4.*n*(phi1-phi2)),pow(wPhi1,4)*pow(wPhi2,4)); // <w1^4 w2^4 cos(4n*(phi1-phi2))> 
4387    if(fUsePhiWeights) fDirectCorrelationsW->Fill(4.5,cos(n*(phi1-phi2)),pow(wPhi1,3)*wPhi2);           // <w1^3 w2 cos(n*(phi1-phi2))>
4388    // ...
4389    // ................................................................................................................
4390  
4391    // non-weighted corrections for non-uniform acceptance (cos terms)
4392    // ................................................................................................................
4393    fDirectCorrectionsCos->Fill(1.5,cos(n*(phi1+phi2)),1.); // <<cos(n*(phi1+phi2))>>
4394    // ...
4395    // ................................................................................................................
4396   
4397    // non-weighted corrections for non-uniform acceptance (sin terms)
4398    // ................................................................................................................
4399    fDirectCorrectionsSin->Fill(1.5,sin(n*(phi1+phi2)),1.); // <<sin(n*(phi1+phi2))>>
4400    // ...
4401    // ................................................................................................................
4402    
4403    // weighted corrections for non-uniform acceptance (cos terms)
4404    // ................................................................................................................
4405    // fDirectCorrectionsCosW->Fill(1.5,???,1.); // to be improved (continued)
4406    // ...
4407    // ................................................................................................................
4408   
4409    // non-weighted corrections for non-uniform acceptance (sin terms)
4410    // ................................................................................................................
4411    // fDirectCorrectionsSinW->Fill(1.5,???,1.); // to be improved (continued)
4412    // ...
4413    // ................................................................................................................
4414
4415   } // end of for(Int_t i2=0;i2<nPrim;i2++)
4416  } // end of for(Int_t i1=0;i1<nPrim;i1++)
4417  
4418  // 3-particle correlations:         
4419  for(Int_t i1=0;i1<nPrim;i1++)
4420  {
4421   aftsTrack=anEvent->GetTrack(i1);
4422   if(!(aftsTrack->InRPSelection())) continue;
4423   phi1=aftsTrack->Phi();
4424   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
4425   for(Int_t i2=0;i2<nPrim;i2++)
4426   {
4427    if(i2==i1)continue;
4428    aftsTrack=anEvent->GetTrack(i2);
4429    if(!(aftsTrack->InRPSelection())) continue;
4430    phi2=aftsTrack->Phi();
4431    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
4432    for(Int_t i3=0;i3<nPrim;i3++)
4433    {
4434     if(i3==i1||i3==i2)continue;
4435     aftsTrack=anEvent->GetTrack(i3);
4436     if(!(aftsTrack->InRPSelection())) continue;
4437     phi3=aftsTrack->Phi();
4438     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
4439     
4440     // non-weighted correlations:
4441     fDirectCorrelations->Fill(5.,cos(2.*n*phi1-n*(phi2+phi3)),1.);       //<3>_{2n|nn,n}
4442     fDirectCorrelations->Fill(6.,cos(3.*n*phi1-2.*n*phi2-n*phi3),1.);    //<3>_{3n|2n,n}
4443     fDirectCorrelations->Fill(7.,cos(4.*n*phi1-2.*n*phi2-2.*n*phi3),1.); //<3>_{4n|2n,2n}
4444     fDirectCorrelations->Fill(8.,cos(4.*n*phi1-3.*n*phi2-n*phi3),1.);    //<3>_{4n|3n,n}
4445     
4446     // weighted correlations:
4447     // ..............................................................................................................................
4448     // 2-p:
4449     if(fUsePhiWeights) fDirectCorrelationsW->Fill(5.,cos(n*(phi1-phi2)),wPhi1*wPhi2*pow(wPhi3,2)); // <w1 w2 w3^2 cos(n*(phi1-phi2))>
4450     // 3-p:
4451     if(fUsePhiWeights) fDirectCorrelationsW->Fill(20.,cos(2.*n*phi1-n*(phi2+phi3)),pow(wPhi1,2)*wPhi2*wPhi3); // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
4452     // ...
4453     // ..............................................................................................................................
4454     
4455     // non-weighted corrections for non-uniform acceptance (cos terms)
4456     // ................................................................................................................
4457     fDirectCorrectionsCos->Fill(2.,cos(n*(phi1-phi2-phi3)),1.); // <<cos(n*(phi1-phi2-phi3))>>
4458     // ...
4459     // ................................................................................................................
4460   
4461     // non-weighted corrections for non-uniform acceptance (sin terms)
4462     // ................................................................................................................
4463     fDirectCorrectionsSin->Fill(2.,sin(n*(phi1-phi2-phi3)),1.); // <<sin(n*(phi1-phi2-phi3))>>
4464     // ...
4465     // ................................................................................................................
4466     
4467     // weighted corrections for non-uniform acceptance (cos terms)
4468     // ................................................................................................................
4469     // ...
4470     // ................................................................................................................
4471     
4472     // weighted corrections for non-uniform acceptance (sin terms)
4473     // ................................................................................................................
4474     // ...
4475     // ................................................................................................................
4476
4477    } // end of for(Int_t i3=0;i3<nPrim;i3++)
4478   } // end of for(Int_t i2=0;i2<nPrim;i2++)
4479  } // end of for(Int_t i1=0;i1<nPrim;i1++)
4480
4481  // 4-particle correlations:       
4482  for(Int_t i1=0;i1<nPrim;i1++)
4483  {
4484   aftsTrack=anEvent->GetTrack(i1);
4485   if(!(aftsTrack->InRPSelection())) continue;
4486   phi1=aftsTrack->Phi();
4487   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
4488   for(Int_t i2=0;i2<nPrim;i2++)
4489   {
4490    if(i2==i1)continue;
4491    aftsTrack=anEvent->GetTrack(i2);
4492    if(!(aftsTrack->InRPSelection())) continue;
4493    phi2=aftsTrack->Phi();
4494    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
4495    for(Int_t i3=0;i3<nPrim;i3++)
4496    {
4497     if(i3==i1||i3==i2)continue;
4498     aftsTrack=anEvent->GetTrack(i3);
4499     if(!(aftsTrack->InRPSelection())) continue;
4500     phi3=aftsTrack->Phi();
4501     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
4502     for(Int_t i4=0;i4<nPrim;i4++)
4503     {
4504      if(i4==i1||i4==i2||i4==i3)continue;
4505      aftsTrack=anEvent->GetTrack(i4);
4506      if(!(aftsTrack->InRPSelection())) continue;
4507      phi4=aftsTrack->Phi();
4508      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
4509      
4510      // non-weighted:
4511      fDirectCorrelations->Fill(10.,cos(n*phi1+n*phi2-n*phi3-n*phi4),1.);            // <4>_{n,n|n,n} 
4512      fDirectCorrelations->Fill(11.,cos(2.*n*phi1+n*phi2-2.*n*phi3-n*phi4),1.);      // <4>_{2n,n|2n,n}
4513      fDirectCorrelations->Fill(12.,cos(2.*n*phi1+2*n*phi2-2.*n*phi3-2.*n*phi4),1.); // <4>_{2n,2n|2n,2n}
4514      fDirectCorrelations->Fill(13.,cos(3.*n*phi1-n*phi2-n*phi3-n*phi4),1.);         // <4>_{3n|n,n,n}
4515      fDirectCorrelations->Fill(14.,cos(3.*n*phi1+n*phi2-3.*n*phi3-n*phi4),1.);      // <4>_{3n,n|3n,n}   
4516      fDirectCorrelations->Fill(15.,cos(3.*n*phi1+n*phi2-2.*n*phi3-2.*n*phi4),1.);   // <4>_{3n,n|2n,2n}
4517      fDirectCorrelations->Fill(16.,cos(4.*n*phi1-2.*n*phi2-n*phi3-n*phi4),1.);      // <4>_{4n|2n,n,n}
4518      
4519      // weighted:
4520      //.......................................................................................
4521      // 4-p:
4522      if(fUsePhiWeights) fDirectCorrelationsW->Fill(40.,cos(n*phi1+n*phi2-n*phi3-n*phi4),wPhi1*wPhi2*wPhi3*wPhi4); 
4523      // ...             
4524      //.......................................................................................
4525      
4526     }  
4527    }
4528   }
4529  }
4530
4531  // 5-particle correlations:      
4532  for(Int_t i1=0;i1<nPrim;i1++)
4533  {
4534   //cout<<"i1 = "<<i1<<endl;
4535   aftsTrack=anEvent->GetTrack(i1);
4536   if(!(aftsTrack->InRPSelection())) continue;  
4537   phi1=aftsTrack->Phi();
4538   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
4539   for(Int_t i2=0;i2<nPrim;i2++)
4540   {
4541    if(i2==i1)continue;
4542    aftsTrack=anEvent->GetTrack(i2);
4543    if(!(aftsTrack->InRPSelection())) continue;
4544    phi2=aftsTrack->Phi();
4545    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
4546    for(Int_t i3=0;i3<nPrim;i3++)
4547    {
4548     if(i3==i1||i3==i2)continue;
4549     aftsTrack=anEvent->GetTrack(i3);
4550     if(!(aftsTrack->InRPSelection())) continue;
4551     phi3=aftsTrack->Phi();
4552     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
4553     for(Int_t i4=0;i4<nPrim;i4++)
4554     {
4555      if(i4==i1||i4==i2||i4==i3)continue;
4556      aftsTrack=anEvent->GetTrack(i4);
4557      if(!(aftsTrack->InRPSelection())) continue;
4558      phi4=aftsTrack->Phi();
4559      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
4560      for(Int_t i5=0;i5<nPrim;i5++)
4561      {
4562       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
4563       aftsTrack=anEvent->GetTrack(i5);
4564       if(!(aftsTrack->InRPSelection())) continue;
4565       phi5=aftsTrack->Phi();
4566       if(fUsePhiWeights && fPhiWeights) wPhi5 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi5*fnBinsPhi/TMath::TwoPi())));
4567       
4568       // non-weighted:
4569       //------------------------------------------------------------------------------------------------------
4570       fDirectCorrelations->Fill(18.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{2n,n|n,n,n}
4571       fDirectCorrelations->Fill(19.,cos(2.*n*phi1+2.*n*phi2-2.*n*phi3-n*phi4-n*phi5),1.); //<5>_{2n,2n|2n,n,n}
4572       fDirectCorrelations->Fill(20.,cos(3.*n*phi1+n*phi2-2.*n*phi3-n*phi4-n*phi5),1.);    //<5>_{3n,n|2n,n,n}
4573       fDirectCorrelations->Fill(21.,cos(4.*n*phi1-n*phi2-n*phi3-n*phi4-n*phi5),1.);       //<5>_{4n|n,n,n,n}
4574       //------------------------------------------------------------------------------------------------------
4575       
4576       // weighted:
4577       //..............................................................................................................
4578       // 5-p:
4579       if(fUsePhiWeights) fDirectCorrelationsW->Fill(60.,cos(2.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5),pow(wPhi1,2)*wPhi2*wPhi3*wPhi4*wPhi5);     
4580       //..............................................................................................................
4581       
4582      }
4583     }  
4584    }
4585   }
4586  }
4587  
4588  // 6-particle correlations:
4589  for(Int_t i1=0;i1<nPrim;i1++)
4590  {
4591   //cout<<"i1 = "<<i1<<endl;
4592   aftsTrack=anEvent->GetTrack(i1);
4593   if(!(aftsTrack->InRPSelection())) continue;
4594   phi1=aftsTrack->Phi();
4595   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
4596   for(Int_t i2=0;i2<nPrim;i2++)
4597   {
4598    if(i2==i1)continue;
4599    aftsTrack=anEvent->GetTrack(i2);
4600    if(!(aftsTrack->InRPSelection())) continue;
4601    phi2=aftsTrack->Phi();
4602    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
4603    for(Int_t i3=0;i3<nPrim;i3++)
4604    {
4605     if(i3==i1||i3==i2)continue;
4606     aftsTrack=anEvent->GetTrack(i3);
4607     if(!(aftsTrack->InRPSelection())) continue;
4608     phi3=aftsTrack->Phi();
4609     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
4610     for(Int_t i4=0;i4<nPrim;i4++)
4611     {
4612      if(i4==i1||i4==i2||i4==i3)continue;
4613      aftsTrack=anEvent->GetTrack(i4);
4614      if(!(aftsTrack->InRPSelection())) continue;
4615      phi4=aftsTrack->Phi();
4616      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
4617      for(Int_t i5=0;i5<nPrim;i5++)
4618      {
4619       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
4620       aftsTrack=anEvent->GetTrack(i5);
4621       if(!(aftsTrack->InRPSelection())) continue;
4622       phi5=aftsTrack->Phi();
4623       if(fUsePhiWeights && fPhiWeights) wPhi5 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi5*fnBinsPhi/TMath::TwoPi())));
4624       for(Int_t i6=0;i6<nPrim;i6++)
4625       {
4626        if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
4627        aftsTrack=anEvent->GetTrack(i6);
4628        if(!(aftsTrack->InRPSelection())) continue;
4629        phi6=aftsTrack->Phi(); 
4630        if(fUsePhiWeights && fPhiWeights) wPhi6 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi6*fnBinsPhi/TMath::TwoPi())));
4631        
4632        // non-weighted:
4633        //-----------------------------------------------------------------------------------------------------------
4634        fDirectCorrelations->Fill(23.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),1.);       //<6>_{n,n,n|n,n,n}
4635        fDirectCorrelations->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}
4636        fDirectCorrelations->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}
4637        fDirectCorrelations->Fill(26.,cos(3.*n*phi1+n*phi2-n*phi3-n*phi4-n*phi5-n*phi6),1.);    //<6>_{3n,n|n,n,n,n}  
4638        //-----------------------------------------------------------------------------------------------------------
4639
4640        // weighted:
4641        //.................................................................................................................
4642        // 6-p:
4643        if(fUsePhiWeights) fDirectCorrelationsW->Fill(80.,cos(n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6),wPhi1*wPhi2*wPhi3*wPhi4*wPhi5*wPhi6);
4644        //.................................................................................................................       
4645           
4646       } 
4647      }
4648     }  
4649    }
4650   }
4651  }
4652  
4653  // 7-particle correlations:
4654  for(Int_t i1=0;i1<nPrim;i1++)
4655  {
4656   //cout<<"i1 = "<<i1<<endl;
4657   aftsTrack=anEvent->GetTrack(i1);
4658   if(!(aftsTrack->InRPSelection())) continue;
4659   phi1=aftsTrack->Phi();
4660   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
4661   for(Int_t i2=0;i2<nPrim;i2++)
4662   {
4663    if(i2==i1)continue;
4664    aftsTrack=anEvent->GetTrack(i2);
4665    if(!(aftsTrack->InRPSelection())) continue;
4666    phi2=aftsTrack->Phi();
4667    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
4668    for(Int_t i3=0;i3<nPrim;i3++)
4669    {
4670     if(i3==i1||i3==i2)continue;
4671     aftsTrack=anEvent->GetTrack(i3);
4672     if(!(aftsTrack->InRPSelection())) continue;
4673     phi3=aftsTrack->Phi();
4674     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
4675     for(Int_t i4=0;i4<nPrim;i4++)
4676     {
4677      if(i4==i1||i4==i2||i4==i3)continue;
4678      aftsTrack=anEvent->GetTrack(i4);
4679      if(!(aftsTrack->InRPSelection())) continue;
4680      phi4=aftsTrack->Phi();
4681      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
4682      for(Int_t i5=0;i5<nPrim;i5++)
4683      {
4684       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
4685       aftsTrack=anEvent->GetTrack(i5);
4686       if(!(aftsTrack->InRPSelection())) continue;
4687       phi5=aftsTrack->Phi();
4688       if(fUsePhiWeights && fPhiWeights) wPhi5 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi5*fnBinsPhi/TMath::TwoPi())));
4689       for(Int_t i6=0;i6<nPrim;i6++)
4690       {
4691        if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
4692        aftsTrack=anEvent->GetTrack(i6);
4693        if(!(aftsTrack->InRPSelection())) continue;
4694        phi6=aftsTrack->Phi(); 
4695        if(fUsePhiWeights && fPhiWeights) wPhi6 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi6*fnBinsPhi/TMath::TwoPi())));
4696        for(Int_t i7=0;i7<nPrim;i7++)
4697        {
4698         if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
4699         aftsTrack=anEvent->GetTrack(i7);
4700         if(!(aftsTrack->InRPSelection())) continue;
4701         phi7=aftsTrack->Phi(); 
4702         if(fUsePhiWeights && fPhiWeights) wPhi7 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi7*fnBinsPhi/TMath::TwoPi())));
4703         
4704         // non-weighted:
4705         //---------------------------------------------------------------------------------------------------------------
4706         fDirectCorrelations->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}
4707         //---------------------------------------------------------------------------------------------------------------
4708         
4709         // weighted:
4710         //..........................................................................................................................................
4711         if(fUsePhiWeights) fDirectCorrelationsW->Fill(100.,cos(2.*n*phi1+n*phi2+n*phi3-n*phi4-n*phi5-n*phi6-n*phi7),
4712                                                            pow(wPhi1,2.)*wPhi2*wPhi3*wPhi4*wPhi5*wPhi6*wPhi7);
4713         //..........................................................................................................................................
4714         
4715        } 
4716       } 
4717      }
4718     }  
4719    }
4720   }
4721  }
4722  
4723  cout<<endl;
4724  
4725  // 8-particle correlations:
4726  for(Int_t i1=0;i1<nPrim;i1++)
4727  {
4728   cout<<"i1 = "<<i1<<endl;
4729   aftsTrack=anEvent->GetTrack(i1);
4730   if(!(aftsTrack->InRPSelection())) continue;
4731   phi1=aftsTrack->Phi();
4732   if(fUsePhiWeights && fPhiWeights) wPhi1 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi1*fnBinsPhi/TMath::TwoPi())));
4733   for(Int_t i2=0;i2<nPrim;i2++)
4734   {
4735    if(i2==i1)continue;
4736    aftsTrack=anEvent->GetTrack(i2);
4737    if(!(aftsTrack->InRPSelection())) continue;
4738    phi2=aftsTrack->Phi();
4739    if(fUsePhiWeights && fPhiWeights) wPhi2 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi2*fnBinsPhi/TMath::TwoPi())));
4740    for(Int_t i3=0;i3<nPrim;i3++)
4741    {
4742     if(i3==i1||i3==i2)continue;
4743     aftsTrack=anEvent->GetTrack(i3);
4744     if(!(aftsTrack->InRPSelection())) continue;
4745     phi3=aftsTrack->Phi();
4746     if(fUsePhiWeights && fPhiWeights) wPhi3 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi3*fnBinsPhi/TMath::TwoPi())));
4747     for(Int_t i4=0;i4<nPrim;i4++)
4748     {
4749      if(i4==i1||i4==i2||i4==i3)continue;
4750      aftsTrack=anEvent->GetTrack(i4);
4751      if(!(aftsTrack->InRPSelection())) continue;
4752      phi4=aftsTrack->Phi();
4753      if(fUsePhiWeights && fPhiWeights) wPhi4 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi4*fnBinsPhi/TMath::TwoPi())));
4754      for(Int_t i5=0;i5<nPrim;i5++)
4755      {
4756       if(i5==i1||i5==i2||i5==i3||i5==i4)continue;
4757       aftsTrack=anEvent->GetTrack(i5);
4758       if(!(aftsTrack->InRPSelection())) continue;
4759       phi5=aftsTrack->Phi();
4760       if(fUsePhiWeights && fPhiWeights) wPhi5 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi5*fnBinsPhi/TMath::TwoPi())));
4761       for(Int_t i6=0;i6<nPrim;i6++)
4762       {
4763        if(i6==i1||i6==i2||i6==i3||i6==i4||i6==i5)continue;
4764        aftsTrack=anEvent->GetTrack(i6);
4765        if(!(aftsTrack->InRPSelection())) continue;
4766        phi6=aftsTrack->Phi();
4767        if(fUsePhiWeights && fPhiWeights) wPhi6 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi6*fnBinsPhi/TMath::TwoPi()))); 
4768        for(Int_t i7=0;i7<nPrim;i7++)
4769        {
4770         if(i7==i1||i7==i2||i7==i3||i7==i4||i7==i5||i7==i6)continue;
4771         aftsTrack=anEvent->GetTrack(i7);
4772         if(!(aftsTrack->InRPSelection())) continue;
4773         phi7=aftsTrack->Phi();
4774         if(fUsePhiWeights && fPhiWeights) wPhi7 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi7*fnBinsPhi/TMath::TwoPi()))); 
4775         for(Int_t i8=0;i8<nPrim;i8++)
4776         {
4777          if(i8==i1||i8==i2||i8==i3||i8==i4||i8==i5||i8==i6||i8==i7)continue;
4778          aftsTrack=anEvent->GetTrack(i8);
4779          if(!(aftsTrack->InRPSelection())) continue;
4780          phi8=aftsTrack->Phi();
4781          if(fUsePhiWeights && fPhiWeights) wPhi8 = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(phi8*fnBinsPhi/TMath::TwoPi()))); 
4782           
4783          // non-weighted: 
4784          //--------------------------------------------------------------------------------------------------------------------
4785          fDirectCorrelations->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}
4786          //--------------------------------------------------------------------------------------------------------------------
4787          
4788          // weighted: 
4789          //...........................................................................................................................................
4790          if(fUsePhiWeights) fDirectCorrelationsW->Fill(120.,cos(n*phi1+n*phi2+n*phi3+n*phi4-n*phi5-n*phi6-n*phi7-n*phi8),
4791                                                            wPhi1*wPhi2*wPhi3*wPhi4*wPhi5*wPhi6*wPhi7*wPhi8);
4792          //...........................................................................................................................................
4793      
4794         } 
4795        } 
4796       } 
4797      }
4798     }  
4799    }
4800   }
4801  }
4802  
4803 } // end of AliFlowAnalysisWithQCumulants::EvaluateNestedLoopsForIntegratedFlow(AliFlowEventSimple* anEvent)
4804
4805
4806 //================================================================================================================================
4807
4808
4809 void AliFlowAnalysisWithQCumulants::CompareResultsFromNestedLoopsAndFromQVectorsForIntFlow(Bool_t useParticleWeights)
4810 {
4811  // compare results needed for int. flow calculated with nested loops and with those calculated from Q-vectors
4812
4813  cout<<endl;
4814  cout<<endl;
4815  cout<<"   *************************************"<<endl;
4816  cout<<"   **** cross-checking the formulas ****"<<endl;
4817  cout<<"   ****     for integrated flow     ****"<<endl;
4818  cout<<"   *************************************"<<endl;
4819  cout<<endl;
4820  cout<<endl;
4821  
4822  if(!(useParticleWeights))
4823  {
4824   cout<<"   **** results for non-weighted correlations: ****"<<endl;
4825   cout<<endl;
4826   cout<<"<2>_{1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(1)<<endl;
4827   cout<<"<2>_{1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(1)<<endl;
4828   cout<<endl;
4829   cout<<"<2>_{2n,2n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(2)<<endl;
4830   cout<<"<2>_{2n,2n} from nested loops = "<<fDirectCorrelations->GetBinContent(2)<<endl;
4831   cout<<endl;
4832   cout<<"<2>_{3n,3n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(3)<<endl;
4833   cout<<"<2>_{3n,3n} from nested loops = "<<fDirectCorrelations->GetBinContent(3)<<endl;
4834   cout<<endl;
4835   cout<<"<2>_{4n,4n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(4)<<endl;
4836   cout<<"<2>_{4n,4n} from nested loops = "<<fDirectCorrelations->GetBinContent(4)<<endl;
4837   cout<<endl; 
4838   cout<<"<3>_{2n|1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(6)<<endl;
4839   cout<<"<3>_{2n|1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(6)<<endl;
4840   cout<<endl;
4841   cout<<"<3>_{3n|2n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(7)<<endl;
4842   cout<<"<3>_{3n|2n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(7)<<endl;
4843   cout<<endl;
4844   cout<<"<3>_{4n,2n,2n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(8)<<endl;
4845   cout<<"<3>_{4n,2n,2n} from nested loops = "<<fDirectCorrelations->GetBinContent(8)<<endl;
4846   cout<<endl;
4847   cout<<"<3>_{4n,3n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(9)<<endl;
4848   cout<<"<3>_{4n,3n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(9)<<endl;
4849   cout<<endl; 
4850   cout<<"<4>_{1n,1n|1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(11)<<endl;
4851   cout<<"<4>_{1n,1n|1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(11)<<endl;
4852   cout<<endl;
4853   cout<<"<4>_{2n,1n|2n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(12)<<endl;
4854   cout<<"<4>_{2n,1n|2n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(12)<<endl;
4855   cout<<endl;
4856   cout<<"<4>_{2n,2n|2n,2n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(13)<<endl;
4857   cout<<"<4>_{2n,2n|2n,2n} from nested loops = "<<fDirectCorrelations->GetBinContent(13)<<endl;
4858   cout<<endl;
4859   cout<<"<4>_{3n|1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(14)<<endl;
4860   cout<<"<4>_{3n|1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(14)<<endl;
4861   cout<<endl;
4862   cout<<"<4>_{3n,1n|3n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(15)<<endl;
4863   cout<<"<4>_{3n,1n|3n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(15)<<endl;
4864   cout<<endl;
4865   cout<<"<4>_{3n,1n|2n,2n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(16)<<endl;
4866   cout<<"<4>_{3n,1n|2n,2n} from nested loops = "<<fDirectCorrelations->GetBinContent(16)<<endl;
4867   cout<<endl; 
4868   cout<<"<4>_{4n|2n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(17)<<endl;
4869   cout<<"<4>_{4n|2n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(17)<<endl;
4870   cout<<endl;
4871   cout<<"<5>_{2n,1n|1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(19)<<endl;
4872   cout<<"<5>_{2n,1n|1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(19)<<endl;
4873   cout<<endl;
4874   cout<<"<5>_{2n,2n|2n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(20)<<endl;
4875   cout<<"<5>_{2n,2n|2n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(20)<<endl;
4876   cout<<endl;
4877   cout<<"<5>_{3n,1n|2n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(21)<<endl;
4878   cout<<"<5>_{3n,1n|2n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(21)<<endl;
4879   cout<<endl;
4880   cout<<"<5>_{4n|1n,1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(22)<<endl;
4881   cout<<"<5>_{4n|1n,1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(22)<<endl;
4882   cout<<endl;
4883   cout<<"<6>_{1n,1n,1n|1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(24)<<endl;
4884   cout<<"<6>_{1n,1n,1n|1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(24)<<endl;
4885   cout<<endl; 
4886   cout<<"<6>_{2n,1n,1n|2n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(25)<<endl;
4887   cout<<"<6>_{2n,1n,1n|2n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(25)<<endl;
4888   cout<<endl;
4889   cout<<"<6>_{2n,2n|1n,1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(26)<<endl;
4890   cout<<"<6>_{2n,2n|1n,1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(26)<<endl;
4891   cout<<endl; 
4892   cout<<"<6>_{3n,1n|1n,1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(27)<<endl;
4893   cout<<"<6>_{3n,1n|1n,1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(27)<<endl;
4894   cout<<endl; 
4895   cout<<"<7>_{2n,1n,1n|1n,1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(29)<<endl;
4896   cout<<"<7>_{2n,1n,1n|1n,1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(29)<<endl;
4897   cout<<endl; 
4898   cout<<"<8>_{1n,1n,1n,1n|1n,1n,1n,1n} from Q-vectors    = "<<fQCorrelations[0][0]->GetBinContent(31)<<endl;
4899   cout<<"<8>_{1n,1n,1n,1n|1n,1n,1n,1n} from nested loops = "<<fDirectCorrelations->GetBinContent(31)<<endl;
4900   cout<<endl; 
4901   cout<<endl; 
4902   cout<<"   **** results for non-weighted correction terms: ****"<<endl;
4903   cout<<endl;
4904   //.........................................................................................
4905   cout<<"<cos(n*phi1)> from Q-vectors    = "<<fQCorrections[0][0][1]->GetBinContent(1)<<endl;
4906   cout<<"<cos(n*phi1)> from nested loops = "<<fDirectCorrectionsCos->GetBinContent(1)<<endl;
4907   cout<<endl;
4908   cout<<"<sin(n*phi1)> from Q-vectors    = "<<fQCorrections[0][0][0]->GetBinContent(1)<<endl;
4909   cout<<"<sin(n*phi1)> from nested loops = "<<fDirectCorrectionsSin->GetBinContent(1)<<endl;
4910   cout<<endl;  
4911   cout<<"<cos(n*(phi1+phi2))> from Q-vectors    = "<<fQCorrections[0][0][1]->GetBinContent(2)<<endl;
4912   cout<<"<cos(n*(phi1+phi2))> from nested loops = "<<fDirectCorrectionsCos->GetBinContent(2)<<endl;
4913   cout<<endl;
4914   cout<<"<sin(n*(phi1+phi2))> from Q-vectors    = "<<fQCorrections[0][0][0]->GetBinContent(2)<<endl;
4915   cout<<"<sin(n*(phi1+phi2))> from nested loops = "<<fDirectCorrectionsSin->GetBinContent(2)<<endl;
4916   cout<<endl; 
4917   cout<<"<cos(n*(phi1-phi2-phi3))> from Q-vectors    = "<<fQCorrections[0][0][1]->GetBinContent(3)<<endl;
4918   cout<<"<cos(n*(phi1-phi2-phi3))> from nested loops = "<<fDirectCorrectionsCos->GetBinContent(3)<<endl;
4919   cout<<endl;
4920   cout<<"<sin(n*(phi1-phi2-phi3))> from Q-vectors    = "<<fQCorrections[0][0][0]->GetBinContent(3)<<endl;
4921   cout<<"<sin(n*(phi1-phi2-phi3))> from nested loops = "<<fDirectCorrectionsSin->GetBinContent(3)<<endl;
4922   cout<<endl;  
4923   //.........................................................................................
4924  }
4925  
4926  if(useParticleWeights)
4927  {
4928   cout<<"   **** results for weighted correlations: ****"<<endl;
4929   cout<<endl;
4930   //.........................................................................................
4931   cout<<"<w1 w2 cos(n*(phi1-phi2))> from Q-vectors         = "<<fQCorrelations[1][0]->GetBinContent(1)<<endl;
4932   cout<<"<<w1 w2 cos(n*(phi1-phi2))> from nested loops     = "<<fDirectCorrelationsW->GetBinContent(1)<<endl;
4933   cout<<endl;
4934   cout<<"<w1^2 w2^2 cos(2n*(phi1-phi2))> from Q-vectors    = "<<fQCorrelations[1][0]->GetBinContent(2)<<endl;
4935   cout<<"<w1^2 w2^2 cos(2n*(phi1-phi2))> from nested loops = "<<fDirectCorrelationsW->GetBinContent(2)<<endl;
4936   cout<<endl;
4937   cout<<"<w1^3 w2^3 cos(3n*(phi1-phi2))> from Q-vectors    = "<<fQCorrelations[1][0]->GetBinContent(3)<<endl;
4938   cout<<"<w1^3 w2^3 cos(3n*(phi1-phi2))> from nested loops = "<<fDirectCorrelationsW->GetBinContent(3)<<endl;
4939   cout<<endl;
4940   cout<<"<w1^4 w2^4 cos(4n*(phi1-phi2))> from Q-vectors    = "<<fQCorrelations[1][0]->GetBinContent(4)<<endl;
4941   cout<<"<w1^4 w2^4 cos(4n*(phi1-phi2))> from nested loops = "<<fDirectCorrelationsW->GetBinContent(4)<<endl;
4942   cout<<endl;  
4943   /*
4944   cout<<"<w1^3 w2 cos(n*(phi1-phi2))> from Q-vectors       = "<<fQCorrelationsW->GetBinContent(5)<<endl;
4945   cout<<"<w1^3 w2 cos(n*(phi1-phi2))> from nested loops    = "<<fDirectCorrelationsW->GetBinContent(5)<<endl;
4946   cout<<endl;
4947   cout<<"<w1 w2 w3^2 cos(n*(phi1-phi2))> from Q-vectors    = "<<fQCorrelationsW->GetBinContent(6)<<endl;
4948   cout<<"<w1 w2 w3^2 cos(n*(phi1-phi2))> from nested loops = "<<fDirectCorrelationsW->GetBinContent(6)<<endl;
4949   cout<<endl;
4950   cout<<"<w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))> from Q-vectors    = "<<fQCorrelationsW->GetBinContent(21)<<endl;
4951   cout<<"<w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))> from nested loops = "<<fDirectCorrelationsW->GetBinContent(21)<<endl;
4952   cout<<endl;
4953   */ 
4954   cout<<"<w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> from Q-vectors    = "<<fQCorrelations[1][0]->GetBinContent(11)<<endl;
4955   cout<<"<w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> from nested loops = "<<fDirectCorrelationsW->GetBinContent(41)<<endl;
4956   cout<<endl;
4957   //.........................................................................................
4958   //cout<<endl; 
4959   //cout<<endl; 
4960   //cout<<"   **** results for weighted correction terms: ****"<<endl;
4961   //cout<<endl;
4962   //.........................................................................................
4963  }
4964  
4965 } // end of AliFlowAnalysisWithQCumulants::CompareResultsFromNestedLoopsAndFromQVectorsForIntFlow(Bool_t useParticleWeights)
4966
4967
4968 //================================================================================================================================
4969
4970
4971 void AliFlowAnalysisWithQCumulants::CalculateQProductsForIntFlow()
4972 {
4973  // calculate averages like <<2><4>>, <<2><6>>, <<4><6>>, etc. which are needed to calculate covariances 
4974
4975  // binning of fQProducts is organized as follows:
4976  // 
4977  // 1st bin: <2><4> 
4978  // 2nd bin: <2><6>
4979  // 3rd bin: <2><8>
4980  // 4th bin: <4><6>
4981  // 5th bin: <4><8>
4982  // 6th bin: <6><8>
4983
4984  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
4985
4986  Double_t twoEBE = 0.; // <2>
4987  Double_t fourEBE = 0.; // <4>
4988  Double_t sixEBE = 0.; // <6>
4989  Double_t eightEBE = 0.; // <8>
4990  
4991  twoEBE = fQCorrelationsEBE[0]->GetBinContent(1);
4992  fourEBE = fQCorrelationsEBE[0]->GetBinContent(11);
4993  if(dMult>5) 
4994  {
4995   sixEBE = fQCorrelationsEBE[0]->GetBinContent(24);
4996   if(dMult>7) 
4997   { 
4998    eightEBE = fQCorrelationsEBE[0]->GetBinContent(31);
4999   }
5000  }
5001  
5002  // <2><4>
5003  if(dMult>3)
5004  {
5005   fQProducts[0][0]->Fill(0.5,twoEBE*fourEBE,dMult*(dMult-1)*dMult*(dMult-1)*(dMult-2)*(dMult-3));
5006  }
5007  
5008  // <2><6>
5009  if(dMult>5)
5010  {
5011   fQProducts[0][0]->Fill(1.5,twoEBE*sixEBE,dMult*(dMult-1)*dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5));
5012  }
5013  
5014  // <2><8>
5015  if(dMult>7)
5016  {
5017   fQProducts[0][0]->Fill(2.5,twoEBE*eightEBE,dMult*(dMult-1)*dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7));
5018  }
5019  
5020  // <4><6>
5021  if(dMult>5)
5022  {
5023   fQProducts[0][0]->Fill(3.5,fourEBE*sixEBE,dMult*(dMult-1)*(dMult-2)*(dMult-3)*dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5));
5024  }
5025  
5026  // <4><8>
5027  if(dMult>7)
5028  {
5029   fQProducts[0][0]->Fill(4.5,fourEBE*eightEBE,dMult*(dMult-1)*(dMult-2)*(dMult-3)*
5030                                  dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7));
5031  }
5032  
5033  // <6><8>
5034  if(dMult>7)
5035  {
5036   fQProducts[0][0]->Fill(5.5,sixEBE*eightEBE,dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*
5037                                 dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7));
5038  }
5039  
5040 } // end of AliFlowAnalysisWithQCumulants::CalculateQProductsForIntFlow()
5041
5042
5043 //================================================================================================================================
5044
5045
5046 void AliFlowAnalysisWithQCumulants::CalculateCovariancesForIntFlow(Bool_t useParticleWeights, TString eventWeights)
5047 {
5048  // calculate covariances Cov(2,4), Cov(2,6), etc (needed to propagate errors for integrated flow)
5049  
5050  // binning of fCovariances[pW] is organized as follows:
5051  // 
5052  // 1st bin: <<2><4>>-<<2>><<4>> 
5053  // 2nd bin: <<2><6>>-<<2>><<6>>
5054  // 3rd bin: <<2><8>>-<<2>><<8>>
5055  // 4th bin: <<4><6>>-<<4>><<6>>
5056  // 5th bin: <<4><8>>-<<4>><<8>>
5057  // 6th bin: <<6><8>>-<<6>><<8>>
5058  
5059  // shortcuts for flags:
5060  Int_t pW = (Int_t)(useParticleWeights);
5061  Int_t eW = -1;
5062  
5063  if(eventWeights == "exact")
5064  {
5065   eW = 0;
5066  }
5067   
5068  for(Int_t power=0;power<2;power++)
5069  { 
5070   if(!(fQCorrelations[pW][eW] && fQProducts[pW][eW] && fCovariances[pW][eW] && fSumOfEventWeights[pW][eW][power] && fProductOfEventWeights[pW][eW]))
5071   { 
5072    cout<<"WARNING: fQCorrelations[pW][eW] && fQProducts[pW][eW] && fCovariances[pW][eW] && fSumOfEventWeights[pW][eW][power] && fProductOfEventWeights[pW][eW] is NULL in AFAWQC::CCFIF() !!!!"<<endl;
5073    cout<<"pW    = "<<pW<<endl;
5074    cout<<"eW    = "<<eW<<endl;
5075    cout<<"power = "<<power<<endl;
5076    exit(0);
5077   }
5078  } 
5079  
5080  // average 2-, 4-, 6- and 8-particle azimuthal correlations for all events:
5081  Double_t two = fCorrelations[pW][eW]->GetBinContent(1); // <<2>>  
5082  Double_t four = fCorrelations[pW][eW]->GetBinContent(11); // <<4>>  
5083  Double_t six = fCorrelations[pW][eW]->GetBinContent(24); // <<6>>  
5084  Double_t eight = fCorrelations[pW][eW]->GetBinContent(31); // <<8>> 
5085  // average products of 2-, 4-, 6- and 8-particle azimuthal correlations:  
5086  Double_t product24 = fQProducts[pW][eW]->GetBinContent(1); // <<2><4>>  
5087  Double_t product26 = fQProducts[pW][eW]->GetBinContent(2); // <<2><6>>  
5088  Double_t product28 = fQProducts[pW][eW]->GetBinContent(3); // <<2><8>>  
5089  Double_t product46 = fQProducts[pW][eW]->GetBinContent(4); // <<4><6>> 
5090  Double_t product48 = fQProducts[pW][eW]->GetBinContent(5); // <<4><8>>  
5091  Double_t product68 = fQProducts[pW][eW]->GetBinContent(6); // <<6><8>>
5092  // denominator in the expression for the unbiased estimator for covariance:
5093  Double_t denom24 = 0.; 
5094  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(1) && fSumOfEventWeights[pW][eW][0]->GetBinContent(2))
5095  {
5096   denom24 = 1-(fProductOfEventWeights[pW][eW]->GetBinContent(1))/
5097               (fSumOfEventWeights[pW][eW][0]->GetBinContent(1) * fSumOfEventWeights[pW][eW][0]->GetBinContent(2));
5098  }
5099  Double_t denom26 = 0.; 
5100  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(1) && fSumOfEventWeights[pW][eW][0]->GetBinContent(3))
5101  {
5102   denom26 = 1-(fProductOfEventWeights[pW][eW]->GetBinContent(2))/
5103               (fSumOfEventWeights[pW][eW][0]->GetBinContent(1) * fSumOfEventWeights[pW][eW][0]->GetBinContent(3));
5104  }
5105  Double_t denom28 = 0.; 
5106  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(1) && fSumOfEventWeights[pW][eW][0]->GetBinContent(4))
5107  {
5108   denom28 = 1-(fProductOfEventWeights[pW][eW]->GetBinContent(3))/
5109               (fSumOfEventWeights[pW][eW][0]->GetBinContent(1) * fSumOfEventWeights[pW][eW][0]->GetBinContent(4));
5110  }
5111  Double_t denom46 = 0.; 
5112  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(2) && fSumOfEventWeights[pW][eW][0]->GetBinContent(3))
5113  {
5114   denom46 = 1-(fProductOfEventWeights[pW][eW]->GetBinContent(4))/
5115               (fSumOfEventWeights[pW][eW][0]->GetBinContent(2) * fSumOfEventWeights[pW][eW][0]->GetBinContent(3));
5116  }
5117  Double_t denom48 = 0.; 
5118  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(2) && fSumOfEventWeights[pW][eW][0]->GetBinContent(4))
5119  {
5120   denom48 = 1-(fProductOfEventWeights[pW][eW]->GetBinContent(5))/
5121               (fSumOfEventWeights[pW][eW][0]->GetBinContent(2) * fSumOfEventWeights[pW][eW][0]->GetBinContent(4));
5122  }
5123  Double_t denom68 = 0.; 
5124  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(3) && fSumOfEventWeights[pW][eW][0]->GetBinContent(4))
5125  {
5126   denom68 = 1-(fProductOfEventWeights[pW][eW]->GetBinContent(6))/
5127               (fSumOfEventWeights[pW][eW][0]->GetBinContent(3) * fSumOfEventWeights[pW][eW][0]->GetBinContent(4));
5128  }
5129  
5130  // final covariances: 
5131  Double_t cov24 = 0.;
5132  if(denom24)
5133  {
5134   cov24 = (product24-two*four)/denom24; // Cov(<2>,<4>) 
5135   fCovariances[pW][eW]->SetBinContent(1,cov24);
5136  } 
5137  Double_t cov26 = 0.;
5138  if(denom26)
5139  {
5140   cov26 = (product26-two*six)/denom26; // Cov(<2>,<6>) 
5141   fCovariances[pW][eW]->SetBinContent(2,cov26);
5142  } 
5143  Double_t cov28 = 0.;
5144  if(denom28)
5145  {
5146   cov28 = (product28-two*eight)/denom28; // Cov(<2>,<8>) 
5147   fCovariances[pW][eW]->SetBinContent(3,cov28);
5148  } 
5149  Double_t cov46 = 0.;
5150  if(denom46)
5151  {
5152   cov46 = (product46-four*six)/denom46; // Cov(<4>,<6>) 
5153   fCovariances[pW][eW]->SetBinContent(4,cov46);
5154  } 
5155  Double_t cov48 = 0.;
5156  if(denom48)
5157  {
5158   cov48 = (product48-four*eight)/denom48; // Cov(<4>,<8>) 
5159   fCovariances[pW][eW]->SetBinContent(5,cov48);
5160  } 
5161  Double_t cov68 = 0.;
5162  if(denom68)
5163  {
5164   cov68 = (product68-six*eight)/denom68; // Cov(<6>,<8>) 
5165   fCovariances[pW][eW]->SetBinContent(6,cov68);
5166  } 
5167
5168 } // end of AliFlowAnalysisWithQCumulants::CalculateCovariancesForIntFlow(Bool_t useParticleWeights, TString eventWeights)
5169
5170
5171 //================================================================================================================================
5172
5173
5174 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForIntFlow(Bool_t useParticleWeights, TString eventWeights) // to be improved (there is better way to implement this method)
5175 {
5176  // From fQCorrelations[pW][eW] access measured correlations and spread, calculate statistical errors and store the
5177  // final results and statistical errors for correlations in fCorrelations[pW][eW] (binning is the same as in fQCorrelations[pW][eW]).
5178  
5179  // shortcuts for flags:
5180  Int_t pW = (Int_t)(useParticleWeights);
5181  
5182  Int_t eW = -1;
5183  
5184  if(eventWeights == "exact")
5185  {
5186   eW = 0;
5187  }
5188  
5189  for(Int_t power=0;power<2;power++)
5190  {
5191   if(!(fQCorrelations[pW][eW] && fCorrelations[pW][eW] && fSumOfEventWeights[pW][eW][power])) 
5192   {
5193    cout<<"WARNING: fQCorrelations[pW][eW] && fCorrelations[pW][eW] && fSumOfEventWeights[pW][eW][power] is NULL in AFAWQC::FCFIF() !!!!"<<endl;
5194    cout<<"pW    = "<<pW<<endl;
5195    cout<<"eW    = "<<eW<<endl;
5196    cout<<"power = "<<power<<endl;
5197    exit(0);
5198   }
5199  }
5200  
5201  // <<2>>:
5202  Double_t correlation2p = fQCorrelations[pW][eW]->GetBinContent(1);  
5203  Double_t spread2p = fQCorrelations[pW][eW]->GetBinError(1); 
5204  Double_t sumOfEventWeightsLinear2p = fSumOfEventWeights[pW][eW][0]->GetBinContent(1);
5205  Double_t sumOfEventWeightsQuadratic2p = fSumOfEventWeights[pW][eW][1]->GetBinContent(1);
5206  // stat.error = termA * spread * termB:
5207  // termB = 1/sqrt(1-termA^2)
5208  Double_t termA2p = 0.;  
5209  Double_t termB2p = 0.;
5210  Double_t statError2p = 0.;
5211  if(sumOfEventWeightsLinear2p)
5212  {
5213   termA2p = pow(sumOfEventWeightsQuadratic2p,0.5)/sumOfEventWeightsLinear2p;
5214  } else
5215    {
5216     cout<<"WARNING: sumOfEventWeightsLinear2p == 0 in in AFAWQC::FCFIF() !!!!"<<endl;
5217    }
5218       
5219  if(1-pow(termA2p,2.) > 0)
5220  {
5221   termB2p = 1./pow(1-pow(termA2p,2.),0.5);
5222  } else
5223    {
5224     cout<<"WARNING: 1-pow(termA2p,2.) <= 0 in in AFAWQC::FCFIF() !!!!"<<endl;   
5225    }     
5226    
5227  statError2p = termA2p*spread2p*termB2p;
5228  fCorrelations[pW][eW]->SetBinContent(1,correlation2p);
5229  fCorrelations[pW][eW]->SetBinError(1,statError2p);
5230          
5231  // <<4>>:
5232  Double_t correlation4p = fQCorrelations[pW][eW]->GetBinContent(11);  
5233  Double_t spread4p = fQCorrelations[pW][eW]->GetBinError(11); 
5234  Double_t sumOfEventWeightsLinear4p = fSumOfEventWeights[pW][eW][0]->GetBinContent(2);
5235  Double_t sumOfEventWeightsQuadratic4p = fSumOfEventWeights[pW][eW][1]->GetBinContent(2);
5236  Double_t termA4p = 0.;  
5237  Double_t termB4p = 0.;
5238  Double_t statError4p = 0.;
5239  if(sumOfEventWeightsLinear4p)
5240  {
5241   termA4p = pow(sumOfEventWeightsQuadratic4p,0.5)/sumOfEventWeightsLinear4p;
5242  } else
5243    {
5244     cout<<"WARNING: sumOfEventWeightsLinear4p == 0 in in AFAWQC::FCFIF() !!!!"<<endl;
5245    }
5246  if(1-pow(termA4p,2.) > 0)
5247  {
5248   termB4p = 1./pow(1-pow(termA4p,2.),0.5);
5249  } else
5250    {
5251     cout<<"WARNING: 1-pow(termA4p,2.) <= 0 in in AFAWQC::FCFIF() !!!!"<<endl;   
5252    }  
5253    
5254  statError4p = termA4p*spread4p*termB4p;
5255  fCorrelations[pW][eW]->SetBinContent(11,correlation4p);
5256  fCorrelations[pW][eW]->SetBinError(11,statError4p);
5257
5258  // <<6>>:
5259  Double_t correlation6p = fQCorrelations[pW][eW]->GetBinContent(24);  
5260  Double_t spread6p = fQCorrelations[pW][eW]->GetBinError(24); 
5261  Double_t sumOfEventWeightsLinear6p = fSumOfEventWeights[pW][eW][0]->GetBinContent(3);
5262  Double_t sumOfEventWeightsQuadratic6p = fSumOfEventWeights[pW][eW][1]->GetBinContent(3);
5263  Double_t termA6p = 0.;  
5264  Double_t termB6p = 0.;
5265  Double_t statError6p = 0.;
5266  if(sumOfEventWeightsLinear6p)
5267  {
5268   termA6p = pow(sumOfEventWeightsQuadratic6p,0.5)/sumOfEventWeightsLinear6p;
5269  } else
5270    {
5271     cout<<"WARNING: sumOfEventWeightsLinear6p == 0 in in AFAWQC::FCFIF() !!!!"<<endl;
5272    }
5273  if(1-pow(termA6p,2.) > 0)
5274  {
5275   termB6p = 1./pow(1-pow(termA6p,2.),0.5);
5276  } else
5277    {
5278     cout<<"WARNING: 1-pow(termA6p,2.) <= 0 in in AFAWQC::FCFIF() !!!!"<<endl;   
5279    }  
5280    
5281  statError6p = termA6p*spread6p*termB6p;
5282  fCorrelations[pW][eW]->SetBinContent(24,correlation6p);
5283  fCorrelations[pW][eW]->SetBinError(24,statError6p);
5284               
5285  // <<8>>             
5286  Double_t correlation8p = fQCorrelations[pW][eW]->GetBinContent(31);  
5287  // ...
5288  fCorrelations[pW][eW]->SetBinContent(31,correlation8p);
5289  // ... 
5290                           
5291 } // end of AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
5292
5293
5294 //================================================================================================================================
5295
5296
5297 void AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(Int_t nRP)
5298 {
5299  // Fill profile fAverageMultiplicity to hold average multiplicities and number of events for events with nRP>=0, nRP>=1, ... , and nRP>=8
5300  
5301  // Binning of fAverageMultiplicity is organized as follows:
5302  //  1st bin: all events (including the empty ones)
5303  //  2nd bin: event with # of RPs greater or equal to 1
5304  //  3rd bin: event with # of RPs greater or equal to 2
5305  //  4th bin: event with # of RPs greater or equal to 3
5306  //  5th bin: event with # of RPs greater or equal to 4
5307  //  6th bin: event with # of RPs greater or equal to 5
5308  //  7th bin: event with # of RPs greater or equal to 6
5309  //  8th bin: event with # of RPs greater or equal to 7
5310  //  9th bin: event with # of RPs greater or equal to 8
5311  
5312  if(!fAvMultiplicity)
5313  {
5314   cout<<"WARNING: fAvMultiplicity is NULL in AFAWQC::FAM() !!!!"<<endl;
5315   exit(0);
5316  }
5317  
5318  if(nRP<0)
5319  {
5320   cout<<"WARNING: nRP<0 in in AFAWQC::FAM() !!!!"<<endl;
5321   exit(0);
5322  }
5323  
5324  for(Int_t i=0;i<9;i++)
5325  {
5326   if(nRP>=i) fAvMultiplicity->Fill(i+0.5,nRP,1);
5327  }
5328  
5329 } // end of AliFlowAnalysisWithQCumulants::FillAverageMultiplicities(nRP)
5330
5331
5332 //================================================================================================================================
5333
5334
5335 void AliFlowAnalysisWithQCumulants::CalculateCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
5336 {
5337  // calculate cumulants from measured correlations and store results in fCumulants[pW][eW][0]. 
5338  // (Remark: these cumulants are biased by non-uniform acceptance, corrected cumulants are stored in fCumulants[pW][eW][1].)
5339  
5340  // Binning of fCumulants[pW][nua] is organized as follows:
5341  //  1st bin: QC{2}
5342  //  2nd bin: QC{4}
5343  //  3rd bin: QC{6}
5344  //  4th bin: QC{8}
5345  
5346  // shortcuts for the flags:
5347  Int_t pW = (Int_t)(useParticleWeights); // (0=weights not used, 1=weights used)
5348  
5349  Int_t eW = -1;
5350  
5351  if(eventWeights == "exact")
5352  {
5353   eW = 0;
5354  }
5355  
5356  if(!(fCorrelations[pW][eW] && fCovariances[pW][eW] && fCumulants[pW][eW][0] && fAvMultiplicity))
5357  {
5358   cout<<"WARNING: fCorrelations[pW][eW] && fCovariances[pW][eW] && fCumulants[pW][eW][0] && fAvMultiplicity is NULL in AFAWQC::CCFIF() !!!!"<<endl;
5359   cout<<"pW = "<<pW<<endl;
5360   cout<<"eW = "<<eW<<endl;
5361   exit(0);
5362  }
5363  
5364  // correlations:
5365  Double_t two = fCorrelations[pW][eW]->GetBinContent(1); // <<2>> 
5366  Double_t four = fCorrelations[pW][eW]->GetBinContent(11); // <<4>>  
5367  Double_t six = fCorrelations[pW][eW]->GetBinContent(24); // <<6>> 
5368  Double_t eight = fCorrelations[pW][eW]->GetBinContent(31); // <<8>>  
5369  // stat. error of correlations:
5370  Double_t twoError = fCorrelations[pW][eW]->GetBinError(1); // stat. error of <<2>>   
5371  Double_t fourError = fCorrelations[pW][eW]->GetBinError(11); // stat. error of <<4>>  
5372  Double_t sixError = fCorrelations[pW][eW]->GetBinError(24); // stat. error of <<6>>  
5373  //Double_t eightError = fQCorrelations[pW]->GetBinError(31); // stat. error of <<8>>
5374  // spread of correlations:
5375  Double_t twoSpread = 0.; // spread of <<2>>
5376  Double_t fourSpread = 0.; // spread of <<6>>
5377  Double_t sixSpread = 0.; // spread of <<8>>
5378  //Double_t eightSpread = 0.;
5379  // stat. error = prefactor * spread:
5380  Double_t twoPrefactor = 0; 
5381  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(1))
5382  {
5383   twoPrefactor = pow(fSumOfEventWeights[pW][eW][1]->GetBinContent(1),0.5)/fSumOfEventWeights[pW][eW][0]->GetBinContent(1);
5384   if(twoPrefactor) twoSpread = twoError/twoPrefactor;
5385  }
5386  Double_t fourPrefactor = 0; 
5387  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(2))
5388  {
5389   fourPrefactor = pow(fSumOfEventWeights[pW][eW][1]->GetBinContent(2),0.5)/fSumOfEventWeights[pW][eW][0]->GetBinContent(2);
5390   if(fourPrefactor) fourSpread = fourError/fourPrefactor;
5391  }
5392  Double_t sixPrefactor = 0; 
5393  if(fSumOfEventWeights[pW][eW][0]->GetBinContent(3))
5394  {
5395   sixPrefactor = pow(fSumOfEventWeights[pW][eW][1]->GetBinContent(3),0.5)/fSumOfEventWeights[pW][eW][0]->GetBinContent(3);
5396   if(sixPrefactor) sixSpread = sixError/sixPrefactor;
5397  }
5398  // ... 8th
5399  // covariances:
5400  Double_t cov24 = fCovariances[pW][eW]->GetBinContent(1); // Cov(<2>,<4>)
5401  Double_t cov26 = fCovariances[pW][eW]->GetBinContent(2); // Cov(<2>,<6>) 
5402  //Double_t cov28 = fCovariances[pW]->GetBinContent(3); // Cov(<2>,<8>)
5403  Double_t cov46 = fCovariances[pW][eW]->GetBinContent(4); // Cov(<4>,<6>)
5404  //Double_t cov48 = fCovariances[pW]->GetBinContent(5); // Cov(<4>,<8>) 
5405  //Double_t cov68 = fCovariances[pW]->GetBinContent(6); // Cov(<6>,<8>)  
5406  // cumulants: 
5407  Double_t qc2 = 0.; // QC{2}
5408  Double_t qc4 = 0.; // QC{4}
5409  Double_t qc6 = 0.; // QC{6}
5410  Double_t qc8 = 0.; // QC{8}
5411  
5412  if(two) qc2 = two; 
5413  if(four) qc4 = four-2.*pow(two,2.); 
5414  if(six) qc6 = six-9.*two*four+12.*pow(two,3.); 
5415  if(eight) qc8 = eight-16.*two*six-18.*pow(four,2.)+144.*pow(two,2.)*four-144.*pow(two,4.); 
5416  
5417  // stat. error of cumulants:
5418  Double_t qc2Error = 0; // stat. error of QC{2}
5419  Double_t qc4Error = 0; // stat. error of QC{4}
5420  Double_t qc6Error = 0; // stat. error of QC{6}
5421  // Double_t qc8Error = 0; // stat. error of QC{8} // to be improved (calculated)
5422  // spread of cumulants:
5423  //Double_t qc2Spread = 0; // spread of QC{2}
5424  Double_t qc4Spread = 0; // spread of QC{4}
5425  Double_t qc6Spread = 0; // spread of QC{6}
5426  // Double_t qc8Spread = 0; // spread of QC{8} // to be improved (calculated)
5427  
5428  qc2Error = twoError; // final stat. error of QC{2}
5429  
5430  if(16.*pow(two,2.)*pow(twoSpread,2.)+pow(fourSpread,2.)-8.*two*cov24 >= 0.)
5431  {
5432   qc4Spread = pow(16.*pow(two,2.)*pow(twoSpread,2.)+pow(fourSpread,2.)-8.*two*cov24,0.5); 
5433  } else
5434    {
5435     cout<<"WARNING: spread of QC{4} is imaginary !!!!"<<endl;
5436    }
5437   
5438  qc4Error = fourPrefactor*qc4Spread; // final stat. error of QC{4}  
5439      
5440  if(81.*pow(4.*pow(two,2.)-four,2.)*pow(twoSpread,2.)   
5441     + 81.*pow(two,2.)*pow(fourSpread,2.)+pow(sixSpread,2.) 
5442     - 162.*(4.*pow(two,2.)-four)*two*cov24
5443     + 18.*(4.*pow(two,2.)-four)*cov26
5444     - 18.*two*cov46 >= 0.)
5445  {  
5446   qc6Spread = pow(81.*pow(4.*pow(two,2.)-four,2.)*pow(twoSpread,2.)   
5447                   + 81.*pow(two,2.)*pow(fourSpread,2.)+pow(sixSpread,2.) 
5448                   - 162.*(4.*pow(two,2.)-four)*two*cov24
5449                   + 18.*(4.*pow(two,2.)-four)*cov26
5450                   - 18.*two*cov46,0.5);
5451  } else 
5452    {
5453     cout<<"WARNING: stat. error of QC{6} is imaginary !!!!"<<endl;
5454    }          
5455    
5456  qc6Error = sixPrefactor*qc6Spread; // final stat. error of QC{6} 
5457    
5458  // store the results and statistical errors for cumulants:
5459  fCumulants[pW][eW][0]->SetBinContent(1,qc2);
5460  fCumulants[pW][eW][0]->SetBinError(1,qc2Error);
5461  fCumulants[pW][eW][0]->SetBinContent(2,qc4);
5462  fCumulants[pW][eW][0]->SetBinError(2,qc4Error);
5463  fCumulants[pW][eW][0]->SetBinContent(3,qc6);
5464  fCumulants[pW][eW][0]->SetBinError(3,qc6Error);
5465  fCumulants[pW][eW][0]->SetBinContent(4,qc8); 
5466  // fCumulants[pW]->SetBinError(4,qc8Error); // to be improved (calculated)
5467    
5468 } // end of AliFlowAnalysisWithQCumulants::CalculateCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
5469
5470
5471 //================================================================================================================================ 
5472
5473
5474 void AliFlowAnalysisWithQCumulants::CalculateIntFlow(Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
5475 {
5476  // calculate final results for integrated flow 
5477  
5478  // Results for integrated flow are stored in fInfFlow[pW][nua]. Binning of fIntFlow[pW][nua] is organized as follows:
5479  //  1st bin: v{2}
5480  //  2nd bin: v{4}
5481  //  3rd bin: v{6}
5482  //  4th bin: v{8}
5483  
5484  // shortcuts for the flags:
5485  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not useed, 1=pWeights used
5486  Int_t nua = (Int_t)(correctedForNUA); // 0=not corrected for NUA, 1=corrected for NUA
5487  Int_t eW = -1;
5488  
5489  if(eventWeights = "exact")
5490  {
5491   eW = 0;
5492  }
5493    
5494  if(!(fCumulants[pW][eW][nua] && fIntFlow[pW][eW][nua]))
5495  {
5496   cout<<"WARNING: fCumulants[pW][eW][nua] && fIntFlow[pW][eW][nua] is NULL in AFAWQC::CIF() !!!!"<<endl;
5497   cout<<"pW = "<<pW<<endl;
5498   cout<<"eW = "<<eW<<endl;
5499   cout<<"nua = "<<nua<<endl;
5500   exit(0);
5501  }
5502    
5503  // cumulants:
5504  Double_t qc2 = fCumulants[pW][eW][nua]->GetBinContent(1); // QC{2}  
5505  Double_t qc4 = fCumulants[pW][eW][nua]->GetBinContent(2); // QC{4}  
5506  Double_t qc6 = fCumulants[pW][eW][nua]->GetBinContent(3); // QC{6}  
5507  Double_t qc8 = fCumulants[pW][eW][nua]->GetBinContent(4); // QC{8}
5508    
5509  // cumulants' statistical errors:
5510  Double_t qc2Error = fCumulants[pW][eW][nua]->GetBinError(1); // error of QC{2}  
5511  Double_t qc4Error = fCumulants[pW][eW][nua]->GetBinError(2); // error of QC{4}  
5512  Double_t qc6Error = fCumulants[pW][eW][nua]->GetBinError(3); // error of QC{6}  
5513  //Double_t qc8Error = fCumulants[pW][nua]->GetBinError(4); // error of QC{8}
5514    
5515  // integrated flow estimates:
5516  Double_t v2 = 0.; // v{2}  
5517  Double_t v4 = 0.; // v{4}  
5518  Double_t v6 = 0.; // v{6}  
5519  Double_t v8 = 0.; // v{8}
5520  
5521  // calculate integrated flow estimates from cumulants: 
5522  if(qc2>=0.) v2 = pow(qc2,1./2.); 
5523  if(qc4<=0.) v4 = pow(-1.*qc4,1./4.); 
5524  if(qc6>=0.) v6 = pow((1./4.)*qc6,1./6.); 
5525  if(qc8<=0.) v8 = pow((-1./33.)*qc8,1./8.); 
5526    
5527  // statistical errors of integrated flow estimates:
5528  Double_t v2Error = 0.; // error of v{2}  
5529  Double_t v4Error = 0.; // error of v{4}  
5530  Double_t v6Error = 0.; // error of v{6}  
5531  Double_t v8Error = 0.; // error of v{8}
5532    
5533  // calculate statistical errors for integrated flow estimates:
5534  if(qc2>0.) v2Error = (1./(2.*pow(qc2,0.5)))*qc2Error; 
5535  if(qc4<0.) v4Error = (1./(4.*pow(-1.*qc4,3./4.)))*qc4Error; 
5536  if(qc6>0.) v6Error = (1./(6.*pow(2.,1./3.)*pow(qc6,5./6.)))*qc6Error;
5537  if(qc8<0.) v8Error = 0.; // to be improved (calculated)
5538   
5539  // store final results and statistical errors for integrated flow:
5540  fIntFlow[pW][eW][nua]->SetBinContent(1,v2);
5541  fIntFlow[pW][eW][nua]->SetBinError(1,v2Error);
5542  fIntFlow[pW][eW][nua]->SetBinContent(2,v4);
5543  fIntFlow[pW][eW][nua]->SetBinError(2,v4Error);
5544  fIntFlow[pW][eW][nua]->SetBinContent(3,v6);
5545  fIntFlow[pW][eW][nua]->SetBinError(3,v6Error);
5546  fIntFlow[pW][eW][nua]->SetBinContent(4,v8);
5547  fIntFlow[pW][eW][nua]->SetBinError(4,v8Error);
5548      
5549 } // end of AliFlowAnalysisWithQCumulants::CalculateIntFlow(Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
5550
5551
5552 //================================================================================================================================ 
5553
5554
5555 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow(Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
5556 {
5557  // fill in AliFlowCommonHistResults histograms relevant for 'NONAME' integrated flow (to be improved (name))
5558  
5559  // shortcuts for the flags:
5560  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not useed, 1=pWeights used
5561  Int_t nua = (Int_t)(correctedForNUA); // 0=not corrected for NUA, 1=corrected for NUA
5562  Int_t eW = -1;
5563  
5564  if(eventWeights == "exact")
5565  {
5566   eW = 0;
5567  }
5568  
5569  if(!fIntFlow[pW][eW][nua])
5570  {
5571   cout<<"WARNING: fIntFlow[pW][eW][nua] is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
5572   cout<<"pW = "<<pW<<endl;
5573   cout<<"eW = "<<eW<<endl;
5574   cout<<"nua = "<<nua<<endl;
5575   exit(0); 
5576  }  
5577     
5578  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
5579  {
5580   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
5581   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
5582   exit(0);
5583  }
5584  
5585  Double_t v2 = fIntFlow[pW][eW][nua]->GetBinContent(1);
5586  Double_t v4 = fIntFlow[pW][eW][nua]->GetBinContent(2);
5587  Double_t v6 = fIntFlow[pW][eW][nua]->GetBinContent(3);
5588  Double_t v8 = fIntFlow[pW][eW][nua]->GetBinContent(4);
5589   
5590  Double_t v2Error = fIntFlow[pW][eW][nua]->GetBinError(1);
5591  Double_t v4Error = fIntFlow[pW][eW][nua]->GetBinError(2);
5592  Double_t v6Error = fIntFlow[pW][eW][nua]->GetBinError(3);
5593  Double_t v8Error = fIntFlow[pW][eW][nua]->GetBinError(4);
5594  
5595  fCommonHistsResults2nd->FillIntegratedFlow(v2,v2Error); 
5596  fCommonHistsResults4th->FillIntegratedFlow(v4,v4Error); 
5597  fCommonHistsResults6th->FillIntegratedFlow(v6,v6Error); 
5598  fCommonHistsResults8th->FillIntegratedFlow(v8,v8Error);  
5599
5600 } // end of AliFlowAnalysisWithQCumulants::FillCommonHistResultsIntFlow(Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
5601
5602
5603 //================================================================================================================================ 
5604
5605
5606 void AliFlowAnalysisWithQCumulants::ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
5607 {
5608  // apply correction for non-uniform acceptance to cumulants for integrated flow 
5609  // (Remark: non-corrected cumulants are accessed from fCumulants[pW][0], corrected cumulants are stored in fCumulants[pW][1])
5610    
5611  // shortcuts for the flags:
5612  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not used, 1=pWeights used
5613  Int_t eW = -1;
5614  
5615  if(eventWeights == "exact")
5616  {
5617   eW = 0;
5618  }
5619  
5620  if(!(fCumulants[pW][eW][0] && fCumulants[pW][eW][1] && fCorrections[pW][eW]))
5621  {
5622   cout<<"WARNING: fCumulants[pW][eW][0] && fCumulants[pW][eW][1] && fCorrections[pW][eW] is NULL in AFAWQC::ACFNUATCFIF() !!!!"<<endl;
5623   cout<<"pW = "<<pW<<endl;
5624   cout<<"eW = "<<eW<<endl;
5625   exit(0);
5626  } 
5627  
5628  // non-corrected cumulants:
5629  Double_t qc2 = fCumulants[pW][eW][0]->GetBinContent(1); 
5630  Double_t qc4 = fCumulants[pW][eW][0]->GetBinContent(2); 
5631  Double_t qc6 = fCumulants[pW][eW][0]->GetBinContent(3); 
5632  Double_t qc8 = fCumulants[pW][eW][0]->GetBinContent(4); 
5633  // statistical error of non-corrected cumulants:  
5634  Double_t qc2Error = fCumulants[pW][eW][0]->GetBinError(1); 
5635  Double_t qc4Error = fCumulants[pW][eW][0]->GetBinError(2); 
5636  Double_t qc6Error = fCumulants[pW][eW][0]->GetBinError(3); 
5637  Double_t qc8Error = fCumulants[pW][eW][0]->GetBinError(4); 
5638  // corrections for non-uniform acceptance:
5639  Double_t qc2Correction = fCorrections[pW][eW]->GetBinContent(1); 
5640  Double_t qc4Correction = fCorrections[pW][eW]->GetBinContent(2); 
5641  Double_t qc6Correction = fCorrections[pW][eW]->GetBinContent(3); 
5642  Double_t qc8Correction = fCorrections[pW][eW]->GetBinContent(4); 
5643  // corrected cumulants:
5644  Double_t qc2Corrected = qc2 + qc2Correction;
5645  Double_t qc4Corrected = qc4 + qc4Correction;
5646  Double_t qc6Corrected = qc6 + qc6Correction;
5647  Double_t qc8Corrected = qc8 + qc8Correction;
5648   
5649  // ... to be improved (I need here also to correct error of QCs for NUA. 
5650  // For simplicity sake I assume at the moment that this correction is negliglible, but it will be added eventually...)
5651  
5652  // store corrected results and statistical errors for cumulants:   
5653  fCumulants[pW][eW][1]->SetBinContent(1,qc2Corrected);
5654  fCumulants[pW][eW][1]->SetBinContent(2,qc4Corrected);
5655  fCumulants[pW][eW][1]->SetBinContent(3,qc6Corrected);
5656  fCumulants[pW][eW][1]->SetBinContent(4,qc8Corrected);
5657  fCumulants[pW][eW][1]->SetBinError(1,qc2Error); // to be improved (correct also qc2Error for NUA)
5658  fCumulants[pW][eW][1]->SetBinError(2,qc4Error); // to be improved (correct also qc4Error for NUA)
5659  fCumulants[pW][eW][1]->SetBinError(3,qc6Error); // to be improved (correct also qc6Error for NUA)
5660  fCumulants[pW][eW][1]->SetBinError(4,qc8Error); // to be improved (correct also qc8Error for NUA)  
5661  
5662 } // end of AliFlowAnalysisWithQCumulants::ApplyCorrectionForNonUniformAcceptanceToCumulantsForIntFlow(Bool_t useParticleWeights, TString eventWeights)
5663
5664
5665 //================================================================================================================================
5666
5667   
5668 void AliFlowAnalysisWithQCumulants::PrintQuantifyingCorrectionsForNonUniformAcceptance(Bool_t useParticleWeights, TString eventWeights)
5669 {
5670  // print on the screen QC{n,biased}/QC{n,corrected}
5671  
5672  // shortcuts for the flags:
5673  Int_t pW = (Int_t)(useParticleWeights); // 0=pWeights not used, 1=pWeights used
5674  
5675  Int_t eW = -1;
5676  
5677  if(eventWeights == "exact")
5678  {
5679   eW = 0;
5680  } 
5681  
5682  if(!(fCumulants[pW][eW][0] && fCumulants[pW][eW][1]))
5683  {
5684   cout<<"WARNING: fCumulants[pW][eW][0] && fCumulants[pW][eW][1] is NULL in AFAWQC::PQCFNUA() !!!!"<<endl;
5685   cout<<"pW = "<<pW<<endl;
5686   cout<<"eW = "<<eW<<endl;
5687   exit(0);
5688  }
5689    
5690  cout<<endl;
5691  cout<<" Quantifying the bias to Q-cumulants from"<<endl;
5692  cout<<"  non-uniform acceptance of the detector:"<<endl;
5693  cout<<endl;
5694   
5695  if(fCumulants[pW][eW][1]->GetBinContent(1)) 
5696  { 
5697   cout<<"  QC{2,biased}/QC{2,corrected} = "<<(fCumulants[pW][eW][0]->GetBinContent(1))/(fCumulants[pW][eW][1]->GetBinContent(1))<<endl;   
5698  }
5699  if(fCumulants[pW][eW][1]->GetBinContent(2)) 
5700  { 
5701   cout<<"  QC{4,biased}/QC{4,corrected} = "<<fCumulants[pW][eW][0]->GetBinContent(2)/fCumulants[pW][eW][1]->GetBinContent(2)<<endl;   
5702  }
5703  
5704  cout<<endl;
5705    
5706 } // end of AliFlowAnalysisWithQCumulants::PrintQuantifyingCorrectionsForNonUniformAcceptance(Bool_t useParticleWeights, TString eventWeights)
5707
5708
5709 //================================================================================================================================
5710
5711
5712 void AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForIntegratedFlow()
5713 {
5714  // calculate all weighted correlations needed for integrated flow and store them in 1D profile fQCorrelations[1][eW] and fQExtraCorrelations[1][eW]
5715  
5716  for(Int_t eW=0;eW<2;eW++)
5717  {
5718   if(!(fQCorrelationsEBE[1] && fQCorrelations[1][eW]))
5719   {
5720    cout<<"WARNING: fQCorrelationsEBE[1] && fQCorrelations[1][eW] is NULL in AFAWQC::CWCFIF() !!!!"<<endl;
5721    cout<<"eW = "<<eW<<endl;
5722    exit(0);
5723   }
5724  }
5725  
5726  // Remark 1: binning of fQCorrelations[W] is organized as follows:
5727  //..............................................................................................
5728  //       ---- bins 1-20: 2-particle correlations ----
5729  // 1st bin: two1n1nW1W1 = <w1 w2 cos(n*(phi1-phi2))>
5730  // 2nd bin: two2n2nW2W2 = <w1^2 w2^2 cos(2n*(phi1-phi2))>
5731  // 3rd bin: two3n3nW3W3 = <w1^3 w2^3 cos(3n*(phi1-phi2))>
5732  // 4th bin: two4n4nW4W4 = <w1^4 w2^4 cos(4n*(phi1-phi2))>
5733  // 5th bin: two1n1nW3W1 = <w1^3 w2 cos(n*(phi1-phi2))>
5734  // 6th bin: two1n1nW1W1W2 = <w1 w2 w3^2 cos(n*(phi1-phi2))>  
5735  //       ---- bins 21-40: 3-particle correlations ----
5736  // 21st bin: three2n1n1nW2W1W1 = <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))> 
5737  //       ---- bins 41-60: 4-particle correlations ----
5738  // 41st bin: four1n1n1n1nW1W1W1W1 = <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
5739  //       ---- bins 61-80: 5-particle correlations ---- 
5740  //       ---- bins 81-100: 6-particle correlations ----
5741  //       ---- bins 101-120: 7-particle correlations ----
5742  //       ---- bins 121-140: 8-particle correlations ----
5743  //..............................................................................................
5744  
5745  // multiplicity (number of particles used to determine the reaction plane)
5746  Double_t dMult = (*fSMpk)(0,0);
5747  
5748  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
5749  Double_t dReQ1n1k = (*fReQ)(0,1);
5750  Double_t dReQ2n2k = (*fReQ)(1,2);
5751  Double_t dReQ3n3k = (*fReQ)(2,3);
5752  Double_t dReQ4n4k = (*fReQ)(3,4);
5753  Double_t dReQ1n3k = (*fReQ)(0,3);
5754  Double_t dImQ1n1k = (*fImQ)(0,1);
5755  Double_t dImQ2n2k = (*fImQ)(1,2);
5756  Double_t dImQ3n3k = (*fImQ)(2,3);
5757  Double_t dImQ4n4k = (*fImQ)(3,4);
5758  Double_t dImQ1n3k = (*fImQ)(0,3);
5759
5760  // dMs are variables introduced in order to simplify some Eqs. bellow:
5761  //..............................................................................................
5762  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
5763  Double_t dM22 = (*fSMpk)(1,2)-(*fSMpk)(0,4); // dM22 = sum_{i,j=1,i!=j}^M w_i^2 w_j^2
5764  Double_t dM33 = (*fSMpk)(1,3)-(*fSMpk)(0,6); // dM33 = sum_{i,j=1,i!=j}^M w_i^3 w_j^3
5765  Double_t dM44 = (*fSMpk)(1,4)-(*fSMpk)(0,8); // dM44 = sum_{i,j=1,i!=j}^M w_i^4 w_j^4
5766  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
5767  Double_t dM211 = (*fSMpk)(0,2)*(*fSMpk)(1,1)-2.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
5768                 - (*fSMpk)(1,2)+2.*(*fSMpk)(0,4); // dM211 = sum_{i,j,k=1,i!=j!=k}^M w_i^2 w_j w_k
5769  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
5770                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
5771                  + 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
5772  //..............................................................................................
5773
5774  //  ***********************************************
5775  //  **** weighted multi-particle correlations: ****
5776  //  ***********************************************
5777  //.............................................................................................. 
5778  // weighted 2-particle correlations:
5779  Double_t two1n1nW1W1 = 0.; // <w1 w2 cos(n*(phi1-phi2))>
5780  Double_t two2n2nW2W2 = 0.; // <w1^2 w2^2 cos(2n*(phi1-phi2))>
5781  Double_t two3n3nW3W3 = 0.; // <w1^3 w2^3 cos(3n*(phi1-phi2))>
5782  Double_t two4n4nW4W4 = 0.; // <w1^4 w2^4 cos(4n*(phi1-phi2))>
5783  Double_t two1n1nW3W1 = 0.; // <w1^3 w2 cos(n*(phi1-phi2))>
5784  Double_t two1n1nW1W1W2 = 0.; // <w1 w2 w3^2 cos(n*(phi1-phi2))> 
5785  
5786  if(dMult>1) 
5787  { 
5788   if(dM11)
5789   {
5790    two1n1nW1W1 = (pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))/dM11; 
5791    
5792    // average weighted correlation <w1 w2 cos(n*(phi1-phi2))> for single event: 
5793    fQCorrelationsEBE[1]->SetBinContent(1,two1n1nW1W1);
5794
5795    // average weighted correlation <w1 w2 cos(n*(phi1-phi2))> for all events:
5796    //fQCorrelationsW->Fill(0.,two1n1nW1W1,dM11);
5797    fQCorrelations[1][0]->Fill(0.5,two1n1nW1W1,dM11);
5798   }
5799   if(dM22)
5800   {
5801    two2n2nW2W2 = (pow(dReQ2n2k,2)+pow(dImQ2n2k,2)-(*fSMpk)(0,4))/dM22; 
5802    //fQCorrelationsW->Fill(1.,two2n2nW2W2,dM22); 
5803    fQCorrelations[1][0]->Fill(1.5,two2n2nW2W2,dM22);
5804   }
5805   if(dM33)
5806   {
5807    two3n3nW3W3 = (pow(dReQ3n3k,2)+pow(dImQ3n3k,2)-(*fSMpk)(0,6))/dM33;
5808    //fQCorrelationsW->Fill(2.,two3n3nW3W3,dM33);
5809    fQCorrelations[1][0]->Fill(2.5,two3n3nW3W3,dM33);
5810   }
5811   if(dM44)
5812   {
5813    two4n4nW4W4 = (pow(dReQ4n4k,2)+pow(dImQ4n4k,2)-(*fSMpk)(0,8))/dM44; 
5814    //fQCorrelationsW->Fill(3.,two4n4nW4W4,dM44); 
5815    fQCorrelations[1][0]->Fill(3.5,two4n4nW4W4,dM44); 
5816   } 
5817   if(dM31)
5818   {
5819    two1n1nW3W1 = (dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k-(*fSMpk)(0,4))/dM31; 
5820    //fQCorrelationsW->Fill(4.,two1n1nW3W1,dM31);  
5821   } 
5822   if(dM211)
5823   {
5824    two1n1nW1W1W2 = ((*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2)-(*fSMpk)(0,2))
5825                  - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k
5826                  - (*fSMpk)(0,4)))/dM211;
5827    //fQCorrelationsW->Fill(5.,two1n1nW1W1W2,dM211);  
5828   }  
5829  } // end of if(dMult>1)
5830  //..............................................................................................
5831  
5832  //..............................................................................................
5833  // weighted 3-particle correlations:
5834  Double_t three2n1n1nW2W1W1 = 0.; // <w1^2 w2 w3 cos(n*(2phi1-phi2-phi3))>
5835  
5836  if(dMult>2) 
5837  { 
5838   if(dM211)
5839   {                                                       
5840    three2n1n1nW2W1W1 = (pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k
5841                      - 2.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
5842                      - pow(dReQ2n2k,2)-pow(dImQ2n2k,2)
5843                      + 2.*(*fSMpk)(0,4))/dM211;                                                                               
5844    //fQCorrelationsW->Fill(20.,three2n1n1nW2W1W1,dM211);
5845   } 
5846  } // end of if(dMult>2) 
5847  //..............................................................................................
5848  
5849  //..............................................................................................
5850  // weighted 4-particle correlations:
5851  Double_t four1n1n1n1nW1W1W1W1 = 0.; // <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))>
5852  if(dMult>3) 
5853  { 
5854   if(dM1111)
5855   {      
5856    four1n1n1n1nW1W1W1W1 = (pow(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.),2)
5857                         - 2.*(pow(dReQ1n1k,2.)*dReQ2n2k+2.*dReQ1n1k*dImQ1n1k*dImQ2n2k-pow(dImQ1n1k,2.)*dReQ2n2k)
5858                         + 8.*(dReQ1n3k*dReQ1n1k+dImQ1n3k*dImQ1n1k)
5859                         + (pow(dReQ2n2k,2)+pow(dImQ2n2k,2))
5860                         - 4.*(*fSMpk)(0,2)*(pow(dReQ1n1k,2)+pow(dImQ1n1k,2))
5861                         - 6.*(*fSMpk)(0,4)+2.*(*fSMpk)(1,2))/dM1111;  
5862                         
5863    // average weighted correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for single event: 
5864    fQCorrelationsEBE[1]->SetBinContent(11,four1n1n1n1nW1W1W1W1);
5865
5866    // average weighted correlation <w1 w2 w3 w4 cos(n*(phi1+phi2-phi3-phi4))> for all events:                        
5867    //fQCorrelationsW->Fill(40.,four1n1n1n1nW1W1W1W1,dM1111);
5868    
5869    fQCorrelations[1][0]->Fill(10.5,four1n1n1n1nW1W1W1W1,dM1111);
5870   } 
5871  } // end of if(dMult>3) 
5872  //..............................................................................................
5873  
5874 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForIntegratedFlow()
5875
5876
5877 //================================================================================================================================
5878
5879
5880 void AliFlowAnalysisWithQCumulants::CalculateWeightedQProductsForIntFlow() // to be improved (completed)
5881 {
5882  // calculate averages like <<2><4>>, <<2><6>>, <<4><6>>, etc. which are needed to calculate covariances 
5883  // Remark: here we take weighted correlations!
5884  
5885  // binning of fQProductsW is organized as follows:
5886  // 
5887  // 1st bin: <2><4> 
5888  // 2nd bin: <2><6>
5889  // 3rd bin: <2><8>
5890  // 4th bin: <4><6>
5891  // 5th bin: <4><8>
5892  // 6th bin: <6><8>
5893  
5894  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
5895
5896  Double_t dM11 = (*fSMpk)(1,1)-(*fSMpk)(0,2); // dM11 = sum_{i,j=1,i!=j}^M w_i w_j
5897  Double_t dM1111 = (*fSMpk)(3,1)-6.*(*fSMpk)(0,2)*(*fSMpk)(1,1)  
5898                  + 8.*(*fSMpk)(0,3)*(*fSMpk)(0,1)
5899                  + 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
5900
5901  Double_t twoEBEW = 0.; // <2>
5902  Double_t fourEBEW = 0.; // <4>
5903  
5904  twoEBEW = fQCorrelationsEBE[1]->GetBinContent(1);
5905  fourEBEW = fQCorrelationsEBE[1]->GetBinContent(11);
5906  
5907  // <2><4>
5908  if(dMult>3)
5909  {
5910   fQProducts[1][0]->Fill(0.5,twoEBEW*fourEBEW,dM11*dM1111);
5911  }
5912  
5913 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedQProductsForIntFlow()  
5914
5915
5916 //================================================================================================================================
5917
5918
5919 void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
5920 {
5921  // initialize all arrays needed to calculate the integrated flow
5922  
5923  for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++) // not weighted or weighted
5924  {
5925   fQCorrelationsEBE[pW] = NULL;
5926   for(Int_t sc=0;sc<2;sc++)
5927   {
5928    fQCorrectionsEBE[pW][sc] = NULL;
5929   }
5930   for(Int_t eW=0;eW<2;eW++)
5931   {
5932    // profiles:
5933    fQCorrelations[pW][eW] = NULL;
5934    fQProducts[pW][eW] = NULL;
5935    for(Int_t sc=0;sc<2;sc++) // sin or cos terms
5936    {
5937     fQCorrections[pW][eW][sc] = NULL;
5938    }
5939    // histograms with results:
5940    fCorrelations[pW][eW] = NULL;
5941    fCovariances[pW][eW] = NULL;
5942    fCorrections[pW][eW] = NULL;
5943    fProductOfEventWeights[pW][eW] = NULL;
5944    for(Int_t power=0;power<2;power++) 
5945    {
5946     fSumOfEventWeights[pW][eW][power] = NULL;    
5947    }
5948    for(Int_t nua=0;nua<2;nua++) // not corrected or corrected
5949    {
5950     fCumulants[pW][eW][nua] = NULL;
5951     fIntFlow[pW][eW][nua] = NULL;
5952    }
5953   } 
5954  }
5955  
5956 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForIntFlow()
5957
5958
5959 //================================================================================================================================
5960
5961
5962 void AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
5963 {
5964  // initialize all arrays needed to calcualted differential flow
5965  
5966  // nested lists in fDiffFlowProfiles:
5967  for(Int_t t=0;t<2;t++)
5968  {
5969   fDFPType[t] = NULL;
5970   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++)
5971   {
5972    fDFPParticleWeights[t][pW] = NULL;
5973    for(Int_t eW=0;eW<2;eW++)
5974    {   
5975     fDFPEventWeights[t][pW][eW] = NULL;
5976     fDiffFlowCorrelations[t][pW][eW] = NULL;
5977     fDiffFlowProductsOfCorrelations[t][pW][eW] = NULL;
5978     for(Int_t sc=0;sc<2;sc++)
5979     {
5980      fDiffFlowCorrectionTerms[t][pW][eW][sc] = NULL;
5981     }
5982    } 
5983   }
5984  }  
5985  
5986  // profiles in nested lists in fDiffFlowProfiles:
5987  for(Int_t t=0;t<2;t++) // type: RP or POI
5988  { 
5989   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++) // particle weights: not used or used 
5990   {
5991    for(Int_t eW=0;eW<2;eW++)
5992    {
5993     // correlations:
5994     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
5995     {
5996      fCorrelationsPro[t][pW][eW][correlationIndex] = NULL;
5997     }
5998     // products of correlations:
5999     for(Int_t productOfCorrelationsIndex=0;productOfCorrelationsIndex<6;productOfCorrelationsIndex++)
6000     {
6001      fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] = NULL;
6002     }
6003     // correction terms:
6004     for(Int_t sc=0;sc<2;sc++)
6005     {
6006      for(Int_t correctionsIndex=0;correctionsIndex<2;correctionsIndex++)
6007      {
6008       fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex] = NULL;
6009      } 
6010     } 
6011    }
6012   }
6013  }  
6014  
6015  // nested lists in fDiffFlowResults:
6016  for(Int_t t=0;t<2;t++)
6017  {
6018   fDFRType[t] = NULL;
6019   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++)
6020   {
6021    fDFRParticleWeights[t][pW] = NULL;
6022    for(Int_t eW=0;eW<2;eW++)
6023    {    
6024     fDFREventWeights[t][pW][eW] = NULL;
6025     fDiffFlowFinalCorrelations[t][pW][eW] = NULL;
6026     fDiffFlowFinalCorrections[t][pW][eW] = NULL;
6027     fDiffFlowFinalCovariances[t][pW][eW] = NULL;
6028     for(Int_t nua=0;nua<2;nua++)
6029     {
6030      fDFRCorrections[t][pW][eW][nua] = NULL;   
6031      fDiffFlowFinalCumulants[t][pW][eW][nua] = NULL;   
6032      fDiffFlowFinalFlow[t][pW][eW][nua] = NULL;
6033     }
6034    } 
6035   }
6036  }  
6037  
6038  // 2D and 1D histograms in nested lists in fDiffFlowResults:
6039  for(Int_t t=0;t<2;t++) 
6040  {
6041   fNonEmptyBins2D[t] = NULL;
6042   for(Int_t pe=0;pe<2;pe++)
6043   {
6044    fNonEmptyBins1D[t][pe] = NULL;
6045   }
6046   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++)
6047   {
6048    for(Int_t eW=0;eW<2;eW++)
6049    {
6050     // correlations:
6051     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++) 
6052     {
6053      fFinalCorrelations2D[t][pW][eW][correlationIndex] = NULL;
6054      for(Int_t pe=0;pe<2;pe++)
6055      {
6056       fFinalCorrelations1D[t][pW][eW][pe][correlationIndex] = NULL;   
6057      }
6058     }
6059     // corrections:
6060     for(Int_t correctionIndex=0;correctionIndex<4;correctionIndex++) 
6061     {
6062      fFinalCorrections2D[t][pW][eW][correctionIndex] = NULL;
6063      for(Int_t pe=0;pe<2;pe++)
6064      {
6065       fFinalCorrections1D[t][pW][eW][pe][correctionIndex] = NULL;     
6066      }
6067     }
6068     // covariances:
6069     for(Int_t covarianceIndex=0;covarianceIndex<4;covarianceIndex++) 
6070     {
6071      fFinalCovariances2D[t][pW][eW][covarianceIndex] = NULL;
6072      for(Int_t pe=0;pe<2;pe++)
6073      {
6074       fFinalCovariances1D[t][pW][eW][pe][covarianceIndex] = NULL;     
6075      }
6076     }
6077     for(Int_t nua=0;nua<2;nua++) 
6078     {  
6079      // cumulants:
6080      for(Int_t cumulantIndex=0;cumulantIndex<4;cumulantIndex++) 
6081      {
6082       fFinalCumulants2D[t][pW][eW][nua][cumulantIndex] = NULL;
6083       fFinalCumulantsPt[t][pW][eW][nua][cumulantIndex] = NULL;     
6084       fFinalCumulantsEta[t][pW][eW][nua][cumulantIndex] = NULL;       
6085      }
6086      // final flow:
6087      for(Int_t finalFlowIndex=0;finalFlowIndex<4;finalFlowIndex++) 
6088      {
6089       fFinalFlow2D[t][pW][eW][nua][finalFlowIndex] = NULL;
6090       fFinalFlowPt[t][pW][eW][nua][finalFlowIndex] = NULL;   
6091       fFinalFlowEta[t][pW][eW][nua][finalFlowIndex] = NULL;   
6092      }
6093     } 
6094    }  
6095   }
6096  }
6097  
6098  for(Int_t t=0;t<3;t++) // type (RP, POI, POI&&RP)
6099  {
6100   for(Int_t m=0;m<4;m++) // multiple of harmonic
6101   {
6102    for(Int_t k=0;k<9;k++) // power of weight
6103    {
6104     fReEBE[t][m][k] = NULL;
6105     fImEBE[t][m][k] = NULL;
6106     fs[t][k] = NULL; // to be improved (this doesn't need to be within loop over m)
6107    }   
6108   }
6109  }
6110   
6111 } // end of AliFlowAnalysisWithQCumulants::InitializeArraysForDiffFlow()
6112
6113
6114 //================================================================================================================================
6115
6116
6117 void AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
6118 {
6119  // organize and book everything needed for differential flow
6120  
6121  // book and nest all lists belonging to the list fDiffFlowProfiles "Profiles":
6122  TList list; // to be improved (do I need this here?)
6123  list.SetOwner(kTRUE); // to be improved (do I need this here?)
6124  TString typeFlag[2] = {"RP","POI"}; // to be improved (do I need this here?)
6125  TString pWeightsFlag[2] = {"not used","used"};  // to be improved (do I need this here?)
6126  TString eWeightsFlag[2] = {"exact","non-exact"};  // to be improved (do I need this here?)
6127  //TString sinCosFlag[2] = {"sin","cos"}; // to be improved (do I need this here?)
6128  TString nuaFlag[2] = {"not corrected","corrected"}; // nua = non-uniform acceptance // to be improved (do I need this here?)
6129  
6130  // book all 2D profiles and add to appropriate lists:
6131  TProfile2D styleProfile("","",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6132  styleProfile.SetXTitle("p_{t}");
6133  styleProfile.SetYTitle("#eta");
6134  TString correlationName[4] = {"<2'>","<4'>","<6'>","<8'>"};
6135  TString cumulantName[4] = {"QC{2'}","QC{4'}","QC{6'}","QC{8'}"};
6136  TString productOfCorrelationsName[5] = {"<2><2'>","<2><4'>","<4><2'>","<4><4'>","<2'><4'>"};
6137  TString correctionsSinTermsName[2] = {"sin(1)","sin(2)"};
6138  TString correctionsCosTermsName[2] = {"cos(1)","cos(2)"};
6139  TString correctionName[4] = {"corr. to QC{2'}","corr. to QC{4'}","corr. to QC{6'}","corr. to QC{8'}"};
6140  TString covarianceName[4] = {"Cov(2,2')","Cov(2,4')","Cov(2',4')","Cov(4,2')"}; // to be improved (reorganized)
6141  TString flowName[4] = {"v'{2}","v'{4}","v'{6}","v'{8}"}; 
6142  
6143  for(Int_t t=0;t<2;t++) // type: RP or POI
6144  { 
6145   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++) // weights: not used or used 
6146   {
6147    for(Int_t eW=0;eW<2;eW++)
6148    {
6149     // correlations:
6150     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
6151     {
6152      fCorrelationsPro[t][pW][eW][correlationIndex] = (TProfile2D*)styleProfile.Clone(correlationName[correlationIndex].Data());
6153      fCorrelationsPro[t][pW][eW][correlationIndex]->SetTitle(correlationName[correlationIndex].Data()); 
6154      fDiffFlowCorrelations[t][pW][eW]->Add(fCorrelationsPro[t][pW][eW][correlationIndex]);
6155     }
6156     // products of correlations:
6157     for(Int_t productOfCorrelationsIndex=0;productOfCorrelationsIndex<5;productOfCorrelationsIndex++)
6158     {
6159      fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex] = (TProfile2D*)styleProfile.Clone(productOfCorrelationsName[productOfCorrelationsIndex].Data());
6160      fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex]->SetTitle(productOfCorrelationsName[productOfCorrelationsIndex].Data()); 
6161      fDiffFlowProductsOfCorrelations[t][pW][eW]->Add(fProductsOfCorrelationsPro[t][pW][eW][productOfCorrelationsIndex]);
6162     }
6163     // correction terms:
6164     for(Int_t sc=0;sc<2;sc++)
6165     {
6166      for(Int_t correctionsIndex=0;correctionsIndex<2;correctionsIndex++)
6167      {
6168       if(sc==0)
6169       {
6170        fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex] = (TProfile2D*)styleProfile.Clone(correctionsSinTermsName[correctionsIndex].Data());
6171        fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex]->SetTitle(correctionsSinTermsName[correctionsIndex].Data());
6172        fDiffFlowCorrectionTerms[t][pW][eW][sc]->Add(fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex]);
6173       }
6174       if(sc==1)
6175       {
6176        fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex] = (TProfile2D*)styleProfile.Clone(correctionsCosTermsName[correctionsIndex].Data());
6177        fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex]->SetTitle(correctionsCosTermsName[correctionsIndex].Data());
6178        fDiffFlowCorrectionTerms[t][pW][eW][sc]->Add(fCorrectionTermsPro[t][pW][eW][sc][correctionsIndex]);
6179       }    
6180      }
6181     }
6182    }   
6183   }  
6184  }
6185    
6186  // book all 2D and 1D histograms for final results and store them in appropriate lists:
6187  TH2D styleHistPtEta("","",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6188  styleHistPtEta.SetXTitle("p_{t}");
6189  styleHistPtEta.SetYTitle("#eta");
6190  TH1D styleHistPt("","",fnBinsPt,fPtMin,fPtMax);
6191  styleHistPt.SetXTitle("p_{t}");
6192  TH1D styleHistEta("","",fnBinsEta,fEtaMin,fEtaMax);
6193  styleHistEta.SetXTitle("#eta");
6194  for(Int_t t=0;t<2;t++) // RP or POI
6195  {
6196   // 2D:
6197   fNonEmptyBins2D[t] = (TH2D*)styleHistPtEta.Clone(Form("%s, (p_{t},#eta)",typeFlag[t].Data()));
6198   fNonEmptyBins2D[t]->SetTitle(Form("Non-empty bins: %s (p_{t},#eta)",typeFlag[t].Data())); 
6199   fDFRType[t]->Add(fNonEmptyBins2D[t]); 
6200   // 1D:
6201   fNonEmptyBins1D[t][0] = (TH1D*)styleHistPt.Clone(Form("%s, p_{t}",typeFlag[t].Data()));
6202   fNonEmptyBins1D[t][0]->SetTitle(Form("Non-empty bins: %s (p_{t})",typeFlag[t].Data())); 
6203   fDFRType[t]->Add(fNonEmptyBins1D[t][0]); 
6204   fNonEmptyBins1D[t][1] = (TH1D*)styleHistEta.Clone(Form("%s, #eta",typeFlag[t].Data()));
6205   fNonEmptyBins1D[t][1]->SetTitle(Form("Non-empty bins: %s (#eta)",typeFlag[t].Data())); 
6206   fDFRType[t]->Add(fNonEmptyBins1D[t][1]); 
6207   
6208   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++) // particle weights not used or used
6209   {
6210    for(Int_t eW=0;eW<2;eW++)
6211    {
6212     // correlations:
6213     for(Int_t correlationIndex=0;correlationIndex<4;correlationIndex++)
6214     {
6215      // 2D:
6216      fFinalCorrelations2D[t][pW][eW][correlationIndex] = (TH2D*)styleHistPtEta.Clone(Form("%s, (p_{t},#eta)",correlationName[correlationIndex].Data()));
6217      fFinalCorrelations2D[t][pW][eW][correlationIndex]->SetTitle(Form("%s (p_{t},#eta): %s, pWeights %s, eWeights %s",correlationName[correlationIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6218      fDiffFlowFinalCorrelations[t][pW][eW]->Add(fFinalCorrelations2D[t][pW][eW][correlationIndex]);   
6219      // 1D:
6220      for(Int_t pe=0;pe<2;pe++) // pt or eta:
6221      {
6222       if(pe==0) 
6223       { 
6224        fFinalCorrelations1D[t][pW][eW][pe][correlationIndex] = (TH1D*)styleHistPt.Clone(Form("%s, (p_{t})",correlationName[correlationIndex].Data()));
6225        fFinalCorrelations1D[t][pW][eW][pe][correlationIndex]->SetTitle(Form("%s (p_{t}): %s, pWeights %s, eWeights %s",correlationName[correlationIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6226        fDiffFlowFinalCorrelations[t][pW][eW]->Add(fFinalCorrelations1D[t][pW][eW][pe][correlationIndex]);   
6227       }
6228       if(pe==1)
6229       {
6230        fFinalCorrelations1D[t][pW][eW][pe][correlationIndex] = (TH1D*)styleHistEta.Clone(Form("%s, (#eta)",correlationName[correlationIndex].Data()));
6231        fFinalCorrelations1D[t][pW][eW][pe][correlationIndex]->SetTitle(Form("%s (#eta): %s, pWeights %s, eWeights %s",correlationName[correlationIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6232        fDiffFlowFinalCorrelations[t][pW][eW]->Add(fFinalCorrelations1D[t][pW][eW][pe][correlationIndex]); 
6233       } 
6234      } 
6235     }    
6236     // corrections:
6237     for(Int_t correctionIndex=0;correctionIndex<4;correctionIndex++)
6238     {
6239      // 2D:
6240      fFinalCorrections2D[t][pW][eW][correctionIndex] = (TH2D*)styleHistPtEta.Clone(Form("%s, (p_{t},#eta)",correctionName[correctionIndex].Data()));
6241      fFinalCorrections2D[t][pW][eW][correctionIndex]->SetTitle(Form("%s (p_{t},#eta): %s, pWeights %s, eWeights %s",correctionName[correctionIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6242      fDiffFlowFinalCorrections[t][pW][eW]->Add(fFinalCorrections2D[t][pW][eW][correctionIndex]);   
6243      // 1D:
6244      for(Int_t pe=0;pe<2;pe++) // pt or eta:
6245      {
6246       if(pe==0) 
6247       { 
6248        fFinalCorrections1D[t][pW][eW][pe][correctionIndex] = (TH1D*)styleHistPt.Clone(Form("%s, (p_{t})",correctionName[correctionIndex].Data()));
6249        fFinalCorrections1D[t][pW][eW][pe][correctionIndex]->SetTitle(Form("%s (p_{t}): %s, pWeights %s, eWeights %s",correctionName[correctionIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6250        fDiffFlowFinalCorrections[t][pW][eW]->Add(fFinalCorrections1D[t][pW][eW][pe][correctionIndex]);   
6251       }
6252       if(pe==1)
6253       {
6254        fFinalCorrections1D[t][pW][eW][pe][correctionIndex] = (TH1D*)styleHistEta.Clone(Form("%s, (#eta)",correctionName[correctionIndex].Data()));
6255        fFinalCorrections1D[t][pW][eW][pe][correctionIndex]->SetTitle(Form("%s (#eta): %s, pWeights %s, eWeights %s",correctionName[correctionIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6256        fDiffFlowFinalCorrections[t][pW][eW]->Add(fFinalCorrections1D[t][pW][eW][pe][correctionIndex]); 
6257       } 
6258      } 
6259     }
6260     // covariances:
6261     for(Int_t covarianceIndex=0;covarianceIndex<4;covarianceIndex++)
6262     {
6263      // 2D:
6264      fFinalCovariances2D[t][pW][eW][covarianceIndex] = (TH2D*)styleHistPtEta.Clone(Form("%s, (p_{t},#eta)",covarianceName[covarianceIndex].Data()));
6265      fFinalCovariances2D[t][pW][eW][covarianceIndex]->SetTitle(Form("%s (p_{t},#eta): %s, pWeights %s, eWeights %s",covarianceName[covarianceIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6266      fDiffFlowFinalCovariances[t][pW][eW]->Add(fFinalCovariances2D[t][pW][eW][covarianceIndex]);  
6267      // 1D:
6268      for(Int_t pe=0;pe<2;pe++) // pt or eta:
6269      {
6270       if(pe==0) 
6271       { 
6272        fFinalCovariances1D[t][pW][eW][pe][covarianceIndex] = (TH1D*)styleHistPt.Clone(Form("%s, (p_{t})",covarianceName[covarianceIndex].Data()));
6273        fFinalCovariances1D[t][pW][eW][pe][covarianceIndex]->SetTitle(Form("%s (p_{t}): %s, pWeights %s, eWeights %s",covarianceName[covarianceIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6274        fDiffFlowFinalCovariances[t][pW][eW]->Add(fFinalCovariances1D[t][pW][eW][pe][covarianceIndex]);   
6275       }
6276       if(pe==1)
6277       {
6278        fFinalCovariances1D[t][pW][eW][pe][covarianceIndex] = (TH1D*)styleHistEta.Clone(Form("%s, (#eta)",covarianceName[covarianceIndex].Data()));
6279        fFinalCovariances1D[t][pW][eW][pe][covarianceIndex]->SetTitle(Form("%s (#eta): %s, pWeights %s, eWeights %s",covarianceName[covarianceIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data())); 
6280        fDiffFlowFinalCovariances[t][pW][eW]->Add(fFinalCovariances1D[t][pW][eW][pe][covarianceIndex]); 
6281       } 
6282      } 
6283     }
6284     for(Int_t nua=0;nua<2;nua++) // corrected or not 
6285     {
6286      // cumulants:
6287      for(Int_t cumulantIndex=0;cumulantIndex<4;cumulantIndex++)
6288      {
6289       // 2D:
6290       fFinalCumulants2D[t][pW][eW][nua][cumulantIndex] = (TH2D*)styleHistPtEta.Clone(Form("%s, (p_{t},#eta)",cumulantName[cumulantIndex].Data()));
6291       fFinalCumulants2D[t][pW][eW][nua][cumulantIndex]->SetTitle(Form("%s (p_{t},#eta): %s, pWeights %s, eWeights %s, %s for NUA",cumulantName[cumulantIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())); 
6292       fDiffFlowFinalCumulants[t][pW][eW][nua]->Add(fFinalCumulants2D[t][pW][eW][nua][cumulantIndex]);   
6293       // pt:
6294       fFinalCumulantsPt[t][pW][eW][nua][cumulantIndex] = (TH1D*)styleHistPt.Clone(Form("%s, (p_{t})",cumulantName[cumulantIndex].Data()));
6295       fFinalCumulantsPt[t][pW][eW][nua][cumulantIndex]->SetTitle(Form("%s (p_{t}): %s, pWeights %s, eWeights %s, %s for NUA",cumulantName[cumulantIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())); 
6296       fDiffFlowFinalCumulants[t][pW][eW][nua]->Add(fFinalCumulantsPt[t][pW][eW][nua][cumulantIndex]);   
6297       // eta:     
6298       fFinalCumulantsEta[t][pW][eW][nua][cumulantIndex] = (TH1D*)styleHistEta.Clone(Form("%s, (#eta)",cumulantName[cumulantIndex].Data()));
6299       fFinalCumulantsEta[t][pW][eW][nua][cumulantIndex]->SetTitle(Form("%s (#eta): %s, pWeights %s, eWeights %s, %s for NUA",cumulantName[cumulantIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())); 
6300       fDiffFlowFinalCumulants[t][pW][eW][nua]->Add(fFinalCumulantsEta[t][pW][eW][nua][cumulantIndex]);  
6301      }       
6302      // flow:
6303      for(Int_t flowIndex=0;flowIndex<4;flowIndex++)
6304      {
6305       // 2D:
6306       fFinalFlow2D[t][pW][eW][nua][flowIndex] = (TH2D*)styleHistPtEta.Clone(Form("%s, (p_{t},#eta)",flowName[flowIndex].Data()));
6307       fFinalFlow2D[t][pW][eW][nua][flowIndex]->SetTitle(Form("%s (p_{t},#eta): %s, pWeights %s, eWeights %s, %s for NUA",flowName[flowIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())); 
6308       fDiffFlowFinalFlow[t][pW][eW][nua]->Add(fFinalFlow2D[t][pW][eW][nua][flowIndex]);   
6309       // pt: 
6310       fFinalFlowPt[t][pW][eW][nua][flowIndex] = (TH1D*)styleHistPt.Clone(Form("%s, (p_{t})",flowName[flowIndex].Data()));
6311       fFinalFlowPt[t][pW][eW][nua][flowIndex]->SetTitle(Form("%s (p_{t}): %s, pWeights %s, eWeights %s, %s for NUA",flowName[flowIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())); 
6312       fDiffFlowFinalFlow[t][pW][eW][nua]->Add(fFinalFlowPt[t][pW][eW][nua][flowIndex]);   
6313       // eta:
6314       fFinalFlowEta[t][pW][eW][nua][flowIndex] = (TH1D*)styleHistEta.Clone(Form("%s, (#eta)",flowName[flowIndex].Data()));
6315       fFinalFlowEta[t][pW][eW][nua][flowIndex]->SetTitle(Form("%s (#eta): %s, pWeights %s, eWeights %s, %s for NUA",flowName[flowIndex].Data(),typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data())); 
6316       fDiffFlowFinalFlow[t][pW][eW][nua]->Add(fFinalFlowEta[t][pW][eW][nua][flowIndex]);   
6317      }
6318     }   
6319    } 
6320   } 
6321  } 
6322    
6323  // Event-by-event r_{m*n,k}(pt,eta), p_{m*n,k}(pt,eta) and q_{m*n,k}(pt,eta)
6324  // Explanantion of notation:
6325  //  1.) n is harmonic, m is multiple of harmonic;
6326  //  2.) k is power of weight;
6327  //  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);   
6328  //  4.) p_{m*n,k}(pt,eta) = Q-vector evaluated in harmonic m*n for POIs in particular (pt,eta) bin 
6329  //                          (if i-th POI is also RP, than it is weighted with w_i^k);   
6330  //  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 
6331  //                          (i-th RP&&POI is weighted with w_i^k)            
6332   
6333  TProfile2D styleRe("typeMultiplePowerRe","typeMultiplePowerRe",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6334  TProfile2D styleIm("typeMultiplePowerIm","typeMultiplePowerIm",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6335  
6336  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
6337  { 
6338   for(Int_t m=0;m<4;m++)
6339   {
6340    for(Int_t k=0;k<9;k++)
6341    {
6342     fReEBE[t][m][k] = (TProfile2D*)styleRe.Clone(Form("typeFlag%dmultiple%dpower%dRe",t,m,k)); 
6343     fImEBE[t][m][k] = (TProfile2D*)styleIm.Clone(Form("typeFlag%dmultiple%dpower%dIm",t,m,k));
6344    }
6345   } 
6346  } 
6347
6348  TProfile2D styleS("typePower","typePower",fnBinsPt,fPtMin,fPtMax,fnBinsEta,fEtaMin,fEtaMax);
6349
6350  for(Int_t t=0;t<3;t++) // typeFlag (0 = RP, 1 = POI, 2 = RP&&POI )
6351  { 
6352   for(Int_t k=0;k<9;k++)
6353   {
6354    fs[t][k] = (TProfile2D*)styleS.Clone(Form("typeFlag%dpower%d",t,k));
6355   }
6356  }
6357    
6358 } // end of AliFlowAnalysisWithQCumulants::BookEverythingForDifferentialFlow()
6359
6360
6361 //================================================================================================================================
6362
6363
6364 void AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow(TString type)
6365 {
6366  // calculate all reduced correlations needed for differential flow for each (pt,eta) bin:
6367  
6368  Int_t typeFlag = -1; 
6369   
6370  // reduced correlations ares stored in fCorrelationsPro[t][pW][index] and are indexed as follows:
6371  // index:
6372  // 0: <2'>
6373  // 1: <4'>
6374
6375  // multiplicity:
6376  Double_t dMult = (*fSMpk)(0,0);
6377  
6378  // real and imaginary parts of non-weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
6379  Double_t dReQ1n = (*fReQ)(0,0);
6380  Double_t dReQ2n = (*fReQ)(1,0);
6381  //Double_t dReQ3n = (*fReQ)(2,0);
6382  //Double_t dReQ4n = (*fReQ)(3,0);
6383  Double_t dImQ1n = (*fImQ)(0,0);
6384  Double_t dImQ2n = (*fImQ)(1,0);
6385  //Double_t dImQ3n = (*fImQ)(2,0);
6386  //Double_t dImQ4n = (*fImQ)(3,0);
6387
6388  // looping over all (pt,eta) bins and calculating correlations needed for differential flow: 
6389  for(Int_t p=1;p<=fnBinsPt;p++)
6390  {
6391   for(Int_t e=1;e<=fnBinsEta;e++)
6392   {
6393    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin): 
6394    Double_t p1n0kRe = 0.;
6395    Double_t p1n0kIm = 0.;
6396
6397    // number of POIs in particular (pt,eta) bin:
6398    Double_t mp = 0.;
6399
6400    // 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):
6401    Double_t q1n0kRe = 0.;
6402    Double_t q1n0kIm = 0.;
6403    Double_t q2n0kRe = 0.;
6404    Double_t q2n0kIm = 0.;
6405
6406    // number of particles which are both RPs and POIs in particular (pt,eta) bin:
6407    Double_t mq = 0.;
6408    
6409    // q_{m*n,0}:
6410    q1n0kRe = fReEBE[2][0][0]->GetBinContent(fReEBE[2][0][0]->GetBin(p,e))
6411            * fReEBE[2][0][0]->GetBinEntries(fReEBE[2][0][0]->GetBin(p,e));
6412    q1n0kIm = fImEBE[2][0][0]->GetBinContent(fImEBE[2][0][0]->GetBin(p,e))
6413            * fImEBE[2][0][0]->GetBinEntries(fImEBE[2][0][0]->GetBin(p,e));
6414    q2n0kRe = fReEBE[2][1][0]->GetBinContent(fReEBE[2][1][0]->GetBin(p,e))
6415            * fReEBE[2][1][0]->GetBinEntries(fReEBE[2][1][0]->GetBin(p,e));
6416    q2n0kIm = fImEBE[2][1][0]->GetBinContent(fImEBE[2][1][0]->GetBin(p,e))
6417            * fImEBE[2][1][0]->GetBinEntries(fImEBE[2][1][0]->GetBin(p,e));
6418            
6419    mq = fReEBE[2][0][0]->GetBinEntries(fReEBE[2][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
6420    
6421    if(type == "POI")
6422    {
6423     // p_{m*n,0}:
6424     p1n0kRe = fReEBE[1][0][0]->GetBinContent(fReEBE[1][0][0]->GetBin(p,e))
6425             * fReEBE[1][0][0]->GetBinEntries(fReEBE[1][0][0]->GetBin(p,e));
6426     p1n0kIm = fImEBE[1][0][0]->GetBinContent(fImEBE[1][0][0]->GetBin(p,e))  
6427             * fImEBE[1][0][0]->GetBinEntries(fImEBE[1][0][0]->GetBin(p,e));
6428             
6429     mp = fReEBE[1][0][0]->GetBinEntries(fReEBE[1][0][0]->GetBin(p,e)); // to be improved (cross-checked by accessing other profiles here)
6430     
6431     typeFlag = 1;
6432    }
6433    else if(type == "RP")
6434    {
6435     // p_{m*n,0} = q_{m*n,0}:
6436     p1n0kRe = q1n0kRe; 
6437     p1n0kIm = q1n0kIm; 
6438     mp = mq; 
6439     
6440     typeFlag = 0;
6441    }
6442    
6443    // count events with non-empty (pt,eta) bin:
6444    if(mp>0)
6445    {
6446     fNonEmptyBins2D[typeFlag]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,1);
6447    }
6448    
6449    // 2'-particle correlation for particular (pt,eta) bin:
6450    Double_t two1n1nPtEta = 0.;
6451    if(mp*dMult-mq)
6452    {
6453     two1n1nPtEta = (p1n0kRe*dReQ1n+p1n0kIm*dImQ1n-mq)
6454                  / (mp*dMult-mq);
6455    
6456     // fill the 2D profile to get the average correlation for each (pt,eta) bin:
6457     if(type == "POI")
6458     { 
6459      //f2pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
6460      
6461      fCorrelationsPro[1][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
6462     }
6463     else if(type == "RP")
6464     {
6465      //f2pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);   
6466      fCorrelationsPro[0][0][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nPtEta,mp*dMult-mq);
6467     }
6468    } // end of if(mp*dMult-mq)
6469   
6470    // 4'-particle correlation:
6471    Double_t four1n1n1n1nPtEta = 0.;
6472    if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6473        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)) // to be improved (introduce a new variable for this expression)
6474    {
6475     four1n1n1n1nPtEta = ((pow(dReQ1n,2.)+pow(dImQ1n,2.))*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6476                       - q2n0kRe*(pow(dReQ1n,2.)-pow(dImQ1n,2.))
6477                       - 2.*q2n0kIm*dReQ1n*dImQ1n
6478                       - p1n0kRe*(dReQ1n*dReQ2n+dImQ1n*dImQ2n)
6479                       + p1n0kIm*(dImQ1n*dReQ2n-dReQ1n*dImQ2n)
6480                       - 2.*dMult*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)
6481                       - 2.*(pow(dReQ1n,2.)+pow(dImQ1n,2.))*mq                      
6482                       + 6.*(q1n0kRe*dReQ1n+q1n0kIm*dImQ1n)                                            
6483                       + 1.*(q2n0kRe*dReQ2n+q2n0kIm*dImQ2n)                      
6484                       + 2.*(p1n0kRe*dReQ1n+p1n0kIm*dImQ1n)                       
6485                       + 2.*mq*dMult                      
6486                       - 6.*mq)        
6487                       / ((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6488                           + mq*(dMult-1.)*(dMult-2.)*(dMult-3.)); 
6489     
6490     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
6491     if(type == "POI")
6492     {
6493      //f4pPtEtaPOI->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
6494      //                  (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6495      //                   + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
6496      
6497      fCorrelationsPro[1][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
6498                                      (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6499                                      + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));
6500     }
6501     else if(type == "RP")
6502     {
6503      //f4pPtEtaRP->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
6504      //                 (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6505      //                  + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));   
6506                        
6507      fCorrelationsPro[0][0][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nPtEta,
6508                                        (mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6509                                        + mq*(dMult-1.)*(dMult-2.)*(dMult-3.));                   
6510     }
6511    } // end of if((mp-mq)*dMult*(dMult-1.)*(dMult-2.)
6512      //            +mq*(dMult-1.)*(dMult-2.)*(dMult-3.))
6513    
6514   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
6515  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
6516  
6517 } // end of AliFlowAnalysisWithQCumulants::CalculateCorrelationsForDifferentialFlow()
6518
6519
6520 //================================================================================================================================
6521
6522
6523 void AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow(TString type)
6524 {
6525  // calculate all weighted correlations needed for differential flow 
6526  
6527  // real and imaginary parts of weighted Q-vectors evaluated in harmonics n, 2n, 3n and 4n: 
6528  Double_t dReQ1n1k = (*fReQ)(0,1);
6529  Double_t dReQ2n2k = (*fReQ)(1,2);
6530  Double_t dReQ1n3k = (*fReQ)(0,3);
6531  //Double_t dReQ4n4k = (*fReQ)(3,4);
6532  Double_t dImQ1n1k = (*fImQ)(0,1);
6533  Double_t dImQ2n2k = (*fImQ)(1,2);
6534  Double_t dImQ1n3k = (*fImQ)(0,3);
6535  //Double_t dImQ4n4k = (*fImQ)(3,4);
6536  
6537  // S^M_{p,k} (see .h file for the definition of fSMpk):
6538  Double_t dSM1p1k = (*fSMpk)(0,1);
6539  Double_t dSM1p2k = (*fSMpk)(0,2);
6540  Double_t dSM1p3k = (*fSMpk)(0,3);
6541  Double_t dSM2p1k = (*fSMpk)(1,1);
6542  Double_t dSM3p1k = (*fSMpk)(2,1);
6543  
6544  // looping over all (pt,eta) bins and calculating weighted correlations needed for differential flow: 
6545  for(Int_t p=1;p<=fnBinsPt;p++)
6546  {
6547   for(Int_t e=1;e<=fnBinsEta;e++)
6548   {
6549    // real and imaginary parts of p_{m*n,0} (non-weighted Q-vector evaluated for POIs in particular (pt,eta) bin):  
6550    Double_t p1n0kRe = 0.;
6551    Double_t p1n0kIm = 0.;
6552
6553    // number of POIs in particular (pt,eta) bin):
6554    Double_t mp = 0.;
6555
6556    // real and imaginary parts of q_{m*n,k}: 
6557    // (weighted Q-vector evaluated for particles which are both RPs and POIs in particular (pt,eta) bin)
6558    Double_t q1n2kRe = 0.;
6559    Double_t q1n2kIm = 0.;
6560    Double_t q2n1kRe = 0.;
6561    Double_t q2n1kIm = 0.;
6562
6563    // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
6564    Double_t s1p1k = 0.; 
6565    Double_t s1p2k = 0.; 
6566    Double_t s1p3k = 0.; 
6567    
6568    // M0111 from Eq. (118) in QC2c (to be improved (notation))
6569    Double_t dM0111 = 0.;
6570  
6571    if(type == "POI")
6572    {
6573     // p_{m*n,0}:
6574     p1n0kRe = fReEBE[1][0][0]->GetBinContent(fReEBE[1][0][0]->GetBin(p,e))
6575             * fReEBE[1][0][0]->GetBinEntries(fReEBE[1][0][0]->GetBin(p,e));
6576     p1n0kIm = fImEBE[1][0][0]->GetBinContent(fImEBE[1][0][0]->GetBin(p,e))
6577             * fImEBE[1][0][0]->GetBinEntries(fImEBE[1][0][0]->GetBin(p,e)); 
6578             
6579     mp = fReEBE[1][0][0]->GetBinEntries(fReEBE[1][0][0]->GetBin(p,e));
6580     
6581     // q_{m*n,k}: 
6582     q1n2kRe = fReEBE[2][0][2]->GetBinContent(fReEBE[2][0][2]->GetBin(p,e))
6583             * fReEBE[2][0][2]->GetBinEntries(fReEBE[2][0][2]->GetBin(p,e));
6584     q1n2kIm = fImEBE[2][0][2]->GetBinContent(fImEBE[2][0][2]->GetBin(p,e))
6585             * fImEBE[2][0][2]->GetBinEntries(fImEBE[2][0][2]->GetBin(p,e));
6586     q2n1kRe = fReEBE[2][1][1]->GetBinContent(fReEBE[2][1][1]->GetBin(p,e))
6587             * fReEBE[2][1][1]->GetBinEntries(fReEBE[2][1][1]->GetBin(p,e)); 
6588     q2n1kIm = fImEBE[2][1][1]->GetBinContent(fImEBE[2][1][1]->GetBin(p,e))
6589             * fImEBE[2][1][1]->GetBinEntries(fImEBE[2][1][1]->GetBin(p,e));
6590        
6591     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
6592     s1p1k = pow(fs[2][1]->GetBinContent(fs[2][1]->GetBin(p,e)),1.); 
6593     s1p2k = pow(fs[2][2]->GetBinContent(fs[2][2]->GetBin(p,e)),1.); 
6594     s1p3k = pow(fs[2][3]->GetBinContent(fs[2][3]->GetBin(p,e)),1.); 
6595    
6596     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
6597     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
6598            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
6599            + 2.*(s1p3k-s1p2k*dSM1p1k));
6600    }
6601    else if(type == "RP")
6602    {
6603     p1n0kRe = fReEBE[0][0][0]->GetBinContent(fReEBE[0][0][0]->GetBin(p,e))
6604             * fReEBE[0][0][0]->GetBinEntries(fReEBE[0][0][0]->GetBin(p,e));
6605     p1n0kIm = fImEBE[0][0][0]->GetBinContent(fImEBE[0][0][0]->GetBin(p,e))
6606             * fImEBE[0][0][0]->GetBinEntries(fImEBE[0][0][0]->GetBin(p,e));
6607             
6608     mp = fReEBE[0][0][0]->GetBinEntries(fReEBE[0][0][0]->GetBin(p,e));
6609     
6610     // q_{m*n,k}: 
6611     q1n2kRe = fReEBE[0][0][2]->GetBinContent(fReEBE[0][0][2]->GetBin(p,e))
6612             * fReEBE[0][0][2]->GetBinEntries(fReEBE[0][0][2]->GetBin(p,e));
6613     q1n2kIm = fImEBE[0][0][2]->GetBinContent(fImEBE[0][0][2]->GetBin(p,e))
6614             * fImEBE[0][0][2]->GetBinEntries(fImEBE[0][0][2]->GetBin(p,e));
6615     q2n1kRe = fReEBE[0][1][1]->GetBinContent(fReEBE[0][1][1]->GetBin(p,e))
6616             * fReEBE[0][1][1]->GetBinEntries(fReEBE[0][1][1]->GetBin(p,e));
6617     q2n1kIm = fImEBE[0][1][1]->GetBinContent(fImEBE[0][1][1]->GetBin(p,e))
6618             * fImEBE[0][1][1]->GetBinEntries(fImEBE[0][1][1]->GetBin(p,e));
6619    
6620     // s_{1,1}, s_{1,2} and s_{1,3} // to be improved (add explanation)  
6621     s1p1k = pow(fs[0][1]->GetBinContent(fs[0][1]->GetBin(p,e)),1.); 
6622     s1p2k = pow(fs[0][2]->GetBinContent(fs[0][2]->GetBin(p,e)),1.); 
6623     s1p3k = pow(fs[0][3]->GetBinContent(fs[0][3]->GetBin(p,e)),1.); 
6624    
6625     // M0111 from Eq. (118) in QC2c (to be improved (notation)):
6626     dM0111 = mp*(dSM3p1k-3.*dSM1p1k*dSM1p2k+2.*dSM1p3k)
6627            - 3.*(s1p1k*(dSM2p1k-dSM1p2k)
6628            + 2.*(s1p3k-s1p2k*dSM1p1k));
6629     //...............................................................................................   
6630    }
6631    
6632    // 2'-particle correlation:
6633    Double_t two1n1nW0W1PtEta = 0.;
6634    if(mp*dSM1p1k-s1p1k)
6635    {
6636     two1n1nW0W1PtEta = (p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k-s1p1k)
6637                  / (mp*dSM1p1k-s1p1k);
6638    
6639     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
6640     if(type == "POI")
6641     {
6642      //f2pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
6643      //                   mp*dSM1p1k-s1p1k);
6644      fCorrelationsPro[1][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);
6645     }
6646     else if(type == "RP")
6647     {
6648      //f2pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,
6649      //                  mp*dSM1p1k-s1p1k); 
6650      fCorrelationsPro[0][1][0][0]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,two1n1nW0W1PtEta,mp*dSM1p1k-s1p1k);  
6651     }
6652    } // end of if(mp*dMult-dmPrimePrimePtEta)
6653    
6654    // 4'-particle correlation:
6655    Double_t four1n1n1n1nW0W1W1W1PtEta = 0.;
6656    if(dM0111)
6657    {
6658     four1n1n1n1nW0W1W1W1PtEta = ((pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
6659                       - q2n1kRe*(pow(dReQ1n1k,2.)-pow(dImQ1n1k,2.))
6660                       - 2.*q2n1kIm*dReQ1n1k*dImQ1n1k
6661                       - p1n0kRe*(dReQ1n1k*dReQ2n2k+dImQ1n1k*dImQ2n2k)
6662                       + p1n0kIm*(dImQ1n1k*dReQ2n2k-dReQ1n1k*dImQ2n2k)
6663                       - 2.*dSM1p2k*(p1n0kRe*dReQ1n1k+p1n0kIm*dImQ1n1k)
6664                       - 2.*(pow(dReQ1n1k,2.)+pow(dImQ1n1k,2.))*s1p1k                                            
6665                       + 6.*(q1n2kRe*dReQ1n1k+q1n2kIm*dImQ1n1k)                                           
6666                       + 1.*(q2n1kRe*dReQ2n2k+q2n1kIm*dImQ2n2k)                         
6667                       + 2.*(p1n0kRe*dReQ1n3k+p1n0kIm*dImQ1n3k)                      
6668                       + 2.*s1p1k*dSM1p2k                                      
6669                       - 6.*s1p3k)        
6670                       / dM0111; // to be imropoved (notation of dM0111)
6671    
6672     // fill the 2D profile to get the average correlation for each (pt, eta) bin:
6673     if(type == "POI")
6674     {
6675      //f4pPtEtaPOIW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
6676      fCorrelationsPro[1][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111);
6677     }
6678     else if(type == "RP")
6679     {
6680      //f4pPtEtaRPW->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
6681      fCorrelationsPro[0][1][0][1]->Fill(fPtMin+(p-1)*fPtBinWidth,fEtaMin+(e-1)*fEtaBinWidth,four1n1n1n1nW0W1W1W1PtEta,dM0111); 
6682     }
6683    } // end of if(dM0111)
6684   
6685   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
6686  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
6687   
6688 } // end of AliFlowAnalysisWithQCumulants::CalculateWeightedCorrelationsForDifferentialFlow(TString type)
6689
6690
6691 //================================================================================================================================
6692
6693
6694 void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
6695 {
6696  // 1.) Access average for 2D correlations from profiles and store them in 2D final results histograms;
6697  // 2.) Access spread for 2D correlations from profiles, calculate error and store it in 2D final results histograms;
6698  // 3.) Make projections along pt and eta axis and store results and errors in 1D final results histograms.
6699  
6700  Int_t typeFlag = -1;
6701  Int_t pWeightsFlag = -1;
6702  Int_t eWeightsFlag = -1;
6703
6704  if(type == "RP")
6705  {
6706   typeFlag = 0;
6707  } else if(type == "POI")
6708    {
6709     typeFlag = 1;
6710    } else 
6711      {
6712       cout<<"WARNING: type must be either RP or POI in AFAWQC::FCFDF() !!!!"<<endl;
6713       exit(0);
6714      }
6715      
6716  if(!useParticleWeights)
6717  {
6718   pWeightsFlag = 0;
6719  } else 
6720    {
6721     pWeightsFlag = 1;   
6722    }   
6723    
6724  if(eventWeights == "exact")
6725  {
6726   eWeightsFlag = 0;
6727  }          
6728   
6729  // shortcuts:
6730  Int_t t = typeFlag;
6731  Int_t pW = pWeightsFlag;
6732  Int_t eW = eWeightsFlag;
6733  
6734  // from 2D histogram fNonEmptyBins2D make two 1D histograms fNonEmptyBins1D in pt and eta (to be improved (i.e. moved somewhere else))  
6735  // pt:
6736  for(Int_t p=1;p<fnBinsPt;p++)
6737  {
6738   Double_t contentPt = 0.;
6739   for(Int_t e=1;e<=fnBinsEta;e++)
6740   {
6741    contentPt += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
6742   }
6743   fNonEmptyBins1D[t][0]->SetBinContent(p,contentPt);
6744  }
6745  // eta:
6746  for(Int_t e=1;e<fnBinsEta;e++)
6747  {
6748   Double_t contentEta = 0.;
6749   for(Int_t p=1;p<=fnBinsPt;p++)
6750   {
6751    contentEta += (fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e)));          
6752   }
6753   fNonEmptyBins1D[t][1]->SetBinContent(e,contentEta);
6754  }
6755  
6756  // from 2D profile in (pt,eta) make two 1D profiles in (pt) and (eta):
6757  TProfile *profile[2][4]; // [0=pt,1=eta][correlation index] // to be improved (do not hardwire the correlation index)
6758  
6759  for(Int_t pe=0;pe<2;pe++) // pt or eta
6760  {
6761   for(Int_t ci=0;ci<4;ci++) // correlation index
6762   {
6763    if(pe==0) profile[pe][ci] = this->MakePtProjection(fCorrelationsPro[t][pW][eW][ci]);
6764    if(pe==1) profile[pe][ci] = this->MakeEtaProjection(fCorrelationsPro[t][pW][eW][ci]);
6765   }
6766  }
6767   
6768  // transfer 2D profile into 2D histogram:
6769  // to be improved (see in documentation if there is a method to transfer values from 2D profile into 2D histogram)    
6770  for(Int_t ci=0;ci<4;ci++)
6771  {
6772   for(Int_t p=1;p<=fnBinsPt;p++)
6773   {
6774    for(Int_t e=1;e<=fnBinsEta;e++)
6775    {
6776     Double_t correlation = fCorrelationsPro[t][pW][eW][ci]->GetBinContent(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e)); 
6777     Double_t spread = fCorrelationsPro[t][pW][eW][ci]->GetBinError(fCorrelationsPro[t][pW][eW][ci]->GetBin(p,e));
6778     Double_t nEvts = fNonEmptyBins2D[t]->GetBinContent(fNonEmptyBins2D[t]->GetBin(p,e));
6779     Double_t error = 0.;
6780     fFinalCorrelations2D[t][pW][eW][ci]->SetBinContent(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),correlation);          
6781     if(nEvts>0)
6782     {
6783      error = spread/pow(nEvts,0.5);
6784      fFinalCorrelations2D[t][pW][eW][ci]->SetBinError(fFinalCorrelations2D[t][pW][eW][ci]->GetBin(p,e),error);
6785     }
6786    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
6787   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
6788  } // end of for(Int_t ci=0;ci<4;ci++)
6789  
6790  // transfer 1D profile into 1D histogram (pt):
6791  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
6792  for(Int_t ci=0;ci<4;ci++)
6793  {
6794   for(Int_t p=1;p<=fnBinsPt;p++)
6795   {
6796    if(profile[0][ci])
6797    {
6798     Double_t correlation = profile[0][ci]->GetBinContent(p); 
6799     Double_t spread = profile[0][ci]->GetBinError(p);
6800     Double_t nEvts = fNonEmptyBins1D[t][0]->GetBinContent(p);
6801     Double_t error = 0.;
6802     fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinContent(p,correlation); 
6803     if(nEvts>0)
6804     {
6805      error = spread/pow(nEvts,0.5);
6806      fFinalCorrelations1D[t][pW][eW][0][ci]->SetBinError(p,error);
6807     }  
6808    }   
6809   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
6810  } // end of for(Int_t ci=0;ci<4;ci++)
6811  
6812  // transfer 1D profile into 1D histogram (eta):
6813  // to be improved (see in documentation if there is a method to transfer values from 1D profile into 1D histogram)    
6814  for(Int_t ci=0;ci<4;ci++)
6815  {
6816   for(Int_t e=1;e<=fnBinsEta;e++)
6817   {
6818    if(profile[1][ci])
6819    {
6820     Double_t correlation = profile[1][ci]->GetBinContent(e); 
6821     fFinalCorrelations1D[t][pW][eW][1][ci]->SetBinContent(e,correlation);      
6822    }    
6823   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
6824  } // end of for(Int_t ci=0;ci<4;ci++)
6825   
6826 } // end of void AliFlowAnalysisWithQCumulants::FinalizeCorrelationsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
6827
6828
6829 //================================================================================================================================
6830
6831
6832 void AliFlowAnalysisWithQCumulants::CalculateCumulantsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
6833 {
6834  // calcualate cumulants for differential flow from measured correlations
6835  // Remark: cumulants calculated here are NOT corrected for non-uniform acceptance. This correction is applied in the method ...
6836   
6837  Int_t typeFlag = -1;
6838  Int_t pWeightsFlag = -1;
6839  Int_t eWeightsFlag = -1;
6840
6841  if(type == "RP")
6842  {
6843   typeFlag = 0;
6844  } else if(type == "POI")
6845    {
6846     typeFlag = 1;
6847    } else 
6848      {
6849       cout<<"WARNING: type must be either RP or POI in AFAWQC::CCFDF() !!!!"<<endl;
6850       exit(0);
6851      }
6852      
6853  if(!useParticleWeights)
6854  {
6855   pWeightsFlag = 0;
6856  } else 
6857    {
6858     pWeightsFlag = 1;   
6859    }       
6860   
6861  if(eventWeights == "exact")
6862  {
6863   eWeightsFlag = 0;
6864  } 
6865   
6866  // shortcuts:
6867  Int_t t = typeFlag;
6868  Int_t pW = pWeightsFlag; 
6869  Int_t eW = eWeightsFlag; 
6870  
6871  // correlation <<2>>: 
6872  Double_t two = fQCorrelations[pW][eW]->GetBinContent(1);
6873   
6874  // 2D (pt,eta):
6875  // to be improved (see documentation if I can do all this without looping)
6876  for(Int_t p=1;p<=fnBinsPt;p++)
6877  {
6878   for(Int_t e=1;e<=fnBinsEta;e++) 
6879   {  
6880    // reduced correlations:   
6881    Double_t twoPrime = fFinalCorrelations2D[t][pW][eW][0]->GetBinContent(fFinalCorrelations2D[t][pW][eW][0]->GetBin(p,e)); // <<2'>>(pt,eta)
6882    Double_t fourPrime = fFinalCorrelations2D[t][pW][eW][1]->GetBinContent(fFinalCorrelations2D[t][pW][eW][1]->GetBin(p,e)); // <<4'>>(pt,eta)
6883    for(Int_t nua=0;nua<2;nua++)
6884    {
6885     // QC{2'}:
6886     Double_t qc2Prime = twoPrime; // QC{2'} = <<2'>>
6887     fFinalCumulants2D[t][pW][eW][nua][0]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e),qc2Prime);    
6888     // QC{4'}:
6889     Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
6890     fFinalCumulants2D[t][pW][eW][nua][1]->SetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e),qc4Prime);   
6891    } // end of for(Int_t nua=0;nua<2;nua++)   
6892   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
6893  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
6894  
6895  // 1D (pt):
6896  // to be improved (see documentation if I can do all this without looping)
6897  // to be improved (treat pt and eta in one go)
6898  // to be improved (combine loops over nua for 2D and 1D)
6899  for(Int_t p=1;p<=fnBinsPt;p++)
6900  {
6901   // reduced correlations:   
6902   Double_t twoPrime = fFinalCorrelations1D[t][pW][eW][0][0]->GetBinContent(p); // <<2'>>(pt)
6903   Double_t fourPrime = fFinalCorrelations1D[t][pW][eW][0][1]->GetBinContent(p); // <<4'>>(pt)
6904   // spread of reduced correlations:
6905   Double_t twoPrimeError = fFinalCorrelations1D[t][pW][eW][0][0]->GetBinError(p); // sigma_2'/sqrt{N_2'}(pt)
6906   for(Int_t nua=0;nua<2;nua++)
6907   {
6908    // QC{2'}:
6909    Double_t qc2Prime = twoPrime; // QC{2'}
6910    Double_t qc2PrimeError = twoPrimeError; // sigma_{d_n{2}}/sqrt{N_2'} // to be improved
6911    fFinalCumulantsPt[t][pW][eW][nua][0]->SetBinContent(p,qc2Prime); 
6912    fFinalCumulantsPt[t][pW][eW][nua][0]->SetBinError(p,qc2PrimeError);   
6913    // QC{4'}:
6914    Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
6915    fFinalCumulantsPt[t][pW][eW][nua][1]->SetBinContent(p,qc4Prime); 
6916   } // end of for(Int_t nua=0;nua<2;nua++) 
6917  } // end of for(Int_t p=1;p<=fnBinsPt;p++)
6918  
6919  
6920  // 1D (eta):
6921  // to be improved (see documentation if I can do all this without looping)
6922  // to be improved (treat pt and eta in one go)
6923  // to be improved (combine loops over nua for 2D and 1D)
6924  for(Int_t e=1;e<=fnBinsEta;e++)
6925  {
6926   // reduced correlations:   
6927   Double_t twoPrime = fFinalCorrelations1D[t][pW][eW][1][0]->GetBinContent(e); // <<2'>>(eta)
6928   Double_t fourPrime = fFinalCorrelations1D[t][pW][eW][1][1]->GetBinContent(e); // <<4'>>(eta)
6929   for(Int_t nua=0;nua<2;nua++)
6930   {
6931    // QC{2'}:
6932    Double_t qc2Prime = twoPrime; // QC{2'}
6933    fFinalCumulantsEta[t][pW][eW][nua][0]->SetBinContent(e,qc2Prime);    
6934    // QC{4'}:
6935    Double_t qc4Prime = fourPrime - 2.*twoPrime*two; // QC{4'} = <<4'>> - 2*<<2'>><<2>>
6936    fFinalCumulantsEta[t][pW][eW][nua][1]->SetBinContent(e,qc4Prime);
6937   } // end of for(Int_t nua=0;nua<2;nua++)   
6938  } // end of for(Int_t e=1;e<=fnBinsEta;e++)
6939  
6940   
6941 } // end of void AliFlowAnalysisWithQCumulants::CalculateCumulantsForDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights); 
6942
6943
6944 //================================================================================================================================
6945
6946
6947 void AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
6948 {
6949  // calculate differential flow from differential cumulants and previously obtained integrated flow:
6950  
6951  Int_t typeFlag = -1;
6952  Int_t pWeightsFlag = -1;
6953  Int_t eWeightsFlag = -1;
6954
6955  if(type == "RP")
6956  {
6957   typeFlag = 0;
6958  } else if(type == "POI")
6959    {
6960     typeFlag = 1;
6961    } else 
6962      {
6963       cout<<"WARNING: type must be either RP or POI in AFAWQC::CDF() !!!!"<<endl;
6964       exit(0);
6965      }
6966      
6967  if(!useParticleWeights)
6968  {
6969   pWeightsFlag = 0;
6970  } else 
6971    {
6972     pWeightsFlag = 1;   
6973    }       
6974   
6975  if(eventWeights == "exact")
6976  {
6977   eWeightsFlag = 0;
6978  }  
6979   
6980  // shortcuts:
6981  Int_t t = typeFlag;
6982  Int_t pW = pWeightsFlag; 
6983  Int_t eW = eWeightsFlag; 
6984  
6985  // integrated flow:
6986  Double_t v2 = 0.;
6987  Double_t v4 = 0.;  
6988  
6989  if(pW == 0)
6990  {
6991   v2 = fIntFlow[pW][eW][1]->GetBinContent(1);   
6992   v4 = fIntFlow[pW][eW][1]->GetBinContent(2);    
6993  }
6994      
6995  if(pW == 1)
6996  {
6997   v2 = fIntFlow[pW][eW][0]->GetBinContent(1);   
6998   v4 = fIntFlow[pW][eW][0]->GetBinContent(2);    
6999  }
7000  
7001  // 2D:
7002  for(Int_t nua=0;nua<2;nua++)
7003  {
7004   for(Int_t p=1;p<=fnBinsPt;p++)
7005   {
7006    for(Int_t e=1;e<=fnBinsEta;e++) 
7007    { 
7008     // differential cumulants:
7009     Double_t qc2Prime = fFinalCumulants2D[t][pW][eW][nua][0]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][0]->GetBin(p,e)); // QC{2'}                    
7010     Double_t qc4Prime = fFinalCumulants2D[t][pW][eW][nua][1]->GetBinContent(fFinalCumulants2D[t][pW][eW][nua][1]->GetBin(p,e)); // QC{4'}
7011     // differential flow:
7012     Double_t v2Prime = 0.;                    
7013     Double_t v4Prime = 0.; 
7014     if(v2) 
7015     {
7016      v2Prime = qc2Prime/v2;
7017      fFinalFlow2D[t][pW][eW][nua][0]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][0]->GetBin(p,e),v2Prime);  
7018     }                   
7019     if(v4)
7020     {
7021      v4Prime = -qc4Prime/pow(v4,3.); 
7022      fFinalFlow2D[t][pW][eW][nua][1]->SetBinContent(fFinalFlow2D[t][pW][eW][nua][1]->GetBin(p,e),v4Prime);  
7023     }                    
7024    } // end of for(Int_t e=1;e<=fnBinsEta;e++)
7025   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
7026  } // end of for(Int_t nua=0;nua<2;nua++)
7027  
7028  // 1D (pt): // to be improved (combined with eta, combined nua loop with 2D)
7029  for(Int_t nua=0;nua<2;nua++)
7030  {
7031   for(Int_t p=1;p<=fnBinsPt;p++)
7032   {
7033    // differential cumulants:
7034    Double_t qc2Prime = fFinalCumulantsPt[t][pW][eW][nua][0]->GetBinContent(p); // QC{2'}                    
7035    Double_t qc4Prime = fFinalCumulantsPt[t][pW][eW][nua][1]->GetBinContent(p); // QC{4'}
7036    // differential flow:
7037    Double_t v2Prime = 0.;                    
7038    Double_t v4Prime = 0.; 
7039    if(v2) 
7040    {
7041     v2Prime = qc2Prime/v2;
7042     fFinalFlowPt[t][pW][eW][nua][0]->SetBinContent(p,v2Prime);  
7043    }                   
7044    if(v4)
7045    {
7046     v4Prime = -qc4Prime/pow(v4,3.); 
7047     fFinalFlowPt[t][pW][eW][nua][1]->SetBinContent(p,v4Prime);  
7048    }                    
7049   } // end of for(Int_t p=1;p<=fnBinsPt;p++)
7050  } // end of for(Int_t nua=0;nua<2;nua++)
7051  
7052  // 1D (eta): // to be improved (combined with pt, combined nua loop with 2D)
7053  for(Int_t nua=0;nua<2;nua++)
7054  {
7055   for(Int_t e=1;e<=fnBinsEta;e++)
7056   {
7057    // differential cumulants:
7058    Double_t qc2Prime = fFinalCumulantsEta[t][pW][eW][nua][0]->GetBinContent(e); // QC{2'}                    
7059    Double_t qc4Prime = fFinalCumulantsEta[t][pW][eW][nua][1]->GetBinContent(e); // QC{4'}
7060    // differential flow:
7061    Double_t v2Prime = 0.;                    
7062    Double_t v4Prime = 0.; 
7063    if(v2) 
7064    {
7065     v2Prime = qc2Prime/v2;
7066     fFinalFlowEta[t][pW][eW][nua][0]->SetBinContent(e,v2Prime);  
7067    }                   
7068    if(v4)
7069    {
7070     v4Prime = -qc4Prime/pow(v4,3.); 
7071     fFinalFlowEta[t][pW][eW][nua][1]->SetBinContent(e,v4Prime);  
7072    }                    
7073   } // end of for(Int_t e=1;e<=fnBinsEta;e++)
7074  } // end of for(Int_t nua=0;nua<2;nua++)
7075
7076 } // end of AliFlowAnalysisWithQCumulants::CalculateDiffFlow(TString type, Bool_t useParticleWeights)
7077
7078
7079 //================================================================================================================================
7080
7081
7082 void AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
7083 {
7084  // calculate final results for integrated flow of RPs and POIs 
7085  
7086  Int_t typeFlag = -1;
7087  Int_t pWeightsFlag = -1;
7088  Int_t eWeightsFlag = -1;
7089
7090  if(type == "RP")
7091  {
7092   typeFlag = 0;
7093  } else if(type == "POI")
7094    {
7095     typeFlag = 1;
7096    } else 
7097      {
7098       cout<<"WARNING: type must be either RP or POI in AFAWQC::CDF() !!!!"<<endl;
7099       exit(0);
7100      }
7101      
7102  if(!useParticleWeights)
7103  {
7104   pWeightsFlag = 0;
7105  } else 
7106    {
7107     pWeightsFlag = 1;   
7108    }       
7109   
7110  if(eventWeights == "exact")
7111  {
7112   eWeightsFlag = 0;
7113  } 
7114   
7115  // shortcuts:
7116  Int_t t = typeFlag;
7117  Int_t pW = pWeightsFlag; 
7118  Int_t eW = eWeightsFlag; 
7119   
7120  // pt yield:    
7121  TH1F *yield2ndPt = NULL;
7122  TH1F *yield4thPt = NULL;
7123  TH1F *yield6thPt = NULL;
7124  TH1F *yield8thPt = NULL;
7125  
7126  if(type == "POI")
7127  {
7128   yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtPOI())->Clone();
7129   yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtPOI())->Clone();
7130   yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtPOI())->Clone();
7131   yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtPOI())->Clone();  
7132  } 
7133  else if(type == "RP")
7134  {
7135   yield2ndPt = (TH1F*)(fCommonHists2nd->GetHistPtRP())->Clone();
7136   yield4thPt = (TH1F*)(fCommonHists4th->GetHistPtRP())->Clone();
7137   yield6thPt = (TH1F*)(fCommonHists6th->GetHistPtRP())->Clone();
7138   yield8thPt = (TH1F*)(fCommonHists8th->GetHistPtRP())->Clone();  
7139  } 
7140  
7141  Int_t nBinsPt = yield2ndPt->GetNbinsX();
7142  
7143  TH1D *flow2ndPt = NULL;
7144  TH1D *flow4thPt = NULL;
7145  TH1D *flow6thPt = NULL;
7146  TH1D *flow8thPt = NULL;
7147  
7148  // to be improve (nua = 0 is hardwired)
7149  flow2ndPt = (TH1D*)fFinalFlowPt[t][pW][eW][0][0]->Clone();
7150  flow4thPt = (TH1D*)fFinalFlowPt[t][pW][eW][0][1]->Clone();
7151  flow6thPt = (TH1D*)fFinalFlowPt[t][pW][eW][0][2]->Clone();
7152  flow8thPt = (TH1D*)fFinalFlowPt[t][pW][eW][0][3]->Clone(); 
7153    
7154  Double_t dvn2nd = 0., dvn4th = 0., dvn6th = 0., dvn8th = 0.; // differential flow
7155  Double_t dVn2nd = 0., dVn4th = 0., dVn6th = 0., dVn8th = 0.; // integrated flow 
7156  //Double_t dSd2nd = 0., dSd4th = 0., dSd6th = 0., dSd8th = 0.; // error on integrated flow (to be improved - calculation needed)
7157
7158  Double_t dYield2nd = 0., dYield4th = 0., dYield6th = 0., dYield8th = 0.; // pt yield 
7159  Double_t dSum2nd = 0., dSum4th = 0., dSum6th = 0., dSum8th = 0.; // needed for normalizing integrated flow
7160  
7161  // looping over pt bins:
7162  for(Int_t p=1;p<nBinsPt+1;p++)
7163  {
7164   dvn2nd = flow2ndPt->GetBinContent(p);
7165   dvn4th = flow4thPt->GetBinContent(p);
7166   dvn6th = flow6thPt->GetBinContent(p);
7167   dvn8th = flow8thPt->GetBinContent(p);
7168
7169   dYield2nd = yield2ndPt->GetBinContent(p);  
7170   dYield4th = yield4thPt->GetBinContent(p);
7171   dYield6th = yield6thPt->GetBinContent(p);
7172   dYield8th = yield8thPt->GetBinContent(p);
7173   
7174   dVn2nd += dvn2nd*dYield2nd;
7175   dVn4th += dvn4th*dYield4th;
7176   dVn6th += dvn6th*dYield6th;
7177   dVn8th += dvn8th*dYield8th;
7178   
7179   dSum2nd += dYield2nd;
7180   dSum4th += dYield4th;
7181   dSum6th += dYield6th;
7182   dSum8th += dYield8th;
7183   
7184   // ... to be improved - errors needed to be calculated   
7185   
7186  } // end of for(Int_t p=1;p<nBinsPt+1;p++)
7187
7188  // normalizing the results for integrated flow:
7189  
7190  
7191  
7192  
7193  
7194  if(dSum2nd) dVn2nd/=dSum2nd;
7195  if(dSum4th) dVn4th/=dSum4th;
7196  //if(dSum6th) dVn6th/=dSum6th;
7197  //if(dSum8th) dVn8th/=dSum8th;
7198  
7199  /*
7200  // storing the results for integrated flow:
7201  if(!(useParticleWeights))
7202  {
7203   if(type == "POI")
7204   {
7205    // 2nd:
7206    fIntFlowResultsPOIQC->SetBinContent(1,dVn2nd);
7207    fIntFlowResultsPOIQC->SetBinError(1,dSd2nd);
7208    // 4th:
7209    fIntFlowResultsPOIQC->SetBinContent(2,dVn4th);
7210    fIntFlowResultsPOIQC->SetBinError(2,dSd4th);
7211    // 6th:
7212    fIntFlowResultsPOIQC->SetBinContent(3,dVn6th);
7213    fIntFlowResultsPOIQC->SetBinError(3,dSd6th);
7214    // 8th:
7215    fIntFlowResultsPOIQC->SetBinContent(4,dVn8th);
7216    fIntFlowResultsPOIQC->SetBinError(4,dSd8th);
7217   }
7218   else if (type == "RP")
7219   {
7220    // 2nd:
7221    fIntFlowResultsRPQC->SetBinContent(1,dVn2nd);
7222    fIntFlowResultsRPQC->SetBinError(1,dSd2nd);
7223    // 4th:
7224    fIntFlowResultsRPQC->SetBinContent(2,dVn4th);
7225    fIntFlowResultsRPQC->SetBinError(2,dSd4th);
7226    // 6th:
7227    fIntFlowResultsRPQC->SetBinContent(3,dVn6th);
7228    fIntFlowResultsRPQC->SetBinError(3,dSd6th);
7229    // 8th:
7230    fIntFlowResultsRPQC->SetBinContent(4,dVn8th);
7231    fIntFlowResultsRPQC->SetBinError(4,dSd8th);
7232   }
7233  } 
7234  else if (useParticleWeights)
7235  {
7236   if(type == "POI")
7237   {
7238    // 2nd:
7239    fIntFlowResultsPOIQCW->SetBinContent(1,dVn2nd);
7240    fIntFlowResultsPOIQCW->SetBinError(1,dSd2nd);
7241    // 4th:
7242    fIntFlowResultsPOIQCW->SetBinContent(2,dVn4th);
7243    fIntFlowResultsPOIQCW->SetBinError(2,dSd4th);
7244    // 6th:
7245    fIntFlowResultsPOIQCW->SetBinContent(3,dVn6th);
7246    fIntFlowResultsPOIQCW->SetBinError(3,dSd6th);
7247    // 8th:
7248    fIntFlowResultsPOIQCW->SetBinContent(4,dVn8th);
7249    fIntFlowResultsPOIQCW->SetBinError(4,dSd8th);
7250   }
7251   else if (type == "RP")
7252   {
7253    // 2nd:
7254    fIntFlowResultsRPQCW->SetBinContent(1,dVn2nd);
7255    fIntFlowResultsRPQCW->SetBinError(1,dSd2nd);
7256    // 4th:
7257    fIntFlowResultsRPQCW->SetBinContent(2,dVn4th);
7258    fIntFlowResultsRPQCW->SetBinError(2,dSd4th);
7259    // 6th:
7260    fIntFlowResultsRPQCW->SetBinContent(3,dVn6th);
7261    fIntFlowResultsRPQCW->SetBinError(3,dSd6th);
7262    // 8th:
7263    fIntFlowResultsRPQCW->SetBinContent(4,dVn8th);
7264    fIntFlowResultsRPQCW->SetBinError(4,dSd8th);
7265   }
7266  }
7267  */
7268  
7269  // storing the results for integrated flow in common histos:
7270  // to be improved - now they are being filled twice ...
7271  if(type == "POI")
7272  {
7273   fCommonHistsResults2nd->FillIntegratedFlowPOI(dVn2nd,0.); // to be improved (errors)
7274   fCommonHistsResults4th->FillIntegratedFlowPOI(dVn4th,0.); // to be improved (errors)
7275   fCommonHistsResults6th->FillIntegratedFlowPOI(dVn6th,0.); // to be improved (errors)
7276   fCommonHistsResults8th->FillIntegratedFlowPOI(dVn8th,0.); // to be improved (errors)
7277  }
7278  else if (type == "RP")
7279  {
7280   fCommonHistsResults2nd->FillIntegratedFlowRP(dVn2nd,0.); // to be improved (errors)
7281   fCommonHistsResults4th->FillIntegratedFlowRP(dVn4th,0.); // to be improved (errors)
7282   fCommonHistsResults6th->FillIntegratedFlowRP(dVn6th,0.); // to be improved (errors)
7283   fCommonHistsResults8th->FillIntegratedFlowRP(dVn8th,0.); // to be improved (errors)
7284  }
7285  
7286  delete flow2ndPt;
7287  delete flow4thPt;
7288  //delete flow6thPt;
7289  //delete flow8thPt;
7290  
7291  delete yield2ndPt;
7292  delete yield4thPt;
7293  delete yield6thPt;
7294  delete yield8thPt;
7295   
7296 } // end of AliFlowAnalysisWithQCumulants::CalculateFinalResultsForRPandPOIIntegratedFlow(TString type, Bool_t useParticleWeights, TString eventWeights)
7297
7298
7299 //================================================================================================================================
7300
7301
7302 void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
7303 {
7304  // initialize arrays used for distributions:
7305  
7306  for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++) // non-weighted or weighted
7307  {
7308   for(Int_t eW=0;eW<2;eW++)
7309   {
7310    for(Int_t di=0;di<4;di++) // distribution index
7311    {
7312     fDistributions[pW][eW][di] = NULL;
7313    }
7314   } 
7315  }
7316  
7317 } // end of void AliFlowAnalysisWithQCumulants::InitializeArraysForDistributions()
7318
7319
7320 //================================================================================================================================
7321
7322
7323 void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
7324 {
7325  // book all histograms for distributions
7326  
7327  /*
7328  //weighted <2>_{n|n} distribution
7329  f2pDistribution = new TH1D("f2pDistribution","<2>_{n|n} distribution",100000,-0.02,0.1);
7330  f2pDistribution->SetXTitle("<2>_{n|n}");
7331  f2pDistribution->SetYTitle("Counts");
7332  fHistList->Add(f2pDistribution);
7333
7334  //weighted <4>_{n,n|n,n} distribution
7335  f4pDistribution = new TH1D("f4pDistribution","<4>_{n,n|n,n} distribution",100000,-0.00025,0.002);
7336  f4pDistribution->SetXTitle("<4>_{n,n|n,n}");
7337  f4pDistribution->SetYTitle("Counts");
7338  fHistList->Add(f4pDistribution); 
7339  
7340  //weighted <6>_{n,n,n|n,n,n} distribution
7341  f6pDistribution = new TH1D("f6pDistribution","<6>_{n,n,n|n,n,n} distribution",100000,-0.000005,0.000025);
7342  f6pDistribution->SetXTitle("<6>_{n,n,n|n,n,n}");
7343  f6pDistribution->SetYTitle("Counts");
7344  fHistList->Add(f6pDistribution);
7345  
7346  //weighted <8>_{n,n,n,n|n,n,n,n} distribution
7347  f8pDistribution = new TH1D("f8pDistribution","<8>_{n,n,n,n|n,n,n,n} distribution",100000,-0.000000001,0.00000001);
7348  f8pDistribution->SetXTitle("<8>_{n,n,n,n|n,n,n,n}");
7349  f8pDistribution->SetYTitle("Counts");
7350  fHistList->Add(f8pDistribution);
7351  */
7352  
7353 } // end of void AliFlowAnalysisWithQCumulants::BookEverythingForDistributions()
7354
7355
7356 //================================================================================================================================
7357
7358
7359 void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
7360 {
7361  // book and nest all lists in fHistList 
7362  
7363  // booking and nesting:  
7364  fHistList->Add(fWeightsList); 
7365  
7366  fIntFlowList = new TList();
7367  fIntFlowList->SetName("Integrated Flow");
7368  fIntFlowList->SetOwner(kTRUE);
7369  fHistList->Add(fIntFlowList);
7370  
7371  fIntFlowResults = new TList();
7372  fIntFlowResults->SetName("Results");
7373  fIntFlowResults->SetOwner(kTRUE);
7374  fIntFlowList->Add(fIntFlowResults);
7375  
7376  fIntFlowProfiles = new TList();
7377  fIntFlowProfiles->SetName("Profiles");
7378  fIntFlowProfiles->SetOwner(kTRUE);
7379  fIntFlowList->Add(fIntFlowProfiles);
7380  
7381  fDiffFlowList = new TList();
7382  fDiffFlowList->SetName("Differential Flow");
7383  fDiffFlowList->SetOwner(kTRUE); 
7384  fHistList->Add(fDiffFlowList);
7385    
7386  fDiffFlowProfiles = new TList(); 
7387  fDiffFlowProfiles->SetName("Profiles");
7388  fDiffFlowProfiles->SetOwner(kTRUE);
7389  fDiffFlowList->Add(fDiffFlowProfiles);
7390  
7391  fDiffFlowResults = new TList();
7392  fDiffFlowResults->SetName("Results");
7393  fDiffFlowResults->SetOwner(kTRUE);
7394  fDiffFlowList->Add(fDiffFlowResults);
7395  
7396  fDistributionsList = new TList();
7397  fDistributionsList->SetName("Distributions");
7398  fDistributionsList->SetOwner(kTRUE);
7399  fHistList->Add(fDistributionsList);
7400  
7401  fNestedLoopsList = new TList();
7402  fNestedLoopsList->SetName("Nested Loops");
7403  fNestedLoopsList->SetOwner(kTRUE);
7404  fHistList->Add(fNestedLoopsList);
7405  
7406  // flags for naming nested lists:  
7407  TList list;
7408  list.SetOwner(kTRUE);
7409  TString typeFlag[2] = {"RP","POI"}; 
7410  TString pWeightsFlag[2] = {"not used","used"}; 
7411  TString eWeightsFlag[2] = {"exact","non-exact"};
7412  TString nuaFlag[2] = {"not corrected","corrected"}; // nua = non-uniform acceptance
7413  TString sinCosFlag[2] = {"sin","cos"};
7414
7415  // nested lists in fDiffFlowProfiles (Differential Flow/Profiles): 
7416  for(Int_t t=0;t<2;t++) // type: RP or POI
7417  {
7418   fDFPType[t] = (TList*)list.Clone();
7419   fDFPType[t]->SetName(Form("%s",typeFlag[t].Data()));
7420   fDiffFlowProfiles->Add(fDFPType[t]);  
7421   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++) // weights: not used or used  
7422   {
7423    fDFPParticleWeights[t][pW] = (TList*)list.Clone();
7424    fDFPParticleWeights[t][pW]->SetName(Form("%s, pWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data()));
7425    fDFPType[t]->Add(fDFPParticleWeights[t][pW]);
7426    for(Int_t eW=0;eW<2;eW++)
7427    { 
7428     fDFPEventWeights[t][pW][eW] = (TList*)list.Clone();
7429     fDFPEventWeights[t][pW][eW]->SetName(Form("%s, pWeights %s, eWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()));
7430     fDFPParticleWeights[t][pW]->Add(fDFPEventWeights[t][pW][eW]);
7431     // correlations: 
7432     fDiffFlowCorrelations[t][pW][eW] = (TList*)list.Clone();
7433     fDiffFlowCorrelations[t][pW][eW]->SetName(Form("Correlations (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()));
7434     fDFPEventWeights[t][pW][eW]->Add(fDiffFlowCorrelations[t][pW][eW]);
7435     // products of correlations:
7436     fDiffFlowProductsOfCorrelations[t][pW][eW] = (TList*)list.Clone();
7437     fDiffFlowProductsOfCorrelations[t][pW][eW]->SetName(Form("Products of correlations (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()));
7438     fDFPEventWeights[t][pW][eW]->Add(fDiffFlowProductsOfCorrelations[t][pW][eW]);
7439     // correction terms:   
7440     for(Int_t sc=0;sc<2;sc++) // corrections for NUA: sin or cos terms 
7441     {
7442      fDiffFlowCorrectionTerms[t][pW][eW][sc] = (TList*)list.Clone();
7443      fDiffFlowCorrectionTerms[t][pW][eW][sc]->SetName(Form("Corrections for NUA (%s, pWeights %s, eWeights %s, %s terms)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),sinCosFlag[sc].Data()));
7444      fDFPEventWeights[t][pW][eW]->Add(fDiffFlowCorrectionTerms[t][pW][eW][sc]);
7445     }
7446    }
7447   } 
7448  } 
7449  
7450  // nested lists in fDiffFlowResults (Differential Flow/Results):
7451  for(Int_t t=0;t<2;t++) // RP or POI
7452  {
7453   fDFRType[t] = (TList*)list.Clone();
7454   fDFRType[t]->SetName(Form("%s",typeFlag[t].Data()));
7455   fDiffFlowResults->Add(fDFRType[t]);  
7456   for(Int_t pW=0;pW<1+(Int_t)(fUsePhiWeights||fUsePtWeights||fUseEtaWeights);pW++) // particle weights not used or used
7457   {
7458    fDFRParticleWeights[t][pW] = (TList*)list.Clone();
7459    fDFRParticleWeights[t][pW]->SetName(Form("%s, pWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data()));
7460    fDFRType[t]->Add(fDFRParticleWeights[t][pW]);
7461    for(Int_t eW=0;eW<2;eW++) // event weights: exact ot non-exact // to be improved (terminology)
7462    {
7463     fDFREventWeights[t][pW][eW] = (TList*)list.Clone();
7464     fDFREventWeights[t][pW][eW]->SetName(Form("%s, pWeights %s, eWeights %s",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()));
7465     fDFRParticleWeights[t][pW]->Add(fDFREventWeights[t][pW][eW]);
7466     // final correlations:    
7467     fDiffFlowFinalCorrelations[t][pW][eW] = (TList*)list.Clone();
7468     fDiffFlowFinalCorrelations[t][pW][eW]->SetName(Form("Correlations (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()));
7469     fDFREventWeights[t][pW][eW]->Add(fDiffFlowFinalCorrelations[t][pW][eW]); 
7470     // final covariances:    
7471     fDiffFlowFinalCovariances[t][pW][eW] = (TList*)list.Clone();
7472     fDiffFlowFinalCovariances[t][pW][eW]->SetName(Form("Covariances (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()));
7473     fDFREventWeights[t][pW][eW]->Add(fDiffFlowFinalCovariances[t][pW][eW]);
7474     // final corrections:    
7475     fDiffFlowFinalCorrections[t][pW][eW] = (TList*)list.Clone();
7476     fDiffFlowFinalCorrections[t][pW][eW]->SetName(Form("Corrections (%s, pWeights %s, eWeights %s)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data()));
7477     fDFREventWeights[t][pW][eW]->Add(fDiffFlowFinalCorrections[t][pW][eW]);
7478     for(Int_t nua=0;nua<2;nua++)
7479     {
7480      fDFRCorrections[t][pW][eW][nua] = (TList*)list.Clone();
7481      fDFRCorrections[t][pW][eW][nua]->SetName(Form("%s, pWeights %s, eWeights %s, %s for NUA",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data()));
7482      fDFREventWeights[t][pW][eW]->Add(fDFRCorrections[t][pW][eW][nua]); 
7483      // final cumulants:    
7484      fDiffFlowFinalCumulants[t][pW][eW][nua] = (TList*)list.Clone();
7485      fDiffFlowFinalCumulants[t][pW][eW][nua]->SetName(Form("Cumulants (%s, pWeights %s, eWeights %s, %s for NUA)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data()));
7486      fDFRCorrections[t][pW][eW][nua]->Add(fDiffFlowFinalCumulants[t][pW][eW][nua]); 
7487      // final differential flow:
7488      fDiffFlowFinalFlow[t][pW][eW][nua] = (TList*)list.Clone();
7489      fDiffFlowFinalFlow[t][pW][eW][nua]->SetName(Form("Differential Flow (%s, pWeights %s, eWeights %s, %s for NUA)",typeFlag[t].Data(),pWeightsFlag[pW].Data(),eWeightsFlag[eW].Data(),nuaFlag[nua].Data()));
7490      fDFRCorrections[t][pW][eW][nua]->Add(fDiffFlowFinalFlow[t][pW][eW][nua]);          
7491     }
7492    } 
7493   }
7494  } 
7495  
7496 } // end of void AliFlowAnalysisWithQCumulants::BookAndNestAllLists()
7497
7498
7499 //================================================================================================================================
7500
7501
7502 void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
7503 {
7504  // fill common result histograms for differential flow
7505  
7506  // shortcuts for the flags:
7507  Int_t t = 0; // 0=RP, 1=POI
7508  Int_t pW = (Int_t)(useParticleWeights); // 0=weights not useed, 1=weights used
7509  Int_t eW = -1; 
7510  Int_t nua = (Int_t)(correctedForNUA); // 0=not corrected for NUA, 1=corrected for NUA
7511  
7512  if(type == "POI")
7513  {
7514   t = 1;
7515  }
7516  
7517  if(eventWeights == "exact")
7518  {
7519   eW = 0;
7520  }
7521   
7522  for(Int_t o=0;o<4;o++) // order
7523  {
7524   if(!fFinalFlowPt[t][pW][eW][nua][o])
7525   {
7526     cout<<"WARNING: fFinalFlowPt[t][pW][eW][nua][o] is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
7527     cout<<"t = "<<t<<endl;
7528     cout<<"pW = "<<pW<<endl;
7529     cout<<"eW = "<<eW<<endl;
7530     cout<<"nua = "<<nua<<endl;
7531     cout<<"o = "<<o<<endl;
7532     exit(0); 
7533   }
7534   if(!fFinalFlowEta[t][pW][eW][nua][o])
7535   {
7536     cout<<"WARNING: fFinalFlowEta[t][pW][eW][nua][o] is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
7537     cout<<"t = "<<t<<endl;
7538     cout<<"pW = "<<pW<<endl;
7539     cout<<"eW = "<<eW<<endl;
7540     cout<<"nua = "<<nua<<endl;
7541     cout<<"o = "<<o<<endl;
7542     exit(0); 
7543   }  
7544  } 
7545    
7546  if(!(fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th))
7547  {
7548   cout<<"WARNING: fCommonHistsResults2nd && fCommonHistsResults4th && fCommonHistsResults6th && fCommonHistsResults8th"<<endl; 
7549   cout<<"         is NULL in AFAWQC::FCHRIF() !!!!"<<endl;
7550   exit(0);
7551  }
7552  
7553  // pt:
7554  for(Int_t p=1;p<=fnBinsPt;p++)
7555  {
7556   Double_t v2 = fFinalFlowPt[t][pW][eW][nua][0]->GetBinContent(p);
7557   Double_t v4 = fFinalFlowPt[t][pW][eW][nua][1]->GetBinContent(p);
7558   Double_t v6 = fFinalFlowPt[t][pW][eW][nua][2]->GetBinContent(p);
7559   Double_t v8 = fFinalFlowPt[t][pW][eW][nua][3]->GetBinContent(p);
7560   
7561   //Double_t v2Error = fFinalFlow1D[t][pW][nua][0][0]->GetBinError(p);
7562   //Double_t v4Error = fFinalFlow1D[t][pW][nua][0][1]->GetBinError(p);
7563   //Double_t v6Error = fFinalFlow1D[t][pW][nua][0][2]->GetBinError(p);
7564   //Double_t v8Error = fFinalFlow1D[t][pW][nua][0][3]->GetBinError(p);
7565  
7566   if(type == "RP")
7567   {
7568    fCommonHistsResults2nd->FillDifferentialFlowPtRP(p,v2,0.);
7569    fCommonHistsResults4th->FillDifferentialFlowPtRP(p,v4,0.);
7570    fCommonHistsResults6th->FillDifferentialFlowPtRP(p,v6,0.);
7571    fCommonHistsResults8th->FillDifferentialFlowPtRP(p,v8,0.);
7572   } else if(type == "POI")
7573     {
7574      fCommonHistsResults2nd->FillDifferentialFlowPtPOI(p,v2,0.);
7575      fCommonHistsResults4th->FillDifferentialFlowPtPOI(p,v4,0.);
7576      fCommonHistsResults6th->FillDifferentialFlowPtPOI(p,v6,0.);
7577      fCommonHistsResults8th->FillDifferentialFlowPtPOI(p,v8,0.);
7578     }
7579  } // end of for(Int_t p=1;p<=fnBinsPt;p++)   
7580  
7581  // eta:
7582  for(Int_t e=1;e<=fnBinsEta;e++)
7583  {
7584   Double_t v2 = fFinalFlowEta[t][pW][eW][nua][0]->GetBinContent(e);
7585   Double_t v4 = fFinalFlowEta[t][pW][eW][nua][1]->GetBinContent(e);
7586   Double_t v6 = fFinalFlowEta[t][pW][eW][nua][2]->GetBinContent(e);
7587   Double_t v8 = fFinalFlowEta[t][pW][eW][nua][3]->GetBinContent(e);
7588   
7589   //Double_t v2Error = fFinalFlow1D[t][pW][nua][1][0]->GetBinError(e);
7590   //Double_t v4Error = fFinalFlow1D[t][pW][nua][1][1]->GetBinError(e);
7591   //Double_t v6Error = fFinalFlow1D[t][pW][nua][1][2]->GetBinError(e);
7592   //Double_t v8Error = fFinalFlow1D[t][pW][nua][1][3]->GetBinError(e);
7593  
7594   if(type == "RP")
7595   {
7596    fCommonHistsResults2nd->FillDifferentialFlowEtaRP(e,v2,0.);
7597    fCommonHistsResults4th->FillDifferentialFlowEtaRP(e,v4,0.);
7598    fCommonHistsResults6th->FillDifferentialFlowEtaRP(e,v6,0.);
7599    fCommonHistsResults8th->FillDifferentialFlowEtaRP(e,v8,0.);
7600   } else if(type == "POI")
7601     {
7602      fCommonHistsResults2nd->FillDifferentialFlowEtaPOI(e,v2,0.);
7603      fCommonHistsResults4th->FillDifferentialFlowEtaPOI(e,v4,0.);
7604      fCommonHistsResults6th->FillDifferentialFlowEtaPOI(e,v6,0.);
7605      fCommonHistsResults8th->FillDifferentialFlowEtaPOI(e,v8,0.);
7606     }
7607  } // end of for(Int_t e=1;e<=fnBinsEta;e++)    
7608  
7609 } // end of void AliFlowAnalysisWithQCumulants::FillCommonHistResultsDiffFlow(TString type, Bool_t useParticleWeights, TString eventWeights, Bool_t correctedForNUA)
7610
7611
7612 //================================================================================================================================
7613
7614
7615 void AliFlowAnalysisWithQCumulants::AccessConstants()
7616 {
7617  // access needed common constants from AliFlowCommonConstants
7618  
7619  fnBinsPhi = AliFlowCommonConstants::GetNbinsPhi();
7620  fPhiMin = AliFlowCommonConstants::GetPhiMin();      
7621  fPhiMax = AliFlowCommonConstants::GetPhiMax();
7622  if(fnBinsPhi) fPhiBinWidth = (fPhiMax-fPhiMin)/fnBinsPhi;  
7623  fnBinsPt = AliFlowCommonConstants::GetNbinsPt();
7624  fPtMin = AliFlowCommonConstants::GetPtMin();        
7625  fPtMax = AliFlowCommonConstants::GetPtMax();
7626  if(fnBinsPt) fPtBinWidth = (fPtMax-fPtMin)/fnBinsPt;  
7627  fnBinsEta = AliFlowCommonConstants::GetNbinsEta();
7628  fEtaMin = AliFlowCommonConstants::GetEtaMin();      
7629  fEtaMax = AliFlowCommonConstants::GetEtaMax();
7630  if(fnBinsEta) fEtaBinWidth = (fEtaMax-fEtaMin)/fnBinsEta;  
7631  
7632 } // end of void AliFlowAnalysisWithQCumulants::AccessConstants()
7633
7634
7635 //================================================================================================================================
7636
7637
7638 void AliFlowAnalysisWithQCumulants::CalculateSumAndProductOfEventWeights()
7639 {
7640  // 1.) calculate sum of linear and quadratic event weights;
7641  // 2.) calculate products of event weights
7642  
7643  Double_t dMult = (*fSMpk)(0,0); // multiplicity (number of particles used to determine the reaction plane)
7644
7645  Double_t eventWeight[4] = {0}; 
7646  eventWeight[0] = dMult*(dMult-1); // event weight for <2> 
7647  eventWeight[1] = dMult*(dMult-1)*(dMult-2)*(dMult-3); // event weight for <4> 
7648  eventWeight[2] = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5); // event weight for <6> 
7649  eventWeight[3] = dMult*(dMult-1)*(dMult-2)*(dMult-3)*(dMult-4)*(dMult-5)*(dMult-6)*(dMult-7); // event weight for <8> 
7650  
7651  for(Int_t p=0;p<2;p++)
7652  {
7653   for(Int_t c=0;c<4;c++)
7654   { 
7655    fSumOfEventWeights[0][0][p]->Fill(c+0.5,pow(eventWeight[c],p+1)); 
7656   }
7657  }
7658   
7659  // to be improved (hardwired pW and eW):
7660  fProductOfEventWeights[0][0]->Fill(0.5,eventWeight[0]*eventWeight[1]); 
7661  fProductOfEventWeights[0][0]->Fill(1.5,eventWeight[0]*eventWeight[2]); 
7662  fProductOfEventWeights[0][0]->Fill(2.5,eventWeight[0]*eventWeight[3]); 
7663  fProductOfEventWeights[0][0]->Fill(3.5,eventWeight[1]*eventWeight[2]); 
7664  fProductOfEventWeights[0][0]->Fill(4.5,eventWeight[1]*eventWeight[3]); 
7665  fProductOfEventWeights[0][0]->Fill(5.5,eventWeight[2]*eventWeight[3]); 
7666        
7667 } // end of void AliFlowAnalysisWithQCumulants::CalculateSumAndProductOfEventWeights()
7668
7669
7670 //================================================================================================================================
7671