#ifndef DPlotDrawer_h #define DPlotDrawer_h #include #include #include #include #include #include #include "TObject.h" #include "TObjArray.h" #include "TMath.h" #include "TStyle.h" #include "TROOT.h" #include "TCanvas.h" #include "TVirtualPad.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGraph.h" #include "TGraphErrors.h" #include "TGraph2D.h" #include "THStack.h" #include "TMultiGraph.h" #include "TGaxis.h" #include "TLegend.h" #include "TClass.h" #include "TPaletteAxis.h" #include "TPaveText.h" #include "DPlotSet.h" #include "DPadInstructions.h" #include "DCanvasInstructions.h" using namespace std; class DPlotDrawer : public TObject { public: DPlotDrawer(); //If drawers return a TObjArray, it is of TCanvas* //Single pad: TCanvas* Draw_Object(TObject* locPlot, const DCanvasInstructions* locCanvasInstructions = NULL); TCanvas* Draw_Superimpose(TObjArray* locObjectArray, const DCanvasInstructions* locCanvasInstructions = NULL); //Multiple pads: TObjArray* Draw_Array(TObjArray* locObjectArray, const DCanvasInstructions* locCanvasInstructions = NULL); //1 per pad TObjArray* Draw_2DArray(TObjArray* locObjectArray, const DCanvasInstructions* locCanvasInstructions = NULL); //array dimensions: plot type, pad //PlotSet(s) TObjArray* Draw_PlotSet(DPlotSet* locPlotSet, const DCanvasInstructions* locCanvasInstructions = NULL); TObjArray* Draw_PlotSetArray(TObjArray* locPlotSetArray, const DCanvasInstructions* locCanvasInstructions = NULL); //Save Options bool dSavePlotsFlag; //if true, will save objs of all types in dSaveFileExtensions vector dSaveFileExtensions; bool dDebugFlag; private: enum DEdgePlotBits { d_TopEdge = 0, d_BottomEdge, d_LeftEdge, d_RightEdge, d_AdjacentFlag }; //Build Plotsets TObjArray* Build_PlotSets_Superimpose(TObjArray* locObjectArray, const DPadInstructions* locPadInstructions); //Canvases int Design_Canvases(int locNumPads, const DCanvasInstructions* locCanvasInstructions, int& locNumRows, int& locNumColumns); int Calc_NumCanvases(const DCanvasInstructions* locCanvasInstructions, int locNumObjects, int locMaxNumPadsPerCanvas); int Calc_MaxNumPadsPerCanvas(const DCanvasInstructions* locCanvasInstructions); int Calc_PadLayout(const DCanvasInstructions* locCanvasInstructions, float locTargetNumPads, bool locTargetIsMinNumPads, int& locNumRows, int& locNumColumns); TObjArray* Create_Canvas(TObjArray* locPlotSetArray, int locTotalNumPads, TObjArray* locCanvasArray, const DCanvasInstructions* locCanvasInstructions, int locNumPadsPerCanvas, int locOverallPadIndex, int& locNumPadsThisCanvas, int& locNumRows, int& locNumColumns); void Calc_CanvasSize(const DCanvasInstructions* locCanvasInstructions, int locNumRows, int locNumColumns, int& locCanvasWidth, int& locCanvasHeight); TObjArray* Create_AdjacentPads(TCanvas* locCanvas, int locNumColumns, int locNumRows); string Get_CanvasName(string locCanvasBaseName, int locCanvasIndex); void Save_Canvas(TCanvas *locCanvas, const DCanvasInstructions* locCanvasInstructions); bitset<5> Find_EdgePlotBits(const DCanvasInstructions* locCanvasInstructions, int locNumColumns, int locNumRows, int locCanvasPadIndex, int locNumPads, int locOverallPadIndex); //Draw void Draw_Pad_Hist(const TObjArray* locPlotSetArray, int locOverallPadIndex, const DPadInstructions* locPadInstructions, bitset<5> locEdgePlotBits = bitset<5>(0x1F), pair locCombinedRangePair = pair(1.0, -1.0)); void Draw_Pad_Graph(const TObjArray* locPlotSetArray, int locOverallPadIndex, const DPadInstructions* locPadInstructions, bitset<5> locEdgePlotBits = bitset<5>(0x1F), pair locCombinedRangePair = pair(1.0, -1.0)); void Tweak_PadPlots(TObjArray* locObjectArray, const DPadInstructions* locPadInstructions, bitset<5> locEdgePlotBits, pair locCombinedRangePair, TObject* locCollectionObject = NULL); void Draw_Legend(const TObjArray* locObjectArray, const DPadInstructions* locPadInstructions); //Draw Utilities: All Objects: Axes map Build_AxisMap(TObject* locObject); void Apply_AxisRanges(map& locAxisMap, const DPadInstructions* locPadInstructions, bool locIsHistFlag); void Set_ValueRange(const TObjArray* locObjectArray, bool locIs1DFlag, const DPadInstructions* locPadInstructions, pair locValueRangePair); void Apply_AxisStyle(map& locAxisMap); //Draw Utilities: All Objects: Axes: Adjacent Plots void DisableOrAlign_Axes(bitset<5> locEdgePlotBits, map& locAxisMap); void Adjust_AxisRanges(bool locIs2DFlag, map& locAxisMap, bitset<5> locEdgePlotBits, pair locValueMinMax); void Fix_AxisTextSizes(bitset<5> locEdgePlotBits, map& locAxisMap); //Draw Utilities: All Objects: Misc void Fix_PadTitlePosition(bitset<5> locEdgePlotBits = bitset<5>(0x1F)); void Set_Logs(const DPadInstructions* locPadInstructions); void Draw_ScaleAxis(pair locRightAxisMinMax, string locAxisTitle, int locAxisColor, int locLabelFont, int locTitleFont); void Modify_Palette(TObject* locObject, const DPadInstructions* locPadInstructions, bitset<5> locEdgePlotBits = bitset<5>(0x1F)); void Modify_Palette(TPaletteAxis* locPaletteAxis, const DPadInstructions* locPadInstructions, bitset<5> locEdgePlotBits = bitset<5>(0x1F)); //Draw/Calc Utilities: Histograms void Set_HistStyle(TH1* locHist, DPlotSet* locPlotSet); pair Scale_Histogram(TH1*& locHist, bool locScaleByMaxFlag, double locFirstHistScaleReference); void Draw_ScaleAxis_Hist(const TObjArray* locPlotSetArray, int locOverallPadIndex, pair locRightAxisMinMax); //Draw/Calc Utilities: Graph void Set_GraphStyle(TGraph* locGraph, DPlotSet* locPlotSet); pair Scale_Graph(TGraph*& locGraph, bool locScaleByMaxFlag, double locScaleReference); double Calc_GraphMeanY(TGraph* locGraph); pair Find_GraphMinMax(TGraph* locGraph, double locRangeMin = 1.0, double locRangeMax = -1.0); void Draw_ScaleAxis_Graph(const TObjArray* locPlotSetArray, int locOverallPadIndex, pair locRightAxisMinMax); //Misc pair Find_CombinedRange_PlotSets(const TObjArray* locPlotSetArray, const DCanvasInstructions* locCanvasInstructions, int locOverallPadIndex, int locNumPads); pair Find_CombinedRange_Pad(const TObjArray* locPadArray, const DPadInstructions* locPadInstructions); pair Find_ValueMinMax(const TObject* locObject, pair locAxisRangePair = pair(1.0, -1.0)); void Finalize_MinMax(pair& locMinMaxPair, bool locIsHistFlag); bool Check_IsPadRightMarginLarge(const DCanvasInstructions* locCanvasInstructions, TObjArray* locPlotSetArray, int locFirstPadIndex, int locLastPadIndex); int Get_NumDimensions(TObject* locObject); DCanvasInstructions* dDefaultCanvasInstructions; bool dResultAxisLogScale; //true if the result-axis (e.g. y-axis for 1d plots) is log scale bool dCommonGraphRange_OnlyErrorsFlag; //if true: when determining the common range for graphs, ignore data with no/0 errors ClassDef(DPlotDrawer, 1) }; #endif