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) {
 
  110     for (; theFirstCell != theLastCell;){
 
  113       theLastCell = theCellLink->
end();
 
  118     thisPair.second = 
true;
 
  125   std::vector<std::pair<xAOD::CaloCluster*, bool>>& tracksClusters,
 
  128   double targetRingEnergy,
 
  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;
 
  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,
 
  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,
 
  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.0
e-6 * eClustersOld) {
 
  258                                                   const double eExpect,
 
  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,
 
  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;
 
  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) {