]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/SPECTRA/macros/runProtonsFeedDownAnalysis.C
4ec4b0bd9ab094f2146a7183cccd4602e1360e27
[u/mrichter/AliRoot.git] / PWG2 / SPECTRA / macros / runProtonsFeedDownAnalysis.C
1 void runProtonsFeedDownAnalysis(const char* esdAnalysisType = "Hybrid",
2                                 const char* pidMode = "Bayesian") {
3   //Macro to run the proton feed-down 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","TPC","Bayesian","/home/mbroz/FeedDownAnalysis/");
26   //runInteractive("ESD","TPC","Bayesian","pp0901.xml");
27   runBatch("ESD","TPC","Bayesian","wn.xml");  
28   // runProof("ESD","TPC","Bayesian",200000,"/COMMON/COMMON/LHC09a4_run8101X");
29   
30   timer.Stop();
31   timer.Print();
32 }
33
34 //_________________________________________________//
35 void runLocal(const char* mode = "ESD",
36               const char* analysisType = 0x0,
37               const char* pidMode = 0x0,
38               const char* path = 0x0) {
39   TString smode = mode;
40   TString outputFilename = "Protons.FeedDown."; outputFilename += mode;
41   if(analysisType) {
42     outputFilename += "."; outputFilename += analysisType;
43   }
44   outputFilename += ".root";
45
46   //____________________________________________________//
47   //_____________Setting up the par files_______________//
48   //____________________________________________________//
49   setupPar("STEERBase");
50   gSystem->Load("libSTEERBase.so");
51   setupPar("ESD");
52   gSystem->Load("libVMC.so");
53   gSystem->Load("libESD.so");
54   setupPar("AOD");
55   gSystem->Load("libAOD.so");
56   setupPar("ANALYSIS");
57   gSystem->Load("libANALYSIS.so");
58   setupPar("ANALYSISalice");
59   gSystem->Load("libANALYSISalice.so");
60   setupPar("CORRFW");
61   gSystem->Load("libCORRFW.so");
62   setupPar("PWG2spectra");
63   gSystem->Load("libPWG2spectra.so");
64   //____________________________________________________//  
65   
66   //____________________________________________//
67   AliTagAnalysis *tagAnalysis = new AliTagAnalysis("ESD"); 
68   tagAnalysis->ChainLocalTags(path);
69
70   AliRunTagCuts *runCuts = new AliRunTagCuts();
71   AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
72   AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
73   AliEventTagCuts *evCuts = new AliEventTagCuts();
74   
75   TChain* chain = 0x0;
76   chain = tagAnalysis->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
77   //chain->SetBranchStatus("*Calo*",0);
78
79   //____________________________________________//
80   gROOT->LoadMacro("configProtonFeedDownAnalysis.C");
81   AliProtonFeedDownAnalysis *analysis = GetProtonFeedDownAnalysisObject(mode,
82                                                                         analysisType,
83                                                                         pidMode);
84   //____________________________________________//
85   // Make the analysis manager
86   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManagerFD");
87   AliVEventHandler* esdH = new AliESDInputHandler;
88   mgr->SetInputEventHandler(esdH);
89   AliMCEventHandler *mc = new AliMCEventHandler();
90   mgr->SetMCtruthEventHandler(mc);
91
92   //____________________________________________//
93   AliProtonFeedDownAnalysisTask *taskProtons = new AliProtonFeedDownAnalysisTask("TaskProtonsFD");
94   taskProtons->SetAnalysisObject(analysis);
95   mgr->AddTask(taskProtons);
96
97   // Create containers for input/output
98   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("dataChain",
99                                                            TChain::Class(),
100                                                            AliAnalysisManager::kInputContainer);
101   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
102                                                             TList::Class(),
103                                                             AliAnalysisManager::kOutputContainer,
104                                                             outputFilename.Data());
105
106   //____________________________________________//
107   mgr->ConnectInput(taskProtons,0,mgr->GetCommonInputContainer());
108   mgr->ConnectOutput(taskProtons,0,coutput1);
109   if (!mgr->InitAnalysis()) return;
110   mgr->PrintStatus();
111   mgr->StartAnalysis("local",chain);
112 }
113
114 //_________________________________________________//
115 void runInteractive(const char* mode = "ESD",
116                     const char* analysisType = 0x0,
117                     const char* pidMode = 0x0,
118                     const char* collectionName = "tag.xml") {
119   gSystem->Load("libProofPlayer.so");
120
121   TString smode = mode;
122   TString outputFilename = "Protons.FeedDown."; outputFilename += mode;
123   if(analysisType) {
124     outputFilename += "."; outputFilename += analysisType;
125   }
126   outputFilename += ".root";
127
128   printf("*** Connect to AliEn ***\n");
129   TGrid::Connect("alien://");
130  
131   //____________________________________________________//
132   //_____________Setting up the par files_______________//
133   //____________________________________________________//
134   setupPar("STEERBase");
135   gSystem->Load("libSTEERBase.so");
136   setupPar("ESD");
137   gSystem->Load("libVMC.so");
138   gSystem->Load("libESD.so");
139   setupPar("AOD");
140   gSystem->Load("libAOD.so");
141   setupPar("ANALYSIS");
142   gSystem->Load("libANALYSIS.so");
143   setupPar("ANALYSISalice");
144   gSystem->Load("libANALYSISalice.so");
145   setupPar("CORRFW");
146   gSystem->Load("libCORRFW.so");
147   setupPar("PWG2spectra");
148   gSystem->Load("libPWG2spectra.so");
149   //____________________________________________________//  
150  
151   //____________________________________________//
152   AliTagAnalysis *tagAnalysis = new AliTagAnalysis("ESD");
153  
154   AliRunTagCuts *runCuts = new AliRunTagCuts();
155   AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
156   AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
157   AliEventTagCuts *evCuts = new AliEventTagCuts();
158  
159   //grid tags
160   TAlienCollection* coll = TAlienCollection::Open(collectionName);
161   TGridResult* TagResult = coll->GetGridResult("",0,0);
162   tagAnalysis->ChainGridTags(TagResult);
163   TChain* chain = 0x0;
164   chain = tagAnalysis->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
165   //chain->SetBranchStatus("*Calo*",0);
166   
167   //____________________________________________//
168   gROOT->LoadMacro("configProtonFeedDownAnalysis.C");
169   AliProtonFeedDownAnalysis *analysis = GetProtonFeedDownAnalysisObject(mode,
170                                                                         analysisType,
171                                                                         pidMode);
172   //____________________________________________//
173   // Make the analysis manager
174   // Make the analysis manager
175   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManagerFD");
176   AliVEventHandler* esdH = new AliESDInputHandler;
177   mgr->SetInputEventHandler(esdH);
178   AliMCEventHandler *mc = new AliMCEventHandler();
179   mgr->SetMCtruthEventHandler(mc);
180
181   //____________________________________________//
182   AliProtonFeedDownAnalysisTask *taskProtons = new AliProtonFeedDownAnalysisTask("TaskProtonsFD");
183   taskProtons->SetAnalysisObject(analysis);
184   mgr->AddTask(taskProtons);
185
186   // Create containers for input/output
187   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("dataChain",
188                                                            TChain::Class(),
189                                                            AliAnalysisManager::kInputContainer);
190   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
191                                                             TList::Class(),
192                                                             AliAnalysisManager::kOutputContainer,
193                                                             outputFilename.Data());
194   
195   //____________________________________________//
196   mgr->ConnectInput(taskProtons,0,mgr->GetCommonInputContainer());
197   mgr->ConnectOutput(taskProtons,0,coutput1);
198   if (!mgr->InitAnalysis()) return;
199   mgr->PrintStatus();
200   mgr->StartAnalysis("local",chain);
201 }
202
203 //_________________________________________________//
204 void runBatch(const char* mode = "ESD",
205               const char* analysisType = 0x0,
206               const char* pidMode = 0x0,
207               const char *collectionfile = "wn.xml") {
208   TString smode = mode;
209   TString outputFilename = "Protons.FeedDown."; outputFilename += mode;
210   if(analysisType) {
211     outputFilename += "."; outputFilename += analysisType;
212   }
213   outputFilename += ".root";
214
215   printf("*** Connect to AliEn ***\n");
216   TGrid::Connect("alien://");
217   gSystem->Load("libProofPlayer.so");
218
219   //____________________________________________________//
220   //_____________Setting up the par files_______________//
221   //____________________________________________________//
222   gSystem->Load("libSTEERBase.so");
223   gSystem->Load("libESD.so");
224   gSystem->Load("libAOD.so");
225   gSystem->Load("libANALYSIS") ;
226   gSystem->Load("libANALYSISalice") ;
227   gSystem->Load("libCORRFW.so") ;
228
229   setupPar("PWG2spectra");
230   gSystem->Load("libPWG2spectra.so");
231   //____________________________________________________//  
232
233   //____________________________________________//
234   AliTagAnalysis *tagAnalysis = new AliTagAnalysis("ESD");
235   TChain *chain = 0x0;
236   chain = tagAnalysis->GetChainFromCollection(collectionfile,"esdTree");
237
238   //____________________________________________//
239   gROOT->LoadMacro("configProtonFeedDownAnalysis.C");
240   AliProtonFeedDownAnalysis *analysis = GetProtonFeedDownAnalysisObject(mode,
241                                                                         analysisType,
242                                                                         pidMode);
243   //____________________________________________//
244   // Make the analysis manager
245   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManagerFD");
246   AliVEventHandler* esdH = new AliESDInputHandler;
247   mgr->SetInputEventHandler(esdH);
248   AliMCEventHandler *mc = new AliMCEventHandler();
249   mgr->SetMCtruthEventHandler(mc);
250
251   //____________________________________________//
252   AliProtonFeedDownAnalysisTask *taskProtons = new AliProtonFeedDownAnalysisTask("TaskProtonsFD");
253   taskProtons->SetAnalysisObject(analysis);
254   mgr->AddTask(taskProtons);
255
256   // Create containers for input/output
257   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("dataChain",
258                                                            TChain::Class(),
259                                                            AliAnalysisManager::kInputContainer);
260   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
261                                                             TList::Class(),
262                                                             AliAnalysisManager::kOutputContainer,
263                                                             outputFilename.Data());
264
265   //____________________________________________//
266   mgr->ConnectInput(taskProtons,0,mgr->GetCommonInputContainer());
267   mgr->ConnectOutput(taskProtons,0,coutput1);
268   if (!mgr->InitAnalysis()) return;
269   mgr->PrintStatus();
270   mgr->StartAnalysis("local",chain);
271 }
272
273 //_________________________________________________//
274 void runProof(const char* mode = "ESD",
275               const char* analysisType = 0x0,
276               const char* pidMode = 0x0,
277               Int_t stats = 0, 
278               const char* dataset = 0x0) {  
279   TString smode = mode;
280   TString outputFilename = "Protons.FeedDown."; outputFilename += mode;
281   if(analysisType) {
282     outputFilename += "."; outputFilename += analysisType;
283   }
284   outputFilename += ".root";
285
286   printf("****** Connect to PROOF *******\n");
287   TProof::Open("alicecaf.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("ANALYSISalice.par");
300   gProof->EnablePackage("ANALYSISalice");
301   gProof->UploadPackage("CORRFW.par");
302   gProof->EnablePackage("CORRFW");
303   gProof->UploadPackage("PWG2spectra.par");
304   gProof->EnablePackage("PWG2spectra");
305   
306   //____________________________________________//
307   gROOT->LoadMacro("configProtonFeedDownAnalysis.C");
308   AliProtonFeedDownAnalysis *analysis = GetProtonFeedDownAnalysisObject(mode,
309                                                                         analysisType,
310                                                                         pidMode);
311   //____________________________________________//
312
313   //____________________________________________//
314   // Make the analysis manager
315   AliAnalysisManager *mgr = new AliAnalysisManager("protonAnalysisManagerFD");
316   AliVEventHandler* esdH = new AliESDInputHandler;
317   mgr->SetInputEventHandler(esdH);
318   AliMCEventHandler *mc = new AliMCEventHandler();
319   mgr->SetMCtruthEventHandler(mc);
320   //____________________________________________//
321   //Create the proton task
322   AliProtonFeedDownAnalysisTask *taskProtons = new AliProtonFeedDownAnalysisTask("TaskProtonsFD");
323   taskProtons->SetAnalysisObject(analysis);
324   mgr->AddTask(taskProtons);
325
326   // Create containers for input/output
327   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("dataChain",
328                                                            TChain::Class(),
329                                                            AliAnalysisManager::kInputContainer);
330   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("outputList",
331                                                             TList::Class(),
332                                                             AliAnalysisManager::kOutputContainer,
333                                                             outputFilename.Data());
334
335   //____________________________________________//
336   mgr->ConnectInput(taskProtons,0,mgr->GetCommonInputContainer());
337   mgr->ConnectOutput(taskProtons,0,coutput1);
338   if (!mgr->InitAnalysis()) return;
339   mgr->PrintStatus();
340
341   if(dataset)
342     mgr->StartAnalysis("proof",dataset,stats);
343   else {
344     // You should get this macro and the txt file from:
345     // http://aliceinfo.cern.ch/Offline/Analysis/CAF/
346     gROOT->LoadMacro("CreateESDChain.C");
347     TChain* chain = 0x0;
348     chain = CreateESDChain("ESD82XX_30K.txt",stats);
349     chain->SetBranchStatus("*Calo*",0);
350
351     mgr->StartAnalysis("proof",chain);
352   }
353 }
354
355 //_________________________________________________//
356 Int_t setupPar(const char* pararchivename) {
357   ///////////////////
358   // Setup PAR File//
359   ///////////////////
360   if (pararchivename) {
361     char processline[1024];
362     sprintf(processline,".! tar xvzf %s.par",pararchivename);
363     gROOT->ProcessLine(processline);
364     const char* ocwd = gSystem->WorkingDirectory();
365     gSystem->ChangeDirectory(pararchivename);
366     
367     // check for BUILD.sh and execute
368     if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
369       printf("*******************************\n");
370       printf("*** Building PAR archive    ***\n");
371       printf("*******************************\n");
372       
373       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
374         Error("runAnalysis","Cannot Build the PAR Archive! - Abort!");
375         return -1;
376       }
377     }
378     // check for SETUP.C and execute
379     if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
380       printf("*******************************\n");
381       printf("*** Setup PAR archive       ***\n");
382       printf("*******************************\n");
383       gROOT->Macro("PROOF-INF/SETUP.C");
384     }
385     
386     gSystem->ChangeDirectory("../");
387   } 
388   return 1;
389 }