-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetPeakPos8TeV.cxx
97 lines (73 loc) · 2.92 KB
/
GetPeakPos8TeV.cxx
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
void GetPeakPos(){
TFile *fdata = TFile::Open("Pi0Tagging_8TeV_01_28.root", "Update");
TH2F* hdata = (TH2F*) fdata->Get("hInvMassVsPt_data");
TH2F* hMC = (TH2F*) fdata->Get("hInvMassVsPt_MC");
double xdata[100];
double ydata[100];
std::vector<float> vec = {1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.2, 2.4, 2.6,
2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.4, 4.8, 5.2,
5.6, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0,
12.0, 14.0, 20.0};
for(int i = 0; i < vec.size() - 1; ++i){
TH1D* hprojData = (TH1D*) hdata->ProjectionX(Form("hdata_%i", i), hdata->GetYaxis()->FindBin(vec.at(i) + 0.001), hdata->GetYaxis()->FindBin(vec.at(i+1) - 0.001));
TF1* fgaus = new TF1("fgaus", "gaus(0)", 0.1, 0.15);
fgaus->SetParLimits(1, 0.11, 0.15);
hprojData->Fit(fgaus, "M0R");
float mean = fgaus->GetParameter(1);
float sig = fgaus->GetParameter(2);
fgaus->SetRange(mean - 2*sig, mean + 2*sig);
hprojData->Fit(fgaus, "M0R");
xdata[i] = (vec.at(i)+vec.at(i+1)) / 2.;
ydata[i] = fgaus->GetParameter(1);
TCanvas Can("Can", "", 500, 500);
Can.cd();
hprojData->Draw();
fgaus->Draw("same");
Can.SaveAs(Form("DataBin%i.png", i));
}
TGraph grData(vec.size() - 1, xdata, ydata);
double xMC[100];
double yMC[100];
for(int i = 0; i < vec.size() - 1; ++i){
TH1D* hprojMC = (TH1D*) hMC->ProjectionX(Form("hMC_%i", i), hdata->GetYaxis()->FindBin(vec.at(i) + 0.001), hdata->GetYaxis()->FindBin(vec.at(i+1) - 0.001));
TF1* fgaus = new TF1("fgaus", "gaus(0)", 0.1, 0.15);
fgaus->SetParLimits(1, 0.11, 0.15);
hprojMC->Fit(fgaus, "M0R");
float mean = fgaus->GetParameter(1);
float sig = fgaus->GetParameter(2);
fgaus->SetRange(mean - 2*sig, mean + 2*sig);
hprojMC->Fit(fgaus, "MR0");
xMC[i] = (vec.at(i)+vec.at(i+1)) / 2.;
yMC[i] = fgaus->GetParameter(1);
TCanvas Can("Can", "", 500, 500);
Can.cd();
hprojMC->Draw();
fgaus->Draw("same");
Can.SaveAs(Form("MCBin%i.png", i));
}
TGraph grMC(vec.size() - 1, xMC, yMC);
TGraph *grRatio = (TGraph*) grData.Clone("ratio");
for(int i = 0; i < grMC.GetN(); ++i){
grRatio->SetPointY(i, grData.GetPointY(i)/grMC.GetPointY(i));
}
grRatio->Print();
TF1 funcData("funcData", "[0] + [1]*TMath::Power(x,[2])", 1.4,7);
TF1 funcMC("funcMC", "[0] + [1]*TMath::Power(x,[2])", 1.4,7);
grData.Fit(&funcData, "MQR0");
grMC.Fit(&funcMC, "MQR0");
TFile fMassPos("fMassPos.root", "Update");
fMassPos.cd();
grData.Write("MassPos8TeV_data", TObject::kOverwrite);
grMC.Write("MassPos8TeV_MC", TObject::kOverwrite);
funcData.Write("MassPos8TeV_func", TObject::kOverwrite);
fMassPos.Close();
TCanvas Can("Can", "", 1000, 1000);
Can.cd();
grData.Draw();
funcData.SetLineColor(1);
funcData.Draw("same");
funcMC.Draw("same");
grMC.SetLineColor(kRed);
grMC.Draw("same");
Can.SaveAs("PeakPos.png");
}