#ifndef RooStats_NumberCountingPdfFactory
#include "RooStats/NumberCountingPdfFactory.h"
#endif
#ifndef RooStats_RooStatsUtils
#include "RooStats/RooStatsUtils.h"
#endif
#include "RooRealVar.h"
#include "RooAddition.h"
#include "RooProduct.h"
#include "RooDataSet.h"
#include "RooProdPdf.h"
#include "RooFitResult.h"
#include "RooPoisson.h"
#include "RooGlobalFunc.h"
#include "RooCmdArg.h"
#include "RooWorkspace.h"
#include "TTree.h"
#include <sstream>
ClassImp(RooStats::NumberCountingPdfFactory) ;
using namespace RooStats;
using namespace RooFit;
NumberCountingPdfFactory::NumberCountingPdfFactory() {
}
NumberCountingPdfFactory::~NumberCountingPdfFactory(){
}
void NumberCountingPdfFactory::AddModel(Double_t* sig,
Int_t nbins,
RooWorkspace* ws,
const char* pdfName, const char* muName) {
using namespace RooFit;
using std::vector;
TList likelihoodFactors;
RooRealVar* masterSignal =
new RooRealVar(muName,"masterSignal",1., 0., 3.);
for(Int_t i=0; i<nbins; ++i){
std::stringstream str;
str<<"_"<<i;
RooRealVar* expectedSignal =
new RooRealVar(("expected_s"+str.str()).c_str(),("expected_s"+str.str()).c_str(),sig[i], 0., 2*sig[i]);
expectedSignal->setConstant(kTRUE);
RooProduct* s =
new RooProduct(("s"+str.str()).c_str(),("s"+str.str()).c_str(), RooArgSet(*masterSignal, *expectedSignal));
RooRealVar* b =
new RooRealVar(("b"+str.str()).c_str(),("b"+str.str()).c_str(), .5, 0.,1.);
RooRealVar* tau =
new RooRealVar(("tau"+str.str()).c_str(),("tau"+str.str()).c_str(), .5, 0., 1.);
tau->setConstant(kTRUE);
RooAddition* splusb =
new RooAddition(("splusb"+str.str()).c_str(),("s"+str.str()+"+"+"b"+str.str()).c_str(),
RooArgSet(*s,*b));
RooProduct* bTau =
new RooProduct(("bTau"+str.str()).c_str(),("b*tau"+str.str()).c_str(), RooArgSet(*b, *tau));
RooRealVar* x =
new RooRealVar(("x"+str.str()).c_str(),("x"+str.str()).c_str(), 0.5 , 0., 1.);
RooRealVar* y =
new RooRealVar(("y"+str.str()).c_str(),("y"+str.str()).c_str(), 0.5, 0., 1.);
RooPoisson* sigRegion =
new RooPoisson(("sigRegion"+str.str()).c_str(),("sigRegion"+str.str()).c_str(), *x,*splusb);
RooPoisson* sideband =
new RooPoisson(("sideband"+str.str()).c_str(),("sideband"+str.str()).c_str(), *y,*bTau);
likelihoodFactors.Add(sigRegion);
likelihoodFactors.Add(sideband);
}
RooArgSet likelihoodFactorSet(likelihoodFactors);
RooProdPdf joint(pdfName,"joint", likelihoodFactorSet );
RooMsgService::instance().setGlobalKillBelow(RooMsgService::ERROR) ;
ws->import(joint);
RooMsgService::instance().setGlobalKillBelow(RooMsgService::DEBUG) ;
}
void NumberCountingPdfFactory::AddExpData(Double_t* sig,
Double_t* back,
Double_t* back_syst,
Int_t nbins,
RooWorkspace* ws, const char* dsName) {
using std::vector;
Double_t* mainMeas = new Double_t[nbins];
for(Int_t i=0; i<nbins; ++i){
mainMeas[i] = sig[i] + back[i];
}
return AddData(mainMeas, back, back_syst, nbins, ws, dsName);
}
void NumberCountingPdfFactory::AddExpDataWithSideband(Double_t* sigExp,
Double_t* backExp,
Double_t* tau,
Int_t nbins,
RooWorkspace* ws, const char* dsName) {
Double_t* mainMeas = new Double_t[nbins];
Double_t* sideband = new Double_t[nbins];
for(Int_t i=0; i<nbins; ++i){
mainMeas[i] = sigExp[i] + backExp[i];
sideband[i] = backExp[i]*tau[i];
}
return AddDataWithSideband(mainMeas, sideband, tau, nbins, ws, dsName);
}
RooRealVar* NumberCountingPdfFactory::SafeObservableCreation(RooWorkspace* ws, const char* varName, Double_t value) {
return SafeObservableCreation(ws, varName, value, 10.*value);
}
RooRealVar* NumberCountingPdfFactory::SafeObservableCreation(RooWorkspace* ws, const char* varName,
Double_t value, Double_t maximum) {
RooRealVar* x = ws->var( varName );
if( !x )
x = new RooRealVar(varName, varName, value, 0, maximum );
if( x->getMax() < value )
x->setMax( max(x->getMax(), 10*value ) );
x->setVal( value );
return x;
}
void NumberCountingPdfFactory::AddData(Double_t* mainMeas,
Double_t* back,
Double_t* back_syst,
Int_t nbins,
RooWorkspace* ws, const char* dsName) {
using namespace RooFit;
using std::vector;
Double_t MaxSigma = 8;
TList observablesCollection;
TTree* tree = new TTree();
Double_t* xForTree = new Double_t[nbins];
Double_t* yForTree = new Double_t[nbins];
for(Int_t i=0; i<nbins; ++i){
std::stringstream str;
str<<"_"<<i;
Double_t _tau = 1./back[i]/back_syst[i]/back_syst[i];
RooRealVar* tau = SafeObservableCreation(ws, ("tau"+str.str()).c_str(), _tau );
cout << "\nWARNING: changed value of " << tau->GetName() << " to " << tau->getVal() <<
" to be consistent with background and its uncertainty. " <<
" Also stored these values of tau into workspace with name . " << (string(tau->GetName())+string(dsName)).c_str() <<
" if you test with a different dataset, you should adjust tau appropriately.\n"<< endl;
ws->import(*((RooRealVar*) tau->clone( (string(tau->GetName())+string(dsName)).c_str() ) ) );
RooRealVar* x = SafeObservableCreation(ws, ("x"+str.str()).c_str(), mainMeas[i]);
RooRealVar* y = SafeObservableCreation(ws, ("y"+str.str()).c_str(), back[i]*_tau );
observablesCollection.Add(x);
observablesCollection.Add(y);
xForTree[i] = mainMeas[i];
yForTree[i] = back[i]*_tau;
tree->Branch(("x"+str.str()).c_str(), xForTree+i ,("x"+str.str()+"/D").c_str());
tree->Branch(("y"+str.str()).c_str(), yForTree+i ,("y"+str.str()+"/D").c_str());
ws->var(("b"+str.str()).c_str())->setMax( 1.2*back[i]+MaxSigma*(sqrt(back[i])+back[i]*back_syst[i]) );
ws->var(("b"+str.str()).c_str())->setVal( back[i] );
}
tree->Fill();
RooArgList* observableList = new RooArgList(observablesCollection);
RooDataSet* data = new RooDataSet(dsName,"Number Counting Data", tree, *observableList);
RooMsgService::instance().setGlobalKillBelow(RooMsgService::FATAL) ;
ws->import(*data);
RooMsgService::instance().setGlobalKillBelow(RooMsgService::DEBUG) ;
}
void NumberCountingPdfFactory::AddDataWithSideband(Double_t* mainMeas,
Double_t* sideband,
Double_t* tauForTree,
Int_t nbins,
RooWorkspace* ws, const char* dsName) {
using namespace RooFit;
using std::vector;
Double_t MaxSigma = 8;
TList observablesCollection;
TTree* tree = new TTree();
Double_t* xForTree = new Double_t[nbins];
Double_t* yForTree = new Double_t[nbins];
for(Int_t i=0; i<nbins; ++i){
std::stringstream str;
str<<"_"<<i;
Double_t _tau = tauForTree[i];
Double_t back_syst = 1./sqrt(sideband[i]);
Double_t back = (sideband[i]/_tau);
RooRealVar* tau = SafeObservableCreation(ws, ("tau"+str.str()).c_str(), _tau );
cout << "\nWARNING: changed value of " << tau->GetName() << " to " << tau->getVal() <<
" to be consistent with background and its uncertainty. " <<
" Also stored these values of tau into workspace with name . " << (string(tau->GetName())+string(dsName)).c_str() <<
" if you test with a different dataset, you should adjust tau appropriately.\n"<< endl;
ws->import(*((RooRealVar*) tau->clone( (string(tau->GetName())+string(dsName)).c_str() ) ) );
RooRealVar* x = SafeObservableCreation(ws, ("x"+str.str()).c_str(), mainMeas[i]);
RooRealVar* y = SafeObservableCreation(ws, ("y"+str.str()).c_str(), sideband[i] );
observablesCollection.Add(x);
observablesCollection.Add(y);
xForTree[i] = mainMeas[i];
yForTree[i] = sideband[i];
tree->Branch(("x"+str.str()).c_str(), xForTree+i ,("x"+str.str()+"/D").c_str());
tree->Branch(("y"+str.str()).c_str(), yForTree+i ,("y"+str.str()+"/D").c_str());
ws->var(("b"+str.str()).c_str())->setMax( 1.2*back+MaxSigma*(sqrt(back)+back*back_syst) );
ws->var(("b"+str.str()).c_str())->setVal( back );
}
tree->Fill();
RooArgList* observableList = new RooArgList(observablesCollection);
RooDataSet* data = new RooDataSet(dsName,"Number Counting Data", tree, *observableList);
RooMsgService::instance().setGlobalKillBelow(RooMsgService::FATAL) ;
ws->import(*data);
RooMsgService::instance().setGlobalKillBelow(RooMsgService::DEBUG) ;
}
Last change: Fri Nov 21 08:37:07 2008
Last generated: 2008-11-21 08:37
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.