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

#include "AEvent.h"

10
AEvent::AEvent() : fNPoints(1024) {	//fNPoints is number of points in one event, 1024 or 1000
11 12 13 14 15 16

	Init();
	Reset();

}

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

	Init();
	Reset();
}

23 24
AEvent::~AEvent() {
	// TODO Auto-generated destructor stub
25 26
	delete fGraphSignal;
	delete fGraphCFD;
27
	delete fInputEvent;
28 29 30 31 32 33 34 35 36 37 38 39 40
}


void AEvent::ProcessEvent() {

	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();

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

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

51
	SetMaxAmplitudes();
52

53
	SetGraphs();
54
	FindFrontProperties();
55
	SetLED();
Vratislav Chudoba's avatar
Vratislav Chudoba committed
56
//	SetGraphs();
57
	SetCFD();
58
	SetChargeCFD();
59
	SetChargeLED();
60

61 62 63 64 65 66
	return;

}

void AEvent::Reset() {

67
	for (Int_t i = 0; i < fNPoints; i++) {
68 69
		fAmpPos[i] = 0;
		fTime[i] = 0;
70
		fAmpCFD[i] = 0;
71
	}
72
	fTimeLED = -100.;
73
	fEdgeSlope=0.;
74
	fEdgeXi=0.;
75
	fEdgeSlope=-100.;
76 77
	fTime10=0.;
	fTime90=0.;
78 79
	fAmpMax = 0.;
	fTimeAmpMax = 0.;
80
	fTimeCFD = -100.;
81
	fZeroLevel = 0.;
82 83
	fChargeCFD = -10.;
	fChargeLED = -10.;
84
	fTimeFront = -100.;
85 86 87 88 89 90 91 92 93 94 95 96 97
}

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

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

}

void AEvent::Init() {

98 99 100 101
	fAmpPos.Set(fNPoints);
	fTime.Set(fNPoints);
	fAmpCFD.Set(fNPoints);

102 103
	fGraphSignal = new TGraph();
	fGraphCFD = new TGraph();
104 105
	fInputEvent = 0;

106 107 108
	fCFratio = 0.;
	fCFtimeDelay = 0.;

109 110 111
	fNoiseRangeMin = 0.;
	fNoiseRangeMax = 1.;

112 113 114 115
}

void AEvent::SetGraphs() {

116
	fGraphSignal->Set(fNPoints);
117 118

	for (Int_t i=0; i<fNPoints; i++) {
119
		fGraphSignal->SetPoint(i, fTime[i], fAmpPos[i]);
120 121 122 123
	}

	return;
}
124

125
void AEvent::SetCFD() {
126

Muzalevsky I.A's avatar
Muzalevsky I.A committed
127
	Double_t time = 0;
128
	Double_t mytime = fCFtimeDelay;
129 130 131 132
	fGraphCFD->Set(fNPoints);

	//working variables
	Double_t maxCFD = 0., minCFD = 0.;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
133
	Double_t TmaxCFD = 0., TminCFD = 0.;	
134 135
	Double_t ampCFD;
	const Double_t timeStep = 0.1;
136 137 138
	Int_t i = 0; //for graph 
 
	//while goes by the graph with the step of timeStep
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
	while( mytime < (200. - fCFtimeDelay) ) {

		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;
	}
159

160
	//looking for the first point with the closest values to 0 and writing to fTimeCFD
Muzalevsky I.A's avatar
Muzalevsky I.A committed
161
	time = TminCFD;
162
	while( (fGraphCFD->Eval(time) <= 0) && (time <= TmaxCFD) /*&& (time >= TminCFD)*/ ) {
Muzalevsky I.A's avatar
Muzalevsky I.A committed
163 164 165 166
		fTimeCFD = time;
		time = time + timeStep;
	}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
167
}
Muzalevsky I.A's avatar
Muzalevsky I.A committed
168

169 170
void AEvent::FindFrontProperties() {

171 172 173 174 175
	//in percents
	const Double_t minHeight = 0.1;
	const Double_t maxHeight = 0.9;

	const Double_t timeStep = 0.05;	//in ns
176
	Double_t time = 0;			//in ns
177
	Double_t mytime = 0.;
178

179
	if (!fGraphSignal) {
180
		Warning("AEvent::FindFrontProperties", "Graph was not set");
181 182 183
		return;
	}

184
	//TODO search of minimum should be done from the lower edge on the time axis
185

186
	while (fGraphSignal->Eval(time) <= maxHeight*fAmpMax && time<200.) {
187
		fTime90 = time;
188 189 190 191 192 193
		time = time + timeStep;
	};

	time = fTime90;
	while( fGraphSignal->Eval(time) >= minHeight*fAmpMax && time>0) {
		fTime10 = time;
194
		time = time - timeStep;
195
	}
196

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

200
	fGraphSignal->Fit(fit1,"RQN","goff");
201

202
	fEdgeSlope = fit1->GetParameter(1);
203
	fEdgeXi = fit1->GetChisquare();
204

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
	//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);	
	//cout<<"par 0 "<<b<<endl;
	//cout<<"par 1 "<<a<<endl;

	if( a!= 0. && b!= 0. ) {	//in case of fit data is empty
		while(line->Eval(mytime) <= 0 && mytime <= 200.) {	
			//cout<< "mytime "<<mytime<<endl;
			fTimeFront = mytime;
			mytime = mytime + timeStep;
		}
	}

223 224
	delete fit1;
}
225

226
Double_t AEvent::FindZeroLevel() {
227 228 229

	SetGraphs();
	Double_t correction = 0;
230
	TF1 *fit1 = new TF1("fit1","[0]");	//function for one parameter fitting in the range of pmin-pmax
231
	fit1->SetRange(fNoiseRangeMin,fNoiseRangeMax);
232 233 234 235 236

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

238 239
	fGraphSignal->Fit(fit1,"RQN","goff");
	correction = fit1->GetParameter(0);
240

241 242
	delete fit1;
	return correction;
243
}
244

245
void AEvent::SetChargeCFD(Int_t tmin, Int_t tmax) { // tmin = -3, tmax = 17
246
	
247 248 249 250
	Double_t integral = 0.;					//voltage
	Double_t time_sig = 0;					//approximate signal duration in seconds
	const Double_t res = 50.; 				//resistance 50 Om
	time_sig = (double)(-tmin + tmax)*(1e-9);
251

252
	/*for(Int_t i = 0; i < fNPoints; i++) {
253
		if( fTime[i] > (fTimeCFD + tmin) && fTime[i] < (fTimeCFD + tmax) ) {
254 255
			integral = integral + fAmpPos[i];
		}
256 257 258 259 260 261 262 263 264 265
	}*/

	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);

266
	fChargeCFD = integral*time_sig/res;
267 268 269 270 271

	return;

}

272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
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
	time_sig = (double)(-tmin + tmax)*(1e-9);

/*	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;

	Int_t i = 0;
	while ( fTime[i] < (fTimeLED + tmin) && (i < (fGraphSignal->GetN()-1)) ) { imin = i; i++; }
289
//	i = 0;
290 291 292 293 294 295 296 297 298 299
	while ( fTime[i] < (fTimeLED + tmax) && (i < (fGraphSignal->GetN()-1)) ) { imax = i; i++; }

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

	fChargeLED = integral*time_sig/res;

	return;

}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
300
Double_t AEvent::GetfCFD() {
301
		return fTimeCFD;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
302 303
}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
304 305 306 307
Double_t AEvent::GetfLED() {
		return fTimeLED;
}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
308 309 310
Double_t AEvent::GetOnefTime(Int_t i) {
		return fTime[i];
}
311

Muzalevsky I.A's avatar
Muzalevsky I.A committed
312 313
Double_t AEvent::GetOnefAmpPos(Int_t i) {
		return fAmpPos[i];
314
}
315 316

Double_t AEvent::GetT_10() {
317
		return fTime10;
318 319 320
}

Double_t AEvent::GetT_90() {
321
		return fTime90;
322 323 324
}

Double_t AEvent::GetEdgeSlope() {
325 326
		return fEdgeSlope;
}
327

328 329 330 331
Double_t AEvent::GetEdgeXi() {
		return fEdgeXi;
}

332 333 334 335 336 337 338 339 340 341 342 343 344
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;
345

346
}
347 348 349 350

void AEvent::SetLED(Double_t threshold) {
	
	Double_t time = 0;
351 352
	const Double_t timeStep = 0.05;
	while( time < fTimeAmpMax && fGraphSignal->Eval(time) <= threshold ) {
353 354 355
		fTimeLED = time;
		time = time + timeStep;
	}
356 357
	//fTimeLED = time; найти номера точек которые лежат на 3 нс раньше и на 20 нс позже чем точка с временем timeled (искать точки в пределах условных)
	// сделать через функцию getpoint и цикл по точкам от 
358 359

}