CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/SimG4Core/Application/src/EventAction.cc

Go to the documentation of this file.
00001 #include "SimG4Core/Application/interface/RunManager.h"
00002 #include "SimG4Core/Application/interface/EventAction.h"
00003 #include "SimG4Core/Application/interface/G4SimVertex.h"
00004 #include "SimG4Core/Application/interface/G4SimTrack.h"
00005 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00006 #include "SimG4Core/Notification/interface/EndOfEvent.h"
00007 
00008 #include <fstream>
00009 
00010 using std::cout;
00011 using std::endl;
00012 
00013 EventAction::EventAction(const edm::ParameterSet & p,
00014                          RunManager* rm,
00015                          SimTrackManager* iManager) 
00016     : m_runManager(rm),
00017       m_trackManager(iManager),
00018       m_stopFile(p.getParameter<std::string>("StopFile")),
00019       m_debug(p.getUntrackedParameter<bool>("debug",false))
00020 {
00021   m_trackManager->setCollapsePrimaryVertices(p.getParameter<bool>("CollapsePrimaryVertices"));
00022 }
00023 
00024 EventAction::~EventAction() {}
00025     
00026 void EventAction::BeginOfEventAction(const G4Event * anEvent)
00027 {
00028     if (std::ifstream(m_stopFile.c_str()))
00029     {
00030         cout << "BeginOfEventAction: termination signal received at event "
00031              << anEvent->GetEventID() << endl;
00032         //RunManager::instance()->abortRun(true);
00033         m_runManager->abortRun(true);
00034     }
00035 
00036     m_trackManager->reset();
00037     BeginOfEvent e(anEvent);
00038     m_beginOfEventSignal(&e);
00039 
00040 }
00041 
00042 void EventAction::EndOfEventAction(const G4Event * anEvent)
00043 {
00044     if (std::ifstream(m_stopFile.c_str()))
00045     {
00046         cout << "EndOfEventAction: termination signal received at event "
00047              << anEvent->GetEventID() << endl;
00048         //RunManager::instance()->abortRun(true);
00049         m_runManager->abortRun(this);
00050     }
00051     if (anEvent->GetNumberOfPrimaryVertex()==0)
00052     {
00053         cout << " EndOfEventAction: event " << anEvent->GetEventID()
00054              << " must have failed (no G4PrimaryVertices found) and will be skipped " << endl;
00055         return;
00056     }
00057 
00058     // m_trackManager->storeTracks(RunManager::instance()->simEvent());
00059     m_trackManager->storeTracks(m_runManager->simEvent());
00060     // dispatch now end of event, and only then delete tracks...
00061     EndOfEvent e(anEvent);
00062     m_endOfEventSignal(&e);
00063 
00064     m_trackManager->deleteTracks();
00065     m_trackManager->cleanTkCaloStateInfoMap();
00066 
00067 }
00068 
00069 void EventAction::addTrack(TrackWithHistory* iTrack, bool inHistory, bool withAncestor)
00070 {
00071   m_trackManager->addTrack(iTrack, inHistory, withAncestor);
00072 }
00073 
00074 void EventAction::addTkCaloStateInfo(uint32_t t,std::pair< math::XYZVectorD ,math::XYZTLorentzVectorD> p)
00075 {
00076   m_trackManager->addTkCaloStateInfo(t,p);
00077 }