AEvent.cpp 2.92 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 25
AEvent::~AEvent() {
	// TODO Auto-generated destructor stub
	delete gSignal;
26
	delete gCFD;
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 58 59 60 61
		fAmpPos[j] = amp[j]*(-1.);
		fTime[j] = time[j];
	}

	Double_t maxAmp = 0.;
	Double_t maxAmpT = 0.;

	maxAmp = fAmpPos[0];
62
	for(Int_t j=0; j < fNPoints; j++) {
63 64 65 66 67 68 69 70
		if(fAmpPos[j] > maxAmp) {
			maxAmp = fAmpPos[j];
			maxAmpT = fTime[j];
		}
	}
	fAmpMax = maxAmp;
	fTimeAmpMax = maxAmpT;

71 72 73 74
	SetGraphs();

	SetCFD();

75 76 77 78 79 80
	return;

}

void AEvent::Reset() {

81
	for (Int_t i = 0; i < fNPoints; i++) {
82 83
		fAmpPos[i] = 0;
		fTime[i] = 0;
84
		fAmpCFD[i] = 0;
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
	}

	fAmpMax = 0.;
	fTimeAmpMax = 0.;
}

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

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

}

void AEvent::Init() {

102 103 104 105
	fAmpPos.Set(fNPoints);
	fTime.Set(fNPoints);
	fAmpCFD.Set(fNPoints);

106
	gSignal = new TGraph();
107
	gCFD = new TGraph();
108 109 110 111 112 113 114 115 116 117 118 119 120 121
	fInputEvent = 0;

}

void AEvent::SetGraphs() {

	gSignal->Set(fNPoints);

	for (Int_t i=0; i<fNPoints; i++) {
		gSignal->SetPoint(i, fTime[i], fAmpPos[i]);
	}

	return;
}
122

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
void AEvent::SetCFD(/*Double_t c, Int_t td*/) {

	gCFD->Set(fNPoints);
	Double_t c = 0.5; //attenuation coefficient
	Int_t td = 5;	//time of delay in points
	Double_t maxCFD, minCFD, imax, imin, tmax, tmin, level;
	maxCFD = 0.;
	minCFD = 0.;
	level = 100.;
	for (Int_t i=0; i<fNPoints; i++) {

	//CFD method
		if(i>td) {
			fAmpCFD[i] = fAmpPos[i]*c*(-1);
			fAmpCFD[i] = fAmpCFD[i] + fAmpPos[i - td];
			gCFD->SetPoint(i, fTime[i], fAmpCFD[i]);
		}

	//point for max CFD amplitude	
		if(fAmpCFD[i] > maxCFD) {
				maxCFD = fAmpCFD[i];
				imax = i;
				tmax = fTime[i];
		}

	//point for min CFD amplitude	
		if(fAmpCFD[i] < minCFD) {
				minCFD = fAmpCFD[i];
				imin = i;
				tmin = fTime[i];	
		}

	}

	//finding "zero" of CFD amplitude
	for(Int_t j = imin; j < imax; j++) {   
		if(abs(fAmpCFD[j]) < level) {level = abs(fAmpCFD[j]); fCFD = fTime[j];}	
	}

	return;


165
}