112 TH2 *gHistInvEMatrix;
114 TVirtualFitter *gFitter=0;
116 void chisquare_corr(Int_t &npar, Double_t * , Double_t &f, Double_t *u, Int_t ) {
122 TH1 *hfit = (TH1*)gFitter->GetObjectFit();
123 TF1 *f1 = (TF1*)gFitter->GetUserFunc();
126 npar = f1->GetNpar();
130 Int_t nPoints=hfit->GetNbinsX();
131 Double_t *df=
new Double_t[nPoints];
132 for (Int_t i=0;i<nPoints;i++) {
133 x = hfit->GetBinCenter(i+1);
134 TF1::RejectPoint(kFALSE);
135 df[i] = f1->EvalPar(&x,u)-hfit->GetBinContent(i+1);
136 if (TF1::RejectedPoint()) df[i]=0.0;
139 for (Int_t i=0;i<nPoints;i++) {
140 for (Int_t j=0;j<nPoints;j++) {
141 f += df[i]*df[j]*gHistInvEMatrix->GetBinContent(i+1,j+1);
145 f1->SetNumberFitPoints(npfit);
148 Double_t bw_func(Double_t *x,Double_t *par) {
149 Double_t dm=x[0]-par[1];
150 return par[0]/(dm*dm+par[2]*par[2]);
158 Double_t GenerateEvent(Double_t bgr,
163 if(rnd->Rndm()>bgr) {
170 t=TMath::Tan((t-0.5)*TMath::Pi())*gamma+mass;
177 static Double_t
const E0=2.4;
178 static Double_t
const N0=2.9;
185 t= -(TMath::Power(1.-t,1./(1.-N0))-1.0)*E0;
196 Double_t DetectorEvent(Double_t mTrue) {
198 static Double_t frac=0.1;
199 static Double_t wideBias=0.03;
200 static Double_t wideSigma=0.5;
201 static Double_t smallBias=0.0;
202 static Double_t smallSigma=0.1;
203 if(rnd->Rndm()>frac) {
204 return rnd->Gaus(mTrue+smallBias,smallSigma);
206 return rnd->Gaus(mTrue+wideBias,wideSigma);
213 TH1::SetDefaultSumw2();
216 gStyle->SetOptFit(1111);
222 Double_t
const luminosityData=100000;
223 Double_t
const luminosityMC=1000000;
224 Double_t
const crossSection=1.0;
226 Int_t
const nDet=250;
227 Int_t
const nGen=100;
228 Double_t
const xminDet=0.0;
229 Double_t
const xmaxDet=10.0;
230 Double_t
const xminGen=0.0;
231 Double_t
const xmaxGen=10.0;
236 TH1D *histMgenMC=
new TH1D(
"MgenMC",
";mass(gen)",nGen,xminGen,xmaxGen);
237 TH1D *histMdetMC=
new TH1D(
"MdetMC",
";mass(det)",nDet,xminDet,xmaxDet);
238 TH2D *histMdetGenMC=
new TH2D(
"MdetgenMC",
";mass(det);mass(gen)",
239 nDet,xminDet,xmaxDet,nGen,xminGen,xmaxGen);
240 Int_t neventMC=rnd->Poisson(luminosityMC*crossSection);
241 for(Int_t i=0;i<neventMC;i++) {
242 Double_t mGen=GenerateEvent(0.3,
245 Double_t mDet=DetectorEvent(TMath::Abs(mGen));
254 histMgenMC->Fill(mGen,luminosityData/luminosityMC);
256 histMdetMC->Fill(mDet,luminosityData/luminosityMC);
271 histMdetGenMC->Fill(mDet,mGen,luminosityData/luminosityMC);
278 TH2D *histMdetGenSysMC=
new TH2D(
"MdetgenSysMC",
";mass(det);mass(gen)",
279 nDet,xminDet,xmaxDet,nGen,xminGen,xmaxGen);
280 neventMC=rnd->Poisson(luminosityMC*crossSection);
281 for(Int_t i=0;i<neventMC;i++) {
282 Double_t mGen=GenerateEvent
286 Double_t mDet=DetectorEvent(TMath::Abs(mGen));
287 histMdetGenSysMC->Fill(mDet,mGen,luminosityData/luminosityMC);
293 TH1D *histMgenData=
new TH1D(
"MgenData",
";mass(gen)",nGen,xminGen,xmaxGen);
294 TH1D *histMdetData=
new TH1D(
"MdetData",
";mass(det)",nDet,xminDet,xmaxDet);
295 Int_t neventData=rnd->Poisson(luminosityData*crossSection);
296 for(Int_t i=0;i<neventData;i++) {
297 Double_t mGen=GenerateEvent(0.4,
300 Double_t mDet=DetectorEvent(TMath::Abs(mGen));
303 histMgenData->Fill(mGen);
306 histMdetData->Fill(mDet);
311 TH1D *histDensityGenData=
new TH1D(
"DensityGenData",
";mass(gen)",
312 nGen,xminGen,xmaxGen);
313 TH1D *histDensityGenMC=
new TH1D(
"DensityGenMC",
";mass(gen)",
314 nGen,xminGen,xmaxGen);
315 for(Int_t i=1;i<=nGen;i++) {
316 histDensityGenData->SetBinContent(i,histMgenData->GetBinContent(i)/
317 histMgenData->GetBinWidth(i));
318 histDensityGenMC->SetBinContent(i,histMgenMC->GetBinContent(i)/
319 histMgenMC->GetBinWidth(i));
325 TUnfoldDensity unfold(histMdetGenMC,TUnfold::kHistMapOutputVert);
333 if(unfold.SetInput(histMdetData)>=10000) {
334 std::cout<<
"Unfolding result may be wrong\n";
346 TSpline *logTauX,*logTauY;
350 #ifdef VERBOSE_LCURVE_SCAN
351 Int_t oldinfo=gErrorIgnoreLevel;
352 gErrorIgnoreLevel=kInfo;
356 iBest=unfold.ScanLcurve(nScan,tauMin,tauMax,&lCurve,&logTauX,&logTauY);
359 #ifdef VERBOSE_LCURVE_SCAN
360 gErrorIgnoreLevel=oldinfo;
367 Double_t SYS_ERROR1_MSTART=6;
368 Double_t SYS_ERROR1_SIZE=0.1;
369 TH2D *histMdetGenSys1=
new TH2D(
"Mdetgensys1",
";mass(det);mass(gen)",
370 nDet,xminDet,xmaxDet,nGen,xminGen,xmaxGen);
371 for(Int_t i=0;i<=nDet+1;i++) {
372 if(histMdetData->GetBinCenter(i)>=SYS_ERROR1_MSTART) {
373 for(Int_t j=0;j<=nGen+1;j++) {
374 histMdetGenSys1->SetBinContent(i,j,SYS_ERROR1_SIZE);
378 unfold.AddSysError(histMdetGenSysMC,
"SYSERROR_MC",TUnfold::kHistMapOutputVert,
379 TUnfoldSys::kSysErrModeMatrix);
380 unfold.AddSysError(histMdetGenSys1,
"SYSERROR1",TUnfold::kHistMapOutputVert,
381 TUnfoldSys::kSysErrModeRelative);
386 std::cout<<
"tau="<<unfold.GetTau()<<
"\n";
387 std::cout<<
"chi**2="<<unfold.GetChi2A()<<
"+"<<unfold.GetChi2L()
388 <<
" / "<<unfold.GetNdf()<<
"\n";
389 std::cout<<
"chi**2(sys)="<<unfold.GetChi2Sys()<<
"\n";
395 Double_t t[1],x[1],y[1];
396 logTauX->GetKnot(iBest,t[0],x[0]);
397 logTauY->GetKnot(iBest,t[0],y[0]);
398 TGraph *bestLcurve=
new TGraph(1,x,y);
399 TGraph *bestLogTauLogChi2=
new TGraph(1,t,x);
405 TH1 *histMunfold=unfold.GetOutput(
"Unfolded");
408 TH1 *histMdetFold=unfold.GetFoldedOutput(
"FoldedBack");
416 TH2 *histEmatTotal=unfold.GetEmatrixTotal(
"EmatTotal");
419 TH1D *histTotalError=
420 new TH1D(
"TotalError",
";mass(gen)",nGen,xminGen,xmaxGen);
421 for(Int_t bin=1;bin<=nGen;bin++) {
422 histTotalError->SetBinContent(bin,histMunfold->GetBinContent(bin));
423 histTotalError->SetBinError
424 (bin,TMath::Sqrt(histEmatTotal->GetBinContent(bin,bin)));
432 TH1 *histRhoi=unfold.GetRhoItotal(
"rho_I",
445 gFitter=TVirtualFitter::Fitter(histMunfold);
446 gFitter->SetFCN(chisquare_corr);
448 TF1 *bw=
new TF1(
"bw",bw_func,xminGen,xmaxGen,3);
449 bw->SetParameter(0,1000.);
450 bw->SetParameter(1,3.8);
451 bw->SetParameter(2,0.2);
455 histMunfold->Fit(bw,
"UE");
469 histMdetGenMC->Draw(
"BOX");
476 histTotalError->SetLineColor(kBlue);
477 histTotalError->Draw(
"E");
478 histMunfold->SetLineColor(kGreen);
479 histMunfold->Draw(
"SAME E1");
480 histDensityGenData->SetLineColor(kRed);
481 histDensityGenData->Draw(
"SAME");
482 histDensityGenMC->Draw(
"SAME HIST");
489 histMdetFold->SetLineColor(kBlue);
490 histMdetFold->Draw();
491 histMdetMC->Draw(
"SAME HIST");
493 TH1 *histInput=unfold.GetInput(
"Minput",
";mass(det)");
495 histInput->SetLineColor(kRed);
496 histInput->Draw(
"SAME");
505 bestLogTauLogChi2->SetMarkerColor(kRed);
506 bestLogTauLogChi2->Draw(
"*");
511 bestLcurve->SetMarkerColor(kRed);
512 bestLcurve->Draw(
"*");
514 output.SaveAs(
"testUnfold1.ps");