]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/SPECTRA/macros/runProtonAnalysis.C
Fixing the mgr->GetCommonInputContainer()
[u/mrichter/AliRoot.git] / PWG2 / SPECTRA / macros / runProtonAnalysis.C
1 void runProtonAnalysis(const char* esdAnalysisType = "Hybrid",
2                        const char* pidMode = "Bayesian") {
3   //Macro to run the proton analysis tested for local, proof & GRID.
4   //Local: Takes four arguments, the analysis mode, the type of the ESD 
5   //       analysis, the PID mode and the path where the tag and ESD or 
6   //       AOD files reside.
7   //Interactive: Takes four arguments, the analysis mode, the type of the ESD 
8   //             analysis, the PID mode and the name of the collection of tag 
9   //             files.
10   //Batch: Takes four arguments, the analysis mode, the type of the ESD 
11   //       analysis, the PID mode and the name of the collection file with 
12   //       the event list for each file.
13   //Proof: Takes five arguments, the analysis level, the analysis mode in 
14   //       case of ESD, the PID mode, the number of events and the dataset 
15   //       name and .  
16   //Analysis mode can be: "MC", "ESD", "AOD"
17   //ESD analysis type can be one of the three: "TPC", "Hybrid", "Global"
18   //PID mode can be one of the four: "Bayesian" (standard Bayesian approach) 
19   //   "Ratio" (ratio of measured over expected/theoretical dE/dx a la STAR) 
20   //   "Sigma1" (N-sigma area around the fitted dE/dx vs P band)
21   //   "Sigma2" (same as previous but taking into account the No of TPC points)
22   TStopwatch timer;
23   timer.Start();
24   
25   runLocal("ESD",
26            esdAnalysisType,
27            pidMode,
28            "/home/pchrist/ALICE/Baryons/Analysis/Protons/Local/data");
29   //runInteractive("ESD",esdAnalysisType,pidMode,"tag.xml");
30   //runBatch("ESD",esdAnalysisType,pidMode,"wn.xml");  
31   /*runProof("ESD",esdAnalysisType,pidMode,
32     500000,0,"/COMMON/COMMON/LHC09a4_run8100X#esdTree");*/
33   
34   timer.Stop();
35   timer.Print();
36 }
37
38 //_________________________________________________//
39 void runLocal(const char* mode = "ESD",
40               const char* analysisType = 0x0,
41               const char* pidMode = 0x0,
42               const char* path = "/home/pchrist/ALICE/Alien/Tutorial/November2007/Tags") {
43   TString smode = mode;
44   TString outputFilename = "Protons."; outputFilename += mode;
45   if(analysisType) {
46     outputFilename += "."; outputFilename += analysisType;
47   }
48   outputFilename += ".root";
49
50   //____________________________________________________//
51   //_____________Setting up the par files_______________//
52   //____________________________________________________//
53   setupPar("STEERBase");
54   gSystem->Load("libSTEERBase.so");
55   setupPar("ESD");
56   gSystem->Load("libVMC.so");
57   gSystem->Load("libESD.so");
58   setupPar("AOD");
59   gSystem->Load("libAOD.so");
60   setupPar("ANALYSIS");
61   gSystem->Load("libANALYSIS.so");
62   setupPar("ANALYSISalice");
63   gSystem->Load("libANALYSISalice.so");
64   setupPar("CORRFW");
65   gSystem->Load("libCORRFW.so");
66   setupPar("PWG2spectra");
67   gSystem->Load("libPWG2spectra.so");
68   //____________________________________________________//  
69
70   //____________________________________________//
71   AliTagAnalysis *tagAnalysis = new AliTagAnalysis("ESD"); 
72   tagAnalysis->ChainLocalTags(path);
73
74   AliRunTagCuts *runCuts = new AliRunTagCuts();
75   AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
76   AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
77   AliEventTagCuts *evCuts = new AliEventTagCuts();
78   
79   TChain* chain = 0x0;
80   chain = tagAnalysis->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
81   chain->SetBranchStatus("*Calo*",0);
82
83   //____________________________________________//
84   gROOT->LoadMacro("configProtonAnalysis.C");
85   AliProtonAnalysis *analysis = GetProtonAnalysisObject(mode,
86                                                         analysisType,
87                                                         pidMode);
88   //____________________________________________//
89   // Make the analysis manager
90   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManager");
91   AliVEventHandler* esdH = new AliESDInputHandler;
92   mgr->SetInputEventHandler(esdH);  
93   if(smode == "MC") {
94     AliMCEventHandler *mc = new AliMCEventHandler();
95     mgr->SetMCtruthEventHandler(mc);
96   }
97   
98   //____________________________________________//
99   //Create the proton task
100   AliAnalysisTaskProtons *taskProtons = new AliAnalysisTaskProtons("TaskProtons");
101   taskProtons->SetAnalysisObject(analysis);
102   mgr->AddTask(taskProtons);
103
104   // Create containers for input/output
105   AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
106   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
107                                                             TList::Class(),
108                                                             AliAnalysisManager::kOutputContainer,
109                                                             outputFilename.Data());
110
111   //____________________________________________//
112   mgr->ConnectInput(taskProtons,0,cinput1);
113   mgr->ConnectOutput(taskProtons,0,coutput1);
114   if (!mgr->InitAnalysis()) return;
115   mgr->PrintStatus();
116   mgr->StartAnalysis("local",chain);
117 }
118
119 //_________________________________________________//
120 void runInteractive(const char* mode = "ESD",
121                     const char* analysisType = 0x0,
122                     const char* pidMode = 0x0,
123                     const char* collectionName = "tag.xml") {
124   gSystem->Load("libProofPlayer.so");
125
126   TString smode = mode;
127   TString outputFilename = "Protons."; outputFilename += mode;
128   if(analysisType) {
129     outputFilename += "."; outputFilename += analysisType;
130   }
131   outputFilename += ".root";
132
133   printf("*** Connect to AliEn ***\n");
134   TGrid::Connect("alien://");
135  
136   //____________________________________________________//
137   //_____________Setting up the par files_______________//
138   //____________________________________________________//
139   setupPar("STEERBase");
140   gSystem->Load("libSTEERBase.so");
141   setupPar("ESD");
142   gSystem->Load("libVMC.so");
143   gSystem->Load("libESD.so");
144   setupPar("AOD");
145   gSystem->Load("libAOD.so");
146   setupPar("ANALYSIS");
147   gSystem->Load("libANALYSIS.so");
148   setupPar("ANALYSISalice");
149   gSystem->Load("libANALYSISalice.so");
150   setupPar("CORRFW");
151   gSystem->Load("libCORRFW.so");
152   setupPar("PWG2spectra");
153   gSystem->Load("libPWG2spectra.so");
154   //____________________________________________________//  
155   
156   //____________________________________________//
157   AliTagAnalysis *tagAnalysis = new AliTagAnalysis("ESD");
158  
159   AliRunTagCuts *runCuts = new AliRunTagCuts();
160   AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
161   AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
162   AliEventTagCuts *evCuts = new AliEventTagCuts();
163  
164   //grid tags
165   TAlienCollection* coll = TAlienCollection::Open(collectionName);
166   TGridResult* TagResult = coll->GetGridResult("",0,0);
167   tagAnalysis->ChainGridTags(TagResult);
168   TChain* chain = 0x0;
169   chain = tagAnalysis->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
170   chain->SetBranchStatus("*Calo*",0);
171   
172   //____________________________________________//
173   gROOT->LoadMacro("configProtonAnalysis.C");
174   AliProtonAnalysis *analysis = GetProtonAnalysisObject(mode,
175                                                         analysisType,
176                                                         pidMode);
177   //____________________________________________//
178   // Make the analysis manager
179   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManager");
180   AliVEventHandler* esdH = new AliESDInputHandler;
181   mgr->SetInputEventHandler(esdH);  
182   if(smode == "MC") {
183     AliMCEventHandler *mc = new AliMCEventHandler();
184     mgr->SetMCtruthEventHandler(mc);
185   }
186
187   //____________________________________________//
188   //Create the proton task
189   AliAnalysisTaskProtons *taskProtons = new AliAnalysisTaskProtons("TaskProtons");
190   taskProtons->SetAnalysisObject(analysis);
191   mgr->AddTask(taskProtons);
192
193   // Create containers for input/output
194   AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
195   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
196                                                             TList::Class(),
197                                                             AliAnalysisManager::kOutputContainer,
198                                                             outputFilename.Data());
199   
200   //____________________________________________//
201   mgr->ConnectInput(taskProtons,0,cinput1);
202   mgr->ConnectOutput(taskProtons,0,coutput1);
203   if (!mgr->InitAnalysis()) return;
204   mgr->PrintStatus();
205   mgr->StartAnalysis("local",chain);
206 }
207
208 //_________________________________________________//
209 void runBatch(const char* mode = "ESD",
210               const char* analysisType = 0x0,
211               const char* pidMode = 0x0,
212               const char *collectionfile = "wn.xml") {
213   TString smode = mode;
214   TString outputFilename = "Protons."; outputFilename += mode;
215   if(analysisType) {
216     outputFilename += "."; outputFilename += analysisType;
217   }
218   outputFilename += ".root";
219
220   printf("*** Connect to AliEn ***\n");
221   TGrid::Connect("alien://");
222   gSystem->Load("libProofPlayer.so");
223
224   //____________________________________________________//
225   //_____________Setting up the par files_______________//
226   //____________________________________________________//
227   setupPar("STEERBase");
228   gSystem->Load("libSTEERBase.so");
229   setupPar("ESD");
230   gSystem->Load("libVMC.so");
231   gSystem->Load("libESD.so");
232   setupPar("AOD");
233   gSystem->Load("libAOD.so");
234   setupPar("ANALYSIS");
235   gSystem->Load("libANALYSIS.so");
236   setupPar("ANALYSISalice");
237   gSystem->Load("libANALYSISalice.so");
238   setupPar("CORRFW");
239   gSystem->Load("libCORRFW.so");
240   setupPar("PWG2spectra");
241   gSystem->Load("libPWG2spectra.so");
242   //____________________________________________________//  
243
244   //____________________________________________//
245   //Usage of event tags
246   AliTagAnalysis *tagAnalysis = new AliTagAnalysis();
247   TChain *chain = 0x0;
248   chain = tagAnalysis->GetChainFromCollection(collectionfile,"esdTree");
249   chain->SetBranchStatus("*Calo*",0);
250
251   //____________________________________________//
252   gROOT->LoadMacro("configProtonAnalysis.C");
253   AliProtonAnalysis *analysis = GetProtonAnalysisObject(mode,
254                                                         analysisType,
255                                                         pidMode);
256   //____________________________________________//
257   // Make the analysis manager
258   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManager");
259   AliVEventHandler* esdH = new AliESDInputHandler;
260   mgr->SetInputEventHandler(esdH);  
261   if(smode == "MC") {
262     AliMCEventHandler *mc = new AliMCEventHandler();
263     mgr->SetMCtruthEventHandler(mc);
264   }
265   
266   //____________________________________________//
267   //Create the proton task
268   AliAnalysisTaskProtons *taskProtons = new AliAnalysisTaskProtons("TaskProtons");
269   taskProtons->SetAnalysisObject(analysis);
270   mgr->AddTask(taskProtons);
271
272   // Create containers for input/output
273   AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
274   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
275                                                             TList::Class(),
276                                                             AliAnalysisManager::kOutputContainer,
277                                                             outputFilename.Data());
278
279   //____________________________________________//
280   mgr->ConnectInput(taskProtons,0,cinput1);
281   mgr->ConnectOutput(taskProtons,0,coutput1);
282   if (!mgr->InitAnalysis()) return;
283   mgr->PrintStatus();
284   mgr->StartAnalysis("grid",chain);
285 }
286
287 //_________________________________________________//
288 void runProof(const char* mode = "ESD",
289               const char* analysisType = 0x0,
290               const char* pidMode = 0x0,
291               Int_t stats = 0, Int_t startingPoint = 0,
292               const char* dataset = 0x0) {  
293   TString smode = mode;
294   TString outputFilename = "Protons."; outputFilename += mode;
295   if(analysisType) {
296     outputFilename += "."; outputFilename += analysisType;
297   }
298   outputFilename += ".root";
299
300   gEnv->SetValue("XSec.GSI.DelegProxy","2");
301   printf("****** Connect to PROOF *******\n");
302   TProof::Open("alicecaf.cern.ch"); 
303   gProof->SetParallel();
304
305   // Enable the Analysis Package
306   gProof->UploadPackage("STEERBase.par");
307   gProof->EnablePackage("STEERBase");
308   gProof->UploadPackage("ESD.par");
309   gProof->EnablePackage("ESD");
310   gProof->UploadPackage("AOD.par");
311   gProof->EnablePackage("AOD");
312   gProof->UploadPackage("ANALYSIS.par");
313   gProof->EnablePackage("ANALYSIS");
314   gProof->UploadPackage("ANALYSISalice.par");
315   gProof->EnablePackage("ANALYSISalice");
316   gProof->UploadPackage("CORRFW.par");
317   gProof->EnablePackage("CORRFW");
318   gProof->UploadPackage("PWG2spectra.par");
319   gProof->EnablePackage("PWG2spectra");
320   
321   //____________________________________________//
322   gROOT->LoadMacro("configProtonAnalysis.C");
323   AliProtonAnalysis *analysis = GetProtonAnalysisObject(mode,
324                                                         analysisType,
325                                                         pidMode);
326   //____________________________________________//
327
328   //____________________________________________//
329   // Make the analysis manager
330   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManager");
331   AliVEventHandler* esdH = new AliESDInputHandler;
332   mgr->SetInputEventHandler(esdH);
333   if(smode == "MC") {
334     AliMCEventHandler *mc = new AliMCEventHandler();
335     mgr->SetMCtruthEventHandler(mc);
336   }
337   //____________________________________________//
338   //Create the proton task
339   AliAnalysisTaskProtons *taskProtons = new AliAnalysisTaskProtons("TaskProtons");
340   taskProtons->SetAnalysisObject(analysis);
341   mgr->AddTask(taskProtons);
342
343   // Create containers for input/output
344   AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
345   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
346                                                             TList::Class(),
347                                                             AliAnalysisManager::kOutputContainer,
348                                                             outputFilename.Data());
349
350   //____________________________________________//
351   mgr->ConnectInput(taskProtons,0,cinput1);
352   mgr->ConnectOutput(taskProtons,0,coutput1);
353   if (!mgr->InitAnalysis()) return;
354   mgr->PrintStatus();
355
356   if(dataset)
357     mgr->StartAnalysis("proof",dataset,stats,startingPoint);
358   else {
359     // You should get this macro and the txt file from:
360     // http://aliceinfo.cern.ch/Offline/Analysis/CAF/
361     gROOT->LoadMacro("CreateESDChain.C");
362     TChain* chain = 0x0;
363     chain = CreateESDChain("ESD82XX_30K.txt",stats);
364     chain->SetBranchStatus("*Calo*",0);
365
366     mgr->StartAnalysis("proof",chain);
367   }
368 }
369
370 //_________________________________________________//
371 Int_t setupPar(const char* pararchivename) {
372   ///////////////////
373   // Setup PAR File//
374   ///////////////////
375   if (pararchivename) {
376     char processline[1024];
377     sprintf(processline,".! tar xvzf %s.par",pararchivename);
378     gROOT->ProcessLine(processline);
379     const char* ocwd = gSystem->WorkingDirectory();
380     gSystem->ChangeDirectory(pararchivename);
381     
382     // check for BUILD.sh and execute
383     if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
384       printf("*******************************\n");
385       printf("*** Building PAR archive    ***\n");
386       printf("*******************************\n");
387       
388       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
389         Error("runAnalysis","Cannot Build the PAR Archive! - Abort!");
390         return -1;
391       }
392     }
393     // check for SETUP.C and execute
394     if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
395       printf("*******************************\n");
396       printf("*** Setup PAR archive       ***\n");
397       printf("*******************************\n");
398       gROOT->Macro("PROOF-INF/SETUP.C");
399     }
400     
401     gSystem->ChangeDirectory("../");
402   } 
403   return 1;
404 }