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 storeTrack_ = extractor(g4trk).storeTrack();
00039 saved_ = false;
00040 genParticleID_ = extractGenID( g4trk);
00041
00042
00043 weight_ = 10000*genParticleID_;
00044 #ifdef DEBUG
00045 LogDebug("TrackInformation") << " TrackWithHistory : created history for " << trackID_
00046 << " with mother " << parentID_;
00047 #endif
00048 }
00049 }
00050
00051 void TrackWithHistory::checkAtEnd(const G4Track * gt) {
00052
00053 math::XYZVectorD vposdir(gt->GetVertexPosition().x(),gt->GetVertexPosition().y(),gt->GetVertexPosition().z());
00054 math::XYZVectorD vmomdir(gt->GetVertexMomentumDirection().x(),gt->GetVertexMomentumDirection().y(),gt->GetVertexMomentumDirection().z());
00055 bool ok = true;
00056 double epsilon = 1.e-6;
00057 double eps2 = epsilon*epsilon;
00058 if ((vertexPosition_-vposdir).Mag2() > eps2) {
00059 edm::LogWarning("TrackInformation") << "TrackWithHistory vertex position check failed"
00060 << "\nAt construction: " << vertexPosition_
00061 << "\nAt end: " << vposdir;
00062 ok = false;
00063 }
00064 math::XYZVectorD dirDiff = momentum_.Unit() - vmomdir;
00065 if (dirDiff.Mag2() > eps2 && momentum_.Unit().R() > eps2) {
00066 edm::LogWarning("TrackInformation") << "TrackWithHistory momentum direction check failed"
00067 << "\nAt construction: " << momentum_.Unit()
00068 << "\nAt end: " << vmomdir;
00069 ok = false;
00070 }
00071 if (!ok) throw SimG4Exception("TrackWithHistory::checkAtEnd failed");
00072 }
00073
00074 int TrackWithHistory::extractGenID(const G4Track* gt) const {
00075 void * vgprimary = gt->GetDynamicParticle()->GetPrimaryParticle();
00076 if (vgprimary == 0) return -1;
00077
00078 G4PrimaryParticle* gprimary = (G4PrimaryParticle*) vgprimary;
00079 GenParticleInfoExtractor ext;
00080 return ext(gprimary).id();
00081 }