22 edm::SimTrackContainer::const_iterator itr = SimTk->end();;
26 std::vector<unsigned int> trkId, trkOcc;
30 std::vector<PSimHit> matchedSimIds = associate.
associateHit((**iTrkHit));
31 for (
unsigned int isim=0; isim<matchedSimIds.size(); isim++) {
32 unsigned tkId = matchedSimIds[isim].trackId();
34 for (
unsigned int j=0; j<trkId.size(); j++) {
35 if ( tkId == trkId[j] ) {
41 if (!found) { trkId.push_back(tkId); trkOcc.push_back(1); }
47 std::cout <<
"Reconstructed Track with " << i <<
" recHits.";
48 for (
unsigned int isim=0; isim<trkId.size(); isim++){
49 std::cout <<
"\n trkId " << trkId[isim] <<
" Occurance " << trkOcc[isim] <<
", ";
56 unsigned int matchSimTrk=0;
57 if (!trkOcc.empty()) {
58 unsigned int maxTrkOcc=0, idxMax=0;
59 for(
unsigned int j=0; j<trkOcc.size(); j++) {
60 if(trkOcc[j] > maxTrkOcc ) { maxTrkOcc = trkOcc[j]; idxMax = j; }
62 matchSimTrk = trkId[idxMax];
63 for (
auto simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++) {
64 if ( simTrkItr->trackId() == matchSimTrk ) {
66 matchedId = simTrkItr->type();
67 if (
debug)
std::cout <<
"matched trackId (maximum occurance) " << matchSimTrk <<
" type " << matchedId << std::endl;
76 if (matchedId==0 &&
debug) {
77 std::cout <<
"Could not find matched SimTrk and track history now " << std::endl;
87 edm::SimTrackContainer::const_iterator trkInfo =
spr::matchedSimTrack(iEvent, SimTk, SimVtx, pTrack,associate, debug);
88 unsigned int matchSimTrk = trkInfo->trackId();
90 if (debug)
std::cout <<
"matchedSimTrackId finds the SimTrk ID of the current track to be " << matchSimTrk << std::endl;
92 std::vector<int> matchTkid;
93 if( trkInfo->type() != 0) {
94 for(
auto simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
95 if (
validSimTrack(matchSimTrk, simTrkItr, SimTk, SimVtx,
false))
96 matchTkid.push_back((
int)simTrkItr->trackId());
104 for (edm::SimTrackContainer::const_iterator simTrkItr=SimTk->begin();
105 simTrkItr!= SimTk->end(); simTrkItr++) {
106 if (simTkId == simTrkItr->trackId()) {
109 info.
pdgId = simTrkItr->type();
110 info.
charge = simTrkItr->charge();
112 edm::SimTrackContainer::const_iterator parentItr =
spr::parentSimTrack(simTrkItr, SimTk, SimVtx, debug);
115 if (parentItr != SimTk->end() )
std::cout <<
"original parent of " << simTrkItr->trackId() <<
" " << parentItr->trackId() <<
", " << parentItr->type() << std::endl;
116 else std::cout <<
"original parent of " << simTrkItr->trackId() <<
" not found" << std::endl;
119 if (parentItr != SimTk->end()) {
121 info.
pdgId = parentItr->type();
122 info.
charge = parentItr->charge();
135 if (debug)
std::cout <<
"Inside validSimTrack: trackId " << thisTrkItr->trackId() <<
" vtxIndex " << thisTrkItr->vertIndex() <<
" to be matched to " << simTkId << std::endl;
138 if (thisTrkItr->trackId() == simTkId)
return true;
141 int vertIndex = thisTrkItr->vertIndex();
142 if (vertIndex == -1 || vertIndex >= (
int)SimVtx->size())
return false;
144 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
145 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
146 int parent = simVtxItr->parentIndex();
148 if (debug)
std::cout <<
"validSimTrack:: parent index " << parent <<
" ";
150 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
152 for (simVtxItr=SimVtx->begin(); simVtxItr!=SimVtx->end(); ++simVtxItr) {
153 if (simVtxItr->parentIndex() > 0) {
155 double dist = pos2.P();
157 parent = simVtxItr->parentIndex();
164 if (debug)
std::cout <<
"final index " << parent << std::endl;;
166 for(edm::SimTrackContainer::const_iterator simTrkItr= SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
167 if ((
int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
return validSimTrack(simTkId, simTrkItr, SimTk, SimVtx, debug) ;
177 edm::SimTrackContainer::const_iterator itr = SimTk->end();
179 int vertIndex = thisTrkItr->vertIndex();
181 if (debug)
std::cout <<
"SimTrackParent " << thisTrkItr->trackId() <<
" Vertex " << vertIndex <<
" Type " << thisTrkItr->type() <<
" Charge " << (
int)thisTrkItr->charge() << std::endl;
183 if( vertIndex == -1 )
return thisTrkItr;
184 else if (vertIndex >= (
int)SimVtx->size())
return itr;
186 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
187 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
188 int parent = simVtxItr->parentIndex();
190 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
192 for (simVtxItr=SimVtx->begin(); simVtxItr!=SimVtx->end(); ++simVtxItr) {
193 if (simVtxItr->parentIndex() > 0) {
195 double dist = pos2.P();
197 parent = simVtxItr->parentIndex();
203 for (edm::SimTrackContainer::const_iterator simTrkItr= SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
204 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.