#ifndef RooStats_NeymanConstruction
#include "RooStats/NeymanConstruction.h"
#endif
#ifndef RooStats_RooStatsUtils
#include "RooStats/RooStatsUtils.h"
#endif
#ifndef RooStats_PointSetInterval
#include "RooStats/PointSetInterval.h"
#endif
#include "RooStats/SamplingDistribution.h"
#include "RooStats/ToyMCSampler.h"
#include "RooStats/ModelConfig.h"
#include "RooMsgService.h"
#include "RooGlobalFunc.h"
#include "RooDataSet.h"
#include "TFile.h"
#include "TTree.h"
#include "TMath.h"
#include "TH1F.h"
ClassImp(RooStats::NeymanConstruction) ;
using namespace RooFit;
using namespace RooStats;
NeymanConstruction::NeymanConstruction(RooAbsData& data, ModelConfig& model):
fSize(0.05),
fData(data),
fModel(model),
fTestStatSampler(0),
fPointsToTest(0),
fLeftSideFraction(0),
fConfBelt(0),
fAdaptiveSampling(false),
fAdditionalNToysFactor(1.),
fSaveBeltToFile(false),
fCreateBelt(false)
{
}
NeymanConstruction::~NeymanConstruction() {
}
PointSetInterval* NeymanConstruction::GetInterval() const {
TFile* f=0;
if(fSaveBeltToFile){
oocoutI(f,Contents) << "NeymanConstruction saving ConfidenceBelt to file SamplingDistributions.root" << endl;
f = new TFile("SamplingDistributions.root","recreate");
}
if(!&fData) {
oocoutF((TObject*)0,Contents) << "Neyman Construction: data is not set, can't get interval" << endl;
return 0;
}
Int_t npass = 0;
RooArgSet* point;
RooArgSet* fPOI = new RooArgSet(*fModel.GetParametersOfInterest());
RooDataSet* pointsInInterval = new RooDataSet("pointsInInterval",
"points in interval",
*(fPointsToTest->get(0)) );
for(Int_t i=0; i<fPointsToTest->numEntries(); ++i){
point = (RooArgSet*) fPointsToTest->get(i);
*fPOI = *point;
fTestStatSampler->SetParametersForTestStat(*fPOI);
Double_t thisTestStatistic = fTestStatSampler->EvaluateTestStatistic(fData, *fPOI );
SamplingDistribution* samplingDist=0;
Double_t sigma;
Double_t upperEdgeOfAcceptance, upperEdgeMinusSigma, upperEdgePlusSigma;
Double_t lowerEdgeOfAcceptance, lowerEdgeMinusSigma, lowerEdgePlusSigma;
Int_t additionalMC=0;
Int_t totalMC = (Int_t) (2./fSize/TMath::Min(fLeftSideFraction,1.-fLeftSideFraction));
if(fLeftSideFraction==0. || fLeftSideFraction ==1.){
totalMC = (Int_t) (2./fSize);
}
Double_t tmc = Double_t(totalMC)*fAdditionalNToysFactor;
totalMC = (Int_t) tmc;
ToyMCSampler* toyMCSampler = dynamic_cast<ToyMCSampler*>(fTestStatSampler);
if(fAdaptiveSampling && toyMCSampler) {
do{
additionalMC = 2*totalMC;
samplingDist =
toyMCSampler->AppendSamplingDistribution(*point,
samplingDist,
additionalMC);
totalMC=samplingDist->GetSize();
sigma = 1;
upperEdgeOfAcceptance =
samplingDist->InverseCDF( 1. - ((1.-fLeftSideFraction) * fSize) ,
sigma, upperEdgePlusSigma);
sigma = -1;
samplingDist->InverseCDF( 1. - ((1.-fLeftSideFraction) * fSize) ,
sigma, upperEdgeMinusSigma);
sigma = 1;
lowerEdgeOfAcceptance =
samplingDist->InverseCDF( fLeftSideFraction * fSize ,
sigma, lowerEdgePlusSigma);
sigma = -1;
samplingDist->InverseCDF( fLeftSideFraction * fSize ,
sigma, lowerEdgeMinusSigma);
ooccoutD(samplingDist,Eval) << "NeymanConstruction: "
<< "total MC = " << totalMC
<< " this test stat = " << thisTestStatistic << endl
<< " upper edge -1sigma = " << upperEdgeMinusSigma
<< ", upperEdge = "<<upperEdgeOfAcceptance
<< ", upper edge +1sigma = " << upperEdgePlusSigma << endl
<< " lower edge -1sigma = " << lowerEdgeMinusSigma
<< ", lowerEdge = "<<lowerEdgeOfAcceptance
<< ", lower edge +1sigma = " << lowerEdgePlusSigma << endl;
} while((
(thisTestStatistic <= upperEdgeOfAcceptance &&
thisTestStatistic > upperEdgeMinusSigma)
|| (thisTestStatistic >= upperEdgeOfAcceptance &&
thisTestStatistic < upperEdgePlusSigma)
|| (thisTestStatistic <= lowerEdgeOfAcceptance &&
thisTestStatistic > lowerEdgeMinusSigma)
|| (thisTestStatistic >= lowerEdgeOfAcceptance &&
thisTestStatistic < lowerEdgePlusSigma)
) && (totalMC < 100./fSize)
) ;
} else {
samplingDist = fTestStatSampler->GetSamplingDistribution(*point);
lowerEdgeOfAcceptance =
samplingDist->InverseCDF( fLeftSideFraction * fSize );
upperEdgeOfAcceptance =
samplingDist->InverseCDF( 1. - ((1.-fLeftSideFraction) * fSize) );
}
if(fConfBelt && fCreateBelt){
fConfBelt->AddAcceptanceRegion(*point, i,
lowerEdgeOfAcceptance,
upperEdgeOfAcceptance);
}
TIter itr = point->createIterator();
RooRealVar* myarg;
ooccoutP(samplingDist,Eval) << "NeymanConstruction: Prog: "<< i+1<<"/"<<fPointsToTest->numEntries()
<< " total MC = " << samplingDist->GetSize()
<< " this test stat = " << thisTestStatistic << endl;
ooccoutP(samplingDist,Eval) << " ";
while ((myarg = (RooRealVar *)itr.Next())) {
ooccoutP(samplingDist,Eval) << myarg->GetName() << "=" << myarg->getVal() << " ";
}
ooccoutP(samplingDist,Eval) << "[" << lowerEdgeOfAcceptance << ", "
<< upperEdgeOfAcceptance << "] " << " in interval = " <<
(thisTestStatistic >= lowerEdgeOfAcceptance && thisTestStatistic <= upperEdgeOfAcceptance)
<< endl << endl;
if(thisTestStatistic >= lowerEdgeOfAcceptance && thisTestStatistic <= upperEdgeOfAcceptance) {
pointsInInterval->add(*point);
++npass;
}
if(fSaveBeltToFile){
samplingDist->Write();
string tmpName = "hist_";
tmpName+=samplingDist->GetName();
TH1F* h = new TH1F(tmpName.c_str(),"",500,0.,5.);
for(int ii=0; ii<samplingDist->GetSize(); ++ii){
h->Fill(samplingDist->GetSamplingDistribution().at(ii) );
}
h->Write();
delete h;
}
delete samplingDist;
}
oocoutI(pointsInInterval,Eval) << npass << " points in interval" << endl;
PointSetInterval* interval
= new PointSetInterval("ClassicalConfidenceInterval", *pointsInInterval);
if(fSaveBeltToFile){
fConfBelt->Write();
f->Close();
}
delete f;
return interval;
}
NeymanConstruction.cxx:10 NeymanConstruction.cxx:11 NeymanConstruction.cxx:12 NeymanConstruction.cxx:13 NeymanConstruction.cxx:14 NeymanConstruction.cxx:15 NeymanConstruction.cxx:16 NeymanConstruction.cxx:17 NeymanConstruction.cxx:18 NeymanConstruction.cxx:19 NeymanConstruction.cxx:20 NeymanConstruction.cxx:21 NeymanConstruction.cxx:22 NeymanConstruction.cxx:23 NeymanConstruction.cxx:24 NeymanConstruction.cxx:25 NeymanConstruction.cxx:26 NeymanConstruction.cxx:27 NeymanConstruction.cxx:28 NeymanConstruction.cxx:29 NeymanConstruction.cxx:30 NeymanConstruction.cxx:31 NeymanConstruction.cxx:32 NeymanConstruction.cxx:33 NeymanConstruction.cxx:34 NeymanConstruction.cxx:35 NeymanConstruction.cxx:36 NeymanConstruction.cxx:37 NeymanConstruction.cxx:38 NeymanConstruction.cxx:39 NeymanConstruction.cxx:40 NeymanConstruction.cxx:41 NeymanConstruction.cxx:42 NeymanConstruction.cxx:43 NeymanConstruction.cxx:44 NeymanConstruction.cxx:45 NeymanConstruction.cxx:46 NeymanConstruction.cxx:47 NeymanConstruction.cxx:48 NeymanConstruction.cxx:49 NeymanConstruction.cxx:50 NeymanConstruction.cxx:51 NeymanConstruction.cxx:52 NeymanConstruction.cxx:53 NeymanConstruction.cxx:54 NeymanConstruction.cxx:55 NeymanConstruction.cxx:56 NeymanConstruction.cxx:57 NeymanConstruction.cxx:58 NeymanConstruction.cxx:59 NeymanConstruction.cxx:60 NeymanConstruction.cxx:61 NeymanConstruction.cxx:62 NeymanConstruction.cxx:63 NeymanConstruction.cxx:64 NeymanConstruction.cxx:65 NeymanConstruction.cxx:66 NeymanConstruction.cxx:67 NeymanConstruction.cxx:68 NeymanConstruction.cxx:69 NeymanConstruction.cxx:70 NeymanConstruction.cxx:71 NeymanConstruction.cxx:72 NeymanConstruction.cxx:73 NeymanConstruction.cxx:74 NeymanConstruction.cxx:75 NeymanConstruction.cxx:76 NeymanConstruction.cxx:77 NeymanConstruction.cxx:78 NeymanConstruction.cxx:79 NeymanConstruction.cxx:80 NeymanConstruction.cxx:81 NeymanConstruction.cxx:82 NeymanConstruction.cxx:83 NeymanConstruction.cxx:84 NeymanConstruction.cxx:85 NeymanConstruction.cxx:86 NeymanConstruction.cxx:87 NeymanConstruction.cxx:88 NeymanConstruction.cxx:89 NeymanConstruction.cxx:90 NeymanConstruction.cxx:91 NeymanConstruction.cxx:92 NeymanConstruction.cxx:93 NeymanConstruction.cxx:94 NeymanConstruction.cxx:95 NeymanConstruction.cxx:96 NeymanConstruction.cxx:97 NeymanConstruction.cxx:98 NeymanConstruction.cxx:99 NeymanConstruction.cxx:100 NeymanConstruction.cxx:101 NeymanConstruction.cxx:102 NeymanConstruction.cxx:103 NeymanConstruction.cxx:104 NeymanConstruction.cxx:105 NeymanConstruction.cxx:106 NeymanConstruction.cxx:107 NeymanConstruction.cxx:108 NeymanConstruction.cxx:109 NeymanConstruction.cxx:110 NeymanConstruction.cxx:111 NeymanConstruction.cxx:112 NeymanConstruction.cxx:113 NeymanConstruction.cxx:114 NeymanConstruction.cxx:115 NeymanConstruction.cxx:116 NeymanConstruction.cxx:117 NeymanConstruction.cxx:118 NeymanConstruction.cxx:119 NeymanConstruction.cxx:120 NeymanConstruction.cxx:121 NeymanConstruction.cxx:122 NeymanConstruction.cxx:123 NeymanConstruction.cxx:124 NeymanConstruction.cxx:125 NeymanConstruction.cxx:126 NeymanConstruction.cxx:127 NeymanConstruction.cxx:128 NeymanConstruction.cxx:129 NeymanConstruction.cxx:130 NeymanConstruction.cxx:131 NeymanConstruction.cxx:132 NeymanConstruction.cxx:133 NeymanConstruction.cxx:134 NeymanConstruction.cxx:135 NeymanConstruction.cxx:136 NeymanConstruction.cxx:137 NeymanConstruction.cxx:138 NeymanConstruction.cxx:139 NeymanConstruction.cxx:140 NeymanConstruction.cxx:141 NeymanConstruction.cxx:142 NeymanConstruction.cxx:143 NeymanConstruction.cxx:144 NeymanConstruction.cxx:145 NeymanConstruction.cxx:146 NeymanConstruction.cxx:147 NeymanConstruction.cxx:148 NeymanConstruction.cxx:149 NeymanConstruction.cxx:150 NeymanConstruction.cxx:151 NeymanConstruction.cxx:152 NeymanConstruction.cxx:153 NeymanConstruction.cxx:154 NeymanConstruction.cxx:155 NeymanConstruction.cxx:156 NeymanConstruction.cxx:157 NeymanConstruction.cxx:158 NeymanConstruction.cxx:159 NeymanConstruction.cxx:160 NeymanConstruction.cxx:161 NeymanConstruction.cxx:162 NeymanConstruction.cxx:163 NeymanConstruction.cxx:164 NeymanConstruction.cxx:165 NeymanConstruction.cxx:166 NeymanConstruction.cxx:167 NeymanConstruction.cxx:168 NeymanConstruction.cxx:169 NeymanConstruction.cxx:170 NeymanConstruction.cxx:171 NeymanConstruction.cxx:172 NeymanConstruction.cxx:173 NeymanConstruction.cxx:174 NeymanConstruction.cxx:175 NeymanConstruction.cxx:176 NeymanConstruction.cxx:177 NeymanConstruction.cxx:178 NeymanConstruction.cxx:179 NeymanConstruction.cxx:180 NeymanConstruction.cxx:181 NeymanConstruction.cxx:182 NeymanConstruction.cxx:183 NeymanConstruction.cxx:184 NeymanConstruction.cxx:185 NeymanConstruction.cxx:186 NeymanConstruction.cxx:187 NeymanConstruction.cxx:188 NeymanConstruction.cxx:189 NeymanConstruction.cxx:190 NeymanConstruction.cxx:191 NeymanConstruction.cxx:192 NeymanConstruction.cxx:193 NeymanConstruction.cxx:194 NeymanConstruction.cxx:195 NeymanConstruction.cxx:196 NeymanConstruction.cxx:197 NeymanConstruction.cxx:198 NeymanConstruction.cxx:199 NeymanConstruction.cxx:200 NeymanConstruction.cxx:201 NeymanConstruction.cxx:202 NeymanConstruction.cxx:203 NeymanConstruction.cxx:204 NeymanConstruction.cxx:205 NeymanConstruction.cxx:206 NeymanConstruction.cxx:207 NeymanConstruction.cxx:208 NeymanConstruction.cxx:209 NeymanConstruction.cxx:210 NeymanConstruction.cxx:211 NeymanConstruction.cxx:212 NeymanConstruction.cxx:213 NeymanConstruction.cxx:214 NeymanConstruction.cxx:215 NeymanConstruction.cxx:216 NeymanConstruction.cxx:217 NeymanConstruction.cxx:218 NeymanConstruction.cxx:219 NeymanConstruction.cxx:220 NeymanConstruction.cxx:221 NeymanConstruction.cxx:222 NeymanConstruction.cxx:223 NeymanConstruction.cxx:224 NeymanConstruction.cxx:225 NeymanConstruction.cxx:226 NeymanConstruction.cxx:227 NeymanConstruction.cxx:228 NeymanConstruction.cxx:229 NeymanConstruction.cxx:230 NeymanConstruction.cxx:231 NeymanConstruction.cxx:232 NeymanConstruction.cxx:233 NeymanConstruction.cxx:234 NeymanConstruction.cxx:235 NeymanConstruction.cxx:236 NeymanConstruction.cxx:237 NeymanConstruction.cxx:238 NeymanConstruction.cxx:239 NeymanConstruction.cxx:240 NeymanConstruction.cxx:241 NeymanConstruction.cxx:242 NeymanConstruction.cxx:243 NeymanConstruction.cxx:244 NeymanConstruction.cxx:245 NeymanConstruction.cxx:246 NeymanConstruction.cxx:247 NeymanConstruction.cxx:248 NeymanConstruction.cxx:249 NeymanConstruction.cxx:250 NeymanConstruction.cxx:251 NeymanConstruction.cxx:252 NeymanConstruction.cxx:253 NeymanConstruction.cxx:254 NeymanConstruction.cxx:255 NeymanConstruction.cxx:256 NeymanConstruction.cxx:257 NeymanConstruction.cxx:258 NeymanConstruction.cxx:259 NeymanConstruction.cxx:260 NeymanConstruction.cxx:261 NeymanConstruction.cxx:262 NeymanConstruction.cxx:263 NeymanConstruction.cxx:264 NeymanConstruction.cxx:265 NeymanConstruction.cxx:266 NeymanConstruction.cxx:267 NeymanConstruction.cxx:268 NeymanConstruction.cxx:269 NeymanConstruction.cxx:270 NeymanConstruction.cxx:271 NeymanConstruction.cxx:272 NeymanConstruction.cxx:273 NeymanConstruction.cxx:274 NeymanConstruction.cxx:275 NeymanConstruction.cxx:276 NeymanConstruction.cxx:277 NeymanConstruction.cxx:278 NeymanConstruction.cxx:279 NeymanConstruction.cxx:280 NeymanConstruction.cxx:281 NeymanConstruction.cxx:282 NeymanConstruction.cxx:283 NeymanConstruction.cxx:284 NeymanConstruction.cxx:285 NeymanConstruction.cxx:286 NeymanConstruction.cxx:287 NeymanConstruction.cxx:288 NeymanConstruction.cxx:289 NeymanConstruction.cxx:290 NeymanConstruction.cxx:291 NeymanConstruction.cxx:292 NeymanConstruction.cxx:293 NeymanConstruction.cxx:294 NeymanConstruction.cxx:295 NeymanConstruction.cxx:296 NeymanConstruction.cxx:297 NeymanConstruction.cxx:298 NeymanConstruction.cxx:299 NeymanConstruction.cxx:300 NeymanConstruction.cxx:301 NeymanConstruction.cxx:302 NeymanConstruction.cxx:303 NeymanConstruction.cxx:304 NeymanConstruction.cxx:305 NeymanConstruction.cxx:306 NeymanConstruction.cxx:307 NeymanConstruction.cxx:308 NeymanConstruction.cxx:309 NeymanConstruction.cxx:310 NeymanConstruction.cxx:311 NeymanConstruction.cxx:312 NeymanConstruction.cxx:313 NeymanConstruction.cxx:314