23 #include "boost/dynamic_bitset.hpp" 29 double phiGmtUnit = 2. *
M_PI / 576.;
30 return phi * phiGmtUnit;
47 : omtfConfig(omtfConfig),
49 magneticFieldEsToken(magneticFieldEsToken),
50 propagatorEsToken(propagatorEsToken) {
52 TFile
inFile(muonMatcherFileName.c_str());
53 edm::LogImportant(
"l1tOmtfEventPrint") <<
" CandidateSimMuonMatcher: using muonMatcherFileName " 54 << muonMatcherFileName << std::endl;
63 <<
" CandidateSimMuonMatcher: candidateSimMuonMatcherType " 85 const std::shared_ptr<OMTFinput>&
input,
88 const std::vector<l1t::RegionalMuonCand>& candMuons) {
92 if (gbCandidate->getPtConstr() > 0) {
93 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::observeProcesorEmulation procIndx" << procIndx <<
" " 94 << *gbCandidate << std::endl;
95 this->gbCandidates.emplace_back(gbCandidate);
111 LogTrace(
"l1tOmtfEventPrint") <<
"simTrackIsMuonInOmtf: simTrack type " << std::setw(3) <<
simTrack.type() <<
" pt " 112 << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " << std::setw(9)
113 <<
simTrack.momentum().eta() <<
" phi " << std::setw(9) <<
simTrack.momentum().phi()
120 LogTrace(
"l1tOmtfEventPrint") <<
"simTrackIsMuonInOmtf: is in OMTF";
122 LogTrace(
"l1tOmtfEventPrint") <<
"simTrackIsMuonInOmtf: not in OMTF";
130 if (
simTrack.eventId().bunchCrossing() != 0)
140 if (
simTrack.eventId().bunchCrossing() == 0)
168 if (trackingParticle.
pt() < 2.5)
172 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticleIsMuonInOmtfBx0, pdgId " << std::setw(3)
173 << trackingParticle.
pdgId() <<
" pt " << std::setw(9) << trackingParticle.
pt()
174 <<
" eta " << std::setw(9) << trackingParticle.
momentum().eta() <<
" phi " 175 << std::setw(9) << trackingParticle.
momentum().phi() <<
" event " 177 << trackingParticle.
g4Tracks().at(0).trackId() <<
" parentVertex Rho " 178 << trackingParticle.
parentVertex()->position().Rho() <<
" eta " 179 << trackingParticle.
parentVertex()->position().eta() <<
" phi " 180 << trackingParticle.
parentVertex()->position().phi() << std::endl;
182 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticleIsMuonInOmtfBx0, pdgId " << std::setw(3)
183 << trackingParticle.
pdgId() <<
" pt " << std::setw(9) << trackingParticle.
pt()
184 <<
" eta " << std::setw(9) << trackingParticle.
momentum().eta() <<
" phi " 185 << std::setw(9) << trackingParticle.
momentum().phi() <<
" trackId " 186 << trackingParticle.
g4Tracks().at(0).trackId();
206 std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {
207 LogTrace(
"l1tOmtfEventPrint") <<
"\nCandidateSimMuonMatcher::observeEventEnd" << std::endl;
209 std::vector<const l1t::RegionalMuonCand*> ghostBustedRegionalCands =
220 LogTrace(
"l1tOmtfEventPrint") <<
"simTraksHandle size " << simTraksHandle.
product()->size() << std::endl;
221 LogTrace(
"l1tOmtfEventPrint") <<
"simVertices size " <<
simVertices.product()->size() << std::endl;
230 ghostBustedProcMuons,
239 ghostBustedProcMuons,
248 LogTrace(
"l1tOmtfEventPrint") <<
"\nCandidateSimMuonMatcher::observeEventEnd trackingParticleHandle size " 249 << trackingParticleHandle.
product()->size() << std::endl;
252 std::function<bool(const TrackingParticle&)> trackParticleFilter =
255 match(ghostBustedRegionalCands, ghostBustedProcMuons, trackingParticleHandle.
product(), trackParticleFilter);
264 edm::LogError(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::ghostBust(): gbCandidates.size() " 268 boost::dynamic_bitset<> isKilled(mtfCands->
size(0),
false);
270 for (
unsigned int i1 = 0;
i1 < mtfCands->
size(0); ++
i1) {
271 if (mtfCands->
at(0,
i1).hwPt() == 0)
273 LogTrace(
"l1tOmtfEventPrint") <<
"\nCandidateSimMuonMatcher::ghostBust regionalCand pt " << std::setw(3)
274 << mtfCands->
at(0,
i1).hwPt() <<
" qual " << std::setw(2)
275 << mtfCands->
at(0,
i1).hwQual() <<
" proc " << std::setw(2)
276 << mtfCands->
at(0,
i1).processor();
277 for (
unsigned int i2 =
i1 + 1;
i2 < mtfCands->
size(0); ++
i2) {
278 auto& mtfCand1 = mtfCands->
at(0,
i1);
279 auto& mtfCand2 = mtfCands->
at(0,
i2);
280 if (mtfCand2.hwPt() == 0)
283 if (
std::abs(mtfCand1.hwEta() - mtfCand2.hwEta()) < (0.3 / 0.010875)) {
309 std::vector<const l1t::RegionalMuonCand*> resultCands;
311 for (
unsigned int i1 = 0;
i1 < mtfCands->
size(0); ++
i1) {
313 if (!isKilled[
i1] && mtfCands->
at(0,
i1).hwPt()) {
314 resultCands.push_back(&(mtfCands->
at(0,
i1)));
318 if (mtfCands->
at(0,
i1).hwPt()) {
319 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::ghostBust\n regionalCand pt " << std::setw(3)
320 << mtfCands->
at(0,
i1).hwPt() <<
" qual " << std::setw(2)
321 << mtfCands->
at(0,
i1).hwQual() <<
" proc " << std::setw(2)
322 << mtfCands->
at(0,
i1).processor() <<
" eta " << std::setw(4)
323 << mtfCands->
at(0,
i1).hwEta() <<
" gloablEta " << std::setw(8)
324 << mtfCands->
at(0,
i1).hwEta() * 0.010875 <<
" hwPhi " << std::setw(3)
325 << mtfCands->
at(0,
i1).hwPhi() <<
" globalPhi " << std::setw(8)
327 mtfCands->
at(0,
i1).processor()))
328 <<
" fireadLayers " << std::bitset<18>(mtfCands->
at(0,
i1).trackAddress().at(0))
329 <<
" gb isKilled " << isKilled.test(
i1) << std::endl;
335 if (resultCands.size() >= 3)
336 LogTrace(
"l1tOmtfEventPrint") <<
" ghost !!!!!! " << std::endl;
337 LogTrace(
"l1tOmtfEventPrint") << std::endl;
364 int charge = trackingParticle.
pdgId() > 0 ? -1 : 1;
367 GlobalPoint r3GP(trackingParticle.
vx(), trackingParticle.
vy(), trackingParticle.
vz());
379 edm::LogImportant(
"l1tOmtfEventPrint") <<
"Track with no vertex, defaulting to (0,0,0)";
383 edm::LogImportant(
"l1tOmtfEventPrint") <<
"simVertex.vertexId() != vtxInd. simVertex.vertexId() " 384 <<
simVertex.vertexId() <<
" vtxInd " <<
vtxInd <<
" !!!!!!!!!!!!!!!!!";
404 static const float inv_sqrt_2pi = 0.3989422804014327;
405 float a = (
x -
m) /
s;
416 double candGloablEta = muonCand->
hwEta() * 0.010875;
422 if (candGlobalPhi >
M_PI)
423 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
441 result.muonCand = muonCand;
442 result.procMuon = procMuon;
444 double treshold = 6. * sigma;
446 treshold = 7. * sigma;
448 treshold = 20. * sigma;
462 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: simTrack type " <<
simTrack.type() <<
" pt " 463 << std::setw(8) <<
simTrack.momentum().pt() <<
" eta " << std::setw(8)
464 <<
simTrack.momentum().eta() <<
" phi " << std::setw(8) <<
simTrack.momentum().phi()
467 << muonCand->
hwPt() <<
" candGloablEta " << std::setw(8) << candGloablEta
468 <<
" candGlobalPhi " << std::setw(8) << candGlobalPhi <<
" hwQual " 469 << muonCand->
hwQual() <<
" deltaEta " << std::setw(8) <<
result.deltaEta
470 <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi <<
" sigma " << std::setw(8)
471 << sigma <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood <<
" result " 472 << (short)
result.result << std::endl;
484 double candGloablEta = muonCand->
hwEta() * 0.010875;
490 if (candGlobalPhi >
M_PI)
491 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
511 result.muonCand = muonCand;
512 result.procMuon = procMuon;
514 double treshold = 6. * sigma;
515 if (trackingParticle.
pt() > 20)
516 treshold = 7. * sigma;
517 if (trackingParticle.
pt() > 100)
518 treshold = 20. * sigma;
523 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: trackingParticle type " 524 << trackingParticle.
pdgId() <<
" pt " << std::setw(8) << trackingParticle.
pt()
525 <<
" eta " << std::setw(8) << trackingParticle.
momentum().eta() <<
" phi " 526 << std::setw(8) << trackingParticle.
momentum().phi() <<
" propagation eta " 529 <<
" candGloablEta " << std::setw(8) << candGloablEta <<
" candGlobalPhi " 530 << std::setw(8) << candGlobalPhi <<
" hwQual " << muonCand->
hwQual() <<
" deltaEta " 531 << std::setw(8) <<
result.deltaEta <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi
532 <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood <<
" result " 533 << (short)
result.result << std::endl;
540 std::vector<const l1t::RegionalMuonCand*>& muonCands,
545 return a.matchingLikelihood >
b.matchingLikelihood;
562 std::vector<MatchingResult> cleanedMatchingResults;
566 cleanedMatchingResults.push_back(matchingResult);
578 unsigned int iCand = 0;
579 for (
auto& muonCand : muonCands) {
581 for (
auto& matchingResult : cleanedMatchingResults) {
582 if (matchingResult.muonCand == muonCand) {
590 result.muonCand = muonCand;
591 result.procMuon = ghostBustedProcMuons.at(iCand);
592 cleanedMatchingResults.push_back(
result);
597 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__
598 <<
" cleanedMatchingResults:" << std::endl;
599 for (
auto&
result : cleanedMatchingResults) {
601 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__ <<
" simTrack type " 602 <<
result.pdgId <<
" pt " << std::setw(8) <<
result.genPt <<
" eta " << std::setw(8)
603 <<
result.genEta <<
" phi " << std::setw(8) <<
result.genPhi;
605 LogTrace(
"l1tOmtfEventPrint") <<
"no matched track ";
608 LogTrace(
"l1tOmtfEventPrint") <<
" muonCand pt " << std::setw(8) <<
result.muonCand->hwPt() <<
" hwQual " 609 <<
result.muonCand->hwQual() <<
" hwEta " <<
result.muonCand->hwEta()
610 <<
" deltaEta " << std::setw(8) <<
result.deltaEta <<
" deltaPhi " << std::setw(8)
611 <<
result.deltaPhi <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood
612 <<
" result " << (short)
result.result;
613 LogTrace(
"l1tOmtfEventPrint") <<
" procMuon " << *(
result.procMuon) << std::endl;
615 LogTrace(
"l1tOmtfEventPrint") <<
" no muonCand " 616 <<
" result " << (short)
result.result << std::endl;
618 LogTrace(
"l1tOmtfEventPrint") <<
" " << std::endl;
620 return cleanedMatchingResults;
634 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, simTrack type " << std::setw(3) <<
simTrack.type()
635 <<
" pt " << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " << std::setw(9)
636 <<
simTrack.momentum().eta() <<
" phi " << std::setw(9) <<
simTrack.momentum().phi()
645 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" propagation failed: genPt " <<
result.genPt
646 <<
" genEta " <<
result.genEta <<
" eventId " <<
simTrack.eventId().event()
657 <<
"CandidateSimMuonMatcher::match simTrack IS in OMTF region, matching to the omtfCands";
659 LogTrace(
"l1tOmtfEventPrint") <<
"simTrack NOT in OMTF region ";
670 unsigned int iCand = 0;
671 for (
auto& muonCand : muonCands) {
695 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
704 std::vector<const l1t::RegionalMuonCand*>& muonCands,
709 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match trackingParticles->size() " 715 if (simTrackFilter(trackingParticle) ==
false)
718 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, trackingParticle type " << std::setw(3)
719 << trackingParticle.pdgId() <<
" pt " << std::setw(9) << trackingParticle.pt()
720 <<
" eta " << std::setw(9) << trackingParticle.momentum().eta() <<
" phi " 721 << std::setw(9) << trackingParticle.momentum().phi() << std::endl;
727 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match:" << __LINE__ <<
" propagation failed" 734 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, tsof.globalPosition().eta() " 741 <<
"CandidateSimMuonMatcher::match trackingParticle IS in OMTF region, matching to the omtfCands";
743 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticle NOT in OMTF region ";
755 unsigned int iCand = 0;
756 for (
auto& muonCand : muonCands) {
763 result =
match(muonCand, ghostBustedProcMuons.at(iCand), trackingParticle, tsof);
776 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
784 std::vector<const l1t::RegionalMuonCand*>& muonCands,
795 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::matchSimple: simTrack type " << std::setw(3)
796 <<
simTrack.type() <<
" pt " << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " 797 << std::setw(9) <<
simTrack.momentum().eta() <<
" phi " << std::setw(9)
798 <<
simTrack.momentum().phi() << std::endl;
802 unsigned int iCand = 0;
803 for (
auto& muonCand : muonCands) {
809 double candGloablEta = muonCand->hwEta() * 0.010875;
813 if (candGlobalPhi >
M_PI)
814 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
822 result.muonCand = muonCand;
823 result.procMuon = ghostBustedProcMuons.at(iCand);
838 double treshold = 0.7;
841 else if (
simTrack.momentum().pt() < 10)
843 else if (
simTrack.momentum().pt() < 20)
850 result.matchingLikelihood = 1. / 0.001;
855 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::matchSimple: simTrack type " <<
simTrack.type()
856 <<
" pt " << std::setw(8) <<
simTrack.momentum().pt() <<
" eta " << std::setw(8)
857 <<
simTrack.momentum().eta() <<
" phi " << std::setw(8)
858 <<
simTrack.momentum().phi() <<
"\n muonCand pt " << std::setw(8)
859 << muonCand->hwPt() <<
" candGloablEta " << std::setw(8) << candGloablEta
860 <<
" candGlobalPhi " << std::setw(8) << candGlobalPhi <<
" hwQual " 861 << muonCand->hwQual() <<
" deltaEta " << std::setw(8) <<
result.deltaEta
862 <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi <<
" matchingLikelihood " 863 <<
result.matchingLikelihood <<
" result " << (short)
result.result << std::endl;
881 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
MatchingResult match(const l1t::RegionalMuonCand *omtfCand, const AlgoMuonPtr &procMuon, const SimTrack &simTrack, TrajectoryStateOnSurface &tsof)
T getParameter(std::string const &) const
EncodedEventId eventId() const
Signal source, crossing number.
Vector momentum() const
spatial momentum vector
int event() const
get the contents of the subdetector field (should be protected?)
double hwGmtPhiToGlobalPhi(int phi)
double vx() const
x coordinate of parent vertex position
bool trackingParticleIsMuonInOmtfEvent0(const TrackingParticle &trackingParticle)
TH1D * deltaPhiPropCandStdDev
Geom::Phi< T > phi() const
edm::ESHandle< MagneticField > magField
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF) ...
TrajectoryStateOnSurface atStation2(const FreeTrajectoryState &ftsStart) const
T const * product() const
Global3DPoint GlobalPoint
float normal_pdf(float x, float m, float s)
bool isNonnull() const
Checks for non-null.
void beginRun(edm::EventSetup const &eventSetup) override
TrajectoryStateOnSurface propagate(const SimTrack &simTrack, const edm::SimVertexContainer *simVertices)
Log< level::Error, false > LogError
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
CandidateSimMuonMatcher(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > &magneticFieldEsToken, const edm::ESGetToken< Propagator, TrackingComponentsRecord > &propagatorEsToken)
void observeProcesorEmulation(unsigned int iProcessor, l1t::tftype mtfType, const std::shared_ptr< OMTFinput > &, const AlgoMuons &algoCandidates, const AlgoMuons &gbCandidates, const std::vector< l1t::RegionalMuonCand > &candMuons) override
const OMTFConfiguration * omtfConfig
const math::XYZTLorentzVectorD & momentum() const
const std::vector< SimTrack > & g4Tracks() const
static std::string const input
bool simTrackIsMuonInOmtf(const SimTrack &simTrack)
const int hwQual() const
Get quality code.
bool trackingParticleIsMuonInBx0(const TrackingParticle &trackingParticle)
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
std::vector< MatchingResult > cleanMatching(std::vector< MatchingResult > matchingResults, std::vector< const l1t::RegionalMuonCand *> &muonCands, AlgoMuons &ghostBustedProcMuons)
unsigned size(int bx) const
int type() const
particle type (HEP PDT convension)
std::vector< MatchingResult > matchSimple(std::vector< const l1t::RegionalMuonCand *> &muonCands, AlgoMuons &ghostBustedProcMuons, const edm::SimTrackContainer *simTracks, const edm::SimVertexContainer *simVertices, std::function< bool(const SimTrack &)> const &simTrackFilter)
bool simTrackIsMuonInOmtfBx0(const SimTrack &simTrack)
double foldPhi(double phi)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > & propagatorEsToken
GlobalPoint globalPosition() const
const edm::ParameterSet & edmCfg
int bunchCrossing() const
get the detector field from this detid
TH1D * deltaPhiPropCandMean
bool simTrackIsMuonInBx0(const SimTrack &simTrack)
Abs< T >::type abs(const T &t)
Log< level::Error, true > LogImportant
bool isMatched(TrackingRecHit const &hit)
const T & at(int bx, unsigned i) const
FreeTrajectoryState simTrackToFts(const SimTrack &simTrack, const SimVertex &simVertex)
void observeEventBegin(const edm::Event &event) override
const TrackingVertexRef & parentVertex() const
int calcGlobalPhi(int locPhi, int proc) const
double vy() const
y coordinate of parent vertex position
std::vector< SimVertex > SimVertexContainer
edm::ESHandle< Propagator > propagator
std::vector< AlgoMuonPtr > AlgoMuons
unsigned int getProcIndx(unsigned int iProcessor, l1t::tftype mtfType) const
input phi should be in the hardware scale (nPhiBins units for 2pi), can be in range -nPhiBins ...
Monte Carlo truth information used for tracking validation.
bool trackingParticleIsMuonInOmtfBx0(const TrackingParticle &trackingParticle)
std::shared_ptr< AlgoMuon > AlgoMuonPtr
std::vector< TrackingParticle > TrackingParticleCollection
double pt() const
Transverse momentum. Note this is taken from the first SimTrack only.
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > & magneticFieldEsToken
std::vector< MatchingResult > matchingResults
std::vector< SimTrack > SimTrackContainer
~CandidateSimMuonMatcher() override
void observeEventEnd(const edm::Event &event, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
std::vector< const l1t::RegionalMuonCand * > ghostBust(const l1t::RegionalMuonCandBxCollection *mtfCands, const AlgoMuons &gbCandidates, AlgoMuons &ghostBustedProcMuons)
double vz() const
z coordinate of parent vertex position