ATLAS Offline Software
TrigEgammaTLAPhotonReAlgo.cxx
Go to the documentation of this file.
1  /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
11 
12 
13 class ISvcLocator;
14  // helpers functions, if needed
15 struct DescendingEt{
16 
17  bool operator()(const xAOD::Photon* l, const xAOD::Photon* r) const {
18  return l->p4().Et() > r->p4().Et();
19  }
20 
21 };
22 
24 
26  double thresholdPt;
27 
28  bool operator()(const xAOD::Photon* myphoton) const {
29  return myphoton->p4().Pt() > thresholdPt;
30  }
31 
32  };
33 
34 
35 TrigEgammaTLAPhotonReAlgo::TrigEgammaTLAPhotonReAlgo(const std::string & name, ISvcLocator* pSvcLocator)
36  : AthReentrantAlgorithm (name, pSvcLocator)
37  {
38 
39  }
40 
42 {
43 
44  // here we simply check that the class properties have been correctly initialized at the config stage
45  ATH_MSG_DEBUG( "Initializing " << name() << " ...") ;
46  ATH_MSG_DEBUG( "pT threshold for saving Photons to TLA Collection: " << m_photonPtThreshold) ;
47  ATH_MSG_DEBUG( "Maximum number of Photons to be saved: " << m_maxNPhotons );
48 
49  // check if the data handles have been initialized
50  ATH_CHECK(m_inputPhotonsKeys.initialize());
51  ATH_CHECK(m_TLAOutPhotonsKey.initialize());
52 
53 
54  if (static_cast<int>(m_maxNPhotons) == 0){ // allow m_maxNPhotons == -1 as flag to save all Photons
55  ATH_MSG_ERROR("This algorithm is initialized to save NO (0) Photons, so it shouldn't be running at all!");
56  return StatusCode::FAILURE;
57  }
58 
59 
60  return StatusCode::SUCCESS;
61 }
62 
63 StatusCode TrigEgammaTLAPhotonReAlgo::execute(const EventContext& ctx) const
64 {
65  using namespace xAOD;
66 
67  ATH_MSG_DEBUG("Executing " << name() << " ...");
68 
71 
72  // effectively make the TLA Photon Container
73 
74  ATH_MSG_DEBUG("Retrieving Photons from " << h_inputPhotons.key() );
75  ATH_MSG_DEBUG("Placing <selected> Photons in " << h_TLAPhotons.key() );
76 
77  //ATH_CHECK(h_TLAPhotons.record (std::make_unique<xAOD::PhotonContainer>(),
78  // std::make_unique<PhotonAuxContainer>()) );
79 
80 
81  const xAOD::PhotonContainer* inputPhotons = h_inputPhotons.get();
82  std::vector<const xAOD::Photon*> originalPhotons(inputPhotons->begin(), inputPhotons->end());
83 
84  // 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)
86 
87  int maxNPhotons = static_cast<int>(m_maxNPhotons);
88  int sizeOfOriginalPhotonContainer = static_cast<int>(originalPhotons.size());
89 
90  // take the largest between the number of photons requested and the size of the vector, in iterator form
91  if (m_maxNPhotons > 0) it_maxPhotonBound = maxNPhotons < sizeOfOriginalPhotonContainer ? originalPhotons.begin() + maxNPhotons : originalPhotons.end();
92  else it_maxPhotonBound = originalPhotons.end();
93 
94  // check the sort order of the input container is ok
95  // use a partial sort to save some time
96  std::partial_sort (originalPhotons.begin(), it_maxPhotonBound, originalPhotons.end(), DescendingEt());
97 
98  // get an iterator to the last element above the pT threshold (because we ordered the photons, this is the last one we want)
100  it_ptThresholdBound = std::partition(originalPhotons.begin(), it_maxPhotonBound, HasPtAboveThreshold(static_cast<float>(m_photonPtThreshold)));
101 
102  //make the output photon container
103  ATH_CHECK(h_TLAPhotons.record (std::make_unique<xAOD::PhotonContainer>(),
104  std::make_unique<PhotonAuxContainer>()) ); // in FastPhotonFex this was TrigEMClusterAuxContainer
105 
106 
107  //loop on all the photons from the beginning to the last photon we want, and put them the output photon collection
108  //also, set a link to their parent photon
109 
110 
111  for( auto it_ph=originalPhotons.begin(); it_ph!=it_ptThresholdBound; ++it_ph ) {
112  xAOD::Photon* copiedPhoton = new xAOD::Photon(*(*it_ph));
113 
114  ATH_CHECK(setOriginalObjectLink(*(*it_ph),*copiedPhoton));
115 
116  h_TLAPhotons->push_back(copiedPhoton);
117  ATH_MSG_DEBUG("Selected photon pT: " << copiedPhoton->pt());
118 
119 
120 
121  }
122 
123  return StatusCode::SUCCESS;
124 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
HasPtAboveThreshold::HasPtAboveThreshold
HasPtAboveThreshold(double thresholdPt)
Definition: TrigEgammaTLAPhotonReAlgo.cxx:25
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrigEgammaTLAPhotonReAlgo::m_TLAOutPhotonsKey
SG::WriteHandleKey< xAOD::PhotonContainer > m_TLAOutPhotonsKey
Definition: TrigEgammaTLAPhotonReAlgo.h:47
xAOD::Egamma_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle as a TLoretzVector.
Definition: Egamma_v1.cxx:98
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
DescendingEt
Definition: TrigEgammaTLAPhotonReAlgo.cxx:15
TrigEgammaTLAPhotonReAlgo::m_photonPtThreshold
Gaudi::Property< float > m_photonPtThreshold
Definition: TrigEgammaTLAPhotonReAlgo.h:54
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigEgammaTLAPhotonReAlgo::TrigEgammaTLAPhotonReAlgo
TrigEgammaTLAPhotonReAlgo(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigEgammaTLAPhotonReAlgo.cxx:35
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigEMClusterAuxContainer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TrigEgammaTLAPhotonReAlgo.h
TrigEgammaTLAPhotonReAlgo::m_maxNPhotons
Gaudi::Property< int > m_maxNPhotons
Definition: TrigEgammaTLAPhotonReAlgo.h:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrigEgammaTLAPhotonReAlgo::m_inputPhotonsKeys
SG::ReadHandleKey< xAOD::PhotonContainer > m_inputPhotonsKeys
Definition: TrigEgammaTLAPhotonReAlgo.h:40
DescendingEt::operator()
bool operator()(const xAOD::Photon *l, const xAOD::Photon *r) const
Definition: TrigEgammaTLAPhotonReAlgo.cxx:17
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
TrigEgammaTLAPhotonReAlgo::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigEgammaTLAPhotonReAlgo.cxx:63
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TrigEMClusterContainer.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
PhotonAuxContainer.h
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::setOriginalObjectLink
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...
Definition: IParticleHelpers.cxx:30
TrigEgammaTLAPhotonReAlgo::initialize
virtual StatusCode initialize() override
Definition: TrigEgammaTLAPhotonReAlgo.cxx:41
StateLessPT_NewConfig.partition
partition
Definition: StateLessPT_NewConfig.py:49
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
HasPtAboveThreshold::thresholdPt
double thresholdPt
Definition: TrigEgammaTLAPhotonReAlgo.cxx:26
HasPtAboveThreshold::operator()
bool operator()(const xAOD::Photon *myphoton) const
Definition: TrigEgammaTLAPhotonReAlgo.cxx:28
IParticleHelpers.h
HasPtAboveThreshold
Definition: TrigEgammaTLAPhotonReAlgo.cxx:23
PhotonContainer.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.