#ifndef DCanvasInstructions_h #define DCanvasInstructions_h #include #include #include #include #include "TObject.h" #include "TStyle.h" #include "TColor.h" #include "TROOT.h" #include "RVersion.h" #include "DPadInstructions.h" using namespace std; class DCanvasInstructions : public TObject { public: DCanvasInstructions(string locStyleName = "Default"); DPadInstructions* Get_PadInstructions(size_t locPadIndex = 0) const; //Pad Alignment float dTargetPadAspectRatio; int dMinPadWidth; //Style TStyle* dStyle; float dPadLargeRightMargin; //For TH2* or right-side scaling axis //pad (e.g. plot-specific) instructions override TStyle instructions vector dPadInstructions; //Adjacent plots float dAdjacentPadTopMargin; //For adjacent plots in more than one row (title in hist) //common y (or z for 2D) range for all plots in a canvas //if false, is common only within each row bool dCommonRangeFlag; //common height for all plots in a canvas //if false & adjacent, then all plots in a row //else not used bool dCommonGraphRange_OnlyErrorsFlag; //if true: when determining the common range for graphs, ignore data with no/0 errors void Set_TargetCanvasAspectRatio(float locTargetCanvasAspectRatio); void Set_TargetCanvasHeight(int locTargetCanvasHeight); int Get_TargetCanvasHeight(void) const; int Get_TargetCanvasWidth(void) const; float Get_TargetCanvasAspectRatio(void) const; void Set_OptStat(int locOptStat); void Set_OptFit(int locOptFit); void Set_LabelSize(double locLabelSize); //Adjacent plots bool Get_AdjacentPlotsFlag(void) const{return dAdjacentPlotsFlag;} void Set_AdjacentPlotsFlag(bool locAdjacentPlotsFlag); private: float dTargetCanvasAspectRatio; int dTargetCanvasHeight; bool dAdjacentPlotsFlag; //if true then draw plots directly adjacent to each other on a canvas ClassDef(DCanvasInstructions, 1) }; inline DPadInstructions* DCanvasInstructions::Get_PadInstructions(size_t locPadIndex) const { if(dPadInstructions.empty()) return NULL; return ((locPadIndex < dPadInstructions.size()) ? dPadInstructions[locPadIndex] : dPadInstructions[0]); } inline int DCanvasInstructions::Get_TargetCanvasHeight(void) const { return dTargetCanvasHeight; } inline float DCanvasInstructions::Get_TargetCanvasAspectRatio(void) const { return dTargetCanvasAspectRatio; } inline int DCanvasInstructions::Get_TargetCanvasWidth(void) const { return (int(float(dTargetCanvasHeight)*dTargetCanvasAspectRatio + 0.000000001)); } inline void DCanvasInstructions::Set_TargetCanvasAspectRatio(float locTargetCanvasAspectRatio) { dTargetCanvasAspectRatio = locTargetCanvasAspectRatio; dStyle->SetCanvasDefW(dTargetCanvasAspectRatio*Get_TargetCanvasHeight()); } inline void DCanvasInstructions::Set_TargetCanvasHeight(int locTargetCanvasHeight) { dTargetCanvasHeight = locTargetCanvasHeight; dStyle->SetCanvasDefH(dTargetCanvasHeight); dStyle->SetCanvasDefW(Get_TargetCanvasWidth()); } inline void DCanvasInstructions::Set_OptStat(int locOptStat) { dStyle->SetOptStat(locOptStat); } inline void DCanvasInstructions::Set_OptFit(int locOptFit) { dStyle->SetOptFit(locOptFit); } inline void DCanvasInstructions::Set_LabelSize(double locLabelSize) { dStyle->SetLabelSize(locLabelSize, "xyz"); } inline void DCanvasInstructions::Set_AdjacentPlotsFlag(bool locAdjacentPlotsFlag) { dAdjacentPlotsFlag = locAdjacentPlotsFlag; int locFontOnesDigit = dAdjacentPlotsFlag ? 3 : 2; if(dAdjacentPlotsFlag) { dCommonRangeFlag = true; //user can disable if they really want to //Turn off grid: histogram titles need to be in the pane //Titles are needed to differentiate histograms dStyle->SetPadGridX(kFALSE); dStyle->SetPadGridY(kFALSE); } //Set new font precision: switching text sizes from fractions to pixels //Do this by setting the last digit to 3 (instead of the default of 2) //or switch back if argument is false! //https://root.cern.ch/doc/master/classTAttText.html#T4 //titles int locFont = 10*(int(dStyle->GetTitleFont("X") + 0.1)/10) + locFontOnesDigit; dStyle->SetTitleFont(locFont, "X"); locFont = 10*(int(dStyle->GetTitleFont("Y") + 0.1)/10) + locFontOnesDigit; dStyle->SetTitleFont(locFont, "Y"); locFont = 10*(int(dStyle->GetTitleFont("Z") + 0.1)/10) + locFontOnesDigit; dStyle->SetTitleFont(locFont, "Z"); locFont = 10*(int(dStyle->GetTitleFont("T") + 0.1)/10) + locFontOnesDigit; dStyle->SetTitleFont(locFont, "T"); //labels locFont = 10*(int(dStyle->GetLabelFont("X") + 0.1)/10) + locFontOnesDigit; dStyle->SetLabelFont(locFont, "X"); locFont = 10*(int(dStyle->GetLabelFont("Y") + 0.1)/10) + locFontOnesDigit; dStyle->SetLabelFont(locFont, "Y"); locFont = 10*(int(dStyle->GetLabelFont("Z") + 0.1)/10) + locFontOnesDigit; dStyle->SetLabelFont(locFont, "Z"); locFont = 10*(int(dStyle->GetLabelFont("T") + 0.1)/10) + locFontOnesDigit; dStyle->SetLabelFont(locFont, "T"); } #endif