14#include <dqm/analysis/modules/DQMHistAnalysisPhysics.h>
16#include <RooRealVar.h>
17#include <RooDataHist.h>
18#include "RooCBShape.h"
19#include "RooCrystalBall.h"
20#include "RooChebychev.h"
23#include "RooFitResult.h"
47 B2DEBUG(20,
"DQMHistAnalysisPhysics: Constructor done.");
67 m_ratio_text =
new TPaveText(0.55, 0.6, 0.85, 0.9,
"NDC");
77 m_cmUPSee =
new TCanvas(
"PhysicsObjects/fit_mUPSee");
82 m_cmUPSmumu =
new TCanvas(
"PhysicsObjects/fit_mUPSmumu");
85 addDeltaPar(
"PhysicsObjects",
"physicsresults", HistDelta::c_Events, 3000000, 1);
88 B2DEBUG(20,
"DQMHistAnalysisPhysics: initialized.");
94 B2DEBUG(20,
"DQMHistAnalysisPhysics: beginRun called.");
100 double xMin = histo->GetXaxis()->GetXmin();
101 double xMax = histo->GetXaxis()->GetXmax();
102 RooRealVar m(
"m", parts.c_str(), xMin, xMax);
104 RooDataHist data(
"data",
"histogram", m, histo);
106 RooRealVar mean(
"mean",
"mass", 10.579, 10.5, 10.7);
107 RooRealVar sigma(
"sigma",
"resolution", 0.05, 0.01, 0.15);
108 RooRealVar alphaL(
"alphaL",
"left tail alpha", 1.5, 0.1, 5);
109 RooRealVar nL(
"nL",
"left tail n", 1.0, 0.1, 10);
110 RooRealVar alphaR(
"alphaR",
"right tail alpha", 2.0, 0.1, 5);
111 RooRealVar nR(
"nR",
"right tail n", 1.0, 0.1, 10);
113 RooCrystalBall signal(
"signal",
"Double CB", m, mean, sigma, sigma, alphaL, nL, alphaR, nR);
115 RooRealVar a0(
"a0",
"poly constant", 0.0, -1.0, 1.0);
116 RooChebychev bkg(
"bkg",
"Background PDF", m, RooArgList(a0));
119 double nMax = histo->GetEntries() * 2.0;
120 RooRealVar nsig(
"nsig",
"yield of signal", histo->GetEntries() * 0.3, 0, nMax);
121 RooRealVar nbkg(
"nbkg",
"yield of background", histo->GetEntries() * 0.7, 0, nMax);
123 RooAddPdf model(
"model",
"sig+bkg", RooArgList(signal, bkg), RooArgList(nsig, nbkg));
125 model.fitTo(data, RooFit::Extended(kTRUE));
127 RooPlot* frame = m.frame();
128 data.plotOn(frame, RooFit::DrawOption(
"B"), RooFit::FillColor(kGray), RooFit::LineWidth(1), RooFit::MarkerSize(0),
129 RooFit::XErrorSize(0), RooFit::DataError(RooAbsData::None), RooFit::LineStyle(kSolid), RooFit::LineColor(kBlack));
130 model.plotOn(frame, RooFit::LineColor(kBlue), RooFit::LineWidth(1));
131 frame->SetTitle(
"Upsilon(4S) Mass Fit");
132 frame->GetXaxis()->SetTitle((parts).c_str());
135 auto measuredMass = mean.getVal();
136 auto massUncertainty = mean.getError();
137 auto measuredWidth = sigma.getVal();
140 double mean_mUPS = histo->GetMean();
141 text->AddText(Form(
"mean : %.3f",
float(mean_mUPS)));
142 text->AddText(Form(
"fit mean : %.3f +-%.3f",
float(measuredMass),
float(massUncertainty)));
143 text->AddText(Form(
"fit width : %.3f",
float(measuredWidth)));
147 m_monObj->setVariable(prefix +
"mass", measuredMass, massUncertainty);
148 m_monObj->setVariable(prefix +
"width", measuredWidth);
157 if (m_IsPhysicsRun ==
true) {
160 auto m_hphysicsresults =
findHist(
"PhysicsObjects/physicsresults",
true);
161 if (m_hphysicsresults) {
162 double had_ntot = m_hphysicsresults->GetBinContent(2);
163 double hadb2_ntot = m_hphysicsresults->GetBinContent(3);
164 double hadb2_tight_ntot = m_hphysicsresults->GetBinContent(4);
165 double mumu_tight_ntot = m_hphysicsresults->GetBinContent(5);
166 double bhabha_trk_ecl_ntot = m_hphysicsresults->GetBinContent(6);
168 double ratio_hadron_bhabha = 0.;
169 double ratio_hadronb2_bhabha = 0.;
170 double ratio_hadronb2_tight_bhabha = 0.;
171 double ratio_mumu_tight_bhabha = 0.;
172 double error_hadron_bhabha = -10.;
173 double error_hadronb2_bhabha = -10.;
174 double error_hadronb2_tight_bhabha = -10.;
175 double error_mumu_tight_bhabha = -10.;
178 if (bhabha_trk_ecl_ntot != 0) {
179 ratio_hadron_bhabha = had_ntot / bhabha_trk_ecl_ntot;
180 error_hadron_bhabha = ratio_hadron_bhabha *
sqrt((1 / had_ntot) + (1 / bhabha_trk_ecl_ntot));
181 ratio_hadronb2_bhabha = hadb2_ntot / bhabha_trk_ecl_ntot;
182 error_hadronb2_bhabha = ratio_hadronb2_bhabha *
sqrt((1 / hadb2_ntot) + (1 / bhabha_trk_ecl_ntot));
183 ratio_hadronb2_tight_bhabha = hadb2_tight_ntot / bhabha_trk_ecl_ntot;
184 error_hadronb2_tight_bhabha = ratio_hadronb2_tight_bhabha *
sqrt((1 / hadb2_tight_ntot) + (1 / bhabha_trk_ecl_ntot));
185 ratio_mumu_tight_bhabha = mumu_tight_ntot / bhabha_trk_ecl_ntot;
186 error_mumu_tight_bhabha = ratio_mumu_tight_bhabha *
sqrt((1 / mumu_tight_ntot) + (1 / bhabha_trk_ecl_ntot));
188 m_ratio_text->AddText(Form(
"hadronb2_tight/bhabha: %.4f +/- %.4f",
float(ratio_hadronb2_tight_bhabha),
189 float(error_hadronb2_tight_bhabha)));
190 m_ratio_text->AddText(Form(
"hadronb2/bhabha: %.4f +/- %.4f",
float(ratio_hadronb2_bhabha),
float(error_hadronb2_bhabha)));
191 m_ratio_text->AddText(Form(
"mumu_tight/bhabha: %.4f +/- %.4f",
float(ratio_mumu_tight_bhabha),
float(error_mumu_tight_bhabha)));
192 m_ratio_text->AddText(Form(
"hadron/bhabha: %.4f +/- %.4f",
float(ratio_hadron_bhabha),
float(error_hadron_bhabha)));
197 auto hist_hadronb2_tight_over_bhabha_trk_ecl =
getDelta(
"PhysicsObjects",
"physicsresults", 0,
true);
198 if (hist_hadronb2_tight_over_bhabha_trk_ecl) {
199 if (hist_hadronb2_tight_over_bhabha_trk_ecl->GetBinContent(6) != 0) {
200 double hadronb2_tight_over_bhabha_trk_ecl = hist_hadronb2_tight_over_bhabha_trk_ecl->GetBinContent(4) /
201 hist_hadronb2_tight_over_bhabha_trk_ecl->GetBinContent(6);
202 B2DEBUG(1,
"hadronb2_tight_over_bhabha_trk_ecl:" << hadronb2_tight_over_bhabha_trk_ecl);
203 setEpicsPV(
"hadronb2_tight_over_bhabha_trk_ecl", hadronb2_tight_over_bhabha_trk_ecl);
208 auto hmUPSmumu =
getDelta(
"PhysicsObjects/mUPS");
216 hmUPSmumu =
findHist(
"PhysicsObjects/mUPS",
true);
221 hmUPSmumu->Draw(
"hist");
226 auto hmUPSee =
getDelta(
"PhysicsObjects/mUPSe");
234 hmUPSee =
findHist(
"PhysicsObjects/mUPSe",
true);
239 hmUPSee->Draw(
"hist");
243 auto* m_cphysicsresults =
findCanvas(
"PhysicsObjects/c_physicsresults");
244 if (m_cphysicsresults) {
245 m_cphysicsresults->cd();
247 m_cphysicsresults->Modified();
248 m_cphysicsresults->Update();
254 auto m_hphysicsresults =
findHist(
"PhysicsObjects/physicsresults");
255 if (m_hphysicsresults) {
256 double had_ntot = m_hphysicsresults->GetBinContent(2);
257 double hadb2_ntot = m_hphysicsresults->GetBinContent(3);
258 double hadb2_tight_ntot = m_hphysicsresults->GetBinContent(4);
259 double mumu_tight_ntot = m_hphysicsresults->GetBinContent(5);
260 double bhabha_trk_ecl_ntot = m_hphysicsresults->GetBinContent(6);
261 double ratio_hadron_bhabha_final = 0.;
262 double ratio_hadronb2_bhabha_final = 0.;
263 double ratio_hadronb2_tight_bhabha_final = 0.;
264 double ratio_mumu_tight_bhabha_final = 0.;
266 if (bhabha_trk_ecl_ntot != 0) {
267 ratio_hadron_bhabha_final = had_ntot / bhabha_trk_ecl_ntot;
268 ratio_hadronb2_bhabha_final = hadb2_ntot / bhabha_trk_ecl_ntot;
269 ratio_hadronb2_tight_bhabha_final = hadb2_tight_ntot / bhabha_trk_ecl_ntot;
270 ratio_mumu_tight_bhabha_final = mumu_tight_ntot / bhabha_trk_ecl_ntot;
272 m_monObj->setVariable(
"ratio_hadron_bhabha_hlt", ratio_hadron_bhabha_final);
273 m_monObj->setVariable(
"ratio_hadronb2_bhabha_hlt", ratio_hadronb2_bhabha_final);
274 m_monObj->setVariable(
"ratio_hadronb2_tight_bhabha_hlt", ratio_hadronb2_tight_bhabha_final);
275 m_monObj->setVariable(
"ratio_mumu_tight_bhabha_hlt", ratio_mumu_tight_bhabha_final);
276 m_monObj->setVariable(
"hadronb2_tight_hlt", hadb2_tight_ntot);
277 m_monObj->setVariable(
"bhabha_trk_ecl_hlt", bhabha_trk_ecl_ntot);
285 B2DEBUG(20,
"DQMHistAnalysisPhysics: terminate called");
static TCanvas * findCanvas(TString cname)
Find canvas by name.
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
static void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static void UpdateCanvas(const std::string &name, bool updated=true)
Mark canvas as updated (or not)
static const std::string & getRunType(void)
Get the list of the reference histograms.
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
DQMHistAnalysisModule()
Constructor / Destructor.
void setEpicsPV(const std::string &keyname, double value)
Write value to a EPICS PV.
void terminate(void) override final
This method is called at the end of the event processing.
TPaveText * m_ratio_text
TPaveText, ratios physics results.
int m_minEntriesUPSee
min entries for Ups(ee)
void initialize(void) override final
Initializer.
TCanvas * m_cmUPSee
Tcanvas for mUPSee.
void endRun(void) override final
End-of-run action.
std::string m_pvPrefix
prefix for EPICS PVs
void fitUpsilonFromHisto(TH1 *histo, TPaveText *text, std::string parts, std::string prefix, std::string pvname)
fit histogram with UPS mass
MonitoringObject * m_monObj
Monitoring Object.
TCanvas * m_cmUPSmumu
Tcanvas for mUPSmumu.
int m_minEntriesUPSmumu
min entries for Ups(mumu)
DQMHistAnalysisPhysicsModule()
Constructor.
TPaveText * m_cmUPSee_text
TPaveText, Ups ee Invariant Mass.
TPaveText * m_cmUPSmumu_text
TPaveText, Ups Invariant Mass (mumu)
void beginRun(void) override final
Called when entering a new run.
void event(void) override final
This method is called for each event.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.