60a4812cb3f45e0748fa7168467ed2768805b776
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / macros / lego_train / AddAMRsn.C
1 #ifndef __CINT__
2 #include "AliRsnTrainManager.h"
3 #endif
4 Bool_t AddAMRsnTrain(TString analysisSource = "proof", TString analysisMode = "test",TString input="aod",TString inputMC="", TString postfix = "",TString idStr="0")
5 {
6
7    Bool_t usePrivateTrain = kFALSE;
8    usePrivateTrain = kTRUE;
9
10    TString legoTrainPath = "$ALICE_ROOT/PWGLF/RESONANCES/macros/lego_train";
11 //   legoTrainPath = "/home/mvala/git/AliRsn/PWGLF/RESONANCES/macros/lego_train";
12    AliAnalysisManager::SetGlobalStr("RsnLegoTrainPath",legoTrainPath.Data());
13
14    AliAnalysisManager *mrg = AliAnalysisManager::GetAnalysisManager();
15
16    TString rsnBaseSettings = "Rsn_pp";
17 //   rsnBaseSettings = "Rsn_PbPb";
18 //   rsnBaseSettings = "Rsn_pPb";
19
20    Bool_t useRsnMini = kTRUE;
21 //   useRsnMini = kFALSE;
22
23
24    Bool_t useMixing = kFALSE;
25 //   useMixing = kTRUE;
26
27    // RSN Setting (same as old AddRsnToManager<Rsn>.C)
28    // Rsn Particle
29    TString rsnStr="Phi";
30    // Rsn Cut
31    TString rsnCutStr="";
32
33    rsnCutStr="PhiNsigma:KTPCnsig30";
34
35    if ((rsnCutStr.IsNull())&&(!postfix.IsNull())) {
36       rsnCutStr = "PhiNsigma:";
37       rsnCutStr.Append(postfix.Data());
38    }
39
40    // Rsn Quality Cut
41    TString rsnQualityCutStr = "";
42 //   rsnQualityCutStr = "pp_LHC11a_p4_120";
43 //   rsnQualityCutStr = "pp_LHC11a_p4_70";
44
45
46    TString extraMacro = "";
47    TString extraMacroArgs = "";
48 //   extraMacro = "RsnTrainSettingsExtra.C";
49 //   extraMacroArgs = "10.0,10,1,1,1,1,1,1,1,0";
50 //   extraMacroArgs = "10, 5, 5, -1, 1, 0, 1, 1, 1, 0";
51
52    input.ToLower();
53    inputMC.ToLower();
54    Bool_t useMC = !inputMC.CompareTo("mc");
55    Bool_t valid;
56
57    if (usePrivateTrain) {
58       if (!RsnLoadMacro("RsnPrivateTrainBaseSettings.C")) return kFALSE;
59
60       RsnPrivateTrainBaseSettings();
61
62       Int_t eventMixinPar = AliAnalysisManager::GetGlobalInt("rsnUseEventMixingPar",valid);
63       Int_t rsnPar = AliAnalysisManager::GetGlobalInt("rsnUseRSNPar",valid);
64       Int_t rsnParDev = AliAnalysisManager::GetGlobalInt("rsnUseRSNParDev",valid);
65       if (eventMixinPar) rsnPar = 1;
66       if (rsnPar&&rsnParDev>=0) rsnParDev=1;
67
68       Int_t pidResponse = AliAnalysisManager::GetGlobalInt("rsnUsePIDResponse",valid);
69       Int_t useRsnIH = AliAnalysisManager::GetGlobalInt("rsnUseRsnInputHandler",valid);
70       Int_t physSel = AliAnalysisManager::GetGlobalInt("rsnUsePhysSel",valid);
71       Int_t useCentralityTask = AliAnalysisManager::GetGlobalInt("rsnUseCentralityTask",valid);
72       Int_t useEventPlaneTask = AliAnalysisManager::GetGlobalInt("rsnUseEventPlaneTask",valid);
73       Int_t useVZEROEPSelection = AliAnalysisManager::GetGlobalInt("rsnUseVZEROEPSelection",valid);
74       Int_t usePIDqa = AliAnalysisManager::GetGlobalInt("rsnUsePIDqa",valid);
75
76       // ALICE stuff
77       AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
78       if (!mgr) { Printf("Error[AddAMRsn] mgr is null !!!"); return kFALSE; }
79
80       AliAnalysisGrid *analysisPlugin = mgr->GetGridHandler();
81       if (!analysisPlugin) { Printf("Error[AddAMRsn] : analysisPlugin is null !!!"); return kFALSE; }
82
83       TString myAdditionalLibs;
84       if (eventMixinPar) { AliAnalysisAlien::SetupPar("EventMixing"); myAdditionalLibs += " EventMixing.par"; }
85       else { gSystem->Load("libEventMixing.so"); myAdditionalLibs += " libEventMixing.so"; }
86
87       TString rsnLibName = "PWGLFresonances";
88       if (gSystem->Getenv("ALICE_ROOT")) {
89          TString alirootVersion = gSystem->GetFromPipe("aliroot --version | awk '{print $3}'");
90          if (alirootVersion<"v5-02-19-AN" && alirootVersion.CompareTo("trunk")) rsnLibName = "PWG2resonances";
91          if (rsnPar) { AliAnalysisAlien::SetupPar(rsnLibName.Data()); myAdditionalLibs += Form(" %s.par",rsnLibName.Data()); }
92          else { gSystem->Load(Form("lib%s.so",rsnLibName.Data())); myAdditionalLibs += Form(" lib%s.so",rsnLibName.Data()); }
93       }
94       if (rsnParDev>=0) {
95          if (rsnParDev) { AliAnalysisAlien::SetupPar("PWGLFresonancesdev"); myAdditionalLibs += " PWGLFresonancesdev.par"; }
96          else { gSystem->Load("libPWGLFresonancesdev.so"); myAdditionalLibs += " libPWGLFresonancesdev.so"; }
97       }
98       analysisPlugin->SetAdditionalLibs(myAdditionalLibs.Data());
99
100       AliMultiInputEventHandler *multiInputHandler = 0;
101       AliInputEventHandler *inputHandler = mgr->GetInputEventHandler();
102
103       TString className = inputHandler->ClassName();
104       if (!className.CompareTo("AliMultiInputEventHandler")) {
105          multiInputHandler = (AliMultiInputEventHandler *)inputHandler;
106       }
107
108       AliRsnInputHandler *rsnIH=0;
109       if (pidResponse) {
110          if (multiInputHandler) {
111             // add PID Response Handler
112             if (!RsnLoadMacro("AddPIDResponseInputHandler.C")) return kFALSE;
113             AddPIDResponseInputHandler(multiInputHandler,useMC);
114          } else {
115             Printf("Adding PIDResponse task ...");
116             gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
117             AddTaskPIDResponse(useMC);
118          }
119       }
120
121       if (multiInputHandler && useRsnIH) {
122          // add Rsn input handler (it has to be after ESD,MC,Tender input handler, but before Mixing)
123          rsnIH = new AliRsnInputHandler();
124          multiInputHandler->AddInputEventHandler(rsnIH);
125       }
126
127       if (physSel>0) {
128          if (!input.CompareTo("esd")) {
129             gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
130             Bool_t physSelBigOut = kTRUE;
131 //            physSelBigOut = kFALSE;
132
133             AddTaskPhysicsSelection(useMC,kTRUE,0,physSelBigOut);
134             if (physSelBigOut) mrg->SetSpecialOutputLocation("root://aaa//aaa/");
135          }
136
137          // maybe we can put it in $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C
138          if (multiInputHandler) {
139             AliInputEventHandler *ih = multiInputHandler->GetFirstInputEventHandler();
140             ih->SetEventSelection(multiInputHandler->GetEventSelection());
141          }
142       }
143
144       if (useCentralityTask) {
145          gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
146          AliCentralitySelectionTask *centralityTask = AddTaskCentrality(kFALSE);
147       }
148
149       if (useEventPlaneTask) {
150          gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskEventplane.C");
151          AliEPSelectionTask *eventPlaneTask = AddTaskEventplane();
152       }
153
154       if (useVZEROEPSelection) {
155          gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskVZEROEPSelection.C");
156          AddTaskVZEROEPSelection();
157       }
158
159       if (usePIDqa) {
160          gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDqa.C");
161          AddTaskPIDqa();
162       }
163
164    } else {
165
166       gSystem->Load("libEventMixing");
167       gSystem->Load("libCORRFW");
168       gSystem->Load("libPWGLFresonances");
169    }
170
171    if (!input.CompareTo("esd")) rsnBaseSettings.Append("_ESD");
172    else rsnBaseSettings.Append("_AOD");
173
174    // use mc
175    if (useMC) rsnBaseSettings.Append("_MC");
176
177    // use mini
178    if (useRsnMini) rsnBaseSettings.Append("_MINI");
179
180    // use mixing
181    if (useMixing) rsnBaseSettings.Append("_MIX");
182
183    if (!RsnLoadMacro("AddRsnTaskTrain.C")) return kFALSE;
184    AddRsnTaskTrain(rsnBaseSettings.Data(),rsnStr.Data(),rsnCutStr.Data(),rsnQualityCutStr.Data(),extraMacro,extraMacroArgs);
185
186    Printf("%s_%s_%s %s",rsnBaseSettings.Data(),rsnStr.Data(),rsnCutStr.Data(),rsnQualityCutStr.Data());
187
188    return kTRUE;
189 }
190
191 Bool_t RsnLoadMacro(TString macro,TString path="") {
192
193    Bool_t valid;
194    TString lego_path = AliAnalysisManager::GetGlobalStr("RsnLegoTrainPath",valid);
195    if (!valid) lego_path = "$ALICE_ROOT/PWG2/RESONANCES/macros/lego_train";
196
197    if (!gSystem->AccessPathName(macro.Data())) {
198       gROOT->LoadMacro(macro.Data());
199       Printf("Macro loaded from %s/%s ...",gSystem->pwd(),macro.Data());
200       return kTRUE;
201    }
202
203    if (!gSystem->AccessPathName(gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())))) {
204       gROOT->LoadMacro(gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())));
205       Printf("Macro loaded from %s ...",gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())));
206       return kTRUE;
207    }
208
209    Printf("Error loading %s",macro.Data());
210
211    return kFALSE;
212 }