Back to home page

sPhenix code displayed by LXR

 
 

    


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);  // throwaway - we skip the first line
0056   //  cout << __FILE__<< " " << __LINE__ << ": " << line << endl;
0057 
0058   int abs_pad = INT_MAX;
0059   int Radius = INT_MAX;
0060   // int Pad;
0061   // int  U;
0062   // int  G;
0063   // string  Pin;
0064   // int PinColID;
0065   // int PinRowID;
0066   // string PadName;
0067   int FEE = INT_MAX;
0068   //  int FEE_Connector;
0069   int FEE_Chan = INT_MAX;
0070   // double phi;
0071   // double x;
0072   // double y;
0073   // double PadX;
0074   // double PadY;
0075   double PadR = NAN;
0076   double PadPhi = NAN;
0077 
0078   while (getline(infile, line))
0079   {
0080     //      cout << line<< endl;
0081     std::stringstream ss(line);
0082     std::string next;
0083 
0084     //  0  26    26
0085     //  1   0    0
0086     //  2   0    0
0087     //  3   1    1
0088     //  4   1    1
0089     //  5   0    C5
0090     //  6   2    2
0091     //  7   5    5
0092     //  8   0    ZZ.00.000
0093     //  9   5    5.0
0094     // 10   0    J2
0095     // 11 147    147
0096     // 12   0    0.005570199740407434
0097     // 13  69    69.99891405342764
0098     // 14   0    0.38991196551332985
0099     // 15  77    77.86043476908294
0100     // 16 305    305.14820499531316
0101     // 17 314    314.9248709046211
0102     // 18   0    0.24982557215053805
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     //      cout << setw(5) << key << setw(5) << FEE << setw(5) << FEE_Chan << " " << PadR << "  " << PadPhi << endl;
0157   }
0158   return 0;
0159 }
0160 
0161 unsigned int TPCMap::getLayer(const unsigned int FEE, const unsigned int FEEChannel, const unsigned int /* packetid */) 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 /* packetid */) 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 /* packetid */) 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 /* packetid */) 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 }