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");
175 std::vector<std::pair<eflowRecCluster *, float>> bestClusters_02 =
m_theMatchingToolForPull_02->doMatches(thisEfRecTrack, data.clusters, -1);
176 for (
auto &matchpair : bestClusters_02)
179 float distancesq = matchpair.second;
181 if (distancesq < 0.15 * 0.15)
185 static const std::string cone15Str{
"cone_015"};
186 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, cone15Str);
188 static const std::string cone2Str{
"cone_02"};
189 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, cone2Str);
194 for (
const auto& thePair : matchedClusters) {
196 if (
m_addCPData) deltaRPrime.push_back(std::sqrt(thePair.second));
200 const std::vector<eflowTrackClusterLink*>* matchedClusters_02 = thisEfRecTrack->getAlternativeClusterMatches(
"cone_02");
201 if (!matchedClusters_02)
continue;
202 else bestClusters = *matchedClusters_02;
205 if (bestClusters.empty())
continue;
207 if (msgLvl(MSG::DEBUG))
209 for (
auto *thisClusterLink : bestClusters ) {
211 ATH_MSG_DEBUG(
"Matched this track to cluster with e,pt, eta and phi " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
218 unsigned int linkIndex = 0;
219 for (
auto *trkClusLink : bestClusters){
225 if (std::find(data.clusters.begin(), data.clusters.end(), trkClusLink->getCluster()) == data.clusters.end()) {
232 thisEfRecTrack->addClusterMatch(trackClusterLink);
234 thisEfRecTrack->addDeltaRPrime(deltaRPrime[linkIndex]);
242 std::vector<eflowRecCluster *> clusters(data.clusters.begin(), data.clusters.end());
245 ATH_MSG_DEBUG(
"Created " << nCaloObjects <<
" eflowCaloObjects.");
246 if (msgLvl(MSG::DEBUG)){
247 for (
auto thisEFlowCaloObject : *(data.caloObjects)){
248 ATH_MSG_DEBUG(
"This eflowCaloObject has " << thisEFlowCaloObject->nTracks() <<
" tracks and " << thisEFlowCaloObject->nClusters() <<
" clusters ");
249 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nTracks();
count++){
251 ATH_MSG_DEBUG(
"Have track with e, pt, eta and phi of " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
", " << thisTrack->
eta() <<
" and " << thisTrack->
phi());
253 for (
unsigned int count = 0;
count < thisEFlowCaloObject->nClusters();
count++){
255 ATH_MSG_DEBUG(
"Have cluster with e, pt, eta and phi of " << thisCluster->
e() <<
", " << thisCluster->
pt() <<
", " << thisCluster->
eta() <<
" and " << thisCluster->
phi());
260 const double gaussianRadius = 0.032;
261 const double gaussianRadiusError = 1.0e-3;
262 const double maximumRadiusSigma = 3.0;
270 for (
unsigned int iCalo = nCaloObj; iCalo < data.caloObjects->size(); ++iCalo) {
278 else return nCaloObj;
282 unsigned int nEFCaloObs = data.caloObjects->size();
283 for (
unsigned int iCalo = startingPoint; iCalo < nEFCaloObs; ++iCalo) {
293 unsigned int nClusters = thisEflowCaloObject.
nClusters();
294 unsigned int nTrackMatches = thisEflowCaloObject.
nTracks();
296 ATH_MSG_DEBUG(
"Have got an eflowCaloObject with " << nClusters <<
" clusters and " << nTrackMatches <<
" track matches");
298 if (msgLevel(MSG::DEBUG)){
299 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack){
309 if (nTrackMatches < 1)
return;
317 if (
isEOverPFail(expectedEnergy, expectedSigma, clusterEnergy))
return;
320 const std::vector<std::pair<eflowTrackClusterLink *, std::pair<float, float>>> &matchedTrackList = thisEflowCaloObject.
efRecLink();
322 ATH_MSG_DEBUG(
"Matched Track List has size " << matchedTrackList.size());
324 if (msgLevel(MSG::DEBUG))
326 for (
unsigned int iTrack = 0; iTrack < nTrackMatches; ++iTrack)
329 ATH_MSG_DEBUG(
"eflowCaloObject has track match with E, pt and eta " << thisTrack->
e() <<
", " << thisTrack->
pt() <<
" and " << thisTrack->
eta());
333 ATH_MSG_DEBUG(
"About to perform subtraction for this eflowCaloObject");
335 bool wasAnnihilated =
false;
340 if (
canAnnihilate(expectedEnergy, expectedSigma, clusterEnergy)){
342 wasAnnihilated =
true;
344 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterList;
345 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
346 unsigned nCluster = thisEflowCaloObject.
nClusters();
347 for (
unsigned iCluster = 0; iCluster < nCluster; ++iCluster){
351 ATH_MSG_DEBUG(
"We are going to annihilate. ExpectedEnergy, expectedSigma and clusterEnergy are " << expectedEnergy <<
", " << expectedSigma <<
" and " << clusterEnergy);
352 if (msgLevel(MSG::DEBUG))
353 for (
const auto& thisPair : clusterList)
354 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
363 if (msgLevel(MSG::DEBUG))
364 for (
const auto& thisPair : clusterList)
365 ATH_MSG_DEBUG(
"Have Annihilated cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
368 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
369 eflowRecTrack *thisEfRecTrack = (matchedTrackList[iTrack].first)->getTrack();
377 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
384 if (!thisEfRecTrack->
hasBin())
continue;
390 ATH_MSG_DEBUG(
"Am not in dense environment for this eflowCaloObject");
393 std::vector<eflowRecCluster *> matchedClusters;
394 const std::vector<eflowTrackClusterLink *>& links = thisEfRecTrack->
getClusterMatches();
395 matchedClusters.reserve(links.size());
396 for (
auto* thisEFlowTrackClusterLink : links)
397 matchedClusters.push_back(thisEFlowTrackClusterLink->getCluster());
400 matchedClusters.end(),
403 if (msgLvl(MSG::DEBUG)) {
404 for (
auto* thisClus : matchedClusters)
406 "Haved matched cluster "
407 << thisClus->getCluster()->index() <<
" with e,pt, eta and phi of "
408 << thisClus->getCluster()->e() <<
", "
409 << thisClus->getCluster()->pt() <<
", "
410 << thisClus->getCluster()->eta() <<
" and "
411 << thisClus->getCluster()->phi() <<
" will be subtracted");
415 std::vector<std::pair<xAOD::CaloCluster *, bool>> clusterSubtractionList;
416 clusterSubtractionList.reserve(matchedClusters.size());
417 std::map<xAOD::CaloCluster *, double> clusterEnergyMap;
418 for (
auto *thisEFlowRecCluster : matchedClusters){
420 clusterSubtractionList.emplace_back(thisCluster,
false);
421 clusterEnergyMap[thisCluster] = thisCluster->
e();
424 ATH_MSG_DEBUG(
"Have filled clusterSubtractionList for this eflowCaloObject");
426 unsigned int trackIndex = thisEfRecTrack->
getTrack()->index();
429 auto sumClusEnergy = [](
double accumulator, std::pair<xAOD::CaloCluster *, bool> thisPair){
return accumulator += thisPair.first->e();};
430 double totalClusterEnergy = std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
435 if (msgLevel(MSG::DEBUG))
436 for (
const auto& thisPair : clusterSubtractionList)
437 ATH_MSG_DEBUG(
"Annihilating cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
445 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
447 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
456 totalClusterEnergy = std::accumulate(clusterSubtractionList.begin(),clusterSubtractionList.end(),0.0,sumClusEnergy);
461 if (msgLevel(MSG::DEBUG))
462 for (
const auto& thisPair : clusterSubtractionList){
463 ATH_MSG_DEBUG(
"Annihilating remnant cluster with E and eta " << thisPair.first->e() <<
" and " << thisPair.first->eta());
467 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
469 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
473 std::vector<std::pair<float, float>> clusterSubtractedEnergyRatios;
475 m_pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, thisEflowCaloObject, trackIndex);
480 ATH_MSG_DEBUG(
"Have subtracted charged shower for this eflowRecTrack");
494 unsigned int nEFCaloObs = data.caloObjects->size();
496 for (
unsigned int iCalo = 0; iCalo < nEFCaloObs; ++iCalo) {
505 for (
unsigned iTrack = 0; iTrack < thisEflowCaloObject.
nTracks(); ++iTrack){
510 if (!thisEfRecTrack->
hasBin())
continue;
518 const std::vector<eflowTrackClusterLink *>& links = thisEfRecTrack->
getClusterMatches();
520 for (
auto thisLink : links){
534 for (; theCell != lastCell;){
538 double oldCellEnergy = theCell->
energy()*(theCell.
weight());
539 double subtractedCellWeight = (oldCellEnergy - truthEnergy)/oldCellEnergy;
543 lastCell = theCellLinks->
end();
546 theCell.
reweight(subtractedCellWeight);
553 float oldEnergy = thisCluster->
e();
555 if (0.0 != oldEnergy) {
556 float energyAdjustment = thisCluster->
e() / oldEnergy;
557 thisCluster->
setRawE(thisCluster->
rawE() * energyAdjustment);
569 if ((expectedEnergy == 0) && (clusterEnergy > 0))
return false;
579 std::stringstream result;
580 result <<
" track with E, eta and phi "<< track->e() <<
", " << track->eta() <<
" and " << track->phi();
585 std::stringstream result;
586 result <<
" cluster with E, eta and phi of " << cluster->
e() <<
", " << cluster->
eta() <<
" and " << cluster->
phi();
592 for (
const auto *thisEFRecCluster : recClusterContainer){
593 if (thisEFRecCluster->getTrackMatches().empty()) {
597 std::vector<eflowTrackClusterLink*> theTrackLinks = thisEFRecCluster->getTrackMatches();
598 for (
auto *thisTrack : theTrackLinks){
607 unsigned int numTracks = thisEflowCaloObject.
nTracks();
608 const std::string allCaloStr{
"AllCalo"};
609 for (
unsigned int iTrack = 0; iTrack < numTracks; ++iTrack){
611 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)
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.