BmnRoot
Loading...
Searching...
No Matches
BmnFillTrigInfoDst.cxx
Go to the documentation of this file.
1/********************************************************************************
2 * BmnFillTrigInfoDst.cxx *
3 *******************************************************************************/
4
6
7#include "BmnFDPoint.h"
8#include "BmnTrigDigit.h"
9#include "BmnTrigInfoDst.h"
10#include "BmnTrigWaveDigit.h"
11#include "FairRootManager.h"
12
13#include <TStopwatch.h>
14#include <iostream>
15using namespace std;
16
17static Double_t workTime = 0.0;
18
19// ---- Default constructor -------------------------------------------
21 : BmnFillTrigInfoDst(false)
22{
23 LOG(debug) << "Defaul Constructor of BmnFillTrigInfoDst";
24}
25
26// ---- Constructor with flag whether experimental data are used --------
28 : BmnTask("BmnFillTrigInfoDst")
29 , isExpData(isExp)
30 , doProcessTriggers(true)
31 , fDigiEventHeader(nullptr)
32 , fVCDigits(nullptr)
33 , fBC0Digits(nullptr)
34 , fBC1Digits(nullptr)
35 , fBC2Digits(nullptr)
36 , fBDDigits(nullptr)
37 , fSiMDDigits(nullptr)
38 , fFDDigits(nullptr)
39 , fBC1Digits_Top(nullptr)
40 , fBC1Digits_Bottom(nullptr)
41 , fTrigInfo(nullptr)
42{
43 fGr4FitBC1Top = new TGraph();
44 fGr4FitBC1Bottom = new TGraph();
45 f_gaus = new TF1("f_gaus", "gaus", 0, 500);
46
47 // It is bad way to do it here. Need transmit run number to the task and get parameters from DB
48 // These constants are derived from fitting the time-of-flight between BC2 and BC1.
49 f_BC1 = new TF1("f_BC1", "[0] + [1]*TMath::Exp([2]*([3]+x))", 0, 20000);
50 f_BC1->SetParameters(1.07489, -3.01848, -0.000169763, 358.637);
51 // These constants depends on DAQ settings
52 LimitTdcLow = 2600.;
53 LimitTdcHgh = 2670.;
54 LimitWvLow = 320;
55 LimitWvHgh = 350;
56 // These constants depends on waveform of the signal
57 GateFitLow = 5.5;
58 GateFitHgh = 2.5;
59
60 LOG(debug) << "Constructor with experimental data flag of BmnFillTrigInfoDst";
61}
62
63// ---- Destructor ----------------------------------------------------
65{
66 LOG(debug) << "Destructor of BmnFillTrigInfoDst";
67 if (fTrigInfo)
68 delete fTrigInfo;
69}
70
71// ---- Init ----------------------------------------------------------
73{
74 LOG(debug) << "Initialization of BmnFillTrigInfoDst";
75
76 // Get a handle from the IO manager
77 FairRootManager* ioman = FairRootManager::Instance();
78 if (!ioman) {
79 LOG(error) << "Init: FairRootManager is not instantiated! BmnFillTrigInfoDst task will be deactivated";
80 SetActive(kFALSE);
81 return kERROR;
82 }
83
84 // Get input branches
85 if (isExpData) {
86 fDigiEventHeader = (BmnEventHeader*)ioman->GetObject("BmnEventHeader.");
87 fVCDigits = (TClonesArray*)ioman->GetObject("TQDC_VCS");
88 fBC0Digits = (TClonesArray*)ioman->GetObject("TQDC_BC0");
89 fBC1Digits = (TClonesArray*)ioman->GetObject("TQDC_BC1S");
90 if (!fBC1Digits)
91 fBC1Digits = (TClonesArray*)ioman->GetObject("TQDC_BC1");
92 fBC2Digits = (TClonesArray*)ioman->GetObject("TQDC_BC2AS");
93 if (!fBC2Digits)
94 fBC2Digits = (TClonesArray*)ioman->GetObject("TQDC_BC2");
95 fBDDigits = (TClonesArray*)ioman->GetObject("BD");
96 fSiMDDigits = (TClonesArray*)ioman->GetObject("SiMD");
97 fFDDigits = (TClonesArray*)ioman->GetObject("TQDC_FD");
98 fBC1Digits_Top = (TClonesArray*)ioman->GetObject("TQDC_BC1T");
99 fBC1Digits_Bottom = (TClonesArray*)ioman->GetObject("TQDC_BC1B");
100 } else {
101 fBDDigits = (TClonesArray*)ioman->GetObject("BdDigit");
102 fFDDigits = (TClonesArray*)ioman->GetObject("FDPoint");
103 }
104
105 if (isExpData && !fVCDigits && !fBC0Digits && !fBC1Digits && !fBC2Digits && !fBDDigits && !fSiMDDigits
106 && !fFDDigits)
107 {
108 LOG(error) << "Init: all trigger branches not found! BmnFillTrigInfoDst task will process only basic data";
109 doProcessTriggers = false;
110 // SetActive(kFALSE);
111 // return kERROR;
112 }
113
114 // Create and register TrigInfo object for trigger output data
115 fTrigInfo = new BmnTrigInfoDst(isExpData);
116 ioman->Register("BmnTrigInfo.", "TRIGGER", fTrigInfo, kTRUE);
117 if (!fTrigInfo) {
118 LOG(error) << "Init: BmnTrigInfo not created! BmnFillTrigInfoDst task will be deactivated";
119 SetActive(kFALSE);
120 return kERROR;
121 }
122
123 return kSUCCESS;
124}
125
126// ---- Exec ----------------------------------------------------------
127void BmnFillTrigInfoDst::Exec(Option_t* /*option*/)
128{
129 if (!IsActive())
130 return;
131
132 TStopwatch sw;
133 sw.Start();
134
135 if (fVerbose > 1)
136 cout << "\n======================== BmnFillTrigInfoDst exec started =====================\n" << endl;
137
138 fTrigInfo->Reset();
139
140 if (fDigiEventHeader) {
141 fTrigInfo->SetInputSignalsAR(fDigiEventHeader->GetInputSignalsAR());
142 fTrigInfo->SetInputSignalsBR(fDigiEventHeader->GetInputSignalsBR());
143 fTrigInfo->SetInputSignalsVector(fDigiEventHeader->GetInputSignalsVector());
144 }
145
146 if (doProcessTriggers) {
147 if (fVCDigits && fVCDigits->GetEntriesFast() > 0) {
148 BmnTrigWaveDigit* digiVC = (BmnTrigWaveDigit*)fVCDigits->At(0);
149 fTrigInfo->SetVCAmp(digiVC->GetPeak());
150 }
151 if (fBC0Digits && fBC0Digits->GetEntriesFast() > 0) {
152 BmnTrigWaveDigit* digiBC0 = (BmnTrigWaveDigit*)fBC0Digits->At(0);
153 fTrigInfo->SetBC0Amp(digiBC0->GetPeak());
154 fTrigInfo->GetBC0Digits()->AbsorbObjects(fBC0Digits);
155 }
156 if (fBC1Digits && fBC1Digits->GetEntriesFast() > 0) {
157 BmnTrigWaveDigit* digiBC1 = (BmnTrigWaveDigit*)fBC1Digits->At(0);
158 fTrigInfo->SetBC1Integral(digiBC1->GetIntegral());
159 fTrigInfo->SetBC1Amp(digiBC1->GetPeak());
160 fTrigInfo->GetBC1Digits()->AbsorbObjects(fBC1Digits);
161 }
162 if (fBC2Digits && fBC2Digits->GetEntriesFast() > 0) {
163 BmnTrigWaveDigit* digiBC2 = (BmnTrigWaveDigit*)fBC2Digits->At(0);
164 fTrigInfo->SetBC2Amp(digiBC2->GetPeak());
165 fTrigInfo->GetBC2Digits()->AbsorbObjects(fBC2Digits);
166 }
167 if (fBDDigits) {
168 fTrigInfo->SetBDMult(fBDDigits->GetEntriesFast());
169 fTrigInfo->GetBDDigits()->AbsorbObjects(fBDDigits);
170 }
171 if (fSiMDDigits)
172 fTrigInfo->SetSiMDMult(fSiMDDigits->GetEntriesFast());
173 if (fFDDigits && fFDDigits->GetEntriesFast() > 0) {
174 if (isExpData) {
175 BmnTrigWaveDigit* digiFD = (BmnTrigWaveDigit*)fFDDigits->At(0);
176 fTrigInfo->SetFDAmp(digiFD->GetPeak());
177 }
178 fTrigInfo->GetFDDigits()->AbsorbObjects(fFDDigits);
179 }
180 if (isExpData && fBC1Digits_Top && fBC1Digits_Top->GetEntriesFast() > 0 && fBC1Digits_Bottom
181 && fBC1Digits_Bottom->GetEntriesFast() > 0)
182 {
183 Float_t* amp_temp = new Float_t();
184 fTrigInfo->SetT0_time(CalculateT0(amp_temp));
185 fTrigInfo->SetT0_amp(*amp_temp);
186 delete amp_temp;
187 } else {
188 fTrigInfo->SetT0_time(0.);
189 fTrigInfo->SetT0_amp(0.);
190 }
191 }
192
193 sw.Stop();
194 workTime += sw.RealTime();
195}
196
197// ---- Finish --------------------------------------------------------
199{
200 LOG(debug) << "Finish of BmnFillTrigInfoDst";
201 printf("Work time of BmnFillTrigInfoDst: %4.2f sec.\n", workTime);
202}
203
204// ---- CalculateT0 ----------------------------------------------------
205Float_t BmnFillTrigInfoDst::CalculateT0(Float_t* amp)
206{
207 Float_t tempT0 = 0.;
208 if (amp)
209 *amp = 0;
210
211 // Get WaveDigit for BC1_Top and BC1_Bottom detectors
212 BmnTrigWaveDigit* digBC1T = (BmnTrigWaveDigit*)fBC1Digits_Top->UncheckedAt(0);
213 BmnTrigWaveDigit* digBC1B = (BmnTrigWaveDigit*)fBC1Digits_Bottom->UncheckedAt(0);
214 Int_t nSemplesWF = digBC1T->GetNSamples();
215 Short_t* valBC1T = digBC1T->GetShortValue();
216 Short_t* valBC1B = digBC1B->GetShortValue();
217 vector<Double_t> vtimeBC1T = digBC1T->TdcVector();
218 vector<Double_t> vtimeBC1B = digBC1B->TdcVector();
219
220 if (nSemplesWF <= 0 || LimitWvHgh >= nSemplesWF)
221 return 0;
222
223 if (vtimeBC1T.size() == 0 || vtimeBC1B.size() == 0)
224 return 0;
225
226 if (valBC1T == nullptr || valBC1B == nullptr)
227 return 0;
228
229 Double_t timeBC1 = 0, timeBC1T = 0, timeBC1B = 0;
230
231 // Find TDC time for Top and Bottom in TdcDigitsArray
232 timeBC1T = FindTimeFromVector(vtimeBC1T);
233 timeBC1B = FindTimeFromVector(vtimeBC1B);
234 timeBC1 = (timeBC1T + timeBC1B) * 0.5;
235
236 // calculate the signal amplitude of Top and Bottom
237 Double_t maxBC1T = 0, maxBC1B = 0, maxBC1T_fit = 0, maxBC1B_fit = 0;
238 Double_t maxStBC1T = 0, maxStBC1B = 0;
239
240 ClearTGraph(fGr4FitBC1Top);
241 ClearTGraph(fGr4FitBC1Bottom);
242 for (Int_t ist = LimitWvLow; ist < LimitWvHgh; ist++) {
243 fGr4FitBC1Top->AddPoint(ist, valBC1T[ist]);
244 fGr4FitBC1Bottom->AddPoint(ist, valBC1B[ist]);
245 if (maxBC1T < valBC1T[ist]) {
246 maxBC1T = valBC1T[ist];
247 maxStBC1T = (Double_t)ist;
248 }
249 if (maxBC1B < valBC1B[ist]) {
250 maxBC1B = valBC1B[ist];
251 maxStBC1B = (Double_t)ist;
252 }
253 }
254
255 f_gaus->SetParameters(maxBC1T, maxStBC1T, 1);
256 fGr4FitBC1Top->Fit(f_gaus, "QW", "", maxStBC1T - GateFitLow, maxStBC1T + GateFitHgh);
257 maxBC1T_fit = f_gaus->GetParameter(0);
258
259 f_gaus->SetParameters(maxBC1B, maxStBC1B, 1);
260 fGr4FitBC1Bottom->Fit(f_gaus, "QW", "", maxStBC1B - GateFitLow, maxStBC1B + GateFitHgh);
261 maxBC1B_fit = f_gaus->GetParameter(0);
262
263 // calculate the geometric mean of amplitude
264 Double_t gAmpBC1 = TMath::Sqrt(maxBC1T_fit * maxBC1B_fit);
265
266 // correct the time on amplitude
267 // tempT0 = timeBC1;
268 tempT0 = timeBC1 + f_BC1->Eval(gAmpBC1);
269 if (amp)
270 *amp = gAmpBC1;
271
272 return tempT0;
273}
274
275// ---- find time from vector of TDC hits ----------------------------------
276Double_t BmnFillTrigInfoDst::FindTimeFromVector(vector<Double_t> vtime)
277{
278
279 for (UInt_t i = 0; i < vtime.size(); i++) {
280 if (vtime.at(i) > LimitTdcLow && vtime.at(i) < LimitTdcHgh)
281 return vtime.at(i);
282 }
283 return 0;
284}
285
286// ---- clear points in TGraph ----------------------------------
287void BmnFillTrigInfoDst::ClearTGraph(TGraph* g1)
288{
289 if (g1 == nullptr)
290 return;
291
292 for (int ip = g1->GetN() - 1; ip >= 0; ip--) {
293 g1->RemovePoint(ip);
294 }
295}
int i
Definition P4_F32vec4.h:22
vector< uint32_t > & GetInputSignalsVector()
UInt_t GetInputSignalsBR()
UInt_t GetInputSignalsAR()
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
BmnTask.
Definition BmnTask.h:13
void SetBDMult(UInt_t a)
void SetT0_time(Float_t v)
void SetSiMDMult(UInt_t a)
void SetInputSignalsVector(vector< uint32_t > v)
void SetT0_amp(Float_t v)
void SetBC2Amp(Float_t a)
TClonesArray * GetBDDigits()
void SetVCAmp(Float_t a)
void SetFDAmp(Float_t a)
TClonesArray * GetBC0Digits()
TClonesArray * GetBC1Digits()
TClonesArray * GetBC2Digits()
void SetInputSignalsAR(UInt_t v)
void SetBC1Amp(Float_t a)
void SetInputSignalsBR(UInt_t v)
TClonesArray * GetFDDigits()
void SetBC1Integral(Float_t a)
void SetBC0Amp(Float_t a)
Short_t * GetShortValue() const
int GetPeak(UInt_t start=0, UInt_t stop=1e9) const
UInt_t GetNSamples() const
vector< Double_t > & TdcVector()
int GetIntegral(UInt_t start=0, UInt_t stop=1e9) const
STL namespace.