Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:53

0001 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
0002 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h"
0003 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0004 
0005 typedef edm::RefVector<edm::HepMCProduct, HepMC::GenVertex> GenVertexRefVector;
0006 typedef edm::Ref<edm::HepMCProduct, HepMC::GenVertex> GenVertexRef;
0007 
0008 // Constructors
0009 
0010 TrackingVertex::TrackingVertex() : position_(LorentzVector(0, 0, 0, 0)), eId_(0) {
0011   //  daughterTracks_.clear();
0012 }
0013 
0014 TrackingVertex::TrackingVertex(const LorentzVector& p, const bool inVolume, const EncodedEventId eId)
0015     : position_(p), inVolume_(inVolume), eId_(eId) {
0016   //  daughterTracks_.clear();
0017 }
0018 
0019 // Add a reference to vertex vectors
0020 
0021 void TrackingVertex::addG4Vertex(const SimVertex& v) { g4Vertices_.push_back(v); }
0022 
0023 void TrackingVertex::addGenVertex(const GenVertexRef& ref) { genVertices_.push_back(ref); }
0024 
0025 // Add a reference to track vectors
0026 
0027 void TrackingVertex::addDaughterTrack(const TrackingParticleRef& ref) { daughterTracks_.push_back(ref); }
0028 
0029 void TrackingVertex::addParentTrack(const TrackingParticleRef& ref) { sourceTracks_.push_back(ref); }
0030 
0031 void TrackingVertex::clearDaughterTracks() { daughterTracks_.clear(); }
0032 
0033 void TrackingVertex::clearParentTracks() { sourceTracks_.clear(); }
0034 
0035 // Iterators over vertices and tracks
0036 
0037 TrackingVertex::genv_iterator TrackingVertex::genVertices_begin() const { return genVertices_.begin(); }
0038 TrackingVertex::genv_iterator TrackingVertex::genVertices_end() const { return genVertices_.end(); }
0039 TrackingVertex::g4v_iterator TrackingVertex::g4Vertices_begin() const { return g4Vertices_.begin(); }
0040 TrackingVertex::g4v_iterator TrackingVertex::g4Vertices_end() const { return g4Vertices_.end(); }
0041 
0042 TrackingVertex::tp_iterator TrackingVertex::daughterTracks_begin() const { return daughterTracks_.begin(); }
0043 TrackingVertex::tp_iterator TrackingVertex::daughterTracks_end() const { return daughterTracks_.end(); }
0044 TrackingVertex::tp_iterator TrackingVertex::sourceTracks_begin() const { return sourceTracks_.begin(); }
0045 TrackingVertex::tp_iterator TrackingVertex::sourceTracks_end() const { return sourceTracks_.end(); }
0046 
0047 // Accessors for whole vectors
0048 
0049 const std::vector<SimVertex>& TrackingVertex::g4Vertices() const { return g4Vertices_; }
0050 const GenVertexRefVector& TrackingVertex::genVertices() const { return genVertices_; }
0051 const TrackingParticleRefVector& TrackingVertex::sourceTracks() const { return sourceTracks_; }
0052 const TrackingParticleRefVector& TrackingVertex::daughterTracks() const { return daughterTracks_; }
0053 
0054 std::ostream& operator<<(std::ostream& s, const TrackingVertex& v) {
0055   using std::endl;
0056   typedef GenVertexRefVector::iterator genv_iterator;
0057   typedef std::vector<SimVertex>::const_iterator g4v_iterator;
0058   typedef TrackingParticleRefVector::iterator tp_iterator;
0059   typedef std::vector<SimTrack>::const_iterator g4t_iterator;
0060 
0061   s << "Vertex Position & Event #" << v.position() << " " << v.eventId().bunchCrossing() << "." << v.eventId().event()
0062     << endl;
0063   s << " Associated with " << v.daughterTracks().size() << " tracks" << endl;
0064   for (genv_iterator genV = v.genVertices_begin(); genV != v.genVertices_end(); ++genV) {
0065     s << " HepMC vertex position " << (*(*genV)).position().x() << "," << (*(*genV)).position().y()
0066       << (*(*genV)).position().z() << endl;
0067   }
0068 
0069   for (g4v_iterator g4V = v.g4Vertices_begin(); g4V != v.g4Vertices_end(); ++g4V) {
0070     s << " Geant vertex position " << (*g4V).position() << endl;
0071     // Probably empty all the time, currently
0072   }
0073 
0074   // Loop over daughter track(s)
0075   for (tp_iterator iTP = v.daughterTracks_begin(); iTP != v.daughterTracks_end(); ++iTP) {
0076     s << " Daughter starts:      " << (*(*iTP)).vertex();
0077     for (g4t_iterator g4T = (*(*iTP)).g4Track_begin(); g4T != (*(*iTP)).g4Track_end(); ++g4T) {
0078       s << " p " << g4T->momentum();
0079     }
0080     s << endl;
0081   }
0082 
0083   // Loop over source track(s) (can be multiple since vertices are collapsed)
0084   for (tp_iterator iTP = v.sourceTracks_begin(); iTP != v.sourceTracks_end(); ++iTP) {
0085     s << " Source   starts: " << (*(*iTP)).vertex();
0086     for (g4t_iterator g4T = (*iTP)->g4Track_begin(); g4T != (*iTP)->g4Track_end(); ++g4T) {
0087       s << ", p " << g4T->momentum();
0088     }
0089     s << endl;
0090   }
0091   return s;
0092 }