CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DTTrigPhase2Prod.cc
Go to the documentation of this file.
10 
17 
21 
24 
48 
62 
63 // DT trigger GeomUtils
65 
66 //RPC TP
71 
72 #include <fstream>
73 #include <iostream>
74 #include <queue>
75 #include <cmath>
76 
77 using namespace edm;
78 using namespace std;
79 using namespace cmsdt;
80 
82  typedef std::map<DTChamberId, DTDigiCollection, std::less<DTChamberId>> DTDigiMap;
83  typedef DTDigiMap::iterator DTDigiMap_iterator;
84  typedef DTDigiMap::const_iterator DTDigiMap_const_iterator;
85 
86 public:
89 
91  ~DTTrigPhase2Prod() override;
92 
94  void beginRun(edm::Run const& iRun, const edm::EventSetup& iEventSetup) override;
95 
97  void produce(edm::Event& iEvent, const edm::EventSetup& iEventSetup) override;
98 
100  void endRun(edm::Run const& iRun, const edm::EventSetup& iEventSetup) override;
101 
102  // Methods
103  int rango(const metaPrimitive& mp) const;
104  bool outer(const metaPrimitive& mp) const;
105  bool inner(const metaPrimitive& mp) const;
106  void printmP(const std::string& ss, const metaPrimitive& mP) const;
107  void printmP(const metaPrimitive& mP) const;
108  void printmPC(const std::string& ss, const metaPrimitive& mP) const;
109  void printmPC(const metaPrimitive& mP) const;
110  bool hasPosRF(int wh, int sec) const;
111 
112  // Getter-methods
113  MP_QUALITY getMinimumQuality(void);
114 
115  // Setter-methods
116  void setChiSquareThreshold(float ch2Thr);
117  void setMinimumQuality(MP_QUALITY q);
118 
119  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
120 
121  // data-members
124  std::vector<std::pair<int, MuonPath>> primitives_;
125 
126 private:
127  // Trigger Configuration Manager CCB validity flag
129 
130  // BX offset used to correct DTTPG output
132 
133  // Debug Flag
134  bool debug_;
135  bool dump_;
139  int co_option_; //coincidence
142 
151 
152  // ParameterSet
155 
156  // Grouping attributes and methods
157  int algo_; // Grouping code
158  std::unique_ptr<MotherGrouping> grouping_obj_;
159  std::unique_ptr<MuonPathAnalyzer> mpathanalyzer_;
160  std::unique_ptr<LateralityProvider> latprovider_;
161  std::unique_ptr<MPFilter> mpathqualityenhancer_;
162  std::unique_ptr<MPFilter> mpathqualityenhancerbayes_;
163  std::unique_ptr<MPFilter> mpathredundantfilter_;
164  std::unique_ptr<MPFilter> mpathhitsfilter_;
165  std::unique_ptr<MuonPathAnalyzer> mpathassociator_;
166  std::unique_ptr<MuonPathConfirmator> mpathconfirmator_;
167  std::unique_ptr<MPFilter> mpathcorfilter_;
168  std::unique_ptr<MPFilter> mpathcoifilter_;
169  std::shared_ptr<GlobalCoordsObtainer> globalcoordsobtainer_;
170 
171  // Buffering
175  std::vector<DTDigiCollection*> distribDigis(std::queue<std::pair<DTLayerId, DTDigi>>& inQ);
176  void processDigi(std::queue<std::pair<DTLayerId, DTDigi>>& inQ,
177  std::vector<std::queue<std::pair<DTLayerId, DTDigi>>*>& vec);
178 
179  // RPC
180  std::unique_ptr<RPCIntegrator> rpc_integrator_;
181  bool useRPC_;
182 
183  void assignIndex(std::vector<metaPrimitive>& inMPaths);
184  void assignIndexPerBX(std::vector<metaPrimitive>& inMPaths);
185  int assignQualityOrder(const metaPrimitive& mP) const;
186 
187  const std::unordered_map<int, int> qmap_;
188 };
189 
190 namespace {
191  struct {
192  bool operator()(std::pair<DTLayerId, DTDigi> a, std::pair<DTLayerId, DTDigi> b) const {
193  return (a.second.time() < b.second.time());
194  }
195  } const DigiTimeOrdering;
196 } // namespace
197 
199  : qmap_({{8, 8}, {7, 7}, {6, 6}, {4, 4}, {3, 3}, {2, 2}, {1, 1}}) {
200  produces<L1Phase2MuDTPhContainer>();
201  produces<L1Phase2MuDTThContainer>();
202  produces<L1Phase2MuDTExtPhContainer>();
203  produces<L1Phase2MuDTExtThContainer>();
204 
205  debug_ = pset.getUntrackedParameter<bool>("debug");
206  dump_ = pset.getUntrackedParameter<bool>("dump");
207 
208  scenario_ = pset.getParameter<int>("scenario");
209 
210  df_extended_ = pset.getParameter<int>("df_extended");
211  co_option_ = pset.getParameter<int>("co_option");
212  co_quality_ = pset.getParameter<int>("co_quality");
213  max_index_ = pset.getParameter<int>("max_primitives") - 1;
214 
215  dtDigisToken_ = consumes<DTDigiCollection>(pset.getParameter<edm::InputTag>("digiTag"));
216 
217  rpcRecHitsLabel_ = consumes<RPCRecHitCollection>(pset.getParameter<edm::InputTag>("rpcRecHits"));
218  useRPC_ = pset.getParameter<bool>("useRPC");
219 
220  // Choosing grouping scheme:
221  algo_ = pset.getParameter<int>("algo");
222 
223  // shortcuts
224 
225  output_mixer_ = pset.getParameter<bool>("output_mixer");
226  output_latpredictor_ = pset.getParameter<bool>("output_latpredictor");
227  output_slfitter_ = pset.getParameter<bool>("output_slfitter");
228  output_slfilter_ = pset.getParameter<bool>("output_slfilter");
229  output_confirmed_ = pset.getParameter<bool>("output_confirmed");
230  output_matcher_ = pset.getParameter<bool>("output_matcher");
231  allow_confirmation_ = pset.getParameter<bool>("allow_confirmation");
232 
233  edm::ConsumesCollector consumesColl(consumesCollector());
234  globalcoordsobtainer_ = std::make_shared<GlobalCoordsObtainer>(pset);
235  globalcoordsobtainer_->generate_luts();
236 
237  if (algo_ == PseudoBayes) {
238  grouping_obj_ =
239  std::make_unique<PseudoBayesGrouping>(pset.getParameter<edm::ParameterSet>("PseudoBayesPattern"), consumesColl);
240  } else if (algo_ == HoughTrans) {
241  grouping_obj_ =
242  std::make_unique<HoughGrouping>(pset.getParameter<edm::ParameterSet>("HoughGrouping"), consumesColl);
243  } else {
244  grouping_obj_ = std::make_unique<TrapezoidalGrouping>(pset, consumesColl);
245  }
246 
247  if (algo_ == Standard) {
248  if (debug_)
249  LogDebug("DTTrigPhase2Prod") << "DTp2:constructor: JM analyzer";
250  mpathanalyzer_ = std::make_unique<MuonPathSLFitter>(pset, consumesColl, globalcoordsobtainer_);
251  latprovider_ = std::make_unique<LateralityCoarsedProvider>(pset, consumesColl);
252  } else {
253  if (debug_)
254  LogDebug("DTTrigPhase2Prod") << "DTp2:constructor: Full chamber analyzer";
255  mpathanalyzer_ = std::make_unique<MuonPathAnalyzerInChamber>(pset, consumesColl, globalcoordsobtainer_);
256  }
257 
258  // Getting buffer option
259  activateBuffer_ = pset.getParameter<bool>("activateBuffer");
260  superCellhalfspacewidth_ = pset.getParameter<int>("superCellspacewidth") / 2;
261  superCelltimewidth_ = pset.getParameter<double>("superCelltimewidth");
262 
263  mpathqualityenhancer_ = std::make_unique<MPSLFilter>(pset);
264  mpathqualityenhancerbayes_ = std::make_unique<MPQualityEnhancerFilterBayes>(pset);
265  mpathredundantfilter_ = std::make_unique<MPRedundantFilter>(pset);
266  mpathhitsfilter_ = std::make_unique<MPCleanHitsFilter>(pset);
267  mpathconfirmator_ = std::make_unique<MuonPathConfirmator>(pset, consumesColl);
268  mpathassociator_ = std::make_unique<MuonPathCorFitter>(pset, consumesColl, globalcoordsobtainer_);
269  mpathcorfilter_ = std::make_unique<MPCorFilter>(pset);
270  mpathcoifilter_ = std::make_unique<MPCoincidenceFilter>(pset);
271  rpc_integrator_ = std::make_unique<RPCIntegrator>(pset, consumesColl);
272 
273  dtGeomH = esConsumes<DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
274 }
275 
277  if (debug_)
278  LogDebug("DTTrigPhase2Prod") << "DTp2: calling destructor" << std::endl;
279 }
280 
281 void DTTrigPhase2Prod::beginRun(edm::Run const& iRun, const edm::EventSetup& iEventSetup) {
282  if (debug_)
283  LogDebug("DTTrigPhase2Prod") << "beginRun " << iRun.id().run();
284  if (debug_)
285  LogDebug("DTTrigPhase2Prod") << "beginRun: getting DT geometry";
286 
287  grouping_obj_->initialise(iEventSetup); // Grouping object initialisation
288  mpathanalyzer_->initialise(iEventSetup); // Analyzer object initialisation
289  mpathqualityenhancer_->initialise(iEventSetup); // Filter object initialisation
290  mpathredundantfilter_->initialise(iEventSetup); // Filter object initialisation
291  mpathqualityenhancerbayes_->initialise(iEventSetup); // Filter object initialisation
292  mpathhitsfilter_->initialise(iEventSetup);
293  mpathassociator_->initialise(iEventSetup); // Associator object initialisation
294  mpathcorfilter_->initialise(iEventSetup);
295  mpathcoifilter_->initialise(iEventSetup);
296 
297  if (auto geom = iEventSetup.getHandle(dtGeomH)) {
298  dtGeo_ = &(*geom);
299  }
300 }
301 
302 void DTTrigPhase2Prod::produce(Event& iEvent, const EventSetup& iEventSetup) {
303  if (debug_)
304  LogDebug("DTTrigPhase2Prod") << "produce";
306  iEvent.getByToken(dtDigisToken_, dtdigis);
307 
308  if (debug_)
309  LogDebug("DTTrigPhase2Prod") << "\t Getting the RPC RecHits" << std::endl;
311  iEvent.getByToken(rpcRecHitsLabel_, rpcRecHits);
312 
314  // GROUPING CODE:
316 
317  DTDigiMap digiMap;
319  for (const auto& detUnitIt : *dtdigis) {
320  const DTLayerId& layId = detUnitIt.first;
321  const DTChamberId chambId = layId.superlayerId().chamberId();
322  const DTDigiCollection::Range& range = detUnitIt.second;
323  digiMap[chambId].put(range, layId);
324  }
325 
326  // generate a list muon paths for each event!!!
327  if (debug_ && activateBuffer_)
328  LogDebug("DTTrigPhase2Prod") << "produce - Getting and grouping digis per chamber using a buffer and super cells.";
329  else if (debug_)
330  LogDebug("DTTrigPhase2Prod") << "produce - Getting and grouping digis per chamber.";
331 
332  std::map<int, MuonPathPtrs> muonpaths;
333  for (const auto& ich : dtGeo_->chambers()) {
334  // The code inside this for loop would ideally later fit inside a trigger unit (in principle, a DT station) of the future Phase 2 DT Trigger.
335  const DTChamber* chamb = ich;
336  DTChamberId chid = chamb->id();
337  DTDigiMap_iterator dmit = digiMap.find(chid);
338 
339  if (dmit == digiMap.end())
340  continue;
341 
342  if (activateBuffer_) { // Use buffering (per chamber) or not
343  // Import digis from the station
344  std::vector<std::pair<DTLayerId, DTDigi>> tmpvec;
345  tmpvec.clear();
346 
347  for (const auto& dtLayerIdIt : (*dmit).second) {
348  for (DTDigiCollection::const_iterator digiIt = (dtLayerIdIt.second).first;
349  digiIt != (dtLayerIdIt.second).second;
350  digiIt++) {
351  tmpvec.emplace_back(dtLayerIdIt.first, *digiIt);
352  }
353  }
354 
355  // Check to enhance CPU time usage
356  if (tmpvec.empty())
357  continue;
358 
359  // Order digis depending on TDC time and insert them into a queue (FIFO buffer). TODO: adapt for MC simulations.
360  std::sort(tmpvec.begin(), tmpvec.end(), DigiTimeOrdering);
361  std::queue<std::pair<DTLayerId, DTDigi>> timequeue;
362 
363  for (const auto& elem : tmpvec)
364  timequeue.emplace(elem);
365  tmpvec.clear();
366 
367  // Distribute the digis from the queue into supercells
368  std::vector<DTDigiCollection*> superCells;
369  superCells = distribDigis(timequeue);
370 
371  // Process each supercell & collect the resulting muonpaths (as the muonpaths std::vector is only enlarged each time
372  // the groupings access it, it's not needed to "collect" the final products).
373 
374  while (!superCells.empty()) {
375  grouping_obj_->run(iEvent, iEventSetup, *(superCells.back()), muonpaths[chid.rawId()]);
376  superCells.pop_back();
377  }
378  } else {
379  grouping_obj_->run(iEvent, iEventSetup, (*dmit).second, muonpaths[chid.rawId()]);
380  }
381  }
382  digiMap.clear();
383 
384  if (dump_) {
385  for (auto& ch_muonpaths : muonpaths) {
386  for (unsigned int i = 0; i < ch_muonpaths.second.size(); i++) {
387  stringstream ss;
388  ss << iEvent.id().event() << " mpath " << i << ": ";
389  for (int lay = 0; lay < ch_muonpaths.second.at(i)->nprimitives(); lay++)
390  ss << ch_muonpaths.second.at(i)->primitive(lay)->channelId() << " ";
391  for (int lay = 0; lay < ch_muonpaths.second.at(i)->nprimitives(); lay++)
392  ss << ch_muonpaths.second.at(i)->primitive(lay)->tdcTimeStamp() << " ";
393  for (int lay = 0; lay < ch_muonpaths.second.at(i)->nprimitives(); lay++)
394  ss << ch_muonpaths.second.at(i)->primitive(lay)->laterality() << " ";
395  LogInfo("DTTrigPhase2Prod") << ss.str();
396  }
397  }
398  }
399 
400  std::map<int, std::vector<lat_vector>> lateralities;
401  if (!output_mixer_) {
402  for (auto& ch_muonpaths : muonpaths) {
403  if (algo_ == Standard) {
404  latprovider_->run(iEvent, iEventSetup, ch_muonpaths.second, lateralities[ch_muonpaths.first]);
405  }
406  }
407  }
408 
409  // FILTER GROUPING
410  std::map<int, MuonPathPtrs> filteredmuonpaths;
411  for (auto& ch_muonpaths : muonpaths) {
412  if (algo_ == Standard) {
413  mpathredundantfilter_->run(iEvent, iEventSetup, ch_muonpaths.second, filteredmuonpaths[ch_muonpaths.first]);
414  } else {
415  mpathhitsfilter_->run(iEvent, iEventSetup, ch_muonpaths.second, filteredmuonpaths[ch_muonpaths.first]);
416  }
417  }
418 
419  if (dump_) {
420  for (auto& ch_filteredmuonpaths : filteredmuonpaths) {
421  for (unsigned int i = 0; i < ch_filteredmuonpaths.second.size(); i++) {
422  stringstream ss;
423  ss << iEvent.id().event() << " filt. mpath " << i << ": ";
424  for (int lay = 0; lay < ch_filteredmuonpaths.second.at(i)->nprimitives(); lay++)
425  ss << ch_filteredmuonpaths.second.at(i)->primitive(lay)->channelId() << " ";
426  for (int lay = 0; lay < ch_filteredmuonpaths.second.at(i)->nprimitives(); lay++)
427  ss << ch_filteredmuonpaths.second.at(i)->primitive(lay)->tdcTimeStamp() << " ";
428  LogInfo("DTTrigPhase2Prod") << ss.str();
429  }
430  }
431  }
432 
434 
438 
439  if (debug_) {
440  for (auto& ch_muonpaths : muonpaths) {
441  LogDebug("DTTrigPhase2Prod") << "MUON PATHS found: " << ch_muonpaths.second.size() << " ("
442  << filteredmuonpaths[ch_muonpaths.first].size() << ") in event "
443  << iEvent.id().event();
444  }
445  }
446  if (debug_)
447  LogDebug("DTTrigPhase2Prod") << "filling NmetaPrimtives" << std::endl;
448  std::map<int, std::vector<metaPrimitive>> metaPrimitives;
449  std::map<int, MuonPathPtrs> outmpaths;
450  if (algo_ == Standard) {
451  if (debug_)
452  LogDebug("DTTrigPhase2Prod") << "Fitting 1SL ";
453  for (auto& ch_muonpaths : muonpaths) { // FIXME, do we need filtered muonpaths?
455  mpathanalyzer_->run(iEvent,
456  iEventSetup,
457  ch_muonpaths.second,
458  lateralities[ch_muonpaths.first],
459  metaPrimitives[ch_muonpaths.first]);
460  else if (output_mixer_) {
461  for (auto& inMPath : ch_muonpaths.second) {
462  auto sl = inMPath->primitive(0)->superLayerId(); // 0, 1, 2
463  int selected_lay = 1;
464  if (inMPath->primitive(0)->tdcTimeStamp() != -1)
465  selected_lay = 0;
466  int dumLayId = inMPath->primitive(selected_lay)->cameraId();
467  auto dtDumlayerId = DTLayerId(dumLayId);
468  DTSuperLayerId MuonPathSLId(dtDumlayerId.wheel(), dtDumlayerId.station(), dtDumlayerId.sector(), sl + 1);
469  if (sl == 0)
470  metaPrimitives[ch_muonpaths.first].emplace_back(metaPrimitive({MuonPathSLId.rawId(),
471  -1,
472  -1,
473  -1,
474  -1,
475  -1,
476  -1,
477  -1,
478  -1,
479  -1,
480  inMPath->primitive(0)->channelId(),
481  inMPath->primitive(0)->tdcTimeStamp(),
482  -1,
483  inMPath->primitive(1)->channelId(),
484  inMPath->primitive(1)->tdcTimeStamp(),
485  -1,
486  inMPath->primitive(2)->channelId(),
487  inMPath->primitive(2)->tdcTimeStamp(),
488  -1,
489  inMPath->primitive(3)->channelId(),
490  inMPath->primitive(3)->tdcTimeStamp(),
491  -1,
492  -1,
493  -1,
494  -1,
495  -1,
496  -1,
497  -1,
498  -1,
499  -1,
500  -1,
501  -1,
502  -1,
503  -1,
504  -1}));
505  else
506  metaPrimitives[ch_muonpaths.first].emplace_back(metaPrimitive({MuonPathSLId.rawId(),
507  -1,
508  -1,
509  -1,
510  -1,
511  -1,
512  -1,
513  -1,
514  -1,
515  -1,
516  -1,
517  -1,
518  -1,
519  -1,
520  -1,
521  -1,
522  -1,
523  -1,
524  -1,
525  -1,
526  -1,
527  -1,
528  inMPath->primitive(0)->channelId(),
529  inMPath->primitive(0)->tdcTimeStamp(),
530  -1,
531  inMPath->primitive(1)->channelId(),
532  inMPath->primitive(1)->tdcTimeStamp(),
533  -1,
534  inMPath->primitive(2)->channelId(),
535  inMPath->primitive(2)->tdcTimeStamp(),
536  -1,
537  inMPath->primitive(3)->channelId(),
538  inMPath->primitive(3)->tdcTimeStamp(),
539  -1,
540  -1}));
541  }
542  } else if (output_latpredictor_) {
543  int imp = -1;
544  for (auto& inMPath : ch_muonpaths.second) {
545  imp++;
546  auto sl = inMPath->primitive(0)->superLayerId(); // 0, 1, 2
547  int selected_lay = 1;
548  if (inMPath->primitive(0)->tdcTimeStamp() != -1)
549  selected_lay = 0;
550  int dumLayId = inMPath->primitive(selected_lay)->cameraId();
551  auto dtDumlayerId = DTLayerId(dumLayId);
552  DTSuperLayerId MuonPathSLId(dtDumlayerId.wheel(), dtDumlayerId.station(), dtDumlayerId.sector(), sl + 1);
553  for (auto& latcomb : lateralities[ch_muonpaths.first][imp]) {
554  if (sl == 0)
555  metaPrimitives[ch_muonpaths.first].emplace_back(metaPrimitive({MuonPathSLId.rawId(),
556  -1,
557  -1,
558  -1,
559  -1,
560  -1,
561  -1,
562  -1,
563  -1,
564  -1,
565  inMPath->primitive(0)->channelId(),
566  inMPath->primitive(0)->tdcTimeStamp(),
567  latcomb[0],
568  inMPath->primitive(1)->channelId(),
569  inMPath->primitive(1)->tdcTimeStamp(),
570  latcomb[1],
571  inMPath->primitive(2)->channelId(),
572  inMPath->primitive(2)->tdcTimeStamp(),
573  latcomb[2],
574  inMPath->primitive(3)->channelId(),
575  inMPath->primitive(3)->tdcTimeStamp(),
576  latcomb[3],
577  -1,
578  -1,
579  -1,
580  -1,
581  -1,
582  -1,
583  -1,
584  -1,
585  -1,
586  -1,
587  -1,
588  -1,
589  -1}));
590  else
591  metaPrimitives[ch_muonpaths.first].emplace_back(metaPrimitive({MuonPathSLId.rawId(),
592  -1,
593  -1,
594  -1,
595  -1,
596  -1,
597  -1,
598  -1,
599  -1,
600  -1,
601  -1,
602  -1,
603  -1,
604  -1,
605  -1,
606  -1,
607  -1,
608  -1,
609  -1,
610  -1,
611  -1,
612  -1,
613  inMPath->primitive(0)->channelId(),
614  inMPath->primitive(0)->tdcTimeStamp(),
615  latcomb[0],
616  inMPath->primitive(1)->channelId(),
617  inMPath->primitive(1)->tdcTimeStamp(),
618  latcomb[1],
619  inMPath->primitive(2)->channelId(),
620  inMPath->primitive(2)->tdcTimeStamp(),
621  latcomb[2],
622  inMPath->primitive(3)->channelId(),
623  inMPath->primitive(3)->tdcTimeStamp(),
624  latcomb[3],
625  -1}));
626  }
627  }
628  }
629  }
630  } else {
631  // implementation for advanced (2SL) grouping, no filter required..
632  if (debug_)
633  LogDebug("DTTrigPhase2Prod") << "Fitting 2SL at once ";
634  for (auto& ch_muonpaths : muonpaths) {
635  mpathanalyzer_->run(iEvent, iEventSetup, ch_muonpaths.second, outmpaths[ch_muonpaths.first]);
636  }
637  }
638 
640 
641  if (dump_) {
642  for (auto& ch_outmpaths : outmpaths) {
643  for (unsigned int i = 0; i < ch_outmpaths.second.size(); i++) {
644  LogInfo("DTTrigPhase2Prod") << iEvent.id().event() << " mp " << i << ": "
645  << ch_outmpaths.second.at(i)->bxTimeValue() << " "
646  << ch_outmpaths.second.at(i)->horizPos() << " "
647  << ch_outmpaths.second.at(i)->tanPhi() << " " << ch_outmpaths.second.at(i)->phi()
648  << " " << ch_outmpaths.second.at(i)->phiB() << " "
649  << ch_outmpaths.second.at(i)->quality() << " "
650  << ch_outmpaths.second.at(i)->chiSquare();
651  }
652  }
653  for (auto& ch_metaPrimitives : metaPrimitives) {
654  for (unsigned int i = 0; i < ch_metaPrimitives.second.size(); i++) {
655  stringstream ss;
656  ss << iEvent.id().event() << " mp " << i << ": ";
657  printmP(ss.str(), ch_metaPrimitives.second.at(i));
658  }
659  }
660  }
661 
662  muonpaths.clear();
663  filteredmuonpaths.clear();
664 
668 
669  std::map<int, std::vector<metaPrimitive>> confirmedMetaPrimitives;
670  for (auto& ch_metaPrimitives : metaPrimitives) {
672  mpathconfirmator_->run(
673  iEvent, iEventSetup, ch_metaPrimitives.second, dtdigis, confirmedMetaPrimitives[ch_metaPrimitives.first]);
674  else
675  for (auto& mp : ch_metaPrimitives.second) {
676  confirmedMetaPrimitives[ch_metaPrimitives.first].push_back(mp);
677  }
678  }
679 
680  metaPrimitives.clear();
682 
684  // FILTER SECTIONS:
686 
687  if (debug_)
688  LogDebug("DTTrigPhase2Prod") << "declaring new vector for filtered" << std::endl;
689 
690  std::map<int, std::vector<metaPrimitive>> filteredMetaPrimitives;
691  if (algo_ == Standard)
692  for (auto& ch_confirmedMetaPrimitives : confirmedMetaPrimitives) {
693  if (!skip_processing_)
695  iEventSetup,
696  ch_confirmedMetaPrimitives.second,
697  filteredMetaPrimitives[ch_confirmedMetaPrimitives.first]);
698  else
699  for (auto& mp : ch_confirmedMetaPrimitives.second) {
700  filteredMetaPrimitives[ch_confirmedMetaPrimitives.first].push_back(mp);
701  }
702  }
703  if (dump_) {
704  for (auto& ch_filteredMetaPrimitives : filteredMetaPrimitives) {
705  for (unsigned int i = 0; i < ch_filteredMetaPrimitives.second.size(); i++) {
706  stringstream ss;
707  ss << iEvent.id().event() << " filtered mp " << i << ": ";
708  printmP(ss.str(), ch_filteredMetaPrimitives.second.at(i));
709  }
710  }
711  }
712 
714  confirmedMetaPrimitives.clear();
715 
716  if (debug_)
717  for (auto& ch_filteredMetaPrimitives : filteredMetaPrimitives) {
718  LogDebug("DTTrigPhase2Prod") << "DTp2 in event:" << iEvent.id().event() << " we found "
719  << ch_filteredMetaPrimitives.second.size() << " filteredMetaPrimitives (superlayer)"
720  << std::endl;
721  }
722  if (debug_)
723  LogDebug("DTTrigPhase2Prod") << "filteredMetaPrimitives: starting correlations" << std::endl;
724 
728 
729  std::map<int, std::vector<metaPrimitive>> correlatedMetaPrimitives;
730  if (algo_ == Standard) {
731  for (auto& ch_filteredMetaPrimitives : filteredMetaPrimitives) {
732  if (!skip_processing_)
734  iEventSetup,
735  ch_filteredMetaPrimitives.second,
736  correlatedMetaPrimitives[ch_filteredMetaPrimitives.first]);
737  else
738  for (auto& mp : ch_filteredMetaPrimitives.second) {
739  correlatedMetaPrimitives[ch_filteredMetaPrimitives.first].push_back(mp);
740  }
741  }
742  } else {
743  for (auto& ch_outmpaths : outmpaths) {
744  for (const auto& muonpath : ch_outmpaths.second) {
745  correlatedMetaPrimitives[ch_outmpaths.first].emplace_back(muonpath->rawId(),
746  (double)muonpath->bxTimeValue(),
747  muonpath->horizPos(),
748  muonpath->tanPhi(),
749  muonpath->phi(),
750  muonpath->phiB(),
751  muonpath->phi_cmssw(),
752  muonpath->phiB_cmssw(),
753  muonpath->chiSquare(),
754  (int)muonpath->quality(),
755  muonpath->primitive(0)->channelId(),
756  muonpath->primitive(0)->tdcTimeStamp(),
757  muonpath->primitive(0)->laterality(),
758  muonpath->primitive(1)->channelId(),
759  muonpath->primitive(1)->tdcTimeStamp(),
760  muonpath->primitive(1)->laterality(),
761  muonpath->primitive(2)->channelId(),
762  muonpath->primitive(2)->tdcTimeStamp(),
763  muonpath->primitive(2)->laterality(),
764  muonpath->primitive(3)->channelId(),
765  muonpath->primitive(3)->tdcTimeStamp(),
766  muonpath->primitive(3)->laterality(),
767  muonpath->primitive(4)->channelId(),
768  muonpath->primitive(4)->tdcTimeStamp(),
769  muonpath->primitive(4)->laterality(),
770  muonpath->primitive(5)->channelId(),
771  muonpath->primitive(5)->tdcTimeStamp(),
772  muonpath->primitive(5)->laterality(),
773  muonpath->primitive(6)->channelId(),
774  muonpath->primitive(6)->tdcTimeStamp(),
775  muonpath->primitive(6)->laterality(),
776  muonpath->primitive(7)->channelId(),
777  muonpath->primitive(7)->tdcTimeStamp(),
778  muonpath->primitive(7)->laterality());
779  }
780  }
781  }
782 
784 
785  if (debug_)
786  for (auto& ch_correlatedMetaPrimitives : correlatedMetaPrimitives) {
787  LogDebug("DTTrigPhase2Prod") << "DTp2 in event:" << iEvent.id().event() << " we found "
788  << ch_correlatedMetaPrimitives.second.size() << " correlatedMetPrimitives (chamber)";
789  }
790  if (dump_) {
791  for (auto& ch_correlatedMetaPrimitives : correlatedMetaPrimitives) {
792  LogDebug("DTTrigPhase2Prod") << "DTp2 in event:" << iEvent.id().event() << " we found "
793  << ch_correlatedMetaPrimitives.second.size() << " correlatedMetPrimitives (chamber)";
794  }
795  for (auto& ch_correlatedMetaPrimitives : correlatedMetaPrimitives) {
796  for (unsigned int i = 0; i < ch_correlatedMetaPrimitives.second.size(); i++) {
797  stringstream ss;
798  ss << iEvent.id().event() << " correlated mp " << i << ": ";
799  printmPC(ss.str(), ch_correlatedMetaPrimitives.second.at(i));
800  }
801  }
802  }
803 
804  // Correlated Filtering
805  std::map<int, std::vector<metaPrimitive>> filtCorrelatedMetaPrimitives;
806  if (algo_ == Standard) {
807  for (auto& ch_filteredMetaPrimitives : filteredMetaPrimitives) {
808  if (!skip_processing_)
809  mpathcorfilter_->run(iEvent,
810  iEventSetup,
811  ch_filteredMetaPrimitives.second,
812  correlatedMetaPrimitives[ch_filteredMetaPrimitives.first],
813  filtCorrelatedMetaPrimitives[ch_filteredMetaPrimitives.first]);
814  else {
815  for (auto& mp : ch_filteredMetaPrimitives.second) {
816  filtCorrelatedMetaPrimitives[ch_filteredMetaPrimitives.first].push_back(mp);
817  }
818  if (output_matcher_)
819  for (auto& mp : correlatedMetaPrimitives[ch_filteredMetaPrimitives.first]) {
820  filtCorrelatedMetaPrimitives[ch_filteredMetaPrimitives.first].push_back(mp);
821  }
822  }
823  }
824  }
825 
826  correlatedMetaPrimitives.clear();
827  filteredMetaPrimitives.clear();
828 
829  // Coincidence (co) filter
830 
831  std::vector<metaPrimitive> allMetaPrimitives;
832  for (auto& ch_filtcorrelatedMetaPrimitives : filtCorrelatedMetaPrimitives) {
833  for (const auto& metaPrimitiveIt : ch_filtcorrelatedMetaPrimitives.second) {
834  allMetaPrimitives.push_back(metaPrimitiveIt);
835  }
836  }
837 
838  std::map<int, std::vector<metaPrimitive>> coMetaPrimitives;
839  if (algo_ == Standard) {
840  for (auto& ch_filtcorrelatedMetaPrimitives : filtCorrelatedMetaPrimitives) {
841  if (!skip_processing_)
842  mpathcoifilter_->run(iEvent,
843  iEventSetup,
844  allMetaPrimitives,
845  filtCorrelatedMetaPrimitives[ch_filtcorrelatedMetaPrimitives.first],
846  coMetaPrimitives[ch_filtcorrelatedMetaPrimitives.first]);
847  else {
848  for (auto& mp : ch_filtcorrelatedMetaPrimitives.second) {
849  coMetaPrimitives[ch_filtcorrelatedMetaPrimitives.first].push_back(mp);
850  }
851  }
852  }
853  }
854 
855  allMetaPrimitives.clear();
856 
858 
859  double shift_back = 0;
860  if (scenario_ == MC) //scope for MC
861  shift_back = 400;
862  else if (scenario_ == DATA) //scope for data
863  shift_back = 0;
864  else if (scenario_ == SLICE_TEST) //scope for slice test
865  shift_back = 400;
866 
867  // RPC integration
868  if (useRPC_) {
869  rpc_integrator_->initialise(iEventSetup, shift_back);
870  rpc_integrator_->prepareMetaPrimitives(rpcRecHits);
871  for (auto& ch_correlatedMetaPrimitives : coMetaPrimitives) {
872  rpc_integrator_->matchWithDTAndUseRPCTime(ch_correlatedMetaPrimitives.second); // Probably this is a FIXME
873  }
874  rpc_integrator_->makeRPCOnlySegments();
875  rpc_integrator_->storeRPCSingleHits();
876  rpc_integrator_->removeRPCHitsUsed();
877  }
878 
880  vector<L1Phase2MuDTPhDigi> outP2Ph;
881  vector<L1Phase2MuDTExtPhDigi> outExtP2Ph;
882  vector<L1Phase2MuDTThDigi> outP2Th;
883  vector<L1Phase2MuDTExtThDigi> outExtP2Th;
884 
885  // Assigning index value
886  if (!skip_processing_)
887  for (auto& ch_correlatedMetaPrimitives : coMetaPrimitives) {
888  assignIndex(ch_correlatedMetaPrimitives.second);
889  }
890 
891  for (auto& ch_correlatedMetaPrimitives : coMetaPrimitives) {
892  for (const auto& metaPrimitiveIt : ch_correlatedMetaPrimitives.second) {
893  DTChamberId chId(metaPrimitiveIt.rawId);
894  DTSuperLayerId slId(metaPrimitiveIt.rawId);
895  if (debug_)
896  LogDebug("DTTrigPhase2Prod") << "looping in final vector: SuperLayerId" << chId << " x=" << metaPrimitiveIt.x
897  << " quality=" << metaPrimitiveIt.quality
898  << " BX=" << round(metaPrimitiveIt.t0 / 25.) << " index=" << metaPrimitiveIt.index;
899 
900  int sectorTP = chId.sector();
901  //sectors 13 and 14 exist only for the outermost stations for sectors 4 and 10 respectively
902  //due to the larger MB4 that are divided into two.
903  if (sectorTP == 13)
904  sectorTP = 4;
905  if (sectorTP == 14)
906  sectorTP = 10;
907  sectorTP = sectorTP - 1;
908  int sl = 0;
909  if (metaPrimitiveIt.quality < LOWLOWQ || metaPrimitiveIt.quality == CHIGHQ) {
910  if (inner(metaPrimitiveIt))
911  sl = 1;
912  else
913  sl = 3;
914  }
915 
916  float tp_t0 =
917  (metaPrimitiveIt.t0 - shift_back * LHC_CLK_FREQ) * ((float)TIME_TO_TDC_COUNTS / (float)LHC_CLK_FREQ);
918 
919  if (debug_)
920  LogDebug("DTTrigPhase2Prod") << "pushing back phase-2 dataformat carlo-federica dataformat";
921 
922  if (slId.superLayer() != 2) {
923  if (df_extended_ == 1 || df_extended_ == 2) {
924  int pathWireId[8] = {metaPrimitiveIt.wi1,
925  metaPrimitiveIt.wi2,
926  metaPrimitiveIt.wi3,
927  metaPrimitiveIt.wi4,
928  metaPrimitiveIt.wi5,
929  metaPrimitiveIt.wi6,
930  metaPrimitiveIt.wi7,
931  metaPrimitiveIt.wi8};
932 
933  int pathTDC[8] = {max((int)round(metaPrimitiveIt.tdc1 - shift_back * LHC_CLK_FREQ), -1),
934  max((int)round(metaPrimitiveIt.tdc2 - shift_back * LHC_CLK_FREQ), -1),
935  max((int)round(metaPrimitiveIt.tdc3 - shift_back * LHC_CLK_FREQ), -1),
936  max((int)round(metaPrimitiveIt.tdc4 - shift_back * LHC_CLK_FREQ), -1),
937  max((int)round(metaPrimitiveIt.tdc5 - shift_back * LHC_CLK_FREQ), -1),
938  max((int)round(metaPrimitiveIt.tdc6 - shift_back * LHC_CLK_FREQ), -1),
939  max((int)round(metaPrimitiveIt.tdc7 - shift_back * LHC_CLK_FREQ), -1),
940  max((int)round(metaPrimitiveIt.tdc8 - shift_back * LHC_CLK_FREQ), -1)};
941 
942  int pathLat[8] = {metaPrimitiveIt.lat1,
943  metaPrimitiveIt.lat2,
944  metaPrimitiveIt.lat3,
945  metaPrimitiveIt.lat4,
946  metaPrimitiveIt.lat5,
947  metaPrimitiveIt.lat6,
948  metaPrimitiveIt.lat7,
949  metaPrimitiveIt.lat8};
950 
951  // phiTP (extended DF)
952  outExtP2Ph.emplace_back(
953  L1Phase2MuDTExtPhDigi((int)round(metaPrimitiveIt.t0 / (float)LHC_CLK_FREQ) - shift_back,
954  chId.wheel(), // uwh (m_wheel)
955  sectorTP, // usc (m_sector)
956  chId.station(), // ust (m_station)
957  sl, // ust (m_station)
958  (int)round(metaPrimitiveIt.phi * PHIRES_CONV), // uphi (m_phiAngle)
959  (int)round(metaPrimitiveIt.phiB * PHIBRES_CONV), // uphib (m_phiBending)
960  metaPrimitiveIt.quality, // uqua (m_qualityCode)
961  metaPrimitiveIt.index, // uind (m_segmentIndex)
962  tp_t0, // ut0 (m_t0Segment)
963  (int)round(metaPrimitiveIt.chi2 * CHI2RES_CONV), // uchi2 (m_chi2Segment)
964  (int)round(metaPrimitiveIt.x * 1000), // ux (m_xLocal)
965  (int)round(metaPrimitiveIt.tanPhi * 1000), // utan (m_tanPsi)
966  (int)round(metaPrimitiveIt.phi_cmssw * PHIRES_CONV), // uphi (m_phiAngleCMSSW)
967  (int)round(metaPrimitiveIt.phiB_cmssw * PHIBRES_CONV), // uphib (m_phiBendingCMSSW)
968  metaPrimitiveIt.rpcFlag, // urpc (m_rpcFlag)
969  pathWireId,
970  pathTDC,
971  pathLat));
972  }
973  if (df_extended_ == 0 || df_extended_ == 2) {
974  // phiTP (standard DF)
975  outP2Ph.push_back(L1Phase2MuDTPhDigi(
976  (int)round(metaPrimitiveIt.t0 / (float)LHC_CLK_FREQ) - shift_back,
977  chId.wheel(), // uwh (m_wheel)
978  sectorTP, // usc (m_sector)
979  chId.station(), // ust (m_station)
980  sl, // ust (m_station)
981  (int)round(metaPrimitiveIt.phi * PHIRES_CONV), // uphi (_phiAngle)
982  (int)round(metaPrimitiveIt.phiB * PHIBRES_CONV), // uphib (m_phiBending)
983  metaPrimitiveIt.quality, // uqua (m_qualityCode)
984  metaPrimitiveIt.index, // uind (m_segmentIndex)
985  tp_t0, // ut0 (m_t0Segment)
986  (int)round(metaPrimitiveIt.chi2 * CHI2RES_CONV), // uchi2 (m_chi2Segment)
987  metaPrimitiveIt.rpcFlag // urpc (m_rpcFlag)
988  ));
989  }
990  } else {
991  if (df_extended_ == 1 || df_extended_ == 2) {
992  int pathWireId[4] = {metaPrimitiveIt.wi1, metaPrimitiveIt.wi2, metaPrimitiveIt.wi3, metaPrimitiveIt.wi4};
993 
994  int pathTDC[4] = {max((int)round(metaPrimitiveIt.tdc1 - shift_back * LHC_CLK_FREQ), -1),
995  max((int)round(metaPrimitiveIt.tdc2 - shift_back * LHC_CLK_FREQ), -1),
996  max((int)round(metaPrimitiveIt.tdc3 - shift_back * LHC_CLK_FREQ), -1),
997  max((int)round(metaPrimitiveIt.tdc4 - shift_back * LHC_CLK_FREQ), -1)};
998 
999  int pathLat[4] = {metaPrimitiveIt.lat1, metaPrimitiveIt.lat2, metaPrimitiveIt.lat3, metaPrimitiveIt.lat4};
1000 
1001  // thTP (extended DF)
1002  outExtP2Th.emplace_back(
1003  L1Phase2MuDTExtThDigi((int)round(metaPrimitiveIt.t0 / (float)LHC_CLK_FREQ) - shift_back,
1004  chId.wheel(), // uwh (m_wheel)
1005  sectorTP, // usc (m_sector)
1006  chId.station(), // ust (m_station)
1007  (int)round(metaPrimitiveIt.phi * ZRES_CONV), // uz (m_zGlobal)
1008  (int)round(metaPrimitiveIt.phiB * KRES_CONV), // uk (m_kSlope)
1009  metaPrimitiveIt.quality, // uqua (m_qualityCode)
1010  metaPrimitiveIt.index, // uind (m_segmentIndex)
1011  tp_t0, // ut0 (m_t0Segment)
1012  (int)round(metaPrimitiveIt.chi2 * CHI2RES_CONV), // uchi2 (m_chi2Segment)
1013  (int)round(metaPrimitiveIt.x * 1000), // ux (m_yLocal)
1014  (int)round(metaPrimitiveIt.phi_cmssw * ZRES_CONV), // uphi (m_zCMSSW)
1015  (int)round(metaPrimitiveIt.phiB_cmssw * KRES_CONV), // uphib (m_kCMSSW)
1016  metaPrimitiveIt.rpcFlag, // urpc (m_rpcFlag)
1017  pathWireId,
1018  pathTDC,
1019  pathLat));
1020  }
1021  if (df_extended_ == 0 || df_extended_ == 2) {
1022  // thTP (standard DF)
1023  outP2Th.push_back(L1Phase2MuDTThDigi(
1024  (int)round(metaPrimitiveIt.t0 / (float)LHC_CLK_FREQ) - shift_back,
1025  chId.wheel(), // uwh (m_wheel)
1026  sectorTP, // usc (m_sector)
1027  chId.station(), // ust (m_station)
1028  (int)round(metaPrimitiveIt.phi * ZRES_CONV), // uz (m_zGlobal)
1029  (int)round(metaPrimitiveIt.phiB * KRES_CONV), // uk (m_kSlope)
1030  metaPrimitiveIt.quality, // uqua (m_qualityCode)
1031  metaPrimitiveIt.index, // uind (m_segmentIndex)
1032  tp_t0, // ut0 (m_t0Segment)
1033  (int)round(metaPrimitiveIt.chi2 * CHI2RES_CONV), // uchi2 (m_chi2Segment)
1034  metaPrimitiveIt.rpcFlag // urpc (m_rpcFlag)
1035  ));
1036  }
1037  }
1038  }
1039  }
1040 
1041  // Storing RPC hits that were not used elsewhere
1042  if (useRPC_) {
1043  for (auto rpc_dt_digi = rpc_integrator_->rpcRecHits_translated_.begin();
1044  rpc_dt_digi != rpc_integrator_->rpcRecHits_translated_.end();
1045  rpc_dt_digi++) {
1046  outP2Ph.push_back(*rpc_dt_digi);
1047  }
1048  }
1049 
1050  // Storing Phi results
1051  if (df_extended_ == 1 || df_extended_ == 2) {
1052  std::unique_ptr<L1Phase2MuDTExtPhContainer> resultExtP2Ph(new L1Phase2MuDTExtPhContainer);
1053  resultExtP2Ph->setContainer(outExtP2Ph);
1054  iEvent.put(std::move(resultExtP2Ph));
1055  }
1056  if (df_extended_ == 0 || df_extended_ == 2) {
1057  std::unique_ptr<L1Phase2MuDTPhContainer> resultP2Ph(new L1Phase2MuDTPhContainer);
1058  resultP2Ph->setContainer(outP2Ph);
1059  iEvent.put(std::move(resultP2Ph));
1060  }
1061  outExtP2Ph.clear();
1062  outExtP2Ph.erase(outExtP2Ph.begin(), outExtP2Ph.end());
1063  outP2Ph.clear();
1064  outP2Ph.erase(outP2Ph.begin(), outP2Ph.end());
1065 
1066  // Storing Theta results
1067  if (df_extended_ == 1 || df_extended_ == 2) {
1068  std::unique_ptr<L1Phase2MuDTExtThContainer> resultExtP2Th(new L1Phase2MuDTExtThContainer);
1069  resultExtP2Th->setContainer(outExtP2Th);
1070  iEvent.put(std::move(resultExtP2Th));
1071  }
1072  if (df_extended_ == 0 || df_extended_ == 2) {
1073  std::unique_ptr<L1Phase2MuDTThContainer> resultP2Th(new L1Phase2MuDTThContainer);
1074  resultP2Th->setContainer(outP2Th);
1075  iEvent.put(std::move(resultP2Th));
1076  }
1077  outExtP2Th.clear();
1078  outExtP2Th.erase(outExtP2Th.begin(), outExtP2Th.end());
1079  outP2Th.clear();
1080  outP2Th.erase(outP2Th.begin(), outP2Th.end());
1081 }
1082 
1083 void DTTrigPhase2Prod::endRun(edm::Run const& iRun, const edm::EventSetup& iEventSetup) {
1084  grouping_obj_->finish();
1085  mpathanalyzer_->finish();
1086  mpathqualityenhancer_->finish();
1087  mpathqualityenhancerbayes_->finish();
1088  mpathredundantfilter_->finish();
1089  mpathhitsfilter_->finish();
1090  mpathassociator_->finish();
1091  rpc_integrator_->finish();
1092 };
1093 
1095  int counter = (mp.wi5 != -1) + (mp.wi6 != -1) + (mp.wi7 != -1) + (mp.wi8 != -1);
1096  return (counter > 2);
1097 }
1098 
1100  int counter = (mp.wi1 != -1) + (mp.wi2 != -1) + (mp.wi3 != -1) + (mp.wi4 != -1);
1101  return (counter > 2);
1102 }
1103 
1104 bool DTTrigPhase2Prod::hasPosRF(int wh, int sec) const { return wh > 0 || (wh == 0 && sec % 4 > 1); }
1105 
1106 void DTTrigPhase2Prod::printmP(const string& ss, const metaPrimitive& mP) const {
1107  DTSuperLayerId slId(mP.rawId);
1108  LogInfo("DTTrigPhase2Prod") << ss << (int)slId << "\t " << setw(2) << left << mP.wi1 << " " << setw(2) << left
1109  << mP.wi2 << " " << setw(2) << left << mP.wi3 << " " << setw(2) << left << mP.wi4 << " "
1110  << setw(5) << left << mP.tdc1 << " " << setw(5) << left << mP.tdc2 << " " << setw(5)
1111  << left << mP.tdc3 << " " << setw(5) << left << mP.tdc4 << " " << setw(10) << right
1112  << mP.x << " " << setw(9) << left << mP.tanPhi << " " << setw(5) << left << mP.t0 << " "
1113  << setw(13) << left << mP.chi2 << " r:" << rango(mP);
1114 }
1115 
1117  DTSuperLayerId slId(mP.rawId);
1118  LogInfo("DTTrigPhase2Prod") << (int)slId << "\t " << setw(2) << left << mP.wi1 << " " << setw(2) << left << mP.wi2
1119  << " " << setw(2) << left << mP.wi3 << " " << setw(2) << left << mP.wi4 << " " << setw(5)
1120  << left << mP.tdc1 << " " << setw(5) << left << mP.tdc2 << " " << setw(5) << left
1121  << mP.tdc3 << " " << setw(5) << left << mP.tdc4 << " " << setw(10) << right << mP.x << " "
1122  << setw(9) << left << mP.tanPhi << " " << setw(5) << left << mP.t0 << " " << setw(13)
1123  << left << mP.chi2 << " r:" << rango(mP) << std::endl;
1124 }
1125 
1126 void DTTrigPhase2Prod::printmPC(const string& ss, const metaPrimitive& mP) const {
1127  DTChamberId ChId(mP.rawId);
1128  LogInfo("DTTrigPhase2Prod") << ss << (int)ChId << "\t " << setw(2) << left << mP.wi1 << " " << setw(2) << left
1129  << mP.wi2 << " " << setw(2) << left << mP.wi3 << " " << setw(2) << left << mP.wi4 << " "
1130  << setw(2) << left << mP.wi5 << " " << setw(2) << left << mP.wi6 << " " << setw(2) << left
1131  << mP.wi7 << " " << setw(2) << left << mP.wi8 << " " << setw(5) << left << mP.tdc1 << " "
1132  << setw(5) << left << mP.tdc2 << " " << setw(5) << left << mP.tdc3 << " " << setw(5)
1133  << left << mP.tdc4 << " " << setw(5) << left << mP.tdc5 << " " << setw(5) << left
1134  << mP.tdc6 << " " << setw(5) << left << mP.tdc7 << " " << setw(5) << left << mP.tdc8
1135  << " " << setw(2) << left << mP.lat1 << " " << setw(2) << left << mP.lat2 << " "
1136  << setw(2) << left << mP.lat3 << " " << setw(2) << left << mP.lat4 << " " << setw(2)
1137  << left << mP.lat5 << " " << setw(2) << left << mP.lat6 << " " << setw(2) << left
1138  << mP.lat7 << " " << setw(2) << left << mP.lat8 << " " << setw(10) << right << mP.x << " "
1139  << setw(9) << left << mP.tanPhi << " " << setw(5) << left << mP.t0 << " " << setw(13)
1140  << left << mP.chi2 << " r:" << rango(mP);
1141 }
1142 
1144  DTChamberId ChId(mP.rawId);
1145  LogInfo("DTTrigPhase2Prod") << (int)ChId << "\t " << setw(2) << left << mP.wi1 << " " << setw(2) << left << mP.wi2
1146  << " " << setw(2) << left << mP.wi3 << " " << setw(2) << left << mP.wi4 << " " << setw(2)
1147  << left << mP.wi5 << " " << setw(2) << left << mP.wi6 << " " << setw(2) << left << mP.wi7
1148  << " " << setw(2) << left << mP.wi8 << " " << setw(5) << left << mP.tdc1 << " " << setw(5)
1149  << left << mP.tdc2 << " " << setw(5) << left << mP.tdc3 << " " << setw(5) << left
1150  << mP.tdc4 << " " << setw(5) << left << mP.tdc5 << " " << setw(5) << left << mP.tdc6
1151  << " " << setw(5) << left << mP.tdc7 << " " << setw(5) << left << mP.tdc8 << " "
1152  << setw(2) << left << mP.lat1 << " " << setw(2) << left << mP.lat2 << " " << setw(2)
1153  << left << mP.lat3 << " " << setw(2) << left << mP.lat4 << " " << setw(2) << left
1154  << mP.lat5 << " " << setw(2) << left << mP.lat6 << " " << setw(2) << left << mP.lat7
1155  << " " << setw(2) << left << mP.lat8 << " " << setw(10) << right << mP.x << " " << setw(9)
1156  << left << mP.tanPhi << " " << setw(5) << left << mP.t0 << " " << setw(13) << left
1157  << mP.chi2 << " r:" << rango(mP) << std::endl;
1158 }
1159 
1161  if (mp.quality == 1 or mp.quality == 2)
1162  return 3;
1163  if (mp.quality == 3 or mp.quality == 4)
1164  return 4;
1165  return mp.quality;
1166 }
1167 
1168 void DTTrigPhase2Prod::assignIndex(std::vector<metaPrimitive>& inMPaths) {
1169  std::map<int, std::vector<metaPrimitive>> primsPerBX;
1170  for (const auto& metaPrimitive : inMPaths) {
1171  int BX = round(metaPrimitive.t0 / 25.);
1172  primsPerBX[BX].push_back(metaPrimitive);
1173  }
1174  inMPaths.clear();
1175  for (auto& prims : primsPerBX) {
1176  assignIndexPerBX(prims.second);
1177  for (const auto& primitive : prims.second)
1178  if (primitive.index <= max_index_)
1179  inMPaths.push_back(primitive);
1180  }
1181 }
1182 
1183 void DTTrigPhase2Prod::assignIndexPerBX(std::vector<metaPrimitive>& inMPaths) {
1184  // First we asociate a new index to the metaprimitive depending on quality or phiB;
1185  uint32_t rawId = -1;
1186  int numP = -1;
1187  for (auto& metaPrimitiveIt : inMPaths) {
1188  numP++;
1189  rawId = metaPrimitiveIt.rawId;
1190  int iOrder = assignQualityOrder(metaPrimitiveIt);
1191  int inf = 0;
1192  int numP2 = -1;
1193  for (auto& metaPrimitiveItN : inMPaths) {
1194  int nOrder = assignQualityOrder(metaPrimitiveItN);
1195  numP2++;
1196  if (rawId != metaPrimitiveItN.rawId)
1197  continue;
1198  if (numP2 == numP) {
1199  metaPrimitiveIt.index = inf;
1200  break;
1201  } else if (iOrder < nOrder) {
1202  inf++;
1203  } else if (iOrder > nOrder) {
1204  metaPrimitiveItN.index++;
1205  } else if (iOrder == nOrder) {
1206  if (std::abs(metaPrimitiveIt.phiB) >= std::abs(metaPrimitiveItN.phiB)) {
1207  inf++;
1208  } else if (std::abs(metaPrimitiveIt.phiB) < std::abs(metaPrimitiveItN.phiB)) {
1209  metaPrimitiveItN.index++;
1210  }
1211  }
1212  } // ending second for
1213  } // ending first for
1214 }
1215 
1217  if (mP.quality > 8 || mP.quality < 1)
1218  return -1;
1219 
1220  return qmap_.find(mP.quality)->second;
1221 }
1222 
1223 std::vector<DTDigiCollection*> DTTrigPhase2Prod::distribDigis(std::queue<std::pair<DTLayerId, DTDigi>>& inQ) {
1224  std::vector<std::queue<std::pair<DTLayerId, DTDigi>>*> tmpVector;
1225  tmpVector.clear();
1226  std::vector<DTDigiCollection*> collVector;
1227  collVector.clear();
1228  while (!inQ.empty()) {
1229  processDigi(inQ, tmpVector);
1230  }
1231  for (auto& sQ : tmpVector) {
1232  DTDigiCollection tmpColl;
1233  while (!sQ->empty()) {
1234  tmpColl.insertDigi((sQ->front().first), (sQ->front().second));
1235  sQ->pop();
1236  }
1237  collVector.push_back(&tmpColl);
1238  }
1239  return collVector;
1240 }
1241 
1242 void DTTrigPhase2Prod::processDigi(std::queue<std::pair<DTLayerId, DTDigi>>& inQ,
1243  std::vector<std::queue<std::pair<DTLayerId, DTDigi>>*>& vec) {
1244  bool classified = false;
1245  if (!vec.empty()) {
1246  for (auto& sC : vec) { // Conditions for entering a super cell.
1247  if ((sC->front().second.time() + superCelltimewidth_) > inQ.front().second.time()) {
1248  // Time requirement
1249  if (TMath::Abs(sC->front().second.wire() - inQ.front().second.wire()) <= superCellhalfspacewidth_) {
1250  // Spatial requirement
1251  sC->push(std::move(inQ.front()));
1252  classified = true;
1253  }
1254  }
1255  }
1256  }
1257  if (classified) {
1258  inQ.pop();
1259  return;
1260  }
1261 
1262  std::queue<std::pair<DTLayerId, DTDigi>> newQueue;
1263 
1264  std::pair<DTLayerId, DTDigi> tmpPair;
1265  tmpPair = std::move(inQ.front());
1266  newQueue.push(tmpPair);
1267  inQ.pop();
1268 
1269  vec.push_back(&newQueue);
1270 }
1271 
1273  // dtTriggerPhase2PrimitiveDigis
1275  desc.add<edm::InputTag>("digiTag", edm::InputTag("CalibratedDigis"));
1276  desc.add<int>("timeTolerance", 999999);
1277  desc.add<double>("tanPhiTh", 1.0);
1278  desc.add<double>("tanPhiThw2max", 1.3);
1279  desc.add<double>("tanPhiThw2min", 0.5);
1280  desc.add<double>("tanPhiThw1max", 0.9);
1281  desc.add<double>("tanPhiThw1min", 0.2);
1282  desc.add<double>("tanPhiThw0", 0.5);
1283  desc.add<double>("chi2Th", 0.01);
1284  desc.add<double>("chi2corTh", 0.1);
1285  desc.add<bool>("useBX_correlation", false);
1286  desc.add<double>("dT0_correlate_TP", 25.0);
1287  desc.add<int>("dBX_correlate_TP", 0);
1288  desc.add<double>("dTanPsi_correlate_TP", 99999.0);
1289  desc.add<bool>("clean_chi2_correlation", true);
1290  desc.add<bool>("allow_confirmation", true);
1291  desc.add<double>("minx_match_2digis", 1.0);
1292  desc.add<int>("scenario", 0);
1293  desc.add<int>("df_extended", 0);
1294  desc.add<int>("co_option", 0);
1295  desc.add<int>("co_quality", 0);
1296  desc.add<int>("max_primitives", 999);
1297  desc.add<bool>("output_mixer", false);
1298  desc.add<bool>("output_latpredictor", false);
1299  desc.add<bool>("output_slfitter", false);
1300  desc.add<bool>("output_slfilter", false);
1301  desc.add<bool>("output_confirmed", false);
1302  desc.add<bool>("output_matcher", false);
1303  desc.add<edm::FileInPath>("ttrig_filename", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/wire_rawId_ttrig.txt"));
1304  desc.add<edm::FileInPath>("z_filename", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/wire_rawId_z.txt"));
1305  desc.add<edm::FileInPath>("lut_sl1", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/fitterlut_sl1.dat"));
1306  desc.add<edm::FileInPath>("lut_sl2", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/fitterlut_slx.dat"));
1307  desc.add<edm::FileInPath>("lut_sl3", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/fitterlut_sl3.dat"));
1308  desc.add<edm::FileInPath>("lut_2sl", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/fitterlut_2sl.dat"));
1309  desc.add<edm::FileInPath>("shift_filename", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/wire_rawId_x.txt"));
1310  desc.add<edm::FileInPath>("maxdrift_filename",
1311  edm::FileInPath("L1Trigger/DTTriggerPhase2/data/drift_time_per_chamber.txt"));
1312  desc.add<edm::FileInPath>("shift_theta_filename", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/theta_shift.txt"));
1313  desc.add<edm::FileInPath>("global_coords_filename",
1314  edm::FileInPath("L1Trigger/DTTriggerPhase2/data/global_coord_perp_x_phi0.txt"));
1315  desc.add<edm::FileInPath>("laterality_filename",
1316  edm::FileInPath("L1Trigger/DTTriggerPhase2/data/lat_predictions.dat"));
1317  desc.add<int>("algo", 0);
1318  desc.add<int>("minHits4Fit", 3);
1319  desc.add<bool>("splitPathPerSL", true);
1320  desc.addUntracked<bool>("debug", false);
1321  desc.addUntracked<bool>("dump", false);
1322  desc.add<edm::InputTag>("rpcRecHits", edm::InputTag("rpcRecHits"));
1323  desc.add<bool>("useRPC", false);
1324  desc.add<int>("bx_window", 1);
1325  desc.add<double>("phi_window", 50.0);
1326  desc.add<int>("max_quality_to_overwrite_t0", 9);
1327  desc.add<bool>("storeAllRPCHits", false);
1328  desc.add<bool>("activateBuffer", false);
1329  desc.add<double>("superCelltimewidth", 400);
1330  desc.add<int>("superCellspacewidth", 20);
1331  {
1333  psd0.addUntracked<bool>("debug", false);
1334  psd0.add<double>("angletan", 0.3);
1335  psd0.add<double>("anglebinwidth", 1.0);
1336  psd0.add<double>("posbinwidth", 2.1);
1337  psd0.add<double>("maxdeltaAngDeg", 10);
1338  psd0.add<double>("maxdeltaPos", 10);
1339  psd0.add<int>("UpperNumber", 6);
1340  psd0.add<int>("LowerNumber", 4);
1341  psd0.add<double>("MaxDistanceToWire", 0.03);
1342  psd0.add<int>("minNLayerHits", 6);
1343  psd0.add<int>("minSingleSLHitsMax", 3);
1344  psd0.add<int>("minSingleSLHitsMin", 3);
1345  psd0.add<bool>("allowUncorrelatedPatterns", true);
1346  psd0.add<int>("minUncorrelatedHits", 3);
1347  desc.add<edm::ParameterSetDescription>("HoughGrouping", psd0);
1348  }
1349  {
1351  psd0.add<edm::FileInPath>(
1352  "pattern_filename", edm::FileInPath("L1Trigger/DTTriggerPhase2/data/PseudoBayesPatterns_uncorrelated_v0.root"));
1353  psd0.addUntracked<bool>("debug", false);
1354  psd0.add<int>("minNLayerHits", 3);
1355  psd0.add<int>("minSingleSLHitsMax", 3);
1356  psd0.add<int>("minSingleSLHitsMin", 0);
1357  psd0.add<int>("allowedVariance", 1);
1358  psd0.add<bool>("allowDuplicates", false);
1359  psd0.add<bool>("setLateralities", true);
1360  psd0.add<bool>("allowUncorrelatedPatterns", true);
1361  psd0.add<int>("minUncorrelatedHits", 3);
1362  psd0.add<bool>("saveOnPlace", true);
1363  psd0.add<int>("maxPathsPerMatch", 256);
1364  desc.add<edm::ParameterSetDescription>("PseudoBayesPattern", psd0);
1365  }
1366  descriptions.add("dtTriggerPhase2PrimitiveDigis", desc);
1367 }
1368 
int station() const
Return the station number.
Definition: DTChamberId.h:45
std::unique_ptr< MotherGrouping > grouping_obj_
std::map< DTChamberId, DTDigiCollection, std::less< DTChamberId > > DTDigiMap
bool hasPosRF(int wh, int sec) const
void produce(edm::Event &iEvent, const edm::EventSetup &iEventSetup) override
Producer: process every event and generates trigger data.
int superLayer() const
Return the superlayer number.
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
constexpr int CHI2RES_CONV
Definition: constants.h:365
constexpr float PHIBRES_CONV
Definition: constants.h:364
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:32
std::unique_ptr< LateralityProvider > latprovider_
DTTrigPhase2Prod(const edm::ParameterSet &pset)
Constructor.
void processDigi(std::queue< std::pair< DTLayerId, DTDigi >> &inQ, std::vector< std::queue< std::pair< DTLayerId, DTDigi >> *> &vec)
std::unique_ptr< MPFilter > mpathhitsfilter_
edm::EDGetTokenT< DTDigiCollection > dtDigisToken_
std::vector< DTDigiCollection * > distribDigis(std::queue< std::pair< DTLayerId, DTDigi >> &inQ)
std::unique_ptr< RPCIntegrator > rpc_integrator_
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomH
std::unique_ptr< MuonPathConfirmator > mpathconfirmator_
edm::EDGetTokenT< RPCRecHitCollection > rpcRecHitsLabel_
Primitive< F, X >::type primitive(const F &f)
Definition: Primitive.h:41
std::vector< short > latcomb
void assignIndex(std::vector< metaPrimitive > &inMPaths)
const DTGeometry * dtGeo_
int iEvent
Definition: GenABIO.cc:224
void printmPC(const std::string &ss, const metaPrimitive &mP) const
DTChamberId chamberId() const
Return the corresponding ChamberId.
bool inner(const metaPrimitive &mp) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::unique_ptr< MuonPathAnalyzer > mpathanalyzer_
constexpr float KRES_CONV
Definition: constants.h:368
string inf
Definition: EcalCondDB.py:96
std::unique_ptr< MPFilter > mpathqualityenhancer_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void printmP(const std::string &ss, const metaPrimitive &mP) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr float ZRES_CONV
Definition: constants.h:367
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
std::unique_ptr< MPFilter > mpathcoifilter_
std::unique_ptr< MPFilter > mpathcorfilter_
RunID const & id() const
Definition: RunBase.h:39
Log< level::Info, false > LogInfo
MP_QUALITY
Definition: constants.h:44
bool outer(const metaPrimitive &mp) const
void endRun(edm::Run const &iRun, const edm::EventSetup &iEventSetup) override
endRun: finish things
std::unique_ptr< MPFilter > mpathredundantfilter_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr int TIME_TO_TDC_COUNTS
Definition: constants.h:235
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::shared_ptr< GlobalCoordsObtainer > globalcoordsobtainer_
std::pair< const_iterator, const_iterator > Range
std::unique_ptr< MuonPathAnalyzer > mpathassociator_
double b
Definition: hdecay.h:120
std::vector< DigiType >::const_iterator const_iterator
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< MPFilter > mpathqualityenhancerbayes_
constexpr int LHC_CLK_FREQ
Definition: constants.h:222
int rango(const metaPrimitive &mp) const
DTDigiMap::iterator DTDigiMap_iterator
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
int sector() const
Definition: DTChamberId.h:52
void assignIndexPerBX(std::vector< metaPrimitive > &inMPaths)
~DTTrigPhase2Prod() override
Destructor.
double a
Definition: hdecay.h:121
DTDigiMap::const_iterator DTDigiMap_const_iterator
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:48
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
constexpr float PHIRES_CONV
Definition: constants.h:363
int assignQualityOrder(const metaPrimitive &mP) const
const std::unordered_map< int, int > qmap_
void beginRun(edm::Run const &iRun, const edm::EventSetup &iEventSetup) override
Create Trigger Units before starting event processing.
def move(src, dest)
Definition: eostools.py:511
std::vector< std::pair< int, MuonPath > > primitives_
RunNumber_t run() const
Definition: RunID.h:26
Definition: Run.h:45
#define LogDebug(id)