14 #pragma GCC diagnostic ignored "-Wuseless-cast"
20 MACH3LOG_ERROR(
"Trying to create BinnedSplineHandler with uninitialized covariance object");
26 MACH3LOG_ERROR(
"Trying to create BinnedSplineHandler with uninitialized MaCh3Modes object");
82 const std::string& SampleTitle,
83 const std::vector<std::string>& OscChanFileNames,
84 const std::vector<std::string>& SplineVarNames) {
88 Dimensions.push_back(
static_cast<int>(SplineVarNames.size()));
108 MACH3LOG_INFO(
"SplineModeVecs_Sample is of size {}", SplineModeVecs_Sample.size());
113 int nOscChan = int(OscChanFileNames.size());
118 std::vector<std::vector<TAxis *>> SampleBinning(nOscChan);
119 for (
int iOscChan = 0; iOscChan < nOscChan; iOscChan++)
121 SampleBinning[iOscChan] =
FindSplineBinning(OscChanFileNames[iOscChan], SampleTitle);
123 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
128 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
131 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
138 std::map<unsigned int, std::map<unsigned int, std::map<std::string, std::pair<unsigned int, unsigned int>>>> systZeroCounts;
140 unsigned int iSample = entry.iSample;
141 unsigned int iSyst = entry.iSyst;
146 auto& counts = systZeroCounts[iSample][iSyst][modeSuffix];
149 if (entry.value == -1)
152 if (counts.second > 1)
155 "Sample '{}' | OscChan {} | Syst '{}' | Mode '{}' | Var {} => Value: {}",
168 for (
const auto& samplePair : systZeroCounts) {
169 unsigned int iSample = samplePair.first;
171 for (
const auto& systPair : samplePair.second) {
172 unsigned int iSyst = systPair.first;
173 const auto& systName = SplineFileParPrefixNames_Sample[iSyst];
174 for (
const auto& modePair : systPair.second) {
175 const auto& modeSuffix = modePair.first;
176 const auto& counts = modePair.second;
178 "Sample '{}': Systematic '{}' has missing splines in mode '{}'. Expected Splines: {}, Missing Splines: {}",
196 if (
static_cast<unsigned int>(NSplines_All) !=
MonolithIndex) {
198 MACH3LOG_ERROR(
"Something's gone wrong when we tried to get the size of your monolith");
214 int ValidSplineCounter = 0;
215 int ValidKnotCounter = 0;
217 int splineindex = entry.value;
221 bool foundUniqueSpline =
false;
223 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
227 paramNo_arr[ValidSplineCounter] =
static_cast<short int>(iUniqueSyst);
228 foundUniqueSpline =
true;
234 if (!foundUniqueSpline)
239 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
254 nKnots_arr[ValidSplineCounter] = ValidKnotCounter;
255 for(
int i = 0; i < splineKnots; i++){
262 ValidKnotCounter += splineKnots;
263 delete[] tmpXCoeffArr;
264 delete[] tmpManyCoeffArr;
265 ValidSplineCounter++;
303 #pragma omp parallel for simd
305 for (
unsigned int splineNum = 0; splineNum <
NSplines_valid; ++splineNum)
313 const short int segment_X = short(Param*
_max_knots+segment);
343 for (
int iOscChan = 0; iOscChan <
nOscChans[iSample]; ++iOscChan)
347 int nModesInSyst =
static_cast<int>(
SplineModeVecs[iSample][iSyst].size());
348 for (
int iMode = 0; iMode < nModesInSyst; ++iMode)
350 const int nDims =
static_cast<int>(
SplineBinning[iSample][iOscChan].size());
351 std::vector<int> nBins(nDims);
352 for (
int iDim = 0; iDim < nDims; ++iDim) {
353 nBins[iDim] =
SplineBinning[iSample][iOscChan][iDim]->GetNbins();
356 std::vector<int> iVar(nDims, 0);
369 IndexVectMap[std::make_tuple(iSample, iOscChan, iSyst, iMode, iVar)] =
static_cast<int>(
IndexVect.size() - 1);
371 int iDim = nDims - 1;
372 while (iDim >= 0 && ++iVar[iDim] == nBins[iDim]) {
387 const std::string& SampleTitle) {
390 TH1* Axis_Hist =
nullptr;
392 auto File = std::unique_ptr<TFile>(TFile::Open(FileName.c_str(),
"READ"));
393 if (!File || File->IsZombie())
396 MACH3LOG_ERROR(
"This is caused by something here! {} : {}", __FILE__, __LINE__);
403 std::string TemplateName =
"dev_tmp_0_0";
404 TObject *Obj = File->Get(TemplateName.c_str());
408 TemplateName =
"dev_tmp.0.0";
409 Obj = File->Get(TemplateName.c_str());
412 MACH3LOG_ERROR(
"Could not find dev_tmp_0_0 in spline file. Spline binning cannot be set!");
419 bool isHist2D = Obj->IsA() == TH2F::Class();
421 bool isHist3D = Obj->IsA() == TH3F::Class();
422 if (!isHist2D && !isHist3D)
424 MACH3LOG_ERROR(
"Object doesn't inherit from either TH2D and TH3D - Odd A");
435 Axis_Hist = File->Get<TH2F>(TemplateName.c_str());
440 Axis_Hist = File->Get<TH3F>((TemplateName.c_str()));
441 if (
Dimensions[iSample] != 3 && Axis_Hist->GetZaxis()->GetNbins() != 1)
448 std::vector<TAxis*> ReturnVec(3);
449 ReturnVec[0] =
static_cast<TAxis*
>(Axis_Hist->GetXaxis()->Clone());
450 ReturnVec[1] =
static_cast<TAxis*
>(Axis_Hist->GetYaxis()->Clone());
453 ReturnVec[2] =
static_cast<TAxis*
>(Axis_Hist->GetZaxis()->Clone());
456 constexpr
double DummyEdges[2] = {-1e15, 1e15};
457 ReturnVec[2] =
new TAxis(1, DummyEdges);
460 for (
unsigned int iAxis = 0; iAxis < ReturnVec.size(); ++iAxis) {
490 int FullCounter_All = 0;
491 int FullCounter_NonFlat = 0;
493 for (
unsigned int index = 0; index <
IndexVect.size(); index++)
497 int iSample = entry.iSample;
502 entry.iMode, entry.iVar)) {
505 SampleAll[iSample]++;
508 SampleNonFlat[iSample]++;
513 for (
size_t iSample = 0; iSample <
SampleTitles.size(); iSample++)
515 MACH3LOG_DEBUG(
"{:<10} has {:<10} splines, of which {:<10} are not flat",
518 SampleNonFlat[iSample]);
520 FullCounter_All += SampleAll[iSample];
521 FullCounter_NonFlat += SampleNonFlat[iSample];
525 MACH3LOG_INFO(
"Total number of splines loaded: {}", FullCounter_All);
526 MACH3LOG_INFO(
"Total number of non-flat splines loaded: {}", FullCounter_NonFlat);
530 return FullCounter_NonFlat;
532 return FullCounter_All;
539 std::vector<TSpline3_red*> UniqueSystSplines;
548 std::map<std::pair<int, int>,
bool> HasNonFlatSpline = {};
552 const int splineindex = entry.value;
553 CounterIdx = {entry.iSample, entry.iSyst};
556 if (HasNonFlatSpline[CounterIdx]) {
562 HasNonFlatSpline[CounterIdx] =
true;
567 bool FoundSyst =
false;
568 for (
unsigned int iFoundSyst = 0;iFoundSyst <
UniqueSystNames.size(); iFoundSyst++)
587 for(
const auto& [syst_sample, is_non_flat] : HasNonFlatSpline){
593 auto[sample, syst] = syst_sample;
595 MACH3LOG_WARN(
"Could only find flat splines for syst {} in sample {}. This might cause problems.", syst_name, sample);
598 nParams =
static_cast<short int>(UniqueSystSplines.size());
602 for (
int iSpline = 0; iSpline <
nParams; iSpline++)
611 UniqueSystSplines[iSpline]->GetKnot(iKnot, xPoint, yPoint);
620 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++) {
624 for (
const auto& line : table.Render()) {
628 int nCombinations_FlatSplines = 0;
629 int nCombinations_All = 0;
631 for (
unsigned int index = 0; index <
IndexVect.size(); index++)
633 int splineindex =
IndexVect[index].value;;
636 nCombinations_FlatSplines++;
641 MACH3LOG_INFO(
"Number of combinations of Sample, OscChan, Syst and Mode which have entirely flat response: {} / {}", nCombinations_FlatSplines, nCombinations_All);
651 for (
int i = 0; i < nPoints; i++) {
653 for (
int j = 0; j <
_nCoeff_; j++) {
658 for(
int i=0; i<nPoints; i++) {
684 for (
size_t iSample = 0; iSample <
SampleTitles.size(); ++iSample) {
686 return static_cast<int>(iSample);
709 std::map<int, std::set<int>> OscToSysts;
712 if (entry.iSample != iSample)
continue;
713 OscToSysts[entry.iOscChan].insert(entry.iSyst);
715 MACH3LOG_INFO(
"Sample {} has {} oscillation channels", SampleTitle, OscToSysts.size());
717 for (
const auto& OscPair : OscToSysts) {
718 int osc = OscPair.first;
719 const std::set<int>& SystSet = OscPair.second;
720 MACH3LOG_INFO(
"Oscillation channel {} has {} systematics", osc, SystSet.size());
726 int iSyst,
int iMode,
const std::vector<int>& iVar)
const {
738 for (
size_t i = 0; i < iVar.size(); ++i) {
751 const int NBins = Axis->GetNbins();
752 std::string text =
"";
753 for (
int iBin = 0; iBin <= NBins; iBin++) {
754 text += fmt::format(
"{} ", Axis->GetXbins()->GetAt(iBin));
761 int iOscChan,
int EventMode,
const std::vector<double>& VarVals) {
763 std::vector<SplineIndex> ReturnVec;
778 std::vector<int> var_bins;
779 for (
size_t i = 0; i < VarVals.size(); ++i) {
780 int bin =
SplineBinning[SampleIndex][iOscChan][i]->FindBin(VarVals[i]) - 1;
781 if (bin < 0 || bin >=
SplineBinning[SampleIndex][iOscChan][i]->GetNbins()) {
784 var_bins.push_back(bin);
787 for(
int iSyst=0; iSyst <
nSplineParams[SampleIndex]; iSyst++){
788 std::vector<int> spline_modes =
SplineModeVecs[SampleIndex][iSyst];
789 int nSampleModes =
static_cast<int>(spline_modes.size());
792 for(
int iMode = 0; iMode<nSampleModes; iMode++) {
794 if (Mode == spline_modes[iMode]) {
795 int index =
IndexVectMap.at(std::make_tuple(SampleIndex, iOscChan, iSyst, iMode,
806 ReturnVec.push_back(idx);
820 size_t InputVectorSize = InputVector.size();
821 std::vector< std::vector<int> > ReturnVec(InputVectorSize);
824 for (
size_t iSyst=0;iSyst<InputVectorSize;iSyst++) {
825 std::vector<int> TmpVec;
826 std::vector<std::string> TestVec;
829 for (
unsigned int iMode = 0 ; iMode < InputVector[iSyst].size() ; iMode++) {
830 int Mode = InputVector[iSyst][iMode];
833 bool IncludeMode =
true;
834 for (
auto TestString : TestVec) {
835 if (ModeName == TestString) {
842 TmpVec.push_back(Mode);
843 TestVec.push_back(ModeName);
847 ReturnVec[iSyst] = TmpVec;
892 for (
int iOscChan = 0; iOscChan < nOscChannels; iOscChan++) {
894 TSpline3* mySpline =
nullptr;
897 std::set<std::string> SplineFileNames;
898 auto File = std::unique_ptr<TFile>(TFile::Open(OscChanFileNames[iOscChan].c_str()));
900 if (!File || File->IsZombie()) {
907 for (
auto k : *File->GetListOfKeys()) {
908 auto Key =
static_cast<TKey*
>(k);
909 TClass *Class = gROOT->GetClass(Key->GetClassName(),
false);
910 if(!Class->InheritsFrom(
"TSpline3")) {
914 std::string FullSplineName = std::string(Key->GetName());
916 if (SplineFileNames.count(FullSplineName) > 0) {
917 MACH3LOG_CRITICAL(
"Skipping spline - Found a spline whose name has already been encountered before: {}", FullSplineName);
920 SplineFileNames.insert(FullSplineName);
926 std::vector<int> VarBins;
928 for (std::size_t i =
kVarBinToken; i < Tokens.size(); ++i) {
929 VarBins.push_back(std::stoi(Tokens.at(i)));
942 MACH3LOG_DEBUG(
"Couldn't Match any systematic name in ParameterHandler with spline name: {}" , FullSplineName);
947 for (
unsigned int iMode = 0; iMode <
SplineModeVecs[iSample][SystNum].size(); iMode++) {
957 MACH3LOG_DEBUG(
"Couldn't find mode for {} in {}. Problem Spline is : {} ", Mode, Syst, FullSplineName);
961 mySpline = Key->ReadObject<TSpline3>();
964 MACH3LOG_TRACE(
"Pushed back monolith for spline {}", FullSplineName);
966 int nKnots = mySpline->GetNp();
968 for (
int iKnot = 0; iKnot < nKnots; iKnot++) {
970 mySpline->GetKnot(iKnot, x, y);
971 if (y < 0.99999 || y > 1.00001)
979 int index =
IndexVectMap.at(std::make_tuple(iSample, iOscChan, SystNum, ModeNum, VarBins));
988 if(mySpline)
delete mySpline;
1015 size_t pos = FileName.find(
' ');
1016 if (pos != std::string::npos) {
1017 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
1018 while ((pos = FileName.find(
' ')) != std::string::npos) {
1019 FileName[pos] =
'_';
1022 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"OPEN");
1024 TMacro *ConfigCov = SplineFile->Get<TMacro>(
"ParameterHandler");
1032 MACH3LOG_ERROR(
"Loading precomputed spline file, however encountered different YAML config, please regenerate input");
1041 for (
int iSpline = 0; iSpline <
nParams; iSpline++) {
1044 SplineFile->Close();
1056 TTree *Settings = SplineFile->Get<TTree>(
"Settings");
1057 int CoeffIndex_temp;
1058 unsigned int NSplines_valid_temp;
1059 short int nParams_temp, max_knots_temp;
1060 Settings->SetBranchAddress(
"CoeffIndex", &CoeffIndex_temp);
1061 Settings->SetBranchAddress(
"NSplines_valid", &NSplines_valid_temp);
1062 Settings->SetBranchAddress(
"nParams", &nParams_temp);
1063 Settings->SetBranchAddress(
"max_knots", &max_knots_temp);
1065 int SplineBinning_size1, SplineBinning_size2, SplineBinning_size3;
1066 Settings->SetBranchAddress(
"SplineBinning_size1", &SplineBinning_size1);
1067 Settings->SetBranchAddress(
"SplineBinning_size2", &SplineBinning_size2);
1068 Settings->SetBranchAddress(
"SplineBinning_size3", &SplineBinning_size3);
1069 int SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3;
1070 Settings->SetBranchAddress(
"SplineModeVecs_size1", &SplineModeVecs_size1);
1071 Settings->SetBranchAddress(
"SplineModeVecs_size2", &SplineModeVecs_size2);
1072 Settings->SetBranchAddress(
"SplineModeVecs_size3", &SplineModeVecs_size3);
1073 std::vector<std::string>* SampleNames_temp =
nullptr;
1074 Settings->SetBranchAddress(
"SampleNames", &SampleNames_temp);
1075 std::vector<std::string>* SampleTitles_temp =
nullptr;
1076 Settings->SetBranchAddress(
"SampleTitles", &SampleTitles_temp);
1077 std::vector<int>* nSplineParams_temp =
nullptr;
1078 Settings->SetBranchAddress(
"nSplineParams", &nSplineParams_temp);
1079 Settings->GetEntry(0);
1090 auto Resize3D = [](
auto& vec,
int d1,
int d2,
int d3) {
1092 for (
int i = 0; i < d1; ++i) {
1094 for (
int j = 0; j < d2; ++j) {
1095 vec[i][j].resize(d3);
1100 Resize3D(
SplineBinning, SplineBinning_size1, SplineBinning_size2, SplineBinning_size3);
1101 Resize3D(
SplineModeVecs, SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3);
1108 TTree *MonolithTree = SplineFile->Get<TTree>(
"MonolithTree");
1113 std::vector<int>* monolith_index_temp =
nullptr;
1114 MonolithTree->SetBranchAddress(
"monolith_index", &monolith_index_temp);
1117 std::vector<unsigned int>* nKnots_arr_temp =
nullptr;
1118 MonolithTree->SetBranchAddress(
"nKnots_arr", &nKnots_arr_temp);
1119 std::vector<short int>* paramNo_arr_temp =
nullptr;
1120 MonolithTree->SetBranchAddress(
"paramNo_arr", ¶mNo_arr_temp);
1121 std::vector<int>* UniqueSystIndices_temp =
nullptr;
1122 MonolithTree->SetBranchAddress(
"UniqueSystIndices", &UniqueSystIndices_temp);
1126 MonolithTree->SetBranchAddress(
"xcoeff",
xcoeff_arr);
1128 MonolithTree->GetEntry(0);
1140 TTree *IndexTree = SplineFile->Get<TTree>(
"IndexVec");
1143 IndexTree->SetBranchAddress(
"SplineIndex", &IndexTemp);
1144 IndexVect.resize(IndexTree->GetEntries());
1146 for (Long64_t iEntry = 0; iEntry < IndexTree->GetEntries(); ++iEntry) {
1147 IndexTree->GetEntry(iEntry);
1150 auto key = std::make_tuple(IndexTemp->iSample, IndexTemp->iOscChan, IndexTemp->iSyst,
1151 IndexTemp->iMode, IndexTemp->iVar);
1156 TTree *SplineBinningTree = SplineFile->Get<TTree>(
"SplineBinningTree");
1157 std::vector<int> indices(3);
1158 SplineBinningTree->SetBranchAddress(
"i", &indices[0]);
1159 SplineBinningTree->SetBranchAddress(
"j", &indices[1]);
1160 SplineBinningTree->SetBranchAddress(
"k", &indices[2]);
1161 TAxis* axis =
nullptr;
1162 SplineBinningTree->SetBranchAddress(
"axis", &axis);
1165 for (Long64_t entry = 0; entry < SplineBinningTree->GetEntries(); ++entry) {
1166 SplineBinningTree->GetEntry(entry);
1170 SplineBinning[i][j][k] =
static_cast<TAxis*
>(axis->Clone());
1173 std::vector<int> indices_mode(3);
1175 TTree *SplineModeTree = SplineFile->Get<TTree>(
"SplineModeTree");
1176 SplineModeTree->SetBranchAddress(
"i", &indices_mode[0]);
1177 SplineModeTree->SetBranchAddress(
"j", &indices_mode[1]);
1178 SplineModeTree->SetBranchAddress(
"k", &indices_mode[2]);
1179 SplineModeTree->SetBranchAddress(
"value", &mode_value);
1182 for (Long64_t entry = 0; entry < SplineModeTree->GetEntries(); ++entry) {
1183 SplineModeTree->GetEntry(entry);
1184 int i = indices_mode[0];
1185 int j = indices_mode[1];
1186 int k = indices_mode[2];
1197 size_t pos = FileName.find(
' ');
1198 if (pos != std::string::npos) {
1199 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
1200 while ((pos = FileName.find(
' ')) != std::string::npos) {
1201 FileName[pos] =
'_';
1205 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"recreate");
1207 TMacro ConfigSave =
YAMLtoTMacro(ConfigCurrent,
"ParameterHandler");
1216 SplineFile->Close();
1222 TTree *Settings =
new TTree(
"Settings",
"Settings");
1225 short int nParams_temp =
nParams;
1228 Settings->Branch(
"CoeffIndex", &CoeffIndex_temp,
"CoeffIndex/I");
1229 Settings->Branch(
"NSplines_valid", &NSplines_valid_temp,
"NSplines_valid/i");
1230 Settings->Branch(
"nParams", &nParams_temp,
"nParams/S");
1231 Settings->Branch(
"max_knots", &max_knots_temp,
"max_knots/S");
1233 int SplineBinning_size1 =
static_cast<int>(
SplineBinning.size());
1234 int SplineBinning_size2 = (SplineBinning_size1 > 0) ?
static_cast<int>(
SplineBinning[0].size()) : 0;
1235 int SplineBinning_size3 = (SplineBinning_size2 > 0) ?
static_cast<int>(
SplineBinning[0][0].size()) : 0;
1237 Settings->Branch(
"SplineBinning_size1", &SplineBinning_size1,
"SplineBinning_size1/I");
1238 Settings->Branch(
"SplineBinning_size2", &SplineBinning_size2,
"SplineBinning_size2/I");
1239 Settings->Branch(
"SplineBinning_size3", &SplineBinning_size3,
"SplineBinning_size3/I");
1241 int SplineModeVecs_size1 =
static_cast<int>(
SplineModeVecs.size());
1242 int SplineModeVecs_size2 = (SplineModeVecs_size1 > 0) ?
static_cast<int>(
SplineModeVecs[0].size()) : 0;
1243 int SplineModeVecs_size3 = (SplineModeVecs_size2 > 0) ?
static_cast<int>(
SplineModeVecs[0][0].size()) : 0;
1245 Settings->Branch(
"SplineModeVecs_size1", &SplineModeVecs_size1,
"SplineModeVecs_size1/I");
1246 Settings->Branch(
"SplineModeVecs_size2", &SplineModeVecs_size2,
"SplineModeVecs_size2/I");
1247 Settings->Branch(
"SplineModeVecs_size3", &SplineModeVecs_size3,
"SplineModeVecs_size3/I");
1249 std::vector<std::string> SampleNames_temp =
SampleNames;
1250 Settings->Branch(
"SampleNames", &SampleNames_temp);
1251 std::vector<std::string> SampleTitles_temp =
SampleTitles;
1252 Settings->Branch(
"SampleTitles", &SampleTitles_temp);
1254 Settings->Branch(
"nSplineParams", &nSplineParams_temp);
1266 MACH3LOG_ERROR(
"{} Will not work as manycoeff_arr is nullptr :(", __func__);
1270 TTree *MonolithTree =
new TTree(
"MonolithTree",
"MonolithTree");
1274 MonolithTree->Branch(
"monolith_index", &monolith_index_temp);
1275 std::vector<unsigned int> nKnots_arr_temp =
nKnots_arr;
1276 MonolithTree->Branch(
"nKnots_arr", &nKnots_arr_temp);
1277 std::vector<short int> paramNo_arr_temp =
paramNo_arr;
1278 MonolithTree->Branch(
"paramNo_arr", ¶mNo_arr_temp);
1280 MonolithTree->Branch(
"UniqueSystIndices", &UniqueSystIndices_temp);
1283 MonolithTree->Fill();
1285 MonolithTree->Write();
1286 delete MonolithTree;
1293 TTree *IndexTree =
new TTree(
"IndexVec",
"IndexVec");
1295 IndexTree->Branch(
"SplineIndex", &entry);
1310 TTree *SplineBinningTree =
new TTree(
"SplineBinningTree",
"SplineBinningTree");
1311 std::vector<int> indices(3);
1312 TAxis* axis =
nullptr;
1313 SplineBinningTree->Branch(
"i", &indices[0],
"i/I");
1314 SplineBinningTree->Branch(
"j", &indices[1],
"j/I");
1315 SplineBinningTree->Branch(
"k", &indices[2],
"k/I");
1316 SplineBinningTree->Branch(
"axis",
"TAxis", &axis);
1323 indices[0] =
static_cast<int>(i);
1324 indices[1] =
static_cast<int>(j);
1325 indices[2] =
static_cast<int>(k);
1326 SplineBinningTree->Fill();
1331 SplineBinningTree->Write();
1332 delete SplineBinningTree;
1334 std::vector<int> indices_mode(3);
1337 TTree *SplineModeTree =
new TTree(
"SplineModeTree",
"SplineModeTree");
1339 SplineModeTree->Branch(
"i", &indices_mode[0],
"i/I");
1340 SplineModeTree->Branch(
"j", &indices_mode[1],
"j/I");
1341 SplineModeTree->Branch(
"k", &indices_mode[2],
"k/I");
1342 SplineModeTree->Branch(
"value", &mode_value,
"value/I");
1348 indices_mode[0] =
static_cast<int>(i);
1349 indices_mode[1] =
static_cast<int>(j);
1350 indices_mode[2] =
static_cast<int>(k);
1352 SplineModeTree->Fill();
1358 SplineModeTree->Write();
1359 delete SplineModeTree;
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
#define _MaCh3_Safe_Include_End_
#define MACH3LOG_CRITICAL
void CleanContainer(T &)
Base case: do nothing for non-pointer types.
void CleanVector(T &)
Base case: do nothing for non-vector types.
@ kSpline
For splined parameters (1D)
constexpr int _nCoeff_
KS: We store coefficients {y,b,c,d} in one array one by one, this is only to define it once rather th...
void ApplyKnotWeightCapTSpline3(TSpline3 *&Spline, const int splineParsIndex, ParameterHandlerGeneric *ParHandler)
EM: Apply capping to knot weight for specified spline parameter. param graph needs to have been set i...
bool isFlat(TSpline3_red *&spl)
CW: Helper function used in the constructor, tests to see if the spline is flat.
TMacro YAMLtoTMacro(const YAML::Node &yaml_node, const std::string &name)
Convert a YAML node to a ROOT TMacro object.
YAML::Node TMacroToYAML(const TMacro ¯o)
KS: Convert a ROOT TMacro object to a YAML node.
bool compareYAMLNodes(const YAML::Node &node1, const YAML::Node &node2, bool Mute=false)
Compare if yaml nodes are identical.
bool isValidSplineIndex(const std::string &SampleTitle, int iSyst, int iOscChan, int iMode, const std::vector< int > &iVar) const
Ensure we have spline for a given bin.
virtual void FillSampleArray(const std::string &SampleTitle, const std::vector< std::string > &OscChanFileNames)
Loads and processes splines from ROOT files for a given sample.
std::vector< short int > paramNo_arr
CW: CPU array with the number of points per spline (not per spline point!)
void LoadIndexDir(std::unique_ptr< TFile > &SplineFile)
KS: Load preprocessed Index.
ParameterHandlerGeneric * ParHandler
Pointer to covariance from which we get information about spline params.
void CalcSplineWeights() final
CPU based code which eval weight for each spline.
std::vector< std::vector< std::string > > SplineFileParPrefixNames
[Sample][Syst]
void LoadSettingsDir(std::unique_ptr< TFile > &SplineFile)
KS: Load preprocessed Settings.
void PrintBinning(TAxis *Axis) const
Print spline binning.
void MoveToGPU()
CW: The shared initialiser from constructors of TResponseFunction_red.
void PrepareSplineFile(std::string FileName) final
KS: Prepare spline file that can be used for fast loading.
void CleanUpMemory()
Remove setup variables not needed for spline evaluations.
std::vector< SplineIndex > GetEventSplines(const std::string &SampleTitle, int iOscChan, int EventMode, const std::vector< double > &VarVals)
Return the splines which affect a given event.
void PrepForReweight()
Initialise flat structure.
void InvestigateMissingSplines() const
This function will find missing splines in file.
std::vector< int > nSplineParams
std::vector< std::vector< std::vector< int > > > SplineModeVecs
unsigned int MonolithIndex
std::vector< int > nOscChans
M3::float_t * xcoeff_arr
x coefficients for each spline
std::vector< std::string > SampleTitles
void PrintSampleDetails(const std::string &SampleTitle) const
Print info like Sample ID of spline params etc.
std::vector< std::string > UniqueSystNames
name of each spline parameter
std::vector< M3::float_t > cpu_spline_weights
Stores weight from spline evaluation for each single spline.
std::vector< std::vector< SplineInterpolation > > SplineInterpolationTypes
spline interpolation types for each sample. These vectors are from a call to GetSplineInterpolationFr...
std::vector< SplineIndex > IndexVect
Variables related to determined which modes have splines and which piggy-back of other modes.
void GetSplineCoeff_SepMany(int splineindex, M3::float_t *&xArray, M3::float_t *&manyArray)
Rather work with spline coefficients in the splines, let's copy ND and use coefficient arrays.
void Evaluate() final
CW: This Eval should be used when using two separate x,{y,a,b,c,d} arrays to store the weights; proba...
std::vector< int > Dimensions
void PrepareIndexDir(std::unique_ptr< TFile > &SplineFile) const
KS: Prepare Index Info within SplineFile.
void BuildSampleIndexingArray(const std::string &SampleTitle)
Only need 1 indexing array everything else interfaces with this to get binning properties.
int CountNumberOfLoadedSplines(bool NonFlat=false, int Verbosity=0) const
Count how many splines we have.
std::vector< int > monolith_index
keep track which splines are flat (-1) otherwise map with flattened splines
std::vector< unsigned int > nKnots_arr
KS: CPU Number of knots per spline.
void AddSample(const std::string &SampleName, const std::string &SampleTitle, const std::vector< std::string > &OscChanFileNames, const std::vector< std::string > &SplineVarNames)
add oscillation channel to spline monolith
std::vector< TAxis * > FindSplineBinning(const std::string &FileName, const std::string &SampleTitle)
Grab histograms with spline binning.
std::vector< std::vector< std::string > > DimensionLabels
std::vector< std::vector< int > > StripDuplicatedModes(const std::vector< std::vector< int > > &InputVector) const
Creates an array to be filled with monolith indexes for each sample (allows for indexing between 7D b...
void LoadSplineFile(std::string FileName) final
KS: Load preprocessed spline file.
void PrepareMonolithDir(std::unique_ptr< TFile > &SplineFile) const
KS: Prepare Monolith Info within SplineFile.
void LoadMonolithDir(std::unique_ptr< TFile > &SplineFile)
KS: Load preprocessed Monolith.
std::vector< std::vector< std::vector< TAxis * > > > SplineBinning
Holds TAxis for [sample][channel][dimension].
std::vector< TSpline3_red * > splinevec_Monolith
holds each spline object before stripping into coefficient monolith
void PrepareOtherInfoDir(std::unique_ptr< TFile > &SplineFile) const
KS: Prepare Other Info within SplineFile.
void PrepareSettingsDir(std::unique_ptr< TFile > &SplineFile) const
KS: Prepare Settings Info within SplineFile.
const M3::float_t * RetPointer(const SplineIndex &Variables) const
get pointer to spline weight based on bin variables
MaCh3Modes * Modes
pointer to MaCh3 Mode from which we get spline suffix
void PrintArrayDetails(const std::string &SampleTitle) const
Print info like Sample ID of spline params etc.
std::map< std::tuple< int, int, int, int, std::vector< int > >, int > IndexVectMap
Map between spline origin/properties (iSample, iOscChan, iSyst, iMode, iVar1, iVar2,...
std::vector< std::vector< int > > GlobalSystIndex
This holds the global spline index and is used to grab the current parameter value to evaluate spline...
BinnedSplineHandler(ParameterHandlerGeneric *ParamHandler, MaCh3Modes *Modes_, const bool Use_GPU=true)
Constructor.
virtual ~BinnedSplineHandler()
Destructor.
virtual std::vector< std::string > GetTokensFromSplineName(const std::string &FullSplineName)=0
Extract metadata tokens encoded in a spline name. allows experiment to have different formats of spli...
std::vector< std::string > SampleNames
void TransferToMonolith()
flatten multidimensional spline array into proper monolith
std::vector< int > UniqueSystIndices
Global index of each spline param, it allows us to match spline ordering with global.
int GetSampleIndex(const std::string &SampleTitle) const
Get index of sample based on name.
M3::float_t * manycoeff_arr
ybcd coefficients for each spline
Creates fancy formatted text tables for terminal output.
Custom exception class used throughout MaCh3.
KS: Class describing MaCh3 modes used in the analysis, it is being initialised from config.
int GetNModes() const
KS: Get number of modes, keep in mind actual number is +1 greater due to unknown category.
std::string GetSplineSuffixFromMaCh3Mode(const int Index)
DB: Get binned spline mode suffix from MaCh3 Mode.
const M3::float_t * RetPointer(const int iParam) const
DB Pointer return to param position.
YAML::Node GetConfig() const
Getter to return a copy of the YAML node.
Class responsible for handling of systematic error parameters with different types defined in the con...
int GetNumParamsFromSampleName(const std::string &SampleName, const SystType Type) const
DB Grab the number of parameters for the relevant SampleName.
const std::vector< std::string > GetParsNamesFromSampleName(const std::string &SampleName, const SystType Type) const
DB Grab the parameter names for the relevant SampleName.
const std::vector< std::string > GetSplineParsNamesFromSampleName(const std::string &SampleName) const
DB Get spline parameters depending on given SampleName.
const std::vector< int > GetGlobalSystIndexFromSampleName(const std::string &SampleName, const SystType Type) const
DB Get spline parameters depending on given SampleName.
const std::vector< SplineInterpolation > GetSplineInterpolationFromSampleName(const std::string &SampleName) const
Get the interpolation types for splines affecting a particular SampleName.
const std::vector< std::vector< int > > GetSplineModeVecFromSampleName(const std::string &SampleName) const
DB Grab the Spline Modes for the relevant SampleName.
Base class for calculating weight from spline.
SplineMonolithGPU * gpu_monolith
KS: Store info about Spline monolith, this allow to obtain better step time. As all necessary informa...
unsigned int NSplines_valid
Number of valid splines.
short int nParams
Number of parameters that have splines.
short int _max_knots
Max knots for production.
void FindSplineSegment()
CW:Code used in step by step reweighting, Find Spline Segment for each param.
short int * SplineSegments
std::vector< FastSplineInfo > SplineInfoArray
float * ParamValues
Store parameter values they are not in FastSplineInfo as in case of GPU we need to copy paste it to G...
bool useGPU
Whether to use GPU or not.
void LoadFastSplineInfoDir(std::unique_ptr< TFile > &SplineFile)
KS: Load preprocessed FastSplineInfo.
void PrepareFastSplineInfoDir(std::unique_ptr< TFile > &SplineFile) const
KS: Prepare Fast Spline Info within SplineFile.
void SetupSegments()
Since we find segment before actual reweight and sometimes we want to copy it to GPU we have differen...
Class responsible for calculating spline weight on GPU.
__host__ void InitGPU_SplineMonolith(unsigned int total_nknots, unsigned int n_splines, unsigned int n_tf1, int Eve_size)
Allocate memory on gpu for spline monolith.
__host__ void CleanupPinnedMemory(M3::float_t *cpu_total_weights, short int *segment, float *vals)
Clean up pinned variables at CPU.
__host__ void RunGPU_SplineMonolith_Binned(M3::float_t *cpu_spline_weights, float *vals, short int *segment)
__host__ void CopyToGPU_SplineMonolith_Binned(M3::float_t *manycoeff_arr, M3::float_t *xcoeff_arr, const std::vector< short int > &uniquesplinevec_Monolith, const std::vector< unsigned int > &coeffindexvec, const int n_params, const unsigned int n_splines, const short int spline_size, const unsigned int total_nknots)
Copies data from CPU to GPU for the spline monolith.
CW: Reduced TSpline3 class.
MaCh3 event-by-event cross-section spline code.
std::string join(const Container &values, std::string_view separator=" ")
Join all values in a container into a single string.
@ Right
Align text to the right.
@ Left
Align text to the left.
constexpr static const double _BAD_DOUBLE_
Default value used for double initialisation.
constexpr static const char * float_t_str_repr
constexpr static const float_t Unity
constexpr static const int _BAD_INT_
Default value used for int initialisation.
constexpr T fmaf_t(T x, T y, T z)
Function template for fused multiply-add.
void AddPath(std::string &FilePath)
Prepends the MACH3 environment path to FilePath if it is not already present.
Flat representation of a spline index entry.
std::vector< int > iVar
Kinematic bins index, assumed to be size of 3 for now.
int iMode
Mode index within a systematic.
int value
Index into the flattened spline weight vector.
int iOscChan
Oscillation channel index.
int iSyst
Systematic parameter index.