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