11#include "GaudiKernel/Bootstrap.h"
12#include "GaudiKernel/IMessageSvc.h"
13#include "GaudiKernel/ISvcLocator.h"
29 bool& annFlag,
bool addCPData)
const
31 std::vector<std::pair<xAOD::CaloCluster*, bool>> localClusterBoolPairVec(
32 1, std::pair(tracksCluster,
false));
34 cellSubtractionManager, theTrack, localClusterBoolPairVec, orderedCells, annFlag, addCPData);
39 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters)
41 for (
auto& thisPair : tracksClusters)
49 float oldEnergy = theCluster->
e();
51 if (0.0 != oldEnergy) {
52 float energyAdjustment = theCluster->
e() / oldEnergy;
53 theCluster->
setRawE(theCluster->
rawE() * energyAdjustment);
61 const std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters)
63 double eClustersOld = 0;
65 for (
auto& thisPair : tracksClusters)
66 eClustersOld += (thisPair.first)->e();
72 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
79 for (
CellIt it = beginRing; it != endRing; ++it) {
81 for (
const std::pair<const CaloCell*, int>& thisPair : it->second) {
86 double cellWeight = theIterator.
weight();
87 eRing += thisPair.first->energy() * cellWeight;
96 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
bool& annFlag,
99 for (
auto& thisPair : tracksClusters) {
109 for (; theFirstCell != theLastCell;){
112 theLastCell = theCellLink->
end();
117 thisPair.second =
true;
124 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
127 double targetRingEnergy,
129 bool addCPData)
const
132 ATH_MSG_ERROR(
"eflowCellSubtractionFacilitator::subtractPartialRings: eRings is zero.");
135 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
137 for (
const std::pair<const CaloCell*, int>& thisPair : itRing->second) {
141 tracksClusters[thisPair.second].second =
true;
142 const CaloCell* cell = thisPair.first;
145 double oldCellWeight = theIterator.
weight();
146 double ringWeight = targetRingEnergy / eRings;
147 const double newCellWeight = oldCellWeight * ringWeight;
148 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
150 <<
" is changing weight of cell with energy " << cell->e()
151 <<
" from " << oldCellWeight <<
" to " << newCellWeight);
152 theIterator.
reweight(newCellWeight);
160 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
163 bool addCPData)
const
167 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
169 for (
const std::pair<const CaloCell*, int>& thisPair : itRing->second) {
173 tracksClusters[thisPair.second].second =
true;
174 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
175 << cluster->
e() <<
" is removing cell with e "
176 << thisPair.first->e());
187 const std::pair<eflowCaloENUM, short>& ring,
189 const double eExpect,
191 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
193 bool addCPData )
const
199 const short ringNo = ring.second;
201 const double r1 = ringNo * cellSubtractionManager.
ringThickness(subtLayer);
203 (ringNo + 1) * cellSubtractionManager.
ringThickness(subtLayer);
209 double eRings =
getRingsEnergy(tracksClusters, beginRing, endRing);
211 if (eSubtracted + eRings > eExpect) {
214 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting partial ring, "
215 "eSubtracted, eRings and eExpect are "
216 << eSubtracted <<
", " << eRings <<
", " << eExpect);
220 double targetRingEnergy = eRings - (eExpect - eSubtracted);
221 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: targetRingEnergy is "
222 << targetRingEnergy);
224 tracksClusters, beginRing, endRing, targetRingEnergy, eRings, theTrack, addCPData);
225 eSubtracted = eExpect;
235 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting full ring ");
239 eSubtracted += eRings;
243 if (std::fabs(eClustersOld - eSubtracted) < 1.0e-6 * eClustersOld) {
259 const double eExpect,
268 double oldCellWeight = theIterator.
weight();
269 double oldCellEnergy = cell->energy() * oldCellWeight;
271 if (oldCellEnergy != 0. && eSubtracted + oldCellEnergy > eExpect) {
274 double targetCellEnergy = oldCellEnergy - (eExpect - eSubtracted);
276 double energyWeight = targetCellEnergy / oldCellEnergy;
277 double newCellWeight = oldCellWeight * energyWeight;
278 theIterator.
reweight(newCellWeight);
281 eSubtracted = eExpect;
291 eSubtracted += oldCellEnergy;
301 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
303 const double eExpect,
309 CellIt endCellPosition = reorderedCells.
end();
310 while (itCellPosition != endCellPosition) {
312 std::vector<std::pair<const CaloCell*, int>>
::iterator itEntry =
313 itCellPosition->second.begin();
314 std::vector<std::pair<const CaloCell*, int>>
::iterator endEntry =
315 itCellPosition->second.end();
316 for (; itEntry != endEntry; ++itEntry) {
317 const std::pair<const CaloCell*, int> thisPair = *itEntry;
320 tracksClusters[thisPair.second].second =
true;
321 const CaloCell* cell = thisPair.first;
322 bool isFinished =
subtractCaloCell(eSubtracted, eExpect, cluster, cell, theTrack, addCPData);
327 CellIt tmp = itCellPosition;
338 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
340 bool& annFlag,
bool addCPData)
const
343 const double trackEnergy = theTrack.
getTrack()->
e();
344 const double eExpect = cellSubtractionManager.
fudgeMean() * trackEnergy;
345 const double sigmaEExpect =
346 cellSubtractionManager.
fudgeStdDev() * trackEnergy;
347 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: For track with trackEnergy "
348 << trackEnergy <<
" expect to subtract " << eExpect
349 <<
" with width of " << sigmaEExpect);
351 double eSubtracted = 0.0;
356 std::map<double, RingId>::const_iterator ringIt =
358 std::map<double, RingId>::const_iterator ringEnd =
359 cellSubtractionManager.
rankEnd();
360 for (; ringIt != ringEnd; ++ringIt) {
378 if (orderedCells.
mapSize() <= 0 || eSubtracted >= eExpect) {
414 for (; itCell != endCell; ++itCell) {
416 if (pCell == thisCell) {
Data object for each calorimeter readout cell.
unsigned index() const
Accessor for the index of the cell in the CaloCellContainer.
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.
AsgMessaging(const std::string &name)
Constructor with a name.
Concrete class derived class from pure virtual eflowAbstractCellList.
CellIt getLowerBound(eflowCaloENUM layer, double r)
void reorderWithoutLayers()
void deleteFromList(CellIt &start, CellIt &end)
bool subtractRings(eflowRingSubtractionManager &ringSubtractionManager, const std::pair< eflowCaloENUM, short > &ring, double &eSubtracted, const double eExpect, eflowCellList &orderedCells, std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, bool &annFlag, eflowRecTrack &theTrack, bool addCPData) const
static void updateClusterKinematics(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters)
double subtractCells(eflowRingSubtractionManager &ringSubtractionManager, eflowRecTrack &theTrack, xAOD::CaloCluster *tracksClus, eflowCellList &orderedCells, bool &annFlag, bool addCPData) const
static bool subtractCaloCell(double &eSubtracted, const double eExpect, xAOD::CaloCluster *cluster, const CaloCell *cell, eflowRecTrack &theTrack, bool addCPData)
void subtractPartialRings(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, CellIt beginRing, CellIt endRing, double targetRingEnergy, double eRing, eflowRecTrack &theTrack, bool addCPData) const
static CaloClusterCellLink::iterator getCellIterator(xAOD::CaloCluster *thisCluster, const CaloCell *thisCell)
static double getRingsEnergy(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, CellIt beginRing, CellIt endRing)
static bool subtractReorderedCells(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, double eSubtracted, const double eExpect, eflowCellList &orderedCells, eflowRecTrack &theTrack, bool addCPData)
eflowCellSubtractionFacilitator()
void subtractFullRings(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, CellIt beginRing, CellIt endRing, eflowRecTrack &theTrack, bool addCPData) const
static double getTotalEnergy(const std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters)
static void annihilateClusters(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, bool &annFlag, eflowRecTrack &theTrack, bool addCPData)
This class extends the information about a xAOD::Track.
const xAOD::TrackParticle * getTrack() const
void addSubtractedCaloCell(ElementLink< CaloCellContainer > theCellLink, const double &weight)
This stores information, a rank and ring thickness, about cell rings in an ordered way.
std::map< double, RingId >::const_iterator rankBegin() const
std::map< double, RingId >::const_iterator rankEnd() const
double ringThickness(eflowCaloENUM layer) const
double fudgeStdDev() const
void setRawEta(flt_t)
Set for signal state UNCALIBRATED.
void setRawPhi(flt_t)
Set for signal state UNCALIBRATED.
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).
void setCalE(flt_t)
Set Energy for signal state CALIBRATED.
bool removeCell(const CaloCell *ptr)
Method to remove a cell to the cluster (slow!) (Beware: Kinematics not updated!).
virtual double e() const override final
The total energy of the particle.
std::map< eflowCellPosition, std::vector< std::pair< constCaloCell *, int > > >::iterator CellIt
eflowCalo::LAYER eflowCaloENUM
singleton-like access to IMessageSvc via open function and helper
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.