CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingAction.cc
Go to the documentation of this file.
11 
13 
14 #include "G4UImanager.hh"
15 #include "G4TrackingManager.hh"
16 #include "G4PhysicalVolumeStore.hh"
17 #include "G4TransportationManager.hh"
18 
19 //#define DebugLog
20 
22  : eventAction_(e),currentTrack_(0),
23  detailedTiming(p.getUntrackedParameter<bool>("DetailedTiming",false)),
24  checkTrack(p.getUntrackedParameter<bool>("CheckTrack",false)),
25  trackMgrVerbose(p.getUntrackedParameter<int>("G4TrackManagerVerbosity",0))
26 {
27  worldSolid = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()->GetSolid();
28 }
29 
31 
32 void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)
33 {
35 
36  if (currentTrack_ != 0) {
37  throw SimG4Exception("TrackingAction: currentTrack is a mess...");
38  }
39  currentTrack_ = new TrackWithHistory(aTrack);
40 
41  /*
42  Trick suggested by Vladimir I. in order to debug with high
43  level verbosity only a single problematic tracks
44  */
45 
46  /*
47  if ( aTrack->GetTrackID() == palce_here_the_trackid_of_problematic_tracks ) {
48  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 6");
49  } else if ( aTrack->GetTrackID() == place_here_the_trackid_of_following_track_to_donwgrade_the_severity ) {
50  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 0");
51  }
52  */
53  BeginOfTrack bt(aTrack);
55 
56  TrackInformation * trkInfo = (TrackInformation *)aTrack->GetUserInformation();
57  if(trkInfo->isPrimary()) {
59  }
60  /*
61  G4cout << "Track " << aTrack->GetTrackID() << " R "
62  << (aTrack->GetVertexPosition()).r() << " Z "
63  << std::abs((aTrack->GetVertexPosition()).z()) << G4endl << "Top Solid "
64  << worldSolid->GetName() << " is it inside "
65  << worldSolid->Inside(aTrack->GetVertexPosition())
66  << " compared to " << kOutside << G4endl;
67  */
68  if (worldSolid->Inside(aTrack->GetVertexPosition()) == kOutside) {
69  // G4cout << "Kill Track " << aTrack->GetTrackID() << G4endl;
70  G4Track* theTrack = (G4Track *)(aTrack);
71  theTrack->SetTrackStatus(fStopAndKill);
72  }
73 }
74 
75 void TrackingAction::PostUserTrackingAction(const G4Track * aTrack)
76 {
78  if (eventAction_->trackContainer() != 0) {
79 
80  TrackInformationExtractor extractor;
81  if (extractor(aTrack).storeTrack()) {
83 
84  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
85  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
86  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
88 
89  uint32_t id = aTrack->GetTrackID();
90 
91  std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p(pos,mom);
93 #ifdef DebugLog
94  LogDebug("SimTrackManager") << "TrackingAction addTkCaloStateInfo "
95  << id << " of momentum " << mom << " at " << pos;
96 #endif
97  }
98 
99  bool withAncestor =
100  ((extractor(aTrack).getIDonCaloSurface() == aTrack->GetTrackID())
101  || (extractor(aTrack).isAncestor()));
102 
103  if (extractor(aTrack).isInHistory()) {
104 
105  // check with end-of-track information
106  if(checkTrack) { currentTrack_->checkAtEnd(aTrack); }
107 
108  eventAction_->addTrack(currentTrack_, true, withAncestor);
109 #ifdef DebugLog
110  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
111  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
112  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
113  LogDebug("SimTrackManager") << "TrackingAction addTrack "
114  << currentTrack_->trackID()
115  << " added with " << true << " and " << withAncestor
116  << " at " << pos;
117 #endif
118 
119  } else {
120  eventAction_->addTrack(currentTrack_, false, false);
121 
122 #ifdef DebugLog
123  LogDebug("SimTrackManager") << "TrackingAction addTrack "
124  << currentTrack_->trackID() << " added with "
125  << false << " and " << false;
126 #endif
127 
128  delete currentTrack_;
129  }
130  }
131  EndOfTrack et(aTrack);
132  m_endOfTrackSignal(&et);
133  currentTrack_ = 0; // reset for next track
134 }
135 
136 G4TrackingManager * TrackingAction::getTrackManager()
137 {
138  G4TrackingManager * theTrackingManager = 0;
139  theTrackingManager = fpTrackingManager;
140  theTrackingManager->SetVerboseLevel(trackMgrVerbose);
141  return theTrackingManager;
142 }
#define LogDebug(id)
virtual ~TrackingAction()
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
static void setTrack(const G4Track *)
virtual void PreUserTrackingAction(const G4Track *aTrack)
TrackWithHistory * currentTrack_
float float float z
void prepareForNewPrimary()
Definition: EventAction.h:43
G4VSolid * worldSolid
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
EventAction * eventAction_
G4TrackingManager * getTrackManager()
unsigned int trackID() const
static void postTracking(const G4Track *)
void checkAtEnd(const G4Track *)
TrackingAction(EventAction *ea, const edm::ParameterSet &ps)
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
const TrackContainer * trackContainer() const
Definition: EventAction.h:38
virtual void PostUserTrackingAction(const G4Track *aTrack)
bool isPrimary() const
void addTkCaloStateInfo(uint32_t t, const std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > &p)
Definition: EventAction.cc:75
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
Definition: EventAction.cc:70
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal