ATLAS Offline Software
GenParticleJetFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // GenParticleJetFinder.cxx
7 // Source file for class GenParticleJetFinder
9 // (c) ATLAS Detector software
11 
14 
15 Trk::GenParticleJetFinder::GenParticleJetFinder(const std::string& type, const std::string& name, const IInterface* parent)
17  m_yijCut (0.003)
18 {
19  declareInterface<IGenParticleJetFinder>(this);
20 
21  declareProperty("yCut", m_yijCut);
22 }
23 
28  ATH_MSG_INFO ("initialise in " << name() );
29  return StatusCode::SUCCESS;
30 }
31 
36  ATH_MSG_INFO ( "starting finalize() in " << name() );
37  return StatusCode::SUCCESS;
38 }
39 
43 std::vector< Trk::GenParticleJet >* Trk::GenParticleJetFinder::jetMCFinder( std::vector <HepMC::ConstGenParticlePtr>& GenStableCharged) const
44 {
45  if (GenStableCharged.empty()) {
46  ATH_MSG_INFO ("no selected charged particles!");
47  return nullptr;
48  }
49  std::vector< Trk::GenParticleJet >* myJets
50  = new std::vector< Trk::GenParticleJet >;
51  ATH_MSG_DEBUG ( "start jetMCFinder() with input GenParticle-vector "
52  << "of size " << GenStableCharged.size() );
53 
54  myJets->clear();
55  double totalEnergyFromTracks=0.;
56  int partIterations=0;
57  double yijmin=100.;
58  bool combineParticles = false;
59 
61 
62  for( auto i = GenStableCharged.begin() ; i < GenStableCharged.end(); ++i){
63  totalEnergyFromTracks = totalEnergyFromTracks + (*i)->momentum().e();
64  Trk::GenParticleJet tempPJ;
65  tempPJ.addParticle( *i, int(i - GenStableCharged.begin()) );
66  myJets->push_back(tempPJ);
67  }
68 
69  int numParts = myJets->size();
70  do {
71  combineParticles = false;
72  yijmin=100.;
73  for( std::vector<Trk::GenParticleJet>::iterator i = myJets->begin() ; i<myJets->end(); ++i) {
74 
75  for( std::vector<Trk::GenParticleJet>::iterator j = myJets->begin() ; j<myJets->end(); ++j) {
76 
77  if (i!=j) {
78 
79  double yij=0;
80  double absI= sqrt((i->getMomentum()).dot(i->getMomentum()));
81  double absJ= sqrt(((*j).getMomentum()).dot((*j).getMomentum()));
82  double IdotJ= (((*i).getMomentum()).dot((*j).getMomentum()));
83  if (fabs(absI*absJ)<0.000001 || fabs(totalEnergyFromTracks)<0.00001) {
84 
85  ATH_MSG_WARNING ("JetMCFinder: momenta / total energy is 0, "
86  << "can't continue calculations." );
87  delete myJets;
88  return nullptr;
89 
90  } else {
91  yij=2*(i->getEnergy())*(j->getEnergy())/pow(totalEnergyFromTracks,2)*(1-(IdotJ/(absI*absJ)));
92  if (yij<yijmin) {
93 
94  combineParticles=true;
95  yijmin=yij;
96  iAtMin=i;
97  jAtMin=j;
98 
99  };
100  };
101  }
102  }
103  }
104  partIterations++;
105 
106  /* If one pair of particles are found which have the required minimal */
107 
108  if (combineParticles) {
109 
110  ATH_MSG_VERBOSE ("combining: " << (*iAtMin).getNumParticles()
111  << " ("<<(*iAtMin).getIndicesInEvent().size()<<")"
112  << " and "<< (*jAtMin).getNumParticles()
113  << " ("<<(*jAtMin).getIndicesInEvent().size()<<")" );
114  if((*iAtMin).getNumParticles()>(*jAtMin).getNumParticles()) {
115 
116  auto partsTemp = (*jAtMin).getParticles();
117  std::vector<int> indexTemp = (*jAtMin).getIndicesInEvent();
118  // int partsTempSize = partsTemp.size();
119  if (!partsTemp.empty()) {
120 
121  std::vector<int>::iterator ki=indexTemp.begin();
122  for (auto k =partsTemp.begin(); k!=partsTemp.end(); ++k, ++ki) {
123  (*iAtMin).addParticle(*k,*ki);
124  }
125  } else {
126 
127  ATH_MSG_WARNING ("No particles in this jet, logic failed, stop finder." );
128  delete myJets;
129  return nullptr;
130  }
131  myJets->erase(jAtMin);
132  }
133  else {
134 
135  auto partsTemp = (*iAtMin).getParticles();
136  std::vector<int> indexTemp = (*iAtMin).getIndicesInEvent();
137  if (!partsTemp.empty()) {
138 
139  std::vector<int>::iterator ki=indexTemp.begin();
140  for (auto k =partsTemp.begin(); k!=partsTemp.end(); ++k, ++ki) {
141  // tempPartJet.addParticle(*k);
142  (*jAtMin).addParticle(*k,*ki);
143  }
144  }
145  else {
146  ATH_MSG_WARNING ( "No particles in this jet, logic failed, stop finder." );
147  delete myJets;
148  return nullptr;
149  }
150  myJets->erase(iAtMin);
151  }
152  }
153  int currentNumParts = 0;
154  for(std::vector<Trk::GenParticleJet>::iterator k = myJets->begin(); k<myJets->end(); ++k)
155  currentNumParts = currentNumParts + k->getNumParticles();
156 
157  if(numParts != currentNumParts){
158  ATH_MSG_WARNING ( "Losing particles in jets!!" );
159  delete myJets;
160  return nullptr;
161  }
162  if(partIterations==999)
163  ATH_MSG_INFO ( "JetMCFinder cut off because of too many (1000) iterations");
164 
165  } while (yijmin<m_yijCut && partIterations<1000);
166  return myJets;
167 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::GenParticleJetFinder::jetMCFinder
virtual std::vector< Trk::GenParticleJet > * jetMCFinder(std::vector< HepMC::ConstGenParticlePtr > &) const
main method returning vector of truth-jets
Definition: GenParticleJetFinder.cxx:43
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::GenParticleJetFinder::finalize
virtual StatusCode finalize()
finalize
Definition: GenParticleJetFinder.cxx:35
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::GenParticleJet::addParticle
void addParticle(HepMC::ConstGenParticlePtr part, int indexInEvent=-1)
Definition: GenParticleJet.h:61
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::GenParticleJetFinder::initialize
virtual StatusCode initialize()
initialize
Definition: GenParticleJetFinder.cxx:27
test_pyathena.parent
parent
Definition: test_pyathena.py:15
dot.dot
def dot(G, fn, nodesToHighlight=[])
Definition: dot.py:5
Trk::GenParticleJetFinder::m_yijCut
float m_yijCut
Definition: GenParticleJetFinder.h:44
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::GenParticleJet
short class to organise MC generated particles as a jet.
Definition: GenParticleJet.h:32
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
GenParticleJetFinder.h
GenParticleJet.h
xAOD::JetConstituent::e
double e() const
The total energy of the particle.
Definition: JetConstituentVector.h:76
AthAlgTool
Definition: AthAlgTool.h:26
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
Trk::GenParticleJetFinder::GenParticleJetFinder
GenParticleJetFinder(const std::string &type, const std::string &name, const IInterface *parent)
Definition: GenParticleJetFinder.cxx:15
fitman.k
k
Definition: fitman.py:528