GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
LevelSchemeDraw.hh
Go to the documentation of this file.
1#ifndef GAMR_NUCLEUS_DRAWLEVELSCHEME_HH
2#define GAMR_NUCLEUS_DRAWLEVELSCHEME_HH
3
4#include <map>
5
6#include <TArrow.h>
7#include <TText.h>
8#include <TLatex.h>
9#include <TBox.h>
10#include <TGaxis.h>
11#include <TPolyLine.h>
12#include <TLine.h>
13
14namespace GamR {
15 namespace Nucleus {
16 namespace LevelSchemeDraw {
17 class Scheme;
18
19 class State : public TNamed, public TAttLine {
20 public:
22 int index;
23 Double_t fEnergy;
24 Double_t fDrawPos;
25 Double_t fLabelPos;
26 Double_t fLeft;
27 Double_t fRight;
28 Double_t fExtLeft;
29 Double_t fExtRight;
30
31 double textsize = 0.05;
32 std::string fLeftLab;
33 std::string fRightLab;
34
36 TLine *extline = NULL;
37
38 TLatex *fLeftLabel = NULL;
39 TLatex *fRightLabel = NULL;
40 State() : fEnergy(0), fDrawPos(0), fLabelPos(0), fLeft(0), fRight(1), extension(false) { SetLineColor(kBlack); fLeftLabel = new TLatex(); fRightLabel = new TLatex();}
41 State(std::string name, Scheme *scheme, double energy, double left, double right, std::string leftlabel, std::string rightlabel, EColor color=kBlack) :
42 TNamed(name, name),
43 fEnergy(energy),
44 fDrawPos(energy),
45 fLabelPos(energy),
46 fLeft(left),
47 fRight(right),
48 fScheme(scheme),
49 fLeftLab(leftlabel),
50 fRightLab(rightlabel),
51 extension(false)
52 { SetLineColor(color); SetLineWidth(3); fLeftLabel = new TLatex(); fRightLabel = new TLatex(); }
53 ~State() { }
54 void SetLeftRight(double left, double right) { fLeft = left; fRight = right; } // *MENU* *ARGS={left=>fLeft right=>fRight}
55 void SetWidth(double width) { double cent = (fLeft + fRight)/2.0; fLeft = cent - width/2.0; fRight = cent + width/2.0; } // *MENU* *ARGS={width=>fRight-fLeft}
56 void SetLabels(const char *leftlab, const char *rightlab) { fLeftLab = (std::string)leftlab; fRightLab = (std::string)rightlab; } // *MENU*
57 void SetExtension(double left, double right) { fExtLeft = left; fExtRight = right; extension = true; extline = new TLine(); } // *MENU*
58 void AddTransition(const char* name_fin, double width, double start, double stop, double labelpos = 0.5, EColor color=kBlack); // *MENU*
59 Int_t DistancetoPrimitive(Int_t px, Int_t py);
60 void ExecuteEvent(Int_t event, Int_t px, Int_t py);
61 void Paint(Option_t *option="");
62 bool operator<(const State &rhs) const { return fEnergy < rhs.fEnergy; }
63 bool operator==(const State &rhs) const { return fEnergy == rhs.fEnergy; }
64
65 private:
66 bool p1;
67 int px1, px2, pxold;
68 ClassDef(State, 1);
69 };
70 class Transition : public TPolyLine {
71 public:
75 //these are experimentally observed things
76 Double_t fStart;
77 Double_t fStop;
78 Double_t fWidth;
79 Double_t fLabelPos;
80 TText *fLabel = NULL;
81 TBox *fLabelBox = NULL;
82 double textsize = 0.05;
83 Transition() : fInitial(NULL), fFinal(NULL), TPolyLine(), fStart(0.5), fStop(0.5), fLabelPos(0.5) { SetLineColor(kBlack); SetFillColor(kBlack); fLabel = new TText(); fLabelBox = new TBox(); SetPolyLine(7); }
84 Transition(Scheme *scheme, State *initial, State *final, double width, double start, double stop, double labelpos, EColor color) :
85 fScheme(scheme),
86 TPolyLine(),
87 fInitial(initial),
88 fFinal(final),
89 fWidth(width),
90 fStart(start),
91 fStop(stop),
92 fLabelPos(labelpos)
93 { SetLineColor(color); SetFillColor(color); fLabel = new TText(); fLabelBox = new TBox(); SetPolyLine(7); }
95 void SetStartStop(double start, double stop) { fStart = start; fStop = stop; } // *MENU* *ARGS={start=>fStart stop=>fStop}
96 void Paint(Option_t *option = "");
97 Int_t DistancetoPrimitive(Int_t px, Int_t py);
98 void ExecuteEvent(Int_t event, Int_t px, Int_t py);
99 void Draw(Option_t *option = "") { TPolyLine::Draw(option); }
100 double GetX1();
101 double GetX2();
102 double GetY1();
103 double GetY2();
104 double GetPerpTheta();
105 double GetLength();
106 double GetWidth();
107 double GetWidthX();
108 double GetWidthY();
109 double GetHeadWidth();
110 double GetHeadWidthX();
111 double GetHeadWidthY();
112 double GetHeadLength();
113 void PaintArrow();
114
115 private:
116 bool p1,p2;
117 int px1, px2, px1old, px2old;
118 int py1, py2, py1old, py2old;
119 double XtoAbsPixel(double x);
120 double YtoAbsPixel(double y);
121 double AbsPixeltoX(double xpix);
122 double AbsPixeltoY(double ypix);
123
124 ClassDef(Transition, 1);
125 };
126 class Scheme : public TNamed {
127 public:
128 std::map<std::string, State> fStates;
129 std::vector<Transition> fTransitions;
130 double ylo = 0;
131 double yhi = 1e9;
132 double xlo = 0.0;
133 double xhi = 1.0;
134 double textsize = 0.05;
135 double fWidthScale = 0.01;
136
137 TH2F *fDrawHist = NULL;
138 TGaxis *fAxis = NULL;
139 Scheme() { fDrawHist = new TH2F("", "", 100, xlo, xhi, 100, ylo, yhi); }
140 Scheme(std::string name) : TNamed(name, name) { fDrawHist = new TH2F(name.c_str(), name.c_str(), 100, xlo, xhi, 100, ylo, yhi); }
141 void AddState(std::string name, double energy, double left, double right, std::string leftlab, std::string rightlab, EColor color=kBlack) { State state(name, this, energy, left, right, leftlab, rightlab, color); state.textsize = textsize; fStates[name]=state; }
142 void AddTransition(std::string initState, std::string finState, double width, double start, double stop, double labelpos=0.5, EColor color=kBlack) {
143 Transition transition(this, &fStates[initState], &fStates[finState], width, start, stop, labelpos, color);
144 transition.textsize = textsize;
145 fTransitions.push_back(transition);
146
147 }
148 void SetDrawRange(double xlow, double xhigh, double eLow, double eHigh) { ylo = eLow; yhi = eHigh; xlo = xlow; xhi = xhigh; fDrawHist->SetBins(100, xlo, xhi, 100, ylo, yhi); }
149 void SetTextSize(double size) {
150 textsize = size;
151 for (auto &state : fStates) {
152 state.second.textsize = textsize;
153 }
154 for (auto &transition : fTransitions) {
155 transition.textsize = textsize;
156 }
157 }
159 void Paint(Option_t *option="");
160
161 void ReadScheme(std::string filename);
162 void WriteScheme(std::string filename);
163
165
166 };
167 }
168 }
169}
170
171
172#endif
void py(TVirtualPad *canvas)
void px(TVirtualPad *canvas)
std::map< std::string, State > fStates
void AddState(std::string name, double energy, double left, double right, std::string leftlab, std::string rightlab, EColor color=kBlack)
void SetDrawRange(double xlow, double xhigh, double eLow, double eHigh)
void ReadScheme(std::string filename)
void AddTransition(std::string initState, std::string finState, double width, double start, double stop, double labelpos=0.5, EColor color=kBlack)
void WriteScheme(std::string filename)
void AddTransition(const char *name_fin, double width, double start, double stop, double labelpos=0.5, EColor color=kBlack)
bool operator==(const State &rhs) const
bool operator<(const State &rhs) const
void SetLabels(const char *leftlab, const char *rightlab)
void ExecuteEvent(Int_t event, Int_t px, Int_t py)
void SetLeftRight(double left, double right)
void SetExtension(double left, double right)
Int_t DistancetoPrimitive(Int_t px, Int_t py)
State(std::string name, Scheme *scheme, double energy, double left, double right, std::string leftlabel, std::string rightlabel, EColor color=kBlack)
void SetStartStop(double start, double stop)
Transition(Scheme *scheme, State *initial, State *final, double width, double start, double stop, double labelpos, EColor color)
void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition Gain.cc:19