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

460 {
461 return details::jsonToRootHistogramInternal<Traits>( dir, name, j, std::make_index_sequence<Traits::Dimension>() );
462 }
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:198

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

868 {
869 using std::abs;
870 const auto& jaxis = j.at( "axis" );
871 const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
872 const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
873 const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
874 const auto nAllEntries = j.at( "nEntries" ).get<unsigned int>();
875 // compute the various momenta
876 BinAccessor ba{ type, j };
877 double sumX{}, sum2X{}, sum3X{}, sum4X{}, nEntries{ 0 };
878 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, ArthTypeAccessor::is_integral( type ) );
879 for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
880 const double binXValue = xBinAv( nx );
881 const auto n = ba[nx];
882 nEntries += n;
883 auto val = binXValue * n;
884 sumX += val;
885 val *= binXValue;
886 sum2X += val;
887 val *= binXValue;
888 sum3X += val;
889 val *= binXValue;
890 sum4X += val;
891 }
892 const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
893 if ( !( abs( nEntries ) > 0.0 ) ) { return ""; }
894 const double meanX = sumX / nEntries;
895 const double sigmaX2 = ( sum2X / nEntries ) - std::pow( meanX, 2 );
896 const double stddevX = detail::sqrt_or_zero( sigmaX2 );
897 const double EX3 = sum3X / nEntries;
898 const double A = sigmaX2 * stddevX;
899 const double skewnessX = ( abs( A ) > 0.0 ? ( EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX ) / A : 0.0 );
900 const double B = sigmaX2 * sigmaX2;
901 const double kurtosisX =
902 ( abs( B ) > 0.0 && abs( A ) > 0.0
903 ? ( sum4X / nEntries - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) ) ) / B
904 : 3.0 );
905 // print
906 return fmt::format( fmt::runtime( detail::histo1DFormatting ), detail::formatName( name, stringsWidth ),
907 stringsWidth, stringsWidth, ftitle, stringsWidth, detail::IntWithFixedWidth{ nAllEntries },
908 meanX, stddevX, skewnessX, kurtosisX - 3.0 );
909 }
constexpr std::string_view histo1DFormatting
Definition Utils.h:58
std::string formatTitle(std::string_view title, unsigned int width)
Definition Utils.h:41
T sqrt_or_zero(const T x)
sqrt or zero
Definition Utils.h:73
std::string formatName(std::string_view name, unsigned int width)
Definition Utils.h:48
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:859
helper struct to print integers with fixed width
Definition Utils.h:67

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

594 {
595 // fix name and dir if needed
596 details::fixNameAndDir( name, dir );
597 // Change to the proper directory in the ROOT file
598 auto previousDir = details::changeDir( file, dir );
599 // write to file
600 if constexpr ( N == 1 ) {
602 } else if constexpr ( N == 2 ) {
604 } else if constexpr ( N == 3 ) {
606 }
607 // switch back to the previous directory
608 previousDir->cd();
609 }
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:181
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:331
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:512
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:483
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:549

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

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

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

477 {
478 saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
479 }
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:465