41 ATH_MSG_ERROR(
"Failed to get TrackPositionProvider for cluster preselection!");
42 return StatusCode::FAILURE;
63 return StatusCode::SUCCESS;
72 data.caloObjects = theEflowCaloObjectContainer;
81 ATH_MSG_DEBUG(
"This event has " <<
data.tracks.size() <<
" tracks " <<
data.clusters.size() <<
" clusters ");
101 unsigned int nMatches(0);
104 const unsigned int nCaloObj =
data.caloObjects->size();
105 const EventContext &ctx = Gaudi::Hive::currentContext();
108 for (
auto *thisEfRecTrack :
data.tracks)
111 if (!thisEfRecTrack->hasBin()) {
112 std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>();
113 thisEflowCaloObject->
addTrack(thisEfRecTrack);
114 data.caloObjects->push_back(std::move(thisEflowCaloObject));
124 std::vector<eflowTrackClusterLink*> bestClusters;
125 std::vector<float> deltaRPrime;
134 TruthLink truthLink = truthLinkAccessor(*(thisEfRecTrack->getTrack()));
137 if (truthLink.
isValid()) trackMatchedTruthParticle = *truthLink;
139 if (trackMatchedTruthParticle){
143 if (!caloClusterReadDecorHandleNLeadingTruthParticles.isValid()){
144 ATH_MSG_WARNING(
"Failed to retrieve CaloCluster decoration with key " << caloClusterReadDecorHandleNLeadingTruthParticles.key());
147 for (
auto * thisCluster :
data.clusters){
152 std::string::size_type
pos = decorHandleName.find(
".");
153 std::string decorName = decorHandleName.substr(
pos+1);
157 std::vector<std::pair<unsigned int, double > > uniqueIDTruthPairs =
accessor(*(thisCluster->getCluster()));
159 for (
auto &uniqueIDTruthPair : uniqueIDTruthPairs){
160 if (uniqueIDTruthPair.first ==
uniqueID){
162 bestClusters.push_back(thisLink);
169 else ATH_MSG_VERBOSE(
"Track with pt, eta and phi " << thisEfRecTrack->getTrack()->pt() <<
", " << thisEfRecTrack->getTrack()->eta() <<
" and " << thisEfRecTrack->getTrack()->phi() <<
" does not have a valid truth pointer");
177 for (
auto &matchpair : bestClusters_02)
180 float distancesq = matchpair.second;
182 if (distancesq < 0.15 * 0.15)
186 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,
"cone_015");
188 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,
"cone_02");
193 for (
auto thePair : matchedClusters) {
195 if (
m_addCPData) deltaRPrime.push_back(std::sqrt(thePair.second));
199 const std::vector<eflowTrackClusterLink*>* matchedClusters_02 = thisEfRecTrack->getAlternativeClusterMatches(
"cone_02");
200 if (!matchedClusters_02)
continue;
201 else bestClusters = *matchedClusters_02;
204 if (bestClusters.empty())
continue;
208 for (
auto *thisClusterLink : bestClusters ) {
210 ATH_MSG_DEBUG(
"Matched this track to cluster with e,pt, eta and phi " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
218 for (
auto *trkClusLink : bestClusters){
224 if (
std::find(
data.clusters.begin(),
data.clusters.end(), trkClusLink->getCluster()) ==
data.clusters.end()) {
231 thisEfRecTrack->addClusterMatch(trackClusterLink);
233 thisEfRecTrack->addDeltaRPrime(deltaRPrime[
linkIndex]);
241 std::vector<eflowRecCluster *>
clusters(
data.clusters.begin(),
data.clusters.end());
244 ATH_MSG_DEBUG(
"Created " << nCaloObjects <<
" eflowCaloObjects.");
246 for (
auto thisEFlowCaloObject : *(
data.caloObjects)){
247 ATH_MSG_DEBUG(
"This eflowCaloObject has " << thisEFlowCaloObject->nTracks() <<
" tracks and " << thisEFlowCaloObject->nClusters() <<
" clusters ");
248 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nTracks();
count++){
250 ATH_MSG_DEBUG(
"Have track with e, pt, eta and phi of " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
", " << thisTrack->
eta() <<
" and " << thisTrack->
phi());
252 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nClusters();
count++){
254 ATH_MSG_DEBUG(
"Have cluster with e, pt, eta and phi of " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
259 const double gaussianRadius = 0.032;
260 const double gaussianRadiusError = 1.0e-3;
261 const double maximumRadiusSigma = 3.0;
269 for (
unsigned int iCalo = nCaloObj; iCalo <
data.caloObjects->size(); ++iCalo) {
277 else return nCaloObj;
281 unsigned int nEFCaloObs =
data.caloObjects->size();
282 for (
unsigned int iCalo = startingPoint; iCalo < nEFCaloObs; ++iCalo) {
292 unsigned int nClusters = thisEflowCaloObject.
nClusters();
293 unsigned int nTrackMatches = thisEflowCaloObject.
nTracks();
295 ATH_MSG_DEBUG(
"Have got an eflowCaloObject with " << nClusters <<
" clusters and " << nTrackMatches <<
" track matches");
298 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack){
308 if (nTrackMatches < 1)
return;
316 if (
isEOverPFail(expectedEnergy, expectedSigma, clusterEnergy))
return;
319 const std::vector<std::pair<eflowTrackClusterLink *, std::pair<float, float>>> &matchedTrackList = thisEflowCaloObject.
efRecLink();
321 ATH_MSG_DEBUG(
"Matched Track List has size " << matchedTrackList.size());
325 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack)
328 ATH_MSG_DEBUG(
"eflowCaloObject has track match with E, pt and eta " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
" and " << thisTrack->
eta());
332 ATH_MSG_DEBUG(
"About to perform subtraction for this eflowCaloObject");
334 bool wasAnnihilated =
false;
339 if (
canAnnihilate(expectedEnergy, expectedSigma, clusterEnergy)){
341 wasAnnihilated =
true;
343 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterList;
344 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
345 unsigned nCluster = thisEflowCaloObject.
nClusters();
346 for (
unsigned iCluster = 0; iCluster < nCluster; ++iCluster){
350 ATH_MSG_DEBUG(
"We are going to annihilate. ExpectedEnergy, expectedSigma and clusterEnergy are " << expectedEnergy <<
", " << expectedSigma <<
" and " << clusterEnergy);
352 for (
auto thisPair : clusterList)
353 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
360 Subtractor::annihilateClusters(clusterList);
363 for (
auto thisPair : clusterList)
364 ATH_MSG_DEBUG(
"Have Annihilated cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
367 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
368 eflowRecTrack *thisEfRecTrack = (matchedTrackList[iTrack].first)->getTrack();
376 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
383 if (!thisEfRecTrack->
hasBin())
continue;
389 ATH_MSG_DEBUG(
"Am not in dense environment for this eflowCaloObject");
392 std::vector<eflowRecCluster *> matchedClusters;
394 matchedClusters.reserve(
links.size());
395 for (
auto* thisEFlowTrackClusterLink :
links)
396 matchedClusters.push_back(thisEFlowTrackClusterLink->getCluster());
398 std::sort(matchedClusters.begin(),
399 matchedClusters.end(),
403 for (
auto* thisClus : matchedClusters)
405 "Haved matched cluster "
406 << thisClus->getCluster()->index() <<
" with e,pt, eta and phi of "
407 << thisClus->getCluster()->e() <<
", "
408 << thisClus->getCluster()->pt() <<
", "
409 << thisClus->getCluster()->eta() <<
" and "
410 << thisClus->getCluster()->phi() <<
" will be subtracted");
414 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterSubtractionList;
415 clusterSubtractionList.reserve(matchedClusters.size());
416 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
417 for (
auto *thisEFlowRecCluster : matchedClusters){
419 clusterSubtractionList.emplace_back(thisCluster,
false);
420 clusterEnergyMap[thisCluster] = thisCluster->
e();
423 ATH_MSG_DEBUG(
"Have filled clusterSubtractionList for this eflowCaloObject");
425 unsigned int trackIndex = thisEfRecTrack->
getTrack()->
index();
428 auto sumClusEnergy = [](
double accumulator, std::pair<xAOD::CaloCluster *, bool> thisPair){
return accumulator += thisPair.first->e();};
429 double totalClusterEnergy =
std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
435 for (
auto thisPair : clusterSubtractionList)
436 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
441 Subtractor::annihilateClusters(clusterSubtractionList);
444 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
455 totalClusterEnergy =
std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
461 for (
auto thisPair : clusterSubtractionList){
462 ATH_MSG_DEBUG(
"Annihilating remnant cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
466 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
472 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
479 ATH_MSG_DEBUG(
"Have subtracted charged shower for this eflowRecTrack");
493 unsigned int nEFCaloObs =
data.caloObjects->size();
495 for (
unsigned int iCalo = 0; iCalo < nEFCaloObs; ++iCalo) {
504 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
509 if (!thisEfRecTrack->
hasBin())
continue;
519 for (
auto thisLink :
links){
533 for (; theCell != lastCell;){
537 double oldCellEnergy = theCell->
energy()*(theCell.
weight());
538 double subtractedCellWeight = (oldCellEnergy - truthEnergy)/oldCellEnergy;
542 lastCell = theCellLinks->
end();
545 theCell.
reweight(subtractedCellWeight);
552 float oldEnergy = thisCluster->
e();
554 if (0.0 != oldEnergy) {
555 float energyAdjustment = thisCluster->
e() / oldEnergy;
556 thisCluster->
setRawE(thisCluster->
rawE() * energyAdjustment);
568 if ((expectedEnergy == 0) && (clusterEnergy > 0))
return false;
579 result <<
" track with E, eta and phi "<<
track->e() <<
", " <<
track->eta() <<
" and " <<
track->phi();
585 result <<
" cluster with E, eta and phi of " << cluster->
e() <<
", " << cluster->
eta() <<
" and " << cluster->
phi();
591 for (
const auto *thisEFRecCluster : recClusterContainer){
592 if (thisEFRecCluster->getTrackMatches().empty()) {
596 std::vector<eflowTrackClusterLink*> theTrackLinks = thisEFRecCluster->getTrackMatches();
597 for (
auto *thisTrack : theTrackLinks){
606 unsigned int numTracks = thisEflowCaloObject.
nTracks();
608 for (
unsigned int iTrack = 0; iTrack < numTracks; ++iTrack){
610 for (
auto thisPair : clusterList){