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