GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
write_cal.cxx
Go to the documentation of this file.
1//Experiment: S1607
2
3//Root version: 6.08/02
4//GRSISort:3.1.3.2
5
6//Compilation: If placed in the GRSISort/scripts directory, GRSISort will automatically compile it with a make
7
8//Usage is: TAC_offset /path/to/analysistree.root
9
10//The analog TAC signals are delayed by a (rather) fixed time. This can create problems when building the AnalysisTree coincidences. To avoid that, a constant offset can be applied to the TAC timestamp. This value is given in the calfile. This script helps determining which value should be set. It produces a set of histograms with the timestamp difference between each TAC and its starting LaBr. One set of histograms is done with the TAC offset timestamp set to 0 and the other with the current one from the calfile. You should adjust the offset so the main peak is roughly at 0.
11
12//NOTE: take into account that the histograms are in ns, but the calfile parameters (offset or time build window, for example) are in 10 ns.
13
14#include "TFile.h"
15#include "TChain.h"
16#include "TTree.h"
17#include "TH1F.h"
18#include "TF1.h"
19#include "TMath.h"
20
21#include "TGriffin.h"
22#include "TSceptar.h"
23#include "TLaBr.h"
24#include "TZeroDegree.h"
25#include "TTAC.h"
26
27#include <vector>
28#include <string>
29
30constexpr int FirstChannel = 84;
31constexpr int LastChannel = 91;
32
33int main(int argc, char** argv)
34{
35 if(argc == 1) {
36 std::cout << "Usage: " << argv[0] << " <analysis tree file(s)>" << std::endl;
37 return 1;
38 }
39
40 std::cout << std::endl
41 << "WARNING: This script assumes that the TACs are in channels " << FirstChannel << " - " << LastChannel << " (which are the default). Should have they been assigned to other channel numbers, the script should be edited acordingly" << std::endl
42 << std::endl;
43
44 auto* file = new TFile(argv[1]);
45
46 auto* AnalysisTree = static_cast<TTree*>(file->Get("AnalysisTree"));
47
48 TChannel::ReadCalFromTree(AnalysisTree);
49
50 TChannel* channel = nullptr;
51
52 std::array<double, 8> offset;
53
54 for(int n = FirstChannel; n <= LastChannel; n++) {
56 offset[n - FirstChannel] = static_cast<double>(channel->GetTimeOffset());
57 std::cout << "Current TAC offset in the calfile: " << offset[n - FirstChannel] << " for channel #" << n << std::endl;
58 }
59
60 TLaBr* labr = nullptr;
61 TTAC* tac = nullptr;
62 TGriffin* grif = nullptr;
63
64 if(AnalysisTree->SetBranchAddress("TLaBr", &labr) == TTree::kMissingBranch) {
65 labr = new TLaBr;
66 }
67 if(AnalysisTree->SetBranchAddress("TTAC", &tac) == TTree::kMissingBranch) {
68 tac = new TTAC;
69 }
70 if(AnalysisTree->SetBranchAddress("TGriffin", &grif) == TTree::kMissingBranch) {
71 grif = new TGriffin;
72 }
73
74 Long64_t nEntries = AnalysisTree->GetEntries();
75
76 std::string outname = argv[1];
77 outname.replace(outname.begin(), outname.end() - 14, "TAC_offset");
78 std::cout << "writing to '" << outname << "'" << std::endl;
79
80 TFile outfile(outname.c_str(), "recreate");
81
82 TList list;
83
84 UInt_t labr1 = 0;
85 UInt_t labr2 = 0;
86 UInt_t tac1 = 0; //counters
87
88 Double_t progress = 0.;
89 Int_t multi_labr = 0;
90 Int_t multi_tac = 0;
91 Int_t multi_grif = 0;
92
93 //TAC offset histograms
94 std::array<TH1D*, 8> TAC_offset;
95 for(int i = 0; i < 8; ++i) {
96 TAC_offset[i] = new TH1D(Form("TAC_offset_%d", i), Form("TAC_offset_%d; time (ns); counts/ns", i), 10000, -5000., 5000.);
97 list.Add(TAC_offset[i]);
98 }
99
100 std::array<TH1D*, 8> TAC_offset_corrected;
101 for(int i = 0; i < 8; ++i) {
102 TAC_offset_corrected[i] = new TH1D(Form("TAC_offset_corrected_%d", i), Form("TAC_offset_corrected_%d; time (ns); counts/ns", i), 10000, -5000., 5000.);
103 list.Add(TAC_offset_corrected[i]);
104 }
105
106 std::array<TH1D*, 8> time_diff;
107 for(int i = 0; i < 8; ++i) {
108 time_diff[i] = new TH1D(Form("time_diff%d", i), Form("Time difference for LaBr_%d - LaBr with TAC coincidence; time (ns); counts/ns", i), 10000, -5000., 5000.);
109 list.Add(time_diff[i]);
110 }
111
112 std::array<TH1D*, 8> time_diff_noTAC;
113 for(int i = 0; i < 8; ++i) {
114 time_diff_noTAC[i] = new TH1D(Form("time_diff_noTAC%d", i), Form("Time difference for LaBr_%d - LaBr with no TAC coincidence; time (ns); counts/ns", i), 10000, -5000., 5000.);
115 list.Add(time_diff_noTAC[i]);
116 }
117
118 std::array<TH1D*, 8> timestamp_diff_noTACcoinc;
119 for(int i = 0; i < 8; ++i) {
120 timestamp_diff_noTACcoinc[i] = new TH1D(Form("timestamp_diff_noTACcoinc%d", i), Form("Timestamp difference for LaBr_%d - LaBr, no TAC coincidence; time (ns); counts/ns", i), 10000, -5000., 5000.);
121 list.Add(timestamp_diff_noTACcoinc[i]);
122 }
123
124 std::array<TH1D*, 8> timestamp_diff_TACcoinc;
125 for(int i = 0; i < 8; ++i) {
126 timestamp_diff_TACcoinc[i] = new TH1D(Form("timestamp_diff_TACcoinc%d", i), Form("Timestamp difference for LaBr_%d - LaBr, with TAC coincidence; time (ns); counts/ns", i), 10000, -5000., 5000.);
127 list.Add(timestamp_diff_TACcoinc[i]);
128 }
129
130 TH1D* timestamp_diff_hpge = new TH1D("timestamp_diff_hpge", "Timestamp difference for HPGe - LaBr, with TAC coincidence; time (ns); counts/ns", 10000, -5000., 5000.);
131 list.Add(timestamp_diff_hpge);
132 TH1D* time_diff_hpge = new TH1D("time_diff_hpge", "Time difference for HPGe - LaBr, with TAC coincidence; time (ns); counts/ns", 10000, -5000., 5000.);
133 list.Add(time_diff_hpge);
134
135 for(Long64_t n = 0; n < nEntries; ++n) { //This is the main loop, that will cycle through the entire AnalysisTree
136 AnalysisTree->GetEntry(n);
137
138 //Builds the number of detector hits in each event (multiplicity of the coincidence)
139 multi_labr = labr->GetMultiplicity();
140 multi_tac = tac->GetMultiplicity();
141 multi_grif = grif->GetMultiplicity();
142
143 if(multi_labr == 2) {
144 labr1 = labr->GetLaBrHit(0)->GetDetector() - 1; //GetDetector goes from 1-8, while the counter goes from 0-7, hence the -1
145 labr2 = labr->GetLaBrHit(1)->GetDetector() - 1; //GetDetector goes from 1-8, while the counter goes from 0-7, hence the -1
146 timestamp_diff_noTACcoinc[labr2]->Fill(static_cast<Double_t>(labr->GetLaBrHit(1)->GetTimeStamp() - labr->GetLaBrHit(0)->GetTimeStamp()));
147 time_diff_noTAC[labr2]->Fill(labr->GetLaBrHit(1)->GetTime() - labr->GetLaBrHit(0)->GetTime());
148 }
149
150 if(multi_labr == 2 && multi_tac == 1) { //It only looks for LaBrx2+TAC coincidences
151 labr1 = labr->GetLaBrHit(0)->GetDetector() - 1; //GetDetector goes from 1-8, while the counter goes from 0-7, hence the -1
152 labr2 = labr->GetLaBrHit(1)->GetDetector() - 1; //GetDetector goes from 1-8, while the counter goes from 0-7, hence the -1
153 tac1 = tac->GetTACHit(0)->GetDetector() - 1; //GetDetector goes from 1-8, while the counter goes from 0-7, hence the -1
154 if(labr1 < labr2) {
155 if(tac1 == labr1) {
156 TAC_offset[tac1]->Fill(labr->GetLaBrHit(0)->GetTime() - tac->GetTACHit(0)->GetTime() + offset[tac1] * 10);
157 TAC_offset_corrected[tac1]->Fill(labr->GetLaBrHit(0)->GetTime() - tac->GetTACHit(0)->GetTime());
158 time_diff[labr2]->Fill(labr->GetLaBrHit(1)->GetTime() - labr->GetLaBrHit(0)->GetTime());
159 timestamp_diff_TACcoinc[labr2]->Fill(static_cast<Double_t>(labr->GetLaBrHit(1)->GetTimeStamp() - labr->GetLaBrHit(0)->GetTimeStamp()));
160 if(multi_grif > 0) {
161 for(int i = 0; i < multi_grif; i++) {
162 time_diff_hpge->Fill(grif->GetGriffinHit(i)->GetTime() - labr->GetLaBrHit(0)->GetTime());
163 timestamp_diff_hpge->Fill(static_cast<Double_t>(grif->GetGriffinHit(i)->GetTimeStamp() - labr->GetLaBrHit(0)->GetTimeStamp()));
164 }
165 }
166 }
167 } else if(labr1 > labr2) {
168 if(tac1 == labr2) {
169 TAC_offset[tac1]->Fill(labr->GetLaBrHit(1)->GetTime() - tac->GetTACHit(0)->GetTime() + offset[tac1] * 10);
170 TAC_offset_corrected[tac1]->Fill(labr->GetLaBrHit(1)->GetTime() - tac->GetTACHit(0)->GetTime());
171 time_diff[labr2]->Fill(labr->GetLaBrHit(1)->GetTime() - labr->GetLaBrHit(0)->GetTime());
172 timestamp_diff_TACcoinc[labr2]->Fill(static_cast<Double_t>(labr->GetLaBrHit(1)->GetTimeStamp() - labr->GetLaBrHit(0)->GetTimeStamp()));
173 if(multi_grif > 0) {
174 for(int i = 0; i < multi_grif; i++) {
175 time_diff_hpge->Fill(grif->GetGriffinHit(i)->GetTime() - labr->GetLaBrHit(0)->GetTime());
176 timestamp_diff_hpge->Fill(static_cast<Double_t>(grif->GetGriffinHit(i)->GetTimeStamp() - labr->GetLaBrHit(0)->GetTimeStamp()));
177 }
178 }
179 }
180 }
181 }
182
183 if(n % 10000 == 0) {
184 progress = (static_cast<double>(n)) / (static_cast<double>(nEntries));
185 std::cout << std::setw(4) << 100 * progress << "% done\r" << std::flush;
186 }
187
188 } //Analysistree loop
189 std::cout << "100% done" << std::endl;
190
191 list.Sort();
192 list.Write();
193
194 return 0;
195}
Long64_t GetTimeOffset() const
Definition TChannel.h:176
static Int_t ReadCalFromTree(TTree *, Option_t *opt="overwrite")
static TChannel * GetChannelByNumber(int temp_num)
Definition TChannel.cxx:482
virtual Long64_t GetTimeStamp(Option_t *="") const
virtual Int_t GetDetector() const
!
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
Short_t GetMultiplicity() const override
Definition TGriffin.h:52
TGriffinHit * GetGriffinHit(const int &i)
!
Definition TGriffin.h:47
Definition TLaBr.h:28
TLaBrHit * GetLaBrHit(const int &i) const
Definition TLaBr.h:49
Definition TTAC.h:27
TTACHit * GetTACHit(const int &i) const
Definition TTAC.h:36
int main(int argc, char **argv)
Definition write_cal.cxx:33
constexpr int LastChannel
Definition write_cal.cxx:31
constexpr int FirstChannel
Definition write_cal.cxx:30