test_rates_root.cpp 1.25 KB
Newer Older
Roel Aaij's avatar
Roel Aaij committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <numeric>
#include <iostream>
#include <array>

#include <generate.h>
#include <storage.h>

#include <test_functions.h>

#include <TApplication.h>
#include <TH1.h>
#include <TCanvas.h>

using namespace std;

int main(int argc, char* argv[]) {

   TApplication app{"test_rate", &argc, argv};

   map<bool, unique_ptr<TH1I>> histos;

   array<float, 4> rates{7000., 0., 0., 0.};

   for (bool use_avx2 : {false, true}) {
      string name = string{"diffs_"} + (use_avx2 ? "avx2" : "scalar");
      auto r = histos.emplace(use_avx2, make_unique<TH1I>(name.c_str(), name.c_str(), 100, 0, 1000000));
      auto& time_histo = r.first->second;

      Generators gens{1052, 9523, rates};

      long dt = std::lround(1e8);

      long time_start = 0, time_end = time_start + dt;

      auto [times, values] = generate(time_start, time_end, gens, use_avx2);

      const size_t n_times = times.size();
      for (size_t i = 0; i < n_times - 1; ++i) {
         if (((values[i + 1]) >> 13) == (values[i] >> 13)) {
            time_histo->Fill(times[i + 1] - times[i]);
         }
      }
   }

   TCanvas canvas{"canvas", "canvas", 600, 800};
   canvas.Divide(1, 2);

   for (auto& [arch, histo] : histos) {
      canvas.cd(arch + 1);
      histo->Draw();
   }
   app.Run();
}