GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
CoincidenceMatrixPair.hh
Go to the documentation of this file.
1#ifndef GAMRSORT_COINCIDENCEMATRIXPAIR_HH
2#define GAMRSORT_COINCIDENCEMATRIXPAIR_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 std::string IDX;
25 std::string IDY;
26
27public:
28 CoincidenceMatrixPair(Sorter *parent, std::vector<std::string> opts) : p(parent)
29 {
30 if (opts.size() < 5)
31 throw std::runtime_error("Invalid arguments, expect: Prefix GroupX GroupY IDX IDY");
32 Prefix = opts[0];
33 GroupX = opts[1];
34 GroupY = opts[2];
35 IDX = opts[3];
36 IDY = opts[4];
37 std::string name(Prefix + "_g" + GroupX + "m" + X + "id" + IDX + "g" + GroupY + "m" + Y + "id" + IDY);
38 ptrMatrix = p->GetMatrix(name);
39 ptrMatrix->SetBins(4096, 0, 4096, 4096, 0, 4096);
40 }
41
42 void operator()(TTreeReader &R)
43 {
44 TTreeReaderValue<std::vector<DetX>> rDetsX(R, ("DetGroup._" + GroupX).c_str());
45 TTreeReaderValue<std::vector<DetY>> rDetsY(R, ("DetGroup._" + GroupY).c_str());
46 while (R.Next() && !p->Done()) {
47 p->Tick();
48 std::vector<DetX> vecDetsX = *rDetsX;
49 std::vector<DetY> vecDetsY = *rDetsY;
50 if (vecDetsX.size() + vecDetsY.size() < 2) {
51 continue;
52 }
53 for (auto &Det1 : vecDetsX) {
54 for (auto &Det2 : vecDetsY) {
55 if ((Det1.ID != std::stoi(IDX)) || (Det2.ID != std::stoi(IDY))) {
56 continue;
57 }
58 auto x = Det1.template GetCal<X>();
59 auto y = Det2.template GetCal<Y>();
60 if (!(x && y)) {
61 continue;
62 }
63 ptrMatrix->Fill(x, y);
64 } // fold 2
65 } // fold 1
66 } // all events
67 } // Sorter::CoincidenceMatrix::operator()
68};
69
70} // namespace Type
71} // namespace Sort
72} // namespace GamR
73
74#endif
CoincidenceMatrixPair(Sorter *parent, std::vector< std::string > opts)
Definition Gain.cc:19