CMS 3D CMS Logo

ChannelAssignment.cc
Go to the documentation of this file.
3 
4 #include <vector>
5 #include <array>
6 #include <set>
7 #include <algorithm>
8 #include <numeric>
9 #include <iterator>
10 
11 using namespace std;
12 using namespace edm;
13 using namespace tt;
14 
15 namespace trklet {
16 
18  : setup_(setup),
19  useDuplicateRemoval_(iConfig.getParameter<bool>("UseDuplicateRemoval")),
20  boundaries_(iConfig.getParameter<vector<double>>("PtBoundaries")),
21  seedTypeNames_(iConfig.getParameter<vector<string>>("SeedTypes")),
22  numSeedTypes_(seedTypeNames_.size()),
23  numChannelsTrack_(useDuplicateRemoval_ ? 2 * boundaries_.size() : numSeedTypes_),
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  }
116 
117  // sets channelId of given TTTrackRef, return false if track outside pt range
118  bool ChannelAssignment::channelId(const TTTrackRef& ttTrackRef, int& channelId) {
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  }
147 
148  // sets layerId of given TTStubRef and seedType, returns false if seeed stub
149  bool ChannelAssignment::layerId(int seedType, const TTStubRef& ttStubRef, int& layerId) const {
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  }
174 
175  // index of first stub channel belonging to given track channel
176  int ChannelAssignment::offsetStub(int channelTrack) const {
177  return channelTrack / numChannelsTrack_ * numChannelsStub_ + offsetsStubs_[channelTrack % numChannelsTrack_];
178  }
179 
180  //
181  int ChannelAssignment::channelId(int seedType, int layerId) const {
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  }
192 
193 } // namespace trklet
size
Write out results.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::string > seedTypeNames_
unsigned int seedlayers(int inner, int seed) const
Definition: Settings.h:145
Class to process and provide run-time constants used by Track Trigger emulators.
Definition: Setup.h:44
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
int offsetStub(int channelTrack) const
bool channelId(const TTTrackRef &ttTrackRef, int &channelId)
unsigned int projlayers(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:155
Definition: TTTypes.h:54
int layerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:507
std::vector< double > boundaries_
unsigned int projdisks(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:156
std::vector< int > offsetsStubs_
int offsetLayerDisks() const
Definition: Setup.h:367
int offsetLayerId() const
Definition: Setup.h:369
std::vector< std::vector< int > > seedTypesProjectionLayers_
uint8_t channelId(const VFATFrame &frame)
retrieve this channel identifier
std::vector< std::vector< int > > seedTypesSeedLayers_
HLT enums.
int numBarrelLayer() const
Definition: Setup.h:371
bool layerId(int seedType, const TTStubRef &ttStubRef, int &layerId) const
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)