Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:55

0001 #include "PHG4CellDefs.h"
0002 
0003 #include <phool/phool.h>
0004 
0005 #include <cstdlib>  // for exit
0006 #include <iostream>
0007 
0008 using namespace std;
0009 
0010 unsigned short
0011 generic_lower_16bit_key(const PHG4CellDefs::keytype key, const PHG4CellDefs::CellBinning binning);
0012 
0013 unsigned short
0014 generic_upper_16bit_key(const PHG4CellDefs::keytype key, const PHG4CellDefs::CellBinning binning);
0015 
0016 unsigned int
0017 generic_32bit_key(const PHG4CellDefs::keytype key, const PHG4CellDefs::CellBinning binning);
0018 
0019 PHG4CellDefs::keytype
0020 generic_16bit_genkey(const unsigned short detid, const PHG4CellDefs::CellBinning binning, const unsigned short upper16bits, const unsigned short lower16bits);
0021 
0022 PHG4CellDefs::keytype
0023 generic_32bit_genkey(const unsigned short detid, const PHG4CellDefs::CellBinning binning, const unsigned int bit32);
0024 
0025 PHG4CellDefs::keytype
0026 PHG4CellDefs::SizeBinning::genkey(const unsigned short detid, const unsigned short zbin, const unsigned short iphi)
0027 {
0028   PHG4CellDefs::keytype key = generic_16bit_genkey(detid, sizebinning, zbin, iphi);
0029   return key;
0030 }
0031 
0032 unsigned short int
0033 PHG4CellDefs::SizeBinning::get_phibin(const PHG4CellDefs::keytype key)
0034 {
0035   unsigned short int phibin = generic_lower_16bit_key(key, sizebinning);
0036   return phibin;
0037 }
0038 
0039 unsigned short int
0040 PHG4CellDefs::SizeBinning::get_zbin(const PHG4CellDefs::keytype key)
0041 {
0042   unsigned short int zbin = generic_upper_16bit_key(key, sizebinning);
0043   return zbin;
0044 }
0045 
0046 PHG4CellDefs::keytype
0047 PHG4CellDefs::EtaPhiBinning::genkey(const unsigned short detid, const unsigned short iphi, const unsigned short ieta)
0048 {
0049   PHG4CellDefs::keytype key = generic_16bit_genkey(detid, etaphibinning, iphi, ieta);
0050   return key;
0051 }
0052 
0053 unsigned short int
0054 PHG4CellDefs::EtaPhiBinning::get_etabin(const PHG4CellDefs::keytype key)
0055 {
0056   unsigned short int etabin = generic_lower_16bit_key(key, etaphibinning);
0057   return etabin;
0058 }
0059 
0060 unsigned short int
0061 PHG4CellDefs::EtaPhiBinning::get_phibin(const PHG4CellDefs::keytype key)
0062 {
0063   unsigned short int phibin = generic_upper_16bit_key(key, etaphibinning);
0064   return phibin;
0065 }
0066 
0067 PHG4CellDefs::keytype
0068 PHG4CellDefs::SpacalBinning::genkey(const unsigned short etabin, const unsigned short phibin, const unsigned short fiberid)
0069 {
0070   PHG4CellDefs::keytype key = generic_16bit_genkey(etabin, spacalbinning, phibin, fiberid);
0071   return key;
0072 }
0073 
0074 unsigned short int
0075 PHG4CellDefs::SpacalBinning::get_etabin(const PHG4CellDefs::keytype key)
0076 {
0077   unsigned long long tmp = key >> 48U;
0078   unsigned short int etabin = tmp;
0079   return etabin;
0080 }
0081 
0082 unsigned short int
0083 PHG4CellDefs::SpacalBinning::get_phibin(const PHG4CellDefs::keytype key)
0084 {
0085   unsigned short int phibin = generic_upper_16bit_key(key, spacalbinning);
0086   return phibin;
0087 }
0088 
0089 unsigned short int
0090 PHG4CellDefs::SpacalBinning::get_fiberid(const PHG4CellDefs::keytype key)
0091 {
0092   unsigned short int fiberid = generic_lower_16bit_key(key, spacalbinning);
0093   return fiberid;
0094 }
0095 
0096 // yes the arguments are flipped but it is consistent later on
0097 // changing this would just be a real headache
0098 // cppcheck-suppress funcArgOrderDifferent
0099 PHG4CellDefs::keytype PHG4CellDefs::ScintillatorSlatBinning::genkey(const unsigned short detid, const unsigned short icolumn, const unsigned short irow)
0100 {
0101   PHG4CellDefs::keytype key = generic_16bit_genkey(detid, scintillatorslatbinning, icolumn, irow);
0102   return key;
0103 }
0104 
0105 unsigned short int
0106 PHG4CellDefs::ScintillatorSlatBinning::get_row(const PHG4CellDefs::keytype key)
0107 {
0108   unsigned short int rowbin = generic_lower_16bit_key(key, scintillatorslatbinning);
0109   return rowbin;
0110 }
0111 
0112 unsigned short int
0113 PHG4CellDefs::ScintillatorSlatBinning::get_column(const PHG4CellDefs::keytype key)
0114 {
0115   unsigned short int columnbin = generic_upper_16bit_key(key, scintillatorslatbinning);
0116   return columnbin;
0117 }
0118 PHG4CellDefs::keytype
0119 PHG4CellDefs::EtaXsizeBinning::genkey(const unsigned short detid, const unsigned short ixbin, const unsigned short ieta)
0120 {
0121   PHG4CellDefs::keytype key = generic_16bit_genkey(detid, etaxsizebinning, ixbin, ieta);
0122   return key;
0123 }
0124 
0125 unsigned short int
0126 PHG4CellDefs::EtaXsizeBinning::get_etabin(const PHG4CellDefs::keytype key)
0127 {
0128   unsigned short int etabin = generic_lower_16bit_key(key, etaxsizebinning);
0129   return etabin;
0130 }
0131 
0132 unsigned short int
0133 PHG4CellDefs::EtaXsizeBinning::get_xsizebin(const PHG4CellDefs::keytype key)
0134 {
0135   unsigned short int etabin = generic_upper_16bit_key(key, etaxsizebinning);
0136   return etabin;
0137 }
0138 
0139 PHG4CellDefs::keytype
0140 PHG4CellDefs::MVTXBinning::genkey(const unsigned short detid, const unsigned int bit32_index)
0141 {
0142   PHG4CellDefs::keytype key = generic_32bit_genkey(detid, mvtxbinning, bit32_index);
0143   return key;
0144 }
0145 
0146 unsigned int
0147 PHG4CellDefs::MVTXBinning::get_index(const PHG4CellDefs::keytype key)
0148 {
0149   unsigned int index = generic_32bit_key(key, mvtxbinning);
0150   return index;
0151 }
0152 
0153 PHG4CellDefs::keytype
0154 PHG4CellDefs::TPCBinning::genkey(const unsigned short detid, const unsigned short mod, const unsigned short pad)
0155 {
0156   PHG4CellDefs::keytype key = generic_16bit_genkey(detid, tpcbinning, mod, pad);
0157   return key;
0158 }
0159 
0160 unsigned short
0161 PHG4CellDefs::TPCBinning::get_radbin(const PHG4CellDefs::keytype key)
0162 {
0163   unsigned short radbin = generic_lower_16bit_key(key, tpcbinning);
0164   return radbin;
0165 }
0166 
0167 unsigned short
0168 PHG4CellDefs::TPCBinning::get_phibin(const PHG4CellDefs::keytype key)
0169 {
0170   unsigned short phibin = generic_upper_16bit_key(key, tpcbinning);
0171   return phibin;
0172 }
0173 
0174 bool PHG4CellDefs::has_binning(const PHG4CellDefs::keytype key, const PHG4CellDefs::CellBinning binning)
0175 {
0176   keytype tmp = (key >> bitshift_binning) & 0xFFFFU;
0177   if (tmp == binning)
0178   {
0179     return true;
0180   }
0181   return false;
0182 }
0183 
0184 short PHG4CellDefs::get_binning(const PHG4CellDefs::keytype key)
0185 {
0186   keytype tmp = (key >> bitshift_binning) & 0xFFFFU;
0187   short int i = tmp;
0188   return i;
0189 }
0190 
0191 short int
0192 PHG4CellDefs::get_detid(const PHG4CellDefs::keytype key)
0193 {
0194   keytype tmp = (key >> bitshift_layer);
0195   return tmp;
0196 }
0197 
0198 unsigned short
0199 generic_lower_16bit_key(const PHG4CellDefs::keytype key, const PHG4CellDefs::CellBinning binning)
0200 {
0201   // check correct binning first
0202   PHG4CellDefs::keytype tmp = binning;
0203   tmp = (tmp << PHG4CellDefs::bitshift_binning);
0204   if ((key & tmp) == tmp)
0205   {
0206     unsigned short int low16bitkey = (key & 0xFFFFU);
0207     return low16bitkey;
0208   }
0209   cout << PHWHERE << " could not decode 0x" << hex << key << dec << endl;
0210   cout << "key 0x" << hex << key << ", binning: 0x" << tmp
0211        << " and: " << (key & tmp) << dec << endl;
0212   exit(1);
0213 }
0214 
0215 unsigned short
0216 generic_upper_16bit_key(const PHG4CellDefs::keytype key, const PHG4CellDefs::CellBinning binning)
0217 {
0218   // check correct binning first
0219   PHG4CellDefs::keytype tmp = binning;
0220   tmp = (tmp << PHG4CellDefs::bitshift_binning);
0221   if ((key & tmp) == tmp)
0222   {
0223     PHG4CellDefs::keytype keytmp = key >> PHG4CellDefs::bitshift_upperkey;
0224     unsigned short int hi16bitkey = (keytmp & 0xFFFFU);
0225     return hi16bitkey;
0226   }
0227   cout << PHWHERE << " could not decode 0x" << hex << key << dec << endl;
0228   exit(1);
0229 }
0230 
0231 unsigned int
0232 generic_32bit_key(const PHG4CellDefs::keytype key, const PHG4CellDefs::CellBinning binning)
0233 {
0234   // check correct binning first
0235   PHG4CellDefs::keytype tmp = binning;
0236   tmp = (tmp << PHG4CellDefs::bitshift_binning);
0237   if ((key & tmp) == tmp)
0238   {
0239     unsigned int bit32key = (key & 0xFFFFFFFF);
0240     return bit32key;
0241   }
0242   cout << PHWHERE << " could not decode 0x" << hex << key << dec << endl;
0243   exit(1);
0244 }
0245 
0246 PHG4CellDefs::keytype
0247 generic_16bit_genkey(const unsigned short detid, const PHG4CellDefs::CellBinning binning, const unsigned short upper16bits, const unsigned short lower16bits)
0248 {
0249   PHG4CellDefs::keytype tmp = detid;
0250   PHG4CellDefs::keytype key = tmp << PHG4CellDefs::bitshift_layer;  // layer/detector id used by extrating ranges
0251   tmp = binning;
0252   key |= (tmp << PHG4CellDefs::bitshift_binning);  // binning method used to decode the key
0253   tmp = upper16bits;
0254   key |= (tmp << PHG4CellDefs::bitshift_upperkey);  // upper bits used by column, so we can easily extract
0255                                                     // slats by column which are combined to towers
0256   key |= lower16bits;
0257   return key;
0258 }
0259 
0260 PHG4CellDefs::keytype
0261 generic_32bit_genkey(const unsigned short detid, const PHG4CellDefs::CellBinning binning, const unsigned int bit32)
0262 {
0263   PHG4CellDefs::keytype tmp = detid;
0264   PHG4CellDefs::keytype key = tmp << PHG4CellDefs::bitshift_layer;  // layer/detector id used by extrating ranges
0265   tmp = binning;
0266   key |= (tmp << PHG4CellDefs::bitshift_binning);  // binning method used to decode the key
0267   key |= bit32;
0268   return key;
0269 }