Adding an AnalysisTask for the femto analysis
[u/mrichter/AliRoot.git] / PWG2 / runProtonAnalysis.C
1 void runProtonAnalysis() {
2   TStopwatch timer;
3   timer.Start();
4   
5   //runLocal();
6   //runInteractive();
7   //runBatch();
8   runProof();
9
10   timer.Stop();
11   timer.Print();
12 }
13
14 //_________________________________________________//
15 void runLocal() {
16   TStopwatch timer;
17   timer.Start();
18   gSystem->Load("libTree.so");
19   //____________________________________________________//
20   //_____________Setting up STEERBase.par_______________//
21   //____________________________________________________//
22   setupPar("STEERBase");
23   gSystem->Load("libSTEERBase.so");
24
25   //____________________________________________________//
26   //_____________Setting up ESD.par_____________________//
27   //____________________________________________________//
28   setupPar("ESD");
29   gSystem->Load("libVMC.so");
30   gSystem->Load("libESD.so");
31   
32   //____________________________________________________//
33   //_____________Setting up AOD.par_____________________//
34   //____________________________________________________//
35   setupPar("AOD");
36   gSystem->Load("libAOD.so");
37                                                                 
38   //_________________________________________________________//
39   //_____________Setting up ANALYSIS.par_____________________//
40   //_________________________________________________________//
41   setupPar("ANALYSIS");
42   gSystem->Load("libANALYSIS.so");
43
44   //____________________________________________________________//
45   //_____________Setting up PWG2spectra.par_____________________//
46   //____________________________________________________________//
47   setupPar("PWG2spectra");
48   gSystem->Load("libPWG2spectra.so");
49   
50   gROOT->LoadMacro("AliAnalysisTaskProtons.cxx++");
51
52   //____________________________________________//
53   AliTagAnalysis *TagAna = new AliTagAnalysis("ESD"); 
54   TagAna->ChainLocalTags("/home/pchrist/ALICE/Alien/Tutorial/November2007/Tags");
55
56   AliRunTagCuts *runCuts = new AliRunTagCuts();
57   AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
58   AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
59   AliEventTagCuts *evCuts = new AliEventTagCuts();
60   
61   TChain* chain = 0x0;
62   chain = TagAna->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
63   chain->SetBranchStatus("*Calo*",0);
64
65   //____________________________________________//
66   // Make the analysis manager
67   AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
68   AliVEventHandler* esdH = new AliESDInputHandler;
69   mgr->SetInputEventHandler(esdH);  
70   //____________________________________________//
71   // 1st Proton task
72   AliAnalysisTaskProtons *task1 = new AliAnalysisTaskProtons("TaskProtons");
73   TFile *f = TFile::Open("PriorProb/PriorProbabilities.root ");
74   TF1 *fitElectrons = (TF1 *)f->Get("fitElectrons");
75   TF1 *fitMuons = (TF1 *)f->Get("fitMuons");
76   TF1 *fitPions = (TF1 *)f->Get("fitPions");
77   TF1 *fitKaons = (TF1 *)f->Get("fitKaons");
78   TF1 *fitProtons = (TF1 *)f->Get("fitProtons");
79   task1->SetPriorProbabilityFunctions(fitElectrons,
80                                       fitMuons,
81                                       fitPions,
82                                       fitKaons,
83                                       fitProtons);
84   mgr->AddTask(task1);
85
86   // Create containers for input/output
87   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
88   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("clist1", TList::Class(),AliAnalysisManager::kOutputContainer,"Protons.ESD.root");
89   
90   //____________________________________________//
91   mgr->ConnectInput(task1,0,cinput1);
92   mgr->ConnectOutput(task1,0,coutput1);
93   if (!mgr->InitAnalysis()) return;
94   mgr->PrintStatus();
95   mgr->StartAnalysis("local",chain);
96
97   timer.Stop();
98   timer.Print();
99 }
100
101 //_________________________________________________//
102 void runInteractive() {
103   TStopwatch timer;
104   timer.Start();
105   gSystem->Load("libProofPlayer.so");
106
107   printf("*** Connect to AliEn ***\n");
108   TGrid::Connect("alien://");
109  
110   //____________________________________________________//
111   //_____________Setting up STEERBase.par_______________//
112   //____________________________________________________//
113   setupPar("STEERBase");
114   gSystem->Load("libSTEERBase.so");
115
116   //____________________________________________________//
117   //_____________Setting up ESD.par_____________________//
118   //____________________________________________________//
119   setupPar("ESD");
120   gSystem->Load("libVMC.so");
121   gSystem->Load("libESD.so");
122
123   //____________________________________________________//
124   //_____________Setting up AOD.par_____________________//
125   //____________________________________________________//
126   setupPar("AOD");
127   gSystem->Load("libAOD.so");
128
129   //_________________________________________________________//
130   //_____________Setting up ANALYSIS.par_____________________//
131   //_________________________________________________________//
132   setupPar("ANALYSIS");
133   gSystem->Load("libANALYSIS.so");
134
135   //____________________________________________________________//
136   //_____________Setting up PWG2spectra.par_____________________//
137   //____________________________________________________________//
138   setupPar("PWG2spectra");
139   gSystem->Load("libPWG2spectra.so");
140   
141   gROOT->LoadMacro("AliAnalysisTaskProtons.cxx++");
142   
143   //____________________________________________//
144   AliTagAnalysis *TagAna = new AliTagAnalysis("ESD");
145  
146   AliRunTagCuts *runCuts = new AliRunTagCuts();
147   AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
148   AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
149   AliEventTagCuts *evCuts = new AliEventTagCuts();
150  
151   //grid tags
152   TAlienCollection* coll = TAlienCollection::Open("tag.xml");
153   TGridResult* TagResult = coll->GetGridResult("",0,0);
154   TagAna->ChainGridTags(TagResult);
155   TChain* chain = 0x0;
156   chain = TagAna->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
157   chain->SetBranchStatus("*Calo*",0);
158
159   //____________________________________________//
160   // Make the analysis manager
161   AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
162   AliVEventHandler* esdH = new AliESDInputHandler;
163   mgr->SetInputEventHandler(esdH);  
164   //____________________________________________//
165   // 1st Proton task
166   AliAnalysisTaskProtons *task1 = new AliAnalysisTaskProtons("TaskProtons");
167   TFile *f = TFile::Open("PriorProb/PriorProbabilities.root ");
168   TF1 *fitElectrons = (TF1 *)f->Get("fitElectrons");
169   TF1 *fitMuons = (TF1 *)f->Get("fitMuons");
170   TF1 *fitPions = (TF1 *)f->Get("fitPions");
171   TF1 *fitKaons = (TF1 *)f->Get("fitKaons");
172   TF1 *fitProtons = (TF1 *)f->Get("fitProtons");
173   task1->SetPriorProbabilityFunctions(fitElectrons,
174                                       fitMuons,
175                                       fitPions,
176                                       fitKaons,
177                                       fitProtons);
178   mgr->AddTask(task1);
179
180   // Create containers for input/output
181   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
182   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("clist1", TList::Class(),AliAnalysisManager::kOutputContainer,"Protons.ESD.root");
183   
184   //____________________________________________//
185   mgr->ConnectInput(task1,0,cinput1);
186   mgr->ConnectOutput(task1,0,coutput1);
187   if (!mgr->InitAnalysis()) return;
188   mgr->PrintStatus();
189   mgr->StartAnalysis("local",chain);
190
191   timer.Stop();
192   timer.Print();
193 }
194
195 //_________________________________________________//
196 void runBatch() {
197   TStopwatch timer;
198   timer.Start();
199
200   printf("*** Connect to AliEn ***\n");
201   TGrid::Connect("alien://");
202   gSystem->Load("libProofPlayer.so");
203
204   //____________________________________________________//
205   //_____________Setting up STEERBase.par_______________//
206   //____________________________________________________//
207   setupPar("STEERBase");
208   gSystem->Load("libSTEERBase.so");
209
210   //____________________________________________________//
211   //_____________Setting up ESD.par_____________________//
212   //____________________________________________________//
213   setupPar("ESD");
214   gSystem->Load("libVMC.so");
215   gSystem->Load("libESD.so");
216
217   //____________________________________________________//
218   //_____________Setting up AOD.par_____________________//
219   //____________________________________________________//
220   setupPar("AOD");
221   gSystem->Load("libAOD.so");
222
223   //_________________________________________________________//
224   //_____________Setting up ANALYSIS.par_____________________//
225   //_________________________________________________________//
226   setupPar("ANALYSIS");
227   gSystem->Load("libANALYSIS.so");
228
229   //____________________________________________________________//
230   //_____________Setting up PWG2spectra.par_____________________//
231   //____________________________________________________________//
232   setupPar("PWG2spectra");
233   gSystem->Load("libPWG2spectra.so");
234
235   //ANALYSIS PART
236   gROOT->LoadMacro("AliAnalysisTaskProtons.cxx++");
237   const char *collectionfile = "wn.xml";
238
239   //____________________________________________//
240   //Usage of event tags
241   AliTagAnalysis *analysis = new AliTagAnalysis();
242   TChain *chain = 0x0;
243   chain = analysis->GetChainFromCollection(collectionfile,"esdTree");
244   chain->SetBranchStatus("*Calo*",0);
245
246   //____________________________________________//
247   // Make the analysis manager
248   AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
249   AliVEventHandler* esdH = new AliESDInputHandler;
250   mgr->SetInputEventHandler(esdH);  
251   //____________________________________________//
252   // 1st Proton task
253   AliAnalysisTaskProtons *task1 = new AliAnalysisTaskProtons("TaskProtons");
254   TFile *f = TFile::Open("PriorProb/PriorProbabilities.root ");
255   TF1 *fitElectrons = (TF1 *)f->Get("fitElectrons");
256   TF1 *fitMuons = (TF1 *)f->Get("fitMuons");
257   TF1 *fitPions = (TF1 *)f->Get("fitPions");
258   TF1 *fitKaons = (TF1 *)f->Get("fitKaons");
259   TF1 *fitProtons = (TF1 *)f->Get("fitProtons");
260   task1->SetPriorProbabilityFunctions(fitElectrons,
261                                       fitMuons,
262                                       fitPions,
263                                       fitKaons,
264                                       fitProtons);
265   mgr->AddTask(task1);
266
267   // Create containers for input/output
268   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
269   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("clist1", TList::Class(),AliAnalysisManager::kOutputContainer,"Protons.ESD.root");
270   
271   //____________________________________________//
272   mgr->ConnectInput(task1,0,cinput1);
273   mgr->ConnectOutput(task1,0,coutput1);
274   if (!mgr->InitAnalysis()) return;
275   mgr->PrintStatus();
276   mgr->StartAnalysis("grid",chain);
277
278   timer.Stop();
279   timer.Print();
280 }
281
282 //_________________________________________________//
283 void runProof() {
284   TStopwatch timer;
285   timer.Start();
286   printf("****** Connect to PROOF *******\n");
287   TProof::Open("proof://lxb6046.cern.ch"); 
288   gProof->SetParallel();
289
290   // Enable the Analysis Package
291   gProof->UploadPackage("STEERBase.par");
292   gProof->EnablePackage("STEERBase");
293   gProof->UploadPackage("ESD.par");
294   gProof->EnablePackage("ESD");
295   gProof->UploadPackage("AOD.par");
296   gProof->EnablePackage("AOD");
297   gProof->UploadPackage("ANALYSIS.par");
298   gProof->EnablePackage("ANALYSIS");
299   gProof->UploadPackage("PWG2spectra.par");
300   gProof->EnablePackage("PWG2spectra");
301   
302   // You should get this macro and the txt file from:
303   // http://aliceinfo.cern.ch/Offline/Analysis/CAF/
304   gROOT->LoadMacro("CreateESDChain.C");
305   TChain* chain = 0x0;
306   chain = CreateESDChain("ESD82XX_30K.txt",10);
307   chain->SetBranchStatus("*Calo*",0);
308
309   gProof->Load("AliAnalysisTaskProtons.cxx++");
310
311     //____________________________________________//
312   // Make the analysis manager
313   AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
314   AliVEventHandler* esdH = new AliESDInputHandler;
315   mgr->SetInputEventHandler(esdH);  
316   //____________________________________________//
317   // 1st Proton task
318   AliAnalysisTaskProtons *task1 = new AliAnalysisTaskProtons("TaskProtons");
319   TFile *f = TFile::Open("PriorProb/PriorProbabilities.root ");
320   TF1 *fitElectrons = (TF1 *)f->Get("fitElectrons");
321   TF1 *fitMuons = (TF1 *)f->Get("fitMuons");
322   TF1 *fitPions = (TF1 *)f->Get("fitPions");
323   TF1 *fitKaons = (TF1 *)f->Get("fitKaons");
324   TF1 *fitProtons = (TF1 *)f->Get("fitProtons");
325   task1->SetPriorProbabilityFunctions(fitElectrons,
326                                       fitMuons,
327                                       fitPions,
328                                       fitKaons,
329                                       fitProtons);
330   mgr->AddTask(task1);
331
332   // Create containers for input/output
333   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
334   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("clist1", TList::Class(),AliAnalysisManager::kOutputContainer,"Protons.ESD.root");
335   
336   //____________________________________________//
337   mgr->ConnectInput(task1,0,cinput1);
338   mgr->ConnectOutput(task1,0,coutput1);
339   if (!mgr->InitAnalysis()) return;
340   mgr->PrintStatus();
341   mgr->StartAnalysis("proof",chain);
342
343   timer.Stop();
344   timer.Print();
345 }
346
347 //_________________________________________________//
348 Int_t setupPar(const char* pararchivename) {
349   ///////////////////
350   // Setup PAR File//
351   ///////////////////
352   if (pararchivename) {
353     char processline[1024];
354     sprintf(processline,".! tar xvzf %s.par",pararchivename);
355     gROOT->ProcessLine(processline);
356     const char* ocwd = gSystem->WorkingDirectory();
357     gSystem->ChangeDirectory(pararchivename);
358     
359     // check for BUILD.sh and execute
360     if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
361       printf("*******************************\n");
362       printf("*** Building PAR archive    ***\n");
363       printf("*******************************\n");
364       
365       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
366         Error("runAnalysis","Cannot Build the PAR Archive! - Abort!");
367         return -1;
368       }
369     }
370     // check for SETUP.C and execute
371     if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
372       printf("*******************************\n");
373       printf("*** Setup PAR archive       ***\n");
374       printf("*******************************\n");
375       gROOT->Macro("PROOF-INF/SETUP.C");
376     }
377     
378     gSystem->ChangeDirectory("../");
379   } 
380   return 1;
381 }