CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimDataFormats/TrackingAnalysis/src/TrackingParticle.cc

Go to the documentation of this file.
00001 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00002 
00003 typedef std::vector<TrackingVertex>                TrackingVertexCollection;
00004 typedef edm::Ref<TrackingVertexCollection>         TrackingVertexRef;
00005 typedef edm::RefVector<TrackingVertexCollection>   TrackingVertexRefVector;
00006 typedef TrackingVertexRefVector::iterator          tv_iterator;
00007 
00008 TrackingParticle::TrackingParticle( char q, const LorentzVector & p4, const Point & vtx,
00009                                     double t, const int pdgId, const int status, const EncodedEventId eventId) :
00010         ParticleBase( q, p4, vtx,pdgId,status ), t_( t ), pdgId_( pdgId ), eventId_( eventId )
00011 {
00012 }
00013 
00014 TrackingParticle::~TrackingParticle()
00015 {
00016 }
00017 
00018 void TrackingParticle::addGenParticle( const edm::Ref<edm::HepMCProduct, HepMC::GenParticle > &ref)
00019 {
00020     genParticles_.push_back(ref);
00021 }
00022 
00023 void TrackingParticle::addG4Track( const SimTrack& t)
00024 {
00025     g4Tracks_.push_back(t);
00026 }
00027 
00028 void TrackingParticle::addPSimHit( const PSimHit & hit)
00029 {
00030     trackPSimHit_.push_back(hit);
00031 }
00032 
00033 TrackingParticle::genp_iterator TrackingParticle::genParticle_begin() const
00034 {
00035     return genParticles_.begin();
00036 }
00037 
00038 TrackingParticle::genp_iterator TrackingParticle::genParticle_end() const
00039 {
00040     return genParticles_.end();
00041 }
00042 
00043 TrackingParticle::g4t_iterator TrackingParticle::g4Track_begin() const
00044 {
00045     return g4Tracks_.begin();
00046 }
00047 
00048 TrackingParticle::g4t_iterator TrackingParticle::g4Track_end() const
00049 {
00050     return g4Tracks_.end();
00051 }
00052 
00053 const std::vector<PSimHit>::const_iterator TrackingParticle::pSimHit_begin() const
00054 {
00055     return trackPSimHit_.begin();
00056 }
00057 
00058 const std::vector<PSimHit>::const_iterator TrackingParticle::pSimHit_end() const
00059 {
00060     return trackPSimHit_.end();
00061 }
00062 
00063 std::vector<PSimHit> TrackingParticle::trackPSimHit(DetId::Detector detector) const
00064 {
00065     std::vector<PSimHit> result;    
00066     for (std::vector<PSimHit>::const_iterator iHit = trackPSimHit_.begin(); iHit != trackPSimHit_.end(); ++iHit)
00067         if ( detector == DetId( (uint32_t)((*iHit).detUnitId()) ).det() )
00068             result.push_back(*iHit);
00069     return result;
00070 }
00071 
00072 void TrackingParticle::setParentVertex(const TrackingVertexRef &ref)
00073 {
00074     parentVertex_ = ref;
00075 }
00076 
00077 void TrackingParticle::addDecayVertex(const TrackingVertexRef &ref)
00078 {
00079     decayVertices_.push_back(ref);
00080 }
00081 
00082 void TrackingParticle::clearParentVertex()
00083 {
00084     parentVertex_ = TrackingVertexRef();
00085 }
00086 
00087 void TrackingParticle::clearDecayVertices()
00088 {
00089     decayVertices_.clear();
00090 }
00091 
00092 void TrackingParticle::setMatchedHit(const int &hitnumb)
00093 {
00094     matchedHit_ = hitnumb;
00095 }
00096 
00097 void TrackingParticle::setVertex(const Point & vtx, double t)
00098 {
00099     t_ = t;
00100     ParticleBase::setVertex(vtx);
00101 }
00102 
00103 std::ostream& operator<< (std::ostream& s, TrackingParticle const & tp)
00104 {
00105     s << "TP momentum, q, ID, & Event #: "
00106     << tp.p4()                      << " " << tp.charge() << " "   << tp.pdgId() << " "
00107     << tp.eventId().bunchCrossing() << "." << tp.eventId().event() << std::endl;
00108     s << " Hits for this track: " << tp.trackPSimHit().size() << std::endl;
00109 
00110     for (int i = 1; i < DetId::Calo + 1; ++i)
00111     {
00112         int numberOfHits = tp.trackPSimHit((DetId::Detector)i).size();
00113         if (numberOfHits)
00114           s << "\t sub-detector id : " << i << " -> " << numberOfHits << std::endl;
00115     }
00116 
00117     for (TrackingParticle::genp_iterator hepT = tp.genParticle_begin(); hepT !=  tp.genParticle_end(); ++hepT)
00118     {
00119         s << " HepMC Track Momentum " << (*hepT)->momentum().rho() << std::endl;
00120     }
00121 
00122     for (TrackingParticle::g4t_iterator g4T = tp.g4Track_begin(); g4T !=  tp.g4Track_end(); ++g4T)
00123     {
00124         s << " Geant Track Momentum  " << g4T->momentum() << std::endl;
00125         s << " Geant Track ID & type " << g4T->trackId() << " " << g4T->type() << std::endl;
00126         if (g4T->type() !=  tp.pdgId())
00127         {
00128             s << " Mismatch b/t TrackingParticle and Geant types" << std::endl;
00129         }
00130     }
00131     // Loop over decay vertices
00132     s << " TP Vertex " << tp.vertex() << std::endl;
00133     s << " Source vertex: " << tp.parentVertex()->position() << std::endl;
00134     s << " " << tp.decayVertices().size() << " Decay vertices" << std::endl;
00135     for (tv_iterator iTV = tp.decayVertices_begin(); iTV != tp.decayVertices_end(); ++iTV)
00136     {
00137         s << " Decay vertices:      " << (**iTV).position() << std::endl;
00138     }
00139 
00140     return s;
00141 }