All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "art/Framework/Services/Registry/ServiceHandle.h"
20 
21 #include "Geant4/G4Event.hh"
22 #include "Geant4/G4UImanager.hh"
23 #include "Geant4/G4VVisManager.hh"
24 #include "Geant4/G4TrajectoryContainer.hh"
25 #include "Geant4/G4ios.hh"
26 
27 
28 namespace larg4 {
29 
31  {
32  art::ServiceHandle<sim::LArG4Parameters const> lgp;
33  m_energyCutoff = lgp->VisualizationEnergyCut()*CLHEP::GeV;
34  m_drawNeutrals = lgp->DrawNeutrals();
35 
36  }
37 
39  {
40  }
41 
43  {
44  // If graphics is ON
45  if(G4VVisManager::GetConcreteInstance()){
46  G4cout << "Geant4 visualisation is ON" << G4endl;
47  G4UImanager* UI = G4UImanager::GetUIpointer();
48  UI->ApplyCommand("/tracking/storeTrajectory 1");
49  UI->ApplyCommand("/vis/scene/notifyhandlers");
50  }
51  }
52 
54  {
55  // If graphics is ON
56  if (G4VVisManager::GetConcreteInstance())
57  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
58  }
59 
61  {}
62 
63  void VisualizationAction::EndOfEventAction(const G4Event* a_event)
64  {
65  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
66 
67  if (pVVisManager)
68  {
69  G4TrajectoryContainer* trajectoryContainer = a_event->GetTrajectoryContainer();
70  G4int n_trajectories = 0;
71  if (trajectoryContainer)
72  n_trajectories = trajectoryContainer->entries();
73 
74  for (G4int i=0; i < n_trajectories; i++)
75  {
76  G4VTrajectory* trajectory = (*trajectoryContainer)[i];
77 
78  // Only draw "interesting" trajectories, according to cuts
79  // and limits set by the user.
80 
81  G4bool drawThisTrack = false;
82  if ( trajectory->GetInitialMomentum().mag() > m_energyCutoff )
83  drawThisTrack = true;
84 
85  if ( ! m_drawNeutrals )
86  {
87  G4double charge = trajectory->GetCharge();
88  // electron-, muon-, and tau-neutrino codes:
89  if ( charge == 0 )
90  drawThisTrack = false;
91  }
92 
93  if ( drawThisTrack )
94  trajectory->DrawTrajectory();
95  //trajectory->DrawTrajectory(50);
96  }
97  }
98  }
99 
100 
101 
102 
103 } // namespace LArG4
util::quantities::gigaelectronvolt GeV
Store parameters for running LArG4.
G4bool m_drawNeutrals
Whether or not to draw neutral tracks (default is no).
virtual void BeginOfEventAction(const G4Event *)
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.