01f490a86a3ebfd9fd18e8d5213a3eedf3d0193c
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / macros / runProofCascadePbPb.C
1 void runProofCascadePbPb (
2                           TString  proofCluster      = "mnicassi@alice-caf.cern.ch", //skaf.saske.sk",
3                           TString  alirootVer        = "VO_ALICE@AliRoot::v4-21-16-AN", 
4                           TString  rootVer           = "VO_ALICE@ROOT::v5-27-06d",
5                           TString  dataset           = "/alice/sim/LHC11a7_000137161",
6 //                          TString  dataset           = "/alice/data/LHC10h_000137161_p1_5plus",                        
7                           TString  outFileMC         = "CascadePerformance.root",
8                           TString  outFileData       = "CascadeAna.root",
9                           Bool_t   runperformancetask= kFALSE, 
10                           Bool_t   useMC             = kFALSE, 
11                           Bool_t   dataonalien       = kFALSE,
12                           Float_t  centrlowlim       = 0., 
13                           Float_t  centruplim        = 20., 
14                           TString  centrest          = "V0M",
15                           Short_t  lCollidingSystems = 1,       //0 = pp, 1 = AA
16                           Float_t  vtxlim            = 15.,  
17                           Bool_t   usecfcontainers   = kTRUE,
18                           Bool_t   kextrasel         = kTRUE,
19                           Bool_t   acccut            = kFALSE,
20                           Int_t    nEvents           = 5000, 
21                           Int_t    nEventsSkip       = 0) { //1.0*1e7
22
23   gEnv->SetValue("XSec.GSI.DelegProxy","2");
24
25   TString alirootMode = "";    // STEERBase,ESD,AOD,ANALYSIS,ANALYSISalice (default aliroot mode)
26   TString extraLibs;
27   TList *list = new TList();
28   alirootMode="ALIROOT";
29   extraLibs+= "ANALYSIS:ANALYSISalice:CORRFW";  
30
31   // sets $ALIROOT_MODE on each worker to let proof to know to run in special mode
32   list->Add(new TNamed("ALIROOT_MODE", alirootMode.Data()));
33   list->Add(new TNamed("ALIROOT_EXTRA_LIBS", extraLibs.Data()));
34   if (dataonalien) list->Add(new TNamed("ALIROOT_ENABLE_ALIEN", "1"));
35
36   // REM: same version of AliRoot on client!
37   TProof::Mgr(proofCluster.Data())->SetROOTVersion(rootVer.Data()); //If not using the default version, do it the first time only
38   TProof::Open(proofCluster.Data());
39   // enable n workers per machine
40 //  TProof::Open(proofCluster.Data(),"workers=nx")       
41   // enable less workers
42 //  TProof::Open(proofCluster.Data(),"workers=20"); //For performance reasons, try to avoid it.
43   if (!gProof) {
44     Error("runProof.C","Connection to AF failed.");
45     return;
46   }
47   gProof->EnablePackage(alirootVer.Data(), list);
48
49   Analysis(dataset.Data(), outFileMC, outFileData, 
50            useMC, nEvents, nEventsSkip,
51            centrlowlim, centruplim, centrest, 
52            vtxlim, usecfcontainers, lCollidingSystems, kextrasel,
53            runperformancetask, acccut);
54
55 }
56
57 //________________________________________________________________________
58 void Analysis(TString dataset, TString outFileMC, TString outFileData, 
59               Bool_t useMC, Int_t nEvents, Int_t nEventsSkip, 
60               Float_t centrlowlim, Float_t centruplim, TString centrest,
61               Float_t vtxlim, Bool_t usecfcontainers, Short_t  lCollidingSystems,
62               Bool_t kextrasel, Bool_t runperformancetask, Bool_t acccut) {
63
64   TString format = GetFormatFromDataSet(dataset);
65
66   // ALICE stuff
67   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
68   if (!mgr) mgr = new AliAnalysisManager("Test train");
69
70   InputHandlerSetup(format,useMC);
71
72   // compile analysis task
73   if (runperformancetask) gProof->Load("AliAnalysisTaskCheckPerformanceCascadePbPb.cxx++");
74   else gProof->Load("AliAnalysisTaskCheckCascadePbPb.cxx++");
75
76   // create manager
77   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
78   if (!mgr) mgr = new AliAnalysisManager("Cascade analysis");
79
80   // create task
81   if (runperformancetask) {
82     AliAnalysisTaskCheckPerformanceCascadePbPb *task = new AliAnalysisTaskCheckPerformanceCascadePbPb("AliAnalysisTaskCheckPerformanceCascadePbPb");
83     task->SetDebugLevelCascade           (0);
84     task->SetUseCFCont                   (usecfcontainers);
85   } else {
86     AliAnalysisTaskCheckCascadePbPb *task = new AliAnalysisTaskCheckCascadePbPb("AliAnalysisTaskCheckCascadePbPb");
87     task->SetUseCFContCascadeCuts       (usecfcontainers);
88   }
89
90   task->SetCollidingSystems           (lCollidingSystems); // only for multiplicity binning 
91   task->SetAnalysisType               (format);
92   task->SetRelaunchV0CascVertexers    (0);                 // used but code is commented out
93   task->SetQualityCutZprimVtxPos      (kTRUE);             // selects vertices in +-10cm
94   task->SetQualityCutNoTPConlyPrimVtx (kTRUE);             // retains only events with tracking + SPD vertex 
95   task->SetQualityCutTPCrefit         (kTRUE);             // requires TPC refit flag to be true to select a track
96   task->SetQualityCut80TPCcls         (kTRUE);             // rejects tracks that have less than 80 clusters in the TPC
97   task->SetExtraSelections            (kextrasel);         // used to add other selection cuts 
98   task->SetCentralityLowLim           (centrlowlim);       // setting centrality selection vriables
99   task->SetCentralityUpLim            (centruplim);
100   task->SetCentralityEst              (centrest);
101   task->SetVertexRange                (vtxlim);
102
103   // physics selection
104   gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
105   AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(useMC,kFALSE);//,kFALSE); // PbPb: use this second flag up to run 133 and for runs with the CMBS2* triggers (from 137135, including 137161) 
106 //  task->SelectCollisionCandidates();
107   
108   // for early PbPb runs collected with CMBS1 (up to 137133) manual settings
109   if (!useMC) {
110     AliPhysicsSelection * physSel = physSelTask->GetPhysicsSelection();
111   
112     if (dataset=="/alice/data/LHC10h_000137045_p1_plus") {
113       physSel->AddCollisionTriggerClass("+CMBS1A-B-NOPF-ALL");   // on the web page
114       physSel->AddCollisionTriggerClass("+CMBS1C-B-NOPF-ALL");
115       physSel->AddCollisionTriggerClass("+CMBAC-B-NOPF-ALL");
116  
117       // This are needed only to fill the statistics tables
118       physSel->AddBGTriggerClass("+CMBAC-C-NOPF-ALL");
119       physSel->AddBGTriggerClass("+CMBS1C-C-NOPF-ALL");
120       physSel->AddBGTriggerClass("+CMBS1A-C-NOPF-ALL");
121       physSel->AddBGTriggerClass("+CMBAC-A-NOPF-ALL");
122       physSel->AddBGTriggerClass("+CMBS1C-A-NOPF-ALL");
123       physSel->AddBGTriggerClass("+CMBS1A-A-NOPF-ALL");
124       physSel->AddBGTriggerClass("+CMBAC-E-NOPF-ALL");
125       physSel->AddBGTriggerClass("+CMBS1C-E-NOPF-ALL");
126       physSel->AddBGTriggerClass("+CMBS1A-E-NOPF-ALL");
127     } else {
128     // we used these manual settings for run137161 (first and second mult paper)
129     physSel->AddCollisionTriggerClass("+CMBS2A-B-NOPF-ALL");
130     physSel->AddCollisionTriggerClass("+CMBS2C-B-NOPF-ALL");
131     physSel->AddCollisionTriggerClass("+CMBAC-B-NOPF-ALL");
132     }
133
134     task->SelectCollisionCandidates(AliVEvent::kUserDefined);
135   } else {
136
137     task->SelectCollisionCandidates(AliVEvent::kMB); 
138   }
139
140   // centrality selection 
141   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
142   AliCentralitySelectionTask *taskCentr = AddTaskCentrality();
143   if (useMC) taskCentr->SetMCInput();
144
145   // create output container
146   if (runperformancetask) AliAnalysisDataContainer *output = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer, outFileMC);
147   else       AliAnalysisDataContainer *output = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer, outFileData);
148
149   // add task to the manager
150   mgr->AddTask(task);
151
152   // connect input and output
153   mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
154   mgr->ConnectOutput(task, 1, output);
155
156   // run analysis
157   mgr->InitAnalysis();
158   // process dataset  
159   mgr->StartAnalysis("proof", dataset.Data(), nEvents, nEventsSkip);  // single dataset
160 //  mgr->StartAnalysis("proof","/alice/sim/LHC11a7_000137161|/alice/sim/LHC11a7_000137162|/alice/sim/LHC11a7_000137430|/alice/sim/LHC11a7_000137431|/alice/sim/LHC11a7_000137432",nEvents, nEventsSkip);  // multiple dataset
161
162 }
163
164 //________________________________________________________________________
165 TString GetFormatFromDataSet(TString dataset) {
166
167 //  Info("runProof.C","Detecting format from dataset (may take while, depends on network connection)...");
168   TString dsTreeName;
169   if (dataset.Contains("#")) {
170     Info("runProof.C",Form("Detecting format from dataset name '%s' ...",dataset.Data()));
171     dsTreeName=dataset(dataset.Last('#'),dataset.Length());
172   } else {
173     Info("runProof.C",Form("Detecting format from dataset '%s' (may take while, depends on network connection) ...",dataset.Data()));
174     TFileCollection *ds = gProof->GetDataSet(dataset.Data());
175     if (!ds) {
176       Error(Form("Dataset %s doesn't exist on proof cluster!!!!",dataset.Data()));
177       return "";
178     }
179     dsTreeName = ds->GetDefaultTreeName();
180   }
181
182   if (dsTreeName.Contains("esdTree")) {
183     Info("runProof.C","ESD input format detected ...");
184     return "ESD";
185   } else if (dsTreeName.Contains("aodTree"))  {
186     Info("runProof.C","AOD input format detected ...");
187     return "AOD";
188   } else {
189     Error("runProof.C",Form("Tree %s is not supported !!!",dsTreeName.Data()));
190     Error("runProof.C",Form("Maybe set your DS to %s#esdTree or %s#aodTree",dataset.Data(),dataset.Data()));
191   }
192
193   return "";
194 }
195
196 //________________________________________________________________________
197 Bool_t InputHandlerSetup(TString format = "esd", Bool_t useKine = kTRUE) {
198   format.ToLower();
199
200   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
201
202   AliAnalysisDataContainer *cin = mgr->GetCommonInputContainer();
203
204   if (cin) return;
205
206   if (!format.CompareTo("esd")) {
207     AliESDInputHandler *esdInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
208
209     if (!esdInputHandler) {
210       Info("CustomAnalysisTaskInputSetup", "Creating esdInputHandler ...");
211       esdInputHandler = new AliESDInputHandler();
212       mgr->SetInputEventHandler(esdInputHandler);
213     }
214
215     if (useKine) {
216       AliMCEventHandler* mcInputHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
217
218       if (!mcInputHandler) {
219         Info("CustomAnalysisTaskInputSetup", "Creating mcInputHandler ...");
220         AliMCEventHandler* mcInputHandler = new AliMCEventHandler();
221         mgr->SetMCtruthEventHandler(mcInputHandler);
222       }
223     }
224
225   } else if (!format.CompareTo("aod")) {
226     AliAODInputHandler *aodInputHandler = dynamic_cast<AliAODInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
227
228     if (!aodInputHandler) {
229       Info("CustomAnalysisTaskInputSetup", "Creating aodInputHandler ...");
230       aodInputHandler = new AliAODInputHandler();
231       mgr->SetInputEventHandler(aodInputHandler);
232     }
233   } else {
234     AliWarning("Wrong input format!!! Only ESD and AOD are supported. Skipping Task ...");
235     return kFALSE;
236   }
237
238   return kTRUE;
239 }
240
241 //________________________________________________________________________