]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/PilotTrain/PilotAnalysis_sim.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGPP / PilotTrain / PilotAnalysis_sim.C
1 #include "Riostream.h"
2 void LoadLibraries();
3 void AddAnalysisTasks(); 
4 class AliAnalysisAlien;                                                                                                                    
5 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode);
6
7 Int_t runNumbers[5] = {126437};
8
9 Bool_t doQAsym        = 1;   // output ok
10 Bool_t doVZERO        = 1;   // output ok but there is a 2nd file
11 Bool_t doVertex       = 1;   // output ok
12 Bool_t doSPD          = 1;   // output ok, needs RP   
13 Bool_t doTPC          = 1;   // output ok
14 Bool_t doEventStat    = 0;   // output ok
15 Bool_t doSDD          = 1;   // outout ok needs RP
16 Bool_t doSSDdEdx      = 1;   // testing
17 // new 
18 Bool_t doTRD          = 1;   // TRD 
19 Bool_t doITS          = 1;   // ITS
20 Bool_t doCALO         = 1;   // Calorimeter
21 Bool_t doMUONTrig     = 1;   // MUON trigger
22 Bool_t doImpParRes    = 1;   // Impact parameter resolution
23 Bool_t doMUON         = 1;   // MUON QA
24
25 Bool_t doMUONEff      = 0;   // MUON efficiency  NEEDS geometry
26 Bool_t doV0           = 0;   // V0 recosntruction performance NEEDS MCtruth 
27
28 TString     train_name         = "QA";      // QA local folder name
29 TString     train_tag          = "";        // Train special tag appended to 
30                                             // visible name. ("sim", "pp", ...)
31                // Name in train page (DON'T CHANGE)
32 TString     visible_name       = Form("QA$2_$3%s", train_tag.Data()); //# FIXED #
33 TString     job_comment        = "PWGPP QA train"; // Can add observations here
34                // Job tag (DON'T CHANGE)
35 TString     job_tag            = Form("%s: %s", visible_name.Data(), job_comment.Data());
36                // Package versions - Modify as needed
37 TString     root_version       = "v5-27-06-1";
38 TString     aliroot_version    = "v4-20-12-AN";
39                // Production directory - change as needed for test mode
40 TString     grid_datadir       = "/alice/sim/LHC10f7";
41                // Work directory in GRID (DON'T CHANGE)
42 TString     grid_workdir       = "/alice/cern.ch/user/a/alidaq/QA/QA$2";
43                // Job splitting
44 Int_t       grid_split         = 20;       // Splitting
45                // Debug level
46 Int_t       debug_level        = 1;        // Debugging
47                // Data pattern - change as needed for test mode
48 TString     data_pattern       = "*ESDs.root";
49                // Output directory (DON'T CHANGE)
50 TString     alien_outdir       = "$1/QA$2";
51                // Input collection (production mode)
52 TString     data_collection    = "$1/qa1.xml";
53 TString     mergeExcludes      = ""; // Files to be excluded for merging
54 TString     terminateFiles     = "trending.root"; // Files produced during Terminate
55
56 Bool_t useProductionMode       = kTRUE;
57 Bool_t useMergeViaJDL          = kTRUE;
58 Bool_t useFastReadOption       = kTRUE;
59 Bool_t useOverwriteMode        = kFALSE;
60 Bool_t useDevelopmentVersion   = kFALSE;
61
62 void PilotAnalysis(const char *plugin_mode = "full")
63 {
64   TString smode(plugin_mode);
65   smode.ToLower();
66   if (smode == "test") useProductionMode = kFALSE;
67   if (!useProductionMode) {
68      TGrid::Connect("alien://");
69      if (!gGrid || !gGrid->IsConnected()) {
70        ::Error("PilotAnalysis", "No grid connection");
71        return;
72      }
73   }   
74   // Write configuration
75   TString cdir = gSystem->WorkingDirectory();
76   gSystem->MakeDirectory(train_name);
77   gSystem->ChangeDirectory(train_name);
78   ofstream out;
79   out.open(Form("%sConfig.C",train_name.Data()), ios::out);
80   out << "{" << endl;
81   out << "   train_name      = " << "\"" << train_name.Data() << "\";" << endl;
82   out << "   root_version    = " << "\"" << root_version.Data() << "\";" << endl;
83   out << "   aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
84   out << "   grid_datadir   = " << "\"" << grid_datadir.Data() << "\";" << endl;
85   if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
86   out << "   alien_outdir    = " << "\"" << alien_outdir.Data() << "\";" << endl;
87   out << "   doQAsim         = " << doQAsym << ";" << endl;
88   out << "   doVZERO         = " << doVZERO << ";" << endl;
89   out << "   doVertex        = " << doVertex << ";" << endl;
90   out << "   doSPD           = " << doSPD << ";" << endl;
91   out << "   doSDD           = " << doSDD << ";" << endl;
92   out << "   doSSDdEdx       = " << doSSDdEdx << ";" << endl;
93   out << "   doTPC           = " << doTPC << ";" << endl;
94   out << "   doTRD           = " << doTRD << ";" << endl;
95   out << "   doImpParRes     = " << doImpParRes << ";" << endl;
96   out << "   doMUON          = " << doMUON << ";" << endl;
97   out << "   doEventStat     = " << doEventStat << ";" << endl;
98   out << "}" << endl;
99   out.close();
100   
101   // Load libraries
102   gSystem->SetIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
103   LoadLibraries();
104   // Create manager
105   AliAnalysisManager *mgr  = new AliAnalysisManager("PilotAnalysis", "Production train");
106   mgr->SetNSysInfo(100);
107   // Input handler
108   AliESDInputHandlerRP *esdHandler = new AliESDInputHandlerRP();
109   esdHandler->SetReadFriends(kTRUE);
110   esdHandler->SetActiveBranches("ESDfriend");
111   mgr->SetInputEventHandler(esdHandler);
112   mgr->SetDebugLevel(debug_level);
113   mgr->SetSaveCanvases(kFALSE);
114
115   // AnalysisTasks
116   AddAnalysisTasks();
117   // Grid handler
118   AliAnalysisAlien *alienHandler = CreateAlienHandler(plugin_mode);
119   mgr->SetGridHandler(alienHandler);
120   if (mgr->InitAnalysis()) {                                                                                                              
121     mgr->PrintStatus(); 
122     mgr->StartAnalysis("grid");
123   }
124 }
125
126 void LoadLibraries()
127 {
128   gSystem->Load("libANALYSIS");
129   gSystem->Load("libANALYSISalice");
130   gSystem->Load("libCORRFW");
131   gSystem->Load("libTender");
132   gSystem->Load("libPWG0base");
133   gSystem->Load("libPWG0dep");
134   gSystem->Load("libPWG0selectors");
135   gSystem->Load("libPWGPP");
136   gSystem->Load("libPWG2");
137   gSystem->Load("libPWG2forward");
138
139   if (doCALO) {
140      gSystem->Load("libEMCALUtils");
141      gSystem->Load("libPWG4PartCorrBase");
142      gSystem->Load("libPWG4PartCorrDep");
143   }  
144   if(doMUONTrig || doAOD) {
145      gSystem->Load("libPWGHFbase");
146      gSystem->Load("libPWGmuon");
147      gSystem->Load("libPWGmuondep");
148   }   
149 }
150
151 void AddAnalysisTasks()
152 {
153   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
154   mgr->SetCommonFileName("QAresults.root");
155   //
156   // Event Statistics (Jan Fiete)
157   //
158
159   if (doEventStat) {
160       gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
161       AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
162       if (!terminateFiles.IsNull()) terminateFiles += ",";
163       terminateFiles += "event_stat.root";
164   }
165   // Vertexing (A. Dainese)
166   // 
167   if (doVertex) {
168     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskVertexESD.C");
169     AliAnalysisTaskVertexESD* taskvertexesd =  AddTaskVertexESD();
170     taskvertexesd->SelectCollisionCandidates();
171   }  
172
173   // TPC QA (E. Sicking)
174   //
175   if (doQAsym) {
176     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskQAsym.C");
177     AliAnalysisTaskSE * taskqasim = AddTaskQAsym(0);
178     taskqasim->SelectCollisionCandidates();
179   }  
180   //
181   // VZERO QA  (C. Cheshkov)
182   //
183   if (doVZERO) {
184     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskVZEROQA.C");
185     AliAnalysisTaskSE * taskv0qa = AddTaskVZEROQA(0);
186 //  taskv0qa->SelectCollisionCandidates();
187   }
188   //
189   // TPC (Jacek Otwinowski & Michael Knichel)
190   //
191   if (doTPC) {
192     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/TPC/macros/AddTaskPerformanceTPCdEdxQA.C");
193     AliPerformanceTask *tpcQA = AddTaskPerformanceTPCdEdxQA(kFALSE, kTRUE);   
194     tpcQA->SelectCollisionCandidates();
195   }  
196   //
197   // SPD (A. Mastroserio)
198   //
199   if (doSPD) {
200     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskSPDQA.C");
201     AliAnalysisTaskSE* taskspdqa = AddTaskSPDQA();
202     taskspdqa->SelectCollisionCandidates();
203   }  
204   //
205   // SDD (F. Prino)
206   //
207   if (doSDD) {
208     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddSDDPoints.C");
209     AliAnalysisTaskSE* tasksdd = AddSDDPoints();
210     tasksdd->SelectCollisionCandidates();
211   }
212   //
213   // SSD dEdx (Marek Chojnacki)
214   //
215   if (doSSDdEdx) {
216     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskdEdxSSDQA.C");
217     AliAnalysisTaskSE* taskssddedx = AddTaskdEdxSSDQA();
218     taskssddedx->SelectCollisionCandidates();
219   }
220
221   //
222   // ITS
223   //
224   if (doITS) {
225       gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskPerformanceITS.C");
226       AliAnalysisTaskITSTrackingCheck *itsQA = AddTaskPerformanceITS(kFALSE);
227   }
228   //
229   // TRD (Alex Bercuci, M. Fasel) 
230   //
231   if(doTRD) {
232       gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTrainPerformanceTRD.C");
233       // steer individual TRD tasks
234       Bool_t 
235       doCheckESD(kTRUE),  // AliTRDcheckESD
236       doCheckDET(kTRUE),  // AliTRDcheckDET
237       doEffic(kTRUE),     // AliTRDefficiency
238       doResolution(kTRUE),// AliTRDresolution
239       doCheckPID(kTRUE),  // AliTRDcheckPID
240       doV0Monitor(kFALSE);// AliTRDv0Monitor
241       AddTrainPerformanceTRD(Translate(doCheckESD, doCheckDET, doEffic, doResolution, doCheckPID, doV0Monitor));
242   }
243
244   //
245   // Calorimetry (Gustavo Conesa)
246   //
247
248   if(doCALO) {
249       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
250       AliAnalysisTaskParticleCorrelation *taskCaloQA = AddTaskCalorimeterQA("ESD", kTRUE, kFALSE);
251       taskCaloQA->SetDebugLevel(0);
252   }
253
254   //
255   // Muon Trigger
256   //
257   
258   if(doMUONTrig) {
259       gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskMTRchamberEfficiency.C");
260       AliAnalysisTaskTrigChEff *taskMuonTrig = AddTaskMTRchamberEfficiency();
261   }
262
263   //
264   // Muon Efficiency
265   //
266
267   if(doMUONEff) {
268       gROOT->LoadMacro("$ALICE_ROOT/PWG3/muondep/AddTaskMUONTrackingEfficiency.C");
269       AliAnalysisTaskMuonTrackingEff *taskMuonTrackEff = AddTaskMUONTrackingEfficiency();
270   }
271   
272   //
273   // V0-Decay Reconstruction (Ana Marin)
274   // 
275
276   if (doV0) {
277       gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskV0QA.C");
278       AliAnalysisTaskV0QA *taskv0QA = AddTaskV0QA(kFALSE);
279   }
280   // Impact parameter resolution (xianbao.yuan@pd.infn.it, andrea.dainese@pd.infn.it)
281   //
282   if (doImpParRes) {
283     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskImpParRes.C");
284     AliAnalysisTaskSE* taskimpparres= AddTaskImpParRes();
285     taskimpparres->SelectCollisionCandidates();
286   }  
287   // MUON QA (Philippe Pillot)
288   //
289   if (doMUON) {
290     gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskMuonQA.C");
291     AliAnalysisTaskSE* taskmuonqa= AddTaskMuonQA(kFALSE, kFALSE);
292   }  
293 }
294
295 //______________________________________________________________________________
296 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
297 {
298 // Check if user has a valid token, otherwise make one. This has limitations.
299 // One can always follow the standard procedure of calling alien-token-init then
300 //   source /tmp/gclient_env_$UID in the current shell.
301    if (!AliAnalysisGrid::CreateToken()) return NULL;
302    AliAnalysisAlien *plugin = new AliAnalysisAlien();
303 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
304    plugin->SetRunMode(plugin_mode);
305    if (useProductionMode) {
306       plugin->SetProductionMode();
307       plugin->AddDataFile(data_collection);
308    }   
309    plugin->SetJobTag(job_tag);
310    plugin->SetNtestFiles(1);
311    plugin->SetCheckCopy(kFALSE);
312    plugin->SetOneStageMerging(kTRUE);
313 // Set versions of used packages
314    plugin->SetAPIVersion("V1.1x");
315    plugin->SetROOTVersion(root_version);
316    plugin->SetAliROOTVersion(aliroot_version);
317 // Declare input data to be processed.
318 // Method 1: Create automatically XML collections using alien 'find' command.
319 // Define production directory LFN
320    plugin->SetGridDataDir(grid_datadir);
321 // Set data search pattern
322    plugin->SetDataPattern(data_pattern);
323 // ...then add run numbers to be considered
324 //   if (!iAODanalysis) plugin->SetRunRange(run_range[0], run_range[1]);
325    //plugin->SetRunPrefix("000");
326 //   plugin->SetOutputSingleFolder("output");
327    if (!useProductionMode) {
328       plugin->SetOutputToRunNo();
329       for (Int_t i=0; i<2; i++) {
330          if (!runNumbers[i]) break;
331          plugin->AddRunNumber(runNumbers[i]);
332       }   
333    }
334 // Define alien work directory where all files will be copied. Relative to alien $HOME.
335    plugin->SetGridWorkingDir(grid_workdir);
336 // Declare alien output directory. Relative to working directory.
337    if (alien_outdir.IsNull()) alien_outdir = Form("output_%s",train_name.Data());
338    plugin->SetGridOutputDir(alien_outdir);
339
340    if (useDevelopmentVersion) {
341      plugin->EnablePackage("STEERBase");
342      plugin->EnablePackage("ESD");
343      plugin->EnablePackage("AOD");
344      plugin->EnablePackage("ANALYSIS");
345      plugin->EnablePackage("ANALYSISalice");
346    }
347
348 // Declare the analysis source files names separated by blancs. To be compiled runtime
349 // using ACLiC on the worker nodes.
350 // Declare all libraries (other than the default ones for the framework. These will be
351 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
352    plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/ITS -I$ALICE_ROOT/TRD");
353    
354    plugin->SetAdditionalLibs("libTender.so libPWG0base.so libPWG0dep.so libPWG0selectors.so libPWGPP.so libPWG2.so \
355                               libPWG2forward.so libEMCALUtils.so libPWG4PartCorrBase.so libPWG4PartCorrDep.so \
356                               libPWGHFbase.so libPWGmuon.so libPWGmuondep.so");
357      
358 // Declare the output file names separated by blancs.
359 // (can be like: file.root or file.root@ALICE::Niham::File)
360    plugin->SetDefaultOutputs();
361    plugin->SetMaxMergeFiles(20);
362    plugin->SetNrunsPerMaster(1);
363    
364    // Put default output files to archive
365    TString listhists = "";
366    TString listaods  = "";
367    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
368    if (!mergeExcludes.IsNull()) plugin->SetMergeExcludes(mergeExcludes);
369    if (!terminateFiles.IsNull()) plugin->SetTerminateFiles(terminateFiles);
370 // Set friends
371 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
372    plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
373 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
374    plugin->SetSplitMaxInputFileNumber(grid_split);
375 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
376 //   plugin->SetMaxInitFailed(5);
377 // Optionally modify the number of replicas
378    plugin->SetNumberOfReplicas(4);
379 // Optionally resubmit threshold.
380 //   plugin->SetMasterResubmitThreshold(90);
381 // Optionally set time to live (default 30000 sec)
382    plugin->SetTTL(70000);
383 // Optionally set input format (default xml-single)
384    plugin->SetInputFormat("xml-single");
385 // Optionally modify the name of the generated JDL (default analysis.jdl)
386    plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
387 // Optionally modify the executable name (default analysis.sh)
388    plugin->SetExecutable(Form("%s.sh", train_name.Data()));
389 // Optionally modify job price (default 1)
390    plugin->SetPrice(1);      
391 // Optionally modify split mode (default 'se')    
392    plugin->SetSplitMode("se");
393    plugin->SetExecutableCommand("aliroot -b -q");
394 // Merge via JDL
395    plugin->SetMergeViaJDL(useMergeViaJDL);
396 // Use fastread option
397    plugin->SetFastReadOption(useFastReadOption);
398 // UseOverwrite mode
399    plugin->SetOverwriteMode(useOverwriteMode);   
400 /*********************************************************
401  ***     PROOF MODE SPECIFIC SETTINGS         ************
402  *********************************************************/
403 // Proof cluster
404 //   plugin->SetProofCluster("alice-caf");
405    plugin->SetProofCluster("skaf.saske.sk");
406 // Dataset to be used   
407    plugin->SetProofDataSet("/alice/data/LHC10e_000128175_p1#esdTree");
408 // May need to reset proof. Supported modes: 0-no reset, 1-soft, 2-hard
409    plugin->SetProofReset(0);
410 // May limit number of workers
411    plugin->SetNproofWorkers(20);   
412 // May use a specific version of root installed in proof
413    plugin->SetRootVersionForProof("current_dbg");
414 // May set the aliroot mode. Check http://aaf.cern.ch/node/83 
415    plugin->SetAliRootMode("ALIROOT"); // Loads AF libs by default
416 // May request ClearPackages (individual ClearPackage not supported)
417    plugin->SetClearPackages(kFALSE);
418 // Plugin test mode works only providing a file containing test file locations
419    plugin->SetFileForTestMode(gSystem->ExpandPathName("$ALICE_ROOT/PWGPP/PilotTrain/files.txt"));
420    return plugin;
421 }