68 using namespace cmsdt;
71 typedef std::map<DTChamberId, DTDigiCollection, std::less<DTChamberId>>
DTDigiMap;
97 bool hasPosRF(
int wh,
int sec)
const;
103 void setChiSquareThreshold(
float ch2Thr);
145 std::vector<DTDigiCollection*> distribDigis(std::queue<std::pair<DTLayerId, DTDigi>>& inQ);
146 void processDigi(std::queue<std::pair<DTLayerId, DTDigi>>& inQ,
147 std::vector<std::queue<std::pair<DTLayerId, DTDigi>>*>& vec);
153 void assignIndex(std::vector<metaPrimitive>& inMPaths);
154 void assignIndexPerBX(std::vector<metaPrimitive>& inMPaths);
157 const std::unordered_map<int, int>
qmap_;
162 bool operator()(std::pair<DTLayerId, DTDigi>
a, std::pair<DTLayerId, DTDigi>
b)
const {
163 return (a.second.time() < b.second.time());
165 }
const DigiTimeOrdering;
169 : qmap_({{9, 9}, {8, 8}, {7, 6}, {6, 7}, {5, 3}, {4, 5}, {3, 4}, {2, 2}, {1, 1}}) {
170 produces<L1Phase2MuDTPhContainer>();
210 LogDebug(
"DTTrigPhase2Prod") <<
"DTp2:constructor: JM analyzer";
214 LogDebug(
"DTTrigPhase2Prod") <<
"DTp2:constructor: Full chamber analyzer";
228 dtGeomH = esConsumes<DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
233 LogDebug(
"DTTrigPhase2Prod") <<
"DTp2: calling destructor" << std::endl;
238 LogDebug(
"DTTrigPhase2Prod") <<
"beginRun " << iRun.
id().
run();
240 LogDebug(
"DTTrigPhase2Prod") <<
"beginRun: getting DT geometry";
255 LogDebug(
"DTTrigPhase2Prod") <<
"produce";
260 LogDebug(
"DTTrigPhase2Prod") <<
"\t Getting the RPC RecHits" << std::endl;
270 for (
const auto& detUnitIt : *dtdigis) {
271 const DTLayerId& layId = detUnitIt.first;
274 digiMap[chambId].put(range, layId);
279 LogDebug(
"DTTrigPhase2Prod") <<
"produce - Getting and grouping digis per chamber using a buffer and super cells.";
281 LogDebug(
"DTTrigPhase2Prod") <<
"produce - Getting and grouping digis per chamber.";
290 if (dmit == digiMap.end())
295 std::vector<std::pair<DTLayerId, DTDigi>> tmpvec;
298 for (
const auto& dtLayerIdIt : (*dmit).second) {
300 digiIt != (dtLayerIdIt.second).second;
302 tmpvec.emplace_back(dtLayerIdIt.first, *digiIt);
311 std::sort(tmpvec.begin(), tmpvec.end(), DigiTimeOrdering);
312 std::queue<std::pair<DTLayerId, DTDigi>> timequeue;
314 for (
const auto& elem : tmpvec)
315 timequeue.emplace(elem);
319 std::vector<DTDigiCollection*> superCells;
325 while (!superCells.empty()) {
326 grouping_obj_->run(iEvent, iEventSetup, *(superCells.back()), muonpaths);
327 superCells.pop_back();
330 grouping_obj_->run(iEvent, iEventSetup, (*dmit).second, muonpaths);
336 for (
unsigned int i = 0;
i < muonpaths.size();
i++) {
338 ss << iEvent.
id().
event() <<
" mpath " <<
i <<
": ";
339 for (
int lay = 0; lay < muonpaths.at(
i)->nprimitives(); lay++)
340 ss << muonpaths.at(
i)->primitive(lay)->channelId() <<
" ";
341 for (
int lay = 0; lay < muonpaths.at(
i)->nprimitives(); lay++)
342 ss << muonpaths.at(
i)->primitive(lay)->tdcTimeStamp() <<
" ";
343 for (
int lay = 0; lay < muonpaths.at(
i)->nprimitives(); lay++)
344 ss << muonpaths.at(
i)->primitive(lay)->laterality() <<
" ";
345 LogInfo(
"DTTrigPhase2Prod") << ss.str();
356 for (
unsigned int i = 0;
i < filteredmuonpaths.size();
i++) {
358 ss << iEvent.
id().
event() <<
" filt. mpath " <<
i <<
": ";
359 for (
int lay = 0; lay < filteredmuonpaths.at(
i)->nprimitives(); lay++)
360 ss << filteredmuonpaths.at(
i)->primitive(lay)->channelId() <<
" ";
361 for (
int lay = 0; lay < filteredmuonpaths.at(
i)->nprimitives(); lay++)
362 ss << filteredmuonpaths.at(
i)->primitive(lay)->tdcTimeStamp() <<
" ";
363 LogInfo(
"DTTrigPhase2Prod") << ss.str();
372 LogDebug(
"DTTrigPhase2Prod") <<
"MUON PATHS found: " << muonpaths.size() <<
" (" << filteredmuonpaths.size()
373 <<
") in event " << iEvent.
id().
event();
375 LogDebug(
"DTTrigPhase2Prod") <<
"filling NmetaPrimtives" << std::endl;
376 std::vector<metaPrimitive> metaPrimitives;
380 LogDebug(
"DTTrigPhase2Prod") <<
"Fitting 1SL ";
381 mpathanalyzer_->run(iEvent, iEventSetup, filteredmuonpaths, metaPrimitives);
385 LogDebug(
"DTTrigPhase2Prod") <<
"Fitting 2SL at once ";
390 for (
unsigned int i = 0;
i < outmpaths.size();
i++) {
391 LogInfo(
"DTTrigPhase2Prod") << iEvent.
id().
event() <<
" mp " <<
i <<
": " << outmpaths.at(
i)->bxTimeValue() <<
" "
392 << outmpaths.at(
i)->horizPos() <<
" " << outmpaths.at(
i)->tanPhi() <<
" "
393 << outmpaths.at(
i)->phi() <<
" " << outmpaths.at(
i)->phiB() <<
" "
394 << outmpaths.at(
i)->quality() <<
" " << outmpaths.at(
i)->chiSquare();
396 for (
unsigned int i = 0;
i < metaPrimitives.size();
i++) {
398 ss << iEvent.
id().
event() <<
" mp " <<
i <<
": ";
399 printmP(ss.str(), metaPrimitives.at(
i));
404 filteredmuonpaths.clear();
411 LogDebug(
"DTTrigPhase2Prod") <<
"declaring new vector for filtered" << std::endl;
413 std::vector<metaPrimitive> filteredMetaPrimitives;
418 for (
unsigned int i = 0;
i < filteredMetaPrimitives.size();
i++) {
420 ss << iEvent.
id().
event() <<
" filtered mp " <<
i <<
": ";
421 printmP(ss.str(), filteredMetaPrimitives.at(
i));
425 metaPrimitives.clear();
426 metaPrimitives.erase(metaPrimitives.begin(), metaPrimitives.end());
429 LogDebug(
"DTTrigPhase2Prod") <<
"DTp2 in event:" << iEvent.
id().
event() <<
" we found "
430 << filteredMetaPrimitives.size() <<
" filteredMetaPrimitives (superlayer)"
433 LogDebug(
"DTTrigPhase2Prod") <<
"filteredMetaPrimitives: starting correlations" << std::endl;
439 std::vector<metaPrimitive> correlatedMetaPrimitives;
441 mpathassociator_->run(iEvent, iEventSetup, dtdigis, filteredMetaPrimitives, correlatedMetaPrimitives);
443 for (
const auto& muonpath : outmpaths) {
444 correlatedMetaPrimitives.emplace_back(muonpath->rawId(),
445 (double)muonpath->bxTimeValue(),
446 muonpath->horizPos(),
450 muonpath->phi_cmssw(),
451 muonpath->phiB_cmssw(),
452 muonpath->chiSquare(),
453 (int)muonpath->quality(),
454 muonpath->primitive(0)->channelId(),
455 muonpath->primitive(0)->tdcTimeStamp(),
456 muonpath->primitive(0)->laterality(),
457 muonpath->primitive(1)->channelId(),
458 muonpath->primitive(1)->tdcTimeStamp(),
459 muonpath->primitive(1)->laterality(),
460 muonpath->primitive(2)->channelId(),
461 muonpath->primitive(2)->tdcTimeStamp(),
462 muonpath->primitive(2)->laterality(),
463 muonpath->primitive(3)->channelId(),
464 muonpath->primitive(3)->tdcTimeStamp(),
465 muonpath->primitive(3)->laterality(),
466 muonpath->primitive(4)->channelId(),
467 muonpath->primitive(4)->tdcTimeStamp(),
468 muonpath->primitive(4)->laterality(),
469 muonpath->primitive(5)->channelId(),
470 muonpath->primitive(5)->tdcTimeStamp(),
471 muonpath->primitive(5)->laterality(),
472 muonpath->primitive(6)->channelId(),
473 muonpath->primitive(6)->tdcTimeStamp(),
474 muonpath->primitive(6)->laterality(),
475 muonpath->primitive(7)->channelId(),
476 muonpath->primitive(7)->tdcTimeStamp(),
477 muonpath->primitive(7)->laterality());
480 filteredMetaPrimitives.clear();
483 LogDebug(
"DTTrigPhase2Prod") <<
"DTp2 in event:" << iEvent.
id().
event() <<
" we found "
484 << correlatedMetaPrimitives.size() <<
" correlatedMetPrimitives (chamber)";
487 LogInfo(
"DTTrigPhase2Prod") <<
"DTp2 in event:" << iEvent.
id().
event() <<
" we found "
488 << correlatedMetaPrimitives.size() <<
" correlatedMetPrimitives (chamber)";
490 for (
unsigned int i = 0;
i < correlatedMetaPrimitives.size();
i++) {
492 ss << iEvent.
id().
event() <<
" correlated mp " <<
i <<
": ";
493 printmPC(ss.str(), correlatedMetaPrimitives.at(
i));
497 double shift_back = 0;
516 vector<L1Phase2MuDTPhDigi> outP2Ph;
517 vector<L1Phase2MuDTExtPhDigi> outExtP2Ph;
518 vector<L1Phase2MuDTThDigi> outP2Th;
519 vector<L1Phase2MuDTExtThDigi> outExtP2Th;
523 for (
const auto& metaPrimitiveIt : correlatedMetaPrimitives) {
527 LogDebug(
"DTTrigPhase2Prod") <<
"looping in final vector: SuperLayerId" << chId <<
" x=" << metaPrimitiveIt.x
528 <<
" quality=" << metaPrimitiveIt.quality
529 <<
" BX=" << round(metaPrimitiveIt.t0 / 25.) <<
" index=" << metaPrimitiveIt.index;
531 int sectorTP = chId.
sector();
538 sectorTP = sectorTP - 1;
540 if (metaPrimitiveIt.quality <
LOWLOWQ || metaPrimitiveIt.quality ==
CHIGHQ) {
541 if (
inner(metaPrimitiveIt))
548 LogDebug(
"DTTrigPhase2Prod") <<
"pushing back phase-2 dataformat carlo-federica dataformat";
552 int pathWireId[8] = {metaPrimitiveIt.wi1,
559 metaPrimitiveIt.wi8};
561 int pathTDC[8] = {
max((
int)round(metaPrimitiveIt.tdc1 - shift_back *
LHC_CLK_FREQ), -1),
562 max((
int)round(metaPrimitiveIt.tdc2 - shift_back * LHC_CLK_FREQ), -1),
563 max((
int)round(metaPrimitiveIt.tdc3 - shift_back * LHC_CLK_FREQ), -1),
564 max((
int)round(metaPrimitiveIt.tdc4 - shift_back * LHC_CLK_FREQ), -1),
565 max((
int)round(metaPrimitiveIt.tdc5 - shift_back * LHC_CLK_FREQ), -1),
566 max((
int)round(metaPrimitiveIt.tdc6 - shift_back * LHC_CLK_FREQ), -1),
567 max((
int)round(metaPrimitiveIt.tdc7 - shift_back * LHC_CLK_FREQ), -1),
568 max((
int)round(metaPrimitiveIt.tdc8 - shift_back * LHC_CLK_FREQ), -1)};
570 int pathLat[8] = {metaPrimitiveIt.lat1,
571 metaPrimitiveIt.lat2,
572 metaPrimitiveIt.lat3,
573 metaPrimitiveIt.lat4,
574 metaPrimitiveIt.lat5,
575 metaPrimitiveIt.lat6,
576 metaPrimitiveIt.lat7,
577 metaPrimitiveIt.lat8};
580 outExtP2Ph.emplace_back(
588 metaPrimitiveIt.quality,
589 metaPrimitiveIt.index,
590 (int)round(metaPrimitiveIt.t0) - shift_back *
LHC_CLK_FREQ,
592 (int)round(metaPrimitiveIt.x * 1000),
593 (int)round(metaPrimitiveIt.tanPhi * 1000),
594 (int)round(metaPrimitiveIt.phi_cmssw *
PHIRES_CONV),
596 metaPrimitiveIt.rpcFlag,
604 (
int)round(metaPrimitiveIt.t0 / (
float)
LHC_CLK_FREQ) - shift_back,
611 metaPrimitiveIt.quality,
612 metaPrimitiveIt.index,
613 (int)round(metaPrimitiveIt.t0) - shift_back *
LHC_CLK_FREQ,
615 metaPrimitiveIt.rpcFlag
620 int pathWireId[4] = {metaPrimitiveIt.wi1, metaPrimitiveIt.wi2, metaPrimitiveIt.wi3, metaPrimitiveIt.wi4};
622 int pathTDC[4] = {
max((
int)round(metaPrimitiveIt.tdc1 - shift_back *
LHC_CLK_FREQ), -1),
623 max((
int)round(metaPrimitiveIt.tdc2 - shift_back * LHC_CLK_FREQ), -1),
624 max((
int)round(metaPrimitiveIt.tdc3 - shift_back * LHC_CLK_FREQ), -1),
625 max((
int)round(metaPrimitiveIt.tdc4 - shift_back * LHC_CLK_FREQ), -1)};
627 int pathLat[4] = {metaPrimitiveIt.lat1, metaPrimitiveIt.lat2, metaPrimitiveIt.lat3, metaPrimitiveIt.lat4};
630 outExtP2Th.emplace_back(
635 (int)round(metaPrimitiveIt.phi *
ZRES_CONV),
636 (int)round(metaPrimitiveIt.phiB *
KRES_CONV),
637 metaPrimitiveIt.quality,
638 metaPrimitiveIt.index,
639 (int)round(metaPrimitiveIt.t0) - shift_back *
LHC_CLK_FREQ,
641 (int)round(metaPrimitiveIt.x * 1000),
642 (int)round(metaPrimitiveIt.phi_cmssw *
PHIRES_CONV),
644 metaPrimitiveIt.rpcFlag,
652 (
int)round(metaPrimitiveIt.t0 / (
float)
LHC_CLK_FREQ) - shift_back,
656 (int)round(metaPrimitiveIt.phi *
ZRES_CONV),
657 (int)round(metaPrimitiveIt.phiB *
KRES_CONV),
658 metaPrimitiveIt.quality,
659 metaPrimitiveIt.index,
660 (int)round(metaPrimitiveIt.t0) - shift_back *
LHC_CLK_FREQ,
662 metaPrimitiveIt.rpcFlag
670 for (
auto rpc_dt_digi =
rpc_integrator_->rpcRecHits_translated_.begin();
673 outP2Ph.push_back(*rpc_dt_digi);
680 resultExtP2Ph->setContainer(outExtP2Ph);
685 resultP2Ph->setContainer(outP2Ph);
689 outExtP2Ph.erase(outExtP2Ph.begin(), outExtP2Ph.end());
691 outP2Ph.erase(outP2Ph.begin(), outP2Ph.end());
696 resultExtP2Th->setContainer(outExtP2Th);
701 resultP2Th->setContainer(outP2Th);
705 outExtP2Th.erase(outExtP2Th.begin(), outExtP2Th.end());
707 outP2Th.erase(outP2Th.begin(), outP2Th.end());
721 return (counter > 2);
726 return (counter > 2);
733 LogInfo(
"DTTrigPhase2Prod") << ss << (int)slId <<
"\t " << setw(2) << left << mP.
wi1 <<
" " << setw(2) << left
734 << mP.
wi2 <<
" " << setw(2) << left << mP.
wi3 <<
" " << setw(2) << left << mP.
wi4 <<
" "
735 << setw(5) << left << mP.
tdc1 <<
" " << setw(5) << left << mP.
tdc2 <<
" " << setw(5)
736 << left << mP.
tdc3 <<
" " << setw(5) << left << mP.
tdc4 <<
" " << setw(10) << right
737 << mP.
x <<
" " << setw(9) << left << mP.
tanPhi <<
" " << setw(5) << left << mP.
t0 <<
" "
738 << setw(13) << left << mP.
chi2 <<
" r:" <<
rango(mP);
743 LogInfo(
"DTTrigPhase2Prod") << ss << (int)ChId <<
"\t " << setw(2) << left << mP.
wi1 <<
" " << setw(2) << left
744 << mP.
wi2 <<
" " << setw(2) << left << mP.
wi3 <<
" " << setw(2) << left << mP.
wi4 <<
" "
745 << setw(2) << left << mP.
wi5 <<
" " << setw(2) << left << mP.
wi6 <<
" " << setw(2) << left
746 << mP.
wi7 <<
" " << setw(2) << left << mP.
wi8 <<
" " << setw(5) << left << mP.
tdc1 <<
" "
747 << setw(5) << left << mP.
tdc2 <<
" " << setw(5) << left << mP.
tdc3 <<
" " << setw(5)
748 << left << mP.
tdc4 <<
" " << setw(5) << left << mP.
tdc5 <<
" " << setw(5) << left
749 << mP.
tdc6 <<
" " << setw(5) << left << mP.
tdc7 <<
" " << setw(5) << left << mP.
tdc8
750 <<
" " << setw(2) << left << mP.
lat1 <<
" " << setw(2) << left << mP.
lat2 <<
" "
751 << setw(2) << left << mP.
lat3 <<
" " << setw(2) << left << mP.
lat4 <<
" " << setw(2)
752 << left << mP.
lat5 <<
" " << setw(2) << left << mP.
lat6 <<
" " << setw(2) << left
753 << mP.
lat7 <<
" " << setw(2) << left << mP.
lat8 <<
" " << setw(10) << right << mP.
x <<
" "
754 << setw(9) << left << mP.
tanPhi <<
" " << setw(5) << left << mP.
t0 <<
" " << setw(13)
755 << left << mP.
chi2 <<
" r:" <<
rango(mP);
767 std::map<int, std::vector<metaPrimitive>> primsPerBX;
773 for (
auto& prims : primsPerBX) {
775 for (
const auto&
primitive : prims.second)
784 for (
auto& metaPrimitiveIt : inMPaths) {
786 rawId = metaPrimitiveIt.rawId;
790 for (
auto& metaPrimitiveItN : inMPaths) {
793 if (rawId != metaPrimitiveItN.rawId)
796 metaPrimitiveIt.index =
inf;
798 }
else if (iOrder < nOrder) {
800 }
else if (iOrder > nOrder) {
801 metaPrimitiveItN.index++;
802 }
else if (iOrder == nOrder) {
805 }
else if (
std::abs(metaPrimitiveIt.phiB) <
std::abs(metaPrimitiveItN.phiB)) {
806 metaPrimitiveItN.index++;
821 std::vector<std::queue<std::pair<DTLayerId, DTDigi>>*> tmpVector;
823 std::vector<DTDigiCollection*> collVector;
825 while (!inQ.empty()) {
828 for (
auto& sQ : tmpVector) {
830 while (!sQ->empty()) {
831 tmpColl.insertDigi((sQ->front().first), (sQ->front().second));
834 collVector.push_back(&tmpColl);
840 std::vector<std::queue<std::pair<DTLayerId, DTDigi>>*>& vec) {
841 bool classified =
false;
843 for (
auto& sC : vec) {
859 std::queue<std::pair<DTLayerId, DTDigi>> newQueue;
861 std::pair<DTLayerId, DTDigi> tmpPair;
863 newQueue.push(tmpPair);
866 vec.push_back(&newQueue);
int assignQualityOrder(const metaPrimitive &mP) const
EventNumber_t event() const
std::unique_ptr< MotherGrouping > grouping_obj_
std::map< DTChamberId, DTDigiCollection, std::less< DTChamberId > > DTDigiMap
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
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.
edm::ConsumesCollector consumesColl(consumesCollector())
constexpr int CHI2RES_CONV
constexpr float PHIBRES_CONV
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
bool getByToken(EDGetToken token, Handle< PROD > &result) const
DTTrigPhase2Prod(const edm::ParameterSet &pset)
Constructor.
DTChamberId chamberId() const
Return the corresponding ChamberId.
DTGeometry const * dtGeo_
#define DEFINE_FWK_MODULE(type)
std::vector< MuonPathPtr > MuonPathPtrs
produces< L1Phase2MuDTExtThContainer >()
edm::EDGetTokenT< DTDigiCollection > dtDigisToken_
void processDigi(std::queue< std::pair< DTLayerId, DTDigi >> &inQ, std::vector< std::queue< std::pair< DTLayerId, DTDigi >> * > &vec)
std::vector< DTDigiCollection * > distribDigis(std::queue< std::pair< DTLayerId, DTDigi >> &inQ)
std::unique_ptr< RPCIntegrator > rpc_integrator_
void printmPC(const std::string &ss, const metaPrimitive &mP) const
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomH
edm::EDGetTokenT< RPCRecHitCollection > rpcRecHitsLabel_
Primitive< F, X >::type primitive(const F &f)
const uint16_t range(const Frame &aFrame)
produces< L1Phase2MuDTExtPhContainer >()
void assignIndex(std::vector< metaPrimitive > &inMPaths)
int superCellhalfspacewidth_
DTChamberId id() const
Return the DTChamberId of this chamber.
std::unique_ptr< MuonPathAnalyzer > mpathanalyzer_
constexpr float KRES_CONV
std::unique_ptr< MPFilter > mpathqualityenhancer_
Abs< T >::type abs(const T &t)
int superLayer() const
Return the superlayer number.
std::unique_ptr< MuonPathAssociator > mpathassociator_
constexpr float ZRES_CONV
bool inner(const metaPrimitive &mp) const
float superCelltimewidth_
Log< level::Info, false > LogInfo
void endRun(edm::Run const &iRun, const edm::EventSetup &iEventSetup) override
endRun: finish things
std::unique_ptr< MPFilter > mpathredundantfilter_
std::shared_ptr< GlobalCoordsObtainer > globalcoordsobtainer_
std::pair< const_iterator, const_iterator > Range
bool outer(const metaPrimitive &mp) const
std::string geometry_tag_
std::vector< DigiType >::const_iterator const_iterator
constexpr int LHC_CLK_FREQ
DTDigiMap::iterator DTDigiMap_iterator
void assignIndexPerBX(std::vector< metaPrimitive > &inMPaths)
~DTTrigPhase2Prod() override
Destructor.
static std::atomic< unsigned int > counter
DTDigiMap::const_iterator DTDigiMap_const_iterator
constexpr float PHIRES_CONV
int station() const
Return the station number.
int wheel() const
Return the wheel number.
const std::unordered_map< int, int > qmap_
void printmP(const std::string &ss, const metaPrimitive &mP) const
void beginRun(edm::Run const &iRun, const edm::EventSetup &iEventSetup) override
Create Trigger Units before starting event processing.
int rango(const metaPrimitive &mp) const
std::vector< std::pair< int, MuonPath > > primitives_
produces< L1Phase2MuDTThContainer >()