ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
MC::Loops< Evt, Prt, Vtx > Class Template Reference

#include <Loops.h>

Collaboration diagram for MC::Loops< Evt, Prt, Vtx >:

Public Member Functions

 Loops ()
 Default constructor. More...
 
 Loops (const Evt *evt)
 Constructor passing the event; immediately index the event that is passed. More...
 
bool isLoop (const Prt &p) const
 Is this particle in a loop? More...
 
bool isLoop (const Vtx &v) const
 Is this vertex in a loop? More...
 
const std::vector< Prt > & loop_particles () const
 Accessor: return the full list of particles in loops. More...
 
const std::vector< Vtx > & loop_vertices () const
 Accessor: return the full list of vertices in loops. More...
 
int findLoops (const Evt *evt, bool force)
 Function that does the work to identify loops Pass the event of interest. More...
 

Private Attributes

const Evt * m_evt = nullptr
 Local pointer to the event passed in the constructor or most recent call to findLoops. More...
 
std::vector< Prt > m_loop_particles
 List of all particles in m_evt that are in loops. More...
 
std::vector< Vtx > m_loop_vertices
 List of all vertices in m_evt that are in loops. More...
 

Detailed Description

template<class Evt, class Prt, class Vtx>
class MC::Loops< Evt, Prt, Vtx >

Definition at line 14 of file Loops.h.

Constructor & Destructor Documentation

◆ Loops() [1/2]

template<class Evt , class Prt , class Vtx >
MC::Loops< Evt, Prt, Vtx >::Loops ( )
inline

Default constructor.

Definition at line 18 of file Loops.h.

18 {}

◆ Loops() [2/2]

template<class Evt , class Prt , class Vtx >
MC::Loops< Evt, Prt, Vtx >::Loops ( const Evt *  evt)
inline

Constructor passing the event; immediately index the event that is passed.

Definition at line 21 of file Loops.h.

21  {
22  findLoops(evt,true);
23  }

Member Function Documentation

◆ findLoops()

template<class Evt , class Prt , class Vtx >
int MC::Loops< Evt, Prt, Vtx >::findLoops ( const Evt *  evt,
bool  force 
)
inline

Function that does the work to identify loops Pass the event of interest.

'force' allows the event to be re-searched even if it was previously.

Definition at line 47 of file Loops.h.

47  {
48  // If the event is empty, return -1 (an error code, basically)
49  if (!evt) return -1;
50  // If we have already indexed the event and are not forced to do it again, return
51  if (evt == m_evt && !force) return 0;
52 
53  // Update the local event pointer. This is now the most recent event that has been indexed.
54  m_evt = evt;
55  // Clear the lists of particles and vertices. These will now refer to this event.
56  m_loop_particles.clear();
57  m_loop_vertices.clear();
58 
59  // Create a map, keeping track of whether particles are in loops.
60  // 0 for "unknown", 1 for "in a loop", -1 for "not in a loop"
61  std::map<Prt, int> incycle;
62 
63  // Easiest case to deal with: if a particle has no production or end vertex, it is not in a loop
64  for (const auto & p: *m_evt){
65  if (!p->end_vertex()||!p->production_vertex()){
66  incycle[p] = -1;
67  } else {
68  incycle[p] = 0;
69  }
70  }
71 
72  // Now begin interating through particles to try to find loops
73  size_t minincycle = m_evt->particles_size();
74  for (;;) {
75  // Number of particles still unknown in the current iteration
76  size_t unknown = 0;
77  for (const auto & p: *m_evt) {
78 
79  // If the particle was already identified as in/not in a loop, skip it
80  if (incycle[p] != 0) continue;
81  // Otherwise it is unknown on this iteration
82  unknown++;
83 
84  // Start from the end vertex of the particle
85  auto ev = p->end_vertex();
86  if (ev) {
87  // If the end vertex of a particle exclusively has particles not in loops
88  // then this particle cannot be in a loop either
89  bool goodo = true;
90  for (auto& po: *ev) goodo = goodo && (incycle[po] == -1);
91  if (goodo) incycle[p] = -1;
92  }
93 
94  // Now start from the production vertex of the particle
95  auto pv = p->production_vertex();
96  if (pv) {
97  // If the production vertex of a particle exclusively has particles not
98  // in loops, then this particle cannot be in a loop either
99  bool goodi = true;
100 #ifdef HEPMC3
101  for (auto& pi: ev->particles_in()) goodi = goodi && (incycle[pi] == -1);
102 #else
103  for (auto ip = ev->particles_in_const_begin();
104  ip != ev->particles_in_const_end();
105  ++ip)
106  {
107  goodi = goodi && (incycle[*ip] == -1);
108  }
109 #endif
110  if (goodi) incycle[p] = -1;
111  }
112  }
113  // If the number of unknown particles has not changed, we are done iterating
114  if (minincycle == unknown) break;
115  // If the number of unknown particles has changed, update at iterate again
116  minincycle = std::min(minincycle, unknown);
117  } // Outer loop - iterate until all particles have been dealt with
118 
119  // Any remaining particles that have not been identified are a part of a loop
120  // Add them to our list of looping particles
121  for (const auto & p: *m_evt){
122  if (incycle[p] == 0) incycle[p] = 1;
123  if (incycle[p] == 1) m_loop_particles.push_back(p);
124  }
125 
126  // Now loop over all vertices.
127 #ifdef HEPMC3
128  for (auto & v: m_evt->vertices()) {
129 #else
130  for (auto iv = m_evt->vertices_begin(); iv != m_evt->vertices_end(); ++iv) {
131  auto v = *iv;
132 #endif
133  bool push = false;
134  // First check incoming particles.
135  // If any incoming are in loops, consider this vertex to be in a loop.
136 #ifdef HEPMC3
137  for ( auto& pin: v->particles_in()){
138  if (incycle[pin] == 1) {
139 #else
140  for ( auto ipin = v->particles_in_const_begin();
141  ipin != v->particles_in_const_end();
142  ++ipin){
143  if (incycle[*ipin] == 1) {
144 #endif
145  push = true;
146  break;
147  }
148  } // End of loop over incoming particles
149  // In case we have not yet identified the vertex as being in a loop
150  // then check the outgoing particles from the vertex.
151  // If any outgoing are in loops, consider this vertex to be in a loop.
152  if(!push) {
153  for ( const auto& pou: *v) {
154  if (incycle[pou] == 1) {
155  push = true;
156  break;
157  }
158  }
159  }
160  // Update the records if this vertex is in a loop.
161  if (push) m_loop_vertices.push_back(v);
162  } // End of loop over vertices
163 
164  // All finished. Return success.
165  return 0;
166  } // End of the findLoops function

◆ isLoop() [1/2]

template<class Evt , class Prt , class Vtx >
bool MC::Loops< Evt, Prt, Vtx >::isLoop ( const Prt &  p) const
inline

Is this particle in a loop?

Definition at line 26 of file Loops.h.

26  {
27  return std::find(m_loop_particles.begin(), m_loop_particles.end(), p) != m_loop_particles.end();
28  }

◆ isLoop() [2/2]

template<class Evt , class Prt , class Vtx >
bool MC::Loops< Evt, Prt, Vtx >::isLoop ( const Vtx &  v) const
inline

Is this vertex in a loop?

Definition at line 31 of file Loops.h.

31  {
32  return std::find(m_loop_vertices.begin(), m_loop_vertices.end(), v) != m_loop_vertices.end();
33  }

◆ loop_particles()

template<class Evt , class Prt , class Vtx >
const std::vector<Prt>& MC::Loops< Evt, Prt, Vtx >::loop_particles ( ) const
inline

Accessor: return the full list of particles in loops.

Definition at line 36 of file Loops.h.

36  {
37  return m_loop_particles;
38  }

◆ loop_vertices()

template<class Evt , class Prt , class Vtx >
const std::vector<Vtx>& MC::Loops< Evt, Prt, Vtx >::loop_vertices ( ) const
inline

Accessor: return the full list of vertices in loops.

Definition at line 41 of file Loops.h.

41  {
42  return m_loop_vertices;
43  }

Member Data Documentation

◆ m_evt

template<class Evt , class Prt , class Vtx >
const Evt* MC::Loops< Evt, Prt, Vtx >::m_evt = nullptr
private

Local pointer to the event passed in the constructor or most recent call to findLoops.

Definition at line 171 of file Loops.h.

◆ m_loop_particles

template<class Evt , class Prt , class Vtx >
std::vector<Prt> MC::Loops< Evt, Prt, Vtx >::m_loop_particles
private

List of all particles in m_evt that are in loops.

Definition at line 174 of file Loops.h.

◆ m_loop_vertices

template<class Evt , class Prt , class Vtx >
std::vector<Vtx> MC::Loops< Evt, Prt, Vtx >::m_loop_vertices
private

List of all vertices in m_evt that are in loops.

Definition at line 177 of file Loops.h.


The documentation for this class was generated from the following file:
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:138
calibdata.force
bool force
Definition: calibdata.py:18
MC::Loops::m_loop_vertices
std::vector< Vtx > m_loop_vertices
List of all vertices in m_evt that are in loops.
Definition: Loops.h:177
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
pi
#define pi
Definition: TileMuonFitter.cxx:65
MC::Loops::m_loop_particles
std::vector< Prt > m_loop_particles
List of all particles in m_evt that are in loops.
Definition: Loops.h:174
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ev
int ev
Definition: globals.cxx:25
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
MC::Loops::m_evt
const Evt * m_evt
Local pointer to the event passed in the constructor or most recent call to findLoops.
Definition: Loops.h:171
Muon::nsw::unknown
@ unknown
Definition: NSWTriggerElink.h:36
python.PyAthena.v
v
Definition: PyAthena.py:154
python.changerun.pv
pv
Definition: changerun.py:79
MC::Loops::findLoops
int findLoops(const Evt *evt, bool force)
Function that does the work to identify loops Pass the event of interest.
Definition: Loops.h:47