Skip to content

Commit

Permalink
add protection for empty input histogram in the fitting function
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Aug 24, 2022
1 parent c5d5f23 commit e03333c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion DQMOffline/Alignment/interface/DiMuonMassBiasClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ namespace diMuonMassBias {
assert(v.size() == 3);
std::copy(std::begin(v), std::end(v), x);
}

static constexpr int minimumHits = 10;

} // namespace diMuonMassBias

class DiMuonMassBiasClient : public DQMEDHarvester {
Expand Down Expand Up @@ -83,7 +86,7 @@ class DiMuonMassBiasClient : public DQMEDHarvester {

float meanConfig_[3]; /* parmaeters for the fit: mean */
float widthConfig_[3]; /* parameters for the fit: width */
float sigmaConfig_[3]; /* parmaeters for the fit: sigma */
float sigmaConfig_[3]; /* parameters for the fit: sigma */

// list of histograms to harvest
std::vector<std::string> MEtoHarvest_;
Expand Down
14 changes: 11 additions & 3 deletions DQMOffline/Alignment/src/DiMuonMassBiasClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ void DiMuonMassBiasClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGett
diMuonMassBias::fitOutputs DiMuonMassBiasClient::fitVoigt(TH1* hist, const bool& fitBackground) const
//-----------------------------------------------------------------------------------
{
if (hist->GetEntries() < diMuonMassBias::minimumHits) {
edm::LogWarning("DiMuonMassBiasClient") << " Input histogram:" << hist->GetName() << " has not enough entries ("
<< hist->GetEntries() << ") for a meaningful Voigtian fit!\n"
<< "Skipping!";

return diMuonMassBias::fitOutputs(Measurement1D(0., 0.), Measurement1D(0., 0.));
}

TCanvas* c1 = new TCanvas();
if (debugMode_) {
c1->Clear();
Expand All @@ -168,9 +176,9 @@ diMuonMassBias::fitOutputs DiMuonMassBiasClient::fitVoigt(TH1* hist, const bool&
RooDataHist datahist("datahist", "datahist", InvMass, RooFit::Import(*hist));
datahist.plotOn(frame);

RooRealVar mean("#mu", "mean", meanConfig_[0], meanConfig_[1], meanConfig_[2]); //90.0, 60.0, 120.0
RooRealVar width("width", "width", widthConfig_[0], widthConfig_[1], widthConfig_[2]); // 5.0, 0.0, 120.0
RooRealVar sigma("#sigma", "sigma", sigmaConfig_[0], sigmaConfig_[1], sigmaConfig_[2]); // 5.0, 0.0, 120.0
RooRealVar mean("#mu", "mean", meanConfig_[0], meanConfig_[1], meanConfig_[2]); //90.0, 60.0, 120.0 (for Z)
RooRealVar width("width", "width", widthConfig_[0], widthConfig_[1], widthConfig_[2]); // 5.0, 0.0, 120.0 (for Z)
RooRealVar sigma("#sigma", "sigma", sigmaConfig_[0], sigmaConfig_[1], sigmaConfig_[2]); // 5.0, 0.0, 120.0 (for Z)
RooVoigtian voigt("voigt", "voigt", InvMass, mean, width, sigma);

RooRealVar lambda("#lambda", "slope", -0.01, -100., 1.);
Expand Down

0 comments on commit e03333c

Please sign in to comment.