20 #include "CAFAna/Analysis/CovMxSurface.h" 43 std::vector<std::string> polarity = {
"fhc",
"rhc" };
46 std::vector<std::string>
detector = {
"neardet",
"fardet" };
63 size_t pspos = optstring.find(
"pullsyst=");
64 if (pspos != std::string::npos) {
65 if (optstring.substr(pspos+8, 1) !=
"=")
66 assert(
false and
"The pullsyst option must take the form \"pullsyst=xxx\".");
67 size_t start = pspos+9;
68 size_t end = optstring.find(
"_", pspos);
69 if (end != std::string::npos)
70 pull_syst = optstring.substr(start, end-start);
72 pull_syst =
std::stod(optstring.substr(start));
78 if (pull_syst ==
"all" and covmx_systs)
assert (
false and
79 "Treating systematics as both pull terms and covariance matrix is not permitted.");
83 size_t cmspos = optstring.find(
"covmxsyst=");
84 if (cmspos != std::string::npos) {
85 if (optstring.substr(cmspos+9, 1) !=
"=")
86 assert(
false and
"The covmxsyst option must take the form \"covmxsyst=xxx\".");
88 assert(
false and
"All covmxsysts already, \"covmxsyst=xxx\" is redundant");
89 if (pull_syst!=
"none")
90 assert(
false and
"Are you sure you want to use a single CM syst with a single pull term?");
91 size_t start = cmspos+10;
92 size_t end = optstring.find(
"_", cmspos);
93 if (end != std::string::npos)
94 cm_syst = optstring.substr(start, end-start);
96 cm_syst =
std::stod(optstring.substr(start));
101 TDirectory* fakedata_dir =
nullptr;
102 size_t upos = optstring.find(
"universe");
103 if (upos != std::string::npos) {
105 size_t start = upos + 8;
106 size_t end = optstring.find(
"_", upos);
107 if (end != std::string::npos)
108 universe = std::stoi(optstring.substr(start, end - start));
110 universe = std::stoi(optstring.substr(start));
115 TFile* fakedata_file = TFile::Open(fakedata_filename.c_str(),
"read");
117 fakedata_dir = (TDirectory*)fakedata_file->Get(dirname.c_str());
119 assert(
false and
"Unable to load fake data directory.");
124 size_t dmpos = optstring.find(
"dm41=");
125 if (dmpos != std::string::npos) {
126 if (optstring.substr(dmpos+4, 1) !=
"=")
127 throw std::runtime_error(
"The dm41 option must take the form \"dm41=xxx\".");
128 size_t start = dmpos+5;
129 size_t end = optstring.find(
"_", dmpos);
130 if (end != std::string::npos)
131 dm41 =
std::stod(optstring.substr(start, end-start));
133 dm41 =
std::stod(optstring.substr(start));
138 bool prof_delta24 = not
CheckOption(opt,
"noprofdelta24");
141 bool th24vsth34 =
false;
142 bool th24vsdm41 =
false;
143 bool th34vsdm41 =
false;
144 if (
CheckOption(opt,
"th24vsth34")) th24vsth34 =
true;
145 else if (
CheckOption(opt,
"th24vsdm41")) th24vsdm41 =
true;
146 else if (
CheckOption(opt,
"th34vsdm41")) th34vsdm41 =
true;
147 else throw std::runtime_error(
"The options string must contain plot type: \"th24vsth34\", \"th24vsdm41\" or \"th34vsdm41\".");
150 if (th24vsth34 && dm41 == -1)
151 throw std::runtime_error(
"If you want to run a th24 vs th34 surface, you must specify a value for dm41.");
164 std::vector<covmx::Sample> samples;
165 std::vector<IPrediction*> preds;
166 std::vector<const ISyst*> isysts;
167 for (
size_t d = 0;
d < 2; ++
d) {
168 for (
size_t p = 0;
p < 2; ++
p) {
169 if (!use_polarity[
p] || !use_detector[
d])
continue;
172 if(samples.size()==1)
175 preds.push_back(
LoadPrediction(samples.back(), pull_syst ==
"none" ?
"nosysts" :
"systs"));
181 std::vector<Spectrum*>
cosmic;
182 for (
auto sample : samples){
189 std::vector<Spectrum*>
data;
191 for (
auto sample : samples){
198 for (
size_t i = 0;
i < preds.size(); ++
i) {
202 if (cosmic[
i]) *data[
i] += *cosmic[
i];
210 std::vector<const ISyst*> pull_systs = {};
211 SystConcat* sc =
nullptr;
212 if (pull_syst ==
"all") {
214 if (samples.size() == 1)
219 pull_systs = sc->GetActiveSysts();
222 else if (pull_syst !=
"none") {
224 if (samples.size() == 1) {
225 for (
const ISyst* syst : isysts) {
227 pull_systs = { syst };
231 if (pull_systs.empty()) {
232 std::ostringstream err;
233 err <<
"Couldn't find requested pull systematic " << pull_syst;
234 assert (
false and err.str().c_str());
239 std::vector<SystConcat> all_scs =
GetSystConcats(samples, preds, isysts);
240 for (
auto it_sc : all_scs) {
241 if (
GetSystBaseName(it_sc.GetActiveSysts()[0]->ShortName()) == pull_syst) {
242 sc =
new SystConcat(it_sc);
243 pull_systs = sc->GetActiveSysts();
251 CovarianceMatrix* mx =
nullptr;
252 if (covmx_systs || cm_syst!=
"none") {
253 std::vector<CovarianceMatrix*> CMs;
254 std::vector<Binning>
bins;
255 for (
auto d : data) bins.push_back(
d->GetBinnings()[0]);
256 mx =
new CovarianceMatrix(bins);
258 for (CovarianceMatrix* it_mx :
GetMatrices(samples)) {
261 if (cm_syst!=
"none" && cm_syst!=sysname)
continue;
265 <<
" to covariance matrix." <<
std::endl;
266 mx->AddMatrix(it_mx);
269 std::cout <<
"Omitting pull term " << pull_syst
282 if (covmx_systs||cm_syst!=
"none") expt =
new OscCovMxExperiment(preds, mx, data, cosmic);
287 expts.push_back(expt);
292 calc->
SetDm(4, dm41);
301 std::map<const IFitVar*, std::vector<double> > seed_values;
309 std::vector<const IFitVar*> xy_vars;
317 else if (th24vsdm41 || th34vsdm41) {
342 CovMxSurface surf(*xbins, *ybins, &multi_expt, calc, xy_vars[0], xy_vars[1],
344 preds, data, cosmic, part, njobs);
348 TFile*
f =
new TFile(outfile.c_str(),
"recreate");
349 surf.
SaveTo(f, optstring.c_str());
std::vector< SystConcat > GetSystConcats(std::vector< covmx::Sample > samples, std::vector< IPrediction * > preds, std::vector< const ISyst * > systs)
Get correctly concatenated systs for ND and FD.
const FitSinSqTheta24Sterile kFitSinSqTheta24Sterile
size_t JobNumber()
What's the process number for a grid job?
Represent the binning of a Spectrum's x-axis.
Cuts and Vars for the 2020 FD DiF Study.
std::string GetSystBaseName(std::string name)
Get the last part of a systematic's ShortName.
double stod(const std::string &val)
bool RunningOnGrid()
Is this a grid (condor) job?
void SetDelta(int i, int j, double delta)
Adapt the PMNS_Sterile calculator to standard interface.
const FitDmSq32Sterile kFitDmSq32Sterile
const FitTheta24InDegreesSterile kFitTheta24InDegreesSterile
const FitSinSqTheta34Sterile kFitSinSqTheta34Sterile
static SystShifts Nominal()
std::string FindCAFAnaDir()
void SetAngles(osc::OscCalcSterile *calc)
Encapsulate code to systematically shift a caf::SRProxy.
void SaveTo(TDirectory *dir) const
Standard SaveTo implementation.
const XML_Char const XML_Char * data
const FitDelta24InPiUnitsSterile kFitDelta24InPiUnitsSterile
osc::OscCalcSterile * DefaultSterileCalc(int nflavors)
Create a sterile calculator with default assumptions for all parameters.
Sum up livetimes from individual cosmic triggers.
std::vector< const IExperiment * > GetConstraints()
Gaussian constrains on atmospheric parameters.
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
std::vector< bool > GetOptionConfig(TString opt, std::vector< std::string > options)
Compare a single data spectrum to the MC + cosmics expectation.
std::vector< CovarianceMatrix * > GetMatrices(std::vector< covmx::Sample > samples, bool cvmfs=true)
std::vector< float > Spectrum
SystConcat GetSystConcat(std::vector< covmx::Sample > samples, std::vector< const ISyst * > systs, std::vector< IPrediction * > preds)
Get correctly concatenated systs for ND and FD.
bool CheckOption(TString opts, TString opt)
Combine multiple component experiments.
void SetDm(int i, double dm)
IPrediction * LoadPrediction(std::string detector, bool rhc=false, std::string syst_type="all")
Function to load prediction object.
static Binning LogUniform(int n, double lo, double hi)
std::unique_ptr< Spectrum > LoadCosmic(covmx::Sample sample, bool cvmfs=true)
Get cosmics for a given sample.
assert(nhit_max >=nhit_nbins)
const FitTheta34InDegreesSterile kFitTheta34InDegreesSterile
std::string to_string(ModuleType mt)
Prevent histograms being added to the current directory.
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
const FitDmSq41Sterile kFitDmSq41Sterile
const double kNus19SensLivetime
std::vector< const ISyst * > GetSystsFromFile(covmx::Sample sample)
Get systematics for a given sample.
const FitTheta23Sterile kFitTheta23Sterile