more for weigths
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliAnalysisTaskQCumulants.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  * analysis task for Q-cumulants      * 
18  *                                    * 
19  * authors: Naomi van der Kolk        *
20  *           (kolk@nikhef.nl)         *  
21  *          Raimond Snellings         *
22  *           (snelling@nikhef.nl)     * 
23  *          Ante Bilandzic            *
24  *           (anteb@nikhef.nl)        * 
25  * ***********************************/
26  
27 #include "Riostream.h"
28 #include "TChain.h"
29 #include "TTree.h"
30 #include "TFile.h"
31 #include "TList.h"
32 #include "TH1.h"
33 #include "TGraph.h"
34 #include "TProfile.h"
35 #include "TProfile2D.h"
36 #include "TProfile3D.h"
37
38 #include "AliAnalysisTask.h"
39 #include "AliAnalysisDataSlot.h"
40 #include "AliAnalysisDataContainer.h"
41 #include "AliAnalysisManager.h"
42
43 #include "AliESDEvent.h"
44 #include "AliESDInputHandler.h"
45
46 #include "AliAODEvent.h"
47 #include "AliAODInputHandler.h"
48
49 #include "AliMCEventHandler.h"
50 #include "AliMCEvent.h"
51
52 #include "../../CORRFW/AliCFManager.h"
53
54 #include "AliAnalysisTaskQCumulants.h"
55 #include "AliFlowEventSimpleMaker.h"
56 #include "AliFlowAnalysisWithQCumulants.h"
57 #include "AliFlowCumuConstants.h"
58 #include "AliFlowCommonConstants.h"
59 #include "AliFlowCommonHist.h"
60 #include "AliFlowCommonHistResults.h"
61 #include "AliQCumulantsFunctions.h"
62
63 ClassImp(AliAnalysisTaskQCumulants)
64
65 //================================================================================================================
66
67 AliAnalysisTaskQCumulants::AliAnalysisTaskQCumulants(const char *name, Bool_t on): 
68  AliAnalysisTask(name,""), 
69  fESD(NULL),
70  fAOD(NULL),
71  fQCA(NULL),//Q-cumulant Analysis (QCA) object
72  fEventMaker(NULL),
73  fAnalysisType("ESD"), 
74  fCFManager1(NULL),
75  fCFManager2(NULL),
76  fListHistos(NULL),
77  fQAInt(NULL),
78  fQADiff(NULL),
79  fQA(on)
80 {
81  //constructor
82  cout<<"AliAnalysisTaskQCumulants::AliAnalysisTaskQCumulants(const char *name)"<<endl;
83  
84  // Define input and output slots here
85  // Input slot #0 works with a TChain
86  DefineInput(0, TChain::Class());
87   
88  // Output slot #0 writes into a TList container
89  DefineOutput(0, TList::Class());  
90  if(on) 
91  {
92   DefineOutput(1, TList::Class());
93   DefineOutput(2, TList::Class()); 
94  }  
95 }
96
97 AliAnalysisTaskQCumulants::AliAnalysisTaskQCumulants(): 
98  fESD(NULL),
99  fAOD(NULL), 
100  fQCA(NULL),//Q-cumulant Analysis (QCA) object
101  fEventMaker(NULL),
102  fAnalysisType("ESD"),
103  fCFManager1(NULL),
104  fCFManager2(NULL),
105  fListHistos(NULL),  
106  fQAInt(NULL),
107  fQADiff(NULL),
108  fQA(kFALSE)
109 {
110  //dummy constructor
111  cout<<"AliAnalysisTaskQCumulants::AliAnalysisTaskQCumulants()"<<endl;
112 }
113
114 //================================================================================================================
115
116 void AliAnalysisTaskQCumulants::ConnectInputData(Option_t *) 
117 {
118  //connect ESD or AOD (called once)
119  cout<<"AliAnalysisTaskQCumulants::ConnectInputData(Option_t *)"<<endl;
120
121  TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
122  if (!tree) 
123  {
124   Printf("ERROR: Could not read chain from input slot 0");
125  } 
126  else 
127  {
128  //disable all branches and enable only the needed ones
129   if (fAnalysisType == "MC") {
130      // we want to process only MC
131       tree->SetBranchStatus("*", kFALSE);
132
133       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
134
135       if (!esdH) {
136         Printf("ERROR: Could not get ESDInputHandler");
137       } else {
138         fESD = esdH->GetEvent();
139       }
140     }
141     else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1"  ) {
142       tree->SetBranchStatus("*", kFALSE);
143       tree->SetBranchStatus("Tracks.*", kTRUE);
144
145       AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
146
147       if (!esdH) {
148         Printf("ERROR: Could not get ESDInputHandler");
149       } else
150         fESD = esdH->GetEvent();
151     }
152     else if (fAnalysisType == "AOD") {
153       AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
154
155       if (!aodH) {
156         Printf("ERROR: Could not get AODInputHandler");
157       }
158       else {
159         fAOD = aodH->GetEvent();
160       }
161     }
162     else {
163       Printf("Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
164
165     }
166   }
167 }
168
169 //================================================================================================================
170
171 void AliAnalysisTaskQCumulants::CreateOutputObjects() 
172 {
173  //called at every worker node to initialize
174  cout<<"AliAnalysisTaskQCumulants::CreateOutputObjects()"<<endl;
175
176  
177  //OpenFile(0);
178  
179
180  if(!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) 
181  {
182   cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
183   exit(1);
184  }
185  
186  //event maker
187  fEventMaker = new AliFlowEventSimpleMaker();
188  
189  //analyser
190  fQCA = new AliFlowAnalysisWithQCumulants();
191  fQCA->Init();
192
193  if(fQCA->GetHistList()) 
194  {
195   fListHistos = fQCA->GetHistList();
196   //fListHistos->Print();
197  }
198  else 
199  {
200   Printf("ERROR: Could not retrieve histogram list"); 
201  }
202  
203  //PostData(0,fListHistos);
204  
205 }
206
207 //================================================================================================================
208
209 void AliAnalysisTaskQCumulants::Exec(Option_t *) 
210 {
211  //main loop (called for each event)
212  if (fAnalysisType == "MC") {
213     // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
214     // This handler can return the current MC event
215
216     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
217     if (!eventHandler) {
218       Printf("ERROR: Could not retrieve MC event handler");
219       return;
220     }
221
222     AliMCEvent* mcEvent = eventHandler->MCEvent();
223     if (!mcEvent) {
224       Printf("ERROR: Could not retrieve MC event");
225       return;
226     }
227
228     Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
229     fCFManager1->SetEventInfo(mcEvent);
230     fCFManager2->SetEventInfo(mcEvent);
231
232     //Q-cumulant analysis 
233     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
234     fQCA->Make(fEvent);
235     delete fEvent;
236   }
237   else if (fAnalysisType == "ESD") {
238     if (!fESD) {
239       Printf("ERROR: fESD not available");
240       return;
241     }
242     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
243     
244     //Q-cumulant analysis    
245     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);//cuts
246     //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
247     
248     fQCA->Make(fEvent); 
249     
250     delete fEvent;
251   }
252   else if (fAnalysisType == "ESDMC0") {
253     if (!fESD) {
254       Printf("ERROR: fESD not available");
255       return;
256     }
257     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
258     
259     AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
260     if (!eventHandler) {
261       Printf("ERROR: Could not retrieve MC event handler");
262       return;
263     }
264
265     AliMCEvent* mcEvent = eventHandler->MCEvent();
266     if (!mcEvent) {
267       Printf("ERROR: Could not retrieve MC event");
268       return;
269     }
270
271     fCFManager1->SetEventInfo(mcEvent);
272     fCFManager2->SetEventInfo(mcEvent);
273
274     //Q-cumulant analysis 
275     AliFlowEventSimple* fEvent=NULL;
276     if (fAnalysisType == "ESDMC0") { 
277       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
278     } else if (fAnalysisType == "ESDMC1") {
279       fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
280     }
281     fQCA->Make(fEvent);
282     delete fEvent;
283     //delete mcEvent;
284   }
285   
286   else if (fAnalysisType == "AOD") {
287     if (!fAOD) {
288       Printf("ERROR: fAOD not available");
289       return;
290     }
291     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
292
293     // analysis 
294     //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
295     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
296     fQCA->Make(fEvent);
297     delete fEvent;
298   }
299   
300   PostData(0,fListHistos); 
301   if(fQA) 
302   {
303    PostData(1,fQAInt);
304    PostData(2,fQADiff); 
305   }
306 }
307
308 //================================================================================================================
309
310 void AliAnalysisTaskQCumulants::Terminate(Option_t *) 
311 {
312  //accessing the output list which contains the merged 2D and 3D profiles from all worker nodes
313  fListHistos = (TList*)GetOutputData(0);
314  //fListHistos->Print();
315  
316  if(fListHistos)
317  {          
318   //final results (integrated flow)
319   TH1D *intFlowResults = dynamic_cast<TH1D*>(fListHistos->FindObject("fIntFlowResultsQC"));
320   
321   //final results (differential flow)
322   TH1D *diffFlowResults2ndOrder = dynamic_cast<TH1D*>(fListHistos->FindObject("fDiffFlowResults2ndOrderQC"));
323   TH1D *diffFlowResults4thOrder = dynamic_cast<TH1D*>(fListHistos->FindObject("fDiffFlowResults4thOrderQC"));
324   
325   //final results for covariances (1st bin <2*4>-<2>*<4>, 2nd bin <2*6>-<2>*<6>, ...)
326   TH1D *covariances = dynamic_cast<TH1D*>(fListHistos->FindObject("fCovariances"));
327   
328   //common control histograms (taking into account only the events with 2 and more particles)  
329   AliFlowCommonHist *commonHist2nd = dynamic_cast<AliFlowCommonHist*>(fListHistos->FindObject("AliFlowCommonHist2ndOrderQC"));
330   
331   //common control histograms (taking into account only the events with 4 and more particles)  
332   AliFlowCommonHist *commonHist4th = dynamic_cast<AliFlowCommonHist*>(fListHistos->FindObject("AliFlowCommonHist4thOrderQC"));
333   
334   //common control histograms (taking into account only the events with 6 and more particles)  
335   AliFlowCommonHist *commonHist6th = dynamic_cast<AliFlowCommonHist*>(fListHistos->FindObject("AliFlowCommonHist6thOrderQC"));
336   
337   //common control histograms (taking into account only the events with 8 and more particles)  
338   AliFlowCommonHist *commonHist8th = dynamic_cast<AliFlowCommonHist*>(fListHistos->FindObject("AliFlowCommonHist8thOrderQC"));
339   
340   //common histograms to store the final results for the 2nd order integrated and differential flow
341   AliFlowCommonHistResults *commonHistRes2nd = dynamic_cast<AliFlowCommonHistResults*>(fListHistos->FindObject("AliFlowCommonHistResults2ndOrderQC"));
342   
343   //common histograms to store the final results for the 4th order integrated and differential flow
344   AliFlowCommonHistResults *commonHistRes4th = dynamic_cast<AliFlowCommonHistResults*>(fListHistos->FindObject("AliFlowCommonHistResults4thOrderQC"));
345   
346   //common histograms to store the final results for the 6th order integrated and differential flow
347   AliFlowCommonHistResults *commonHistRes6th = dynamic_cast<AliFlowCommonHistResults*>(fListHistos->FindObject("AliFlowCommonHistResults6thOrderQC"));
348   
349   //common histograms to store the final results for the 8th order integrated and differential flow
350   AliFlowCommonHistResults *commonHistRes8th = dynamic_cast<AliFlowCommonHistResults*>(fListHistos->FindObject("AliFlowCommonHistResults8thOrderQC"));
351   
352   //average selected multiplicity (for int. flow) 
353   TProfile *AvMult = dynamic_cast<TProfile*>(fListHistos->FindObject("fAvMultIntFlowQC"));
354   
355   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
356   //                        !!!! to be removed !!!!
357   //profiles containing the Q-vectors from all events 
358   TProfile *qvectorForEachEventX = dynamic_cast<TProfile*>(fListHistos->FindObject("fQvectorForEachEventX"));
359   TProfile *qvectorForEachEventY = dynamic_cast<TProfile*>(fListHistos->FindObject("fQvectorForEachEventY"));  
360   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
361     
362   //multi-particle correlations calculated from Q-vectors
363   TProfile *QCorrelations = dynamic_cast<TProfile*>(fListHistos->FindObject("fQCorrelations"));
364   
365   //average of products: 1st bin: <2*4>, 2nd bin: <2*6>, ...
366   TProfile *QProduct = dynamic_cast<TProfile*>(fListHistos->FindObject("fQProduct"));
367   
368   //average 2-, 3- and 4-particle correlations per pt-bin 
369   TProfile *binnedPt2p1n1nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerPtBin1n1nRP"));
370   TProfile *binnedPt2p2n2nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerPtBin2n2nRP"));
371   TProfile *binnedPt3p2n1n1nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerPtBin2n1n1nRP"));
372   TProfile *binnedPt3p1n1n2nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerPtBin1n1n2nRP"));
373   TProfile *binnedPt4p1n1n1n1nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f4PerPtBin1n1n1n1nRP"));
374   
375   //average 2-, 3- and 4-particle correlations per eta-bin 
376   TProfile *binnedEta2p1n1nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerEtaBin1n1nRP"));
377   TProfile *binnedEta2p2n2nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerEtaBin2n2nRP"));
378   TProfile *binnedEta3p2n1n1nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerEtaBin2n1n1nRP"));
379   TProfile *binnedEta3p1n1n2nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerEtaBin1n1n2nRP"));
380   TProfile *binnedEta4p1n1n1n1nRP = dynamic_cast<TProfile*>(fListHistos->FindObject("f4PerEtaBin1n1n1n1nRP"));  
381   
382   //average 2-, 3- and 4-particle correlations per pt-bin 
383   TProfile *binnedPt2p1n1nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerPtBin1n1nPOI"));
384   TProfile *binnedPt2p2n2nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerPtBin2n2nPOI"));
385   TProfile *binnedPt3p2n1n1nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerPtBin2n1n1nPOI"));
386   TProfile *binnedPt3p1n1n2nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerPtBin1n1n2nPOI"));
387   TProfile *binnedPt4p1n1n1n1nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f4PerPtBin1n1n1n1nPOI"));
388   
389   //average 2-, 3- and 4-particle correlations per eta-bin 
390   TProfile *binnedEta2p1n1nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerEtaBin1n1nPOI"));
391   TProfile *binnedEta2p2n2nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f2PerEtaBin2n2nPOI"));
392   TProfile *binnedEta3p2n1n1nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerEtaBin2n1n1nPOI"));
393   TProfile *binnedEta3p1n1n2nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f3PerEtaBin1n1n2nPOI"));
394   TProfile *binnedEta4p1n1n1n1nPOI = dynamic_cast<TProfile*>(fListHistos->FindObject("f4PerEtaBin1n1n1n1nPOI")); 
395     
396   //average values of Q-vector components (1st bin: <Q_x>, 2nd bin: <Q_y>, 3rd bin: <(Q_x)^2>, 4th bin: <(Q_y)^2>) 
397   TProfile *QVectorComponents = dynamic_cast<TProfile*>(fListHistos->FindObject("fQvectorComponents"));
398   
399   //multi-particle correlations calculated with nested loop 
400   TProfile *DirectCorrelations = dynamic_cast<TProfile*>(fListHistos->FindObject("fDirectCorrelations"));
401  
402   //----------------------------------------------------
403  
404   fQCA = new AliFlowAnalysisWithQCumulants();  
405  
406   fQCA->SetIntFlowResults(intFlowResults); 
407   fQCA->SetDiffFlowResults2nd(diffFlowResults2ndOrder);
408   fQCA->SetDiffFlowResults4th(diffFlowResults4thOrder); 
409   fQCA->SetCovariances(covariances); 
410   
411   fQCA->SetCommonHists2nd(commonHist2nd); 
412   fQCA->SetCommonHists4th(commonHist4th);
413   fQCA->SetCommonHists6th(commonHist6th);
414   fQCA->SetCommonHists8th(commonHist8th);
415
416   fQCA->SetCommonHistsResults2nd(commonHistRes2nd); 
417   fQCA->SetCommonHistsResults4th(commonHistRes4th);
418   fQCA->SetCommonHistsResults6th(commonHistRes6th);
419   fQCA->SetCommonHistsResults8th(commonHistRes8th);
420  
421   fQCA->SetAverageMultiplicity(AvMult);
422   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
423   //             !!!! to be removed !!!!
424   fQCA->SetQvectorForEachEventX(qvectorForEachEventX);
425   fQCA->SetQvectorForEachEventY(qvectorForEachEventY);
426   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
427   fQCA->SetQCorrelations(QCorrelations);
428   fQCA->SetQProduct(QProduct);
429   fQCA->SetQVectorComponents(QVectorComponents);
430  
431   fQCA->SetTwo1n1nPerPtBinRP(binnedPt2p1n1nRP);
432   fQCA->SetTwo2n2nPerPtBinRP(binnedPt2p2n2nRP);
433   fQCA->SetThree2n1n1nPerPtBinRP(binnedPt3p2n1n1nRP);
434   fQCA->SetThree1n1n2nPerPtBinRP(binnedPt3p1n1n2nRP);
435   fQCA->SetFour1n1n1n1nPerPtBinRP(binnedPt4p1n1n1n1nRP);
436   
437   fQCA->SetTwo1n1nPerEtaBinRP(binnedEta2p1n1nRP);
438   fQCA->SetTwo2n2nPerEtaBinRP(binnedEta2p2n2nRP);
439   fQCA->SetThree2n1n1nPerEtaBinRP(binnedEta3p2n1n1nRP);
440   fQCA->SetThree1n1n2nPerEtaBinRP(binnedEta3p1n1n2nRP);
441   fQCA->SetFour1n1n1n1nPerEtaBinRP(binnedEta4p1n1n1n1nRP); 
442   
443   fQCA->SetTwo1n1nPerPtBinPOI(binnedPt2p1n1nPOI);
444   fQCA->SetTwo2n2nPerPtBinPOI(binnedPt2p2n2nPOI);
445   fQCA->SetThree2n1n1nPerPtBinPOI(binnedPt3p2n1n1nPOI);
446   fQCA->SetThree1n1n2nPerPtBinPOI(binnedPt3p1n1n2nPOI);
447   fQCA->SetFour1n1n1n1nPerPtBinPOI(binnedPt4p1n1n1n1nPOI);
448   
449   fQCA->SetTwo1n1nPerEtaBinPOI(binnedEta2p1n1nPOI);
450   fQCA->SetTwo2n2nPerEtaBinPOI(binnedEta2p2n2nPOI);
451   fQCA->SetThree2n1n1nPerEtaBinPOI(binnedEta3p2n1n1nPOI);
452   fQCA->SetThree1n1n2nPerEtaBinPOI(binnedEta3p1n1n2nPOI);
453   fQCA->SetFour1n1n1n1nPerEtaBinPOI(binnedEta4p1n1n1n1nPOI);    
454  
455   fQCA->SetDirectCorrelations(DirectCorrelations);
456  
457   fQCA->Finish();
458   
459   //----------------------------------------------------
460  }
461  else
462  {
463   cout<<"histogram list pointer is empty"<<endl;
464  }
465 }
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486