-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_2_5.C
141 lines (113 loc) · 5.5 KB
/
task_2_5.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
void task_2_5(){
using namespace RooFit;
unsigned int cate = 0;
RooRealVar m("m","",5.0,5.8);
RooRealVar wgt("wgt","",1.,0.,1000.);
RooDataSet *rds_data = new RooDataSet("rds_data","",RooArgSet(m,wgt),"wgt");
RooDataSet *rds_mc = new RooDataSet("rds_mc","",RooArgSet(m));
TFile *fin = new TFile("/eos/uscms/store/user/cmsdas/2025/long_exercises/long-ex-bs-mumu/bspsiphiData.root");
TTree *tin = (TTree*)fin->Get("bspsiphiData");
unsigned int cate_t;
float wgt_t,m_t;
tin->SetBranchAddress("cate",&cate_t);
tin->SetBranchAddress("wgt",&wgt_t);
tin->SetBranchAddress("m",&m_t);
for(int evt=0; evt<tin->GetEntries(); evt++) {
tin->GetEntry(evt);
if (cate_t!=cate) continue;
if (m_t<5.0 || m_t>=5.8) continue;
m.setVal(m_t);
wgt.setVal(wgt_t);
rds_data->add(RooArgSet(m,wgt),wgt_t);
}
delete fin;
fin = new TFile("/eos/uscms/store/user/cmsdas/2025/long_exercises/long-ex-bs-mumu/bspsiphiMc.root");
tin = (TTree*)fin->Get("bspsiphiMc");
tin->SetBranchAddress("cate",&cate_t);
tin->SetBranchAddress("m",&m_t);
for(int evt=0; evt<tin->GetEntries(); evt++) {
tin->GetEntry(evt);
if (cate_t!=cate) continue;
if (m_t<5.0 || m_t>=5.8) continue;
m.setVal(m_t);
rds_mc->add(RooArgSet(m));
}
delete fin;
RooRealVar sigmc_mean1("sigmc_mean1","",5.37,5.2,5.5);
RooRealVar sigmc_mean2("sigmc_mean2","",5.37,5.2,5.5);
RooRealVar sigmc_sigma1("sigmc_sigma1","",0.030,0.005,0.060);
RooRealVar sigmc_sigma2("sigmc_sigma2","",0.080,0.040,0.200);
RooRealVar sig_frac("sig_frac","",0.9,0.5,1.0);
RooGaussian sigmc_g1("sig_g1","",m,sigmc_mean1,sigmc_sigma1);
RooGaussian sigmc_g2("sig_g2","",m,sigmc_mean2,sigmc_sigma2);
RooAddPdf pdf_sigmc("pdf_sigmc","",RooArgList(sigmc_g1,sigmc_g2),RooArgList(sig_frac));
pdf_sigmc.fitTo(*rds_mc);
RooPlot *frame1 = m.frame(Title(" "),Bins(80));
rds_mc->plotOn(frame1, Name("t_rds_mc"));
pdf_sigmc.plotOn(frame1, Name("t_pdf_sigmc"), LineWidth(3));
TCanvas* canvas1 = new TCanvas("canvas1", "", 600, 600);
canvas1->SetMargin(0.15,0.06,0.13,0.07);
frame1->GetYaxis()->SetTitleOffset(1.50);
frame1->GetYaxis()->SetTitle("Entries / 0.01 GeV");
frame1->GetXaxis()->SetTitleOffset(1.15);
frame1->GetXaxis()->SetLabelOffset(0.01);
frame1->GetXaxis()->SetTitle("M(#mu#muKK) [GeV]");
frame1->GetXaxis()->SetTitleSize(0.043);
frame1->GetYaxis()->SetTitleSize(0.043);
frame1->Draw();
TLegend* leg1 = new TLegend(0.58,0.77,0.93,0.92);
leg1->SetFillStyle(0);
leg1->SetLineWidth(0);
leg1->SetHeader(Form("Category %d",cate));
leg1->AddEntry(frame1->findObject("t_rds_mc"),"Simluation","EP");
leg1->AddEntry(frame1->findObject("t_pdf_sigmc"),"Fit","L");
leg1->Draw();
canvas1->Print("task_2_5a.pdf");
canvas1->Print("task_2_5a.png");
sigmc_mean1.setConstant(true);
sigmc_mean2.setConstant(true);
sigmc_sigma1.setConstant(true);
sigmc_sigma2.setConstant(true);
sig_frac.setConstant(true);
RooRealVar sig_shift("sig_shift","",0.,-0.02,0.02);
RooRealVar sig_scale("sig_scale","",1.,0.8,1.2);
RooAddition sig_mean1("sig_mean1","",RooArgList(sigmc_mean1,sig_shift));
RooAddition sig_mean2("sig_mean2","",RooArgList(sigmc_mean2,sig_shift));
RooProduct sig_sigma1("sig_sigma1","",RooArgList(sigmc_sigma1,sig_scale));
RooProduct sig_sigma2("sig_sigma2","",RooArgList(sigmc_sigma2,sig_scale));
RooGaussian sig_g1("sig_g1","",m,sig_mean1,sig_sigma1);
RooGaussian sig_g2("sig_g2","",m,sig_mean2,sig_sigma2);
RooAddPdf pdf_sig("pdf_sig","",RooArgList(sig_g1,sig_g2),RooArgList(sig_frac));
RooRealVar comb_coeff("comb_coeff","",-1.2,-10.,10.);
RooExponential pdf_comb("pdf_comb","",m,comb_coeff);
double n_comb_guess = rds_data->sumEntries("m>5.46||m<5.26")*0.8/0.6;
double n_sig_guess = rds_data->sumEntries("m>5.26&&m<5.46")-n_comb_guess/4.;
RooRealVar n_sig("n_sig","",n_sig_guess,0.,rds_data->sumEntries());
RooRealVar n_comb("n_comb","",n_comb_guess,0.,rds_data->sumEntries());
RooAddPdf model("model","",RooArgList(pdf_sig,pdf_comb),RooArgList(n_sig,n_comb));
model.fitTo(*rds_data, Extended(true), SumW2Error(true));
RooPlot *frame2 = m.frame(Title(" "),Bins(80));
rds_data->plotOn(frame2, Name("t_rds_data"));
model.plotOn(frame2, Name("t_model"), LineWidth(3));
model.plotOn(frame2, Name("t_pdf_comb"), Components("pdf_comb"), LineWidth(3), LineStyle(2), LineColor(kGray+1));
TCanvas* canvas2 = new TCanvas("canvas2", "", 600, 600);
canvas2->SetMargin(0.15,0.06,0.13,0.07);
frame2->GetYaxis()->SetTitleOffset(1.50);
frame2->GetYaxis()->SetTitle("Entries / 0.01 GeV");
frame2->GetXaxis()->SetTitleOffset(1.15);
frame2->GetXaxis()->SetLabelOffset(0.01);
frame2->GetXaxis()->SetTitle("M(#mu#muKK) [GeV]");
frame2->GetXaxis()->SetTitleSize(0.043);
frame2->GetYaxis()->SetTitleSize(0.043);
frame2->Draw();
TLegend* leg2 = new TLegend(0.58,0.77,0.93,0.92);
leg2->SetFillStyle(0);
leg2->SetLineWidth(0);
leg2->SetHeader(Form("Category %d",cate));
leg2->AddEntry(frame2->findObject("t_rds_data"),"Data","EP");
leg2->AddEntry(frame2->findObject("t_model"),"Fit","L");
leg2->AddEntry(frame2->findObject("t_pdf_comb"),"Combinatorial bkg.","L");
leg2->Draw();
canvas2->Print("task_2_5b.pdf");
canvas2->Print("task_2_5b.png");
}