CMS 3D CMS Logo

PrintTrackNumberAction.cc
Go to the documentation of this file.
2 
5 
6 #include "G4Event.hh"
7 #include "G4Track.hh"
8 #include "G4VProcess.hh"
9 
11  : theNoTracks(0), theNoTracksThisEvent(0), theNoTracksNoUL(0), theNoTracksThisEventNoUL(0) {
12  theNoTracksToPrint = p.getUntrackedParameter<int>("EachNTrack", -1);
13  // do not count tracks killed by user limits (MinEkineCut for the moment only)
14  bNoUserLimits = p.getUntrackedParameter<bool>("NoUserLimits", true);
15  std::cout << " PrintTrackNumberAction::bNoUserLimits " << bNoUserLimits << std::endl;
16 }
17 
19 
21  const G4Track *aTrack = (*trk)();
22 
23  theNoTracks++;
25 
26  if (bNoUserLimits) {
27  bool countTrk = true;
28  // tracks that have been killed before first step (by MinEkineCut).
29  // In fact the track makes the first step, MinEkineCut process determines
30  // that the energy is too low, set it to 0, and then at the next step
31  // the 0-energy particle dies
32  if (aTrack->GetCurrentStepNumber() == 2) {
33  const G4VProcess *proccur = aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep();
34  if (proccur != nullptr) {
35  if (proccur->GetProcessName() == "MinEkineCut") {
36  countTrk = false;
37  } else {
38  // for e+, last step is annihil, while previous is MinEkineCut
39  const G4VProcess *procprev = aTrack->GetStep()->GetPreStepPoint()->GetProcessDefinedStep();
40  if (procprev != nullptr) {
41  if (procprev->GetProcessName() == "MinEkineCut") {
42  countTrk = false;
43  }
44  }
45  }
46  }
47  }
48  if (countTrk) {
51  if (theNoTracksToPrint > 0) {
53  std::cout << "PTNA: Simulating Track Number = " << theNoTracksThisEventNoUL << std::endl;
54  }
55  }
56  }
57  } else {
58  if (theNoTracksToPrint > 0) {
60  std::cout << "PTNA: Simulating Track Number = " << theNoTracksThisEvent << std::endl;
61  }
62  }
63  }
64 }
65 
67  const G4Event *g4e = (*e)();
68  std::cout << "PTNA: Event simulated= " << g4e->GetEventID() << " #tracks= ";
69  if (bNoUserLimits) {
70  std::cout << theNoTracksThisEventNoUL << " Total #tracks in run= " << theNoTracksNoUL
71  << " counting killed by UL= " << theNoTracks << std::endl;
73  } else {
74  std::cout << theNoTracksThisEvent << " Total #tracks in run= " << theNoTracks << std::endl;
76  }
77 }
PrintTrackNumberAction(edm::ParameterSet const &p)
T getUntrackedParameter(std::string const &, T const &) const
void update(const EndOfTrack *trk) override
This routine will be called when the appropriate signal arrives.