#include <SimGeneral/TrackingAnalysis/interface/MergedTruthProducer.h>
Public Member Functions | |
MergedTruthProducer (const edm::ParameterSet &) | |
Private Member Functions | |
void | produce (edm::Event &, const edm::EventSetup &) |
Private Attributes | |
edm::ParameterSet | conf_ |
std::string | MessageCategory_ |
Definition at line 10 of file MergedTruthProducer.h.
MergedTruthProducer::MergedTruthProducer | ( | const edm::ParameterSet & | conf | ) | [explicit] |
Definition at line 15 of file MergedTruthProducer.cc.
References conf_, and MessageCategory_.
00015 { 00016 produces<TrackingVertexCollection>("MergedTrackTruth"); 00017 produces<TrackingParticleCollection>("MergedTrackTruth"); 00018 00019 conf_ = conf; 00020 MessageCategory_ = "MergedTruthProducer"; 00021 00022 }
void MergedTruthProducer::produce | ( | edm::Event & | event, | |
const edm::EventSetup & | ||||
) | [private, virtual] |
Implements edm::EDProducer.
Definition at line 24 of file MergedTruthProducer.cc.
References TrackingParticle::addDecayVertex(), edm::RefVector< C, T, F >::begin(), TrackingVertex::clearDaughterTracks(), TrackingParticle::clearDecayVertices(), TrackingVertex::clearParentTracks(), TrackingParticle::clearParentVertex(), edm::RefVector< C, T, F >::end(), edm::Ref< C, T, F >::key(), and TrackingParticle::setParentVertex().
00024 { 00025 00026 edm::Handle<TrackingParticleCollection> elecPH; 00027 edm::Handle<TrackingParticleCollection> rawPH; 00028 edm::Handle<TrackingVertexCollection> rawVH; 00029 00030 event.getByLabel("trackingtruthprod",rawPH); 00031 event.getByLabel("trackingtruthprod",rawVH); 00032 event.getByLabel("electrontruth","ElectronTrackTruth", elecPH); 00033 00034 // std::auto_ptr<TrackingParticleCollection> trackCollection(new TrackingParticleCollection(rawPH.product())); 00035 // std::auto_ptr<TrackingParticleCollection> elecCollection(new TrackingParticleCollection(elecPH.product())); 00036 // std::auto_ptr<TrackingVertexCollection> vertexCollection(new TrackingVertexCollection(rawVH.product())); 00037 00038 // Create collections of things we will put in event and size appropriately 00039 auto_ptr<TrackingParticleCollection> tPC(new TrackingParticleCollection); 00040 auto_ptr<TrackingVertexCollection> tVC(new TrackingVertexCollection ); 00041 tPC->reserve(rawPH->size()); 00042 tVC->reserve(rawVH->size()); 00043 00044 // Get references before put so we can cross reference 00045 TrackingParticleRefProd refTPC = event.getRefBeforePut<TrackingParticleCollection>("MergedTrackTruth"); 00046 TrackingVertexRefProd refTVC = event.getRefBeforePut<TrackingVertexCollection>("MergedTrackTruth"); 00047 00048 std::set<EncodedTruthId> electronGID; // Keeps track of GeantIDs of electron tracks we've added 00049 00050 // Copy vertices discarding parent & child tracks 00051 00052 for (TrackingVertexCollection::const_iterator iVertex = rawVH->begin(); iVertex != rawVH->end(); ++iVertex) { 00053 TrackingVertex newVertex = (*iVertex); 00054 newVertex.clearDaughterTracks(); 00055 newVertex.clearParentTracks(); 00056 tVC->push_back(newVertex); 00057 } 00058 00059 uint eIndex = 0; 00060 for (TrackingParticleCollection::const_iterator iTrack = elecPH->begin(); iTrack != elecPH->end(); ++iTrack, ++eIndex) { 00061 00062 // Copy references from old vertex, set on new vertex, see comments in next loop 00063 00064 TrackingVertexRef sourceV = iTrack->parentVertex(); 00065 TrackingVertexRefVector decayVs = iTrack->decayVertices(); 00066 TrackingParticle newTrack = *iTrack; 00067 newTrack.clearParentVertex(); 00068 newTrack.clearDecayVertices(); 00069 uint parentIndex = sourceV.key(); 00070 newTrack.setParentVertex(TrackingVertexRef(refTVC,parentIndex)); 00071 (tVC->at(parentIndex)).addDaughterTrack(TrackingParticleRef(refTPC,eIndex)); 00072 for (TrackingVertexRefVector::const_iterator iDecayV = decayVs.begin(); iDecayV != decayVs.end(); ++iDecayV) { 00073 uint daughterIndex = iDecayV->key(); 00074 newTrack.addDecayVertex(TrackingVertexRef(refTVC,daughterIndex)); 00075 (tVC->at(daughterIndex)).addParentTrack(TrackingParticleRef(refTPC,eIndex)); 00076 } 00077 tPC->push_back(newTrack); 00078 00079 // Keep track of which tracks we did so we can skip later 00080 00081 for (TrackingParticle::g4t_iterator g4T = iTrack->g4Track_begin(); g4T != iTrack->g4Track_end(); ++g4T) { 00082 uint GID = g4T->trackId(); 00083 if (GID) { 00084 electronGID.insert(EncodedTruthId(iTrack->eventId(),GID)); 00085 } 00086 } 00087 } 00088 00089 for (TrackingParticleCollection::const_iterator iTrack = rawPH->begin(); iTrack != rawPH->end(); ++iTrack) { 00090 bool addTrack = false; 00091 for (TrackingParticle::g4t_iterator g4T = iTrack->g4Track_begin(); g4T != iTrack->g4Track_end(); ++g4T) { 00092 uint GID = g4T->trackId(); 00093 if (electronGID.count(EncodedTruthId(iTrack->eventId(),GID))) { 00094 // Do nothing 00095 } else { 00096 addTrack = true; 00097 } 00098 } 00099 00100 if (addTrack) { // Skip tracks that were in electron list 00101 TrackingVertexRef sourceV = iTrack->parentVertex(); 00102 TrackingVertexRefVector decayVs = iTrack->decayVertices(); 00103 TrackingParticle newTrack = *iTrack; 00104 newTrack.clearParentVertex(); 00105 newTrack.clearDecayVertices(); 00106 00107 // Set vertex indices for new vertex product and track references in those vertices 00108 00109 uint parentIndex = sourceV.key(); // Index of parent vertex in vertex container 00110 uint tIndex = tPC->size(); // Index of this track in track container 00111 newTrack.setParentVertex(TrackingVertexRef(refTVC,parentIndex)); // Add vertex to track 00112 (tVC->at(parentIndex)).addDaughterTrack(TrackingParticleRef(refTPC,tIndex)); // Add track to vertex 00113 for (TrackingVertexRefVector::const_iterator iDecayV = decayVs.begin(); iDecayV != decayVs.end(); ++iDecayV) { 00114 uint daughterIndex = iDecayV->key(); 00115 newTrack.addDecayVertex(TrackingVertexRef(refTVC,daughterIndex)); // Add vertex to track 00116 (tVC->at(daughterIndex)).addParentTrack(TrackingParticleRef(refTPC,tIndex)); // Add track to vertex 00117 } 00118 tPC->push_back(newTrack); 00119 } 00120 } 00121 00122 // Put TrackingParticles and TrackingVertices in event 00123 00124 event.put(tPC,"MergedTrackTruth"); 00125 event.put(tVC,"MergedTrackTruth"); 00126 00127 // timers.pop(); 00128 // timers.pop(); 00129 }
edm::ParameterSet MergedTruthProducer::conf_ [private] |
std::string MergedTruthProducer::MessageCategory_ [private] |