-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analise.C
186 lines (136 loc) · 5.69 KB
/
Analise.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <iostream>
#include <TTree.h>
#include <vector>
#include <TLorentzVector.h>
#include <fstream>
#include <string>
#include <cstring>
#include <THStack.h>
#include <stdio.h>
#include <TLatex.h>
#include <TF1.h>
#include <TH1.h>
#include <TGaxis.h>
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooPlot.h"
#include "RooCBShape.h"
#include "RooChebychev.h"
#include "RooWorkspace.h"
#include "RooAbsData.h"
#include "RooArgSet.h"
#include "RooAbsArg.h"
#include "RooStats/ModelConfig.h"
#include "RooExponential.h"
using namespace std;
using namespace RooFit;
using namespace RooStats;
void Analise(){
// Declaration of leaf types
Double_t event;
TLorentzVector *dimuon_p4;
TLorentzVector *muonP_p4;
TLorentzVector *muonN_p4;
// List of branches
TBranch *b_event;
TBranch *b_dimuon_p4;
TBranch *b_muonP_p4;
TBranch *b_muonN_p4;
//List of histos
TH1S *hUpiMassCut = new TH1S("UpiMass", "m_{#Upislon}", 200, 8.5, 9.86);
hUpiMassCut->GetXaxis()->SetTitle("m_{#Upislon} (GeV)");
hUpiMassCut->GetYaxis()->SetTitle("Events");
TH1S *hdimuonMass = new TH1S("dimuonMass", "m_{#mu^{+}#mu^{-}}", 500000,200,2000);
hdimuonMass->GetXaxis()->SetTitle("m_{#mu^{+}#mu^{-}} (GeV)");
hdimuonMass->GetYaxis()->SetTitle("Events");
//pointer to the analyzed TTree or TChain
TChain* fChain = new TChain("oniaTree");
fChain->Add("Skim4.root/oniaTree;5");
fChain->Add("Skim4.root/oniaTree;4");
fChain->SetMakeClass(1);
// Set object pointer
dimuon_p4 = 0;
muonP_p4 = 0;
muonN_p4 = 0;
// Set branch addresses and branch pointers
fChain->SetBranchAddress("event", &event, &b_event);
fChain->SetBranchAddress("dimuon_p4", &dimuon_p4, &b_dimuon_p4);
fChain->SetBranchAddress("muonP_p4", &muonP_p4, &b_muonP_p4);
fChain->SetBranchAddress("muonN_p4", &muonN_p4, &b_muonN_p4);
int nentries = fChain->GetEntries();
cout << "Numero de entradas " << nentries << endl;
for(int i=0; i<nentries; i++){
fChain->GetEntry(i);
double etacut = abs(dimuon_p4->Eta());
double mass = dimuon_p4->M();
double pt1 = muonN_p4->Pt();
double pt2 = muonP_p4->Pt();
if(pt1 > 3.5 && pt2 > 3.5 && etacut < 2.1 && mass >= 8.5 && mass <= 9.86)hUpiMassCut->Fill(mass);
hdimuonMass->Fill(mass);
} //for i
fChain->GetFile()->Close();
TCanvas *c = new TCanvas("c","c",5,5,1000,1000);
hUpiMassCut->Draw("E1");
hUpiMassCut->SetMarkerStyle(12);
hUpiMassCut->SetMarkerColor(10);
// Declare observable x
RooRealVar x("x","m_{#Upsilon}(GeV)",8.5,9.86);
// Fit/p.d.f to the data
RooRealVar mean("mean","m_{#Upsilon}",9.4,9.2,9.7) ;
RooRealVar sigma("sigma","#sigma_{m_{#Upsilon}}",0.01,0.6) ;
RooRealVar alpha("alpha","#alpha",-5,-0.000001);
RooRealVar constant("constant","Constant",0,10);
//RooCBShape pdf_sum("crystalBall", "crystalBall", x, mean, sigma, alpha, constant);
RooBreitWigner pdf_sum("pdf_sum","pdf_sum",x,mean,sigma);
//RooGaussian pdf_sum("sig","Signal component",x,mean,sigma);
//RooRealVar eff_upi("eff_upi","The upi efficiency",0.98,0.00001,1.);
//RooRealVar lumi_upi("lumi_psi","The CMS luminosity",900,0,1500,"pb-1");
RooRealVar cross_upi("cross_upi","The upi xsec",0.013,0.,40.,"pb");
//RooRealVar a("a","expo",-1,1);
RooRealVar a0("a0","a0",0.25,-1.,1) ;
RooRealVar a1("a1","a1",0.03,-0.1,1) ;
//RooRealVar a2("a2","a2",-0.5,-1.,1) ;
//RooExponential bkg("expo", "expo", x, a);
RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1));
//RooRealVar sigfrac("sigfrac","fraction of signal component",0.5,0.1,1.);
RooRealVar b("b", "N_{sig}",0,160000);
RooRealVar s("s", "N_{bg}",0,20000);
RooExtendPdf esig("esig","esig",pdf_sum,s) ;
RooExtendPdf ebkg("ebkg","ebkg",bkg,b) ;
RooAddPdf model("model", "model",RooArgList(esig,ebkg));
// Create a binned dataset that imports contents of TH1 and associates its contents to observable 'x'
RooDataHist dh("dh","dh",x,Import(*hUpiMassCut));
model.fitTo(dh);
RooFitResult* fitresult = model.fitTo(dh, Extended(true), Save() );
// Make plot of binned dataset showing Poisson error bars (RooFit default)
RooPlot* frame = x.frame();
dh.plotOn(frame);
model.plotOn(frame);
//model.plotOn(frame,Components(bkg),LineStyle(kDashed));
double n_param, reduced_chi_square;
n_param = fitresult->floatParsFinal().getSize();
reduced_chi_square = frame->chiSquare(n_param)/2.86;
model.plotOn(frame,Components(bkg),LineStyle(kDashed));
frame->Draw();
TPaveText* paveText = new TPaveText(0.5,0.5,0.9,0.9,"brNDC");
//paveText->SetBorderSize(1);
paveText->SetFillColor(kWhite);
paveText->SetFillStyle(1001);
paveText->SetTextSize(0.025);
paveText->AddText(Form("#chi^{2}/ndof = %10f ", reduced_chi_square));
paveText->AddText(Form("Mean_{m_{#Upsilon}} = %.5f #pm %.5f GeV", mean.getVal(), mean.getError()));
paveText->AddText(Form("#sigma_{m_{#Upsilon}} = %.5f #pm %.5f GeV", sigma.getVal(), sigma.getError()));
//paveText->AddText(Form("#alpha = %.5f #pm %.5f GeV", alpha.getVal(), alpha.getError()));
//paveText->AddText(Form("Constant = %.5f #pm %.5f GeV", constant.getVal(), constant.getError()));
//paveText->AddText(Form("chi square = %f ", reduced_chi_square));
//paveText->AddText(Form("sigfrac = %f #pm %f", sigfrac.getVal(), sigfrac.getError()));
paveText->AddText(Form("a0 = %.5f #pm %.5f GeV", a0.getVal(), a0.getError()));
paveText->AddText(Form("a1 = %f #pm %f", a1.getVal(), a1.getError()));
//paveText->AddText(Form("a2 = %f #pm %f", a2.getVal(), a2.getError()));
//paveText->AddText(Form("a = %f #pm %f", a.getVal(), a.getError()));
paveText->AddText(Form("s = %.5f #pm %.5f GeV", s.getVal(), s.getError()));
paveText->AddText(Form("b = %f #pm %f", b.getVal(), b.getError()));
paveText->Draw();
//frame->addObject(t1);
}