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