Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ScoreLogColorMap Class Reference

#include <G4ScoreLogColorMap.hh>

+ Inheritance diagram for G4ScoreLogColorMap:

Public Member Functions

 ~G4ScoreLogColorMap () override=default
 
void GetMapColor (G4double val, G4double color[4]) override
 
void DrawColorChartBar (G4int nPoint) override
 
void DrawColorChartText (G4int nPoint) override
 
 G4VScoreColorMap (G4String mName)
 
- Public Member Functions inherited from G4VScoreColorMap
 G4VScoreColorMap (G4String mName)
 
virtual ~G4VScoreColorMap ()=default
 
G4String GetName () const
 
void SetFloatingMinMax (G4bool vl=true)
 
G4bool IfFloatMinMax () const
 
void SetMinMax (G4double minVal, G4double maxVal)
 
G4double GetMin () const
 
G4double GetMax () const
 
virtual void DrawColorChart (G4int nPoint=5)
 
void SetPSUnit (G4String &unit)
 
void SetPSName (G4String &psName)
 

Additional Inherited Members

- Protected Attributes inherited from G4VScoreColorMap
G4String fName
 
G4bool ifFloat = true
 
G4double fMinVal = 0.0
 
G4double fMaxVal = DBL_MAX
 
G4VVisManagerfVisManager = nullptr
 
G4String fPSUnit = ""
 
G4String fPSName = ""
 

Detailed Description

Definition at line 35 of file G4ScoreLogColorMap.hh.

Constructor & Destructor Documentation

◆ ~G4ScoreLogColorMap()

G4ScoreLogColorMap::~G4ScoreLogColorMap ( )
overridedefault

Member Function Documentation

◆ DrawColorChartBar()

void G4ScoreLogColorMap::DrawColorChartBar ( G4int nPoint)
overridevirtual

Reimplemented from G4VScoreColorMap.

Definition at line 149 of file G4ScoreLogColorMap.cc.

150{
151 G4bool lmin = true, lmax = true;
152 if(fMinVal <= 0.)
153 lmin = false;
154 if(fMaxVal <= 0.)
155 lmax = false;
156 G4double min = 0.;
157 if(lmin)
158 min = std::log10(fMinVal);
159 G4double max = 0.;
160 if(lmax)
161 max = std::log10(fMaxVal);
162
163 G4double smin = -0.89, smax = smin + 0.05 * (_nPoint) *0.83, step = 0.001;
164 G4double c[4];
165 for(auto y = smin; y < smax; y += step)
166 {
167 G4double ra = (y - smin) / (smax - smin), rb = 1. - ra;
168 G4Polyline line;
169 line.push_back(G4Point3D(-0.96, y, 0.));
170 line.push_back(G4Point3D(-0.91, y, 0.));
171 G4double val = std::pow(10., (ra * max + rb * min) / (ra + rb));
172 this->GetMapColor(val, c);
173 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0)
174 return;
175 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.)
176 continue;
177 G4Colour col(c[0], c[1], c[2]);
178 G4VisAttributes att(col);
179 line.SetVisAttributes(&att);
180 fVisManager->Draw2D(line);
181 }
182}
HepGeom::Point3D< G4double > G4Point3D
Definition G4Point3D.hh:34
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
void GetMapColor(G4double val, G4double color[4]) override
G4VVisManager * fVisManager
virtual void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
void SetVisAttributes(const G4VisAttributes *)
Definition G4Visible.cc:98
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments

◆ DrawColorChartText()

void G4ScoreLogColorMap::DrawColorChartText ( G4int nPoint)
overridevirtual

Reimplemented from G4VScoreColorMap.

Definition at line 183 of file G4ScoreLogColorMap.cc.

184{
185 G4bool lmin = true, lmax = true;
186 if(fMinVal <= 0.)
187 lmin = false;
188 if(fMaxVal <= 0.)
189 lmax = false;
190
191 G4double min = 0.;
192 if(lmin)
193 min = std::log10(fMinVal);
194
195 G4double max = 0.;
196 if(lmax)
197 max = std::log10(fMaxVal);
198
199 G4double c[4] = { 1., 1., 1., 1. };
200 G4Colour black(0., 0., 0.);
201 for(auto n = 0; n < _nPoint; ++n)
202 {
203 G4double a = n / (_nPoint - 1.), b = 1. - a;
204 G4double v = (a * max + b * min) / (a + b);
205
206 this->GetMapColor(std::pow(10., v), c);
207 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0)
208 return;
209 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.)
210 continue;
211
212 // background color
213 for(auto l = 0; l < 21; ++l)
214 {
215 G4Polyline line;
216 line.push_back(G4Point3D(-0.908, -0.905 + 0.05 * n + 0.002 * l, 0.));
217 line.push_back(G4Point3D(-0.705, -0.905 + 0.05 * n + 0.002 * l, 0.));
218 G4VisAttributes attblack(black);
219 line.SetVisAttributes(&attblack);
220 fVisManager->Draw2D(line);
221 }
222 // text
223 std::ostringstream oss;
224 oss << std::setw(8) << std::setprecision(1) << std::scientific
225 << std::pow(10., v);
226 std::string str = oss.str();
227 G4String value(str);
228 G4Text text(value, G4Point3D(-0.9, -0.9 + 0.05 * n, 0));
229 G4double size = 12.;
230 text.SetScreenSize(size);
231 G4Colour color(1., 1., 1.);
232 G4VisAttributes att(color);
233 text.SetVisAttributes(&att);
234
235 fVisManager->Draw2D(text);
236 }
237
238 // draw ps name
239 // background
240 G4int lpsname = 20;
241 if(lpsname > 0)
242 {
243 for(auto l = 0; l < 22; ++l)
244 {
245 G4Polyline line;
246 line.push_back(G4Point3D(-0.9, -0.965 + 0.002 * l, 0.));
247 line.push_back(G4Point3D(-0.9 + 0.025 * lpsname, -0.965 + 0.002 * l, 0.));
248 G4VisAttributes attblack(black);
249 line.SetVisAttributes(&attblack);
250 fVisManager->Draw2D(line);
251 }
252 // ps name
253 G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.));
254 G4double size = 12.;
255 txtpsname.SetScreenSize(size);
256 G4Colour color(1., 1., 1.);
257 G4VisAttributes att(color);
258 txtpsname.SetVisAttributes(&att);
259 fVisManager->Draw2D(txtpsname);
260 }
261
262 // draw unit
263 // background
264 auto len = fPSUnit.size();
265 if(len > 0)
266 {
267 for(auto l = 0; l < 21; ++l)
268 {
269 G4Polyline line;
270 line.push_back(G4Point3D(-0.7, -0.9 + 0.002 * l, 0.));
271 line.push_back(G4Point3D(-0.7 + 0.3, -0.9 + 0.002 * l, 0.));
272 G4VisAttributes attblack(black);
273 line.SetVisAttributes(&attblack);
274 fVisManager->Draw2D(line);
275 }
276 // unit
277 G4String psunit = "[" + fPSUnit + "]";
278 G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.));
279 G4double size = 12.;
280 txtunit.SetScreenSize(size);
281 G4Colour color(1., 1., 1.);
282 G4VisAttributes att(color);
283 txtunit.SetVisAttributes(&att);
284 fVisManager->Draw2D(txtunit);
285 }
286}
int G4int
Definition G4Types.hh:85

◆ G4VScoreColorMap()

G4VScoreColorMap::G4VScoreColorMap ( G4String mName)

Definition at line 39 of file G4VScoreColorMap.cc.

43 : fName(mName)
44{}

◆ GetMapColor()

void G4ScoreLogColorMap::GetMapColor ( G4double val,
G4double color[4] )
overridevirtual

Implements G4VScoreColorMap.

Definition at line 43 of file G4ScoreLogColorMap.cc.

44{
45 G4bool lmin = true, lmax = true, lval = true;
46 if(fMinVal < 0.)
47 {
48 lmin = false;
49 G4String message = " The min. value (fMinVal) is negative. : ";
51 G4Exception("G4ScoreLogColorMap::GetMapColor()",
52 "DigiHitsUtilsScoreLogColorMap000", JustWarning, message);
53 }
54 if(fMaxVal < 0.)
55 {
56 lmax = false;
57 G4String message = " The max. value (fMaxVal) is negative. : ";
59 G4Exception("G4ScoreLogColorMap::GetMapColor()",
60 "DigiHitsUtilsScoreLogColorMap001", JustWarning, message);
61 }
62 if(!lmin || !lmax)
63 {
64 color[0] = 0.;
65 color[1] = 0.;
66 color[2] = 0.;
67 color[3] = 0.;
68 return;
69 }
70
71 if(val < 0.)
72 {
73 lval = false;
74 G4String message = " 'val' (first argument) is negative : ";
76 G4Exception("G4ScoreLogColorMap::GetMapColor()",
77 "DigiHitsUtilsScoreLogColorMap002", JustWarning, message);
78 }
79 if(!lval)
80 {
81 color[0] = 0.;
82 color[1] = 0.;
83 color[2] = 0.;
84 color[3] = -1.;
85 return;
86 }
87
88 G4double logmin = 0., logmax = 0., logval = 0.;
89 if(lmin)
90 {
91 if(fMinVal > 0.)
92 logmin = std::log10(fMinVal);
93 else
94 logmin = 0.;
95 }
96 if(lmax)
97 logmax = std::log10(fMaxVal);
98 if(lval)
99 logval = std::log10(val);
100 G4double value = 0.;
101 if(lmax)
102 value = (logval - logmin) / (logmax - logmin);
103
104 if(value > 1.)
105 {
106 value = 1.;
107 }
108 if(value < 0.)
109 {
110 value = 0.;
111 }
112
113 // color map
114 const G4int NCOLOR = 6;
115 struct ColorMap
116 {
117 G4double val;
118 G4double rgb[4];
119 } colormap[] = { { 0.0, { 1., 1., 1., 1. } }, // value, r, g, b, alpha
120 { 0.2, { 0., 0., 1., 1. } }, { 0.4, { 0., 1., 1., 1. } },
121 { 0.6, { 0., 1., 0., 1. } }, { 0.8, { 1., 1., 0., 1. } },
122 { 1.0, { 1., 0., 0., 1. } } };
123
124 // search
125 G4int during[2] = { 0, 0 };
126 for(auto i = 1; i < NCOLOR; ++i)
127 {
128 if(colormap[i].val >= value)
129 {
130 during[0] = i - 1;
131 during[1] = i;
132 break;
133 }
134 }
135
136 // interpolate
137 G4double a = std::fabs(value - colormap[during[0]].val);
138 G4double b = std::fabs(value - colormap[during[1]].val);
139 for(auto i = 0; i < 4; ++i)
140 {
141 color[i] =
142 (b * colormap[during[0]].rgb[i] + a * colormap[during[1]].rgb[i]) /
143 (colormap[during[1]].val - colormap[during[0]].val);
144 if(color[i] > 1.)
145 color[i] = 1.;
146 }
147}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
static G4String ConvertToString(G4bool boolVal)

Referenced by DrawColorChartBar(), and DrawColorChartText().


The documentation for this class was generated from the following files: