ATLAS Offline Software
CaloHadDMCoeffHelper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 //-----------------------------------------------------------------------
19 #include <iostream>
20 #include <sstream>
21 #include <fstream>
22 #include <cstring>
23 
24 #define MAX_BUFFER_LEN 1024
25 
26 
28 {
29 
30 }
31 
33 {
34 
35 }
36 
37 
38 // get HadDMArea from bin number
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 }
50 
51 // get HadDMArea from area name
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 }
62 
63 
64 int CaloHadDMCoeffHelper::getBin(CaloHadDMCoeff2 * coeff, const int n_area, int ifrac, int iener, int ilambda, int ieta) const
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 }
73 
74 
75 /* ****************************************************************************
76 
77 **************************************************************************** */
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 }
215 
216 
217 
218 /* **************************************************************************
219 parsing dimension string
220 *************************************************************************** */
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 }
254 
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
CaloHadDMCoeffHelper::CaloHadDMCoeffHelper
CaloHadDMCoeffHelper()
Definition: CaloHadDMCoeffHelper.cxx:27
CaloHadDMCoeffHelper::InitDataFromFile
CaloHadDMCoeff2 * InitDataFromFile(std::string &hadDMCoeffFileName)
Definition: CaloHadDMCoeffHelper.cxx:78
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::getHadDMAreaFromBin
const CaloHadDMCoeff2::HadDMArea * getHadDMAreaFromBin(CaloHadDMCoeff2 *m_coeff, int iBin) const
Definition: CaloHadDMCoeffHelper.cxx:39
CaloHadDMCoeffHelper.h
CaloHadDMCoeffHelper::kAREA_LOOKUP
@ kAREA_LOOKUP
Definition: CaloHadDMCoeffHelper.h:24
CaloHadDMCoeff2::HadDMArea::m_length
int m_length
Definition: CaloHadDMCoeff2.h:46
CaloHadDMCoeffHelper::getBin
int getBin(CaloHadDMCoeff2 *m_coeff, const int n_area, int ifrac, int iener, int ilambda, int ieta) const
Definition: CaloHadDMCoeffHelper.cxx:64
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
CaloHadDMCoeffHelper::getHadDMAreaFromName
const CaloHadDMCoeff2::HadDMArea * getHadDMAreaFromName(CaloHadDMCoeff2 *m_coeff, const std::string &sname) const
Definition: CaloHadDMCoeffHelper.cxx:52
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
CaloHadDMCoeffHelper::~CaloHadDMCoeffHelper
virtual ~CaloHadDMCoeffHelper()
Definition: CaloHadDMCoeffHelper.cxx:32