41 ATH_MSG_ERROR(
"Failed to get TrackPositionProvider for cluster preselection!");
42 return StatusCode::FAILURE;
62 return StatusCode::SUCCESS;
71 data.caloObjects = theEflowCaloObjectContainer;
80 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();
106 for (
auto *thisEfRecTrack : data.tracks)
109 if (!thisEfRecTrack->hasBin()) {
110 std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>();
111 thisEflowCaloObject->addTrack(thisEfRecTrack);
112 data.caloObjects->push_back(std::move(thisEflowCaloObject));
116 if (msgLvl(MSG::DEBUG))
119 ATH_MSG_DEBUG(
"Matching track with e,pt, eta and phi " << track->e() <<
", " << track->pt() <<
", " << track->eta() <<
" and " << track->phi());
122 std::vector<eflowTrackClusterLink*> bestClusters;
123 std::vector<float> deltaRPrime;
132 TruthLink truthLink = truthLinkAccessor(*(thisEfRecTrack->getTrack()));
135 if (truthLink.
isValid()) trackMatchedTruthParticle = *truthLink;
137 if (trackMatchedTruthParticle){
141 if (!caloClusterReadDecorHandleNLeadingTruthParticles.isValid()){
142 ATH_MSG_WARNING(
"Failed to retrieve CaloCluster decoration with key " << caloClusterReadDecorHandleNLeadingTruthParticles.key());
145 for (
auto * thisCluster : data.clusters){
150 std::string::size_type pos = decorHandleName.find(
".");
151 std::string decorName = decorHandleName.substr(pos+1);
155 std::vector<std::pair<unsigned int, double > > uniqueIDTruthPairs = accessor(*(thisCluster->getCluster()));
157 for (
auto &uniqueIDTruthPair : uniqueIDTruthPairs){
158 if (uniqueIDTruthPair.first == uniqueID){
160 bestClusters.push_back(thisLink);
167 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");
174 std::vector<std::pair<eflowRecCluster *, float>> bestClusters_02 =
m_theMatchingToolForPull_02->doMatches(thisEfRecTrack, data.clusters, -1);
175 for (
auto &matchpair : bestClusters_02)
178 float distancesq = matchpair.second;
180 if (distancesq < 0.15 * 0.15)
184 static const std::string cone15Str{
"cone_015"};
185 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, cone15Str);
187 static const std::string cone2Str{
"cone_02"};
188 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, cone2Str);
193 for (
const 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;
206 if (msgLvl(MSG::DEBUG))
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());
217 unsigned int linkIndex = 0;
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.");
245 if (msgLvl(MSG::DEBUG)){
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");
297 if (msgLevel(MSG::DEBUG)){
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());
323 if (msgLevel(MSG::DEBUG))
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);
351 if (msgLevel(MSG::DEBUG))
352 for (
const auto& thisPair : clusterList)
353 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
362 if (msgLevel(MSG::DEBUG))
363 for (
const 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;
393 const std::vector<eflowTrackClusterLink *>& links = thisEfRecTrack->
getClusterMatches();
394 matchedClusters.reserve(links.size());
395 for (
auto* thisEFlowTrackClusterLink : links)
396 matchedClusters.push_back(thisEFlowTrackClusterLink->getCluster());
399 matchedClusters.end(),
402 if (msgLvl(MSG::DEBUG)) {
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);
434 if (msgLevel(MSG::DEBUG))
435 for (
const auto& thisPair : clusterSubtractionList)
436 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
444 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
446 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
455 totalClusterEnergy = std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
460 if (msgLevel(MSG::DEBUG))
461 for (
const 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;
468 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
472 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
474 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
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;
517 const std::vector<eflowTrackClusterLink *>& links = thisEfRecTrack->
getClusterMatches();
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;
578 std::stringstream result;
579 result <<
" track with E, eta and phi "<< track->e() <<
", " << track->eta() <<
" and " << track->phi();
584 std::stringstream result;
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();
607 const std::string allCaloStr{
"AllCalo"};
608 for (
unsigned int iTrack = 0; iTrack < numTracks; ++iTrack){
610 for (
const auto& thisPair : clusterList){
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
Handle class for reading a decoration on an object.
double energy() const
get energy (data member)
const_iterator to loop over cells belonging to a cluster
unsigned index() const
Accessor for the index of the cell in the CaloCellContainer.
weight_t weight() const
Accessor for weight associated to this cell.
void reweight(const weight_t newWeight)
Update the weight.
weight_t weight() const
Accessor for weight associated to this cell.
Bookkeeping of cells that make up a cluster Simplified replacement for CaloCellLink,...
const_iterator end() const
const end method
const_iterator begin() const
const begin method
static void calculateKine(xAOD::CaloCluster *clu, const bool useweight=true, const bool updateLayers=true, const bool useGPUCriteria=false)
Helper class to calculate cluster kinematics based on cells.
ElementLink implementation for ROOT usage.
bool isValid() const
Check if the element can be found.
static void fillClustersToRecover(PFData &data)
static void fillClustersToConsider(PFData &data, eflowRecClusterContainer &recClusterContainer)
static std::unique_ptr< IPositionProvider > Get(const std::string &positionType)
static void fillTracksToConsider(PFData &data, eflowRecTrackContainer &recTrackContainer)
static void fillTracksToRecover(PFData &data)
Helper class to provide type-safe access to aux data.
Handle class for reading a decoration on an object.
static unsigned int makeTrkCluCaloObjects(eflowRecTrackContainer *eflowTrackContainer, eflowRecClusterContainer *eflowClusterContainer, eflowCaloObjectContainer *caloObjectContainer)
An internal EDM object which stores information about systems of associated tracks and calorimeter cl...
void simulateShower(const EventContext &ctx, eflowLayerIntegrator *integrator, const eflowEEtaBinnedParameters *binnedParameters, const PFEnergyPredictorTool *energyP, bool useLegacyEnergyBinIndexing)
double getExpectedVariance() const
double getClusterEnergy() const
unsigned nClusters() const
const eflowRecTrack * efRecTrack(int i) const
const std::vector< std::pair< eflowTrackClusterLink *, std::pair< float, float > > > & efRecLink() const
double getExpectedEnergy() const
const eflowRecCluster * efRecCluster(int i) const
Inherits from eflowEEtaBinBase.
This class calculates the LHED (Layer of Highest Energy Density) in a cluster or group of clusters.
This class extends the information about a xAOD::CaloCluster.
void addTrackMatch(eflowTrackClusterLink *trackMatch)
xAOD::CaloCluster * getCluster()
This class extends the information about a xAOD::Track.
double getEExpect() const
const std::vector< eflowTrackClusterLink * > & getClusterMatches() const
bool isSubtracted() const
const xAOD::TrackParticle * getTrack() const
void addSubtractedCaloCell(ElementLink< CaloCellContainer > theCellLink, const double &weight)
double getCellTruthEnergy(const CaloCell *cell) const
bool isInDenseEnvironment() const
double getVarEExpect() const
static void annihilateClusters(std::vector< std::pair< xAOD::CaloCluster *, bool > > &clusters)
Stores pointers to an eflowRecTrack and an eflowRecCluster.
static eflowTrackClusterLink * getInstance(eflowRecTrack *track, eflowRecCluster *cluster, const EventContext &ctx)
void setRawEta(flt_t)
Set for signal state UNCALIBRATED.
void setRawPhi(flt_t)
Set for signal state UNCALIBRATED.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version).
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters).
void setRawE(flt_t)
Set Energy for signal state UNCALIBRATED.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
CaloClusterCellLink * getOwnCellLinks()
Get a pointer to the owned CaloClusterCellLink object (non-const version).
bool removeCell(const CaloCell *ptr)
Method to remove a cell to the cluster (slow!) (Beware: Kinematics not updated!).
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .).
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual double e() const override final
The total energy of the particle.
static std::string release
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.