Skip to content

Commit 43fea07

Browse files
committed
resolve conflict with master
1 parent 1742401 commit 43fea07

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

PWGHF/D2H/Macros/HFInvMassFitter.cxx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <TDatabasePDG.h>
4040
#include <TLine.h>
4141
#include <TPaveText.h>
42+
#include <TRandom3.h>
4243
#include <TString.h>
4344
#include <TStyle.h>
4445
#include <TVirtualPad.h>
@@ -129,12 +130,18 @@ HFInvMassFitter::HFInvMassFitter(TH1* histoToFit,
129130
mIntegralSgn(0),
130131
mHistoTemplateRefl(nullptr),
131132
mDrawBgPrefit(false),
132-
mHighlightPeakRegion(false)
133+
mHighlightPeakRegion(false),
134+
mRandomSeed(-1),
135+
mRandomGen(nullptr)
133136
{
134137
// standard constructor
135138
mHistoInvMass = histoToFit;
136139
mHistoInvMass->SetName("mHistoInvMass");
137140
mHistoInvMass->SetDirectory(nullptr);
141+
if (mRandomSeed >= 0) {
142+
mRandomGen = new TRandom3();
143+
mRandomGen->SetSeed(mRandomSeed);
144+
}
138145
}
139146

140147
HFInvMassFitter::~HFInvMassFitter()
@@ -991,3 +998,27 @@ void HFInvMassFitter::setTemplateReflections(TH1* histoRefl)
991998
mHistoTemplateRefl = histoRefl;
992999
mHistoTemplateRefl->SetName("mHistoTemplateRefl");
9931000
}
1001+
1002+
double HFInvMassFitter::randomizeInitialParameter(const ParameterRanges& parameterRanges)
1003+
{
1004+
constexpr double DefaultSigmaFraction{10.};
1005+
constexpr int MaximalNumberOfIterations{20};
1006+
1007+
if (mRandomSeed < 0) {
1008+
return parameterRanges.initial;
1009+
}
1010+
const auto sigma = parameterRanges.sigma < 0 ? (parameterRanges.upper - parameterRanges.lower) / DefaultSigmaFraction : parameterRanges.sigma;
1011+
1012+
double result;
1013+
int nIter{0};
1014+
do {
1015+
result = mRandomGen->Gaus(parameterRanges.initial, sigma);
1016+
++nIter;
1017+
if (nIter > MaximalNumberOfIterations) {
1018+
printf("randomizeInitialFitParameter() - long while loop with lower = %f upper = %f initial = %f sigma = %f\n", parameterRanges.lower, parameterRanges.upper, parameterRanges.initial, sigma);
1019+
throw std::runtime_error("");
1020+
}
1021+
} while (result < parameterRanges.lower || result > parameterRanges.upper);
1022+
1023+
return result;
1024+
}

PWGHF/D2H/Macros/HFInvMassFitter.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <TF1.h>
2929
#include <TH1.h>
3030
#include <TNamed.h>
31+
#include <TRandom3.h>
3132
#include <TVirtualPad.h>
3233

3334
#include <Rtypes.h>
@@ -39,6 +40,14 @@
3940

4041
class HFInvMassFitter : public TNamed
4142
{
43+
private:
44+
struct ParameterRanges {
45+
double lower{};
46+
double upper{};
47+
double initial{};
48+
double sigma{-999.};
49+
};
50+
4251
public:
4352
enum TypeOfBkgPdf {
4453
Expo = 0,
@@ -141,6 +150,7 @@ class HFInvMassFitter : public TNamed
141150
HFInvMassFitter& operator=(const HFInvMassFitter& source);
142151
void fillWorkspace(RooWorkspace& w) const;
143152
void highlightPeakRegion(const RooPlot* plot, Color_t color = kGray + 1, Width_t width = 1, Style_t style = 2) const;
153+
double randomizeInitialParameter(const ParameterRanges& parameterRanges);
144154

145155
TH1* mHistoInvMass; // histogram to fit
146156
std::string mFitOption;
@@ -212,6 +222,8 @@ class HFInvMassFitter : public TNamed
212222
TH1* mHistoTemplateRefl; /// reflection histogram
213223
bool mDrawBgPrefit; /// draw background after fitting the sidebands
214224
bool mHighlightPeakRegion; /// draw vertical lines showing the peak region (usually +- 3 sigma)
225+
int mRandomSeed; /// seed for random engine for fit's initial parameters randomization
226+
TRandom3* mRandomGen; /// engine for fit's initial parameters randomization
215227

216228
ClassDefOverride(HFInvMassFitter, 1);
217229
};

0 commit comments

Comments
 (0)