ATLAS Offline Software
CheckCloningFactor.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "GaudiKernel/MsgStream.h"
8 #include "GaudiKernel/DataSvc.h"
9 
10 #include <set>
11 
12 CheckCloningFactor::CheckCloningFactor(const std::string& name, ISvcLocator* pSvcLocator)
13 : AthAlgorithm(name, pSvcLocator)
14 {
15  // Set users' request
16  declareProperty("McEventKey", m_key="GEN_EVENT");
17  declareProperty("Tolerance", m_tolerance=0.000001);
18  m_eventCount = 0;
19 }
20 
22 
23  for (int i=0; i<=2; ++i) bqKinematics[i].clear();
24  m_eventCount = 0;
25 
26  return StatusCode::SUCCESS;
27 
28 }
29 
30 
32 
33  ++m_eventCount;
34 
35  // Read Data from Transient Store
36  const McEventCollection* mcCollptr = nullptr;
37  if (evtStore()->retrieve(mcCollptr, m_key).isFailure()) {
38  ATH_MSG_ERROR("Could not retrieve McEventCollection");
39  return StatusCode::FAILURE;
40  }
41 
42  // Loop over all events in McEventCollection
44  std::vector<HepMC::ConstGenParticlePtr> bQuarks;
45  for (itr = mcCollptr->begin(); itr!=mcCollptr->end(); ++itr) {
46  // Loop over all particles in the event and find the b-quarks
47  const HepMC::GenEvent* genEvt = (*itr);
48  for (auto pitr: *genEvt) {
49  int p_id = pitr->pdg_id();
50  if ( (std::abs(p_id)==5) && (pitr->status() == 62 || pitr->status() == 63) ) {
51  bQuarks.push_back(pitr);
52  }
53  }
54  }
55  //Unfortunately it is not clear what should happen in the case of absence of b quarks. To prevent bad things we return false.
56  if ( bQuarks.size()==0) return StatusCode::FAILURE;
57  // Loop over the b-quarks and find the one with higest pt
59  double lastPt(-1.0);
60  for (auto bItr = bQuarks.begin(); bItr!=bQuarks.end(); ++bItr) {
61  double thisPt=(*bItr)->momentum().perp();
62  if (thisPt>lastPt) { recordedBQuarkIt=bItr; }
63  }
64  //cppcheck-suppress uninitvar
65  auto BQMom=(*recordedBQuarkIt)->momentum();
66  double b_pt = BQMom.perp();
67  double b_rapid = BQMom.pseudoRapidity();
68  double b_phi = BQMom.phi();
69 
70  unsigned int nAccumulatedEvents = bqKinematics[0].size();
71  bool isUnique(true);
72  for (unsigned int i=0; i<nAccumulatedEvents; ++i) {
73  double pt = (bqKinematics[0])[i];
74  double rap = (bqKinematics[1])[i];
75  double phi = (bqKinematics[2])[i];
76  if ((std::abs(pt-b_pt)<m_tolerance) &&
77  (std::abs(rap-b_rapid)<m_tolerance) &&
78  (std::abs(phi-b_phi)<m_tolerance) ) isUnique=false;
79  if (!isUnique) break;
80  }
81 
82  if (isUnique) {
83  bqKinematics[0].push_back(b_pt);
84  bqKinematics[1].push_back(b_rapid);
85  bqKinematics[2].push_back(b_phi);
86  }
87 
88  return StatusCode::SUCCESS;
89 }
90 
91 
93 
94  int uniqueEvents = bqKinematics[0].size();
95  ATH_MSG_INFO("Total number of accepted events = " << m_eventCount);
96  ATH_MSG_INFO("Total number of unique events = " << uniqueEvents);
97  ATH_MSG_INFO("Ratio = " << (double)m_eventCount / (double)uniqueEvents);
98 
99  return StatusCode::SUCCESS;
100 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
CheckCloningFactor::initialize
StatusCode initialize()
Definition: CheckCloningFactor.cxx:21
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CheckCloningFactor::m_eventCount
int m_eventCount
Definition: CheckCloningFactor.h:20
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
test_pyathena.pt
pt
Definition: test_pyathena.py:11
CheckCloningFactor::m_key
std::string m_key
Definition: CheckCloningFactor.h:18
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CheckCloningFactor::bqKinematics
std::vector< double > bqKinematics[3]
Definition: CheckCloningFactor.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
McEventCollection.h
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
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CheckCloningFactor.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CheckCloningFactor::execute
StatusCode execute()
Definition: CheckCloningFactor.cxx:31
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
CheckCloningFactor::m_tolerance
double m_tolerance
Definition: CheckCloningFactor.h:19
CheckCloningFactor::CheckCloningFactor
CheckCloningFactor(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CheckCloningFactor.cxx:12
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
CheckCloningFactor::finalize
StatusCode finalize()
Definition: CheckCloningFactor.cxx:92