4 #pragma GCC diagnostic ignored "-Wuseless-cast"
16 MACH3LOG_ERROR(
"Trying to create BinnedSplineHandler with uninitialized covariance object");
22 MACH3LOG_ERROR(
"Trying to create BinnedSplineHandler with uninitialized MaCh3Modes object");
70 const std::string& SampleTitle,
71 const std::vector<std::string>& OscChanFileNames,
72 const std::vector<std::string>& SplineVarNames) {
76 Dimensions.push_back(
static_cast<int>(SplineVarNames.size()));
96 MACH3LOG_INFO(
"SplineModeVecs_Sample is of size {}", SplineModeVecs_Sample.size());
101 int nOscChan = int(OscChanFileNames.size());
106 std::vector<std::vector<TAxis *>> SampleBinning(nOscChan);
107 for (
int iOscChan = 0; iOscChan < nOscChan; iOscChan++)
109 SampleBinning[iOscChan] =
FindSplineBinning(OscChanFileNames[iOscChan], SampleTitle);
111 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
116 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
119 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
126 std::map<unsigned int, std::map<unsigned int, std::map<std::string, std::pair<unsigned int, unsigned int>>>> systZeroCounts;
128 unsigned int iSample = entry.iSample;
129 unsigned int iSyst = entry.iSyst;
134 auto& counts = systZeroCounts[iSample][iSyst][modeSuffix];
137 if (entry.value == -1)
140 if (counts.second > 1)
143 "Sample '{}' | OscChan {} | Syst '{}' | Mode '{}' | Var {} => Value: {}",
148 fmt::join(entry.iVar,
" "),
156 for (
const auto& samplePair : systZeroCounts) {
157 unsigned int iSample = samplePair.first;
159 for (
const auto& systPair : samplePair.second) {
160 unsigned int iSyst = systPair.first;
161 const auto& systName = SplineFileParPrefixNames_Sample[iSyst];
162 for (
const auto& modePair : systPair.second) {
163 const auto& modeSuffix = modePair.first;
164 const auto& counts = modePair.second;
166 "Sample '{}': Systematic '{}' has missing splines in mode '{}'. Expected Splines: {}, Missing Splines: {}",
186 MACH3LOG_ERROR(
"Something's gone wrong when we tried to get the size of your monolith");
202 int splineindex = entry.value;
205 bool foundUniqueSpline =
false;
207 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
212 foundUniqueSpline =
true;
218 if (!foundUniqueSpline)
223 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
242 for(
int i = 0; i < splineKnots; i++){
249 delete[] tmpXCoeffArr;
250 delete[] tmpManyCoeffArr;
272 #pragma omp parallel for simd
278 const short int currentsegment = short(
SplineSegments[uniqueIndex]);
281 const int coeffOffset = segCoeff *
_nCoeff_;
300 if(weight < 0){weight = 0.;}
312 for (
int iOscChan = 0; iOscChan <
nOscChans[iSample]; ++iOscChan)
316 int nModesInSyst =
static_cast<int>(
SplineModeVecs[iSample][iSyst].size());
317 for (
int iMode = 0; iMode < nModesInSyst; ++iMode)
319 const int nBins1 =
SplineBinning[iSample][iOscChan][0]->GetNbins();
320 const int nBins2 =
SplineBinning[iSample][iOscChan][1]->GetNbins();
321 const int nBins3 =
SplineBinning[iSample][iOscChan][2]->GetNbins();
322 for (
int iVar1 = 0; iVar1 < nBins1; ++iVar1) {
323 for (
int iVar2 = 0; iVar2 < nBins2; ++iVar2) {
324 for (
int iVar3 = 0; iVar3 < nBins3; ++iVar3) {
331 entry.
iVar = {iVar1, iVar2, iVar3};
333 IndexVectMap[std::make_tuple(iSample, iOscChan, iSyst, iMode, std::vector<int>{iVar1, iVar2, iVar3})] =
static_cast<int>(
IndexVect.size() - 1);
348 constexpr
int nDummyBins = 1;
349 constexpr
double DummyEdges[2] = {-1e15, 1e15};
350 TAxis* DummyAxis =
new TAxis(nDummyBins, DummyEdges);
351 TH2F* Hist2D =
nullptr;
352 TH3F* Hist3D =
nullptr;
354 auto File = std::unique_ptr<TFile>(
TFile::Open(FileName.c_str(),
"READ"));
355 if (!File || File->IsZombie())
358 MACH3LOG_ERROR(
"This is caused by something here! {} : {}", __FILE__, __LINE__);
365 std::string TemplateName =
"dev_tmp_0_0";
366 TObject *Obj = File->Get(TemplateName.c_str());
370 TemplateName =
"dev_tmp.0.0";
371 Obj = File->Get(TemplateName.c_str());
374 MACH3LOG_ERROR(
"Could not find dev_tmp_0_0 in spline file. Spline binning cannot be set!");
381 bool isHist2D = Obj->IsA() == TH2F::Class();
383 bool isHist3D = Obj->IsA() == TH3F::Class();
384 if (!isHist2D && !isHist3D)
386 MACH3LOG_ERROR(
"Object doesn't inherit from either TH2D and TH3D - Odd A");
397 Hist2D = File->Get<TH2F>(TemplateName.c_str());
402 Hist3D = File->Get<TH3F>((TemplateName.c_str()));
403 if (
Dimensions[iSample] != 3 && Hist3D->GetZaxis()->GetNbins() != 1)
410 std::vector<TAxis*> ReturnVec;
415 ReturnVec[0] =
static_cast<TAxis*
>(Hist2D->GetXaxis()->Clone());
416 ReturnVec[1] =
static_cast<TAxis*
>(Hist2D->GetYaxis()->Clone());
417 ReturnVec[2] =
static_cast<TAxis*
>(DummyAxis->Clone());
418 }
else if (isHist3D) {
419 ReturnVec[0] =
static_cast<TAxis*
>(Hist3D->GetXaxis()->Clone());
420 ReturnVec[1] =
static_cast<TAxis*
>(Hist3D->GetYaxis()->Clone());
421 ReturnVec[2] =
static_cast<TAxis*
>(DummyAxis->Clone());
424 ReturnVec[0] =
static_cast<TAxis*
>(Hist3D->GetXaxis()->Clone());
425 ReturnVec[1] =
static_cast<TAxis*
>(Hist3D->GetYaxis()->Clone());
426 ReturnVec[2] =
static_cast<TAxis*
>(Hist3D->GetZaxis()->Clone());
432 for (
unsigned int iAxis = 0; iAxis < ReturnVec.size(); ++iAxis) {
456 int FullCounter_All = 0;
457 int FullCounter_NonFlat = 0;
459 for (
unsigned int index = 0; index <
IndexVect.size(); index++)
463 int iSample = entry.iSample;
468 entry.iMode, entry.iVar)) {
471 SampleAll[iSample]++;
474 SampleNonFlat[iSample]++;
479 for (
size_t iSample = 0; iSample <
SampleTitles.size(); iSample++)
481 MACH3LOG_DEBUG(
"{:<10} has {:<10} splines, of which {:<10} are not flat",
484 SampleNonFlat[iSample]);
486 FullCounter_All += SampleAll[iSample];
487 FullCounter_NonFlat += SampleNonFlat[iSample];
491 MACH3LOG_INFO(
"Total number of splines loaded: {}", FullCounter_All);
492 MACH3LOG_INFO(
"Total number of non-flat splines loaded: {}", FullCounter_NonFlat);
496 return FullCounter_NonFlat;
498 return FullCounter_All;
505 std::vector<TSpline3_red*> UniqueSystSplines;
506 bool FoundNonFlatSpline =
false;
514 int splineindex = entry.value;
516 if(SampleCounter != entry.iSample || SystCounter != entry.iSyst) {
517 SampleCounter = entry.iSample;
518 SystCounter = entry.iSyst;
519 FoundNonFlatSpline =
false;
522 bool FoundSyst =
false;
523 for (
unsigned int iFoundSyst = 0; iFoundSyst <
UniqueSystNames.size(); iFoundSyst++) {
528 if (FoundSyst)
continue;
535 FoundNonFlatSpline =
true;
537 if (FoundNonFlatSpline) {
540 MACH3LOG_INFO(
"{} syst has no response in sample {}", SystName, entry.iSample);
541 MACH3LOG_INFO(
"Whilst this isn't necessarily a problem, it seems odd");
544 nParams =
static_cast<short int>(UniqueSystSplines.size());
550 for (
int iSpline = 0; iSpline <
nParams; iSpline++)
559 UniqueSystSplines[iSpline]->GetKnot(iKnot, xPoint, yPoint);
568 MACH3LOG_INFO(
"{:<15} | {:<20} | {:<6}",
"Spline Index",
"Syst Name",
"nKnots");
569 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
574 int nCombinations_FlatSplines = 0;
575 int nCombinations_All = 0;
577 for (
unsigned int index = 0; index <
IndexVect.size(); index++)
579 int splineindex =
IndexVect[index].value;;
582 nCombinations_FlatSplines++;
587 MACH3LOG_INFO(
"Number of combinations of Sample, OscChan, Syst and Mode which have entirely flat response: {} / {}", nCombinations_FlatSplines, nCombinations_All);
597 for (
int i = 0; i < nPoints; i++) {
599 for (
int j = 0; j <
_nCoeff_; j++) {
604 for(
int i=0; i<nPoints; i++) {
631 for (
size_t iSample = 0; iSample <
SampleTitles.size(); ++iSample) {
633 return static_cast<int>(iSample);
656 std::map<int, std::set<int>> OscToSysts;
659 if (entry.iSample != iSample)
continue;
660 OscToSysts[entry.iOscChan].insert(entry.iSyst);
662 MACH3LOG_INFO(
"Sample {} has {} oscillation channels", SampleTitle, OscToSysts.size());
664 for (
const auto& OscPair : OscToSysts) {
665 int osc = OscPair.first;
666 const std::set<int>& SystSet = OscPair.second;
667 MACH3LOG_INFO(
"Oscillation channel {} has {} systematics", osc, SystSet.size());
673 int iSyst,
int iMode,
const std::vector<int>& iVar)
const {
685 for (
size_t i = 0; i < iVar.size(); ++i) {
698 const int NBins = Axis->GetNbins();
699 std::string text =
"";
700 for (
int iBin = 0; iBin <= NBins; iBin++) {
701 text += fmt::format(
"{} ", Axis->GetXbins()->GetAt(iBin));
708 int iOscChan,
int EventMode,
double Var1Val,
709 double Var2Val,
double Var3Val) {
711 std::vector<SplineIndex> ReturnVec;
726 std::vector<int> var_bins;
727 std::vector<double> vars = {Var1Val, Var2Val, Var3Val};
728 for (
size_t i = 0; i < vars.size(); ++i) {
729 int bin =
SplineBinning[SampleIndex][iOscChan][i]->FindBin(vars[i]) - 1;
730 if (bin < 0 || bin >=
SplineBinning[SampleIndex][iOscChan][i]->GetNbins()) {
733 var_bins.push_back(bin);
736 for(
int iSyst=0; iSyst <
nSplineParams[SampleIndex]; iSyst++){
737 std::vector<int> spline_modes =
SplineModeVecs[SampleIndex][iSyst];
738 int nSampleModes =
static_cast<int>(spline_modes.size());
741 for(
int iMode = 0; iMode<nSampleModes; iMode++) {
743 if (Mode == spline_modes[iMode]) {
744 int index =
IndexVectMap.at(std::make_tuple(SampleIndex, iOscChan, iSyst, iMode,
755 ReturnVec.push_back(idx);
769 size_t InputVectorSize = InputVector.size();
770 std::vector< std::vector<int> > ReturnVec(InputVectorSize);
773 for (
size_t iSyst=0;iSyst<InputVectorSize;iSyst++) {
774 std::vector<int> TmpVec;
775 std::vector<std::string> TestVec;
778 for (
unsigned int iMode = 0 ; iMode < InputVector[iSyst].size() ; iMode++) {
779 int Mode = InputVector[iSyst][iMode];
782 bool IncludeMode =
true;
783 for (
auto TestString : TestVec) {
784 if (ModeName == TestString) {
791 TmpVec.push_back(Mode);
792 TestVec.push_back(ModeName);
796 ReturnVec[iSyst] = TmpVec;
806 for (
int iOscChan = 0; iOscChan < nOscChannels; iOscChan++) {
808 TSpline3* mySpline =
nullptr;
811 std::set<std::string> SplineFileNames;
812 auto File = std::unique_ptr<TFile>(
TFile::Open(OscChanFileNames[iOscChan].c_str()));
814 if (!File || File->IsZombie()) {
821 for (
auto k : *File->GetListOfKeys()) {
822 auto Key =
static_cast<TKey*
>(k);
823 TClass *Class = gROOT->GetClass(Key->GetClassName(),
false);
824 if(!Class->InheritsFrom(
"TSpline3")) {
828 std::string FullSplineName = std::string(Key->GetName());
830 if (SplineFileNames.count(FullSplineName) > 0) {
831 MACH3LOG_CRITICAL(
"Skipping spline - Found a spline whose name has already been encountered before: {}", FullSplineName);
834 SplineFileNames.insert(FullSplineName);
839 MACH3LOG_ERROR(
"Invalid tokens from spline name - Expected {} tokens. Check implementation in GetTokensFromSplineName()",
static_cast<int>(
kNTokens));
848 std::vector<int> VarBins = {Var1Bin, Var2Bin, Var3Bin};
859 MACH3LOG_DEBUG(
"Couldn't Match any systematic name in ParameterHandler with spline name: {}" , FullSplineName);
864 for (
unsigned int iMode = 0; iMode <
SplineModeVecs[iSample][SystNum].size(); iMode++) {
874 MACH3LOG_DEBUG(
"Couldn't find mode for {} in {}. Problem Spline is : {} ", Mode, Syst, FullSplineName);
878 mySpline = Key->ReadObject<TSpline3>();
881 MACH3LOG_TRACE(
"Pushed back monolith for spline {}", FullSplineName);
883 int nKnots = mySpline->GetNp();
885 for (
int iKnot = 0; iKnot < nKnots; iKnot++) {
887 mySpline->GetKnot(iKnot, x, y);
888 if (y < 0.99999 || y > 1.00001)
896 int index =
IndexVectMap.at(std::make_tuple(iSample, iOscChan, SystNum, ModeNum, VarBins));
906 if(mySpline)
delete mySpline;
933 size_t pos = FileName.find(
' ');
934 if (pos != std::string::npos) {
935 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
936 while ((pos = FileName.find(
' ')) != std::string::npos) {
940 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"OPEN");
942 TMacro *ConfigCov = SplineFile->Get<TMacro>(
"ParameterHandler");
950 MACH3LOG_ERROR(
"Loading precomputed spline file, however encountered different YAML config, please regenerate input");
959 for (
int iSpline = 0; iSpline <
nParams; iSpline++) {
969 TTree *Settings = SplineFile->Get<TTree>(
"Settings");
970 int CoeffIndex_temp, MonolithSize_temp;
971 short int nParams_temp;
972 Settings->SetBranchAddress(
"CoeffIndex", &CoeffIndex_temp);
973 Settings->SetBranchAddress(
"MonolithSize", &MonolithSize_temp);
974 Settings->SetBranchAddress(
"nParams", &nParams_temp);
976 int SplineBinning_size1, SplineBinning_size2, SplineBinning_size3;
977 Settings->SetBranchAddress(
"SplineBinning_size1", &SplineBinning_size1);
978 Settings->SetBranchAddress(
"SplineBinning_size2", &SplineBinning_size2);
979 Settings->SetBranchAddress(
"SplineBinning_size3", &SplineBinning_size3);
980 int SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3;
981 Settings->SetBranchAddress(
"SplineModeVecs_size1", &SplineModeVecs_size1);
982 Settings->SetBranchAddress(
"SplineModeVecs_size2", &SplineModeVecs_size2);
983 Settings->SetBranchAddress(
"SplineModeVecs_size3", &SplineModeVecs_size3);
984 std::vector<std::string>* SampleNames_temp =
nullptr;
985 Settings->SetBranchAddress(
"SampleNames", &SampleNames_temp);
986 std::vector<std::string>* SampleTitles_temp =
nullptr;
987 Settings->SetBranchAddress(
"SampleTitles", &SampleTitles_temp);
988 std::vector<int>* nSplineParams_temp =
nullptr;
989 Settings->SetBranchAddress(
"nSplineParams", &nSplineParams_temp);
990 Settings->GetEntry(0);
1003 auto Resize3D = [](
auto& vec,
int d1,
int d2,
int d3) {
1005 for (
int i = 0; i < d1; ++i) {
1007 for (
int j = 0; j < d2; ++j) {
1008 vec[i][j].resize(d3);
1013 Resize3D(
SplineBinning, SplineBinning_size1, SplineBinning_size2, SplineBinning_size3);
1014 Resize3D(
SplineModeVecs, SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3);
1021 TTree *MonolithTree = SplineFile->Get<TTree>(
"MonolithTree");
1027 MonolithTree->SetBranchAddress(
"isflatarray",
isflatarray);
1030 std::vector<int>* coeffindexvec_temp =
nullptr;
1031 MonolithTree->SetBranchAddress(
"coeffindexvec", &coeffindexvec_temp);
1032 std::vector<int>* uniquecoeffindices_temp =
nullptr;
1033 MonolithTree->SetBranchAddress(
"uniquecoeffindices", &uniquecoeffindices_temp);
1034 std::vector<int>* uniquesplinevec_Monolith_temp =
nullptr;
1035 MonolithTree->SetBranchAddress(
"uniquesplinevec_Monolith", &uniquesplinevec_Monolith_temp);
1036 std::vector<int>* UniqueSystIndices_temp =
nullptr;
1037 MonolithTree->SetBranchAddress(
"UniqueSystIndices", &UniqueSystIndices_temp);
1041 MonolithTree->SetBranchAddress(
"xcoeff",
xcoeff_arr);
1043 MonolithTree->GetEntry(0);
1055 TTree *IndexTree = SplineFile->Get<TTree>(
"IndexVec");
1058 IndexTree->SetBranchAddress(
"SplineIndex", &IndexTemp);
1059 IndexVect.resize(IndexTree->GetEntries());
1061 for (Long64_t iEntry = 0; iEntry < IndexTree->GetEntries(); ++iEntry) {
1062 IndexTree->GetEntry(iEntry);
1065 auto key = std::make_tuple(IndexTemp->iSample, IndexTemp->iOscChan, IndexTemp->iSyst,
1066 IndexTemp->iMode, IndexTemp->iVar);
1071 TTree *SplineBinningTree = SplineFile->Get<TTree>(
"SplineBinningTree");
1072 std::vector<int> indices(3);
1073 SplineBinningTree->SetBranchAddress(
"i", &indices[0]);
1074 SplineBinningTree->SetBranchAddress(
"j", &indices[1]);
1075 SplineBinningTree->SetBranchAddress(
"k", &indices[2]);
1076 TAxis* axis =
nullptr;
1077 SplineBinningTree->SetBranchAddress(
"axis", &axis);
1080 for (Long64_t entry = 0; entry < SplineBinningTree->GetEntries(); ++entry) {
1081 SplineBinningTree->GetEntry(entry);
1085 SplineBinning[i][j][k] =
static_cast<TAxis*
>(axis->Clone());
1088 std::vector<int> indices_mode(3);
1090 TTree *SplineModeTree = SplineFile->Get<TTree>(
"SplineModeTree");
1091 SplineModeTree->SetBranchAddress(
"i", &indices_mode[0]);
1092 SplineModeTree->SetBranchAddress(
"j", &indices_mode[1]);
1093 SplineModeTree->SetBranchAddress(
"k", &indices_mode[2]);
1094 SplineModeTree->SetBranchAddress(
"value", &mode_value);
1097 for (Long64_t entry = 0; entry < SplineModeTree->GetEntries(); ++entry) {
1098 SplineModeTree->GetEntry(entry);
1099 int i = indices_mode[0];
1100 int j = indices_mode[1];
1101 int k = indices_mode[2];
1112 size_t pos = FileName.find(
' ');
1113 if (pos != std::string::npos) {
1114 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
1115 while ((pos = FileName.find(
' ')) != std::string::npos) {
1116 FileName[pos] =
'_';
1120 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"recreate");
1122 TMacro ConfigSave =
YAMLtoTMacro(ConfigCurrent,
"ParameterHandler");
1131 SplineFile->Close();
1137 TTree *Settings =
new TTree(
"Settings",
"Settings");
1140 short int nParams_temp =
nParams;
1142 Settings->Branch(
"CoeffIndex", &CoeffIndex_temp,
"CoeffIndex/I");
1143 Settings->Branch(
"MonolithSize", &MonolithSize_temp,
"MonolithSize/I");
1144 Settings->Branch(
"nParams", &nParams_temp,
"nParams/S");
1146 int SplineBinning_size1 =
static_cast<int>(
SplineBinning.size());
1147 int SplineBinning_size2 = (SplineBinning_size1 > 0) ?
static_cast<int>(
SplineBinning[0].size()) : 0;
1148 int SplineBinning_size3 = (SplineBinning_size2 > 0) ?
static_cast<int>(
SplineBinning[0][0].size()) : 0;
1150 Settings->Branch(
"SplineBinning_size1", &SplineBinning_size1,
"SplineBinning_size1/I");
1151 Settings->Branch(
"SplineBinning_size2", &SplineBinning_size2,
"SplineBinning_size2/I");
1152 Settings->Branch(
"SplineBinning_size3", &SplineBinning_size3,
"SplineBinning_size3/I");
1154 int SplineModeVecs_size1 =
static_cast<int>(
SplineModeVecs.size());
1155 int SplineModeVecs_size2 = (SplineModeVecs_size1 > 0) ?
static_cast<int>(
SplineModeVecs[0].size()) : 0;
1156 int SplineModeVecs_size3 = (SplineModeVecs_size2 > 0) ?
static_cast<int>(
SplineModeVecs[0][0].size()) : 0;
1158 Settings->Branch(
"SplineModeVecs_size1", &SplineModeVecs_size1,
"SplineModeVecs_size1/I");
1159 Settings->Branch(
"SplineModeVecs_size2", &SplineModeVecs_size2,
"SplineModeVecs_size2/I");
1160 Settings->Branch(
"SplineModeVecs_size3", &SplineModeVecs_size3,
"SplineModeVecs_size3/I");
1162 std::vector<std::string> SampleNames_temp =
SampleNames;
1163 Settings->Branch(
"SampleNames", &SampleNames_temp);
1164 std::vector<std::string> SampleTitles_temp =
SampleTitles;
1165 Settings->Branch(
"SampleTitles", &SampleTitles_temp);
1167 Settings->Branch(
"nSplineParams", &nSplineParams_temp);
1178 TTree *MonolithTree =
new TTree(
"MonolithTree",
"MonolithTree");
1183 MonolithTree->Branch(
"coeffindexvec", &coeffindexvec_temp);
1185 MonolithTree->Branch(
"uniquecoeffindices", &uniquecoeffindices_temp);
1187 MonolithTree->Branch(
"uniquesplinevec_Monolith", &uniquesplinevec_Monolith_temp);
1189 MonolithTree->Branch(
"UniqueSystIndices", &UniqueSystIndices_temp);
1192 MonolithTree->Fill();
1194 MonolithTree->Write();
1195 delete MonolithTree;
1202 TTree *IndexTree =
new TTree(
"IndexVec",
"IndexVec");
1204 IndexTree->Branch(
"SplineIndex", &entry);
1219 TTree *SplineBinningTree =
new TTree(
"SplineBinningTree",
"SplineBinningTree");
1220 std::vector<int> indices(3);
1221 TAxis* axis =
nullptr;
1222 SplineBinningTree->Branch(
"i", &indices[0],
"i/I");
1223 SplineBinningTree->Branch(
"j", &indices[1],
"j/I");
1224 SplineBinningTree->Branch(
"k", &indices[2],
"k/I");
1225 SplineBinningTree->Branch(
"axis",
"TAxis", &axis);
1232 indices[0] =
static_cast<int>(i);
1233 indices[1] =
static_cast<int>(j);
1234 indices[2] =
static_cast<int>(k);
1235 SplineBinningTree->Fill();
1240 SplineBinningTree->Write();
1241 delete SplineBinningTree;
1243 std::vector<int> indices_mode(3);
1246 TTree *SplineModeTree =
new TTree(
"SplineModeTree",
"SplineModeTree");
1248 SplineModeTree->Branch(
"i", &indices_mode[0],
"i/I");
1249 SplineModeTree->Branch(
"j", &indices_mode[1],
"j/I");
1250 SplineModeTree->Branch(
"k", &indices_mode[2],
"k/I");
1251 SplineModeTree->Branch(
"value", &mode_value,
"value/I");
1257 indices_mode[0] =
static_cast<int>(i);
1258 indices_mode[1] =
static_cast<int>(j);
1259 indices_mode[2] =
static_cast<int>(k);
1261 SplineModeTree->Fill();
1267 SplineModeTree->Write();
1268 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.
bool * isflatarray
Need to keep track of which splines are flat and which aren't.
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.
std::vector< int > coeffindexvec
Number of coefficients for a single flat (after flattening)
void PrintBinning(TAxis *Axis) const
Print spline binning.
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.
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
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< 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
std::vector< SplineIndex > GetEventSplines(const std::string &SampleTitle, int iOscChan, int EventMode, double Var1Val, double Var2Val, double Var3Val)
Return the splines which affect a given event.
std::vector< int > uniquesplinevec_Monolith
Maps single spline object with single parameter.
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.
BinnedSplineHandler(ParameterHandlerGeneric *ParamHandler, MaCh3Modes *Modes_)
Constructor.
std::vector< M3::float_t > weightvec_Monolith
Stores weight from spline evaluation for each single 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
std::vector< int > uniquecoeffindices
Unique coefficient indices.
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...
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
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.
short int nParams
Number of parameters that have splines.
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...
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.
CW: Reduced TSpline3 class.
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 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.