LArSoft  v09_90_00
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  //theMessenger = new LArStackingActionMessenger(this);
54  fStack = dum;
55  // Positive values effect action in this routine. Negative values
56  // effect action in G4BadIdeaAction.
57 }
58 
60 { //delete theMessenger;
61 }
62 
63 G4ClassificationOfNewTrack LArStackingAction::ClassifyNewTrack(const G4Track* aTrack)
64 {
65  G4ClassificationOfNewTrack classification = fWaiting;
67  TString volName(InsideTPC(aTrack));
68  Double_t buffer = 500; // Keep muNucl neutrals within 5m (for now) of larTPC.
69 
70  // These 3 for now for investigation in gdb.
71  //int pdg = aTrack->GetDefinition()->GetPDGEncoding();
72  int ppdg = aTrack->GetParentID();
73  TString process("NA");
74  if (ppdg) process = (TString)aTrack->GetCreatorProcess()->GetProcessName();
75 
76  switch (fstage) {
77  case 0: // Fstage 0 : Primary muons only
78  if (aTrack->GetParentID() == 0) {
79  G4ParticleDefinition* particleType = aTrack->GetDefinition();
80  if (((particleType == G4MuonPlus::MuonPlusDefinition()) ||
81  (particleType == G4MuonMinus::MuonMinusDefinition())) &&
82  !volName.Contains("unknown")) {
83  classification = fUrgent;
84  }
85  }
86  if (volName.Contains("unknown")) classification = fKill;
87  break;
88 
89  case 1: // Stage 1 : K0,Lambda,n's made urgent here.
90  // Suspended tracks will be sent to the waiting stack
91  if (aTrack->GetTrackStatus() == fSuspend) { break; }
92 
93  if ((aTrack->GetDefinition()->GetPDGEncoding() == 2112 ||
94  aTrack->GetDefinition()->GetPDGEncoding() == 130 ||
95  aTrack->GetDefinition()->GetPDGEncoding() == 310 ||
96  aTrack->GetDefinition()->GetPDGEncoding() == 311 ||
97  aTrack->GetDefinition()->GetPDGEncoding() == 3122) &&
98  (aTrack->GetParentID() == 1) && !volName.Contains("unknown")) {
99 
100  const G4ThreeVector tr4Pos = aTrack->GetPosition();
101  // G4 returns positions in mm, have to convert to cm for LArSoft coordinate systems
102  const TVector3 trPos(tr4Pos.x() / CLHEP::cm, tr4Pos.y() / CLHEP::cm, tr4Pos.z() / CLHEP::cm);
103  //double locNeut = trPos.Mag();
104  classification = fUrgent;
105  // std::cout << "LArStackingAction: DetHalfWidth, Height, FullLength: " << geom->DetHalfWidth() << ", " << geom->DetHalfHeight() << ", " << geom->DetLength() << std::endl;
106 
107  if (trPos.X() < (geom->DetHalfWidth() * 2.0 + buffer) && trPos.X() > (-buffer) &&
108  trPos.Y() < (geom->DetHalfHeight() * 2.0 + buffer) &&
109  trPos.Y() > (-geom->DetHalfHeight() * 2.0 - buffer) &&
110  trPos.Z() < (geom->DetLength() + buffer) && trPos.Z() > (-buffer))
111 
112  {
113  classification = fUrgent;
114  break;
115  }
116  // These tracks need to be "scored" cuz every now and then they
117  // might get to the LAr.
118  else {
119  classification = fKill;
120  break;
121  }
122  }
123 
124  // if(aTrack->GetDefinition()->GetPDGCharge()==0.) { break; }
125  if (volName.Contains("unknown")) classification = fKill;
126  break;
127 
128  default:
129  // Track all other Primaries. Accept all secondaries in TPC.
130  // Kill muon ionization electrons outside TPC
131  // ignore primaries since they have no creator process
132 
133  if (aTrack->GetParentID() == 0 && !volName.Contains("unknown")) {
134  classification = fUrgent;
135  break;
136  }
137 
138  if (volName.Contains(geom->GetLArTPCVolumeName()) && aTrack->GetParentID() != 0) {
139  classification = fUrgent;
140  if (fStack & 0x4 && aTrack->GetCreatorProcess()->GetProcessName().contains("muIoni")) {
141  classification = fKill;
142  }
143  break;
144  }
145  else if (volName.Contains("unknown")) {
146  classification = fKill;
147  break;
148  }
149  // Leave this here, even though I claim we've Killed these in stage 2.
150  if (aTrack->GetDefinition()->GetPDGEncoding() == 11 &&
151  aTrack->GetCreatorProcess()->GetProcessName().contains("muIoni")) {
152  classification = fKill;
153  break;
154  }
155  // For now, kill every other thing, no matter where it is.
156  classification = fKill;
157 
158  } // end switch
159 
160  return classification;
161 }
162 
163 std::string LArStackingAction::InsideTPC(const G4Track* aTrack)
164 {
166  const G4ThreeVector tr4Pos = aTrack->GetPosition();
167 
168  // G4 returns positions in mm, have to convert to cm for LArSoft coordinate systems
169  const geo::Point_t trPos(tr4Pos.x() / CLHEP::cm, tr4Pos.y() / CLHEP::cm, tr4Pos.z() / CLHEP::cm);
170 
171  return geom->VolumeName(trPos);
172 }
173 
175 {
176 
177  // Here when Urgent stack is empty. Waiting stack about to be made Urgent,
178  // upon saying ReClassify().
179  fstage++;
180 
181  // I yanked the ExN04's use here of stackManager->clear(), which clears stack
182  // and prepares to end the event. Think I may wanna do something like this if
183  // muon has been tracked, its doca is large, there are no hit voxels in the TPC,
184  // and I'm in further need of optimization.
185 
186  if (fstage == 1) {
187  // Stage 0->1 : check if at least "reqMuon" hits on muon chamber
188  // otherwise abort current event
189 
190  stackManager->ReClassify();
191  return;
192  }
193 
194  else if (fstage == 2) {
195  // Stage 1->2 : check the isolation of muon tracks
196  // at least "reqIsoMuon" isolated muons
197  // otherwise abort current event.
198  // Isolation requires "reqIso" or less hits
199  // (including own hits) in the RoI region
200  // in the tracker layers.
201  stackManager->ReClassify();
202  return;
203  }
204 
205  else {
206  // Other stage change : just re-classify
207  stackManager->ReClassify();
208  }
209 }
210 
212 {
213  fstage = 0;
214  //trkHits = 0;
215  //muonHits = 0;
216 }
std::string GetLArTPCVolumeName(TPCID const &tpcid=tpc_zero) const
Return the name of specified LAr TPC volume.
Length_t DetHalfWidth(TPCID const &tpcid=tpc_zero) const
Returns the half width of the active volume of the specified TPC.
virtual void NewStage()
std::string InsideTPC(const G4Track *aTrack)
Length_t DetLength(TPCID const &tpcid=tpc_zero) const
Returns the length of the active volume of the specified TPC.
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)
Length_t DetHalfHeight(TPCID const &tpcid=tpc_zero) const
Returns the half height of the active volume of the specified TPC.
virtual void PrepareNewEvent()
art framework interface to geometry description