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