ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TestBeam
TBRec
src
TBCellNoiseCorrection.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
TBCellNoiseCorrection.h
"
6
7
#include "CaloDetDescr/CaloDetDescrElement.h"
8
#include "
CaloEvent/CaloCell.h
"
9
#include "
AthenaKernel/RNGWrapper.h
"
10
11
#include "
PathResolver/PathResolver.h
"
12
13
#include "CLHEP/Random/RandFlat.h"
14
15
#include <TFile.h>
16
#include <TChain.h>
17
18
19
using
CLHEP::RandFlat;
20
21
22
TBCellNoiseCorrection::TBCellNoiseCorrection
(
const
std::string&
type
,
23
const
std::string& name,
24
const
IInterface* parent)
25
:
CaloCellCorrection
(
type
, name, parent),
26
m_noise_correction
(false),
m_noise_file
(),
27
m_engine
(0),
28
m_tree
(0),
m_xcryo
(0.),
m_ytable
(0.),
m_energy
(-1.),
m_cell_id
(0),
m_cell_energy
(0),
m_entries
(0)
29
//m_myevtnum(-1)
30
{
31
declareInterface<CaloCellCorrection>(
this
);
32
declareProperty
(
"NoiseFile"
,
m_noise_file
);
33
declareProperty
(
"NoiseAdd"
,
m_noise_correction
);
34
declareProperty
(
"NoiseX"
,
m_xcryo
);
35
declareProperty
(
"NoiseY"
,
m_ytable
);
36
declareProperty
(
"NoiseE"
,
m_energy
);
37
}
38
39
// Desctructor
40
41
TBCellNoiseCorrection::~TBCellNoiseCorrection
()
42
{ }
43
44
45
StatusCode
TBCellNoiseCorrection::initialize
()
46
{
47
ATH_MSG_DEBUG
(
" TBCellNoiseCorrection initialization "
);
48
49
// RandomNumbers
50
ATH_CHECK
(
m_rndmSvc
.retrieve() );
51
m_engine
=
m_rndmSvc
->getEngine(
this
,
"TB_NOISE"
);
52
53
if
(
m_energy
> 0.) {
// Do we have run parameters (x,y,energy) ?
54
ATH_MSG_DEBUG
(
" Trying to patch the noise file name "
);
55
std::string fname =
PathResolver::find_file
(
"xcryo_ytable.txt"
,
"DATAPATH"
);
56
std::ifstream xfile;
57
xfile.open(fname.c_str());
58
if
(!xfile.good()){
59
ATH_MSG_FATAL
(
"Could not open file xcryo_ytable.txt"
);
60
return
StatusCode::FAILURE;
61
}
62
int
runnumber
= 0;
63
float
x
,
y
,en=-1;
64
std::string line;
65
while
(getline(xfile, line,
'\n'
)) {
66
std::istringstream buf(line);
67
buf >>
runnumber
>>
x
>>
y
>> en;
68
if
(en < 0. || !(
x
==
m_xcryo
&&
y
==
m_ytable
&& en ==
m_energy
))
continue
;
69
break
;
70
}
71
if
(en < 0.) {
72
ATH_MSG_FATAL
(
" Do not have X: "
<<
m_xcryo
<<
" Y: "
<<
m_ytable
<<
" E: "
<<
m_energy
<<
" in xcryo_ytable.txt"
);
73
return
StatusCode::FAILURE;
74
}
75
// we have run number - let's change the file name (and take only one):
76
ATH_MSG_DEBUG
(
"Found run number: "
<<
runnumber
);
77
unsigned
pos =
m_noise_file
[0].find_last_of(
"0123456789"
);
78
std::ostringstream buf;
79
buf<<
runnumber
;
80
m_noise_file
[0].replace(pos-3,4,buf.str());
81
ATH_MSG_DEBUG
(
"patched name: "
<<
m_noise_file
[0].c_str() );
82
}
83
84
// Open file and get Tree
85
/*
86
m_root = new TFile(m_noise_file.c_str(),"READ");
87
if(!m_root->IsOpen()){
88
ATH_MSG_FATAL( "Could not open root file: "<<m_noise_file );
89
return StatusCode::FAILURE;
90
}
91
m_tree = (TTree*) m_root->Get("NoiseTree");
92
if(!m_tree) {
93
ATH_MSG_FATAL( "No NoiseTree in root file: "<<m_noise_file );
94
return StatusCode::FAILURE;
95
}
96
*/
97
// Make a chain
98
m_tree
=
new
TChain(
"NoiseTree"
);
99
for
(
unsigned
int
l=0; l<
m_noise_file
.size(); ++l) {
100
m_tree
->AddFile(
m_noise_file
[l].c_str());
101
}
102
m_entries
=
m_tree
->GetEntries();
103
if
(
m_entries
< 100) {
104
ATH_MSG_FATAL
(
"Noise chain has less then 100 events !!!!"
);
105
return
StatusCode::FAILURE;
106
}
107
m_tree
->SetBranchAddress(
"cell_id"
, &
m_cell_id
);
108
m_tree
->SetBranchAddress(
"cell_ener"
, &
m_cell_energy
);
109
ATH_MSG_DEBUG
(
" Got NoiseTree with "
<<
m_entries
<<
" entries"
);
110
112
ServiceHandle<IIncidentSvc>
pIncSvc(
"IncidentSvc"
, name());
113
ATH_CHECK
( pIncSvc.retrieve() );
114
115
//start listening to "BeginEvent"
116
const
int
PRIORITY = 100;
117
pIncSvc->addListener(
this
,
"BeginEvent"
, PRIORITY);
118
119
ATH_MSG_DEBUG
(
" TBCellNoiseCorrection initialization finished"
);
120
121
return
StatusCode::SUCCESS;
122
}
123
124
StatusCode
TBCellNoiseCorrection::finalize
()
125
{
126
// m_root->Close();
127
// m_root = NULL;
128
if
(
m_tree
)
m_tree
->Delete() ;
129
// m_cell_id = NULL;
130
// m_cell_energy = NULL;
131
132
return
StatusCode::SUCCESS;
133
}
134
// MakeCorrection: This is called with a pointer to the Cell Object.
135
136
void
TBCellNoiseCorrection::MakeCorrection
(
CaloCell
* theCell,
137
const
EventContext&
/*ctx*/
)
const
138
{
139
140
// const CaloDetDescrElement* elt = theCell->caloDDE();
141
142
if
(
m_noise_correction
) {
143
unsigned
int
cid = theCell->
ID
().
get_identifier32
().
get_compact
();
144
double
e = theCell->
energy
();
145
unsigned
int
size
=
m_cell_id
->size();
146
unsigned
int
i;
147
// removing this, should use the BadChannel now
148
// if(cid == 810049536) e = 0.; // Not working cell in data
149
for
(i = 0; i <
size
; ++i) {
150
if
(std::as_const(
m_cell_id
)->at(i) == cid) {
151
e += std::as_const(
m_cell_energy
)->at(i);
152
break
;
153
}
154
}
155
if
(i ==
size
) {
156
ATH_MSG_ERROR
(
"Could not find a noise value for cell: "
<<std::hex<<cid<<std::dec );
157
}
158
159
theCell->
setEnergy
(e);
160
}
161
162
}
163
164
void
TBCellNoiseCorrection::handle
(
const
Incident &inc) {
165
ATH_MSG_DEBUG
(
" Handle BeginEvent "
);
166
167
if
( inc.type() ==
"BeginEvent"
) {
168
m_engine
->setSeed (
"TBCellNoseCorrection"
, inc.context());
169
unsigned
int
random = int(RandFlat::shoot(
m_engine
->getEngine (inc.context()), 0.,
m_entries
-1.));
170
ATH_MSG_DEBUG
(
"Reading noise event: "
<<random );
171
m_tree
->GetEntry(random);
172
unsigned
int
size
=
m_cell_id
->size();
173
unsigned
int
sizee =
m_cell_energy
->size();
174
if
(
size
!= sizee) {
175
ATH_MSG_ERROR
(
"Not equal size of noise vectors !!!! Something wrong !!!"
);
176
}
177
}
178
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CaloCell.h
PathResolver.h
RNGWrapper.h
size
size_t size() const
Number of registered mappings.
TBCellNoiseCorrection.h
y
#define y
x
#define x
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
CaloCellCorrection
Definition
CaloCellCorrection.h:46
CaloCell
Data object for each calorimeter readout cell.
Definition
CaloCell.h:57
CaloCell::energy
double energy() const
get energy (data member)
Definition
CaloCell.h:327
CaloCell::setEnergy
virtual void setEnergy(float energy)
set energy
Definition
CaloCell.h:472
CaloCell::ID
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition
CaloCell.h:295
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition
Identifier32.h:47
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition
PathResolver.cxx:220
ServiceHandle
Definition
ClusterMakerTool.h:36
TBCellNoiseCorrection::~TBCellNoiseCorrection
virtual ~TBCellNoiseCorrection()
Definition
TBCellNoiseCorrection.cxx:41
TBCellNoiseCorrection::m_noise_file
std::vector< std::string > m_noise_file
Definition
TBCellNoiseCorrection.h:46
TBCellNoiseCorrection::m_noise_correction
bool m_noise_correction
Definition
TBCellNoiseCorrection.h:45
TBCellNoiseCorrection::m_engine
ATHRNG::RNGWrapper * m_engine
Definition
TBCellNoiseCorrection.h:51
TBCellNoiseCorrection::m_tree
TChain * m_tree
Definition
TBCellNoiseCorrection.h:53
TBCellNoiseCorrection::MakeCorrection
void MakeCorrection(CaloCell *theCell, const EventContext &ctx) const override
Definition
TBCellNoiseCorrection.cxx:136
TBCellNoiseCorrection::TBCellNoiseCorrection
TBCellNoiseCorrection(const std::string &type, const std::string &name, const IInterface *parent)
Definition
TBCellNoiseCorrection.cxx:22
TBCellNoiseCorrection::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition
TBCellNoiseCorrection.h:50
TBCellNoiseCorrection::m_cell_energy
std::vector< float > * m_cell_energy
Definition
TBCellNoiseCorrection.h:59
TBCellNoiseCorrection::finalize
virtual StatusCode finalize() override
Definition
TBCellNoiseCorrection.cxx:124
TBCellNoiseCorrection::m_cell_id
std::vector< unsigned int > * m_cell_id
Definition
TBCellNoiseCorrection.h:58
TBCellNoiseCorrection::handle
virtual void handle(const Incident &) override
Definition
TBCellNoiseCorrection.cxx:164
TBCellNoiseCorrection::m_ytable
float m_ytable
Definition
TBCellNoiseCorrection.h:55
TBCellNoiseCorrection::initialize
virtual StatusCode initialize() override
Definition
TBCellNoiseCorrection.cxx:45
TBCellNoiseCorrection::m_energy
float m_energy
Definition
TBCellNoiseCorrection.h:56
TBCellNoiseCorrection::m_entries
unsigned int m_entries
Definition
TBCellNoiseCorrection.h:60
TBCellNoiseCorrection::m_xcryo
float m_xcryo
Definition
TBCellNoiseCorrection.h:54
runnumber
static std::vector< uint32_t > runnumber
Definition
iLumiCalc.h:37
type
Generated on
for ATLAS Offline Software by
1.17.0