GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
ExampleEventHelper.cxx
Go to the documentation of this file.
2
4{
5 // try and get the cycle length if we have a PPG provided
6 if(Ppg() != nullptr) {
7 // the ODB cycle length is in microseconds!
9 if(slot == 0) {
10 std::stringstream str;
11 str << "Got ODB cycle length " << fCycleLength << " us = " << fCycleLength / 1e6 << " s" << std::endl;
12 std::cout << str.str();
13 }
14 } else if(slot == 0) {
15 std::stringstream str;
16 str << DRED << "No ppg provided, can't fill cycle spectra!" << RESET_COLOR << std::endl;
17 std::cout << str.str();
18 }
19
20 // some variables to easily change range and binning for multiple histograms at once
21 int energyBins = 10000;
22 double lowEnergy = 0.;
23 double highEnergy = 2000.;
24
25 fH2[slot]["zdsMultGriffinMult"] = new TH2I("zdsMultGriffinMult", "ZDS multiplicity vs. GRIFFIN multiplicity (unsuppressed)", 65, -0.5, 64.5, 10, -0.5, 9.5);
26
27 // unsuppressed spectra
28 fH1[slot]["griffinE"] = new TH1F("griffinE", Form("Unsuppressed griffin energy;energy [keV];counts/%.1f keV", (highEnergy - lowEnergy) / energyBins), energyBins, lowEnergy, highEnergy);
29 // suppressed spectra
30 fH1[slot]["griffinESupp"] = new TH1F("griffinESupp", Form("Suppressed griffin energy;energy [keV];counts/%.1f keV", (highEnergy - lowEnergy) / energyBins), energyBins, lowEnergy, highEnergy);
31 // unsuppressed addback spectra
32 fH1[slot]["griffinEAddback"] = new TH1F("griffinEAddback", Form("Unsuppressed griffin addback energy;energy [keV];counts/%.1f keV", (highEnergy - lowEnergy) / energyBins), energyBins, lowEnergy, highEnergy);
33 // suppressed addback spectra
34 fH1[slot]["griffinESuppAddback"] = new TH1F("griffinESuppAddback", Form("Suppressed griffin addback energy;energy [keV];counts/%.1f keV", (highEnergy - lowEnergy) / energyBins), energyBins, lowEnergy, highEnergy);
35 fH1[slot]["griffinESuppAddbackBeta"] = new TH1F("griffinESuppAddbackBeta", Form("Suppressed griffin addback energy w/ #beta-tag;energy [keV];counts/%.1f keV", (highEnergy - lowEnergy) / energyBins), energyBins, lowEnergy, highEnergy);
36 fH2[slot]["griffinESuppAddbackMatrixBeta"] = new TH2F("griffinESuppAddbackMatrixBeta", "Suppressed griffin addback energy matrix w/ #beta-tag;energy [keV];energy [keV]", energyBins / 5, lowEnergy, highEnergy, energyBins / 5, lowEnergy, highEnergy);
37 fH2[slot]["griffinESuppAddbackMatrixBetaBg"] = new TH2F("griffinESuppAddbackMatrixBetaBg", "Suppressed griffin addback energy matrix w/ #beta-tag (time random BG);energy [keV];energy [keV]", energyBins / 5, lowEnergy, highEnergy, energyBins / 5, lowEnergy, highEnergy);
38
39 // timing spectra
40 fH2[slot]["griffinZdsTS"] = new TH2F("griffinZdsTS", "GRIFFIN crystal vs. GRIFFIN-ZDS timestamp difference (suppressed addback);#DeltaTS_{GRIFFIN-ZDS}", 200, -1000., 1000., 64, 0.5, 64.5);
41 fH2[slot]["griffinZdsTime"] = new TH2F("griffinZdsTime", "GRIFFIN crystal vs. GRIFFIN-ZDS timing (suppressed addback);#Deltat_{GRIFFIN-ZDS}", 2000, -1000., 1000., 64, 0.5, 64.5);
42 fH2[slot]["griffinGriffinTS"] = new TH2F("griffinGriffinTS", "GRIFFIN crystal vs. GRIFFIN-GRIFFIN timestamp difference (suppressed addback);#DeltaTS_{GRIFFIN-GRIFFIN}", 2000, -1000., 1000., 64, 0.5, 64.5);
43 fH2[slot]["griffinGriffinTime"] = new TH2F("griffinGriffinTime", "GRIFFIN crystal vs. GRIFFIN-GRIFFIN timing (suppressed addback);#Deltat_{GRIFFIN-GRIFFIN}", 2000, -1000., 1000., 64, 0.5, 64.5);
44
45 // cycle spectra
46 if(fCycleLength > 0) {
47 fH2[slot]["griffinCycle"] = new TH2F("griffinCycle", "GRIFFIN suppressed addback energy w/ #beta-tag vs. time in cycle;time in cycle [s];energy [keV]", 100 * fCycleLength / 1e6, 0., fCycleLength / 1e6, energyBins / 5, lowEnergy, highEnergy);
48 fH1[slot]["zdsCycle"] = new TH1F("zdsCycle", "ZDS hits in cycle;time in cycle [s]", 100 * fCycleLength / 1e6, 0., fCycleLength / 1e6);
49 }
50}
51
52// Coincidences Gates
54{ // Griffin-Griffin
55 return -250. <= h2->GetTime() - h1->GetTime() && h2->GetTime() - h1->GetTime() <= 250.;
56}
58{
59 return (-500. <= h1->GetTime() - h2->GetTime() && h1->GetTime() - h2->GetTime() <= -250.) || (250. <= h1->GetTime() - h2->GetTime() && h1->GetTime() - h2->GetTime() <= 500.);
60}
62{ // Griffin-Zds
63 return -200. <= h1->GetTime() - h2->GetTime() && h1->GetTime() - h2->GetTime() <= 20.;
64}
66{
67 return (-310. <= h1->GetTime() - h2->GetTime() && h1->GetTime() - h2->GetTime() <= -200.) || (20. <= h1->GetTime() - h2->GetTime() && h1->GetTime() - h2->GetTime() <= 130.);
68}
69
70// TODO: Change the function arguments to match the detectors you want to use and the declaration in the header file!
71void ExampleEventHelper::Exec(unsigned int slot, TGriffin& grif, TGriffinBgo& grifBgo, TZeroDegree& zds) // NOLINT
72{
73 // we use .at() here instead of [] so that we get meaningful error message if a histogram we try to fill wasn't created
74 // e.g. because of a typo
75
76 // multiplicities
77 fH2[slot].at("zdsMultGriffinMult")->Fill(grif.GetMultiplicity(), zds.GetMultiplicity());
78
79 // loop over unsuppressed griffin hits
80 for(int g = 0; g < grif.GetMultiplicity(); ++g) {
81 auto grif1 = grif.GetGriffinHit(g);
82 fH1[slot].at("griffinE")->Fill(grif1->GetEnergy());
83 }
84
85 // loop over suppressed griffin hits
86 for(int g = 0; g < grif.GetSuppressedMultiplicity(&grifBgo); ++g) {
87 auto grif1 = grif.GetSuppressedHit(g);
88 fH1[slot].at("griffinESupp")->Fill(grif1->GetEnergy());
89 }
90
91 // loop over unsuppressed griffin addback hits
92 for(int g = 0; g < grif.GetAddbackMultiplicity(); ++g) {
93 auto grif1 = grif.GetAddbackHit(g);
94 fH1[slot].at("griffinEAddback")->Fill(grif1->GetEnergy());
95 }
96
97 // loop over suppressed griffin addback hits
98 for(int g = 0; g < grif.GetSuppressedAddbackMultiplicity(&grifBgo); ++g) {
99 auto grif1 = grif.GetSuppressedAddbackHit(g);
100 fH1[slot].at("griffinESuppAddback")->Fill(grif1->GetEnergy());
101 // we use a flag to check if there is any beta in coincidence with this gamma-ray and only fill afterwards
102 // otherwise we could double-count gamma-rays that are in coincidence with more than one beta
103 // e.g. because of double triggering of SCEPTAR/ZDS where we get a second trigger from the tail of the real signal
104 bool promptBeta = false;
105 for(int z = 0; z < zds.GetMultiplicity(); ++z) {
106 auto zds1 = zds.GetZeroDegreeHit(z);
107 fH2[slot].at("griffinZdsTS")->Fill(grif1->GetTimeStampNs() - zds1->GetTimeStampNs(), grif1->GetArrayNumber());
108 fH2[slot].at("griffinZdsTime")->Fill(grif1->GetTime() - zds1->GetTime(), grif1->GetArrayNumber());
109 if(PromptCoincidence(grif1, zds1)) promptBeta = true;
110 }
111 if(promptBeta) {
112 fH1[slot].at("griffinESuppAddbackBeta")->Fill(grif1->GetEnergy());
113 if(fCycleLength > 0.) {
114 fH2[slot].at("griffinCycle")->Fill(std::fmod(grif1->GetTime() / 1e3, fCycleLength) / 1e6, grif1->GetEnergy());
115 }
116 for(int g2 = g + 1; g2 < grif.GetSuppressedAddbackMultiplicity(&grifBgo); ++g2) {
117 auto grif2 = grif.GetSuppressedAddbackHit(g2);
118 fH2[slot].at("griffinGriffinTS")->Fill(grif1->GetTimeStampNs() - grif2->GetTimeStampNs(), grif1->GetArrayNumber());
119 fH2[slot].at("griffinGriffinTime")->Fill(grif1->GetTime() - grif2->GetTime(), grif1->GetArrayNumber());
120 if(PromptCoincidence(grif1, grif2)) {
121 // fill twice to get a symmetric matrix
122 fH2[slot].at("griffinESuppAddbackMatrixBeta")->Fill(grif1->GetEnergy(), grif2->GetEnergy());
123 fH2[slot].at("griffinESuppAddbackMatrixBeta")->Fill(grif2->GetEnergy(), grif1->GetEnergy());
124 } else if(TimeRandom(grif1, grif2)) {
125 // fill twice to get a symmetric matrix
126 fH2[slot].at("griffinESuppAddbackMatrixBetaBg")->Fill(grif1->GetEnergy(), grif2->GetEnergy());
127 fH2[slot].at("griffinESuppAddbackMatrixBetaBg")->Fill(grif2->GetEnergy(), grif1->GetEnergy());
128 }
129 }
130 }
131 }
132 if(fCycleLength > 0.) {
133 for(int z = 0; z < zds.GetMultiplicity(); ++z) {
134 auto zds1 = zds.GetZeroDegreeHit(z);
135 fH1[slot].at("zdsCycle")->Fill(std::fmod(zds1->GetTime() / 1e3, fCycleLength) / 1e6);
136 }
137 }
138}
139
140void ExampleEventHelper::EndOfSort(std::shared_ptr<std::map<std::string, TList>>& list)
141{
142 auto coincident = static_cast<TH2*>(list->at("").FindObject(fH2[0].at("griffinESuppAddbackMatrixBeta")));
143 if(coincident == nullptr) {
144 std::cout << "Failed to find griffinESuppAddbackMatrixBeta histogram in list:" << std::endl;
145 list->at("").Print();
146 return;
147 }
148 auto timeRandom = static_cast<TH2*>(list->at("").FindObject(fH2[0].at("griffinESuppAddbackMatrixBetaBg")));
149 if(timeRandom == nullptr) {
150 std::cout << "Failed to find griffinESuppAddbackMatrixBetaBg histogram in list:" << std::endl;
151 list->at("").Print();
152 return;
153 }
154
155 auto corrected = static_cast<TH2*>(coincident->Clone("griffinESuppAddbackMatrixBetaCorr"));
156 // coinc = -250 - 250 = 500 wide, bg = -500 - -250 plus 250 - 500 = 500 wide
157 corrected->Add(timeRandom, -1.);
158 list->at("").Add(corrected);
159}
bool PromptCoincidence(TGriffinHit *one, TGriffinHit *two)
bool TimeRandom(TGriffinHit *h1, TGriffinHit *h2)
bool TimeRandom(TGriffinHit *h1, TGriffinHit *h2)
bool PromptCoincidence(TGriffinHit *h1, TGriffinHit *h2)
#define DRED
Definition Globals.h:18
#define RESET_COLOR
Definition Globals.h:5
void EndOfSort(std::shared_ptr< std::map< std::string, TList > > &list) override
This method gets called at the end of Finalize()
void Exec(unsigned int slot, TGriffin &grif, TGriffinBgo &grifBgo, TZeroDegree &zds)
void CreateHistograms(unsigned int slot) override
Virtual helper function that the user uses to create their histograms.
virtual Double_t GetTime(const ETimeFlag &correct_flag=ETimeFlag::kAll, Option_t *opt="") const
Returns a time value to the nearest nanosecond!
virtual Short_t GetMultiplicity() const
Definition TDetector.h:73
std::vector< TGRSIMap< std::string, TH2 * > > fH2
Definition TGRSIHelper.h:49
std::vector< TGRSIMap< std::string, TH1 * > > fH1
Definition TGRSIHelper.h:48
TPPG * Ppg()
Definition TGRSIHelper.h:43
TGriffinHit * GetAddbackHit(const int &i)
Definition TGriffin.cxx:289
Short_t GetAddbackMultiplicity()
Definition TGriffin.cxx:265
TGriffinHit * GetSuppressedAddbackHit(const int &i)
Definition TGriffin.cxx:539
Short_t GetSuppressedMultiplicity(const TBgo *bgo)
Definition TGriffin.cxx:502
Short_t GetSuppressedAddbackMultiplicity(const TBgo *bgo)
Definition TGriffin.cxx:555
TGriffinHit * GetSuppressedHit(const int &i)
!
Definition TGriffin.cxx:486
TGriffinHit * GetGriffinHit(const int &i)
!
Definition TGriffin.cxx:244
Long64_t OdbCycleLength() const
Definition TPPG.h:171
TZeroDegreeHit * GetZeroDegreeHit(const int &i) const
Definition TZeroDegree.h:36