Go to the documentation of this file.00001 #include "SimG4Core/CountProcesses/interface/CountProcessesAction.h"
00002
00003 #include "SimG4Core/Notification/interface/BeginOfRun.h"
00004 #include "SimG4Core/Notification/interface/EndOfRun.h"
00005 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
00006
00007 #include "G4Track.hh"
00008 #include "G4Run.hh"
00009 #include "G4Event.hh"
00010 #include "G4Step.hh"
00011 #include "G4ProcessManager.hh"
00012 #include "G4ParticleTable.hh"
00013
00014 CountProcessesAction::CountProcessesAction(edm::ParameterSet const & p)
00015 : fDEBUG(p.getUntrackedParameter<bool>("DEBUG",false))
00016 {}
00017
00018 CountProcessesAction::~CountProcessesAction() {}
00019
00020 void CountProcessesAction::update(const BeginOfRun * run)
00021 {
00022 G4ParticleTable * partTable = G4ParticleTable::GetParticleTable();
00023 int siz = partTable->size();
00024 for (int ii= 0; ii < siz; ii++)
00025 {
00026 G4ParticleDefinition * particle = partTable->GetParticle(ii);
00027 std::string particleName = particle->GetParticleName();
00028 if (fDEBUG)
00029 std::cout << ii << " PCA " << particleName<< " " << particle->GetPDGStable()
00030 << " " << particle->IsShortLived() << std::endl;
00031 theParticleList[particleName] = 0;
00032
00033
00034 G4ProcessManager * pmanager = particle->GetProcessManager();
00035 G4ProcessVector * pvect = pmanager->GetProcessList();
00036 int sizproc = pvect->size();
00037 for (int jj = 0; jj < sizproc; jj++)
00038 {
00039 std::string processName = (*pvect)[jj]->GetProcessName();
00040 if (fDEBUG)
00041 std::cout << jj << " PCR " << processName<< std::endl;
00042 theProcessList[pss(particleName,processName)] = 0;
00043 }
00044 }
00045 DumpProcessList(0);
00046 }
00047
00048 void CountProcessesAction::update(const BeginOfTrack * trk)
00049 {
00050
00051 const G4Track * aTrack = (*trk)();
00052 std::string particleName = aTrack->GetDefinition()->GetParticleName();
00053 theParticleList[particleName]++;
00054
00055
00056 const G4VProcess * proc = aTrack->GetCreatorProcess();
00057 std::string processName;
00058 if (proc != 0) processName = proc->GetProcessName();
00059 else processName = "Primary";
00060 pss parproc(particleName,processName);
00061 mpssi::iterator ite = theCreatorProcessList.find(parproc);
00062 if (ite == theCreatorProcessList.end()) theCreatorProcessList[ parproc ] = 1;
00063 else (*ite).second = (*ite).second +1;
00064 if (fDEBUG)
00065 std::cout << " creator " << particleName << " " << processName
00066 << theCreatorProcessList.size() << std::endl;
00067 }
00068
00069 void CountProcessesAction::update(const G4Step* aStep )
00070 {
00071 std::string processName;
00072 if(aStep->GetPostStepPoint()->GetProcessDefinedStep() != 0)
00073 processName = aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
00074 else processName = "User Limit";
00075 std::string particleName = aStep->GetTrack()->GetDefinition()->GetParticleName();
00076 theProcessList[pss(particleName,processName)] = theProcessList[pss(particleName,processName)] + 1;
00077 }
00078
00079 void CountProcessesAction::update(const EndOfRun * run)
00080 {
00081 DumpProcessList(1);
00082 DumpCreatorProcessList(1);
00083 DumpParticleList();
00084 }
00085
00086 void CountProcessesAction::DumpProcessList(bool printNsteps, std::ostream& out)
00087 {
00088 mpssi::iterator ite;
00089 for (ite = theProcessList.begin(); ite != theProcessList.end(); ite++)
00090 {
00091 if (!printNsteps)
00092 out << "PROC_LIST " << (*ite).first.first << " : "
00093 << (*ite) .first.second << std::endl;
00094 else if ((*ite).second != 0)
00095 out << "PROC_COUNT " << (*ite).first.first << " : "
00096 << (*ite) .first.second << " = " << (*ite).second << std::endl;
00097 }
00098 }
00099
00100 void CountProcessesAction::DumpCreatorProcessList(bool printNsteps, std::ostream& out)
00101 {
00102 mpssi::iterator ite;
00103 for (ite = theCreatorProcessList.begin(); ite != theCreatorProcessList.end(); ite++)
00104 {
00105 if (!printNsteps)
00106 out << "PROC-CREATOR_LIST " << (*ite).first.first << " : "
00107 <<(*ite) .first.second << std::endl;
00108 else if ((*ite).second != 0)
00109 out << "PROC_CREATOR_COUNT " << (*ite).first.first << " : "
00110 <<(*ite) .first.second << " = " << (*ite).second << std::endl;
00111 }
00112 }
00113
00114 void CountProcessesAction::DumpParticleList(std::ostream& out)
00115 {
00116 psi::iterator ite;
00117 for (ite = theParticleList.begin(); ite != theParticleList.end(); ite++)
00118 {
00119 if ((*ite).second != 0)
00120 out << "PART_LIST: " << (*ite).first << " = " << (*ite).second << std::endl;
00121 }
00122 }
00123