/* * AEvent.cpp * * Created on: Dec 28, 2016 * Author: daria */ #include "AEvent.h" AEvent::AEvent() : fNPoints(1024) { //fNPoints is number of points in one event, 1024 or 1000 Init(); Reset(); } AEvent::AEvent(const Int_t npoints) : fNPoints(npoints) { Init(); Reset(); } AEvent::~AEvent() { // TODO Auto-generated destructor stub delete fGraphSignal; delete fGraphCFD; delete fInputEvent; } 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 < fNPoints; j++) { fAmpPos[j] = amp[j]*(-1.); fTime[j] = time[j]; } fZeroLevel = FindZeroLevel(); for(Int_t j = 0; j < fNPoints; j++) { fAmpPos[j] = fAmpPos[j] - fZeroLevel; } 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; SetGraphs(); SetCFD(); SetChargeCFD(); return; } void AEvent::Reset() { for (Int_t i = 0; i < fNPoints; i++) { fAmpPos[i] = 0; fTime[i] = 0; fAmpCFD[i] = 0; } fAmpMax = 0.; fTimeAmpMax = 0.; fTimeCFD = 0.; fZeroLevel = 0.; fChargeCFD = 0.; } void AEvent::SetInputEvent(RawEvent** event) { if (event == 0) { Warning("AEvent::SetInputEvent", "Input event was set as 0."); } fInputEvent = *event; } void AEvent::Init() { fAmpPos.Set(fNPoints); fTime.Set(fNPoints); fAmpCFD.Set(fNPoints); fGraphSignal = new TGraph(); fGraphCFD = new TGraph(); fInputEvent = 0; fCFratio = 0.; fCFtimeDelay = 0.; fNoiseRangeMin = 0.; fNoiseRangeMax = 1.; } void AEvent::SetGraphs() { fGraphSignal->Set(fNPoints); for (Int_t i=0; iSetPoint(i, fTime[i], fAmpPos[i]); } return; } void AEvent::SetCFD() { Double_t level = 100.; //is necessary to find cfd amplitude value closest to zero fGraphCFD->Set(fNPoints); //working variables Double_t maxCFD = 0., minCFD = 0.; Int_t imax = 0, imin = 0; for (Int_t i=0; ifCFtimeDelay) { fAmpCFD[i] = fAmpPos[i]*fCFratio*(-1); fAmpCFD[i] = fAmpCFD[i] + fAmpPos[i - fCFtimeDelay]; fGraphCFD->SetPoint(i, fTime[i], fAmpCFD[i]); } //point for max CFD amplitude if(fAmpCFD[i] > maxCFD) { maxCFD = fAmpCFD[i]; imax = i; } //point for min CFD amplitude if(fAmpCFD[i] < minCFD) { minCFD = fAmpCFD[i]; imin = i; } } //finding "zero" of CFD amplitude for(Int_t j = imin; j < imax; j++) { if(abs(fAmpCFD[j]) < level) { level = abs(fAmpCFD[j]); fTimeCFD = fTime[j]; } } } Double_t AEvent::FindZeroLevel() { SetGraphs(); Double_t correction = 0; TF1 *fit1 = new TF1("fit1","[0]"); //function for one parameter fitting in the range of pmin-pmax fit1->SetRange(fNoiseRangeMin,fNoiseRangeMax); if (!fGraphSignal) { Warning("AEvent::FindZeroLevel", "Graph was not set"); return 0; } fGraphSignal->Fit(fit1,"RQN","goff"); correction = fit1->GetParameter(0); delete fit1; return correction; } void AEvent::SetChargeCFD(Int_t tmin, Int_t tmax) { 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); for(Int_t i = 0; i < fNPoints; i++) { if( fTime[i] > (fTimeCFD + tmin) && fTime[i] < (fTimeCFD + tmax) ) { integral = integral + fAmpPos[i]; } } fChargeCFD = integral*time_sig/res; // cout<