Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:27

0001 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
0002 #include "SimG4Core/Notification/interface/G4TrackToParticleID.h"
0003 #include "SimG4Core/Notification/interface/TrackInformation.h"
0004 #include "SimG4Core/Notification/interface/GenParticleInfo.h"
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include "G4VProcess.hh"
0009 #include "G4DynamicParticle.hh"
0010 #include "G4PrimaryParticle.hh"
0011 #include "G4ThreeVector.hh"
0012 
0013 #include <iostream>
0014 
0015 G4ThreadLocal G4Allocator<TrackWithHistory>* fpTrackWithHistoryAllocator = nullptr;
0016 
0017 TrackWithHistory::TrackWithHistory(const G4Track* g4trk, int pID) {
0018   trackID_ = g4trk->GetTrackID();
0019   pdgID_ = G4TrackToParticleID::particleID(g4trk);
0020   parentID_ = pID;
0021   auto mom = g4trk->GetMomentum();
0022   momentum_ = math::XYZVectorD(mom.x(), mom.y(), mom.z());
0023   totalEnergy_ = g4trk->GetTotalEnergy();
0024   auto pos = g4trk->GetPosition();
0025   vertexPosition_ = math::XYZVectorD(pos.x(), pos.y(), pos.z());
0026   time_ = g4trk->GetGlobalTime();
0027   auto p = g4trk->GetCreatorProcess();
0028   procType_ = (nullptr != p) ? p->GetProcessSubType() : 0;
0029   TrackInformation* trkinfo = static_cast<TrackInformation*>(g4trk->GetUserInformation());
0030   storeTrack_ = trkinfo->storeTrack();
0031   auto vgprimary = g4trk->GetDynamicParticle()->GetPrimaryParticle();
0032   if (vgprimary != nullptr) {
0033     auto priminfo = static_cast<GenParticleInfo*>(vgprimary->GetUserInformation());
0034     if (nullptr != priminfo) {
0035       genParticleID_ = priminfo->id();
0036     }
0037   }
0038   // V.I. weight is computed in the same way as before
0039   // without usage of G4Track::GetWeight()
0040   weight_ = 10000 * genParticleID_;
0041 }
0042 
0043 TrackWithHistory::TrackWithHistory(const G4PrimaryParticle* ptr, int trackID, const math::XYZVectorD& pos, double time) {
0044   trackID_ = trackID;
0045   pdgID_ = G4TrackToParticleID::particleID(ptr, trackID_);
0046   parentID_ = trackID;
0047   auto mom = ptr->GetMomentum();
0048   momentum_ = math::XYZVectorD(mom.x(), mom.y(), mom.z());
0049   totalEnergy_ = ptr->GetTotalEnergy();
0050   vertexPosition_ = math::XYZVectorD(pos.x(), pos.y(), pos.z());
0051   time_ = time;
0052   storeTrack_ = true;
0053   auto priminfo = static_cast<GenParticleInfo*>(ptr->GetUserInformation());
0054   if (nullptr != priminfo) {
0055     genParticleID_ = priminfo->id();
0056   }
0057   weight_ = 10000. * genParticleID_;
0058 }