AliPhysics  608b256 (608b256)
RunAnalysisAODVertexingHF.C
Go to the documentation of this file.
1 class AliAnalysisGrid;
2 class AliAnalysisAlien;
3 
5 {
6  //
7  // Test macro for AliAnalysisTaskSE's for heavy-flavour candidates
8  // It has the structure of a Analysis Train:
9  // - in this macro, change things related to running mode
10  // and input preparation
11  // - add your task using a AddTaskXXX macro
12  //
13  // A.Dainese, andrea.dainese@lnl.infn.it
14  // "grid" mode added by R.Bala, bala@to.infn.it
15  //
16 
17 
18  gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_PHYSICS -I$ALICE_PHYSICS/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/STEER/STEERBase -I$ALICE_ROOT/STEER/ESD -I$ALICE_ROOT/STEER/AOD -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -I$ALICE_PHYSICS/OADB -I$ALICE_PHYSICS/PWGHF -I$ALICE_PHYSICS/PWGHF/base -I$ALICE_PHYSICS/PWGHF/vertexingHF -I$ALICE_PHYSICS/PWG/FLOW/Base -I$ALICE_PHYSICS/PWG/FLOW/Tasks -I$ALICE_PHYSICS/PWG -g");
19  //
20  TString trainName = "D2H";
21  TString analysisMode = "grid"; // "local", "grid", or "proof"
22  TString inputMode = "list"; // "list", "xml", or "dataset"
23  Long64_t nentries=123567890,firstentry=0;
24  Bool_t useParFiles=kFALSE;
25  Bool_t useAlienPlugin=kTRUE;
26  TString pluginmode="full";
27  TString testfileslistWithPlugin="";
28  Bool_t saveProofToAlien=kFALSE;
29  TString proofOutdir = "";
30  TString loadMacroPath="$ALICE_PHYSICS/PWGHF/vertexingHF/macros/";
31  //TString loadMacroPath="./"; // this is normally needed for CAF
32  //
33 
34  if(analysisMode=="grid") {
35  // Connect to AliEn
36  TGrid::Connect("alien://");
37  } else if(analysisMode=="proof") {
38  // Connect to the PROOF cluster
39  if(inputMode!="dataset") {printf("Input mode must be dataset, for proof analysis\n"); return;}
40  gEnv->SetValue("XSec.GSI.DelegProxy","2");
41  TProof::Open("alicecaf");
42  //TProof::Reset("alicecaf");
43  if(saveProofToAlien) {
44  TGrid::Connect("alien://");
45  if(gGrid) {
46  TString homedir = gGrid->GetHomeDirectory();
47  TString workdir = homedir + trainName;
48  if(!gGrid->Cd(workdir)) {
49  gGrid->Cd(homedir);
50  if(gGrid->Mkdir(workdir)) {
51  gGrid->Cd(trainName);
52  ::Info("VertexingTrain::Connect()", "Directory %s created", gGrid->Pwd());
53  }
54  }
55  gGrid->Mkdir("proof_output");
56  gGrid->Cd("proof_output");
57  proofOutdir = Form("alien://%s", gGrid->Pwd());
58  }
59  }
60  }
61 
62 
63  // AliRoot libraries
64  if(analysisMode=="local" || analysisMode=="grid") {
65  TString loadLibraries="LoadLibraries.C"; loadLibraries.Prepend(loadMacroPath.Data());
66  gROOT->LoadMacro(loadLibraries.Data());
67  LoadLibraries(useParFiles);
68  gSystem->Load("libGui");
69  gSystem->Load("libRAWDatabase");
70  gSystem->Load("libCDB");
71  gSystem->Load("libSTEER");
72  gSystem->Load("libTRDbase");
73  gSystem->Load("libPWGTRD");
74  } else if (analysisMode=="proof") {
75  gSystem->Load("libTree");
76  gSystem->Load("libGeom");
77  gSystem->Load("libPhysics");
78  gSystem->Load("libVMC");
79  gSystem->Load("libMinuit");
80  gSystem->Load("libGui");
81  gSystem->Load("libRAWDatabase");
82  gSystem->Load("libCDB");
83  gSystem->Load("libSTEER");
84  gSystem->Load("libTRDbase");
85  gSystem->Load("libPWGTRD");
86  // Enable the needed packages
87  //gProof->ClearPackages();
88  TString parDir="/afs/cern.ch/user/d/dainesea/code/";
89  TString parFile;
90  if(!useParFiles) {
91  gProof->UploadPackage("AF-v4-17");
92  gProof->EnablePackage("AF-v4-17");
93  // --- Enable the PWGHFvertexingHF Package
94  parFile="PWGHFvertexingHF.par"; parFile.Prepend(parDir.Data());
95  gProof->UploadPackage(parFile.Data());
96  gProof->EnablePackage("PWGHFvertexingHF");
97  } else {
98  // --- Enable the STEERBase Package
99  parFile="STEERBase.par"; parFile.Prepend(parDir.Data());
100  gProof->UploadPackage(parFile.Data());
101  gProof->EnablePackage("STEERBase");
102  // --- Enable the ESD Package
103  parFile="ESD.par"; parFile.Prepend(parDir.Data());
104  gProof->UploadPackage(parFile.Data());
105  gProof->EnablePackage("ESD");
106  // --- Enable the AOD Package
107  parFile="AOD.par"; parFile.Prepend(parDir.Data());
108  gProof->UploadPackage(parFile.Data());
109  gProof->EnablePackage("AOD");
110  // --- Enable the ANALYSIS Package
111  parFile="ANALYSIS.par"; parFile.Prepend(parDir.Data());
112  gProof->UploadPackage(parFile.Data());
113  gProof->EnablePackage("ANALYSIS");
114  // --- Enable the ANALYSISalice Package
115  parFile="ANALYSISalice.par"; parFile.Prepend(parDir.Data());
116  gProof->UploadPackage(parFile.Data());
117  gProof->EnablePackage("ANALYSISalice");
118  // --- Enable the CORRFW Package
119  parFile="CORRFW.par"; parFile.Prepend(parDir.Data());
120  gProof->UploadPackage(parFile.Data());
121  gProof->EnablePackage("CORRFW");
122  // --- Enable the PWGHFbase Package
123  parFile="PWGHFbase.par"; parFile.Prepend(parDir.Data());
124  gProof->UploadPackage(parFile.Data());
125  gProof->EnablePackage("PWGHFbase");
126  // --- Enable the PWGHFvertexingHF Package
127  parFile="PWGHFvertexingHF.par"; parFile.Prepend(parDir.Data());
128  gProof->UploadPackage(parFile.Data());
129  gProof->EnablePackage("PWGHFvertexingHF");
130  }
131  gProof->ShowEnabledPackages(); // show a list of enabled packages
132  }
133 
134 
135  // Create Alien plugin, if requested
136  if(useAlienPlugin) {
137  // if(analysisMode!="grid") {printf("Analysis mode must be grid, to use alien plugin\n"); return;}
138  AliAnalysisGrid *alienHandler = CreateAlienHandler(pluginmode,useParFiles,testfileslistWithPlugin);
139  if(!alienHandler) return;
140  }
141 
142 
143  //-------------------------------------------------------------------
144  // Prepare input
145  TChain *chainAOD = 0;
146  TString dataset; // for proof
147 
148  if(!useAlienPlugin) {
149  TString makeAODInputChain="../MakeAODInputChain.C"; makeAODInputChain.Prepend(loadMacroPath.Data());
150  if(inputMode=="list") {
151  // Local files
152  gROOT->LoadMacro(makeAODInputChain.Data());
153  chainAOD = MakeAODInputChain();// with this it reads ./AliAOD.root and ./AliAOD.VertexingHF.root
154  //chainAOD = MakeAODInputChain("alien:///alice/cern.ch/user/r/rbala/newtrain/out_lhc08x/180100/",1,1);
155  printf("ENTRIES %d\n",chainAOD->GetEntries());
156  } else if(inputMode=="xml") {
157  // xml
158  gROOT->LoadMacro(makeAODInputChain.Data());
159  chainAOD = MakeAODInputChain("collection_aod.xml","collection_aodHF.xml");
160  } else if(inputMode=="dataset") {
161  // CAF dataset
162  //gProof->ShowDataSets();
163  dataset="/ITS/dainesea/AODVertexingHF_LHC08x_180100";
164  }
165  }
166 
167  // Create the analysis manager
168  AliAnalysisManager *mgr = new AliAnalysisManager("My Manager","My Manager");
169  mgr->SetDebugLevel(10);
170  // Connect plug-in to the analysis manager
171  if(useAlienPlugin) mgr->SetGridHandler(alienHandler);
172 
173  // Input
174  AliAODInputHandler *inputHandler = new AliAODInputHandler("handler","handler for D2H");
175  if(analysisMode=="proof" ) {
176  inputHandler->AddFriend("./AliAOD.VertexingHF.root");
177  //inputHandler->AddFriend("deltas/AliAOD.VertexingHF.root");
178  if(saveProofToAlien) mgr->SetSpecialOutputLocation(proofOutdir);
179  }
180  mgr->SetInputEventHandler(inputHandler);
181  //-------------------------------------------------------------------
182 
183 
184  //-------------------------------------------------------------------
185  // Analysis tasks (wagons of the train)
186  //
187  // First add the task for the PID response setting
188  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
189  AliAnalysisTaskSE *setupTask = AddTaskPIDResponse(kFALSE,kTRUE);
190 
191  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDqa.C");
192  AliAnalysisTaskPIDqa *pidQA = AddTaskPIDqa();
193 
194 
195  TString taskName;
196 
198  /*taskName="../AddD2HTrain.C"; taskName.Prepend(loadMacroPath.Data());
199  gROOT->LoadMacro(taskName.Data());
200  Bool_t readMC=kFALSE;
201  AddD2HTrain(readMC);//,1,0,0,0,0,0,0,0,0,0,0);*/
202 
204 
205  taskName="AddTaskHFQA.C"; taskName.Prepend(loadMacroPath.Data());
206  gROOT->LoadMacro(taskName.Data());
207  AliAnalysisTaskSEHFQA *qaTask = AddTaskHFQA(0,"",kFALSE, kTRUE, 0 , "QApp",kTRUE,kTRUE,kFALSE, kTRUE, kFALSE,kTRUE);
208 
209  /* taskName="AddTaskCompareHF.C"; taskName.Prepend(loadMacroPath.Data());
210  gROOT->LoadMacro(taskName.Data());
211  AliAnalysisTaskSECompareHF *cmpTask = AddTaskCompareHF();
212  */
213  taskName="AddTaskD0Mass.C"; taskName.Prepend(loadMacroPath.Data());
214  gROOT->LoadMacro(taskName.Data());
215  AliAnalysisTaskSED0Mass *d0massTask = AddTaskD0Mass();
216  AliAnalysisTaskSED0Mass *d0massLikeSignTask = AddTaskD0Mass(1);
217  /*
218  taskName="AddTaskDplus.C"; taskName.Prepend(loadMacroPath.Data());
219  gROOT->LoadMacro(taskName.Data());
220  AliAnalysisTaskSEDplus *dplusTask = AddTaskDplus();
221 
222  taskName="AddTaskDs.C"; taskName.Prepend(loadMacroPath.Data());
223  gROOT->LoadMacro(taskName.Data());
224  AliAnalysisTaskSEDs *dsTask = AddTaskDs();
225 
226  //taskName="AddTaskSelectHF.C"; taskName.Prepend(loadMacroPath.Data());
227  //gROOT->LoadMacro(taskName.Data());
228  //AliAnalysisTaskSESelectHF *seleTask = AddTaskSelectHF();
229 
230  taskName="AddTaskBkgLikeSignD0.C"; taskName.Prepend(loadMacroPath.Data());
231  gROOT->LoadMacro(taskName.Data());
232  AliAnalysisTaskSEBkgLikeSignD0 *lsD0Task = AddTaskBkgLikeSignD0();
233 
234  taskName="AddTaskCFMultiVarMultiStep.C"; taskName.Prepend(loadMacroPath.Data());
235  gROOT->LoadMacro(taskName.Data());
236  AliCFHeavyFlavourTaskMultiVarMultiStep *cfmvmsTask = AddTaskCFMultiVarMultiStep();
237 
238 
239  taskName="AddTaskSECharmFraction.C";
240  taskName.Prepend(loadMacroPath.Data());
241  gROOT->LoadMacro(taskName.Data());
242  Int_t switchMC[5]={0,0,0,0,0};
243  Int_t ppPbPb=1;// 0 for pp, 1 for PbPb, used to siwtch on/off the removal of daughters from the primary vertex
244  AliAnalysisTaskSECharmFraction *cFractTask = AddTaskSECharmFraction("standard",switchMC,readMC,kTRUE,kFALSE,"D0toKpiCharmFractCuts.root","c",ppPbPb);
245  // arguments: filename,switchMC,readmc,usepid,likesign,cutfilename,containerprefix
246 
247 
248  // attach a private task (not committed)
249  // (the files MyTask.h MyTask.cxx AddMyTask.C have to be declared in plugin
250  // configuration, see below)
251 
252  if(analysisMode.Data()=="proof") {
253  gProof->LoadMacro("MyTask.cxx++g");
254  } else {
255  gROOT->LoadMacro("MyTask.cxx++g");
256  }
257  gROOT->LoadMacro("AddMyTask.C");
258  MyTask *myTask = AddMyTask();
259 
260 
261  if(analysisMode.Data()=="proof") {
262  gProof->LoadMacro("AliDStarJets.cxx++g");
263  } else {
264  gROOT->LoadMacro("AliDStarJets.cxx++g");
265  }
266  gROOT->LoadMacro("AddTaskDStarJets.C");
267  AliDStarJets *myTask = AddTaskDStarJets();
268  */
269  //-------------------------------------------------------------------
270 
271  //
272  // Run the analysis
273  //
274  if(chainAOD) printf("CHAIN HAS %d ENTRIES\n",(Int_t)chainAOD->GetEntries());
275 
276  if(!mgr->InitAnalysis()) return;
277  mgr->PrintStatus();
278  if(analysisMode=="grid" && !useAlienPlugin) analysisMode="local";
279  if(analysisMode!="proof") {
280  mgr->StartAnalysis(analysisMode.Data(),chainAOD,nentries,firstentry);
281  } else {
282  // proof
283  mgr->StartAnalysis(analysisMode.Data(),dataset.Data(),nentries,firstentry);
284  }
285 
286  return;
287 }
288 //_____________________________________________________________________________
289 //
290 AliAnalysisGrid* CreateAlienHandler(TString pluginmode="test",Bool_t useParFiles=kFALSE, TString testfileslistWithPlugin="")
291 {
292  // Check if user has a valid token, otherwise make one. This has limitations.
293  // One can always follow the standard procedure of calling alien-token-init then
294  // source /tmp/gclient_env_$UID in the current shell.
295  AliAnalysisAlien *plugin = new AliAnalysisAlien();
296  // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
297  plugin->SetRunMode(pluginmode.Data());
298  plugin->SetUser();
299  // Set versions of used packages
300  plugin->SetAPIVersion("V1.1x");
301  plugin->SetROOTVersion();
302  plugin->SetAliROOTVersion();
303  plugin->SetNtestFiles(1);
304  gROOT->LoadMacro("$ALICE_PHYSICS/PWGHF/vertexingHF/AddGoodRuns.C");
305 
306  // Declare input data to be processed.
307  //************************************************
308  // Set data file list to test on local mode
309  //************************************************
310  plugin->SetFileForTestMode(testfileslistWithPlugin.Data());
311 
312  //************************************************
313  // Set data search pattern for DATA
314  //************************************************
315  //Method 1: To create automatically xml through plugin
316  plugin->SetGridDataDir("/alice/data/2010/LHC10d"); // specify LHC period
317  plugin->SetDataPattern("pass2/AOD018/*AliAOD.root"); // specify reco pass and AOD set
318  plugin->SetFriendChainName("./AliAOD.VertexingHF.root");
319  // OR plugin->SetFriendChainName("deltas/AliAOD.VertexingHF.root");
320  // Adds only the good runs from the Monalisa Run Condition Table
321  // More than one period can be added but the period name has to be removed from GridDataDir (to be tested)
322  Int_t totruns=0;
323  //totruns += AddGoodRuns(plugin,"LHC10b"); // specify LHC period
324  //totruns += AddGoodRuns(plugin,"LHC10c"); // specify LHC period
325  totruns += AddGoodRuns(plugin,"LHC10d"); // specify LHC period
326  plugin->SetNrunsPerMaster(totruns);
327 
328  // Method 2: Declare existing data files (e.g xml collections)
329 
330  //plugin->AddDataFile("/alice/cern.ch/user/r/rbala/000168068_000170593.xml");
331  // plugin->SetDataPattern("*AliAOD.root");
332  // plugin->SetFriendChainName("./AliAOD.VertexingHF.root");
333 
334  //************************************************
335  // Set data search pattern for MONTECARLO
336  //************************************************
337  /*
338  plugin->SetGridDataDir("/alice/sim/LHC10d3"); // specify MC sample
339  plugin->SetDataPattern("AOD005/*AliAOD.root"); // specify AOD set
340  plugin->SetFriendChainName("./AliAOD.VertexingHF.root");
341  // OR plugin->SetFriendChainName("deltas/AliAOD.VertexingHF.root");
342  // Adds only the good runs from the Monalisa Run Condition Table
343  // More than one period can be added!
344  Int_t totruns=0;
345  totruns += AddGoodRuns(plugin,"LHC10b","LHC10d3"); // specify LHC period for anchor runs; and the name of the MC production
346  //totruns += AddGoodRuns(plugin,"LHC10c","LHC10f7"); // specify LHC period for anchor runs; and the name of the MC production
347  //totruns += AddGoodRuns(plugin,"LHC10d","LHC10f7"); // specify LHC period for anchor runs; and the name of the MC production
348  plugin->SetNrunsPerMaster(totruns);
349  */
350  //
351  // Define alien work directory where all files will be copied. Relative to alien $HOME.
352  plugin->SetGridWorkingDir("myHFanalysis");
353  // Name of executable
354  plugin->SetExecutable("myHFanalysis.sh");
355  // Declare alien output directory. Relative to working directory.
356  plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output
357  // Declare the analysis source files names separated by blancs. To be compiled runtime
358  // using ACLiC on the worker nodes.
359  //plugin->SetAnalysisSource("AliDStarJets.cxx");
360  // Declare all libraries (other than the default ones for the framework. These will be
361  // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
362  plugin->SetAdditionalLibs("libPWGflowBase.so libPWGflowTasks.so libPWGHFbase.so libPWGHFvertexingHF.so libGui.so libRAWDatabase.so libCDB.so libSTEER.so libTRDbase.so libPWGTRD.so");
363  // use par files
364  if(useParFiles) {
365  plugin->EnablePackage("STEERBase.par");
366  plugin->EnablePackage("ESD.par");
367  plugin->EnablePackage("AOD.par");
368  plugin->EnablePackage("ANALYSIS.par");
369  plugin->EnablePackage("OADB.par");
370  plugin->EnablePackage("ANALYSISalice.par");
371  plugin->EnablePackage("CORRFW.par");
372  plugin->EnablePackage("PWGHFbase.par");
373  plugin->EnablePackage("PWGHFvertexingHF.par");
374  }
375  plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_PHYSICS -I$ALICE_PHYSICS/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/STEER/STEERBase -I$ALICE_ROOT/STEER/ESD -I$ALICE_ROOT/STEER/AOD -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -I$ALICE_PHYSICS/OADB -I$ALICE_PHYSICS/PWGHF -I$ALICE_PHYSICS/PWGHF/base -I$ALICE_PHYSICS/PWGHF/vertexingHF -I$ALICE_PHYSICS/PWG/FLOW/Base -I$ALICE_PHYSICS/PWG/FLOW/Tasks -I$ALICE_PHYSICS/PWG -g");
376 
377  plugin->SetDefaultOutputs(kTRUE);
378  // merging via jdl
379  plugin->SetMergeViaJDL(kTRUE);
380  plugin->SetOneStageMerging(kFALSE);
381  plugin->SetMaxMergeStages(2);
382 
383  // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
384  plugin->SetAnalysisMacro("AnalysisHF.C");
385  // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
386  // Optionally modify the name of the generated JDL (default analysis.jdl)
387  plugin->SetJDLName("TaskHF.jdl");
388 
389  return plugin;
390 }
AliAnalysisGrid * CreateAlienHandler(TString pluginmode="test", Bool_t useParFiles=kFALSE, TString testfileslistWithPlugin="")
long long Long64_t
Definition: External.C:43
TSystem * gSystem
int Int_t
Definition: External.C:63
AliAnalysisTaskSEHFQA * AddTaskHFQA(AliAnalysisTaskSEHFQA::DecChannel ch, TString filecutsname="", Bool_t readMC=kFALSE, Bool_t simplemode=kFALSE, Int_t system=1, TString finDirname="", Bool_t trackon=kTRUE, Bool_t pidon=kTRUE, Bool_t centralityon=kTRUE, Bool_t eventselon=kTRUE, Bool_t flowobson=kFALSE, Bool_t filldistribforeffcheckson=kFALSE)
Definition: AddTaskHFQA.C:1
void RunAnalysisAODVertexingHF()
AliAnalysisTaskSED0Mass * AddTaskD0Mass(Int_t flag=0, Bool_t readMC=kFALSE, Bool_t filldistr=kFALSE, Bool_t cutOnDistr=kFALSE, Int_t system=0, Int_t flagD0D0bar=0, Float_t minC=0, Float_t maxC=0, TString finDirname="Loose", TString finname="", TString finObjname="D0toKpiCuts", Bool_t flagAOD049=kFALSE, Bool_t FillMassPt=false, Bool_t FillImpPar=false, Bool_t DrawDetSignal=false, Bool_t PIDCheck=false, Bool_t FillMassY=false, Bool_t FillMCAcc=true, Int_t AODProtection=1)
Definition: AddTaskD0Mass.C:1
void LoadLibraries()
TChain * MakeAODInputChain(const char *collectionfileAOD, const char *collectionfileAODfriend, Int_t nfiles=-1, Bool_t stdoutCheck=kFALSE)
bool Bool_t
Definition: External.C:53
Int_t AddGoodRuns(AliAnalysisAlien *plugin, TString lhcPeriod, TString mcprod="")
Definition: AddGoodRuns.C:1