Skip to content

Commit 751fa4f

Browse files
authored
Merge pull request #45446 from stahlleiton/DeDxMomentum_CMSSW_14_1_X
Store track momentum at hit for PbPb UPC dEdX calibration
2 parents 59bdefa + 5f1453a commit 751fa4f

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

PhysicsTools/PatAlgos/plugins/DeDxEstimatorRekeyer.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DeDxEstimatorRekeyer : public edm::global::EDProducer<> {
3030
// ----------member data ---------------------------
3131
const edm::EDGetTokenT<reco::TrackCollection> tracksToken_;
3232
const edm::EDGetTokenT<reco::DeDxHitInfoAss> dedxHitAssToken_;
33+
const edm::EDGetTokenT<edm::ValueMap<std::vector<float>>> dedxHitMomToken_;
3334
const std::map<std::string, edm::EDGetTokenT<edm::ValueMap<reco::DeDxData>>> dedxEstimatorsTokens_;
3435
const std::map<std::string, edm::EDGetTokenT<pat::PackedCandidateCollection>> packedCandidatesTokens_;
3536
const std::map<std::string, edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>>> trk2pcTokens_;
@@ -39,6 +40,7 @@ void DeDxEstimatorRekeyer::fillDescriptions(edm::ConfigurationDescriptions& desc
3940
edm::ParameterSetDescription desc;
4041
desc.add<edm::InputTag>("tracks", {"generalTracks"});
4142
desc.add<edm::InputTag>("dedxHits", {"dedxHitInfo"});
43+
desc.add<edm::InputTag>("dedxMomentum", {"dedxHitInfo:momentumAtHit"});
4244
desc.add<std::vector<edm::InputTag>>(
4345
"packedCandidates",
4446
{edm::InputTag("packedPFCandidates"), edm::InputTag("lostTracks"), edm::InputTag("lostTracks:eleTracks")});
@@ -50,6 +52,8 @@ void DeDxEstimatorRekeyer::fillDescriptions(edm::ConfigurationDescriptions& desc
5052
DeDxEstimatorRekeyer::DeDxEstimatorRekeyer(const edm::ParameterSet& iConfig)
5153
: tracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracks"))),
5254
dedxHitAssToken_(consumes<reco::DeDxHitInfoAss>(iConfig.getParameter<edm::InputTag>("dedxHits"))),
55+
dedxHitMomToken_(
56+
consumes<edm::ValueMap<std::vector<float>>>(iConfig.getParameter<edm::InputTag>("dedxMomentum"))),
5357
dedxEstimatorsTokens_(
5458
getTokens<edm::ValueMap<reco::DeDxData>>(iConfig.getParameter<std::vector<edm::InputTag>>("dedxEstimators"))),
5559
packedCandidatesTokens_(getTokens<pat::PackedCandidateCollection>(
@@ -60,6 +64,7 @@ DeDxEstimatorRekeyer::DeDxEstimatorRekeyer(const edm::ParameterSet& iConfig)
6064
produces<edm::ValueMap<reco::DeDxData>>(d.first);
6165
produces<reco::DeDxHitInfoCollection>();
6266
produces<reco::DeDxHitInfoAss>();
67+
produces<edm::ValueMap<std::vector<float>>>("momentumAtHit");
6368
}
6469

6570
void DeDxEstimatorRekeyer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
@@ -102,25 +107,36 @@ void DeDxEstimatorRekeyer::produce(edm::StreamID, edm::Event& iEvent, const edm:
102107
}
103108

104109
// Rekey dEdx hit info
110+
const auto& dedxHitMom = iEvent.get(dedxHitMomToken_);
105111
const auto& dedxHitAss = iEvent.get(dedxHitAssToken_);
106112
const auto& dedxHitInfoHandle = iEvent.getRefBeforePut<reco::DeDxHitInfoCollection>();
107113
auto dedxHitInfoAssociation = std::make_unique<reco::DeDxHitInfoAss>(dedxHitInfoHandle);
108114
reco::DeDxHitInfoAss::Filler filler(*dedxHitInfoAssociation);
109115
auto resultdedxHitColl = std::make_unique<reco::DeDxHitInfoCollection>();
110116
resultdedxHitColl->reserve(pcTrkMap.size() > 0 ? pcTrkMap.size() * pcTrkMap[0].second.size() : 0);
117+
std::vector<std::vector<float>> momenta;
118+
momenta.reserve(resultdedxHitColl->capacity());
111119
// Loop over packed candidates
112120
for (const auto& h : pcTrkMap) {
113121
std::vector<int> indices(h.first->size(), -1);
114122
for (const auto& p : h.second) {
115123
indices[p.first.key()] = resultdedxHitColl->size();
116-
resultdedxHitColl->emplace_back(*dedxHitAss[p.second]);
124+
const auto& dedxHit = dedxHitAss[p.second];
125+
resultdedxHitColl->emplace_back(*dedxHit);
126+
momenta.emplace_back(dedxHitMom[dedxHit]);
117127
}
118128
filler.insert(h.first, indices.begin(), indices.end());
119129
}
120130
const auto& dedxHitCollHandle = iEvent.put(std::move(resultdedxHitColl));
121131
// Fill the association map and put it into the event
122132
filler.fill();
123133
iEvent.put(std::move(dedxHitInfoAssociation));
134+
// Fill the value map and put it into the event
135+
auto dedxMomenta = std::make_unique<edm::ValueMap<std::vector<float>>>();
136+
edm::ValueMap<std::vector<float>>::Filler mfiller(*dedxMomenta);
137+
mfiller.insert(dedxHitCollHandle, momenta.begin(), momenta.end());
138+
mfiller.fill();
139+
iEvent.put(std::move(dedxMomenta), "momentumAtHit");
124140
}
125141

126142
//define this as a plug-in

RecoTracker/DeDx/plugins/DeDxEstimatorProducer.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ void DeDxEstimatorProducer::produce(edm::Event& iEvent, const edm::EventSetup& i
130130
int NClusterSaturating = 0;
131131
DeDxHitCollection dedxHits;
132132

133-
dedxHits.reserve(track->recHitsSize() / 2);
134133
if (useDeDxHits) {
135134
if (usePixel)
136135
dedxHits = (*pixelDeDxHits)[track];

RecoTracker/DeDx/plugins/DeDxHitInfoProducer.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class DeDxHitInfoProducer : public edm::stream::EDProducer<> {
5959
const float trackMomentum,
6060
const LocalVector& trackDirection,
6161
reco::DeDxHitInfo& hitDeDxInfo,
62+
std::vector<float>& hitMomentum,
6263
const LocalPoint& hitLocalPos);
6364

6465
// ----------member data ---------------------------
@@ -76,6 +77,7 @@ class DeDxHitInfoProducer : public edm::stream::EDProducer<> {
7677
const bool useCalibration_;
7778
const bool doShapeTest_;
7879
const bool usePixelShape_;
80+
const bool storeMomentumAtHit_;
7981

8082
const unsigned int lowPtTracksPrescalePass_, lowPtTracksPrescaleFail_;
8183
GenericTruncatedAverageDeDxEstimator lowPtTracksEstimator_;
@@ -116,6 +118,7 @@ DeDxHitInfoProducer::DeDxHitInfoProducer(const edm::ParameterSet& iConfig)
116118
useCalibration_(iConfig.getParameter<bool>("useCalibration")),
117119
doShapeTest_(iConfig.getParameter<bool>("shapeTest")),
118120
usePixelShape_(not iConfig.getParameter<edm::InputTag>("clusterShapeCache").label().empty()),
121+
storeMomentumAtHit_(iConfig.getParameter<bool>("storeMomentumAtHit")),
119122
lowPtTracksPrescalePass_(iConfig.getParameter<uint32_t>("lowPtTracksPrescalePass")),
120123
lowPtTracksPrescaleFail_(iConfig.getParameter<uint32_t>("lowPtTracksPrescaleFail")),
121124
lowPtTracksEstimator_(iConfig.getParameter<edm::ParameterSet>("lowPtTracksEstimatorParameters")),
@@ -129,6 +132,8 @@ DeDxHitInfoProducer::DeDxHitInfoProducer(const edm::ParameterSet& iConfig)
129132
produces<reco::DeDxHitInfoCollection>();
130133
produces<reco::DeDxHitInfoAss>();
131134
produces<edm::ValueMap<int>>("prescale");
135+
if (storeMomentumAtHit_)
136+
produces<edm::ValueMap<std::vector<float>>>("momentumAtHit");
132137

133138
if (!usePixel_ && !useStrip_)
134139
edm::LogError("DeDxHitsProducer") << "No Pixel Hits NOR Strip Hits will be saved. Running this module is useless";
@@ -160,6 +165,7 @@ void DeDxHitInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
160165

161166
std::vector<int> indices;
162167
std::vector<int> prescales;
168+
std::vector<std::vector<float>> hitMomenta;
163169
uint64_t state[2] = {iEvent.id().event(), iEvent.id().luminosityBlock()};
164170
for (unsigned int j = 0; j < trackCollection.size(); j++) {
165171
const reco::Track& track = trackCollection[j];
@@ -181,15 +187,18 @@ void DeDxHitInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
181187
}
182188

183189
reco::DeDxHitInfo hitDeDxInfo;
190+
std::vector<float> hitMomentum;
184191
auto const& trajParams = track.extra()->trajParams();
185192
auto hb = track.recHitsBegin();
186193
for (unsigned int h = 0; h < track.recHitsSize(); h++) {
187194
auto recHit = *(hb + h);
188195
if (!trackerHitRTTI::isFromDet(*recHit))
189196
continue;
190197

191-
processHit(recHit, track.p(), trajParams[h].direction(), hitDeDxInfo, trajParams[h].position());
198+
const auto& traj = trajParams[h];
199+
processHit(recHit, traj.momentum().mag(), traj.direction(), hitDeDxInfo, hitMomentum, traj.position());
192200
}
201+
assert(!storeMomentumAtHit_ || hitMomentum.size() == hitDeDxInfo.size());
193202

194203
if (!passPt) {
195204
std::vector<DeDxHit> hits;
@@ -230,6 +239,8 @@ void DeDxHitInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
230239
}
231240
indices.push_back(resultdedxHitColl->size());
232241
resultdedxHitColl->push_back(hitDeDxInfo);
242+
if (storeMomentumAtHit_)
243+
hitMomenta.push_back(hitMomentum);
233244
}
234245
///////////////////////////////////////
235246

@@ -247,6 +258,14 @@ void DeDxHitInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
247258
pfiller.insert(dedxHitCollHandle, prescales.begin(), prescales.end());
248259
pfiller.fill();
249260
iEvent.put(std::move(dedxPrescale), "prescale");
261+
262+
if (storeMomentumAtHit_) {
263+
auto dedxMomenta = std::make_unique<edm::ValueMap<std::vector<float>>>();
264+
edm::ValueMap<std::vector<float>>::Filler mfiller(*dedxMomenta);
265+
mfiller.insert(dedxHitCollHandle, hitMomenta.begin(), hitMomenta.end());
266+
mfiller.fill();
267+
iEvent.put(std::move(dedxMomenta), "momentumAtHit");
268+
}
250269
}
251270

252271
void DeDxHitInfoProducer::processRec(reco::DeDxHitInfo& hitDeDxInfo,
@@ -279,6 +298,7 @@ void DeDxHitInfoProducer::processHit(const TrackingRecHit* recHit,
279298
const float trackMomentum,
280299
const LocalVector& trackDirection,
281300
reco::DeDxHitInfo& hitDeDxInfo,
301+
std::vector<float>& hitMomentum,
282302
const LocalPoint& hitLocalPos) {
283303
auto const& thit = static_cast<BaseTrackerRecHit const&>(*recHit);
284304
if (!thit.isValid())
@@ -327,10 +347,14 @@ void DeDxHitInfoProducer::processHit(const TrackingRecHit* recHit,
327347
const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
328348
if (!matchedHit)
329349
return;
350+
if (storeMomentumAtHit_)
351+
hitMomentum.push_back(trackMomentum);
330352

331353
processRec(hitDeDxInfo, matchedHit->monoHit(), hitLocalPos, trackDirection, cosineAbs);
332354
processRec(hitDeDxInfo, matchedHit->stereoHit(), hitLocalPos, trackDirection, cosineAbs);
333355
}
356+
if (storeMomentumAtHit_ && (clus.isPixel() || clus.isStrip()))
357+
hitMomentum.push_back(trackMomentum);
334358
}
335359

336360
//define this as a plug-in

RecoTracker/DeDx/python/dedxEstimators_cff.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
calibrationPath = cms.string("file:Gains.root"),
1818
shapeTest = cms.bool(True),
1919
clusterShapeCache = cms.InputTag("siPixelClusterShapeCache"),
20+
storeMomentumAtHit = cms.bool(False),
2021

2122
lowPtTracksPrescalePass = cms.uint32(100), # prescale factor for low pt tracks above the dEdx cut
2223
lowPtTracksPrescaleFail = cms.uint32(2000), # prescale factor for low pt tracks below the dEdx cut
@@ -91,7 +92,7 @@
9192

9293
# dEdx for Run-3 UPC
9394
from Configuration.Eras.Modifier_run3_upc_cff import run3_upc
94-
run3_upc.toModify(dedxHitInfo, minTrackPt = 0)
95+
run3_upc.toModify(dedxHitInfo, minTrackPt = 0, storeMomentumAtHit = True)
9596

9697
from RecoTracker.DeDx.dedxHitCalibrator_cfi import dedxHitCalibrator as _dedxHitCalibrator
9798
from SimGeneral.MixingModule.SiStripSimParameters_cfi import SiStripSimBlock as _SiStripSimBlock

0 commit comments

Comments
 (0)