ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Simulation::VertexPositionFromFile Class Reference

#include <VertexPositionFromFile.h>

Inheritance diagram for Simulation::VertexPositionFromFile:
Collaboration diagram for Simulation::VertexPositionFromFile:

Public Member Functions

 VertexPositionFromFile (const std::string &t, const std::string &n, const IInterface *p)
 Constructor with parameters. More...
 
virtual ~VertexPositionFromFile ()=default
 Destructor. More...
 
StatusCode initialize () override final
 Athena algtool's Hooks. More...
 
StatusCode finalize () override final
 Athena algtool's Hooks. More...
 
CLHEP::HepLorentzVector * generate (const EventContext &ctx) const override final
 returns current shift More...
 

Private Types

typedef std::pair< int, int > RunEventPair
 using typedefs to make code more readable for (run,event) -> (x,y,z) mapping More...
 
typedef std::vector< double > XYZCoordinates
 
typedef std::map< RunEventPair, XYZCoordinatesEventCoordinatesMap
 

Private Member Functions

StatusCode readVertexPosFile ()
 read-in and cache vertex positions from file More...
 
StatusCode readRunEventNumFile ()
 read-in and cache run/event number overrides locally for vertex positioning More...
 

Private Attributes

Gaudi::Property< std::string > m_vertexPositionFile {this, "VertexPositionsFile", ""}
 set vertex position by file More...
 
EventCoordinatesMap m_vertexPositionMap {}
 vertex position for (run,event) pairs More...
 
Gaudi::Property< std::string > m_runEventNumbersFile {this, "RunAndEventNumbersFile", ""}
 run and event number overrides according to file (to be used optionally in combination with 'set vertex by file') More...
 
std::vector< int > m_vertexPositionRunNum {}
 run number override vector More...
 
std::vector< int > m_vertexPositionEventNum {}
 event number override vector More...
 
SG::ReadHandleKey< xAOD::EventInfom_eventInfoKey {this, "EventInfoKey", "EventInfo"}
 Name of the EventInfo object in StoreGate. More...
 

Detailed Description

Returns a VertexShift based on what is given in the input file.

based on: https://svnweb.cern.ch/trac/atlasoff/browser/Simulation/G4Atlas/G4AtlasUtilities/trunk/src/VertexPositioner.cxx

Author
Elmar.Ritsch -at- cern.ch

Definition at line 35 of file VertexPositionFromFile.h.

Member Typedef Documentation

◆ EventCoordinatesMap

Definition at line 56 of file VertexPositionFromFile.h.

◆ RunEventPair

typedef std::pair< int, int > Simulation::VertexPositionFromFile::RunEventPair
private

using typedefs to make code more readable for (run,event) -> (x,y,z) mapping

Definition at line 54 of file VertexPositionFromFile.h.

◆ XYZCoordinates

typedef std::vector< double > Simulation::VertexPositionFromFile::XYZCoordinates
private

Definition at line 55 of file VertexPositionFromFile.h.

Constructor & Destructor Documentation

◆ VertexPositionFromFile()

Simulation::VertexPositionFromFile::VertexPositionFromFile ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Constructor with parameters.

Constructor.

Definition at line 19 of file VertexPositionFromFile.cxx.

22  : base_class(t,n,p)
23  {
24  }

◆ ~VertexPositionFromFile()

virtual Simulation::VertexPositionFromFile::~VertexPositionFromFile ( )
virtualdefault

Destructor.

Member Function Documentation

◆ finalize()

StatusCode Simulation::VertexPositionFromFile::finalize ( )
finaloverride

Athena algtool's Hooks.

Definition at line 55 of file VertexPositionFromFile.cxx.

56  {
57  ATH_MSG_VERBOSE("Finalizing ...");
58  return StatusCode::SUCCESS;
59  }

◆ generate()

CLHEP::HepLorentzVector * Simulation::VertexPositionFromFile::generate ( const EventContext &  ctx) const
finaloverride

returns current shift

modifies (displaces) the given GenEvent

Definition at line 161 of file VertexPositionFromFile.cxx.

162  {
163  unsigned int runNumber(0), eventNumber(0);
164  // override the run/event number from file
165  if (!m_runEventNumbersFile.empty()) {
166  // This works because we iterate over the file exactly once
167  static std::atomic<size_t> runEventNumbersIndex(0);
168  ATH_MSG_DEBUG("Retrieving event info from event file, position " << runEventNumbersIndex);
169  runNumber = m_vertexPositionRunNum[runEventNumbersIndex];
170  eventNumber = m_vertexPositionEventNum[runEventNumbersIndex];
171  ++runEventNumbersIndex;
172  }
173  // use run/event numbers from EventInfo class in storegate
174  else {
175  ATH_MSG_DEBUG("Retrieving event info from SG");
177  if (eventInfo.isValid()) {
178  // read out run/event number
179  runNumber = eventInfo->runNumber();
180  eventNumber = eventInfo->eventNumber();
181  }
182  else {
183  ATH_MSG_ERROR("Could not retrieve event info from SG");
184  return nullptr;
185  }
186  }
187  ATH_MSG_DEBUG("Got run/event: " << runNumber << "/" << eventNumber);
188  // read the (x,y,z) coordinates for the current (run,event)
189  const RunEventPair curRunEvtPair(runNumber, eventNumber);
190  const XYZCoordinates &updatedVertexPosition = m_vertexPositionMap.at(curRunEvtPair);
191  ATH_MSG_DEBUG("Got vertex offset: " << updatedVertexPosition[0] << " " <<
192  updatedVertexPosition[1] << " " << updatedVertexPosition[2]);
193  // no (x,y,z) coordinates given for the current (run,event) numbers
194  if (updatedVertexPosition.size()!=3) {
195  ATH_MSG_ERROR("Vertex position requested, but no info found in map for run/event: " <<
196  runNumber << "/" << eventNumber);
197  return nullptr;
198  }
199  // store the actual vertex offset
200  CLHEP::HepLorentzVector *vertexOffset =
201  new CLHEP::HepLorentzVector( updatedVertexPosition[0], updatedVertexPosition[1],
202  updatedVertexPosition[2], 0. );
203  // and return it
204  return vertexOffset;
205  }

◆ initialize()

StatusCode Simulation::VertexPositionFromFile::initialize ( )
finaloverride

Athena algtool's Hooks.

Definition at line 27 of file VertexPositionFromFile.cxx.

28  {
29  ATH_MSG_VERBOSE("Initializing ...");
30 
31  // read-in and cache the content of the VertexPositionsFile, throw error if:
32  // * no VertexPositionsFile is given
33  // * or something goes wrong in the file read-in
34  if ( m_vertexPositionFile.empty() || readVertexPosFile().isFailure() ) {
35  ATH_MSG_ERROR("Something went wrong with setting up the vertex positioning from file '"
36  << m_vertexPositionFile << "'");
37  return StatusCode::FAILURE;
38  }
39 
40  // if a filename is given for a event number overrides
41  // --> read in this file and cache its content locally
42  if ( !m_runEventNumbersFile.empty() && readRunEventNumFile().isFailure()) {
43  ATH_MSG_ERROR("Something went wrong with setting up the run/event number overrides from file'"
44  << m_runEventNumbersFile << "'");
45  return StatusCode::FAILURE;
46  }
47 
49 
50  // everything set up properly
51  return StatusCode::SUCCESS;
52  }

◆ readRunEventNumFile()

StatusCode Simulation::VertexPositionFromFile::readRunEventNumFile ( )
private

read-in and cache run/event number overrides locally for vertex positioning

Definition at line 118 of file VertexPositionFromFile.cxx.

119  {
120  FILE *vefile = fopen( m_runEventNumbersFile.value().c_str(),"r");
121  if ( !vefile) {
122  ATH_MSG_ERROR("Could not open vertex positioning run/event number file: "<< m_runEventNumbersFile);
123  return StatusCode::FAILURE;
124  }
125  ATH_MSG_VERBOSE("Opened vertex positioning run/event number file: " << m_runEventNumbersFile);
126  //svcMgr.EvtIdModifierSvc.add_modifier(run_nbr=167776, evt_nbr=22, time_stamp=1299948350, lbk_nbr=130, nevts=1)
127  int verun(0); // run number
128  int veevent(0); // event number
129  int vetime(0); // time stamp
130  int velbn(0); // lumi block nr
131  int ven(0); // num events
132  int numReadIn(0); // number of read-ins
133  // read in file
134  while (true) {
135  // fill local variables with values given in file
136  int r = fscanf(vefile, "svcMgr.EvtIdModifierSvc.add_modifier(run_nbr=%i, evt_nbr=%i, time_stamp=%i, lbk_nbr=%i, nevts=%i)\n",
137  &verun, &veevent, &vetime, &velbn, &ven);
138 
139  // if read-in was successful
140  if (r>0) {
141  ATH_MSG_DEBUG( "Read "<<r<<" vertex positioning run/event values: "
142  <<verun<<"/"<<veevent<<" "<<vetime<<"," <<velbn<<","<<ven );
143  // store the run and event number locally
144  m_vertexPositionRunNum.push_back( verun);
145  m_vertexPositionEventNum.push_back( veevent);
146  ++numReadIn;
147  }
148  // nothing read-in
149  else {
150  ATH_MSG_VERBOSE("Got "<<r<<" from fscanf, stopping");
151  break;
152  }
153  } // loop over lines in file
154  // close file
155  fclose(vefile);
156  ATH_MSG_VERBOSE("Read " << numReadIn <<" vertex positioning run/event entries from file.");
157  return StatusCode::SUCCESS;
158  }

◆ readVertexPosFile()

StatusCode Simulation::VertexPositionFromFile::readVertexPosFile ( )
private

read-in and cache vertex positions from file

Definition at line 62 of file VertexPositionFromFile.cxx.

63  {
64  ATH_MSG_INFO("Will read in vertex positions from file.");
65  FILE *vfile = fopen( m_vertexPositionFile.value().c_str(),"r");
66  if (!vfile) {
67  ATH_MSG_ERROR("Could not open vertex position file: " << m_vertexPositionFile);
68  return StatusCode::FAILURE;
69  }
70  ATH_MSG_DEBUG("Opened vertex position file: " << m_vertexPositionFile);
71  int vrun(0); // run number
72  int vevent(0); // event number
73  double vx(0.); // vertex coordinates
74  double vy(0.); // vertex coordinates
75  double vz(0.); // vertex coordinates
76  unsigned int numReadIn(0); // number of vertex overrides read in
77  // read in file
78  while (true) {
79  // fill local variables with values given in file
80  int r = fscanf(vfile, "%i %i %lf %lf %lf\n", &vrun, &vevent, &vx, &vy, &vz);
81  // if read-in was successful
82  if (r>0) {
83  ATH_MSG_VERBOSE( "Read "<<r<<" vertex position values from file: "<<vrun
84  <<"/"<<vevent<<" "<<vx<<","<<vy<<","<<vz);
85  // get the corresponding (#run,#event) entry in the m_vertexPositionMap
86  RunEventPair curRunEvt(vrun, vevent);
87  XYZCoordinates &curCoordinates = m_vertexPositionMap[curRunEvt];
88  // check if (vrun,vevent) combination already filled
89  if ( curCoordinates.size()!=0) {
90  ATH_MSG_WARNING( "Already position information for run/event "<<vrun<<"/"<<vevent
91  << ", size=" << curCoordinates.size() );
92  }
93  else {
94  curCoordinates.resize(3);
95  }
96  // store the (x,y,z) coordinates in the vertexPositionMap:
97  curCoordinates[0] = vx;
98  curCoordinates[1] = vy;
99  curCoordinates[2] = vz;
100  // use this trick to only allocate the amount of memory
101  // actually used by curXYZ
102  //curCoordinates.swap( curCoordinates);
103  ++numReadIn;
104  }
105  // nothing read-in
106  else {
107  ATH_MSG_VERBOSE("Got "<<r<<" from fscanf, stopping");
108  break;
109  }
110  } // loop over lines in file
111  // close file
112  fclose(vfile);
113  ATH_MSG_VERBOSE("Read " << numReadIn << " vertex position entries from file.");
114  return StatusCode::SUCCESS;
115  }

Member Data Documentation

◆ m_eventInfoKey

SG::ReadHandleKey<xAOD::EventInfo> Simulation::VertexPositionFromFile::m_eventInfoKey {this, "EventInfoKey", "EventInfo"}
private

Name of the EventInfo object in StoreGate.

Definition at line 72 of file VertexPositionFromFile.h.

◆ m_runEventNumbersFile

Gaudi::Property<std::string> Simulation::VertexPositionFromFile::m_runEventNumbersFile {this, "RunAndEventNumbersFile", ""}
private

run and event number overrides according to file (to be used optionally in combination with 'set vertex by file')

Name of file containing event info overrides for pos overrides

Definition at line 69 of file VertexPositionFromFile.h.

◆ m_vertexPositionEventNum

std::vector<int> Simulation::VertexPositionFromFile::m_vertexPositionEventNum {}
private

event number override vector

Definition at line 71 of file VertexPositionFromFile.h.

◆ m_vertexPositionFile

Gaudi::Property<std::string> Simulation::VertexPositionFromFile::m_vertexPositionFile {this, "VertexPositionsFile", ""}
private

set vertex position by file

Name of file containing vertex position overrides

Definition at line 64 of file VertexPositionFromFile.h.

◆ m_vertexPositionMap

EventCoordinatesMap Simulation::VertexPositionFromFile::m_vertexPositionMap {}
private

vertex position for (run,event) pairs

Definition at line 65 of file VertexPositionFromFile.h.

◆ m_vertexPositionRunNum

std::vector<int> Simulation::VertexPositionFromFile::m_vertexPositionRunNum {}
private

run number override vector

Definition at line 70 of file VertexPositionFromFile.h.


The documentation for this class was generated from the following files:
beamspotman.r
def r
Definition: beamspotman.py:676
Simulation::VertexPositionFromFile::m_runEventNumbersFile
Gaudi::Property< std::string > m_runEventNumbersFile
run and event number overrides according to file (to be used optionally in combination with 'set vert...
Definition: VertexPositionFromFile.h:69
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Simulation::VertexPositionFromFile::XYZCoordinates
std::vector< double > XYZCoordinates
Definition: VertexPositionFromFile.h:55
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Simulation::VertexPositionFromFile::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Name of the EventInfo object in StoreGate.
Definition: VertexPositionFromFile.h:72
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Simulation::VertexPositionFromFile::m_vertexPositionMap
EventCoordinatesMap m_vertexPositionMap
vertex position for (run,event) pairs
Definition: VertexPositionFromFile.h:65
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
Simulation::VertexPositionFromFile::readVertexPosFile
StatusCode readVertexPosFile()
read-in and cache vertex positions from file
Definition: VertexPositionFromFile.cxx:62
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Simulation::VertexPositionFromFile::m_vertexPositionEventNum
std::vector< int > m_vertexPositionEventNum
event number override vector
Definition: VertexPositionFromFile.h:71
Simulation::VertexPositionFromFile::m_vertexPositionRunNum
std::vector< int > m_vertexPositionRunNum
run number override vector
Definition: VertexPositionFromFile.h:70
Simulation::VertexPositionFromFile::m_vertexPositionFile
Gaudi::Property< std::string > m_vertexPositionFile
set vertex position by file
Definition: VertexPositionFromFile.h:64
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Simulation::VertexPositionFromFile::readRunEventNumFile
StatusCode readRunEventNumFile()
read-in and cache run/event number overrides locally for vertex positioning
Definition: VertexPositionFromFile.cxx:118
Simulation::VertexPositionFromFile::RunEventPair
std::pair< int, int > RunEventPair
using typedefs to make code more readable for (run,event) -> (x,y,z) mapping
Definition: VertexPositionFromFile.h:54