ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArG4
LArG4SD
src
CalibrationHitMerger.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
CalibrationHitMerger.h
"
6
8
LArG4::CalibrationHitMerger::CalibrationHitMerger
(
const
std::string& name, ISvcLocator* pSvcLocator ) :
9
::
AthAlgorithm
( name, pSvcLocator )
10
{}
11
13
StatusCode
LArG4::CalibrationHitMerger::initialize
()
14
{
15
ATH_CHECK
(
m_inputHits
.initialize());
16
ATH_CHECK
(
m_outputHits
.initialize());
17
return
StatusCode::SUCCESS;
18
}
19
20
22
StatusCode
LArG4::CalibrationHitMerger::execute
(
const
EventContext& ctx)
23
{
24
// skip if not input collection
25
if
(
m_inputHits
.empty() ) {
26
return
StatusCode::SUCCESS;
27
}
28
// TODO: is there a way to conveniently get the total number of hits in all m_inputHits
29
// and reserve the corresponding size in the outputHandle
30
SG::WriteHandle<CaloCalibrationHitContainer>
outputHandle{
m_outputHits
, ctx};
31
ATH_CHECK
( outputHandle.
record
(std::make_unique<CaloCalibrationHitContainer>()) );
32
calibrationHits_t
calibrationHits;
33
unsigned
int
nHitsMerged(0);
34
for
(
const
auto
& collKey:
m_inputHits
) {
35
SG::ReadHandle<CaloCalibrationHitContainer>
inputHandle{collKey, ctx};
36
ATH_MSG_DEBUG
(inputHandle.
name
() <<
" has "
<< inputHandle->size() <<
" hits."
);
37
for
(
const
CaloCalibrationHit
*
hit
: *inputHandle ) {
38
// If we haven't had a hit in this cell before, create one and add
39
// it to the hit collection.
40
41
// If we've had a hit in this cell before, then add the energy to
42
// the existing hit.
43
44
// Look for the key in the hitCollection (this is a binary search).
45
auto
bookmark = calibrationHits.lower_bound(
hit
);
46
47
// The lower_bound method of a map finds the first element
48
// whose key is not less than the identifier. If this element
49
// == our hit, we've found a match.
50
51
// Reminders:
52
// bookmark = iterator (pointer) into the hitCollection set.
53
// (*bookmark) = a member of the set, which is a LArG4Hit*.
54
55
// Equals() is a function defined in LArG4Hit.h; it has the value of
56
// "true" when a LArG4Hit* points to the same identifier.
57
58
if
(bookmark == calibrationHits.end() ||
59
!(*bookmark)->Equals(
hit
)) {
60
auto
&& hitCopy = std::make_unique<CaloCalibrationHit>(*
hit
);
61
// We haven't had a hit in this readout cell before. Add it
62
// to our set.
63
if
(calibrationHits.empty() ||
64
bookmark == calibrationHits.begin()) {
65
// Insert the hit before the first entry in the map.
66
calibrationHits.insert(hitCopy.release());
67
}
else
{
68
// We'just done a binary search of hitCollection, so we should use
69
// the results of that search to speed up the insertion of a new
70
// hit into the map. The "insert" method is faster if the new
71
// entry is right _after_ the bookmark. If we left bookmark
72
// unchanged, the new entry would go right _before_ the
73
// bookmark. We therefore want to decrement the bookmark from
74
// the lower_bound search.
75
calibrationHits.insert(--bookmark, hitCopy.release());
76
}
77
}
else
{
78
++nHitsMerged;
79
// Update the existing hit.
80
(*bookmark)->Add(
hit
);
81
}
82
}
83
}
84
85
// Loop through the hits...
86
for
(
auto
*
hit
: calibrationHits)
87
{
88
// Can we actually do this with move?
89
outputHandle->push_back(
hit
);
90
}
// End of loop over hits
91
// Clean up
92
calibrationHits.clear();
93
ATH_MSG_DEBUG
(outputHandle.
name
() <<
" has "
<< outputHandle->size() <<
" hits. Merged "
<< nHitsMerged <<
" hits."
);
94
return
StatusCode::SUCCESS;
95
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CalibrationHitMerger.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
CaloCalibrationHit
Class to store calorimeter calibration hit.
Definition
CaloCalibrationHit.h:24
LArG4::CalibrationHitMerger::calibrationHits_t
std::set< CaloCalibrationHit *, LessHit > calibrationHits_t
Definition
CalibrationHitMerger.h:49
LArG4::CalibrationHitMerger::m_outputHits
SG::WriteHandleKey< CaloCalibrationHitContainer > m_outputHits
Definition
CalibrationHitMerger.h:56
LArG4::CalibrationHitMerger::m_inputHits
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_inputHits
Definition
CalibrationHitMerger.h:54
LArG4::CalibrationHitMerger::CalibrationHitMerger
CalibrationHitMerger(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
CalibrationHitMerger.cxx:8
LArG4::CalibrationHitMerger::initialize
virtual StatusCode initialize() override final
Athena algorithm's interface methods.
Definition
CalibrationHitMerger.cxx:13
LArG4::CalibrationHitMerger::execute
virtual StatusCode execute(const EventContext &ctx) override final
Athena Algorithm execute.
Definition
CalibrationHitMerger.cxx:22
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition
AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Generated on
for ATLAS Offline Software by
1.17.0