22 #include "RooRealVar.h"
23 #include "RooDataHist.h"
24 #include "RooArgList.h"
26 #include "RooBreitWigner.h"
27 #include "RooCBShape.h"
28 #include "RooFFTConvPdf.h"
29 #include "RooGlobalFunc.h"
30 #include "RooFitResult.h"
39 TFile*
f = TFile::Open(inFilename.c_str(),
"UPDATE");
40 if (
f == 0 || !
f->IsOpen()) {
45 if (
f->GetSize() < 1000.) {
51 TIter next_run(
f->GetListOfKeys());
53 while ((key_run =
dynamic_cast<TKey*
>(next_run())) != 0) {
54 TObject* obj_run = key_run->ReadObj();
55 TDirectory* tdir_run =
dynamic_cast<TDirectory*
>(obj_run);
57 std::string tdir_run_name(tdir_run->GetName());
58 if (tdir_run_name.find(
"run") != std::string::npos) {
59 run_dir = tdir_run_name;
60 TIter next_perf(tdir_run->GetListOfKeys());
62 while ((key_perf =
dynamic_cast<TKey*
>(next_perf())) != 0) {
63 std::string perf_name(key_perf->GetName());
64 if (perf_name.find(
"DiMuMon") != std::string::npos) {
65 TObject* obj_perf = key_perf->ReadObj();
66 TDirectory* tdir_perf =
dynamic_cast<TDirectory*
>(obj_perf);
68 run_dir = run_dir +
'/';
69 TIter next_module(tdir_perf->GetListOfKeys());
71 while ((key_module =
dynamic_cast<TKey*
>(next_module())) != 0) {
72 std::string module_name(key_module->GetName());
73 if (module_name.find(
"Jpsi") != std::string::npos) {
75 }
else if (module_name.find(
"Zmumu") != std::string::npos) {
86 else if (tdir_run_name.find(
"DiMuMon") != std::string::npos) {
87 TObject* obj_perf = key_run->ReadObj();
88 TDirectory* tdir_perf =
dynamic_cast<TDirectory*
>(obj_perf);
91 TIter next_module(tdir_perf->GetListOfKeys());
93 while ((key_module =
dynamic_cast<TKey*
>(next_module())) != 0) {
94 std::string module_name(key_module->GetName());
95 if (module_name.find(
"Jpsi") != std::string::npos) {
97 }
else if (module_name.find(
"Zmumu") != std::string::npos) {
116 const std::string& moduleName) {
117 TObject* obj_mod = key_module->ReadObj();
118 TDirectory* tdir_mod =
dynamic_cast<TDirectory*
>(obj_mod);
121 TIter next_trigger(tdir_mod->GetListOfKeys());
122 TKey* key_trigger(0);
123 while ((key_trigger =
dynamic_cast<TKey*
>(next_trigger())) != 0) {
124 std::string triggerName = key_trigger->GetName();
134 const std::string& triggerName) {
137 path = run_dir +
"DiMuMon/" + resonName +
"/" + triggerName;
139 if (
f->cd(
path.c_str()) == 0) {
142 std::vector<std::string> regions;
143 regions.push_back(
"All");
144 regions.push_back(
"BB");
145 regions.push_back(
"EAEA");
146 regions.push_back(
"ECEC");
147 std::vector<std::string> vars;
148 vars.push_back(
"eta");
149 vars.push_back(
"etaAll");
150 vars.push_back(
"etaPos");
151 vars.push_back(
"etaNeg");
152 vars.push_back(
"phi");
153 vars.push_back(
"phiAll");
154 vars.push_back(
"phiPos");
155 vars.push_back(
"phiNeg");
156 vars.push_back(
"pt");
157 vars.push_back(
"ptAll");
158 vars.push_back(
"ptPos");
159 vars.push_back(
"ptNeg");
160 vars.push_back(
"etaDiff");
161 vars.push_back(
"etaSumm");
162 vars.push_back(
"phiDiff");
163 vars.push_back(
"phiSumm");
164 vars.push_back(
"crtDiff");
166 std::map< std::string, TH1F* > h_invmass;
167 std::map< std::string, std::map< std::string, TH2F*> > h_2DinvmassVSx;
168 std::map< std::string, std::map< std::string, TH1F*> > h_invmassVSx;
169 std::map< std::string, std::map< std::string, TH1F*> > h_widthVSx;
177 h_chi2 = (
TH1F*) (
f->Get((
path +
"_detail/chi2").c_str())->Clone());
179 std::vector<std::string>
::iterator ireg = regions.begin();
180 for (ireg = regions.begin(); ireg != regions.end(); ++ireg) {
182 std::string hname2D = resonName +
"_2DinvmassVS" + *
ivar +
"_" + *ireg;
184 h_2DinvmassVSx[*ireg][*
ivar] = (
TH2F*) (
f->Get((
path +
"/" + hname2D).c_str())->Clone());
185 std::string hnameMean = resonName +
"_invmassVS" + *
ivar +
"_" + *ireg;
186 std::string hnameWidth = resonName +
"_widthVS" + *
ivar +
"_" + *ireg;
187 std::vector<TH1F*> hfitted;
189 h_invmassVSx[*ireg][*
ivar] = (
TH1F*) (
f->Get((
path +
"/" + hnameMean).c_str())->Clone());
190 hfitted.push_back(h_invmassVSx[*ireg][*
ivar]);
192 h_widthVSx[*ireg][*
ivar] = (
TH1F*) (
f->Get((
path +
"_detail/" + hnameWidth).c_str())->Clone());
193 hfitted.push_back(h_widthVSx[*ireg][*
ivar]);
194 fitHistos(h_2DinvmassVSx[*ireg][*
ivar], hfitted, 0, triggerName, resonName, h_chi2);
198 f->cd((
path +
"/").c_str());
199 h_invmassVSx[*ireg][*
ivar]->Write(
"", TObject::kOverwrite);
200 f->cd((
path +
"_detail/").c_str());
201 h_widthVSx[*ireg][*
ivar]->Write(
"", TObject::kOverwrite);
203 fitHistos(h_2DinvmassVSx[*ireg][*
ivar], hfitted, 1, triggerName, resonName, h_chi2);
206 f->cd((
path +
"/").c_str());
207 h_invmassVSx[*ireg][*
ivar]->Write(
"", TObject::kOverwrite);
211 h_widthVSx[*ireg][*
ivar] = (
TH1F*) (
f->Get((
path +
"_detail/" + hnameWidth).c_str())->Clone());
212 hfitted.push_back(h_widthVSx[*ireg][*
ivar]);
213 fitHistos(h_2DinvmassVSx[*ireg][*
ivar], hfitted, 2, triggerName, resonName, h_chi2);
217 f->cd((
path +
"_detail/").c_str());
218 h_widthVSx[*ireg][*
ivar]->Write((
path +
"_detail/" + hnameWidth).c_str(), TObject::kOverwrite);
224 h_chi2->Write(
"", TObject::kOverwrite);
230 const std::string& resonName,
TH1F* h_chi2) {
231 bool saveHistos =
false;
235 std::string
hname = hin->GetName();
238 int nbins = hin->GetNbinsX();
240 snprintf(num2str, 50,
"%s_%i", (
hname).c_str(),
i);
241 TH1F* htemp = (
TH1F*) (hin->ProjectionY(num2str,
i + 1,
i + 1));
244 if (htemp->GetEntries() > 50) {
245 double mean = 999., meanErr = 999.,
sigma = 999., sigmaErr = 999.,
chi2 = 0.;
246 if (resonName ==
"Jpsi" || resonName ==
"Upsi") {
247 mean = htemp->GetMean();
248 sigma = htemp->GetRMS();
250 fn->SetParameters(htemp->GetEntries() / 4,
mean,
sigma);
251 htemp->Fit(
"fn",
"RQMN");
252 mean =
fn->GetParameter(1);
256 if (saveHistos ==
false) {
257 htemp->Fit(
"fn",
"RQMN");
259 ctemp =
new TCanvas(
"ctemp",
"ctemp", 500, 500);
260 TString psName = num2str + triggerName +
".ps";
261 htemp->Fit(
"fn",
"RQM");
262 ctemp->Print(psName);
265 double frange = 2.4 *
sigma;
266 double hrange = htemp->GetXaxis()->GetXmax() - htemp->GetXaxis()->GetXmin();
267 double ndf = frange / hrange * (htemp->GetNbinsX()) - 3;
269 mean =
fn->GetParameter(1);
270 meanErr =
fn->GetParError(1);
272 sigmaErr =
fn->GetParError(2);
279 RooAbsPdf::verboseEval(-100);
280 RooRealVar
m(
"mass",
"dimuon invariable mass", 91.2, 71., 111.,
"GeV");
281 RooDataHist*
data = 0;
282 data =
new RooDataHist(
"data",
"data",
m, htemp);
283 RooRealVar bwm0(
"bw_#mu",
"bw_#mu", 91.2, 85.2, 97.2);
284 RooRealVar bwsg(
"bw_#sigma",
"bw_#sigma", 2.4952);
285 RooBreitWigner bw(
"bw",
"bw",
m, bwm0, bwsg);
287 RooRealVar cbm0(
"cb_#mu",
"cb_#mu", 0);
288 RooRealVar cbsg(
"cb_#sigma",
"cb_#sigma", 3., 1., 10.);
289 RooRealVar cbal(
"cb_#alpha",
"cb_#alpha", 2.0);
290 RooRealVar cbn(
"cb_n",
"cb_n", 1., 0.05, 3.);
291 RooCBShape cb(
"cb",
"cb",
m, cbm0, cbsg, cbal, cbn);
294 RooFFTConvPdf bxc(
"bxc",
"BW (X) CB",
m, bw, cb);
295 auto resourceToDelete = bxc.fitTo(*
data, RooFit::PrintLevel(-1), RooFit::PrintEvalErrors(-1), RooFit::Warnings(kFALSE));
297 if (saveHistos ==
true) {
299 data->plotOn(frame, RooFit::MarkerSize(0.9));
301 bxc.plotOn(frame, RooFit::LineColor(kBlue));
304 delete resourceToDelete;
305 mean = bwm0.getVal();
306 meanErr = bwm0.getError();
307 sigma = cbsg.getVal();
308 sigmaErr = cbsg.getError();
313 hout.at(0)->SetBinContent(
i + 1,
mean);
314 hout.at(0)->SetBinError(
i + 1, meanErr);
315 hout.at(1)->SetBinContent(
i + 1,
sigma);
316 hout.at(1)->SetBinError(
i + 1, sigmaErr);
317 }
else if (
mode == 1) {
318 hout.at(0)->SetBinContent(
i + 1,
mean);
319 hout.at(0)->SetBinError(
i + 1, meanErr);
320 }
else if (
mode == 2) {
321 hout.at(0)->SetBinContent(
i + 1,
sigma);
322 hout.at(0)->SetBinError(
i + 1, sigmaErr);