ATLAS Offline Software
ValidationBarcodeSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // framework include
7 #include "GaudiKernel/IIncidentSvc.h"
9 
10 
13  base_class(name,svc),
14  m_incidentSvc("IncidentSvc", name),
15  m_firstVertex(-HepMC::SIM_BARCODE_THRESHOLD-1),
16  m_vertexIncrement(-1),
17  m_currentVertex(-1),
18  m_firstSecondary(HepMC::SIM_BARCODE_THRESHOLD+1),
19  m_secondaryIncrement(1),
20  m_currentSecondary(1),
21  m_particleGenerationIncrement(HepMC::SIM_REGENERATION_INCREMENT),
22  m_barcodeGenerationOffset(1e8)
23 {
24  // python properties
25  declareProperty("VertexIncrement" , m_vertexIncrement);
26  declareProperty("SecondaryIncrement" , m_secondaryIncrement);
27  declareProperty("BarcodeGenerationOffset" , m_barcodeGenerationOffset);
28 }
29 
30 
32 {}
33 
34 
37 {
38  ATH_MSG_VERBOSE ("initialize() ...");
39 
40  CHECK( m_incidentSvc.retrieve() );
41 
42  // register to the incident service: BeginEvent needed for refresh of counter
43  m_incidentSvc->addListener( this, IncidentType::BeginEvent);
44 
45  ATH_MSG_VERBOSE ("initialize() successful");
46  return StatusCode::SUCCESS;
47 }
48 
49 
52 {
53  m_currentVertex += m_vertexIncrement;
54  // a naive underflog checking based on the fact that vertex
55  // barcodes should never be positive
56  if ( m_currentVertex > 0)
57  {
58  ATH_MSG_ERROR("ValidationBarcodeSvc::newVertex(...)"
59  << " will return a vertex barcode greater than 0: "
60  << m_currentVertex << ". Possibly Integer Underflow?");
61  }
62  return m_currentVertex;
63 }
64 
65 
69 {
70  m_currentSecondary += m_secondaryIncrement;
71  // a naive overflow checking based on the fact that particle
72  // barcodes should never be negative
73  if ( m_currentSecondary < 0)
74  {
75  ATH_MSG_ERROR("ValidationBarcodeSvc::newSecondaryParticle(...)"
76  << " will return a particle barcode of less than 0: "
77  << m_currentSecondary << ". Possibly Integer Overflow?");
78  }
79  int primGen = int( (parentBC-m_particleGenerationIncrement) / m_barcodeGenerationOffset);
80  int returnBC = m_currentSecondary + (primGen+1)*m_barcodeGenerationOffset;
81 
82  return returnBC;
83 }
84 
85 
88 {
89  m_currentSecondary += m_secondaryIncrement;
90  // a naive overflow checking based on the fact that particle
91  // barcodes should never be negative
92  if ( m_currentSecondary < 0)
93  {
94  ATH_MSG_ERROR("ValidationBarcodeSvc::newGeneratedParticle(...)"
95  << " will return a particle barcode of less than 0: "
96  << m_currentSecondary << ". Possibly Integer Overflow?");
97  }
98  int primGen = int( (parentBC-m_particleGenerationIncrement) / m_barcodeGenerationOffset);
99  int returnBC = m_currentSecondary + (primGen+1)*m_barcodeGenerationOffset;
100 
101  return returnBC;
102 }
103 
104 
107 {
108  m_currentVertex += m_vertexIncrement;
109  // a naive underflog checking based on the fact that vertex
110  // barcodes should never be positive
111  if ( m_currentVertex > 0)
112  {
113  ATH_MSG_ERROR("ValidationBarcodeSvc::newGeneratedVertex(...)"
114  << " will return a vertex barcode greater than 0: "
115  << m_currentVertex << ". Possibly Integer Underflow?");
116  }
117  return m_currentVertex;
118 }
119 
120 
123 {
124  return m_firstSecondary;
125 }
126 
127 
130 {
131  return m_firstVertex;
132 }
133 
134 
136 void Barcode::ValidationBarcodeSvc::handle(const Incident& inc)
137 {
138  if ( inc.type() == IncidentType::BeginEvent )
139  {
140  ATH_MSG_VERBOSE("'BeginEvent' incident caught. Resetting Vertex and Particle barcode counters.");
141  m_currentVertex = m_firstVertex - m_vertexIncrement;
142  m_currentSecondary = m_firstSecondary - m_secondaryIncrement;
143  }
144 }
145 
146 
149 {
150  ATH_MSG_VERBOSE ("finalize() ...");
151  ATH_MSG_VERBOSE ("finalize() successful");
152  return StatusCode::SUCCESS;
153 }
HepMC::SIM_BARCODE_THRESHOLD
constexpr int SIM_BARCODE_THRESHOLD
Constant defining the barcode threshold for simulated particles, eg. can be used to separate generato...
Definition: MagicNumbers.h:29
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Barcode::ValidationBarcodeSvc::m_vertexIncrement
int m_vertexIncrement
Definition: ValidationBarcodeSvc.h:78
Barcode::ValidationBarcodeSvc::secondaryVertexBcOffset
virtual int secondaryVertexBcOffset() const override
Return the secondary vertex offset.
Definition: ValidationBarcodeSvc.cxx:129
Barcode::ValidationBarcodeSvc::newSimulationVertex
virtual int newSimulationVertex() override
Generate a new unique vertex barcode, based on the parent particle barcode and the physics process co...
Definition: ValidationBarcodeSvc.cxx:51
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Barcode::ValidationBarcodeSvc::secondaryParticleBcOffset
virtual int secondaryParticleBcOffset() const override
Return the secondary particle and vertex offsets.
Definition: ValidationBarcodeSvc.cxx:122
Barcode::ValidationBarcodeSvc::ValidationBarcodeSvc
ValidationBarcodeSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
Definition: ValidationBarcodeSvc.cxx:12
Barcode::ValidationBarcodeSvc::m_secondaryIncrement
int m_secondaryIncrement
Definition: ValidationBarcodeSvc.h:83
ValidationBarcodeSvc.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Barcode::ValidationBarcodeSvc::newGeneratedVertex
virtual int newGeneratedVertex() override
Generate a new unique vertex barcode below the simulation offset.
Definition: ValidationBarcodeSvc.cxx:106
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Barcode::ValidationBarcodeSvc::m_barcodeGenerationOffset
int m_barcodeGenerationOffset
not sure why this is needed...
Definition: ValidationBarcodeSvc.h:88
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
HepMC::SIM_REGENERATION_INCREMENT
constexpr int SIM_REGENERATION_INCREMENT
Constant defining the barcode threshold for regenerated particles, i.e. particles surviving an intera...
Definition: MagicNumbers.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Barcode::ValidationBarcodeSvc::initialize
virtual StatusCode initialize() override
Athena algorithm's interface methods.
Definition: ValidationBarcodeSvc.cxx:36
MagicNumbers.h
Barcode::ValidationBarcodeSvc::newSecondaryParticle
virtual int newSecondaryParticle(int parentBC=HepMC::UNDEFINED_ID) override
Generate a new unique barcode for a secondary particle, based on the parent particle barcode.
Definition: ValidationBarcodeSvc.cxx:68
Barcode::ValidationBarcodeSvc::finalize
virtual StatusCode finalize() override
framework methods
Definition: ValidationBarcodeSvc.cxx:148
HepMC
Definition: Barcode.h:14
Barcode::ValidationBarcodeSvc::~ValidationBarcodeSvc
virtual ~ValidationBarcodeSvc()
Destructor.
Definition: ValidationBarcodeSvc.cxx:31
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
Barcode::ValidationBarcodeSvc::newGeneratedParticle
virtual int newGeneratedParticle(int parentBC=HepMC::UNDEFINED_ID) override
Generate a new unique particle barcode below the simulation offset (for particles from pre-defined de...
Definition: ValidationBarcodeSvc.cxx:87
Barcode::ValidationBarcodeSvc::handle
virtual void handle(const Incident &inc) override
Incident to reset the barcodes at the beginning of the event.
Definition: ValidationBarcodeSvc.cxx:136