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  pSetDRin_(iConfig.getParameter<ParameterSet>("DRin")),
20  widthLayerId_(pSetDRin_.getParameter<int>("WidthLayerId")),
21  widthStubId_(pSetDRin_.getParameter<int>("WidthStubId")),
22  widthSeedStubId_(pSetDRin_.getParameter<int>("WidthSeedStubId")),
23  widthPSTilt_(pSetDRin_.getParameter<int>("WidthPSTilt")),
24  depthMemory_(pSetDRin_.getParameter<int>("DepthMemory")),
25  ptBoundaries_(pSetDRin_.getParameter<vector<double>>("PtBoundaries")),
26  pSetDR_(iConfig.getParameter<ParameterSet>("DR")),
27  numComparisonModules_(pSetDR_.getParameter<int>("NumComparisonModules")),
28  minIdenticalStubs_(pSetDR_.getParameter<int>("MinIdenticalStubs")),
29  numNodesDR_(2 * (ptBoundaries_.size() + 1)),
30  seedTypeNames_(iConfig.getParameter<vector<string>>("SeedTypes")),
31  numSeedTypes_(seedTypeNames_.size()),
32  numChannelsTrack_(numSeedTypes_),
33  channelEncoding_(iConfig.getParameter<vector<int>>("IRChannelsIn")) {
34  const ParameterSet& pSetSeedTypesSeedLayers = iConfig.getParameter<ParameterSet>("SeedTypesSeedLayers");
35  const ParameterSet& pSetSeedTypesProjectionLayers = iConfig.getParameter<ParameterSet>("SeedTypesProjectionLayers");
38  for (const string& s : seedTypeNames_) {
39  seedTypesSeedLayers_.emplace_back(pSetSeedTypesSeedLayers.getParameter<vector<int>>(s));
40  seedTypesProjectionLayers_.emplace_back(pSetSeedTypesProjectionLayers.getParameter<vector<int>>(s));
41  }
42  // consistency check
43  const int offsetBarrel = setup_->offsetLayerId();
44  const int numBarrelLayer = setup_->numBarrelLayer();
45  const int offsetDisk = setup_->offsetLayerDisks() + offsetBarrel;
46  static constexpr int invalidSeedLayer = -1;
47  static constexpr int invalidLayerDisk = 0;
48  const Settings settings;
49  const auto& seedlayers = settings.seedlayers();
50  const auto& projlayers = settings.projlayers();
51  const auto& projdisks = settings.projdisks();
52  // convert Seetings layer ids into ChannelAssignment layer ids
53  vector<set<int>> allSeedingLayer(seedlayers.size());
54  vector<set<int>> allProjectionLayer(seedlayers.size());
55  for (int iSeed = 0; iSeed < (int)seedlayers.size(); iSeed++)
56  for (const auto& layer : seedlayers[iSeed])
57  if (layer != invalidSeedLayer)
58  allSeedingLayer[iSeed].insert(layer < numBarrelLayer ? layer + offsetBarrel
59  : layer + offsetDisk - numBarrelLayer);
60  for (int iSeed = 0; iSeed < (int)projlayers.size(); iSeed++)
61  for (const auto& layer : projlayers[iSeed])
62  if (layer != invalidLayerDisk)
63  allProjectionLayer[iSeed].insert(layer);
64  for (int iSeed = 0; iSeed < (int)projdisks.size(); iSeed++)
65  for (const auto& disk : projdisks[iSeed])
66  if (disk != invalidLayerDisk)
67  allProjectionLayer[iSeed].insert(disk - offsetBarrel + offsetDisk);
68  // check if ChannelAssignment seedTypesSeedLayers_ and seedTypesProjectionLayers_ are subsets of Settings pendants
69  for (int iSubSeed = 0; iSubSeed < numSeedTypes_; iSubSeed++) {
70  const vector<int>& seedLayers = seedTypesSeedLayers_[iSubSeed];
71  bool subset(false);
72  for (int iAllSeed = 0; iAllSeed < (int)seedlayers.size(); iAllSeed++) {
73  // compare seed layer
74  const set<int>& asl = allSeedingLayer[iAllSeed];
75  set<int> sl(seedLayers.begin(), seedLayers.end());
76  set<int> intersect;
77  set_intersection(sl.begin(), sl.end(), asl.begin(), asl.end(), inserter(intersect, intersect.begin()));
78  if (intersect == sl) {
79  subset = true;
80  // compare projection layer
81  const vector<int>& projectionLayers = seedTypesProjectionLayers_[iSubSeed];
82  const set<int>& apl = allProjectionLayer[iAllSeed];
83  set<int> pl(projectionLayers.begin(), projectionLayers.end());
84  set<int> intersect;
85  set_intersection(pl.begin(), pl.end(), apl.begin(), apl.end(), inserter(intersect, intersect.begin()));
86  if (intersect == pl)
87  break;
88  set<int> difference;
90  pl.begin(), pl.end(), intersect.begin(), intersect.end(), inserter(difference, difference.begin()));
91  cms::Exception exception("LogicError.");
92  exception << "ProjectionLayers ( ";
93  for (int layer : difference)
94  exception << layer << " ";
95  exception << ") are not supported with seed type ( ";
96  for (int layer : seedLayers)
97  exception << layer << " ";
98  exception << ")";
99  exception.addContext("trklet::ChannelAssignment::ChannelAssignment");
100  throw exception;
101  }
102  }
103  if (subset)
104  continue;
105  cms::Exception exception("LogicError.");
106  exception << "SeedLayers ( ";
107  for (int layer : seedLayers)
108  exception << layer << " ";
109  exception << ") are not supported";
110  exception.addContext("trklet::ChannelAssignment::ChannelAssignment");
111  throw exception;
112  }
113  auto bigger = [](const vector<int>& lhs, const vector<int>& rhs) { return lhs.size() < rhs.size(); };
114  numSeedingLayers_ = max_element(seedTypesSeedLayers_.begin(), seedTypesSeedLayers_.end(), bigger)->size();
116  max_element(seedTypesProjectionLayers_.begin(), seedTypesProjectionLayers_.end(), bigger)->size();
117  auto acc = [](int sum, vector<int> ints) { return sum += (int)ints.size(); };
118  offsetsStubs_.reserve(numSeedTypes_);
119  numChannelsStub_ = accumulate(
121  for (int seed = 0; seed < numSeedTypes_; seed++) {
122  const auto it = next(seedTypesProjectionLayers_.begin(), seed);
123  offsetsStubs_.emplace_back(accumulate(seedTypesProjectionLayers_.begin(), it, numSeedingLayers_ * seed, acc));
124  }
125  }
126 
127  // returns channelId of given TTTrackRef
128  int ChannelAssignment::channelId(const TTTrackRef& ttTrackRef) const {
129  const int seedType = ttTrackRef->trackSeedType();
130  if (seedType >= numSeedTypes_) {
131  cms::Exception exception("logic_error");
132  exception << "TTTracks form seed type" << seedType << " not in supported list: (";
133  for (const auto& s : seedTypeNames_)
134  exception << s << " ";
135  exception << ").";
136  exception.addContext("trklet:ChannelAssignment:channelId");
137  throw exception;
138  }
139  return ttTrackRef->phiSector() * numSeedTypes_ + seedType;
140  }
141 
142  // sets layerId of given TTStubRef and seedType, returns false if seeed stub
143  bool ChannelAssignment::layerId(int seedType, const TTStubRef& ttStubRef, int& layerId) const {
144  layerId = -1;
145  if (seedType < 0 || seedType >= numSeedTypes_) {
146  cms::Exception exception("logic_error");
147  exception.addContext("trklet::ChannelAssignment::layerId");
148  exception << "TTTracks with with seed type " << seedType << " not supported.";
149  throw exception;
150  }
151  const int layer = setup_->layerId(ttStubRef);
152  const vector<int>& seedingLayers = seedTypesSeedLayers_[seedType];
153  if (find(seedingLayers.begin(), seedingLayers.end(), layer) != seedingLayers.end())
154  return false;
155  const vector<int>& projectingLayers = seedTypesProjectionLayers_[seedType];
156  const auto pos = find(projectingLayers.begin(), projectingLayers.end(), layer);
157  if (pos == projectingLayers.end()) {
158  const string& name = seedTypeNames_[seedType];
159  cms::Exception exception("logic_error");
160  exception.addContext("trklet::ChannelAssignment::layerId");
161  exception << "TTStub from layer " << layer << " (barrel: 1-6; discs: 11-15) from seed type " << name
162  << " not supported.";
163  throw exception;
164  }
165  layerId = distance(projectingLayers.begin(), pos);
166  return true;
167  }
168 
169  // index of first stub channel belonging to given track channel
170  int ChannelAssignment::offsetStub(int channelTrack) const {
171  const int region = channelTrack / numChannelsTrack_;
172  const int channel = channelTrack % numChannelsTrack_;
173  return region * numChannelsStub_ + offsetsStubs_[channel];
174  }
175 
176  // returns TBout channel Id
177  int ChannelAssignment::channelId(int seedType, int layerId) const {
178  const vector<int>& projections = seedTypesProjectionLayers_.at(seedType);
179  const auto itp = find(projections.begin(), projections.end(), layerId);
180  if (itp != projections.end())
181  return distance(projections.begin(), itp);
182  const vector<int>& seeds = seedTypesSeedLayers_.at(seedType);
183  const auto its = find(seeds.begin(), seeds.end(), layerId);
184  if (its != seeds.end())
185  return (int)projections.size() + distance(seeds.begin(), its);
186  return -1;
187  }
188 
189  // return DR node for given ttTrackRef
190  int ChannelAssignment::nodeDR(const TTTrackRef& ttTrackRef) const {
191  const double pt = ttTrackRef->momentum().perp();
192  int bin(0);
193  for (double b : ptBoundaries_) {
194  if (pt < b)
195  break;
196  bin++;
197  }
198  if (ttTrackRef->rInv() >= 0.)
199  bin += numNodesDR_ / 2;
200  else
201  bin = numNodesDR_ / 2 - 1 - bin;
202  return bin;
203  }
204 
205  // layers a seed types can project to using default layer id [barrel: 1-6, discs: 11-15]
206  int ChannelAssignment::layerId(int seedType, int channel) const {
207  if (channel < numProjectionLayers(seedType))
208  return seedTypesProjectionLayers_.at(seedType).at(channel);
209  return seedTypesSeedLayers_.at(seedType).at(channel - numProjectionLayers(seedType));
210  }
211 
212 } // namespace trklet
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< std::string > seedTypeNames_
unsigned int seedlayers(int inner, int seed) const
Definition: Settings.h:154
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
int nodeDR(const TTTrackRef &ttTrackRef) const
int channelId(const TTTrackRef &ttTrackRef) 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
unsigned int projlayers(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:164
Definition: TTTypes.h:54
int layerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:511
unsigned int projdisks(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:165
std::vector< int > offsetsStubs_
int offsetLayerDisks() const
Definition: Setup.h:371
int offsetLayerId() const
Definition: Setup.h:373
int numProjectionLayers(int seedType) const
std::vector< std::vector< int > > seedTypesProjectionLayers_
double b
Definition: hdecay.h:120
std::vector< std::vector< int > > seedTypesSeedLayers_
HLT enums.
std::vector< double > ptBoundaries_
int numBarrelLayer() const
Definition: Setup.h:375
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)
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)