LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
LArStackingAction.cxx
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 
29 
30 #include "CLHEP/Units/SystemOfUnits.h"
31 
32 #include "Geant4/G4MuonMinus.hh"
33 #include "Geant4/G4MuonPlus.hh"
34 #include "Geant4/G4ParticleDefinition.hh"
35 #include "Geant4/G4StackManager.hh"
36 #include "Geant4/G4String.hh"
37 #include "Geant4/G4ThreeVector.hh"
38 #include "Geant4/G4Track.hh"
39 #include "Geant4/G4TrackStatus.hh"
40 #include "Geant4/G4VProcess.hh"
41 
42 // ROOT includes
43 #include "RtypesCore.h"
44 #include "TString.h"
45 #include "TVector3.h"
46 
47 // Framework includes
49 
51  : fstage(0), freqMuon(2), freqIsoMuon(0), freqIso(10), fangRoI(30. * CLHEP::deg)
52 {
53  fStack = dum;
54  // Positive values effect action in this routine. Negative values effect action in
55  // G4BadIdeaAction.
56 }
57 
58 G4ClassificationOfNewTrack LArStackingAction::ClassifyNewTrack(const G4Track* aTrack)
59 {
60  G4ClassificationOfNewTrack classification = fWaiting;
62  TString volName(InsideTPC(aTrack));
63  Double_t buffer = 500; // Keep muNucl neutrals within 5m (for now) of larTPC.
64 
65  // These 3 for now for investigation in gdb.
66  int ppdg = aTrack->GetParentID();
67  TString process("NA");
68  if (ppdg) process = (TString)aTrack->GetCreatorProcess()->GetProcessName();
69 
70  switch (fstage) {
71  case 0: // Fstage 0 : Primary muons only
72  if (aTrack->GetParentID() == 0) {
73  G4ParticleDefinition* particleType = aTrack->GetDefinition();
74  if (((particleType == G4MuonPlus::MuonPlusDefinition()) ||
75  (particleType == G4MuonMinus::MuonMinusDefinition())) &&
76  !volName.Contains("unknown")) {
77  classification = fUrgent;
78  }
79  }
80  if (volName.Contains("unknown")) classification = fKill;
81  break;
82 
83  case 1: // Stage 1 : K0,Lambda,n's made urgent here.
84  // Suspended tracks will be sent to the waiting stack
85  if (aTrack->GetTrackStatus() == fSuspend) { break; }
86 
87  if ((aTrack->GetDefinition()->GetPDGEncoding() == 2112 ||
88  aTrack->GetDefinition()->GetPDGEncoding() == 130 ||
89  aTrack->GetDefinition()->GetPDGEncoding() == 310 ||
90  aTrack->GetDefinition()->GetPDGEncoding() == 311 ||
91  aTrack->GetDefinition()->GetPDGEncoding() == 3122) &&
92  (aTrack->GetParentID() == 1) && !volName.Contains("unknown")) {
93 
94  const G4ThreeVector tr4Pos = aTrack->GetPosition();
95  // G4 returns positions in mm, have to convert to cm for LArSoft coordinate systems
96  const TVector3 trPos(tr4Pos.x() / CLHEP::cm, tr4Pos.y() / CLHEP::cm, tr4Pos.z() / CLHEP::cm);
97  classification = fUrgent;
98 
99  auto const& tpc = geom->TPC({0, 0});
100  if (trPos.X() < (tpc.HalfWidth() * 2.0 + buffer) && trPos.X() > (-buffer) &&
101  trPos.Y() < (tpc.HalfHeight() * 2.0 + buffer) &&
102  trPos.Y() > (-tpc.HalfHeight() * 2.0 - buffer) && trPos.Z() < (tpc.Length() + buffer) &&
103  trPos.Z() > (-buffer)) {
104  classification = fUrgent;
105  break;
106  }
107  // These tracks need to be "scored" cuz every now and then they might get to the
108  // LAr.
109  else {
110  classification = fKill;
111  break;
112  }
113  }
114 
115  if (volName.Contains("unknown")) classification = fKill;
116  break;
117 
118  default:
119  // Track all other Primaries. Accept all secondaries in TPC. Kill muon ionization
120  // electrons outside TPC ignore primaries since they have no creator process
121  if (aTrack->GetParentID() == 0 && !volName.Contains("unknown")) {
122  classification = fUrgent;
123  break;
124  }
125 
126  auto const& tpc = geom->TPC({0, 0});
127  if (volName.Contains(tpc.ActiveVolume()->GetName()) && aTrack->GetParentID() != 0) {
128  classification = fUrgent;
129  if (fStack & 0x4 && aTrack->GetCreatorProcess()->GetProcessName().contains("muIoni")) {
130  classification = fKill;
131  }
132  break;
133  }
134  else if (volName.Contains("unknown")) {
135  classification = fKill;
136  break;
137  }
138  // Leave this here, even though I claim we've Killed these in stage 2.
139  if (aTrack->GetDefinition()->GetPDGEncoding() == 11 &&
140  aTrack->GetCreatorProcess()->GetProcessName().contains("muIoni")) {
141  classification = fKill;
142  break;
143  }
144  // For now, kill every other thing, no matter where it is.
145  classification = fKill;
146 
147  } // end switch
148 
149  return classification;
150 }
151 
152 std::string LArStackingAction::InsideTPC(const G4Track* aTrack)
153 {
155  const G4ThreeVector tr4Pos = aTrack->GetPosition();
156 
157  // G4 returns positions in mm, have to convert to cm for LArSoft coordinate systems
158  const geo::Point_t trPos(tr4Pos.x() / CLHEP::cm, tr4Pos.y() / CLHEP::cm, tr4Pos.z() / CLHEP::cm);
159 
160  return geom->VolumeName(trPos);
161 }
162 
164 {
165  // Here when Urgent stack is empty. Waiting stack about to be made Urgent, upon saying
166  // ReClassify().
167  fstage++;
168 
169  // I yanked the ExN04's use here of stackManager->clear(), which clears stack and
170  // prepares to end the event. Think I may wanna do something like this if muon has been
171  // tracked, its doca is large, there are no hit voxels in the TPC, and I'm in further
172  // need of optimization.
173 
174  if (fstage == 1) {
175  // Stage 0->1 : check if at least "reqMuon" hits on muon chamber otherwise abort
176  // current event
177 
178  stackManager->ReClassify();
179  return;
180  }
181 
182  else if (fstage == 2) {
183  // Stage 1->2 : check the isolation of muon tracks at least "reqIsoMuon" isolated
184  // muons otherwise abort current event. Isolation requires "reqIso" or
185  // less hits (including own hits) in the RoI region in the tracker
186  // layers.
187  stackManager->ReClassify();
188  return;
189  }
190 
191  else {
192  // Other stage change : just re-classify
193  stackManager->ReClassify();
194  }
195 }
196 
198 {
199  fstage = 0;
200 }
virtual void NewStage()
std::string InsideTPC(const G4Track *aTrack)
std::string VolumeName(Point_t const &point) const
Returns the name of the deepest volume containing specified point.
Float_t x4[n_points_geant4]
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
virtual void PrepareNewEvent()
TPCGeo const & TPC(TPCID const &tpcid=details::tpc_zero) const
Returns the specified TPC.
Definition: GeometryCore.h:448
art framework interface to geometry description