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