Factory function that generates MaCh3 DUNE instance including configured samples.
27 {
28
29
30 if (FitManager == nullptr) {
31 MACH3LOG_ERROR("Didn't find a good config in input configuration");
32 throw MaCh3Exception(__FILE__, __LINE__);
33 }
34
35
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
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
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
59
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
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
100 std::vector<std::string> XsecFixParams = GetFromManager<std::vector<std::string>>(FitManager->raw()["General"]["Systematics"]["XsecFix"], {""});
101
102
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
115
116 xsec->setParameters();
117 osc->setParameters(oscpars);
118
119
120
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
131
132
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)