CMS 3D CMS Logo

Stub.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 #include <iterator>
5 #include <algorithm>
6 #include <utility>
7 
8 using namespace edm;
9 using namespace std;
10 using namespace tt;
11 
12 namespace trackerDTC {
13 
14  Stub::Stub(const ParameterSet& iConfig,
15  const Setup* setup,
16  const LayerEncoding* layerEncoding,
17  SensorModule* sm,
18  const TTStubRef& ttStubRef)
19  : setup_(setup),
20  layerEncoding_(layerEncoding),
21  sm_(sm),
22  ttStubRef_(ttStubRef),
23  hybrid_(iConfig.getParameter<bool>("UseHybrid")),
24  valid_(true) {
25  regions_.reserve(setup->numOverlappingRegions());
26  // get stub local coordinates
27  const MeasurementPoint& mp = ttStubRef->clusterRef(0)->findAverageLocalCoordinatesCentered();
28 
29  // convert to uniformed local coordinates
30 
31  // column number in pitch units
32  col_ = (int)floor(pow(-1, sm->signCol()) * (mp.y() - sm->numColumns() / 2) / setup->baseCol());
33  // row number in half pitch units
34  row_ = (int)floor(pow(-1, sm->signRow()) * (mp.x() - sm->numRows() / 2) / setup->baseRow());
35  // bend number in quarter pitch units
36  bend_ = (int)floor(pow(-1, sm->signBend()) * (ttStubRef->bendBE()) / setup->baseBend());
37  // reduced row number for look up
38  rowLUT_ = (int)floor((double)row_ / pow(2., setup->widthRow() - setup->dtcWidthRowLUT()));
39  // sub row number inside reduced row number
40  rowSub_ = row_ - (rowLUT_ + .5) * pow(2, setup->widthRow() - setup->dtcWidthRowLUT());
41 
42  // convert local to global coordinates
43 
44  const double y = (col_ + .5) * setup->baseCol() * sm->pitchCol();
45  // radius of a column of strips/pixel in cm
46  d_ = sm->r() + y * sm->sinTilt();
47  // stub z in cm
48  z_ = digi(sm->z() + y * sm->cosTilt(), setup->tmttBaseZ());
49 
50  const double x0 = rowLUT_ * setup->baseRow() * setup->dtcNumMergedRows() * sm->pitchRow();
51  const double x1 = (rowLUT_ + 1) * setup->baseRow() * setup->dtcNumMergedRows() * sm->pitchRow();
52  const double x = (rowLUT_ + .5) * setup->baseRow() * setup->dtcNumMergedRows() * sm->pitchRow();
53  // stub r in cm
54  r_ = sqrt(d_ * d_ + x * x);
55 
56  const double phi0 = sm->phi() + atan2(x0, d_);
57  const double phi1 = sm->phi() + atan2(x1, d_);
58  const double c = (phi0 + phi1) / 2.;
59  const double m = (phi1 - phi0) / setup->dtcNumMergedRows();
60 
61  // intercept of linearized stub phi in rad
62  c_ = digi(c, setup->tmttBasePhi());
63  // slope of linearized stub phi in rad / strip
64  m_ = digi(m, setup->dtcBaseM());
65 
66  if (hybrid_) {
67  if (abs(z_ / r_) > setup->hybridMaxCot())
68  // did not pass eta cut
69  valid_ = false;
70  } else {
71  // extrapolated z at radius T assuming z0=0
72  const double zT = setup->chosenRofZ() * z_ / r_;
73  // extrapolated z0 window at radius T
74  const double dZT = setup->beamWindowZ() * abs(1. - setup->chosenRofZ() / r_);
75  double zTMin = zT - dZT;
76  double zTMax = zT + dZT;
77  if (zTMin >= setup->maxZT() || zTMax < -setup->maxZT())
78  // did not pass "eta" cut
79  valid_ = false;
80  else {
81  zTMin = max(zTMin, -setup->maxZT());
82  zTMax = min(zTMax, setup->maxZT());
83  }
84  // range of stub cot(theta)
85  cot_ = {zTMin / setup->chosenRofZ(), zTMax / setup->chosenRofZ()};
86  }
87 
88  // stub r w.r.t. chosenRofPhi in cm
89  static const double chosenRofPhi = hybrid_ ? setup->hybridChosenRofPhi() : setup->chosenRofPhi();
90  r_ = digi(r_ - chosenRofPhi, setup->tmttBaseR());
91 
92  // radial (cylindrical) component of sensor separation
93  const double dr = sm->sep() / (sm->cosTilt() - sm->sinTilt() * z_ / d_);
94  // converts bend into inv2R in 1/cm
95  const double inv2ROverBend = sm->pitchRow() / dr / d_;
96  // inv2R in 1/cm
97  const double inv2R = -bend_ * setup->baseBend() * inv2ROverBend;
98  // inv2R uncertainty in 1/cm
99  const double dInv2R = setup->bendCut() * inv2ROverBend;
100  const double minPt = hybrid_ ? setup->hybridMinPtStub() : setup->minPt();
101  const double maxInv2R = setup->invPtToDphi() / minPt - setup->dtcBaseInv2R() / 2.;
102  double inv2RMin = digi(inv2R - dInv2R, setup->dtcBaseInv2R());
103  double inv2RMax = digi(inv2R + dInv2R, setup->dtcBaseInv2R());
104  if (inv2RMin > maxInv2R || inv2RMax < -maxInv2R) {
105  // did not pass pt cut
106  valid_ = false;
107  } else {
108  inv2RMin = max(inv2RMin, -maxInv2R);
109  inv2RMax = min(inv2RMax, maxInv2R);
110  }
111  // range of stub inv2R in 1/cm
112  inv2R_ = {inv2RMin, inv2RMax};
113 
114  // stub phi w.r.t. detector region centre in rad
115  phi_ = c_ + rowSub_ * m_;
116 
117  // range of stub extrapolated phi to radius chosenRofPhi in rad
118  phiT_.first = phi_ - r_ * inv2R_.first;
119  phiT_.second = phi_ - r_ * inv2R_.second;
120  if (phiT_.first > phiT_.second)
121  swap(phiT_.first, phiT_.second);
122 
123  if (phiT_.first < 0.)
124  regions_.push_back(0);
125  if (phiT_.second >= 0.)
126  regions_.push_back(1);
127 
128  // apply data format specific manipulations
129  if (!hybrid_)
130  return;
131 
132  // stub r w.r.t. an offset in cm
133  r_ -= sm->offsetR() - chosenRofPhi;
134  // stub z w.r.t. an offset in cm
135  z_ -= sm->offsetZ();
136  if (sm->type() == SensorModule::Disk2S) {
137  // encoded r
138  r_ = sm->encodedR() + (sm->side() ? -col_ : (col_ + sm->numColumns() / 2));
139  r_ = (r_ + 0.5) * setup->hybridBaseR(sm->type());
140  }
141 
142  // encode bend
143  const vector<double>& encodingBend = setup->encodingBend(sm->windowSize(), sm->psModule());
144  const auto pos = find(encodingBend.begin(), encodingBend.end(), abs(ttStubRef->bendBE()));
145  const int uBend = distance(encodingBend.begin(), pos);
146  bend_ = pow(-1, signbit(bend_)) * uBend;
147  }
148 
149  // returns bit accurate representation of Stub
151 
152  // returns true if stub belongs to region
153  bool Stub::inRegion(int region) const { return find(regions_.begin(), regions_.end(), region) != regions_.end(); }
154 
155  // truncates double precision to f/w integer equivalent
156  double Stub::digi(double value, double precision) const { return (floor(value / precision) + .5) * precision; }
157 
158  // returns 64 bit stub in hybrid data format
160  const SensorModule::Type type = sm_->type();
161  // layer encoding
162  const int decodedLayerId = layerEncoding_->decode(sm_);
163  // stub phi w.r.t. processing region border in rad
164  double phi = phi_ - (region - .5) * setup_->baseRegion() + setup_->hybridRangePhi() / 2.;
165  if (phi >= setup_->hybridRangePhi())
166  phi = setup_->hybridRangePhi() - setup_->hybridBasePhi(type) / 2.;
167  // convert stub variables into bit vectors
168  const TTBV hwR(r_, setup_->hybridBaseR(type), setup_->hybridWidthR(type), true);
169  const TTBV hwPhi(phi, setup_->hybridBasePhi(type), setup_->hybridWidthPhi(type), true);
170  const TTBV hwZ(z_, setup_->hybridBaseZ(type), setup_->hybridWidthZ(type), true);
171  const TTBV hwAlpha(row_, setup_->hybridBaseAlpha(type), setup_->hybridWidthAlpha(type), true);
172  const TTBV hwBend(bend_, setup_->hybridWidthBend(type), true);
173  const TTBV hwLayer(decodedLayerId, setup_->hybridWidthLayerId());
174  const TTBV hwGap(0, setup_->hybridNumUnusedBits(type));
175  const TTBV hwValid(1, 1);
176  // assemble final bitset
177  return Frame(hwGap.str() + hwR.str() + hwZ.str() + hwPhi.str() + hwAlpha.str() + hwBend.str() + hwLayer.str() +
178  hwValid.str());
179  }
180 
182  int layerM = sm_->layerId();
183  // convert unique layer id [1-6,11-15] into reduced layer id [0-6]
184  // a fiducial track may not cross more then 7 detector layers, for stubs from a given track the reduced layer id is actually unique
185  int layer(-1);
186  if (layerM == 1)
187  layer = 0;
188  else if (layerM == 2)
189  layer = 1;
190  else if (layerM == 6 || layerM == 11)
191  layer = 2;
192  else if (layerM == 5 || layerM == 12)
193  layer = 3;
194  else if (layerM == 4 || layerM == 13)
195  layer = 4;
196  else if (layerM == 14)
197  layer = 5;
198  else if (layerM == 3 || layerM == 15)
199  layer = 6;
200  // assign stub to phi sectors within a processing region, to be generalized
201  TTBV sectorsPhi(0, setup_->numOverlappingRegions() * setup_->numSectorsPhi());
202  if (phiT_.first < 0.) {
203  if (phiT_.first < -setup_->baseSector())
204  sectorsPhi.set(0);
205  else
206  sectorsPhi.set(1);
207  if (phiT_.second < 0. && phiT_.second >= -setup_->baseSector())
208  sectorsPhi.set(1);
209  }
210  if (phiT_.second >= 0.) {
211  if (phiT_.second < setup_->baseSector())
212  sectorsPhi.set(2);
213  else
214  sectorsPhi.set(3);
215  if (phiT_.first >= 0. && phiT_.first < setup_->baseSector())
216  sectorsPhi.set(2);
217  }
218  // assign stub to eta sectors within a processing region
219  pair<int, int> sectorEta({0, setup_->numSectorsEta() - 1});
220  for (int bin = 0; bin < setup_->numSectorsEta(); bin++)
221  if (asinh(cot_.first) < setup_->boundarieEta(bin + 1)) {
222  sectorEta.first = bin;
223  break;
224  }
225  for (int bin = sectorEta.first; bin < setup_->numSectorsEta(); bin++)
226  if (asinh(cot_.second) < setup_->boundarieEta(bin + 1)) {
227  sectorEta.second = bin;
228  break;
229  }
230  // stub phi w.r.t. processing region centre in rad
231  const double phi = phi_ - (region - .5) * setup_->baseRegion();
232  // convert stub variables into bit vectors
233  const TTBV hwValid(1, 1);
234  const TTBV hwGap(0, setup_->tmttNumUnusedBits());
235  const TTBV hwLayer(layer, setup_->tmttWidthLayer());
236  const TTBV hwSectorEtaMin(sectorEta.first, setup_->tmttWidthSectorEta());
237  const TTBV hwSectorEtaMax(sectorEta.second, setup_->tmttWidthSectorEta());
238  const TTBV hwR(r_, setup_->tmttBaseR(), setup_->tmttWidthR(), true);
239  const TTBV hwPhi(phi, setup_->tmttBasePhi(), setup_->tmttWidthPhi(), true);
240  const TTBV hwZ(z_, setup_->tmttBaseZ(), setup_->tmttWidthZ(), true);
241  const TTBV hwInv2RMin(inv2R_.first, setup_->tmttBaseInv2R(), setup_->tmttWidthInv2R(), true);
242  const TTBV hwInv2RMax(inv2R_.second, setup_->tmttBaseInv2R(), setup_->tmttWidthInv2R(), true);
243  TTBV hwSectorPhis(0, setup_->numSectorsPhi());
244  for (int sectorPhi = 0; sectorPhi < setup_->numSectorsPhi(); sectorPhi++)
245  hwSectorPhis[sectorPhi] = sectorsPhi[region * setup_->numSectorsPhi() + sectorPhi];
246  // assemble final bitset
247  return Frame(hwGap.str() + hwValid.str() + hwR.str() + hwPhi.str() + hwZ.str() + hwLayer.str() +
248  hwSectorPhis.str() + hwSectorEtaMin.str() + hwSectorEtaMax.str() + hwInv2RMin.str() +
249  hwInv2RMax.str());
250  }
251 
252 } // namespace trackerDTC
double offsetR() const
Definition: SensorModule.h:65
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
int numRows() const
Definition: SensorModule.h:41
double hybridRangePhi() const
Definition: Setup.h:300
int tmttWidthSectorEta() const
Definition: Setup.h:225
double r_
Definition: Stub.h:65
int tmttWidthZ() const
Definition: Setup.h:221
int numSectorsPhi() const
Definition: Setup.h:409
int hybridWidthLayerId() const
Definition: Setup.h:280
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
tt::Frame formatHybrid(int region) const
Definition: Stub.cc:159
Type type() const
Definition: SensorModule.h:19
int rowSub_
Definition: Stub.h:63
int tmttWidthInv2R() const
Definition: Setup.h:227
Class to process and provide run-time constants used by Track Trigger emulators.
Definition: Setup.h:44
double tmttBasePhi() const
Definition: Setup.h:233
double boundarieEta(int eta) const
Definition: Setup.h:417
double hybridBaseAlpha(SensorModule::Type type) const
Definition: Setup.h:288
bool psModule() const
Definition: SensorModule.h:29
constexpr int pow(int x)
Definition: conifer.h:24
minPt
Definition: PV_cfg.py:223
tt::SensorModule * sm_
Definition: Stub.h:47
T x() const
Definition: PV2DBase.h:43
bool hybrid_
Definition: Stub.h:51
bool inRegion(int region) const
Definition: Stub.cc:153
int hybridWidthZ(SensorModule::Type type) const
Definition: Setup.h:272
static const uint16_t valid_
Definition: Constants.h:17
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< int > regions_
Definition: Stub.h:83
const tt::Setup * setup_
Definition: Stub.h:43
double phi_
Definition: Stub.h:67
double c_
Definition: Stub.h:73
double m_
Definition: Stub.h:71
int hybridWidthPhi(SensorModule::Type type) const
Definition: Setup.h:274
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
double hybridBaseR(SensorModule::Type type) const
Definition: Setup.h:282
T y() const
Definition: PV2DBase.h:44
double d_
Definition: Stub.h:75
int numSectorsEta() const
Definition: Setup.h:411
Definition: TTTypes.h:54
bool valid_
Definition: Stub.h:53
std::string str() const
Definition: TTBV.h:253
const LayerEncoding * layerEncoding_
Definition: Stub.h:45
double baseSector() const
Definition: Setup.h:420
T sqrt(T t)
Definition: SSEVec.h:19
int tmttNumUnusedBits() const
Definition: Setup.h:239
double offsetZ() const
Definition: SensorModule.h:67
double cosTilt() const
Definition: SensorModule.h:61
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool signBend() const
Definition: SensorModule.h:37
int tmttWidthR() const
Definition: Setup.h:217
int hybridNumUnusedBits(SensorModule::Type type) const
Definition: Setup.h:290
double r() const
Definition: SensorModule.h:45
int hybridWidthAlpha(SensorModule::Type type) const
Definition: Setup.h:276
Definition: value.py:1
bool side() const
Definition: SensorModule.h:25
double pitchRow() const
Definition: SensorModule.h:53
int rowLUT_
Definition: Stub.h:61
std::pair< double, double > phiT_
Definition: Stub.h:81
int numColumns() const
Definition: SensorModule.h:39
double phi() const
Definition: SensorModule.h:47
double sep() const
Definition: SensorModule.h:51
double pitchCol() const
Definition: SensorModule.h:55
double z() const
Definition: SensorModule.h:49
tt::Frame formatTMTT(int region) const
Definition: Stub.cc:181
double tmttBaseR() const
Definition: Setup.h:229
double tmttBaseZ() const
Definition: Setup.h:231
TTStubRef ttStubRef() const
Definition: Stub.h:24
tt::Frame frame(int region) const
Definition: Stub.cc:150
int hybridWidthBend(SensorModule::Type type) const
Definition: Setup.h:278
Class to encode layer ids used between DTC and TFP in Hybrid.
Definition: LayerEncoding.h:19
Definition: DTC.h:12
int windowSize() const
Definition: SensorModule.h:69
int tmttWidthLayer() const
Definition: Setup.h:223
HLT enums.
double z_
Definition: Stub.h:69
double digi(double value, double precision) const
Definition: Stub.cc:156
double hybridBasePhi(SensorModule::Type type) const
Definition: Setup.h:284
std::pair< double, double > cot_
Definition: Stub.h:79
double hybridBaseZ(SensorModule::Type type) const
Definition: Setup.h:286
int encodedR() const
Definition: SensorModule.h:63
float x
int numOverlappingRegions() const
Definition: Setup.h:347
int tmttWidthPhi() const
Definition: Setup.h:219
double sinTilt() const
Definition: SensorModule.h:59
int decode(tt::SensorModule *sm) const
int layerId() const
Definition: SensorModule.h:43
double baseRegion() const
Definition: Setup.h:184
bool signCol() const
Definition: SensorModule.h:35
double tmttBaseInv2R() const
Definition: Setup.h:235
int hybridWidthR(SensorModule::Type type) const
Definition: Setup.h:270
std::pair< double, double > inv2R_
Definition: Stub.h:77
bool signRow() const
Definition: SensorModule.h:33