ATLAS Offline Software
Loading...
Searching...
No Matches
ROIPhiRZContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ROIPHIRZCOLLECTION_H
6#define ROIPHIRZCOLLECTION_H
7
8#include <vector>
9#include <array>
10#include <algorithm>
11#include <cmath>
14
15#include <iostream>
16
17// class to hold ROIs defined by Phi, r and z
18class ROIPhiRZ : public std::array<float,3>
19{
20public:
22 inline double eta() const {
23 const double R = r();
24 const double Z = z();
25 return std::atanh( Z / std::sqrt( R*R + Z*Z ) );
26 }
27 inline double theta() const {
28 double Z = z();
29 double R = r();
30 return std::atan2(1., Z / R);
31 }
32 inline float phi() const {
33 return (*this)[kPhi];
34 }
35 inline float r() const {
36 return (*this)[kR];
37 }
38 inline float z() const {
39 return (*this)[kZ];
40 }
41
42};
43
49class ROIPhiRZContainer : public std::vector<ROIPhiRZ>
50{
51public:
52
55 inline bool hasMatchingROI( float phi, double eta, double r, double z, float roi_phi_width, double roi_eta_width) const {
56 return hasMatchingROI(*this,phi,eta,r,z,roi_phi_width,roi_eta_width);
57 }
58
59 inline const_iterator lowerPhiBound( float phi, float roi_phi_width) const {
60 return lowerPhiBound( *this, phi, roi_phi_width);
61 }
62
63 void addROI(const Amg::Vector3D &global_position, float roi_phi_width) {
64
65 float phi = global_position.phi();
66 assert (std::abs(phi)<=M_PI );
67 float z = global_position.z();
68 float r = global_position.perp();
69 if ( std::abs(phi) > M_PI - roi_phi_width) {
70 constexpr float pi_2 = 2*M_PI;
71 float sign_phi_times_2_pi = std::copysign(pi_2,phi);
72 // wrap ROIs close to -pi and pi around. Thus when searching for the lower bound ROI for phi-phi_width
73 // ROIs close to -pi and ROIs close to +pi will be found.
74 this->emplace_back( ROIPhiRZ{phi - sign_phi_times_2_pi, r, z} );
75 }
76 this->emplace_back( ROIPhiRZ{phi, r, z});
77 }
78
79 void sort() {
80 // sort output ROIs by phi
81 std::sort( this->begin(), this->end(), order );
82 }
83
84 static inline double eta(const ROIPhiRZ &roi) {
85 const double R = roi.r();
86 const double Z = roi.z();
87 return std::atanh( Z / std::sqrt( R*R + Z*Z ) );
88 }
89 static inline double theta(const ROIPhiRZ &roi) {
90 return std::atan2(1., roi.z() / roi.r());
91 }
92 static inline float phi(const ROIPhiRZ &roi) {
93 return roi.phi();
94 }
95
96protected:
97 static inline double sqr(double a) { return a * a; }
98
101 static inline double deltaEta(const ROIPhiRZ &roi, double other_r, double other_z, double other_eta) {
102 //Correct eta of ROI to take into account the z postion of the reference
103 double newR = roi.r() - other_r;
104 double newZ = roi.z() - other_z;
105 double newEta = std::atanh( newZ / std::sqrt( newR*newR + newZ*newZ ) );
106 double delta_eta = std::abs(newEta - other_eta);
107 return delta_eta;
108 }
109
112 static inline bool order(const ROIPhiRZ &a, const ROIPhiRZ &b) { return a.phi() < b.phi(); }
113
120 static inline ROIPhiRZContainer::const_iterator lowerPhiBound( const ROIPhiRZContainer &rois, float phi, float roi_phi_width) {
121 if (phi>M_PI) {
122 phi -= 2*M_PI;
123 }
124 //search first ROI which is greater than phi - row_phi-width i.e. the first ROI which could be within the vicinity of phi
125 return std::upper_bound( rois.begin(), rois.end(), phi-roi_phi_width, [](float value, const ROIPhiRZ &element) { return element.phi() >= value; } );
126 }
127
128
129 static inline bool hasMatchingROI( const ROIPhiRZContainer &rois, float phi, double eta, double r, double z, float roi_phi_width, double roi_eta_width) {
130 ROIPhiRZContainer::const_iterator start_roi_iter = lowerPhiBound( rois, phi, roi_phi_width);
131 // by construction if the iterator is valid the cluster it is pointing to has a phi larger than phi-roi_phi_width.
132 // So now just check for all clusters which are not too far away in phi whether there is one with a matching eta.
133 for (ROIPhiRZContainer::const_iterator roi_iter = start_roi_iter; roi_iter != rois.end() && roi_iter->phi() < phi + roi_phi_width; ++roi_iter) {
134 if ( deltaEta(*roi_iter, r, z , eta) < roi_eta_width) { return true; }
135 }
136 return false;
137 }
138
139};
140
141CLASS_DEF( ROIPhiRZContainer , 1290867916 , 1 )
142
143#endif
#define M_PI
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
static Double_t a
#define z
container for phi sorted ROIs defined by phi, r and z.
static double sqr(double a)
static double deltaEta(const ROIPhiRZ &roi, double other_r, double other_z, double other_eta)
Helper function to compute a z position corrected delta eta.
bool hasMatchingROI(float phi, double eta, double r, double z, float roi_phi_width, double roi_eta_width) const
Test whether there is a matching ROI for the given phi and r,z corrected eta.
void addROI(const Amg::Vector3D &global_position, float roi_phi_width)
static double theta(const ROIPhiRZ &roi)
static bool order(const ROIPhiRZ &a, const ROIPhiRZ &b)
Helper function to order ROIs defined by phi,r,z by phi.
const_iterator lowerPhiBound(float phi, float roi_phi_width) const
static bool hasMatchingROI(const ROIPhiRZContainer &rois, float phi, double eta, double r, double z, float roi_phi_width, double roi_eta_width)
static ROIPhiRZContainer::const_iterator lowerPhiBound(const ROIPhiRZContainer &rois, float phi, float roi_phi_width)
Helper function to find the lower bound of ROIs which match |phi - ROI_phi| < ROI_width;.
static float phi(const ROIPhiRZ &roi)
static double eta(const ROIPhiRZ &roi)
double eta() const
float phi() const
float r() const
float z() const
double theta() const
int r
Definition globals.cxx:22
Eigen::Matrix< double, 3, 1 > Vector3D
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.