AEvent.cpp 3.97 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 59 60 61 62 63 64 65
//	SetGraphs();
	const Double_t zeroLevel = FindZeroLevel();
//	const Double_t zeroLevel = 0;
	for(Int_t j = 0; j < fNPoints; j++) {
		//fAmpPos[j] = amp[j]*(-1.) - zeroLevel;
		fAmpPos[j] = fAmpPos[j] - zeroLevel;
	}

66 67 68 69
	Double_t maxAmp = 0.;
	Double_t maxAmpT = 0.;

	maxAmp = fAmpPos[0];
70
	for(Int_t j=0; j < fNPoints; j++) {
71 72 73 74 75 76 77 78
		if(fAmpPos[j] > maxAmp) {
			maxAmp = fAmpPos[j];
			maxAmpT = fTime[j];
		}
	}
	fAmpMax = maxAmp;
	fTimeAmpMax = maxAmpT;

79 80 81 82
	SetGraphs();

	SetCFD();

83 84 85 86 87 88
	return;

}

void AEvent::Reset() {

89
	for (Int_t i = 0; i < fNPoints; i++) {
90 91
		fAmpPos[i] = 0;
		fTime[i] = 0;
92
		fAmpCFD[i] = 0;
93 94 95 96
	}

	fAmpMax = 0.;
	fTimeAmpMax = 0.;
97
	fCFD = 0.;
98 99 100 101 102 103 104 105 106 107 108 109 110
}

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

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

}

void AEvent::Init() {

111 112 113 114
	fAmpPos.Set(fNPoints);
	fTime.Set(fNPoints);
	fAmpCFD.Set(fNPoints);

115 116
	fGraphSignal = new TGraph();
	fGraphCFD = new TGraph();
117 118
	fInputEvent = 0;

119 120 121
	fCFratio = 0.;
	fCFtimeDelay = 0.;

122 123 124 125
}

void AEvent::SetGraphs() {

126
	fGraphSignal->Set(fNPoints);
127 128

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

	return;
}
134

135
void AEvent::SetCFD() {
136 137

	Double_t level = 100.;	//is necessary to find cfd amplitude value closest to zero
138 139 140 141 142 143

	fGraphCFD->Set(fNPoints);

	//working variables
	Double_t maxCFD = 0., minCFD = 0.;
	Int_t imax = 0, imin = 0;
144 145 146

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

147 148 149 150 151
		//CFD method
		if(i>fCFtimeDelay) {
			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 157
			maxCFD = fAmpCFD[i];
			imax = i;
158 159
		}

160
		//point for min CFD amplitude
161
		if(fAmpCFD[i] < minCFD) {
162 163
			minCFD = fAmpCFD[i];
			imin = i;
164 165 166 167 168 169
		}

	}

	//finding "zero" of CFD amplitude
	for(Int_t j = imin; j < imax; j++) {   
170 171 172 173
		if(abs(fAmpCFD[j]) < level) {
			level = abs(fAmpCFD[j]);
			fCFD = fTime[j];
		}
174
	}
Muzalevsky I.A's avatar
Muzalevsky I.A committed
175
}
176

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
Double_t AEvent::FindZeroLevel(Int_t pmin, Int_t pmax) {

//	fGraphZero->Set(fNPoints);
//	const Double_t *amp = fInputEvent->GetAmp();
//	const Double_t *time = fInputEvent->GetTime();
	SetGraphs();
	Double_t correction = 0;
	TF1 *fit1 = new TF1("fit1","[0]");
	fit1->SetRange(pmin,pmax);

//	Warning("AEvent::FindZeroLevel", "Graph was not set");
	if (!fGraphSignal) {
		Warning("AEvent::FindZeroLevel", "Graph was not set");
		return 0;
	}
//	fGraphSignal->Print();
	fGraphSignal->Fit(fit1,"RQN","goff");
//	fGraphSignal->Fit(fit1,"QR","goff");
	correction = fit1->GetParameter(0);
//	printf("zero level %f\n", correction);
	delete fit1;
	return correction;
199

Muzalevsky I.A's avatar
Muzalevsky I.A committed
200 201 202 203 204 205 206
Double_t AEvent::GetfCFD() {
		return fCFD;
}

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

Muzalevsky I.A's avatar
Muzalevsky I.A committed
208 209
Double_t AEvent::GetOnefAmpPos(Int_t i) {
		return fAmpPos[i];
210
}