The Gaudi Framework  master (9f3f8895)
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 522 of file Utils.h.

523 {
524 return details::jsonToRootHistogramInternal<Traits>( dir, name, j, std::make_index_sequence<Traits::Dimension>() );
525 }
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:265

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

878 {
879 using std::abs;
880 const auto& jaxis = j.at( "axis" );
881 const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
882 const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
883 const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
884 const auto nAllEntries = j.at( "nEntries" ).get<unsigned int>();
885 // compute the various momenta
886 BinAccessor ba{ type, j };
887 double nEntries{ 0 };
888 detail::WeightedMoments momentsX;
889 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, ArthTypeAccessor::is_integral( type ) );
890 for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
891 const auto n = ba[nx];
892 nEntries += n;
893 momentsX.add( xBinAv( nx ), n );
894 }
895 const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
896 if ( !( abs( nEntries ) > 0.0 ) ) { return ""; }
897 // print
898 return fmt::format( fmt::runtime( detail::histo1DFormatting ), detail::formatName( name, stringsWidth ),
899 stringsWidth, stringsWidth, ftitle, stringsWidth, detail::IntWithFixedWidth{ nAllEntries },
900 momentsX.mean(), momentsX.stddev(), momentsX.skewness(), momentsX.kurtosis() );
901 }
constexpr std::string_view histo1DFormatting
Definition Utils.h:56
std::string formatTitle(std::string_view title, unsigned int width)
Definition Utils.h:39
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:869
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 903 of file Utils.h.

904 {
905 using std::abs;
906 const auto& jaxis = j.at( "axis" );
907 const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
908 const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
909 const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
910 const auto minValueY = jaxis[1].at( "minValue" ).get<double>();
911 const auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
912 const auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
913 const auto nAllEntries = j.at( "nEntries" ).get<double>();
914 // compute the various memneta
915 BinAccessor ba{ type, j };
916 double nEntries{};
917 detail::WeightedMoments momentsX, momentsY;
918 const auto isInt = ArthTypeAccessor::is_integral( type );
919 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, isInt );
920 const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, isInt );
921 for ( unsigned int ny = 1; ny <= nBinsY; ++ny ) {
922 const auto offset = ny * ( nBinsX + 2 );
923 for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
924 const auto n = ba[offset + nx];
925 nEntries += n;
926 momentsX.add( xBinAv( nx ), n );
927 momentsY.add( yBinAv( ny ), n );
928 }
929 }
930 // print
931 const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
932 return fmt::format( fmt::runtime( detail::histo2DFormatting ), detail::formatName( name, stringsWidth ),
933 stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, momentsX.mean(),
934 momentsX.stddev(), momentsY.mean(), momentsY.stddev() );
935 }
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 937 of file Utils.h.

938 {
939 using std::abs;
940 const auto& jaxis = j.at( "axis" );
941 const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
942 const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
943 const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
944 const auto minValueY = jaxis[1].at( "minValue" ).get<double>();
945 const auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
946 const auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
947 const auto minValueZ = jaxis[2].at( "minValue" ).get<double>();
948 const auto maxValueZ = jaxis[2].at( "maxValue" ).get<double>();
949 const auto nBinsZ = jaxis[2].at( "nBins" ).get<unsigned int>();
950 const auto nAllEntries = j.at( "nEntries" ).get<double>();
951 // compute the various memneta
952 BinAccessor ba{ type, j };
953 double nEntries{};
954 detail::WeightedMoments momentsX, momentsY, momentsZ;
955 const auto isInt = ArthTypeAccessor::is_integral( type );
956 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, isInt );
957 const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, isInt );
958 const details::BinAvValue zBinAv( minValueZ, maxValueZ, nBinsZ, isInt );
959 for ( unsigned int nz = 1; nz <= nBinsZ; ++nz ) {
960 const auto offsetz = nz * ( nBinsY + 2 );
961 for ( unsigned int ny = 1; ny <= nBinsY; ++ny ) {
962 const auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
963 for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
964 const auto n = ba[offset + nx];
965 nEntries += n;
966 momentsX.add( xBinAv( nx ), n );
967 momentsY.add( yBinAv( ny ), n );
968 momentsZ.add( zBinAv( nz ), n );
969 }
970 }
971 }
972 // print
973 const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
974 return fmt::format( fmt::runtime( detail::histo3DFormatting ), detail::formatName( name, stringsWidth ),
975 stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, momentsX.mean(),
976 momentsX.stddev(), momentsY.mean(), momentsY.stddev(), momentsZ.mean(), momentsZ.stddev() );
977 }
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 711 of file Utils.h.

712 {
713 using std::abs;
714 // Type to use for internal calculation. Use double to avoid precision issues across different builds.
715 using FPType = double;
716 // get original histogram from the Entity
717 auto const& gaudiHisto =
719 // compute min and max values, we actually display the axis limits
720 auto const& gaudiAxisX = gaudiHisto.template axis<0>();
721 const FPType minValueX = gaudiAxisX.minValue();
722 const FPType maxValueX = gaudiAxisX.maxValue();
723 const unsigned int nBinsX = gaudiAxisX.numBins();
724 // Compute fist and second momenta for normal dimension
725 // Compute 1st and 2nd momenta for the profile dimension
726 unsigned int nEntries{ 0 }, nAllEntries{ 0 };
727 detail::WeightedMoments momentsX;
728 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, std::is_integral_v<Arithmetic> );
729 for ( unsigned int nx = 0; nx <= nBinsX + 1; ++nx ) {
730 auto const& [tmp, sumw2] = gaudiHisto.binValue( nx );
731 auto const& [nent, sumw] = tmp;
732 nAllEntries += nent;
733 if ( nx > 0 && nx <= nBinsX ) {
734 nEntries += nent;
735 momentsX.add( xBinAv( nx ), abs( sumw ) );
736 }
737 }
738 const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
739 if ( ( nEntries == 0 ) || !( abs( momentsX.sumW() ) > 0 ) ) { return ""; }
740 // print
741 return fmt::format( fmt::runtime( detail::histo1DFormatting ), detail::formatName( name, stringsWidth ),
742 stringsWidth, stringsWidth, ftitle, stringsWidth, detail::IntWithFixedWidth{ nEntries },
743 momentsX.mean(), momentsX.stddev(), momentsX.skewness(), momentsX.kurtosis() );
744 }
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 748 of file Utils.h.

749 {
750 using std::abs;
751 // Type to use for internal calculation. Use double to avoid precision issues across different builds.
752 using FPType = double;
753 // get original histogram from the Entity
754 auto const& gaudiHisto =
756 // compute min and max values, we actually display the axis limits
757 auto const& gaudiAxisX = gaudiHisto.template axis<0>();
758 const FPType minValueX = gaudiAxisX.minValue();
759 const FPType maxValueX = gaudiAxisX.maxValue();
760 const unsigned int nBinsX = gaudiAxisX.numBins();
761 auto const& gaudiAxisY = gaudiHisto.template axis<1>();
762 const FPType minValueY = gaudiAxisY.minValue();
763 const FPType maxValueY = gaudiAxisY.maxValue();
764 const unsigned int nBinsY = gaudiAxisY.numBins();
765 // Compute fist and second momenta for normal dimenstion
766 // Compute 1st and 2nd momenta for the profile dimension
767 FPType nEntries{ 0 }, nAllEntries{ 0 };
768 detail::WeightedMoments momentsX, momentsY;
769 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, std::is_integral_v<Arithmetic> );
770 const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, std::is_integral_v<Arithmetic> );
771 for ( unsigned int ny = 0; ny <= nBinsY + 1; ++ny ) {
772 const auto offset = ny * ( nBinsX + 2 );
773 for ( unsigned int nx = 0; nx <= nBinsX + 1; ++nx ) {
774 auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
775 auto const& [nent, sumw] = tmp;
776 nAllEntries += nent;
777 if ( nx > 0 && ny > 0 && nx <= nBinsX && ny <= nBinsY ) {
778 nEntries += nent;
779 const auto sumw_abs = abs( sumw );
780 momentsX.add( xBinAv( nx ), sumw_abs );
781 momentsY.add( yBinAv( ny ), sumw_abs );
782 }
783 }
784 }
785 // print
786 const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
787 return fmt::format( fmt::runtime( detail::histo2DFormatting ), detail::formatName( name, stringsWidth ),
788 stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, momentsX.mean(),
789 momentsX.stddev(), momentsY.mean(), momentsY.stddev() );
790 }

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

795 {
796 using std::abs;
797 // Type to use for internal calculation. Use double to avoid precision issues across different builds.
798 using FPType = double;
799 // get original histogram from the Entity
800 auto const& gaudiHisto =
802 // compute min and max values, we actually display the axis limits
803 auto const& gaudiAxisX = gaudiHisto.template axis<0>();
804 const FPType minValueX = gaudiAxisX.minValue();
805 const FPType maxValueX = gaudiAxisX.maxValue();
806 const unsigned int nBinsX = gaudiAxisX.numBins();
807 auto const& gaudiAxisY = gaudiHisto.template axis<1>();
808 const FPType minValueY = gaudiAxisY.minValue();
809 const FPType maxValueY = gaudiAxisY.maxValue();
810 const unsigned int nBinsY = gaudiAxisY.numBins();
811 auto const& gaudiAxisZ = gaudiHisto.template axis<2>();
812 const FPType minValueZ = gaudiAxisZ.minValue();
813 const FPType maxValueZ = gaudiAxisZ.maxValue();
814 const unsigned int nBinsZ = gaudiAxisZ.numBins();
815 // Compute fist and second momenta for normal dimenstion
816 // Compute 1st and 2nd momenta for the profile dimension
817 FPType nEntries{ 0 }, nAllEntries{ 0 };
818 detail::WeightedMoments momentsX, momentsY, momentsZ;
819 const details::BinAvValue xBinAv( minValueX, maxValueX, nBinsX, std::is_integral_v<Arithmetic> );
820 const details::BinAvValue yBinAv( minValueY, maxValueY, nBinsY, std::is_integral_v<Arithmetic> );
821 const details::BinAvValue zBinAv( minValueZ, maxValueZ, nBinsZ, std::is_integral_v<Arithmetic> );
822 for ( unsigned int nz = 0; nz <= nBinsZ + 1; ++nz ) {
823 const auto offsetz = nz * ( nBinsY + 2 );
824 for ( unsigned int ny = 0; ny <= nBinsY; ++ny ) {
825 const auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
826 for ( unsigned int nx = 0; nx <= nBinsX; ++nx ) {
827 auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
828 auto const& [nent, sumw] = tmp;
829 nAllEntries += nent;
830 if ( nx > 0 && ny > 0 && nz > 0 && nx <= nBinsX && ny <= nBinsY && nz <= nBinsZ ) {
831 nEntries += nent;
832 const auto sumw_abs = abs( sumw );
833 momentsX.add( xBinAv( nx ), sumw_abs );
834 momentsY.add( yBinAv( ny ), sumw_abs );
835 momentsZ.add( zBinAv( nz ), sumw_abs );
836 }
837 }
838 }
839 }
840 // print
841 const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
842 return fmt::format( fmt::runtime( detail::histo3DFormatting ), detail::formatName( name, stringsWidth ),
843 stringsWidth, stringsWidth, ftitle, stringsWidth, nEntries, nAllEntries, momentsX.mean(),
844 momentsX.stddev(), momentsY.mean(), momentsY.stddev(), momentsZ.mean(), momentsZ.stddev() );
845 }

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

546 {
547 // get original histogram from the Entity
548 auto const& gaudiHisto =
550 // convert to Root
551 auto const& gaudiAxis = gaudiHisto.template axis<0>();
552 details::ProfileWrapper<TProfile> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiAxis.numBins(),
553 gaudiAxis.minValue(), gaudiAxis.maxValue() };
554 if ( !gaudiAxis.labels().empty() ) {
555 auto& axis = *histo.GetXaxis();
556 for ( unsigned int i = 0; i < gaudiAxis.labels().size(); i++ ) {
557 axis.SetBinLabel( i + 1, gaudiAxis.labels()[i].c_str() );
558 }
559 }
560 for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
561 auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
562 auto const& [nent, sumw] = tmp;
563 histo.SetBinContent( i, sumw );
564 histo.setBinNEntries( i, nent );
565 histo.setBinW2( i, sumw2 );
566 }
567 unsigned long totNEntries{ 0 };
568 for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
569 histo.SetEntries( totNEntries );
570 return histo;
571 }
helper Wrapper around TProfileX to be able to fill it
Definition Utils.h:376

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

575 {
576 // get original histogram from the Entity
577 auto const& gaudiHisto =
579 // convert to Root
580 auto const& gaudiXAxis = gaudiHisto.template axis<0>();
581 auto const& gaudiYAxis = gaudiHisto.template axis<1>();
582 details::ProfileWrapper<TProfile2D> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiXAxis.numBins(),
583 gaudiXAxis.minValue(), gaudiXAxis.maxValue(), gaudiYAxis.numBins(),
584 gaudiYAxis.minValue(), gaudiYAxis.maxValue() };
585 if ( !gaudiXAxis.labels().empty() ) {
586 auto& axis = *histo.GetXaxis();
587 for ( unsigned int i = 0; i < gaudiXAxis.labels().size(); i++ ) {
588 axis.SetBinLabel( i + 1, gaudiXAxis.labels()[i].c_str() );
589 }
590 }
591 if ( !gaudiYAxis.labels().empty() ) {
592 auto& axis = *histo.GetYaxis();
593 for ( unsigned int i = 0; i < gaudiYAxis.labels().size(); i++ ) {
594 axis.SetBinLabel( i + 1, gaudiYAxis.labels()[i].c_str() );
595 }
596 }
597 for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
598 auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
599 auto const& [nent, sumw] = tmp;
600 histo.SetBinContent( i, sumw );
601 histo.setBinNEntries( i, nent );
602 histo.setBinW2( i, sumw2 );
603 }
604 unsigned long totNEntries{ 0 };
605 for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
606 histo.SetEntries( totNEntries );
607 return histo;
608 }

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

612 {
613 // get original histogram from the Entity
614 auto const& gaudiHisto =
616 // convert to Root
617 auto const& gaudiXAxis = gaudiHisto.template axis<0>();
618 auto const& gaudiYAxis = gaudiHisto.template axis<1>();
619 auto const& gaudiZAxis = gaudiHisto.template axis<2>();
620 details::ProfileWrapper<TProfile3D> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiXAxis.numBins(),
621 gaudiXAxis.minValue(), gaudiXAxis.maxValue(), gaudiYAxis.numBins(),
622 gaudiYAxis.minValue(), gaudiYAxis.maxValue(), gaudiZAxis.numBins(),
623 gaudiZAxis.minValue(), gaudiZAxis.maxValue() };
624 if ( !gaudiXAxis.labels().empty() ) {
625 auto& axis = *histo.GetXaxis();
626 for ( unsigned int i = 0; i < gaudiXAxis.labels().size(); i++ ) {
627 axis.SetBinLabel( i + 1, gaudiXAxis.labels()[i].c_str() );
628 }
629 }
630 if ( !gaudiYAxis.labels().empty() ) {
631 auto& axis = *histo.GetYaxis();
632 for ( unsigned int i = 0; i < gaudiYAxis.labels().size(); i++ ) {
633 axis.SetBinLabel( i + 1, gaudiYAxis.labels()[i].c_str() );
634 }
635 }
636 if ( !gaudiZAxis.labels().empty() ) {
637 auto& axis = *histo.GetZaxis();
638 for ( unsigned int i = 0; i < gaudiZAxis.labels().size(); i++ ) {
639 axis.SetBinLabel( i + 1, gaudiZAxis.labels()[i].c_str() );
640 }
641 }
642 for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
643 auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
644 auto const& [nent, sumw] = tmp;
645 histo.SetBinContent( i, sumw );
646 histo.setBinNEntries( i, nent );
647 histo.setBinW2( i, sumw2 );
648 }
649 unsigned long totNEntries{ 0 };
650 for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
651 histo.SetEntries( totNEntries );
652 return histo;
653 }
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 657 of file Utils.h.

657 {
658 // fix name and dir if needed
659 details::fixNameAndDir( name, dir );
660 // Change to the proper directory in the ROOT file
661 auto previousDir = details::changeDir( file, dir );
662 // write to file
663 if constexpr ( N == 1 ) {
665 } else if constexpr ( N == 2 ) {
667 } else if constexpr ( N == 3 ) {
669 }
670 // switch back to the previous directory
671 previousDir->cd();
672 }
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:398
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:248
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:575
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:546
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:612

◆ saveRootHisto() [1/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 540 of file Utils.h.

540 {
541 saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
542 }
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:528

◆ saveRootHisto() [2/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 528 of file Utils.h.

528 {
529 // get the Root histogram
530 auto [histo, newDir] = jsonToRootHistogram<Traits>( dir, name, j );
531 // Change to the proper directory in the ROOT file
532 auto previousDir = details::changeDir( file, newDir );
533 // write to file
534 histo.Write();
535 // switch back to the previous directory
536 previousDir->cd();
537 }
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:522