/******************************************************************************/ /* */ /* EVENTCRITERIA.HH */ /* */ /******************************************************************************/ // Shourov K. Chatterji // shourov@ligo.mit.edu // 2004-Sep-27 /* Protect against double inclusion */ /* -------------------------------- */ #ifndef EVENTCRITERIA_HH #define EVENTCRITERIA_HH /* Include header files */ /* -------------------- */ #include #include #include "event.hh" #include "segment.hh" /* Begin namespace event */ /* --------------------- */ namespace event { /* Event Sort Criteria */ /* ------------------- */ // base class for event sort criteria struct EventSortCriterion : public std::binary_function { EventSortCriterion() {} virtual ~EventSortCriterion() {} virtual bool operator()(const Event& event1, const Event& event2) = 0; }; // sort events by increasing center time struct IncreasingEventCenterTimeSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getCenterTime() < event2.getCenterTime(); } }; // sort events by decreasing center time struct DecreasingEventCenterTimeSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getCenterTime() > event2.getCenterTime(); } }; // sort events by increasing center frequency struct IncreasingEventCenterFrequencySortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getCenterFrequency() < event2.getCenterFrequency(); } }; // sort events by decreasing center frequency struct DecreasingEventCenterFrequencySortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getCenterFrequency() > event2.getCenterFrequency(); } }; // sort events by increasing duration struct IncreasingEventDurationSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getDuration() < event2.getDuration(); } }; // sort events by decreasing duration struct DecreasingEventDurationSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getDuration() > event2.getDuration(); } }; // sort events by increasing bandwidth struct IncreasingEventBandwidthSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getBandwidth() < event2.getBandwidth(); } }; // sort events by decreasing bandwidth struct DecreasingEventBandwidthSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getBandwidth() > event2.getBandwidth(); } }; // sort events by increasing normalized energy struct IncreasingEventNormalizedEnergySortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getNormalizedEnergy() < event2.getNormalizedEnergy(); } }; // sort events by decreasing normalized energy struct DecreasingEventNormalizedEnergySortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getNormalizedEnergy() > event2.getNormalizedEnergy(); } }; // sort events by increasing start time struct IncreasingEventStartTimeSortCriterion : public EventSortCriterion { IncreasingEventStartTimeSortCriterion(double durationInflation = 1.0) : durationInflation(durationInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getStartTime(durationInflation) < event2.getStartTime(durationInflation); } double durationInflation; }; // sort events by decreasing start time struct DecreasingEventStartTimeSortCriterion : public EventSortCriterion { DecreasingEventStartTimeSortCriterion(double durationInflation = 1.0) : durationInflation(durationInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getStartTime(durationInflation) > event2.getStartTime(durationInflation); } double durationInflation; }; // sort events by increasing stop time struct IncreasingEventStopTimeSortCriterion : public EventSortCriterion { IncreasingEventStopTimeSortCriterion(double durationInflation = 1.0) : durationInflation(durationInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getStopTime(durationInflation) < event2.getStopTime(durationInflation); } double durationInflation; }; // sort events by decreasing stop time struct DecreasingEventStopTimeSortCriterion : public EventSortCriterion { DecreasingEventStopTimeSortCriterion(double durationInflation = 1.0) : durationInflation(durationInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getStopTime(durationInflation) > event2.getStopTime(durationInflation); } double durationInflation; }; // sort events by increasing low frequency struct IncreasingEventLowFrequencySortCriterion : public EventSortCriterion { IncreasingEventLowFrequencySortCriterion(double bandwidthInflation = 1.0) : bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getLowFrequency(bandwidthInflation) < event2.getLowFrequency(bandwidthInflation); } double bandwidthInflation; }; // sort events by decreasing low frequency struct DecreasingEventLowFrequencySortCriterion : public EventSortCriterion { DecreasingEventLowFrequencySortCriterion(double bandwidthInflation = 1.0) : bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getLowFrequency(bandwidthInflation) > event2.getLowFrequency(bandwidthInflation); } double bandwidthInflation; }; // sort events by increasing high frequency struct IncreasingEventHighFrequencySortCriterion : public EventSortCriterion { IncreasingEventHighFrequencySortCriterion(double bandwidthInflation = 1.0) : bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getHighFrequency(bandwidthInflation) < event2.getHighFrequency(bandwidthInflation); } double bandwidthInflation; }; // sort events by decreasing high frequency struct DecreasingEventHighFrequencySortCriterion : public EventSortCriterion { DecreasingEventHighFrequencySortCriterion(double bandwidthInflation = 1.0) : bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event1, const Event& event2) { return event1.getHighFrequency(bandwidthInflation) > event2.getHighFrequency(bandwidthInflation); } double bandwidthInflation; }; // sort events by increasing quality factor struct IncreasingEventQualityFactorSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getQualityFactor() < event2.getQualityFactor(); } }; // sort events by decreasing quality factor struct DecreasingEventQualityFactorSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getQualityFactor() > event2.getQualityFactor(); } }; // sort events by increasing time frequency area struct IncreasingEventTimeFrequencyAreaSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getTimeFrequencyArea() < event2.getTimeFrequencyArea(); } }; // sort events by decreasing time frequency area struct DecreasingEventTimeFrequencyAreaSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getTimeFrequencyArea() > event2.getTimeFrequencyArea(); } }; // sort events by increasing signal to noise ratio struct IncreasingEventSignalToNoiseRatioSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getSignalToNoiseRatio() < event2.getSignalToNoiseRatio(); } }; // sort events by decreasing signal to noise ratio struct DecreasingEventSignalToNoiseRatioSortCriterion : public EventSortCriterion { bool operator()(const Event& event1, const Event& event2) { return event1.getSignalToNoiseRatio() > event2.getSignalToNoiseRatio(); } }; // sort events by increasing negative log significance struct IncreasingEventLogSignificanceSortCriterion : public EventSortCriterion { IncreasingEventLogSignificanceSortCriterion(double precision = 0.001) : precision(precision) {} bool operator()(const Event& event1, const Event& event2) { return event1.getLogSignificance(precision) < event2.getLogSignificance(precision); } double precision; }; // sort events by decreasing negative log significance struct DecreasingEventLogSignificanceSortCriterion : public EventSortCriterion { DecreasingEventLogSignificanceSortCriterion(double precision = 0.001) : precision(precision) {} bool operator()(const Event& event1, const Event& event2) { return event1.getLogSignificance(precision) > event2.getLogSignificance(precision); } double precision; }; /* Event Cut Criteria */ /* ------------------ */ // base class for event cut criteria struct EventCutCriterion : public std::unary_function { EventCutCriterion() {} virtual ~EventCutCriterion() {} virtual bool operator()(const Event& event) = 0; }; // cut events with center time less than threshold struct EventCenterTimeLessThanCutCriterion : public EventCutCriterion { EventCenterTimeLessThanCutCriterion(double threshold) : threshold(threshold) {} bool operator()(const Event& event) { return event.getCenterTime() < threshold; } double threshold; }; // cut events with center time greater than threshold struct EventCenterTimeGreaterThanCutCriterion : public EventCutCriterion { EventCenterTimeGreaterThanCutCriterion(double threshold) : threshold(threshold) {} bool operator()(const Event& event) { return event.getCenterTime() >= threshold; } double threshold; }; // cut events with center frequency less than threshold struct EventCenterFrequencyLessThanCutCriterion : public EventCutCriterion { EventCenterFrequencyLessThanCutCriterion(double threshold) : threshold(threshold) {} bool operator()(const Event& event) { return event.getCenterFrequency() < threshold; } double threshold; }; // cut events with center frequency greater than threshold struct EventCenterFrequencyGreaterThanCutCriterion : public EventCutCriterion { EventCenterFrequencyGreaterThanCutCriterion(double threshold) : threshold(threshold) {} bool operator()(const Event& event) { return event.getCenterFrequency() >= threshold; } double threshold; }; // cut events with duration less than threshold struct EventDurationLessThanCutCriterion : public EventCutCriterion { EventDurationLessThanCutCriterion(double threshold, double durationInflation = 1.0) : threshold(threshold), durationInflation(durationInflation) {} bool operator()(const Event& event) { return event.getDuration(durationInflation) < threshold; } double threshold; double durationInflation; }; // cut events with duration greater than threshold struct EventDurationGreaterThanCutCriterion : public EventCutCriterion { EventDurationGreaterThanCutCriterion(double threshold, double durationInflation = 1.0) : threshold(threshold), durationInflation(durationInflation) {} bool operator()(const Event& event) { return event.getDuration(durationInflation) >= threshold; } double threshold; double durationInflation; }; // cut events with bandwidth less than threshold struct EventBandwidthLessThanCutCriterion : public EventCutCriterion { EventBandwidthLessThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getBandwidth(bandwidthInflation) < threshold; } double threshold; double bandwidthInflation; }; // cut events with bandwidth greater than threshold struct EventBandwidthGreaterThanCutCriterion : public EventCutCriterion { EventBandwidthGreaterThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getBandwidth(bandwidthInflation) >= threshold; } double threshold; double bandwidthInflation; }; // cut events with normalized energy less than threshold struct EventNormalizedEnergyLessThanCutCriterion : public EventCutCriterion { EventNormalizedEnergyLessThanCutCriterion(double threshold, double uncertaintyFactor = 0.0) : threshold(threshold), uncertaintyFactor(uncertaintyFactor) {} bool operator()(const Event& event) { return event.getNormalizedEnergy() < threshold + uncertaintyFactor * event.getIncoherentEnergy(); } double threshold; double uncertaintyFactor; }; // cut events with normalized energy greater than threshold struct EventNormalizedEnergyGreaterThanCutCriterion : public EventCutCriterion { EventNormalizedEnergyGreaterThanCutCriterion(double threshold, double uncertaintyFactor = 0.0) : threshold(threshold), uncertaintyFactor(uncertaintyFactor) {} bool operator()(const Event& event) { return event.getNormalizedEnergy() >= threshold + uncertaintyFactor * event.getIncoherentEnergy(); } double threshold; double uncertaintyFactor; }; // cut events with start time less than threshold struct EventStartTimeLessThanCutCriterion : public EventCutCriterion { EventStartTimeLessThanCutCriterion(double threshold, double durationInflation = 1.0) : threshold(threshold), durationInflation(durationInflation) {} bool operator()(const Event& event) { return event.getStartTime(durationInflation) < threshold; } double threshold; double durationInflation; }; // cut events with start time greater than threshold struct EventStartTimeGreaterThanCutCriterion : public EventCutCriterion { EventStartTimeGreaterThanCutCriterion(double threshold, double durationInflation = 1.0) : threshold(threshold), durationInflation(durationInflation) {} bool operator()(const Event& event) { return event.getStartTime(durationInflation) >= threshold; } double threshold; double durationInflation; }; // cut events with stop time less than threshold struct EventStopTimeLessThanCutCriterion : public EventCutCriterion { EventStopTimeLessThanCutCriterion(double threshold, double durationInflation = 1.0) : threshold(threshold), durationInflation(durationInflation) {} bool operator()(const Event& event) { return event.getStopTime(durationInflation) < threshold; } double threshold; double durationInflation; }; // cut events with stop time greater than threshold struct EventStopTimeGreaterThanCutCriterion : public EventCutCriterion { EventStopTimeGreaterThanCutCriterion(double threshold, double durationInflation = 1.0) : threshold(threshold), durationInflation(durationInflation) {} bool operator()(const Event& event) { return event.getStopTime(durationInflation) >= threshold; } double threshold; double durationInflation; }; // cut events with low frequency less than threshold struct EventLowFrequencyLessThanCutCriterion : public EventCutCriterion { EventLowFrequencyLessThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getLowFrequency(bandwidthInflation) < threshold; } double threshold; double bandwidthInflation; }; // cut events with low frequency greater than threshold struct EventLowFrequencyGreaterThanCutCriterion : public EventCutCriterion { EventLowFrequencyGreaterThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getLowFrequency(bandwidthInflation) >= threshold; } double threshold; double bandwidthInflation; }; // cut events with high frequency less than threshold struct EventHighFrequencyLessThanCutCriterion : public EventCutCriterion { EventHighFrequencyLessThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold) {} bool operator()(const Event& event) { return event.getHighFrequency(bandwidthInflation) < threshold; } double threshold; double bandwidthInflation; }; // cut events with high frequency greater than threshold struct EventHighFrequencyGreaterThanCutCriterion : public EventCutCriterion { EventHighFrequencyGreaterThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getHighFrequency(bandwidthInflation) >= threshold; } double threshold; double bandwidthInflation; }; // cut events with quality factor less than threshold struct EventQualityFactorLessThanCutCriterion : public EventCutCriterion { EventQualityFactorLessThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold) {} bool operator()(const Event& event) { return event.getQualityFactor(bandwidthInflation) < threshold; } double threshold; double bandwidthInflation; }; // cut events with quality factor greater than threshold struct EventQualityFactorGreaterThanCutCriterion : public EventCutCriterion { EventQualityFactorGreaterThanCutCriterion(double threshold, double bandwidthInflation = 1.0) : threshold(threshold), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getQualityFactor(bandwidthInflation) >= threshold; } double threshold; double bandwidthInflation; }; // cut events with time-frequency area less than threshold struct EventTimeFrequencyAreaLessThanCutCriterion : public EventCutCriterion { EventTimeFrequencyAreaLessThanCutCriterion(double threshold, double durationInflation = 1.0, double bandwidthInflation = 1.0) : threshold(threshold), durationInflation(durationInflation), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getTimeFrequencyArea(durationInflation, bandwidthInflation) < threshold; } double threshold; double durationInflation; double bandwidthInflation; }; // cut events with time-frequency area greater than threshold struct EventTimeFrequencyAreaGreaterThanCutCriterion : public EventCutCriterion { EventTimeFrequencyAreaGreaterThanCutCriterion(double threshold, double durationInflation = 1.0, double bandwidthInflation = 1.0) : threshold(threshold), durationInflation(durationInflation), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return event.getTimeFrequencyArea(durationInflation, bandwidthInflation) >= threshold; } double threshold; double durationInflation; double bandwidthInflation; }; // cut events with signal to noise ratio less than threshold struct EventSignalToNoiseRatioLessThanCutCriterion : public EventCutCriterion { EventSignalToNoiseRatioLessThanCutCriterion(double threshold) : threshold(threshold) {} bool operator()(const Event& event) { return event.getSignalToNoiseRatio() < threshold; } double threshold; }; // cut events with signal to noise ratio greater than threshold struct EventSignalToNoiseRatioGreaterThanCutCriterion : public EventCutCriterion { EventSignalToNoiseRatioGreaterThanCutCriterion(double threshold) : threshold(threshold) {} bool operator()(const Event& event) { return event.getSignalToNoiseRatio() >= threshold; } double threshold; }; // cut events with log significance less than threshold struct EventLogSignificanceLessThanCutCriterion : public EventCutCriterion { EventLogSignificanceLessThanCutCriterion(double threshold, double precision = 0.001) : threshold(threshold), precision(precision) {} bool operator()(const Event& event) { return event.getLogSignificance(precision) < threshold; } double threshold; double precision; }; // cut events with log significance greater than threshold struct EventLogSignificanceGreaterThanCutCriterion : public EventCutCriterion { EventLogSignificanceGreaterThanCutCriterion(double threshold, double precision = 0.001) : threshold(threshold), precision(precision) {} bool operator()(const Event& event) { return event.getLogSignificance(precision) >= threshold; } double threshold; double precision; }; // cut events with center time inside a specified time segment struct EventCenterTimeInsideSegmentCutCriterion : public EventCutCriterion { EventCenterTimeInsideSegmentCutCriterion(double startTime, double stopTime) : startTime(startTime), stopTime(stopTime) {} bool operator()(const Event& event) { return (event.getCenterTime() >= startTime) && (event.getCenterTime() < stopTime); } double startTime; double stopTime; }; // cut events with center time outside a specified time segment struct EventCenterTimeOutsideSegmentCutCriterion : public EventCutCriterion { EventCenterTimeOutsideSegmentCutCriterion(double startTime, double stopTime) : startTime(startTime), stopTime(stopTime) {} bool operator()(const Event& event) { return (event.getCenterTime() < startTime) || (event.getCenterTime() >= stopTime); } double startTime; double stopTime; }; // cut events which are fully inside the specified time segment struct EventInsideSegmentCutCriterion : public EventCutCriterion { EventInsideSegmentCutCriterion(double startTime, double stopTime, double durationInflation = 1.0) : startTime(startTime), stopTime(stopTime), durationInflation(durationInflation) {} bool operator()(const Event& event) { return (event.getStartTime(durationInflation) >= startTime) && (event.getStopTime(durationInflation) < stopTime); } double startTime; double stopTime; double durationInflation; }; // cut events which aren't fully inside the specified time segment struct EventNotInsideSegmentCutCriterion : public EventCutCriterion { EventNotInsideSegmentCutCriterion(double startTime, double stopTime, double durationInflation = 1.0) : startTime(startTime), stopTime(stopTime), durationInflation(durationInflation) {} bool operator()(const Event& event) { return (event.getStartTime(durationInflation) < startTime) || (event.getStopTime(durationInflation) >= stopTime); } double startTime; double stopTime; double durationInflation; }; // cut events which are fully outside the specified time segment struct EventOutsideSegmentCutCriterion : public EventCutCriterion { EventOutsideSegmentCutCriterion(double startTime, double stopTime, double durationInflation = 1.0) : startTime(startTime), stopTime(stopTime), durationInflation(durationInflation) {} bool operator()(const Event& event) { return (event.getStopTime(durationInflation) < startTime) || (event.getStartTime(durationInflation) >= stopTime); } double startTime; double stopTime; double durationInflation; }; // cut events which aren't fully outside the specified time segment struct EventNotOutsideSegmentCutCriterion : public EventCutCriterion { EventNotOutsideSegmentCutCriterion(double startTime, double stopTime, double durationInflation = 1.0) : startTime(startTime), stopTime(stopTime), durationInflation(durationInflation) {} bool operator()(const Event& event) { return (event.getStopTime(durationInflation) >= startTime) && (event.getStartTime(durationInflation) < stopTime); } double startTime; double stopTime; double durationInflation; }; // cut events with center frequency inside a specified frequency band struct EventCenterFrequencyInsideBandCutCriterion : public EventCutCriterion { EventCenterFrequencyInsideBandCutCriterion(double lowFrequency, double highFrequency) : lowFrequency(lowFrequency), highFrequency(highFrequency) {} bool operator()(const Event& event) { return (event.getCenterFrequency() >= lowFrequency) && (event.getCenterFrequency() < highFrequency); } double lowFrequency; double highFrequency; }; // cut events with center frequency outside a specified frequency band struct EventCenterFrequencyOutsideBandCutCriterion : public EventCutCriterion { EventCenterFrequencyOutsideBandCutCriterion(double lowFrequency, double highFrequency) : lowFrequency(lowFrequency), highFrequency(highFrequency) {} bool operator()(const Event& event) { return (event.getCenterFrequency() < lowFrequency) || (event.getCenterFrequency() >= highFrequency); } double lowFrequency; double highFrequency; }; // cut events which are fully inside the specified frequency band struct EventInsideBandCutCriterion : public EventCutCriterion { EventInsideBandCutCriterion(double lowFrequency, double highFrequency, double bandwidthInflation = 1.0) : lowFrequency(lowFrequency), highFrequency(highFrequency), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return (event.getLowFrequency(bandwidthInflation) >= lowFrequency) && (event.getHighFrequency(bandwidthInflation) < highFrequency); } double lowFrequency; double highFrequency; double bandwidthInflation; }; // cut events which aren't fully inside the specified frequency band struct EventNotInsideBandCutCriterion : public EventCutCriterion { EventNotInsideBandCutCriterion(double lowFrequency, double highFrequency, double bandwidthInflation = 1.0) : lowFrequency(lowFrequency), highFrequency(highFrequency), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return (event.getLowFrequency(bandwidthInflation) < lowFrequency) || (event.getHighFrequency(bandwidthInflation) >= highFrequency); } double lowFrequency; double highFrequency; double bandwidthInflation; }; // cut events which are fully outside the specified frequency band struct EventOutsideBandCutCriterion : public EventCutCriterion { EventOutsideBandCutCriterion(double lowFrequency, double highFrequency, double bandwidthInflation = 1.0) : lowFrequency(lowFrequency), highFrequency(highFrequency), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return (event.getHighFrequency(bandwidthInflation) < lowFrequency) || (event.getLowFrequency(bandwidthInflation) >= highFrequency); } double lowFrequency; double highFrequency; double bandwidthInflation; }; // cut events which aren't fully outside the specified frequency band struct EventNotOutsideBandCutCriterion : public EventCutCriterion { EventNotOutsideBandCutCriterion(double lowFrequency, double highFrequency, double bandwidthInflation = 1.0) : lowFrequency(lowFrequency), highFrequency(highFrequency), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event) { return (event.getHighFrequency(bandwidthInflation) >= lowFrequency) && (event.getLowFrequency(bandwidthInflation) < highFrequency); } double lowFrequency; double highFrequency; double bandwidthInflation; }; /* Event Coincidence Criteria */ /* -------------------------- */ // base class for event coincidence criteria struct EventCoincidenceCriterion : public std::binary_function { EventCoincidenceCriterion() {} virtual ~EventCoincidenceCriterion() {} virtual bool operator()(const Event& event1, const Event& event2) = 0; }; // generic test for time-frequency coincidence between two events struct EventTimeFrequencyCoincidenceCriterion : public EventCoincidenceCriterion { EventTimeFrequencyCoincidenceCriterion(double coincidenceWindowDuration, double coincidenceWindowBandwidth, double durationInflation, double bandwidthInflation) : coincidenceWindowDuration(coincidenceWindowDuration), coincidenceWindowBandwidth(coincidenceWindowBandwidth), durationInflation(durationInflation), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event1, const Event& event2) { if (coincidenceWindowDuration != ignore) { if ((event1.getStartTime(durationInflation) - event2.getStopTime(durationInflation) > coincidenceWindowDuration) || (event2.getStartTime(durationInflation) - event1.getStopTime(durationInflation) > coincidenceWindowDuration)) { return false; } } if (coincidenceWindowBandwidth != ignore) { if ((event1.getLowFrequency(bandwidthInflation) - event2.getHighFrequency(bandwidthInflation) > coincidenceWindowBandwidth) || (event2.getLowFrequency(bandwidthInflation) - event1.getHighFrequency(bandwidthInflation) > coincidenceWindowBandwidth)) { return false; } } return true; } double coincidenceWindowDuration; double coincidenceWindowBandwidth; double durationInflation; double bandwidthInflation; }; // overlap test for time only coincidence between events struct EventTimeOverlapCriterion : public EventTimeFrequencyCoincidenceCriterion { EventTimeOverlapCriterion(double durationInflation = 1.0) : EventTimeFrequencyCoincidenceCriterion(0.0, ignore, durationInflation, 0.0) {} }; // overlap test for time-frequency coincidence between events struct EventTimeFrequencyOverlapCriterion : public EventTimeFrequencyCoincidenceCriterion { EventTimeFrequencyOverlapCriterion(double durationInflation = 1.0, double bandwidthInflation = 1.0) : EventTimeFrequencyCoincidenceCriterion(0.0, 0.0, durationInflation, bandwidthInflation) {} }; // strict test for time only coincidence between events struct EventStrictTimeCoincidenceCriterion : public EventTimeFrequencyCoincidenceCriterion { EventStrictTimeCoincidenceCriterion(double coincidenceWindowDuration) : EventTimeFrequencyCoincidenceCriterion(coincidenceWindowDuration, ignore, 0.0, 0.0) {} }; // loose test for time only coincidence between events struct EventLooseTimeCoincidenceCriterion : public EventTimeFrequencyCoincidenceCriterion { EventLooseTimeCoincidenceCriterion(double coincidenceWindowDuration) : EventTimeFrequencyCoincidenceCriterion(coincidenceWindowDuration, ignore, 1.0, 0.0) {} }; // strict test for time-frequency coincidence between events struct EventStrictTimeFrequencyCoincidenceCriterion : public EventTimeFrequencyCoincidenceCriterion { EventStrictTimeFrequencyCoincidenceCriterion(double coincidenceWindowDuration, double coincidenceWindowBandwidth) : EventTimeFrequencyCoincidenceCriterion(coincidenceWindowDuration, coincidenceWindowBandwidth, 0.0, 0.0) {} }; // loose test for time-frequency coincidence between events struct EventLooseTimeFrequencyCoincidenceCriterion : public EventTimeFrequencyCoincidenceCriterion { EventLooseTimeFrequencyCoincidenceCriterion(double coincidenceWindowDuration, double coincidenceWindowBandwidth) : EventTimeFrequencyCoincidenceCriterion(coincidenceWindowDuration, coincidenceWindowBandwidth, 1.0, 1.0) {} }; // generic test for time-frequency coincidence between two events struct EventAlternateTimeFrequencyCoincidenceCriterion : public EventCoincidenceCriterion { EventAlternateTimeFrequencyCoincidenceCriterion(double coincidenceWindowDuration, double coincidenceWindowBandwidth, double durationInflation, double bandwidthInflation) : coincidenceWindowDuration(coincidenceWindowDuration), coincidenceWindowBandwidth(coincidenceWindowBandwidth), durationInflation(durationInflation), bandwidthInflation(bandwidthInflation) {} bool operator()(const Event& event1, const Event& event2) { if (coincidenceWindowDuration != ignore) { if (std::fabs(event1.getCenterTime() - event2.getCenterTime()) > std::max(event1.getDuration(durationInflation), event2.getDuration(durationInflation)) / 2 + coincidenceWindowDuration) { return false; } } if (coincidenceWindowBandwidth != ignore) { if (std::fabs(event1.getCenterFrequency() - event2.getCenterFrequency()) > std::max(event1.getBandwidth(bandwidthInflation), event2.getBandwidth(bandwidthInflation)) / 2 + coincidenceWindowBandwidth) { return false; } } return true; } double coincidenceWindowDuration; double coincidenceWindowBandwidth; double durationInflation; double bandwidthInflation; }; /* Event and Segment Coincidence Criteria */ /* -------------------------------------- */ // base class for event and segment coincidence criteria struct EventSegmentCoincidenceCriterion : public std::binary_function { EventSegmentCoincidenceCriterion() {} virtual ~EventSegmentCoincidenceCriterion() {} virtual bool operator()(const Event& event, const segment::Segment& segment) = 0; }; // test events for center time inside a specified time segment struct EventCenterInSegmentCoincidenceCriterion : public EventSegmentCoincidenceCriterion { bool operator()(const Event& event, const ::segment::Segment& segment) { return (event.getCenterTime() >= segment.getStartTime()) && (event.getCenterTime() < segment.getStopTime()); } }; // test for events which are fully inside the specified time segment struct EventStrictSegmentCoincidenceCriterion : public EventSegmentCoincidenceCriterion { EventStrictSegmentCoincidenceCriterion(double durationInflation = 1.0) : durationInflation(durationInflation) {} bool operator()(const Event& event, const ::segment::Segment& segment) { return (event.getStartTime(durationInflation) >= segment.getStartTime()) && (event.getStopTime(durationInflation) < segment.getStopTime()); } double durationInflation; }; // test for events which at least overlap the specified time segment struct EventLooseSegmentCoincidenceCriterion : public EventSegmentCoincidenceCriterion { EventLooseSegmentCoincidenceCriterion(double durationInflation = 1.0) : durationInflation(durationInflation) {} bool operator()(const Event& event, const ::segment::Segment& segment) { return (event.getStopTime(durationInflation) >= segment.getStartTime()) && (event.getStartTime(durationInflation) < segment.getStopTime()); } double durationInflation; }; /* End namespace event */ /* ------------------- */ } /* End protection against double inclusion */ /* --------------------------------------- */ #endif