GamR  0.0.0
GammaROOT
Loading...
Searching...
No Matches
TimeDifference.hh
Go to the documentation of this file.
1#ifndef GAMRSORT_TIMEDIFFERENCE_HH
2#define GAMRSORT_TIMEDIFFERENCE_HH
3
4#include "Sorter.hh"
5
6#include <memory>
7#include <sstream>
8#include <string>
9#include <vector>
10
11#include <TH2.h>
12#include <TTreeReader.h>
13#include <TTreeReaderArray.h>
14#include <TTreeReaderValue.h>
15
16#include <nucleus/Photon.hh>
17
18namespace GamR {
19namespace Sort {
20namespace Type {
21
22template <class Det, size_t E, size_t T>
24private:
25 Sorter *p;
26 std::shared_ptr<TH2D> ptrPkMatrixSum;
27 std::shared_ptr<TH2D> ptrBgMatrixSum;
28 std::shared_ptr<GamR::Nucleus::Photon> ptrRefPhoton;
29 std::vector<int> detIds;
30 std::string gid;
31
32public:
33 TimeDifference(Sorter *parent, std::vector<std::string> opts) : p(parent)
34 {
35 if (opts.size() < 7)
36 throw std::length_error("Invalid arguments, expect: prefix group ref_E "
37 "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;
45 float energy;
46 ss >> energy;
47 float pklow;
48 ss >> pklow;
49 float pkhigh;
50 ss >> pkhigh;
51 float bglow;
52 ss >> bglow;
53 float bghigh;
54 ss >> bghigh;
55 std::string nameprefix(prefix + "_g" + gid + "m" + E + "td" + T);
56
57 ptrRefPhoton = std::make_shared<GamR::Nucleus::Photon>(energy, pklow, pkhigh, bglow, bghigh);
58 ptrRefPhoton->SetName((nameprefix + "R").c_str());
59
60 p->WriteObject(ptrRefPhoton.get());
61
62 int id;
63 while (ss >> id) {
64 detIds.push_back(id);
65 };
66
67 // Create the histogram objects
68 ptrPkMatrixSum = p->GetMatrix((nameprefix + "P").c_str());
69 ptrBgMatrixSum = p->GetMatrix((nameprefix + "B").c_str());
70
71 // Setting bins
72 ptrPkMatrixSum->SetBins(4096, 0, 4096, 8192, -4096, 4096);
73 ptrBgMatrixSum->SetBins(4096, 0, 4096, 8192, -4096, 4096);
74 // ptrPkMatrixSum -> SetCanExtend(TH1::kAllAxes);
75 // ptrBgMatrixSum -> SetCanExtend(TH1::kAllAxes);
76
77 // Set titles
78
79 std::stringstream ssTitle;
80 ssTitle.str("");
81 ssTitle << "$E_{1}=" << ptrRefPhoton->GetEnergy() << "$ Gate: $";
82 ssTitle << ptrRefPhoton->GetGate()->GetLow() << "\\to";
83 ssTitle << ptrRefPhoton->GetGate()->GetHigh();
84 ssTitle << "$;Gamma Energy, E_{2}";
85 ssTitle << "[keV];$\\Delta t = t_{2}-t_{1}$";
86
87 ptrPkMatrixSum->SetTitle(ssTitle.str().c_str());
88
89 // Background
90 ssTitle.str("");
91 ssTitle << "$E_{1}=" << ptrRefPhoton->GetEnergy() << "$ GateBG: $";
92 ssTitle << ptrRefPhoton->GetGateBG()->GetLow() << "\\to";
93 ssTitle << ptrRefPhoton->GetGateBG()->GetHigh();
94 ssTitle << "$;Gamma Energy, E_{2}";
95 ssTitle << "[keV];$\\Delta t = t_{2}-t_{1}$";
96
97 ptrBgMatrixSum->SetTitle(ssTitle.str().c_str());
98
99 } // Sorter::TimeWalk
100
101 void operator()(TTreeReader &R)
102 {
103 std::string group = "DetGroup._" + gid;
104 TTreeReaderValue<std::vector<Det>> rdrDets(R, group.c_str());
105 while (R.Next() && !p->Done()) {
106 std::vector<Det> vecDets = *rdrDets;
107 p->Tick();
108 if (vecDets.size() < 2) {
109 continue;
110 }
111 for (auto &deti : vecDets) {
112 for (auto &detj : vecDets) {
113 if (deti.ID == detj.ID) {
114 continue;
115 }
116 Bool_t pkgated = ptrRefPhoton->GetGate()->Pass(deti.template GetCal<E>());
117 Bool_t bggated = ptrRefPhoton->GetGateBG()->Pass(deti.template GetCal<E>());
118
119 if ((pkgated || bggated) && (deti.template Get<T>() > 0) && (detj.template Get<T>() > 0)) {
120 // tdiff = T2 - T1 ALWAYS.
121 auto tdiff = detj.template GetCal<T>() - deti.template GetCal<T>();
122 if (pkgated) {
123 ptrPkMatrixSum->Fill(detj.template GetCal<E>(), tdiff);
124 } else if (bggated) {
125 ptrBgMatrixSum->Fill(detj.template GetCal<E>(), tdiff);
126 }
127 } // gated
128 } // fold 2
129 } // fold 1
130 } // all events
131 } // Sorter::TimeWalk::operator()
132};
133
134} // namespace Type
135} // namespace Sort
136} // namespace GamR
137
138#endif
void ss(std::vector< int > indexes, TCanvas *canvas, Option_t *option)
TimeDifference(Sorter *parent, std::vector< std::string > opts)
Definition Gain.cc:19