Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:31

0001 #include "SimG4Core/PrintTrackNumber/interface/PrintTrackNumberAction.h"
0002 
0003 #include "SimG4Core/Notification/interface/EndOfEvent.h"
0004 #include "SimG4Core/Notification/interface/EndOfTrack.h"
0005 
0006 #include "G4Event.hh"
0007 #include "G4ios.hh"
0008 #include "G4Track.hh"
0009 #include "G4VProcess.hh"
0010 
0011 PrintTrackNumberAction::PrintTrackNumberAction(edm::ParameterSet const &p)
0012     : theNoTracks(0), theNoTracksThisEvent(0), theNoTracksNoUL(0), theNoTracksThisEventNoUL(0) {
0013   theNoTracksToPrint = p.getUntrackedParameter<int>("EachNTrack", -1);
0014   // do not count tracks killed by user limits (MinEkineCut for the moment only)
0015   bNoUserLimits = p.getUntrackedParameter<bool>("NoUserLimits", true);
0016   G4cout << " PrintTrackNumberAction::bNoUserLimits " << bNoUserLimits << G4endl;
0017 }
0018 
0019 PrintTrackNumberAction::~PrintTrackNumberAction() {}
0020 
0021 void PrintTrackNumberAction::update(const EndOfTrack *trk) {
0022   const G4Track *aTrack = (*trk)();
0023 
0024   theNoTracks++;
0025   theNoTracksThisEvent++;
0026 
0027   if (bNoUserLimits) {
0028     bool countTrk = true;
0029     // tracks that have been killed before first step (by MinEkineCut).
0030     // In fact the track makes the first step, MinEkineCut process determines
0031     // that the energy is too low, set it to 0, and then at the next step
0032     // the 0-energy particle dies
0033     if (aTrack->GetCurrentStepNumber() == 2) {
0034       const G4VProcess *proccur = aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep();
0035       if (proccur != nullptr) {
0036         if (proccur->GetProcessName() == "MinEkineCut") {
0037           countTrk = false;
0038         } else {
0039           // for e+, last step is annihil, while previous is MinEkineCut
0040           const G4VProcess *procprev = aTrack->GetStep()->GetPreStepPoint()->GetProcessDefinedStep();
0041           if (procprev != nullptr) {
0042             if (procprev->GetProcessName() == "MinEkineCut") {
0043               countTrk = false;
0044             }
0045           }
0046         }
0047       }
0048     }
0049     if (countTrk) {
0050       theNoTracksNoUL++;
0051       theNoTracksThisEventNoUL++;
0052       if (theNoTracksToPrint > 0) {
0053         if (theNoTracksThisEventNoUL % theNoTracksToPrint == 0) {
0054           G4cout << "PTNA: Simulating Track Number = " << theNoTracksThisEventNoUL << G4endl;
0055         }
0056       }
0057     }
0058   } else {
0059     if (theNoTracksToPrint > 0) {
0060       if (theNoTracksThisEvent % theNoTracksToPrint == 0) {
0061         G4cout << "PTNA: Simulating Track Number = " << theNoTracksThisEvent << G4endl;
0062       }
0063     }
0064   }
0065 }
0066 
0067 void PrintTrackNumberAction::update(const EndOfEvent *e) {
0068   const G4Event *g4e = (*e)();
0069   G4cout << "PTNA: Event simulated= " << g4e->GetEventID() << " #tracks= ";
0070   if (bNoUserLimits) {
0071     G4cout << theNoTracksThisEventNoUL << "  Total #tracks in run= " << theNoTracksNoUL
0072            << " counting killed by UL= " << theNoTracks << G4endl;
0073     theNoTracksThisEventNoUL = 0;
0074   } else {
0075     G4cout << theNoTracksThisEvent << "  Total #tracks in run= " << theNoTracks << G4endl;
0076     theNoTracksThisEvent = 0;
0077   }
0078 }