AEvent.cpp 1.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
/*
 * AEvent.cpp
 *
 *  Created on: Dec 28, 2016
 *      Author: daria
 */

#include "AEvent.h"

AEvent::AEvent() : fNPoints(1024) {
	// TODO Auto-generated constructor stub

	Init();
	Reset();

}

AEvent::~AEvent() {
	// TODO Auto-generated destructor stub
	delete gSignal;
}

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

	for(Int_t j = 0; j < NCELLS; j++) {
		fAmpPos[j] = amp[j]*(-1.);
		fTime[j] = time[j];
	}

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

	maxAmp = fAmpPos[0];
	for(Int_t j=0; j<NCELLS; j++) {
		if(fAmpPos[j] > maxAmp) {
			maxAmp = fAmpPos[j];
			maxAmpT = fTime[j];
		}
	}
	fAmpMax = maxAmp;
	fTimeAmpMax = maxAmpT;

	return;

}

void AEvent::Reset() {

	for (Int_t i = 0; i < NCELLS; i++) {
		fAmpPos[i] = 0;
		fTime[i] = 0;
	}

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

	gSignal = new TGraph();
	fInputEvent = 0;

}

void AEvent::SetGraphs() {

	gSignal->Set(fNPoints);

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

	return;
}