GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
CoincidenceMatrix.hh
Go to the documentation of this file.
1#ifndef GAMRSORT_COINCIDENCEMATRIX_HH
2#define GAMRSORT_COINCIDENCEMATRIX_HH
3
4#include "Sorter.hh"
5
6#include <string>
7#include <vector>
8
9#include <TTreeReader.h>
10#include <TTreeReaderValue.h>
11
12namespace GamR {
13namespace Sort {
14namespace Type {
15
16template <class DetX, class DetY, size_t X, size_t Y>
18private:
19 Sorter *p;
20 std::shared_ptr<TH2D> ptrMatrix;
21 std::string Prefix;
22 std::string GroupX;
23 std::string GroupY;
24
25public:
26 CoincidenceMatrix(Sorter *parent, std::vector<std::string> opts) : p(parent)
27 {
28 if (opts.size() < 3)
29 throw std::length_error("Invalid arguments, expect: Prefix GroupX GroupY");
30 Prefix = opts[0];
31 GroupX = opts[1];
32 GroupY = opts[2];
33 std::string name(Prefix + "_g" + GroupX + "m" + X + "g" + GroupY + "m" + Y);
34 p->SetXsize(4096, 0, 4096);
35 p->SetYsize(4096, 0, 4096);
36 ptrMatrix = p->GetMatrix(name);
37 // ptrMatrix -> SetBins(4096, 0, 4096, 4096, 0, 4096); // made knob.
38 }
39
40 void operator()(TTreeReader &R)
41 {
42 TTreeReaderValue<std::vector<DetX>> rDetsX(R, ("DetGroup._" + GroupX).c_str());
43 TTreeReaderValue<std::vector<DetY>> rDetsY(R, ("DetGroup._" + GroupY).c_str());
44 while (R.Next() && !p->Done()) {
45 p->Tick();
46 std::vector<DetX> vecDetsX = *rDetsX;
47 std::vector<DetY> vecDetsY = *rDetsY;
48 if (vecDetsX.size() + vecDetsY.size() < 2) {
49 continue;
50 }
51 for (auto &Det1 : vecDetsX) {
52 for (auto &Det2 : vecDetsY) {
53 if (Det1.ID == Det2.ID) {
54 continue;
55 }
56 auto x = Det1.template GetCal<X>();
57 auto y = Det2.template GetCal<Y>();
58 if (!(x && y)) {
59 continue;
60 }
61 ptrMatrix->Fill(x, y);
62 } // fold 2
63 } // fold 1
64 } // all events
65 } // Sorter::CoincidenceMatrix::operator()
66};
67
68} // namespace Type
69} // namespace Sort
70} // namespace GamR
71
72#endif
CoincidenceMatrix(Sorter *parent, std::vector< std::string > opts)
Definition Gain.cc:19