forked from desy-cms/analysis-backgroundmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom Double-Crystal-Ball pdf.
- added the required files to allow storage in a ROOT file - created workspace is now stored in ROOT file - fit with this function is not yet properly converging
- Loading branch information
1 parent
c3d69d5
commit 1d79bf4
Showing
7 changed files
with
250 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef Analysis_BackgroundModel_RooDoubleCB_h | ||
#define Analysis_BackgroundModel_RooDoubleCB_h 1 | ||
|
||
#include "RooAbsPdf.h" | ||
#include "RooRealProxy.h" | ||
#include "RooAbsReal.h" | ||
|
||
namespace analysis { | ||
namespace backgroundmodel { | ||
|
||
class RooDoubleCB : public RooAbsPdf { | ||
public: | ||
inline RooDoubleCB() {}; | ||
RooDoubleCB(const char* name, const char* title, | ||
RooAbsReal& x, | ||
RooAbsReal& mean, | ||
RooAbsReal& width, | ||
RooAbsReal& alpha1, | ||
RooAbsReal& n1, | ||
RooAbsReal& alpha2, | ||
RooAbsReal& n2 | ||
); | ||
RooDoubleCB(const RooDoubleCB& other, const char* name = 0) ; | ||
virtual TObject* clone(const char* newname) const; | ||
inline virtual ~RooDoubleCB() {}; | ||
int getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, | ||
const char* name = 0) const; | ||
double analyticalIntegral(int code, const char* rangeName = 0) const; | ||
|
||
protected: | ||
double evaluate() const; | ||
|
||
RooRealProxy x_; | ||
RooRealProxy mean_; | ||
RooRealProxy width_; | ||
RooRealProxy alpha1_; | ||
RooRealProxy n1_; | ||
RooRealProxy alpha2_; | ||
RooRealProxy n2_; | ||
|
||
ClassDef(RooDoubleCB,1); | ||
}; | ||
|
||
} | ||
} | ||
|
||
#endif // Analysis_BackgroundModel_RooDoubleCB_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include "TMath.h" | ||
|
||
#include "RooRealVar.h" | ||
#include "RooRealConstant.h" | ||
#include "Analysis/BackgroundModel/interface/RooDoubleCB.h" | ||
|
||
|
||
using namespace analysis::backgroundmodel; | ||
|
||
|
||
ClassImp(RooDoubleCB) | ||
|
||
|
||
RooDoubleCB::RooDoubleCB(const char* name, const char* title, | ||
RooAbsReal& x, | ||
RooAbsReal& mean, | ||
RooAbsReal& width, | ||
RooAbsReal& alpha1, | ||
RooAbsReal& n1, | ||
RooAbsReal& alpha2, | ||
RooAbsReal& n2 | ||
) : | ||
RooAbsPdf(name, title), | ||
x_("x", "x", this, x), | ||
mean_("mean", "mean", this, mean), | ||
width_("width", "width", this, width), | ||
alpha1_("alpha1", "alpha1", this, alpha1), | ||
n1_("n1", "n1", this, n1), | ||
alpha2_("alpha2", "alpha2", this, alpha2), | ||
n2_("n2", "n2", this, n2) { | ||
} | ||
|
||
|
||
RooDoubleCB::RooDoubleCB(const RooDoubleCB& other, const char* name) : | ||
RooAbsPdf(other, name), | ||
x_("x", this, other.x_), | ||
mean_("mean", this, other.mean_), | ||
width_("width", this, other.width_), | ||
alpha1_("alpha1", this, other.alpha1_), | ||
n1_("n1", this, other.n1_), | ||
alpha2_("alpha2", this, other.alpha2_), | ||
n2_("n2", this, other.n2_) { | ||
} | ||
|
||
|
||
TObject* RooDoubleCB::clone(const char* newname) const { | ||
return new RooDoubleCB(*this, newname); | ||
} | ||
|
||
|
||
double RooDoubleCB::evaluate() const { | ||
double t = (x_ - mean_)/width_; | ||
if (t > -alpha1_ && t < alpha2_) { | ||
return std::exp(-0.5*t*t); | ||
} else if (t < -alpha1_) { | ||
double A1 = std::pow(n1_/fabs(alpha1_), n1_) * std::exp(-alpha1_*alpha1_/2); | ||
double B1 = n1_/std::fabs(alpha1_) - std::fabs(alpha1_); | ||
return A1 * std::pow(B1-t, -n1_); | ||
} else if (t > alpha2_) { | ||
double A2 = std::pow(n2_/fabs(alpha2_), n2_) * std::exp(-alpha2_*alpha2_/2); | ||
double B2 = n2_/std::fabs(alpha2_)-std::fabs(alpha2_); | ||
return A2 * std::pow(B2+t, -n2_); | ||
} else { | ||
std::cerr << "ERROR evaluating range..." << std::endl; | ||
return 99; | ||
} | ||
} | ||
|
||
|
||
int RooDoubleCB::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, | ||
const char* range) const { | ||
if (matchArgs(allVars, analVars, x_)) return 1; | ||
return 0; | ||
} | ||
|
||
|
||
double RooDoubleCB::analyticalIntegral(int code, | ||
const char* rangeName) const { | ||
assert(code == 1) ; | ||
|
||
double central = 0; | ||
double left = 0; | ||
double right = 0; | ||
|
||
static const double root2 = std::sqrt(2) ; | ||
static const double rootPiBy2 = std::sqrt(std::atan2(0.0, -1.0) / 2.0); | ||
double xscale = root2 * width_; | ||
|
||
//compute gaussian contribution | ||
double centralLow = std::max(x_.min(rangeName), mean_ - alpha1_ * width_); | ||
double centralHigh = std::min(x_.max(rangeName), mean_ + alpha2_ * width_); | ||
if (centralLow < centralHigh) // is the gaussian part in range? | ||
central = rootPiBy2 * width_ * (TMath::Erf((centralHigh - mean_)/xscale) - | ||
TMath::Erf((centralLow - mean_)/xscale)); | ||
|
||
//compute left tail; | ||
double A1 = (std::pow(n1_/std::fabs(alpha1_), n1_) * | ||
std::exp(-alpha1_*alpha1_/2)); | ||
double B1 = n1_/std::fabs(alpha1_) - std::fabs(alpha1_); | ||
|
||
double leftLow = x_.min(rangeName); | ||
double leftHigh = std::min(x_.max(rangeName), mean_ - alpha1_*width_); | ||
if (leftLow < leftHigh) { //is the left tail in range? | ||
if (std::fabs(n1_ - 1.0) > 1.e-5) | ||
left = A1/(-n1_+1.0) * width_ * | ||
(std::pow(B1-(leftLow-mean_)/width_,-n1_+1.) - | ||
std::pow(B1-(leftHigh-mean_)/width_,-n1_+1.)); | ||
else | ||
left = A1 * width_ * (std::log(B1-(leftLow-mean_)/width_) - | ||
std::log(B1-(leftHigh-mean_)/width_)); | ||
} | ||
|
||
//compute right tail; | ||
double A2 = (std::pow(n2_/std::fabs(alpha2_), n2_) * | ||
std::exp(-alpha2_*alpha2_/2)); | ||
double B2 = n2_/std::fabs(alpha2_) - std::fabs(alpha2_); | ||
|
||
double rightLow = std::max(x_.min(rangeName), mean_ + alpha2_*width_); | ||
double rightHigh = x_.max(rangeName); | ||
if (rightLow < rightHigh) { //is the right tail in range? | ||
if (std::fabs(n2_-1.0)>1.e-5) | ||
right = A2/(-n2_+1.0) * width_ * | ||
(std::pow(B2+(rightHigh-mean_)/width_, -n2_+1.) - | ||
std::pow(B2 + (rightLow-mean_)/width_, -n2_+1.)); | ||
else | ||
right = A2 * width_ * (std::log(B2+(rightHigh-mean_)/width_) - | ||
std::log(B2+(rightLow-mean_)/width_)); | ||
} | ||
|
||
return left + central + right; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "Analysis/BackgroundModel/interface/RooDoubleCB.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<lcgdict> | ||
<class name="analysis::backgroundmodel::RooDoubleCB" /> | ||
</lcgdict> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
plots | ||
workspace |