ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ScoreLogColorMap.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
28 
29 #include "G4ScoreLogColorMap.hh"
30 #include <cmath>
31 #include <string>
32 #include <sstream>
33 #include <iomanip>
34 
35 
36 #include "G4VVisManager.hh"
37 #include "G4VisAttributes.hh"
38 #include "G4Text.hh"
39 #include "G4Circle.hh"
40 #include "G4Polyline.hh"
41 #include "G4Colour.hh"
42 
44 :G4VScoreColorMap(mName)
45 {;}
46 
48 {;}
49 
50 #include "G4UIcommand.hh"
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 }
139 
140 
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 }
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 }