Removing dummy if
[u/mrichter/AliRoot.git] / PWGUD / selectors / dNdEta / run.C
1 void Load(const char* taskName, Bool_t debug)
2 {
3   TString compileTaskName;
4   compileTaskName.Form("%s.cxx+", taskName);
5   if (debug)
6     compileTaskName += "g";
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
22 void 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 = "")
23 {
24   // runWhat options: 0 = AlidNdEtaTask
25   //                  1 = AlidNdEtaCorrectionTask
26   //                  2 = both
27   //
28   // aProof option: 0 no proof
29   //                1 proof with chain
30   //                2 proof with dataset
31   //
32   // requiredData option: 0 = only ESD
33   //                      1 = ESD+MC
34   //                      2 = RAW (ESD+check on event type)
35   //
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   //
39   
40   TString taskName;
41   if (runWhat == 0 || runWhat == 2)
42   {
43     Printf("Running AlidNdEtaTask");
44   }
45   if (runWhat == 1 || runWhat == 2)
46   {
47     Printf("Running AlidNdEtaCorrectionTask");
48     if (requiredData != 1)
49     {
50       Printf("AlidNdEtaCorrectionTask needs MC. Exiting...");
51       return;
52     }
53   }
54
55   if (nRuns < 0)
56     nRuns = 1234567890;
57
58   if (aProof)
59   {
60     TProof::Open("alice-caf"); 
61
62     Bool_t fullAliroot = kFALSE;
63     // Enable the needed package
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     }
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     }
82     else
83     {
84       // needed if ITS recpoints are accessed, see AlidNdEtaTask, FULLALIROOT define statement
85       gProof->UploadPackage("$ALICE_ROOT/v4-18-15-AN-all.par");
86       gProof->EnablePackage("v4-18-15-AN-all");
87     
88       gProof->Exec("TGrid::Connect(\"alien://\")", kTRUE);
89       
90       // TODO add this to loadlibs.C
91       gProof->Exec("gSystem->Load(\"libXMLParser\")", kTRUE);
92     }
93
94     gProof->UploadPackage("$ALICE_ROOT/PWG0base");
95     gProof->EnablePackage("$ALICE_ROOT/PWG0base");
96   }
97   else
98   {
99     gSystem->AddIncludePath("-I${ALICE_ROOT}/include/ -I${ALICE_ROOT}/PWG0/ -I${ALICE_ROOT}/PWG0/dNdEta/"); 
100     gSystem->Load("libVMC");
101     gSystem->Load("libTree");
102     gSystem->Load("libProof");
103     gSystem->Load("libSTEERBase");
104     gSystem->Load("libESD");
105     gSystem->Load("libAOD");
106     gSystem->Load("libANALYSIS");
107     gSystem->Load("libANALYSISalice");
108     gSystem->Load("libPWG0base");
109   }
110
111   // Create the analysis manager
112   mgr = new AliAnalysisManager;
113
114   // Add ESD handler
115   
116   if (fullAliroot)
117     AliESDInputHandler* esdH = new AliESDInputHandlerRP; // for RecPoints
118   else
119     AliESDInputHandler* esdH = new AliESDInputHandler;
120   
121   esdH->SetInactiveBranches("FMD AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks MuonTracks TrdTracks");
122   mgr->SetInputEventHandler(esdH);
123
124   AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kSPD | AliPWG0Helper::kFieldOn;
125   //AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kSPD | AliPWG0Helper::kFieldOn | AliPWG0Helper::kSPDOnlyL0;
126   //AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kTPCITS | AliPWG0Helper::kFieldOn;
127   
128   AliTriggerAnalysis::Trigger trigger      = AliTriggerAnalysis::kAcceptAll | AliTriggerAnalysis::kOfflineFlag;
129   //AliTriggerAnalysis::Trigger trigger      = AliTriggerAnalysis::kAcceptAll | AliTriggerAnalysis::kOfflineFlag | AliTriggerAnalysis::kOneParticle;
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; 
138
139   AliPWG0Helper::DiffTreatment diffTreatment = AliPWG0Helper::kMCFlags;
140   //AliPWG0Helper::DiffTreatment diffTreatment = AliPWG0Helper::kE710Cuts;
141   
142   AliPWG0Helper::PrintConf(analysisMode, trigger, diffTreatment);
143
144   AliESDtrackCuts* esdTrackCuts = 0;
145   if (!(analysisMode & AliPWG0Helper::kSPD))
146   {
147     // selection of esd tracks
148     gROOT->ProcessLine(".L ../CreateStandardCuts.C");
149     esdTrackCuts = CreateTrackCuts(analysisMode);
150     if (!esdTrackCuts)
151     {
152       printf("ERROR: esdTrackCuts could not be created\n");
153       return;
154     }
155     esdTrackCuts->SetHistogramsOn(kTRUE);
156   }
157
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   
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)
202   if (0 && requiredData != 2)
203   {
204     //const char* fastORFile = "spdFOEff_run104824_52.root";
205     //const char* fastORFile = "spdFOEff_run104867_92.root";
206     //const char* fastORFile = "spdFOEff_run105054_7.root";
207     const char* fastORFile = "spdFOEff_run114931.root";
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");
212     physicsSelectionTask->GetPhysicsSelection()->Initialize(114931);
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   
236   // Create, add task
237   if (runWhat == 0 || runWhat == 2)
238   {
239     Load("AlidNdEtaTask", aDebug);
240     task = new AlidNdEtaTask(optStr);
241
242     if (requiredData == 1)
243       task->SetReadMC();
244       
245     //physicsSelectionTask->GetPhysicsSelection()->SetBin0Callback("AlidNdEtaTask");
246
247     // syst. error flags
248     //task->SetUseMCVertex();
249     //task->SetUseMCKine();
250     //task->SetOnlyPrimaries();
251     //task->SetFillPhi();
252     //task->SetSymmetrize();
253
254     // INEL>0 definition
255     if (trigger & AliTriggerAnalysis::kOneParticle)
256       task->SetMultAxisEta1();
257
258     task->SetTrigger(trigger);
259     task->SetAnalysisMode(analysisMode);
260     task->SetTrackCuts(esdTrackCuts);
261     //task->SetDeltaPhiCut(0.064);
262     task->SetDiffTreatment(diffTreatment);
263
264     mgr->AddTask(task);
265
266     // Attach input
267     mgr->ConnectInput(task, 0, cInput);
268
269     // Attach output
270     cOutput = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer);
271     mgr->ConnectOutput(task, 1, cOutput);
272   }
273
274   if (runWhat == 1 || runWhat == 2)
275   {
276     Load("AlidNdEtaCorrectionTask", aDebug);
277     task2 = new AlidNdEtaCorrectionTask(optStr);
278
279     // syst. error flags
280     //task2->SetFillPhi();
281     //task2->SetOnlyPrimaries();
282     //task2->SetSymmetrize();
283
284     // to account for gaps in real life SPD geometry
285     task2->SetSkipParticles();
286
287     // INEL>0 definition
288     if (trigger & AliTriggerAnalysis::kOneParticle)
289       task2->SetMultAxisEta1();
290
291     task2->SetTrigger(trigger);
292     task2->SetAnalysisMode(analysisMode);
293     task2->SetTrackCuts(esdTrackCuts);
294     //task2->SetDeltaPhiCut(0.064);
295     task2->SetDiffTreatment(diffTreatment);
296
297     mgr->AddTask(task2);
298
299     // Attach input
300     mgr->ConnectInput(task2, 0, cInput);
301
302     // Attach output
303     cOutput = mgr->CreateContainer("cOutput2", TList::Class(), AliAnalysisManager::kOutputContainer);
304     mgr->ConnectOutput(task2, 0, cOutput);
305   }
306
307   if (requiredData == 1) 
308   {
309     // Enable MC event handler
310     AliMCEventHandler* handler = new AliMCEventHandler;
311     handler->SetReadTR(kFALSE);
312     mgr->SetMCtruthEventHandler(handler);
313   }
314
315   // Enable debug printouts
316   if (aDebug)
317     mgr->SetDebugLevel(2);
318
319   // Run analysis
320   mgr->InitAnalysis();
321   mgr->PrintStatus();
322
323   if (aProof == 2)
324   {
325     // process dataset
326
327     mgr->StartAnalysis("proof", data, nRuns, offset);
328     
329     if (save)
330     {
331       TString path("maps/");
332       path += TString(data).Tokenize("/")->Last()->GetName();
333       
334       UInt_t triggerNoFlags = (UInt_t) trigger % (UInt_t) AliTriggerAnalysis::kStartOfFlags;
335       switch (triggerNoFlags)
336       {
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;
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;
347         default: Printf("ERROR: Trigger undefined for path to files"); return;
348       }
349       
350       if (trigger & AliTriggerAnalysis::kOneParticle)
351         path += "-onepart";
352       
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       
360       if (analysisMode & AliPWG0Helper::kSPD)
361         path += "/spd";
362       
363       if (analysisMode & AliPWG0Helper::kSPDOnlyL0)
364         path += "onlyL0";
365       
366       if (analysisMode & AliPWG0Helper::kTPC)
367         path += "/tpc";
368         
369       if (analysisMode & AliPWG0Helper::kTPCITS)
370         path += "/tpcits";
371
372       gSystem->mkdir(path, kTRUE);
373       if (runWhat == 0 || runWhat == 2)
374       {
375         gSystem->Rename("analysis_esd_raw.root", path + "/analysis_esd_raw.root");
376         if (requiredData == 1)
377           gSystem->Rename("analysis_mc.root", path + "/analysis_mc.root");
378       }
379       if (runWhat == 1 || runWhat == 2)
380       {
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");
385       }
386       gSystem->Rename("event_stat.root", path + "/event_stat.root");
387       
388       Printf(">>>>> Moved files to %s", path.Data());
389     }
390   }
391   else if (aProof == 3)
392   {
393     gROOT->ProcessLine(".L CreateChainFromDataSet.C");
394     ds = gProof->GetDataSet(data)->GetStagedSubset();
395     chain = CreateChainFromDataSet(ds, "esdTree", nRuns);
396     mgr->StartAnalysis("local", chain, 1234567890, offset);
397   }
398   else
399   {
400     // Create chain of input files
401     gROOT->LoadMacro("../CreateESDChain.C");
402
403     chain = CreateESDChain(data, nRuns, offset);
404     //chain = CreateChain("TE", data, nRuns, offset);
405
406     mgr->StartAnalysis((aProof > 0) ? "proof" : "local", chain);
407   }
408 }
409