CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
trackerTFP::LayerEncoding Class Reference

Class to encode layer ids for Kalman Filter Layers consitent with rough r-z track parameters are counted from 0 onwards. More...

#include <LayerEncoding.h>

Public Member Functions

 LayerEncoding ()
 
 LayerEncoding (const DataFormats *dataFormats)
 
const std::vector< int > & layerEncoding (int binEta, int binZT, int binCot) const
 
const int layerIdKF (int binEta, int binZT, int binCot, int layerId) const
 
const std::vector< int > & maybeLayer (int binEta, int binZT, int binCot) const
 
TTBV maybePattern (int binEta, int binZT, int binCot) const
 
 ~LayerEncoding ()
 

Private Attributes

const DataFormatcot_
 
const DataFormatsdataFormats_
 
std::vector< std::vector< std::vector< std::vector< int > > > > layerEncoding_
 
std::vector< std::vector< std::vector< std::vector< int > > > > maybeLayer_
 
const tt::Setupsetup_
 
const DataFormatzT_
 

Detailed Description

Class to encode layer ids for Kalman Filter Layers consitent with rough r-z track parameters are counted from 0 onwards.

Author
Thomas Schuh
Date
2020, July

Definition at line 18 of file LayerEncoding.h.

Constructor & Destructor Documentation

◆ LayerEncoding() [1/2]

trackerTFP::LayerEncoding::LayerEncoding ( )
inline

Definition at line 20 of file LayerEncoding.h.

20 {}

◆ LayerEncoding() [2/2]

trackerTFP::LayerEncoding::LayerEncoding ( const DataFormats dataFormats)

Definition at line 16 of file LayerEncoding.cc.

References funct::abs(), trackerTFP::DataFormat::base(), trackerTFP::begin, tt::Setup::boundarieEta(), tt::Setup::chosenRofZ(), trackerTFP::cot, cot_, ztail::d, dumpMFGeometry_cfg::delta, HLT_2023v12_cff::distance, alcaDQMUpload::encode(), trackerTFP::end, geometryDiff::file, spr::find(), trackerTFP::DataFormat::floating(), mps_fire::i, dqmiolumiharvest::j, MainPageGenerator::l, trackerTFP::layer, layerEncoding(), layerEncoding_, PostProcessor_cff::layerIds, hgcalTBTopologyTester_cfi::layers, visualization-live-secondInstance_cfg::m, maybeLayer(), maybeLayer_, edm_modernize_messagelogger::ml, tt::Setup::numLayers(), tt::Setup::numSectorsEta(), MillePedeFileConverter_cfg::out, funct::pow(), print(), tt::SensorModule::r(), tt::Setup::sensorModules(), setup_, contentValuesCheck::ss, trackerTFP::DataFormat::toSigned(), tier0::unique(), trackerTFP::DataFormat::width(), tt::SensorModule::z(), trackerTFP::zht, trackerTFP::zT, and zT_.

17  : setup_(dataFormats->setup()),
18  dataFormats_(dataFormats),
19  zT_(&dataFormats->format(Variable::zT, Process::zht)),
20  cot_(&dataFormats->format(Variable::cot, Process::zht)),
22  vector<vector<vector<int>>>(pow(2, zT_->width()), vector<vector<int>>(pow(2, cot_->width())))),
24  vector<vector<vector<int>>>(pow(2, zT_->width()), vector<vector<int>>(pow(2, cot_->width())))) {
25  // number of boundaries of fiducial area in r-z plane for a given set of rough r-z track parameter
26  static constexpr int boundaries = 2;
27  // find unique sensor mouldes in r-z
28  // allowed distance in r and z in cm between modules to consider them not unique
29  static constexpr double delta = 1.e-3;
30  vector<const SensorModule*> sensorModules;
31  sensorModules.reserve(setup_->sensorModules().size());
32  for (const SensorModule& sm : setup_->sensorModules())
33  sensorModules.push_back(&sm);
34  auto smallerR = [](const SensorModule* lhs, const SensorModule* rhs) { return lhs->r() < rhs->r(); };
35  auto smallerZ = [](const SensorModule* lhs, const SensorModule* rhs) { return lhs->z() < rhs->z(); };
36  auto equalRZ = [](const SensorModule* lhs, const SensorModule* rhs) {
37  return abs(lhs->r() - rhs->r()) < delta && abs(lhs->z() - rhs->z()) < delta;
38  };
39  stable_sort(sensorModules.begin(), sensorModules.end(), smallerR);
40  stable_sort(sensorModules.begin(), sensorModules.end(), smallerZ);
41  sensorModules.erase(unique(sensorModules.begin(), sensorModules.end(), equalRZ), sensorModules.end());
42  // find set of moudles for each set of rough r-z track parameter
43  // loop over eta sectors
44  for (int binEta = 0; binEta < setup_->numSectorsEta(); binEta++) {
45  // cotTheta of eta sector centre
46  const double sectorCot = (sinh(setup_->boundarieEta(binEta + 1)) + sinh(setup_->boundarieEta(binEta))) / 2.;
47  // z at radius choenRofZ of eta sector centre
48  const double sectorZT = setup_->chosenRofZ() * sectorCot;
49  // loop over bins in zT
50  for (int binZT = 0; binZT < pow(2, zT_->width()); binZT++) {
51  // z at radius chosenRofZ wrt zT of sectorZT of this bin centre
52  const double zT = zT_->floating(zT_->toSigned(binZT));
53  // z at radius chosenRofZ wrt zT of sectorZT of this bin boundaries
54  const vector<double> zTs = {sectorZT + zT - zT_->base() / 2., sectorZT + zT + zT_->base() / 2.};
55  // loop over bins in cotTheta
56  for (int binCot = 0; binCot < pow(2, cot_->width()); binCot++) {
57  // cotTheta wrt sectorCot of this bin centre
58  const double cot = cot_->floating(cot_->toSigned(binCot));
59  // layer ids crossed by left and right rough r-z parameter shape boundaries
60  vector<set<int>> layers(boundaries);
61  // cotTheta wrt sectorCot of this bin boundaries
62  const vector<double> cots = {sectorCot + cot - cot_->base() / 2., sectorCot + cot + cot_->base() / 2.};
63  // loop over all unique modules
64  for (const SensorModule* sm : sensorModules) {
65  // check if module is crossed by left and right rough r-z parameter shape boundaries
66  for (int i = 0; i < boundaries; i++) {
67  const int j = boundaries - i - 1;
68  const double zTi = zTs[sm->r() > setup_->chosenRofZ() ? i : j];
69  const double coti = cots[sm->r() > setup_->chosenRofZ() ? j : i];
70  // distance between module and boundary in moudle tilt angle direction
71  const double d =
72  (zTi - sm->z() + (sm->r() - setup_->chosenRofZ()) * coti) / (sm->cosTilt() - sm->sinTilt() * coti);
73  // compare distance with module size and add module layer id to layers if module is crossed
74  if (abs(d) < sm->numColumns() * sm->pitchCol() / 2.)
75  layers[i].insert(sm->layerId());
76  }
77  }
78  // mayber layers are given by layer ids crossed by only one booundary
79  set<int> maybeLayer;
80  set_symmetric_difference(layers[0].begin(),
81  layers[0].end(),
82  layers[1].begin(),
83  layers[1].end(),
84  inserter(maybeLayer, maybeLayer.end()));
85  // layerEncoding is given by sorted layer ids crossed by any booundary
86  set<int> layerEncoding;
87  set_union(layers[0].begin(),
88  layers[0].end(),
89  layers[1].begin(),
90  layers[1].end(),
91  inserter(layerEncoding, layerEncoding.end()));
92  vector<int>& le = layerEncoding_[binEta][binZT][binCot];
93  le = vector<int>(layerEncoding.begin(), layerEncoding.end());
94  vector<int>& ml = maybeLayer_[binEta][binZT][binCot];
95  ml.reserve(maybeLayer.size());
96  for (int m : maybeLayer) {
97  int layer = distance(le.begin(), find(le.begin(), le.end(), m));
98  if (layer >= setup_->numLayers())
99  layer = setup_->numLayers() - 1;
100  ml.push_back(layer);
101  }
102  }
103  }
104  }
105  const bool print = false;
106  if (!print)
107  return;
108  static constexpr int widthLayer = 3;
109  static constexpr auto layerIds = {1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15};
110  stringstream ss;
111  for (int layer : layerIds) {
112  auto encode = [layer, this](const vector<int>& layers, int& l) {
113  const auto it = find(layers.begin(), layers.end(), layer);
114  if (it == layers.end())
115  return false;
116  l = distance(layers.begin(), it);
117  if (l >= setup_->numLayers())
118  l = setup_->numLayers() - 1;
119  return true;
120  };
121  for (int binEta = 0; binEta < setup_->numSectorsEta(); binEta++) {
122  for (int binZT = 0; binZT < pow(2, zT_->width()); binZT++) {
123  for (int binCot = 0; binCot < pow(2, cot_->width()); binCot++) {
124  const int zT =
125  binZT < pow(2, zT_->width() - 1) ? binZT + pow(2, zT_->width() - 1) : binZT - pow(2, zT_->width() - 1);
126  const int cot = binCot < pow(2, cot_->width() - 1) ? binCot + pow(2, cot_->width() - 1)
127  : binCot - pow(2, cot_->width() - 1);
128  const vector<int>& layers = layerEncoding_[binEta][zT][cot];
129  const vector<int>& maybes = maybeLayer_[binEta][zT][cot];
130  int layerKF(-1);
131  if (encode(layers, layerKF))
132  ss << "1" << TTBV(layerKF, widthLayer) << (encode(maybes, layerKF) ? "1" : "0");
133  else
134  ss << "00000";
135  ss << endl;
136  }
137  }
138  }
139  }
140  fstream file;
141  file.open("layerEncoding.txt", ios::out);
142  file << ss.rdbuf();
143  file.close();
144  }
const std::vector< int > & maybeLayer(int binEta, int binZT, int binCot) const
Definition: LayerEncoding.h:28
const DataFormats * dataFormats_
Definition: LayerEncoding.h:40
double base() const
Definition: DataFormats.h:117
double chosenRofZ() const
Definition: Setup.h:413
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
double boundarieEta(int eta) const
Definition: Setup.h:417
const tt::Setup * setup_
Definition: LayerEncoding.h:38
const std::vector< int > & layerEncoding(int binEta, int binZT, int binCot) const
Definition: LayerEncoding.h:24
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int numSectorsEta() const
Definition: Setup.h:411
const std::vector< SensorModule > & sensorModules() const
Definition: Setup.h:126
def unique(seq, keepstr=True)
Definition: tier0.py:24
const DataFormat * cot_
Definition: LayerEncoding.h:44
double floating(int i) const
Definition: DataFormats.h:94
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double r() const
Definition: SensorModule.h:45
d
Definition: ztail.py:151
int numLayers() const
Definition: Setup.h:215
int toSigned(int i) const
Definition: DataFormats.h:100
double z() const
Definition: SensorModule.h:49
def encode(args, files)
std::vector< std::vector< std::vector< std::vector< int > > > > layerEncoding_
Definition: LayerEncoding.h:46
std::vector< std::vector< std::vector< std::vector< int > > > > maybeLayer_
Definition: LayerEncoding.h:48
const DataFormat * zT_
Definition: LayerEncoding.h:42
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ ~LayerEncoding()

trackerTFP::LayerEncoding::~LayerEncoding ( )
inline

Definition at line 22 of file LayerEncoding.h.

22 {}

Member Function Documentation

◆ layerEncoding()

const std::vector<int>& trackerTFP::LayerEncoding::layerEncoding ( int  binEta,
int  binZT,
int  binCot 
) const
inline

Definition at line 24 of file LayerEncoding.h.

References layerEncoding_.

Referenced by LayerEncoding().

24  {
25  return layerEncoding_.at(binEta).at(binZT).at(binCot);
26  }
std::vector< std::vector< std::vector< std::vector< int > > > > layerEncoding_
Definition: LayerEncoding.h:46

◆ layerIdKF()

const int trackerTFP::LayerEncoding::layerIdKF ( int  binEta,
int  binZT,
int  binCot,
int  layerId 
) const

Definition at line 147 of file LayerEncoding.cc.

References HLT_2023v12_cff::distance, spr::find(), trackerTFP::layer, layerEncoding_, hgcalTBTopologyTester_cfi::layers, tt::Setup::numLayers(), and setup_.

Referenced by trklet::KFin::produce(), and trackerTFP::ProducerKFin::produce().

147  {
148  const vector<int>& layers = layerEncoding_[binEta][binZT][binCot];
149  const auto it = find(layers.begin(), layers.end(), layerId);
150  if (it == layers.end())
151  return -1;
152  int layer = distance(layers.begin(), it);
153  if (layer >= setup_->numLayers())
154  layer = setup_->numLayers() - 1;
155  return layer;
156  }
const tt::Setup * setup_
Definition: LayerEncoding.h:38
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int numLayers() const
Definition: Setup.h:215
std::vector< std::vector< std::vector< std::vector< int > > > > layerEncoding_
Definition: LayerEncoding.h:46

◆ maybeLayer()

const std::vector<int>& trackerTFP::LayerEncoding::maybeLayer ( int  binEta,
int  binZT,
int  binCot 
) const
inline

Definition at line 28 of file LayerEncoding.h.

References maybeLayer_.

Referenced by LayerEncoding().

28  {
29  return maybeLayer_.at(binEta).at(binZT).at(binCot);
30  }
std::vector< std::vector< std::vector< std::vector< int > > > > maybeLayer_
Definition: LayerEncoding.h:48

◆ maybePattern()

TTBV trackerTFP::LayerEncoding::maybePattern ( int  binEta,
int  binZT,
int  binCot 
) const

Definition at line 159 of file LayerEncoding.cc.

References HLT_2023v12_cff::distance, spr::find(), layerEncoding_, hgcalTBTopologyTester_cfi::layers, visualization-live-secondInstance_cfg::m, maybeLayer_, tt::Setup::numLayers(), and setup_.

Referenced by trklet::KFin::produce(), and trackerTFP::ProducerKFin::produce().

159  {
160  TTBV ttBV(0, setup_->numLayers());
161  const vector<int>& layers = layerEncoding_[binEta][binZT][binCot];
162  const vector<int>& maybes = maybeLayer_[binEta][binZT][binCot];
163  for (int m : maybes)
164  ttBV.set(distance(layers.begin(), find(layers.begin(), layers.end(), m)));
165  return ttBV;
166  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
const tt::Setup * setup_
Definition: LayerEncoding.h:38
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int numLayers() const
Definition: Setup.h:215
std::vector< std::vector< std::vector< std::vector< int > > > > layerEncoding_
Definition: LayerEncoding.h:46
std::vector< std::vector< std::vector< std::vector< int > > > > maybeLayer_
Definition: LayerEncoding.h:48

Member Data Documentation

◆ cot_

const DataFormat* trackerTFP::LayerEncoding::cot_
private

Definition at line 44 of file LayerEncoding.h.

Referenced by LayerEncoding().

◆ dataFormats_

const DataFormats* trackerTFP::LayerEncoding::dataFormats_
private

Definition at line 40 of file LayerEncoding.h.

◆ layerEncoding_

std::vector<std::vector<std::vector<std::vector<int> > > > trackerTFP::LayerEncoding::layerEncoding_
private

Definition at line 46 of file LayerEncoding.h.

Referenced by LayerEncoding(), layerEncoding(), layerIdKF(), and maybePattern().

◆ maybeLayer_

std::vector<std::vector<std::vector<std::vector<int> > > > trackerTFP::LayerEncoding::maybeLayer_
private

Definition at line 48 of file LayerEncoding.h.

Referenced by LayerEncoding(), maybeLayer(), and maybePattern().

◆ setup_

const tt::Setup* trackerTFP::LayerEncoding::setup_
private

◆ zT_

const DataFormat* trackerTFP::LayerEncoding::zT_
private

Definition at line 42 of file LayerEncoding.h.

Referenced by LayerEncoding().