ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEgammaTLAPhotonReAlgo.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
12
13
14
15class ISvcLocator;
16 // helpers functions, if needed
18
19 bool operator()(const xAOD::Photon* l, const xAOD::Photon* r) const {
20 return l->p4().Et() > r->p4().Et();
21 }
22
23};
24
26
29
30 bool operator()(const xAOD::Photon* myphoton) const {
31 return myphoton->p4().Pt() > thresholdPt;
32 }
33
34 };
35
36
37TrigEgammaTLAPhotonReAlgo::TrigEgammaTLAPhotonReAlgo(const std::string & name, ISvcLocator* pSvcLocator)
38 : AthReentrantAlgorithm (name, pSvcLocator)
39 {
40
41 }
42
44{
45
46 // here we simply check that the class properties have been correctly initialized at the config stage
47 ATH_MSG_DEBUG( "Initializing " << name() << " ...") ;
48 ATH_MSG_DEBUG( "pT threshold for saving Photons to TLA Collection: " << m_photonPtThreshold) ;
49 ATH_MSG_DEBUG( "Maximum number of Photons to be saved: " << m_maxNPhotons );
50
51 // check if the data handles have been initialized
52 ATH_CHECK(m_inputPhotonsKeys.initialize());
53 ATH_CHECK(m_TLAOutPhotonsKey.initialize());
54
55
56 if (static_cast<int>(m_maxNPhotons) == 0){ // allow m_maxNPhotons == -1 as flag to save all Photons
57 ATH_MSG_ERROR("This algorithm is initialized to save NO (0) Photons, so it shouldn't be running at all!");
58 return StatusCode::FAILURE;
59 }
60
61
62 return StatusCode::SUCCESS;
63}
64
65StatusCode TrigEgammaTLAPhotonReAlgo::execute(const EventContext& ctx) const
66{
67 using namespace xAOD;
68
69 ATH_MSG_DEBUG("Executing " << name() << " ...");
70
73
74 // effectively make the TLA Photon Container
75
76 ATH_MSG_DEBUG("Retrieving Photons from " << h_inputPhotons.key() );
77 ATH_MSG_DEBUG("Placing <selected> Photons in " << h_TLAPhotons.key() );
78
79 //ATH_CHECK(h_TLAPhotons.record (std::make_unique<xAOD::PhotonContainer>(),
80 // std::make_unique<PhotonAuxContainer>()) );
81
82
83 const xAOD::PhotonContainer* inputPhotons = h_inputPhotons.get();
84 std::vector<const xAOD::Photon*> originalPhotons(inputPhotons->begin(), inputPhotons->end());
85
86 // define the maximum number of photons we care about: either equivalent to m_maxNPhotons if smaller than size of vector, or keep all photons (in case of negative value)
87 std::vector<const xAOD::Photon*>::iterator it_maxPhotonBound;
88
89 int maxNPhotons = static_cast<int>(m_maxNPhotons);
90 int sizeOfOriginalPhotonContainer = static_cast<int>(originalPhotons.size());
91
92 // take the largest between the number of photons requested and the size of the vector, in iterator form
93 if (m_maxNPhotons > 0) it_maxPhotonBound = maxNPhotons < sizeOfOriginalPhotonContainer ? originalPhotons.begin() + maxNPhotons : originalPhotons.end();
94 else it_maxPhotonBound = originalPhotons.end();
95
96 // check the sort order of the input container is ok
97 // use a partial sort to save some time
98 std::partial_sort (originalPhotons.begin(), it_maxPhotonBound, originalPhotons.end(), DescendingEt());
99
100 // get an iterator to the last element above the pT threshold (because we ordered the photons, this is the last one we want)
101 std::vector<const xAOD::Photon*>::iterator it_ptThresholdBound;
102 it_ptThresholdBound = std::partition(originalPhotons.begin(), it_maxPhotonBound, HasPtAboveThreshold(static_cast<float>(m_photonPtThreshold)));
103
104 //make the output photon container
105 ATH_CHECK(h_TLAPhotons.record (std::make_unique<xAOD::PhotonContainer>(),
106 std::make_unique<PhotonAuxContainer>()) ); // in FastPhotonFex this was TrigEMClusterAuxContainer
107
108
109 //loop on all the photons from the beginning to the last photon we want, and put them the output photon collection
110 //also, set a link to their parent photon
111
112
113 for( auto it_ph=originalPhotons.begin(); it_ph!=it_ptThresholdBound; ++it_ph ) {
114 xAOD::Photon* copiedPhoton = new xAOD::Photon(*(*it_ph));
115
116 ATH_CHECK(setOriginalObjectLink(*(*it_ph),*copiedPhoton));
117
118 h_TLAPhotons->push_back(copiedPhoton);
119 ATH_MSG_DEBUG("Selected photon pT: " << copiedPhoton->pt());
120
121
122
123 }
124
125 return StatusCode::SUCCESS;
126}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
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.
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::WriteHandleKey< xAOD::PhotonContainer > m_TLAOutPhotonsKey
virtual StatusCode initialize() override
Gaudi::Property< float > m_photonPtThreshold
virtual StatusCode execute(const EventContext &ctx) const override
TrigEgammaTLAPhotonReAlgo(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::PhotonContainer > m_inputPhotonsKeys
Gaudi::Property< int > m_maxNPhotons
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
virtual FourMom_t p4() const override final
The full 4-momentum of the particle as a TLoretzVector.
Definition Egamma_v1.cxx:94
int r
Definition globals.cxx:22
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
DataModel_detail::iterator< DVL > partition(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of partition for DataVector/List.
void partial_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > mid, DataModel_detail::iterator< DVL > end)
Specialization of partial_sort for DataVector/List.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Photon_v1 Photon
Definition of the current "egamma version".
bool operator()(const xAOD::Photon *l, const xAOD::Photon *r) const
HasPtAboveThreshold(double thresholdPt)
bool operator()(const xAOD::Photon *myphoton) const