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) {
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)) {
113 if (
simTrack.eventId().bunchCrossing() != 0)
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);
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)));
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;
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;
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;
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);
380 result.muonCand = muonCand;
381 result.procMuon = procMuon;
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)
401 << sigma <<
" Likelihood " << std::setw(8) <<
result.matchingLikelihood <<
" result " 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);
441 result.muonCand = muonCand;
442 result.procMuon = procMuon;
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)
462 <<
result.matchingLikelihood <<
" result " << (short)
result.result << std::endl;
469 std::vector<const l1t::RegionalMuonCand*>& muonCands,
474 return a.matchingLikelihood >
b.matchingLikelihood;
490 std::vector<MatchingResult> cleanedMatchingResults;
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) {
519 result.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()
572 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" propagation failed" << std::endl;
585 unsigned int iCand = 0;
586 for (
auto& muonCand : muonCands) {
602 LogTrace(
"l1tOmtfEventPrint") << __FUNCTION__ <<
":" << __LINE__ <<
" no matching candidate found" << std::endl;
610 std::vector<const l1t::RegionalMuonCand*>& muonCands,
615 LogTrace(
"l1tOmtfEventPrint") <<
"CandidateSimMuonMatcher::match trackingParticles->size() " 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;
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);
668 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) ...
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 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.
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
const tftype trackFinderType() const
Get track-finder which found the muon (bmtf, emtf_pos/emtf_neg or omtf_pos/omtf_neg) ...
TH1D * deltaPhiPropCandMean
Abs< T >::type abs(const T &t)
TrajectoryStateOnSurface atStation2(FreeTrajectoryState ftsStart, float eta) const
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
static int calcGlobalPhi(int locPhi, tftype t, int proc)
const TrackingVertexRef & parentVertex() const
double vy() const
y coordinate of parent vertex position
std::vector< SimVertex > SimVertexContainer
edm::ESHandle< Propagator > propagator
std::vector< AlgoMuonPtr > AlgoMuons
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
static std::vector< const l1t::RegionalMuonCand * > ghostBust(const l1t::RegionalMuonCandBxCollection *mtfCands, const AlgoMuons &gbCandidates, AlgoMuons &ghostBustedProcMuons)
double vz() const
z coordinate of parent vertex position