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