GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
GatedTimeDifference.hh
Go to the documentation of this file.
1#ifndef GAMRSORT_GATEDTIMEDIFFERENCE_HH
2#define GAMRSORT_GATEDTIMEDIFFERENCE_HH
3#include "Sorter.hh"
4
5#include <memory>
6#include <sstream>
7#include <string>
8#include <vector>
9
10#include <TH2.h>
11#include <TTreeReader.h>
12#include <TTreeReaderArray.h>
13#include <TTreeReaderValue.h>
14
15#include <nucleus/Photon.hh>
16
17namespace GamR {
18namespace Sort {
19namespace Type {
20
21template <class DetGate, size_t S, class DetTime, size_t E, size_t T>
23private:
24 Sorter *p;
25 std::shared_ptr<TH2D> ptrPkMatrixSum;
26 std::shared_ptr<TH2D> ptrBgMatrixSum;
27 std::shared_ptr<GamR::TK::Gate> ptrGate;
28 std::shared_ptr<GamR::Nucleus::Photon> ptrRefPhoton;
29 std::string gid;
30 std::string gid_gate;
31
32public:
33 GatedTimeDifference(Sorter *parent, std::vector<std::string> opts) : p(parent)
34 {
35 if (opts.size() < 10)
36 throw std::length_error("Invalid arguments, expect: prefix gate_group gate_s gate_S group "
37 "ref_E ref_p ref_P ref_b ref_B");
38
39 std::stringstream ss;
40 std::copy(opts.begin(), opts.end(), std::ostream_iterator<std::string>(ss, "\n"));
41
42 std::string prefix;
43 ss >> prefix;
44 ss >> gid_gate;
45 float siglow;
46 ss >> siglow;
47 float sighigh;
48 ss >> sighigh;
49
50 ss >> gid;
51 float energy;
52 ss >> energy;
53 float pklow;
54 ss >> pklow;
55 float pkhigh;
56 ss >> pkhigh;
57 float bglow;
58 ss >> bglow;
59 float bghigh;
60 ss >> bghigh;
61
62 std::string nameprefix(prefix + "_g" + gid_gate + "w" + S + "_g" + gid + "m" + E + "td" + T);
63
64 ptrGate = std::make_shared<GamR::TK::Gate>(siglow, sighigh);
65 ptrGate->SetName((nameprefix + "G").c_str());
66 p->WriteObject(ptrGate.get());
67
68 ptrRefPhoton = std::make_shared<GamR::Nucleus::Photon>(energy, pklow, pkhigh, bglow, bghigh);
69 ptrRefPhoton->SetName((nameprefix + "R").c_str());
70 p->WriteObject(ptrRefPhoton.get());
71
72 // Create the histogram objects
73 ptrPkMatrixSum = p->GetMatrix((nameprefix + "P").c_str());
74 ptrBgMatrixSum = p->GetMatrix((nameprefix + "B").c_str());
75
76 // Setting bins
77 ptrPkMatrixSum->SetBins(4096, 0, 4096, 8192, -4096, 4096);
78 ptrBgMatrixSum->SetBins(4096, 0, 4096, 8192, -4096, 4096);
79 // ptrPkMatrixSum -> SetCanExtend(TH1::kAllAxes);
80 // ptrBgMatrixSum -> SetCanExtend(TH1::kAllAxes);
81
82 // Set titles
83
84 std::stringstream ssTitle;
85 ssTitle.str("");
86 ssTitle << "Gated(" << siglow << "," << sighigh << ") ";
87 ssTitle << "$E_{1}=" << ptrRefPhoton->GetEnergy() << "$ Gate: $";
88 ssTitle << ptrRefPhoton->GetGate()->GetLow() << "\\to";
89 ssTitle << ptrRefPhoton->GetGate()->GetHigh();
90 ssTitle << "$;Gamma Energy, E_{2}";
91 ssTitle << "[keV];$\\Delta t = t_{2}-t_{1}$";
92
93 ptrPkMatrixSum->SetTitle(ssTitle.str().c_str());
94
95 // Background
96 ssTitle.str("");
97 ssTitle << "Gated(" << siglow << "," << sighigh << ") ";
98 ssTitle << "$E_{1}=" << ptrRefPhoton->GetEnergy() << "$ GateBG: $";
99 ssTitle << ptrRefPhoton->GetGateBG()->GetLow() << "\\to";
100 ssTitle << ptrRefPhoton->GetGateBG()->GetHigh();
101 ssTitle << "$;Gamma Energy, E_{2}";
102 ssTitle << "[keV];$\\Delta t = t_{2}-t_{1}$";
103
104 ptrBgMatrixSum->SetTitle(ssTitle.str().c_str());
105
106 } // Sorter::TimeWalk
107
108 void operator()(TTreeReader &R)
109 {
110 std::string group_gate = "DetGroup._" + gid_gate;
111 std::string group = "DetGroup._" + gid;
112 TTreeReaderValue<std::vector<DetTime>> rdrDets(R, group.c_str());
113 TTreeReaderValue<std::vector<DetGate>> rdrGaters(R, group_gate.c_str());
114 while (R.Next() && !p->Done()) {
115 p->Tick();
116 std::vector<DetGate> vecGaters = *rdrGaters;
117 std::vector<DetTime> vecDets = *rdrDets;
118 // Have enough for triples?
119 if ((vecDets.size() < 2) && (vecDets.size() < 1)) {
120 continue;
121 }
122
123 // Do we fit through the first coincidence window?
124 Bool_t gated = kFALSE;
125 for (auto &gaters : vecGaters) {
126 if (ptrGate->Pass(gaters.template GetCal<S>())) {
127 gated = kTRUE;
128 break;
129 }
130 }
131 if (!gated) {
132 continue;
133 }
134
135 // Great, now project out the time difference
136 for (auto &deti : vecDets) {
137 for (auto &detj : vecDets) {
138 if (deti.ID == detj.ID) {
139 continue;
140 }
141 Bool_t pkgated = ptrRefPhoton->GetGate()->Pass(deti.template GetCal<E>());
142 Bool_t bggated = ptrRefPhoton->GetGateBG()->Pass(deti.template GetCal<E>());
143
144 if ((pkgated || bggated) && (deti.template Get<T>() > 0) && (detj.template Get<T>() > 0)) {
145 // tdiff = T2 - T1 ALWAYS.
146 auto tdiff = detj.template GetCal<T>() - deti.template GetCal<T>();
147 if (pkgated) {
148 ptrPkMatrixSum->Fill(detj.template GetCal<E>(), tdiff);
149 } else if (bggated) {
150 ptrBgMatrixSum->Fill(detj.template GetCal<E>(), tdiff);
151 }
152 } // gated time
153 } // fold 2
154 } // fold 1
155 } // all events
156 } // Sorter::TimeWalk::operator()
157};
158
159} // namespace Type
160} // namespace Sort
161} // namespace GamR
162
163#endif
void ss(std::vector< int > indexes, TCanvas *canvas, Option_t *option)
GatedTimeDifference(Sorter *parent, std::vector< std::string > opts)
Definition Gain.cc:19