ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VScoreColorMap.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VScoreColorMap.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 "G4VScoreColorMap.hh"
30 #include <string>
31 #include <sstream>
32 #include <iomanip>
33 
34 #include "G4VVisManager.hh"
35 #include "G4VisAttributes.hh"
36 #include "G4Text.hh"
37 #include "G4Circle.hh"
38 #include "G4Polyline.hh"
39 #include "G4Colour.hh"
40 #include "G4Polyhedron.hh"
41 
43 :fName(mName),ifFloat(true),fMinVal(0.),fMaxVal(DBL_MAX),fVisManager(nullptr)
44 {;}
45 
47 {;}
48 
50 
52  if(!fVisManager) {
53  G4cerr << "G4VScoringMesh::DrawColorChart(): no visualization system" << G4endl;
54  return;
55  }
56 
57  DrawColorChartBar(_nPoint);
58  DrawColorChartText(_nPoint);
59 }
60 
62 
63  G4double min = this->GetMin();
64  G4double max = this->GetMax();
65  G4double smin = -0.89, smax = smin + 0.05*(_nPoint)*0.83, step=0.001;
66  G4double c[4];
67 
69 
70  for(G4double y = smin; y < smax; y+=step) {
71  G4double ra = (y-smin)/(smax-smin), rb = 1.-ra;
72  G4Polyline line;
73  line.push_back(G4Point3D(-0.96, y, 0.));
74  line.push_back(G4Point3D(-0.91, y, 0.));
75  this->GetMapColor((ra*max+rb*min)/(ra+rb), c);
76  G4Colour col(c[0], c[1], c[2]);
77  G4VisAttributes att(col);
78  line.SetVisAttributes(&att);
79  fVisManager->Draw2D(line);
80  }
81 
83 }
84 
86 
87  G4double min = this->GetMin();
88  G4double max = this->GetMax();
89  G4double c[4];
90  G4Colour black(0.1, 0.1, 0.1, 0.8);
91 
93 
94  for(int n = 0; n < _nPoint; n++) {
95  G4double a = n/(_nPoint-1.), b = 1.-a;
96  G4double v = (a*max + b*min)/(a+b);
97  // background color
98 
99  for(int l = 0; l < 21; l++) {
100  G4Polyline line;
101  line.push_back(G4Point3D(-0.9, -0.905+0.05*n+0.002*l, 0.));
102  line.push_back(G4Point3D(-0.75, -0.905+0.05*n+0.002*l, 0.));
103  G4VisAttributes attblack(black);
104  line.SetVisAttributes(&attblack);
105  fVisManager->Draw2D(line);
106  }
107 
108  // text
109  //char cstring[80];
110  //std::sprintf(cstring, "%8.2e", v);
111  //G4String value(cstring);
112  std::ostringstream oss;
113  oss << std::setw(8) << std::setprecision(1) << std::scientific << v;
114  std::string str = oss.str();
115  G4String value = str;//.c_str());
116 
117 
118  G4Text text(value, G4Point3D(-0.9, -0.9+0.05*n, 0.4));
119  G4double size = 12.;
120  text.SetScreenSize(size);
121  this->GetMapColor(v, c);
122  G4Colour color(c[0], c[1], c[2], 1.);
123  G4VisAttributes att(color);
124  text.SetVisAttributes(&att);
125 
126  fVisManager->Draw2D(text);
127  }
128 
129  // draw ps name
130  // background
131  G4double lpsname = 2.+fPSName.size()*0.95;
132  if(lpsname > 0) {
133  for(int l = 0; l < 22; l++) {
134  G4Polyline line;
135  line.push_back(G4Point3D(-0.92, -0.965+0.002*l, 0.));
136  line.push_back(G4Point3D(-0.92+0.025*lpsname, -0.965+0.002*l, 0.));
137  G4VisAttributes attblack(black);
138  //G4VisAttributes attblack(G4Colour(.5, .5, 1.));
139  line.SetVisAttributes(&attblack);
140  fVisManager->Draw2D(line);
141  }
142 
143  // ps name
144  G4Text txtpsname(fPSName, G4Point3D(-0.9, -0.96, 0.1));
145  G4double size = 12.;
146  txtpsname.SetScreenSize(size);
147  G4Colour color(1., 1., 1.);
148  G4VisAttributes att(color);
149  txtpsname.SetVisAttributes(&att);
150  fVisManager->Draw2D(txtpsname);
151 
152  }
153 
154  // draw unit
155  // background
156  G4double len = 2.+fPSUnit.size();
157  if(len > 0) {
158  for(int l = 0; l < 21; l++) {
159  G4Polyline line;
160  line.push_back(G4Point3D(-0.7, -0.9+0.002*l, 0.));
161  line.push_back(G4Point3D(-0.7+0.025*len, -0.9+0.002*l, 0.));
162  G4VisAttributes attblack(black);
163  //G4VisAttributes attblack(G4Colour(.5, .5, .5));
164  line.SetVisAttributes(&attblack);
165  fVisManager->Draw2D(line);
166  }
167 
168  // unit
169  G4String psunit = "[" + fPSUnit + "]";
170  G4Text txtunit(psunit, G4Point3D(-0.69, -0.9, 0.1));
171  G4double size = 12.;
172  txtunit.SetScreenSize(size);
173  G4Colour color(1., 1., 1.);
174  G4VisAttributes att(color);
175  txtunit.SetVisAttributes(&att);
176  fVisManager->Draw2D(txtunit);
177  }
178 
180 }
181 
182