AEvent.cpp 10.6 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * AEvent.cpp
 *
 *  Created on: Dec 28, 2016
 *      Author: daria
 */

#include "AEvent.h"
9
AEvent::AEvent() : fNPoints(1024) {	//fNPoints is number of points in one event, 1024 or 1000
10 11 12 13 14 15

	Init();
	Reset();

}

16 17 18 19 20 21
AEvent::AEvent(const Int_t npoints) : fNPoints(npoints) {

	Init();
	Reset();
}

22 23
AEvent::~AEvent() {
	// TODO Auto-generated destructor stub
24 25
	delete fGraphSignal;
	delete fGraphCFD;
26
	delete fInputEvent;
27 28 29
}


Vratislav Chudoba's avatar
Vratislav Chudoba committed
30
void AEvent::ProcessEvent(Bool_t bSmooth) {
31 32 33 34 35 36 37 38 39

	if (fInputEvent == NULL) {
		Warning("AEvent::ProcessEvent", "Input event wasn't set. Function won't be processed.");
		return;
	}

	const Double_t *amp = fInputEvent->GetAmp();
	const Double_t *time = fInputEvent->GetTime();

40
	for(Int_t j = 0; j < fNPoints; j++) {
41 42 43 44
		fAmpPos[j] = amp[j]*(-1.);
		fTime[j] = time[j];
	}

45
	fZeroLevel = FindZeroLevel();
46
	for(Int_t j = 0; j < fNPoints; j++) {
47
		fAmpPos[j] = fAmpPos[j] - fZeroLevel;
48 49
	}

50
	SetMaxAmplitudes();
51

Vratislav Chudoba's avatar
Vratislav Chudoba committed
52 53 54
	if (bSmooth == kTRUE) {
		SmoothGraphs();
	}
55 56 57
	else {
		SetGraphs();
	}
Vratislav Chudoba's avatar
Vratislav Chudoba committed
58

59
	FindFrontProperties();
60
	SetLED();
Vratislav Chudoba's avatar
Vratislav Chudoba committed
61
//	SetGraphs();
62

63
	SetCFD();
64
	SetChargeCFD();
65
	SetChargeLED();
66
	SetChargeTF();
67
	SetToT();
68
	SetThreshold();
Vratislav Chudoba's avatar
Vratislav Chudoba committed
69
//	SmoothGraphs();
70

71 72 73 74 75 76
	return;

}

void AEvent::Reset() {

77
	for (Int_t i = 0; i < fNPoints; i++) {
78 79
		fAmpPos[i] = 0;
		fTime[i] = 0;
80
		fAmpCFD[i] = 0;
81
	}
82
	fTimeLED = -100.;
83
	fEdgeSlope=0.;
84
	fEdgeXi=0.;
85
	fEdgeSlope=-100.;
86 87
	fTime10=0.;
	fTime90=0.;
88
	fTimeMid=0.;
89 90
	fToT=-100.;
	fAmpMid=0.;
91 92
	fAmpMax = 0.;
	fTimeAmpMax = 0.;
93
	fTimeCFD = -100.;
94
	fZeroLevel = 0.;
95 96
	fChargeCFD = -10.;
	fChargeLED = -10.;
97
	fTimeFront = -100.;
98 99
	fTimeThreshBack = -100.;
	fTimeThresh = -100.;
100 101 102 103 104 105 106 107 108 109 110 111 112
}

void AEvent::SetInputEvent(RawEvent** event) {

	if (event == 0) {
		Warning("AEvent::SetInputEvent", "Input event was set as 0.");
	}
	fInputEvent = *event;

}

void AEvent::Init() {

113 114 115 116
	fAmpPos.Set(fNPoints);
	fTime.Set(fNPoints);
	fAmpCFD.Set(fNPoints);

117 118
	fGraphSignal = new TGraph();
	fGraphCFD = new TGraph();
119
//	fGraphSmooth = new TGraph();
120 121
	fInputEvent = 0;

122 123 124
	fCFratio = 0.;
	fCFtimeDelay = 0.;

125 126 127
	fNoiseRangeMin = 0.;
	fNoiseRangeMax = 1.;

128 129 130 131
}

void AEvent::SetGraphs() {

132
	fGraphSignal->Set(fNPoints);
133 134

	for (Int_t i=0; i<fNPoints; i++) {
135
		fGraphSignal->SetPoint(i, fTime[i], fAmpPos[i]);
136 137 138 139
	}

	return;
}
140

141 142 143
void AEvent::SmoothGraphs() {

	//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 152 153 154 155 156 157
		tmin = 0;
		tmax = 0;
		meanTime = 0;
		meanAmp = 0;
    		for(Int_t j = i - winMidSize; j <= (i + winMidSize); ++j) {
			if (j == i - winMidSize) { tmin = fTime[j]; }
			if (j == i + winMidSize) { tmax = fTime[j]; }
158
      			sumAmp += fAmpPos[j];
159 160 161 162
    		}
		meanTime = (tmax - tmin)*0.5 + tmin;
		//cout<<"mean time "<<meant<<endl;

163
    		meanAmp = sumAmp / fWinSize;
164 165
		//cout<<"mean amp "<<fAmpPos[i]<<endl;

166
    	fGraphSignal->SetPoint(i, meanTime, meanAmp);
167 168 169
		
	}	

170
//	fGraphSignal->Clone
Vratislav Chudoba's avatar
Vratislav Chudoba committed
171

172 173 174
	return;
}

175
void AEvent::SetCFD() {
176

Muzalevsky I.A's avatar
Muzalevsky I.A committed
177
	Double_t time = 0;
178
	Double_t mytime = fCFtimeDelay;
179 180 181 182
	fGraphCFD->Set(fNPoints);

	//working variables
	Double_t maxCFD = 0., minCFD = 0.;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
183
	Double_t TmaxCFD = 0., TminCFD = 0.;	
184 185
	Double_t ampCFD;
	const Double_t timeStep = 0.1;
186 187 188
	Int_t i = 0; //for graph 
 
	//while goes by the graph with the step of timeStep
189
	while( mytime < (fTimeLast - fCFtimeDelay) ) {
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

		ampCFD = fGraphSignal->Eval(mytime)*fCFratio*(-1) + fGraphSignal->Eval(mytime - fCFtimeDelay);
		fGraphCFD->SetPoint(i, mytime, ampCFD);

		//point for max CFD amplitude
		if( ampCFD > maxCFD) {
			maxCFD = ampCFD;
			TmaxCFD = mytime;
		}

		//point for min CFD amplitude
		if( ampCFD < minCFD) {
			minCFD = ampCFD;
			TminCFD = mytime;
		}

		i++;
		mytime = mytime + timeStep;
	}
209

210
	//looking for the first point with the closest values to 0 and writing to fTimeCFD
Muzalevsky I.A's avatar
Muzalevsky I.A committed
211
	time = TminCFD;
212
	while( (fGraphCFD->Eval(time) <= 0) && (time <= TmaxCFD) /*&& (time >= TminCFD)*/ ) {
Muzalevsky I.A's avatar
Muzalevsky I.A committed
213 214 215 216
		fTimeCFD = time;
		time = time + timeStep;
	}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
217
}
Muzalevsky I.A's avatar
Muzalevsky I.A committed
218

219 220
void AEvent::FindFrontProperties() {

221 222 223 224 225
	//in percents
	const Double_t minHeight = 0.1;
	const Double_t maxHeight = 0.9;

	const Double_t timeStep = 0.05;	//in ns
226
	Double_t time = 0;			//in ns
227
	Double_t mytime = fTimeAmpMax;
228

229
	if (!fGraphSignal) {
230
		Warning("AEvent::FindFrontProperties", "Graph was not set");
231 232 233
		return;
	}

234
	//TODO search of minimum should be done from the lower edge on the time axis
235

236
	while (fGraphSignal->Eval(time) <= maxHeight*fAmpMax && time<200.) {
237
		fTime90 = time;
238 239 240 241 242 243
		time = time + timeStep;
	};

	time = fTime90;
	while( fGraphSignal->Eval(time) >= minHeight*fAmpMax && time>0) {
		fTime10 = time;
244
		time = time - timeStep;
245
	}
246

247
	TF1 *fit1 = new TF1("fit1","[1]*x+[0]");	//function for one parameter fitting in the range of pmin-pmax
248
	fit1->SetRange(fTime10,fTime90);
249

250
	fGraphSignal->Fit(fit1,"RQN","goff");
251

252
	fEdgeSlope = fit1->GetParameter(1);
253
	fEdgeXi = fit1->GetChisquare();
254

255
	fTimeMid = (fTime90 -fTime10)*0.5 + fTime10; 	//time point between fTime90 and fTime10
256
	fAmpMid = fGraphSignal->Eval(fTimeMid);
257

258 259 260 261 262 263 264 265 266
	//adding point where fit function crosses zero
	Double_t a = 0, b = 0;
	TF1 *line = new TF1("line","[1]*x + [0]");
	a = fit1->GetParameter(1);
	b = fit1->GetParameter(0);
	line->SetParameter(0,b);
	line->SetParameter(1,a);	

	if( a!= 0. && b!= 0. ) {	//in case of fit data is empty
267
		while(line->Eval(mytime) >=0 && mytime <= fTimeLast && mytime>=0) {	
268 269
			//cout<< "mytime "<<mytime<<endl;
			fTimeFront = mytime;
270
			mytime = mytime - timeStep;
271 272 273
		}
	}

274 275
	delete fit1;
}
276

277
Double_t AEvent::FindZeroLevel() {
278 279 280

	SetGraphs();
	Double_t correction = 0;
281
	TF1 *fit1 = new TF1("fit1","[0]");	//function for one parameter fitting in the range of pmin-pmax
282
	fit1->SetRange(fNoiseRangeMin,fNoiseRangeMax);
283 284 285 286 287

	if (!fGraphSignal) {
		Warning("AEvent::FindZeroLevel", "Graph was not set");
		return 0;
	}
288

289 290
	fGraphSignal->Fit(fit1,"RQN","goff");
	correction = fit1->GetParameter(0);
291

292 293
	delete fit1;
	return correction;
294
}
295

296
void AEvent::SetChargeCFD(Int_t tmin, Int_t tmax) { // tmin = -3, tmax = 17
297
	
298 299 300
	Double_t integral = 0.;					//voltage
	Double_t time_sig = 0;					//approximate signal duration in seconds
	const Double_t res = 50.; 				//resistance 50 Om
301
	time_sig = (double)(-tmin + tmax);
302

303
	/*for(Int_t i = 0; i < fNPoints; i++) {
304
		if( fTime[i] > (fTimeCFD + tmin) && fTime[i] < (fTimeCFD + tmax) ) {
305 306
			integral = integral + fAmpPos[i];
		}
307 308 309 310 311 312 313 314 315 316
	}*/

	Int_t imin = 0, imax = 0;

	Int_t i = 0;
	while ( fTime[i] < (fTimeCFD + tmin) && (i < (fGraphSignal->GetN()-1)) ) { imin = i; i++; }
	while ( fTime[i] < (fTimeCFD + tmax) && (i < (fGraphSignal->GetN()-1)) ) { imax = i; i++; }

	integral = fGraphSignal->Integral(imin, imax);

317
	fChargeCFD = integral*time_sig/res;
318 319 320 321 322

	return;

}

323 324 325 326 327
void AEvent::SetChargeLED(Int_t tmin, Int_t tmax) { // tmin = -3, tmax = 17
	
	Double_t integral = 0.;					//voltage
	Double_t time_sig = 0;					//approximate signal duration in seconds
	const Double_t res = 50.; 				//resistance 50 Om
328
	time_sig = (double)(-tmin + tmax);
329 330 331 332 333 334 335 336

/*	for(Int_t i = 0; i < fNPoints; i++) {
		if( fTime[i] > (fTimeLED + tmin) && fTime[i] < (fTimeLED + tmax) ) {
			integral = integral + fAmpPos[i];
		}
	}*/

	Int_t imin = 0, imax = 0;
337 338

	Int_t i = 0;
339
	while ( fTime[i] < (fTimeLED + tmin) && (i < (fGraphSignal->GetN()-1)) ) { imin = i; i++; }
340 341 342
//	i = 0;
	while ( fTime[i] < (fTimeLED + tmax) && (i < (fGraphSignal->GetN()-1)) ) { imax = i; i++; }

343 344 345 346 347 348 349 350
	integral = fGraphSignal->Integral(imin, imax);

	fChargeLED = integral*time_sig/res;

	return;

}

351 352 353 354 355
void AEvent::SetChargeTF(Int_t tmin, Int_t tmax) { // tmin = -3, tmax = 17
	
	Double_t integral = 0.;					//voltage
	Double_t time_sig = 0;					//approximate signal duration in seconds
	const Double_t res = 50.; 				//resistance 50 Om
356
	time_sig = (double)(-tmin + tmax);
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372

	Int_t imin = 0, imax = 0;

	Int_t i = 0;
	while ( fTime[i] < (fTimeFront + tmin) && (i < (fGraphSignal->GetN()-1)) ) { imin = i; i++; }
//	i = 0;
	while ( fTime[i] < (fTimeFront + tmax) && (i < (fGraphSignal->GetN()-1)) ) { imax = i; i++; }

	integral = fGraphSignal->Integral(imin, imax);

	fChargeTF = integral*time_sig/res;

	return;

}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
373
Double_t AEvent::GetfCFD() {
374
		return fTimeCFD;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
375 376
}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
377 378 379 380
Double_t AEvent::GetfLED() {
		return fTimeLED;
}

381 382 383 384
Double_t AEvent::GetfThresh() {
	return fTimeThresh;
}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
385 386 387
Double_t AEvent::GetOnefTime(Int_t i) {
		return fTime[i];
}
388

Muzalevsky I.A's avatar
Muzalevsky I.A committed
389 390
Double_t AEvent::GetOnefAmpPos(Int_t i) {
		return fAmpPos[i];
391
}
392 393

Double_t AEvent::GetT_10() {
394
		return fTime10;
395 396 397
}

Double_t AEvent::GetT_90() {
398
		return fTime90;
399 400 401
}

Double_t AEvent::GetEdgeSlope() {
402 403
		return fEdgeSlope;
}
404

405 406 407 408
Double_t AEvent::GetEdgeXi() {
		return fEdgeXi;
}

409 410 411 412 413 414 415 416
Double_t AEvent::GetfChargeCFD() {
		return fChargeCFD;
}

Double_t AEvent::GetfChargeTF() {
		return fChargeTF;
}

417 418 419 420 421 422 423 424 425 426 427 428 429
void AEvent::SetMaxAmplitudes() {
	Double_t maxAmp = 0.;
	Double_t maxAmpT = 0.;

	maxAmp = fAmpPos[0];
	for(Int_t j=0; j < fNPoints; j++) {
		if(fAmpPos[j] > maxAmp) {
			maxAmp = fAmpPos[j];
			maxAmpT = fTime[j];
		}
	}
	fAmpMax = maxAmp;
	fTimeAmpMax = maxAmpT;
430
	fTimeLast = fTime[fNPoints-1];
431
}
432 433 434 435

void AEvent::SetLED(Double_t threshold) {
	
	Double_t time = 0;
436 437
	const Double_t timeStep = 0.05;
	while( time < fTimeAmpMax && fGraphSignal->Eval(time) <= threshold ) {
438 439 440
		fTimeLED = time;
		time = time + timeStep;
	}
441 442
	//fTimeLED = time; найти номера точек которые лежат на 3 нс раньше и на 20 нс позже чем точка с временем timeled (искать точки в пределах условных)
	// сделать через функцию getpoint и цикл по точкам от 
443 444

}
445

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
void AEvent::SetThreshold(Double_t thresholdBack, Double_t threshRise) {
	
	Double_t time = fTimeAmpMax;
	const Double_t timeStep = 0.05;
	while( time < fTimeLast && fGraphSignal->Eval(time) >= thresholdBack ) {
		fTimeThreshBack = time;
		time = time + timeStep;
	}
	
	time  = fTimeAmpMax;
	
	while( time >0 && fGraphSignal->Eval(time) >= threshRise) {
		fTimeThresh = time;
		time = time - timeStep;
	}
	//fTimeLED = time; найти номера точек которые лежат на 3 нс раньше и на 20 нс позже чем точка с временем timeled (искать точки в пределах условных)
	// сделать через функцию getpoint и цикл по точкам от 

}

466 467
void AEvent::SetToT() {

468 469 470
	Double_t time = fTimeAmpMax;
	Double_t timeBack;
	const Double_t ns = 10.; //withing this interval signal should end for sure, in nanosec
471 472 473 474

	const Double_t timeStep = 0.05;

	//cout<<"fAmpMid "<<fAmpMid<<endl;
475
	while( fGraphSignal->Eval(time) >= fAmpMid &&  time < fTimeLast) {
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
		//cout<<"timeback "<<timeBack<<endl;
		//cout<<"fGraphSignal->Eval(time) "<<fGraphSignal->Eval(time)<<endl;
		//cout<<endl;
		//if(timeBack>150.) {return;}
		timeBack = time;
		time = time + timeStep;
	}
	//cout<<"timeback "<<timeBack<<endl;

	fToT = timeBack - fTimeMid;
	//cout<<"ftot "<<fToT<<endl;



}