Skip to content

Commit d0d2227

Browse files
authored
Update ParticleFlow.cxx
Added linking between Track and HCal cluster Added and refined arbitration for Track and HCal cluster matching I've implemented these algorithms as part of my bachelor degree project and I have written them very similar to the ones for the track + ecal cluster matching. I tried to stick to the existing variable "convention" but think that they might need some refinement at a later stage as "Calo" and "HadCalo" sound confusingly similar to describe the ECal and HCal respectively.
1 parent 828a75d commit d0d2227

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

Recon/src/Recon/ParticleFlow.cxx

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ void ParticleFlow::configure(framework::config::Parameters& ps) {
1010
inputHcalCollName_ = ps.getParameter<std::string>("inputHcalCollName");
1111
inputTrackCollName_ = ps.getParameter<std::string>("inputTrackCollName");
1212
outputCollName_ = ps.getParameter<std::string>("outputCollName");
13-
14-
input_ecal_passname_ = ps.getParameter<std::string>("input_ecal_passname");
15-
input_hcal_passname_ = ps.getParameter<std::string>("input_hcal_passname");
16-
input_tracks_passname_ =
17-
ps.getParameter<std::string>("input_tracks_passname");
18-
19-
input_track_event_passname_ =
20-
ps.getParameter<std::string>("input_track_event_passname");
21-
input_ecal_event_passname_ =
22-
ps.getParameter<std::string>("input_ecal_event_passname");
23-
input_hcal_event_passname_ =
24-
ps.getParameter<std::string>("input_hcal_event_passname");
25-
2613
// Algorithm configuration
2714
singleParticle_ = ps.getParameter<bool>("singleParticle");
2815
tkHadCaloMatchDist_ = ps.getParameter<double>("tkHadCaloMatchDist");
@@ -70,12 +57,11 @@ void ParticleFlow::fillCandEMCalo(ldmx::PFCandidate& cand,
7057
const ldmx::CaloCluster& em) {
7158
float corr = 1.;
7259
float e = em.getEnergy();
73-
// update energy: use min or max factor if outside calibration range
7460
if (e < eCorr_->GetX()[0]) {
75-
corr = eCorr_->GetY()[0];
61+
corr = eCorr_->GetX()[0];
7662
} else if (e > eCorr_->GetX()[eCorr_->GetN() - 1]) {
77-
corr = eCorr_->GetY()[eCorr_->GetN() - 1];
78-
} else { // else look up calibration factor
63+
corr = eCorr_->GetX()[eCorr_->GetN() - 1];
64+
} else {
7965
corr = eCorr_->Eval(e);
8066
}
8167
cand.setEcalEnergy(e * corr);
@@ -95,9 +81,9 @@ void ParticleFlow::fillCandHadCalo(ldmx::PFCandidate& cand,
9581
float corr = 1.;
9682
float e = had.getEnergy();
9783
if (e < hCorr_->GetX()[0]) {
98-
corr = hCorr_->GetY()[0];
84+
corr = hCorr_->GetX()[0];
9985
} else if (e > hCorr_->GetX()[hCorr_->GetN() - 1]) {
100-
corr = hCorr_->GetY()[hCorr_->GetN() - 1];
86+
corr = hCorr_->GetX()[hCorr_->GetN() - 1];
10187
} else {
10288
corr = hCorr_->Eval(e);
10389
}
@@ -115,16 +101,16 @@ void ParticleFlow::fillCandHadCalo(ldmx::PFCandidate& cand,
115101

116102
// produce track, ecal, and hcal linking
117103
void ParticleFlow::produce(framework::Event& event) {
118-
if (!event.exists(inputTrackCollName_, input_track_event_passname_)) return;
119-
if (!event.exists(inputEcalCollName_, input_ecal_event_passname_)) return;
120-
if (!event.exists(inputHcalCollName_, input_hcal_event_passname_)) return;
104+
if (!event.exists(inputTrackCollName_)) return;
105+
if (!event.exists(inputEcalCollName_)) return;
106+
if (!event.exists(inputHcalCollName_)) return;
121107
// get the track and clustering info
122-
const auto ecalClusters = event.getCollection<ldmx::CaloCluster>(
123-
inputEcalCollName_, input_ecal_passname_);
124-
const auto hcalClusters = event.getCollection<ldmx::CaloCluster>(
125-
inputHcalCollName_, input_hcal_passname_);
126-
const auto tracks = event.getCollection<ldmx::SimTrackerHit>(
127-
inputTrackCollName_, input_tracks_passname_);
108+
const auto ecalClusters =
109+
event.getCollection<ldmx::CaloCluster>(inputEcalCollName_);
110+
const auto hcalClusters =
111+
event.getCollection<ldmx::CaloCluster>(inputHcalCollName_);
112+
const auto tracks =
113+
event.getCollection<ldmx::SimTrackerHit>(inputTrackCollName_);
128114

129115
std::vector<ldmx::PFCandidate> pfCands;
130116
// multi-particle case
@@ -138,7 +124,7 @@ void ParticleFlow::produce(framework::Event& event) {
138124
4c. (Upstream?) Categorize hcal clusters as: EM/Had-like
139125
5. Build candidates by category, moving from Tk-Ecal-Hcal
140126
*/
141-
127+
std::cout << "PF Multiple Particles for Event: "<< event.getEventNumber() << std::endl;
142128
//
143129
// track-calo linking
144130
//
@@ -274,6 +260,8 @@ void ParticleFlow::produce(framework::Event& event) {
274260
std::vector<bool> EMIsHadLinked(ecalClusters.size(), false);
275261
std::vector<bool> HadIsEMLinked(hcalClusters.size(), false);
276262
std::map<int, int> EMHadPairs{};
263+
std::map<int, int> HadEMPairs{};
264+
277265
for (int i = 0; i < ecalClusters.size(); i++) {
278266
if (emHadCaloMap.count(i)) {
279267
// pick first (highest-energy) unused matching cluster
@@ -282,6 +270,7 @@ void ParticleFlow::produce(framework::Event& event) {
282270
HadIsEMLinked[had_idx] = true;
283271
EMIsHadLinked[i] = true;
284272
EMHadPairs[i] = had_idx;
273+
HadEMPairs[had_idx] = i;
285274
break;
286275
}
287276
}
@@ -316,7 +305,7 @@ void ParticleFlow::produce(framework::Event& event) {
316305
// Begin building pf candidates from tracks
317306
//
318307

319-
// starting from tracks
308+
// loop through tracks
320309
for (int i = 0; i < tracks.size(); i++) {
321310
ldmx::PFCandidate cand;
322311
fillCandTrack(cand, tracks[i]); // append track info to candidate
@@ -347,7 +336,6 @@ void ParticleFlow::produce(framework::Event& event) {
347336

348337
// std::vector<ldmx::PFCandidate> emMatch;
349338
// std::vector<ldmx::PFCandidate> emUnmatch;
350-
// ECal clusters
351339
for (int i = 0; i < ecalClusters.size(); i++) {
352340
if (EMIsTkLinked[i]) continue; // already linked with ECal with Track in the previous step
353341
if (EMIsHadLinked[i] && HadIsTkLinked[EMHadPairs[i]]) continue; // already linked with track through Hcal
@@ -364,7 +352,6 @@ void ParticleFlow::produce(framework::Event& event) {
364352
}
365353

366354
// std::vector<ldmx::PFCandidate> hadOnly;
367-
// HCal clusters
368355
for (int i = 0; i < hcalClusters.size(); i++) {
369356
if (HadIsEMLinked[i]) continue; // already linked with ecal
370357
if (HadIsTkLinked[i]) continue; // already linked with track
@@ -373,6 +360,7 @@ void ParticleFlow::produce(framework::Event& event) {
373360
// hadOnly.push_back(cand);
374361
pfCands.push_back(cand);
375362
}
363+
376364

377365
// // track / ecal cluster arbitration
378366
// std::vector<ldmx::PFCandidate> caloMatchedTks;
@@ -445,6 +433,7 @@ void ParticleFlow::produce(framework::Event& event) {
445433
// }
446434

447435
} else {
436+
std::cout << "Matching Single Particle Signals" << std::endl;
448437
// Single-particle builder
449438
ldmx::PFCandidate pf;
450439
int pid = 0; // initialize pid to add
@@ -478,4 +467,4 @@ void ParticleFlow::onProcessEnd() {
478467

479468
} // namespace recon
480469

481-
DECLARE_PRODUCER(recon::ParticleFlow);
470+
DECLARE_PRODUCER_NS(recon, ParticleFlow);

0 commit comments

Comments
 (0)