New version of task for prompt charm fraction analysis (A. Rossi)
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / RunAnalysisAODVertexingHF.C
CommitLineData
1a6db1e0 1class AliAnalysisGrid;\r
7cf95461 2TString mySE="ALICE::CNAF::SE";\r
1a6db1e0 3\r
32bb35a1 4void RunAnalysisAODVertexingHF()\r
5{\r
6 //\r
7 // Test macro for AliAnalysisTaskSE's for heavy-flavour candidates\r
8 // It has the structure of a Analysis Train:\r
9 // - in this macro, change things related to running mode\r
10 // and input preparation \r
11 // - add your task using a AddTaskXXX macro \r
12 //\r
13 // A.Dainese, andrea.dainese@lnl.infn.it\r
14 // "grid" mode added by R.Bala, bala@to.infn.it\r
15 //\r
16\r
7cf95461 17 gSystem->Setenv("alien_CLOSE_SE",mySE.Data());\r
18\r
d2a0f79f 19 gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -I$ALICE_ROOT/PWG3 -I$ALICE_ROOT/PWG3/vertexingHF -g"); \r
1a6db1e0 20 //\r
6015e14b 21 TString trainName = "Test";\r
75e79c0f 22 TString analysisMode = "grid"; // "local", "grid", or "proof"\r
23 TString inputMode = "list"; // "list", "xml", or "dataset"\r
1a6db1e0 24 Long64_t nentries=1234567890,firstentry=0;\r
aabcfd8f 25 Bool_t useParFiles=kFALSE;\r
75ff3310 26 Bool_t useAlienPlugin=kTRUE;\r
1a02c480 27 TString pluginmode="test";\r
6015e14b 28 Bool_t saveProofToAlien=kFALSE;\r
29 TString proofOutdir = "";\r
1a6db1e0 30 TString loadMacroPath="$ALICE_ROOT/PWG3/vertexingHF/";\r
a73f46fd 31 //TString loadMacroPath="./"; // this is normally needed for CAF\r
1a6db1e0 32 //\r
32bb35a1 33\r
1a6db1e0 34 if(analysisMode=="grid") {\r
35 // Connect to AliEn\r
36 TGrid::Connect("alien://");\r
37 } else if(analysisMode=="proof") {\r
38 // Connect to the PROOF cluster\r
1a02c480 39 if(inputMode!="dataset") {printf("Input mode must be dataset, for proof analysis\n"); return;}\r
75e79c0f 40 gEnv->SetValue("XSec.GSI.DelegProxy","2");\r
1a6db1e0 41 TProof::Open("alicecaf");\r
42 //TProof::Reset("alicecaf");\r
6015e14b 43 if(saveProofToAlien) {\r
44 TGrid::Connect("alien://");\r
45 if(gGrid) {\r
46 TString homedir = gGrid->GetHomeDirectory();\r
47 TString workdir = homedir + trainName;\r
48 if(!gGrid->Cd(workdir)) {\r
49 gGrid->Cd(homedir);\r
50 if(gGrid->Mkdir(workdir)) {\r
51 gGrid->Cd(trainName);\r
52 ::Info("VertexingTrain::Connect()", "Directory %s created", gGrid->Pwd());\r
53 }\r
54 } \r
55 gGrid->Mkdir("proof_output");\r
56 gGrid->Cd("proof_output");\r
57 proofOutdir = Form("alien://%s", gGrid->Pwd());\r
58 } \r
59 }\r
1a6db1e0 60 }\r
32bb35a1 61\r
32bb35a1 62\r
1a6db1e0 63 // AliRoot libraries\r
64 if(analysisMode=="local" || analysisMode=="grid") {\r
65 TString loadLibraries="LoadLibraries.C"; loadLibraries.Prepend(loadMacroPath.Data());\r
66 gROOT->LoadMacro(loadLibraries.Data());\r
67 LoadLibraries(useParFiles);\r
68 } else if (analysisMode=="proof") {\r
69 gSystem->Load("libTree.so");\r
70 gSystem->Load("libGeom.so");\r
71 gSystem->Load("libPhysics.so");\r
72 gSystem->Load("libVMC.so"); \r
73 // Enable the needed packages\r
74 //gProof->ClearPackages();\r
a73f46fd 75 TString parDir="/afs/cern.ch/user/d/dainesea/code/";\r
76 TString parFile;\r
1a6db1e0 77 if(!useParFiles) {\r
75e79c0f 78 gProof->UploadPackage("AF-v4-17");\r
79 gProof->EnablePackage("AF-v4-17");\r
a73f46fd 80 // --- Enable the PWG3vertexingHF Package\r
81 parFile="PWG3vertexingHF.par"; parFile.Prepend(parDir.Data());\r
82 gProof->UploadPackage(parFile.Data());\r
83 gProof->EnablePackage("PWG3vertexingHF");\r
1a6db1e0 84 } else {\r
1a6db1e0 85 // --- Enable the STEERBase Package\r
86 parFile="STEERBase.par"; parFile.Prepend(parDir.Data());\r
87 gProof->UploadPackage(parFile.Data());\r
88 gProof->EnablePackage("STEERBase");\r
89 // --- Enable the ESD Package\r
90 parFile="ESD.par"; parFile.Prepend(parDir.Data());\r
91 gProof->UploadPackage(parFile.Data());\r
92 gProof->EnablePackage("ESD");\r
93 // --- Enable the AOD Package\r
94 parFile="AOD.par"; parFile.Prepend(parDir.Data());\r
95 gProof->UploadPackage(parFile.Data());\r
96 gProof->EnablePackage("AOD");\r
97 // --- Enable the ANALYSIS Package\r
98 parFile="ANALYSIS.par"; parFile.Prepend(parDir.Data());\r
99 gProof->UploadPackage(parFile.Data());\r
100 gProof->EnablePackage("ANALYSIS");\r
101 // --- Enable the ANALYSISalice Package\r
102 parFile="ANALYSISalice.par"; parFile.Prepend(parDir.Data());\r
103 gProof->UploadPackage(parFile.Data());\r
104 gProof->EnablePackage("ANALYSISalice");\r
105 // --- Enable the CORRFW Package\r
106 parFile="CORRFW.par"; parFile.Prepend(parDir.Data());\r
107 gProof->UploadPackage(parFile.Data());\r
108 gProof->EnablePackage("CORRFW");\r
b093f071 109 // --- Enable the PWG3base Package\r
110 parFile="PWG3base.par"; parFile.Prepend(parDir.Data());\r
111 gProof->UploadPackage(parFile.Data());\r
112 gProof->EnablePackage("PWG3base");\r
1a6db1e0 113 // --- Enable the PWG3vertexingHF Package\r
114 parFile="PWG3vertexingHF.par"; parFile.Prepend(parDir.Data());\r
115 gProof->UploadPackage(parFile.Data());\r
116 gProof->EnablePackage("PWG3vertexingHF");\r
b093f071 117 // --- Enable the JETAN Package\r
118 parFile="JETAN.par"; parFile.Prepend(parDir.Data());\r
119 gProof->UploadPackage(parFile.Data());\r
120 gProof->EnablePackage("JETAN");\r
121 // --- Enable the PWG3muon Package\r
122 parFile="PWG3muon.par"; parFile.Prepend(parDir.Data());\r
123 gProof->UploadPackage(parFile.Data());\r
124 gProof->EnablePackage("PWG3muon");\r
125 // --- Enable the PWG4PartCorrBase Package\r
126 parFile="PWG4PartCorrBase.par"; parFile.Prepend(parDir.Data());\r
127 gProof->UploadPackage(parFile.Data());\r
128 gProof->EnablePackage("PWG4PartCorrBase");\r
129 // --- Enable the PWG4PartCorrDep Package\r
130 parFile="PWG4PartCorrDep.par"; parFile.Prepend(parDir.Data());\r
131 gProof->UploadPackage(parFile.Data());\r
132 gProof->EnablePackage("PWG4PartCorrDep");\r
1a6db1e0 133 }\r
134 gProof->ShowEnabledPackages(); // show a list of enabled packages\r
135 }\r
32bb35a1 136\r
137\r
1a6db1e0 138 // Create Alien plugin, if requested\r
139 if(useAlienPlugin) { \r
75e79c0f 140 if(analysisMode!="grid") {printf("Analysis mode must be grid, to use alien plugin\n"); return;}\r
1a6db1e0 141 AliAnalysisGrid *alienHandler = CreateAlienHandler(pluginmode,useParFiles); \r
142 if(!alienHandler) return;\r
143 }\r
32bb35a1 144\r
145\r
146 //-------------------------------------------------------------------\r
75e79c0f 147 // Prepare input\r
32bb35a1 148 TChain *chainAOD = 0;\r
1a6db1e0 149 TString dataset; // for proof\r
150\r
151 if(!useAlienPlugin) {\r
aabcfd8f 152 TString makeAODInputChain="MakeAODInputChain.C"; makeAODInputChain.Prepend(loadMacroPath.Data());\r
1a6db1e0 153 if(inputMode=="list") {\r
154 // Local files\r
75e79c0f 155 gROOT->LoadMacro(makeAODInputChain.Data());\r
1a6db1e0 156 chainAOD = MakeAODInputChain();// with this it reads ./AliAOD.root and ./AliAOD.VertexingHF.root\r
aabcfd8f 157 //chainAOD = MakeAODInputChain("alien:///alice/cern.ch/user/r/rbala/newtrain/out_lhc08x/180100/",1,1);\r
1a6db1e0 158 } else if(inputMode=="xml") {\r
159 // xml\r
75e79c0f 160 gROOT->LoadMacro(makeAODInputChain.Data());\r
1a6db1e0 161 chainAOD = MakeAODInputChain("collection_aod.xml","collection_aodHF.xml");\r
162 } else if(inputMode=="dataset") {\r
163 // CAF dataset\r
75e79c0f 164 //gProof->ShowDataSets();\r
165 dataset="/ITS/dainesea/AODVertexingHF_LHC08x_180100";\r
1a6db1e0 166 }\r
32bb35a1 167 }\r
168\r
169 // Create the analysis manager\r
170 AliAnalysisManager *mgr = new AliAnalysisManager("My Manager","My Manager");\r
7cf95461 171 mgr->SetDebugLevel(0);\r
1a6db1e0 172 // Connect plug-in to the analysis manager\r
173 if(useAlienPlugin) mgr->SetGridHandler(alienHandler);\r
174\r
32bb35a1 175 // Input\r
176 AliAODInputHandler *inputHandler = new AliAODInputHandler();\r
6015e14b 177 if(analysisMode=="proof") {\r
178 inputHandler->AddFriend("AliAOD.VertexingHF.root");\r
179 if(saveProofToAlien) mgr->SetSpecialOutputLocation(proofOutdir);\r
180 }\r
32bb35a1 181 mgr->SetInputEventHandler(inputHandler);\r
182 //-------------------------------------------------------------------\r
183\r
184 \r
185 //-------------------------------------------------------------------\r
1a6db1e0 186 // Analysis tasks (wagons of the train) \r
32bb35a1 187 //\r
1a6db1e0 188 TString taskName;\r
189\r
190 taskName="AddTaskCompareHF.C"; taskName.Prepend(loadMacroPath.Data());\r
191 gROOT->LoadMacro(taskName.Data());\r
32bb35a1 192 AliAnalysisTaskSECompareHF *cmpTask = AddTaskCompareHF();\r
f3be8296 193 \r
a273622f 194 taskName="AddTaskD0Mass.C"; taskName.Prepend(loadMacroPath.Data());\r
195 gROOT->LoadMacro(taskName.Data());\r
196 AliAnalysisTaskSED0Mass *d0massTask = AddTaskD0Mass();\r
197\r
198 \r
d486095a 199 taskName="AddTaskDplus.C"; taskName.Prepend(loadMacroPath.Data());\r
200 gROOT->LoadMacro(taskName.Data());\r
201 AliAnalysisTaskSEDplus *dplusTask = AddTaskDplus();\r
81c01455 202 \r
1a6db1e0 203 //taskName="AddTaskSelectHF.C"; taskName.Prepend(loadMacroPath.Data());\r
204 //gROOT->LoadMacro(taskName.Data());\r
205 //AliAnalysisTaskSESelectHF *seleTask = AddTaskSelectHF();\r
a9f684f8 206\r
17e8df02 207 taskName="AddTaskBkgLikeSignD0.C"; taskName.Prepend(loadMacroPath.Data());\r
208 gROOT->LoadMacro(taskName.Data());\r
209 AliAnalysisTaskSEBkgLikeSignD0 *lsD0Task = AddTaskBkgLikeSignD0();\r
210\r
8f6dd855 211 taskName="AddTaskBkgLikeSignJPSI.C"; taskName.Prepend(loadMacroPath.Data());\r
b093f071 212 gROOT->LoadMacro(taskName.Data());\r
17e8df02 213 AliAnalysisTaskSEBkgLikeSignJPSI *lsJPSITask = AddTaskBkgLikeSignJPSI();\r
a9f684f8 214\r
d234e959 215 taskName="AddTaskBtoJPSItoEle.C"; taskName.Prepend(loadMacroPath.Data());\r
216 gROOT->LoadMacro(taskName.Data());\r
217 AliAnalysisTaskSEBtoJPSItoEle *jpsiTask = AddTaskBtoJPSItoEle();\r
a9f684f8 218\r
75ff3310 219 taskName="AddTaskCFMultiVarMultiStep.C"; taskName.Prepend(loadMacroPath.Data());\r
b093f071 220 gROOT->LoadMacro(taskName.Data());\r
09d822de 221 AliCFHeavyFlavourTaskMultiVarMultiStep *cfmvmsTask = AddTaskCFMultiVarMultiStep();\r
a9f684f8 222\r
d234e959 223 taskName="AddTaskCharmFraction.C"; taskName.Prepend(loadMacroPath.Data());\r
224 gROOT->LoadMacro(taskName.Data());\r
624c07ab 225 Int_t switchMC[5]={1,1,1,1,1};\r
226 AliAnalysisTaskSECharmFraction *cFractTask = AddTaskCharmFraction("d0D0.root",switchMC);\r
32bb35a1 227\r
f6cc2d5d 228 // attach a private task (not committed)\r
229 // (the files MyTask.h MyTask.cxx AddMyTask.C have to be declared in plugin\r
230 // configuration, see below)\r
231 /*\r
75e79c0f 232 if(analysisMode.Data()=="proof") {\r
233 gProof->LoadMacro("MyTask.cxx++g");\r
234 } else {\r
235 gROOT->LoadMacro("MyTask.cxx++g");\r
236 }\r
237 gROOT->LoadMacro("AddMyTask.C");\r
238 MyTask *myTask = AddMyTask();\r
f6cc2d5d 239 */\r
624c07ab 240 /*\r
241 if(analysisMode.Data()=="proof") {\r
242 gProof->LoadMacro("AliDStarJets.cxx++g");\r
243 } else {\r
244 gROOT->LoadMacro("AliDStarJets.cxx++g");\r
245 }\r
246 gROOT->LoadMacro("AddTaskDStarJets.C");\r
247 AliDStarJets *myTask = AddTaskDStarJets();\r
248 */\r
32bb35a1 249 //-------------------------------------------------------------------\r
250\r
251 //\r
252 // Run the analysis\r
253 // \r
1a6db1e0 254 if(chainAOD) printf("CHAIN HAS %d ENTRIES\n",(Int_t)chainAOD->GetEntries());\r
255\r
256 if(!mgr->InitAnalysis()) return;\r
257 mgr->PrintStatus();\r
258 if(analysisMode=="grid" && !useAlienPlugin) analysisMode="local";\r
ff395ef6 259 if(analysisMode!="proof") {\r
75e79c0f 260 mgr->StartAnalysis(analysisMode.Data(),chainAOD,nentries,firstentry);\r
261 } else {\r
262 // proof\r
263 mgr->StartAnalysis(analysisMode.Data(),dataset.Data(),nentries,firstentry);\r
264 }\r
32bb35a1 265\r
266 return;\r
267}\r
1a6db1e0 268//_____________________________________________________________________________\r
269//\r
270AliAnalysisGrid* CreateAlienHandler(TString pluginmode="test",Bool_t useParFiles=kFALSE)\r
271{\r
272 // Check if user has a valid token, otherwise make one. This has limitations.\r
273 // One can always follow the standard procedure of calling alien-token-init then\r
274 // source /tmp/gclient_env_$UID in the current shell.\r
275 if (!AliAnalysisGrid::CreateToken()) return NULL;\r
276 AliAnalysisAlien *plugin = new AliAnalysisAlien();\r
277 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")\r
278 plugin->SetRunMode(pluginmode.Data());\r
279 plugin->SetUser("dainesea");\r
280 plugin->SetNtestFiles(1);\r
281 // Set versions of used packages\r
282 plugin->SetAPIVersion("V2.4");\r
e501585f 283 plugin->SetROOTVersion("v5-24-00");\r
7cf95461 284 plugin->SetAliROOTVersion("v4-18-06-AN");\r
1a6db1e0 285 // Declare input data to be processed.\r
286 // Method 1: Create automatically XML collections using alien 'find' command.\r
287 // Define production directory LFN\r
75ff3310 288 //plugin->SetGridDataDir("/alice/cern.ch/user/r/rbala/newtrain/out_lhc08x/");\r
e501585f 289 //plugin->SetGridDataDir("/alice/cern.ch/user/m/mgheata/analysisESD/output_train_default_28May2009_09h33/");\r
7cf95461 290 plugin->SetGridDataDir("/alice/sim/PDC_09/LHC09a5/AOD1/");\r
1a6db1e0 291 // Set data search pattern\r
292 plugin->SetDataPattern("AliAOD.root");\r
293 plugin->SetFriendChainName("AliAOD.VertexingHF.root");\r
294 // ...then add run numbers to be considered\r
e501585f 295 //plugin->AddRunNumber(529007);\r
d234e959 296 // or\r
297 //plugin->SetRunRange(529000,529007);\r
1a6db1e0 298 // Method 2: Declare existing data files (raw collections, xml collections, root file)\r
299 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())\r
300 // XML collections added via this method can be combined with the first method if\r
301 // the content is compatible (using or not tags)\r
302 //plugin->AddDataFile("/alice/cern.ch/user/r/rbala/newtrain/collection/collection_aod_lhc08w.xml");\r
303 // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");\r
304 // Define alien work directory where all files will be copied. Relative to alien $HOME.\r
7cf95461 305 plugin->SetGridWorkingDir("lhc09a5_061009");\r
1a6db1e0 306 // Declare alien output directory. Relative to working directory.\r
307 plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output\r
308 // Declare the analysis source files names separated by blancs. To be compiled runtime\r
309 // using ACLiC on the worker nodes.\r
624c07ab 310 //plugin->SetAnalysisSource("AliDStarJets.cxx");\r
1a6db1e0 311 // Declare all libraries (other than the default ones for the framework. These will be\r
312 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.\r
624c07ab 313 plugin->SetAdditionalLibs("libPWG3vertexingHF.so libPWG3base.so libPWG3muon.so libPWG4PartCorrBase.so libPWG4PartCorrDep.so MakeAODInputChain.C"/* AliDStarJets.cxx AliDStarJets.h"*/);\r
1a6db1e0 314 // use par files\r
315 if(useParFiles) {\r
316 plugin->EnablePackage("STEERBase.par");\r
317 plugin->EnablePackage("ESD.par");\r
318 plugin->EnablePackage("AOD.par");\r
319 plugin->EnablePackage("ANALYSIS.par");\r
320 plugin->EnablePackage("ANALYSISalice.par");\r
321 plugin->EnablePackage("CORRFW.par");\r
75ff3310 322 plugin->EnablePackage("PWG3base.par");\r
1a6db1e0 323 plugin->EnablePackage("PWG3vertexingHF.par");\r
75ff3310 324 plugin->EnablePackage("PWG3muon.par");\r
325 plugin->EnablePackage("PWG4PartCorrBase.par");\r
326 plugin->EnablePackage("PWG4PartCorrDep.par");\r
1a6db1e0 327 }\r
d2a0f79f 328 plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TPC -I$ALICE_ROOT/CONTAINERS -I$ALICE_ROOT/STEER -I$ALICE_ROOT/TRD -I$ALICE_ROOT/macros -I$ALICE_ROOT/ANALYSIS -I$ALICE_ROOT/PWG3 -I$ALICE_ROOT/PWG3/vertexingHF -g");\r
1a6db1e0 329 // Declare the output file names separated by blancs.\r
330 // (can be like: file.root or file.root@ALICE::Niham::File)\r
e501585f 331 plugin->SetDefaultOutputs(kTRUE);\r
332 //plugin->SetOutputFiles("output.root CmpHF.root CmpHFnt.root D0InvMass.root InvMassDplus.root InvMassDplus_nt1.root InvMassDplus_nt2.root");\r
1a6db1e0 333 // Optionally define the files to be archived.\r
334 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:*.root@ALICE::NIHAM::File");\r
335 plugin->SetOutputArchive("log_archive.zip:stdout,stderr");\r
336 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)\r
337 plugin->SetAnalysisMacro("AnalysisHF.C");\r
338 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)\r
339 plugin->SetSplitMaxInputFileNumber(5);\r
340 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.\r
341 //plugin->SetMaxInitFailed(5);\r
342 // Optionally resubmit threshold.\r
343 //plugin->SetMasterResubmitThreshold(90);\r
344 // Optionally set time to live (default 30000 sec)\r
345 //plugin->SetTTL(20000);\r
346 // Optionally set input format (default xml-single)\r
347 plugin->SetInputFormat("xml-single");\r
348 // Optionally modify the name of the generated JDL (default analysis.jdl)\r
349 plugin->SetJDLName("TaskHF.jdl");\r
350 // Optionally modify job price (default 1)\r
351 //plugin->SetPrice(1); \r
352 // Optionally modify split mode (default 'se') \r
353 plugin->SetSplitMode("se");\r
354 // Optionally set the preferred SE \r
7cf95461 355 plugin->SetPreferedSE(mySE.Data());\r
1a6db1e0 356 \r
357 return plugin;\r
358}\r