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