ATLAS Offline Software
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"
7 #include "CaloEvent/CaloCell.h"
8 #include "Identifier/Identifier.h"
11 
12 //Constructor
13 CaloNoise2Ntuple::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),
26  m_pileupNoise(0),
27  m_tree(nullptr),
28  m_runNumber(0),
29  m_lumiBlock(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 
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 
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();
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) {
159  }
160  else {
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloNoise2Ntuple::m_iCool
int m_iCool
Definition: CaloNoise2Ntuple.h:66
CaloNoise2Ntuple::m_SubHash
int m_SubHash
Definition: CaloNoise2Ntuple.h:67
CaloNoise2Ntuple::m_elecNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_elecNoiseKey
Definition: CaloNoise2Ntuple.h:58
CaloNoise2Ntuple::m_phi
float m_phi
Definition: CaloNoise2Ntuple.h:71
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloNoise2Ntuple::m_lumiBlock
int m_lumiBlock
Definition: CaloNoise2Ntuple.h:80
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCell_Base_ID::is_em_endcap
bool is_em_endcap(const Identifier id) const
test if the id belongs to the EM Endcap
CaloCell_Base_ID::pos_neg
int pos_neg(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
CaloNoise2Ntuple::m_noise
float m_noise
Definition: CaloNoise2Ntuple.h:74
CaloCell.h
CaloCell_Base_ID::calo_sample
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Definition: CaloCell_Base_ID.cxx:141
CaloCell_Base_ID::is_tile
bool is_tile(const Identifier id) const
test if the id belongs to the Tiles
CaloNoise2Ntuple.int
int
Definition: CaloNoise2Ntuple.py:29
CaloNoise::getNoise
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition: CaloNoise.h:34
CaloNoise2Ntuple::m_runNumber
int m_runNumber
Definition: CaloNoise2Ntuple.h:79
CaloGain::TILELOWLOW
@ TILELOWLOW
Definition: CaloGain.h:12
CaloCell_Base_ID::is_hec
bool is_hec(const Identifier id) const
test if the id belongs to the HEC
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
CaloDetDescrElement::eta_raw
float eta_raw() const
cell eta_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:350
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloGain::TILEHIGHHIGH
@ TILEHIGHHIGH
Definition: CaloGain.h:15
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CaloNoise2Ntuple::m_totalNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_totalNoiseKey
Definition: CaloNoise2Ntuple.h:56
CaloCell_Base_ID::is_em
bool is_em(const Identifier id) const
test if the id belongs to LArEM
CaloIdManager
This class initializes the Calo (LAr and Tile) offline identifiers.
Definition: CaloIdManager.h:45
CaloNoise2Ntuple::m_calo_id
const CaloCell_ID * m_calo_id
Definition: CaloNoise2Ntuple.h:53
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCell_Base_ID::is_fcal
bool is_fcal(const Identifier id) const
test if the id belongs to the FCAL - true also for MiniFCAL
CaloNoise2Ntuple::m_OffId
int m_OffId
Definition: CaloNoise2Ntuple.h:69
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
CaloNoise2Ntuple::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: CaloNoise2Ntuple.h:51
CaloNoise2Ntuple::m_layer
int m_layer
Definition: CaloNoise2Ntuple.h:72
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloNoise2Ntuple::execute
virtual StatusCode execute() override
standard Athena-Algorithm method
Definition: CaloNoise2Ntuple.cxx:75
CaloCell_Base_ID::subcalo_cell_hash
IdentifierHash subcalo_cell_hash(const Identifier cellId, int &subCalo) const
create hash id from 'global' cell id
WriteCellNoiseToCool.igain
igain
Definition: WriteCellNoiseToCool.py:338
CaloGain::TILEHIGHLOW
@ TILEHIGHLOW
Definition: CaloGain.h:14
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloNoise2Ntuple::m_eta
float m_eta
Definition: CaloNoise2Ntuple.h:70
CaloNoise2Ntuple::m_treeName
std::string m_treeName
Definition: CaloNoise2Ntuple.h:64
CaloCell_Base_ID::is_em_barrel
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
ReadCellNoiseFromCool.ncell
ncell
Definition: ReadCellNoiseFromCool.py:197
CaloGain::TILELOWHIGH
@ TILELOWHIGH
Definition: CaloGain.h:13
CaloNoise2Ntuple::m_elecNoise
float m_elecNoise
Definition: CaloNoise2Ntuple.h:75
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloNoise.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloNoise2Ntuple::m_tree
TTree * m_tree
Definition: CaloNoise2Ntuple.h:77
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
CaloNoise2Ntuple::m_Hash
int m_Hash
Definition: CaloNoise2Ntuple.h:68
CaloCell_Base_ID::cell_id
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
EventInfo.h
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CaloGain::LARMEDIUMGAIN
@ LARMEDIUMGAIN
Definition: CaloGain.h:18
CaloNoise2Ntuple::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: CaloNoise2Ntuple.cxx:41
CaloNoise2Ntuple::m_Gain
int m_Gain
Definition: CaloNoise2Ntuple.h:73
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloNoise2Ntuple::finalize
virtual StatusCode finalize() override
standard Athena-Algorithm method
Definition: CaloNoise2Ntuple.cxx:181
CaloNoise2Ntuple::~CaloNoise2Ntuple
virtual ~CaloNoise2Ntuple()
Default Destructor.
Definition: CaloNoise2Ntuple.cxx:36
PlotCalibFromCool.ngain
ngain
Definition: PlotCalibFromCool.py:565
CaloNoise2Ntuple::m_pileupNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_pileupNoiseKey
Definition: CaloNoise2Ntuple.h:60
CaloNoise2Ntuple.h
CaloGain::LARLOWGAIN
@ LARLOWGAIN
Definition: CaloGain.h:18
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CaloNoise2Ntuple::stop
virtual StatusCode stop() override
standard Athena-Algorithm method
Definition: CaloNoise2Ntuple.cxx:91
CaloGain.h
CaloNoise2Ntuple::m_pileupNoise
float m_pileupNoise
Definition: CaloNoise2Ntuple.h:76
CaloNoise2Ntuple::CaloNoise2Ntuple
CaloNoise2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: CaloNoise2Ntuple.cxx:13
CaloDetDescrElement::phi_raw
float phi_raw() const
cell phi_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:352
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size
CaloNoise2Ntuple::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloNoise2Ntuple.h:62
Identifier
Definition: IdentifierFieldParser.cxx:14