ATLAS Offline Software
Loading...
Searching...
No Matches
LArClusterCollisionTimeAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <algorithm>
9
10//__________________________________________________________________________
12 {
13 ATH_MSG_DEBUG ("LArClusterCollisionTimeAlg initialize()");
14 ATH_CHECK( m_clusterContainerName.initialize() );
15 ATH_CHECK( m_outputName.initialize() );
16 return StatusCode::SUCCESS;
17
18 }
19
20//__________________________________________________________________________
22 {
23
24 ATH_MSG_INFO( m_nCollEvt << "/" << m_nEvt << " Events found to be collision events with at least one cluster in each EM endcap." );
25 ATH_MSG_DEBUG ("LArClusterCollisionTimeAlg finalize()");
26 return StatusCode::SUCCESS;
27 }
28
30
32
33 //Sort clusters by Energy
34 std::sort(clusters.begin(),clusters.end(),[](const xAOD::CaloCluster* o1, const xAOD::CaloCluster* o2) {return o1->e() > o2->e();});
35
36 result.nClusters=std::min(m_maxClusters.value(),clusters.size());
37
38 if (result.nClusters>0) {
39 // Tell clang to optimize assuming that FP operations may trap.
41
42 for (size_t i=0;i<result.nClusters;++i) {
43 const xAOD::CaloCluster* clu=clusters[i];
44 result.time+=clu->time();
45 result.energy+=clu->e();
46 }
47
48 result.time/=(float)(result.nClusters);
49 result.energy/=(float)(result.nClusters);
50 }
51
52 return result;
53}
54
55//__________________________________________________________________________
56StatusCode LArClusterCollisionTimeAlg::execute(const EventContext& ctx) const {
57 ATH_MSG_DEBUG ("LArClusterCollisionTimeAlg execute()");
58
59 m_nEvt++;
60
61 // Get the cluster container
63 if( !cluster_container.isValid()) { // record empty object
64 ATH_MSG_WARNING ("Could not get ClusterContainer with key " << m_clusterContainerName);
65 // Construct the output object
67 ATH_CHECK( larTime.record (std::make_unique<LArCollisionTime>()) );
68 return StatusCode::SUCCESS;
69 }
70
71 std::vector<const xAOD::CaloCluster*> clustersEMECA,clustersEMECC;
72
73 const unsigned barrelPattern=CaloSampling::barrelPattern();
74
75 for(const xAOD::CaloCluster* pCluster : *cluster_container) {
76 if ((pCluster->samplingPattern() & barrelPattern) == 0 ) { //Take only clusters that have only endcap samplings, ignore barrel
77 if (pCluster->eta()>0.)
78 clustersEMECA.push_back(pCluster);
79 else
80 clustersEMECC.push_back(pCluster);
81 }
82 } //End loop over clusters
83
84 const perSide_t sideA=analyseClustersPerSide(clustersEMECA);
85 const perSide_t sideC=analyseClustersPerSide(clustersEMECC);
86
87 auto tmplarTime = std::make_unique<LArCollisionTime>(sideA.nClusters,sideC.nClusters,sideA.energy,sideC.energy,sideA.time,sideC.time);
88 // Construct the output object
90 if (! larTime.put (std::move (tmplarTime)) ) {
91 ATH_MSG_WARNING( "Could not record the LArCollisionTime object with key "<<m_outputName );
92 }
93
94 ATH_MSG_DEBUG("Number/Time/Energy, Side A: " << sideA.nClusters << "/" << sideA.time << "/" << sideA.energy);
95 ATH_MSG_DEBUG("Number/Time/Energy, Side C: " << sideC.nClusters << "/" << sideC.time << "/" << sideC.energy);
96
97 if ( sideA.nClusters>0 && sideC.nClusters>0 && std::fabs(sideA.time-sideC.time)<m_timeCut) {
98 setFilterPassed(true,ctx);
99 m_nCollEvt++;
100 }
101 else {
102 setFilterPassed(false,ctx);
103 }
104
105
106 return StatusCode::SUCCESS;
107}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
virtual void setFilterPassed(bool state, const EventContext &ctx) const
static constexpr unsigned int barrelPattern()
Get the bit-pattern for barrel samplings.
StatusCode execute(const EventContext &ctx) const override final
standard Athena-Algorithm method
perSide_t analyseClustersPerSide(std::vector< const xAOD::CaloCluster * > &clusters) const
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerName
SG::WriteHandleKey< LArCollisionTime > m_outputName
StatusCode initialize() override final
standard Athena-Algorithm method
Gaudi::Property< size_t > m_maxClusters
StatusCode finalize() override final
standard Athena-Algorithm method
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
const_pointer_type put(std::unique_ptr< T > data, bool returnExisting=false) const
Record an object to the store.
flt_t time() const
Access cluster time.
virtual double e() const
The total energy of the particle.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Tell the compiler to optimize assuming that FP may trap.
#define CXXUTILS_TRAPPING_FP
Definition trapping_fp.h:24