35 std::vector<edm::EDGetTokenT<reco::PFCandidateCollection>>
pf_;
36 std::vector<edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>>>
pf2pc_;
42 std::vector<edm::EDGetTokenT<edm::Association<reco::TrackExtraCollection>>>
trackExtraAssocs_;
49 linkToPackedPF_(iConfig.getParameter<
bool>(
"linkToPackedPFCandidates")),
50 saveTeVMuons_(iConfig.getParameter<
std::
string>(
"saveTeVMuons")),
51 dropDirectionalIso_(iConfig.getParameter<
std::
string>(
"dropDirectionalIso")),
52 dropPfP4_(iConfig.getParameter<
std::
string>(
"dropPfP4")),
53 slimCaloVars_(iConfig.getParameter<
std::
string>(
"slimCaloVars")),
54 slimKinkVars_(iConfig.getParameter<
std::
string>(
"slimKinkVars")),
55 slimCaloMETCorr_(iConfig.getParameter<
std::
string>(
"slimCaloMETCorr")),
56 slimMatches_(iConfig.getParameter<
std::
string>(
"slimMatches")),
57 segmentsMuonSelection_(iConfig.getParameter<
std::
string>(
"segmentsMuonSelection")),
58 saveSegments_(iConfig.getParameter<
bool>(
"saveSegments")),
59 modifyMuon_(iConfig.getParameter<
bool>(
"modifyMuons")) {
61 const std::vector<edm::InputTag> &
pf = iConfig.
getParameter<std::vector<edm::InputTag>>(
"pfCandidates");
62 const std::vector<edm::InputTag> &pf2pc = iConfig.
getParameter<std::vector<edm::InputTag>>(
"packedPFCandidates");
63 if (
pf.size() != pf2pc.size())
64 throw cms::Exception(
"Configuration") <<
"Mismatching pfCandidates and packedPFCandidates\n";
66 pf_.push_back(consumes<reco::PFCandidateCollection>(
tag));
73 muonModifier_ = std::make_unique<pat::ObjectModifier<pat::Muon>>(mod_config, consumesCollector());
75 produces<std::vector<pat::Muon>>();
77 produces<DTRecSegment4DCollection>();
78 produces<CSCSegmentCollection>();
82 std::vector<edm::InputTag> trackExtraAssocTags = iConfig.
getParameter<std::vector<edm::InputTag>>(
"trackExtraAssocs");
90 muonModifier_->setEventContent(iSetup);
100 auto out = std::make_unique<std::vector<pat::Muon>>();
101 out->reserve(
src->size());
103 auto outDTSegments = std::make_unique<DTRecSegment4DCollection>();
104 std::set<DTRecSegment4DRef> dtSegmentsRefs;
105 auto outCSCSegments = std::make_unique<CSCSegmentCollection>();
106 std::set<CSCSegmentRef> cscSegmentsRefs;
109 muonModifier_->setEvent(
iEvent);
112 std::map<reco::CandidatePtr, pat::PackedCandidateRef> mu2pc;
113 if (linkToPackedPF_) {
116 for (
unsigned int ipfh = 0, npfh = pf_.size(); ipfh < npfh; ++ipfh) {
118 iEvent.getByToken(pf2pc_[ipfh], pf2pc);
119 const auto &pfcoll = (*pf);
120 const auto &pfmap = (*pf2pc);
121 for (
unsigned int i = 0,
n =
pf->size();
i <
n; ++
i) {
123 if (
p.muonRef().isNonnull())
129 std::vector<edm::Handle<edm::Association<reco::TrackExtraCollection>>>
trackExtraAssocs(trackExtraAssocs_.size());
130 for (
unsigned int i = 0;
i < trackExtraAssocs_.size(); ++
i) {
134 for (vector<pat::Muon>::const_iterator it =
src->begin(), ed =
src->end(); it != ed; ++it) {
139 muonModifier_->modify(
mu);
142 if (saveTeVMuons_(
mu)) {
147 if (linkToPackedPF_) {
150 if (dropDirectionalIso_(
mu)) {
152 mu.setPFIsolation(
"pfIsoMeanDRProfileR03",
zero);
153 mu.setPFIsolation(
"pfIsoSumDRProfileR03",
zero);
154 mu.setPFIsolation(
"pfIsoMeanDRProfileR04",
zero);
155 mu.setPFIsolation(
"pfIsoSumDRProfileR04",
zero);
157 if (
mu.isPFMuon() && dropPfP4_(
mu))
159 if (slimCaloVars_(
mu) &&
mu.isEnergyValid()) {
162 ene.
tower = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
tower);
164 ene.
towerS9 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
towerS9);
166 ene.
had = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
had);
168 ene.
hadS9 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hadS9);
170 ene.
hadMax = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hadMax);
172 ene.
em = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
em);
174 ene.
emS25 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
emS25);
176 ene.
emMax = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
emMax);
186 MiniFloatConverter::reduceMantissaToNbitsRounding<14>(ene.
ecal_position.Y()),
187 MiniFloatConverter::reduceMantissaToNbitsRounding<14>(ene.
ecal_position.Z()));
189 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hcal_position.Y()),
190 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hcal_position.Z()));
191 mu.setCalEnergy(ene);
193 if (slimKinkVars_(
mu) &&
mu.isQualityValid()) {
197 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(qual.
tkKink_position.Y()),
198 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(qual.
tkKink_position.Z()));
199 mu.setCombinedQuality(qual);
204 MiniFloatConverter::reduceMantissaToNbitsRounding<10>(corrs.
corrX()),
205 MiniFloatConverter::reduceMantissaToNbitsRounding<10>(corrs.
corrY()));
206 mu.embedCaloMETMuonCorrs(corrs);
208 if (slimMatches_(
mu) &&
mu.isMatchesValid()) {
210 cmatch.edgeX = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.edgeX);
211 cmatch.edgeY = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.edgeY);
212 cmatch.xErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.xErr);
213 cmatch.yErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.yErr);
214 cmatch.dXdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.dXdZErr);
215 cmatch.dYdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.dYdZErr);
217 smatch.
xErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
xErr);
218 smatch.
yErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
yErr);
219 smatch.
dXdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
dXdZErr);
220 smatch.
dYdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
dYdZErr);
221 if (saveSegments_ && segmentsMuonSelection_(
mu)) {
235 std::map<DTRecSegment4DRef, size_t> dtMap;
236 std::vector<DTRecSegment4D> outDTSegmentsTmp;
237 std::map<CSCSegmentRef, size_t> cscMap;
238 std::vector<CSCSegment> outCSCSegmentsTmp;
239 for (
auto &seg : dtSegmentsRefs) {
240 dtMap[seg] = outDTSegments->size();
241 outDTSegmentsTmp.push_back(*seg);
243 for (
auto &seg : cscSegmentsRefs) {
244 cscMap[seg] = outCSCSegments->size();
245 outCSCSegmentsTmp.push_back(*seg);
247 outDTSegments->put(
DTChamberId(), outDTSegmentsTmp.begin(), outDTSegmentsTmp.end());
248 outCSCSegments->put(
CSCDetId(), outCSCSegmentsTmp.begin(), outCSCSegmentsTmp.end());
251 for (
auto &
mu : *
out) {
252 if (
mu.isMatchesValid()) {