CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
trklet::ChannelAssignment Class Reference

Class to assign tracklet tracks and stubs to output channel based on their Pt or seed type as well as DTC stubs to input channel. More...

#include <ChannelAssignment.h>

Public Member Functions

 ChannelAssignment ()
 
 ChannelAssignment (const edm::ParameterSet &iConfig, const tt::Setup *setup)
 
const std::vector< int > & channelEncoding () const
 
bool channelId (const TTTrackRef &ttTrackRef, int &channelId)
 
int channelId (int seedType, int layerId) const
 
bool layerId (int seedType, const TTStubRef &ttStubRef, int &layerId) const
 
int layerId (int seedType, int channel) const
 
int maxNumProjectionLayers () const
 
int numChannelsStub () const
 
int numChannelsTrack () const
 
int numProjectionLayers (int seedType) const
 
int numSeedingLayers () const
 
int numSeedTypes () const
 
int offsetStub (int channelTrack) const
 
const std::vector< int > & seedingLayers (int seedType) const
 
tt::SensorModule::Type type (const TTStubRef &ttStubRef) const
 
 ~ChannelAssignment ()
 

Private Attributes

std::vector< double > boundaries_
 
std::vector< int > channelEncoding_
 
int maxNumProjectionLayers_
 
int numChannelsStub_
 
int numChannelsTrack_
 
int numSeedingLayers_
 
int numSeedTypes_
 
std::vector< int > offsetsStubs_
 
std::vector< std::string > seedTypeNames_
 
std::vector< std::vector< int > > seedTypesProjectionLayers_
 
std::vector< std::vector< int > > seedTypesSeedLayers_
 
const tt::Setupsetup_
 
bool useDuplicateRemoval_
 

Detailed Description

Class to assign tracklet tracks and stubs to output channel based on their Pt or seed type as well as DTC stubs to input channel.

Author
Thomas Schuh
Date
2020, Nov; updated 2021 Oct

Definition at line 20 of file ChannelAssignment.h.

Constructor & Destructor Documentation

◆ ChannelAssignment() [1/2]

trklet::ChannelAssignment::ChannelAssignment ( )
inline

Definition at line 22 of file ChannelAssignment.h.

22 {}

◆ ChannelAssignment() [2/2]

trklet::ChannelAssignment::ChannelAssignment ( const edm::ParameterSet iConfig,
const tt::Setup setup 
)

Definition at line 17 of file ChannelAssignment.cc.

References cppFunctionSkipper::exception, edm::ParameterSet::getParameter(), createfilelist::int, maxNumProjectionLayers_, GetRecoTauVFromDQM_MC_cff::next, tt::Setup::numBarrelLayer(), numChannelsStub_, numSeedingLayers_, numSeedTypes_, tt::Setup::offsetLayerDisks(), tt::Setup::offsetLayerId(), offsetsStubs_, trklet::Settings::projdisks(), trklet::Settings::projlayers(), alignCSCRings::s, fileCollector::seed, trklet::Settings::seedlayers(), seedTypeNames_, seedTypesProjectionLayers_, seedTypesSeedLayers_, DBoxMetadataHelper::set_difference(), DBoxMetadataHelper::set_intersection(), setup_, and findQualityFiles::size.

18  : setup_(setup),
19  useDuplicateRemoval_(iConfig.getParameter<bool>("UseDuplicateRemoval")),
20  boundaries_(iConfig.getParameter<vector<double>>("PtBoundaries")),
21  seedTypeNames_(iConfig.getParameter<vector<string>>("SeedTypes")),
24  channelEncoding_(iConfig.getParameter<vector<int>>("IRChannelsIn")) {
25  const ParameterSet& pSetSeedTypesSeedLayers = iConfig.getParameter<ParameterSet>("SeedTypesSeedLayers");
26  const ParameterSet& pSetSeedTypesProjectionLayers = iConfig.getParameter<ParameterSet>("SeedTypesProjectionLayers");
29  for (const string& s : seedTypeNames_) {
30  seedTypesSeedLayers_.emplace_back(pSetSeedTypesSeedLayers.getParameter<vector<int>>(s));
31  seedTypesProjectionLayers_.emplace_back(pSetSeedTypesProjectionLayers.getParameter<vector<int>>(s));
32  }
33  auto acc = [](int& sum, vector<int> ints) { return sum += (int)ints.size(); };
34  numChannelsStub_ = accumulate(seedTypesProjectionLayers_.begin(), seedTypesProjectionLayers_.end(), 0, acc);
36  for (int seed = 0; seed < numSeedTypes_; seed++) {
37  const auto it = next(seedTypesProjectionLayers_.begin(), seed);
38  offsetsStubs_.emplace_back(accumulate(seedTypesProjectionLayers_.begin(), it, 0, acc));
39  }
40  // consistency check
41  const int offsetBarrel = setup_->offsetLayerId();
42  const int numBarrelLayer = setup_->numBarrelLayer();
43  const int offsetDisk = setup_->offsetLayerDisks() + offsetBarrel;
44  static constexpr int invalidSeedLayer = -1;
45  static constexpr int invalidLayerDisk = 0;
46  const Settings settings;
47  const auto& seedlayers = settings.seedlayers();
48  const auto& projlayers = settings.projlayers();
49  const auto& projdisks = settings.projdisks();
50  // convert Seetings layer ids into ChannelAssignment layer ids
51  vector<set<int>> allSeedingLayer(seedlayers.size());
52  vector<set<int>> allProjectionLayer(seedlayers.size());
53  for (int iSeed = 0; iSeed < (int)seedlayers.size(); iSeed++)
54  for (const auto& layer : seedlayers[iSeed])
55  if (layer != invalidSeedLayer)
56  allSeedingLayer[iSeed].insert(layer < numBarrelLayer ? layer + offsetBarrel
57  : layer + offsetDisk - numBarrelLayer);
58  for (int iSeed = 0; iSeed < (int)projlayers.size(); iSeed++)
59  for (const auto& layer : projlayers[iSeed])
60  if (layer != invalidLayerDisk)
61  allProjectionLayer[iSeed].insert(layer);
62  for (int iSeed = 0; iSeed < (int)projdisks.size(); iSeed++)
63  for (const auto& disk : projdisks[iSeed])
64  if (disk != invalidLayerDisk)
65  allProjectionLayer[iSeed].insert(disk - offsetBarrel + offsetDisk);
66  // check if ChannelAssignment seedTypesSeedLayers_ and seedTypesProjectionLayers_ are subsets of Settings pendants
67  for (int iSubSeed = 0; iSubSeed < numSeedTypes_; iSubSeed++) {
68  const vector<int>& seedLayers = seedTypesSeedLayers_[iSubSeed];
69  bool subset(false);
70  for (int iAllSeed = 0; iAllSeed < (int)seedlayers.size(); iAllSeed++) {
71  // compare seed layer
72  const set<int>& asl = allSeedingLayer[iAllSeed];
73  set<int> sl(seedLayers.begin(), seedLayers.end());
74  set<int> intersect;
75  set_intersection(sl.begin(), sl.end(), asl.begin(), asl.end(), inserter(intersect, intersect.begin()));
76  if (intersect == sl) {
77  subset = true;
78  // compare projection layer
79  const vector<int>& projectionLayers = seedTypesProjectionLayers_[iSubSeed];
80  const set<int>& apl = allProjectionLayer[iAllSeed];
81  set<int> pl(projectionLayers.begin(), projectionLayers.end());
82  set<int> intersect;
83  set_intersection(pl.begin(), pl.end(), apl.begin(), apl.end(), inserter(intersect, intersect.begin()));
84  if (intersect == pl)
85  break;
86  set<int> difference;
88  pl.begin(), pl.end(), intersect.begin(), intersect.end(), inserter(difference, difference.begin()));
89  cms::Exception exception("LogicError.");
90  exception << "ProjectionLayers ( ";
91  for (int layer : difference)
92  exception << layer << " ";
93  exception << ") are not supported with seed type ( ";
94  for (int layer : seedLayers)
95  exception << layer << " ";
96  exception << ")";
97  exception.addContext("trklet::ChannelAssignment::ChannelAssignment");
98  throw exception;
99  }
100  }
101  if (subset)
102  continue;
103  cms::Exception exception("LogicError.");
104  exception << "SeedLayers ( ";
105  for (int layer : seedLayers)
106  exception << layer << " ";
107  exception << ") are not supported";
108  exception.addContext("trklet::ChannelAssignment::ChannelAssignment");
109  throw exception;
110  }
111  auto bigger = [](const vector<int>& lhs, const vector<int>& rhs) { return lhs.size() < rhs.size(); };
112  numSeedingLayers_ = max_element(seedTypesSeedLayers_.begin(), seedTypesSeedLayers_.end(), bigger)->size();
114  max_element(seedTypesProjectionLayers_.begin(), seedTypesProjectionLayers_.end(), bigger)->size();
115  }
size
Write out results.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::string > seedTypeNames_
std::vector< int > channelEncoding_
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
std::vector< double > boundaries_
std::vector< int > offsetsStubs_
int offsetLayerDisks() const
Definition: Setup.h:367
int offsetLayerId() const
Definition: Setup.h:369
std::vector< std::vector< int > > seedTypesProjectionLayers_
std::vector< std::vector< int > > seedTypesSeedLayers_
int numBarrelLayer() const
Definition: Setup.h:371
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
ROOT::VecOps::RVec< int > ints
Definition: Resolutions.cc:4
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)

◆ ~ChannelAssignment()

trklet::ChannelAssignment::~ChannelAssignment ( )
inline

Definition at line 24 of file ChannelAssignment.h.

24 {}

Member Function Documentation

◆ channelEncoding()

const std::vector<int>& trklet::ChannelAssignment::channelEncoding ( ) const
inline

Definition at line 40 of file ChannelAssignment.h.

References channelEncoding_.

40 { return channelEncoding_; }
std::vector< int > channelEncoding_

◆ channelId() [1/2]

bool trklet::ChannelAssignment::channelId ( const TTTrackRef ttTrackRef,
int &  channelId 
)

Definition at line 118 of file ChannelAssignment.cc.

References boundaries_, cppFunctionSkipper::exception, numChannelsTrack_, numSeedTypes_, DiDispStaMuonMonitor_cfi::pt, alignCSCRings::s, seedTypeNames_, and useDuplicateRemoval_.

Referenced by trklet::ProducerTBout::produce().

118  {
119  if (!useDuplicateRemoval_) {
120  const int seedType = ttTrackRef->trackSeedType();
121  if (seedType >= numSeedTypes_) {
122  cms::Exception exception("logic_error");
123  exception << "TTTracks form seed type" << seedType << " not in supported list: (";
124  for (const auto& s : seedTypeNames_)
125  exception << s << " ";
126  exception << ").";
127  exception.addContext("trklet:ChannelAssignment:channelId");
128  throw exception;
129  }
130  channelId = ttTrackRef->phiSector() * numSeedTypes_ + seedType;
131  return true;
132  }
133  const double pt = ttTrackRef->momentum().perp();
134  channelId = -1;
135  for (double boundary : boundaries_) {
136  if (pt < boundary)
137  break;
138  else
139  channelId++;
140  }
141  if (channelId == -1)
142  return false;
143  channelId = ttTrackRef->rInv() < 0. ? channelId : numChannelsTrack_ - channelId - 1;
144  channelId += ttTrackRef->phiSector() * numChannelsTrack_;
145  return true;
146  }
std::vector< std::string > seedTypeNames_
bool channelId(const TTTrackRef &ttTrackRef, int &channelId)
std::vector< double > boundaries_

◆ channelId() [2/2]

int trklet::ChannelAssignment::channelId ( int  seedType,
int  layerId 
) const

Definition at line 181 of file ChannelAssignment.cc.

References HLT_2022v15_cff::distance, spr::find(), layerId(), DetachedQuadStep_cff::seeds, seedTypesProjectionLayers_, and seedTypesSeedLayers_.

181  {
182  const vector<int>& projections = seedTypesProjectionLayers_.at(seedType);
183  const vector<int>& seeds = seedTypesSeedLayers_.at(seedType);
184  const auto itp = find(projections.begin(), projections.end(), layerId);
185  const auto its = find(seeds.begin(), seeds.end(), layerId);
186  if (its != seeds.end())
187  return (int)projections.size() + distance(seeds.begin(), its);
188  if (itp != projections.end())
189  return distance(projections.begin(), itp);
190  return -1;
191  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< std::vector< int > > seedTypesProjectionLayers_
std::vector< std::vector< int > > seedTypesSeedLayers_
bool layerId(int seedType, const TTStubRef &ttStubRef, int &layerId) const

◆ layerId() [1/2]

bool trklet::ChannelAssignment::layerId ( int  seedType,
const TTStubRef ttStubRef,
int &  layerId 
) const

Definition at line 149 of file ChannelAssignment.cc.

References HLT_2022v15_cff::distance, cppFunctionSkipper::exception, spr::find(), tt::Setup::layerId(), Skims_PA_cff::name, numSeedTypes_, seedingLayers(), seedTypeNames_, seedTypesProjectionLayers_, seedTypesSeedLayers_, and setup_.

Referenced by channelId(), trklet::KFin::consume(), and L1FPGATrackProducer::produce().

149  {
150  layerId = -1;
151  if (seedType < 0 || seedType >= numSeedTypes_) {
152  cms::Exception exception("logic_error");
153  exception.addContext("trklet::ChannelAssignment::layerId");
154  exception << "TTTracks with with seed type " << seedType << " not supported.";
155  throw exception;
156  }
157  const int layer = setup_->layerId(ttStubRef);
158  const vector<int>& seedingLayers = seedTypesSeedLayers_[seedType];
159  if (find(seedingLayers.begin(), seedingLayers.end(), layer) != seedingLayers.end())
160  return false;
161  const vector<int>& projectingLayers = seedTypesProjectionLayers_[seedType];
162  const auto pos = find(projectingLayers.begin(), projectingLayers.end(), layer);
163  if (pos == projectingLayers.end()) {
164  const string& name = seedTypeNames_[seedType];
165  cms::Exception exception("logic_error");
166  exception.addContext("trklet::ChannelAssignment::layerId");
167  exception << "TTStub from layer " << layer << " (barrel: 1-6; discs: 11-15) from seed type " << name
168  << " not supported.";
169  throw exception;
170  }
171  layerId = distance(projectingLayers.begin(), pos);
172  return true;
173  }
std::vector< std::string > seedTypeNames_
const std::vector< int > & seedingLayers(int seedType) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
int layerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:507
std::vector< std::vector< int > > seedTypesProjectionLayers_
std::vector< std::vector< int > > seedTypesSeedLayers_
bool layerId(int seedType, const TTStubRef &ttStubRef, int &layerId) const

◆ layerId() [2/2]

int trklet::ChannelAssignment::layerId ( int  seedType,
int  channel 
) const
inline

Definition at line 48 of file ChannelAssignment.h.

References seedTypesProjectionLayers_.

48 { return seedTypesProjectionLayers_.at(seedType).at(channel); }
std::vector< std::vector< int > > seedTypesProjectionLayers_

◆ maxNumProjectionLayers()

int trklet::ChannelAssignment::maxNumProjectionLayers ( ) const
inline

Definition at line 38 of file ChannelAssignment.h.

References maxNumProjectionLayers_.

Referenced by L1FPGATrackProducer::produce().

◆ numChannelsStub()

int trklet::ChannelAssignment::numChannelsStub ( ) const
inline

◆ numChannelsTrack()

int trklet::ChannelAssignment::numChannelsTrack ( ) const
inline

◆ numProjectionLayers()

int trklet::ChannelAssignment::numProjectionLayers ( int  seedType) const
inline

Definition at line 36 of file ChannelAssignment.h.

References seedTypesProjectionLayers_.

Referenced by trklet::KFin::consume(), and L1FPGATrackProducer::produce().

36 { return (int)seedTypesProjectionLayers_.at(seedType).size(); }
std::vector< std::vector< int > > seedTypesProjectionLayers_

◆ numSeedingLayers()

int trklet::ChannelAssignment::numSeedingLayers ( ) const
inline

Definition at line 52 of file ChannelAssignment.h.

References numSeedingLayers_.

Referenced by trklet::KFin::consume().

◆ numSeedTypes()

int trklet::ChannelAssignment::numSeedTypes ( ) const
inline

Definition at line 32 of file ChannelAssignment.h.

References numSeedTypes_.

◆ offsetStub()

int trklet::ChannelAssignment::offsetStub ( int  channelTrack) const

Definition at line 176 of file ChannelAssignment.cc.

References numChannelsStub_, numChannelsTrack_, and offsetsStubs_.

Referenced by trklet::KFin::consume(), and L1FPGATrackProducer::produce().

176  {
177  return channelTrack / numChannelsTrack_ * numChannelsStub_ + offsetsStubs_[channelTrack % numChannelsTrack_];
178  }
std::vector< int > offsetsStubs_

◆ seedingLayers()

const std::vector<int>& trklet::ChannelAssignment::seedingLayers ( int  seedType) const
inline

Definition at line 44 of file ChannelAssignment.h.

References seedTypesSeedLayers_.

Referenced by trklet::KFin::consume(), and layerId().

44 { return seedTypesSeedLayers_.at(seedType); }
std::vector< std::vector< int > > seedTypesSeedLayers_

◆ type()

tt::SensorModule::Type trklet::ChannelAssignment::type ( const TTStubRef ttStubRef) const
inline

Definition at line 46 of file ChannelAssignment.h.

References setup_, and tt::Setup::type().

46 { return setup_->type(ttStubRef); }
SensorModule::Type type(const TTStubRef &ttStubRef) const
Definition: Setup.cc:325

Member Data Documentation

◆ boundaries_

std::vector<double> trklet::ChannelAssignment::boundaries_
private

Definition at line 60 of file ChannelAssignment.h.

Referenced by channelId().

◆ channelEncoding_

std::vector<int> trklet::ChannelAssignment::channelEncoding_
private

Definition at line 76 of file ChannelAssignment.h.

Referenced by channelEncoding().

◆ maxNumProjectionLayers_

int trklet::ChannelAssignment::maxNumProjectionLayers_
private

Definition at line 74 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), and maxNumProjectionLayers().

◆ numChannelsStub_

int trklet::ChannelAssignment::numChannelsStub_
private

Definition at line 68 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), numChannelsStub(), and offsetStub().

◆ numChannelsTrack_

int trklet::ChannelAssignment::numChannelsTrack_
private

Definition at line 66 of file ChannelAssignment.h.

Referenced by channelId(), numChannelsTrack(), and offsetStub().

◆ numSeedingLayers_

int trklet::ChannelAssignment::numSeedingLayers_
private

Definition at line 80 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), and numSeedingLayers().

◆ numSeedTypes_

int trklet::ChannelAssignment::numSeedTypes_
private

Definition at line 64 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), channelId(), layerId(), and numSeedTypes().

◆ offsetsStubs_

std::vector<int> trklet::ChannelAssignment::offsetsStubs_
private

Definition at line 78 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), and offsetStub().

◆ seedTypeNames_

std::vector<std::string> trklet::ChannelAssignment::seedTypeNames_
private

Definition at line 62 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), channelId(), and layerId().

◆ seedTypesProjectionLayers_

std::vector<std::vector<int> > trklet::ChannelAssignment::seedTypesProjectionLayers_
private

Definition at line 72 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), channelId(), layerId(), and numProjectionLayers().

◆ seedTypesSeedLayers_

std::vector<std::vector<int> > trklet::ChannelAssignment::seedTypesSeedLayers_
private

Definition at line 70 of file ChannelAssignment.h.

Referenced by ChannelAssignment(), channelId(), layerId(), and seedingLayers().

◆ setup_

const tt::Setup* trklet::ChannelAssignment::setup_
private

◆ useDuplicateRemoval_

bool trklet::ChannelAssignment::useDuplicateRemoval_
private

Definition at line 58 of file ChannelAssignment.h.

Referenced by channelId().