Updated macros for lego train (mavala)
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / macros / lego_train / AddRsnTask.C
CommitLineData
221dc8d3 1#ifndef __CINT__
2#include <TString.h>
3#include <AliAnalysisManager.h>
4#include <AliRsnAnalysisTask.h>
5#include <AliRsnDaughterSelector.h>
6#include <AliRsnMiniAnalysisTask.h>
7#endif
8AliAnalysisTaskSE *AddRsnTask(TString rsnPart,TString rsnCut,TString postfix="")
9{
10 // Analysis Manager
11 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
12 if (!mgr) { Printf("Error [AddRsnTaskTrain%s] : mgr is null !!!",postfix.Data()); return 0;}
13
14 // initialize task with all available slots, even if not all of them will be used:
15 AliAnalysisTaskSE *task = 0;
16
17 Bool_t valid;
18 Int_t useMC = AliRsnTrainManager::GetGlobalInt("IsMC",valid);
19 Int_t isRsnMini = AliRsnTrainManager::GetGlobalInt("IsRsnMini",valid);
20 Int_t physSelBit = AliRsnTrainManager::GetGlobalInt("RsnPhysSelFilterBit",valid);
ae15a5ec 21 Int_t isMixing = AliRsnTrainManager::GetGlobalInt("IsMixing",valid);
22 Int_t collisionType = AliRsnTrainManager::GetGlobalInt("IsCollisionType",valid);
23 Int_t isAOD049 = AliRsnTrainManager::GetGlobalInt("RsnUseAOD049Patch",valid);
221dc8d3 24
25 if (isRsnMini) {
26 postfix.Prepend("Mini");
a9d94049 27 AliRsnMiniAnalysisTask *taskRsnMini = new AliRsnMiniAnalysisTask(TString::Format("Rsn%s",postfix.Data()).Data(),useMC);
221dc8d3 28 Int_t refreshPrint = AliRsnTrainManager::GetGlobalInt("RsnMixPrintRefresh",valid);
29 if (valid) taskRsnMini->SetMixPrintRefresh(refreshPrint);
30 task = (AliAnalysisTaskSE *) taskRsnMini;
31 }
32 else {
a9d94049 33 AliRsnAnalysisTask *taskRsn = new AliRsnAnalysisTask(TString::Format("Rsn%s",postfix.Data()).Data());
221dc8d3 34 task = (AliAnalysisTaskSE *) taskRsn;
35 }
ae15a5ec 36
a9d94049 37 postfix.Append(TString::Format("_%s_%s",rsnPart.Data(),rsnCut.Data()).Data());
221dc8d3 38
39 if (physSelBit>=0) task->SelectCollisionCandidates((AliVEvent::EOfflineTriggerTypes)physSelBit);
40
41 AliRsnInputHandler *rsnIH=0;
42 // TODO this is tmp hack
43 if (!rsnIH) rsnIH = new AliRsnInputHandler();
44
45
46 TList *listRsn = new TList();
47 listRsn->Add(new TNamed(rsnPart.Data(),rsnCut.Data()));
48
b68f0fc1 49 if (!RsnLoadMacroTask("RsnConfig.C")) return 0;
221dc8d3 50 if (!RsnConfig(task,rsnIH,listRsn)) {
51 Printf("Error in RsnConfig.C");
52 return 0;
53 }
54
ae15a5ec 55 // setup Event Mixing
56 if (isMixing) AddEventMixingSettings(task);
57
58 if (isAOD049 && (!useMC) && (collisionType==1)) {
8c877c2b 59 if (isRsnMini) taskRsnMini->SetUseCentralityPatch(kTRUE);
ae15a5ec 60 }
61
221dc8d3 62 // add the task to manager
63 mgr->AddTask(task);
64
65 AliRsnDaughterSelector *sel = 0;
66
67 if (!isRsnMini) {
68 sel = rsnIH->GetSelector();
69 sel->Init();
70 }
71
72 // connect input container according to source choice
73 mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
74
75 // create paths for the output in the common file
76 TString commonPath = AliAnalysisManager::GetCommonFileName();
77
78 // create containers for output
79 AliAnalysisDataContainer *output = mgr->CreateContainer(Form("RsnHist%s", postfix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, commonPath.Data());
80
81// // big outout (expert only)
82// Int_t useBigOutput = 0;
83// if (useBigOutput) {
84// Printf("Using Big output ...");
85// task->UseBigOutput();
86// output->SetSpecialOutput();
87// mgr->SetSpecialOutputLocation("root://lx000.saske.sk:21094//tmp/mvala/");
88// }
89
90 mgr->ConnectOutput(task, 1, output);
91
92 return task;
93}
b68f0fc1 94
ae15a5ec 95void AddEventMixingSettings(AliAnalysisTaskSE *task) {
96
97 Bool_t valid = kTRUE;
98 Int_t collisionType = AliRsnTrainManager::GetGlobalInt("IsCollisionType",valid);
99 Int_t isRsnMini = AliRsnTrainManager::GetGlobalInt("IsRsnMini",valid);
100 Int_t mixNum = AliRsnTrainManager::GetGlobalInt("RsnNumMix",valid);
101
50700f47 102 Double_t mixDiffMult = AliRsnTrainManager::GetGlobalInt("RsnMixDiffMult",valid);
103 Double_t mixDiffVz = AliRsnTrainManager::GetGlobalInt("RsnMixDiffVz",valid);
104 Double_t mixDiffAngle = AliRsnTrainManager::GetGlobalInt("RsnMixDiffAngle",valid);
ae15a5ec 105
106 if (isRsnMini) {
107 AliRsnMiniAnalysisTask *taskRsn = (AliRsnMiniAnalysisTask *) task;
108 if (collisionType == 0) {
109 // taskRsn->UseMultiplicity("TRACKS");
110 taskRsn->UseMultiplicity("QUALITY");
ae15a5ec 111 } else {
112 taskRsn->UseCentrality("V0M");
ae15a5ec 113 }
50700f47 114 if (mixDiffMult>0.0) taskRsn->SetMaxDiffMult(mixDiffMult);
115
ae15a5ec 116 // set mixing
117 taskRsn->UseContinuousMix();
118 //task->UseBinnedMix();
119 taskRsn->SetNMix(mixNum);
120
50700f47 121 if (mixDiffVz>0.0) taskRsn->SetMaxDiffVz(mixDiffVz);
122 if (mixDiffAngle>0.0) taskRsn->SetMaxDiffAngle(mixDiffAngle);
123 // 30.0 * TMath::DegToRad()
ae15a5ec 124 }
125 // TODO RSN non Mini
126
127}
128
b68f0fc1 129Bool_t RsnLoadMacroTask(TString macro,TString path="") {
130
131 Bool_t valid;
132 TString lego_path = AliAnalysisManager::GetGlobalStr("RsnLegoTrainPath",valid);
133 if (!valid) lego_path = "$ALICE_ROOT/PWGLF/RESONANCES/macros/lego_train";
134
135 if (!gSystem->AccessPathName(macro.Data())) {
136 gROOT->LoadMacro(macro.Data());
137 Printf("Macro loaded from %s/%s ...",gSystem->pwd(),macro.Data());
138 return kTRUE;
139 }
140
141 if (!gSystem->AccessPathName(gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())))) {
142 gROOT->LoadMacro(gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())));
143 Printf("Macro loaded from %s ...",gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())));
144 return kTRUE;
145 }
146
147 Printf("Error loading %s",macro.Data());
148
149 return kFALSE;
150}