17 #include "EEmcSectorFit.h"
18 #include "eeSinglePeak.h"
53 for ( UInt_t i=0;i<
yield.size();i++ )
58 Double_t X[]={x,0.,0.};
59 Double_t P[]={a,m,s,0.2,3.5};
60 sum += eeSinglePeak(X,P);
74 for ( UInt_t i=0;i<
yield.size();i++ )
76 yield[i] = par[4*i+0];
77 sigma[i] = par[4*i+1];
78 umean[i] = par[4*i+2];
79 vmean[i] = par[4*i+3];
83 for ( Int_t plane=0;plane<2; plane++ )
89 for ( Int_t strip=0;strip<288;strip++ )
92 Double_t nmip = histo -> GetBinContent(strip+1);
94 Double_t x = (Double_t)strip + 0.5;
98 mychi2 += (nmip-f)*(nmip-f)/nmip;
103 else if ( f > 0.499 ) {
105 mychi2 += (nmip-f)*(nmip-f)/f;
121 for ( UInt_t i=0;i<
yield.size();i++ )
124 if ( TMath::Abs(xx-(Double_t)x-0.5) <= 1.0 )
return 0.;
128 Double_t r = histo->GetBinContent(bin) -
FitFunc( (Double_t)x+0.5, plane );
140 min=TMath::Max(x-dx,0);
141 max=TMath::Min(x+dx,288);
149 max=TMath::Min(x,288);
154 for ( Int_t xx=min;xx<=max;xx++ )
165 for ( Int_t i=0;i<288;i++ )
185 TLine *lU =
new TLine(u,0.,u,y);lU->SetLineColor(2);
186 TLine *lV =
new TLine(v,0.,v,y);lV->SetLineColor(2);
187 mSMD[0]->GetListOfFunctions()->Add(lU);
188 mSMD[1]->GetListOfFunctions()->Add(lV);
199 Command(
"SET ERR 1");
200 for ( Int_t i=0;i<(Int_t)
yield.size();i++ )
202 mnparm(4*i+0, TString(
"yield"),
yield[i], 0.1, 0.25*
yield[i], 2.0*
yield[i], flg );
203 mnparm(4*i+1, TString(
"sigma"),
sigma[i], 0.1, 0.5, 2.5, flg );
204 mnparm(4*i+2, TString(
"umean"),
umean[i], 0.1, 0.0, 288.0, flg );
205 mnparm(4*i+3, TString(
"vmean"),
vmean[i], 0.1, 0.0, 288.0, flg );
236 for ( UInt_t i=0;i<
yield.size();i++ )
238 TString uname=
"fitu";uname+=i;
239 TString vname=
"fitv";vname+=i;
240 TF1 *fitu=
new TF1(uname,eeSinglePeak,0.,288.,5);
241 TF1 *fitv=
new TF1(vname,eeSinglePeak,0.,288.,5);
242 fitu->SetLineColor(4);
243 fitv->SetLineColor(4);
244 fitu->SetLineWidth(1);
245 fitv->SetLineWidth(1);
246 fitu->SetParameter(0,
yield[i] );
247 fitu->SetParameter(1,
umean[i] );
248 fitu->SetParameter(2,
sigma[i] );
249 fitu->SetParameter(3, 0.2 );
250 fitu->SetParameter(4, 3.5 );
251 fitv->SetParameter(0,
yield[i] );
252 fitv->SetParameter(1,
vmean[i] );
253 fitv->SetParameter(2,
sigma[i] );
254 fitv->SetParameter(3, 0.2 );
255 fitv->SetParameter(4, 3.5 );
256 mSMD[0]->GetListOfFunctions()->Add( fitu );
257 mSMD[1]->GetListOfFunctions()->Add( fitv );
258 umin=TMath::Min( fitu->GetParameter(1), umin );
259 umax=TMath::Max( fitu->GetParameter(1), umax );
260 vmin=TMath::Min( fitv->GetParameter(1), vmin );
261 vmax=TMath::Max( fitv->GetParameter(1), vmax );
264 umin=TMath::Max(umin,1.0);
265 umax=TMath::Min(umax,287.0);
266 vmin=TMath::Max(vmin,1.0);
267 vmax=TMath::Min(vmax,287.0);
270 mSMD[0]->GetXaxis()->SetRangeUser(umin-20.,umax+20.);
272 mSMD[1]->GetXaxis()->SetRangeUser(vmin-20.,vmax+20.);
287 std::vector<Double_t> chi2vec;
290 std::vector< std::vector<Double_t> > yields;
291 std::vector< std::vector<Double_t> > sigmas;
292 std::vector< std::vector<Double_t> > umeans;
293 std::vector< std::vector<Double_t> > vmeans;
294 std::vector< Double_t > mychi2;
296 std::vector< Double_t > old_yield =
yield;
297 std::vector< Double_t > old_sigma =
sigma;
298 std::vector< Double_t > old_umean =
umean;
299 std::vector< Double_t > old_vmean =
vmean;
302 while ( std::next_permutation( old_vmean.begin(), old_vmean.end() ) )
312 for ( UInt_t i=0;i<
sigma.size();i++ ) {
318 mychi2.push_back(
mChi2 );
319 yields.push_back(
yield );
320 sigmas.push_back(
sigma );
321 umeans.push_back(
umean );
322 vmeans.push_back(
vmean );
331 Double_t min = 9.0E12;
332 for ( UInt_t i=0;i<mychi2.size();i++ )
334 if ( mychi2[i]< min )
347 for ( UInt_t i=0;i<
sigma.size();i++ ) {
357 std::cout <<
"chi^2 =" <<
mChi2 << std::endl;
358 std::cout <<
"ndf =" <<
mNDF << std::endl;
382 for ( UInt_t i=0;i<
yield.size();i++ )
384 TString uname=
"fitu";uname+=i;
385 TString vname=
"fitv";vname+=i;
386 TF1 *fitu=
new TF1(uname,eeSinglePeak,0.,288.,5);
387 TF1 *fitv=
new TF1(vname,eeSinglePeak,0.,288.,5);
388 fitu->SetLineColor(4);
389 fitv->SetLineColor(4);
390 fitu->SetLineWidth(1);
391 fitv->SetLineWidth(1);
392 fitu->SetParameter(0,
yield[i] );
393 fitu->SetParameter(1,
umean[i] );
394 fitu->SetParameter(2,
sigma[i] );
395 fitu->SetParameter(3, 0.2 );
396 fitu->SetParameter(4, 3.5 );
397 fitv->SetParameter(0,
yield[i] );
398 fitv->SetParameter(1,
vmean[i] );
399 fitv->SetParameter(2,
sigma[i] );
400 fitv->SetParameter(3, 0.2 );
401 fitv->SetParameter(4, 3.5 );
402 uu->GetListOfFunctions()->Add( fitu );
403 vv->GetListOfFunctions()->Add( fitv );
404 umin=TMath::Min( fitu->GetParameter(1), umin );
405 umax=TMath::Max( fitu->GetParameter(1), umax );
406 vmin=TMath::Min( fitv->GetParameter(1), vmin );
407 vmax=TMath::Max( fitv->GetParameter(1), vmax );
410 umin=TMath::Max(umin,1.0);
411 umax=TMath::Min(umax,287.0);
412 vmin=TMath::Max(vmin,1.0);
413 vmax=TMath::Min(vmax,287.0);
416 uu->GetXaxis()->SetRangeUser(umin-20.,umax+20.);
418 vv->GetXaxis()->SetRangeUser(vmin-20.,vmax+20.);
EEmcSectorFit(Int_t maxGammas=10)
Int_t mNDF
Degrees o' freedom.
void print() const
print summary
void AddCandidate(Double_t yield, Double_t sigma, Double_t u, Double_t v)
Add a candidate to the list of candidate gammas.
void InitParameters()
Initialize parameters.
std::vector< Double_t > sigma
Width of N gammas.
std::vector< Double_t > vmean
Mean V position of N gammas.
Double_t FitFunc(Double_t x, Int_t plane) const
Evaluate the N gamma fit for the specified plane.
Int_t MaxStrip(Int_t plane) const
Find maximum residual strip in specified plane. Returns strip index.
std::vector< Double_t > umean
Mean U position of N gammas.
virtual ~EEmcSectorFit()
Destructor.
TH1F * mSMD[2]
The histograms we fit.
Double_t mChi2
Chi^2 of the fit.
void Draw(Option_t *opts)
Draws the current fit.
virtual Int_t Eval(Int_t np, Double_t *gr, Double_t &x2, Double_t *p, Int_t flg)
Double_t Residual(Int_t x, Int_t plane) const
void Clear(Option_t *opts="")
Clear the array of photon candidates.
void AddFits(TH1F *u, TH1F *v)
Adds TF1 to histogram.
std::vector< Double_t > yield
Yield of N gammas.
Bool_t doPermutations
Flag to determine if we test all permutations or not.
TH1F * histo(Int_t plane)
Return the histogram for the specified plane.
Simultaneous fit of two smd planes to N gammas.