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

#include <CaloLCCoeffHelper.h>

Collaboration diagram for CaloLCCoeffHelper:

Public Member Functions

 CaloLCCoeffHelper ()
virtual ~CaloLCCoeffHelper ()

Static Public Member Functions

static std::optional< CaloLocalHadCoeffInitDataFromFile (const char *fname)
static void PrintData (CaloLocalHadCoeff *m_data, std::ostream &fout)
static void PrintData (CaloLocalHadCoeff *m_data, const char *fname)
static const CaloLocalHadCoeff::LocalHadAreagetAreaFromName (const CaloLocalHadCoeff *m_coeff, const std::string &sname, int &m_indx)
static bool Interpolate (const CaloLocalHadCoeff *m_data, const unsigned int n_area, std::vector< float > &x, CaloLocalHadCoeff::LocalHadCoeff &pars, const std::vector< int > &dim, double xfit=0.)
static CaloLocalHadDefs::LocalHadDimensionId getDimensionId (const std::string &dimensionName)

Static Private Member Functions

static std::optional< CaloLocalHadCoeff::LocalHadDimensionparse_dim (const std::string &sLine)

Detailed Description

Definition at line 15 of file CaloLCCoeffHelper.h.

Constructor & Destructor Documentation

◆ CaloLCCoeffHelper()

CaloLCCoeffHelper::CaloLCCoeffHelper ( )
default

◆ ~CaloLCCoeffHelper()

CaloLCCoeffHelper::~CaloLCCoeffHelper ( )
virtualdefault

Member Function Documentation

◆ getAreaFromName()

const CaloLocalHadCoeff::LocalHadArea * CaloLCCoeffHelper::getAreaFromName ( const CaloLocalHadCoeff * m_coeff,
const std::string & sname,
int & m_indx )
static

Definition at line 39 of file CaloLCCoeffHelper.cxx.

40{
41 for(int i_area=0; i_area<coeff->getSizeAreaSet(); i_area++) {
42 if(sname == coeff->getArea(i_area)->getTitle()) {
43 indx = i_area;
44 return coeff->getArea(i_area);
45 }
46 }
47 std::cout << "CaloLCCoeffHelper::getAreaFromName() -> Error! No such area '" << sname << "'" << std::endl;
48 return nullptr;
49}
constexpr double coeff(const unsigned l, const unsigned k)
Calculates the n-th coefficient of the legendre polynomial series.

◆ getDimensionId()

CaloLocalHadDefs::LocalHadDimensionId CaloLCCoeffHelper::getDimensionId ( const std::string & dimensionName)
inlinestatic

Definition at line 32 of file CaloLCCoeffHelper.h.

33 {
34 if(dimensionName == "DIMC_SIDE") {
36 }else if(dimensionName == "DIMC_ETA") {
38 }else if(dimensionName == "DIMC_PHI") {
40 }else if(dimensionName == "DIMC_ENER") {
42 }else if(dimensionName == "DIMC_EDENS") {
44 }else if(dimensionName == "DIMC_LAMBDA") {
46
47 }else if(dimensionName == "DIMW_SIDE") {
49 }else if(dimensionName == "DIMW_ETA") {
51 }else if(dimensionName == "DIMW_PHI") {
53 }else if(dimensionName == "DIMW_ENER") {
55 }else if(dimensionName == "DIMW_EDENS") {
57
58 }else if(dimensionName == "DIMO_SIDE") {
60 }else if(dimensionName == "DIMO_PHI") {
62 }else if(dimensionName == "DIMO_ENER") {
64 }else if(dimensionName == "DIMO_ETA") {
66 }else if(dimensionName == "DIMO_LAMBDA") {
68
69 }else if(dimensionName == "DIMD_EMFRAC") {
71 }else if(dimensionName == "DIMD_SIDE") {
73 }else if(dimensionName == "DIMD_ETA") {
75 }else if(dimensionName == "DIMD_PHI") {
77 }else if(dimensionName == "DIMD_ENER") {
79 }else if(dimensionName == "DIMD_LAMBDA") {
81
82 }else{
83 //std::cout << " CaloUtils/CaloLocalHadCoeffHelper/getDimensionId() -> Error! Unknown dimension '" << dimensionName << "'" << std::endl;
85 }
86 }

◆ InitDataFromFile()

std::optional< CaloLocalHadCoeff > CaloLCCoeffHelper::InitDataFromFile ( const char * fname)
static

Definition at line 56 of file CaloLCCoeffHelper.cxx.

57{
58 std::optional<CaloLocalHadCoeff> data=std::make_optional<CaloLocalHadCoeff>();
59
60 char cLine[1024];
61
62 // Find the full path to filename
63 std::cout << "CaloLCCoeffHelper::InitDataFromFile - Reading file '" << filename << "'." << std::endl;
64
65 std::ifstream fin(filename);
66 if ( !fin ) {
67 std::cout << "CaloLCCoeffHelper::InitDataFromFile - Can't open file '" << filename << "'." << std::endl;
68 return std::nullopt;
69 }
70
71 std::string sLine;
72 std::istringstream ist;
73 while(fin.getline(cLine,sizeof(cLine)-1)) {
74 if( strlen(cLine)==0 || cLine[0] == '#' || cLine[0] == '\n') continue;
75
76 // parsing area line
77 sLine = cLine;
78 ist.clear(); ist.str(sLine);
79 std::string sdummy, area_title;
80 int area_indx(0), area_type(0), area_npars(0);
81 if( !(ist >> sdummy >> area_indx >> area_title >> area_type >> area_npars) ||
82 area_npars < 0 || area_npars > 1000 ) {
83 std::cout << "CaloLCCoeffHelper::initDataFromFile() -> Error! Could not parse line '" << cLine << "' at p1." << std::endl;
84 return std::nullopt;
85 }
86
87 CaloLocalHadCoeff::LocalHadArea theArea(area_title.c_str(), area_type, area_npars);
88
89 // loop over defined dimensions
90 while(fin.getline(cLine,sizeof(cLine)-1)){
91 if( cLine[0] == '#') continue;
92 sLine = cLine;
93 if(sLine.find("break") != std::string::npos) {
94 break;
95 }
96 auto dim = parse_dim(sLine);
97 if( !dim ) {
98 std::cout << "CaloLCCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << sLine << "' at p2a." << std::endl;
99 return std::nullopt;
100 }
101 theArea.addDimension(*dim);
102 }
103 data->addArea(theArea);
104
105 // now reading parameters
106 for(int i_len=0; i_len<theArea.getLength(); i_len++){
107 if(!fin.getline(cLine,sizeof(cLine)-1)) {
108 std::cout << "panic " << std::endl;
109 return std::nullopt;
110 }
111 sLine = cLine;
112 ist.clear(); ist.str(sLine);
113 int idummy;
114 if( !(ist >> idummy) ) {
115 std::cout << "CaloLCCoeffHelper::initDataFromFile() -> Warning! Area " << theArea.getTitle() << " doesn't have parameters." << std::endl;
116 break;
117 }
118 if(idummy != theArea.getOffset()+i_len){
119 std::cout << "CaloLCCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p3." << std::endl;
120 return std::nullopt;
121 }
122 for(int j=0; j<theArea.getNdim(); j++) {
123 if(!(ist >> idummy)) {
124 std::cout << "CaloLCCoeffHelper::initDataFromFile() -> panic!" << std::endl;
125 return std::nullopt;
126 }
127 }
129 pars.resize(theArea.getNpars(),0.0);
130 for(int j=0; j<theArea.getNpars(); j++) {
131 if( !(ist >> pars[j]) ) {
132 std::cout << "CaloLCCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p4." << std::endl;
133 std::cout << " dmArea.m_title" << theArea.getTitle() << std::endl;
134 return std::nullopt;
135 }
136 }
137 data->setCoeff(theArea.getOffset()+i_len, pars);
138 }
139 }
140 fin.close();
141
142 return data;
143}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static std::optional< CaloLocalHadCoeff::LocalHadDimension > parse_dim(const std::string &sLine)
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.

◆ Interpolate()

bool CaloLCCoeffHelper::Interpolate ( const CaloLocalHadCoeff * m_data,
const unsigned int n_area,
std::vector< float > & x,
CaloLocalHadCoeff::LocalHadCoeff & pars,
const std::vector< int > & dim,
double xfit = 0. )
static

Definition at line 231 of file CaloLCCoeffHelper.cxx.

234{
235 // Sanity check
236 if( n_area >= (unsigned int)data->getSizeAreaSet()) return false;
237 // We are not extrapolator
238 if(!data->isFilled(data->getBin(n_area,x))) {
239 return false;
240 }
241
242 const CaloLocalHadCoeff::LocalHadArea *area = data->getArea(n_area);
243 unsigned int ndim;
244 if(dim.empty()) {
245 std::cout << "CaloLCCoeffHelper::Interpolate() -> Error! Empty vector of dimensions to interpolate trough." << std::endl;
246 return false;
247 } else if ( (int)dim.size() > area->getNdim()){
248 std::cout << "CaloLCCoeffHelper::Interpolate() -> Error! Vector of dimensions to interpolate exceed defined in area." << std::endl;
249 return false;
250 } else ndim=dim.size();
251 unsigned int ncorners = (1<<ndim);
252
253 std::vector<double > vXadj(ndim);
254 std::vector<unsigned int > vgbins(ncorners);
255 std::vector<double > vWeights(ncorners);
256 std::vector<int> ebindx;
257 std::vector<int> bx;
258 unsigned int nip;
259
260 switch (area->getType()) {
262 nip = data->getCoeff(area->getOffset()+1)->size();
263 if(area->getType() == CaloLocalHadDefs::AREA_DMFIT) {
264 nip = 1;
265 } else {
266 nip = data->getCoeff(area->getOffset()+1)->size();
267 }
268 pars.resize(nip);
269 for(unsigned int ip=0; ip<nip; ++ip) {
270 bool isa = data->getInterpArrays(n_area,dim,x,vXadj,vgbins);
271 if(! isa) {
272 std::cout<<"No arrays for x: ";
273 for(unsigned int l=0; l<x.size(); ++l) std::cout<<x[l]<<" ";
274 std::cout<<std::endl;
275 return false;
276 }
277 for(unsigned int i_len=0; i_len<ncorners; ++i_len){
278 // Check for empty bin here TODO !!!!!
279 if(data->isFilled(vgbins[i_len])) {
281 data->getCoeff(vgbins[i_len]);
282 if(area->getType() == CaloLocalHadDefs::AREA_DMFIT) {
283 // std::cout << "xxx " << xfit << " " << (*pars)[0] << " " << (*pars)[1] << " " << (*pars)[2] << std::endl;
284 vWeights[i_len] = (*lpars)[0] + (*lpars)[1]*pow(xfit,(*lpars)[2]);
285 } else {
286 vWeights[i_len] = (*lpars)[ip];
287 }
288 // std::cout<<vWeights[i_len]<<" ";
289 } else {
290 // std::cout<<x[0]<<" "<<x[1]<<" : "<<vXadj[0]<<" "<<vXadj[1]<<" | ";
291 // if empty, put inside average over all neighbours in our list
292 vWeights[i_len] = 0.;
293 unsigned int icount = 0;
294 data->bin2indexes(vgbins[i_len],ebindx);
295 // for(unsigned int blen=0; blen<ebindx.size(); ++blen) { std::cout<<ebindx[blen]<<" "; }
296 //std::cout<<" | ";
297 for(unsigned int blen=0; blen<ncorners; ++blen){
298 if(blen == i_len) continue;
299 if(!data->isFilled(vgbins[blen])){
300 data->bin2indexes(vgbins[i_len],bx);
301 //for(unsigned int l=0; l<bx.size(); ++l) { std::cout<<bx[l]<<" "; }
302 //std::cout<<" nf| ";
303 continue;
304 }
305 if(data->isNeighbour(vgbins[blen], ebindx)) {
307 data->getCoeff(vgbins[blen]);
308 if(area->getType() == CaloLocalHadDefs::AREA_DMFIT) {
309 vWeights[i_len] = (*lpars)[0] + (*lpars)[1]*pow(xfit,(*lpars)[2]);
310 } else {
311 vWeights[i_len] += (*lpars)[ip];
312 }
313 ++icount;
314 }
315 }
316 if(icount) {
317 //std::cout<<"i";
318 vWeights[i_len] /= icount;
319 }
320 //std::cout<<vWeights[i_len]<<"a ";
321 //std::cout<<std::endl;
322 }
323 }
324 pars[ip] = CaloWeightInterpolator::getWeight(vWeights,vXadj);
325 }
326 return true;
327 }
328 default: {
329 std::cout<<"Not implemented yet for this Area type !!!"<<std::endl;
330 return false;
331 }
332 }
333 // Should not get here, but syntax needs this
334 return false;
335}
double area(double R)
#define x
constexpr int pow(int base, int exp) noexcept
l
Printing final latex table to .tex output file.
static double getWeight(std::vector< double > &w, std::vector< double > &x)

◆ parse_dim()

std::optional< CaloLocalHadCoeff::LocalHadDimension > CaloLCCoeffHelper::parse_dim ( const std::string & sLine)
staticprivate

Definition at line 342 of file CaloLCCoeffHelper.cxx.

343{
344 std::optional<CaloLocalHadCoeff::LocalHadDimension> dim{std::nullopt};
345 std::istringstream ist(sLine.c_str());
346
347 std::string dim_title;
348 std::string stype;
349 int dim_nbins(0), dim_type(0);
350 float dim_xmax(0), dim_xmin(0);
351
352 if( !(ist >> dim_title >> dim_nbins >> dim_xmin >> dim_xmax >> stype) ){
353 std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at p1." << std::endl;
354 return std::nullopt;
355 }
356
357 // Check nbins for reasonableness --- prevents a coverity warning.
358 if (dim_nbins < 1)
359 dim_nbins = 1;
360 else if (dim_nbins > 10000)
361 dim_nbins = 10000;
362
363 if(stype.find("flat") != std::string::npos) {
364 // equidistant binning
365 dim.emplace(dim_title.c_str(), dim_type, dim_nbins, dim_xmin, dim_xmax);
366 }else if(stype.find("hand") != std::string::npos) {
367 // user defined binning
368 std::vector<float> x_bins;
369 float e;
370 for(int i=0; i<dim_nbins+1; i++) {
371 if( !(ist >> e) ) {
372 std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at p2." << std::endl;
373 return std::nullopt;
374 }else{
375 x_bins.push_back(e);
376 }
377 }
378 dim.emplace(dim_title.c_str(), dim_type, x_bins);
379 }else{
380 std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at p3." << std::endl;
381 return std::nullopt;
382 }
383 return dim;
384}

◆ PrintData() [1/2]

void CaloLCCoeffHelper::PrintData ( CaloLocalHadCoeff * m_data,
const char * fname )
static

Definition at line 150 of file CaloLCCoeffHelper.cxx.

151{
152 std::ofstream fout;
153 fout.open(fname);
155 fout.close();
156}
static void PrintData(CaloLocalHadCoeff *m_data, std::ostream &fout)
static TFile * fout
Definition listroot.cxx:40

◆ PrintData() [2/2]

void CaloLCCoeffHelper::PrintData ( CaloLocalHadCoeff * m_data,
std::ostream & fout )
static

Definition at line 163 of file CaloLCCoeffHelper.cxx.

164{
165 boost::io::ios_base_all_saver ifs (fout);
166 const char *comments =
167 {
168 "# Coefficients for local hadronic calibration .\n\n"
169 };
170 fout << comments << std::endl;
171 char line[1024];
172
173 // loop over areas
174 for(int i_area=0; i_area < data->getSizeAreaSet(); i_area++){
175 const CaloLocalHadCoeff::LocalHadArea *area = data->getArea(i_area);
176 fout << "area " << i_area << " " << area->getTitle() << " " << area->getType() << " " << area->getNpars() << std::endl;
177 for(int i_dim=0; i_dim<area->getNdim(); i_dim++){
178 const CaloLocalHadCoeff::LocalHadDimension *dim = area->getDimension(i_dim);
179 snprintf(line,sizeof(line),
180 "%-6s %2d %6.3f %12.3f ",dim->getTitle().c_str(), dim->getNbins(), dim->getXmin(), dim->getXmax() );
181 std::string sline(line);
182 sline += "flat";
183 fout << sline;
184// if( !dim.m_xbins.size() ) {
185// sline += "flat";
186// fout << sline;
187// }else {
188// sline += "hand";
189// fout << sline;
190// for(unsigned int i=0; i<dim.m_xbins.size(); i++){
191// fout << " " << dim.m_xbins[i];
192// }
193// }
194 fout << std::endl;
195 }
196 fout << "break" << std::endl; // i.e. no more dimensions
197
198 // now printing the data
199 for(int i_data=0; i_data<area->getLength(); i_data++) {
200 int indx = area->getOffset() + i_data;
201 const CaloLocalHadCoeff::LocalHadCoeff *pars = data->getCoeff(indx);
202 if( !pars ) {
203 std::cout << "CaloLCCoeffHelper::PrintData() -> Error! Wrong bin number" << std::endl;
204 return;
205 }
206 fout << std::setw(5) << indx << " ";
207 std::vector<int > v_dim_indexes;
208 data->bin2indexes(indx, v_dim_indexes);
209 for(unsigned int i_dim=0; i_dim<v_dim_indexes.size(); i_dim++){
210 fout << std::setw(4) << v_dim_indexes[i_dim] << " ";
211 }
212 fout << " ";
213 for(unsigned int i_par=0; i_par<(*pars).size(); i_par++) {
214 fout << std::fixed << std::setprecision(6) << std::setw(12) << (*pars)[i_par] << " ";
215 }
216 fout << std::endl;
217 }
218
219 // end of DM area
220 fout << std::endl;
221 }
222 // printing title strin
223}

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