ATLAS Offline Software
SpacePointConversionUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRIGONLINESPACEPOINTTOOL_SPACEPOINT_CONVERSION_UTILS_H
6 #define TRIGONLINESPACEPOINTTOOL_SPACEPOINT_CONVERSION_UTILS_H
7 
8 #include <cmath>
9 #include <array>
10 
11 namespace Trk {
12  class SpacePoint;
13  class PrepRawData;
14 }
17 class AtlasDetectorID;
18 class PixelID;
19 class SCT_ID;
20 class Identifier;
21 class IdentifierHash;
23 class IRoiDescriptor;
27 namespace FTF {//FastTrackFinder
28 
30 
31  friend class BaseSpacePointFilter;
32 
33  public:
34  LayerCalculator(const AtlasDetectorID* aId, const PixelID* pId, const SCT_ID* sId, int offs[3]) :
35  m_atlasId(aId), m_pixelId(pId), m_sctId(sId) {
36  m_offsetEndcapPixels = offs[0];
37  m_offsetBarrelSCT = offs[1];
38  m_offsetEndcapSCT = offs[2];
39  }
40  bool isPixel(const Identifier& id) {
41  return m_atlasId->is_pixel(id);
42  }
43  bool isBarrel(const Identifier& id) {
44  if(m_atlasId->is_pixel(id)) {
45  return (m_pixelId->barrel_ec(id)==0);
46  }
47  if(m_atlasId->is_sct(id)) {
48  return (m_sctId->barrel_ec(id)==0);
49  }
50  return false;
51  }
52  int getLayer(const Identifier& id) {
53  int layerId=-1;
54  if(isPixel(id)) {
55  layerId = m_pixelId->layer_disk(id);
56  if(!isBarrel(id)) layerId += m_offsetEndcapPixels;
57  }
58  else {
59  layerId = m_sctId->layer_disk(id);
60  if(isBarrel(id)) layerId += m_offsetBarrelSCT;
61  else layerId += m_offsetEndcapSCT;
62  }
63  return layerId;
64  }
65  protected:
68  const SCT_ID* m_sctId;
70  };
71 
73  public:
74  BaseSpacePointFilter(std::vector<TrigSiSpacePointBase>& vec, LayerCalculator& lc) : m_vec(vec), m_layerCalculator(lc),
75  m_layerId(-1), m_dr(0.0), m_dz(0.0) {};
76  virtual ~BaseSpacePointFilter(){};
77  virtual void operator()(const Trk::SpacePoint*) = 0;
78  int vectorSize() {
79  return m_vec.size();
80  }
81  void setLayer(const Identifier& id) {
83  setErrors(id);
84  }
85 
86  void setLayer(short layerId, const Identifier& id) {
87  m_layerId = layerId;
88  setErrors(id);
89  }
90 
91  void setErrors(const Identifier& id) {
92  if(m_layerCalculator.isPixel(id)) {
93  if(m_layerCalculator.isBarrel(id)) {
94  m_dr=0.01;
95  m_dz=0.13;
96  }
97  else {
98  m_dz=0.01;
99  m_dr=0.13;
100  }
101  }
102  else {
103  if(m_layerCalculator.isBarrel(id)) {
104  m_dr=0.01;
105  m_dz=0.82;
106  }
107  else {
108  m_dz=0.01;
109  m_dr=0.82;
110  }
111  }
112  }
113 
115  m_vec.push_back(TrigSiSpacePointBase(m_layerId, p->globalPosition().perp(), p->globalPosition().phi(), p->globalPosition().z(),
116  m_dr, m_dz, p));
117  }
118  protected:
119  std::vector<TrigSiSpacePointBase>& m_vec;
122  double m_dr, m_dz;
123  };
124 
126  public:
127  RoI_Filter(std::vector<TrigSiSpacePointBase>& vec, LayerCalculator& lc, const IRoiDescriptor* roi,
128  bool filter_phi=true,
129  const std::map<Identifier, std::vector<long int> >* clusterMap=nullptr) : BaseSpacePointFilter(vec,lc),
130  m_roi(roi), m_filter_phi(filter_phi), m_clusterMap(clusterMap) { }
131  virtual void operator()(const Trk::SpacePoint* p) {
132 
133  bool unused=true;
134  // if a cluster map is specified, use it to reject spacepoints where one or more clusters has already be used on a track
135  if (m_clusterMap) {
136  const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*> clusterList = p->clusterList();
137  if (clusterList.first) {
138  Identifier id1=(clusterList.first)->identify();
139  unused = m_clusterMap->find(id1)==m_clusterMap->end();
140  }
141  if (clusterList.second) {
142  Identifier id2=(clusterList.second)->identify();
143  unused = unused && (m_clusterMap->find(id2)==m_clusterMap->end());
144  }
145 
146  }
147 
148  if(m_filter_phi) {
149  if( unused && RoiUtil::contains( *m_roi, p->globalPosition().z(), p->globalPosition().perp(), p->globalPosition().phi() ) ) createSpacePoint(p);
150  }
151  else {
152  if( unused && RoiUtil::containsZed(*m_roi, p->globalPosition().z(), p->globalPosition().perp() )) createSpacePoint(p);
153  }
154  }
155  private:
158  const std::map<Identifier, std::vector<long int> >* m_clusterMap;
159  };
160 
161  template < typename T> class SpacePointSelector {
162  public:
163  SpacePointSelector(T& t) : m_filter(t), m_hash2layer(nullptr), m_pIDC(nullptr) {};
165  void operator() (const IdentifierHash& id) {
166 
167  if (m_pIDC) {
168  auto collIt = m_pIDC->indexFindPtr(id);
169  if(collIt!=nullptr) {
170  if(m_hash2layer == nullptr) m_filter.setLayer(collIt->identify());
171  else {
172  int layerId = m_hash2layer->at((int)collIt->identifyHash());
173  if(layerId<0) return;
174  m_filter.setLayer(layerId,collIt->identify());
175  }
176  std::for_each(collIt->begin(),collIt->end(),m_filter);
177  }
178  }
179  }
180  void operator()(const SpacePointCollection* coll) {
181  if(m_hash2layer == nullptr) m_filter.setLayer(coll->identify());
182  else m_filter.setLayer(m_hash2layer->at((int)coll->identifyHash()),coll->identify());
183  std::for_each(coll->begin(),coll->end(),m_filter);
184  }
185 
186  int select(const SpacePointContainer& p, const std::vector<IdentifierHash>& idVec, const std::vector<short>* h2l = nullptr) {
187  m_hash2layer = h2l;
188  m_pIDC=&p;
189  int ret = m_filter.vectorSize();
190  std::for_each(idVec.begin(),idVec.end(),*this);
191  return m_filter.vectorSize()-ret;
192  }
193 
194  private:
196  const std::vector<short>* m_hash2layer;
198  };
199 
201  public:
202  SpacePointShifter(double dx, double dy) : m_shift_x(dx), m_shift_y(dy) {};
204  double xs = sp.x() - m_shift_x;
205  double ys = sp.y() - m_shift_y;
206  double Phi = atan2(ys,xs);
207  double r = std::sqrt(xs*xs+ys*ys);
208  sp.phi(Phi);
209  sp.r(r);
210  sp.x(xs);
211  sp.y(ys);
212  }
213  protected:
215  };
216 
218  public:
219  SpacePointTransform(std::array<float, 4>& x, std::array<float, 4>& y, std::array<float, 4>& z) :
220  m_xtrf(x), m_ytrf(y), m_ztrf(z) {};
222  m_xtrf(spt.m_xtrf), m_ytrf(spt.m_ytrf), m_ztrf(spt.m_ztrf) {};
223 
225 
226  double xs = sp.offlineSpacePoint()->globalPosition().x()-m_xtrf[0];
227  double ys = sp.offlineSpacePoint()->globalPosition().y()-m_ytrf[0];
228  double zs = sp.offlineSpacePoint()->globalPosition().z()-m_ztrf[0];
229 
230  double xr = m_xtrf[1]*xs+m_xtrf[2]*ys+m_xtrf[3]*zs;
231  double yr = m_ytrf[1]*xs+m_ytrf[2]*ys+m_ytrf[3]*zs;
232  double zr = m_ztrf[1]*xs+m_ztrf[2]*ys+m_ztrf[3]*zs;
233  double Phi = atan2(ys,xs);
234  double r = std::sqrt(xr*xr+yr*yr);
235  sp.phi(Phi);
236  sp.r(r);
237  sp.x(xr);
238  sp.y(yr);
239  sp.z(zr);
240  }
241  protected:
242  std::array<float, 4>& m_xtrf;
243  std::array<float, 4>& m_ytrf;
244  std::array<float, 4>& m_ztrf;
245  };
246 
247 }
248 
249 
250 #endif
FTF::SpacePointTransform::m_ytrf
std::array< float, 4 > & m_ytrf
Definition: SpacePointConversionUtils.h:243
FTF::LayerCalculator::isBarrel
bool isBarrel(const Identifier &id)
Definition: SpacePointConversionUtils.h:43
FTF::LayerCalculator::LayerCalculator
LayerCalculator(const AtlasDetectorID *aId, const PixelID *pId, const SCT_ID *sId, int offs[3])
Definition: SpacePointConversionUtils.h:34
FTF::RoI_Filter::m_filter_phi
bool m_filter_phi
Definition: SpacePointConversionUtils.h:157
AtlasDetectorID::is_pixel
bool is_pixel(Identifier id) const
Definition: AtlasDetectorID.h:760
TrigSiSpacePointBase::phi
void phi(const double phi)
Definition: TrigSiSpacePointBase.h:52
Trk::SpacePoint
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:35
beamspotman.r
def r
Definition: beamspotman.py:676
FTF::BaseSpacePointFilter::m_dr
double m_dr
Definition: SpacePointConversionUtils.h:122
FTF::SpacePointTransform::operator()
void operator()(TrigSiSpacePointBase &sp)
Definition: SpacePointConversionUtils.h:224
FTF::BaseSpacePointFilter::BaseSpacePointFilter
BaseSpacePointFilter(std::vector< TrigSiSpacePointBase > &vec, LayerCalculator &lc)
Definition: SpacePointConversionUtils.h:74
FTF::SpacePointSelector::m_hash2layer
const std::vector< short > * m_hash2layer
Definition: SpacePointConversionUtils.h:196
FTF::BaseSpacePointFilter::~BaseSpacePointFilter
virtual ~BaseSpacePointFilter()
Definition: SpacePointConversionUtils.h:76
FTF::BaseSpacePointFilter::setLayer
void setLayer(short layerId, const Identifier &id)
Definition: SpacePointConversionUtils.h:86
FTF::BaseSpacePointFilter::createSpacePoint
void createSpacePoint(const Trk::SpacePoint *p)
Definition: SpacePointConversionUtils.h:114
SpacePointCollection::identify
virtual Identifier identify() const override final
Definition: SpacePointCollection.cxx:36
Trk::SpacePoint::globalPosition
virtual const Amg::Vector3D & globalPosition() const override final
Interface method to get the global Position.
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:146
AtlasDetectorID::is_sct
bool is_sct(Identifier id) const
Definition: AtlasDetectorID.h:770
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
FTF::LayerCalculator::isPixel
bool isPixel(const Identifier &id)
Definition: SpacePointConversionUtils.h:40
FTF::RoI_Filter::RoI_Filter
RoI_Filter(std::vector< TrigSiSpacePointBase > &vec, LayerCalculator &lc, const IRoiDescriptor *roi, bool filter_phi=true, const std::map< Identifier, std::vector< long int > > *clusterMap=nullptr)
Definition: SpacePointConversionUtils.h:127
FTF::RoI_Filter::m_roi
const IRoiDescriptor * m_roi
Definition: SpacePointConversionUtils.h:156
RoiUtil::containsZed
bool containsZed(const IRoiDescriptor &roi, double z, double r)
Definition: RoiUtil.cxx:94
FTF::BaseSpacePointFilter::m_layerCalculator
LayerCalculator m_layerCalculator
Definition: SpacePointConversionUtils.h:120
xAOD::identify
Identifier identify(const UncalibratedMeasurement *meas)
Returns the associated identifier.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
TrigSiSpacePointBase::x
void x(const double x)
Definition: TrigSiSpacePointBase.h:54
FTF::BaseSpacePointFilter::setLayer
void setLayer(const Identifier &id)
Definition: SpacePointConversionUtils.h:81
FTF::LayerCalculator::m_atlasId
const AtlasDetectorID * m_atlasId
Definition: SpacePointConversionUtils.h:66
FTF::LayerCalculator::m_offsetEndcapPixels
int m_offsetEndcapPixels
Definition: SpacePointConversionUtils.h:69
Phi
@ Phi
Definition: RPCdef.h:8
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
python.LumiCalcHtml.lc
lc
Definition: LumiCalcHtml.py:579
TrigSiSpacePointBase::offlineSpacePoint
const Trk::SpacePoint * offlineSpacePoint() const
Definition: TrigSiSpacePointBase.h:81
SpacePointCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
Definition: SpacePointCollection.cxx:41
x
#define x
PrepRawData.h
FTF::SpacePointTransform::m_xtrf
std::array< float, 4 > & m_xtrf
Definition: SpacePointConversionUtils.h:242
FTF::SpacePointSelector::m_pIDC
const SpacePointContainer * m_pIDC
Definition: SpacePointConversionUtils.h:197
FTF::RoI_Filter::m_clusterMap
const std::map< Identifier, std::vector< long int > > * m_clusterMap
Definition: SpacePointConversionUtils.h:158
FTF::RoI_Filter
Definition: SpacePointConversionUtils.h:125
SpacePoint
Definition: Trigger/TrigAccel/TrigCudaFitter/src/SpacePoint.h:7
FTF::LayerCalculator
Definition: SpacePointConversionUtils.h:29
TrigSiSpacePointBase::z
void z(const double z)
Definition: TrigSiSpacePointBase.h:53
FTF::LayerCalculator::m_pixelId
const PixelID * m_pixelId
Definition: SpacePointConversionUtils.h:67
FTF::SpacePointShifter::m_shift_x
double m_shift_x
Definition: SpacePointConversionUtils.h:214
TrigSiSpacePointBase::r
void r(const double r)
Definition: TrigSiSpacePointBase.h:51
FTF::BaseSpacePointFilter::m_dz
double m_dz
Definition: SpacePointConversionUtils.h:122
FTF::SpacePointSelector::operator()
void operator()(const SpacePointCollection *coll)
Definition: SpacePointConversionUtils.h:180
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
id2
HWIdentifier id2
Definition: LArRodBlockPhysicsV0.cxx:562
z
#define z
FTF::SpacePointTransform::m_ztrf
std::array< float, 4 > & m_ztrf
Definition: SpacePointConversionUtils.h:244
IRoiDescriptor
Describes the API of the Region of Ineterest geometry.
Definition: IRoiDescriptor.h:23
FTF::LayerCalculator::m_offsetEndcapSCT
int m_offsetEndcapSCT
Definition: SpacePointConversionUtils.h:69
FTF::SpacePointShifter::SpacePointShifter
SpacePointShifter(double dx, double dy)
Definition: SpacePointConversionUtils.h:202
TrigSiSpacePointBase::y
void y(const double y)
Definition: TrigSiSpacePointBase.h:55
FTF::SpacePointTransform::SpacePointTransform
SpacePointTransform(std::array< float, 4 > &x, std::array< float, 4 > &y, std::array< float, 4 > &z)
Definition: SpacePointConversionUtils.h:219
FTF::SpacePointSelector::~SpacePointSelector
~SpacePointSelector()
Definition: SpacePointConversionUtils.h:164
FTF::SpacePointTransform::SpacePointTransform
SpacePointTransform(const SpacePointTransform &spt)
Definition: SpacePointConversionUtils.h:221
FTF::SpacePointShifter
Definition: SpacePointConversionUtils.h:200
FTF::BaseSpacePointFilter::m_layerId
int m_layerId
Definition: SpacePointConversionUtils.h:121
FTF::SpacePointSelector::select
int select(const SpacePointContainer &p, const std::vector< IdentifierHash > &idVec, const std::vector< short > *h2l=nullptr)
Definition: SpacePointConversionUtils.h:186
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
FTF::SpacePointSelector::m_filter
T & m_filter
Definition: SpacePointConversionUtils.h:195
RoiUtil.h
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
FTF::RoI_Filter::operator()
virtual void operator()(const Trk::SpacePoint *p)
Definition: SpacePointConversionUtils.h:131
FTF::SpacePointTransform
Definition: SpacePointConversionUtils.h:217
FTF::BaseSpacePointFilter
Definition: SpacePointConversionUtils.h:72
FTF::SpacePointShifter::m_shift_y
double m_shift_y
Definition: SpacePointConversionUtils.h:214
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:292
FTF::SpacePointShifter::operator()
void operator()(TrigSiSpacePointBase &sp)
Definition: SpacePointConversionUtils.h:203
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
FTF::BaseSpacePointFilter::operator()
virtual void operator()(const Trk::SpacePoint *)=0
unused
void unused(Args &&...)
Definition: VP1ExpertSettings.cxx:39
FTF::LayerCalculator::m_offsetBarrelSCT
int m_offsetBarrelSCT
Definition: SpacePointConversionUtils.h:69
y
#define y
FTF::LayerCalculator::getLayer
int getLayer(const Identifier &id)
Definition: SpacePointConversionUtils.h:52
SCT_ID
Definition: SCT_ID.h:68
SpacePointCollection
Definition: SpacePointCollection.h:40
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
FTF::SpacePointSelector
Definition: SpacePointConversionUtils.h:161
FTF::BaseSpacePointFilter::setErrors
void setErrors(const Identifier &id)
Definition: SpacePointConversionUtils.h:91
RoiUtil::contains
bool contains(const IRoiDescriptor &roi, double z0, double dzdr)
see whether a segment is contained within the roi in r-z
Definition: RoiUtil.cxx:42
SpacePointContainer
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePointContainer.h:29
FTF::SpacePointSelector::SpacePointSelector
SpacePointSelector(T &t)
Definition: SpacePointConversionUtils.h:163
TrigSiSpacePointBase
Definition: TrigSiSpacePointBase.h:23
FTF::SpacePointSelector::operator()
void operator()(const IdentifierHash &id)
Definition: SpacePointConversionUtils.h:165
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
FTF::BaseSpacePointFilter::vectorSize
int vectorSize()
Definition: SpacePointConversionUtils.h:78
PixelID
Definition: PixelID.h:67
FTF
header for factorised IRoiDescriptor interface
Definition: TrigInDetUtils.h:18
AtlasDetectorID
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Definition: AtlasDetectorID.h:57
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
FTF::BaseSpacePointFilter::m_vec
std::vector< TrigSiSpacePointBase > & m_vec
Definition: SpacePointConversionUtils.h:119
FTF::LayerCalculator::m_sctId
const SCT_ID * m_sctId
Definition: SpacePointConversionUtils.h:68
Identifier
Definition: IdentifierFieldParser.cxx:14