70 bool hfilled_sidebands =
false;
84 if (!hfilled_sidebands)
return;
91 mf::LogInfo(
"BuildWorkspace") <<
"Only drawing XSecs. Exiting";
93 TFile *
f =
new TFile(Outputfile.Data(),
"RECREATE");
94 TDirectory *HistoDir = f->mkdir(
"OriginalHistograms");
97 std::vector<TH1 *> pre_xsecs =
DrawXSecs();
98 for (
size_t k = 0;
k < pre_xsecs.size(); ++
k) {
99 pre_xsecs[
k]->Write();
103 for (
size_t k = 0;
k < pre_smear.size(); ++
k) {
104 pre_smear[
k]->Write();
124 TCanvas* ceffgraph =
new TCanvas(Form(
"ceffgraph%i",i),Form(
"Efficiency for channel %i",i));
127 effgraph->Draw(
"*a");
176 RooStats::HistFactory::Measurement meas(
"ProtoDUNEFitExample",
"ProtoDUNE fit example");
180 meas.SetLumiRelErr(0.001);
181 meas.AddConstantParam(
"Lumi");
184 meas.SetExportOnly(
false);
201 RooStats::HistFactory::HistoToWorkspaceFactoryFast h2w(meas);
202 RooWorkspace*
ws = h2w.MakeCombinedModel(meas);
219 RooFitResult *fitresult = NULL;
220 TTree *toys_tree = NULL;
221 TString treename(
"protodUNE_dataresults");
224 std::vector<TString> truebinsnameVec;
225 std::vector<TString> sidebandNames;
229 truebinsnameVec.push_back(str);
235 truebinsnameVec.push_back(str);
241 sidebandNames.push_back(str);
244 std::vector< TString > incidentNameVec;
247 std::cout <<
"NameVec " <<
l <<
" " << str <<
std::endl;
248 incidentNameVec.push_back(str);
251 incidentNameVec.push_back(Form(
"%s_%.1f-%.1f",
253 std::cout << incidentNameVec.back() <<
std::endl;
256 std::vector<TCanvas*> bfplots =
258 ws,
"beforefit",
"Poisson",
"ratio", truebinsnameVec,
_RecoBinning,
261 RooAbsData *asimovdata = ws->data(
"asimovData");
262 std::vector<TCanvas*> bfAsimovplots =
264 ws,
"asimov",
"Poisson",
"ratio", truebinsnameVec,
_RecoBinning,
273 std::cout <<
"Got tree " << toys_tree <<
std::endl;
274 toys_tree->SetNameTitle(
"protodUNE_mctoysresults",
"protodUNE_mctoysresults");
277 TTree *mctoys_results1 = (TTree*)toys_tree->Clone();
280 TTree *mctoys_results2 = (TTree*)toys_tree->Clone();
283 TTree *mctoys_results3 = (TTree*)toys_tree->Clone();
286 TTree *mctoys_results4 = (TTree*)toys_tree->Clone();
294 TFile *f =
new TFile(Outputfile.Data(),
"UPDATE");
300 nuisancecanvas->Write();
302 pullscanvas->Write();
303 nuispullscanvas->Write();
305 avresultcanvas->Write();
307 for(
unsigned int i=0; i < bfAsimovplots.size(); i++){
308 bfAsimovplots[i]->Write();
310 for(
unsigned int i=0; i < bfplots.size(); i++){
377 treename =
"protodUNE_asimovresults";
380 fitresult = fitandgen->
FitData(ws);
387 if(fitresult->status() != 0){
388 std::cout <<
"WARNING::Fit failed - trying with Scan" <<
std::endl;
390 fitresult = fitandgen->
FitData(ws);
393 if(fitresult->status() != 0){
395 std::cout <<
"WARNING::Fit failed with fit strategy 0 - trying with fit strategy 1." <<
std::endl;
396 fitandgen->
SetAlgorithm(ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
398 fitresult = fitandgen->
FitData(ws);
402 if(fitresult->status() != 0){
403 std::cout <<
"WARNING::Fit failed - trying with improve" <<
std::endl;
406 fitresult = fitandgen->
FitData(ws);
411 std::cerr <<
"No fit resuls found. Will exit!" <<
std::endl;
416 ws->import(*fitresult,kTRUE);
421 std::vector<TCanvas*> afplots =
423 ws,
"afterfit",
"Poisson",
"ratio", truebinsnameVec,
_RecoBinning,
436 toys_tree->SetNameTitle(treename.Data(),treename.Data());
440 ws,
"PDFit", fitresult);
442 TTree *mctoys_results1 = (TTree*)toys_tree->Clone();
445 TTree *mctoys_results2 = (TTree*)toys_tree->Clone();
447 RooArgList prefit_POI = fitresult->floatParsInit();
480 TFile *f =
new TFile(Outputfile.Data(),
"UPDATE");
489 nuisancecanvas->Write();
491 avresultcanvas->Write();
495 for(
unsigned int i=0; i < bfAsimovplots.size(); i++){
496 bfAsimovplots[i]->Write();
498 for(
unsigned int i=0; i < bfplots.size(); i++){
501 for(
unsigned int i=0; i < afplots.size(); i++){
505 TDirectory *NLLDir = f->mkdir(
"NLLPlots");
507 for (
size_t i = 0; i < nllplots.size(); ++i) {
508 nllplots[i]->Write();
519 TDirectory *HistoDir = f->mkdir(
"OriginalHistograms");
536 TDirectory * SystDir = f->mkdir(
"SystematicHists");
548 TCanvas* ceffgraph =
new TCanvas(Form(
"ceffgraph%i",i),Form(
"Efficiency for channel %i",i));
551 effgraph->Draw(
"*a");
558 std::vector<TH1 *> pre_xsecs =
DrawXSecs();
559 for (
size_t k = 0;
k < pre_xsecs.size(); ++
k) {
560 pre_xsecs[
k]->Write();
563 std::vector<TH1 *> post_xsecs =
DrawXSecs(fitresult);
564 for (
size_t k = 0;
k < post_xsecs.size(); ++
k) {
565 post_xsecs[
k]->Write();
567 std::cout <<
"Finished XSec" <<
std::endl;
580 std::cout <<
"Wrote incident" <<
std::endl;
583 TCanvas* ceffgraph =
new TCanvas(
"ceffgraph",
"Efficiency" );
void SetAlgorithm(std::string min)
std::vector< TH1 * > _interactingEfficiencyNums
std::vector< TGraphAsymmErrors * > _efficiencyGraphs
TH1 * _incidentEfficiencyNum
std::vector< TCanvas * > PlotDatasetsAndPdfs(RooWorkspace *work, TString name, TString error, TString plottodraw, std::vector< TString > binnames, std::vector< double > recobins, std::vector< TString > incidentBinNames, std::vector< TString > sidebandBinNames, std::vector< double > sidebandBins, TString measurement="PDFit", bool doNegativeReco=false, RooAbsData *data=NULL, RooFitResult *result=NULL)
bool FillSidebandHistograms_Pions()
void SetMinimiser(std::string min)
void SetInterpolationCode(RooWorkspace *ws, int code)
RooFitResult * FitData(RooWorkspace *ws, bool isWeighted=false)
void SaveWorkspace(RooWorkspace *ws, TString outFileName)
std::vector< std::string > _SidebandTopologyName
TGraphAsymmErrors * _incidentEfficiency
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool _AddSidebandsToMeasurement
std::vector< TH1 * > _truthsighistos
std::vector< std::string > _BackgroundTopologyName
std::vector< TH1 * > _incsighistos
std::vector< TH1 * > _incdatahistos
std::vector< TH1 * > _bkghistos
void AddIncidentSamplesAndChannelsToMeasurement(RooStats::HistFactory::Measurement &meas)
std::vector< TH1 * > _interactingEfficiencyDenoms
std::vector< TH1 * > _syst_hists
void AddSidebandSamplesAndChannelsToMeasurement(RooStats::HistFactory::Measurement &meas)
void AddSamplesAndChannelsToMeasurement(RooStats::HistFactory::Measurement &meas)
TH1 * _incidentEfficiencyDenom
RooFitResult * FitAsimovData(RooWorkspace *w)
std::vector< double > _SidebandBinning
TH2 * GetFitCovariance(RooFitResult *result)
TCanvas * PlotParametersPull(TTree *tree, RooWorkspace *ws)
std::vector< double > _TruthBinning
std::vector< TH2 * > DrawSmearingMatrix(RooFitResult *fitresult, bool doPostFit=false)
std::vector< TGraphAsymmErrors * > _interactingEfficiencies
bool _AddIncidentToMeasurement
TCanvas * PlotNuisanceParameters(TTree *tree, RooWorkspace *ws)
std::vector< TH1 * > DrawXSecs(RooFitResult *fitresult=0x0)
std::vector< std::string > _IncidentTopologyName
bool FillHistogramVectors_Pions()
std::vector< TCanvas * > PlotNLL(RooWorkspace *work, TString name, RooFitResult *result, bool plotPLL=false)
TH2 * GetFitCorrelationMatrix(RooFitResult *result)
void SetFitStrategy(int fs)
void SaveSnapshot(RooWorkspace *ws, TString snapshotname)
std::vector< TH1 * > _datahistos
std::vector< TH1 * > _incbkghistos
TTree * GenerateAndFit(RooWorkspace *ws, int nexp)
TCanvas * PlotAverageResultsFromToys(TTree *tree, RooWorkspace *ws, TString channelname, TString catname, RooArgList *PreFit_POI=0x0)
TTree * RooFitResultToTTree(RooWorkspace *ws, RooFitResult *res)
std::vector< double > _RecoBinning
void ScaleMCToData(bool data_is_mc=false)
TCanvas * PlotNuisanceParametersPull(TTree *tree, RooWorkspace *ws)
RooFitResult * GenerateAndFitOneToy(RooWorkspace *ws)
std::vector< TH1 * > _sighistos
void DecorateEfficiency(TGraphAsymmErrors *eff, std::string x_title="E_{true} at vertex [MeV]")
QTextStream & endl(QTextStream &s)