ATLAS Offline Software
Loading...
Searching...
No Matches
MCTrueSeedFinder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*********************************************************************
6 MCTrueSeedFinder.cxx - Description in header file
7*********************************************************************/
8
9#include <utility>
10
12#include "TrkTrack/Track.h"
16
17#include "AtlasHepMC/GenEvent.h"
23
24namespace {
26 class Interactions_pair {
27 public:
28 float first;
29 Amg::Vector3D second;
30 Interactions_pair(float p1, Amg::Vector3D p2)
31 : first(p1), second(std::move(p2)) {};
33 bool operator> (const Interactions_pair& other) const
34 {return first < other.first;}
36 bool operator< (const Interactions_pair& other) const
37 {return first > other.first;}
38 };
39}
40
41namespace Trk
42{
43
44 MCTrueSeedFinder::MCTrueSeedFinder(const std::string& t, const std::string& n, const IInterface* p) :
45 base_class(t,n,p),
48 {
49 declareProperty("RemoveHardScattering", m_removeHardScattering, "Do not consider hard-scattering");
50 declareProperty("RemoveInTimePileUp", m_removeInTimePileUp, "Do not consider in-time pile-up");
51 }
52
53
55 = default;
56
57
59 {
60 ATH_CHECK( m_mcEventCollectionKey.initialize() );
61 return StatusCode::SUCCESS;
62 }
63
64
66 MCTrueSeedFinder::findSeed(const std::vector<const Trk::Track*>& perigeeList,
67 const xAOD::Vertex* constraint) const
68 {
69 std::vector<Amg::Vector3D> seeds = findMultiSeeds (perigeeList, constraint);
70 if (seeds.empty()) {
71 return Amg::Vector3D(0.,0.,0.);
72 }
73 return seeds[0];
74 }
75
76
78 MCTrueSeedFinder::findSeed(const std::vector<const Trk::TrackParameters*>& vectorTrk,
79 const xAOD::Vertex* constraint) const
80 {
81 std::vector<Amg::Vector3D> seeds = findMultiSeeds (vectorTrk, constraint);
82 if (seeds.empty()) {
83 return Amg::Vector3D(0.,0.,0.);
84 }
85 return seeds[0];
86 }
87
88
89 std::vector<Amg::Vector3D> MCTrueSeedFinder::findMultiSeeds(const std::vector<const Trk::TrackParameters*>& /* perigeeList */,const xAOD::Vertex * /* constraint */) const
90 {
91 std::vector<Amg::Vector3D> seeds;
92 if( retrieveInteractionsInfo (seeds).isFailure() ) {
93 seeds.clear();
94 }
95
96 return seeds;
97 }
98
99
100 std::vector<Amg::Vector3D> MCTrueSeedFinder::findMultiSeeds(const std::vector<const Trk::Track*>& /* vectorTrk */,const xAOD::Vertex * /* constraint */) const
101 {
102 std::vector<Amg::Vector3D> seeds;
103 if( retrieveInteractionsInfo (seeds).isFailure() ) {
104 seeds.clear();
105 }
106
107 return seeds;
108 }
109
110 StatusCode
111 MCTrueSeedFinder::retrieveInteractionsInfo (std::vector<Amg::Vector3D>& interactions) const
112 {
113 ATH_MSG_DEBUG("Retrieving interactions information");
114 msg(MSG::DEBUG) << "StoreGate Step: MCTrueSeedFinder retrieves -- " << m_mcEventCollectionKey.key() << endmsg;
116 if ( !mcEventCollection.isValid() ) {
117 msg(MSG::DEBUG)
118 << "Could not retrieve McEventCollection/" << m_mcEventCollectionKey.key() << " from StoreGate." << endmsg;
119 return StatusCode::FAILURE;
120 }
121
122 interactions.clear();
123 std::vector<Interactions_pair> interactionsColl;
124 McEventCollection::const_iterator itr = mcEventCollection->begin();
125 for ( ; itr != mcEventCollection->end(); ++itr ) {
126 const HepMC::GenEvent* myEvent=(*itr);
127 if(!pass( myEvent, mcEventCollection.cptr())) continue; //checked if events is acceptable
128
129
130 //get "intensity" (scalar sum ot p_T^2)
131 double sum_pt2(0.0);
132 for (const auto& part: *myEvent) {
133 if(!pass(part, mcEventCollection.cptr())) continue; //select stable charged particles
134 sum_pt2 += part->momentum().perp2();
135 }
136 ATH_MSG_DEBUG("Calculated Sum P_T^2 = " << sum_pt2);
137
138 //get position of interaction from first non-zero vertex
139 Amg::Vector3D vtxPosition;
140 auto Vert = myEvent->vertices().begin();
141 msg(MSG::DEBUG) << "Retrieved position x: " << (*Vert)->position().x() <<
142 " y: " << (*Vert)->position().y() <<
143 " z: " << (*Vert)->position().z() << endmsg;
144 vtxPosition = Amg::Vector3D((*Vert)->position().x(),
145 (*Vert)->position().y(),
146 (*Vert)->position().z());
147
148 //now store info about position and "intensity" (here: scalar sum of p_T^2)
149 interactionsColl.emplace_back(sum_pt2, vtxPosition );
150 } // end loop over GenEvent
151
152 //now sort the container and store results to interactions
153 std::sort(interactionsColl.begin(), interactionsColl.end());
154 std::vector<Interactions_pair>::iterator itIp = interactionsColl.begin();
155 ATH_MSG_DEBUG("Sorted collection:");
156 for (; itIp < interactionsColl.end(); ++itIp) {
157 interactions.push_back(itIp->second);
158 ATH_MSG_DEBUG("(" << itIp->second.x() << ", " << itIp->second.y() << ", "
159 << itIp->second.z() << "), SumPt2 = " << itIp->first);
160 }
161
162 ATH_MSG_DEBUG("New interactions info stored successfully: " << interactions.size() << " interactions found.");
163 return StatusCode::SUCCESS;
164
165 }
166
168 const McEventCollection* coll ) const {
169
170 //we select in-time pile-up interactions and hard-scattering, if valid
171
172
173 bool isEmpty = ( evt->particles_size() == 0 );
174 bool isDummy = ( ( evt->event_number() == -1 ) &&
175 ( HepMC::signal_process_id(evt) == 0 ) );
176 if( isDummy ) isEmpty = false;
177
178 if( isEmpty ) return false;
179 if( isDummy ) return false;
180
181 // We can't do the further selection without the full truth record:
182 if( ! coll ) return true;
183
186
187 if( *iter == evt ) {
188 //this is the hard-scattering event (first of the collection)
189 return ! m_removeHardScattering;
190 }
191
192 int gotzero = 1;
193 for( ; iter != end; ++iter ) {
194 if( ( ( ( *iter )->event_number() == -1 ) &&
195 ( HepMC::signal_process_id( *iter ) == 0 ) ) ) {
196 ++gotzero;
197 }
198 if( evt == *iter ) break;
199 }
200
201 if( gotzero == 1 && m_removeInTimePileUp ) return false;
202 if( gotzero == 2 ) return false; //remove2BCPileUp
203 if( gotzero == 3 ) return false; //remove800nsPileUp
204 if( gotzero == 4 ) return false; //removeCavernBkg
205
206 return true;
207 }
208
210 const McEventCollection* coll ) const {
211
212 // Check if the particle is coming from a "good" GenEvent:
213 if( ! pass( part->parent_event(), coll ) ) return false;
214
215 // Now check for stable particles
217 if( ! MC::isGenStable( part ) ) return false;
218 if( ! MC::isSimInteracting( part ) ) return false;
219 }
220
221 // finally require it to be charged
222 int pdg = part->pdg_id();
223
225 if( std::abs(pdg) < 7 || std::abs(pdg) == 21 ) return false;
226
227 float charge = MC::charge(pdg);
228
229 return std::abs( charge ) >= 1E-5;
230 }
231
232
233}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
bool operator>(const DataVector< T > &a, const DataVector< T > &b)
Based on operator<.
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
ATLAS-specific HepMC functions.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
bool m_removeHardScattering
Flag to consider hard-scattering interaction.
MCTrueSeedFinder(const std::string &t, const std::string &n, const IInterface *p)
StatusCode retrieveInteractionsInfo(std::vector< Amg::Vector3D > &interactions) const
bool pass(const HepMC::GenEvent *evt, const McEventCollection *coll=0) const
Function selecting GenEvent objects.
virtual ~MCTrueSeedFinder()
virtual std::vector< Amg::Vector3D > findMultiSeeds(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds full vector of linearization points from a vector of tracks and returns it as an Amg::Vector3D ...
bool m_removeInTimePileUp
Flag to consider in-time pile-up interactions.
SG::ReadHandleKey< McEventCollection > m_mcEventCollectionKey
virtual StatusCode initialize() override
virtual Amg::Vector3D findSeed(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds a linearization point out of a vector of tracks and returns it as an Amg::Vector3D object.
Eigen::Matrix< double, 3, 1 > Vector3D
int signal_process_id(const GenEvent &evt)
Definition GenEvent.h:572
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
bool isSimInteracting(const T &p)
Identify if the particle could interact with the detector during the simulation, e....
double charge(const T &p)
bool isGenStable(const T &p)
Determine if the particle is stable at the generator (not det-sim) level,.
Ensure that the ATLAS eigen extensions are properly loaded.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Vertex_v1 Vertex
Define the latest version of the vertex class.
MsgStream & msg
Definition testRead.cxx:32