File indexing completed on 2025-08-06 08:17:59
0001 #include "TPCMap.h"
0002
0003 #include <climits>
0004 #include <cmath>
0005 #include <fstream>
0006 #include <iomanip>
0007 #include <iostream>
0008 #include <sstream>
0009
0010 void TPCMap::setMapNames(const std::string &r1, const std::string &r2, const std::string &r3)
0011 {
0012 const char *calibrationroot = getenv("CALIBRATIONROOT");
0013 std::string full_path;
0014 if (calibrationroot)
0015 {
0016 full_path = std::string(calibrationroot) + "/TPC/Mapping/PadPlane/";
0017 }
0018 else
0019 {
0020 full_path = "./";
0021 }
0022 std::string full_path_r1 = full_path + r1;
0023 std::string full_path_r2 = full_path + r2;
0024 std::string full_path_r3 = full_path + r3;
0025 int status;
0026 status = digest_map(full_path_r1, 0);
0027 if (status)
0028 {
0029 std::cout << "reading " << full_path_r1 << " failed" << std::endl;
0030 }
0031 status = digest_map(full_path_r2, 1);
0032 if (status)
0033 {
0034 std::cout << "reading " << full_path_r2 << " failed" << std::endl;
0035 }
0036 status = digest_map(full_path_r3, 2);
0037 if (status)
0038 {
0039 std::cout << "reading " << full_path_r3 << " failed" << std::endl;
0040 }
0041 }
0042
0043 int TPCMap::digest_map(const std::string &fileName, const unsigned int section_offset)
0044 {
0045 std::ifstream infile(fileName, std::ios::in);
0046
0047 if (!infile.is_open())
0048 {
0049 std::cout << "Could not open file: "<< fileName << std::endl;
0050 _broken = 1;
0051 return -1;
0052 }
0053
0054 std::string line;
0055 getline(infile, line);
0056
0057
0058 int abs_pad = INT_MAX;
0059 int Radius = INT_MAX;
0060
0061
0062
0063
0064
0065
0066
0067 int FEE = INT_MAX;
0068
0069 int FEE_Chan = INT_MAX;
0070
0071
0072
0073
0074
0075 double PadR = NAN;
0076 double PadPhi = NAN;
0077
0078 while (getline(infile, line))
0079 {
0080
0081 std::stringstream ss(line);
0082 std::string next;
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 int index = 0;
0105 while (ss.good())
0106 {
0107 getline(ss, next, ',');
0108 if (index == 0)
0109 {
0110 abs_pad = std::stoul(next);
0111 }
0112 else if (index == 1)
0113 {
0114 Radius = stoul(next);
0115 }
0116 else if (index == 9)
0117 {
0118 FEE = stoul(next);
0119 }
0120 else if (index == 11)
0121 {
0122 FEE_Chan = stoul(next);
0123 }
0124 else if (index == 17)
0125 {
0126 PadR = stod(next);
0127 }
0128 else if (index == 18)
0129 {
0130 PadPhi = stod(next);
0131 }
0132 index++;
0133 }
0134
0135 if (section_offset == 1)
0136 {
0137 FEE += 6;
0138 }
0139 if (section_offset == 2)
0140 {
0141 FEE += 14;
0142 }
0143
0144 struct tpc_map x
0145 {
0146 };
0147 x.padnr = abs_pad;
0148 x.layer = Radius + section_offset * 16 + 7;
0149 x.FEE = FEE;
0150 x.FEEChannel = FEE_Chan;
0151 x.PadR = PadR;
0152 x.PadPhi = PadPhi;
0153
0154 unsigned int key = 256 * (FEE) + FEE_Chan;
0155 tmap[key] = x;
0156
0157 }
0158 return 0;
0159 }
0160
0161 unsigned int TPCMap::getLayer(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int ) const
0162 {
0163 if (FEE >= 26 || FEEChannel > 255)
0164 {
0165 return 0.;
0166 }
0167 unsigned int key = 256 * FEE + FEEChannel;
0168
0169 std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
0170 if (itr == tmap.end())
0171 {
0172 return 0;
0173 }
0174 return itr->second.layer;
0175 }
0176
0177 unsigned int TPCMap::getPad(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int ) const
0178 {
0179 if (FEE >= 26 || FEEChannel > 255)
0180 {
0181 return 0.;
0182 }
0183 unsigned int key = 256 * FEE + FEEChannel;
0184
0185 std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
0186 if (itr == tmap.end())
0187 {
0188 return -100;
0189 }
0190 return itr->second.padnr;
0191 }
0192
0193 double TPCMap::getR(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int ) const
0194 {
0195 if (FEE >= 26 || FEEChannel > 255)
0196 {
0197 return 0.;
0198 }
0199 unsigned int key = 256 * FEE + FEEChannel;
0200
0201 std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
0202 if (itr == tmap.end())
0203 {
0204 return -100;
0205 }
0206 return itr->second.PadR;
0207 }
0208
0209 double TPCMap::getPhi(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int ) const
0210 {
0211 if (FEE > 25 || FEEChannel > 255)
0212 {
0213 return 0.;
0214 }
0215 unsigned int key = 256 * FEE + FEEChannel;
0216
0217 std::map<unsigned int, struct tpc_map>::const_iterator itr = tmap.find(key);
0218 if (itr == tmap.end())
0219 {
0220 return -100;
0221 }
0222 return itr->second.PadPhi;
0223 }