Fixes
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / MakeAOD.C
CommitLineData
ffca499d 1/**
2 * @defgroup pwg2_forward_scripts_makers Maker scripts
3 * @ingroup pwg2_forward_scripts
4 */
7c1a1f1d 5/**
ffca499d 6 * @file MakeAOD.C
7 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
8 * @date Wed Mar 23 09:40:10 2011
7c1a1f1d 9 *
ffca499d 10 * @brief Run first pass of the analysis - AOD generation
11 *
12 * @ingroup pwg2_forward_scripts_makers
7c1a1f1d 13 */
c389303e 14/**
15 * Run first pass of the analysis - that is read in ESD and produce AOD
16 *
0be6c8cd 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 *
ffca499d 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
0be6c8cd 34 * @param name Name of train - free form. This will be the name
35 * of the output directory if the plug-in is used
7e4038b5 36 *
ffca499d 37 * @ingroup pwg2_forward_aod
7e4038b5 38 */
0171f148 39void MakeAOD(const char* esddir,
0be6c8cd 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)
7e4038b5 45{
0be6c8cd 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");
b6b35c77 54 gROOT->LoadMacro("TrainSetup.C+g");
0be6c8cd 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
da60d315 63 // --- Libraries to load -------------------------------------------
0bd4b00f 64 gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadLibs.C");
2d68d438 65
da60d315 66 // --- Check for proof mode, and possibly upload pars --------------
1174780f 67 if (proof> 0) {
68 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadPars.C");
01caf91f 69 if (!LoadPars(proof)) {
70 Error("MakeAOD", "Failed to load PARs");
71 return;
72 }
1174780f 73 }
7e4038b5 74
da60d315 75 // --- Our data chain ----------------------------------------------
b2e7f2d6 76 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/MakeChain.C");
77 TChain* chain = MakeChain("ESD", esddir,true);
c389303e 78 // If 0 or less events is select, choose all
79 if (nEvents <= 0) nEvents = chain->GetEntries();
e1f47419 80
81 // --- Set the macro path ------------------------------------------
82 gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWG2/FORWARD/analysis2:"
83 "$ALICE_ROOT/ANALYSIS/macros",
84 gROOT->GetMacroPath()));
da60d315 85
86 // --- Creating the manager and handlers ---------------------------
9453b19e 87 AliAnalysisManager *mgr = new AliAnalysisManager(name,
88 "Forward multiplicity");
0f84fefb 89 AliAnalysisManager::SetCommonFileName("forward.root");
fea27ee0 90
0171f148 91 // --- ESD input handler -------------------------------------------
7e4038b5 92 AliESDInputHandler *esdHandler = new AliESDInputHandler();
7e4038b5 93 mgr->SetInputEventHandler(esdHandler);
94
0171f148 95 // --- Monte Carlo handler -----------------------------------------
96 if (mc) {
c389303e 97 AliMCEventHandler* mcHandler = new AliMCEventHandler();
98 mgr->SetMCtruthEventHandler(mcHandler);
0171f148 99 mcHandler->SetReadTR(true);
c389303e 100 }
0171f148 101
102 // --- AOD output handler ------------------------------------------
7e4038b5 103 AliAODHandler* aodHandler = new AliAODHandler();
104 mgr->SetOutputEventHandler(aodHandler);
e308a636 105 aodHandler->SetNeedsHeaderReplication();
9d05ffeb 106 aodHandler->SetOutputFileName("AliAOD.root");
da60d315 107
108 // --- Add tasks ---------------------------------------------------
1174780f 109 // Physics selection
e1f47419 110 gROOT->LoadMacro("AddTaskPhysicsSelection.C");
ffca499d 111 AddTaskPhysicsSelection(mc, kTRUE, kFALSE);
0be6c8cd 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
1174780f 121
9d05ffeb 122#if 0
1174780f 123 // Centrality
01caf91f 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 }
1174780f 129#endif
e28f5fc5 130 if(centrality) {
e1f47419 131 gROOT->LoadMacro("AddTaskCentrality.C");
ffca499d 132 AddTaskCentrality();
e28f5fc5 133 }
1174780f 134 // FMD
ffca499d 135 gROOT->LoadMacro("AddTaskForwardMult.C");
136 AddTaskForwardMult(mc);
1174780f 137
1f52daed 138 // Central
0be6c8cd 139 gROOT->LoadMacro("AddTaskCentralMult.C");
140 AddTaskCentralMult();
7e4038b5 141
da60d315 142 // --- Run the analysis --------------------------------------------
7e4038b5 143 TStopwatch t;
9d99b0dd 144 if (!mgr->InitAnalysis()) {
0171f148 145 Error("MakeAOD", "Failed to initialize analysis train!");
9d99b0dd 146 return;
147 }
c389303e 148 // Skip terminate if we're so requested and not in Proof or full mode
0171f148 149 mgr->SetSkipTerminate(false);
9d99b0dd 150 // Some informative output
151 mgr->PrintStatus();
e308a636 152 if (proof) mgr->SetDebugLevel(3);
0171f148 153 if (mgr->GetDebugLevel() < 1 && !proof)
bad9a3c1 154 mgr->SetUseProgressBar(kTRUE,100);
2d68d438 155
9d99b0dd 156 // Run the train
157 t.Start();
01caf91f 158 Printf("=== RUNNING ANALYSIS on %9d events ==========================",
159 nEvents);
0171f148 160 mgr->StartAnalysis(proof ? "proof" : "local", chain, nEvents);
9d99b0dd 161 t.Stop();
162 t.Print();
7e4038b5 163}
164//
165// EOF
166//