Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRestAnalysisPlot supports color/line/fill style def with strings #121

Merged
merged 2 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions source/framework/core/inc/TRestAnalysisPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,35 @@
#define RestCore_TRestAnalysisPlot

#include <TLatex.h>
#include <TRestRun.h>

#include "TCanvas.h"
#include "TH3D.h"

#include <TRestRun.h>
#include "TRestAnalysisTree.h"

const int REST_MAX_TAGS = 15;

// as enum "EColor" defined in Rtypes.h
// as enum "ELineStyle" defined in TAttLine.h
// as enum "EFillStyle" defined in TAttFill.h
const map<string, int> ColorIdMap{
{"white", kWhite}, {"black", kBlack}, {"gray", kGray}, {"red", kRed}, {"green", kGreen},
{"blue", kBlue}, {"yellow", kYellow}, {"magenta", kMagenta}, {"cyan", kCyan}, {"orange", kOrange},
{"spring", kSpring}, {"teal", kTeal}, {"azure", kAzure}, {"violet", kViolet}, {"pink", kPink}};
const map<string, int> LineStyleMap{
{"solid", kSolid}, {"dashed", kDashed}, {"dotted", kDotted}, {"dashDotted", kDashDotted}};
const map<string, int> FillStyleMap{
{"dotted", kFDotted1}, {"dashed", kFDashed1}, {"dotted1", kFDotted1},
{"dotted2", kFDotted2}, {"dotted3", kFDotted3}, {"hatched1", kFHatched1},
{"hatched2", kHatched2}, {"hatched3", kFHatched3}, {"hatched4", kFHatched4},
{"wicker", kFWicker}, {"scales", kFScales}, {"bricks", kFBricks},
{"snowflakes", kFSnowflakes}, {"circles", kFCircles}, {"tiles", kFTiles},
{"mondrian", kFMondrian}, {"diamonds", kFDiamonds}, {"waves1", kFWaves1},
{"dashed1", kFDashed1}, {"dashed2", kFDashed2}, {"alhambra", kFAlhambra},
{"waves2", kFWaves2}, {"stars1", kFStars1}, {"stars2", kFStars2},
{"pyramids", kFPyramids}, {"frieze", kFFrieze}, {"metopes", kFMetopes},
{"empty", kFEmpty}, {"solid", kFSolid}};

class TRestAnalysisPlot : public TRestMetadata {
public:
struct Histo_Info_Set {
Expand Down Expand Up @@ -136,6 +157,9 @@ class TRestAnalysisPlot : public TRestMetadata {
TRestAnalysisTree* GetTree(TString fileName);
TRestRun* GetRunInfo(TString fileName);
bool IsDynamicRange(TString rangeString);
Int_t GetColorIDFromString(string in);
Int_t GetFillStyleIDFromString(string in);
Int_t GetLineStyleIDFromString(string in);

protected:
public:
Expand Down
41 changes: 37 additions & 4 deletions source/framework/core/src/TRestAnalysisPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,11 @@ TRestAnalysisPlot::Histo_Info_Set TRestAnalysisPlot::SetupHistogramFromConfigFil
}

// 5. read draw style(line color, width, fill style, etc.)
hist.lineColor = StringToInteger(GetParameter("lineColor", histele, "602"));
hist.lineColor = GetColorIDFromString(GetParameter("lineColor", histele, "602"));
hist.lineWidth = StringToInteger(GetParameter("lineWidth", histele, "1"));
hist.lineStyle = StringToInteger(GetParameter("lineStyle", histele, "1"));
hist.fillStyle = StringToInteger(GetParameter("fillStyle", histele, "1001"));
hist.fillColor = StringToInteger(GetParameter("fillColor", histele, "0"));
hist.lineStyle = GetLineStyleIDFromString(GetParameter("lineStyle", histele, "1"));
hist.fillStyle = GetFillStyleIDFromString(GetParameter("fillStyle", histele, "1001"));
hist.fillColor = GetColorIDFromString(GetParameter("fillColor", histele, "0"));

return hist;
}
Expand Down Expand Up @@ -587,6 +587,39 @@ bool TRestAnalysisPlot::IsDynamicRange(TString rangeString) {
return (string(rangeString)).find(", ") != -1;
}

Int_t TRestAnalysisPlot::GetColorIDFromString(string in) {
if (in.find_first_not_of("0123456789") == string::npos) {
return StringToInteger(in);
} else if (ColorIdMap.count(in) != 0) {
return ColorIdMap.at(in);
} else {
warning << "cannot find color with name \"" << in << "\"" << endl;
}
return -1;
}

Int_t TRestAnalysisPlot::GetFillStyleIDFromString(string in) {
if (in.find_first_not_of("0123456789") == string::npos) {
return StringToInteger(in);
} else if (FillStyleMap.count(in) != 0) {
return FillStyleMap.at(in);
} else {
warning << "cannot find fill style with name \"" << in << "\"" << endl;
}
return -1;
}

Int_t TRestAnalysisPlot::GetLineStyleIDFromString(string in) {
if (in.find_first_not_of("0123456789") == string::npos) {
return StringToInteger(in);
} else if (LineStyleMap.count(in) != 0) {
return LineStyleMap.at(in);
} else {
warning << "cannot find line style with name \"" << in << "\"" << endl;
}
return -1;
}

void TRestAnalysisPlot::PlotCombinedCanvas() {
// Initializing canvas window
if (fCombinedCanvas != nullptr) {
Expand Down