VisualizationAction.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file VisualizationAction.h
3 //
4 /// \author seligman@nevis.columbia.edu
5 ////////////////////////////////////////////////////////////////////////
6 /// VisualizationAction.cc
7 /// 19-Mar-2002 Bill Seligman
8 ///
9 /// Use UserAction to implement the standard visualization control for
10 /// a typical Geant4 job. Everything in this class comes from the
11 /// Geant4 examples; the only difference is that it's put into an
12 /// UserAction class.
13 ///
14 /// 25-Feb-2009 WGS: Revised for FMWK/LArSoft
15 
18 
19 #include "Geant4/G4Event.hh"
20 #include "Geant4/G4UImanager.hh"
21 #include "Geant4/G4VVisManager.hh"
22 #include "Geant4/G4TrajectoryContainer.hh"
23 #include "Geant4/G4ios.hh"
24 
25 
26 namespace larg4 {
27 
29  {
33 
34  }
35 
37  {
38  }
39 
41  {
42  // If graphics is ON
43  if(G4VVisManager::GetConcreteInstance()){
44  G4cout << "Geant4 visualisation is ON" << G4endl;
45  G4UImanager* UI = G4UImanager::GetUIpointer();
46  UI->ApplyCommand("/tracking/storeTrajectory 1");
47  UI->ApplyCommand("/vis/scene/notifyhandlers");
48  }
49  }
50 
52  {
53  // If graphics is ON
54  if (G4VVisManager::GetConcreteInstance())
55  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
56  }
57 
59  {}
60 
61  void VisualizationAction::EndOfEventAction(const G4Event* a_event)
62  {
63  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
64 
65  if (pVVisManager)
66  {
67  G4TrajectoryContainer* trajectoryContainer = a_event->GetTrajectoryContainer();
68  G4int n_trajectories = 0;
69  if (trajectoryContainer)
70  n_trajectories = trajectoryContainer->entries();
71 
72  for (G4int i=0; i < n_trajectories; i++)
73  {
74  G4VTrajectory* trajectory = (*trajectoryContainer)[i];
75 
76  // Only draw "interesting" trajectories, according to cuts
77  // and limits set by the user.
78 
79  G4bool drawThisTrack = false;
80  if ( trajectory->GetInitialMomentum().mag() > m_energyCutoff )
81  drawThisTrack = true;
82 
83  if ( ! m_drawNeutrals )
84  {
85  G4double charge = trajectory->GetCharge();
86  // electron-, muon-, and tau-neutrino codes:
87  if ( charge == 0 )
88  drawThisTrack = false;
89  }
90 
91  if ( drawThisTrack )
92  trajectory->DrawTrajectory();
93  //trajectory->DrawTrajectory(50);
94  }
95  }
96  }
97 
98 
99 
100 
101 } // 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 *)
Geant4 interface.
static constexpr double GeV
Definition: Units.h:28
virtual void BeginOfRunAction(const G4Run *)
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