ATLAS Offline Software
Loading...
Searching...
No Matches
CaloThinCellsInAODAlg.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
3 */
10
13
18{
19 ATH_MSG_INFO("Thinning cells from '"<< m_clusterCntKey.key()<<"' container with "<< m_clusterPtCut <<" MeV and "<< m_clusterEtaCut <<".");
20 if (!m_isMC) ATH_MSG_INFO("Outputs are: CaloCells ('"<< m_caloCellOutputKey.key() <<"'), rawCh ('"<< m_rawChOutputKey.key()<<"') and digits ('"<< m_digitsOutputKey.key() <<"').");
21 else ATH_MSG_INFO("Outputs are: CaloCells ('"<< m_caloCellOutputKey.key() <<"'), rawCh ('"<< m_rawChOutputKey.key()<<"'), digits ('"<< m_digitsOutputKey.key() <<"') and hits ('"<< m_hitsOutputKey.key() <<"')");
22
23 ATH_CHECK(m_cablingKey.initialize());
24
25 // inputs
26 ATH_CHECK(m_clusterCntKey.initialize());
27 ATH_CHECK(m_hitsInputKey.initialize(m_isMC));
28 ATH_CHECK(m_digitsInputKey.initialize());
29 ATH_CHECK(m_rawChInputKey.initialize());
30 ATH_CHECK(m_caloCellInputKey.initialize());
31
32 // outputs
33 ATH_CHECK(m_hitsOutputKey.initialize());
34 ATH_CHECK(m_digitsOutputKey.initialize());
35 ATH_CHECK(m_rawChOutputKey.initialize());
36 ATH_CHECK(m_caloCellOutputKey.initialize());
37
38 // calo id helpers
39 ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
40 ATH_CHECK(detStore()->retrieve(m_caloCellId,"CaloCell_ID"));
41
42 return StatusCode::SUCCESS;
43}
44
49StatusCode CaloThinCellsInAODAlg::execute (const EventContext& ctx) const
50{
51 ATH_MSG_DEBUG("Executing CaloThinCellsInAODAlg...");
52
54 const LArOnOffIdMapping* larCabling=*cablingHdl;
55
56 //Get event inputs from read handles:
61
62 // Write to the new containers
64 ATH_CHECK(outputCells.record(std::make_unique<ConstCaloCellCont_t>(SG::VIEW_ELEMENTS)));
65
67 ATH_CHECK(outputDigits.record(std::make_unique<ConstLArDigitCont_t>(SG::VIEW_ELEMENTS)));
68
70 ATH_CHECK(outputRawChannels.record(std::make_unique<LArRawChannelContainer>()));
71
73 ATH_CHECK(outputHits.record(std::make_unique<LArHitContainer>()));
74
75 auto keepCellSet = std::make_unique<std::bitset<200000> >();
76 size_t nCellsAllClus = 0;
77
78 for (const xAOD::CaloCluster* clus : *clusterContainer){
79
80 // cluster filters
81 if (clus->pt() < m_clusterPtCut) continue;
82 if (std::abs(clus->eta()) > m_clusterEtaCut) continue;
83
84 ATH_MSG_DEBUG("Cluster pt: "<< clus->pt()<<", eta/phi: "<< clus->eta() <<" / "<< clus->phi());
85
86 const CaloClusterCellLink* cellLinks = clus->getCellLinks();
87
88 if (!cellLinks){
89 ATH_MSG_DEBUG( " Cluster without cell links found in collection: " << m_clusterCntKey.key() << " ===> cells cannot be written in AOD as requested ! " );
90 continue;
91 }
92 if (cellLinks->getCellContainerLink().dataID() != m_caloCellInputKey.key()) {
93 ATH_MSG_DEBUG( " Cluster points to cell container " << cellLinks->getCellContainerLink().dataID() << " which is different from the cell container being thinned: " << m_caloCellInputKey.key() << "; cluster skipped.");
94 continue;
95 }
96
97 nCellsAllClus += cellLinks->size();
100 for (; it != end; ++it) {
101 if (it.index() >= inputCellContainer->size()) {
102 ATH_MSG_DEBUG( " Cell index " << it.index() << " is larger than the number of cells in " << m_caloCellInputKey.key() << " (" << inputCellContainer->size() << ")" );
103 continue;
104 }
105 const CaloCell* cell = (*it); //get the caloCells
106
107 Identifier cellId = cell->ID();
108
109 if (m_caloCellId->is_em_barrel(cellId)){ // cells belong to EM Barrel
110 HWIdentifier chhwid = larCabling->createSignalChannelID(cellId);
111 IdentifierHash chOnlHash = m_onlineID->channel_Hash(chhwid);
112
113 if (!keepCellSet->test(chOnlHash)){
114 keepCellSet->set(chOnlHash);
115 outputCells->push_back(cell);
116 }
117 }
118 }//end loop over calo cell links
119 } // end loop over clusters
120 ATH_MSG_DEBUG("\tTotal Copied " << outputCells->size() << " of " << nCellsAllClus << " calo cells, linked to CaloCluster.");
121
122 if (keepCellSet->any()){
123 //start loop over raw channels
124 for(const LArRawChannel& chan : *inputRawChContainer) {
125 const IdentifierHash onlHash=m_onlineID->channel_Hash(chan.hardwareID());
126 if (keepCellSet->test(onlHash)) {
127 outputRawChannels->push_back(chan);
128 }
129 }
130 ATH_MSG_DEBUG("\tCopied " << outputRawChannels->size() << " of " << (*inputRawChContainer).size() << " raw channels.");
131
132 //start loop over digits
133 for (const LArDigit* dig : *inputDigitsContainer) {
134 const IdentifierHash onlHash=m_onlineID->channel_Hash(dig->hardwareID());
135 if (keepCellSet->test(onlHash)) {
136 outputDigits->push_back(dig);
137 }
138 } //end loop over input container
139 ATH_MSG_DEBUG("\tCopied " << outputDigits->size() << " of " << inputDigitsContainer->size() << " digits.");
140 }
141
142 //(MC) start loop over hits container
143 if (m_isMC){
144 if (keepCellSet->any()){
145 SG::ReadHandle<LArHitContainer> inputHitsContainer(m_hitsInputKey,ctx);
146
147 for (const LArHit* hit : *inputHitsContainer) {
148 const HWIdentifier hwid = larCabling->createSignalChannelID(hit->cellID());
149 const IdentifierHash onlHash = m_onlineID->channel_Hash(hwid);
150
151 if (keepCellSet->test(onlHash)) {
152 LArHit* clusHit = new LArHit(hit->cellID(),hit->energy(),hit->time());
153 clusHit->finalize();
154 outputHits->push_back(clusHit);
155 }
156 } //end loop over input container
157
158 ATH_MSG_DEBUG("\tCopied " << outputHits->size() << " of " << inputHitsContainer->size() << " hits.");
159 } // end keepCellSet->any()
160 } // end-if MC
161
162 return StatusCode::SUCCESS;
163}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
Gaudi::Property< float > m_clusterPtCut
SG::ReadHandleKey< LArRawChannelContainer > m_rawChInputKey
SG::ReadHandleKey< LArDigitContainer > m_digitsInputKey
const CaloCell_ID * m_caloCellId
SG::ReadHandleKey< LArHitContainer > m_hitsInputKey
virtual StatusCode initialize() override
Gaudi initialize method.
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
SG::WriteHandleKey< LArRawChannelContainer > m_rawChOutputKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
SG::WriteHandleKey< ConstCaloCellCont_t > m_caloCellOutputKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterCntKey
SG::ReadHandleKey< CaloCellContainer > m_caloCellInputKey
const LArOnlineID * m_onlineID
Gaudi::Property< float > m_clusterEtaCut
SG::WriteHandleKey< LArHitContainer > m_hitsOutputKey
Gaudi::Property< bool > m_isMC
SG::WriteHandleKey< ConstLArDigitCont_t > m_digitsOutputKey
This is a "hash" representation of an Identifier.
Liquid Argon digit base class.
Definition LArDigit.h:25
Class to store hit energy and time in LAr cell from G4 simulation.
Definition LArHit.h:25
void finalize()
The method to be called at the end of event by SD.
Definition LArHit.h:143
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Liquid Argon ROD output object base class.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.