ROOT logo
// @(#)root/roostats:$Id$
// Author: George Lewis, Kyle Cranmer
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef HISTFACTORY_SYSTEMATICS_H
#define HISTFACTORY_SYSTEMATICS_H

#include <string>
#include <fstream>
#include <iostream>

#include "TH1.h"
#include "RooStats/HistFactory/HistRef.h"

namespace RooStats{
namespace HistFactory {

  namespace Constraint {
    enum Type{ Gaussian, Poisson };            
    std::string Name( Type type ); 
    Type GetType( const std::string& Name );
  }


  // Base class for common functions
  /*
  class Systematic {
    
  public:

    virtual void Print(std::ostream& = std::cout);
    virtual void writeToFile(const std::string& FileName, 
			     const std::string& Directory);
    
    
  };
  */

  class OverallSys {

  public:

    OverallSys() : fLow(0), fHigh(0) {} 

    void SetName( const std::string& Name ) { fName = Name; }
    std::string GetName() { return fName; }

    void SetLow( double Low )   { fLow  = Low; }
    void SetHigh( double High ) { fHigh = High; }
    double GetLow() { return fLow; }
    double GetHigh() { return fHigh; }

    void Print(std::ostream& = std::cout);  
    void PrintXML(std::ostream&);

  protected:
    std::string fName;
    double fLow;
    double fHigh;

  };


  class NormFactor {

  public:

    NormFactor();

    void SetName( const std::string& Name ) { fName = Name; }
    std::string GetName() { return fName; }

    void SetVal( double Val ) { fVal = Val; }
    double GetVal() { return fVal; }

    void SetConst( bool Const=true ) { fConst = Const; }
    bool GetConst() { return fConst; }

    void SetLow( double Low )   { fLow  = Low; }
    void SetHigh( double High ) { fHigh = High; }
    double GetLow() { return fLow; }
    double GetHigh() { return fHigh; }

    void Print(std::ostream& = std::cout);      
    void PrintXML(std::ostream&);

  protected:

    std::string fName;
    double fVal;
    double fLow;
    double fHigh;
    bool fConst;

  };


  class HistoSys {

  public:

    HistoSys() : fhLow(NULL), fhHigh(NULL) {;}
    HistoSys(const std::string& Name) : fName(Name), fhLow(NULL), fhHigh(NULL) {;}

    void Print(std::ostream& = std::cout);  
    void PrintXML(std::ostream&);
    void writeToFile( const std::string& FileName, const std::string& DirName );

    void SetHistoLow( TH1* Low ) { fhLow = Low; }
    void SetHistoHigh( TH1* High ) { fhHigh = High; }
    
    TH1* GetHistoLow();
    TH1* GetHistoHigh();
    
    void SetName( const std::string& Name ) { fName = Name; }
    std::string GetName() { return fName; }

    void SetInputFileLow( const std::string& InputFileLow ) { fInputFileLow = InputFileLow; }
    void SetInputFileHigh( const std::string& InputFileHigh ) { fInputFileHigh = InputFileHigh; }
    
    std::string GetInputFileLow() { return fInputFileLow; }
    std::string GetInputFileHigh() { return fInputFileHigh; }

    void SetHistoNameLow( const std::string& HistoNameLow ) { fHistoNameLow = HistoNameLow; }
    void SetHistoNameHigh( const std::string& HistoNameHigh ) { fHistoNameHigh = HistoNameHigh; }
    
    std::string GetHistoNameLow() { return fHistoNameLow; }
    std::string GetHistoNameHigh() { return fHistoNameHigh; }

    void SetHistoPathLow( const std::string& HistoPathLow ) { fHistoPathLow = HistoPathLow; }
    void SetHistoPathHigh( const std::string& HistoPathHigh ) { fHistoPathHigh = HistoPathHigh; }
    
    std::string GetHistoPathLow() { return fHistoPathLow; }
    std::string GetHistoPathHigh() { return fHistoPathHigh; }

  protected:

    std::string fName;

    std::string fInputFileLow;
    std::string fHistoNameLow;
    std::string fHistoPathLow;

    std::string fInputFileHigh;
    std::string fHistoNameHigh;
    std::string fHistoPathHigh;

    // The Low and High Histograms
    HistRef fhLow;
    HistRef fhHigh;

  };


  class HistoFactor {

  public:

    HistoFactor() : fhLow(NULL), fhHigh(NULL) {;}

    void SetName( const std::string& Name ) { fName = Name; }
    std::string GetName() { return fName; }
    
    void SetInputFileLow( const std::string& InputFileLow ) { fInputFileLow = InputFileLow; }
    void SetInputFileHigh( const std::string& InputFileHigh ) { fInputFileHigh = InputFileHigh; }
    
    std::string GetInputFileLow() { return fInputFileLow; }
    std::string GetInputFileHigh() { return fInputFileHigh; }

    void SetHistoNameLow( const std::string& HistoNameLow ) { fHistoNameLow = HistoNameLow; }
    void SetHistoNameHigh( const std::string& HistoNameHigh ) { fHistoNameHigh = HistoNameHigh; }
    
    std::string GetHistoNameLow() { return fHistoNameLow; }
    std::string GetHistoNameHigh() { return fHistoNameHigh; }

    void SetHistoPathLow( const std::string& HistoPathLow ) { fHistoPathLow = HistoPathLow; }
    void SetHistoPathHigh( const std::string& HistoPathHigh ) { fHistoPathHigh = HistoPathHigh; }
    
    std::string GetHistoPathLow() { return fHistoPathLow; }
    std::string GetHistoPathHigh() { return fHistoPathHigh; }

    void Print(std::ostream& = std::cout);  
    void writeToFile( const std::string& FileName, const std::string& DirName );
    void PrintXML(std::ostream&);

    TH1* GetHistoLow();
    TH1* GetHistoHigh();
    void SetHistoLow( TH1* Low ) { fhLow = Low; }
    void SetHistoHigh( TH1* High ) { fhHigh = High; }

  protected:

    std::string fName;

    std::string fInputFileLow;
    std::string fHistoNameLow;
    std::string fHistoPathLow;

    std::string fInputFileHigh;
    std::string fHistoNameHigh;
    std::string fHistoPathHigh;

    // The Low and High Histograms
    HistRef fhLow;
    HistRef fhHigh;

  };


  class ShapeSys {

  public:

    ShapeSys() :  fConstraintType(Constraint::Gaussian), fhError(NULL) {}

    void SetName( const std::string& Name ) { fName = Name; }
    std::string GetName() { return fName; }

    void SetInputFile( const std::string& InputFile ) { fInputFile = InputFile; }
    std::string GetInputFile() { return fInputFile; }

    void SetHistoName( const std::string& HistoName ) { fHistoName = HistoName; }
    std::string GetHistoName() { return fHistoName; }

    void SetHistoPath( const std::string& HistoPath ) { fHistoPath = HistoPath; }
    std::string GetHistoPath() { return fHistoPath; }

    void Print(std::ostream& = std::cout);  
    void PrintXML(std::ostream&);
    void writeToFile( const std::string& FileName, const std::string& DirName );

    TH1* GetErrorHist();
    void SetErrorHist(TH1* hError) { fhError = hError; }

    void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
    Constraint::Type GetConstraintType() { return fConstraintType; }

  protected:

    std::string fName;
    std::string fInputFile;
    std::string fHistoName;
    std::string fHistoPath;
    Constraint::Type fConstraintType; 

    // The histogram holding the error
    HistRef fhError;

  };


  class ShapeFactor {

  public:

    ShapeFactor();
    
    void SetName( const std::string& Name ) { fName = Name; }
    std::string GetName() { return fName; }

    void Print(std::ostream& = std::cout);  
    void PrintXML(std::ostream&);
    void writeToFile( const std::string& FileName, const std::string& DirName);

    void SetInitialShape(TH1* shape) { fhInitialShape = shape; }
    TH1* GetInitialShape() { return fhInitialShape; }

    void SetConstant(bool constant) { fConstant = constant; }
    bool IsConstant() { return fConstant; }
    
    bool HasInitialShape() { return fHasInitialShape; }

    void SetInputFile( const std::string& InputFile ) { 
      fInputFile = InputFile; 
      fHasInitialShape=true;
    }
    std::string GetInputFile() { return fInputFile; }

    void SetHistoName( const std::string& HistoName ) { 
      fHistoName = HistoName; 
      fHasInitialShape=true; 
    }
    std::string GetHistoName() { return fHistoName; }

    void SetHistoPath( const std::string& HistoPath ) { 
      fHistoPath = HistoPath; 
      fHasInitialShape=true;
    }
    std::string GetHistoPath() { return fHistoPath; }

  protected:
    std::string fName;

    bool fConstant;

    // A histogram representing
    // the initial shape
    bool fHasInitialShape;
    std::string fHistoName;
    std::string fHistoPath;
    std::string fInputFile;
    TH1* fhInitialShape;

  };


  class StatError {

  public:

    StatError() : fActivate(false), fUseHisto(false), fhError(NULL) {;}

    void Print(std::ostream& = std::cout);  
    void PrintXML(std::ostream&);
    void writeToFile( const std::string& FileName, const std::string& DirName );

    void Activate( bool IsActive=true ) { fActivate = IsActive; }
    bool GetActivate() { return fActivate; }

    void SetUseHisto( bool UseHisto=true ) { fUseHisto = UseHisto; }
    bool GetUseHisto() { return fUseHisto; }

    void SetInputFile( const std::string& InputFile ) { fInputFile = InputFile; }
    std::string GetInputFile() { return fInputFile; }

    void SetHistoName( const std::string& HistoName ) { fHistoName = HistoName; }
    std::string GetHistoName() { return fHistoName; }

    void SetHistoPath( const std::string& HistoPath ) { fHistoPath = HistoPath; }
    std::string GetHistoPath() { return fHistoPath; }


    TH1* GetErrorHist();
    void SetErrorHist(TH1* Error) { fhError = Error; }

  protected:

    bool fActivate;
    bool fUseHisto; // Use an external histogram for the errors 
    std::string fInputFile;
    std::string fHistoName;
    std::string fHistoPath;

    // The histogram holding the error
    HistRef fhError;

  };

  class StatErrorConfig {

  public:

    StatErrorConfig() : fRelErrorThreshold( .05 ), fConstraintType( Constraint::Gaussian ) {;}
    void Print(std::ostream& = std::cout);  
    void PrintXML(std::ostream&);

    void SetRelErrorThreshold( double Threshold ) { fRelErrorThreshold = Threshold; }
    double GetRelErrorThreshold() { return fRelErrorThreshold; }

    void SetConstraintType( Constraint::Type ConstrType ) { fConstraintType = ConstrType; }
    Constraint::Type GetConstraintType() { return fConstraintType; }

  protected:

    double fRelErrorThreshold;
    Constraint::Type fConstraintType; 

  };


}
}

#endif
 Systematics.h:1
 Systematics.h:2
 Systematics.h:3
 Systematics.h:4
 Systematics.h:5
 Systematics.h:6
 Systematics.h:7
 Systematics.h:8
 Systematics.h:9
 Systematics.h:10
 Systematics.h:11
 Systematics.h:12
 Systematics.h:13
 Systematics.h:14
 Systematics.h:15
 Systematics.h:16
 Systematics.h:17
 Systematics.h:18
 Systematics.h:19
 Systematics.h:20
 Systematics.h:21
 Systematics.h:22
 Systematics.h:23
 Systematics.h:24
 Systematics.h:25
 Systematics.h:26
 Systematics.h:27
 Systematics.h:28
 Systematics.h:29
 Systematics.h:30
 Systematics.h:31
 Systematics.h:32
 Systematics.h:33
 Systematics.h:34
 Systematics.h:35
 Systematics.h:36
 Systematics.h:37
 Systematics.h:38
 Systematics.h:39
 Systematics.h:40
 Systematics.h:41
 Systematics.h:42
 Systematics.h:43
 Systematics.h:44
 Systematics.h:45
 Systematics.h:46
 Systematics.h:47
 Systematics.h:48
 Systematics.h:49
 Systematics.h:50
 Systematics.h:51
 Systematics.h:52
 Systematics.h:53
 Systematics.h:54
 Systematics.h:55
 Systematics.h:56
 Systematics.h:57
 Systematics.h:58
 Systematics.h:59
 Systematics.h:60
 Systematics.h:61
 Systematics.h:62
 Systematics.h:63
 Systematics.h:64
 Systematics.h:65
 Systematics.h:66
 Systematics.h:67
 Systematics.h:68
 Systematics.h:69
 Systematics.h:70
 Systematics.h:71
 Systematics.h:72
 Systematics.h:73
 Systematics.h:74
 Systematics.h:75
 Systematics.h:76
 Systematics.h:77
 Systematics.h:78
 Systematics.h:79
 Systematics.h:80
 Systematics.h:81
 Systematics.h:82
 Systematics.h:83
 Systematics.h:84
 Systematics.h:85
 Systematics.h:86
 Systematics.h:87
 Systematics.h:88
 Systematics.h:89
 Systematics.h:90
 Systematics.h:91
 Systematics.h:92
 Systematics.h:93
 Systematics.h:94
 Systematics.h:95
 Systematics.h:96
 Systematics.h:97
 Systematics.h:98
 Systematics.h:99
 Systematics.h:100
 Systematics.h:101
 Systematics.h:102
 Systematics.h:103
 Systematics.h:104
 Systematics.h:105
 Systematics.h:106
 Systematics.h:107
 Systematics.h:108
 Systematics.h:109
 Systematics.h:110
 Systematics.h:111
 Systematics.h:112
 Systematics.h:113
 Systematics.h:114
 Systematics.h:115
 Systematics.h:116
 Systematics.h:117
 Systematics.h:118
 Systematics.h:119
 Systematics.h:120
 Systematics.h:121
 Systematics.h:122
 Systematics.h:123
 Systematics.h:124
 Systematics.h:125
 Systematics.h:126
 Systematics.h:127
 Systematics.h:128
 Systematics.h:129
 Systematics.h:130
 Systematics.h:131
 Systematics.h:132
 Systematics.h:133
 Systematics.h:134
 Systematics.h:135
 Systematics.h:136
 Systematics.h:137
 Systematics.h:138
 Systematics.h:139
 Systematics.h:140
 Systematics.h:141
 Systematics.h:142
 Systematics.h:143
 Systematics.h:144
 Systematics.h:145
 Systematics.h:146
 Systematics.h:147
 Systematics.h:148
 Systematics.h:149
 Systematics.h:150
 Systematics.h:151
 Systematics.h:152
 Systematics.h:153
 Systematics.h:154
 Systematics.h:155
 Systematics.h:156
 Systematics.h:157
 Systematics.h:158
 Systematics.h:159
 Systematics.h:160
 Systematics.h:161
 Systematics.h:162
 Systematics.h:163
 Systematics.h:164
 Systematics.h:165
 Systematics.h:166
 Systematics.h:167
 Systematics.h:168
 Systematics.h:169
 Systematics.h:170
 Systematics.h:171
 Systematics.h:172
 Systematics.h:173
 Systematics.h:174
 Systematics.h:175
 Systematics.h:176
 Systematics.h:177
 Systematics.h:178
 Systematics.h:179
 Systematics.h:180
 Systematics.h:181
 Systematics.h:182
 Systematics.h:183
 Systematics.h:184
 Systematics.h:185
 Systematics.h:186
 Systematics.h:187
 Systematics.h:188
 Systematics.h:189
 Systematics.h:190
 Systematics.h:191
 Systematics.h:192
 Systematics.h:193
 Systematics.h:194
 Systematics.h:195
 Systematics.h:196
 Systematics.h:197
 Systematics.h:198
 Systematics.h:199
 Systematics.h:200
 Systematics.h:201
 Systematics.h:202
 Systematics.h:203
 Systematics.h:204
 Systematics.h:205
 Systematics.h:206
 Systematics.h:207
 Systematics.h:208
 Systematics.h:209
 Systematics.h:210
 Systematics.h:211
 Systematics.h:212
 Systematics.h:213
 Systematics.h:214
 Systematics.h:215
 Systematics.h:216
 Systematics.h:217
 Systematics.h:218
 Systematics.h:219
 Systematics.h:220
 Systematics.h:221
 Systematics.h:222
 Systematics.h:223
 Systematics.h:224
 Systematics.h:225
 Systematics.h:226
 Systematics.h:227
 Systematics.h:228
 Systematics.h:229
 Systematics.h:230
 Systematics.h:231
 Systematics.h:232
 Systematics.h:233
 Systematics.h:234
 Systematics.h:235
 Systematics.h:236
 Systematics.h:237
 Systematics.h:238
 Systematics.h:239
 Systematics.h:240
 Systematics.h:241
 Systematics.h:242
 Systematics.h:243
 Systematics.h:244
 Systematics.h:245
 Systematics.h:246
 Systematics.h:247
 Systematics.h:248
 Systematics.h:249
 Systematics.h:250
 Systematics.h:251
 Systematics.h:252
 Systematics.h:253
 Systematics.h:254
 Systematics.h:255
 Systematics.h:256
 Systematics.h:257
 Systematics.h:258
 Systematics.h:259
 Systematics.h:260
 Systematics.h:261
 Systematics.h:262
 Systematics.h:263
 Systematics.h:264
 Systematics.h:265
 Systematics.h:266
 Systematics.h:267
 Systematics.h:268
 Systematics.h:269
 Systematics.h:270
 Systematics.h:271
 Systematics.h:272
 Systematics.h:273
 Systematics.h:274
 Systematics.h:275
 Systematics.h:276
 Systematics.h:277
 Systematics.h:278
 Systematics.h:279
 Systematics.h:280
 Systematics.h:281
 Systematics.h:282
 Systematics.h:283
 Systematics.h:284
 Systematics.h:285
 Systematics.h:286
 Systematics.h:287
 Systematics.h:288
 Systematics.h:289
 Systematics.h:290
 Systematics.h:291
 Systematics.h:292
 Systematics.h:293
 Systematics.h:294
 Systematics.h:295
 Systematics.h:296
 Systematics.h:297
 Systematics.h:298
 Systematics.h:299
 Systematics.h:300
 Systematics.h:301
 Systematics.h:302
 Systematics.h:303
 Systematics.h:304
 Systematics.h:305
 Systematics.h:306
 Systematics.h:307
 Systematics.h:308
 Systematics.h:309
 Systematics.h:310
 Systematics.h:311
 Systematics.h:312
 Systematics.h:313
 Systematics.h:314
 Systematics.h:315
 Systematics.h:316
 Systematics.h:317
 Systematics.h:318
 Systematics.h:319
 Systematics.h:320
 Systematics.h:321
 Systematics.h:322
 Systematics.h:323
 Systematics.h:324
 Systematics.h:325
 Systematics.h:326
 Systematics.h:327
 Systematics.h:328
 Systematics.h:329
 Systematics.h:330
 Systematics.h:331
 Systematics.h:332
 Systematics.h:333
 Systematics.h:334
 Systematics.h:335
 Systematics.h:336
 Systematics.h:337
 Systematics.h:338
 Systematics.h:339
 Systematics.h:340
 Systematics.h:341
 Systematics.h:342
 Systematics.h:343
 Systematics.h:344
 Systematics.h:345
 Systematics.h:346
 Systematics.h:347
 Systematics.h:348
 Systematics.h:349
 Systematics.h:350
 Systematics.h:351
 Systematics.h:352
 Systematics.h:353
 Systematics.h:354
 Systematics.h:355
 Systematics.h:356
 Systematics.h:357
 Systematics.h:358
 Systematics.h:359
 Systematics.h:360
 Systematics.h:361
 Systematics.h:362
 Systematics.h:363
 Systematics.h:364
 Systematics.h:365
 Systematics.h:366
 Systematics.h:367
 Systematics.h:368
 Systematics.h:369
 Systematics.h:370
 Systematics.h:371
 Systematics.h:372
 Systematics.h:373
 Systematics.h:374
 Systematics.h:375
 Systematics.h:376
 Systematics.h:377
 Systematics.h:378
 Systematics.h:379
 Systematics.h:380