79 {
81 vector<BesTruthTrack*>* trackList = sensitiveManager->
GetTrackList();
82 G4int nTrack = trackList->size();
83 BesTruthTrack* track;
84
85 vector<BesTruthVertex*>* vertexList = sensitiveManager->
GetVertexList();
86 G4int nVertex = vertexList->size();
87 BesTruthVertex* vertex;
88
89
90 for ( int i = 0; i < nTrack - 1; i++ )
91 for ( int j = i + 1; j < nTrack; j++ )
92 if ( ( *trackList )[i]->GetIndex() > ( *trackList )[j]->GetIndex() )
93 {
94 track = ( *trackList )[i];
95 ( *trackList )[i] = ( *trackList )[j];
96 ( *trackList )[j] = track;
97 }
98
100
101
102 for ( int i = 0; i < nTrack; i++ )
103 {
104 track = ( *trackList )[i];
105
106
107 bool isPrimary = false;
108 bool startPointFound = false;
109 BesTruthVertex* startPoint = nullptr;
110
111 for ( int i = 0; i < nVertex; i++ )
112 {
113 vertex = ( *vertexList )[i];
115 {
117 startPointFound = true;
118 startPoint = vertex;
119 break;
120 }
121 }
122
123 if ( !startPointFound )
124 std::cout << "error in finding the start point of a track" << std::endl;
125
126 bool endPointFound = false;
127
128 for ( int i = 0; i < nVertex; i++ )
129 {
130 vertex = ( *vertexList )[i];
132 {
134 {
135
136 Event::McParticle* mcParticle = new Event::McParticle;
137
138
139 HepLorentzVector initialMomentum(
140 track->
GetP4().x() / 1000., track->
GetP4().y() / 1000.,
141 track->
GetP4().z() / 1000., track->
GetP4().t() / 1000. );
142
143 HepLorentzVector initialPosition(
146
148
149
151
152
154
157
158
159
160
161 if ( track->
GetSource() ==
"FromGenerator" )
163 else if ( track->
GetSource() ==
"FromG4" )
166
167
168
169
170
173
174
175 HepLorentzVector finalPosition( vertex->
GetPosition().x() / 10.,
178 mcParticle->
finalize( finalPosition );
179
180
181 particleCol->push_back( mcParticle );
182
183 endPointFound = true;
184 }
185 }
186 }
187
188 if ( !endPointFound )
189 {
190
192 {
193
194 Event::McParticle* mcParticle = new Event::McParticle;
195
196 HepLorentzVector initialMomentum(
197 track->
GetP4().x() / 1000., track->
GetP4().y() / 1000., track->
GetP4().z() / 1000.,
198 track->
GetP4().t() / 1000. );
199 HepLorentzVector initialPosition(
202
204
205
207
208
211
212
215
216
217
218
219 if ( track->
GetSource() ==
"FromGenerator" )
221 else if ( track->
GetSource() ==
"FromG4" )
224
225
226
227
228
229
230 particleCol->push_back( mcParticle );
231 continue;
232 }
233 }
234 }
235
236
237 SmartRefVector<Event::McParticle> primaryParticleCol;
238 Event::McParticleCol::iterator iter_particle;
239 for ( iter_particle = particleCol->begin(); iter_particle != particleCol->end();
240 iter_particle++ )
241 {
242
243 if ( ( *iter_particle )->primaryParticle() )
244 {
245 Event::McParticle* mcPart = (Event::McParticle*)( *iter_particle );
246 primaryParticleCol.push_back( mcPart );
247 }
248 }
249
250 if ( primaryParticleCol.empty() ) std::cout << "no primary particle found!" << std::endl;
251
252
253 SmartRefVector<Event::McParticle>::iterator iter_primary;
254 for ( iter_primary = primaryParticleCol.begin(); iter_primary != primaryParticleCol.end();
255 iter_primary++ )
256 {
257 if ( !( ( *iter_primary )->leafParticle() ) )
AddMother( ( *iter_primary ), particleCol );
258 }
259
260
261 StatusCode sc = m_evtSvc->registerObject( "/Event/MC/McParticleCol", particleCol );
262 if ( sc != StatusCode::SUCCESS )
263 G4cout << "Could not register McParticle collection" << G4endl;
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287}
std::vector< BesTruthVertex * > * GetVertexList()
std::vector< BesTruthTrack * > * GetTrackList()
static BesSensitiveManager * GetSensitiveManager()
HepLorentzVector GetP4() const
BesTruthVertex * GetTerminalVertex() const
BesTruthVertex * GetVertex() const
vector< int > GetDaughterIndexes() const
BesTruthTrack * GetParentTrack() const
G4ThreeVector GetPosition() const
void setVertexIndex0(int index0)
methods for setting and getting vertex indexes
@ DECAYFLT
Decayed by generator.
@ PRIMARY
Decayed in flight.
@ ERROR
this particle is a leaf in the particle tree
void initialize(StdHepId id, unsigned int statusBits, const HepLorentzVector &initialMomentum, const HepLorentzVector &initialPosition, const std::string process="")
Set the initial attributes of the McParticle.
void addStatusFlag(unsigned int flag)
add a new flag to the status flags
void finalize(const HepLorentzVector &finalPosition)
Set the final attributes of the McParticle.
void setVertexIndex1(int index1)
void setTrackIndex(int trackIndex)
ObjectList< McParticle > McParticleCol