00001 #include "Integrator.hh" 00002 #include "intarray.hh" 00003 00004 #include "BaselineFinder.hh" 00005 #include "SumChannels.hh" 00006 #include "RootWriter.hh" 00007 #include <algorithm> 00008 #include <cmath> 00009 00010 Integrator::Integrator() : 00011 ChannelModule(GetDefaultName(), 00012 "Numerically integrate each channel's waveform") 00013 { 00014 AddDependency<BaselineFinder>(); 00015 RegisterParameter("threshold" , threshold = 0, 00016 "Assume samples less than threshold away from baseline are zero"); 00017 } 00018 00019 Integrator::~Integrator() 00020 { 00021 Finalize(); 00022 } 00023 00024 int Integrator::Initialize() 00025 { 00026 return 0; 00027 } 00028 00029 int Integrator::Finalize() { return 0; } 00030 00031 int Integrator::Process(ChannelData* chdata) 00032 { 00033 Baseline& baseline = chdata->baseline; 00034 if(!baseline.found_baseline) 00035 return 0; 00036 00037 //get the relevant variables 00038 const double* wave = chdata->GetBaselineSubtractedWaveform(); 00039 00040 const int nsamps = chdata->nsamps; 00041 std::vector<double>& integral = chdata->integral; 00042 integral.resize(nsamps); 00043 00044 //perform the integration 00045 integral[0] = wave[0] ; 00046 for(int samp = 1; samp < nsamps; samp++){ 00047 double onestep = wave[samp] ; 00048 integral[samp] = integral[samp-1] 00049 + ( std::abs(onestep) > threshold ? onestep : 0 ); 00050 } 00051 00052 //find the min/max 00053 chdata->integral_max_index = std::max_element(integral.begin(), 00054 integral.end()) 00055 - integral.begin(); 00056 chdata->integral_min_index = std::min_element(integral.begin(), 00057 integral.end()) 00058 - integral.begin(); 00059 chdata->integral_max = integral[chdata->integral_max_index]; 00060 chdata->integral_min = integral[chdata->integral_min_index]; 00061 chdata->integral_max_time = chdata->SampleToTime(chdata->integral_max_index); 00062 chdata->integral_min_time = chdata->SampleToTime(chdata->integral_min_index); 00063 00064 //baseline interpolation integral 00065 for(int i=0; i<(int)baseline.interpolations.size(); i++){ 00066 Spe* pe = &baseline.interpolations[i]; 00067 pe->integral = integral[chdata->TimeToSample(pe->start_time)]-integral[chdata->TimeToSample(pe->start_time+pe->length)]; 00068 } 00069 return 0; 00070 }