File indexing completed on 2024-04-06 12:04:21
0001 #include "DataFormats/HGCDigi/interface/HGCSample.h"
0002 #include <iostream>
0003 #include <cassert>
0004 #include <string>
0005 #include <chrono>
0006 #include <random>
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 int main(int argc, char** argv) {
0017 std::cout << "Basic performance tests for HGCSample (pseudo-random seed set according to local time)\n" << std::endl;
0018 std::cout << "num parameters entered: " << argc << std::endl;
0019
0020
0021 unsigned long int repetitions = 100;
0022 if (argc > 1)
0023 repetitions = std::stoul(argv[1], nullptr, 0);
0024 std::cout << "\t + repetitions [int]: " << repetitions << std::endl;
0025
0026
0027 bool generateRandomValues = (argc > 2 ? true : false);
0028 std::cout << "\t + generateRandomValues [true/false]: " << generateRandomValues << "\n" << std::endl;
0029
0030
0031 uint32_t adc = 124;
0032 uint32_t gain = 15;
0033 const uint32_t thrADC = 900;
0034 bool thr = adc > thrADC;
0035 uint32_t toa = 0;
0036 bool mode = false;
0037 bool toaFired = true;
0038
0039
0040 unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
0041 std::minstd_rand0 myrand(seed1);
0042
0043
0044 unsigned long int u = 0;
0045 for (; u < repetitions; u++) {
0046
0047 if (generateRandomValues) {
0048 adc = myrand() % 4096;
0049 toa = myrand() % 1024;
0050 gain = myrand() % 16;
0051 mode = myrand() % 2;
0052 thr = myrand() % 2;
0053 toaFired = myrand() % 2;
0054 }
0055
0056 HGCSample aSample;
0057
0058 aSample.set(thr, mode, gain, toa, adc);
0059 aSample.setToAValid(toaFired);
0060
0061 assert(thr == aSample.threshold());
0062 assert(mode == aSample.mode());
0063 assert(toa == aSample.toa());
0064 assert(gain == aSample.gain());
0065 assert(adc == aSample.data());
0066 assert(thr == aSample.threshold());
0067 assert(toaFired == aSample.getToAValid());
0068
0069
0070
0071
0072 HGCSample ASample;
0073 ASample.setThreshold(thr);
0074 ASample.setMode(mode);
0075 ASample.setGain(gain);
0076 ASample.setToA(toa);
0077 ASample.setData(adc);
0078 ASample.setToAValid(toaFired);
0079
0080 assert(ASample.threshold() == aSample.threshold());
0081 assert(ASample.mode() == aSample.mode());
0082 assert(ASample.gain() == aSample.gain());
0083 assert(ASample.toa() == aSample.toa());
0084 assert(ASample.data() == aSample.data());
0085 assert(ASample.getToAValid() == aSample.getToAValid());
0086
0087 HGCSample bSample;
0088 bSample.setThreshold(thr);
0089 bSample.setMode(mode);
0090 bSample.setGain(gain + 100);
0091 bSample.setToA(toa + 100);
0092 bSample.setData(adc + 100);
0093 bSample.setToAValid(toaFired);
0094
0095
0096 bSample.setThreshold(thr);
0097 bSample.setMode(mode);
0098 bSample.setGain(gain);
0099 bSample.setToA(toa);
0100 bSample.setData(adc);
0101 bSample.setToAValid(toaFired);
0102 assert(thr == aSample.threshold() && thr == bSample.threshold());
0103 assert(mode == aSample.mode() && mode == bSample.mode());
0104 assert(gain == aSample.gain() && gain == bSample.gain());
0105 assert(toa == aSample.toa() && toa == bSample.toa());
0106 assert(adc == aSample.data() && adc == bSample.data());
0107 assert(toaFired == aSample.getToAValid() && toaFired == bSample.getToAValid());
0108 }
0109
0110 std::cout << "\nDone " << repetitions << "\t" << u << std::endl;
0111
0112 return 0;
0113 }