AEvent.cpp 6.73 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 41 42 43 44 45 46 47 48 49 50 51 52
}

void AEvent::SetRawDataFile(const char* inprawfile, const char* treename) {

	TString iFileName = inprawfile;
	TFile *fraw = new TFile(iFileName.Data());
	if ( !fraw->IsOpen() ) {
		Error("SetRawDataFile", "File %s was not opened and won't be processed", iFileName.Data());
	}
	TTree *traw = (TTree*)fraw->Get(treename);
	if (!traw) {
		Error("SetRawDataFile", "Tree %s was not found in file %s", treename, iFileName.Data());
	}
}

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

53
	for(Int_t j = 0; j < fNPoints; j++) {
54 55 56 57
		fAmpPos[j] = amp[j]*(-1.);
		fTime[j] = time[j];
	}

58
	fZeroLevel = FindZeroLevel();
59
	for(Int_t j = 0; j < fNPoints; j++) {
60
		fAmpPos[j] = fAmpPos[j] - fZeroLevel;
61 62
	}

63
	SetMaxAmplitudes();
64

65
	SetGraphs();
66
	FindFrontProperties();
67
	SetGraphs();
68
	SetCFD();
69
	SetChargeCFD();
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
	}

83
	fEdgeSlope=0.;
84
	fEdgeXi=0.;
85
	fEdgeSlope=-100.;
86 87
	fTime10=0.;
	fTime90=0.;
88 89
	fAmpMax = 0.;
	fTimeAmpMax = 0.;
90 91
	fTimeCFD = 0.;
	fZeroLevel = 0.;
92
	fChargeCFD = 0.;
93 94 95 96 97 98 99 100 101 102 103 104 105
}

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

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

}

void AEvent::Init() {

106 107 108 109
	fAmpPos.Set(fNPoints);
	fTime.Set(fNPoints);
	fAmpCFD.Set(fNPoints);

110 111
	fGraphSignal = new TGraph();
	fGraphCFD = new TGraph();
112 113
	fInputEvent = 0;

114 115 116
	fCFratio = 0.;
	fCFtimeDelay = 0.;

117 118 119
	fNoiseRangeMin = 0.;
	fNoiseRangeMax = 1.;

120 121 122 123
}

void AEvent::SetGraphs() {

124
	fGraphSignal->Set(fNPoints);
125 126

	for (Int_t i=0; i<fNPoints; i++) {
127
		fGraphSignal->SetPoint(i, fTime[i], fAmpPos[i]);
128 129 130 131
	}

	return;
}
132

133
void AEvent::SetCFD() {
134 135

	Double_t level = 100.;	//is necessary to find cfd amplitude value closest to zero
Muzalevsky I.A's avatar
Muzalevsky I.A committed
136
	Double_t time = 0;
137 138 139 140
	fGraphCFD->Set(fNPoints);

	//working variables
	Double_t maxCFD = 0., minCFD = 0.;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
141
	Double_t TmaxCFD = 0., TminCFD = 0.;	
142
	Int_t imax = 0, imin = 0;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
143
	const Double_t timeStep = 0.05;
144 145 146

	for (Int_t i=0; i<fNPoints; i++) {

147
		//CFD method
Muzalevsky I.A's avatar
Muzalevsky I.A committed
148
		if(i>fCFtimeDelay) { // условие, чтобы не выскочить из размера массива ( обрезает границы на fCFtimeDelay)
149 150 151
			fAmpCFD[i] = fAmpPos[i]*fCFratio*(-1);
			fAmpCFD[i] = fAmpCFD[i] + fAmpPos[i - fCFtimeDelay];
			fGraphCFD->SetPoint(i, fTime[i], fAmpCFD[i]);
152 153
		}

154
		//point for max CFD amplitude
155
		if(fAmpCFD[i] > maxCFD) {
156
			maxCFD = fAmpCFD[i];
Muzalevsky I.A's avatar
Muzalevsky I.A committed
157
			TmaxCFD = fTime[i];
158
			imax = i;
159 160
		}

161
		//point for min CFD amplitude
162
		if(fAmpCFD[i] < minCFD) {
163
			minCFD = fAmpCFD[i];
Muzalevsky I.A's avatar
Muzalevsky I.A committed
164
			TminCFD = fTime[i];
165
			imin = i;
166 167 168 169
		}

	}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
170
/*	//finding "zero" of CFD amplitude
171
	for(Int_t j = imin; j < imax; j++) {   
172 173
		if(abs(fAmpCFD[j]) < level) {
			level = abs(fAmpCFD[j]);
174
			fTimeCFD = fTime[j];
175
		}
176
	}
Muzalevsky I.A's avatar
Muzalevsky I.A committed
177 178 179 180 181 182 183 184
*/
	//I want to find zero of CFD using graph and eval
	time = TminCFD;
	while( (fGraphCFD->Eval(time) <= 0) && (time <= TmaxCFD) && (time >= TminCFD) ) {
		fTimeCFD = time;
		time = time + timeStep;
	}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
185
}
Muzalevsky I.A's avatar
Muzalevsky I.A committed
186

187 188
void AEvent::FindFrontProperties() {

189 190 191 192 193
	//in percents
	const Double_t minHeight = 0.1;
	const Double_t maxHeight = 0.9;

	const Double_t timeStep = 0.05;	//in ns
194
	Double_t time = 0;			//in ns
195
//	Int_t NumM = 0.;
196

197
	if (!fGraphSignal) {
198
		Warning("AEvent::FindFrontProperties", "Graph was not set");
199 200 201
		return;
	}

202 203
	//TODO search of minimum should be done from the lower edge on the time axis
//	cout << "Event!!!!!!!!!!!!!" << endl;
204 205
//	while( fGraphSignal->Eval(time) >= minHeight*fAmpMax && time>0) {
	while (fGraphSignal->Eval(time) <= maxHeight*fAmpMax && time<200.) {
206 207
//		cout << fAmpMax << "\t" << fGraphSignal->Eval(time) << "\t" << fTimeAmpMax << "\t" << time << endl;
		fTime90 = time;
208 209 210 211 212 213
		time = time + timeStep;
	};

	time = fTime90;
	while( fGraphSignal->Eval(time) >= minHeight*fAmpMax && time>0) {
		fTime10 = time;
214
		time = time - timeStep;
215
	}
216 217 218
//	cout << "Found time10 " << fTime10 << "\t" << fGraphSignal->Eval(fTime10) << "\t" << minHeight*fAmpMax << "\t" << fAmpMax << endl;
//	cout << "Found time10 " << fTime10 << "\t" << TMath::Abs(fGraphSignal->Eval(fTime10) - minHeight*fAmpMax) / fAmpMax * 100 << endl;
//	cout << "Found time90 " << fTime90 << "\t" << GetT_90() << endl;
219 220 221

//	cout<< "Time90 - time10 "<< fTime90 - fTime10 << endl;
//	if(fTime90 - fTime10 == 0.25 ) { cout<< "Zero !!"<<endl; }
222

223
	TF1 *fit1 = new TF1("fit1","[1]*x+[0]");	//function for one parameter fitting in the range of pmin-pmax
224
	fit1->SetRange(fTime10,fTime90);
225 226
//	fGraphSignal->Fit(fit1,"RQ","goff");
	fGraphSignal->Fit(fit1,"RQN","goff");
227
	fEdgeSlope = fit1->GetParameter(1);
228
	fEdgeXi = fit1->GetChisquare();
229 230 231 232

	delete fit1;
}
////////
233
Double_t AEvent::FindZeroLevel() {
234 235 236

	SetGraphs();
	Double_t correction = 0;
237
	TF1 *fit1 = new TF1("fit1","[0]");	//function for one parameter fitting in the range of pmin-pmax
238
	fit1->SetRange(fNoiseRangeMin,fNoiseRangeMax);
239 240 241 242 243

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

245 246
	fGraphSignal->Fit(fit1,"RQN","goff");
	correction = fit1->GetParameter(0);
247

248 249
	delete fit1;
	return correction;
250
}
251

252 253
void AEvent::SetChargeCFD(Int_t tmin, Int_t tmax) {
	
254 255 256 257
	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);
258 259

	for(Int_t i = 0; i < fNPoints; i++) {
260
		if( fTime[i] > (fTimeCFD + tmin) && fTime[i] < (fTimeCFD + tmax) ) {
261 262 263
			integral = integral + fAmpPos[i];
		}
	}
264
	fChargeCFD = integral*time_sig/res;
265 266 267 268 269 270 271
//	cout<<fCharge<<endl;
//	printf("\nIntegral is %f , charge is %lf \n", integral, fCharge);

	return;

}

Muzalevsky I.A's avatar
Muzalevsky I.A committed
272
Double_t AEvent::GetfCFD() {
273
		return fTimeCFD;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
274 275 276 277 278
}

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

Muzalevsky I.A's avatar
Muzalevsky I.A committed
280 281
Double_t AEvent::GetOnefAmpPos(Int_t i) {
		return fAmpPos[i];
282
}
283 284

Double_t AEvent::GetT_10() {
285
		return fTime10;
286 287 288
}

Double_t AEvent::GetT_90() {
289
		return fTime90;
290 291 292
}

Double_t AEvent::GetEdgeSlope() {
293 294
		return fEdgeSlope;
}
295

296 297 298 299
Double_t AEvent::GetEdgeXi() {
		return fEdgeXi;
}

300 301 302 303 304 305 306 307 308 309 310 311 312
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;
313

314
}