]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/muon/RunSingleMuonAnalysisFromAOD.C
Transition PWG3 --> PWGHF
[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 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
35   gSystem->Load("libTree");
36   gSystem->Load("libGeom");
37   gSystem->Load("libVMC");
38
39   if(mode==kMproof)
40     TProof::Open("alicecaf.cern.ch");
41
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   }
64
65   // Connect to alien
66   //
67   if(mode==kMgridInteractive || mode==kMgridBatch)
68     TGrid::Connect("alien://"); 
69
70
71   TString outFileName("singleMuAnalysis.root");
72   outFileName.Prepend(Form("%s/",outputDir));  
73
74   // Get the chain.
75   TChain* chain = 0x0;
76   if(mode!=kMproof) chain = CreateChain(mode, inputPath, aodFilename);
77
78   //____________________________________________//
79   // Make the analysis manager
80   AliAnalysisManager *mgr = new AliAnalysisManager("TestManager");
81   AliVEventHandler* aodH = new AliAODInputHandler;
82   mgr->SetInputEventHandler(aodH);
83   //____________________________________________//
84   // Single muon task
85   AliAnalysisTaskSingleMu *task1 = new AliAnalysisTaskSingleMu("SingleMu");
86   mgr->AddTask(task1);
87   // Create containers for input/output
88   AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
89   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("tree1", TTree::Class(),AliAnalysisManager::kOutputContainer,outFileName.Data());
90   
91   //____________________________________________//
92   mgr->ConnectInput(task1,0,cinput1);
93   mgr->ConnectOutput(task1,0,coutput1);
94   if (!mgr->InitAnalysis()) return;
95   mgr->PrintStatus();
96
97   if(mode==kMproof)
98     mgr->StartAnalysis(modeName[mode].Data(), inputPath, nRuns, offset);
99   else 
100     mgr->StartAnalysis(modeName[mode].Data(),chain);
101
102   timer.Stop();
103   timer.Print();
104 }
105
106
107 //______________________________________________________________________________
108 Bool_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 //______________________________________________________________________________
152 TChain* 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 }