45using std::string, std::vector, std::pair, std::map;
72 _rhoList(
"rhoList",
"List of rho parameters",
this), _options(options), _widthFactor(rho),
86 _rhoList(
"rhoList",
"List of rho parameters",
this),
87 _options(options), _widthFactor(rho), _nSigma(
nSigma), _rotate(
rotate),
101 _rhoList(
"rhoList",
"List of rho parameters",
this), _options(options), _widthFactor(-1.0),
108 coutE(InputArguments)
109 <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The vector-size of rho is different from that of varList."
110 <<
"Unable to create the PDF." << std::endl;
132 _rhoList(
"rhoList",
"List of rho parameters",
this), _options(options), _widthFactor(-1.0),
139 for (
unsigned int i=0; i <
rhoList.size(); ++i) {
140 const auto rho =
rhoList.at(i);
142 coutE(InputArguments) <<
"RooNDKeysPdf::ctor(" <<
GetName() <<
") ERROR: parameter " << rho->GetName()
143 <<
" is not of type RooRealVar" << std::endl;
152 coutE(InputArguments) <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The size of rhoList is different from varList."
153 <<
"Unable to create the PDF." << std::endl;
170 _rhoList(
"rhoList",
"List of rho parameters",
this),
179 for (
unsigned int i=0; i <
rhoList.size(); ++i) {
180 const auto rho =
rhoList.at(i);
182 coutE(InputArguments) <<
"RooNDKeysPdf::ctor(" <<
GetName() <<
") ERROR: parameter " << rho->GetName()
183 <<
" is not of type RooRealVar" << std::endl;
191 coutE(InputArguments) <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The size of rhoList is different from varList."
192 <<
"Unable to create the PDF." << std::endl;
209 _rhoList(
"rhoList",
"List of rho parameters",
this), _options(
"a"), _widthFactor(rho),
216 coutW(InputArguments) <<
"RooNDKeysPdf::RooNDKeysPdf() : Warning : asymmetric mirror(s) no longer supported."
232 _rhoList(
"rhoList",
"List of rho parameters",
this), _options(options), _widthFactor(rho),
245 _varList(
"varList",
this,
other._varList),
246 _rhoList(
"rhoList",
this,
other._rhoList),
247 _options(
other._options),
248 _widthFactor(
other._widthFactor),
249 _nSigma(
other._nSigma),
250 _fixedShape(
other._fixedShape),
251 _mirror(
other._mirror),
252 _debug(
other._debug),
253 _verbose(
other._verbose),
255 _nEvents(
other._nEvents),
256 _nEventsM(
other._nEventsM),
257 _nEventsW(
other._nEventsW),
260 _dataPts(
other._dataPts),
261 _dataPtsR(
other._dataPtsR),
262 _weights0(
other._weights0),
263 _weights1(
other._weights1),
264 _weights(_options.Contains(
"a") ? &_weights1 : &_weights0),
265 _sortTVIdcs(
other._sortTVIdcs),
272 _sigma(
other._sigma),
273 _xDatLo(
other._xDatLo),
274 _xDatHi(
other._xDatHi),
275 _xDatLo3s(
other._xDatLo3s),
276 _xDatHi3s(
other._xDatHi3s),
277 _netFluxZ(
other._netFluxZ),
278 _nEventsBW(
other._nEventsBW),
279 _nEventsBMSW(
other._nEventsBMSW),
280 _xVarLo(
other._xVarLo),
281 _xVarHi(
other._xVarHi),
282 _xVarLoM3s(
other._xVarLoM3s),
283 _xVarLoP3s(
other._xVarLoP3s),
284 _xVarHiM3s(
other._xVarHiM3s),
285 _xVarHiP3s(
other._xVarHiP3s),
286 _bpsIdcs(
other._bpsIdcs),
287 _ibNoSort(
other._ibNoSort),
288 _sIdcs(
other._sIdcs),
289 _bIdcs(
other._bIdcs),
290 _bmsIdcs(
other._bmsIdcs),
291 _rangeBoxInfo(
other._rangeBoxInfo),
292 _fullBoxInfo(
other._fullBoxInfo),
294 _minWeight(
other._minWeight),
295 _maxWeight(
other._maxWeight),
302 _sigmaAvgR(
other._sigmaAvgR),
303 _rotate(
other._rotate),
304 _sortInput(
other._sortInput),
305 _nAdpt(
other._nAdpt),
381 cxcoutD(InputArguments) <<
"RooNDKeysPdf::setOptions() options = " <<
_options
384 <<
"\n\tdebug = " <<
_debug
389 coutW(InputArguments) <<
"RooNDKeysPdf::setOptions() : Warning : nSigma = " <<
_nSigma <<
" < 2.0. "
390 <<
"Calculated normalization could be too large."
417 coutE(InputArguments) <<
"ERROR: RooNDKeysPdf::initialize() : The observable list is empty. "
418 <<
"Unable to begin generating the PDF." << std::endl;
423 coutE(InputArguments) <<
"ERROR: RooNDKeysPdf::initialize() : The input data set is empty. "
424 <<
"Unable to begin generating the PDF." << std::endl;
428 _d =
static_cast<double>(
_nDim);
430 std::vector<double> dummy(
_nDim,0.);
504 std::vector<double>& point =
_dataPts[i];
594 coutI(Contents) <<
"RooNDKeysPdf::loadDataSet(" <<
this <<
")"
595 <<
"\n Number of events in dataset: " <<
_nEvents
596 <<
"\n Weighted number of events in dataset: " <<
_nEventsW << std::endl;
707 coutI(Contents) <<
"RooNDKeysPdf::loadWeightSet(" <<
this <<
") : Number of weighted events : " <<
_wMap.size() << std::endl;
719 bi->netFluxZ =
bi->netFluxZ &&
true;
720 }
else {
bi->netFluxZ =
false; }
743 if (
x[
j]>
bi->xVarLo[
j] &&
x[
j]<
bi->xVarHi[
j]) {
747 if (
x[
j]>
bi->xVarLoM3s[
j] &&
x[
j]<
bi->xVarHiP3s[
j]) {
754 bi->bIdcs.push_back(i);
759 bi->bpsIdcs[i] =
true;
762 if ((
x[
j]>
bi->xVarLoM3s[
j] &&
x[
j]<
bi->xVarLoP3s[
j]) &&
x[
j]<(
bi->xVarLo[
j]+
bi->xVarHi[
j])/2.) {
764 }
else if ((
x[
j]>
bi->xVarHiM3s[
j] &&
x[
j]<
bi->xVarHiP3s[
j]) &&
x[
j]>(
bi->xVarLo[
j]+
bi->xVarHi[
j])/2.) {
770 bi->bmsIdcs.push_back(i);
775 coutI(Contents) <<
"RooNDKeysPdf::calculateShell() : "
776 <<
"\n Events in shell " <<
bi->sIdcs.size()
777 <<
"\n Events in box " <<
bi->bIdcs.size()
778 <<
"\n Events in box and shell " <<
bi->bpsIdcs.size()
790 bi->nEventsBMSW +=
_wMap.at(
bi->bmsIdcs[i]);
796 cxcoutD(Eval) <<
"RooNDKeysPdf::calculatePreNorm() : "
797 <<
"\n nEventsBMSW " <<
bi->nEventsBMSW
798 <<
"\n nEventsBW " <<
bi->nEventsBW
810 for (
unsigned int i = 0; i <
_dataPtsR.size(); ++i) {
820 if (
bi->bpsIdcs.find(i) !=
bi->bpsIdcs.
end()) {
832 return (*a.second)[j] < (*b.second)[j];
838 cxcoutD(Eval) <<
"RooNDKeysPdf::sortDataIndices() : Number of sorted events : " <<
_sortTVIdcs[
j].size() << std::endl;
846 cxcoutD(Eval) <<
"RooNDKeysPdf::calculateBandWidth()" << std::endl;
857 cxcoutD(Eval) <<
"RooNDKeysPdf::calculateBandWidth() Using static bandwidth." << std::endl;
864 weight[
j] =
_n * (*_sigmaR)[
j];
871 cxcoutD(Eval) <<
"RooNDKeysPdf::calculateBandWidth() Using adaptive bandwidth." << std::endl;
873 double sqrt12 = sqrt(12.);
879 std::vector<std::vector<double>> *
weights_prev(
nullptr);
880 std::vector<std::vector<double>> *
weights_new(
nullptr);
923 std::vector<int> indices;
938 for (
const auto& i : indices) {
949 (*_dx)[
j] =
x[
j] - point[
j];
957 double r = (*_dx)[
j];
958 double c = 1. / (2. * weight[
j] * weight[
j]);
962 g *= exp(-
c *
r *
r);
1001 return (*
a.second)[
j] < (*
b.second)[
j];
1014 m.reserve(std::distance(lo,
hi));
1015 for (it=lo; it!=
hi; ++it) {
1016 m.push_back(it->first);
1019 std::sort(
m.begin(),
m.end());
1025 for (it=lo; it!=
hi; ++it) {
1028 if (found !=
ibMapRT.
end() && !(it->first < *found)) {
1029 ibMap.push_back(it->first);
1050 bi->xVarLoM3s.resize(
_nDim,0.);
1051 bi->xVarLoP3s.resize(
_nDim,0.);
1052 bi->xVarHiM3s.resize(
_nDim,0.);
1053 bi->xVarHiP3s.resize(
_nDim,0.);
1055 bi->netFluxZ =
true;
1056 bi->bpsIdcs.clear();
1059 bi->bmsIdcs.clear();
1070 bi->xVarLo[
j] = var->getVal() ;
1071 bi->xVarHi[
j] = var->getVal() ;
1089 _x[
j] = var->getVal(nset);
1121 cxcoutD(Eval) <<
"Calling RooNDKeysPdf::analyticalIntegral(" <<
GetName() <<
") with code " << code
1155 cxcoutD(Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Found new boundaries ... " << (
rangeName?
rangeName:
"<none>") << std::endl;
1169 double norm=
bi->nEventsBW;
1173 cxcoutD(Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Using mirrored normalization : " <<
bi->nEventsBW << std::endl;
1174 return bi->nEventsBW;
1192 if ((
x[
j] >
bi->xVarLoM3s[
j] &&
x[
j] <
bi->xVarLoP3s[
j]) &&
x[
j] < (
bi->xVarLo[
j] +
bi->xVarHi[
j]) / 2.) {
1194 }
else if ((
x[
j] >
bi->xVarHiM3s[
j] &&
x[
j] <
bi->xVarHiP3s[
j]) &&
x[
j] > (
bi->xVarLo[
j] +
bi->xVarHi[
j]) / 2.) {
1199 prob *= (0.5 + std::erf(std::abs(
chi[
j]) / sqrt(2.)) / 2.);
1201 prob *= (0.5 - std::erf(std::abs(
chi[
j]) / sqrt(2.)) / 2.);
1208 cxcoutD(Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Final normalization : " <<
norm <<
" " <<
bi->nEventsBW << std::endl;
1219 std::vector<RooRealVar *>
varVec;
1221 for (
const auto var :
varList) {
1223 coutE(InputArguments) <<
"RooNDKeysPdf::createDatasetFromHist(" <<
GetName() <<
") WARNING: variable "
1224 << var->GetName() <<
" is not of type RooRealVar. Skip." << std::endl;
1232 std::string classname = hist.
ClassName();
1233 if (classname.find(
"TH1") == 0) {
1235 }
else if (classname.find(
"TH2") == 0) {
1237 }
else if (classname.find(
"TH3") == 0) {
1243 coutE(InputArguments) <<
"RooNDKeysPdf::createDatasetFromHist(" <<
GetName()
1244 <<
") ERROR: input histogram dimension not between [1-3]: " <<
histndim << std::endl;
1252 for (
int i = 1; i <= hist.
GetXaxis()->GetNbins(); ++i) {
1258 if (
varVec.size() == 1) {
1263 for (
int j = 1;
j <= hist.
GetYaxis()->GetNbins(); ++
j) {
1267 if (
varVec.size() == 2) {
1272 for (
int k = 1; k <= hist.
GetZaxis()->GetNbins(); ++k) {
1296 cxcoutD(Eval) <<
"RooNDKeysPdf::getWeights() Return evaluated weights." << std::endl;
1316 _rho[
j] = rho->getVal();
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
std::vector< itPair > itVec
std::pair< Int_t, VecTVecDouble::iterator > itPair
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
TMatrixTSym< Double_t > TMatrixDSym
TMatrixT< Double_t > TMatrixD
TVectorT< Double_t > TVectorD
const_iterator begin() const
const_iterator end() const
Storage_t::size_type size() const
bool addTyped(const RooAbsCollection &list, bool silent=false)
Adds elements of a given RooAbsCollection to the container if they match the specified type.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
const RooArgSet * nset() const
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
bool matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Meta object that tracks value changes in a given set of RooAbsArgs by registering itself as value cli...
bool hasChanged(bool clearState)
Returns true if state has changed since last call with clearState=true.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
Container class to hold unbinned data.
Generic N-dimensional implementation of a kernel estimation p.d.f.
std::map< Int_t, bool > _ibNoSort
std::vector< std::vector< double > > _weights0
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
void calculatePreNorm(BoxInfo *bi) const
bi->nEventsBMSW=0.; bi->nEventsBW=0.;
std::vector< double > _xDatHi
std::vector< std::vector< double > > * _weights
void createPdf(bool firstCall, RooDataSet const &data)
evaluation order of constructor.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void loopRange(std::vector< double > &x, std::vector< Int_t > &indices) const
determine closest points to x, to loop over in evaluate()
std::vector< double > _xDatLo
void initialize(RooDataSet const &data)
initialization
std::map< Int_t, double > _wMap
void sortDataIndices(BoxInfo *bi=nullptr)
sort entries, as needed for loopRange()
void loadDataSet(bool firstCall, RooDataSet const &data)
copy the dataset and calculate some useful variables
std::vector< TVectorD > _dataPtsR
std::vector< double > _mean
void calculateShell(BoxInfo *bi) const
determine points in +/- nSigma shell around the box determined by the variable ranges.
void calculateBandWidth()
std::vector< double > _xDatLo3s
std::vector< double > _x1
std::vector< std::vector< double > > _dataPts
std::vector< double > _x0
std::vector< double > _x2
double gauss(std::vector< double > &x, std::vector< std::vector< double > > &weights) const
loop over all closest point to x, as determined by loopRange()
std::vector< double > _rho
void loadWeightSet(RooDataSet const &data)
std::vector< itVec > _sortTVIdcs
Weights to be used. Points either to _weights0 or _weights1.
void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const
std::map< std::pair< std::string, int >, BoxInfo * > _rangeBoxInfo
std::vector< Int_t > _idx
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
std::vector< std::vector< double > > _weights1
std::vector< double > _xDatHi3s
TMatrixD getWeights(const int &k) const
Return evaluated weights.
std::vector< double > _sigma
void mirrorDataSet()
determine mirror dataset.
void setOptions()
set the configuration
RooDataSet * createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const
void checkInitWeights() const
RooChangeTracker * _tracker
Variable that can be changed from the outside.
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
TH1 is the base class of all histogram classes in ROOT.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual TMatrixTBase< Element > & Zero()
Set matrix elements to zero.
void Print(Option_t *name="") const override
Print the matrix as a table of elements.
TMatrixT< Element > & T()
const char * GetName() const override
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
void ToLower()
Change string to lower-case.
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TVectorT< Element > & Zero()
Set vector elements to zero.
void Print(Option_t *option="") const override
Print the vector as a list of elements.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
constexpr Double_t TwoPi()