.so cleanup: removed from gSystem->Load()
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TestAOD / runGridBoth.C
1
2 class  AliAnalysisManager;
3 class  AliAnalysisAlien;
4 class AliSpectraBothPID;
5 Int_t mc=-1;
6 Int_t aod=-1;
7 TString griddatadir="";
8 TString datapattern="";
9 TString gridworkingdir="";
10 TString aliroot="";
11 TString root="";
12
13
14 void runGridBoth(TString mode="test",TString configfile="config.txt",Int_t day=15,Int_t month=6, Int_t year=2012) 
15 {
16
17
18         ifstream infile(configfile);
19         char buffer[256];
20         while (infile.eof()==false)
21         {
22                 buffer[0]='#'; 
23                 while (buffer[0]=='#'&&infile.eof()==false)
24                         infile.getline(buffer,256);
25                 TString tmpstring(buffer);
26                 cout<<buffer<<endl;
27                 if(tmpstring.Contains("MC"))
28                 {
29                         tmpstring.Remove(0,3);
30                         cout<<tmpstring<<endl;
31                         if (!tmpstring.IsDigit())
32                         {
33                                 cout<<"Wrong format of MC flag in config file "<<endl;
34                                 return;         
35                         }
36                         mc=tmpstring.Atoi();
37                 }
38                 else if(tmpstring.Contains("AOD")&&tmpstring.Length()<6)
39                 {
40                         tmpstring.Remove(0,4);
41                         if (!tmpstring.IsDigit())
42                         {
43                                 cout<<"Wrong format of AOD flag in config file "<<endl;
44                                 return;         
45                         }
46                         aod=tmpstring.Atoi();
47                 }
48                 else if(tmpstring.Contains("GridDataDir"))
49                 {
50                         griddatadir=tmpstring.Remove(0,12);             
51                 }
52                 else if(tmpstring.Contains("DataPattern"))
53                 {       
54                         datapattern=tmpstring.Remove(0,12);
55                 }
56                 else if (tmpstring.Contains("GridWorkingDir"))
57                 {
58                         gridworkingdir=tmpstring.Remove(0,15);
59                 }
60                 else if(tmpstring.Contains("root")&&!tmpstring.Contains("aliroot"))
61                 {       
62                         root=tmpstring.Remove(0,5);
63                 }
64                 else if (tmpstring.Contains("aliroot"))
65                 {
66                         aliroot=tmpstring.Remove(0,8);
67                 }
68
69                 else
70                         continue;
71
72         }
73          
74         if(mc<0||aod<0||griddatadir.Length()<1||root.Length()<1||datapattern.Length()<1||gridworkingdir.Length()<1||aliroot.Length()<1)
75         {
76                 cout<<"lack of config info"<<endl;
77                 return; 
78         }       
79 cout<<mc<<" "<<aod<<" "<<griddatadir.Data()<<" "<<root.Data()<<" "<<datapattern.Data()<<" "<<gridworkingdir.Data()<<" "<<aliroot.Data()<<endl;
80         
81
82   TString daystring=Form("%d%d%d",year,month,day);      
83   //to be used with Aliroot > v5-03-32-AN
84   AliLog::SetGlobalDebugLevel(100);
85   // Load common libraries
86   gEnv->SetValue("XSec.GSI.DelegProxy", "2");
87   
88   // Load common libraries
89   gSystem->Load("libCore");
90   gSystem->Load("libTree");
91   gSystem->Load("libGeom");
92   gSystem->Load("libVMC");
93   gSystem->Load("libPhysics");
94   gSystem->Load("libMinuit");
95   gSystem->Load("libGui");
96   gSystem->Load("libXMLParser");
97   gSystem->Load("libSTEERBase");
98   gSystem->Load("libESD");
99   gSystem->Load("libCDB");
100   gSystem->Load("libAOD");
101   gSystem->Load("libANALYSIS");
102   gSystem->Load("libANALYSISalice");
103   gSystem->Load("libCORRFW");
104   gSystem->Load("libProof");
105   gSystem->Load("libRAWDatabase");
106   gSystem->Load("libSTEER");
107   gSystem->Load("libTender");
108     gSystem->Load("libTenderSupplies");
109 gSystem->Load("libPWGLFspectra");
110   gROOT->ProcessLine(".include $ALICE_ROOT/include ");
111   gSystem->SetIncludePath("-I.");
112   gROOT->ProcessLine(".include $ALICE_ROOT/TOF ");
113
114   //gSystem->Load("libPWGLFspectra");
115  // gROOT->LoadMacro("AliSpectraBothTrackCuts.cxx+g");
116  // gROOT->LoadMacro("AliSpectraBothEventCuts.cxx+g");
117   // gROOT->LoadMacro("HistogramNames.cxx");
118  // gROOT->LoadMacro("AliSpectraBothHistoManager.cxx+g");
119  // gROOT->LoadMacro("AliSpectraBothPID.cxx+g");
120  // gROOT->LoadMacro("AliAnalysisTaskSpectraBoth.cxx+g");
121   //__________________________________________________________________________
122   // Use AliRoot includes to compile our task
123   gROOT->ProcessLine(".include $ALICE_ROOT/include  ");
124   gSystem->SetIncludePath("-I.");
125   gROOT->ProcessLine(".include $ALICE_ROOT/TOF ");
126   gROOT->LoadMacro("$ALICE_ROOT/PWGLF/SPECTRA/PiKaPr/TestAOD/AddTaskSpectraBoth.C");
127         
128   // Create and configure the alien handler plugin
129   AliAnalysisGrid *alienHandler = CreateAlienHandler(mode,daystring);  
130   if (!alienHandler) return;
131   // Create the analysis manager
132   AliAnalysisManager *mgr = new AliAnalysisManager("testAnalysis");
133   // Connect plug-in to the analysis manager
134   mgr->SetGridHandler(alienHandler);
135   if(aod)
136   {     
137         AliAODInputHandler* aodH = new AliAODInputHandler();
138         mgr->SetInputEventHandler(aodH);
139   }
140   else
141   {
142          AliESDInputHandler* esdH = new AliESDInputHandler();   
143          mgr->SetInputEventHandler(esdH);
144          if(mc)
145         {
146              AliMCEventHandler *mch = new AliMCEventHandler();
147              mgr->SetMCtruthEventHandler(mch);
148         }
149   }             
150   
151   // Add PID task
152  // Bool_t isMC=kFALSE, Bool_t autoMCesd=kTRUE,
153    //    Bool_t tuneOnData=kFALSE, Int_t recoPass=2, Bool_t cachePID=kFALSE, TString detResponse="",
154 //Bool_t useTPCEtaCorrection = kFALSE  gROOT->LoadMacro("./AddTaskSpectraBoth.C");
155
156   Double_t Nsigmapid=3.;
157   Double_t pt=5.;
158   Double_t p=5.;
159   Double_t y=.2;
160   Double_t ptTofMatch=.6;
161   UInt_t trkbit=1;
162   UInt_t trkbit2=16;
163
164   UInt_t trkbitQVector=1;
165   Bool_t UseCentPatchAOD049=kFALSE;
166   Double_t DCA=100000;
167   UInt_t minNclsTPC=70;
168   UInt_t minNclsTPC2=0; 
169   Int_t rebinfactor=1;          
170  Bool_t mcfactor=0;
171  if(mc)
172         mcfactor=1;     
173
174  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
175   AliAnalysisTaskPIDResponse *taskPID=AddTaskPIDResponse(mcfactor,kTRUE,kFALSE,2,kFALSE,"",kTRUE);
176 taskPID->SetUseTPCEtaCorrection(kTRUE);
177  if(!aod)
178   {     
179         gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
180         AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
181         if(mc)
182         {
183              physSelTask->GetPhysicsSelection()->SetAnalyzeMC();
184          } 
185   }
186         
187
188         AliAnalysisTaskSpectraBoth* task1=0x0;  
189         AliAnalysisTaskSpectraBoth* task2=0x0;
190         AliAnalysisTaskSpectraBoth* task3=0x0;
191         AliAnalysisTaskSpectraBoth* task4=0x0;  
192
193
194
195         task1=AddTaskSpectraBoth(mcfactor,-1,-1,-1,-1,-0.8,0.8,Nsigmapid,pt,p,-0.5,0.5,ptTofMatch,trkbit,trkbitQVector,UseCentPatchAOD049,DCA,minNclsTPC,rebinfactor,"V0M",2);
196
197         task2=AddTaskSpectraBoth(mcfactor,-1,-1,-1,-1,-0.8,0.8,Nsigmapid,pt,p,-0.465,0.035,ptTofMatch,trkbit,trkbitQVector,UseCentPatchAOD049,DCA,minNclsTPC,rebinfactor,"V0M",2);
198         
199         task3=AddTaskSpectraBoth(mcfactor,-1,-1,-1,-1,-0.8,0.8,2.0,pt,p,-0.465,0.035,ptTofMatch,trkbit,trkbitQVector,UseCentPatchAOD049,DCA,minNclsTPC,rebinfactor,"V0M",2);
200
201         task4=AddTaskSpectraBoth(mcfactor,-1,-1,-1,-1,-0.8,0.8,Nsigmapid,pt,p,-0.465,0.035,ptTofMatch,trkbit2,trkbitQVector,UseCentPatchAOD049,DCA,minNclsTPC2,rebinfactor,"V0M",2);
202
203         
204
205
206   if(mc)
207   {
208         task1->SetdotheMCLoopAfterEventCuts(kTRUE);
209         task2->SetdotheMCLoopAfterEventCuts(kTRUE);
210         task3->SetdotheMCLoopAfterEventCuts(kTRUE);
211         task4->SetdotheMCLoopAfterEventCuts(kTRUE);
212
213
214   }
215   else
216  {
217         task1->GetEventCuts()->SetTriggerSettings(AliVEvent::kINT7);
218         task2->GetEventCuts()->SetTriggerSettings(AliVEvent::kINT7);
219         task3->GetEventCuts()->SetTriggerSettings(AliVEvent::kINT7);
220         task4->GetEventCuts()->SetTriggerSettings(AliVEvent::kINT7);
221
222
223 }       
224   if(!aod)
225   {
226         AliESDtrackCuts* cuttpc1=AliESDtrackCuts::GetStandardITSTPCTrackCuts2011();
227         task1->SetAliESDtrackCuts(cuttpc1);
228         AliESDtrackCuts* cuttpc2=AliESDtrackCuts::GetStandardITSTPCTrackCuts2011();
229
230         task2->SetAliESDtrackCuts(cuttpc2);
231   }
232         
233   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDqa.C");
234   AddTaskPIDqa(); 
235    if(mode.Contains("test"))
236         mgr->SetDebugLevel(1);
237   //mgr->Init();
238   if (!mgr->InitAnalysis())return;
239   mgr->PrintStatus();
240
241   mgr->StartAnalysis("grid");
242 }
243
244
245 AliAnalysisGrid* CreateAlienHandler(TString mode="test",TString daystring)
246 {
247   TString filename="*AliAOD.root";
248  
249                 
250   if(!aod)
251   {
252         filename="*AliESDs.root";
253   }
254
255
256
257  
258   TString jobsettings=griddatadir;
259   jobsettings+=datapattern;
260   if(aod)
261         jobsettings+="AOD";
262   else
263         jobsettings+="ESD";
264
265   if(mc)
266         jobsettings+="MC";
267   else
268         jobsettings+="DATA";
269                 
270                 
271   jobsettings.ReplaceAll("/","");       
272
273  jobsettings.ReplaceAll("*","");
274         
275         
276
277   AliAnalysisAlien *plugin = new AliAnalysisAlien();
278   //plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/TOF  -I$ALICE_ROOT/PWGLF/SPECTRA/PiKaPr/TestAOD");
279   //plugin->SetAdditionalLibs("libSTEERBase.so libESD.so libAOD.so libANALYSISalice.so libPWGLFspectra.so libTender.so libTenderSupplies.so");
280   //plugin->SetAnalysisSource("AliSpectraBothHistoManager.cxx AliSpectraBothTrackCuts.cxx AliSpectraBothEventCuts.cxx AliSpectraBothPID.cxx AliAnalysisTaskSpectraBoth.cxx");
281     plugin->AddIncludePath("-I. -I$ROOTSYS/include -I$ALICE_ROOT/include -I$ALICE_ROOT/TOF ");
282   plugin->SetAdditionalLibs("libTender.so libTenderSupplies.so libPWGLFspectra.so");
283  // plugin->SetAnalysisSource("AliSpectraBothHistoManager.cxx AliSpectraBothTrackCuts.cxx AliSpectraBothEventCuts.cxx AliSpectraBothPID.cxx AliAnalysisTaskSpectraBoth.cxx");
284   plugin->SetOverwriteMode();
285   plugin->SetExecutableCommand("aliroot -q -b");  
286   plugin->SetRunMode(mode.Data());
287   plugin->SetNtestFiles(1);
288   //Set versions of used packages
289   plugin->SetAPIVersion("V1.1x");
290   plugin->SetROOTVersion(root.Data());
291   plugin->SetAliROOTVersion(aliroot.Data());
292   // Declare input data to be processed
293   plugin->SetGridDataDir(griddatadir.Data());
294   plugin->SetDataPattern(Form("%s/%s",datapattern.Data(),filename.Data()));
295   plugin->SetGridWorkingDir(Form("%s%s",gridworkingdir.Data(),daystring.Data()));
296   plugin->SetAnalysisMacro(Form("%s.C",jobsettings.Data()));
297   plugin->SetExecutable(Form("%s.sh",jobsettings.Data()));
298   plugin->SetJDLName(Form("Task%s.jdl",jobsettings.Data()));
299
300   if(mc)
301   {
302       plugin->SetRunPrefix(""); 
303     }  
304   else
305     {
306       plugin->SetRunPrefix("000"); 
307     }   
308   FILE* listruns=fopen("runs.txt","r");
309   Int_t irun;
310   while(!feof(listruns))
311   {
312       fscanf(listruns,"%d\n",&irun);
313       plugin->AddRunNumber(irun);
314   }
315   plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output 
316   plugin->SetMaxMergeFiles(25);
317   plugin->SetMergeExcludes("EventStat_temp.root"
318                             "event_stat.root");
319   plugin->SetMergeViaJDL(true);
320   plugin->SetTTL(15*3600);
321   // Optionally set input format (default xml-single)
322   plugin->SetInputFormat("xml-single");
323   // Optionally modify job price (default 1)
324   plugin->SetPrice(1);      
325   // Optionally modify split mode (default 'se')    
326   //plugin->SetSplitMaxInputFileNumber();
327   plugin->SetSplitMode("se");
328   return plugin;
329 }