#include #include #include #include #include #include #include #include #include #ifndef __GNUC__ #define __restrict__ #endif namespace RAT { TriggerSum::TriggerSum() { fBaseline = 0.0; fNoiseAmplitude = 0.0; } TriggerSum::~TriggerSum() { deepdelete_vector(fPulse); } static bool cmp(const TriggerPulse * const __restrict__ a, const TriggerPulse * const __restrict__ b) { return a->GetStartTime() < b->GetStartTime(); } double TriggerSum::GetHeight(double time) { //Get height of sum at a particular itme double height = fBaseline+fNoiseAmplitude*CLHEP::RandGauss::shoot(); const unsigned int imax = GetNext(time); for(unsigned int i = 0; i < imax; i++) height += fPulse[i]->GetPulseHeight(time); return height; } double TriggerSum::GetHeightByIndex(int i) { //Get height of sum at position of trigger pulse i double height = fBaseline+fNoiseAmplitude*CLHEP::RandGauss::shoot(); float time = fPulse[i]->GetStartTime(); for (int j=0; j<=i; j++){ height+=fPulse[j]->GetPulseHeight(time); } return height; } int TriggerSum::GetNext(double time) { static GenericTrigPulse * const foo = new GenericTrigPulse(); foo->SetStartTime(time); const int ret = upper_bound(fPulse.begin(), fPulse.end(), foo, cmp) - fPulse.begin(); return ret; } double TriggerSum::GetNextTime(double time) { return fPulse[GetNext(time)]->GetStartTime(); } } // namespace RAT