R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandTimeRes.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#include "R3BNeulandTimeRes.h"
15#include "R3BNeulandCalData.h"
16#include "TF1.h"
17#include "TF2.h"
18#include "TFile.h"
19#include "TMath.h"
20#include "TSpectrum.h"
21#include <FairRootManager.h>
22#include <TClonesArray.h>
23
24#include <fstream>
25#include <signal.h>
26#include <sstream>
27
29 : FairTask("NeulandTimeRes", 1)
30 , fUpdateRate(1000000)
31 , fNEventsNeeded(10000)
32 , fTrigger(-1)
33{
34}
35
36R3BNeulandTimeRes::R3BNeulandTimeRes(const char* name, Int_t iVerbose)
37 : FairTask(name, iVerbose)
38 , fUpdateRate(1000000)
39 , fNEventsNeeded(10000)
40 , fTrigger(-1)
41{
42}
43
45
47{
48 std::cout << "init init" << std::endl;
49
50 FairRootManager* rm = FairRootManager::Instance();
51 if (!rm)
52 {
53 return kFATAL;
54 }
55
56 header = (R3BEventHeader*)rm->GetObject("EventHeader.");
57 if (!header)
58 {
59 return kFATAL;
60 }
61
62 fPmt = (TClonesArray*)rm->GetObject("NeulandCalData");
63 if (!fPmt)
64 {
65 return kFATAL;
66 }
67
68 for (Int_t pln = 0; pln < fNofPlanes; pln++)
69 {
70 for (Int_t bar = 0; bar < fNofBarsPerPlane; bar++)
71 {
72
73 bar_done[pln][bar] = 0;
74
75 std::ostringstream hss;
76 hss << "h_p" << pln + 1 << "b" << bar + 1;
77 TString hname = hss.str();
78
79 std::ostringstream hssq;
80 hssq << "hq_p" << pln + 1 << "b" << bar + 1;
81 TString hnameq = hssq.str();
82
83 hTimeRes[pln][bar] = new TH1F(hname, hname, 1000, -20., 20.);
84 hTimeResQ[pln][bar] = new TH2F(hnameq, hnameq, 400, 0, 1000, 400, -20., 20.);
85 }
86 }
87
88 fNEvents = 0;
89 bars_done = 0;
90 finished = 0;
91
92 return kSUCCESS;
93}
94
95void R3BNeulandTimeRes::Exec(Option_t* option)
96{
97
98 fNEvents++;
99
100 // std::cout << fNEvents << std::endl;
101
102 if (finished)
103 {
104 // if (fNEvents == fNEventsNeeded) {
105 std::cout << std::endl;
106 std::cout << "done 1" << std::endl;
107 raise(SIGINT);
108 }
109
110 if (fTrigger >= 0)
111 {
112 if (header->GetTrigger() != fTrigger)
113 {
114 return;
115 }
116 }
117
118 Int_t nHits = fPmt->GetEntries();
119
120 // if (nHits < 4) return; // better cosmic peaks
121
122 Double_t fCharge1[300] = { 0. }, fCharge2[300] = { 0. };
123 Double_t fTime1[300] = { 0. }, fTime2[300] = { 0. };
124
125 Int_t mult[fNofPlanes];
126
127 for (Int_t pl = 0; pl < fNofPlanes; pl++)
128 mult[pl] = 0;
129
130 // Loop over mapped hits
131 for (Int_t i = 0; i < nHits; i++)
132 {
133
134 R3BNeulandCalData* hit = (R3BNeulandCalData*)fPmt->At(i);
135
136 if (!hit)
137 continue; // should not happen
138
139 Int_t iPlane = (hit->GetBarId() - 1) / 50;
140 Int_t iBar = (hit->GetBarId() - 1) % 50;
141 Int_t iSide = hit->GetSide() - 1;
142
143 if (hit->GetTime() > 0)
144 mult[iPlane]++;
145
146 if (0 == iSide)
147 {
148 fCharge1[iPlane * 50 + iBar] = hit->GetQdc();
149 fTime1[iPlane * 50 + iBar] = hit->GetTime() - wlk(fCharge1[iPlane * 50 + iBar]);
150 // fTime1[iPlane*50+iBar] = hit->GetTime();
151 }
152 else
153 {
154 fCharge2[iPlane * 50 + iBar] = hit->GetQdc();
155 fTime2[iPlane * 50 + iBar] = hit->GetTime() - wlk(fCharge2[iPlane * 50 + iBar]);
156 // fTime2[iPlane*50+iBar] = hit->GetTime();
157 }
158 }
159
160 for (Int_t pl = 0; pl < fNofPlanes; pl++)
161 {
162 for (Int_t bar = 1; bar < fNofBarsPerPlane; bar++)
163 {
164
165 if (bar_done[pl][bar] == 1)
166 continue;
167
168 Double_t t1 = fTime1[pl * 50 + bar - 1];
169 Double_t t2 = fTime2[pl * 50 + bar - 1];
170 Double_t t3 = fTime1[pl * 50 + bar];
171 Double_t t4 = fTime2[pl * 50 + bar];
172
173 Double_t qdc12 = sqrt(fCharge1[pl * 50 + bar - 1] * fCharge2[pl * 50 + bar - 1]);
174 Double_t qdc34 = sqrt(fCharge1[pl * 50 + bar] * fCharge2[pl * 50 + bar]);
175
176 // fill time diff histos
177 if (t1 > 0 && t2 > 0 && t3 > 0 && t4 > 0 && qdc12 > 75. && qdc34 > 75.)
178 {
179 // if (t1 > 0 && t2 > 0 && t3 > 0 && t4 > 0) {
180 if (pl % 2 == 0 && mult[pl] > 10)
181 {
182 hTimeRes[pl][bar]->Fill((t3 + t4) / 2. - (t1 + t2) / 2.);
183 hTimeResQ[pl][bar]->Fill(qdc34, (t3 + t4) / 2. - (t1 + t2) / 2.);
184 }
185 if (pl % 2 == 1 && mult[pl] > 10)
186 {
187 hTimeRes[pl][bar]->Fill((t3 + t4) / 2. - (t1 + t2) / 2.);
188 hTimeResQ[pl][bar]->Fill(qdc34, (t3 + t4) / 2. - (t1 + t2) / 2.);
189 }
190 }
191
192 if (hTimeRes[pl][bar]->GetEntries() > 3000)
193 {
194
195 bar_done[pl][bar] = 1;
196
197 bars_done++;
198
199 std::cout << std::endl;
200 std::cout << "bars done: " << bars_done << std::endl;
201
202 // do fitting
203 Int_t a = hTimeRes[pl][bar]->GetEntries();
204
205 Double_t ampli = hTimeRes[pl][bar]->GetMaximum();
206 Int_t binmax = hTimeRes[pl][bar]->GetMaximumBin();
207 Double_t posi = hTimeRes[pl][bar]->GetXaxis()->GetBinCenter(binmax);
208
209 Double_t sigma = 0.150;
210 Double_t min = posi - 1.0;
211 Double_t max = posi + 1.0;
212
213 std::cout << "position of peak: " << posi << " " << ampli << std::endl;
214
215 std::ostringstream fss;
216 fss << "f_p" << pl + 1 << "b" << bar + 1;
217 TString fname = fss.str();
218
219 if (pl % 2 == 0)
220 {
221 fitfunc[pl][bar] = new TF1(fname, "gaus");
222 fitfunc[pl][bar]->SetParameters(ampli, posi, sigma);
223 }
224 else
225 {
226 fitfunc[pl][bar] = new TF1(fname, "gaus(0)+gaus(3)");
227 fitfunc[pl][bar]->SetParameters(ampli, posi - 0.3, sigma, ampli, posi + 0.3, sigma);
228 }
229
230 hTimeRes[pl][bar]->Fit(fitfunc[pl][bar], "", "", min, max);
231
232 Double_t nmax = fitfunc[pl][bar]->GetParameter(0);
233 Double_t mean = fitfunc[pl][bar]->GetParameter(1);
234 Double_t tres = fitfunc[pl][bar]->GetParameter(2);
235
236 delete fitfunc[pl][bar];
237
238 std::ofstream timeres_file("timeres.txt", std::ios::app);
239
240 timeres_file << "time res p" << pl + 1 << "b" << bar + 1 << " " << nmax << " " << mean << " "
241 << tres << std::endl;
242
243 timeres_file.close();
244 }
245
246 if (bars_done == fNofPlanes * (fNofBarsPerPlane - 1))
247 finished = 1;
248 }
249 }
250}
251
253
255{
256
257 std::cout << "done 1.5" << std::endl;
258
259 TFile* fff = new TFile("histos_timeres.root", "recreate");
260
261 for (Int_t pln = 0; pln < fNofPlanes; pln++)
262 {
263 for (Int_t bar = 0; bar < fNofBarsPerPlane; bar++)
264 {
265 hTimeRes[pln][bar]->Write();
266 hTimeResQ[pln][bar]->Write();
267 }
268 }
269 fff->Close();
270}
271
272Double_t R3BNeulandTimeRes::wlk(Double_t x)
273{
274 Double_t y = 0;
275 Double_t par1 = 3.34290e+01; // not considered
276 Double_t par2 = -4.48725e+05;
277 Double_t par3 = -2.07310e+02;
278 Double_t par4 = 2.48974e+02;
279 Double_t par5 = 6.36355e-03;
280 Double_t par6 = -2.93865e-05;
281
282 if (x > 0 && x < 400)
283 y = par2 * TMath::Power(x, par3) + par4 / x + par5 * x + par6 * x * x;
284 else
285 y = 0;
286
287 return y;
288 // return 0.;
289}
Int_t GetSide() const
Double_t GetTime() const
auto GetQdc() const -> double
Int_t GetBarId() const
virtual ~R3BNeulandTimeRes()
Destructor.
virtual void FinishTask()
Method for finish of the task execution.
virtual InitStatus Init()
Method for task initialization.
virtual void FinishEvent()
A method for finish of processing of an event.
R3BNeulandTimeRes()
Default constructor.
virtual void Exec(Option_t *option)
Method for event loop implementation.