]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runAliAnalysisTaskCumulants.C
working cumulant task
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runAliAnalysisTaskCumulants.C
1 // from CreateESDChain.C - instead of  #include "CreateESDChain.C"
2 TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0) ;
3 void LookupWrite(TChain* chain, const char* target) ;
4
5 void runAliAnalysisTaskCumulants(Int_t nRuns = 100, TString type = "ESD", const Char_t* dataDir="/data/alice2/ab2/", Int_t offset = 0) 
6 //void runAliAnalysisTaskCumulants(Int_t nRuns = 2, TString type = "MC", const Char_t* dataDir="/Users/snelling/alice_data/TherminatorFix", Int_t offset = 0) 
7 {
8   TStopwatch timer;
9   timer.Start();
10
11   // include path (to find the .h files when compiling)
12   gSystem->AddIncludePath("-I$ALICE_ROOT/include") ;
13   gSystem->AddIncludePath("-I$ROOTSYS/include") ;
14
15   // load needed libraries
16   gSystem->Load("libTree.so");
17   gSystem->Load("libESD.so");
18   cerr<<"libESD loaded..."<<endl;
19   gSystem->Load("libANALYSIS.so");
20   cerr<<"libANALYSIS.so loaded..."<<endl;
21   gSystem->Load("libPWG2flow.so");
22   
23   //  gROOT->LoadMacro("AliFlowLYZConstants.cxx+");
24   //  gROOT->LoadMacro("AliFlowCommonConstants.cxx+");
25   //  gROOT->LoadMacro("AliFlowVector.cxx+");
26   //  gROOT->LoadMacro("AliFlowTrackSimple.cxx+");
27   //  gROOT->LoadMacro("AliFlowEventSimple.cxx+");
28   //  gROOT->LoadMacro("AliFlowEventSimpleMaker.cxx+");
29   //  gROOT->LoadMacro("AliFlowCommonHist.cxx+");
30   //  gROOT->LoadMacro("AliFlowCommonHistResults.cxx+");
31   //  gROOT->LoadMacro("AliFlowLYZHist1.cxx+");
32   //  gROOT->LoadMacro("AliFlowLYZHist2.cxx+");
33   //  gROOT->LoadMacro("AliFlowAnalysisWithLeeYangZeros.cxx+"); 
34   //  gROOT->LoadMacro("AliAnalysisTaskLeeYangZeros.cxx+");
35
36   // create the TChain. CreateESDChain() is defined in CreateESDChain.C
37   TChain* chain = CreateESDChain(dataDir, nRuns, offset);
38   cout<<"chain ("<<chain<<")"<<endl;
39
40   //____________________________________________//
41   // Make the analysis manager
42   AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
43   AliVEventHandler* esdH = new AliESDInputHandler;
44   mgr->SetInputEventHandler(esdH);  
45   AliMCEventHandler *mc = new AliMCEventHandler();
46   mgr->SetMCtruthEventHandler(mc);
47   //____________________________________________//
48   // 1st Cumulant task
49   AliAnalysisTaskCumulants *task1 = new AliAnalysisTaskCumulants("TaskCumulants");
50   task1->SetAnalysisType(type);
51   mgr->AddTask(task1);
52
53   // Create containers for input/output
54   AliAnalysisDataContainer *cinput1 = 
55     mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
56   AliAnalysisDataContainer *coutput1 = 
57     mgr->CreateContainer("cobj1", TList::Class(),AliAnalysisManager::kOutputContainer);
58
59   //____________________________________________//
60   mgr->ConnectInput(task1,0,cinput1);
61   mgr->ConnectOutput(task1,0,coutput1);
62
63   if (!mgr->InitAnalysis()) return;
64   mgr->PrintStatus();
65   mgr->StartAnalysis("local",chain);
66
67   timer.Stop();
68   timer.Print();
69 }
70
71
72 // Helper macros for creating chains
73 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
74
75 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
76 {
77   // creates chain of files in a given directory or file containing a list.
78   // In case of directory the structure is expected as:
79   // <aDataDir>/<dir0>/AliESDs.root
80   // <aDataDir>/<dir1>/AliESDs.root
81   // ...
82   
83   if (!aDataDir)
84     return 0;
85   
86   Long_t id, size, flags, modtime;
87   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
88     {
89       printf("%s not found.\n", aDataDir);
90       return 0;
91     }
92   
93   TChain* chain = new TChain("esdTree");
94   TChain* chaingAlice = 0;
95   
96   if (flags & 2)
97     {
98       TString execDir(gSystem->pwd());
99       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
100       TList* dirList            = baseDir->GetListOfFiles();
101       Int_t nDirs               = dirList->GetEntries();
102       gSystem->cd(execDir);
103       
104       Int_t count = 0;
105       
106       for (Int_t iDir=0; iDir<nDirs; ++iDir)
107         {
108           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
109           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
110             continue;
111           
112           if (offset > 0)
113             {
114               --offset;
115               continue;
116             }
117           
118           if (count++ == aRuns)
119             break;
120           
121           TString presentDirName(aDataDir);
122           presentDirName += "/";
123           presentDirName += presentDir->GetName();        
124           chain->Add(presentDirName + "/AliESDs.root/esdTree");
125           cerr<<presentDirName<<endl;
126         }
127       
128     }
129   else
130     {
131       // Open the input stream
132       ifstream in;
133       in.open(aDataDir);
134       
135       Int_t count = 0;
136       
137       // Read the input list of files and add them to the chain
138       TString esdfile;
139       while(in.good()) {
140         in >> esdfile;
141         if (!esdfile.Contains("root")) continue; // protection
142         
143         if (offset > 0)
144           {
145             --offset;
146             continue;
147           }
148         
149         if (count++ == aRuns)
150           break;
151         
152         // add esd file
153         chain->Add(esdfile);
154       }
155       
156       in.close();
157     }
158   
159   return chain;
160 }
161
162 void LookupWrite(TChain* chain, const char* target)
163 {
164   // looks up the chain and writes the remaining files to the text file target
165   
166   chain->Lookup();
167   
168   TObjArray* list = chain->GetListOfFiles();
169   TIterator* iter = list->MakeIterator();
170   TObject* obj = 0;
171   
172   ofstream outfile;
173   outfile.open(target);
174   
175   while ((obj = iter->Next()))
176     outfile << obj->GetTitle() << "#AliESDs.root" << endl;
177   
178   outfile.close();
179   
180   delete iter;
181 }