CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/SimG4Core/Application/src/TrackingAction.cc

Go to the documentation of this file.
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 "FWCore/MessageLogger/interface/MessageLogger.h"
00013 
00014 #include "G4UImanager.hh" 
00015 #include "G4TrackingManager.hh"
00016 #include "G4PhysicalVolumeStore.hh"
00017 #include "G4TransportationManager.hh"
00018 
00019 //#define DebugLog
00020 
00021 TrackingAction::TrackingAction(EventAction * e, const edm::ParameterSet & p) 
00022   : eventAction_(e),currentTrack_(0),
00023   detailedTiming(p.getUntrackedParameter<bool>("DetailedTiming",false)),
00024   trackMgrVerbose(p.getUntrackedParameter<int>("G4TrackManagerVerbosity",0)) {
00025 
00026   worldSolid = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume()->GetSolid();
00027 }
00028 
00029 TrackingAction::~TrackingAction() {}
00030 
00031 void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)
00032 {
00033 
00034     CurrentG4Track::setTrack(aTrack);
00035 
00036     if (currentTrack_ != 0) 
00037         throw SimG4Exception("TrackingAction: currentTrack is a mess...");
00038     currentTrack_ = new TrackWithHistory(aTrack);
00039 
00040     /*
00041       Trick suggested by Vladimir I. in order to debug with high 
00042       level verbosity only a single problematic tracks
00043     */      
00044 
00045     /*
00046     if ( aTrack->GetTrackID() == palce_here_the_trackid_of_problematic_tracks  ) {
00047       G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 6");
00048     } else if ( aTrack->GetTrackID() == place_here_the_trackid_of_following_track_to_donwgrade_the_severity ) {
00049       G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 0");
00050     }
00051     */
00052     BeginOfTrack bt(aTrack);
00053     m_beginOfTrackSignal(&bt);
00054 
00055     if (isNewPrimary(aTrack)) {
00056       eventAction_->prepareForNewPrimary();
00057     }
00058     //    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;
00059     if (worldSolid->Inside(aTrack->GetVertexPosition()) == kOutside) {
00060       //      G4cout << "Kill Track " << aTrack->GetTrackID() << G4endl;
00061       G4Track* theTrack = (G4Track *)(aTrack);
00062       theTrack->SetTrackStatus(fStopAndKill);
00063     }      
00064 
00065 }
00066 
00067 void TrackingAction::PostUserTrackingAction(const G4Track * aTrack)
00068 {
00069     CurrentG4Track::postTracking(aTrack);
00070     if (eventAction_->trackContainer() != 0)
00071     {
00072 
00073       TrackInformationExtractor extractor;
00074       if (extractor(aTrack).storeTrack())
00075         {
00076           currentTrack_->save();
00077           
00078           math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
00079                                (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
00080                                (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
00081           math::XYZTLorentzVectorD mom;
00082           
00083           uint32_t id = aTrack->GetTrackID();
00084           
00085           std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p(pos,mom);
00086           eventAction_->addTkCaloStateInfo(id,p);
00087 #ifdef DebugLog
00088           LogDebug("SimTrackManager") << "TrackingAction addTkCaloStateInfo " << id << " of momentum " << mom << " at " << pos;
00089 #endif
00090         }
00091 
00092       bool withAncestor = ((extractor(aTrack).getIDonCaloSurface() == aTrack->GetTrackID()) || (extractor(aTrack).isAncestor()));
00093       if (extractor(aTrack).isInHistory())
00094         {
00095           currentTrack_->checkAtEnd(aTrack);  // check with end-of-track information
00096           eventAction_->addTrack(currentTrack_, true, withAncestor);
00097 #ifdef DebugLog
00098           math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
00099                                (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
00100                                (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
00101           LogDebug("SimTrackManager") << "TrackingAction addTrack "  << currentTrack_->trackID() << " added with " << true << " and " << withAncestor << " at " << pos;
00102 #endif
00103         }
00104       else
00105         {
00106           eventAction_->addTrack(currentTrack_, false, false);
00107 #ifdef DebugLog
00108           LogDebug("SimTrackManager") << "TrackingAction addTrack " << currentTrack_->trackID() << " added with " << false << " and " << false;
00109 #endif
00110           delete currentTrack_;
00111         }
00112     }
00113     EndOfTrack et(aTrack);
00114     m_endOfTrackSignal(&et);
00115     currentTrack_ = 0; // reset for next track
00116 }
00117 
00118 G4TrackingManager * TrackingAction::getTrackManager()
00119 {
00120     G4TrackingManager * theTrackingManager = 0;
00121     theTrackingManager = fpTrackingManager;
00122     theTrackingManager->SetVerboseLevel(trackMgrVerbose);
00123     return theTrackingManager;
00124 }
00125  
00126 bool TrackingAction::isNewPrimary(const G4Track * aTrack){
00127 
00128   TrackInformation * trkInfo = (TrackInformation *)aTrack->GetUserInformation();
00129   return trkInfo->isPrimary();
00130 
00131 }