//  
// Author: Soeren Stamm <mailto: stamm@physik.hu-berlin.de>
// Update: $Id: AtlHistFactorySystematic.h,v 1.6 2016/04/19 07:46:21 stamm Exp $
// Copyright: 2015 (C) Soeren Stamm
//
#ifndef ATLAS_AtlHistFactorySystematic
#define ATLAS_AtlHistFactorySystematic
#ifndef ROOT_TNamed
#include <TNamed.h>
#endif
#ifndef ROOT_TH1
#include <TH1.h>
#endif
#ifndef ROOT_TH1F
#include <TH1F.h>
#endif
#ifndef ROOT_TGraph
#include <TGraph.h>
#endif
#ifndef ROOT_TString
#include <TString.h>
#endif
#ifndef ROOT_TFile
#include <TFile.h>
#endif

class AtlHistFactorySystematic : public TNamed {
    
protected:
    TH1 *fHistUp;   // Histogram for   up-variation (1-sigma)
    TH1 *fHistDown; // Histogram for down-variation (1-sigma)
    TH1 *fHistNom;  // Nominal histogram
    TH1 *fHistShapeResidual;    // Chi2 normalized residuals
    TGraph *fGraphShapeQQPlot;  // Q-Q plots of normalized residuals

    TFile *fTemplateFile; // File holding all templates
    
    TString *fDiscriminant;  // Full path to the discriminant histogram

    Bool_t fIsNominal;     // Is this nominal?
    Bool_t fUseShape;      // Use shape information?
    Bool_t fUseFullStats;  // Use full staistics for shape comparison?

    Int_t fNPseudoExp;    // Number of pseudo exp. for shape tests
    TH1F *fHistChi2;      // Chi2 Distribution for shape tests
    Bool_t fUsePseudoExp; // Use pseudo exp. for shape tests?

    Double_t fPValue_up;   // p-value from Chi2 test (up-syst.)
    Double_t fPValue_down; // p-value from Chi2 test (down-syst.)
    
public:
    AtlHistFactorySystematic();
    AtlHistFactorySystematic(const char* systname,
			     const char* systtitle,
			     Bool_t useShape);
    virtual ~AtlHistFactorySystematic();
    
    virtual void Initialize(const char* BaseDir,
			    const char* scheme) = 0;
    virtual void Clear(Option_t *option = "") = 0;
    virtual void SaveTemplates(TFile *fout);
    virtual void SaveShapeCtrlPlots(TFile *fout,
				    const char* process);
    virtual void ExportShapePlots(const char* process,
				  const char* dir);
    
    void ChangeProcess(const char* process);
    void PerformShapeTest(Double_t& pval_up,
			  Double_t& kstest_min);
    
    void GetRateUnc(Double_t& rate_up, Double_t& rate_down);
    TH1F* GetChi2Distribution();
    
    void SetDiscriminant(const char* discriminant);

    inline TH1* GetHistUp() const { return fHistUp; }
    inline TH1* GetHistDown() const { return fHistDown; }
    inline TH1* GetHistNominal() const { return fHistNom; }

    inline Bool_t GetUseShape() const { return fUseShape; }
    inline Bool_t GetUseFullStats() const { return fUseFullStats; }
    
    inline Bool_t IsNominal() const { return fIsNominal; }

    inline void SetChi2Distribution(TH1F *h_chi2) { fHistChi2 = h_chi2; }
    inline void SetHistNominal(TH1 *h) { fHistNom = h; }
    inline void SetHistUp(TH1 *h) { fHistUp = h; }
    inline void SetHistDown(TH1 *h) { fHistDown = h; }

    inline void SetTemplateFile(TFile *f) { fTemplateFile = f; }

    inline void SetUseFullStats(Bool_t flag = kTRUE) { fUseFullStats = flag; }
    inline void SetUsePseudoExp(Bool_t flag = kTRUE) { fUsePseudoExp = flag; }
    inline void SetUseShape(Bool_t useShape = kTRUE) { fUseShape = useShape; }

protected:
    virtual void GetHistsFromFile(const char* process) = 0;
    virtual void ComputeUpDownVariation(const char* process) = 0;
    virtual void ComputeChi2Distribution();
    
    ClassDef(AtlHistFactorySystematic, 1) // Histfactory Systematic
};
#endif

 AtlHistFactorySystematic.h:1
 AtlHistFactorySystematic.h:2
 AtlHistFactorySystematic.h:3
 AtlHistFactorySystematic.h:4
 AtlHistFactorySystematic.h:5
 AtlHistFactorySystematic.h:6
 AtlHistFactorySystematic.h:7
 AtlHistFactorySystematic.h:8
 AtlHistFactorySystematic.h:9
 AtlHistFactorySystematic.h:10
 AtlHistFactorySystematic.h:11
 AtlHistFactorySystematic.h:12
 AtlHistFactorySystematic.h:13
 AtlHistFactorySystematic.h:14
 AtlHistFactorySystematic.h:15
 AtlHistFactorySystematic.h:16
 AtlHistFactorySystematic.h:17
 AtlHistFactorySystematic.h:18
 AtlHistFactorySystematic.h:19
 AtlHistFactorySystematic.h:20
 AtlHistFactorySystematic.h:21
 AtlHistFactorySystematic.h:22
 AtlHistFactorySystematic.h:23
 AtlHistFactorySystematic.h:24
 AtlHistFactorySystematic.h:25
 AtlHistFactorySystematic.h:26
 AtlHistFactorySystematic.h:27
 AtlHistFactorySystematic.h:28
 AtlHistFactorySystematic.h:29
 AtlHistFactorySystematic.h:30
 AtlHistFactorySystematic.h:31
 AtlHistFactorySystematic.h:32
 AtlHistFactorySystematic.h:33
 AtlHistFactorySystematic.h:34
 AtlHistFactorySystematic.h:35
 AtlHistFactorySystematic.h:36
 AtlHistFactorySystematic.h:37
 AtlHistFactorySystematic.h:38
 AtlHistFactorySystematic.h:39
 AtlHistFactorySystematic.h:40
 AtlHistFactorySystematic.h:41
 AtlHistFactorySystematic.h:42
 AtlHistFactorySystematic.h:43
 AtlHistFactorySystematic.h:44
 AtlHistFactorySystematic.h:45
 AtlHistFactorySystematic.h:46
 AtlHistFactorySystematic.h:47
 AtlHistFactorySystematic.h:48
 AtlHistFactorySystematic.h:49
 AtlHistFactorySystematic.h:50
 AtlHistFactorySystematic.h:51
 AtlHistFactorySystematic.h:52
 AtlHistFactorySystematic.h:53
 AtlHistFactorySystematic.h:54
 AtlHistFactorySystematic.h:55
 AtlHistFactorySystematic.h:56
 AtlHistFactorySystematic.h:57
 AtlHistFactorySystematic.h:58
 AtlHistFactorySystematic.h:59
 AtlHistFactorySystematic.h:60
 AtlHistFactorySystematic.h:61
 AtlHistFactorySystematic.h:62
 AtlHistFactorySystematic.h:63
 AtlHistFactorySystematic.h:64
 AtlHistFactorySystematic.h:65
 AtlHistFactorySystematic.h:66
 AtlHistFactorySystematic.h:67
 AtlHistFactorySystematic.h:68
 AtlHistFactorySystematic.h:69
 AtlHistFactorySystematic.h:70
 AtlHistFactorySystematic.h:71
 AtlHistFactorySystematic.h:72
 AtlHistFactorySystematic.h:73
 AtlHistFactorySystematic.h:74
 AtlHistFactorySystematic.h:75
 AtlHistFactorySystematic.h:76
 AtlHistFactorySystematic.h:77
 AtlHistFactorySystematic.h:78
 AtlHistFactorySystematic.h:79
 AtlHistFactorySystematic.h:80
 AtlHistFactorySystematic.h:81
 AtlHistFactorySystematic.h:82
 AtlHistFactorySystematic.h:83
 AtlHistFactorySystematic.h:84
 AtlHistFactorySystematic.h:85
 AtlHistFactorySystematic.h:86
 AtlHistFactorySystematic.h:87
 AtlHistFactorySystematic.h:88
 AtlHistFactorySystematic.h:89
 AtlHistFactorySystematic.h:90
 AtlHistFactorySystematic.h:91
 AtlHistFactorySystematic.h:92
 AtlHistFactorySystematic.h:93
 AtlHistFactorySystematic.h:94
 AtlHistFactorySystematic.h:95
 AtlHistFactorySystematic.h:96
 AtlHistFactorySystematic.h:97
 AtlHistFactorySystematic.h:98
 AtlHistFactorySystematic.h:99
 AtlHistFactorySystematic.h:100
 AtlHistFactorySystematic.h:101
 AtlHistFactorySystematic.h:102
 AtlHistFactorySystematic.h:103
 AtlHistFactorySystematic.h:104