CMS 3D CMS Logo

TkNavigableSimElectronAssembler.cc

Go to the documentation of this file.
00001 #include "SimGeneral/TrackingAnalysis/interface/TkNavigableSimElectronAssembler.h"
00002 
00003 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00004 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h"
00005 
00006 using namespace std;
00007 
00012 TkNavigableSimElectronAssembler::ElectronList
00013 TkNavigableSimElectronAssembler::assemble (TrackPtrContainer& allTracks) const
00014 {
00015   //
00016   // Create lists of electron tracks and non-electron tracks
00017   // (use lists for constant time removal, see below)
00018   //
00019   TrackList tracks(allTracks.begin(), allTracks.end());
00020   TrackList electronTracks(electronFilter(tracks));
00021 //  std::cout << "TkNavigableSimElectronAssembler: found "
00022 //          << electronTracks.size()
00023 //          << " electron segments" << std::endl;
00024   if ( electronTracks.empty() ) return ElectronList();
00025   //
00026   // build assembled tracks
00027   //
00028   ElectronList electrons;
00029   TrackList trackSegments;
00030   while ( electronTracks.size() ) {
00031     //
00032     // initialise new combined electron
00033     //
00034     const TrackPtr startSegment = electronTracks.front();
00035     electronTracks.pop_front();
00036     trackSegments.clear();
00037     trackSegments.push_back(startSegment);
00038 //    std::cout << "Starting assembly with segment at " << *startSegment
00039 //              << std::endl;
00040 //       << " (p=" << startSegment->momentum().mag()
00041 //       << ",r_vtx=";
00042 //     if ( startSegment->vertex() )
00043 //       std::cout << startSegment->vertex()->position().perp();
00044 //     std::cout << ",&vtx=" << startSegment->vertex() << ")" << std::endl;
00045     //
00046     // add segments before current segment
00047     //
00048     searchInwards(electronTracks, startSegment, trackSegments);
00049 //    std::cout << "nb segments after inward search " << trackSegments.size()
00050 //            << std::endl;
00051     //
00052     // add segments after current segment
00053     //
00054     searchOutwards(electronTracks, startSegment, trackSegments);
00055 //    std::cout << "nb segments after outward search " << trackSegments.size()
00056 //            << std::endl;
00057     //
00058     // store list of segments
00059     //
00060     electrons.push_back(trackSegments);
00061   }
00062 
00063   return electrons;
00064 }
00065 
00066 
00067 void
00068 TkNavigableSimElectronAssembler::searchInwards (TrackList& electronTracks,
00069                                                 const TrackPtr startSegment,
00070                                                 TrackList& trackSegments) const
00071 {
00072 
00073   TrackPtr currentSegment(startSegment);
00074 //  TrackPtr debug = findParent(*currentSegment);
00075 //  std::cout << "searchInwards: parent " << debug << std::endl;
00076   while ( TrackPtr nextSegment = findParent(*currentSegment) ) {
00077     trackSegments.push_front(nextSegment);
00078     electronTracks.remove(nextSegment);
00079     currentSegment = nextSegment;
00080 //     EncodedSimTrackId packedId(nextSegment->id());
00081 //     if ( packedId.bunch()!=startId.bunch() ||
00082 //       packedId.eventInBunch()!=startId.eventInBunch() )
00083 //       std::cout << "*** inconsistency in bunch / event number! ***" << std::endl;
00084 //     std::cout << "Adding parent at " << nextSegment
00085 //       << " (p=" << nextSegment->momentum().mag()
00086 //       << ",r_vtx=";
00087 //     if ( nextSegment->vertex() )
00088 //       std::cout << nextSegment->vertex()->position().perp();
00089 //     std::cout << ",&vtx=" << nextSegment->vertex() << ")" << std::endl;
00090   }
00091 }
00092 
00093 
00094 const TkNavigableSimElectronAssembler::TrackPtr
00095 TkNavigableSimElectronAssembler::findParent (const TrackingParticle& track)
00096   const
00097 {
00098   //
00099   // verify Bremsstrahlung
00100   //
00101   std::pair<const TrackPtr, const TrackPtr> segmentPair
00102     = checkVertex(track.parentVertex().get());
00103   //
00104   return segmentPair.first;
00105 }
00106 
00107 
00108 void
00109 TkNavigableSimElectronAssembler::searchOutwards (TrackList& electronTracks,
00110                                                  const TrackPtr startSegment,
00111                                                  TrackList& trackSegments)
00112   const
00113 {
00114 //   EncodedSimTrackId startId(startSegment->id());
00115   TrackPtr currentSegment(startSegment);
00116   while ( TrackPtr nextSegment = findChild(*currentSegment) ) {
00117     trackSegments.push_back(nextSegment);
00118     electronTracks.remove(nextSegment);
00119     currentSegment = nextSegment;
00120 //     EncodedSimTrackId packedId(nextSegment->id());
00121 //     if ( packedId.bunch()!=startId.bunch() ||
00122 //       packedId.eventInBunch()!=startId.eventInBunch() )
00123 //       std::cout << "*** inconsistency in bunch / event number! ***" << std::endl;
00124 //     std::cout << "Adding child at " << nextSegment
00125 //       << " (p=" << nextSegment->momentum().mag()
00126 //       << ",r_vtx=";
00127 //     if ( nextSegment->vertex() )
00128 //       std::cout << nextSegment->vertex()->position().perp();
00129 //     std::cout << ",&vtx=" << nextSegment->vertex() << ")" << std::endl;
00130   }
00131 }
00132 
00133 
00134 const TkNavigableSimElectronAssembler::TrackPtr
00135 TkNavigableSimElectronAssembler::findChild (const TrackingParticle& track)
00136   const
00137 {
00138   //
00139   // verify bremsstrahlung
00140   //
00141 
00142   // for 131
00143   //  std::pair<TrackPtr, TrackPtr> segmentPair
00144   //    = checkVertex(track.decayVertex().get());
00145   //  std::pair<TrackPtr, TrackPtr> result(0,0);
00146 
00147   TrackingVertexRefVector decayVertices = track.decayVertices();
00148   if ( decayVertices.empty() ) {
00149 //    std::cout << "Decay vertex is null " << std::endl;
00150     return 0;
00151   }
00152 
00153   std::pair<TrackPtr, TrackPtr> segmentPair
00154     //    = checkVertex(&(*track.decayVertices().at(0)));
00155     = checkVertex( &(*decayVertices.at(0)) );
00156   //
00157   return segmentPair.second;
00158 }
00159 
00160 
00165 std::pair<TkNavigableSimElectronAssembler::TrackPtr,
00166           TkNavigableSimElectronAssembler::TrackPtr>
00167 TkNavigableSimElectronAssembler::checkVertex (const TrackingVertex* vertex) const
00168 {
00169   std::pair<TrackPtr, TrackPtr> result(0,0);
00170   //
00171   // check vertex & parent
00172   //
00173   if ( vertex==0 )  return result;
00174   const TrackingParticleRefVector parents(vertex->sourceTracks());
00175   if ( parents.empty() ) {
00176 //     std::cout << "No parent track at vertex" << std::endl;
00177     return result;
00178   }
00179   if ( parents.size() != 1 ) {
00180 //     std::cout << "More than 1 parent track at vertex" << std::endl;
00181     return result;
00182   }
00183   if ( abs( (**parents.begin()).pdgId()) != 11 ) {
00184 //    std::cout << "Found parent track of type "
00185 //            << (**parents.begin()).pdgId() << " at vertex" << std::endl;
00186     return result;
00187   }
00188   //
00189   // check secondaries
00190   //
00191   const TrackingParticleRefVector secondaries(vertex->daughterTracks());
00192   TrackPtr child(0);
00193   int nPhoton(0);
00194 //   std::cout << "Types at vertex =";
00195   for ( TrackingVertex::tp_iterator it=vertex->daughterTracks_begin();
00196         it!=vertex->daughterTracks_end(); it++ ) {
00197 //     std::cout << " " << (*it).pdgId();
00198     if ( abs((**it).pdgId()) == 11 ) {
00199       // accept only one electron in list of secondaries
00200       if ( child )  std::cout << std::endl << "Found several electrons at vertex" << std::endl;
00201       if ( child )  return result;
00202       child = const_cast<TrackPtr>(&(**it));
00203     }
00204     // accept <= 1 photon
00205     else if ( (**it).pdgId() == 22 ) {
00206       nPhoton++;
00207       if ( nPhoton>1 ) {
00208 //      std::cout << "Found several photons at vertex" << std::endl;
00209         return result;
00210       }
00211     }
00212     else {
00213 //      std::cout << std::endl << "Found track of type "
00214 //              << (**parents.begin()).pdgId() << " at vertex" << std::endl;
00215       return result;
00216     }
00217   }
00218 //  std::cout << std::endl;
00219 //  if ( child==0 ) {
00220 //    std::cout << "No electron found at vertex" << std::endl;
00221 //  }
00222 //  else {
00223 //    std::cout << "ElectronAssembler::electron child" << std::endl;
00224 //    std::cout << *child << std::endl;
00225 //  }
00226 
00227   //
00228   result.first = const_cast<TrackPtr>(&(**parents.begin()));
00229   result.second = child;
00230   return result;
00231 }
00232 
00233 
00237 TkNavigableSimElectronAssembler::TrackList
00238 TkNavigableSimElectronAssembler::electronFilter (TrackList& allTracks) const
00239 {
00240   TrackList electrons;
00241   TrackList others;
00242 
00243   for ( TrackList::iterator it = allTracks.begin();
00244         it != allTracks.end(); it++ ) {
00245     if ( abs((**it).pdgId())==11 ) {
00246       electrons.push_back(*it);
00247       //      allTracks.erase(it);
00248     }
00249     else {
00250       others.push_back(*it);
00251     }
00252   }
00253 
00254   // on output, argument contains only non-electrons
00255   allTracks = others;
00256   return electrons;
00257 }
00258 
00259 
00262 /*
00263 TrackingParticleRef TkNavigableSimElectronAssembler::findInitialSegmentRef(
00264   const TrackPtr& firstSegment) const
00265 {
00266   TrackingVertexRef startV = (*firstSegment).parentVertex();
00267 
00268   TrackingParticleRefVector daughters = (*startV).daughterTracks();
00269   for (TrackingParticleRefVector::iterator it = daughters.begin();
00270        it != daughters.end(); it++) {
00271     TrackingParticleRef d = (*it);
00272 
00273     // TrackingParticles pointed to by firstSegment and one of vertex
00274     // daughters match ?
00275     // comparison temporarily done through Geant track ID and type
00276     // should be done through edm::Ref
00277     TrackingParticle::g4t_iterator gTkf = (*firstSegment).g4Track_begin();
00278     TrackingParticle::g4t_iterator gTkd = (*d.get()).g4Track_begin();
00279 
00280     if ( ( (*gTkf).trackId() == (*gTkd).trackId() )
00281          && ( (*gTkf).type() == (*gTkd).type() ) ) {
00282       return d;
00283     }
00284   }
00285 
00286 //  std::cout << "PASCAL:: Now make producer of electron tracks" << std::endl;
00287 //  std::cout << "Question: do-able without crossing frame info ?? " << std::endl;
00288 
00289   return TrackingParticleRef();
00290 }
00291 */

Generated on Tue Jun 9 17:47:28 2009 for CMSSW by  doxygen 1.5.4