Page MenuHomeHEPForge

No OneTemporary

This file is larger than 256 KB, so syntax highlighting was skipped.
diff --git a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu.cxx b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu.cxx
index 8462644..18fafa9 100644
--- a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu.h"
// The constructor
ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu::ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu";
- plotTitles = "; p_{#mu} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu";
+ fPlotTitles = "; p_{#mu} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pim1pip/CC2pi_1pim1pip_pMu_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pmu;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
Pmu = event->PartInfo(j)->fP;
}
}
double pmu = FitUtils::p(Pmu);
- this->X_VAR = pmu;
+ this->fXVar = pmu;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pimCnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == -211) {
pimCnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pimCnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pim1pip_Evt_1Dpmu_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppim_nu.cxx b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppim_nu.cxx
index 7cfb36b..f2483d8 100644
--- a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppim_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppim_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pim1pip_Evt_1Dppim_nu.h"
// The constructor
ANL_CC2pi_1pim1pip_Evt_1Dppim_nu::ANL_CC2pi_1pim1pip_Evt_1Dppim_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pim1pip_Evt_1Dppim_nu";
- plotTitles = "; p_{#pi-} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pim1pip_Evt_1Dppim_nu";
+ fPlotTitles = "; p_{#pi-} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pim1pip/CC2pi_1pim1pip_ppim_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pim1pip_Evt_1Dppim_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Ppim;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == -211) {
Ppim = event->PartInfo(j)->fP;
}
}
double ppim = FitUtils::p(Ppim);
- this->X_VAR = ppim;
+ this->fXVar = ppim;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pim1pip_Evt_1Dppim_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pimCnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == -211) {
pimCnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pimCnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pim1pip_Evt_1Dppim_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pim1pip_Evt_1Dppim_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppip_nu.cxx b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppip_nu.cxx
index 8f657a9..7b38b28 100644
--- a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppip_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dppip_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pim1pip_Evt_1Dppip_nu.h"
// The constructor
ANL_CC2pi_1pim1pip_Evt_1Dppip_nu::ANL_CC2pi_1pim1pip_Evt_1Dppip_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pim1pip_Evt_1Dppip_nu";
- plotTitles = "; p_{#pi+} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pim1pip_Evt_1Dppip_nu";
+ fPlotTitles = "; p_{#pi+} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pim1pip/CC2pi_1pim1pip_ppip_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pim1pip_Evt_1Dppip_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Ppip;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 211) {
Ppip = event->PartInfo(j)->fP;
}
}
double ppip = FitUtils::p(Ppip);
- this->X_VAR = ppip;
+ this->fXVar = ppip;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pim1pip_Evt_1Dppip_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pimCnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == -211) {
pimCnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pimCnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pim1pip_Evt_1Dppip_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pim1pip_Evt_1Dppip_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu.cxx b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu.cxx
index e14a443..eab9972 100644
--- a/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu.h"
// The constructor
ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu::ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu";
- plotTitles = "; p_{prot} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu";
+ fPlotTitles = "; p_{prot} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pim1pip/CC2pi_1pim1pip_pProt_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pprot;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 2212) {
Pprot = event->PartInfo(j)->fP;
}
}
double pprot = FitUtils::p(Pprot);
- this->X_VAR = pprot;
+ this->fXVar = pprot;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pimCnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == -211) {
pimCnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pimCnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pim1pip_Evt_1Dpprot_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pim1pip_XSec_1DEnu_nu.cxx b/src/ANL/ANL_CC2pi_1pim1pip_XSec_1DEnu_nu.cxx
index d2712a8..c1396ba 100644
--- a/src/ANL/ANL_CC2pi_1pim1pip_XSec_1DEnu_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pim1pip_XSec_1DEnu_nu.cxx
@@ -1,126 +1,126 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pim1pip_XSec_1DEnu_nu.h"
// The constructor
ANL_CC2pi_1pim1pip_XSec_1DEnu_nu::ANL_CC2pi_1pim1pip_XSec_1DEnu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pim1pip_XSec_1DEnu_nu";
- plotTitles = "; E_{#nu} (GeV); #sigma(E_{#nu}) (cm^{2}/nucleon)";
+ fName = "ANL_CC2pi_1pim1pip_XSec_1DEnu_nu";
+ fPlotTitles = "; E_{#nu} (GeV); #sigma(E_{#nu}) (cm^{2}/nucleon)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- normError = 0.20; // normalisation error on ANL BNL flux
- isEnu1D = true;
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fNormError = 0.20; // normalisation error on ANL BNL flux
+ fIsEnu1D = true;
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pim1pip/CC2pi_1pim1pip1p_xsec.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
// Need to multiply the data by a factor because of the way the data is scanned (e.g. 1E-38)
- dataHist->Scale(1.E-41);
+ fDataHist->Scale(1.E-41);
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pim1pip_XSec_1DEnu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = event->PartInfo(0)->fP;
double Enu = Pnu.E()/1000.;
// No hadronic mass cut or similar here so very simple FillEventVariables
- this->X_VAR = Enu;
+ this->fXVar = Enu;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pim1pip_XSec_1DEnu_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pimCnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == -211) {
pimCnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pimCnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pim1pip_XSec_1DEnu_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pim1pip_XSec_1DEnu_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu.cxx
index 163c1c4..fa163fc 100644
--- a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu.h"
// The constructor
ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu::ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu";
- plotTitles = "; p_{#mu} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu";
+ fPlotTitles = "; p_{#mu} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pi0/CC2pi_1pip1pi0_pMu_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pmu;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
Pmu = event->PartInfo(j)->fP;
}
}
double pmu = FitUtils::p(Pmu);
- this->X_VAR = pmu;
+ this->fXVar = pmu;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pi0Cnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 111) {
pi0Cnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pi0Cnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pi0_Evt_1Dpmu_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu.cxx
index 0271b17..7809400 100644
--- a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu.h"
// The constructor
ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu::ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu";
- plotTitles = "; p_{#pi0} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu";
+ fPlotTitles = "; p_{#pi0} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pi0/CC2pi_1pip1pi0_ppi0_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Ppi0;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 111) {
Ppi0 = event->PartInfo(j)->fP;
}
}
double ppi0 = FitUtils::p(Ppi0);
- this->X_VAR = ppi0;
+ this->fXVar = ppi0;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pi0Cnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 111) {
pi0Cnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pi0Cnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pi0_Evt_1Dppi0_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu.cxx
index 2f0d180..6ef799d 100644
--- a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu.h"
// The constructor
ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu::ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu";
- plotTitles = "; p_{#pi+} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu";
+ fPlotTitles = "; p_{#pi+} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pi0/CC2pi_1pip1pi0_ppip_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Ppip;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 211) {
Ppip = event->PartInfo(j)->fP;
}
}
double ppip = FitUtils::p(Ppip);
- this->X_VAR = ppip;
+ this->fXVar = ppip;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pi0Cnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 111) {
pi0Cnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pi0Cnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pi0_Evt_1Dppip_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu.cxx
index f2c1eac..3c35139 100644
--- a/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu.cxx
@@ -1,139 +1,139 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu.h"
// The constructor
ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu::ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu";
- plotTitles = "; p_{prot} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu";
+ fPlotTitles = "; p_{prot} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pi0/CC2pi_1pip1pi0_pProt_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pp;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 2212) {
Pp = event->PartInfo(j)->fP;
}
}
double pprot = FitUtils::p(Pp);
- this->X_VAR = pprot;
+ this->fXVar = pprot;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pi0Cnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 111) {
pi0Cnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pi0Cnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pi0_Evt_1Dpprot_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu.cxx
index 529a1bd..c076a9d 100644
--- a/src/ANL/ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu.cxx
@@ -1,125 +1,125 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu.h"
// The constructor
ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu::ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu";
- plotTitles = "; E_{#nu} (GeV); #sigma(E_{#nu}) (cm^{2}/nucleon)";
+ fName = "ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu";
+ fPlotTitles = "; E_{#nu} (GeV); #sigma(E_{#nu}) (cm^{2}/nucleon)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fNormError = 0.20; // normalisation error on ANL BNL flux
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pi0/CC2pi_1pip1pi01p_xsec.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
// Need to multiply the data by a factor because of the way the data is scanned (e.g. 1E-38)
- dataHist->Scale(1.E-41);
+ fDataHist->Scale(1.E-41);
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = event->PartInfo(0)->fP;
double Enu = Pnu.E()/1000.;
// No hadronic mass cut or similar here so very simple FillEventVariables
- this->X_VAR = Enu;
+ this->fXVar = Enu;
return;
}
// Signal asks for 1pi+, 1pi0, 1mu-, 1p
bool ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int pi0Cnt = 0;
int lepCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 111) {
pi0Cnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (pi0Cnt != 1) return false;
if (lepCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pi0_XSec_1DEnu_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu.cxx
index 1818b81..ddd8ecf 100644
--- a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu.cxx
@@ -1,135 +1,135 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu.h"
// The constructor
ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu::ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu";
- plotTitles = "; p_{#mu} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu";
+ fPlotTitles = "; p_{#mu} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pip/CC2pi_1pip1pip1n_pMu_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pmu;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
Pmu = event->PartInfo(j)->fP;
}
}
double pmu = FitUtils::p(Pmu);
- this->X_VAR = pmu;
+ this->fXVar = pmu;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int lepCnt = 0;
int neutronCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 2112) {
neutronCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (lepCnt != 1) return false;
if (neutronCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pip_Evt_1Dpmu_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu.cxx
index 0c65595..db9a25c 100644
--- a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu.cxx
@@ -1,135 +1,135 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu.h"
// The constructor
ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu::ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu";
- plotTitles = "; p_{n} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu";
+ fPlotTitles = "; p_{n} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pip/CC2pi_1pip1pip1n_pNeutron_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pneutron;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 2112) {
Pneutron = event->PartInfo(j)->fP;
}
}
double pneut = FitUtils::p(Pneutron);
- this->X_VAR = pneut;
+ this->fXVar = pneut;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int lepCnt = 0;
int neutronCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 2112) {
neutronCnt++;
} else { // Can add this for bubble chambers because they strictly select 1 lep, 1 pion, 1 nucleon
return false;
}
}
if (pipCnt != 1) return false;
if (lepCnt != 1) return false;
if (neutronCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pip_Evt_1Dpneut_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu.cxx
index 2a5ccbd..d01a2af 100644
--- a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu.cxx
@@ -1,136 +1,136 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu.h"
// The constructor
ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu::ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu";
- plotTitles = "; p_{#pi high} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu";
+ fPlotTitles = "; p_{#pi high} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pip/CC2pi_1pip1pip1n_pHigh_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Ppip_high;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
// Select highest momentum positive pion
if (PID == 211 && (event->PartInfo(j)->fP).E() > Ppip_high.E()) {
Ppip_high = event->PartInfo(j)->fP;
}
}
double ppip_highest = FitUtils::p(Ppip_high);
- this->X_VAR = ppip_highest;
+ this->fXVar = ppip_highest;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int lepCnt = 0;
int neutronCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 2112) {
neutronCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (lepCnt != 1) return false;
if (neutronCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pip_Evt_1DppipHigh_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu.cxx
index 354af5c..31122f8 100644
--- a/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu.cxx
@@ -1,137 +1,137 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu.h"
// The constructor
ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu::ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu";
- plotTitles = "; p_{#pi low} (GeV); Number of events (area norm.)";
+ fName = "ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu";
+ fPlotTitles = "; p_{#pi low} (GeV); Number of events (area norm.)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- isRawEvents = true;
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fIsRawEvents = true;
+ fNormError = 0.20; // normalisation error on ANL BNL flux
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// there's also _unweight rather than weight data file
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pip/CC2pi_1pip1pip1n_pLow_weight.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu::FillEventVariables(FitEvent *event) {
// Because we're looking for a low momentum particle, let's initalise this to a very high momentum particle
TLorentzVector Ppip_low(1E5,1E5,1E5,1E5);
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
// Select highest momentum positive pion
if (PID == 211 && event->PartInfo(j)->fP.E() < Ppip_low.E()) {
Ppip_low = event->PartInfo(j)->fP;
}
}
double ppip_lowest = FitUtils::p(Ppip_low);
- this->X_VAR = ppip_lowest;
+ this->fXVar = ppip_lowest;
return;
}
// Signal asks for 1pi-, 1pi+, 1mu-, 1p
bool ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int lepCnt = 0;
int neutronCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 2112) {
neutronCnt++;
} else {
return false;
}
}
if (pipCnt != 1) return false;
if (lepCnt != 1) return false;
if (neutronCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pip_Evt_1DppipLow_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_CC2pi_1pip1pip_XSec_1DEnu_nu.cxx b/src/ANL/ANL_CC2pi_1pip1pip_XSec_1DEnu_nu.cxx
index a865a2b..c94de89 100644
--- a/src/ANL/ANL_CC2pi_1pip1pip_XSec_1DEnu_nu.cxx
+++ b/src/ANL/ANL_CC2pi_1pip1pip_XSec_1DEnu_nu.cxx
@@ -1,121 +1,121 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
/**
* D.Day et al, "Study of \nud charged-current two-pion production in the threshold region", Physical Review D, Volume 28, Number 11, 1 December 1983 \n
* Derrick, Musgrave, Ammar, Day, Kafka and Mann, "Two- and three-pion productin by \nu\mud recations nears threshold: The implication for nucleon-decay experiments", Physical Review D, Vol 30, Number 7, 1 October 1984
*/
#include "ANL_CC2pi_1pip1pip_XSec_1DEnu_nu.h"
// The constructor
ANL_CC2pi_1pip1pip_XSec_1DEnu_nu::ANL_CC2pi_1pip1pip_XSec_1DEnu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
- measurementName = "ANL_CC2pi_1pip1pip_XSec_1DEnu_nu";
- plotTitles = "; E_{#nu} (GeV); #sigma(E_{#nu}) (cm^{2}/nucleon)";
+ fName = "ANL_CC2pi_1pip1pip_XSec_1DEnu_nu";
+ fPlotTitles = "; E_{#nu} (GeV); #sigma(E_{#nu}) (cm^{2}/nucleon)";
EnuMin = 0.;
EnuMax = 6.0;
- isDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
- normError = 0.20; // normalisation error on ANL BNL flux
+ fIsDiag = true; // refers to covariance matrix; this measurement has none so only use errors, not covariance
+ fNormError = 0.20; // normalisation error on ANL BNL flux
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/CC2pi/1pip1pip/CC2pi_1pip1pip1n_xsec.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
// Need to multiply the data by a factor because of the way the data is scanned (e.g. 1E-38)
- dataHist->Scale(1.E-41);
+ fDataHist->Scale(1.E-41);
- this->scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)*(16./8.);
};
void ANL_CC2pi_1pip1pip_XSec_1DEnu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = event->PartInfo(0)->fP;
double Enu = Pnu.E()/1000.;
// No hadronic mass cut or similar here so very simple FillEventVariables
- this->X_VAR = Enu;
+ this->fXVar = Enu;
return;
}
// Signal asks for 1pi+, 1pi+, 1mu-, 1n
bool ANL_CC2pi_1pip1pip_XSec_1DEnu_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int lepCnt = 0;
int neutronCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
} else if (PID == 211) {
pipCnt++;
} else if (PID == 2112) {
neutronCnt++;
} else {
return false;
}
}
if (pipCnt != 2) return false;
if (lepCnt != 1) return false;
if (neutronCnt != 1) return false;
return true;
}
/*
void ANL_CC2pi_1pip1pip_XSec_1DEnu_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void ANL_CC2pi_1pip1pip_XSec_1DEnu_nu::ScaleEvents() {
- PlotUtils::FluxUnfoldedScaling(mcHist, fluxHist);
- PlotUtils::FluxUnfoldedScaling(mcFine, fluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcHist, fFluxHist);
+ PlotUtils::FluxUnfoldedScaling(mcFine, fFluxHist);
- mcHist->Scale(scaleFactor);
- mcFine->Scale(scaleFactor);
+ mcHist->Scale(fScaleFactor);
+ mcFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/ANL/ANL_NC1ppim_Evt_1DcosmuStar_nu.cxx b/src/ANL/ANL_NC1ppim_Evt_1DcosmuStar_nu.cxx
index 41913f9..fcbac31 100644
--- a/src/ANL/ANL_NC1ppim_Evt_1DcosmuStar_nu.cxx
+++ b/src/ANL/ANL_NC1ppim_Evt_1DcosmuStar_nu.cxx
@@ -1,123 +1,123 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "ANL_NC1ppim_Evt_1DcosmuStar_nu.h"
/**
* M. Derrick et al., "Study of the reaction \nu n \rightarrow \nu p \pi^-", Physics Letters, Volume 92B, Number 3,4, 363, 19 May 1980
*/
ANL_NC1ppim_Evt_1DcosmuStar_nu::ANL_NC1ppim_Evt_1DcosmuStar_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile) {
- measurementName = "ANL_NC1ppim_Evt_1DcosmuStar_nu";
- plotTitles = "; cos*_{#mu}; Number of events";
+ fName = "ANL_NC1ppim_Evt_1DcosmuStar_nu";
+ fPlotTitles = "; cos*_{#mu}; Number of events";
EnuMin = 0.3;
EnuMax = 1.5;
- isDiag = true;
- isRawEvents = true;
- isEnu1D = false;
+ fIsDiag = true;
+ fIsRawEvents = true;
+ fIsEnu1D = false;
fDefaultTypes="EVT/SHAPE/DIAG";
fAllowedTypes="EVT/SHAPE/DIAG";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/NC1ppim/ANL_NC1ppim_cosMuStar.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
// Set Poisson errors on data points (number of events weighted)
- for (int i = 0; i < dataHist->GetNbinsX()+1; ++i) {
- dataHist->SetBinError(i+1, sqrt(dataHist->GetBinContent(i+1)));
+ for (int i = 0; i < fDataHist->GetNbinsX()+1; ++i) {
+ fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
- this->scaleFactor = this->eventHist->Integral("width")/((nevents+0.)*fluxHist->Integral("width"))*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")/((fNEvents+0.)*fFluxHist->Integral("width"))*(16./8.);
};
void ANL_NC1ppim_Evt_1DcosmuStar_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = event->PartInfo(0)->fP;
TLorentzVector Pin = event->PartInfo(1)->fP;
TLorentzVector Pp;
TLorentzVector Ppim;
TLorentzVector PnuOut;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0 && (event->PartInfo(j)->fStatus != 2)) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == -211) {
Ppim = event->PartInfo(j)->fP;
} else if (PID == 2212) {
Pp = event->PartInfo(j)->fP;
} else if (PID == 14) {
PnuOut = event->PartInfo(j)->fP;
}
}
// Boost into centre of mass frame
TLorentzVector CMS = Pnu + Pin;
// Boost outgoing neutrino backwards CMS
PnuOut.Boost(-CMS.BoostVector());
// Boost incoming neutrino forwards by CMS
Pnu.Boost(CMS.BoostVector());
double cosmuStar = cos(FitUtils::th(PnuOut, Pnu));
- this->X_VAR = cosmuStar;
+ this->fXVar = cosmuStar;
return;
};
bool ANL_NC1ppim_Evt_1DcosmuStar_nu::isSignal(FitEvent *event) {
// Incoming particle should be a neutrino
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
// Outgoing particle should be a neutrino
if (((event->PartInfo(2))->fPID != 14) && ((event->PartInfo(3))->fPID != 14)) return false;
int pimCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == -211) {
pimCnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false; // require only three prong events! (allow photons?)
}
}
// don't think there's away of implementing spectator proton cuts in NEUT?
// 100 MeV or larger protons
if (pimCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
diff --git a/src/ANL/ANL_NC1ppim_XSec_1DEnu_nu.cxx b/src/ANL/ANL_NC1ppim_XSec_1DEnu_nu.cxx
index 8a6f194..1b5c4d5 100644
--- a/src/ANL/ANL_NC1ppim_XSec_1DEnu_nu.cxx
+++ b/src/ANL/ANL_NC1ppim_XSec_1DEnu_nu.cxx
@@ -1,91 +1,91 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "ANL_NC1ppim_XSec_1DEnu_nu.h"
/**
* M. Derrick et al., "Study of the reaction \nu n \rightarrow \nu p \pi^-", Physics Letters, Volume 92B, Number 3,4, 363, 19 May 1980
*/
ANL_NC1ppim_XSec_1DEnu_nu::ANL_NC1ppim_XSec_1DEnu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile) {
- measurementName = "ANL_NC1ppim_XSec_1DEnu_nu";
- plotTitles = "; E_{#nu};#sigma(E_{#nu}) (cm^{2}/nucleon)";
+ fName = "ANL_NC1ppim_XSec_1DEnu_nu";
+ fPlotTitles = "; E_{#nu};#sigma(E_{#nu}) (cm^{2}/nucleon)";
EnuMin = 0.3;
EnuMax = 1.5;
- isDiag = true;
- isRawEvents = false;
- isEnu1D = true;
+ fIsDiag = true;
+ fIsRawEvents = false;
+ fIsEnu1D = true;
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/ANL/NC1ppim/ANL_NC1ppim_Enu_xsec.csv");
this->SetupDefaultHist();
- fullcovar = StatUtils::MakeDiagonalCovarMatrix(dataHist);
- covar = StatUtils::GetInvert(fullcovar);
+ fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
+ covar = StatUtils::GetInvert(fFullCovar);
// Scale to cross-section
- dataHist->Scale(1.E-41);
+ fDataHist->Scale(1.E-41);
- this->scaleFactor = this->eventHist->Integral("width")/((nevents+0.)*fluxHist->Integral("width"))*(16./8.);
+ this->fScaleFactor = this->fEventHist->Integral("width")/((fNEvents+0.)*fFluxHist->Integral("width"))*(16./8.);
};
void ANL_NC1ppim_XSec_1DEnu_nu::FillEventVariables(FitEvent *event) {
// Very simple here!
double Enu = ((event->PartInfo(0))->fP).E()/1000.;
- this->X_VAR = Enu;
+ this->fXVar = Enu;
return;
};
bool ANL_NC1ppim_XSec_1DEnu_nu::isSignal(FitEvent *event) {
// Incoming particle should be a neutrino
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
// Outgoing particle should be a neutrino
if (((event->PartInfo(2))->fPID != 14) && ((event->PartInfo(3))->fPID != 14)) return false;
int pimCnt = 0;
int protonCnt = 0;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == -211) {
pimCnt++;
} else if (PID == 2212) {
protonCnt++;
} else {
return false; // require only three prong events! (allow photons?)
}
}
// don't think there's away of implementing spectator proton cuts in NEUT?
// 100 MeV or larger protons
if (pimCnt != 1) return false;
if (protonCnt != 1) return false;
return true;
}
diff --git a/src/BNL/BNL_CC1npip_Evt_1DQ2_nu.cxx b/src/BNL/BNL_CC1npip_Evt_1DQ2_nu.cxx
index b1b64e2..42492ad 100644
--- a/src/BNL/BNL_CC1npip_Evt_1DQ2_nu.cxx
+++ b/src/BNL/BNL_CC1npip_Evt_1DQ2_nu.cxx
@@ -1,153 +1,153 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "BNL_CC1npip_Evt_1DQ2_nu.h"
// The constructor
BNL_CC1npip_Evt_1DQ2_nu::BNL_CC1npip_Evt_1DQ2_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile) {
fName = "BNL_CC1npip_Evt_1DQ2_nu";
fPlotTitles = "; Q^{2}_{CC#pi} (GeV^{2}); Number of events";
EnuMin = 0.;
EnuMax = 3.;
- isDiag = true;
- isRawEvents = true;
+ fIsDiag = true;
+ fIsRawEvents = true;
fAllowedTypes += "EVT";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/BNL/CC1pip_on_n/BNL_CC1pip_on_n_noEvents_q2_noWcut_firstQ2gone.txt");
this->SetupDefaultHist();
// set Poisson errors on fDataHist (scanned does not have this)
// Simple counting experiment here
for (int i = 0; i < fDataHist->GetNbinsX() + 1; i++) {
fDataHist->SetBinError(i+1, sqrt(fDataHist->GetBinContent(i+1)));
}
fFullCovar = StatUtils::MakeDiagonalCovarMatrix(fDataHist);
covar = StatUtils::GetInvert(fFullCovar);
this->fScaleFactor = this->fEventHist->Integral("width")/(fNEvents+0.)*16./8.;
};
void BNL_CC1npip_Evt_1DQ2_nu::FillEventVariables(FitEvent *event) {
// set up the 4-vectors from NEUT
TLorentzVector Pnu = event->PartInfo(0)->fP;
TLorentzVector Pn;
TLorentzVector Ppip;
TLorentzVector Pmu;
// Loop over the particle stack to find relevant particles
// start at 2 because 0=nu, 1=nucleon, by NEUT default
for (UInt_t j = 2; j < event->Npart(); ++j) {
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0) continue; //move on if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 211) {
Ppip = event->PartInfo(j)->fP;
} else if (PID == 2112) {
Pn = event->PartInfo(j)->fP;
} else if (PID == 13) {
Pmu = (event->PartInfo(j))->fP;
}
}
// double hadMass = FitUtils::MpPi(Pn, Ppip);
// no hadronic mass constraint in BNL CC1n1pi+
double q2CCpip = FitUtils::Q2CC1piprec(Pnu, Pmu, Ppip);
fXVar = q2CCpip;
return;
};
bool BNL_CC1npip_Evt_1DQ2_nu::isSignal(FitEvent *event) {
if ((event->PartInfo(0))->fPID != 14) return false;
if (((event->PartInfo(0))->fP.E() < this->EnuMin*1000.) || ((event->PartInfo(0))->fP.E() > this->EnuMax*1000.)) return false;
if (((event->PartInfo(2))->fPID != 13) && ((event->PartInfo(3))->fPID != 13)) return false;
int pipCnt = 0;
int lepCnt = 0;
int neutronCnt = 0;
TLorentzVector Pnu = (event->PartInfo(0))->fP;
TLorentzVector Pmu;
TLorentzVector Ppip;
TLorentzVector Pn;
for (UInt_t j = 2; j < event->Npart(); j++) {
if (!((event->PartInfo(j))->fIsAlive) && (event->PartInfo(j))->fStatus != 0) continue; //move to next particle if NOT ALIVE and NOT NORMAL
int PID = (event->PartInfo(j))->fPID;
if (PID == 13) {
lepCnt++;
Pmu = (event->PartInfo(j))->fP;
}
else if (PID == 211) {
pipCnt++;
Ppip = (event->PartInfo(j))->fP;
}
else if (PID == 2112) {
neutronCnt++;
Pn = (event->PartInfo(j))->fP;
}
else
return false; // require only three prong events! (allow photons?)
}
// don't think there's away of implementing spectator proton cuts in NEUT?
// 100 MeV or larger protons
if (pipCnt != 1) return false;
if (lepCnt != 1) return false;
if (neutronCnt != 1) return false;
// No further requirements from what I can see
return true;
}
/*
void BNL_CC1npip_Evt_1DQ2_nu::FillHistograms() {
if (makeHadronicMassHist) {
hadMassHist->Fill(hadMass);
}
Measurement1D::FillHistograms();
}
void BNL_CC1npip_Evt_1DQ2_nu::ScaleEvents() {
PlotUtils::FluxUnfoldedScaling(fMCHist, fFluxHist);
PlotUtils::FluxUnfoldedScaling(fMCFine, fFluxHist);
fMCHist->Scale(fScaleFactor);
fMCFine->Scale(fScaleFactor);
return;
}
*/
diff --git a/src/FitBase/FitWeight.cxx b/src/FitBase/FitWeight.cxx
index 02cde00..303ef6b 100644
--- a/src/FitBase/FitWeight.cxx
+++ b/src/FitBase/FitWeight.cxx
@@ -1,1457 +1,1452 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "FitWeight.h"
//********************************************************************
FitWeight::FitWeight(std::string name, std::string inputfile) {
//********************************************************************
// To be completed...
this->fName = name;
this->fNormEnum = 0;
this->fDialEnums.clear();
this->fDialNames.clear();
this->fDialValues.clear();
this->fIsUsingNeut = false;
this->fIsUsingNIWG = false;
this->fIsUsingNuwro = false;
this->fIsUsingGenie = false;
this->fIsUsingT2K = false;
fSplineHead = NULL;
this->fName = name;
// If file is a root file read it
if (inputfile.find(".root") != std::string::npos) {
// Open File
// Get Fit Result Tree
// Get Parameter Names and Types
// Add Parameter Results
// If file is a card file read it
} else {
// Parse Card Lines
// Parse Card Inputs
// Setup RW Dials
}
}
//********************************************************************
FitWeight::FitWeight(std::string name) {
//********************************************************************
this->fNormEnum = 0;
this->fDialEnums.clear();
this->fDialNames.clear();
this->fDialValues.clear();
this->fIsUsingNeut = false;
this->fIsUsingNIWG = false;
this->fIsUsingNuwro = false;
this->fIsUsingGenie = false;
this->fIsUsingT2K = false;
fIsUsingModeNorm = false;
fSplineHead = NULL;
this->fName = name;
std::cout << "Creating FitWeight norm enum = " << this->fNormEnum
<< std::endl;
}
//********************************************************************
int FitWeight::GetDialEnum(std::string name, int type) {
//********************************************************************
if (type == -1) {
return fDialEnums[this->GetDialPos(name)];
}
int offset = type * 1000;
int this_enum = -1;
switch (type) {
// NEUT DIAL TYPE
case kNEUT: {
#ifdef __NEUT_ENABLED__ // --- NEUT BLOCK
int neut_enum = (int)neut::rew::NSyst::FromString(name);
if (neut_enum != 0){
this_enum = neut_enum + offset;
}
#else
ERR(FTL) << "NEUT RW Not Enabled!" << endl;
throw;
#endif
break;
}
// NIWG DIAL TYPE
case kNIWG: {
#ifdef __NIWG_ENABLED__ // --- NIWG BLOCK
int niwg_enum = (int)niwg::rew::NIWGSyst::FromString(name);
this_enum = niwg_enum + offset;
#else
ERR(FTL) << "NIWG RW Not Enabled!" << endl;
throw;
#endif
break;
}
// NUWRO DIAL TYPE
case kNUWRO: {
#ifdef __NUWRO_REWEIGHT_ENABLED__ // --- NUWRO BLOCK
int nuwro_enum = (int)nuwro::rew::NuwroSyst::FromString(name);
if (nuwro_enum <= 0){
ERR(FTL) << "Uknown NuWro RW Parameter!" << endl;
ERR(FTL) << "Check '"
<< name
<< "' matches that in NuWroSyst.h"
<< endl;
throw;
}
this_enum = nuwro_enum + offset;
#else
ERR(FTL) << "NUWRO RW Not Enabled!" << endl;
throw;
#endif
break;
}
// GENIE DIAL TYPE
case kGENIE: {
#ifdef __GENIE_ENABLED__
int genie_enum = (int)genie::rew::GSyst::FromString(name);
this_enum = genie_enum + offset;
#else
ERR(FTL) << "GENIE RW Not Enabled!" << endl;
throw;
#endif
break;
}
case kCUSTOM: {
int custom_enum = 0; // PLACEHOLDER
this_enum = custom_enum + offset;
break;
}
// T2K DIAL TYPE
case kT2K: {
#ifdef __T2KREW_ENABLED__
int t2k_enum = (int)t2krew::T2KSyst::FromString(name);
this_enum = t2k_enum + offset;
#else
ERR(FTL) << "T2K RW Not Enabled!" << endl;
throw;
#endif
break;
}
// NORM DIAL TYPE
case kNORM: {
this_enum = fNormEnum + offset;
fNormEnum++;
break;
}
case kMODENORM: {
size_t us_pos = name.find_first_of('_');
std::string numstr = name.substr(us_pos + 1);
int mode_num = std::atoi(numstr.c_str());
if (!mode_num) {
ERR(FTL) << "Attempting to parse dial name: \"" << name
<< "\" as a mode norm dial but failed." << endl;
throw;
}
this_enum = 60 + mode_num + offset;
break;
}
// UNKOWN DIAL TYPE
default: {
ERR(FTL) << " Uknown dial type found = " << type << " " << kNORM << endl;
// throw; // Don't throw so fitter puts out its name
}
}
return this_enum;
}
//********************************************************************
int FitWeight::GetRWEnum(int this_enum) {
//********************************************************************
return (this_enum % 1000);
}
//********************************************************************
unsigned int FitWeight::GetDialPos(int this_enum) {
//********************************************************************
std::vector<int>::iterator enIter = fDialEnums.begin();
unsigned int count = 0;
for (; enIter != fDialEnums.end(); enIter++) {
if (((int)(*enIter)) == this_enum) {
return count;
}
count++;
}
std::cerr << "No Value saved for ENUM " << this_enum << std::endl;
exit(-1);
return -1;
}
//********************************************************************
bool FitWeight::DialIncluded(std::string name){
//********************************************************************
std::vector<std::string>::iterator naIter = fDialNames.begin();
bool found = false;
for (; naIter != fDialNames.end(); naIter++) {
if (((std::string)(*naIter)) == name) {
found = true;
break;
}
}
return found;
}
//********************************************************************
unsigned int FitWeight::GetDialPos(std::string name) {
//********************************************************************
std::vector<std::string>::iterator naIter = fDialNames.begin();
unsigned int count = 0;
for (; naIter != fDialNames.end(); naIter++) {
if (((std::string)(*naIter)) == name) {
return count;
}
count++;
}
std::cerr << "No Value saved for Dial Name " << name << std::endl;
exit(-1);
return -1;
}
//********************************************************************
void FitWeight::IncludeDial(std::string name, int type, double startval) {
//********************************************************************
int this_enum = this->GetDialEnum(name, type);
int rw_enum = this->GetRWEnum(this_enum);
LOG(FIT) << "Including dial " << name << " [type, rw_enum, fit_enum] = ["
<< generator_event_type(type) << ", " << rw_enum << ", " << this_enum
<< "] " << std::endl;
int id = int(this_enum - (this_enum % 1000)) / 1000;
if (id == kNORM) startval = 1.0;
switch (id) {
// NEUT RW INCLUDE DIAL
case kNEUT:
#ifdef __NEUT_ENABLED__
if (!fIsUsingNeut) this->SetupNeutRW();
this->fNeutRW->Systematics().Init(
static_cast<neut::rew::NSyst_t>(rw_enum));
break;
#else
ERR(FTL) << "NEUT RW Not Enabled!" << endl;
throw;
#endif
// NIWG RW INCLUDE DIAL
case kNIWG:
#ifdef __NIWG_ENABLED__
if (!fIsUsingNIWG) this->SetupNIWGRW();
this->fNIWGRW->Systematics().Init(
static_cast<niwg::rew::NIWGSyst_t>(rw_enum));
break;
#else
ERR(FTL) << "NIWG RW Not Enabled!" << endl;
throw;
#endif
// NUWRO RW INCLUDE DIAL
case kNUWRO:
#ifdef __NUWRO_REWEIGHT_ENABLED__
if (!fIsUsingNuwro) this->SetupNuwroRW();
this->fNuwroRW->Systematics().Add(
static_cast<nuwro::rew::NuwroSyst_t>(rw_enum));
break;
#else
LOG(FTL) << "Trying to Include NuWro Dial is unsupported!" << std::endl;
throw;
#endif
// GENIE RW INCLUDE DIAL
case kGENIE:
#ifdef __GENIE__ENABLED__
if (!fIsUsingGenie) this->SetupGenieRW();
this->fGenieRW->Systematics().Add(
static_cast<genie::rew::GSyst_t>(rw_enum));
break;
#else
ERR(FTL) << "Trying to Include GENIE Dial is unsupported!" << std::endl;
throw;
#endif
// T2K RW INCLUDE DIAL
case kT2K:
#ifdef __T2KREW_ENABLED__
if (!fIsUsingT2K) this->SetupT2KRW();
this->fT2KRW->Systematics().Include(static_cast<t2krew::T2KSyst_t>(rw_enum));
break;
#else
ERR(FTL) << "Trying to Include T2K Dial is unsupported!" << std::endl;
throw;
#endif
// SAMPLE NORM DIAL
case kNORM:
break;
case kMODENORM:
break;
default:
ERR(FTL) << " Trying to include dial of unkown type " << name
<< " == " << type << endl;
break;
}
// Setup ENUMS
fDialEnums.push_back(this_enum);
fDialNames.push_back(name);
fDialValues.push_back(startval);
fDialFuncs.push_back(FitBase::GetRWConvFunction(GetDialType(this_enum), name));
fDialUnits.push_back(FitBase::GetRWUnits(GetDialType(this_enum), name));
// Set Values
this->SetDialValue(this_enum, startval);
return;
}
//********************************************************************
void FitWeight::SetDialValue(std::string name, double val) {
//********************************************************************
int this_enum = this->GetDialEnum(name);
this->SetDialValue(this_enum, val);
}
//********************************************************************
void FitWeight::SetDialValue(int this_enum, double val) {
//*********************************************************************
fIsDialChanged = true;
int rw_enum = GetRWEnum(this_enum);
unsigned int pos = GetDialPos(this_enum);
LOG(DEB) << "Setting dial value " << this_enum << " to " << val << std::endl;
// -- DIAL BLOCKS
int id = int(this_enum - (this_enum % 1000)) / 1000;
switch (id) {
case kNEUT: {
#ifdef __NEUT_ENABLED__ // --- NEUT BLOCK
this->fNeutRW->Systematics().Set(static_cast<neut::rew::NSyst_t>(rw_enum),
val);
this->fIsNeutChanged = true;
#else
LOG(FTL) << " NEUT DIAL ERROR " << std::endl;
#endif
break;
}
case kNIWG: {
#ifdef __NIWG_ENABLED__
this->fNIWGRW->Systematics().Set(
static_cast<niwg::rew::NIWGSyst_t>(rw_enum), val);
this->fIsNIWGChanged = true;
#else
LOG(FTL) << " NIWG DIAL ERROR " << std::endl;
#endif
break;
}
case kNUWRO: {
#ifdef __NUWRO_REWEIGHT_ENABLED__
fNuwroRW->Systematics().SetSystVal(
static_cast<nuwro::rew::NuwroSyst_t>(rw_enum), val);
this->fIsNuwroChanged = true;
#else
LOG(FTL) << " NUWRO DIAL ERROR " << std::endl;
#endif
break;
}
case kGENIE: {
#ifdef __GENIE_ENABLED__
fGenieRW->Systematics().Set(static_cast<genie::rew::GSyst_t>(rw_enum),
val);
this->fIsGenieChanged = true;
#else
LOG(FTL) << " GENIE DIAL ERROR " << std::endl;
#endif
break;
}
case kT2K: {
#ifdef __T2KREW_ENABLED__
fT2KRW->Systematics().SetTwkDial(static_cast<t2krew::T2KSyst_t>(rw_enum),
val);
this->fIsT2KChanged = true;
#else
LOG(FTL) << " T2K DIAL ERROR " << std::endl;
#endif
break;
}
case kCUSTOM:
case kNORM: {
break;
}
case kMODENORM: {
this->fIsUsingModeNorm = true;
break;
}
default: {
LOG(FTL) << "Dial type error: " << generator_event_type(id) << std::endl;
throw;
}
}
fDialValues[pos] = val;
return;
}
//********************************************************************
void FitWeight::Reconfigure(bool silent) {
//********************************************************************
if ((fIsUsingNeut or fIsUsingNIWG) and fIsUsingT2K) {
ERR(WRN) << " Make sure no correlated or overlapping dials are being used "
"between T2KRW and NEUT/NIWG RW"
<< std::endl;
}
if (!fIsDialChanged) return;
if (!silent and LOG_LEVEL(MIN)) this->PrintState();
#ifdef __NEUT_ENABLED__ // --- NEUT BLOCK
if (fIsNeutChanged and fIsUsingNeut){ fNeutRW->Reconfigure(); }
#endif
#ifdef __NIWG_ENABLED__ // --- NIWG BLOCK
if (fIsNIWGChanged and fIsUsingNIWG) fNIWGRW->Reconfigure();
#endif
#ifdef __NUWRO_REWEIGHT_ENABLED__ // --- NUWRO BLOCK
if (fIsNuwroChanged and fIsUsingNuwro) fNuwroRW->Reconfigure();
#endif
#ifdef __GENIE_ENABLED__
if (fIsGenieChanged and fIsUsingGenie) fGenieRW->Reconfigure();
#endif
#ifdef __T2KREW_ENABLED__
if (fIsT2KChanged and fIsUsingT2K) fT2KRW->Reconfigure();
#endif
fIsDialChanged = false;
fIsNeutChanged = false;
fIsNIWGChanged = false;
fIsNuwroChanged = false;
fIsGenieChanged = false;
fIsT2KChanged = false;
return;
}
//********************************************************************
void FitWeight::PrintState() {
//********************************************************************
LOG(MIN) << "-----------------------" << std::endl;
LOG(MIN) << this->fName << " Cur. State:" << std::endl;
// Loop over the Dials and print some info
for (unsigned int i = 0; i < fDialNames.size(); i++) {
std::string name = fDialNames.at(i);
int this_enum = fDialEnums.at(i);
double val = fDialValues.at(i);
std::string type = GetDialType(this_enum);
if (FitPar::Config().GetParB("convert_dials")) {
double val = fDialFuncs.at(i).Eval(fDialValues.at(i));
LOG(MIN) << "-> " << std::setw(2) << i << ". " << std::setw(10) << type + "_par. ";
std::cout << std::setw(40) << fDialNames.at(i) << std::setw(5) << " = " << val
<< " " << fDialUnits.at(i) << std::endl;
} else {
(void)val;
LOG(MIN) << "-> " << std::setw(2) << i << ". " << std::setw(10) << type + "_par. ";
std::cout << std::setw(40) << std::left << fDialNames.at(i) << std::setw(5)
<< " = " << fDialValues.at(i) << " " << fDialUnits.at(i) << std::endl;
}
}
LOG(MIN) << "-----------------------" << std::endl;
}
//********************************************************************
std::string FitWeight::GetDialType(int this_enum) {
//********************************************************************
int id = int(this_enum - (this_enum % 1000)) / 1000;
switch (id) {
case kNEUT: {
return "neut";
}
case kNIWG: {
return "niwg";
}
case kGENIE: {
return "genie";
}
case kT2K: {
return "t2k";
}
case kCUSTOM: {
return "custom";
}
case kNORM: {
return "norm";
}
case kMODENORM: {
return "modenorm";
}
default: { return "unknown"; }
}
}
//********************************************************************
double FitWeight::CalcWeight(BaseFitEvt* evt) {
//********************************************************************
double rw_weight = 1.0;
// SPLINE WEIGHTS
if (evt->fType == kEVTSPLINE) {
rw_weight = this->CalcSplineWeight(evt);
evt->Weight = rw_weight;
return rw_weight;
};
// GENERATOR WEIGHTS
if (fIsDialChanged) this->Reconfigure();
rw_weight = 1.0;
switch (evt->fType) {
#ifdef __NEUT_ENABLED__ // --- NEUT BLOCK
case kNEUT:
if (fIsUsingNeut) {
GeneratorUtils::FillNeutCommons(evt->fNeutVect);
rw_weight *= fNeutRW->CalcWeight();
}
#ifdef __NIWG_ENABLED__ // --- NIWG BLOCK
if (fIsUsingNIWG) {
niwg::rew::NIWGEvent* niwg_event =
GeneratorUtils::GetNIWGEvent(evt->fNeutVect);
rw_weight *= fNIWGRW->CalcWeight(*niwg_event);
delete niwg_event;
}
#endif
#ifdef __T2KREW_ENABLED__
if (fIsUsingT2K) {
rw_weight *= fT2KRW->CalcWeight(evt->fNeutVect);
}
#endif
break;
#endif
#ifdef __NUWRO_REWEIGHT_ENABLED__
case kNUWRO:
if (fIsUsingNuwro) {
rw_weight *= fNuwroRW->CalcWeight(evt->fNuwroEvent);
}
break;
#endif
#ifdef __GENIE_ENABLED__
case kGENIE:
if (fIsUsingGenie) {
rw_weight *= fGenieRW->CalcWeight(*(evt->genie_event->event));
}
#endif
default:
break;
}
if (fIsUsingModeNorm) {
for (size_t de_it = 0; de_it < fDialEnums.size(); ++de_it) {
int this_enum = fDialEnums[de_it];
if ((int(this_enum - (this_enum % 1000)) / 1000) != kMODENORM) {
continue;
}
if (evt->Mode == (GetRWEnum(this_enum) - 60)) {
rw_weight *= fDialValues[de_it];
}
}
}
evt->Weight = rw_weight;
return rw_weight;
}
//********************************************************************
#ifdef __NEUT_ENABLED__
void FitWeight::SetupNeutRW() {
//********************************************************************
LOG(FIT) << "Setting up NEUT RW" << endl;
fIsUsingNeut = true;
fIsNeutChanged = true;
// Create RW Engine
fNeutRW = new neut::rew::NReWeight();
// get list of vetoed calc engines (just for debug really)
std::string rw_engine_list =
FitPar::Config().GetParS("FitWeight.fNeutRW_veto");
bool xsec_ccqe = rw_engine_list.find("xsec_ccqe") == std::string::npos;
bool xsec_res = rw_engine_list.find("xsec_res") == std::string::npos;
bool xsec_ccres = rw_engine_list.find("xsec_ccres") == std::string::npos;
bool xsec_coh = rw_engine_list.find("xsec_coh") == std::string::npos;
bool xsec_dis = rw_engine_list.find("xsec_dis") == std::string::npos;
bool xsec_ncel = rw_engine_list.find("xsec_ncel") == std::string::npos;
bool xsec_nc = rw_engine_list.find("xsec_nc") == std::string::npos;
bool xsec_ncres = rw_engine_list.find("xsec_ncres") == std::string::npos;
bool nucl_casc = rw_engine_list.find("nucl_casc") == std::string::npos;
bool nucl_piless = rw_engine_list.find("nucl_piless") == std::string::npos;
// Activate each calc engine
if (xsec_ccqe)
fNeutRW->AdoptWghtCalc("xsec_ccqe", new neut::rew::NReWeightNuXSecCCQE);
if (xsec_res)
fNeutRW->AdoptWghtCalc("xsec_res", new neut::rew::NReWeightNuXSecRES);
if (xsec_ccres)
fNeutRW->AdoptWghtCalc("xsec_ccres", new neut::rew::NReWeightNuXSecCCRES);
if (xsec_coh)
fNeutRW->AdoptWghtCalc("xsec_coh", new neut::rew::NReWeightNuXSecCOH);
if (xsec_dis)
fNeutRW->AdoptWghtCalc("xsec_dis", new neut::rew::NReWeightNuXSecDIS);
if (xsec_ncel)
fNeutRW->AdoptWghtCalc("xsec_ncel", new neut::rew::NReWeightNuXSecNCEL);
if (xsec_nc)
fNeutRW->AdoptWghtCalc("xsec_nc", new neut::rew::NReWeightNuXSecNC);
if (xsec_ncres)
fNeutRW->AdoptWghtCalc("xsec_ncres", new neut::rew::NReWeightNuXSecNCRES);
if (nucl_casc)
fNeutRW->AdoptWghtCalc("nucl_casc", new neut::rew::NReWeightCasc);
if (nucl_piless)
fNeutRW->AdoptWghtCalc("nucl_piless", new neut::rew::NReWeightNuclPiless);
fNeutRW->Reconfigure();
}
#endif
//********************************************************************
#ifdef __NIWG_ENABLED__
void FitWeight::SetupNIWGRW() {
//********************************************************************
// EXTRA CHECK if NEUT is also enabled, just incase it was
// missed at build time.
#ifndef __NEUT_ENABLED__
ERR(FTL) << "Can't run NIWG event calculation without NEUT also enabled"
<< std::endl;
ERR(FTL) << "Check your build configuration!" << std::endl;
exit(-1);
#endif
// Now Setup the rw engine
LOG(FIT) << "Setting up NIWG RW" << std::endl;
fIsUsingNIWG = true;
fIsNIWGChanged = true;
// Create RW Engine
fNIWGRW = new niwg::rew::NIWGReWeight();
// Get List of Veto Calcs (For Debugging)
std::string rw_engine_list =
FitPar::Config().GetParS("FitWeight.fNIWGRW_veto");
bool niwg_2012a = rw_engine_list.find("niwg_2012a") == std::string::npos;
bool niwg_2014a = rw_engine_list.find("niwg_2014a") == std::string::npos;
bool niwg_pimult = rw_engine_list.find("niwg_pimult") == std::string::npos;
bool niwg_mec = rw_engine_list.find("niwg_mec") == std::string::npos;
bool niwg_rpa = rw_engine_list.find("niwg_rpa") == std::string::npos;
bool niwg_eff_rpa = rw_engine_list.find("niwg_eff_rpa") == std::string::npos;
bool niwg_proton =
rw_engine_list.find("niwg_protonFSIbug") == std::string::npos;
bool niwg_hadron =
rw_engine_list.find("niwg_HadronMultSwitch") == std::string::npos;
// Add the RW Calcs
if (niwg_2012a)
fNIWGRW->AdoptWghtCalc("niwg_2012a", new niwg::rew::NIWGReWeight2012a);
if (niwg_2014a)
fNIWGRW->AdoptWghtCalc("niwg_2014a", new niwg::rew::NIWGReWeight2014a);
if (niwg_pimult)
fNIWGRW->AdoptWghtCalc("niwg_pimult", new niwg::rew::NIWGReWeightPiMult);
if (niwg_mec)
fNIWGRW->AdoptWghtCalc("niwg_mec", new niwg::rew::NIWGReWeightMEC);
if (niwg_rpa)
fNIWGRW->AdoptWghtCalc("niwg_rpa", new niwg::rew::NIWGReWeightRPA);
if (niwg_eff_rpa)
fNIWGRW->AdoptWghtCalc("niwg_eff_rpa",
new niwg::rew::NIWGReWeightEffectiveRPA);
if (niwg_proton)
fNIWGRW->AdoptWghtCalc("niwg_protonFSIbug",
new niwg::rew::NIWGReWeightProtonFSIbug);
if (niwg_hadron)
fNIWGRW->AdoptWghtCalc("niwg_HadronMultSwitch",
new niwg::rew::NIWGReWeightHadronMultSwitch);
fNIWGRW->Reconfigure();
}
#endif
//********************************************************************
#ifdef __NUWRO_REWEIGHT_ENABLED__
void FitWeight::SetupNuwroRW() {
//********************************************************************
LOG(FIT) << "Setting up NUWRO RW" << std::endl;
fIsUsingNuwro = true;
fIsNuwroChanged = true;
// Create Engine
fNuwroRW = new nuwro::rew::NuwroReWeight();
// Get List of Veto Calcs (For Debugging)
std::string rw_engine_list =
FitPar::Config().GetParS("FitWeight.fNuwroRW_veto");
bool xsec_qel = rw_engine_list.find("nuwro_QEL") == std::string::npos;
bool xsec_flag = rw_engine_list.find("nuwro_FlagNorm") == std::string::npos;
bool xsec_res = rw_engine_list.find("nuwro_RES") == std::string::npos;
// Add the RW Calcs
if (xsec_qel)
fNuwroRW->AdoptWghtCalc("nuwro_QEL", new nuwro::rew::NuwroReWeight_QEL);
if (xsec_flag)
fNuwroRW->AdoptWghtCalc("nuwro_FlagNorm",
new nuwro::rew::NuwroReWeight_FlagNorm);
// if (xsec_res) fNuwroRW->AdoptWghtCalc( "nuwro_RES", new
// nuwro::rew::NuwroReWeight_SPP );
fNuwroRW->Reconfigure();
}
#endif
#ifdef __T2KREW_ENABLED__
//********************************************************************
void FitWeight::SetupT2KRW() {
//********************************************************************
LOG(FIT) << "Setting up T2K RW" << std::endl;
fIsUsingT2K = true;
fIsT2KChanged = true;
// Create Main RW Engine
fT2KRW = new t2krew::T2KReWeight();
// Setup Sub RW Engines (Only activated for neut and niwg)
fT2KNeutRW = new t2krew::T2KNeutReWeight();
fT2KNIWGRW = new t2krew::T2KNIWGReWeight();
fT2KRW->AdoptWghtEngine("fNeutRW", fT2KNeutRW);
fT2KRW->AdoptWghtEngine("fNIWGRW", fT2KNIWGRW);
fT2KRW->Reconfigure();
}
#endif
#ifdef __GENIE_ENABLED__
//********************************************************************
void FitWeight::SetupGenieRW() {
//********************************************************************
LOG(FIT) << "Setting up GENIE RW" << std::endl;
fIsUsingGenie = true;
fIsGenieChanged = true;
// Create Engine
GHepRecord::SetPrintLevel(-2);
fGenieRW = new genie::rew::GReWeight();
// Get List of Vetos (Just for debugging)
std::string rw_engine_list =
FitPar::Config().GetParS("FitWeight.fGenieRW_veto");
bool xsec_ncel = rw_engine_list.find("xsec_ncel") == std::string::npos;
bool xsec_ccqe = rw_engine_list.find("xsec_ccqe") == std::string::npos;
bool xsec_coh = rw_engine_list.find("xsec_coh") == std::string::npos;
bool xsec_nnres = rw_engine_list.find("xsec_nonresbkg") == std::string::npos;
bool xsec_nudis = rw_engine_list.find("nuclear_dis") == std::string::npos;
bool xsec_resdec =
rw_engine_list.find("hadro_res_decay") == std::string::npos;
bool xsec_fzone = rw_engine_list.find("hadro_intranuke") == std::string::npos;
bool xsec_intra = rw_engine_list.find("hadro_fzone") == std::string::npos;
bool xsec_agky = rw_engine_list.find("hadro_agky") == std::string::npos;
bool xsec_qevec = rw_engine_list.find("xsec_ccqe_vec") == std::string::npos;
bool xsec_dis = rw_engine_list.find("xsec_dis") == std::string::npos;
bool xsec_nc = rw_engine_list.find("xsec_nc") == std::string::npos;
bool xsec_ccres = rw_engine_list.find("xsec_ccres") == std::string::npos;
bool xsec_ncres = rw_engine_list.find("xsec_ncres") == std::string::npos;
bool xsec_nucqe = rw_engine_list.find("nuclear_qe") == std::string::npos;
// Now actually add the RW Calcs
if (xsec_ncel)
fGenieRW->AdoptWghtCalc("xsec_ncel", new genie::rew::GReWeightNuXSecNCEL);
if (xsec_ccqe)
fGenieRW->AdoptWghtCalc("xsec_ccqe", new genie::rew::GReWeightNuXSecCCQE);
if (xsec_coh)
fGenieRW->AdoptWghtCalc("xsec_coh", new genie::rew::GReWeightNuXSecCOH);
if (xsec_nnres)
fGenieRW->AdoptWghtCalc("xsec_nonresbkg",
new genie::rew::GReWeightNonResonanceBkg);
if (xsec_nudis)
fGenieRW->AdoptWghtCalc("nuclear_dis", new genie::rew::GReWeightDISNuclMod);
if (xsec_resdec)
fGenieRW->AdoptWghtCalc("hadro_res_decay",
new genie::rew::GReWeightResonanceDecay);
if (xsec_fzone)
fGenieRW->AdoptWghtCalc("hadro_fzone", new genie::rew::GReWeightFZone);
if (xsec_intra)
fGenieRW->AdoptWghtCalc("hadro_intranuke", new genie::rew::GReWeightINuke);
if (xsec_agky)
fGenieRW->AdoptWghtCalc("hadro_agky", new genie::rew::GReWeightAGKY);
if (xsec_qevec)
fGenieRW->AdoptWghtCalc("xsec_ccqe_vec",
new genie::rew::GReWeightNuXSecCCQEvec);
if (xsec_dis)
fGenieRW->AdoptWghtCalc("xsec_dis", new genie::rew::GReWeightNuXSecDIS);
if (xsec_nc)
fGenieRW->AdoptWghtCalc("xsec_nc", new genie::rew::GReWeightNuXSecNC);
if (xsec_ccres)
fGenieRW->AdoptWghtCalc("xsec_ccres", new genie::rew::GReWeightNuXSecCCRES);
if (xsec_ncres)
fGenieRW->AdoptWghtCalc("xsec_ncres", new genie::rew::GReWeightNuXSecNCRES);
if (xsec_nucqe)
fGenieRW->AdoptWghtCalc("nuclear_qe", new genie::rew::GReWeightFGM);
fGenieRW->Reconfigure();
}
#endif
//********************************************************************
double FitWeight::GetDialValue(std::string name, std::string option) {
//********************************************************************
int this_enum = this->GetDialEnum(name);
int this_pos = this->GetDialPos(this_enum);
double val = this->GetDialValue(this_enum);
if (!option.compare("ABS"))
return fDialFuncs[this_pos].Eval(val);
else if (!option.compare("FRC"))
return fDialFuncs[this_pos].Eval(val) / fDialFuncs[this_pos].Eval(0.0);
else
return val;
}
//********************************************************************
double FitWeight::GetDialValue(int this_enum) {
//********************************************************************
unsigned int pos = this->GetDialPos(this_enum);
return fDialValues.at(pos);
}
//********************************************************************
void FitWeight::UpdateWeightEngine(const double* x) {
//********************************************************************
this->SetAllDials(x, fDialEnums.size());
return;
}
//********************************************************************
bool FitWeight::HasRWDialChanged(const double* x) {
//********************************************************************
for (unsigned int i = 0; i < fDialValues.size(); i++) {
int rw_enum = fDialEnums.at(i);
int id = int(rw_enum - (rw_enum % 1000)) / 1000;
if (id == kNORM) continue;
if (x[i] != fDialValues.at(i)) return true;
}
return false;
}
//********************************************************************
void FitWeight::SetAllDials(const double* x, int npt) {
//********************************************************************
for (int i = 0; i < npt; i++) {
int this_enum = fDialEnums.at(i);
this->SetDialValue(this_enum, x[i]);
}
return;
};
//********************************************************************
void FitWeight::GetAllDials(double* x, int npt) {
//********************************************************************
for (int i = 0; i < npt; i++) {
int this_enum = fDialEnums.at(i);
x[i] = this->GetDialValue(this_enum);
}
return;
};
//********************************************************************
double FitWeight::GetSampleNorm(std::string samplename) {
//********************************************************************
std::string norm_dial = samplename + "_norm";
// Loop through and see if we have one
std::vector<std::string>::iterator naIter = fDialNames.begin();
bool found_dial = false;
for (; naIter != fDialNames.end(); naIter++) {
if (((std::string)(*naIter)) == norm_dial) {
found_dial = true;
break;
}
}
if (!found_dial && !samplename.empty()) {
LOG(FIT) << " Late initialisation of norm: " << norm_dial << std::endl;
this->IncludeDial(norm_dial, kNORM, 1.0);
this->Reconfigure();
return 1.0;
} else {
-<<<<<<< HEAD
- LOG(REC) << " Getting sample norm " << norm_dial << " = "
- << this->GetDialValue(norm_dial) << std::endl;
-=======
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
return this->GetDialValue(norm_dial);
}
}
//********************************************************************
std::vector<std::string> FitWeight::GetDialNames() {
//********************************************************************
return fDialNames;
}
//********************************************************************
std::vector<int> FitWeight::GetDialEnums() {
//********************************************************************
return fDialEnums;
}
//********************************************************************
std::vector<double> FitWeight::GetDialValues() {
//********************************************************************
return fDialValues;
}
//********************************************************************
void FitWeight::SetupEventCoeff(BaseFitEvt* event) {
//********************************************************************
if (!fSplineHead) fSplineHead = new FitSplineHead();
fSplineHead->SetupEventWeights(event);
}
//********************************************************************
void FitWeight::GenSplines(BaseFitEvt* event, bool save_graph) {
//********************************************************************
double nom = this->CalcWeight(event);
event->dial_coeff->SetAt(nom, 0);
// Get Current Dial Values and save to reset
std::list<FitSpline*>::iterator spl_iter = fSplineHead->SplineObjects.begin();
for (; spl_iter != fSplineHead->SplineObjects.end(); spl_iter++) {
FitSpline* spl = (*spl_iter);
int dim = spl->ndim;
// ND Splines
if (dim == 1)
this->Fit1DSplineCoeff(event, spl, nom, save_graph);
else if (dim == 2)
this->Fit2DSplineCoeff(event, spl, nom, save_graph);
else if (dim >= 3)
this->FitNDSplineCoeff(event, spl, nom, save_graph);
}
return;
}
//********************************************************************
void FitWeight::Fit2DSplineCoeff(BaseFitEvt* event, FitSpline* spl, double nom,
bool save_graph) {
//********************************************************************
int enum_x = spl->var_enums[0];
int enum_y = spl->var_enums[1];
double cur_x = this->GetDialValue(enum_x);
double cur_y = this->GetDialValue(enum_y);
// int npar = spl->npar;
std::vector<double> knots_x = spl->x_vals[0];
std::vector<double> knots_y = spl->x_vals[1];
int n_knots_x = knots_x.size();
int n_knots_y = knots_y.size();
double val_x = 0.0;
double val_y = 0.0;
int count = 0;
double weightval = 0.0;
bool hasresponse = false;
TGraph2D gr_2D_scan = TGraph2D(n_knots_x * n_knots_y);
// Loop over grid
for (std::vector<double>::iterator iter_x = knots_x.begin();
iter_x != knots_x.end(); iter_x++) {
// X RW Value
val_x = (*iter_x);
this->SetDialValue(enum_x, val_x);
this->Reconfigure(true);
for (std::vector<double>::iterator iter_y = knots_y.begin();
iter_y != knots_y.end(); iter_y++) {
// Y RW Value
val_y = (*iter_y);
this->SetDialValue(enum_y, val_y);
weightval = this->CalcWeight(event) / nom;
if (weightval != 1.0) hasresponse = true;
gr_2D_scan.SetPoint(count, val_x, val_y, weightval);
count++;
}
}
// Save GRAPH
if (hasresponse and save_graph) {
gr_2D_scan.SetName(
Form("SplineFit_%s_%s", spl->id.c_str(), spl->form.c_str()));
std::vector<std::string> titles =
PlotUtils::ParseToStr(spl->id, ",");
gr_2D_scan.SetTitle(Form("SplineFit_%s_%s;%s;%s;Weight Response",
spl->id.c_str(), spl->form.c_str(),
titles[0].c_str(), titles[1].c_str()));
gr_2D_scan.Write();
}
this->SetDialValue(enum_x, cur_x);
this->SetDialValue(enum_y, cur_y);
return;
}
//********************************************************************
void FitWeight::Fit1DSplineCoeff(BaseFitEvt* event, FitSpline* spl, double nom,
bool save_graph) {
//********************************************************************
int this_enum = spl->var_enums[0];
double current = this->GetDialValue(this_enum);
int npar = spl->npar;
std::vector<double> knots = spl->x_vals[0];
int n_knots = knots.size();
double val = 0.0;
double* allweights;
double* allvals;
allweights = new double[n_knots];
allvals = new double[n_knots];
int count = 0;
double weightval = 0.0;
bool hasresponse = false;
for (std::vector<double>::iterator iter = knots.begin(); iter != knots.end();
iter++) {
val = (*iter);
this->SetDialValue(this_enum, val);
this->Reconfigure(true);
weightval = this->CalcWeight(event) / nom;
if (weightval != 1.0) hasresponse = true;
allweights[count] = weightval;
allvals[count++] = val;
}
if (!hasresponse) {
event->dial_coeff->SetAt(-999.9, 1);
}
TGraph* gr = new TGraph(n_knots, &knots[0], allweights);
TF1* f1 =
new TF1("f1", spl, -1.0 + knots[0], 1.0 + knots[knots.size() - 1], npar);
if (save_graph and hasresponse) f1->SetNpx(400);
// Check for TSpline3
if (spl->needs_fit) {
gr->Fit(f1, "WQM");
for (int i = 0; i < npar; i++) {
event->dial_coeff->SetAt(f1->GetParameter(i), i + spl->offset);
}
} else {
std::vector<double> dial_coeff = spl->GetSplineCoeff(allweights);
for (int i = 0; i < npar; i++) {
event->dial_coeff->SetAt(dial_coeff[i], i + spl->offset);
f1->FixParameter(i, dial_coeff[i]);
}
gr->Fit(f1, "WQM");
}
if (save_graph and hasresponse) {
TSpline3* spl3 =
new TSpline3(Form("Spline3_dial%i_%s_%s;%s;Weight Response", this_enum,
spl->id.c_str(), spl->form.c_str(), spl->id.c_str()),
&knots[0], allweights, n_knots);
TCanvas* c3 = new TCanvas("c3", "c3", 800, 600);
c3->cd();
spl3->SetLineColor(kBlue);
spl3->Draw("C");
gr->SetTitle(Form("SplineFit_dial%i_%s_%s;%s;Weight Response", this_enum,
spl->id.c_str(), spl->form.c_str(), spl->id.c_str()));
gr->SetMarkerStyle(22);
gr->SetName(Form("SplineFit_dial%i_%s_%s", this_enum, spl->id.c_str(),
spl->form.c_str()));
gr->Write();
gr->Draw("SAME P");
f1->Draw("SAME C");
c3->Update();
c3->Write(Form("Spline3_dial%i_%s_%s;%s;Weight Response", this_enum,
spl->id.c_str(), spl->form.c_str(), spl->id.c_str()));
delete c3;
delete spl3;
}
delete gr;
delete f1;
delete allweights;
this->SetDialValue(this_enum, current);
}
//********************************************************************
void FitWeight::ReadSplineHead(FitSplineHead* splhead) {
//********************************************************************
fSplineHead = splhead;
fSplineHead->Reconfigure(this->fDialEnums, this->fDialValues);
}
//********************************************************************
void FitWeight::SetupSpline(std::string dialname, std::string splinename,
std::string points_def) {
//********************************************************************
// Create spline head if none setup
if (!fSplineHead) fSplineHead = new FitSplineHead();
// Parse Enum Mapping
std::vector<std::string> parsed_dials =
PlotUtils::ParseToStr(dialname, ",");
std::vector<int> list_enums;
for (UInt_t i = 0; i < parsed_dials.size(); i++) {
list_enums.push_back(this->GetDialEnum(parsed_dials.at(i)));
}
// Add new spline
FitSpline* spl = new FitSpline(dialname, splinename, list_enums, points_def);
fSplineHead->AddSpline(spl);
return;
}
//********************************************************************
void FitWeight::ResetSplines() {
//********************************************************************
delete fSplineHead;
fSplineHead = NULL;
}
//********************************************************************
double FitWeight::CalcSplineWeight(BaseFitEvt* evt) {
//********************************************************************
double rw_weight = fSplineHead->CalcWeight(evt->dial_coeff->GetArray());
return rw_weight;
}
//********************************************************************
bool FitWeight::HasDialChanged() {
//********************************************************************
return fIsDialChanged;
};
// Global Conversion Functions
// ---------------------------
//********************************************************************
TF1 FitBase::GetRWConvFunction(std::string type, std::string name) {
//********************************************************************
std::string dialfunc = "x";
std::string parType = type;
double low = -10000.0;
double high = 10000.0;
if (parType.find("parameter") == std::string::npos) parType += "_parameter";
string line;
ifstream card(
(string(getenv("EXT_FIT")) + "/parameters/dial_conversion.card").c_str(),
ifstream::in);
while (getline(card, line, '\n')) {
istringstream stream(line);
string token, parname;
int val = 0;
double entry;
if (line.c_str()[0] == '#') continue;
while (getline(stream, token, ' ')) {
stream >> ws;
istringstream stoken(token);
stoken >> entry;
if (val == 0) {
if (token.compare(parType) != 0) {
break;
}
} else if (val == 1) {
if (token.compare(name) != 0) {
break;
}
} else if (val == 2) {
} else if (val == 3) {
dialfunc = token;
} else if (val == 3) {
} else if (val == 4) {
low = entry;
} else if (val == 5) {
high = entry;
} else
break;
val++;
}
}
TF1 convfunc = TF1((name + "_convfunc").c_str(), dialfunc.c_str(), low, high);
return convfunc;
}
//********************************************************************
std::string FitBase::GetRWUnits(std::string type, std::string name) {
//********************************************************************
std::string unit = "sig.";
std::string parType = type;
if (parType.find("parameter") == std::string::npos) {
parType += "_parameter";
}
std::string line;
ifstream card((string(getenv("EXT_FIT")) + "/parameters/dial_conversion.card").c_str(), ifstream::in);
while (getline(card, line, '\n')) {
istringstream stream(line);
string token, parname;
int val = 0;
double entry;
if (line.c_str()[0] == '#') continue;
while (getline(stream, token, ' ')) {
stream >> ws;
istringstream stoken(token);
stoken >> entry;
if (val == 0) {
if (token.compare(parType) != 0) {
break;
}
} else if (val == 1) {
if (token.compare(name) != 0) {
break;
}
} else if (val == 2) {
unit = token;
} else if (val == 3) {
} else if (val == 4) {
} else if (val == 5) {
} else
break;
val++;
}
}
return unit;
}
//********************************************************************
double FitBase::RWAbsToSigma(std::string type, std::string name, double val) {
//********************************************************************
TF1 f1 = GetRWConvFunction(type, name);
double conv_val = f1.GetX(val);
if (fabs(conv_val) < 1E-10) conv_val = 0.0;
return conv_val;
}
//********************************************************************
double FitBase::RWSigmaToAbs(std::string type, std::string name, double val) {
//********************************************************************
TF1 f1 = GetRWConvFunction(type, name);
double conv_val = f1.Eval(val);
return conv_val;
}
//********************************************************************
double FitBase::RWFracToSigma(std::string type, std::string name, double val) {
//********************************************************************
TF1 f1 = GetRWConvFunction(type, name);
double conv_val = f1.GetX((val * f1.Eval(0.0)));
if (fabs(conv_val) < 1E-10) conv_val = 0.0;
return conv_val;
}
//********************************************************************
double FitBase::RWSigmaToFrac(std::string type, std::string name, double val) {
//********************************************************************
TF1 f1 = GetRWConvFunction(type, name);
double conv_val = f1.Eval(val) / f1.Eval(0.0);
return conv_val;
}
int FitBase::ConvDialType(std::string type){
if (!type.compare("neut_parameter")) return kNEUT;
else if (!type.compare("niwg_parameter")) return kNIWG;
else if (!type.compare("nuwro_parameter")) return kNUWRO;
else if (!type.compare("t2k_parameter")) return kT2K;
else if (!type.compare("genie_parameter")) return kGENIE;
else if (!type.compare("norm_parameter")) return kNORM;
else return kUNKNOWN;
}
std::string FitBase::ConvDialType(int type){
switch(type){
case kNEUT: { return "neut_parameter"; }
case kNIWG: { return "niwg_parameter"; }
case kNUWRO: { return "nuwro_parameter"; }
case kT2K: { return "t2k_parameter"; }
case kGENIE: { return "genie_parameter"; }
case kNORM: { return "norm_parameter"; }
default: return "unknown_parameter";
}
}
int FitBase::GetDialEnum(std::string type, std::string name){
return FitBase::GetDialEnum( FitBase::ConvDialType(type), name );
}
int FitBase::GetDialEnum(int type, std::string name){
int offset = type * 1000;
int this_enum = -1; //Not Found
// Select Types
switch (type) {
// NEUT DIAL TYPE
case kNEUT: {
#ifdef __NEUT_ENABLED__
int neut_enum = (int)neut::rew::NSyst::FromString(name);
if (neut_enum != 0){ this_enum = neut_enum + offset; }
#else
this_enum = -2; //Not enabled
#endif
break;
}
// NIWG DIAL TYPE
case kNIWG: {
#ifdef __NIWG_ENABLED__
int niwg_enum = (int)niwg::rew::NIWGSyst::FromString(name);
if (niwg_enum != 0){ this_enum = niwg_enum + offset; }
#else
this_enum = -2;
#endif
break;
}
// NUWRO DIAL TYPE
case kNUWRO: {
#ifdef __NUWRO_REWEIGHT_ENABLED__
int nuwro_enum = (int)nuwro::rew::NuwroSyst::FromString(name);
if (nuwro_enum > 0){ this_enum = nuwro_enum + offset; }
#else
this_enum = -2;
#endif
}
}
// If Not Enabled
if (this_enum == -2){
ERR(FTL) << "RW Engine not supported for " << FitBase::ConvDialType(type) << endl;
ERR(FTL) << "Check dial " << name << endl;
}
// If Not Found
if (this_enum == -1){
ERR(FTL) << "Dial " << name << " not found." << endl;
}
return this_enum;
}
diff --git a/src/FitBase/InputHandler.cxx b/src/FitBase/InputHandler.cxx
index 65a51c3..e0fd2f5 100644
--- a/src/FitBase/InputHandler.cxx
+++ b/src/FitBase/InputHandler.cxx
@@ -1,1136 +1,1054 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "InputHandler.h"
//****************************************************************************
InputHandler::InputHandler(std::string handle, std::string infile_name) {
//****************************************************************************
LOG(SAM) << "Creating InputHandler for " << handle << "..." << std::endl;
LOG(SAM) << " -> [" << infile_name << "]" << std::endl;
// Initial Setup
fMaxEvents = FitPar::Config().GetParI("MAXEVENTS");
fIsJointInput = false;
fEvent = new FitEvent();
fSignalEvent = new BaseFitEvt();
fInput = infile_name;
fName = handle;
// Parse Infile to allow enviornmental flags
fInputFile = ParseInputFile(fInput);
LOG(SAM) << " -> Type = " << fInputType << std::endl;
LOG(SAM) << " -> Input = " << fInputFile << std::endl;
// Automatically check what sort of event file it is
if (fInputType.compare("JOINT")){
fInputRootFile = new TFile(fInputFile.c_str(), "READ");
if (!fInputRootFile || fInputRootFile->IsZombie()){
ERR(FTL) << "Cannot find InputFile!" << endl;
throw;
}
}
// Setup the handler for each type
-<<<<<<< HEAD
if (!fInputType.compare("NEUT"))
ReadNeutFile();
else if (!fInputType.compare("NUWRO"))
ReadNuWroFile();
else if (!fInputType.compare("GENIE"))
ReadGenieFile();
else if (!fInputType.compare("GiBUU_nu"))
ReadGiBUUFile(false);
else if (!fInputType.compare("GiBUU_nub"))
ReadGiBUUFile(true);
else if (!fInputType.compare("HIST"))
ReadHistogramFile();
else if (!fInputType.compare("BNSPLN"))
ReadBinSplineFile();
else if (!fInputType.compare("EVSPLN"))
ReadEventSplineFile();
else if (!fInputType.compare("NUANCE"))
ReadNuanceFile();
else if (!fInputType.compare("JOINT"))
ReadJointFile();
else if (!fInputType.compare("EMPTY"))
ReadEmptyEvents(); // For Validation
else {
LOG(FTL) << " -> ERROR: Invalid Event File Type" << std::endl;
fInputRootFile->ls();
throw;
}
// Setup MaxEvents After setup of ttree
if (fMaxEvents > 1 && fMaxEvents < fNEvents) {
LOG(SAM) << " -> Reading only " << fMaxEvents
<< " events from total." << std::endl;
fNEvents = fMaxEvents;
-=======
- if (!inType.compare("NEUT")) {
- this->ReadNeutFile();
- } else if (!inType.compare("NUWRO")) {
- this->ReadNuWroFile();
- } else if (!inType.compare("GENIE")) {
- this->ReadGenieFile();
- } else if (!inType.compare("GiBUU_nu")) {
- this->ReadGiBUUFile(false);
- } else if (!inType.compare("GiBUU_nub")) {
- this->ReadGiBUUFile(true);
- } else if (!inType.compare("HIST")) {
- this->ReadHistogramFile();
- } else if (!inType.compare("BNSPLN")) {
- this->ReadBinSplineFile();
- } else if (!inType.compare("EVSPLN")) {
- this->ReadEventSplineFile();
- } else if (!inType.compare("NUANCE")) {
- this->ReadNuanceFile();
- } else if (!inType.compare("JOINT")) {
- this->ReadJointFile();
- } else {
- LOG(FTL) << " -> ERROR: Invalid input file type: " << inType << std::endl;
- inRootFile->ls();
- exit(-1);
- }
-
- // Setup MaxEvents After setup of ttree
- if (maxEvents > 1 && maxEvents < nEvents) {
- LOG(SAM) << " -> Reading only " << maxEvents << " events from total." << std::endl;
- nEvents = maxEvents;
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
}
fFluxList.push_back(fFluxHist);
fEventList.push_back(this->fEventHist);
fXSecList.push_back(this->fXSecHist);
LOG(SAM) << " -> Finished handler initialisation." << std::endl;
return;
};
//********************************************************************
std::string InputHandler::ParseInputFile(std::string inputstring) {
//********************************************************************
// Parse out the input_type
-<<<<<<< HEAD
const int nfiletypes = 9;
+ // The hard-coded list of supported input generators
const std::string filetypes[nfiletypes] = {"NEUT", "NUWRO", "GENIE",
"EVSPLN", "JOINT", "NUANCE",
"GiBUU_nu", "GiBUU_nub", "EMPTY"};
-=======
- const int nfiletypes = 8;
- // The hard-coded list of supported input generators
- const std::string filetypes[nfiletypes] = {"NEUT", "NUWRO", "GENIE", "EVSPLN", "JOINT", "NUANCE", "GiBUU_nu", "GiBUU_nub"};
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
for (int i = 0; i < nfiletypes; i++) {
std::string temptypes = filetypes[i] + ":";
if (inputstring.find(temptypes) != std::string::npos) {
fInputType = filetypes[i];
inputstring.replace(inputstring.find(temptypes), temptypes.size(), "");
break;
}
}
-<<<<<<< HEAD
// If no input type ERROR!
if (fInputType.empty()){
ERR(FTL) << "No input type supplied for InputHandler!" << endl;
ERR(FTL) << "Problematic Input: " << inputstring << endl;
throw;
}
- // Parse out envir flags
-=======
// Parse the "environement" flags in the fitter config
// Can specify NEUT_DIR = "" and others in parameters/fitter.config.dat
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
const int nfiledir = 5;
const std::string filedir[nfiledir] = {"NEUT_DIR", "NUWRO_DIR", "GENIE_DIR", "NUANCE_DIR", "EVSPLN_DIR"};
for (int i = 0; i < nfiledir; i++) {
std::string tempdir = "@" + filedir[i];
if (inputstring.find(tempdir) != std::string::npos) {
std::string event_folder = FitPar::Config().GetParS(filedir[i]);
-<<<<<<< HEAD
- inputstring.replace(inputstring.find(tempdir), tempdir.size(),
- event_folder);
-=======
- inputstring.replace(inputstring.find(tempDir), tempDir.size(), event_folder);
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
-
+ inputstring.replace(inputstring.find(tempdir), tempdir.size(), event_folder);
break;
}
}
return inputstring;
}
//********************************************************************
bool InputHandler::CanIGoFast() {
//********************************************************************
-<<<<<<< HEAD
if (fEventType == 6) {
-=======
- if (eventType == 6) {
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
return true;
}
return false;
}
//********************************************************************
void InputHandler::ReadEmptyEvents(){
//********************************************************************
fEventType = kEMPTY;
// Set flux histograms to empty
fFluxHist = new TH1D( (fName + "_FLUX").c_str(),
(fName + "_FLUX;E_{#nu};Flux").c_str(),
1,0.0,1.0);
fFluxHist->SetBinContent(1,1);
// Set Event Hist to empty
fEventHist = new TH1D((fName + "_EVT").c_str(),
(fName + "_EVT;E_{#nu};Flux").c_str(),
1,0.0,1.0);
fEventHist->SetBinContent(1,1);
// Set XSec hist to empty
fXSecHist = new TH1D((fName + "_XSEC").c_str(),
(fName + "_XSEC;E_{#nu};XSec").c_str(),
1,0.0,1.0);
fXSecHist->SetBinContent(1,1);
fNEvents = 0;
}
//********************************************************************
void InputHandler::ReadEventSplineFile() {
//********************************************************************
-<<<<<<< HEAD
-=======
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
LOG(SAM) << " -> Setting up SPLINE inputs" << std::endl;
// Event Type 7 SPLINES
fEventType = 6;
// Get flux histograms NEUT supplies
fFluxHist = (TH1D*) fInputRootFile->Get((fName + "_FLUX").c_str());
fEventHist = (TH1D*) fInputRootFile->Get((fName + "_EVT" ).c_str());
fXSecHist = (TH1D*) fInputRootFile->Get((fName + "_XSEC").c_str());
// Setup Spline Stuff
fSplineHead = (FitSplineHead*)fInputRootFile->Get((fName + "_splineHead").c_str());
tn = new TChain(Form("%s", (fName + "_splineEvents").c_str()), "");
tn->Add(Form("%s/%s", fInputFile.c_str(),(fName + "_splineEvents").c_str()));
// Assign nvect
fNEvents = tn->GetEntries();
tn->SetBranchAddress("FitEvent", &fEvent);
// Load Dial Coeffs into vector
for (int i = 0; i < fNEvents; i++) {
tn->GetEntry(i);
tn->Show(i);
fAllSplines.push_back(*fEvent->dial_coeff);
}
// Set MAXEVENTS CALC Here before we load in splines
if (fMaxEvents > 1 and fMaxEvents < fNEvents) {
LOG(SAM) << " -> Reading only " << fMaxEvents
<< " events from total spline events." << std::endl;
fNEvents = fMaxEvents;
}
// Load all the splines into signal memory
// for (int i = 0; i < fNEvents; i++){
// tn->GetEntry(i);
// BaseFitEvt* base_event = (new BaseFitEvt(fEvent));
// base_event->fType=6;
// fSignalEvents.push_back( base_event );
// }
// Print out what was read in
LOG(SAM) << " -> Successfully Read SPLINE file" << std::endl;
if (LOG_LEVEL(SAM)) PrintStartInput();
int cnt = 1;
std::list<FitSpline*>::iterator spl_iter =
this->fSplineHead->SplineObjects.begin();
for (; spl_iter != this->fSplineHead->SplineObjects.end(); spl_iter++) {
FitSpline* spl = (*spl_iter);
LOG(SAM) << " -> Spline " << cnt << ". " << spl->id << " " << spl->form
<< " "
<< "NDIM(" << spl->ndim << ") "
<< "NPAR(" << spl->npar << ") "
<< "PTS(" << spl->points << ") " << std::endl;
cnt++;
}
}
//********************************************************************
FitSplineHead* InputHandler::GetSplineHead() {
//********************************************************************
return fSplineHead;
}
//********************************************************************
void InputHandler::SetupCache(){
//********************************************************************
tn->SetCacheSize( FitPar::Config().GetParI("cachesize") );
tn->AddBranchToCache("*",kTRUE);
tn->StopCacheLearningPhase();
}
//********************************************************************
void InputHandler::ReadJointFile() {
//********************************************************************
LOG(SAM) << " -> Reading list of inputs from file" << std::endl;
fIsJointInput = true;
// Parse Input File
std::string line;
std::ifstream card(fInputFile.c_str(), ifstream::in);
std::vector<std::string> input_lines;
while (std::getline(card, line, '\n')) {
std::istringstream stream(line);
// Add normalisation option for second line
input_lines.push_back(line);
// Split to get normalisation
}
card.close();
// Loop over input and get the flux files
// Using a temporary input handler to do this, which is a bit dodge.
int count_low = 0;
int temp_type = -1;
for (UInt_t i = 0; i < input_lines.size(); i++) {
// Create Temporary InputHandlers inside
InputHandler* temp_input = new InputHandler(
std::string(Form("temp_input_%i", i)), input_lines.at(i));
if (temp_type != temp_input->GetType() and i > 0) {
ERR(FTL) << " Can't use joint events with mismatched trees yet!"
<< std::endl;
ERR(FTL) << " Make them all the same type!" << std::endl;
}
temp_type = temp_input->GetType();
TH1D* temp_flux = (TH1D*)temp_input->GetFluxHistogram()->Clone();
TH1D* temp_evts = (TH1D*)temp_input->GetEventHistogram()->Clone();
TH1D* temp_xsec = (TH1D*)temp_input->GetXSecHistogram()->Clone();
int temp_events = temp_input->GetNEvents();
temp_flux->SetName(
(fName + "_" + temp_input->GetInputStateString() + "_FLUX")
.c_str());
temp_evts->SetName(
(fName + "_" + temp_input->GetInputStateString() + "_EVT")
.c_str());
temp_xsec->SetName(
(fName + "_" + temp_input->GetInputStateString() + "_XSEC")
.c_str());
fFluxList.push_back(temp_flux);
fEventList.push_back(temp_evts);
fXSecList.push_back(temp_xsec);
fJointIndexLow.push_back(count_low);
fJointIndexHigh.push_back(count_low + temp_events);
fJointIndexHist.push_back((TH1D*)temp_evts->Clone());
count_low += temp_events;
if (i == 0) {
fFluxHist = (TH1D*)temp_flux->Clone();
fEventHist = (TH1D*)temp_evts->Clone();
} else {
fFluxHist->Add(temp_flux);
fEventHist->Add(temp_evts);
}
std::cout << "Added Input File " << input_lines.at(i) << std::endl
<< " with " << temp_events << std::endl;
}
// Now have all correctly normalised histograms all we need to do is setup the
// TChains
// Input Assumes all the same type
std::string tree_name = "";
if (temp_type == 0)
tree_name = "neuttree";
else if (temp_type == 1)
tree_name = "treeout";
// Add up the TChains
tn = new TChain(tree_name.c_str());
for (UInt_t i = 0; i < input_lines.size(); i++) {
// PARSE INPUT
std::cout << "Adding new tchain " << input_lines.at(i) << std::endl;
std::string temp_file = ParseInputFile(input_lines.at(i));
tn->Add(temp_file.c_str());
}
// Setup Events
fNEvents = tn->GetEntries();
if (temp_type == 0) {
#ifdef __NEUT_ENABLED__
fEventType = 0;
fNeutVect = NULL;
tn->SetBranchAddress("vectorbranch", &fNeutVect);
fEvent->SetEventAddress(&fNeutVect);
#endif
} else if (temp_type == 1) {
#ifdef __NUWRO_ENABLED__
fEventType = 1;
fNuwroEvent = NULL;
tn->SetBranchAddress("e", &fNuwroEvent);
fEvent->SetEventAddress(&fNuwroEvent);
#endif
}
// Normalise event histogram PDFS for weights
for (UInt_t i = 0; i < input_lines.size(); i++) {
TH1D* temp_hist = (TH1D*)fJointIndexHist.at(i)->Clone();
fJointIndexScale.push_back(
double(fNEvents) / fEventHist->Integral("width") *
fJointIndexHist.at(i)->Integral("width") /
double(fJointIndexHigh.at(i) - fJointIndexLow.at(i)));
temp_hist->Scale(double(fNEvents) / fEventHist->Integral("width"));
temp_hist->Scale(fJointIndexHist.at(i)->Integral("width") /
double(fJointIndexHigh.at(i)));
fJointIndexHist.at(i) = temp_hist;
}
fEventHist->SetNameTitle((fName + "_EVT").c_str(),
(fName + "_EVT").c_str());
fFluxHist->SetNameTitle((fName + "_FLUX").c_str(),
(fName + "_FLUX").c_str());
return;
}
//********************************************************************
void InputHandler::ReadNeutFile() {
//********************************************************************
#ifdef __NEUT_ENABLED__
LOG(SAM) << " -> Setting up NEUT inputs" << std::endl;
// Event Type 0 Neut
fEventType = kNEUT;
// Get flux histograms NEUT supplies
-<<<<<<< HEAD
fFluxHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "flux")).c_str());
fFluxHist->SetNameTitle((fName + "_FLUX").c_str(),
- (fName + "; E_{#nu} (GeV)").c_str());
+ (fName + "; E_{#nu} (GeV)").c_str());
fEventHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "evtrt")).c_str());
- fEventHist->SetNameTitle(
- (fName + "_EVT").c_str(),
- (fName + "; E_{#nu} (GeV); Event Rate").c_str());
+ fEventHist->SetNameTitle( (fName + "_EVT").c_str(),
+ (fName + "; E_{#nu} (GeV); Event Rate").c_str());
fXSecHist = (TH1D*)fEventHist->Clone();
fXSecHist->Divide(fFluxHist);
- fXSecHist->SetNameTitle(
- (fName + "_XSEC").c_str(),
- (fName + "_XSEC;E_{#nu} (GeV); XSec (1#times10^{-38} cm^{2})")
- .c_str());
-=======
- this->fluxHist = (TH1D*)inRootFile->Get( (PlotUtils::GetObjectWithName(inRootFile, "flux")).c_str());
- this->fluxHist->SetNameTitle((this->handleName + "_FLUX").c_str(), (this->handleName + "; E_{#nu} (GeV)").c_str());
-
- // Get the event histograms from NEUT
- this->eventHist = (TH1D*)inRootFile->Get( (PlotUtils::GetObjectWithName(inRootFile, "evtrt")).c_str());
- this->eventHist->SetNameTitle( (this->handleName + "_EVT").c_str(), (this->handleName + "; E_{#nu} (GeV); Event Rate").c_str());
-
- this->xsecHist = (TH1D*)eventHist->Clone();
- this->xsecHist->Divide(this->fluxHist);
- this->xsecHist->SetNameTitle( (this->handleName + "_XSEC").c_str(), (this->handleName + "_XSEC;E_{#nu} (GeV); XSec (1#times10^{-38} cm^{2})") .c_str());
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
+ fXSecHist->SetNameTitle( (fName + "_XSEC").c_str(),
+ (fName + "_XSEC;E_{#nu} (GeV); XSec (1#times10^{-38} cm^{2})")
+ .c_str());
// Read in the file once only
tn = new TChain("neuttree", "");
tn->Add(Form("%s/neuttree", fInputFile.c_str()));
// Assign nvect
fNEvents = tn->GetEntries();
fNeutVect = NULL;
tn->SetBranchAddress("vectorbranch", &fNeutVect);
// Make the custom event read in nvect when calling CalcKinematics
fEvent->SetEventAddress(&fNeutVect);
// Print out what was read in
LOG(SAM) << " -> Successfully Read NEUT file" << std::endl;
-<<<<<<< HEAD
- if (LOG_LEVEL(SAM)) PrintStartInput();
-=======
- if (LOG_LEVEL(SAM)) {
- this->PrintStartInput();
+ if (LOG_LEVEL(SAM)){
+ PrintStartInput();
}
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
#else
ERR(FTL) << "ERROR: Invalid Event File Provided" << std::endl;
ERR(FTL) << "NEUT Input Not Enabled." << std::endl;
ERR(FTL) << "Rebuild with --enable-neut or check FitBuild.h!" << std::endl;
exit(-1);
#endif
return;
}
//********************************************************************
void InputHandler::ReadNuWroFile() {
//********************************************************************
#ifdef __NUWRO_ENABLED__
LOG(SAM) << " -> Setting up Nuwro inputs" << std::endl;
// Event Type 1 == NuWro
fEventType = kNUWRO;
// Setup the TChain for nuwro event tree
tn = new TChain("treeout");
tn->AddFile(fInputFile.c_str());
// Get entries and fNuwroEvent
fNEvents = tn->GetEntries();
fNuwroEvent = NULL;
tn->SetBranchAddress("e", &fNuwroEvent);
fEvent->SetEventAddress(&fNuwroEvent);
// Check if we have saved an xsec histogram before
fFluxHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "FluxHist")).c_str());
fEventHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "EvtHist")).c_str());
// Check if we are forcing plot generation (takes time)
bool regenFlux = FitPar::Config().GetParB("input.regen_nuwro_plots");
if (regenFlux)
LOG(SAM)
<< " -> Forcing NuWro XSec/Flux plots to be generated at the start. "
<< std::endl;
// Already generated flux and event histograms
if (fFluxHist and fEventHist and !regenFlux) {
fXSecHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "xsec")).c_str());
fFluxHist->SetNameTitle((fName + "_FLUX").c_str(),
(fName + "_FLUX").c_str());
fEventHist->SetNameTitle((fName + "_EVT").c_str(),
(fName + "_EVT").c_str());
fXSecHist->SetNameTitle((fName + "_XSEC").c_str(),
(fName + "_XSEC").c_str());
// Need to regenerate if not found
} else {
LOG(SAM)
<< " -> No NuWro XSec or Flux Histograms found, need to regenerate!"
<< std::endl;
// Can grab flux histogram from the pars
tn->GetEntry(0);
int beamtype = fNuwroEvent->par.beam_type;
if (beamtype == 0) {
std::string fluxstring = fNuwroEvent->par.beam_energy;
std::vector<double> fluxvals =
PlotUtils::ParseToDbl(fluxstring, " ");
int pdg = fNuwroEvent->par.beam_particle;
double Elow = double(fluxvals[0]) / 1000.0;
double Ehigh = double(fluxvals[1]) / 1000.0;
std::cout << " - Adding new nuwro flux "
<< "pdg: " << pdg << "Elow: " << Elow << "Ehigh: " << Ehigh
<< std::endl;
fFluxHist = new TH1D("fluxplot", "fluxplot", fluxvals.size() - 2, Elow, Ehigh);
for (int j = 2; j < fluxvals.size(); j++) {
cout << j << " " << fluxvals[j] << endl;
fFluxHist->SetBinContent(j - 1, fluxvals[j]);
}
} else if (beamtype == 1) {
std::string fluxstring = fNuwroEvent->par.beam_content;
std::vector<std::string> fluxlines =
PlotUtils::ParseToStr(fluxstring, "\n");
for (int i = 0; i < fluxlines.size(); i++) {
std::vector<double> fluxvals =
PlotUtils::ParseToDbl(fluxlines[i], " ");
int pdg = int(fluxvals[0]);
double pctg = double(fluxvals[1]) / 100.0;
double Elow = double(fluxvals[2]) / 1000.0;
double Ehigh = double(fluxvals[3]) / 1000.0;
std::cout << " - Adding new nuwro flux "
<< "pdg: " << pdg << "pctg: " << pctg << "Elow: " << Elow
<< "Ehigh: " << Ehigh << std::endl;
TH1D* fluxplot =
new TH1D("fluxplot", "fluxplot", fluxvals.size() - 4, Elow, Ehigh);
for (int j = 4; j < fluxvals.size(); j++) {
fluxplot->SetBinContent(j + 1, fluxvals[j]);
}
if (fFluxHist)
fFluxHist->Add(fluxplot);
else
fFluxHist = (TH1D*)fluxplot->Clone();
}
}
fFluxHist->SetNameTitle("nuwro_flux",
"nuwro_flux;E_{#nu} (GeV); Flux");
fEventHist = (TH1D*)fFluxHist->Clone();
fEventHist->Reset();
fEventHist->SetNameTitle("nuwro_evt", "nuwro_evt");
fXSecHist = (TH1D*)fFluxHist->Clone();
fXSecHist->Reset();
fXSecHist->SetNameTitle("nuwro_xsec", "nuwro_xsec");
// Start Processing
LOG(SAM) << " -> Processing NuWro Input Flux for " << fNEvents
<< " events (This can take a while...) " << std::endl;
double Enu = 0.0;
double TotXSec = 0.0;
double totaleventmode = 0.0;
double totalevents = 0.0;
// --- loop
for (int i = 0; i < fNEvents; i++) {
tn->GetEntry(i);
if (i % 100000 == 0) cout << " i " << i << std::endl;
// Get Variables
Enu = fNuwroEvent->in[0].E() / 1000.0;
TotXSec = fNuwroEvent->weight;
// Fill a flux and xsec histogram
fEventHist->Fill(Enu);
fXSecHist->Fill(Enu, TotXSec);
// Keep Tally
totaleventmode += TotXSec;
totalevents++;
};
LOG(SAM) << " -> Flux Processing Loop Finished." << std::endl;
if (fEventHist->Integral() == 0.0) {
std::cout << "ERROR NO EVENTS FOUND IN RANGE! " << std::endl;
exit(-1);
}
// Sort out plot scaling
double AvgXSec = (totaleventmode * 1.0E38 / (totalevents + 0.));
LOG(SAM) << " -> Average XSec = " << AvgXSec << std::endl;
fEventHist->Scale(1.0 / fEventHist->Integral()); // Convert to PDF
fEventHist->Scale(fFluxHist->Integral() *
AvgXSec); // Convert to Proper Event Rate
fXSecHist->Add(fEventHist); // Get Event Rate Plot
fXSecHist->Divide(fFluxHist); // Make XSec Plot
// fEventHist = (TH1D*)fFluxHist->Clone();
// fEventHist->Multiply(fXSecHist);
// Clear over/underflows incase they mess with integrals later.
fFluxHist->SetBinContent(0, 0.0);
fFluxHist->SetBinContent(fFluxHist->GetNbinsX() + 2, 0.0);
fEventHist->SetBinContent(0, 0.0);
fEventHist->SetBinContent(fEventHist->GetNbinsX() + 2, 0.0);
LOG(SAM)
<< " -> Finished making NuWro event plots. Saving them for next time..."
<< std::endl;
TFile* temp_save_file = new TFile(fInputFile.c_str(), "UPDATE");
temp_save_file->cd();
fFluxHist->Write("FluxHist", TObject::kOverwrite);
fEventHist->Write("EventHist", TObject::kOverwrite);
fXSecHist->Write("XSecHist", TObject::kOverwrite);
temp_save_file->ls();
temp_save_file->Close();
delete temp_save_file;
fFluxHist->SetNameTitle((fName + "_FLUX").c_str(),
(fName + "_FLUX").c_str());
fEventHist->SetNameTitle((fName + "_EVT").c_str(),
(fName + "_EVT").c_str());
fXSecHist->SetNameTitle((fName + "_XSEC").c_str(),
(fName + "_XSEC").c_str());
}
// Print out what was read in
LOG(SAM) << " -> Successfully Read NUWRO file" << std::endl;
if (LOG_LEVEL(SAM)) PrintStartInput();
#else
ERR(FTL) << "ERROR: Invalid Event File Provided" << std::endl;
ERR(FTL) << "NuWro Input Not Enabled." << std::endl;
ERR(FTL) << "Rebuild with --enable-nuwro or check FitBuild.h!" << std::endl;
exit(-1);
#endif
return;
}
//********************************************************************
void InputHandler::ReadGenieFile() {
//********************************************************************
#ifdef __GENIE_ENABLED__
// Event Type 1 NuWro
fEventType = 5;
// Open Root File
LOG(SAM) << "Reading event file " << fInputFile << std::endl;
// Get flux histograms NEUT supplies
fFluxHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "spectrum")).c_str());
fFluxHist->SetNameTitle((fName + "_FLUX").c_str(),
(fName + "; E_{#nu} (GeV)").c_str());
fEventHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "spectrum")).c_str());
fEventHist->SetNameTitle(
(fName + "_EVT").c_str(),
(fName + "; E_{#nu} (GeV); Event Rate").c_str());
fXSecHist = (TH1D*)fInputRootFile->Get(
(PlotUtils::GetObjectWithName(fInputRootFile, "spectrum")).c_str());
fXSecHist->SetNameTitle(
(fName + "_XSEC").c_str(),
(fName + "; E_{#nu} (GeV); Event Rate").c_str());
double average_xsec = 0.0;
int total_events = 0;
// Setup the TChain for nuwro event tree
tn = new TChain("gtree");
tn->AddFile(fInputFile.c_str());
fNEvents = tn->GetEntries();
LOG(SAM) << "Number of GENIE Eevents " << tn->GetEntries() << std::endl;
fGenieGHep = NULL;
fGenieNtpl = NULL;
// NtpMCEventRecord * fGenieNtpl = 0; tree->SetBranchAddress(gmrec, &fGenieNtpl);
tn->SetBranchAddress("gmcrec", &fGenieNtpl);
fEventHist->Reset();
// Make the custom event read in nvect when calling CalcKinematics
fEvent->SetEventAddress(&fGenieNtpl);
LOG(SAM) << "Processing GENIE flux events." << std::endl;
for (int i = 0; i < fNEvents; i++) {
tn->GetEntry(i);
EventRecord& event = *(fGenieNtpl->event);
GHepParticle* neu = event.Probe();
GHepRecord genie_record = static_cast<GHepRecord>(event);
// double xsec = (genie_record.XSec() / (1E-38 * genie::units::cm2));
double xsec = (1E+38/genie::units::cm2) * (1.0/2.0) * genie_record.XSec();
average_xsec += xsec;
total_events += 1;
fEventHist->Fill(neu->E());
fXSecHist->Fill(neu->E(), xsec);
fGenieNtpl->Clear();
}
average_xsec = average_xsec / (total_events + 0.);
fEventHist->Scale( average_xsec * fFluxHist->Integral("width") / total_events, "width" );
fXSecHist = (TH1D*)fEventHist->Clone();
fXSecHist->Divide(fFluxHist);
// Set Titles
fEventHist->SetNameTitle((fName + "_EVT").c_str(),
(fName + "_EVT;E_{#nu} (GeV); Events (1#times10^{-38})")
.c_str());
fXSecHist->SetNameTitle((fName + "_XSEC").c_str(),
(fName + "_XSEC;E_{#nu} (GeV); XSec (1#times10^{-38} cm^{2})")
.c_str());
#else
ERR(FTL) << "ERROR: Invalid Event File Provided" << std::endl;
ERR(FTL) << "GENIE Input Not Enabled." << std::endl;
ERR(FTL) << "Rebuild with --enable-genie or check FitBuild.h!" << std::endl;
exit(-1);
#endif
return;
}
//********************************************************************
void InputHandler::ReadGiBUUFile(bool IsNuBarDominant) {
//********************************************************************
#ifdef __GiBUU_ENABLED__
fEventType = kGiBUU;
// Open Root File
LOG(SAM) << "Opening event file " << fInputFile << std::endl;
TFile* rootFile = new TFile(fInputFile.c_str(), "READ");
// Get flux histograms NEUT supplies
TH1D* numuFlux = dynamic_cast<TH1D*>(rootFile->Get("numu_flux"));
TH1D* numubFlux = dynamic_cast<TH1D*>(rootFile->Get("numub_flux"));
if (numuFlux) {
numuFlux = static_cast<TH1D*>(numuFlux->Clone());
numuFlux->SetDirectory(NULL);
numuFlux->SetNameTitle(
(fName + "_numu_FLUX").c_str(),
(fName + "; E_{#nu} (GeV); #Phi_{#nu} (A.U.)").c_str());
fFluxList.push_back(numuFlux);
}
if (numubFlux) {
numubFlux = static_cast<TH1D*>(numubFlux->Clone());
numubFlux->SetDirectory(NULL);
numubFlux->SetNameTitle(
(fName + "_numub_FLUX").c_str(),
(fName + "; E_{#nu} (GeV); #Phi_{#bar{#nu}} (A.U.)")
.c_str());
fFluxList.push_back(numubFlux);
}
rootFile->Close();
// Set flux hist to the dominant mode
fFluxHist = IsNuBarDominant ? numubFlux : numuFlux;
if (!fFluxHist) {
ERR(FTL) << "Couldn't find: "
<< (IsNuBarDominant ? "numub_flux" : "numu_flux")
<< " in input file: " << fInputRootFile->GetName() << std::endl;
exit(1);
}
fFluxHist->SetNameTitle(
(fName + "_FLUX").c_str(),
(fName + "; E_{#nu} (GeV);" +
(IsNuBarDominant ? "#Phi_{#bar{#nu}} (A.U.)" : "#Phi_{#nu} (A.U.)"))
.c_str());
tn = new TChain("giRooTracker");
tn->AddFile(fInputFile.c_str());
fEventHist =
static_cast<TH1D*>(fFluxHist->Clone((fName + "_EVT").c_str()));
fEventHist->Reset();
fNEvents = tn->GetEntries();
fEventHist->SetBinContent(
1, double(fNEvents) / fEventHist->GetXaxis()->GetBinWidth(1));
GiBUUStdHepReader* giRead = new GiBUUStdHepReader();
giRead->SetBranchAddresses(tn);
fEvent->SetEventAddress(giRead);
#endif
}
//********************************************************************
void InputHandler::ReadBinSplineFile() {
//********************************************************************
// Bin Splines are saved as one event for each histogram bin.
// So just read in as normal event splines and it'll all get sorted easily.
}
//********************************************************************
void InputHandler::ReadHistogramFile() {
//********************************************************************
// Convert the raw histogram into a series of events with X variables
// So we don't have to pass stuff upsteam
}
//********************************************************************
void InputHandler::ReadNuanceFile() {
//********************************************************************
#ifdef __NUANCE_ENABLED__
// Read in Nuance output ROOT file (converted from hbook)
LOG(SAM) << " Reading NUANCE " << std::endl;
fEventType = kNUANCE;
// Read in NUANCE Tree
tn = new TChain("h3");
tn->AddFile(fInputFile.c_str());
// Get entries and fNuwroEvent
fNEvents = tn->GetEntries();
fNuanceEvt = new NuanceEvent();
// SetBranchAddress for Nuance
// tn->SetBranchAddress("cc",&fNuanceEvt->cc);
// tn->SetBranchAddress("bound",&fNuanceEvt->bound);
tn->SetBranchAddress("neutrino", &fNuanceEvt->neutrino);
tn->SetBranchAddress("target", &fNuanceEvt->target);
tn->SetBranchAddress("channel", &fNuanceEvt->channel);
// tn->SetBranchAddress("iniQ", &fNuanceEvt->iniQ);
// tn->SetBranchAddress("finQ", &fNuanceEvt->finQ);
// tn->SetBranchAddress("lepton0", &fNuanceEvt->lepton0);
// tn->SetBranchAddress("polar", &fNuanceEvt->polar);
// tn->SetBranchAddress("qsq", &fNuanceEvt->qsq);
// tn->SetBranchAddress("w", &fNuanceEvt->w);
// tn->SetBranchAddress("x",&fNuanceEvt->x);
// tn->SetBranchAddress("y",&fNuanceEvt->y);
tn->SetBranchAddress("p_neutrino", &fNuanceEvt->p_neutrino);
tn->SetBranchAddress("p_targ", &fNuanceEvt->p_targ);
// tn->SetBranchAddress("vertex", &fNuanceEvt->vertex);
// tn->SetBranchAddress("start",&fNuanceEvt->start);
// tn->SetBranchAddress("depth",&fNuanceEvt->depth);
// tn->SetBranchAddress("flux",&fNuanceEvt->flux);
tn->SetBranchAddress("n_leptons", &fNuanceEvt->n_leptons);
tn->SetBranchAddress("p_ltot", &fNuanceEvt->p_ltot);
tn->SetBranchAddress("lepton", &fNuanceEvt->lepton);
tn->SetBranchAddress("p_lepton", &fNuanceEvt->p_lepton);
tn->SetBranchAddress("n_hadrons", &fNuanceEvt->n_hadrons);
tn->SetBranchAddress("p_htot", &fNuanceEvt->p_htot);
tn->SetBranchAddress("hadron", &fNuanceEvt->hadron);
tn->SetBranchAddress("p_hadron", &fNuanceEvt->p_hadron);
fEvent->SetEventAddress(&fNuanceEvt);
fFluxHist = new TH1D((fName + "_FLUX").c_str(),
(fName + "_FLUX").c_str(), 1, 0.0, 1.0);
fFluxHist->SetBinContent(1, 1.0);
fEventHist = new TH1D((fName + "_EVT").c_str(),
(fName + "_EVT").c_str(), 1, 0.0, 1.0);
fEventHist->SetBinContent(1, fNEvents);
#else
ERR(FTL) << "ERROR: Invalid Event File Provided" << std::endl;
ERR(FTL) << "NUANCE Input Not Enabled." << std::endl;
ERR(FTL) << "Rebuild with -DUSE_NUANCE=1!" << std::endl;
exit(-1);
#endif
}
//********************************************************************
void InputHandler::PrintStartInput() {
//********************************************************************
LOG(SAM) << " -> Total events = " << fNEvents << std::endl;
LOG(SAM) << " -> Energy Range = " << fFluxHist->GetXaxis()->GetXmin() << "-"
<< fFluxHist->GetXaxis()->GetXmax() << " GeV" << std::endl;
LOG(SAM) << " -> Integrated Flux Hist = "
<< fFluxHist->Integral(0, fFluxHist->GetNbinsX(), "width")
<< std::endl;
LOG(SAM) << " -> Integrated Event Hist = "
<< fEventHist->Integral(0, fEventHist->GetNbinsX(), "width")
<< std::endl;
LOG(SAM) << " -> Integrated Inclusive XSec = "
<< (fEventHist->Integral(0, fEventHist->GetNbinsX(), "width") /
fFluxHist->Integral(0, fFluxHist->GetNbinsX(), "width")) *
1E-38
<< std::endl;
if (fEventType == kEVTSPLINE) return;
// Get First event info
tn->GetEntry(0);
fEvent->CalcKinematics();
LOG(SAM) << " -> Event 0. Neutrino PDG = " << fEvent->PartInfo(0)->fPID
<< std::endl;
LOG(SAM) << " Target A = " << fEvent->GetTargetA()
<< std::endl;
LOG(SAM) << " Target Z = " << fEvent->GetTargetZ()
<< std::endl;
}
//********************************************************************
std::string InputHandler::GetInputStateString() {
//********************************************************************
tn->GetEntry(0);
fEvent->CalcKinematics();
std::ostringstream state;
state << "T" << fEventType << "_PDG" << fEvent->PartInfo(0)->fPID << "_Z"
<< fEvent->GetTargetZ() << "_A" << fEvent->GetTargetA();
return state.str();
}
//********************************************************************
void InputHandler::ReadEvent(unsigned int i) {
//********************************************************************
bool using_events =
(fEventType == kNEUT ||
fEventType == 5 ||
fEventType == kNUWRO ||
fEventType == kEVTSPLINE ||
fEventType == kNUANCE ||
fEventType == kGiBUU);
if (using_events) {
tn->LoadTree(i);
tn->GetEntry(i);
if (fEventType != kEVTSPLINE) fEvent->CalcKinematics();
fEvent->Index = i;
fEventIndex = i;
fEvent->InputWeight = GetInputWeight(i);
} else {
GetTreeEntry(i);
}
}
//********************************************************************
void InputHandler::GetTreeEntry(const Long64_t i) {
//********************************************************************
-<<<<<<< HEAD
+ // If we're just reading from the input root file
if (fEventType != kEVTSPLINE)
tn->GetEntry(i);
+ // If we've got splines enabled
else
(*(fEvent->dial_coeff)) = fAllSplines.at(i);
-=======
- // If we're just reading from the input root file
- if (eventType != kEVTSPLINE) {
- tn->GetEntry(i);
- // If we've got splines enabled
- } else {
- (*(cust_event->dial_coeff)) = spline_list.at(i);
- }
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
fEventIndex = i;
fEvent->InputWeight = GetInputWeight(i);
}
//********************************************************************
double InputHandler::GetInputWeight(const int entry) {
//********************************************************************
if (fEventType == kGiBUU) {
return fEvent->InputWeight;
}
if (!fIsJointInput) {
return 1.0;
}
double weight = 1.0;
// Find Histogram
for (UInt_t j = 0; j < fJointIndexLow.size(); j++) {
if (entry >= fJointIndexLow.at(j) and entry < fJointIndexHigh.at(j)) {
weight *= fJointIndexScale.at(j);
break;
}
}
return weight;
}
//********************************************************************
int InputHandler::GetGenEvents() {
//********************************************************************
if (fEventType == 6)
return fSplineHead->ngen_events;
else
return GetNEvents();
}
//********************************************************************
double InputHandler::TotalIntegratedFlux(double low, double high,
std::string intOpt) {
//********************************************************************
if( fEventType == kGiBUU){
return 1.0;
}
int minBin = fFluxHist->GetXaxis()->FindBin(low);
int maxBin = fFluxHist->GetXaxis()->FindBin(high);
double integral =
fFluxHist->Integral(minBin, maxBin + 1, intOpt.c_str());
return integral;
};
//********************************************************************
double InputHandler::PredictedEventRate(double low, double high,
std::string intOpt) {
//********************************************************************
int minBin = fFluxHist->GetXaxis()->FindBin(low);
int maxBin = fFluxHist->GetXaxis()->FindBin(high);
return fEventHist->Integral(minBin, maxBin + 1, intOpt.c_str());
}
diff --git a/src/FitBase/Measurement1D.cxx b/src/FitBase/Measurement1D.cxx
index 90c2307..b950ab1 100644
--- a/src/FitBase/Measurement1D.cxx
+++ b/src/FitBase/Measurement1D.cxx
@@ -1,1266 +1,1263 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "Measurement1D.h"
/*
Constructor/destructor Functions
*/
//********************************************************************
Measurement1D::Measurement1D() {
//********************************************************************
fCurrentNorm = 1.0;
fMCHist = NULL;
fDataHist = NULL;
fMCFine = NULL;
fMCWeighted = NULL;
fMaskHist = NULL;
this->covar = NULL;
fFullCovar = NULL;
fDecomp = NULL;
this->fakeDataFile = "";
fFluxHist = NULL;
fEventHist = NULL;
fXSecHist = NULL;
fDefaultTypes = "FIX/FULL/CHI2";
fAllowedTypes = "FIX,FREE,SHAPE/FULL,DIAG/CHI2/NORM/ENUCORR/Q2CORR/ENU1D/MASK";
fIsFix = false;
fIsShape = false;
fIsFree = false;
fIsDiag = false;
fIsFull = false;
fAddNormPen = false;
fIsMask = false;
fIsChi2SVD = false;
fIsRawEvents = false;
fIsDifXSec = false;
fIsEnu1D = false;
}
//********************************************************************
Measurement1D::~Measurement1D(){
//********************************************************************
}
//********************************************************************
void Measurement1D::Init(){
//********************************************************************
}
/*
Setup Functions
-- All these are used only at the start of the Measurement
*/
//********************************************************************
void Measurement1D::SetupMeasurement(std::string inputfile, std::string type, FitWeight *rw, std::string fkdt){
//********************************************************************
// Reset everything to NULL
Init();
// Check if name contains Evt, indicating that it is a raw number of events measurements
// and should thus be treated as once
fIsRawEvents = false;
if ((fName.find("Evt") != std::string::npos) && fIsRawEvents == false) {
fIsRawEvents = true;
LOG(SAM) << "Found event rate measurement but fIsRawEvents == false!" << std::endl;
LOG(SAM) << "Overriding this and setting fIsRawEvents == true!" << std::endl;
}
fIsEnu1D = false;
if (fName.find("XSec_1DEnu") != std::string::npos) {
fIsEnu1D = true;
LOG(SAM) << "::" << fName << "::" << std::endl;
LOG(SAM) << "Found XSec Enu measurement, applying flux integrated scaling, not flux averaged!" << std::endl;
}
if (fIsEnu1D && fIsRawEvents) {
LOG(SAM) << "Found 1D Enu XSec distribution AND fIsRawEvents, is this really correct?!" << std::endl;
LOG(SAM) << "Check experiment constructor for " << fName << " and correct this!" << std::endl;
LOG(SAM) << "I live in " << __FILE__ << ":" << __LINE__ << std::endl;
exit(-1);
}
fRW = rw;
this->SetupInputs(inputfile);
// Set Default Options
SetFitOptions( fDefaultTypes );
// Set Passed Options
SetFitOptions(type);
// Still adding support for flat flux inputs
// // Set Enu Flux Scaling
// if (isFlatFluxFolding) this->Input()->ApplyFluxFolding( this->defaultFluxHist );
}
//********************************************************************
void Measurement1D::SetupDefaultHist(){
//********************************************************************
// Setup fMCHist
fMCHist = (TH1D*) fDataHist->Clone();
fMCHist->SetNameTitle( (fName + "_MC").c_str(), (fName + "_MC" + fPlotTitles).c_str() );
// Setup fMCFine
Int_t nBins = fMCHist->GetNbinsX();
fMCFine = new TH1D( (fName + "_MC_FINE").c_str(), (fName + "_MC_FINE" + fPlotTitles).c_str(),
nBins*6, fMCHist->GetBinLowEdge(1), fMCHist->GetBinLowEdge(nBins+1) );
fMCStat = (TH1D*) fMCHist->Clone();
fMCStat->Reset();
fMCHist->Reset();
fMCFine->Reset();
// Setup the NEUT Mode Array
PlotUtils::CreateNeutModeArray((TH1D*)fMCHist,(TH1**)fMCHist_PDG);
PlotUtils::ResetNeutModeArray((TH1**)fMCHist_PDG);
// Setup bin masks using sample name
if (fIsMask){
std::string maskloc = FitPar::Config().GetParDIR( fName + ".mask");
if (maskloc.empty()){
maskloc = FitPar::GetDataBase() + "/masks/" + fName + ".mask";
}
SetBinMask(maskloc);
}
return;
}
//********************************************************************
void Measurement1D::SetFitOptions(std::string opt){
//********************************************************************
// Do nothing if default given
if (opt == "DEFAULT") return;
// CHECK Conflicting Fit Options
std::vector<std::string> fit_option_allow = PlotUtils::ParseToStr(fAllowedTypes, "/");
for (UInt_t i = 0; i < fit_option_allow.size(); i++){
std::vector<std::string> fit_option_section = PlotUtils::ParseToStr(fit_option_allow.at(i), ",");
bool found_option = false;
for (UInt_t j = 0; j < fit_option_section.size(); j++){
std::string av_opt = fit_option_section.at(j);
if (!found_option and opt.find(av_opt) != std::string::npos) {
found_option = true;
} else if (found_option and opt.find(av_opt) != std::string::npos){
ERR(FTL) << "ERROR: Conflicting fit options provided: "<<opt<<std::endl;
ERR(FTL) << "Conflicting group = "<<fit_option_section.at(i)<<std::endl;
ERR(FTL) << "You should only supply one of these options in card file."<<std::endl;
exit(-1);
}
}
}
// Check all options are allowed
std::vector<std::string> fit_options_input = PlotUtils::ParseToStr(opt,"/");
for (UInt_t i = 0; i < fit_options_input.size(); i++){
if (fAllowedTypes.find(fit_options_input.at(i)) == std::string::npos){
ERR(FTL) <<"ERROR: Fit Option '"<<fit_options_input.at(i)<<"' Provided is not allowed for this measurement."<<std::endl;
ERR(FTL) <<"Fit Options should be provided as a '/' seperated list (e.g. FREE/DIAG/NORM)" << std::endl;
ERR(FTL) <<"Available options for "<<fName<<" are '"<< fAllowedTypes <<"'"<<std::endl;
exit(-1);
}
}
// Set TYPE
fFitType = opt;
// FIX,SHAPE,FREE
if (opt.find("FIX") != std::string::npos){
fIsFree = fIsShape = false;
fIsFix = true;
} else if (opt.find("SHAPE") != std::string::npos){
fIsFree = fIsFix = false;
fIsShape = true;
} else if (opt.find("FREE") != std::string::npos){
fIsFix = fIsShape = false;
fIsFree = true;
}
// DIAG,FULL (or default to full)
if (opt.find("DIAG") != std::string::npos){
fIsDiag = true;
fIsFull = false;
} else if (opt.find("FULL") != std::string::npos){
fIsDiag = false;
fIsFull = true;
}
// CHI2/LL (OTHERS?)
if (opt.find("LOG") != std::string::npos) fIsChi2 = false;
else fIsChi2 = true;
// EXTRAS
if (opt.find("RAW") != std::string::npos) fIsRawEvents = true;
if (opt.find("DIF") != std::string::npos) fIsDifXSec = true;
if (opt.find("ENU1D") != std::string::npos) fIsEnu1D = true;
if (opt.find("NORM") != std::string::npos) fAddNormPen = true;
if (opt.find("MASK") != std::string::npos) fIsMask = true;
return;
};
//********************************************************************
void Measurement1D::SetDataValues(std::string dataFile) {
//********************************************************************
// Override this function if the input file isn't in a suitable format
LOG(SAM) << "Reading data from: " << dataFile.c_str() << std::endl;
fDataHist = PlotUtils::GetTH1DFromFile(dataFile, (fName+"_data"), fPlotTitles);
fDataTrue = (TH1D*)fDataHist->Clone();
return;
};
//********************************************************************
void Measurement1D::SetDataFromDatabase(std::string inhistfile, std::string histname){
//********************************************************************
LOG(SAM) << "Filling histogram from "<< inhistfile << "->"<< histname <<std::endl;
fDataHist = PlotUtils::GetTH1DFromRootFile((std::string(std::getenv("EXT_FIT")) + "/data/" + inhistfile), histname);
fDataHist->SetNameTitle((fName+"_data").c_str(), (fName + "_data").c_str());
return;
};
//********************************************************************
void Measurement1D::SetDataFromFile(std::string inhistfile, std::string histname){
//********************************************************************
LOG(SAM) << "Filling histogram from "<< inhistfile << "->"<< histname <<std::endl;
fDataHist = PlotUtils::GetTH1DFromRootFile((inhistfile), histname);
return;
};
//********************************************************************
void Measurement1D::SetCovarMatrix(std::string covarFile){
//********************************************************************
// Covariance function, only really used when reading in the MB Covariances.
TFile* tempFile = new TFile(covarFile.c_str(),"READ");
TH2D* covarPlot = new TH2D();
// TH2D* decmpPlot = new TH2D();
TH2D* covarInvPlot = new TH2D();
TH2D* fFullCovarPlot = new TH2D();
std::string covName = "";
std::string covOption = FitPar::Config().GetParS("thrown_covariance");
if (fIsShape || fIsFree) covName = "shp_";
if (fIsDiag) covName += "diag";
else covName += "full";
covarPlot = (TH2D*) tempFile->Get((covName + "cov").c_str());
covarInvPlot = (TH2D*) tempFile->Get((covName + "covinv").c_str());
if (!covOption.compare("SUB")) fFullCovarPlot = (TH2D*) tempFile->Get((covName + "cov").c_str());
else if (!covOption.compare("FULL")) fFullCovarPlot = (TH2D*) tempFile->Get("fullcov");
else ERR(WRN) <<"Incorrect thrown_covariance option in parameters."<<std::endl;
int dim = int(fDataHist->GetNbinsX());//-this->masked->Integral());
int covdim = int(fDataHist->GetNbinsX());
this->covar = new TMatrixDSym(dim);
fFullCovar = new TMatrixDSym(dim);
fDecomp = new TMatrixDSym(dim);
int row,column = 0;
row = 0;
column = 0;
for (Int_t i = 0; i < covdim; i++){
// if (this->masked->GetBinContent(i+1) > 0) continue;
for (Int_t j = 0; j < covdim; j++){
// if (this->masked->GetBinContent(j+1) > 0) continue;
(*this->covar)(row, column) = covarPlot->GetBinContent(i+1,j+1);
(*fFullCovar)(row, column) = fFullCovarPlot->GetBinContent(i+1,j+1);
column++;
}
column = 0;
row++;
}
// Set bin errors on data
if (!fIsDiag){
StatUtils::SetDataErrorFromCov(fDataHist, fFullCovar);
}
// Get Deteriminant and inverse matrix
fCovDet = this->covar->Determinant();
TDecompSVD LU = TDecompSVD(*this->covar);
this->covar = new TMatrixDSym(dim, LU .Invert().GetMatrixArray(), "");
return;
};
//********************************************************************
void Measurement1D::SetCovarMatrixFromText(std::string covarFile, int dim){
//********************************************************************
////////////////////////////////////////////////////////////
// WARNING this reads in the data CORRELATIONS
// WARNING this reads in the data CORRELATIONS
// WARNING this reads in the data CORRELATIONS
// WARNING this reads in the data CORRELATIONS
////////////////////////////////////////////////////////////
// Make a counter to track the line number
int row = 0;
std::string line;
- std::ifstream covar(covarFile.c_str(),ifstream::in);
+ std::ifstream covarread(covarFile.c_str(),ifstream::in);
this->covar = new TMatrixDSym(dim);
fFullCovar = new TMatrixDSym(dim);
- if(covar.is_open()) LOG(SAM) << "Reading covariance matrix from file: " << covarFile << std::endl;
+ if(covarread.is_open()) LOG(SAM) << "Reading covariance matrix from file: " << covarFile << std::endl;
else ERR(FTL) <<"Covariance matrix provided is incorrect: "<<covarFile<<std::endl;
// MINERvA CC1pip needs slightly different method
// Only half the covariance matrix is given and I'm too lazy to write the full one so let the code do it instead
if (fName.find("MINERvA_CC1pip") == std::string::npos ||
(fName.find("MINERvA_CCNpip") && fName.find("2016"))) {
- while(std::getline(covar, line, '\n')){
+ while(std::getline(covarread, line, '\n')){
std::istringstream stream(line);
double entry;
int column = 0;
// Loop over entries and insert them into matrix
// Multiply by the errors to get the covariance, rather than the correlation matrix
while(stream >> entry){
double val = entry * fDataHist->GetBinError(row+1)*1E38*fDataHist->GetBinError(column+1)*1E38;
(*covar)(row, column) = val;
(*fFullCovar)(row, column) = val;
column++;
}
row++;
}
// Robust matrix inversion method
TDecompSVD LU = TDecompSVD(*this->covar);
this->covar = new TMatrixDSym(dim, LU .Invert().GetMatrixArray(), "");
} else { // Here's the MINERvA CC1pip method; very similar
- while(std::getline(covar, line, '\n')){
+ while(std::getline(covarread, line, '\n')){
std::istringstream stream(line);
double entry;
int column = 0;
while (column < dim) {
if (column < row) {
(*this->covar)(row,column) = (*this->covar)(column,row);
column++;
} else {
while(stream >> entry){
double val = entry*(fDataHist->GetBinError(row+1)*1E38*fDataHist->GetBinError(column+1)*1E38); // need in these units to do Cholesky
(*this->covar)(row, column) = val;
(*fFullCovar)(row, column) = val;
column++;
}
}
}
row++;
}
// Robust matrix inversion method
TDecompChol a = TDecompChol(*this->covar);
this->covar = new TMatrixDSym(dim, a.Invert().GetMatrixArray(), "");
} // end special treatment for MINERvA CC1pi+
return;
};
//********************************************************************
void Measurement1D::SetSmearingMatrix(std::string smearfile, int truedim, int recodim){
//********************************************************************
// The smearing matrix describes the migration from true bins (rows) to reco bins (columns)
// Counter over the true bins!
int row = 0;
std::string line;
std::ifstream smear(smearfile.c_str(),ifstream::in);
// Note that the smearing matrix may be rectangular.
fSmearMatrix = new TMatrixD(truedim, recodim);
if(smear.is_open()) LOG(SAM) << "Reading smearing matrix from file: " << smearfile << std::endl;
else ERR(FTL) <<"Smearing matrix provided is incorrect: "<< smearfile <<std::endl;
while(std::getline(smear, line, '\n')){
std::istringstream stream(line);
double entry;
int column = 0;
while(stream >> entry){
double val = entry;
(*fSmearMatrix)(row, column) = val/100.; // Convert to fraction from percentage (this may not be general enough)
column++;
}
row++;
}
return;
}
//********************************************************************
void Measurement1D::SetCovarFromDataFile(std::string covarFile, std::string covName){
//********************************************************************
LOG(SAM) << "Getting covariance from "<<covarFile<<"->"<<covName<<std::endl;
TFile* tempFile = new TFile(covarFile.c_str(),"READ");
TH2D* covPlot = (TH2D*) tempFile->Get(covName.c_str());
covPlot->SetDirectory(0);
int dim = covPlot->GetNbinsX();
fFullCovar = new TMatrixDSym(dim);
for (int i = 0; i < dim; i++){
for (int j = 0; j < dim; j++){
(*fFullCovar)(i,j) = covPlot->GetBinContent(i+1,j+1);
}
}
this->covar = (TMatrixDSym*) fFullCovar->Clone();
fDecomp =(TMatrixDSym*) fFullCovar->Clone();
TDecompSVD LU = TDecompSVD(*this->covar);
this->covar = new TMatrixDSym(dim, LU .Invert().GetMatrixArray(), "");
TDecompChol LUChol = TDecompChol(*fDecomp);
LUChol.Decompose();
fDecomp = new TMatrixDSym(dim, LU .GetU().GetMatrixArray(), "");
return;
};
//********************************************************************
void Measurement1D::SetBinMask(std::string maskFile){
//********************************************************************
// Create a mask histogram.
int nbins = fDataHist->GetNbinsX();
fMaskHist = new TH1I((fName+"_fMaskHist").c_str(),(fName+"_fMaskHist; Bin; Mask?").c_str(),nbins,0,nbins);
std::string line;
std::ifstream mask(maskFile.c_str(),ifstream::in);
if (mask.is_open()) LOG(SAM) <<"Reading bin mask from file: "<<maskFile <<std::endl;
else std::cerr <<" Cannot find mask file."<<std::endl;
while(std::getline(mask, line, '\n')){
std::istringstream stream(line);
int column = 0;
double entry;
int bin;
while (stream >> entry){
if (column == 0) bin = int(entry);
if (column > 1) break;
column++;
}
fMaskHist->SetBinContent(bin,entry);
}
// Set masked data bins to zero
PlotUtils::MaskBins(fDataHist, fMaskHist);
return;
}
/*
XSec Functions
*/
//********************************************************************
void Measurement1D::SetFluxHistogram(std::string fluxFile, int minE, int maxE, double fluxNorm){
//********************************************************************
// Note this expects the flux bins to be given in terms of MeV
LOG(SAM) << "Reading flux from file: " << fluxFile << std::endl;
TGraph f(fluxFile.c_str(),"%lg %lg");
fFluxHist = new TH1D((fName+"_flux").c_str(), (fName+"; E_{#nu} (GeV)").c_str(), f.GetN()-1, minE, maxE);
Double_t *yVal = f.GetY();
for (int i = 0; i<fFluxHist->GetNbinsX(); ++i)
fFluxHist->SetBinContent(i+1, yVal[i]*fluxNorm);
};
//********************************************************************
double Measurement1D::TotalIntegratedFlux(std::string intOpt, double low, double high){
//********************************************************************
if(GetInput()->GetType() == kGiBUU){
return 1.0;
}
// Set Energy Limits
if (low == -9999.9) low = this->EnuMin;
if (high == -9999.9) high = this->EnuMax;
int minBin = fFluxHist->GetXaxis()->FindBin(low);
int maxBin = fFluxHist->GetXaxis()->FindBin(high);
// Get integral over custom range
double integral = fFluxHist->Integral(minBin, maxBin+1, intOpt.c_str());
return integral;
};
/*
Reconfigure LOOP
*/
//********************************************************************
void Measurement1D::ResetAll(){
//********************************************************************
// Simple function to reset the mc Histograms incase that is all that is needed.
// Clear histograms
fMCHist->Reset();
fMCFine->Reset();
fMCStat->Reset();
PlotUtils::ResetNeutModeArray((TH1**)fMCHist_PDG);
return;
};
//********************************************************************
void Measurement1D::FillHistograms(){
//********************************************************************
if (Signal){
fMCHist->Fill(fXVar, Weight);
fMCFine->Fill(fXVar, Weight);
fMCStat->Fill(fXVar, 1.0);
PlotUtils::FillNeutModeArray(fMCHist_PDG, Mode, fXVar, Weight);
}
return;
};
//********************************************************************
void Measurement1D::ScaleEvents(){
//********************************************************************
- LOG(REC) << std::setw(20) << " " << mcHist->Integral() << "/" << nevents << " events passed selection" << std::endl;
+ LOG(REC) << std::setw(20) << " " << fMCHist->Integral() << "/" << fNEvents << " events passed selection" << std::endl;
// Simple function to scale to xsec result if this is all that is needed.
// Scale bin errors correctly
TH1D* tempFine = (TH1D*) fMCFine->Clone();
// Create Weighted Histogram
if (fMCWeighted) delete fMCWeighted;
fMCWeighted = (TH1D*) fMCHist->Clone();
fMCWeighted->SetNameTitle( (fName + "_MC_WGHTS").c_str(),
(fName + "_MC_WGHTS" + fPlotTitles).c_str() );
fMCWeighted->GetYaxis()->SetTitle("Weighted Events");
// Should apply different scaling for:
// 1D Enu distributions -- need bin by bin flux unfolding (bin by bin flux integration)
// 1D count distributions -- need shape scaling to data
// anything else -- flux averages
// Scaling for raw event rates
if (fIsRawEvents) {
PlotUtils::ScaleNeutModeArray((TH1**)fMCHist_PDG, (fDataHist->Integral()/fMCHist->Integral()), "width");
fMCHist->Scale(fDataHist->Integral()/fMCHist->Integral());
fMCFine->Scale(fDataHist->Integral()/fMCFine->Integral());
// Scaling for XSec as function of Enu
} else if (fIsEnu1D) {
PlotUtils::FluxUnfoldedScaling(fMCHist, fFluxHist);
PlotUtils::FluxUnfoldedScaling(fMCFine, fFluxHist);
fMCHist->Scale(fScaleFactor);
fMCFine->Scale(fScaleFactor);
// Any other differential scaling
} else {
fMCHist->Scale(fScaleFactor, "width");
fMCFine->Scale(fScaleFactor, "width");
PlotUtils::ScaleNeutModeArray((TH1**)fMCHist_PDG, fScaleFactor, "width");
}
// Proper error scaling - ROOT Freaks out with xsec weights sometimes
// Scale the MC histogram
for(int i=0; i<fMCStat->GetNbinsX();i++) {
if (fMCStat->GetBinContent(i+1) != 0) {
fMCHist->SetBinError(i+1, fMCHist->GetBinContent(i+1) * fMCStat->GetBinError(i+1) / fMCStat->GetBinContent(i+1) );
} else {
fMCHist->SetBinError(i+1, fMCHist->Integral());
}
}
// Scale the fine MC histogram
for(int i=0; i<tempFine->GetNbinsX();i++) {
if (tempFine->GetBinContent(i+1) != 0) {
fMCFine->SetBinError(i+1, fMCFine->GetBinContent(i+1) * tempFine->GetBinError(i+1) / tempFine->GetBinContent(i+1) );
} else {
fMCFine->SetBinError(i+1, fMCFine->Integral());
}
}
return;
};
//********************************************************************
void Measurement1D::ApplyNormScale(double norm){
//********************************************************************
fCurrentNorm = norm;
fMCHist->Scale(1.0/norm);
fMCFine->Scale(1.0/norm);
PlotUtils::ScaleNeutModeArray((TH1**)fMCHist_PDG, 1.0/norm);
return;
};
//********************************************************************
void Measurement1D::ApplySmearingMatrix(){
//********************************************************************
if (!fSmearMatrix){
ERR(WRN) << fName <<": attempted to apply smearing matrix, but none was set"<<std::endl;
return;
}
TH1D* unsmeared = (TH1D*)fMCHist->Clone();
TH1D* smeared = (TH1D*)fMCHist->Clone();
smeared->Reset();
// Loop over reconstructed bins
// true = row; reco = column
for (int rbin=0; rbin < fSmearMatrix->GetNcols(); ++rbin){
// Sum up the constributions from all true bins
double rBinVal = 0;
// Loop over true bins
for (int tbin=0; tbin < fSmearMatrix->GetNrows(); ++tbin){
rBinVal += (*fSmearMatrix)(tbin,rbin)*unsmeared->GetBinContent(tbin+1);
}
smeared->SetBinContent(rbin+1, rBinVal);
}
fMCHist = (TH1D*)smeared->Clone();
return;
}
/*
Statistic Functions - Outsources to StatUtils
*/
//********************************************************************
int Measurement1D::GetNDOF(){
//********************************************************************
return fDataHist->GetNbinsX(); // - fMaskHist->Integral();
}
//********************************************************************
double Measurement1D::GetLikelihood() {
//********************************************************************
double stat = 0.0;
// Fix weird masking bug
if (!fIsMask){
if (fMaskHist){
fMaskHist = NULL;
}
} else {
if (fMaskHist){
PlotUtils::MaskBins(fMCHist, fMaskHist);
}
}
// Sort Initial Scaling
double scaleF = 0.0;
if (fMCHist->Integral(1, fMCHist->GetNbinsX(), "width")){
scaleF = fDataHist->Integral(1,fDataHist->GetNbinsX(),"width")/fMCHist->Integral(1, fMCHist->GetNbinsX(), "width");
}
if (fIsShape){
fMCHist->Scale(scaleF);
fMCFine->Scale(scaleF);
}
// Get Chi2
if (fIsChi2){
if (!fIsDiag){
if (!fIsChi2SVD) {
stat = StatUtils::GetChi2FromCov(fDataHist, fMCHist, covar, fMaskHist);
} else {
stat = StatUtils::GetChi2FromSVD(fDataHist,fMCHist, fFullCovar, fMaskHist);
}
} else {
if (fIsRawEvents) {
stat = StatUtils::GetChi2FromEventRate(fDataHist, fMCHist, fMaskHist);
} else {
stat = StatUtils::GetChi2FromDiag(fDataHist, fMCHist, fMaskHist);
}
}
} else {
if (!fIsDiag){
if (!fIsChi2SVD) stat = StatUtils::GetLikelihoodFromCov(fDataHist, fMCHist, covar, fMaskHist);
else stat = StatUtils::GetLikelihoodFromSVD(fDataHist,fMCHist, fFullCovar, fMaskHist);
} else {
if (fIsRawEvents) stat = StatUtils::GetLikelihoodFromEventRate(fDataHist, fMCHist, fMaskHist);
else stat = StatUtils::GetLikelihoodFromDiag(fDataHist, fMCHist, fMaskHist);
}
}
// Sort Penalty Terms
if (fAddNormPen){
if (fNormError <= 0.0){
ERR(WRN) << "Norm error for class " << fName << " is 0.0!" << endl;
ERR(WRN) << "Skipping norm penalty." << endl;
}
double penalty = (1. - fCurrentNorm)*(1. - fCurrentNorm)/(fNormError*fNormError);
stat += penalty;
}
// Return to normal scaling
if (fIsShape){
fMCHist->Scale(1./scaleF);
fMCFine->Scale(1./scaleF);
}
return stat;
}
//********************************************************************
void Measurement1D::SetFakeDataValues(std::string fakeOption) {
//********************************************************************
// Reset things
if (fIsFakeData){
this->ResetFakeData();
} else {
fIsFakeData = true;
}
// Make a copy of the original data histogram.
if (!(fDataOrig)) fDataOrig = (TH1D*)fDataHist->Clone((fName+"_data_original").c_str());
TH1D *tempData = (TH1D*)fDataHist->Clone();
TFile *fake = new TFile();
if (fakeOption.compare("MC")==0){
LOG(SAM) << "Setting fake data from MC "<<std::endl;
fDataHist = (TH1D*)fMCHist->Clone((fName+"_MC").c_str());
if (fMCHist->Integral() == 0.0) ERR(WRN) << fName <<": Invalid histogram"<<std::endl;
}
else {
fake = new TFile(fakeOption.c_str());
fDataHist = (TH1D*)fake->Get((fName+"_MC").c_str());
}
fDataHist ->SetNameTitle((fName+"_FAKE").c_str(), (fName+fPlotTitles).c_str());
fDataTrue = (TH1D*)fDataHist->Clone();
fDataTrue ->SetNameTitle((fName+"_FAKE_TRUE").c_str(), (fName+fPlotTitles).c_str());
int nbins = fDataHist->GetNbinsX();
double alpha_i = 0.0;
double alpha_j = 0.0;
for (int i = 0; i < nbins; i++){
for (int j = 0; j < nbins; j++){
alpha_i = fDataHist->GetBinContent(i+1)/tempData->GetBinContent(i+1);
alpha_j = fDataHist->GetBinContent(j+1)/tempData->GetBinContent(j+1);
(*this->covar)(i,j) = (1.0/(alpha_i*alpha_j))*(*this->covar)(i,j);
(*fFullCovar)(i,j) = alpha_i*alpha_j*(*fFullCovar)(i,j);
}
}
(this->covar) = (TMatrixDSym*) fFullCovar->Clone();
TDecompSVD LU = TDecompSVD(*this->covar);
this->covar = new TMatrixDSym(nbins, LU .Invert().GetMatrixArray(), "");
return;
};
//********************************************************************
void Measurement1D::ResetFakeData(){
//********************************************************************
if (fIsFakeData)
if (fDataHist) delete fDataHist;
fDataHist = (TH1D*) fDataTrue->Clone((fName+"_FKDAT").c_str());
return;
}
//********************************************************************
void Measurement1D::ResetData(){
//********************************************************************
if (fIsFakeData)
if (fDataHist) delete fDataHist;
fDataHist = (TH1D*) fDataTrue->Clone((fName+"_Data").c_str());
fIsFakeData = false;
}
//********************************************************************
void Measurement1D::ThrowCovariance(){
//********************************************************************
// Take a fDecomposition and use it to throw the current dataset.
// Requires fDataTrue also be set incase used repeatedly.
delete fDataHist;
fDataHist = StatUtils::ThrowHistogram(fDataTrue, fFullCovar);
return;
};
/*
Access Functions
*/
//********************************************************************
std::vector<TH1*> Measurement1D::GetMCList(){
//********************************************************************
// If this isn't a NULL pointer, make the plot pretty!
if (!fMCHist) return std::vector<TH1*> (1, fMCHist);
std::ostringstream chi2;
chi2 << std::setprecision(5) << this->GetLikelihood();
int plotcolor = kRed;
if (FitPar::Config().GetParI("linecolour") > 0){
plotcolor = FitPar::Config().GetParI("linecolour");
}
int plotstyle = 1;
if (FitPar::Config().GetParI("linestyle") > 0){
plotstyle = FitPar::Config().GetParI("linestyle");
}
int plotfillstyle=0;
if (FitPar::Config().GetParI("fillstyle") > 0){
plotfillstyle = FitPar::Config().GetParI("fillstyle");
}
fMCHist->SetTitle(chi2.str().c_str());
fMCHist->SetLineWidth(3);
fMCHist->SetLineColor(plotcolor);
fMCHist->SetFillColor(plotcolor);
fMCHist->SetLineStyle(plotstyle);
fMCHist->SetFillStyle(plotfillstyle);
return std::vector<TH1*> (1, fMCHist);
};
//********************************************************************
std::vector<TH1*> Measurement1D::GetDataList(){
//********************************************************************
// If this isn't a NULL pointer, make the plot pretty!
if (!fDataHist) return std::vector<TH1*> (1, fDataHist);
fDataHist->SetLineWidth(2);
fDataHist->SetMarkerStyle(8);
fDataHist->SetLineColor(kBlack);
return std::vector<TH1*> (1, fDataHist);
};
//********************************************************************
void Measurement1D::GetBinContents(std::vector<double>& cont, std::vector<double>& err){
//********************************************************************
// Return a vector of the main bin contents
for (int i = 0; i < fMCHist->GetNbinsX(); i++){
cont.push_back(fMCHist->GetBinContent(i+1));
err.push_back(fMCHist->GetBinError(i+1));
}
return;
};
//********************************************************************
std::vector<double> Measurement1D::GetXSec(std::string option){
//********************************************************************
std::vector<double> vals;
vals.push_back(0.0);
vals.push_back(0.0);
bool getMC = !option.compare("MC");
bool getDT = !option.compare("DATA");
for (int i = 0; i < fMCHist->GetNbinsX(); i++){
if (fDataHist->GetBinContent(i+1) == 0.0 and fDataHist->GetBinError(i+1) == 0.0) continue;
if (getMC){
vals[0] += fMCHist->GetBinContent(i+1) * fMCHist->GetXaxis()->GetBinWidth(i+1);
vals[1] += fMCHist->GetBinError(i+1) * fMCHist->GetBinError(i+1) * fMCHist->GetXaxis()->GetBinWidth(i+1) * fMCHist->GetXaxis()->GetBinWidth(i+1);
} else if (getDT){
vals[0] += fDataHist->GetBinContent(i+1) * fDataHist->GetXaxis()->GetBinWidth(i+1);
vals[1] += fDataHist->GetBinError(i+1) * fDataHist->GetBinError(i+1) * fDataHist->GetXaxis()->GetBinWidth(i+1) * fDataHist->GetXaxis()->GetBinWidth(i+1);
}
}
// If not diag Get the total error from the covariance
if (!fIsDiag and !fIsRawEvents and getDT and fFullCovar){
vals[1] = 0.0;
for (int i = 0; i < fDataHist->GetNbinsX(); i++){
for(int j = 0; j < fDataHist->GetNbinsX(); j++){
vals[1] += (*fFullCovar)(i,j);
}
}
vals[1] = sqrt(vals[1]) * 1E-38;
}
return vals;
}
/*
Write Functions
*/
// Save all the histograms at once
//********************************************************************
void Measurement1D::Write(std::string drawOpt){
//********************************************************************
// If null pointer return
if (!fMCHist and !fDataHist){
LOG(SAM) << fName <<"Incomplete histogram set!"<<std::endl;
return;
}
// Get Draw Options
drawOpt = FitPar::Config().GetParS("drawopts");
bool drawData = (drawOpt.find("DATA") != std::string::npos);
bool drawNormal = (drawOpt.find("MC") != std::string::npos);
bool drawEvents = (drawOpt.find("EVT") != std::string::npos);
bool drawFine = (drawOpt.find("FINE") != std::string::npos);
bool drawRatio = (drawOpt.find("RATIO") != std::string::npos);
bool drawModes = (drawOpt.find("MODES") != std::string::npos);
bool drawShape = (drawOpt.find("SHAPE") != std::string::npos);
bool residual = (drawOpt.find("RESIDUAL") != std::string::npos);
// bool drawMatrix = (drawOpt.find("MATRIX") != std::string::npos);
- // bool drawXSec = (drawOpt.find("XSEC") != std::string::npos);
+ bool drawXSec = (drawOpt.find("XSEC") != std::string::npos);
bool drawFlux = (drawOpt.find("FLUX") != std::string::npos);
bool drawMask = (drawOpt.find("MASK") != std::string::npos);
bool drawCov = (drawOpt.find("COV") != std::string::npos);
bool drawInvCov = (drawOpt.find("INVCOV") != std::string::npos);
bool drawDecomp = (drawOpt.find("DECOMP") != std::string::npos);
bool drawCanvPDG = (drawOpt.find("CANVPDG") != std::string::npos);
bool drawCanvMC = (drawOpt.find("CANVMC") != std::string::npos);
bool drawWeighted = (drawOpt.find("WGHT") != std::string::npos);
// Save standard plots
if (drawData) this->GetDataList().at(0)->Write();
if (drawNormal) this->GetMCList() .at(0)->Write();
// Save only mc and data if splines
if(fEventType == 4 or fEventType==3){ return; }
// Draw Extra plots
if (drawFine) this->GetFineList().at(0)->Write();
if (fIsMask and drawMask) fMaskHist->Write( (fName + "_MSK").c_str() ); //< save mask
if (drawFlux) fFluxHist->Write();
if (drawXSec) fXSecHist->Write();
if (drawEvents) fEventHist->Write();
if (fIsMask and drawMask and fMaskHist){
fMaskHist->Write( (fName + "_MSK").c_str() ); //< save mask
}
// Save neut stack
if (drawModes){
LOG(SAM) << "Writing MC Hist PDG"<<std::endl;
THStack combo_fMCHist_PDG = PlotUtils::GetNeutModeStack((fName + "_MC_PDG").c_str(), (TH1**)fMCHist_PDG, 0);
combo_fMCHist_PDG.Write();
}
// Save Matrix plots
if (!fIsRawEvents and !fIsDiag){
if (drawCov and fFullCovar){
TH2D cov = TH2D((*fFullCovar));
cov.SetNameTitle((fName+"_cov").c_str(),(fName+"_cov;Bins; Bins;").c_str());
-
- if (isMask && drawMask) {
- this->maskHist->Write( (this->measurementName + "_MSK").c_str() ); //< save mask
+ cov.Write();
+ }
+ }
+
+ if (fIsMask && drawMask && fMaskHist) {
+ fMaskHist->Write( (this->fName + "_MSK").c_str() ); //< save mask
}
-
// Save neut stack
if (drawModes){
//LOG(SAM) << "Writing MC Hist PDG"<<std::endl;
- THStack combo_mcHist_PDG = PlotUtils::GetNeutModeStack((this->measurementName + "_MC_PDG").c_str(), (TH1**)this->mcHist_PDG, 0);
+ THStack combo_mcHist_PDG = PlotUtils::GetNeutModeStack((this->fName + "_MC_PDG").c_str(), (TH1**)this->fMCHist_PDG, 0);
combo_mcHist_PDG.Write();
}
// Save Matrix plots
- if (!isRawEvents && !isDiag && fFullCovar){
- if (drawCov && fullcovar){
- TH2D cov = TH2D((*this->fullcovar));
- cov.SetNameTitle((this->measurementName+"_cov").c_str(),(this->measurementName+"_cov;Bins; Bins;").c_str());
+ if (!fIsRawEvents && !fIsDiag && fFullCovar){
+ if (drawCov && fFullCovar){
+ TH2D cov = TH2D((*this->fFullCovar));
+ cov.SetNameTitle((this->fName+"_cov").c_str(),(this->fName+"_cov;Bins; Bins;").c_str());
cov.Write();
}
if (drawInvCov && covar){
TH2D covinv = TH2D((*this->covar));
covinv.SetNameTitle((fName+"_covinv").c_str(),(fName+"_cov;Bins; Bins;").c_str());
covinv.Write();
}
if (drawDecomp and fDecomp){
TH2D covdec = TH2D((*fDecomp));
covdec.SetNameTitle((fName+"_covdec").c_str(),(fName+"_cov;Bins; Bins;").c_str());
covdec.Write();
}
}
// Save ratio plots if required
if (drawRatio){
// Needed for error bars
for(int i = 0; i < fMCHist->GetNbinsX()*fMCHist->GetNbinsY(); i++)
fMCHist->SetBinError(i+1,0.0);
fDataHist->GetSumw2();
fMCHist->GetSumw2();
// Create Ratio Histograms
TH1D* dataRatio = (TH1D*) fDataHist->Clone((fName + "_data_RATIO").c_str());
TH1D* mcRatio = (TH1D*) fMCHist->Clone((fName + "_MC_RATIO").c_str());
mcRatio->Divide(fMCHist);
dataRatio->Divide(fMCHist);
// Cancel bin errors on MC
for(int i = 0; i < mcRatio->GetNbinsX(); i++)
mcRatio->SetBinError(i+1,fMCHist->GetBinError(i+1) / fMCHist->GetBinContent(i+1));
mcRatio->SetMinimum(0);
mcRatio->SetMaximum(2);
dataRatio->SetMinimum(0);
dataRatio->SetMaximum(2);
mcRatio->Write();
dataRatio->Write();
delete mcRatio;
delete dataRatio;
}
// Save Shape Plots if required
if (drawShape){
// Create Shape Histogram
TH1D* mcShape = (TH1D*) fMCHist->Clone((fName + "_MC_SHAPE").c_str());
double shapeScale = fDataHist->Integral("width")/fMCHist->Integral("width");
mcShape->Scale(shapeScale);
std::stringstream ss;
ss << shapeScale;
mcShape->SetTitle(ss.str().c_str());
mcShape->SetLineWidth(3);
mcShape->SetLineStyle(7); //dashes
mcShape->Write();
// Save shape ratios
if (drawRatio) {
// Needed for error bars
mcShape->GetSumw2();
// Create shape ratio histograms
TH1D* mcShapeRatio = (TH1D*)mcShape->Clone((fName + "_MC_SHAPE_RATIO").c_str());
TH1D* dataShapeRatio = (TH1D*)fDataHist->Clone((fName + "_data_SHAPE_RATIO").c_str());
// Divide the histograms
mcShapeRatio ->Divide(mcShape);
dataShapeRatio ->Divide(mcShape);
// Colour the shape ratio plots
mcShapeRatio ->SetLineWidth(3);
mcShapeRatio ->SetLineStyle(7); // dashes
mcShapeRatio ->Write();
dataShapeRatio->Write();
delete mcShapeRatio;
delete dataShapeRatio;
}
delete mcShape;
}
- // Save residual calculations of what contributed to the chi2 values.
- if (residual){
-
- }
-
// Make a pretty PDG Canvas
if (drawCanvPDG){
TCanvas* c1 = new TCanvas((fName + "_PDG_CANV").c_str(),
(fName + "_PDG_CANV").c_str(),
800,600);
fDataHist->Draw("E1");
fMCHist->Draw("HIST SAME");
THStack combo_fMCHist_PDG = PlotUtils::GetNeutModeStack((fName + "_MC_PDG").c_str(),
(TH1**)fMCHist_PDG, 0);
combo_fMCHist_PDG.Draw("HIST SAME");
TLegend leg = PlotUtils::GenerateStackLegend(combo_fMCHist_PDG, 0.6,0.6,0.9,0.9);
fDataHist->Draw("E1 SAME");
// leg.Draw("SAME");
c1->Write();
delete c1;
}
if (drawCanvMC){
TCanvas* c1 = new TCanvas((fName + "_MC_CANV").c_str(),
(fName + "_MC_CANV").c_str(),
800,600);
c1->cd();
fDataHist->Draw("E1");
fMCHist->Draw("SAME HIST");
TH1D* mcShape = (TH1D*) fMCHist->Clone((fName + "_MC_SHAPE").c_str());
double shapeScale = fDataHist->Integral("width")/fMCHist->Integral("width");
mcShape->Scale(shapeScale);
mcShape->SetLineStyle(7);
mcShape->Draw("SAME HIST");
TLegend* leg = new TLegend(0.6,0.6,0.9,0.9);
leg->AddEntry(fDataHist, (fName + " Data").c_str(), "ep");
leg->AddEntry(fMCHist, (fName + " MC").c_str(), "l");
leg->AddEntry(mcShape, (fName + " Shape").c_str(), "l");
leg->Draw("SAME");
c1->Write();
delete c1;
}
if (drawWeighted){
fMCWeighted->Write();
}
// Returning
LOG(SAM) << fName << "Written Histograms: "<<fName<<std::endl;
return;
};
// ********************************************
// Returns the NEUT mode stack
THStack Measurement1D::GetModeStack(){
// ********************************************
THStack combo_hist = PlotUtils::GetNeutModeStack((fName + "_MC_PDG").c_str(), (TH1**)fMCHist_PDG, 0);
return combo_hist;
}
diff --git a/src/FitBase/MeasurementBase.cxx b/src/FitBase/MeasurementBase.cxx
index ab352ce..ed6a3f5 100644
--- a/src/FitBase/MeasurementBase.cxx
+++ b/src/FitBase/MeasurementBase.cxx
@@ -1,363 +1,364 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "MeasurementBase.h"
/*
Constructor/Destructors
*/
//********************************************************************
// 2nd Level Constructor (Inherits From MeasurementBase.h)
MeasurementBase::MeasurementBase() {
//********************************************************************
fScaleFactor = 1.0;
fMCFilled = false;
};
//********************************************************************
// 2nd Level Destructor (Inherits From MeasurementBase.h)
MeasurementBase::~MeasurementBase() {
//********************************************************************
};
//********************************************************************
double MeasurementBase::TotalIntegratedFlux(std::string intOpt, double low, double high){
//********************************************************************
// Set Energy Limits
if (low == -9999.9) low = this->EnuMin;
if (high == -9999.9) high = this->EnuMax;
return GetInput()->TotalIntegratedFlux(low, high, intOpt);
};
//********************************************************************
double MeasurementBase::PredictedEventRate(std::string intOpt, double low, double high){
//********************************************************************
// Set Energy Limits
if (low == -9999.9) low = this->EnuMin;
if (high == -9999.9) high = this->EnuMax;
return GetInput()->PredictedEventRate(low, high, intOpt) * 1E-38;
};
//********************************************************************
void MeasurementBase::SetupInputs(std::string inputfile){
//********************************************************************
// Add this infile to the global manager
if (FitPar::Config().GetParB("EventManager")){
FitBase::AddInput(fName, inputfile);
// Get a pointer to the input so we can grab flux stuff
// Slightly Convoluted...
fInput = FitBase::GetInput( FitBase::GetInputID(inputfile) );
} else {
fInput = new InputHandler(fName, inputfile);
}
fFluxHist = fInput->GetFluxHistogram();
fEventHist = fInput->GetEventHistogram();
fXSecHist = fInput->GetXSecHistogram();
fNEvents = fInput->GetNEvents();
inputfilename = inputfile;
}
//***********************************************
int MeasurementBase::GetInputID(){
//***********************************************
return FitBase::GetInputID(inputfilename);
}
//***********************************************
void MeasurementBase::Reconfigure(){
//***********************************************
LOG(REC) << " Reconfiguring sample "<<fName<<std::endl;
bool using_evtmanager = FitPar::Config().GetParB("EventManager");
int input_id = -1;
if (using_evtmanager) input_id = FitBase::GetInputID(inputfilename);
cust_event = fInput->GetEventPointer();
if (FitPar::Config().GetParI("cachesize") > 0){
fInput->SetupCache();
}
// Reset Histograms
this->ResetAll();
// READ in spline head for this input
if (fInput->GetType() == kEVTSPLINE){
FitBase::GetRW()->ReadSplineHead(fInput->GetSplineHead());
}
FitEvent* cust_event = fInput->GetEventPointer();
int fNEvents = fInput->GetNEvents();
int countwidth = (fNEvents/5);
// Reset Signal Vectors
fXVar_VECT.clear();
fYVar_VECT.clear();
fZVar_VECT.clear();
this->fMode_VECT.clear();
this->fIndex_VECT.clear();
size_t NSignal = 0;
// MAIN EVENT LOOP
for (int i = 0; i < fNEvents; i++){
// Read in the TChain and Calc Kinematics
if (using_evtmanager){
cust_event = FitBase::EvtManager().GetEvent(input_id, i);
} else {
fInput->ReadEvent(i);
cust_event->RWWeight = FitBase::GetRW()->CalcWeight(cust_event);
cust_event->Weight = cust_event->RWWeight*cust_event->InputWeight;
Weight = cust_event->Weight;
}
Weight = cust_event->Weight;
// Initialize
fXVar = 0.0;
fYVar = 0.0;
fZVar = 0.0;
Signal = false;
Mode = cust_event->Mode;
// Extract Measurement Variables
this->FillEventVariables(cust_event);
Signal = this->isSignal(cust_event);
// Push Back Signal
if (Signal){
fXVar_VECT .push_back(fXVar);
fYVar_VECT .push_back(fYVar);
fZVar_VECT .push_back(fZVar);
this->fMode_VECT .push_back(Mode);
this->fIndex_VECT .push_back( (UInt_t)i);
NSignal++;
}
// Fill Histogram Values
this->FillHistograms();
// this->FillExtraHistograms();
// Print Out
- if (LOG_LEVEL(REC) && countwidth && !(i % countwidth))
+ if (LOG_LEVEL(REC) && countwidth > 0 && !(i % countwidth)){
LOG(REC).unsetf(ios_base::fixed);
- std::cout << std::setw(7) << std::right << i << "/" << nevents
- << " events (" << std::setw(2) << double(i)/double(nevents)*100.
- << std::left << std::setw(5) << "%) "
- << "[S,X,Y,Z,M,W] = ["
- << std::fixed << std::setprecision(2) << std::right
- << Signal << ", "
- << std::setw(5) << fXVar << ", " << std::setw(5) << fYVar << ", "
- << std::setw(5) << fYVar << ", " << std::setw(5) << Mode << ", "
- << std::setw(5) << Weight << "] "<< std::endl;
-
+ std::cout << std::setw(7) << std::right << i << "/" << fNEvents
+ << " events (" << std::setw(2) << double(i)/double(fNEvents)*100.
+ << std::left << std::setw(5) << "%) "
+ << "[S,X,Y,Z,M,W] = ["
+ << std::fixed << std::setprecision(2) << std::right
+ << Signal << ", "
+ << std::setw(5) << fXVar << ", " << std::setw(5) << fYVar << ", "
+ << std::setw(5) << fYVar << ", " << std::setw(5) << Mode << ", "
+ << std::setw(5) << Weight << "] "<< std::endl;
+ }
+
}
- int npassed = X_VAR_VECT.size();
- LOG(REC) << npassed << "/" << nevents << " passed selection " << std::endl;
+ int npassed = fXVar_VECT.size();
+ LOG(REC) << npassed << "/" << fNEvents << " passed selection " << std::endl;
if (npassed == 0) {
LOG(REC) << "WARNING: NO EVENTS PASSED SELECTION!" << std::endl;
}
// Finalise Histograms
fMCFilled = true;
this->ConvertEventRates();
}
//***********************************************
void MeasurementBase::ReconfigureFast(){
//***********************************************
LOG(REC) << " Reconfiguring signal "<<this->fName<<std::endl;
bool using_evtmanager = FitPar::Config().GetParB("EventManager");
int input_id = -1;
if (using_evtmanager){
input_id = FitBase::GetInputID(inputfilename);
} else {
cust_event = fInput->GetEventPointer();
}
// Check if we Can't Signal Reconfigure
if (!fMCFilled){
this->Reconfigure();
return;
}
// Reset Histograms
this->ResetAll();
// READ in spline head for this input
if (fInput->GetType() == kEVTSPLINE){
FitBase::GetRW()->ReadSplineHead(fInput->GetSplineHead());
}
// Get Pointer To Base Event (Just Generator Formats)
int countwidth = (fIndex_VECT.size() / 5);
// Setup Iterators
std::vector<double>::iterator X = fXVar_VECT.begin();
std::vector<double>::iterator Y = fYVar_VECT.begin();
std::vector<double>::iterator Z = fZVar_VECT.begin();
std::vector<int>::iterator M = fMode_VECT.begin();
std::vector<UInt_t>::iterator I = fIndex_VECT.begin();
// SIGNAL LOOP
for (int i = 0; I != fIndex_VECT.end(); I++, i++){
// Just Update Weight
if (using_evtmanager){
Weight = FitBase::EvtManager().GetEventWeight(input_id, (*I));
} else {
fInput->GetTreeEntry((*I));
Weight = FitBase::GetRW()->CalcWeight(cust_event) * cust_event->InputWeight;
}
fXVar = (*X);
fYVar = (*Y);
fZVar = (*Z);
Mode = (*M);
// Set signal to true because here every event looped is true signal
Signal = true;
// Sort Histograms
this->FillHistograms();
// Get Next Iteration
X++;
Y++;
Z++;
M++;
// Print Out
if (LOG_LEVEL(REC) && (i) % countwidth == 0)
LOG(REC) << "Reconfigured " << i <<" signal events. [X,Y,Z,M,W] = ["
<< fXVar << ", " << fYVar << ", "
<< fZVar << ", " << Mode << ", "
<< Weight << "] " << std::endl;
}
// Finalise histograms
fMCFilled = true;
this->ConvertEventRates();
}
//***********************************************
void MeasurementBase::ConvertEventRates(){
//***********************************************
this->ScaleEvents();
this->ApplyNormScale( FitBase::GetRW()->GetSampleNorm( this->fName ) ) ;
}
//***********************************************
InputHandler* MeasurementBase::GetInput(){
//***********************************************
if(FitPar::Config().GetParB("EventManager")){
return FitBase::GetInput(FitBase::GetInputID(inputfilename));
} else {
return this->fInput;
}
return NULL;
};
//***********************************************
void MeasurementBase::Renormalise(){
//***********************************************
// Called when the fitter has changed a measurements normalisation but not any reweight dials
// Means we don't have to call the time consuming reconfigure when this happens.
double norm = FitBase::GetRW()->GetDialValue( this->fName + "_norm" );
if ((this->fCurrentNorm == 0.0 and norm != 0.0) or not fMCFilled){
this->ReconfigureFast();
return;
}
if (this->fCurrentNorm == norm) return;
this->ApplyNormScale( 1.0 / this->fCurrentNorm );
this->ApplyNormScale( norm );
return;
};
//***********************************************
void MeasurementBase::SetSignal(bool sig){
//***********************************************
Signal = sig;
}
//***********************************************
void MeasurementBase::SetSignal(FitEvent* evt){
//***********************************************
Signal = this->isSignal(evt);
}
//***********************************************
void MeasurementBase::SetWeight(double wght){
//***********************************************
Weight = wght;
}
//***********************************************
void MeasurementBase::SetMode(int md){
//***********************************************
Mode = md;
}
//***********************************************
std::vector<TH1*> MeasurementBase::GetFluxList(){
//***********************************************
return GetInput()->GetFluxList();
}
//***********************************************
std::vector<TH1*> MeasurementBase::GetEventRateList(){
//***********************************************
return GetInput()->GetEventList();
}
//***********************************************
std::vector<TH1*> MeasurementBase::GetXSecList(){
//***********************************************
return GetInput()->GetXSecList();
}
diff --git a/src/MINERvA/MINERvA_CC1pi0_XSec_1DEnu_antinu.cxx b/src/MINERvA/MINERvA_CC1pi0_XSec_1DEnu_antinu.cxx
index 9fa82d4..59a9b6c 100644
--- a/src/MINERvA/MINERvA_CC1pi0_XSec_1DEnu_antinu.cxx
+++ b/src/MINERvA/MINERvA_CC1pi0_XSec_1DEnu_antinu.cxx
@@ -1,71 +1,71 @@
#include "MINERvA_CC1pi0_XSec_1DEnu_antinu.h"
// The constructor
MINERvA_CC1pi0_XSec_1DEnu_antinu::MINERvA_CC1pi0_XSec_1DEnu_antinu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile) {
fName = "MINERvA_CC1pi0_XSec_1DEnu_nubar_2016";
fPlotTitles = "; E_{#nu} (GeV); d#sigma(E_{#nu}) (cm^{2}/nucleon)";
EnuMin = 1.5;
EnuMax = 10;
fIsDiag = false;
fAllowedTypes += "NEW";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CC1pi0/2016_upd/cc1pi0_enu.txt");
// MINERvA mucked up the scaling in the data-release where everything was bin-width normalised to the first bin, not the nth bin
- double binOneWidth = fDataHist->GetBinWidth(1);
+ // double binOneWidth = fDataHist->GetBinWidth(1);
for (int i = 0; i < fDataHist->GetNbinsX()+1; i++) {
- double binNWidth = fDataHist->GetBinWidth(i+1);
+ //double binNWidth = fDataHist->GetBinWidth(i+1);
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*1E-40);
fDataHist->SetBinError(i+1, fDataHist->GetBinContent(i+1)*fDataHist->GetBinError(i+1)/100.);
//fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*binOneWidth/binNWidth);
//fDataHist->SetBinError(i+1, fDataHist->GetBinError(i+1)*binOneWidth/binNWidth);
}
// This is a correlation matrix, changed to covariance in SetCovarMatrixFromText
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CC1pi0/2016_upd/cc1pi0_enu_corr.txt", fDataHist->GetNbinsX());
this->SetupDefaultHist();
fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents);
};
void MINERvA_CC1pi0_XSec_1DEnu_antinu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = (event->PartInfo(0))->fP;
TLorentzVector Ppi0;
TLorentzVector Pmu;
// Loop over the particle stack
for (unsigned int j = 2; j < event->Npart(); ++j) {
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0) continue;
int PID = (event->PartInfo(j))->fPID;
if (PID == 111) {
Ppi0 = event->PartInfo(j)->fP;
} else if (PID == -13) {
Pmu = (event->PartInfo(j))->fP;
}
}
double hadMass = FitUtils::Wrec(Pnu, Pmu);
double Enu;
if (hadMass > 100 && hadMass < 1800) {
//Enu = FitUtils::EnuCC1pi0rec(Pnu, Pmu, Ppi0);
Enu = Pnu.E()/1000.;
} else {
Enu = -999;
}
fXVar = Enu;
return;
};
//********************************************************************
bool MINERvA_CC1pi0_XSec_1DEnu_antinu::isSignal(FitEvent *event) {
//********************************************************************
return SignalDef::isCC1pi0Bar_MINERvA(event, EnuMin, EnuMax);
}
diff --git a/src/MINERvA/MINERvA_CCNpip_XSec_1DTpi_nu.cxx b/src/MINERvA/MINERvA_CCNpip_XSec_1DTpi_nu.cxx
index ef68b3d..2e62cde 100644
--- a/src/MINERvA/MINERvA_CCNpip_XSec_1DTpi_nu.cxx
+++ b/src/MINERvA/MINERvA_CCNpip_XSec_1DTpi_nu.cxx
@@ -1,224 +1,212 @@
#include "MINERvA_CCNpip_XSec_1DTpi_nu.h"
// The constructor
MINERvA_CCNpip_XSec_1DTpi_nu::MINERvA_CCNpip_XSec_1DTpi_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
fName = "MINERvA_CCNpip_XSec_1DTpi_nu";
fPlotTitles = "; T_{#pi} (MeV); d#sigma/dT_{#pi} (cm^{2}/MeV/nucleon)";
EnuMin = 1.5;
EnuMax = 10;
fIsDiag = false;
fAllowedTypes += "NEW";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// Reserve length 3 for the number of pions
piIndex.reserve(3);
TpiVect.reserve(3);
if (type.find("NEW") != std::string::npos) {
fName += "_2016";
isNew = true;
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_tpi.txt");
// MINERvA mucked up the scaling in the data-release where everything was bin-width normalised to the first bin, not the nth bin
double binOneWidth = fDataHist->GetBinWidth(1);
for (int i = 0; i < fDataHist->GetNbinsX()+1; i++) {
double binNWidth = fDataHist->GetBinWidth(i+1);
// First scale to 1E-40
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*1E-40);
// Then set the error as absolute error, not the percent error (which the datafile is listed with)
fDataHist->SetBinError(i+1, fDataHist->GetBinContent(i+1)*fDataHist->GetBinError(i+1)/100.);
// Scale the bin content
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*binOneWidth/binNWidth);
fDataHist->SetBinError(i+1, fDataHist->GetBinError(i+1)*binOneWidth/binNWidth);
}
// This is a correlation matrix
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_tpi_corr.txt", fDataHist->GetNbinsX());
} else {
isNew = false;
if (fIsShape) {
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_Tpi_shape.txt");
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_Tpi_shape_cov.txt", fDataHist->GetNbinsX());
} else {
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_Tpi.txt");
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_Tpi_cov.txt", fDataHist->GetNbinsX());
}
// Adjust MINERvA data to flux correction; roughly a 11% normalisation increase in data
for (int i = 0; i < fDataHist->GetNbinsX() + 1; i++) {
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*1.11);
}
}
- this->SetupDefaultHist();
+ SetupDefaultHist();
-<<<<<<< HEAD
- fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)/TotalIntegratedFlux("width");
-=======
// Make some auxillary helper plots
- hnPions = new TH1I((measurementName+"_Npions").c_str(), (measurementName+"_Npions; Number of pions; Counts").c_str(), 11, -1, 10);
- onePions = (TH1D*)(dataHist->Clone());
- twoPions = (TH1D*)(dataHist->Clone());
- threePions = (TH1D*)(dataHist->Clone());
- morePions = (TH1D*)(dataHist->Clone());
-
- onePions->SetNameTitle((measurementName+"_1pions").c_str(), (measurementName+"_1pions"+plotTitles).c_str());
- twoPions->SetNameTitle((measurementName+"_2pions").c_str(), (measurementName+"_2pions;"+plotTitles).c_str());
- threePions->SetNameTitle((measurementName+"_3pions").c_str(), (measurementName+"_3pions"+plotTitles).c_str());
- morePions->SetNameTitle((measurementName+"_4pions").c_str(), (measurementName+"_4pions"+plotTitles).c_str());
-
- scaleFactor = this->eventHist->Integral("width")*double(1E-38)/double(nevents)/TotalIntegratedFlux("width");
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
+ hnPions = new TH1I((fName+"_Npions").c_str(), (fName+"_Npions; Number of pions; Counts").c_str(), 11, -1, 10);
+ onePions = (TH1D*)(fDataHist->Clone());
+ twoPions = (TH1D*)(fDataHist->Clone());
+ threePions = (TH1D*)(fDataHist->Clone());
+ morePions = (TH1D*)(fDataHist->Clone());
+
+ onePions->SetNameTitle((fName+"_1pions").c_str(), (fName+"_1pions"+fPlotTitles).c_str());
+ twoPions->SetNameTitle((fName+"_2pions").c_str(), (fName+"_2pions;"+fPlotTitles).c_str());
+ threePions->SetNameTitle((fName+"_3pions").c_str(), (fName+"_3pions"+fPlotTitles).c_str());
+ morePions->SetNameTitle((fName+"_4pions").c_str(), (fName+"_4pions"+fPlotTitles).c_str());
+
+ fScaleFactor = fEventHist->Integral("width")*double(1E-38)/double(fNEvents)/TotalIntegratedFlux("width");
+
};
void MINERvA_CCNpip_XSec_1DTpi_nu::FillEventVariables(FitEvent *event) {
piIndex.clear();
TpiVect.clear();
TLorentzVector Pnu = (event->PartInfo(0))->fP;
TLorentzVector Pmu;
// Loop over the particle stack
for (unsigned int j = 2; j < event->Npart(); ++j) {
// Only include alive particles
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0) continue;
int PID = (event->PartInfo(j))->fPID;
// Pick up the charged pions
if (abs(PID) == 211) {
piIndex.push_back(j);
// Find muon
} else if (PID == 13) {
Pmu = (event->PartInfo(j))->fP;
}
}
// Hadronic mass cut in true
double hadMass = FitUtils::Wrec(Pnu, Pmu);
double Tpi = -999;
// If hadronic mass passes signal, loop over the pions
if (hadMass > 100 && hadMass < 1800 && piIndex.size() > 0) {
// Loop over surviving pions and pick up their kinetic energy
for (size_t k = 0; k < piIndex.size(); ++k) {
TLorentzVector Ppip = event->PartInfo(piIndex[k])->fP;
Tpi = FitUtils::T(Ppip)*1000.;
TpiVect.push_back(Tpi);
}
} else {
Tpi = -999;
}
fXVar = Tpi;
return;
};
//********************************************************************
// Need to override FillHistograms() here because we fill the histogram N_pion times
void MINERvA_CCNpip_XSec_1DTpi_nu::FillHistograms() {
//********************************************************************
if (Signal){
// Need to loop over all the pions in the sample
-<<<<<<< HEAD
- for (size_t k = 0; k < TpiVect.size(); ++k) {
- this->fMCHist->Fill(TpiVect.at(k), Weight);
- this->fMCFine->Fill(TpiVect.at(k), Weight);
- this->fMCStat->Fill(TpiVect.at(k), 1.0);
-
- PlotUtils::FillNeutModeArray(fMCHist_PDG, Mode, TpiVect.at(k), Weight);
-=======
for (int k = 0; k < nPions; ++k) {
double tpi = TpiVect[k];
- this->mcHist->Fill(tpi, Weight);
- this->mcFine->Fill(tpi, Weight);
- this->mcStat->Fill(tpi, 1.0);
+ this->fMCHist->Fill(tpi, Weight);
+ this->fMCFine->Fill(tpi, Weight);
+ this->fMCStat->Fill(tpi, 1.0);
if (nPions == 1) {
onePions->Fill(tpi, Weight);
} else if (nPions == 2) {
twoPions->Fill(tpi, Weight);
} else if (nPions == 3) {
threePions->Fill(tpi, Weight);
} else if (nPions > 3) {
morePions->Fill(tpi, Weight);
}
- PlotUtils::FillNeutModeArray(mcHist_PDG, Mode, TpiVect[k], Weight);
->>>>>>> 11fb11c0eacec8ee8d48186e0c9c847ce29a1930
+ PlotUtils::FillNeutModeArray(fMCHist_PDG, Mode, TpiVect[k], Weight);
}
hnPions->Fill(nPions);
}
}
//********************************************************************
bool MINERvA_CCNpip_XSec_1DTpi_nu::isSignal(FitEvent *event) {
//********************************************************************
// Last false refers to that this is NOT the restricted MINERvA phase space, in which only forward-going muons are accepted
return SignalDef::isCCNpip_MINERvA(event, nPions, EnuMin, EnuMax, false);
}
//********************************************************************
void MINERvA_CCNpip_XSec_1DTpi_nu::ScaleEvents() {
//********************************************************************
Measurement1D::ScaleEvents();
- onePions->Scale(this->scaleFactor, "width");
- twoPions->Scale(this->scaleFactor, "width");
- threePions->Scale(this->scaleFactor, "width");
- morePions->Scale(this->scaleFactor, "width");
- hnPions->Scale(this->scaleFactor, "width");
+ onePions->Scale(this->fScaleFactor, "width");
+ twoPions->Scale(this->fScaleFactor, "width");
+ threePions->Scale(this->fScaleFactor, "width");
+ morePions->Scale(this->fScaleFactor, "width");
+ hnPions->Scale(this->fScaleFactor, "width");
return;
}
//********************************************************************
void MINERvA_CCNpip_XSec_1DTpi_nu::Write(std::string drawOpts) {
//********************************************************************
Measurement1D::Write(drawOpts);
hnPions->Write();
// Draw the npions stack
onePions->SetTitle("1#pi");
onePions->SetLineColor(kBlack);
//onePions->SetFillStyle(0);
onePions->SetFillColor(onePions->GetLineColor());
twoPions->SetTitle("2#pi");
twoPions->SetLineColor(kRed);
//twoPions->SetFillStyle(0);
twoPions->SetFillColor(twoPions->GetLineColor());
threePions->SetTitle("3#pi");
threePions->SetLineColor(kGreen);
//threePions->SetFillStyle(0);
threePions->SetFillColor(threePions->GetLineColor());
morePions->SetTitle(">3#pi");
morePions->SetLineColor(kBlue);
//morePions->SetFillStyle(0);
morePions->SetFillColor(morePions->GetLineColor());
- THStack pionStack = THStack((measurementName+"_pionStack").c_str(), (measurementName+"_pionStack").c_str());
+ THStack pionStack = THStack((fName+"_pionStack").c_str(), (fName+"_pionStack").c_str());
pionStack.Add(onePions);
pionStack.Add(twoPions);
pionStack.Add(threePions);
pionStack.Add(morePions);
pionStack.Write();
return;
}
diff --git a/src/MINERvA/MINERvA_CCNpip_XSec_1Dpmu_nu.cxx b/src/MINERvA/MINERvA_CCNpip_XSec_1Dpmu_nu.cxx
index bb22b4b..ff63df9 100644
--- a/src/MINERvA/MINERvA_CCNpip_XSec_1Dpmu_nu.cxx
+++ b/src/MINERvA/MINERvA_CCNpip_XSec_1Dpmu_nu.cxx
@@ -1,70 +1,70 @@
#include "MINERvA_CCNpip_XSec_1Dpmu_nu.h"
// The constructor
MINERvA_CCNpip_XSec_1Dpmu_nu::MINERvA_CCNpip_XSec_1Dpmu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile) {
fName = "MINERvA_CCNpip_XSec_1Dpmu_nu_2016";
fPlotTitles = "; p_{#mu} (GeV); d#sigma/dp_{#mu} (cm^{2}/GeV/nucleon)";
EnuMin = 1.5;
EnuMax = 10;
fIsDiag = false;
fAllowedTypes += "NEW";
- isDiag = false;
+ fIsDiag = false;
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_pmu.txt");
// MINERvA mucked up the scaling in the data-release where everything was bin-width normalised to the first bin, not the nth bin
double binOneWidth = fDataHist->GetBinWidth(1);
for (int i = 0; i < fDataHist->GetNbinsX()+1; i++) {
double binNWidth = fDataHist->GetBinWidth(i+1);
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*1E-40);
fDataHist->SetBinError(i+1, fDataHist->GetBinContent(i+1)*fDataHist->GetBinError(i+1)/100.);
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*binOneWidth/binNWidth);
fDataHist->SetBinError(i+1, fDataHist->GetBinError(i+1)*binOneWidth/binNWidth);
}
// This is a correlation matrix, FIX IT
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_pmu_corr.txt", fDataHist->GetNbinsX());
this->SetupDefaultHist();
fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)/TotalIntegratedFlux("width");
};
void MINERvA_CCNpip_XSec_1Dpmu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = (event->PartInfo(0))->fP;
TLorentzVector Ppip;
TLorentzVector Pmu;
// Loop over the particle stack
for (unsigned int j = 2; j < event->Npart(); ++j) {
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0) continue;
int PID = (event->PartInfo(j))->fPID;
if (PID == 211 && event->PartInfo(j)->fP.E() > Ppip.E()) {
Ppip = event->PartInfo(j)->fP;
} else if (PID == 13) {
Pmu = (event->PartInfo(j))->fP;
}
}
double hadMass = FitUtils::Wrec(Pnu, Pmu);
double pmu = -999;
if (hadMass > 100 && hadMass < 1800) {
pmu = FitUtils::p(Pmu);
}
fXVar = pmu;
return;
};
//********************************************************************
bool MINERvA_CCNpip_XSec_1Dpmu_nu::isSignal(FitEvent *event) {
//********************************************************************
int dummy;
return SignalDef::isCCNpip_MINERvA(event, dummy, EnuMin, EnuMax, false);
}
diff --git a/src/MINERvA/MINERvA_CCNpip_XSec_1Dth_nu.cxx b/src/MINERvA/MINERvA_CCNpip_XSec_1Dth_nu.cxx
index 1f05dea..9f7d795 100644
--- a/src/MINERvA/MINERvA_CCNpip_XSec_1Dth_nu.cxx
+++ b/src/MINERvA/MINERvA_CCNpip_XSec_1Dth_nu.cxx
@@ -1,212 +1,212 @@
#include "MINERvA_CCNpip_XSec_1Dth_nu.h"
// The constructor
MINERvA_CCNpip_XSec_1Dth_nu::MINERvA_CCNpip_XSec_1Dth_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
fName = "MINERvA_CCNpip_XSec_1Dth_nu";
fPlotTitles = "; #theta_{#pi} (degrees); d#sigma/d#theta_{#pi} (cm^{2}/degrees/nucleon)";
EnuMin = 1.5;
EnuMax = 10;
fIsDiag = false;
fAllowedTypes += "NEW";
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
// Reserve length 3 for the number of pions
piIndex.reserve(3);
thVect.reserve(3);
if (type.find("NEW") != std::string::npos) {
fName += "_2016";
isNew = true;
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_thpi.txt");
// MINERvA mucked up the scaling in the data-release where everything was bin-width normalised to the first bin, not the nth bin
double binOneWidth = fDataHist->GetBinWidth(1);
for (int i = 0; i < fDataHist->GetNbinsX()+1; i++) {
double binNWidth = fDataHist->GetBinWidth(i+1);
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*1E-40);
fDataHist->SetBinError(i+1, fDataHist->GetBinContent(i+1)*fDataHist->GetBinError(i+1)/100.);
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*binOneWidth/binNWidth);
fDataHist->SetBinError(i+1, fDataHist->GetBinError(i+1)*binOneWidth/binNWidth);
}
// This is a correlation matrix! but it's all fixed in SetCovarMatrixFromText
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_thpi_corr.txt", fDataHist->GetNbinsX());
} else {
isNew = false;
if (fIsShape) {
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_th_shape.txt");
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_th_shape_cov.txt", fDataHist->GetNbinsX());
} else {
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_th.txt");
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/MINERvA_CCNpi_th_cov.txt", fDataHist->GetNbinsX());
}
// Adjust MINERvA data to flux correction; roughly a 11% normalisation increase in data
// Please change when MINERvA releases new data!
for (int i = 0; i < fDataHist->GetNbinsX() + 1; i++) {
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*1.11);
}
}
this->SetupDefaultHist();
// Make some auxillary helper plots
hnPions = new TH1I((fName+"_Npions").c_str(), (fName+"_Npions; Number of pions; Counts").c_str(), 11, -1, 10);
- onePions = (TH1D*)(dataHist->Clone());
- twoPions = (TH1D*)(dataHist->Clone());
- threePions = (TH1D*)(dataHist->Clone());
- morePions = (TH1D*)(dataHist->Clone());
+ onePions = (TH1D*)(fDataHist->Clone());
+ twoPions = (TH1D*)(fDataHist->Clone());
+ threePions = (TH1D*)(fDataHist->Clone());
+ morePions = (TH1D*)(fDataHist->Clone());
- onePions->SetNameTitle((fName+"_1pions").c_str(), (fName+"_1pions"+plotTitles).c_str());
- twoPions->SetNameTitle((fName+"_2pions").c_str(), (fName+"_2pions;"+plotTitles).c_str());
- threePions->SetNameTitle((fName+"_3pions").c_str(), (fName+"_3pions"+plotTitles).c_str());
- morePions->SetNameTitle((fName+"_4pions").c_str(), (fName+"_4pions"+plotTitles).c_str());
+ onePions->SetNameTitle((fName+"_1pions").c_str(), (fName+"_1pions"+fPlotTitles).c_str());
+ twoPions->SetNameTitle((fName+"_2pions").c_str(), (fName+"_2pions;"+fPlotTitles).c_str());
+ threePions->SetNameTitle((fName+"_3pions").c_str(), (fName+"_3pions"+fPlotTitles).c_str());
+ morePions->SetNameTitle((fName+"_4pions").c_str(), (fName+"_4pions"+fPlotTitles).c_str());
fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)/TotalIntegratedFlux("width");
};
void MINERvA_CCNpip_XSec_1Dth_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = (event->PartInfo(0))->fP;
TLorentzVector Pmu;
TLorentzVector Ppip;
piIndex.clear();
thVect.clear();
// Loop over the particle stack
for (unsigned int j = 2; j < event->Npart(); ++j) {
// Only include alive particles
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0) continue;
int PID = (event->PartInfo(j))->fPID;
// Select highest momentum (energy) charged pion
if (abs(PID) == 211) {
piIndex.push_back(j);
// Find muon
} else if (PID == 13) {
Pmu = (event->PartInfo(j))->fP;
}
}
double hadMass = FitUtils::Wrec(Pnu, Pmu);
double th;
// If hadronic mass passes signal, loop over the pions
if (hadMass > 100 && hadMass < 1800 && piIndex.size() > 0) {
// Loop over surviving pions and pick up their kinetic energy
for (unsigned int k = 0; k < piIndex.size(); ++k) {
Ppip = (event->PartInfo(piIndex[k]))->fP;
th = (180./M_PI)*FitUtils::th(Pnu, Ppip);
thVect.push_back(th);
}
} else {
th = -999;
}
fXVar = th;
return;
};
//********************************************************************
bool MINERvA_CCNpip_XSec_1Dth_nu::isSignal(FitEvent *event) {
//********************************************************************
// Last false refers to that this is NOT the restricted MINERvA phase space, in which only forward-going muons are accepted
return SignalDef::isCCNpip_MINERvA(event, nPions, EnuMin, EnuMax, false);
}
//********************************************************************
void MINERvA_CCNpip_XSec_1Dth_nu::ScaleEvents() {
//********************************************************************
Measurement1D::ScaleEvents();
- onePions->Scale(this->scaleFactor, "width");
- twoPions->Scale(this->scaleFactor, "width");
- threePions->Scale(this->scaleFactor, "width");
- morePions->Scale(this->scaleFactor, "width");
- hnPions->Scale(this->scaleFactor, "width");
+ onePions->Scale(this->fScaleFactor, "width");
+ twoPions->Scale(this->fScaleFactor, "width");
+ threePions->Scale(this->fScaleFactor, "width");
+ morePions->Scale(this->fScaleFactor, "width");
+ hnPions->Scale(this->fScaleFactor, "width");
return;
}
//********************************************************************
// Need to override FillHistograms() here because we fill the histogram N_pion times
void MINERvA_CCNpip_XSec_1Dth_nu::FillHistograms() {
//********************************************************************
if (Signal){
// Need to loop over all the pions in the sample
for (size_t k = 0; k < thVect.size(); ++k) {
double th = thVect[k];
this->fMCHist->Fill(th, Weight);
this->fMCFine->Fill(th, Weight);
this->fMCStat->Fill(th, 1.0);
if (nPions == 1) {
onePions->Fill(th, Weight);
} else if (nPions == 2) {
twoPions->Fill(th, Weight);
} else if (nPions == 3) {
threePions->Fill(th, Weight);
} else if (nPions > 3) {
morePions->Fill(th, Weight);
}
PlotUtils::FillNeutModeArray(fMCHist_PDG, Mode, th, Weight);
}
hnPions->Fill(nPions);
}
return;
}
//********************************************************************
void MINERvA_CCNpip_XSec_1Dth_nu::Write(std::string drawOpts) {
//********************************************************************
Measurement1D::Write(drawOpts);
hnPions->Write();
// Draw the npions stack
onePions->SetTitle("1#pi");
onePions->SetLineColor(kBlack);
//onePions->SetFillStyle(0);
onePions->SetFillColor(onePions->GetLineColor());
twoPions->SetTitle("2#pi");
twoPions->SetLineColor(kRed);
//twoPions->SetFillStyle(0);
twoPions->SetFillColor(twoPions->GetLineColor());
threePions->SetTitle("3#pi");
threePions->SetLineColor(kGreen);
//threePions->SetFillStyle(0);
threePions->SetFillColor(threePions->GetLineColor());
morePions->SetTitle(">3#pi");
morePions->SetLineColor(kBlue);
//morePions->SetFillStyle(0);
morePions->SetFillColor(morePions->GetLineColor());
THStack pionStack = THStack((fName+"_pionStack").c_str(), (fName+"_pionStack").c_str());
pionStack.Add(onePions);
pionStack.Add(twoPions);
pionStack.Add(threePions);
pionStack.Add(morePions);
pionStack.Write();
return;
}
diff --git a/src/MINERvA/MINERvA_CCNpip_XSec_1Dthmu_nu.cxx b/src/MINERvA/MINERvA_CCNpip_XSec_1Dthmu_nu.cxx
index fa3a5a1..42d77d5 100644
--- a/src/MINERvA/MINERvA_CCNpip_XSec_1Dthmu_nu.cxx
+++ b/src/MINERvA/MINERvA_CCNpip_XSec_1Dthmu_nu.cxx
@@ -1,73 +1,73 @@
#include "MINERvA_CCNpip_XSec_1Dthmu_nu.h"
// The constructor
MINERvA_CCNpip_XSec_1Dthmu_nu::MINERvA_CCNpip_XSec_1Dthmu_nu(std::string inputfile, FitWeight *rw, std::string type, std::string fakeDataFile){
fName = "MINERvA_CCNpip_XSec_1Dthmu_nu_2016";
fPlotTitles = "; #theta_{#mu} (degrees); d#sigma/d#theta_{#mu} (cm^{2}/degrees/nucleon)";
EnuMin = 1.5;
EnuMax = 10;
fIsDiag = false;
fAllowedTypes += "NEW";
- isDiag = false;
+ fIsDiag = false;
Measurement1D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
this->SetDataValues(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_thmu.txt");
// MINERvA mucked up the scaling in the data-release where everything was bin-width normalised to the first bin, not the nth bin
double binOneWidth = fDataHist->GetBinWidth(1);
for (int i = 0; i < fDataHist->GetNbinsX()+1; i++) {
double binNWidth = fDataHist->GetBinWidth(i+1);
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*1E-40);
fDataHist->SetBinError(i+1, fDataHist->GetBinContent(i+1)*fDataHist->GetBinError(i+1)/100.);
fDataHist->SetBinContent(i+1, fDataHist->GetBinContent(i+1)*binOneWidth/binNWidth);
fDataHist->SetBinError(i+1, fDataHist->GetBinError(i+1)*binOneWidth/binNWidth);
}
// This is a correlation matrix
this->SetCovarMatrixFromText(std::string(std::getenv("EXT_FIT"))+"/data/MINERvA/CCNpip/2016_upd/ccnpip_thmu_corr.txt", fDataHist->GetNbinsX());
this->SetupDefaultHist();
fScaleFactor = this->fEventHist->Integral("width")*double(1E-38)/double(fNEvents)/TotalIntegratedFlux("width");
};
void MINERvA_CCNpip_XSec_1Dthmu_nu::FillEventVariables(FitEvent *event) {
TLorentzVector Pnu = (event->PartInfo(0))->fP;
TLorentzVector Ppip;
TLorentzVector Pmu;
// Loop over the particle stack
for (unsigned int j = 2; j < event->Npart(); ++j){
if (!(event->PartInfo(j))->fIsAlive && (event->PartInfo(j))->fStatus != 0) continue;
int PID = (event->PartInfo(j))->fPID;
if (PID == 211 && event->PartInfo(j)->fP.E() > Ppip.E()) {
Ppip = event->PartInfo(j)->fP;
} else if (PID == 13) {
Pmu = (event->PartInfo(j))->fP;
}
}
double hadMass = FitUtils::Wrec(Pnu, Pmu);
double thmu;
// Include up to some given hadronic mass cut
if (hadMass > 100 && hadMass < 1800) {
thmu = (180./M_PI)*FitUtils::th(Pnu, Pmu);
} else {
thmu = -999;
}
fXVar = thmu;
return;
};
//********************************************************************
bool MINERvA_CCNpip_XSec_1Dthmu_nu::isSignal(FitEvent *event) {
//********************************************************************
// Last false refers to that this is NOT the restricted MINERvA phase space, in which only forward-going muons are accepted
int dummy;
return SignalDef::isCCNpip_MINERvA(event, dummy, EnuMin, EnuMax, false);
}
diff --git a/src/Routines/ComparisonRoutines.cxx b/src/Routines/ComparisonRoutines.cxx
index feff11a..53d4bea 100755
--- a/src/Routines/ComparisonRoutines.cxx
+++ b/src/Routines/ComparisonRoutines.cxx
@@ -1,691 +1,691 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "StatusMessage.h"
#include "ComparisonRoutines.h"
/*
Constructor/Destructor
*/
//************************
void ComparisonRoutines::Init(){
//************************
fInputFile = "";
fInputRootFile = NULL;
fOutputFile = "";
fOutputRootFile = NULL;
fStrategy = "Compare";
fRoutines.clear();
fCardFile = "";
fFakeDataInput = "";
fSampleFCN = NULL;
fAllowedRoutines = ("Compare");
};
//*************************************
ComparisonRoutines::~ComparisonRoutines(){
//*************************************
};
/*
Input Functions
*/
//*************************************
ComparisonRoutines::ComparisonRoutines(int argc, char* argv[]){
//*************************************
// Set everything to defaults
Init();
std::vector<std::string> configs_cmd;
std::string maxevents_flag = "";
int verbosity_flag = 0;
int error_flag = 0;
// If No Arguments print commands
for (int i = 1; i< argc; ++i){
if (i+1 != argc){
// Cardfile
if (!std::strcmp(argv[i], "-c")) { fCardFile=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-o")) { fOutputFile=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-f")) { fStrategy=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-q")) { configs_cmd.push_back(argv[i+1]); ++i;}
else if (!std::strcmp(argv[i], "-n")) { maxevents_flag=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-v")) { verbosity_flag -= 1; }
else if (!std::strcmp(argv[i], "+v")) { verbosity_flag += 1; }
else if (!std::strcmp(argv[i], "-e")) { error_flag -= 1; }
else if (!std::strcmp(argv[i], "+e")) { error_flag += 1; }
else {
std::cerr << "ERROR: unknown command line option given! - '"
<<argv[i]<<" "<<argv[i+1]<<"'"<< std::endl;
throw;
}
}
}
if (fCardFile.empty()){
std::cerr << "ERROR: card file not specified." << std::endl;
std::cerr << "Run with '-h' to see options." << std::endl;
throw;
}
if (fOutputFile.empty()){
std::cerr << "WARNING: output file not specified." << std::endl;
std::cerr << "Using cardfile.root" << std::endl;
fOutputFile = fCardFile + ".root";
}
// Fill fit routines and check they are good
fRoutines = PlotUtils::ParseToStr(fStrategy,",");
for (UInt_t i = 0; i < fRoutines.size(); i++){
if (fAllowedRoutines.find(fRoutines[i]) == std::string::npos){
ERR(FTL) << "Unknown fit routine given! "
<< "Must be provided as a comma seperated list." << std::endl;
ERR(FTL) << "Allowed Routines: " << fAllowedRoutines << std::endl;
throw;
}
}
// CONFIG
// ---------------------------
std::string par_dir = std::string(std::getenv("EXT_FIT"))+"/parameters/";
FitPar::Config().ReadParamFile( par_dir + "config.list.dat" );
FitPar::Config().ReadParamFile( fCardFile );
for (UInt_t iter = 0; iter < configs_cmd.size(); iter++){
FitPar::Config().ForceParam(configs_cmd[iter]);
}
if (!maxevents_flag.empty()){
FitPar::Config().SetParI("MAXEVENTS", atoi(maxevents_flag.c_str()));
}
if (verbosity_flag != 0){
int curverb = FitPar::Config().GetParI("VERBOSITY");
FitPar::Config().SetParI("VERBOSITY", curverb + verbosity_flag);
}
if (error_flag != 0){
int curwarn = FitPar::Config().GetParI("ERROR");
FitPar::Config().SetParI("ERROR", curwarn + error_flag);
}
LOG_VERB(FitPar::Config().GetParI("VERBOSITY"));
ERR_VERB(FitPar::Config().GetParI("ERROR"));
// CARD
// ---------------------------
// Parse Card Options
ReadCard(fCardFile);
// Outputs
// ---------------------------
// Save Configs to output file
fOutputRootFile = new TFile(fOutputFile.c_str(),"RECREATE");
FitPar::Config().Write();
// Starting Setup
// ---------------------------
SetupRWEngine();
SetupFCN();
return;
};
//*************************************
void ComparisonRoutines::ReadCard(std::string cardfile){
//*************************************
// Read cardlines into vector
std::vector<std::string> cardlines = PlotUtils::ParseFileToStr(cardfile,"\n");
FitPar::Config().cardLines = cardlines;
// Read Samples first (norm params can be overridden)
int linecount = 0;
for (std::vector<std::string>::iterator iter = cardlines.begin();
iter != cardlines.end(); iter++){
std::string line = (*iter);
linecount++;
// Skip Comments
if (line.empty()) continue;
if (line.c_str()[0] == '#') continue;
// Read Valid Samples
int samstatus = ReadSamples(line);
// Show line if bad to help user
if (samstatus == kErrorStatus) {
ERR(FTL) << "Bad Input in cardfile " << fCardFile
<< " at line " << linecount << "!" << endl;
cout << line << endl;
throw;
}
}
// Read Parameters second
linecount = 0;
for (std::vector<std::string>::iterator iter = cardlines.begin();
iter != cardlines.end(); iter++){
std::string line = (*iter);
linecount++;
// Skip Comments
if (line.empty()) continue;
if (line.c_str()[0] == '#') continue;
// Try Parameter Reads
int parstatus = ReadParameters(line);
int fakstatus = ReadFakeDataPars(line);
// Show line if bad to help user
if (parstatus == kErrorStatus ||
fakstatus == kErrorStatus ){
ERR(FTL) << "Bad Parameter Input in cardfile " << fCardFile
<< " at line " << linecount << "!" << endl;
cout << line << endl;
throw;
}
}
return;
};
//*****************************************
int ComparisonRoutines::ReadParameters(std::string parstring){
//******************************************
std::string inputspec = "RW Dial Inputs Syntax \n"
"free input w/ limits: TYPE NAME START MIN MAX STEP [STATE] \n"
"fix input: TYPE NAME VALUE [STATE] \n"
"free input w/o limits: TYPE NAME START FREE,[STATE] \n"
"Allowed Types: \n"
"neut_parameter,niwg_parameter,t2k_parameter,"
"nuwro_parameter,gibuu_parameter";
// Check sample input
if (parstring.find("parameter") == std::string::npos) return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(parstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(parstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0].find("parameter") == std::string::npos){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Input rw dials need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Setup default inputs
std::string partype = strvct[0];
std::string parname = strvct[1];
double parval = dblvct[2];
std::string state = "FIX"; //[DEFAULT]
// Check Type
if (FitBase::ConvDialType(partype) == kUNKNOWN){
ERR(FTL) << "Unknown parameter type! " << partype << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Check Parameter Name
if (FitBase::GetDialEnum(partype, parname) == -1){
ERR(FTL) << "Bad RW parameter name! " << partype << " " << parname << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Option Extra (No Limits)
if (strvct.size() == 4){
state = strvct[3];
}
// Run Parameter Conversion if needed
if (state.find("ABS") != std::string::npos){
parval = FitBase::RWAbsToSigma( partype, parname, parval );
} else if (state.find("FRAC") != std::string::npos){
parval = FitBase::RWFracToSigma( partype, parname, parval );
}
// Check no repeat params
if (std::find(fParams.begin(), fParams.end(), parname) != fParams.end()){
ERR(FTL) << "Duplicate parameter names given for " << parname << endl;
throw;
}
// Setup Containers
fParams.push_back(parname);
fTypeVals[parname] = FitBase::ConvDialType(partype);
fCurVals[parname] = parval;
fStateVals[parname] = state;
// Print the parameter
LOG(MIN) << "Read Parameter " << parname << " " << parval << " "
<< state << std::endl;
// Tell reader its all good
return kGoodStatus;
}
//*******************************************
int ComparisonRoutines::ReadFakeDataPars(std::string parstring){
//******************************************
std::string inputspec = "Fake Data Dial Inputs Syntax \n"
"fake value: fake_parameter NAME VALUE \n"
"Name should match dialnames given in actual dial specification.";
// Check sample input
if (parstring.find("fake_parameter") == std::string::npos)
return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(parstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(parstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0] == "fake_parameter"){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Fake dials need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Read Inputs
std::string parname = strvct[1];
double parval = dblvct[2];
// Setup Container
fFakeVals[parname] = parval;
// Print the fake parameter
LOG(MIN) << "Read Fake Parameter " << parname << " " << parval << std::endl;
// Tell reader its all good
return kGoodStatus;
}
//******************************************
int ComparisonRoutines::ReadSamples(std::string samstring){
//******************************************
std::string inputspec = "";
// Check sample input
if (samstring.find("sample") == std::string::npos)
return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(samstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(samstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0] != "sample"){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Sample need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Setup default inputs
std::string samname = strvct[1];
std::string samfile = strvct[2];
std::string samtype = "DEFAULT";
double samnorm = 1.0;
// Optional Type
if (strvct.size() > 3){
samtype = strvct[3];
}
// Optional Norm
if (strvct.size() > 4){
samnorm = dblvct[4];
}
// Add Sample Names as Norm Dials
std::string normname = samname + "_norm";
// Check no repeat params
if (std::find(fParams.begin(), fParams.end(), normname) != fParams.end()){
ERR(FTL) << "Duplicate samples given for " << samname << endl;
throw;
}
fParams.push_back(normname);
fTypeVals[normname] = kNORM;
fStateVals[normname] = samtype;
fCurVals[normname] = samnorm;
// Print read in
LOG(MIN) << "Read sample " << samname << " "
<< samfile << " " << samtype << " "
<< samnorm << endl;
// Tell reader its all good
return kGoodStatus;
}
/*
Setup Functions
*/
//*************************************
void ComparisonRoutines::SetupRWEngine(){
//*************************************
for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams[i];
FitBase::GetRW() -> IncludeDial(name, fTypeVals.at(name) );
}
return;
}
//*************************************
void ComparisonRoutines::SetupFCN(){
//*************************************
LOG(FIT)<<"Making the jointFCN"<<std::endl;
if (fSampleFCN) delete fSampleFCN;
fSampleFCN = new JointFCN(fCardFile, fOutputRootFile);
SetFakeData();
return;
}
//*************************************
void ComparisonRoutines::SetFakeData(){
//*************************************
if (fFakeDataInput.empty()) return;
if (fFakeDataInput.compare("MC") == 0){
LOG(FIT)<<"Setting fake data from MC starting prediction." <<std::endl;
UpdateRWEngine(fFakeVals);
FitBase::GetRW()->Reconfigure();
fSampleFCN->ReconfigureAllEvents();
fSampleFCN->SetFakeData("MC");
UpdateRWEngine(fCurVals);
LOG(FIT)<<"Set all data to fake MC predictions."<<std::endl;
} else {
fSampleFCN->SetFakeData(fFakeDataInput);
}
return;
}
/*
Fitting Functions
*/
//*************************************
void ComparisonRoutines::UpdateRWEngine(std::map<std::string,double>& updateVals){
//*************************************
for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams[i];
if (updateVals.find(name) == updateVals.end()) continue;
FitBase::GetRW()->SetDialValue(name,updateVals.at(name));
}
FitBase::GetRW()->Reconfigure();
return;
}
//*************************************
void ComparisonRoutines::Run(){
//*************************************
for (UInt_t i = 0; i < fRoutines.size(); i++){
std::string routine = fRoutines.at(i);
- int fitstate = kFitUnfinished;
+ //int fitstate = kFitUnfinished;
LOG(FIT)<<"Running Routine: "<<routine<<std::endl;
if (routine == "Compare"){
UpdateRWEngine(fCurVals);
GenerateComparison();
PrintState();
}
}
return;
}
//*************************************
void ComparisonRoutines::GenerateComparison(){
//*************************************
// Main Event Loop from event Manager
bool using_evtmanager = FitPar::Config().GetParB("EventManager");
if (using_evtmanager) {
std::list<MeasurementBase*> samchain = fSampleFCN->GetSampleList();
std::list<MeasurementBase*>::const_iterator iterSam = samchain.begin();
std::map<int, InputHandler*> fInputs = FitBase::EvtManager().GetInputs();
std::map<int, InputHandler*>::const_iterator iterInp = fInputs.begin();
int timestart = time(NULL);
for (; iterInp != fInputs.end(); iterInp++) {
int input_id = (iterInp->first);
InputHandler* cur_input = (iterInp->second);
FitEvent* cust_event = cur_input->GetEventPointer();
int fNEvents = cur_input->GetNEvents();
int countwidth = (fNEvents / 10);
// MAIN EVENT LOOP
for (int i = 0; i < fNEvents; i++) {
// Get Event from input list
cust_event = FitBase::EvtManager().GetEvent(input_id, i);
// Get Weight
double Weight = (FitBase::GetRW()->CalcWeight(cust_event) \
* cust_event->InputWeight);
// Skip if dodgy weight
if (fabs(cust_event->Mode) > 60 || cust_event->Mode == 0 ||
Weight > 200.0 || Weight <= 0.0)
continue;
// Loop over samples and fill histograms
iterSam = samchain.begin();
for (; iterSam != samchain.end(); iterSam++) {
MeasurementBase* exp = (*iterSam);
if (exp->GetInputID() != input_id) continue;
exp->FillEventVariables(cust_event);
exp->SetMode(cust_event->Mode);
exp->SetSignal(cust_event);
exp->SetWeight(Weight);
exp->FillHistograms();
}
// Print Out
if (LOG_LEVEL(REC) and i % countwidth == 0)
LOG(REC) << "Reconfigured " << i << " total events. W=" << Weight
<< std::endl;
}
}
// Convert Binned events
iterSam = samchain.begin();
for (; iterSam != samchain.end(); iterSam++) {
MeasurementBase* exp = (*iterSam);
exp->ConvertEventRates();
}
std::cout << " Time Taken = " << time(NULL) - timestart << std::endl;
std::cout << "Finished reconfiguring all events" << std::endl;
} else {
fSampleFCN->ReconfigureAllEvents();
}
}
//*************************************
void ComparisonRoutines::PrintState(){
//*************************************
LOG(FIT)<<"------------"<<std::endl;
// Count max size
int maxcount = 0;
for (UInt_t i = 0; i < fParams.size(); i++){
maxcount = max(int(fParams[i].size()), maxcount);
}
// Header
LOG(FIT) << " # " << left << setw(maxcount) << "Parameter "
<< " = "
<< setw(10) << "Value" << " +- "
<< setw(10) << "Error" << " "
<< setw(8) << "(Units)" << " "
<< setw(10) << "Conv. Val" << " +- "
<< setw(10) << "Conv. Err" << " "
<< setw(8) << "(Units)" << std::endl;
// Parameters
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams.at(i);
std::string typestr = FitBase::ConvDialType(fTypeVals[syst]);
std::string curunits = "(sig.)";
double curval = fCurVals[syst];
double curerr = 0.0;
if (fStateVals[syst].find("ABS") != std::string::npos){
curval = FitBase::RWSigmaToAbs(typestr, syst, curval);
curerr = (FitBase::RWSigmaToAbs(typestr, syst, curerr) -
FitBase::RWSigmaToAbs(typestr, syst, 0.0));
curunits = "(Abs.)";
} else if (fStateVals[syst].find("FRAC") != std::string::npos){
curval = FitBase::RWSigmaToFrac(typestr, syst, curval);
curerr = (FitBase::RWSigmaToFrac(typestr, syst, curerr) -
FitBase::RWSigmaToFrac(typestr, syst, 0.0));
curunits = "(Frac)";
}
std::string convunits = "(" + FitBase::GetRWUnits(typestr, syst) + ")";
double convval = FitBase::RWSigmaToAbs(typestr, syst, curval);
double converr = (FitBase::RWSigmaToAbs(typestr, syst, curerr) -
FitBase::RWSigmaToAbs(typestr, syst, 0.0));
std::ostringstream curparstring;
curparstring << " " << setw(3) << left
<< i << ". "
<< setw(maxcount) << syst << " = "
<< setw(10) << curval << " +- "
<< setw(10) << curerr << " "
<< setw(8) << curunits << " "
<< setw(10) << convval << " +- "
<< setw(10) << converr << " "
<< setw(8) << convunits;
LOG(FIT) << curparstring.str() << endl;
}
LOG(FIT)<<"------------"<<std::endl;
double like = fSampleFCN->GetLikelihood();
LOG(FIT)<<"Likelihood for JointFCN == " << like << endl;
LOG(FIT)<<"------------"<<std::endl;
}
/*
Write Functions
*/
//*************************************
void ComparisonRoutines::SaveCurrentState(std::string subdir){
//*************************************
LOG(FIT)<<"Saving current full FCN predictions" <<std::endl;
// Setup DIRS
TDirectory* curdir = gDirectory;
if (!subdir.empty()){
TDirectory* newdir =(TDirectory*) gDirectory->mkdir(subdir.c_str());
newdir->cd();
}
fSampleFCN->Write();
// Change back to current DIR
curdir->cd();
return;
}
//*************************************
void ComparisonRoutines::SaveNominal(){
//*************************************
fOutputRootFile->cd();
LOG(FIT)<<"Saving Nominal Predictions (be cautious with this)" <<std::endl;
FitBase::GetRW()->Reconfigure();
GenerateComparison();
SaveCurrentState("nominal");
};
/*
MISC Functions
*/
//*************************************
int ComparisonRoutines::GetStatus(){
//*************************************
return 0;
}
diff --git a/src/Routines/MinimizerRoutines.cxx b/src/Routines/MinimizerRoutines.cxx
index fd952ec..c1ebb6e 100755
--- a/src/Routines/MinimizerRoutines.cxx
+++ b/src/Routines/MinimizerRoutines.cxx
@@ -1,1534 +1,1534 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "StatusMessage.h"
#include "MinimizerRoutines.h"
/*
Constructor/Destructor
*/
//************************
void MinimizerRoutines::Init(){
//************************
fInputFile = "";
fInputRootFile = NULL;
fOutputFile = "";
fOutputRootFile = NULL;
fCovar = NULL;
fCovarFree = NULL;
fCorrel = NULL;
fCorrelFree = NULL;
fDecomp = NULL;
fDecompFree = NULL;
fStrategy = "Migrad,FixAtLimBreak,Migrad";
fRoutines.clear();
fCardFile = "";
fFakeDataInput = "";
fSampleFCN = NULL;
fMinimizer = NULL;
fMinimizerFCN = NULL;
fCallFunctor = NULL;
fAllowedRoutines = ("Migrad,Simplex,Combined,"
"Brute,Fumili,ConjugateFR,"
"ConjugatePR,BFGS,BFGS2,"
"SteepDesc,GSLSimAn,FixAtLim,FixAtLimBreak"
"Chi2Scan1D,Chi2Scan2D,Contours,ErrorBands");
};
//*************************************
MinimizerRoutines::~MinimizerRoutines(){
//*************************************
};
/*
Input Functions
*/
//*************************************
MinimizerRoutines::MinimizerRoutines(int argc, char* argv[]){
//*************************************
// Set everything to defaults
Init();
std::vector<std::string> configs_cmd;
std::string maxevents_flag = "";
int verbosity_flag = 0;
int error_flag = 0;
// If No Arguments print commands
for (int i = 1; i< argc; ++i){
if (i+1 != argc){
// Cardfile
if (!std::strcmp(argv[i], "-c")) { fCardFile=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-o")) { fOutputFile=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-f")) { fStrategy=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-q")) { configs_cmd.push_back(argv[i+1]); ++i;}
else if (!std::strcmp(argv[i], "-n")) { maxevents_flag=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-v")) { verbosity_flag -= 1; }
else if (!std::strcmp(argv[i], "+v")) { verbosity_flag += 1; }
else if (!std::strcmp(argv[i], "-e")) { error_flag -= 1; }
else if (!std::strcmp(argv[i], "+e")) { error_flag += 1; }
else {
std::cerr << "ERROR: unknown command line option given! - '"
<<argv[i]<<" "<<argv[i+1]<<"'"<< std::endl;
throw;
}
}
}
if (fCardFile.empty()){
std::cerr << "ERROR: card file not specified." << std::endl;
std::cerr << "Run with '-h' to see options." << std::endl;
throw;
}
if (fOutputFile.empty()){
std::cerr << "WARNING: output file not specified." << std::endl;
std::cerr << "Using cardfile.root" << std::endl;
fOutputFile = fCardFile + ".root";
}
// Fill fit routines and check they are good
fRoutines = PlotUtils::ParseToStr(fStrategy,",");
for (UInt_t i = 0; i < fRoutines.size(); i++){
if (fAllowedRoutines.find(fRoutines[i]) == std::string::npos){
ERR(FTL) << "Unknown fit routine given! "
<< "Must be provided as a comma seperated list." << std::endl;
ERR(FTL) << "Allowed Routines: " << fAllowedRoutines << std::endl;
throw;
}
}
// CONFIG
// ---------------------------
std::string par_dir = std::string(std::getenv("EXT_FIT"))+"/parameters/";
FitPar::Config().ReadParamFile( par_dir + "config.list.dat" );
FitPar::Config().ReadParamFile( fCardFile );
for (UInt_t iter = 0; iter < configs_cmd.size(); iter++){
FitPar::Config().ForceParam(configs_cmd[iter]);
}
if (!maxevents_flag.empty()){
FitPar::Config().SetParI("MAXEVENTS", atoi(maxevents_flag.c_str()));
}
if (verbosity_flag != 0){
int curverb = FitPar::Config().GetParI("VERBOSITY");
FitPar::Config().SetParI("VERBOSITY", curverb + verbosity_flag);
}
if (error_flag != 0){
int curwarn = FitPar::Config().GetParI("ERROR");
FitPar::Config().SetParI("ERROR", curwarn + error_flag);
}
LOG_VERB(FitPar::Config().GetParI("VERBOSITY"));
ERR_VERB(FitPar::Config().GetParI("ERROR"));
// CARD
// ---------------------------
// Parse Card Options
ReadCard(fCardFile);
// Outputs
// ---------------------------
// Save Configs to output file
fOutputRootFile = new TFile(fOutputFile.c_str(),"RECREATE");
FitPar::Config().Write();
// Starting Setup
// ---------------------------
SetupCovariance();
SetupRWEngine();
SetupFCN();
return;
};
//*************************************
void MinimizerRoutines::ReadCard(std::string cardfile){
//*************************************
// Read cardlines into vector
std::vector<std::string> cardlines = PlotUtils::ParseFileToStr(cardfile,"\n");
FitPar::Config().cardLines = cardlines;
// Read Samples first (norm params can be overridden)
int linecount = 0;
for (std::vector<std::string>::iterator iter = cardlines.begin();
iter != cardlines.end(); iter++){
std::string line = (*iter);
linecount++;
// Skip Comments
if (line.empty()) continue;
if (line.c_str()[0] == '#') continue;
// Read Valid Samples
int samstatus = ReadSamples(line);
// Show line if bad to help user
if (samstatus == kErrorStatus) {
ERR(FTL) << "Bad Input in cardfile " << fCardFile
<< " at line " << linecount << "!" << endl;
cout << line << endl;
throw;
}
}
// Read Parameters second
linecount = 0;
for (std::vector<std::string>::iterator iter = cardlines.begin();
iter != cardlines.end(); iter++){
std::string line = (*iter);
linecount++;
// Skip Comments
if (line.empty()) continue;
if (line.c_str()[0] == '#') continue;
// Try Parameter Reads
int parstatus = ReadParameters(line);
int fakstatus = ReadFakeDataPars(line);
// Show line if bad to help user
if (parstatus == kErrorStatus ||
fakstatus == kErrorStatus ){
ERR(FTL) << "Bad Parameter Input in cardfile " << fCardFile
<< " at line " << linecount << "!" << endl;
cout << line << endl;
throw;
}
}
return;
};
//*****************************************
int MinimizerRoutines::ReadParameters(std::string parstring){
//******************************************
std::string inputspec = "RW Dial Inputs Syntax \n"
"free input w/ limits: TYPE NAME START MIN MAX STEP [STATE] \n"
"fix input: TYPE NAME VALUE [STATE] \n"
"free input w/o limits: TYPE NAME START FREE,[STATE] \n"
"Allowed Types: \n"
"neut_parameter,niwg_parameter,t2k_parameter,"
"nuwro_parameter,gibuu_parameter";
// Check sample input
if (parstring.find("parameter") == std::string::npos) return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(parstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(parstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0].find("parameter") == std::string::npos){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Input rw dials need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Setup default inputs
std::string partype = strvct[0];
std::string parname = strvct[1];
double parval = dblvct[2];
double minval = parval - 1.0;
double maxval = parval + 1.0;
double stepval = 1.0;
std::string state = "FIX"; //[DEFAULT]
// Check Type
if (FitBase::ConvDialType(partype) == kUNKNOWN){
ERR(FTL) << "Unknown parameter type! " << partype << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Check Parameter Name
if (FitBase::GetDialEnum(partype, parname) == -1){
ERR(FTL) << "Bad RW parameter name! " << partype << " " << parname << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Option Extra (No Limits)
if (strvct.size() == 4){
state = strvct[3];
}
// Check for weirder inputs
if (strvct.size() > 4 && strvct.size() < 6){
ERR(FTL) << "Provided incomplete limits for " << parname << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Option Extra (With limits and steps)
if (strvct.size() >= 6){
minval = dblvct[3];
maxval = dblvct[4];
stepval = dblvct[5];
}
// Option Extra (dial state after limits)
if (strvct.size() == 7){
state = strvct[6];
}
// Run Parameter Conversion if needed
if (state.find("ABS") != std::string::npos){
parval = FitBase::RWAbsToSigma( partype, parname, parval );
minval = FitBase::RWAbsToSigma( partype, parname, minval );
maxval = FitBase::RWAbsToSigma( partype, parname, maxval );
stepval = FitBase::RWAbsToSigma( partype, parname, stepval );
} else if (state.find("FRAC") != std::string::npos){
parval = FitBase::RWFracToSigma( partype, parname, parval );
minval = FitBase::RWFracToSigma( partype, parname, minval );
maxval = FitBase::RWFracToSigma( partype, parname, maxval );
stepval = FitBase::RWFracToSigma( partype, parname, stepval );
}
// Check no repeat params
if (std::find(fParams.begin(), fParams.end(), parname) != fParams.end()){
ERR(FTL) << "Duplicate parameter names given for " << parname << endl;
throw;
}
// Setup Containers
fParams.push_back(parname);
fTypeVals[parname] = FitBase::ConvDialType(partype);
fStartVals[parname] = parval;
fCurVals[parname] = fStartVals[parname];
fErrorVals[parname] = 0.0;
fStateVals[parname] = state;
bool fixstate = state.find("FIX") != std::string::npos;
fFixVals[parname] = fixstate;
fStartFixVals[parname] = fFixVals[parname];
fMinVals[parname] = minval;
fMaxVals[parname] = maxval;
fStepVals[parname] = stepval;
// Print the parameter
LOG(MIN) << "Read Parameter " << parname << " " << parval << " "
<< minval << " " << maxval << " "
<< stepval << " " << state << std::endl;
// Tell reader its all good
return kGoodStatus;
}
//*******************************************
int MinimizerRoutines::ReadFakeDataPars(std::string parstring){
//******************************************
std::string inputspec = "Fake Data Dial Inputs Syntax \n"
"fake value: fake_parameter NAME VALUE \n"
"Name should match dialnames given in actual dial specification.";
// Check sample input
if (parstring.find("fake_parameter") == std::string::npos)
return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(parstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(parstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0] == "fake_parameter"){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Fake dials need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Read Inputs
std::string parname = strvct[1];
double parval = dblvct[2];
// Setup Container
fFakeVals[parname] = parval;
// Print the fake parameter
LOG(MIN) << "Read Fake Parameter " << parname << " " << parval << std::endl;
// Tell reader its all good
return kGoodStatus;
}
//******************************************
int MinimizerRoutines::ReadSamples(std::string samstring){
//******************************************
std::string inputspec = "";
// Check sample input
if (samstring.find("sample") == std::string::npos)
return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(samstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(samstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0] != "sample"){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Sample need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Setup default inputs
std::string samname = strvct[1];
std::string samfile = strvct[2];
std::string samtype = "DEFAULT";
double samnorm = 1.0;
// Optional Type
if (strvct.size() > 3){
samtype = strvct[3];
}
// Optional Norm
if (strvct.size() > 4){
samnorm = dblvct[4];
}
// Add Sample Names as Norm Dials
std::string normname = samname + "_norm";
// Check no repeat params
if (std::find(fParams.begin(), fParams.end(), normname) != fParams.end()){
ERR(FTL) << "Duplicate samples given for " << samname << endl;
throw;
}
fParams.push_back(normname);
fTypeVals[normname] = kNORM;
fStartVals[normname] = samnorm;
fCurVals[normname] = fStartVals[normname];
fErrorVals[normname] = 0.0;
fMinVals[normname] = 0.1;
fMaxVals[normname] = 10.0;
fStepVals[normname] = 0.5;
bool state = samtype.find("FREE") == std::string::npos;
fFixVals[normname] = state;
fStartFixVals[normname] = state;
// Print read in
LOG(MIN) << "Read sample " << samname << " "
<< samfile << " " << samtype << " "
<< samnorm << endl;
// Tell reader its all good
return kGoodStatus;
}
/*
Setup Functions
*/
//*************************************
void MinimizerRoutines::SetupRWEngine(){
//*************************************
for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams[i];
FitBase::GetRW() -> IncludeDial(name, fTypeVals.at(name) );
}
UpdateRWEngine(fStartVals);
return;
}
//*************************************
void MinimizerRoutines::SetupFCN(){
//*************************************
LOG(FIT)<<"Making the jointFCN"<<std::endl;
if (fSampleFCN) delete fSampleFCN;
fSampleFCN = new JointFCN(fCardFile, fOutputRootFile);
SetFakeData();
fMinimizerFCN = new MinimizerFCN( fSampleFCN );
fCallFunctor = new ROOT::Math::Functor( *fMinimizerFCN, fParams.size() );
fSampleFCN->CreateIterationTree( "fit_iterations", FitBase::GetRW() );
return;
}
//******************************************
void MinimizerRoutines::SetupFitter(std::string routine){
//******************************************
// Make the fitter
std::string fitclass = "";
std::string fittype = "";
// Get correct types
if (!routine.compare("Migrad")) { fitclass = "Minuit2"; fittype = "Migrad";
} else if (!routine.compare("Simplex")) { fitclass = "Minuit2"; fittype = "Simplex";
} else if (!routine.compare("Combined")) { fitclass = "Minuit2"; fittype = "Combined";
} else if (!routine.compare("Brute")) { fitclass = "Minuit2"; fittype = "Scan";
} else if (!routine.compare("Fumili")) { fitclass = "Minuit2"; fittype = "Fumili";
} else if (!routine.compare("ConjugateFR")) { fitclass = "GSLMultiMin"; fittype = "ConjugateFR";
} else if (!routine.compare("ConjugatePR")) { fitclass = "GSLMultiMin"; fittype = "ConjugatePR";
} else if (!routine.compare("BFGS")) { fitclass = "GSLMultiMin"; fittype = "BFGS";
} else if (!routine.compare("BFGS2")) { fitclass = "GSLMultiMin"; fittype = "BFGS2";
} else if (!routine.compare("SteepDesc")) { fitclass = "GSLMultiMin"; fittype = "SteepestDescent";
// } else if (!routine.compare("GSLMulti")) { fitclass = "GSLMultiFit"; fittype = ""; // Doesn't work out of the box
} else if (!routine.compare("GSLSimAn")) { fitclass = "GSLSimAn"; fittype = ""; }
// make minimizer
if (fMinimizer) delete fMinimizer;
fMinimizer = ROOT::Math::Factory::CreateMinimizer(fitclass, fittype);
fMinimizer->SetMaxFunctionCalls(FitPar::Config().GetParI("minimizer.maxcalls"));
if (!routine.compare("Brute")){
fMinimizer->SetMaxFunctionCalls(fParams.size() * fParams.size()*4);
fMinimizer->SetMaxIterations(fParams.size() * fParams.size()*4);
}
fMinimizer->SetMaxIterations(FitPar::Config().GetParI("minimizer.maxiterations"));
fMinimizer->SetTolerance(FitPar::Config().GetParD("minimizer.tolerance"));
fMinimizer->SetStrategy(FitPar::Config().GetParI("minimizer.strategy"));
fMinimizer->SetFunction(*fCallFunctor);
int ipar = 0;
//Add Fit Parameters
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams.at(i);
bool fixed = true;
double vstart, vstep, vlow, vhigh;
vstart = vstep = vlow = vhigh = 0.0;
if (fCurVals.find(syst) != fCurVals.end() ) vstart = fCurVals.at(syst);
if (fMinVals.find(syst) != fMinVals.end() ) vlow = fMinVals.at(syst);
if (fMaxVals.find(syst) != fMaxVals.end() ) vhigh = fMaxVals.at(syst);
if (fStepVals.find(syst) != fStepVals.end()) vstep = fStepVals.at(syst);
if (fFixVals.find(syst) != fFixVals.end() ) fixed = fFixVals.at(syst);
// fix for errors
if (vhigh == vlow) vhigh += 1.0;
fMinimizer->SetVariable(ipar, syst, vstart, vstep);
fMinimizer->SetVariableLimits(ipar,vlow,vhigh);
if (fixed) {
fMinimizer->FixVariable(ipar);
LOG(FIT) << "Fixed Param: "<<syst<<std::endl;
} else {
LOG(FIT) << "Free Param: "<<syst
<<" Start:"<<vstart
<<" Range:"<<vlow<<" to "<<vhigh
<<" Step:"<<vstep<<std::endl;
}
ipar++;
}
LOG(FIT) << "Setup Minimizer: "<<fMinimizer->NDim()<<"(NDim) "<<fMinimizer->NFree()<<"(NFree)"<<std::endl;
return;
}
//*************************************
void MinimizerRoutines::SetFakeData(){
//*************************************
if (fFakeDataInput.empty()) return;
if (fFakeDataInput.compare("MC") == 0){
LOG(FIT)<<"Setting fake data from MC starting prediction." <<std::endl;
UpdateRWEngine(fFakeVals);
FitBase::GetRW()->Reconfigure();
fSampleFCN->ReconfigureAllEvents();
fSampleFCN->SetFakeData("MC");
UpdateRWEngine(fCurVals);
LOG(FIT)<<"Set all data to fake MC predictions."<<std::endl;
} else {
fSampleFCN->SetFakeData(fFakeDataInput);
}
return;
}
/*
Fitting Functions
*/
//*************************************
void MinimizerRoutines::UpdateRWEngine(std::map<std::string,double>& updateVals){
//*************************************
for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams[i];
if (updateVals.find(name) == updateVals.end()) continue;
FitBase::GetRW()->SetDialValue(name,updateVals.at(name));
}
FitBase::GetRW()->Reconfigure();
return;
}
//*************************************
void MinimizerRoutines::Run(){
//*************************************
for (UInt_t i = 0; i < fRoutines.size(); i++){
std::string routine = fRoutines.at(i);
int fitstate = kFitUnfinished;
LOG(FIT)<<"Running Routine: "<<routine<<std::endl;
// Try Routines
if (routine.find("LowStat") != std::string::npos) LowStatRoutine(routine);
else if (routine == "FixAtLim") FixAtLimit();
else if (routine == "FixAtLimBreak") fitstate = FixAtLimit();
else if (routine.find("ErrorBands") != std::string::npos) GenerateErrorBands();
else if (!routine.compare("Chi2Scan1D")) Create1DScans();
else if (!routine.compare("Chi2Scan2D")) Chi2Scan2D();
else fitstate = RunFitRoutine(routine);
// If ending early break here
if (fitstate == kFitFinished || fitstate == kNoChange){
LOG(FIT) << "Ending fit routines loop." << endl;
break;
}
}
return;
}
//*************************************
int MinimizerRoutines::RunFitRoutine(std::string routine){
//*************************************
int endfits = kFitUnfinished;
// set fitter at the current start values
fOutputRootFile->cd();
SetupFitter(routine);
// choose what to do with the minimizer depending on routine.
if (!routine.compare("Migrad") or
!routine.compare("Simplex") or
!routine.compare("Combined") or
!routine.compare("Brute") or
!routine.compare("Fumili") or
!routine.compare("ConjugateFR") or
!routine.compare("ConjugatePR") or
!routine.compare("BFGS") or
!routine.compare("BFGS2") or
!routine.compare("SteepDesc") or
// !routine.compare("GSLMulti") or
!routine.compare("GSLSimAn")) {
if (fMinimizer->NFree() > 0){
std::cout << StatusMessage(fMinimizer->Minimize()) << std::endl;
GetMinimizerState();
}
}
// other otptions
else if (!routine.compare("Contour")) {
CreateContours();
}
return endfits;
}
//*************************************
void MinimizerRoutines::PrintState(){
//*************************************
LOG(FIT)<<"------------"<<std::endl;
// Count max size
int maxcount = 0;
for (UInt_t i = 0; i < fParams.size(); i++){
maxcount = max(int(fParams[i].size()), maxcount);
}
// Header
LOG(FIT) << " # " << left << setw(maxcount) << "Parameter "
<< " = "
<< setw(10) << "Value" << " +- "
<< setw(10) << "Error" << " "
<< setw(8) << "(Units)" << " "
<< setw(10) << "Conv. Val" << " +- "
<< setw(10) << "Conv. Err" << " "
<< setw(8) << "(Units)" << std::endl;
// Parameters
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams.at(i);
std::string typestr = FitBase::ConvDialType(fTypeVals[syst]);
std::string curunits = "(sig.)";
double curval = fCurVals[syst];
double curerr = fErrorVals[syst];
if (fStateVals[syst].find("ABS") != std::string::npos){
curval = FitBase::RWSigmaToAbs(typestr, syst, curval);
curerr = (FitBase::RWSigmaToAbs(typestr, syst, curerr) -
FitBase::RWSigmaToAbs(typestr, syst, 0.0));
curunits = "(Abs.)";
} else if (fStateVals[syst].find("FRAC") != std::string::npos){
curval = FitBase::RWSigmaToFrac(typestr, syst, curval);
curerr = (FitBase::RWSigmaToFrac(typestr, syst, curerr) -
FitBase::RWSigmaToFrac(typestr, syst, 0.0));
curunits = "(Frac)";
}
std::string convunits = "(" + FitBase::GetRWUnits(typestr, syst) + ")";
double convval = FitBase::RWSigmaToAbs(typestr, syst, curval);
double converr = (FitBase::RWSigmaToAbs(typestr, syst, curerr) -
FitBase::RWSigmaToAbs(typestr, syst, 0.0));
std::ostringstream curparstring;
curparstring << " " << setw(3) << left
<< i << ". "
<< setw(maxcount) << syst << " = "
<< setw(10) << curval << " +- "
<< setw(10) << curerr << " "
<< setw(8) << curunits << " "
<< setw(10) << convval << " +- "
<< setw(10) << converr << " "
<< setw(8) << convunits;
LOG(FIT) << curparstring.str() << endl;
}
LOG(FIT)<<"------------"<<std::endl;
double like = fSampleFCN->GetLikelihood();
LOG(FIT)<<"Likelihood for JointFCN == " << like << endl;
LOG(FIT)<<"------------"<<std::endl;
}
//*************************************
void MinimizerRoutines::GetMinimizerState(){
//*************************************
LOG(FIT) << "Minimizer State: "<<std::endl;
// Get X and Err
const double *values = fMinimizer->X();
const double *errors = fMinimizer->Errors();
- int ipar = 0;
+ // int ipar = 0;
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams.at(i);
fCurVals[syst] = values[i];
fErrorVals[syst] = errors[i];
}
PrintState();
// Covar
SetupCovariance();
if (fMinimizer->CovMatrixStatus() > 0){
// Fill Full Covar
for (int i = 0; i < fCovar->GetNbinsX(); i++){
for (int j = 0; j < fCovar->GetNbinsY(); j++){
fCovar->SetBinContent(i+1,j+1, fMinimizer->CovMatrix(i,j));
}
}
int freex = 0;
int freey = 0;
for (int i = 0; i < fCovar->GetNbinsX(); i++){
if (fMinimizer->IsFixedVariable(i)) continue;
freey = 0;
for (int j = 0; j < fCovar->GetNbinsY(); j++){
if (fMinimizer->IsFixedVariable(j)) continue;
fCovarFree->SetBinContent(freex+1,freey+1, fMinimizer->CovMatrix(i,j));
freey++;
}
freex++;
}
fCorrel = PlotUtils::GetCorrelationPlot(fCovar,"correlation");
fDecomp = PlotUtils::GetDecompPlot(fCovar,"decomposition");
if (fMinimizer->NFree() > 0){
fCorrelFree = PlotUtils::GetCorrelationPlot(fCovarFree,"correlation_free");
fDecompFree = PlotUtils::GetDecompPlot(fCovarFree,"decomposition_free");
}
}
return;
};
//*************************************
void MinimizerRoutines::LowStatRoutine(std::string routine){
//*************************************
LOG(FIT) << "Running Low Statistics Routine: "<<routine<<std::endl;
int lowstatsevents = FitPar::Config().GetParI("LOWSTATEVENTS");
int maxevents = FitPar::Config().GetParI("MAXEVENTS");
int verbosity = FitPar::Config().GetParI("VERBOSITY");
std::string trueroutine = routine;
std::string substring = "LowStat";
trueroutine.erase( trueroutine.find(substring),
substring.length() );
// Set MAX EVENTS=1000
FitPar::Config().SetParI("MAXEVENTS",lowstatsevents);
FitPar::Config().SetParI("VERBOSITY",3);
SetupFCN();
RunFitRoutine(trueroutine);
FitPar::Config().SetParI("MAXEVENTS",maxevents);
SetupFCN();
FitPar::Config().SetParI("VERBOSITY",verbosity);
return;
}
//*************************************
void MinimizerRoutines::Create1DScans(){
//*************************************
// 1D Scan Routine
// Steps through all free parameters about nominal using the step size
// Creates a graph for each free parameter
// At the current point create a 1D Scan for all parametes (Uncorrelated)
for (UInt_t i = 0; i < fParams.size(); i++){
if (fFixVals[fParams[i]]) continue;
LOG(FIT) << "Running 1D Scan for " << fParams[i] << endl;
fSampleFCN->CreateIterationTree(fParams[i] +
"_scan1D_iterations",
FitBase::GetRW());
double scanmiddlepoint = fCurVals[fParams[i]];
// Determine N points needed
double limlow = fMinVals[fParams[i]];
double limhigh = fMaxVals[fParams[i]];
double step = fStepVals[fParams[i]];
int npoints = int( fabs(limhigh - limlow)/(step+0.) );
TH1D* contour = new TH1D(("Chi2Scan1D_" + fParams[i]).c_str(),
("Chi2Scan1D_" + fParams[i] +
";" + fParams[i]).c_str(),
npoints, limlow, limhigh);
// Fill bins
for (int x = 0; x < contour->GetNbinsX(); x++){
// Set X Val
fCurVals[fParams[i]] = contour->GetXaxis()->GetBinCenter(x+1);
// Run Eval
double *vals = FitUtils::GetArrayFromMap( fParams, fCurVals );
double chi2 = fSampleFCN->DoEval( vals );
delete vals;
// Fill Contour
contour->SetBinContent(x+1, chi2);
}
// Save contour
contour->Write();
// Reset Parameter
fCurVals[fParams[i]] = scanmiddlepoint;
// Save TTree
fSampleFCN->WriteIterationTree();
}
return;
}
//*************************************
void MinimizerRoutines::Chi2Scan2D(){
//*************************************
// Chi2 Scan 2D
// Creates a 2D chi2 scan by stepping through all free parameters
// Works for all pairwise combos of free parameters
// Scan I
for (UInt_t i = 0; i < fParams.size(); i++){
if (fFixVals[fParams[i]]) continue;
// Scan J
for (UInt_t j = 0; j < i; j++){
if (fFixVals[fParams[j]]) continue;
fSampleFCN->CreateIterationTree( fParams[i] + "_" +
fParams[j] + "_" +
"scan2D_iterations",
FitBase::GetRW() );
double scanmid_i = fCurVals[fParams[i]];
double scanmid_j = fCurVals[fParams[j]];
double limlow_i = fMinVals[fParams[i]];
double limhigh_i = fMaxVals[fParams[i]];
double step_i = fStepVals[fParams[i]];
double limlow_j = fMinVals[fParams[j]];
double limhigh_j = fMaxVals[fParams[j]];
double step_j = fStepVals[fParams[j]];
int npoints_i = int( fabs(limhigh_i - limlow_i)/(step_i+0.) ) + 1;
int npoints_j = int( fabs(limhigh_j - limlow_j)/(step_j+0.) ) + 1;
TH2D* contour = new TH2D(("Chi2Scan2D_" + fParams[i] + "_" + fParams[j]).c_str(),
("Chi2Scan2D_" + fParams[i] + "_" + fParams[j] +
";" + fParams[i] + ";" + fParams[j]).c_str(),
npoints_i, limlow_i, limhigh_i,
npoints_j, limlow_j, limhigh_j );
// Begin Scan
LOG(FIT)<<"Running scan for "<<fParams[i]<<" "<<fParams[j]<<endl;
// Fill bins
for (int x = 0; x < contour->GetNbinsX(); x++){
// Set X Val
fCurVals[fParams[i]] = contour->GetXaxis()->GetBinCenter(x+1);
// Loop Y
for (int y = 0; y < contour->GetNbinsY(); y++){
// Set Y Val
fCurVals[fParams[j]] = contour->GetYaxis()->GetBinCenter(y+1);
// Run Eval
double *vals = FitUtils::GetArrayFromMap( fParams, fCurVals );
double chi2 = fSampleFCN->DoEval( vals );
delete vals;
// Fill Contour
contour->SetBinContent(x+1,y+1, chi2);
fCurVals[fParams[j]] = scanmid_j;
}
fCurVals[fParams[i]] = scanmid_i;
fCurVals[fParams[j]] = scanmid_j;
}
// Save contour
contour->Write();
// Save Iterations
fSampleFCN->WriteIterationTree();
}
}
return;
}
//*************************************
void MinimizerRoutines::CreateContours(){
//*************************************
// Use MINUIT for this if possible
ERR(FTL) << " Contours not yet implemented as it is really slow!" << endl;
throw;
return;
}
//*************************************
int MinimizerRoutines::FixAtLimit(){
//*************************************
bool fixedparam = false;
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams.at(i);
if (fFixVals[syst]) continue;
double curVal = fCurVals.at(syst);
double minVal = fMinVals.at(syst);
double maxVal = fMinVals.at(syst);
if (fabs(curVal - minVal) < 0.0001){
fCurVals[syst] = minVal;
fFixVals[syst] = true;
fixedparam = true;
}
if (fabs(maxVal - curVal) < 0.0001){
fCurVals[syst] = maxVal;
fFixVals[syst] = true;
fixedparam = true;
}
}
if (!fixedparam){
LOG(FIT) << "No dials needed fixing!" << endl;
return kNoChange;
}else return kStateChange;
}
/*
Write Functions
*/
//*************************************
void MinimizerRoutines::SaveResults(){
//*************************************
fOutputRootFile->cd();
if (fMinimizer){
SetupCovariance();
SaveMinimizerState();
}
SaveCurrentState();
}
//*************************************
void MinimizerRoutines::SaveMinimizerState(){
//*************************************
if (!fMinimizer){
ERR(FTL) << "Can't save minimizer state without min object" << endl;
throw;
}
// Save main fit tree
fSampleFCN->WriteIterationTree();
// Get Vals and Errors
GetMinimizerState();
// Save tree with fit status
std::vector<std::string> nameVect;
std::vector<double> valVect;
std::vector<double> errVect;
std::vector<double> minVect;
std::vector<double> maxVect;
std::vector<double> startVect;
std::vector<int> endfixVect;
std::vector<int> startfixVect;
// int NFREEPARS = fMinimizer->NFree();
int NPARS = fMinimizer->NDim();
int ipar = 0;
// Dial Vals
for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams.at(i);
nameVect .push_back( name );
valVect .push_back( fCurVals.at(name) );
errVect .push_back( fErrorVals.at(name) );
minVect .push_back( fMinVals.at(name) );
maxVect .push_back( fMaxVals.at(name) );
startVect .push_back( fStartVals.at(name) );
endfixVect .push_back( fFixVals.at(name) );
startfixVect.push_back( fStartFixVals.at(name) );
ipar++;
}
int NFREE = fMinimizer->NFree();
int NDIM = fMinimizer->NDim();
double CHI2 = fSampleFCN->GetLikelihood();
int NBINS = fSampleFCN->GetNDOF();
int NDOF = NBINS - NFREE;
// Write fit results
TTree* fit_tree = new TTree("fit_result","fit_result");
fit_tree->Branch("parameter_names",&nameVect);
fit_tree->Branch("parameter_values",&valVect);
fit_tree->Branch("parameter_errors",&errVect);
fit_tree->Branch("parameter_min",&minVect);
fit_tree->Branch("parameter_max",&maxVect);
fit_tree->Branch("parameter_start",&startVect);
fit_tree->Branch("parameter_fix",&endfixVect);
fit_tree->Branch("parameter_startfix",&startfixVect);
fit_tree->Branch("CHI2",&CHI2,"CHI2/D");
fit_tree->Branch("NDOF",&NDOF,"NDOF/I");
fit_tree->Branch("NBINS",&NBINS,"NBINS/I");
fit_tree->Branch("NDIM",&NDIM,"NDIM/I");
fit_tree->Branch("NFREE",&NFREE,"NFREE/I");
fit_tree->Fill();
fit_tree->Write();
// Make dial variables
TH1D dialvar = TH1D("fit_dials","fit_dials",NPARS,0,NPARS);
TH1D startvar = TH1D("start_dials","start_dials",NPARS,0,NPARS);
TH1D minvar = TH1D("min_dials","min_dials",NPARS,0,NPARS);
TH1D maxvar = TH1D("max_dials","max_dials",NPARS,0,NPARS);
TH1D dialvarfree = TH1D("fit_dials_free","fit_dials_free",NFREE,0,NFREE);
TH1D startvarfree = TH1D("start_dials_free","start_dials_free",NFREE,0,NFREE);
TH1D minvarfree = TH1D("min_dials_free","min_dials_free",NFREE,0,NFREE);
TH1D maxvarfree = TH1D("max_dials_free","max_dials_free",NFREE,0,NFREE);
int freecount = 0;
for (UInt_t i = 0; i < nameVect.size(); i++){
std::string name = nameVect.at(i);
dialvar.SetBinContent(i+1, valVect.at(i));
dialvar.SetBinError(i+1, errVect.at(i));
dialvar.GetXaxis()->SetBinLabel(i+1, name.c_str());
startvar.SetBinContent(i+1, startVect.at(i));
startvar.GetXaxis()->SetBinLabel(i+1, name.c_str());
minvar.SetBinContent(i+1, minVect.at(i));
minvar.GetXaxis()->SetBinLabel(i+1, name.c_str());
maxvar.SetBinContent(i+1, maxVect.at(i));
maxvar.GetXaxis()->SetBinLabel(i+1, name.c_str());
if (!startfixVect.at(i)){
freecount++;
dialvarfree.SetBinContent(freecount, valVect.at(i));
dialvarfree.SetBinError(freecount, errVect.at(i));
dialvarfree.GetXaxis()->SetBinLabel(freecount, name.c_str());
startvarfree.SetBinContent(freecount, startVect.at(i));
startvarfree.GetXaxis()->SetBinLabel(freecount, name.c_str());
minvarfree.SetBinContent(freecount, minVect.at(i));
minvarfree.GetXaxis()->SetBinLabel(freecount, name.c_str());
maxvarfree.SetBinContent(freecount, maxVect.at(i));
maxvarfree.GetXaxis()->SetBinLabel(freecount, name.c_str());
}
}
// Save Dial Plots
dialvar.Write();
startvar.Write();
minvar.Write();
maxvar.Write();
dialvarfree.Write();
startvarfree.Write();
minvarfree.Write();
maxvarfree.Write();
// Save fit_status plot
TH1D statusplot = TH1D("fit_status","fit_status",8,0,8);
std::string fit_labels[8] = {"status", "cov_status", \
"maxiter", "maxfunc", \
"iter", "func", \
"precision", "tolerance"};
double fit_vals[8];
fit_vals[0] = fMinimizer->Status() + 0.;
fit_vals[1] = fMinimizer->CovMatrixStatus() + 0.;
fit_vals[2] = fMinimizer->MaxIterations() + 0.;
fit_vals[3] = fMinimizer->MaxFunctionCalls()+ 0.;
fit_vals[4] = fMinimizer->NIterations() + 0.;
fit_vals[5] = fMinimizer->NCalls() + 0.;
fit_vals[6] = fMinimizer->Precision() + 0.;
fit_vals[7] = fMinimizer->Tolerance() + 0.;
for (int i = 0; i < 8; i++){
statusplot.SetBinContent(i+1, fit_vals[i]);
statusplot.GetXaxis()->SetBinLabel(i+1, fit_labels[i].c_str());
}
statusplot.Write();
// Save Covars
if (fCovar) fCovar->Write();
if (fCovarFree) fCovarFree->Write();
if (fCorrel) fCorrel->Write();
if (fCorrelFree) fCorrelFree->Write();
if (fDecomp) fDecomp->Write();
if (fDecompFree) fDecompFree->Write();
return;
}
//*************************************
void MinimizerRoutines::SaveCurrentState(std::string subdir){
//*************************************
LOG(FIT)<<"Saving current full FCN predictions" <<std::endl;
// Setup DIRS
TDirectory* curdir = gDirectory;
if (!subdir.empty()){
TDirectory* newdir =(TDirectory*) gDirectory->mkdir(subdir.c_str());
newdir->cd();
}
FitBase::GetRW()->Reconfigure();
fSampleFCN->ReconfigureAllEvents();
fSampleFCN->Write();
// Change back to current DIR
curdir->cd();
return;
}
//*************************************
void MinimizerRoutines::SaveNominal(){
//*************************************
fOutputRootFile->cd();
LOG(FIT)<<"Saving Nominal Predictions (be cautious with this)" <<std::endl;
FitBase::GetRW()->Reconfigure();
SaveCurrentState("nominal");
};
//*************************************
void MinimizerRoutines::SavePrefit(){
//*************************************
fOutputRootFile->cd();
LOG(FIT)<<"Saving Prefit Predictions"<<std::endl;
UpdateRWEngine(fStartVals);
SaveCurrentState("prefit");
UpdateRWEngine(fCurVals);
};
/*
MISC Functions
*/
//*************************************
int MinimizerRoutines::GetStatus(){
//*************************************
return 0;
}
//*************************************
void MinimizerRoutines::SetupCovariance(){
//*************************************
// Remove covares if they exist
if (fCovar) delete fCovar;
if (fCovarFree) delete fCovarFree;
if (fCorrel) delete fCorrel;
if (fCorrelFree) delete fCorrelFree;
if (fDecomp) delete fDecomp;
if (fDecompFree) delete fDecompFree;
int NFREE = 0;
int NDIM = 0;
// Get NFREE from min or from vals (for cases when doing throws)
if (fMinimizer){
NFREE = fMinimizer->NFree();
NDIM = fMinimizer->NDim();
} else {
NDIM = fParams.size();
for (UInt_t i = 0; i < fParams.size(); i++){
if (!fFixVals[fParams[i]]) NFREE++;
}
}
if (NDIM == 0) return;
cout << "NFREE == " << NFREE << endl;
fCovar = new TH2D("covariance","covariance",NDIM,0,NDIM,NDIM,0,NDIM);
if (NFREE > 0){
fCovarFree = new TH2D("covariance_free",
"covariance_free",
NFREE,0,NFREE,
NFREE,0,NFREE);
}
// Set Bin Labels
int countall = 0;
int countfree = 0;
for (UInt_t i = 0; i < fParams.size(); i++){
fCovar->GetXaxis()->SetBinLabel(countall+1,fParams[i].c_str());
fCovar->GetYaxis()->SetBinLabel(countall+1,fParams[i].c_str());
countall++;
if (!fFixVals[fParams[i]] and NFREE > 0){
fCovarFree->GetXaxis()->SetBinLabel(countfree+1,fParams[i].c_str());
fCovarFree->GetYaxis()->SetBinLabel(countfree+1,fParams[i].c_str());
countfree++;
}
}
fCorrel = PlotUtils::GetCorrelationPlot(fCovar,"correlation");
fDecomp = PlotUtils::GetDecompPlot(fCovar,"decomposition");
if (NFREE > 0) fCorrelFree = PlotUtils::GetCorrelationPlot(fCovarFree, "correlation_free");
if (NFREE > 0) fDecompFree = PlotUtils::GetDecompPlot(fCovarFree,"decomposition_free");
return;
};
//*************************************
void MinimizerRoutines::ThrowCovariance(bool uniformly){
//*************************************
std::vector<double> rands;
if (!fDecompFree) {
ERR(WRN) << "Trying to throw 0 free parameters"<<std::endl;
return;
}
// Generate Random Gaussians
for (Int_t i = 0; i < fDecompFree->GetNbinsX(); i++){
rands.push_back(gRandom->Gaus(0.0,1.0));
}
// Reset Thrown Values
for (UInt_t i = 0; i < fParams.size(); i++){
fThrownVals[fParams[i]] = fCurVals[fParams[i]];
}
// Loop and get decomp
for (Int_t i = 0; i < fDecompFree->GetNbinsX(); i++){
std::string parname = std::string(fDecompFree->GetXaxis()->GetBinLabel(i+1));
double mod = 0.0;
if (!uniformly){
for (Int_t j = 0; j < fDecompFree->GetNbinsY(); j++){
mod += rands[j] * fDecompFree->GetBinContent(j+1,i+1);
}
}
if (fCurVals.find(parname) != fCurVals.end()) {
if (uniformly) fThrownVals[parname] = gRandom->Uniform(fMinVals[parname],fMaxVals[parname]);
else { fThrownVals[parname] = fCurVals[parname] + mod; }
}
}
// Check Limits
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams[i];
if (fFixVals[syst]) continue;
if (fThrownVals[syst] < fMinVals[syst]) fThrownVals[syst] = fMinVals[syst];
if (fThrownVals[syst] > fMaxVals[syst]) fThrownVals[syst] = fMaxVals[syst];
}
return;
};
//*************************************
void MinimizerRoutines::GenerateErrorBands(){
//*************************************
TDirectory* errorDIR = (TDirectory*) fOutputRootFile->mkdir("error_bands");
errorDIR->cd();
TFile* tempfile = new TFile((fOutputFile + ".throws.root").c_str(),"RECREATE");
tempfile->cd();
int nthrows = FitPar::Config().GetParI("error_throws");
UpdateRWEngine(fCurVals);
fSampleFCN->ReconfigureAllEvents();
TDirectory* nominal = (TDirectory*) tempfile->mkdir("nominal");
nominal->cd();
fSampleFCN->Write();
TDirectory* outnominal = (TDirectory*) fOutputRootFile->mkdir("nominal_throw");
outnominal->cd();
fSampleFCN->Write();
errorDIR->cd();
TTree* parameterTree = new TTree("throws","throws");
double chi2;
for (UInt_t i = 0; i < fParams.size(); i++)
parameterTree->Branch(fParams[i].c_str(), &fThrownVals[fParams[i]], (fParams[i] + "/D").c_str());
parameterTree->Branch("chi2",&chi2,"chi2/D");
bool uniformly = FitPar::Config().GetParB("error_uniform");
// Run Throws and save
for (Int_t i = 0; i < nthrows; i++){
TDirectory* throwfolder = (TDirectory*)tempfile->mkdir(Form("throw_%i",i));
throwfolder->cd();
// Generate Random Parameter Throw
ThrowCovariance(uniformly);
// Run Eval
double *vals = FitUtils::GetArrayFromMap( fParams, fThrownVals );
- double chi2 = fSampleFCN->DoEval( vals );
+ chi2 = fSampleFCN->DoEval( vals );
delete vals;
// Save the FCN
fSampleFCN->Write();
parameterTree->Fill();
}
errorDIR->cd();
fDecompFree->Write();
fCovarFree->Write();
parameterTree->Write();
delete parameterTree;
// Now go through the keys in the temporary file and look for TH1D, and TH2D plots
TIter next(nominal->GetListOfKeys());
TKey *key;
while ((key = (TKey*)next())) {
TClass *cl = gROOT->GetClass(key->GetClassName());
if (!cl->InheritsFrom("TH1D") and !cl->InheritsFrom("TH2D")) continue;
TH1D *baseplot = (TH1D*)key->ReadObj();
std::string plotname = std::string(baseplot->GetName());
int nbins = baseplot->GetNbinsX()*baseplot->GetNbinsY();
// Setup TProfile with RMS option
TProfile* tprof = new TProfile((plotname + "_prof").c_str(),(plotname + "_prof").c_str(),nbins, 0, nbins, "S");
// Setup The TTREE
double* bincontents;
bincontents = new double[nbins];
double* binlowest;
binlowest = new double[nbins];
double* binhighest;
binhighest = new double[nbins];
errorDIR->cd();
TTree* bintree = new TTree((plotname + "_tree").c_str(), (plotname + "_tree").c_str());
for (Int_t i = 0; i < nbins; i++){
bincontents[i] = 0.0;
binhighest[i] = 0.0;
binlowest[i] = 0.0;
bintree->Branch(Form("content_%i",i),&bincontents[i],Form("content_%i/D",i));
}
for (Int_t i = 0; i < nthrows; i++){
TH1* newplot = (TH1*)tempfile->Get(Form(("throw_%i/" + plotname).c_str(),i));
for (Int_t j = 0; j < nbins; j++){
tprof->Fill(j+0.5, newplot->GetBinContent(j+1));
bincontents[j] = newplot->GetBinContent(j+1);
if (bincontents[j] < binlowest[j] or i == 0) binlowest[j] = bincontents[j];
if (bincontents[j] > binhighest[j] or i == 0) binhighest[j] = bincontents[j];
}
errorDIR->cd();
bintree->Fill();
delete newplot;
}
errorDIR->cd();
for (Int_t j = 0; j < nbins; j++){
if (!uniformly){
baseplot->SetBinError(j+1,tprof->GetBinError(j+1));
} else {
baseplot->SetBinContent(j+1, (binlowest[j] + binhighest[j]) / 2.0);
baseplot->SetBinError(j+1, (binhighest[j] - binlowest[j])/2.0);
}
}
errorDIR->cd();
baseplot->Write();
tprof->Write();
bintree->Write();
delete baseplot;
delete tprof;
delete bintree;
delete [] bincontents;
}
return;
};
diff --git a/src/Routines/SystematicRoutines.cxx b/src/Routines/SystematicRoutines.cxx
index c66dbcc..837a371 100755
--- a/src/Routines/SystematicRoutines.cxx
+++ b/src/Routines/SystematicRoutines.cxx
@@ -1,1158 +1,1158 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "StatusMessage.h"
#include "SystematicRoutines.h"
/*
Constructor/Destructor
*/
//************************
void SystematicRoutines::Init(){
//************************
fInputFile = "";
fInputRootFile = NULL;
fOutputFile = "";
fOutputRootFile = NULL;
fCovar = fCovarFree = NULL;
fCorrel = fCorrelFree = NULL;
fDecomp = fDecompFree = NULL;
fStrategy = "ErrorBands";
fRoutines.clear();
fCardFile = "";
fFakeDataInput = "";
fSampleFCN = NULL;
fAllowedRoutines = ("ErrorBands,PlotLimits");
};
//*************************************
SystematicRoutines::~SystematicRoutines(){
//*************************************
};
/*
Input Functions
*/
//*************************************
SystematicRoutines::SystematicRoutines(int argc, char* argv[]){
//*************************************
// Set everything to defaults
Init();
std::vector<std::string> configs_cmd;
std::string maxevents_flag = "";
int verbosity_flag = 0;
int error_flag = 0;
// If No Arguments print commands
for (int i = 1; i< argc; ++i){
if (i+1 != argc){
// Cardfile
if (!std::strcmp(argv[i], "-c")) { fCardFile=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-o")) { fOutputFile=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-f")) { fStrategy=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-q")) { configs_cmd.push_back(argv[i+1]); ++i;}
else if (!std::strcmp(argv[i], "-n")) { maxevents_flag=argv[i+1]; ++i;}
else if (!std::strcmp(argv[i], "-v")) { verbosity_flag -= 1; }
else if (!std::strcmp(argv[i], "+v")) { verbosity_flag += 1; }
else if (!std::strcmp(argv[i], "-e")) { error_flag -= 1; }
else if (!std::strcmp(argv[i], "+e")) { error_flag += 1; }
else {
std::cerr << "ERROR: unknown command line option given! - '"
<<argv[i]<<" "<<argv[i+1]<<"'"<< std::endl;
throw;
}
}
}
if (fCardFile.empty()){
std::cerr << "ERROR: card file not specified." << std::endl;
std::cerr << "Run with '-h' to see options." << std::endl;
throw;
}
if (fOutputFile.empty()){
std::cerr << "WARNING: output file not specified." << std::endl;
std::cerr << "Using cardfile.root" << std::endl;
fOutputFile = fCardFile + ".root";
}
// Fill fit routines and check they are good
fRoutines = PlotUtils::ParseToStr(fStrategy,",");
for (UInt_t i = 0; i < fRoutines.size(); i++){
if (fAllowedRoutines.find(fRoutines[i]) == std::string::npos){
ERR(FTL) << "Unknown fit routine given! "
<< "Must be provided as a comma seperated list." << std::endl;
ERR(FTL) << "Allowed Routines: " << fAllowedRoutines << std::endl;
throw;
}
}
// CONFIG
// ---------------------------
std::string par_dir = std::string(std::getenv("EXT_FIT"))+"/parameters/";
FitPar::Config().ReadParamFile( par_dir + "config.list.dat" );
FitPar::Config().ReadParamFile( fCardFile );
for (UInt_t iter = 0; iter < configs_cmd.size(); iter++){
FitPar::Config().ForceParam(configs_cmd[iter]);
}
if (!maxevents_flag.empty()){
FitPar::Config().SetParI("MAXEVENTS", atoi(maxevents_flag.c_str()));
}
if (verbosity_flag != 0){
int curverb = FitPar::Config().GetParI("VERBOSITY");
FitPar::Config().SetParI("VERBOSITY", curverb + verbosity_flag);
}
if (error_flag != 0){
int curwarn = FitPar::Config().GetParI("ERROR");
FitPar::Config().SetParI("ERROR", curwarn + error_flag);
}
LOG_VERB(FitPar::Config().GetParI("VERBOSITY"));
ERR_VERB(FitPar::Config().GetParI("ERROR"));
// CARD
// ---------------------------
// Parse Card Options
ReadCard(fCardFile);
// Outputs
// ---------------------------
// Save Configs to output file
fOutputRootFile = new TFile(fOutputFile.c_str(),"RECREATE");
FitPar::Config().Write();
// Starting Setup
// ---------------------------
SetupCovariance();
SetupFCN();
GetCovarFromFCN();
SetupRWEngine();
return;
};
//*************************************
void SystematicRoutines::ReadCard(std::string cardfile){
//*************************************
// Read cardlines into vector
std::vector<std::string> cardlines = PlotUtils::ParseFileToStr(cardfile,"\n");
FitPar::Config().cardLines = cardlines;
// Read Samples first (norm params can be overridden)
int linecount = 0;
for (std::vector<std::string>::iterator iter = cardlines.begin();
iter != cardlines.end(); iter++){
std::string line = (*iter);
linecount++;
// Skip Comments
if (line.empty()) continue;
if (line.c_str()[0] == '#') continue;
// Read Valid Samples
int samstatus = ReadSamples(line);
// Show line if bad to help user
if (samstatus == kErrorStatus) {
ERR(FTL) << "Bad Input in cardfile " << fCardFile
<< " at line " << linecount << "!" << endl;
cout << line << endl;
throw;
}
}
// Read Parameters second
linecount = 0;
for (std::vector<std::string>::iterator iter = cardlines.begin();
iter != cardlines.end(); iter++){
std::string line = (*iter);
linecount++;
// Skip Comments
if (line.empty()) continue;
if (line.c_str()[0] == '#') continue;
// Try Parameter Reads
int parstatus = ReadParameters(line);
int fakstatus = ReadFakeDataPars(line);
// Show line if bad to help user
if (parstatus == kErrorStatus ||
fakstatus == kErrorStatus ){
ERR(FTL) << "Bad Parameter Input in cardfile " << fCardFile
<< " at line " << linecount << "!" << endl;
cout << line << endl;
throw;
}
}
return;
};
//*****************************************
int SystematicRoutines::ReadParameters(std::string parstring){
//******************************************
std::string inputspec = "RW Dial Inputs Syntax \n"
"free input w/ limits: TYPE NAME START MIN MAX STEP [STATE] \n"
"fix input: TYPE NAME VALUE [STATE] \n"
"free input w/o limits: TYPE NAME START FREE,[STATE] \n"
"Allowed Types: \n"
"neut_parameter,niwg_parameter,t2k_parameter,"
"nuwro_parameter,gibuu_parameter";
// Check sample input
if (parstring.find("parameter") == std::string::npos) return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(parstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(parstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0].find("parameter") == std::string::npos){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Input rw dials need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Setup default inputs
std::string partype = strvct[0];
std::string parname = strvct[1];
double parval = dblvct[2];
double minval = parval - 1.0;
double maxval = parval + 1.0;
double stepval = 1.0;
std::string state = "FIX"; //[DEFAULT]
// Check Type
if (FitBase::ConvDialType(partype) == kUNKNOWN){
ERR(FTL) << "Unknown parameter type! " << partype << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Check Parameter Name
if (FitBase::GetDialEnum(partype, parname) == -1){
ERR(FTL) << "Bad RW parameter name! " << partype << " " << parname << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Option Extra (No Limits)
if (strvct.size() == 4){
state = strvct[3];
}
// Check for weirder inputs
if (strvct.size() > 4 && strvct.size() < 6){
ERR(FTL) << "Provided incomplete limits for " << parname << endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Option Extra (With limits and steps)
if (strvct.size() >= 6){
minval = dblvct[3];
maxval = dblvct[4];
stepval = dblvct[5];
}
// Option Extra (dial state after limits)
if (strvct.size() == 7){
state = strvct[6];
}
// Run Parameter Conversion if needed
if (state.find("ABS") != std::string::npos){
parval = FitBase::RWAbsToSigma( partype, parname, parval );
minval = FitBase::RWAbsToSigma( partype, parname, minval );
maxval = FitBase::RWAbsToSigma( partype, parname, maxval );
stepval = FitBase::RWAbsToSigma( partype, parname, stepval );
} else if (state.find("FRAC") != std::string::npos){
parval = FitBase::RWFracToSigma( partype, parname, parval );
minval = FitBase::RWFracToSigma( partype, parname, minval );
maxval = FitBase::RWFracToSigma( partype, parname, maxval );
stepval = FitBase::RWFracToSigma( partype, parname, stepval );
}
// Check no repeat params
if (std::find(fParams.begin(), fParams.end(), parname) != fParams.end()){
ERR(FTL) << "Duplicate parameter names given for " << parname << endl;
throw;
}
// Setup Containers
fParams.push_back(parname);
fTypeVals[parname] = FitBase::ConvDialType(partype);
fStartVals[parname] = parval;
fCurVals[parname] = fStartVals[parname];
fErrorVals[parname] = 0.0;
fStateVals[parname] = state;
bool fixstate = state.find("FIX") != std::string::npos;
fFixVals[parname] = fixstate;
fStartFixVals[parname] = fFixVals[parname];
fMinVals[parname] = minval;
fMaxVals[parname] = maxval;
fStepVals[parname] = stepval;
// Print the parameter
LOG(MIN) << "Read Parameter " << parname << " " << parval << " "
<< minval << " " << maxval << " "
<< stepval << " " << state << std::endl;
// Tell reader its all good
return kGoodStatus;
}
//*******************************************
int SystematicRoutines::ReadFakeDataPars(std::string parstring){
//******************************************
std::string inputspec = "Fake Data Dial Inputs Syntax \n"
"fake value: fake_parameter NAME VALUE \n"
"Name should match dialnames given in actual dial specification.";
// Check sample input
if (parstring.find("fake_parameter") == std::string::npos)
return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(parstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(parstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0] == "fake_parameter"){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Fake dials need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Read Inputs
std::string parname = strvct[1];
double parval = dblvct[2];
// Setup Container
fFakeVals[parname] = parval;
// Print the fake parameter
LOG(MIN) << "Read Fake Parameter " << parname << " " << parval << std::endl;
// Tell reader its all good
return kGoodStatus;
}
//******************************************
int SystematicRoutines::ReadSamples(std::string samstring){
//******************************************
std::string inputspec = "";
// Check sample input
if (samstring.find("sample") == std::string::npos)
return kGoodStatus;
// Parse inputs
std::vector<std::string> strvct = PlotUtils::ParseToStr(samstring, " ");
std::vector<double> dblvct = PlotUtils::ParseToDbl(samstring, " ");
// Skip if comment or parameter somewhere later in line
if (strvct[0].c_str()[0] == '#' ||
strvct[0] != "sample"){
return kGoodStatus;
}
// Check length
if (strvct.size() < 3){
ERR(FTL) << "Sample need to provide at least 3 inputs." << std::endl;
std::cout << inputspec << std::endl;
return kErrorStatus;
}
// Setup default inputs
std::string samname = strvct[1];
std::string samfile = strvct[2];
std::string samtype = "DEFAULT";
double samnorm = 1.0;
// Optional Type
if (strvct.size() > 3){
samtype = strvct[3];
}
// Optional Norm
if (strvct.size() > 4){
samnorm = dblvct[4];
}
// Add Sample Names as Norm Dials
std::string normname = samname + "_norm";
// Check no repeat params
if (std::find(fParams.begin(), fParams.end(), normname) != fParams.end()){
ERR(FTL) << "Duplicate samples given for " << samname << endl;
throw;
}
fParams.push_back(normname);
fTypeVals[normname] = kNORM;
fStartVals[normname] = samnorm;
fCurVals[normname] = fStartVals[normname];
fErrorVals[normname] = 0.0;
fMinVals[normname] = 0.1;
fMaxVals[normname] = 10.0;
fStepVals[normname] = 0.5;
bool state = samtype.find("FREE") == std::string::npos;
fFixVals[normname] = state;
fStartFixVals[normname] = state;
// Print read in
LOG(MIN) << "Read sample " << samname << " "
<< samfile << " " << samtype << " "
<< samnorm << endl;
// Tell reader its all good
return kGoodStatus;
}
/*
Setup Functions
*/
//*************************************
void SystematicRoutines::SetupRWEngine(){
//*************************************
for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams[i];
FitBase::GetRW() -> IncludeDial(name, fTypeVals.at(name) );
}
UpdateRWEngine(fStartVals);
return;
}
//*************************************
void SystematicRoutines::SetupFCN(){
//*************************************
LOG(FIT)<<"Making the jointFCN"<<std::endl;
if (fSampleFCN) delete fSampleFCN;
fSampleFCN = new JointFCN(fCardFile, fOutputRootFile);
SetFakeData();
return;
}
//*************************************
void SystematicRoutines::SetFakeData(){
//*************************************
if (fFakeDataInput.empty()) return;
if (fFakeDataInput.compare("MC") == 0){
LOG(FIT)<<"Setting fake data from MC starting prediction." <<std::endl;
UpdateRWEngine(fFakeVals);
FitBase::GetRW()->Reconfigure();
fSampleFCN->ReconfigureAllEvents();
fSampleFCN->SetFakeData("MC");
UpdateRWEngine(fCurVals);
LOG(FIT)<<"Set all data to fake MC predictions."<<std::endl;
} else {
fSampleFCN->SetFakeData(fFakeDataInput);
}
return;
}
//*****************************************
void SystematicRoutines::GetCovarFromFCN(){
//*****************************************
LOG(FIT) << "Loading ParamPull objects from FCN to build covar" << endl;
// Make helperstring
std::ostringstream helperstr;
// Keep track of what is being thrown
std::map<std::string, std::string> dialthrowhandle;
// Get Covariance Objects from FCN
std::list<ParamPull*> inputpulls = fSampleFCN->GetPullList();
for (PullListConstIter iter = inputpulls.begin();
iter != inputpulls.end(); iter++){
ParamPull* pull = (*iter);
if (pull->GetType().find("THROW")){
fInputThrows.push_back(pull);
fInputCovar.push_back(pull->GetFullCovarMatrix());
fInputDials.push_back(pull->GetDataHist());
LOG(FIT) << "Read ParamPull: " << pull->GetName() << " " << pull->GetType() << endl;
}
TH1D dialhist = pull->GetDataHist();
TH1D minhist = pull->GetMinHist();
TH1D maxhist = pull->GetMaxHist();
TH1I typehist = pull->GetDialTypes();
for (int i = 0; i < dialhist.GetNbinsX(); i++){
std::string name = std::string(dialhist.GetXaxis()->GetBinLabel(i+1));
dialthrowhandle[name] = pull->GetName();
if (fCurVals.find(name) == fCurVals.end()){
ERR(WRN) << name << " Dial not found in throws, so adding that. " << endl;
// Add to Containers
fParams.push_back(name);
fCurVals[name] = dialhist.GetBinContent(i+1);
fStartVals[name] = dialhist.GetBinContent(i+1);
fMinVals[name] = minhist.GetBinContent(i+1);
fMaxVals[name] = maxhist.GetBinContent(i+1);
fStepVals[name] = 1.0;
fFixVals[name] = false;
fStartFixVals[name] = false;
fTypeVals[name] = typehist.GetBinContent(i+1);
fStateVals[name] = "FREE" + pull->GetType();
// Maker Helper
helperstr << FitBase::ConvDialType(fTypeVals[name]) << " "
<< name << " " << fMinVals[name] << " "
<< fMaxVals[name] << " " << fStepVals[name] << " " << fStateVals[name] << endl;
}
}
}
// Check if no throws given
if (fInputThrows.empty()){
ERR(WRN) << "No covariances given to nuissyst" << endl;
ERR(WRN) << "Pushing back an uncorrelated gaussian throw error for each free parameter using step size" << endl;
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams[i];
if (fFixVals[syst]) continue;
// Make Terms
std::string name = syst + "_pull";
std::ostringstream pullterm;
pullterm << "DIAL:" << syst << ";"
<< fStartVals[syst] << ";"
<< fStepVals[syst];
std::string type = fTypeVals[syst] + "/GAUSTHROW";
// Push Back Pulls
ParamPull* pull = new ParamPull( name, pullterm.str(), type );
fInputThrows.push_back(pull);
fInputCovar.push_back(pull->GetFullCovarMatrix());
fInputDials.push_back(pull->GetDataHist());
// Print Whats added
ERR(WRN) << "Added ParamPull : " << name << " " << pullterm.str() << " " << type << endl;
// Add helper string for future fits
helperstr << "covar " << name << " " << pullterm.str() << " " << type << endl;
// Keep Track of Throws
dialthrowhandle[syst] = pull->GetName();
}
}
// Print Helper String
if (!helperstr.str().empty()){
ERR(WRN) << "To remove these warnings in future studies, add the lines below to your card." << endl;
cout << endl << helperstr.str() << endl;
sleep(2);
}
// Print Throw State
- for (int i = 0; i < fParams.size(); i++){
+ for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams[i];
if (dialthrowhandle.find(syst) != dialthrowhandle.end()){
LOG(FIT) << "Dial " << i << ". " << setw(40) << syst << " = THROWING with " << dialthrowhandle[syst] << endl;
} else {
LOG(FIT) << "Dial " << i << ". " << setw(40) << syst << " = FIXED" << endl;
}
}
// Pause anyway
sleep(1);
return;
}
/*
Fitting Functions
*/
//*************************************
void SystematicRoutines::UpdateRWEngine(std::map<std::string,double>& updateVals){
//*************************************
for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams[i];
if (updateVals.find(name) == updateVals.end()) continue;
FitBase::GetRW()->SetDialValue(name,updateVals.at(name));
}
FitBase::GetRW()->Reconfigure();
return;
}
//*************************************
void SystematicRoutines::Run(){
//*************************************
for (UInt_t i = 0; i < fRoutines.size(); i++){
std::string routine = fRoutines.at(i);
int fitstate = kFitUnfinished;
LOG(FIT)<<"Running Routine: "<<routine<<std::endl;
if (routine.find("PlotLimits") != std::string::npos) PlotLimits();
else if (routine.find("ErrorBands") != std::string::npos) GenerateErrorBands();
// If ending early break here
if (fitstate == kFitFinished || fitstate == kNoChange){
LOG(FIT) << "Ending fit routines loop." << endl;
break;
}
}
return;
}
//*************************************
void SystematicRoutines::PrintState(){
//*************************************
LOG(FIT)<<"------------"<<std::endl;
// Count max size
int maxcount = 0;
for (UInt_t i = 0; i < fParams.size(); i++){
maxcount = max(int(fParams[i].size()), maxcount);
}
// Header
LOG(FIT) << " # " << left << setw(maxcount) << "Parameter "
<< " = "
<< setw(10) << "Value" << " +- "
<< setw(10) << "Error" << " "
<< setw(8) << "(Units)" << " "
<< setw(10) << "Conv. Val" << " +- "
<< setw(10) << "Conv. Err" << " "
<< setw(8) << "(Units)" << std::endl;
// Parameters
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams.at(i);
std::string typestr = FitBase::ConvDialType(fTypeVals[syst]);
std::string curunits = "(sig.)";
double curval = fCurVals[syst];
double curerr = fErrorVals[syst];
if (fStateVals[syst].find("ABS") != std::string::npos){
curval = FitBase::RWSigmaToAbs(typestr, syst, curval);
curerr = (FitBase::RWSigmaToAbs(typestr, syst, curerr) -
FitBase::RWSigmaToAbs(typestr, syst, 0.0));
curunits = "(Abs.)";
} else if (fStateVals[syst].find("FRAC") != std::string::npos){
curval = FitBase::RWSigmaToFrac(typestr, syst, curval);
curerr = (FitBase::RWSigmaToFrac(typestr, syst, curerr) -
FitBase::RWSigmaToFrac(typestr, syst, 0.0));
curunits = "(Frac)";
}
std::string convunits = "(" + FitBase::GetRWUnits(typestr, syst) + ")";
double convval = FitBase::RWSigmaToAbs(typestr, syst, curval);
double converr = (FitBase::RWSigmaToAbs(typestr, syst, curerr) -
FitBase::RWSigmaToAbs(typestr, syst, 0.0));
std::ostringstream curparstring;
curparstring << " " << setw(3) << left
<< i << ". "
<< setw(maxcount) << syst << " = "
<< setw(10) << curval << " +- "
<< setw(10) << curerr << " "
<< setw(8) << curunits << " "
<< setw(10) << convval << " +- "
<< setw(10) << converr << " "
<< setw(8) << convunits;
LOG(FIT) << curparstring.str() << endl;
}
LOG(FIT)<<"------------"<<std::endl;
double like = fSampleFCN->GetLikelihood();
LOG(FIT)<<"Likelihood for JointFCN == " << like << endl;
LOG(FIT)<<"------------"<<std::endl;
}
/*
Write Functions
*/
//*************************************
void SystematicRoutines::SaveResults(){
//*************************************
fOutputRootFile->cd();
SaveCurrentState();
}
//*************************************
void SystematicRoutines::SaveCurrentState(std::string subdir){
//*************************************
LOG(FIT)<<"Saving current full FCN predictions" <<std::endl;
// Setup DIRS
TDirectory* curdir = gDirectory;
if (!subdir.empty()){
TDirectory* newdir =(TDirectory*) gDirectory->mkdir(subdir.c_str());
newdir->cd();
}
FitBase::GetRW()->Reconfigure();
fSampleFCN->ReconfigureAllEvents();
fSampleFCN->Write();
// Change back to current DIR
curdir->cd();
return;
}
//*************************************
void SystematicRoutines::SaveNominal(){
//*************************************
fOutputRootFile->cd();
LOG(FIT)<<"Saving Nominal Predictions (be cautious with this)" <<std::endl;
FitBase::GetRW()->Reconfigure();
SaveCurrentState("nominal");
};
//*************************************
void SystematicRoutines::SavePrefit(){
//*************************************
fOutputRootFile->cd();
LOG(FIT)<<"Saving Prefit Predictions"<<std::endl;
UpdateRWEngine(fStartVals);
SaveCurrentState("prefit");
UpdateRWEngine(fCurVals);
};
/*
MISC Functions
*/
//*************************************
int SystematicRoutines::GetStatus(){
//*************************************
return 0;
}
//*************************************
void SystematicRoutines::SetupCovariance(){
//*************************************
// Remove covares if they exist
if (fCovar) delete fCovar;
if (fCovarFree) delete fCovarFree;
if (fCorrel) delete fCorrel;
if (fCorrelFree) delete fCorrelFree;
if (fDecomp) delete fDecomp;
if (fDecompFree) delete fDecompFree;
int NFREE = 0;
int NDIM = 0;
// Get NFREE from min or from vals (for cases when doing throws)
if (fMinimizer){
NFREE = fMinimizer->NFree();
NDIM = fMinimizer->NDim();
} else {
NDIM = fParams.size();
for (UInt_t i = 0; i < fParams.size(); i++){
if (!fFixVals[fParams[i]]) NFREE++;
}
}
if (NDIM == 0) return;
fCovar = new TH2D("covariance","covariance",NDIM,0,NDIM,NDIM,0,NDIM);
if (NFREE > 0){
fCovarFree = new TH2D("covariance_free",
"covariance_free",
NFREE,0,NFREE,
NFREE,0,NFREE);
}
// Set Bin Labels
int countall = 0;
int countfree = 0;
for (UInt_t i = 0; i < fParams.size(); i++){
fCovar->GetXaxis()->SetBinLabel(countall+1,fParams[i].c_str());
fCovar->GetYaxis()->SetBinLabel(countall+1,fParams[i].c_str());
countall++;
if (!fFixVals[fParams[i]] and NFREE > 0){
fCovarFree->GetXaxis()->SetBinLabel(countfree+1,fParams[i].c_str());
fCovarFree->GetYaxis()->SetBinLabel(countfree+1,fParams[i].c_str());
countfree++;
}
}
fCorrel = PlotUtils::GetCorrelationPlot(fCovar,"correlation");
fDecomp = PlotUtils::GetDecompPlot(fCovar,"decomposition");
if (NFREE > 0)fCorrelFree = PlotUtils::GetCorrelationPlot(fCovarFree, "correlation_free");
if (NFREE > 0)fDecompFree = PlotUtils::GetDecompPlot(fCovarFree,"decomposition_free");
return;
};
//*************************************
void SystematicRoutines::ThrowCovariance(bool uniformly){
//*************************************
// Set fThrownVals to all values in currentVals
- for (int i = 0; i < fParams.size(); i++){
+ for (UInt_t i = 0; i < fParams.size(); i++){
std::string name = fParams.at(i);
fThrownVals[name] = fCurVals[name];
}
for (PullListConstIter iter = fInputThrows.begin();
iter != fInputThrows.end(); iter++){
ParamPull* pull = *iter;
pull->ThrowCovariance();
TH1D dialhist = pull->GetDataHist();
for (int i = 0; i < dialhist.GetNbinsX(); i++){
std::string name = std::string(dialhist.GetXaxis()->GetBinLabel(i+1));
cout << "Thrown BinX = " << name << endl;
if (fCurVals.find(name) != fCurVals.end()){
fThrownVals[name] = dialhist.GetBinContent(i+1);
cout << "ThrownVals = " << name << " " << fThrownVals[name] << endl;
sleep(1);
}
}
// Reset throw incase pulls are calculated.
pull->ResetToy();
}
return;
};
//*************************************
void SystematicRoutines::GenerateErrorBands(){
//*************************************
TDirectory* errorDIR = (TDirectory*) fOutputRootFile->mkdir("error_bands");
errorDIR->cd();
TFile* tempfile = new TFile((fOutputFile + ".throws.root").c_str(),"RECREATE");
tempfile->cd();
int nthrows = FitPar::Config().GetParI("error_throws");
UpdateRWEngine(fCurVals);
fSampleFCN->ReconfigureAllEvents();
TDirectory* nominal = (TDirectory*) tempfile->mkdir("nominal");
nominal->cd();
fSampleFCN->Write();
TDirectory* outnominal = (TDirectory*) fOutputRootFile->mkdir("nominal_throw");
outnominal->cd();
fSampleFCN->Write();
errorDIR->cd();
TTree* parameterTree = new TTree("throws","throws");
double chi2;
for (UInt_t i = 0; i < fParams.size(); i++)
parameterTree->Branch(fParams[i].c_str(), &fThrownVals[fParams[i]], (fParams[i] + "/D").c_str());
parameterTree->Branch("chi2",&chi2,"chi2/D");
bool uniformly = FitPar::Config().GetParB("error_uniform");
// Run Throws and save
for (Int_t i = 0; i < nthrows; i++){
TDirectory* throwfolder = (TDirectory*)tempfile->mkdir(Form("throw_%i",i));
throwfolder->cd();
// Generate Random Parameter Throw
ThrowCovariance(uniformly);
// Run Eval
double *vals = FitUtils::GetArrayFromMap( fParams, fThrownVals );
chi2 = fSampleFCN->DoEval( vals );
delete vals;
// Save the FCN
fSampleFCN->Write();
parameterTree->Fill();
}
errorDIR->cd();
fDecompFree->Write();
fCovarFree->Write();
parameterTree->Write();
delete parameterTree;
// Now go through the keys in the temporary file and look for TH1D, and TH2D plots
TIter next(nominal->GetListOfKeys());
TKey *key;
while ((key = (TKey*)next())) {
TClass *cl = gROOT->GetClass(key->GetClassName());
if (!cl->InheritsFrom("TH1D") and !cl->InheritsFrom("TH2D")) continue;
TH1D *baseplot = (TH1D*)key->ReadObj();
std::string plotname = std::string(baseplot->GetName());
int nbins = baseplot->GetNbinsX()*baseplot->GetNbinsY();
// Setup TProfile with RMS option
TProfile* tprof = new TProfile((plotname + "_prof").c_str(),(plotname + "_prof").c_str(),nbins, 0, nbins, "S");
// Setup The TTREE
double* bincontents;
bincontents = new double[nbins];
double* binlowest;
binlowest = new double[nbins];
double* binhighest;
binhighest = new double[nbins];
errorDIR->cd();
TTree* bintree = new TTree((plotname + "_tree").c_str(), (plotname + "_tree").c_str());
for (Int_t i = 0; i < nbins; i++){
bincontents[i] = 0.0;
binhighest[i] = 0.0;
binlowest[i] = 0.0;
bintree->Branch(Form("content_%i",i),&bincontents[i],Form("content_%i/D",i));
}
for (Int_t i = 0; i < nthrows; i++){
TH1* newplot = (TH1*)tempfile->Get(Form(("throw_%i/" + plotname).c_str(),i));
for (Int_t j = 0; j < nbins; j++){
tprof->Fill(j+0.5, newplot->GetBinContent(j+1));
bincontents[j] = newplot->GetBinContent(j+1);
if (bincontents[j] < binlowest[j] or i == 0) binlowest[j] = bincontents[j];
if (bincontents[j] > binhighest[j] or i == 0) binhighest[j] = bincontents[j];
}
errorDIR->cd();
bintree->Fill();
delete newplot;
}
errorDIR->cd();
for (Int_t j = 0; j < nbins; j++){
if (!uniformly){
baseplot->SetBinError(j+1,tprof->GetBinError(j+1));
} else {
baseplot->SetBinContent(j+1, (binlowest[j] + binhighest[j]) / 2.0);
baseplot->SetBinError(j+1, (binhighest[j] - binlowest[j])/2.0);
}
}
errorDIR->cd();
baseplot->Write();
tprof->Write();
bintree->Write();
delete baseplot;
delete tprof;
delete bintree;
delete [] bincontents;
}
return;
};
//*************************************
void SystematicRoutines::PlotLimits(){
//*************************************
TDirectory* limfolder = (TDirectory*) fOutputRootFile->mkdir("Limits");
limfolder->cd();
// Set all parameters at their starting values
for (UInt_t i = 0; i < fParams.size(); i++){
fCurVals[fParams[i]] = fStartVals[fParams[i]];
}
TDirectory* nomfolder = (TDirectory*) limfolder->mkdir("nominal");
nomfolder->cd();
UpdateRWEngine(fCurVals);
fSampleFCN->ReconfigureAllEvents();
fSampleFCN->Write();
limfolder->cd();
std::vector<std::string> allfolders;
// Loop through each parameter
for (UInt_t i = 0; i < fParams.size(); i++){
std::string syst = fParams[i];
if (fFixVals[syst]) continue;
// Loop Downwards
while (fCurVals[syst] > fMinVals[syst]){
fCurVals[syst] = fCurVals[syst] - fStepVals[syst];
// Check Limit
if (fCurVals[syst] < fMinVals[syst])
fCurVals[syst] = fMinVals[syst];
// Check folder exists
std::string curvalstring = std::string( Form( (syst + "_%f").c_str(), fCurVals[syst] ) );
if (std::find(allfolders.begin(), allfolders.end(), curvalstring) != allfolders.end())
break;
// Make new folder for variation
TDirectory* minfolder = (TDirectory*) limfolder->mkdir(Form( (syst + "_%f").c_str(), fCurVals[syst] ) );
minfolder->cd();
allfolders.push_back(curvalstring);
// Update Iterations
double *vals = FitUtils::GetArrayFromMap( fParams, fCurVals );
- double chi2 = fSampleFCN->DoEval( vals );
+ fSampleFCN->DoEval( vals );
delete vals;
// Save to folder
fSampleFCN->Write();
}
// Reset before next loop
fCurVals[syst] = fStartVals[syst];
// Loop Upwards now
while (fCurVals[syst] < fMaxVals[syst]){
fCurVals[syst] = fCurVals[syst] + fStepVals[syst];
// Check Limit
if (fCurVals[syst] > fMaxVals[syst])
fCurVals[syst] = fMaxVals[syst];
// Check folder exists
std::string curvalstring = std::string( Form( (syst + "_%f").c_str(), fCurVals[syst] ) );
if (std::find(allfolders.begin(), allfolders.end(), curvalstring) != allfolders.end())
break;
// Make new folder
TDirectory* maxfolder = (TDirectory*) limfolder->mkdir(Form( (syst + "_%f").c_str(), fCurVals[syst] ) );
maxfolder->cd();
allfolders.push_back(curvalstring);
// Update Iterations
double *vals = FitUtils::GetArrayFromMap( fParams, fCurVals );
- double chi2 = fSampleFCN->DoEval( vals );
+ fSampleFCN->DoEval( vals );
delete vals;
// Save to file
fSampleFCN->Write();
}
// Reset before leaving
fCurVals[syst] = fStartVals[syst];
UpdateRWEngine(fCurVals);
}
return;
}
diff --git a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx
index 01f5299..6c70245 100644
--- a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx
+++ b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx
@@ -1,261 +1,255 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "T2K_CC0pi_XSec_2DPcos_nu.h"
T2K_CC0pi_XSec_2DPcos_nu::T2K_CC0pi_XSec_2DPcos_nu(std::string name,
std::string inputfile,
FitWeight *rw,
std::string type){
fName = name;
if (fName == "T2K_CC0pi_XSec_2DPcos_nu_I") fAnalysis = 1;
else fAnalysis = 2;
forwardgoing = (type.find("REST") != std::string::npos);
EnuMin = 0;
EnuMax = 10.0;
fBeamDistance = 0.280;
fDefaultTypes = "FIX";
fAllowedTypes = "DIAG,FULL/FREE,SHAPE,FIX/SYSTCOV/STATCOV";
fNDataPointsX = 12;
fNDataPointsY = 10;
Measurement2D::SetupMeasurement(inputfile, type, rw, fakeDataFile);
fIsSystCov = type.find("SYSTCOV") != std::string::npos;
fIsStatCov = type.find("STATCOV") != std::string::npos;
fIsNormCov = type.find("NORMCOV") != std::string::npos;
fPlotTitles = "; P_{#mu} (GeV); cos#theta_{#mu}; d^{2}#sigma/dP_{#mu}dcos#theta_{#mu} (cm^{2}/GeV)";
SetHistograms();
SetupDefaultHist();
// Diagonal covar setup
if (!fIsShape) fAddNormPen = true;
fNormError = 0.089; // Set from covar mat instead...
// Get Scaling
fScaleFactor = ((fEventHist->Integral("width")/(fNEvents+0.)) * 1E-38 /
(TotalIntegratedFlux()));
};
-int T2K_CC0pi_XSec_2DPcos_nu::GetNDOF(){
- if (fAnalysis == 1){ return 67; }
- else return 90;
-}
-
bool T2K_CC0pi_XSec_2DPcos_nu::isSignal(FitEvent *event){
- bool sig = SignalDef::isT2K_CC0pi(event, EnuMin, EnuMax, forwardgoing);
return SignalDef::isT2K_CC0pi(event, EnuMin, EnuMax, forwardgoing);
};
void T2K_CC0pi_XSec_2DPcos_nu::FillEventVariables(FitEvent* event){
double pmu = -999.9;
double CosThetaMu = -999.9;
// Loop over all particles
for (UInt_t j = 2; j < event->Npart(); ++j){
// Muon section
if ((event->PartInfo(j))->fPID == 13){
// Now find the kinematic values and fill the histogram
pmu = (event->PartInfo(j))->fP.Vect().Mag()/1000;
CosThetaMu = cos(((event->PartInfo(0))->fP.Vect().Angle((event->PartInfo(j))->fP.Vect())));
continue;
}
}
fXVar = pmu;
fYVar = CosThetaMu;
return;
};
// Modification is needed after the full reconfigure to move bins around
// Otherwise this would need to be replaced by a TH2Poly which is too awkward.
void T2K_CC0pi_XSec_2DPcos_nu::ConvertEventRates(){
// Do standard conversion.
Measurement2D::ConvertEventRates();
if (fAnalysis == 1){
// Following code handles weird ND280 Binning
int nbins = this->fMCHist->GetNbinsX() + 1;
double total = 0.0;
// Y = 1
total = 0.0;
for (int i = 3; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(1);
total += this->fMCHist->GetBinContent(i, 1) * width;
this->fMCHist->SetBinContent(i,1,0);
}
this->fMCHist->SetBinContent(3, 1, total / (1.0 * 29.6));
// Y = 2
total = 0.0;
for (int i = 5; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(2);
total += this->fMCHist->GetBinContent(i, 2)* width;
this->fMCHist->SetBinContent(i,2,0);
}
this->fMCHist->SetBinContent(5, 2, total / (0.6 *29.4));
// Y = 3
total = 0.0;
for (int i = 7; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(3);
total += this->fMCHist->GetBinContent(i, 3)* width;
this->fMCHist->SetBinContent(i, 3,0);
}
this->fMCHist->SetBinContent(7, 3, total/ (0.1 * 29.2));
// Y = 4
total = 0.0;
for (int i = 7; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(4);
total += this->fMCHist->GetBinContent(i, 4)* width;
this->fMCHist->SetBinContent(i, 4,0);
}
this->fMCHist->SetBinContent(7, 4, total / (0.1 * 29.2));
// Y = 5
total = 0.0;
for (int i = 8; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(5);
total += this->fMCHist->GetBinContent(i, 5)* width;
this->fMCHist->SetBinContent(i,5,0);
}
this->fMCHist->SetBinContent(8, 5, total / (0.05 * 29.0));
// Y = 6
total = 0.0;
for (int i = 9; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(6);
total += this->fMCHist->GetBinContent(i, 6)* width;
this->fMCHist->SetBinContent(i, 6,0);
}
this->fMCHist->SetBinContent(9, 6, total / (0.05 * 28.5));
// Y = 7
total = 0.0;
for (int i = 8; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(7);
total += this->fMCHist->GetBinContent(i, 7)* width;
this->fMCHist->SetBinContent(i, 7,0);
}
this->fMCHist->SetBinContent(8, 7, total/ (0.04 * 28.0));
// Y = 8
total = 0.0;
for (int i = 11; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(8);
total += this->fMCHist->GetBinContent(i, 8)* width;
this->fMCHist->SetBinContent(i, 8,0);
}
this->fMCHist->SetBinContent(11, 8, total / (0.4 * 27.0));
// Y = 9
total = 0.0;
for (int i = 9; i < nbins; i++){
double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(9);
total += this->fMCHist->GetBinContent(i, 9)* width;
this->fMCHist->SetBinContent(i,9,0);
}
this->fMCHist->SetBinContent(9, 9, total / (0.02 * 25.0));
}
return;
}
void T2K_CC0pi_XSec_2DPcos_nu::SetHistograms(){
// Open file
std::string infile = FitPar::GetDataBase()+"/T2K/CC0pi/T2K_CC0PI_2DPmuCosmu_Data.root";
TFile* rootfile = new TFile(infile.c_str(), "READ");
TH2D* tempcov;
// ANALYSIS 2
if (fAnalysis == 2){
// Get Data
fDataHist = (TH2D*) rootfile->Get("analysis2_data");
fDataHist->SetDirectory(0);
fDataHist->SetNameTitle((fName + "_data").c_str(),
(fName + "_data" + fPlotTitles).c_str());
// Get Map
fMapHist = (TH2I*) rootfile->Get("analysis2_map");
fMapHist->SetDirectory(0);
fMapHist->SetNameTitle((fName + "_map").c_str(),
(fName + "_map" + fPlotTitles).c_str());
// Get Syst/Stat Covar
TH2D* tempsyst = (TH2D*) rootfile->Get("analysis2_systcov");
TH2D* tempstat = (TH2D*) rootfile->Get("analysis2_statcov");
TH2D* tempnorm = (TH2D*) rootfile->Get("analysis2_normcov");
// Create covar [Default is both]
tempcov = (TH2D*) tempsyst->Clone();
tempcov->Reset();
if (fIsSystCov) tempcov->Add(tempsyst);
if (fIsStatCov) tempcov->Add(tempstat);
if (fIsNormCov) tempcov->Add(tempnorm);
if (!fIsSystCov && !fIsStatCov && !fIsNormCov){
tempcov->Add(tempsyst);
tempcov->Add(tempstat);
tempcov->Add(tempnorm);
}
// SARAS ANALYSIS
} else if (fAnalysis == 1){
cout << "HELP AWKWARD BINNING";
}
// Setup Covar
int nbins = tempcov->GetNbinsX();
fFullCovar = new TMatrixDSym(nbins);
for (int i = 0; i < nbins; i++){
for (int j = 0; j < nbins; j++){
(*fFullCovar)(i,j) = tempcov->GetBinContent(i+1,j+1);
}
}
covar = StatUtils::GetInvert(fFullCovar);
fDecomp = StatUtils::GetDecomp(covar);
// Set Data Errors
StatUtils::SetDataErrorFromCov(fDataHist, fFullCovar, fMapHist, 1E-38);
// Remove root file
rootfile->Close();
return;
};
diff --git a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h
index 6e1d629..0dee264 100644
--- a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h
+++ b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h
@@ -1,71 +1,67 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#ifndef T2K_CC0PI_2DPCOS_NU_H_SEEN
#define T2K_CC0PI_2DPCOS_NU_H_SEEN
#include "Measurement2D.h"
class T2K_CC0pi_XSec_2DPcos_nu : public Measurement2D {
public:
/// Basic Constructor.
/// /brief Parses two different measurements.
///
/// T2K_CC0pi_XSec_2DPcos_nu -> T2K CC0PI Analysis 2
/// T2K_CC0pi_XSec_2DPcos_nu_I -> T2K CC0PI Analysis 1
/// T2K_CC0pi_XSec_2DPcos_nu_II -> T2K CC0PI Analysis 2
T2K_CC0pi_XSec_2DPcos_nu(std::string name, std::string inputfile, FitWeight *rw, std::string type);
/// Virtual Destructor
~T2K_CC0pi_XSec_2DPcos_nu() {};
- /// Return NDOF
- /// /brief Have to override default because binning is awful
- int GetNDOF();
-
/// Numu CC0PI Signal Definition
///
/// /item
bool isSignal(FitEvent *nvect);
/// Read histograms in a special way because format is different.
/// Read from FitPar::GetDataBase()+"/T2K/CC0pi/T2K_CC0PI_2DPmuCosmu_Data.root"
void SetHistograms();
/// Bin Tmu CosThetaMu
void FillEventVariables(FitEvent* customEvent);
/// Have to do a weird event scaling for analysis 1
void ConvertEventRates();
private:
bool forwardgoing;
bool only_allowed_particles;
bool numu_event;
double numu_energy;
int particle_pdg;
double pmu, CosThetaMu;
int fAnalysis;
bool fIsSystCov, fIsStatCov, fIsNormCov;
};
#endif
diff --git a/src/Utils/PlotUtils.cxx b/src/Utils/PlotUtils.cxx
index 704a8dc..fe1c484 100644
--- a/src/Utils/PlotUtils.cxx
+++ b/src/Utils/PlotUtils.cxx
@@ -1,974 +1,974 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "PlotUtils.h"
#include "FitEvent.h"
#include "FitParameters.h"
// This function is intended to be modified to enforce a consistent masking for all models.
TH2D* PlotUtils::SetMaskHist(std::string type, TH2D* data){
TH2D *fMaskHist = (TH2D*)data->Clone("fMaskHist");
for (int xBin = 0; xBin < fMaskHist->GetNbinsX(); ++xBin){
for (int yBin = 0; yBin < fMaskHist->GetNbinsY(); ++yBin){
if (data->GetBinContent(xBin+1, yBin+1) == 0) fMaskHist->SetBinContent(xBin+1, yBin+1, 0);
else fMaskHist->SetBinContent(xBin+1, yBin+1, 0.5);
if (!type.compare("MB_numu_2D")){
if (yBin == 19 && xBin < 8) fMaskHist->SetBinContent(xBin+1, yBin+1, 1.0);
} else {
if (yBin == 19 && xBin < 11) fMaskHist->SetBinContent(xBin+1, yBin+1, 1.0);
}
if (yBin == 18 && xBin < 3) fMaskHist->SetBinContent(xBin+1, yBin+1, 1.0);
if (yBin == 17 && xBin < 2) fMaskHist->SetBinContent(xBin+1, yBin+1, 1.0);
if (yBin == 16 && xBin < 1) fMaskHist->SetBinContent(xBin+1, yBin+1, 1.0);
}
}
return fMaskHist;
};
bool PlotUtils::CheckObjectWithName(TFile *inFile, std::string substring){
TIter nextkey(inFile->GetListOfKeys());
TKey *key;
while ( (key = (TKey*)nextkey()) ) {
std::string test(key->GetName());
if (test.find(substring) != std::string::npos) return true;
}
return false;
};
std::string PlotUtils::GetObjectWithName(TFile *inFile, std::string substring){
TIter nextkey(inFile->GetListOfKeys());
TKey *key;
std::string output="NULL";
while ( (key = (TKey*)nextkey()) ) {
std::string test(key->GetName());
if (test.find(substring) != std::string::npos)
output = test;
}
return output;
};
void PlotUtils::CreateNeutModeArray(TH1* hist, TH1* neutarray[]){
for (int i = 0; i < 60; i++){
neutarray[i] = (TH1*)hist->Clone(Form("%s_NMODE_%i",hist->GetName(),i));
}
return;
};
void PlotUtils::DeleteNeutModeArray(TH1* neutarray[]){
for (int i = 0; i < 60; i++){
delete neutarray[i];
}
return;
};
void PlotUtils::FillNeutModeArray(TH1D* hist[], int mode, double xval, double weight){
if (abs(mode) > 60) return;
hist[abs(mode)]->Fill(xval, weight);
return;
};
void PlotUtils::FillNeutModeArray(TH2D* hist[], int mode, double xval, double yval, double weight){
if (abs(mode) > 60) return;
hist[abs(mode)]->Fill(xval,yval,weight);
return;
};
THStack PlotUtils::GetNeutModeStack(std::string title, TH1* ModeStack[], int option) {
(void) option;
THStack allmodes = THStack(title.c_str(),title.c_str());
for (int i = 0; i < 60; i++){
allmodes.Add(ModeStack[i]);
}
// Credit to Clarence for copying all this out.
// CC
ModeStack[1]->SetTitle("CCQE");
ModeStack[1]->SetFillColor(kBlue);
// ModeStack[1]->SetFillStyle(3444);
ModeStack[1]->SetLineColor(kBlue);
ModeStack[2]->SetTitle("2p/2h Nieves");
ModeStack[2]->SetFillColor(kRed);
//ModeStack[2]->SetFillStyle(3344);
ModeStack[2]->SetLineColor(kRed);
//ModeStack[11]->SetTitle("#it{#nu + p #rightarrow l^{-} + p + #pi^{+}}");
ModeStack[11]->SetTitle("CC1#pi^{+} on p");
ModeStack[11]->SetFillColor(kGreen);
//ModeStack[11]->SetFillStyle(3004);
ModeStack[11]->SetLineColor(kGreen);
//ModeStack[12]->SetTitle("#it{#nu + n #rightarrow l^{-} + p + #pi^{0}}");
ModeStack[12]->SetTitle("CC1#pi^{0} on n");
ModeStack[12]->SetFillColor(kGreen+3);
//ModeStack[12]->SetFillStyle(3005);
ModeStack[12]->SetLineColor(kGreen);
//ModeStack[13]->SetTitle("#it{#nu + n #rightarrow l^{-} + n + #pi^{+}}");
ModeStack[13]->SetTitle("CC1#pi^{+} on n");
ModeStack[13]->SetFillColor(kGreen-2);
//ModeStack[13]->SetFillStyle(3004);
ModeStack[13]->SetLineColor(kGreen);
ModeStack[16]->SetTitle("CC coherent");
ModeStack[16]->SetFillColor(kBlue);
//ModeStack[16]->SetFillStyle(3644);
ModeStack[16]->SetLineColor(kBlue);
//ModeStack[17]->SetTitle("#it{#nu + n #rightarrow l^{-} + p + #gamma}");
ModeStack[17]->SetTitle("CC1#gamma");
ModeStack[17]->SetFillColor(kMagenta);
//ModeStack[17]->SetFillStyle(3001);
ModeStack[17]->SetLineColor(kMagenta);
ModeStack[21]->SetTitle("Multi #pi (1.3 < W < 2.0)");
ModeStack[21]->SetFillColor(kYellow);
//ModeStack[21]->SetFillStyle(3005);
ModeStack[21]->SetLineColor(kYellow);
//ModeStack[22]->SetTitle("#it{#nu + n #rightarrow l^{-} + p + #eta^{0}}");
ModeStack[22]->SetTitle("CC1#eta^{0} on n");
ModeStack[22]->SetFillColor(kYellow-2);
//ModeStack[22]->SetFillStyle(3013);
ModeStack[22]->SetLineColor(kYellow-2);
//ModeStack[23]->SetTitle("#it{#nu + n #rightarrow l^{-} + #Lambda + K^{+}}");
ModeStack[23]->SetTitle("CC1#Labda1K^{+}");
ModeStack[23]->SetFillColor(kYellow-6);
//ModeStack[23]->SetFillStyle(3013);
ModeStack[23]->SetLineColor(kYellow-6);
ModeStack[26]->SetTitle("DIS (W > 2.0)");
ModeStack[26]->SetFillColor(kRed);
//ModeStack[26]->SetFillStyle(3006);
ModeStack[26]->SetLineColor(kRed);
// NC
//ModeStack[31]->SetTitle("#it{#nu + n #rightarrow #nu + n + #pi^{0}}");
ModeStack[31]->SetTitle("NC1#pi^{0} on n");
ModeStack[31]->SetFillColor(kBlue);
//ModeStack[31]->SetFillStyle(3004);
ModeStack[31]->SetLineColor(kBlue);
//ModeStack[32]->SetTitle("#it{#nu + p #rightarrow #nu + p + #pi^{0}}");
ModeStack[32]->SetTitle("NC1#pi^{0} on p");
ModeStack[32]->SetFillColor(kBlue+3);
//ModeStack[32]->SetFillStyle(3004);
ModeStack[32]->SetLineColor(kBlue+3);
//ModeStack[33]->SetTitle("#it{#nu + n #rightarrow #nu + p + #pi^{-}}");
ModeStack[33]->SetTitle("NC1#pi^{-} on n");
ModeStack[33]->SetFillColor(kBlue-2);
//ModeStack[33]->SetFillStyle(3005);
ModeStack[33]->SetLineColor(kBlue-2);
//ModeStack[34]->SetTitle("#it{#nu + p #rightarrow #nu + n + #pi^{+}}");
ModeStack[34]->SetTitle("NC1#pi^{+} on p");
ModeStack[34]->SetFillColor(kBlue-8);
//ModeStack[34]->SetFillStyle(3005);
ModeStack[34]->SetLineColor(kBlue-8);
ModeStack[36]->SetTitle("NC Coherent");
ModeStack[36]->SetFillColor(kBlue+8);
//ModeStack[36]->SetFillStyle(3644);
ModeStack[36]->SetLineColor(kBlue+8);
//ModeStack[38]->SetTitle("#it{#nu + n #rightarrow #nu + n + #gamma}");
ModeStack[38]->SetTitle("NC1#gamma on n");
ModeStack[38]->SetFillColor(kMagenta);
//ModeStack[38]->SetFillStyle(3001);
ModeStack[38]->SetLineColor(kMagenta);
//ModeStack[39]->SetTitle("#it{#nu + p #rightarrow #nu + p + #gamma}");
ModeStack[39]->SetTitle("NC1#gamma on p");
ModeStack[39]->SetFillColor(kMagenta-10);
//ModeStack[39]->SetFillStyle(3001);
ModeStack[39]->SetLineColor(kMagenta-10);
ModeStack[41]->SetTitle("Multi #pi (1.3 < W < 2.0)");
ModeStack[41]->SetFillColor(kBlue-10);
//ModeStack[41]->SetFillStyle(3005);
ModeStack[41]->SetLineColor(kBlue-10);
//ModeStack[42]->SetTitle("#it{#nu + n #rightarrow #nu + n + #eta^{0}}");
ModeStack[42]->SetTitle("NC1#eta^{0} on n");
ModeStack[42]->SetFillColor(kYellow-2);
//ModeStack[42]->SetFillStyle(3013);
ModeStack[42]->SetLineColor(kYellow-2);
//ModeStack[43]->SetTitle("#it{#nu + p #rightarrow #nu + p + #eta^{0}}");
ModeStack[43]->SetTitle("NC1#eta^{0} on p");
ModeStack[43]->SetFillColor(kYellow-4);
//ModeStack[43]->SetFillStyle(3013);
ModeStack[43]->SetLineColor(kYellow-4);
//ModeStack[44]->SetTitle("#it{#nu + n #rightarrow #nu + #Lambda + K^{0}}");
ModeStack[44]->SetTitle("NC1#Lambda1K^{0} on n");
ModeStack[44]->SetFillColor(kYellow - 6);
//ModeStack[44]->SetFillStyle(3014);
ModeStack[44]->SetLineColor(kYellow - 6);
//ModeStack[45]->SetTitle("#it{#nu + p #rightarrow #nu + #Lambda + K^{+}}");
ModeStack[45]->SetTitle("NC1#Lambda1K^{+}");
ModeStack[45]->SetFillColor(kYellow - 10);
//ModeStack[45]->SetFillStyle(3014);
ModeStack[45]->SetLineColor(kYellow - 10);
ModeStack[46]->SetTitle("DIS (W > 2.0)");
ModeStack[46]->SetFillColor(kRed);
//ModeStack[46]->SetFillStyle(3006);
ModeStack[46]->SetLineColor(kRed);
//ModeStack[51]->SetTitle("#it{#nu + p #rightarrow #nu + p}");
ModeStack[51]->SetTitle("NC on p");
ModeStack[51]->SetFillColor(kBlack);
//ModeStack[51]->SetFillStyle(3444);
ModeStack[51]->SetLineColor(kBlack);
//ModeStack[52]->SetTitle("#it{#nu + n #rightarrow #nu + n}");
ModeStack[52]->SetTitle("NC on n");
ModeStack[52]->SetFillColor(kGray);
//ModeStack[52]->SetFillStyle(3444);
ModeStack[52]->SetLineColor(kGray);
return allmodes;
};
TLegend PlotUtils::GenerateStackLegend(THStack stack, int xlow, int ylow, int xhigh, int yhigh){
TLegend leg = TLegend(xlow,ylow,xhigh,yhigh);
TObjArray* histarray = stack.GetStack();
int nhist = histarray->GetEntries();
for (int i = 0; i < nhist; i++){
TH1* hist = (TH1*)(histarray->At(i));
leg.AddEntry( (hist), ((TH1*)histarray->At(i))->GetTitle(), "fl");
}
leg.SetName(Form("%s_LEG",stack.GetName()));
return leg;
};
void PlotUtils::ScaleNeutModeArray(TH1* hist[], double factor, std::string option){
for (int i = 0; i < 60; i++){
if (hist[i])
hist[i]->Scale(factor,option.c_str());
}
return;
};
void PlotUtils::ResetNeutModeArray(TH1* hist[]){
for (int i = 0; i < 60; i++){
if (hist[i])
hist[i]->Reset();
}
return;
};
std::vector<std::string> PlotUtils::ParseToStr(std::string str, const char* del){
std::istringstream stream(str);
std::string temp_string;
std::vector<string> vals;
while (std::getline(stream, temp_string, *del)) {
if (temp_string.empty()) continue;
vals.push_back(temp_string);
}
return vals;
}
std::vector<double> PlotUtils::ParseToDbl(std::string str, const char* del){
std::istringstream stream(str);
std::string temp_string;
std::vector<double> vals;
while (std::getline(stream, temp_string, *del)) {
if (temp_string.empty()) continue;
std::istringstream stream(temp_string);
double entry;
stream >> entry;
vals.push_back(entry);
}
return vals;
}
//********************************************************************
std::vector<std::string> PlotUtils::ParseFileToStr(std::string str, const char* del){
//********************************************************************
std::vector<std::string> linevect;
std::string line;
ifstream read;
read.open(str.c_str());
if (!read.is_open()){
std::cerr << "Cannot open file " << str << " in ParseFileToStr" << std::endl;
throw;
}
while( std::getline(read, line, *del) ){
linevect.push_back(line);
}
read.close();
return linevect;
}
//********************************************************************
void PlotUtils::FluxUnfoldedScaling(TH2D* fMCHist, TH1D* fFluxHist, int axis){
//********************************************************************
// Mostly copied from TH1D version below
// Need to specify which axes (default is x-axis)
(void) axis;
// Make a temporary TGraph which holds the points from the flux (essentially copying the TH1D to a TGraph)
TGraph* fluxGraph = new TGraph(fFluxHist->GetNbinsX());
for (int i = 0; i < fFluxHist->GetNbinsX(); i++){
fluxGraph->SetPoint(i, fFluxHist->GetXaxis()->GetBinCenter(i+1), fFluxHist->GetBinContent(i+1));
}
// Resolution for the interpolation used for the flux
// Set to 100 times fines than flux histogram, should be enough buy may need tweaking!
- int resolution = 100*fluxHist->GetXaxis()->GetNbins();
+ int resolution = 100*fFluxHist->GetXaxis()->GetNbins();
// The new interpolated flux histogram with fine binning
TH1D* fineFlux = new TH1D("fineFlux", "fineFlux", resolution, fFluxHist->GetXaxis()->GetBinLowEdge(1), fFluxHist->GetXaxis()->GetBinLowEdge(fFluxHist->GetNbinsX()+1));
// Set the new TH1D with the TGraph interpolated bin content
for (int i = 0; i < fineFlux->GetNbinsX(); i++) {
fineFlux->SetBinContent(i+1, fluxGraph->Eval(fineFlux->GetXaxis()->GetBinCenter(i+1), 0, "S"));
}
/*
// The histogram which contains the Enu projection of the TH2D
TH1D* EnuHist = NULL;
// if Enu is on x-axis
if (axis == 0) {
EnuHist = (TH1D*)fMCHist->ProjectionY();
} else if (axis == 1) {
EnuHist = (TH1D*)fMCHist->ProjectionX();
}
*/
for (int i = 1; i < fMCHist->GetNbinsX()+1; i++) {
// Get the low edge of the ith bin
Double_t binLowEdge = fMCHist->GetXaxis()->GetBinLowEdge(i)/1000.;
// Get the high edge of the ith bin
Double_t binHighEdge = fMCHist->GetXaxis()->GetBinLowEdge(i+1)/1000.;
// Find the correpsonding bin in the interpolated flux histogram
// Start by finding the low edge of the bin
Int_t fluxLow = 0;
Int_t fluxHigh = 0;
// Find the binLowEdge in the new interpolated flux histogram which matches the mc binning's edge
double diff = 999; // Set the initial difference to be very large
for (; fluxLow < fineFlux->GetNbinsX(); fluxLow++) {
// the difference between the mc bin edge and the flux bin edge
double temp = fabs(binLowEdge - fineFlux->GetBinLowEdge(fluxLow));
// if difference is larger than previous
if (temp < diff) {
diff = temp;
} else {
break;
}
}
if (diff > 0.5) {
// This is a known issue for all BEBC 1pi 1DEnu classes in the first bin, where the flux histogram starts at 8.9GeV but MC binning starts at 5GeV
std::cerr << "Warning " << __FILE__ << ":" << __LINE__ << std::endl;
std::cerr << "Couldn't find good low-edge bin match for flux histogram " << fFluxHist->GetName() << " and MC " << fMCHist->GetName() << std::endl;
std::cout << "fluxLow = " << fluxLow << std::endl;
std::cout << "binLowEdge - fineFlux->GetBinLowEdge(fluxLow) = " << binLowEdge << " - " << fineFlux->GetBinLowEdge(fluxLow) << " = " << binLowEdge - fineFlux->GetBinLowEdge(fluxLow) << std::endl;
}
diff = 999;
for (; fluxHigh < fineFlux->GetNbinsX(); fluxHigh++) {
double temp = fabs(binHighEdge - fineFlux->GetBinLowEdge(fluxHigh));
if (temp < diff) {
diff = temp;
} else {
break;
}
}
if (diff > 0.5) {
// This is a known issue for anti-nu BEBC 1pi 1DEnu classes in the last bin, where the flux histogram ends at 180 GeV but MC binning continues to 200 GeV
std::cerr << "Warning " << __FILE__ << ":" << __LINE__ << std::endl;
std::cerr << "Couldn't find good high-edge bin match for flux histogram " << fFluxHist->GetName() << " and MC " << fMCHist->GetName() << std::endl;
std::cout << "fluxHigh = " << fluxHigh << std::endl;
std::cout << "binHighEdge - fineFlux->GetBinLowEdge(fluxHigh) = " << binHighEdge << " - " << fineFlux->GetBinLowEdge(fluxHigh) << " = " << binHighEdge - fineFlux->GetBinLowEdge(fluxHigh) << std::endl;
}
// fluxHigh - 1 because Integral takes the binLowEdge into account, and fluxHigh is our high edge
double fluxInt = fineFlux->Integral(fluxLow, fluxHigh - 1, "width");
// Scale every projected bin by the flux integration
//if (axis == 0) {
for (int j = 1; j < fMCHist->GetYaxis()->GetNbins()+1; j++) {
double binWidth = fMCHist->GetYaxis()->GetBinWidth(j);
fMCHist->SetBinContent(i, j, fMCHist->GetBinContent(i,j)/(fluxInt*binWidth));
fMCHist->SetBinError(i, j, fMCHist->GetBinError(i,j)/(fluxInt*binWidth));
}
/*
} else if (axis == 1) {
for (int j = 1; j < fMCHist->GetXaxis()->GetNbins()+1; j++) {
fMCHist->SetBinContent(j, i, fMCHist->GetBinContent(j,i)/fluxInt);
fMCHist->SetBinError(j, i, fMCHist->GetBinError(j,i)/fluxInt);
}
}
*/
}
delete fineFlux;
delete fluxGraph;
//delete EnuHist;
return;
};
// This interpolates the flux by a TGraph instead of requiring the flux and MC flux to have the same binning
//********************************************************************
-void PlotUtils::FluxUnfoldedScaling(TH1D* mcHist, TH1D* fluxHist) {
+void PlotUtils::FluxUnfoldedScaling(TH1D* mcHist, TH1D* fFluxHist) {
//********************************************************************
// Make a temporary TGraph which holds the points from the flux (essentially copying the TH1D to a TGraph)
TGraph* fluxGraph = new TGraph(fFluxHist->GetNbinsX());
- for (int i = 0; i < fluxHist->GetNbinsX()+1; i++){
- fluxGraph->SetPoint(i, fluxHist->GetXaxis()->GetBinCenter(i+1), fluxHist->GetBinContent(i+1));
+ for (int i = 0; i < fFluxHist->GetNbinsX()+1; i++){
+ fluxGraph->SetPoint(i, fFluxHist->GetXaxis()->GetBinCenter(i+1), fFluxHist->GetBinContent(i+1));
}
// Resolution for the interpolation used for the flux
// Make 100 times finer than flux histogram, COULD BE TWEAKED
- int resolution = 100.*fluxHist->GetXaxis()->GetNbins();
+ int resolution = 100.*fFluxHist->GetXaxis()->GetNbins();
// The new interpolated flux histogram with fine binning
TH1D* fineFlux = new TH1D("fineFlux", "fineFlux", resolution, fFluxHist->GetXaxis()->GetBinLowEdge(1), fFluxHist->GetXaxis()->GetBinLowEdge(fFluxHist->GetNbinsX()+1));
// Set the new TH1D with the TGraph interpolated bin content
for (int i = 0; i < fineFlux->GetNbinsX(); i++) {
// The start and end of the flux histogram might go to zero
// So we really need to take care with these bins; here I just set it flat
- if (fluxHist->GetBinCenter(1) > fineFlux->GetXaxis()->GetBinCenter(i+1)) {
- fineFlux->SetBinContent(i+1, fluxHist->GetBinContent(1));
+ if (fFluxHist->GetBinCenter(1) > fineFlux->GetXaxis()->GetBinCenter(i+1)) {
+ fineFlux->SetBinContent(i+1, fFluxHist->GetBinContent(1));
} else {
fineFlux->SetBinContent(i+1, fluxGraph->Eval(fineFlux->GetXaxis()->GetBinCenter(i+1), 0, "S"));
}
}
- for (int i = 1; i < fMCHist->GetNbinsX()+1; i++) {
+ for (int i = 1; i < mcHist->GetNbinsX()+1; i++) {
// Get the low edge of the ith bin
- Double_t binLowEdge = fMCHist->GetBinLowEdge(i);
+ Double_t binLowEdge = mcHist->GetBinLowEdge(i);
// Get the high edge of the ith bin
- Double_t binHighEdge = fMCHist->GetBinLowEdge(i+1);
+ Double_t binHighEdge = mcHist->GetBinLowEdge(i+1);
// Find the correpsonding bin in the interpolated flux histogram
// Start by finding the low edge of the bin
Int_t fluxLow = 0;
Int_t fluxHigh = 0;
// Find the binLowEdge in the new interpolated flux histogram which matches the mc binning's edge
double diff = 999; // Set the initial difference to be very large
for (; fluxLow < fineFlux->GetNbinsX(); fluxLow++) {
// the difference between the mc bin edge and the flux bin edge
double temp = fabs(binLowEdge - fineFlux->GetBinLowEdge(fluxLow));
// if difference is larger than previous
if (temp < diff) {
diff = temp;
} else {
break;
}
}
if (diff > 0.5) {
// This is a known issue for all BEBC 1pi 1DEnu classes in the first bin, where the flux histogram starts at 8.9GeV but MC binning starts at 5GeV
std::cerr << "Warning " << __FILE__ << ":" << __LINE__ << std::endl;
- std::cerr << "Couldn't find good low-edge bin match for flux histogram " << fFluxHist->GetName() << " and MC " << fMCHist->GetName() << std::endl;
+ std::cerr << "Couldn't find good low-edge bin match for flux histogram " << fFluxHist->GetName() << " and MC " << mcHist->GetName() << std::endl;
std::cout << "fluxLow = " << fluxLow << std::endl;
std::cout << "binLowEdge - fineFlux->GetBinLowEdge(fluxLow) = " << binLowEdge << " - " << fineFlux->GetBinLowEdge(fluxLow) << " = " << binLowEdge - fineFlux->GetBinLowEdge(fluxLow) << std::endl;
}
diff = 999;
for (; fluxHigh < fineFlux->GetNbinsX(); fluxHigh++) {
double temp = fabs(binHighEdge - fineFlux->GetBinLowEdge(fluxHigh));
if (temp < diff) {
diff = temp;
} else {
break;
}
}
if (diff > 0.5) {
// This is a known issue for anti-nu BEBC 1pi 1DEnu classes in the last bin, where the flux histogram ends at 180 GeV but MC binning continues to 200 GeV
std::cerr << "Warning " << __FILE__ << ":" << __LINE__ << std::endl;
- std::cerr << "Couldn't find good high-edge bin match for flux histogram " << fFluxHist->GetName() << " and MC " << fMCHist->GetName() << std::endl;
+ std::cerr << "Couldn't find good high-edge bin match for flux histogram " << fFluxHist->GetName() << " and MC " << mcHist->GetName() << std::endl;
std::cout << "fluxHigh = " << fluxHigh << std::endl;
std::cout << "binHighEdge - fineFlux->GetBinLowEdge(fluxHigh) = " << binHighEdge << " - " << fineFlux->GetBinLowEdge(fluxHigh) << " = " << binHighEdge - fineFlux->GetBinLowEdge(fluxHigh) << std::endl;
}
// fluxHigh - 1 because Integral takes the binLowEdge into account, and fluxHigh is our high edge
double fluxInt = fineFlux->Integral(fluxLow, fluxHigh - 1, "width");
// Scale the bin content in bin i by the flux integral in that bin
if (fluxInt == 0) continue;
mcHist->SetBinContent(i, mcHist->GetBinContent(i)/fluxInt);
mcHist->SetBinError(i, mcHist->GetBinError(i)/fluxInt);
}
delete fineFlux;
delete fluxGraph;
return;
};
//********************************************************************
void PlotUtils::Set2DHistFromText(std::string dataFile, TH2* hist, double norm, bool skipbins){
//********************************************************************
std::string line;
std::ifstream data(dataFile.c_str(),ifstream::in);
int yBin = 0;
while(std::getline(data, line, '\n')){
std::istringstream stream(line);
double entry;
int xBin = 0;
// Loop over entries and insert them into the histogram
while(stream >> entry){
if (!skipbins or entry != -1.0){
hist->SetBinContent(xBin+1, yBin+1, entry*norm);
}
xBin++;
}
yBin++;
}
return;
}
TH1D* PlotUtils::GetTH1DFromFile(std::string dataFile, std::string title, std::string fPlotTitles, std::string alt_name){
TH1D* tempPlot;
// If format is a root file
if (dataFile.find(".root") != std::string::npos){
TFile* temp_infile = new TFile(dataFile.c_str(), "READ");
tempPlot = (TH1D*)temp_infile->Get(title.c_str());
tempPlot->SetDirectory(0);
temp_infile->Close();
delete temp_infile;
// Else its a space seperated txt file
} else {
// Make a TGraph Errors
TGraphErrors *gr = new TGraphErrors(dataFile.c_str(),"%lg %lg %lg");
if (gr->IsZombie()) {
exit(-1);
}
double* bins = gr->GetX();
double* values = gr->GetY();
double* errors = gr->GetEY();
int npoints = gr->GetN();
// Fill the histogram from it
tempPlot = new TH1D(title.c_str(),title.c_str(),npoints-1,bins);
for (int i = 0; i < npoints; ++i){
tempPlot->SetBinContent(i+1, values[i]);
tempPlot->SetBinError(i+1, errors[i]);
}
delete values;
delete errors;
delete bins;
}
// Allow alternate naming for root files
if (!alt_name.empty()){
tempPlot->SetNameTitle(alt_name.c_str(), alt_name.c_str());
}
// Allow alternate axis titles
if (!fPlotTitles.empty()){
tempPlot->SetNameTitle( tempPlot->GetName(), (std::string(tempPlot->GetTitle()) + fPlotTitles).c_str() );
}
return tempPlot;
};
TH1D* PlotUtils::GetRatioPlot(TH1D* hist1, TH1D* hist2){
// make copy of first hist
TH1D* new_hist = (TH1D*) hist1->Clone();
// Do bins and errors ourselves as scales can go awkward
for (int i = 0; i < new_hist->GetNbinsX(); i++){
if (hist2->GetBinContent(i+1) == 0.0){
new_hist->SetBinContent(i+1, 0.0);
}
new_hist->SetBinContent(i+1, hist1->GetBinContent(i+1) / hist2->GetBinContent(i+1) );
new_hist->SetBinError(i+1, hist1->GetBinError(i+1) / hist2->GetBinContent(i+1) );
}
return new_hist;
};
TH1D* PlotUtils::GetRenormalisedPlot(TH1D* hist1, TH1D* hist2){
// make copy of first hist
TH1D* new_hist = (TH1D*) hist1->Clone();
if (hist1->Integral("width") == 0 or hist2->Integral("width") == 0){
new_hist->Reset();
return new_hist;
}
Double_t scaleF = hist2->Integral("width") / hist1->Integral("width");
new_hist->Scale(scaleF);
return new_hist;
};
TH1D* PlotUtils::GetShapePlot(TH1D* hist1){
// make copy of first hist
TH1D* new_hist = (TH1D*) hist1->Clone();
if (hist1->Integral("width") == 0){
new_hist->Reset();
return new_hist;
}
Double_t scaleF1 = 1.0 / hist1->Integral("width");
new_hist->Scale(scaleF1);
return new_hist;
};
TH1D* PlotUtils::GetShapeRatio(TH1D* hist1, TH1D* hist2){
TH1D* new_hist1 = GetShapePlot(hist1);
TH1D* new_hist2 = GetShapePlot(hist2);
// Do bins and errors ourselves as scales can go awkward
for (int i = 0; i < new_hist1->GetNbinsX(); i++){
if (hist2->GetBinContent(i+1) == 0){
new_hist1->SetBinContent(i+1, 0.0);
}
new_hist1->SetBinContent(i+1, new_hist1->GetBinContent(i+1) / new_hist2->GetBinContent(i+1) );
new_hist1->SetBinError(i+1, new_hist1->GetBinError(i+1) / new_hist2->GetBinContent(i+1) );
}
delete new_hist2;
return new_hist1;
};
TH2D* PlotUtils::GetCovarPlot(TMatrixDSym* cov, std::string name, std::string title){
TH2D* CovarPlot;
if (cov) CovarPlot = new TH2D((*cov));
else CovarPlot = new TH2D(name.c_str(), title.c_str(), 1,0,1,1,0,1);
CovarPlot->SetName(name.c_str());
CovarPlot->SetTitle(title.c_str());
return CovarPlot;
}
TH2D* PlotUtils::GetFullCovarPlot(TMatrixDSym* cov, std::string name){
return PlotUtils::GetCovarPlot(cov, name + "_COV", name + "_COV;Bins;Bins;Covariance (#times10^{-76})");
}
TH2D* PlotUtils::GetInvCovarPlot(TMatrixDSym* cov, std::string name){
return PlotUtils::GetCovarPlot(cov, name + "_INVCOV", name + "_INVCOV;Bins;Bins;Inv. Covariance (#times10^{-76})");
}
TH2D* PlotUtils::GetDecompCovarPlot(TMatrixDSym* cov, std::string name){
return PlotUtils::GetCovarPlot(cov, name + "_DECCOV", name + "_DECCOV;Bins;Bins;Decomp Covariance (#times10^{-76})");
}
TH1D* PlotUtils::GetTH1DFromRootFile(std::string file, std::string name){
TFile* rootHistFile = new TFile(file.c_str(),"READ");
TH1D* tempHist = (TH1D*) rootHistFile->Get(name.c_str())->Clone();
tempHist->SetDirectory(0);
rootHistFile->Close();
return tempHist;
}
void PlotUtils::AddNeutModeArray(TH1D* hist1[], TH1D* hist2[], double scaling){
for (int i = 0; i < 60; i++){
if (!hist2[i]) continue;
if (!hist1[i]) continue;
hist1[i]->Add(hist2[i], scaling);
}
return;
}
void PlotUtils::ScaleToData(TH1D* data, TH1D* mc, TH1I* mask){
double scaleF = GetDataMCRatio(data, mc, mask);
mc->Scale(scaleF);
return;
}
void PlotUtils::MaskBins(TH1D* hist, TH1I* mask){
for (int i = 0; i < hist->GetNbinsX(); i++){
if (mask->GetBinContent(i+1) <= 0.5) continue;
hist->SetBinContent(i+1, 0.0);
hist->SetBinError(i+1, 0.0);
LOG(REC)<<"MaskBins: Set "<<hist->GetName()<<" Bin "<<i+1<<" to 0.0 +- 0.0"<<std::endl;
}
return;
}
void PlotUtils::MaskBins(TH2D* hist, TH2I* mask){
for (int i = 0; i < hist->GetNbinsX(); i++){
for (int j = 0; j < hist->GetNbinsY(); j++){
if (mask->GetBinContent(i+1,j+1) <= 0.5) continue;
hist->SetBinContent(i+1,j+1, 0.0);
hist->SetBinError(i+1, j+1,0.0);
LOG(REC)<<"MaskBins: Set "<<hist->GetName()<<" Bin "<<i+1<<" "<<j+1<<" to 0.0 +- 0.0"<<std::endl;
}
}
return;
}
double PlotUtils::GetDataMCRatio(TH1D* data, TH1D* mc, TH1I* mask){
double rat = 1.0;
TH1D* newmc = (TH1D*)mc->Clone();
TH1D* newdt = (TH1D*)data->Clone();
if (mask){
MaskBins(newmc, mask);
MaskBins(newdt, mask);
}
rat = newdt->Integral()/newmc->Integral();
return rat;
}
TH2D* PlotUtils::GetCorrelationPlot(TH2D* cov, std::string name){
TH2D* cor = (TH2D*)cov->Clone();
cor->Reset();
for (int i = 0; i < cov->GetNbinsX(); i++){
for (int j = 0; j < cov->GetNbinsY(); j++){
if (cov->GetBinContent(i+1,i+1) != 0.0 and cov->GetBinContent(j+1,j+1) != 0.0)
cor->SetBinContent(i+1,j+1, cov->GetBinContent(i+1,j+1)/(sqrt(cov->GetBinContent(i+1,i+1) * cov->GetBinContent(j+1,j+1))));
}
}
if (!name.empty()) {
cor->SetNameTitle(name.c_str(), (name + ";;correlation").c_str());
}
cor->SetMinimum(-1);
cor->SetMaximum(1);
return cor;
}
TH2D* PlotUtils::GetDecompPlot(TH2D* cov, std::string name){
TMatrixDSym* covarmat = new TMatrixDSym(cov->GetNbinsX());
for (int i = 0; i < cov->GetNbinsX(); i++)
for (int j = 0; j < cov->GetNbinsY(); j++)
(*covarmat)(i,j) = cov->GetBinContent(i+1,j+1);
TMatrixDSym* decompmat = StatUtils::GetDecomp(covarmat);
TH2D* dec = (TH2D*) cov->Clone();
for (int i = 0; i < cov->GetNbinsX(); i++)
for (int j = 0; j < cov->GetNbinsY(); j++)
dec->SetBinContent(i+1,j+1,(*decompmat)(i,j));
delete covarmat;
delete decompmat;
dec->SetNameTitle(name.c_str(),(name + ";;;decomposition").c_str());
return dec;
}
TH2D* PlotUtils::MergeIntoTH2D(TH1D* xhist, TH1D* yhist, std::string zname){
std::vector<double> xedges, yedges;
for (int i = 0; i < xhist->GetNbinsX()+2; i++) {
xedges.push_back(xhist->GetXaxis()->GetBinLowEdge(i+1));
// std::cout<<"Xedge "<<i<<" "<<xhist->GetXaxis()->GetBinLowEdge(i+1)<<std::endl;
}
for (int i = 0; i < yhist->GetNbinsX()+2; i++) {
yedges.push_back(yhist->GetXaxis()->GetBinLowEdge(i+1));
// std::cout<<"Yedge "<<i<<" "<<yhist->GetXaxis()->GetBinLowEdge(i+1)<<std::endl;
}
int nbinsx = xhist->GetNbinsX();
int nbinsy = yhist->GetNbinsX();
std::string name = std::string(xhist->GetName())+"_vs_"+std::string(yhist->GetName());
std::string titles = ";" + std::string(xhist->GetXaxis()->GetTitle()) + ";" + std::string(yhist->GetXaxis()->GetTitle()) + ";" + zname;
TH2D* newplot = new TH2D(name.c_str(),(name+titles).c_str(), nbinsx, &xedges[0], nbinsy, &yedges[0]);
return newplot;
}
//***************************************************
void PlotUtils::MatchEmptyBins(TH1D* data, TH1D* mc){
//**************************************************
for (int i = 0; i < data->GetNbinsX(); i++){
if (data->GetBinContent(i+1) == 0.0 or data->GetBinError(i+1) == 0.0)
mc->SetBinContent(i+1,0.0);
}
return;
}
//***************************************************
void PlotUtils::MatchEmptyBins(TH2D* data, TH2D* mc){
//**************************************************
for (int i = 0; i < data->GetNbinsX(); i++){
for (int j = 0; j < data->GetNbinsY(); j++){
if (data->GetBinContent(i+1,j+1) == 0.0 or data->GetBinError(i+1,j+1) == 0.0)
mc->SetBinContent(i+1,j+1,0.0);
}
}
return;
}
//***************************************************
TH1D* PlotUtils::GetProjectionX(TH2D* hist, TH2I* mask){
//***************************************************
TH2D* maskedhist = StatUtils::ApplyHistogramMasking(hist, mask);
TH1D* hist_X = maskedhist->ProjectionX();
delete maskedhist;
return hist_X;
}
//***************************************************
TH1D* PlotUtils::GetProjectionY(TH2D* hist, TH2I* mask){
//***************************************************
TH2D* maskedhist = StatUtils::ApplyHistogramMasking(hist, mask);
TH1D* hist_Y = maskedhist->ProjectionY();
delete maskedhist;
return hist_Y;
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Dec 21, 1:52 PM (15 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4023030
Default Alt Text
(407 KB)

Event Timeline