31{
33
34
36
39 SG::ReadHandle<McEventCollection> bkgContainer(
m_bkgInputKey, ctx);
40 if (!bkgContainer.isValid()) {
41 ATH_MSG_ERROR(
"Could not get background McEventCollection container " << bkgContainer.name() <<
" from store " << bkgContainer.store());
42 return StatusCode::FAILURE;
43 }
44 bkgContainerPtr = bkgContainer.cptr();
45
46 ATH_MSG_DEBUG(
"Found background McEventCollection container " << bkgContainer.name() <<
" in store " << bkgContainer.store());
47 }
48
50 if (!signalContainer.isValid()) {
51 ATH_MSG_ERROR(
"Could not get signal McEventCollection container " << signalContainer.name() <<
" from store " << signalContainer.store());
52 return StatusCode::FAILURE;
53 }
54 ATH_MSG_DEBUG(
"Found signal McEventCollection container " << signalContainer.name() <<
" in store " << signalContainer.store());
55
56
57 SG::WriteHandle<McEventCollection> outputContainer(
m_outputKey, ctx);
58 ATH_CHECK(outputContainer.record(std::make_unique<McEventCollection>()));
59 if (!outputContainer.isValid()) {
60 ATH_MSG_ERROR(
"Could not record output McEventCollection container " << outputContainer.name() <<
" to store " << outputContainer.store());
61 return StatusCode::FAILURE;
62 }
63 ATH_MSG_DEBUG(
"Recorded output McEventCollection container " << outputContainer.name() <<
" in store " << outputContainer.store());
64
65 unsigned int droppedSeparatorGenEvents{0};
66#ifdef HEPMC3
67 int backupPileUpType{0};
68 int backupBunchCrossingTime{0};
69#endif
70
72#ifdef HEPMC3
73 if ( (*it)->event_number() == -1 ) {
74 ++droppedSeparatorGenEvents;
75 ATH_MSG_VERBOSE(
"Signal: Skipping a separator GenEvent. " << droppedSeparatorGenEvents <<
" skipped so far.");
76 backupBunchCrossingTime+=25;
77 continue;
78 }
79#endif
80 HepMC::GenEvent* copiedEvent = new HepMC::GenEvent(**it);
82#ifdef HEPMC3
83 auto bunchCrossingTime = (*it)->attribute<HepMC3::IntAttribute>("BunchCrossingTime");
84 if (bunchCrossingTime) {
85 copiedEvent->add_attribute("BunchCrossingTime",std::make_shared<HepMC3::IntAttribute>(bunchCrossingTime->value()));
86 }
87 else {
88 copiedEvent->add_attribute("BunchCrossingTime",std::make_shared<HepMC3::IntAttribute>(backupBunchCrossingTime));
89 }
90 auto pileupType = (*it)->attribute<HepMC3::IntAttribute>("PileUpType");
91 if (pileupType) {
92 copiedEvent->add_attribute("PileUpType",std::make_shared<HepMC3::IntAttribute>(pileupType->value()));
93 }
94 else {
95 copiedEvent->add_attribute("PileUpType",std::make_shared<HepMC3::IntAttribute>(backupPileUpType));
96 if (backupPileUpType == 0) { backupPileUpType = 1; }
97 }
98#endif
99 if (!copiedEvent->heavy_ion() && (*it)->heavy_ion()) {
100
101
102#ifdef HEPMC3
103 HepMC::GenHeavyIonPtr hinew=std::make_shared<HepMC::GenHeavyIon>(*((*it)->heavy_ion()));
104 copiedEvent->set_heavy_ion(std::move(hinew));
105#else
106 copiedEvent->set_heavy_ion(*((*it)->heavy_ion()));
107#endif
108 }
109 outputContainer->push_back(copiedEvent);
110 }
111
112#ifdef HEPMC3
113 backupBunchCrossingTime = 0;
114#endif
115
119
121 }
122 for ( ;
it != bkgContainerPtr->
end(); ++
it) {
123#ifdef HEPMC3
124 if ( (*it)->event_number() == -1 ) {
125 ++droppedSeparatorGenEvents;
126 ATH_MSG_VERBOSE(
"Background: Skipping a separator GenEvent. " << droppedSeparatorGenEvents <<
" skipped so far.");
127 backupBunchCrossingTime+=25;
128 continue;
129 }
130#endif
131 HepMC::GenEvent* copiedEvent = new HepMC::GenEvent(**it);
133#ifdef HEPMC3
134 auto bunchCrossingTime = (*it)->attribute<HepMC3::IntAttribute>("BunchCrossingTime");
135 if (bunchCrossingTime) {
136 copiedEvent->add_attribute("BunchCrossingTime",std::make_shared<HepMC3::IntAttribute>(bunchCrossingTime->value()));
137 }
138 else {
139 copiedEvent->add_attribute("BunchCrossingTime",std::make_shared<HepMC3::IntAttribute>(backupBunchCrossingTime));
140 }
141 auto pileupType = (*it)->attribute<HepMC3::IntAttribute>("PileUpType");
142 if (pileupType) {
143 copiedEvent->add_attribute("PileUpType",std::make_shared<HepMC3::IntAttribute>(pileupType->value()));
144 }
145 else {
146 copiedEvent->add_attribute("PileUpType",std::make_shared<HepMC3::IntAttribute>(backupPileUpType));
147 if (backupPileUpType == 0) { backupPileUpType = 1; }
148 }
149#endif
150 if (!copiedEvent->heavy_ion() && (*it)->heavy_ion()) {
151
152
153#ifdef HEPMC3
154 HepMC::GenHeavyIonPtr hinew=std::make_shared<HepMC::GenHeavyIon>(*((*it)->heavy_ion()));
155 copiedEvent->set_heavy_ion(std::move(hinew));
156#else
157 copiedEvent->set_heavy_ion(*((*it)->heavy_ion()));
158#endif
159 }
160 outputContainer->push_back(copiedEvent);
161 }
162 }
163 ATH_MSG_VERBOSE(
"output size: " << outputContainer->size() <<
", Signal Input size: " << signalContainer->size() <<
", Bkg Input size: " << bkgContainerPtr->
size() <<
", dropped neutrino GenEvents: " << (
m_removeBkgHardScatterTruth ? 1 : 0) <<
" , dropped Separator GenEvents: " << droppedSeparatorGenEvents);
164
166 if (!outputContainer->empty()) {
168 for (const HepMC::GenEvent *event : *outputContainer) {
170 }
171 }
172 }
173
175 return StatusCode::SUCCESS;
176}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
bool msgLvl(const MSG::Level lvl) const
Gaudi::Property< bool > m_removeBkgHardScatterTruth
SG::ReadHandleKey< McEventCollection > m_bkgInputKey
SG::WriteHandleKey< McEventCollection > m_outputKey
SG::ReadHandleKey< McEventCollection > m_signalInputKey
DataModel_detail::const_iterator< DataVector > const_iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
int signal_process_id(const GenEvent &e)
void fillBarcodesAttribute(GenEvent *)