]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/FLOW/macros/redoFinish.C
from nagmeh: addtask for pid config task and updates to pid config task
[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       gSystem->Unlink("mergedAnalysisResultsTemp.root");
45       fileTemp->Copy("mergedAnalysisResultsTemp.root");
46       delete fileTemp;
47     }
48     // Access <mergedFileName>:
49     mergedFile = TFile::Open(mergedFileFullPathName.Data(),"UPDATE");
50   }
51
52   // Access from <mergedFileName> the merged TDirectoryFile's for each method and from them the lists holding histograms:
53   
54   TList* mergedFileKeys = mergedFile->GetListOfKeys();
55   for(Int_t i=0; i<mergedFileKeys->GetEntries(); i++)
56   {
57     TDirectory* directory = dynamic_cast<TDirectory*>(mergedFile->Get(mergedFileKeys->At(i)->GetName()));
58     if (!directory) continue;
59
60     TList* listTemp = directory->GetListOfKeys();
61     if(!listTemp) continue;
62     for (Int_t icent=0; icent<listTemp->GetEntries(); icent++)
63     {
64       TList* list = dynamic_cast<TList*>(directory->Get(listTemp->At(icent)->GetName()));
65       if (!list) continue;
66       if(checkForCommonHistResults && (!CheckForCommonHistResults(list))) continue;
67       ////////////////////
68       if(TString(list->GetName()).Contains("MCEP"))
69       {
70         AliFlowAnalysisWithMCEventPlane* mcep = new AliFlowAnalysisWithMCEventPlane();
71         mcep->GetOutputHistograms(list);
72         mcep->Finish();
73         directory->Add(list,kTRUE);
74         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
75       }
76       // SP:
77       else if(TString(list->GetName()).Contains("SP"))
78       {
79         AliFlowAnalysisWithScalarProduct* sp = new AliFlowAnalysisWithScalarProduct();
80         sp->GetOutputHistograms(list);
81         sp->GetHistProConfig()->SetBinContent(1,(Int_t)bApplyCorrectionForNUA*
82                                               sp->GetHistProConfig()->GetEntries());
83         sp->Finish();
84         directory->Add(list,kTRUE);
85         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
86       }
87       // GFC:
88       else if(TString(list->GetName()).Contains("GFC"))
89       {
90         AliFlowAnalysisWithCumulants* gfc = new AliFlowAnalysisWithCumulants();
91         gfc->GetOutputHistograms(list);
92         gfc->Finish();
93         directory->Add(list,kTRUE);
94         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
95       }
96       // QC:
97       else if(TString(list->GetName()).Contains("QC"))
98       {
99         AliFlowAnalysisWithQCumulants* qc = new AliFlowAnalysisWithQCumulants();
100         qc->GetOutputHistograms(list);
101         qc->GetIntFlowFlags()->SetBinContent(3,(Int_t)bApplyCorrectionForNUA);
102         qc->GetIntFlowFlags()->SetBinContent(8,(Int_t)bApplyCorrectionForNUAVsM);
103         qc->GetIntFlowFlags()->SetBinContent(9,(Int_t)bPropagateErrorAlsoFromNIT);
104         qc->GetIntFlowFlags()->SetBinContent(11,(Int_t)bMinimumBiasReferenceFlow);
105         qc->Finish();
106         directory->Add(list,kTRUE);
107         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
108       }
109       // FQD:
110       else if(TString(list->GetName()).Contains("FQD"))
111       {
112         AliFlowAnalysisWithFittingQDistribution* fqd = new AliFlowAnalysisWithFittingQDistribution();
113         fqd->GetOutputHistograms(list);
114         fqd->Finish(kTRUE);
115         directory->Add(list,kTRUE);
116         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
117       }
118       // LYZ1SUM:
119       else if(TString(list->GetName()).Contains("LYZ1SUM"))
120       {
121         AliFlowAnalysisWithLeeYangZeros* lyz1sum = new AliFlowAnalysisWithLeeYangZeros();
122         lyz1sum->SetFirstRun(kTRUE);
123         lyz1sum->SetUseSum(kTRUE);
124         lyz1sum->GetOutputHistograms(list);
125         lyz1sum->Finish();
126         directory->Add(list,kTRUE);
127         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
128       }
129       // LYZ2SUM:
130       else if(TString(list->GetName()).Contains("LYZ2SUM"))
131       {
132         AliFlowAnalysisWithLeeYangZeros* lyz2sum = new AliFlowAnalysisWithLeeYangZeros();
133         lyz2sum->SetFirstRun(kFALSE);
134         lyz2sum->SetUseSum(kTRUE);
135         lyz2sum->GetOutputHistograms(list);
136         lyz2sum->Finish();
137         directory->Add(list,kTRUE);
138         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
139       }
140       // LYZ1PROD:
141       else if(TString(list->GetName()).Contains("LYZ1PROD"))
142       {
143         AliFlowAnalysisWithLeeYangZeros* lyz1prod = new AliFlowAnalysisWithLeeYangZeros();
144         lyz1prod->SetFirstRun(kTRUE);
145         lyz1prod->SetUseSum(kFALSE);
146         lyz1prod->GetOutputHistograms(list);
147         lyz1prod->Finish();
148         directory->Add(list,kTRUE);
149         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
150       }
151       // LYZ2PROD:
152       else if(TString(list->GetName()).Contains("LYZ2PROD"))
153       {
154         AliFlowAnalysisWithLeeYangZeros* lyz2prod = new AliFlowAnalysisWithLeeYangZeros();
155         lyz2prod->SetFirstRun(kFALSE);
156         lyz2prod->SetUseSum(kFALSE);
157         lyz2prod->GetOutputHistograms(list);
158         lyz2prod->Finish();
159         directory->Add(list,kTRUE);
160         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
161       }
162       // LYZEP:
163       else if(TString(list->GetName()).Contains("LYZEP"))
164       {
165         AliFlowAnalysisWithLYZEventPlane* lyzep = new AliFlowAnalysisWithLYZEventPlane();
166         lyzep->GetOutputHistograms(list);
167         lyzep->Finish();
168         directory->Add(list,kTRUE);
169         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
170       }
171       // MH:
172       else if(TString(list->GetName()).Contains("MH"))
173       {
174         AliFlowAnalysisWithMixedHarmonics* mh = new AliFlowAnalysisWithMixedHarmonics();
175         mh->GetOutputHistograms(list);
176         mh->GetAnalysisSettings()->SetBinContent(1,(Int_t)bApplyCorrectionForNUA);
177         mh->Finish();
178         directory->Add(list,kTRUE);
179         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
180       }
181       // NL:
182       else if(TString(list->GetName()).Contains("NL"))
183       {
184         AliFlowAnalysisWithNestedLoops* nl = new AliFlowAnalysisWithNestedLoops();
185         nl->GetOutputHistograms(list);
186         nl->Finish();
187         directory->Add(list,kTRUE);
188         directory->Write(directory->GetName(),TObject::kSingleKey+TObject::kWriteDelete);
189       }
190     }//for icent
191   }//
192
193     // Close the final output file:
194     delete mergedFile;
195
196     // Giving the final names if neccessary:
197     if(!(mergedFileName == outputFileName))
198     {
199       TSystemFile *outputFileFinal = new TSystemFile(mergedFileName.Data(),".");
200       outputFileFinal->Rename(outputFileName.Data());
201       delete outputFileFinal;
202       TSystemFile *mergedFileFinal = new TSystemFile("mergedAnalysisResultsTemp.root",".");
203       mergedFileFinal->Rename(mergedFileName.Data());
204       delete mergedFileFinal;
205     } // end of if(!(mergedFileName == outputFileName))
206
207     cout<<endl;
208
209 } // end of void redoFinish(Int_t mode=mLocal)
210
211 void LoadLibraries()
212 {
213   //--------------------------------------
214   // Load the needed libraries most of them already loaded by aliroot
215   //--------------------------------------
216   //gSystem->Load("libTree");
217   gSystem->Load("libGeom");
218   gSystem->Load("libVMC");
219   gSystem->Load("libXMLIO");
220   gSystem->Load("libPhysics");
221
222   // for AliRoot
223   gSystem->Load("libANALYSIS");
224   gSystem->Load("libANALYSISalice");
225   gSystem->Load("libPWGflowBase");
226   gSystem->Load("libPWGflowTasks");
227 } // end of void LoadLibrariesRF(const libModes mode)
228
229 Bool_t CheckForCommonHistResults(TList* list) {
230     // check for common hist results. Redmer Alexander Bertens, r.a.bertens@cern.ch
231     for(Int_t i(0); i < list->GetEntries(); i++) if(((list->At(i))->IsA())->GetBaseClass("AliFlowCommonHistResults")) return kTRUE;
232     return kFALSE;
233 }