Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcMap.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcMap.cc
1 #include "TpcMap.h"
2 
3 #include <climits>
4 #include <cmath>
5 #include <fstream>
6 #include <iomanip>
7 #include <iostream>
8 #include <sstream>
9 
11 {
12  const char *calibrationroot = getenv("CALIBRATIONROOT");
13  std::string full_path;
14  if (calibrationroot)
15  {
16  full_path = std::string(calibrationroot) + "/TPC/Mapping/PadPlane/";
17  }
18  else
19  {
20  calibrationroot = getenv("TPCCALIB");
21  if (calibrationroot)
22  {
23  full_path = std::string(calibrationroot) + "/";
24  }
25  else
26  {
27  full_path = "./";
28  }
29  }
30 
31  std::string full_path_r1 = full_path + r1;
32  std::string full_path_r2 = full_path + r2;
33  std::string full_path_r3 = full_path + r3;
34  int status;
35  status = digest_map(full_path_r1, 0);
36  if (status)
37  {
38  std::cout << "reading " << full_path_r1 << " failed" << std::endl;
39  }
40  status = digest_map(full_path_r2, 1);
41  if (status)
42  {
43  std::cout << "reading " << full_path_r2 << " failed" << std::endl;
44  }
45  status = digest_map(full_path_r3, 2);
46  if (status)
47  {
48  std::cout << "reading " << full_path_r3 << " failed" << std::endl;
49  }
50 }
51 
52 int TpcMap::digest_map(const std::string &fileName, const unsigned int section_offset)
53 {
54  std::ifstream infile(fileName, std::ios::in);
55 
56  if (!infile.is_open())
57  {
58  std::cout << "Could not open file: "<< fileName << std::endl;
59  _broken = 1;
60  return -1;
61  }
62 
64  getline(infile, line); // throwaway - we skip the first line
65  // cout << __FILE__<< " " << __LINE__ << ": " << line << endl;
66 
67  int abs_pad = INT_MAX;
68  int Radius = INT_MAX;
69  // int Pad;
70  // int U;
71  // int G;
72  // string Pin;
73  // int PinColID;
74  // int PinRowID;
75  // string PadName;
76  int FEE = INT_MAX;
77  // int FEE_Connector;
78  int FEE_Chan = INT_MAX;
79  // double phi;
80  // double x;
81  // double y;
82  // double PadX;
83  // double PadY;
84  double PadR = NAN;
85  double PadPhi = NAN;
86 
87  while (getline(infile, line))
88  {
89  // cout << line<< endl;
90  std::stringstream ss(line);
92 
93  // 0 26 26
94  // 1 0 0
95  // 2 0 0
96  // 3 1 1
97  // 4 1 1
98  // 5 0 C5
99  // 6 2 2
100  // 7 5 5
101  // 8 0 ZZ.00.000
102  // 9 5 5.0
103  // 10 0 J2
104  // 11 147 147
105  // 12 0 0.005570199740407434
106  // 13 69 69.99891405342764
107  // 14 0 0.38991196551332985
108  // 15 77 77.86043476908294
109  // 16 305 305.14820499531316
110  // 17 314 314.9248709046211
111  // 18 0 0.24982557215053805
112 
113  int index = 0;
114  while (ss.good())
115  {
116  getline(ss, next, ',');
117  if (index == 2)
118  {
119  abs_pad = std::stoul(next);
120  }
121  else if (index == 1)
122  {
123  Radius = stoul(next);
124  }
125  else if (index == 9)
126  {
127  FEE = stoul(next);
128  }
129  else if (index == 11)
130  {
131  FEE_Chan = stoul(next);
132  }
133  else if (index == 17)
134  {
135  PadR = stod(next);
136  }
137  else if (index == 18)
138  {
139  PadPhi = stod(next);
140  }
141  index++;
142  }
143 
144  if (section_offset == 1)
145  {
146  FEE += 6;
147  }
148  if (section_offset == 2)
149  {
150  FEE += 14;
151  }
152 
153  struct tpc_map x
154  {
155  };
156  x.padnr = abs_pad;
157  x.layer = Radius + section_offset * 16 + 7;
158  x.FEE = FEE;
159  x.FEEChannel = FEE_Chan;
160  x.PadR = PadR;
161  x.PadPhi = PadPhi;
162 
163  unsigned int key = 256 * (FEE) + FEE_Chan;
164  tmap[key] = x;
165  // cout << setw(5) << key << setw(5) << FEE << setw(5) << FEE_Chan << " " << PadR << " " << PadPhi << endl;
166  }
167  return 0;
168 }
169 
170 unsigned int TpcMap::getLayer(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int /* packetid */) const
171 {
172  if (FEE >= 26 || FEEChannel > 255)
173  {
174  return 0.;
175  }
176  unsigned int key = 256 * FEE + FEEChannel;
177 
178  std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
179  if (itr == tmap.end())
180  {
181  return 0;
182  }
183  return itr->second.layer;
184 }
185 
186 unsigned int TpcMap::getPad(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int /* packetid */) const
187 {
188  if (FEE >= 26 || FEEChannel > 255)
189  {
190  return 0.;
191  }
192  unsigned int key = 256 * FEE + FEEChannel;
193 
194  std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
195  if (itr == tmap.end())
196  {
197  return -100;
198  }
199  return itr->second.padnr;
200 }
201 
202 double TpcMap::getR(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int /* packetid */) const
203 {
204  if (FEE >= 26 || FEEChannel > 255)
205  {
206  return 0.;
207  }
208  unsigned int key = 256 * FEE + FEEChannel;
209 
210  std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
211  if (itr == tmap.end())
212  {
213  return -100;
214  }
215  return itr->second.PadR;
216 }
217 
218 double TpcMap::getPhi(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int /* packetid */) const
219 {
220  if (FEE > 25 || FEEChannel > 255)
221  {
222  return 0.;
223  }
224  unsigned int key = 256 * FEE + FEEChannel;
225 
226  std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
227  if (itr == tmap.end())
228  {
229  return -100;
230  }
231  return itr->second.PadPhi;
232 }