-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CMSInterferenceFunc to use base class CMSExternalMorph
This should make extending external morphs, e.g. to replace RooParametricHist, much simpler.
- Loading branch information
Showing
12 changed files
with
113 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef CMSExternalMorph_h | ||
#define CMSExternalMorph_h | ||
#include <vector> | ||
|
||
#include "RooAbsReal.h" | ||
#include "RooRealVar.h" | ||
#include "RooRealProxy.h" | ||
|
||
class CMSExternalMorph : public RooAbsReal { | ||
public: | ||
CMSExternalMorph(); | ||
/* | ||
* All subclasses need to provide an edges array of length nbins+1 | ||
* of the observable (x) | ||
* TODO: CMSHistFunc and CMSHistSum do not check the binning is compatible | ||
* with their binning other than having the correct length | ||
*/ | ||
CMSExternalMorph( | ||
const char* name, | ||
const char* title, | ||
RooRealVar& x, | ||
const std::vector<double>& edges | ||
); | ||
CMSExternalMorph(CMSExternalMorph const& other, const char* name = 0); | ||
virtual ~CMSExternalMorph(); | ||
|
||
/* Batch accessor for CMSHistFunc / CMSHistSum, to be overriden by concrete | ||
* implementations. hasChanged() should indicate whether or not | ||
* batchGetBinValues() would return a new vector, given the state of | ||
* any dependent variables. | ||
*/ | ||
virtual bool hasChanged() const = 0; | ||
virtual const std::vector<double>& batchGetBinValues() const = 0; | ||
|
||
protected: | ||
RooRealProxy x_; | ||
std::vector<double> edges_; | ||
|
||
double evaluate() const; | ||
|
||
private: | ||
ClassDef(CMSExternalMorph, 1) | ||
}; | ||
|
||
#endif // CMSExternalMorph_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
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
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,33 @@ | ||
#include "../interface/CMSExternalMorph.h" | ||
|
||
CMSExternalMorph::CMSExternalMorph() {} | ||
|
||
CMSExternalMorph::CMSExternalMorph( | ||
const char* name, | ||
const char* title, | ||
RooRealVar& x, | ||
const std::vector<double>& edges | ||
) : | ||
RooAbsReal(name, title), | ||
x_("x", "", this, x), | ||
edges_(edges) | ||
{ | ||
} | ||
|
||
CMSExternalMorph::CMSExternalMorph(CMSExternalMorph const& other, const char* name) : | ||
RooAbsReal(other, name), | ||
x_("x", this, other.x_), | ||
edges_(other.edges_) | ||
{ | ||
} | ||
|
||
CMSExternalMorph::~CMSExternalMorph() = default; | ||
|
||
double CMSExternalMorph::evaluate() const { | ||
auto it = std::upper_bound(std::begin(edges_), std::end(edges_), x_->getVal()); | ||
if ( (it == std::begin(edges_)) or (it == std::end(edges_)) ) { | ||
return 0.0; | ||
} | ||
size_t idx = std::distance(std::begin(edges_), it) - 1; | ||
return batchGetBinValues()[idx]; | ||
} |
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
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
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