Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TrajectoriesModel.cc
Go to the documentation of this file.
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// John Allison 26th August 1998.
30// Model which knows how to draw GEANT4 trajectories.
31
33
35#include "G4VGraphicsScene.hh"
36#include "G4RunManager.hh"
38#include "G4Run.hh"
39#include "G4Event.hh"
40#include "G4AttDefStore.hh"
41#include "G4AttValue.hh"
42#include "G4AttDef.hh"
43#include "G4AttCheck.hh"
44#include "G4UIcommand.hh"
45#include "G4VVisManager.hh"
46#include "G4Text.hh"
47#include "G4SystemOfUnits.hh"
48
49#include <sstream>
50
52:fpCurrentTrajectory(0)
53,fRunID(-1)
54,fEventID(-1)
55{
56 fType = "G4TrajectoriesModel";
57 fGlobalTag = "G4TrajectoriesModel for any type of trajectory";
59}
60
62
64
66{
68 const G4Run* currentRun = runManager->GetCurrentRun();
69 if(currentRun)
70 {
71 fRunID = currentRun->GetRunID();
72 }
73 else
74 {
75 fRunID = -1;
76 return;
77 }
78
79 const G4Event* event = fpMP->GetEvent();
80 if (event) {
81 fEventID = event->GetEventID();
82 } else {
83 fEventID = -1;
84 return;
85 }
86
88 if (!pVVisManager) return;
89
90 G4TrajectoryContainer* TC = event -> GetTrajectoryContainer ();
91 if (!TC) return;
92
93 // Need to set the static "current" modeling parameters separately
95
96 for (std::size_t iT = 0; iT < TC->entries(); ++iT) {
97 fpCurrentTrajectory = (*TC) [iT];
98 // Debug trajectory:
99 // fpCurrentTrajectory->ShowTrajectory(); G4cout << G4endl;
100 // Debug G4AttValues:
101 // G4TrajectoriesModelDebugG4AttValues(fpCurrentTrajectory);
102 if (fpCurrentTrajectory)
103 sceneHandler.AddCompound (*fpCurrentTrajectory);
104 }
105
106 // If time windowing is active, display head time if requested
107 const auto& timeParameters = fpMP->GetTimeParameters();
108 if (timeParameters.fDisplayHeadTime && timeParameters.fStartTime >= 0.) {
109 const auto& tp = timeParameters; // Alias
110 std::ostringstream oss;
111 oss << std::fixed << std::setprecision(2) << timeParameters.fEndTime/ns << " ns";
112 G4Text headTime(oss.str());
113 headTime.SetLayout(G4Text::centre);
114 headTime.SetScreenSize(tp.fDisplayHeadTimeSize);
115 headTime.SetPosition(G4Point3D(tp.fDisplayHeadTimeX, tp.fDisplayHeadTimeY, 0.));
116 G4VisAttributes headTimeVisAtts
117 (G4Colour(tp.fDisplayHeadTimeRed, tp.fDisplayHeadTimeGreen, tp.fDisplayHeadTimeBlue));
118 headTime.SetVisAttributes(&headTimeVisAtts);
119 pVVisManager->Draw2D(headTime);
120 }
121}
122
123const std::map<G4String,G4AttDef>* G4TrajectoriesModel::GetAttDefs() const
124{
125 G4bool isNew;
126 std::map<G4String,G4AttDef>* store
127 = G4AttDefStore::GetInstance("G4TrajectoriesModel", isNew);
128 if (isNew) {
129 (*store)["RunID"] =
130 G4AttDef("RunID","Run ID","Physics","","G4int");
131 (*store)["EventID"] =
132 G4AttDef("EventID","Event ID","Physics","","G4int");
133 }
134 return store;
135}
136
137std::vector<G4AttValue>* G4TrajectoriesModel::CreateCurrentAttValues() const
138{
139 std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
140 values->push_back
141 (G4AttValue("RunID",G4UIcommand::ConvertToString(fRunID),""));
142 values->push_back
143 (G4AttValue("EventID",G4UIcommand::ConvertToString(fEventID),""));
144 return values;
145}
146
147// Debug material...
148
149#include "G4VTrajectoryPoint.hh"
150
152{
153 // Trajectory attributes
154 { // Scope bracket - allows re-use of names without compiler warnings.
155 std::vector<G4AttValue>* attValues = pTraj->CreateAttValues();
156 if (attValues) {
157 G4AttCheck attCheck(attValues, pTraj->GetAttDefs());
158 G4cout << "\nProvided G4Atts:\n" << attCheck;
159 if (attCheck.Check()) G4cout << "Error" << G4endl;
160 else {
161 std::vector<G4AttValue> standardValues;
162 std::map<G4String,G4AttDef> standardDefinitions;
163 attCheck.Standard(&standardValues, &standardDefinitions);
164 G4cout << "\nStandard G4Atts:\n"
165 << G4AttCheck(&standardValues, &standardDefinitions);
166 }
167 delete attValues;
168 }
169 }
170 // Trajectory point attributes
171 for (G4int i = 0; i < pTraj->GetPointEntries(); ++i) {
172 G4VTrajectoryPoint* aPoint = pTraj->GetPoint(i);
173 std::vector<G4AttValue>* attValues = aPoint->CreateAttValues();
174 if (attValues) {
175 G4AttCheck attCheck(attValues, aPoint->GetAttDefs());
176 G4cout << "\nProvided G4Atts:\n" << attCheck;
177 if (attCheck.Check()) G4cout << "Error" << G4endl;
178 else {
179 std::vector<G4AttValue> standardValues;
180 std::map<G4String,G4AttDef> standardDefinitions;
181 attCheck.Standard(&standardValues, &standardDefinitions);
182 G4cout << "\nStandard G4Atts:\n"
183 << G4AttCheck(&standardValues, &standardDefinitions);
184 }
185 delete attValues;
186 }
187 }
188}
HepGeom::Point3D< G4double > G4Point3D
Definition G4Point3D.hh:34
void G4TrajectoriesModelDebugG4AttValues(const G4VTrajectory *)
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4bool Check(const G4String &leader="") const
G4bool Standard(std::vector< G4AttValue > *standardValues, std::map< G4String, G4AttDef > *standardDefinitions) const
static G4RunManager * GetMasterRunManager()
const G4Run * GetCurrentRun() const
Definition G4Run.hh:48
G4int GetRunID() const
Definition G4Run.hh:82
void SetLayout(Layout)
@ centre
Definition G4Text.hh:76
virtual void DescribeYourselfTo(G4VGraphicsScene &)
std::vector< G4AttValue > * CreateCurrentAttValues() const
const std::map< G4String, G4AttDef > * GetAttDefs() const
std::size_t entries() const
static G4String ConvertToString(G4bool boolVal)
virtual void AddCompound(const G4VTrajectory &)=0
void SetScreenSize(G4double)
void SetPosition(const G4Point3D &)
G4String fGlobalDescription
Definition G4VModel.hh:106
static void SetCurrentModelingParameters(const G4ModelingParameters *)
Definition G4VModel.cc:63
G4String fType
Definition G4VModel.hh:104
const G4ModelingParameters * fpMP
Definition G4VModel.hh:108
G4String fGlobalTag
Definition G4VModel.hh:105
virtual std::vector< G4AttValue > * CreateAttValues() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
virtual G4int GetPointEntries() const =0
virtual std::vector< G4AttValue > * CreateAttValues() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())=0
static G4VVisManager * GetConcreteInstance()
void SetVisAttributes(const G4VisAttributes *)
Definition G4Visible.cc:108
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)
#define ns(x)
Definition xmltok.c:1649