/* * 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; } SetMaxAmplitudes(); SetGraphs(); FindFrontProperties(); SetCFD(); SetChargeCFD(); return; } void AEvent::Reset() { for (Int_t i = 0; i < fNPoints; i++) { fAmpPos[i] = 0; fTime[i] = 0; fAmpCFD[i] = 0; } fEdgeSlope=0.; fTime10=0.; fTime90=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]; } } } /////// trying to create method void AEvent::FindFrontProperties() { Int_t NumM = 0.; if (!fGraphSignal) { Warning("AEvent::FindZeroLevel", "Graph was not set"); return; } if(fNPoints == 1000) { NumM = fTimeAmpMax*10.; } //10 = 1000 points / 100 ns if(fNPoints == 1024) { NumM = fTimeAmpMax*5.; } //5 = 1024 points / 204.8 ns for(Int_t i=NumM;i>0;i--) { if( fAmpPos[i]<0.1*fAmpMax ) {fTime10 = fTime[i+1];break;} } for(Int_t i=NumM;i>0;i--) { if( fAmpPos[i]<0.9*fAmpMax ) {fTime90 = fTime[i+1];break;} } TF1 *fit1 = new TF1("fit1","[1]*x+[0]"); //function for one parameter fitting in the range of pmin-pmax fit1->SetRange(fTime10,fTime90); fGraphSignal->Fit(fit1,"RQN","goff"); fEdgeSlope = fit1->GetParameter(1); delete fit1; } //////// 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< maxAmp) { maxAmp = fAmpPos[j]; maxAmpT = fTime[j]; } } fAmpMax = maxAmp; fTimeAmpMax = maxAmpT; }