33 ATH_MSG_ERROR(
"Failed to get TrackPositionProvider for cluster preselection!");
34 return StatusCode::FAILURE;
49 return StatusCode::SUCCESS;
58 data.caloObjects = theEflowCaloObjectContainer;
67 ATH_MSG_DEBUG(
"This event has " <<
data.tracks.size() <<
" tracks " <<
data.clusters.size() <<
" clusters ");
86 unsigned int nMatches(0);
89 const unsigned int nCaloObj =
data.caloObjects->size();
90 const EventContext &ctx = Gaudi::Hive::currentContext();
93 for (
auto *thisEfRecTrack :
data.tracks)
96 if (!thisEfRecTrack->hasBin()) {
97 std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>();
98 thisEflowCaloObject->
addTrack(thisEfRecTrack);
99 data.caloObjects->push_back(std::move(thisEflowCaloObject));
109 std::vector<eflowTrackClusterLink*> bestClusters;
110 std::vector<float> deltaRPrime;
118 for (
auto &matchpair : bestClusters_02)
121 float distancesq = matchpair.second;
123 if (distancesq < 0.15 * 0.15)
127 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,
"cone_015");
129 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,
"cone_02");
134 for (
auto thePair : matchedClusters) {
136 if (
m_addCPData) deltaRPrime.push_back(std::sqrt(thePair.second));
140 const std::vector<eflowTrackClusterLink*>* matchedClusters_02 = thisEfRecTrack->getAlternativeClusterMatches(
"cone_02");
141 if (!matchedClusters_02)
continue;
142 else bestClusters = *matchedClusters_02;
145 if (bestClusters.empty())
continue;
149 for (
auto *thisClusterLink : bestClusters ) {
151 ATH_MSG_DEBUG(
"Matched this track to cluster with e,pt, eta and phi " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
159 for (
auto *trkClusLink : bestClusters){
165 if (
std::find(
data.clusters.begin(),
data.clusters.end(), trkClusLink->getCluster()) ==
data.clusters.end()) {
172 thisEfRecTrack->addClusterMatch(trackClusterLink);
180 std::vector<eflowRecCluster *>
clusters(
data.clusters.begin(),
data.clusters.end());
183 ATH_MSG_DEBUG(
"Created " << nCaloObjects <<
" eflowCaloObjects.");
185 for (
auto thisEFlowCaloObject : *(
data.caloObjects)){
186 ATH_MSG_DEBUG(
"This eflowCaloObject has " << thisEFlowCaloObject->nTracks() <<
" tracks and " << thisEFlowCaloObject->nClusters() <<
" clusters ");
187 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nTracks();
count++){
189 ATH_MSG_DEBUG(
"Have track with e, pt, eta and phi of " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
", " << thisTrack->
eta() <<
" and " << thisTrack->
phi());
191 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nClusters();
count++){
193 ATH_MSG_DEBUG(
"Have cluster with e, pt, eta and phi of " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
198 const double gaussianRadius = 0.032;
199 const double gaussianRadiusError = 1.0e-3;
200 const double maximumRadiusSigma = 3.0;
208 for (
unsigned int iCalo = nCaloObj; iCalo <
data.caloObjects->size(); ++iCalo) {
214 else return nCaloObj;
218 unsigned int nEFCaloObs =
data.caloObjects->size();
219 for (
unsigned int iCalo = startingPoint; iCalo < nEFCaloObs; ++iCalo) {
229 unsigned int nClusters = thisEflowCaloObject.
nClusters();
230 unsigned int nTrackMatches = thisEflowCaloObject.
nTracks();
232 ATH_MSG_DEBUG(
"Have got an eflowCaloObject with " << nClusters <<
" clusters and " << nTrackMatches <<
" track matches");
235 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack){
245 if (nTrackMatches < 1)
return;
253 if (
isEOverPFail(expectedEnergy, expectedSigma, clusterEnergy))
return;
256 const std::vector<std::pair<eflowTrackClusterLink *, std::pair<float, float>>> &matchedTrackList = thisEflowCaloObject.
efRecLink();
258 ATH_MSG_DEBUG(
"Matched Track List has size " << matchedTrackList.size());
262 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack)
265 ATH_MSG_DEBUG(
"eflowCaloObject has track match with E, pt and eta " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
" and " << thisTrack->
eta());
269 ATH_MSG_DEBUG(
"About to perform subtraction for this eflowCaloObject");
271 bool wasAnnihilated =
false;
276 if (
canAnnihilate(expectedEnergy, expectedSigma, clusterEnergy)){
278 wasAnnihilated =
true;
280 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterList;
281 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
282 unsigned nCluster = thisEflowCaloObject.
nClusters();
283 for (
unsigned iCluster = 0; iCluster < nCluster; ++iCluster){
287 ATH_MSG_DEBUG(
"We are going to annihilate. ExpectedEnergy, expectedSigma and clusterEnergy are " << expectedEnergy <<
", " << expectedSigma <<
" and " << clusterEnergy);
289 for (
auto thisPair : clusterList)
290 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
293 Subtractor::annihilateClusters(clusterList);
296 for (
auto thisPair : clusterList)
297 ATH_MSG_DEBUG(
"Have Annihilated cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
300 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
301 eflowRecTrack *thisEfRecTrack = (matchedTrackList[iTrack].first)->getTrack();
309 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
316 if (!thisEfRecTrack->
hasBin())
continue;
322 ATH_MSG_DEBUG(
"Am not in dense environment for this eflowCaloObject");
325 std::vector<eflowRecCluster *> matchedClusters;
327 matchedClusters.reserve(
links.size());
328 for (
auto* thisEFlowTrackClusterLink :
links)
329 matchedClusters.push_back(thisEFlowTrackClusterLink->getCluster());
331 std::sort(matchedClusters.begin(),
332 matchedClusters.end(),
336 for (
auto* thisClus : matchedClusters)
338 "Haved matched cluster "
339 << thisClus->getCluster()->index() <<
" with e,pt, eta and phi of "
340 << thisClus->getCluster()->e() <<
", "
341 << thisClus->getCluster()->pt() <<
", "
342 << thisClus->getCluster()->eta() <<
" and "
343 << thisClus->getCluster()->phi() <<
" will be subtracted");
347 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterSubtractionList;
348 clusterSubtractionList.reserve(matchedClusters.size());
349 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
350 for (
auto *thisEFlowRecCluster : matchedClusters){
352 clusterSubtractionList.emplace_back(thisCluster,
false);
353 clusterEnergyMap[thisCluster] = thisCluster->
e();
356 ATH_MSG_DEBUG(
"Have filled clusterSubtractionList for this eflowCaloObject");
358 unsigned int trackIndex = thisEfRecTrack->
getTrack()->
index();
361 auto sumClusEnergy = [](
double accumulator, std::pair<xAOD::CaloCluster *, bool> thisPair){
return accumulator += thisPair.first->e();};
362 double totalClusterEnergy =
std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
368 for (
auto thisPair : clusterSubtractionList)
369 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
371 Subtractor::annihilateClusters(clusterSubtractionList);
374 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
385 totalClusterEnergy =
std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
391 for (
auto thisPair : clusterSubtractionList){
392 ATH_MSG_DEBUG(
"Annihilating remnant cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
396 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
402 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
409 ATH_MSG_DEBUG(
"Have subtracted charged shower for this eflowRecTrack");
421 if ((expectedEnergy == 0) && (clusterEnergy > 0))
return false;
432 result <<
" track with E, eta and phi "<<
track->e() <<
", " <<
track->eta() <<
" and " <<
track->phi();
438 result <<
" cluster with E, eta and phi of " << cluster->
e() <<
", " << cluster->
eta() <<
" and " << cluster->
phi();
444 for (
const auto *thisEFRecCluster : recClusterContainer){
445 if (thisEFRecCluster->getTrackMatches().empty()) {
449 std::vector<eflowTrackClusterLink*> theTrackLinks = thisEFRecCluster->getTrackMatches();
450 for (
auto *thisTrack : theTrackLinks){