ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloLocalHadCalib
src
CaloLocalHadCoeffHelper.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
//-----------------------------------------------------------------------
6
// File and Version Information:
7
// $Id: CaloHadDMCoeffHelper.cxx,v 1.2 2009-03-06 14:43:23 pospelov Exp $
8
//
9
// Description: see CaloHadDMCoeffHelper.h
10
//
11
// Environment:
12
// Software developed for the ATLAS Detector at CERN LHC
13
//
14
// Author List:
15
// Gennady Pospelov
16
//
17
//-----------------------------------------------------------------------
18
#include "
CaloLocalHadCalib/CaloLocalHadCoeffHelper.h
"
19
#include <iostream>
20
#include <sstream>
21
#include <cstring>
22
#include <iomanip>
23
#include <format>
24
25
26
#define MAX_BUFFER_LEN 1024
27
28
29
CaloLocalHadCoeffHelper::CaloLocalHadCoeffHelper
()
30
{
31
32
}
33
34
35
CaloLocalHadCoeffHelper::~CaloLocalHadCoeffHelper
()
36
{
37
38
}
39
40
41
// get HadDMArea from area name
42
const
CaloLocalHadCoeff::LocalHadArea
*
CaloLocalHadCoeffHelper::getAreaFromName
(
const
CaloLocalHadCoeff
* coeff,
const
std::string& sname,
int
&indx)
const
43
{
44
for
(
int
i_area=0; i_area<coeff->
getSizeAreaSet
(); i_area++) {
45
if
(sname == coeff->
getArea
(i_area)->
getTitle
()) {
46
indx = i_area;
47
return
coeff->
getArea
(i_area);
48
}
49
}
50
std::cout <<
"CaloLocalHadCoeffHelper::getAreaFromName() -> Error! No such area '"
<< sname <<
"'"
<< std::endl;
51
return
nullptr
;
52
}
53
54
55
56
/* ****************************************************************************
57
To read set of local hadronic coefficients from text file
58
**************************************************************************** */
59
CaloLocalHadCoeff
*
CaloLocalHadCoeffHelper::InitDataFromFile
(
const
char
*filename)
60
{
61
CaloLocalHadCoeff
*data =
new
CaloLocalHadCoeff
();
62
63
char
cLine[
MAX_BUFFER_LEN
];
64
65
// Find the full path to filename
66
std::cout <<
"CaloLocalHadCoeffHelper::InitDataFromFile - Reading file '"
<< filename <<
"'."
<< std::endl;
67
68
std::ifstream fin(filename);
69
if
( !fin ) {
70
std::cout <<
"CaloLocalHadCoeffHelper::InitDataFromFile - Can't open file '"
<< filename <<
"'."
<< std::endl;
71
delete
data;
return
nullptr
;
72
}
73
74
std::string sLine;
75
std::istringstream ist;
76
while
(fin.getline(cLine,
sizeof
(cLine)-1)) {
77
if
( strlen(cLine)==0 || cLine[0] ==
'#'
|| cLine[0] ==
'\n'
)
continue
;
78
79
// parsing area line
80
sLine = cLine;
81
ist.clear(); ist.str(sLine);
82
std::string sdummy, area_title;
83
int
area_indx(0), area_type(0), area_npars(0);
84
if
( !(ist >> sdummy >> area_indx >> area_title >> area_type >> area_npars) ||
85
area_npars < 0 || area_npars > 1000 ) {
86
std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() -> Error! Could not parse line '"
<< cLine <<
"' at p1."
<< std::endl;
87
delete
data;
return
nullptr
;
88
}
89
90
CaloLocalHadCoeff::LocalHadArea
theArea(area_title.c_str(), area_type, area_npars);
91
92
// loop over defined dimensions
93
while
(fin.getline(cLine,
sizeof
(cLine)-1)){
94
if
( cLine[0] ==
'#'
)
continue
;
95
sLine = cLine;
96
if
(sLine.find(
"break"
) != std::string::npos) {
97
break
;
98
}
99
CaloLocalHadCoeff::LocalHadDimension
*dim =
parse_dim
(sLine);
100
if
( !dim ) {
101
std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() ->Error! Could not parse line '"
<< sLine <<
"' at p2a."
<< std::endl;
102
delete
data;
return
nullptr
;
103
}
104
theArea.
addDimension
(*dim);
105
delete
dim;
106
}
107
108
data->addArea(theArea);
109
110
// now reading parameters
111
for
(
int
i_len=0; i_len<theArea.
getLength
(); i_len++){
112
if
(!fin.getline(cLine,
sizeof
(cLine)-1)) {
113
std::cout <<
"panic "
<< std::endl;
114
delete
data;
return
nullptr
;
115
}
116
sLine = cLine;
117
ist.clear(); ist.str(sLine);
118
int
idummy;
119
if
( !(ist >> idummy) ) {
120
std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() -> Warning! Area "
<< theArea.
getTitle
() <<
" doesn't have parameters."
<< std::endl;
121
break
;
122
}
123
if
(idummy != theArea.
getOffset
()+i_len){
124
std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() ->Error! Could not parse line '"
<< cLine <<
"' at p3."
<< std::endl;
125
delete
data;
return
nullptr
;
126
}
127
for
(
int
j=0; j<theArea.
getNdim
(); j++) {
128
if
(!(ist >> idummy)) {
129
std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() -> panic!"
<< std::endl;
130
delete
data;
return
nullptr
;
131
}
132
}
133
CaloLocalHadCoeff::LocalHadCoeff
pars;
134
pars.resize(theArea.
getNpars
(),0.0);
135
for
(
int
j=0; j<theArea.
getNpars
(); j++) {
136
if
( !(ist >> pars[j]) ) {
137
std::cout <<
"CaloLocalHadCoeffHelper::initDataFromFile() ->Error! Could not parse line '"
<< cLine <<
"' at p4."
<< std::endl;
138
std::cout <<
" dmArea.m_title"
<< theArea.
getTitle
() << std::endl;
139
delete
data;
return
nullptr
;
140
}
141
}
142
data->setCoeff(theArea.
getOffset
()+i_len, pars);
143
}
144
}
145
fin.close();
146
147
return
data;
148
}
149
150
151
152
/* ****************************************************************************
153
154
**************************************************************************** */
155
void
CaloLocalHadCoeffHelper::PrintData
(
const
CaloLocalHadCoeff
*data,
const
char
*fname)
156
{
157
std::ofstream
fout
;
158
fout
.open(fname);
159
PrintData
(data,
fout
);
160
fout
.close();
161
}
162
163
164
165
/* ****************************************************************************
166
167
**************************************************************************** */
168
void
CaloLocalHadCoeffHelper::PrintData
(
const
CaloLocalHadCoeff
*data, std::ostream &
fout
)
169
{
170
const
char
*comments =
171
{
172
"# Coefficients for local hadronic calibration .\n\n"
173
};
174
fout
<< comments << std::endl;
175
char
line[1024];
176
177
// loop over areas
178
for
(
int
i_area=0; i_area < data->getSizeAreaSet(); i_area++){
179
const
CaloLocalHadCoeff::LocalHadArea
*
area
= data->getArea(i_area);
180
fout
<<
"area "
<< i_area <<
" "
<<
area
->getTitle() <<
" "
<<
area
->getType() <<
" "
<<
area
->getNpars() << std::endl;
181
for
(
int
i_dim=0; i_dim<
area
->getNdim(); i_dim++){
182
const
CaloLocalHadCoeff::LocalHadDimension
*dim =
area
->getDimension(i_dim);
183
sprintf(line,
"%-6s %2d %6.3f %12.3f "
,dim->getTitle().c_str(), dim->getNbins(), dim->getXmin(), dim->getXmax() );
184
std::string sline(line);
185
sline +=
"flat"
;
186
fout
<< sline;
187
// if( !dim.m_xbins.size() ) {
188
// sline += "flat";
189
// fout << sline;
190
// }else {
191
// sline += "hand";
192
// fout << sline;
193
// for(unsigned int i=0; i<dim.m_xbins.size(); i++){
194
// fout << " " << dim.m_xbins[i];
195
// }
196
// }
197
fout
<< std::endl;
198
}
199
fout
<<
"break"
<< std::endl;
// i.e. no more dimensions
200
201
// now printing the data
202
for
(
int
i_data=0; i_data<
area
->getLength(); i_data++) {
203
int
indx =
area
->getOffset() + i_data;
204
const
CaloLocalHadCoeff::LocalHadCoeff
*pars = data->getCoeff(indx);
205
if
( !pars ) {
206
std::cout <<
"CaloLocalHadCoeffHelper::PrintData() -> Error! Wrong bin number"
<< std::endl;
207
return
;
208
}
209
fout
<< std::format(
"{:>5} "
, indx);
210
std::vector<int > v_dim_indexes;
211
data->bin2indexes(indx, v_dim_indexes);
212
for
(
unsigned
int
i_dim=0; i_dim<v_dim_indexes.size(); i_dim++){
213
fout
<< std::format(
"{:>4} "
, v_dim_indexes[i_dim]);
214
}
215
fout
<<
" "
;
216
for
(
unsigned
int
i_par=0; i_par<(*pars).size(); i_par++) {
217
fout
<< std::format(
"{:>12.6f} "
, (*pars)[i_par]);
218
}
219
fout
<< std::endl;
220
}
221
222
// end of DM area
223
fout
<< std::endl;
224
}
225
// printing title strin
226
}
227
228
229
230
/* **************************************************************************
231
parsing dimension string of type 'ener 8 3.1 6.3'
232
*************************************************************************** */
233
CaloLocalHadCoeff::LocalHadDimension
*
CaloLocalHadCoeffHelper::parse_dim
(std::string &sLine)
234
{
235
CaloLocalHadCoeff::LocalHadDimension
*dim =
nullptr
;
236
std::istringstream ist(sLine.c_str());
237
238
std::string dim_title;
239
std::string stype;
240
int
dim_nbins(0), dim_type(0);
241
float
dim_xmax(0), dim_xmin(0);
242
243
if
( !(ist >> dim_title >> dim_nbins >> dim_xmin >> dim_xmax >> stype) ||
244
dim_nbins <= 0 ||
245
dim_nbins > 1000)
246
{
247
std::cout <<
"CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '"
<< sLine <<
"' at p1."
<< std::endl;
248
return
nullptr
;
249
}
250
251
if
(stype.find(
"flat"
) != std::string::npos) {
252
// equidistant binning
253
dim =
new
CaloLocalHadCoeff::LocalHadDimension
(dim_title.c_str(), dim_type, dim_nbins, dim_xmin, dim_xmax);
254
}
else
if
(stype.find(
"hand"
) != std::string::npos) {
255
// user defined binning
256
std::vector<float> x_bins;
257
float
e;
258
for
(
int
i=0; i<dim_nbins+1; i++) {
259
if
( !(ist >> e) ) {
260
std::cout <<
"CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '"
<< sLine <<
"' at p2."
<< std::endl;
261
return
nullptr
;
262
}
else
{
263
x_bins.push_back(e);
264
}
265
}
266
dim =
new
CaloLocalHadCoeff::LocalHadDimension
(dim_title.c_str(), dim_type, x_bins);
267
}
else
{
268
std::cout <<
"CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '"
<< sLine <<
"' at p3."
<< std::endl;
269
return
nullptr
;
270
}
271
return
dim;
272
}
MAX_BUFFER_LEN
#define MAX_BUFFER_LEN
Definition
CaloDmDescrManager.cxx:33
CaloLocalHadCoeffHelper.h
area
double area(double R)
Definition
ConvertStaveServices.cxx:42
CaloLocalHadCoeffHelper::InitDataFromFile
CaloLocalHadCoeff * InitDataFromFile(const char *fname)
Definition
CaloLocalHadCoeffHelper.cxx:59
CaloLocalHadCoeffHelper::parse_dim
CaloLocalHadCoeff::LocalHadDimension * parse_dim(std::string &sLine)
Definition
CaloLocalHadCoeffHelper.cxx:233
CaloLocalHadCoeffHelper::~CaloLocalHadCoeffHelper
virtual ~CaloLocalHadCoeffHelper()
Definition
CaloLocalHadCoeffHelper.cxx:35
CaloLocalHadCoeffHelper::getAreaFromName
const CaloLocalHadCoeff::LocalHadArea * getAreaFromName(const CaloLocalHadCoeff *coeff, const std::string &sname, int &indx) const
Definition
CaloLocalHadCoeffHelper.cxx:42
CaloLocalHadCoeffHelper::CaloLocalHadCoeffHelper
CaloLocalHadCoeffHelper()
Definition
CaloLocalHadCoeffHelper.cxx:29
CaloLocalHadCoeffHelper::PrintData
void PrintData(const CaloLocalHadCoeff *data, std::ostream &fout)
Definition
CaloLocalHadCoeffHelper.cxx:168
CaloLocalHadCoeff::LocalHadArea
Definition of correction area.
Definition
CaloLocalHadCoeff.h:145
CaloLocalHadCoeff::LocalHadArea::getLength
int getLength() const
return area length
Definition
CaloLocalHadCoeff.h:177
CaloLocalHadCoeff::LocalHadArea::getTitle
const std::string & getTitle() const
return name
Definition
CaloLocalHadCoeff.h:183
CaloLocalHadCoeff::LocalHadArea::getNdim
int getNdim() const
get number of dimensions
Definition
CaloLocalHadCoeff.h:179
CaloLocalHadCoeff::LocalHadArea::getNpars
int getNpars() const
return number of parameters
Definition
CaloLocalHadCoeff.h:173
CaloLocalHadCoeff::LocalHadArea::getOffset
int getOffset() const
return area offset
Definition
CaloLocalHadCoeff.h:175
CaloLocalHadCoeff::LocalHadArea::addDimension
void addDimension(LocalHadDimension &dim)
to add new dimension
Definition
CaloLocalHadCoeff.cxx:135
CaloLocalHadCoeff::LocalHadDimension
Class defines binning for user dimension.
Definition
CaloLocalHadCoeff.h:47
CaloLocalHadCoeff
Hold binned correction data for local hadronic calibration procedure.
Definition
CaloLocalHadCoeff.h:41
CaloLocalHadCoeff::getArea
const LocalHadArea * getArea(int n_area) const
return area
Definition
CaloLocalHadCoeff.cxx:201
CaloLocalHadCoeff::LocalHadCoeff
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
Definition
CaloLocalHadCoeff.h:220
CaloLocalHadCoeff::getSizeAreaSet
int getSizeAreaSet() const
return number of areas defined for this data set
Definition
CaloLocalHadCoeff.h:248
fout
static TFile * fout
Definition
listroot.cxx:40
Generated on
for ATLAS Offline Software by
1.17.0