]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/FLOW/macros/redoFinish.C
add a convenience script to load flow libraries
[u/mrichter/AliRoot.git] / PWGCF / FLOW / macros / redoFinish.C
1 // Macro redoFinish.C is typically used after the merging macros (mergeOutput.C or
2 // mergeOutputOnGrid.C) have been used to produce the merged, large statistics
3 // file of flow analysis. Results stored in merged file are WRONG because after
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
11 // Name of the merged, large statistics file obtained with the merging macros:
12 TString mergedFileName = "mergedAnalysisResults.root";
13 // Final output file name holding correct final results for large statistics sample:
14 TString outputFileName = "AnalysisResults.root";
15
16 Bool_t bApplyCorrectionForNUA = kFALSE; // apply correction for non-uniform acceptance
17 Bool_t bApplyCorrectionForNUAVsM = kFALSE; // apply correction for non-uniform acceptance in each multiplicity bin independently
18 Bool_t bPropagateErrorAlsoFromNIT = kFALSE; // propagate error also from non-isotropic terms
19 Bool_t bMinimumBiasReferenceFlow = kTRUE; // store in CRH for reference flow the result obtained wihout rebinning in multiplicity (kTRUE)
20 Bool_t checkForCommonHistResults = kTRUE; // check explicitely if the TList AliFlowCommonHistResults is available in the output
21
22 void redoFinish()
23 {
24   LoadLibraries();
25
26   TString mergedFileFullPathName(gSystem->pwd());
27   mergedFileFullPathName+="/";
28   mergedFileFullPathName+=mergedFileName.Data();
29   TFile *mergedFile = NULL;
30   if(gSystem->AccessPathName(mergedFileFullPathName.Data(),kFileExists))
31   {
32     cout<<endl;
33     cout<<" WARNING: Couldn't find a file: "<<mergedFileName.Data()<<endl;
34     cout<<"          in directory "<<gSystem->pwd()<<" !!!!"<<endl;
35     cout<<endl;
36     exit(0);
37   }
38   else
39   {
40     // Create temporarily copy of <mergedFileName> if neccessary:
41     if(!(mergedFileName == outputFileName))
42     {
43       TSystemFile *fileTemp = new TSystemFile(mergedFileFullPathName.Data(),".");
44       fileTemp->Copy("mergedAnalysisResultsTemp.root");
45       delete fileTemp;
46     }
47     // Access <mergedFileName>:
48     mergedFile = TFile::Open(mergedFileFullPathName.Data(),"UPDATE");
49   }
50
51   // Access from <mergedFileName> the merged TDirectoryFile's for each method and from them the lists holding histograms:
52   
53   TList* mergedFileKeys = mergedFile->GetListOfKeys();
54   for(Int_t i=0; i<mergedFileKeys->GetEntries(); i++)
55   {
56     TDirectory* directory = dynamic_cast<TDirectory*>(mergedFile->Get(mergedFileKeys->At(i)->GetName()));
57     if (!directory) continue;
58
59     TList* listTemp = directory->GetListOfKeys();
60     if(!listTemp) continue;
61     for (Int_t icent=0; icent<listTemp->GetEntries(); icent++)
62     {
63       TList* list = dynamic_cast<TList*>(directory->Get(listTemp->At(icent)->GetName()));
64       if (!list) continue;
65       if(checkForCommonHistResults && (!CheckForCommonHistResults(list))) continue;
66       ////////////////////
67       if(TString(list->GetName()).Contains("MCEP"))
68       {
69         AliFlowAnalysisWithMCEventPlane* mcep = new AliFlowAnalysisWithMCEventPlane();
70         mcep->GetOutputHistograms(list);
71         mcep->Finish();
72         directory->Add(list,kTRUE);
73         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
74       }
75       // SP:
76       else if(TString(list->GetName()).Contains("SP"))
77       {
78         AliFlowAnalysisWithScalarProduct* sp = new AliFlowAnalysisWithScalarProduct();
79         sp->GetOutputHistograms(list);
80         //sp->GetHistProFlags()->SetBinContent(1,(Int_t)bApplyCorrectionForNUA);
81         sp->Finish();
82         directory->Add(list,kTRUE);
83         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
84       }
85       // GFC:
86       else if(TString(list->GetName()).Contains("GFC"))
87       {
88         AliFlowAnalysisWithCumulants* gfc = new AliFlowAnalysisWithCumulants();
89         gfc->GetOutputHistograms(list);
90         gfc->Finish();
91         directory->Add(list,kTRUE);
92         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
93       }
94       // QC:
95       else if(TString(list->GetName()).Contains("QC"))
96       {
97         AliFlowAnalysisWithQCumulants* qc = new AliFlowAnalysisWithQCumulants();
98         qc->GetOutputHistograms(list);
99         qc->GetIntFlowFlags()->SetBinContent(3,(Int_t)bApplyCorrectionForNUA);
100         qc->GetIntFlowFlags()->SetBinContent(8,(Int_t)bApplyCorrectionForNUAVsM);
101         qc->GetIntFlowFlags()->SetBinContent(9,(Int_t)bPropagateErrorAlsoFromNIT);
102         qc->GetIntFlowFlags()->SetBinContent(11,(Int_t)bMinimumBiasReferenceFlow);
103         qc->Finish();
104         directory->Add(list,kTRUE);
105         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
106       }
107       // FQD:
108       else if(TString(list->GetName()).Contains("FQD"))
109       {
110         AliFlowAnalysisWithFittingQDistribution* fqd = new AliFlowAnalysisWithFittingQDistribution();
111         fqd->GetOutputHistograms(list);
112         fqd->Finish(kTRUE);
113         directory->Add(list,kTRUE);
114         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
115       }
116       // LYZ1SUM:
117       else if(TString(list->GetName()).Contains("LYZ1SUM"))
118       {
119         AliFlowAnalysisWithLeeYangZeros* lyz1sum = new AliFlowAnalysisWithLeeYangZeros();
120         lyz1sum->SetFirstRun(kTRUE);
121         lyz1sum->SetUseSum(kTRUE);
122         lyz1sum->GetOutputHistograms(list);
123         lyz1sum->Finish();
124         directory->Add(list,kTRUE);
125         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
126       }
127       // LYZ2SUM:
128       else if(TString(list->GetName()).Contains("LYZ2SUM"))
129       {
130         AliFlowAnalysisWithLeeYangZeros* lyz2sum = new AliFlowAnalysisWithLeeYangZeros();
131         lyz2sum->SetFirstRun(kFALSE);
132         lyz2sum->SetUseSum(kTRUE);
133         lyz2sum->GetOutputHistograms(list);
134         lyz2sum->Finish();
135         directory->Add(list,kTRUE);
136         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
137       }
138       // LYZ1PROD:
139       else if(TString(list->GetName()).Contains("LYZ1PROD"))
140       {
141         AliFlowAnalysisWithLeeYangZeros* lyz1prod = new AliFlowAnalysisWithLeeYangZeros();
142         lyz1prod->SetFirstRun(kTRUE);
143         lyz1prod->SetUseSum(kFALSE);
144         lyz1prod->GetOutputHistograms(list);
145         lyz1prod->Finish();
146         directory->Add(list,kTRUE);
147         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
148       }
149       // LYZ2PROD:
150       else if(TString(list->GetName()).Contains("LYZ2PROD"))
151       {
152         AliFlowAnalysisWithLeeYangZeros* lyz2prod = new AliFlowAnalysisWithLeeYangZeros();
153         lyz2prod->SetFirstRun(kFALSE);
154         lyz2prod->SetUseSum(kFALSE);
155         lyz2prod->GetOutputHistograms(list);
156         lyz2prod->Finish();
157         directory->Add(list,kTRUE);
158         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
159       }
160       // LYZEP:
161       else if(TString(list->GetName()).Contains("LYZEP"))
162       {
163         AliFlowAnalysisWithLYZEventPlane* lyzep = new AliFlowAnalysisWithLYZEventPlane();
164         lyzep->GetOutputHistograms(list);
165         lyzep->Finish();
166         directory->Add(list,kTRUE);
167         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
168       }
169       // MH:
170       else if(TString(list->GetName()).Contains("MH"))
171       {
172         AliFlowAnalysisWithMixedHarmonics* mh = new AliFlowAnalysisWithMixedHarmonics();
173         mh->GetOutputHistograms(list);
174         mh->GetAnalysisSettings()->SetBinContent(1,(Int_t)bApplyCorrectionForNUA);
175         mh->Finish();
176         directory->Add(list,kTRUE);
177         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
178       }
179       // NL:
180       else if(TString(list->GetName()).Contains("NL"))
181       {
182         AliFlowAnalysisWithNestedLoops* nl = new AliFlowAnalysisWithNestedLoops();
183         nl->GetOutputHistograms(list);
184         nl->Finish();
185         directory->Add(list,kTRUE);
186         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
187       }
188     }//for icent
189   }//
190
191     // Close the final output file:
192     delete mergedFile;
193
194     // Giving the final names if neccessary:
195     if(!(mergedFileName == outputFileName))
196     {
197       TSystemFile *outputFileFinal = new TSystemFile(mergedFileName.Data(),".");
198       outputFileFinal->Rename(outputFileName.Data());
199       delete outputFileFinal;
200       TSystemFile *mergedFileFinal = new TSystemFile("mergedAnalysisResultsTemp.root",".");
201       mergedFileFinal->Rename(mergedFileName.Data());
202       delete mergedFileFinal;
203     } // end of if(!(mergedFileName == outputFileName))
204
205     cout<<endl;
206
207 } // end of void redoFinish(Int_t mode=mLocal)
208
209 void LoadLibraries()
210 {
211   //--------------------------------------
212   // Load the needed libraries most of them already loaded by aliroot
213   //--------------------------------------
214   //gSystem->Load("libTree");
215   gSystem->Load("libGeom");
216   gSystem->Load("libVMC");
217   gSystem->Load("libXMLIO");
218   gSystem->Load("libPhysics");
219
220   // for AliRoot
221   gSystem->Load("libANALYSIS");
222   gSystem->Load("libANALYSISalice");
223   gSystem->Load("libPWGflowBase");
224   gSystem->Load("libPWGflowTasks");
225 } // end of void LoadLibrariesRF(const libModes mode)
226
227 Bool_t CheckForCommonHistResults(TList* list) {
228     // check for common hist results. Redmer Alexander Bertens, r.a.bertens@cern.ch
229     for(Int_t i(0); i < list->GetEntries(); i++) if(((list->At(i))->IsA())->GetBaseClass("AliFlowCommonHistResults")) return kTRUE;
230     return kFALSE;
231 }