1 //==========================================================================================
2 // Before using the macro makeWeights.C you should already have available the output .root
3 // files from various methods from the previous run over data (without any weights). When
4 // calling this macro you must specify the analysis type and the method from which output
5 // file you would like to make the weights for the next run (for the cumulants, GFC and QC,
6 // you must also specify the order):
8 // 1. type of analysis can be: ESD, AOD, MC, ESDMC0 or ESDMC1;
10 // 2. method can be: MCEP, LYZ1, LYZ2, LYZEP, FQD, GFC or QC;
12 // 3. cumulant order can be: 2nd, 4th, 6th or 8th.
13 //==========================================================================================
16 enum libModes {mLocal,mLocalSource};
17 //mLocal: Analyze data on your computer using aliroot
18 //mLocalSource: Analyze data on your computer using root + source files
21 //void makeWeights(TString type="", TString method="GFC", TString cumulantOrder="4th", Int_t mode=mLocalSource)
22 void makeWeights(TString type="ESD", TString method="GFC", TString cumulantOrder="4th", Int_t mode=mLocal)
24 // load needed libraries:
25 LoadWeightLibraries(mode);
28 // open the output file from the first run of the specified method:
29 TString inputFileName = "output";
31 file = TFile::Open(((((inputFileName.Append(method.Data())).Append("analysis")).Append(type.Data())).Append(".root")).Data(), "READ");
33 // using pt weights linear or quadratic in pt:
34 Bool_t useLinearPt = kTRUE;
35 Bool_t useQuadraticPt = kFALSE;
36 if(useLinearPt && useQuadraticPt)
38 cout<<" WARNING: you can use pt weights linear or quadratic in pt, but not at the same time. "<<endl;
41 Bool_t useFunctionOfPt = useLinearPt||useQuadraticPt;
43 // accessing the results:
44 TString cobj = "cobj";
45 TString afc = "AliFlowCommonHist";
46 TString afcr = "AliFlowCommonHistResults";
49 AliFlowCommonHist *commonHist = NULL;
50 AliFlowCommonHistResults *commonHistRes = NULL;
54 file->GetObject((cobj.Append(method.Data()).Data()),pList);
57 if(!(method=="GFC"||method=="QC"))
59 commonHist = dynamic_cast<AliFlowCommonHist*> (pList->FindObject((afc.Append(method.Data())).Data()));
60 commonHistRes = dynamic_cast<AliFlowCommonHistResults*> (pList->FindObject((afcr.Append(method.Data())).Data()));
61 }else if(method=="GFC")
63 commonHist = dynamic_cast<AliFlowCommonHist*> (pList->FindObject((afc.Append(method.Data())).Data()));
64 commonHistRes = dynamic_cast<AliFlowCommonHistResults*> (pList->FindObject((((afcr.Append(cumulantOrder.Data()).Append("Order")).Append(method.Data())).Data())));
67 commonHist = dynamic_cast<AliFlowCommonHist*> (pList->FindObject(((afc.Append(cumulantOrder.Data())).Append("Order")).Append(method.Data())));
68 commonHistRes = dynamic_cast<AliFlowCommonHistResults*> (pList->FindObject((((afcr.Append(cumulantOrder.Data()).Append("Order")).Append(method.Data())).Data())));
73 //making the output file and creating the TList to hold the histograms with weights:
74 TFile* outputFile = new TFile("weights.root","RECREATE");
75 TList* listWeights = new TList();
77 Double_t nParticlesInBin = 0; // number of particles in particular phi bin
78 Double_t nParticlesPerBin = 0; // average number of particles per phi bin
79 Double_t nParticles = 0; // number of particles in all phi bins
82 // common control histos:
85 // azimuthal acceptance:
86 (commonHist->GetHistPhiRP())->SetName("phi_weights");
87 (commonHist->GetHistPhiRP())->SetTitle("phi_weights: correction for non-uniform acceptance");
88 (commonHist->GetHistPhiRP())->SetYTitle("weights");
89 (commonHist->GetHistPhiRP())->SetXTitle("#phi");
90 nBinsPhi = (commonHist->GetHistPhiRP())->GetNbinsX();
91 nParticles = (commonHist->GetHistPhiRP())->Integral();
92 if(nBinsPhi) nParticlesPerBin = nParticles/nBinsPhi;
93 // loop over phi bins:
94 for(Int_t b=1;b<nBinsPhi+1;b++)
96 nParticlesInBin = (commonHist->GetHistPhiRP())->GetBinContent(b);
97 // calculate the phi weight wPhi for each bin:
98 if(nParticlesInBin) wPhi = nParticlesPerBin/nParticlesInBin;
99 (commonHist->GetHistPhiRP())->SetBinContent(b,wPhi);
101 listWeights->Add(commonHist->GetHistPhiRP());
102 }else{cout<<" WARNING: the common control histos from the 1st run were not accessed."<<endl;}
104 // common results histos:
108 (commonHistRes->GetHistDiffFlowPtPOI())->SetName("pt_weights");
109 if(!useFunctionOfPt) listWeights->Add(commonHistRes->GetHistDiffFlowPtPOI());
111 (commonHistRes->GetHistDiffFlowEtaPOI())->SetName("eta_weights");
112 listWeights->Add(commonHistRes->GetHistDiffFlowEtaPOI());
113 }else{cout<<" WARNING: the common results histos from the 1st run were not accessed."<<endl;}
115 // pt weights linear and quadratic in pt:
118 Double_t ptMin = AliFlowCommonConstants::GetPtMin();
119 Double_t ptMax = AliFlowCommonConstants::GetPtMax();
120 Int_t nBinsPt = AliFlowCommonConstants::GetNbinsPt();
121 Double_t ptCutOff = 2.0; // for pt > ptCutOff use constant weights
124 cout<<" WARNING: number of pt bins is 0. "<<endl;
127 Double_t ptBinWidth = 1.*(ptMax-ptMin)/nBinsPt;
129 TH1D *ptFunction = new TH1D("ptFunction", "ptFunction", nBinsPt, ptMin, ptMax);
130 ptFunction->SetName("pt_weights");
131 ptFunction->SetXTitle("p_{t} [GeV]");
132 ptFunction->SetYTitle("weights");
137 ptFunction->SetTitle("p_{t} weights: #propto p_{t}");
142 ptFunction->SetTitle("p_{t} weights: #propto p_{t}^{2}");
144 for(Int_t b=1;b<nBinsPt+1;b++)
146 if(ptMin+b*ptBinWidth < ptCutOff)
148 ptFunction->SetBinContent(b, pow(ptMin+b*ptBinWidth, power));
151 ptFunction->SetBinContent(b, pow(ptCutOff, power));
154 listWeights->Add(ptFunction);
157 outputFile->WriteObject(listWeights,"weights","SingleKey");
164 void LoadWeightLibraries(const libModes mode) {
166 //--------------------------------------
167 // Load the needed libraries most of them already loaded by aliroot
168 //--------------------------------------
169 gSystem->Load("libTree.so");
170 gSystem->Load("libGeom.so");
171 gSystem->Load("libVMC.so");
172 gSystem->Load("libXMLIO.so");
173 gSystem->Load("libPhysics.so");
175 //----------------------------------------------------------
176 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
177 //----------------------------------------------------------
179 //--------------------------------------------------------
180 // If you want to use already compiled libraries
181 // in the aliroot distribution
182 //--------------------------------------------------------
184 //==================================================================================
185 //load needed libraries:
186 gSystem->AddIncludePath("-I$ROOTSYS/include");
187 gSystem->Load("libTree.so");
190 gSystem->AddIncludePath("-I$ALICE_ROOT/include");
191 gSystem->Load("libANALYSIS.so");
192 gSystem->Load("libPWG2flowCommon.so");
193 cerr<<"libPWG2flowCommon.so loaded ..."<<endl;
197 else if (mode==mLocalSource) {
199 // In root inline compile
202 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
203 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
204 gROOT->LoadMacro("AliFlowCommon/AliFlowCumuConstants.cxx+");
207 gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+");
208 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");
209 gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
212 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");
214 // Output histosgrams
215 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
216 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
217 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
218 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
220 cout << "finished loading macros!" << endl;