00001 #include "SimG4Core/Application/interface/TrackingAction.h"
00002 #include "SimG4Core/Application/interface/EventAction.h"
00003 #include "SimG4Core/Notification/interface/NewTrackAction.h"
00004 #include "SimG4Core/Notification/interface/CurrentG4Track.h"
00005 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
00006 #include "SimG4Core/Notification/interface/EndOfTrack.h"
00007 #include "SimG4Core/Notification/interface/TrackInformation.h"
00008 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
00009 #include "SimG4Core/Notification/interface/TrackInformationExtractor.h"
00010 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00011
00012 #include "G4UImanager.hh"
00013 #include "G4TrackingManager.hh"
00014
00015 TrackingAction::TrackingAction(EventAction * e, const edm::ParameterSet & p)
00016 : eventAction_(e),currentTrack_(0),
00017 detailedTiming(p.getUntrackedParameter<bool>("DetailedTiming",false)),
00018 trackMgrVerbose(p.getUntrackedParameter<int>("G4TrackManagerVerbosity",0)){}
00019
00020 TrackingAction::~TrackingAction() {}
00021
00022 void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)
00023 {
00024 CurrentG4Track::setTrack(aTrack);
00025
00026 if (currentTrack_ != 0)
00027 throw SimG4Exception("TrackingAction: currentTrack is a mess...");
00028 currentTrack_ = new TrackWithHistory(aTrack);
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 BeginOfTrack bt(aTrack);
00043 m_beginOfTrackSignal(&bt);
00044 }
00045
00046 void TrackingAction::PostUserTrackingAction(const G4Track * aTrack)
00047 {
00048 CurrentG4Track::postTracking(aTrack);
00049 if (eventAction_->trackContainer() != 0)
00050 {
00051
00052 TrackInformationExtractor extractor;
00053 if (extractor(aTrack).storeTrack())
00054 {
00055 currentTrack_->save();
00056
00057 math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
00058 (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
00059 (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
00060 math::XYZTLorentzVectorD mom;
00061
00062 uint32_t id = aTrack->GetTrackID();
00063
00064 std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p(pos,mom);
00065 eventAction_->addTkCaloStateInfo(id,p);
00066
00067 }
00068 if (extractor(aTrack).isInHistory())
00069 {
00070 currentTrack_->checkAtEnd(aTrack);
00071 eventAction_->addTrack(currentTrack_, true);
00072 }
00073 else
00074 {
00075 eventAction_->addTrack(currentTrack_, false);
00076 delete currentTrack_;
00077 }
00078 }
00079 EndOfTrack et(aTrack);
00080 m_endOfTrackSignal(&et);
00081 currentTrack_ = 0;
00082 }
00083
00084 G4TrackingManager * TrackingAction::getTrackManager()
00085 {
00086 G4TrackingManager * theTrackingManager = 0;
00087 theTrackingManager = fpTrackingManager;
00088 theTrackingManager->SetVerboseLevel(trackMgrVerbose);
00089 return theTrackingManager;
00090 }
00091