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
11
12
14#include "TrkTrack/Track.h"
18
19#include "AtlasHepMC/GenEvent.h"
25#include "GaudiKernel/IPartPropSvc.h"
26
27// Helper functors:
28#include "HepPDT/ParticleDataTable.hh"
29
30namespace {
32 class Interactions_pair {
33 public:
34 float first;
35 Amg::Vector3D second;
36 Interactions_pair(float p1, Amg::Vector3D p2)
37 : first(p1), second(std::move(p2)) {};
39 bool operator> (const Interactions_pair& other) const
40 {return first < other.first;}
42 bool operator< (const Interactions_pair& other) const
43 {return first > other.first;}
44 };
45}
46
47namespace Trk
48{
49
50 MCTrueSeedFinder::MCTrueSeedFinder(const std::string& t, const std::string& n, const IInterface* p) :
51 base_class(t,n,p),
52 m_partPropSvc( "PartPropSvc", n ),
55 {
56 declareProperty("RemoveHardScattering", m_removeHardScattering, "Do not consider hard-scattering");
57 declareProperty("RemoveInTimePileUp", m_removeInTimePileUp, "Do not consider in-time pile-up");
58 declareProperty( "PartPropSvc", m_partPropSvc, "Handle to the particle property service" );
59 }
60
61
63 = default;
64
65
67 {
68 ATH_CHECK( m_mcEventCollectionKey.initialize() );
69 return StatusCode::SUCCESS;
70 }
71
72
74 MCTrueSeedFinder::findSeed(const std::vector<const Trk::Track*>& perigeeList,
75 const xAOD::Vertex* constraint) const
76 {
77 std::vector<Amg::Vector3D> seeds = findMultiSeeds (perigeeList, constraint);
78 if (seeds.empty()) {
79 return Amg::Vector3D(0.,0.,0.);
80 }
81 return seeds[0];
82 }
83
84
86 MCTrueSeedFinder::findSeed(const std::vector<const Trk::TrackParameters*>& vectorTrk,
87 const xAOD::Vertex* constraint) const
88 {
89 std::vector<Amg::Vector3D> seeds = findMultiSeeds (vectorTrk, constraint);
90 if (seeds.empty()) {
91 return Amg::Vector3D(0.,0.,0.);
92 }
93 return seeds[0];
94 }
95
96
97 std::vector<Amg::Vector3D> MCTrueSeedFinder::findMultiSeeds(const std::vector<const Trk::TrackParameters*>& /* perigeeList */,const xAOD::Vertex * /* constraint */) const
98 {
99 std::vector<Amg::Vector3D> seeds;
100 if( retrieveInteractionsInfo (seeds).isFailure() ) {
101 seeds.clear();
102 }
103
104 return seeds;
105 }
106
107
108 std::vector<Amg::Vector3D> MCTrueSeedFinder::findMultiSeeds(const std::vector<const Trk::Track*>& /* vectorTrk */,const xAOD::Vertex * /* constraint */) const
109 {
110 std::vector<Amg::Vector3D> seeds;
111 if( retrieveInteractionsInfo (seeds).isFailure() ) {
112 seeds.clear();
113 }
114
115 return seeds;
116 }
117
118 StatusCode
119 MCTrueSeedFinder::retrieveInteractionsInfo (std::vector<Amg::Vector3D>& interactions) const
120 {
121 ATH_MSG_DEBUG("Retrieving interactions information");
122 msg(MSG::DEBUG) << "StoreGate Step: MCTrueSeedFinder retrieves -- " << m_mcEventCollectionKey.key() << endmsg;
124 if ( !mcEventCollection.isValid() ) {
125 msg(MSG::DEBUG)
126 << "Could not retrieve McEventCollection/" << m_mcEventCollectionKey.key() << " from StoreGate." << endmsg;
127 return StatusCode::FAILURE;
128 }
129
130 interactions.clear();
131 std::vector<Interactions_pair> interactionsColl;
132 McEventCollection::const_iterator itr = mcEventCollection->begin();
133 for ( ; itr != mcEventCollection->end(); ++itr ) {
134 const HepMC::GenEvent* myEvent=(*itr);
135 if(!pass( myEvent, mcEventCollection.cptr())) continue; //checked if events is acceptable
136
137
138 //get "intensity" (scalar sum ot p_T^2)
139 double sum_pt2(0.0);
140 for (const auto& part: *myEvent) {
141 if(!pass(part, mcEventCollection.cptr())) continue; //select stable charged particles
142 sum_pt2 += part->momentum().perp2();
143 }
144 ATH_MSG_DEBUG("Calculated Sum P_T^2 = " << sum_pt2);
145
146 //get position of interaction from first non-zero vertex
147 Amg::Vector3D vtxPosition;
148#ifdef HEPMC3
149 auto Vert = myEvent->vertices().begin();
150#else
151 HepMC::GenEvent::vertex_const_iterator Vert = myEvent->vertices_begin();
152#endif
153 msg(MSG::DEBUG) << "Retrieved position x: " << (*Vert)->position().x() <<
154 " y: " << (*Vert)->position().y() <<
155 " z: " << (*Vert)->position().z() << endmsg;
156 vtxPosition = Amg::Vector3D((*Vert)->position().x(),
157 (*Vert)->position().y(),
158 (*Vert)->position().z());
159
160 //now store info about position and "intensity" (here: scalar sum of p_T^2)
161 interactionsColl.emplace_back(sum_pt2, vtxPosition );
162 } // end loop over GenEvent
163
164 //now sort the container and store results to interactions
165 std::sort(interactionsColl.begin(), interactionsColl.end());
166 std::vector<Interactions_pair>::iterator itIp = interactionsColl.begin();
167 ATH_MSG_DEBUG("Sorted collection:");
168 for (; itIp < interactionsColl.end(); ++itIp) {
169 interactions.push_back(itIp->second);
170 ATH_MSG_DEBUG("(" << itIp->second.x() << ", " << itIp->second.y() << ", "
171 << itIp->second.z() << "), SumPt2 = " << itIp->first);
172 }
173
174 ATH_MSG_DEBUG("New interactions info stored successfully: " << interactions.size() << " interactions found.");
175 return StatusCode::SUCCESS;
176
177 }
178
179 bool MCTrueSeedFinder::pass( const HepMC::GenEvent* evt,
180 const McEventCollection* coll ) const {
181
182 //we select in-time pile-up interactions and hard-scattering, if valid
183
184
185 bool isEmpty = ( evt->particles_size() == 0 );
186 bool isDummy = ( ( evt->event_number() == -1 ) &&
187 ( HepMC::signal_process_id(evt) == 0 ) );
188 if( isDummy ) isEmpty = false;
189
190 if( isEmpty ) return false;
191 if( isDummy ) return false;
192
193 // We can't do the further selection without the full truth record:
194 if( ! coll ) return true;
195
198
199 if( *iter == evt ) {
200 //this is the hard-scattering event (first of the collection)
201 return ! m_removeHardScattering;
202 }
203
204 int gotzero = 1;
205 for( ; iter != end; ++iter ) {
206 if( ( ( ( *iter )->event_number() == -1 ) &&
207 ( HepMC::signal_process_id( *iter ) == 0 ) ) ) {
208 ++gotzero;
209 }
210 if( evt == *iter ) break;
211 }
212
213 if( gotzero == 1 && m_removeInTimePileUp ) return false;
214 if( gotzero == 2 ) return false; //remove2BCPileUp
215 if( gotzero == 3 ) return false; //remove800nsPileUp
216 if( gotzero == 4 ) return false; //removeCavernBkg
217
218 return true;
219 }
220
222 const McEventCollection* coll ) const {
223
224 // Check if the particle is coming from a "good" GenEvent:
225 if( ! pass( part->parent_event(), coll ) ) return false;
226
227 // Now check for stable particles
229 if( ! MC::isGenStable( part ) ) return false;
230 if( ! MC::isSimInteracting( part ) ) return false;
231 }
232
233 // finally require it to be charged
234 int pdg = part->pdg_id();
235
237 if( std::abs(pdg) < 7 || std::abs(pdg) == 21 ) return false;
238
239 const HepPDT::ParticleData* pd = m_partPropSvc->PDT()->particle( std::abs( pdg ) );
240 if( ! pd ) {
241 ATH_MSG_DEBUG( "Could not get particle data for = " << part
242 << " process id " <<HepMC::signal_process_id(part->parent_event()));
243 return false;
244 }
245 float charge = pd->charge();
246
247 return std::abs( charge ) >= 1E-5;
248 }
249
250
251}
#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 ...
ServiceHandle< IPartPropSvc > m_partPropSvc
Get particle properties.
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 &e)
Definition GenEvent.h:636
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...
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
bool isSimInteracting(const T &p)
Identify if the particle could interact with the detector during the simulation, e....
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