49 x(
"x",
"x dimension",this, xx),
50 y(
"y",
"y dimension",this, yy)
64 x(
"x", this, other.
x),
67 if(
_verbosedebug) { std::cout <<
"Roo2DKeysPdf::Roo2DKeysPdf copy ctor" << std::endl; }
102 _x[iEvt] = other.
_x[iEvt];
103 _y[iEvt] = other.
_y[iEvt];
104 _hx[iEvt] = other.
_hx[iEvt];
105 _hy[iEvt] = other.
_hy[iEvt];
114 if(
_verbosedebug) { std::cout <<
"Roo2DKeysPdf::Roo2KeysPdf dtor" << std::endl; }
130 if(
_verbosedebug) { std::cout <<
"Roo2DKeysPdf::loadDataSet" << std::endl; }
134 if(
_verbosedebug) { std::cout <<
"Roo2DKeysPdf::loadDataSet(RooDataSet& data, TString options)" << std::endl; }
141 std::cout <<
"ERROR: Roo2DKeysPdf::loadDataSet The input data set is empty. Unable to begin generating the PDF" << std::endl;
169 std::cout <<
"Roo2DKeysPdf::Roo2DKeysPdf invalid RooAbsReal name: "<<xx.
GetName()<<
" not in the data set" << std::endl;
174 std::cout <<
"Roo2DKeysPdf::Roo2DKeysPdf invalid RooAbsReal name: "<<yy.
GetName()<<
" not in the data set" << std::endl;
179 std::cout <<
"Roo2DKeysPdf::Roo2DKeysPdf Unable to initialize object; incompatible RooDataSet doesn't contain"<< std::endl;
180 std::cout <<
" all of the RooAbsReal arguments"<< std::endl;
193 _x[j] =
X->getVal() ;
194 _y[j] = Y->getVal() ;
205 std::cout <<
"Roo2DKeysPdf::Roo2DKeysPdf Empty data set was used; can't generate a PDF"<< std::endl;
225 if(
_verbosedebug) { std::cout <<
"Roo2DKeysPdf::setOptions" << std::endl; }
247 std::cout <<
"Roo2DKeysPdf::setOptions(TString options) options = "<< options << std::endl;
248 std::cout <<
"\t_BandWidthType = " <<
_BandWidthType << std::endl;
250 std::cout <<
"\t_debug = " <<
_debug << std::endl;
251 std::cout <<
"\t_verbosedebug = " <<
_verbosedebug << std::endl;
252 std::cout <<
"\t_vverbosedebug = " <<
_vverbosedebug << std::endl;
261 std::cout <<
"Roo2DKeysPdf::getOptions(void)" << std::endl;
262 std::cout <<
"\t_BandWidthType = " <<
_BandWidthType << std::endl;
264 std::cout <<
"\t_debug = " <<
_debug << std::endl;
265 std::cout <<
"\t_verbosedebug = " <<
_verbosedebug << std::endl;
266 std::cout <<
"\t_vverbosedebug = " <<
_vverbosedebug << std::endl;
276 if(
_verbosedebug) { std::cout <<
"Roo2DKeysPdf::calculateBandWidth(Int_t kernel)" << std::endl; }
285 double sqrtSum = sqrt( sigSum );
287 if(sigProd != 0.0)
h =
_n16*sqrt( sigSum/sigProd );
290 std::cout <<
"Roo2DKeysPdf::calculateBandWidth The sqr(variance sum) == 0.0. " <<
" Your dataset represents a delta function."<< std::endl;
296 double xhmin = hXSigma * sqrt(2.)/10;
297 double yhmin = hYSigma * sqrt(2.)/10;
304 std::cout <<
"Roo2DKeysPdf::calculateBandWidth Using a normal bandwidth (same for a given dimension) based on"<< std::endl;
305 std::cout <<
" h_j = n^{-1/6}*sigma_j for the j^th dimension and n events * "<<
_widthScaleFactor<< std::endl;
312 if(
_hx[j]<xhmin)
_hx[j] = xhmin;
313 if(
_hy[j]<yhmin)
_hy[j] = yhmin;
318 std::cout <<
"Roo2DKeysPdf::calculateBandWidth Using an adaptive bandwidth (in general different for all events) [default]"<< std::endl;
324 double f_ti = std::pow(
g(
_x[j],
_x, hXSigma,
_y[j],
_y, hYSigma), -0.25 ) ;
325 _hx[j] = xnorm * f_ti;
326 _hy[j] = ynorm * f_ti;
327 if(
_hx[j]<xhmin)
_hx[j] = xhmin;
328 if(
_hy[j]<yhmin)
_hy[j] = yhmin;
345 if(
_vverbosedebug) { std::cout <<
"Roo2DKeysPdf::evaluate()" << std::endl; }
361 if(
_vverbosedebug ) { std::cout <<
"Roo2DKeysPdf::evaluateFull()" << std::endl; }
373 rx2 = 0.0; ry2 = 0.0; zx = 0.0; zy = 0.0;
374 if(
_hx[j] != 0.0) rx2 = (thisX -
_x[j])/
_hx[j];
375 if(
_hy[j] != 0.0) ry2 = (thisY -
_y[j])/
_hy[j];
377 if(
_hx[j] != 0.0) zx = exp(-0.5*rx2*rx2)/
_hx[j];
378 if(
_hy[j] != 0.0) zy = exp(-0.5*ry2*ry2)/
_hy[j];
392 rx2 = 0.0; ry2 = 0.0; zx = 0.0; zy = 0.0;
393 if(
_hx[j] != 0.0) rx2 = (thisX -
_x[j])/
_hx[j];
394 if(
_hy[j] != 0.0) ry2 = (thisY -
_y[j])/
_hy[j];
396 if(
_hx[j] != 0.0) zx = exp(-0.5*rx2*rx2)/
_hx[j];
397 if(
_hy[j] != 0.0) zy = exp(-0.5*ry2*ry2)/
_hy[j];
417 if(
_vverbosedebug) { std::cout <<
"Roo2DKeysPdf::highBoundaryCorrection" << std::endl; }
419 if(thisH == 0.0)
return 0.0;
420 double correction = (thisVar + tVar - 2.0* high )/thisH;
421 return exp(-0.5*correction*correction)/thisH;
429 if(
_vverbosedebug) { std::cout <<
"Roo2DKeysPdf::lowBoundaryCorrection" << std::endl; }
431 if(thisH == 0.0)
return 0.0;
432 double correction = (thisVar + tVar - 2.0* low )/thisH;
433 return exp(-0.5*correction*correction)/thisH;
447double Roo2DKeysPdf::g(
double varMean1,
double * _var1,
double sigma1,
double varMean2,
double * _var2,
double sigma2)
const
449 if((
_nEvents == 0.0) || (sigma1 == 0.0) || (sigma2 == 0))
return 0.0;
451 double c1 = -1.0/(2.0*sigma1*sigma1);
452 double c2 = -1.0/(2.0*sigma2*sigma2);
458 double r1 = _var1[i] - varMean1;
459 double r2 = _var2[i] - varMean2;
460 z += exp(
c1 * r1*r1 ) * exp(
c2 * r2*r2 );
471 if(
_BandWidthType == 1) std::cout <<
"The Bandwidth Type selected is Trivial" << std::endl;
472 else std::cout <<
"The Bandwidth Type selected is Adaptive" << std::endl;
482 if(!strcmp(axis,
x.
GetName()) || !strcmp(axis,
"x") || !strcmp(axis,
"X"))
return _xMean;
483 else if(!strcmp(axis,
y.
GetName()) || !strcmp(axis,
"y") || !strcmp(axis,
"Y"))
return _yMean;
486 std::cout <<
"Roo2DKeysPdf::getMean unknown axis "<<axis<< std::endl;
496 if(!strcmp(axis,
x.
GetName()) || !strcmp(axis,
"x") || !strcmp(axis,
"X"))
return _xSigma;
497 else if(!strcmp(axis,
y.
GetName()) || !strcmp(axis,
"y") || !strcmp(axis,
"Y"))
return _ySigma;
500 std::cout <<
"Roo2DKeysPdf::getSigma unknown axis "<<axis<< std::endl;
528 std::cout <<
"Roo2DKeysPdf::writeHistToFile This member function is temporarily disabled" << std::endl;
530 std::unique_ptr<TFile> file{
TFile::Open(outputFile,
"UPDATE")};
533 std::cout <<
"Roo2DKeysPdf::writeHistToFile unable to open file "<< outputFile << std::endl;
562 TFile * file =
nullptr;
565 file =
new TFile(outputFile,
"UPDATE");
568 std::cout <<
"Roo2DKeysPdf::writeNTupleToFile unable to open file "<< outputFile << std::endl;
578 label +=
" the source data for 2D Keys PDF";
580 if(!_theTree) { std::cout <<
"Unable to get a TTree for output" << std::endl;
return; }
584 const char * xname = xArg.
GetName();
585 const char * yname = yArg.
GetName();
586 if (!strcmp(xname,
"")) xname =
"x";
587 if (!strcmp(yname,
"")) yname =
"y";
589 _theTree->
Branch(xname, &theX,
" x/D");
590 _theTree->
Branch(yname, &theY,
" y/D");
591 _theTree->
Branch(
"hx", &hx,
" hx/D");
592 _theTree->
Branch(
"hy", &hx,
" hy/D");
613 out <<
"Roo2DKeysPDF instance domain information:"<< std::endl;
614 out <<
"\tX_min = " <<
_lox << std::endl;
615 out <<
"\tX_max = " <<
_hix << std::endl;
616 out <<
"\tY_min = " <<
_loy << std::endl;
617 out <<
"\tY_max = " <<
_hiy << std::endl;
619 out <<
"Data information:" << std::endl;
620 out <<
"\t<x> = " <<
_xMean << std::endl;
621 out <<
"\tsigma(x) = " <<
_xSigma << std::endl;
622 out <<
"\t<y> = " <<
_yMean << std::endl;
623 out <<
"\tsigma(y) = " <<
_ySigma << std::endl;
625 out <<
"END of info for Roo2DKeys pdf instance"<< std::endl;
int Int_t
Signed integer 4 bytes (int)
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 x1
Option_t Option_t TPoint TPoint const char y1
Two-dimensional kernel estimation PDF.
double getMean(const char *axis) const
Roo2DKeysPdf(const char *name, const char *title, RooAbsReal &xx, RooAbsReal &yy, RooDataSet &data, TString options="a", double widthScaleFactor=1.0)
Constructor.
void writeNTupleToFile(char *outputFile, const char *name) const
Saves the data and calculated bandwidths to a file, as a record of what produced the PDF and to give ...
void writeToFile(char *outputFile, const char *name) const
double lowBoundaryCorrection(double thisVar, double thisH, double low, double tVar) const
double evaluate() const override
Evaluates the kernel estimation for x,y, interpolating between the points if necessary.
Int_t getBandWidthType() const
void PrintInfo(std::ostream &) const
Prints out _p[_nPoints][_nPoints] indicating the domain limits.
Int_t loadDataSet(RooDataSet &data, TString options)
Loads a new data set into the class instance.
double g(double varMean1, double *_var1, double sigma1, double varMean2, double *_var2, double sigma2) const
Calculates f(t_i) for the bandwidths.
double getSigma(const char *axis) const
~Roo2DKeysPdf() override
Destructor.
void setWidthScaleFactor(double widthScaleFactor)
double highBoundaryCorrection(double thisVar, double thisH, double high, double tVar) const
Apply the mirror at boundary correction to a dimension given the space position to evaluate at (thisV...
void writeHistToFile(char *outputFile, const char *histName) const
Plots the PDF as a histogram and saves it to a file, so that it can be loaded in as a Roo2DHist PDF i...
Int_t calculateBandWidth(Int_t kernel=-999)
Calculates the kernel bandwidth for x & y and the probability look up table _p[i][j].
void setOptions(TString options)
void getOptions(void) const
double evaluateFull(double thisX, double thisY) const
Evaluates the sum of the product of the 2D kernels for use in calculating the fixed kernel estimate,...
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
TH1 * createHistogram(const char *name, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Abstract base class for objects that represent a real value and implements functionality common to al...
TH1 * fillHistogram(TH1 *hist, const RooArgList &plotVars, double scaleFactor=1, const RooArgSet *projectedVars=nullptr, bool scaleForDensity=true, const RooArgSet *condObs=nullptr, bool setError=true) const
Fill the ROOT histogram 'hist' with values sampled from this function at the bin centers.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Container class to hold unbinned data.
Variable that can be changed from the outside.
double max(const char *rname=nullptr) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
const T & arg() const
Return reference to object held in proxy.
double min(const char *rname=nullptr) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write memory objects to this file.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void Close(Option_t *option="") override
Close a file.
void SetName(const char *name) override
Change the name of this histogram.
2-D histogram with a float per channel (see TH1 documentation)
const char * GetName() const override
Returns name of object.
void ToLower()
Change string to lower-case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
virtual void SetAutoSave(Long64_t autos=-300000000)
In case of a program crash, it will be possible to recover the data in the tree up to the last AutoSa...
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.