本文整理汇总了C++中RooDataSet::mean方法的典型用法代码示例。如果您正苦于以下问题:C++ RooDataSet::mean方法的具体用法?C++ RooDataSet::mean怎么用?C++ RooDataSet::mean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RooDataSet
的用法示例。
在下文中一共展示了RooDataSet::mean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IntervalExamples
void IntervalExamples()
{
// Time this macro
TStopwatch t;
t.Start();
// set RooFit random seed for reproducible results
RooRandom::randomGenerator()->SetSeed(3001);
// make a simple model via the workspace factory
RooWorkspace* wspace = new RooWorkspace();
wspace->factory("Gaussian::normal(x[-10,10],mu[-1,1],sigma[1])");
wspace->defineSet("poi","mu");
wspace->defineSet("obs","x");
// specify components of model for statistical tools
ModelConfig* modelConfig = new ModelConfig("Example G(x|mu,1)");
modelConfig->SetWorkspace(*wspace);
modelConfig->SetPdf( *wspace->pdf("normal") );
modelConfig->SetParametersOfInterest( *wspace->set("poi") );
modelConfig->SetObservables( *wspace->set("obs") );
// create a toy dataset
RooDataSet* data = wspace->pdf("normal")->generate(*wspace->set("obs"),100);
data->Print();
// for convenience later on
RooRealVar* x = wspace->var("x");
RooRealVar* mu = wspace->var("mu");
// set confidence level
double confidenceLevel = 0.95;
// example use profile likelihood calculator
ProfileLikelihoodCalculator plc(*data, *modelConfig);
plc.SetConfidenceLevel( confidenceLevel);
LikelihoodInterval* plInt = plc.GetInterval();
// example use of Feldman-Cousins
FeldmanCousins fc(*data, *modelConfig);
fc.SetConfidenceLevel( confidenceLevel);
fc.SetNBins(100); // number of points to test per parameter
fc.UseAdaptiveSampling(true); // make it go faster
// Here, we consider only ensembles with 100 events
// The PDF could be extended and this could be removed
fc.FluctuateNumDataEntries(false);
// Proof
// ProofConfig pc(*wspace, 4, "workers=4", kFALSE); // proof-lite
//ProofConfig pc(w, 8, "localhost"); // proof cluster at "localhost"
// ToyMCSampler* toymcsampler = (ToyMCSampler*) fc.GetTestStatSampler();
// toymcsampler->SetProofConfig(&pc); // enable proof
PointSetInterval* interval = (PointSetInterval*) fc.GetInterval();
// example use of BayesianCalculator
// now we also need to specify a prior in the ModelConfig
wspace->factory("Uniform::prior(mu)");
modelConfig->SetPriorPdf(*wspace->pdf("prior"));
// example usage of BayesianCalculator
BayesianCalculator bc(*data, *modelConfig);
bc.SetConfidenceLevel( confidenceLevel);
SimpleInterval* bcInt = bc.GetInterval();
// example use of MCMCInterval
MCMCCalculator mc(*data, *modelConfig);
mc.SetConfidenceLevel( confidenceLevel);
// special options
mc.SetNumBins(200); // bins used internally for representing posterior
mc.SetNumBurnInSteps(500); // first N steps to be ignored as burn-in
mc.SetNumIters(100000); // how long to run chain
mc.SetLeftSideTailFraction(0.5); // for central interval
MCMCInterval* mcInt = mc.GetInterval();
// for this example we know the expected intervals
double expectedLL = data->mean(*x)
+ ROOT::Math::normal_quantile( (1-confidenceLevel)/2,1)
/ sqrt(data->numEntries());
double expectedUL = data->mean(*x)
+ ROOT::Math::normal_quantile_c((1-confidenceLevel)/2,1)
/ sqrt(data->numEntries()) ;
// Use the intervals
std::cout << "expected interval is [" <<
expectedLL << ", " <<
expectedUL << "]" << endl;
cout << "plc interval is [" <<
plInt->LowerLimit(*mu) << ", " <<
plInt->UpperLimit(*mu) << "]" << endl;
std::cout << "fc interval is ["<<
interval->LowerLimit(*mu) << " , " <<
interval->UpperLimit(*mu) << "]" << endl;
//.........这里部分代码省略.........
示例2: createWorkspace
//.........这里部分代码省略.........
// output file name and workspace
std::stringstream outfilename;
outfilename << "tmpFiles/backupWorkSpace/ws_createWorkspace_Chi_rap" << iRap << "_pt" << iPT << ".root";
RooWorkspace* ws = new RooWorkspace(workspacename.c_str());
// define pt and y cuts on dataset
std::stringstream cutString;
if(onia::KinParticleChi && !onia::KinParticleChiButJpsiRap) {
cutString << "(chicPt >= " << ptMin << " && chicPt < "<< ptMax << ") && "
<< "(TMath::Abs(chicRap) >= " << yMin << " && TMath::Abs(chicRap) < " << yMax << ")";
}
if(!onia::KinParticleChi) {
cutString << "(JpsiPt >= " << ptMin << " && JpsiPt < "<< ptMax << ") && "
<< "(TMath::Abs(JpsiRap) >= " << yMin << " && TMath::Abs(JpsiRap) < " << yMax << ")";
}
if(onia::KinParticleChi && onia::KinParticleChiButJpsiRap) {
cutString << "(chicPt >= " << ptMin << " && chicPt < "<< ptMax << ") && "
<< "(TMath::Abs(JpsiRap) >= " << yMin << " && TMath::Abs(JpsiRap) < " << yMax << ")";
}
cout << "cutString: " << cutString.str().c_str() << endl;
// get the dataset for the fit
RooDataSet* binData = (RooDataSet*)fullData->reduce(cutString.str().c_str());
std::stringstream name;
name << "jpsi_data_rap" << iRap << "_pt" << iPT;
binData->SetNameTitle(name.str().c_str(), "Data For Fitting");
cout << "numEvents = " << binData->sumEntries() << endl;
double chicMeanPt = binData->mean(*chicPt);
RooRealVar var_chicMeanPt("var_chicMeanPt","var_chicMeanPt",chicMeanPt);
if(!ws->var("var_chicMeanPt")) ws->import(var_chicMeanPt);
else ws->var("var_chicMeanPt")->setVal(chicMeanPt);
cout << "chicMeanPt = " << chicMeanPt << endl;
double jpsiMeanPt = binData->mean(*JpsiPt);
RooRealVar var_jpsiMeanPt("var_jpsiMeanPt","var_jpsiMeanPt",jpsiMeanPt);
if(!ws->var("var_jpsiMeanPt")) ws->import(var_jpsiMeanPt);
else ws->var("var_jpsiMeanPt")->setVal(jpsiMeanPt);
cout << "jpsiMeanPt = " << jpsiMeanPt << endl;
std::stringstream cutStringPosRapChic;
cutStringPosRapChic << "chicRap > 0";
RooDataSet* binDataPosRapChic = (RooDataSet*)binData->reduce(cutStringPosRapChic.str().c_str());
double chicMeanAbsRap = binDataPosRapChic->mean(*chicRap);
cout << "chicMeanAbsRap = " << chicMeanAbsRap << endl;
RooRealVar var_chicMeanAbsRap("var_chicMeanAbsRap","var_chicMeanAbsRap",chicMeanAbsRap);
if(!ws->var("var_chicMeanAbsRap")) ws->import(var_chicMeanAbsRap);
else ws->var("var_chicMeanAbsRap")->setVal(chicMeanAbsRap);
std::stringstream cutStringPosRapJpsi;
cutStringPosRapJpsi << "JpsiRap > 0";
RooDataSet* binDataPosRapJpsi = (RooDataSet*)binData->reduce(cutStringPosRapJpsi.str().c_str());
double jpsiMeanAbsRap = binDataPosRapJpsi->mean(*JpsiRap);
cout << "jpsiMeanAbsRap = " << jpsiMeanAbsRap << endl;
RooRealVar var_jpsiMeanAbsRap("var_jpsiMeanAbsRap","var_jpsiMeanAbsRap",jpsiMeanAbsRap);
if(!ws->var("var_jpsiMeanAbsRap")) ws->import(var_jpsiMeanAbsRap);
else ws->var("var_jpsiMeanAbsRap")->setVal(jpsiMeanAbsRap);
// Import variables to workspace
ws->import(*binData);
ws->writeToFile(outfilename.str().c_str());