22 edm::SimTrackContainer::const_iterator itr = SimTk->end();;
24 edm::SimTrackContainer::const_iterator simTrkItr;
25 edm::SimVertexContainer::const_iterator simVtxItr;
29 std::vector<unsigned int> trkId, trkOcc;
33 std::vector<PSimHit> matchedSimIds = associate.
associateHit((**iTrkHit));
34 for (
unsigned int isim=0; isim<matchedSimIds.size(); isim++) {
35 unsigned tkId = matchedSimIds[isim].trackId();
37 for (
unsigned int j=0; j<trkId.size(); j++) {
38 if ( tkId == trkId[j] ) {
44 if (!found) { trkId.push_back(tkId); trkOcc.push_back(1); }
50 std::cout <<
"Reconstructed Track with " << i <<
" recHits.";
51 for (
unsigned int isim=0; isim<trkId.size(); isim++){
52 std::cout <<
"\n trkId " << trkId[isim] <<
" Occurance " << trkOcc[isim] <<
", ";
59 unsigned int matchSimTrk=0;
60 if (!trkOcc.empty()) {
61 unsigned int maxTrkOcc=0, idxMax=0;
62 for(
unsigned int j=0; j<trkOcc.size(); j++) {
63 if(trkOcc[j] > maxTrkOcc ) { maxTrkOcc = trkOcc[j]; idxMax = j; }
65 matchSimTrk = trkId[idxMax];
66 for (simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++) {
67 if ( simTrkItr->trackId() == matchSimTrk ) {
69 matchedId = simTrkItr->type();
70 if (
debug)
std::cout <<
"matched trackId (maximum occurance) " << matchSimTrk <<
" type " << matchedId << std::endl;
79 if (matchedId==0 &&
debug) {
80 std::cout <<
"Could not find matched SimTrk and track history now " << std::endl;
90 edm::SimTrackContainer::const_iterator trkInfo =
spr::matchedSimTrack(iEvent, SimTk, SimVtx, pTrack,associate, debug);
91 unsigned int matchSimTrk = trkInfo->trackId();
93 if (debug)
std::cout <<
"matchedSimTrackId finds the SimTrk ID of the current track to be " << matchSimTrk << std::endl;
95 std::vector<int> matchTkid;
96 if( trkInfo->type() != 0) {
97 edm::SimTrackContainer::const_iterator simTrkItr;
98 for(simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
99 if (
validSimTrack(matchSimTrk, simTrkItr, SimTk, SimVtx,
false))
100 matchTkid.push_back((
int)simTrkItr->trackId());
108 for (edm::SimTrackContainer::const_iterator simTrkItr=SimTk->begin();
109 simTrkItr!= SimTk->end(); simTrkItr++) {
110 if (simTkId == simTrkItr->trackId()) {
113 info.
pdgId = simTrkItr->type();
114 info.
charge = simTrkItr->charge();
116 edm::SimTrackContainer::const_iterator parentItr =
spr::parentSimTrack(simTrkItr, SimTk, SimVtx, debug);
119 if (parentItr != SimTk->end() )
std::cout <<
"original parent of " << simTrkItr->trackId() <<
" " << parentItr->trackId() <<
", " << parentItr->type() << std::endl;
120 else std::cout <<
"original parent of " << simTrkItr->trackId() <<
" not found" << std::endl;
123 if (parentItr != SimTk->end()) {
125 info.
pdgId = parentItr->type();
126 info.
charge = parentItr->charge();
139 if (debug)
std::cout <<
"Inside validSimTrack: trackId " << thisTrkItr->trackId() <<
" vtxIndex " << thisTrkItr->vertIndex() <<
" to be matched to " << simTkId << std::endl;
142 if (thisTrkItr->trackId() == simTkId)
return true;
145 int vertIndex = thisTrkItr->vertIndex();
146 if (vertIndex == -1 || vertIndex >= (
int)SimVtx->size())
return false;
148 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
149 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
150 int parent = simVtxItr->parentIndex();
152 if (debug)
std::cout <<
"validSimTrack:: parent index " << parent <<
" ";
154 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
156 for (simVtxItr=SimVtx->begin(); simVtxItr!=SimVtx->end(); ++simVtxItr) {
157 if (simVtxItr->parentIndex() > 0) {
159 double dist = pos2.P();
161 parent = simVtxItr->parentIndex();
168 if (debug)
std::cout <<
"final index " << parent << std::endl;;
170 for(edm::SimTrackContainer::const_iterator simTrkItr= SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
171 if ((
int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
return validSimTrack(simTkId, simTrkItr, SimTk, SimVtx, debug) ;
181 edm::SimTrackContainer::const_iterator itr = SimTk->end();
183 int vertIndex = thisTrkItr->vertIndex();
185 if (debug)
std::cout <<
"SimTrackParent " << thisTrkItr->trackId() <<
" Vertex " << vertIndex <<
" Type " << thisTrkItr->type() <<
" Charge " << (
int)thisTrkItr->charge() << std::endl;
187 if( vertIndex == -1 )
return thisTrkItr;
188 else if (vertIndex >= (
int)SimVtx->size())
return itr;
190 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
191 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
192 int parent = simVtxItr->parentIndex();
194 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
196 for (simVtxItr=SimVtx->begin(); simVtxItr!=SimVtx->end(); ++simVtxItr) {
197 if (simVtxItr->parentIndex() > 0) {
199 double dist = pos2.P();
201 parent = simVtxItr->parentIndex();
207 for (edm::SimTrackContainer::const_iterator simTrkItr= SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
208 if ((
int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
return parentSimTrack(simTrkItr, SimTk, SimVtx, debug);
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
edm::SimTrackContainer::const_iterator matchedSimTrack(const edm::Event &iEvent, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, const reco::Track *pTrack, TrackerHitAssociator &associate, bool debug=false)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
simTkInfo matchedSimTrackInfo(unsigned int simTkId, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, bool debug=false)
std::vector< int > matchedSimTrackId(const edm::Event &, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, const reco::Track *pTrack, TrackerHitAssociator &associate, bool debug=false)
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
bool validSimTrack(unsigned int simTkId, edm::SimTrackContainer::const_iterator thisTrkItr, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, bool debug=false)
edm::SimTrackContainer::const_iterator parentSimTrack(edm::SimTrackContainer::const_iterator thisTrkItr, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, bool debug=false)
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.