CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ( 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 }
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_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
StringCutObjectSelector< reco::Muon, false > muonsCut_
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
edm::InputTag caloMuons_
CaloMuonMerger::~CaloMuonMerger ( )
inlineoverride

Definition at line 25 of file CaloMuonMerger.cc.

25 {}

Member Function Documentation

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

Definition at line 62 of file CaloMuonMerger.cc.

References reco::Muon::caloCompatibility(), reco::Muon::CaloMuon, caloMuonsCut_, caloMuonToken_, relval_parameters_module::energy, reco::LeafCandidate::eta(), Exception, edm::Event::getByToken(), mps_fire::i, reco::Muon::isCaloCompatibilityValid(), reco::isMuon(), edm::Ref< C, T, F >::isNonnull(), mergeCaloMuons_, mergeTracks_, minCaloCompatibility_, eostools::move(), RPCpg::mu, HLT_FULL_cff::muon, patZpeak::muons, muonsCut_, muonToken_, submitPVResolutionJobs::out, reco::LeafCandidate::pt(), edm::Event::put(), reco::Muon::setCalEnergy(), reco::Muon::setCaloCompatibility(), reco::Muon::setInnerTrack(), reco::Muon::setType(), mathSSE::sqrt(), reco::Muon::track(), HLT_FULL_cff::track, tracks, tracksCut_, trackToken_, and reco::Muon::type().

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()) {
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);
109  }
110  }
111 
112  // merge reco::Track avoiding duplication of innerTracks
113  if (mergeTracks_) {
114  for (size_t i = 0; i < tracks->size(); i++) {
115  reco::TrackRef track(tracks, 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 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
double pt() const final
transverse momentum
void setType(unsigned int type)
Definition: Muon.h:296
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
bool isCaloCompatibilityValid() const
Definition: Muon.h:160
auto const & tracks
cannot be loose
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: Muon.h:108
StringCutObjectSelector< reco::CaloMuon, false > caloMuonsCut_
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
double minCaloCompatibility_
edm::EDGetTokenT< std::vector< reco::Track > > trackToken_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
void setCaloCompatibility(float input)
Definition: Muon.h:159
T sqrt(T t)
Definition: SSEVec.h:19
def move
Definition: eostools.py:511
const int mu
Definition: Constants.h:22
edm::EDGetTokenT< std::vector< reco::Muon > > muonToken_
StringCutObjectSelector< reco::Muon, false > muonsCut_
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
static const unsigned int CaloMuon
Definition: Muon.h:290
tuple muons
Definition: patZpeak.py:41
unsigned int type() const
Definition: Muon.h:297
float caloCompatibility() const
Definition: Muon.h:158
double eta() const final
momentum pseudorapidity

Member Data Documentation

edm::InputTag CaloMuonMerger::caloMuons_
private

Definition at line 33 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

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

Definition at line 34 of file CaloMuonMerger.cc.

Referenced by produce().

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

Definition at line 41 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().

bool CaloMuonMerger::mergeCaloMuons_
private

Definition at line 32 of file CaloMuonMerger.cc.

Referenced by produce().

bool CaloMuonMerger::mergeTracks_
private

Definition at line 36 of file CaloMuonMerger.cc.

Referenced by produce().

double CaloMuonMerger::minCaloCompatibility_
private

Definition at line 35 of file CaloMuonMerger.cc.

Referenced by produce().

edm::InputTag CaloMuonMerger::muons_
private

Definition at line 30 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

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

Definition at line 31 of file CaloMuonMerger.cc.

Referenced by produce().

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

Definition at line 40 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().

edm::InputTag CaloMuonMerger::tracks_
private

Definition at line 37 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

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

Definition at line 38 of file CaloMuonMerger.cc.

Referenced by produce().

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

Definition at line 42 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().