The Gaudi Framework  master (e68eea06)
Loading...
Searching...
No Matches
Gaudi::Histograming::Sink Namespace Reference

Namespaces

namespace  detail
 
namespace  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::string > jsonToRootHistogram (std::string &dir, std::string &name, nlohmann::json const &j)
 generic function to convert json to a ROOT Histogram
 
template<typename Histo>
nlohmann::json rootHistogramTojson (Histo const &)
 generic function to convert a ROOT Histogram to json
 
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
 
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
 
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.
 
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.
 
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.
 
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 453 of file Utils.h.

454 {
455 return details::jsonToRootHistogramInternal<Traits>( dir, name, j, std::make_index_sequence<Traits::Dimension>() );
456 }
std::tuple< typename Traits::Histo, std::string > jsonToRootHistogramInternal(std::string &dir, std::string &name, nlohmann::json const &j, std::index_sequence< index... >)
generic function to convert json to a ROOT Histogram - internal implementation
Definition Utils.h:196

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

862 {
863 using std::abs;
864 const auto& jaxis = j.at( "axis" );
865 const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
866 const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
867 const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
868 const auto nAllEntries = j.at( "nEntries" ).get<unsigned int>();
869 // compute the various momenta
870 BinAccessor ba{ type, j };
871 double sumX{}, sum2X{}, sum3X{}, sum4X{}, nEntries{ 0 };
872 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, ArthTypeAccessor::is_integral( type ) );
873 for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
874 const double binXValue = xBinAv( nx );
875 const auto n = ba[nx];
876 nEntries += n;
877 auto val = binXValue * n;
878 sumX += val;
879 val *= binXValue;
880 sum2X += val;
881 val *= binXValue;
882 sum3X += val;
883 val *= binXValue;
884 sum4X += val;
885 }
886 const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
887 if ( !( abs( nEntries ) > 0.0 ) ) { return ""; }
888 const double meanX = sumX / nEntries;
889 const double sigmaX2 = ( sum2X / nEntries ) - std::pow( meanX, 2 );
890 const double stddevX = detail::sqrt_or_zero( sigmaX2 );
891 const double EX3 = sum3X / nEntries;
892 const double A = sigmaX2 * stddevX;
893 const double skewnessX = ( abs( A ) > 0.0 ? ( EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX ) / A : 0.0 );
894 const double B = sigmaX2 * sigmaX2;
895 const double kurtosisX =
896 ( abs( B ) > 0.0 && abs( A ) > 0.0
897 ? ( sum4X / nEntries - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) ) ) / B
898 : 3.0 );
899 // print
900 return fmt::format( fmt::runtime( detail::histo1DFormatting ), detail::formatName( name, stringsWidth ),
901 stringsWidth, stringsWidth, ftitle, stringsWidth, detail::IntWithFixedWidth{ nAllEntries },
902 meanX, stddevX, skewnessX, kurtosisX - 3.0 );
903 }
constexpr std::string_view histo1DFormatting
Definition Utils.h:56
std::string formatTitle(std::string_view title, unsigned int width)
Definition Utils.h:39
T sqrt_or_zero(const T x)
sqrt or zero
Definition Utils.h:71
std::string formatName(std::string_view name, unsigned int width)
Definition Utils.h:46
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition ParticleID.h:191
static bool is_integral(const std::string_view type)
Definition Utils.h:853
helper struct to print integers with fixed width
Definition Utils.h:65

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

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

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

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

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

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

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

702 {
703 using std::abs;
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 const auto sumw_abs = abs( sumw );
737 totalSumW += sumw_abs;
738 sumX += binXValue * sumw_abs;
739 sum2X += binXValue * binXValue * sumw_abs;
740 sumY += binYValue * sumw_abs;
741 sum2Y += binYValue * binYValue * sumw_abs;
742 }
743 }
744 }
745 const FPType meanX = abs( totalSumW ) > 0 ? sumX / totalSumW : 0.0;
746 const FPType stddevX =
747 abs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / totalSumW ) ) / totalSumW ) : 0.0;
748 const FPType meanY = abs( totalSumW ) > 0 ? sumY / totalSumW : 0.0;
749 const FPType stddevY =
750 abs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / totalSumW ) ) / totalSumW ) : 0.0;
751 // print
752 const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
753 return fmt::format( fmt::runtime( detail::histo2DFormatting ), detail::formatName( name, stringsWidth ),
754 stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY,
755 stddevY );
756 }

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

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

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

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

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

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

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

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

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

588 {
589 // fix name and dir if needed
590 details::fixNameAndDir( name, dir );
591 // Change to the proper directory in the ROOT file
592 auto previousDir = details::changeDir( file, dir );
593 // write to file
594 if constexpr ( N == 1 ) {
596 } else if constexpr ( N == 2 ) {
598 } else if constexpr ( N == 3 ) {
600 }
601 // switch back to the previous directory
602 previousDir->cd();
603 }
TDirectory * changeDir(TFile &file, std::string_view dir)
changes to the ROOT directory given in the current ROOT file and returns the current directory before...
Definition Utils.h:329
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:179
details::ProfileWrapper< TProfile2D > profileHisto2DToRoot(std::string name, Monitoring::Hub::Entity const &ent)
Direct conversion of 2D histograms from Gaudi to ROOT format.
Definition Utils.h:506
details::ProfileWrapper< TProfile > profileHisto1DToRoot(std::string name, Monitoring::Hub::Entity const &ent)
Direct conversion of 1D histograms from Gaudi to ROOT format.
Definition Utils.h:477
details::ProfileWrapper< TProfile3D > profileHisto3DToRoot(std::string name, Monitoring::Hub::Entity const &ent)
Direct conversion of 3D histograms from Gaudi to ROOT format.
Definition Utils.h:543

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

459 {
460 // get the Root histogram
461 auto [histo, newDir] = jsonToRootHistogram<Traits>( dir, name, j );
462 // Change to the proper directory in the ROOT file
463 auto previousDir = details::changeDir( file, newDir );
464 // write to file
465 histo.Write();
466 // switch back to the previous directory
467 previousDir->cd();
468 }
std::tuple< typename Traits::Histo, std::string > jsonToRootHistogram(std::string &dir, std::string &name, nlohmann::json const &j)
generic function to convert json to a ROOT Histogram
Definition Utils.h:453

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

471 {
472 saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
473 }
void saveRootHisto(TFile &file, std::string dir, std::string name, nlohmann::json const &j)
generic method to save histograms to files, based on Traits
Definition Utils.h:459