The Gaudi Framework  master (37c0b60a)
Gaudi::Histograming::Sink Namespace Reference

Namespaces

 detail
 
 details
 

Classes

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

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

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

812  {
813  const auto& jaxis = j.at( "axis" );
814  const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
815  const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
816  const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
817  const auto nAllEntries = j.at( "nEntries" ).get<unsigned int>();
818  // compute the various momenta
819  BinAccessor ba{ type, j };
820  double sumX{}, sum2X{}, sum3X{}, sum4X{}, nEntries{ 0 };
821  const double binXSize = ( maxValueX - minValueX ) / nBinsX;
822  for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
823  const double binXValue = minValueX + ( nx - 0.5 ) * binXSize;
824  const auto n = ba[nx];
825  nEntries += n;
826  auto val = binXValue * n;
827  sumX += val;
828  val *= binXValue;
829  sum2X += val;
830  val *= binXValue;
831  sum3X += val;
832  val *= binXValue;
833  sum4X += val;
834  }
835  const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
836  if ( !( fabs( nEntries ) > 0.0 ) ) { return ""; }
837  const double meanX = sumX / nEntries;
838  const double sigmaX2 = ( sum2X / nEntries ) - std::pow( meanX, 2 );
839  const double stddevX = detail::sqrt_or_zero( sigmaX2 );
840  const double EX3 = sum3X / nEntries;
841  const double A = sigmaX2 * stddevX;
842  const double skewnessX = ( fabs( A ) > 0.0 ? ( EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX ) / A : 0.0 );
843  const double B = sigmaX2 * sigmaX2;
844  const double kurtosisX =
845  ( fabs( B ) > 0.0 && fabs( A ) > 0.0
846  ? ( sum4X / nEntries - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) ) ) / B
847  : 3.0 );
848  // print
849  return fmt::format( fmt::runtime( detail::histo1DFormatting ), name, stringsWidth, stringsWidth, ftitle,
850  stringsWidth, detail::IntWithFixedWidth{ nAllEntries }, meanX, stddevX, skewnessX,
851  kurtosisX - 3.0 );
852  }

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

855  {
856  const auto& jaxis = j.at( "axis" );
857  const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
858  const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
859  const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
860  const auto minValueY = jaxis[1].at( "minValue" ).get<double>();
861  const auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
862  const auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
863  const auto nAllEntries = j.at( "nEntries" ).get<double>();
864  // compute the various memneta
865  BinAccessor ba{ type, j };
866  double nEntries{};
867  double sumX{}, sumY{};
868  double sum2X{}, sum2Y{};
869  const double binXSize = ( maxValueX - minValueX ) / nBinsX;
870  const double binYSize = ( maxValueY - minValueY ) / nBinsY;
871  for ( unsigned int ny = 1; ny <= nBinsY; ++ny ) {
872  const auto offset = ny * ( nBinsX + 2 );
873  for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
874  const double binXValue = minValueX + ( nx - 0.5 ) * binXSize;
875  const double binYValue = minValueY + ( ny - 0.5 ) * binYSize;
876  const auto n = ba[offset + nx];
877  nEntries += n;
878  sumX += n * binXValue;
879  sum2X += n * binXValue * binXValue;
880  sumY += n * binYValue;
881  sum2Y += n * binYValue * binYValue;
882  }
883  }
884  const double meanX = fabs( nEntries ) > 0 ? sumX / nEntries : 0.0;
885  const double stddevX =
886  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
887  const double meanY = fabs( nEntries ) > 0 ? sumY / nEntries : 0.0;
888  const double stddevY =
889  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
890  // print
891  const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
892  return fmt::format( fmt::runtime( detail::histo2DFormatting ), name, stringsWidth, stringsWidth, ftitle,
893  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY );
894  }

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

897  {
898  const auto& jaxis = j.at( "axis" );
899  const auto minValueX = jaxis[0].at( "minValue" ).get<double>();
900  const auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
901  const auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
902  const auto minValueY = jaxis[1].at( "minValue" ).get<double>();
903  const auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
904  const auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
905  const auto minValueZ = jaxis[2].at( "minValue" ).get<double>();
906  const auto maxValueZ = jaxis[2].at( "maxValue" ).get<double>();
907  const auto nBinsZ = jaxis[2].at( "nBins" ).get<unsigned int>();
908  const auto nAllEntries = j.at( "nEntries" ).get<double>();
909  // compute the various memneta
910  BinAccessor ba{ type, j };
911  double nEntries{};
912  double sumX{}, sumY{}, sumZ{};
913  double sum2X{}, sum2Y{}, sum2Z{};
914  const double binXSize = ( maxValueX - minValueX ) / nBinsX;
915  const double binYSize = ( maxValueY - minValueY ) / nBinsY;
916  const double binZSize = ( maxValueZ - minValueZ ) / nBinsZ;
917  for ( unsigned int nz = 1; nz <= nBinsZ; ++nz ) {
918  const auto offsetz = nz * ( nBinsY + 2 );
919  for ( unsigned int ny = 1; ny <= nBinsY; ++ny ) {
920  const auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
921  for ( unsigned int nx = 1; nx <= nBinsX; ++nx ) {
922  const double binXValue = minValueX + ( nx - 0.5 ) * binXSize;
923  const double binYValue = minValueY + ( ny - 0.5 ) * binYSize;
924  const double binZValue = minValueZ + ( nz - 0.5 ) * binZSize;
925  const auto n = ba[offset + nx];
926  nEntries += n;
927  sumX += n * binXValue;
928  sum2X += n * binXValue * binXValue;
929  sumY += n * binYValue;
930  sum2Y += n * binYValue * binYValue;
931  sumZ += n * binZValue;
932  sum2Z += n * binZValue * binZValue;
933  }
934  }
935  }
936  const double meanX = fabs( nEntries ) > 0 ? sumX / nEntries : 0.0;
937  const double stddevX =
938  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
939  const double meanY = fabs( nEntries ) > 0 ? sumY / nEntries : 0.0;
940  const double stddevY =
941  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
942  const double meanZ = fabs( nEntries ) > 0 ? sumZ / nEntries : 0.0;
943  const double stddevZ =
944  fabs( nEntries ) > 0 ? detail::sqrt_or_zero( ( sum2Z - sumZ * ( sumZ / nEntries ) ) / nEntries ) : 0.0;
945  // print
946  const std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
947  return fmt::format( fmt::runtime( detail::histo3DFormatting ), name, stringsWidth, stringsWidth, ftitle,
948  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY, meanZ, stddevZ );
949  }

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

610  {
611  // Type to use for internal calculation. Use double to avoid precision issues across different builds.
612  using FPType = double;
613  // get original histogram from the Entity
614  auto const& gaudiHisto =
616  // compute min and max values, we actually display the axis limits
617  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
618  const FPType minValueX = gaudiAxisX.minValue();
619  const FPType maxValueX = gaudiAxisX.maxValue();
620  const unsigned int nBinsX = gaudiAxisX.numBins();
621  // Compute fist and second momenta for normal dimenstion
622  // Compute 1st and 2nd momenta for the profile dimension
623  unsigned int nEntries{ 0 }, nAllEntries{ 0 };
624  FPType totalSumW{ 0 };
625  FPType sumX{ 0 };
626  FPType sum2X{ 0 };
627  FPType sum3X{ 0 };
628  FPType sum4X{ 0 };
629  const FPType binXSize = ( maxValueX - minValueX ) / nBinsX;
630  for ( unsigned int nx = 0; nx <= nBinsX + 1; ++nx ) {
631  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx );
632  auto const& [nent, sumw] = tmp;
633  nAllEntries += nent;
634  if ( nx > 0 && nx <= nBinsX ) {
635  const FPType binXValue = minValueX + ( nx - 0.5 ) * binXSize;
636  nEntries += nent;
637  totalSumW += sumw;
638  auto val = binXValue * sumw;
639  sumX += val;
640  val *= binXValue;
641  sum2X += val;
642  val *= binXValue;
643  sum3X += val;
644  val *= binXValue;
645  sum4X += val;
646  }
647  }
648  const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
649  if ( nEntries == 0 || !( fabs( totalSumW ) > 0 ) ) { return ""; }
650  const FPType meanX = sumX / totalSumW;
651  const FPType sigmaX2 = ( sum2X / totalSumW ) - std::pow( meanX, 2 );
652  const FPType stddevX = detail::sqrt_or_zero( sigmaX2 );
653  const FPType EX3 = sum3X / totalSumW;
654  const FPType A = sigmaX2 * stddevX;
655  const FPType skewnessX = ( fabs( A ) > 0.0 ? ( EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX ) / A : 0.0 );
656  const FPType B = sigmaX2 * sigmaX2;
657  const FPType kurtosisX =
658  ( fabs( B ) > 0.0 && fabs( A ) > 0.0
659  ? ( sum4X / totalSumW - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) ) ) / B
660  : 3.0 );
661  // print
662  return fmt::format( fmt::runtime( detail::histo1DFormatting ), name, stringsWidth, stringsWidth, ftitle,
663  stringsWidth, detail::IntWithFixedWidth{ nEntries }, meanX, stddevX, skewnessX,
664  kurtosisX - FPType{ 3.0 } );
665  }

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

670  {
671  // Type to use for internal calculation. Use double to avoid precision issues across different builds.
672  using FPType = double;
673  // get original histogram from the Entity
674  auto const& gaudiHisto =
676  // compute min and max values, we actually display the axis limits
677  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
678  const FPType minValueX = gaudiAxisX.minValue();
679  const FPType maxValueX = gaudiAxisX.maxValue();
680  const unsigned int nBinsX = gaudiAxisX.numBins();
681  auto const& gaudiAxisY = gaudiHisto.template axis<1>();
682  const FPType minValueY = gaudiAxisY.minValue();
683  const FPType maxValueY = gaudiAxisY.maxValue();
684  const unsigned int nBinsY = gaudiAxisY.numBins();
685  // Compute fist and second momenta for normal dimenstion
686  // Compute 1st and 2nd momenta for the profile dimension
687  FPType nEntries{ 0 }, nAllEntries{ 0 };
688  FPType totalSumW{ 0 };
689  FPType sumX{ 0 }, sumY{ 0 };
690  FPType sum2X{ 0 }, sum2Y{ 0 };
691  const FPType binXSize = ( maxValueX - minValueX ) / nBinsX;
692  const FPType binYSize = ( maxValueY - minValueY ) / nBinsY;
693  for ( unsigned int ny = 0; ny <= nBinsY + 1; ++ny ) {
694  const auto offset = ny * ( nBinsX + 2 );
695  for ( unsigned int nx = 0; nx <= nBinsX + 1; ++nx ) {
696  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
697  auto const& [nent, sumw] = tmp;
698  nAllEntries += nent;
699  if ( nx > 0 && ny > 0 && nx <= nBinsX && ny <= nBinsY ) {
700  const FPType binXValue = minValueX + ( nx - 0.5 ) * binXSize;
701  const FPType binYValue = minValueY + ( ny - 0.5 ) * binYSize;
702  nEntries += nent;
703  totalSumW += sumw;
704  sumX += binXValue * sumw;
705  sum2X += binXValue * binXValue * sumw;
706  sumY += binYValue * sumw;
707  sum2Y += binYValue * binYValue * sumw;
708  }
709  }
710  }
711  const FPType meanX = fabs( totalSumW ) > 0 ? sumX / totalSumW : 0.0;
712  const FPType stddevX =
713  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / totalSumW ) ) / totalSumW ) : 0.0;
714  const FPType meanY = fabs( totalSumW ) > 0 ? sumY / totalSumW : 0.0;
715  const FPType stddevY =
716  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / totalSumW ) ) / totalSumW ) : 0.0;
717  // print
718  const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
719  return fmt::format( fmt::runtime( detail::histo2DFormatting ), name, stringsWidth, stringsWidth, ftitle,
720  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY );
721  }

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

726  {
727  // Type to use for internal calculation. Use double to avoid precision issues across different builds.
728  using FPType = double;
729  // get original histogram from the Entity
730  auto const& gaudiHisto =
732  // compute min and max values, we actually display the axis limits
733  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
734  const FPType minValueX = gaudiAxisX.minValue();
735  const FPType maxValueX = gaudiAxisX.maxValue();
736  const unsigned int nBinsX = gaudiAxisX.numBins();
737  auto const& gaudiAxisY = gaudiHisto.template axis<1>();
738  const FPType minValueY = gaudiAxisY.minValue();
739  const FPType maxValueY = gaudiAxisY.maxValue();
740  const unsigned int nBinsY = gaudiAxisY.numBins();
741  auto const& gaudiAxisZ = gaudiHisto.template axis<2>();
742  const FPType minValueZ = gaudiAxisZ.minValue();
743  const FPType maxValueZ = gaudiAxisZ.maxValue();
744  const unsigned int nBinsZ = gaudiAxisZ.numBins();
745  // Compute fist and second momenta for normal dimenstion
746  // Compute 1st and 2nd momenta for the profile dimension
747  FPType nEntries{ 0 }, nAllEntries{ 0 };
748  FPType totalSumW{};
749  FPType sumX{ 0 }, sumY{ 0 }, sumZ{ 0 };
750  FPType sum2X{ 0 }, sum2Y{ 0 }, sum2Z{ 0 };
751  const FPType binXSize = ( maxValueX - minValueX ) / nBinsX;
752  const FPType binYSize = ( maxValueY - minValueY ) / nBinsY;
753  const FPType binZSize = ( maxValueZ - minValueZ ) / nBinsZ;
754  for ( unsigned int nz = 0; nz <= nBinsZ + 1; ++nz ) {
755  const auto offsetz = nz * ( nBinsY + 2 );
756  for ( unsigned int ny = 0; ny <= nBinsY; ++ny ) {
757  const auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
758  for ( unsigned int nx = 0; nx <= nBinsX; ++nx ) {
759  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
760  auto const& [nent, sumw] = tmp;
761  nAllEntries += nent;
762  if ( nx > 0 && ny > 0 && nz > 0 && nx <= nBinsX && ny <= nBinsY && nz <= nBinsZ ) {
763  const FPType binXValue = minValueX + ( nx - 0.5 ) * binXSize;
764  const FPType binYValue = minValueY + ( ny - 0.5 ) * binYSize;
765  const FPType binZValue = minValueZ + ( nz - 0.5 ) * binZSize;
766  nEntries += nent;
767  totalSumW += sumw;
768  sumX += binXValue * sumw;
769  sum2X += binXValue * binXValue * sumw;
770  sumY += binYValue * sumw;
771  sum2Y += binYValue * binYValue * sumw;
772  sumZ += binZValue * sumw;
773  sum2Z += binZValue * binZValue * sumw;
774  }
775  }
776  }
777  }
778  const FPType meanX = fabs( totalSumW ) > 0 ? sumX / totalSumW : 0.0;
779  const FPType stddevX =
780  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2X - sumX * ( sumX / totalSumW ) ) / totalSumW ) : 0.0;
781  const FPType meanY = fabs( totalSumW ) > 0 ? sumY / totalSumW : 0.0;
782  const FPType stddevY =
783  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2Y - sumY * ( sumY / totalSumW ) ) / totalSumW ) : 0.0;
784  const FPType meanZ = fabs( totalSumW ) > 0 ? sumZ / totalSumW : 0.0;
785  const FPType stddevZ =
786  fabs( totalSumW ) > 0 ? detail::sqrt_or_zero( ( sum2Z - sumZ * ( sumZ / totalSumW ) ) / totalSumW ) : 0.0;
787  // print
788  const std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
789  return fmt::format( fmt::runtime( detail::histo3DFormatting ), name, stringsWidth, stringsWidth, ftitle,
790  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY, meanZ, stddevZ );
791  }

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

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

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

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

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

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

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

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

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

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

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

473  {
474  saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
475  }
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:23
IOTest.N
N
Definition: IOTest.py:112
std::fabs
T fabs(T... args)
std::move
T move(T... args)
Gaudi::Accumulators::HistogramingCounterBase
A base counter dealing with Histograms.
Definition: StaticHistogram.h:653
Gaudi::Histograming::Sink::details::fixNameAndDir
void fixNameAndDir(std::string &name, std::string &dir)
handles cases where name includes '/' character(s) and move needed part of it to dir.
Definition: Utils.h:177
Gaudi::Histograming::Sink::detail::histo2DFormatting
constexpr std::string_view histo2DFormatting
Definition: Utils.h:56
Gaudi::Histograming::Sink::detail::sqrt_or_zero
T sqrt_or_zero(const T x)
sqrt or zero
Definition: Utils.h:69
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:58
cpluginsvc.n
n
Definition: cpluginsvc.py:234
gaudirun.type
type
Definition: gaudirun.py:160
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi::Histograming::Sink::detail::formatTitle
std::string formatTitle(std::string_view title, unsigned int width)
Definition: Utils.h:47
Gaudi::Histograming::Sink::detail::histo1DFormatting
constexpr std::string_view histo1DFormatting
Definition: Utils.h:54
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:327
std::pow
T pow(T... args)