CMS 3D CMS Logo

Stub.cc
Go to the documentation of this file.
2 
6 
7 #include <cmath>
8 
9 using namespace std;
10 using namespace trklet;
11 
12 Stub::Stub(Settings const& settings) : settings_(settings) {}
13 
14 Stub::Stub(L1TStub& stub, Settings const& settings, double phiminsec, double phimaxsec) : settings_(settings) {
15  double r = stub.r();
16  double z = stub.z();
17  double sbend = stub.bend();
18 
19  l1tstub_ = &stub;
20 
21  int bendbits = 4;
22  if (stub.isPSmodule())
23  bendbits = 3;
24 
25  int ibend = bendencode(sbend, stub.isPSmodule());
26 
27  bend_.set(ibend, bendbits, true, __LINE__, __FILE__);
28 
29  int layer = stub.layer() + 1;
30 
31  // hold the real values from L1Stub
32  double stubphi = stub.phi();
33 
34  if (layer < 999) {
35  disk_.set(0, 4, false, __LINE__, __FILE__);
36 
37  assert(layer > 0 && layer <= N_LAYER);
38  double rmin = settings_.rmean(layer - 1) - settings_.drmax();
39  double rmax = settings_.rmean(layer - 1) + settings_.drmax();
40 
41  if (r < rmin || r > rmax) {
42  edm::LogProblem("Tracklet") << "Error r, rmin, rmeas, rmax :" << r << " " << rmin << " " << 0.5 * (rmin + rmax)
43  << " " << rmax;
44  }
45 
46  int irbits = settings_.nrbitsstub(layer - 1);
47 
48  int ir = lround((1 << irbits) * ((r - settings_.rmean(layer - 1)) / (rmax - rmin)));
49 
50  double zmin = -settings_.zlength();
51  double zmax = settings_.zlength();
52 
53  if (z < zmin || z > zmax) {
54  edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax;
55  }
56 
57  int izbits = settings_.nzbitsstub(layer - 1);
58 
59  int iz = lround((1 << izbits) * z / (zmax - zmin));
60 
61  if (z < zmin || z > zmax) {
62  edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax;
63  }
64 
65  assert(phimaxsec - phiminsec > 0.0);
66 
67  if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) {
68  stubphi += 2 * M_PI;
69  }
70  assert((phimaxsec - phiminsec) > 0.0);
71 
72  int iphibits = settings_.nphibitsstub(layer - 1);
73 
74  double deltaphi = reco::reduceRange(stubphi - phiminsec);
75 
76  int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec);
77 
78  layer_.set(layer - 1, 3, true, __LINE__, __FILE__);
79  r_.set(ir, irbits, false, __LINE__, __FILE__);
80  z_.set(iz, izbits, false, __LINE__, __FILE__);
81  phi_.set(iphi, iphibits, true, __LINE__, __FILE__);
82 
83  phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__);
84 
85  } else {
86  // Here we handle the hits on disks.
87 
88  int disk = stub.module();
89  assert(disk > 0 && disk <= N_DISK);
90  int sign = 1;
91  if (z < 0.0)
92  sign = -1;
93 
94  double zmin = sign * (settings_.zmean(disk - 1) - sign * settings_.dzmax());
95  double zmax = sign * (settings_.zmean(disk - 1) + sign * settings_.dzmax());
96 
97  if ((z > zmax) || (z < zmin)) {
98  edm::LogProblem("Tracklet") << "Error disk z, zmax, zmin: " << z << " " << zmax << " " << zmin;
99  }
100 
101  int iz =
102  (1 << settings.nzbitsstub(disk + N_DISK)) * ((z - sign * settings_.zmean(disk - 1)) / std::abs(zmax - zmin));
103 
104  assert(phimaxsec - phiminsec > 0.0);
105  if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) {
106  stubphi += 2 * M_PI;
107  }
108 
109  assert(phimaxsec - phiminsec > 0.0);
110  if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) {
111  stubphi += 2 * M_PI;
112  }
113 
114  int iphibits = settings_.nphibitsstub(disk + 5);
115 
116  double deltaphi = reco::reduceRange(stubphi - phiminsec);
117 
118  int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec);
119 
120  double rmin = 0;
121  double rmax = settings_.rmaxdisk();
122 
123  if (r < rmin || r > rmax) {
124  edm::LogProblem("Tracklet") << "Error disk r, rmin, rmax :" << r << " " << rmin << " " << rmax;
125  }
126 
127  int ir = (1 << settings_.nrbitsstub(disk + 5)) * (r - rmin) / (rmax - rmin);
128 
129  int irSS = -1;
130  if (!stub.isPSmodule()) {
131  for (unsigned int i = 0; i < N_DSS_MOD * 2; ++i) {
132  if (disk <= 2) {
133  if (std::abs(r - settings_.rDSSinner(i)) < 0.2) {
134  irSS = i;
135  break;
136  }
137  } else {
138  if (std::abs(r - settings_.rDSSouter(i)) < 0.2) {
139  irSS = i;
140  break;
141  }
142  }
143  }
144  if (irSS < 0) {
145  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " didn't find rDSS value! r = " << r
146  << " Check that correct geometry is used!";
147  }
148  }
149  if (irSS < 0) {
150  //PS modules
151  r_.set(ir, settings_.nrbitsstub(disk + N_DISK), true, __LINE__, __FILE__);
152  } else {
153  //SS modules
154  r_.set(irSS, 4, true, __LINE__, __FILE__); // in case of SS modules, store index, not r itself
155  }
156 
157  z_.set(iz, settings.nzbitsstub(disk + 5), false, __LINE__, __FILE__);
158  phi_.set(iphi, iphibits, true, __LINE__, __FILE__);
159  phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__);
160 
161  disk_.set(sign * disk, 4, false, __LINE__, __FILE__);
162 
163  double alphanorm = stub.alphanorm();
164  assert(std::abs(alphanorm) < 1.0);
165  int ialphanew = alphanorm * (1 << (settings.nbitsalpha() - 1));
166  assert(ialphanew < (1 << (settings.nbitsalpha() - 1)));
167  assert(ialphanew >= -(1 << (settings.nbitsalpha() - 1)));
168  alphanew_.set(ialphanew, settings.nbitsalpha(), false, __LINE__, __FILE__);
169  }
170 }
171 
172 FPGAWord Stub::iphivmFineBins(int VMbits, int finebits) const {
173  unsigned int finephi = (phicorr_.value() >> (phicorr_.nbits() - VMbits - finebits)) & ((1 << finebits) - 1);
174  return FPGAWord(finephi, finebits, true, __LINE__, __FILE__);
175 }
176 
177 unsigned int Stub::phiregionaddress() const {
179  return (iphi << 7) + stubindex_.value();
180 }
181 
184  FPGAWord phiregion(iphi, 3, true, __LINE__, __FILE__);
185  return phiregion.str() + stubindex_.str();
186 }
187 
188 void Stub::setAllStubIndex(int nstub) {
189  if (nstub >= (1 << 7)) {
190  if (settings_.debugTracklet())
191  edm::LogPrint("Tracklet") << "Warning too large stubindex!";
192  nstub = (1 << 7) - 1;
193  }
194 
195  stubindex_.set(nstub, 7);
196 }
197 
198 void Stub::setPhiCorr(int phiCorr) {
199  int iphicorr = phi_.value() - phiCorr;
200 
201  if (iphicorr < 0)
202  iphicorr = 0;
203  if (iphicorr >= (1 << phi_.nbits()))
204  iphicorr = (1 << phi_.nbits()) - 1;
205 
206  phicorr_.set(iphicorr, phi_.nbits(), true, __LINE__, __FILE__);
207 }
208 
209 double Stub::rapprox() const {
210  if (disk_.value() == 0) {
211  int lr = 1 << (8 - settings_.nrbitsstub(layer_.value()));
212  return r_.value() * settings_.kr() * lr + settings_.rmean(layer_.value());
213  }
214  if (!l1tstub_->isPSmodule()) {
215  if (abs(disk_.value()) <= 2)
216  return settings_.rDSSinner(r_.value());
217  else
218  return settings_.rDSSouter(r_.value());
219  }
220  return r_.value() * settings_.kr();
221 }
222 
223 double Stub::zapprox() const {
224  if (disk_.value() == 0) {
225  int lz = 1;
226  if (layer_.value() >= 3) {
227  lz = 16;
228  }
229  return z_.value() * settings_.kz() * lz;
230  }
231  int sign = 1;
232  if (disk_.value() < 0)
233  sign = -1;
234  if (sign < 0) {
235  //Should understand why this is needed to get agreement with integer calculations
236  return (z_.value() + 1) * settings_.kz() + sign * settings_.zmean(abs(disk_.value()) - 1);
237  } else {
238  return z_.value() * settings_.kz() + sign * settings_.zmean(abs(disk_.value()) - 1);
239  }
240 }
241 
242 double Stub::phiapprox(double phimin, double) const {
243  int lphi = 1;
244  if (layer_.value() >= 3) {
245  lphi = 8;
246  }
247  return reco::reduceRange(phimin + phi_.value() * settings_.kphi() / lphi);
248 }
249 
250 unsigned int Stub::layerdisk() const {
251  if (layer_.value() == -1)
252  return 5 + abs(disk_.value());
253  return layer_.value();
254 }
trklet::Stub::phi_
FPGAWord phi_
Definition: Stub.h:78
trklet::Stub::Stub
Stub(Settings const &settings)
Definition: Stub.cc:12
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
trklet::Stub::phiregionaddressstr
std::string phiregionaddressstr() const
Definition: Stub.cc:182
trklet::Stub::alphanew_
FPGAWord alphanew_
Definition: Stub.h:79
trklet::FPGAWord::str
std::string str() const
Definition: FPGAWord.cc:54
trklet::L1TStub::layer
unsigned int layer() const
Definition: L1TStub.h:44
trklet::Settings::dzmax
double dzmax() const
Definition: Settings.h:116
deltaPhi.h
phimin
float phimin
Definition: ReggeGribovPartonMCHadronizer.h:107
trklet::Stub::r_
FPGAWord r_
Definition: Stub.h:76
trklet::Stub::layer_
FPGAWord layer_
Definition: Stub.h:74
trklet::bendencode
int bendencode(double bend, bool isPS)
Definition: Util.h:39
trklet::Settings
Definition: Settings.h:31
trklet::L1TStub::bend
double bend() const
Definition: L1TStub.h:60
trklet::L1TStub
Definition: L1TStub.h:12
trklet::L1TStub::z
double z() const
Definition: L1TStub.h:56
trklet::Settings::nbitsallstubs
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:93
cms::cuda::assert
assert(be >=bs)
trklet::FPGAWord::set
void set(int value, int nbits, bool positive=true, int line=-1, const char *file=nullptr)
Definition: FPGAWord.cc:14
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
trklet::Settings::rmean
double rmean(unsigned int iLayer) const
Definition: Settings.h:143
trklet::N_DISK
constexpr int N_DISK
Definition: Settings.h:20
trklet::Stub::phiapprox
double phiapprox(double phimin, double) const
Definition: Stub.cc:242
trklet::FPGAWord::nbits
int nbits() const
Definition: FPGAWord.h:25
trklet::Stub::bend_
FPGAWord bend_
Definition: Stub.h:81
trklet::Settings::rDSSinner
double rDSSinner(unsigned int iBin) const
Definition: Settings.h:150
trklet::Stub::phicorr_
FPGAWord phicorr_
Definition: Stub.h:83
SiStripMonitorCluster_cfi.zmin
zmin
Definition: SiStripMonitorCluster_cfi.py:200
trklet::Stub::r
const FPGAWord & r() const
Definition: Stub.h:49
trklet::Settings::nrbitsstub
unsigned int nrbitsstub(unsigned int layerdisk) const
Definition: Settings.h:71
trklet::Stub::disk_
FPGAWord disk_
Definition: Stub.h:75
trklet::Settings::rDSSouter
double rDSSouter(unsigned int iBin) const
Definition: Settings.h:153
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
trklet::Stub::z_
FPGAWord z_
Definition: Stub.h:77
trklet::Stub::disk
const FPGAWord & disk() const
Definition: Stub.h:57
trklet::Stub::iphivmFineBins
FPGAWord iphivmFineBins(int VMbits, int finebits) const
Definition: Stub.cc:172
trklet::Stub::z
const FPGAWord & z() const
Definition: Stub.h:50
SiStripMonitorCluster_cfi.zmax
zmax
Definition: SiStripMonitorCluster_cfi.py:201
trklet::L1TStub::isPSmodule
unsigned int isPSmodule() const
Definition: L1TStub.h:93
edm::LogProblem
Log< level::Error, true > LogProblem
Definition: MessageLogger.h:131
trklet::N_LAYER
constexpr int N_LAYER
Definition: Settings.h:19
trklet::Settings::zmean
double zmean(unsigned int iDisk) const
Definition: Settings.h:146
trklet::L1TStub::module
unsigned int module() const
Definition: L1TStub.h:52
trklet::Stub::layerdisk
unsigned int layerdisk() const
Definition: Stub.cc:250
trklet::FPGAWord
Definition: FPGAWord.h:9
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trklet::Settings::kr
double kr() const
Definition: Settings.h:271
trklet::Settings::drmax
double drmax() const
Definition: Settings.h:115
trklet::Settings::rmaxdisk
double rmaxdisk() const
Definition: Settings.h:112
trklet::N_DSS_MOD
constexpr unsigned int N_DSS_MOD
Definition: Settings.h:24
trklet::Settings::nzbitsstub
unsigned int nzbitsstub(unsigned int layerdisk) const
Definition: Settings.h:69
trklet::Stub::rapprox
double rapprox() const
Definition: Stub.cc:209
trklet::L1TStub::alphanorm
double alphanorm() const
Definition: L1TStub.cc:91
trklet::Settings::nphibitsstub
unsigned int nphibitsstub(unsigned int layerdisk) const
Definition: Settings.h:70
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
trklet
Definition: AllProjectionsMemory.h:9
trklet::Stub::setAllStubIndex
void setAllStubIndex(int nstub)
Definition: Stub.cc:188
trklet::FPGAWord::value
int value() const
Definition: FPGAWord.h:24
trklet::Settings::nbitsalpha
int nbitsalpha() const
Definition: Settings.h:194
trklet::Settings::kphi
double kphi() const
Definition: Settings.h:267
trklet::Stub::phiregionaddress
unsigned int phiregionaddress() const
Definition: Stub.cc:177
std
Definition: JetResolutionObject.h:76
trklet::Stub::setPhiCorr
void setPhiCorr(int phiCorr)
Definition: Stub.cc:198
Exception
Definition: hltDiff.cc:245
trklet::Settings::kz
double kz() const
Definition: Settings.h:270
trklet::Settings::debugTracklet
bool debugTracklet() const
Definition: Settings.h:161
Exception.h
trklet::L1TStub::r
double r() const
Definition: L1TStub.h:57
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trklet::Stub::layer
const FPGAWord & layer() const
Definition: Stub.h:56
trklet::Stub::settings_
Settings const & settings_
Definition: Stub.h:88
edm::Log
Definition: MessageLogger.h:70
Stub.h
trklet::Stub::stubindex_
FPGAWord stubindex_
Definition: Stub.h:85
trklet::Stub::zapprox
double zapprox() const
Definition: Stub.cc:223
trklet::L1TStub::phi
double phi() const
Definition: L1TStub.h:62
trklet::Stub::l1tstub_
L1TStub * l1tstub_
Definition: Stub.h:87
reco::reduceRange
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
trklet::Settings::zlength
double zlength() const
Definition: Settings.h:111