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();
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));
117 if (msgLvl(MSG::DEBUG))
120 ATH_MSG_DEBUG(
"Matching track with e,pt, eta and phi " << track->e() <<
", " << track->pt() <<
", " << track->eta() <<
" and " << track->phi());
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 > > uniqueIDTruthPairs = accessor(*(thisCluster->getCluster()));
158 for (
auto &uniqueIDTruthPair : uniqueIDTruthPairs){
159 if (uniqueIDTruthPair.first == uniqueID){
161 bestClusters.push_back(thisLink);
168 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");
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 (
const 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;
205 if (msgLvl(MSG::DEBUG))
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());
216 unsigned int linkIndex = 0;
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.");
244 if (msgLvl(MSG::DEBUG)){
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");
296 if (msgLevel(MSG::DEBUG)){
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());
322 if (msgLevel(MSG::DEBUG))
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);
350 if (msgLevel(MSG::DEBUG))
351 for (
const auto& thisPair : clusterList)
352 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
361 if (msgLevel(MSG::DEBUG))
362 for (
const 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;
392 const std::vector<eflowTrackClusterLink *>& links = thisEfRecTrack->
getClusterMatches();
393 matchedClusters.reserve(links.size());
394 for (
auto* thisEFlowTrackClusterLink : links)
395 matchedClusters.push_back(thisEFlowTrackClusterLink->getCluster());
398 matchedClusters.end(),
401 if (msgLvl(MSG::DEBUG)) {
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);
433 if (msgLevel(MSG::DEBUG))
434 for (
const auto& thisPair : clusterSubtractionList)
435 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
443 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
445 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
454 totalClusterEnergy = std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
459 if (msgLevel(MSG::DEBUG))
460 for (
const 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;
467 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
471 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
473 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
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;
516 const std::vector<eflowTrackClusterLink *>& links = thisEfRecTrack->
getClusterMatches();
518 for (
auto thisLink : links){
532 for (; theCell != lastCell;){
536 double oldCellEnergy = theCell->
energy()*(theCell.
weight());
537 double subtractedCellWeight = (oldCellEnergy - truthEnergy)/oldCellEnergy;
541 lastCell = theCellLinks->
end();
544 theCell.
reweight(subtractedCellWeight);
551 float oldEnergy = thisCluster->
e();
553 if (0.0 != oldEnergy) {
554 float energyAdjustment = thisCluster->
e() / oldEnergy;
555 thisCluster->
setRawE(thisCluster->
rawE() * energyAdjustment);
567 if ((expectedEnergy == 0) && (clusterEnergy > 0))
return false;
577 std::stringstream result;
578 result <<
" track with E, eta and phi "<< track->e() <<
", " << track->eta() <<
" and " << track->phi();
583 std::stringstream result;
584 result <<
" cluster with E, eta and phi of " << cluster->
e() <<
", " << cluster->
eta() <<
" and " << cluster->
phi();
590 for (
const auto *thisEFRecCluster : recClusterContainer){
591 if (thisEFRecCluster->getTrackMatches().empty()) {
595 std::vector<eflowTrackClusterLink*> theTrackLinks = thisEFRecCluster->getTrackMatches();
596 for (
auto *thisTrack : theTrackLinks){
605 unsigned int numTracks = thisEflowCaloObject.
nTracks();
607 for (
unsigned int iTrack = 0; iTrack < numTracks; ++iTrack){
609 for (
const auto& thisPair : clusterList){
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
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.