22 edm::SimTrackContainer::const_iterator itr = SimTk->end();;
26 std::vector<unsigned int> trkId, trkOcc;
27 for(
auto const& trkHit : pTrack->
recHits()) {
29 std::vector<PSimHit> matchedSimIds = associate.
associateHit(*trkHit);
30 for (
unsigned int isim=0; isim<matchedSimIds.size(); isim++) {
31 unsigned tkId = matchedSimIds[isim].trackId();
33 for (
unsigned int j=0; j<trkId.size(); j++) {
34 if ( tkId == trkId[j] ) {
40 if (!found) { trkId.push_back(tkId); trkOcc.push_back(1); }
46 std::cout <<
"Reconstructed Track with " <<
i <<
" recHits.";
47 for (
unsigned int isim=0; isim<trkId.size(); isim++){
48 std::cout <<
"\n trkId " << trkId[isim] <<
" Occurance " << trkOcc[isim] <<
", ";
55 unsigned int matchSimTrk=0;
56 if (!trkOcc.empty()) {
57 unsigned int maxTrkOcc=0, idxMax=0;
58 for(
unsigned int j=0; j<trkOcc.size(); j++) {
59 if(trkOcc[j] > maxTrkOcc ) { maxTrkOcc = trkOcc[j]; idxMax = j; }
61 matchSimTrk = trkId[idxMax];
62 for (
auto simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++) {
63 if ( simTrkItr->trackId() == matchSimTrk ) {
65 matchedId = simTrkItr->type();
66 if (
debug)
std::cout <<
"matched trackId (maximum occurance) " << matchSimTrk <<
" type " << matchedId << std::endl;
75 if (matchedId==0 &&
debug) {
76 std::cout <<
"Could not find matched SimTrk and track history now " << std::endl;
86 edm::SimTrackContainer::const_iterator trkInfo =
spr::matchedSimTrack(iEvent, SimTk, SimVtx, pTrack,associate, debug);
87 unsigned int matchSimTrk = trkInfo->trackId();
89 if (debug)
std::cout <<
"matchedSimTrackId finds the SimTrk ID of the current track to be " << matchSimTrk << std::endl;
91 std::vector<int> matchTkid;
92 if( trkInfo->type() != 0) {
93 for(
auto simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
94 if (
validSimTrack(matchSimTrk, simTrkItr, SimTk, SimVtx,
false))
95 matchTkid.push_back((
int)simTrkItr->trackId());
103 for (edm::SimTrackContainer::const_iterator simTrkItr=SimTk->begin();
104 simTrkItr!= SimTk->end(); simTrkItr++) {
105 if (simTkId == simTrkItr->trackId()) {
108 info.
pdgId = simTrkItr->type();
109 info.
charge = simTrkItr->charge();
111 edm::SimTrackContainer::const_iterator parentItr =
spr::parentSimTrack(simTrkItr, SimTk, SimVtx, debug);
114 if (parentItr != SimTk->end() )
std::cout <<
"original parent of " << simTrkItr->trackId() <<
" " << parentItr->trackId() <<
", " << parentItr->type() << std::endl;
115 else std::cout <<
"original parent of " << simTrkItr->trackId() <<
" not found" << std::endl;
118 if (parentItr != SimTk->end()) {
120 info.
pdgId = parentItr->type();
121 info.
charge = parentItr->charge();
134 if (debug)
std::cout <<
"Inside validSimTrack: trackId " << thisTrkItr->trackId() <<
" vtxIndex " << thisTrkItr->vertIndex() <<
" to be matched to " << simTkId << std::endl;
137 if (thisTrkItr->trackId() == simTkId)
return true;
140 int vertIndex = thisTrkItr->vertIndex();
141 if (vertIndex == -1 || vertIndex >= (
int)SimVtx->size())
return false;
143 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
144 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
145 int parent = simVtxItr->parentIndex();
147 if (debug)
std::cout <<
"validSimTrack:: parent index " << parent <<
" ";
149 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
151 for (simVtxItr=SimVtx->begin(); simVtxItr!=SimVtx->end(); ++simVtxItr) {
152 if (simVtxItr->parentIndex() > 0) {
154 double dist = pos2.P();
156 parent = simVtxItr->parentIndex();
163 if (debug)
std::cout <<
"final index " << parent << std::endl;;
165 for(edm::SimTrackContainer::const_iterator simTrkItr= SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
166 if ((
int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
return validSimTrack(simTkId, simTrkItr, SimTk, SimVtx, debug) ;
176 edm::SimTrackContainer::const_iterator itr = SimTk->end();
178 int vertIndex = thisTrkItr->vertIndex();
180 if (debug)
std::cout <<
"SimTrackParent " << thisTrkItr->trackId() <<
" Vertex " << vertIndex <<
" Type " << thisTrkItr->type() <<
" Charge " << (
int)thisTrkItr->charge() << std::endl;
182 if( vertIndex == -1 )
return thisTrkItr;
183 else if (vertIndex >= (
int)SimVtx->size())
return itr;
185 edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
186 for (
int iv=0; iv<vertIndex; iv++) simVtxItr++;
187 int parent = simVtxItr->parentIndex();
189 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
191 for (simVtxItr=SimVtx->begin(); simVtxItr!=SimVtx->end(); ++simVtxItr) {
192 if (simVtxItr->parentIndex() > 0) {
194 double dist = pos2.P();
196 parent = simVtxItr->parentIndex();
202 for (edm::SimTrackContainer::const_iterator simTrkItr= SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++){
203 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.
auto recHits() const
Access to reconstructed hits on the track.
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)
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)