10 #include "RooAddPdf.h" 11 #include "RooDataHist.h" 12 #include "RooExponential.h" 13 #include "RooGaussian.h" 15 #include "RooRealVar.h" 16 #include "RooVoigtian.h" 17 #include "RooCBShape.h" 21 : TopFolder_(iConfig.getParameter<
std::
string>(
"FolderName")),
22 useTH1s_(iConfig.getParameter<
bool>(
"useTH1s")),
23 fitBackground_(iConfig.getParameter<
bool>(
"fitBackground")),
24 useRooCBShape_(iConfig.getParameter<
bool>(
"useRooCBShape")),
25 useRooCMSShape_(iConfig.getParameter<
bool>(
"useRooCMSShape")),
26 debugMode_(iConfig.getParameter<
bool>(
"debugMode")),
30 edm::LogInfo(
"DiMuonMassBiasClient") <<
"DiMuonMassBiasClient::Constructing DiMuonMassBiasClient ";
52 edm::LogInfo(
"DiMuonMassBiasClient") <<
"DiMuonMassBiasClient::Deleting DiMuonMassBiasClient ";
59 edm::LogInfo(
"DiMuonMassBiasClient") <<
"DiMuonMassBiasClient::beginJob done";
66 edm::LogInfo(
"DiMuonMassBiasClient") <<
"DiMuonMassBiasClient:: Begining of Run";
76 edm::LogError(
"DiMuonMassBiasClient") <<
"could not find MonitorElement for key: " <<
key << std::endl;
80 const auto&
title =
ME->getTitle();
81 const auto&
xtitle =
ME->getAxisTitle(1);
82 const auto&
ytitle =
ME->getAxisTitle(2);
84 const auto& nxbins =
ME->getNbinsX();
85 const auto&
xmin =
ME->getAxisMin(1);
86 const auto&
xmax =
ME->getAxisMax(1);
108 if (toHarvest ==
nullptr) {
109 edm::LogError(
"DiMuonMassBiasClient") <<
"could not find input MonitorElement: " << inFolder + hname << std::endl;
122 const auto&
key = toHarvest.first;
123 const auto&
ME = toHarvest.second;
126 edm::LogPrint(
"DiMuonMassBiasClient") <<
"dealing with key: " <<
key << std::endl;
129 edm::LogError(
"DiMuonMassBiasClient") <<
"could not find MonitorElement for key: " <<
key << std::endl;
133 const auto&
title =
ME->getTitle();
134 const auto&
xtitle =
ME->getAxisTitle(1);
135 const auto&
ytitle =
ME->getAxisTitle(2);
137 const auto& nxbins =
ME->getNbinsX();
138 const auto&
xmin =
ME->getAxisMin(1);
139 const auto&
xmax =
ME->getAxisMax(1);
141 TProfile* p_mean =
new TProfile((
"Mean" +
key).c_str(),
142 (
title +
";" +
xtitle +
";#LT M_{#mu^{-}#mu^{+}} #GT [GeV]").c_str(),
148 TProfile* p_width =
new TProfile(
154 TH2F* bareHisto =
ME->getTH2F();
155 for (
int bin = 1;
bin <= nxbins;
bin++) {
156 const auto&
xaxis = bareHisto->GetXaxis();
157 const auto& low_edge =
xaxis->GetBinLowEdge(
bin);
158 const auto& high_edge =
xaxis->GetBinUpEdge(
bin);
161 edm::LogPrint(
"DiMuonMassBiasClient") <<
"dealing with bin: " <<
bin <<
" range: (" << std::setprecision(2)
162 << low_edge <<
"," << std::setprecision(2) << high_edge <<
")";
164 TH1D* Proj = bareHisto->ProjectionY(Form(
"%s_proj_%i",
key.c_str(),
bin),
bin,
bin);
165 Proj->SetTitle(Form(
"%s #in (%.2f,%.2f), bin: %i", Proj->GetTitle(), low_edge, high_edge,
bin));
170 edm::LogWarning(
"DiMuonMassBiasClient") <<
"the current bin has invalid data" << std::endl;
185 p_mean->SetBinEntries(
bin, 1. / (bias.
error() * bias.
error()));
188 LogDebug(
"DiMuonBassBiasClient") <<
" Bin: " <<
bin <<
" value: " << bias.
value() <<
" from profile ( " 189 << p_mean->GetBinContent(
bin) <<
") - error: " << bias.
error()
190 <<
" from profile ( " << p_mean->GetBinError(
bin) <<
" )";
197 p_width->SetBinEntries(
bin, 1. / (
width.error() *
width.error()));
217 const auto&
key = toHarvest.first;
218 const auto&
ME = toHarvest.second;
221 edm::LogPrint(
"DiMuonMassBiasClient") <<
"dealing with key: " <<
key << std::endl;
224 edm::LogError(
"DiMuonMassBiasClient") <<
"could not find MonitorElement for key: " <<
key << std::endl;
228 TH2F* bareHisto =
ME->getTH2F();
230 const auto&
xaxis = bareHisto->GetXaxis();
231 const auto& low_edge =
xaxis->GetBinLowEdge(
bin);
232 const auto& high_edge =
xaxis->GetBinUpEdge(
bin);
235 edm::LogPrint(
"DiMuonMassBiasClient") <<
"dealing with bin: " <<
bin <<
" range: (" << std::setprecision(2)
236 << low_edge <<
"," << std::setprecision(2) << high_edge <<
")";
237 TH1D* Proj = bareHisto->ProjectionY(Form(
"%s_proj_%i",
key.c_str(),
bin),
bin,
bin);
238 Proj->SetTitle(Form(
"%s #in (%.2f,%.2f), bin: %i", Proj->GetTitle(), low_edge, high_edge,
bin));
243 edm::LogWarning(
"DiMuonMassBiasClient") <<
"the current bin has invalid data" << std::endl;
263 edm::LogInfo(
"DiMuonMassBiasClient") <<
"DiMuonMassBiasClient::endLuminosityBlock";
288 edm::LogWarning(
"DiMuonMassBiasClient") <<
" Input histogram:" <<
hist->GetName() <<
" has not enough entries (" 289 <<
hist->GetEntries() <<
") for a meaningful Voigtian fit!\n" 295 TCanvas*
c1 =
new TCanvas();
298 c1->SetLeftMargin(0.15);
299 c1->SetRightMargin(0.10);
305 Double_t
xmin =
hist->GetXaxis()->GetXmin();
306 Double_t
xmax =
hist->GetXaxis()->GetXmax();
309 edm::LogPrint(
"DiMuonMassBiasClient") <<
"fitting range: (" <<
xmin <<
"-" <<
xmax <<
")" << std::endl;
312 RooRealVar InvMass(
"InvMass",
"di-muon mass M(#mu^{+}#mu^{-}) [GeV]",
xmin,
xmax);
313 std::unique_ptr<RooPlot>
frame{InvMass.frame()};
314 RooDataHist datahist(
"datahist",
"datahist", InvMass, RooFit::Import(*
hist));
315 datahist.plotOn(
frame.get());
318 RooRealVar
mean(
"#mu",
"mean", meanConfig_[0], meanConfig_[1], meanConfig_[2]);
319 RooRealVar
width(
"width",
"width", widthConfig_[0], widthConfig_[1], widthConfig_[2]);
320 RooRealVar sigma(
"#sigma",
"sigma", sigmaConfig_[0], sigmaConfig_[1], sigmaConfig_[2]);
321 RooVoigtian voigt(
"voigt",
"voigt", InvMass,
mean,
width, sigma);
324 RooRealVar peakCB(
"peakCB",
"peakCB", meanConfig_[0], meanConfig_[1], meanConfig_[2]);
325 RooRealVar sigmaCB(
"#sigma",
"sigma", sigmaConfig_[0], sigmaConfig_[1], sigmaConfig_[2]);
326 RooRealVar alphaCB(
"#alpha",
"alpha", 1., 0., 10.);
327 RooRealVar nCB(
"n",
"n", 1., 0., 100.);
328 RooCBShape
crystalball(
"crystalball",
"crystalball", InvMass, peakCB, sigmaCB, alphaCB, nCB);
331 RooRealVar lambda(
"#lambda",
"slope", 0., -50., 50.);
332 RooExponential expo(
"expo",
"expo", InvMass, lambda);
335 RooRealVar exp_alpha(
"#alpha",
"alpha", 40.0, 20.0, 160.0);
336 RooRealVar exp_beta(
"#beta",
"beta", 0.05, 0.0, 2.0);
337 RooRealVar exp_gamma(
"#gamma",
"gamma", 0.02, 0.0, 0.1);
338 RooRealVar exp_peak(
"peak",
"peak", meanConfig_[0]);
339 RooCMSShape exp_pdf(
"exp_pdf",
"bkg shape", InvMass, exp_alpha, exp_beta, exp_gamma, exp_peak);
342 RooRealVar
b(
"N_{b}",
"Number of background events", 0,
hist->GetEntries() / 10.);
343 RooRealVar
s(
"N_{s}",
"Number of signal events", 0,
hist->GetEntries());
345 if (fitBackground_) {
347 if (useRooCBShape_) {
348 if (useRooCMSShape_) {
351 listPdf.add(exp_pdf);
358 if (useRooCMSShape_) {
361 listPdf.add(exp_pdf);
369 RooAddPdf fullModel(
"fullModel",
"Signal + Background Model", listPdf, RooArgList(
s,
b));
370 fullModel.fitTo(datahist, RooFit::PrintLevel(-1));
371 fullModel.plotOn(
frame.get(), RooFit::LineColor(kRed));
372 if (useRooCMSShape_) {
373 fullModel.plotOn(
frame.get(), RooFit::Components(exp_pdf), RooFit::LineStyle(kDashed));
375 fullModel.plotOn(
frame.get(), RooFit::Components(expo), RooFit::LineStyle(kDashed));
377 fullModel.paramOn(
frame.get(), RooFit::Layout(0.65, 0.90, 0.90));
379 if (useRooCBShape_) {
381 crystalball.fitTo(datahist, RooFit::PrintLevel(-1));
384 RooFit::Layout(0.65, 0.90, 0.90));
387 voigt.fitTo(datahist, RooFit::PrintLevel(-1));
388 voigt.plotOn(
frame.get(), RooFit::LineColor(kRed));
389 voigt.paramOn(
frame.get(), RooFit::Layout(0.65, 0.90, 0.90));
394 datahist.plotOn(
frame.get());
395 frame->GetYaxis()->SetTitle(
"n. of events");
396 TString histName =
hist->GetName();
397 frame->SetName(
"frame" + histName);
402 c1->Print(
"fit_debug" + histName +
".pdf");
406 float mass_mean = useRooCBShape_ ? peakCB.getVal() :
mean.getVal();
407 float mass_sigma = useRooCBShape_ ? sigmaCB.getVal() : sigma.getVal();
409 float mass_mean_err = useRooCBShape_ ? peakCB.getError() :
mean.getError();
410 float mass_sigma_err = useRooCBShape_ ? sigmaCB.getError() : sigma.getError();
424 desc.add<
bool>(
"useTH1s",
false);
425 desc.add<
bool>(
"fitBackground",
false);
426 desc.add<
bool>(
"useRooCMSShape",
false);
427 desc.add<
bool>(
"useRooCBShape",
false);
428 desc.add<
bool>(
"debugMode",
false);
431 fit_par.add<std::vector<double>>(
"mean_par",
436 fit_par.add<std::vector<double>>(
"width_par",
441 fit_par.add<std::vector<double>>(
"sigma_par",
448 desc.add<std::vector<std::string>>(
"MEtoHarvest",
449 {
"DiMuMassVsMuMuPhi",
451 "DiMuMassVsMuPlusPhi",
452 "DiMuMassVsMuPlusEta",
453 "DiMuMassVsMuMinusPhi",
454 "DiMuMassVsMuMinusEta",
455 "DiMuMassVsMuMuDeltaEta",
456 "DiMuMassVsCosThetaCS"});
void getMEsToHarvest(DQMStore::IGetter &igetter)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
std::map< std::string, MonitorElement * > widthHistos_
virtual void setCurrentFolder(std::string const &fullpath)
static PFTauRenderPlugin instance
diMuonMassBias::fitOutputs fitLineShape(TH1 *hist, const bool &fitBackground=false) const
~DiMuonMassBiasClient() override
Destructor.
const std::string TopFolder_
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
BeginRun.
Log< level::Error, false > LogError
std::map< std::string, MonitorElement * > harvestTargets_
std::map< std::string, MonitorElement * > meanProfiles_
std::map< std::string, MonitorElement * > widthProfiles_
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
#define DEFINE_FWK_MODULE(type)
std::vector< std::string > MEtoHarvest_
Log< level::Warning, true > LogPrint
void dqmEndJob(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_) override
EndJob.
void beginJob(void) override
BeginJob.
Log< level::Info, false > LogInfo
void fitAndFillProfile(std::pair< std::string, MonitorElement *> toHarvest, DQMStore::IBooker &iBooker)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static constexpr int minimumHits
virtual MonitorElement * get(std::string const &fullpath) const
DiMuonMassBiasClient(const edm::ParameterSet &ps)
Constructor.
std::map< std::string, MonitorElement * > meanHistos_
void bookMEs(DQMStore::IBooker &ibooker)
book MEs
void fitAndFillHisto(std::pair< std::string, MonitorElement *> toHarvest, DQMStore::IBooker &iBooker)
double crystalball(double *x, double *par)
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
void fillArrayF(float *x, const edm::ParameterSet &cfg, const char *name)