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

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

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

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

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

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

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

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

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

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

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

◆ 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::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
std::abs
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition: ParticleID.h:191
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)