CMS 3D CMS Logo

HitPatternHelper.cc
Go to the documentation of this file.
1 //
2 // Created by J.Li on 1/23/21.
3 //
4 
9 
10 #include <vector>
11 #include <algorithm>
12 #include <cmath>
13 
14 namespace hph {
15 
17  const tt::Setup& setupTT,
18  const trackerTFP::DataFormats& dataFormats,
19  const trackerTFP::LayerEncoding& layerEncoding)
20  : iConfig_(iConfig),
21  oldKFPSet_(iConfig.getParameter<edm::ParameterSet>("oldKFPSet")),
22  setupTT_(setupTT),
23  dataFormats_(dataFormats),
24  dfcot_(dataFormats_.format(trackerTFP::Variable::cot, trackerTFP::Process::kfin)),
25  dfzT_(dataFormats_.format(trackerTFP::Variable::zT, trackerTFP::Process::kfin)),
26  layerEncoding_(layerEncoding),
27  hphDebug_(iConfig.getParameter<bool>("hphDebug")),
28  useNewKF_(iConfig.getParameter<bool>("useNewKF")),
29  chosenRofZNewKF_(setupTT_.chosenRofZ()),
30  etaRegionsNewKF_(setupTT_.boundarieEta()),
31  layermap_(),
32  nEtaRegions_(tmtt::KFbase::nEta_ / 2),
33  nKalmanLayers_(tmtt::KFbase::nKFlayer_) {
34  if (useNewKF_) {
37  } else {
38  chosenRofZ_ = oldKFPSet_.getParameter<double>("ChosenRofZ");
39  etaRegions_ = oldKFPSet_.getParameter<std::vector<double>>("EtaRegions");
40  }
41  static constexpr auto layerIds = {1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15}; //layer ID 11~15 correspond to D1~D5
42  // Converting tmtt::KFbase::layerMap_ to a format that is acceptatble by HitPatternHelper
43  for (int i = 0; i < nEtaRegions_; i++) {
44  for (int j : layerIds) {
45  int layer;
46  if (j < 7) {
48  } else {
50  }
51  if (layer < nKalmanLayers_) {
52  layermap_[i][layer].push_back(j);
53  }
54  }
55  }
56  }
57 
58  HitPatternHelper::HitPatternHelper(const Setup* setup, int hitpattern, double cot, double z0)
59  : setup_(setup),
60  hphDebug_(setup_->hphDebug()),
61  useNewKF_(setup_->useNewKF()),
62  etaRegions_(setup_->etaRegions()),
63  layermap_(setup_->layermap()),
64  nKalmanLayers_(setup_->nKalmanLayers()),
65  etaBin_(setup_->etaRegion(z0, cot, true)),
66  cotBin_(setup_->digiCot(cot, etaBin_)),
67  zTBin_(setup_->digiZT(z0, cot, etaBin_)),
68  layerEncoding_(setup->layerEncoding(etaBin_, zTBin_, cotBin_)),
69  layerEncodingMap_(setup->layerEncodingMap(etaBin_, zTBin_, cotBin_)),
70  numExpLayer_(layerEncoding_.size()),
71  hitpattern_(hitpattern),
72  etaSector_(setup_->etaRegion(z0, cot, useNewKF_)),
73  numMissingLayer_(0),
74  numMissingPS_(0),
75  numMissing2S_(0),
76  numPS_(0),
77  num2S_(0),
78  numMissingInterior1_(0),
79  numMissingInterior2_(0),
80  binary_(11, 0), //there are 11 unique layer IDs, as defined in variable "layerIds"
81  bonusFeatures_() {
82  int kf_eta_reg = etaSector_;
83  if (kf_eta_reg < ((int)etaRegions_.size() - 1) / 2) {
84  kf_eta_reg = ((int)etaRegions_.size() - 1) / 2 - 1 - kf_eta_reg;
85  } else {
86  kf_eta_reg = kf_eta_reg - (int)(etaRegions_.size() - 1) / 2;
87  }
88 
89  int nbits = floor(log2(hitpattern_)) + 1;
90  int lay_i = 0;
91  bool seq = false;
92  for (int i = 0; i < nbits; i++) {
93  lay_i = ((1 << i) & hitpattern_) >> i; //0 or 1 in ith bit (right to left)
94 
95  if (lay_i && !seq)
96  seq = true; //sequence starts when first 1 found
97  if (!lay_i && seq) {
98  numMissingInterior1_++; //This is the same as the "tmp_trk_nlaymiss_interior" calculated in Trackquality.cc
99  }
100  if (!lay_i) {
101  bool realhit = false;
102  if (layermap_[kf_eta_reg][i].empty())
103  continue;
104  for (int j : layermap_[kf_eta_reg][i]) {
105  int k = findLayer(j);
106  if (k > 0)
107  realhit = true;
108  }
109  if (realhit)
110  numMissingInterior2_++; //This variable doesn't make sense for new KF because it uses the layermap from Old KF
111  }
112  }
113 
114  if (hphDebug_) {
115  if (useNewKF_) {
116  edm::LogVerbatim("TrackTriggerHPH") << "Running with New KF";
117  } else {
118  edm::LogVerbatim("TrackTriggerHPH") << "Running with Old KF";
119  }
120  edm::LogVerbatim("TrackTriggerHPH") << "======================================================";
121  edm::LogVerbatim("TrackTriggerHPH")
122  << "Looking at hitpattern " << std::bitset<7>(hitpattern_) << "; Looping over KF layers:";
123  }
124 
125  if (useNewKF_) {
126  //New KF uses sensor modules to determine the hitmask already
127  for (int i = 0; i < numExpLayer_; i++) {
128  if (hphDebug_) {
129  edm::LogVerbatim("TrackTriggerHPH") << "--------------------------";
130  edm::LogVerbatim("TrackTriggerHPH") << "Looking at KF layer " << i;
131  if (layerEncoding_[i] < 10) {
132  edm::LogVerbatim("TrackTriggerHPH") << "KF expects L" << layerEncoding_[i];
133  } else {
134  edm::LogVerbatim("TrackTriggerHPH") << "KF expects D" << layerEncoding_[i] - 10;
135  }
136  }
137 
138  if (((1 << i) & hitpattern_) >> i) {
139  if (hphDebug_) {
140  edm::LogVerbatim("TrackTriggerHPH") << "Layer found in hitpattern";
141  }
142 
144  if (layerEncodingMap_[layerEncoding_[i]]->psModule()) {
145  numPS_++;
146  } else {
147  num2S_++;
148  }
149  } else {
150  if (hphDebug_) {
151  edm::LogVerbatim("TrackTriggerHPH") << "Layer missing in hitpattern";
152  }
153 
154  if (layerEncodingMap_[layerEncoding_[i]]->psModule()) {
155  numMissingPS_++;
156  } else {
157  numMissing2S_++;
158  }
159  }
160  }
161 
162  } else {
163  //Old KF uses the hard coded layermap to determien hitmask
164  for (int i = 0; i < nKalmanLayers_; i++) { //Loop over each digit of hitpattern
165 
166  if (hphDebug_) {
167  edm::LogVerbatim("TrackTriggerHPH") << "--------------------------";
168  edm::LogVerbatim("TrackTriggerHPH") << "Looking at KF layer " << i;
169  }
170 
171  if (layermap_[kf_eta_reg][i].empty()) {
172  if (hphDebug_) {
173  edm::LogVerbatim("TrackTriggerHPH") << "KF does not expect this layer";
174  }
175 
176  continue;
177  }
178 
179  for (int j :
180  layermap_[kf_eta_reg][i]) { //Find out which layer the Old KF is dealing with when hitpattern is encoded
181 
182  if (hphDebug_) {
183  if (j < 10) {
184  edm::LogVerbatim("TrackTriggerHPH") << "KF expects L" << j;
185  } else {
186  edm::LogVerbatim("TrackTriggerHPH") << "KF expects D" << j - 10;
187  }
188  }
189 
190  int k = findLayer(j);
191  if (k < 0) {
192  //k<0 means even though layer j is predicted by Old KF, this prediction is rejected because it contradicts
193  if (hphDebug_) { //a more accurate prediction made with the help of information from sensor modules
194  edm::LogVerbatim("TrackTriggerHPH") << "Rejected by sensor modules";
195  }
196 
197  continue;
198  }
199 
200  if (hphDebug_) {
201  edm::LogVerbatim("TrackTriggerHPH") << "Confirmed by sensor modules";
202  }
203  //prediction is accepted
204  if (((1 << i) & hitpattern_) >> i) {
205  if (hphDebug_) {
206  edm::LogVerbatim("TrackTriggerHPH") << "Layer found in hitpattern";
207  }
208 
209  binary_[reducedId(j)] = 1;
210  if (layerEncodingMap_[layerEncoding_[k]]->psModule()) {
211  numPS_++;
212  } else {
213  num2S_++;
214  }
215  } else {
216  if (hphDebug_) {
217  edm::LogVerbatim("TrackTriggerHPH") << "Layer missing in hitpattern";
218  }
219 
220  if (layerEncodingMap_[layerEncoding_[k]]->psModule()) {
221  numMissingPS_++;
222  } else {
223  numMissing2S_++;
224  }
225  }
226  }
227  }
228  }
229 
230  if (hphDebug_) {
231  edm::LogVerbatim("TrackTriggerHPH") << "------------------------------";
232  edm::LogVerbatim("TrackTriggerHPH") << "numPS = " << numPS_ << ", num2S = " << num2S_
233  << ", missingPS = " << numMissingPS_ << ", missing2S = " << numMissing2S_;
234  edm::LogVerbatim("TrackTriggerHPH") << "======================================================";
235  }
236  }
237 
238  int Setup::etaRegion(double z0, double cot, bool useNewKF) const {
239  //Calculating eta sector based on cot and z0
240  double chosenRofZ;
241  std::vector<double> etaRegions;
242  if (useNewKF) {
245  } else {
248  }
249  double kfzRef = z0 + chosenRofZ * cot;
250  int kf_eta_reg = 0;
251  for (int iEtaSec = 1; iEtaSec < ((int)etaRegions.size() - 1); iEtaSec++) { // Doesn't apply eta < 2.4 cut.
252  double etaMax = etaRegions[iEtaSec];
253  double zRefMax = chosenRofZ / tan(2. * atan(exp(-etaMax)));
254  if (kfzRef < zRefMax)
255  break;
256  kf_eta_reg = iEtaSec;
257  }
258  return kf_eta_reg;
259  }
260 
261  int Setup::digiCot(double cot, int binEta) const {
262  double cotLocal = dfcot_.digi(cot - setupTT_.sectorCot(binEta));
263  return dfcot_.toUnsigned(dfcot_.integer(cotLocal));
264  }
265 
266  int Setup::digiZT(double z0, double cot, int binEta) const {
267  double zT = z0 + setupTT_.chosenRofZ() * cot;
268  double zTLocal = dfzT_.digi(zT - setupTT_.sectorCot(binEta) * setupTT_.chosenRofZ());
269  return dfzT_.toUnsigned(dfzT_.integer(zTLocal));
270  }
271 
272  int HitPatternHelper::reducedId(int layerId) {
273  if (hphDebug_ && (layerId > 15 || layerId < 1)) {
274  edm::LogVerbatim("TrackTriggerHPH") << "Warning: invalid layer id !";
275  }
276  if (layerId <= 6) {
277  layerId = layerId - 1;
278  return layerId;
279  } else {
280  layerId = layerId - 5;
281  return layerId;
282  }
283  }
284 
285  int HitPatternHelper::findLayer(int layerId) {
286  for (int i = 0; i < (int)layerEncoding_.size(); i++) {
287  if (layerId == (int)layerEncoding_[i]) {
288  return i;
289  }
290  }
291  return -1;
292  }
293 
294 } // namespace hph
Log< level::Info, true > LogVerbatim
static constexpr std::pair< unsigned, unsigned > layerMap_[nEta_/2][nGPlayer_+1]
Definition: KFbase.h:61
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
double chosenRofZ() const
Definition: Setup.h:417
double chosenRofZ_
Class to process and provide run-time constants used by Track Trigger emulators.
Definition: Setup.h:44
bool useNewKF() const
const trackerTFP::DataFormat dfcot_
double chosenRofZ() const
double chosenRofZNewKF_
int digiZT(double z0, double cot, int binEta) const
const trackerTFP::DataFormat dfzT_
edm::ParameterSet oldKFPSet_
std::vector< int > binary_
int integer(double d) const
Definition: DataFormats.h:96
std::map< int, const tt::SensorModule * > layerEncodingMap_
std::vector< double > etaRegions_
std::vector< double > etaRegionsNewKF_
static unsigned int calcLayerIdReduced(unsigned int layerId)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< int > layerEncoding_
int findLayer(int layerId)
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
const tt::Setup setupTT_
std::vector< double > etaRegions() const
std::vector< double > etaRegions_
int toUnsigned(int i) const
Definition: DataFormats.h:102
HLT enums.
Class to encode layer ids for Kalman Filter Layers consitent with rough r-z track parameters are coun...
Definition: LayerEncoding.h:19
Class to calculate and provide dataformats used by Track Trigger emulator.
Definition: DataFormats.h:216
double digi(double d) const
Definition: DataFormats.h:98
double sectorCot(int eta) const
Definition: Setup.h:432
Setup(const edm::ParameterSet &iConfig, const tt::Setup &setupTT, const trackerTFP::DataFormats &dataFormats, const trackerTFP::LayerEncoding &layerEncoding)
int reducedId(int layerId)
int digiCot(double cot, int binEta) const
std::map< int, std::map< int, std::vector< int > > > layermap_
HitPatternHelper(const Setup *setup, int hitpattern, double cot, double z0)
int etaRegion(double z0, double cot, bool useNewKF) const
std::map< int, std::map< int, std::vector< int > > > layermap_