#include <SFramework/TSHistogramExporter.h>
#include <SFramework/TSUtils.h>

#include "QFramework/TQStringUtils.h"
#include "QFramework/TQHistogramUtils.h"
#include "QFramework/TQUtils.h"
#include "QFramework/TQIterator.h"

#include "RooProduct.h"
#include "RooRealIntegral.h"
#include "RooSimultaneous.h"
#include "RooAddPdf.h"
#include "RooConstVar.h"
#include "RooProdPdf.h"
#include "RooBinning.h"

#include "TH1.h"
#include "TAxis.h"
#include "TMath.h"

// #define _DEBUG_

#ifdef __cpp_generic_lambdas
#if __cpp_generic_lambdas >= 201304
#define HAS_GENERIC_LAMBDAS
#endif
#endif

namespace {
  /*
  void info(const TString& message) {
    std::cout << "SFramework/TSUtils: " << message.Data() << std::endl;
  }
   void error(const TString& message) {
     info(TQStringUtils::makeBoldRed(TString("ERROR: ") + message));
   }
  void warn(const TString& message) {
    info(TQStringUtils::makeBoldYellow(TString("WARNING: ") + message));
  }
  */
}

#include "QFramework/TQLibrary.h"

ClassImp(TSHistogramExporter)

RooExpectedEvents::RooExpectedEvents(const char* name, const char* title, RooAbsPdf& pdf, const RooArgSet& normSet) : RooAbsReal(name,title),
  _pdf(pdf),
  _normSet(normSet)
{
  addServer(_pdf);
}

RooExpectedEvents::~RooExpectedEvents(){}

double RooExpectedEvents::evaluate() const {
  return this->_pdf.expectedEvents(_normSet);
}

TObject* RooExpectedEvents::clone(const char*) const {
  return new RooExpectedEvents(this->GetName(),this->GetTitle(),_pdf,_normSet);
}

ClassImp(RooExpectedEvents)

#ifdef HAS_GENERIC_LAMBDAS
namespace {
  namespace SFINAE {
    // SFINAE test
    // https://stackoverflow.com/questions/257288/is-it-possible-to-write-a-template-to-check-for-a-functions-existence


    class true_val    {char dummy[1];};
    class false_val   {char dummy[2];};

    template <typename T>
    class hasCompSelectSwitch {
    public:
      template <typename C> static true_val    test(decltype(&C::setAllowComponentSelection));
      template <typename C> static false_val   test(...);

      enum { value = sizeof(test<T>(0)) == sizeof(true_val) };
    };

    // static_if
    //https://stackoverflow.com/questions/37617677/implementing-a-compile-time-static-if-logic-for-different-string-types-in-a-co
    template <typename T, typename F>          auto static_if(std::true_type, T t, F /*f*/) { return t; }
    template <typename T, typename F>          auto static_if(std::false_type, T /*t*/, F f) { return f; }
    template <bool B, typename T, typename F>  auto static_if(T t, F f) { return static_if(std::integral_constant<bool, B>{}, t, f); }
    template <bool B, typename T>              auto static_if(T t) { return static_if(std::integral_constant<bool, B>{}, t, [](auto&&...){}); }

    template <class C> inline void trySetAllowComponentSelection(C* integral, bool val){
      static_if<hasCompSelectSwitch<C>::value>
        ([&](auto* ri) {ri->setAllowComponentSelection(val); })
        (integral);
    }
  }
}
#endif

namespace {


  struct Exposer : RooAbsReal {
    using RooAbsReal::plotOnCompSelect;
  };

  template<class T> bool has(const std::vector<T> v,T x){
    for(const auto& e:v){
      if(e==x) return true;
    }
    return false;
  }

  void plotOnCompSelect(const RooAbsReal* thisObj,RooArgSet* selNodes){
    (thisObj->*&Exposer::plotOnCompSelect)(selNodes);
  }


  void findUniqueProdComponents(RooProdPdf* Pdf, RooArgSet& components, const TString& filter) {
    static int counter = 0;
    counter++;

    if (counter > 50) {
      throw std::runtime_error("FindUniqueProdComponents detected infinite loop. Please check.");
    }

    RooArgList pdfList = Pdf->pdfList();
    if (pdfList.getSize() == 1) {
      components.add(pdfList);
    } else {
      ROOFIT_ITERATE(pdfList,RooAbsArg,nextArg){
        RooProdPdf* pdf = (RooProdPdf*)nextArg;
        if(pdf->IsA() != RooProdPdf::Class()){
          if(TQStringUtils::matches(pdf->GetName(),filter)) components.add(*pdf);
          continue;
        }
        findUniqueProdComponents(pdf, components, filter);
      }
    }
    counter = 0;
  }
}


TSHistogramExporter::TSHistogramExporter(TQFolder* style, RooFitResult* fr) :
  styleModel(style),
  fitResult(fr)
{
  // default constructor
}

TSHistogramExporter::~TSHistogramExporter(){
}

RooCategory* TSHistogramExporter::Region::getChannelCategory(){
  return TSHistogramExporter::getCategories(this->simPdf);
}

void TSHistogramExporter::Region::select(){
  if(this->getChannelCategory()){
    this->getChannelCategory()->setLabel(this->getName());
  }
}

TSHistogramExporter::Region::~Region(){
}

bool TSHistogramExporter::Region::isCombined() const {
  return this->combined;
}

const RooArgSet& TSHistogramExporter::Region::getObservables() const { return this->observables; }

std::vector<int> TSHistogramExporter::Region::getRemovedBins(RooAbsReal* obs) const {
  if(removedBins.find(obs) != removedBins.end()){
    return this->removedBins.at(obs);
  }
  return std::vector<int>();
}

bool TSHistogramExporter::Region::isRemovedBin(RooAbsReal* obs, int idx) const {
  if(removedBins.find(obs) != removedBins.end()){
    const auto& v = removedBins.at(obs);
    if(std::find(v.begin(),v.end(),idx) != v.end()){
      return true;
    }
  }
  return false;
}

void TSHistogramExporter::Region::removeBins(RooAbsReal* obs, const std::vector<int> bins) {
  removedBins[obs] = bins;
}
const TString& TSHistogramExporter::Region::getName() const { return this->name; }
TSHistogramExporter::Region::Region(const TString& n, RooAbsPdf* p, RooArgSet* obs, bool combined) : name(n), func(p), observables(*obs), simPdf(0), combined(combined)
{
  // do nothing
}
TSHistogramExporter::Region::Region(const TString& n, RooSimultaneous* sim, RooRealSumPdf* p, RooArgSet* obs, bool combined) : Region(n,(RooAbsPdf*)p,obs,combined) {
  this->simPdf = sim;
  addSamples(p);
}
RooDataSet* TSHistogramExporter::Region::getData(const TString& name, int index) const {
  return this->datasets.at(name)[index];
}
int TSHistogramExporter::Region::nData(const TString& name) const {
  return this->datasets.at(name).size();
}

std::vector<TString> TSHistogramExporter::Region::allData() const {
  std::vector<TString> retval;
  for(auto it: datasets){
    retval.push_back(it.first);
  }
  return retval;
}
std::vector<TString> TSHistogramExporter::Region::allSamples() const {
  std::vector<TString> retval;
  for(auto it: samples){
    retval.push_back(it.first);
  }
  return retval;
}
void TSHistogramExporter::Region::print() const {
  std::cout << "Region '" << this->name << "': " << func->GetName() << " " << ( this->combined ? "combined " : "single" ) << " observables: ";
  ROOFIT_ITERATE(observables,RooAbsArg,obj){
    RooRealVar* var = dynamic_cast<RooRealVar*>(obj);
    if(var){
      std::cout << var->GetName() << ",";
    }
  }
  std::cout <<std::endl;
  for(const auto& it:this->samples){
    std::cout << "  " << it.first << ": ";
    for(const auto& s:it.second){
      std::cout << s->GetName() << " ";
    }
    std::cout << std::endl;
  }
  for(const auto& it:this->datasets){
    std::cout << "  " << it.first << ": ";
    for(const auto& d:it.second){
      std::cout << d->GetName() << " ";
    }
    std::cout << std::endl;
  }
}
RooAbsPdf* TSHistogramExporter::Region::getPdf() const { return const_cast<RooAbsPdf*>(func); }
void TSHistogramExporter::Region::addSample(const TString& name, RooAbsReal* obj){
  if(!has(this->samples[name],obj))
    this->samples[name].push_back(obj);
}
void TSHistogramExporter::Region::addData(const TString& name, RooDataSet* obj){
  if(!has(this->datasets[name],obj))
    this->datasets[name].push_back(obj);
}
void TSHistogramExporter::Region::addSamples(const Region* other){
  if(!other) return;
  for(const auto& it:other->samples){
    for(const auto& s:it.second){
      this->addSample(it.first,s);
    }
  }
}
void TSHistogramExporter::Region::addSamples(RooRealSumPdf* sumPdf){
  if(!sumPdf) return;
  TString regionname(sumPdf->GetName());
  TQStringUtils::removeTrailing(regionname,"_model");
  ROOFIT_ITERATE(sumPdf->funcList(),RooAbsArg,obj){
    RooProduct* prod = dynamic_cast<RooProduct*>(obj);
    DEBUGclass("investigating element '%s'",obj->GetName());
    if(!prod){
      throw std::runtime_error(TString::Format("object %s is not of type 'RooProduct'",obj->GetName()).Data());
    }
    TString pname(prod->GetName());
    int start = pname.Index(regionname);
    if(start < 0){
      start = pname.Index(regionname(0,regionname.First("_")));
    }
    if(start >= 0){
      pname.Remove(start-1,pname.Length()-start+1);
    } else {
      throw std::runtime_error(TString::Format("unable to isolate region name '%s' from '%s'",regionname.Data(),pname.Data()).Data());
    }
    addSample(pname,prod);
  }
}
double TSHistogramExporter::Region::expectedEvents() const {
  return func->expectedEvents(this->getObservables());
}

TH1* TSHistogramExporter::Region::makeHistogram(const TString& n,RooArgList& mylist) const {
  if(this->isCombined()) return NULL;
  if (mylist.getSize()==1){
    RooRealVar* xvar= dynamic_cast<RooRealVar*> (mylist.at(0));
    std::list<Double_t>* bl = func->binBoundaries(*xvar,xvar->getMin(),xvar->getMax()) ;
    Double_t* ba = new Double_t[bl->size()+1] ; int i=0 ;
    for (auto it=bl->begin() ; it!=bl->end() ; ++it) {
      ba[i++] = *it ;
    }
    if(ba[i-1] < xvar->getMax()*(1-1e-8)){
      ba[i]=xvar->getMax();
      i++;
    }
    TH1F* histo =  new TH1F(n, xvar->GetTitle(), i-1, ba);
    histo->GetXaxis()->SetTitle(xvar->GetTitle());
    delete[] ba ;
    delete bl;
    return histo;

  } else if (mylist.getSize()==2){
    RooRealVar* xvar= dynamic_cast<RooRealVar*> (mylist.at(0));
    std::list<Double_t>* bl = func->binBoundaries(*xvar,xvar->getMin(),xvar->getMax()) ;
    Double_t* ba = new Double_t[bl->size()+1] ; int i=0 ;
    RooRealVar* yvar= dynamic_cast<RooRealVar*> (mylist.at(1));
    std::list<Double_t>* bl_y = func->binBoundaries(*yvar,yvar->getMin(),yvar->getMax()) ;
    Double_t* ba_y = new Double_t[bl_y->size()+1] ; int j=0 ;
    for (auto it=bl->begin() ; it!=bl->end() ; ++it) {
      ba[i++] = *it ;
    }
    if(ba[i-1] < xvar->getMax()*(1-1e-8)){
      ba[i]=xvar->getMax();
      i++;
    }
    for (auto it_y=bl_y->begin() ; it_y!=bl_y->end() ; ++it_y) {
      ba_y[j++] = *it_y ;
    }
    if(ba_y[j-1] < yvar->getMax()*(1-1e-8)){
      ba_y[j]=yvar->getMax();
      j++;
    }
    TH2F* histo2D =  new TH2F(n, n, i-1, ba, j-1, ba_y);
    histo2D->GetXaxis()->SetTitle(xvar->GetTitle());
    histo2D->GetYaxis()->SetTitle(yvar->GetTitle());
    delete[] ba ;
    delete bl;
    delete[] ba_y ;
    delete bl_y;
    return histo2D;
  }
  return NULL;
}

RooAbsReal* RooPdfEvaluator::getFunc(){
  return this->_func;
}

RooPdfEvaluator::RooPdfEvaluator(const RooPdfEvaluator& other):RooAbsTestStatistic(other),
  nset(other.nset),
  params(other.params),
  covMat(other.covMat),
  corrMat(other.corrMat),
  threshold(other.threshold),
  ccheck(other.ccheck)
{
  this->_func = other._func;
  this->_data = NULL;
  this->_nEvents = 1;
  this->_setNum = 1;
  this->_numSets = 1;
  this->_hesse = (RooAbsPdf*)(other._hesse->clone());
}


RooPdfEvaluator::RooPdfEvaluator(RooAbsReal* f, const RooFitResult* fr, double t,double _ccheck) :
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,26,00)
  RooAbsTestStatistic("tmp","tmp",*f,*(new RooDataSet()),RooArgSet(),Configuration()),
#endif
  _hesse(NULL),
  nset(NULL),
  params(NULL),
  threshold(t),
  ccheck(_ccheck)
{
  this->_data = NULL;
  this->_nEvents = 1;
  this->_setNum = 1;
  this->_numSets = 1;
  if(f && fr){
    DEBUGclass("initializing Pdf evaluator");          
    this->_func = f;
    RooArgSet* parset = _func->getObservables(fr->floatParsFinal());
    this->params = new RooArgList();
    ROOFIT_ITERATE(fr->floatParsFinal(),RooAbsArg,obj){
      const RooRealVar* comp = dynamic_cast<const RooRealVar*>(obj);
      if(!comp) continue;
      RooRealVar* par = dynamic_cast<RooRealVar*>(parset->find(comp->GetName()));
      if(!par){
        continue;
      }
      this->params->add(*par) ;
      par->setVal(comp->getVal());
      if (comp->getError() > 0.) {
        par->setError(comp->getError());
      }
      if (comp->getErrorLo() > 0. and comp->getErrorHi() > 0.) {
        par->setAsymError(comp->getErrorLo(),comp->getErrorHi());
      }
    }
    int n = params->getSize();
    covMat.ResizeTo(n,n);
    corrMat.ResizeTo(n,n);
    DEBUGclass("obtaining covariance matrix");              
    this->covMat = TSUtils::retrieveCovariances(params,fr);
    DEBUGclass("obtaining correlation matrix");                  
    this->corrMat = TSUtils::getCorrelationMatrix(this->covMat);
    delete parset;
    DEBUGclass("creating Hesse Pdf");                      
    this->_hesse = TSUtils::createHessePdf(fr,this->params);
  } else if(!fr){
    throw std::runtime_error("NULL fit result passed to RooPdfEvaluator!");
  }
  DEBUGclass("done constructing reader");                          
}

TObject* RooPdfEvaluator::clone(const char*) const {
  return new RooPdfEvaluator(*this);
}

Double_t RooPdfEvaluator::evaluatePartition(
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,20,00)
                                            size_t /*firstEvent*/, size_t /*lastEvent*/, size_t /*stepSize*/
#else
                                            Int_t /*firstEvent*/, Int_t /*lastEvent*/, Int_t /*stepSize*/
#endif
                                            ) const {
  return this->_func->getVal(this->nset);
}


int RooPdfEvaluator::getParameterIndex(const char* pname) const{
  if(!this->params) return -1;
  for(int i=0; i<this->params->getSize(); ++i){
    if(TQStringUtils::equal(pname,params->at(i)->GetName())) return i;
  }
  return -1;
}

void RooPdfEvaluator::setCorrelation(const char* p1, const char* p2, double val){
  if(!this->params) return;
  for(int i=0; i<this->params->getSize(); ++i){
    for(int j=0; j<this->params->getSize(); ++j){
      if(i==j) continue;
      if(TQStringUtils::matches(params->at(i)->GetName(),p1) && TQStringUtils::matches(params->at(j)->GetName(),p2)){
        double v1 = sqrt(this->covMat(i,i));
        double v2 = sqrt(this->covMat(j,j));
        this->covMat (i,j) = v1*v2*val;;
        this->covMat (j,i) = v1*v2*val;;
        this->corrMat(i,j) = val;
        this->corrMat(j,i) = val;
      }
    }
  }
}

double RooPdfEvaluator::getCorrelation(const char* p1, const char* p2) const {
  int i1 = this->getParameterIndex(p1);
  int i2 = this->getParameterIndex(p2);
  if(i1<0 || i2 < 0) return 0;
  return this->corrMat(i1,i2);
}

RooPdfEvaluator::~RooPdfEvaluator(){
  if(this->params) delete this->params ;
  if(this->nset)   delete this->nset ;
  if(this->_hesse) delete this->_hesse;
}

namespace {
  void getAxes(TH1* hist, const RooArgList& plotVars, int& xbins, RooRealVar*&xvar, TAxis*& xaxis, int& ybins, RooRealVar*&yvar, TAxis*& yaxis, int& zbins, RooRealVar*&zvar, TAxis*& zaxis){
    // Check that the number of plotVars matches the input histogram's dimension
    xbins=0;
    ybins=1;
    zbins=1;
    switch(hist->GetDimension()) {
    case 3:
      zbins= hist->GetNbinsZ();
      zvar = (RooRealVar*)(plotVars.at(2));
      zvar->setValueDirty();
      zaxis= hist->GetZaxis();
      assert(0 != zvar && 0 != zaxis);
      // [[fallthrough]];
      // fall through
    case 2:
      ybins= hist->GetNbinsY();
      yvar = (RooRealVar*)(plotVars.at(1));
      yvar->setValueDirty();
      yaxis= hist->GetYaxis();
      assert(0 != yvar && 0 != yaxis);
      // [[fallthrough]];
      // fall through
    case 1:
      xbins= hist->GetNbinsX();
      xvar = (RooRealVar*)(plotVars.at(0));
      xvar->setValueDirty();
      xaxis= hist->GetXaxis();
      assert(0 != xvar && 0 != xaxis);
      break;
    default:
      throw std::runtime_error("fillHistogram: wrong dimensionality");
      break;
    }

  }

  void setNextBin(TH1* hist, int bin, int& xbin, int xbins, RooRealVar*xvar, TAxis* xaxis, int& ybin, int ybins, RooRealVar*yvar, TAxis* yaxis, int& zbin, int /*zbins*/, RooRealVar*zvar, TAxis* zaxis){
    switch(hist->GetDimension()) {
    case 3:
      if(bin % (xbins*ybins) == 0) {
        zbin++;
        zvar->setVal(zaxis->GetBinCenter(zbin));
      }
      // [[fallthrough]];
      // fall through
    case 2:
      if(bin % xbins == 0) {
        ybin= (ybin%ybins) + 1;
        yvar->setVal(yaxis->GetBinCenter(ybin));
      }
      // [[fallthrough]];
      // fall through
    case 1:
      xbin= (xbin%xbins) + 1;
      xvar->setVal(xaxis->GetBinCenter(xbin));
      break;
    default:
      throw std::runtime_error("RooAbsReal::fillHistogram: Internal Error!");
      break;
    }
  }
}


//void RooPdfEvaluator::fillHistogram(TH1 *hist,const RooArgList& plotVars) const {
void RooPdfEvaluator::fillHistogram(TH1 *hist, const RooArgList& plotVars, ErrorCalculation mode) {
  // Prepare to loop over the histogram bins
  Int_t xbins,ybins,zbins;
  RooRealVar *xvar = NULL;
  RooRealVar *yvar = NULL;
  RooRealVar *zvar = NULL;
  TAxis *xaxis = NULL;
  TAxis *yaxis = NULL;
  TAxis *zaxis = NULL;
  getAxes(hist,plotVars,xbins,xvar,xaxis,ybins,yvar,yaxis,zbins,zvar,zaxis);
  Int_t bins= xbins*ybins*zbins;
  if(mode == SamplingErrors && _hesse){
    double Z = 1;
    int n = Int_t(100./TMath::Erfc(Z/sqrt(2.))) ;
    if (n<100) n=100 ;
    RooAbsCollection* origVals = this->params->snapshot();
    DEBUGclass("generating %d samples",n);
    RooDataSet* samples = _hesse->generate(*(this->params),n) ;
    std::vector<double> sum2(bins);
    DEBUGclass("evaluating %d samples",n);
    for (int i=0 ; i<samples->numEntries() ; ++i) {
      *(this->params) = (*samples->get(i));
      int xbin=0,ybin=0,zbin=0;
      for(Int_t bin= 0; bin < bins; bin++) {
        setNextBin(hist,bin,xbin,xbins,xvar,xaxis,ybin,ybins,yvar,yaxis,zbin,zbins,zvar,zaxis);
        this->setValueDirty();
        Double_t result = this->getVal();
        sum2[bin] += result*result;
      }
    }
    for(int i=0; i<this->params->getSize(); ++i){
      RooRealVar* v = (RooRealVar*)(this->params->at(i));
      v->setVal(((RooRealVar*)origVals->find(v->GetName()))->getVal());
    }
    delete samples;
    delete origVals;
    int xbin=0,ybin=0,zbin=0;
    for(Int_t bin= 0; bin < bins; bin++) {
      setNextBin(hist,bin,xbin,xbins,xvar,xaxis,ybin,ybins,yvar,yaxis,zbin,zbins,zvar,zaxis);
      this->setValueDirty();
      Double_t result = this->getVal();
      int binid = hist->GetBin(xbin,ybin,zbin);
      hist->SetBinContent(binid,result);
      hist->SetBinError(binid,sqrt(sum2[bin])/n);
    }
  } else {
    int xbin=0,ybin=0,zbin=0;
    for(Int_t bin= 0; bin < bins; bin++) {
      setNextBin(hist,bin,xbin,xbins,xvar,xaxis,ybin,ybins,yvar,yaxis,zbin,zbins,zvar,zaxis);
      this->setValueDirty();
      Double_t result = this->getVal();
      Double_t unc = (mode == NoErrors || result < 1e-6) ? 0. : this->getError(mode);
      int binid = hist->GetBin(xbin,ybin,zbin);
      hist->SetBinContent(binid,result);
      hist->SetBinError  (binid,unc);
    }
  }
}

double  RooPdfEvaluator::getValue() const {
  return this->getVal();
}

double RooPdfEvaluator::getError(ErrorCalculation mode) {
  // Calculate error on self by propagated errors on parameters with correlations as given by fit result
  // Mode "NoErrors":
  // return 0 always
  //
  // Mode "LinearErrors"
  // The linearly propagated error is calculated as follows
  //                                    T
  // error(x) = F_a(x) * Corr(a,a') F_a'(x)
  //
  // where     F_a(x) = [ f(x,a+da) - f(x,a-da) ] / 2, with f(x) this function and 'da' taken from the fit result
  //       Corr(a,a') = the correlation matrix from the fit result
  //
  // side effects: after application of this function, all parameters will be set to the fit result values
  //
  // Mode "SamplingErrors"
  // Throw toys to determine the uncertainty on the result

  switch(mode){
  case NoErrors: {
    return 0.;
    break;
  }
  case LinearErrors: {
    DEBUGclass("getting variations");
    const TVectorD F(this->getVariations());
    if(this->allEntriesZero(F)) return 0.;
    // Calculate error in linear approximation from variations and correlation coefficient
    DEBUGclass("multiplying with covariance matrix");
    Double_t sum = F*(this->corrMat*F) ;
    // nExpected already contained in sum, as getVariations uses getVal internally
    DEBUGclass("returning");
    return sqrt(sum) ;
    break;
  }
  case SamplingErrors: {
    if(!_hesse) return 0.;
     // Generate 100 random parameter points distributed according to fit result covariance matrix
    double Z = 1;
    int n = Int_t(100./TMath::Erfc(Z/sqrt(2.))) ;
    if (n<100) n=100 ;

    RooAbsCollection* origVals = this->params->snapshot();
    DEBUGclass("generating %d samples",n);
    RooDataSet* d = _hesse->generate(*(this->params),n) ;
    DEBUGclass("evaluating %d samples",n);
    double sum=0;
    double sum2=0;
    for (int i=0 ; i<d->numEntries() ; ++i) {
      *(this->params) = (*d->get(i));
      double val = this->getValue();
      sum+=val;
      sum2+=(val*val);
    }
    for(int i=0; i<this->params->getSize(); ++i){
      RooRealVar* v = (RooRealVar*)(this->params->at(i));
      v->setVal(((RooRealVar*)origVals->find(v->GetName()))->getVal());
    }
    DEBUGclass("returning");
    delete d;
    delete origVals;
    return sqrt(sum2/n);
    break;
  }
  }
  return 0.;
}

bool RooPdfEvaluator::allEntriesZero(const TVectorD& v) const {
  for(int i=0; i<v.GetNrows(); ++i){
    if(v[i]>this->threshold) return false;
  }
  return true;
}


void RooPdfEvaluator::setDirty() {
  if(!this->_func) return;
  if(!this->params){
    throw std::runtime_error("no parameters available!");
  }
  for (Int_t ivar=0 ; ivar<this->params->getSize() ; ++ivar) {
    RooRealVar* v = (RooRealVar*)(this->params->at(ivar));
    v->setValueDirty();
  }
//  RooArgSet* cache = const_cast<RooArgSet*>(&(this->_cachedNodes));
//  cache->removeAll();
  this->setValueDirty();
  this->_func->setValueDirty();
  this->_func->getVal();
}

TVectorD RooPdfEvaluator::getVariations() {
  // Make vector of variations
  if(!this->params){
    throw std::runtime_error("no parameters available!");
  }
  TVectorD F(this->params->getSize()) ;
  this->setValueDirty();
  Double_t nom = this->getVal();
  if(!TQUtils::isNum(nom)){
    std::cerr << "  WARNING: non-numeric nominal value encounterd for '" << this->getFunc()->GetName() << "', using 0 instead!" << std::endl;
    nom = 0;
  }
  for (Int_t ivar=0 ; ivar<this->params->getSize() ; ++ivar) {
    RooRealVar* v = (RooRealVar*)(this->params->at(ivar));
    Double_t cenVal = v->getVal() ;
    Double_t errVal = sqrt(this->covMat(ivar,ivar));
    double var = 0;
    if(TQUtils::isNum(errVal)){
      // Make Plus variation
      v->setVal(cenVal+errVal) ;
      this->setValueDirty();
      const double plusVar = this->getVal();
      // Make Minus variation
      v->setVal(cenVal-errVal) ;
      this->setValueDirty();
      const double minusVar = this->getVal();
      v->setVal(cenVal) ;
      DEBUG("  varying %s from %f by +/-%f: %f %f %f",v->GetName(),cenVal,errVal,nom,plusVar,minusVar);
      if(TQUtils::isNum(plusVar) && TQUtils::isNum(minusVar)){
        var = (plusVar-minusVar)/2 ;
      } else if(TQUtils::isNum(plusVar)){
        var = plusVar-nom;
      } else if (TQUtils::isNum(minusVar)){
        var = nom-minusVar;
      }
    }
    F[ivar] = var;
  }
  return F;
}



void TSHistogramExporter::Region::collectSelectionVars(const TString& nfPattern) {
  RooArgSet* allVars(this->getPdf()->getParameters((RooArgSet*)0));
  //allVars->Print("v");
  for(const auto& s:this->samples){
    TString sname(s.first);
    TString pattern(nfPattern);
    pattern.ReplaceAll("$(SAMPLENAME)",sname);
    RooAbsArg* arg = allVars->find(pattern);
    if(!arg) throw std::runtime_error(TString::Format("unable to find selection var '%s' for sample '%s'",pattern.Data(),sname.Data()).Data());
    RooRealVar* var = dynamic_cast<RooRealVar*>(arg);
    if(!var) throw std::runtime_error(TString::Format("find selection var '%s' for sample '%s' is not of type RooRealVar!",pattern.Data(),sname.Data()).Data());
    this->selectionVars[sname] = var;
  }
  delete allVars;
}

TString TSHistogramExporter::Region::getSelectionVariableNames(const std::vector<TString>& keys) const {
  // in legacy mode, we expect there to be an "NF" parameter that we can use to turn on/off parts of the PDF
  TString compNames;
  bool first = true;
  for(const auto& p:keys){
    RooRealVar* v = selectionVars.at(p);
    if(!first){
      compNames.Append(",");
    }
    first = false;
    compNames.Append(v->GetName());
  }
  return compNames;
}

void TSHistogramExporter::Region::selectComponentsLegacy(const std::vector<TString>& keys) const {
  // in legacy mode, we expect there to be an "NF" parameter that we can use to turn on/off parts of the PDF
  for(const auto& v:selectionVars){
    v.second->setVal(0);
  }
  for(const auto& k:keys){
    RooRealVar* var = selectionVars.at(k);
    if(!var){
      throw std::runtime_error(TString::Format("unable to retrieve parameter for sample '%s'",k.Data()).Data());
    }
    var->setVal(1);
  }
}

TString TSHistogramExporter::Region::getComponentNames(const std::vector<TString>& keys) const {
  TString compNames;
  bool first = true;
  for(const auto& p:keys){
    for(const auto& s:samples.at(p)){
      if(!first){
        compNames.Append(",");
      }
      first = false;
      compNames.Append(s->GetName());
    }
  }
  return compNames;
}

RooArgSet* TSHistogramExporter::selectBranchNodes(RooAbsReal* func, const TString& compNames){
 // Get complete set of tree branch nodes
  RooArgSet branchNodeSet ;
  func->branchNodeServerList(&branchNodeSet) ;

  // Discard any non-RooAbsReal nodes
  ROOFIT_ITERATE(branchNodeSet,RooAbsArg,arg){
    if (!dynamic_cast<RooAbsReal*>(arg)) {
      branchNodeSet.remove(*arg) ;
    }
  }

  return (RooArgSet*)(branchNodeSet.selectByName(compNames));
}

void TSHistogramExporter::Region::selectComponents(const std::vector<TString>& keys) const {
  TString compNames = this->getComponentNames(keys);
  TSHistogramExporter::selectComponents(this->func,compNames);

}

void TSHistogramExporter::selectComponents(RooAbsReal* func, const TString& compNames) {
  // in the component selection mode, we use RooFits internal component selection mechanism to select parts of the PDF
  RooArgSet* selected = TSHistogramExporter::selectBranchNodes(func,compNames);
  plotOnCompSelect(func,selected);
  delete selected;
}

void TSHistogramExporter::Region::unselectComponentsLegacy() const {
  for(const auto& v:selectionVars){
    v.second->setVal(1);
  }
}
void TSHistogramExporter::Region::unselectComponents() const {
  TSHistogramExporter::unselectComponents(func);
}

void TSHistogramExporter::unselectComponents(RooAbsReal* func) {
  plotOnCompSelect(func,0) ;
}


RooAbsReal* TSHistogramExporter::Region::createIntegral(const TString& nameAppend, const RooArgSet& normSet, const RooArgSet& projectedVars) const {
  TString resultname = this->getName()+nameAppend;
  this->func->getVal(normSet);
  TString nEventsName = this->getName()+"_nEvents";
  RooExpectedEvents* nEvents = new RooExpectedEvents(nEventsName,nEventsName,*(this->func),normSet);
  TString intname=TString::Format("%s_Int",this->func->GetName());
  RooArgList terms;
  RooRealIntegral* integral = new RooRealIntegral(intname,intname,*(this->func),projectedVars,&normSet);
#ifdef HAS_GENERIC_LAMBDAS
  ::SFINAE::trySetAllowComponentSelection(integral,true);
#endif
  terms.add(*integral);
  terms.add(*nEvents);
  RooProduct* prod = new RooProduct(resultname.Data(),resultname.Data(),terms);
  return prod;
}

RooAbsReal* TSHistogramExporter::Region::createIntegral() const {
  TString resultname = this->getName()+"_yield";
  this->func->getVal(this->getObservables());
  TString nEventsName = this->getName()+"_nEvents";
  RooExpectedEvents* nEvents = new RooExpectedEvents(nEventsName,nEventsName,*(this->func),this->getObservables());
  TString intname=TString::Format("%s_Int",this->func->GetName());
  RooArgList terms;
  RooRealIntegral* integral = new RooRealIntegral(intname,intname,*(this->func),this->getObservables(),&(this->getObservables()));
#ifdef HAS_GENERIC_LAMBDAS
  ::SFINAE::trySetAllowComponentSelection(integral,true);
#endif
  terms.add(*integral);
  terms.add(*nEvents);
  RooProduct* prod = new RooProduct(resultname.Data(),resultname.Data(),terms);
  return prod;
}

bool TSHistogramExporter::getMC(TDirectory* dir, Region* region, std::map< const TString, std::vector<TString> > samples, int calculateErrors, double checkThreshold){
  // obtain the MC histograms
  DEBUGclass("initializing %s with calculate errors %d",region->getName().Data(), calculateErrors);
  #ifdef _DEBUG_
  region->print();
  #endif

  bool legacyMode = !nfPattern.IsNull();
  if(legacyMode){
    region->collectSelectionVars(nfPattern);
    region->unselectComponentsLegacy();
#ifdef HAS_GENERIC_LAMBDAS
  } else if(::SFINAE::hasCompSelectSwitch<RooRealIntegral>::value){
    region->unselectComponents();
#endif
  } else {
    throw std::runtime_error("RooRealIntegral does not have a setAllowComponentSelection member function, cannot use CompSelect mechanism - please use legacy mechanism suppling an NF pattern!");
  }

  // get the number of events
  double nExp = region->expectedEvents();
  if(nExp < 0){
    throw std::runtime_error(TString::Format("number of expected events in region %s is %g < 0!",region->getName().Data(),nExp).Data());
  }


  // sort out the observables
  RooArgSet observables(region->getObservables());
  RooArgSet projectedVars;
  RooArgList x(region->getObservables());

  // create helper objects
  RooAbsReal *projected = NULL;
  RooArgSet normSet;
  if(!legacyMode) normSet.add(observables);
  if(!region->isCombined()){
    projected               = region->createIntegral("_projected",normSet,projectedVars);
  }
  RooAbsReal* integral = region->createIntegral();

  double epsilon = 1e-12;
  DEBUGclass("creating integral reader");
  RooPdfEvaluator intReader (integral, fitResult,epsilon,checkThreshold);
  DEBUGclass("creating histogram reader");
  RooPdfEvaluator histReader(projected,fitResult,epsilon,checkThreshold);

  DEBUGclass("decorrelating");    
  std::vector<TString> decorrelatePars = this->getTagVString("decorrelate");
  for(const auto& p1:decorrelatePars){
    for(const auto& p2:decorrelatePars){
      intReader .setCorrelation(p1,p2,0);
      histReader.setCorrelation(p1,p2,0);
    }
  }
  DEBUGclass("correlating");      
  std::vector<TString> correlatePars = this->getTagVString("correlate");
  for(const auto& p1:correlatePars){
    for(const auto& p2:correlatePars){
      intReader .setCorrelation(p1,p2,1);
      histReader.setCorrelation(p1,p2,1);
    }
  }

  // loop over the regions
  double sumEvents = 0;
  int nSummedSamples = 0;
  std::vector<TH1*> histograms;
  for(const auto& sample:samples){
    RooLinkedList args;

    DEBUGclass(" evaluating sample %s",sample.first.Data());

    /////////////////////////////////////
    // obtain the results from the Pdf
    /////////////////////////////////////
    TH1* hist = 0;
    if(!region->isCombined()){
      DEBUGclass("   creating histogram");
      hist = region->makeHistogram(sample.first,x);
      if (!hist){
        std::cout << "  WARNING: unable to create histogram " << sample.first << std::endl;
      } else {
        hist->SetDirectory(dir);
        //checkConsistency(hist,x);
      }
    }

    DEBUGclass("   selecting components");
    if(!legacyMode){
      region->selectComponents      (sample.second);
    } else {
      region->selectComponentsLegacy(sample.second);
    }

    intReader.setDirty();
    DEBUGclass("   evaluating integral");
    double yieldVal = intReader.getVal();
    DEBUGclass("   evaluating integral uncertainty");

    double yieldErr = intReader.getError((RooPdfEvaluator::ErrorCalculation)calculateErrors);
    if(!TQUtils::isNum(yieldErr)){
      throw std::runtime_error(TString::Format("encountered non-numeric error in %s using fitResult '%s'",integral->GetName(),fitResult->GetName()).Data());
    }

    histReader.setDirty();
    if(hist){
      DEBUGclass("   filling histogram");
      histReader.fillHistogram(hist,x, (RooPdfEvaluator::ErrorCalculation)calculateErrors);
    }

    if(!legacyMode){
      region->unselectComponents();
    } else {
      region->unselectComponentsLegacy();
    }

    /////////////////////////////////////
    // sanitize the histograms
    /////////////////////////////////////

    DEBUGclass("   finalizing");

    if(hist){
      histograms.push_back(hist);
      hist->SetName(sample.first);
      hist->SetTitle(sample.first);

      // apply the bin width correction
      double nevents_hist = hist->Integral();
      if(nevents_hist>0){
        double density_hist = hist->Integral("WIDTH");
        double scaling = density_hist/nevents_hist;
        hist->Scale(scaling);
      } else {
        hist->Reset();
      }

      double epsilon_total = epsilon * hist->GetNbinsX() * samples.size();
      if(hist->Integral() <= epsilon_total && yieldVal <= epsilon_total){
        // check if we have any events
        hist->Reset();
        yieldVal = 0;
        yieldErr = 0;
      } else if(!TMath::AreEqualRel(hist->Integral(),yieldVal,1E-04)){
        // check if the yield and differential histograms agree
        std::cout << TString::Format("  WARNING: integral of histogram '%s' is %g and does not match total yield %g, correcting total yield and error neglecting bin-to-bin correlations!",hist->GetName(),hist->Integral(),yieldVal) << std::endl;
        yieldVal = TQHistogramUtils::getIntegralAndError(hist,yieldErr);
      } else {
        // if yield and differential agree in integral and the histogram has only one bin, we can run a few additional checks
        if(hist->GetNbinsX() == 1){
          double binErr = hist->GetBinError(1);
          if(binErr == 0){
//            std::cout << TString::Format("  WARNING: single-bin histogram '%s' does not have error, recycling %.1f%% uncertainty from total yield!",hist->GetName(),100*yieldErr/yieldVal) << std::endl;
//            hist->SetBinError(1,yieldErr);
            double err = sqrt(yieldVal);
            std::cout << TString::Format("  WARNING: single-bin histogram '%s' does not have error, using sqrt(n)=%.1f%% uncertainty!",hist->GetName(),100*err/yieldVal) << std::endl;
            hist->SetBinError(1,err);
            binErr = err;
          }
          if(!TMath::AreEqualRel(binErr/yieldVal,yieldErr/yieldVal,1E-06)){
            std::cout << TString::Format("  WARNING: in single-bin histogram '%s', uncertainties on bin and integral do not match: d(bin)=%g but d(integral)=%g - using single bin uncertainty!",hist->GetName(),binErr/yieldVal,yieldErr/yieldVal) << std::endl;
            yieldErr = binErr;
          } else {
            //            std::cout << TString::Format("  INFO: in single-bin histogram '%s', uncertainties on bin and integral: d(bin)=%g and d(integral)=%g!",hist->GetName(),binErr/yieldVal,yieldErr/yieldVal) << std::endl;
          }
        }
      }

      // check if any bin contents come out <=0 and print a warning if that happens
      for(int i=1; i<TQHistogramUtils::getNbinsGlobal(hist)-1; ++i){
        if(hist->IsBinOverflow(i) || hist->IsBinUnderflow(i)) continue;
        if(hist->GetBinContent(i) <= 0 ){
          std::cout << TString::Format("  WARNING: histogram '%s' has null/negative bin contents in bin %d",sample.first.Data(),i) << std::endl;
        }
        if((calculateErrors>0) && hist->GetBinError(i) < 1e-12){
          std::cout << TString::Format("  WARNING: histogram '%s' has close-to-zero uncertainty in bin %d",sample.first.Data(),i) << std::endl;
        }
      }
    }

    DEBUGclass("   saving integral");

    // create a single-bin histogram to save the yield
    TH1* yield = new TH1F(sample.first+"_count",sample.first,1,0,1);
    yield->SetDirectory(dir);
    yield->SetBinContent(1,yieldVal);
    yield->SetBinError  (1,yieldErr);
    histograms.push_back(yield);

    // we only add the samples to the sumEvents that are indeed a single sample to avoid double counting
    if(sample.second.size() == 1){
      nSummedSamples++;
      sumEvents += yieldVal;
    }

    // look if there's anything in the model that we can use to style the histogram
    if(styleModel){
      TH1* otherHist = dynamic_cast<TH1*>(styleModel->getObject(sample.first,region->getName()));
      if(otherHist){
        TQHistogramUtils::copyStyle(yield,otherHist);
        yield->SetTitle(otherHist->GetTitle());
        if(hist){
          TQHistogramUtils::copyStyle(hist,otherHist);
          hist->SetTitle(otherHist->GetTitle());
          hist->GetXaxis()->SetTitle(otherHist->GetXaxis()->GetTitle());
        }
      }
    }
  }

  intReader.setDirty();
  histReader.setDirty();

  if(nSummedSamples > 0 && sumEvents <= 0){
    throw std::runtime_error("sum over all samples in this region is <= 0!");
  }

  // in order to avoid normalization problems, we normalize the sum of integrals to the number of expected events in the region
  // if everything worked out fine, this shouldn't do anything, but unfortunately, this is sometimes needed
 // double scale = nExp/sumEvents;
  //if(!TMath::AreEqualRel(scale, 1., 1E-06)){
   // std::cout << TString::Format("WARNING: correcting scaling of histograms in region '%s' by a factor of %.16f",region->getName().Data(),scale) << std::endl;
    //for(auto hist:histograms){
     // hist->Scale(scale);
     // hist->SetEntries(1);
   // }
  //}

  // add everything to the output file
  for(auto hist:histograms){
    double totalEvents = 0;
    for(size_t ibin = 0; ibin<TQHistogramUtils::getNbinsGlobal(hist); ++ibin){
      std::vector<Int_t> coords(3);
      hist->GetBinXYZ(ibin,coords[0],coords[1],coords[2]);
      size_t iObs = 0;
      for(auto* o:region->getObservables()){
	if(region->isRemovedBin(static_cast<RooRealVar*>(o),coords[iObs])){
	  hist->SetBinContent(ibin,0);
	  hist->SetBinError(ibin,0);	  
	} else {
	  totalEvents += hist->GetBinContent(ibin);
	}
	++iObs;
      }
    }
    hist->SetDirectory(dir);
    hist->SetEntries(totalEvents);    
  }

  delete integral;
  delete projected;

  return true;
}

int TSHistogramExporter::getData(TDirectory* dir, const TString& selector, const TString& histname, const Region* region) {
  RooArgList obs(region->getObservables());
  std::vector<TString> varnames;
  TSUtils::getParameterNames(&obs,varnames);

  int n_histograms = 0;
  
  // loop over datasets
  std::vector<TString> dataNames(region->allData());
  for(const auto& dsname:dataNames){
    if(!TQStringUtils::matches(dsname,selector)) continue;

    TH1* data = NULL;
    TH1* data_count = new TH1F(histname+"_count",histname,1,0,1);
    data_count->SetDirectory(dir);
    int ndata = 0;
    
    int n = region->nData(dsname);
    RooDataSet* dataset = NULL;
    for(int i=0; i<n; ++i){
      dataset = region->getData(dsname,i);
      if(!dataset) throw std::runtime_error("error retrieving dataset!");
      double entries = dataset->sumEntries();
      data_count->AddBinContent(1,entries);

      ndata++;
      if(region->isCombined() || n!=1) continue;
      TH1* thisdata = dataset->createHistogram(TQStringUtils::concat(varnames),
					       static_cast<RooRealVar&>(obs[0]),
					       obs.size() > 1 ? RooFit::YVar(static_cast<RooRealVar&>(obs[1])) : RooCmdArg::none(),
					       obs.size() > 2 ? RooFit::ZVar(static_cast<RooRealVar&>(obs[2])) : RooCmdArg::none()
					       );
      if(!thisdata) continue; 
      //checkConsistency(thisdata,obs);
      if(data){
	data->Add(thisdata);
	thisdata->SetDirectory(NULL);
	delete thisdata;
      } else {
	data = thisdata;
	data->SetDirectory(dir);
	data->SetName(histname);
	data->Sumw2(false);
	if(styleModel){
	  TH1* otherHist = dynamic_cast<TH1*>(styleModel->getObject("Data",dataNames[0]));
	  if(otherHist){
	    TQHistogramUtils::copyStyle(data,otherHist);
	    data->SetTitle(otherHist->GetTitle());
	    data->GetXaxis()->SetTitle(otherHist->GetXaxis()->GetTitle());
	  }
	} else {
	  data->SetTitle(histname);
	}
      }
      if(ndata>1){
	if(data){
	  data->Scale(1./ndata);
	  TQHistogramUtils::applyPoissonErrors(data);
	}
	data_count->Scale(1./ndata);
	TQHistogramUtils::applyPoissonErrors(data_count);
      }
      if(data){
	data->SetEntries(entries);
      }
      data_count->SetEntries(entries);

      double totalEvents = 0;
      for(size_t ibin = 0; ibin<TQHistogramUtils::getNbinsGlobal(data); ++ibin){
	std::vector<Int_t> coords(3);
	data->GetBinXYZ(ibin,coords[0],coords[1],coords[2]);
	size_t iObs = 0;
	for(auto* o:region->getObservables()){
	  if(region->isRemovedBin(static_cast<RooRealVar*>(o),coords[iObs])){
	    data->SetBinContent(ibin,0);
	    data->SetBinError(ibin,0);	  
	  } else {
	    totalEvents += data->GetBinContent(ibin);
	  }
	  ++iObs;
	}
      }
      data->SetDirectory(dir);
      data->SetEntries(totalEvents);    

      n_histograms ++;
    }      
  }
  return n_histograms;
}

RooCategory* TSHistogramExporter::getCategories(RooSimultaneous* simPdf){
  if(!simPdf) return NULL;
  return const_cast<RooCategory*>(dynamic_cast<const RooCategory*>(&(simPdf->indexCat())));
}

std::vector<TSHistogramExporter::Region*> TSHistogramExporter::makeRegions(RooSimultaneous* pdf, const RooArgSet* observables, const std::list<RooAbsData*>& datasets){
  RooCategory* channelCat = TSHistogramExporter::getCategories(pdf);
  std::map<const TString,TList*> allSplitData;
  for(auto ds:datasets){
    TList* dataList = ds->split(*(channelCat), true);
    if(!dataList){
      throw std::runtime_error(TString::Format("unable to split dataset '%s' at '%s'",ds->GetName(),channelCat->GetName()).Data());
    }
    allSplitData[ds->GetName()] = dataList;
  }
  std::vector<TSHistogramExporter::Region*> regions;
  std::map<TString,RooRealSumPdf*> cats = TSHistogramExporter::getComponents(pdf);
  for(const auto& cat:cats){
    RooArgSet* obs = cat.second->getObservables(*observables);
    TSHistogramExporter::Region* region = new TSHistogramExporter::Region(cat.first,pdf,cat.second,obs,false);
    if(region->isCombined()) throw std::runtime_error("single region is combined!");
    for(auto ds:datasets){
      RooDataSet* data = dynamic_cast<RooDataSet*>(allSplitData[ds->GetName()]->FindObject(cat.first));
      region->addData(ds->GetName(),data);
    }
    regions.push_back(region);
  }
  for(auto it:allSplitData){
    it.second->SetOwner(false);
    delete it.second;
  }
  return regions;
}

std::map<TString,RooRealSumPdf*> TSHistogramExporter::getComponents(RooSimultaneous* pdf){
  std::map<TString,RooRealSumPdf*> cats;
  RooCategory* channelCat = getCategories(pdf);
  for(size_t i=0; i<channelCat->size(); ++i){
    TString catname(TSUtils::lookupName(channelCat,i));    
    RooProdPdf* prodpdf = dynamic_cast<RooProdPdf*>(pdf->getPdf(catname));
    if(!prodpdf){
      throw std::runtime_error(TString::Format("unable to find obtain prodPdf of region '%s'",catname.Data()).Data());
    }
    RooRealSumPdf* sumpdf = NULL;
    RooArgSet thisComponents;
    ::findUniqueProdComponents(prodpdf, thisComponents, "*");
    ROOFIT_ITERATE(thisComponents,RooAbsArg,comp){
      if (comp->IsA() == RooRealSumPdf::Class()) {
        sumpdf = dynamic_cast<RooRealSumPdf*>(comp);
        break;
      }
    }
    if(!sumpdf){
      throw std::runtime_error(TString::Format("unable to find sumPdf of region '%s'",catname.Data()).Data());
    }
    cats[catname] = sumpdf;
  }
  return cats;
}

int TSHistogramExporter::addCombinedRegions(TCollection* input, std::vector<TSHistogramExporter::Region*>& regions, const std::vector<TSHistogramExporter::Region*>& origregions){
  TQFolderIterator ritr(input,true);
  int n = 0;
  while(ritr.hasNext()){
    TQFolder* combination = ritr.readNext();
    TString name(combination->GetName());
    std::vector<TString> selection = combination->getTagVString("Components");
    RooArgSet allObs;
    RooArgList funcs;
    RooArgList coefs;
    RooConstVar* unity = new RooConstVar("1","1",1);
    std::vector<Region*> selectedRegions;
    for(const auto& r:origregions){
      bool selected = false;
      for(const auto& n:selection){
        if(TQStringUtils::matches(r->getName(),n)){
          selected = true;
        }
      }
      if(!selected) continue;
      selectedRegions.push_back(r);
    }
    for(const auto r:selectedRegions){
      allObs.add(r->getObservables());
      funcs.add(*r->getPdf());
      coefs.add(*unity);
    }
    RooAbsPdf * pdf= new RooRealSumPdf(name,"",funcs,coefs);
    Region* result = new Region(name,pdf,&allObs,true);
    if(!result->isCombined()) throw std::runtime_error("combined region is not combined!");
    for(const auto r:selectedRegions){
      result->addSamples(r);
      for(const auto& d:r->allData()){
        for(int i=0; i<r->nData(d); ++i){
          result->addData(d,r->getData(d,i));
        }
      }
    }
    regions.push_back(result);
    n++;
  }
  return n;
}

int TSHistogramExporter::addCombinedSamples(TCollection* input,std::map< const TString, std::vector<TString> >& samples, const std::vector<TString>& allSamples){
  TQFolderIterator sitr(input,true);
  int n = 0;
  while(sitr.hasNext()){
    TQFolder* combination = sitr.readNext();
    std::vector<TString> keys = combination->getTagVString("Components");
    std::vector<TString> blacklist = combination->getTagVString("Blacklist");
    std::vector<TString> samplelist;
    for(const auto& s:allSamples){
      bool add = false;
      for(const auto& k:keys){
        if(TQStringUtils::matches(s,k)){
          add = true;
        }
      }
      for(const auto& k:blacklist){
        if(TQStringUtils::matches(s,k)){
          add = false;
        }
      }
      if(add){
        samplelist.push_back(s);
      }
    }
    if(samplelist.size() > 0){
      samples[combination->GetName()] = samplelist;
      n++;
    } else {
      std::cout << "ERROR: expression for sample '" << combination->GetName() << "' does not match any!" << std::endl;
    }
  }
  return n;
}
 TSHistogramExporter.cxx:1
 TSHistogramExporter.cxx:2
 TSHistogramExporter.cxx:3
 TSHistogramExporter.cxx:4
 TSHistogramExporter.cxx:5
 TSHistogramExporter.cxx:6
 TSHistogramExporter.cxx:7
 TSHistogramExporter.cxx:8
 TSHistogramExporter.cxx:9
 TSHistogramExporter.cxx:10
 TSHistogramExporter.cxx:11
 TSHistogramExporter.cxx:12
 TSHistogramExporter.cxx:13
 TSHistogramExporter.cxx:14
 TSHistogramExporter.cxx:15
 TSHistogramExporter.cxx:16
 TSHistogramExporter.cxx:17
 TSHistogramExporter.cxx:18
 TSHistogramExporter.cxx:19
 TSHistogramExporter.cxx:20
 TSHistogramExporter.cxx:21
 TSHistogramExporter.cxx:22
 TSHistogramExporter.cxx:23
 TSHistogramExporter.cxx:24
 TSHistogramExporter.cxx:25
 TSHistogramExporter.cxx:26
 TSHistogramExporter.cxx:27
 TSHistogramExporter.cxx:28
 TSHistogramExporter.cxx:29
 TSHistogramExporter.cxx:30
 TSHistogramExporter.cxx:31
 TSHistogramExporter.cxx:32
 TSHistogramExporter.cxx:33
 TSHistogramExporter.cxx:34
 TSHistogramExporter.cxx:35
 TSHistogramExporter.cxx:36
 TSHistogramExporter.cxx:37
 TSHistogramExporter.cxx:38
 TSHistogramExporter.cxx:39
 TSHistogramExporter.cxx:40
 TSHistogramExporter.cxx:41
 TSHistogramExporter.cxx:42
 TSHistogramExporter.cxx:43
 TSHistogramExporter.cxx:44
 TSHistogramExporter.cxx:45
 TSHistogramExporter.cxx:46
 TSHistogramExporter.cxx:47
 TSHistogramExporter.cxx:48
 TSHistogramExporter.cxx:49
 TSHistogramExporter.cxx:50
 TSHistogramExporter.cxx:51
 TSHistogramExporter.cxx:52
 TSHistogramExporter.cxx:53
 TSHistogramExporter.cxx:54
 TSHistogramExporter.cxx:55
 TSHistogramExporter.cxx:56
 TSHistogramExporter.cxx:57
 TSHistogramExporter.cxx:58
 TSHistogramExporter.cxx:59
 TSHistogramExporter.cxx:60
 TSHistogramExporter.cxx:61
 TSHistogramExporter.cxx:62
 TSHistogramExporter.cxx:63
 TSHistogramExporter.cxx:64
 TSHistogramExporter.cxx:65
 TSHistogramExporter.cxx:66
 TSHistogramExporter.cxx:67
 TSHistogramExporter.cxx:68
 TSHistogramExporter.cxx:69
 TSHistogramExporter.cxx:70
 TSHistogramExporter.cxx:71
 TSHistogramExporter.cxx:72
 TSHistogramExporter.cxx:73
 TSHistogramExporter.cxx:74
 TSHistogramExporter.cxx:75
 TSHistogramExporter.cxx:76
 TSHistogramExporter.cxx:77
 TSHistogramExporter.cxx:78
 TSHistogramExporter.cxx:79
 TSHistogramExporter.cxx:80
 TSHistogramExporter.cxx:81
 TSHistogramExporter.cxx:82
 TSHistogramExporter.cxx:83
 TSHistogramExporter.cxx:84
 TSHistogramExporter.cxx:85
 TSHistogramExporter.cxx:86
 TSHistogramExporter.cxx:87
 TSHistogramExporter.cxx:88
 TSHistogramExporter.cxx:89
 TSHistogramExporter.cxx:90
 TSHistogramExporter.cxx:91
 TSHistogramExporter.cxx:92
 TSHistogramExporter.cxx:93
 TSHistogramExporter.cxx:94
 TSHistogramExporter.cxx:95
 TSHistogramExporter.cxx:96
 TSHistogramExporter.cxx:97
 TSHistogramExporter.cxx:98
 TSHistogramExporter.cxx:99
 TSHistogramExporter.cxx:100
 TSHistogramExporter.cxx:101
 TSHistogramExporter.cxx:102
 TSHistogramExporter.cxx:103
 TSHistogramExporter.cxx:104
 TSHistogramExporter.cxx:105
 TSHistogramExporter.cxx:106
 TSHistogramExporter.cxx:107
 TSHistogramExporter.cxx:108
 TSHistogramExporter.cxx:109
 TSHistogramExporter.cxx:110
 TSHistogramExporter.cxx:111
 TSHistogramExporter.cxx:112
 TSHistogramExporter.cxx:113
 TSHistogramExporter.cxx:114
 TSHistogramExporter.cxx:115
 TSHistogramExporter.cxx:116
 TSHistogramExporter.cxx:117
 TSHistogramExporter.cxx:118
 TSHistogramExporter.cxx:119
 TSHistogramExporter.cxx:120
 TSHistogramExporter.cxx:121
 TSHistogramExporter.cxx:122
 TSHistogramExporter.cxx:123
 TSHistogramExporter.cxx:124
 TSHistogramExporter.cxx:125
 TSHistogramExporter.cxx:126
 TSHistogramExporter.cxx:127
 TSHistogramExporter.cxx:128
 TSHistogramExporter.cxx:129
 TSHistogramExporter.cxx:130
 TSHistogramExporter.cxx:131
 TSHistogramExporter.cxx:132
 TSHistogramExporter.cxx:133
 TSHistogramExporter.cxx:134
 TSHistogramExporter.cxx:135
 TSHistogramExporter.cxx:136
 TSHistogramExporter.cxx:137
 TSHistogramExporter.cxx:138
 TSHistogramExporter.cxx:139
 TSHistogramExporter.cxx:140
 TSHistogramExporter.cxx:141
 TSHistogramExporter.cxx:142
 TSHistogramExporter.cxx:143
 TSHistogramExporter.cxx:144
 TSHistogramExporter.cxx:145
 TSHistogramExporter.cxx:146
 TSHistogramExporter.cxx:147
 TSHistogramExporter.cxx:148
 TSHistogramExporter.cxx:149
 TSHistogramExporter.cxx:150
 TSHistogramExporter.cxx:151
 TSHistogramExporter.cxx:152
 TSHistogramExporter.cxx:153
 TSHistogramExporter.cxx:154
 TSHistogramExporter.cxx:155
 TSHistogramExporter.cxx:156
 TSHistogramExporter.cxx:157
 TSHistogramExporter.cxx:158
 TSHistogramExporter.cxx:159
 TSHistogramExporter.cxx:160
 TSHistogramExporter.cxx:161
 TSHistogramExporter.cxx:162
 TSHistogramExporter.cxx:163
 TSHistogramExporter.cxx:164
 TSHistogramExporter.cxx:165
 TSHistogramExporter.cxx:166
 TSHistogramExporter.cxx:167
 TSHistogramExporter.cxx:168
 TSHistogramExporter.cxx:169
 TSHistogramExporter.cxx:170
 TSHistogramExporter.cxx:171
 TSHistogramExporter.cxx:172
 TSHistogramExporter.cxx:173
 TSHistogramExporter.cxx:174
 TSHistogramExporter.cxx:175
 TSHistogramExporter.cxx:176
 TSHistogramExporter.cxx:177
 TSHistogramExporter.cxx:178
 TSHistogramExporter.cxx:179
 TSHistogramExporter.cxx:180
 TSHistogramExporter.cxx:181
 TSHistogramExporter.cxx:182
 TSHistogramExporter.cxx:183
 TSHistogramExporter.cxx:184
 TSHistogramExporter.cxx:185
 TSHistogramExporter.cxx:186
 TSHistogramExporter.cxx:187
 TSHistogramExporter.cxx:188
 TSHistogramExporter.cxx:189
 TSHistogramExporter.cxx:190
 TSHistogramExporter.cxx:191
 TSHistogramExporter.cxx:192
 TSHistogramExporter.cxx:193
 TSHistogramExporter.cxx:194
 TSHistogramExporter.cxx:195
 TSHistogramExporter.cxx:196
 TSHistogramExporter.cxx:197
 TSHistogramExporter.cxx:198
 TSHistogramExporter.cxx:199
 TSHistogramExporter.cxx:200
 TSHistogramExporter.cxx:201
 TSHistogramExporter.cxx:202
 TSHistogramExporter.cxx:203
 TSHistogramExporter.cxx:204
 TSHistogramExporter.cxx:205
 TSHistogramExporter.cxx:206
 TSHistogramExporter.cxx:207
 TSHistogramExporter.cxx:208
 TSHistogramExporter.cxx:209
 TSHistogramExporter.cxx:210
 TSHistogramExporter.cxx:211
 TSHistogramExporter.cxx:212
 TSHistogramExporter.cxx:213
 TSHistogramExporter.cxx:214
 TSHistogramExporter.cxx:215
 TSHistogramExporter.cxx:216
 TSHistogramExporter.cxx:217
 TSHistogramExporter.cxx:218
 TSHistogramExporter.cxx:219
 TSHistogramExporter.cxx:220
 TSHistogramExporter.cxx:221
 TSHistogramExporter.cxx:222
 TSHistogramExporter.cxx:223
 TSHistogramExporter.cxx:224
 TSHistogramExporter.cxx:225
 TSHistogramExporter.cxx:226
 TSHistogramExporter.cxx:227
 TSHistogramExporter.cxx:228
 TSHistogramExporter.cxx:229
 TSHistogramExporter.cxx:230
 TSHistogramExporter.cxx:231
 TSHistogramExporter.cxx:232
 TSHistogramExporter.cxx:233
 TSHistogramExporter.cxx:234
 TSHistogramExporter.cxx:235
 TSHistogramExporter.cxx:236
 TSHistogramExporter.cxx:237
 TSHistogramExporter.cxx:238
 TSHistogramExporter.cxx:239
 TSHistogramExporter.cxx:240
 TSHistogramExporter.cxx:241
 TSHistogramExporter.cxx:242
 TSHistogramExporter.cxx:243
 TSHistogramExporter.cxx:244
 TSHistogramExporter.cxx:245
 TSHistogramExporter.cxx:246
 TSHistogramExporter.cxx:247
 TSHistogramExporter.cxx:248
 TSHistogramExporter.cxx:249
 TSHistogramExporter.cxx:250
 TSHistogramExporter.cxx:251
 TSHistogramExporter.cxx:252
 TSHistogramExporter.cxx:253
 TSHistogramExporter.cxx:254
 TSHistogramExporter.cxx:255
 TSHistogramExporter.cxx:256
 TSHistogramExporter.cxx:257
 TSHistogramExporter.cxx:258
 TSHistogramExporter.cxx:259
 TSHistogramExporter.cxx:260
 TSHistogramExporter.cxx:261
 TSHistogramExporter.cxx:262
 TSHistogramExporter.cxx:263
 TSHistogramExporter.cxx:264
 TSHistogramExporter.cxx:265
 TSHistogramExporter.cxx:266
 TSHistogramExporter.cxx:267
 TSHistogramExporter.cxx:268
 TSHistogramExporter.cxx:269
 TSHistogramExporter.cxx:270
 TSHistogramExporter.cxx:271
 TSHistogramExporter.cxx:272
 TSHistogramExporter.cxx:273
 TSHistogramExporter.cxx:274
 TSHistogramExporter.cxx:275
 TSHistogramExporter.cxx:276
 TSHistogramExporter.cxx:277
 TSHistogramExporter.cxx:278
 TSHistogramExporter.cxx:279
 TSHistogramExporter.cxx:280
 TSHistogramExporter.cxx:281
 TSHistogramExporter.cxx:282
 TSHistogramExporter.cxx:283
 TSHistogramExporter.cxx:284
 TSHistogramExporter.cxx:285
 TSHistogramExporter.cxx:286
 TSHistogramExporter.cxx:287
 TSHistogramExporter.cxx:288
 TSHistogramExporter.cxx:289
 TSHistogramExporter.cxx:290
 TSHistogramExporter.cxx:291
 TSHistogramExporter.cxx:292
 TSHistogramExporter.cxx:293
 TSHistogramExporter.cxx:294
 TSHistogramExporter.cxx:295
 TSHistogramExporter.cxx:296
 TSHistogramExporter.cxx:297
 TSHistogramExporter.cxx:298
 TSHistogramExporter.cxx:299
 TSHistogramExporter.cxx:300
 TSHistogramExporter.cxx:301
 TSHistogramExporter.cxx:302
 TSHistogramExporter.cxx:303
 TSHistogramExporter.cxx:304
 TSHistogramExporter.cxx:305
 TSHistogramExporter.cxx:306
 TSHistogramExporter.cxx:307
 TSHistogramExporter.cxx:308
 TSHistogramExporter.cxx:309
 TSHistogramExporter.cxx:310
 TSHistogramExporter.cxx:311
 TSHistogramExporter.cxx:312
 TSHistogramExporter.cxx:313
 TSHistogramExporter.cxx:314
 TSHistogramExporter.cxx:315
 TSHistogramExporter.cxx:316
 TSHistogramExporter.cxx:317
 TSHistogramExporter.cxx:318
 TSHistogramExporter.cxx:319
 TSHistogramExporter.cxx:320
 TSHistogramExporter.cxx:321
 TSHistogramExporter.cxx:322
 TSHistogramExporter.cxx:323
 TSHistogramExporter.cxx:324
 TSHistogramExporter.cxx:325
 TSHistogramExporter.cxx:326
 TSHistogramExporter.cxx:327
 TSHistogramExporter.cxx:328
 TSHistogramExporter.cxx:329
 TSHistogramExporter.cxx:330
 TSHistogramExporter.cxx:331
 TSHistogramExporter.cxx:332
 TSHistogramExporter.cxx:333
 TSHistogramExporter.cxx:334
 TSHistogramExporter.cxx:335
 TSHistogramExporter.cxx:336
 TSHistogramExporter.cxx:337
 TSHistogramExporter.cxx:338
 TSHistogramExporter.cxx:339
 TSHistogramExporter.cxx:340
 TSHistogramExporter.cxx:341
 TSHistogramExporter.cxx:342
 TSHistogramExporter.cxx:343
 TSHistogramExporter.cxx:344
 TSHistogramExporter.cxx:345
 TSHistogramExporter.cxx:346
 TSHistogramExporter.cxx:347
 TSHistogramExporter.cxx:348
 TSHistogramExporter.cxx:349
 TSHistogramExporter.cxx:350
 TSHistogramExporter.cxx:351
 TSHistogramExporter.cxx:352
 TSHistogramExporter.cxx:353
 TSHistogramExporter.cxx:354
 TSHistogramExporter.cxx:355
 TSHistogramExporter.cxx:356
 TSHistogramExporter.cxx:357
 TSHistogramExporter.cxx:358
 TSHistogramExporter.cxx:359
 TSHistogramExporter.cxx:360
 TSHistogramExporter.cxx:361
 TSHistogramExporter.cxx:362
 TSHistogramExporter.cxx:363
 TSHistogramExporter.cxx:364
 TSHistogramExporter.cxx:365
 TSHistogramExporter.cxx:366
 TSHistogramExporter.cxx:367
 TSHistogramExporter.cxx:368
 TSHistogramExporter.cxx:369
 TSHistogramExporter.cxx:370
 TSHistogramExporter.cxx:371
 TSHistogramExporter.cxx:372
 TSHistogramExporter.cxx:373
 TSHistogramExporter.cxx:374
 TSHistogramExporter.cxx:375
 TSHistogramExporter.cxx:376
 TSHistogramExporter.cxx:377
 TSHistogramExporter.cxx:378
 TSHistogramExporter.cxx:379
 TSHistogramExporter.cxx:380
 TSHistogramExporter.cxx:381
 TSHistogramExporter.cxx:382
 TSHistogramExporter.cxx:383
 TSHistogramExporter.cxx:384
 TSHistogramExporter.cxx:385
 TSHistogramExporter.cxx:386
 TSHistogramExporter.cxx:387
 TSHistogramExporter.cxx:388
 TSHistogramExporter.cxx:389
 TSHistogramExporter.cxx:390
 TSHistogramExporter.cxx:391
 TSHistogramExporter.cxx:392
 TSHistogramExporter.cxx:393
 TSHistogramExporter.cxx:394
 TSHistogramExporter.cxx:395
 TSHistogramExporter.cxx:396
 TSHistogramExporter.cxx:397
 TSHistogramExporter.cxx:398
 TSHistogramExporter.cxx:399
 TSHistogramExporter.cxx:400
 TSHistogramExporter.cxx:401
 TSHistogramExporter.cxx:402
 TSHistogramExporter.cxx:403
 TSHistogramExporter.cxx:404
 TSHistogramExporter.cxx:405
 TSHistogramExporter.cxx:406
 TSHistogramExporter.cxx:407
 TSHistogramExporter.cxx:408
 TSHistogramExporter.cxx:409
 TSHistogramExporter.cxx:410
 TSHistogramExporter.cxx:411
 TSHistogramExporter.cxx:412
 TSHistogramExporter.cxx:413
 TSHistogramExporter.cxx:414
 TSHistogramExporter.cxx:415
 TSHistogramExporter.cxx:416
 TSHistogramExporter.cxx:417
 TSHistogramExporter.cxx:418
 TSHistogramExporter.cxx:419
 TSHistogramExporter.cxx:420
 TSHistogramExporter.cxx:421
 TSHistogramExporter.cxx:422
 TSHistogramExporter.cxx:423
 TSHistogramExporter.cxx:424
 TSHistogramExporter.cxx:425
 TSHistogramExporter.cxx:426
 TSHistogramExporter.cxx:427
 TSHistogramExporter.cxx:428
 TSHistogramExporter.cxx:429
 TSHistogramExporter.cxx:430
 TSHistogramExporter.cxx:431
 TSHistogramExporter.cxx:432
 TSHistogramExporter.cxx:433
 TSHistogramExporter.cxx:434
 TSHistogramExporter.cxx:435
 TSHistogramExporter.cxx:436
 TSHistogramExporter.cxx:437
 TSHistogramExporter.cxx:438
 TSHistogramExporter.cxx:439
 TSHistogramExporter.cxx:440
 TSHistogramExporter.cxx:441
 TSHistogramExporter.cxx:442
 TSHistogramExporter.cxx:443
 TSHistogramExporter.cxx:444
 TSHistogramExporter.cxx:445
 TSHistogramExporter.cxx:446
 TSHistogramExporter.cxx:447
 TSHistogramExporter.cxx:448
 TSHistogramExporter.cxx:449
 TSHistogramExporter.cxx:450
 TSHistogramExporter.cxx:451
 TSHistogramExporter.cxx:452
 TSHistogramExporter.cxx:453
 TSHistogramExporter.cxx:454
 TSHistogramExporter.cxx:455
 TSHistogramExporter.cxx:456
 TSHistogramExporter.cxx:457
 TSHistogramExporter.cxx:458
 TSHistogramExporter.cxx:459
 TSHistogramExporter.cxx:460
 TSHistogramExporter.cxx:461
 TSHistogramExporter.cxx:462
 TSHistogramExporter.cxx:463
 TSHistogramExporter.cxx:464
 TSHistogramExporter.cxx:465
 TSHistogramExporter.cxx:466
 TSHistogramExporter.cxx:467
 TSHistogramExporter.cxx:468
 TSHistogramExporter.cxx:469
 TSHistogramExporter.cxx:470
 TSHistogramExporter.cxx:471
 TSHistogramExporter.cxx:472
 TSHistogramExporter.cxx:473
 TSHistogramExporter.cxx:474
 TSHistogramExporter.cxx:475
 TSHistogramExporter.cxx:476
 TSHistogramExporter.cxx:477
 TSHistogramExporter.cxx:478
 TSHistogramExporter.cxx:479
 TSHistogramExporter.cxx:480
 TSHistogramExporter.cxx:481
 TSHistogramExporter.cxx:482
 TSHistogramExporter.cxx:483
 TSHistogramExporter.cxx:484
 TSHistogramExporter.cxx:485
 TSHistogramExporter.cxx:486
 TSHistogramExporter.cxx:487
 TSHistogramExporter.cxx:488
 TSHistogramExporter.cxx:489
 TSHistogramExporter.cxx:490
 TSHistogramExporter.cxx:491
 TSHistogramExporter.cxx:492
 TSHistogramExporter.cxx:493
 TSHistogramExporter.cxx:494
 TSHistogramExporter.cxx:495
 TSHistogramExporter.cxx:496
 TSHistogramExporter.cxx:497
 TSHistogramExporter.cxx:498
 TSHistogramExporter.cxx:499
 TSHistogramExporter.cxx:500
 TSHistogramExporter.cxx:501
 TSHistogramExporter.cxx:502
 TSHistogramExporter.cxx:503
 TSHistogramExporter.cxx:504
 TSHistogramExporter.cxx:505
 TSHistogramExporter.cxx:506
 TSHistogramExporter.cxx:507
 TSHistogramExporter.cxx:508
 TSHistogramExporter.cxx:509
 TSHistogramExporter.cxx:510
 TSHistogramExporter.cxx:511
 TSHistogramExporter.cxx:512
 TSHistogramExporter.cxx:513
 TSHistogramExporter.cxx:514
 TSHistogramExporter.cxx:515
 TSHistogramExporter.cxx:516
 TSHistogramExporter.cxx:517
 TSHistogramExporter.cxx:518
 TSHistogramExporter.cxx:519
 TSHistogramExporter.cxx:520
 TSHistogramExporter.cxx:521
 TSHistogramExporter.cxx:522
 TSHistogramExporter.cxx:523
 TSHistogramExporter.cxx:524
 TSHistogramExporter.cxx:525
 TSHistogramExporter.cxx:526
 TSHistogramExporter.cxx:527
 TSHistogramExporter.cxx:528
 TSHistogramExporter.cxx:529
 TSHistogramExporter.cxx:530
 TSHistogramExporter.cxx:531
 TSHistogramExporter.cxx:532
 TSHistogramExporter.cxx:533
 TSHistogramExporter.cxx:534
 TSHistogramExporter.cxx:535
 TSHistogramExporter.cxx:536
 TSHistogramExporter.cxx:537
 TSHistogramExporter.cxx:538
 TSHistogramExporter.cxx:539
 TSHistogramExporter.cxx:540
 TSHistogramExporter.cxx:541
 TSHistogramExporter.cxx:542
 TSHistogramExporter.cxx:543
 TSHistogramExporter.cxx:544
 TSHistogramExporter.cxx:545
 TSHistogramExporter.cxx:546
 TSHistogramExporter.cxx:547
 TSHistogramExporter.cxx:548
 TSHistogramExporter.cxx:549
 TSHistogramExporter.cxx:550
 TSHistogramExporter.cxx:551
 TSHistogramExporter.cxx:552
 TSHistogramExporter.cxx:553
 TSHistogramExporter.cxx:554
 TSHistogramExporter.cxx:555
 TSHistogramExporter.cxx:556
 TSHistogramExporter.cxx:557
 TSHistogramExporter.cxx:558
 TSHistogramExporter.cxx:559
 TSHistogramExporter.cxx:560
 TSHistogramExporter.cxx:561
 TSHistogramExporter.cxx:562
 TSHistogramExporter.cxx:563
 TSHistogramExporter.cxx:564
 TSHistogramExporter.cxx:565
 TSHistogramExporter.cxx:566
 TSHistogramExporter.cxx:567
 TSHistogramExporter.cxx:568
 TSHistogramExporter.cxx:569
 TSHistogramExporter.cxx:570
 TSHistogramExporter.cxx:571
 TSHistogramExporter.cxx:572
 TSHistogramExporter.cxx:573
 TSHistogramExporter.cxx:574
 TSHistogramExporter.cxx:575
 TSHistogramExporter.cxx:576
 TSHistogramExporter.cxx:577
 TSHistogramExporter.cxx:578
 TSHistogramExporter.cxx:579
 TSHistogramExporter.cxx:580
 TSHistogramExporter.cxx:581
 TSHistogramExporter.cxx:582
 TSHistogramExporter.cxx:583
 TSHistogramExporter.cxx:584
 TSHistogramExporter.cxx:585
 TSHistogramExporter.cxx:586
 TSHistogramExporter.cxx:587
 TSHistogramExporter.cxx:588
 TSHistogramExporter.cxx:589
 TSHistogramExporter.cxx:590
 TSHistogramExporter.cxx:591
 TSHistogramExporter.cxx:592
 TSHistogramExporter.cxx:593
 TSHistogramExporter.cxx:594
 TSHistogramExporter.cxx:595
 TSHistogramExporter.cxx:596
 TSHistogramExporter.cxx:597
 TSHistogramExporter.cxx:598
 TSHistogramExporter.cxx:599
 TSHistogramExporter.cxx:600
 TSHistogramExporter.cxx:601
 TSHistogramExporter.cxx:602
 TSHistogramExporter.cxx:603
 TSHistogramExporter.cxx:604
 TSHistogramExporter.cxx:605
 TSHistogramExporter.cxx:606
 TSHistogramExporter.cxx:607
 TSHistogramExporter.cxx:608
 TSHistogramExporter.cxx:609
 TSHistogramExporter.cxx:610
 TSHistogramExporter.cxx:611
 TSHistogramExporter.cxx:612
 TSHistogramExporter.cxx:613
 TSHistogramExporter.cxx:614
 TSHistogramExporter.cxx:615
 TSHistogramExporter.cxx:616
 TSHistogramExporter.cxx:617
 TSHistogramExporter.cxx:618
 TSHistogramExporter.cxx:619
 TSHistogramExporter.cxx:620
 TSHistogramExporter.cxx:621
 TSHistogramExporter.cxx:622
 TSHistogramExporter.cxx:623
 TSHistogramExporter.cxx:624
 TSHistogramExporter.cxx:625
 TSHistogramExporter.cxx:626
 TSHistogramExporter.cxx:627
 TSHistogramExporter.cxx:628
 TSHistogramExporter.cxx:629
 TSHistogramExporter.cxx:630
 TSHistogramExporter.cxx:631
 TSHistogramExporter.cxx:632
 TSHistogramExporter.cxx:633
 TSHistogramExporter.cxx:634
 TSHistogramExporter.cxx:635
 TSHistogramExporter.cxx:636
 TSHistogramExporter.cxx:637
 TSHistogramExporter.cxx:638
 TSHistogramExporter.cxx:639
 TSHistogramExporter.cxx:640
 TSHistogramExporter.cxx:641
 TSHistogramExporter.cxx:642
 TSHistogramExporter.cxx:643
 TSHistogramExporter.cxx:644
 TSHistogramExporter.cxx:645
 TSHistogramExporter.cxx:646
 TSHistogramExporter.cxx:647
 TSHistogramExporter.cxx:648
 TSHistogramExporter.cxx:649
 TSHistogramExporter.cxx:650
 TSHistogramExporter.cxx:651
 TSHistogramExporter.cxx:652
 TSHistogramExporter.cxx:653
 TSHistogramExporter.cxx:654
 TSHistogramExporter.cxx:655
 TSHistogramExporter.cxx:656
 TSHistogramExporter.cxx:657
 TSHistogramExporter.cxx:658
 TSHistogramExporter.cxx:659
 TSHistogramExporter.cxx:660
 TSHistogramExporter.cxx:661
 TSHistogramExporter.cxx:662
 TSHistogramExporter.cxx:663
 TSHistogramExporter.cxx:664
 TSHistogramExporter.cxx:665
 TSHistogramExporter.cxx:666
 TSHistogramExporter.cxx:667
 TSHistogramExporter.cxx:668
 TSHistogramExporter.cxx:669
 TSHistogramExporter.cxx:670
 TSHistogramExporter.cxx:671
 TSHistogramExporter.cxx:672
 TSHistogramExporter.cxx:673
 TSHistogramExporter.cxx:674
 TSHistogramExporter.cxx:675
 TSHistogramExporter.cxx:676
 TSHistogramExporter.cxx:677
 TSHistogramExporter.cxx:678
 TSHistogramExporter.cxx:679
 TSHistogramExporter.cxx:680
 TSHistogramExporter.cxx:681
 TSHistogramExporter.cxx:682
 TSHistogramExporter.cxx:683
 TSHistogramExporter.cxx:684
 TSHistogramExporter.cxx:685
 TSHistogramExporter.cxx:686
 TSHistogramExporter.cxx:687
 TSHistogramExporter.cxx:688
 TSHistogramExporter.cxx:689
 TSHistogramExporter.cxx:690
 TSHistogramExporter.cxx:691
 TSHistogramExporter.cxx:692
 TSHistogramExporter.cxx:693
 TSHistogramExporter.cxx:694
 TSHistogramExporter.cxx:695
 TSHistogramExporter.cxx:696
 TSHistogramExporter.cxx:697
 TSHistogramExporter.cxx:698
 TSHistogramExporter.cxx:699
 TSHistogramExporter.cxx:700
 TSHistogramExporter.cxx:701
 TSHistogramExporter.cxx:702
 TSHistogramExporter.cxx:703
 TSHistogramExporter.cxx:704
 TSHistogramExporter.cxx:705
 TSHistogramExporter.cxx:706
 TSHistogramExporter.cxx:707
 TSHistogramExporter.cxx:708
 TSHistogramExporter.cxx:709
 TSHistogramExporter.cxx:710
 TSHistogramExporter.cxx:711
 TSHistogramExporter.cxx:712
 TSHistogramExporter.cxx:713
 TSHistogramExporter.cxx:714
 TSHistogramExporter.cxx:715
 TSHistogramExporter.cxx:716
 TSHistogramExporter.cxx:717
 TSHistogramExporter.cxx:718
 TSHistogramExporter.cxx:719
 TSHistogramExporter.cxx:720
 TSHistogramExporter.cxx:721
 TSHistogramExporter.cxx:722
 TSHistogramExporter.cxx:723
 TSHistogramExporter.cxx:724
 TSHistogramExporter.cxx:725
 TSHistogramExporter.cxx:726
 TSHistogramExporter.cxx:727
 TSHistogramExporter.cxx:728
 TSHistogramExporter.cxx:729
 TSHistogramExporter.cxx:730
 TSHistogramExporter.cxx:731
 TSHistogramExporter.cxx:732
 TSHistogramExporter.cxx:733
 TSHistogramExporter.cxx:734
 TSHistogramExporter.cxx:735
 TSHistogramExporter.cxx:736
 TSHistogramExporter.cxx:737
 TSHistogramExporter.cxx:738
 TSHistogramExporter.cxx:739
 TSHistogramExporter.cxx:740
 TSHistogramExporter.cxx:741
 TSHistogramExporter.cxx:742
 TSHistogramExporter.cxx:743
 TSHistogramExporter.cxx:744
 TSHistogramExporter.cxx:745
 TSHistogramExporter.cxx:746
 TSHistogramExporter.cxx:747
 TSHistogramExporter.cxx:748
 TSHistogramExporter.cxx:749
 TSHistogramExporter.cxx:750
 TSHistogramExporter.cxx:751
 TSHistogramExporter.cxx:752
 TSHistogramExporter.cxx:753
 TSHistogramExporter.cxx:754
 TSHistogramExporter.cxx:755
 TSHistogramExporter.cxx:756
 TSHistogramExporter.cxx:757
 TSHistogramExporter.cxx:758
 TSHistogramExporter.cxx:759
 TSHistogramExporter.cxx:760
 TSHistogramExporter.cxx:761
 TSHistogramExporter.cxx:762
 TSHistogramExporter.cxx:763
 TSHistogramExporter.cxx:764
 TSHistogramExporter.cxx:765
 TSHistogramExporter.cxx:766
 TSHistogramExporter.cxx:767
 TSHistogramExporter.cxx:768
 TSHistogramExporter.cxx:769
 TSHistogramExporter.cxx:770
 TSHistogramExporter.cxx:771
 TSHistogramExporter.cxx:772
 TSHistogramExporter.cxx:773
 TSHistogramExporter.cxx:774
 TSHistogramExporter.cxx:775
 TSHistogramExporter.cxx:776
 TSHistogramExporter.cxx:777
 TSHistogramExporter.cxx:778
 TSHistogramExporter.cxx:779
 TSHistogramExporter.cxx:780
 TSHistogramExporter.cxx:781
 TSHistogramExporter.cxx:782
 TSHistogramExporter.cxx:783
 TSHistogramExporter.cxx:784
 TSHistogramExporter.cxx:785
 TSHistogramExporter.cxx:786
 TSHistogramExporter.cxx:787
 TSHistogramExporter.cxx:788
 TSHistogramExporter.cxx:789
 TSHistogramExporter.cxx:790
 TSHistogramExporter.cxx:791
 TSHistogramExporter.cxx:792
 TSHistogramExporter.cxx:793
 TSHistogramExporter.cxx:794
 TSHistogramExporter.cxx:795
 TSHistogramExporter.cxx:796
 TSHistogramExporter.cxx:797
 TSHistogramExporter.cxx:798
 TSHistogramExporter.cxx:799
 TSHistogramExporter.cxx:800
 TSHistogramExporter.cxx:801
 TSHistogramExporter.cxx:802
 TSHistogramExporter.cxx:803
 TSHistogramExporter.cxx:804
 TSHistogramExporter.cxx:805
 TSHistogramExporter.cxx:806
 TSHistogramExporter.cxx:807
 TSHistogramExporter.cxx:808
 TSHistogramExporter.cxx:809
 TSHistogramExporter.cxx:810
 TSHistogramExporter.cxx:811
 TSHistogramExporter.cxx:812
 TSHistogramExporter.cxx:813
 TSHistogramExporter.cxx:814
 TSHistogramExporter.cxx:815
 TSHistogramExporter.cxx:816
 TSHistogramExporter.cxx:817
 TSHistogramExporter.cxx:818
 TSHistogramExporter.cxx:819
 TSHistogramExporter.cxx:820
 TSHistogramExporter.cxx:821
 TSHistogramExporter.cxx:822
 TSHistogramExporter.cxx:823
 TSHistogramExporter.cxx:824
 TSHistogramExporter.cxx:825
 TSHistogramExporter.cxx:826
 TSHistogramExporter.cxx:827
 TSHistogramExporter.cxx:828
 TSHistogramExporter.cxx:829
 TSHistogramExporter.cxx:830
 TSHistogramExporter.cxx:831
 TSHistogramExporter.cxx:832
 TSHistogramExporter.cxx:833
 TSHistogramExporter.cxx:834
 TSHistogramExporter.cxx:835
 TSHistogramExporter.cxx:836
 TSHistogramExporter.cxx:837
 TSHistogramExporter.cxx:838
 TSHistogramExporter.cxx:839
 TSHistogramExporter.cxx:840
 TSHistogramExporter.cxx:841
 TSHistogramExporter.cxx:842
 TSHistogramExporter.cxx:843
 TSHistogramExporter.cxx:844
 TSHistogramExporter.cxx:845
 TSHistogramExporter.cxx:846
 TSHistogramExporter.cxx:847
 TSHistogramExporter.cxx:848
 TSHistogramExporter.cxx:849
 TSHistogramExporter.cxx:850
 TSHistogramExporter.cxx:851
 TSHistogramExporter.cxx:852
 TSHistogramExporter.cxx:853
 TSHistogramExporter.cxx:854
 TSHistogramExporter.cxx:855
 TSHistogramExporter.cxx:856
 TSHistogramExporter.cxx:857
 TSHistogramExporter.cxx:858
 TSHistogramExporter.cxx:859
 TSHistogramExporter.cxx:860
 TSHistogramExporter.cxx:861
 TSHistogramExporter.cxx:862
 TSHistogramExporter.cxx:863
 TSHistogramExporter.cxx:864
 TSHistogramExporter.cxx:865
 TSHistogramExporter.cxx:866
 TSHistogramExporter.cxx:867
 TSHistogramExporter.cxx:868
 TSHistogramExporter.cxx:869
 TSHistogramExporter.cxx:870
 TSHistogramExporter.cxx:871
 TSHistogramExporter.cxx:872
 TSHistogramExporter.cxx:873
 TSHistogramExporter.cxx:874
 TSHistogramExporter.cxx:875
 TSHistogramExporter.cxx:876
 TSHistogramExporter.cxx:877
 TSHistogramExporter.cxx:878
 TSHistogramExporter.cxx:879
 TSHistogramExporter.cxx:880
 TSHistogramExporter.cxx:881
 TSHistogramExporter.cxx:882
 TSHistogramExporter.cxx:883
 TSHistogramExporter.cxx:884
 TSHistogramExporter.cxx:885
 TSHistogramExporter.cxx:886
 TSHistogramExporter.cxx:887
 TSHistogramExporter.cxx:888
 TSHistogramExporter.cxx:889
 TSHistogramExporter.cxx:890
 TSHistogramExporter.cxx:891
 TSHistogramExporter.cxx:892
 TSHistogramExporter.cxx:893
 TSHistogramExporter.cxx:894
 TSHistogramExporter.cxx:895
 TSHistogramExporter.cxx:896
 TSHistogramExporter.cxx:897
 TSHistogramExporter.cxx:898
 TSHistogramExporter.cxx:899
 TSHistogramExporter.cxx:900
 TSHistogramExporter.cxx:901
 TSHistogramExporter.cxx:902
 TSHistogramExporter.cxx:903
 TSHistogramExporter.cxx:904
 TSHistogramExporter.cxx:905
 TSHistogramExporter.cxx:906
 TSHistogramExporter.cxx:907
 TSHistogramExporter.cxx:908
 TSHistogramExporter.cxx:909
 TSHistogramExporter.cxx:910
 TSHistogramExporter.cxx:911
 TSHistogramExporter.cxx:912
 TSHistogramExporter.cxx:913
 TSHistogramExporter.cxx:914
 TSHistogramExporter.cxx:915
 TSHistogramExporter.cxx:916
 TSHistogramExporter.cxx:917
 TSHistogramExporter.cxx:918
 TSHistogramExporter.cxx:919
 TSHistogramExporter.cxx:920
 TSHistogramExporter.cxx:921
 TSHistogramExporter.cxx:922
 TSHistogramExporter.cxx:923
 TSHistogramExporter.cxx:924
 TSHistogramExporter.cxx:925
 TSHistogramExporter.cxx:926
 TSHistogramExporter.cxx:927
 TSHistogramExporter.cxx:928
 TSHistogramExporter.cxx:929
 TSHistogramExporter.cxx:930
 TSHistogramExporter.cxx:931
 TSHistogramExporter.cxx:932
 TSHistogramExporter.cxx:933
 TSHistogramExporter.cxx:934
 TSHistogramExporter.cxx:935
 TSHistogramExporter.cxx:936
 TSHistogramExporter.cxx:937
 TSHistogramExporter.cxx:938
 TSHistogramExporter.cxx:939
 TSHistogramExporter.cxx:940
 TSHistogramExporter.cxx:941
 TSHistogramExporter.cxx:942
 TSHistogramExporter.cxx:943
 TSHistogramExporter.cxx:944
 TSHistogramExporter.cxx:945
 TSHistogramExporter.cxx:946
 TSHistogramExporter.cxx:947
 TSHistogramExporter.cxx:948
 TSHistogramExporter.cxx:949
 TSHistogramExporter.cxx:950
 TSHistogramExporter.cxx:951
 TSHistogramExporter.cxx:952
 TSHistogramExporter.cxx:953
 TSHistogramExporter.cxx:954
 TSHistogramExporter.cxx:955
 TSHistogramExporter.cxx:956
 TSHistogramExporter.cxx:957
 TSHistogramExporter.cxx:958
 TSHistogramExporter.cxx:959
 TSHistogramExporter.cxx:960
 TSHistogramExporter.cxx:961
 TSHistogramExporter.cxx:962
 TSHistogramExporter.cxx:963
 TSHistogramExporter.cxx:964
 TSHistogramExporter.cxx:965
 TSHistogramExporter.cxx:966
 TSHistogramExporter.cxx:967
 TSHistogramExporter.cxx:968
 TSHistogramExporter.cxx:969
 TSHistogramExporter.cxx:970
 TSHistogramExporter.cxx:971
 TSHistogramExporter.cxx:972
 TSHistogramExporter.cxx:973
 TSHistogramExporter.cxx:974
 TSHistogramExporter.cxx:975
 TSHistogramExporter.cxx:976
 TSHistogramExporter.cxx:977
 TSHistogramExporter.cxx:978
 TSHistogramExporter.cxx:979
 TSHistogramExporter.cxx:980
 TSHistogramExporter.cxx:981
 TSHistogramExporter.cxx:982
 TSHistogramExporter.cxx:983
 TSHistogramExporter.cxx:984
 TSHistogramExporter.cxx:985
 TSHistogramExporter.cxx:986
 TSHistogramExporter.cxx:987
 TSHistogramExporter.cxx:988
 TSHistogramExporter.cxx:989
 TSHistogramExporter.cxx:990
 TSHistogramExporter.cxx:991
 TSHistogramExporter.cxx:992
 TSHistogramExporter.cxx:993
 TSHistogramExporter.cxx:994
 TSHistogramExporter.cxx:995
 TSHistogramExporter.cxx:996
 TSHistogramExporter.cxx:997
 TSHistogramExporter.cxx:998
 TSHistogramExporter.cxx:999
 TSHistogramExporter.cxx:1000
 TSHistogramExporter.cxx:1001
 TSHistogramExporter.cxx:1002
 TSHistogramExporter.cxx:1003
 TSHistogramExporter.cxx:1004
 TSHistogramExporter.cxx:1005
 TSHistogramExporter.cxx:1006
 TSHistogramExporter.cxx:1007
 TSHistogramExporter.cxx:1008
 TSHistogramExporter.cxx:1009
 TSHistogramExporter.cxx:1010
 TSHistogramExporter.cxx:1011
 TSHistogramExporter.cxx:1012
 TSHistogramExporter.cxx:1013
 TSHistogramExporter.cxx:1014
 TSHistogramExporter.cxx:1015
 TSHistogramExporter.cxx:1016
 TSHistogramExporter.cxx:1017
 TSHistogramExporter.cxx:1018
 TSHistogramExporter.cxx:1019
 TSHistogramExporter.cxx:1020
 TSHistogramExporter.cxx:1021
 TSHistogramExporter.cxx:1022
 TSHistogramExporter.cxx:1023
 TSHistogramExporter.cxx:1024
 TSHistogramExporter.cxx:1025
 TSHistogramExporter.cxx:1026
 TSHistogramExporter.cxx:1027
 TSHistogramExporter.cxx:1028
 TSHistogramExporter.cxx:1029
 TSHistogramExporter.cxx:1030
 TSHistogramExporter.cxx:1031
 TSHistogramExporter.cxx:1032
 TSHistogramExporter.cxx:1033
 TSHistogramExporter.cxx:1034
 TSHistogramExporter.cxx:1035
 TSHistogramExporter.cxx:1036
 TSHistogramExporter.cxx:1037
 TSHistogramExporter.cxx:1038
 TSHistogramExporter.cxx:1039
 TSHistogramExporter.cxx:1040
 TSHistogramExporter.cxx:1041
 TSHistogramExporter.cxx:1042
 TSHistogramExporter.cxx:1043
 TSHistogramExporter.cxx:1044
 TSHistogramExporter.cxx:1045
 TSHistogramExporter.cxx:1046
 TSHistogramExporter.cxx:1047
 TSHistogramExporter.cxx:1048
 TSHistogramExporter.cxx:1049
 TSHistogramExporter.cxx:1050
 TSHistogramExporter.cxx:1051
 TSHistogramExporter.cxx:1052
 TSHistogramExporter.cxx:1053
 TSHistogramExporter.cxx:1054
 TSHistogramExporter.cxx:1055
 TSHistogramExporter.cxx:1056
 TSHistogramExporter.cxx:1057
 TSHistogramExporter.cxx:1058
 TSHistogramExporter.cxx:1059
 TSHistogramExporter.cxx:1060
 TSHistogramExporter.cxx:1061
 TSHistogramExporter.cxx:1062
 TSHistogramExporter.cxx:1063
 TSHistogramExporter.cxx:1064
 TSHistogramExporter.cxx:1065
 TSHistogramExporter.cxx:1066
 TSHistogramExporter.cxx:1067
 TSHistogramExporter.cxx:1068
 TSHistogramExporter.cxx:1069
 TSHistogramExporter.cxx:1070
 TSHistogramExporter.cxx:1071
 TSHistogramExporter.cxx:1072
 TSHistogramExporter.cxx:1073
 TSHistogramExporter.cxx:1074
 TSHistogramExporter.cxx:1075
 TSHistogramExporter.cxx:1076
 TSHistogramExporter.cxx:1077
 TSHistogramExporter.cxx:1078
 TSHistogramExporter.cxx:1079
 TSHistogramExporter.cxx:1080
 TSHistogramExporter.cxx:1081
 TSHistogramExporter.cxx:1082
 TSHistogramExporter.cxx:1083
 TSHistogramExporter.cxx:1084
 TSHistogramExporter.cxx:1085
 TSHistogramExporter.cxx:1086
 TSHistogramExporter.cxx:1087
 TSHistogramExporter.cxx:1088
 TSHistogramExporter.cxx:1089
 TSHistogramExporter.cxx:1090
 TSHistogramExporter.cxx:1091
 TSHistogramExporter.cxx:1092
 TSHistogramExporter.cxx:1093
 TSHistogramExporter.cxx:1094
 TSHistogramExporter.cxx:1095
 TSHistogramExporter.cxx:1096
 TSHistogramExporter.cxx:1097
 TSHistogramExporter.cxx:1098
 TSHistogramExporter.cxx:1099
 TSHistogramExporter.cxx:1100
 TSHistogramExporter.cxx:1101
 TSHistogramExporter.cxx:1102
 TSHistogramExporter.cxx:1103
 TSHistogramExporter.cxx:1104
 TSHistogramExporter.cxx:1105
 TSHistogramExporter.cxx:1106
 TSHistogramExporter.cxx:1107
 TSHistogramExporter.cxx:1108
 TSHistogramExporter.cxx:1109
 TSHistogramExporter.cxx:1110
 TSHistogramExporter.cxx:1111
 TSHistogramExporter.cxx:1112
 TSHistogramExporter.cxx:1113
 TSHistogramExporter.cxx:1114
 TSHistogramExporter.cxx:1115
 TSHistogramExporter.cxx:1116
 TSHistogramExporter.cxx:1117
 TSHistogramExporter.cxx:1118
 TSHistogramExporter.cxx:1119
 TSHistogramExporter.cxx:1120
 TSHistogramExporter.cxx:1121
 TSHistogramExporter.cxx:1122
 TSHistogramExporter.cxx:1123
 TSHistogramExporter.cxx:1124
 TSHistogramExporter.cxx:1125
 TSHistogramExporter.cxx:1126
 TSHistogramExporter.cxx:1127
 TSHistogramExporter.cxx:1128
 TSHistogramExporter.cxx:1129
 TSHistogramExporter.cxx:1130
 TSHistogramExporter.cxx:1131
 TSHistogramExporter.cxx:1132
 TSHistogramExporter.cxx:1133
 TSHistogramExporter.cxx:1134
 TSHistogramExporter.cxx:1135
 TSHistogramExporter.cxx:1136
 TSHistogramExporter.cxx:1137
 TSHistogramExporter.cxx:1138
 TSHistogramExporter.cxx:1139
 TSHistogramExporter.cxx:1140
 TSHistogramExporter.cxx:1141
 TSHistogramExporter.cxx:1142
 TSHistogramExporter.cxx:1143
 TSHistogramExporter.cxx:1144
 TSHistogramExporter.cxx:1145
 TSHistogramExporter.cxx:1146
 TSHistogramExporter.cxx:1147
 TSHistogramExporter.cxx:1148
 TSHistogramExporter.cxx:1149
 TSHistogramExporter.cxx:1150
 TSHistogramExporter.cxx:1151
 TSHistogramExporter.cxx:1152
 TSHistogramExporter.cxx:1153
 TSHistogramExporter.cxx:1154
 TSHistogramExporter.cxx:1155
 TSHistogramExporter.cxx:1156
 TSHistogramExporter.cxx:1157
 TSHistogramExporter.cxx:1158
 TSHistogramExporter.cxx:1159
 TSHistogramExporter.cxx:1160
 TSHistogramExporter.cxx:1161
 TSHistogramExporter.cxx:1162
 TSHistogramExporter.cxx:1163
 TSHistogramExporter.cxx:1164
 TSHistogramExporter.cxx:1165
 TSHistogramExporter.cxx:1166
 TSHistogramExporter.cxx:1167
 TSHistogramExporter.cxx:1168
 TSHistogramExporter.cxx:1169
 TSHistogramExporter.cxx:1170
 TSHistogramExporter.cxx:1171
 TSHistogramExporter.cxx:1172
 TSHistogramExporter.cxx:1173
 TSHistogramExporter.cxx:1174
 TSHistogramExporter.cxx:1175
 TSHistogramExporter.cxx:1176
 TSHistogramExporter.cxx:1177
 TSHistogramExporter.cxx:1178
 TSHistogramExporter.cxx:1179
 TSHistogramExporter.cxx:1180
 TSHistogramExporter.cxx:1181
 TSHistogramExporter.cxx:1182
 TSHistogramExporter.cxx:1183
 TSHistogramExporter.cxx:1184
 TSHistogramExporter.cxx:1185
 TSHistogramExporter.cxx:1186
 TSHistogramExporter.cxx:1187
 TSHistogramExporter.cxx:1188
 TSHistogramExporter.cxx:1189
 TSHistogramExporter.cxx:1190
 TSHistogramExporter.cxx:1191
 TSHistogramExporter.cxx:1192
 TSHistogramExporter.cxx:1193
 TSHistogramExporter.cxx:1194
 TSHistogramExporter.cxx:1195
 TSHistogramExporter.cxx:1196
 TSHistogramExporter.cxx:1197
 TSHistogramExporter.cxx:1198
 TSHistogramExporter.cxx:1199
 TSHistogramExporter.cxx:1200
 TSHistogramExporter.cxx:1201
 TSHistogramExporter.cxx:1202
 TSHistogramExporter.cxx:1203
 TSHistogramExporter.cxx:1204
 TSHistogramExporter.cxx:1205
 TSHistogramExporter.cxx:1206
 TSHistogramExporter.cxx:1207
 TSHistogramExporter.cxx:1208
 TSHistogramExporter.cxx:1209
 TSHistogramExporter.cxx:1210
 TSHistogramExporter.cxx:1211
 TSHistogramExporter.cxx:1212
 TSHistogramExporter.cxx:1213
 TSHistogramExporter.cxx:1214
 TSHistogramExporter.cxx:1215
 TSHistogramExporter.cxx:1216
 TSHistogramExporter.cxx:1217
 TSHistogramExporter.cxx:1218
 TSHistogramExporter.cxx:1219
 TSHistogramExporter.cxx:1220
 TSHistogramExporter.cxx:1221
 TSHistogramExporter.cxx:1222
 TSHistogramExporter.cxx:1223
 TSHistogramExporter.cxx:1224
 TSHistogramExporter.cxx:1225
 TSHistogramExporter.cxx:1226
 TSHistogramExporter.cxx:1227
 TSHistogramExporter.cxx:1228
 TSHistogramExporter.cxx:1229
 TSHistogramExporter.cxx:1230
 TSHistogramExporter.cxx:1231
 TSHistogramExporter.cxx:1232
 TSHistogramExporter.cxx:1233
 TSHistogramExporter.cxx:1234
 TSHistogramExporter.cxx:1235
 TSHistogramExporter.cxx:1236
 TSHistogramExporter.cxx:1237
 TSHistogramExporter.cxx:1238
 TSHistogramExporter.cxx:1239
 TSHistogramExporter.cxx:1240
 TSHistogramExporter.cxx:1241
 TSHistogramExporter.cxx:1242
 TSHistogramExporter.cxx:1243
 TSHistogramExporter.cxx:1244
 TSHistogramExporter.cxx:1245
 TSHistogramExporter.cxx:1246
 TSHistogramExporter.cxx:1247
 TSHistogramExporter.cxx:1248
 TSHistogramExporter.cxx:1249
 TSHistogramExporter.cxx:1250
 TSHistogramExporter.cxx:1251
 TSHistogramExporter.cxx:1252
 TSHistogramExporter.cxx:1253
 TSHistogramExporter.cxx:1254
 TSHistogramExporter.cxx:1255
 TSHistogramExporter.cxx:1256
 TSHistogramExporter.cxx:1257
 TSHistogramExporter.cxx:1258
 TSHistogramExporter.cxx:1259
 TSHistogramExporter.cxx:1260
 TSHistogramExporter.cxx:1261
 TSHistogramExporter.cxx:1262
 TSHistogramExporter.cxx:1263
 TSHistogramExporter.cxx:1264
 TSHistogramExporter.cxx:1265
 TSHistogramExporter.cxx:1266
 TSHistogramExporter.cxx:1267
 TSHistogramExporter.cxx:1268
 TSHistogramExporter.cxx:1269
 TSHistogramExporter.cxx:1270
 TSHistogramExporter.cxx:1271
 TSHistogramExporter.cxx:1272
 TSHistogramExporter.cxx:1273
 TSHistogramExporter.cxx:1274
 TSHistogramExporter.cxx:1275
 TSHistogramExporter.cxx:1276
 TSHistogramExporter.cxx:1277
 TSHistogramExporter.cxx:1278
 TSHistogramExporter.cxx:1279
 TSHistogramExporter.cxx:1280
 TSHistogramExporter.cxx:1281
 TSHistogramExporter.cxx:1282
 TSHistogramExporter.cxx:1283
 TSHistogramExporter.cxx:1284
 TSHistogramExporter.cxx:1285
 TSHistogramExporter.cxx:1286
 TSHistogramExporter.cxx:1287
 TSHistogramExporter.cxx:1288
 TSHistogramExporter.cxx:1289
 TSHistogramExporter.cxx:1290
 TSHistogramExporter.cxx:1291
 TSHistogramExporter.cxx:1292
 TSHistogramExporter.cxx:1293
 TSHistogramExporter.cxx:1294
 TSHistogramExporter.cxx:1295
 TSHistogramExporter.cxx:1296
 TSHistogramExporter.cxx:1297
 TSHistogramExporter.cxx:1298
 TSHistogramExporter.cxx:1299
 TSHistogramExporter.cxx:1300
 TSHistogramExporter.cxx:1301
 TSHistogramExporter.cxx:1302
 TSHistogramExporter.cxx:1303
 TSHistogramExporter.cxx:1304
 TSHistogramExporter.cxx:1305
 TSHistogramExporter.cxx:1306
 TSHistogramExporter.cxx:1307
 TSHistogramExporter.cxx:1308
 TSHistogramExporter.cxx:1309
 TSHistogramExporter.cxx:1310
 TSHistogramExporter.cxx:1311
 TSHistogramExporter.cxx:1312
 TSHistogramExporter.cxx:1313
 TSHistogramExporter.cxx:1314
 TSHistogramExporter.cxx:1315
 TSHistogramExporter.cxx:1316
 TSHistogramExporter.cxx:1317
 TSHistogramExporter.cxx:1318
 TSHistogramExporter.cxx:1319
 TSHistogramExporter.cxx:1320
 TSHistogramExporter.cxx:1321
 TSHistogramExporter.cxx:1322
 TSHistogramExporter.cxx:1323
 TSHistogramExporter.cxx:1324
 TSHistogramExporter.cxx:1325
 TSHistogramExporter.cxx:1326
 TSHistogramExporter.cxx:1327
 TSHistogramExporter.cxx:1328
 TSHistogramExporter.cxx:1329
 TSHistogramExporter.cxx:1330
 TSHistogramExporter.cxx:1331
 TSHistogramExporter.cxx:1332
 TSHistogramExporter.cxx:1333
 TSHistogramExporter.cxx:1334
 TSHistogramExporter.cxx:1335
 TSHistogramExporter.cxx:1336
 TSHistogramExporter.cxx:1337
 TSHistogramExporter.cxx:1338
 TSHistogramExporter.cxx:1339
 TSHistogramExporter.cxx:1340
 TSHistogramExporter.cxx:1341
 TSHistogramExporter.cxx:1342
 TSHistogramExporter.cxx:1343
 TSHistogramExporter.cxx:1344
 TSHistogramExporter.cxx:1345
 TSHistogramExporter.cxx:1346
 TSHistogramExporter.cxx:1347
 TSHistogramExporter.cxx:1348
 TSHistogramExporter.cxx:1349
 TSHistogramExporter.cxx:1350
 TSHistogramExporter.cxx:1351
 TSHistogramExporter.cxx:1352