Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Binned spline CI #62

Merged
merged 17 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CIValidations/NuOscillatorInterfaceValidations.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <Constants/OscillatorConstants.h>
#include "Utils/Comparison.h"

#include "Oscillator/OscillatorFactory.h"
Expand Down Expand Up @@ -25,7 +26,7 @@ int main() {
auto osc = OscillatorFactory().CreateOscillator(
"NuOscillatorInterfaceValidations.yml");

std::vector<double> Energies;
std::vector<FLOAT_T> Energies;
double start = -3;
double end = 3;
size_t nbins = 100;
Expand All @@ -37,7 +38,7 @@ int main() {
osc->SetEnergyArrayInCalcer(Energies);
osc->Setup();

std::vector<double> OscParProp = {0.3, 0.5, 0.020, 7.53e-5,
std::vector<FLOAT_T> OscParProp = {0.3, 0.5, 0.020, 7.53e-5,
2.494e-3, 0.0, 1300, 2.6, 0.5};
osc->CalculateProbabilities(OscParProp);

Expand Down
79 changes: 79 additions & 0 deletions CIValidations/Scripts/CreateBinnedSplineFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "TRandom3.h"
#include "TSpline.h"
#include "TFile.h"
#include "TGraph.h"
#include "TString.h"
#include "TH3F.h"

#include <iostream>
#include <algorithm>

void CreateBinnedSplineFile(){

int nTrueEnergyBins = 5;
int nXBins = 10;
//To make splines in Etrue, x and y change this to be a larger number
int nYBins = 1;
double TrueEnergyBins[] = {0., 1.0, 2.0, 3.0, 4.0, 5.0};
double XBins[] = {0., 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
double YBins[] = {0.,10.0};

//Let's try out 5 systematics
//This gives us a total of 5*10*10*5 = 2500 splines
std::vector<int> SystematicKnots = {5, 7, 7, 2, 3};//, 7, 2, 7, 7, 7};
std::vector<std::vector<std::string>> SystematicModeNames = {{"ccqe"}, {"cc1pipm"}, {"2p2h"}, {"other"}, {"ccqe"}};
//Values to centre the gaussian response on
std::vector<double> SystematicMeanResponse = {1.0, 2.0, 1.0, 1.5, 1.0};
std::vector<int> SystematicNominalKnot = {3, 4, 4, 1, 2};
std::vector<std::string> SystematicNames = {"mysyst1", "mysyst2", "mysyst3","mysyst4","mysyst5"};

if(SystematicKnots.size() != SystematicNames.size() && SystematicNames.size() != SystematicNominalKnot.size() && SystematicKnots.size() != SystematicMeanResponse.size()) {
std::cerr << "Systematic vectors are not of equal length this might cause problems, please fix!" << std::endl;
throw;
}

TRandom3 Random = TRandom3(0);

auto OutputFile = std::unique_ptr<TFile>(TFile::Open("BinnedSplinesTutorialInputs.root", "RECREATE"));

//Firstly let's write the dev.tmp.0.0 file which sets the binning
TH3F* BinningHist = new TH3F("dev_tmp.0.0", "dev_tmp.0.0", nTrueEnergyBins, TrueEnergyBins, nXBins, XBins, nYBins, YBins);

for(auto iSyst = 0 ; iSyst < SystematicNames.size() ; ++iSyst){
for(auto SystematicModeName : SystematicModeNames[iSyst]){
for(auto SystematicKnotNumber : SystematicKnots) {
for(auto TrueEnergyBin_i = 0 ; TrueEnergyBin_i < nTrueEnergyBins ; ++TrueEnergyBin_i){
for(auto XBin_i = 0 ; XBin_i < nXBins ; ++XBin_i){
for(auto YBin_i = 0 ; YBin_i < nYBins ; ++YBin_i){
double knot_w = 1;
TGraph *graph = new TGraph(SystematicKnotNumber);

for(auto iKnot = 0 ; iKnot < SystematicKnotNumber ; ++iKnot) {
//Check on if you are the nominal knot
if(iKnot != SystematicNominalKnot[iSyst]) {
//Do a random throw from a gaussian
knot_w = Random.Gaus(SystematicMeanResponse[iSyst], 1.0);
knot_w = std::max(0., knot_w);
// std::cout << "Knot_w is " << knot_w << std::endl;
//point number, x-val, y-val
}
graph->SetPoint(iKnot, iKnot, knot_w);
}
TSpline3 *Spline = new TSpline3(Form("dev.%s.%s.sp.%i.%i.%i", SystematicNames[iSyst].c_str(), SystematicModeName.c_str(), TrueEnergyBin_i, XBin_i, YBin_i),graph);
Spline->SetName(Form("dev.%s.%s.sp.%i.%i.%i", SystematicNames[iSyst].c_str(), SystematicModeName.c_str(), TrueEnergyBin_i, XBin_i, YBin_i));
//This makes things slow but removes many backup-cycles being saved to the file
Spline->Write(Spline->GetName(), TDirectoryFile::kOverwrite);
delete graph;
delete Spline;
}
}
}
}
}
}

OutputFile->Write();
OutputFile->Close();

return;
}
Loading
Loading