ATLAS Offline Software
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>
13 #include "AthenaKernel/CLASS_DEF.h"
14 
15 #include <iostream>
16 
17 // class to hold ROIs defined by Phi, r and z
18 class ROIPhiRZ : public std::array<float,3>
19 {
20 public:
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 
49 class ROIPhiRZContainer : public std::vector<ROIPhiRZ>
50 {
51 public:
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 
96 protected:
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 
141 CLASS_DEF( ROIPhiRZContainer , 1290867916 , 1 )
142 
143 #endif
ROIPhiRZContainer::sort
void sort()
Definition: ROIPhiRZContainer.h:79
beamspotman.r
def r
Definition: beamspotman.py:676
ROIPhiRZContainer::hasMatchingROI
static bool hasMatchingROI(const ROIPhiRZContainer &rois, float phi, double eta, double r, double z, float roi_phi_width, double roi_eta_width)
Definition: ROIPhiRZContainer.h:129
Monitored::Z
@ Z
Definition: HistogramFillerUtils.h:24
ROIPhiRZContainer
container for phi sorted ROIs defined by phi, r and z.
Definition: ROIPhiRZContainer.h:50
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
M_PI
#define M_PI
Definition: ActiveFraction.h:11
ROIPhiRZContainer::phi
static float phi(const ROIPhiRZ &roi)
Definition: ROIPhiRZContainer.h:92
ROIPhiRZContainer::hasMatchingROI
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.
Definition: ROIPhiRZContainer.h:55
athena.value
value
Definition: athena.py:124
ROIPhiRZContainer::lowerPhiBound
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;.
Definition: ROIPhiRZContainer.h:120
ROIPhiRZContainer::eta
static double eta(const ROIPhiRZ &roi)
Definition: ROIPhiRZContainer.h:84
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
GeoPrimitives.h
ROIPhiRZContainer::lowerPhiBound
const_iterator lowerPhiBound(float phi, float roi_phi_width) const
Definition: ROIPhiRZContainer.h:59
ROIPhiRZ::r
float r() const
Definition: ROIPhiRZContainer.h:35
z
#define z
ROIPhiRZContainer::addROI
void addROI(const Amg::Vector3D &global_position, float roi_phi_width)
Definition: ROIPhiRZContainer.h:63
ROIPhiRZContainer::theta
static double theta(const ROIPhiRZ &roi)
Definition: ROIPhiRZContainer.h:89
ROIPhiRZ::theta
double theta() const
Definition: ROIPhiRZContainer.h:27
ROIPhiRZ::phi
float phi() const
Definition: ROIPhiRZContainer.h:32
AnalysisUtils::Delta::R
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
Definition: AnalysisMisc.h:49
ROIPhiRZContainer::order
static bool order(const ROIPhiRZ &a, const ROIPhiRZ &b)
Helper function to order ROIs defined by phi,r,z by phi.
Definition: ROIPhiRZContainer.h:112
ROIPhiRZ::kZ
@ kZ
Definition: ROIPhiRZContainer.h:21
ROIPhiRZ::eta
double eta() const
Definition: ROIPhiRZContainer.h:22
lumiFormat.array
array
Definition: lumiFormat.py:91
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ROIPhiRZContainer::deltaEta
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.
Definition: ROIPhiRZContainer.h:101
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ROIPhiRZ::z
float z() const
Definition: ROIPhiRZContainer.h:38
a
TList * a
Definition: liststreamerinfos.cxx:10
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition: Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:64
ROIPhiRZ::ERoiParameters
ERoiParameters
Definition: ROIPhiRZContainer.h:21
TriggerTest.rois
rois
Definition: TriggerTest.py:23
ROIPhiRZContainer::sqr
static double sqr(double a)
Definition: ROIPhiRZContainer.h:97
ROIPhiRZ::kR
@ kR
Definition: ROIPhiRZContainer.h:21
CLASS_DEF.h
macros to associate a CLID to a type
ROIPhiRZ::kPhi
@ kPhi
Definition: ROIPhiRZContainer.h:21
ROIPhiRZ
Definition: ROIPhiRZContainer.h:19