CMS 3D CMS Logo

CaloMuonMerger.cc
Go to the documentation of this file.
1 //
2 //
3 
15 
19 
21 
23 public:
24  explicit CaloMuonMerger(const edm::ParameterSet& iConfig);
25  ~CaloMuonMerger() override {}
26 
27  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
28 
29 private:
39 
43 };
44 
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),
54  tracks_(mergeTracks_ ? iConfig.getParameter<edm::InputTag>("tracks") : edm::InputTag()),
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 }
61 
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 }
151 
CaloMuonMerger::minCaloCompatibility_
double minCaloCompatibility_
Definition: CaloMuonMerger.cc:35
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
Muon.h
CaloMuonMerger::caloMuonsCut_
StringCutObjectSelector< reco::CaloMuon, false > caloMuonsCut_
Definition: CaloMuonMerger.cc:34
funct::false
false
Definition: Factorize.h:34
muon
Definition: MuonCocktails.h:17
CaloMuonMerger::trackToken_
edm::EDGetTokenT< std::vector< reco::Track > > trackToken_
Definition: CaloMuonMerger.cc:42
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
CaloMuonMerger::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: CaloMuonMerger.cc:62
EDProducer.h
CaloMuonMerger::tracksCut_
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
Definition: CaloMuonMerger.cc:38
CaloMuonMerger::muonToken_
edm::EDGetTokenT< std::vector< reco::Muon > > muonToken_
Definition: CaloMuonMerger.cc:40
edm::Handle
Definition: AssociativeIterator.h:50
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackCollection >
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuonFwd.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
CaloMuonMerger::muonsCut_
StringCutObjectSelector< reco::Muon, false > muonsCut_
Definition: CaloMuonMerger.cc:31
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CaloMuonMerger::caloMuons_
edm::InputTag caloMuons_
Definition: CaloMuonMerger.cc:33
CaloMuon.h
funct::true
true
Definition: Factorize.h:173
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
CaloMuonMerger::caloMuonToken_
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
Definition: CaloMuonMerger.cc:41
iEvent
int iEvent
Definition: GenABIO.cc:224
mergedMuons_cfi.caloMuons
caloMuons
Definition: mergedMuons_cfi.py:7
reco::Muon::CaloMuon
static const unsigned int CaloMuon
Definition: Muon.h:288
p4
double p4[4]
Definition: TauolaWrapper.h:92
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
CaloMuonMerger::CaloMuonMerger
CaloMuonMerger(const edm::ParameterSet &iConfig)
Definition: CaloMuonMerger.cc:45
InputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
CaloMuonMerger::tracks_
edm::InputTag tracks_
Definition: CaloMuonMerger.cc:37
CaloMuonMerger::mergeCaloMuons_
bool mergeCaloMuons_
Definition: CaloMuonMerger.cc:32
CaloMuonMerger::mergeTracks_
bool mergeTracks_
Definition: CaloMuonMerger.cc:36
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
StringCutObjectSelector< reco::Muon, false >
Exception
Definition: hltDiff.cc:246
CaloMuonMerger::muons_
edm::InputTag muons_
Definition: CaloMuonMerger.cc:30
CaloMuonMerger::~CaloMuonMerger
~CaloMuonMerger() override
Definition: CaloMuonMerger.cc:25
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
CaloMuonMerger
Merges reco::CaloMuons, reco::Muons and optionally reco::Tracks avoiding innerTrack duplications in a...
Definition: CaloMuonMerger.cc:22
reco::isMuon
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:9