ATLAS Offline Software
Loading...
Searching...
No Matches
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
11namespace Trk {
12 class SpacePoint;
13 class PrepRawData;
14}
17class AtlasDetectorID;
18class PixelID;
19class SCT_ID;
20class Identifier;
21class IdentifierHash;
23class IRoiDescriptor;
27namespace FTF {//FastTrackFinder
28
30
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:
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) {};
77 virtual void operator()(const Trk::SpacePoint*) = 0;
78 int vectorSize() {
79 return m_vec.size();
80 }
81 void setLayer(const Identifier& id) {
82 m_layerId = m_layerCalculator.getLayer(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 }
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) {};
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
std::vector< size_t > vec
static Double_t sp
HWIdentifier id2
#define y
#define x
#define z
void unused(Args &&...)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
void setLayer(const Identifier &id)
std::vector< TrigSiSpacePointBase > & m_vec
BaseSpacePointFilter(std::vector< TrigSiSpacePointBase > &vec, LayerCalculator &lc)
void setErrors(const Identifier &id)
void setLayer(short layerId, const Identifier &id)
void createSpacePoint(const Trk::SpacePoint *p)
virtual void operator()(const Trk::SpacePoint *)=0
bool isBarrel(const Identifier &id)
const AtlasDetectorID * m_atlasId
LayerCalculator(const AtlasDetectorID *aId, const PixelID *pId, const SCT_ID *sId, int offs[3])
bool isPixel(const Identifier &id)
int getLayer(const Identifier &id)
virtual void operator()(const Trk::SpacePoint *p)
const IRoiDescriptor * m_roi
const std::map< Identifier, std::vector< long int > > * m_clusterMap
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)
void operator()(const SpacePointCollection *coll)
int select(const SpacePointContainer &p, const std::vector< IdentifierHash > &idVec, const std::vector< short > *h2l=nullptr)
const std::vector< short > * m_hash2layer
const SpacePointContainer * m_pIDC
void operator()(const IdentifierHash &id)
void operator()(TrigSiSpacePointBase &sp)
SpacePointShifter(double dx, double dy)
SpacePointTransform(std::array< float, 4 > &x, std::array< float, 4 > &y, std::array< float, 4 > &z)
std::array< float, 4 > & m_xtrf
std::array< float, 4 > & m_ztrf
void operator()(TrigSiSpacePointBase &sp)
SpacePointTransform(const SpacePointTransform &spt)
std::array< float, 4 > & m_ytrf
Describes the API of the Region of Ineterest geometry.
This is a "hash" representation of an Identifier.
This is an Identifier helper class for the Pixel subdetector.
Definition PixelID.h:67
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
virtual Identifier identify() const override final
virtual IdentifierHash identifyHash() const override final
int r
Definition globals.cxx:22
header for factorised IRoiDescriptor interface
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
bool containsZed(const IRoiDescriptor &roi, double z, double r)
Definition RoiUtil.cxx:94
Ensure that the ATLAS eigen extensions are properly loaded.