Fix Coverity leaks
[u/mrichter/AliRoot.git] / PWG2 / runAODAnalysisExample.C
1 void produceAOD()
2 {
3     gSystem->Load("libTree.so");
4     gSystem->Load("libGeom.so");
5     gSystem->Load("libVMC.so");
6     gSystem->Load("libXMLIO.so");
7     SetupPar("STEERBase");
8 //    gSystem->Load("STEERBase/libSTEERBase.so");
9     SetupPar("ESD");
10 //    gSystem->Load("ESD/libESD.so");
11     SetupPar("AOD");
12 //    gSystem->Load("AOD/libAOD.so");
13     SetupPar("ANALYSIS");
14 //    gSystem->Load("ANALYSIS/libANALYSIS.so");
15     SetupPar("PWG0base");
16     // Make the analysis manager
17     //
18     // Chain from CAF
19     gROOT->LoadMacro("CreateESDChain.C");
20 //     TChain* chain = CreateESDChain("ESD1503X_v1.txt", 10);
21     TChain* chain = CreateESDChain("/mnt/data/alice/pbpb_therminator/central.2/", 885);
22
23     AliAODHandler* aodHandler   = new AliAODHandler();
24     aodHandler->SetOutputFileName("aod.root");
25     AliESDInputHandler *esdHandler = new AliESDInputHandler();
26     esdHandler->SetInactiveBranches("FMD CaloCluster");
27     
28     AliMCEventHandler* mcHandler = new AliMCEventHandler();
29
30     AliAnalysisManager *mgr  = new AliAnalysisManager("esd to aod to histos", "testing aod analysis");
31     mgr->SetInputEventHandler(esdHandler);
32     mgr->SetOutputEventHandler(aodHandler);
33     mgr->SetMCtruthEventHandler(mcHandler);
34     mgr->SetDebugLevel(10);
35     AliLog::EnableDebug(kTRUE);
36     AliLog::SetGlobalLogLevel(2);
37
38
39     // Set of cuts
40     // 
41     // standard
42     AliESDtrackCuts* esdTrackCutsL = new AliESDtrackCuts("AliESDtrackCuts", "Loose");
43     esdTrackCutsL->SetMinNClustersTPC(50);
44     esdTrackCutsL->SetMaxChi2PerClusterTPC(3.5);
45     esdTrackCutsL->SetMaxCovDiagonalElements(2,2,0.5,0.5,2);
46     esdTrackCutsL->SetRequireTPCRefit(kTRUE);
47     esdTrackCutsL->SetMinNsigmaToVertex(3);
48     esdTrackCutsL->SetRequireSigmaToVertex(kTRUE);
49     esdTrackCutsL->SetAcceptKingDaughters(kFALSE);
50     //
51     // hard
52     AliESDtrackCuts* esdTrackCutsH = new AliESDtrackCuts("AliESDtrackCuts", "Hard");
53     esdTrackCutsH->SetMinNClustersTPC(100);
54     esdTrackCutsH->SetMaxChi2PerClusterTPC(2.0);
55     esdTrackCutsH->SetMaxCovDiagonalElements(2,2,0.5,0.5,2);
56     esdTrackCutsH->SetRequireTPCRefit(kTRUE);
57     esdTrackCutsH->SetMinNsigmaToVertex(2);
58     esdTrackCutsH->SetRequireSigmaToVertex(kTRUE);
59     esdTrackCutsH->SetAcceptKingDaughters(kFALSE);
60     //
61     AliAnalysisFilter* trackFilter = new AliAnalysisFilter("trackFilter");
62     trackFilter->AddCuts(esdTrackCutsL);
63     trackFilter->AddCuts(esdTrackCutsH);
64     //
65     AliAnalysisTaskESDfilter *esdfilter = new AliAnalysisTaskESDfilter("ESD Filter");
66     esdfilter->SetTrackFilter(trackFilter);
67     esdfilter->SetDebugLevel(10);
68     mgr->AddTask(esdfilter);
69
70     // Create containers for input/output
71     // Top ESD container
72     AliAnalysisDataContainer *cin_esd = mgr->GetCommonInputContainer();
73
74     // Output AOD container
75     AliAnalysisDataContainer *cout_aod = mgr->GetCommonOutputContainer();
76
77     mgr->ConnectInput  (esdfilter,  0, cin_esd  );
78     mgr->ConnectOutput (esdfilter,  0, cout_aod );
79    //
80     // Run the analysis
81     //    
82     mgr->InitAnalysis();
83     mgr->PrintStatus();
84     mgr->StartAnalysis("local",chain);
85     delete mgr;
86 }
87
88 void runPWG2()
89 {
90     gSystem->Load("libTree.so");
91     gSystem->Load("libGeom.so");
92     gSystem->Load("libVMC.so");
93     gSystem->Load("libXMLIO.so");
94     SetupPar("STEERBase");
95 //    gSystem->Load("STEERBase/libSTEERBase.so");
96     SetupPar("ESD");
97 //    gSystem->Load("ESD/libESD.so");
98     SetupPar("AOD");
99 //    gSystem->Load("AOD/libAOD.so");
100     SetupPar("ANALYSIS");
101 //    gSystem->Load("ANALYSIS/libANALYSIS.so");
102     SetupPar("PWG0base");
103 //    gSystem->Load("PWG0base/libPWG0base.so");
104 //    SetupPar("TASKFILTER");
105 //    gSystem->Load("TASKFILTER/libTASKFILTER.so");
106 //    gSystem->Load("JETAN/libJETAN.so");
107   SetupPar("PWG2spectra");
108   gROOT->ProcessLine(".L $ALICE_ROOT/PWG2/AliAnalysisTaskProtons.cxx++g");
109    //
110 //    if (gApplication) gApplication->InitializeGraphics();
111     // Create the chain
112     //
113     // Chain from aod.root
114      TChain* chain = new TChain("aodTree");
115      chain->Add("aod.root");
116  //   TChain* chain = CreateESDChain("ESD12001.txt", 2);  
117     // Chain from local files
118 //    gROOT->LoadMacro("CreateLocalChain.C");
119 //    TChain* chain = CreateLocalChain();  
120     // Chain from ALIEN files
121 //    TGrid::Connect("alien://"); 
122 //    gROOT->LoadMacro("CreateChain.C");
123 //    TChain* chain = CreateChain("global.xml");  
124
125     //
126     // Make the analysis manager
127     //
128     AliAODInputHandler *aodHandler = new AliAODInputHandler();
129
130     AliAnalysisManager *mgr  = new AliAnalysisManager("esd to aod to histos", "testing aod analysis");
131     mgr->SetInputEventHandler(aodHandler);
132     mgr->SetDebugLevel(10);
133     AliLog::EnableDebug(kTRUE);
134     AliLog::SetGlobalLogLevel(2);
135
136
137    //
138   //____________________________________________//
139   // 1st Proton task
140   AliAnalysisTaskProtons *taskproton = new AliAnalysisTaskProtons("TaskProtons");
141   taskproton->SetType("AOD");
142   TFile *f = TFile::Open("$ALICE_ROOT/PWG2/data/PriorProbabilities.root ");
143   TF1 *fitElectrons = (TF1 *)f->Get("fitElectrons");
144   TF1 *fitMuons = (TF1 *)f->Get("fitMuons");
145   TF1 *fitPions = (TF1 *)f->Get("fitPions");
146   TF1 *fitKaons = (TF1 *)f->Get("fitKaons");
147   TF1 *fitProtons = (TF1 *)f->Get("fitProtons");
148   taskproton->SetPriorProbabilityFunctions(fitElectrons,
149                                       fitMuons,
150                                       fitPions,
151                                       fitKaons,
152                                       fitProtons);
153   mgr->AddTask(taskproton);
154     // Create containers for input/output
155     // Top AOD container
156     AliAnalysisDataContainer *cin_aod = mgr->GetCommonInputContainer();
157
158     // Output histogram container
159     AliAnalysisDataContainer *cout_hist = mgr->CreateContainer("protonhistos", TList::Class(),AliAnalysisManager::kOutputContainer,"protonhistos.root");
160
161     mgr->ConnectInput(taskproton,0,cin_aod);
162     mgr->ConnectOutput(taskproton,0,cout_hist);
163    //
164     // Run the analysis
165     //    
166     mgr->InitAnalysis();
167     mgr->PrintStatus();
168     mgr->StartAnalysis("local",chain);
169 }
170
171 void SetupPar(char* pararchivename)
172 {
173     if (pararchivename) {
174         char processline[1024];
175         sprintf(processline,".! tar xvzf %s.par",pararchivename);
176         gROOT->ProcessLine(processline);
177         TString ocwd = gSystem->WorkingDirectory();
178         gSystem->ChangeDirectory(pararchivename);
179         
180         // check for BUILD.sh and execute
181         if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
182             printf("*******************************\n");
183             printf("*** Building PAR archive    ***\n");
184             printf("*******************************\n");
185             
186             if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
187                 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
188                 return -1;
189             }
190         }
191         // check for SETUP.C and execute
192         if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
193             printf("*******************************\n");
194             printf("*** Setup PAR archive       ***\n");
195             printf("*******************************\n");
196             gROOT->Macro("PROOF-INF/SETUP.C");
197         }
198         
199         gSystem->ChangeDirectory(ocwd.Data());
200    printf("Current dir: %s\n", ocwd.Data());
201     } 
202 }