//--------------------------------------------------------------------- // File and Version Information: // $Id: $ // // Description: // energy() returns energy sum of digis in cluster. // where() returns a TVector3 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 "PndEmcCluster.h" #include "PndEmcClusterLiloPos.h" #include "PndEmcClusterLinearPos.h" #include "PndEmcDigi.h" #include "PndEmcStructure.h" #include "TVector3.h" #include #include #include #include #include #include using std::endl; using std::vector; //---------------- // Constructors -- //---------------- PndEmcCluster::PndEmcCluster() : fMemberDigiMap( new PndEmcDigiPtrDict ), fEnergyValid( false ), fEnergy( 0 ), fWhereValid( false ), fWhere( 0 ), fTheClusLiloPos( 0 ), fTheClusLinearPos( 0 ) { } PndEmcCluster::PndEmcCluster(int digiList, int localMaxList) : fMemberDigiMap( new PndEmcDigiPtrDict ), fEnergyValid( false ), fEnergy( 0 ), fWhereValid( false ), fWhere( 0 ), fTheClusLiloPos( 0 ), fTheClusLinearPos( 0 ) { fDigiList.reserve(digiList); fLocalMaxList.reserve(localMaxList); } //-------------- // Destructor -- //-------------- PndEmcCluster::~PndEmcCluster() { delete fWhere; fMemberDigiMap->clear(); delete fMemberDigiMap; if ( fTheClusLiloPos != 0) delete fTheClusLiloPos; if ( fTheClusLinearPos != 0) delete fTheClusLinearPos; } double PndEmcCluster::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 PndEmcCluster::theta() const { return where().Theta(); } double PndEmcCluster::phi() const { return where().Phi(); } double PndEmcCluster::thetaIndex() const { return 0; } double PndEmcCluster::phiIndex() const { return 0; } TVector3 PndEmcCluster::position() const { return this->where(); } TVector3 PndEmcCluster::where() const { if ( !fWhereValid ) { delete fWhere; fWhere = new TVector3( algWhere( this ) ); fWhereValid = true; } return *fWhere; } double PndEmcCluster::x() const { return where().x(); } double PndEmcCluster::y() const { return where().y(); } double PndEmcCluster::z() const { return where().z(); } //------------- // Modifiers -- //------------- void PndEmcCluster::addDigi( PndEmcDigi* theDigi ) { fDigiList.push_back(theDigi); PndEmcTwoCoordIndex *theTCI = theDigi->GetTCI(); fMemberDigiMap->insert(PndEmcDigiPtrDict::value_type(theTCI, theDigi)); invalidateCache(); } int PndEmcCluster::numberOfDigis() const { return fDigiList.size(); } void PndEmcCluster::setNBumps(unsigned nbumps) { _nbumps = nbumps; } void PndEmcCluster::Print(const Option_t* opt) const { std::cout<<"*********************************"<< endl; std::cout<<"total energy of cluster: "<< energy() << endl; } const PndEmcClusterLiloPos& PndEmcCluster::liloPositions() const { if (fTheClusLiloPos == 0) fTheClusLiloPos = new PndEmcClusterLiloPos( *this ); return *fTheClusLiloPos; } const PndEmcClusterLinearPos& PndEmcCluster::linearPositions() const { if (fTheClusLinearPos == 0) fTheClusLinearPos = new PndEmcClusterLinearPos( *this ); return *fTheClusLinearPos; } void PndEmcCluster::addCluster(PndEmcCluster* 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 PndEmcCluster::selectCentroidMethod( CentroidMethod alg, PndEmcClusterLiloPosData ClusterPositionParameters ) { TVector3 (*algorithm)(const PndEmcCluster*) = 0; switch (alg) { case lilo: algorithm = PndEmcClusterLiloPos::liloWhere; PndEmcClusterLiloPos::SetParameters(ClusterPositionParameters); break; case linear: algorithm = PndEmcClusterLinearPos::linearWhere; break; default: std::cout << "PndEmcCluster::selectCentroidMethod. " << "Attmpted to select unknown cluster position method." << endl; } // Now actually set the pointer algPointer() = algorithm; } TVector3 PndEmcCluster::algWhere( const PndEmcCluster* me ) { return algPointer()( me ); } // Set the default cluster position method TVector3 (*&PndEmcCluster::algPointer())( const PndEmcCluster* ) { static TVector3 (*pointer)( const PndEmcCluster* ) = PndEmcClusterLiloPos::liloWhere; return pointer; } void PndEmcCluster::invalidateCache() { fEnergyValid = false; fWhereValid = false; if ( fTheClusLiloPos != 0) { delete fTheClusLiloPos; fTheClusLiloPos = 0; } } //check if a digi belong to this cluester bool PndEmcCluster::isInCluster( PndEmcDigi* 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; } void PndEmcCluster::ValidateDigiMap() { fMemberDigiMap->clear(); vector::iterator digi_iter; for (digi_iter=fDigiList.begin();digi_iter!=fDigiList.end();++digi_iter) { (*digi_iter)->ValidateTCI(); PndEmcTwoCoordIndex *theTCI = (*digi_iter)->GetTCI(); fMemberDigiMap->insert(PndEmcDigiPtrDict::value_type(theTCI, (*digi_iter))); } } ClassImp(PndEmcCluster)