Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (f31105fd)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Gaudi::Histograming::Sink Namespace Reference

Namespaces

 detail
 
 details
 

Classes

struct  ArthTypeAccessor
 
class  Base
 
struct  BinAccessor
 
struct  Root
 
struct  Traits
 templated Traits dealing with Root Histogram filling for standard histograms More...
 
struct  Traits< false, RootHisto, N >
 Specialization of Traits dealing with non profile Root Histograms. More...
 
struct  Traits< true, RootHisto, N >
 Specialization of Traits dealing with profile Root Histograms. More...
 

Functions

template<typename Traits >
std::tuple< typename Traits::Histo, std::stringjsonToRootHistogram (std::string &dir, std::string &name, nlohmann::json const &j)
 generic function to convert json to a ROOT Histogram More...
 
template<typename Histo >
nlohmann::json rootHistogramTojson (Histo const &)
 generic function to convert a ROOT Histogram to json More...
 
template<typename Traits >
void saveRootHisto (TFile &file, std::string dir, std::string name, nlohmann::json const &j)
 generic method to save histograms to files, based on Traits More...
 
template<unsigned int N, bool isProfile, typename ROOTHisto >
void saveRootHisto (TFile &file, std::string dir, std::string name, nlohmann::json const &j)
 generic method to save regular histograms to files More...
 
template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper< TProfile > profileHisto1DToRoot (std::string name, Monitoring::Hub::Entity const &ent)
 Direct conversion of 1D histograms from Gaudi to ROOT format. More...
 
template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper< TProfile2D > profileHisto2DToRoot (std::string name, Monitoring::Hub::Entity const &ent)
 Direct conversion of 2D histograms from Gaudi to ROOT format. More...
 
template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper< TProfile3D > profileHisto3DToRoot (std::string name, Monitoring::Hub::Entity const &ent)
 Direct conversion of 3D histograms from Gaudi to ROOT format. More...
 
template<unsigned int N, Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
void saveProfileHisto (TFile &file, std::string dir, std::string name, Monitoring::Hub::Entity const &ent)
 
template<Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full, typename Arithmetic = double>
std::string printProfileHisto1D (std::string_view name, Gaudi::Monitoring::Hub::Entity const &ent, unsigned int stringsWidth=45)
 
template<Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full, typename Arithmetic = double>
std::string printProfileHisto2D (std::string_view name, Gaudi::Monitoring::Hub::Entity const &ent, unsigned int stringsWidth=45)
 
template<Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full, typename Arithmetic = double>
std::string printProfileHisto3D (std::string_view name, Gaudi::Monitoring::Hub::Entity const &ent, unsigned int stringsWidth=45)
 
std::string printHistogram1D (std::string_view type, std::string_view name, std::string_view title, const nlohmann::json &j, unsigned int stringsWidth=45)
 
std::string printHistogram2D (std::string_view type, std::string_view name, std::string_view title, const nlohmann::json &j, unsigned int stringsWidth=45)
 
std::string printHistogram3D (std::string_view type, std::string_view name, std::string_view title, const nlohmann::json &j, unsigned int stringsWidth=45)
 

Function Documentation

◆ jsonToRootHistogram()

template<typename Traits >
std::tuple< typename Traits::Histo, std::string > Gaudi::Histograming::Sink::jsonToRootHistogram ( std::string dir,
std::string name,
nlohmann::json const &  j 
)

generic function to convert json to a ROOT Histogram

returns the Root histogram and the dir where to save it in the Root file This may be different from input dir in case name has slashes

Definition at line 466 of file Utils.h.

467  {
468  return details::jsonToRootHistogramInternal<Traits>( dir, name, j, std::make_index_sequence<Traits::Dimension>() );
469  }

◆ printHistogram1D()

std::string Gaudi::Histograming::Sink::printHistogram1D ( std::string_view  type,
std::string_view  name,
std::string_view  title,
const nlohmann::json &  j,
unsigned int  stringsWidth = 45 
)
inline

Definition at line 865 of file Utils.h.

866  {
867  const auto& jaxis = j.at( "axis" );
868  const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
869  const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
870  const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
871  const auto nAllEntries = j.at( "nEntries" ).get<unsigned int>();
872  // compute the various momenta
873  BinAccessor ba{ type, j };
874  double sumX{}, sum2X{}, sum3X{}, sum4X{}, nEntries{ 0 };
875  const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, ArthTypeAccessor::is_integral( type ) );
876  for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
877  const double binXValue = xBinAv( nx );
878  const auto n = ba[nx];
879  nEntries += n;
880  auto val = binXValue * n;
881  sumX += val;
882  val *= binXValue;
883  sum2X += val;
884  val *= binXValue;
885  sum3X += val;
886  val *= binXValue;
887  sum4X += val;
888  }
889  const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
890  if ( !( fabs( nEntries ) > 0.0 ) ) { return ""; }
891  const double meanX = sumX / nEntries;
892  const double sigmaX2 = ( sum2X / nEntries ) - std::pow( meanX, 2 );
893  const double stddevX = detail::sqrt_or_zero( sigmaX2 );
894  const double EX3 = sum3X / nEntries;
895  const double A = sigmaX2 * stddevX;
896  const double skewnessX = ( fabs( A ) > 0.0 ? ( EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX ) / A : 0.0 );
897  const double B = sigmaX2 * sigmaX2;
898  const double kurtosisX =
899  ( fabs( B ) > 0.0 && fabs( A ) > 0.0
900  ? ( sum4X / nEntries - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) ) ) / B
901  : 3.0 );
902  // print
903  return fmt::format( fmt::runtime( detail::histo1DFormatting ), detail::formatName( name, stringsWidth ),
904  stringsWidth, stringsWidth, ftitle, stringsWidth, detail::IntWithFixedWidth{ nAllEntries },
905  meanX, stddevX, skewnessX, kurtosisX - 3.0 );
906  }

◆ printHistogram2D()

std::string Gaudi::Histograming::Sink::printHistogram2D ( std::string_view  type,
std::string_view  name,
std::string_view  title,
const nlohmann::json &  j,
unsigned int  stringsWidth = 45 
)
inline

Definition at line 908 of file Utils.h.

909  {
910  const auto& jaxis = j.at( "axis" );
911  const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
912  const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
913  const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
914  const auto minValueY = jaxis[1].at( "minValue" ).get<double>();
915  const auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
916  const auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
917  const auto nAllEntries = j.at( "nEntries" ).get<double>();
918  // compute the various memneta
919  BinAccessor ba{ type, j };
920  double nEntries{};
921  double sumX{}, sumY{};
922  double sum2X{}, sum2Y{};
923  const auto isInt = ArthTypeAccessor::is_integral( type );
924  const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, isInt );
925  const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, isInt );
926  for ( unsigned int ny = 1; ny <= nBinsY; ++ny ) {
927  const auto offset = ny * ( nBinsX + 2 );
928  for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
929  const double binXValue = xBinAv( nx );
930  const double binYValue = yBinAv( ny );
931  const auto n = ba[offset + nx];
932  nEntries += n;
933  sumX += n * binXValue;
934  sum2X += n * binXValue * binXValue;
935  sumY += n * binYValue;
936  sum2Y += n * binYValue * binYValue;
937  }
938  }
939  const double meanX = fabs( nEntries ) > 0 ? sumX / nEntries : 0.0;
940  const double stddevX =
941  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
942  const double meanY = fabs( nEntries ) > 0 ? sumY / nEntries : 0.0;
943  const double stddevY =
944  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
945  // print
946  const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
947  return fmt::format( fmt::runtime( detail::histo2DFormatting ), detail::formatName( name, stringsWidth ),
948  stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY,
949  stddevY );
950  }

◆ printHistogram3D()

std::string Gaudi::Histograming::Sink::printHistogram3D ( std::string_view  type,
std::string_view  name,
std::string_view  title,
const nlohmann::json &  j,
unsigned int  stringsWidth = 45 
)
inline

Definition at line 952 of file Utils.h.

953  {
954  const auto& jaxis = j.at( "axis" );
955  const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
956  const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
957  const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
958  const auto minValueY = jaxis[1].at( "minValue" ).get<double>();
959  const auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
960  const auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
961  const auto minValueZ = jaxis[2].at( "minValue" ).get<double>();
962  const auto maxValueZ = jaxis[2].at( "maxValue" ).get<double>();
963  const auto nBinsZ = jaxis[2].at( "nBins" ).get<unsigned int>();
964  const auto nAllEntries = j.at( "nEntries" ).get<double>();
965  // compute the various memneta
966  BinAccessor ba{ type, j };
967  double nEntries{};
968  double sumX{}, sumY{}, sumZ{};
969  double sum2X{}, sum2Y{}, sum2Z{};
970  const auto isInt = ArthTypeAccessor::is_integral( type );
971  const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, isInt );
972  const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, isInt );
973  const details::BinAvValue zBinAv( minValueZ, maxValueZ, nBinsZ, isInt );
974  for ( unsigned int nz = 1; nz <= nBinsZ; ++nz ) {
975  const auto offsetz = nz * ( nBinsY + 2 );
976  for ( unsigned int ny = 1; ny <= nBinsY; ++ny ) {
977  const auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
978  for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
979  const double binXValue = xBinAv( nx );
980  const double binYValue = yBinAv( ny );
981  const double binZValue = zBinAv( nz );
982  const auto n = ba[offset + nx];
983  nEntries += n;
984  sumX += n * binXValue;
985  sum2X += n * binXValue * binXValue;
986  sumY += n * binYValue;
987  sum2Y += n * binYValue * binYValue;
988  sumZ += n * binZValue;
989  sum2Z += n * binZValue * binZValue;
990  }
991  }
992  }
993  const double meanX = fabs( nEntries ) > 0 ? sumX / nEntries : 0.0;
994  const double stddevX =
995  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
996  const double meanY = fabs( nEntries ) > 0 ? sumY / nEntries : 0.0;
997  const double stddevY =
998  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
999  const double meanZ = fabs( nEntries ) > 0 ? sumZ / nEntries : 0.0;
1000  const double stddevZ =
1001  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2Z - sumZ * ( sumZ / nEntries ) ) / nEntries ) : 0.0;
1002  // print
1003  const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
1004  return fmt::format( fmt::runtime( detail::histo3DFormatting ), detail::formatName( name, stringsWidth ),
1005  stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY,
1006  stddevY, meanZ, stddevZ );
1007  }

◆ printProfileHisto1D()

template<Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full, typename Arithmetic = double>
std::string Gaudi::Histograming::Sink::printProfileHisto1D ( std::string_view  name,
Gaudi::Monitoring::Hub::Entity const &  ent,
unsigned int  stringsWidth = 45 
)

Definition at line 655 of file Utils.h.

656  {
657  // Type to use for internal calculation. Use double to avoid precision issues across different builds.
658  using FPType = double;
659  // get original histogram from the Entity
660  auto const& gaudiHisto =
662  // compute min and max values, we actually display the axis limits
663  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
664  const FPType minValueX = gaudiAxisX.minValue();
665  const FPType maxValueX = gaudiAxisX.maxValue();
666  const unsigned int nBinsX = gaudiAxisX.numBins();
667  // Compute fist and second momenta for normal dimenstion
668  // Compute 1st and 2nd momenta for the profile dimension
669  unsigned int nEntries{ 0 }, nAllEntries{ 0 };
670  FPType totalSumW{ 0 };
671  FPType sumX{ 0 }, sum2X{ 0 }, sum3X{ 0 }, sum4X{ 0 };
672  const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, std::is_integral_v<Arithmetic> );
673  for ( unsigned int nx = 0; nx <= nBinsX + 1; ++nx ) {
674  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx );
675  auto const& [nent, sumw] = tmp;
676  nAllEntries += nent;
677  if ( nx > 0 && nx <= nBinsX ) {
678  const FPType binXValue = xBinAv( nx );
679  nEntries += nent;
680  totalSumW += sumw;
681  auto val = binXValue * sumw;
682  sumX += val;
683  val *= binXValue;
684  sum2X += val;
685  val *= binXValue;
686  sum3X += val;
687  val *= binXValue;
688  sum4X += val;
689  }
690  }
691  const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
692  if ( nEntries == 0 || !( fabs( totalSumW ) > 0 ) ) { return ""; }
693  const FPType meanX = sumX / totalSumW;
694  const FPType sigmaX2 = ( sum2X / totalSumW ) - std::pow( meanX, 2 );
695  const FPType stddevX = detail::sqrt_or_zero( sigmaX2 );
696  const FPType EX3 = sum3X / totalSumW;
697  const FPType A = sigmaX2 * stddevX;
698  const FPType skewnessX = ( fabs( A ) > 0.0 ? ( EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX ) / A : 0.0 );
699  const FPType B = sigmaX2 * sigmaX2;
700  const FPType kurtosisX =
701  ( fabs( B ) > 0.0 && fabs( A ) > 0.0
702  ? ( sum4X / totalSumW - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) ) ) / B
703  : 3.0 );
704  // print
705  return fmt::format( fmt::runtime( detail::histo1DFormatting ), detail::formatName( name, stringsWidth ),
706  stringsWidth, stringsWidth, ftitle, stringsWidth, detail::IntWithFixedWidth{ nEntries }, meanX,
707  stddevX, skewnessX, kurtosisX - FPType{ 3.0 } );
708  }

◆ printProfileHisto2D()

template<Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full, typename Arithmetic = double>
std::string Gaudi::Histograming::Sink::printProfileHisto2D ( std::string_view  name,
Gaudi::Monitoring::Hub::Entity const &  ent,
unsigned int  stringsWidth = 45 
)

Definition at line 712 of file Utils.h.

713  {
714  // Type to use for internal calculation. Use double to avoid precision issues across different builds.
715  using FPType = double;
716  // get original histogram from the Entity
717  auto const& gaudiHisto =
719  // compute min and max values, we actually display the axis limits
720  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
721  const FPType minValueX = gaudiAxisX.minValue();
722  const FPType maxValueX = gaudiAxisX.maxValue();
723  const unsigned int nBinsX = gaudiAxisX.numBins();
724  auto const& gaudiAxisY = gaudiHisto.template axis<1>();
725  const FPType minValueY = gaudiAxisY.minValue();
726  const FPType maxValueY = gaudiAxisY.maxValue();
727  const unsigned int nBinsY = gaudiAxisY.numBins();
728  // Compute fist and second momenta for normal dimenstion
729  // Compute 1st and 2nd momenta for the profile dimension
730  FPType nEntries{ 0 }, nAllEntries{ 0 };
731  FPType totalSumW{ 0 };
732  FPType sumX{ 0 }, sumY{ 0 };
733  FPType sum2X{ 0 }, sum2Y{ 0 };
734  const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, std::is_integral_v<Arithmetic> );
735  const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, std::is_integral_v<Arithmetic> );
736  for ( unsigned int ny = 0; ny <= nBinsY + 1; ++ny ) {
737  const auto offset = ny * ( nBinsX + 2 );
738  for ( unsigned int nx = 0; nx <= nBinsX + 1; ++nx ) {
739  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
740  auto const& [nent, sumw] = tmp;
741  nAllEntries += nent;
742  if ( nx > 0 && ny > 0 && nx <= nBinsX && ny <= nBinsY ) {
743  const FPType binXValue = xBinAv( nx );
744  const FPType binYValue = yBinAv( ny );
745  nEntries += nent;
746  totalSumW += sumw;
747  sumX += binXValue * sumw;
748  sum2X += binXValue * binXValue * sumw;
749  sumY += binYValue * sumw;
750  sum2Y += binYValue * binYValue * sumw;
751  }
752  }
753  }
754  const FPType meanX = fabs( totalSumW ) > 0 ? sumX / totalSumW : 0.0;
755  const FPType stddevX =
756  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / totalSumW ) ) / totalSumW ) : 0.0;
757  const FPType meanY = fabs( totalSumW ) > 0 ? sumY / totalSumW : 0.0;
758  const FPType stddevY =
759  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / totalSumW ) ) / totalSumW ) : 0.0;
760  // print
761  const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
762  return fmt::format( fmt::runtime( detail::histo2DFormatting ), detail::formatName( name, stringsWidth ),
763  stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY,
764  stddevY );
765  }

◆ printProfileHisto3D()

template<Gaudi::Accumulators::atomicity Atomicity = Gaudi::Accumulators::atomicity::full, typename Arithmetic = double>
std::string Gaudi::Histograming::Sink::printProfileHisto3D ( std::string_view  name,
Gaudi::Monitoring::Hub::Entity const &  ent,
unsigned int  stringsWidth = 45 
)

Definition at line 769 of file Utils.h.

770  {
771  // Type to use for internal calculation. Use double to avoid precision issues across different builds.
772  using FPType = double;
773  // get original histogram from the Entity
774  auto const& gaudiHisto =
776  // compute min and max values, we actually display the axis limits
777  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
778  const FPType minValueX = gaudiAxisX.minValue();
779  const FPType maxValueX = gaudiAxisX.maxValue();
780  const unsigned int nBinsX = gaudiAxisX.numBins();
781  auto const& gaudiAxisY = gaudiHisto.template axis<1>();
782  const FPType minValueY = gaudiAxisY.minValue();
783  const FPType maxValueY = gaudiAxisY.maxValue();
784  const unsigned int nBinsY = gaudiAxisY.numBins();
785  auto const& gaudiAxisZ = gaudiHisto.template axis<2>();
786  const FPType minValueZ = gaudiAxisZ.minValue();
787  const FPType maxValueZ = gaudiAxisZ.maxValue();
788  const unsigned int nBinsZ = gaudiAxisZ.numBins();
789  // Compute fist and second momenta for normal dimenstion
790  // Compute 1st and 2nd momenta for the profile dimension
791  FPType nEntries{ 0 }, nAllEntries{ 0 };
792  FPType totalSumW{};
793  FPType sumX{ 0 }, sumY{ 0 }, sumZ{ 0 };
794  FPType sum2X{ 0 }, sum2Y{ 0 }, sum2Z{ 0 };
795  const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, std::is_integral_v<Arithmetic> );
796  const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, std::is_integral_v<Arithmetic> );
797  const details::BinAvValue zBinAv( minValueZ, maxValueZ, nBinsZ, std::is_integral_v<Arithmetic> );
798  for ( unsigned int nz = 0; nz <= nBinsZ + 1; ++nz ) {
799  const auto offsetz = nz * ( nBinsY + 2 );
800  for ( unsigned int ny = 0; ny <= nBinsY; ++ny ) {
801  const auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
802  for ( unsigned int nx = 0; nx <= nBinsX; ++nx ) {
803  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
804  auto const& [nent, sumw] = tmp;
805  nAllEntries += nent;
806  if ( nx > 0 && ny > 0 && nz > 0 && nx <= nBinsX && ny <= nBinsY && nz <= nBinsZ ) {
807  const FPType binXValue = xBinAv( nx );
808  const FPType binYValue = yBinAv( ny );
809  const FPType binZValue = zBinAv( nz );
810  nEntries += nent;
811  totalSumW += sumw;
812  sumX += binXValue * sumw;
813  sum2X += binXValue * binXValue * sumw;
814  sumY += binYValue * sumw;
815  sum2Y += binYValue * binYValue * sumw;
816  sumZ += binZValue * sumw;
817  sum2Z += binZValue * binZValue * sumw;
818  }
819  }
820  }
821  }
822  const FPType meanX = fabs( totalSumW ) > 0 ? sumX / totalSumW : 0.0;
823  const FPType stddevX =
824  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / totalSumW ) ) / totalSumW ) : 0.0;
825  const FPType meanY = fabs( totalSumW ) > 0 ? sumY / totalSumW : 0.0;
826  const FPType stddevY =
827  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / totalSumW ) ) / totalSumW ) : 0.0;
828  const FPType meanZ = fabs( totalSumW ) > 0 ? sumZ / totalSumW : 0.0;
829  const FPType stddevZ =
830  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2Z - sumZ * ( sumZ / totalSumW ) ) / totalSumW ) : 0.0;
831  // print
832  const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
833  return fmt::format( fmt::runtime( detail::histo3DFormatting ), detail::formatName( name, stringsWidth ),
834  stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY,
835  stddevY, meanZ, stddevZ );
836  }

◆ profileHisto1DToRoot()

template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper<TProfile> Gaudi::Histograming::Sink::profileHisto1DToRoot ( std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Direct conversion of 1D histograms from Gaudi to ROOT format.

Definition at line 490 of file Utils.h.

490  {
491  // get original histogram from the Entity
492  auto const& gaudiHisto =
494  // convert to Root
495  auto const& gaudiAxis = gaudiHisto.template axis<0>();
496  details::ProfileWrapper<TProfile> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiAxis.numBins(),
497  gaudiAxis.minValue(), gaudiAxis.maxValue() };
498  if ( !gaudiAxis.labels().empty() ) {
499  auto& axis = *histo.GetXaxis();
500  for ( unsigned int i = 0; i < gaudiAxis.labels().size(); i++ ) {
501  axis.SetBinLabel( i + 1, gaudiAxis.labels()[i].c_str() );
502  }
503  }
504  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
505  auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
506  auto const& [nent, sumw] = tmp;
507  histo.SetBinContent( i, sumw );
508  histo.setBinNEntries( i, nent );
509  histo.setBinW2( i, sumw2 );
510  }
511  unsigned long totNEntries{ 0 };
512  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
513  histo.SetEntries( totNEntries );
514  return histo;
515  }

◆ profileHisto2DToRoot()

template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper<TProfile2D> Gaudi::Histograming::Sink::profileHisto2DToRoot ( std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Direct conversion of 2D histograms from Gaudi to ROOT format.

Definition at line 519 of file Utils.h.

519  {
520  // get original histogram from the Entity
521  auto const& gaudiHisto =
523  // convert to Root
524  auto const& gaudiXAxis = gaudiHisto.template axis<0>();
525  auto const& gaudiYAxis = gaudiHisto.template axis<1>();
526  details::ProfileWrapper<TProfile2D> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiXAxis.numBins(),
527  gaudiXAxis.minValue(), gaudiXAxis.maxValue(), gaudiYAxis.numBins(),
528  gaudiYAxis.minValue(), gaudiYAxis.maxValue() };
529  if ( !gaudiXAxis.labels().empty() ) {
530  auto& axis = *histo.GetXaxis();
531  for ( unsigned int i = 0; i < gaudiXAxis.labels().size(); i++ ) {
532  axis.SetBinLabel( i + 1, gaudiXAxis.labels()[i].c_str() );
533  }
534  }
535  if ( !gaudiYAxis.labels().empty() ) {
536  auto& axis = *histo.GetYaxis();
537  for ( unsigned int i = 0; i < gaudiYAxis.labels().size(); i++ ) {
538  axis.SetBinLabel( i + 1, gaudiYAxis.labels()[i].c_str() );
539  }
540  }
541  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
542  auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
543  auto const& [nent, sumw] = tmp;
544  histo.SetBinContent( i, sumw );
545  histo.setBinNEntries( i, nent );
546  histo.setBinW2( i, sumw2 );
547  }
548  unsigned long totNEntries{ 0 };
549  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
550  histo.SetEntries( totNEntries );
551  return histo;
552  }

◆ profileHisto3DToRoot()

template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper<TProfile3D> Gaudi::Histograming::Sink::profileHisto3DToRoot ( std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Direct conversion of 3D histograms from Gaudi to ROOT format.

Definition at line 556 of file Utils.h.

556  {
557  // get original histogram from the Entity
558  auto const& gaudiHisto =
560  // convert to Root
561  auto const& gaudiXAxis = gaudiHisto.template axis<0>();
562  auto const& gaudiYAxis = gaudiHisto.template axis<1>();
563  auto const& gaudiZAxis = gaudiHisto.template axis<2>();
564  details::ProfileWrapper<TProfile3D> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiXAxis.numBins(),
565  gaudiXAxis.minValue(), gaudiXAxis.maxValue(), gaudiYAxis.numBins(),
566  gaudiYAxis.minValue(), gaudiYAxis.maxValue(), gaudiZAxis.numBins(),
567  gaudiZAxis.minValue(), gaudiZAxis.maxValue() };
568  if ( !gaudiXAxis.labels().empty() ) {
569  auto& axis = *histo.GetXaxis();
570  for ( unsigned int i = 0; i < gaudiXAxis.labels().size(); i++ ) {
571  axis.SetBinLabel( i + 1, gaudiXAxis.labels()[i].c_str() );
572  }
573  }
574  if ( !gaudiYAxis.labels().empty() ) {
575  auto& axis = *histo.GetYaxis();
576  for ( unsigned int i = 0; i < gaudiYAxis.labels().size(); i++ ) {
577  axis.SetBinLabel( i + 1, gaudiYAxis.labels()[i].c_str() );
578  }
579  }
580  if ( !gaudiZAxis.labels().empty() ) {
581  auto& axis = *histo.GetZaxis();
582  for ( unsigned int i = 0; i < gaudiZAxis.labels().size(); i++ ) {
583  axis.SetBinLabel( i + 1, gaudiZAxis.labels()[i].c_str() );
584  }
585  }
586  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
587  auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
588  auto const& [nent, sumw] = tmp;
589  histo.SetBinContent( i, sumw );
590  histo.setBinNEntries( i, nent );
591  histo.setBinW2( i, sumw2 );
592  }
593  unsigned long totNEntries{ 0 };
594  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
595  histo.SetEntries( totNEntries );
596  return histo;
597  }

◆ rootHistogramTojson()

template<typename Histo >
nlohmann::json Gaudi::Histograming::Sink::rootHistogramTojson ( Histo const &  )

generic function to convert a ROOT Histogram to json

essentially used for backward compatibility of old HistogramService with MonitoringHub

◆ saveProfileHisto()

template<unsigned int N, Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
void Gaudi::Histograming::Sink::saveProfileHisto ( TFile &  file,
std::string  dir,
std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Definition at line 601 of file Utils.h.

601  {
602  // fix name and dir if needed
604  // Change to the proper directory in the ROOT file
605  auto previousDir = details::changeDir( file, dir );
606  // write to file
607  if constexpr ( N == 1 ) {
608  profileHisto1DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
609  } else if constexpr ( N == 2 ) {
610  profileHisto2DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
611  } else if constexpr ( N == 3 ) {
612  profileHisto3DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
613  }
614  // switch back to the previous directory
615  previousDir->cd();
616  }

◆ saveRootHisto() [1/2]

template<typename Traits >
void Gaudi::Histograming::Sink::saveRootHisto ( TFile &  file,
std::string  dir,
std::string  name,
nlohmann::json const &  j 
)

generic method to save histograms to files, based on Traits

Definition at line 472 of file Utils.h.

472  {
473  // get the Root histogram
474  auto [histo, newDir] = jsonToRootHistogram<Traits>( dir, name, j );
475  // Change to the proper directory in the ROOT file
476  auto previousDir = details::changeDir( file, newDir );
477  // write to file
478  histo.Write();
479  // switch back to the previous directory
480  previousDir->cd();
481  }

◆ saveRootHisto() [2/2]

template<unsigned int N, bool isProfile, typename ROOTHisto >
void Gaudi::Histograming::Sink::saveRootHisto ( TFile &  file,
std::string  dir,
std::string  name,
nlohmann::json const &  j 
)

generic method to save regular histograms to files

Can be used in most cases as the handler function to register into Sink::Base contains all the boiler plate code and redirects specific code to the adapted Traits template

Definition at line 484 of file Utils.h.

484  {
485  saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
486  }
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:23
IOTest.N
N
Definition: IOTest.py:112
std::fabs
T fabs(T... args)
std::move
T move(T... args)
Gaudi::Accumulators::HistogramingCounterBase
A base counter dealing with Histograms.
Definition: StaticHistogram.h:660
Gaudi::Histograming::Sink::details::fixNameAndDir
void fixNameAndDir(std::string &name, std::string &dir)
handles cases where name includes '/' character(s) and move needed part of it to dir.
Definition: Utils.h:188
Gaudi::Histograming::Sink::detail::histo2DFormatting
constexpr std::string_view histo2DFormatting
Definition: Utils.h:67
Gaudi::Histograming::Sink::detail::sqrt_or_zero
T sqrt_or_zero(const T x)
sqrt or zero
Definition: Utils.h:80
ProduceConsume.j
j
Definition: ProduceConsume.py:104
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Gaudi::Histograming::Sink::detail::histo3DFormatting
constexpr std::string_view histo3DFormatting
Definition: Utils.h:69
cpluginsvc.n
n
Definition: cpluginsvc.py:234
gaudirun.type
type
Definition: gaudirun.py:160
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi::Histograming::Sink::detail::formatName
std::string formatName(std::string_view name, unsigned int width)
Definition: Utils.h:55
Gaudi::Histograming::Sink::detail::formatTitle
std::string formatTitle(std::string_view title, unsigned int width)
Definition: Utils.h:48
Gaudi::Histograming::Sink::detail::histo1DFormatting
constexpr std::string_view histo1DFormatting
Definition: Utils.h:65
Gaudi::Histograming::Sink::details::changeDir
TDirectory * changeDir(TFile &file, const std::string &dir)
changes to the ROOT directory given in the current ROOT file and returns the current directory before...
Definition: Utils.h:338
std::pow
T pow(T... args)