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;
72 const std::shared_ptr<OMTFinput>&
input,
75 const std::vector<l1t::RegionalMuonCand>& candMuons) {
79 if (gbCandidate->getPtConstr() > 0) {
80 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::observeProcesorEmulation procIndx" << procIndx <<
" " 81 << *gbCandidate << std::endl;
82 this->gbCandidates.emplace_back(gbCandidate);
98 LogTrace(
"l1tOmtfEventPrint") <<
"simTrackIsMuonInOmtf, simTrack type " << std::setw(3) <<
simTrack.type() <<
" pt " 99 << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " << std::setw(9)
100 <<
simTrack.momentum().eta() <<
" phi " << std::setw(9) <<
simTrack.momentum().phi()
114 if (
simTrack.eventId().bunchCrossing() != 0)
124 if (
simTrack.eventId().bunchCrossing() == 0)
152 if (trackingParticle.
pt() < 2.5)
156 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticleIsMuonInOmtfBx0, pdgId " << std::setw(3)
157 << trackingParticle.
pdgId() <<
" pt " << std::setw(9) << trackingParticle.
pt()
158 <<
" eta " << std::setw(9) << trackingParticle.
momentum().eta() <<
" phi " 159 << std::setw(9) << trackingParticle.
momentum().phi() <<
" event " 161 << trackingParticle.
g4Tracks().at(0).trackId() <<
" parentVertex Rho " 162 << trackingParticle.
parentVertex()->position().Rho() <<
" eta " 163 << trackingParticle.
parentVertex()->position().eta() <<
" phi " 164 << trackingParticle.
parentVertex()->position().phi() << std::endl;
166 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticleIsMuonInOmtfBx0, pdgId " << std::setw(3)
167 << trackingParticle.
pdgId() <<
" pt " << std::setw(9) << trackingParticle.
pt()
168 <<
" eta " << std::setw(9) << trackingParticle.
momentum().eta() <<
" phi " 169 << std::setw(9) << trackingParticle.
momentum().phi() <<
" trackId " 170 << trackingParticle.
g4Tracks().at(0).trackId();
190 std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {
191 LogTrace(
"l1tOmtfEventPrint") <<
"\nCandidateSimMuonMatcher::observeEventEnd" << std::endl;
193 std::vector<const l1t::RegionalMuonCand*> ghostBustedRegionalCands =
204 LogTrace(
"l1tOmtfEventPrint") <<
"simTraksHandle size " << simTraksHandle.
product()->size() << std::endl;
205 LogTrace(
"l1tOmtfEventPrint") <<
"simVertices size " <<
simVertices.product()->size() << std::endl;
213 ghostBustedRegionalCands, ghostBustedProcMuons, simTraksHandle.
product(),
simVertices.product(), simTrackFilter);
218 LogTrace(
"l1tOmtfEventPrint") <<
"\nCandidateSimMuonMatcher::observeEventEnd trackingParticleHandle size " 219 << trackingParticleHandle.
product()->size() << std::endl;
222 std::function<bool(const TrackingParticle&)> trackParticleFilter =
225 match(ghostBustedRegionalCands, ghostBustedProcMuons, trackingParticleHandle.
product(), trackParticleFilter);
234 edm::LogError(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::ghostBust(): gbCandidates.size() " 238 boost::dynamic_bitset<> isKilled(mtfCands->
size(0),
false);
240 for (
unsigned int i1 = 0;
i1 < mtfCands->
size(0); ++
i1) {
241 if (mtfCands->
at(0,
i1).hwPt() == 0)
243 LogTrace(
"l1tOmtfEventPrint") <<
"\nCandidateSimMuonMatcher::ghostBust regionalCand pt " << std::setw(3)
244 << mtfCands->
at(0,
i1).hwPt() <<
" qual " << std::setw(2)
245 << mtfCands->
at(0,
i1).hwQual() <<
" proc " << std::setw(2)
246 << mtfCands->
at(0,
i1).processor();
247 for (
unsigned int i2 =
i1 + 1;
i2 < mtfCands->
size(0); ++
i2) {
248 auto& mtfCand1 = mtfCands->
at(0,
i1);
249 auto& mtfCand2 = mtfCands->
at(0,
i2);
250 if (mtfCand2.hwPt() == 0)
253 if (
std::abs(mtfCand1.hwEta() - mtfCand2.hwEta()) < (0.3 / 0.010875)) {
262 if (
std::abs(gloablHwPhi1 - gloablHwPhi2) < 8) {
275 std::vector<const l1t::RegionalMuonCand*> resultCands;
277 for (
unsigned int i1 = 0;
i1 < mtfCands->
size(0); ++
i1) {
279 if (!isKilled[
i1] && mtfCands->
at(0,
i1).hwPt()) {
280 resultCands.push_back(&(mtfCands->
at(0,
i1)));
284 if (mtfCands->
at(0,
i1).hwPt()) {
285 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::ghostBust\n regionalCand pt " << std::setw(3)
286 << mtfCands->
at(0,
i1).hwPt() <<
" qual " << std::setw(2)
287 << mtfCands->
at(0,
i1).hwQual() <<
" proc " << std::setw(2)
288 << mtfCands->
at(0,
i1).processor() <<
" eta " << std::setw(4)
289 << mtfCands->
at(0,
i1).hwEta() <<
" gloablEta " << std::setw(8)
290 << mtfCands->
at(0,
i1).hwEta() * 0.010875 <<
" hwPhi " << std::setw(3)
291 << mtfCands->
at(0,
i1).hwPhi() <<
" globalPhi " << std::setw(8)
293 mtfCands->
at(0,
i1).processor()))
294 <<
" fireadLayers " << std::bitset<18>(mtfCands->
at(0,
i1).trackAddress().at(0))
295 <<
" gb isKilled " << isKilled.test(
i1) << std::endl;
301 if (resultCands.size() >= 3)
302 LogTrace(
"l1tOmtfEventPrint") <<
" ghost !!!!!! " << std::endl;
303 LogTrace(
"l1tOmtfEventPrint") << std::endl;
314 float zAtRPC = trackAtRPC.globalPosition().z();
337 int charge = trackingParticle.
pdgId() > 0 ? -1 : 1;
340 GlobalPoint r3GP(trackingParticle.
vx(), trackingParticle.
vy(), trackingParticle.
vz());
352 edm::LogImportant(
"l1tOmtfEventPrint") <<
"Track with no vertex, defaulting to (0,0,0)";
356 edm::LogImportant(
"l1tOmtfEventPrint") <<
"simVertex.vertexId() != vtxInd. simVertex.vertexId() " 357 <<
simVertex.vertexId() <<
" vtxInd " <<
vtxInd <<
" !!!!!!!!!!!!!!!!!";
377 static const float inv_sqrt_2pi = 0.3989422804014327;
378 float a = (
x -
m) /
s;
389 double candGloablEta = muonCand->
hwEta() * 0.010875;
395 if (candGlobalPhi >
M_PI)
396 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
414 result.muonCand = muonCand;
415 result.procMuon = procMuon;
417 double treshold = 6. * sigma;
419 treshold = 7. * sigma;
421 treshold = 20. * sigma;
426 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: simTrack type " <<
simTrack.type() <<
" pt " 427 << std::setw(8) <<
simTrack.momentum().pt() <<
" eta " << std::setw(8)
428 <<
simTrack.momentum().eta() <<
" phi " << std::setw(8) <<
simTrack.momentum().phi()
431 << muonCand->
hwPt() <<
" candGloablEta " << std::setw(8) << candGloablEta
432 <<
" candGlobalPhi " << std::setw(8) << candGlobalPhi <<
" hwQual " 433 << muonCand->
hwQual() <<
" deltaEta " << std::setw(8) <<
result.deltaEta
434 <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi <<
" sigma " << std::setw(8)
435 << sigma <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood <<
" result " 436 << (short)
result.result << std::endl;
448 double candGloablEta = muonCand->
hwEta() * 0.010875;
454 if (candGlobalPhi >
M_PI)
455 candGlobalPhi = candGlobalPhi - (2. *
M_PI);
475 result.muonCand = muonCand;
476 result.procMuon = procMuon;
478 double treshold = 6. * sigma;
479 if (trackingParticle.
pt() > 20)
480 treshold = 7. * sigma;
481 if (trackingParticle.
pt() > 100)
482 treshold = 20. * sigma;
487 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match: trackingParticle type " 488 << trackingParticle.
pdgId() <<
" pt " << std::setw(8) << trackingParticle.
pt()
489 <<
" eta " << std::setw(8) << trackingParticle.
momentum().eta() <<
" phi " 490 << std::setw(8) << trackingParticle.
momentum().phi() <<
" propagation eta " 493 <<
" candGloablEta " << std::setw(8) << candGloablEta <<
" candGlobalPhi " 494 << std::setw(8) << candGlobalPhi <<
" hwQual " << muonCand->
hwQual() <<
" deltaEta " 495 << std::setw(8) <<
result.deltaEta <<
" deltaPhi " << std::setw(8) <<
result.deltaPhi
496 <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood <<
" result " 497 << (short)
result.result << std::endl;
504 std::vector<const l1t::RegionalMuonCand*>& muonCands,
509 return a.matchingLikelihood >
b.matchingLikelihood;
526 std::vector<MatchingResult> cleanedMatchingResults;
529 matchingResult.muonCand ==
531 cleanedMatchingResults.push_back(matchingResult);
543 unsigned int iCand = 0;
544 for (
auto& muonCand : muonCands) {
546 for (
auto& matchingResult : cleanedMatchingResults) {
547 if (matchingResult.muonCand == muonCand) {
555 result.muonCand = muonCand;
556 result.procMuon = ghostBustedProcMuons.at(iCand);
557 cleanedMatchingResults.push_back(
result);
562 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__
563 <<
" CandidateSimMuonMatcher::match cleanedMatchingResults:" << std::endl;
564 for (
auto&
result : cleanedMatchingResults) {
566 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::cleanMatching:" << __LINE__ <<
" simTrack type " 567 <<
result.pdgId <<
" pt " << std::setw(8) <<
result.genPt <<
" eta " << std::setw(8)
568 <<
result.genEta <<
" phi " << std::setw(8) <<
result.genPhi;
570 LogTrace(
"l1tOmtfEventPrint") <<
"no matched track ";
573 LogTrace(
"l1tOmtfEventPrint") <<
" muonCand pt " << std::setw(8) <<
result.muonCand->hwPt() <<
" hwQual " 574 <<
result.muonCand->hwQual() <<
" hwEta " <<
result.muonCand->hwEta()
575 <<
" deltaEta " << std::setw(8) <<
result.deltaEta <<
" deltaPhi " << std::setw(8)
576 <<
result.deltaPhi <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood
577 <<
" result " << (short)
result.result;
578 LogTrace(
"l1tOmtfEventPrint") <<
" procMuon " << *(
result.procMuon) << std::endl;
580 LogTrace(
"l1tOmtfEventPrint") <<
" no muonCand " 581 <<
" result " << (short)
result.result << std::endl;
583 LogTrace(
"l1tOmtfEventPrint") <<
" " << std::endl;
585 return cleanedMatchingResults;
599 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, simTrack type " << std::setw(3) <<
simTrack.type()
600 <<
" pt " << std::setw(9) <<
simTrack.momentum().pt() <<
" eta " << std::setw(9)
601 <<
simTrack.momentum().eta() <<
" phi " << std::setw(9) <<
simTrack.momentum().phi()
608 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" propagation failed" << std::endl;
620 <<
"CandidateSimMuonMatcher::match simTrack IS in OMTF region, matching to the omtfCands";
622 LogTrace(
"l1tOmtfEventPrint") <<
"simTrack NOT in OMTF region ";
633 unsigned int iCand = 0;
634 for (
auto& muonCand : muonCands) {
658 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
666 std::vector<const l1t::RegionalMuonCand*>& muonCands,
671 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match trackingParticles->size() " 677 if (simTrackFilter(trackingParticle) ==
false)
680 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, trackingParticle type " << std::setw(3)
681 << trackingParticle.pdgId() <<
" pt " << std::setw(9) << trackingParticle.pt()
682 <<
" eta " << std::setw(9) << trackingParticle.momentum().eta() <<
" phi " 683 << std::setw(9) << trackingParticle.momentum().phi() << std::endl;
689 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match:" << __LINE__ <<
" propagation failed" 696 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match, tsof.globalPosition().eta() " 703 <<
"CandidateSimMuonMatcher::match trackingParticle IS in OMTF region, matching to the omtfCands";
705 LogTrace(
"l1tOmtfEventPrint") <<
"trackingParticle NOT in OMTF region ";
717 unsigned int iCand = 0;
718 for (
auto& muonCand : muonCands) {
725 result =
match(muonCand, ghostBustedProcMuons.at(iCand), trackingParticle, tsof);
738 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)
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