ATLAS Offline Software
Loading...
Searching...
No Matches
CaloNoise2Ntuple.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 "CaloNoise2Ntuple.h"
8#include "Identifier/Identifier.h"
11
12//Constructor
13CaloNoise2Ntuple::CaloNoise2Ntuple(const std::string& name, ISvcLocator* pSvcLocator):
14 AthAlgorithm(name,pSvcLocator),
15 m_calo_id(nullptr),
16 m_iCool(0),
17 m_SubHash(0),
18 m_Hash(0),
19 m_OffId(0),
20 m_eta(0),
21 m_phi(0),
22 m_layer(0),
23 m_Gain(0),
24 m_noise(0),
25 m_elecNoise(0),
27 m_tree(nullptr),
28 m_runNumber(0),
30{
31 declareProperty("TreeName",m_treeName="mytree");
32}
33
34//__________________________________________________________________________
35//Destructor
37{
38 ATH_MSG_DEBUG ( "CaloNoise2Ntuple destructor called" );
39}
40//__________________________________________________________________________
42{
43 ATH_MSG_DEBUG ("CaloNoise2Ntuple initialize()" );
44
45 ATH_CHECK( m_thistSvc.retrieve() );
46
47 const CaloIdManager* mgr = nullptr;
48 ATH_CHECK( detStore()->retrieve( mgr ) );
49 m_calo_id = mgr->getCaloCell_ID();
50
51 ATH_CHECK( m_totalNoiseKey.initialize() );
52 ATH_CHECK( m_elecNoiseKey.initialize() );
53 ATH_CHECK( m_pileupNoiseKey.initialize() );
54 ATH_CHECK( m_caloMgrKey.initialize() );
55
56 m_tree = new TTree(m_treeName.c_str(),"Calo Noise ntuple");
57 m_tree->Branch("iCool",&m_iCool,"iCool/I");
58 m_tree->Branch("iSubHash",&m_SubHash,"iSubHash/I");
59 m_tree->Branch("iHash",&m_Hash,"iHash/I");
60 m_tree->Branch("iOffId",&m_OffId,"iOffId/I");
61 m_tree->Branch("eta",&m_eta,"eta/F");
62 m_tree->Branch("phi",&m_phi,"phi/F");
63 m_tree->Branch("layer",&m_layer,"layer/I");
64 m_tree->Branch("iGain",&m_Gain,"iGain/I");
65 m_tree->Branch("Noise",&m_noise,"Noise/F");
66 m_tree->Branch("ElecNoise",&m_elecNoise,"ElecNoise/F");
67 m_tree->Branch("PileupNoise",&m_pileupNoise,"PileupNoise/F");
68 ATH_CHECK( m_thistSvc->regTree((std::string("/file1/calonoise/")+m_treeName).c_str(),m_tree));
69
70 ATH_MSG_INFO ( " end of CaloNoise2Ntuple::initialize " );
71 return StatusCode::SUCCESS;
72
73}
74//__________________________________________________________________________
76{
77 ATH_MSG_DEBUG ("CaloNoise2Ntuple execute()" );
78
79 const xAOD::EventInfo* eventInfo = nullptr;
80 if (evtStore()->retrieve(eventInfo).isFailure()) {
81 ATH_MSG_WARNING ( " Cannot access to event info " );
82 return StatusCode::SUCCESS;
83 }
84 m_lumiBlock = eventInfo->lumiBlock();
85 m_runNumber = eventInfo->runNumber();
86
87 return StatusCode::SUCCESS;
88}
89
90//__________________________________________________________________________
92{
93 ATH_MSG_INFO ( " Run Number, lumiblock " << m_runNumber << " " << m_lumiBlock );
94
95 const EventContext& ctx = Gaudi::Hive::currentContext();
100 ATH_CHECK(caloMgrHandle.isValid());
101 const CaloDetDescrManager* calodetdescrmgr = *caloMgrHandle;
102
103 int ncell=m_calo_id->calo_cell_hash_max();
104 ATH_MSG_INFO ( " start loop over Calo cells " << ncell );
105 for (int i=0;i<ncell;i++) {
106 IdentifierHash idHash=i;
107 Identifier id=m_calo_id->cell_id(idHash);
108 const CaloDetDescrElement* calodde = calodetdescrmgr->get_element(id);
109 int subCalo;
110 IdentifierHash idSubHash = m_calo_id->subcalo_cell_hash (idHash, subCalo);
111
112 int iCool=-1;
113 if (m_calo_id->is_em(id)) { // EM calo
114 if (m_calo_id->is_em_barrel(id)) {
115 if (m_calo_id->pos_neg(id) > 0 )
116 iCool=2;
117 else
118 iCool=1;
119 }
120 if (m_calo_id->is_em_endcap(id)) {
121 if (m_calo_id->pos_neg(id) > 0 )
122 iCool=3;
123 else
124 iCool=0;
125 }
126
127 }
128 if (m_calo_id->is_hec(id)) { // HEC
129 iCool=16;
130 }
131 if (m_calo_id->is_fcal(id)) { // Fcal
132 iCool=32;
133 }
134 if (m_calo_id->is_tile(id)) { // Tile
135 iCool=48;
136 }
137 int ii = (int) (idSubHash);
138
139 m_iCool = iCool;
140 m_SubHash = ii;
141 m_Hash = i;
142 m_OffId = (int)(id.get_identifier32().get_compact());
143
144 m_eta = calodde->eta_raw();
145 m_phi = calodde->phi_raw();
146 m_layer = m_calo_id->calo_sample(id);
147
148 int ngain;
149 if (subCalo<3) ngain=3;
150 else ngain=4;
151
152 for (int igain=0;igain<ngain;igain++) {
153
155 if (subCalo<3) {
156 if (igain==0) gain=CaloGain::LARHIGHGAIN;
157 if (igain==1) gain=CaloGain::LARMEDIUMGAIN;
158 if (igain==2) gain=CaloGain::LARLOWGAIN;
159 }
160 else {
161 if (igain==0) gain=CaloGain::TILELOWLOW;
162 if (igain==1) gain=CaloGain::TILELOWHIGH;
163 if (igain==2) gain=CaloGain::TILEHIGHLOW;
164 if (igain==3) gain=CaloGain::TILEHIGHHIGH;
165 }
166 m_Gain = igain;
167
168 m_noise = totalNoise->getNoise(id,gain);
169 m_elecNoise = elecNoise->getNoise(id,gain);
170 m_pileupNoise = pileupNoise->getNoise(id,gain);
171
172 m_tree->Fill();
173
174 } // loop over gains
175
176 } // loop over cells
177
178 return StatusCode::SUCCESS;
179 }
180
182{
183 return StatusCode::SUCCESS;
184}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
This class initializes the Calo (LAr and Tile) offline identifiers.
SG::ReadCondHandleKey< CaloNoise > m_pileupNoiseKey
virtual StatusCode execute() override
standard Athena-Algorithm method
const CaloCell_ID * m_calo_id
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
SG::ReadCondHandleKey< CaloNoise > m_totalNoiseKey
virtual ~CaloNoise2Ntuple()
Default Destructor.
virtual StatusCode stop() override
standard Athena-Algorithm method
virtual StatusCode finalize() override
standard Athena-Algorithm method
ServiceHandle< ITHistSvc > m_thistSvc
std::string m_treeName
virtual StatusCode initialize() override
standard Athena-Algorithm method
SG::ReadCondHandleKey< CaloNoise > m_elecNoiseKey
CaloNoise2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
This is a "hash" representation of an Identifier.
uint32_t lumiBlock() const
The current event's luminosity block number.
uint32_t runNumber() const
The current event's run number.
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ TILELOWLOW
Definition CaloGain.h:12
@ LARLOWGAIN
Definition CaloGain.h:18
@ TILELOWHIGH
Definition CaloGain.h:13
@ TILEHIGHLOW
Definition CaloGain.h:14
@ TILEHIGHHIGH
Definition CaloGain.h:15
@ LARHIGHGAIN
Definition CaloGain.h:18
EventInfo_v1 EventInfo
Definition of the latest event info version.