LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ExampleAction.cxx
Go to the documentation of this file.
1 
11 
12 // self-register with the factory
15 
16 // G4 includes
17 #include "Geant4/G4Event.hh"
18 #include "Geant4/G4Track.hh"
19 #include "Geant4/G4ThreeVector.hh"
20 #include "Geant4/G4ParticleDefinition.hh"
21 #include "Geant4/G4PrimaryParticle.hh"
22 #include "Geant4/G4DynamicParticle.hh"
23 #include "Geant4/G4VUserPrimaryParticleInformation.hh"
24 #include "Geant4/G4Step.hh"
25 #include "Geant4/G4StepPoint.hh"
26 #include "Geant4/G4VProcess.hh"
27 #include "Geant4/G4VPhysicalVolume.hh"
28 #include "Geant4/G4VTouchable.hh"
29 
30 // ROOT includes
31 #include <TLorentzVector.h>
32 #include <TString.h>
33 
34 // C/C++ includes
35 #include <algorithm>
36 #include <string>
37 
38 namespace altns {
39 
40  // Initialize static members.
41 
42  //-------------------------------------------------------------
43  // Constructor.
45  : fSomeValue(0)
46  , fVerbose(0)
47  , fStepMsgMaxPerEvt(42)
48  , fTrack2ndMsgMaxPerEvt(2)
49  {
51  }
52 
53  //-------------------------------------------------------------
54  // Destructor.
56  {
58  }
59 
60  //-------------------------------------------------------------
62  {
64 
65  fSomeValue = pset.get< double >("SomeValue",0)*CLHEP::GeV;
66  fVerbose = pset.get< int >("Verbose",0);
67  fStepMsgMaxPerEvt = pset.get< int >("StepMsgMaxPerEvt",42);
68  fTrack2ndMsgMaxPerEvt = pset.get< int >("Track2ndMsgMaxPerEvt",2);
69 
70  }
71 
72  //-------------------------------------------------------------
73  void ExampleAction::PrintConfig(std::string const& /* opt */)
74  {
75  mf::LogInfo("ExampleAction")
76  << "ExampleAction::PrintConfig \n"
77  << " SomeValue " << fSomeValue << "\n"
78  << " Verbose " << fVerbose << "\n"
79  << " StepMsgMaxPerEvt " << fStepMsgMaxPerEvt << "\n"
80  << " Track2ndMsgMaxPerEvt " << fTrack2ndMsgMaxPerEvt << "\n";
81 
82  }
83 
84  //-------------------------------------------------------------
86  {
90 
91  mf::LogInfo("ExampleAction")
92  << "ExampleAction::BeginOfEventAction EventID="
93  << event->GetEventID();
94 
95  fStepMsg = 0;
96  fTrack2ndMsg = 0;
97 
98  }
99 
100  //-------------------------------------------------------------
102  {
105 
106  mf::LogInfo("ExampleAction")
107  << "ExampleAction::EndOfEventAction EventID="
108  << event->GetEventID();
109  }
110 
111  //-------------------------------------------------------------
113  {
116 
117  G4int parent_id = track->GetParentID();
118  if ( parent_id > 0 && fTrack2ndMsg > fTrack2ndMsgMaxPerEvt ) return;
119 
120  mf::LogInfo("ExampleAction")
121  << "ExampleAction::PreTrackingAction TrackID="
122  << track->GetTrackID()
123  << " is a " << track->GetParticleDefinition()->GetParticleName();
124  }
125 
126  //-------------------------------------------------------------
128  {
131 
132  G4int parent_id = track->GetParentID();
133  std::string extra_msg = "";
134  if ( parent_id > 0 ) {
135  ++fTrack2ndMsg;
136  if ( fTrack2ndMsg > fTrack2ndMsgMaxPerEvt ) return;
138  extra_msg = "...last such message this event";
139  }
140  }
141 
142  mf::LogInfo("ExampleAction")
143  << "ExampleAction::PostTrackingAction TrackID="
144  << track->GetTrackID()
145  << " " << extra_msg;
146  }
147 
148  //-------------------------------------------------------------
149  void ExampleAction::SteppingAction(const G4Step* step)
150  {
152 
153  ++fStepMsg;
154  if ( ++fStepMsg > fStepMsgMaxPerEvt ) return;
155 
156  std::string extra_msg = "";
157  if ( fStepMsg == fStepMsgMaxPerEvt ) {
158  extra_msg = "...last such message this event";
159  }
160 
161  mf::LogInfo("ExampleAction")
162  << "ExampleAction::SteppingAction TrackID="
163  << step->GetTrack()->GetTrackID()
164  << " " << extra_msg;
165 
166 
167  }
168 
169  //-------------------------------------------------------------
170  G4ClassificationOfNewTrack
172  {
183 
184  G4int parent_id = track->GetParentID();
185  std::string tsrc = "primary";
186  if ( parent_id < 0 ) tsrc = "postponed (from previous event)";
187  if ( parent_id > 0 ) tsrc = "secondary";
188 
189  mf::LogInfo("ExampleAction")
190  << "ExampleAction::StackClassifyNewTrack TrackID="
191  << track->GetTrackID()
192  << " ParentID=" << parent_id << " "
193  << track->GetDefinition()->GetParticleName()
194  << " (" << tsrc << " particle)";
195 
196  // One *must* return a classification
197  // Since we're not doing anything useful in NewStage/PrepareNewEvent
198  // the only things we should return are fUrgent or fKill
199  return fUrgent;
200  }
201 
202  //-------------------------------------------------------------
204  {
215 
216  mf::LogInfo("ExampleAction")
217  << "ExampleAction::StackNewStage";
218  }
219 
220  //-------------------------------------------------------------
222  {
229 
230  mf::LogInfo("ExampleAction")
231  << "ExampleAction::StackPrepareNewEvent";
232  }
233 
234 } // end namespace
void SteppingAction(const G4Step *)
G4UserSteppingAction interface.
void PostTrackingAction(const G4Track *)
G4ClassificationOfNewTrack StackClassifyNewTrack(const G4Track *)
G4UserStackingAction interfaces.
int fVerbose
verbosity
Definition: ExampleAction.h:54
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int fStepMsgMaxPerEvt
shut up about steps
Definition: ExampleAction.h:55
Use Geant4&#39;s user "hooks" to kill particles in the rock.
void Config(fhicl::ParameterSet const &pset)
Override Config() to extract any necessary parameters.
int fTrack2ndMsgMaxPerEvt
shut up about 2ndary tracks
Definition: ExampleAction.h:56
A class for generating concrete UserAction derived classes based on the factory pattern. This code supplies a CPP macro which allows the classes to self-register and thus no modification of this class is needed in order to expand the list of classes it knows about.
#define USERACTIONREG3(_ns, _name, _fqname)
void PrintConfig(std::string const &opt)
Override PrintConfig() to print out current configuration.
void BeginOfEventAction(const G4Event *)
T get(std::string const &key) const
Definition: ParameterSet.h:231
int fTrack2ndMsg
of 2ndary track printed this evt?
Definition: ExampleAction.h:59
double fSomeValue
some user config value
Definition: ExampleAction.h:53
int fStepMsg
steps have we printed this evt?
Definition: ExampleAction.h:58
Float_t track
Definition: plot.C:34
void PreTrackingAction(const G4Track *)
G4UserTrackingAction interfaces.
Event finding and building.
void EndOfEventAction(const G4Event *)