LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
VisualizationAction.cxx
Go to the documentation of this file.
1 //
15 
18 
20 
21 #include "Geant4/G4Event.hh"
22 #include "Geant4/G4TrajectoryContainer.hh"
23 #include "Geant4/G4UImanager.hh"
24 #include "Geant4/G4VVisManager.hh"
25 #include "Geant4/G4ios.hh"
26 
27 namespace larg4 {
28 
30  {
32  m_energyCutoff = lgp->VisualizationEnergyCut() * CLHEP::GeV;
34  }
35 
37 
39  {
40  // If graphics is ON
41  if (G4VVisManager::GetConcreteInstance()) {
42  G4cout << "Geant4 visualisation is ON" << G4endl;
43  G4UImanager* UI = G4UImanager::GetUIpointer();
44  UI->ApplyCommand("/tracking/storeTrajectory 1");
45  UI->ApplyCommand("/vis/scene/notifyhandlers");
46  }
47  }
48 
50  {
51  // If graphics is ON
52  if (G4VVisManager::GetConcreteInstance())
53  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
54  }
55 
57 
58  void VisualizationAction::EndOfEventAction(const G4Event* a_event)
59  {
60  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
61 
62  if (pVVisManager) {
63  G4TrajectoryContainer* trajectoryContainer = a_event->GetTrajectoryContainer();
64  G4int n_trajectories = 0;
65  if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();
66 
67  for (G4int i = 0; i < n_trajectories; i++) {
68  G4VTrajectory* trajectory = (*trajectoryContainer)[i];
69 
70  // Only draw "interesting" trajectories, according to cuts
71  // and limits set by the user.
72 
73  G4bool drawThisTrack = false;
74  if (trajectory->GetInitialMomentum().mag() > m_energyCutoff) drawThisTrack = true;
75 
76  if (!m_drawNeutrals) {
77  G4double charge = trajectory->GetCharge();
78  // electron-, muon-, and tau-neutrino codes:
79  if (charge == 0) drawThisTrack = false;
80  }
81 
82  if (drawThisTrack) trajectory->DrawTrajectory();
83  //trajectory->DrawTrajectory(50);
84  }
85  }
86  }
87 
88 } // namespace LArG4
Store parameters for running LArG4.
double VisualizationEnergyCut() const
G4bool m_drawNeutrals
Whether or not to draw neutral tracks (default is no).
virtual void BeginOfEventAction(const G4Event *)
G4UserEventAction interfaces.
Geant4 interface.
virtual void BeginOfRunAction(const G4Run *)
G4UserRunAction interfaces.
virtual void EndOfEventAction(const G4Event *)
virtual void EndOfRunAction(const G4Run *)
G4double m_energyCutoff
Don&#39;t draw particles with energies less than this cut.
bool DrawNeutrals() const