00001 #include "Differentiator.hh" 00002 #include "EventHandler.hh" 00003 #include "V172X_Params.hh" 00004 #include "RootWriter.hh" 00005 #include "ConvertData.hh" 00006 #include "BaselineFinder.hh" 00007 #include "SumChannels.hh" 00008 00009 #include "TMath.h" 00010 #include <vector> 00011 00012 #include "intarray.hh" 00013 00014 Differentiator::Differentiator(): 00015 ChannelModule(GetDefaultName(), 00016 "Numerically differentiate the channel's waveform") 00017 { 00018 AddDependency<ConvertData>(); 00019 AddDependency<BaselineFinder>(); 00020 00021 //Register all the config handler parameters 00022 RegisterParameter("decay_constant", decay_constant = 120.00, 00023 "Decay time constant in microsec of the integrator"); 00024 } 00025 00026 Differentiator::~Differentiator() 00027 { 00028 Finalize(); 00029 } 00030 00031 int Differentiator::Initialize() 00032 { 00033 return 0; 00034 } 00035 00036 int Differentiator::Process(ChannelData* chdata) 00037 { 00038 00039 const Baseline& baseline = chdata->baseline; 00040 if(!baseline.found_baseline) 00041 return 0; 00042 double* wave = chdata->GetWaveform(); 00043 00044 const int& nsamps = chdata->nsamps; 00045 chdata->derivative.resize(nsamps); 00046 00047 std::vector<double>& derivative = chdata->derivative; 00048 double sample_interval = 1./(double)chdata->sample_rate; 00049 derivative[0] = 0; 00050 for(int index = 1; index < nsamps; index++) 00051 { 00052 double prev_value = baseline.mean - wave[index-1]; 00053 double curr_value = baseline.mean - wave[index]; 00054 derivative[index] = (curr_value - 00055 prev_value*TMath::Exp(-sample_interval/decay_constant))*(1 + sample_interval/decay_constant); 00056 } 00057 00058 00059 return 0; 00060 } 00061 00062 int Differentiator::Finalize() 00063 { 00064 return 0; 00065 }