本文整理汇总了C++中RooRealVar::setUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ RooRealVar::setUnit方法的具体用法?C++ RooRealVar::setUnit怎么用?C++ RooRealVar::setUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RooRealVar
的用法示例。
在下文中一共展示了RooRealVar::setUnit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fitbkgdataCard
void fitbkgdataCard(TString configCard="template.config",
bool dobands = true, // create baerror bands for BG models
bool dosignal = false, // plot the signal model (needs to be present)
bool blinded = true, // blind the data in the plots?
bool verbose = true ) {
gROOT->Macro("MitStyle.C");
gStyle->SetErrorX(0);
gStyle->SetOptStat(0);
gROOT->ForceStyle();
TString projectDir;
std::vector<TString> catdesc;
std::vector<TString> catnames;
std::vector<int> polorder;
double massmin = -1.;
double massmax = -1.;
double theCMenergy = -1.;
bool readStatus = readFromConfigCard( configCard,
projectDir,
catnames,
catdesc,
polorder,
massmin,
massmax,
theCMenergy
);
if( !readStatus ) {
std::cerr<<" ERROR: Could not read from card > "<<configCard.Data()<<" <."<<std::endl;
return;
}
TFile *fdata = new TFile(TString::Format("%s/CMS-HGG-data.root",projectDir.Data()),"READ");
if( !fdata ) {
std::cerr<<" ERROR: Could not open file "<<projectDir.Data()<<"/CMS-HGG-data.root."<<std::endl;
return;
}
if( !gSystem->cd(TString::Format("%s/databkg/",projectDir.Data())) ) {
std::cerr<<" ERROR: Could not change directory to "<<TString::Format("%s/databkg/",projectDir.Data()).Data()<<"."<<std::endl;
return;
}
// ----------------------------------------------------------------------
// load the input workspace....
RooWorkspace* win = (RooWorkspace*)fdata->Get("cms_hgg_workspace_data");
if( !win ) {
std::cerr<<" ERROR: Could not load workspace > cms_hgg_workspace_data < from file > "<<TString::Format("%s/CMS-HGG-data.root",projectDir.Data()).Data()<<" <."<<std::endl;
return;
}
RooRealVar *intLumi = win->var("IntLumi");
RooRealVar *hmass = win->var("CMS_hgg_mass");
if( !intLumi || !hmass ) {
std::cerr<<" ERROR: Could not load needed variables > IntLumi < or > CMS_hgg_mass < forom input workspace."<<std::endl;
return;
}
//win->Print();
hmass->setRange(massmin,massmax);
hmass->setBins(4*(int)(massmax-massmin));
hmass->SetTitle("m_{#gamma#gamma}");
hmass->setUnit("GeV");
hmass->setRange("fitrange",massmin,massmax);
hmass->setRange("blind1",100.,110.);
hmass->setRange("blind2",150.,180.);
// ----------------------------------------------------------------------
// some auxiliray vectro (don't know the meaning of all of them ... yet...
std::vector<RooAbsData*> data_vec;
std::vector<RooAbsPdf*> pdfShape_vec; // vector to store the NOT-EXTENDED PDFs (aka pdfshape)
std::vector<RooAbsPdf*> pdf_vec; // vector to store the EXTENDED PDFs
std::vector<RooAbsReal*> normu_vec; // this holds the normalization vars for each Cat (needed in bands for combined cat)
RooArgList normList; // list of range-limityed normalizations (needed for error bands on combined category)
//std::vector<RooRealVar*> coeffv;
//std::vector<RooAbsReal*> normu_vecv; // ???
// ----------------------------------------------------------------------
// define output works
RooWorkspace *wOut = new RooWorkspace("wbkg","wbkg") ;
// util;ities for the combined fit
RooCategory finalcat ("finalcat", "finalcat") ;
RooSimultaneous fullbkgpdf("fullbkgpdf","fullbkgpdf",finalcat);
RooDataSet datacomb ("datacomb", "datacomb", RooArgList(*hmass,finalcat)) ;
RooDataSet *datacombcat = new RooDataSet("data_combcat","",RooArgList(*hmass)) ;
// add the 'combcat' to the list...if more than one cat
if( catnames.size() > 1 ) {
//.........这里部分代码省略.........
示例2: draw_data_mgg
void draw_data_mgg(TString folderName,bool blind=true,float min=103,float max=160)
{
TFile inputFile(folderName+"/data.root");
const int nCat = 5;
TString cats[5] = {"HighPt","Hbb","Zbb","HighRes","LowRes"};
TCanvas cv;
for(int iCat=0; iCat < nCat; iCat++) {
RooWorkspace *ws = (RooWorkspace*)inputFile.Get(cats[iCat]+"_mgg_workspace");
RooFitResult* res = (RooFitResult*)ws->obj("fitresult_pdf_data");
RooRealVar * mass = ws->var("mgg");
mass->setRange("all",min,max);
mass->setRange("blind",121,130);
mass->setRange("low",106,121);
mass->setRange("high",130,160);
mass->setUnit("GeV");
mass->SetTitle("m_{#gamma#gamma}");
RooAbsPdf * pdf = ws->pdf("pdf");
RooPlot *plot = mass->frame(min,max,max-min);
plot->SetTitle("");
RooAbsData* data = ws->data("data")->reduce(Form("mgg > %f && mgg < %f",min,max));
double nTot = data->sumEntries();
if(blind) data = data->reduce("mgg < 121 || mgg>130");
double nBlind = data->sumEntries();
double norm = nTot/nBlind; //normalization for the plot
data->plotOn(plot);
pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::Range("Full"),RooFit::LineWidth(0.1) );
plot->Print();
//add the fix error band
RooCurve* c = plot->getCurve("pdf_Norm[mgg]_Range[Full]_NormRange[Full]");
const int Nc = c->GetN();
//TGraphErrors errfix(Nc);
//TGraphErrors errfix2(Nc);
TGraphAsymmErrors errfix(Nc);
TGraphAsymmErrors errfix2(Nc);
Double_t *x = c->GetX();
Double_t *y = c->GetY();
double NtotalFit = ws->var("Nbkg1")->getVal()*ws->var("Nbkg1")->getVal() + ws->var("Nbkg2")->getVal()*ws->var("Nbkg2")->getVal();
for( int i = 0; i < Nc; i++ )
{
errfix.SetPoint(i,x[i],y[i]);
errfix2.SetPoint(i,x[i],y[i]);
mass->setVal(x[i]);
double shapeErr = pdf->getPropagatedError(*res)*NtotalFit;
//double totalErr = TMath::Sqrt( shapeErr*shapeErr + y[i] );
//total normalization error
double totalErr = TMath::Sqrt( shapeErr*shapeErr + y[i]*y[i]/NtotalFit );
if ( y[i] - totalErr > .0 )
{
errfix.SetPointError(i, 0, 0, totalErr, totalErr );
}
else
{
errfix.SetPointError(i, 0, 0, y[i] - 0.01, totalErr );
}
//2sigma
if ( y[i] - 2.*totalErr > .0 )
{
errfix2.SetPointError(i, 0, 0, 2.*totalErr, 2.*totalErr );
}
else
{
errfix2.SetPointError(i, 0, 0, y[i] - 0.01, 2.*totalErr );
}
/*
std::cout << x[i] << " " << y[i] << " "
<< " ,pdf get Val: " << pdf->getVal()
<< " ,pdf get Prop Err: " << pdf->getPropagatedError(*res)*NtotalFit
<< " stat uncertainty: " << TMath::Sqrt(y[i]) << " Ntot: " << NtotalFit << std::endl;
*/
}
errfix.SetFillColor(kYellow);
errfix2.SetFillColor(kGreen);
//pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kGreen),RooFit::Range("Full"), RooFit::VisualizeError(*res,2.0,kFALSE));
//pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kYellow),RooFit::Range("Full"), RooFit::VisualizeError(*res,1.0,kFALSE));
//pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kGreen),RooFit::Range("Full"), RooFit::VisualizeError(*res,2.0,kTRUE));
//pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kYellow),RooFit::Range("Full"), RooFit::VisualizeError(*res,1.0,kTRUE));
plot->addObject(&errfix,"4");
plot->addObject(&errfix2,"4");
plot->addObject(&errfix,"4");
data->plotOn(plot);
TBox blindBox(121,plot->GetMinimum()-(plot->GetMaximum()-plot->GetMinimum())*0.015,130,plot->GetMaximum());
blindBox.SetFillColor(kGray);
if(blind) {
plot->addObject(&blindBox);
pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kGreen),RooFit::Range("Full"), RooFit::VisualizeError(*res,2.0,kTRUE));
pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kYellow),RooFit::Range("Full"), RooFit::VisualizeError(*res,1.0,kTRUE));
}
//plot->addObject(&errfix,"4");
//.........这里部分代码省略.........
示例3: main
int main(int argc, char *argv[]){
OptionParser(argc,argv);
TStopwatch sw;
sw.Start();
TFile *inFile = TFile::Open(filename_.c_str());
RooWorkspace *inWS = (RooWorkspace*)inFile->Get("cms_hgg_workspace");
RooRealVar *mass = (RooRealVar*)inWS->var("CMS_hgg_mass");
mass->SetTitle("m_{#gamma#gamma}");
mass->setUnit("GeV");
RooRealVar *intLumi = (RooRealVar*)inWS->var("IntLumi");
RooRealVar *MH = new RooRealVar("MH","m_{H}",mhLow_,mhHigh_);
MH->setUnit("GeV");
RooRealVar *MH_SM = new RooRealVar("MH_SM","m_{H} (SM)",mhLow_,mhHigh_);
RooRealVar *DeltaM = new RooRealVar("DeltaM","#Delta m_{H}",0.,-10.,10.);
DeltaM->setUnit("GeV");
RooAddition *MH_2 = new RooAddition("MH_2","m_{H} (2)",RooArgList(*MH,*DeltaM));
RooRealVar *higgsDecayWidth = new RooRealVar("HiggsDecayWidth","#Gamma m_{H}",0.,0.,10.);
TFile *outFile = new TFile(outfilename_.c_str(),"RECREATE");
RooWorkspace *outWS = new RooWorkspace("wsig_8TeV");
transferMacros(inFile,outFile);
// run fits for each line in datfile
ifstream datfile;
datfile.open(datfilename_.c_str());
if (datfile.fail()) exit(1);
while (datfile.good()){
string line;
getline(datfile,line);
if (line=="\n" || line.substr(0,1)=="#" || line==" " || line.empty()) continue;
vector<string> els;
split(els,line,boost::is_any_of(" "));
assert(els.size()==4);
string proc = els[0];
int cat = boost::lexical_cast<int>(els[1]);
int nGaussiansRV = boost::lexical_cast<int>(els[2]);
int nGaussiansWV = boost::lexical_cast<int>(els[3]);
cout << "-----------------------------------------------------------------" << endl;
cout << Form("Running fits for proc:%s - cat:%d with nGausRV:%d nGausWV:%d",proc.c_str(),cat,nGaussiansRV,nGaussiansWV) << endl;
cout << "-----------------------------------------------------------------" << endl;
// get datasets for each MH here
map<int,RooDataSet*> datasetsRV;
map<int,RooDataSet*> datasetsWV;
map<int,RooDataSet*> datasets;
for (int mh=mhLow_; mh<=mhHigh_; mh+=5){
RooDataSet *dataRV = (RooDataSet*)inWS->data(Form("sig_%s_mass_m%d_rv_cat%d",proc.c_str(),mh,cat));
RooDataSet *dataWV = (RooDataSet*)inWS->data(Form("sig_%s_mass_m%d_wv_cat%d",proc.c_str(),mh,cat));
RooDataSet *data = (RooDataSet*)inWS->data(Form("sig_%s_mass_m%d_cat%d",proc.c_str(),mh,cat));
datasetsRV.insert(pair<int,RooDataSet*>(mh,dataRV));
datasetsWV.insert(pair<int,RooDataSet*>(mh,dataWV));
datasets.insert(pair<int,RooDataSet*>(mh,data));
}
// these guys do the fitting
// right vertex
InitialFit initFitRV(mass,MH,mhLow_,mhHigh_);
initFitRV.setVerbosity(verbose_);
initFitRV.buildSumOfGaussians(Form("%s_cat%d",proc.c_str(),cat),nGaussiansRV);
initFitRV.setDatasets(datasetsRV);
initFitRV.runFits(1);
initFitRV.saveParamsToFileAtMH(Form("dat/in/%s_cat%d_rv.dat",proc.c_str(),cat),125);
initFitRV.loadPriorConstraints(Form("dat/in/%s_cat%d_rv.dat",proc.c_str(),cat),constraintValue_);
initFitRV.runFits(1);
initFitRV.plotFits(Form("plots/%s_cat%d/rv",proc.c_str(),cat));
map<int,map<string,RooRealVar*> > fitParamsRV = initFitRV.getFitParams();
// wrong vertex
InitialFit initFitWV(mass,MH,mhLow_,mhHigh_);
initFitWV.setVerbosity(verbose_);
initFitWV.buildSumOfGaussians(Form("%s_cat%d",proc.c_str(),cat),nGaussiansWV,recursive_);
initFitWV.setDatasets(datasetsWV);
initFitWV.runFits(1);
initFitWV.saveParamsToFileAtMH(Form("dat/in/%s_cat%d_wv.dat",proc.c_str(),cat),125);
initFitWV.loadPriorConstraints(Form("dat/in/%s_cat%d_wv.dat",proc.c_str(),cat),constraintValue_);
initFitWV.runFits(1);
initFitRV.plotFits(Form("plots/%s_cat%d/wv",proc.c_str(),cat));
map<int,map<string,RooRealVar*> > fitParamsWV = initFitWV.getFitParams();
//these guys do the interpolation
// right vertex
LinearInterp linInterpRV(MH,mhLow_,mhHigh_,fitParamsRV,doSecondaryModels_);
linInterpRV.setVerbosity(verbose_);
linInterpRV.setSecondaryModelVars(MH_SM,DeltaM,MH_2,higgsDecayWidth);
linInterpRV.interpolate(nGaussiansRV);
map<string,RooSpline1D*> splinesRV = linInterpRV.getSplines();
// wrong vertex
LinearInterp linInterpWV(MH,mhLow_,mhHigh_,fitParamsWV,doSecondaryModels_);
linInterpWV.setVerbosity(verbose_);
linInterpWV.setSecondaryModelVars(MH_SM,DeltaM,MH_2,higgsDecayWidth);
linInterpWV.interpolate(nGaussiansWV);
map<string,RooSpline1D*> splinesWV = linInterpWV.getSplines();
//.........这里部分代码省略.........