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 reco::Particle( q, p4, vtx,pdgId,status ), t_( t ), pdgId_( pdgId ), eventId_( eventId ), subdetVectorFill_( false ) {
00011 }
00012
00013 TrackingParticle::~TrackingParticle() {
00014 }
00015
00016 void TrackingParticle::addGenParticle( const edm::Ref<edm::HepMCProduct, HepMC::GenParticle > &ref) {
00017 genParticles_.push_back(ref);
00018 }
00019
00020 void TrackingParticle::addG4Track( const SimTrack& t) {
00021 g4Tracks_.push_back(t);
00022 }
00023
00024 void TrackingParticle::addPSimHit( const PSimHit& hit){
00025 trackPSimHit_.push_back(hit);
00026 }
00027
00028 TrackingParticle::genp_iterator TrackingParticle::genParticle_begin() const {
00029 return genParticles_.begin();
00030 }
00031
00032 TrackingParticle::genp_iterator TrackingParticle::genParticle_end() const {
00033 return genParticles_.end();
00034 }
00035
00036 TrackingParticle::g4t_iterator TrackingParticle::g4Track_begin() const {
00037 return g4Tracks_.begin();
00038 }
00039
00040 TrackingParticle::g4t_iterator TrackingParticle::g4Track_end() const {
00041 return g4Tracks_.end();
00042 }
00043
00044 const std::vector<PSimHit>::const_iterator TrackingParticle::pSimHit_begin() const {
00045 return trackPSimHit_.begin();
00046 }
00047
00048 const std::vector<PSimHit>::const_iterator TrackingParticle::pSimHit_end() const {
00049 return trackPSimHit_.end();
00050 }
00051
00052 const std::vector<PSimHit>::const_iterator TrackingParticle::trackerPSimHit_begin() {
00053
00054
00055
00056 if(!subdetVectorFill_)
00057 fillSubDetHitVectors();
00058
00059 return trackerPSimHit_.begin();
00060 }
00061
00062 const std::vector<PSimHit>::const_iterator TrackingParticle::trackerPSimHit_end() {
00063
00064
00065
00066 if(!subdetVectorFill_)
00067 fillSubDetHitVectors();
00068
00069 return trackerPSimHit_.end();
00070 }
00071
00072 const std::vector<PSimHit>::const_iterator TrackingParticle::muonPSimHit_begin() {
00073
00074
00075
00076 if(!subdetVectorFill_)
00077 fillSubDetHitVectors();
00078
00079 return muonPSimHit_.begin();
00080 }
00081
00082 const std::vector<PSimHit>::const_iterator TrackingParticle::muonPSimHit_end() {
00083
00084
00085
00086 if(!subdetVectorFill_)
00087 fillSubDetHitVectors();
00088
00089 return muonPSimHit_.end();
00090 }
00091
00092 const std::vector<PSimHit>& TrackingParticle::trackerPSimHit() {
00093
00094
00095
00096 if(!subdetVectorFill_)
00097 fillSubDetHitVectors();
00098
00099 return trackerPSimHit_;
00100 }
00101
00102 const std::vector<PSimHit>& TrackingParticle::muonPSimHit() {
00103
00104
00105
00106 if(!subdetVectorFill_)
00107 fillSubDetHitVectors();
00108
00109 return muonPSimHit_;
00110 }
00111
00112 void TrackingParticle::fillSubDetHitVectors() {
00113 trackerPSimHit_.clear();
00114 muonPSimHit_.clear();
00115 subdetVectorFill_ = true;
00116
00117 for(std::vector<PSimHit>::const_iterator aHit = trackPSimHit_.begin(); aHit != trackPSimHit_.end(); ++aHit) {
00118 unsigned int subDet_enum = DetId( (uint32_t)((*aHit).detUnitId()) ).det();
00119 switch (subDet_enum) {
00120 case DetId::Tracker:
00121 {
00122 trackerPSimHit_.push_back((*aHit));
00123 break;
00124 }
00125 case DetId::Muon:
00126 {
00127 muonPSimHit_.push_back((*aHit));
00128 break;
00129 }
00130 default:
00131 {
00132 std::cout << "TrackingParticle WARNING - Not Tracker or Muon Subdetector " << subDet_enum << std::endl;
00133 break;
00134 }
00135 }
00136 }
00137 }
00138
00139
00140 void TrackingParticle::setParentVertex(const TrackingVertexRef &ref) {
00141 parentVertex_ = ref;
00142 }
00143
00144 void TrackingParticle::addDecayVertex(const TrackingVertexRef &ref){
00145 decayVertices_.push_back(ref);
00146 }
00147
00148 void TrackingParticle::clearParentVertex() {
00149 parentVertex_ = TrackingVertexRef();
00150 }
00151
00152 void TrackingParticle::clearDecayVertices() {
00153 decayVertices_.clear();
00154 }
00155
00156 void TrackingParticle::setMatchedHit(const int &hitnumb) {
00157 matchedHit_ = hitnumb;
00158 }
00159
00160 void TrackingParticle::setVertex(const Point & vtx, double t){
00161 t_ = t;
00162 reco::Particle::setVertex(vtx);
00163 }
00164
00165 std::ostream& operator<< (std::ostream& s, const TrackingParticle & tp) {
00166
00167
00168 s << "TP momentum, q, ID, & Event #: "
00169 << tp.p4() << " " << tp.charge() << " " << tp.pdgId() << " "
00170 << tp.eventId().bunchCrossing() << "." << tp.eventId().event() << std::endl;
00171 s << " Hits for this track: " << tp.trackPSimHit().size() << std::endl;
00172 s << "\t Tracker: " << tp.trackerPSimHit_.size() << std::endl;
00173 s << "\t Muon: " << tp.muonPSimHit_.size() << std::endl;
00174
00175 for (TrackingParticle::genp_iterator hepT = tp.genParticle_begin(); hepT != tp.genParticle_end(); ++hepT) {
00176 s << " HepMC Track Momentum " << (*hepT)->momentum().mag() << std::endl;
00177 }
00178
00179 for (TrackingParticle::g4t_iterator g4T = tp.g4Track_begin(); g4T != tp.g4Track_end(); ++g4T) {
00180 s << " Geant Track Momentum " << g4T->momentum() << std::endl;
00181 s << " Geant Track ID & type " << g4T->trackId() << " " << g4T->type() << std::endl;
00182 if (g4T->type() != tp.pdgId()) {
00183 s << " Mismatch b/t TrackingParticle and Geant types" << std::endl;
00184 }
00185 }
00186
00187 s << " TP Vertex " << tp.vertex() << std::endl;
00188 s << " Source vertex: " << tp.parentVertex()->position() << std::endl;
00189 s << " " << tp.decayVertices().size() << " Decay vertices" << std::endl;
00190 for (tv_iterator iTV = tp.decayVertices_begin(); iTV != tp.decayVertices_end(); ++iTV) {
00191 s << " Decay vertices: " << (**iTV).position() << std::endl;
00192 }
00193
00194 return s;
00195 }