//--------------------------------------------------------------------- // File and Version Information: // $Id: $ // // Description: // energy() returns energy sum of digis in cluster. // where() returns a HepPoint at the centre of the // cluster. // x() returns the x element of this. // y() returns the y element of this. // z() returns the z element of this. // // Software developed for the BaBar Detector at the SLAC B-Factory. // Adapted for the PANDA experiment at GSI // // Author List: // Xiaorong Shi Lawrence Livermore National Lab // Steve Playfer University of Edinburgh // Stephen Gowdy University of Edinburgh // Helmut Marsiske SLAC //--------------------------------------------------------------------- #include #include #include "math.h" #include #include "float.h" #include #include "EmcCluster.h" #include "EmcClusterLiloPos.h" #include "EmcDigi.h" #include "EmcStructure.h" #include "TVector3.h" //---------------- // Constructors -- //---------------- EmcCluster::EmcCluster() : fMemberDigiMap( new EmcDigiPtrDict ), fEnergyValid( false ), fEnergy( 0 ), fWhereValid( false ), fWhere( 0 ), fTheClusLiloPos( 0 ) { } EmcCluster::EmcCluster(int digiList, int localMaxList) : fMemberDigiMap( new EmcDigiPtrDict ), fEnergyValid( false ), fEnergy( 0 ), fWhereValid( false ), fWhere( 0 ), fTheClusLiloPos( 0 ) { fDigiList.reserve(digiList); fLocalMaxList.reserve(localMaxList); } //-------------- // Destructor -- //-------------- EmcCluster::~EmcCluster() { delete fWhere; fMemberDigiMap->clear(); delete fMemberDigiMap; if ( fTheClusLiloPos != 0) delete fTheClusLiloPos; } double EmcCluster::energy() const { if ( ! fEnergyValid ) { double sum=0; std::vector::const_iterator digi_iter; for (digi_iter=fDigiList.begin();digi_iter!=fDigiList.end();++digi_iter) { sum+=(*digi_iter)->GetEnergy(); } fEnergy = sum; fEnergyValid = true; } return fEnergy; } double EmcCluster::theta() const { return where().Theta(); } double EmcCluster::phi() const { return where().Phi(); } double EmcCluster::thetaIndex() const { return 0; } double EmcCluster::phiIndex() const { return 0; } TVector3 EmcCluster::position() const { return this->where(); } TVector3 EmcCluster::where() const { if ( !fWhereValid ) { delete fWhere; fWhere = new TVector3( algWhere( this ) ); fWhereValid = true; } return *fWhere; } double EmcCluster::x() const { return where().x(); } double EmcCluster::y() const { return where().y(); } double EmcCluster::z() const { return where().z(); } //------------- // Modifiers -- //------------- void EmcCluster::addDigi( EmcDigi* theDigi ) { fDigiList.push_back(theDigi); TwoCoordIndex *theTCI = theDigi->GetTCI(); fMemberDigiMap->insert(EmcDigiPtrDict::value_type(theTCI, theDigi)); invalidateCache(); } int EmcCluster::numberOfDigis() const { return fDigiList.size(); } void EmcCluster::Print(const Option_t* opt) const { std::cout<<"*********************************"<< endl; std::cout<<"total energy of cluster: "<< energy() << endl; } const EmcClusterLiloPos& EmcCluster::liloPositions() const { if (fTheClusLiloPos == 0) fTheClusLiloPos = new EmcClusterLiloPos( *this ); return *fTheClusLiloPos; } void EmcCluster::addCluster(EmcCluster* cluster) { const vector tmpList = cluster->digiList(); vector::const_iterator digi_iter; for (digi_iter=tmpList.begin();digi_iter!=tmpList.end();++digi_iter) { addDigi(*digi_iter); } } void EmcCluster::selectCentroidMethod( CentroidMethod alg ) { TVector3 (*algorithm)(const EmcCluster*) = 0; switch (alg) { case lilo: algorithm = EmcClusterLiloPos::liloWhere; break; default: std::cout << "EmcCluster::selectCentroidMethod. " << "Attmpted to select unknown cluster position method." << endl; } // Now actually set the pointer algPointer() = algorithm; } TVector3 EmcCluster::algWhere( const EmcCluster* me ) { return algPointer()( me ); } // Set the default cluster position method TVector3 (*&EmcCluster::algPointer())( const EmcCluster* ) { static TVector3 (*pointer)( const EmcCluster* ) = EmcClusterLiloPos::liloWhere; return pointer; } void EmcCluster::invalidateCache() { fEnergyValid = false; fWhereValid = false; if ( fTheClusLiloPos != 0) { delete fTheClusLiloPos; fTheClusLiloPos = 0; } } //check if a digi belong to this cluester bool EmcCluster::isInCluster( EmcDigi* theDigi ) { vector::iterator digi_iter; for (digi_iter=fDigiList.begin();digi_iter!=fDigiList.end();++digi_iter) { if(theDigi->isNeighbour(*digi_iter)) return true; } return false; } ClassImp(EmcCluster)