hooks for PMD flow analysis
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / redoFinish.C
CommitLineData
441ea1cf 1// Macro redoFinish.C is typically used after the merging macros (mergeOutput.C or
021fb870 2// mergeOutputOnGrid.C) have been used to produce the merged, large statistics
441ea1cf 3// file of flow analysis. Results stored in merged file are WRONG because after
021fb870 4// merging the results from small statistics files are trivially summed up in all
5// histograms. This is taken into account and corrected for with macro redoFinish.C.
6// Another typical use of the macro redoFinish.C is to repeat the call to Finish()
7// in all classes, but with different values of some settings which might modify
8// the final results (Example: redo the Finish() and apply correction for detector
9// effects in QC code because by default this correction is switched off).
10
441ea1cf 11// Name of the merged, large statistics file obtained with the merging macros:
12TString mergedFileName = "outputCentralityTrain.root";
021fb870 13// Final output file name holding correct final results for large statistics sample:
441ea1cf 14TString outputFileName = "AnalysisResults.root";
021fb870 15// Methods for which the flow analysis will be redone:
16const Int_t nMethods = 12;
17TString method[nMethods] = {"MCEP","SP","GFC","QC","FQD","LYZ1SUM","LYZ1PROD","LYZ2SUM","LYZ2PROD","LYZEP","MH","NL"};
18// Methods for which some settings can be modified before redoing Finish():
19// QC:
20Bool_t bApplyCorrectionForNUA = kFALSE; // apply correction for non-uniform acceptance
21Bool_t bApplyCorrectionForNUAVsM = kFALSE; // apply correction for non-uniform acceptance in each multiplicity bin independently
22Bool_t bPropagateErrorAlsoFromNIT = kFALSE; // propagate error also from non-isotropic terms
b77b6434 23Bool_t bMinimumBiasReferenceFlow = kTRUE; // store in CRH for reference flow the result obtained wihout rebinning in multiplicity (kTRUE)
ad87ae62 24
6a6afe42 25enum libModes {mLocal,mLocalSource};
26
441ea1cf 27void redoFinish(TString type="ESD global", Int_t mode=mLocal)
6a6afe42 28{
441ea1cf 29 // type: type of analysis can be ESD, AOD, MC, ....
30 // (if type="" output files are from simulation 'on the fly')
31 // mode: if mode = mLocal: analyze data on your computer using aliroot
32 // if mode = mLocalSource: analyze data on your computer using root + source files
ad87ae62 33
441ea1cf 34 // Load needed libraries:
35 LoadLibrariesRF(mode);
021fb870 36
441ea1cf 37 // Accessing <mergedFileName>:
38 TString mergedFileFullPathName(gSystem->pwd());
39 mergedFileFullPathName+="/";
40 mergedFileFullPathName+=mergedFileName.Data();
41 TFile *mergedFile = NULL;
42 if(gSystem->AccessPathName(mergedFileFullPathName.Data(),kFileExists))
43 {
44 cout<<endl;
45 cout<<" WARNING: Couldn't find a file: "<<mergedFileName.Data()<<endl;
46 cout<<" in directory "<<gSystem->pwd()<<" !!!!"<<endl;
47 cout<<endl;
48 exit(0);
49 }
50 else
51 {
021fb870 52 // Create temporarily copy of <mergedFileName> if neccessary:
53 if(!(mergedFileName == outputFileName))
54 {
441ea1cf 55 TSystemFile *fileTemp = new TSystemFile(mergedFileFullPathName.Data(),".");
56 fileTemp->Copy("mergedAnalysisResultsTemp.root");
57 delete fileTemp;
021fb870 58 }
59 // Access <mergedFileName>:
60 mergedFile = TFile::Open(mergedFileFullPathName.Data(),"UPDATE");
441ea1cf 61 }
62
63 // Access from <mergedFileName> the merged TDirectoryFile's for each method and from them the lists holding histograms:
64 for(Int_t i=0; i<nMethods; i++)
ad87ae62 65 {
441ea1cf 66 TString directoryName("");
67 TDirectory* directory = NULL;
68 cout<<endl;
69 // Form a file name for each method:
70 directoryName+="output";
71 directoryName+=method[i].Data();
72 directoryName+="analysis";
73 directoryName+=type.Data();
74 // Access this file:
75 directory = (TDirectory*)mergedFile->FindObjectAny(directoryName.Data());
76 // Form a list name for each method:
77 if(!directory)
57340a27 78 {
441ea1cf 79 cout<<" WARNING: Couldn't find a TDirectory "<<directoryName.Data()<<" in file "<<mergedFileName.Data()<<endl;
80 continue;
81 }
ad87ae62 82
441ea1cf 83 TList* listTemp = directory->GetListOfKeys();
84 if (!listTemp)
85 {
86 cout<<" WARNING: Accessing TList from TDirectoryFile failed for method "<<method[i].Data()<<" !!!!"<<endl;
87 cout<<" Did you actually specify "<<method[i].Data()<<" in the analysis?"<<endl;
88 cout<<endl;
89 continue;
90 }
91
92 for (Int_t icent=0; icent<listTemp->GetEntries(); icent++)
93 {
94 TList* list = dynamic_cast<TList*>(directory->Get(listTemp->At(icent)->GetName()));
95 if (!list) continue;
96
97 ////////////////////
98 if(TString(list->GetName()).Contains("cobjMCEP"))
99 {
100 AliFlowAnalysisWithMCEventPlane* mcep = new AliFlowAnalysisWithMCEventPlane();
101 mcep->GetOutputHistograms(list);
102 mcep->Finish();
103 directory->Add(list,kTRUE);
104 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
105 }
106 // SP:
107 else if(TString(list->GetName()).Contains("cobjSP"))
108 {
109 AliFlowAnalysisWithScalarProduct* sp = new AliFlowAnalysisWithScalarProduct();
110 sp->GetOutputHistograms(list);
111 sp->Finish();
112 directory->Add(list,kTRUE);
113 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
114 }
115 // GFC:
116 else if(TString(list->GetName()).Contains("cobjGFC"))
117 {
118 AliFlowAnalysisWithCumulants* gfc = new AliFlowAnalysisWithCumulants();
119 gfc->GetOutputHistograms(list);
120 gfc->Finish();
121 directory->Add(list,kTRUE);
122 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
123 }
124 // QC:
125 else if(TString(list->GetName()).Contains("cobjQC"))
126 {
127 AliFlowAnalysisWithQCumulants* qc = new AliFlowAnalysisWithQCumulants();
128 qc->GetOutputHistograms(list);
129 qc->GetIntFlowFlags()->SetBinContent(3,(Int_t)bApplyCorrectionForNUA);
130 qc->GetIntFlowFlags()->SetBinContent(8,(Int_t)bApplyCorrectionForNUAVsM);
131 qc->GetIntFlowFlags()->SetBinContent(9,(Int_t)bPropagateErrorAlsoFromNIT);
132 qc->GetIntFlowFlags()->SetBinContent(11,(Int_t)bMinimumBiasReferenceFlow);
133 qc->Finish();
134 directory->Add(list,kTRUE);
135 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
136 }
137 // FQD:
138 else if(TString(list->GetName()).Contains("cobjFQD"))
139 {
140 AliFlowAnalysisWithFittingQDistribution* fqd = new AliFlowAnalysisWithFittingQDistribution();
141 fqd->GetOutputHistograms(list);
142 fqd->Finish(kTRUE);
143 directory->Add(list,kTRUE);
144 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
145 }
146 // LYZ1SUM:
147 else if(TString(list->GetName()).Contains("cobjLYZ1SUM"))
148 {
149 AliFlowAnalysisWithLeeYangZeros* lyz1sum = new AliFlowAnalysisWithLeeYangZeros();
150 lyz1sum->SetFirstRun(kTRUE);
151 lyz1sum->SetUseSum(kTRUE);
152 lyz1sum->GetOutputHistograms(list);
153 lyz1sum->Finish();
154 directory->Add(list,kTRUE);
155 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
156 }
157 // LYZ2SUM:
158 else if(TString(list->GetName()).Contains("cobjLYZ2SUM"))
159 {
160 AliFlowAnalysisWithLeeYangZeros* lyz2sum = new AliFlowAnalysisWithLeeYangZeros();
161 lyz2sum->SetFirstRun(kFALSE);
162 lyz2sum->SetUseSum(kTRUE);
163 lyz2sum->GetOutputHistograms(list);
164 lyz2sum->Finish();
165 directory->Add(list,kTRUE);
166 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
167 }
168 // LYZ1PROD:
169 else if(TString(list->GetName()).Contains("cobjLYZ1PROD"))
170 {
171 AliFlowAnalysisWithLeeYangZeros* lyz1prod = new AliFlowAnalysisWithLeeYangZeros();
172 lyz1prod->SetFirstRun(kTRUE);
173 lyz1prod->SetUseSum(kFALSE);
174 lyz1prod->GetOutputHistograms(list);
175 lyz1prod->Finish();
176 directory->Add(list,kTRUE);
177 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
178 }
179 // LYZ2PROD:
180 else if(TString(list->GetName()).Contains("cobjLYZ2PROD"))
181 {
182 AliFlowAnalysisWithLeeYangZeros* lyz2prod = new AliFlowAnalysisWithLeeYangZeros();
183 lyz2prod->SetFirstRun(kFALSE);
184 lyz2prod->SetUseSum(kFALSE);
185 lyz2prod->GetOutputHistograms(list);
186 lyz2prod->Finish();
187 directory->Add(list,kTRUE);
188 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
189 }
190 // LYZEP:
191 else if(TString(list->GetName()).Contains("cobjLYZEP"))
192 {
193 AliFlowAnalysisWithLYZEventPlane* lyzep = new AliFlowAnalysisWithLYZEventPlane();
194 lyzep->GetOutputHistograms(list);
195 lyzep->Finish();
196 directory->Add(list,kTRUE);
197 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
198 }
199 // MH:
200 else if(TString(list->GetName()).Contains("cobjMH"))
201 {
202 AliFlowAnalysisWithMixedHarmonics* mh = new AliFlowAnalysisWithMixedHarmonics();
203 mh->GetOutputHistograms(list);
204 mh->Finish();
205 directory->Add(list,kTRUE);
206 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
207 }
208 // NL:
209 else if(TString(list->GetName()).Contains("cobjNL"))
210 {
211 AliFlowAnalysisWithNestedLoops* nl = new AliFlowAnalysisWithNestedLoops();
212 nl->GetOutputHistograms(list);
213 nl->Finish();
214 directory->Add(list,kTRUE);
215 directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
216 }
217 }//for icent
218 }// end of for(Int_t i=0;i<nMethods;i++)
219
220 // Close the final output file:
221 delete mergedFile;
222
223 // Giving the final names if neccessary:
224 if(!(mergedFileName == outputFileName))
225 {
226 TSystemFile *outputFileFinal = new TSystemFile(mergedFileName.Data(),".");
227 outputFileFinal->Rename(outputFileName.Data());
228 delete outputFileFinal;
229 TSystemFile *mergedFileFinal = new TSystemFile("mergedAnalysisResultsTemp.root",".");
230 mergedFileFinal->Rename(mergedFileName.Data());
231 delete mergedFileFinal;
232 } // end of if(!(mergedFileName == outputFileName))
233
234 cout<<endl;
9455e15e 235
021fb870 236} // end of void redoFinish(Int_t mode=mLocal)
441ea1cf 237
238void LoadLibrariesRF(const libModes mode)
239{
240
6a6afe42 241 //--------------------------------------
242 // Load the needed libraries most of them already loaded by aliroot
243 //--------------------------------------
ad87ae62 244 //gSystem->Load("libTree");
5d040cf3 245 gSystem->Load("libGeom");
246 gSystem->Load("libVMC");
247 gSystem->Load("libXMLIO");
248 gSystem->Load("libPhysics");
441ea1cf 249
6a6afe42 250 //----------------------------------------------------------
441ea1cf 251 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
6a6afe42 252 //----------------------------------------------------------
441ea1cf 253 if (mode==mLocal)
254 {
6a6afe42 255 //--------------------------------------------------------
441ea1cf 256 // If you want to use already compiled libraries
6a6afe42 257 // in the aliroot distribution
258 //--------------------------------------------------------
259
441ea1cf 260 //==================================================================================
261 //load needed libraries:
262 gSystem->AddIncludePath("-I$ROOTSYS/include");
263 //gSystem->Load("libTree");
264
265 // for AliRoot
266 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
267 gSystem->Load("libANALYSIS");
268 gSystem->Load("libPWG2flowCommon");
269 //cerr<<"libPWG2flowCommon loaded ..."<<endl;
6a6afe42 270
6a6afe42 271 }
441ea1cf 272
273 else if (mode==mLocalSource)
274 {
275
6a6afe42 276 // In root inline compile
441ea1cf 277
278 // Constants
6a6afe42 279 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
280 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
441ea1cf 281
6a6afe42 282 // Flow event
441ea1cf 283 gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+");
284 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");
285 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");
5062cb0f 286 gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
441ea1cf 287
d91df799 288 // Output histograms
6a6afe42 289 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
290 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
291 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
292 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
441ea1cf 293
d91df799 294 // Functions needed for various methods
295 gROOT->LoadMacro("AliFlowCommon/AliCumulantsFunctions.cxx+");
296 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZEventPlane.cxx+");
441ea1cf 297
d91df799 298 // Flow Analysis code for various methods
441ea1cf 299 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithMCEventPlane.cxx+");
d91df799 300 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithScalarProduct.cxx+");
301 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithLYZEventPlane.cxx+");
302 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithLeeYangZeros.cxx+");
303 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithCumulants.cxx+");
441ea1cf 304 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx+");
d91df799 305 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithFittingQDistribution.cxx+");
441ea1cf 306 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithMixedHarmonics.cxx+");
307 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithNestedLoops.cxx+");
308
309 cout << "finished loading macros!" << endl;
310
311 } // end of else if (mode==mLocalSource)
312
ad87ae62 313} // end of void LoadLibrariesRF(const libModes mode)
6a6afe42 314
441ea1cf 315