Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-12 23:42:12

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   // GetPrimaryParticle() returns the pointer to the corresponding G4PrimaryParticle object
0033   // if this particle is a primary particle OR is defined as a
0034   // pre-assigned decay product. Otherwise return nullptr.
0035   // Therefore here the genParticleID_ is -1 for not primary particles
0036   if (vgprimary != nullptr) {
0037     auto priminfo = static_cast<GenParticleInfo*>(vgprimary->GetUserInformation());
0038     if (nullptr != priminfo) {
0039       genParticleID_ = priminfo->id();
0040       isPrimary_ = true;
0041     }
0042   }
0043   // V.I. weight is computed in the same way as before
0044   // without usage of G4Track::GetWeight()
0045   weight_ = 10000 * genParticleID_;
0046 }
0047 
0048 TrackWithHistory::TrackWithHistory(const G4PrimaryParticle* ptr, int trackID, const math::XYZVectorD& pos, double time) {
0049   trackID_ = trackID;
0050   pdgID_ = G4TrackToParticleID::particleID(ptr, trackID_);
0051   parentID_ = trackID;
0052   auto mom = ptr->GetMomentum();
0053   momentum_ = math::XYZVectorD(mom.x(), mom.y(), mom.z());
0054   totalEnergy_ = ptr->GetTotalEnergy();
0055   vertexPosition_ = math::XYZVectorD(pos.x(), pos.y(), pos.z());
0056   time_ = time;
0057   storeTrack_ = true;
0058   auto priminfo = static_cast<GenParticleInfo*>(ptr->GetUserInformation());
0059   if (nullptr != priminfo) {
0060     genParticleID_ = priminfo->id();
0061     isPrimary_ = true;
0062   }
0063   weight_ = 10000. * genParticleID_;
0064 }