// CheckChiSquare.cpp #include "CheckChiSquare.h" #include #include #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include "trfutil/trfstream.h" #include "trffit/MTrack.h" #include "trfcut/CutRecorder.hpp" using std::cout; using std::endl; using std::string; using trf::CheckChiSquare; using trf::CutRecord; using trf::CutRecorder; using trf::MTrack; //********************************************************************** // Free functions. //********************************************************************** namespace { // Creator. ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "CheckChiSquare" ); double max_chisq = data.get_double("max_chisq"); string cut_name; if(data.has("cut_name")) cut_name = data.get_string("cut_name"); CheckChiSquare* pobj = new CheckChiSquare(max_chisq, cut_name); if ( data.has("debug") ) { bool flag = data.get_bool("debug"); pobj->set_debug(flag); } return ObjPtr(pobj); } } //********************************************************************** // Member functions. //********************************************************************** // Output stream. void CheckChiSquare::ostr(ostream& stream) const { stream << begin_object; stream << "Check chi-square <= " << _max_chisq; stream << end_object; } //********************************************************************** // Constructor. CheckChiSquare::CheckChiSquare(double max_chisq, const string& cut_name) : _max_chisq(max_chisq) { CutRecorder* p = CutRecorder::instance(); assert(p != 0); _cut_id = p->get_cutid(cut_name); } //********************************************************************** // Return the creator. ObjCreator CheckChiSquare::get_creator() { return create; } //********************************************************************** // Write the object data. ObjData CheckChiSquare::write_data() const { ObjData data( get_type_name() ); data.add_double( "max_chisq", get_max_chisq() ); return data; } //********************************************************************** // return track status. bool CheckChiSquare::status_with_record(const MTrack& trm, CutRecord* prec) const { if ( get_debug() ) { string disposition = "fail"; if ( trm.get_chi_square() <= _max_chisq ) { disposition = "pass"; } cout << "CheckChiSquare: found/max = " << trm.get_chi_square() << "/" << _max_chisq << " -- " << disposition; cout << endl; } // Cut double chisq = trm.get_chi_square(); bool passed = chisq <= _max_chisq; // Report the result. make_report(*this, passed?"pass":"fail", chisq); // Fill cut record. if(prec && _cut_id.is_valid()) { prec->add_cut(_cut_id, chisq); prec->set_passed(passed && prec->passed()); } return passed; } //**********************************************************************