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
00017
00018
00019 TrackList tracks(allTracks.begin(), allTracks.end());
00020 TrackList electronTracks(electronFilter(tracks));
00021
00022
00023
00024 if ( electronTracks.empty() ) return ElectronList();
00025
00026
00027
00028 ElectronList electrons;
00029 TrackList trackSegments;
00030 while ( electronTracks.size() ) {
00031
00032
00033
00034 const TrackPtr startSegment = electronTracks.front();
00035 electronTracks.pop_front();
00036 trackSegments.clear();
00037 trackSegments.push_back(startSegment);
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 searchInwards(electronTracks, startSegment, trackSegments);
00049
00050
00051
00052
00053
00054 searchOutwards(electronTracks, startSegment, trackSegments);
00055
00056
00057
00058
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
00075
00076 while ( TrackPtr nextSegment = findParent(*currentSegment) ) {
00077 trackSegments.push_front(nextSegment);
00078 electronTracks.remove(nextSegment);
00079 currentSegment = nextSegment;
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 }
00091 }
00092
00093
00094 const TkNavigableSimElectronAssembler::TrackPtr
00095 TkNavigableSimElectronAssembler::findParent (const TrackingParticle& track)
00096 const
00097 {
00098
00099
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
00115 TrackPtr currentSegment(startSegment);
00116 while ( TrackPtr nextSegment = findChild(*currentSegment) ) {
00117 trackSegments.push_back(nextSegment);
00118 electronTracks.remove(nextSegment);
00119 currentSegment = nextSegment;
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 }
00131 }
00132
00133
00134 const TkNavigableSimElectronAssembler::TrackPtr
00135 TkNavigableSimElectronAssembler::findChild (const TrackingParticle& track)
00136 const
00137 {
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 TrackingVertexRefVector decayVertices = track.decayVertices();
00148 if ( decayVertices.empty() ) {
00149
00150 return 0;
00151 }
00152
00153 std::pair<TrackPtr, TrackPtr> segmentPair
00154
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
00172
00173 if ( vertex==0 ) return result;
00174 const TrackingParticleRefVector parents(vertex->sourceTracks());
00175 if ( parents.empty() ) {
00176
00177 return result;
00178 }
00179 if ( parents.size() != 1 ) {
00180
00181 return result;
00182 }
00183 if ( abs( (**parents.begin()).pdgId()) != 11 ) {
00184
00185
00186 return result;
00187 }
00188
00189
00190
00191 const TrackingParticleRefVector secondaries(vertex->daughterTracks());
00192 TrackPtr child(0);
00193 int nPhoton(0);
00194
00195 for ( TrackingVertex::tp_iterator it=vertex->daughterTracks_begin();
00196 it!=vertex->daughterTracks_end(); it++ ) {
00197
00198 if ( abs((**it).pdgId()) == 11 ) {
00199
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
00205 else if ( (**it).pdgId() == 22 ) {
00206 nPhoton++;
00207 if ( nPhoton>1 ) {
00208
00209 return result;
00210 }
00211 }
00212 else {
00213
00214
00215 return result;
00216 }
00217 }
00218
00219
00220
00221
00222
00223
00224
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
00248 }
00249 else {
00250 others.push_back(*it);
00251 }
00252 }
00253
00254
00255 allTracks = others;
00256 return electrons;
00257 }
00258
00259
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291