The Gaudi Framework  v39r1 (adb068b2)
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 447 of file Utils.h.

448  {
449  return details::jsonToRootHistogramInternal<Traits>( dir, name, j, std::make_index_sequence<Traits::Dimension>() );
450  }

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

796  {
797  auto& jaxis = j.at( "axis" );
798  auto minValueX = jaxis[0].at( "minValue" ).get<double>();
799  auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
800  auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
801  auto nAllEntries = j.at( "nEntries" ).get<unsigned int>();
802  // compute the various momenta
803  BinAccessor ba{ type, j };
804  double sumX{}, sum2X{}, sum3X{}, sum4X{}, nEntries{ 0 };
805  double binXSize = ( maxValueX - minValueX ) / nBinsX;
806  double binXValue = minValueX + binXSize / 2;
807  for ( unsigned int nx = 1; nx <= nBinsX; nx++ ) {
808  auto n = ba[nx];
809  nEntries += n;
810  auto val = binXValue * n;
811  sumX += val;
812  val *= binXValue;
813  sum2X += val;
814  val *= binXValue;
815  sum3X += val;
816  val *= binXValue;
817  sum4X += val;
818  binXValue += binXSize;
819  }
820  std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
821  if ( nEntries == 0 ) {
822  return fmt::format( fmt::runtime( detail::histo1DFormatting ), name, stringsWidth, stringsWidth, ftitle,
823  stringsWidth, detail::IntWithFixedWidth{}, 0.0, 0.0, 0.0, 0.0 );
824  }
825  double meanX = sumX / nEntries;
826  double sigmaX2 = sum2X / nEntries - meanX * meanX;
827  double stddevX = sqrt( sigmaX2 );
828  double EX3 = sum3X / nEntries;
829  double skewnessX = EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX;
830  double kurtosisX = sum4X / nEntries - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) );
831  skewnessX /= sigmaX2 * stddevX;
832  kurtosisX /= sigmaX2 * sigmaX2;
833  // print
834  return fmt::format( fmt::runtime( detail::histo1DFormatting ), name, stringsWidth, stringsWidth, ftitle,
835  stringsWidth, detail::IntWithFixedWidth{ nAllEntries }, meanX, stddevX, skewnessX,
836  kurtosisX - 3.0 );
837  }

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

840  {
841  auto& jaxis = j.at( "axis" );
842  auto minValueX = jaxis[0].at( "minValue" ).get<double>();
843  auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
844  auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
845  auto minValueY = jaxis[1].at( "minValue" ).get<double>();
846  auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
847  auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
848  auto nAllEntries = j.at( "nEntries" ).get<double>();
849  // compute the various memneta
850  BinAccessor ba{ type, j };
851  double nEntries{};
852  double sumX{}, sumY{};
853  double sum2X{}, sum2Y{};
854  double binXSize = ( maxValueX - minValueX ) / nBinsX;
855  double binYSize = ( maxValueY - minValueY ) / nBinsY;
856  double binYValue = minValueY + binYSize / 2;
857  for ( unsigned int ny = 1; ny <= nBinsY; ny++ ) {
858  double binXValue = minValueX + binXSize / 2;
859  auto offset = ny * ( nBinsX + 2 );
860  for ( unsigned int nx = 1; nx <= nBinsX; nx++ ) {
861  auto n = ba[offset + nx];
862  nEntries += n;
863  sumX += n * binXValue;
864  sum2X += n * binXValue * binXValue;
865  sumY += n * binYValue;
866  sum2Y += n * binYValue * binYValue;
867  binXValue += binXSize;
868  }
869  binYValue += binYSize;
870  }
871  double meanX = nEntries > 0 ? sumX / nEntries : 0.0;
872  double stddevX = nEntries > 0 ? sqrt( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
873  double meanY = nEntries > 0 ? sumY / nEntries : 0.0;
874  double stddevY = nEntries > 0 ? sqrt( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
875  // print
876  std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
877  return fmt::format( fmt::runtime( detail::histo2DFormatting ), name, stringsWidth, stringsWidth, ftitle,
878  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY );
879  }

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

882  {
883  auto& jaxis = j.at( "axis" );
884  auto minValueX = jaxis[0].at( "minValue" ).get<double>();
885  auto maxValueX = jaxis[0].at( "maxValue" ).get<double>();
886  auto nBinsX = jaxis[0].at( "nBins" ).get<unsigned int>();
887  auto minValueY = jaxis[1].at( "minValue" ).get<double>();
888  auto maxValueY = jaxis[1].at( "maxValue" ).get<double>();
889  auto nBinsY = jaxis[1].at( "nBins" ).get<unsigned int>();
890  auto minValueZ = jaxis[2].at( "minValue" ).get<double>();
891  auto maxValueZ = jaxis[2].at( "maxValue" ).get<double>();
892  auto nBinsZ = jaxis[2].at( "nBins" ).get<unsigned int>();
893  auto nAllEntries = j.at( "nEntries" ).get<double>();
894  // compute the various memneta
895  BinAccessor ba{ type, j };
896  double nEntries{};
897  double sumX{}, sumY{}, sumZ{};
898  double sum2X{}, sum2Y{}, sum2Z{};
899  double binXSize = ( maxValueX - minValueX ) / nBinsX;
900  double binYSize = ( maxValueY - minValueY ) / nBinsY;
901  double binZSize = ( maxValueZ - minValueZ ) / nBinsZ;
902  double binZValue = minValueZ + binZSize / 2;
903  for ( unsigned int nz = 1; nz <= nBinsZ; nz++ ) {
904  double binYValue = minValueY + binYSize / 2;
905  auto offsetz = nz * ( nBinsY + 2 );
906  for ( unsigned int ny = 1; ny <= nBinsY; ny++ ) {
907  double binXValue = minValueX + binXSize / 2;
908  auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
909  for ( unsigned int nx = 1; nx <= nBinsX; nx++ ) {
910  auto n = ba[offset + nx];
911  nEntries += n;
912  sumX += n * binXValue;
913  sum2X += n * binXValue * binXValue;
914  sumY += n * binYValue;
915  sum2Y += n * binYValue * binYValue;
916  sumZ += n * binZValue;
917  sum2Z += n * binZValue * binZValue;
918  binXValue += binXSize;
919  }
920  binYValue += binYSize;
921  }
922  binZValue += binZSize;
923  }
924  double meanX = nEntries > 0 ? sumX / nEntries : 0.0;
925  double stddevX = nEntries > 0 ? sqrt( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
926  double meanY = nEntries > 0 ? sumY / nEntries : 0.0;
927  double stddevY = nEntries > 0 ? sqrt( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
928  double meanZ = nEntries > 0 ? sumZ / nEntries : 0.0;
929  double stddevZ = nEntries > 0 ? sqrt( ( sum2Z - sumZ * ( sumZ / nEntries ) ) / nEntries ) : 0.0;
930  // print
931  std::string ftitle = detail::formatTitle( title, stringsWidth - 2 );
932  return fmt::format( fmt::runtime( detail::histo3DFormatting ), name, stringsWidth, stringsWidth, ftitle,
933  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY, meanZ, stddevZ );
934  }

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

605  {
606  // get original histogram from the Entity
607  auto const& gaudiHisto =
609  // compute min and max values, we actually display the axis limits
610  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
611  Arithmetic minValueX = gaudiAxisX.minValue();
612  Arithmetic maxValueX = gaudiAxisX.maxValue();
613  unsigned int nBinsX = gaudiAxisX.numBins();
614  // Compute fist and second momenta for normal dimenstion
615  // Compute 1st and 2nd momenta for the profile dimension
616  unsigned int nEntries{ 0 }, nAllEntries{ 0 };
617  Arithmetic sumX{};
618  Arithmetic sum2X{};
619  Arithmetic sum3X{};
620  Arithmetic sum4X{};
621  Arithmetic binXSize = ( maxValueX - minValueX ) / nBinsX;
622  Arithmetic binXValue = minValueX - binXSize / 2;
623  for ( unsigned int nx = 0; nx <= nBinsX + 1; nx++ ) {
624  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx );
625  auto const& [nent, sumw] = tmp;
626  nAllEntries += nent;
627  if ( nx > 0 && nx <= nBinsX ) {
628  nEntries += nent;
629  auto val = binXValue * nent;
630  sumX += val;
631  val *= binXValue;
632  sum2X += val;
633  val *= binXValue;
634  sum3X += val;
635  val *= binXValue;
636  sum4X += val;
637  binXValue += binXSize;
638  }
639  }
640  std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
641  if ( nEntries == 0 ) {
642  return fmt::format( fmt::runtime( detail::histo1DFormatting ), name, stringsWidth, stringsWidth, ftitle,
643  stringsWidth, detail::IntWithFixedWidth{}, 0.0, 0.0, 0.0, 0.0 );
644  }
645  Arithmetic meanX = sumX / nEntries;
646  Arithmetic sigmaX2 = sum2X / nEntries - meanX * meanX;
647  Arithmetic stddevX = sqrt( sigmaX2 );
648  Arithmetic EX3 = sum3X / nEntries;
649  Arithmetic skewnessX = EX3 - ( 3 * sigmaX2 + meanX * meanX ) * meanX;
650  Arithmetic kurtosisX = sum4X / nEntries - meanX * ( 4 * EX3 - meanX * ( 6 * sigmaX2 + 3 * meanX * meanX ) );
651  skewnessX /= sigmaX2 * stddevX;
652  kurtosisX /= sigmaX2 * sigmaX2;
653  // print
654  return fmt::format( fmt::runtime( detail::histo1DFormatting ), name, stringsWidth, stringsWidth, ftitle,
655  stringsWidth, detail::IntWithFixedWidth{ nEntries }, meanX, stddevX, skewnessX,
656  kurtosisX - Arithmetic{ 3.0 } );
657  }

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

662  {
663  // get original histogram from the Entity
664  auto const& gaudiHisto =
666  // compute min and max values, we actually display the axis limits
667  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
668  Arithmetic minValueX = gaudiAxisX.minValue();
669  Arithmetic maxValueX = gaudiAxisX.maxValue();
670  unsigned int nBinsX = gaudiAxisX.numBins();
671  auto const& gaudiAxisY = gaudiHisto.template axis<1>();
672  Arithmetic minValueY = gaudiAxisY.minValue();
673  Arithmetic maxValueY = gaudiAxisY.maxValue();
674  unsigned int nBinsY = gaudiAxisY.numBins();
675  // Compute fist and second momenta for normal dimenstion
676  // Compute 1st and 2nd momenta for the profile dimension
677  Arithmetic nEntries{ 0 }, nAllEntries{ 0 };
678  Arithmetic sumX{}, sumY{};
679  Arithmetic sum2X{}, sum2Y{};
680  Arithmetic binXSize = ( maxValueX - minValueX ) / nBinsX;
681  Arithmetic binYSize = ( maxValueY - minValueY ) / nBinsY;
682  Arithmetic binYValue = minValueY - binYSize / 2;
683  for ( unsigned int ny = 0; ny <= nBinsY + 1; ny++ ) {
684  Arithmetic binXValue = minValueX - binXSize / 2;
685  auto offset = ny * ( nBinsX + 2 );
686  for ( unsigned int nx = 0; nx <= nBinsX + 1; nx++ ) {
687  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
688  auto const& [nent, sumw] = tmp;
689  nAllEntries += nent;
690  if ( nx > 0 && ny > 0 && nx <= nBinsX && ny <= nBinsY ) {
691  nEntries += nent;
692  sumX += binXValue * nent;
693  sum2X += binXValue * binXValue * nent;
694  sumY += binYValue * nent;
695  sum2Y += binYValue * binYValue * nent;
696  binXValue += binXSize;
697  }
698  }
699  binYValue += binYSize;
700  }
701  Arithmetic meanX = nEntries > 0 ? sumX / nEntries : 0.0;
702  Arithmetic stddevX = nEntries > 0 ? sqrt( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
703  Arithmetic meanY = nEntries > 0 ? sumY / nEntries : 0.0;
704  Arithmetic stddevY = nEntries > 0 ? sqrt( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
705  // print
706  std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
707  return fmt::format( fmt::runtime( detail::histo2DFormatting ), name, stringsWidth, stringsWidth, ftitle,
708  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY );
709  }

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

714  {
715  // get original histogram from the Entity
716  auto const& gaudiHisto =
718  // compute min and max values, we actually display the axis limits
719  auto const& gaudiAxisX = gaudiHisto.template axis<0>();
720  Arithmetic minValueX = gaudiAxisX.minValue();
721  Arithmetic maxValueX = gaudiAxisX.maxValue();
722  unsigned int nBinsX = gaudiAxisX.numBins();
723  auto const& gaudiAxisY = gaudiHisto.template axis<1>();
724  Arithmetic minValueY = gaudiAxisY.minValue();
725  Arithmetic maxValueY = gaudiAxisY.maxValue();
726  unsigned int nBinsY = gaudiAxisY.numBins();
727  auto const& gaudiAxisZ = gaudiHisto.template axis<2>();
728  Arithmetic minValueZ = gaudiAxisZ.minValue();
729  Arithmetic maxValueZ = gaudiAxisZ.maxValue();
730  unsigned int nBinsZ = gaudiAxisZ.numBins();
731  // Compute fist and second momenta for normal dimenstion
732  // Compute 1st and 2nd momenta for the profile dimension
733  Arithmetic nEntries{ 0 }, nAllEntries{ 0 };
734  Arithmetic sumX{}, sumY{}, sumZ{};
735  Arithmetic sum2X{}, sum2Y{}, sum2Z{};
736  Arithmetic binXSize = ( maxValueX - minValueX ) / nBinsX;
737  Arithmetic binYSize = ( maxValueY - minValueY ) / nBinsY;
738  Arithmetic binZSize = ( maxValueZ - minValueZ ) / nBinsZ;
739  Arithmetic binZValue = minValueZ - binZSize / 2;
740  for ( unsigned int nz = 0; nz <= nBinsZ + 1; nz++ ) {
741  Arithmetic binYValue = minValueY - binYSize / 2;
742  auto offsetz = nz * ( nBinsY + 2 );
743  for ( unsigned int ny = 0; ny <= nBinsY; ny++ ) {
744  Arithmetic binXValue = minValueX - binXSize / 2;
745  auto offset = ( offsetz + ny ) * ( nBinsX + 2 );
746  for ( unsigned int nx = 0; nx <= nBinsX; nx++ ) {
747  auto const& [tmp, sumw2] = gaudiHisto.binValue( nx + offset );
748  auto const& [nent, sumw] = tmp;
749  nAllEntries += nent;
750  if ( nx > 0 && ny > 0 && nz > 0 && nx <= nBinsX && ny <= nBinsY && nz <= nBinsZ ) {
751  nEntries += nent;
752  sumX += binXValue * nent;
753  sum2X += binXValue * binXValue * nent;
754  sumY += binYValue * nent;
755  sum2Y += binYValue * binYValue * nent;
756  sumZ += binZValue * nent;
757  sum2Z += binZValue * binZValue * nent;
758  binXValue += binXSize;
759  }
760  }
761  binYValue += binYSize;
762  }
763  binZValue += binZSize;
764  }
765  Arithmetic meanX = nEntries > 0 ? sumX / nEntries : 0.0;
766  Arithmetic stddevX = nEntries > 0 ? sqrt( ( sum2X - sumX * ( sumX / nEntries ) ) / nEntries ) : 0.0;
767  Arithmetic meanY = nEntries > 0 ? sumY / nEntries : 0.0;
768  Arithmetic stddevY = nEntries > 0 ? sqrt( ( sum2Y - sumY * ( sumY / nEntries ) ) / nEntries ) : 0.0;
769  Arithmetic meanZ = nEntries > 0 ? sumZ / nEntries : 0.0;
770  Arithmetic stddevZ = nEntries > 0 ? sqrt( ( sum2Z - sumZ * ( sumZ / nEntries ) ) / nEntries ) : 0.0;
771  // print
772  std::string ftitle = detail::formatTitle( gaudiHisto.title(), stringsWidth - 2 );
773  return fmt::format( fmt::runtime( detail::histo3DFormatting ), name, stringsWidth, stringsWidth, ftitle,
774  stringsWidth, nEntries, nAllEntries, meanX, stddevX, meanY, stddevY, meanZ, stddevZ );
775  }

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

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

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

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

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

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

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

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

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

453  {
454  // get the Root histogram
455  auto [histo, newDir] = jsonToRootHistogram<Traits>( dir, name, j );
456  // Change to the proper directory in the ROOT file
457  auto previousDir = details::changeDir( file, newDir );
458  // write to file
459  histo.Write();
460  // switch back to the previous directory
461  previousDir->cd();
462  }

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

465  {
466  saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
467  }
Gaudi::Accumulators::sqrt
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:34
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:23
IOTest.N
N
Definition: IOTest.py:112
std::move
T move(T... args)
Gaudi::Accumulators::HistogramingCounterBase
A base counter dealing with Histograms.
Definition: StaticHistogram.h: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:169
Gaudi::Histograming::Sink::detail::histo2DFormatting
constexpr std::string_view histo2DFormatting
Definition: Utils.h:55
Gaudi::Histograming::Sink::details::changeDir
TDirectory * changeDir(TFile &file, std::string dir)
changes to the ROOT directory given in the current ROOT file and returns the current directory before...
Definition: Utils.h:319
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:57
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:46
Gaudi::Histograming::Sink::detail::histo1DFormatting
constexpr std::string_view histo1DFormatting
Definition: Utils.h:53