<commit_before>#ifndef MNV_MUH1D_cxx
#define MNV_MUH1D_cxx 1

#include "PlotUtils/MUH1D.h"
#include "HistogramUtils.h"

#include <TMath.h>
#include <TDirectory.h>

using namespace PlotUtils;

ClassImp(MUH1D);

//==================================================================================
// CONSTRUCTORS
//==================================================================================

//--------------------------------------------------------
// Copy constructors with default normalized bin width
//--------------------------------------------------------
MUH1D::MUH1D() : 
  TH1D(),
  fNormBinWidth(1.)
{ 
  SilentSumw2(); 
}

MUH1D::MUH1D( const TVectorD& v ) :
  TH1D( v ),
  fNormBinWidth(1.)
{ 
  SilentSumw2(); 
}

MUH1D::MUH1D( const TH1D& h1d ) :
  TH1D( h1d ) 
{ 
  fNormBinWidth = h1d.GetBinWidth(1);
  SilentSumw2();
}


//--------------------------------------------------------
// Copy constructors with specified normalized bin width
//--------------------------------------------------------
MUH1D::MUH1D(Double_t normBinWidth) :
  TH1D(),
  fNormBinWidth(normBinWidth)
{
  SilentSumw2();
}

MUH1D::MUH1D( const TVectorD& v, Double_t normBinWidth ) :
  TH1D( v ),
  fNormBinWidth(normBinWidth)
{
  SilentSumw2(); 
}

MUH1D::MUH1D( const TH1D& h1d, Double_t normBinWidth ) :
  TH1D( h1d ),
  fNormBinWidth(normBinWidth)
{ 
  SilentSumw2();
}

MUH1D::MUH1D( const MUH1D& h ) :
  TH1D( h )
{
  // Deep copy the variables
  DeepCopy( h );
}

MUH1D& MUH1D::operator=( const MUH1D& h )
{
  // If this is me, then no copy is necessary
  if( this == &h )
    return *this;

  //call the base class assignment operator
  this->TH1D::operator=(h);

  // Delete and clear all vert and lat error bands
  for( std::map<std::string, MUVertErrorBand*>::iterator it = fVertErrorBandMap.begin(); it != fVertErrorBandMap.end(); ++it )
    delete it->second;
  fVertErrorBandMap.clear();

  for( std::map<std::string, MULatErrorBand*>::iterator it = fLatErrorBandMap.begin(); it != fLatErrorBandMap.end(); ++it )
    delete it->second;
  fLatErrorBandMap.clear();

  //delete and clear all uncorr errors
  for( std::map<std::string, TH1D*>::iterator it = fUncorrErrorMap.begin(); it != fUncorrErrorMap.end(); ++it )
    delete it->second;
  fUncorrErrorMap.clear();


  // Then deeop copy the variables
  DeepCopy(h);

  return *this;
}

void MUH1D::DeepCopy( const MUH1D& h )
{
  // Set bin norm width
  fNormBinWidth = h.GetNormBinWidth();

  //change to this's directory so children are in the same place
  const TString oldDir = gDirectory->GetPath();
  this->GetDirectory()->cd();


  // Copy the vert and lat error bands
  std::vector<std::string> vertNames = h.GetVertErrorBandNames();
  for( std::vector<std::string>::iterator name = vertNames.begin(); name != vertNames.end(); ++name )
    fVertErrorBandMap[*name] = new MUVertErrorBand( *h.GetVertErrorBand(*name) );

  std::vector<std::string> latNames = h.GetLatErrorBandNames();
  for( std::vector<std::string>::iterator name = latNames.begin(); name != latNames.end(); ++name )
    fLatErrorBandMap[*name] = new MULatErrorBand( *h.GetLatErrorBand(*name) );

  //copy all uncorr errors
  std::vector<std::string> uncorrNames = h.GetUncorrErrorNames();
  for( std::vector<std::string>::iterator name = uncorrNames.begin(); name != uncorrNames.end(); ++name )
    fUncorrErrorMap[*name] = new TH1D( *h.GetUncorrError(*name) );

  //copy all "special" error matrices
  //todo: These were unfortunately named.  There is not always a clear distinction between these "special" error matrices and those derived from error bands.
  //todo: It's not clear how we want to handle shape only stuff here. GetSysErrorMatricesNames does not include them but that might be fine.
  //
  // NOTE(JVY): Copy opver also the shape-only matrices. 
  //            After all, even if they're calculated from bands, why would it hurt to have them copied ???
  //            We can, of course, discuss and iterate on this some more, but somehow this needs to be fixed.
  //
  std::vector<std::string> allSysNames = h.GetSysErrorMatricesNames();
  for( std::vector<std::string>::iterator name = allSysNames.begin(); name != allSysNames.end(); ++name )
  {
    //this restricts us to only the special matrices
    if( h.HasErrorMatrix(*name) )
      fSysErrorMatrix[*name] = new TMatrixD( h.GetSysErrorMatrix(*name) );
    std::string sname = *name + "_asShape";
    if ( h.HasErrorMatrix( sname ) )
      fSysErrorMatrix[sname] = new TMatrixD( h.GetSysErrorMatrix(*name,false,true) );
  }

  //add removed "special" error matrices
  //
  // NOTE(JVY): Same with shape-only as above.
  //
  std::vector<std::string> removedSysNames = h.GetRemovedSysErrorMatricesNames();
  for( std::vector<std::string>::iterator name = removedSysNames.begin(); name != removedSysNames.end(); ++name )
  {
     fRemovedSysErrorMatrix[*name] = new TMatrixD( h.GetSysErrorMatrix(*name) );<commit_msg>minor typo (in the comments)<commit_after>#ifndef MNV_MUH1D_cxx
#define MNV_MUH1D_cxx 1

#include "PlotUtils/MUH1D.h"
#include "HistogramUtils.h"

#include <TMath.h>
#include <TDirectory.h>

using namespace PlotUtils;

ClassImp(MUH1D);

//==================================================================================
// CONSTRUCTORS
//==================================================================================

//--------------------------------------------------------
// Copy constructors with default normalized bin width
//--------------------------------------------------------
MUH1D::MUH1D() : 
  TH1D(),
  fNormBinWidth(1.)
{ 
  SilentSumw2(); 
}

MUH1D::MUH1D( const TVectorD& v ) :
  TH1D( v ),
  fNormBinWidth(1.)
{ 
  SilentSumw2(); 
}

MUH1D::MUH1D( const TH1D& h1d ) :
  TH1D( h1d ) 
{ 
  fNormBinWidth = h1d.GetBinWidth(1);
  SilentSumw2();
}


//--------------------------------------------------------
// Copy constructors with specified normalized bin width
//--------------------------------------------------------
MUH1D::MUH1D(Double_t normBinWidth) :
  TH1D(),
  fNormBinWidth(normBinWidth)
{
  SilentSumw2();
}

MUH1D::MUH1D( const TVectorD& v, Double_t normBinWidth ) :
  TH1D( v ),
  fNormBinWidth(normBinWidth)
{
  SilentSumw2(); 
}

MUH1D::MUH1D( const TH1D& h1d, Double_t normBinWidth ) :
  TH1D( h1d ),
  fNormBinWidth(normBinWidth)
{ 
  SilentSumw2();
}

MUH1D::MUH1D( const MUH1D& h ) :
  TH1D( h )
{
  // Deep copy the variables
  DeepCopy( h );
}

MUH1D& MUH1D::operator=( const MUH1D& h )
{
  // If this is me, then no copy is necessary
  if( this == &h )
    return *this;

  //call the base class assignment operator
  this->TH1D::operator=(h);

  // Delete and clear all vert and lat error bands
  for( std::map<std::string, MUVertErrorBand*>::iterator it = fVertErrorBandMap.begin(); it != fVertErrorBandMap.end(); ++it )
    delete it->second;
  fVertErrorBandMap.clear();

  for( std::map<std::string, MULatErrorBand*>::iterator it = fLatErrorBandMap.begin(); it != fLatErrorBandMap.end(); ++it )
    delete it->second;
  fLatErrorBandMap.clear();

  //delete and clear all uncorr errors
  for( std::map<std::string, TH1D*>::iterator it = fUncorrErrorMap.begin(); it != fUncorrErrorMap.end(); ++it )
    delete it->second;
  fUncorrErrorMap.clear();


  // Then deeop copy the variables
  DeepCopy(h);

  return *this;
}

void MUH1D::DeepCopy( const MUH1D& h )
{
  // Set bin norm width
  fNormBinWidth = h.GetNormBinWidth();

  //change to this's directory so children are in the same place
  const TString oldDir = gDirectory->GetPath();
  this->GetDirectory()->cd();


  // Copy the vert and lat error bands
  std::vector<std::string> vertNames = h.GetVertErrorBandNames();
  for( std::vector<std::string>::iterator name = vertNames.begin(); name != vertNames.end(); ++name )
    fVertErrorBandMap[*name] = new MUVertErrorBand( *h.GetVertErrorBand(*name) );

  std::vector<std::string> latNames = h.GetLatErrorBandNames();
  for( std::vector<std::string>::iterator name = latNames.begin(); name != latNames.end(); ++name )
    fLatErrorBandMap[*name] = new MULatErrorBand( *h.GetLatErrorBand(*name) );

  //copy all uncorr errors
  std::vector<std::string> uncorrNames = h.GetUncorrErrorNames();
  for( std::vector<std::string>::iterator name = uncorrNames.begin(); name != uncorrNames.end(); ++name )
    fUncorrErrorMap[*name] = new TH1D( *h.GetUncorrError(*name) );

  //copy all "special" error matrices
  //todo: These were unfortunately named.  There is not always a clear distinction between these "special" error matrices and those derived from error bands.
  //todo: It's not clear how we want to handle shape only stuff here. GetSysErrorMatricesNames does not include them but that might be fine.
  //
  // NOTE(JVY): Copy over also the shape-only matrices. 
  //            After all, even if they're calculated from bands, why would it hurt to have them copied ???
  //            We can, of course, discuss and iterate on this some more, but somehow this needs to be fixed.
  //
  std::vector<std::string> allSysNames = h.GetSysErrorMatricesNames();
  for( std::vector<std::string>::iterator name = allSysNames.begin(); name != allSysNames.end(); ++name )
  {
    //this restricts us to only the special matrices
    if( h.HasErrorMatrix(*name) )
      fSysErrorMatrix[*name] = new TMatrixD( h.GetSysErrorMatrix(*name) );
    std::string sname = *name + "_asShape";
    if ( h.HasErrorMatrix( sname ) )
      fSysErrorMatrix[sname] = new TMatrixD( h.GetSysErrorMatrix(*name,false,true) );
  }

  //add removed "special" error matrices
  //
  // NOTE(JVY): Same with shape-only as above.
  //
  std::vector<std::string> removedSysNames = h.GetRemovedSysErrorMatricesNames();
  for( std::vector<std::string>::iterator name = removedSysNames.begin(); name != removedSysNames.end(); ++name )
  {
     fRemovedSysErrorMatrix[*name] = new TMatrixD( h.GetSysErrorMatrix(*name) );
{'fraction_non_alphanumeric': 0.2107823267126064, 'fraction_numerical': 0.010336441021483584, 'mean_word_length': 3.384273656152821, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5480620', 'n_tokens_mistral': 3344, 'n_tokens_neox': 3187, 'n_words': 812}