00001 #include "PrePulse.h"
00002 #include "TPulseIsland.h"
00003
00004 #include <cmath>
00005 #include <vector>
00006 #include <iostream>
00007
00008 PrePulse::PrePulse(int start, int stop, int loc, int height, TPulseIsland* pulse) :
00009 fStart(start), fStop(stop), fLocation(loc), fHeight(height), fPulse(pulse) {}
00010
00011 PrePulse::~PrePulse() {}
00012
00013 int PrePulse::GetStart() const {
00014 return fStart;
00015 }
00016
00017 int PrePulse::GetStop() const {
00018 return fStop;
00019 }
00020
00021 int PrePulse::GetLocation() const {
00022 return fLocation;
00023 }
00024
00025 int PrePulse::GetHeight() const {
00026 return fHeight;
00027 }
00028
00029 TPulseIsland* PrePulse::GetPulse() const {
00030 return fPulse;
00031 }
00032
00033 void PrePulse::Print() {
00034 std::cout << "PrePulse Information:"
00035 << "\t" << "Strt" << "\t" << "Stop"
00036 << "\t" << "Loc" << "\t" << "Hght"
00037 << std::endl;
00038 std::cout << " "
00039 << "\t" << fStart << "\t" << fStop
00040 << "\t" << fLocation << "\t" << fHeight
00041 << std::endl;
00042 }
00043
00044 std::vector<PrePulse> PrePulse::FindPrePulses(TPulseIsland* pulse, int rise, int fall) {
00045
00046
00047 std::vector<int> samples = pulse->GetSamples();
00048 unsigned int nsamps = samples.size();
00049 int pPed = pulse->GetPedestal(0);
00050 int pPol = pulse->GetTriggerPolarity();
00051 std::vector<PrePulse> prepulses;
00052
00053 int s1, s2, ds;
00054 int start, stop, loc, height;
00055 bool found = false;
00056 for (unsigned int i = 1; i < nsamps; ++i) {
00057 s1 = pPol * (samples[i-1] - pPed);
00058 s2 = pPol * (samples[i] - pPed);
00059 ds = s2 - s1;
00060 if (found) {
00061 if (-ds > fall) {
00062 stop = (int)i;
00063 prepulses.push_back(PrePulse(start, stop, loc, height, pulse));
00064 start = stop = loc = height = 0;
00065 found = false;
00066 }
00067 if (s2 > height) {
00068 loc = (int)i;
00069 height = s2;
00070 }
00071 } else {
00072 if (ds > rise) {
00073 found = true;
00074 start = (int)(i - 1);
00075 loc = start + 1;
00076 height = s2;
00077 }
00078 }
00079 }
00080
00081 return prepulses;
00082 }