CMS 3D CMS Logo

ProducerTBout.cc
Go to the documentation of this file.
12 
16 
17 #include <string>
18 #include <vector>
19 #include <deque>
20 #include <iterator>
21 #include <cmath>
22 #include <numeric>
23 
24 using namespace std;
25 using namespace edm;
26 using namespace trackerTFP;
27 using namespace tt;
28 
29 namespace trklet {
30 
40  class ProducerTBout : public stream::EDProducer<> {
41  public:
42  explicit ProducerTBout(const ParameterSet&);
43  ~ProducerTBout() override {}
44 
45  private:
46  void beginRun(const Run&, const EventSetup&) override;
47  void produce(Event&, const EventSetup&) override;
48  virtual void endJob() {}
49 
50  // ED input token of TTTracks
52  // ED input token of Tracklet tracks
54  // ED input token of Tracklet Stubs
56  // ED output token for stubs
59  // ED output token for tracks
62  // Setup token
64  // DataFormats token
66  // ChannelAssignment token
68  // configuration
70  // helper class to store configurations
71  const Setup* setup_ = nullptr;
72  // helper class to extract structured data from tt::Frames
73  const DataFormats* dataFormats_ = nullptr;
74  // helper class to assign tracks to channel
75  ChannelAssignment* channelAssignment_ = nullptr;
76  //
78  };
79 
80  ProducerTBout::ProducerTBout(const ParameterSet& iConfig) : iConfig_(iConfig) {
81  const InputTag& inputTag = iConfig.getParameter<InputTag>("InputTag");
82  const string& branchAcceptedStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
83  const string& branchAcceptedTracks = iConfig.getParameter<string>("BranchAcceptedTracks");
84  const string& branchLostStubs = iConfig.getParameter<string>("BranchLostStubs");
85  const string& branchLostTracks = iConfig.getParameter<string>("BranchLostTracks");
86  // book in- and output ED products
87  edGetTokenTTTracks_ = consumes<TTTracks>(inputTag);
88  edGetTokenTracks_ = consumes<Streams>(inputTag);
89  edGetTokenStubs_ = consumes<StreamsStub>(inputTag);
90  edPutTokenAcceptedStubs_ = produces<StreamsStub>(branchAcceptedStubs);
91  edPutTokenAcceptedTracks_ = produces<StreamsTrack>(branchAcceptedTracks);
92  edPutTokenLostStubs_ = produces<StreamsStub>(branchLostStubs);
93  edPutTokenLostTracks_ = produces<StreamsTrack>(branchLostTracks);
94  // book ES products
95  esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
96  esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
97  esGetTokenChannelAssignment_ = esConsumes<ChannelAssignment, ChannelAssignmentRcd, Transition::BeginRun>();
98  //
99  enableTruncation_ = iConfig.getParameter<bool>("EnableTruncation");
100  }
101 
102  void ProducerTBout::beginRun(const Run& iRun, const EventSetup& iSetup) {
103  // helper class to store configurations
104  setup_ = &iSetup.getData(esGetTokenSetup_);
106  return;
107  // check process history if desired
108  if (iConfig_.getParameter<bool>("CheckHistory"))
110  // helper class to extract structured data from tt::Frames
112  // helper class to assign tracks to channel
114  }
115 
117  const int numStreamsTracks = setup_->numRegions() * channelAssignment_->numChannelsTrack();
118  const int numStreamsStubs = setup_->numRegions() * channelAssignment_->numChannelsStub();
119  // empty KFin products
120  StreamsStub streamAcceptedStubs(numStreamsStubs);
121  StreamsTrack streamAcceptedTracks(numStreamsTracks);
122  StreamsStub streamLostStubs(numStreamsStubs);
123  StreamsTrack streamLostTracks(numStreamsTracks);
124  // read in hybrid track finding product and produce KFin product
126  // create and structure TTrackRefs in h/w channel
127  vector<deque<TTTrackRef>> ttTrackRefs(numStreamsTracks);
128  Handle<TTTracks> handleTTTracks;
129  iEvent.getByToken<TTTracks>(edGetTokenTTTracks_, handleTTTracks);
130  int channelId(-1);
131  for (int i = 0; i < (int)handleTTTracks->size(); i++) {
132  const TTTrackRef ttTrackRef(handleTTTracks, i);
133  if (channelAssignment_->channelId(ttTrackRef, channelId))
134  ttTrackRefs[channelId].push_back(ttTrackRef);
135  }
136  // get and trunacte tracks
137  Handle<Streams> handleTracks;
138  iEvent.getByToken<Streams>(edGetTokenTracks_, handleTracks);
139  channelId = 0;
140  for (const Stream& streamTrack : *handleTracks) {
141  const int nTracks = accumulate(
142  streamTrack.begin(), streamTrack.end(), 0, [](int sum, const Frame& f) { return sum + (f.any() ? 1 : 0); });
143  StreamTrack& accepted = streamAcceptedTracks[channelId];
144  StreamTrack& lost = streamLostTracks[channelId];
145  auto limit = streamTrack.end();
146  if (enableTruncation_ && (int)streamTrack.size() > setup_->numFrames())
147  limit = next(streamTrack.begin(), setup_->numFrames());
148  accepted.reserve(distance(streamTrack.begin(), limit));
149  lost.reserve(distance(limit, streamTrack.end()));
150  int nFrame(0);
151  const deque<TTTrackRef>& ttTracks = ttTrackRefs[channelId++];
152  if ((int)ttTracks.size() != nTracks) {
153  cms::Exception exception("LogicError.");
154  const int region = channelId / channelAssignment_->numChannelsTrack();
155  const int channel = channelId % channelAssignment_->numChannelsTrack();
156  exception << "Region " << region << " output channel " << channel << " has " << nTracks
157  << " tracks found but created " << ttTracks.size() << " TTTracks.";
158  exception.addContext("trklet::ProducerTBout::produce");
159  throw exception;
160  }
161  auto toFrameTrack = [&nFrame, &ttTracks](const Frame& frame) {
162  if (frame.any())
163  return FrameTrack(ttTracks[nFrame++], frame);
164  return FrameTrack();
165  };
166  transform(streamTrack.begin(), limit, back_inserter(accepted), toFrameTrack);
167  transform(limit, streamTrack.end(), back_inserter(lost), toFrameTrack);
168  }
169  // get and trunacte stubs
170  Handle<StreamsStub> handleStubs;
171  iEvent.getByToken<StreamsStub>(edGetTokenStubs_, handleStubs);
172  const StreamsStub& streamsStub = *handleStubs;
173  // reserve output ed products
174  channelId = 0;
175  for (const StreamStub& streamStub : streamsStub) {
176  auto limit = streamStub.end();
177  if (enableTruncation_ && (int)streamStub.size() > setup_->numFrames())
178  limit = next(streamStub.begin(), setup_->numFrames());
179  streamAcceptedStubs[channelId] = StreamStub(streamStub.begin(), limit);
180  streamLostStubs[channelId++] = StreamStub(limit, streamStub.end());
181  }
182  }
183  // store products
184  iEvent.emplace(edPutTokenAcceptedStubs_, std::move(streamAcceptedStubs));
185  iEvent.emplace(edPutTokenAcceptedTracks_, std::move(streamAcceptedTracks));
186  iEvent.emplace(edPutTokenLostStubs_, std::move(streamLostStubs));
187  iEvent.emplace(edPutTokenLostTracks_, std::move(streamLostTracks));
188  }
189 
190 } // namespace trklet
191 
void produce(Event &, const EventSetup &) override
EDGetTokenT< StreamsStub > edGetTokenStubs_
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< StreamTrack > StreamsTrack
Definition: TTTypes.h:67
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void beginRun(const Run &, const EventSetup &) override
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
EDGetTokenT< TTTracks > edGetTokenTTTracks_
std::vector< FrameStub > StreamStub
Definition: TTTypes.h:63
EDPutTokenT< StreamsTrack > edPutTokenLostTracks_
ESGetToken< DataFormats, DataFormatsRcd > esGetTokenDataFormats_
int numFrames() const
Definition: Setup.h:153
EDPutTokenT< StreamsStub > edPutTokenLostStubs_
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
bool channelId(const TTTrackRef &ttTrackRef, int &channelId)
std::pair< TTTrackRef, Frame > FrameTrack
Definition: TTTypes.h:62
int iEvent
Definition: GenABIO.cc:224
Definition: TTTypes.h:54
ESGetToken< ChannelAssignment, ChannelAssignmentRcd > esGetTokenChannelAssignment_
virtual void endJob()
ChannelAssignment * channelAssignment_
bool configurationSupported() const
Definition: Setup.h:60
double f[11][100]
EDPutTokenT< StreamsTrack > edPutTokenAcceptedTracks_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ProcessHistory const & processHistory() const
Definition: Run.cc:115
void checkHistory(const edm::ProcessHistory &processHistory) const
Definition: Setup.cc:238
std::vector< Frame > Stream
Definition: TTTypes.h:65
EDGetTokenT< Streams > edGetTokenTracks_
const Setup * setup_
ESGetToken< Setup, SetupRcd > esGetTokenSetup_
std::vector< Stream > Streams
Definition: TTTypes.h:68
Transforms TTTracks and Streams from Tracklet pattern reco. into StreamsTrack by adding to the digiti...
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
int numRegions() const
Definition: Setup.h:345
HLT enums.
const DataFormats * dataFormats_
std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > TTTracks
Definition: TTTypes.h:70
EDPutTokenT< StreamsStub > edPutTokenAcceptedStubs_
Class to calculate and provide dataformats used by Track Trigger emulator.
Definition: DataFormats.h:216
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
unsigned transform(const HcalDetId &id, unsigned transformCode)