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  trackMgrVerbose(p.getUntrackedParameter<int>("G4TrackManagerVerbosity",0)) {
25 
26  worldSolid = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()->GetSolid();
27 }
28 
30 
31 void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)
32 {
33 
35 
36  if (currentTrack_ != 0)
37  throw SimG4Exception("TrackingAction: currentTrack is a mess...");
38  currentTrack_ = new TrackWithHistory(aTrack);
39 
40  /*
41  Trick suggested by Vladimir I. in order to debug with high
42  level verbosity only a single problematic tracks
43  */
44 
45  /*
46  if ( aTrack->GetTrackID() == palce_here_the_trackid_of_problematic_tracks ) {
47  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 6");
48  } else if ( aTrack->GetTrackID() == place_here_the_trackid_of_following_track_to_donwgrade_the_severity ) {
49  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 0");
50  }
51  */
52  BeginOfTrack bt(aTrack);
54 
55  if (isNewPrimary(aTrack)) {
57  }
58  // G4cout << "Track " << aTrack->GetTrackID() << " R " << (aTrack->GetVertexPosition()).r() << " Z " << std::abs((aTrack->GetVertexPosition()).z()) << G4endl << "Top Solid " << worldSolid->GetName() << " is it inside " << worldSolid->Inside(aTrack->GetVertexPosition()) << " compared to " << kOutside << G4endl;
59  if (worldSolid->Inside(aTrack->GetVertexPosition()) == kOutside) {
60  // G4cout << "Kill Track " << aTrack->GetTrackID() << G4endl;
61  G4Track* theTrack = (G4Track *)(aTrack);
62  theTrack->SetTrackStatus(fStopAndKill);
63  }
64 
65 }
66 
67 void TrackingAction::PostUserTrackingAction(const G4Track * aTrack)
68 {
70  if (eventAction_->trackContainer() != 0)
71  {
72 
73  TrackInformationExtractor extractor;
74  if (extractor(aTrack).storeTrack())
75  {
77 
78  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
79  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
80  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
82 
83  uint32_t id = aTrack->GetTrackID();
84 
85  std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p(pos,mom);
87 #ifdef DebugLog
88  LogDebug("SimTrackManager") << "TrackingAction addTkCaloStateInfo " << id << " of momentum " << mom << " at " << pos;
89 #endif
90  }
91 
92  bool withAncestor = ((extractor(aTrack).getIDonCaloSurface() == aTrack->GetTrackID()) || (extractor(aTrack).isAncestor()));
93  if (extractor(aTrack).isInHistory())
94  {
95  currentTrack_->checkAtEnd(aTrack); // check with end-of-track information
96  eventAction_->addTrack(currentTrack_, true, withAncestor);
97 #ifdef DebugLog
98  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
99  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
100  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
101  LogDebug("SimTrackManager") << "TrackingAction addTrack " << currentTrack_->trackID() << " added with " << true << " and " << withAncestor << " at " << pos;
102 #endif
103  }
104  else
105  {
106  eventAction_->addTrack(currentTrack_, false, false);
107 #ifdef DebugLog
108  LogDebug("SimTrackManager") << "TrackingAction addTrack " << currentTrack_->trackID() << " added with " << false << " and " << false;
109 #endif
110  delete currentTrack_;
111  }
112  }
113  EndOfTrack et(aTrack);
114  m_endOfTrackSignal(&et);
115  currentTrack_ = 0; // reset for next track
116 }
117 
118 G4TrackingManager * TrackingAction::getTrackManager()
119 {
120  G4TrackingManager * theTrackingManager = 0;
121  theTrackingManager = fpTrackingManager;
122  theTrackingManager->SetVerboseLevel(trackMgrVerbose);
123  return theTrackingManager;
124 }
125 
126 bool TrackingAction::isNewPrimary(const G4Track * aTrack){
127 
128  TrackInformation * trkInfo = (TrackInformation *)aTrack->GetUserInformation();
129  return trkInfo->isPrimary();
130 
131 }
#define LogDebug(id)
virtual ~TrackingAction()
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:15
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:9
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
bool isNewPrimary(const G4Track *aTrack)
Definition: DDAxes.h:10
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
Definition: EventAction.cc:70
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal