1 //=====================================================================================//
2 // Macro makeWeights.C is used to make phi, pt and eta weights. Before using the macro //
3 // makeWeights.C you should already have available the output .root files from various //
4 // methods stored in the common output file "AnalysisResults.root". When calling this //
5 // macro you must specify the analysis type and the method whose output file you would //
6 // like to use to make the weights for the subsequent runs (for cumulants, GFC and QC, //
7 // you must also specify the cumulant order). //
8 //=====================================================================================//
10 //========================= phi-weights ========================
11 // Phi-weights are obtained by inverting and normalizing the
12 // azimuthal acceptance profile. This procedure isn't applicable
13 // if the detector has a gap in azimuthal acceptance (i.e. if
14 // there exists a phi bin with no entries in the histogram for
15 // detector's azimuthal acceptance profile).
16 //========================= pt-weights =========================
17 // You can make pt-weights in three different ways:
18 // 1.) pt-weights are growing linearly as a function of pt for
19 // pt <= ptCutoff. For pt > ptCutoff the pt-weights are
20 // constant and equal to ptMax. To enable this option set
21 // useLinearPtWeights = kTRUE;
22 // 2.) pt-weights are growing quadratically as a function of pt
23 // for pt <= ptCutoff. For pt > ptCutoff the pt-weights are
24 // constant and equal to ptMax. To enable this option set
25 // useQadraticPtWeights = kTRUE;
26 // 3.) pt-weights are simply v(pt) from the specified method's
27 // result for differential flow vs pt. To enable this option
28 // set useLinearPtWeights = kFALSE and useQadraticPtWeights = kFALSE.
29 Double_t ptCutoff = 2; // in GeV
30 Double_t ptWeightsMax = 0.2;
31 Bool_t useLinearPtWeights = kTRUE;
32 Bool_t useQuadraticPtWeights = kFALSE;
33 //========================= eta-weights ========================
34 // Eta-weights are simply v(eta) from the specified method's
35 // result for differential flow vs eta.
36 //==============================================================
38 enum libModes {mLocal,mLocalSource};
40 //void makeWeights(TString type="", TString method="GFC", TString cumulantOrder="4th", Int_t mode=mLocalSource)
41 void makeWeights(TString type="", TString method="QC", TString cumulantOrder="4th", Int_t mode=mLocal)
43 // 1. type: "ESD", "AOD", "ESDMC0", "ESDMC1", for Monte Carlo and 'on the fly' use simply "", ;
44 // 2. method: MCEP, LYZ1, LYZ2, LYZEP, SP, FQD, GFC or QC;
45 // 3. cumulantOrder: 2nd, 4th, 6th or 8th;
46 // 4. mode: if mode = mLocal -> analyze data on your computer using aliroot
47 // if mode = mLocalSource -> analyze data on your computer using root + source files
49 // Cross-check if the user's settings make sense:
52 // Load needed libraries:
53 LoadLibrariesMW(mode);
55 // Name of the common output file:
56 TString outputFileName = "AnalysisResults.root";
57 TFile *outputFile = NULL;
58 // Access the common output file:
59 if(!(gSystem->AccessPathName(Form("%s%s%s",gSystem->pwd(),"/",outputFileName.Data()),kFileExists)))
61 outputFile = TFile::Open(outputFileName.Data(),"READ");
65 cout<<"WARNING: Couldn't find the file "<<outputFileName.Data()<<" in "<<endl;
66 cout<<" directory "<<gSystem->pwd()<<" !!!!"<<endl;
71 // Access the output file of the specified method in the common output file:
72 TString methodFileName = "output";
73 ((methodFileName.Append(method.Data())).Append("analysis")).Append(type.Data())));
74 TDirectoryFile *methodFile = (TDirectoryFile*)outputFile->FindObjectAny(methodFileName.Data());
75 TList *methodList = NULL;
78 methodFile->GetObject(Form("cobj%s",method.Data()),methodList);
82 cout<<"WARNING: Couldn't access the list "<<methodList->GetName()<<" !!!!"<<endl;
89 cout<<"WARNING: Couldn't find the file "<<methodFileName.Data()<<".root in "<<endl;
90 cout<<" common output file "<<gSystem->pwd()<<"/"<<outputFileName.Data()<<" !!!!"<<endl;
95 // Accessing common control and results histograms from which phi, pt and eta weights will be made:
96 AliFlowCommonHist *commonHist = NULL;
97 AliFlowCommonHistResults *commonHistRes = NULL;
98 if(!(method=="GFC"||method=="QC"))
100 commonHist = dynamic_cast<AliFlowCommonHist*> methodList->FindObject(Form("AliFlowCommonHist%s",method.Data()));
101 commonHistRes = dynamic_cast<AliFlowCommonHistResults*> methodList->FindObject(Form("AliFlowCommonHistResults%s",method.Data()));
102 } else if(method=="GFC") // GFC has distinct common hist results for different cumulant orders (but control histos are the same for different orders)
104 commonHist = dynamic_cast<AliFlowCommonHist*> methodList->FindObject(Form("AliFlowCommonHist%s",method.Data()));
105 commonHistRes = dynamic_cast<AliFlowCommonHistResults*> methodList->FindObject(Form("AliFlowCommonHistResults%sOrder%s",cumulantOrder.Data(),method.Data()));
106 } else // this is for sure QC - treated separately because it has distinct both common control and result histograms for different QC orders
108 commonHist = dynamic_cast<AliFlowCommonHist*> methodList->FindObject(Form("AliFlowCommonHist%sOrder%s",cumulantOrder.Data(),method.Data()));
109 commonHistRes = dynamic_cast<AliFlowCommonHistResults*> methodList->FindObject(Form("AliFlowCommonHistResults%sOrder%s",cumulantOrder.Data(),method.Data()));
114 cout<<"WARNING: commonHist is NULL !!!!"<<endl;
121 cout<<"WARNING: commonHistRes is NULL !!!!"<<endl;
126 // Making the output file "weights.root" in which list "weights" will be saved.
127 // List "weights" will hold histograms phiWeights, ptWeights and etaWeights which
128 // will hold the phi, pt and eta weights, respectively:
129 TFile *weightsFile = new TFile("weights.root","RECREATE");
130 TList *weightsList = new TList();
131 gStyle->SetOptStat(0); // remove statistic box from all histograms
134 TH1F *phiWeights = (TH1F*)commonHist->GetHistPhiRP()->Clone("phi_weights"); // to be improved (transferred into TH1D eventually)
135 phiWeights->SetTitle("#phi-weights: correcting for non-uniform acceptance");
136 phiWeights->SetYTitle("w_{#phi}");
137 phiWeights->SetXTitle("#phi");
138 Int_t nBinsPhi = 0; // number of phi bins
139 Int_t counterOfEmptyBinsPhi = 0; // number of empty phi bins
140 Double_t nParticlesInBin = 0.; // number of particles in particular phi bin
141 Double_t nParticlesPerBin = 0.; // average number of particles per phi bin
142 Double_t nParticles = 0.; // number of particles in all phi bins
143 // calculate phi-weights:
144 nBinsPhi = phiWeights->GetNbinsX();
145 nParticles = phiWeights->Integral();
146 if(nBinsPhi) nParticlesPerBin = nParticles/nBinsPhi;
147 for(Int_t b=1;b<=nBinsPhi;b++)
149 Double_t wPhi = 0.; // phi-weight for particular phi bin
150 nParticlesInBin = phiWeights->GetBinContent(b);
153 wPhi = nParticlesPerBin/nParticlesInBin;
156 counterOfEmptyBinsPhi++;
158 phiWeights->SetBinContent(b,wPhi);
160 if(!counterOfEmptyBinsPhi)
162 weightsList->Add(phiWeights);
163 cout<<"Phi weights created."<<endl;
166 cout<<"WARNING: Couldn't create phi weights because "<<counterOfEmptyBinsPhi<<" phi bins were empty !!!!"<<endl;
170 Double_t ptMin = AliFlowCommonConstants::GetMaster()->GetPtMin();
171 Double_t ptMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
172 Int_t nBinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
173 Double_t ptBinWidth = 0.;
174 if(nBinsPt) ptBinWidth = (ptMax-ptMin)/nBinsPt;
175 TH1D *ptWeights = new TH1D("pt_weights","",nBinsPt,ptMin,ptMax);
176 ptWeights->SetXTitle("p_{t} [GeV]");
177 ptWeights->SetYTitle("w_{p_{T}}");
178 if(useLinearPtWeights)
180 ptWeights->SetTitle("Linear p_{T}-weights: optimizing the flow signal");
181 } else if(useQuadraticPtWeights)
183 ptWeights->SetTitle("Quadratic p_{T}-weights: optimizing the flow signal");
186 ptWeights->SetTitle("Differential flow as p_{T}-weights: optimizing the flow signal");
188 // calculate pt weights:
189 for(Int_t b=1;b<=nBinsPt;b++)
191 if(useLinearPtWeights)
193 if(ptMin+b*ptBinWidth < ptCutoff)
195 ptWeights->SetBinContent(b,(ptMin+b*ptBinWidth)*(ptWeightsMax/ptCutoff));
198 ptWeights->SetBinContent(b,ptWeightsMax);
202 weightsList->Add(ptWeights);
203 cout<<"Pt weights (linear) created."<<endl;
205 } else if(useQuadraticPtWeights)
207 if(ptMin+b*ptBinWidth < ptCutoff)
209 ptWeights->SetBinContent(b,pow(ptMin+b*ptBinWidth,2.)*(ptWeightsMax/pow(ptCutoff,2.)));
212 ptWeights->SetBinContent(b,ptWeightsMax);
216 weightsList->Add(ptWeights);
217 cout<<"Pt weights (quadratic) created."<<endl;
219 } else // differential flow result is used as a pt-weight:
221 ptWeights->SetBinContent(b,commonHistRes->GetHistDiffFlowPtPOI()->GetBinContent(b));
224 weightsList->Add(ptWeights);
225 cout<<"Pt weights (from differential flow) created."<<endl;
228 } // end of for(Int_t b=1;b<=nBinsPt;b++)
231 TH1D *etaWeights = commonHistRes->GetHistDiffFlowEtaPOI()->Clone("eta_weights");
232 etaWeights->SetXTitle("#eta [GeV]");
233 etaWeights->SetYTitle("w_{#eta}");
234 etaWeights->SetTitle("Differential flow as #eta-weights: optimizing the flow signal");
237 weightsList->Add(etaWeights);
238 cout<<"Eta weights (from differential flow) created."<<endl;
241 // Save list holding histogram with weights:
242 weightsFile->WriteObject(weightsList,"weights","SingleKey");
244 cout<<"New file \"weights.root\" created to hold those phi, pt and eta weights."<<endl;
249 } // end of void makeWeights(TString type="", TString method="QC", TString cumulantOrder="4th", Int_t mode=mLocal)
251 void CrossCheckSettings()
253 // Check in this method if the settings make sense
255 if(useLinearPtWeights && useQuadraticPtWeights)
258 cout<<"WARNING: You cannot set useLinearPtWeights and useQuadraticPtWeights to kTRUE"<<endl;
259 cout<<" at the same time. Please make up your mind."<<endl;
266 cout<<"WARNING: It doesn't make much sense to have ptCutoff < 0."<<endl;
273 cout<<"WARNING: It doesn't make much sense to have ptWeightsMax < 0."<<endl;
278 } // end of void CrossCheckSettings()
280 void LoadLibrariesMW(const libModes mode) {
282 //--------------------------------------
283 // Load the needed libraries most of them already loaded by aliroot
284 //--------------------------------------
285 //gSystem->Load("libTree");
286 gSystem->Load("libGeom");
287 gSystem->Load("libVMC");
288 gSystem->Load("libXMLIO");
289 gSystem->Load("libPhysics");
291 //----------------------------------------------------------
292 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
293 //----------------------------------------------------------
295 //--------------------------------------------------------
296 // If you want to use already compiled libraries
297 // in the aliroot distribution
298 //--------------------------------------------------------
300 //==================================================================================
301 //load needed libraries:
302 gSystem->AddIncludePath("-I$ROOTSYS/include");
303 //gSystem->Load("libTree");
306 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
307 gSystem->Load("libANALYSIS");
308 gSystem->Load("libPWG2flowCommon");
309 //cerr<<"libPWG2flowCommon loaded ..."<<endl;
313 else if (mode==mLocalSource) {
315 // In root inline compile
318 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
319 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
320 gROOT->LoadMacro("AliFlowCommon/AliFlowCumuConstants.cxx+");
323 gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+");
324 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");
325 gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
328 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");
330 // Output histosgrams
331 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
332 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
333 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
334 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
336 cout << "finished loading macros!" << endl;
340 } // end of void LoadLibrariesMW(const libModes mode)