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