Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExN04StackingAction.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 //
28 //
29 
30 #include "ExN04StackingAction.hh"
31 #include "G4SDManager.hh"
32 #include "G4RunManager.hh"
33 #include "G4Event.hh"
34 #include "G4HCofThisEvent.hh"
35 #include "G4Track.hh"
36 #include "G4TrackStatus.hh"
37 #include "G4ParticleDefinition.hh"
38 #include "G4ParticleTypes.hh"
39 #include "ExN04StackingActionMessenger.hh"
40 #include "G4ios.hh"
41 
43  : trkHits(0), muonHits(0), stage(0)
44 {
45  angRoI = 30.0*deg;
46  reqMuon = 2;
47  reqIso = 10;
48  theMessenger = new ExN04StackingActionMessenger(this);
49 }
50 
52 { delete theMessenger; }
53 
56 {
57  G4ClassificationOfNewTrack classification = fWaiting;
58  switch(stage)
59  {
60  case 0: // Stage 0 : Primary muons only
61  if(aTrack->GetParentID()==0)
62  {
63  G4ParticleDefinition * particleType = aTrack->GetDefinition();
64  if((particleType==G4MuonPlus::MuonPlusDefinition())
65  ||(particleType==G4MuonMinus::MuonMinusDefinition()))
66  { classification = fUrgent; }
67  }
68  break;
69 
70  case 1: // Stage 1 : Charged primaries only
71  // Suspended tracks will be sent to the waiting stack
72  if(aTrack->GetParentID()!=0) { break; }
73  if(aTrack->GetTrackStatus()==fSuspend) { break; }
74  if(aTrack->GetDefinition()->GetPDGCharge()==0.) { break; }
75  classification = fUrgent;
76  break;
77 
78  default: // Stage 2 : Accept all primaries
79  // Accept all secondaries in RoI
80  // Kill secondaries outside RoI
81  if(aTrack->GetParentID()==0)
82  {
83  classification = fUrgent;
84  break;
85  }
86  if((angRoI<0.)||InsideRoI(aTrack,angRoI))
87  {
88  classification = fUrgent;
89  break;
90  }
91  classification = fKill;
92  }
93  return classification;
94 }
95 
96 G4bool ExN04StackingAction::InsideRoI(const G4Track * aTrack,G4double ang)
97 {
98  if(!muonHits)
99  { muonHits = (ExN04MuonHitsCollection*)GetCollection("muonCollection"); }
100  if(!muonHits)
101  { G4cerr << "muonCollection NOT FOUND" << G4endl;
102  return true; }
103 
104  G4int nhits = muonHits->entries();
105 
106  const G4ThreeVector trPos = aTrack->GetPosition();
107  for(G4int i=0;i<nhits;i++)
108  {
109  G4ThreeVector muHitPos = (*muonHits)[i]->GetPos();
110  G4double angl = muHitPos.angle(trPos);
111  if(angl<ang) { return true; }
112  }
113 
114  return false;
115 }
116 
117 G4VHitsCollection* ExN04StackingAction::GetCollection(G4String colName)
118 {
121  int colID = SDMan->GetCollectionID(colName);
122  if(colID>=0)
123  {
124  const G4Event* currentEvent = runMan->GetCurrentEvent();
125  G4HCofThisEvent* HCE = currentEvent->GetHCofThisEvent();
126  return HCE->GetHC(colID);
127  }
128  return 0;
129 }
130 
132 {
133  stage++;
134  G4int nhits;
135  if(stage==1)
136  {
137  // Stage 0->1 : check if at least "reqMuon" hits on muon chamber
138  // otherwise abort current event
139  if(!muonHits)
140  { muonHits = (ExN04MuonHitsCollection*)GetCollection("muonCollection"); }
141  if(!muonHits)
142  { G4cerr << "muonCollection NOT FOUND" << G4endl;
143  return; }
144  nhits = muonHits->entries();
145  G4cout << "Stage 0->1 : " << nhits << " hits found in the muon chamber."
146  << G4endl;
147  if(nhits<reqMuon)
148  {
149  stackManager->clear();
150  G4cout << "++++++++ event aborted" << G4endl;
151  return;
152  }
154  return;
155  }
156 
157  else if(stage==2)
158  {
159  // Stage 1->2 : check the isolation of muon tracks
160  // at least "reqIsoMuon" isolated muons
161  // otherwise abort current event.
162  // Isolation requires "reqIso" or less hits
163  // (including own hits) in the RoI region
164  // in the tracker layers.
165  nhits = muonHits->entries();
166  if(!trkHits)
167  { trkHits = (ExN04TrackerHitsCollection*)GetCollection("trackerCollection"); }
168  if(!trkHits)
169  { G4cerr << "trackerCollection NOT FOUND" << G4endl;
170  return; }
171  G4int nTrkhits = trkHits->entries();
172  G4int isoMuon = 0;
173  for(G4int j=0;j<nhits;j++)
174  {
175  G4ThreeVector hitPos = (*muonHits)[j]->GetPos();
176  G4int nhitIn = 0;
177  for(G4int jj=0;(jj<nTrkhits)&&(nhitIn<=reqIso);jj++)
178  {
179  G4ThreeVector trkhitPos = (*trkHits)[jj]->GetPos();
180  if(trkhitPos.angle(hitPos)<angRoI) nhitIn++;
181  }
182  if(nhitIn<=reqIso) isoMuon++;
183  }
184  G4cout << "Stage 1->2 : " << isoMuon << " isolated muon found." << G4endl;
185  if(isoMuon<reqIsoMuon)
186  {
187  stackManager->clear();
188  G4cout << "++++++++ event aborted" << G4endl;
189  return;
190  }
192  return;
193  }
194 
195  else
196  {
197  // Other stage change : just re-classify
199  }
200 }
201 
203 {
204  stage = 0;
205  trkHits = 0;
206  muonHits = 0;
207 }
208 
209