Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

/*
 *  See header file for a description of this class.
 *
 *  \author G. Cerminara - INFN Torino
 */

#include "DTOccupancyPoint.h"

#include <cmath>

DTOccupancyPoint::DTOccupancyPoint() : theMean(0.), theRMS(0.) {
  debug = false;  // FIXME: to be removed
}

DTOccupancyPoint::DTOccupancyPoint(double mean, double rms) : theMean(mean), theRMS(rms) {
  debug = false;  // FIXME: to be removed
}

DTOccupancyPoint::DTOccupancyPoint(double mean, double rms, DTLayerId layerId)
    : theMean(mean), theRMS(rms), theLayerId(layerId) {
  debug = false;  // FIXME: to be removed
}

DTOccupancyPoint::~DTOccupancyPoint() {}

double DTOccupancyPoint::mean() const { return theMean; }

double DTOccupancyPoint::rms() const { return theRMS; }

double DTOccupancyPoint::distance(const DTOccupancyPoint& anotherPoint) const {
  return sqrt(deltaMean(anotherPoint) * deltaMean(anotherPoint) + deltaRMS(anotherPoint) * deltaRMS(anotherPoint));
}

double DTOccupancyPoint::deltaMean(const DTOccupancyPoint& anotherPoint) const {
  return fabs(mean() - anotherPoint.mean());
}

double DTOccupancyPoint::deltaRMS(const DTOccupancyPoint& anotherPoint) const {
  return fabs(rms() - anotherPoint.rms());
}

bool DTOccupancyPoint::operator==(const DTOccupancyPoint& other) const {
  // FIXME: should add the layer ID? not clear
  if (theMean == other.mean() && theRMS == other.rms() && theLayerId == other.layerId())
    return true;
  return false;
}

bool DTOccupancyPoint::operator!=(const DTOccupancyPoint& other) const {
  if (theMean != other.mean() || theRMS != other.rms() || theLayerId != other.layerId())
    return true;
  return false;
}

bool DTOccupancyPoint::operator<(const DTOccupancyPoint& other) const {
  if (distance(DTOccupancyPoint()) == other.distance(DTOccupancyPoint())) {
    return false;
  }

  if (fabs(distance(DTOccupancyPoint()) - other.distance(DTOccupancyPoint())) < 0.000001) {
    if (layerId().rawId() < other.layerId().rawId()) {
      return true;
    } else {
      return false;
    }
  }

  if (distance(DTOccupancyPoint()) < other.distance(DTOccupancyPoint()))
    return true;
  return false;
}

double computeAverageRMS(const DTOccupancyPoint& onePoint, const DTOccupancyPoint& anotherPoint) {
  double ret = (onePoint.rms() + anotherPoint.rms()) / 2.;
  return ret;
}

double computeMinRMS(const DTOccupancyPoint& onePoint, const DTOccupancyPoint& anotherPoint) {
  double ret = -1;
  if (onePoint.rms() > anotherPoint.rms()) {
    ret = anotherPoint.rms();
  } else {
    ret = onePoint.rms();
  }
  return ret;
}

void DTOccupancyPoint::setLayerId(DTLayerId layerId) { theLayerId = layerId; }

DTLayerId DTOccupancyPoint::layerId() const { return theLayerId; }