Commit 7159af25 authored by Mark Hodgkinson's avatar Mark Hodgkinson
Browse files

Bug fixes to ensure subtraction status setting is propagated.

Add new class to define function to set subtraction status.
parent 4f249865
......@@ -22,7 +22,6 @@ class IPFSubtractionTool : virtual public IAlgTool {
virtual void execute(eflowCaloObjectContainer*, eflowRecTrackContainer*, eflowRecClusterContainer*) = 0;
DeclareInterfaceID(IPFSubtractionTool,1,0);
};
};
#endif
......@@ -49,8 +49,7 @@ public:
std::string printTrack(const xAOD::TrackParticle* track);
std::string printCluster(const xAOD::CaloCluster* cluster);
void printAllClusters(const eflowRecClusterContainer& recClusterContainer);
void markSubtractionStatus(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterList, eflowCaloObject& thisEflowCaloObject);
eflowCaloObjectContainer* m_eflowCaloObjectContainer;
eflowRecTrackContainer* m_eflowTrackContainer;
eflowRecClusterContainer* m_eflowClusterContainer;
......
......@@ -49,7 +49,6 @@ class PFRecoverSplitShowersTool : public extends<AthAlgTool, IPFSubtractionTool>
void printClusterList(std::vector<xAOD::CaloCluster*>& clusters, std::string prefix);
void performSubtraction(eflowCaloObject* thisEflowCaloObject);
void markSubtractionStatus(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterList, eflowCaloObject& thisEflowCaloObject);
eflowCaloObjectContainer* m_eflowCaloObjectContainer;
std::vector<eflowRecCluster*> m_clustersToConsider;
......
#ifndef PFSUBTRACTIONSTATUSSETTER_H
#define PFSUBTRACTIONSTATUSSETTER_H
#include "xAODCaloEvent/CaloCluster.h"
class eflowCaloObject;
#include <vector>
#include <utility>
class PFSubtractionStatusSetter {
public:
void markSubtractionStatus(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterList, eflowCaloObject& thisEflowCaloObject);
};
#endif
......@@ -31,7 +31,7 @@ class eflowCellSubtractionFacilitator{
eflowCellSubtractionFacilitator();
double subtractCells(eflowRingSubtractionManager& ringSubtractionManager, double trackEnergy, xAOD::CaloCluster* tracksClus, eflowCellList& orderedCells);
double subtractCells(eflowRingSubtractionManager& ringSubtractionManager, double trackEnergy, std::vector<std::pair<xAOD::CaloCluster*, bool> > tracksClus, eflowCellList& orderedCells);
double subtractCells(eflowRingSubtractionManager& ringSubtractionManager, double trackEnergy, std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClus, eflowCellList& orderedCells);
bool annFlag() {return m_annFlag;}
void setAnnFlag() { m_annFlag = true; }
......@@ -56,7 +56,7 @@ class eflowCellSubtractionFacilitator{
bool subtractCaloCell(double & eSubtracted, const double eExpect, xAOD::CaloCluster* cluster, CaloCell* cell);
void annihilateClusters(std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters);
bool subtractReorderedCells(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters,
bool subtractReorderedCells(std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters,
double eSubtracted, const double eExpect, eflowCellList& orderedCells);
};
#endif
......@@ -38,7 +38,7 @@ public:
~Subtractor() { }
static void subtractTracksFromClusters(eflowRecTrack* efRecTrack, std::vector<std::pair<xAOD::CaloCluster*, bool> > clusterSubtractionList);
static void subtractTracksFromClusters(eflowRecTrack* efRecTrack, std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterSubtractionList);
static void annihilateClusters(std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusters);
static void annihilateCluster(xAOD::CaloCluster* cluster);
static void makeOrderedCellList(const eflowTrackCaloPoints& trackCalo, const std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusters, eflowCellList & orderedCells);
......
......@@ -18,6 +18,7 @@
#include "eflowRec/eflowCellSubtractionFacilitator.h"
#include "eflowRec/eflowSubtractor.h"
#include "eflowRec/eflowRingThicknesses.h"
#include "eflowRec/PFSubtractionStatusSetter.h"
#include "CaloEvent/CaloCluster.h"
......@@ -309,6 +310,8 @@ void PFCellLevelSubtractionTool::calculateRadialEnergyProfiles(){
void PFCellLevelSubtractionTool::performSubtraction() {
ATH_MSG_DEBUG("In performSubtraction");
PFSubtractionStatusSetter pfSubtractionStatusSetter;
unsigned int nEFCaloObs = m_eflowCaloObjectContainer->size();
for (unsigned int iEFCalOb = 0; iEFCalOb < nEFCaloObs; ++iEFCalOb) {
......@@ -349,8 +352,9 @@ void PFCellLevelSubtractionTool::performSubtraction() {
ATH_MSG_DEBUG("About to perform subtraction for this eflowCaloObject");
const std::vector<std::pair<eflowTrackClusterLink*, bool> >& matchedTrackList = thisEflowCaloObject->efRecLink();
if (canAnnihilated(expectedEnergy, expectedSigma, clusterEnergy)) {
/* Check if we can annihilate right away */
std::vector<std::pair<xAOD::CaloCluster*, bool> > clusterList;
unsigned nCluster = thisEflowCaloObject->nClusters();
......@@ -360,10 +364,10 @@ void PFCellLevelSubtractionTool::performSubtraction() {
Subtractor::annihilateClusters(clusterList);
//Now we should mark all of these clusters as being subtracted
this->markSubtractionStatus(clusterList, *thisEflowCaloObject);
pfSubtractionStatusSetter.markSubtractionStatus(clusterList, *thisEflowCaloObject);
} else {
/* Subtract the track from all matched clusters */
for (int iTrack = 0; iTrack < nTrackMatches; ++iTrack) {
......@@ -378,7 +382,6 @@ void PFCellLevelSubtractionTool::performSubtraction() {
if (efRecTrack->isInDenseEnvironment()) continue;
ATH_MSG_DEBUG("Have bin and am not in dense environment for this eflowCaloObject");
std::vector<eflowRecCluster*> matchedClusters;
......@@ -395,8 +398,7 @@ void PFCellLevelSubtractionTool::performSubtraction() {
Subtractor::subtractTracksFromClusters(efRecTrack, clusterSubtractionList);
//Now need to mark which clusters were modified in the subtraction procedure
this->markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
ATH_MSG_DEBUG("Have performed subtraction for this eflowCaloObject");
......@@ -404,7 +406,7 @@ void PFCellLevelSubtractionTool::performSubtraction() {
if (canAnnihilated(0, expectedSigma, clusterEnergy)) {
Subtractor::annihilateClusters(clusterSubtractionList);
//Now we should mark all of these clusters as being subtracted
this->markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
}
ATH_MSG_DEBUG("Have checked if can annihilate clusters for this eflowCaloOject");
......@@ -468,26 +470,3 @@ void PFCellLevelSubtractionTool::printAllClusters(const eflowRecClusterContainer
}
}
}
void PFCellLevelSubtractionTool::markSubtractionStatus(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterList, eflowCaloObject& thisEflowCaloObject){
//An eflowCaloObject may have one cluster and N tracks, and then one would have N eflowTrackClusterLink* for each track-cluster pair
//Hence there can be more entries in the track cluster link list due to duplication
const std::vector<std::pair<eflowTrackClusterLink*, bool> >& matchedTrackList = thisEflowCaloObject.efRecLink();
for (auto thisClusterPair : clusterList){
xAOD::CaloCluster* thisCluster = thisClusterPair.first;
for (auto thisTrackClusterLinkPair : matchedTrackList){
//if the subtraction status is already true, then no need to update it
if (true == thisTrackClusterLinkPair.second) continue;
//eflowTrackCluster link returns an eflowRecCluster pointer, which in turn returns an xAIOD:;CaloCluster* pointer
xAOD::CaloCluster* thisMatchedTrackCluster = (thisTrackClusterLinkPair.first)->getCluster()->getCluster();
//Now we can do a floating point comparison of the energy to check which cluster we have
if (fabs(thisCluster->e() - thisMatchedTrackCluster->e()) < 0.0001){
if (true == thisClusterPair.second) thisTrackClusterLinkPair.second = true;
}//if have a match of the cluster
}//loop on track cluster link pairs
}//loop on cluster pair list
}
......@@ -117,7 +117,7 @@ void PFOChargedCreatorAlgorithm::createChargedPFO(const eflowCaloObject& energyF
for (auto trackClusterLink : trackClusterLinks){
if (false == trackClusterLink.second) continue;
eflowRecCluster* efRecCluster = (trackClusterLink.first)->getCluster();
ElementLink<xAOD::CaloClusterContainer> theOriginalClusterLink = efRecCluster->getOriginalClusElementLink();
......
......@@ -19,6 +19,7 @@
#include "eflowRec/eflowRingSubtractionManager.h"
#include "eflowRec/eflowCellSubtractionFacilitator.h"
#include "eflowRec/eflowSubtractor.h"
#include "eflowRec/PFSubtractionStatusSetter.h"
#include "CaloEvent/CaloClusterContainer.h"
#include "xAODCaloEvent/CaloClusterKineHelper.h"
......@@ -210,6 +211,9 @@ int PFRecoverSplitShowersTool::matchAndCreateEflowCaloObj() {
}
void PFRecoverSplitShowersTool::performSubtraction(eflowCaloObject* thisEflowCaloObject) {
PFSubtractionStatusSetter pfSubtractionStatusSetter;
for (unsigned iTrack = 0; iTrack < thisEflowCaloObject->nTracks(); ++iTrack) {
eflowRecTrack* thisEfRecTrack = thisEflowCaloObject->efRecTrack(iTrack);
/* Get matched cluster via Links */
......@@ -222,27 +226,27 @@ void PFRecoverSplitShowersTool::performSubtraction(eflowCaloObject* thisEflowCal
std::vector<std::pair<xAOD::CaloCluster*, bool> > clusterSubtractionList;
clusterSubtractionList.reserve(matchedClusters.size());
for (auto thisEFlowRecCluster : matchedClusters) clusterSubtractionList.push_back(std::pair(thisEFlowRecCluster->getCluster(),false));
if (getSumEnergy(clusterSubtractionList) - thisEfRecTrack->getEExpect() < m_subtractionSigmaCut
* sqrt(thisEfRecTrack->getVarEExpect())) {
/* Check if we can annihilate right away */
Subtractor::annihilateClusters(clusterSubtractionList);
//Now we should mark all of these clusters as being subtracted
//Now need to mark which clusters were modified in the subtraction procedure
this->markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
} else {
/* Subtract the track from all matched clusters */
Subtractor::subtractTracksFromClusters(thisEfRecTrack, clusterSubtractionList);
//Now need to mark which clusters were modified in the subtraction procedure
this->markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
/* Annihilate the cluster(s) if the remnant is small (i.e. below k*sigma) */
if (getSumEnergy(clusterSubtractionList) < m_subtractionSigmaCut
* sqrt(thisEfRecTrack->getVarEExpect())) {
Subtractor::annihilateClusters(clusterSubtractionList);
//Now we should mark all of these clusters as being subtracted
this->markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, *thisEflowCaloObject);
}
}
/* Flag tracks as subtracted */
......@@ -264,26 +268,3 @@ double PFRecoverSplitShowersTool::getSumEnergy(const std::vector<std::pair<xAOD:
for (auto thisPair : clusters) result += (thisPair.first)->e();
return result;
}
void PFRecoverSplitShowersTool::markSubtractionStatus(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterList, eflowCaloObject& thisEflowCaloObject){
//An eflowCaloObject may have one cluster and N tracks, and then one would have N eflowTrackClusterLink* for each track-cluster pair
//Hence there can be more entries in the track cluster link list due to duplication
const std::vector<std::pair<eflowTrackClusterLink*, bool> >& matchedTrackList = thisEflowCaloObject.efRecLink();
for (auto thisClusterPair : clusterList){
xAOD::CaloCluster* thisCluster = thisClusterPair.first;
for (auto thisTrackClusterLinkPair : matchedTrackList){
//if the subtraction status is already true, then no need to update it
if (true == thisTrackClusterLinkPair.second) continue;
//eflowTrackCluster link returns an eflowRecCluster pointer, which in turn returns an xAIOD:;CaloCluster* pointer
xAOD::CaloCluster* thisMatchedTrackCluster = (thisTrackClusterLinkPair.first)->getCluster()->getCluster();
//Now we can do a floating point comparison of the energy to check which cluster we have
if (fabs(thisCluster->e() - thisMatchedTrackCluster->e()) < 0.0001){
if (true == thisClusterPair.second) thisTrackClusterLinkPair.second = true;
}//if have a match of the cluster
}//loop on track cluster link pairs
}//loop on cluster pair list
}
#include "eflowRec/PFSubtractionStatusSetter.h"
#include "eflowRec/eflowCaloObject.h"
#include "eflowRec/eflowRecCluster.h"
#include "eflowRec/eflowTrackClusterLink.h"
void PFSubtractionStatusSetter::markSubtractionStatus(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterList, eflowCaloObject& thisEflowCaloObject){
//An eflowCaloObject may have one cluster and N tracks, and then one would have N eflowTrackClusterLink* for each track-cluster pair
//Hence there can be more entries in the track cluster link list due to duplication
const std::vector<std::pair<eflowTrackClusterLink*, bool> >& matchedTrackList = thisEflowCaloObject.efRecLink();
for (auto thisClusterPair : clusterList){
xAOD::CaloCluster* thisCluster = thisClusterPair.first;
unsigned int counter = 0;
for (auto& thisTrackClusterLinkPair : matchedTrackList){
//if the subtraction status is already true, then no need to update it
if (true == thisTrackClusterLinkPair.second) {
counter++;
continue;
}
//eflowTrackCluster link returns an eflowRecCluster pointer, which in turn returns an xAOD:;CaloCluster* pointer
xAOD::CaloCluster* thisMatchedTrackCluster = (thisTrackClusterLinkPair.first)->getCluster()->getCluster();
//Now we can do a floating point comparison of the energy to check which cluster we have
if (fabs(thisCluster->e() - thisMatchedTrackCluster->e()) < 0.0001){
if (true == thisClusterPair.second) thisEflowCaloObject.setTrackClusterLinkSubtractionStatus(counter, true);
}//if have a match of the cluster
counter++;
}//loop on track cluster link pairs
}//loop on cluster pair list
}
......@@ -15,7 +15,8 @@
eflowCellSubtractionFacilitator::eflowCellSubtractionFacilitator(): m_annFlag(false) { }
double eflowCellSubtractionFacilitator::subtractCells(eflowRingSubtractionManager& cellSubtractionManager, double trackEnergy, xAOD::CaloCluster* tracksCluster, eflowCellList& orderedCells) {
return subtractCells(cellSubtractionManager, trackEnergy, std::vector<std::pair<xAOD::CaloCluster*, bool> > (1,std::pair(tracksCluster,false)), orderedCells);
std::vector<std::pair<xAOD::CaloCluster*, bool> > localClusterBoolPairVec(1,std::pair(tracksCluster,false));
return subtractCells(cellSubtractionManager, trackEnergy, localClusterBoolPairVec, orderedCells);
}
void eflowCellSubtractionFacilitator::updateClusterKinematics(std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters) {
......@@ -60,7 +61,7 @@ double eflowCellSubtractionFacilitator::getRingsEnergy(const std::vector<std::pa
}
void eflowCellSubtractionFacilitator::annihilateClusters(std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters) {
for (auto thisPair : tracksClusters){
for (auto& thisPair : tracksClusters){
xAOD::CaloCluster* thisCluster = thisPair.first;
const CaloClusterCellLink* theCellLink = thisCluster->getCellLinks();
CaloClusterCellLink* theCellLink_nonConst = const_cast<CaloClusterCellLink*>(theCellLink);
......@@ -196,7 +197,7 @@ bool eflowCellSubtractionFacilitator::subtractCaloCell(
}
}
bool eflowCellSubtractionFacilitator::subtractReorderedCells(const std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters, double eSubtracted, const double eExpect,
bool eflowCellSubtractionFacilitator::subtractReorderedCells(std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters, double eSubtracted, const double eExpect,
eflowCellList& reorderedCells) {
CellIt itCellPosition = reorderedCells.begin();
CellIt endCellPosition = reorderedCells.end();
......@@ -207,6 +208,8 @@ bool eflowCellSubtractionFacilitator::subtractReorderedCells(const std::vector<s
for (; itEntry != endEntry; ++itEntry) {
const std::pair<CaloCell*, int> thisPair = *itEntry;
xAOD::CaloCluster* cluster = tracksClusters[thisPair.second].first;
//flag this cluster as having had subtraction applied to it
tracksClusters[thisPair.second].second = true;
CaloCell* cell = thisPair.first;
bool isFinished = subtractCaloCell(eSubtracted, eExpect, cluster, cell);
if (isFinished) return true;
......@@ -219,7 +222,7 @@ bool eflowCellSubtractionFacilitator::subtractReorderedCells(const std::vector<s
return false;
}
double eflowCellSubtractionFacilitator::subtractCells(eflowRingSubtractionManager& cellSubtractionManager, double trackEnergy, std::vector<std::pair<xAOD::CaloCluster*, bool> > tracksClusters, eflowCellList& orderedCells) {
double eflowCellSubtractionFacilitator::subtractCells(eflowRingSubtractionManager& cellSubtractionManager, double trackEnergy, std::vector<std::pair<xAOD::CaloCluster*, bool> >& tracksClusters, eflowCellList& orderedCells) {
const double eExpect = cellSubtractionManager.fudgeMean() * trackEnergy;
const double sigmaEExpect = cellSubtractionManager.fudgeStdDev() * trackEnergy;
......
......@@ -26,7 +26,7 @@
namespace eflowSubtract {
void Subtractor::subtractTracksFromClusters(eflowRecTrack* efRecTrack, std::vector<std::pair<xAOD::CaloCluster*, bool> > clusterSubtractionList) {
void Subtractor::subtractTracksFromClusters(eflowRecTrack* efRecTrack, std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusterSubtractionList) {
/* Make ordered cell list */
/* (Invokes newCluster() on orderedCells, than adds all the cells in tracksClus) */
......@@ -66,7 +66,13 @@ namespace eflowSubtract {
void Subtractor::annihilateClusters(std::vector<std::pair<xAOD::CaloCluster*, bool> >& clusters) {
for (auto thisPair : clusters) annihilateCluster(thisPair.first);
for (auto& thisPair : clusters) {
annihilateCluster(thisPair.first);
//mark subtraction status as true
thisPair.second = true;
}
}
void Subtractor::annihilateCluster(xAOD::CaloCluster* cluster) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment