CMS 3D CMS Logo

CMSSimEventManager.cc
Go to the documentation of this file.
6 
9 
10 #include "G4Track.hh"
11 #include "G4Event.hh"
12 #include "G4TrajectoryContainer.hh"
13 #include "G4PrimaryTransformer.hh"
14 #include "G4TrackingManager.hh"
15 #include "G4TrackStatus.hh"
16 #include "G4UserSteppingAction.hh"
17 
18 #include "G4SDManager.hh"
19 #include "G4StateManager.hh"
20 #include "G4ApplicationState.hh"
21 #include "G4TransportationManager.hh"
22 #include "G4Navigator.hh"
23 
25  : verbose_(iConfig.getParameter<int>("EventVerbose")) {
26  m_stateManager = G4StateManager::GetStateManager();
27  m_defTrackManager = new G4TrackingManager();
28  m_primaryTransformer = new G4PrimaryTransformer();
29  m_sdManager = G4SDManager::GetSDMpointerIfExist();
30  m_navigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
31  m_tracks.reserve(1000);
32 }
33 
35  delete m_primaryTransformer;
36  delete m_defTrackManager;
37  delete m_eventAction;
38  delete m_stackingAction;
39 }
40 
41 void CMSSimEventManager::ProcessOneEvent(G4Event* anEvent) {
42  trackID_ = 0;
43  m_stateManager->SetNewState(G4State_EventProc);
44 
45  // Resetting Navigator has been moved to CMSSimEventManager,
46  // so that resetting is now done for every event.
47  G4ThreeVector center(0, 0, 0);
48  m_navigator->LocateGlobalPointAndSetup(center, nullptr, false);
49 
50  G4Track* track = nullptr;
51 
52  anEvent->SetHCofThisEvent(m_sdManager->PrepareNewEvent());
53  m_sdManager->PrepareNewEvent();
55 
56  // Fill primary tracks
57  StackTracks(m_primaryTransformer->GimmePrimaries(anEvent), true);
58 
59  if (0 < verbose_) {
60  edm::LogVerbatim("CMSSimEventManager::ProcessOneEvent")
61  << "### Event #" << anEvent->GetEventID() << " " << trackID_ << " primary tracks";
62  }
63 
64  // Loop over main stack of tracks
65  do {
66  track = m_tracks.back();
67  m_tracks.pop_back();
68  m_defTrackManager->ProcessOneTrack(track);
69  G4TrackVector* secondaries = m_defTrackManager->GimmeSecondaries();
70  StackTracks(secondaries, false);
71  delete track;
72  } while (!m_tracks.empty());
73 
74  m_sdManager->TerminateCurrentEvent(anEvent->GetHCofThisEvent());
76  m_stateManager->SetNewState(G4State_GeomClosed);
77 }
78 
79 void CMSSimEventManager::StackTracks(G4TrackVector* trackVector, bool IDisSet) {
80  if (trackVector == nullptr || trackVector->empty())
81  return;
82  for (auto& newTrack : *trackVector) {
83  ++trackID_;
84  if (!IDisSet) {
85  newTrack->SetTrackID(trackID_);
86  auto pp = newTrack->GetDynamicParticle()->GetPrimaryParticle();
87  if (pp != nullptr) {
88  pp->SetTrackID(trackID_);
89  }
90  }
91  if (m_stackingAction->ClassifyNewTrack(newTrack) == fKill) {
92  delete newTrack;
93  } else {
94  newTrack->SetOriginTouchableHandle(newTrack->GetTouchableHandle());
95  m_tracks.push_back(newTrack);
96  }
97  }
98  trackVector->clear();
99 }
100 
102 
104 
106  m_trackingAction = ptr;
107  m_defTrackManager->SetUserAction((G4UserTrackingAction*)ptr);
108 }
109 
110 void CMSSimEventManager::SetUserAction(G4UserSteppingAction* ptr) { m_defTrackManager->SetUserAction(ptr); }
Log< level::Info, true > LogVerbatim
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack) final
G4PrimaryTransformer * m_primaryTransformer
G4TrackingManager * m_defTrackManager
TrackingAction * m_trackingAction
void BeginOfEventAction(const G4Event *evt) override
Definition: EventAction.cc:25
void ProcessOneEvent(G4Event *anEvent)
G4Navigator * m_navigator
void StackTracks(G4TrackVector *, bool IDisSet)
void EndOfEventAction(const G4Event *evt) override
Definition: EventAction.cc:41
void SetUserAction(EventAction *ptr)
G4StateManager * m_stateManager
EventAction * m_eventAction
G4SDManager * m_sdManager
std::vector< G4Track * > m_tracks
StackingAction * m_stackingAction
CMSSimEventManager(const edm::ParameterSet &iConfig)