ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TestBeam
TBRec
src
TBNoiseWrite.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// class TBNoiseWrite // Write ROOT Tree with noise in randomly triggered
6
// events
7
//
8
// author: A.Minaenko
9
// date: 08/05/2008
10
11
#include "
TBNoiseWrite.h
"
12
13
#include "
PathResolver/PathResolver.h
"
14
15
#include <TFile.h>
16
#include <TTree.h>
17
18
#include "
CaloEvent/CaloCell.h
"
19
#include "
CaloEvent/CaloCellContainer.h
"
20
21
#include "
TBEvent/TBEventInfo.h
"
22
23
#include <fstream>
24
25
TBNoiseWrite::TBNoiseWrite
(
const
std::string& name,
26
ISvcLocator* pSvcLocator) :
27
AthAlgorithm
(name, pSvcLocator),
28
m_nEvent
(0),
m_nEventRandomTrigger
(0),
m_first
(true),
29
m_cell_id
(0),
30
m_cell_energy
(0),
31
m_caloCellContainerName
(
"AllCalo"
),
32
m_headerTreeName
(
"HeaderTree"
),
33
m_noiseTreeName
(
"NoiseTree"
),
34
m_rootfile_name
(
"tbh6tree_noise.root"
),
35
m_rootfile
(0),
36
m_header_tree
(0),
37
m_tree
(0),
38
//m_calo_id(0),
39
//m_calo_dd_man(0),
40
m_txtFileWithXY
(
"xcryo_ytable.txt"
)
41
{
42
declareProperty
(
"CellContainer"
,
m_caloCellContainerName
);
43
declareProperty
(
"RootFileName"
,
m_rootfile_name
);
44
declareProperty
(
"NoiseTreeName"
,
m_noiseTreeName
);
45
46
m_header
.m_nRun = 0;
47
m_header
.m_beamMom = 0;
48
m_header
.m_xCryo = 0;
49
m_header
.m_yTable = 0;
50
}
51
52
TBNoiseWrite::~TBNoiseWrite
()
53
{ }
54
55
StatusCode
TBNoiseWrite::initialize
()
56
{
57
// Cell vectors
58
m_cell_id
=
new
std::vector<unsigned int>;
59
m_cell_energy
=
new
std::vector<float>;
60
61
// Open file and create TTrees
62
m_rootfile
=
new
TFile(
m_rootfile_name
.data(),
"RECREATE"
);
63
if
(!
m_rootfile
->IsOpen()) {
64
ATH_MSG_FATAL
(
"Cann't open Root file"
);
65
return
StatusCode::FAILURE;
66
}
67
m_header_tree
=
68
new
TTree(
m_headerTreeName
.c_str(),
m_headerTreeName
.c_str());
69
m_tree
=
new
TTree(
m_noiseTreeName
.c_str(),
m_noiseTreeName
.c_str());
70
71
// Define branches
72
// Header
73
m_header_tree
->
74
Branch(
"Header"
,&
m_header
.m_nRun,
"nrun/I:ener/F:xcryo:ytable"
);
75
// Cell parameters
76
m_tree
->Branch(
"cell_id"
, &
m_cell_id
);
77
m_tree
->Branch(
"cell_ener"
, &
m_cell_energy
);
78
79
ATH_MSG_INFO
(
"end of initialize()"
);
80
return
StatusCode::SUCCESS;
81
}
82
83
84
StatusCode
TBNoiseWrite::finalize
()
85
{
86
ATH_MSG_INFO
(
"finalize(): (invoked/random) ("
<<
m_nEvent
87
<<
"/"
<<
m_nEventRandomTrigger
<<
")"
);
88
ATH_MSG_INFO
(
"Print contents of "
<<
m_noiseTreeName
);
89
m_rootfile
->Print();
90
m_rootfile
->Write();
91
m_rootfile
->Close();
92
return
StatusCode::SUCCESS;
93
}
94
95
void
TBNoiseWrite::clear
()
96
{
97
m_cell_id
->clear();
98
m_cell_energy
->clear();
99
}
100
101
StatusCode
TBNoiseWrite::execute
(
const
EventContext&
/*ctx*/
)
102
{
103
m_nEvent
++;
104
ATH_MSG_DEBUG
(
"Executing TBNoiseWrite "
);
105
106
// Retrieve Event Info
107
const
TBEventInfo
* theEventInfo;
108
ATH_CHECK
(
evtStore
()->retrieve(theEventInfo,
"TBEventInfo"
) );
109
unsigned
short
evType = theEventInfo->
getEventType
();
110
ATH_MSG_DEBUG
(
"Event Type found "
<< evType );
111
if
(evType != 3)
return
StatusCode::FAILURE;
112
113
// Do first event initialization (run header filling)
114
if
(
m_first
) {
115
m_first
=
false
;
116
// Fill run header
117
m_header
.m_nRun = theEventInfo->
getRunNum
();
118
m_header
.m_beamMom = theEventInfo->
getBeamMomentum
();
119
// Get xcryo and ytable from a file
120
if
(!this->
getXcryoYtable
(
m_header
.m_xCryo,
m_header
.m_yTable,
121
m_header
.m_beamMom)) {
122
ATH_MSG_ERROR
(
"xCryo and yTable are not found for run "
<<
123
m_header
.m_nRun <<
" in file "
<<
m_txtFileWithXY
);
124
return
StatusCode::FAILURE;
125
}
126
ATH_MSG_INFO
(
"nRun = "
<<
m_header
.m_nRun <<
", beamMomentum = "
127
<<
m_header
.m_beamMom <<
" GeV, CryoX = "
<<
m_header
.m_xCryo
128
<<
", tableY = "
<<
m_header
.m_yTable );
129
m_header_tree
->Fill();
130
}
131
132
this->
clear
();
133
134
// Get cell information
135
const
CaloCellContainer
* cellContainer = 0;
136
ATH_CHECK
(
evtStore
()->retrieve(cellContainer,
m_caloCellContainerName
) );
137
138
// Cell loop
139
for
(
const
CaloCell
* cell : *cellContainer) {
140
unsigned
int
id
= cell->ID().get_identifier32().get_compact();
141
m_cell_id
->push_back(
id
);
142
m_cell_energy
->push_back((
float
)cell->energy());
143
}
144
// Fill the tree
145
m_tree
->Fill();
146
m_nEventRandomTrigger
++;
147
return
StatusCode::SUCCESS;
148
149
}
150
151
StatusCode
TBNoiseWrite::getXcryoYtable
(
float
&
x
,
float
&
y
,
float
&e) {
152
153
ATH_MSG_DEBUG
(
"in getXcryoYtable(float x, float y)"
);
154
155
std::ifstream xyFile;
156
std::string line;
157
std::string filename =
PathResolver::find_file
(
m_txtFileWithXY
,
"DATAPATH"
);
158
xyFile.open(filename.c_str());
159
if
(!xyFile.is_open()) {
160
ATH_MSG_ERROR
(
"File "
<<
m_txtFileWithXY
<<
" fail to open in $DATAPATH"
);
161
return
StatusCode::FAILURE;
162
}
163
164
while
( getline(xyFile, line,
'\n'
) ) {
165
int
run
;
166
std::istringstream buf(line);
167
e = 0;
168
buf >>
run
>>
x
>>
y
>> e;
169
ATH_MSG_DEBUG
(
"run,x,y,e= "
<<
run
<<
" "
<<
x
<<
" "
<<
y
<<
" "
<<e);
170
if
(
run
==
m_header
.m_nRun && xyFile.good())
return
StatusCode::SUCCESS;
171
}
172
173
return
StatusCode::FAILURE;
174
}
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_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CaloCellContainer.h
CaloCell.h
PathResolver.h
TBEventInfo.h
TBNoiseWrite.h
y
#define y
x
#define x
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
CaloCellContainer
Container class for CaloCell.
Definition
CaloCellContainer.h:55
CaloCell
Data object for each calorimeter readout cell.
Definition
CaloCell.h:57
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition
PathResolver.cxx:220
TBEventInfo
Definition
TBEventInfo.h:27
TBEventInfo::getBeamMomentum
float getBeamMomentum() const
Definition
TBEventInfo.h:73
TBEventInfo::getEventType
int getEventType() const
Definition
TBEventInfo.h:71
TBEventInfo::getRunNum
unsigned int getRunNum() const
Definition
TBEventInfo.h:72
TBNoiseWrite::m_txtFileWithXY
std::string m_txtFileWithXY
Text file containing xCryo and yTable.
Definition
TBNoiseWrite.h:64
TBNoiseWrite::clear
void clear()
Definition
TBNoiseWrite.cxx:95
TBNoiseWrite::m_nEvent
int m_nEvent
Definition
TBNoiseWrite.h:34
TBNoiseWrite::m_rootfile
TFile * m_rootfile
Definition
TBNoiseWrite.h:59
TBNoiseWrite::m_noiseTreeName
std::string m_noiseTreeName
Definition
TBNoiseWrite.h:57
TBNoiseWrite::m_cell_id
std::vector< unsigned int > * m_cell_id
Definition
TBNoiseWrite.h:50
TBNoiseWrite::finalize
virtual StatusCode finalize() override
Definition
TBNoiseWrite.cxx:84
TBNoiseWrite::m_caloCellContainerName
std::string m_caloCellContainerName
Definition
TBNoiseWrite.h:55
TBNoiseWrite::m_headerTreeName
std::string m_headerTreeName
Definition
TBNoiseWrite.h:56
TBNoiseWrite::initialize
virtual StatusCode initialize() override
Definition
TBNoiseWrite.cxx:55
TBNoiseWrite::TBNoiseWrite
TBNoiseWrite(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TBNoiseWrite.cxx:25
TBNoiseWrite::m_nEventRandomTrigger
int m_nEventRandomTrigger
Definition
TBNoiseWrite.h:35
TBNoiseWrite::m_tree
TTree * m_tree
Definition
TBNoiseWrite.h:61
TBNoiseWrite::m_rootfile_name
std::string m_rootfile_name
Definition
TBNoiseWrite.h:58
TBNoiseWrite::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
TBNoiseWrite.cxx:101
TBNoiseWrite::getXcryoYtable
StatusCode getXcryoYtable(float &x, float &y, float &eBeam)
Get Xcryo and Ytable from a text file.
Definition
TBNoiseWrite.cxx:151
TBNoiseWrite::~TBNoiseWrite
virtual ~TBNoiseWrite()
Definition
TBNoiseWrite.cxx:52
TBNoiseWrite::m_first
bool m_first
Definition
TBNoiseWrite.h:36
TBNoiseWrite::m_header
NoiseHeader m_header
Definition
TBNoiseWrite.h:45
TBNoiseWrite::m_cell_energy
std::vector< float > * m_cell_energy
Definition
TBNoiseWrite.h:51
TBNoiseWrite::m_header_tree
TTree * m_header_tree
Definition
TBNoiseWrite.h:60
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0