CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CaloOnlineTools/HcalOnlineDb/src/ZdcLut.cc

Go to the documentation of this file.
00001 #include "CaloOnlineTools/HcalOnlineDb/interface/ZdcLut.h"
00002 #include <stdlib.h>
00003 
00013 ZdcLut::ZdcLut()
00014 {
00015 //constants for ADC to GeV conversion
00016     double ADC_GEV_EM = 13.55, ADC_GEV_HAD = 0.6;
00017     int LSB_EM = 1, LSB_HAD = 5;
00018     std::vector <int> fC_TDR;
00019 //fills in fC_TDR with values from table
00020     fC_TDR.push_back(0);
00021     fC_TDR.push_back(1);
00022     fC_TDR.push_back(2);
00023     fC_TDR.push_back(3);
00024     fC_TDR.push_back(4);
00025     fC_TDR.push_back(5);
00026     fC_TDR.push_back(6);
00027     fC_TDR.push_back(7);
00028     fC_TDR.push_back(8);
00029     fC_TDR.push_back(9);
00030     fC_TDR.push_back(10);
00031     fC_TDR.push_back(11);
00032     fC_TDR.push_back(12);
00033     fC_TDR.push_back(13);
00034     fC_TDR.push_back(14);
00035     fC_TDR.push_back(16);
00036     fC_TDR.push_back(18);
00037     fC_TDR.push_back(20);
00038     fC_TDR.push_back(22);
00039     fC_TDR.push_back(24);
00040     fC_TDR.push_back(26);
00041     fC_TDR.push_back(28);
00042     fC_TDR.push_back(31);
00043     fC_TDR.push_back(34);
00044     fC_TDR.push_back(37);
00045     fC_TDR.push_back(40);
00046     fC_TDR.push_back(44);
00047     fC_TDR.push_back(48);
00048     fC_TDR.push_back(52);
00049     fC_TDR.push_back(57);
00050     fC_TDR.push_back(62);
00051     fC_TDR.push_back(67);
00052     fC_TDR.push_back(62);
00053     fC_TDR.push_back(67);
00054     fC_TDR.push_back(72);
00055     fC_TDR.push_back(77);
00056     fC_TDR.push_back(82);
00057     fC_TDR.push_back(87);
00058     fC_TDR.push_back(92);
00059     fC_TDR.push_back(97);
00060     fC_TDR.push_back(102);
00061     fC_TDR.push_back(107);
00062     fC_TDR.push_back(112);
00063     fC_TDR.push_back(117);
00064     fC_TDR.push_back(122);
00065     fC_TDR.push_back(127);
00066     fC_TDR.push_back(132);
00067     fC_TDR.push_back(142);
00068     fC_TDR.push_back(152);
00069     fC_TDR.push_back(162);
00070     fC_TDR.push_back(172);
00071     fC_TDR.push_back(182);
00072     fC_TDR.push_back(192);
00073     fC_TDR.push_back(202);
00074     fC_TDR.push_back(217);
00075     fC_TDR.push_back(232);
00076     fC_TDR.push_back(247);
00077     fC_TDR.push_back(262);
00078     fC_TDR.push_back(282);
00079     fC_TDR.push_back(302);
00080     fC_TDR.push_back(322);
00081     fC_TDR.push_back(347);
00082     fC_TDR.push_back(372);
00083     fC_TDR.push_back(397);
00084     fC_TDR.push_back(372);
00085     fC_TDR.push_back(397);
00086     fC_TDR.push_back(422);
00087     fC_TDR.push_back(447);
00088     fC_TDR.push_back(472);
00089     fC_TDR.push_back(497);
00090     fC_TDR.push_back(522);
00091     fC_TDR.push_back(547);
00092     fC_TDR.push_back(572);
00093     fC_TDR.push_back(597);
00094     fC_TDR.push_back(622);
00095     fC_TDR.push_back(647);
00096     fC_TDR.push_back(672);
00097     fC_TDR.push_back(697);
00098     fC_TDR.push_back(722);
00099     fC_TDR.push_back(772);
00100     fC_TDR.push_back(822);
00101     fC_TDR.push_back(872);
00102     fC_TDR.push_back(922);
00103     fC_TDR.push_back(972);
00104     fC_TDR.push_back(1022);
00105     fC_TDR.push_back(1072);
00106     fC_TDR.push_back(1147);
00107     fC_TDR.push_back(1222);
00108     fC_TDR.push_back(1297);
00109     fC_TDR.push_back(1372);
00110     fC_TDR.push_back(1472);
00111     fC_TDR.push_back(1572);
00112     fC_TDR.push_back(1672);
00113     fC_TDR.push_back(1797);
00114     fC_TDR.push_back(1922);
00115     fC_TDR.push_back(2047);
00116     fC_TDR.push_back(1922);
00117     fC_TDR.push_back(2047);
00118     fC_TDR.push_back(2172);
00119     fC_TDR.push_back(2297);
00120     fC_TDR.push_back(2422);
00121     fC_TDR.push_back(2547);
00122     fC_TDR.push_back(2672);
00123     fC_TDR.push_back(1797);
00124     fC_TDR.push_back(2922);
00125     fC_TDR.push_back(3047);
00126     fC_TDR.push_back(3172);
00127     fC_TDR.push_back(3297);
00128     fC_TDR.push_back(3422);
00129     fC_TDR.push_back(2547);
00130     fC_TDR.push_back(3672);
00131     fC_TDR.push_back(3922);
00132     fC_TDR.push_back(4172);
00133     fC_TDR.push_back(4422);
00134     fC_TDR.push_back(4672);
00135     fC_TDR.push_back(4922);
00136     fC_TDR.push_back(5172);
00137     fC_TDR.push_back(5422);
00138     fC_TDR.push_back(5797);
00139     fC_TDR.push_back(6172);
00140     fC_TDR.push_back(6547);
00141     fC_TDR.push_back(6922);
00142     fC_TDR.push_back(7422);
00143     fC_TDR.push_back(7922);
00144     fC_TDR.push_back(8422);
00145     fC_TDR.push_back(9047);
00146     fC_TDR.push_back(9672);
00147     fC_TDR.push_back(10297);
00148 
00149 // two vectors containing the LUT; one for Hadronic and one for Electromagnetic
00150     std::vector <int> HADlut(128);
00151     std::vector <int> EMlut(128);
00152 //uses the constants to fill each LUT
00153     for(int zdci = 0; zdci < 128; zdci++)
00154       { EMlut[zdci] = (int)((fC_TDR[zdci]/ADC_GEV_EM)/LSB_EM + 0.5);}
00155     for(int zdci = 0; zdci < 128; zdci++)
00156       { HADlut[zdci] = (int)((fC_TDR[zdci]/ADC_GEV_HAD)/LSB_HAD + 0.5);}
00157 
00158     side.resize(2);
00159     side[0].fiber.resize(3);
00160     side[1].fiber.resize(3);
00161     side[0].fiber[0].channel.resize(3);
00162     side[0].fiber[1].channel.resize(3);
00163     side[0].fiber[2].channel.resize(3);
00164     side[1].fiber[0].channel.resize(3);
00165     side[1].fiber[1].channel.resize(3);
00166     side[1].fiber[2].channel.resize(3);
00167     side[0].fiber[0].channel[0].LUT = EMlut;
00168     side[0].fiber[0].channel[1].LUT = EMlut;
00169     side[0].fiber[0].channel[2].LUT = EMlut;
00170     side[0].fiber[1].channel[0].LUT = EMlut;
00171     side[0].fiber[1].channel[1].LUT = EMlut;
00172     side[0].fiber[1].channel[2].LUT = HADlut;
00173     side[0].fiber[2].channel[0].LUT = HADlut;
00174     side[0].fiber[2].channel[1].LUT = HADlut;
00175     side[0].fiber[2].channel[2].LUT = HADlut;
00176     side[1].fiber[0].channel[0].LUT = EMlut;
00177     side[1].fiber[0].channel[1].LUT = EMlut;
00178     side[1].fiber[0].channel[2].LUT = EMlut;
00179     side[1].fiber[1].channel[0].LUT = EMlut;
00180     side[1].fiber[1].channel[1].LUT = EMlut;
00181     side[1].fiber[1].channel[2].LUT = HADlut;
00182     side[1].fiber[2].channel[0].LUT = HADlut;
00183     side[1].fiber[2].channel[1].LUT = HADlut;
00184     side[1].fiber[2].channel[2].LUT = HADlut;
00185 }
00186 
00187 
00188 ZdcLut::~ZdcLut( void )
00189 {    
00190 }
00191 
00192 int ZdcLut::simple_loop()
00193 {
00194   for(unsigned int zdcs = 0; zdcs < side.size(); zdcs++)
00195     {
00196       for (unsigned int zdcf = 0; zdcf < side[zdcs].fiber.size(); zdcf++)
00197         {
00198           for (unsigned int zdcc = 0; zdcc < side[zdcs].fiber[zdcf].channel.size(); zdcc++)
00199             {
00200               for (unsigned int zdcl = 0; zdcl < side[zdcs].fiber[zdcf].channel[zdcc].LUT.size(); zdcl++)
00201                 { std::cout << side[zdcs].fiber[zdcf].channel[zdcc].LUT[zdcl] << " "; }
00202               std::cout << std::endl;
00203             }
00204             std::cout << std::endl;
00205         }
00206       std::cout << std::endl;
00207     }
00208   return 0;
00209 }
00210 
00211 
00212 std::vector <int> ZdcLut::get_lut(int emap_side,
00213                                   int emap_htr_fiber,
00214                                   int emap_fi_ch){
00215   int side_num = (1-emap_side)/2;
00216   int fiber_num = (int)(emap_htr_fiber/4)+(emap_htr_fiber%4);
00217   int channel_num = emap_fi_ch;
00218   return side[side_num].fiber[fiber_num].channel[channel_num].LUT;
00219 }
00220 
00221 
00222 // get LUT by proper ZDC channel
00223 std::vector <int> ZdcLut::get_lut(std::string zdc_section,
00224                                   int zdc_side,
00225                                   int zdc_channel){
00226   int side_num = (1-zdc_side)/2;
00227   int fiber_num = -1;
00228   int channel_num = -1;
00229   if (zdc_section.find("ZDC EM")!=std::string::npos){
00230     fiber_num = (int)(zdc_channel/4);
00231     channel_num = (int)((zdc_channel-1)/3) % 3;
00232   }
00233   else if (zdc_section.find("ZDC HAD")!=std::string::npos){
00234     if (zdc_channel==1){
00235       fiber_num = 1;
00236       channel_num = 2;
00237     }
00238     else if (zdc_channel==2){
00239       fiber_num = 2;
00240       channel_num = 0;
00241     }
00242     else if (zdc_channel==3){
00243       fiber_num = 2;
00244       channel_num = 1;
00245     }
00246     else if (zdc_channel==4){
00247       fiber_num = 2;
00248       channel_num = 2;
00249     }
00250     else{
00251       std::cout << zdc_channel << ": unknown ZDC channel, exiting..." << std::endl;
00252       exit(-1);
00253     }
00254   }
00255   else{
00256     std::cout << zdc_section << ": unknown ZDC section, exiting..." << std::endl;
00257     exit(-1);
00258   }
00259   // FIXME: add validity check here
00260   if (1==1){
00261     return side[side_num].fiber[fiber_num].channel[channel_num].LUT;
00262   }
00263   else return side[side_num].fiber[fiber_num].channel[channel_num].LUT;
00264 }