Book an AIDA::IDataPointSet into the THistSvc as a TH1D at path.
262 {
263 auto modEvent = std::make_unique<HepMC::GenEvent>(event);
264
266
267 SG::ReadHandle<xAOD::EventInfo> evtInfo(
m_evtInfoKey, ctx);
268 modEvent->set_event_number(static_cast<int>(evtInfo->eventNumber()));
269 }
270
271
272#ifdef HEPMC3
273 std::shared_ptr<HepMC3::GenRunInfo> modRunInfo;
274 if (
event.run_info()) {
275 modRunInfo = std::make_shared<HepMC3::GenRunInfo>(*(
event.run_info().get()));
276 if (
event.run_info()->weight_names().empty() &&
event.weights().size() == 1) {
277 modRunInfo->set_weight_names({"Default"});
278 }
279 }
280 else {
282 modRunInfo = std::make_shared<HepMC3::GenRunInfo>();
283 std::vector<std::string> w_names;
284 for (
size_t i = 0;
i <
event.weights().size();
i++) { w_names.push_back(std::string(
"badweight") + std::to_string(i)); }
285 modRunInfo->set_weight_names(w_names);
286 }
287 modEvent->set_run_info(std::move(modRunInfo));
288 std::vector<std::string> w_names = modEvent->weight_names();
289 if (w_names.size()) {
290 std::vector<std::pair<std::string,std::string> > w_subs = {
291 {" nominal ",""},
292 {" set = ","_"},
293 {" = ","_"},
294 {"=",""},
295 {",",""},
296 {".",""},
297 {":",""},
298 {" ","_"},
299 {"#","num"},
300 {"\n","_"},
301 {"/","over"}
302 };
303 for (std::string& wname : w_names) {
304 for (const auto& sub : w_subs) {
305 size_t start_pos = wname.find(sub.first);
306 while (start_pos != std::string::npos) {
307 wname.replace(start_pos, sub.first.length(), sub.second);
308 start_pos = wname.find(sub.first);
309 }
310 }
311 }
312 modEvent->run_info()->set_weight_names(w_names);
313 }
314#else
315 const HepMC::WeightContainer& old_wc = event.weights();
316 std::vector<std::string> old_wnames = old_wc.weight_names();
317 if (old_wnames.size()) {
318 HepMC::WeightContainer& new_wc = modEvent->weights();
319 new_wc.clear();
320 std::vector<std::pair<std::string,std::string> > w_subs = {
321 {" nominal ",""},
322 {" set = ","_"},
323 {" = ","_"},
324 {"=",""},
325 {",",""},
326 {".",""},
327 {":",""},
328 {" ","_"},
329 {"#","num"},
330 {"\n","_"},
331 {"/","over"}
332 };
333 std::map<std::string, double> new_name_to_value;
334 std::map<std::string, std::string> old_name_to_new_name;
335 for (const std::string& old_name : old_wnames) {
336 std::string wname = std::string(old_name);
337 double value = old_wc[old_name];
338 for (const auto& sub : w_subs) {
339 size_t start_pos = wname.find(sub.first);
340 while (start_pos != std::string::npos) {
341 wname.replace(start_pos, sub.first.length(), sub.second);
342 start_pos = wname.find(sub.first);
343 }
344 }
345 new_name_to_value[wname] =
value;
346 old_name_to_new_name[old_name] = wname;
347 }
348 auto itEnd = old_name_to_new_name.end();
349 for (const std::string& old_name : old_wnames) {
350 if (old_name_to_new_name.find(old_name) == itEnd) continue;
351 const std::string& new_name = old_name_to_new_name[old_name];
352 new_wc[ new_name ] = new_name_to_value[new_name];
353 }
354
355 }
356#endif
357
358#ifdef HEPMC3
359 modEvent->set_units(HepMC3::Units::GEV, HepMC3::Units::MM);
360 if (modEvent->particles().size() == 1) modEvent->set_beam_particles(modEvent->particles().front(), modEvent->particles().front());
362
363
364 double etotal = 0;
365 for (const auto& p : modEvent->particles()) {
367 etotal +=
p->momentum().e();
368 }
369 const double ebeam = 0.5*etotal;
370
371 HepMC::GenParticlePtr b1 = std::make_shared<HepMC::GenParticle>(HepMC::FourVector(0,0,ebeam,ebeam),2212,4);
372 HepMC::GenParticlePtr b2 = std::make_shared<HepMC::GenParticle>(HepMC::FourVector(0,0,-1*ebeam,ebeam),2212,4);
373
374 std::vector<HepMC::GenParticlePtr> notBeams;
377 }
378
379 for (const auto& bp : notBeams) bp->production_vertex()->remove_particle_out(bp);
380
381 modEvent->set_beam_particles(std::move(b1), std::move(b2));
382 }
383 if (modEvent->beams().front()->momentum().e() > 50000.0) {
385 }
386#else
387 modEvent->use_units(HepMC::Units::GEV, HepMC::Units::MM);
388 if (modEvent->particles_size() == 1) modEvent->set_beam_particles(*modEvent->particles_begin(), *modEvent->particles_begin());
389 if (modEvent->beam_particles().first->momentum().e() > 50000.0) {
391 }
392#endif
393
394 return modEvent;
395}
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
void MeV2GeV(HepMC::GenEvent &event)
GenParticle * GenParticlePtr
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isBeam(const T &p)
Identify if the particle is beam particle.