ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | List of all members
CaloHadDMCoeffHelper Class Reference

Helper class to read dead material correction coeffitients from ASCII file. More...

#include <CaloHadDMCoeffHelper.h>

Collaboration diagram for CaloHadDMCoeffHelper:

Public Types

enum  key_area_type { kAREA_PROF, kAREA_LOOKUP, kAREA_SMPW }
 

Public Member Functions

 CaloHadDMCoeffHelper ()
 
virtual ~CaloHadDMCoeffHelper ()
 
CaloHadDMCoeff2InitDataFromFile (std::string &hadDMCoeffFileName)
 
const CaloHadDMCoeff2::HadDMAreagetHadDMAreaFromBin (CaloHadDMCoeff2 *m_coeff, int iBin) const
 
int getBin (CaloHadDMCoeff2 *m_coeff, const int n_area, int ifrac, int iener, int ilambda, int ieta) const
 
const CaloHadDMCoeff2::HadDMAreagetHadDMAreaFromName (CaloHadDMCoeff2 *m_coeff, const std::string &sname) const
 

Private Member Functions

int parse_dim (std::string &sLine, CaloHadDMCoeff2::HadDMDimension &dim)
 

Detailed Description

Helper class to read dead material correction coeffitients from ASCII file.

Version
$Id: CaloHadDMCoeffHelper.h,v 1.1 2009-03-03 17:30:21 pospelov Exp $
Author
Gennady Pospelov guenn.nosp@m.adi..nosp@m.pospe.nosp@m.lov@.nosp@m.cern..nosp@m.ch
Date
23-Januar-2009

Definition at line 22 of file CaloHadDMCoeffHelper.h.

Member Enumeration Documentation

◆ key_area_type

Enumerator
kAREA_PROF 
kAREA_LOOKUP 
kAREA_SMPW 

Definition at line 24 of file CaloHadDMCoeffHelper.h.

Constructor & Destructor Documentation

◆ CaloHadDMCoeffHelper()

CaloHadDMCoeffHelper::CaloHadDMCoeffHelper ( )

Definition at line 27 of file CaloHadDMCoeffHelper.cxx.

28 {
29 
30 }

◆ ~CaloHadDMCoeffHelper()

CaloHadDMCoeffHelper::~CaloHadDMCoeffHelper ( )
virtual

Definition at line 32 of file CaloHadDMCoeffHelper.cxx.

33 {
34 
35 }

Member Function Documentation

◆ getBin()

int CaloHadDMCoeffHelper::getBin ( CaloHadDMCoeff2 m_coeff,
const int  n_area,
int  ifrac,
int  iener,
int  ilambda,
int  ieta 
) const

Definition at line 64 of file CaloHadDMCoeffHelper.cxx.

65 {
66  const CaloHadDMCoeff2::HadDMArea *dmArea = coeff->getHadDMArea(n_area);
67  int iBin = ieta + ilambda*dmArea->m_dimEta.m_nbins
68  + iener*dmArea->m_dimEta.m_nbins*dmArea->m_dimLambda.m_nbins
69  + ifrac*dmArea->m_dimEta.m_nbins*dmArea->m_dimLambda.m_nbins*dmArea->m_dimEner.m_nbins
70  + dmArea->m_offset;
71  return iBin;
72 }

◆ getHadDMAreaFromBin()

const CaloHadDMCoeff2::HadDMArea * CaloHadDMCoeffHelper::getHadDMAreaFromBin ( CaloHadDMCoeff2 m_coeff,
int  iBin 
) const

Definition at line 39 of file CaloHadDMCoeffHelper.cxx.

40 {
41  int i_area = 0;
42  int narea = coeff->getSizeDMAreaSet();
43  for(i_area=0; i_area<narea; i_area++) {
44  if( iBin < coeff->getHadDMArea(i_area)->m_offset ) break;
45  if( iBin >= coeff->getHadDMArea(i_area)->m_offset
46  && (i_area == narea-1 || iBin < coeff->getHadDMArea(i_area+1)->m_offset) ) break;
47  }
48  return coeff->getHadDMArea(i_area);
49 }

◆ getHadDMAreaFromName()

const CaloHadDMCoeff2::HadDMArea * CaloHadDMCoeffHelper::getHadDMAreaFromName ( CaloHadDMCoeff2 m_coeff,
const std::string &  sname 
) const

Definition at line 52 of file CaloHadDMCoeffHelper.cxx.

53 {
54  for(int i_area=0; i_area<coeff->getSizeDMAreaSet(); i_area++) {
55  if(sname == coeff->getHadDMArea(i_area)->m_title) {
56  return coeff->getHadDMArea(i_area);
57  }
58  }
59  std::cout << "CaloHadDMCoeffHelper::getHadDMAreaFromName() -> Error! No such dmArea '" << sname << "'" << std::endl;
60  return nullptr;
61 }

◆ InitDataFromFile()

CaloHadDMCoeff2 * CaloHadDMCoeffHelper::InitDataFromFile ( std::string &  hadDMCoeffFileName)

Definition at line 78 of file CaloHadDMCoeffHelper.cxx.

79 {
81 
82  char cLine[MAX_BUFFER_LEN];
83 
84  // Find the full path to filename
85  std::cout << "CaloHadDMCoeffHelper::InitDataFromFile() - Reading file '" << filename << "'." << std::endl;
86 
87  std::ifstream fin(filename.c_str());
88  if ( !fin ) {
89  std::cout << "CaloHadDMCoeffHelper::InitDataFromFile() - Can't open file '" << filename << "'." << std::endl;
90  delete data; return nullptr;
91  }
92 
93  int offset = 0;
94 
95  std::string sLine;
96  std::string sdummy;
97  std::istringstream ist;
98  while(fin.getline(cLine,sizeof(cLine)-1)) {
99  if( strlen(cLine)==0 || cLine[0] == '#' || cLine[0] == '\n') continue;
100 
101  // creating new dead material area
103  // parsing zone line
104  sLine = cLine;
105  ist.clear(); ist.str(sLine);
106  if( !(ist >> sdummy >> dmArea.m_indx >> dmArea.m_is_on >> dmArea.m_title) && sdummy.find("zone")==std::string::npos ) {
107  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() -> Error! Could not parse line '" << cLine << "' at p1." << std::endl;
108  delete data; return nullptr;
109  }
110 
111  dmArea.m_type = kAREA_PROF;
112  if(dmArea.m_title.find("DEAD_FCAL") != std::string::npos) {
113  dmArea.m_type = kAREA_SMPW;
114  }else if(dmArea.m_title.find("DEAD_LEAKAGE") != std::string::npos) {
115  dmArea.m_type = kAREA_LOOKUP;
116  }else if(dmArea.m_title.find("DEAD_UNCLASS") != std::string::npos) {
117  dmArea.m_type = kAREA_LOOKUP;
118  }
119 
120  // loop over dimensions of this zones
121  std::vector<CaloHadDMCoeff2::HadDMDimension > v_dims;
122  while(fin.getline(cLine,sizeof(cLine)-1)){
123  if( cLine[0] == '#') continue;
124  sLine = cLine;
125  // reading number of parameters
126  if(sLine.find("npars") != std::string::npos){
127  ist.clear(); ist.str(sLine);
128  if( !(ist >> sdummy >> dmArea.m_nPars) ||
129  dmArea.m_nPars < 0 ||
130  dmArea.m_nPars > 1000)
131  {
132  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p2." << std::endl;
133  delete data; return nullptr;
134  }
135  // this is the end of zone
136  break;
137  }
139  if( !parse_dim(sLine, dim) ) {
140  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << sLine << "' at p2a." << std::endl;
141  delete data; return nullptr;
142  }
143  v_dims.push_back(dim);
144  }
145  // calculation offset for this area
146  int ndim = (int) v_dims.size();
147  int length = 1;
148  for(int i=0; i<ndim; i++){
149  length = length*v_dims[i].m_vBins.size();
150  }
151  dmArea.m_offset = offset;
152  dmArea.m_length = length;
153  // calculation of dimension locator coefficient
154  for(int i_dim=0; i_dim<ndim; i_dim++){
155  int xloc = 1;
156  for(int j=i_dim+1; j<ndim; j++){
157  xloc = xloc*v_dims[j].m_vBins.size();
158  }
159  v_dims[i_dim].xloc = xloc;
160  }
161  if( v_dims.size() != 4 ){
162  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() ->Error! Wrong number of dimensions for area'" << dmArea.m_title << "' at p3." << std::endl;
163  delete data; return nullptr;
164  }
165  dmArea.m_dimFrac = v_dims[0];
166  dmArea.m_dimEner = v_dims[1];
167  dmArea.m_dimLambda = v_dims[2];
168  dmArea.m_dimEta = v_dims[3];
169 
170  data->addHadDMArea(dmArea);
171  offset += length; // ofset for next DM area
172  // putting zero parameters
174  pars.resize(dmArea.m_nPars, 0.0);
175  for(int i_len=0; i_len<dmArea.m_length; i_len++) data->addHadDMCoeff(pars);
176  // now reading parameters
177  for(int i_len=0; i_len<dmArea.m_length; i_len++){
178  if(!fin.getline(cLine,sizeof(cLine)-1)) {
179  std::cout << "panic " << std::endl;
180  delete data; return nullptr;
181  }
182  sLine = cLine;
183  ist.clear(); ist.str(sLine);
184  int idummy;
185  if( !(ist >> idummy) ) {
186  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() -> Warning! Area " << dmArea.m_title << " doesn't have parameters." << std::endl;
187  break;
188  }
189  if(idummy != dmArea.m_offset+i_len){
190  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p3." << std::endl;
191  delete data; return nullptr;
192  }
193  for(int j=0; j<(int)v_dims.size(); j++) {
194  if(!(ist >> idummy)) {
195  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() -> panic!" << std::endl;
196  delete data; return nullptr;
197  }
198  }
200  pars.resize(dmArea.m_nPars,0.0);
201  for(int j=0; j<dmArea.m_nPars; j++) {
202  if( !(ist >> pars[j]) ) {
203  std::cout << "CaloHadDMCoeffHelper::initDataFromFile() ->Error! Could not parse line '" << cLine << "' at p4." << std::endl;
204  std::cout << " dmArea.m_title" << dmArea.m_title << std::endl;
205  delete data; return nullptr;
206  }
207  }
208  data->setHadDMCoeff(dmArea.m_offset+i_len,pars);
209  }
210  }
211  fin.close();
212 
213  return data;
214 }

◆ parse_dim()

int CaloHadDMCoeffHelper::parse_dim ( std::string &  sLine,
CaloHadDMCoeff2::HadDMDimension dim 
)
private

Definition at line 221 of file CaloHadDMCoeffHelper.cxx.

222 {
223  std::string dummy;
224  std::string stype;
225  std::istringstream ist(sLine.c_str());
226 
227  if( !(ist >> dim.m_title >> dim.m_nbins >> dim.m_vMin >> dim.m_vMax >> stype)||
228  dim.m_nbins < 0 ||
229  dim.m_nbins > 1000)
230  {
231  std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at pp1." << std::endl;
232  return 0;
233  }
234  // bins according to flat scale
235  if(stype.find("flat") != std::string::npos) {
237  dim.m_bin_size = (dim.m_vMax - dim.m_vMin)/float(dim.m_nbins);
238  for(int i=0; i<dim.m_nbins; i++) dim.m_vBins.push_back(dim.m_vMin + i*(dim.m_vMax - dim.m_vMin)/float(dim.m_nbins));
239  // bins are setted in the string
240  }else if(stype.find("hand") != std::string::npos) {
242  float e;
243  for(int i=0; i<dim.m_nbins; i++) if( ist >> e ) dim.m_vBins.push_back(e);
244  }else{
245  std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at pp3." << std::endl;
246  return 0;
247  }
248  if((int)dim.m_vBins.size() != dim.m_nbins){
249  std::cout << "CaloHadDMCoeffHelper::parse_dim() -> Error! Could not parse line '" << sLine << "' at pp4." << std::endl;
250  return 0;
251  }
252  return (int) dim.m_vBins.size();
253 }

The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloHadDMCoeff2::HadDMArea::m_is_on
int m_is_on
Definition: CaloHadDMCoeff2.h:42
CaloHadDMCoeff2::kDIM_HAND
@ kDIM_HAND
Definition: CaloHadDMCoeff2.h:25
CaloHadDMCoeffHelper::kAREA_PROF
@ kAREA_PROF
Definition: CaloHadDMCoeffHelper.h:24
CaloHadDMCoeff2
Dead material correction coefficients.
Definition: CaloHadDMCoeff2.h:23
CaloHadDMCoeff2::HadDMArea::m_offset
int m_offset
Definition: CaloHadDMCoeff2.h:45
CaloHadDMCoeff2::HadDMArea::m_dimEta
HadDMDimension m_dimEta
Definition: CaloHadDMCoeff2.h:50
CaloHadDMCoeff2::HadDMArea
Definition: CaloHadDMCoeff2.h:39
CaloHadDMCoeff2::HadDMDimension::m_nbins
int m_nbins
Definition: CaloHadDMCoeff2.h:30
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloHadDMCoeff2::HadDMDimension
Definition: CaloHadDMCoeff2.h:27
python.xAODType.dummy
dummy
Definition: xAODType.py:4
CaloHadDMCoeff2::HadDMArea::m_type
int m_type
Definition: CaloHadDMCoeff2.h:43
CaloHadDMCoeff2::HadDMArea::m_indx
int m_indx
Definition: CaloHadDMCoeff2.h:41
MAX_BUFFER_LEN
#define MAX_BUFFER_LEN
Definition: CaloHadDMCoeffHelper.cxx:24
CaloHadDMCoeff2::HadDMArea::m_title
std::string m_title
Definition: CaloHadDMCoeff2.h:40
CaloHadDMCoeff2::HadDMArea::m_dimLambda
HadDMDimension m_dimLambda
Definition: CaloHadDMCoeff2.h:49
MuonCalib::Legendre::coeff
constexpr double coeff(unsigned int l, unsigned int k)
Calculates the n-th coefficient of the legendre polynomial series.
Definition: LegendrePoly.h:73
CaloHadDMCoeff2::HadDMArea::m_dimFrac
HadDMDimension m_dimFrac
Definition: CaloHadDMCoeff2.h:47
CaloHadDMCoeffHelper::kAREA_SMPW
@ kAREA_SMPW
Definition: CaloHadDMCoeffHelper.h:24
CaloHadDMCoeff2::HadDMArea::m_dimEner
HadDMDimension m_dimEner
Definition: CaloHadDMCoeff2.h:48
CaloHadDMCoeff2::HadDMCoeff
std::vector< float > HadDMCoeff
Definition: CaloHadDMCoeff2.h:54
CaloHadDMCoeffHelper::kAREA_LOOKUP
@ kAREA_LOOKUP
Definition: CaloHadDMCoeffHelper.h:24
CaloHadDMCoeff2::HadDMArea::m_length
int m_length
Definition: CaloHadDMCoeff2.h:46
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
compute_lumi.fin
fin
Definition: compute_lumi.py:19
CaloHadDMCoeff2::HadDMArea::m_nPars
int m_nPars
Definition: CaloHadDMCoeff2.h:44
CaloHadDMCoeff2::kDIM_FLAT
@ kDIM_FLAT
Definition: CaloHadDMCoeff2.h:25
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
readCCLHist.float
float
Definition: readCCLHist.py:83
CaloHadDMCoeffHelper::parse_dim
int parse_dim(std::string &sLine, CaloHadDMCoeff2::HadDMDimension &dim)
Definition: CaloHadDMCoeffHelper.cxx:221