Geant4-11
Public Member Functions | Protected Attributes
G4ScoreLogColorMap Class Reference

#include <G4ScoreLogColorMap.hh>

Inheritance diagram for G4ScoreLogColorMap:
G4VScoreColorMap

Public Member Functions

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

Protected Attributes

G4double fMaxVal
 
G4double fMinVal
 
G4String fName
 
G4String fPSName
 
G4String fPSUnit
 
G4VVisManagerfVisManager
 
G4bool ifFloat
 

Detailed Description

Definition at line 35 of file G4ScoreLogColorMap.hh.

Constructor & Destructor Documentation

◆ G4ScoreLogColorMap()

G4ScoreLogColorMap::G4ScoreLogColorMap ( G4String  mName)

Definition at line 42 of file G4ScoreLogColorMap.cc.

43 : G4VScoreColorMap(mName)
44{
45 ;
46}
G4VScoreColorMap(G4String mName)

◆ ~G4ScoreLogColorMap()

G4ScoreLogColorMap::~G4ScoreLogColorMap ( )
virtual

Definition at line 48 of file G4ScoreLogColorMap.cc.

48{ ; }

Member Function Documentation

◆ DrawColorChart()

void G4VScoreColorMap::DrawColorChart ( G4int  nPoint = 5)
virtualinherited

Definition at line 54 of file G4VScoreColorMap.cc.

55{
57 if(!fVisManager)
58 {
59 G4cerr << "G4VScoringMesh::DrawColorChart(): no visualization system"
60 << G4endl;
61 return;
62 }
63
64 DrawColorChartBar(_nPoint);
65 DrawColorChartText(_nPoint);
66}
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
virtual void DrawColorChartText(G4int nPoint)
G4VVisManager * fVisManager
virtual void DrawColorChartBar(G4int nPoint)
static G4VVisManager * GetConcreteInstance()

References G4VScoreColorMap::DrawColorChartBar(), G4VScoreColorMap::DrawColorChartText(), G4VScoreColorMap::fVisManager, G4cerr, G4endl, and G4VVisManager::GetConcreteInstance().

Referenced by G4ScoringBox::Draw(), G4ScoringCylinder::Draw(), G4ScoringBox::DrawColumn(), and G4ScoringCylinder::DrawColumn().

◆ DrawColorChartBar()

void G4ScoreLogColorMap::DrawColorChartBar ( G4int  nPoint)
virtual

Reimplemented from G4VScoreColorMap.

Definition at line 157 of file G4ScoreLogColorMap.cc.

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}
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])
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

References G4VVisManager::Draw2D(), G4VScoreColorMap::fMaxVal, G4VScoreColorMap::fMinVal, G4VScoreColorMap::fVisManager, GetMapColor(), G4INCL::Math::max(), G4INCL::Math::min(), and G4Visible::SetVisAttributes().

◆ DrawColorChartText()

void G4ScoreLogColorMap::DrawColorChartText ( G4int  nPoint)
virtual

Reimplemented from G4VScoreColorMap.

Definition at line 192 of file G4ScoreLogColorMap.cc.

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}
int G4int
Definition: G4Types.hh:85
Definition: G4Text.hh:72

References G4VVisManager::Draw2D(), G4VScoreColorMap::fMaxVal, G4VScoreColorMap::fMinVal, G4VScoreColorMap::fPSName, G4VScoreColorMap::fPSUnit, G4VScoreColorMap::fVisManager, GetMapColor(), G4INCL::Math::max(), G4INCL::Math::min(), CLHEP::detail::n, G4VMarker::SetScreenSize(), and G4Visible::SetVisAttributes().

◆ 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 {
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}
@ 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:445

References G4UIcommand::ConvertToString(), G4VScoreColorMap::fMaxVal, G4VScoreColorMap::fMinVal, G4Exception(), and JustWarning.

Referenced by DrawColorChartBar(), and DrawColorChartText().

◆ GetMax()

G4double G4VScoreColorMap::GetMax ( ) const
inlineinherited

◆ GetMin()

G4double G4VScoreColorMap::GetMin ( ) const
inlineinherited

◆ GetName()

G4String G4VScoreColorMap::GetName ( ) const
inlineinherited

◆ IfFloatMinMax()

G4bool G4VScoreColorMap::IfFloatMinMax ( ) const
inlineinherited

◆ SetFloatingMinMax()

void G4VScoreColorMap::SetFloatingMinMax ( G4bool  vl = true)
inlineinherited

Definition at line 47 of file G4VScoreColorMap.hh.

47{ ifFloat = vl; }

References G4VScoreColorMap::ifFloat.

Referenced by G4ScoringMessenger::SetNewValue().

◆ SetMinMax()

void G4VScoreColorMap::SetMinMax ( G4double  minVal,
G4double  maxVal 
)
inlineinherited

Definition at line 49 of file G4VScoreColorMap.hh.

50 {
51 if(minVal >= maxVal)
52 {
53 G4cerr << "WARNING: G4VScoreColoMap::SetMinMax() : minimum is larger "
54 "than or equal to maximum. Verify values you set, ["
55 << minVal << ", " << maxVal << "]" << G4endl;
56 fMinVal = maxVal;
57 fMaxVal = minVal;
58 }
59 else
60 {
61 fMinVal = minVal;
62 fMaxVal = maxVal;
63 }
64 }

References G4VScoreColorMap::fMaxVal, G4VScoreColorMap::fMinVal, G4cerr, and G4endl.

Referenced by G4ScoringBox::Draw(), G4ScoringCylinder::Draw(), G4ScoringBox::DrawColumn(), G4ScoringCylinder::DrawColumn(), and G4ScoringMessenger::SetNewValue().

◆ SetPSName()

void G4VScoreColorMap::SetPSName ( G4String psName)
inlineinherited

◆ SetPSUnit()

void G4VScoreColorMap::SetPSUnit ( G4String unit)
inlineinherited

Field Documentation

◆ fMaxVal

G4double G4VScoreColorMap::fMaxVal
protectedinherited

◆ fMinVal

G4double G4VScoreColorMap::fMinVal
protectedinherited

◆ fName

G4String G4VScoreColorMap::fName
protectedinherited

Definition at line 79 of file G4VScoreColorMap.hh.

Referenced by G4VScoreColorMap::GetName().

◆ fPSName

G4String G4VScoreColorMap::fPSName
protectedinherited

◆ fPSUnit

G4String G4VScoreColorMap::fPSUnit
protectedinherited

◆ fVisManager

G4VVisManager* G4VScoreColorMap::fVisManager
protectedinherited

◆ ifFloat

G4bool G4VScoreColorMap::ifFloat
protectedinherited

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