ATLAS Offline Software
MapEta.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 #include "MapEta.h"
6 
7 // For reading the data files in Athena.
8 #ifndef LARG4_STAND_ALONE
10 #endif
11 
12 #include <iostream>
13 #include <fstream>
14 
15 MapEta::MapEta(int isampling)
16  : m_directory ("/afs/cern.ch/atlas/offline/data/lar/calo_data"),
17  m_init (0),
18  m_nx (0),
19  m_ny (0),
20  m_resp (nullptr),
21  m_xt0 (nullptr),
22  m_xt1 (nullptr),
23  m_xt2 (nullptr)
24 {
25  Initialize(isampling);
26 }
27 
29 {
30  if (m_resp) delete [] m_resp;
31  if (m_xt0) delete [] m_xt0;
32  if (m_xt1) delete [] m_xt1;
33  if (m_xt2) delete [] m_xt2;
34 }
35 
36 
37 void MapEta::SetDirectory(const std::string& dir)
38 {
40 }
41 
42 void MapEta::Initialize(int isampling)
43 {
44  if (m_init==1) return;
45  if (isampling < 1 || isampling >3) return;
46  std::string filename{};
47  if (isampling==1) filename = "deta_strip.map";
48  if (isampling==2) filename = "deta_middle.map";
49  if (isampling==3) filename = "eta_trans.map";
50  std::string fileLocation;
51 #ifdef LARG4_STAND_ALONE
52  // The stand-alone program expects to find the file via AFS.
53  fileLocation = m_directory + "/" + filename;
54 #else
55  // In Athena, the PathResolver tool will find the file for us.
56  std::cout << "filename " << filename << std::endl;
57  //std::string larLocation = PathResolver::find_directory("lar","DATAPATH");
58  //fileLocation=larLocation+"/calo_data/"+filename;
59  std::string larLocation = PathResolver::find_directory("LArG4Barrel","ATLASCALDATA");
60  fileLocation=larLocation+"/"+filename;
61  std::cout << "fileLocation " << fileLocation << std::endl;
62 #endif
63 
64  std::ifstream in(fileLocation);
65  if (in)
66  {
68  if(m_nx>0 && m_ny>0 && m_nx<10000 && m_ny<10000){//coverity issue. This is a tainted variable protection, 10000 can be changed if required.
69  m_deltax=(m_xmax-m_xmin)/((float) m_nx);
70  m_deltay=(m_ymax-m_ymin)/((float) m_ny);
71  // what is written as xmax in the map is x of last point + delta x
72  // (such that npoint = (xmax-xmin)/deltax
73  // to get the real last point in the map we should subtract deltax
76  m_resp = new float[m_ny*m_nx];
77  m_xt0 = new float[m_ny*m_nx];
78  m_xt1 = new float[m_ny*m_nx];
79  m_xt2 = new float[m_ny*m_nx];
80  int ii,jj;
81  for (int ix=0;ix<m_nx;ix++) {
82  for (int iy=0;iy<m_ny;iy++) {
83  in>>ii>>jj>>m_resp[ix+iy*m_nx]>>m_xt0[ix+iy*m_nx]>>m_xt1[ix+iy*m_nx]>>m_xt2[ix+iy*m_nx];
84  if (ii != ix || jj != iy) std::cout << "MapEta: inconsistency when reading map..." << std::endl;
85  }
86  }
87 
88  std::cout << "Eta Map read " << " Nbins " << m_nx << " " << m_ny
89  << " bin size*1000 " << 1000*m_deltax << " " << 1000*m_deltay
90  << " X range " << m_xmin << " " << m_xmax
91  << " Y range " << m_ymin << " " << m_ymax << std::endl;
92  m_init=1;
93  }
94  else{
95  std::cout << "Error in MapEta::Initialize: nx or ny out of limits." << std::endl;
96  return;
97  }
98  }
99  else{
100  std::cout << "Error in MapEta::Initialize: The file could not be open." << std::endl;
101  return;
102  }
103 }
104 
105 void MapEta::GetData(double x,double y,double* resp, double* xt0, double* xt1, double* xt2) const
106 {
107  *resp=1;
108  *xt0=1;
109  *xt1=0;
110  *xt2=0;
111  if (m_nx==0 || m_ny ==0) return;
112  if (x<m_xmin ) x=m_xmin+0.01*m_deltax;
113  if (x>=m_xmax) x=m_xmax-0.01*m_deltax;
114  if (y<m_ymin ) y=m_ymin+0.01*m_deltay;
115  if (y>=m_ymax) y=m_ymax-0.01*m_deltay;
116 
117  int ix,iy;
118  ix = (int) ((x-m_xmin)/m_deltax);
119  iy = (int) ((y-m_ymin)/m_deltay);
120  float x0 = ((float) ix)*m_deltax+m_xmin;
121  float x1 = x0+m_deltax;
122  float y0 = ((float) iy)*m_deltay+m_ymin;
123  float y1 = y0+m_deltay;
124 
125 
126  if (ix<0 || ix+1 >= m_nx || iy<0 || iy+1 >= m_ny) {
127  std::cout << "MapEta: Out of range " << ix << " " << iy << std::endl;
128  return;
129  }
130  double w[4];
131  w[0]=(x1-x)*(y1-y);
132  w[1]=(x-x0)*(y1-y);
133  w[2]=(x1-x)*(y-y0);
134  w[3]=(x-x0)*(y-y0);
135 
136  double sumw=0.;
137  *resp=0;
138  *xt0=0;
139  for (int i=0;i<2;i++) {
140  for (int j=0;j<2;j++) {
141  int n=ix+i+(iy+j)*m_nx;
142  int m=i+2*j;
143  sumw +=w[m];
144  *resp += m_resp[n]*w[m];
145  *xt0 += m_xt0[n]*w[m];
146  *xt1 += m_xt1[n]*w[m];
147  *xt2 += m_xt2[n]*w[m];
148  }
149  }
150  const double inv_sumw = 1. / sumw;
151  if (sumw>0.) {
152  *resp = *resp*inv_sumw;
153  *xt0 = *xt0*inv_sumw;
154  *xt1 = *xt1*inv_sumw;
155  *xt2 = *xt2*inv_sumw;
156  }
157 
158 }
159 void MapEta::GetData0(double x,double y,double* resp) const
160 {
161  *resp=1;
162  if (m_nx==0 || m_ny ==0) return;
163  if (x<m_xmin ) x=m_xmin+0.01*m_deltax;
164  if (x>=m_xmax) x=m_xmax-0.01*m_deltax;
165  if (y<m_ymin ) y=m_ymin+0.01*m_deltay;
166  if (y>=m_ymax) y=m_ymax-0.01*m_deltay;
167 
168  int ix,iy;
169  ix = (int) ((x-m_xmin)/m_deltax);
170  iy = (int) ((y-m_ymin)/m_deltay);
171  float x0 = ((float) ix)*m_deltax+m_xmin;
172  float x1 = x0+m_deltax;
173  float y0 = ((float) iy)*m_deltay+m_ymin;
174  float y1 = y0+m_deltay;
175 
176  if (ix<0 || ix+1 >= m_nx || iy<0 || iy+1 >= m_ny) {
177  std::cout << "MapEta: Out of range " << ix << " " << iy << std::endl;
178  return;
179  }
180  double w[4];
181  w[0]=(x1-x)*(y1-y);
182  w[1]=(x-x0)*(y1-y);
183  w[2]=(x1-x)*(y-y0);
184  w[3]=(x-x0)*(y-y0);
185 
186  double sumw=0.;
187  *resp = 0;
188  for (int i=0;i<2;i++) {
189  for (int j=0;j<2;j++) {
190  int n=ix+i+(iy+j)*m_nx;
191  int m=i+2*j;
192  sumw +=w[m];
193  *resp += m_resp[n]*w[m];
194  }
195  }
196  if (sumw>0.) *resp = *resp/sumw;
197  else *resp = 1;
198 
199 }
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
MapEta::~MapEta
~MapEta()
Definition: MapEta.cxx:28
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MapEta::m_xmin
float m_xmin
Definition: MapEta.h:17
MapEta::m_xmax
float m_xmax
Definition: MapEta.h:17
MapEta::MapEta
MapEta(int isampling)
Definition: MapEta.cxx:15
MapEta::m_deltay
float m_deltay
Definition: MapEta.h:18
MapEta::GetData
void GetData(double x, double y, double *resp, double *xt0, double *xt1, double *xt2) const
Definition: MapEta.cxx:105
PathResolver::find_directory
static std::string find_directory(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:307
plotBeamSpotVxVal.sumw
int sumw
Definition: plotBeamSpotVxVal.py:236
x
#define x
MapEta::m_ymax
float m_ymax
Definition: MapEta.h:17
MapEta::m_xt2
float * m_xt2
Definition: MapEta.h:22
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
MapEta::GetData0
void GetData0(double x, double y, double *resp) const
Definition: MapEta.cxx:159
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
MapEta::m_xt0
float * m_xt0
Definition: MapEta.h:20
MapEta::m_init
int m_init
Definition: MapEta.h:15
MapEta::Initialize
void Initialize(int isampling)
Definition: MapEta.cxx:42
MapEta::m_resp
float * m_resp
Definition: MapEta.h:19
beamspotman.dir
string dir
Definition: beamspotman.py:623
MapEta.h
MapEta::m_ny
int m_ny
Definition: MapEta.h:16
MapEta::m_xt1
float * m_xt1
Definition: MapEta.h:21
MapEta::m_directory
std::string m_directory
Definition: MapEta.h:14
PathResolver.h
MapEta::m_deltax
float m_deltax
Definition: MapEta.h:18
MapEta::m_nx
int m_nx
Definition: MapEta.h:16
MapEta::m_ymin
float m_ymin
Definition: MapEta.h:17
y
#define y
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
MapEta::SetDirectory
void SetDirectory(const std::string &dir)
Definition: MapEta.cxx:37
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
readCCLHist.float
float
Definition: readCCLHist.py:83