GEMC  2.3
Geant4 Monte-Carlo Framework
dmesg_init.cc
Go to the documentation of this file.
1 
6 // G4 headers
7 #include "G4RunManager.hh"
8 #include "G4VisExecutive.hh"
9 #include "G4TrajectoryDrawByParticleID.hh"
10 
11 // gemc headers
12 #include "options.h"
13 #include "dmesg_init.h"
14 #include "string_utilities.h"
15 
19 vector<string> init_dmesg(goptions gemcOpt)
20 {
21  vector<string> commands;
22 
23  // Geant4 Process verbosity
24  double PHI_VERB = gemcOpt.optMap["PHY_VERBOSITY"].arg ;
25  int OVERL = (int) gemcOpt.optMap["CHECK_OVERLAPS"].arg ;
26  int DAWN_N = (int) gemcOpt.optMap["DAWN_N"].arg ;
27  int SAVE_ALL_MOTHERS = (int) gemcOpt.optMap["SAVE_ALL_MOTHERS"].arg ;
28 
29  char phi_verb[2];
30  sprintf(phi_verb, "%d", (int) PHI_VERB);
31  string proc_verb1 = "/process/setVerbose ";
32  string proc_verb2 = "/process/verbose ";
33  proc_verb1.append(phi_verb);
34  proc_verb1.append(" all");
35  proc_verb2.append(phi_verb);
36 
37 
38  // Geant4 Tracking Verbosity
39  double TRACK_VERB = gemcOpt.optMap["G4TRACK_VERBOSITY"].arg ;
40  char track_verb[2];
41  sprintf(track_verb, "%d", (int) TRACK_VERB);
42  string tra_verb = "/tracking/verbose ";
43  tra_verb.append(track_verb);
44  commands.push_back(tra_verb);
45 
46  // keep trajectories in the container if mother infos are required
47  if(SAVE_ALL_MOTHERS)
48  commands.push_back("/tracking/storeTrajectory 2");
49  else
50  commands.push_back("/tracking/storeTrajectory 0");
51 
52 
53  // sets all verbosity to zero
54  commands.push_back("/control/verbose 0");
55  commands.push_back("/geometry/navigator/verbose 0");
56  commands.push_back("/event/verbose 0");
57  commands.push_back("/run/verbose 0");
58  commands.push_back("/run/particle/verbose 0");
59  commands.push_back("/material/verbose 0");
60  commands.push_back(proc_verb1.c_str());
61  commands.push_back(proc_verb2.c_str());
62  commands.push_back("/process/eLoss/verbose 0");
63  commands.push_back("/vis/verbose 0");
64  commands.push_back("/vis/viewer/flush");
65  commands.push_back("/process/setVerbose 0 all");
66 
67 
68 
69 
70  if(OVERL>1)
71  commands.push_back("/geometry/test/grid_test 1");
72 
73  if(OVERL>2)
74  commands.push_back("/geometry/test/cylinder_test 1");
75 
76 
77  if(DAWN_N>0)
78  {
79  char dawn[10];
80  sprintf(dawn, "%d", DAWN_N);
81  string DN = "/run/beamOn ";
82  DN.append(dawn);
83 
84  commands.push_back("/vis/open DAWNFILE");
85  commands.push_back("/vis/drawVolume");
86  commands.push_back("/vis/scene/add/trajectories rich smooth");
87  commands.push_back("/vis/scene/add/hits");
88  commands.push_back("/vis/scene/endOfEventAction accumulate -1");
89  commands.push_back(DN);
90  }
91 
92 
93 
94  return commands;
95 }
96 
100 vector<string> init_dvmesg(goptions gemcOpt, G4VisManager *VM)
101 {
102  vector<string> commands;
103  commands.push_back("/vis/scene/create Hall-B");
104  double use_gui = gemcOpt.optMap["USE_GUI"].arg;
105  int HIGH_RES = (int) gemcOpt.optMap["HIGH_RES"].arg ;
106  vector<string> wpos = get_info(gemcOpt.optMap["GUIPOS"].args);
107 
108 
109  double newxpos = 700 + get_number(wpos[0]);
110  string newpos = "+" + stringify(newxpos) + "+" + wpos[1];
111 
112  // OpenGL immediate mode
113  if(use_gui==1)
114  commands.push_back("/vis/open OGLSQt " + gemcOpt.optMap["geometry"].args + newpos);
115  // openGL stored mode
116  else if(use_gui==2)
117  commands.push_back("/vis/open OGLIQt " + gemcOpt.optMap["geometry"].args + newpos);
118 
119  commands.push_back("/vis/viewer/set/autoRefresh 1");
120 
121  if(HIGH_RES==1)
122  {
123  commands.push_back("/vis/scene/add/trajectories rich smooth");
124  commands.push_back("/vis/viewer/set/background .8 .9 .98 1"); // 205, 230, 251 = CD, E6, FA
125  commands.push_back("/vis/scene/add/hits");
126  // This rendering can be problematic for some operation solid.
127  // Leaving this out for now, and letting G4 do what's more comfy.
128  // commands.push_back("/vis/viewer/set/lineSegmentsPerCircle 50");
129  commands.push_back("/vis/scene/endOfEventAction accumulate -1");
130 
131  // increasing visualisation storing
132  commands.push_back("/vis/ogl/set/displayListLimit 500000");
133  }
134  else
135  {
136  commands.push_back("/vis/scene/add/trajectories");
137  commands.push_back("/vis/scene/add/hits");
138  commands.push_back("/vis/scene/endOfEventAction accumulate -1");
139  }
140 
141 
142 
143 
144  // tracks colors
145  // these steps come from the user manual chapter Trajectory Drawing Models
146  // Create and configure a drawByParticleID model named gemcColorIDModel
147  // positive particles: RED
148  // negative particles: GREEN
149  // specific colors below
150  G4TrajectoryDrawByParticleID* gemcColorIDModel = new G4TrajectoryDrawByParticleID("gemcColorIDModel");
151  gemcColorIDModel->SetDefault("gray");
152  gemcColorIDModel->Set("neutron", "black");
153  gemcColorIDModel->Set("gamma", "blue");
154  gemcColorIDModel->Set("e-", "cyan");
155  gemcColorIDModel->Set("pi+", "magenta");
156  gemcColorIDModel->Set("pi-", "yellow");
157  gemcColorIDModel->Set("proton", G4Colour(0.95, 0.6, 0.3)); // orange
158 
159  G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
160  for(int i=0; i<particleTable->entries(); i++)
161  {
162  string pname = particleTable->GetParticleName(i);
163  double charge = particleTable->FindParticle(pname)->GetPDGCharge();
164  string pcolor ;
165  if(pname != "neutron" &&
166  pname != "gamma" &&
167  pname != "e-" &&
168  pname != "pi+" &&
169  pname != "pi-" &&
170  pname != "proton" )
171  {
172  if(charge>0)
173  gemcColorIDModel->Set(pname, "red");
174  if(charge==0)
175  gemcColorIDModel->Set(pname, "white");
176  if(charge<0)
177  gemcColorIDModel->Set(pname, "green");
178  }
179  }
180 
181  VM->RegisterModel(gemcColorIDModel);
182  VM->SelectTrajectoryModel(gemcColorIDModel->Name());
183 
184  // Draw by Process - interesting! But not working yet?
185  // commands.push_back("/vis/modeling/trajectories/create/drawByAttribute gemcColorAttributeModel");
186  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/setAttribute CPN");
187  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/verbose true");
188  //
189  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/addValue brem_key eBrem");
190  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/addValue annihil_key annihil");
191  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/addValue decay_key Decay");
192  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/addValue muIon_key muIoni");
193  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/addValue eIon_key eIoni");
194  //
195  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/brem_key/setLineColour yellow");
196  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/annihil_key/setLineColour yellow");
197  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/decay_key/setLineColour yellow");
198  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/eIon_key/setLineColour yellow");
199  // commands.push_back("/vis/modeling/trajectories/gemcColorAttributeModel/muIon_key/setLineColour yellow");
200 
201  return commands;
202 }
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
vector< string > init_dvmesg(goptions gemcOpt, G4VisManager *VM)
Initialization Routine for Visualization.
Definition: dmesg_init.cc:100
vector< string > get_info(string input, string chars)
get information from strings such as "5*GeV, 2*deg, 10*deg", parses out strings in second argument ...
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
string stringify(double x)
map< string, aopt > optMap
Options map.
Definition: options.h:75
vector< string > init_dmesg(goptions gemcOpt)
General Initialization Routine.
Definition: dmesg_init.cc:19