#ifndef DPlotSet_h #define DPlotSet_h #include #include #include "TObject.h" #include "TObjArray.h" #include "TColor.h" #include "DPadInstructions.h" using namespace std; class DPlotSet : public TObject { public: //Single-object constructors DPlotSet(TObject* locObject); //use defaults DPlotSet(TObject* locObject, int locColor, string locLegendName = ""); DPlotSet(TObject* locObject, const DPadInstructions* locPadInstructions, int locObjectIndex = 0, int locNumObjects = 0); //Sequential-array constructors //array can have gaps!!: won't draw anything for those pads DPlotSet(TObjArray* locObjectArray); //use defaults DPlotSet(TObjArray* locObjectArray, int locColor, string locLegendName = ""); DPlotSet(TObjArray* locObjectArray, const DPadInstructions* locPadInstructions, int locObjectIndex = 0, int locNumObjects = 0); //Sporadic-object constructor //not every pad DPlotSet(void); DPlotSet(int locColor, string locLegendName = ""); //Get Max Plot Index int Get_MaxPlotIndex(void) const; //Individual plot setters/getters void Add_Plot(TObject* locObject); //appends void Add_Plot(TObject* locObject, int locPadIndex); TObject* Get_FirstPlot(void) const; TObject* Get_Plot(int locPadIndex) const; TObjArray* Get_Plots(int locMinPadIndex = 1, int locMaxPadIndex = 0) const; void Remove_Plot(int locPadIndex); //Utility string Get_ObjectType(TObject* locObject) const; //MEMBERS string dDrawOption; //if "" (default), use defaults from DPadInstruction (if 1D hist, figure out by whether or not errors) bool dHistFillColorFlag; int dHistFillColor; int dLineColor; int dLineWidth; int dLineStyle; int dMarkerColor; int dMarkerStyle; double dMarkerSize; //default is -1: ignore & use gStyle. Will use if > 0 string dLegendName; //"": none private: map dPlotMapByPad; //int = pad index starting from 0 ClassDef(DPlotSet, 1) }; /***************************************************** CONSTRUCTORS: SINGLE OBJECT *****************************************************/ //Single-object constructors inline DPlotSet::DPlotSet(TObject* locObject) : dDrawOption(""), dHistFillColorFlag(true), dHistFillColor(kTeal - 4), dLineColor(kBlack), dLineWidth(1), dLineStyle(1), dMarkerColor(kBlack), dMarkerStyle(20), dMarkerSize(-1.0), dLegendName("") { Add_Plot(locObject, 0); } inline DPlotSet::DPlotSet(TObject* locObject, int locColor, string locLegendName) : dDrawOption(""), dHistFillColorFlag(true), dHistFillColor(locColor), dLineColor(locColor), dLineWidth(1), dLineStyle(1), dMarkerColor(locColor), dMarkerStyle(20), dMarkerSize(-1.0), dLegendName(locLegendName) { Add_Plot(locObject, 0); } inline DPlotSet::DPlotSet(TObject* locObject, const DPadInstructions* locPadInstructions, int locObjectIndex, int locNumObjects) { string locObjectType = Get_ObjectType(locObject); dDrawOption = locPadInstructions->Get_DrawOption(locObjectType, locObjectIndex, locNumObjects); dHistFillColorFlag = locPadInstructions->dHistFillColorFlag; dHistFillColor = locPadInstructions->Get_HistFillColor(locObjectIndex, locNumObjects); dLineColor = locPadInstructions->Get_ObjectLineColor(locObjectIndex, locNumObjects); dLineWidth = locPadInstructions->Get_ObjectLineWidth(locObjectIndex, locNumObjects); dLineStyle = locPadInstructions->Get_ObjectLineStyle(locObjectIndex, locNumObjects); dMarkerColor = locPadInstructions->Get_MarkerColor(locObjectIndex, locNumObjects); dMarkerStyle = locPadInstructions->Get_MarkerStyle(locObjectIndex, locNumObjects); dMarkerSize = -1.0; dLegendName = locPadInstructions->Get_LegendName(locObjectIndex, locNumObjects); Add_Plot(locObject, 0); } /**************************************************** CONSTRUCTORS: SEQUENTIAL ARRAY ***************************************************/ //Sequential-array constructors inline DPlotSet::DPlotSet(TObjArray* locObjectArray) : dDrawOption(""), dHistFillColorFlag(true), dHistFillColor(kTeal - 4), dLineColor(kBlack), dLineWidth(1), dLineStyle(1), dMarkerColor(kBlack), dMarkerStyle(20), dMarkerSize(-1.0), dLegendName("") { for(int loc_i = 0; loc_i < locObjectArray->GetEntriesFast(); ++loc_i) Add_Plot(locObjectArray->At(loc_i), loc_i); } inline DPlotSet::DPlotSet(TObjArray* locObjectArray, int locColor, string locLegendName) : dDrawOption(""), dHistFillColorFlag(true), dHistFillColor(locColor), dLineColor(locColor), dLineWidth(1), dLineStyle(1), dMarkerColor(locColor), dMarkerStyle(20), dMarkerSize(-1.0), dLegendName(locLegendName) { for(int loc_i = 0; loc_i < locObjectArray->GetEntriesFast(); ++loc_i) Add_Plot(locObjectArray->At(loc_i), loc_i); } inline DPlotSet::DPlotSet(TObjArray* locObjectArray, const DPadInstructions* locPadInstructions, int locObjectIndex, int locNumObjects) { dHistFillColorFlag = locPadInstructions->dHistFillColorFlag; dHistFillColor = locPadInstructions->Get_HistFillColor(locObjectIndex, locNumObjects); dLineColor = locPadInstructions->Get_ObjectLineColor(locObjectIndex, locNumObjects); dLineWidth = locPadInstructions->Get_ObjectLineWidth(locObjectIndex, locNumObjects); dLineStyle = locPadInstructions->Get_ObjectLineStyle(locObjectIndex, locNumObjects); dMarkerColor = locPadInstructions->Get_MarkerColor(locObjectIndex, locNumObjects); dMarkerStyle = locPadInstructions->Get_MarkerStyle(locObjectIndex, locNumObjects); dMarkerSize = -1.0; dLegendName = locPadInstructions->Get_LegendName(locObjectIndex, locNumObjects); for(int loc_i = 0; loc_i < locObjectArray->GetEntriesFast(); ++loc_i) { if(locObjectArray->At(loc_i) == NULL) continue; if(dDrawOption == "") { string locObjectType = Get_ObjectType(locObjectArray->At(loc_i)); dDrawOption = locPadInstructions->Get_DrawOption(locObjectType, locObjectIndex, locNumObjects); } Add_Plot(locObjectArray->At(loc_i), loc_i); } } /**************************************************** CONSTRUCTORS: SPORADIC OBJECT ****************************************************/ //Sporadic-object constructors //not every pad inline DPlotSet::DPlotSet(void) : dDrawOption(""), dHistFillColorFlag(true), dHistFillColor(kBlack), dLineColor(kBlack), dLineWidth(1), dLineStyle(1), dMarkerColor(kBlack), dMarkerStyle(20), dMarkerSize(-1.0), dLegendName("") {} inline DPlotSet::DPlotSet(int locColor, string locLegendName) : dDrawOption(""), dHistFillColorFlag(true), dHistFillColor(locColor), dLineColor(locColor), dLineWidth(1), dLineStyle(1), dMarkerColor(locColor), dMarkerStyle(20), dMarkerSize(-1.0), dLegendName(locLegendName) {} /************************************************************ ADD/GET PLOTS ************************************************************/ //Get Max Plot Index inline int DPlotSet::Get_MaxPlotIndex(void) const { if(dPlotMapByPad.empty()) return -1; return dPlotMapByPad.rbegin()->first; } //Individual plot setters/getters inline void DPlotSet::Add_Plot(TObject* locObject, int locPadIndex) { if(locObject != NULL) dPlotMapByPad[locPadIndex] = locObject; } inline void DPlotSet::Add_Plot(TObject* locObject) { if(dPlotMapByPad.empty()) Add_Plot(locObject, 0); else Add_Plot(locObject, Get_MaxPlotIndex() + 1); } //Individual plot setters/getters inline void DPlotSet::Remove_Plot(int locPadIndex) { auto locIterator = dPlotMapByPad.find(locPadIndex); if(locIterator != dPlotMapByPad.end()) dPlotMapByPad.erase(locIterator); } inline TObject* DPlotSet::Get_Plot(int locPadIndex) const { auto locIterator = dPlotMapByPad.find(locPadIndex); if(locIterator == dPlotMapByPad.end()) return NULL; return locIterator->second; } inline TObject* DPlotSet::Get_FirstPlot(void) const { if(dPlotMapByPad.empty()) return NULL; return dPlotMapByPad.begin()->second; } inline TObjArray* DPlotSet::Get_Plots(int locMinPadIndex, int locMaxPadIndex) const { TObjArray* locPlotArray = new TObjArray(); for(auto& locPadPair : dPlotMapByPad) { int locPadIndex = locPadPair.first; if(locMaxPadIndex < locMinPadIndex) locPlotArray->AddLast(locPadPair.second); else if((locPadIndex >= locMinPadIndex) && (locPadIndex <= locMaxPadIndex)) locPlotArray->AddLast(locPadPair.second); } return locPlotArray; } /************************************************************ MISCELLANEOUS ************************************************************/ inline string DPlotSet::Get_ObjectType(TObject* locObject) const { if(locObject->IsA()->InheritsFrom(TH1::Class())) //histogram { if(locObject->IsA()->InheritsFrom(TH3::Class())) return "TH3"; if(locObject->IsA()->InheritsFrom(TH2::Class())) return "TH2"; return "TH1"; } else if(locObject->IsA()->InheritsFrom(TGraph::Class())) { if(locObject->IsA()->InheritsFrom(TGraphErrors::Class())) return "TGraphErrors"; else return "TGraph"; } else if(locObject->IsA()->InheritsFrom(TGraph2D::Class())) return "TGraph2D"; else return ""; } #endif