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