11#include "GaudiKernel/Bootstrap.h"
12#include "GaudiKernel/IMessageSvc.h"
13#include "GaudiKernel/ISvcLocator.h"
29 bool& annFlag,
const 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 (
auto thisCell : it->second) {
83 std::pair<const CaloCell*, int> thisPair = thisCell;
87 double cellWeight = theIterator.
weight();
88 eRing += thisPair.first->energy() * cellWeight;
97 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
bool& annFlag,
100 for (
auto& thisPair : tracksClusters) {
110 for (; theFirstCell != theLastCell;){
113 theLastCell = theCellLink->
end();
118 thisPair.second =
true;
125 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
128 double targetRingEnergy,
130 const bool& addCPData)
const
132 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
134 for (
auto thisCell : itRing->second) {
136 std::pair<const CaloCell*, int> thisPair = thisCell;
139 tracksClusters[thisPair.second].second =
true;
140 const CaloCell* cell = thisPair.first;
143 double oldCellWeight = theIterator.
weight();
144 double ringWeight = targetRingEnergy / eRings;
145 const double newCellWeight = oldCellWeight * ringWeight;
146 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
148 <<
" is changing weight of cell with energy " << cell->e()
149 <<
" from " << oldCellWeight <<
" to " << newCellWeight);
150 theIterator.
reweight(newCellWeight);
158 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
161 const bool& addCPData)
const
165 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
167 for (
auto thisCell : itRing->second) {
169 std::pair<const CaloCell*, int> thisPair = thisCell;
172 tracksClusters[thisPair.second].second =
true;
173 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
174 << cluster->
e() <<
" is removing cell with e "
175 << thisPair.first->e());
186 const std::pair<eflowCaloENUM, short>& ring,
188 const double eExpect,
190 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
192 const bool& addCPData )
const
198 const short ringNo = ring.second;
200 const double r1 = ringNo * cellSubtractionManager.
ringThickness(subtLayer);
202 (ringNo + 1) * cellSubtractionManager.
ringThickness(subtLayer);
208 double eRings =
getRingsEnergy(tracksClusters, beginRing, endRing);
210 if (eSubtracted + eRings > eExpect) {
213 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting partial ring, "
214 "eSubtracted, eRings and eExpect are "
215 << eSubtracted <<
", " << eRings <<
", " << eExpect);
219 double targetRingEnergy = eRings - (eExpect - eSubtracted);
220 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: targetRingEnergy is "
221 << targetRingEnergy);
223 tracksClusters, beginRing, endRing, targetRingEnergy, eRings, theTrack, addCPData);
224 eSubtracted = eExpect;
234 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting full ring ");
238 eSubtracted += eRings;
242 if (fabs(eClustersOld - eSubtracted) < 1.0e-6 * eClustersOld) {
258 const double eExpect,
262 const bool& addCPData)
267 double oldCellWeight = theIterator.
weight();
268 double oldCellEnergy = cell->energy() * oldCellWeight;
270 if (oldCellEnergy != 0. && eSubtracted + oldCellEnergy > eExpect) {
273 double targetCellEnergy = oldCellEnergy - (eExpect - eSubtracted);
275 double energyWeight = targetCellEnergy / oldCellEnergy;
276 double newCellWeight = oldCellWeight * energyWeight;
277 theIterator.
reweight(newCellWeight);
280 eSubtracted = eExpect;
290 eSubtracted += oldCellEnergy;
300 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
302 const double eExpect,
305 const bool& addCPData)
308 CellIt endCellPosition = reorderedCells.
end();
309 while (itCellPosition != endCellPosition) {
311 std::vector<std::pair<const CaloCell*, int>>
::iterator itEntry =
312 itCellPosition->second.begin();
313 std::vector<std::pair<const CaloCell*, int>>
::iterator endEntry =
314 itCellPosition->second.end();
315 for (; itEntry != endEntry; ++itEntry) {
316 const std::pair<const CaloCell*, int> thisPair = *itEntry;
319 tracksClusters[thisPair.second].second =
true;
320 const CaloCell* cell = thisPair.first;
321 bool isFinished =
subtractCaloCell(eSubtracted, eExpect, cluster, cell, theTrack, addCPData);
326 CellIt tmp = itCellPosition;
337 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
339 bool& annFlag,
const bool& addCPData)
const
342 const double trackEnergy = theTrack.
getTrack()->
e();
343 const double eExpect = cellSubtractionManager.
fudgeMean() * trackEnergy;
344 const double sigmaEExpect =
345 cellSubtractionManager.
fudgeStdDev() * trackEnergy;
346 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: For track with trackEnergy "
347 << trackEnergy <<
" expect to subtract " << eExpect
348 <<
" with width of " << sigmaEExpect);
350 double eSubtracted = 0.0;
355 std::map<double, RingId>::const_iterator ringIt =
357 std::map<double, RingId>::const_iterator ringEnd =
358 cellSubtractionManager.
rankEnd();
359 for (; ringIt != ringEnd; ++ringIt) {
377 if (orderedCells.
mapSize() <= 0 || eSubtracted >= eExpect) {
413 for (; itCell != endCell; ++itCell) {
415 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)
static void updateClusterKinematics(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters)
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, const 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 void annihilateClusters(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, bool &annFlag, eflowRecTrack &theTrack, const bool &addCPData)
void subtractFullRings(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, CellIt beginRing, CellIt endRing, eflowRecTrack &theTrack, const bool &addCPData) const
eflowCellSubtractionFacilitator()
static bool subtractCaloCell(double &eSubtracted, const double eExpect, xAOD::CaloCluster *cluster, const CaloCell *cell, eflowRecTrack &theTrack, const bool &addCPData)
double subtractCells(eflowRingSubtractionManager &ringSubtractionManager, eflowRecTrack &theTrack, xAOD::CaloCluster *tracksClus, eflowCellList &orderedCells, bool &annFlag, const bool &addCPData) const
void subtractPartialRings(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, CellIt beginRing, CellIt endRing, double targetRingEnergy, double eRing, eflowRecTrack &theTrack, const bool &addCPData) const
static bool subtractReorderedCells(std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters, double eSubtracted, const double eExpect, eflowCellList &orderedCells, eflowRecTrack &theTrack, const bool &addCPData)
static double getTotalEnergy(const std::vector< std::pair< xAOD::CaloCluster *, bool > > &tracksClusters)
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.