11 #include "GaudiKernel/Bootstrap.h"
12 #include "GaudiKernel/IMessageSvc.h"
13 #include "GaudiKernel/ISvcLocator.h"
20 : AsgMessaging(
"eflowCellSubtractionFacilitator")
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,
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) {
105 for (; theFirstCell != theLastCell; ++theFirstCell){
112 thisPair.second =
true;
119 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
122 double targetRingEnergy,
126 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
128 for (
auto thisCell : itRing->second) {
130 std::pair<const CaloCell*, int> thisPair = thisCell;
133 tracksClusters[thisPair.second].second =
true;
137 double oldCellWeight = theIterator.
weight();
138 double ringWeight = targetRingEnergy / eRings;
139 const double newCellWeight = oldCellWeight * ringWeight;
140 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
142 <<
" is changing weight of cell with energy " <<
cell->e()
143 <<
" from " << oldCellWeight <<
" to " << newCellWeight);
144 theIterator.
reweight(newCellWeight);
152 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
159 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
161 for (
auto thisCell : itRing->second) {
163 std::pair<const CaloCell*, int> thisPair = thisCell;
166 tracksClusters[thisPair.second].second =
true;
167 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
168 << cluster->
e() <<
" is removing cell with e "
169 << thisPair.first->e());
180 const std::pair<eflowCaloENUM, short>& ring,
182 const double eExpect,
184 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
192 const short ringNo = ring.second;
194 const double r1 = ringNo * cellSubtractionManager.
ringThickness(subtLayer);
196 (ringNo + 1) * cellSubtractionManager.
ringThickness(subtLayer);
202 double eRings =
getRingsEnergy(tracksClusters, beginRing, endRing);
204 if (eSubtracted + eRings > eExpect) {
207 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting partial ring, "
208 "eSubtracted, eRings and eExpect are "
209 << eSubtracted <<
", " << eRings <<
", " << eExpect);
213 double targetRingEnergy = eRings - (eExpect - eSubtracted);
214 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: targetRingEnergy is "
215 << targetRingEnergy);
217 tracksClusters, beginRing, endRing, targetRingEnergy, eRings, theTrack,
addCPData);
218 eSubtracted = eExpect;
228 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting full ring ");
232 eSubtracted += eRings;
236 if (fabs(eClustersOld - eSubtracted) < 1.0
e-6 * eClustersOld) {
252 const double eExpect,
261 double oldCellWeight = theIterator.
weight();
262 double oldCellEnergy =
cell->energy() * oldCellWeight;
264 if (oldCellEnergy != 0. && eSubtracted + oldCellEnergy > eExpect) {
267 double targetCellEnergy = oldCellEnergy - (eExpect - eSubtracted);
269 double energyWeight = targetCellEnergy / oldCellEnergy;
270 double newCellWeight = oldCellWeight * energyWeight;
271 theIterator.
reweight(newCellWeight);
274 eSubtracted = eExpect;
284 eSubtracted += oldCellEnergy;
294 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
296 const double eExpect,
302 CellIt endCellPosition = reorderedCells.
end();
303 while (itCellPosition != endCellPosition) {
305 std::vector<std::pair<const CaloCell*, int>>
::iterator itEntry =
306 itCellPosition->second.begin();
307 std::vector<std::pair<const CaloCell*, int>>
::iterator endEntry =
308 itCellPosition->second.end();
309 for (; itEntry != endEntry; ++itEntry) {
310 const std::pair<const CaloCell*, int> thisPair = *itEntry;
313 tracksClusters[thisPair.second].second =
true;
331 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
333 bool& annFlag,
const bool&
addCPData)
const
336 const double trackEnergy = theTrack.
getTrack()->
e();
337 const double eExpect = cellSubtractionManager.
fudgeMean() * trackEnergy;
338 const double sigmaEExpect =
339 cellSubtractionManager.
fudgeStdDev() * trackEnergy;
340 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: For track with trackEnergy "
341 << trackEnergy <<
" expect to subtract " << eExpect
342 <<
" with width of " << sigmaEExpect);
344 double eSubtracted = 0.0;
349 std::map<double, RingId>::const_iterator ringIt =
351 std::map<double, RingId>::const_iterator ringEnd =
352 cellSubtractionManager.
rankEnd();
353 for (; ringIt != ringEnd; ++ringIt) {
371 if (orderedCells.
mapSize() <= 0 || eSubtracted >= eExpect) {
407 for (; itCell != endCell; ++itCell) {
409 if (pCell == thisCell) {