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;
445 double treshold = 0.15;
456 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: simTrack type " <<
simTrack.type() <<
" pt " 457 << std::setw(8) <<
simTrack.momentum().pt() <<
" eta " << std::setw(8)
458 <<
simTrack.momentum().eta() <<
" phi " << std::setw(8) <<
simTrack.momentum().phi()
461 << muonCand->
hwPt() <<
" candGloablEta " << std::setw(8) << candGloablEta
462 <<
" candGlobalPhi " << std::setw(8) << candGlobalPhi <<
" hwQual " 463 << muonCand->
hwQual() <<
" deltaEta " << std::setw(8) <<
result.deltaEta
464 <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi <<
" sigma " << std::setw(8)
465 << sigma <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood <<
" result " 466 << (short)
result.result << std::endl;
478 double candGloablEta = muonCand->
hwEta() * 0.010875;
484 if (candGlobalPhi >
M_PI)
485 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
505 result.muonCand = muonCand;
506 result.procMuon = procMuon;
508 double treshold = 6. * sigma;
509 if (trackingParticle.
pt() > 20)
510 treshold = 7. * sigma;
511 if (trackingParticle.
pt() > 100)
512 treshold = 20. * sigma;
517 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: trackingParticle type " 518 << trackingParticle.
pdgId() <<
" pt " << std::setw(8) << trackingParticle.
pt()
519 <<
" eta " << std::setw(8) << trackingParticle.
momentum().eta() <<
" phi " 520 << std::setw(8) << trackingParticle.
momentum().phi() <<
" propagation eta " 523 <<
" candGloablEta " << std::setw(8) << candGloablEta <<
" candGlobalPhi " 524 << std::setw(8) << candGlobalPhi <<
" hwQual " << muonCand->
hwQual() <<
" deltaEta " 525 << std::setw(8) <<
result.deltaEta <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi
526 <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood <<
" result " 527 << (short)
result.result << std::endl;
534 std::vector<const l1t::RegionalMuonCand*>& muonCands,
539 return a.matchingLikelihood >
b.matchingLikelihood;
556 std::vector<MatchingResult> cleanedMatchingResults;
560 cleanedMatchingResults.push_back(matchingResult);
572 unsigned int iCand = 0;
573 for (
auto& muonCand : muonCands) {
575 for (
auto& matchingResult : cleanedMatchingResults) {
576 if (matchingResult.muonCand == muonCand) {
584 result.muonCand = muonCand;
585 result.procMuon = ghostBustedProcMuons.at(iCand);
586 cleanedMatchingResults.push_back(
result);
591 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__
592 <<
" cleanedMatchingResults:" << std::endl;
593 for (
auto&
result : cleanedMatchingResults) {
595 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__ <<
" simTrack type " 596 <<
result.pdgId <<
" pt " << std::setw(8) <<
result.genPt <<
" eta " << std::setw(8)
597 <<
result.genEta <<
" phi " << std::setw(8) <<
result.genPhi;
599 LogTrace(
"l1tOmtfEventPrint") <<
"no matched track ";
602 LogTrace(
"l1tOmtfEventPrint") <<
" muonCand pt " << std::setw(8) <<
result.muonCand->hwPt() <<
" hwQual " 603 <<
result.muonCand->hwQual() <<
" hwEta " <<
result.muonCand->hwEta()
604 <<
" deltaEta " << std::setw(8) <<
result.deltaEta <<
" deltaPhi " << std::setw(8)
605 <<
result.deltaPhi <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood
606 <<
" result " << (short)
result.result;
607 LogTrace(
"l1tOmtfEventPrint") <<
" procMuon " << *(
result.procMuon) << std::endl;
609 LogTrace(
"l1tOmtfEventPrint") <<
" no muonCand " 610 <<
" result " << (short)
result.result << std::endl;
612 LogTrace(
"l1tOmtfEventPrint") <<
" " << std::endl;
614 return cleanedMatchingResults;
628 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, simTrack type " << std::setw(3) <<
simTrack.type()
629 <<
" pt " << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " << std::setw(9)
630 <<
simTrack.momentum().eta() <<
" phi " << std::setw(9) <<
simTrack.momentum().phi()
639 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" propagation failed: genPt " <<
result.genPt
640 <<
" genEta " <<
result.genEta <<
" eventId " <<
simTrack.eventId().event()
651 <<
"CandidateSimMuonMatcher::match simTrack IS in OMTF region, matching to the omtfCands";
653 LogTrace(
"l1tOmtfEventPrint") <<
"simTrack NOT in OMTF region ";
664 unsigned int iCand = 0;
665 for (
auto& muonCand : muonCands) {
675 result.simVertex = &(simVertices->at(
689 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
698 std::vector<const l1t::RegionalMuonCand*>& muonCands,
703 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match trackingParticles->size() " 709 if (simTrackFilter(trackingParticle) ==
false)
712 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, trackingParticle type " << std::setw(3)
713 << trackingParticle.pdgId() <<
" pt " << std::setw(9) << trackingParticle.pt()
714 <<
" eta " << std::setw(9) << trackingParticle.momentum().eta() <<
" phi " 715 << std::setw(9) << trackingParticle.momentum().phi() << std::endl;
721 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match:" << __LINE__ <<
" propagation failed" 728 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, tsof.globalPosition().eta() " 735 <<
"CandidateSimMuonMatcher::match trackingParticle IS in OMTF region, matching to the omtfCands";
737 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticle NOT in OMTF region ";
749 unsigned int iCand = 0;
750 for (
auto& muonCand : muonCands) {
757 result =
match(muonCand, ghostBustedProcMuons.at(iCand), trackingParticle, tsof);
770 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
778 std::vector<const l1t::RegionalMuonCand*>& muonCands,
789 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::matchSimple: simTrack type " << std::setw(3)
790 <<
simTrack.type() <<
" pt " << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " 791 << std::setw(9) <<
simTrack.momentum().eta() <<
" phi " << std::setw(9)
792 <<
simTrack.momentum().phi() << std::endl;
796 unsigned int iCand = 0;
797 for (
auto& muonCand : muonCands) {
803 double candGloablEta = muonCand->hwEta() * 0.010875;
807 if (candGlobalPhi >
M_PI)
808 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
816 result.muonCand = muonCand;
817 result.procMuon = ghostBustedProcMuons.at(iCand);
832 double treshold = 0.7;
835 else if (
simTrack.momentum().pt() < 10)
837 else if (
simTrack.momentum().pt() < 20)
844 result.matchingLikelihood = 1. / 0.001;
849 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::matchSimple: simTrack type " <<
simTrack.type()
850 <<
" pt " << std::setw(8) <<
simTrack.momentum().pt() <<
" eta " << std::setw(8)
851 <<
simTrack.momentum().eta() <<
" phi " << std::setw(8)
852 <<
simTrack.momentum().phi() <<
"\n muonCand pt " << std::setw(8)
853 << muonCand->hwPt() <<
" candGloablEta " << std::setw(8) << candGloablEta
854 <<
" candGlobalPhi " << std::setw(8) << candGlobalPhi <<
" hwQual " 855 << muonCand->hwQual() <<
" deltaEta " << std::setw(8) <<
result.deltaEta
856 <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi <<
" matchingLikelihood " 857 <<
result.matchingLikelihood <<
" result " << (short)
result.result << std::endl;
875 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