Geant4  10.01.p03
RE05StackingAction.cc
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 // $Id: RE05StackingAction.cc 77724 2013-11-27 17:11:16Z gcosmo $
27 //
30 //
31 
32 #include "RE05StackingAction.hh"
33 #include "G4SDManager.hh"
34 #include "G4RunManager.hh"
35 #include "G4Event.hh"
36 #include "G4HCofThisEvent.hh"
37 #include "G4Track.hh"
38 #include "G4TrackStatus.hh"
39 #include "G4ParticleDefinition.hh"
40 #include "G4ParticleTypes.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "G4ios.hh"
44 
46  : trkHits(0), muonHits(0), stage(0)
47 {
48  angRoI = 30.0*deg;
49  reqMuon = 2;
50  reqIso = 10;
52 }
53 
55 { delete theMessenger; }
56 
59 {
60  G4ClassificationOfNewTrack classification = fWaiting;
61  switch(stage)
62  {
63  case 0: // Stage 0 : Primary muons only
64  if(aTrack->GetParentID()==0)
65  {
66  G4ParticleDefinition * particleType = aTrack->GetDefinition();
67  if((particleType==G4MuonPlus::MuonPlusDefinition())
68  ||(particleType==G4MuonMinus::MuonMinusDefinition()))
69  { classification = fUrgent; }
70  }
71  break;
72 
73  case 1: // Stage 1 : Charged primaries only
74  // Suspended tracks will be sent to the waiting stack
75  if(aTrack->GetParentID()!=0) { break; }
76  if(aTrack->GetTrackStatus()==fSuspend) { break; }
77  if(aTrack->GetDefinition()->GetPDGCharge()==0.) { break; }
78  classification = fUrgent;
79  break;
80 
81  default: // Stage 2 : Accept all primaries
82  // Accept all secondaries in RoI
83  // Kill secondaries outside RoI
84  if(aTrack->GetParentID()==0)
85  {
86  classification = fUrgent;
87  break;
88  }
89  if((angRoI<0.)||InsideRoI(aTrack,angRoI))
90  {
91  classification = fUrgent;
92  break;
93  }
94  classification = fKill;
95  }
96  return classification;
97 }
98 
100 {
101  if(!muonHits)
102  { muonHits = (RE05MuonHitsCollection*)GetCollection("muonCollection"); }
103  if(!muonHits)
104  { G4cerr << "muonCollection NOT FOUND" << G4endl;
105  return true; }
106 
107  G4int nhits = muonHits->entries();
108 
109  const G4ThreeVector trPos = aTrack->GetPosition();
110  for(G4int i=0;i<nhits;i++)
111  {
112  G4ThreeVector muHitPos = (*muonHits)[i]->GetPos();
113  G4double angl = muHitPos.angle(trPos);
114  if(angl<ang) { return true; }
115  }
116 
117  return false;
118 }
119 
121 {
124  int colID = SDMan->GetCollectionID(colName);
125  if(colID>=0)
126  {
127  const G4Event* currentEvent = runMan->GetCurrentEvent();
128  G4HCofThisEvent* HCE = currentEvent->GetHCofThisEvent();
129  return HCE->GetHC(colID);
130  }
131  return 0;
132 }
133 
135 {
136  stage++;
137  G4int nhits;
138  if(stage==1)
139  {
140  // Stage 0->1 : check if at least "reqMuon" hits on muon chamber
141  // otherwise abort current event
142  if(!muonHits)
143  { muonHits = (RE05MuonHitsCollection*)GetCollection("muonCollection"); }
144  if(!muonHits)
145  { G4cerr << "muonCollection NOT FOUND" << G4endl;
146  return; }
147  nhits = muonHits->entries();
150  if(nhits<reqMuon)
151  {
152  stackManager->clear();
154  return;
155  }
157  return;
158  }
159 
160  else if(stage==2)
161  {
162  // Stage 1->2 : check the isolation of muon tracks
163  // at least "reqIsoMuon" isolated muons
164  // otherwise abort current event.
165  // Isolation requires "reqIso" or less hits
166  // (including own hits) in the RoI region
167  // in the tracker layers.
168  nhits = muonHits->entries();
169  if(!trkHits)
170  { trkHits = (RE05TrackerHitsCollection*)GetCollection("trackerCollection"); }
171  if(!trkHits)
172  { G4cerr << "trackerCollection NOT FOUND" << G4endl;
173  return; }
174  G4int nTrkhits = trkHits->entries();
175  G4int isoMuon = 0;
176  for(G4int j=0;j<nhits;j++)
177  {
178  G4ThreeVector hitPos = (*muonHits)[j]->GetPos();
179  G4int nhitIn = 0;
180  for(G4int jj=0;(jj<nTrkhits)&&(nhitIn<=reqIso);jj++)
181  {
182  G4ThreeVector trkhitPos = (*trkHits)[jj]->GetPos();
183  if(trkhitPos.angle(hitPos)<angRoI) nhitIn++;
184  }
185  if(nhitIn<=reqIso) isoMuon++;
186  }
188  if(isoMuon<reqIsoMuon)
189  {
190  stackManager->clear();
192  return;
193  }
195  return;
196  }
197 
198  else
199  {
200  // Other stage change : just re-classify
202  }
203 }
204 
206 {
207  stage = 0;
208  trkHits = 0;
209  muonHits = 0;
210 }
211 
212 
G4ParticleDefinition * GetDefinition() const
G4int GetParentID() const
static G4MuonPlus * MuonPlusDefinition()
Definition: G4MuonPlus.cc:94
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
RE05StackingActionMessenger * theMessenger
CLHEP::Hep3Vector G4ThreeVector
Definition of the RE05StackingActionMessenger class.
const G4ThreeVector & GetPosition() const
G4TrackStatus GetTrackStatus() const
G4int entries() const
G4VHitsCollection * GetCollection(G4String colName)
G4bool InsideRoI(const G4Track *aTrack, G4double ang)
RE05MuonHitsCollection * muonHits
int G4int
Definition: G4Types.hh:78
static const double deg
Definition: G4SIunits.hh:133
bool G4bool
Definition: G4Types.hh:79
Definition of the RE05StackingAction class.
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
RE05TrackerHitsCollection * trkHits
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
static G4MuonMinus * MuonMinusDefinition()
Definition: G4MuonMinus.cc:95
virtual void PrepareNewEvent()
#define G4endl
Definition: G4ios.hh:61
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
G4StackManager * stackManager
double G4double
Definition: G4Types.hh:76
const G4Event * GetCurrentEvent() const
G4double GetPDGCharge() const
G4GLOB_DLL std::ostream G4cerr