CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/SimG4Core/Notification/src/NewTrackAction.cc

Go to the documentation of this file.
00001 #include "SimG4Core/Notification/interface/NewTrackAction.h"
00002 #include "SimG4Core/Notification/interface/TrackInformation.h"
00003 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00004 #include "SimG4Core/Notification/interface/TrackInformationExtractor.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "G4Track.hh"
00009 
00010 //#define DebugLog
00011 
00012 NewTrackAction::NewTrackAction() {}
00013 
00014 void NewTrackAction::primary(const G4Track * aTrack) const {
00015   primary(const_cast<G4Track *>(aTrack)); 
00016 }
00017 
00018 void NewTrackAction::primary(G4Track * aTrack) const {
00019   addUserInfoToPrimary(aTrack);
00020 }
00021 
00022 void NewTrackAction::secondary(const G4Track * aSecondary,const G4Track & mother, int flag) const {
00023   secondary(const_cast<G4Track *>(aSecondary),mother,flag); 
00024 }
00025 
00026 void NewTrackAction::secondary(G4Track * aSecondary,const G4Track & mother, int flag) const {
00027   if (aSecondary->GetParentID() != mother.GetTrackID()) 
00028     throw SimG4Exception("NewTrackAction: secondary parent ID does not match mother id");
00029   TrackInformationExtractor extractor;
00030   const TrackInformation & motherInfo(extractor(mother));
00031   addUserInfoToSecondary(aSecondary,motherInfo,flag);
00032 #ifdef DebugLog
00033   LogDebug("SimTrackManager") << "NewTrackAction: Add track " << aSecondary->GetTrackID() << " from mother " << mother.GetTrackID();
00034 #endif
00035 }
00036 
00037 void NewTrackAction::addUserInfoToPrimary(G4Track * aTrack) const {
00038   TrackInformation * trkInfo = new TrackInformation();
00039   trkInfo->isPrimary(true);
00040   trkInfo->storeTrack(true);
00041   trkInfo->putInHistory();
00042   trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
00043   trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
00044   aTrack->SetUserInformation(trkInfo);  
00045 }
00046 
00047 void NewTrackAction::addUserInfoToSecondary(G4Track * aTrack,const TrackInformation & motherInfo, int flag) const {
00048 
00049   TrackInformation * trkInfo = new TrackInformation();
00050 //  LogDebug("SimG4CoreApplication") << "NewTrackAction called for "
00051 //                                 << aTrack->GetTrackID()
00052 //                                 << " mother " << motherInfo.isPrimary()
00053 //                                 << " flag " << flag;
00054   
00055   // Take care of cascade decays
00056   if (flag == 1) {
00057     trkInfo->isPrimary(true);
00058     trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
00059     trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
00060   } else {
00061     trkInfo->setGenParticlePID(motherInfo.genParticlePID());
00062     trkInfo->setGenParticleP(motherInfo.genParticleP());
00063   }
00064 
00065   // Store if decay or conversion
00066   if (flag > 0) {
00067     trkInfo->storeTrack(true);
00068     trkInfo->putInHistory();
00069     trkInfo->setIDonCaloSurface(aTrack->GetTrackID(),
00070                                 motherInfo.getIDCaloVolume(),
00071                                 motherInfo.getIDLastVolume(),
00072                                 aTrack->GetDefinition()->GetPDGEncoding(),
00073                                 aTrack->GetMomentum().mag());
00074   } else {
00075     // transfer calo ID from mother (to be checked in TrackingAction)
00076     trkInfo->setIDonCaloSurface(motherInfo.getIDonCaloSurface(),
00077                                 motherInfo.getIDCaloVolume(),
00078                                 motherInfo.getIDLastVolume(),
00079                                 motherInfo.caloSurfaceParticlePID(),
00080                                 motherInfo.caloSurfaceParticleP());
00081   }
00082   aTrack->SetUserInformation(trkInfo);  
00083 }