Add possbility to read also the RecPoints
[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 }
76bd0732 71 if(readHLT) esdH->SetReadHLT();
72 mgr->SetInputEventHandler(esdH);
76bd0732 73
74 //-------------------------------------------------------------------
75 // Analysis tasks (wagons of the train)
76 //
77 TString taskName;
4f8ced9e 78 /*
62b52cbf 79 if(!uselibPWG1) gROOT->LoadMacro("AliAlignmentDataFilterITS.cxx++g");
76bd0732 80 taskName="AddTaskAlignmentDataFilterITS.C";
81 taskName.Prepend(loadMacroPath.Data());
82 gROOT->LoadMacro(taskName.Data());
83 AliAlignmentDataFilterITS *itsTask = AddTaskAlignmentDataFilterITS();
62b52cbf 84
85 if(!uselibPWG1) gROOT->LoadMacro("AliTrackMatchingTPCITSCosmics.cxx++g");
76bd0732 86 taskName="AddTaskTrackMatchingTPCITS.C";
87 taskName.Prepend(loadMacroPath.Data());
88 gROOT->LoadMacro(taskName.Data());
89 AliTrackMatchingTPCITSCosmics *tpcitsTask = AddTaskTrackMatchingTPCITS();
90 if(readHLT) tpcitsTask->SetReadHLTESD(kTRUE);
4f8ced9e 91 */
1b65f728 92 Bool_t readMC=kTRUE;
1b65f728 93 if(!uselibPWG1) gROOT->LoadMacro("AliAnalysisTaskVertexESD.cxx++g");
94 taskName="AddTaskVertexESD.C";
95 taskName.Prepend(loadMacroPath.Data());
96 gROOT->LoadMacro(taskName.Data());
4f8ced9e 97 //AliAnalysisTaskVertexESD *vtxTask = AddTaskVertexESD(readMC);
1b65f728 98
99 if(!uselibPWG1) gROOT->LoadMacro("AliAnalysisTaskITSTrackingCheck.cxx++g");
100 taskName="AddTaskPerformanceITS.C";
101 taskName.Prepend(loadMacroPath.Data());
102 gROOT->LoadMacro(taskName.Data());
4f8ced9e 103 AliAnalysisTaskITSTrackingCheck *itsTask = AddTaskPerformanceITS(readMC,readRP);
1b65f728 104
105 if(readMC) {
106 AliMCEventHandler *mcH = new AliMCEventHandler();
107 mgr->SetMCtruthEventHandler(mcH);
108 }
4f8ced9e 109
76bd0732 110 //
111 // Run the analysis
112 //
113 if(chainESD) printf("CHAIN HAS %d ENTRIES\n",(Int_t)chainESD->GetEntries());
114
115 if(!mgr->InitAnalysis()) return;
116 mgr->PrintStatus();
117 if(analysisMode=="grid" && !useAlienPlugin) analysisMode="local";
118 mgr->StartAnalysis(analysisMode.Data(),chainESD,nentries,firstentry);
119
120 return;
121}
122//_____________________________________________________________________________
123//
62b52cbf 124AliAnalysisGrid* CreateAlienHandler(TString pluginmode="test",
125 Bool_t uselibPWG1=kFALSE)
76bd0732 126{
127 // Check if user has a valid token, otherwise make one. This has limitations.
128 // One can always follow the standard procedure of calling alien-token-init then
129 // source /tmp/gclient_env_$UID in the current shell.
130 if (!AliAnalysisGrid::CreateToken()) return NULL;
131 AliAnalysisAlien *plugin = new AliAnalysisAlien();
132 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
133 plugin->SetRunMode(pluginmode.Data());
134 plugin->SetUser("dainesea");
135 plugin->SetNtestFiles(1);
136 // Set versions of used packages
137 plugin->SetAPIVersion("V2.4");
138 plugin->SetROOTVersion("v5-24-00");
62b52cbf 139 plugin->SetAliROOTVersion("v4-18-07-AN");
76bd0732 140 // Declare input data to be processed.
141 // Method 1: Create automatically XML collections using alien 'find' command.
142 // Define production directory LFN
62b52cbf 143 plugin->SetGridDataDir("/alice/data/2009/LHC09c");
76bd0732 144 //plugin->SetGridDataDir("/alice/cern.ch/user/s/sitta/output/000088361/");
145 // Set data search pattern
146 //plugin->SetDataPattern("AliESDs.root");
62b52cbf 147 plugin->SetDataPattern("ESD.tag.root");
148 Int_t n=0;
149 n++; plugin->AddRunNumber("000080015");
150 n++; plugin->AddRunNumber("000080261");
151 plugin->SetNrunsPerMaster(n);
76bd0732 152 // Method 2: Declare existing data files (raw collections, xml collections, root file)
153 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
154 // XML collections added via this method can be combined with the first method if
155 // the content is compatible (using or not tags)
156 // e.g.: find -z -x 80015 /alice/data/2009/LHC09c/000080015/ESDs/ ESD.tag.root > 80015.xml
157 //plugin->AddDataFile("79876.xml");
62b52cbf 158 //plugin->AddDataFile("80015.xml");
76bd0732 159 //plugin->AddDataFile("80261.xml");
160 // plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
161 // Define alien work directory where all files will be copied. Relative to alien $HOME.
162 plugin->SetGridWorkingDir("analysisITS");
163 // Declare alien output directory. Relative to working directory.
62b52cbf 164 plugin->SetGridOutputDir("output151009"); // In this case will be $HOME/work/output
76bd0732 165 // Declare the analysis source files names separated by blancs. To be compiled runtime
166 // using ACLiC on the worker nodes.
62b52cbf 167 if(!uselibPWG1) {
168 plugin->SetAnalysisSource("AliAlignmentDataFilterITS.cxx");
169 plugin->SetAnalysisSource("AliTrackMatchingTPCITSCosmics.cxx");
170 }
76bd0732 171 // Declare all libraries (other than the default ones for the framework. These will be
172 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
173 //plugin->SetAdditionalLibs("AliAlignmentDataFilterITS.h AliAlignmentDataFilterITS.cxx libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
76bd0732 174 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 175 if(!uselibPWG1) {
176 plugin->SetAdditionalLibs("AliAlignmentDataFilterITS.h AliAlignmentDataFilterITS.cxx AliTrackMatchingTPCITSCosmics.h AliTrackMatchingTPCITSCosmics.cxx libProof.so libRAWDatabase.so libRAWDatarec.so libCDB.so libSTEER.so libITSbase.so libITSrec.so");
177 } else {
ae1e2a16 178 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 179 }
76bd0732 180 // Declare the output file names separated by blancs.
181 // (can be like: file.root or file.root@ALICE::Niham::File)
182 plugin->SetDefaultOutputs(kTRUE);
183 // Optionally define the files to be archived.
184 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:*.root@ALICE::NIHAM::File");
185 plugin->SetOutputArchive("log_archive.zip:stdout,stderr");
186 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
187 plugin->SetAnalysisMacro("AnalysisITS.C");
188 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
62b52cbf 189 plugin->SetSplitMaxInputFileNumber(1);
76bd0732 190 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
191 //plugin->SetMaxInitFailed(5);
192 // Optionally resubmit threshold.
193 //plugin->SetMasterResubmitThreshold(90);
194 // Optionally set time to live (default 30000 sec)
195 //plugin->SetTTL(20000);
196 // Optionally set input format (default xml-single)
197 plugin->SetInputFormat("xml-single");
198 // Optionally modify the name of the generated JDL (default analysis.jdl)
199 plugin->SetJDLName("TaskAnalysisITS.jdl");
200 // Optionally modify job price (default 1)
201 //plugin->SetPrice(1);
202 // Optionally modify split mode (default 'se')
203 plugin->SetSplitMode("se");
204 // Optionally set the preferred SE
205 plugin->SetPreferedSE("ALICE::CNAF::SE");
206
207 return plugin;
208}
209//-----------------------------------------------------------------------------
210TChain *CreateESDChain(TString esdpath=".",Int_t ifirst=-1,Int_t ilast=-1) {
211
212
213 TChain *chainESD = new TChain("esdTree");
214
215 if(ifirst<0) {
216 chainESD->Add("AliESDs.root");
217 } else {
218 for(Int_t i=ifirst; i<=ilast; i++) {
4f8ced9e 219 TString command=".! ln -s ";
220 command+=esdpath.Data();
221 command+=i;
222 command+= "/AliESDs_def.root ";
223 command+=esdpath.Data();
224 command+=i;
225 command+= "/AliESDs.root ";
226 gROOT->ProcessLine(command.Data());
227 command.ReplaceAll("AliESDs","AliESDfriends");
228 gROOT->ProcessLine(command.Data());
76bd0732 229 TString esdfile=esdpath; esdfile+=i; esdfile.Append("/AliESDs.root");
230 chainESD->Add(esdfile.Data());
231 }
232 }
233
234 return chainESD;
235}