// BSurfCylinder.cpp #include "BSurfCylinder.h" #include #include #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include "trfutil/trfstream.h" #include "trfbase/CrossStat.h" #include "trfbase/ETrack.h" using std::sqrt; using trf::CrossStat; using trf::Surface; using trf::VTrack; using trf::ETrack; using trf::SurfCylinder; using trf::BSurfCylinder; //********************************************************************** // Free functions. //********************************************************************** namespace { // Creator. ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "BSurfCylinder" ); double radius = data.get_double("radius"); double zmin = data.get_double("zmin"); double zmax = data.get_double("zmax"); return ObjPtr( new BSurfCylinder(radius,zmin,zmax) ); } } //********************************************************************** // Member functions. //********************************************************************** // output stream void BSurfCylinder::ostr(ostream& stream) const { stream << begin_object; SurfCylinder::raw_ostr(stream); stream << ", zmin " << _zmin << " and zmax " << _zmax; stream << end_object; } //********************************************************************** // bounded equality bool BSurfCylinder::safe_bound_equal(const Surface& srf) const { BSurfCylinder bcy = (BSurfCylinder&) srf; return SurfCylinder::safe_pure_equal(srf) && _zmin == bcy._zmin && _zmax == bcy._zmax; } //********************************************************************** // constructor BSurfCylinder::BSurfCylinder(double radius, double zmin, double zmax) : SurfCylinder(radius), _zmin(zmin), _zmax(zmax) { assert ( _zmax > _zmin ); } //********************************************************************** // Clone. Surface* BSurfCylinder::new_surface() const { return new BSurfCylinder( get_radius(), _zmin, _zmax ); } //********************************************************************** // Return the creator. ObjCreator BSurfCylinder::get_creator() { return create; } //********************************************************************** // Write the object data. ObjData BSurfCylinder::write_data() const { ObjData data( get_type_name() ); data.add_double( "radius", get_radius() ); data.add_double( "zmin", get_zmin() ); data.add_double( "zmax", get_zmax() ); return data; } //********************************************************************** // Calculate crossing status for VTrack. CrossStat BSurfCylinder::status(const VTrack& trv) const { double prec = CrossStat::get_static_precision(); double dztrk = prec; return status(trv,dztrk); } //********************************************************************** // Calculate crossing status for ETrack. CrossStat BSurfCylinder::status(const ETrack& tre) const { double nsigma = CrossStat::get_static_nsigma(); double prec = CrossStat::get_static_precision(); double dztrk = nsigma*sqrt(tre.get_error()(1,1)) + prec; return status(tre,dztrk); } //********************************************************************** // Calculate crossing status for VTrack plus track z-reach. CrossStat BSurfCylinder::status(const VTrack& trv, double dztrk) const { CrossStat xstat = SurfCylinder::pure_status(trv); // If track is not at surface exit with bounds flags undefined. if ( ! xstat.at() ) return xstat; assert( ! xstat.bounds_checked() ); // Calculate whether z track +/- nsigma is in and/or out of bounds. double ztrk = trv.get_vector()(1); double ztrk1 = ztrk - dztrk; double ztrk2 = ztrk + dztrk; // fully out of bounds if ( ztrk2 < _zmin || ztrk1 > _zmax ) return CrossStat(CrossStat::OUT_OF_BOUNDS); // fully in bounds if ( ztrk1 > _zmin && ztrk2 < _zmax ) return CrossStat(CrossStat::IN_BOUNDS); // must be both return CrossStat(CrossStat::BOTH_BOUNDS); } //**********************************************************************