AEvent.cpp 5.19 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();
Vratislav Chudoba's avatar
Vratislav Chudoba committed
55
//	SetGraphs();
56
	SetCFD();
57
	SetChargeCFD();
58

59 60 61 62 63 64
	return;

}

void AEvent::Reset() {

65
	for (Int_t i = 0; i < fNPoints; i++) {
66 67
		fAmpPos[i] = 0;
		fTime[i] = 0;
68
		fAmpCFD[i] = 0;
69 70
	}

71
	fEdgeSlope=0.;
72
	fEdgeXi=0.;
73
	fEdgeSlope=-100.;
74 75
	fTime10=0.;
	fTime90=0.;
76 77
	fAmpMax = 0.;
	fTimeAmpMax = 0.;
78 79
	fTimeCFD = 0.;
	fZeroLevel = 0.;
80
	fChargeCFD = 0.;
81 82 83 84 85 86 87 88 89 90 91 92 93
}

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

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

}

void AEvent::Init() {

94 95 96 97
	fAmpPos.Set(fNPoints);
	fTime.Set(fNPoints);
	fAmpCFD.Set(fNPoints);

98 99
	fGraphSignal = new TGraph();
	fGraphCFD = new TGraph();
100 101
	fInputEvent = 0;

102 103 104
	fCFratio = 0.;
	fCFtimeDelay = 0.;

105 106 107
	fNoiseRangeMin = 0.;
	fNoiseRangeMax = 1.;

108 109 110 111
}

void AEvent::SetGraphs() {

112
	fGraphSignal->Set(fNPoints);
113 114

	for (Int_t i=0; i<fNPoints; i++) {
115
		fGraphSignal->SetPoint(i, fTime[i], fAmpPos[i]);
116 117 118 119
	}

	return;
}
120

121
void AEvent::SetCFD() {
122

Muzalevsky I.A's avatar
Muzalevsky I.A committed
123
	Double_t time = 0;
124
	Double_t mytime = fCFtimeDelay;
125 126 127 128
	fGraphCFD->Set(fNPoints);

	//working variables
	Double_t maxCFD = 0., minCFD = 0.;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
129
	Double_t TmaxCFD = 0., TminCFD = 0.;	
130 131
	Double_t ampCFD;
	const Double_t timeStep = 0.1;
132 133 134
	Int_t i = 0; //for graph 
 
	//while goes by the graph with the step of timeStep
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
	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;
	}
155

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

Muzalevsky I.A's avatar
Muzalevsky I.A committed
163
}
Muzalevsky I.A's avatar
Muzalevsky I.A committed
164

165 166
void AEvent::FindFrontProperties() {

167 168 169 170 171
	//in percents
	const Double_t minHeight = 0.1;
	const Double_t maxHeight = 0.9;

	const Double_t timeStep = 0.05;	//in ns
172
	Double_t time = 0;			//in ns
173

174
	if (!fGraphSignal) {
175
		Warning("AEvent::FindFrontProperties", "Graph was not set");
176 177 178
		return;
	}

179
	//TODO search of minimum should be done from the lower edge on the time axis
180

181
	while (fGraphSignal->Eval(time) <= maxHeight*fAmpMax && time<200.) {
182
		fTime90 = time;
183 184 185 186 187 188
		time = time + timeStep;
	};

	time = fTime90;
	while( fGraphSignal->Eval(time) >= minHeight*fAmpMax && time>0) {
		fTime10 = time;
189
		time = time - timeStep;
190
	}
191

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

195
	fGraphSignal->Fit(fit1,"RQN","goff");
196
	fEdgeSlope = fit1->GetParameter(1);
197
	fEdgeXi = fit1->GetChisquare();
198 199 200

	delete fit1;
}
201

202
Double_t AEvent::FindZeroLevel() {
203 204 205

	SetGraphs();
	Double_t correction = 0;
206
	TF1 *fit1 = new TF1("fit1","[0]");	//function for one parameter fitting in the range of pmin-pmax
207
	fit1->SetRange(fNoiseRangeMin,fNoiseRangeMax);
208 209 210 211 212

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

214 215
	fGraphSignal->Fit(fit1,"RQN","goff");
	correction = fit1->GetParameter(0);
216

217 218
	delete fit1;
	return correction;
219
}
220

221 222
void AEvent::SetChargeCFD(Int_t tmin, Int_t tmax) {
	
223 224 225 226
	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);
227 228

	for(Int_t i = 0; i < fNPoints; i++) {
229
		if( fTime[i] > (fTimeCFD + tmin) && fTime[i] < (fTimeCFD + tmax) ) {
230 231 232
			integral = integral + fAmpPos[i];
		}
	}
233
	fChargeCFD = integral*time_sig/res;
234 235 236 237 238

	return;

}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
239
Double_t AEvent::GetfCFD() {
240
		return fTimeCFD;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
241 242 243 244 245
}

Double_t AEvent::GetOnefTime(Int_t i) {
		return fTime[i];
}
246

Muzalevsky I.A's avatar
Muzalevsky I.A committed
247 248
Double_t AEvent::GetOnefAmpPos(Int_t i) {
		return fAmpPos[i];
249
}
250 251

Double_t AEvent::GetT_10() {
252
		return fTime10;
253 254 255
}

Double_t AEvent::GetT_90() {
256
		return fTime90;
257 258 259
}

Double_t AEvent::GetEdgeSlope() {
260 261
		return fEdgeSlope;
}
262

263 264 265 266
Double_t AEvent::GetEdgeXi() {
		return fEdgeXi;
}

267 268 269 270 271 272 273 274 275 276 277 278 279
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;
280

281
}