11 #include "GaudiKernel/Bootstrap.h"
12 #include "GaudiKernel/IMessageSvc.h"
13 #include "GaudiKernel/ISvcLocator.h"
20 : AsgMessaging(
"eflowCellSubtractionFacilitator")
31 std::vector<std::pair<xAOD::CaloCluster*, bool>> localClusterBoolPairVec(
32 1, std::pair(tracksCluster,
false));
34 cellSubtractionManager, trackEnergy, localClusterBoolPairVec, orderedCells, annFlag);
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)
99 for (
auto& thisPair : tracksClusters) {
104 for (; theFirstCell != theLastCell; ++theFirstCell)
109 thisPair.second =
true;
116 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
119 double targetRingEnergy,
122 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
124 for (
auto thisCell : itRing->second) {
126 std::pair<const CaloCell*, int> thisPair = thisCell;
129 tracksClusters[thisPair.second].second =
true;
133 double oldCellWeight = theIterator.
weight();
134 const double newCellWeight = oldCellWeight * targetRingEnergy / eRings;
135 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
137 <<
" is changing weight of cell with energy " <<
cell->e()
138 <<
" from " << oldCellWeight <<
" to " << newCellWeight);
139 theIterator.
reweight(newCellWeight);
146 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
152 for (
CellIt itRing = beginRing; itRing != endRing; ++itRing) {
154 for (
auto thisCell : itRing->second) {
156 std::pair<const CaloCell*, int> thisPair = thisCell;
159 tracksClusters[thisPair.second].second =
true;
160 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Cluster with e "
161 << cluster->
e() <<
" is removing cell with e "
162 << thisPair.first->e());
171 const std::pair<eflowCaloENUM, short>& ring,
173 const double eExpect,
175 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
176 bool& annFlag )
const
182 const short ringNo = ring.second;
184 const double r1 = ringNo * cellSubtractionManager.
ringThickness(subtLayer);
186 (ringNo + 1) * cellSubtractionManager.
ringThickness(subtLayer);
192 double eRings =
getRingsEnergy(tracksClusters, beginRing, endRing);
194 if (eSubtracted + eRings > eExpect) {
197 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting partial ring, "
198 "eSubtracted, eRings and eExpect are "
199 << eSubtracted <<
", " << eRings <<
", " << eExpect);
203 double targetRingEnergy = eRings - (eExpect - eSubtracted);
204 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: targetRingEnergy is "
205 << targetRingEnergy);
207 tracksClusters, beginRing, endRing, targetRingEnergy, eRings);
208 eSubtracted = eExpect;
218 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: Subtracting full ring ");
222 eSubtracted += eRings;
226 if (fabs(eClustersOld - eSubtracted) < 1.0
e-6 * eClustersOld) {
242 const double eExpect,
249 double oldCellWeight = theIterator.
weight();
250 double oldCellEnergy =
cell->energy() * oldCellWeight;
252 if (oldCellEnergy != 0. && eSubtracted + oldCellEnergy > eExpect) {
255 double targetCellEnergy = oldCellEnergy - (eExpect - eSubtracted);
257 double newCellWeight = oldCellWeight * targetCellEnergy / oldCellEnergy;
258 theIterator.
reweight(newCellWeight);
260 eSubtracted = eExpect;
269 eSubtracted += oldCellEnergy;
279 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
281 const double eExpect,
285 CellIt endCellPosition = reorderedCells.
end();
286 while (itCellPosition != endCellPosition) {
288 std::vector<std::pair<const CaloCell*, int>>
::iterator itEntry =
289 itCellPosition->second.begin();
290 std::vector<std::pair<const CaloCell*, int>>
::iterator endEntry =
291 itCellPosition->second.end();
292 for (; itEntry != endEntry; ++itEntry) {
293 const std::pair<const CaloCell*, int> thisPair = *itEntry;
296 tracksClusters[thisPair.second].second =
true;
314 std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
319 const double eExpect = cellSubtractionManager.
fudgeMean() * trackEnergy;
320 const double sigmaEExpect =
321 cellSubtractionManager.
fudgeStdDev() * trackEnergy;
322 ATH_MSG_DEBUG(
"eflowCellSubtractionFacilitator: For track with trackEnergy "
323 << trackEnergy <<
" expect to subtract " << eExpect
324 <<
" with width of " << sigmaEExpect);
326 double eSubtracted = 0.0;
331 std::map<double, RingId>::const_iterator ringIt =
333 std::map<double, RingId>::const_iterator ringEnd =
334 cellSubtractionManager.
rankEnd();
335 for (; ringIt != ringEnd; ++ringIt) {
351 if (orderedCells.
mapSize() <= 0 || eSubtracted >= eExpect) {
387 for (; itCell != endCell; ++itCell) {
389 if (pCell == thisCell) {