35 std::vector<edm::EDGetTokenT<reco::PFCandidateCollection>>
pf_;
36 std::vector<edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>>>
pf2pc_;
48 linkToPackedPF_(iConfig.getParameter<
bool>(
"linkToPackedPFCandidates")),
49 saveTeVMuons_(iConfig.getParameter<
std::
string>(
"saveTeVMuons")),
50 dropDirectionalIso_(iConfig.getParameter<
std::
string>(
"dropDirectionalIso")),
51 dropPfP4_(iConfig.getParameter<
std::
string>(
"dropPfP4")),
52 slimCaloVars_(iConfig.getParameter<
std::
string>(
"slimCaloVars")),
53 slimKinkVars_(iConfig.getParameter<
std::
string>(
"slimKinkVars")),
54 slimCaloMETCorr_(iConfig.getParameter<
std::
string>(
"slimCaloMETCorr")),
55 slimMatches_(iConfig.getParameter<
std::
string>(
"slimMatches")),
56 segmentsMuonSelection_(iConfig.getParameter<
std::
string>(
"segmentsMuonSelection")),
57 saveSegments_(iConfig.getParameter<
bool>(
"saveSegments")),
58 modifyMuon_(iConfig.getParameter<
bool>(
"modifyMuons")) {
60 const std::vector<edm::InputTag> &
pf = iConfig.
getParameter<std::vector<edm::InputTag>>(
"pfCandidates");
61 const std::vector<edm::InputTag> &pf2pc = iConfig.
getParameter<std::vector<edm::InputTag>>(
"packedPFCandidates");
62 if (
pf.size() != pf2pc.size())
63 throw cms::Exception(
"Configuration") <<
"Mismatching pfCandidates and packedPFCandidates\n";
65 pf_.push_back(consumes<reco::PFCandidateCollection>(
tag));
72 muonModifier_ = std::make_unique<pat::ObjectModifier<pat::Muon>>(mod_config, consumesCollector());
74 produces<std::vector<pat::Muon>>();
76 produces<DTRecSegment4DCollection>();
77 produces<CSCSegmentCollection>();
83 muonModifier_->setEventContent(iSetup);
93 auto out = std::make_unique<std::vector<pat::Muon>>();
96 auto outDTSegments = std::make_unique<DTRecSegment4DCollection>();
97 std::set<DTRecSegment4DRef> dtSegmentsRefs;
98 auto outCSCSegments = std::make_unique<CSCSegmentCollection>();
99 std::set<CSCSegmentRef> cscSegmentsRefs;
102 muonModifier_->setEvent(
iEvent);
105 std::map<reco::CandidatePtr, pat::PackedCandidateRef> mu2pc;
106 if (linkToPackedPF_) {
109 for (
unsigned int ipfh = 0, npfh = pf_.size(); ipfh < npfh; ++ipfh) {
111 iEvent.getByToken(pf2pc_[ipfh], pf2pc);
112 const auto &pfcoll = (*pf);
113 const auto &pfmap = (*pf2pc);
114 for (
unsigned int i = 0,
n =
pf->size();
i <
n; ++
i) {
116 if (
p.muonRef().isNonnull())
122 for (vector<pat::Muon>::const_iterator it =
src->begin(), ed =
src->end(); it != ed; ++it) {
127 muonModifier_->modify(
mu);
130 if (saveTeVMuons_(
mu)) {
135 if (linkToPackedPF_) {
138 if (dropDirectionalIso_(
mu)) {
140 mu.setPFIsolation(
"pfIsoMeanDRProfileR03", zero);
141 mu.setPFIsolation(
"pfIsoSumDRProfileR03", zero);
142 mu.setPFIsolation(
"pfIsoMeanDRProfileR04", zero);
143 mu.setPFIsolation(
"pfIsoSumDRProfileR04", zero);
145 if (
mu.isPFMuon() && dropPfP4_(
mu))
147 if (slimCaloVars_(
mu) &&
mu.isEnergyValid()) {
150 ene.
tower = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
tower);
152 ene.
towerS9 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
towerS9);
154 ene.
had = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
had);
156 ene.
hadS9 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hadS9);
158 ene.
hadMax = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hadMax);
160 ene.
em = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
em);
162 ene.
emS25 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
emS25);
164 ene.
emMax = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
emMax);
174 MiniFloatConverter::reduceMantissaToNbitsRounding<14>(ene.
ecal_position.Y()),
175 MiniFloatConverter::reduceMantissaToNbitsRounding<14>(ene.
ecal_position.Z()));
177 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hcal_position.Y()),
178 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.
hcal_position.Z()));
179 mu.setCalEnergy(ene);
181 if (slimKinkVars_(
mu) &&
mu.isQualityValid()) {
185 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(qual.
tkKink_position.Y()),
186 MiniFloatConverter::reduceMantissaToNbitsRounding<12>(qual.
tkKink_position.Z()));
187 mu.setCombinedQuality(qual);
192 MiniFloatConverter::reduceMantissaToNbitsRounding<10>(corrs.
corrX()),
193 MiniFloatConverter::reduceMantissaToNbitsRounding<10>(corrs.
corrY()));
194 mu.embedCaloMETMuonCorrs(corrs);
196 if (slimMatches_(
mu) &&
mu.isMatchesValid()) {
198 cmatch.edgeX = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.edgeX);
199 cmatch.edgeY = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.edgeY);
200 cmatch.xErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.xErr);
201 cmatch.yErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.yErr);
202 cmatch.dXdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.dXdZErr);
203 cmatch.dYdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.dYdZErr);
205 smatch.
xErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
xErr);
206 smatch.
yErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
yErr);
207 smatch.
dXdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
dXdZErr);
208 smatch.
dYdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.
dYdZErr);
209 if (saveSegments_ && segmentsMuonSelection_(
mu)) {
221 std::map<DTRecSegment4DRef, size_t> dtMap;
222 std::vector<DTRecSegment4D> outDTSegmentsTmp;
223 std::map<CSCSegmentRef, size_t> cscMap;
224 std::vector<CSCSegment> outCSCSegmentsTmp;
225 for (
auto &seg : dtSegmentsRefs) {
226 dtMap[seg] = outDTSegments->size();
227 outDTSegmentsTmp.push_back(*seg);
229 for (
auto &seg : cscSegmentsRefs) {
230 cscMap[seg] = outCSCSegments->size();
231 outCSCSegmentsTmp.push_back(*seg);
233 outDTSegments->put(
DTChamberId(), outDTSegmentsTmp.begin(), outDTSegmentsTmp.end());
234 outCSCSegments->put(
CSCDetId(), outCSCSegmentsTmp.begin(), outCSCSegmentsTmp.end());
237 for (
auto &
mu : *
out) {
238 if (
mu.isMatchesValid()) {