CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CaloMuonMerger (const edm::ParameterSet &iConfig)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
virtual ~CaloMuonMerger ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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:184
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_
virtual CaloMuonMerger::~CaloMuonMerger ( )
inlinevirtual

Definition at line 26 of file CaloMuonMerger.cc.

26 { }

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 68 of file CaloMuonMerger.cc.

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

68  {
72 
73  iEvent.getByToken(muonToken_,muons);
74  if(mergeCaloMuons_) iEvent.getByToken(caloMuonToken_,caloMuons);
75  if(mergeTracks_) iEvent.getByToken(trackToken_,tracks);
76 
77  std::auto_ptr<std::vector<reco::Muon> > out(new 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(out);
147 }
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
void setType(unsigned int type)
Definition: Muon.h:214
virtual float pt() const
transverse momentum
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
bool isCaloCompatibilityValid() const
Definition: Muon.h:152
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:49
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:151
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
virtual float eta() const
momentum pseudorapidity
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
const int mu
Definition: Constants.h:22
edm::EDGetTokenT< std::vector< reco::Muon > > muonToken_
tuple out
Definition: dbtoconf.py:99
tuple tracks
Definition: testEve_cfg.py:39
StringCutObjectSelector< reco::Muon, false > muonsCut_
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
static const unsigned int CaloMuon
Definition: Muon.h:210
tuple muons
Definition: patZpeak.py:38
unsigned int type() const
Definition: Muon.h:215
float caloCompatibility() const
Definition: Muon.h:150

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().