test
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 
21 //using namespace std;
22 
24  : eventAction_(e),currentTrack_(0),
25  detailedTiming(p.getUntrackedParameter<bool>("DetailedTiming",false)),
26  checkTrack(p.getUntrackedParameter<bool>("CheckTrack",false)),
27  trackMgrVerbose(p.getUntrackedParameter<int>("G4TrackManagerVerbosity",0))
28 {
29  worldSolid = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()->GetSolid();
30 }
31 
33 
34 void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)
35 {
37 
38  if (currentTrack_ != 0) {
39  throw SimG4Exception("TrackingAction: currentTrack is a mess...");
40  }
41  currentTrack_ = new TrackWithHistory(aTrack);
42 
43  /*
44  Trick suggested by Vladimir I. in order to debug with high
45  level verbosity only a single problematic tracks
46  */
47 
48  /*
49  if ( aTrack->GetTrackID() == palce_here_the_trackid_of_problematic_tracks ) {
50  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 6");
51  } else if ( aTrack->GetTrackID() == place_here_the_trackid_of_following_track_to_donwgrade_the_severity ) {
52  G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 0");
53  }
54  */
55  BeginOfTrack bt(aTrack);
57 
58  TrackInformation * trkInfo = (TrackInformation *)aTrack->GetUserInformation();
59  if(trkInfo && trkInfo->isPrimary()) {
61  }
62  /*
63  G4cout << "Track " << aTrack->GetTrackID() << " R "
64  << (aTrack->GetVertexPosition()).r() << " Z "
65  << std::abs((aTrack->GetVertexPosition()).z()) << G4endl << "Top Solid "
66  << worldSolid->GetName() << " is it inside "
67  << worldSolid->Inside(aTrack->GetVertexPosition())
68  << " compared to " << kOutside << G4endl;
69  */
70  // VI: why this check is TrackingAction?
71  if (worldSolid->Inside(aTrack->GetVertexPosition()) == kOutside) {
72  // G4cout << "Kill Track " << aTrack->GetTrackID() << G4endl;
73  G4Track* theTrack = (G4Track *)(aTrack);
74  theTrack->SetTrackStatus(fStopAndKill);
75  }
76 }
77 
78 void TrackingAction::PostUserTrackingAction(const G4Track * aTrack)
79 {
81  if (eventAction_->trackContainer() != 0) {
82 
83  TrackInformationExtractor extractor;
84  if (extractor(aTrack).storeTrack()) {
86 
87  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
88  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
89  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
91 
92  uint32_t id = aTrack->GetTrackID();
93 
94  std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p(pos,mom);
96 #ifdef DebugLog
97  LogDebug("SimTrackManager") << "TrackingAction addTkCaloStateInfo "
98  << id << " of momentum " << mom << " at " << pos;
99 #endif
100  }
101 
102  bool withAncestor =
103  ((extractor(aTrack).getIDonCaloSurface() == aTrack->GetTrackID())
104  || (extractor(aTrack).isAncestor()));
105 
106  if (extractor(aTrack).isInHistory()) {
107 
108  // check with end-of-track information
109  if(checkTrack) { currentTrack_->checkAtEnd(aTrack); }
110 
111  eventAction_->addTrack(currentTrack_, true, withAncestor);
112  /*
113  cout << "TrackingAction addTrack "
114  << currentTrack_->trackID() << " E(GeV)= " << aTrack->GetKineticEnergy()
115  << " " << aTrack->GetDefinition()->GetParticleName()
116  << " added= " << withAncestor
117  << " at " << aTrack->GetPosition() << endl;
118  */
119 #ifdef DebugLog
120  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
121  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
122  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
123  LogDebug("SimTrackManager") << "TrackingAction addTrack "
124  << currentTrack_->trackID()
125  << " added with " << true << " and " << withAncestor
126  << " at " << pos;
127 #endif
128 
129  } else {
130  eventAction_->addTrack(currentTrack_, false, false);
131 
132 #ifdef DebugLog
133  LogDebug("SimTrackManager") << "TrackingAction addTrack "
134  << currentTrack_->trackID() << " added with "
135  << false << " and " << false;
136 #endif
137 
138  delete currentTrack_;
139  }
140  }
141  EndOfTrack et(aTrack);
142  m_endOfTrackSignal(&et);
143  currentTrack_ = 0; // reset for next track
144 }
145 
146 G4TrackingManager * TrackingAction::getTrackManager()
147 {
148  G4TrackingManager * theTrackingManager = 0;
149  theTrackingManager = fpTrackingManager;
150  theTrackingManager->SetVerboseLevel(trackMgrVerbose);
151  return theTrackingManager;
152 }
#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:90
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
Definition: EventAction.cc:85
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal