ATLAS Offline Software
Loading...
Searching...
No Matches
CaloLocalHadCoeffHelper Class Reference

#include <CaloLocalHadCoeffHelper.h>

Collaboration diagram for CaloLocalHadCoeffHelper:

Public Types

enum  keys_dim_order {
  DIM_EMFRAC , DIM_SIDE , DIM_ETA , DIM_PHI ,
  DIM_ENER , DIM_LAMBDA , DIM_UNKNOWN
}

Public Member Functions

 CaloLocalHadCoeffHelper ()
virtual ~CaloLocalHadCoeffHelper ()
CaloLocalHadCoeffInitDataFromFile (const char *fname)
void PrintData (const CaloLocalHadCoeff *data, std::ostream &fout)
void PrintData (const CaloLocalHadCoeff *data, const char *fname)
const CaloLocalHadCoeff::LocalHadAreagetAreaFromName (const CaloLocalHadCoeff *coeff, const std::string &sname, int &indx) const

Private Member Functions

CaloLocalHadCoeff::LocalHadDimensionparse_dim (std::string &sLine)

Detailed Description

Definition at line 14 of file CaloLocalHadCoeffHelper.h.

Member Enumeration Documentation

◆ keys_dim_order

Constructor & Destructor Documentation

◆ CaloLocalHadCoeffHelper()

CaloLocalHadCoeffHelper::CaloLocalHadCoeffHelper ( )

Definition at line 29 of file CaloLocalHadCoeffHelper.cxx.

30{
31
32}

◆ ~CaloLocalHadCoeffHelper()

CaloLocalHadCoeffHelper::~CaloLocalHadCoeffHelper ( )
virtual

Definition at line 35 of file CaloLocalHadCoeffHelper.cxx.

36{
37
38}

Member Function Documentation

◆ getAreaFromName()

const CaloLocalHadCoeff::LocalHadArea * CaloLocalHadCoeffHelper::getAreaFromName ( const CaloLocalHadCoeff * coeff,
const std::string & sname,
int & indx ) const

Definition at line 42 of file CaloLocalHadCoeffHelper.cxx.

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}
const std::string & getTitle() const
return name
const LocalHadArea * getArea(int n_area) const
return area
int getSizeAreaSet() const
return number of areas defined for this data set

◆ InitDataFromFile()

CaloLocalHadCoeff * CaloLocalHadCoeffHelper::InitDataFromFile ( const char * fname)

Definition at line 59 of file CaloLocalHadCoeffHelper.cxx.

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 }
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}
#define MAX_BUFFER_LEN
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
CaloLocalHadCoeff::LocalHadDimension * parse_dim(std::string &sLine)
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.

◆ parse_dim()

CaloLocalHadCoeff::LocalHadDimension * CaloLocalHadCoeffHelper::parse_dim ( std::string & sLine)
private

Definition at line 234 of file CaloLocalHadCoeffHelper.cxx.

235{
236 CaloLocalHadCoeff::LocalHadDimension *dim = nullptr;
237 std::istringstream ist(sLine.c_str());
238
239 std::string dim_title;
240 std::string stype;
241 int dim_nbins(0), dim_type(0);
242 float dim_xmax(0), dim_xmin(0);
243
244 if( !(ist >> dim_title >> dim_nbins >> dim_xmin >> dim_xmax >> stype) ||
245 dim_nbins <= 0 ||
246 dim_nbins > 1000)
247 {
248 std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at p1." << std::endl;
249 return nullptr;
250 }
251
252 if(stype.find("flat") != std::string::npos) {
253 // equidistant binning
254 dim = new CaloLocalHadCoeff::LocalHadDimension(dim_title.c_str(), dim_type, dim_nbins, dim_xmin, dim_xmax);
255 }else if(stype.find("hand") != std::string::npos) {
256 // user defined binning
257 std::vector<float> x_bins;
258 float e;
259 for(int i=0; i<dim_nbins+1; i++) {
260 if( !(ist >> e) ) {
261 std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at p2." << std::endl;
262 return nullptr;
263 }else{
264 x_bins.push_back(e);
265 }
266 }
267 dim = new CaloLocalHadCoeff::LocalHadDimension(dim_title.c_str(), dim_type, x_bins);
268 }else{
269 std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at p3." << std::endl;
270 return nullptr;
271 }
272 return dim;
273}

◆ PrintData() [1/2]

void CaloLocalHadCoeffHelper::PrintData ( const CaloLocalHadCoeff * data,
const char * fname )

Definition at line 155 of file CaloLocalHadCoeffHelper.cxx.

156{
157 std::ofstream fout;
158 fout.open(fname);
160 fout.close();
161}
void PrintData(const CaloLocalHadCoeff *data, std::ostream &fout)
static TFile * fout
Definition listroot.cxx:40

◆ PrintData() [2/2]

void CaloLocalHadCoeffHelper::PrintData ( const CaloLocalHadCoeff * data,
std::ostream & fout )

Definition at line 168 of file CaloLocalHadCoeffHelper.cxx.

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 boost::io::ios_base_all_saver foutsave (fout);
210 fout << std::setw(5) << indx << " ";
211 std::vector<int > v_dim_indexes;
212 data->bin2indexes(indx, v_dim_indexes);
213 for(unsigned int i_dim=0; i_dim<v_dim_indexes.size(); i_dim++){
214 fout << std::setw(4) << v_dim_indexes[i_dim] << " ";
215 }
216 fout << " ";
217 for(unsigned int i_par=0; i_par<(*pars).size(); i_par++) {
218 fout << std::fixed << std::setprecision(6) << std::setw(12) << (*pars)[i_par] << " ";
219 }
220 fout << std::endl;
221 }
222
223 // end of DM area
224 fout << std::endl;
225 }
226 // printing title strin
227}
double area(double R)

The documentation for this class was generated from the following files: