]>
Commit | Line | Data |
---|---|---|
e6f3f2fe | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* Origin: Alberica Toia, CERN, Alberica.Toia@cern.ch */ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // class to determine centrality percentiles from 1D distributions // | |
21 | // // | |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
24 | #include <TNamed.h> | |
25 | #include <TH1D.h> | |
26 | #include <TString.h> | |
27 | #include <TFile.h> | |
28 | #include <TMath.h> | |
29 | #include <TROOT.h> | |
30 | #include <TH2F.h> | |
31 | #include <TF1.h> | |
32 | #include <TNtuple.h> | |
33 | #include <TStyle.h> | |
34 | #include <TGraphErrors.h> | |
35 | #include <vector> | |
36 | #include "AliCentralityGlauberFit.h" | |
37 | ||
38 | ||
39 | ClassImp(AliCentralityGlauberFit) | |
40 | ||
41 | //______________________________________________________________________________ | |
42 | ||
43 | ||
44 | AliCentralityGlauberFit::AliCentralityGlauberFit() { | |
45 | // standard constructor | |
46 | // glauber file | |
47 | TFile *f = TFile::Open("hj-unquenched.root"); | |
48 | glau_ntuple = (TNtuple*) f->Get("gnt"); | |
49 | glau_ntuple->SetBranchAddress("npart",&npart); | |
50 | glau_ntuple->SetBranchAddress("ncoll",&ncoll); | |
51 | glau_ntuple->SetBranchAddress("b",&b); | |
52 | } | |
53 | ||
54 | //-------------------------------------------------------------------------------------------------- | |
55 | ||
56 | AliCentralityGlauberFit::~AliCentralityGlauberFit() { | |
57 | // destructor | |
58 | } | |
59 | ||
60 | //-------------------------------------------------------------------------------------------------- | |
61 | ||
62 | void AliCentralityGlauberFit::AddHisto(TString name) { | |
63 | histnames.push_back(name); | |
64 | } | |
65 | ||
66 | //-------------------------------------------------------------------------------------------------- | |
67 | ||
68 | void AliCentralityGlauberFit::SetOutputFile(TString filename) { | |
69 | outrootfilename = filename; | |
70 | } | |
71 | ||
72 | //-------------------------------------------------------------------------------------------------- | |
73 | ||
74 | void AliCentralityGlauberFit::SetGlauberParam( | |
75 | Int_t fNmu, | |
76 | Float_t fmulow, | |
77 | Float_t fmuhigh, | |
78 | Int_t fNk, | |
79 | Float_t fklow, | |
80 | Float_t fkhigh, | |
81 | Int_t fNalpha, | |
82 | Float_t falphalow, | |
83 | Float_t falphahigh) | |
84 | ||
85 | { | |
86 | Nmu=fNmu; | |
87 | mulow=fmulow; | |
88 | muhigh=fmuhigh; | |
89 | Nk=fNk; | |
90 | klow=fklow; | |
91 | khigh=fkhigh; | |
92 | Nalpha=fNalpha; | |
93 | alphalow=falphalow; | |
94 | alphahigh=falphahigh; | |
95 | } | |
96 | ||
97 | //-------------------------------------------------------------------------------------------------- | |
98 | ||
99 | Float_t AliCentralityGlauberFit::GetPercentileCrossSection() { | |
100 | return percentXsec; | |
101 | } | |
102 | ||
103 | //-------------------------------------------------------------------------------------------------- | |
104 | ||
105 | void AliCentralityGlauberFit::MakeFits(TString infilename) { | |
106 | TH1D *hDATA; | |
107 | TH1D *thistGlau; | |
108 | ||
109 | float efflow = 0.60; | |
110 | float effhigh = 1.00; | |
111 | ||
112 | TFile *outrootfile; | |
113 | ||
114 | // open inrootfile, outrootfile | |
115 | inrootfile = new TFile(infilename); | |
116 | outrootfile = new TFile(outrootfilename,"RECREATE"); | |
117 | ||
118 | // loop over all distribution names | |
119 | vector<TString>::const_iterator hni; | |
120 | for(hni=histnames.begin(); hni!=histnames.end(); hni++) { | |
121 | hDATA = (TH1D*) (inrootfile->Get(*hni)); | |
122 | hDATA->Rebin(10); | |
123 | TH1D *hGLAU = new TH1D("hGLAU","hGLAU",hDATA->GetNbinsX(),0,hDATA->GetNbinsX()*hDATA->GetBinWidth(1)); | |
124 | int chi2min = 9999; | |
125 | Float_t alpha_min=-1; | |
126 | Float_t mu_min=-1; | |
127 | Float_t k_min=-1; | |
128 | Float_t eff_min=-1; | |
129 | Float_t alpha, mu, k, eff, chi2; | |
130 | ||
131 | for (int nalpha=0;nalpha<Nalpha;nalpha++) { | |
132 | alpha = alphalow + ((float) nalpha) * 0.05; | |
133 | mu=0.0; | |
134 | for (int nmu=0; nmu<Nmu; nmu++) { | |
135 | // mu = (mulow*(1-nalpha*0.1*mulow) ) + ((float) nmu ) * (muhigh - mulow ) / Nmu; | |
136 | mu = mulow + ((float) nmu ) * (muhigh - mulow ) / Nmu; | |
137 | ||
138 | for (int nk=0; nk<Nk; nk++) { | |
139 | k = klow + ((float) nk ) * (khigh - klow ) / Nk; | |
140 | ||
141 | for (int neff=0; neff<20; neff++) { | |
142 | eff = efflow + ((float) neff) * (effhigh - efflow) / 20.0; | |
143 | ||
144 | thistGlau = GlauberHisto(mu,k,eff,alpha,hDATA,kFALSE); | |
145 | chi2 = CalculateChi2(hDATA,thistGlau,eff); | |
146 | if ( chi2 < chi2min ) { | |
147 | chi2min = chi2; | |
148 | alpha_min=alpha; | |
149 | mu_min=mu; | |
150 | k_min=k; | |
151 | eff_min=eff; | |
152 | } | |
153 | } | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | thistGlau = GlauberHisto(mu_min,k_min,eff_min,alpha_min,hDATA,kTRUE); | |
159 | hGLAU = (TH1D *) thistGlau->Clone("hGLAU"); | |
160 | hGLAU->SetName( ((TString)hDATA->GetName()).Append(Form("_GLAU_%d_%d_%d_%d",(int)(100*mu_min),(int)(100*k_min),(int)(100*alpha_min),(int)(100*eff_min)))); | |
161 | hGLAU->SetTitle( ((TString)hDATA->GetName()).Append(Form("_GLAU_%.2f_%.2f_%.2f_%.2f",mu_min,k_min,alpha_min,eff_min))); | |
162 | ||
163 | heffi = GetTriggerEfficiencyFunction(hDATA, hGLAU); | |
164 | SaveHisto(hDATA,hGLAU,heffi,outrootfile); | |
165 | ||
166 | } | |
167 | // close inrootfile, outrootfile | |
168 | inrootfile->Close(); | |
169 | outrootfile->Close(); | |
170 | ||
171 | } | |
172 | ||
173 | //-------------------------------------------------------------------------------------------------- | |
174 | ||
175 | TH1D * AliCentralityGlauberFit::GlauberHisto(Float_t mu, Float_t k, Float_t eff, Float_t alpha, TH1D *hDATA, Bool_t save) { | |
176 | ||
177 | TH1D *hSample = NBDhist(mu,k); | |
178 | TH1D *h1 = new TH1D(Form("fit_%.2f_%.2f_%.2f_%.2f",mu,k,eff,alpha),"",hDATA->GetNbinsX(),0,hDATA->GetNbinsX()*hDATA->GetBinWidth(1)); | |
179 | TFile *outFile = NULL; | |
180 | TNtuple *ntuple = NULL; | |
181 | ||
182 | if (save) { | |
183 | outFile = TFile::Open("pippo.root", "RECREATE"); | |
184 | ntuple = new TNtuple("gnt", "Glauber ntuple", "npart:ncoll:b:ntot"); | |
185 | } | |
186 | ||
187 | Int_t nents = glau_ntuple->GetEntries(); | |
188 | for (Int_t i=0;i<nents;++i) { | |
189 | glau_ntuple->GetEntry(i); | |
190 | Int_t n = TMath::Nint(TMath::Power(npart,alpha)); | |
191 | //Int_t n = TMath::Nint(TMath::Power(ncoll,alpha)); | |
192 | Int_t ntot=0; | |
193 | for(Int_t j = 0; j<n; ++j) | |
194 | ntot+=hSample->GetRandom(); | |
195 | h1->Fill(ntot); | |
196 | ||
197 | if (save) | |
198 | ntuple->Fill(npart,ncoll,b,ntot); | |
199 | ||
200 | } | |
201 | ||
202 | if (save) { | |
203 | ntuple->Write(); | |
204 | outFile->Close(); | |
205 | } | |
206 | ||
207 | ||
208 | return h1; | |
209 | ||
210 | } | |
211 | ||
212 | //-------------------------------------------------------------------------------------------------- | |
213 | ||
214 | Float_t AliCentralityGlauberFit::CalculateChi2(TH1D *hDATA, TH1D *thistGlau, Float_t eff) { | |
215 | // note that for different values of neff the mc distribution is identical, just re-scaled below | |
216 | // normalize the two histogram | |
217 | // scale MC up but leave data alone - that preserves error bars !!!! | |
218 | ||
219 | float mcintegral = thistGlau->Integral(); | |
220 | for (int i=1; i<=thistGlau->GetNbinsX(); i++) { | |
221 | float scale = (hDATA->Integral()/mcintegral) / ((float) eff); | |
222 | float temp = scale * thistGlau->GetBinContent(i); | |
223 | thistGlau->SetBinContent(i,temp); | |
224 | } | |
225 | ||
226 | // calculate the chi2 between MC and real data over some range ???? | |
227 | int lowchibin = 10; | |
228 | int highchibin = 80; | |
229 | float chi2 = 0.0; | |
230 | for (int i=lowchibin; i<=highchibin; i++) { | |
231 | if (hDATA->GetBinContent(i) < 1.0) continue; | |
232 | float diff = pow( (thistGlau->GetBinContent(i) - hDATA->GetBinContent(i)) , 2); | |
233 | diff = diff / pow(hDATA->GetBinError(i) , 2); | |
234 | chi2 += diff; | |
235 | } | |
236 | chi2 = chi2 / (highchibin - lowchibin + 1); | |
237 | return chi2; | |
238 | } | |
239 | ||
240 | //-------------------------------------------------------------------------------------------------- | |
241 | ||
242 | TH1D * AliCentralityGlauberFit::GetTriggerEfficiencyFunction(TH1D *hist1, TH1D *hist2) { | |
243 | heffi = (TH1D*)hist1->Clone("heffi"); | |
244 | heffi->Divide(hist2); | |
245 | return heffi; | |
246 | } | |
247 | ||
248 | //-------------------------------------------------------------------------------------------------- | |
249 | ||
250 | Float_t AliCentralityGlauberFit::GetTriggerEfficiencyIntegral(TH1D *hist1, TH1D *hist2) { | |
251 | effi = hist1->Integral()/hist2->Integral(); | |
252 | return effi; | |
253 | } | |
254 | ||
255 | //-------------------------------------------------------------------------------------------------- | |
256 | ||
257 | void AliCentralityGlauberFit::SaveHisto(TH1D *hist1, TH1D *hist2, TH1D *heffi, TFile *outrootfile) { | |
258 | outrootfile->cd(); | |
259 | hist1->Write(); | |
260 | hist2->Write(); | |
261 | heffi->Write(); | |
262 | } | |
263 | ||
264 | //-------------------------------------------------------------------------------------------------- | |
265 | ||
266 | Double_t AliCentralityGlauberFit::NBD(Int_t n, Double_t mu, Double_t k) | |
267 | { | |
268 | Double_t mudk = mu/k; | |
269 | Double_t ret = TMath::Gamma(n+k) / TMath::Gamma(k) / TMath::Factorial(n) * | |
270 | TMath::Power(mudk,n) / TMath::Power(1+mudk,n+k); | |
271 | return ret; | |
272 | } | |
273 | ||
274 | //-------------------------------------------------------------------------------------------------- | |
275 | ||
276 | TH1D *AliCentralityGlauberFit::NBDhist(Double_t mu, Double_t k) | |
277 | { | |
278 | TH1D *h = new TH1D("htemp","",100,0,100); | |
279 | h->SetName(Form("nbd_%f_%f",mu,k)); | |
280 | h->SetDirectory(0); | |
281 | for (Int_t i=0;i<100;++i) { | |
282 | Double_t val = NBD(i,mu,k); | |
283 | h->Fill(i,val); | |
284 | } | |
285 | return h; | |
286 | } | |
287 | ||
288 |