Skip to content

Commit ce21d39

Browse files
authored
Merge pull request #45363 from stahlleiton/DeDx_MiniAOD_CMSSW_14_1_X
Update dEdx settings for HIN UPC MiniAOD
2 parents 55cba4e + fddb79b commit ce21d39

File tree

4 files changed

+134
-4
lines changed

4 files changed

+134
-4
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include "FWCore/Framework/interface/global/EDProducer.h"
2+
#include "FWCore/Framework/interface/Event.h"
3+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
4+
#include "DataFormats/TrackReco/interface/DeDxData.h"
5+
#include "DataFormats/TrackReco/interface/DeDxHitInfo.h"
6+
#include "DataFormats/TrackReco/interface/TrackFwd.h"
7+
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
8+
9+
//
10+
// class declaration
11+
//
12+
13+
class DeDxEstimatorRekeyer : public edm::global::EDProducer<> {
14+
public:
15+
explicit DeDxEstimatorRekeyer(const edm::ParameterSet&);
16+
~DeDxEstimatorRekeyer() override{};
17+
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
18+
19+
private:
20+
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
21+
22+
template <typename T>
23+
std::map<std::string, edm::EDGetTokenT<T>> getTokens(const std::vector<edm::InputTag>& tags) {
24+
std::map<std::string, edm::EDGetTokenT<T>> tokens;
25+
for (const auto& tag : tags)
26+
tokens.emplace(tag.label(), consumes<T>(tag));
27+
return tokens;
28+
};
29+
30+
// ----------member data ---------------------------
31+
const edm::EDGetTokenT<reco::TrackCollection> tracksToken_;
32+
const edm::EDGetTokenT<reco::DeDxHitInfoAss> dedxHitAssToken_;
33+
const std::map<std::string, edm::EDGetTokenT<edm::ValueMap<reco::DeDxData>>> dedxEstimatorsTokens_;
34+
const std::map<std::string, edm::EDGetTokenT<pat::PackedCandidateCollection>> packedCandidatesTokens_;
35+
const std::map<std::string, edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>>> trk2pcTokens_;
36+
};
37+
38+
void DeDxEstimatorRekeyer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
39+
edm::ParameterSetDescription desc;
40+
desc.add<edm::InputTag>("tracks", {"generalTracks"});
41+
desc.add<edm::InputTag>("dedxHits", {"dedxHitInfo"});
42+
desc.add<std::vector<edm::InputTag>>(
43+
"packedCandidates",
44+
{edm::InputTag("packedPFCandidates"), edm::InputTag("lostTracks"), edm::InputTag("lostTracks:eleTracks")});
45+
desc.add<std::vector<edm::InputTag>>("dedxEstimators",
46+
{edm::InputTag("dedxHarmonic2"), edm::InputTag("dedxPixelHarmonic2")});
47+
descriptions.addWithDefaultLabel(desc);
48+
}
49+
50+
DeDxEstimatorRekeyer::DeDxEstimatorRekeyer(const edm::ParameterSet& iConfig)
51+
: tracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))),
52+
dedxHitAssToken_(consumes<reco::DeDxHitInfoAss>(iConfig.getParameter<edm::InputTag>("dedxHits"))),
53+
dedxEstimatorsTokens_(
54+
getTokens<edm::ValueMap<reco::DeDxData>>(iConfig.getParameter<std::vector<edm::InputTag>>("dedxEstimators"))),
55+
packedCandidatesTokens_(getTokens<pat::PackedCandidateCollection>(
56+
iConfig.getParameter<std::vector<edm::InputTag>>("packedCandidates"))),
57+
trk2pcTokens_(getTokens<edm::Association<pat::PackedCandidateCollection>>(
58+
iConfig.getParameter<std::vector<edm::InputTag>>("packedCandidates"))) {
59+
for (const auto& d : dedxEstimatorsTokens_)
60+
produces<edm::ValueMap<reco::DeDxData>>(d.first);
61+
produces<reco::DeDxHitInfoCollection>();
62+
produces<reco::DeDxHitInfoAss>();
63+
}
64+
65+
void DeDxEstimatorRekeyer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
66+
// Get input collections
67+
const auto& tracks = iEvent.getHandle(tracksToken_);
68+
std::vector<reco::TrackRef> trackRefs;
69+
trackRefs.reserve(tracks->size());
70+
for (auto track = tracks->begin(); track != tracks->end(); track++)
71+
trackRefs.emplace_back(tracks, track - tracks->begin());
72+
73+
typedef std::map<pat::PackedCandidateRef, reco::TrackRef> PCTrkMap;
74+
std::vector<std::pair<edm::Handle<pat::PackedCandidateCollection>, PCTrkMap>> pcTrkMap;
75+
pcTrkMap.reserve(packedCandidatesTokens_.size());
76+
for (const auto& p : packedCandidatesTokens_) {
77+
PCTrkMap map;
78+
const auto& trk2pc = iEvent.get(trk2pcTokens_.at(p.first));
79+
for (const auto& track : trackRefs) {
80+
const auto& pc = trk2pc[track];
81+
if (pc.isNonnull())
82+
map.emplace(pc, track);
83+
}
84+
pcTrkMap.emplace_back(iEvent.getHandle(p.second), map);
85+
}
86+
87+
// Rekey dEdx estimators
88+
for (const auto& d : dedxEstimatorsTokens_) {
89+
const auto& dedxEstimators = iEvent.get(d.second);
90+
auto trackDeDxValueMap = std::make_unique<edm::ValueMap<reco::DeDxData>>();
91+
edm::ValueMap<reco::DeDxData>::Filler filler(*trackDeDxValueMap);
92+
// Loop over packed candidates
93+
for (const auto& h : pcTrkMap) {
94+
std::vector<reco::DeDxData> dedxEstimate(h.first->size());
95+
for (const auto& p : h.second)
96+
dedxEstimate[p.first.key()] = dedxEstimators[p.second];
97+
filler.insert(h.first, dedxEstimate.begin(), dedxEstimate.end());
98+
}
99+
// Fill the value map and put it into the event
100+
filler.fill();
101+
iEvent.put(std::move(trackDeDxValueMap), d.first);
102+
}
103+
104+
// Rekey dEdx hit info
105+
const auto& dedxHitAss = iEvent.get(dedxHitAssToken_);
106+
const auto& dedxHitInfoHandle = iEvent.getRefBeforePut<reco::DeDxHitInfoCollection>();
107+
auto dedxHitInfoAssociation = std::make_unique<reco::DeDxHitInfoAss>(dedxHitInfoHandle);
108+
reco::DeDxHitInfoAss::Filler filler(*dedxHitInfoAssociation);
109+
auto resultdedxHitColl = std::make_unique<reco::DeDxHitInfoCollection>();
110+
resultdedxHitColl->reserve(pcTrkMap.size() > 0 ? pcTrkMap.size() * pcTrkMap[0].second.size() : 0);
111+
// Loop over packed candidates
112+
for (const auto& h : pcTrkMap) {
113+
std::vector<int> indices(h.first->size(), -1);
114+
for (const auto& p : h.second) {
115+
indices[p.first.key()] = resultdedxHitColl->size();
116+
resultdedxHitColl->emplace_back(*dedxHitAss[p.second]);
117+
}
118+
filler.insert(h.first, indices.begin(), indices.end());
119+
}
120+
const auto& dedxHitCollHandle = iEvent.put(std::move(resultdedxHitColl));
121+
// Fill the association map and put it into the event
122+
filler.fill();
123+
iEvent.put(std::move(dedxHitInfoAssociation));
124+
}
125+
126+
//define this as a plug-in
127+
#include "FWCore/Framework/interface/MakerMacros.h"
128+
DEFINE_FWK_MODULE(DeDxEstimatorRekeyer);

PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
'keep recoCentrality_hiCentrality_*_*',
167167
'keep recoClusterCompatibility_hiClusterCompatibility_*_*',
168168
'keep QIE10DataFrameHcalDataFrameContainer_hcalDigis_ZDC_*',
169+
'keep *_dedxEstimator_*_*',
169170
]
170171

171172
from Configuration.Eras.Modifier_run3_upc_cff import run3_upc

PhysicsTools/PatAlgos/python/slimming/isolatedTracks_cfi.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@
7676
from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
7777
pp_on_AA.toModify(isolatedTracks, useHighPurity = True)
7878

79-
from Configuration.Eras.Modifier_run3_upc_cff import run3_upc
80-
run3_upc.toModify(isolatedTracks, pT_cut = 0.0, pT_cut_noIso = 0.0, saveDeDxHitInfoCut = "")
81-
8279
def miniAOD_customizeIsolatedTracksFastSim(process):
8380
"""Switch off dE/dx hit info on fast sim, as it's not available"""
8481
process.isolatedTracks.saveDeDxHitInfo = False

PhysicsTools/PatAlgos/python/slimming/slimming_cff.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@
124124
_photonDRN.toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), patPhotonsDRN))
125125

126126
from Configuration.Eras.Modifier_run3_upc_cff import run3_upc
127-
run3_upc.toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), hiPixelTracks, packedPFCandidateTrackChi2, lostTrackChi2))
127+
from PhysicsTools.PatAlgos.modules import DeDxEstimatorRekeyer
128+
dedxEstimator = DeDxEstimatorRekeyer()
129+
from Configuration.Eras.Modifier_run3_egamma_2023_cff import run3_egamma_2023
130+
(run3_upc & ~run3_egamma_2023).toModify(dedxEstimator, dedxEstimators = ["dedxHarmonic2", "dedxPixelHarmonic2", "dedxPixelLikelihood", "dedxStripLikelihood", "dedxAllLikelihood"])
131+
run3_upc.toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), hiPixelTracks, packedPFCandidateTrackChi2, lostTrackChi2, dedxEstimator))
128132

129133
from Configuration.Eras.Modifier_ppRef_2024_cff import ppRef_2024
130134
ppRef_2024.toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), packedPFCandidateTrackChi2, lostTrackChi2))

0 commit comments

Comments
 (0)