6#include <GaudiKernel/StatusCode.h>
25 constexpr float PI_F = std::numbers::pi_v<float>;
30 ISvcLocator* pSvcLocator):
48 return StatusCode::FAILURE;
52 return StatusCode::FAILURE;
55 ATH_MSG_FATAL(
"Number of entries in minPt, phiWidth must match number of entries in OutputROIContainerName.");
56 return StatusCode::FAILURE;
60 for (
unsigned int idx=0; idx<
m_minPtEm.size(); ++idx) {
78 for (
unsigned int output_i=0; output_i<
m_outputIndex.size(); ++output_i) {
88 return StatusCode::SUCCESS;
101 return StatusCode::SUCCESS;
108 return StatusCode::SUCCESS;
111 std::vector< const xAOD::CaloClusterContainer *> inputClusterContainerArr;
113 std::size_t total_cluster_size = 0;
117 inputClusterContainerArr.push_back(input_container.
cptr());
118 total_cluster_size += input_container->size();
125 unsigned int all_clusters{};
126 unsigned int selected_clusters{};
128 std::vector<unsigned int > n_rois;
131 std::vector<uint8_t > max_output;
132 rois.reserve( total_cluster_size);
133 max_output.resize(total_cluster_size);
146 addROI(*cluster, *caloMgr, rois, max_output, n_rois);
153 std::vector< SG::WriteHandle<ROIPhiRZContainer> > output_rois;
156 unsigned int the_size = n_rois[output_rois.size()];
158 ATH_CHECK( output_rois.back().record( std::make_unique<ROIPhiRZContainer>() ) );
159 output_rois.back()->reserve( the_size);
164 std::vector<unsigned int> roi_order;
165 roi_order.reserve( rois.size() );
166 for (
unsigned int idx=0; idx< rois.size(); ++idx) { roi_order.push_back( idx ); }
167 std::sort(roi_order.begin(),roi_order.end(),[&rois](
unsigned int a,
unsigned int b) { return rois[a][0] < rois[b][0]; });
169 for (
unsigned int roi_i : roi_order) {
171 if (output_i>=max_output[roi_i])
break;
172 output_rois[output_i]->push_back( rois[ roi_i ] );
180 for (
unsigned int roi_unordered_i=0; roi_unordered_i < rois.size(); ++roi_unordered_i) {
182 if (output_i>=max_output[roi_unordered_i])
break;
183 if (std::abs(rois[ roi_unordered_i ][0])<PI_F or (rois[ roi_unordered_i ][0] == PI_F)) {
184 output_rois[output_i]->push_back( rois[ roi_unordered_i ] );
192 unsigned int max_size;
195 }
while (rois.size()>max_size && !
m_maxNROIs.compare_exchange_weak(max_size, rois.size()));
199 return StatusCode::SUCCESS;
208 double eta = cluster.
eta();
210 double tantheta = tan(
theta);
211 double phi = cluster.
phi();
217 double r = surfRefPoint.perp();
218 double z = tantheta == 0 ? 0. :
r / tantheta;
226 double z = surfRefPoint.z();
227 double r =
z * tantheta;
238 std::vector<uint_fast8_t> &max_output,
239 std::vector<unsigned int> &n_rois)
const {
241 double energy = cluster.
e();
245 static const SG::AuxElement::ConstAccessor<float> acc(
"EMFraction");
247 if (acc.isAvailable(cluster)) {
248 emFrac = acc(cluster);
251 ATH_MSG_ERROR(
"EM energy requested, but No EM fraction momement stored");
257 std::unique_ptr<const Trk::Surface> surface(
getCaloSurface(cluster, caloDDMgr) );
265 Amg::Vector3D global_position( surface->localToGlobal( localParams) );
266 double et = energy * std::sin(global_position.theta());
268 unsigned int roi_idx=output_rois.size();
271 unsigned int n_duplicates = output_rois.size()-roi_idx-1;
272 if (n_duplicates>0) {
276 unsigned int output_idx=0;
279 n_rois[output_idx] += n_duplicates+1;
283 if (max_output.size() < output_rois.size()) {
284 max_output.resize (output_rois.size());
286 for (; roi_idx < output_rois.size(); ++roi_idx) {
287 max_output[roi_idx]=output_idx;
292 ATH_MSG_DEBUG(
"Skip selected cluster " << energy <<
" * " << std::sin(global_position.theta()) <<
" = " << energy * std::sin(global_position.theta())<<
" >= " <<
m_sortedMinPtEm[0] );
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
An algorithm that can be simultaneously executed in multiple threads.
This class provides the client interface for accessing the detector description information common to...
static Trk::LocalParameters getClusterLocalParameters(const xAOD::CaloCluster &cluster, const Trk::Surface &surf)
StatusCode execute(const EventContext &ctx) const override
std::atomic_uint m_duplicateROI
std::vector< unsigned int > m_outputSorted
SG::WriteHandleKeyArray< ROIPhiRZContainer > m_outputClusterContainerName
Name of the ROI output collection.
std::vector< unsigned int > m_outputIndex
const Trk::Surface * getCaloSurface(const xAOD::CaloCluster &cluster, const CaloDetDescrManager &caloDDMgr) const
Gaudi::Property< bool > m_EMEnergyOnly
std::atomic_uint m_maxNROIs
Gaudi::Property< std::vector< float > > m_minPtEm
StatusCode initialize() override
StatusCode finalize() override
SG::ReadHandleKeyArray< xAOD::CaloClusterContainer > m_inputClusterContainerNames
Names of the cluster intput collections.
CaloClusterROIPhiRZContainerMaker(const std::string &name, ISvcLocator *pSvcLocator)
std::atomic_uint m_selectedClusters
ToolHandle< ICaloSurfaceBuilder > m_calosurf
Tool to build calorimeter layer surfaces.
std::atomic_uint m_allClusters
std::vector< float > m_sortedMinPtEm
Gaudi::Property< std::vector< float > > m_phiWidth
std::vector< unsigned int > m_outputUnsorted
~CaloClusterROIPhiRZContainerMaker()
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Name of the CaloDetDescrManager condition object.
void addROI(const xAOD::CaloCluster &cluster, const CaloDetDescrManager &caloDDMgr, ROIPhiRZContainer &output_rois, std::vector< uint_fast8_t > &max_output, std::vector< unsigned int > &n_rois) const
ToolHandle< IegammaCaloClusterSelector > m_egammaCaloClusterSelector
Tool to filter the calo clusters.
container for phi sorted ROIs defined by phi, r and z.
void addROI(const Amg::Vector3D &global_position, float roi_phi_width)
const_pointer_type cptr()
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Abstract Base Class for tracking surfaces.
virtual const Amg::Vector3D & globalReferencePoint() const
Returns a global reference point on the surface, for PlaneSurface, StraightLineSurface,...
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
@ ENG_FRAC_EM
Energy fraction in EM calorimeters.
Eigen::Matrix< double, 3, 1 > Vector3D
std::pair< double, ParamDefs > DefinedParameter
Typedef to of a std::pair<double, ParamDefs> to identify a passed-through double as a specific type o...
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
bool isBarrel(const xAOD::Egamma *eg)
return true if the cluster is in the barrel
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Extra patterns decribing particle interation process.