Skip to content

Commit

Permalink
Merge pull request #121 from rest-for-physics/style-def-with-string
Browse files Browse the repository at this point in the history
TRestAnalysisPlot supports color/line/fill style def with strings
  • Loading branch information
jgalan authored Jan 18, 2022
2 parents a225aeb + d7824fb commit bb8b1a6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
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

0 comments on commit bb8b1a6

Please sign in to comment.