Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4ScoreLogColorMap.cc
이 파일의 문서화 페이지로 가기
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 // $Id: G4ScoreLogColorMap.cc 89031 2015-03-18 08:40:48Z gcosmo $
28 //
29 
30 #include "G4ScoreLogColorMap.hh"
31 #include <cmath>
32 #include <string>
33 #include <sstream>
34 #include <iomanip>
35 
36 
37 #include "G4VVisManager.hh"
38 #include "G4VisAttributes.hh"
39 #include "G4Text.hh"
40 #include "G4Circle.hh"
41 #include "G4Polyline.hh"
42 #include "G4Colour.hh"
43 
45 :G4VScoreColorMap(mName)
46 {;}
47 
49 {;}
50 
51 #include "G4UIcommand.hh"
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) {
97  if(fMinVal > 0.) logmin = std::log10(fMinVal);
98  else logmin =0.;
99  }
100  if(lmax) logmax = std::log10(fMaxVal);
101  if(lval) logval = std::log10(val);
102  G4double value = 0.;
103  if(lmax) value = (logval-logmin)/(logmax-logmin);
104 
105  if(value > 1.) {value=1.;}
106  if(value < 0.) {value=0.;}
107 
108  // color map
109  const int NCOLOR = 6;
110  struct ColorMap {
111  G4double val;
112  G4double rgb[4];
113  } colormap[] = {{0.0, {1., 1., 1., 1.}}, // value, r, g, b, alpha
114  {0.2, {0., 0., 1., 1.}},
115  {0.4, {0., 1., 1., 1.}},
116  {0.6, {0., 1., 0., 1.}},
117  {0.8, {1., 1., 0., 1.}},
118  {1.0, {1., 0., 0., 1.}}};
119 
120  // search
121  G4int during[2] = {0, 0};
122  for(int i = 1; i < NCOLOR; i++) {
123  if(colormap[i].val >= value) {
124  during[0] = i-1;
125  during[1] = i;
126  break;
127  }
128  }
129 
130  // interpolate
131  G4double a = std::fabs(value - colormap[during[0]].val);
132  G4double b = std::fabs(value - colormap[during[1]].val);
133  for(int i = 0; i < 4; i++) {
134  color[i] = (b*colormap[during[0]].rgb[i] + a*colormap[during[1]].rgb[i])
135  /(colormap[during[1]].val - colormap[during[0]].val);
136  if(color[i] > 1.) color[i] = 1.;
137  }
138 
139 }
140 
141 
143 
144  //G4cout << "++++++ " << fMinVal << " - " << fMaxVal << G4endl;
145  G4bool lmin = true, lmax = true;
146  if(fMinVal <= 0.) lmin = false;
147  if(fMaxVal <= 0.) lmax = false;
148  G4double min = 0.;
149  if(lmin) min = std::log10(fMinVal);
150  G4double max = 0.;
151  if(lmax) max = std::log10(fMaxVal);
152 
153  G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
154  G4double c[4];
155  for(G4double y = smin; y < smax; y+=step) {
156  G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
157  G4Polyline line;
158  line.push_back(G4Point3D(-0.96, y, 0.));
159  line.push_back(G4Point3D(-0.91, y, 0.));
160  G4double val = std::pow(10., (ra*max+rb*min)/(ra+rb));
161  this->GetMapColor(val, c);
162  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
163  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
164  G4Colour col(c[0], c[1], c[2]);
165  G4VisAttributes att(col);
166  line.SetVisAttributes(&att);
167  fVisManager->Draw2D(line);
168  }
169 
170 }
172  G4bool lmin = true, lmax = true;
173  if(fMinVal <= 0.) lmin = false;
174  if(fMaxVal <= 0.) lmax = false;
175 
176  G4double min = 0.;
177  if(lmin) min = std::log10(fMinVal);
178  //if(min > 0.) min = std::floor(min);
179  //else min = std::ceil(min);
180 
181  G4double max = 0.;
182  if(lmax) max = std::log10(fMaxVal);
183  //if(max > 0.) max = std::ceil(max);
184  //else max = std::floor(max);
185 
186  G4double c[4] = {1., 1., 1., 1.};
187  G4Colour black(0., 0., 0.);
188  for(int n = 0; n < _nPoint; n++) {
189  G4double a = n/(_nPoint-1.), b = 1.-a;
190  G4double v = (a*max + b*min)/(a+b);
191 
192  this->GetMapColor(std::pow(10., v), c);
193  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0) return;
194  if(c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == -1.) continue;
195 
196  // background color
197  for(int l = 0; l < 21; l++) {
198  G4Polyline line;
199  line.push_back(G4Point3D(-0.908, -0.905+0.05*n+0.002*l, 0.));
200  line.push_back(G4Point3D(-0.705, -0.905+0.05*n+0.002*l, 0.));
201  G4VisAttributes attblack(black);
202  line.SetVisAttributes(&attblack);
203  fVisManager->Draw2D(line);
204  }
205  // text
206  //char cstring[80];
207  //std::sprintf(cstring, "%8.1e", std::pow(10., v));
208  //G4String value(cstring);
209  std::ostringstream oss;
210  oss << std::setw(8) << std::setprecision(1) << std::scientific << std::pow(10., v);
211  std::string str = oss.str();
212  G4String value(str);//.c_str());
213  G4Text text(value, G4Point3D(-0.9, -0.9+0.05*n, 0));
214  G4double size = 12.;
215  text.SetScreenSize(size);
216  //this->GetMapColor(std::pow(10., v), c);
217  G4Colour color(1.,1.,1.);//c[0], c[1], c[2], 1.);
218  G4VisAttributes att(color);
219  text.SetVisAttributes(&att);
220 
221  fVisManager->Draw2D(text);
222  }
223 
224 
225  // draw ps name
226  // background
227  G4int lpsname = 20;// fPSName.size();
228  if(lpsname > 0) {
229  for(int l = 0; l < 22; l++) {
230  G4Polyline line;
231  line.push_back(G4Point3D(-0.9, -0.965+0.002*l, 0.));
232  line.push_back(G4Point3D(-0.9+0.025*lpsname, -0.965+0.002*l, 0.));
233  G4VisAttributes attblack(black);
234  //G4VisAttributes attblack(G4Colour(.0, .5, .0));
235  line.SetVisAttributes(&attblack);
236  fVisManager->Draw2D(line);
237  }
238  // ps name
239  G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.));
240  G4double size = 12.;
241  txtpsname.SetScreenSize(size);
242  G4Colour color(1., 1., 1.);
243  G4VisAttributes att(color);
244  txtpsname.SetVisAttributes(&att);
245  fVisManager->Draw2D(txtpsname);
246  }
247 
248 
249 
250  // draw unit
251  // background
252  G4int len = fPSUnit.size();
253  if(len > 0) {
254  for(int l = 0; l < 21; l++) {
255  G4Polyline line;
256  line.push_back(G4Point3D(-0.7, -0.9+0.002*l, 0.));
257  line.push_back(G4Point3D(-0.7+0.3, -0.9+0.002*l, 0.));
258  G4VisAttributes attblack(black);
259  //G4VisAttributes attblack(G4Colour(.5, .0, .0));
260  line.SetVisAttributes(&attblack);
261  fVisManager->Draw2D(line);
262  }
263  // unit
264  G4String psunit = "[" + fPSUnit + "]";
265  G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.));
266  G4double size = 12.;
267  txtunit.SetScreenSize(size);
268  G4Colour color(1., 1., 1.);
269  G4VisAttributes att(color);
270  txtunit.SetVisAttributes(&att);
271  fVisManager->Draw2D(txtunit);
272  }
273 
274 }
const XML_Char int len
Definition: expat.h:262
T max(const T t1, const T t2)
brief Return the largest of the two arguments
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
Float_t y
Definition: compare.C:6
virtual void DrawColorChartText(G4int nPoint)
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
G4ScoreLogColorMap(G4String mName)
G4VVisManager * fVisManager
void SetScreenSize(G4double)
virtual void GetMapColor(G4double val, G4double color[4])
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
Definition: G4Text.hh:73
const XML_Char int const XML_Char * value
Definition: expat.h:331
Int_t col[ntarg]
Definition: Style.C:29
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:374
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
const G4int smax
virtual void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
Char_t n[5]
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
virtual void DrawColorChartBar(G4int nPoint)
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
T min(const T t1, const T t2)
brief Return the smallest of the two arguments