#ifndef HEP_HepDataMCPlot
#define HEP_HepDataMCPlot
#ifndef HEP_HepDataMCFolder
#include <HepDataMCFolder.h>
#endif
#ifndef ROOT_TNamed
#include <TNamed.h>
#endif
#ifndef ROOT_HStack
#include <THStack.h>
#endif
#ifndef ROOT_TH1F
#include <TH1F.h>
#endif
#ifndef ROOT_TString
#include <TString.h>
#endif
#ifndef ROOT_TLegend
#include <TLegend.h>
#endif
#ifndef ROOT_TCanvas
#include <TCanvas.h>
#endif
#ifndef ROOT_TGraphAsymmErrors
#include <TGraphAsymmErrors.h>
#endif
class TList;
class TObjString;
class HepDataMCSample;
class TStyle;
class TBrowser;
class TPad;
class TFeldmanCousins;
class TFractionFitter;
class HepTemplate;
class TLine;
#if (__cplusplus > 201100L)
#define const_or_constexpr constexpr
#else
#define const_or_constexpr const
#endif
class HepDataMCPlot : public TNamed {
private:
static const Color_t fgUnifyColor = kYellow;
static const_or_constexpr Double_t fgFeldmanCousinsCL = 0.680;
static const Int_t fgFeldmanCousinsMaxEntries = 0;
THStack *fMCHistStack;
TH1F *fHistDATA;
TH1F *fHistMCTop;
TLegend *fLegend;
TLegend *fLegendLarge;
Bool_t fFirstDraw;
Bool_t fFirstLegend;
TString *fXTitle;
TString *fYTitle;
Int_t fN_MCHistograms;
Bool_t fGroupHistograms;
TList *fMCFolders;
TList *fMCSingleSamples;
Bool_t fUnifyMCStack;
Bool_t fDrawMCError;
Bool_t fDrawNormError;
Bool_t fUseOverflowUnderflow;
Bool_t fDrawData;
Bool_t fDrawDataErrorX;
Bool_t fDrawDataZeroEntryErrors;
Bool_t fDrawDataZeroEntries;
TGraphAsymmErrors *fMCErrors;
TGraphAsymmErrors *fGraphDATA;
Float_t fLumiDATA;
TList *fMCFitTemplates;
TFractionFitter *fFitter;
THStack *fMCFittedHistStack;
Bool_t fDrawCMSLumiAtlasLabel;
Bool_t fUseAtlasStyle;
Bool_t fUseShortCMSLumiLabel;
TString fCenterOfMassEnergyLabel;
TString fAtlasLabelStatus;
TString fLuminosityLabel;
Float_t fAtlasLabelPosX;
Float_t fAtlasLabelPosY;
Float_t fCMSEnergyLabelPosX;
Float_t fCMSEnergyLabelPosY;
Float_t fLuminosityLabelPosX;
Float_t fLuminosityLabelPosY;
Float_t fAddRange;
Bool_t fDrawDataMCRatio;
Bool_t fDataMCRatioCenterOne;
Bool_t fDrawSignificance;
Float_t fRatioHeight;
Bool_t fYRangeUser;
Double_t fYRangeUserMin;
Double_t fYRangeUserMax;
TCanvas *fCanvas;
TPad *fMainPad;
TPad *fRatioPad1;
TPad *fRatioPad2;
TH1 *fHistogramMainPad;
TH1 *fHistogramRatioPad1;
TH1 *fHistogramRatioPad2;
TLine *fRatioLine;
TH1 *fHistogramLastInStack;
Float_t fScaleOverlay;
Bool_t fDrawSignalOverlay;
public:
HepDataMCPlot();
HepDataMCPlot(const char* name, const char* title);
virtual ~HepDataMCPlot();
virtual void Draw(Option_t *option = "");
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
virtual void Browse(TBrowser *b);
virtual void Print(Option_t *option = "") const;
virtual Bool_t IsFolder() const { return kFALSE; }
void DrawLegend();
void DrawLegendPad();
void SetHistDATA(TH1F *h, const char* label, Float_t lumiData);
void AddHistMC(TH1F *h, HepDataMCSample *sample);
void AddHistMC(TH1F *h, HepDataMCFolder *folder,
HepDataMCSample *sample);
void SetXTitle(const char* title);
void SetYTitle(const char* title);
void SetXRange(Double_t xmin, Double_t xmax);
void SetYRange(Double_t ymin, Double_t ymax);
void SetYRangeRatio(Double_t ymin, Double_t ymax, Int_t ratio);
void SetNdivisionsX(Int_t n = 510, Bool_t optim = kTRUE);
void SetNdivisionsY(Int_t n = 510, Bool_t optim = kTRUE);
static TString GetPathInsideFile(TDirectory *dir);
Bool_t GetGroupHistograms() const { return fGroupHistograms; }
void SetGroupHistograms(Bool_t GroupHistograms);
Bool_t GetUnifyMCStack() const { return fUnifyMCStack; }
void SetUnifyMCStack(Bool_t UnifyMCStack);
void SetUnifyMCStack(Bool_t UnifyMCStack, Bool_t DoRedraw);
Bool_t GetDrawMCError() { return fDrawMCError; }
Bool_t GetDrawNormError() { return fDrawNormError; }
void SetDrawMCError(Bool_t DrawMCError);
void SetDrawNormError(Bool_t DrawMCError);
void SetDrawMCError(Bool_t DrawMCError, Bool_t DoRedraw);
void SetDrawData(Bool_t DrawData);
Bool_t GetDrawData() { return fDrawData; }
void SetUseOverflowUnderflow(Bool_t UseOverflowUnderflow = kTRUE);
Bool_t GetUseOverflowUnderflow() {return fUseOverflowUnderflow;}
Bool_t GetDrawDataZeroEntryErrors() { return fDrawDataZeroEntryErrors; }
void SetDrawDataZeroEntryErrors(Bool_t DrawDataZeroEntryErrors = kTRUE);
void SetDrawDataZeroEntries(Bool_t flag = kTRUE);
void ComputeStatisticalUncertainty(TH1F* h, Int_t bin,
Double_t &up, Double_t &lo);
void ComputeNormUncertainty(Int_t bin,
Double_t &up, Double_t &lo);
void PrepareFit(Bool_t single_samples = kFALSE, Bool_t prepare_effs = kFALSE);
Int_t Fit();
virtual void DrawFit(Option_t *option = "");
void ListFolders();
void ListSingleSamples();
void ListTemplateFractions();
Double_t GetTemplateFitFraction(const char* template_name);
Double_t GetTemplateFitFractionError(const char* template_name);
Float_t GetTemplateCutEfficiency(const char* template_name);
void SetTemplateBounds(const char* template_name, Double_t Lower, Double_t Upper);
void SetTemplateStartValue(const char* template_name, Double_t frac, Double_t frac_err);
void FixTemplateFraction(const char* template_name, Bool_t fix = kTRUE);
void Rebin(Int_t ngroup);
void ScaleMCStack(Float_t scale);
void ScaleMCFolder(Float_t scale, const char *mc_folder);
void SetDrawDataMCRatio(Bool_t DrawDataMCRatio = kTRUE);
void SetDrawSignificance(Bool_t DrawSignificance = kTRUE);
void SetDataMCRatioCenterOne(Bool_t DataMCRatioCenter = kTRUE);
Bool_t GetDrawDataMCRatio() {return fDrawDataMCRatio;}
Bool_t GetDrawSignificance() {return fDrawSignificance;}
void ExportTemplates(TFile *f, const char* suffix);
TList* GetListOfMCTemplates(const char* suffix);
void PrintBinStatistics(Option_t *option = "");
void OptimizeBinning(Double_t zs = 15, Double_t zb = 15,
Bool_t DrawStack = kFALSE);
void SetDrawSignalOverlay(Bool_t DrawSignalOverlay);
void SetScaleOverlay(Float_t ScaleOverlay);
inline void AddMCFolder(HepDataMCFolder *folder) {
if ( fMCFolders == 0 ) fMCFolders = new TList;
fMCFolders->Add(folder);
}
inline void AddMCSingleSample(HepDataMCSample *sample) {
if ( fMCSingleSamples == 0 ) fMCSingleSamples = new TList;
fMCSingleSamples->Add(sample);
}
inline void SetMCErrors(TGraphAsymmErrors *ErrorGraph) {
fMCErrors = ErrorGraph;
}
inline void SetLumiDATA(Float_t lumiData) {
fLumiDATA = lumiData;
}
inline TList* GetMCFolders() const { return fMCFolders; }
inline TList* GetMCSingleSamples() { return fMCSingleSamples; }
inline TH1F* GetHistDATA() const { return fHistDATA; }
inline Float_t GetLumiDATA() { return fLumiDATA; }
inline THStack* GetMCHistStack() const { return fMCHistStack; }
inline TLegend* GetLegend() { return fLegend; }
inline TLegend* GetLegendLarge() { return fLegendLarge; }
inline const char* GetXTitle() { return fXTitle->Data(); }
inline const char* GetYTitle() { return fYTitle->Data(); }
inline TGraphAsymmErrors* GetMCErrors() { return fMCErrors; }
inline HepTemplate* GetTemplate(const char* title) {
return (HepTemplate*)fMCFitTemplates->FindObject(title);
}
inline THStack* GetMCFittedHistStack() { return fMCFittedHistStack; }
inline Int_t GetNFitTemplates() {
if(fMCFitTemplates!=0) return fMCFitTemplates->GetEntries();
else return 0;
}
void SetUseAtlasStyle(Bool_t UseAtlasStyle = kTRUE){
fUseAtlasStyle = UseAtlasStyle;
}
Bool_t GetUseAtlasStyle(){ return fUseAtlasStyle;}
void SetAtlasStyle();
inline void SetDrawCMSLumiAtlasLabel(Bool_t DrawCMSLumiAtlasLabel = kTRUE){
fDrawCMSLumiAtlasLabel = DrawCMSLumiAtlasLabel;
}
inline Bool_t GetDrawCMSLumiAtlasLabel(){return fDrawCMSLumiAtlasLabel;}
void DrawATLASLabel(Double_t x,Double_t y,TString text,Color_t color=1);
inline void SetAtlasLabelStatus(TString AtlasLabelStatus){
fAtlasLabelStatus = AtlasLabelStatus;
}
inline TString GetAtlasLabelStatus(){ return fAtlasLabelStatus;}
inline void SetCentreOfMassEnergyLabel(TString CMSEnergy) {
fCenterOfMassEnergyLabel = CMSEnergy;
}
inline void SetCenterOfMassEnergyLabel(TString CMSEnergy) {
SetCentreOfMassEnergyLabel(CMSEnergy);
}
inline TString GetCentreOfEnergyLabel() { return fCenterOfMassEnergyLabel;}
inline TString GetCenterOfEnergyLabel() { return GetCentreOfEnergyLabel(); }
inline void SetLuminosityLabel(TString Luminosity){
fLuminosityLabel = Luminosity;
}
inline TString GetLuminosityLabel() { return fLuminosityLabel;}
void DrawTextLatex(Double_t x, Double_t y,
Color_t color, TString text,
Double_t tsize = 0.04);
inline void SetDrawDataErrorX(Bool_t DrawErrorX) {
fDrawDataErrorX = DrawErrorX;
}
inline void SetAtlasLabelPos(Float_t x, Float_t y) {
fAtlasLabelPosX = x;
fAtlasLabelPosY = y;
}
inline void SetLuminosityLabelPos(Float_t x, Float_t y) {
fLuminosityLabelPosX = x;
fLuminosityLabelPosY = y;
}
inline void SetCMSEnergyLabelPos(Float_t x, Float_t y) {
fCMSEnergyLabelPosX = x;
fCMSEnergyLabelPosY = y;
}
inline void SetLegendPos(Float_t x1, Float_t y1,
Float_t x2, Float_t y2) {
fLegend->SetX1NDC(x1); fLegend->SetY1NDC(y1);
fLegend->SetX2NDC(x2); fLegend->SetY2NDC(y2);
}
inline void SetRatioHeight(Float_t ratio) { fRatioHeight = ratio; }
TCanvas * GetCanvas() const { return fCanvas; }
inline TPad* GetRatioPad1() { return fRatioPad1; }
inline TPad* GetRatioPad2() { return fRatioPad2; }
inline TPad* GetMainPad() { return fMainPad; }
inline TH1* GetHistogramMainPad() { return fHistogramMainPad; }
inline TH1* GetHistogramRatioPad1() { return fHistogramRatioPad1; }
inline TH1* GetHistogramRatioPad2() { return fHistogramRatioPad2; }
inline Bool_t GetDrawSignalOverlay() const {
return fDrawSignalOverlay;
}
private:
TGraphAsymmErrors* SetErrors(TH1F *FromHist,
Bool_t IsData,
Option_t *option = "");
Double_t pValuePoisson(unsigned nObs, double nExp);
Double_t pValuePoissonError(unsigned nObs, double E=1, double V=1);
Double_t pValueToSignificance(double p, bool excess=true);
TH1F* CompareHistograms(TH1* hObs=0, TH1* hExp=0,
bool neglectUncertainty=false,
bool variableBinning=false,
TH1* hPull=0);
Double_t pja_normal_quantile(double p);
void SetXRange(TPad *pad, Double_t xmin, Double_t xmax);
void SetYRange(TPad *pad, Double_t ymin, Double_t ymax);
void DrawNoStack(Option_t *option = "");
void DrawStack(Option_t *option = "");
void DrawDataMCRatio();
void DrawSignificance();
void AddOverflowUnderflowBins(TH1* hist);
void SetColorsNoStack();
void SetColorsStack();
void SetupPad();
void SetupAxis();
ClassDef(HepDataMCPlot,21)
};
#endif