adding some drawing macros for balance functions
[u/mrichter/AliRoot.git] / PWGCF / EBYE / macros / runBalanceFunctionMC.C
CommitLineData
6e28a437 1enum analysisModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};\r
2enum analysisTypes {mESD,mAOD,mMC,mMCESD};\r
3\r
4//\r
5class AliAnalysisGrid;\r
6class AliAnalysisTaskBF;\r
7class AliBalance;\r
8\r
9//Centrality stuff\r
10Int_t binfirst = 0; //where do we start numbering bins\r
11Int_t binlast = 8; //where do we stop numbering bins\r
12const Int_t numberOfCentralityBins = 9;\r
13Float_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile\r
14Float_t impactParameterArray[numberOfCentralityBins+1] = {0.0,3.79,5.30,7.41,9.04,10.40,11.61,12.68,13.67,14.63}; // in fm (impact parametger taken from the MC header)\r
15\r
d9f855f3 16//Acceptance parameterization\r
17Bool_t kUseAcceptance = kTRUE;\r
18const char *acceptanceFilename = "efficiencyALICE.root";\r
19TF1 *fParameterization[numberOfCentralityBins];\r
20\r
21//Analyze a particle\r
22Int_t gPdgCode = -1;\r
23\r
6e28a437 24//________________________________________________________________________//\r
25void runBalanceFunctionMC(Int_t mode = mLocal, \r
26 Int_t type = mMC,\r
27 Bool_t DATA = kFALSE) {\r
28 // Time:\r
29 TStopwatch timer;\r
30 timer.Start();\r
31 \r
32 //Check analysis mode\r
33 if((mode < 0) || (mode > 4)) {\r
34 Printf("Analysis mode not recognized!");\r
35 Printf("You can select out of 0: local, 1: local with par files, 2: proof, 3: grid, 4: grid with par files");\r
36 return;\r
37 }\r
38 \r
39 //Check analysis type\r
40 if((type < 0) || (type > 3)) {\r
41 Printf("Analysis type not recognized!");\r
42 Printf("You can select out of 0: ESD, 1: AOD, 2: MC (stack), 3: MC (from the ESD)");\r
43 return;\r
44 }\r
45 \r
46 // Load needed libraries:\r
47 LoadLibraries(mode);\r
48 \r
49\r
50 // Create and configure the AliEn plug-in:\r
51 if(mode == mGrid || mode == mGridPAR) {\r
52 gROOT->LoadMacro("CreateAlienHandler.C");\r
53 AliAnalysisGrid *alienHandler = CreateAlienHandler(runListFileName); \r
54 if (!alienHandler) return;\r
55 }\r
56 // Chains: \r
57 if(mode == mLocal || mode == mLocalPAR) {\r
58 TChain* chain = 0x0;\r
59 if((type == mESD)||(type == mMCESD)) \r
60 chain = new TChain("esdTree");\r
61 else if(type == mAOD)\r
62 chain = new TChain("aodTree");\r
63 else if(type == mMC)\r
64 chain = new TChain("TE");\r
65\r
d9f855f3 66 TString filename = "galice.root";\r
67 chain->Add(filename.Data());\r
6e28a437 68 }\r
d9f855f3 69\r
6e28a437 70 //Proof\r
71 if(mode == mPROOF) {\r
72 gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));\r
73 }\r
74 \r
75 // analysis manager\r
76 AliAnalysisManager* mgr = new AliAnalysisManager("balanceFunctionManager");\r
77 if(mode == mGrid || mode == mGridPAR)\r
78 mgr->SetGridHandler(alienHandler);\r
79 \r
80 // input handler (ESD or AOD)\r
81 AliVEventHandler* inputH = NULL;\r
82 if((type == mESD)||(type == mMCESD)||(type == mMC)) \r
83 inputH = new AliESDInputHandler();\r
84 else if(type == mAOD)\r
85 inputH = new AliAODInputHandler();\r
86 mgr->SetInputEventHandler(inputH);\r
87 \r
88 // mc event handler\r
89 if((type == mMC) || (type == mMCESD)) {\r
90 AliMCEventHandler* mchandler = new AliMCEventHandler();\r
91 // Not reading track references\r
92 mchandler->SetReadTR(kFALSE);\r
93 mgr->SetMCtruthEventHandler(mchandler);\r
94 } \r
95\r
96 if(mAOD){\r
97 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");\r
98 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();\r
99\r
100 // Add physics selection task (NOT needed for AODs)\r
101 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");\r
102 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(DATA);\r
103 }\r
104\r
d9f855f3 105 //Setup the parameterization\r
106 if(kUseAcceptance) {\r
107 TFile *gParamFile = TFile::Open(acceptanceFilename);\r
108 if((!gParamFile) || (!gParamFile->IsOpen())) {\r
109 Printf("File %s not found!!!",acceptanceFilename);\r
110 return;\r
111 }\r
112\r
113 TString gParamName;\r
114 for(Int_t iCentrality = 0; iCentrality < numberOfCentralityBins; iCentrality++) {\r
115 gParamName = "gParamCentrality"; gParamName += iCentrality;\r
116 fParameterization[iCentrality] = dynamic_cast<TF1 *>(gParamFile->Get(gParamName.Data()));\r
117 }\r
118 }\r
119\r
6e28a437 120 //Add the BF task (all centralities)\r
121 gROOT->LoadMacro("AddTaskBalanceMCCentralityTrain.C"); \r
122 for (Int_t i=binfirst; i<binlast+1; i++) {\r
123 Float_t lowCentralityBinEdge = centralityArray[i];\r
124 Float_t highCentralityBinEdge = centralityArray[i+1];\r
125 Printf("\nWagon for centrality bin %i: %.0f-%.0f",i,lowCentralityBinEdge,highCentralityBinEdge);\r
126 AddTaskBalanceMCCentralityTrain(lowCentralityBinEdge,\r
127 highCentralityBinEdge,\r
128 impactParameterArray[i],\r
129 impactParameterArray[i+1],\r
130 kTRUE,\r
d9f855f3 131 10.,0.3,1.5,-0.8,0.8,\r
132 fParameterization[i],\r
133 gPdgCode);\r
6e28a437 134 }\r
135\r
136 // enable debug printouts\r
137 mgr->SetDebugLevel(2);\r
138 mgr->SetUseProgressBar(1,100);\r
139 if (!mgr->InitAnalysis()) return;\r
140 mgr->PrintStatus();\r
141 \r
142 // start analysis\r
143 if(mode == mLocal || mode == mLocalPAR) \r
144 mgr->StartAnalysis("local",chain);\r
145 else if(mode == mPROOF) \r
146 mgr->StartAnalysis("proof",dataDir,nRuns,offset);\r
147 else if(mode == mGrid || mode == mGridPAR) \r
148 mgr->StartAnalysis("grid");\r
149 \r
150 // Print real and CPU time used for analysis: \r
151 timer.Stop();\r
152 timer.Print();\r
153}\r
154\r
155//=============================================================//\r
156void LoadLibraries(const analysisModes mode) { \r
157 //--------------------------------------\r
158 // Load the needed libraries most of them already loaded by aliroot\r
159 //--------------------------------------\r
160 gSystem->Load("libCore.so"); \r
161 gSystem->Load("libGeom.so");\r
162 gSystem->Load("libVMC.so");\r
163 gSystem->Load("libPhysics.so");\r
164 gSystem->Load("libTree.so");\r
165\r
166 //----------------------------------------------------------\r
167 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< \r
168 //----------------------------------------------------------\r
169 if (mode==mLocal || mode==mGrid || mode == mGridPAR) {\r
170 //--------------------------------------------------------\r
171 // If you want to use already compiled libraries \r
172 // in the aliroot distribution\r
173 //--------------------------------------------------------\r
174 gSystem->Load("libSTEERBase.so");\r
175 gSystem->Load("libESD.so");\r
176 gSystem->Load("libAOD.so");\r
177 gSystem->Load("libANALYSIS.so");\r
178 gSystem->Load("libANALYSISalice.so");\r
1f7eb4d0 179 gSystem->Load("libEventMixing.so");\r
a022cbd0 180 gSystem->Load("libPWGCFebye.so");\r
6e28a437 181 // Use AliRoot includes to compile our task\r
182 gROOT->ProcessLine(".include $ALICE_ROOT/include");\r
183 }\r
184 \r
185 else if (mode == mLocalPAR) {\r
186 //--------------------------------------------------------\r
187 //If you want to use root and par files from aliroot\r
188 //-------------------------------------------------------- \r
189 SetupPar("STEERBase");\r
190 SetupPar("ESD");\r
191 SetupPar("AOD");\r
192 SetupPar("ANALYSIS");\r
193 SetupPar("ANALYSISalice");\r
a022cbd0 194 SetupPar("PWGCFebye");\r
6e28a437 195}\r
196 \r
197 //---------------------------------------------------------\r
198 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>\r
199 //---------------------------------------------------------\r
200 else if (mode==mPROOF) {\r
201 // Connect to proof\r
202 printf("*** Connect to PROOF ***\n");\r
203 gEnv->SetValue("XSec.GSI.DelegProxy","2");\r
204 // Put appropriate username here\r
205 TProof::Open("alice-caf.cern.ch");\r
206 //TProof::Open("skaf.saske.sk");\r
207 //TProof::Open("prf000-iep-grid.saske.sk");\r
208\r
209 gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-12-AN");\r
210 } \r
211 \r
212} // end of void LoadLibraries(const anaModes mode)\r
213\r
214//======================================================================//\r
215void SetupPar(char* pararchivename) {\r
216 //Load par files, create analysis libraries\r
217 //For testing, if par file already decompressed and modified\r
218 //classes then do not decompress.\r
219 \r
220 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; \r
221 TString parpar(Form("%s.par", pararchivename)) ; \r
222 if ( gSystem->AccessPathName(parpar.Data()) ) {\r
223 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;\r
224 TString processline(Form(".! make %s", parpar.Data())) ; \r
225 gROOT->ProcessLine(processline.Data()) ;\r
226 gSystem->ChangeDirectory(cdir) ; \r
227 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;\r
228 gROOT->ProcessLine(processline.Data()) ;\r
229 } \r
230 if ( gSystem->AccessPathName(pararchivename) ) { \r
231 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;\r
232 gROOT->ProcessLine(processline.Data());\r
233 }\r
234 \r
235 TString ocwd = gSystem->WorkingDirectory();\r
236 gSystem->ChangeDirectory(pararchivename);\r
237 \r
238 // check for BUILD.sh and execute\r
239 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {\r
240 printf("*******************************\n");\r
241 printf("*** Building PAR archive ***\n");\r
242 cout<<pararchivename<<endl;\r
243 printf("*******************************\n");\r
244 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {\r
245 Error("runProcess","Cannot Build the PAR Archive! - Abort!");\r
246 return -1;\r
247 }\r
248 }\r
249 // check for SETUP.C and execute\r
250 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {\r
251 printf("*******************************\n");\r
252 printf("*** Setup PAR archive ***\n");\r
253 cout<<pararchivename<<endl;\r
254 printf("*******************************\n");\r
255 gROOT->Macro("PROOF-INF/SETUP.C");\r
256 }\r
257 \r
258 gSystem->ChangeDirectory(ocwd.Data());\r
259 printf("Current dir: %s\n", ocwd.Data());\r
260\r
261} // end of void SetupPar(char* pararchivename) \r
262\r