2 * Flags for the analysis
4 * @ingroup pwg2_forward_analysis_scripts
7 kMC = 0x01, // MC input
8 kProof = 0x02, // Run in proof mode
9 kFull = 0x04, // Do full analysis - including terminate
10 kAnalyse = 0x08, // Run the analysis
11 kTerminate = 0x10 // Run only terminate
15 * Run first pass of the analysis - that is read in ESD and produce AOD
17 * @param esddir ESD input directory. Any file matching the pattern
18 * *AliESDs*.root are added to the chain
19 * @param nEvents Number of events to process. If 0 or less, then
20 * all events are analysed
21 * @param flags Job flags. A bit mask of
22 * - 0x01 (MC) Monte-Carlo truth handler installed
23 * - 0x02 (PROOF) Proof mode
24 * - 0x04 (FULL) Run full analysis - including terminate
25 * - 0x08 (ANALYSE) Run only analysis - not terminate
26 * - 0x10 (TERMINATE) Run no analysis - just terminate.
28 * of these, PROOF, FULL, ANALYSE, and TERMINATE are mutually exclusive.
30 * If PROOF mode is selected, then Terminate will be run on the master node
33 * If FULL is selected, then the full analysis is done. Note that
34 * this can be combined with PROOF but with no effect.
36 * ANALYSE cannot be combined with FULL, PROOF, or TERMINATE. In a
37 * local job, the output AnalysisResults.root will still be made, but
38 * terminate is not called.
40 * In TERMINATE, the file AnalysisResults.root is opened and all
41 * containers found are connected to the tasks. The terminate member
42 * function is then called
45 * @ingroup pwg2_forward_analysis_scripts
47 void RunManager(const char* esddir,
51 // --- Libraries to load -------------------------------------------
52 gSystem->Load("libVMC");
53 gSystem->Load("libTree");
55 gSystem->Load("libSTEERBase");
57 gSystem->Load("libESD") ;
58 gSystem->Load("libAOD") ;
59 gSystem->Load("libANALYSIS");
60 gSystem->Load("libANALYSISalice");
62 gSystem->Load("libPhysics");
63 gSystem->Load("libPWG0base");
64 gSystem->Load("libPWG0dep");
65 gSystem->Load("libPWG2forward");
66 gSystem->Load("libPWG2forward2");
68 // --- Check for proof mode, and possibly upload pars --------------
70 TProof::Open("workers=2");
71 const char* pkgs[] = { "STEERBase", "ESD", "AOD", "ANALYSIS",
72 "ANALYSISalice", "PWG2forward", "PWG2forward2", 0};
73 const char** pkg = pkgs;
75 gProof->UploadPackage(Form("${ALICE_ROOT}/%s.par",*pkg));
76 gProof->EnablePackage(*pkg);
81 // --- Our data chain ----------------------------------------------
82 TChain* chain = new TChain("esdTree");
84 // --- Get list of ESDs --------------------------------------------
85 // Open source directory, and make sure we go back to were we were
86 TString oldDir(gSystem->WorkingDirectory());
87 TSystemDirectory d(esddir, esddir);
88 TList* files = d.GetListOfFiles();
89 gSystem->ChangeDirectory(oldDir);
91 // Sort list of files and check if we should add it
94 TSystemFile* file = 0;
95 while ((file = static_cast<TSystemFile*>(next()))) {
96 if (file->IsDirectory()) continue;
97 TString name(file->GetName());
98 if (!name.EndsWith(".root")) continue;
99 if (!name.Contains("AliESDs")) continue;
100 TString esd(Form("%s/%s", file->GetTitle(), name.Data()));
101 Info("RunManager", "Adding %s to chain", esd.Data());
104 // If 0 or less events is select, choose all
105 if (nEvents <= 0) nEvents = chain->GetEntries();
108 // --- Creating the manager and handlers ---------------------------
109 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train",
110 "FMD analysis train");
112 AliESDInputHandler *esdHandler = new AliESDInputHandler();
113 esdHandler->SetInactiveBranches("AliESDACORDE "
114 "AliRawDataErrorLogs "
125 mgr->SetInputEventHandler(esdHandler);
127 // Monte Carlo handler
129 AliMCEventHandler* mcHandler = new AliMCEventHandler();
130 mgr->SetMCtruthEventHandler(mcHandler);
131 mcHandler->SetReadTR(readTR);
134 // AOD output handler
135 AliAODHandler* aodHandler = new AliAODHandler();
136 mgr->SetOutputEventHandler(aodHandler);
137 aodHandler->SetOutputFileName("AliAODs.root");
139 // --- Add tasks ---------------------------------------------------
140 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/AddTaskFMD.C");
141 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
142 AliAnalysisTask* task = AddTaskFMD();
143 mgr->ConnectOutput(task, 0, mgr->GetCommonOutputContainer());
145 task = AddTaskPhysicsSelection((flags & kMC), kTRUE, kTRUE);
146 mgr->ConnectOutput(task, 0, mgr->GetCommonOutputContainer());
148 // --- Run the analysis --------------------------------------------
150 if (!mgr->InitAnalysis()) {
151 Error("RunManager", "Failed to initialize analysis train!");
154 // Skip terminate if we're so requested and not in Proof or full mode
155 mgr->SetSkipTerminate(!(flags & kProof) &&
158 // Some informative output
160 // mgr->SetDebugLevel(3);
161 if (mgr->GetDebugLevel() < 1 && !(flags & kProof))
162 mgr->SetUseProgressBar(kTRUE);
166 if (!(flags & kTerminate))
167 mgr->StartAnalysis((flags & kProof) ? "proof" : "local", chain, nEvents);
169 mgr->ImportWrappers();