29 double phiGmtUnit = 2. *
M_PI / 576.;
30 return phi * phiGmtUnit;
35 return (phi - 2 *
M_PI);
37 return (phi + 2 *
M_PI);
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;
72 const std::shared_ptr<OMTFinput>&
input,
75 const std::vector<l1t::RegionalMuonCand>& candMuons) {
88 if (
abs(simTrack.
type()) == 13 ||
abs(simTrack.
type()) == 1000015) {
97 LogTrace(
"l1tOmtfEventPrint") <<
"simTrackIsMuonInOmtf, simTrack type " << std::setw(3) << simTrack.
type() <<
" pt "
98 << std::setw(9) << simTrack.
momentum().pt() <<
" eta " << std::setw(9)
99 << simTrack.
momentum().eta() <<
" phi " << std::setw(9) << simTrack.
momentum().phi()
105 if ((fabs(simTrack.
momentum().eta()) >= 0.72) && (fabs(simTrack.
momentum().eta()) <= 1.3)) {
128 if (
abs(trackingParticle.
pdgId()) == 13 ||
abs(trackingParticle.
pdgId()) == 1000015) {
135 if (trackingParticle.
pt() < 2.5)
139 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticleIsMuonInOmtfBx0, pdgId " << std::setw(3)
140 << trackingParticle.
pdgId() <<
" pt " << std::setw(9) << trackingParticle.
pt()
141 <<
" eta " << std::setw(9) << trackingParticle.
momentum().eta() <<
" phi "
142 << std::setw(9) << trackingParticle.
momentum().phi() <<
" event "
144 << trackingParticle.
g4Tracks().at(0).trackId() <<
" parentVertex Rho "
145 << trackingParticle.
parentVertex()->position().Rho() <<
" eta "
146 << trackingParticle.
parentVertex()->position().eta() <<
" phi "
147 << trackingParticle.
parentVertex()->position().phi() << std::endl;
149 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticleIsMuonInOmtfBx0, pdgId " << std::setw(3)
150 << trackingParticle.
pdgId() <<
" pt " << std::setw(9) << trackingParticle.
pt()
151 <<
" eta " << std::setw(9) << trackingParticle.
momentum().eta() <<
" phi "
152 << std::setw(9) << trackingParticle.
momentum().phi() <<
" trackId "
153 << trackingParticle.
g4Tracks().at(0).trackId();
158 if ((fabs(trackingParticle.
momentum().eta()) >= 0.72) && (fabs(trackingParticle.
momentum().eta()) <= 1.3)) {
173 std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {
175 std::vector<const l1t::RegionalMuonCand*> ghostBustedRegionalCands =
185 LogTrace(
"l1tOmtfEventPrint") <<
"simTraksHandle size " << simTraksHandle.
product()->size() << std::endl;
191 ghostBustedRegionalCands, ghostBustedProcMuons, simTraksHandle.
product(), simVertices.
product(), simTrackFilter);
196 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticleHandle size " << trackingParticleHandle.
product()->size()
202 match(ghostBustedRegionalCands, ghostBustedProcMuons, trackingParticleHandle.
product(), trackParticleFilter);
210 if (gbCandidates.size() != mtfCands->
size()) {
211 edm::LogError(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::ghostBust(): gbCandidates.size() "
212 << gbCandidates.size() <<
" != resultGbCandidates.size() " << mtfCands->
size();
216 boost::dynamic_bitset<> isKilled(mtfCands->
size(0),
false);
218 for (
unsigned int i1 = 0; i1 < mtfCands->
size(0); ++i1) {
219 for (
unsigned int i2 = i1 + 1; i2 < mtfCands->
size(0); ++i2) {
220 auto& mtfCand1 = mtfCands->
at(0, i1);
221 auto& mtfCand2 = mtfCands->
at(0, i2);
223 if (
abs(mtfCand1.hwEta() - mtfCand2.hwEta()) < (0.3 / 0.010875)) {
225 mtfCand1.hwPhi(), mtfCand1.trackFinderType(), mtfCand1.processor());
227 mtfCand2.hwPhi(), mtfCand2.trackFinderType(), mtfCand2.processor());
234 if (
abs(gloablHwPhi1 - gloablHwPhi2) < 8) {
235 if (mtfCand1.hwQual() > mtfCand2.hwQual()) {
244 std::vector<const l1t::RegionalMuonCand*> resultCands;
246 for (
unsigned int i1 = 0; i1 < mtfCands->
size(0); ++i1) {
248 if (!isKilled[i1] && mtfCands->
at(0, i1).hwQual()) {
249 resultCands.push_back(&(mtfCands->
at(0, i1)));
250 ghostBustedProcMuons.push_back(gbCandidates.at(i1));
254 <<
"CandidateSimMuonMatcher::ghostBust\n regionalCand pt " << std::setw(3) << mtfCands->
at(0, i1).hwPt()
255 <<
" qual " << std::setw(2) << mtfCands->
at(0, i1).hwQual() <<
" proc " << std::setw(2)
256 << mtfCands->
at(0, i1).processor() <<
" eta " << std::setw(4) << mtfCands->
at(0, i1).hwEta() <<
" gloablEta "
257 << std::setw(8) << mtfCands->
at(0, i1).hwEta() * 0.010875 <<
" hwPhi " << std::setw(3)
258 << mtfCands->
at(0, i1).hwPhi() <<
" globalPhi " << std::setw(8)
260 mtfCands->
at(0, i1).hwPhi(), mtfCands->
at(0, i1).trackFinderType(), mtfCands->
at(0, i1).processor()))
261 <<
" fireadLayers " << std::bitset<18>(mtfCands->
at(0, i1).trackAddress().at(0)) <<
" isKilled "
262 << isKilled.test(i1) << std::endl;
264 LogTrace(
"l1tOmtfEventPrint") << *(gbCandidates.at(i1)) << std::endl;
267 if (resultCands.size() >= 3)
268 LogTrace(
"l1tOmtfEventPrint") <<
" ghost !!!!!! " << std::endl;
269 LogTrace(
"l1tOmtfEventPrint") << std::endl;
302 int charge = trackingParticle.
pdgId() > 0 ? -1 : 1;
305 GlobalPoint r3GP(trackingParticle.
vx(), trackingParticle.
vy(), trackingParticle.
vz());
317 std::cout <<
"Track with no vertex, defaulting to (0,0,0)" << std::endl;
319 simVertex = simVertices->at(vtxInd);
320 if (((
int)simVertex.
vertexId()) != vtxInd) {
321 std::cout <<
"simVertex.vertexId() != vtxInd !!!!!!!!!!!!!!!!!" << std::endl;
322 edm::LogImportant(
"l1tOmtfEventPrint") <<
"simVertex.vertexId() != vtxInd. simVertex.vertexId() "
323 << simVertex.
vertexId() <<
" vtxInd " << vtxInd <<
" !!!!!!!!!!!!!!!!!";
343 static const float inv_sqrt_2pi = 0.3989422804014327;
344 float a = (x -
m) / s;
346 return inv_sqrt_2pi / s *
std::exp(-0.5 * a * a);
355 double candGloablEta = muonCand->
hwEta() * 0.010875;
356 if (
abs(simTrack.
momentum().eta() - candGloablEta) < 0.3) {
361 if (candGlobalPhi >
M_PI)
362 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
383 double treshold = 6. * sigma;
385 treshold = 7. * sigma;
387 treshold = 20. * sigma;
392 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: simTrack type " << simTrack.
type() <<
" pt "
393 << std::setw(8) << simTrack.
momentum().pt() <<
" eta " << std::setw(8)
394 << simTrack.
momentum().eta() <<
" phi " << std::setw(8) << simTrack.
momentum().phi()
397 << muonCand->
hwPt() <<
" candGloablEta " << std::setw(8) << candGloablEta
398 <<
" candGlobalPhi " << std::setw(8) << candGlobalPhi <<
" hwQual "
399 << muonCand->
hwQual() <<
" deltaEta " << std::setw(8) << result.
deltaEta
400 <<
" deltaPhi " << std::setw(8) << result.
deltaPhi <<
" sigma " << std::setw(8)
402 << (short)result.
result << std::endl;
414 double candGloablEta = muonCand->
hwEta() * 0.010875;
415 if (
abs(trackingParticle.
momentum().eta() - candGloablEta) < 0.3) {
420 if (candGlobalPhi >
M_PI)
421 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
444 double treshold = 6. * sigma;
445 if (trackingParticle.
pt() > 20)
446 treshold = 7. * sigma;
447 if (trackingParticle.
pt() > 100)
448 treshold = 20. * sigma;
453 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: simTrack type " << trackingParticle.
pdgId()
454 <<
" pt " << std::setw(8) << trackingParticle.
pt() <<
" eta " << std::setw(8)
455 << trackingParticle.
momentum().eta() <<
" phi " << std::setw(8)
456 << trackingParticle.
momentum().phi() <<
" propagation eta " << std::setw(8)
458 <<
" muonCand pt " << std::setw(8) << muonCand->
hwPt() <<
" candGloablEta "
459 << std::setw(8) << candGloablEta <<
" candGlobalPhi " << std::setw(8) << candGlobalPhi
460 <<
" hwQual " << muonCand->
hwQual() <<
" deltaEta " << std::setw(8) << result.
deltaEta
461 <<
" deltaPhi " << std::setw(8) << result.
deltaPhi <<
" Likelihood " << std::setw(8)
469 std::vector<const l1t::RegionalMuonCand*>& muonCands,
476 for (
unsigned int i1 = 0; i1 < matchingResults.size(); i1++) {
478 for (
unsigned int i2 = i1 + 1; i2 < matchingResults.size(); i2++) {
479 if ((matchingResults[i1].trackingParticle &&
480 matchingResults[i1].trackingParticle == matchingResults[i2].trackingParticle) ||
481 (matchingResults[i1].simTrack && matchingResults[i1].simTrack == matchingResults[i2].simTrack) ||
482 (matchingResults[i1].muonCand == matchingResults[i2].muonCand)) {
490 std::vector<MatchingResult> cleanedMatchingResults;
491 for (
auto& matchingResult : matchingResults) {
493 matchingResult.muonCand ==
495 cleanedMatchingResults.push_back(matchingResult);
507 unsigned int iCand = 0;
508 for (
auto& muonCand : muonCands) {
510 for (
auto& matchingResult : cleanedMatchingResults) {
511 if (matchingResult.muonCand == muonCand) {
520 result.
procMuon = ghostBustedProcMuons.at(iCand);
521 cleanedMatchingResults.push_back(result);
526 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__
527 <<
" CandidateSimMuonMatcher::match cleanedMatchingResults:" << std::endl;
528 for (
auto&
result : cleanedMatchingResults) {
530 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__ <<
" simTrack type "
531 <<
result.pdgId <<
" pt " << std::setw(8) <<
result.genPt <<
" eta " << std::setw(8)
532 <<
result.genEta <<
" phi " << std::setw(8) <<
result.genPhi;
534 LogTrace(
"l1tOmtfEventPrint") <<
"no matched track ";
537 LogTrace(
"l1tOmtfEventPrint") <<
" muonCand pt " << std::setw(8) <<
result.muonCand->hwPt() <<
" hwQual "
538 <<
result.muonCand->hwQual() <<
" hwEta " <<
result.muonCand->hwEta()
539 <<
" deltaEta " << std::setw(8) <<
result.deltaEta <<
" deltaPhi " << std::setw(8)
540 <<
result.deltaPhi <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood
541 <<
" result " << (short)
result.result;
542 LogTrace(
"l1tOmtfEventPrint") <<
" procMuon " << *(
result.procMuon) << std::endl;
544 LogTrace(
"l1tOmtfEventPrint") <<
" no muonCand "
545 <<
" result " << (short)
result.result << std::endl;
547 LogTrace(
"l1tOmtfEventPrint") <<
" " << std::endl;
549 return cleanedMatchingResults;
563 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, simTrack type " << std::setw(3) <<
simTrack.type()
564 <<
" pt " << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " << std::setw(9)
565 <<
simTrack.momentum().eta() <<
" phi " << std::setw(9) <<
simTrack.momentum().phi()
568 bool matched =
false;
572 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" propagation failed" << std::endl;
585 unsigned int iCand = 0;
586 for (
auto& muonCand : muonCands) {
592 matchingResults.push_back(result);
601 matchingResults.push_back(result);
602 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
606 return cleanMatching(matchingResults, muonCands, ghostBustedProcMuons);
610 std::vector<const l1t::RegionalMuonCand*>& muonCands,
615 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match trackingParticles->size() "
616 << trackingParticles->size() << std::endl;
618 for (
auto& trackingParticle : *trackingParticles) {
621 if (simTrackFilter(trackingParticle) ==
false)
624 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, trackingParticle type " << std::setw(3)
625 << trackingParticle.pdgId() <<
" pt " << std::setw(9) << trackingParticle.pt()
626 <<
" eta " << std::setw(9) << trackingParticle.momentum().eta() <<
" phi "
627 << std::setw(9) << trackingParticle.momentum().phi() << std::endl;
629 bool matched =
false;
633 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match:" << __LINE__ <<
" propagation failed"
647 unsigned int iCand = 0;
648 for (
auto& muonCand : muonCands) {
655 result =
match(muonCand, ghostBustedProcMuons.at(iCand), trackingParticle, tsof);
660 matchingResults.push_back(result);
667 matchingResults.push_back(result);
668 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
672 return cleanMatching(matchingResults, muonCands, ghostBustedProcMuons);
MatchingResult match(const l1t::RegionalMuonCand *omtfCand, const AlgoMuonPtr &procMuon, const SimTrack &simTrack, TrajectoryStateOnSurface &tsof)
std::vector< MatchingResult > cleanMatching(std::vector< MatchingResult > matchingResults, std::vector< const l1t::RegionalMuonCand * > &muonCands, AlgoMuons &ghostBustedProcMuons)
EncodedEventId eventId() const
bool isNonnull() const
Checks for non-null.
int event() const
get the contents of the subdetector field (should be protected?)
unsigned size(int bx) const
const std::vector< SimTrack > & g4Tracks() const
double hwGmtPhiToGlobalPhi(int phi)
bool trackingParticleIsMuonInOmtfEvent0(const TrackingParticle &trackingParticle)
Vector momentum() const
spatial momentum vector
TH1D * deltaPhiPropCandStdDev
int pdgId() const
PDG ID.
edm::ESHandle< MagneticField > magField
Geom::Phi< T > phi() const
Global3DPoint GlobalPoint
const l1t::RegionalMuonCand * muonCand
float normal_pdf(float x, float m, float s)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
double pt() const
Transverse momentum. Note this is taken from the first SimTrack only.
GlobalPoint globalPosition() const
void beginRun(edm::EventSetup const &eventSetup) override
Exp< T >::type exp(const T &t)
TrajectoryStateOnSurface propagate(const SimTrack &simTrack, const edm::SimVertexContainer *simVertices)
Log< level::Error, false > LogError
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
static std::string const input
bool simTrackIsMuonInOmtf(const SimTrack &simTrack)
const int hwQual() const
Get quality code.
bool simTrackIsMuonInOmtfBx0(const SimTrack &simTrack)
double foldPhi(double phi)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > & propagatorEsToken
const edm::ParameterSet & edmCfg
double vy() const
y coordinate of parent vertex position
int bunchCrossing() const
get the detector field from this detid
TH1D * deltaPhiPropCandMean
Abs< T >::type abs(const T &t)
Log< level::Error, true > LogImportant
uint16_t const *__restrict__ x
bool isMatched(TrackingRecHit const &hit)
const math::XYZTLorentzVectorD & position() const
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
unsigned int vertexId() const
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
const TrackingVertexRef & parentVertex() const
const tftype trackFinderType() const
Get track-finder which found the muon (bmtf, emtf_pos/emtf_neg or omtf_pos/omtf_neg) ...
FreeTrajectoryState simTrackToFts(const SimTrack &simTrack, const SimVertex &simVertex)
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
void observeEventBegin(const edm::Event &event) override
TrajectoryStateOnSurface atStation2(FreeTrajectoryState ftsStart, float eta) const
static int calcGlobalPhi(int locPhi, tftype t, int proc)
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF) ...
T const * product() const
std::vector< SimVertex > SimVertexContainer
T getParameter(std::string const &) const
propagatorEsToken(esConsumes< Propagator, TrackingComponentsRecord, edm::Transition::BeginRun >(edm::ESInputTag("","SteppingHelixPropagatorAlong")))
double vx() const
x coordinate of parent vertex position
edm::ESHandle< Propagator > propagator
double matchingLikelihood
EncodedEventId eventId() const
Signal source, crossing number.
int type() const
particle type (HEP PDT convension)
std::vector< AlgoMuonPtr > AlgoMuons
const math::XYZTLorentzVectorD & momentum() const
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
Monte Carlo truth information used for tracking validation.
bool trackingParticleIsMuonInOmtfBx0(const TrackingParticle &trackingParticle)
std::shared_ptr< AlgoMuon > AlgoMuonPtr
std::vector< TrackingParticle > TrackingParticleCollection
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
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
magneticFieldEsToken(esConsumes< MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun >())
double vz() const
z coordinate of parent vertex position
static std::vector< const l1t::RegionalMuonCand * > ghostBust(const l1t::RegionalMuonCandBxCollection *mtfCands, const AlgoMuons &gbCandidates, AlgoMuons &ghostBustedProcMuons)
const T & at(int bx, unsigned i) const