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
131 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
133 for (
const std::pair<const CaloCell*, int>& thisPair : itRing->second) {
137 tracksClusters[thisPair.second].second =
true;
138 const CaloCell* cell = thisPair.first;
141 double oldCellWeight = theIterator.
weight();
142 double ringWeight = targetRingEnergy / eRings;
143 const double newCellWeight = oldCellWeight * ringWeight;
144 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
146 <<
" is changing weight of cell with energy " << cell->e()
147 <<
" from " << oldCellWeight <<
" to " << newCellWeight);
148 theIterator.
reweight(newCellWeight);
156 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
159 bool addCPData)
const
163 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
165 for (
const std::pair<const CaloCell*, int>& thisPair : itRing->second) {
169 tracksClusters[thisPair.second].second =
true;
170 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
171 << cluster->
e() <<
" is removing cell with e "
172 << thisPair.first->e());
183 const std::pair<eflowCaloENUM, short>& ring,
185 const double eExpect,
187 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
189 bool addCPData )
const
195 const short ringNo = ring.second;
197 const double r1 = ringNo * cellSubtractionManager.
ringThickness(subtLayer);
199 (ringNo + 1) * cellSubtractionManager.
ringThickness(subtLayer);
205 double eRings =
getRingsEnergy(tracksClusters, beginRing, endRing);
207 if (eSubtracted + eRings > eExpect) {
210 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting partial ring, "
211 "eSubtracted, eRings and eExpect are "
212 << eSubtracted <<
", " << eRings <<
", " << eExpect);
216 double targetRingEnergy = eRings - (eExpect - eSubtracted);
217 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: targetRingEnergy is "
218 << targetRingEnergy);
220 tracksClusters, beginRing, endRing, targetRingEnergy, eRings, theTrack, addCPData);
221 eSubtracted = eExpect;
231 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting full ring ");
235 eSubtracted += eRings;
239 if (std::fabs(eClustersOld - eSubtracted) < 1.0e-6 * eClustersOld) {
255 const double eExpect,
264 double oldCellWeight = theIterator.
weight();
265 double oldCellEnergy = cell->energy() * oldCellWeight;
267 if (oldCellEnergy != 0. && eSubtracted + oldCellEnergy > eExpect) {
270 double targetCellEnergy = oldCellEnergy - (eExpect - eSubtracted);
272 double energyWeight = targetCellEnergy / oldCellEnergy;
273 double newCellWeight = oldCellWeight * energyWeight;
274 theIterator.
reweight(newCellWeight);
277 eSubtracted = eExpect;
287 eSubtracted += oldCellEnergy;
297 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
299 const double eExpect,
305 CellIt endCellPosition = reorderedCells.
end();
306 while (itCellPosition != endCellPosition) {
308 std::vector<std::pair<const CaloCell*, int>>
::iterator itEntry =
309 itCellPosition->second.begin();
310 std::vector<std::pair<const CaloCell*, int>>
::iterator endEntry =
311 itCellPosition->second.end();
312 for (; itEntry != endEntry; ++itEntry) {
313 const std::pair<const CaloCell*, int> thisPair = *itEntry;
316 tracksClusters[thisPair.second].second =
true;
317 const CaloCell* cell = thisPair.first;
318 bool isFinished =
subtractCaloCell(eSubtracted, eExpect, cluster, cell, theTrack, addCPData);
323 CellIt tmp = itCellPosition;
334 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
336 bool& annFlag,
bool addCPData)
const
339 const double trackEnergy = theTrack.
getTrack()->
e();
340 const double eExpect = cellSubtractionManager.
fudgeMean() * trackEnergy;
341 const double sigmaEExpect =
342 cellSubtractionManager.
fudgeStdDev() * trackEnergy;
343 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: For track with trackEnergy "
344 << trackEnergy <<
" expect to subtract " << eExpect
345 <<
" with width of " << sigmaEExpect);
347 double eSubtracted = 0.0;
352 std::map<double, RingId>::const_iterator ringIt =
354 std::map<double, RingId>::const_iterator ringEnd =
355 cellSubtractionManager.
rankEnd();
356 for (; ringIt != ringEnd; ++ringIt) {
374 if (orderedCells.
mapSize() <= 0 || eSubtracted >= eExpect) {
410 for (; itCell != endCell; ++itCell) {
412 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.