ATLAS Offline Software
CaloHadDMCoeff2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 #include <cmath>
9 #include <iomanip>
10 #include <iostream>
11 
12 /* ***************************************************************************
13 c-tor
14 *************************************************************************** */
16 = default;
17 
18 
20 
21 
22 = default;
23 
24 
26 {
27  if (this != &other) {
28  m_DMCoeffSet = other.m_DMCoeffSet;
29  m_DMAreaSet = other.m_DMAreaSet;
30  m_area_offsets = other.m_area_offsets;
31  }
32  return *this;
33 }
34 
35 
36 /* ***************************************************************************
37 methods to deal with DM areas
38 *************************************************************************** */
40 {
41  m_DMAreaSet.push_back(theArea);
42  m_area_offsets.push_back(theArea.m_offset);
43 }
44 
45 void CaloHadDMCoeff2::setHadDMArea(const int n_area, const HadDMArea & theArea)
46 {
47  m_DMAreaSet[n_area] = theArea;
48 }
49 
51 {
52  if(n_area >= 0 && n_area<(int)m_DMAreaSet.size() ) {
53  return &(m_DMAreaSet[n_area]);
54  } else {
55  return nullptr;
56  }
57 }
58 
59 
60 /* ***************************************************************************
61 methods to deal with DM coefficients
62 *************************************************************************** */
64 {
65  m_DMCoeffSet.push_back(theData);
66 }
67 
68 void CaloHadDMCoeff2::setHadDMCoeff(const int iBin, const HadDMCoeff & theData)
69 {
70  m_DMCoeffSet[iBin] = theData;
71 }
72 
74 {
75  if ( iBin > -1 && iBin < (int)m_DMCoeffSet.size() ) {
76  return (& m_DMCoeffSet[iBin]);
77  }else{
78  return nullptr;
79  }
80 }
81 
82 
83 /* ***************************************************************************
84 methods to get DM coefficients bin number
85 *************************************************************************** */
86 
87 // get EM fraction bin number
88 int CaloHadDMCoeff2::getBinFrac(const int n_area, const float & cls_emfrac) const
89 {
90  const HadDMArea *dmArea = &m_DMAreaSet[n_area];
91  if(cls_emfrac < dmArea->m_dimFrac.m_vMin || cls_emfrac >= dmArea->m_dimFrac.m_vMax) return (-1);
92  return (int)((cls_emfrac - dmArea->m_dimFrac.m_vMin)/dmArea->m_dimFrac.m_bin_size);
93 }
94 
95 // get energy bin number
96 int CaloHadDMCoeff2::getBinEner(const int n_area, const float & cls_ener) const
97 {
98  const HadDMArea *dmArea = &m_DMAreaSet[n_area];
99  if( cls_ener < dmArea->m_dimEner.m_vMin || cls_ener >= dmArea->m_dimEner.m_vMax ) return (-1);
100  int iener;
101  for (iener=0; iener<dmArea->m_dimEner.m_nbins; iener++) {
102  if( cls_ener < dmArea->m_dimEner.m_vBins[iener] ) break;
103  if( cls_ener >= dmArea->m_dimEner.m_vBins[iener] && (iener == dmArea->m_dimEner.m_nbins-1 || cls_ener < dmArea->m_dimEner.m_vBins[iener+1]) ) break;
104  }
105  return iener;
106 }
107 
108 // get lambda bin number
109 int CaloHadDMCoeff2::getBinLambda(const int n_area, const float & cls_lambda) const
110 {
111  const HadDMArea *dmArea = &m_DMAreaSet[n_area];
112  if(cls_lambda < dmArea->m_dimLambda.m_vMin || cls_lambda >= dmArea->m_dimLambda.m_vMax) return (-1);
113  return (int)((cls_lambda - dmArea->m_dimLambda.m_vMin)/dmArea->m_dimLambda.m_bin_size);
114 }
115 
116 // get eta bin number
117 int CaloHadDMCoeff2::getBinEta(const int n_area, const float & cls_eta) const
118 {
119  const HadDMArea *dmArea = &m_DMAreaSet[n_area];
120  float cls_abseta = std::abs(cls_eta);
121  if(cls_abseta < dmArea->m_dimEta.m_vMin || cls_abseta >= dmArea->m_dimEta.m_vMax) return (-1);
122  return (int)((cls_abseta - dmArea->m_dimEta.m_vMin)/dmArea->m_dimEta.m_bin_size);
123 }
124 
125 // get general bin number
126 int CaloHadDMCoeff2::getBin(const int n_dm_area, const float &cls_emfrac, const float &cls_ener, const float &cls_lambda, const float &cls_eta) const
127 {
128  if(n_dm_area < 0 || n_dm_area >= (int)m_DMAreaSet.size()) {
129  std::cout << " WARNING CaloHadDMCoeff::getBin -> wrong n_area: " << n_dm_area << std::endl;
130  return (-1);
131  }
132  int iBin = -1;
133  const HadDMArea *dmArea = &m_DMAreaSet[n_dm_area];
134  int ifrac = -1, iener = -1, ilambda = -1, ieta = -1;
135  ifrac = getBinFrac(n_dm_area, cls_emfrac);
136  if( ifrac != -1 ) {
137  iener = getBinEner(n_dm_area, cls_ener);
138  if( iener != -1 ) {
139  ilambda = getBinLambda(n_dm_area, cls_lambda);
140  if( ilambda != -1 ) {
141  ieta = getBinEta(n_dm_area, cls_eta);
142  if ( ieta != -1 ) {
143  iBin = ieta + ilambda*dmArea->m_dimEta.m_nbins
144  + iener*dmArea->m_dimEta.m_nbins*dmArea->m_dimLambda.m_nbins
145  + ifrac*dmArea->m_dimEta.m_nbins*dmArea->m_dimLambda.m_nbins*dmArea->m_dimEner.m_nbins
146  + dmArea->m_offset;
147  } // ieta
148  }// ilambda
149  } // iener
150  } // ifrac
151  return iBin;
152 }
153 
154 
155 const CaloHadDMCoeff2::HadDMCoeff * CaloHadDMCoeff2::getHadDMCoeff(const int & n_area, const float & cls_emfrac, const float & cls_ener, const float & cls_lambda, const float & cls_eta) const
156 {
157  int iBin = getBin(n_area, cls_emfrac, cls_ener, cls_lambda, cls_eta);
158  return getHadDMCoeff(iBin);
159 }
160 
161 
162 
163 /* ***************************************************************************
164 
165 Accessories
166 
167 *************************************************************************** */
168 int CaloHadDMCoeff2::bin2indexes(const int iBin, std::vector<int> &v_dim_indx) const
169 {
170  int i_area = 0;
171  int narea = (int)m_area_offsets.size();
172  for(i_area=0; i_area<narea; i_area++) {
173  if( iBin < m_area_offsets[i_area] ) break;
174  if( iBin >= m_area_offsets[i_area] && (i_area == narea-1 || iBin < m_area_offsets[i_area+1]) ) break;
175  }
176  const HadDMArea *theArea = &m_DMAreaSet[i_area];
177  std::vector<HadDMDimension > v_dims;
178  v_dims.resize(4);
179  v_dims[0] = theArea->m_dimFrac;
180  v_dims[1] = theArea->m_dimEner;
181  v_dims[2] = theArea->m_dimLambda;
182  v_dims[3] = theArea->m_dimEta;
183  int ndim = (int) v_dims.size();
184  v_dim_indx.resize(ndim,0);
185  for(int i_dim=0; i_dim<ndim; i_dim++){
186  int x0 = 0;
187  for(int j=0; j<i_dim; j++){
188  x0 += v_dim_indx[j]*v_dims[j].xloc;
189  }
190  v_dim_indx[i_dim] = (iBin-theArea->m_offset-x0)/v_dims[i_dim].xloc;
191  }
192  return 0;
193 }
194 
195 
196 /* ***************************************************************************
197 for printing DM correction coefficients into text file
198 *************************************************************************** */
199 void CaloHadDMCoeff2::PrintData(std::ostream &fout) const
200 {
201  const char *comments =
202  {
203  "# Coeffs for Dead Material corrections in DeadMaterialCorrectionTool2 tool.\n\n"
204  };
205  fout << comments << std::endl;
206  char line[1024];
207 
208  // loop over DM areas
209  for(int i_zone=0; i_zone < (int)m_DMAreaSet.size(); i_zone++){
210  const HadDMArea *area = &m_DMAreaSet[i_zone];
211  fout << "zone " << area->m_indx << " " << area->m_is_on << " " << area->m_title << std::endl;
212  std::vector<CaloHadDMCoeff2::HadDMDimension > v_dims;
213  v_dims.resize(4);
214  v_dims[0] = area->m_dimFrac;
215  v_dims[1] = area->m_dimEner;
216  v_dims[2] = area->m_dimLambda;
217  v_dims[3] = area->m_dimEta;
218  for(unsigned int i_dim=0; i_dim<v_dims.size(); i_dim++){
219  CaloHadDMCoeff2::HadDMDimension dim = v_dims[i_dim];
220  sprintf(line,"%-6s %2d %6.3f %12.3f ",dim.m_title.c_str(), dim.m_nbins, dim.m_vMin, dim.m_vMax);
221  std::string sline(line);
222  if(dim.m_type == CaloHadDMCoeff2::kDIM_FLAT) {
223  sline += "flat";
224  }else if(dim.m_type == CaloHadDMCoeff2::kDIM_HAND) {
225  sline += "hand";
226  } else {
227  std::cout << "CaloHadDMCoeff2::PrintData2() -> Error! p1." << std::endl;
228  }
229  fout << sline;
230  if(dim.m_type == CaloHadDMCoeff2::kDIM_HAND) {
231  for(unsigned int i=0; i<dim.m_vBins.size(); i++){
232  fout << " " << dim.m_vBins[i];
233  }
234  }
235  fout << std::endl;
236  }
237  fout << "npars " << area->m_nPars << std::endl;
238  // now printing the data
239  for(int i_data=0; i_data<area->m_length; i_data++) {
240  int indx = area->m_offset + i_data;
241  const HadDMCoeff *pars = getHadDMCoeff(indx);
242  fout << std::setw(5) << indx << " ";
243  std::vector<int > v_dim_indexes;
244  bin2indexes(indx, v_dim_indexes);
245  for(unsigned int i_dim=0; i_dim<v_dim_indexes.size(); i_dim++){
246  fout << std::setw(4) << v_dim_indexes[i_dim] << " ";
247  }
248  fout << " ";
249  for(int i_par=0; i_par<area->m_nPars; i_par++){
250  std::stringstream foutx;
251  foutx << std::fixed << std::setprecision(5) << std::setw(12) << (*pars)[i_par] << " ";
252  fout<<foutx.str();
253  }
254  fout << std::endl;
255  }
256  // end of DM area
257  fout << std::endl;
258  }
259  // printing title strin
260 }
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
CaloHadDMCoeff2::HadDMDimension::m_vMax
float m_vMax
Definition: CaloHadDMCoeff2.h:32
WriteBchToCool.comments
comments
Definition: WriteBchToCool.py:297
checkFileSG.line
line
Definition: checkFileSG.py:75
CaloHadDMCoeff2::HadDMDimension::m_bin_size
float m_bin_size
Definition: CaloHadDMCoeff2.h:33
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloHadDMCoeff2::kDIM_HAND
@ kDIM_HAND
Definition: CaloHadDMCoeff2.h:25
CaloHadDMCoeff2.h
CaloHadDMCoeff2::CaloHadDMCoeff2
CaloHadDMCoeff2()
CaloHadDMCoeff2
Dead material correction coefficients.
Definition: CaloHadDMCoeff2.h:23
CaloHadDMCoeff2::setHadDMArea
void setHadDMArea(const int n_area, const HadDMArea &theArea)
Definition: CaloHadDMCoeff2.cxx:45
CaloHadDMCoeff2::PrintData
void PrintData(std::ostream &ff) const
Definition: CaloHadDMCoeff2.cxx:199
CaloHadDMCoeff2::getBin
int getBin(const int n_area, const float &cls_em_frac, const float &cls_energy, const float &cls_lambda, const float &cls_eta) const
Definition: CaloHadDMCoeff2.cxx:126
CaloHadDMCoeff2::HadDMArea::m_offset
int m_offset
Definition: CaloHadDMCoeff2.h:45
CaloHadDMCoeff2::bin2indexes
int bin2indexes(const int iBin, std::vector< int > &v_dim_indx) const
Definition: CaloHadDMCoeff2.cxx:168
CaloHadDMCoeff2::addHadDMCoeff
void addHadDMCoeff(const HadDMCoeff &theData)
Definition: CaloHadDMCoeff2.cxx:63
CaloHadDMCoeff2::HadDMArea::m_dimEta
HadDMDimension m_dimEta
Definition: CaloHadDMCoeff2.h:50
CaloHadDMCoeff2::m_DMCoeffSet
std::vector< HadDMCoeff > m_DMCoeffSet
Definition: CaloHadDMCoeff2.h:86
CaloHadDMCoeff2::HadDMArea
Definition: CaloHadDMCoeff2.h:39
CaloHadDMCoeff2::HadDMDimension::m_nbins
int m_nbins
Definition: CaloHadDMCoeff2.h:30
CaloHadDMCoeff2::HadDMDimension::m_vBins
std::vector< float > m_vBins
Definition: CaloHadDMCoeff2.h:35
CaloHadDMCoeff2::getBinEta
int getBinEta(const int dm_area, const float &cls_eta) const
Definition: CaloHadDMCoeff2.cxx:117
CaloHadDMCoeff2::setHadDMCoeff
void setHadDMCoeff(const int iBin, const HadDMCoeff &theData)
Definition: CaloHadDMCoeff2.cxx:68
CaloHadDMCoeff2::getHadDMArea
const HadDMArea * getHadDMArea(int n_area) const
Definition: CaloHadDMCoeff2.cxx:50
lumiFormat.i
int i
Definition: lumiFormat.py:85
dqt_zlumi_alleff_HIST.fout
fout
Definition: dqt_zlumi_alleff_HIST.py:59
CaloHadDMCoeff2::operator=
CaloHadDMCoeff2 & operator=(const CaloHadDMCoeff2 &other)
Definition: CaloHadDMCoeff2.cxx:25
CaloHadDMCoeff2::HadDMDimension
Definition: CaloHadDMCoeff2.h:27
CaloHadDMCoeff2::m_DMAreaSet
std::vector< HadDMArea > m_DMAreaSet
Definition: CaloHadDMCoeff2.h:87
CaloHadDMCoeff2::HadDMArea::m_dimLambda
HadDMDimension m_dimLambda
Definition: CaloHadDMCoeff2.h:49
CaloHadDMCoeff2::getHadDMCoeff
const HadDMCoeff * getHadDMCoeff(const int &iBin) const
Definition: CaloHadDMCoeff2.cxx:73
CaloHadDMCoeff2::HadDMArea::m_dimFrac
HadDMDimension m_dimFrac
Definition: CaloHadDMCoeff2.h:47
CaloHadDMCoeff2::getBinEner
int getBinEner(const int dm_area, const float &cls_ener) const
Definition: CaloHadDMCoeff2.cxx:96
CaloHadDMCoeff2::HadDMArea::m_dimEner
HadDMDimension m_dimEner
Definition: CaloHadDMCoeff2.h:48
CaloHadDMCoeff2::HadDMCoeff
std::vector< float > HadDMCoeff
Definition: CaloHadDMCoeff2.h:54
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CaloHadDMCoeff2::addHadDMArea
void addHadDMArea(const HadDMArea &theArea)
Definition: CaloHadDMCoeff2.cxx:39
CaloHadDMCoeff2::getBinFrac
int getBinFrac(const int dm_area, const float &cls_frac) const
Definition: CaloHadDMCoeff2.cxx:88
CaloHadDMCoeff2::getBinLambda
int getBinLambda(const int dm_area, const float &cls_lambda) const
Definition: CaloHadDMCoeff2.cxx:109
area
double area(double R)
Definition: ConvertStaveServices.cxx:42
CaloHadDMCoeff2::HadDMDimension::m_vMin
float m_vMin
Definition: CaloHadDMCoeff2.h:31
CaloHadDMCoeff2::m_area_offsets
std::vector< int > m_area_offsets
Definition: CaloHadDMCoeff2.h:88
CaloHadDMCoeff2::kDIM_FLAT
@ kDIM_FLAT
Definition: CaloHadDMCoeff2.h:25