1 // ### Settings that make sense when using the Alien plugin
2 //==============================================================================
3 Int_t runOnData = 0; // Set to 1 if processing real data
4 Int_t iCollision = 0; // 0=pp, 1=Pb-Pb
5 Int_t run_flag = 1100; // year (2011 = 1100)
6 //==============================================================================
7 Bool_t doCDBconnect =1;
8 Bool_t usePhysicsSelection = kTRUE; // use physics selection
9 Bool_t useTender = kFALSE; // use tender wagon
10 Bool_t useCentrality = kFALSE; // centrality
11 Bool_t useV0tender = kFALSE; // use V0 correction in tender
12 Bool_t useDBG = kTRUE; // activate debugging
13 Bool_t useMC = kFALSE; // use MC info
14 Bool_t useKFILTER = kFALSE; // use Kinematics filter
15 Bool_t useTR = kFALSE; // use track references
16 Bool_t useCORRFW = kFALSE; // do not change
17 Bool_t useAODTAGS = kFALSE; // use AOD tags
18 Bool_t useSysInfo = kFALSE; // use sys info
20 // ### Analysis modules to be included. Some may not be yet fully implemented.
21 //==============================================================================
22 Int_t iAODhandler = 1; // Analysis produces an AOD or dAOD's
23 Int_t iESDfilter = 1; // ESD to AOD filter (barrel + muon tracks)
24 Int_t iESDfilterReVtx = -1; // Request revertexing in ESD filtering
25 Int_t iMUONcopyAOD = 1; // Task that copies only muon events in a separate AOD (PWG3)
26 Int_t iJETAN = 0; // Jet analysis (PWG4)
27 Int_t iJETANdelta = 0; // Jet delta AODs
28 Int_t iPWGHFvertexing = 1; // Vertexing HF task (PWG3)
29 Int_t iPWGDQJPSIfilter = 0; // JPSI filtering (PWG3)
30 Int_t iPWGHFd2h = 1; // D0->2 hadrons (PWG3)
31 Int_t iPWGPP =1; // high pt filter task
32 Int_t iPWGLFForward = 1; // Forward mult task (PWGLF)
33 Bool_t doPIDResponse = 1;
34 Bool_t doPIDqa = 1; //new
36 // ### Configuration macros used for each module
37 //==============================================================================
38 TString configPWGHFd2h = (iCollision==0)?"$ALICE_ROOT/PWGHF/vertexingHF/ConfigVertexingHF.C"
39 :"$ALICE_ROOT/PWGHF/vertexingHF/ConfigVertexingHF_highmult.C";
41 Double_t cutsESDfilterReVtx[21] =
42 {1.00e-01,1.00e-01,5.00e-01,3.00e+00,1.00e+00,
43 3.00e+00,1.00e+02,1.00e+03,3.00e+00,3.00e+01,
44 6.00e+00,4.00e+00,7.00e+00,1.00e+03,5.00e+00,
45 5.00e-02,1.00e-03,2.00e+00,1.00e+01,1.00e+00,
52 void AddAnalysisTasks();
53 Bool_t LoadCommonLibraries();
54 Bool_t LoadAnalysisLibraries();
55 Bool_t LoadLibrary(const char *);
56 TChain *CreateChain();
57 const char *cdbPath = "raw://";
60 //______________________________________________________________________________
61 void AODtrain(Int_t merge=0)
63 // Main analysis train macro.
65 if (merge || doCDBconnect) {
66 TGrid::Connect("alien://");
67 if (!gGrid || !gGrid->IsConnected()) {
68 ::Error("QAtrain", "No grid connection");
72 // Set temporary merging directory to current one
73 gSystem->Setenv("TMPDIR", gSystem->pwd());
74 // Set temporary compilation directory to current one
75 gSystem->SetBuildDir(gSystem->pwd(), kTRUE);
76 printf("==================================================================\n");
77 printf("=========== RUNNING FILTERING TRAIN ==========\n");
78 printf("==================================================================\n");
79 printf("= Configuring analysis train for: =\n");
80 if (usePhysicsSelection) printf("= Physics selection =\n");
81 if (useTender) printf("= TENDER =\n");
82 if (iESDfilter) printf("= ESD filter =\n");
83 if (iMUONcopyAOD) printf("= MUON copy AOD =\n");
84 if (iJETAN) printf("= Jet analysis =\n");
85 if (iJETANdelta) printf("= Jet delta AODs =\n");
86 if (iPWGHFvertexing) printf("= PWGHF vertexing =\n");
87 if (iPWGDQJPSIfilter) printf("= PWGDQ j/psi filter =\n");
88 if (iPWGHFd2h) printf("= PWGHF D0->2 hadrons QA =\n");
90 // Load common libraries and set include path
91 if (!LoadCommonLibraries()) {
92 ::Error("AnalysisTrain", "Could not load common libraries");
96 // Make the analysis manager and connect event handlers
97 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "Production train");
98 if (useSysInfo) mgr->SetNSysInfo(100);
99 // Load analysis specific libraries
100 if (!LoadAnalysisLibraries()) {
101 ::Error("AnalysisTrain", "Could not load analysis libraries");
105 // Create input handler (input container created automatically)
107 AliESDInputHandler *esdHandler = new AliESDInputHandler();
108 mgr->SetInputEventHandler(esdHandler);
109 // Monte Carlo handler
111 AliMCEventHandler* mcHandler = new AliMCEventHandler();
112 mgr->SetMCtruthEventHandler(mcHandler);
113 mcHandler->SetReadTR(useTR);
115 // AOD output container, created automatically when setting an AOD handler
117 // AOD output handler
118 AliAODHandler* aodHandler = new AliAODHandler();
119 aodHandler->SetOutputFileName("AliAOD.root");
120 mgr->SetOutputEventHandler(aodHandler);
122 // Debugging if needed
123 if (useDBG) mgr->SetDebugLevel(3);
125 AddAnalysisTasks(cdbPath);
129 mgr->SetGridHandler(new AliAnalysisAlien);
130 mgr->StartAnalysis("gridterminate",0);
135 TChain *chain = CreateChain();
140 mgr->SetSkipTerminate(kTRUE);
141 if (mgr->InitAnalysis()) {
143 mgr->StartAnalysis("local", chain);
148 //______________________________________________________________________________
149 void AddAnalysisTasks(const char *cdb_location){
150 // Add all analysis task wagons to the train
151 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
154 // Tender and supplies. Needs to be called for every event.
156 AliAnalysisManager::SetCommonFileName("AODQA.root");
158 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/TenderSupplies/AddTaskTender.C");
159 // IF V0 tender needed, put kTRUE below
160 AliAnalysisTaskSE *tender = AddTaskTender(useV0tender);
161 // tender->SetDebugLevel(2);
167 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
168 AliAnalysisTaskPIDResponse *PIDResponse = AddTaskPIDResponse();
169 // PIDResponse->SelectCollisionCandidates(AliVEvent::kAny);
176 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDqa.C");
177 AliAnalysisTaskPIDqa *PIDQA = AddTaskPIDqa();
178 PIDQA->SelectCollisionCandidates(AliVEvent::kAny);
182 if (doCDBconnect && !useTender) {
183 gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskCDBconnect.C");
184 AliTaskCDBconnect *taskCDB = AddTaskCDBconnect(cdb_location, run_number);
185 if (!taskCDB) return;
186 AliCDBManager *cdb = AliCDBManager::Instance();
187 cdb->SetDefaultStorage(cdb_location);
188 // taskCDB->SetRunNumber(run_number);
191 if (usePhysicsSelection) {
192 // Physics selection task
193 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
194 mgr->RegisterExtraFile("event_stat.root");
195 AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(useMC);
196 // AliOADBPhysicsSelection * oadbDefaultPbPb = CreateOADBphysicsSelection();
197 // physSelTask->GetPhysicsSelection()->SetCustomOADBObjects(oadbDefaultPbPb,0,0);
198 mgr->AddStatisticsTask(AliVEvent::kAny);
204 gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskFilteredTree.C");
205 AddTaskFilteredTree("FilterEvents_Trees.root");
208 // Centrality (only Pb-Pb)
210 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
211 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
212 //taskCentrality->SelectCollisionCandidates(AliVEvent::kAny);
215 // --- PWGLF - Forward (cholm@nbi.dk) -----------------------------
216 if (iPWGLFForward && usePhysicsSelection) {
217 gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/AddTaskForwardMult.C");
218 UShort_t pwglfForwardSys = 0; // iCollision+1; // pp:1, PbPb:2, pPb:3
219 UShort_t pwglfSNN = 0; // GeV, 0==unknown
220 Short_t pwglfField = 0;
221 AddTaskForwardMult(useMC && useTR, // Need track-refs
222 pwglfForwardSys, // Collision system
225 gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/AddTaskCentralMult.C");
226 AddTaskCentralMult(useMC, pwglfForwardSys, pwglfSNN, pwglfField);
232 // ESD filter task configuration.
233 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/ESDfilter/macros/AddTaskESDFilter.C");
234 AliAnalysisTaskESDfilter *taskesdfilter = 0;
236 printf("Registering delta AOD file\n");
237 mgr->RegisterExtraFile("AliAOD.Muons.root");
238 mgr->RegisterExtraFile("AliAOD.Dimuons.root");
239 taskesdfilter = AddTaskESDFilter(useKFILTER, kTRUE, kFALSE, kFALSE /*usePhysicsSelection*/,kFALSE,kTRUE,kFALSE,kFALSE,run_flag);
241 taskesdfilter = AddTaskESDFilter(useKFILTER, kFALSE, kFALSE, kFALSE /*usePhysicsSelection*/,kFALSE,kTRUE,kFALSE,kFALSE,run_flag); // others
243 if (iESDfilterReVtx>=0 && taskesdfilter) taskesdfilter->SetRefitVertexTracks(iESDfilterReVtx, cutsESDfilterReVtx);
244 taskesdfilter->Dump();
248 // if (iMUONcopyAOD) {
249 // printf("Registering delta AOD file\n");
250 // mgr->RegisterExtraFile("AliAOD.Muons.root");
251 // mgr->RegisterExtraFile("AliAOD.Dimuons.root");
253 // AliAnalysisTaskESDfilter *taskesdfilter =
254 // AddTaskESDFilter(useKFILTER,
255 // iMUONcopyAOD, // write Muon AOD
256 // kFALSE, // write dimuon AOD
257 // kFALSE, // usePhysicsSelection
258 // kFALSE, // centrality OBSOLETE
259 // kTRUE, // enable TPS only tracks
260 // kFALSE, // disable cascades
261 // kFALSE, // disable kinks
262 // run_flag); // run flag (YY00)
263 // mgr->RegisterExtraFile("AliAOD.Dimuons.root");
266 // ********** PWG3 wagons ******************************************************
268 if (iPWGHFvertexing) {
269 gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/macros/AddTaskVertexingHF.C");
270 if (!iPWGHFd2h) TFile::Cp(gSystem->ExpandPathName(configPWGHFd2h.Data()), "file:ConfigVertexingHF.C");
271 AliAnalysisTaskSEVertexingHF *taskvertexingHF = AddTaskVertexingHF();
272 if (!taskvertexingHF) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSEVertexingHF cannot run for this train conditions - EXCLUDED");
273 else mgr->RegisterExtraFile("AliAOD.VertexingHF.root");
274 taskvertexingHF->SelectCollisionCandidates(0);
277 // PWGDQ JPSI filtering (only pp)
278 if (iPWGDQJPSIfilter && (iCollision==0)) {
279 gROOT->LoadMacro("$ALICE_ROOT/PWGDQ/dielectron/macros/AddTaskJPSIFilter.C");
280 AliAnalysisTaskSE *taskJPSIfilter = AddTaskJPSIFilter();
281 if (!taskJPSIfilter) ::Warning("AnalysisTrainNew", "AliAnalysisTaskDielectronFilter cannot run for this train conditions - EXCLUDED");
282 else mgr->RegisterExtraFile("AliAOD.Dielectron.root");
283 taskJPSIfilter->SelectCollisionCandidates(0);
288 gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/AddD2HTrain.C");
289 TFile::Cp(gSystem->ExpandPathName(configPWGHFd2h.Data()), "file:ConfigVertexingHF.C");
290 AddD2HTrain(kFALSE, 1,0,0,0,0,0,0,0,0,0,0);
293 // ********** PWG4 wagons ******************************************************
296 // Configurations flags, move up?
297 TString kDeltaAODJetName = "AliAOD.Jets.root"; //
298 Bool_t kIsPbPb = (iCollision==0)?false:true; // can be more intlligent checking the name of the data set
299 TString kDefaultJetBackgroundBranch = "";
300 TString kJetSubtractBranches = "";
301 UInt_t kHighPtFilterMask = 272;// from esd filter
302 UInt_t iPhysicsSelectionFlag = 0;
304 gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/AddTaskJets.C");
305 // Default jet reconstructor running on ESD's
306 AliAnalysisTaskJets *taskjets = AddTaskJets("AOD","UA1",0.4,kHighPtFilterMask,1.,0); // no background subtraction
307 if (!taskjets) ::Fatal("AnalysisTrainNew", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
308 if(kDeltaAODJetName.Length()>0) taskjets->SetNonStdOutputFile(kDeltaAODJetName.Data());
310 // AddTaskJetsDelta("AliAOD.Jets.root"); // need to modify this accordingly in the add task jets
311 mgr->RegisterExtraFile(kDeltaAODJetName.Data());
314 // UA1 intrinsic background subtraction
315 taskjets = AddTaskJets("AOD","UA1",0.4,kHighPtFilterMask,1.,2); // background subtraction
316 if(kDeltaAODJetName.Length()>0)taskjets->SetNonStdOutputFile(kDeltaAODJetName.Data());
319 taskjets = AddTaskJets("AOD","SISCONE",0.4,kHighPtFilterMask,0.15,0); //no background subtration to be done later....
320 if(kDeltaAODJetName.Length()>0)taskjets->SetNonStdOutputFile(kDeltaAODJetName.Data());
321 cTmp = taskjets->GetNonStdBranch();
322 if(cTmp.Length()>0)kJetSubtractBranches += Form("%s ",cTmp.Data());
324 // Add the clusters..
325 gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/AddTaskJetCluster.C");
326 AliAnalysisTaskJetCluster *taskCl = 0;
329 Float_t fTrackEtaWindow = 0.9;
330 taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelectionFlag,"KT",0.4,0,1, kDeltaAODJetName.Data(),0.15,fTrackEtaWindow,0); // this one is for the background and random jets, random cones with no skip
331 taskCl->SetBackgroundCalc(kTRUE);
332 taskCl->SetNRandomCones(10);
333 taskCl->SetCentralityCut(fCenLo,fCenUp);
334 taskCl->SetGhostEtamax(fTrackEtaWindow);
335 kDefaultJetBackgroundBranch = Form("%s_%s",AliAODJetEventBackground::StdBranchName(),taskCl->GetJetOutputBranch());
337 taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelectionFlag,"ANTIKT",0.4,2,1,kDeltaAODJetName.Data(),0.15);
338 taskCl->SetCentralityCut(fCenLo,fCenUp);
339 if(kIsPbPb)taskCl->SetBackgroundBranch(kDefaultJetBackgroundBranch.Data());
340 taskCl->SetNRandomCones(10);
341 kJetSubtractBranches += Form("%s ",taskCl->GetJetOutputBranch());
343 taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelectionFlag,"ANTIKT",0.2,0,1,kDeltaAODJetName.Data(),0.15);
344 taskCl->SetCentralityCut(fCenLo,fCenUp);
345 if(kIsPbPb)taskCl->SetBackgroundBranch(kDefaultJetBackgroundBranch.Data());
346 kJetSubtractBranches += Form("%s ",taskCl->GetJetOutputBranch());
348 // DO THE BACKGROUND SUBTRACTION
349 if(kIsPbPb&&kJetSubtractBranches.Length()){
350 gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/AddTaskJetBackgroundSubtract.C");
351 AliAnalysisTaskJetBackgroundSubtract *taskSubtract = 0;
352 taskSubtract = AddTaskJetBackgroundSubtract(kJetSubtractBranches,1,"B0","B%d");
353 taskSubtract->SetBackgroundBranch(kDefaultJetBackgroundBranch.Data());
354 if(kDeltaAODJetName.Length()>0)taskSubtract->SetNonStdOutputFile(kDeltaAODJetName.Data());
359 //______________________________________________________________________________
360 Bool_t LoadCommonLibraries()
362 // Load common analysis libraries.
363 if (!gSystem->Getenv("ALICE_ROOT")) {
364 ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
367 Bool_t success = kTRUE;
368 // Load framework classes. Par option ignored here.
369 success &= LoadLibrary("libSTEERBase.so");
370 success &= LoadLibrary("libESD.so");
371 success &= LoadLibrary("libAOD.so");
372 success &= LoadLibrary("libANALYSIS.so");
373 success &= LoadLibrary("libOADB.so");
374 success &= LoadLibrary("libANALYSISalice.so");
375 success &= LoadLibrary("libESDfilter.so");
376 success &= LoadLibrary("libCORRFW.so");
377 gROOT->ProcessLine(".include $ALICE_ROOT/include");
379 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
380 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
381 gSystem->GetIncludePath());
383 ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries: FAILED");
388 //______________________________________________________________________________
389 Bool_t LoadAnalysisLibraries()
391 // Load common analysis libraries.
392 if (useTender || doCDBconnect) {
393 if (!LoadLibrary("TENDER") ||
394 !LoadLibrary("TENDERSupplies")) return kFALSE;
397 if (doCDBconnect && !useTender) {
398 if (!LoadLibrary("PWGPP")) return kFALSE;
401 if (iESDfilter || iPWGMuonTrain) {
402 if (!LoadLibrary("PWGmuon")) return kFALSE;
406 if (!LoadLibrary("JETAN")) return kFALSE;
409 if (!LoadLibrary("JETAN") ||
410 !LoadLibrary("CGAL") ||
411 !LoadLibrary("fastjet") ||
412 !LoadLibrary("siscone") ||
413 !LoadLibrary("SISConePlugin") ||
414 !LoadLibrary("FASTJETAN")) return kFALSE;
418 //if (!LoadLibrary("PWGLFforward", mode, kTRUE)) return kFALSE;
419 if (!LoadLibrary("PWGLFforward2")) return kFALSE;
423 if (iPWGHFvertexing || iPWGHFd2h) {
424 if (!LoadLibrary("PWGflowBase") ||
425 !LoadLibrary("PWGflowTasks") ||
426 !LoadLibrary("PWGTRD") ||
427 !LoadLibrary("PWGHFvertexingHF")) return kFALSE;
429 // if (iPWGHFvertexing || iPWG3d2h) {
430 // if (!LoadLibrary("PWG3base") ||
431 // !LoadLibrary("PWGHFvertexingHF")) return kFALSE;
434 if (iPWGDQJPSIfilter) {
435 if (!LoadLibrary("PWGDQdielectron")) return kFALSE;
438 ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
442 //______________________________________________________________________________
443 Bool_t LoadLibrary(const char *module)
445 // Load a module library in a given mode. Reports success.
449 ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
452 // If a library is specified, just load it
453 if (mod.EndsWith(".so")) {
454 mod.Remove(mod.Index(".so"));
455 result = gSystem->Load(mod);
457 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
462 // Check if the library is already loaded
463 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0) return kTRUE;
464 result = gSystem->Load(Form("lib%s.so", module));
466 ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
473 //______________________________________________________________________________
474 TChain *CreateChain()
476 // Create the input chain
477 chain = new TChain("esdTree");
478 if (gSystem->AccessPathName("AliESDs.root"))
479 ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
481 chain->Add("AliESDs.root");
482 if (chain->GetNtrees()) return chain;
486 //______________________________________________________________________________
489 // Merging method. No staging and no terminate phase.
492 TString outputDir = "wn.xml";
493 TString outputFiles = "EventStat_temp.root,AODQA.root,AliAOD.root,AliAOD.VertexingHF.root,FilterEvents_Trees.root,AliAOD.Muons.root,AliAOD.Jets.root";
494 TString mergeExcludes = "";
495 TObjArray *list = outputFiles.Tokenize(",");
496 TIter *iter = new TIter(list);
499 Bool_t merged = kTRUE;
500 while((str=(TObjString*)iter->Next())) {
501 outputFile = str->GetString();
502 // Skip already merged outputs
503 if (!gSystem->AccessPathName(outputFile)) {
504 printf("Output file <%s> found. Not merging again.",outputFile.Data());
507 if (mergeExcludes.Contains(outputFile.Data())) continue;
508 merged = AliAnalysisAlien::MergeOutput(outputFile, outputDir, 10, 0);
510 printf("ERROR: Cannot merge %s\n", outputFile.Data());
514 // all outputs merged, validate
516 out.open("outputs_valid", ios::out);