//  
// Author: Oliver Maria Kind <mailto: kind@mail.desy.de>
// Update: $Id: HepDataMCPlotter.h,v 1.14 2016/02/16 13:52:04 kind Exp $
// Copyright: 2009 (C) Oliver Maria Kind
//
#ifndef HEP_HepDataMCPlotter
#define HEP_HepDataMCPlotter
#ifndef HEP_HepDataMCPlot
#include <HepDataMCPlot.h>
#endif
#ifndef HEP_HepDataMCFolder
#include <HepDataMCFolder.h>
#endif
#ifndef HEP_HepNtuplePlotCmd
#include <HepNtuplePlotCmd.h>
#endif
#ifndef ROOT_TTask
#include <TTask.h>
#endif
#ifndef ROOT_TList
#include <TList.h>
#endif
#ifndef ROOT_TDirectory
#include <TDirectory.h>
#endif
#ifndef ROOT_TH1F
#include <TH1F.h>
#endif
#ifndef TROOT
#include <TROOT.h>
#endif
#ifndef TStyle
#include <TStyle.h>
#endif

class TFile;
class TKey;
class TSystem;
class HepDataMCSample;
class TObjString;
class TCanvas;
class TROOT;
class TObjArray;

class HepDataMCPlotter : public TTask {

  private:
    TFile   *fOutputRootFile;      // Output file containing all plots 

    TList   *fListOfDataFileNames; // List of data file names
    TList   *fListOfDataFiles;     // List of data files pointers
    TList   *fListOfPlots;         // List of DataMC plots
    TList   *fListOfInFiles;       // List of all input files
    TList   *fNtuplePlotCmds;      // List of ntuple draw commands used by the plotter tasks
    TList   *fMCSamples;           // List of MC samples (input filenames and drawing attributes)
    TList   *fMCSingleSamples;     // List of MC single samples, not belonging to folder (input filenames and drawing attributes)
    TList   *fMCFolders;           // List of folders to group MC samples

    Float_t  fLumiDATA;                // Integrated DATA luminosity (used for over-all normalisation)
    TString *fExportDir;               // Working directory
    TString  fAtlasLabelStatus;        // label in plot after "ATLAS"
    TString  fCenterOfMassEnergyLabel; // Center of mass energy label
    TString  fLuminosityLabel;         // Luminosity label
    Bool_t   fExportROOT;              // Export all plots to a ROOT file 
    Bool_t   fExportEPS;               // Export all plots to EPS files 
    Bool_t   fExportPS;                // Export all plots to PS files 
    Bool_t   fExportPDF;               // Export all plots to PDF  files 
    Bool_t   fExportPNG;               // Export all plots to PNG files 
    Bool_t   fExportC;                 // Export all plots to C files 
    Bool_t   fDrawLegend;              // Draw a legend inside all plots
    Bool_t   fGroupHistograms;         // Group histograms when drawing and in the legend
    Bool_t   fUnifyMCStack;            // Draw MC stack histograms as a single histogram
    Bool_t   fDrawMCError;             // Draw the total MC uncertainty on top
    Bool_t   fDrawDataZeroEntryErrors; // Draw the DATA error bars even for 0 data entry bins
    Bool_t   fLogyaxis;                // Plot y axis in logarithmic scale
    Bool_t   fDrawCMSLumiAtlasLabel;   // Draw labels
    Bool_t   fUseAtlasStyle;	       // Use ATLAS style
    Bool_t   fUseOverflowUnderflow;    // Flag for plotter (default = false)
    Bool_t   fDrawSignalOverlay;       // Flag for drawing the signal MC (assumed to be the least entry in the MC histogram stack) as overlay instead as part of the stack (default = false)
    Float_t  fScaleOverlay;            // Scale factor of the overlay histogram ( default = 1. )
    
  public:
    HepDataMCPlotter(const char* name, const char* title);
    virtual ~HepDataMCPlotter();
    void InitInput();
    virtual void  Exec(Option_t *option = "");
    HepDataMCPlot* BuildNtuplePlot(HepNtuplePlotCmd *cmd) const;

    void AddDataFile(const char* path, const char* label); // *MENU*
    HepDataMCSample* AddMCSample(const char* path, const char* label, Color_t color,
				 Style_t line_style, Width_t line_width,
				 Style_t fill_style);
    HepDataMCSample* AddMCSample(const char* path, const char* label, Color_t color); // *MENU*
    HepDataMCSample* AddMCSample(const char* path, const char* label, Float_t xsec,
				 Color_t color); // *MENU*
    HepDataMCSample* AddMCSample(const char* folder_name, const char* path, const char* label,
				 Float_t xsec, Color_t color); // *MENU*
    HepDataMCSample* AddMCSample(HepDataMCFolder *folder, const char* path, const char* label,
				 Float_t xsec, Color_t color);
    void AddMCFolder(const char* name, const char* title, Color_t color);
    void AddNtuplePlotCmd(const char* TreeName, const char* VarExp,
			  const char* Selection, const char* PlotName,
			  const char* PlotTitle, Int_t Nbins,
			  Double_t Xlow, Double_t Xup,
			  const char* XTitle, const char* YTitle);
    void Export(HepDataMCPlot *Plot, TNamed *PlotName);
    
    inline TList* GetListOfPlots() { return fListOfPlots; }
    inline void SetLumiDATA(Float_t lumi)
    { fLumiDATA = lumi; }
    inline void SetWorkingDir(const char* dir)
    { SetExportDir(dir); }
    inline void SetExportDir(const char* dir) {
	fExportDir->Remove(0);
	fExportDir->Append(dir);
    }
    Bool_t GetExportROOT() { return fExportROOT; }
    Bool_t GetExportEPS()  { return fExportEPS; }
    Bool_t GetExportPS()   { return fExportPS; }
    Bool_t GetExportPDF()  { return fExportPDF; }
    Bool_t GetExportPNG()  { return fExportPNG; }
    Bool_t GetExportC()    { return fExportC; }
    Bool_t GetDrawLegend() { return fDrawLegend; }
    Bool_t GetGroupHistograms() { return fGroupHistograms; }
    Bool_t GetUnifyMCStack() { return fUnifyMCStack; }
    Bool_t GetDrawMCError() { return fDrawMCError; }
    Bool_t GetDrawDataZeroEntryErrors() { return fDrawDataZeroEntryErrors; }
    Bool_t GetLogyaxis() { return fLogyaxis; }
    void SetExportROOT(Bool_t ExportROOT) {
	// Switch export to .root format on or off
	fExportROOT = ExportROOT;
    } // *TOGGLE*
    void SetExportEPS(Bool_t ExportEPS) {
	// Switch export to EPS format on or off
	fExportEPS = ExportEPS;
    }   // *TOGGLE*
    void SetExportPS(Bool_t ExportPS) {
	// Switch export to PS format on or off
	fExportPS = ExportPS;
    }     // *TOGGLE*
    void SetExportPDF(Bool_t ExportPDF) {
	// Switch export to PDF format on or off
	fExportPDF = ExportPDF;
    }   // *TOGGLE*
    void SetExportPNG(Bool_t ExportPNG) {
	// Switch export to PNG format on or off
	fExportPNG = ExportPNG;
    }   // *TOGGLE*
    void SetExportC(Bool_t ExportC) {
	// Switch export to .C on or off
	fExportC = ExportC;
    }       // *TOGGLE*
    void SetDrawLegend(Bool_t DrawLegend) {
	// Switch drawing of the legend on or off
	fDrawLegend = DrawLegend;
    } // *TOGGLE*
    void SetGroupHistograms(Bool_t GroupHistograms); // *TOGGLE*
    void SetUnifyMCStack(Bool_t UnifyMCStack); // *TOGGLE*
    void SetDrawMCError(Bool_t DrawMCError); // *TOGGLE*
    void SetDrawDataZeroEntryErrors(Bool_t DrawDataZeroEntryErrors = kTRUE); // *TOGGLE*
    void SetLogyaxis(Bool_t Logyaxis); // *TOGGLE*
    void SetUseOverflowUnderflow(Bool_t status);
    void SetDrawSignalOverlay(Bool_t status);
    void SetScaleOverlay(Float_t scale);
    void SetUseAtlasStyle(Bool_t UseAtlasStyle = kTRUE) { 
	//
	// Draw plot in ATLAS style
	//
	fUseAtlasStyle = UseAtlasStyle;
    }
    Bool_t GetUseAtlasStyle(){ return fUseAtlasStyle;}
    inline void SetDrawCMSLumiAtlasLabel(Bool_t DrawCMSLumiAtlasLabel = kTRUE){
	fDrawCMSLumiAtlasLabel = DrawCMSLumiAtlasLabel;
    }
    inline Bool_t GetDrawCMSLumiAtlasLabel(){return fDrawCMSLumiAtlasLabel;}
    inline void SetAtlasLabelStatus(TString AtlasLabelStatus){
	fAtlasLabelStatus = AtlasLabelStatus;
    }
    inline TString  GetAtlasLabelStatus(){ return fAtlasLabelStatus;}
    inline void SetCenterOfMassEnergyLabel(TString CenterOfMassEnergy){
	fCenterOfMassEnergyLabel = CenterOfMassEnergy;
    }
    inline TString  GetCenterOfMassEnergyLabel(){ return fCenterOfMassEnergyLabel;}
    inline void SetLuminosityLabel(TString Luminosity){
	fLuminosityLabel = Luminosity;
    }
    inline TString  GetLuminosityLabel(){ return fLuminosityLabel;}
        
  private:
    void ReadHistogramsFromDir(TDirectory *dir);
    void BuildListOfPlots();
    HepDataMCPlot* BuildPlot(TNamed *PlotName);
    TDirectory* MkDirWithParents(TFile *f, const char* dir);
    void Normalize(TH1F &h, HepDataMCSample *sample, Float_t LumiScale = 1.) const;
    TH1F* GetHistFromFile(TFile *f, TNamed *PlotName);
    HepDataMCPlot* CreatePlotFromHist(TH1F* h) const;
    void AddHistMC(HepDataMCPlot *plot, TH1F *h,
		   HepDataMCSample *mc_sample,
		   HepDataMCFolder *folder = 0,
		   Float_t LumiScale = 1.) const;

    ClassDef(HepDataMCPlotter,3) // DATA/MC plotter
};
#endif

 HepDataMCPlotter.h:1
 HepDataMCPlotter.h:2
 HepDataMCPlotter.h:3
 HepDataMCPlotter.h:4
 HepDataMCPlotter.h:5
 HepDataMCPlotter.h:6
 HepDataMCPlotter.h:7
 HepDataMCPlotter.h:8
 HepDataMCPlotter.h:9
 HepDataMCPlotter.h:10
 HepDataMCPlotter.h:11
 HepDataMCPlotter.h:12
 HepDataMCPlotter.h:13
 HepDataMCPlotter.h:14
 HepDataMCPlotter.h:15
 HepDataMCPlotter.h:16
 HepDataMCPlotter.h:17
 HepDataMCPlotter.h:18
 HepDataMCPlotter.h:19
 HepDataMCPlotter.h:20
 HepDataMCPlotter.h:21
 HepDataMCPlotter.h:22
 HepDataMCPlotter.h:23
 HepDataMCPlotter.h:24
 HepDataMCPlotter.h:25
 HepDataMCPlotter.h:26
 HepDataMCPlotter.h:27
 HepDataMCPlotter.h:28
 HepDataMCPlotter.h:29
 HepDataMCPlotter.h:30
 HepDataMCPlotter.h:31
 HepDataMCPlotter.h:32
 HepDataMCPlotter.h:33
 HepDataMCPlotter.h:34
 HepDataMCPlotter.h:35
 HepDataMCPlotter.h:36
 HepDataMCPlotter.h:37
 HepDataMCPlotter.h:38
 HepDataMCPlotter.h:39
 HepDataMCPlotter.h:40
 HepDataMCPlotter.h:41
 HepDataMCPlotter.h:42
 HepDataMCPlotter.h:43
 HepDataMCPlotter.h:44
 HepDataMCPlotter.h:45
 HepDataMCPlotter.h:46
 HepDataMCPlotter.h:47
 HepDataMCPlotter.h:48
 HepDataMCPlotter.h:49
 HepDataMCPlotter.h:50
 HepDataMCPlotter.h:51
 HepDataMCPlotter.h:52
 HepDataMCPlotter.h:53
 HepDataMCPlotter.h:54
 HepDataMCPlotter.h:55
 HepDataMCPlotter.h:56
 HepDataMCPlotter.h:57
 HepDataMCPlotter.h:58
 HepDataMCPlotter.h:59
 HepDataMCPlotter.h:60
 HepDataMCPlotter.h:61
 HepDataMCPlotter.h:62
 HepDataMCPlotter.h:63
 HepDataMCPlotter.h:64
 HepDataMCPlotter.h:65
 HepDataMCPlotter.h:66
 HepDataMCPlotter.h:67
 HepDataMCPlotter.h:68
 HepDataMCPlotter.h:69
 HepDataMCPlotter.h:70
 HepDataMCPlotter.h:71
 HepDataMCPlotter.h:72
 HepDataMCPlotter.h:73
 HepDataMCPlotter.h:74
 HepDataMCPlotter.h:75
 HepDataMCPlotter.h:76
 HepDataMCPlotter.h:77
 HepDataMCPlotter.h:78
 HepDataMCPlotter.h:79
 HepDataMCPlotter.h:80
 HepDataMCPlotter.h:81
 HepDataMCPlotter.h:82
 HepDataMCPlotter.h:83
 HepDataMCPlotter.h:84
 HepDataMCPlotter.h:85
 HepDataMCPlotter.h:86
 HepDataMCPlotter.h:87
 HepDataMCPlotter.h:88
 HepDataMCPlotter.h:89
 HepDataMCPlotter.h:90
 HepDataMCPlotter.h:91
 HepDataMCPlotter.h:92
 HepDataMCPlotter.h:93
 HepDataMCPlotter.h:94
 HepDataMCPlotter.h:95
 HepDataMCPlotter.h:96
 HepDataMCPlotter.h:97
 HepDataMCPlotter.h:98
 HepDataMCPlotter.h:99
 HepDataMCPlotter.h:100
 HepDataMCPlotter.h:101
 HepDataMCPlotter.h:102
 HepDataMCPlotter.h:103
 HepDataMCPlotter.h:104
 HepDataMCPlotter.h:105
 HepDataMCPlotter.h:106
 HepDataMCPlotter.h:107
 HepDataMCPlotter.h:108
 HepDataMCPlotter.h:109
 HepDataMCPlotter.h:110
 HepDataMCPlotter.h:111
 HepDataMCPlotter.h:112
 HepDataMCPlotter.h:113
 HepDataMCPlotter.h:114
 HepDataMCPlotter.h:115
 HepDataMCPlotter.h:116
 HepDataMCPlotter.h:117
 HepDataMCPlotter.h:118
 HepDataMCPlotter.h:119
 HepDataMCPlotter.h:120
 HepDataMCPlotter.h:121
 HepDataMCPlotter.h:122
 HepDataMCPlotter.h:123
 HepDataMCPlotter.h:124
 HepDataMCPlotter.h:125
 HepDataMCPlotter.h:126
 HepDataMCPlotter.h:127
 HepDataMCPlotter.h:128
 HepDataMCPlotter.h:129
 HepDataMCPlotter.h:130
 HepDataMCPlotter.h:131
 HepDataMCPlotter.h:132
 HepDataMCPlotter.h:133
 HepDataMCPlotter.h:134
 HepDataMCPlotter.h:135
 HepDataMCPlotter.h:136
 HepDataMCPlotter.h:137
 HepDataMCPlotter.h:138
 HepDataMCPlotter.h:139
 HepDataMCPlotter.h:140
 HepDataMCPlotter.h:141
 HepDataMCPlotter.h:142
 HepDataMCPlotter.h:143
 HepDataMCPlotter.h:144
 HepDataMCPlotter.h:145
 HepDataMCPlotter.h:146
 HepDataMCPlotter.h:147
 HepDataMCPlotter.h:148
 HepDataMCPlotter.h:149
 HepDataMCPlotter.h:150
 HepDataMCPlotter.h:151
 HepDataMCPlotter.h:152
 HepDataMCPlotter.h:153
 HepDataMCPlotter.h:154
 HepDataMCPlotter.h:155
 HepDataMCPlotter.h:156
 HepDataMCPlotter.h:157
 HepDataMCPlotter.h:158
 HepDataMCPlotter.h:159
 HepDataMCPlotter.h:160
 HepDataMCPlotter.h:161
 HepDataMCPlotter.h:162
 HepDataMCPlotter.h:163
 HepDataMCPlotter.h:164
 HepDataMCPlotter.h:165
 HepDataMCPlotter.h:166
 HepDataMCPlotter.h:167
 HepDataMCPlotter.h:168
 HepDataMCPlotter.h:169
 HepDataMCPlotter.h:170
 HepDataMCPlotter.h:171
 HepDataMCPlotter.h:172
 HepDataMCPlotter.h:173
 HepDataMCPlotter.h:174
 HepDataMCPlotter.h:175
 HepDataMCPlotter.h:176
 HepDataMCPlotter.h:177
 HepDataMCPlotter.h:178
 HepDataMCPlotter.h:179
 HepDataMCPlotter.h:180
 HepDataMCPlotter.h:181
 HepDataMCPlotter.h:182
 HepDataMCPlotter.h:183
 HepDataMCPlotter.h:184
 HepDataMCPlotter.h:185
 HepDataMCPlotter.h:186
 HepDataMCPlotter.h:187
 HepDataMCPlotter.h:188
 HepDataMCPlotter.h:189
 HepDataMCPlotter.h:190
 HepDataMCPlotter.h:191
 HepDataMCPlotter.h:192
 HepDataMCPlotter.h:193
 HepDataMCPlotter.h:194
 HepDataMCPlotter.h:195
 HepDataMCPlotter.h:196
 HepDataMCPlotter.h:197
 HepDataMCPlotter.h:198
 HepDataMCPlotter.h:199
 HepDataMCPlotter.h:200
 HepDataMCPlotter.h:201
 HepDataMCPlotter.h:202
 HepDataMCPlotter.h:203
 HepDataMCPlotter.h:204
 HepDataMCPlotter.h:205