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 std::map< int, const tt::SensorModule * > & layerEncodingMap (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::map< int, const tt::SensorModule * > > > > layerEncodingMap_
 
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 19 of file LayerEncoding.h.

Constructor & Destructor Documentation

◆ LayerEncoding() [1/2]

trackerTFP::LayerEncoding::LayerEncoding ( )
inline

Definition at line 21 of file LayerEncoding.h.

21 {}

◆ LayerEncoding() [2/2]

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

Definition at line 15 of file LayerEncoding.cc.

References funct::abs(), trackerTFP::DataFormat::base(), trackerTFP::begin, tt::Setup::boundarieEta(), tt::Setup::chosenRofZ(), ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), trackerTFP::cot, cot_, ztail::d, dumpMFGeometry_cfg::delta, HLT_2024v11_cff::distance, alcaDQMUpload::encode(), trackerTFP::end, geometryDiff::file, spr::find(), trackerTFP::DataFormat::floating(), mps_fire::i, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, dqmiolumiharvest::j, MainPageGenerator::l, trackerTFP::layer, layerEncoding(), layerEncoding_, layerEncodingMap_, 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_, ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction::internal::barrel::sm(), contentValuesCheck::ss, trackerTFP::DataFormat::toSigned(), tier0::unique(), trackerTFP::DataFormat::width(), tt::SensorModule::z(), trackerTFP::zht, trackerTFP::zT, and zT_.

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

◆ ~LayerEncoding()

trackerTFP::LayerEncoding::~LayerEncoding ( )
inline

Definition at line 23 of file LayerEncoding.h.

23 {}

Member Function Documentation

◆ layerEncoding()

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

Definition at line 25 of file LayerEncoding.h.

References layerEncoding_.

Referenced by LayerEncoding(), and hph::Setup::layerEncoding().

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

◆ layerEncodingMap()

const std::map<int, const tt::SensorModule*>& trackerTFP::LayerEncoding::layerEncodingMap ( int  binEta,
int  binZT,
int  binCot 
) const
inline

Definition at line 28 of file LayerEncoding.h.

References layerEncodingMap_.

Referenced by hph::Setup::layerEncodingMap().

28  {
29  return layerEncodingMap_.at(binEta).at(binZT).at(binCot);
30  }
std::vector< std::vector< std::vector< std::map< int, const tt::SensorModule * > > > > layerEncodingMap_
Definition: LayerEncoding.h:51

◆ layerIdKF()

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

Definition at line 152 of file LayerEncoding.cc.

References HLT_2024v11_cff::distance, spr::find(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, trackerTFP::layer, layerEncoding_, hgcalTBTopologyTester_cfi::layers, tt::Setup::numLayers(), and setup_.

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

152  {
153  const vector<int>& layers = layerEncoding_[binEta][binZT][binCot];
154  const auto it = find(layers.begin(), layers.end(), layerId);
155  if (it == layers.end())
156  return -1;
157  int layer = distance(layers.begin(), it);
158  if (layer >= setup_->numLayers())
159  layer = setup_->numLayers() - 1;
160  return layer;
161  }
const tt::Setup * setup_
Definition: LayerEncoding.h:42
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:50

◆ maybeLayer()

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

Definition at line 32 of file LayerEncoding.h.

References maybeLayer_.

Referenced by LayerEncoding().

32  {
33  return maybeLayer_.at(binEta).at(binZT).at(binCot);
34  }
std::vector< std::vector< std::vector< std::vector< int > > > > maybeLayer_
Definition: LayerEncoding.h:53

◆ maybePattern()

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

Definition at line 164 of file LayerEncoding.cc.

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

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

164  {
165  TTBV ttBV(0, setup_->numLayers());
166  const vector<int>& layers = layerEncoding_[binEta][binZT][binCot];
167  const vector<int>& maybes = maybeLayer_[binEta][binZT][binCot];
168  for (int m : maybes)
169  ttBV.set(distance(layers.begin(), find(layers.begin(), layers.end(), m)));
170  return ttBV;
171  }
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:42
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:50
std::vector< std::vector< std::vector< std::vector< int > > > > maybeLayer_
Definition: LayerEncoding.h:53

Member Data Documentation

◆ cot_

const DataFormat* trackerTFP::LayerEncoding::cot_
private

Definition at line 48 of file LayerEncoding.h.

Referenced by LayerEncoding().

◆ dataFormats_

const DataFormats* trackerTFP::LayerEncoding::dataFormats_
private

Definition at line 44 of file LayerEncoding.h.

◆ layerEncoding_

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

Definition at line 50 of file LayerEncoding.h.

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

◆ layerEncodingMap_

std::vector<std::vector<std::vector<std::map<int, const tt::SensorModule*> > > > trackerTFP::LayerEncoding::layerEncodingMap_
private

Definition at line 51 of file LayerEncoding.h.

Referenced by LayerEncoding(), and layerEncodingMap().

◆ maybeLayer_

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

Definition at line 53 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 46 of file LayerEncoding.h.

Referenced by LayerEncoding().