@@ -67,6 +67,14 @@ namespace Experimental {
6767
6868namespace {
6969
70+ // Return a stringy-field version of the value, formatted to maximum precision.
71+ std::string doubleToString (double val)
72+ {
73+ std::stringstream ss;
74+ ss << std::setprecision (std::numeric_limits<double >::max_digits10) << val;
75+ return ss.str ();
76+ }
77+
7078std::string mathFunc (std::string const &name)
7179{
7280 return " RooFit::Detail::MathFuncs::" + name;
@@ -249,8 +257,9 @@ void codegenImpl(RooMultiPdf &arg, CodegenContext &ctx)
249257
250258 // MathFunc call
251259
252- if (numPdfs > 2 ) { // the value of this number should be discussed.Beyound a certain number of indices MathFunc call
253- // becomes more efficient.
260+ // The value of this number should be discussed. Beyound a certain number of
261+ // indices MathFunc call becomes more efficient.
262+ if (numPdfs > 2 ) {
254263 ctx.addResult (&arg, ctx.buildCall (mathFunc (" multipdf" ), arg.indexCategory (), arg.getPdfList ()));
255264
256265 std::cout << " MathFunc call used\n " ;
@@ -354,15 +363,7 @@ void codegenImpl(RooChebychev &arg, CodegenContext &ctx)
354363
355364void codegenImpl (RooConstVar &arg, CodegenContext &ctx)
356365{
357- // Just return a stringy-field version of the const value.
358- // Formats to the maximum precision.
359- constexpr auto max_precision{std::numeric_limits<double >::max_digits10};
360- std::stringstream ss;
361- ss.precision (max_precision);
362- // Just use toString to make sure we do not output 'inf'.
363- // This is really ugly for large numbers...
364- ss << std::fixed << RooNumber::toString (arg.getVal ());
365- ctx.addResult (&arg, ss.str ());
366+ ctx.addResult (&arg, doubleToString (arg.getVal ()));
366367}
367368
368369void codegenImpl (RooConstraintSum &arg, CodegenContext &ctx)
@@ -507,7 +508,7 @@ void codegenImpl(RooParamHistFunc &arg, CodegenContext &ctx)
507508 // be binned uniformly.
508509 double binV = arg.dataHist ().binVolume (0 );
509510 std::string weightArr = arg.dataHist ().declWeightArrayForCodeSquash (ctx, false );
510- result += " * *(" + weightArr + " + " + idx + " ) * " + std::to_string (binV);
511+ result += " * *(" + weightArr + " + " + idx + " ) * " + doubleToString (binV);
511512 }
512513 ctx.addResult (&arg, result);
513514}
@@ -650,15 +651,7 @@ void codegenImpl(RooRealVar &arg, CodegenContext &ctx)
650651 if (!arg.isConstant ()) {
651652 ctx.addResult (&arg, arg.GetName ());
652653 }
653- // Just return a formatted version of the const value.
654- // Formats to the maximum precision.
655- constexpr auto max_precision{std::numeric_limits<double >::max_digits10};
656- std::stringstream ss;
657- ss.precision (max_precision);
658- // Just use toString to make sure we do not output 'inf'.
659- // This is really ugly for large numbers...
660- ss << std::fixed << RooNumber::toString (arg.getVal ());
661- ctx.addResult (&arg, ss.str ());
654+ ctx.addResult (&arg, doubleToString (arg.getVal ()));
662655}
663656
664657void codegenImpl (RooRecursiveFraction &arg, CodegenContext &ctx)
@@ -812,7 +805,7 @@ std::string rooHistIntegralTranslateImpl(int code, RooAbsArg const &arg, RooData
812805 << std::endl;
813806 return " " ;
814807 }
815- return std::to_string (dataHist.sum (histFuncMode));
808+ return doubleToString (dataHist.sum (histFuncMode));
816809}
817810
818811} // namespace
@@ -853,7 +846,7 @@ std::string codegenIntegralImpl(RooMultiVarGaussian &arg, int code, const char *
853846 throw std::runtime_error (errorMsg.str ().c_str ());
854847 }
855848
856- return std::to_string (arg.analyticalIntegral (code, rangeName));
849+ return doubleToString (arg.analyticalIntegral (code, rangeName));
857850}
858851
859852std::string codegenIntegralImpl (RooPoisson &arg, int code, const char *rangeName, CodegenContext &ctx)
@@ -905,7 +898,7 @@ std::string codegenIntegralImpl(RooUniform &arg, int code, const char *rangeName
905898{
906899 // The integral of a uniform distribution is static, so we can just hardcode
907900 // the result in a string.
908- return std::to_string (arg.analyticalIntegral (code, rangeName));
901+ return doubleToString (arg.analyticalIntegral (code, rangeName));
909902}
910903
911904} // namespace Experimental
0 commit comments