2 const char *dataset = "";
5 Int_t iAODTagCreation = 1;
6 Int_t iAODAddMCBranch = 1;
8 void AnalysisTrainFromESDToAOD(const char *analysisMode = "GRID", Bool_t usePLUGIN = kFALSE, Int_t nev=12345678)
10 //========================================================================
11 // The macro produces a standard AOD starting from ESD files.
12 // (Simplified version of ANALYSIS/macros/AnalysisTrainNew.C)
14 // Two wagons are attached to the train:
15 // AddTaskESDFilter.C and AddTaskTagCreation.C
17 // If the iESDfilter flag is activated, in AddTaskESDFilter.C
18 // two tasks are executed :
19 // 1- with the first one (AliAnalysisTaskESDfilter),
20 // all the branches of the AOD are filled apart from the muons
21 // 2- with the second task (AliAnalysisTaskESDMuonFilter)
22 // muons tracks are added to the tracks branch
24 // In AddTaskESDFilter.C there is the possibility to apply cuts
25 // on the tracks and muon tracks in order to reject them before
28 // - if the flag iAODAddMCBranch is activated the MC branch
29 // (containing Kinematics info) is added to the AOD
31 // - if the iAODTagCreation flag is activated, in AddTaskTagCreation.C the
32 // AliAnalysisTaskTagCreator task is executed in order to create aod tags.
35 // Options tested: (case sensitive)
36 // GRID (with/without AliEn plugin)
37 // LOCAL (you have to specify in TChain *CreateChain(...)
38 // the directory where your data are)
39 //========================================================================
42 // Global configuration flags
43 //=====================================================================
45 Bool_t readTR = kFALSE;
46 Bool_t useKFILTER = kFALSE; // add MC Branch
47 if(iAODAddMCBranch) useKFILTER=kTRUE;
48 if(strcmp(analysisMode,"LOCAL")==0) usePLUGIN = kFALSE;
50 // Load common libraries (STEERBase, ESD, AOD, ANALYSIS. ANALYSISalice)
51 //=====================================================================
52 LoadCommonLibraries(analysisMode);
53 gROOT->ProcessLine(".include $ALICE_ROOT/include");
55 // Load analysis specific libraries
56 //=====================================================================
58 if(!strcmp(analysisMode, "LOCAL")){
59 gSystem->Load("libPWG3base.so");
60 gSystem->Load("libPWG3muon.so");
62 else if(!strcmp(analysisMode, "GRID"))LoadAnalysisLibraries(analysisMode);
65 // If Plugin is used, load macro with JDL parameters
66 //=====================================================================
68 gROOT->LoadMacro("CreateAlienHandler_FromESDToAOD.C");
69 AliAnalysisGrid *alienHandler = CreateAlienHandler_FromESDToAOD();
70 if (!alienHandler) return;
73 // Create the chain. This is dependent on the analysis mode.
74 //=====================================================================
76 if (!strcmp(analysisMode, "GRID")) TGrid::Connect("alien://");
77 TChain* chain = CreateChain(analysisMode,"");
80 // Create the train and set-up the handlers
81 //=====================================================================
82 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "Analysis Train for standard AOD production");
85 if(usePLUGIN) mgr->SetGridHandler(alienHandler);
88 AliESDInputHandler *esdHandler = new AliESDInputHandler();
89 mgr->SetInputEventHandler(esdHandler);
91 // Monte Carlo handler
92 if (iAODAddMCBranch) {
93 AliMCEventHandler* mcHandler = new AliMCEventHandler();
94 mgr->SetMCtruthEventHandler(mcHandler);
95 mcHandler->SetReadTR(readTR);
99 AliAODHandler* aodHandler = new AliAODHandler();
100 mgr->SetOutputEventHandler(aodHandler);
101 aodHandler->SetOutputFileName("AliAODs.root");
103 // Debugging if requested
104 if (debug) mgr->SetDebugLevel(3);
106 // Load the tasks configuration macros for all included wagons
107 //=====================================================================
109 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
110 AliAnalysisTaskESDfilter *esdfilter = AddTaskESDFilter(useKFILTER);
112 if (iAODTagCreation) {
113 // use this line if AddTaskTagCreation.C is available in the grid aliroot version
114 if(!strcmp(analysisMode, "LOCAL")){
115 gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskTagCreation.C");
117 // uncomment this line if AddTaskTagCreation.C is available in the grid aliroot version
118 // gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskTagCreation.C");
119 // otherwise temporary: (and AddTaskTagCreation.C must be also added in the jdl)
120 gROOT->LoadMacro("AddTaskTagCreation.C");
122 AliAnalysisTaskTagCreator *tagcreator = AddTaskTagCreation();
127 //=====================================================================
128 if (mgr->InitAnalysis()) {
130 if(usePLUGIN) mgr->StartAnalysis("GRID");
131 else mgr->StartAnalysis("local", chain,nev);
135 //______________________________________________________________________________
136 Bool_t LoadCommonLibraries(const char *mode)
138 // Load common analysis libraries.
140 if (!strcmp(mode, "LOCAL")) imode = 0;
141 if (!strcmp(mode, "PROOF")) imode = 1;
142 if (!strcmp(mode, "GRID")) imode = 2;
143 if (!gSystem->Getenv("ALICE_ROOT")) {
144 ::Error("LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
147 Bool_t success = kTRUE;
149 gSystem->Load("libTree.so");
150 gSystem->Load("libGeom.so");
151 gSystem->Load("libVMC.so");
152 gSystem->Load("libPhysics.so");
154 // Load framework classes. Par option ignored here.
158 success &= LoadLibrary("libSTEERBase.so", mode);
159 success &= LoadLibrary("libESD.so", mode);
160 success &= LoadLibrary("libAOD.so", mode);
161 success &= LoadLibrary("libANALYSIS.so", mode);
162 success &= LoadLibrary("libANALYSISalice.so", mode);
163 success &= LoadLibrary("libCORRFW.so", mode);
164 gROOT->ProcessLine(".include $ALICE_ROOT/include");
168 if (!gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion);
170 success &= LoadLibrary("STEERBase", mode);
171 success &= LoadLibrary("ESD", mode);
172 success &= LoadLibrary("AOD", mode);
173 success &= LoadLibrary("ANALYSIS", mode);
174 success &= LoadLibrary("ANALYSISalice", mode);
175 success &= LoadLibrary("CORRFW", mode);
177 ires = gProof->EnablePackage(AFversion);
178 if (ires<0) success = kFALSE;
182 ::Error("LoadCommonLibraries", "Unknown run mode: %s", mode);
186 ::Info("LoadCommodLibraries", "Load common libraries: SUCCESS");
187 ::Info("LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
188 gSystem->GetIncludePath());
190 ::Info("LoadCommodLibraries", "Load common libraries: FAILED");
196 //______________________________________________________________________________
197 TChain *CreateChain(const char *mode, const char *plugin_mode)
199 // Create the input chain
201 if (!strcmp(mode, "LOCAL")) imode = 0;
202 if (!strcmp(mode, "PROOF")) imode = 1;
203 if (!strcmp(mode, "GRID")) imode = 2;
204 TChain *chain = NULL;
208 if (!strlen(dataset)) {
210 chain = new TChain("esdTree");
211 if (gSystem->AccessPathName("/n60raid3/alice/roberta/MCBranch/AliESDs.root"))
212 ::Error("CreateChain", "File: AliESDs.root not in ./data dir");
213 else chain->Add("/n60raid3/alice/roberta/MCBranch/AliESDs.root");
216 chain = CreateChainSingle(dataset, "esdTree");
222 TString treeName = "esdTree";
223 chain = CreateChainSingle("wn.xml", treeName);
227 if (chain && chain->GetNtrees()) return chain;
231 //______________________________________________________________________________
232 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
234 // Load a module library in a given mode. Reports success.
237 TString smodule(module);
238 if (!strcmp(mode, "LOCAL")) imode = 0;
239 if (!strcmp(mode, "PROOF")) imode = 1;
240 if (!strcmp(mode, "GRID")) imode = 2;
243 ::Error("LoadLibrary", "Empty module name");
246 // If a library is specified, just load it
247 if (smodule.EndsWith(".so")) {
248 mod.Remove(mod.Index(".so"));
249 result = gSystem->Load(mod);
251 ::Error("LoadLibrary", "Could not load library %s", module);
254 if (rec) anaLibs += Form("%s.so ",mod.Data());
257 // Check if the library is already loaded
258 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
263 result = gSystem->Load(Form("lib%s.so", module));
264 if (rec) anaLibs += Form("lib%s.so ", module);
267 result = gProof->UploadPackage(module);
269 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
271 ::Error("LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
275 result = gProof->EnablePackage(module);
281 ::Error("LoadLibrary", "Could not load module %s", module);
287 //______________________________________________________________________________
288 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
290 printf("*******************************\n");
291 printf("*** Getting the ESD Chain ***\n");
292 printf("*******************************\n");
293 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
296 ::Error("CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
300 TChain* chain = new TChain(treeName);
301 myCollection->Reset() ;
302 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
307 //______________________________________________________________________________
308 Bool_t LoadAnalysisLibraries(const char *mode)
310 // Load common analysis libraries.
311 Bool_t success = kTRUE;
312 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
313 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
314 ::Info("LoadAnalysisLibraries", "Load other libraries: SUCCESS");