More code clean up.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / RunManager.C
CommitLineData
7e4038b5 1/**
c389303e 2 * Flags for the analysis
3 *
4 * @ingroup pwg2_forward_analysis_scripts
5 */
6enum {
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
12};
13
14/**
15 * Run first pass of the analysis - that is read in ESD and produce AOD
16 *
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.
27 *
28 * of these, PROOF, FULL, ANALYSE, and TERMINATE are mutually exclusive.
29 *
30 * If PROOF mode is selected, then Terminate will be run on the master node
31 * in any case.
32 *
33 * If FULL is selected, then the full analysis is done. Note that
34 * this can be combined with PROOF but with no effect.
35 *
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.
39 *
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
7e4038b5 43 *
7e4038b5 44 *
45 * @ingroup pwg2_forward_analysis_scripts
46 */
c389303e 47void RunManager(const char* esddir,
48 Int_t nEvents=1000,
49 UShort_t flags=kFull)
7e4038b5 50{
da60d315 51 // --- Libraries to load -------------------------------------------
0bd4b00f 52 gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadLibs.C");
2d68d438 53
da60d315 54 // --- Check for proof mode, and possibly upload pars --------------
0bd4b00f 55 if (flags & kProof)
56 gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadPars.C");
7e4038b5 57
da60d315 58 // --- Our data chain ----------------------------------------------
0bd4b00f 59 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/MakeESDChain.C");
60 TChain* chain = MakeESDChain(esddir);
c389303e 61 // If 0 or less events is select, choose all
62 if (nEvents <= 0) nEvents = chain->GetEntries();
da60d315 63
64 // --- Creating the manager and handlers ---------------------------
7e4038b5 65 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train",
66 "FMD analysis train");
fea27ee0 67
7e4038b5 68 AliESDInputHandler *esdHandler = new AliESDInputHandler();
69 esdHandler->SetInactiveBranches("AliESDACORDE "
70 "AliRawDataErrorLogs "
71 "CaloClusters "
72 "Cascades "
73 "EMCALCells "
74 "EMCALTrigger "
75 "Kinks "
76 "Cascades "
77 "MuonTracks "
78 "TrdTracks "
2d68d438 79 "CaloClusters "
80 "HLTGlobalTrigger");
7e4038b5 81 mgr->SetInputEventHandler(esdHandler);
82
7e4038b5 83 // Monte Carlo handler
c389303e 84 if (flags & kMC) {
85 AliMCEventHandler* mcHandler = new AliMCEventHandler();
86 mgr->SetMCtruthEventHandler(mcHandler);
87 mcHandler->SetReadTR(readTR);
88 }
7e4038b5 89
90 // AOD output handler
91 AliAODHandler* aodHandler = new AliAODHandler();
92 mgr->SetOutputEventHandler(aodHandler);
fea27ee0 93 aodHandler->SetOutputFileName("AliAODs.root");
da60d315 94
95 // --- Add tasks ---------------------------------------------------
7e4038b5 96 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/AddTaskFMD.C");
97 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
c389303e 98 AliAnalysisTask* task = AddTaskFMD();
0bd4b00f 99 // mgr->ConnectOutput(task, 0, mgr->GetCommonOutputContainer());
2d68d438 100
c389303e 101 task = AddTaskPhysicsSelection((flags & kMC), kTRUE, kTRUE);
0bd4b00f 102 // mgr->ConnectOutput(task, 0, mgr->GetCommonOutputContainer());
7e4038b5 103
da60d315 104 // --- Run the analysis --------------------------------------------
7e4038b5 105 TStopwatch t;
9d99b0dd 106 if (!mgr->InitAnalysis()) {
107 Error("RunManager", "Failed to initialize analysis train!");
108 return;
109 }
c389303e 110 // Skip terminate if we're so requested and not in Proof or full mode
111 mgr->SetSkipTerminate(!(flags & kProof) &&
112 !(flags & kFull) &&
113 (flags & kAnalyse));
9d99b0dd 114 // Some informative output
115 mgr->PrintStatus();
da60d315 116 // mgr->SetDebugLevel(3);
c389303e 117 if (mgr->GetDebugLevel() < 1 && !(flags & kProof))
da60d315 118 mgr->SetUseProgressBar(kTRUE);
2d68d438 119
9d99b0dd 120 // Run the train
121 t.Start();
0bd4b00f 122 if (!(flags & kTerminate)) {
123 Printf("=== RUNNING ANALYSIS ==================================");
c389303e 124 mgr->StartAnalysis((flags & kProof) ? "proof" : "local", chain, nEvents);
0bd4b00f 125 }
c389303e 126 else {
0bd4b00f 127 Printf("=== RUNNING TERMINATE =================================");
128 // mgr->ImportWrappers(0);
c389303e 129 mgr->Terminate();
130 }
9d99b0dd 131 t.Stop();
132 t.Print();
7e4038b5 133}
134//
135// EOF
136//