CMS 3D CMS Logo

DR.cc
Go to the documentation of this file.
2 
3 #include <vector>
4 #include <numeric>
5 #include <algorithm>
6 
7 using namespace std;
8 using namespace edm;
9 using namespace tt;
10 using namespace trackerTFP;
11 
12 namespace trklet {
13 
14  DR::DR(const ParameterSet& iConfig,
15  const Setup* setup,
16  const DataFormats* dataFormats,
17  const ChannelAssignment* channelAssignment,
18  int region)
19  : enableTruncation_(iConfig.getParameter<bool>("EnableTruncation")),
20  setup_(setup),
21  dataFormats_(dataFormats),
22  channelAssignment_(channelAssignment),
23  region_(region),
24  input_(channelAssignment_->numNodesDR()) {}
25 
26  // read in and organize input tracks and stubs
27  void DR::consume(const StreamsTrack& streamsTrack, const StreamsStub& streamsStub) {
28  const int offsetTrack = region_ * channelAssignment_->numNodesDR();
29  auto nonNullTrack = [](int sum, const FrameTrack& frame) { return sum + (frame.first.isNonnull() ? 1 : 0); };
30  auto nonNullStub = [](int sum, const FrameStub& frame) { return sum + (frame.first.isNonnull() ? 1 : 0); };
31  // count tracks and stubs and reserve corresponding vectors
32  int sizeTracks(0);
33  int sizeStubs(0);
34  for (int channel = 0; channel < channelAssignment_->numNodesDR(); channel++) {
35  const int streamTrackId = offsetTrack + channel;
36  const int offsetStub = streamTrackId * setup_->numLayers();
37  const StreamTrack& streamTrack = streamsTrack[streamTrackId];
38  input_[channel].reserve(streamTrack.size());
39  sizeTracks += accumulate(streamTrack.begin(), streamTrack.end(), 0, nonNullTrack);
40  for (int layer = 0; layer < setup_->numLayers(); layer++) {
41  const StreamStub& streamStub = streamsStub[offsetStub + layer];
42  sizeStubs += accumulate(streamStub.begin(), streamStub.end(), 0, nonNullStub);
43  }
44  }
45  tracks_.reserve(sizeTracks);
46  stubs_.reserve(sizeStubs);
47  // transform input data into handy structs
48  for (int channel = 0; channel < channelAssignment_->numNodesDR(); channel++) {
49  vector<Track*>& input = input_[channel];
50  const int streamTrackId = offsetTrack + channel;
51  const int offsetStub = streamTrackId * setup_->numLayers();
52  const StreamTrack& streamTrack = streamsTrack[streamTrackId];
53  for (int frame = 0; frame < (int)streamTrack.size(); frame++) {
54  const FrameTrack& frameTrack = streamTrack[frame];
55  if (frameTrack.first.isNull()) {
56  input.push_back(nullptr);
57  continue;
58  }
59  vector<Stub*> stubs;
60  stubs.reserve(setup_->numLayers());
61  for (int layer = 0; layer < setup_->numLayers(); layer++) {
62  const FrameStub& frameStub = streamsStub[offsetStub + layer][frame];
63  if (frameStub.first.isNull())
64  continue;
65  TTBV ttBV = frameStub.second;
66  const TTBV z(ttBV, dataFormats_->format(Variable::z, Process::kfin).width(), 0, true);
67  ttBV >>= dataFormats_->format(Variable::z, Process::kfin).width();
68  const TTBV phi(ttBV, dataFormats_->format(Variable::phi, Process::kfin).width(), 0, true);
69  ttBV >>= dataFormats_->format(Variable::phi, Process::kfin).width();
70  const TTBV r(ttBV, dataFormats_->format(Variable::r, Process::kfin).width(), 0, true);
71  ttBV >>= dataFormats_->format(Variable::r, Process::kfin).width();
72  const TTBV stubId(ttBV, channelAssignment_->widthSeedStubId(), 0);
74  const TTBV layerId(ttBV, channelAssignment_->widthLayerId(), 0);
75  ttBV >>= channelAssignment_->widthLayerId();
76  const TTBV tilt(ttBV, channelAssignment_->widthPSTilt(), 0);
77  const FrameStub frame(frameStub.first,
78  Frame("1" + tilt.str() + layerId.str() + r.str() + phi.str() + z.str()));
79  stubs_.emplace_back(frame, stubId.val(), layer);
80  stubs.push_back(&stubs_.back());
81  }
82  tracks_.emplace_back(frameTrack, stubs);
83  input.push_back(&tracks_.back());
84  }
85  // remove all gaps between end and last track
86  for (auto it = input.end(); it != input.begin();)
87  it = (*--it) ? input.begin() : input.erase(it);
88  }
89  }
90 
91  // fill output products
92  void DR::produce(StreamsStub& accpetedStubs,
93  StreamsTrack& acceptedTracks,
94  StreamsStub& lostStubs,
96  const int offsetTrack = region_ * channelAssignment_->numNodesDR();
97  for (int node = 0; node < channelAssignment_->numNodesDR(); node++) {
98  const int channelTrack = offsetTrack + node;
99  const int offsetStub = channelTrack * setup_->numLayers();
100  // remove duplicated tracks, no merge of stubs, one stub per layer expected
101  vector<Track*> cms(channelAssignment_->numComparisonModules(), nullptr);
102  vector<Track*>& tracks = input_[node];
103  for (Track*& track : tracks) {
104  if (!track)
105  // gaps propagate trough chain and appear in output stream
106  continue;
107  for (Track*& trackCM : cms) {
108  if (!trackCM) {
109  // tracks used in CMs propagate trough chain and appear in output stream unaltered
110  trackCM = track;
111  break;
112  }
113  if (equalEnough(track, trackCM)) {
114  // tracks compared in CMs propagate trough chain and appear in output stream as gap if identified as duplicate or unaltered elsewise
115  track = nullptr;
116  break;
117  }
118  }
119  }
120  // remove all gaps between end and last track
121  for (auto it = tracks.end(); it != tracks.begin();)
122  it = (*--it) ? tracks.begin() : tracks.erase(it);
123  // store output
124  StreamTrack& streamTrack = acceptedTracks[channelTrack];
125  streamTrack.reserve(tracks.size());
126  for (int layer = 0; layer < setup_->numLayers(); layer++)
127  accpetedStubs[offsetStub + layer].reserve(tracks.size());
128  for (Track* track : tracks) {
129  if (!track) {
130  streamTrack.emplace_back(FrameTrack());
131  for (int layer = 0; layer < setup_->numLayers(); layer++)
132  accpetedStubs[offsetStub + layer].emplace_back(FrameStub());
133  continue;
134  }
135  streamTrack.push_back(track->frame_);
137  for (Stub* stub : track->stubs_) {
138  hitPattern.set(stub->channel_);
139  accpetedStubs[offsetStub + stub->channel_].push_back(stub->frame_);
140  }
141  for (int layer : hitPattern.ids(false))
142  accpetedStubs[offsetStub + layer].emplace_back(FrameStub());
143  }
144  }
145  }
146 
147  // compares two tracks, returns true if those are considered duplicates
148  bool DR::equalEnough(Track* t0, Track* t1) const {
149  int same(0);
150  for (int layer = 0; layer < setup_->numLayers(); layer++) {
151  auto onLayer = [layer](Stub* stub) { return stub->channel_ == layer; };
152  const auto s0 = find_if(t0->stubs_.begin(), t0->stubs_.end(), onLayer);
153  const auto s1 = find_if(t1->stubs_.begin(), t1->stubs_.end(), onLayer);
154  if (s0 != t0->stubs_.end() && s1 != t1->stubs_.end() && **s0 == **s1)
155  same++;
156  }
157  return same >= channelAssignment_->minIdenticalStubs();
158  }
159 
160 } // namespace trklet
std::vector< std::vector< Track * > > input_
Definition: DR.h:70
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
std::vector< StreamTrack > StreamsTrack
Definition: TTTypes.h:67
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
Class to process and provide run-time constants used by Track Trigger emulators.
Definition: Setup.h:44
std::vector< StreamStub > StreamsStub
Definition: TTTypes.h:66
void consume(const tt::StreamsTrack &streamsTrack, const tt::StreamsStub &streamsStub)
Definition: DR.cc:27
std::vector< FrameStub > StreamStub
Definition: TTTypes.h:63
Class to assign tracklet tracks and stubs to output channel based on their Pt or seed type as well as...
std::vector< FrameTrack > StreamTrack
Definition: TTTypes.h:64
static std::string const input
Definition: EdmProvDump.cc:50
std::pair< TTTrackRef, Frame > FrameTrack
Definition: TTTypes.h:62
int channel_
Definition: DR.h:43
const int region_
Definition: DR.h:64
Definition: TTTypes.h:54
void produce(tt::StreamsStub &accpetedStubs, tt::StreamsTrack &acceptedTracks, tt::StreamsStub &lostStubs, tt::StreamsTrack &lostTracks)
Definition: DR.cc:92
bool equalEnough(Track *t0, Track *t1) const
Definition: DR.cc:148
const tt::Setup * setup_
Definition: DR.h:58
int numLayers() const
Definition: Setup.h:215
Namespace of DDCMS conversion namespace.
const ChannelAssignment * channelAssignment_
Definition: DR.h:62
std::vector< Track > tracks_
Definition: DR.h:66
tt::FrameStub frame_
Definition: DR.h:39
HLT enums.
Class to calculate and provide dataformats used by Track Trigger emulator.
Definition: DataFormats.h:216
std::vector< Stub > stubs_
Definition: DR.h:68
const trackerTFP::DataFormats * dataFormats_
Definition: DR.h:60
const DataFormat & format(Variable v, Process p) const
Definition: DataFormats.h:506