55 relMiniIsoPUCorrected_(0),
56 useUserData_(iConfig.exists(
"userData")),
57 computeMuonMVA_(
false),
58 recomputeBasicSelectors_(
false),
128 if ( embedHighLevelSelection_ ) {
138 throw cms::Exception(
"ParameterError") <<
"miniIsoParams must have exactly 9 elements.\n";
148 throw cms::Exception(
"ConfigurationError") <<
"MiniIso is needed for Muon MVA calculation.\n";
150 if (computeMuonMVA_) {
168 produces<std::vector<Muon> >();
251 bool beamSpotIsValid =
false;
252 bool primaryVertexIsValid =
false;
262 if( beamSpotHandle.
isValid() ){
263 beamSpot = *beamSpotHandle;
264 beamSpotIsValid =
true;
267 <<
"No beam spot available from EventSetup, not adding high level selection \n";
269 if( pvHandle.
isValid() && !pvHandle->empty() ) {
270 primaryVertex = pvHandle->at(0);
271 primaryVertexIsValid =
true;
274 <<
"No primary vertex available from EventSetup, not adding high level selection \n";
285 std::vector<Muon> *
patMuons =
new std::vector<Muon>();
300 Muon aMuon(muonBaseRef);
315 chosenTrack = bestTrack;
318 unsigned int nhits = chosenTrack->numberOfValidHits();
326 primaryVertexIsValid,
333 double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
350 (*PUPPIIsolation_neutral_hadrons)[muonBaseRef],
351 (*PUPPIIsolation_photons)[muonBaseRef]);
354 (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonBaseRef],
355 (*PUPPINoLeptonsIsolation_photons)[muonBaseRef]);
366 patMuons->push_back(aMuon);
394 unsigned int idx = itMuon - muons->begin();
403 aMuon.
setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonRef], (*PUPPIIsolation_neutral_hadrons)[muonRef], (*PUPPIIsolation_photons)[muonRef]);
404 aMuon.
setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonRef], (*PUPPINoLeptonsIsolation_photons)[muonRef]);
442 chosenTrack = bestTrack;
444 unsigned int nhits = chosenTrack->numberOfValidHits();
452 primaryVertexIsValid,
459 double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
471 if (pfmu.muonRef().isNonnull()) {
472 if (pfmu.muonRef().id() != muonRef.id())
throw cms::Exception(
"Configuration") <<
"Muon reference within PF candidates does not point to the muon collection." << std::endl;
473 if (pfmu.muonRef().key() == muonRef.key()) {
481 if (simInfoIsAvailalbe){
482 const auto& msi = (*simInfo)[muonBaseRef];
496 patMuons->push_back(aMuon);
501 std::sort(patMuons->begin(), patMuons->end(),
pTComparator_);
511 for(
auto&
muon: *patMuons){
513 muon.setSelectors(0);
514 bool isRun2016BCDEF = (272728 <= iEvent.
run() && iEvent.
run() <= 278808);
529 *(mvaBTagCollectionTag.
product()),
531 &*mvaL1L2L3ResCorrector);
535 *(mvaBTagCollectionTag.
product()));
546 double sip3D = edB3D>0?dB3D/edB3D:0.0;
547 double dz = fabs(
muon.muonBestTrack()->dz(primaryVertex.
position()));
550 if (
muon.pt()>5 and
muon.isLooseMuon() and
552 sip3D<8.0 and dB2D<0.05 and dz<0.1){
561 std::unique_ptr<std::vector<Muon> > ptr(patMuons);
597 for(
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
607 for (
size_t j = 0, nd = deposits.size(); j < nd; ++j) {
611 }
else if (deposits[j]->
contains(muonRef.
id())){
623 for (
size_t j = 0; j<isolationValues.size(); ++j) {
625 if (isolationValues[j]->
contains(baseRef.
id())) {
627 }
else if (isolationValues[j]->
contains(muonRef.
id())) {
648 miniIsoParams_[3], miniIsoParams_[4], miniIsoParams_[5],
649 miniIsoParams_[6], miniIsoParams_[7], miniIsoParams_[8]);
672 iDesc.
add<
bool>(
"embedMuonBestTrack",
true)->setComment(
"embed muon best track (global pflow)");
673 iDesc.
add<
bool>(
"embedTunePMuonBestTrack",
true)->setComment(
"embed muon best track (muon only)");
674 iDesc.
add<
bool>(
"forceBestTrackEmbedding",
true)->setComment(
"force embedding separately the best tracks even if they're already embedded e.g. as tracker or global tracks");
675 iDesc.
add<
bool>(
"embedTrack",
true)->setComment(
"embed external track");
676 iDesc.
add<
bool>(
"embedStandAloneMuon",
true)->setComment(
"embed external stand-alone muon");
677 iDesc.
add<
bool>(
"embedCombinedMuon",
false)->setComment(
"embed external combined muon");
678 iDesc.
add<
bool>(
"embedPickyMuon",
false)->setComment(
"embed external picky track");
679 iDesc.
add<
bool>(
"embedTpfmsMuon",
false)->setComment(
"embed external tpfms track");
680 iDesc.
add<
bool>(
"embedDytMuon",
false)->setComment(
"embed external dyt track ");
683 iDesc.
add<
bool>(
"embedCaloMETMuonCorrs",
true)->setComment(
"whether to add MET muon correction for caloMET or not");
684 iDesc.
add<
edm::InputTag>(
"caloMETMuonCorrs",
edm::InputTag(
"muonMETValueMapProducer" ,
"muCorrData"))->setComment(
"source of MET muon corrections for caloMET");
685 iDesc.
add<
bool>(
"embedTcMETMuonCorrs",
true)->setComment(
"whether to add MET muon correction for tcMET or not");
686 iDesc.
add<
edm::InputTag>(
"tcMETMuonCorrs",
edm::InputTag(
"muonTCMETValueMapProducer" ,
"muCorrData"))->setComment(
"source of MET muon corrections for tcMET");
690 iDesc.
add<
bool>(
"useParticleFlow",
false)->setComment(
"whether to use particle flow or not");
691 iDesc.
add<
bool>(
"embedPFCandidate",
false)->setComment(
"embed external particle flow object");
692 iDesc.
add<
bool>(
"embedPfEcalEnergy",
true)->setComment(
"add ecal energy as reconstructed by PF");
695 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
696 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
697 std::vector<edm::InputTag> emptySourceVector;
700 )->
setComment(
"input with MC match information");
703 iDesc.
add<
bool>(
"computeMiniIso",
false)->setComment(
"whether or not to compute and store electron mini-isolation");
705 iDesc.
add<std::vector<double> >(
"miniIsoParams", std::vector<double>())->
setComment(
"mini-iso parameters to use for muons");
720 isoDepositsPSet.
addOptional<std::vector<edm::InputTag> >(
"user");
734 iDesc.
addOptional(
"isolationValues", isolationValuesPSet);
748 iDesc.
add(
"efficiencies", efficienciesPSet);
749 iDesc.
add<
bool>(
"addEfficiencies",
false);
758 iDesc.
add(
"userIsolation", isolationPSet);
760 iDesc.
add<
bool>(
"embedHighLevelSelection",
true)->setComment(
"embed high level selection");
764 )->
setComment(
"input with high level selection");
766 )->
setComment(
"input with high level selection");
779 bool primaryVertexIsValid,
787 std::pair<bool,Measurement1D>
result =
793 double d0_corr = result.second.value();
794 double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
805 d0_corr = result.second.value();
806 d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
821 d0_corr = result.second.value();
822 d0_err = beamspotIsValid ? result.second.error() : -1.0;
832 d0_corr = result.second.value();
833 d0_err = beamspotIsValid ? result.second.error() : -1.0;
bool embedTpfmsMuon_
embed track from tpfms muon fit into the muon
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_charged_hadrons_
bool enabled() const
'true' if this there is at least one efficiency configured
bool useUserData_
add user data to the muon (this will be data members of th muon even w/o embedding) ...
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_photons_
T getParameter(std::string const &) const
double ecalEnergy() const
return corrected Ecal energy
void setComment(std::string const &value)
Assists in assimilating all pat::UserData into pat objects.
pat::MuonMvaEstimator mvaEstimator_
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
bool addPuppiIsolation_
add puppi isolation
void embedDytMuon()
embed reference to the above dyt Track
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
void embedTpfmsMuon()
embed reference to the above tpfms Track
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > tcMETMuonCorrsToken_
source of tcMET muon corrections
void setIsolation(IsolationKeys key, float value)
bool embedTcMETMuonCorrs_
embed muon MET correction info for tcMET into the muon
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
void embedTcMETMuonCorrs(const reco::MuonMETCorrectionData &t)
edm::EDGetTokenT< std::vector< reco::Vertex > > pvToken_
input source of the primary vertex
bool contains(EventRange const &lh, EventID const &rh)
std::string mvaTrainingFile_
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_photons_
void embedCombinedMuon()
set reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon...
edm::EDGetTokenT< double > rho_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
input source
void embedTunePMuonBestTrack(bool force=false)
bool addEfficiencies_
add efficiencies to the muon (this will be data members of th muon even w/o embedding) ...
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > caloMETMuonCorrsToken_
source of caloMET muon corrections
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void setAllowAnything()
allow any parameter label/value pairs
double zError() const
error on z
void setSimFlavour(int f)
#define DEFINE_FWK_MODULE(type)
bool embedCaloMETMuonCorrs_
embed muon MET correction info for caloMET into the muon
~PATMuonProducer() override
default destructur
float muonRelMiniIsoPUCorrected(const PFIsolation &iso, const math::XYZTLorentzVector &p4, float dr, float rho)
edm::EDGetTokenT< edm::ValueMap< reco::MuonSimInfo > > simInfo_
MC info.
void embedMuonBestTrack(bool force=false)
std::vector< pat::PackedCandidate > PackedCandidateCollection
void setIsolationPUPPINoLeptons(float chargedhadrons, float neutralhadrons, float photons)
sets PUPPINoLeptons isolations
void setMuonMiniIso(pat::Muon &aMuon, const pat::PackedCandidateCollection *pc)
reco::TransientTrack build(const reco::Track *p) const
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
bool embedBestTrack_
embed the track from best muon measurement (global pflow)
edm::EDGetTokenT< reco::JetCorrector > mvaL1Corrector_
void setCutBasedSelectorFlags(reco::Muon &muon, const reco::Vertex *vertex=0, bool run2016_hip_mitigation=false)
bool addResolutions_
add resolutions to the muon (this will be data members of th muon even w/o embedding) ...
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_charged_hadrons_
std::vector< double > miniIsoParams_
void setSimPhi(float phi)
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
void setSimProdRho(float rho)
void setSimHeaviestMotherFlavour(int id)
void setPFCandidateRef(const reco::PFCandidateRef &ref)
add a reference to the source IsolatedPFCandidate
const Point & position() const
position
void embedHighLevel(pat::Muon &aMuon, reco::TrackRef track, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_neutral_hadrons_
void setSimType(reco::MuonSimType type)
void embedStandAloneMuon()
set reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
edm::EDGetTokenT< reco::JetTagCollection > mvaBTagCollectionTag_
PATMuonProducer(const edm::ParameterSet &iConfig)
default constructir
edm::EDGetTokenT< reco::PFCandidateCollection > pfMuonToken_
input source pfCandidates that will be to be transformed into pat::Muons, when using PF2PAT ...
void setIsolationPUPPI(float chargedhadrons, float neutralhadrons, float photons)
sets PUPPI isolations
pat::helper::MultiIsolator isolator_
helper class to add userdefined isolation values to the muon
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
bool enabled() const
'true' if this there is at least one efficiency configured
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
void embedTrack()
set reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
static void fillDescription(edm::ParameterSetDescription &iDesc)
const PFIsolation & miniPFIsolation() const
edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
input source of the primary vertex/beamspot
bool useParticleFlow_
switch to use particle flow (PF2PAT) or not
pat::PATUserDataHelper< pat::Muon > userDataHelper_
helper class to add userData to the muon
bool enabled() const
True if it has a non null configuration.
bool embedStandAloneMuon_
embed track from muon system into the muon
void setComment(std::string const &value)
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
GreaterByPt< Muon > pTComparator_
bool embedTrack_
embed the track from inner tracker into the muon
void setDB(double dB, double edB, IPTYPE type=PV2D)
bool addGenMatch_
add generator match information
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
description of config file parameters
bool isGlobalMuon() const override
bool embedPfEcalEnergy_
add ecal PF energy
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
void embedPFCandidate()
embed the IsolatedPFCandidate pointed to by pfCandidateRef_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
everything that needs to be done during the event loop
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T > > cases)
reco::PFCandidateRef pfCandidateRef() const
double getRelMiniIsoPUCorrected(const pat::Muon &muon, float rho)
const LorentzVector & p4() const final
four-momentum Lorentz vector
ParameterDescriptionBase * add(U const &iLabel, T const &value)
reco::MuonRef muonRef() const
edm::EDGetTokenT< pat::PackedCandidateCollection > pcToken_
void initialize(std::string weightsfile, float dRmax)
bool isAValidMuonTrack(const MuonTrackType &type) const
void addGenParticleRef(const reco::GenParticleRef &ref)
void setPfEcalEnergy(float pfEcalEnergy)
bool embedTunePBestTrack_
embed the track from best muon measurement (muon only)
T const * product() const
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
void setSimMotherPdgId(int id)
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
void setExtSimType(reco::ExtendedMuonSimType type)
void setMiniPFIsolation(PFIsolation const &iso)
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
edm::EDGetTokenT< reco::JetCorrector > mvaL1L2L3ResCorrector_
void fillMuon(Muon &aMuon, const MuonBaseRef &muonRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
common muon filling, for both the standard and PF2PAT case
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
void setSimProdZ(float z)
Particle reconstructed by the particle flow algorithm.
void computeMva(const pat::Muon &imuon, const reco::Vertex &vertex, const reco::JetTagCollection &bTags, const reco::JetCorrector *correctorL1=0, const reco::JetCorrector *correctorL1L2L3Res=0)
pat::helper::EfficiencyLoader efficiencyLoader_
helper class to add efficiencies to the muon
bool embedPickyMuon_
embed track from picky muon fit into the muon
void setNormChi2(double normChi2)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
bool embedDytMuon_
embed track from DYT muon fit into the muon
void embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData &t)
PFIsolation getMiniPFIsolation(const pat::PackedCandidateCollection *pfcands, const math::XYZTLorentzVector &p4, float mindr=0.05, float maxdr=0.2, float kt_scale=10.0, float ptthresh=0.5, float deadcone_ch=0.0001, float deadcone_pu=0.01, float deadcone_ph=0.01, float deadcone_nh=0.01, float dZ_cut=0.0)
float miniIsoDr(const math::XYZTLorentzVector &p4, float mindr, float maxdr, float kt_scale)
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
isolation value pair for temporary storage before being folded into the muon
bool embedGenMatch_
embed the gen match information into the muon
const Point & position() const
position
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels, std::vector< edm::EDGetTokenT< edm::ValueMap< T > > > &tokens)
IsolationLabels isoDepositLabels_
input source for isoDeposits
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
input tags for generator match information
Covariance3DMatrix rotatedCovariance3D() const
IsolationLabels isolationValueLabels_
input source isolation value maps
bool recomputeBasicSelectors_
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
void embedPickyMuon()
embed reference to the above picky Track
bool forceEmbedBestTrack_
force separate embed of the best track even if already embedded
bool embedPFCandidate_
embed pfCandidates into the muon
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
void setNumberOfValidHits(unsigned int numberOfValidHits)
bool computeMuonMVA_
standard muon selectors
void setSimEta(float eta)
bool embedCombinedMuon_
embed track of the combined fit into the muon
Analysis-level muon class.
pat::helper::KinResolutionsLoader resolutionLoader_
helper class to add resolutions to the muon
static std::string const source
void setP4(const LorentzVector &p4) final
set 4-momentum
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_neutral_hadrons_
Global3DVector GlobalVector
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
bool embedHighLevelSelection_
embed high level selection variables