ATLAS Offline Software
Loading...
Searching...
No Matches
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.
 Loops (const Evt *evt)
 Constructor passing the event; immediately index the event that is passed.
bool isLoop (const Prt &p) const
 Is this particle in a loop?
bool isLoop (const Vtx &v) const
 Is this vertex in a loop?
const std::vector< Prt > & loop_particles () const
 Accessor: return the full list of particles in loops.
const std::vector< Vtx > & loop_vertices () const
 Accessor: return the full list of vertices in loops.
int findLoops (const Evt *evt, bool force)
 Function that does the work to identify loops Pass the event of interest.

Private Attributes

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

Detailed Description

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

Definition at line 15 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 19 of file Loops.h.

19{}

◆ 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 22 of file Loops.h.

22 {
23 findLoops(evt,true);
24 }
int findLoops(const Evt *evt, bool force)
Function that does the work to identify loops Pass the event of interest.
Definition Loops.h:48

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 48 of file Loops.h.

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

◆ 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 27 of file Loops.h.

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

◆ 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 32 of file Loops.h.

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

◆ 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 37 of file Loops.h.

37 {
38 return m_loop_particles;
39 }

◆ 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 42 of file Loops.h.

42 {
43 return m_loop_vertices;
44 }

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 151 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 154 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 157 of file Loops.h.


The documentation for this class was generated from the following file: