Geant4 9.6.0
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 (G4String mName)
 
virtual ~G4ScoreLogColorMap ()
 
virtual void GetMapColor (G4double val, G4double color[4])
 
virtual void DrawColorChartBar (G4int nPoint)
 
virtual void DrawColorChartText (G4int nPoint)
 
- Public Member Functions inherited from G4VScoreColorMap
 G4VScoreColorMap (G4String mName)
 
virtual ~G4VScoreColorMap ()
 
virtual void GetMapColor (G4double val, G4double color[4])=0
 
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)
 
virtual void DrawColorChartBar (G4int nPoint)
 
virtual void DrawColorChartText (G4int nPoint)
 
void SetPSUnit (G4String &unit)
 
void SetPSName (G4String &psName)
 

Additional Inherited Members

- Protected Attributes inherited from G4VScoreColorMap
G4String fName
 
G4bool ifFloat
 
G4double fMinVal
 
G4double fMaxVal
 
G4VVisManagerfVisManager
 
G4String fPSUnit
 
G4String fPSName
 

Detailed Description

Definition at line 36 of file G4ScoreLogColorMap.hh.

Constructor & Destructor Documentation

◆ G4ScoreLogColorMap()

G4ScoreLogColorMap::G4ScoreLogColorMap ( G4String  mName)

Definition at line 44 of file G4ScoreLogColorMap.cc.

◆ ~G4ScoreLogColorMap()

G4ScoreLogColorMap::~G4ScoreLogColorMap ( )
virtual

Definition at line 48 of file G4ScoreLogColorMap.cc.

49{;}

Member Function Documentation

◆ DrawColorChartBar()

void G4ScoreLogColorMap::DrawColorChartBar ( G4int  nPoint)
virtual

Reimplemented from G4VScoreColorMap.

Definition at line 138 of file G4ScoreLogColorMap.cc.

138 {
139
140 //G4cout << "++++++ " << fMinVal << " - " << fMaxVal << G4endl;
141 G4bool lmin = true, lmax = true;
142 if(fMinVal <= 0.) lmin = false;
143 if(fMaxVal <= 0.) lmax = false;
144 G4double min = 0.;
145 if(lmin) min = std::log10(fMinVal);
146 G4double max = 0.;
147 if(lmax) max = std::log10(fMaxVal);
148
149 G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
150 G4double c[4];
151 for(G4double y = smin; y < smax; y+=step) {
152 G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
153 G4Polyline line;
154 line.push_back(G4Point3D(-0.96, y, 0.));
155 line.push_back(G4Point3D(-0.91, y, 0.));
156 G4double val = std::pow(10., (ra*max+rb*min)/(ra+rb));
157 this->GetMapColor(val, c);
158 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
159 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
160 G4Colour col(c[0], c[1], c[2]);
161 G4VisAttributes att(col);
162 line.SetVisAttributes(&att);
163 fVisManager->Draw2D(line);
164 }
165
166}
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
double G4double
Definition: G4Types.hh:64
bool G4bool
Definition: G4Types.hh:67
virtual void GetMapColor(G4double val, G4double color[4])
G4VVisManager * fVisManager
virtual void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80

◆ DrawColorChartText()

void G4ScoreLogColorMap::DrawColorChartText ( G4int  nPoint)
virtual

Reimplemented from G4VScoreColorMap.

Definition at line 167 of file G4ScoreLogColorMap.cc.

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

◆ GetMapColor()

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

Implements G4VScoreColorMap.

Definition at line 52 of file G4ScoreLogColorMap.cc.

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

Referenced by DrawColorChartBar(), and DrawColorChartText().


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