CMS 3D CMS Logo

PATMuonProducer.h
Go to the documentation of this file.
1 //
2 //
3 
4 #ifndef PhysicsTools_PatAlgos_PATMuonProducer_h
5 #define PhysicsTools_PatAlgos_PATMuonProducer_h
6 
18 #include <string>
19 
25 
30 
41 
42 namespace pat {
43 
45  public:
47 
48  std::unique_ptr<const pat::MuonMvaEstimator> const& muonMvaEstimator() const { return muonMvaEstimator_; }
49  std::unique_ptr<const pat::MuonMvaEstimator> const& muonLowPtMvaEstimator() const { return muonLowPtMvaEstimator_; }
50 
51  std::unique_ptr<const pat::SoftMuonMvaEstimator> const& softMuonMvaEstimator() const {
52  return softMuonMvaEstimator_;
53  }
54 
55  private:
56  std::unique_ptr<const pat::MuonMvaEstimator> muonLowPtMvaEstimator_;
57  std::unique_ptr<const pat::MuonMvaEstimator> muonMvaEstimator_;
58  std::unique_ptr<const pat::SoftMuonMvaEstimator> softMuonMvaEstimator_;
59  };
60 
62  class TrackerIsolationPt;
63  class CaloIsolationEnergy;
64 
66  class PATMuonProducer : public edm::stream::EDProducer<edm::GlobalCache<PATMuonHeavyObjectCache>> {
67  public:
69  explicit PATMuonProducer(const edm::ParameterSet& iConfig, PATMuonHeavyObjectCache const*);
71  ~PATMuonProducer() override;
72 
73  static std::unique_ptr<PATMuonHeavyObjectCache> initializeGlobalCache(const edm::ParameterSet& iConfig) {
74  return std::make_unique<PATMuonHeavyObjectCache>(iConfig);
75  }
76 
78 
80  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
82  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
83 
84  private:
87  typedef std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> GenAssociations;
88  typedef std::vector<edm::Handle<edm::ValueMap<IsoDeposit>>> IsoDepositMaps;
89  typedef std::vector<edm::Handle<edm::ValueMap<double>>> IsolationValueMaps;
90  typedef std::pair<pat::IsolationKeys, edm::InputTag> IsolationLabel;
91  typedef std::vector<IsolationLabel> IsolationLabels;
92 
94  void fillMuon(Muon& aMuon,
95  const MuonBaseRef& muonRef,
96  const reco::CandidateBaseRef& baseRef,
97  const GenAssociations& genMatches,
98  const IsoDepositMaps& deposits,
99  const IsolationValueMaps& isolationValues) const;
102  template <typename T>
103  void readIsolationLabels(const edm::ParameterSet& iConfig,
104  const char* psetName,
105  IsolationLabels& labels,
106  std::vector<edm::EDGetTokenT<edm::ValueMap<T>>>& tokens);
107 
108  void setMuonMiniIso(pat::Muon& aMuon, const pat::PackedCandidateCollection* pc);
109  double getRelMiniIsoPUCorrected(const pat::Muon& muon, double rho, const std::vector<double>& area);
110 
111  double puppiCombinedIsolation(const pat::Muon& muon, const pat::PackedCandidateCollection* pc);
112  bool isNeutralHadron(long pdgid);
113  bool isChargedHadron(long pdgid);
114  bool isPhoton(long pdgid);
115 
116  // embed various impact parameters with errors
117  // embed high level selection
118  void embedHighLevel(pat::Muon& aMuon,
122  bool primaryVertexIsValid,
124  bool beamspotIsValid);
125  double relMiniIsoPUCorrected(const pat::Muon& aMuon, double rho);
126  std::optional<GlobalPoint> getMuonDirection(const reco::MuonChamberMatch& chamberMatch,
128  const DetId& chamberId);
129  void fillL1TriggerInfo(pat::Muon& muon,
130  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
131  const edm::TriggerNames& names,
133  void fillHltTriggerInfo(pat::Muon& muon,
134  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
135  const edm::TriggerNames& names,
136  const std::vector<std::string>& collection_names);
137 
138  private:
141 
142  // for mini-iso calculation
146  std::vector<double> effectiveAreaVec_;
147  std::vector<double> miniIsoParams_;
149 
185  std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection>>> genMatchTokens_;
205  IsolationLabels isoDepositLabels_;
206  std::vector<edm::EDGetTokenT<edm::ValueMap<IsoDeposit>>> isoDepositTokens_;
208  IsolationLabels isolationValueLabels_;
209  std::vector<edm::EDGetTokenT<edm::ValueMap<double>>> isolationValueTokens_;
218  //PUPPI isolation tokens
222  //PUPPINoLeptons isolation tokens
235 
247 
250 
255  std::vector<std::string> hltCollectionFilters_;
256  };
257 
258 } // namespace pat
259 
260 template <typename T>
262  const char* psetName,
264  std::vector<edm::EDGetTokenT<edm::ValueMap<T>>>& tokens) {
265  labels.clear();
266 
267  if (iConfig.exists(psetName)) {
268  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>(psetName);
269 
270  if (depconf.exists("tracker"))
271  labels.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
272  if (depconf.exists("ecal"))
273  labels.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
274  if (depconf.exists("hcal"))
275  labels.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
276  if (depconf.exists("pfAllParticles")) {
277  labels.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
278  }
279  if (depconf.exists("pfChargedHadrons")) {
280  labels.push_back(
281  std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons")));
282  }
283  if (depconf.exists("pfChargedAll")) {
284  labels.push_back(std::make_pair(pat::PfChargedAllIso, depconf.getParameter<edm::InputTag>("pfChargedAll")));
285  }
286  if (depconf.exists("pfPUChargedHadrons")) {
287  labels.push_back(
288  std::make_pair(pat::PfPUChargedHadronIso, depconf.getParameter<edm::InputTag>("pfPUChargedHadrons")));
289  }
290  if (depconf.exists("pfNeutralHadrons")) {
291  labels.push_back(
292  std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons")));
293  }
294  if (depconf.exists("pfPhotons")) {
295  labels.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons")));
296  }
297  if (depconf.exists("user")) {
298  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag>>("user");
299  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
301  for (; it != ed; ++it, ++key) {
302  labels.push_back(std::make_pair(pat::IsolationKeys(key), *it));
303  }
304  tokens = edm::vector_transform(
305  labels, [this](IsolationLabel const& label) { return consumes<edm::ValueMap<T>>(label.second); });
306  }
307  }
308  tokens = edm::vector_transform(labels, [this](pat::PATMuonProducer::IsolationLabel const& label) {
309  return consumes<edm::ValueMap<T>>(label.second);
310  });
311 }
312 
313 #endif
bool embedTpfmsMuon_
embed track from tpfms muon fit into the muon
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_charged_hadrons_
bool useUserData_
add user data to the muon (this will be data members of th muon even w/o embedding) ...
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels, std::vector< edm::EDGetTokenT< edm::ValueMap< T >>> &tokens)
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_photons_
T getParameter(std::string const &) const
Assists in assimilating all pat::UserData into pat objects.
bool addPuppiIsolation_
add puppi isolation
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > tcMETMuonCorrsToken_
source of tcMET muon corrections
bool embedTcMETMuonCorrs_
embed muon MET correction info for tcMET into the muon
class definition
edm::EDGetTokenT< std::vector< reco::Vertex > > pvToken_
input source of the primary vertex
edm::EDGetTokenT< edm::ValueMap< reco::MuonTimeExtra > > muonTimeExtraToken_
input tag for reading inverse beta
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_photons_
edm::EDGetTokenT< double > rho_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
input source
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 embedCaloMETMuonCorrs_
embed muon MET correction info for caloMET into the muon
edm::EDGetTokenT< edm::ValueMap< reco::MuonSimInfo > > simInfo_
MC info.
std::vector< pat::PackedCandidate > PackedCandidateCollection
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool addTriggerMatching_
Trigger.
bool embedBestTrack_
embed the track from best muon measurement (global pflow)
edm::EDGetTokenT< reco::JetCorrector > mvaL1Corrector_
bool addResolutions_
add resolutions to the muon (this will be data members of th muon even w/o embedding) ...
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_charged_hadrons_
std::vector< double > miniIsoParams_
std::vector< double > effectiveAreaVec_
const std::string names[nVars_]
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_neutral_hadrons_
edm::EDGetTokenT< reco::JetTagCollection > mvaBTagCollectionTag_
edm::EDGetTokenT< reco::PFCandidateCollection > pfMuonToken_
input source pfCandidates that will be to be transformed into pat::Muons, when using PF2PAT ...
pat::helper::MultiIsolator isolator_
helper class to add userdefined isolation values to the muon
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
Definition: HeavyIon.h:7
std::vector< IsolationLabel > IsolationLabels
edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
input source of the primary vertex/beamspot
std::unique_ptr< const pat::MuonMvaEstimator > muonLowPtMvaEstimator_
bool addInverseBeta_
add combined inverse beta measurement into the muon
bool useParticleFlow_
switch to use particle flow (PF2PAT) or not
pat::PATUserDataHelper< pat::Muon > userDataHelper_
helper class to add userData to the muon
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps
char const * label
bool embedStandAloneMuon_
embed track from muon system into the muon
edm::EDGetTokenT< edm::TriggerResults > triggerResults_
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< const pat::SoftMuonMvaEstimator > const & softMuonMvaEstimator() const
GreaterByPt< Muon > pTComparator_
bool embedTrack_
embed the track from inner tracker into the muon
bool addGenMatch_
add generator match information
PATMuonHeavyObjectCache(const edm::ParameterSet &)
Definition: Muon.py:1
bool embedPfEcalEnergy_
add ecal PF energy
bool getdBFromTrack_
switch on reading the dB information from the track
std::unique_ptr< const pat::MuonMvaEstimator > muonMvaEstimator_
edm::EDGetTokenT< pat::PackedCandidateCollection > pcToken_
std::pair< pat::IsolationKeys, edm::InputTag > IsolationLabel
static void globalEndJob(PATMuonHeavyObjectCache *)
std::vector< std::string > hltCollectionFilters_
static std::unique_ptr< PATMuonHeavyObjectCache > initializeGlobalCache(const edm::ParameterSet &iConfig)
Definition: DetId.h:18
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 >
Definition: transform.h:11
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool embedTunePBestTrack_
embed the track from best muon measurement (muon only)
std::unique_ptr< const pat::SoftMuonMvaEstimator > softMuonMvaEstimator_
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
edm::EDGetTokenT< reco::JetCorrector > mvaL1L2L3ResCorrector_
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:16
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
pat::helper::EfficiencyLoader efficiencyLoader_
helper class to add efficiencies to the muon
bool embedPickyMuon_
embed track from picky muon fit into the muon
bool embedDytMuon_
embed track from DYT muon fit into the muon
Calculates a lepton&#39;s calorimetric isolation energy.
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
isolation value pair for temporary storage before being folded into the muon
std::unique_ptr< const pat::MuonMvaEstimator > const & muonMvaEstimator() const
edm::EDGetTokenT< std::vector< pat::TriggerObjectStandAlone > > triggerObjects_
bool embedGenMatch_
embed the gen match information into the muon
IsolationLabels isoDepositLabels_
input source for isoDeposits
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
input tags for generator match information
IsolationLabels isolationValueLabels_
input source isolation value maps
bool forceEmbedBestTrack_
force separate embed of the best track even if already embedded
edm::RefToBase< reco::Muon > MuonBaseRef
typedefs for convenience
bool embedPFCandidate_
embed pfCandidates into the muon
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
bool computeMuonMVA_
standard muon selectors
bool embedCombinedMuon_
embed track of the combined fit into the muon
Analysis-level muon class.
Definition: Muon.h:51
pat::helper::KinResolutionsLoader resolutionLoader_
helper class to add resolutions to the muon
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_neutral_hadrons_
Calculates a lepton&#39;s tracker isolation pt.
std::unique_ptr< const pat::MuonMvaEstimator > const & muonLowPtMvaEstimator() const
bool embedHighLevelSelection_
embed high level selection variables