Geant4 10.7.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 35 of file G4ScoreLogColorMap.hh.

Constructor & Destructor Documentation

◆ G4ScoreLogColorMap()

G4ScoreLogColorMap::G4ScoreLogColorMap ( G4String  mName)

Definition at line 43 of file G4ScoreLogColorMap.cc.

◆ ~G4ScoreLogColorMap()

G4ScoreLogColorMap::~G4ScoreLogColorMap ( )
virtual

Definition at line 47 of file G4ScoreLogColorMap.cc.

48{;}

Member Function Documentation

◆ DrawColorChartBar()

void G4ScoreLogColorMap::DrawColorChartBar ( G4int  nPoint)
virtual

Reimplemented from G4VScoreColorMap.

Definition at line 141 of file G4ScoreLogColorMap.cc.

141 {
142
143 //G4cout << "++++++ " << fMinVal << " - " << fMaxVal << G4endl;
144 G4bool lmin = true, lmax = true;
145 if(fMinVal <= 0.) lmin = false;
146 if(fMaxVal <= 0.) lmax = false;
147 G4double min = 0.;
148 if(lmin) min = std::log10(fMinVal);
149 G4double max = 0.;
150 if(lmax) max = std::log10(fMaxVal);
151
152 G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
153 G4double c[4];
154 for(G4double y = smin; y < smax; y+=step) {
155 G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
156 G4Polyline line;
157 line.push_back(G4Point3D(-0.96, y, 0.));
158 line.push_back(G4Point3D(-0.91, y, 0.));
159 G4double val = std::pow(10., (ra*max+rb*min)/(ra+rb));
160 this->GetMapColor(val, c);
161 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
162 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
163 G4Colour col(c[0], c[1], c[2]);
164 G4VisAttributes att(col);
165 line.SetVisAttributes(&att);
166 fVisManager->Draw2D(line);
167 }
168
169}
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:34
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
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:79
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)
virtual

Reimplemented from G4VScoreColorMap.

Definition at line 170 of file G4ScoreLogColorMap.cc.

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

◆ GetMapColor()

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

Implements G4VScoreColorMap.

Definition at line 51 of file G4ScoreLogColorMap.cc.

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

Referenced by DrawColorChartBar(), and DrawColorChartText().


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