]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/MakeAOD.C
Various smaller Fixes
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / MakeAOD.C
1 /** 
2  * @defgroup pwg2_forward_scripts_makers Maker scripts 
3  * @ingroup pwg2_forward_scripts
4  */
5 /**
6  * @file   MakeAOD.C
7  * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
8  * @date   Wed Mar 23 09:40:10 2011
9  * 
10  * @brief  Run first pass of the analysis - AOD generation
11  * 
12  * @ingroup pwg2_forward_scripts_makers
13  */
14 /** 
15  * Run first pass of the analysis - that is read in ESD and produce AOD
16  * 
17  * If the ROOT AliEn interface library (libRAliEn) can be loaded, 
18  * and the parameter @a name is not empty, then use the plugin to do
19  * the analysis.  Note that in this case, the output is placed 
20  * in a sub-directory named by @a name after escaping spaces and special 
21  * characters 
22  *
23  * If PROOF mode is selected, then Terminate will be run on the master node 
24  * in any case. 
25  *
26  * @param esddir     ESD input directory. Any file matching the pattern 
27  *                   *AliESDs*.root are added to the chain 
28  * @param nEvents    Number of events to process.  If 0 or less, then 
29  *                   all events are analysed
30  * @param proof      If larger then 1, run in PROOF-Lite mode with this 
31  *                   many number of workers. 
32  * @param mc         Data is assumed to be from simulations  
33  * @param centrality Whether to use centrality or not 
34  * @param name       Name of train - free form.  This will be the name
35  *                   of the output directory if the plug-in is used 
36  *
37  * @ingroup pwg2_forward_aod
38  */
39 void MakeAOD(const char* esddir, 
40              Int_t       nEvents    = -1, 
41              Int_t       proof      = 0,
42              Bool_t      mc         = false,
43              Bool_t      centrality = true,
44              const char* name       = 0)
45 {
46   // --- Possibly use plug-in for this -------------------------------
47   if ((name && name[0] != '\0') && gSystem->Load("libRAliEn") >= 0) {
48     gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWG2/FORWARD/analysis2:"
49                              "$ALICE_ROOT/ANALYSIS/macros",
50                              gROOT->GetMacroPath()));
51     gSystem->AddIncludePath("-I${ALICE_ROOT}/include");
52     gSystem->Load("libANALYSIS");
53     gSystem->Load("libANALYSISalice");
54     gROOT->LoadMacro("TrainSetup.C+g");
55     MakeAODTrain t(name, 0, 0, 0, centrality, false);
56     t.SetDataDir(esddir);
57     t.SetDataSet("");
58     t.SetProofServer(Form("workers=%d",proof));
59     t.Run(proof > 0 ? "PROOF" : "LOCAL", "FULL", nEvents, mc, proof > 0);
60     return;
61   }
62
63   // --- Libraries to load -------------------------------------------
64   gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadLibs.C");
65
66   // --- Check for proof mode, and possibly upload pars --------------
67   if (proof> 0) { 
68     gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadPars.C");
69     if (!LoadPars(proof)) { 
70       Error("MakeAOD", "Failed to load PARs");
71       return;
72     }
73   }
74   
75   // --- Our data chain ----------------------------------------------
76   gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/MakeChain.C");
77   TChain* chain = MakeChain("ESD", esddir,true);
78   // If 0 or less events is select, choose all 
79   if (nEvents <= 0) nEvents = chain->GetEntries();
80   
81   // --- Set the macro path ------------------------------------------
82   gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWG2/FORWARD/analysis2:"
83                            "$ALICE_ROOT/ANALYSIS/macros",
84                            gROOT->GetMacroPath()));
85
86   // --- Creating the manager and handlers ---------------------------
87   AliAnalysisManager *mgr  = new AliAnalysisManager(name, 
88                                                     "Forward multiplicity");
89   AliAnalysisManager::SetCommonFileName("forward.root");
90
91   // --- ESD input handler -------------------------------------------
92   AliESDInputHandler *esdHandler = new AliESDInputHandler();
93   mgr->SetInputEventHandler(esdHandler);      
94        
95   // --- Monte Carlo handler -----------------------------------------
96   if (mc) {
97     AliMCEventHandler* mcHandler = new AliMCEventHandler();
98     mgr->SetMCtruthEventHandler(mcHandler);
99     mcHandler->SetReadTR(true);    
100   }
101
102   // --- AOD output handler ------------------------------------------
103   AliAODHandler* aodHandler   = new AliAODHandler();
104   mgr->SetOutputEventHandler(aodHandler);
105   aodHandler->SetNeedsHeaderReplication();
106   aodHandler->SetOutputFileName("AliAOD.root");
107
108   // --- Add tasks ---------------------------------------------------
109   // Physics selection 
110   gROOT->LoadMacro("AddTaskPhysicsSelection.C");
111   AddTaskPhysicsSelection(mc, kTRUE, kFALSE);
112   // --- Fix up physics selection to give proper A,C, and E triggers -
113   AliInputEventHandler* ih =
114     static_cast<AliInputEventHandler*>(mgr->GetInputEventHandler());
115   AliPhysicsSelection* ps = 
116     static_cast<AliPhysicsSelection*>(ih->GetEventSelection());
117   // Ignore trigger class when selecting events.  This mean that we
118   // get offline+(A,C,E) events too
119   ps->SetSkipTriggerClassSelection(true);
120   
121
122 #if 0
123   // Centrality 
124   if (!proof) {
125     gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/Compile.C");
126     Compile("$ALICE_ROOT/PWG2/FORWARD/analysis2/AddTaskCopyHeader.C","");
127     AddTaskCopyHeader();
128   }
129 #endif
130   if(centrality) {
131     gROOT->LoadMacro("AddTaskCentrality.C");
132     AddTaskCentrality();
133   }
134   // FMD 
135   gROOT->LoadMacro("AddTaskForwardMult.C");
136   AddTaskForwardMult(mc);
137
138   // Central 
139   gROOT->LoadMacro("AddTaskCentralMult.C");
140   AddTaskCentralMult(mc);
141   
142   // --- Run the analysis --------------------------------------------
143   TStopwatch t;
144   if (!mgr->InitAnalysis()) {
145     Error("MakeAOD", "Failed to initialize analysis train!");
146     return;
147   }
148   // Skip terminate if we're so requested and not in Proof or full mode
149   mgr->SetSkipTerminate(false);
150   // Some informative output 
151   mgr->PrintStatus();
152   if (proof) mgr->SetDebugLevel(3);
153   if (mgr->GetDebugLevel() < 1 && !proof) 
154     mgr->SetUseProgressBar(kTRUE,100);
155
156   // Run the train 
157   t.Start();
158   Printf("=== RUNNING ANALYSIS on %9d events ==========================",
159          nEvents);
160   mgr->StartAnalysis(proof ? "proof" : "local", chain, nEvents);
161   t.Stop();
162   t.Print();
163 }
164 //
165 // EOF
166 //