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