00001
00002
00003
00004 #include <iomanip>
00005
00006
00007 #include "Event.h"
00008
00009
00010 Lit::Event::Event()
00011 :fVar(),
00012 fTgt(),
00013 fWeight(-1.0),
00014 fType(-1)
00015 {
00016 }
00017
00018
00019 Lit::Event::Event(const VarVec &vvec,
00020 const double weight,
00021 const short type)
00022 :fVar(vvec),
00023 fTgt(),
00024 fWeight(weight),
00025 fType(type)
00026 {
00027 }
00028
00029
00030 Lit::Event::Event(const VarVec &vvec,
00031 const double weight,
00032 const short type,
00033 const VarVec &tvec)
00034 :fVar(vvec),
00035 fTgt(tvec),
00036 fWeight(weight),
00037 fType(type)
00038 {
00039 }
00040
00041
00042 Lit::Event::~Event()
00043 {
00044 }
00045
00046
00047 Lit::VarType Lit::Event::GetVar(const unsigned int i) const
00048 {
00049 assert(i < fVar.size() && "index is out of range");
00050 return fVar[i];
00051 }
00052
00053
00054 Lit::VarType Lit::Event::GetTgt(const unsigned int i) const
00055 {
00056 assert(i < fTgt.size() && "index is out of range");
00057 return fTgt[i];
00058 }
00059
00060
00061 Lit::VarType Lit::Distance(const Event &event1, const Event &event2)
00062 {
00063 const unsigned int size = event1.GetNVar();
00064
00065 if(size != event2.GetNVar())
00066 {
00067 std::cerr << "Distance: two events have different dimensions" << std::endl;
00068 return -1.0;
00069 }
00070
00071 VarType sum = 0.0;
00072 for(unsigned int ivar = 0; ivar != size; ++ivar)
00073 {
00074 sum += Distance(event1.GetVar(ivar), event2.GetVar(ivar));
00075 }
00076
00077 return sum;
00078 }
00079
00080
00081 void Lit::Event::Print(std::ostream& os, const unsigned int w, const unsigned int p) const
00082 {
00083 os << "Event (weight, type) = ("
00084 << std::setw(w) << std::setprecision(p) << fWeight << ", "
00085 << fType << ") ";
00086
00087 for(unsigned int ivar = 0; ivar != GetNVar(); ++ivar)
00088 {
00089 if(ivar == 0)
00090 {
00091 os << "var = (";
00092 }
00093 else
00094 {
00095 os << ", ";
00096 }
00097
00098 os << std::setfill(' ') << std::setw(5) << std::setprecision(3) << GetVar(ivar);
00099 }
00100
00101 if(GetNVar() > 0)
00102 {
00103 os << ")";
00104 }
00105 else
00106 {
00107 os << " no variables";
00108 }
00109
00110 for(unsigned int itgt = 0; itgt != GetNTgt(); ++itgt)
00111 {
00112 if(itgt == 0)
00113 {
00114 os << "tgt = (";
00115 }
00116 else
00117 {
00118 os << ", ";
00119 }
00120
00121 os << std::setfill(' ') << std::setw(5) << std::setprecision(3) << GetTgt(itgt);
00122 }
00123
00124 if(GetNTgt() > 0)
00125 {
00126 os << ")";
00127 }
00128 else
00129 {
00130 os << " no targets";
00131 }
00132 }
00133
00134
00135 std::ostream& Lit::operator<<(std::ostream& os, const Lit::Event& event)
00136 {
00137 event.Print(os);
00138 return os;
00139 }