]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/makeTaskNMLYZ.C
Macros for Lee Yang Zeroes from Naomi van der Kolk
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / makeTaskNMLYZ.C
1 /////////////////////////////////////////////////////////////
2 //
3 // $Id$
4 //
5 // Author: N. van der Kolk
6 //
7 /////////////////////////////////////////////////////////////
8 //
9 // Description: ROOT macro to perform Flow analysis on AliFlowEvents with the Lee Yang Zeros method
10 //
11 /////////////////////////////////////////////////////////////
12
13 // from CreateESDChain.C - instead of  #include "CreateESDChain.C"
14 TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0) ;
15 void LookupWrite(TChain* chain, const char* target) ;
16
17
18 #include <vector>
19 #include <iostream>
20 #include <fstream>
21 #include "TObjArray.h"
22
23 //class AliFlowTrack;
24 //class AliFlowEvent;
25 //class AliFlowSelection;
26 //class AliFlowConstants;
27
28 using namespace std; //required for resolving the 'cout' symbol
29
30
31 void makeTaskNMLYZ(const Char_t* dataDir="/data/alice1/simili/lcgHijing/4", Int_t nRuns =-1, Int_t offset = 0)
32 {
33   cout<<"---New Method for Lee Yang Zeros Flow Analysis with Task Framework---"<<endl;
34
35
36   // include path (to find the .h files when compiling)
37   gSystem->AddIncludePath("-I$ALICE_ROOT/include") ;
38   gSystem->AddIncludePath("-I$ROOTSYS/include") ;
39   gSystem->AddIncludePath("-I$ALICE_ROOT/PWG2/FLOW") ;
40
41   // load needed libraries
42   gSystem->Load("libESD");
43   cerr<<"libESD loaded..."<<endl;
44   gSystem->Load("libANALYSIS.so");
45   cerr<<"libANALYSIS.so loaded..."<<endl;
46   gSystem->Load("libANALYSISRL.so");
47   cerr<<"libANALYSISRL.so loaded..."<<endl;
48
49   // Flow libraries 
50   gSystem->Load("libPWG2flow.so");
51   cerr<<"libPWG2flow.so loaded..."<<endl;
52   gROOT->LoadMacro("AliFlowLYZConstants.cxx+");
53   cerr<<"."<<endl;
54   gROOT->LoadMacro("AliAnalysisTaskRLLYZNewMethod.cxx+");
55   cerr<<"....."<<endl;
56
57   cout<<"---loaded libraries!---"<<endl;
58
59   // create the TChain. CreateESDChain() is defined in CreateESDChain.C
60   TChain* chain = CreateESDChain(dataDir, nRuns, offset);
61   cout<<"chain ("<<chain<<")"<<endl;
62   //cout << " * " << chain->GetEntriesFast() << "*" << endl;
63   //cout << " * " << chain->GetEntries() << " * " << endl ;
64
65   // input files (read) 
66   
67   TString firstRunFileName = "testTaskLYZ_firstrun.root" ;
68   TString secondRunFileName = "testTaskLYZ_secondrun.root" ;
69   TFile* fFirstRunFile = new TFile(firstRunFileName.Data(),"READ");
70   if(!fFirstRunFile || fFirstRunFile->IsZombie()) { cerr << " ERROR: NO first Run file... " << endl ; }
71   TFile* fSecondRunFile = new TFile(secondRunFileName.Data(),"READ");
72   if(!fSecondRunFile || fSecondRunFile->IsZombie()) { cerr << " ERROR: NO first Run file... " << endl ; }
73
74
75   //____________________________________________//
76   // Make the analysis manager
77   AliAnalysisManager *mgr = new AliAnalysisManager("TestLYZNMManager");
78   cout<<"---defined the manager---"<<endl;
79   //____________________________________________//
80   // 1st LYZ task
81   AliAnalysisTaskRLLYZNewMethod *task1 = new AliAnalysisTaskRLLYZNewMethod("LYZtest");
82   
83   //add tasks to manager
84   mgr->AddTask(task1);
85   cout<<"---task1 added---"<<endl;
86   
87   // Create containers for input/output
88   AliAnalysisDataContainer *cinput1 = 
89     mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
90   cout<<"---created input container---"<<endl;
91   
92   AliAnalysisDataContainer *cinput2 = 
93     mgr->CreateContainer("cobj2",TList::Class(),AliAnalysisManager::kInputContainer);
94   cout<<"---created input container2---"<<endl; 
95   
96   AliAnalysisDataContainer *cinput3 = 
97     mgr->CreateContainer("cobj3",TList::Class(),AliAnalysisManager::kInputContainer);
98   cout<<"---created input container3---"<<endl; 
99   
100   AliAnalysisDataContainer *coutput1 = 
101     mgr->CreateContainer("cobj1", TList::Class());
102
103   
104   //____________________________________________//
105   mgr->ConnectInput(task1,0,cinput1);
106   cout<<"---ConnectInput(task1,0,cinput1)---"<<endl;
107   mgr->ConnectInput(task1,1,cinput2);
108   cout<<"---ConnectInput(task1,1,cinput2)---"<<endl; 
109   mgr->ConnectInput(task1,2,cinput3);
110   cout<<"---ConnectInput(task1,1,cinput3)---"<<endl; 
111   mgr->ConnectOutput(task1,0,coutput1);
112   cout<<"---ConnectOutput(task1,0,coutput1)---"<<endl;
113   
114   cerr<<"chain ("<<chain<<")"<<endl;
115   cinput1->SetData(chain);
116   cinput2->SetData(fFirstRunFile);
117   cinput3->SetData(fSecondRunFile);
118
119   if(mgr->InitAnalysis()) {
120     mgr->PrintStatus();
121     mgr->StartAnalysis("local",chain);
122   } 
123 }
124
125
126 // Helper macros for creating chains
127 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
128
129 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
130 {
131   // creates chain of files in a given directory or file containing a list.
132   // In case of directory the structure is expected as:
133   // <aDataDir>/<dir0>/AliESDs.root
134   // <aDataDir>/<dir1>/AliESDs.root
135   // ...
136   
137   if (!aDataDir)
138     return 0;
139   
140   Long_t id, size, flags, modtime;
141   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
142     {
143       printf("%s not found.\n", aDataDir);
144       return 0;
145     }
146   
147   TChain* chain = new TChain("esdTree");
148   TChain* chaingAlice = 0;
149   
150   if (flags & 2)
151     {
152       TString execDir(gSystem->pwd());
153       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
154       TList* dirList            = baseDir->GetListOfFiles();
155       Int_t nDirs               = dirList->GetEntries();
156       gSystem->cd(execDir);
157       
158       Int_t count = 0;
159       
160       for (Int_t iDir=0; iDir<nDirs; ++iDir)
161         {
162           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
163           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
164             continue;
165           
166           if (offset > 0)
167             {
168               --offset;
169               continue;
170             }
171           
172           if (count++ == aRuns)
173             break;
174           
175           TString presentDirName(aDataDir);
176           presentDirName += "/";
177           presentDirName += presentDir->GetName();        
178           chain->Add(presentDirName + "/AliESDs.root/esdTree");
179           cerr<<presentDirName<<endl;
180         }
181       
182     }
183   else
184     {
185       // Open the input stream
186       ifstream in;
187       in.open(aDataDir);
188       
189       Int_t count = 0;
190       
191       // Read the input list of files and add them to the chain
192       TString esdfile;
193       while(in.good()) {
194         in >> esdfile;
195         if (!esdfile.Contains("root")) continue; // protection
196         
197         if (offset > 0)
198           {
199             --offset;
200             continue;
201           }
202         
203         if (count++ == aRuns)
204           break;
205         
206         // add esd file
207         chain->Add(esdfile);
208       }
209       
210       in.close();
211     }
212   
213   return chain;
214 }
215
216 void LookupWrite(TChain* chain, const char* target)
217 {
218   // looks up the chain and writes the remaining files to the text file target
219   
220   chain->Lookup();
221   
222   TObjArray* list = chain->GetListOfFiles();
223   TIterator* iter = list->MakeIterator();
224   TObject* obj = 0;
225   
226   ofstream outfile;
227   outfile.open(target);
228   
229   while ((obj = iter->Next()))
230     outfile << obj->GetTitle() << "#AliESDs.root" << endl;
231   
232   outfile.close();
233   
234   delete iter;
235 }
236