Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ScoreLogColorMap.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28
29#include "G4ScoreLogColorMap.hh"
30#include <cmath>
31#include <string>
32#include <sstream>
33#include <iomanip>
34
35#include "G4VVisManager.hh"
36#include "G4VisAttributes.hh"
37#include "G4Text.hh"
38#include "G4Circle.hh"
39#include "G4Polyline.hh"
40#include "G4Colour.hh"
41
43 : G4VScoreColorMap(mName)
44{
45 ;
46}
47
49
50#include "G4UIcommand.hh"
52{
53 G4bool lmin = true, lmax = true, lval = true;
54 if(fMinVal < 0.)
55 {
56 lmin = false;
57 G4String message = " The min. value (fMinVal) is negative. : ";
59 G4Exception("G4ScoreLogColorMap::GetMapColor()",
60 "DigiHitsUtilsScoreLogColorMap000", JustWarning, message);
61 }
62 if(fMaxVal < 0.)
63 {
64 lmax = false;
65 G4String message = " The max. value (fMaxVal) is negative. : ";
67 G4Exception("G4ScoreLogColorMap::GetMapColor()",
68 "DigiHitsUtilsScoreLogColorMap001", JustWarning, message);
69 }
70 if(!lmin || !lmax)
71 {
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 {
81 lval = false;
82 G4String message = " 'val' (first argument) is negative : ";
84 G4Exception("G4ScoreLogColorMap::GetMapColor()",
85 "DigiHitsUtilsScoreLogColorMap002", JustWarning, message);
86 }
87 if(!lval)
88 {
89 color[0] = 0.;
90 color[1] = 0.;
91 color[2] = 0.;
92 color[3] = -1.;
93 return;
94 }
95
96 G4double logmin = 0., logmax = 0., logval = 0.;
97 if(lmin)
98 {
99 if(fMinVal > 0.)
100 logmin = std::log10(fMinVal);
101 else
102 logmin = 0.;
103 }
104 if(lmax)
105 logmax = std::log10(fMaxVal);
106 if(lval)
107 logval = std::log10(val);
108 G4double value = 0.;
109 if(lmax)
110 value = (logval - logmin) / (logmax - logmin);
111
112 if(value > 1.)
113 {
114 value = 1.;
115 }
116 if(value < 0.)
117 {
118 value = 0.;
119 }
120
121 // color map
122 const int NCOLOR = 6;
123 struct ColorMap
124 {
125 G4double val;
126 G4double rgb[4];
127 } colormap[] = { { 0.0, { 1., 1., 1., 1. } }, // value, r, g, b, alpha
128 { 0.2, { 0., 0., 1., 1. } }, { 0.4, { 0., 1., 1., 1. } },
129 { 0.6, { 0., 1., 0., 1. } }, { 0.8, { 1., 1., 0., 1. } },
130 { 1.0, { 1., 0., 0., 1. } } };
131
132 // search
133 G4int during[2] = { 0, 0 };
134 for(int i = 1; i < NCOLOR; i++)
135 {
136 if(colormap[i].val >= value)
137 {
138 during[0] = i - 1;
139 during[1] = i;
140 break;
141 }
142 }
143
144 // interpolate
145 G4double a = std::fabs(value - colormap[during[0]].val);
146 G4double b = std::fabs(value - colormap[during[1]].val);
147 for(int i = 0; i < 4; i++)
148 {
149 color[i] =
150 (b * colormap[during[0]].rgb[i] + a * colormap[during[1]].rgb[i]) /
151 (colormap[during[1]].val - colormap[during[0]].val);
152 if(color[i] > 1.)
153 color[i] = 1.;
154 }
155}
156
158{
159 // G4cout << "++++++ " << fMinVal << " - " << fMaxVal << G4endl;
160 G4bool lmin = true, lmax = true;
161 if(fMinVal <= 0.)
162 lmin = false;
163 if(fMaxVal <= 0.)
164 lmax = false;
165 G4double min = 0.;
166 if(lmin)
167 min = std::log10(fMinVal);
168 G4double max = 0.;
169 if(lmax)
170 max = std::log10(fMaxVal);
171
172 G4double smin = -0.89, smax = smin + 0.05 * (_nPoint) *0.83, step = 0.001;
173 G4double c[4];
174 for(G4double y = smin; y < smax; y += step)
175 {
176 G4double ra = (y - smin) / (smax - smin), rb = 1. - ra;
177 G4Polyline line;
178 line.push_back(G4Point3D(-0.96, y, 0.));
179 line.push_back(G4Point3D(-0.91, y, 0.));
180 G4double val = std::pow(10., (ra * max + rb * min) / (ra + rb));
181 this->GetMapColor(val, c);
182 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0)
183 return;
184 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.)
185 continue;
186 G4Colour col(c[0], c[1], c[2]);
187 G4VisAttributes att(col);
188 line.SetVisAttributes(&att);
189 fVisManager->Draw2D(line);
190 }
191}
193{
194 G4bool lmin = true, lmax = true;
195 if(fMinVal <= 0.)
196 lmin = false;
197 if(fMaxVal <= 0.)
198 lmax = false;
199
200 G4double min = 0.;
201 if(lmin)
202 min = std::log10(fMinVal);
203 // if(min > 0.) min = std::floor(min);
204 // else min = std::ceil(min);
205
206 G4double max = 0.;
207 if(lmax)
208 max = std::log10(fMaxVal);
209 // if(max > 0.) max = std::ceil(max);
210 // else max = std::floor(max);
211
212 G4double c[4] = { 1., 1., 1., 1. };
213 G4Colour black(0., 0., 0.);
214 for(int n = 0; n < _nPoint; n++)
215 {
216 G4double a = n / (_nPoint - 1.), b = 1. - a;
217 G4double v = (a * max + b * min) / (a + b);
218
219 this->GetMapColor(std::pow(10., v), c);
220 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0)
221 return;
222 if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.)
223 continue;
224
225 // background color
226 for(int l = 0; l < 21; l++)
227 {
228 G4Polyline line;
229 line.push_back(G4Point3D(-0.908, -0.905 + 0.05 * n + 0.002 * l, 0.));
230 line.push_back(G4Point3D(-0.705, -0.905 + 0.05 * n + 0.002 * l, 0.));
231 G4VisAttributes attblack(black);
232 line.SetVisAttributes(&attblack);
233 fVisManager->Draw2D(line);
234 }
235 // text
236 // char cstring[80];
237 // std::sprintf(cstring, "%8.1e", std::pow(10., v));
238 // G4String value(cstring);
239 std::ostringstream oss;
240 oss << std::setw(8) << std::setprecision(1) << std::scientific
241 << std::pow(10., v);
242 std::string str = oss.str();
243 G4String value(str); //.c_str());
244 G4Text text(value, G4Point3D(-0.9, -0.9 + 0.05 * n, 0));
245 G4double size = 12.;
246 text.SetScreenSize(size);
247 // this->GetMapColor(std::pow(10., v), c);
248 G4Colour color(1., 1., 1.); // c[0], c[1], c[2], 1.);
249 G4VisAttributes att(color);
250 text.SetVisAttributes(&att);
251
252 fVisManager->Draw2D(text);
253 }
254
255 // draw ps name
256 // background
257 G4int lpsname = 20; // fPSName.size();
258 if(lpsname > 0)
259 {
260 for(int l = 0; l < 22; l++)
261 {
262 G4Polyline line;
263 line.push_back(G4Point3D(-0.9, -0.965 + 0.002 * l, 0.));
264 line.push_back(G4Point3D(-0.9 + 0.025 * lpsname, -0.965 + 0.002 * l, 0.));
265 G4VisAttributes attblack(black);
266 // G4VisAttributes attblack(G4Colour(.0, .5, .0));
267 line.SetVisAttributes(&attblack);
268 fVisManager->Draw2D(line);
269 }
270 // ps name
271 G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.));
272 G4double size = 12.;
273 txtpsname.SetScreenSize(size);
274 G4Colour color(1., 1., 1.);
275 G4VisAttributes att(color);
276 txtpsname.SetVisAttributes(&att);
277 fVisManager->Draw2D(txtpsname);
278 }
279
280 // draw unit
281 // background
282 G4int len = fPSUnit.size();
283 if(len > 0)
284 {
285 for(int l = 0; l < 21; l++)
286 {
287 G4Polyline line;
288 line.push_back(G4Point3D(-0.7, -0.9 + 0.002 * l, 0.));
289 line.push_back(G4Point3D(-0.7 + 0.3, -0.9 + 0.002 * l, 0.));
290 G4VisAttributes attblack(black);
291 // G4VisAttributes attblack(G4Colour(.5, .0, .0));
292 line.SetVisAttributes(&attblack);
293 fVisManager->Draw2D(line);
294 }
295 // unit
296 G4String psunit = "[" + fPSUnit + "]";
297 G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.));
298 G4double size = 12.;
299 txtunit.SetScreenSize(size);
300 G4Colour color(1., 1., 1.);
301 G4VisAttributes att(color);
302 txtunit.SetVisAttributes(&att);
303 fVisManager->Draw2D(txtunit);
304 }
305}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:34
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
virtual void GetMapColor(G4double val, G4double color[4])
G4ScoreLogColorMap(G4String mName)
virtual void DrawColorChartBar(G4int nPoint)
virtual void DrawColorChartText(G4int nPoint)
Definition: G4Text.hh:72
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:445
void SetScreenSize(G4double)
G4VVisManager * fVisManager
virtual void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:96
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