|
39 | 39 | #include <TDatabasePDG.h> |
40 | 40 | #include <TLine.h> |
41 | 41 | #include <TPaveText.h> |
| 42 | +#include <TRandom3.h> |
42 | 43 | #include <TString.h> |
43 | 44 | #include <TStyle.h> |
44 | 45 | #include <TVirtualPad.h> |
@@ -129,12 +130,18 @@ HFInvMassFitter::HFInvMassFitter(TH1* histoToFit, |
129 | 130 | mIntegralSgn(0), |
130 | 131 | mHistoTemplateRefl(nullptr), |
131 | 132 | mDrawBgPrefit(false), |
132 | | - mHighlightPeakRegion(false) |
| 133 | + mHighlightPeakRegion(false), |
| 134 | + mRandomSeed(-1), |
| 135 | + mRandomGen(nullptr) |
133 | 136 | { |
134 | 137 | // standard constructor |
135 | 138 | mHistoInvMass = histoToFit; |
136 | 139 | mHistoInvMass->SetName("mHistoInvMass"); |
137 | 140 | mHistoInvMass->SetDirectory(nullptr); |
| 141 | + if (mRandomSeed >= 0) { |
| 142 | + mRandomGen = new TRandom3(); |
| 143 | + mRandomGen->SetSeed(mRandomSeed); |
| 144 | + } |
138 | 145 | } |
139 | 146 |
|
140 | 147 | HFInvMassFitter::~HFInvMassFitter() |
@@ -991,3 +998,27 @@ void HFInvMassFitter::setTemplateReflections(TH1* histoRefl) |
991 | 998 | mHistoTemplateRefl = histoRefl; |
992 | 999 | mHistoTemplateRefl->SetName("mHistoTemplateRefl"); |
993 | 1000 | } |
| 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 | +} |
0 commit comments