ATLAS Offline Software
CaloCalibClusterTruthAttributerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 CaloCalibClusterTruthAttributerTool::CaloCalibClusterTruthAttributerTool(const std::string& type, const std::string& name, const IInterface* parent) : base_class(type,name,parent) {
8 }
9 
11 
12 StatusCode CaloCalibClusterTruthAttributerTool::calculateTruthEnergies(const xAOD::CaloCluster& theCaloCluster, unsigned int numTruthParticles, const std::map<Identifier,std::vector<const CaloCalibrationHit*> >& identifierToCaloHitMap, std::vector<std::pair<unsigned int, double > >& truthIDTrueCalHitEnergy) const{
13 
14  ATH_MSG_DEBUG("In calculateTruthEnergies");
15 
16  const CaloClusterCellLink* theCellLinks = theCaloCluster.getCellLinks();
17 
18  if (!theCellLinks) {
19  ATH_MSG_ERROR("A CaloCluster has no CaloClusterCellLinks");
20  return StatusCode::FAILURE;
21  }
22 
23  std::map<unsigned int, double> truthIDTruePtMap;
24 
25  //Loop on calorimeter cells to sum up the truth energies of the truth particles.
26  for (const auto *thisCaloCell : *theCellLinks){
27 
28  if (!thisCaloCell){
29  ATH_MSG_WARNING("Have invalid pointer to CaloCell");
30  continue;
31  }
32 
33  //get the unique calorimeter cell identifier
34  Identifier cellID = thisCaloCell->ID();
35 
36  //look up the calibration hit that corresponds to this calorimeter cell - we use find because not all calorimeter cells will have calibration hits
37  std::map<Identifier,std::vector<const CaloCalibrationHit*> >::const_iterator identifierToCaloHitMapIterator = identifierToCaloHitMap.find(cellID);
38  if (identifierToCaloHitMap.end() == identifierToCaloHitMapIterator) continue;
39  std::vector<const CaloCalibrationHit*> theseCalibrationHits = (*identifierToCaloHitMapIterator).second;
40 
41  for (const auto *thisCalibrationHit : theseCalibrationHits){
42  const int truthID = HepMC::uniqueID(thisCalibrationHit);
43  double thisCalHitTruthEnergy = thisCalibrationHit->energyEM() + thisCalibrationHit->energyNonEM();
44  if (true == m_fullTruthEnergy) thisCalHitTruthEnergy += (thisCalibrationHit->energyEscaped() + thisCalibrationHit->energyInvisible());
45 
46  auto iterator = truthIDTruePtMap.find(truthID);
47  if (iterator != truthIDTruePtMap.end()) truthIDTruePtMap[truthID] += thisCalHitTruthEnergy;
48  else truthIDTruePtMap[truthID] = thisCalHitTruthEnergy;
49 
50  }//calibration hit loop
51 
52  }//loop on calorimeter cells to sum up truth energies
53 
54  //now create a vector with the same information as the map, which we can then sort
55  std::vector<std::pair<unsigned int, double > > truthIDTruePtPairs;
56 
57  truthIDTruePtPairs.reserve(truthIDTruePtMap.size());
58  for (const auto& thisEntry : truthIDTruePtMap) truthIDTruePtPairs.emplace_back(thisEntry);
59 
60  //sort vector by calibration hit truth energy
61  std::sort(truthIDTruePtPairs.begin(),truthIDTruePtPairs.end(),[]( std::pair<unsigned int, double> a, std::pair<unsigned int, double> b) -> bool {return a.second > b.second;} );
62 
63  //store the truthID and truth energy of the top numTruthParticles truth particles
64  if (numTruthParticles > truthIDTruePtPairs.size()) numTruthParticles = truthIDTruePtPairs.size();
65  for ( unsigned int counter = 0; counter < numTruthParticles; counter++) truthIDTrueCalHitEnergy.push_back(truthIDTruePtPairs[counter]);
66 
67  for (const auto& thisPair : truthIDTrueCalHitEnergy) ATH_MSG_DEBUG("Truncated loop 2: truthID and true energy are " << thisPair.first << " and " << thisPair.second << " for cluster with e, eta of " << theCaloCluster.e() << " and " << theCaloCluster.eta() );
68 
69  return StatusCode::SUCCESS;
70 
71 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CaloCalibClusterTruthAttributerTool.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloCalibClusterTruthAttributerTool::calculateTruthEnergies
virtual StatusCode calculateTruthEnergies(const xAOD::CaloCluster &theCaloCluster, unsigned int numTruthParticles, const std::map< Identifier, std::vector< const CaloCalibrationHit * > > &identifierToCaloHitMap, std::vector< std::pair< unsigned int, double > > &barcodeTrueCalHitEnergy) const override
This calculates the truth energies of N leading truth particles in a topocluster.
Definition: CaloCalibClusterTruthAttributerTool.cxx:12
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:905
CaloCalibClusterTruthAttributerTool::CaloCalibClusterTruthAttributerTool
CaloCalibClusterTruthAttributerTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloCalibClusterTruthAttributerTool.cxx:7
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
a
TList * a
Definition: liststreamerinfos.cxx:10
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCalibClusterTruthAttributerTool::~CaloCalibClusterTruthAttributerTool
virtual ~CaloCalibClusterTruthAttributerTool()
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
test_pyathena.counter
counter
Definition: test_pyathena.py:15
CaloCalibClusterTruthAttributerTool::m_fullTruthEnergy
Gaudi::Property< bool > m_fullTruthEnergy
Toggle storage of invisible and escaped energy - by default this is false, and hence we do not store ...
Definition: CaloCalibClusterTruthAttributerTool.h:28
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265
Identifier
Definition: IdentifierFieldParser.cxx:14