]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/FlavourJetTasks/macros/AnalysisTrainCorrJetsLocal.C
Updates from Chiara
[u/mrichter/AliRoot.git] / PWGJE / FlavourJetTasks / macros / AnalysisTrainCorrJetsLocal.C
1 // runEMCalJetAnalysis.C
2 // =====================
3 // This macro can be used to run a jet analysis within the EMCal Jet Framework.
4 //
5 // Examples:
6 // -> Analyze ESDs from the pA pilot run on the AliEn grid with your task in AnaClass.cxx/.h
7 //     dataType = "ESD", useGrid = kTRUE, pattern = "*ESDs/pass2/*ESDs.root", addCXXs = "AnaClass.cxx", 
8 //     addHs = "AnaClass.h", gridDir = "/alice/data/2012/LHC12g", gridMode = "full", runNumbers = "188359 188362"
9 //     
10 // -> Analyze AODs (up to 96 files) locally given in files_aod.txt
11 //     dataType = "AOD", useGrid = kFALSE, numLocalFiles = 96
12 //
13 // MERGING ON ALIEN
14 // ++++++++++++++++
15 // If you run on the grid, you can monitor the jobs with alimonitor.cern.ch. When enough of them are in DONE state,
16 // you have to merge the output. This can be done automatically, if you just change the gridMode to "terminate" and
17 // give the EXACT name of the task whose output should be merged in uniqueName.
18 // 
19 //
20 // Authors: R. Haake, S. Aiola
21
22 #include <ctime>
23 #include "TGrid.h"
24
25 AliAnalysisGrid* CreateAlienHandler(const char* uniqueName, const char* gridDir, const char* gridMode, const char* runNumbers, const Int_t nrunspermaster, 
26                                      const char* pattern, TString additionalCode, TString additionalHeaders, Int_t maxFilesPerWorker, 
27                                      Int_t workerTTL, Bool_t isMC);
28                                     
29 //______________________________________________________________________________
30 void AnalysisTrainCorrJetsLocal (
31          const char*    dataType            = "AOD",                       // set the analysis type, AOD, ESD or sESD
32          Bool_t         useGrid             = kTRUE,                      // local or grid
33          TString localfilename = "file_aodlhc10d.txt",
34          const char*    gridMode            = "test",                      // set the grid run mode (can be "full", "test", "offline", "submit" or "terminate")
35          const char*    pattern             = "*ESDs/pass2/AOD135/*AliAOD.root", //"*/*/AliAOD.root" "*ESDs/pass1/AOD106/*AliAOD.root",    // file pattern (here one can specify subdirs like passX etc.) (used on grid)
36          const char*    gridDir             = "/alice/data/2010/LHC10d",   // /alice/data/2011/LHC11d /alice/sim/2012/LHC12f2b   dir on alien, where the files live (used on grid)
37          const char*    runNumbers          = /*126437*/" 126432 126425 126424 126422 126409 126408 126407 126406 126405 126404 126403 126359 126352 126351 126350 126285 126284 126283 126168 126167 126160 126158 126097 126090 126088 126082 126081 126078 126073 126008 126007 126004 125855 125851 125850 125849 125848 125847 125844 125843 125842 125633 125632 125630 125296 125134 125101 125100 125097 125085 125023 124751 122375 122374",             // considered run numbers (used on grid) /*LHC12g 188359 188362, LHC11a 146860 146859*/ /*LHC12f2b 158285 159582 */
38          const Int_t nrunspermaster= 100,
39          UInt_t         numLocalFiles       = 3,                          // number of files analyzed locally  
40          const char*    runPeriod           = "LHC10d",                    // set the run period (used on grid)
41          const char*    uniqueName          = "DJetNewCode",     // sets base string for the name of the task on the grid
42          UInt_t         pSel                = AliVEvent::kAny,             // used event selection for every task except for the analysis tasks
43          Bool_t         useTender           = kFALSE,                      // trigger, if tender task should be used
44          Bool_t         isMC                = kFALSE,                      // trigger, if MC handler should be used
45
46          // Here you have to specify additional code files you want to use but that are not in aliroot
47          const char*    addCXXs             = "AliAnalysisTaskSEDmesonsFilterCJ.cxx AliAnalysisTaskFlavourJetCorrelations.cxx",
48          const char*    addHs               = "AliAnalysisTaskSEDmesonsFilterCJ.h AliAnalysisTaskFlavourJetCorrelations.h",
49
50          // These two settings depend on the dataset and your quotas on the AliEN services
51          Int_t          maxFilesPerWorker   = 20,
52          Int_t          workerTTL           = 86000,
53          Int_t          nfiletestmode       = 1
54          )
55 {
56
57   // Some pre-settings and constants
58
59   enum AlgoType {kKT, kANTIKT};
60   enum JetType  {kFULLJETS, kCHARGEDJETS, kNEUTRALJETS};
61   gSystem->SetFPEMask();
62   gSystem->Setenv("ETRAIN_ROOT", ".");
63   gSystem->Setenv("ETRAIN_PERIOD", runPeriod);
64   // change this objects to strings
65   TString usedData(dataType);
66   TString additionalCXXs(addCXXs);
67   TString additionalHs(addHs);
68   cout << dataType << " analysis chosen" << endl;
69   if (useGrid)  
70   {
71     cout << "-- using AliEn grid.\n";
72     if (usedData == "sESD") 
73     {
74       cout << "Skimmed ESD analysis not available on the grid!" << endl;
75       return;
76     }
77   }
78   else
79     cout << "-- using local analysis.\n";
80   
81
82   // Load necessary libraries
83   LoadLibs();
84
85   // Create analysis manager
86   AliAnalysisManager* mgr = new AliAnalysisManager(uniqueName);
87
88   // Check type of input and create handler for it
89   TString localFiles("-1");
90   if(usedData == "AOD")
91   {
92     localFiles = localfilename;
93     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/train/AddAODHandler.C");
94     AliAODInputHandler* aodH = AddAODHandler();
95   }
96   else if((usedData == "ESD") || (usedData == "sESD"))
97   {
98     if (usedData == "ESD")
99       localFiles = "files_esd.txt";
100     else
101       localFiles = "files_sesd.txt";
102     
103     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/train/AddESDHandler.C");
104     AliESDInputHandler* esdH = AddESDHandler();
105   }
106   else
107   {
108     cout << "Data type not recognized! You have to specify ESD, AOD, or sESD!\n";
109   }
110   
111   if(!useGrid)
112     cout << "Using " << localFiles.Data() << " as input file list.\n";
113
114   gROOT->LoadMacro("AddTasksFlavourJet.C");
115   //List of arguments:
116
117 // const Int_t iCandtype=1 /*0 = D0, 1=Dstar...*/,
118 // const TString sCutFile = "cutsHF/D0toKpiCutsppRecVtxNoPileupRejNoEMCAL.root",
119 // const Double_t dJetPtCut   = 1.,
120 // const Double_t dJetAreaCut = 0.,
121 // const Int_t iAccCut = 1,
122 // const TString sRunPeriod = "LHC10b",
123 // const Int_t    uBeamType   = 0,
124 // const UInt_t uTriggerMask = AliVEvent::kMB, /*for jets and phys sel; the D mesons trigger is defined in the cut object*/
125 // const Bool_t bIsMC=kFALSE,
126 // TString sText=""/*completes the name of the candidate task lists*/
127
128   AddTasksFlavourJet(1,"/data/Work/jets/testEMCalJetFramework/CutFilesMB/DStartoKpipiCuts_new.root",10.,0.,1,runPeriod,0,pSel,isMC,"");
129
130   // Set the physics selection for all given tasks
131   TObjArray *toptasks = mgr->GetTasks();
132   for (Int_t i=0; i<toptasks->GetEntries(); ++i) 
133   {
134     AliAnalysisTaskSE *task = dynamic_cast<AliAnalysisTaskSE*>(toptasks->At(i));
135     if (!task)
136       continue;
137     if (task->InheritsFrom("AliPhysicsSelectionTask"))
138       continue;
139     ::Info("setPSel", "Set physics selection for %s (%s)", task->GetName(), task->ClassName());
140     task->SelectCollisionCandidates(pSel);
141   }
142
143   if(gridMode=="full") mgr->SetUseProgressBar(1, 25);
144         
145   if (!mgr->InitAnalysis()) 
146     return;
147   mgr->PrintStatus();
148
149   if (useGrid) 
150   {  // GRID CALCULATION
151
152     AliAnalysisGrid *plugin = CreateAlienHandler(uniqueName, gridDir, gridMode, runNumbers, nrunspermaster, pattern, additionalCXXs, additionalHs, maxFilesPerWorker, workerTTL, isMC);
153     plugin->SetNtestFiles(nfiletestmode); 
154
155     mgr->SetGridHandler(plugin);
156
157     // start analysis
158     cout << "Starting GRID Analysis...";
159     if(gridMode=="test") mgr->SetDebugLevel(10);
160     else mgr->SetDebugLevel(0);
161     mgr->StartAnalysis("grid");
162   }
163   else
164   {  // LOCAL CALCULATION
165
166     TChain* chain = 0;
167     if (usedData == "AOD") 
168     {
169       Printf("Run Create AOD Chain");
170       gROOT->LoadMacro("/data/Work/jets/testEMCalJetFramework/AODchainWithFriend/CreateAODChain.C");
171       chain = CreateAODChain(localFiles.Data(), numLocalFiles,0,kTRUE,kTRUE);
172       //Printf("Chain Friend has %d entries", ((TTree*)chain->GetFriend())->GetEntriesFast());
173     }
174     else
175     {  // ESD or skimmed ESD
176       gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/CreateESDChain.C");
177       chain = CreateESDChain(localFiles.Data(), numLocalFiles);
178     }
179     
180     // start analysis
181     cout << "Starting LOCAL Analysis...";
182     mgr->SetDebugLevel(10);
183     mgr->StartAnalysis("local", chain);
184   }
185 }
186
187 //______________________________________________________________________________
188 void LoadLibs()
189 {
190   // Load common libraries (better too many than too few)
191   gSystem->Load("libTree");
192   gSystem->Load("libVMC");
193   gSystem->Load("libGeom");
194   gSystem->Load("libGui");
195   gSystem->Load("libXMLParser");
196   gSystem->Load("libMinuit");
197   gSystem->Load("libMinuit2");
198   gSystem->Load("libProof");
199   gSystem->Load("libPhysics");
200   gSystem->Load("libSTEERBase");
201   gSystem->Load("libESD");
202   gSystem->Load("libAOD");
203   gSystem->Load("libOADB");
204   gSystem->Load("libANALYSIS");
205   gSystem->Load("libCDB");
206   gSystem->Load("libRAWDatabase");
207   gSystem->Load("libSTEER");
208   gSystem->Load("libEVGEN");
209   gSystem->Load("libANALYSISalice");
210   gSystem->Load("libCORRFW");
211   gSystem->Load("libTOFbase");
212   //gSystem->Load("libTOFrec");
213   gSystem->Load("libRAWDatabase.so");
214   gSystem->Load("libRAWDatarec.so");
215   gSystem->Load("libTPCbase.so");
216   gSystem->Load("libTPCrec.so");
217   gSystem->Load("libITSbase.so");
218   gSystem->Load("libITSrec.so");
219   gSystem->Load("libTRDbase.so");
220   gSystem->Load("libTENDER.so");
221   gSystem->Load("libSTAT.so");
222   gSystem->Load("libTRDrec.so");
223   gSystem->Load("libHMPIDbase.so");
224   gSystem->Load("libPWGPP.so");
225   gSystem->Load("libPWGHFbase");
226   gSystem->Load("libPWGDQdielectron");
227   gSystem->Load("libPWGHFhfe");
228   gSystem->Load("libPWGflowBase.so");
229   gSystem->Load("libPWGflowTasks.so");
230   gSystem->Load("libPWGHFvertexingHF");
231   gSystem->Load("libEMCALUtils");
232   gSystem->Load("libPHOSUtils");
233   gSystem->Load("libPWGCaloTrackCorrBase");
234   gSystem->Load("libEMCALraw");
235   gSystem->Load("libEMCALbase");
236   gSystem->Load("libEMCALrec");
237   gSystem->Load("libTRDbase");
238   gSystem->Load("libVZERObase");
239   gSystem->Load("libVZEROrec");
240   gSystem->Load("libTENDER");
241   gSystem->Load("libTENDERSupplies");
242   gSystem->Load("libPWGEMCAL");
243   gSystem->Load("libPWGGAEMCALTasks");
244   gSystem->Load("libPWGTools");
245   gSystem->Load("libPWGCFCorrelationsBase");
246   gSystem->Load("libPWGCFCorrelationsDPhi");
247
248   //load CGAL, Fastjet and SISCone
249   //gSystem->Load("libCGAL");
250   gSystem->Load("libfastjet");
251   gSystem->Load("libSISConePlugin");
252
253   gSystem->Load("libJETAN");
254   gSystem->Load("libFASTJETAN");
255   gSystem->Load("libPWGJEEMCALJetTasks");
256
257
258   // include paths
259   gSystem->AddIncludePath("-Wno-deprecated");
260   gSystem->AddIncludePath("-I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/EMCAL -I$ALICE_ROOT/PWG/EMCAL -I$ALICE_ROOT/PWGJE/EMCALJetTasks");
261   gSystem->AddIncludePath("-I$ALICE_ROOT/PWGDQ/dielectron -I$ALICE_ROOT/PWGHF/hfe");
262   gSystem->AddIncludePath("-I$ALICE_ROOT/JETAN -I$ALICE_ROOT/JETAN/fastjet");
263 }
264
265 AliAnalysisGrid* CreateAlienHandler(const char* uniqueName, const char* gridDir, const char* gridMode, const char* runNumbers, const Int_t nrunspermaster,
266                                      const char* pattern, TString additionalCode, TString additionalHeaders, Int_t maxFilesPerWorker, 
267                                      Int_t workerTTL, Bool_t isMC)
268 {
269   TDatime currentTime;
270   TString tmpName(uniqueName);
271   /*
272   // Only add current date and time when not in terminate mode! In this case the exact name has to be supplied by the user
273   if(strcmp(gridMode, "terminate"))
274   {
275     tmpName += "_";
276     tmpName += currentTime.GetDate();
277     tmpName += "_";
278     tmpName += currentTime.GetTime();
279   }else tmpName +="_20130412_122423";
280   */
281   TString tmpAdditionalLibs("");
282   tmpAdditionalLibs = Form("libTree.so libVMC.so libGeom.so libGui.so libXMLParser.so libMinuit.so libMinuit2.so libProof.so libPhysics.so libSTEERBase.so libESD.so libAOD.so libOADB.so libANALYSIS.so libCDB.so libRAWDatabase.so libSTEER.so libANALYSISalice.so libCORRFW.so libTOFbase.so libRAWDatabase.so libRAWDatarec.so libTPCbase.so libTPCrec.so libITSbase.so libITSrec.so libTRDbase.so libTENDER.so libSTAT.so libTRDrec.so libHMPIDbase.so libPWGPP.so libPWGHFbase.so libPWGDQdielectron.so libPWGHFhfe.so libPWGflowBase.so libPWGflowTasks.so libPWGHFvertexingHF.so libEMCALUtils.so libPHOSUtils.so libPWGCaloTrackCorrBase.so libEMCALraw.so libEMCALbase.so libEMCALrec.so libTRDbase.so libVZERObase.so libVZEROrec.so libTENDER.so libTENDERSupplies.so libPWGEMCAL.so libPWGGAEMCALTasks.so libPWGTools.so libPWGCFCorrelationsBase.so libPWGCFCorrelationsDPhi.so  libCGAL.so libJETAN.so libfastjet.so libSISConePlugin.so libFASTJETAN.so libPWGJE.so libPWGmuon.so libPWGJEEMCALJetTasks.so %s %s",additionalCode.Data(),additionalHeaders.Data());
283
284
285   TString macroName("");
286   TString execName("");
287   TString jdlName("");
288   macroName = Form("%s.C", tmpName.Data());
289   execName = Form("%s.sh", tmpName.Data());
290   jdlName = Form("%s.jdl", tmpName.Data());
291
292   AliAnalysisAlien *plugin = new AliAnalysisAlien();
293   plugin->SetOverwriteMode();
294   plugin->SetRunMode(gridMode);
295
296   // Here you can set the (Ali)ROOT version you want to use
297   plugin->SetAPIVersion("V1.1x");
298   plugin->SetROOTVersion("v5-34-05");
299   plugin->SetAliROOTVersion("v5-04-38-AN");
300
301   plugin->SetGridDataDir(gridDir); // e.g. "/alice/sim/LHC10a6"
302   plugin->SetDataPattern(pattern); //dir structure in run directory
303   plugin->SetFriendChainName("./AliAOD.VertexingHF.root");
304   if (!isMC)
305    plugin->SetRunPrefix("000");
306
307   plugin->AddRunList(runNumbers);
308   plugin->SetNrunsPerMaster(nrunspermaster);
309
310   plugin->SetGridWorkingDir(Form("%s",tmpName.Data()));
311   plugin->SetGridOutputDir("output"); 
312
313   plugin->SetAnalysisSource(additionalCode.Data());
314   plugin->SetAdditionalLibs(tmpAdditionalLibs.Data());
315   plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/STEER/STEERBase -I$ALICE_ROOT/STEER/ESD -I$ALICE_ROOT/STEER/AOD -I$ALICE_ROOT/ANALYSIS  -I$ALICE_ROOT/OADB -I$ALICE_ROOT/PWGHF -I$ALICE_ROOT/PWGHF/base -I$ALICE_ROOT/PWGHF/vertexingHF -I$ALICE_ROOT/PWG/FLOW/Base -I$ALICE_ROOT/PWG/FLOW/Tasks  -I$ALICE_ROOT/PWGJE  -I$ALICE_ROOT/JETAN -I$ALICE_ROOT/PWGJE/EMCALJetTasks -g");
316   plugin->AddExternalPackage("boost::v1_43_0");
317   plugin->AddExternalPackage("cgal::v3.6");
318   plugin->AddExternalPackage("fastjet::v2.4.2");
319
320   plugin->SetDefaultOutputs(kTRUE);
321   // merging via jdl
322   plugin->SetMergeViaJDL(kTRUE);
323   plugin->SetOneStageMerging(kFALSE);
324   plugin->SetMaxMergeStages(2);
325
326   //plugin->SetMergeExcludes("");
327   plugin->SetAnalysisMacro(macroName.Data());
328   plugin->SetSplitMaxInputFileNumber(maxFilesPerWorker);
329   plugin->SetExecutable(execName.Data());
330   plugin->SetTTL(workerTTL);
331   plugin->SetInputFormat("xml-single");
332   plugin->SetJDLName(jdlName.Data());
333   plugin->SetPrice(1);      
334   plugin->SetSplitMode("se");
335
336   return plugin;
337 }