Single Muon Analysis from generic or muon-selected AOD's (Diego)
[u/mrichter/AliRoot.git] / PWG3 / muon / RunSingleMuonAnalysisFromAOD.C
CommitLineData
aad6618e 1//--------------------------------------------------------------------------
2// Base macro for submitting single muon analysis.
3//
4// In case it is not run with full aliroot, it needs to have in the working directory:
5// - STEERBase.par
662e37fe 6// - ESD.par
aad6618e 7// - AOD.par
8// - ANALYSIS.par
662e37fe 9// - ANALYSISalice.par
10// - PWG3muon.par
11//
12// The inputPath is either:
13// - The directory containing the AOD file in local mode
14// - The xml file with the list AODs in the alien catalogue in grid mode
15// - The proof dataset in proof mode
aad6618e 16//
17// The macro reads AODs and outputs file:
662e37fe 18// - outputDir/singleMuAnalysis.root
aad6618e 19//--------------------------------------------------------------------------
20
662e37fe 21enum analysisMode {kMlocal, kMgridInteractive, kMgridBatch, kMproof};
22TString modeName[4] = {"local", "local", "grid", "proof"};
23
24void RunSingleMuonAnalysisFromAOD(Int_t mode=kMlocal, Char_t *inputPath=".", Char_t *outputDir=".", Char_t *aodFilename = "AliAODs.root", Long64_t nRuns = -1, Long64_t offset = 0) {
aad6618e 25 TStopwatch timer;
26 timer.Start();
662e37fe 27
28 // Check if user is running root or aliroot
29 TString checkString = gSystem->Getenv("ALICE_ROOT");
30 checkString.Append("/lib/tgt_linux/libSTEERBase.so");
31 TString foundLib = gSystem->GetLibraries(checkString.Data());
32 Bool_t isFullAliroot = (foundLib.Length()==0) ? kFALSE : kTRUE;
33
34 // Load libraries
aad6618e 35 gSystem->Load("libTree");
36 gSystem->Load("libGeom");
37 gSystem->Load("libVMC");
aad6618e 38
662e37fe 39 if(mode==kMproof)
40 TProof::Open("alicecaf.cern.ch");
aad6618e 41
662e37fe 42 if(isFullAliroot){
43 gSystem->Load("libANALYSIS");
44 gSystem->Load("libANALYSISalice");
45 gSystem->Load("libSTEERBase");
46 gSystem->Load("libAOD");
47 gSystem->Load("libESD");
48 gSystem->Load("${ALICE_ROOT}/lib/tgt_${ALICE_TARGET}/libPWG3muon.so");
49 }
50 else {
51 const Int_t nNeededPar = 6;
52 TString parList[nNeededPar] = {"STEERBase", "ESD", "AOD", "ANALYSIS", "ANALYSISalice", "PWG3muon"};
53 if(mode==kMproof){
54 gProof->UploadPackage("AF-v4-15");
55 gProof->EnablePackage("AF-v4-15");
56 if(!SetupPar("PWG3muon")) return;
57 }
58 else {
59 for(Int_t ipar=0; ipar<nNeededPar; ipar++){
60 if(!SetupPar(parList[ipar].Data())) return;
61 }
62 }
63 }
aad6618e 64
662e37fe 65 // Connect to alien
66 //
67 if(mode==kMgridInteractive || mode==kMgridBatch)
68 TGrid::Connect("alien://");
aad6618e 69
aad6618e 70
662e37fe 71 TString outFileName("singleMuAnalysis.root");
72 outFileName.Prepend(Form("%s/",outputDir));
aad6618e 73
662e37fe 74 // Get the chain.
75 TChain* chain = 0x0;
76 if(mode!=kMproof) chain = CreateChain(mode, inputPath, aodFilename);
aad6618e 77
78 //____________________________________________//
79 // Make the analysis manager
80 AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
81 AliVEventHandler* aodH = new AliAODInputHandler;
82 mgr->SetInputEventHandler(aodH);
83 //____________________________________________//
662e37fe 84 // Single muon task
aad6618e 85 AliAnalysisTaskSingleMu *task1 = new AliAnalysisTaskSingleMu("SingleMu");
86 mgr->AddTask(task1);
87 // Create containers for input/output
88 AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",TChain::Class(),AliAnalysisManager::kInputContainer);
662e37fe 89 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("tree1", TTree::Class(),AliAnalysisManager::kOutputContainer,outFileName.Data());
aad6618e 90
91 //____________________________________________//
92 mgr->ConnectInput(task1,0,cinput1);
93 mgr->ConnectOutput(task1,0,coutput1);
94 if (!mgr->InitAnalysis()) return;
95 mgr->PrintStatus();
662e37fe 96
97 if(mode==kMproof)
98 mgr->StartAnalysis(modeName[mode].Data(), inputPath, nRuns, offset);
99 else
100 mgr->StartAnalysis(modeName[mode].Data(),chain);
aad6618e 101
102 timer.Stop();
103 timer.Print();
104}
662e37fe 105
106
107//______________________________________________________________________________
108Bool_t SetupPar(char* pararchivename)
109{
110 if (pararchivename) {
111 FileStat_t fs;
112 char pararchivenameFull[1024];
113 sprintf(pararchivenameFull, "%s.par", pararchivename);
114 if(gSystem->GetPathInfo(pararchivenameFull, fs)){
115 Error("SetupPar", "PAR Archive %s not found!\nPlease either copy it in the current directory\nor run full aliroot", pararchivenameFull);
116 return kFALSE;
117 }
118 char processline[1024];
119 sprintf(processline,".! tar xvzf %s.par",pararchivename);
120 gROOT->ProcessLine(processline);
121 const char* ocwd = gSystem->WorkingDirectory();
122 gSystem->ChangeDirectory(pararchivename);
123 printf("Current directory = %s\n",gSystem->pwd());
124
125 // check for BUILD.sh and execute
126 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
127 printf("*******************************\n");
128 printf("*** Building PAR archive ***\n");
129 printf("*******************************\n");
130
131 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
132 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
133 return kFALSE;
134 }
135 }
136 // check for SETUP.C and execute
137 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
138 printf("*******************************\n");
139 printf("*** Setup PAR archive ***\n");
140 printf("*******************************\n");
141 gROOT->Macro("PROOF-INF/SETUP.C");
142 }
143
144 gSystem->ChangeDirectory("../");
145 return kTRUE;
146 }
147 return kFALSE;
148}
149
150
151//______________________________________________________________________________
152TChain* CreateChain(Int_t mode, Char_t* inputPath, Char_t* aodFilename = "AliAOD.root")
153{
154 printf("*******************************\n");
155 printf("*** Getting the Chain ***\n");
156 printf("*******************************\n");
157 TChain *chain = 0x0;
158 if(mode==kMgridInteractive || mode==kMgridBatch){
159 AliTagAnalysis *analysis = new AliTagAnalysis();
160 chain = analysis->GetChainFromCollection(inputPath,"aodTree");
161 }
162 else{
163 chain = new TChain("aodTree");
164 TString inFileName(aodFilename);
165 inFileName.Prepend(Form("%s/",inputPath));
166 chain->Add(inFileName);
167 }
168 //if (chain) chain->ls();
169 return chain;
170}