Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:15:09

0001 #include "CaloOnlineTools/HcalOnlineDb/interface/ZdcLut.h"
0002 #include <cstdlib>
0003 
0004 /**
0005 
0006    \class ZdcLut
0007    \brief Generation of ZDC Lookup tables and associate helper methods
0008    \brief Adopted to CMSSW HCAL LUT manager specs
0009    \brief by Gena Kukartsev, Brown University, Dec 08, 2009
0010    \author Elijah Dunn
0011 */
0012 
0013 ZdcLut::ZdcLut() {
0014   //constants for ADC to GeV conversion
0015   double ADC_GEV_EM = 13.55, ADC_GEV_HAD = 0.6;
0016   int LSB_EM = 1, LSB_HAD = 5;
0017   std::vector<int> fC_TDR;
0018   //fills in fC_TDR with values from table
0019   fC_TDR.push_back(0);
0020   fC_TDR.push_back(1);
0021   fC_TDR.push_back(2);
0022   fC_TDR.push_back(3);
0023   fC_TDR.push_back(4);
0024   fC_TDR.push_back(5);
0025   fC_TDR.push_back(6);
0026   fC_TDR.push_back(7);
0027   fC_TDR.push_back(8);
0028   fC_TDR.push_back(9);
0029   fC_TDR.push_back(10);
0030   fC_TDR.push_back(11);
0031   fC_TDR.push_back(12);
0032   fC_TDR.push_back(13);
0033   fC_TDR.push_back(14);
0034   fC_TDR.push_back(16);
0035   fC_TDR.push_back(18);
0036   fC_TDR.push_back(20);
0037   fC_TDR.push_back(22);
0038   fC_TDR.push_back(24);
0039   fC_TDR.push_back(26);
0040   fC_TDR.push_back(28);
0041   fC_TDR.push_back(31);
0042   fC_TDR.push_back(34);
0043   fC_TDR.push_back(37);
0044   fC_TDR.push_back(40);
0045   fC_TDR.push_back(44);
0046   fC_TDR.push_back(48);
0047   fC_TDR.push_back(52);
0048   fC_TDR.push_back(57);
0049   fC_TDR.push_back(62);
0050   fC_TDR.push_back(67);
0051   fC_TDR.push_back(62);
0052   fC_TDR.push_back(67);
0053   fC_TDR.push_back(72);
0054   fC_TDR.push_back(77);
0055   fC_TDR.push_back(82);
0056   fC_TDR.push_back(87);
0057   fC_TDR.push_back(92);
0058   fC_TDR.push_back(97);
0059   fC_TDR.push_back(102);
0060   fC_TDR.push_back(107);
0061   fC_TDR.push_back(112);
0062   fC_TDR.push_back(117);
0063   fC_TDR.push_back(122);
0064   fC_TDR.push_back(127);
0065   fC_TDR.push_back(132);
0066   fC_TDR.push_back(142);
0067   fC_TDR.push_back(152);
0068   fC_TDR.push_back(162);
0069   fC_TDR.push_back(172);
0070   fC_TDR.push_back(182);
0071   fC_TDR.push_back(192);
0072   fC_TDR.push_back(202);
0073   fC_TDR.push_back(217);
0074   fC_TDR.push_back(232);
0075   fC_TDR.push_back(247);
0076   fC_TDR.push_back(262);
0077   fC_TDR.push_back(282);
0078   fC_TDR.push_back(302);
0079   fC_TDR.push_back(322);
0080   fC_TDR.push_back(347);
0081   fC_TDR.push_back(372);
0082   fC_TDR.push_back(397);
0083   fC_TDR.push_back(372);
0084   fC_TDR.push_back(397);
0085   fC_TDR.push_back(422);
0086   fC_TDR.push_back(447);
0087   fC_TDR.push_back(472);
0088   fC_TDR.push_back(497);
0089   fC_TDR.push_back(522);
0090   fC_TDR.push_back(547);
0091   fC_TDR.push_back(572);
0092   fC_TDR.push_back(597);
0093   fC_TDR.push_back(622);
0094   fC_TDR.push_back(647);
0095   fC_TDR.push_back(672);
0096   fC_TDR.push_back(697);
0097   fC_TDR.push_back(722);
0098   fC_TDR.push_back(772);
0099   fC_TDR.push_back(822);
0100   fC_TDR.push_back(872);
0101   fC_TDR.push_back(922);
0102   fC_TDR.push_back(972);
0103   fC_TDR.push_back(1022);
0104   fC_TDR.push_back(1072);
0105   fC_TDR.push_back(1147);
0106   fC_TDR.push_back(1222);
0107   fC_TDR.push_back(1297);
0108   fC_TDR.push_back(1372);
0109   fC_TDR.push_back(1472);
0110   fC_TDR.push_back(1572);
0111   fC_TDR.push_back(1672);
0112   fC_TDR.push_back(1797);
0113   fC_TDR.push_back(1922);
0114   fC_TDR.push_back(2047);
0115   fC_TDR.push_back(1922);
0116   fC_TDR.push_back(2047);
0117   fC_TDR.push_back(2172);
0118   fC_TDR.push_back(2297);
0119   fC_TDR.push_back(2422);
0120   fC_TDR.push_back(2547);
0121   fC_TDR.push_back(2672);
0122   fC_TDR.push_back(1797);
0123   fC_TDR.push_back(2922);
0124   fC_TDR.push_back(3047);
0125   fC_TDR.push_back(3172);
0126   fC_TDR.push_back(3297);
0127   fC_TDR.push_back(3422);
0128   fC_TDR.push_back(2547);
0129   fC_TDR.push_back(3672);
0130   fC_TDR.push_back(3922);
0131   fC_TDR.push_back(4172);
0132   fC_TDR.push_back(4422);
0133   fC_TDR.push_back(4672);
0134   fC_TDR.push_back(4922);
0135   fC_TDR.push_back(5172);
0136   fC_TDR.push_back(5422);
0137   fC_TDR.push_back(5797);
0138   fC_TDR.push_back(6172);
0139   fC_TDR.push_back(6547);
0140   fC_TDR.push_back(6922);
0141   fC_TDR.push_back(7422);
0142   fC_TDR.push_back(7922);
0143   fC_TDR.push_back(8422);
0144   fC_TDR.push_back(9047);
0145   fC_TDR.push_back(9672);
0146   fC_TDR.push_back(10297);
0147 
0148   // two vectors containing the LUT; one for Hadronic and one for Electromagnetic
0149   std::vector<int> HADlut(128);
0150   std::vector<int> EMlut(128);
0151   //uses the constants to fill each LUT
0152   for (int zdci = 0; zdci < 128; zdci++) {
0153     EMlut[zdci] = (int)((fC_TDR[zdci] / ADC_GEV_EM) / LSB_EM + 0.5);
0154   }
0155   for (int zdci = 0; zdci < 128; zdci++) {
0156     HADlut[zdci] = (int)((fC_TDR[zdci] / ADC_GEV_HAD) / LSB_HAD + 0.5);
0157   }
0158 
0159   side.resize(2);
0160   side[0].fiber.resize(3);
0161   side[1].fiber.resize(3);
0162   side[0].fiber[0].channel.resize(3);
0163   side[0].fiber[1].channel.resize(3);
0164   side[0].fiber[2].channel.resize(3);
0165   side[1].fiber[0].channel.resize(3);
0166   side[1].fiber[1].channel.resize(3);
0167   side[1].fiber[2].channel.resize(3);
0168   side[0].fiber[0].channel[0].LUT = EMlut;
0169   side[0].fiber[0].channel[1].LUT = EMlut;
0170   side[0].fiber[0].channel[2].LUT = EMlut;
0171   side[0].fiber[1].channel[0].LUT = EMlut;
0172   side[0].fiber[1].channel[1].LUT = EMlut;
0173   side[0].fiber[1].channel[2].LUT = HADlut;
0174   side[0].fiber[2].channel[0].LUT = HADlut;
0175   side[0].fiber[2].channel[1].LUT = HADlut;
0176   side[0].fiber[2].channel[2].LUT = HADlut;
0177   side[1].fiber[0].channel[0].LUT = EMlut;
0178   side[1].fiber[0].channel[1].LUT = EMlut;
0179   side[1].fiber[0].channel[2].LUT = EMlut;
0180   side[1].fiber[1].channel[0].LUT = EMlut;
0181   side[1].fiber[1].channel[1].LUT = EMlut;
0182   side[1].fiber[1].channel[2].LUT = HADlut;
0183   side[1].fiber[2].channel[0].LUT = HADlut;
0184   side[1].fiber[2].channel[1].LUT = HADlut;
0185   side[1].fiber[2].channel[2].LUT = HADlut;
0186 }
0187 
0188 ZdcLut::~ZdcLut(void) {}
0189 
0190 int ZdcLut::simple_loop() {
0191   for (unsigned int zdcs = 0; zdcs < side.size(); zdcs++) {
0192     for (unsigned int zdcf = 0; zdcf < side[zdcs].fiber.size(); zdcf++) {
0193       for (unsigned int zdcc = 0; zdcc < side[zdcs].fiber[zdcf].channel.size(); zdcc++) {
0194         for (unsigned int zdcl = 0; zdcl < side[zdcs].fiber[zdcf].channel[zdcc].LUT.size(); zdcl++) {
0195           std::cout << side[zdcs].fiber[zdcf].channel[zdcc].LUT[zdcl] << " ";
0196         }
0197         std::cout << std::endl;
0198       }
0199       std::cout << std::endl;
0200     }
0201     std::cout << std::endl;
0202   }
0203   return 0;
0204 }
0205 
0206 std::vector<int> ZdcLut::get_lut(int emap_side, int emap_htr_fiber, int emap_fi_ch) {
0207   int side_num = (1 - emap_side) / 2;
0208   int fiber_num = (int)(emap_htr_fiber / 4) + (emap_htr_fiber % 4);
0209   int channel_num = emap_fi_ch;
0210   return side[side_num].fiber[fiber_num].channel[channel_num].LUT;
0211 }
0212 
0213 // get LUT by proper ZDC channel
0214 std::vector<int> ZdcLut::get_lut(std::string zdc_section, int zdc_side, int zdc_channel) {
0215   int side_num = (1 - zdc_side) / 2;
0216   int fiber_num = -1;
0217   int channel_num = -1;
0218   if (zdc_section.find("ZDC EM") != std::string::npos) {
0219     fiber_num = (int)(zdc_channel / 4);
0220     channel_num = (int)((zdc_channel - 1) / 3) % 3;
0221   } else if (zdc_section.find("ZDC HAD") != std::string::npos) {
0222     if (zdc_channel == 1) {
0223       fiber_num = 1;
0224       channel_num = 2;
0225     } else if (zdc_channel == 2) {
0226       fiber_num = 2;
0227       channel_num = 0;
0228     } else if (zdc_channel == 3) {
0229       fiber_num = 2;
0230       channel_num = 1;
0231     } else if (zdc_channel == 4) {
0232       fiber_num = 2;
0233       channel_num = 2;
0234     } else {
0235       std::cout << zdc_channel << ": unknown ZDC channel, exiting..." << std::endl;
0236       exit(-1);
0237     }
0238   } else {
0239     std::cout << zdc_section << ": unknown ZDC section, exiting..." << std::endl;
0240     exit(-1);
0241   }
0242   // FIXME: add validity check here
0243   if (1 == 1) {
0244     return side[side_num].fiber[fiber_num].channel[channel_num].LUT;
0245   } else
0246     return side[side_num].fiber[fiber_num].channel[channel_num].LUT;
0247 }