Transition PWG0 -> PWGUD
[u/mrichter/AliRoot.git] / PWGUD / selectors / dNdEta / run.C
CommitLineData
7a1ac44b 1void Load(const char* taskName, Bool_t debug)
2{
3 TString compileTaskName;
81be4ee8 4 compileTaskName.Form("%s.cxx+", taskName);
7a1ac44b 5 if (debug)
51f6de65 6 compileTaskName += "g";
7a1ac44b 7
8 if (gProof) {
9 gProof->Load(compileTaskName);
10 } else
11 gROOT->Macro(compileTaskName);
12
13 // Enable debug printouts
14 if (debug)
15 {
16 AliLog::SetClassDebugLevel(taskName, AliLog::kDebug+2);
17 }
18 else
19 AliLog::SetClassDebugLevel(taskName, AliLog::kWarning);
20}
21
02e1bcdb 22void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool_t aDebug = kFALSE, Int_t aProof = kFALSE, Int_t requiredData = 1, const char* option = "")
0f67a57c 23{
0fc41645 24 // runWhat options: 0 = AlidNdEtaTask
25 // 1 = AlidNdEtaCorrectionTask
7a1ac44b 26 // 2 = both
0fc41645 27 //
28 // aProof option: 0 no proof
29 // 1 proof with chain
30 // 2 proof with dataset
a7f69e56 31 //
12bb57f1 32 // requiredData option: 0 = only ESD
33 // 1 = ESD+MC
34 // 2 = RAW (ESD+check on event type)
35 //
a7f69e56 36 // option is passed to the task(s)
37 // option SAVE is removed and results in moving the output files to maps/<ds name>/<trigger>/<det>
38 //
69b09e3b 39
0fc41645 40 TString taskName;
7a1ac44b 41 if (runWhat == 0 || runWhat == 2)
0fc41645 42 {
7a1ac44b 43 Printf("Running AlidNdEtaTask");
0fc41645 44 }
7a1ac44b 45 if (runWhat == 1 || runWhat == 2)
0fc41645 46 {
7a1ac44b 47 Printf("Running AlidNdEtaCorrectionTask");
12bb57f1 48 if (requiredData != 1)
0fc41645 49 {
7a1ac44b 50 Printf("AlidNdEtaCorrectionTask needs MC. Exiting...");
0fc41645 51 return;
52 }
53 }
0fc41645 54
55 if (nRuns < 0)
56 nRuns = 1234567890;
57
0f67a57c 58 if (aProof)
59 {
305f3651 60 TProof::Open("alice-caf");
0f67a57c 61
12bb57f1 62 Bool_t fullAliroot = kFALSE;
0f67a57c 63 // Enable the needed package
567160d6 64 if (1)
65 {
66 gProof->UploadPackage("$ALICE_ROOT/STEERBase");
67 gProof->EnablePackage("$ALICE_ROOT/STEERBase");
68 gProof->UploadPackage("$ALICE_ROOT/ESD");
69 gProof->EnablePackage("$ALICE_ROOT/ESD");
70 gProof->UploadPackage("$ALICE_ROOT/AOD");
71 gProof->EnablePackage("$ALICE_ROOT/AOD");
72 gProof->UploadPackage("$ALICE_ROOT/ANALYSIS");
73 gProof->EnablePackage("$ALICE_ROOT/ANALYSIS");
74 gProof->UploadPackage("$ALICE_ROOT/ANALYSISalice");
75 gProof->EnablePackage("$ALICE_ROOT/ANALYSISalice");
76 }
12bb57f1 77 else if (!fullAliroot)
78 {
79 gProof->UploadPackage("$ALICE_ROOT/AF-v4-18-12-AN.par");
80 gProof->EnablePackage("AF-v4-18-12-AN");
81 }
567160d6 82 else
83 {
12bb57f1 84 // needed if ITS recpoints are accessed, see AlidNdEtaTask, FULLALIROOT define statement
81be4ee8 85 gProof->UploadPackage("$ALICE_ROOT/v4-18-15-AN-all.par");
86 gProof->EnablePackage("v4-18-15-AN-all");
12bb57f1 87
88 gProof->Exec("TGrid::Connect(\"alien://\")", kTRUE);
89
90 // TODO add this to loadlibs.C
91 gProof->Exec("gSystem->Load(\"libXMLParser\")", kTRUE);
567160d6 92 }
0fc41645 93
94 gProof->UploadPackage("$ALICE_ROOT/PWG0base");
95 gProof->EnablePackage("$ALICE_ROOT/PWG0base");
0f67a57c 96 }
97 else
98 {
69b09e3b 99 gSystem->AddIncludePath("-I${ALICE_ROOT}/include/ -I${ALICE_ROOT}/PWG0/ -I${ALICE_ROOT}/PWG0/dNdEta/");
0f67a57c 100 gSystem->Load("libVMC");
101 gSystem->Load("libTree");
69b09e3b 102 gSystem->Load("libProof");
0f67a57c 103 gSystem->Load("libSTEERBase");
104 gSystem->Load("libESD");
1c15d51a 105 gSystem->Load("libAOD");
0f67a57c 106 gSystem->Load("libANALYSIS");
745d6088 107 gSystem->Load("libANALYSISalice");
0f67a57c 108 gSystem->Load("libPWG0base");
109 }
110
0f67a57c 111 // Create the analysis manager
112 mgr = new AliAnalysisManager;
113
861795a8 114 // Add ESD handler
1d107532 115
12bb57f1 116 if (fullAliroot)
117 AliESDInputHandler* esdH = new AliESDInputHandlerRP; // for RecPoints
118 else
81be4ee8 119 AliESDInputHandler* esdH = new AliESDInputHandler;
12bb57f1 120
81be4ee8 121 esdH->SetInactiveBranches("FMD AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks MuonTracks TrdTracks");
861795a8 122 mgr->SetInputEventHandler(esdH);
123
70fdd197 124 AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kSPD | AliPWG0Helper::kFieldOn;
81be4ee8 125 //AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kSPD | AliPWG0Helper::kFieldOn | AliPWG0Helper::kSPDOnlyL0;
126 //AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kTPCITS | AliPWG0Helper::kFieldOn;
127
305f3651 128 AliTriggerAnalysis::Trigger trigger = AliTriggerAnalysis::kAcceptAll | AliTriggerAnalysis::kOfflineFlag;
129 //AliTriggerAnalysis::Trigger trigger = AliTriggerAnalysis::kAcceptAll | AliTriggerAnalysis::kOfflineFlag | AliTriggerAnalysis::kOneParticle;
81be4ee8 130
131 //AliTriggerAnalysis::Trigger trigger = AliTriggerAnalysis::kSPDGFOBits | AliTriggerAnalysis::kOfflineFlag;
132 //AliTriggerAnalysis::Trigger trigger = AliTriggerAnalysis::kSPDGFOBits | AliTriggerAnalysis::kOfflineFlag | AliTriggerAnalysis::kOneParticle;
133
134 //AliTriggerAnalysis::Trigger trigger = AliTriggerAnalysis::kV0AND | AliTriggerAnalysis::kOfflineFlag;
135
136 //AliTriggerAnalysis::Trigger trigger = AliTriggerAnalysis::kV0OR | AliTriggerAnalysis::kOfflineFlag;
137 //AliTriggerAnalysis::Trigger trigger = AliTriggerAnalysis::kV0OR | AliTriggerAnalysis::kOfflineFlag | AliTriggerAnalysis::kOneParticle;
0fc41645 138
81be4ee8 139 AliPWG0Helper::DiffTreatment diffTreatment = AliPWG0Helper::kMCFlags;
140 //AliPWG0Helper::DiffTreatment diffTreatment = AliPWG0Helper::kE710Cuts;
141
142 AliPWG0Helper::PrintConf(analysisMode, trigger, diffTreatment);
770a1f1d 143
0fc41645 144 AliESDtrackCuts* esdTrackCuts = 0;
a7f69e56 145 if (!(analysisMode & AliPWG0Helper::kSPD))
770a1f1d 146 {
147 // selection of esd tracks
148 gROOT->ProcessLine(".L ../CreateStandardCuts.C");
0fc41645 149 esdTrackCuts = CreateTrackCuts(analysisMode);
770a1f1d 150 if (!esdTrackCuts)
151 {
152 printf("ERROR: esdTrackCuts could not be created\n");
153 return;
154 }
1c15d51a 155 esdTrackCuts->SetHistogramsOn(kTRUE);
0fc41645 156 }
157
a7f69e56 158 cInput = mgr->GetCommonInputContainer();
159
160 // remove SAVE option if set
161 Bool_t save = kFALSE;
162 TString optStr(option);
163 if (optStr.Contains("SAVE"))
164 {
165 optStr = optStr(0,optStr.Index("SAVE")) + optStr(optStr.Index("SAVE")+4, optStr.Length());
166 save = kTRUE;
167 }
168
81be4ee8 169 // physics selection
170 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
171 physicsSelectionTask = AddTaskPhysicsSelection((requiredData == 2) ? kFALSE : kTRUE);
172
173 // 900 GeV
174 if (0 && requiredData == 2)
175 {
176 physicsSelectionTask->GetPhysicsSelection()->AddCollisionTriggerClass("+CINT1B-ABCE-NOPF-ALL #769 #3119");
177 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1A-ABCE-NOPF-ALL #446 #2554");
178 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1C-ABCE-NOPF-ALL #1334 #2228");
179 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1-E-NOPF-ALL #790");
180 }
181
182 // 7 TeV, run 114783
183 if (0 && requiredData == 2)
184 {
185 physicsSelectionTask->GetPhysicsSelection()->AddCollisionTriggerClass("+CINT1B-ABCE-NOPF-ALL #345");
186 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1A-ABCE-NOPF-ALL #2130");
187 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1C-ABCE-NOPF-ALL #3018");
188 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1-E-NOPF-ALL #1238");
189 }
190
191 // 7 TeV, run 114786,98
192 if (0 && requiredData == 2)
193 {
194 physicsSelectionTask->GetPhysicsSelection()->AddCollisionTriggerClass("+CINT1B-ABCE-NOPF-ALL #346");
195 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1A-ABCE-NOPF-ALL #2131");
196 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1C-ABCE-NOPF-ALL #3019");
197 physicsSelectionTask->GetPhysicsSelection()->AddBGTriggerClass("+CINT1-E-NOPF-ALL #1238");
198 //physicsSelectionTask->GetPhysicsSelection()->Initialize(114786);
199 }
200
201 // FO efficiency (for MC)
305f3651 202 if (0 && requiredData != 2)
81be4ee8 203 {
204 //const char* fastORFile = "spdFOEff_run104824_52.root";
76532b17 205 //const char* fastORFile = "spdFOEff_run104867_92.root";
81be4ee8 206 //const char* fastORFile = "spdFOEff_run105054_7.root";
76532b17 207 const char* fastORFile = "spdFOEff_run114931.root";
81be4ee8 208
209 Printf("NOTE: Simulating FAST-OR efficiency on the analysis level using file %s", fastORFile);
210 TFile::Open(fastORFile);
211 spdFOEff = (TH1F*) gFile->Get("spdFOEff");
76532b17 212 physicsSelectionTask->GetPhysicsSelection()->Initialize(114931);
81be4ee8 213 physicsSelectionTask->GetPhysicsSelection()->GetTriggerAnalysis()->SetSPDGFOEfficiency(spdFOEff);
214 }
215
216 // V0 syst. study
217 if (0)
218 {
219 Printf("NOTE: Systematic study for VZERO enabled!");
220 physicsSelectionTask->GetPhysicsSelection()->Initialize(104867);
221 for (Int_t i=0; i<1; i++)
222 {
223 // for MC and data
224 //physicsSelectionTask->GetPhysicsSelection()->GetTriggerAnalysis(i)->SetV0HwPars(15, 61.5, 86.5);
225 physicsSelectionTask->GetPhysicsSelection()->GetTriggerAnalysis(i)->SetV0AdcThr(6);
226 // only for MC
227 //physicsSelectionTask->GetPhysicsSelection()->GetTriggerAnalysis(i)->SetV0HwPars(0, 0, 125);
228 //physicsSelectionTask->GetPhysicsSelection()->GetTriggerAnalysis(i)->SetV0AdcThr(0);
229 }
230 }
231
232 // BG study
233 //physicsSelectionTask->GetPhysicsSelection()->AddCollisionTriggerClass("+CINT1A-ABCE-NOPF-ALL");
234 //physicsSelectionTask->GetPhysicsSelection()->AddCollisionTriggerClass("+CINT1C-ABCE-NOPF-ALL");
235
7a1ac44b 236 // Create, add task
237 if (runWhat == 0 || runWhat == 2)
0fc41645 238 {
7a1ac44b 239 Load("AlidNdEtaTask", aDebug);
a7f69e56 240 task = new AlidNdEtaTask(optStr);
770a1f1d 241
12bb57f1 242 if (requiredData == 1)
0fc41645 243 task->SetReadMC();
76532b17 244
245 //physicsSelectionTask->GetPhysicsSelection()->SetBin0Callback("AlidNdEtaTask");
0fc41645 246
51f6de65 247 // syst. error flags
0fc41645 248 //task->SetUseMCVertex();
249 //task->SetUseMCKine();
7a1ac44b 250 //task->SetOnlyPrimaries();
69b09e3b 251 //task->SetFillPhi();
1d107532 252 //task->SetSymmetrize();
81be4ee8 253
254 // INEL>0 definition
76532b17 255 if (trigger & AliTriggerAnalysis::kOneParticle)
256 task->SetMultAxisEta1();
81be4ee8 257
7a1ac44b 258 task->SetTrigger(trigger);
259 task->SetAnalysisMode(analysisMode);
260 task->SetTrackCuts(esdTrackCuts);
81be4ee8 261 //task->SetDeltaPhiCut(0.064);
262 task->SetDiffTreatment(diffTreatment);
263
7a1ac44b 264 mgr->AddTask(task);
51f6de65 265
7a1ac44b 266 // Attach input
267 mgr->ConnectInput(task, 0, cInput);
268
269 // Attach output
270 cOutput = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer);
76532b17 271 mgr->ConnectOutput(task, 1, cOutput);
770a1f1d 272 }
81be4ee8 273
7a1ac44b 274 if (runWhat == 1 || runWhat == 2)
0fc41645 275 {
7a1ac44b 276 Load("AlidNdEtaCorrectionTask", aDebug);
a7f69e56 277 task2 = new AlidNdEtaCorrectionTask(optStr);
51f6de65 278
279 // syst. error flags
69b09e3b 280 //task2->SetFillPhi();
7a1ac44b 281 //task2->SetOnlyPrimaries();
1d107532 282 //task2->SetSymmetrize();
7a1ac44b 283
81be4ee8 284 // to account for gaps in real life SPD geometry
285 task2->SetSkipParticles();
286
287 // INEL>0 definition
76532b17 288 if (trigger & AliTriggerAnalysis::kOneParticle)
289 task2->SetMultAxisEta1();
81be4ee8 290
7a1ac44b 291 task2->SetTrigger(trigger);
292 task2->SetAnalysisMode(analysisMode);
293 task2->SetTrackCuts(esdTrackCuts);
81be4ee8 294 //task2->SetDeltaPhiCut(0.064);
295 task2->SetDiffTreatment(diffTreatment);
7a1ac44b 296
297 mgr->AddTask(task2);
51f6de65 298
7a1ac44b 299 // Attach input
300 mgr->ConnectInput(task2, 0, cInput);
51f6de65 301
7a1ac44b 302 // Attach output
303 cOutput = mgr->CreateContainer("cOutput2", TList::Class(), AliAnalysisManager::kOutputContainer);
304 mgr->ConnectOutput(task2, 0, cOutput);
0fc41645 305 }
0f67a57c 306
81be4ee8 307 if (requiredData == 1)
308 {
0f67a57c 309 // Enable MC event handler
310 AliMCEventHandler* handler = new AliMCEventHandler;
311 handler->SetReadTR(kFALSE);
312 mgr->SetMCtruthEventHandler(handler);
313 }
314
0f67a57c 315 // Enable debug printouts
316 if (aDebug)
317 mgr->SetDebugLevel(2);
318
319 // Run analysis
320 mgr->InitAnalysis();
321 mgr->PrintStatus();
322
0fc41645 323 if (aProof == 2)
324 {
325 // process dataset
326
327 mgr->StartAnalysis("proof", data, nRuns, offset);
a7f69e56 328
329 if (save)
330 {
331 TString path("maps/");
332 path += TString(data).Tokenize("/")->Last()->GetName();
333
1d107532 334 UInt_t triggerNoFlags = (UInt_t) trigger % (UInt_t) AliTriggerAnalysis::kStartOfFlags;
335 switch (triggerNoFlags)
a7f69e56 336 {
1d107532 337 case AliTriggerAnalysis::kMB1: path += "/mb1"; break;
338 case AliTriggerAnalysis::kMB2: path += "/mb2"; break;
339 case AliTriggerAnalysis::kMB3: path += "/mb3"; break;
340 case AliTriggerAnalysis::kSPDGFO: path += "/spdgfo"; break;
341 case AliTriggerAnalysis::kSPDGFOBits: path += "/spdgfobits"; break;
81be4ee8 342 case AliTriggerAnalysis::kAcceptAll: path += "/all"; break;
343 case AliTriggerAnalysis::kV0AND: path += "/v0and"; break;
344 case AliTriggerAnalysis::kV0OR: path += "/v0or"; break;
345 case AliTriggerAnalysis::kNSD1: path += "/nsd1"; break;
346 case AliTriggerAnalysis::kMB1Prime: path += "/mb1prime"; break;
a7f69e56 347 default: Printf("ERROR: Trigger undefined for path to files"); return;
348 }
349
81be4ee8 350 if (trigger & AliTriggerAnalysis::kOneParticle)
351 path += "-onepart";
352
12bb57f1 353 if (strlen(requireClass) > 0 && strlen(rejectClass) == 0)
354 {
355 path += Form("/%s", requireClass);
356 }
357 else if (strlen(rejectClass) > 0)
358 path += Form("/%s--%s", requireClass, rejectClass);
359
a7f69e56 360 if (analysisMode & AliPWG0Helper::kSPD)
361 path += "/spd";
362
81be4ee8 363 if (analysisMode & AliPWG0Helper::kSPDOnlyL0)
364 path += "onlyL0";
365
a7f69e56 366 if (analysisMode & AliPWG0Helper::kTPC)
367 path += "/tpc";
368
81be4ee8 369 if (analysisMode & AliPWG0Helper::kTPCITS)
370 path += "/tpcits";
371
a7f69e56 372 gSystem->mkdir(path, kTRUE);
373 if (runWhat == 0 || runWhat == 2)
1d107532 374 {
a7f69e56 375 gSystem->Rename("analysis_esd_raw.root", path + "/analysis_esd_raw.root");
12bb57f1 376 if (requiredData == 1)
1d107532 377 gSystem->Rename("analysis_mc.root", path + "/analysis_mc.root");
378 }
a7f69e56 379 if (runWhat == 1 || runWhat == 2)
380 {
81be4ee8 381 if (optStr.Contains("process-types"))
382 gSystem->Rename("correction_mapprocess-types.root", path + "/correction_mapprocess-types.root");
383 else
384 gSystem->Rename("correction_map.root", path + "/correction_map.root");
a7f69e56 385 }
81be4ee8 386 gSystem->Rename("event_stat.root", path + "/event_stat.root");
a7f69e56 387
388 Printf(">>>>> Moved files to %s", path.Data());
389 }
0fc41645 390 }
51f6de65 391 else if (aProof == 3)
392 {
69b09e3b 393 gROOT->ProcessLine(".L CreateChainFromDataSet.C");
394 ds = gProof->GetDataSet(data)->GetStagedSubset();
81be4ee8 395 chain = CreateChainFromDataSet(ds, "esdTree", nRuns);
396 mgr->StartAnalysis("local", chain, 1234567890, offset);
51f6de65 397 }
0fc41645 398 else
399 {
400 // Create chain of input files
401 gROOT->LoadMacro("../CreateESDChain.C");
51f6de65 402
0fc41645 403 chain = CreateESDChain(data, nRuns, offset);
1c15d51a 404 //chain = CreateChain("TE", data, nRuns, offset);
0fc41645 405
406 mgr->StartAnalysis((aProof > 0) ? "proof" : "local", chain);
407 }
0f67a57c 408}
dd367a14 409