]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/RunManager.C
ea5e09c7af2a250dc489afa4099cae2318207ba0
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / RunManager.C
1 /** 
2  * Flags for the analysis
3  *
4  * @ingroup pwg2_forward_analysis_scripts
5  */
6 enum {
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
43  * 
44  *
45  * @ingroup pwg2_forward_analysis_scripts
46  */
47 void RunManager(const char* esddir, 
48                 Int_t       nEvents=1000, 
49                 UShort_t    flags=kFull)
50 {
51   // --- Libraries to load -------------------------------------------
52   gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadLibs.C");
53
54   // --- Check for proof mode, and possibly upload pars --------------
55   if (flags & kProof) 
56     gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadPars.C");
57   
58   // --- Our data chain ----------------------------------------------
59   gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/MakeESDChain.C");
60   TChain* chain = MakeESDChain(esddir);
61   // If 0 or less events is select, choose all 
62   if (nEvents <= 0) nEvents = chain->GetEntries();
63
64   // --- Creating the manager and handlers ---------------------------
65   AliAnalysisManager *mgr  = new AliAnalysisManager("Analysis Train", 
66                                                     "FMD analysis train");
67
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 "
79                                   "CaloClusters "
80                                   "HLTGlobalTrigger");
81   mgr->SetInputEventHandler(esdHandler);      
82        
83   // Monte Carlo handler
84   if (flags & kMC) { 
85     AliMCEventHandler* mcHandler = new AliMCEventHandler();
86     mgr->SetMCtruthEventHandler(mcHandler);
87     mcHandler->SetReadTR(readTR);    
88   }
89   
90   // AOD output handler
91   AliAODHandler* aodHandler   = new AliAODHandler();
92   mgr->SetOutputEventHandler(aodHandler);
93   aodHandler->SetOutputFileName("AliAODs.root");
94
95   // --- Add tasks ---------------------------------------------------
96   gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/AddTaskFMD.C");
97   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
98   AliAnalysisTask* task = AddTaskFMD();
99   // mgr->ConnectOutput(task, 0, mgr->GetCommonOutputContainer());
100
101   task = AddTaskPhysicsSelection((flags & kMC), kTRUE, kTRUE);
102   // mgr->ConnectOutput(task, 0, mgr->GetCommonOutputContainer());
103   
104   // --- Run the analysis --------------------------------------------
105   TStopwatch t;
106   if (!mgr->InitAnalysis()) {
107     Error("RunManager", "Failed to initialize analysis train!");
108     return;
109   }
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));
114   // Some informative output 
115   mgr->PrintStatus();
116   // mgr->SetDebugLevel(3);
117   if (mgr->GetDebugLevel() < 1 && !(flags & kProof)) 
118     mgr->SetUseProgressBar(kTRUE);
119
120   // Run the train 
121   t.Start();
122   if (!(flags & kTerminate)) {
123     Printf("=== RUNNING ANALYSIS ==================================");
124     mgr->StartAnalysis((flags & kProof) ? "proof" : "local", chain, nEvents);
125   }
126   else {
127     Printf("=== RUNNING TERMINATE =================================");
128     // mgr->ImportWrappers(0);
129     mgr->Terminate();
130   }
131   t.Stop();
132   t.Print();
133 }
134 //
135 // EOF
136 //