ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
G4TheMTRayTracer.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4TheMTRayTracer.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 "
G4TheMTRayTracer.hh
"
30
#include "
G4SystemOfUnits.hh
"
31
#include "
G4RTMessenger.hh
"
32
#include "
G4VFigureFileMaker.hh
"
33
#include "
G4RTJpegMaker.hh
"
34
#include "
G4RTRun.hh
"
35
#include "
G4RTRunAction.hh
"
36
#include "
G4RTWorkerInitialization.hh
"
37
#include "
G4VRTScanner.hh
"
38
39
#include "
G4MTRunManager.hh
"
40
#include "
G4SDManager.hh
"
41
#include "
G4StateManager.hh
"
42
#include "
G4Colour.hh
"
43
#include "
G4VisAttributes.hh
"
44
#include "
G4UImanager.hh
"
45
#include "
G4UIcommand.hh
"
46
#include "
G4VVisManager.hh
"
47
48
G4TheMTRayTracer
*
G4TheMTRayTracer::theInstance
=
nullptr
;
49
50
G4TheMTRayTracer::G4TheMTRayTracer
(
G4VFigureFileMaker
* figMaker,
51
G4VRTScanner
* scanner)
52
:
G4TheRayTracer
(figMaker,scanner)
53
{
54
if
(!
theInstance
)
55
{
theInstance
=
this
; }
56
else
57
{
G4Exception
(
"G4TheMTRayTracer::G4TheMTRayTracer"
,
"VisRayTracer00100"
,
58
FatalException
,
"G4TheMTRayTracer has to be a singleton."
);}
59
theUserWorkerInitialization
= 0;
60
theRTWorkerInitialization
= 0;
61
theUserRunAction
= 0;
62
theRTRunAction
= 0;
63
}
64
65
G4TheMTRayTracer::~G4TheMTRayTracer
()
66
{
67
if
(
theRTWorkerInitialization
)
68
{
69
delete
theRTWorkerInitialization
;
70
theRTWorkerInitialization
= 0;
71
}
72
if
(
theRTRunAction
)
73
{
74
delete
theRTRunAction
;
75
theRTRunAction
= 0;
76
}
77
}
78
79
void
G4TheMTRayTracer::Trace
(
const
G4String
& fileName)
80
{
81
G4StateManager
* theStateMan =
G4StateManager::GetStateManager
();
82
G4ApplicationState
currentState = theStateMan->
GetCurrentState
();
83
if
(currentState!=
G4State_Idle
)
84
{
85
G4cerr
<<
"Illegal application state <"
<< theStateMan->
GetStateString
(currentState)
86
<<
"> - Trace() ignored. "
<<
G4endl
;
87
return
;
88
}
89
90
if
(!
theFigMaker
)
91
{
92
G4cerr
<<
"Figure file maker class is not specified - Trace() ignored."
<<
G4endl
;
93
return
;
94
}
95
96
G4UImanager
* UI =
G4UImanager::GetUIpointer
();
97
G4int
storeTrajectory = UI->
GetCurrentIntValue
(
"/tracking/storeTrajectory"
);
98
UI->
ApplyCommand
(
"/tracking/storeTrajectory 1"
);
99
100
G4ThreeVector
tmpVec =
targetPosition
-
eyePosition
;
101
eyeDirection
= tmpVec.
unit
();
102
G4int
nPixel =
nColumn
*
nRow
;
103
colorR
=
new
unsigned
char
[nPixel];
104
colorG
=
new
unsigned
char
[nPixel];
105
colorB
=
new
unsigned
char
[nPixel];
106
unsigned
char
defR = (
unsigned
char)(
G4int
(255*
backgroundColour
.
GetRed
()));
107
unsigned
char
defG = (
unsigned
char)(
G4int
(255*
backgroundColour
.
GetGreen
()));
108
unsigned
char
defB = (
unsigned
char)(
G4int
(255*
backgroundColour
.
GetBlue
()));
109
for
(
G4int
ii=0;ii<nPixel;++ii)
110
{
111
colorR
[ii] = defR;
112
colorG
[ii] = defG;
113
colorB
[ii] = defB;
114
}
115
116
G4bool
succeeded =
CreateBitMap
();
117
if
(succeeded)
118
{
CreateFigureFile
(fileName); }
119
else
120
{
G4cerr
<<
"Could not create figure file"
<<
G4endl
;
121
G4cerr
<<
"You might set the eye position outside of the world volume"
<<
G4endl
; }
122
123
G4String
str =
"/tracking/storeTrajectory "
+
G4UIcommand::ConvertToString
(storeTrajectory);
124
UI->
ApplyCommand
(str);
125
126
delete
[]
colorR
;
127
delete
[]
colorG
;
128
delete
[]
colorB
;
129
}
130
131
void
G4TheMTRayTracer::StoreUserActions
()
132
{
133
G4MTRunManager
* mrm =
G4MTRunManager::GetMasterRunManager
();
134
theUserWorkerInitialization
= mrm->
GetUserWorkerInitialization
();
135
theUserRunAction
= mrm->
GetUserRunAction
();
136
137
if
(!
theRTWorkerInitialization
)
theRTWorkerInitialization
=
new
G4RTWorkerInitialization
();
138
if
(!
theRTRunAction
)
theRTRunAction
=
new
G4RTRunAction
();
139
140
mrm->
SetUserInitialization
(
theRTWorkerInitialization
);
141
mrm->
SetUserAction
(
theRTRunAction
);
142
}
143
144
void
G4TheMTRayTracer::RestoreUserActions
()
145
{
146
G4MTRunManager
* mrm =
G4MTRunManager::GetMasterRunManager
();
147
mrm->
SetUserInitialization
(const_cast<G4UserWorkerInitialization*>(
theUserWorkerInitialization
));
148
mrm->
SetUserAction
(const_cast<G4UserRunAction*>(
theUserRunAction
));
149
}
150
151
G4bool
G4TheMTRayTracer::CreateBitMap
()
152
{
153
G4VVisManager
* visMan =
G4VVisManager::GetConcreteInstance
();
154
visMan->
IgnoreStateChanges
(
true
);
155
StoreUserActions
();
156
157
// Event loop
158
G4MTRunManager
* mrm =
G4MTRunManager::GetMasterRunManager
();
159
G4int
nEvent =
nRow
*
nColumn
;
162
G4String
str =
"/run/beamOn "
+
G4UIcommand::ConvertToString
(nEvent);
163
G4UImanager::GetUIpointer
()->
ApplyCommand
(str);
164
165
RestoreUserActions
();
166
visMan->
IgnoreStateChanges
(
false
);
167
168
const
G4RTRun
* theRun =
static_cast<
const
G4RTRun
*
>
(mrm->
GetCurrentRun
());
169
if
(!theRun)
return
false
;
170
171
G4THitsMap<G4Colour>
* colMap = theRun->
GetMap
();
172
auto
itr = colMap->
GetMap
()->cbegin();
173
for
(;itr!=colMap->
GetMap
()->cend();++itr)
174
{
175
G4int
key = itr->first;
176
G4Colour
*
col
= itr->second;
177
colorR
[key] = (
unsigned
char)(
G4int
(255*col->
GetRed
()));
178
colorG
[key] = (
unsigned
char)(
G4int
(255*col->
GetGreen
()));
179
colorB
[key] = (
unsigned
char)(
G4int
(255*col->
GetBlue
()));
180
}
181
182
theScanner
->
Initialize
(
nRow
,nColumn);
183
G4int
iRow, iColumn;
184
while
(
theScanner
->
Coords
(iRow,iColumn))
185
{
186
G4int
iCoord = iRow * nColumn + iColumn;
187
theScanner
->
Draw
(
colorR
[iCoord],
colorG
[iCoord],
colorB
[iCoord]);
188
}
189
190
return
true
;
191
}
192
geant4
tree
geant4-10.6-release
source
visualization
RayTracer
src
G4TheMTRayTracer.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:58
using
1.8.2 with
ECCE GitHub integration