TimeOfFlight.cc
00001 #include "TimeOfFlight.hh"
00002 #include "BaselineFinder.hh"
00003 #include "Integrator.hh"
00004 #include <algorithm>
00005 #include <cmath>
00006
00007 TimeOfFlight::TimeOfFlight() : ChannelModule(GetDefaultName(), "finds the number of particles detected in the channel and the arrive time of the earliest particle detected"){
00008 AddDependency<BaselineFinder>();
00009 AddDependency<Integrator>();
00010 RegisterParameter("search_begin_time" , search_begin_time = -0.5, "time in us to start searching for particle signal");
00011 RegisterParameter("search_end_time" , search_end_time = 0.5, "time in us to end searching for particle signal");
00012 RegisterParameter("ref_threshold" , ref_threshold = 2500, "reference trigger threshold");
00013 RegisterParameter("threshold" , threshold = 20, "particle count threshold");
00014 RegisterParameter("ref_ch" , ref_ch = 2, "proton beam timing info channel");
00015 RegisterParameter("constant_fraction", constant_fraction = 0.5, "constant fraction of the maximum for locating the particle arrival time");
00016 }
00017
00018 TimeOfFlight::~TimeOfFlight()
00019 {
00020 Finalize();
00021 }
00022
00023 int TimeOfFlight::Initialize()
00024 {
00025 return 0;
00026 }
00027
00028 int TimeOfFlight::Finalize() { return 0; }
00029
00030 int TimeOfFlight::Process(ChannelData* chdata)
00031 {
00032 TOF& tof = chdata->tof;
00033 int start = chdata->TimeToSample(search_begin_time, true);
00034
00035 if (chdata->channel_id == ref_ch){
00036 const double* ref_wave = chdata->GetWaveform();
00037
00038 while (ref_wave[start] > ref_threshold){
00039 start--;
00040 }
00041
00042 while(ref_wave[start] < ref_threshold && start > 0){
00043 start--;
00044 }
00045 tof.found_pulse = true;
00046 tof.constant_fraction_time = 1/chdata->sample_rate * (ref_threshold - ref_wave[start]) / (ref_wave[start+1] - ref_wave[start]) + chdata->SampleToTime(start);
00047
00048 return 0;
00049 }
00050
00051
00052 std::vector<Spe>& interpolations = chdata->baseline.interpolations;
00053 int ninterpolations = chdata->baseline.ninterpolations;
00054
00055 for (int i=0; i<ninterpolations; i++){
00056 Spe pulse = interpolations[i];
00057 if(pulse.start_time>search_begin_time && pulse.start_time<search_end_time && pulse.amplitude>threshold){
00058 tof.found_pulse = true;
00059 tof.integral = pulse.integral;
00060 tof.start_time = pulse.start_time;
00061 tof.amplitude = pulse.amplitude;
00062 tof.peak_time = pulse.peak_time;
00063 tof.length = pulse.length;
00064 double cf_threshold = constant_fraction * tof.amplitude;
00065 const double* wave = chdata->GetBaselineSubtractedWaveform();
00066 int j=chdata->TimeToSample(tof.peak_time)-1;
00067 while(j>chdata->TimeToSample(tof.start_time) && -wave[j]>cf_threshold){
00068 j--;
00069 }
00070 tof.constant_fraction_time = 1/chdata->sample_rate * (cf_threshold + wave[j]) / (wave[j] - wave[j+1]) + chdata->SampleToTime(j);
00071
00072 return 0;
00073 }
00074 }
00075 return 0;
00076 }