15#include "CLHEP/Vector/LorentzVector.h"
16#include "CLHEP/Units/SystemOfUnits.h"
18#include "CLHEP/Geometry/Point3D.h"
28 return StatusCode::SUCCESS;
35 bool resetProblem(
false);
36 for (
const auto& particle: event) {
38 if (!particle->production_vertex()) {
39 ATH_MSG_ERROR(
"Stable particle without a production vertex!! " << particle);
43 ATH_MSG_ERROR(
"Stable particle with an end vertex!! " << particle);
48 if (!particle->production_vertex()) {
49 ATH_MSG_ERROR(
"Decayed particle without a production vertex!! " << particle);
52 if (!particle->end_vertex()) {
53 ATH_MSG_ERROR(
"Decayed particle without an end vertex!! " << particle);
59 return StatusCode::FAILURE;
62 return StatusCode::SUCCESS;
73 for (
const auto& originalPartIn: origVertex->particles_in())
ATH_MSG_INFO( originalPartIn );
75 for (
const auto& originalPartOut: origVertex->particles_out())
ATH_MSG_INFO( originalPartOut );
80 for (
const auto& resetPartIn: resetVertex->particles_in())
ATH_MSG_INFO( resetPartIn );
82 for (
const auto& resetPartOut: resetVertex->particles_out())
ATH_MSG_INFO( resetPartOut );
89 const HepMC::GenVertex& resetVertex)
const
95 HepMC::GenVertex::particles_in_const_iterator originalPartInIter(origVertex.particles_in_const_begin());
96 const HepMC::GenVertex::particles_in_const_iterator endOfOriginalListOfParticlesIn(origVertex.particles_in_const_end());
97 while( originalPartInIter!=endOfOriginalListOfParticlesIn ) {
102 HepMC::GenVertex::particles_out_const_iterator originalPartOutIter(origVertex.particles_out_const_begin());
103 const HepMC::GenVertex::particles_out_const_iterator endOfOriginalListOfParticlesOut(origVertex.particles_out_const_end());
104 while( originalPartOutIter!=endOfOriginalListOfParticlesOut) {
106 ++originalPartOutIter;
112 HepMC::GenVertex::particles_in_const_iterator resetPartInIter(resetVertex.particles_in_const_begin());
113 const HepMC::GenVertex::particles_in_const_iterator endOfResetListOfParticlesIn(resetVertex.particles_in_const_end());
114 while( resetPartInIter!=endOfResetListOfParticlesIn ) {
119 HepMC::GenVertex::particles_out_const_iterator resetPartOutIter(resetVertex.particles_out_const_begin());
120 const HepMC::GenVertex::particles_out_const_iterator endOfResetListOfParticlesOut(resetVertex.particles_out_const_end());
121 while( resetPartOutIter!=endOfResetListOfParticlesOut) {
134 if (!origVertex && !resetVertex)
return StatusCode::SUCCESS;
135 if (!origVertex || !resetVertex)
return StatusCode::FAILURE;
142 if (origVertex->position() != resetVertex->position()) {
143 const HepMC::FourVector& oP = origVertex->position();
144 const HepMC::FourVector& rP = resetVertex->position();
145 ATH_MSG_ERROR(
"vertex position differs! Original: ("<<oP.x()<<
","<<oP.y()<<
","<<oP.z()<<
","<<oP.t()<<
"), Reset: ("<<rP.x()<<
","<<rP.y()<<
","<<rP.z()<<
","<<rP.t()<<
")");
148 if (origVertex->particles_in().size() != resetVertex->particles_in().size() ) {
149 ATH_MSG_ERROR (
"particles_in_size differs! Original: "<<origVertex->particles_in().size()<<
", Reset: "<<resetVertex->particles_in().size());
152 if (origVertex->particles_out().size() != resetVertex->particles_out().size() ) {
153 ATH_MSG_ERROR (
"particles_out_size differs! Original: "<<origVertex->particles_out().size()<<
", Reset: "<<resetVertex->particles_out().size());
156 std::vector<HepMC::ConstGenParticlePtr> OriginalListOfParticlesIn = origVertex->particles_in();
157 std::vector<HepMC::ConstGenParticlePtr> ResetListOfParticlesIn = resetVertex->particles_in();
158 for ( std::vector<HepMC::ConstGenParticlePtr>::iterator originalPartInIter(OriginalListOfParticlesIn.begin()),resetPartInIter(ResetListOfParticlesIn.begin());
159 originalPartInIter != OriginalListOfParticlesIn.end() && resetPartInIter != ResetListOfParticlesIn.end();
160 ++originalPartInIter, ++resetPartInIter
170 std::vector<HepMC::ConstGenParticlePtr> OriginalListOfParticlesOut = origVertex->particles_out();
171 std::vector<HepMC::ConstGenParticlePtr> ResetListOfParticlesOut = resetVertex->particles_out();
173 std::sort(OriginalListOfParticlesOut.begin(), OriginalListOfParticlesOut.end(), [](
auto&
a,
auto& b) ->
bool{return a->momentum().pz() > b->momentum().pz(); });
174 std::sort(ResetListOfParticlesOut.begin(), ResetListOfParticlesOut.end(), [](
auto&
a,
auto& b) ->
bool{return a->momentum().pz() > b->momentum().pz(); });
176 for ( std::vector<HepMC::ConstGenParticlePtr>::iterator originalPartOutIter(OriginalListOfParticlesOut.begin()), resetPartOutIter(ResetListOfParticlesOut.begin());
177 originalPartOutIter != OriginalListOfParticlesOut.end() && resetPartOutIter != ResetListOfParticlesOut.end();
178 ++originalPartOutIter, ++resetPartOutIter
186 if(!pass) {
return StatusCode::FAILURE; }
187 return StatusCode::SUCCESS;
193 const HepMC::GenVertex& resetVertex)
const
201 if (origVertex.position() != resetVertex.position()) {
202 const HepMC::FourVector& oP = origVertex.position();
203 const HepMC::FourVector& rP = resetVertex.position();
204 ATH_MSG_ERROR(
"vertex position differs! Original: ("<<oP.x()<<
","<<oP.y()<<
","<<oP.z()<<
","<<oP.t()<<
"), Reset: ("<<rP.x()<<
","<<rP.y()<<
","<<rP.z()<<
","<<rP.t()<<
")");
207 if (origVertex.particles_in_size() != resetVertex.particles_in_size() ) {
208 ATH_MSG_ERROR (
"particles_in_size differs! Original: "<<origVertex.particles_in_size()<<
", Reset: "<<resetVertex.particles_in_size());
211 if (origVertex.particles_out_size() != resetVertex.particles_out_size() ) {
212 ATH_MSG_ERROR (
"particles_out_size differs! Original: "<<origVertex.particles_out_size()<<
", Reset: "<<resetVertex.particles_out_size());
215 HepMC::GenVertex::particles_in_const_iterator originalPartInIter(origVertex.particles_in_const_begin());
216 const HepMC::GenVertex::particles_in_const_iterator endOfOriginalListOfParticlesIn(origVertex.particles_in_const_end());
217 HepMC::GenVertex::particles_in_const_iterator resetPartInIter(resetVertex.particles_in_const_begin());
218 const HepMC::GenVertex::particles_in_const_iterator endOfResetListOfParticlesIn(resetVertex.particles_in_const_end());
219 while( originalPartInIter!=endOfOriginalListOfParticlesIn &&
220 resetPartInIter!=endOfResetListOfParticlesIn ) {
227 ++originalPartInIter;
230 HepMC::GenVertex::particles_out_const_iterator originalPartOutIter(origVertex.particles_out_const_begin());
231 const HepMC::GenVertex::particles_out_const_iterator endOfOriginalListOfParticlesOut(origVertex.particles_out_const_end());
233 const HepMC::GenVertex::particles_out_const_iterator endOfResetListOfParticlesOut(resetVertex.particles_out_const_end());
234 while( originalPartOutIter!=endOfOriginalListOfParticlesOut) {
236 HepMC::GenVertex::particles_out_const_iterator resetPartOutIter(resetVertex.particles_out_const_begin());
237 HepMC::GenVertex::particles_in_const_iterator matchingResetParticleIter{endOfResetListOfParticlesOut};
238 while(resetPartOutIter!=endOfResetListOfParticlesOut) {
240 matchingResetParticleIter = resetPartOutIter;
245 if (matchingResetParticleIter==endOfResetListOfParticlesOut ||
251 ++originalPartOutIter;
254 if(!pass) {
return StatusCode::FAILURE; }
255 return StatusCode::SUCCESS;
261 const HepMC::FourVector& resetMomenta)
const
265 if (
m_momentaLimit<std::abs(origMomenta.px()-resetMomenta.px())) {
268 if (
m_momentaLimit<std::abs(origMomenta.py()-resetMomenta.py())) {
271 if (
m_momentaLimit<std::abs(origMomenta.pz()-resetMomenta.pz())) {
277 if(origMomenta != resetMomenta) {
282 if(!pass) {
return StatusCode::FAILURE; }
283 return StatusCode::SUCCESS;
290 if (!origParticle && !resetParticle)
return StatusCode::SUCCESS;
291 if (!origParticle || !resetParticle)
return StatusCode::FAILURE;
298 if (origParticle->status() != resetParticle->status()) {
299 ATH_MSG_ERROR (
"particle status differs! Original: "<<origParticle->status()<<
", Reset: "<<resetParticle->status());
302 if (origParticle->pdg_id() != resetParticle->pdg_id()) {
303 ATH_MSG_ERROR (
"particle pdg_id differs! Original: "<<origParticle->pdg_id()<<
", Reset: "<<resetParticle->pdg_id());
306 if (
compareMomenta(origParticle->momentum(), resetParticle->momentum()).isFailure()) {
307 const HepMC::FourVector& oM = origParticle->momentum();
308 const HepMC::FourVector& rM = resetParticle->momentum();
309 ATH_MSG_DEBUG(
"particle momentum differs! Original: ("<<oM.x()<<
","<<oM.y()<<
","<<oM.z()<<
","<<oM.t()<<
"), Reset: ("<<rM.x()<<
","<<rM.y()<<
","<<rM.z()<<
","<<rM.t()<<
")");
312 if(!pass) {
return StatusCode::FAILURE; }
313 return StatusCode::SUCCESS;
318 const HepMC::GenParticle& resetParticle)
const
325 if (origParticle.status() != resetParticle.status()) {
326 ATH_MSG_ERROR (
"particle status differs! Original: "<<origParticle.status()<<
", Reset: "<<resetParticle.status());
329 if (origParticle.pdg_id() != resetParticle.pdg_id()) {
330 ATH_MSG_ERROR (
"particle pdg_id differs! Original: "<<origParticle.pdg_id()<<
", Reset: "<<resetParticle.pdg_id());
333 if (
compareMomenta(origParticle.momentum(), resetParticle.momentum()).isFailure()) {
334 const HepMC::FourVector& oM = origParticle.momentum();
335 const HepMC::FourVector& rM = resetParticle.momentum();
336 ATH_MSG_DEBUG(
"particle momentum differs! Original: ("<<oM.x()<<
","<<oM.y()<<
","<<oM.z()<<
","<<oM.t()<<
"), Reset: ("<<rM.x()<<
","<<rM.y()<<
","<<rM.z()<<
","<<rM.t()<<
")");
339 if(!pass) {
return StatusCode::FAILURE; }
340 return StatusCode::SUCCESS;
351 if (!originalMcEventCollection.isValid()) {
352 ATH_MSG_ERROR(
"Could not find original McEventCollection called " << originalMcEventCollection.name() <<
" in store " << originalMcEventCollection.store() <<
".");
353 return StatusCode::FAILURE;
355 const HepMC::GenEvent& originalEvent(**(originalMcEventCollection->begin()));
358 ATH_MSG_FATAL(
"Problems in original GenEvent - bailing out.");
359 return StatusCode::FAILURE;
363 if (!resetMcEventCollection.isValid()) {
364 ATH_MSG_ERROR(
"Could not find reset McEventCollection called " << resetMcEventCollection.name() <<
" in store " << resetMcEventCollection.store() <<
".");
365 return StatusCode::FAILURE;
367 const HepMC::GenEvent& resetEvent(**(resetMcEventCollection->begin()));
371 return StatusCode::FAILURE;
374 if (originalEvent.event_number() != resetEvent.event_number() ) {
375 ATH_MSG_ERROR (
"event_number differs! Original: "<<originalEvent.event_number()<<
", Reset: "<<resetEvent.event_number());
382 std::vector<HepMC::ConstGenParticlePtr> OriginalBeams = originalEvent.beams();
383 std::vector<HepMC::ConstGenParticlePtr> ResetBeams = resetEvent.beams();
385 for ( std::vector<HepMC::ConstGenParticlePtr>::iterator originalBeamIter(OriginalBeams.begin()), resetBeamIter(ResetBeams.begin());
386 originalBeamIter != OriginalBeams.end() && resetBeamIter != ResetBeams.end();
387 ++originalBeamIter, ++resetBeamIter
393 if (originalEvent.particles().size() != resetEvent.particles().size() ) {
394 ATH_MSG_ERROR (
"particles_size differs! Original: "<<originalEvent.particles().size()<<
", Reset: "<<resetEvent.particles().size());
397 if (originalEvent.vertices().size() != resetEvent.vertices().size() ) {
398 ATH_MSG_ERROR (
"vertices_size differs! Original: "<<originalEvent.vertices().size()<<
", Reset: "<<resetEvent.vertices().size());
403 std::vector<HepMC::ConstGenVertexPtr> OriginalListOfVertices = originalEvent.vertices();
404 std::vector<HepMC::ConstGenVertexPtr> ResetListOfVertices = resetEvent.vertices();
406 for( std::vector<HepMC::ConstGenVertexPtr>::iterator origVertexIter(OriginalListOfVertices.begin()),resetVertexIter(ResetListOfVertices.begin());
407 origVertexIter != OriginalListOfVertices.end() && resetVertexIter != ResetListOfVertices.end();
408 ++origVertexIter, ++resetVertexIter
415 ATH_MSG_INFO(
"Completed Truth reset closure check ..... " );
417 return StatusCode::SUCCESS;
430 if (!originalMcEventCollection.
isValid()) {
431 ATH_MSG_ERROR(
"Could not find original McEventCollection called " << originalMcEventCollection.
name() <<
" in store " << originalMcEventCollection.
store() <<
".");
432 return StatusCode::FAILURE;
434 const HepMC::GenEvent& originalEvent(**(originalMcEventCollection->begin()));
437 ATH_MSG_FATAL(
"Problems in original GenEvent - bailing out.");
438 return StatusCode::FAILURE;
442 if (!resetMcEventCollection.
isValid()) {
443 ATH_MSG_ERROR(
"Could not find reset McEventCollection called " << resetMcEventCollection.
name() <<
" in store " << resetMcEventCollection.
store() <<
".");
444 return StatusCode::FAILURE;
446 const HepMC::GenEvent& resetEvent(**(resetMcEventCollection->begin()));
450 return StatusCode::FAILURE;
453 if (originalEvent.event_number() != resetEvent.event_number() ) {
454 ATH_MSG_ERROR (
"event_number differs! Original: "<<originalEvent.event_number()<<
", Reset: "<<resetEvent.event_number());
457 if (originalEvent.signal_process_id() != resetEvent.signal_process_id() ) {
458 ATH_MSG_ERROR (
"signal_process_id differs! Original: "<<originalEvent.signal_process_id()<<
", Reset: "<<resetEvent.signal_process_id());
461 if (originalEvent.valid_beam_particles() != resetEvent.valid_beam_particles() ) {
462 ATH_MSG_ERROR (
"valid_beam_particles differs! Original: "<<originalEvent.valid_beam_particles()<<
", Reset: "<<resetEvent.valid_beam_particles());
464 else if (originalEvent.valid_beam_particles() && resetEvent.valid_beam_particles()) {
465 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> originalBP = originalEvent.beam_particles();
466 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> resetBP = resetEvent.beam_particles();
467 if ( ( !originalBP.first && resetBP.first ) ||
468 ( originalBP.first && !resetBP.first ) ||
469 ( originalBP.first && resetBP.first &&
compareGenParticle(*(originalBP.first), *(resetBP.first)).isFailure() ) ) {
472 if ( ( !originalBP.second && resetBP.second ) ||
473 ( originalBP.second && !resetBP.second ) ||
474 ( originalBP.second && resetBP.second &&
compareGenParticle(*(originalBP.second), *(resetBP.second)).isFailure() ) ) {
478 if (originalEvent.particles_size() != resetEvent.particles_size() ) {
479 ATH_MSG_ERROR (
"particles_size differs! Original: "<<originalEvent.particles_size()<<
", Reset: "<<resetEvent.particles_size());
482 if (originalEvent.vertices_size() != resetEvent.vertices_size() ) {
483 ATH_MSG_ERROR (
"vertices_size differs! Original: "<<originalEvent.vertices_size()<<
", Reset: "<<resetEvent.vertices_size());
488 HepMC::GenEvent::vertex_const_iterator origVertexIter(originalEvent.vertices_begin());
489 const HepMC::GenEvent::vertex_const_iterator endOfOriginalListOfVertices(originalEvent.vertices_end());
490 HepMC::GenEvent::vertex_const_iterator resetVertexIter(resetEvent.vertices_begin());
491 const HepMC::GenEvent::vertex_const_iterator endOfResetListOfVertices(resetEvent.vertices_end());
492 while( origVertexIter!=endOfOriginalListOfVertices &&
493 resetVertexIter!=endOfResetListOfVertices) {
501 ATH_MSG_INFO(
"Completed Truth reset closure check ..... " );
503 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
ATLAS-specific HepMC functions.
Handle class for reading from StoreGate.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
SG::ReadHandleKey< McEventCollection > m_originalMcEventCollection
virtual StatusCode execute(const EventContext &ctx) const override final
StatusCode compareMomenta(const HepMC::FourVector &origMomenta, const HepMC::FourVector &resetMomenta) const
StatusCode compareGenVertex(const HepMC::GenVertex &origVertex, const HepMC::GenVertex &resetVertex) const
StatusCode sanityCheck(const HepMC::GenEvent &event) const
StatusCode compareGenParticle(const HepMC::GenParticle &origParticle, const HepMC::GenParticle &resetParticle) const
void printGenVertex(const HepMC::GenVertex &origVertex, const HepMC::GenVertex &resetVertex) const
virtual StatusCode initialize() override final
Gaudi::Property< bool > m_compareMomenta
Gaudi::Property< bool > m_postSimulation
SG::ReadHandleKey< McEventCollection > m_resetMcEventCollection
int signal_process_id(const GenEvent &e)
const GenParticle * ConstGenParticlePtr
const HepMC::GenVertex * ConstGenVertexPtr
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isDecayed(const T &p)
Identify if the particle decayed.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.