-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoUnfolding.C
97 lines (87 loc) · 2.61 KB
/
DoUnfolding.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
//Set environment variables
char libname[255];
sprintf(libname,"$AMSWD/lib/%s/ntuple_slc4_PG.so",gSystem->GetBuildArch());
gSystem->Load(libname);
gInterpreter->AddIncludePath("$AMSSRC/include");
TString curIncludePath(gSystem->GetIncludePath());
gSystem->SetIncludePath("-I/$AMSSRC/include"+curIncludePath);
BayesianUnfolder unfolder;
TFile fm("Draw/matrix_1.05.root");
// TFile fm("Draw/matrix_1.13.root");
// TFile fm("Draw/matrix_0.97.root");
TH2D *hmatrix = (TH2D*)fm.Get("hmatrix");
TFile fs("Draw/result.root");
TH1D *hunb = (TH1D*)fs.Get("hunb");
TH1D *hunc = (TH1D*)fs.Get("hunc");
TH1D hreb = *hunb;
hreb.Reset();
TH1D hrec = *hunc;
hrec.Reset();
//Temp modifications
for(int i=0; i<hunb->GetNbinsX(); i++)
{
if(hunb->GetBinCenter(i+1)<-0.0015) hunb->SetBinContent(i+1,0);
}
for(int i=0; i<hunc->GetNbinsX(); i++)
{
if(hunc->GetBinCenter(i+1)<-0.0015) hunc->SetBinContent(i+1,0);
}
//Unfolding
unfolder.computeAll(*hmatrix, *hunb, hreb, 100, true, true, 10);
unfolder.computeAll(*hmatrix, *hunc, hrec, 100, true, true, 10);
//Change the format
TH1D *hunreb= (TH1D*)hreb.Clone("hunreb");
TH1D *hunrec= (TH1D*)hrec.Clone("hunrec");
//Calculate the ratio
TH1D *hunrebc = (TH1D*)hunreb->Clone("hunrebc");
hunrebc->Divide(hunrec);
TH1D *hunbc = (TH1D*)hunb->Clone("hunbc");
hunbc->Divide(hunc);
for(int i=1; i<=hunbc->GetNbinsX(); i++)
{
if(hunb->GetBinContent(i)==0) continue;
double a = hunb->GetBinContent(i);
double ea = TMath::Sqrt(a);
double b = hunc->GetBinContent(i);
double eb = TMath::Sqrt(b);
hunbc->SetBinError(i,a/b*sqrt(ea*ea/a/a+eb*eb/b/b));
}
//Store results
TFile *fr = new TFile("unfolding.root","RECREATE");
fr->cd();
hunb->Write();
hunc->Write();
hunbc->Write();
hunreb->Write();
hunrec->Write();
hunrebc->Write();
fr->Write();
fr->Close();
//Print out the correction factors
cout<<"Correction factors of unfolding:"<<endl;
TH1D *hcorr = (TH1D*)hunrebc->Clone("hcorr");
hcorr->Divide(hunbc);
int count;
cout<<endl<<"Bin edges:"<<endl;
count = 0;
for(int i=hcorr->GetNbinsX(); i>0; i--)
{
double BinRightEdge = hcorr->GetBinLowEdge(i) + hcorr->GetBinWidth(i);
if(1/BinRightEdge > 4000) break;
cout<<1/BinRightEdge<<", ";
count++;
}
cout<<endl<<"count = "<<count<<endl;
cout<<endl<<"Correction factors:"<<endl;
count = 0;
for(int i=hcorr->GetNbinsX(); i>0; i--)
{
double BinLeftEdge = hcorr->GetBinLowEdge(i);
if(1/BinLeftEdge > 4000) break;
cout<<hcorr->GetBinContent(i)<<", ";
count++;
}
cout<<endl<<"count = "<<count<<endl;
cout<<endl;
}