CMS 3D CMS Logo

L1FPGATrackProducer.cc
Go to the documentation of this file.
1 // Producer by Anders //
3 // and Emmanuele //
4 // july 2012 @ CU //
6 
8 // FRAMEWORK HEADERS
11 //
18 //
22 
24 // DATA FORMATS HEADERS
27 //
33 //
36 
45 //
48 //
56 //
59 //
64 
66 // DETECTOR GEOMETRY HEADERS
77 //
79 
81 // Tracklet emulation
93 
95 // PHYSICS TOOLS
98 
101 
104 
106 // STD HEADERS
107 #include <memory>
108 #include <string>
109 #include <iostream>
110 #include <fstream>
111 
113 // NAMESPACES
114 using namespace edm;
115 using namespace std;
116 using namespace tt;
117 using namespace trklet;
118 
120 // //
121 // CLASS DEFINITION //
122 // //
124 
126 // this class is needed to make a map
127 // between different types of stubs
129 public:
130  bool operator()(const trklet::L1TStub& a, const trklet::L1TStub& b) const {
131  if (a.x() != b.x())
132  return (b.x() > a.x());
133  else if (a.y() != b.y())
134  return (b.y() > a.y());
135  else if (a.z() != b.z())
136  return (a.z() > b.z());
137  else
138  return a.bend() > b.bend();
139  }
140 };
141 
142 class L1FPGATrackProducer : public edm::one::EDProducer<edm::one::WatchRuns> {
143 public:
145  explicit L1FPGATrackProducer(const edm::ParameterSet& iConfig);
146  ~L1FPGATrackProducer() override;
147 
148 private:
149  int eventnum;
150 
153 
155 
161 
164 
166  std::ofstream asciiEventOut_;
167 
168  // settings containing various constants for the tracklet processing
170 
171  // event processor for the tracklet track finding
173 
174  // used to "kill" stubs from a selected area of the detector
177 
178  unsigned int nHelixPar_;
179  bool extended_;
180  bool reduced_;
181 
183  std::unique_ptr<L1TrackQuality> trackQualityModel_;
184 
185  std::map<string, vector<int>> dtclayerdisk;
186 
190 
195 
196  // ED output token for clock and bit accurate tracks
198  // ED output token for clock and bit accurate stubs
200  // ChannelAssignment token
202  // helper class to assign tracks to channel
204 
205  // helper class to store DTC configuration
206  const Setup* setup_;
207  // helper class to store configuration needed by HitPatternHelper
209 
210  // Setup token
216 
219  void beginRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
220  void endRun(edm::Run const&, edm::EventSetup const&) override;
221  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
222 };
223 
225 // CONSTRUCTOR
227  : config(iConfig),
228  readMoreMcTruth_(iConfig.getParameter<bool>("readMoreMcTruth")),
229  MCTruthClusterInputTag(readMoreMcTruth_ ? config.getParameter<edm::InputTag>("MCTruthClusterInputTag")
230  : edm::InputTag()),
231  MCTruthStubInputTag(readMoreMcTruth_ ? config.getParameter<edm::InputTag>("MCTruthStubInputTag")
232  : edm::InputTag()),
233  TrackingParticleInputTag(readMoreMcTruth_ ? iConfig.getParameter<edm::InputTag>("TrackingParticleInputTag")
234  : edm::InputTag()),
235  // book ED products
236  getTokenBS_(consumes<reco::BeamSpot>(config.getParameter<edm::InputTag>("BeamSpotSource"))),
237  getTokenDTC_(consumes<TTDTC>(edm::InputTag(iConfig.getParameter<edm::InputTag>("InputTagTTDTC")))),
238  // book ED output token for clock and bit accurate tracks
239  putTokenTracks_(produces<Streams>("Level1TTTracks")),
240  // book ED output token for clock and bit accurate stubs
241  putTokenStubs_(produces<StreamsStub>("Level1TTTracks")),
242  // book ES products
243  esGetTokenChannelAssignment_(esConsumes<ChannelAssignment, ChannelAssignmentRcd, Transition::BeginRun>()),
244  esGetTokenBfield_(esConsumes<edm::Transition::BeginRun>()),
245  esGetTokenTGeom_(esConsumes()),
246  esGetTokenTTopo_(esConsumes()),
247  esGetToken_(esConsumes<tt::Setup, tt::SetupRcd, edm::Transition::BeginRun>()),
248  esGetTokenHPH_(esConsumes<hph::Setup, hph::SetupRcd, edm::Transition::BeginRun>()) {
249  if (readMoreMcTruth_) {
250  getTokenTTClusterMCTruth_ = consumes<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthClusterInputTag);
251  getTokenTrackingParticle_ = consumes<std::vector<TrackingParticle>>(TrackingParticleInputTag);
252  }
253 
254  produces<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>>("Level1TTTracks").setBranchAlias("Level1TTTracks");
255 
256  asciiEventOutName_ = iConfig.getUntrackedParameter<string>("asciiFileName", "");
257 
258  fitPatternFile = iConfig.getParameter<edm::FileInPath>("fitPatternFile");
259  processingModulesFile = iConfig.getParameter<edm::FileInPath>("processingModulesFile");
260  memoryModulesFile = iConfig.getParameter<edm::FileInPath>("memoryModulesFile");
261  wiresFile = iConfig.getParameter<edm::FileInPath>("wiresFile");
262 
263  failScenario_ = iConfig.getUntrackedParameter<int>("FailScenario", 0);
264 
265  extended_ = iConfig.getParameter<bool>("Extended");
266  reduced_ = iConfig.getParameter<bool>("Reduced");
267  nHelixPar_ = iConfig.getParameter<unsigned int>("Hnpar");
268 
269  if (extended_) {
270  tableTEDFile = iConfig.getParameter<edm::FileInPath>("tableTEDFile");
271  tableTREFile = iConfig.getParameter<edm::FileInPath>("tableTREFile");
272  }
273 
274  // initial ES products
275  channelAssignment_ = nullptr;
276  setup_ = nullptr;
277 
278  // --------------------------------------------------------------------------------
279  // set options in Settings based on inputs from configuration files
280  // --------------------------------------------------------------------------------
281 
285 
290 
291  settings_.setFakefit(iConfig.getParameter<bool>("Fakefit"));
292  settings_.setStoreTrackBuilderOutput(iConfig.getParameter<bool>("StoreTrackBuilderOutput"));
293  settings_.setRemovalType(iConfig.getParameter<string>("RemovalType"));
294  settings_.setDoMultipleMatches(iConfig.getParameter<bool>("DoMultipleMatches"));
295 
296  if (extended_) {
299 
300  //FIXME: The TED and TRE tables are currently disabled by default, so we
301  //need to allow for the additional tracklets that will eventually be
302  //removed by these tables, once they are finalized
304  }
305 
306  eventnum = 0;
307  if (not asciiEventOutName_.empty()) {
308  asciiEventOut_.open(asciiEventOutName_.c_str());
309  }
310 
311  if (settings_.debugTracklet()) {
312  edm::LogVerbatim("Tracklet") << "fit pattern : " << fitPatternFile.fullPath()
313  << "\n process modules : " << processingModulesFile.fullPath()
314  << "\n memory modules : " << memoryModulesFile.fullPath()
315  << "\n wires : " << wiresFile.fullPath();
316  if (extended_) {
317  edm::LogVerbatim("Tracklet") << "table_TED : " << tableTEDFile.fullPath()
318  << "\n table_TRE : " << tableTREFile.fullPath();
319  }
320  }
321 
322  trackQuality_ = iConfig.getParameter<bool>("TrackQuality");
323  if (trackQuality_) {
324  trackQualityModel_ = std::make_unique<L1TrackQuality>(iConfig.getParameter<edm::ParameterSet>("TrackQualityPSet"));
325  }
327  cms::Exception exception("ConfigurationNotSupported.");
328  exception.addContext("L1FPGATrackProducer::produce");
330  exception << "Storing of TrackBuilder output does not support doMultipleMatches.";
331  if (!settings_.removalType().empty())
332  exception << "Storing of TrackBuilder output does not support duplicate removal.";
333  throw exception;
334  }
335 }
336 
338 // DESTRUCTOR
340  if (asciiEventOut_.is_open()) {
341  asciiEventOut_.close();
342  }
343 }
344 
346 //
348 
350 // BEGIN JOB
353  // GET MAGNETIC FIELD //
354  const MagneticField* theMagneticField = &iSetup.getData(esGetTokenBfield_);
355  double mMagneticFieldStrength = theMagneticField->inTesla(GlobalPoint(0, 0, 0)).z();
356  settings_.setBfield(mMagneticFieldStrength);
357 
358  setup_ = &iSetup.getData(esGetToken_);
359 
361 
362  setupHPH_ = &iSetup.getData(esGetTokenHPH_);
363  // Tracklet pattern reco output channel info.
365  // initialize the tracklet event processing (this sets all the processing & memory modules, wiring, etc)
367 }
368 
370 // PRODUCE
372  typedef std::map<trklet::L1TStub,
375  stubMapType;
376  typedef std::map<unsigned int,
378  stubIndexMapType;
380  TTClusterRef;
381 
383  auto L1TkTracksForOutput = std::make_unique<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>>();
384 
385  stubMapType stubMap;
386  stubIndexMapType stubIndexMap;
387 
389  // GET BS //
390  edm::Handle<reco::BeamSpot> beamSpotHandle;
391  iEvent.getByToken(getTokenBS_, beamSpotHandle);
392  math::XYZPoint bsPosition = beamSpotHandle->position();
393 
394  eventnum++;
396  ev.setEventNum(eventnum);
397  ev.setIP(bsPosition.x(), bsPosition.y());
398 
399  // tracking particles
400  edm::Handle<std::vector<TrackingParticle>> TrackingParticleHandle;
401  if (readMoreMcTruth_)
402  iEvent.getByToken(getTokenTrackingParticle_, TrackingParticleHandle);
403 
404  // tracker topology
405  const TrackerTopology* const tTopo = &iSetup.getData(esGetTokenTTopo_);
406  const TrackerGeometry* const theTrackerGeom = &iSetup.getData(esGetTokenTGeom_);
407 
408  // check killing stubs for detector degradation studies
409  // if failType = 0, StubKiller does not kill any modules
410  int failType = 0;
411  if (failScenario_ < 0 || failScenario_ > 9) {
412  edm::LogVerbatim("Tracklet") << "Invalid fail scenario! Ignoring input";
413  } else
414  failType = failScenario_;
415 
416  stubKiller_ = new StubKiller();
417  stubKiller_->initialise(failType, tTopo, theTrackerGeom);
418 
420  // GET THE PRIMITIVES //
421  edm::Handle<TTDTC> handleDTC;
422  iEvent.getByToken<TTDTC>(getTokenDTC_, handleDTC);
423 
424  // must be defined for code to compile, even if it's not used unless readMoreMcTruth_ is true
425  map<edm::Ptr<TrackingParticle>, int> translateTP;
426 
427  // MC truth association maps
429  if (readMoreMcTruth_) {
430  iEvent.getByToken(getTokenTTClusterMCTruth_, MCTruthTTClusterHandle);
431 
434 
435  int ntps = 1; //count from 1 ; 0 will mean invalid
436 
437  int this_tp = 0;
438  if (readMoreMcTruth_) {
439  for (const auto& iterTP : *TrackingParticleHandle) {
440  edm::Ptr<TrackingParticle> tp_ptr(TrackingParticleHandle, this_tp);
441  this_tp++;
442 
443  // only keep TPs producing a cluster
444  if (MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).empty())
445  continue;
446 
447  if (iterTP.g4Tracks().empty()) {
448  continue;
449  }
450 
451  int sim_eventid = iterTP.g4Tracks().at(0).eventId().event();
452  int sim_type = iterTP.pdgId();
453  float sim_pt = iterTP.pt();
454  float sim_eta = iterTP.eta();
455  float sim_phi = iterTP.phi();
456 
457  float vx = iterTP.vertex().x();
458  float vy = iterTP.vertex().y();
459  float vz = iterTP.vertex().z();
460 
461  if (sim_pt < 1.0 || std::abs(vz) > 100.0 || hypot(vx, vy) > 50.0)
462  continue;
463 
464  ev.addL1SimTrack(sim_eventid, ntps, sim_type, sim_pt, sim_eta, sim_phi, vx, vy, vz);
465 
466  translateTP[tp_ptr] = ntps;
467  ntps++;
468 
469  } //end loop over TPs
470  }
471 
472  } // end if (readMoreMcTruth_)
473 
477 
478  // Process stubs in each region and channel within that tracking region
479  unsigned int theStubIndex = 0;
480  for (const int& region : handleDTC->tfpRegions()) {
481  for (const int& channel : handleDTC->tfpChannels()) {
482  // Get the DTC name & ID from the channel
483  unsigned int atcaSlot = channel % 12;
484  string dtcname = settings_.slotToDTCname(atcaSlot);
485  if (channel % 24 >= 12)
486  dtcname = "neg" + dtcname;
487  dtcname += (channel < 24) ? "_A" : "_B"; // which detector region
488  int dtcId = setup_->dtcId(region, channel);
489 
490  // Get the stubs from the DTC
491  const tt::StreamStub& streamFromDTC{handleDTC->stream(region, channel)};
492 
493  // Prepare the DTC stubs for the IR
494  for (size_t stubIndex = 0; stubIndex < streamFromDTC.size(); ++stubIndex) {
495  const tt::FrameStub& stub{streamFromDTC[stubIndex]};
496  const TTStubRef& stubRef = stub.first;
497 
498  if (stubRef.isNull())
499  continue;
500 
501  const GlobalPoint& ttPos = setup_->stubPos(stubRef);
502 
503  //Get the 2 bits for the layercode
504  string layerword = stub.second.to_string().substr(61, 2);
505  unsigned int layercode = 2 * (layerword[0] - '0') + layerword[1] - '0';
506  assert(layercode < 4);
507 
508  //translation from the two bit layercode to the layer/disk number of each of the
509  //12 channels (dtcs)
510  // FIX: take this from DTC cabling map.
511  static const int layerdisktab[12][4] = {{0, 6, 8, 10},
512  {0, 7, 9, -1},
513  {1, 7, -1, -1},
514  {6, 8, 10, -1},
515  {2, 7, -1, -1},
516  {2, 9, -1, -1},
517  {3, 4, -1, -1},
518  {4, -1, -1, -1},
519  {5, -1, -1, -1},
520  {5, 8, -1, -1},
521  {6, 9, -1, -1},
522  {7, 10, -1, -1}};
523 
524  int layerdisk = layerdisktab[channel % 12][layercode];
525  assert(layerdisk != -1);
526 
527  //Get the 36 bit word - skip the lowest 3 buts (status and layer code)
528  constexpr int DTCLinkWordSize = 64;
529  constexpr int StubWordSize = 36;
530  constexpr int LayerandStatusCodeSize = 3;
531  string stubword =
532  stub.second.to_string().substr(DTCLinkWordSize - StubWordSize - LayerandStatusCodeSize, StubWordSize);
533  string stubwordhex = "";
534 
535  //Loop over the 9 words in the 36 bit stub word
536  for (unsigned int i = 0; i < 9; i++) {
537  bitset<4> bits(stubword.substr(i * 4, 4));
538  ulong val = bits.to_ulong();
539  stubwordhex += ((val < 10) ? ('0' + val) : ('A' + val - 10));
540  }
541 
544  innerCluster = stub.first->clusterRef(0);
546  outerCluster = stub.first->clusterRef(1);
547 
548  // -----------------------------------------------------
549  // check module orientation, if flipped, need to store that information for track fit
550  // -----------------------------------------------------
551 
552  const DetId innerDetId = innerCluster->getDetId();
553  const GeomDetUnit* det_inner = theTrackerGeom->idToDetUnit(innerDetId);
554  const auto* theGeomDet_inner = dynamic_cast<const PixelGeomDetUnit*>(det_inner);
555  const PixelTopology* topol_inner = dynamic_cast<const PixelTopology*>(&(theGeomDet_inner->specificTopology()));
556 
557  MeasurementPoint coords_inner = innerCluster->findAverageLocalCoordinatesCentered();
558  LocalPoint clustlp_inner = topol_inner->localPosition(coords_inner);
559  GlobalPoint posStub_inner = theGeomDet_inner->surface().toGlobal(clustlp_inner);
560 
561  const DetId outerDetId = outerCluster->getDetId();
562  const GeomDetUnit* det_outer = theTrackerGeom->idToDetUnit(outerDetId);
563  const auto* theGeomDet_outer = dynamic_cast<const PixelGeomDetUnit*>(det_outer);
564  const PixelTopology* topol_outer = dynamic_cast<const PixelTopology*>(&(theGeomDet_outer->specificTopology()));
565 
566  MeasurementPoint coords_outer = outerCluster->findAverageLocalCoordinatesCentered();
567  LocalPoint clustlp_outer = topol_outer->localPosition(coords_outer);
568  GlobalPoint posStub_outer = theGeomDet_outer->surface().toGlobal(clustlp_outer);
569 
570  bool isFlipped = (posStub_outer.mag() < posStub_inner.mag());
571 
572  vector<int> assocTPs;
573 
574  for (unsigned int iClus = 0; iClus <= 1; iClus++) { // Loop over both clusters that make up stub.
575 
576  const TTClusterRef& ttClusterRef = stubRef->clusterRef(iClus);
577 
578  // Now identify all TP's contributing to either cluster in stub.
579  if (readMoreMcTruth_) {
580  vector<edm::Ptr<TrackingParticle>> vecTpPtr =
581  MCTruthTTClusterHandle->findTrackingParticlePtrs(ttClusterRef);
582 
583  for (const edm::Ptr<TrackingParticle>& tpPtr : vecTpPtr) {
584  if (translateTP.find(tpPtr) != translateTP.end()) {
585  if (iClus == 0) {
586  assocTPs.push_back(translateTP.at(tpPtr));
587  } else {
588  assocTPs.push_back(-translateTP.at(tpPtr));
589  }
590  // N.B. Since not all tracking particles are stored in InputData::vTPs_, sometimes no match will be found.
591  } else {
592  assocTPs.push_back(0);
593  }
594  }
595  }
596  }
597 
598  double stubbend = stubRef->bendFE(); //stubRef->rawBend()
599  if (ttPos.z() < -120) {
600  stubbend = -stubbend;
601  }
602 
603  bool barrel = (layerdisk < N_LAYER);
604  // See https://github.com/cms-sw/cmssw/tree/master/Geometry/TrackerNumberingBuilder
605  enum TypeBarrel { nonBarrel = 0, tiltedMinus = 1, tiltedPlus = 2, flat = 3 };
606  const TypeBarrel type = static_cast<TypeBarrel>(tTopo->tobSide(innerDetId));
607  bool tiltedBarrel = barrel && (type == tiltedMinus || type == tiltedPlus);
608  unsigned int tiltedRingId = 0;
609  // Tilted module ring no. (Increasing 1 to 12 as |z| increases).
610  if (tiltedBarrel) {
611  tiltedRingId = tTopo->tobRod(innerDetId);
612  if (type == tiltedMinus) {
613  unsigned int layp1 = 1 + layerdisk; // Setup counts from 1
614  unsigned int nTilted = setup_->numTiltedLayerRing(layp1);
615  tiltedRingId = 1 + nTilted - tiltedRingId;
616  }
617  }
618  // Endcap module ring number (1-15) in endcap disks.
619  unsigned int endcapRingId = barrel ? 0 : tTopo->tidRing(innerDetId);
620 
621  const unsigned int intDetId = innerDetId.rawId();
622 
623  // check killing stubs for detector degredation studies
624  const TTStub<Ref_Phase2TrackerDigi_>* theStub = &(*stubRef);
625  bool killThisStub = stubKiller_->killStub(theStub);
626  if (!killThisStub) {
627  ev.addStub(dtcname,
628  region,
629  layerdisk,
630  stubwordhex,
631  setup_->psModule(dtcId),
632  isFlipped,
633  tiltedBarrel,
634  tiltedRingId,
635  endcapRingId,
636  intDetId,
637  ttPos.x(),
638  ttPos.y(),
639  ttPos.z(),
640  stubbend,
641  stubRef->innerClusterPosition(),
642  assocTPs,
643  theStubIndex);
644 
645  const trklet::L1TStub& lastStub = ev.lastStub();
646  stubMap[lastStub] = stubRef;
647  stubIndexMap[lastStub.uniqueIndex()] = stub.first;
648  theStubIndex++;
649  }
650  }
651  }
652  }
653 
655  // NOW RUN THE L1 tracking
656 
657  if (!asciiEventOutName_.empty()) {
658  ev.write(asciiEventOut_);
659  }
660 
661  const std::vector<trklet::Track>& tracks = eventProcessor.tracks();
662 
663  // max number of projection layers
664  const unsigned int maxNumProjectionLayers = channelAssignment_->maxNumProjectionLayers();
665  // number of track channels
666  const unsigned int numStreamsTrack = N_SECTOR * channelAssignment_->numChannelsTrack();
667  // number of stub channels
668  const unsigned int numStreamsStub = N_SECTOR * channelAssignment_->numChannelsStub();
669  // number of seeding layers
670  const unsigned int numSeedingLayers = channelAssignment_->numSeedingLayers();
671  // max number of stub channel per track
672  const unsigned int numStubChannel = maxNumProjectionLayers + numSeedingLayers;
673  // number of stub channels if all seed types streams padded to have same number of stub channels (for coding simplicity)
674  const unsigned int numStreamsStubRaw = numStreamsTrack * numStubChannel;
675 
676  // Streams formatted to allow this code to run outside CMSSW.
677  vector<vector<string>> streamsTrackRaw(numStreamsTrack);
678  vector<vector<StubStreamData>> streamsStubRaw(numStreamsStubRaw);
679 
680  // this performs the actual tracklet event processing
681  eventProcessor.event(ev, streamsTrackRaw, streamsStubRaw);
682 
683  for (const auto& track : tracks) {
684  if (track.duplicate())
685  continue;
686 
687  // this is where we create the TTTrack object
688  double tmp_rinv = track.rinv(settings_);
689  double tmp_phi = track.phi0(settings_);
690  double tmp_tanL = track.tanL(settings_);
691  double tmp_z0 = track.z0(settings_);
692  double tmp_d0 = track.d0(settings_);
693  double tmp_chi2rphi = track.chisqrphi();
694  double tmp_chi2rz = track.chisqrz();
695  unsigned int tmp_hit = track.hitpattern();
696 
697  TTTrack<Ref_Phase2TrackerDigi_> aTrack(tmp_rinv,
698  tmp_phi,
699  tmp_tanL,
700  tmp_z0,
701  tmp_d0,
702  tmp_chi2rphi,
703  tmp_chi2rz,
704  0,
705  0,
706  0,
707  tmp_hit,
709  settings_.bfield());
710 
711  unsigned int trksector = track.sector();
712  unsigned int trkseed = (unsigned int)abs(track.seed());
713 
714  aTrack.setPhiSector(trksector);
715  aTrack.setTrackSeedType(trkseed);
716 
717  const vector<trklet::L1TStub>& stubptrs = track.stubs();
718  vector<trklet::L1TStub> stubs;
719 
720  stubs.reserve(stubptrs.size());
721  for (const auto& stubptr : stubptrs) {
722  stubs.push_back(stubptr);
723  }
724 
725  int countStubs = 0;
726  stubMapType::const_iterator it;
727  stubIndexMapType::const_iterator itIndex;
728  for (const auto& itstubs : stubs) {
729  itIndex = stubIndexMap.find(itstubs.uniqueIndex());
730  if (itIndex != stubIndexMap.end()) {
731  aTrack.addStubRef(itIndex->second);
732  countStubs = countStubs + 1;
733  } else {
734  // could not find stub in stub map
735  }
736  }
737 
738  // pt consistency
739  aTrack.setStubPtConsistency(
740  StubPtConsistency::getConsistency(aTrack, theTrackerGeom, tTopo, settings_.bfield(), settings_.nHelixPar()));
741 
742  // set TTTrack word
743  aTrack.setTrackWordBits();
744 
745  if (trackQuality_) {
746  trackQualityModel_->setL1TrackQuality(aTrack);
747  }
748 
749  // hph::HitPatternHelper hph(setupHPH_, tmp_hit, tmp_tanL, tmp_z0);
750  // if (trackQuality_) {
751  // trackQualityModel_->setBonusFeatures(hph.bonusFeatures());
752  // }
753 
754  // test track word
755  //aTrack.testTrackWordBits();
756 
757  L1TkTracksForOutput->push_back(aTrack);
758  }
759 
760  iEvent.put(std::move(L1TkTracksForOutput), "Level1TTTracks");
761 
762  // produce clock and bit accurate stream output tracks and stubs.
763  // from end of tracklet pattern recognition.
764  // Convertion here is from stream format that allows this code to run
765  // outside CMSSW to the EDProduct one.
766  Streams streamsTrack(numStreamsTrack);
767  StreamsStub streamsStub(numStreamsStub);
768 
769  for (unsigned int chanTrk = 0; chanTrk < numStreamsTrack; chanTrk++) {
770  for (unsigned int itk = 0; itk < streamsTrackRaw[chanTrk].size(); itk++) {
771  std::string bitsTrk = streamsTrackRaw[chanTrk][itk];
772  int iSeed = chanTrk % channelAssignment_->numChannelsTrack(); // seed type
773  streamsTrack[chanTrk].emplace_back(bitsTrk);
774 
775  const unsigned int chanStubOffsetIn = chanTrk * numStubChannel;
776  const unsigned int chanStubOffsetOut = channelAssignment_->offsetStub(chanTrk);
777  const unsigned int numProjLayers = channelAssignment_->numProjectionLayers(iSeed);
778  TTBV hitMap(0, numProjLayers + numSeedingLayers);
779  // remove padding from stub stream
780  for (unsigned int iproj = 0; iproj < numStubChannel; iproj++) {
781  // FW current has one (perhaps invalid) stub per layer per track.
782  const StubStreamData& stubdata = streamsStubRaw[chanStubOffsetIn + iproj][itk];
783  const L1TStub& stub = stubdata.stub();
784  if (!stubdata.valid())
785  continue;
786  const TTStubRef& ttStubRef = stubMap[stub];
787  const int seedType = stubdata.iSeed();
788  const int layerId = setup_->layerId(ttStubRef);
789  const int channelId = channelAssignment_->channelId(seedType, layerId);
790  hitMap.set(channelId);
791  streamsStub[chanStubOffsetOut + channelId].emplace_back(ttStubRef, stubdata.dataBits());
792  }
793  for (int layerId : hitMap.ids(false)) { // invalid stubs
794  streamsStub[chanStubOffsetOut + layerId].emplace_back(tt::FrameStub());
795  }
796  }
797  }
798 
799  iEvent.emplace(putTokenTracks_, std::move(streamsTrack));
800  iEvent.emplace(putTokenStubs_, std::move(streamsStub));
801 
802 }
803 
804 // ///////////////////////////
805 // // DEFINE THIS AS A PLUG-IN
Log< level::Info, true > LogVerbatim
void setMemoryModulesFile(std::string memoryModulesFileName)
Definition: Settings.h:86
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::InputTag MCTruthStubInputTag
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
Definition: Matriplex.h:436
unsigned int tobSide(const DetId &id) const
void setStoreTrackBuilderOutput(bool storeTrackBuilderOutput)
Definition: Settings.h:258
edm::FileInPath tableTREFile
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
trklet::Settings settings_
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
const Point & position() const
position
Definition: BeamSpot.h:59
void init(Settings const &theSettings, const tt::Setup *setup=nullptr)
std::string fullPath() const
Definition: FileInPath.cc:161
void setFitPatternFile(std::string fitPatternFileName)
Definition: Settings.h:82
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
T z() const
Definition: PV3DBase.h:61
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
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
std::string slotToDTCname(unsigned int slot) const
Definition: Settings.h:462
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
const edm::EDGetTokenT< reco::BeamSpot > getTokenBS_
edm::InputTag MCTruthClusterInputTag
void setReduced(bool reduced)
Definition: Settings.h:273
trklet::TrackletEventProcessor eventProcessor
int channelId(const TTTrackRef &ttTrackRef) const
Definition: config.py:1
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
Class to assign tracklet tracks and stubs to output channel based on their Pt or seed type as well as...
const std::vector< int > & tfpChannels() const
Definition: TTDTC.h:26
assert(be >=bs)
const hph::Setup * setupHPH_
int offsetStub(int channelTrack) const
T getUntrackedParameter(std::string const &, T const &) const
edm::FileInPath tableTEDFile
void setRemovalType(std::string removalType)
Definition: Settings.h:261
edm::EDGetTokenT< std::vector< TrackingParticle > > getTokenTrackingParticle_
T x() const
Definition: PV3DBase.h:59
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > esGetTokenTTopo_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > esGetTokenTGeom_
T y() const
Definition: PV3DBase.h:60
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > esGetTokenBfield_
int iEvent
Definition: GenABIO.cc:224
Definition: TTTypes.h:54
const edm::ESGetToken< hph::Setup, hph::SetupRcd > esGetTokenHPH_
GlobalPoint stubPos(const TTStubRef &ttStubRef) const
Definition: Setup.cc:824
std::vector< int > ids(bool b=true, bool singed=false) const
Definition: TTBV.h:334
TTClusterRefT< Ref_Phase2TrackerDigi_ > TTClusterRef
Definition: TTTypes.h:45
double bfield() const
Definition: Settings.h:277
int layerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:511
const std::string & dataBits() const
void initialise(unsigned int killScenario, const TrackerTopology *trackerTopology, const TrackerGeometry *trackerGeometry)
Definition: StubKiller.cc:20
edm::FileInPath processingModulesFile
T mag() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector< int > & tfpRegions() const
Definition: TTDTC.h:24
Transition
Definition: Transition.h:12
const ChannelAssignment * channelAssignment_
bool killStub(const TTStub< Ref_Phase2TrackerDigi_ > *stub, const std::vector< int > layersToKill, const double minPhiToKill, const double maxPhiToKill, const double minZToKill, const double maxZToKill, const double minRToKill, const double maxRToKill, const double fractionOfStubsToKillInLayers, const double fractionOfStubsToKillEverywhere)
Definition: StubKiller.cc:212
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string removalType() const
Definition: Settings.h:251
const edm::ESGetToken< tt::Setup, tt::SetupRcd > esGetToken_
bool doMultipleMatches() const
Definition: Settings.h:254
const edm::EDPutTokenT< Streams > putTokenTracks_
void setFakefit(bool fakefit)
Definition: Settings.h:256
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
bool isNull() const
Checks for null.
Definition: Ref.h:235
TTBV & set()
Definition: TTBV.h:187
const std::vector< Track > & tracks() const
bool operator()(const trklet::L1TStub &a, const trklet::L1TStub &b) const
edm::InputTag TrackingParticleInputTag
bool debugTracklet() const
Definition: Settings.h:194
constexpr unsigned int N_SECTOR
Definition: Settings.h:23
void endRun(edm::Run const &, edm::EventSetup const &) override
int numProjectionLayers(int seedType) const
Definition: DetId.h:17
const L1TStub & stub() const
bool storeTrackBuilderOutput() const
Definition: Settings.h:257
bool psModule(int dtcId) const
Definition: Setup.cc:322
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
void setProcessingModulesFile(std::string processingModulesFileName)
Definition: Settings.h:83
unsigned int nHelixPar() const
Definition: Settings.h:265
L1FPGATrackProducer(const edm::ParameterSet &iConfig)
Constructor/destructor.
const edm::EDGetTokenT< TTDTC > getTokenDTC_
double b
Definition: hdecay.h:120
Class to store hardware like structured TTStub Collection used by Track Trigger emulators.
Definition: TTDTC.h:17
std::vector< Stream > Streams
Definition: TTTypes.h:68
unsigned int tobRod(const DetId &id) const
void setDoMultipleMatches(bool doMultipleMatches)
Definition: Settings.h:262
edm::FileInPath memoryModulesFile
std::map< string, vector< int > > dtclayerdisk
const edm::EDPutTokenT< StreamsStub > putTokenStubs_
double numTiltedLayerRing(int layerId) const
Definition: Setup.h:313
fixed size matrix
HLT enums.
double a
Definition: hdecay.h:121
std::unique_ptr< L1TrackQuality > trackQualityModel_
edm::FileInPath fitPatternFile
File path for configuration files.
edm::EDGetTokenT< TTClusterAssociationMap< Ref_Phase2TrackerDigi_ > > getTokenTTClusterMCTruth_
void setNbitstrackletindex(unsigned int nbitstrackletindex)
Definition: Settings.h:310
void setNHelixPar(unsigned int nHelixPar)
Definition: Settings.h:266
unsigned int tidRing(const DetId &id) const
void setWiresFile(std::string wiresFileName)
Definition: Settings.h:87
void setBfield(double bfield)
Definition: Settings.h:278
void setTableTREFile(std::string tableTREFileName)
Definition: Settings.h:89
void passSetup(const tt::Setup *setup)
Definition: Settings.h:71
edm::ParameterSet config
Containers of parameters passed by python configuration file.
int dtcId(int tklId) const
Definition: Setup.cc:294
void setTableTEDFile(std::string tableTEDFileName)
Definition: Settings.h:88
void event(SLHCEvent &ev, std::vector< std::vector< std::string >> &streamsTrackRaw, std::vector< std::vector< StubStreamData >> &streamsStubRaw)
const tt::StreamStub & stream(int tfpRegion, int tfpChannel) const
Definition: TTDTC.cc:48
def move(src, dest)
Definition: eostools.py:511
void setExtended(bool extended)
Definition: Settings.h:269
Definition: Run.h:45
unsigned int uniqueIndex() const
Definition: L1TStub.h:92
float getConsistency(TTTrack< Ref_Phase2TrackerDigi_ > aTrack, const TrackerGeometry *theTrackerGeom, const TrackerTopology *tTopo, double mMagneticFieldStrength, int nPar)
constexpr int N_LAYER
Definition: Settings.h:25
const ESGetToken< ChannelAssignment, ChannelAssignmentRcd > esGetTokenChannelAssignment_