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,
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>();
171 produces<L1Phase2MuDTThContainer>();
172 produces<L1Phase2MuDTExtPhContainer>();
173 produces<L1Phase2MuDTExtThContainer>();
175 debug_ =
pset.getUntrackedParameter<
bool>(
"debug");
176 dump_ =
pset.getUntrackedParameter<
bool>(
"dump");
178 do_correlation_ =
pset.getParameter<
bool>(
"do_correlation");
179 scenario_ =
pset.getParameter<
int>(
"scenario");
181 df_extended_ =
pset.getParameter<
int>(
"df_extended");
183 dtDigisToken_ = consumes<DTDigiCollection>(
pset.getParameter<
edm::InputTag>(
"digiTag"));
185 rpcRecHitsLabel_ = consumes<RPCRecHitCollection>(
pset.getParameter<
edm::InputTag>(
"rpcRecHits"));
186 useRPC_ =
pset.getParameter<
bool>(
"useRPC");
189 algo_ =
pset.getParameter<
int>(
"algo");
192 geometry_tag_ =
pset.getUntrackedParameter<
std::string>(
"geometry_tag",
"");
195 globalcoordsobtainer_ = std::make_shared<GlobalCoordsObtainer>(
pset);
196 globalcoordsobtainer_->generate_luts();
200 std::make_unique<PseudoBayesGrouping>(
pset.getParameter<
edm::ParameterSet>(
"PseudoBayesPattern"), consumesColl);
203 std::make_unique<HoughGrouping>(
pset.getParameter<
edm::ParameterSet>(
"HoughGrouping"), consumesColl);
205 grouping_obj_ = std::make_unique<InitialGrouping>(
pset, consumesColl);
210 LogDebug(
"DTTrigPhase2Prod") <<
"DTp2:constructor: JM analyzer";
211 mpathanalyzer_ = std::make_unique<MuonPathAnalyticAnalyzer>(
pset, consumesColl, globalcoordsobtainer_);
214 LogDebug(
"DTTrigPhase2Prod") <<
"DTp2:constructor: Full chamber analyzer";
215 mpathanalyzer_ = std::make_unique<MuonPathAnalyzerInChamber>(
pset, consumesColl, globalcoordsobtainer_);
219 activateBuffer_ =
pset.getParameter<
bool>(
"activateBuffer");
220 superCellhalfspacewidth_ =
pset.getParameter<
int>(
"superCellspacewidth") / 2;
221 superCelltimewidth_ =
pset.getParameter<
double>(
"superCelltimewidth");
223 mpathqualityenhancer_ = std::make_unique<MPQualityEnhancerFilter>(
pset);
224 mpathredundantfilter_ = std::make_unique<MPRedundantFilter>(
pset);
225 mpathassociator_ = std::make_unique<MuonPathAssociator>(
pset, consumesColl, globalcoordsobtainer_);
226 rpc_integrator_ = std::make_unique<RPCIntegrator>(
pset, consumesColl);
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()) {
327 superCells.pop_back();
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() <<
" ";
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() <<
" ";
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 ";
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 <<
": ";
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;
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),
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,
592 (
int)round(metaPrimitiveIt.x * 1000),
593 (
int)round(metaPrimitiveIt.tanPhi * 1000),
596 metaPrimitiveIt.rpcFlag,
604 (
int)round(metaPrimitiveIt.t0 / (
float)
LHC_CLK_FREQ) - shift_back,
611 metaPrimitiveIt.quality,
612 metaPrimitiveIt.index,
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),
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(
637 metaPrimitiveIt.quality,
638 metaPrimitiveIt.index,
641 (
int)round(metaPrimitiveIt.x * 1000),
644 metaPrimitiveIt.rpcFlag,
652 (
int)round(metaPrimitiveIt.t0 / (
float)
LHC_CLK_FREQ) - shift_back,
658 metaPrimitiveIt.quality,
659 metaPrimitiveIt.index,
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());
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);
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);