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;
540 bool FoundNonFlatSpline =
false;
548 int splineindex = entry.value;
550 if(SampleCounter != entry.iSample || SystCounter != entry.iSyst) {
551 SampleCounter = entry.iSample;
552 SystCounter = entry.iSyst;
553 FoundNonFlatSpline =
false;
556 bool FoundSyst =
false;
557 for (
unsigned int iFoundSyst = 0; iFoundSyst <
UniqueSystNames.size(); iFoundSyst++) {
562 if (FoundSyst)
continue;
569 FoundNonFlatSpline =
true;
571 if (FoundNonFlatSpline) {
574 MACH3LOG_DEBUG(
"{} syst has no response in sample {}", SystName, entry.iSample);
575 MACH3LOG_DEBUG(
"Whilst this isn't necessarily a problem, it seems odd");
578 nParams =
static_cast<short int>(UniqueSystSplines.size());
582 for (
int iSpline = 0; iSpline <
nParams; iSpline++)
591 UniqueSystSplines[iSpline]->GetKnot(iKnot, xPoint, yPoint);
600 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++) {
604 for (
const auto& line : table.Render()) {
608 int nCombinations_FlatSplines = 0;
609 int nCombinations_All = 0;
611 for (
unsigned int index = 0; index <
IndexVect.size(); index++)
613 int splineindex =
IndexVect[index].value;;
616 nCombinations_FlatSplines++;
621 MACH3LOG_INFO(
"Number of combinations of Sample, OscChan, Syst and Mode which have entirely flat response: {} / {}", nCombinations_FlatSplines, nCombinations_All);
631 for (
int i = 0; i < nPoints; i++) {
633 for (
int j = 0; j <
_nCoeff_; j++) {
638 for(
int i=0; i<nPoints; i++) {
664 for (
size_t iSample = 0; iSample <
SampleTitles.size(); ++iSample) {
666 return static_cast<int>(iSample);
689 std::map<int, std::set<int>> OscToSysts;
692 if (entry.iSample != iSample)
continue;
693 OscToSysts[entry.iOscChan].insert(entry.iSyst);
695 MACH3LOG_INFO(
"Sample {} has {} oscillation channels", SampleTitle, OscToSysts.size());
697 for (
const auto& OscPair : OscToSysts) {
698 int osc = OscPair.first;
699 const std::set<int>& SystSet = OscPair.second;
700 MACH3LOG_INFO(
"Oscillation channel {} has {} systematics", osc, SystSet.size());
706 int iSyst,
int iMode,
const std::vector<int>& iVar)
const {
718 for (
size_t i = 0; i < iVar.size(); ++i) {
731 const int NBins = Axis->GetNbins();
732 std::string text =
"";
733 for (
int iBin = 0; iBin <= NBins; iBin++) {
734 text += fmt::format(
"{} ", Axis->GetXbins()->GetAt(iBin));
741 int iOscChan,
int EventMode,
const std::vector<double>& VarVals) {
743 std::vector<SplineIndex> ReturnVec;
758 std::vector<int> var_bins;
759 for (
size_t i = 0; i < VarVals.size(); ++i) {
760 int bin =
SplineBinning[SampleIndex][iOscChan][i]->FindBin(VarVals[i]) - 1;
761 if (bin < 0 || bin >=
SplineBinning[SampleIndex][iOscChan][i]->GetNbins()) {
764 var_bins.push_back(bin);
767 for(
int iSyst=0; iSyst <
nSplineParams[SampleIndex]; iSyst++){
768 std::vector<int> spline_modes =
SplineModeVecs[SampleIndex][iSyst];
769 int nSampleModes =
static_cast<int>(spline_modes.size());
772 for(
int iMode = 0; iMode<nSampleModes; iMode++) {
774 if (Mode == spline_modes[iMode]) {
775 int index =
IndexVectMap.at(std::make_tuple(SampleIndex, iOscChan, iSyst, iMode,
786 ReturnVec.push_back(idx);
800 size_t InputVectorSize = InputVector.size();
801 std::vector< std::vector<int> > ReturnVec(InputVectorSize);
804 for (
size_t iSyst=0;iSyst<InputVectorSize;iSyst++) {
805 std::vector<int> TmpVec;
806 std::vector<std::string> TestVec;
809 for (
unsigned int iMode = 0 ; iMode < InputVector[iSyst].size() ; iMode++) {
810 int Mode = InputVector[iSyst][iMode];
813 bool IncludeMode =
true;
814 for (
auto TestString : TestVec) {
815 if (ModeName == TestString) {
822 TmpVec.push_back(Mode);
823 TestVec.push_back(ModeName);
827 ReturnVec[iSyst] = TmpVec;
872 for (
int iOscChan = 0; iOscChan < nOscChannels; iOscChan++) {
874 TSpline3* mySpline =
nullptr;
877 std::set<std::string> SplineFileNames;
878 auto File = std::unique_ptr<TFile>(
TFile::Open(OscChanFileNames[iOscChan].c_str()));
880 if (!File || File->IsZombie()) {
887 for (
auto k : *File->GetListOfKeys()) {
888 auto Key =
static_cast<TKey*
>(k);
889 TClass *Class = gROOT->GetClass(Key->GetClassName(),
false);
890 if(!Class->InheritsFrom(
"TSpline3")) {
894 std::string FullSplineName = std::string(Key->GetName());
896 if (SplineFileNames.count(FullSplineName) > 0) {
897 MACH3LOG_CRITICAL(
"Skipping spline - Found a spline whose name has already been encountered before: {}", FullSplineName);
900 SplineFileNames.insert(FullSplineName);
906 std::vector<int> VarBins;
908 for (std::size_t i =
kVarBinToken; i < Tokens.size(); ++i) {
909 VarBins.push_back(std::stoi(Tokens.at(i)));
922 MACH3LOG_DEBUG(
"Couldn't Match any systematic name in ParameterHandler with spline name: {}" , FullSplineName);
927 for (
unsigned int iMode = 0; iMode <
SplineModeVecs[iSample][SystNum].size(); iMode++) {
937 MACH3LOG_DEBUG(
"Couldn't find mode for {} in {}. Problem Spline is : {} ", Mode, Syst, FullSplineName);
941 mySpline = Key->ReadObject<TSpline3>();
944 MACH3LOG_TRACE(
"Pushed back monolith for spline {}", FullSplineName);
946 int nKnots = mySpline->GetNp();
948 for (
int iKnot = 0; iKnot < nKnots; iKnot++) {
950 mySpline->GetKnot(iKnot, x, y);
951 if (y < 0.99999 || y > 1.00001)
959 int index =
IndexVectMap.at(std::make_tuple(iSample, iOscChan, SystNum, ModeNum, VarBins));
968 if(mySpline)
delete mySpline;
995 size_t pos = FileName.find(
' ');
996 if (pos != std::string::npos) {
997 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
998 while ((pos = FileName.find(
' ')) != std::string::npos) {
1002 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"OPEN");
1004 TMacro *ConfigCov = SplineFile->Get<TMacro>(
"ParameterHandler");
1012 MACH3LOG_ERROR(
"Loading precomputed spline file, however encountered different YAML config, please regenerate input");
1021 for (
int iSpline = 0; iSpline <
nParams; iSpline++) {
1024 SplineFile->Close();
1036 TTree *Settings = SplineFile->Get<TTree>(
"Settings");
1037 int CoeffIndex_temp;
1038 unsigned int NSplines_valid_temp;
1039 short int nParams_temp, max_knots_temp;
1040 Settings->SetBranchAddress(
"CoeffIndex", &CoeffIndex_temp);
1041 Settings->SetBranchAddress(
"NSplines_valid", &NSplines_valid_temp);
1042 Settings->SetBranchAddress(
"nParams", &nParams_temp);
1043 Settings->SetBranchAddress(
"max_knots", &max_knots_temp);
1045 int SplineBinning_size1, SplineBinning_size2, SplineBinning_size3;
1046 Settings->SetBranchAddress(
"SplineBinning_size1", &SplineBinning_size1);
1047 Settings->SetBranchAddress(
"SplineBinning_size2", &SplineBinning_size2);
1048 Settings->SetBranchAddress(
"SplineBinning_size3", &SplineBinning_size3);
1049 int SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3;
1050 Settings->SetBranchAddress(
"SplineModeVecs_size1", &SplineModeVecs_size1);
1051 Settings->SetBranchAddress(
"SplineModeVecs_size2", &SplineModeVecs_size2);
1052 Settings->SetBranchAddress(
"SplineModeVecs_size3", &SplineModeVecs_size3);
1053 std::vector<std::string>* SampleNames_temp =
nullptr;
1054 Settings->SetBranchAddress(
"SampleNames", &SampleNames_temp);
1055 std::vector<std::string>* SampleTitles_temp =
nullptr;
1056 Settings->SetBranchAddress(
"SampleTitles", &SampleTitles_temp);
1057 std::vector<int>* nSplineParams_temp =
nullptr;
1058 Settings->SetBranchAddress(
"nSplineParams", &nSplineParams_temp);
1059 Settings->GetEntry(0);
1070 auto Resize3D = [](
auto& vec,
int d1,
int d2,
int d3) {
1072 for (
int i = 0; i < d1; ++i) {
1074 for (
int j = 0; j < d2; ++j) {
1075 vec[i][j].resize(d3);
1080 Resize3D(
SplineBinning, SplineBinning_size1, SplineBinning_size2, SplineBinning_size3);
1081 Resize3D(
SplineModeVecs, SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3);
1088 TTree *MonolithTree = SplineFile->Get<TTree>(
"MonolithTree");
1093 std::vector<int>* monolith_index_temp =
nullptr;
1094 MonolithTree->SetBranchAddress(
"monolith_index", &monolith_index_temp);
1097 std::vector<unsigned int>* nKnots_arr_temp =
nullptr;
1098 MonolithTree->SetBranchAddress(
"nKnots_arr", &nKnots_arr_temp);
1099 std::vector<short int>* paramNo_arr_temp =
nullptr;
1100 MonolithTree->SetBranchAddress(
"paramNo_arr", ¶mNo_arr_temp);
1101 std::vector<int>* UniqueSystIndices_temp =
nullptr;
1102 MonolithTree->SetBranchAddress(
"UniqueSystIndices", &UniqueSystIndices_temp);
1106 MonolithTree->SetBranchAddress(
"xcoeff",
xcoeff_arr);
1108 MonolithTree->GetEntry(0);
1120 TTree *IndexTree = SplineFile->Get<TTree>(
"IndexVec");
1123 IndexTree->SetBranchAddress(
"SplineIndex", &IndexTemp);
1124 IndexVect.resize(IndexTree->GetEntries());
1126 for (Long64_t iEntry = 0; iEntry < IndexTree->GetEntries(); ++iEntry) {
1127 IndexTree->GetEntry(iEntry);
1130 auto key = std::make_tuple(IndexTemp->iSample, IndexTemp->iOscChan, IndexTemp->iSyst,
1131 IndexTemp->iMode, IndexTemp->iVar);
1136 TTree *SplineBinningTree = SplineFile->Get<TTree>(
"SplineBinningTree");
1137 std::vector<int> indices(3);
1138 SplineBinningTree->SetBranchAddress(
"i", &indices[0]);
1139 SplineBinningTree->SetBranchAddress(
"j", &indices[1]);
1140 SplineBinningTree->SetBranchAddress(
"k", &indices[2]);
1141 TAxis* axis =
nullptr;
1142 SplineBinningTree->SetBranchAddress(
"axis", &axis);
1145 for (Long64_t entry = 0; entry < SplineBinningTree->GetEntries(); ++entry) {
1146 SplineBinningTree->GetEntry(entry);
1150 SplineBinning[i][j][k] =
static_cast<TAxis*
>(axis->Clone());
1153 std::vector<int> indices_mode(3);
1155 TTree *SplineModeTree = SplineFile->Get<TTree>(
"SplineModeTree");
1156 SplineModeTree->SetBranchAddress(
"i", &indices_mode[0]);
1157 SplineModeTree->SetBranchAddress(
"j", &indices_mode[1]);
1158 SplineModeTree->SetBranchAddress(
"k", &indices_mode[2]);
1159 SplineModeTree->SetBranchAddress(
"value", &mode_value);
1162 for (Long64_t entry = 0; entry < SplineModeTree->GetEntries(); ++entry) {
1163 SplineModeTree->GetEntry(entry);
1164 int i = indices_mode[0];
1165 int j = indices_mode[1];
1166 int k = indices_mode[2];
1177 size_t pos = FileName.find(
' ');
1178 if (pos != std::string::npos) {
1179 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
1180 while ((pos = FileName.find(
' ')) != std::string::npos) {
1181 FileName[pos] =
'_';
1185 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"recreate");
1187 TMacro ConfigSave =
YAMLtoTMacro(ConfigCurrent,
"ParameterHandler");
1196 SplineFile->Close();
1202 TTree *Settings =
new TTree(
"Settings",
"Settings");
1205 short int nParams_temp =
nParams;
1208 Settings->Branch(
"CoeffIndex", &CoeffIndex_temp,
"CoeffIndex/I");
1209 Settings->Branch(
"NSplines_valid", &NSplines_valid_temp,
"NSplines_valid/i");
1210 Settings->Branch(
"nParams", &nParams_temp,
"nParams/S");
1211 Settings->Branch(
"max_knots", &max_knots_temp,
"max_knots/S");
1213 int SplineBinning_size1 =
static_cast<int>(
SplineBinning.size());
1214 int SplineBinning_size2 = (SplineBinning_size1 > 0) ?
static_cast<int>(
SplineBinning[0].size()) : 0;
1215 int SplineBinning_size3 = (SplineBinning_size2 > 0) ?
static_cast<int>(
SplineBinning[0][0].size()) : 0;
1217 Settings->Branch(
"SplineBinning_size1", &SplineBinning_size1,
"SplineBinning_size1/I");
1218 Settings->Branch(
"SplineBinning_size2", &SplineBinning_size2,
"SplineBinning_size2/I");
1219 Settings->Branch(
"SplineBinning_size3", &SplineBinning_size3,
"SplineBinning_size3/I");
1221 int SplineModeVecs_size1 =
static_cast<int>(
SplineModeVecs.size());
1222 int SplineModeVecs_size2 = (SplineModeVecs_size1 > 0) ?
static_cast<int>(
SplineModeVecs[0].size()) : 0;
1223 int SplineModeVecs_size3 = (SplineModeVecs_size2 > 0) ?
static_cast<int>(
SplineModeVecs[0][0].size()) : 0;
1225 Settings->Branch(
"SplineModeVecs_size1", &SplineModeVecs_size1,
"SplineModeVecs_size1/I");
1226 Settings->Branch(
"SplineModeVecs_size2", &SplineModeVecs_size2,
"SplineModeVecs_size2/I");
1227 Settings->Branch(
"SplineModeVecs_size3", &SplineModeVecs_size3,
"SplineModeVecs_size3/I");
1229 std::vector<std::string> SampleNames_temp =
SampleNames;
1230 Settings->Branch(
"SampleNames", &SampleNames_temp);
1231 std::vector<std::string> SampleTitles_temp =
SampleTitles;
1232 Settings->Branch(
"SampleTitles", &SampleTitles_temp);
1234 Settings->Branch(
"nSplineParams", &nSplineParams_temp);
1246 MACH3LOG_ERROR(
"{} Will not work as manycoeff_arr is nullptr :(", __func__);
1250 TTree *MonolithTree =
new TTree(
"MonolithTree",
"MonolithTree");
1254 MonolithTree->Branch(
"monolith_index", &monolith_index_temp);
1255 std::vector<unsigned int> nKnots_arr_temp =
nKnots_arr;
1256 MonolithTree->Branch(
"nKnots_arr", &nKnots_arr_temp);
1257 std::vector<short int> paramNo_arr_temp =
paramNo_arr;
1258 MonolithTree->Branch(
"paramNo_arr", ¶mNo_arr_temp);
1260 MonolithTree->Branch(
"UniqueSystIndices", &UniqueSystIndices_temp);
1263 MonolithTree->Fill();
1265 MonolithTree->Write();
1266 delete MonolithTree;
1273 TTree *IndexTree =
new TTree(
"IndexVec",
"IndexVec");
1275 IndexTree->Branch(
"SplineIndex", &entry);
1290 TTree *SplineBinningTree =
new TTree(
"SplineBinningTree",
"SplineBinningTree");
1291 std::vector<int> indices(3);
1292 TAxis* axis =
nullptr;
1293 SplineBinningTree->Branch(
"i", &indices[0],
"i/I");
1294 SplineBinningTree->Branch(
"j", &indices[1],
"j/I");
1295 SplineBinningTree->Branch(
"k", &indices[2],
"k/I");
1296 SplineBinningTree->Branch(
"axis",
"TAxis", &axis);
1303 indices[0] =
static_cast<int>(i);
1304 indices[1] =
static_cast<int>(j);
1305 indices[2] =
static_cast<int>(k);
1306 SplineBinningTree->Fill();
1311 SplineBinningTree->Write();
1312 delete SplineBinningTree;
1314 std::vector<int> indices_mode(3);
1317 TTree *SplineModeTree =
new TTree(
"SplineModeTree",
"SplineModeTree");
1319 SplineModeTree->Branch(
"i", &indices_mode[0],
"i/I");
1320 SplineModeTree->Branch(
"j", &indices_mode[1],
"j/I");
1321 SplineModeTree->Branch(
"k", &indices_mode[2],
"k/I");
1322 SplineModeTree->Branch(
"value", &mode_value,
"value/I");
1328 indices_mode[0] =
static_cast<int>(i);
1329 indices_mode[1] =
static_cast<int>(j);
1330 indices_mode[2] =
static_cast<int>(k);
1332 SplineModeTree->Fill();
1338 SplineModeTree->Write();
1339 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.
TFile * Open(const std::string &Name, const std::string &Type, const std::string &File, const int Line)
Opens a ROOT file with the given name and mode.
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.