9 inputEcalCollName_ = ps.
getParameter<std::string>(
"inputEcalCollName");
10 inputHcalCollName_ = ps.
getParameter<std::string>(
"inputHcalCollName");
11 inputTrackCollName_ = ps.
getParameter<std::string>(
"inputTrackCollName");
12 outputCollName_ = ps.
getParameter<std::string>(
"outputCollName");
14 singleParticle_ = ps.
getParameter<
bool>(
"singleParticle");
17 std::vector<float> em1{250.0, 750.0, 1250.0, 1750.0, 2250.0, 2750.0,
18 3250.0, 3750.0, 4250.0, 4750.0, 5250.0, 5750.};
19 std::vector<float> em2{1.175, 1.02, 0.99, 0.985, 0.975, 0.975,
20 0.96, 0.94, 0.87, 0.8, 0.73, 0.665};
21 std::vector<float> h1{25.0, 75.0, 125.0, 175.0, 225.0,
22 275.0, 325.0, 375.0, 425.0};
23 std::vector<float> h2{8.44, 7.38, 7.76, 8.535, 9.47,
24 10.45, 10.47, 9.71, 8.87};
25 eCorr_ =
new TGraph(em1.size(), em1.data(), em2.data());
26 hCorr_ =
new TGraph(h1.size(), h1.data(), h2.data());
101 if (!event.
exists(inputTrackCollName_))
return;
102 if (!event.
exists(inputEcalCollName_))
return;
103 if (!event.
exists(inputHcalCollName_))
return;
105 const auto ecalClusters =
107 const auto hcalClusters =
112 std::vector<ldmx::PFCandidate> pfCands;
114 if (!singleParticle_) {
128 std::map<int, std::vector<int> > tkCaloMap;
129 std::map<int, std::vector<int> > caloTkMap;
130 std::map<std::pair<int, int>,
float> tkEMDist;
132 for (
int i = 0; i < tracks.size(); i++) {
133 const auto& tk = tracks[i];
136 const float p = sqrt(pow(pxyz[0], 2) + pow(pxyz[1], 2) + pow(pxyz[2], 2));
138 for (
int j = 0; j < ecalClusters.size(); j++) {
139 const auto& ecal = ecalClusters[j];
141 const float ecalClusZ = ecal.getCentroidZ();
142 const float tkXAtClus =
143 xyz[0] + pxyz[0] / pxyz[2] * (ecalClusZ - xyz[2]);
144 const float tkYAtClus =
145 xyz[1] + pxyz[1] / pxyz[2] * (ecalClusZ - xyz[2]);
147 (tkXAtClus - ecal.getCentroidX()) / std::max(1.0, ecal.getRMSX()),
148 (tkYAtClus - ecal.getCentroidY()) / std::max(1.0, ecal.getRMSY()));
149 tkEMDist[{i, j}] = dist;
151 (dist < 2) && (ecal.getEnergy() > 0.3 * p &&
152 ecal.getEnergy() < 2 * p);
155 if (tkCaloMap.count(i))
156 tkCaloMap[i].push_back(j);
159 if (caloTkMap.count(j))
160 caloTkMap[j].push_back(i);
168 std::map<int, std::vector<int> > emHadCaloMap;
169 std::map<std::pair<int, int>,
float> EMHadDist;
170 for (
int i = 0; i < ecalClusters.size(); i++) {
171 const auto& ecal = ecalClusters[i];
172 for (
int j = 0; j < hcalClusters.size(); j++) {
173 const auto& hcal = hcalClusters[j];
175 const float xAtHClus =
176 ecal.getCentroidX() +
177 ecal.getDXDZ() * (hcal.getCentroidZ() -
178 ecal.getCentroidZ());
179 const float yAtHClus =
180 ecal.getCentroidY() +
181 ecal.getDYDZ() * (hcal.getCentroidZ() - ecal.getCentroidZ());
183 pow(xAtHClus - hcal.getCentroidX(), 2) /
184 std::max(1.0, pow(hcal.getRMSX(), 2) + pow(ecal.getRMSX(), 2)) +
185 pow(yAtHClus - hcal.getCentroidY(), 2) /
186 std::max(1.0, pow(hcal.getRMSY(), 2) + pow(ecal.getRMSY(), 2)));
187 EMHadDist[{i, j}] = dist;
188 bool isMatch = (dist < 5);
190 if (emHadCaloMap.count(i))
191 emHadCaloMap[i].push_back(j);
193 emHadCaloMap[i] = {j};
200 std::map<int, std::vector<int> > tkHadCaloMap;
217 std::vector<bool> tkIsEMLinked(tracks.size(),
false);
218 std::vector<bool> EMIsTkLinked(ecalClusters.size(),
false);
219 std::map<int, int> tkEMPairs{};
220 for (
int i = 0; i < tracks.size(); i++) {
221 if (tkCaloMap.count(i)) {
223 for (
int em_idx : tkCaloMap[i]) {
224 if (!EMIsTkLinked[em_idx]) {
225 EMIsTkLinked[em_idx] =
true;
226 tkIsEMLinked[i] =
true;
227 tkEMPairs[i] = em_idx;
235 std::vector<bool> EMIsHadLinked(ecalClusters.size(),
false);
236 std::vector<bool> HadIsEMLinked(hcalClusters.size(),
false);
237 std::map<int, int> EMHadPairs{};
238 for (
int i = 0; i < ecalClusters.size(); i++) {
239 if (emHadCaloMap.count(i)) {
241 for (
int had_idx : emHadCaloMap[i]) {
242 if (!HadIsEMLinked[had_idx]) {
243 HadIsEMLinked[had_idx] =
true;
244 EMIsHadLinked[i] =
true;
245 EMHadPairs[i] = had_idx;
262 for (
int i = 0; i < tracks.size(); i++) {
264 fillCandTrack(cand, tracks[i]);
266 if (!tkIsEMLinked[i]) {
269 fillCandEMCalo(cand, ecalClusters[tkEMPairs[i]]);
270 if (EMIsHadLinked[tkEMPairs[i]]) {
272 fillCandHadCalo(cand, hcalClusters[EMHadPairs[tkEMPairs[i]]]);
276 pfCands.push_back(cand);
281 for (
int i = 0; i < ecalClusters.size(); i++) {
283 if (EMIsTkLinked[i])
continue;
286 fillCandEMCalo(cand, ecalClusters[i]);
287 if (EMIsHadLinked[tkEMPairs[i]]) {
288 fillCandHadCalo(cand, hcalClusters[EMHadPairs[i]]);
293 pfCands.push_back(cand);
295 std::vector<ldmx::PFCandidate> hadOnly;
296 for (
int i = 0; i < hcalClusters.size(); i++) {
297 if (HadIsEMLinked[i])
continue;
299 fillCandHadCalo(cand, hcalClusters[i]);
301 pfCands.push_back(cand);
379 fillCandTrack(pf, tracks[0]);
382 if (ecalClusters.size()) {
383 fillCandEMCalo(pf, ecalClusters[0]);
386 if (hcalClusters.size()) {
387 fillCandHadCalo(pf, hcalClusters[0]);
391 pf.setEnergy(pf.getEcalEnergy() + pf.getHcalEnergy());
392 pfCands.push_back(pf);
395 event.add(outputCollName_, pfCands);
virtual void produce(framework::Event &event)
Process the event and put new data products into it.
virtual void onProcessEnd()
Callback for the EventProcessor to take any necessary action when the processing of events finishes,...
virtual void configure(framework::config::Parameters &ps)
Callback for the EventProcessor to configure itself from the given set of parameters.