CMS 3D CMS Logo

ProducerKFin.cc
Go to the documentation of this file.
12 
17 
18 #include <string>
19 #include <vector>
20 #include <deque>
21 #include <iterator>
22 #include <cmath>
23 #include <numeric>
24 #include <algorithm>
25 
26 using namespace std;
27 using namespace edm;
28 using namespace tt;
29 
30 namespace trackerTFP {
31 
37  class ProducerKFin : public stream::EDProducer<> {
38  public:
39  explicit ProducerKFin(const ParameterSet&);
40  ~ProducerKFin() override {}
41 
42  private:
43  void beginRun(const Run&, const EventSetup&) override;
44  void produce(Event&, const EventSetup&) override;
45  virtual void endJob() {}
46 
47  // ED input token of TTTracks
49  // ED input token of Stubs
51  // ED output token for stubs
54  // ED output token for tracks
57  // Setup token
59  // DataFormats token
61  // LayerEncoding token
63  // configuration
65  // helper class to store configurations
66  const Setup* setup_ = nullptr;
67  // helper class to extract structured data from tt::Frames
68  const DataFormats* dataFormats_ = nullptr;
69  // helper class to encode layer
70  const LayerEncoding* layerEncoding_ = nullptr;
71  //
73  };
74 
75  ProducerKFin::ProducerKFin(const ParameterSet& iConfig) : iConfig_(iConfig) {
76  const string& labelTTTracks = iConfig.getParameter<string>("LabelZHTout");
77  const string& labelStubs = iConfig.getParameter<string>("LabelZHT");
78  const string& branchAcceptedStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
79  const string& branchAcceptedTracks = iConfig.getParameter<string>("BranchAcceptedTracks");
80  const string& branchLostStubs = iConfig.getParameter<string>("BranchLostStubs");
81  const string& branchLostTracks = iConfig.getParameter<string>("BranchLostTracks");
82  // book in- and output ED products
84  consumes<vector<TTTrack<Ref_Phase2TrackerDigi_>>>(InputTag(labelTTTracks, branchAcceptedTracks));
85  edGetTokenStubs_ = consumes<StreamsStub>(InputTag(labelStubs, branchAcceptedStubs));
86  edPutTokenAcceptedStubs_ = produces<StreamsStub>(branchAcceptedStubs);
87  edPutTokenAcceptedTracks_ = produces<StreamsTrack>(branchAcceptedTracks);
88  edPutTokenLostStubs_ = produces<StreamsStub>(branchLostStubs);
89  edPutTokenLostTracks_ = produces<StreamsTrack>(branchLostTracks);
90  // book ES products
91  esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
92  esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
93  esGetTokenLayerEncoding_ = esConsumes<LayerEncoding, LayerEncodingRcd, Transition::BeginRun>();
94  //
95  enableTruncation_ = iConfig.getParameter<bool>("EnableTruncation");
96  }
97 
98  void ProducerKFin::beginRun(const Run& iRun, const EventSetup& iSetup) {
99  // helper class to store configurations
100  setup_ = &iSetup.getData(esGetTokenSetup_);
102  return;
103  // check process history if desired
104  if (iConfig_.getParameter<bool>("CheckHistory"))
106  // helper class to extract structured data from tt::Frames
108  // helper class to encode layer
110  }
111 
118  // empty KFin products
119  StreamsStub streamAcceptedStubs(dataFormats_->numStreamsStubs(Process::kf));
120  StreamsTrack streamAcceptedTracks(dataFormats_->numStreamsTracks(Process::kf));
123  // read in SFout Product and produce KFin product
125  Handle<StreamsStub> handleStubs;
126  iEvent.getByToken<StreamsStub>(edGetTokenStubs_, handleStubs);
127  const StreamsStub& streams = *handleStubs.product();
129  iEvent.getByToken<vector<TTTrack<Ref_Phase2TrackerDigi_>>>(edGetTokenTTTracks_, handleTTTracks);
130  const vector<TTTrack<Ref_Phase2TrackerDigi_>>& ttTracks = *handleTTTracks.product();
131  for (int region = 0; region < setup_->numRegions(); region++) {
132  // Unpack input SF data into vector
133  int nStubsZHR(0);
134  for (int channel = 0; channel < dataFormats_->numChannel(Process::zht); channel++) {
135  const int index = region * dataFormats_->numChannel(Process::zht) + channel;
136  const StreamStub& stream = streams[index];
137  nStubsZHR += accumulate(stream.begin(), stream.end(), 0, [](int& sum, const FrameStub& frame) {
138  return sum += frame.first.isNonnull() ? 1 : 0;
139  });
140  }
141  vector<StubZHT> stubsZHT;
142  stubsZHT.reserve(nStubsZHR);
143  for (int channel = 0; channel < dataFormats_->numChannel(Process::zht); channel++) {
144  const int index = region * dataFormats_->numChannel(Process::zht) + channel;
145  for (const FrameStub& frame : streams[index])
146  if (frame.first.isNonnull())
147  stubsZHT.emplace_back(frame, dataFormats_);
148  }
149  vector<deque<FrameStub>> dequesStubs(dataFormats_->numChannel(Process::kf) * setup_->numLayers());
150  vector<deque<FrameTrack>> dequesTracks(dataFormats_->numChannel(Process::kf));
151  int i(0);
152  for (const TTTrack<Ref_Phase2TrackerDigi_>& ttTrack : ttTracks) {
153  if ((int)ttTrack.phiSector() / setup_->numSectorsPhi() != region) {
154  i++;
155  continue;
156  }
157  const int sectorPhi = ttTrack.phiSector() % setup_->numSectorsPhi();
158  deque<FrameTrack>& tracks = dequesTracks[sectorPhi];
159  const int binEta = ttTrack.etaSector();
160  const int binZT = dfzT.toUnsigned(dfzT.integer(ttTrack.z0()));
161  const int binCot = dfcot.toUnsigned(dfcot.integer(ttTrack.tanL()));
162  StubZHT* stubZHT = nullptr;
163  vector<int> layerCounts(setup_->numLayers(), 0);
164  for (const TTStubRef& ttStubRef : ttTrack.getStubRefs()) {
165  const int layerId = setup_->layerId(ttStubRef);
166  const int layerIdKF = layerEncoding_->layerIdKF(binEta, binZT, binCot, layerId);
167  if (layerIdKF == -1)
168  continue;
169  if (layerCounts[layerIdKF] == setup_->zhtMaxStubsPerLayer())
170  continue;
171  layerCounts[layerIdKF]++;
172  deque<FrameStub>& stubs = dequesStubs[sectorPhi * setup_->numLayers() + layerIdKF];
173  auto identical = [ttStubRef, ttTrack](const StubZHT& stub) {
174  return (int)ttTrack.trackSeedType() == stub.trackId() && ttStubRef == stub.ttStubRef();
175  };
176  stubZHT = &*find_if(stubsZHT.begin(), stubsZHT.end(), identical);
177  const double inv2R = dfinv2R.floating(stubZHT->inv2R());
178  const double cot = dfcot.floating(stubZHT->cot()) + setup_->sectorCot(binEta);
179  const double dPhi = dfdPhi.digi(setup_->dPhi(ttStubRef, inv2R));
180  const double dZ = dfdZ.digi(setup_->dZ(ttStubRef, cot));
181  stubs.emplace_back(StubKFin(*stubZHT, dPhi, dZ, layerIdKF).frame());
182  }
183  const int size = *max_element(layerCounts.begin(), layerCounts.end());
184  int layerIdKF(0);
185  for (int layerCount : layerCounts) {
186  deque<FrameStub>& stubs = dequesStubs[sectorPhi * setup_->numLayers() + layerIdKF++];
187  const int nGaps = size - layerCount;
188  stubs.insert(stubs.end(), nGaps, FrameStub());
189  }
190  const TTBV& maybePattern = layerEncoding_->maybePattern(binEta, binZT, binCot);
191  const TrackKFin track(*stubZHT, TTTrackRef(handleTTTracks, i++), maybePattern);
192  tracks.emplace_back(track.frame());
193  const int nGaps = size - 1;
194  tracks.insert(tracks.end(), nGaps, FrameTrack());
195  }
196  // transform deques to vectors & emulate truncation
197  for (int channel = 0; channel < dataFormats_->numChannel(Process::kf); channel++) {
198  const int index = region * dataFormats_->numChannel(Process::kf) + channel;
199  deque<FrameTrack>& tracks = dequesTracks[channel];
200  auto limitTracks = next(tracks.begin(), min(setup_->numFrames(), (int)tracks.size()));
201  if (!enableTruncation_)
202  limitTracks = tracks.end();
203  streamAcceptedTracks[index] = StreamTrack(tracks.begin(), limitTracks);
204  streamLostTracks[index] = StreamTrack(limitTracks, tracks.end());
205  for (int l = 0; l < setup_->numLayers(); l++) {
206  deque<FrameStub>& stubs = dequesStubs[channel * setup_->numLayers() + l];
207  auto limitStubs = next(stubs.begin(), min(setup_->numFrames(), (int)stubs.size()));
208  if (!enableTruncation_)
209  limitStubs = stubs.end();
210  streamAcceptedStubs[index * setup_->numLayers() + l] = StreamStub(stubs.begin(), limitStubs);
211  streamLostStubs[index * setup_->numLayers() + l] = StreamStub(limitStubs, stubs.end());
212  }
213  }
214  }
215  }
216  // store products
217  iEvent.emplace(edPutTokenAcceptedStubs_, move(streamAcceptedStubs));
218  iEvent.emplace(edPutTokenAcceptedTracks_, move(streamAcceptedTracks));
219  iEvent.emplace(edPutTokenLostStubs_, move(streamLostStubs));
220  iEvent.emplace(edPutTokenLostTracks_, move(streamLostTracks));
221  }
222 
223 } // namespace trackerTFP
224 
size
Write out results.
int inv2R() const
Definition: DataFormats.h:764
const DataFormats * dataFormats_
Definition: ProducerKFin.cc:68
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double dZ(const TTStubRef &ttStubRef, double cot) const
Definition: Setup.cc:596
ESGetToken< Setup, SetupRcd > esGetTokenSetup_
Definition: ProducerKFin.cc:58
void beginRun(const Run &, const EventSetup &) override
Definition: ProducerKFin.cc:98
std::vector< StreamTrack > StreamsTrack
Definition: TTTypes.h:67
int numSectorsPhi() const
Definition: Setup.h:409
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
ESGetToken< LayerEncoding, LayerEncodingRcd > esGetTokenLayerEncoding_
Definition: ProducerKFin.cc:62
transforms TTTracks into KF input
Definition: ProducerKFin.cc:37
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
std::vector< FrameStub > StreamStub
Definition: TTTypes.h:63
ESGetToken< DataFormats, DataFormatsRcd > esGetTokenDataFormats_
Definition: ProducerKFin.cc:60
T const * product() const
Definition: Handle.h:70
int numFrames() const
Definition: Setup.h:153
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
TTBV maybePattern(int binEta, int binZT, int binCot) const
std::vector< FrameTrack > StreamTrack
Definition: TTTypes.h:64
double dPhi(const TTStubRef &ttStubRef, double inv2R) const
Definition: Setup.cc:576
EDPutTokenT< StreamsStub > edPutTokenLostStubs_
Definition: ProducerKFin.cc:53
int numChannel(Process p) const
Definition: DataFormats.h:498
int integer(double d) const
Definition: DataFormats.h:96
std::pair< TTTrackRef, Frame > FrameTrack
Definition: TTTypes.h:62
int iEvent
Definition: GenABIO.cc:224
Definition: TTTypes.h:54
double floating(int i) const
Definition: DataFormats.h:94
int layerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:507
EDPutTokenT< StreamsTrack > edPutTokenLostTracks_
Definition: ProducerKFin.cc:56
bool configurationSupported() const
Definition: Setup.h:60
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ProcessHistory const & processHistory() const
Definition: Run.cc:115
bool getData(T &iHolder) const
Definition: EventSetup.h:122
int numLayers() const
Definition: Setup.h:215
void checkHistory(const edm::ProcessHistory &processHistory) const
Definition: Setup.cc:238
void produce(Event &, const EventSetup &) override
EDGetTokenT< vector< TTTrack< Ref_Phase2TrackerDigi_ > > > edGetTokenTTTracks_
Definition: ProducerKFin.cc:48
auto const & tracks
cannot be loose
EDPutTokenT< StreamsTrack > edPutTokenAcceptedTracks_
Definition: ProducerKFin.cc:55
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
int numStreamsTracks(Process p) const
Definition: DataFormats.h:504
int zhtMaxStubsPerLayer() const
Definition: Setup.h:473
int toUnsigned(int i) const
Definition: DataFormats.h:102
int numRegions() const
Definition: Setup.h:345
HLT enums.
int numStreamsStubs(Process p) const
Definition: DataFormats.h:502
Class to encode layer ids for Kalman Filter Layers consitent with rough r-z track parameters are coun...
Definition: LayerEncoding.h:18
EDPutTokenT< StreamsStub > edPutTokenAcceptedStubs_
Definition: ProducerKFin.cc:52
const int layerIdKF(int binEta, int binZT, int binCot, int layerId) const
Class to calculate and provide dataformats used by Track Trigger emulator.
Definition: DataFormats.h:216
edm::Ref< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > >, TTTrack< Ref_Phase2TrackerDigi_ > > TTTrackRef
Definition: TTTypes.h:51
double digi(double d) const
Definition: DataFormats.h:98
double sectorCot(int eta) const
Definition: Setup.h:428
EDGetTokenT< StreamsStub > edGetTokenStubs_
Definition: ProducerKFin.cc:50
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
const LayerEncoding * layerEncoding_
Definition: ProducerKFin.cc:70
const DataFormat & format(Variable v, Process p) const
Definition: DataFormats.h:506