Update (added some options)
[u/mrichter/AliRoot.git] / PWG1 / macros / RunAnalysisITS.C
CommitLineData
76bd0732 1class AliAnalysisGrid;
2
3void RunAnalysisITS() {
4 //
5 // Macro to analyze ESDs from raw data reconstruction
6 // A.Dainese, andrea.dainese@pd.infn.it
7 //
62b52cbf 8 //gSystem->Setenv("alien_CLOSE_SE","ALICE::CNAF::SE");
76bd0732 9
10 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 -g");
11
12 //
1b65f728 13 TString analysisMode = "local"; // "local", "grid", or "proof" (not yet)
76bd0732 14
15 Long64_t nentries=1000000000000000,firstentry=0;
1b65f728 16 Bool_t useAlienPlugin=kFALSE;
62b52cbf 17 Bool_t uselibPWG1=kTRUE;
76bd0732 18 TString pluginmode="full";
19 TString loadMacroPath="./";
20 Bool_t readHLT=kFALSE;
21 //
22
23 if(analysisMode=="grid") {
24 // Connect to AliEn
25 TGrid::Connect("alien://");
26 } else if(analysisMode=="proof") {
27 // Connect to the PROOF cluster
28 printf("PROOF mode not yet functional..\n");
29 return;
30 TProof::Open("alicecaf");
31 //TProof::Reset("alicecaf");
32 }
33
34 // Load analysis libraries
35 gSystem->Load("libANALYSIS.so");
36 gSystem->Load("libANALYSISalice.so");
4f8ced9e 37 if(uselibPWG1) {gSystem->Load("libTENDER.so");gSystem->Load("libPWG1.so");}
62b52cbf 38
76bd0732 39 // Create Alien plugin, if requested
40 if(useAlienPlugin) {
62b52cbf 41 AliAnalysisGrid *alienHandler = CreateAlienHandler(pluginmode,uselibPWG1);
76bd0732 42 if(!alienHandler) return;
43 }
44
45 TChain *chainESD = 0;
46 if(!useAlienPlugin) {
47 // Prepare input chain
4f8ced9e 48 chainESD = CreateESDChain("/home/dainesea/alignEvents2/boxTRUNK280909_zero/event.",1,48);
49 //chainESD=new TChain("esdTree");
62b52cbf 50 //chainESD->Add("alien:///alice/cern.ch/user/s/sitta/output/000088361/ESDs/pass1/09000088361017.10/AliESDs.root");
4f8ced9e 51 //chainESD->Add("./AliESDs.root");
76bd0732 52 }
53
54 // Create the analysis manager
55 AliAnalysisManager *mgr = new AliAnalysisManager("My Manager","My Manager");
56 // Enable debug printouts
57 mgr->SetDebugLevel(10);
58 // Connect plug-in to the analysis manager
59 if(useAlienPlugin) mgr->SetGridHandler(alienHandler);
60
4f8ced9e 61 //-------------------------------------------------------------------
62
76bd0732 63 // Add ESD handler
4f8ced9e 64 Bool_t readRP=kTRUE;
65 AliESDInputHandler *esdH = 0;
66 if(readRP) {
67 esdH = new AliESDInputHandlerRP();
68 } else {
69 esdH = new AliESDInputHandler();
70 }
b900a060 71 esdH->SetActiveBranches("ESDfriend");
76bd0732 72 if(readHLT) esdH->SetReadHLT();
73 mgr->SetInputEventHandler(esdH);
76bd0732 74
75 //-------------------------------------------------------------------
76 // Analysis tasks (wagons of the train)
77 //
78 TString taskName;
4f8ced9e 79 /*
62b52cbf 80 if(!uselibPWG1) gROOT->LoadMacro("AliAlignmentDataFilterITS.cxx++g");
76bd0732 81 taskName="AddTaskAlignmentDataFilterITS.C";
82 taskName.Prepend(loadMacroPath.Data());
83 gROOT->LoadMacro(taskName.Data());
84 AliAlignmentDataFilterITS *itsTask = AddTaskAlignmentDataFilterITS();
62b52cbf 85
86 if(!uselibPWG1) gROOT->LoadMacro("AliTrackMatchingTPCITSCosmics.cxx++g");
76bd0732 87 taskName="AddTaskTrackMatchingTPCITS.C";
88 taskName.Prepend(loadMacroPath.Data());
89 gROOT->LoadMacro(taskName.Data());
90 AliTrackMatchingTPCITSCosmics *tpcitsTask = AddTaskTrackMatchingTPCITS();
91 if(readHLT) tpcitsTask->SetReadHLTESD(kTRUE);
4f8ced9e 92 */
1b65f728 93 Bool_t readMC=kTRUE;
1b65f728 94 if(!uselibPWG1) gROOT->LoadMacro("AliAnalysisTaskVertexESD.cxx++g");
95 taskName="AddTaskVertexESD.C";
96 taskName.Prepend(loadMacroPath.Data());
97 gROOT->LoadMacro(taskName.Data());
4f8ced9e 98 //AliAnalysisTaskVertexESD *vtxTask = AddTaskVertexESD(readMC);
1b65f728 99
100 if(!uselibPWG1) gROOT->LoadMacro("AliAnalysisTaskITSTrackingCheck.cxx++g");
101 taskName="AddTaskPerformanceITS.C";
102 taskName.Prepend(loadMacroPath.Data());
103 gROOT->LoadMacro(taskName.Data());
4f8ced9e 104 AliAnalysisTaskITSTrackingCheck *itsTask = AddTaskPerformanceITS(readMC,readRP);
1b65f728 105
106 if(readMC) {
107 AliMCEventHandler *mcH = new AliMCEventHandler();
108 mgr->SetMCtruthEventHandler(mcH);
109 }
4f8ced9e 110
76bd0732 111 //
112 // Run the analysis
113 //
114 if(chainESD) printf("CHAIN HAS %d ENTRIES\n",(Int_t)chainESD->GetEntries());
115
116 if(!mgr->InitAnalysis()) return;
117 mgr->PrintStatus();
118 if(analysisMode=="grid" && !useAlienPlugin) analysisMode="local";
119 mgr->StartAnalysis(analysisMode.Data(),chainESD,nentries,firstentry);
120
121 return;
122}
123//_____________________________________________________________________________
124//
62b52cbf 125AliAnalysisGrid* CreateAlienHandler(TString pluginmode="test",
126 Bool_t uselibPWG1=kFALSE)
76bd0732 127{
128 // Check if user has a valid token, otherwise make one. This has limitations.
129 // One can always follow the standard procedure of calling alien-token-init then
130 // source /tmp/gclient_env_$UID in the current shell.
131 if (!AliAnalysisGrid::CreateToken()) return NULL;
132 AliAnalysisAlien *plugin = new AliAnalysisAlien();
133 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
134 plugin->SetRunMode(pluginmode.Data());
135 plugin->SetUser("dainesea");
136 plugin->SetNtestFiles(1);
137 // Set versions of used packages
138 plugin->SetAPIVersion("V2.4");
139 plugin->SetROOTVersion("v5-24-00");
62b52cbf 140 plugin->SetAliROOTVersion("v4-18-07-AN");
76bd0732 141 // Declare input data to be processed.
142 // Method 1: Create automatically XML collections using alien 'find' command.
143 // Define production directory LFN
62b52cbf 144 plugin->SetGridDataDir("/alice/data/2009/LHC09c");
76bd0732 145 //plugin->SetGridDataDir("/alice/cern.ch/user/s/sitta/output/000088361/");
146 // Set data search pattern
147 //plugin->SetDataPattern("AliESDs.root");
62b52cbf 148 plugin->SetDataPattern("ESD.tag.root");
149 Int_t n=0;
150 n++; plugin->AddRunNumber("000080015");
151 n++; plugin->AddRunNumber("000080261");
152 plugin->SetNrunsPerMaster(n);
76bd0732 153 // Method 2: Declare existing data files (raw collections, xml collections, root file)
154 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
155 // XML collections added via this method can be combined with the first method if
156 // the content is compatible (using or not tags)
157 // e.g.: find -z -x 80015 /alice/data/2009/LHC09c/000080015/ESDs/ ESD.tag.root > 80015.xml
158 //plugin->AddDataFile("79876.xml");
62b52cbf 159 //plugin->AddDataFile("80015.xml");
76bd0732 160 //plugin->AddDataFile("80261.xml");
161 // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
162 // Define alien work directory where all files will be copied. Relative to alien $HOME.
163 plugin->SetGridWorkingDir("analysisITS");
164 // Declare alien output directory. Relative to working directory.
62b52cbf 165 plugin->SetGridOutputDir("output151009"); // In this case will be $HOME/work/output
76bd0732 166 // Declare the analysis source files names separated by blancs. To be compiled runtime
167 // using ACLiC on the worker nodes.
62b52cbf 168 if(!uselibPWG1) {
169 plugin->SetAnalysisSource("AliAlignmentDataFilterITS.cxx");
170 plugin->SetAnalysisSource("AliTrackMatchingTPCITSCosmics.cxx");
171 }
76bd0732 172 // Declare all libraries (other than the default ones for the framework. These will be
173 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
174 //plugin->SetAdditionalLibs("AliAlignmentDataFilterITS.h AliAlignmentDataFilterITS.cxx libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
76bd0732 175 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 -g");
62b52cbf 176 if(!uselibPWG1) {
177 plugin->SetAdditionalLibs("AliAlignmentDataFilterITS.h AliAlignmentDataFilterITS.cxx AliTrackMatchingTPCITSCosmics.h AliTrackMatchingTPCITSCosmics.cxx libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
178 } else {
ae1e2a16 179 plugin->SetAdditionalLibs("libGui.so libProof.so libMinuit.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so libTPCbase.so libTPCrec.so libTRDbase.so libTRDrec.so libTENDER.so libPWG1.so");
62b52cbf 180 }
76bd0732 181 // Declare the output file names separated by blancs.
182 // (can be like: file.root or file.root@ALICE::Niham::File)
183 plugin->SetDefaultOutputs(kTRUE);
184 // Optionally define the files to be archived.
185 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:*.root@ALICE::NIHAM::File");
186 plugin->SetOutputArchive("log_archive.zip:stdout,stderr");
187 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
188 plugin->SetAnalysisMacro("AnalysisITS.C");
189 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
62b52cbf 190 plugin->SetSplitMaxInputFileNumber(1);
76bd0732 191 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
192 //plugin->SetMaxInitFailed(5);
193 // Optionally resubmit threshold.
194 //plugin->SetMasterResubmitThreshold(90);
195 // Optionally set time to live (default 30000 sec)
196 //plugin->SetTTL(20000);
197 // Optionally set input format (default xml-single)
198 plugin->SetInputFormat("xml-single");
199 // Optionally modify the name of the generated JDL (default analysis.jdl)
200 plugin->SetJDLName("TaskAnalysisITS.jdl");
201 // Optionally modify job price (default 1)
202 //plugin->SetPrice(1);
203 // Optionally modify split mode (default 'se')
204 plugin->SetSplitMode("se");
205 // Optionally set the preferred SE
206 plugin->SetPreferedSE("ALICE::CNAF::SE");
207
208 return plugin;
209}
210//-----------------------------------------------------------------------------
211TChain *CreateESDChain(TString esdpath=".",Int_t ifirst=-1,Int_t ilast=-1) {
212
213
214 TChain *chainESD = new TChain("esdTree");
215
216 if(ifirst<0) {
217 chainESD->Add("AliESDs.root");
218 } else {
219 for(Int_t i=ifirst; i<=ilast; i++) {
4f8ced9e 220 TString command=".! ln -s ";
221 command+=esdpath.Data();
222 command+=i;
223 command+= "/AliESDs_def.root ";
224 command+=esdpath.Data();
225 command+=i;
226 command+= "/AliESDs.root ";
227 gROOT->ProcessLine(command.Data());
228 command.ReplaceAll("AliESDs","AliESDfriends");
229 gROOT->ProcessLine(command.Data());
76bd0732 230 TString esdfile=esdpath; esdfile+=i; esdfile.Append("/AliESDs.root");
231 chainESD->Add(esdfile.Data());
232 }
233 }
234
235 return chainESD;
236}