#ifndef DPadInstructions_h #define DPadInstructions_h #include #include #include #include #include "TObject.h" #include "TStyle.h" #include "TColor.h" using namespace std; class DPadInstructions : public TObject { //vectors: //if size = 0, ignore (use gStyle defaults) //if size = 1, use same for all objects //if size > 1, use individual for each, last one for any extras public: DPadInstructions(void); string Get_DrawOption(size_t locObjectIndex = 0, size_t locNumObjects = 0) const; string Get_DrawOption(string locObjectType, size_t locObjectIndex, size_t locNumObjects = 0) const; string Get_DefaultDrawOption(string locObjectType) const; //e.g. "TH1", "TH2", "TGraph", etc. int Get_ObjectLineWidth(size_t locObjectIndex, size_t locNumObjects = 0) const; int Get_ObjectLineStyle(size_t locObjectIndex, size_t locNumObjects = 0) const; int Get_ObjectLineColor(size_t locObjectIndex, size_t locNumObjects = 0) const; int Get_HistFillColor(size_t locObjectIndex, size_t locNumObjects = 0) const; int Get_MarkerColor(size_t locObjectIndex, size_t locNumObjects = 0) const; int Get_MarkerStyle(size_t locObjectIndex, size_t locNumObjects = 0) const; string Get_LegendName(size_t locObjectIndex, size_t locNumObjects = 0) const; //log flags bool dLogXFlag; bool dLogYFlag; bool dLogZFlag; bool dDrawStatBoxFlag; //Type-agnostic style vector dDrawOptions; //"SAME" is automatically added when needed vector dObjectLineColors; vector dObjectLineWidth; vector dObjectLineStyle; //Legend double dLegendMinBottomY; double dLegendMinLeftX; vector dLegendNames; //Default draw options //first string is plot-type (e.g. "TH1", "TH2", "TGraph") map dDefaultDrawOptionMap; // this is used if dDrawOptions is empty //TH1-specific bool dHistFillColorFlag; //fill with colors, or just draw outline //ignored if hist has error bars: points instead bool dHistStackFlag; bool dScaleFlag; //if true scale 2nd-Nth plots when superimposing (with right-side axis): scale such that integral is equal bool dScaleByMaxFlag; //if false: scales by integral for hists, mean-y for graphs bool dScaleAxisFlag; //if true: draw scale axis on right side when scaling int dSingleHistFillColor; //used when not superimposing (and filling) vector dHistFillColors; //used when superimposing (and filling) //TH2-specific double dPaletteLabelSize; //graph-specific vector dMarkerColors; vector dMarkerStyles; //'X', 'Y', 'Z', 'M' (for hist min/max) //or lowercase void Set_AxisRange(char locAxis, double locRangeMin, double locRangeMax); bool Is_AxisRangeSet(char locAxis) const; pair Get_AxisRange(char locAxis) const; private: //axis ranges map > dAxisRanges; //char: 'X', 'Y', 'Z', 'M' (for hist min/max) //or lowercase int Get_PaletteColor(size_t locObjectIndex, size_t locNumObjects) const; ClassDef(DPadInstructions, 1) }; inline void DPadInstructions::Set_AxisRange(char locAxis, double locRangeMin, double locRangeMax) { locAxis = toupper(locAxis); dAxisRanges[locAxis] = pair(locRangeMin, locRangeMax); } inline bool DPadInstructions::Is_AxisRangeSet(char locAxis) const { locAxis = toupper(locAxis); return (dAxisRanges.find(locAxis) != dAxisRanges.end()); } inline pair DPadInstructions::Get_AxisRange(char locAxis) const { locAxis = toupper(locAxis); const auto locIterator = dAxisRanges.find(locAxis); if(locIterator == dAxisRanges.end()) return pair(9.9e99, -9.9e99); return locIterator->second; } inline string DPadInstructions::Get_DrawOption(size_t locObjectIndex, size_t locNumObjects) const { if(dDrawOptions.empty()) return string(""); if(locNumObjects > dDrawOptions.size()) return dDrawOptions[0]; return ((locObjectIndex < dDrawOptions.size()) ? dDrawOptions[locObjectIndex] : dDrawOptions[0]); } inline string DPadInstructions::Get_DefaultDrawOption(string locObjectType) const { map::const_iterator locIterator = dDefaultDrawOptionMap.find(locObjectType); return ((locIterator != dDefaultDrawOptionMap.end()) ? locIterator->second : string("")); } inline string DPadInstructions::Get_DrawOption(string locObjectType, size_t locObjectIndex, size_t locNumObjects) const { if(dDrawOptions.empty()) return Get_DefaultDrawOption(locObjectType); return Get_DrawOption(locObjectIndex, locNumObjects); } inline int DPadInstructions::Get_ObjectLineWidth(size_t locObjectIndex, size_t locNumObjects) const { if(dObjectLineWidth.empty()) return gStyle->GetHistLineWidth(); if(locNumObjects > dObjectLineWidth.size()) return dObjectLineWidth[0]; return ((locObjectIndex < dObjectLineWidth.size()) ? dObjectLineWidth[locObjectIndex] : dObjectLineWidth[0]); } inline int DPadInstructions::Get_ObjectLineStyle(size_t locObjectIndex, size_t locNumObjects) const { if(dObjectLineStyle.empty()) return gStyle->GetHistLineStyle(); if(locNumObjects > dObjectLineStyle.size()) return dObjectLineStyle[0]; return ((locObjectIndex < dObjectLineStyle.size()) ? dObjectLineStyle[locObjectIndex] : dObjectLineStyle[0]); } inline int DPadInstructions::Get_ObjectLineColor(size_t locObjectIndex, size_t locNumObjects) const { if(dObjectLineColors.empty()) return gStyle->GetHistLineColor(); if(locNumObjects > dObjectLineColors.size()) return Get_PaletteColor(locObjectIndex, locNumObjects); return ((locObjectIndex < dObjectLineColors.size()) ? dObjectLineColors[locObjectIndex] : dObjectLineColors[0]); } inline int DPadInstructions::Get_HistFillColor(size_t locObjectIndex, size_t locNumObjects) const { if((locNumObjects <= 1) && (locObjectIndex == 0)) return dSingleHistFillColor; if(dHistFillColors.empty()) return gStyle->GetHistFillColor(); if(locNumObjects > dHistFillColors.size()) return Get_PaletteColor(locObjectIndex, locNumObjects); return ((locObjectIndex < dHistFillColors.size()) ? dHistFillColors[locObjectIndex] : dHistFillColors[0]); } inline int DPadInstructions::Get_MarkerColor(size_t locObjectIndex, size_t locNumObjects) const { if(dMarkerColors.empty()) return gStyle->GetMarkerColor(); if(locNumObjects > dMarkerColors.size()) return Get_PaletteColor(locObjectIndex, locNumObjects); return ((locObjectIndex < dMarkerColors.size()) ? dMarkerColors[locObjectIndex] : dMarkerColors[0]); } inline int DPadInstructions::Get_MarkerStyle(size_t locObjectIndex, size_t locNumObjects) const { if(dMarkerStyles.empty()) return gStyle->GetMarkerStyle(); if(locNumObjects > dMarkerStyles.size()) return dMarkerStyles[0]; return ((locObjectIndex < dMarkerStyles.size()) ? dMarkerStyles[locObjectIndex] : dMarkerStyles[0]); } inline string DPadInstructions::Get_LegendName(size_t locObjectIndex, size_t locNumObjects) const { if(dLegendNames.empty() || (locNumObjects > dLegendNames.size()) || (locObjectIndex >= dLegendNames.size())) return ""; return dLegendNames.at(locObjectIndex); } inline int DPadInstructions::Get_PaletteColor(size_t locObjectIndex, size_t locNumObjects) const { gStyle->SetPalette(55); //rainbow int locNumColors = TColor::GetNumberOfColors(); double locColorRate = double(locNumColors) / double(locNumObjects); int locColorIndex = int(double(locObjectIndex)*locColorRate); int locColor = TColor::GetColorPalette(locColorIndex); return locColor; } #endif