CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
CaloMuonMerger Class Reference

Merges reco::CaloMuons, reco::Muons and optionally reco::Tracks avoiding innerTrack duplications in a single reco::Muon collection. More...

#include "RecoMuon/MuonIdentification/plugins/CaloMuonMerger.cc"

Inheritance diagram for CaloMuonMerger:
edm::stream::EDProducer<>

Public Member Functions

 CaloMuonMerger (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~CaloMuonMerger () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Attributes

edm::InputTag caloMuons_
 
StringCutObjectSelector< reco::CaloMuon, false > caloMuonsCut_
 
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
 
bool mergeCaloMuons_
 
bool mergeTracks_
 
double minCaloCompatibility_
 
edm::InputTag muons_
 
StringCutObjectSelector< reco::Muon, false > muonsCut_
 
edm::EDGetTokenT< std::vector< reco::Muon > > muonToken_
 
edm::InputTag tracks_
 
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
 
edm::EDGetTokenT< std::vector< reco::Track > > trackToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Merges reco::CaloMuons, reco::Muons and optionally reco::Tracks avoiding innerTrack duplications in a single reco::Muon collection.

Author
Giovanni Petrucciani

Definition at line 22 of file CaloMuonMerger.cc.

Constructor & Destructor Documentation

◆ CaloMuonMerger()

CaloMuonMerger::CaloMuonMerger ( const edm::ParameterSet iConfig)
explicit

Definition at line 45 of file CaloMuonMerger.cc.

References caloMuons_, caloMuonToken_, muons_, muonToken_, tracks_, and trackToken_.

46  : muons_(iConfig.getParameter<edm::InputTag>("muons")),
47  muonsCut_(iConfig.existsAs<std::string>("muonsCut") ? iConfig.getParameter<std::string>("muonsCut") : ""),
48  mergeCaloMuons_(iConfig.existsAs<bool>("mergeCaloMuons") ? iConfig.getParameter<bool>("mergeCaloMuons") : true),
49  caloMuons_(iConfig.getParameter<edm::InputTag>("caloMuons")),
50  caloMuonsCut_(iConfig.existsAs<std::string>("caloMuonsCut") ? iConfig.getParameter<std::string>("caloMuonsCut")
51  : ""),
52  minCaloCompatibility_(mergeCaloMuons_ ? iConfig.getParameter<double>("minCaloCompatibility") : 0),
53  mergeTracks_(iConfig.existsAs<bool>("mergeTracks") ? iConfig.getParameter<bool>("mergeTracks") : false),
55  tracksCut_(iConfig.existsAs<std::string>("tracksCut") ? iConfig.getParameter<std::string>("tracksCut") : "") {
56  muonToken_ = consumes<std::vector<reco::Muon>>(muons_);
57  caloMuonToken_ = consumes<std::vector<reco::CaloMuon>>(caloMuons_);
58  trackToken_ = consumes<std::vector<reco::Track>>(tracks_);
59  produces<std::vector<reco::Muon>>();
60 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
StringCutObjectSelector< reco::CaloMuon, false > caloMuonsCut_
double minCaloCompatibility_
edm::EDGetTokenT< std::vector< reco::Track > > trackToken_
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
edm::InputTag tracks_
edm::EDGetTokenT< std::vector< reco::Muon > > muonToken_
edm::InputTag muons_
StringCutObjectSelector< reco::Muon, false > muonsCut_
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
edm::InputTag caloMuons_

◆ ~CaloMuonMerger()

CaloMuonMerger::~CaloMuonMerger ( )
inlineoverride

Definition at line 25 of file CaloMuonMerger.cc.

25 {}

Member Function Documentation

◆ produce()

void CaloMuonMerger::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 62 of file CaloMuonMerger.cc.

References reco::Muon::CaloMuon, mergedMuons_cfi::caloMuons, caloMuonsCut_, caloMuonToken_, HCALHighEnergyHPDFilter_cfi::energy, Exception, mps_fire::i, iEvent, reco::isMuon(), mergeCaloMuons_, mergeTracks_, minCaloCompatibility_, eostools::move(), amptDefaultParameters_cff::mu, PDWG_BPHSkim_cff::muons, muonsCut_, muonToken_, MillePedeFileConverter_cfg::out, mathSSE::sqrt(), HLT_2022v11_cff::track, tracks, tracksCut_, and trackToken_.

62  {
66 
67  iEvent.getByToken(muonToken_, muons);
68  if (mergeCaloMuons_)
69  iEvent.getByToken(caloMuonToken_, caloMuons);
70  if (mergeTracks_)
71  iEvent.getByToken(trackToken_, tracks);
72 
73  auto out = std::make_unique<std::vector<reco::Muon>>();
74  out->reserve(muons->size() + (mergeTracks_ ? tracks->size() : 0));
75 
76  // copy reco::Muons, turning on the CaloCompatibility flag if enabled and possible
77  for (std::vector<reco::Muon>::const_iterator it = muons->begin(), ed = muons->end(); it != ed; ++it) {
78  if (!muonsCut_(*it))
79  continue;
80  out->push_back(*it);
81  reco::Muon& mu = out->back();
82  if (mergeCaloMuons_ && mu.track().isNonnull()) {
83  if (mu.isCaloCompatibilityValid()) {
84  if (mu.caloCompatibility() >= minCaloCompatibility_) {
85  mu.setType(mu.type() | reco::Muon::CaloMuon);
86  }
87  } else
88  throw cms::Exception("Boh") << "Muon with track and no CaloCompatibility; pt = " << mu.pt()
89  << ", eta = " << mu.eta() << ", type = " << mu.type() << "\n";
90  }
91  }
92 
93  if (mergeCaloMuons_) {
94  // copy reco::CaloMuon
95  for (std::vector<reco::CaloMuon>::const_iterator it = caloMuons->begin(), ed = caloMuons->end(); it != ed; ++it) {
96  if (!caloMuonsCut_(*it))
97  continue;
98  // make a reco::Muon
99  reco::TrackRef track = it->track();
100  double energy = sqrt(track->p() * track->p() + 0.011163691);
101  math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
102  out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
103  reco::Muon& mu = out->back();
104  // fill info
105  mu.setCalEnergy(it->calEnergy());
106  mu.setCaloCompatibility(it->caloCompatibility());
107  mu.setInnerTrack(track);
108  mu.setType(reco::Muon::CaloMuon);
109  }
110  }
111 
112  // merge reco::Track avoiding duplication of innerTracks
113  if (mergeTracks_) {
114  for (size_t i = 0; i < tracks->size(); i++) {
116  if (!tracksCut_(track))
117  continue;
118  // check if it is a muon or calomuon
119  bool isMuon = false;
120  for (std::vector<reco::Muon>::const_iterator muon = muons->begin(); muon < muons->end(); muon++) {
121  if (muon->innerTrack() == track) {
122  isMuon = true;
123  break;
124  }
125  }
126  if (isMuon)
127  continue;
128  if (mergeCaloMuons_) {
129  bool isCaloMuon = false;
130  for (std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon < caloMuons->end(); muon++) {
131  if (muon->innerTrack() == track) {
132  isCaloMuon = true;
133  break;
134  }
135  }
136  if (isCaloMuon)
137  continue;
138  }
139  // make a reco::Muon
140  double energy = sqrt(track->p() * track->p() + 0.011163691);
141  math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
142  out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
143  reco::Muon& mu = out->back();
144  // fill info
145  mu.setInnerTrack(track);
146  }
147  }
148 
149  iEvent.put(std::move(out));
150 }
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:9
StringCutObjectSelector< reco::CaloMuon, false > caloMuonsCut_
double minCaloCompatibility_
edm::EDGetTokenT< std::vector< reco::Track > > trackToken_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
T sqrt(T t)
Definition: SSEVec.h:19
edm::EDGetTokenT< std::vector< reco::Muon > > muonToken_
auto const & tracks
cannot be loose
StringCutObjectSelector< reco::Muon, false > muonsCut_
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
static const unsigned int CaloMuon
Definition: Muon.h:290
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ caloMuons_

edm::InputTag CaloMuonMerger::caloMuons_
private

Definition at line 33 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

◆ caloMuonsCut_

StringCutObjectSelector<reco::CaloMuon, false> CaloMuonMerger::caloMuonsCut_
private

Definition at line 34 of file CaloMuonMerger.cc.

Referenced by produce().

◆ caloMuonToken_

edm::EDGetTokenT<std::vector<reco::CaloMuon> > CaloMuonMerger::caloMuonToken_
private

Definition at line 41 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().

◆ mergeCaloMuons_

bool CaloMuonMerger::mergeCaloMuons_
private

Definition at line 32 of file CaloMuonMerger.cc.

Referenced by produce().

◆ mergeTracks_

bool CaloMuonMerger::mergeTracks_
private

Definition at line 36 of file CaloMuonMerger.cc.

Referenced by produce().

◆ minCaloCompatibility_

double CaloMuonMerger::minCaloCompatibility_
private

Definition at line 35 of file CaloMuonMerger.cc.

Referenced by produce().

◆ muons_

edm::InputTag CaloMuonMerger::muons_
private

Definition at line 30 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

◆ muonsCut_

StringCutObjectSelector<reco::Muon, false> CaloMuonMerger::muonsCut_
private

Definition at line 31 of file CaloMuonMerger.cc.

Referenced by produce().

◆ muonToken_

edm::EDGetTokenT<std::vector<reco::Muon> > CaloMuonMerger::muonToken_
private

Definition at line 40 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().

◆ tracks_

edm::InputTag CaloMuonMerger::tracks_
private

Definition at line 37 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

◆ tracksCut_

StringCutObjectSelector<reco::TrackRef, false> CaloMuonMerger::tracksCut_
private

Definition at line 38 of file CaloMuonMerger.cc.

Referenced by produce().

◆ trackToken_

edm::EDGetTokenT<std::vector<reco::Track> > CaloMuonMerger::trackToken_
private

Definition at line 42 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().