126 {
127#ifdef HEPMC3
130 std::unique_ptr<HepMC::GenEvent> outputEvent = std::make_unique<HepMC::GenEvent>(inputEvent);
131 if (inputEvent.run_info()) {
132 outputEvent->set_run_info(std::make_shared<HepMC3::GenRunInfo>(*(inputEvent.run_info().get())));
133 }
134 if (inputEvent.heavy_ion()) {
135 outputEvent->set_heavy_ion(std::make_shared<HepMC::GenHeavyIon>(*(inputEvent.heavy_ion())));
136 }
138
139
140 for (auto& particle: outputEvent->particles()) {
143
144 const int shadowId =
particle->id();
145
146 particle->add_attribute(
"ShadowParticleId",
147 std::make_shared<HepMC3::IntAttribute>(shadowId));
148
149
150
151
152 }
153 }
154
155
156 for (;;) {
157 std::vector<HepMC::GenParticlePtr> p_to_remove;
158 std::vector<HepMC::GenVertexPtr> v_to_remove;
159 for (auto& particle: outputEvent->particles()) {
162 p_to_remove.push_back(particle);
163 }
164 }
165 for (auto& particle: p_to_remove) outputEvent->remove_particle(particle);
166 for (auto& vertex: outputEvent->vertices()) {
169 v_to_remove.push_back(vertex);
170 }
171 }
172 for (auto& vertex: v_to_remove) outputEvent->remove_vertex(vertex);
173 if (p_to_remove.empty() && v_to_remove.empty()) break;
174 }
175#else
176
177 std::unique_ptr<HepMC::GenEvent> outputEvent = std::make_unique<HepMC::GenEvent>(inputEvent.signal_process_id(),
178 inputEvent.event_number());
179
180 outputEvent->set_mpi ( inputEvent.mpi() );
181 outputEvent->set_event_scale ( inputEvent.event_scale() );
182 outputEvent->set_alphaQCD ( inputEvent.alphaQCD() );
183 outputEvent->set_alphaQED ( inputEvent.alphaQED() );
184 if ( inputEvent.cross_section() ) {
185 outputEvent->set_cross_section ( *inputEvent.cross_section());
186 }
187 if (inputEvent.heavy_ion()) {
188 outputEvent->set_heavy_ion(*(inputEvent.heavy_ion()));
189 }
190 if (inputEvent.pdf_info()) {
191 outputEvent->set_pdf_info(*(inputEvent.pdf_info()));
192 }
193 outputEvent->define_units( inputEvent.momentum_unit(), inputEvent.length_unit() );
194
195
196
197
198
199
200 std::map<const HepMC::GenVertex*,HepMC::GenVertex*> inputEvtVtxToOutputEvtVtx;
201 HepMC::GenEvent::vertex_const_iterator currentVertexIter(inputEvent.vertices_begin());
202 const HepMC::GenEvent::vertex_const_iterator endOfCurrentListOfVertices(inputEvent.vertices_end());
204 for (; currentVertexIter != endOfCurrentListOfVertices; ++currentVertexIter) {
205 const HepMC::GenVertex *pCurrentVertex(*currentVertexIter);
207 continue;
208 }
209 std::unique_ptr<HepMC::GenVertex> copyOfGenVertex =std::make_unique<HepMC::GenVertex>(pCurrentVertex->position(), pCurrentVertex->id(), pCurrentVertex->weights() );
210 copyOfGenVertex->suggest_barcode(
HepMC::barcode(pCurrentVertex) );
211 inputEvtVtxToOutputEvtVtx[pCurrentVertex] = copyOfGenVertex.get();
212 outputEvent->add_vertex( copyOfGenVertex.release() );
213 }
214
215
216 if ( inputEvent.signal_process_vertex() ) {
217 outputEvent->set_signal_process_vertex( inputEvtVtxToOutputEvtVtx[inputEvent.signal_process_vertex()] );
218 }
219 else {
220 outputEvent->set_signal_process_vertex( nullptr );
221 }
222
223
224
225 HepMC::GenParticle*
beam1{};
226 HepMC::GenParticle*
beam2{};
227 for ( HepMC::GenEvent::particle_const_iterator particleIter = inputEvent.particles_begin();
228 particleIter != inputEvent.particles_end(); ++particleIter ) {
229 const HepMC::GenParticle* currentParticle = *particleIter;
231 continue;
232 }
233 std::unique_ptr<HepMC::GenParticle> copyOfGenParticle = std::make_unique<HepMC::GenParticle>(*currentParticle);
234 const bool isBeamParticle1(currentParticle == inputEvent.beam_particles().first);
235 const bool isBeamParticle2(currentParticle == inputEvent.beam_particles().second);
236
237
238
239 const bool shouldAddProdVertex(currentParticle->production_vertex() && inputEvtVtxToOutputEvtVtx[ currentParticle->production_vertex() ]);
240 const bool shouldAddEndVertex(currentParticle->end_vertex() && inputEvtVtxToOutputEvtVtx[ currentParticle->end_vertex() ]);
241 if ( isBeamParticle1 || isBeamParticle2 || shouldAddProdVertex || shouldAddEndVertex ) {
242 HepMC::GenParticle* particleCopy = copyOfGenParticle.release();
243 if ( isBeamParticle1 ) {
244 beam1 = particleCopy;
245 }
246 if ( isBeamParticle2 ) {
247 beam2 = particleCopy;
248 }
249 if ( shouldAddProdVertex || shouldAddEndVertex ) {
250 if ( shouldAddEndVertex ) {
251 inputEvtVtxToOutputEvtVtx[ currentParticle->end_vertex() ]->
252 add_particle_in(particleCopy);
253 }
254 if ( shouldAddProdVertex ) {
255 inputEvtVtxToOutputEvtVtx[ currentParticle->production_vertex() ]->
256 add_particle_out(particleCopy);
257 }
258 }
259 else {
260 ATH_MSG_WARNING (
"Found GenParticle with no production or end vertex! \n" << *currentParticle);
261 }
262 }
263 }
264 outputEvent->set_beam_particles( beam1, beam2 );
265
266
267 outputEvent->set_random_states( inputEvent.random_states() );
268 outputEvent->weights() = inputEvent.weights();
269#endif
270 return outputEvent;
271}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
void fillBarcodesAttribute(GenEvent *)
const GenParticle * ConstGenParticlePtr
const HepMC::GenVertex * ConstGenVertexPtr
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses