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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

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<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache 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 23 of file CaloMuonMerger.cc.

Constructor & Destructor Documentation

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

Definition at line 50 of file CaloMuonMerger.cc.

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

50  :
51  muons_(iConfig.getParameter<edm::InputTag>("muons")),
52  muonsCut_(iConfig.existsAs<std::string>("muonsCut") ? iConfig.getParameter<std::string>("muonsCut") : ""),
53  mergeCaloMuons_(iConfig.existsAs<bool>("mergeCaloMuons") ? iConfig.getParameter<bool>("mergeCaloMuons") : true),
54  caloMuons_(iConfig.getParameter<edm::InputTag>("caloMuons")),
55  caloMuonsCut_(iConfig.existsAs<std::string>("caloMuonsCut") ? iConfig.getParameter<std::string>("caloMuonsCut") : ""),
56  minCaloCompatibility_(mergeCaloMuons_ ? iConfig.getParameter<double>("minCaloCompatibility") : 0),
57  mergeTracks_(iConfig.existsAs<bool>("mergeTracks") ? iConfig.getParameter<bool>("mergeTracks") : false),
59  tracksCut_(iConfig.existsAs<std::string>("tracksCut") ? iConfig.getParameter<std::string>("tracksCut") : "")
60 {
61  muonToken_ = consumes<std::vector<reco::Muon> >(muons_);
62  caloMuonToken_=consumes<std::vector<reco::CaloMuon> >(caloMuons_);
63  trackToken_ = consumes<std::vector<reco::Track> > (tracks_);
64  produces<std::vector<reco::Muon> >();
65 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
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 ( )
inlineoverride

Definition at line 26 of file CaloMuonMerger.cc.

References iEvent, and produce().

26 { }

Member Function Documentation

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

Definition at line 68 of file CaloMuonMerger.cc.

References reco::Muon::caloCompatibility(), reco::Muon::CaloMuon, mergedMuons_cfi::caloMuons, caloMuonsCut_, caloMuonToken_, DEFINE_FWK_MODULE, 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, nano_cff::muons, muonsCut_, muonToken_, MillePedeFileConverter_cfg::out, p4, reco::LeafCandidate::pt(), edm::Event::put(), reco::Muon::setCalEnergy(), reco::Muon::setCaloCompatibility(), reco::Muon::setInnerTrack(), reco::Muon::setType(), mathSSE::sqrt(), HiIsolationCommonParameters_cff::track, reco::Muon::track(), l1t::tracks, tracksCut_, trackToken_, and reco::Muon::type().

Referenced by ~CaloMuonMerger().

68  {
72 
73  iEvent.getByToken(muonToken_,muons);
74  if(mergeCaloMuons_) iEvent.getByToken(caloMuonToken_,caloMuons);
75  if(mergeTracks_) iEvent.getByToken(trackToken_,tracks);
76 
77  auto out = std::make_unique<std::vector<reco::Muon>>();
78  out->reserve(muons->size() + (mergeTracks_?tracks->size():0));
79 
80  // copy reco::Muons, turning on the CaloCompatibility flag if enabled and possible
81  for (std::vector<reco::Muon>::const_iterator it = muons->begin(), ed = muons->end(); it != ed; ++it) {
82  if(!muonsCut_(*it)) continue;
83  out->push_back(*it);
84  reco::Muon & mu = out->back();
85  if (mergeCaloMuons_ && mu.track().isNonnull()) {
86  if (mu.isCaloCompatibilityValid()) {
89  }
90  } else throw cms::Exception("Boh") << "Muon with track and no CaloCompatibility; pt = " << mu.pt() << ", eta = " << mu.eta() << ", type = " << mu.type() << "\n";
91  }
92  }
93 
94  if (mergeCaloMuons_) {
95  // copy reco::CaloMuon
96  for (std::vector<reco::CaloMuon>::const_iterator it = caloMuons->begin(), ed = caloMuons->end(); it != ed; ++it) {
97  if(!caloMuonsCut_(*it)) 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)) continue;
117  // check if it is a muon or calomuon
118  bool isMuon = false;
119  for(std::vector<reco::Muon>::const_iterator muon = muons->begin(); muon < muons->end(); muon++){
120  if(muon->innerTrack() == track){
121  isMuon = true;
122  break;
123  }
124  }
125  if(isMuon) continue;
126  if (mergeCaloMuons_) {
127  bool isCaloMuon = false;
128  for(std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon < caloMuons->end(); muon++){
129  if(muon->innerTrack() == track){
130  isCaloMuon = true;
131  break;
132  }
133  }
134  if(isCaloMuon) continue;
135  }
136  // make a reco::Muon
137  double energy = sqrt(track->p() * track->p() + 0.011163691);
138  math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
139  out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
140  reco::Muon & mu = out->back();
141  // fill info
142  mu.setInnerTrack( track );
143  }
144  }
145 
146  iEvent.put(std::move(out));
147 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
TrackRef track() const override
reference to a Track
Definition: Muon.h:49
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
double eta() const final
momentum pseudorapidity
void setType(unsigned int type)
Definition: Muon.h:268
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
bool isCaloCompatibilityValid() const
Definition: Muon.h:156
double pt() const final
transverse momentum
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: Muon.h:113
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
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
void setCaloCompatibility(float input)
Definition: Muon.h:155
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
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:262
unsigned int type() const
Definition: Muon.h:269
float caloCompatibility() const
Definition: Muon.h:154
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

edm::InputTag CaloMuonMerger::caloMuons_
private

Definition at line 34 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

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

Definition at line 35 of file CaloMuonMerger.cc.

Referenced by produce().

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

Definition at line 42 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().

bool CaloMuonMerger::mergeCaloMuons_
private

Definition at line 33 of file CaloMuonMerger.cc.

Referenced by produce().

bool CaloMuonMerger::mergeTracks_
private

Definition at line 37 of file CaloMuonMerger.cc.

Referenced by produce().

double CaloMuonMerger::minCaloCompatibility_
private

Definition at line 36 of file CaloMuonMerger.cc.

Referenced by produce().

edm::InputTag CaloMuonMerger::muons_
private

Definition at line 31 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

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

Definition at line 32 of file CaloMuonMerger.cc.

Referenced by produce().

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

Definition at line 41 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().

edm::InputTag CaloMuonMerger::tracks_
private

Definition at line 38 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger().

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

Definition at line 39 of file CaloMuonMerger.cc.

Referenced by produce().

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

Definition at line 43 of file CaloMuonMerger.cc.

Referenced by CaloMuonMerger(), and produce().