Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-10 08:05:40

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file eventgenerator/HepMC/HepMCEx01/src/ExN04StackingAction.cc
0027 /// \brief Implementation of the ExN04StackingAction class
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 ExN04StackingAction::~ExN04StackingAction()
0057 {
0058   delete fMessenger;
0059 }
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 G4ClassificationOfNewTrack ExN04StackingAction::ClassifyNewTrack(const G4Track* aTrack)
0063 {
0064   G4ClassificationOfNewTrack classification = fWaiting;
0065   switch (fStage) {
0066     case 0:  // Stage 0 : Primary muons only
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:  // Stage 1 : Charged primaries only
0078              //           Suspended tracks will be sent to the waiting stack
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:  // Stage 2 : Accept all primaries
0092               //           Accept all secondaries in RoI
0093               //           Kill secondaries outside RoI
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0147 void ExN04StackingAction::NewStage()
0148 {
0149   fStage++;
0150   G4int nhits;
0151   if (fStage == 1) {
0152     // Stage 0->1 : check if at least "fReqMuon" hits on muon chamber
0153     //              otherwise abort current event
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     // Stage 1->2 : check the isolation of muon tracks
0174     //              at least "fReqIsoMuon" isolated muons
0175     //              otherwise abort current event.
0176     //              Isolation requires "fReqIso" or less hits
0177     //              (including own hits) in the RoI region
0178     //              in the tracker layers.
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     // Other fStage change : just re-classify
0210     stackManager->ReClassify();
0211   }
0212 }
0213 
0214 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0215 void ExN04StackingAction::PrepareNewEvent()
0216 {
0217   fStage = 0;
0218   fTrkHits = 0;
0219   fMuonHits = 0;
0220 }