EnergyDepositAction.cxx
Go to the documentation of this file.
1 //
2 // EnergyDepositAction.cxx
3 //
4 // Created by Brian Rebel on 10/12/16.
5 //
6 
8 #include "cetlib_except/exception.h"
9 
10 #include "TGeoManager.h"
11 #include "TGeoMaterial.h"
12 #include "TGeoNode.h"
13 
14 // G4 includes
15 #include "Geant4/G4Event.hh"
16 #include "Geant4/G4Track.hh"
17 #include "Geant4/G4ThreeVector.hh"
18 #include "Geant4/G4ParticleDefinition.hh"
19 #include "Geant4/G4PrimaryParticle.hh"
20 #include "Geant4/G4DynamicParticle.hh"
21 #include "Geant4/G4VUserPrimaryParticleInformation.hh"
22 #include "Geant4/G4Step.hh"
23 #include "Geant4/G4StepPoint.hh"
24 #include "Geant4/G4VProcess.hh"
25 
26 #include "Geometry/GeometryGAr.h"
29 
30 #include <regex>
31 
32 namespace gar {
33 
34  namespace garg4 {
35 
36  //-------------------------------------------------------------
37  // Constructor.
38  EnergyDepositAction::EnergyDepositAction(CLHEP::HepRandomEngine* , // engine,
39  fhicl::ParameterSet const& pset)
40  //: fEngine(engine)
41  {
42  this->reconfigure(pset);
43  }
44 
45  //-------------------------------------------------------------
46  // Destructor.
48  {
49  // Delete anything that we created with "new'.
50  }
51 
52  //-------------------------------------------------------------
54  {
55  fEnergyCut = pset.get< double >("EnergyCut");
56  fVolumeName = pset.get< std::vector<std::string> >("GArVolumeName");
57  fMaterialMatchString = pset.get< std::string >("GArMaterialMatchString");
58 
59  // std::cout << "EnergyDepositAction: Name of the Volumes to track for the GArTPC" << std::endl;
60  // for(unsigned int i = 0; i < fVolumeName.size(); i++) std::cout << fVolumeName.at(i) << " ";
61  // std::cout << std::endl;
62 
63  return;
64  }
65 
66  //-------------------------------------------------------------
68  {
69  // Clear any previous information.
70  fDeposits.clear();
71  }
72 
73  //-------------------------------------------------------------
74  void EnergyDepositAction::PreTrackingAction(const G4Track* /*track*/)
75  {
76  }
77 
78  //-------------------------------------------------------------
79  void EnergyDepositAction::PostTrackingAction( const G4Track* /*track*/)
80  {
81  }
82 
83  //-------------------------------------------------------------
84  // With every step, handle energy deposition in gaseous argon
86  {
87  MF_LOG_DEBUG("EnergyDepositAction")
88  << "EnergyDepositAction::SteppingAction";
89 
91  TGeoManager *geomanager = geo->ROOTGeoManager();
92 
93  // Get the pointer to the track
94  G4Track *track = step->GetTrack();
95 
96  const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
97  const CLHEP::Hep3Vector &stop = track->GetPosition();
98 
99  // If it's a null step, don't use it.
100  if(start == stop) return;
101  if(step->GetTotalEnergyDeposit() == 0) return;
102 
103  // check that we are in the correct material to record a hit
104  std::string VolumeName = this->GetVolumeName(track);
105 
106  if( std::find( fVolumeName.begin(), fVolumeName.end(), VolumeName ) == fVolumeName.end() )
107  return;
108 
109  // check the material
110  auto pos = 0.5 * (start + stop);
111  TGeoNode *node = geomanager->FindNode(pos.x()/CLHEP::cm, pos.y()/CLHEP::cm, pos.z()/CLHEP::cm);//Node in cm
112 
113  if(!node){
114  MF_LOG_DEBUG("EnergyDepositAction")
115  << "Node not found in "
116  << pos.x() << " mm "
117  << pos.y() << " mm "
118  << pos.z() << " mm";
119  return;
120  }
121 
122  std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
123  if ( ! std::regex_match(volmaterial, std::regex(fMaterialMatchString)) ) return;
124 
125  // only worry about energy depositions larger than the minimum required
126  if(step->GetTotalEnergyDeposit() * CLHEP::MeV / CLHEP::GeV > fEnergyCut ){
127 
128  MF_LOG_DEBUG("EnergyDepositAction")
129  << "In volume "
130  << VolumeName
131  << " step size is "
132  << step->GetStepLength() / CLHEP::cm
133  << " cm and deposited "
134  << step->GetTotalEnergyDeposit()
135  << " MeV of energy with a minimum of "
136  << fEnergyCut
137  << " required.";
138 
139  // save this deposition
140  this->AddEnergyDeposition(step);
141 
142  } // end if enough energy to worry about this step
143 
144  }// end of EnergyDepositAction::SteppingAction
145 
146  //--------------------------------------------------------------------------
148  {
149  // get the track id for this step
150  auto trackID = ParticleListAction::GetCurrentTrackID();
151 
152  // first check that we are not dealing with ionization, ie delta rays
153  // if we have one of those, set the trackID to be the ID of the parent
154  //if(trackID < 0)
155  // MF_LOG_VERBATIM("EnergyDepositAction")
156  // << "TrackID "
157  // << trackID
158  // << " was created by process "
159  // << step->GetTrack()->GetCreatorProcess()->GetProcessName();
160  //else
161  // MF_LOG_VERBATIM("EnergyDepositAction")
162  // << "TrackID "
163  // << trackID
164  // << " is a primary particle ";
165 
166  // the step mid point is used for the position of the deposit
167  auto midPoint = 0.5 * (step->GetPreStepPoint()->GetPosition() +
168  step->GetPostStepPoint()->GetPosition() );
169  float time = step->GetPreStepPoint()->GetGlobalTime();
170 
171  fDeposits.emplace_back(trackID,
172  time,
173  step->GetTotalEnergyDeposit() * CLHEP::MeV / CLHEP::GeV,
174  midPoint.x() / CLHEP::cm,
175  midPoint.y() / CLHEP::cm,
176  midPoint.z() / CLHEP::cm,
177  step->GetStepLength() / CLHEP::cm,
178  (trackID > 0));
179 
180  return;
181  }
182 
183  //--------------------------------------------------------------------------
185  {
186  // sort the EnergyDeposit lists in each EnergyDeposits object
187  std::sort(fDeposits.begin(), fDeposits.end());
188  }
189 
190  //--------------------------------------------------------------------------
192  {
193  std::string VolName = track->GetVolume()->GetName();
194  VolName.erase(VolName.length()-3, 3);
195  return VolName;
196  }
197 
198 
199  } // garg4
200 
201  } // gar
static constexpr double cm
Definition: Units.h:68
void PreTrackingAction(const G4Track *)
std::string GetVolumeName(const G4Track *track)
void BeginOfEventAction(const G4Event *)
std::string string
Definition: nybbler.cc:12
EnergyDepositAction(CLHEP::HepRandomEngine *engine, fhicl::ParameterSet const &pset)
static constexpr double MeV
Definition: Units.h:129
void PostTrackingAction(const G4Track *)
double fEnergyCut
be included in the list.
static constexpr double GeV
Definition: Units.h:28
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::vector< gar::sdp::EnergyDeposit > fDeposits
energy fDeposits
std::string fMaterialMatchString
Energy deposition will be recorded for materials that match this.
void reconfigure(fhicl::ParameterSet const &pset)
General GArSoft Utilities.
std::vector< std::string > fVolumeName
volume we will record energy depositions in
#define MF_LOG_DEBUG(id)
LArSoft geometry interface.
Definition: ChannelGeo.h:16
art framework interface to geometry description
void AddEnergyDeposition(const G4Step *step)