MaCh3 DUNE 1.0.0
Reference Guide
Loading...
Searching...
No Matches
MaCh3DUNEFactory.cpp
Go to the documentation of this file.
2
5// #include "samplePDFDUNE/samplePDFDUNEBeamNDGar.h"
7
8samplePDFFDBase* GetMaCh3DuneInstance(std::string SampleType, std::string SampleConfig, covarianceXsec* &xsec, covarianceOsc* &osc) {
9
10 samplePDFFDBase *FDSample;
11 if (SampleType == "BeamFD") {
12 FDSample = new samplePDFDUNEBeamFD(SampleConfig, xsec, osc);
13 } else if (SampleType == "BeamND") {
14 FDSample = new samplePDFDUNEBeamND(SampleConfig, xsec, osc);
15 // } else if (SampleType == "BeamNDGar") {
16 // FDSample = new samplePDFDUNEBeamNDGar(SampleConfig, xsec);
17 } else if (SampleType == "Atm") {
18 FDSample = new samplePDFDUNEAtm(SampleConfig, xsec, osc);
19 } else {
20 MACH3LOG_ERROR("Invalid SampleType: {} defined in {}", SampleType, SampleConfig);
21 throw MaCh3Exception(__FILE__, __LINE__);
22 }
23
24 return FDSample;
25}
26
27void MakeMaCh3DuneInstance(manager *FitManager, std::vector<samplePDFFDBase*> &DUNEPdfs, covarianceXsec *&xsec, covarianceOsc *&osc){
28
29 // there's a check inside the manager class that does this; left here for demonstrative purposes
30 if (FitManager == nullptr) {
31 MACH3LOG_ERROR("Didn't find a good config in input configuration");
32 throw MaCh3Exception(__FILE__, __LINE__);
33 }
34
35 //Check that you have specified some DUNE samples
36 if(!FitManager->raw()["General"]["DUNESamples"]){
37 MACH3LOG_ERROR("You didn't specify any DUNESample configs to create samples from. Please add General:DUNESamples to your config");
38 throw MaCh3Exception(__FILE__, __LINE__);
39 }
40
41 // Get inputted systematic parameters covariance matrices
42 std::vector<std::string> xsecCovMatrixFile;
43 if (CheckNodeExists(FitManager->raw(), "General", "Systematics", "XsecCovFile") ){
44 xsecCovMatrixFile = FitManager->raw()["General"]["Systematics"]["XsecCovFile"].as<std::vector<std::string>>();
45 } else {
46 MACH3LOG_ERROR("Require General:Systematics:XsecCovFile node in {}, please add this to the file!", FitManager->GetFileName());
47 throw MaCh3Exception(__FILE__, __LINE__);
48 }
49
50 // Setup the covariance matrices
51 if(xsec == nullptr){
52 xsec = new covarianceXsec(xsecCovMatrixFile, "xsec_cov");
53 }
54 else{
55 MACH3LOG_INFO("covariance Xsec has already been created so I am not re-initialising the object");
56 }
57
58 //Setup the cross-section parameters
59 //This should get the prior values.
60 std::vector<double> XsecParVals = xsec->getNominalArray();
61
62 xsec->setParameters(XsecParVals);
63 xsec->setStepScale(FitManager->raw()["General"]["Systematics"]["XsecStepScale"].as<double>());
64
65 MACH3LOG_INFO("cov xsec setup");
66 MACH3LOG_INFO("------------------------------");
67
68 std::vector<std::string> OscMatrixFile = FitManager->raw()["General"]["Systematics"]["OscCovFile"].as<std::vector<std::string>>();
69 std::string OscMatrixName = FitManager->raw()["General"]["Systematics"]["OscCovName"].as<std::string>();
70 std::vector<double> oscpars = FitManager->raw()["General"]["OscillationParameters"].as<std::vector<double>>();
71
72 std::string OscPars = "";
73
74 for (unsigned int i=0;i<oscpars.size();i++) {
75 OscPars+=std::to_string(oscpars[i]);
76 OscPars+=", ";
77 }
78 MACH3LOG_INFO("Oscillation Parameters being used: {} ", OscPars);
79
80 osc = new covarianceOsc(OscMatrixFile,OscMatrixName.c_str());
81 osc->setName("osc_cov");
82
83 std::vector<std::string> OscFixParams = GetFromManager<std::vector<std::string>>(FitManager->raw()["General"]["Systematics"]["OscFix"], {""});
84 // Fixed xsec parameters loop
85 if (OscFixParams.size() == 1 && OscFixParams.at(0) == "All") {
86 for (int j = 0; j < osc->getNpars(); j++) {
87 osc->toggleFixParameter(j);
88 }
89 } else {
90 for (unsigned int j = 0; j < OscFixParams.size(); j++) {
91 osc->toggleFixParameter(OscFixParams.at(j));
92 }
93 }
94
95 MACH3LOG_INFO("Osc cov setup");
96 MACH3LOG_INFO("------------------------------");
97
98 // ==========================================================
99 //read flat prior, fixed paramas from the config file
100 std::vector<std::string> XsecFixParams = GetFromManager<std::vector<std::string>>(FitManager->raw()["General"]["Systematics"]["XsecFix"], {""});
101
102 // Fixed xsec parameters loop
103 if (XsecFixParams.size() == 1 && XsecFixParams.at(0) == "All") {
104 for (int j = 0; j < xsec->getNpars(); j++) {
105 xsec->toggleFixParameter(j);
106 }
107 } else {
108 for (unsigned int j = 0; j < XsecFixParams.size(); j++) {
109 xsec->toggleFixParameter(XsecFixParams.at(j));
110 }
111 }
112 MACH3LOG_INFO("xsec parameters loop done");
113
114 // Fill the parameter values with their nominal values
115 // should _ALWAYS_ be done before overriding with fix or flat
116 xsec->setParameters();
117 osc->setParameters(oscpars);
118
119 //####################################################################################
120 //Create samplePDFDUNE Objs
121 MACH3LOG_INFO("-------------------------------------------------------------------");
122 MACH3LOG_INFO("Loading DUNE samples..");
123 std::vector<std::string> DUNESampleConfigs = FitManager->raw()["General"]["DUNESamples"].as<std::vector<std::string>>();
124
125 for(unsigned int Sample_i = 0 ; Sample_i < DUNESampleConfigs.size() ; Sample_i++){
126
127 manager* tempSampleManager = new manager(DUNESampleConfigs[Sample_i].c_str());
128 std::string SampleType = tempSampleManager->raw()["SampleType"].as<std::string>();
129
130 DUNEPdfs.push_back(GetMaCh3DuneInstance(SampleType, DUNESampleConfigs[Sample_i], xsec, osc));
131
132 // Pure for debugging, lets us set which weights we don't want via the manager
133#if DEBUG_DUNE_WEIGHTS==1
134 DUNEPdfs.back()->setWeightSwitchOffVector(FitManager->getWeightSwitchOffVector());
135 DUNEPdfs.back()->setXsecWeightSwitchOffVector(FitManager->getXsecWeightSwitchOffVector());
136#endif
137 }
138
139 return;
140}
samplePDFFDBase * GetMaCh3DuneInstance(std::string SampleType, std::string SampleConfig, covarianceXsec *&xsec, covarianceOsc *&osc)
void MakeMaCh3DuneInstance(manager *FitManager, std::vector< samplePDFFDBase * > &DUNEPdfs, covarianceXsec *&xsec, covarianceOsc *&osc)
Factory function that generates MaCh3 DUNE instance including configured samples.
Base class for handling atmospheric samples.
Base class for handling FD Beam samples.
Base class for handling beam ND LAR samples.