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

// #define _DEBUG_

#include "QFramework/TQLibrary.h"

////////////////////////////////////////////////////////////////////////////////////////////////
//
// TQSystematicsHandler:
//
// With the advent of the TQSystematicsHandler, it is now easily
// possible to include not only normalization, but also shape
// systematics into histograms produced by a plotter or add systematic
// uncertainties to the cutflow uncertainties.
//
////////////////////////////////////////////////////////////////////////////////////////////////

ClassImp(TQSystematicsHandler)

TQSystematicsHandler::TQSystematicsHandler(const TString& name) :
TQSystematicsManager(new TQFolder("histograms")),TQFolder(name),
  _config(new TQFolder("systematicsHandler"))
{
  // constructor with name
}

//__________________________________________________________________________________|___________

TQSystematicsHandler::TQSystematicsHandler(const TString& name, TQFolder* cfg) :
TQSystematicsManager(new TQFolder("histograms")),TQFolder(name),  
  _config(cfg)
{
  // constructor with name and config
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::config(){
  return this->_config;
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::addCut(const TString& id){
  // add a cut to the systematics handler
  if(!TQFolder::isValidName(id)){
    ERRORclass("'%s' is not a valid identifier!",id.Data());
    return NULL;
  }
  TQFolder* cut = config()->getFolder("Cuts+")->getFolder(id+"+");
  cut->setTagString("Cut",id);
  return cut;
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::addSystematic(const TString& id, const TString& tags){
  // add a systematic to the systematics handler
  if(!TQFolder::isValidName(id)){
    ERRORclass("'%s' is not a valid identifier!",id.Data());
    return NULL;
  }
  TQFolder* sys = config()->getFolder("Systematics+")->getFolder(id+"+");
  sys->importTags(tags);
  return sys;
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::addSystematic(const TString& id, const TString& upvar, const TString& dnvar){
  // add a systematic to the systematics handler
  if(!TQFolder::isValidName(id)){
    ERRORclass("'%s' is not a valid identifier!",id.Data());
    return NULL;
  }
  TQFolder* sys = config()->getFolder("Systematics+")->getFolder(id+"+");
  sys->setTagString("Up",upvar);
  sys->setTagString("Down",dnvar);  
  return sys;
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::addVariation(const TString& id, const TString& tags){
  // add a variation to the systematics handler
  if(!TQFolder::isValidName(id)){
    ERRORclass("'%s' is not a valid identifier!",id.Data());
    return NULL;
  }
  TQFolder* var = config()->getFolder("Variations+")->getFolder(id+"+");
  var->importTags(tags);
  return var;
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::addSample(const TString& id, const TString& path){
  // add a sample to the systematics handler
  if(!TQFolder::isValidName(id)){
    ERRORclass("'%s' is not a valid identifier!",id.Data());
    return NULL;
  }
  TQFolder* sample = config()->getFolder("Samples+")->getFolder(id+"+");
  sample->setTagString("Path",path);
  return sample;
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::addHistogram(const TString& id, const TString& path, const TString& options){
  TQFolder* hist = config()->getFolder("Histograms+")->getFolder(id+"+");
  hist->setTagString("Path",path);
  TString tmp(path);
  hist->setTagString("Cut",TQFolder::getPathHead(tmp));
  hist->importTags(options);
  return hist;
}

namespace {
  struct HistOptions{
    TString name;
    TString cut;
    TString path;
    TQTaggable* options;
    HistOptions(TString name){
      this->path = name;
      this->name = TQFolder::getPathTail(name);
      this->cut = name;
      this->options = NULL;
    }
    HistOptions(TQFolder* config){
      this->path = config->getTagStringDefault("Path");
      this->name = config->GetName();
      this->cut = config->getTagStringDefault("Cut");
      this->options = config;
    }
  };
}

void TQSystematicsHandler::collectHistograms(TQSampleDataReader* rd, TQFolder* variation){
  // collect the counters from a reader for one subpath of the type systname/file.root/
  TQFolder* cuts = this->config()->getFolder("Cuts");
  if(!variation->hasTag("Variation")) variation->setTagString("Variation",variation->GetName());  
  TQFolderIterator sampleItr(this->config()->getListOfFolders("Samples/?"));
  while(sampleItr.hasNext()){
    TQFolder* sampleConfig = sampleItr.readNext();
    TString sfolderpath = variation->replaceInText(sampleConfig->getTagStringDefault("Path",""));
    if(sfolderpath.Contains("$")){    
      ERROR("sample '%s' has unexpanded alias in path: '%s'. skipping.",sampleConfig->GetName(),sfolderpath.Data());
      continue;
    }
    std::vector<HistOptions> histograms;
    TQIterator histoItr(rd->getListOfHistogramNames(sfolderpath),true);
    if(histoItr.getCollection() && histoItr.getCollection()->GetSize() > 0){
      while(histoItr.hasNext()){
        TString histo(histoItr.readNext()->GetName());
        auto h = HistOptions(histo);
        if(cuts && !cuts->getFolder(h.cut)) continue;
        histograms.push_back(h);
      }
    }
    TQFolderIterator morehistos(this->config()->getListOfFolders("Histograms/?"),true);
    while(morehistos.hasNext()){
      TQFolder* c = morehistos.readNext();
      histograms.emplace_back(HistOptions(c));
    }
    std::map<TString,std::vector<TString> > histoNames;
    for(const auto& hist:histograms){
      TH1* h = rd->getHistogram(sfolderpath,hist.path,hist.options);
      if(!h){
        ERROR("failed to retrieve histogram '%s' from path '%s' with options '%s'",hist.name.Data(),hist.path.Data(),hist.options ? hist.options->exportTagsAsString().Data() : "");
        continue;
      }
      if(histoNames.find(hist.cut) == histoNames.end()) histoNames[hist.cut] = std::vector<TString>();
      histoNames[hist.cut].push_back(hist.name);
      h->SetName(sampleConfig->getName()+"."+hist.name);
      this->storeVarHisto(h,variation->GetName(),hist.cut);
    }
    for(auto histo:histoNames){
      TQFolder* cut = this->getFolder(histo.first+"+");
      cut->setTagList("Shapes",histo.second);
    }
  }
}

//__________________________________________________________________________________|___________

void TQSystematicsHandler::collectCounters(TQSampleDataReader* rd, TQFolder* variation){
  // collect the counters from a reader for one subpath of the type systname/file.root/
  TQFolder* cuts = this->config()->getFolder("Cuts");  
  TQFolderIterator sampleItr(this->config()->getListOfFolders("Samples/?"));
  while(sampleItr.hasNext()){
    TQFolder* sampleConfig = sampleItr.readNext();
    TString sfolderpath = variation->replaceInText(sampleConfig->getTagStringDefault("Path",""));
    if(sfolderpath.Contains("$")){
      ERROR("sample '%s' has unexpanded alias in path: '%s'. skipping.",sampleConfig->GetName(),sfolderpath.Data());
      continue;
    }    
    DEBUGclass("retrieving counters for sample '%s' from path '%s'",sampleConfig->GetName(),sfolderpath.Data());
    TQIterator cntItr(rd->getListOfCounterNames(sfolderpath),true);
    if(!cntItr.getCollection() || cntItr.getCollection()->GetSize() == 0){
      ERRORclass("unable to retrieve list of counters from sample '%s'",sfolderpath.Data());
    } else {
      while(cntItr.hasNext()){
        TString cutname(cntItr.readNext()->GetName());
        if(cuts && !cuts->getFolder(cutname)) continue;        
        TQCounter* cnt = rd->getCounter(sfolderpath,cutname);
        if(cnt->getRawCounter()>0){
          this->getFolder(cutname+"+")->setTagString("Cut",cutname);
          cnt->SetName(sampleConfig->getName()+".yield");      
          TH1* h = TQHistogramUtils::counterToHistogram(cnt);
          this->storeVarHisto(h,variation->GetName(),cutname);
        }
        delete cnt;
      }
    }
  }
}


//__________________________________________________________________________________|___________

void TQSystematicsHandler::collectVariation(TQFolder* var){
  // collect counters and histograms for one systematic
  //@tag: [verbose] This object tag enables verbosity.
  if(this->getTagBoolDefault("verbose",false)){
    INFOclass("collecting variation '%s'",var->GetName());
  }
  TQSampleFolder* sf = this->getSampleFolder(var);
  TQSampleDataReader* rd = new TQSampleDataReader(sf);
  rd->setApplyStyles(false);
  this->collectCounters  (rd,var);
  this->collectHistograms(rd,var);
  delete rd;
}

//__________________________________________________________________________________|___________

void TQSystematicsHandler::collect(){
  // collect counters and histograms for all registered systematics
  DEBUGclass("starting collection of variations");
  TQFolderIterator itr(this->config()->getListOfFolders("Variations/?"),true);
  while(itr.hasNext()){
    this->collectVariation(itr.readNext());
  }
}

//__________________________________________________________________________________|___________

void TQSystematicsHandler::compute(){
  // compute the systematic uncertainties from the variations
  DEBUGclass("starting collection of variations");  
  TQFolderIterator cuts(this->getListOfFolders("?"));
  while(cuts.hasNext()){
    TQFolder* cut = cuts.readNext();
    DEBUGclass("computing for cut '%s'",cut->GetName());      
    cut->importTags(this->config()->getFolder("Cuts")->getFolder(cut->GetName()));
    TQFolderIterator samples(this->config()->getListOfFolders("Samples/?"),true);
    while(samples.hasNext()){
      TQFolder* sample = cut->getFolder(samples.readNext()->getName()+"+");
      sample->setTagString("Sample",sample->GetName());
      DEBUGclass("    for sample '%s'",sample->GetName());
      TQFolderIterator systematics(this->config()->getListOfFolders("Systematics/?"),true);
      while(systematics.hasNext()){
        TQFolder* sysConfig = systematics.readNext();    
        DEBUGclass("        for systematic '%s'",sysConfig->GetName());              
        TQFolder* sys = sample->getFolder(sysConfig->getName()+"+");
        sys->setTagString("Systematic",sysConfig->getName());
        sys->importTags(sysConfig);
        this->includeOverallSys(sysConfig,sys,cut->GetName(),sample->getName()+".yield");
        for(const auto& shape:cut->getTagVString("Shapes")){
          DEBUGclass("            shape '%s'",shape.Data());                        
          this->includeHistoSys(sysConfig,sys->getFolder(shape+"+"),cut->GetName(),sample->getName()+"."+shape);              
        }
      }
    }
  }
}

//__________________________________________________________________________________|___________

void TQSystematicsHandler::exportObjects(TQFolder* section,TQFolder* target, bool includeNormalizationInShape, bool symmetrizeOneSided){
  // export the created objects for one cut
  if(!section || !target) return;

  // obtain the normalization
  TQFolderIterator systItr(section->getListOfFolders("?"),true);  
  double totalyield = 0.;
  std::vector<double> variations;
  while(systItr.hasNext()){
    TQFolder* syst = systItr.readNext();
    if(!syst) continue;
    double up = 0.;
    double dn = 0.;
    // division by 2 here because of double counting of up/down    
    if(syst->getTagDouble("High",up) && syst->getTagDouble("Low",dn)){
      if(TQUtils::isNum(up) && TQUtils::isNum(dn)){
        totalyield += pow(0.5*(up-dn),2);
      } else if(TQUtils::isNum(up)){
        totalyield += pow(up,2);
      } else if(TQUtils::isNum(dn)){
        totalyield += pow(dn,2);
      }
    }
  }
  double normsys = sqrt(fabs(totalyield));
  target->setTagDouble("yield",normsys);

  // obtain the shape(s)
  target->setTagBool("shapeIncludesNormalization",includeNormalizationInShape);
  std::vector<TString> shapes = section->getTagVString("~Shapes");
  for(const auto& shape:shapes){
    DEBUGclass("exporting histograms '%s' for '%s' to '%s'",shape.Data(),section->getPath().Data(),target->getPath().Data());
    TQFolderIterator systItr(section->getListOfFolders("?/"+shape),true);
    std::vector<TH1*> histos_up;
    std::vector<TH1*> histos_dn;
    int n=0;
    while(systItr.hasNext()){
      TQFolder* syst = systItr.readNext();
      if(!syst) continue;
      TH1* h_up = this->getHisto(syst->getTagStringDefault("HistoRelHigh"));
      TH1* h_dn = this->getHisto(syst->getTagStringDefault("HistoRelLow"));
      if(!h_up || !h_dn){
        ERRORclass("unable to retrieve histograms for '%s'",syst->getTagStringDefault("~Systematic").Data());
        continue;
      }
      histos_up.push_back(h_up);
      histos_dn.push_back(h_dn);
      n++;
    }
    TH1* hist = NULL;
    double up;
    double dn;
    double delta;
    for(size_t i=0; i<histos_up.size(); ++i){
      if(!hist){
        hist = TQHistogramUtils::copyHistogram(histos_up[i],shape);
        hist->Reset();
      }
      for(int b=0; b<hist->GetNbinsX()+1; ++b){
        up = histos_up[i]->GetBinContent(b);
        dn = histos_dn[i]->GetBinContent(b);
        if (symmetrizeOneSided && up < 1. && dn < 1.) {
          delta = (up < dn) ? (2. * (1. - up)) : (2. * (1. - dn));
        }
        else if (symmetrizeOneSided && up > 1. && dn > 1.) {
          delta = (up > dn) ? (2. * (up - 1.)) : (2. * (dn - 1.));
        }
        else {
          delta = up - dn;
        }
        hist->AddBinContent(b,pow(0.5*delta,2));
      }
    }
    if(hist){
      double normComp = includeNormalizationInShape ? normsys : 0;
      for(int i=0; i<hist->GetNbinsX()+1; ++i){
        hist->SetBinContent(i,sqrt(hist->GetBinContent(i) + pow(normComp,2)));
        hist->SetBinError(i,0);
      }
      hist->SetEntries(n);
      hist->SetMinimum(0);
      if(!target->addObject(hist)){
        WARNclass("unable to export histogram '%s'",hist->GetName());
      }
    }
  }
}

//__________________________________________________________________________________|___________

TQFolder* TQSystematicsHandler::exportSystematics(const TString& sample, bool includeNormalizationInShape, bool symmetrizeOneSided){
  // create and export variation histograms and counters for all systematics
  TQFolder* systematics = new TQFolder(this->GetName());
  TQFolderIterator cuts(this->getListOfFolders(TQFolder::concatPaths("?",sample)),true);
  while(cuts.hasNext()){
    TQFolder* cut = cuts.readNext();
    if(!cut) continue;
    DEBUGclass("processing section '%s'",cut->getPath().Data());
    TQFolder* target = systematics->getFolder(cut->getTagStringDefault("~Cut")+"+");
    TQSystematicsHandler::exportObjects(cut, target, includeNormalizationInShape, symmetrizeOneSided);
  }
  return systematics;
}

//__________________________________________________________________________________|___________

void TQSystematicsHandler::printSystematics(){
  // create and export variation histograms and counters for all systematics
  TQFolderIterator folders(this->getListOfFolders("?/?"),true);
  while(folders.hasNext()){
    TQFolder* folder = folders.readNext();
    if(!folder) continue;
    std::cout << folder->GetName() << std::endl;
  }
}

//__________________________________________________________________________________|___________

bool TQSystematicsHandler::writeFolderHook(TDirectory* dir, const TString&, int, bool){
  // redirect internal writing to another folder
  TQFolder* tmpfolder = this->copy();
  bool ok = tmpfolder->writeFolder(dir,-1,false);
  delete tmpfolder;
  return ok;
}

//__________________________________________________________________________________|___________

std::vector<TQFolder*> TQSystematicsHandler::getRanking(const TString& cutname, const TString& sample){
  // return the systematics ranking for one specific cut
  TQFolder* section = this->getFolder(TQFolder::concatPaths(cutname,sample));
  std::vector<TQFolder*> retval;
  if(!section){
    ERRORclass("unable to retrieve ranking for cut '%s' and sample '%s'",cutname.Data(),sample.Data());
    return retval;
  }
  TQFolderIterator systematics(section->getListOfFolders("?"),true);
  while(systematics.hasNext()){
    TQFolder* f = systematics.readNext();
    retval.push_back(f);
  }
  std::sort(retval.begin(),retval.end(),[](TQFolder* a, TQFolder* b) {
    return a->getTagDoubleDefault("Percent",0) > b->getTagDoubleDefault("Percent",0);
  });
  return retval;
}

//__________________________________________________________________________________|___________

TQTable* TQSystematicsHandler::getTable(const TString& sample, const TString& cutname){
  // write the systematics table
  std::vector<TQFolder*> ranking = this->getRanking(sample,cutname);
  if(ranking.size() == 0) return NULL;
  TQTable* table = new TQTable(sample+"-"+cutname);
  table->expand(ranking.size()+1,2);
  table->setEntry(0,0,"Systematic");
  table->setEntry(0,1,"\\% yield","latex");
  table->setEntry(0,1,"% yield","plain");
  table->setEntry(0,1,"% yield","html");
  int idx=0;
  for(auto* systematic:ranking){
    double yield = systematic->getTagDoubleDefault("Percent",0);
    size_t row = idx+1;
    table->setEntry(row,0,systematic->GetName(),"ascii");
    //@tag: [title.latex,title.html] This folder tag is used to set the LaTeX/HTML representations of the systematic's title.
    table->setEntry(row,0,systematic->getTagStringDefault("title.latex",systematic->GetName()),"latex");
    table->setEntry(row,0,systematic->getTagStringDefault("title.html",systematic->GetName()),"html");
    table->setEntryValue(row,1,yield);
    ++idx;
  }
  return table;
}

//__________________________________________________________________________________|___________

TQSystematicsHandler::~TQSystematicsHandler(){
  delete _config;
}

//__________________________________________________________________________________|___________

TQSampleFolder* TQSystematicsHandler::getSampleFolder(const TString& name){
  return this->getSampleFolder(this->config()->getFolder("Variations")->getFolder(name));
}


 TQSystematicsHandler.cxx:1
 TQSystematicsHandler.cxx:2
 TQSystematicsHandler.cxx:3
 TQSystematicsHandler.cxx:4
 TQSystematicsHandler.cxx:5
 TQSystematicsHandler.cxx:6
 TQSystematicsHandler.cxx:7
 TQSystematicsHandler.cxx:8
 TQSystematicsHandler.cxx:9
 TQSystematicsHandler.cxx:10
 TQSystematicsHandler.cxx:11
 TQSystematicsHandler.cxx:12
 TQSystematicsHandler.cxx:13
 TQSystematicsHandler.cxx:14
 TQSystematicsHandler.cxx:15
 TQSystematicsHandler.cxx:16
 TQSystematicsHandler.cxx:17
 TQSystematicsHandler.cxx:18
 TQSystematicsHandler.cxx:19
 TQSystematicsHandler.cxx:20
 TQSystematicsHandler.cxx:21
 TQSystematicsHandler.cxx:22
 TQSystematicsHandler.cxx:23
 TQSystematicsHandler.cxx:24
 TQSystematicsHandler.cxx:25
 TQSystematicsHandler.cxx:26
 TQSystematicsHandler.cxx:27
 TQSystematicsHandler.cxx:28
 TQSystematicsHandler.cxx:29
 TQSystematicsHandler.cxx:30
 TQSystematicsHandler.cxx:31
 TQSystematicsHandler.cxx:32
 TQSystematicsHandler.cxx:33
 TQSystematicsHandler.cxx:34
 TQSystematicsHandler.cxx:35
 TQSystematicsHandler.cxx:36
 TQSystematicsHandler.cxx:37
 TQSystematicsHandler.cxx:38
 TQSystematicsHandler.cxx:39
 TQSystematicsHandler.cxx:40
 TQSystematicsHandler.cxx:41
 TQSystematicsHandler.cxx:42
 TQSystematicsHandler.cxx:43
 TQSystematicsHandler.cxx:44
 TQSystematicsHandler.cxx:45
 TQSystematicsHandler.cxx:46
 TQSystematicsHandler.cxx:47
 TQSystematicsHandler.cxx:48
 TQSystematicsHandler.cxx:49
 TQSystematicsHandler.cxx:50
 TQSystematicsHandler.cxx:51
 TQSystematicsHandler.cxx:52
 TQSystematicsHandler.cxx:53
 TQSystematicsHandler.cxx:54
 TQSystematicsHandler.cxx:55
 TQSystematicsHandler.cxx:56
 TQSystematicsHandler.cxx:57
 TQSystematicsHandler.cxx:58
 TQSystematicsHandler.cxx:59
 TQSystematicsHandler.cxx:60
 TQSystematicsHandler.cxx:61
 TQSystematicsHandler.cxx:62
 TQSystematicsHandler.cxx:63
 TQSystematicsHandler.cxx:64
 TQSystematicsHandler.cxx:65
 TQSystematicsHandler.cxx:66
 TQSystematicsHandler.cxx:67
 TQSystematicsHandler.cxx:68
 TQSystematicsHandler.cxx:69
 TQSystematicsHandler.cxx:70
 TQSystematicsHandler.cxx:71
 TQSystematicsHandler.cxx:72
 TQSystematicsHandler.cxx:73
 TQSystematicsHandler.cxx:74
 TQSystematicsHandler.cxx:75
 TQSystematicsHandler.cxx:76
 TQSystematicsHandler.cxx:77
 TQSystematicsHandler.cxx:78
 TQSystematicsHandler.cxx:79
 TQSystematicsHandler.cxx:80
 TQSystematicsHandler.cxx:81
 TQSystematicsHandler.cxx:82
 TQSystematicsHandler.cxx:83
 TQSystematicsHandler.cxx:84
 TQSystematicsHandler.cxx:85
 TQSystematicsHandler.cxx:86
 TQSystematicsHandler.cxx:87
 TQSystematicsHandler.cxx:88
 TQSystematicsHandler.cxx:89
 TQSystematicsHandler.cxx:90
 TQSystematicsHandler.cxx:91
 TQSystematicsHandler.cxx:92
 TQSystematicsHandler.cxx:93
 TQSystematicsHandler.cxx:94
 TQSystematicsHandler.cxx:95
 TQSystematicsHandler.cxx:96
 TQSystematicsHandler.cxx:97
 TQSystematicsHandler.cxx:98
 TQSystematicsHandler.cxx:99
 TQSystematicsHandler.cxx:100
 TQSystematicsHandler.cxx:101
 TQSystematicsHandler.cxx:102
 TQSystematicsHandler.cxx:103
 TQSystematicsHandler.cxx:104
 TQSystematicsHandler.cxx:105
 TQSystematicsHandler.cxx:106
 TQSystematicsHandler.cxx:107
 TQSystematicsHandler.cxx:108
 TQSystematicsHandler.cxx:109
 TQSystematicsHandler.cxx:110
 TQSystematicsHandler.cxx:111
 TQSystematicsHandler.cxx:112
 TQSystematicsHandler.cxx:113
 TQSystematicsHandler.cxx:114
 TQSystematicsHandler.cxx:115
 TQSystematicsHandler.cxx:116
 TQSystematicsHandler.cxx:117
 TQSystematicsHandler.cxx:118
 TQSystematicsHandler.cxx:119
 TQSystematicsHandler.cxx:120
 TQSystematicsHandler.cxx:121
 TQSystematicsHandler.cxx:122
 TQSystematicsHandler.cxx:123
 TQSystematicsHandler.cxx:124
 TQSystematicsHandler.cxx:125
 TQSystematicsHandler.cxx:126
 TQSystematicsHandler.cxx:127
 TQSystematicsHandler.cxx:128
 TQSystematicsHandler.cxx:129
 TQSystematicsHandler.cxx:130
 TQSystematicsHandler.cxx:131
 TQSystematicsHandler.cxx:132
 TQSystematicsHandler.cxx:133
 TQSystematicsHandler.cxx:134
 TQSystematicsHandler.cxx:135
 TQSystematicsHandler.cxx:136
 TQSystematicsHandler.cxx:137
 TQSystematicsHandler.cxx:138
 TQSystematicsHandler.cxx:139
 TQSystematicsHandler.cxx:140
 TQSystematicsHandler.cxx:141
 TQSystematicsHandler.cxx:142
 TQSystematicsHandler.cxx:143
 TQSystematicsHandler.cxx:144
 TQSystematicsHandler.cxx:145
 TQSystematicsHandler.cxx:146
 TQSystematicsHandler.cxx:147
 TQSystematicsHandler.cxx:148
 TQSystematicsHandler.cxx:149
 TQSystematicsHandler.cxx:150
 TQSystematicsHandler.cxx:151
 TQSystematicsHandler.cxx:152
 TQSystematicsHandler.cxx:153
 TQSystematicsHandler.cxx:154
 TQSystematicsHandler.cxx:155
 TQSystematicsHandler.cxx:156
 TQSystematicsHandler.cxx:157
 TQSystematicsHandler.cxx:158
 TQSystematicsHandler.cxx:159
 TQSystematicsHandler.cxx:160
 TQSystematicsHandler.cxx:161
 TQSystematicsHandler.cxx:162
 TQSystematicsHandler.cxx:163
 TQSystematicsHandler.cxx:164
 TQSystematicsHandler.cxx:165
 TQSystematicsHandler.cxx:166
 TQSystematicsHandler.cxx:167
 TQSystematicsHandler.cxx:168
 TQSystematicsHandler.cxx:169
 TQSystematicsHandler.cxx:170
 TQSystematicsHandler.cxx:171
 TQSystematicsHandler.cxx:172
 TQSystematicsHandler.cxx:173
 TQSystematicsHandler.cxx:174
 TQSystematicsHandler.cxx:175
 TQSystematicsHandler.cxx:176
 TQSystematicsHandler.cxx:177
 TQSystematicsHandler.cxx:178
 TQSystematicsHandler.cxx:179
 TQSystematicsHandler.cxx:180
 TQSystematicsHandler.cxx:181
 TQSystematicsHandler.cxx:182
 TQSystematicsHandler.cxx:183
 TQSystematicsHandler.cxx:184
 TQSystematicsHandler.cxx:185
 TQSystematicsHandler.cxx:186
 TQSystematicsHandler.cxx:187
 TQSystematicsHandler.cxx:188
 TQSystematicsHandler.cxx:189
 TQSystematicsHandler.cxx:190
 TQSystematicsHandler.cxx:191
 TQSystematicsHandler.cxx:192
 TQSystematicsHandler.cxx:193
 TQSystematicsHandler.cxx:194
 TQSystematicsHandler.cxx:195
 TQSystematicsHandler.cxx:196
 TQSystematicsHandler.cxx:197
 TQSystematicsHandler.cxx:198
 TQSystematicsHandler.cxx:199
 TQSystematicsHandler.cxx:200
 TQSystematicsHandler.cxx:201
 TQSystematicsHandler.cxx:202
 TQSystematicsHandler.cxx:203
 TQSystematicsHandler.cxx:204
 TQSystematicsHandler.cxx:205
 TQSystematicsHandler.cxx:206
 TQSystematicsHandler.cxx:207
 TQSystematicsHandler.cxx:208
 TQSystematicsHandler.cxx:209
 TQSystematicsHandler.cxx:210
 TQSystematicsHandler.cxx:211
 TQSystematicsHandler.cxx:212
 TQSystematicsHandler.cxx:213
 TQSystematicsHandler.cxx:214
 TQSystematicsHandler.cxx:215
 TQSystematicsHandler.cxx:216
 TQSystematicsHandler.cxx:217
 TQSystematicsHandler.cxx:218
 TQSystematicsHandler.cxx:219
 TQSystematicsHandler.cxx:220
 TQSystematicsHandler.cxx:221
 TQSystematicsHandler.cxx:222
 TQSystematicsHandler.cxx:223
 TQSystematicsHandler.cxx:224
 TQSystematicsHandler.cxx:225
 TQSystematicsHandler.cxx:226
 TQSystematicsHandler.cxx:227
 TQSystematicsHandler.cxx:228
 TQSystematicsHandler.cxx:229
 TQSystematicsHandler.cxx:230
 TQSystematicsHandler.cxx:231
 TQSystematicsHandler.cxx:232
 TQSystematicsHandler.cxx:233
 TQSystematicsHandler.cxx:234
 TQSystematicsHandler.cxx:235
 TQSystematicsHandler.cxx:236
 TQSystematicsHandler.cxx:237
 TQSystematicsHandler.cxx:238
 TQSystematicsHandler.cxx:239
 TQSystematicsHandler.cxx:240
 TQSystematicsHandler.cxx:241
 TQSystematicsHandler.cxx:242
 TQSystematicsHandler.cxx:243
 TQSystematicsHandler.cxx:244
 TQSystematicsHandler.cxx:245
 TQSystematicsHandler.cxx:246
 TQSystematicsHandler.cxx:247
 TQSystematicsHandler.cxx:248
 TQSystematicsHandler.cxx:249
 TQSystematicsHandler.cxx:250
 TQSystematicsHandler.cxx:251
 TQSystematicsHandler.cxx:252
 TQSystematicsHandler.cxx:253
 TQSystematicsHandler.cxx:254
 TQSystematicsHandler.cxx:255
 TQSystematicsHandler.cxx:256
 TQSystematicsHandler.cxx:257
 TQSystematicsHandler.cxx:258
 TQSystematicsHandler.cxx:259
 TQSystematicsHandler.cxx:260
 TQSystematicsHandler.cxx:261
 TQSystematicsHandler.cxx:262
 TQSystematicsHandler.cxx:263
 TQSystematicsHandler.cxx:264
 TQSystematicsHandler.cxx:265
 TQSystematicsHandler.cxx:266
 TQSystematicsHandler.cxx:267
 TQSystematicsHandler.cxx:268
 TQSystematicsHandler.cxx:269
 TQSystematicsHandler.cxx:270
 TQSystematicsHandler.cxx:271
 TQSystematicsHandler.cxx:272
 TQSystematicsHandler.cxx:273
 TQSystematicsHandler.cxx:274
 TQSystematicsHandler.cxx:275
 TQSystematicsHandler.cxx:276
 TQSystematicsHandler.cxx:277
 TQSystematicsHandler.cxx:278
 TQSystematicsHandler.cxx:279
 TQSystematicsHandler.cxx:280
 TQSystematicsHandler.cxx:281
 TQSystematicsHandler.cxx:282
 TQSystematicsHandler.cxx:283
 TQSystematicsHandler.cxx:284
 TQSystematicsHandler.cxx:285
 TQSystematicsHandler.cxx:286
 TQSystematicsHandler.cxx:287
 TQSystematicsHandler.cxx:288
 TQSystematicsHandler.cxx:289
 TQSystematicsHandler.cxx:290
 TQSystematicsHandler.cxx:291
 TQSystematicsHandler.cxx:292
 TQSystematicsHandler.cxx:293
 TQSystematicsHandler.cxx:294
 TQSystematicsHandler.cxx:295
 TQSystematicsHandler.cxx:296
 TQSystematicsHandler.cxx:297
 TQSystematicsHandler.cxx:298
 TQSystematicsHandler.cxx:299
 TQSystematicsHandler.cxx:300
 TQSystematicsHandler.cxx:301
 TQSystematicsHandler.cxx:302
 TQSystematicsHandler.cxx:303
 TQSystematicsHandler.cxx:304
 TQSystematicsHandler.cxx:305
 TQSystematicsHandler.cxx:306
 TQSystematicsHandler.cxx:307
 TQSystematicsHandler.cxx:308
 TQSystematicsHandler.cxx:309
 TQSystematicsHandler.cxx:310
 TQSystematicsHandler.cxx:311
 TQSystematicsHandler.cxx:312
 TQSystematicsHandler.cxx:313
 TQSystematicsHandler.cxx:314
 TQSystematicsHandler.cxx:315
 TQSystematicsHandler.cxx:316
 TQSystematicsHandler.cxx:317
 TQSystematicsHandler.cxx:318
 TQSystematicsHandler.cxx:319
 TQSystematicsHandler.cxx:320
 TQSystematicsHandler.cxx:321
 TQSystematicsHandler.cxx:322
 TQSystematicsHandler.cxx:323
 TQSystematicsHandler.cxx:324
 TQSystematicsHandler.cxx:325
 TQSystematicsHandler.cxx:326
 TQSystematicsHandler.cxx:327
 TQSystematicsHandler.cxx:328
 TQSystematicsHandler.cxx:329
 TQSystematicsHandler.cxx:330
 TQSystematicsHandler.cxx:331
 TQSystematicsHandler.cxx:332
 TQSystematicsHandler.cxx:333
 TQSystematicsHandler.cxx:334
 TQSystematicsHandler.cxx:335
 TQSystematicsHandler.cxx:336
 TQSystematicsHandler.cxx:337
 TQSystematicsHandler.cxx:338
 TQSystematicsHandler.cxx:339
 TQSystematicsHandler.cxx:340
 TQSystematicsHandler.cxx:341
 TQSystematicsHandler.cxx:342
 TQSystematicsHandler.cxx:343
 TQSystematicsHandler.cxx:344
 TQSystematicsHandler.cxx:345
 TQSystematicsHandler.cxx:346
 TQSystematicsHandler.cxx:347
 TQSystematicsHandler.cxx:348
 TQSystematicsHandler.cxx:349
 TQSystematicsHandler.cxx:350
 TQSystematicsHandler.cxx:351
 TQSystematicsHandler.cxx:352
 TQSystematicsHandler.cxx:353
 TQSystematicsHandler.cxx:354
 TQSystematicsHandler.cxx:355
 TQSystematicsHandler.cxx:356
 TQSystematicsHandler.cxx:357
 TQSystematicsHandler.cxx:358
 TQSystematicsHandler.cxx:359
 TQSystematicsHandler.cxx:360
 TQSystematicsHandler.cxx:361
 TQSystematicsHandler.cxx:362
 TQSystematicsHandler.cxx:363
 TQSystematicsHandler.cxx:364
 TQSystematicsHandler.cxx:365
 TQSystematicsHandler.cxx:366
 TQSystematicsHandler.cxx:367
 TQSystematicsHandler.cxx:368
 TQSystematicsHandler.cxx:369
 TQSystematicsHandler.cxx:370
 TQSystematicsHandler.cxx:371
 TQSystematicsHandler.cxx:372
 TQSystematicsHandler.cxx:373
 TQSystematicsHandler.cxx:374
 TQSystematicsHandler.cxx:375
 TQSystematicsHandler.cxx:376
 TQSystematicsHandler.cxx:377
 TQSystematicsHandler.cxx:378
 TQSystematicsHandler.cxx:379
 TQSystematicsHandler.cxx:380
 TQSystematicsHandler.cxx:381
 TQSystematicsHandler.cxx:382
 TQSystematicsHandler.cxx:383
 TQSystematicsHandler.cxx:384
 TQSystematicsHandler.cxx:385
 TQSystematicsHandler.cxx:386
 TQSystematicsHandler.cxx:387
 TQSystematicsHandler.cxx:388
 TQSystematicsHandler.cxx:389
 TQSystematicsHandler.cxx:390
 TQSystematicsHandler.cxx:391
 TQSystematicsHandler.cxx:392
 TQSystematicsHandler.cxx:393
 TQSystematicsHandler.cxx:394
 TQSystematicsHandler.cxx:395
 TQSystematicsHandler.cxx:396
 TQSystematicsHandler.cxx:397
 TQSystematicsHandler.cxx:398
 TQSystematicsHandler.cxx:399
 TQSystematicsHandler.cxx:400
 TQSystematicsHandler.cxx:401
 TQSystematicsHandler.cxx:402
 TQSystematicsHandler.cxx:403
 TQSystematicsHandler.cxx:404
 TQSystematicsHandler.cxx:405
 TQSystematicsHandler.cxx:406
 TQSystematicsHandler.cxx:407
 TQSystematicsHandler.cxx:408
 TQSystematicsHandler.cxx:409
 TQSystematicsHandler.cxx:410
 TQSystematicsHandler.cxx:411
 TQSystematicsHandler.cxx:412
 TQSystematicsHandler.cxx:413
 TQSystematicsHandler.cxx:414
 TQSystematicsHandler.cxx:415
 TQSystematicsHandler.cxx:416
 TQSystematicsHandler.cxx:417
 TQSystematicsHandler.cxx:418
 TQSystematicsHandler.cxx:419
 TQSystematicsHandler.cxx:420
 TQSystematicsHandler.cxx:421
 TQSystematicsHandler.cxx:422
 TQSystematicsHandler.cxx:423
 TQSystematicsHandler.cxx:424
 TQSystematicsHandler.cxx:425
 TQSystematicsHandler.cxx:426
 TQSystematicsHandler.cxx:427
 TQSystematicsHandler.cxx:428
 TQSystematicsHandler.cxx:429
 TQSystematicsHandler.cxx:430
 TQSystematicsHandler.cxx:431
 TQSystematicsHandler.cxx:432
 TQSystematicsHandler.cxx:433
 TQSystematicsHandler.cxx:434
 TQSystematicsHandler.cxx:435
 TQSystematicsHandler.cxx:436
 TQSystematicsHandler.cxx:437
 TQSystematicsHandler.cxx:438
 TQSystematicsHandler.cxx:439
 TQSystematicsHandler.cxx:440
 TQSystematicsHandler.cxx:441
 TQSystematicsHandler.cxx:442
 TQSystematicsHandler.cxx:443
 TQSystematicsHandler.cxx:444
 TQSystematicsHandler.cxx:445
 TQSystematicsHandler.cxx:446
 TQSystematicsHandler.cxx:447
 TQSystematicsHandler.cxx:448
 TQSystematicsHandler.cxx:449
 TQSystematicsHandler.cxx:450
 TQSystematicsHandler.cxx:451
 TQSystematicsHandler.cxx:452
 TQSystematicsHandler.cxx:453
 TQSystematicsHandler.cxx:454
 TQSystematicsHandler.cxx:455
 TQSystematicsHandler.cxx:456
 TQSystematicsHandler.cxx:457
 TQSystematicsHandler.cxx:458
 TQSystematicsHandler.cxx:459
 TQSystematicsHandler.cxx:460
 TQSystematicsHandler.cxx:461
 TQSystematicsHandler.cxx:462
 TQSystematicsHandler.cxx:463
 TQSystematicsHandler.cxx:464
 TQSystematicsHandler.cxx:465
 TQSystematicsHandler.cxx:466
 TQSystematicsHandler.cxx:467
 TQSystematicsHandler.cxx:468
 TQSystematicsHandler.cxx:469
 TQSystematicsHandler.cxx:470