Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:46

0001 #include <iostream>
0002 #include <sstream>
0003 #include <vector>
0004 #include <cstdint>
0005 
0006 //
0007 // Pregenerate QIE Shapes using hardcoded arrays
0008 // This is taken directly from CondFormats/HcalObjects/srcHcalQIEData.cc
0009 // This generation is running upon conditions retrieval typically for the cpu workload
0010 //
0011 // For the GPU workload, it is better to put generated values into constant memory.
0012 // Either this or just use global memory (for global mem, we need getters...).
0013 // Choosign constant memory as thsese
0014 // values are statically known and never change. Any change in any case requires
0015 // recompilation!
0016 //
0017 
0018 const float binMin[32] = {-1, 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14,
0019                           16, 18, 20, 22, 24, 26, 28, 31, 34, 37, 40, 44, 48, 52, 57, 62};
0020 
0021 const float binMin2[64] = {-0.5,  0.5,   1.5,   2.5,   3.5,   4.5,   5.5,   6.5,   7.5,   8.5,   9.5,
0022                            10.5,  11.5,  12.5,  13.5,  14.5,  // 16 bins with width 1x
0023                            15.5,  17.5,  19.5,  21.5,  23.5,  25.5,  27.5,  29.5,  31.5,  33.5,  35.5,
0024                            37.5,  39.5,  41.5,  43.5,  45.5,  47.5,  49.5,  51.5,  53.5,  // 20 bins with width 2x
0025                            55.5,  59.5,  63.5,  67.5,  71.5,  75.5,  79.5,  83.5,  87.5,  91.5,  95.5,
0026                            99.5,  103.5, 107.5, 111.5, 115.5, 119.5, 123.5, 127.5, 131.5, 135.5,  // 21 bins with width 4x
0027                            139.5, 147.5, 155.5, 163.5, 171.5, 179.5, 187.5};  // 7 bins with width 8x
0028 
0029 constexpr uint32_t nbins_qie8 = 32;
0030 constexpr uint32_t nbins_qie11 = 64;
0031 
0032 void dump(std::vector<float> const& vec, std::string const& name) {
0033   std::stringstream str;
0034   str << "float const " << name << "[" << vec.size() << "] = {";
0035   uint32_t counter = 0;
0036   for (auto const& value : vec) {
0037     if (counter % 8 == 0)
0038       str << std::endl;
0039     if (counter == vec.size() - 1)
0040       str << value;
0041     else
0042       str << value << ", ";
0043     counter++;
0044   }
0045   str << "};";
0046   std::cout << str.str() << std::endl;
0047 }
0048 
0049 void generate(uint32_t const nbins, float const* initValues, std::vector<float>& values) {
0050   // preset the first range
0051   for (uint32_t adc = 0; adc < nbins; adc++)
0052     values[adc] = initValues[adc];
0053 
0054   // do the rest
0055   int scale = 1;
0056   for (uint32_t range = 1; range < 4; range++) {
0057     int factor = nbins == 32 ? 5 : 8;
0058     scale *= factor;
0059 
0060     auto const index_offset = range * nbins;
0061     uint32_t const overlap = nbins == 32 ? 2 : 3;
0062     values[index_offset] = values[index_offset - overlap];
0063 
0064     for (uint32_t i = 1; i < nbins; i++)
0065       values[index_offset + i] = values[index_offset + i - 1] + scale * (values[i] - values[i - 1]);
0066   }
0067 
0068   values[nbins * 4] = 2 * values[nbins * 4 - 1] - values[nbins * 4 - 2];
0069 }
0070 
0071 int main(int argc, char* argv[]) {
0072   //
0073   // run 128 bins
0074   //
0075   std::vector<float> valuesqie8(nbins_qie8 * 4 + 1), valuesqie11(nbins_qie11 * 4 + 1);
0076   generate(nbins_qie8, binMin, valuesqie8);
0077   generate(nbins_qie11, binMin2, valuesqie11);
0078 
0079   dump(valuesqie8, std::string{"qie8shape"});
0080   dump(valuesqie11, std::string{"qie11shape"});
0081 
0082   return 0;
0083 }