Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 4 additions & 7 deletions Samples/SampleHandlerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ M3::float_t SampleHandlerBase::GetEventWeight(const int iEntry) {
}

// ************************************************
std::vector< std::vector<int> > SampleHandlerBase::GetSplineBins(int Event, BinnedSplineHandler* BinnedSpline, bool& ThrowCrititcal) const {
std::vector< SplineIndex > SampleHandlerBase::GetSplineBins(int Event, BinnedSplineHandler* BinnedSpline, bool& ThrowCrititcal) const {
// ************************************************
const int SampleIndex = MCEvents[Event].NominalSample;
const auto SampleTitle = GetSampleTitle(SampleIndex);
Expand All @@ -1149,7 +1149,7 @@ std::vector< std::vector<int> > SampleHandlerBase::GetSplineBins(int Event, Binn
MCEvents[Event].nupdgUnosc, MCEvents[Event].nupdg);
const int Mode = static_cast<int>(std::round(ReturnKinematicParameter("Mode", Event)));
const double Etrue = MCEvents[Event].enu_true;
std::vector< std::vector<int> > EventSplines;
std::vector< SplineIndex > EventSplines;
switch(GetNDim(SampleIndex)) {
case 1:
EventSplines = BinnedSpline->GetEventSplines(SampleTitle, OscIndex, Mode, Etrue, *(MCEvents[Event].KinVar[0]), 0.);
Expand Down Expand Up @@ -1188,7 +1188,7 @@ void SampleHandlerBase::SetSplinePointers() {
w_pointers.reserve(w_pointers.size() + NSplines);
const auto SampleId = MCEvents[j].NominalSample;
for(int spline = 0; spline < NSplines; spline++) {
int SystIndex = EventSplines[spline][2];
int SystIndex = EventSplines[spline].iSyst;

bool IsSelected = PassesSelection(SplineParsVec[SampleId][SystIndex], j);
// Need to then break the event loop
Expand All @@ -1197,10 +1197,7 @@ void SampleHandlerBase::SetSplinePointers() {
continue;
}
//Event Splines indexed as: sample name, oscillation channel, syst, mode, etrue, var1, var2 (var2 is a dummy 0 for 1D splines)
w_pointers.push_back(BinnedSpline->RetPointer(EventSplines[spline][0], EventSplines[spline][1],
EventSplines[spline][2], EventSplines[spline][3],
EventSplines[spline][4], EventSplines[spline][5],
EventSplines[spline][6]));
w_pointers.push_back(BinnedSpline->RetPointer(EventSplines[spline]));
} // end loop over splines
w_pointers.shrink_to_fit();
} // end loop over events
Expand Down
15 changes: 8 additions & 7 deletions Samples/SampleHandlerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,15 @@ class SampleHandlerBase : public SampleHandlerInterface
/// @brief Function which does a lot of the lifting regarding the workflow in creating different MC objects
void Initialise();

/// @brief Contains all your splines (binned or unbinned) and handles the setup and the returning of weights from spline evaluations
std::unique_ptr<SplineBase> SplineHandler;

/// @brief Contains oscillator handling calculating oscillation probabilities
std::shared_ptr<OscillationHandler> Oscillator;
//===============================================================================
/// @brief Set pointers for each event to appropriate weights, for unbinned based on event number
/// while for binned based on other kinematical properties
void SetSplinePointers();
/// @brief Retrieve the spline bin indices associated with a given event.
/// @warning ThrowCrititcal argument will be eventually removed
std::vector< std::vector<int> > GetSplineBins(int Event, BinnedSplineHandler* BinnedSpline, bool& ThrowCrititcal) const;
std::vector< SplineIndex > GetSplineBins(int Event, BinnedSplineHandler* BinnedSpline, bool& ThrowCrititcal) const;

//Functions which find the nominal bin and bin edges
/// @brief Functions which find the nominal bin and bin edges
void FindNominalBinAndEdges();

/// @brief set the binning for 2D sample used for the likelihood calculation
Expand Down Expand Up @@ -386,6 +381,12 @@ class SampleHandlerBase : public SampleHandlerInterface
/// @brief Setup spline handler (both binned or unbinned)
void InitialiseSplineObject();

/// Contains all your splines (binned or unbinned) and handles the setup and the returning of weights from spline evaluations
std::unique_ptr<SplineBase> SplineHandler;

/// Contains oscillator handling calculating oscillation probabilities
std::shared_ptr<OscillationHandler> Oscillator;

//===============================================================================
//DB Variables required for GetLikelihood
/// KS: This stores binning information, in future could be come vector to store binning for every used sample
Expand Down
28 changes: 18 additions & 10 deletions Splines/BinnedSplineHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ std::vector<TAxis *> BinnedSplineHandler::FindSplineBinning(const std::string& F
}

//****************************************
const M3::float_t* BinnedSplineHandler::RetPointer(const int sample, const int oscchan, const int syst, const int mode,
const int var1bin, const int var2bin, const int var3bin) const {
const M3::float_t* BinnedSplineHandler::RetPointer(const SplineIndex& Variables) const {
//****************************************
int Index = IndexVectMap.at(std::make_tuple(sample, oscchan, syst, mode, var1bin, var2bin, var3bin));
int Index = IndexVectMap.at(std::make_tuple(Variables.iSample, Variables.iOscChan, Variables.iSyst,
Variables.iMode, Variables.iVar1, Variables.iVar2, Variables.iVar3));
return &weightvec_Monolith[IndexVect[Index].value];
}

//****************************************
int BinnedSplineHandler::CountNumberOfLoadedSplines(bool NonFlat, int Verbosity) {
int BinnedSplineHandler::CountNumberOfLoadedSplines(bool NonFlat, int Verbosity) const {
//****************************************
std::vector<int> SampleAll(SampleTitles.size(), 0);
std::vector<int> SampleNonFlat(SampleTitles.size(), 0);
Expand All @@ -470,7 +470,6 @@ int BinnedSplineHandler::CountNumberOfLoadedSplines(bool NonFlat, int Verbosity)

std::string SampleTitle = SampleTitles[iSample];


if (!isValidSplineIndex(SampleTitle, entry.iOscChan, entry.iSyst,
entry.iMode, entry.iVar1,
entry.iVar2, entry.iVar3)) {
Expand Down Expand Up @@ -712,11 +711,11 @@ void BinnedSplineHandler::PrintBinning(TAxis *Axis) const {
}

//****************************************
std::vector< std::vector<int> > BinnedSplineHandler::GetEventSplines(const std::string& SampleTitle,
std::vector<SplineIndex> BinnedSplineHandler::GetEventSplines(const std::string& SampleTitle,
int iOscChan, int EventMode, double Var1Val,
double Var2Val, double Var3Val) {
//****************************************
std::vector<std::vector<int>> ReturnVec;
std::vector<SplineIndex> ReturnVec;
int SampleIndex = GetSampleIndex(SampleTitle);

int Mode = -1;
Expand Down Expand Up @@ -754,7 +753,16 @@ std::vector< std::vector<int> > BinnedSplineHandler::GetEventSplines(const std::
int splineID = IndexVect[index].value;
//Also check that the spline isn't flat
if(!isflatarray[splineID]) {
ReturnVec.push_back({SampleIndex, iOscChan, iSyst, iMode, Var1Bin, Var2Bin, Var3Bin});
SplineIndex idx;
idx.iSample = SampleIndex;
idx.iOscChan = iOscChan;
idx.iSyst = iSyst;
idx.iMode = iMode;
idx.iVar1 = Var1Bin;
idx.iVar2 = Var2Bin;
idx.iVar3 = Var3Bin;

ReturnVec.push_back(idx);
}
}
}
Expand Down Expand Up @@ -884,8 +892,8 @@ void BinnedSplineHandler::FillSampleArray(const std::string& SampleTitle, const
}

mySpline = Key->ReadObject<TSpline3>();

if (isValidSplineIndex(SampleTitle, iOscChan, SystNum, ModeNum, Var1Bin, Var2Bin, Var3Bin)) { // loop over all the spline knots and check their value
// loop over all the spline knots and check their value
if (isValidSplineIndex(SampleTitle, iOscChan, SystNum, ModeNum, Var1Bin, Var2Bin, Var3Bin)) {
MACH3LOG_TRACE("Pushed back monolith for spline {}", FullSplineName);
// if the value is 1 then set the flat bool to false
nKnots = mySpline->GetNp();
Expand Down
7 changes: 3 additions & 4 deletions Splines/BinnedSplineHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ class BinnedSplineHandler : public SplineBase {
/// @note DB Add virtual so it can be overridden in experiment specific (if needed)
virtual void FillSampleArray(const std::string& SampleTitle, const std::vector<std::string>& OscChanFileNames);
/// @brief Return the splines which affect a given event
std::vector< std::vector<int> > GetEventSplines(const std::string& SampleTitle, int iOscChan, int EventMode, double Var1Val, double Var2Val, double Var3Val);
std::vector<SplineIndex> GetEventSplines(const std::string& SampleTitle, int iOscChan, int EventMode, double Var1Val, double Var2Val, double Var3Val);
/// @brief KS: After calculations are done on GPU we copy memory to CPU. This operation is asynchronous meaning while memory is being copied some operations are being carried. Memory must be copied before actual reweight. This function make sure all has been copied.
void SynchroniseMemTransfer() const final {return;}
/// @brief Count how many splines we have
int CountNumberOfLoadedSplines(bool NonFlat=false, int Verbosity=0);
int CountNumberOfLoadedSplines(bool NonFlat=false, int Verbosity=0) const;

/// @brief get pointer to spline weight based on bin variables
const M3::float_t* RetPointer(const int sample, const int oscchan, const int syst, const int mode,
const int var1bin, const int var2bin, const int var3bin) const;
const M3::float_t* RetPointer(const SplineIndex& Variables) const;
/// @brief KS: Prepare spline file that can be used for fast loading
void PrepareSplineFile(std::string FileName) final;
/// @brief KS: Load preprocessed spline file
Expand Down
Loading