er  dev
ERNeuRadAEvent.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERNeuRadAEvent.h"
10 //--------------------------------------------------------------------------------------------------
11 ERNeuRadAEvent::ERNeuRadAEvent() : fNPoints(1024) { //fNPoints is number of points in one event, 1024 or 1000
12 
13  Init();
14  Reset();
15 
16 }
17 //--------------------------------------------------------------------------------------------------
18 ERNeuRadAEvent::ERNeuRadAEvent(const Int_t npoints) : fNPoints(npoints) {
19 
20  Init();
21  Reset();
22 }
23 //--------------------------------------------------------------------------------------------------
24 ERNeuRadAEvent::~ERNeuRadAEvent() {
25  // TODO Auto-generated destructor stub
26  delete fGraphSignal;
27  delete fGraphCFD;
28  delete fInputEvent;
29 }
30 //--------------------------------------------------------------------------------------------------
31 void ERNeuRadAEvent::ProcessEvent(Bool_t bSmooth) {
32 
33  if (fInputEvent == NULL) {
34  Warning("ERNeuRadAEvent::ProcessEvent", "Input event wasn't set. Function won't be processed.");
35  return;
36  }
37 
38  const Double_t *amp = fInputEvent->GetAmp();
39  const Double_t *time = fInputEvent->GetTime();
40  fEvent = fInputEvent->GetEvent();
41 
42  for(Int_t j = 0; j < fNPoints; j++) {
43  fAmpPos[j] = amp[j]*(-1.);
44  fTime[j] = time[j];
45  }
46 
47  //fZeroLevel = FindZeroLevel();
48  fZeroLevel = 0.;
49  for(Int_t j = 0; j < fNPoints; j++) {
50  fAmpPos[j] = fAmpPos[j] - fZeroLevel;
51  }
52 
53  SetMaxAmplitudes();
54 
55  SetGraphs();
56  FindFrontProperties();
57  SetLED();
58 
59  if (bSmooth == kTRUE) {
60  SmoothGraphs();
61  }
62  else {
63  SetGraphs();
64  }
65 
66  SetCFD();
67  SetChargeCFD();
68  SetChargeLED();
69  SetChargeTF();
70  SetToT();
71  ObtainPE();
72 
73  return;
74 }
75 //--------------------------------------------------------------------------------------------------
76 void ERNeuRadAEvent::Reset() {
77 
78  for (Int_t i = 0; i < fNPoints; i++) {
79  fAmpPos[i] = 0;
80  fTime[i] = 0;
81  fAmpCFD[i] = 0;
82  }
83  fTimeLED = -100.;
84  fEdgeSlope=0.;
85  fEdgeXi=0.;
86  fEdgeSlope=-100.;
87  fTime10=0.;
88  fTime90=0.;
89  fTimeMid=0.;
90  fToT=-100.;
91  fAmpMid=0.;
92  fAmpMax = 0.;
93  fTimeAmpMax = 0.;
94  fTimeCFD = -100.;
95  fZeroLevel = 0.;
96  fChargeCFD = -10.;
97  fChargeLED = -10.;
98  fTimeFront = -100.;
99  fStartTime = 0;
100  fFinishTime = 0;
101  fPEAmps.Reset();
102  fPETimes.Reset();
103 }
104 //--------------------------------------------------------------------------------------------------
105 void ERNeuRadAEvent::SetInputEvent(ERNeuRadRawEvent** event) {
106 
107  if (event == 0) {
108  Warning("ERNeuRadAEvent::SetInputEvent", "Input event was set as 0.");
109  }
110  fInputEvent = *event;
111 }
112 //--------------------------------------------------------------------------------------------------
113 void ERNeuRadAEvent::Init() {
114 
115  fAmpPos.Set(fNPoints);
116  fTime.Set(fNPoints);
117  fAmpCFD.Set(fNPoints);
118 
119  fGraphSignal = new TGraph();
120  fGraphCFD = new TGraph();
121  fInputEvent = 0;
122 
123  fCFratio = 0.;
124  fCFtimeDelay = 0.;
125 
126  fNoiseRangeMin = 0.;
127  fNoiseRangeMax = 1.;
128 
129 }
130 //--------------------------------------------------------------------------------------------------
131 void ERNeuRadAEvent::SetGraphs() { // creating TGraph from TArray
132 
133  fGraphSignal->Set(fNPoints);
134 
135  for (Int_t i=0; i<fNPoints; i++) {
136  fGraphSignal->SetPoint(i, fTime[i], fAmpPos[i]);
137  }
138  return;
139 }
140 //--------------------------------------------------------------------------------------------------
141 void ERNeuRadAEvent::SmoothGraphs() {
142 
143  //smoothing graph
144  fGraphSignal->Set(fNPoints - fWinSize/2);
145 
146  Int_t winMidSize = fWinSize / 2;
147  Double_t tmin, tmax, meanTime, meanAmp, sumAmp;
148 
149  for(Int_t i = winMidSize; i < fNPoints - winMidSize; ++i) {
150  sumAmp = 0;
151  tmin = 0;
152  tmax = 0;
153  meanTime = 0;
154  meanAmp = 0;
155  for(Int_t j = i - winMidSize; j <= (i + winMidSize); ++j) {
156  if (j == i - winMidSize) { tmin = fTime[j]; }
157  if (j == i + winMidSize) { tmax = fTime[j]; }
158  sumAmp += fAmpPos[j];
159  }
160  meanTime = (tmax - tmin)*0.5 + tmin;
161  //cout<<"mean time "<<meant<<endl;
162 
163  meanAmp = sumAmp / fWinSize;
164  //cout<<"mean amp "<<fAmpPos[i]<<endl;
165 
166  fGraphSignal->SetPoint(i, meanTime, meanAmp);
167  }
168  return;
169 }
170 //--------------------------------------------------------------------------------------------------
171 void ERNeuRadAEvent::SetCFD() { // CFD method
172 
173  Double_t time = 0;
174  Double_t mytime = fCFtimeDelay;
175  fGraphCFD->Set(fNPoints);
176 
177  //working variables
178  Double_t maxCFD = 0., minCFD = 0.;
179  Double_t TmaxCFD = 0., TminCFD = 0.;
180  Double_t ampCFD;
181  const Double_t timeStep = 0.1;
182  Int_t i = 0; //for graph
183 
184  //while goes by the graph with the step of timeStep
185  while( mytime < (100. - fCFtimeDelay) ) {
186 
187  ampCFD = fGraphSignal->Eval(mytime)*fCFratio*(-1) + fGraphSignal->Eval(mytime - fCFtimeDelay);
188  fGraphCFD->SetPoint(i, mytime, ampCFD);
189 
190  //point for max CFD amplitude
191  if( ampCFD > maxCFD) {
192  maxCFD = ampCFD;
193  TmaxCFD = mytime;
194  }
195 
196  //point for min CFD amplitude
197  if( ampCFD < minCFD) {
198  minCFD = ampCFD;
199  TminCFD = mytime;
200  }
201 
202  i++;
203  mytime = mytime + timeStep;
204  }
205 
206  //looking for the first point with the closest values to 0 and writing to fTimeCFD
207  time = TminCFD;
208  while( (fGraphCFD->Eval(time) <= 0) && (time <= TmaxCFD) /*&& (time >= TminCFD)*/ ) {
209  fTimeCFD = time;
210  time = time + timeStep;
211  }
212  return;
213 }
214 //--------------------------------------------------------------------------------------------------
215 void ERNeuRadAEvent::FindFrontProperties() {
216 
217  //in percents
218  const Double_t minHeight = 0.1;
219  const Double_t maxHeight = 0.9;
220 
221  const Double_t timeStep = 0.05; //in ns
222  Double_t time = 0; //in ns
223  Double_t mytime = 0.;
224 
225  if (!fGraphSignal) {
226  Warning("ERNeuRadAEvent::FindFrontProperties", "Graph was not set");
227  return;
228  }
229 
230  //TODO search of minimum should be done from the lower edge on the time axis
231 
232  while (fGraphSignal->Eval(time) <= maxHeight*fAmpMax && time<200.) {
233  fTime90 = time;
234  time = time + timeStep;
235  };
236 
237  time = fTime90;
238  while( fGraphSignal->Eval(time) >= minHeight*fAmpMax && time>0) {
239  fTime10 = time;
240  time = time - timeStep;
241  }
242 
243  TF1 *fit1 = new TF1("fit1","[1]*x+[0]"); //function for one parameter fitting in the range of pmin-pmax
244  fit1->SetRange(fTime10,fTime90);
245 
246  fGraphSignal->Fit(fit1,"RQN","goff");
247  fEdgeSlope = fit1->GetParameter(1);
248  fEdgeXi = fit1->GetChisquare();
249 
250  fTimeMid = (fTime90 -fTime10)*0.5 + fTime10; //time point between fTime90 and fTime10
251  fAmpMid = fGraphSignal->Eval(fTimeMid);
252 
253  //adding point where fit function crosses zero
254  Double_t a = 0, b = 0;
255  TF1 *line = new TF1("line","[1]*x + [0]");
256  a = fit1->GetParameter(1);
257  b = fit1->GetParameter(0);
258  line->SetParameter(0,b);
259  line->SetParameter(1,a);
260 
261  if( a!= 0. && b!= 0. ) { //in case of fit data is empty
262  while(line->Eval(mytime) <= 0 && mytime <= 100.) {
263  fTimeFront = mytime;
264  mytime = mytime + timeStep;
265  }
266  }
267 
268  delete fit1;
269 }
270 //--------------------------------------------------------------------------------------------------
271 Double_t ERNeuRadAEvent::FindZeroLevel() {
272 
273  SetGraphs();
274  Double_t correction = 0;
275  TF1 *fit1 = new TF1("fit1","[0]"); //function for one parameter fitting in the range of pmin-pmax
276  fit1->SetRange(fNoiseRangeMin,fNoiseRangeMax);
277 
278  if (!fGraphSignal) {
279  Warning("ERNeuRadAEvent::FindZeroLevel", "Graph was not set");
280  return 0;
281  }
282 
283  fGraphSignal->Fit(fit1,"RQN","goff");
284  correction = fit1->GetParameter(0);
285 
286  delete fit1;
287  return correction;
288 }
289 //--------------------------------------------------------------------------------------------------
290 void ERNeuRadAEvent::SetChargeCFD(Int_t tmin, Int_t tmax) { // tmin = -3, tmax = 17
291 
292  Double_t integral = 0.; //voltage
293  Double_t time_sig = 0; //approximate signal duration in seconds
294  const Double_t res = 50.; //resistance 50 Om
295  time_sig = (double)(-tmin + tmax)*(1e-9);
296 
297  Int_t imin = 0, imax = 0;
298 
299  Int_t i = 0;
300  while ( fTime[i] < (fTimeCFD + tmin) && (i < (fGraphSignal->GetN()-1)) ) { imin = i; i++; }
301  while ( fTime[i] < (fTimeCFD + tmax) && (i < (fGraphSignal->GetN()-1)) ) { imax = i; i++; }
302 
303  integral = fGraphSignal->Integral(imin, imax);
304 
305  fChargeCFD = integral*time_sig/res;
306 
307  return;
308 
309 }
310 //--------------------------------------------------------------------------------------------------
311 void ERNeuRadAEvent::SetChargeLED(Int_t tmin, Int_t tmax) { // tmin = -3, tmax = 17
312 
313  Double_t integral = 0.; //voltage
314  Double_t time_sig = 0; //approximate signal duration in seconds
315  const Double_t res = 50.; //resistance 50 Om
316  time_sig = (double)(-tmin + tmax)*(1e-9);
317 
318  Int_t imin = 0, imax = 0;
319 
320  Int_t i = 0;
321  while ( fTime[i] < (fTimeLED + tmin) && (i < (fGraphSignal->GetN()-1)) ) { imin = i; i++; }
322  while ( fTime[i] < (fTimeLED + tmax) && (i < (fGraphSignal->GetN()-1)) ) { imax = i; i++; }
323 
324  integral = fGraphSignal->Integral(imin, imax);
325 
326  fChargeLED = integral*time_sig/res;
327 
328  return;
329 }
330 //--------------------------------------------------------------------------------------------------
331 void ERNeuRadAEvent::SetChargeTF(Int_t tmin, Int_t tmax) { // tmin = -3, tmax = 17
332 
333  Double_t integral = 0.; //voltage
334  Double_t time_sig = 0; //approximate signal duration in seconds
335  const Double_t res = 50.; //resistance 50 Om
336  time_sig = (double)(-tmin + tmax)*(1e-9);
337 
338  Int_t imin = 0, imax = 0;
339 
340  Int_t i = 0;
341  while ( fTime[i] < (fTimeFront + tmin) && (i < (fGraphSignal->GetN()-1)) ) { imin = i; i++; }
342  while ( fTime[i] < (fTimeFront + tmax) && (i < (fGraphSignal->GetN()-1)) ) { imax = i; i++; }
343 
344  integral = fGraphSignal->Integral(imin, imax);
345 
346  fChargeTF = integral*time_sig/res;
347 
348  return;
349 }
350 //--------------------------------------------------------------------------------------------------
351 Double_t ERNeuRadAEvent::GetfCFD() {
352  return fTimeCFD;
353 }
354 //--------------------------------------------------------------------------------------------------
355 
356 Double_t ERNeuRadAEvent::GetfLED() {
357  return fTimeLED;
358 }
359 //--------------------------------------------------------------------------------------------------
360 Double_t ERNeuRadAEvent::GetOnefTime(Int_t i) {
361  return fTime[i];
362 }
363 //--------------------------------------------------------------------------------------------------
364 Double_t ERNeuRadAEvent::GetOnefAmpPos(Int_t i) {
365  return fAmpPos[i];
366 }
367 //--------------------------------------------------------------------------------------------------
368 Double_t ERNeuRadAEvent::GetT_10() {
369  return fTime10;
370 }
371 //--------------------------------------------------------------------------------------------------
372 Double_t ERNeuRadAEvent::GetT_90() {
373  return fTime90;
374 }
375 //--------------------------------------------------------------------------------------------------
376 Double_t ERNeuRadAEvent::GetEdgeSlope() {
377  return fEdgeSlope;
378 }
379 //--------------------------------------------------------------------------------------------------
380 Double_t ERNeuRadAEvent::GetEdgeXi() {
381  return fEdgeXi;
382 }
383 //--------------------------------------------------------------------------------------------------
384 void ERNeuRadAEvent::SetMaxAmplitudes() {
385  Double_t maxAmp = 0.;
386  Double_t maxAmpT = 0.;
387 
388  maxAmp = fAmpPos[0];
389  for(Int_t j=0; j < fNPoints; j++) {
390  if(fAmpPos[j] > maxAmp) {
391  maxAmp = fAmpPos[j];
392  maxAmpT = fTime[j];
393  }
394  }
395  fAmpMax = maxAmp;
396  fTimeAmpMax = maxAmpT;
397 }
398 //--------------------------------------------------------------------------------------------------
399 void ERNeuRadAEvent::SetLED(Double_t threshold) {
400  Double_t time = 0;
401  const Double_t timeStep = 0.05;
402  while( time < fTimeAmpMax && fGraphSignal->Eval(time) <= threshold ) {
403  fTimeLED = time;
404  time = time + timeStep;
405  }
406 }
407 //--------------------------------------------------------------------------------------------------
408 void ERNeuRadAEvent::SetToT() {
409  Double_t time = fTimeMid;
410  Double_t timeBack = 0;
411  const Double_t ns = 15.; //withing this interval signal should end for sure, in nanosec
412 
413  const Double_t timeStep = 0.05;
414 
415  while( fGraphSignal->Eval(time) >= fAmpMid && time < fTimeMid + ns) {
416  timeBack = time;
417  time = time + timeStep;
418  }
419  fToT = timeBack - fTimeMid;
420  return;
421 }
422 //--------------------------------------------------------------------------------------------------
423 void ERNeuRadAEvent::ObtainPE() {
424  SetPETimes(fInputEvent->GetPETimes());
425  SetPEAmps(fInputEvent->GetPEAmps());
426  return;
427 }
428 //--------------------------------------------------------------------------------------------------
429 Double_t ERNeuRadAEvent::GetStartTime() {
430  return fStartTime;
431 }
432 //--------------------------------------------------------------------------------------------------
433 void ERNeuRadAEvent::SetStartTime(Double_t t) {
434  fStartTime = t;
435  return;
436 }
437 //--------------------------------------------------------------------------------------------------
438 Double_t ERNeuRadAEvent::GetFinishTime() {
439  return fFinishTime;
440 }
441 //--------------------------------------------------------------------------------------------------
442 void ERNeuRadAEvent::SetFinishTime(Double_t t) {
443  fFinishTime = t;
444  return;
445 }
446 //--------------------------------------------------------------------------------------------------
447 void ERNeuRadAEvent::SetEvent(Int_t t) {
448  fEvent = t;
449  return;
450 }
451 //--------------------------------------------------------------------------------------------------
452 ClassImp(ERNeuRadAEvent)
class for processing raw data and getting amp and time properties of signal
class for raw data obtained from measurements or simulations