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