@@ -1481,7 +1481,7 @@ void GReWeightXSecMEC::BuildEnergyDepRatioGraphs(const genie::EventRecord& event
14811481 interaction->InitStatePtr ()->SetProbeE (E_ref);
14821482 double xsec_ref[3 ];
14831483 for (int m = 0 ; m < 3 ; ++m) {
1484- xsec_ref[m] = this ->GetXSecFromSplineOrIntegral (algs[m], interaction);
1484+ xsec_ref[m] = this ->GetXSecIntegral (algs[m], interaction);
14851485 if (xsec_ref[m] <= 0 .) {
14861486 LOG (" ReW" , pWARN) << " Model " << m << " has zero xsec at E_ref="
14871487 << E_ref << " GeV. Setting to 1 to avoid division by zero." ;
@@ -1490,7 +1490,7 @@ void GReWeightXSecMEC::BuildEnergyDepRatioGraphs(const genie::EventRecord& event
14901490 }
14911491
14921492 // Also get the default model's xsec at the reference energy
1493- double xsec_def_ref = this ->GetXSecFromSplineOrIntegral (fXSecAlgCCDef , interaction);
1493+ double xsec_def_ref = this ->GetXSecIntegral (fXSecAlgCCDef , interaction);
14941494 if (xsec_def_ref <= 0 .) {
14951495 LOG (" ReW" , pWARN) << " Default model has zero xsec at E_ref="
14961496 << E_ref << " GeV. Setting to 1." ;
@@ -1509,15 +1509,15 @@ void GReWeightXSecMEC::BuildEnergyDepRatioGraphs(const genie::EventRecord& event
15091509 interaction->InitStatePtr ()->SetProbeE (Ev);
15101510
15111511 // Default model xsec, normalised
1512- double xsec_def = this ->GetXSecFromSplineOrIntegral (fXSecAlgCCDef , interaction);
1512+ double xsec_def = this ->GetXSecIntegral (fXSecAlgCCDef , interaction);
15131513 double xsec_def_norm = xsec_def / xsec_def_ref;
15141514
15151515 // Compute normalised ratio for each model
15161516 double ratio_max = 1.0 ; // default ratio is 1.0
15171517 double ratio_min = 1.0 ;
15181518
15191519 for (int m = 0 ; m < 3 ; ++m) {
1520- double xsec_alt = this ->GetXSecFromSplineOrIntegral (algs[m], interaction);
1520+ double xsec_alt = this ->GetXSecIntegral (algs[m], interaction);
15211521 double xsec_alt_norm = xsec_alt / xsec_ref[m];
15221522
15231523 double ratio = (xsec_def_norm > 0 .)
@@ -1611,69 +1611,47 @@ double GReWeightXSecMEC::CalcWeightDecayAngMECLegendre(double theta_rad, double
16111611 return weight;
16121612}
16131613// _______________________________________________________________________________________
1614- double GReWeightXSecMEC::GetXSecIntegral (const XSecAlgorithmI* xsec_alg,
1615- const Interaction* interaction)
1616- {
1617- double xsec = 0 .;
1618-
1619- XSecSplineList* xssl = XSecSplineList::Instance ();
1620- assert ( xssl );
1621-
1622- // First check if a total cross section spline is already available
1623- // for the requested cross section model and interaction. If it is,
1624- // use it to get the integrated cross section.
1625- std::string curr_tune = xssl->CurrentTune ();
1626- bool spline_computed = xssl->HasSplineFromTune ( curr_tune )
1627- && xssl->SplineExists ( xsec_alg, interaction );
1628- if ( spline_computed ) {
1629- const Spline* spl = xssl->GetSpline ( xsec_alg, interaction );
1630- double Ev = interaction->InitState ().ProbeE ( kRfLab ); // kRfHitNucRest?
1631- if ( spl->ClosestKnotValueIsZero (Ev, " -" ) ) xsec = 0 .;
1632- else xsec = spl->Evaluate ( Ev );
1633- }
1634- // If not, fall back to doing the integration directly
1635- else {
1636- xsec = xsec_alg->Integral ( interaction );
1637- }
1638-
1639- LOG (" ReW" , pDEBUG) << " MECshape spline check: "
1640- << ( spline_computed ? " found" : " not found" );
1641-
1642- return xsec;
1643- }
1644- // _______________________________________________________________________________________
1645- double GReWeightXSecMEC::GetXSecFromSplineOrIntegral (
1614+ double GReWeightXSecMEC::GetXSecIntegral (
16461615 const XSecAlgorithmI* xsec_alg, const Interaction* interaction)
16471616{
16481617 // Search all loaded tunes for a matching spline. Falls back to
16491618 // numerical integration if no spline is found in any tune.
16501619
1620+ double xsec = 0 .;
1621+ bool spline_computed = false ;
1622+
16511623 XSecSplineList* xssl = XSecSplineList::Instance ();
16521624 assert ( xssl );
16531625
16541626 std::string orig_tune = xssl->CurrentTune ();
1655- std::vector<std::string> tunes = xssl->GetLoadedTunes ();
1656-
1657- for (const auto & tune : tunes) {
1658- xssl->SetCurrentTune (tune);
1659- if ( xssl->SplineExists (xsec_alg, interaction) ) {
1660- const Spline* spl = xssl->GetSpline (xsec_alg, interaction);
1661- double Ev = interaction->InitState ().ProbeE (kRfLab );
1662- double xsec = 0 .;
1627+ std::vector< std::string > tunes = xssl->GetLoadedTunes ();
1628+
1629+ for ( const auto & curr_tune : tunes ) {
1630+ xssl->SetCurrentTune ( curr_tune );
1631+ spline_computed = xssl->HasSplineFromTune ( curr_tune )
1632+ && xssl->SplineExists ( xsec_alg, interaction );
1633+ if ( spline_computed ) {
1634+ const Spline* spl = xssl->GetSpline ( xsec_alg, interaction );
1635+ double Ev = interaction->InitState ().ProbeE ( kRfLab );
16631636 if ( spl->ClosestKnotValueIsZero (Ev, " -" ) ) xsec = 0 .;
16641637 else xsec = spl->Evaluate (Ev);
16651638
1666- LOG (" ReW" , pINFO ) << " Found spline for " << xsec_alg->Id ().Key ()
1639+ LOG (" ReW" , pDEBUG ) << " Found spline for " << xsec_alg->Id ().Key ()
16671640 << " in tune " << tune;
16681641
1669- xssl-> SetCurrentTune (orig_tune);
1670- return xsec ;
1642+ // We found the spline, so exit the loop over tunes
1643+ break ;
16711644 }
16721645 }
16731646
1674- xssl->SetCurrentTune (orig_tune);
1647+ // Reset the current tune back to the original before returning a result
1648+ xssl->SetCurrentTune ( orig_tune );
1649+
1650+ if ( spline_computed ) {
1651+ return xsec;
1652+ }
16751653
1676- LOG (" ReW" , pWARN ) << " No spline found for " << xsec_alg->Id ().Key ()
1654+ LOG (" ReW" , pDEBUG ) << " No spline found for " << xsec_alg->Id ().Key ()
16771655 << " in any loaded tune. Falling back to numerical integration." ;
1678- return xsec_alg->Integral (interaction);
1656+ return xsec_alg->Integral ( interaction );
16791657}
0 commit comments