ATLAS Offline Software
xAODDecayTimeFilter.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 #include "CLHEP/Random/RandomEngine.h"
8 #include <limits> // std::numeric_limits
9 
10 
11 xAODDecayTimeFilter::xAODDecayTimeFilter(const std::string& name, ISvcLocator* pSvcLocator)
12  : GenFilter(name, pSvcLocator)
13 {
14  declareProperty("LifetimeLow",m_lifetimeLow = std::numeric_limits<float>::lowest(), "proper decay time value in ps");
15  declareProperty("LifetimeHigh",m_lifetimeHigh = std::numeric_limits<float>::max(), "proper decay time value in ps");
16  declareProperty("Seedlifetime",m_seedlifetime = std::numeric_limits<float>::lowest(), "proper decay time value in ps");
17  declareProperty("Flatlifetime",m_flatlifetime = false, "proper decay time value in ps");
19 }
20 
21 
23  CHECK(m_rndmSvc.retrieve());
24  ATH_MSG_INFO("lifetimeLow=" << m_lifetimeLow);
25  ATH_MSG_INFO("lifetimeHigh=" << m_lifetimeHigh);
26  ATH_MSG_INFO("Seedlifetime=" << m_seedlifetime);
27  ATH_MSG_INFO("flatlifetime=" << m_flatlifetime);
28  for(int pdg : m_particleID){
29  ATH_MSG_INFO("PDG codes=" << pdg);
30  }
31  return StatusCode::SUCCESS;
32 }
33 
34 static double calcmag(const HepMC::FourVector& vect){
35  return std::sqrt(vect.x() * vect.x() + vect.y() * vect.y() + vect.z() * vect.z());
36 }
37 
39  auto startpos = ptr->prodVtx();
40  auto endpos = ptr->decayVtx();
41  HepMC::FourVector diff(endpos->x() - startpos->x(), endpos->y() - startpos->y(), endpos->z() - startpos->z(), endpos->t() - startpos->t());
42  double mag = calcmag(diff);
43  double length = mag;
44  HepMC::FourVector p(ptr->px(),ptr->py(),ptr->pz(),ptr->e());// = ptr->momentum ();
45  return (1000./299.792458) * (length * ptr->m() / calcmag(p));
46 }
47 
49 
50 // Retrieve TruthGen container from xAOD Gen slimmer, contains all particles witout barcode_zero and
51 // duplicated barcode ones
52  const xAOD::TruthParticleContainer* xTruthParticleContainer;
53  if (evtStore()->retrieve(xTruthParticleContainer, "TruthGen").isFailure()) {
54  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthGen" << " found in StoreGate!");
55  return StatusCode::FAILURE;
56  }
57 
58  int nPassPDG = 0;
59  bool passed = true;
60  const EventContext& ctx = Gaudi::Hive::currentContext();
61  CLHEP::HepRandomEngine* rndm = this->getRandomEngine(name(), ctx);
62  if (!rndm) {
63  ATH_MSG_WARNING("Failed to retrieve random number engine xAODDecayTimeFilter.");
64  setFilterPassed(false);
65  return StatusCode::SUCCESS;
66  }
67 
68  // Loop over all particles in the event
69  unsigned int nPart = xTruthParticleContainer->size();
70  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
71  const xAOD::TruthParticle* part = (*xTruthParticleContainer)[iPart];
72 
73  for (int pdg : m_particleID){
74  if(pdg == part->pdgId()){
75  nPassPDG++;
76  double calctau = tau(part);
77  passed &= calctau < m_lifetimeHigh && calctau > m_lifetimeLow;
78  if (m_flatlifetime) {
79  double rnd = rndm->flat();
80  //particle with calctau = m_lifetimeHigh is accepted 100%, the probability decreases exponentially as moving towards m_lifetimeLow
81  double threshold = std::pow(M_E,-1*m_lifetimeHigh/m_seedlifetime)/std::pow(M_E,-1*calctau/m_seedlifetime);
82  passed &= rnd < threshold;
83  }
84  }
85  }
86  }//loop over TruthParticles
87 
88 
89  setFilterPassed((nPassPDG > 0) & passed);
90  return StatusCode::SUCCESS;
91 }
92 
93 
94 CLHEP::HepRandomEngine* xAODDecayTimeFilter::getRandomEngine(const std::string& streamName,
95  const EventContext& ctx) const
96 {
97  ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
98  std::string rngName = name()+streamName;
99  rngWrapper->setSeed( rngName, ctx );
100  return rngWrapper->getEngine(ctx);
101 }
102 
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::TruthParticle_v1::pz
float pz() const
The z component of the particle's momentum.
xAODDecayTimeFilter::m_particleID
std::vector< int > m_particleID
Definition: xAODDecayTimeFilter.h:40
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
xAOD::TruthParticle_v1::px
float px() const
The x component of the particle's momentum.
xAODDecayTimeFilter::filterEvent
virtual StatusCode filterEvent()
Definition: xAODDecayTimeFilter.cxx:48
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
xAOD::TruthParticle_v1::py
float py() const
The y component of the particle's momentum.
calcmag
double calcmag(const HepMC::FourVector &vect)
Definition: DecayTimeFilter.cxx:27
xAODDecayTimeFilter::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: xAODDecayTimeFilter.h:38
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::TruthParticle_v1::e
virtual double e() const override final
The total energy of the particle.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAODDecayTimeFilter::getRandomEngine
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, const EventContext &ctx) const
Definition: xAODDecayTimeFilter.cxx:94
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TruthParticle_v1::decayVtx
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
xAODDecayTimeFilter::xAODDecayTimeFilter
xAODDecayTimeFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODDecayTimeFilter.cxx:11
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
threshold
Definition: chainparser.cxx:74
xAODDecayTimeFilter::tau
double tau(const xAOD::TruthParticle *ptr) const
Definition: xAODDecayTimeFilter.cxx:38
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
xAODDecayTimeFilter::m_flatlifetime
bool m_flatlifetime
Definition: xAODDecayTimeFilter.h:39
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
xAODDecayTimeFilter.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAODDecayTimeFilter::m_lifetimeLow
float m_lifetimeLow
Definition: xAODDecayTimeFilter.h:35
xAODDecayTimeFilter::m_lifetimeHigh
float m_lifetimeHigh
Definition: xAODDecayTimeFilter.h:36
xAODDecayTimeFilter::m_seedlifetime
float m_seedlifetime
Definition: xAODDecayTimeFilter.h:37
xAODDecayTimeFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: xAODDecayTimeFilter.cxx:22
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:25
dumpTgcDigiThreshold.threshold
list threshold
Definition: dumpTgcDigiThreshold.py:34
xAOD::TruthParticle_v1::m
virtual double m() const override final
The mass of the particle.