The Gaudi Framework  master (da3d77e1)
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 456 of file Utils.h.

457  {
458  return details::jsonToRootHistogramInternal<Traits>( dir, name, j, std::make_index_sequence<Traits::Dimension>() );
459  }

◆ 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 853 of file Utils.h.

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

◆ 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 896 of file Utils.h.

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

◆ 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 939 of file Utils.h.

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

◆ 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 645 of file Utils.h.

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

◆ 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 702 of file Utils.h.

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

◆ 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 758 of file Utils.h.

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

◆ 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 480 of file Utils.h.

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

◆ 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 509 of file Utils.h.

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

◆ 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 546 of file Utils.h.

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

◆ 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 591 of file Utils.h.

591  {
592  // fix name and dir if needed
594  // Change to the proper directory in the ROOT file
595  auto previousDir = details::changeDir( file, dir );
596  // write to file
597  if constexpr ( N == 1 ) {
598  profileHisto1DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
599  } else if constexpr ( N == 2 ) {
600  profileHisto2DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
601  } else if constexpr ( N == 3 ) {
602  profileHisto3DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
603  }
604  // switch back to the previous directory
605  previousDir->cd();
606  }

◆ 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 462 of file Utils.h.

462  {
463  // get the Root histogram
464  auto [histo, newDir] = jsonToRootHistogram<Traits>( dir, name, j );
465  // Change to the proper directory in the ROOT file
466  auto previousDir = details::changeDir( file, newDir );
467  // write to file
468  histo.Write();
469  // switch back to the previous directory
470  previousDir->cd();
471  }

◆ 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 474 of file Utils.h.

474  {
475  saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
476  }
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:653
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:178
Gaudi::Histograming::Sink::detail::histo2DFormatting
constexpr std::string_view histo2DFormatting
Definition: Utils.h:57
Gaudi::Histograming::Sink::detail::sqrt_or_zero
T sqrt_or_zero(const T x)
sqrt or zero
Definition: Utils.h:70
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:59
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::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:55
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:328
std::pow
T pow(T... args)