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