File indexing completed on 2025-04-10 08:05:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include "ExN04StackingAction.hh"
0032
0033 #include "ExN04StackingActionMessenger.hh"
0034
0035 #include "G4Event.hh"
0036 #include "G4HCofThisEvent.hh"
0037 #include "G4ParticleDefinition.hh"
0038 #include "G4ParticleTypes.hh"
0039 #include "G4RunManager.hh"
0040 #include "G4SDManager.hh"
0041 #include "G4SystemOfUnits.hh"
0042 #include "G4Track.hh"
0043 #include "G4TrackStatus.hh"
0044
0045
0046 ExN04StackingAction::ExN04StackingAction()
0047 : G4UserStackingAction(), fTrkHits(0), fMuonHits(0), fStage(0)
0048 {
0049 fAngRoI = 30.0 * deg;
0050 fReqMuon = 2;
0051 fReqIso = 10;
0052 fMessenger = new ExN04StackingActionMessenger(this);
0053 }
0054
0055
0056 ExN04StackingAction::~ExN04StackingAction()
0057 {
0058 delete fMessenger;
0059 }
0060
0061
0062 G4ClassificationOfNewTrack ExN04StackingAction::ClassifyNewTrack(const G4Track* aTrack)
0063 {
0064 G4ClassificationOfNewTrack classification = fWaiting;
0065 switch (fStage) {
0066 case 0:
0067 if (aTrack->GetParentID() == 0) {
0068 G4ParticleDefinition* particleType = aTrack->GetDefinition();
0069 if ((particleType == G4MuonPlus::MuonPlusDefinition())
0070 || (particleType == G4MuonMinus::MuonMinusDefinition()))
0071 {
0072 classification = fUrgent;
0073 }
0074 }
0075 break;
0076
0077 case 1:
0078
0079 if (aTrack->GetParentID() != 0) {
0080 break;
0081 }
0082 if (aTrack->GetTrackStatus() == fSuspend) {
0083 break;
0084 }
0085 if (aTrack->GetDefinition()->GetPDGCharge() == 0.) {
0086 break;
0087 }
0088 classification = fUrgent;
0089 break;
0090
0091 default:
0092
0093
0094 if (aTrack->GetParentID() == 0) {
0095 classification = fUrgent;
0096 break;
0097 }
0098 if ((fAngRoI < 0.) || InsideRoI(aTrack, fAngRoI)) {
0099 classification = fUrgent;
0100 break;
0101 }
0102 classification = fKill;
0103 }
0104 return classification;
0105 }
0106
0107
0108 G4bool ExN04StackingAction::InsideRoI(const G4Track* aTrack, G4double ang)
0109 {
0110 if (!fMuonHits) {
0111 fMuonHits = (ExN04MuonHitsCollection*)GetCollection("muonCollection");
0112 }
0113 if (!fMuonHits) {
0114 G4cerr << "muonCollection NOT FOUND" << G4endl;
0115 return true;
0116 }
0117
0118 G4int nhits = fMuonHits->entries();
0119
0120 const G4ThreeVector trPos = aTrack->GetPosition();
0121 for (G4int i = 0; i < nhits; i++) {
0122 G4ThreeVector muHitPos = (*fMuonHits)[i]->GetPos();
0123 G4double angl = muHitPos.angle(trPos);
0124 if (angl < ang) {
0125 return true;
0126 }
0127 }
0128
0129 return false;
0130 }
0131
0132
0133 G4VHitsCollection* ExN04StackingAction::GetCollection(G4String colName)
0134 {
0135 G4SDManager* SDMan = G4SDManager::GetSDMpointer();
0136 G4RunManager* runMan = G4RunManager::GetRunManager();
0137 int colID = SDMan->GetCollectionID(colName);
0138 if (colID >= 0) {
0139 const G4Event* currentEvent = runMan->GetCurrentEvent();
0140 G4HCofThisEvent* HCE = currentEvent->GetHCofThisEvent();
0141 return HCE->GetHC(colID);
0142 }
0143 return 0;
0144 }
0145
0146
0147 void ExN04StackingAction::NewStage()
0148 {
0149 fStage++;
0150 G4int nhits;
0151 if (fStage == 1) {
0152
0153
0154 if (!fMuonHits) {
0155 fMuonHits = (ExN04MuonHitsCollection*)GetCollection("muonCollection");
0156 }
0157 if (!fMuonHits) {
0158 G4cerr << "muonCollection NOT FOUND" << G4endl;
0159 return;
0160 }
0161 nhits = fMuonHits->entries();
0162 G4cout << "Stage 0->1 : " << nhits << " hits found in the muon chamber." << G4endl;
0163 if (nhits < fReqMuon) {
0164 stackManager->clear();
0165 G4cout << "++++++++ event aborted" << G4endl;
0166 return;
0167 }
0168 stackManager->ReClassify();
0169 return;
0170 }
0171
0172 else if (fStage == 2) {
0173
0174
0175
0176
0177
0178
0179 nhits = fMuonHits->entries();
0180 if (!fTrkHits) {
0181 fTrkHits = (ExN04TrackerHitsCollection*)GetCollection("trackerCollection");
0182 }
0183 if (!fTrkHits) {
0184 G4cerr << "trackerCollection NOT FOUND" << G4endl;
0185 return;
0186 }
0187 G4int nTrkhits = fTrkHits->entries();
0188 G4int isoMuon = 0;
0189 for (G4int j = 0; j < nhits; j++) {
0190 G4ThreeVector hitPos = (*fMuonHits)[j]->GetPos();
0191 G4int nhitIn = 0;
0192 for (G4int jj = 0; (jj < nTrkhits) && (nhitIn <= fReqIso); jj++) {
0193 G4ThreeVector trkhitPos = (*fTrkHits)[jj]->GetPos();
0194 if (trkhitPos.angle(hitPos) < fAngRoI) nhitIn++;
0195 }
0196 if (nhitIn <= fReqIso) isoMuon++;
0197 }
0198 G4cout << "Stage 1->2 : " << isoMuon << " isolated muon found." << G4endl;
0199 if (isoMuon < fReqIsoMuon) {
0200 stackManager->clear();
0201 G4cout << "++++++++ event aborted" << G4endl;
0202 return;
0203 }
0204 stackManager->ReClassify();
0205 return;
0206 }
0207
0208 else {
0209
0210 stackManager->ReClassify();
0211 }
0212 }
0213
0214
0215 void ExN04StackingAction::PrepareNewEvent()
0216 {
0217 fStage = 0;
0218 fTrkHits = 0;
0219 fMuonHits = 0;
0220 }