37 ATH_MSG_ERROR(
"Failed to get TrackPositionProvider for cluster preselection!");
38 return StatusCode::FAILURE;
60 return StatusCode::SUCCESS;
69 data.caloObjects = theEflowCaloObjectContainer;
78 ATH_MSG_DEBUG(
"This event has " <<
data.tracks.size() <<
" tracks " <<
data.clusters.size() <<
" clusters ");
100 unsigned int nMatches(0);
103 const unsigned int nCaloObj =
data.caloObjects->size();
104 const EventContext &ctx = Gaudi::Hive::currentContext();
107 for (
auto *thisEfRecTrack :
data.tracks)
110 if (!thisEfRecTrack->hasBin()) {
111 std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>();
112 thisEflowCaloObject->
addTrack(thisEfRecTrack);
113 data.caloObjects->push_back(std::move(thisEflowCaloObject));
123 std::vector<eflowTrackClusterLink*> bestClusters;
124 std::vector<float> deltaRPrime;
133 TruthLink truthLink = truthLinkAccessor(*(thisEfRecTrack->getTrack()));
136 if (truthLink.
isValid()) trackMatchedTruthParticle = *truthLink;
138 if (trackMatchedTruthParticle){
142 if (!caloClusterReadDecorHandleNLeadingTruthParticles.isValid()){
143 ATH_MSG_WARNING(
"Failed to retrieve CaloCluster decoration with key " << caloClusterReadDecorHandleNLeadingTruthParticles.key());
146 for (
auto * thisCluster :
data.clusters){
151 std::string::size_type
pos = decorHandleName.find(
".");
152 std::string decorName = decorHandleName.substr(
pos+1);
156 std::vector<std::pair<unsigned int, double > > barCodeTruthPairs =
accessor(*(thisCluster->getCluster()));
158 for (
auto &barCodeTruthPair : barCodeTruthPairs){
159 if (barCodeTruthPair.first ==
barcode){
161 bestClusters.push_back(thisLink);
168 else ATH_MSG_WARNING(
"Track with pt, eta and phi " << thisEfRecTrack->getTrack()->pt() <<
", " << thisEfRecTrack->getTrack()->eta() <<
" and " << thisEfRecTrack->getTrack()->phi() <<
" does not have a valid truth pointer");
176 for (
auto &matchpair : bestClusters_02)
179 float distancesq = matchpair.second;
181 if (distancesq < 0.15 * 0.15)
185 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,
"cone_015");
187 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,
"cone_02");
192 for (
auto thePair : matchedClusters) {
194 if (
m_addCPData) deltaRPrime.push_back(std::sqrt(thePair.second));
198 const std::vector<eflowTrackClusterLink*>* matchedClusters_02 = thisEfRecTrack->getAlternativeClusterMatches(
"cone_02");
199 if (!matchedClusters_02)
continue;
200 else bestClusters = *matchedClusters_02;
203 if (bestClusters.empty())
continue;
207 for (
auto *thisClusterLink : bestClusters ) {
209 ATH_MSG_DEBUG(
"Matched this track to cluster with e,pt, eta and phi " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
217 for (
auto *trkClusLink : bestClusters){
223 if (
std::find(
data.clusters.begin(),
data.clusters.end(), trkClusLink->getCluster()) ==
data.clusters.end()) {
230 thisEfRecTrack->addClusterMatch(trackClusterLink);
232 thisEfRecTrack->addDeltaRPrime(deltaRPrime[
linkIndex]);
240 std::vector<eflowRecCluster *>
clusters(
data.clusters.begin(),
data.clusters.end());
243 ATH_MSG_DEBUG(
"Created " << nCaloObjects <<
" eflowCaloObjects.");
245 for (
auto thisEFlowCaloObject : *(
data.caloObjects)){
246 ATH_MSG_DEBUG(
"This eflowCaloObject has " << thisEFlowCaloObject->nTracks() <<
" tracks and " << thisEFlowCaloObject->nClusters() <<
" clusters ");
247 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nTracks();
count++){
249 ATH_MSG_DEBUG(
"Have track with e, pt, eta and phi of " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
", " << thisTrack->
eta() <<
" and " << thisTrack->
phi());
251 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nClusters();
count++){
253 ATH_MSG_DEBUG(
"Have cluster with e, pt, eta and phi of " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
258 const double gaussianRadius = 0.032;
259 const double gaussianRadiusError = 1.0e-3;
260 const double maximumRadiusSigma = 3.0;
268 for (
unsigned int iCalo = nCaloObj; iCalo <
data.caloObjects->size(); ++iCalo) {
276 else return nCaloObj;
280 unsigned int nEFCaloObs =
data.caloObjects->size();
281 for (
unsigned int iCalo = startingPoint; iCalo < nEFCaloObs; ++iCalo) {
291 unsigned int nClusters = thisEflowCaloObject.
nClusters();
292 unsigned int nTrackMatches = thisEflowCaloObject.
nTracks();
294 ATH_MSG_DEBUG(
"Have got an eflowCaloObject with " << nClusters <<
" clusters and " << nTrackMatches <<
" track matches");
297 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack){
307 if (nTrackMatches < 1)
return;
315 if (
isEOverPFail(expectedEnergy, expectedSigma, clusterEnergy))
return;
318 const std::vector<std::pair<eflowTrackClusterLink *, std::pair<float, float>>> &matchedTrackList = thisEflowCaloObject.
efRecLink();
320 ATH_MSG_DEBUG(
"Matched Track List has size " << matchedTrackList.size());
324 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack)
327 ATH_MSG_DEBUG(
"eflowCaloObject has track match with E, pt and eta " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
" and " << thisTrack->
eta());
331 ATH_MSG_DEBUG(
"About to perform subtraction for this eflowCaloObject");
333 bool wasAnnihilated =
false;
338 if (
canAnnihilate(expectedEnergy, expectedSigma, clusterEnergy)){
340 wasAnnihilated =
true;
342 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterList;
343 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
344 unsigned nCluster = thisEflowCaloObject.
nClusters();
345 for (
unsigned iCluster = 0; iCluster < nCluster; ++iCluster){
349 ATH_MSG_DEBUG(
"We are going to annihilate. ExpectedEnergy, expectedSigma and clusterEnergy are " << expectedEnergy <<
", " << expectedSigma <<
" and " << clusterEnergy);
351 for (
auto thisPair : clusterList)
352 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
359 Subtractor::annihilateClusters(clusterList);
362 for (
auto thisPair : clusterList)
363 ATH_MSG_DEBUG(
"Have Annihilated cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
366 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
367 eflowRecTrack *thisEfRecTrack = (matchedTrackList[iTrack].first)->getTrack();
375 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
382 if (!thisEfRecTrack->
hasBin())
continue;
388 ATH_MSG_DEBUG(
"Am not in dense environment for this eflowCaloObject");
391 std::vector<eflowRecCluster *> matchedClusters;
393 matchedClusters.reserve(
links.size());
394 for (
auto* thisEFlowTrackClusterLink :
links)
395 matchedClusters.push_back(thisEFlowTrackClusterLink->getCluster());
397 std::sort(matchedClusters.begin(),
398 matchedClusters.end(),
402 for (
auto* thisClus : matchedClusters)
404 "Haved matched cluster "
405 << thisClus->getCluster()->index() <<
" with e,pt, eta and phi of "
406 << thisClus->getCluster()->e() <<
", "
407 << thisClus->getCluster()->pt() <<
", "
408 << thisClus->getCluster()->eta() <<
" and "
409 << thisClus->getCluster()->phi() <<
" will be subtracted");
413 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterSubtractionList;
414 clusterSubtractionList.reserve(matchedClusters.size());
415 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
416 for (
auto *thisEFlowRecCluster : matchedClusters){
418 clusterSubtractionList.emplace_back(thisCluster,
false);
419 clusterEnergyMap[thisCluster] = thisCluster->
e();
422 ATH_MSG_DEBUG(
"Have filled clusterSubtractionList for this eflowCaloObject");
424 unsigned int trackIndex = thisEfRecTrack->
getTrack()->
index();
427 auto sumClusEnergy = [](
double accumulator, std::pair<xAOD::CaloCluster *, bool> thisPair){
return accumulator += thisPair.first->e();};
428 double totalClusterEnergy =
std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
434 for (
auto thisPair : clusterSubtractionList)
435 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
440 Subtractor::annihilateClusters(clusterSubtractionList);
443 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
454 totalClusterEnergy =
std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
460 for (
auto thisPair : clusterSubtractionList){
461 ATH_MSG_DEBUG(
"Annihilating remnant cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
465 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
471 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
478 ATH_MSG_DEBUG(
"Have subtracted charged shower for this eflowRecTrack");
492 unsigned int nEFCaloObs =
data.caloObjects->size();
494 for (
unsigned int iCalo = 0; iCalo < nEFCaloObs; ++iCalo) {
503 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
508 if (!thisEfRecTrack->
hasBin())
continue;
518 for (
auto thisLink :
links){
529 for (; theCell != lastCell; theCell++){
533 double oldCellEnergy = theCell->
energy()*(theCell.
weight());
534 double subtractedCellWeight = (oldCellEnergy - truthEnergy)/oldCellEnergy;
540 float oldEnergy = thisCluster->
e();
542 if (0.0 != oldEnergy) {
543 float energyAdjustment = thisCluster->
e() / oldEnergy;
544 thisCluster->
setRawE(thisCluster->
rawE() * energyAdjustment);
556 if ((expectedEnergy == 0) && (clusterEnergy > 0))
return false;
567 result <<
" track with E, eta and phi "<<
track->e() <<
", " <<
track->eta() <<
" and " <<
track->phi();
573 result <<
" cluster with E, eta and phi of " << cluster->
e() <<
", " << cluster->
eta() <<
" and " << cluster->
phi();
579 for (
const auto *thisEFRecCluster : recClusterContainer){
580 if (thisEFRecCluster->getTrackMatches().empty()) {
584 std::vector<eflowTrackClusterLink*> theTrackLinks = thisEFRecCluster->getTrackMatches();
585 for (
auto *thisTrack : theTrackLinks){
594 unsigned int numTracks = thisEflowCaloObject.
nTracks();
596 for (
unsigned int iTrack = 0; iTrack < numTracks; ++iTrack){
598 for (
auto thisPair : clusterList){