ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TrajectoriesModel.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4TrajectoriesModel.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 // John Allison 26th August 1998.
30 // Model which knows how to draw GEANT4 trajectories.
31 
32 #include "G4TrajectoriesModel.hh"
33 
34 #include "G4ModelingParameters.hh"
35 #include "G4VGraphicsScene.hh"
36 #include "G4RunManager.hh"
37 #ifdef G4MULTITHREADED
38 #include "G4MTRunManager.hh"
39 #endif
40 #include "G4Run.hh"
41 #include "G4Event.hh"
42 #include "G4AttDefStore.hh"
43 #include "G4AttValue.hh"
44 #include "G4AttDef.hh"
45 #include "G4AttCheck.hh"
46 #include "G4UIcommand.hh"
47 #include "G4VVisManager.hh"
48 
50 :fpCurrentTrajectory(0)
51 ,fRunID(-1)
52 ,fEventID(-1)
53 {
54  fType = "G4TrajectoriesModel";
55  fGlobalTag = "G4TrajectoriesModel for any type of trajectory";
57 }
58 
60 
62 
64 {
66 #ifdef G4MULTITHREADED
68  { runManager = G4MTRunManager::GetMasterRunManager(); }
69 #endif
70  const G4Run* currentRun = runManager->GetCurrentRun();
71  if (currentRun) {
72  fRunID = currentRun->GetRunID();
73  } else {
74  fRunID = -1;
75  return;
76  }
77 
78  const G4Event* event = fpMP->GetEvent();
79  if (event) {
80  fEventID = event->GetEventID();
81  } else {
82  fEventID = -1;
83  return;
84  }
85 
86  G4TrajectoryContainer* TC = event -> GetTrajectoryContainer ();
87  if (!TC) return;
88 
90  if (!pVVisManager) return;
91 
92  pVVisManager->BeginDraw();
93  // The use of Begin/EndDraw (optional methods to improve drawing
94  // speed) assumes all trajectories are drawn with the same
95  // transformation. If not, a fatal exception with be raised in
96  // G4VisManager::DrawT.
97  for (std::size_t iT = 0; iT < TC->entries(); ++iT) {
98  fpCurrentTrajectory = (*TC) [iT];
99  // Debug trajectory:
100  // fpCurrentTrajectory->ShowTrajectory(); G4cout << G4endl;
101  // Debug G4AttValues:
102  // G4TrajectoriesModelDebugG4AttValues(fpCurrentTrajectory);
104  sceneHandler.AddCompound (*fpCurrentTrajectory);
105  }
106  pVVisManager->EndDraw();
107 }
108 
109 const std::map<G4String,G4AttDef>* G4TrajectoriesModel::GetAttDefs() const
110 {
111  G4bool isNew;
112  std::map<G4String,G4AttDef>* store
113  = G4AttDefStore::GetInstance("G4TrajectoriesModel", isNew);
114  if (isNew) {
115  (*store)["RunID"] =
116  G4AttDef("RunID","Run ID","Physics","","G4int");
117  (*store)["EventID"] =
118  G4AttDef("EventID","Event ID","Physics","","G4int");
119  }
120  return store;
121 }
122 
123 std::vector<G4AttValue>* G4TrajectoriesModel::CreateCurrentAttValues() const
124 {
125  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
126  values->push_back
128  values->push_back
130  return values;
131 }
132 
133 // Debug material...
134 
135 #include "G4VTrajectoryPoint.hh"
136 
138 {
139  // Trajectory attributes
140  { // Scope bracket - allows re-use of names without compiler warnings.
141  std::vector<G4AttValue>* attValues = pTraj->CreateAttValues();
142  if (attValues) {
143  G4AttCheck attCheck(attValues, pTraj->GetAttDefs());
144  G4cout << "\nProvided G4Atts:\n" << attCheck;
145  if (attCheck.Check()) G4cout << "Error" << G4endl;
146  else {
147  std::vector<G4AttValue> standardValues;
148  std::map<G4String,G4AttDef> standardDefinitions;
149  attCheck.Standard(&standardValues, &standardDefinitions);
150  G4cout << "\nStandard G4Atts:\n"
151  << G4AttCheck(&standardValues, &standardDefinitions);
152  }
153  delete attValues;
154  }
155  }
156  // Trajectory point attributes
157  for (G4int i = 0; i < pTraj->GetPointEntries(); ++i) {
158  G4VTrajectoryPoint* aPoint = pTraj->GetPoint(i);
159  std::vector<G4AttValue>* attValues = aPoint->CreateAttValues();
160  if (attValues) {
161  G4AttCheck attCheck(attValues, aPoint->GetAttDefs());
162  G4cout << "\nProvided G4Atts:\n" << attCheck;
163  if (attCheck.Check()) G4cout << "Error" << G4endl;
164  else {
165  std::vector<G4AttValue> standardValues;
166  std::map<G4String,G4AttDef> standardDefinitions;
167  attCheck.Standard(&standardValues, &standardDefinitions);
168  G4cout << "\nStandard G4Atts:\n"
169  << G4AttCheck(&standardValues, &standardDefinitions);
170  }
171  delete attValues;
172  }
173  }
174 }