40 #ifndef RooStats_NumberCountingPdfFactory
44 #ifndef RooStats_RooStatsUtils
67 using namespace RooStats;
68 using namespace RooFit;
89 const char* pdfName,
const char* muName) {
97 using namespace RooFit;
100 TList likelihoodFactors;
105 new RooRealVar(muName,
"masterSignal",1., 0., 3.);
111 std::stringstream str;
114 new RooRealVar((
"expected_s"+str.str()).c_str(),(
"expected_s"+str.str()).c_str(),sig[i], 0., 2*sig[i]);
118 new RooProduct((
"s"+str.str()).c_str(),(
"s"+str.str()).c_str(),
RooArgSet(*masterSignal, *expectedSignal));
121 new RooRealVar((
"b"+str.str()).c_str(),(
"b"+str.str()).c_str(), .5, 0.,1.);
123 new RooRealVar((
"tau"+str.str()).c_str(),(
"tau"+str.str()).c_str(), .5, 0., 1.);
127 new RooAddition((
"splusb"+str.str()).c_str(),(
"s"+str.str()+
"+"+
"b"+str.str()).c_str(),
130 new RooProduct((
"bTau"+str.str()).c_str(),(
"b*tau"+str.str()).c_str(),
RooArgSet(*b, *tau));
132 new RooRealVar((
"x"+str.str()).c_str(),(
"x"+str.str()).c_str(), 0.5 , 0., 1.);
134 new RooRealVar((
"y"+str.str()).c_str(),(
"y"+str.str()).c_str(), 0.5, 0., 1.);
138 new RooPoisson((
"sigRegion"+str.str()).c_str(),(
"sigRegion"+str.str()).c_str(), *
x,*splusb);
142 new RooPoisson((
"sideband"+str.str()).c_str(),(
"sideband"+str.str()).c_str(), *
y,*bTau,
true);
144 likelihoodFactors.Add(sigRegion);
145 likelihoodFactors.Add(sideband);
149 RooArgSet likelihoodFactorSet(likelihoodFactors);
150 RooProdPdf joint(pdfName,
"joint", likelihoodFactorSet );
171 std::vector<Double_t> mainMeas(nbins);
175 mainMeas[i] = sig[i] + back[i];
177 return AddData(&mainMeas[0], back, back_syst, nbins, ws, dsName);
190 std::vector<Double_t> mainMeas(nbins);
191 std::vector<Double_t> sideband(nbins);
193 mainMeas[i] = sigExp[i] + backExp[i];
194 sideband[i] = backExp[i]*tau[i];
196 return AddDataWithSideband(&mainMeas[0], &sideband[0], tau, nbins, ws, dsName);
205 return SafeObservableCreation(ws, varName, value, 10.*value);
217 x =
new RooRealVar(varName, varName, value, 0, maximum );
236 using namespace RooFit;
241 TList observablesCollection;
244 std::vector<Double_t> xForTree(nbins);
245 std::vector<Double_t> yForTree(nbins);
249 std::stringstream str;
255 Double_t _tau = (1.0 +
sqrt(1 + 4 * err * err))/ (2. * err * err)/ back[i];
257 RooRealVar* tau = SafeObservableCreation(ws, (
"tau"+str.str()).c_str(), _tau );
260 " to be consistent with background and its uncertainty. " <<
261 " Also stored these values of tau into workspace with name . " << (string(tau->
GetName())+
string(dsName)).c_str() <<
262 " if you test with a different dataset, you should adjust tau appropriately.\n"<< endl;
268 RooRealVar*
x = SafeObservableCreation(ws, (
"x"+str.str()).c_str(), mainMeas[i]);
271 RooRealVar*
y = SafeObservableCreation(ws, (
"y"+str.str()).c_str(), back[i]*_tau );
273 observablesCollection.Add(x);
274 observablesCollection.Add(y);
276 xForTree[i] = mainMeas[i];
277 yForTree[i] = back[i]*_tau;
279 tree->Branch((
"x"+str.str()).c_str(), &xForTree[i] ,(
"x"+str.str()+
"/D").c_str());
280 tree->Branch((
"y"+str.str()).c_str(), &yForTree[i] ,(
"y"+str.str()+
"/D").c_str());
282 ws->
var((
"b"+str.str()).c_str())->setMax( 1.2*back[i]+MaxSigma*(
sqrt(back[i])+back[i]*back_syst[i]) );
283 ws->
var((
"b"+str.str()).c_str())->setVal( back[i] );
316 using namespace RooFit;
321 TList observablesCollection;
325 std::vector<Double_t> xForTree(nbins);
326 std::vector<Double_t> yForTree(nbins);
331 std::stringstream str;
339 RooRealVar* tau = SafeObservableCreation(ws, (
"tau"+str.str()).c_str(), _tau );
342 " to be consistent with background and its uncertainty. " <<
343 " Also stored these values of tau into workspace with name . " << (string(tau->
GetName())+
string(dsName)).c_str() <<
344 " if you test with a different dataset, you should adjust tau appropriately.\n"<< endl;
350 RooRealVar*
x = SafeObservableCreation(ws, (
"x"+str.str()).c_str(), mainMeas[i]);
353 RooRealVar*
y = SafeObservableCreation(ws, (
"y"+str.str()).c_str(), sideband[i] );
356 observablesCollection.Add(x);
357 observablesCollection.Add(y);
359 xForTree[i] = mainMeas[i];
360 yForTree[i] = sideband[i];
362 tree->Branch((
"x"+str.str()).c_str(), &xForTree[i] ,(
"x"+str.str()+
"/D").c_str());
363 tree->Branch((
"y"+str.str()).c_str(), &yForTree[i] ,(
"y"+str.str()+
"/D").c_str());
365 ws->
var((
"b"+str.str()).c_str())->setMax( 1.2*back+MaxSigma*(
sqrt(back)+back*back_syst) );
366 ws->
var((
"b"+str.str()).c_str())->setVal( back );
RooProdPdf is an efficient implementation of a product of PDFs of the form.
static RooMsgService & instance()
Return reference to singleton instance.
void AddExpData(Double_t *sigExp, Double_t *bkgExp, Double_t *db, Int_t nbins, RooWorkspace *ws, const char *dsName="ExpectedNumberCountingData")
void setMax(const char *name, Double_t value)
Set maximum of name range to given value.
ClassImp(RooStats::NumberCountingPdfFactory)
void AddExpDataWithSideband(Double_t *sigExp, Double_t *bkgExp, Double_t *tau, Int_t nbins, RooWorkspace *ws, const char *dsName="NumberCountingData")
Double_t getVal(const RooArgSet *set=0) const
RooRealVar represents a fundamental (non-derived) real valued object.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
void setConstant(Bool_t value=kTRUE)
void setGlobalKillBelow(RooFit::MsgLevel level)
virtual const char * GetName() const
Returns name of object.
void AddData(RooWorkspace *)
NumberCountingPdfFactory()
constructor
RooDataSet is a container class to hold unbinned data.
RooProduct a RooAbsReal implementation that represent the product of a given set of other RooAbsReal ...
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found...
virtual ~NumberCountingPdfFactory()
destructor
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
void AddDataWithSideband(Double_t *mainMeas, Double_t *sideband, Double_t *tau, Int_t nbins, RooWorkspace *ws, const char *dsName="ExpectedNumberCountingData")
virtual Double_t getMax(const char *name=0) const
virtual TObject * clone(const char *newname) const
void AddData(Double_t *mainMeas, Double_t *bkgMeas, Double_t *db, Int_t nbins, RooWorkspace *ws, const char *dsName="NumberCountingData")
Bool_t import(const RooAbsArg &arg, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Import a RooAbsArg object, e.g.
RooRealVar * SafeObservableCreation(RooWorkspace *ws, const char *varName, Double_t value)
need to be careful here that the range of observable in the dataset is consistent with the one in the...
A TTree object has a header with a name and a title.
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets...
void AddModel(Double_t *sigExp, Int_t nchan, RooWorkspace *ws, const char *pdfName="CombinedPdf", const char *masterSignalName="masterSignal")
The RooWorkspace is a persistable container for RooFit projects.