4 #pragma GCC diagnostic ignored "-Wuseless-cast"
5 #pragma GCC diagnostic ignored "-Wfloat-conversion"
17 MACH3LOG_ERROR(
"Trying to create BinnedSplineHandler with uninitialized covariance object");
23 MACH3LOG_ERROR(
"Trying to create BinnedSplineHandler with uninitialized MaCh3Modes object");
71 const std::string& SampleTitle,
72 const std::vector<std::string>& OscChanFileNames,
73 const std::vector<std::string>& SplineVarNames) {
77 Dimensions.push_back(
static_cast<int>(SplineVarNames.size()));
97 MACH3LOG_INFO(
"SplineModeVecs_Sample is of size {}", SplineModeVecs_Sample.size());
102 int nOscChan = int(OscChanFileNames.size());
107 std::vector<std::vector<TAxis *>> SampleBinning(nOscChan);
108 for (
int iOscChan = 0; iOscChan < nOscChan; iOscChan++)
110 SampleBinning[iOscChan] =
FindSplineBinning(OscChanFileNames[iOscChan], SampleTitle);
112 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
117 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
120 MACH3LOG_INFO(
"#----------------------------------------------------------------------------------------------------------------------------------#");
127 std::map<unsigned int, std::map<unsigned int, std::map<std::string, std::pair<unsigned int, unsigned int>>>> systZeroCounts;
129 unsigned int iSample = entry.iSample;
130 unsigned int iSyst = entry.iSyst;
135 auto& counts = systZeroCounts[iSample][iSyst][modeSuffix];
138 if (entry.value == -1)
141 if (counts.second > 1)
144 "Sample '{}' | OscChan {} | Syst '{}' | Mode '{}' | Var {} => Value: {}",
149 fmt::join(entry.iVar,
" "),
157 for (
const auto& samplePair : systZeroCounts) {
158 unsigned int iSample = samplePair.first;
160 for (
const auto& systPair : samplePair.second) {
161 unsigned int iSyst = systPair.first;
162 const auto& systName = SplineFileParPrefixNames_Sample[iSyst];
163 for (
const auto& modePair : systPair.second) {
164 const auto& modeSuffix = modePair.first;
165 const auto& counts = modePair.second;
167 "Sample '{}': Systematic '{}' has missing splines in mode '{}'. Expected Splines: {}, Missing Splines: {}",
187 MACH3LOG_ERROR(
"Something's gone wrong when we tried to get the size of your monolith");
203 int splineindex = entry.value;
206 bool foundUniqueSpline =
false;
208 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
213 foundUniqueSpline =
true;
219 if (!foundUniqueSpline)
224 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
243 for(
int i = 0; i < splineKnots; i++){
250 delete[] tmpXCoeffArr;
251 delete[] tmpManyCoeffArr;
273 #pragma omp parallel for simd
279 const short int currentsegment = short(
SplineSegments[uniqueIndex]);
282 const int coeffOffset = segCoeff *
_nCoeff_;
301 if(weight < 0){weight = 0.;}
313 for (
int iOscChan = 0; iOscChan <
nOscChans[iSample]; ++iOscChan)
317 int nModesInSyst =
static_cast<int>(
SplineModeVecs[iSample][iSyst].size());
318 for (
int iMode = 0; iMode < nModesInSyst; ++iMode)
320 const int nBins1 =
SplineBinning[iSample][iOscChan][0]->GetNbins();
321 const int nBins2 =
SplineBinning[iSample][iOscChan][1]->GetNbins();
322 const int nBins3 =
SplineBinning[iSample][iOscChan][2]->GetNbins();
323 for (
int iVar1 = 0; iVar1 < nBins1; ++iVar1) {
324 for (
int iVar2 = 0; iVar2 < nBins2; ++iVar2) {
325 for (
int iVar3 = 0; iVar3 < nBins3; ++iVar3) {
332 entry.
iVar = {iVar1, iVar2, iVar3};
334 IndexVectMap[std::make_tuple(iSample, iOscChan, iSyst, iMode, iVar1, iVar2, iVar3)] =
static_cast<int>(
IndexVect.size() - 1);
349 constexpr
int nDummyBins = 1;
350 constexpr
double DummyEdges[2] = {-1e15, 1e15};
351 TAxis* DummyAxis =
new TAxis(nDummyBins, DummyEdges);
352 TH2F* Hist2D =
nullptr;
353 TH3F* Hist3D =
nullptr;
355 auto File = std::unique_ptr<TFile>(
TFile::Open(FileName.c_str(),
"READ"));
356 if (!File || File->IsZombie())
359 MACH3LOG_ERROR(
"This is caused by something here! {} : {}", __FILE__, __LINE__);
366 std::string TemplateName =
"dev_tmp_0_0";
367 TObject *Obj = File->Get(TemplateName.c_str());
371 TemplateName =
"dev_tmp.0.0";
372 Obj = File->Get(TemplateName.c_str());
375 MACH3LOG_ERROR(
"Could not find dev_tmp_0_0 in spline file. Spline binning cannot be set!");
382 bool isHist2D = Obj->IsA() == TH2F::Class();
384 bool isHist3D = Obj->IsA() == TH3F::Class();
385 if (!isHist2D && !isHist3D)
387 MACH3LOG_ERROR(
"Object doesn't inherit from either TH2D and TH3D - Odd A");
398 Hist2D = File->Get<TH2F>(TemplateName.c_str());
403 Hist3D = File->Get<TH3F>((TemplateName.c_str()));
404 if (
Dimensions[iSample] != 3 && Hist3D->GetZaxis()->GetNbins() != 1)
411 std::vector<TAxis*> ReturnVec;
416 ReturnVec[0] =
static_cast<TAxis*
>(Hist2D->GetXaxis()->Clone());
417 ReturnVec[1] =
static_cast<TAxis*
>(Hist2D->GetYaxis()->Clone());
418 ReturnVec[2] =
static_cast<TAxis*
>(DummyAxis->Clone());
419 }
else if (isHist3D) {
420 ReturnVec[0] =
static_cast<TAxis*
>(Hist3D->GetXaxis()->Clone());
421 ReturnVec[1] =
static_cast<TAxis*
>(Hist3D->GetYaxis()->Clone());
422 ReturnVec[2] =
static_cast<TAxis*
>(DummyAxis->Clone());
425 ReturnVec[0] =
static_cast<TAxis*
>(Hist3D->GetXaxis()->Clone());
426 ReturnVec[1] =
static_cast<TAxis*
>(Hist3D->GetYaxis()->Clone());
427 ReturnVec[2] =
static_cast<TAxis*
>(Hist3D->GetZaxis()->Clone());
433 for (
unsigned int iAxis = 0; iAxis < ReturnVec.size(); ++iAxis) {
457 int FullCounter_All = 0;
458 int FullCounter_NonFlat = 0;
460 for (
unsigned int index = 0; index <
IndexVect.size(); index++)
464 int iSample = entry.iSample;
469 entry.iMode, entry.iVar)) {
472 SampleAll[iSample]++;
475 SampleNonFlat[iSample]++;
480 for (
size_t iSample = 0; iSample <
SampleTitles.size(); iSample++)
482 MACH3LOG_DEBUG(
"{:<10} has {:<10} splines, of which {:<10} are not flat",
485 SampleNonFlat[iSample]);
487 FullCounter_All += SampleAll[iSample];
488 FullCounter_NonFlat += SampleNonFlat[iSample];
492 MACH3LOG_INFO(
"Total number of splines loaded: {}", FullCounter_All);
493 MACH3LOG_INFO(
"Total number of non-flat splines loaded: {}", FullCounter_NonFlat);
497 return FullCounter_NonFlat;
499 return FullCounter_All;
506 std::vector<TSpline3_red*> UniqueSystSplines;
507 bool FoundNonFlatSpline =
false;
515 int splineindex = entry.value;
517 if(SampleCounter != entry.iSample || SystCounter != entry.iSyst) {
518 SampleCounter = entry.iSample;
519 SystCounter = entry.iSyst;
520 FoundNonFlatSpline =
false;
523 bool FoundSyst =
false;
524 for (
unsigned int iFoundSyst = 0; iFoundSyst <
UniqueSystNames.size(); iFoundSyst++) {
529 if (FoundSyst)
continue;
536 FoundNonFlatSpline =
true;
538 if (FoundNonFlatSpline) {
541 MACH3LOG_INFO(
"{} syst has no response in sample {}", SystName, entry.iSample);
542 MACH3LOG_INFO(
"Whilst this isn't necessarily a problem, it seems odd");
545 nParams =
static_cast<short int>(UniqueSystSplines.size());
551 for (
int iSpline = 0; iSpline <
nParams; iSpline++)
560 UniqueSystSplines[iSpline]->GetKnot(iKnot, xPoint, yPoint);
569 MACH3LOG_INFO(
"{:<15} | {:<20} | {:<6}",
"Spline Index",
"Syst Name",
"nKnots");
570 for (
int iUniqueSyst = 0; iUniqueSyst <
nParams; iUniqueSyst++)
575 int nCombinations_FlatSplines = 0;
576 int nCombinations_All = 0;
578 for (
unsigned int index = 0; index <
IndexVect.size(); index++)
580 int splineindex =
IndexVect[index].value;;
583 nCombinations_FlatSplines++;
588 MACH3LOG_INFO(
"Number of combinations of Sample, OscChan, Syst and Mode which have entirely flat response: {} / {}", nCombinations_FlatSplines, nCombinations_All);
598 for (
int i = 0; i < nPoints; i++) {
600 for (
int j = 0; j <
_nCoeff_; j++) {
605 for(
int i=0; i<nPoints; i++) {
632 for (
size_t iSample = 0; iSample <
SampleTitles.size(); ++iSample) {
634 return static_cast<int>(iSample);
657 std::map<int, std::set<int>> OscToSysts;
660 if (entry.iSample != iSample)
continue;
661 OscToSysts[entry.iOscChan].insert(entry.iSyst);
663 MACH3LOG_INFO(
"Sample {} has {} oscillation channels", SampleTitle, OscToSysts.size());
665 for (
const auto& OscPair : OscToSysts) {
666 int osc = OscPair.first;
667 const std::set<int>& SystSet = OscPair.second;
668 MACH3LOG_INFO(
"Oscillation channel {} has {} systematics", osc, SystSet.size());
674 int iSyst,
int iMode,
const std::vector<int>& iVar)
const {
678 bool found =
IndexVectMap.find(std::make_tuple(iSample, iOscChan, iSyst, iMode, iVar[0], iVar[1], iVar[2])) !=
IndexVectMap.end();
686 for (
size_t i = 0; i < iVar.size(); ++i) {
699 const int NBins = Axis->GetNbins();
700 std::string text =
"";
701 for (
int iBin = 0; iBin <= NBins; iBin++) {
702 text += fmt::format(
"{} ", Axis->GetXbins()->GetAt(iBin));
709 int iOscChan,
int EventMode,
double Var1Val,
710 double Var2Val,
double Var3Val) {
712 std::vector<SplineIndex> ReturnVec;
727 std::vector<int> var_bins;
728 std::vector<double> vars = {Var1Val, Var2Val, Var3Val};
729 for (
size_t i = 0; i < vars.size(); ++i) {
730 int bin =
SplineBinning[SampleIndex][iOscChan][i]->FindBin(vars[i]) - 1;
731 if (bin < 0 || bin >=
SplineBinning[SampleIndex][iOscChan][i]->GetNbins()) {
734 var_bins.push_back(bin);
737 for(
int iSyst=0; iSyst <
nSplineParams[SampleIndex]; iSyst++){
738 std::vector<int> spline_modes =
SplineModeVecs[SampleIndex][iSyst];
739 int nSampleModes =
static_cast<int>(spline_modes.size());
742 for(
int iMode = 0; iMode<nSampleModes; iMode++) {
744 if (Mode == spline_modes[iMode]) {
745 int index =
IndexVectMap.at(std::make_tuple(SampleIndex, iOscChan, iSyst, iMode,
746 var_bins[0], var_bins[1], var_bins[2]));
756 ReturnVec.push_back(idx);
770 size_t InputVectorSize = InputVector.size();
771 std::vector< std::vector<int> > ReturnVec(InputVectorSize);
774 for (
size_t iSyst=0;iSyst<InputVectorSize;iSyst++) {
775 std::vector<int> TmpVec;
776 std::vector<std::string> TestVec;
779 for (
unsigned int iMode = 0 ; iMode < InputVector[iSyst].size() ; iMode++) {
780 int Mode = InputVector[iSyst][iMode];
783 bool IncludeMode =
true;
784 for (
auto TestString : TestVec) {
785 if (ModeName == TestString) {
792 TmpVec.push_back(Mode);
793 TestVec.push_back(ModeName);
797 ReturnVec[iSyst] = TmpVec;
807 for (
int iOscChan = 0; iOscChan < nOscChannels; iOscChan++) {
809 TSpline3* mySpline =
nullptr;
812 std::set<std::string> SplineFileNames;
813 auto File = std::unique_ptr<TFile>(
TFile::Open(OscChanFileNames[iOscChan].c_str()));
815 if (!File || File->IsZombie()) {
822 for (
auto k : *File->GetListOfKeys()) {
823 auto Key =
static_cast<TKey*
>(k);
824 TClass *Class = gROOT->GetClass(Key->GetClassName(),
false);
825 if(!Class->InheritsFrom(
"TSpline3")) {
829 std::string FullSplineName = std::string(Key->GetName());
831 if (SplineFileNames.count(FullSplineName) > 0) {
832 MACH3LOG_CRITICAL(
"Skipping spline - Found a spline whose name has already been encountered before: {}", FullSplineName);
835 SplineFileNames.insert(FullSplineName);
840 MACH3LOG_ERROR(
"Invalid tokens from spline name - Expected {} tokens. Check implementation in GetTokensFromSplineName()",
static_cast<int>(
kNTokens));
860 MACH3LOG_DEBUG(
"Couldn't Match any systematic name in ParameterHandler with spline name: {}" , FullSplineName);
865 for (
unsigned int iMode = 0; iMode <
SplineModeVecs[iSample][SystNum].size(); iMode++) {
875 MACH3LOG_DEBUG(
"Couldn't find mode for {} in {}. Problem Spline is : {} ", Mode, Syst, FullSplineName);
879 mySpline = Key->ReadObject<TSpline3>();
881 if (
isValidSplineIndex(SampleTitle, iOscChan, SystNum, ModeNum, {Var1Bin, Var2Bin, Var3Bin})) {
882 MACH3LOG_TRACE(
"Pushed back monolith for spline {}", FullSplineName);
884 int nKnots = mySpline->GetNp();
886 for (
int iKnot = 0; iKnot < nKnots; iKnot++) {
888 mySpline->GetKnot(iKnot, x, y);
889 if (y < 0.99999 || y > 1.00001)
897 int index =
IndexVectMap.at(std::make_tuple(iSample, iOscChan, SystNum, ModeNum, Var1Bin, Var2Bin, Var3Bin));
907 if(mySpline)
delete mySpline;
934 size_t pos = FileName.find(
' ');
935 if (pos != std::string::npos) {
936 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
937 while ((pos = FileName.find(
' ')) != std::string::npos) {
941 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"OPEN");
943 TMacro *ConfigCov = SplineFile->Get<TMacro>(
"ParameterHandler");
951 MACH3LOG_ERROR(
"Loading precomputed spline file, however encountered different YAML config, please regenerate input");
960 for (
int iSpline = 0; iSpline <
nParams; iSpline++) {
970 TTree *Settings = SplineFile->Get<TTree>(
"Settings");
971 int CoeffIndex_temp, MonolithSize_temp;
972 short int nParams_temp;
973 Settings->SetBranchAddress(
"CoeffIndex", &CoeffIndex_temp);
974 Settings->SetBranchAddress(
"MonolithSize", &MonolithSize_temp);
975 Settings->SetBranchAddress(
"nParams", &nParams_temp);
977 int SplineBinning_size1, SplineBinning_size2, SplineBinning_size3;
978 Settings->SetBranchAddress(
"SplineBinning_size1", &SplineBinning_size1);
979 Settings->SetBranchAddress(
"SplineBinning_size2", &SplineBinning_size2);
980 Settings->SetBranchAddress(
"SplineBinning_size3", &SplineBinning_size3);
981 int SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3;
982 Settings->SetBranchAddress(
"SplineModeVecs_size1", &SplineModeVecs_size1);
983 Settings->SetBranchAddress(
"SplineModeVecs_size2", &SplineModeVecs_size2);
984 Settings->SetBranchAddress(
"SplineModeVecs_size3", &SplineModeVecs_size3);
985 std::vector<std::string>* SampleNames_temp =
nullptr;
986 Settings->SetBranchAddress(
"SampleNames", &SampleNames_temp);
987 std::vector<std::string>* SampleTitles_temp =
nullptr;
988 Settings->SetBranchAddress(
"SampleTitles", &SampleTitles_temp);
989 std::vector<int>* nSplineParams_temp =
nullptr;
990 Settings->SetBranchAddress(
"nSplineParams", &nSplineParams_temp);
991 Settings->GetEntry(0);
1004 auto Resize3D = [](
auto& vec,
int d1,
int d2,
int d3) {
1006 for (
int i = 0; i < d1; ++i) {
1008 for (
int j = 0; j < d2; ++j) {
1009 vec[i][j].resize(d3);
1014 Resize3D(
SplineBinning, SplineBinning_size1, SplineBinning_size2, SplineBinning_size3);
1015 Resize3D(
SplineModeVecs, SplineModeVecs_size1, SplineModeVecs_size2, SplineModeVecs_size3);
1022 TTree *MonolithTree = SplineFile->Get<TTree>(
"MonolithTree");
1028 MonolithTree->SetBranchAddress(
"isflatarray",
isflatarray);
1031 std::vector<int>* coeffindexvec_temp =
nullptr;
1032 MonolithTree->SetBranchAddress(
"coeffindexvec", &coeffindexvec_temp);
1033 std::vector<int>* uniquecoeffindices_temp =
nullptr;
1034 MonolithTree->SetBranchAddress(
"uniquecoeffindices", &uniquecoeffindices_temp);
1035 std::vector<int>* uniquesplinevec_Monolith_temp =
nullptr;
1036 MonolithTree->SetBranchAddress(
"uniquesplinevec_Monolith", &uniquesplinevec_Monolith_temp);
1037 std::vector<int>* UniqueSystIndices_temp =
nullptr;
1038 MonolithTree->SetBranchAddress(
"UniqueSystIndices", &UniqueSystIndices_temp);
1042 MonolithTree->SetBranchAddress(
"xcoeff",
xcoeff_arr);
1044 MonolithTree->GetEntry(0);
1056 TTree *IndexTree = SplineFile->Get<TTree>(
"IndexVec");
1059 IndexTree->SetBranchAddress(
"SplineIndex", &IndexTemp);
1060 IndexVect.resize(IndexTree->GetEntries());
1062 for (Long64_t iEntry = 0; iEntry < IndexTree->GetEntries(); ++iEntry) {
1063 IndexTree->GetEntry(iEntry);
1066 auto key = std::make_tuple(IndexTemp->iSample, IndexTemp->iOscChan, IndexTemp->iSyst,
1067 IndexTemp->iMode, IndexTemp->iVar[0], IndexTemp->iVar[1],
1068 IndexTemp->iVar[2]);
1073 TTree *SplineBinningTree = SplineFile->Get<TTree>(
"SplineBinningTree");
1074 std::vector<int> indices(3);
1075 SplineBinningTree->SetBranchAddress(
"i", &indices[0]);
1076 SplineBinningTree->SetBranchAddress(
"j", &indices[1]);
1077 SplineBinningTree->SetBranchAddress(
"k", &indices[2]);
1078 TAxis* axis =
nullptr;
1079 SplineBinningTree->SetBranchAddress(
"axis", &axis);
1082 for (Long64_t entry = 0; entry < SplineBinningTree->GetEntries(); ++entry) {
1083 SplineBinningTree->GetEntry(entry);
1087 SplineBinning[i][j][k] =
static_cast<TAxis*
>(axis->Clone());
1090 std::vector<int> indices_mode(3);
1092 TTree *SplineModeTree = SplineFile->Get<TTree>(
"SplineModeTree");
1093 SplineModeTree->SetBranchAddress(
"i", &indices_mode[0]);
1094 SplineModeTree->SetBranchAddress(
"j", &indices_mode[1]);
1095 SplineModeTree->SetBranchAddress(
"k", &indices_mode[2]);
1096 SplineModeTree->SetBranchAddress(
"value", &mode_value);
1099 for (Long64_t entry = 0; entry < SplineModeTree->GetEntries(); ++entry) {
1100 SplineModeTree->GetEntry(entry);
1101 int i = indices_mode[0];
1102 int j = indices_mode[1];
1103 int k = indices_mode[2];
1114 size_t pos = FileName.find(
' ');
1115 if (pos != std::string::npos) {
1116 MACH3LOG_WARN(
"Filename ({}) contains spaces. Replacing spaces with underscores.", FileName);
1117 while ((pos = FileName.find(
' ')) != std::string::npos) {
1118 FileName[pos] =
'_';
1122 auto SplineFile = std::make_unique<TFile>(FileName.c_str(),
"recreate");
1124 TMacro ConfigSave =
YAMLtoTMacro(ConfigCurrent,
"ParameterHandler");
1133 SplineFile->Close();
1139 TTree *Settings =
new TTree(
"Settings",
"Settings");
1142 short int nParams_temp =
nParams;
1144 Settings->Branch(
"CoeffIndex", &CoeffIndex_temp,
"CoeffIndex/I");
1145 Settings->Branch(
"MonolithSize", &MonolithSize_temp,
"MonolithSize/I");
1146 Settings->Branch(
"nParams", &nParams_temp,
"nParams/S");
1148 int SplineBinning_size1 =
static_cast<int>(
SplineBinning.size());
1149 int SplineBinning_size2 = (SplineBinning_size1 > 0) ?
static_cast<int>(
SplineBinning[0].size()) : 0;
1150 int SplineBinning_size3 = (SplineBinning_size2 > 0) ?
static_cast<int>(
SplineBinning[0][0].size()) : 0;
1152 Settings->Branch(
"SplineBinning_size1", &SplineBinning_size1,
"SplineBinning_size1/I");
1153 Settings->Branch(
"SplineBinning_size2", &SplineBinning_size2,
"SplineBinning_size2/I");
1154 Settings->Branch(
"SplineBinning_size3", &SplineBinning_size3,
"SplineBinning_size3/I");
1156 int SplineModeVecs_size1 =
static_cast<int>(
SplineModeVecs.size());
1157 int SplineModeVecs_size2 = (SplineModeVecs_size1 > 0) ?
static_cast<int>(
SplineModeVecs[0].size()) : 0;
1158 int SplineModeVecs_size3 = (SplineModeVecs_size2 > 0) ?
static_cast<int>(
SplineModeVecs[0][0].size()) : 0;
1160 Settings->Branch(
"SplineModeVecs_size1", &SplineModeVecs_size1,
"SplineModeVecs_size1/I");
1161 Settings->Branch(
"SplineModeVecs_size2", &SplineModeVecs_size2,
"SplineModeVecs_size2/I");
1162 Settings->Branch(
"SplineModeVecs_size3", &SplineModeVecs_size3,
"SplineModeVecs_size3/I");
1164 std::vector<std::string> SampleNames_temp =
SampleNames;
1165 Settings->Branch(
"SampleNames", &SampleNames_temp);
1166 std::vector<std::string> SampleTitles_temp =
SampleTitles;
1167 Settings->Branch(
"SampleTitles", &SampleTitles_temp);
1169 Settings->Branch(
"nSplineParams", &nSplineParams_temp);
1180 TTree *MonolithTree =
new TTree(
"MonolithTree",
"MonolithTree");
1185 MonolithTree->Branch(
"coeffindexvec", &coeffindexvec_temp);
1187 MonolithTree->Branch(
"uniquecoeffindices", &uniquecoeffindices_temp);
1189 MonolithTree->Branch(
"uniquesplinevec_Monolith", &uniquesplinevec_Monolith_temp);
1191 MonolithTree->Branch(
"UniqueSystIndices", &UniqueSystIndices_temp);
1194 MonolithTree->Fill();
1196 MonolithTree->Write();
1197 delete MonolithTree;
1204 TTree *IndexTree =
new TTree(
"IndexVec",
"IndexVec");
1206 IndexTree->Branch(
"SplineIndex", &entry);
1221 TTree *SplineBinningTree =
new TTree(
"SplineBinningTree",
"SplineBinningTree");
1222 std::vector<int> indices(3);
1223 TAxis* axis =
nullptr;
1224 SplineBinningTree->Branch(
"i", &indices[0],
"i/I");
1225 SplineBinningTree->Branch(
"j", &indices[1],
"j/I");
1226 SplineBinningTree->Branch(
"k", &indices[2],
"k/I");
1227 SplineBinningTree->Branch(
"axis",
"TAxis", &axis);
1234 indices[0] =
static_cast<int>(i);
1235 indices[1] =
static_cast<int>(j);
1236 indices[2] =
static_cast<int>(k);
1237 SplineBinningTree->Fill();
1242 SplineBinningTree->Write();
1243 delete SplineBinningTree;
1245 std::vector<int> indices_mode(3);
1248 TTree *SplineModeTree =
new TTree(
"SplineModeTree",
"SplineModeTree");
1250 SplineModeTree->Branch(
"i", &indices_mode[0],
"i/I");
1251 SplineModeTree->Branch(
"j", &indices_mode[1],
"j/I");
1252 SplineModeTree->Branch(
"k", &indices_mode[2],
"k/I");
1253 SplineModeTree->Branch(
"value", &mode_value,
"value/I");
1259 indices_mode[0] =
static_cast<int>(i);
1260 indices_mode[1] =
static_cast<int>(j);
1261 indices_mode[2] =
static_cast<int>(k);
1263 SplineModeTree->Fill();
1269 SplineModeTree->Write();
1270 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::map< std::tuple< int, int, int, int, int, int, int >, int > IndexVectMap
Map between spline origin/properties (iSample, iOscChan, iSyst, iMode, iVar1, iVar2,...
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::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.