예제 #1
0
double upper_limit_Bayesian_BAT(Model* model,double confidence,int Niters){
  cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl;
  cout<<"Calculating upper limit with the Bayesian method(BAT)"<<endl;
  cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl;
  
  RooWorkspace* wspace = new RooWorkspace("wspace");
  RooStats::ModelConfig* modelConfig = new ModelConfig("bayes");
  modelConfig->SetWorkspace(*wspace);
  modelConfig->SetPdf(*model->get_complete_likelihood());
  modelConfig->SetPriorPdf(*model->get_POI_prior());
  modelConfig->SetParametersOfInterest(*model->get_POI_set());
  modelConfig->SetNuisanceParameters(*model->get_nuisance_set());


  cout<<" POI size "<<model->get_POI_set()->getSize()<<endl; 
 


  //BATCalculator batcalc(model->get_data(), model->get_complete_likelihood(), model->get_POI_set(), model->get_POI_prior());
  BATCalculator batcalc(*model->get_data(), *modelConfig);
  batcalc.SetConfidenceLevel(1-(2*(1-confidence)));
  batcalc.SetnMCMC(Niters);
  //batcalc.SetNbins("POI",100);
  double ul=batcalc.GetInterval()->UpperLimit();
  cout<<confidence<<"% CL upper limit: " <<ul<<endl;

  //double prec=batcalc.GetBrfPrecision();
  return ul;

}
std::pair<float,float> ComputeLimitForADataset(float m0, RooDataSet* CurrentDataset, REGION region, REGION NonRegion, TString& modelName, RooWorkspace *ws, const char* tag) {
  
  ws->var("m0")->setVal(m0);
  ws->var("m0")->setConstant(1); 
  m0 = float(ws->var("m0")->getVal());
  
  RooRealVar *mu = ws->var(Concatenate("nSig",GetRegion(region)));
  RooArgSet *poi = new RooArgSet(*mu);
  RooArgSet *nullParams = (RooArgSet*) poi->snapshot();
  nullParams->setRealValue(Concatenate("nSig",GetRegion(region)), 0);
  
  RooStats::ModelConfig *model = new RooStats::ModelConfig();
  model->SetWorkspace(*ws);
  model->SetPdf(*ws->pdf(modelName));
  model->SetParametersOfInterest(*mu);
  model->SetObservables(RooArgSet(*ws->var("inv")));
  model->SetSnapshot(*mu);
  
  RooStats::ModelConfig *nullModel;
  nullModel = model->Clone(modelName+"BgOnly");
  float oldval = ws->var(Concatenate("nSig",GetRegion(region)))->getVal();
  ws->var(Concatenate("nSig",GetRegion(region)))->setVal(0);
  ws->var(Concatenate("nSig",GetRegion(region)))->setConstant(1);
  nullModel->SetSnapshot(RooArgSet(*ws->var(Concatenate("nSig",GetRegion(region)))));
  ws->var(Concatenate("nSig",GetRegion(region)))->setConstant(0);
  ws->var(Concatenate("nSig",GetRegion(region)))->setVal(oldval);
  nullModel->SetWorkspace(*ws);
  nullModel->SetParametersOfInterest(*nullParams);
  
  RooAbsData *data = CurrentDataset;
  
  
  float UpperLimit,Signif;
  ComputeUpperLimit(data,model,UpperLimit,Signif,mu,nullParams,ws,region,tag);
  
  delete poi;
  poi=0;
  delete model;
  model=0;
  
  return make_pair(UpperLimit,Signif);
}
예제 #3
0
void makeModel(RooWorkspace& w) {

   TFile *_file0 = TFile::Open("plots/htotal_root_ZprimeRecomass.root");
   TH1F *Histo = (TH1F*)_file0->Get("htotaldata");
   RooRealVar invm("invm","invm",200.,4000.);    
   RooDataHist* data = new RooDataHist("data","data",invm,Import(*Histo)) ;
   

//   TTree* tree = new TTree("simple","data from ascii file");
//   Long64_t nlines = tree->ReadFile("list_mll_200_2016.txt","x1:x2:x3:invm:x5:x6");
//   Long64_t nlines = tree->ReadFile("a.txt","x1:x2:x3:invm:x5:x6");
//   printf(" found %lld pointsn",nlines);
//   tree->Write();
//   tree->GetEntries();

   RooRealVar mass("mass","mass", 300., 200., 1600.);
   RooRealVar nsig("nsig","Number of signal events", 0., 5000.);
   RooRealVar nbkg("nbkg","Number of background events", 0., 300000.);
   w.import(mass);
   w.import(nsig);
   w.import(nbkg);

//   RooRealVar invm("invm","Invariant mass", 200., 4000.);
//   RooDataSet* data = new RooDataSet("data", "Data", invm, RooFit::Import(*tree));

   data->Print("v");
   w.import(invm);
   w.import(*data);
 
   w.factory("expr::sigma('invm*(0.01292 + 0.00001835 * invm - 0.0000000002733 * invm*invm)',invm)");
   w.factory("expr::width('0.03*invm',invm)");
 
   w.factory("CEXPR::bkgpdf('exp(24.9327 - 2.39287e-03*invm + 3.19926e-07*invm*invm - 3.38799e-11*invm*invm*invm)*pow(invm,-3.3634)',invm)");
   w.factory("Voigtian::sigpdf(invm,mass,width,sigma)");

   w.factory("SUM::model(nbkg*bkgpdf, nsig*sigpdf)");

   RooAbsPdf* sigpdf = w.pdf("sigpdf");
   RooAbsPdf* bkgpdf = w.pdf("bkgpdf");
   RooAbsPdf* model  = w.pdf("model");

   RooStats::ModelConfig* mc = new ModelConfig("mc",&w);
   mc->SetPdf(*w.pdf("model"));
   mc->SetParametersOfInterest(*w.var("nsig"));
   mc->SetObservables(*w.var("invm"));
   w.defineSet("nuisParams","nbkg");

   mc->SetNuisanceParameters(*w.set("nuisParams"));
   w.var("mass")->setConstant(true);

   w.import(*mc);

   w.Print("tree");

   w.writeToFile("MyModel_workspace.root");
  
   TCanvas* c1 = new TCanvas("c1","Control Plots", 900, 700);
   RooPlot* plot = w.var("invm")->frame();
   w.data("data")->plotOn(plot);
   w.pdf("model")->plotOn(plot);
   w.pdf("model")->plotOn(plot, Components("bkgpdf"),LineStyle(kDashed));
   w.pdf("model")->plotOn(plot, Components("sigpdf"),LineColor(kRed));
   plot->Draw();

   return;

}