Go to the documentation of this file.00001 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
00002 #include "SimG4Core/Notification/interface/G4TrackToParticleID.h"
00003 #include "SimG4Core/Notification/interface/TrackInformationExtractor.h"
00004 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00005 #include "SimG4Core/Notification/interface/GenParticleInfoExtractor.h"
00006
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009 #include "G4VProcess.hh"
00010
00011 #include <iostream>
00012
00013 G4Allocator<TrackWithHistory> TrackWithHistoryAllocator;
00014
00015
00016
00017 G4TrackToParticleID * TrackWithHistory::theG4TrackToParticleID(0);
00018
00019 TrackWithHistory::TrackWithHistory(const G4Track * g4trk) :
00020 trackID_(0),particleID_(0),parentID_(0),momentum_(math::XYZVectorD(0.,0.,0.)),
00021 totalEnergy_(0),vertexPosition_(math::XYZVectorD(0.,0.,0.)),globalTime_(0),
00022 localTime_(0),properTime_(0),creatorProcess_(0),weight_(0),
00023 storeTrack_(false),saved_(false) {
00024
00025 if (theG4TrackToParticleID == 0) theG4TrackToParticleID = new G4TrackToParticleID;
00026 if (g4trk!=0) {
00027 TrackInformationExtractor extractor;
00028 trackID_ = g4trk->GetTrackID();
00029 particleID_ = theG4TrackToParticleID->particleID(g4trk);
00030 parentID_ = g4trk->GetParentID();
00031 momentum_ = math::XYZVectorD(g4trk->GetMomentum().x(),g4trk->GetMomentum().y(),g4trk->GetMomentum().z());
00032 totalEnergy_ = g4trk->GetTotalEnergy();
00033 vertexPosition_ = math::XYZVectorD(g4trk->GetPosition().x(),g4trk->GetPosition().y(),g4trk->GetPosition().z());
00034 globalTime_ = g4trk->GetGlobalTime();
00035 localTime_ = g4trk->GetLocalTime();
00036 properTime_ = g4trk->GetProperTime();
00037 creatorProcess_ = g4trk->GetCreatorProcess();
00038 weight_ = g4trk->GetWeight();
00039 storeTrack_ = extractor(g4trk).storeTrack();
00040 saved_ = false;
00041 genParticleID_ = extractGenID( g4trk);
00042 #ifdef DEBUG
00043 LogDebug("TrackInformation") << " TrackWithHistory : created history for " << trackID_
00044 << " with mother " << parentID_;
00045 #endif
00046 }
00047 }
00048
00049 void TrackWithHistory::checkAtEnd(const G4Track * gt) {
00050
00051 math::XYZVectorD vposdir(gt->GetVertexPosition().x(),gt->GetVertexPosition().y(),gt->GetVertexPosition().z());
00052 math::XYZVectorD vmomdir(gt->GetVertexMomentumDirection().x(),gt->GetVertexMomentumDirection().y(),gt->GetVertexMomentumDirection().z());
00053 bool ok = true;
00054 double epsilon = 1.e-6;
00055 double eps2 = epsilon*epsilon;
00056 if ((vertexPosition_-vposdir).Mag2() > eps2) {
00057 edm::LogWarning("TrackInformation") << "TrackWithHistory vertex position check failed"
00058 << "\nAt construction: " << vertexPosition_
00059 << "\nAt end: " << vposdir;
00060 ok = false;
00061 }
00062 math::XYZVectorD dirDiff = momentum_.Unit() - vmomdir;
00063 if (dirDiff.Mag2() > eps2 && momentum_.Unit().R() > eps2) {
00064 edm::LogWarning("TrackInformation") << "TrackWithHistory momentum direction check failed"
00065 << "\nAt construction: " << momentum_.Unit()
00066 << "\nAt end: " << vmomdir;
00067 ok = false;
00068 }
00069 if (!ok) throw SimG4Exception("TrackWithHistory::checkAtEnd failed");
00070 }
00071
00072 int TrackWithHistory::extractGenID(const G4Track* gt) const {
00073 void * vgprimary = gt->GetDynamicParticle()->GetPrimaryParticle();
00074 if (vgprimary == 0) return -1;
00075
00076 G4PrimaryParticle* gprimary = (G4PrimaryParticle*) vgprimary;
00077 GenParticleInfoExtractor ext;
00078 return ext(gprimary).id();
00079 }