// ClusterFindCyl.cpp #include "ClusterFindCyl.h" #include "ClusterContainerCyl.h" #include "ClusterContainerCylZ.h" #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include "trfutil/trfstream.h" #include "trfutil/TRFMath.h" #include "trfutil/TupleManager.h" #include "trfbase/ETrack.h" #include "HitCylPhi.h" #include "HitCylPhiZ.h" using std::string; using std::ostream; using namespace trf; //********************************************************************** // Free functions. //********************************************************************** namespace { // Creator. ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "ClusterFindCyl" ); Ptr psrf; double radius = data.get_double("radius"); bool stereo = data.get_bool("stereo"); int id = data.get_int("tuple_id"); return ObjPtr( new ClusterFindCyl( radius, stereo, id) ); } } //********************************************************************** // Static atributes. //********************************************************************** // tuple enable flag bool ClusterFindCyl::_ltuple = false; // Assign name for ntuple. char* ClusterFindCyl::_tuple_name = "ClusterFindCyl"; //********************************************************************** // Methods. //********************************************************************** // ouput stream void ClusterFindCyl::ostr(ostream& stream) const { stream << begin_object; stream << "Cluster finder for " << _scy << "." << new_line; stream << "Stereo is " << _stereo << "." << new_line; if ( _ptup ) stream << "Tuple ID is " << _id << new_line; int count = _pclusters->size(); if ( count ) { stream << "Finder has " << count << " cluster"; if ( count > 1 ) stream << "s"; stream << ":"; if(_pclusters_ax) { for (ClusterContainerCyl::const_iterator iclu=_pclusters_ax->begin(); iclu!=_pclusters_ax->end(); ++iclu) { stream << new_line; stream << **iclu; } } else { assert(_pclusters_st != 0); for (ClusterContainerCylZ::const_iterator iclu=_pclusters_st->begin(); iclu!=_pclusters_st->end(); ++iclu) { stream << new_line; stream << **iclu; } } } else { stream << "Finder has no clusters."; } stream << end_object; } //********************************************************************** // constructor ClusterFindCyl::ClusterFindCyl(double radius, bool stereo, int id) : _scy(radius), _stereo(stereo), _ptup(0), _id(id), _pclusters_ax(0), _pclusters_st(0) { if ( tuple_is_enabled() ) define_tuple(); // Make cluster container for all clusters in this doublet, and for // clusters near an ETrack. if(!stereo) { _pclusters_ax = new ClusterContainerCyl; _pclusters = _pclusters_ax; } else { _pclusters_st = new ClusterContainerCylZ; _pclusters = _pclusters_st; } } //********************************************************************** // destructor ClusterFindCyl::~ClusterFindCyl() { delete _pclusters; } //********************************************************************** // Return the creator. ObjCreator ClusterFindCyl::get_creator() { return create; } //********************************************************************** // Write the object data. ObjData ClusterFindCyl::write_data() const { ObjData data( get_type_name() ); data.add_double("radius", get_radius() ); data.add_bool( "stereo", get_stereo() ); data.add_int( "tuple_id", get_tuple_id() ); return data; } //********************************************************************** // add a cluster int ClusterFindCyl::add_cluster(const ClusterPtr& pclu) { // Extract the cluster position depending on type if ( pclu->get_type() == ClusCylPhi::get_static_type() ) { const ClusCylPhi& clu = (const ClusCylPhi&) *pclu; assert( clu.get_surface() == _scy ); // assert( _stereo == 0.0 ); // No longer needed MDH 3/28/01 } else if ( pclu->get_type() == ClusCylPhiZ::get_static_type() ) { const ClusCylPhiZ& clu = (const ClusCylPhiZ&) *pclu; assert( clu.get_surface() == _scy ); // assert( clu.get_stereo() == _stereo ); // No longer needed MDH 3/28/01 } else { assert(false); return 1; } // Store cluster. _pclusters->add_cluster(pclu); return 0; } //********************************************************************** // drop all clusters void ClusterFindCyl::drop_clusters() { _pclusters->drop_clusters(); } //********************************************************************** // Return all clusters. ClusterList ClusterFindCyl::get_clusters() const { return _pclusters->get_clusters(); } //********************************************************************** // Return the clusters near a track. // // Clusters have been ordered by phi or phiz in range (0,2pi). // The nearby subset is returned in the same order. ClusterList ClusterFindCyl::get_clusters(const ETrack& tre) const { return get_cluster_container(tre, 0, 0).get_clusters(); } //********************************************************************** // Return the clusters near a track. // // Clusters have been ordered by phi or phiz in range (0,2pi). // The nearby subset is returned in the same order. const ClusterContainer& ClusterFindCyl:: get_cluster_container(const ETrack& tre, const CutRecord* pcut_record, std::map< ClusterPtr, CutRecord*>* precs) const { // Check the track surface. if ( *tre.get_surface() != _scy ) { assert(false); if ( _ptup ) fill_tuple(1); return *_pclusters; } // Return the clusters. if ( _ptup ) { _ptup->capture("ncluster", int(_pclusters->size()) ); fill_tuple(0); } return *_pclusters; } //********************************************************************** // Define the ntuple. void ClusterFindCyl::define_tuple() { assert( _ptup == 0 ); bool defined = TupleManager::is_tuple(_tuple_name); _ptup = &TupleManager::tuple(_tuple_name); if ( ! defined ) { _ptup->columnDirect("id",-999); _ptup->columnDirect("status",-999); _ptup->columnDirect("ncluster",0); } } //********************************************************************** // Fill the ntuple. void ClusterFindCyl::fill_tuple(int status) const { assert( _ptup != 0 ); _ptup->capture("id",_id); _ptup->capture("status",status); _ptup->storeCapturedData(); _ptup->clearData(); } //**********************************************************************