source: trunk/examples/novice/N04/src/ExN04StackingAction.cc @ 1143

Last change on this file since 1143 was 807, checked in by garnier, 16 years ago

update

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