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