ATLAS Offline Software
TrackRecordFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "./TrackRecordFilter.h"
7 
9  ISvcLocator* pSvcLocator):
10  AthReentrantAlgorithm(name, pSvcLocator)
11 {
12 }
13 
15  ATH_CHECK(m_inputKey.initialize());
16  ATH_CHECK(m_outputKey.initialize());
17 
18  return StatusCode::SUCCESS;
19 }
20 
21 StatusCode TrackRecordFilter::execute(const EventContext& ctx) const {
22 
23  // Get message service
24  ATH_MSG_DEBUG ( "TrackRecordFilter::execute()" );
25 
26  // retrieve the collection
28  if (!trackCollection.isPresent() || !trackCollection.isValid()) {
29  ATH_MSG_DEBUG ( "Could not find TrackRecord collection" );
30  return StatusCode::SUCCESS;
31  }
32  ATH_MSG_DEBUG ( "There are " << trackCollection->size() << "tracks in this container " );
33 
35  // create and record a new collection
36  CHECK( filterCollection.record(std::make_unique<TrackRecordCollection>()) );
37 
38  // iterate over the collection
39  for (const auto& trkit : *trackCollection) {
40  int pdgId(trkit.GetPDGCode());
41  ATH_MSG_VERBOSE ( "Track found with pdg id= " << trkit.GetPDGCode() << " with energy "<< trkit.GetEnergy() );
42 
43  if(pdgId) { //Geant makes particle with pdgid=0...
44  // get rid of neutral particles
45  if (std::fabs(MC::charge(pdgId) ) >0.5 && trkit.GetEnergy() > m_cutOff) {
46  filterCollection->push_back(TrackRecord(trkit));
47  }
48  }
49  }
50 
51 
52  ATH_MSG_DEBUG ( "There are " << filterCollection->size() << "that satisfy the filter " );
53  return StatusCode::SUCCESS;
54 }
55 
57  return StatusCode::SUCCESS;
58 }
59 
TrackRecordFilter::execute
StatusCode execute(const EventContext &ctx) const override
Definition: TrackRecordFilter.cxx:21
TrackRecordFilter::initialize
StatusCode initialize() override
Definition: TrackRecordFilter.cxx:14
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
TrackRecordFilter::m_outputKey
SG::WriteHandleKey< TrackRecordCollection > m_outputKey
Definition: TrackRecordFilter.h:30
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
TrackRecordFilter::TrackRecordFilter
TrackRecordFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackRecordFilter.cxx:8
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrackRecordFilter::m_inputKey
SG::ReadHandleKey< TrackRecordCollection > m_inputKey
Definition: TrackRecordFilter.h:29
charge
double charge(const T &p)
Definition: AtlasPID.h:897
TrackRecord
Definition: TrackRecord.h:12
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrackRecordFilter::m_cutOff
DoubleProperty m_cutOff
Definition: TrackRecordFilter.h:31
TrackRecordFilter::finalize
StatusCode finalize() override
Definition: TrackRecordFilter.cxx:56
AtlasHitsVector::size
size_type size() const
Definition: AtlasHitsVector.h:143
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:394
HepMCHelpers.h
AtlasHitsVector::push_back
void push_back(const T &t)
Definition: AtlasHitsVector.h:145
TrackRecordFilter.h