CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/SimG4Core/PrintTrackNumber/src/PrintTrackNumberAction.cc

Go to the documentation of this file.
00001 #include "SimG4Core/PrintTrackNumber/interface/PrintTrackNumberAction.h"
00002 
00003 #include "SimG4Core/Notification/interface/EndOfTrack.h"
00004 #include "SimG4Core/Notification/interface/EndOfEvent.h"
00005 
00006 #include "G4Track.hh"
00007 #include "G4Event.hh"
00008 #include "G4VProcess.hh"
00009 
00010 PrintTrackNumberAction::PrintTrackNumberAction(edm::ParameterSet const & p)
00011     : theNoTracks(0), theNoTracksThisEvent(0),
00012       theNoTracksNoUL(0), theNoTracksThisEventNoUL(0)
00013 {
00014     theNoTracksToPrint = p.getUntrackedParameter<int>("EachNTrack",-1); 
00015     // do not count tracks killed by user limits (MinEkineCut for the moment only)
00016     bNoUserLimits = p.getUntrackedParameter<bool>("NoUserLimits", true); 
00017     std::cout << " PrintTrackNumberAction::bNoUserLimits " << bNoUserLimits << std::endl; 
00018 }
00019  
00020 PrintTrackNumberAction::~PrintTrackNumberAction() {}
00021  
00022 void PrintTrackNumberAction::update(const EndOfTrack * trk)
00023 {
00024     const G4Track * aTrack = (*trk)(); 
00025 
00026     theNoTracks++;
00027     theNoTracksThisEvent++;
00028 
00029     if (bNoUserLimits) 
00030     {
00031         bool countTrk = 1;
00032         // tracks that have been killed before first step (by MinEkineCut). 
00033         // In fact the track makes the first step, MinEkineCut process determines 
00034         // that the energy is too low, set it to 0, and then at the next step 
00035         // the 0-energy particle dies
00036         if (aTrack->GetCurrentStepNumber() == 2) 
00037         {
00038             const G4VProcess* proccur = 
00039                 aTrack->GetStep()->GetPostStepPoint()->GetProcessDefinedStep();
00040             if (proccur != 0)
00041             {
00042                 if (proccur->GetProcessName() == "MinEkineCut") 
00043                 {
00044                     countTrk = false;
00045                 } 
00046                 else 
00047                 {
00048                     // for e+, last step is annihil, while previous is MinEkineCut
00049                     const G4VProcess* procprev = 
00050                         aTrack->GetStep()->GetPreStepPoint()->GetProcessDefinedStep();
00051                     if (procprev != 0)
00052                     {
00053                         if (procprev->GetProcessName() == "MinEkineCut") 
00054                         {
00055                             countTrk = false;
00056                         }
00057                     }
00058                 }
00059             }
00060         }
00061         if (countTrk) 
00062         {
00063             theNoTracksNoUL++;
00064             theNoTracksThisEventNoUL++;
00065             if (theNoTracksToPrint > 0) 
00066             {
00067                 if (theNoTracksThisEventNoUL%theNoTracksToPrint == 0) 
00068                 {
00069                     std::cout << "PTNA: Simulating Track Number = " 
00070                               << theNoTracksThisEventNoUL << std::endl;
00071                 }
00072             }
00073         }
00074     } 
00075     else 
00076     {
00077         if (theNoTracksToPrint > 0) 
00078         {
00079             if (theNoTracksThisEvent%theNoTracksToPrint == 0) 
00080             {
00081                 std::cout << "PTNA: Simulating Track Number = " 
00082                           << theNoTracksThisEvent << std::endl;
00083             }
00084         }
00085     }
00086 }
00087 
00088 
00089 void PrintTrackNumberAction::update(const EndOfEvent * e)
00090 {
00091     const G4Event * g4e = (*e)(); 
00092     std::cout << "PTNA: Event simulated= " << g4e->GetEventID() << " #tracks= ";
00093     if (bNoUserLimits) 
00094     {
00095         std::cout << theNoTracksThisEventNoUL << "  Total #tracks in run= " 
00096                   << theNoTracksNoUL << " counting killed by UL= " << theNoTracks 
00097                   << std::endl;
00098         theNoTracksThisEventNoUL = 0;
00099     } 
00100     else 
00101     {
00102         std::cout << theNoTracksThisEvent << "  Total #tracks in run= " 
00103                   << theNoTracks << std::endl;
00104         theNoTracksThisEvent = 0;
00105     }
00106 }
00107