/* * 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]; } // 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; } 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(); 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.; fCFD = 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.; } 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]); fCFD = fTime[j]; } } } 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; }