GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
SummingCorrectionsHelper.hh
Go to the documentation of this file.
1#ifndef SUMMINGCORRECTIONSHELPER_HH
2#define SUMMINGCORRECTIONSHELPER_HH
3
4#include "TGRSIHelper.h"
5
6#include "TGriffin.h"
7#include "TGriffinBgo.h"
8
9// This is a custom action which respects a well defined interface. It supports parallelism,
10// in the sense that it behaves correctly if implicit multi threading is enabled.
11// Note the plural: in presence of a MT execution, internally more than a single TList is created.
12// The detector types in the specifcation of Book must match those in the call to it as well as those in the Exec function (and be in the same order)!
13
14class SummingCorrectionsHelper : public TGRSIHelper, public ROOT::Detail::RDF::RActionImpl<SummingCorrectionsHelper> {
15public:
16 // constructor sets the prefix (which is used for the output file as well)
17 // and calls Setup which in turn also calls CreateHistograms
18 explicit SummingCorrectionsHelper(TList* list)
19 : TGRSIHelper(list)
20 {
21 if(fUserSettings != nullptr) {
23 try {
24 fPileUpRejection = fUserSettings->GetBool("PileUpRejection", true);
25 } catch(std::exception&) {}
27 fMaxCfd = fUserSettings->GetDouble("MaximumCfd", fMaxCfd);
28 fEnergyBins1D = fUserSettings->GetInt("Energy.Bins.1D", fEnergyBins1D);
29 fEnergyBins2D = fUserSettings->GetInt("Energy.Bins.2D", fEnergyBins2D);
32 fPromptLow = fUserSettings->GetDouble("Timing.GriffinGriffin.Prompt.Low", fPromptLow);
33 fPromptHigh = fUserSettings->GetDouble("Timing.GriffinGriffin.Prompt.High", fPromptHigh);
34 fCoincidentLow = fUserSettings->GetDouble("Timing.GriffinGriffin.Coincident.Low", fCoincidentLow);
35 fCoincidentHigh = fUserSettings->GetDouble("Timing.GriffinGriffin.Coincident.High", fCoincidentHigh);
36 fTimeRandomLow = fUserSettings->GetDouble("Timing.GriffinGriffin.TimeRandom.Low", fTimeRandomLow);
37 fTimeRandomHigh = fUserSettings->GetDouble("Timing.GriffinGriffin.TimeRandom.High", fTimeRandomHigh);
38 fTimeRandomRatio = fUserSettings->GetDouble("Timing.GriffinGriffin.TimeRandom.Ratio", fTimeRandomRatio);
41 for(int i = 0;; ++i) {
42 double tmpLow = 0.;
43 double tmpHigh = 0.;
44 try {
45 tmpLow = fUserSettings->GetDouble(Form("Energy.Background.%d.Low", i), true);
46 tmpHigh = fUserSettings->GetDouble(Form("Energy.Background.%d.High", i), true);
47 } catch(std::out_of_range& e) {
48 break;
49 }
50 fEnergyBackground.emplace_back(tmpLow, tmpHigh);
51 }
52 fEnergyRatio = fUserSettings->GetDouble("Energy.Gate.Ratio", fEnergyRatio);
53 }
54 // if we have a time random gate and no ratio, calculate it
57 }
58 // if we have a energy background gate(s) and no ratio, calculate it
59 if(fEnergyRatio == 0. && !fEnergyBackground.empty()) {
60 double tmpBg = 0.;
61 for(const auto& iter : fEnergyBackground) {
62 tmpBg += iter.second - iter.first;
63 }
64 if(tmpBg != 0.) {
65 fEnergyRatio = (fEnergyGateHigh - fEnergyGateLow) / tmpBg;
66 }
67 }
68 Prefix("SummingCorrectionsHelper");
69 Setup();
70 }
71
72 ROOT::RDF::RResultPtr<std::map<std::string, TList>> Book(ROOT::RDataFrame* d) override
73 {
74 return d->Book<TGriffin, TGriffinBgo>(std::move(*this), {"TGriffin", "TGriffinBgo"});
75 }
76 // this function creates and books all histograms
77 void CreateHistograms(unsigned int slot) override;
78 // this function gets called for every single event and fills the histograms
79 void Exec(unsigned int slot, TGriffin& grif, TGriffinBgo& grifBgo);
80 // this function is optional and is called after the output lists off all slots/workers have been merged
81 void EndOfSort(std::shared_ptr<std::map<std::string, TList>>& list) override {}
82
83private:
84 // any constants that are set in the CreateHistograms function and used in the Exec function can be stored here
85 // or any other settings
86 // some variables to easily change range and binning for multiple histograms at once
87 int fEnergyBins1D{10000};
88 int fEnergyBins2D{2000};
89 double fLowEnergy{0.};
90 double fHighEnergy{2000.};
91
92 // Pile-up Rejection - default k-values for not piled-up hits
93 int fKValueGriffin{379};
94 bool fPileUpRejection{true}; // If true, pile-up is rejected
95 double fMinimumGriffinEnergy{0.}; // reject hits below this energy
96 double fMaxCfd{20.};
97
98 // Coincidences Gates
99 double fPromptLow{-250.};
100 double fPromptHigh{250.};
101
102 // settings for branching ratio summing corrections
103 // timing
104 double fCoincidentLow{-250.};
105 double fCoincidentHigh{250.};
106 double fTimeRandomLow{500.};
107 double fTimeRandomHigh{1500.};
108 double fTimeRandomRatio{0.};
109 // energies
110 double fEnergyGateLow{0.};
111 double fEnergyGateHigh{0.};
112 std::vector<std::pair<double, double>> fEnergyBackground;
113 double fEnergyRatio{0.};
114
115 // ========== functions that fill histograms ==========
116 void FillEfficiencyHistograms(unsigned int slot, TGriffin& grif, TGriffinBgo& grifBgo);
117 void FillBranchingRatioHistograms(unsigned int slot, TGriffin& grif, TGriffinBgo& grifBgo);
118
119 // ========== functions for timing conditions ==========
120 // Griffin-Griffin
121 // Prompt is applied to the 180 degree hits
122 bool Prompt(TGriffinHit* h1, TGriffinHit* h2) const
123 {
124 return fPromptLow < h1->GetTime() - h2->GetTime() && h1->GetTime() - h2->GetTime() < fPromptHigh;
125 }
126 // Coincident and TimeRandom are used for a gate on a third gamma ray if an energy gate has been provided
127 bool Coincident(TGriffinHit* h1, TGriffinHit* h2) const
128 {
129 return fCoincidentLow < h1->GetTime() - h2->GetTime() && h1->GetTime() - h2->GetTime() < fCoincidentHigh;
130 }
131 bool TimeRandom(TGriffinHit* h1, TGriffinHit* h2) const
132 {
133 return fTimeRandomLow < std::abs(h1->GetTime() - h2->GetTime()) && std::abs(h1->GetTime() - h2->GetTime()) < fTimeRandomHigh;
134 }
135
136 bool Gate(TGriffinHit* h1) const
137 {
138 return fEnergyGateLow < h1->GetEnergy() && h1->GetEnergy() < fEnergyGateHigh;
139 }
140 bool Background(TGriffinHit* h1) const
141 {
142 return std::any_of(fEnergyBackground.begin(), fEnergyBackground.end(), [h1](std::pair<double, double> iter) { return iter.first < h1->GetEnergy() && h1->GetEnergy() < iter.second; });
143 }
144
145 // general check for good CFD
146 bool GoodCfd(TDetectorHit* h1) const
147 {
148 return h1->GetTime() - static_cast<double>(h1->GetTimeStampNs()) < fMaxCfd;
149 }
150
151 // ========== functions for pileup rejection, and minimum energy ==========
152 bool Reject(TGriffinHit* hit) const
153 {
154 return ((fPileUpRejection && hit->GetKValue() != fKValueGriffin) || hit->GetEnergy() < fMinimumGriffinEnergy);
155 }
156};
157
158// These are needed functions used by TDataFrameLibrary to create and destroy the instance of this helper
159extern "C" SummingCorrectionsHelper* CreateHelper(TList* list) { return new SummingCorrectionsHelper(list); }
160
161extern "C" void DestroyHelper(TGRSIHelper* helper) { delete helper; }
162
163#endif
void DestroyHelper(TGRSIHelper *helper)
SummingCorrectionsHelper * CreateHelper(TList *list)
bool Background(TGriffinHit *h1) const
std::vector< std::pair< double, double > > fEnergyBackground
bool Prompt(TGriffinHit *h1, TGriffinHit *h2) const
bool Gate(TGriffinHit *h1) const
bool TimeRandom(TGriffinHit *h1, TGriffinHit *h2) const
bool Coincident(TGriffinHit *h1, TGriffinHit *h2) const
void EndOfSort(std::shared_ptr< std::map< std::string, TList > > &list) override
This method gets called at the end of Finalize()
bool Reject(TGriffinHit *hit) const
ROOT::RDF::RResultPtr< std::map< std::string, TList > > Book(ROOT::RDataFrame *d) override
This method will call the Book action on the provided dataframe.
bool GoodCfd(TDetectorHit *h1) const
virtual Long64_t GetTimeStampNs(Option_t *opt="") const
virtual double GetEnergy(Option_t *opt="") const
virtual Short_t GetKValue() const
!
virtual Double_t GetTime(const ETimeFlag &correct_flag=ETimeFlag::kAll, Option_t *opt="") const
Returns a time value to the nearest nanosecond!
TUserSettings * fUserSettings
Definition TGRSIHelper.h:54
std::string & Prefix()
Definition TGRSIHelper.h:36
virtual void Setup()
bool GetBool(const std::string &parameter, bool quiet=false) const
int GetInt(const std::string &parameter, bool quiet=false) const
double GetDouble(const std::string &parameter, bool quiet=false) const