15 #include "EVENT/LCObject.h"
16 #include "EVENT/LCCollection.h"
17 #include "IMPL/ClusterImpl.h"
19 #include "ClusterShapes.h"
20 #include "CLHEP/Vector/ThreeVector.h"
24 using namespace CLHEP ;
47 template <
class In,
class Out,
class Pred >
48 void cluster( In first, In last, Out result, Pred* pred ) {
50 typedef typename In::value_type GenericHitPtr ;
51 typedef typename Pred::hit_type HitType ;
53 typedef std::vector< GenericCluster<HitType >* > ClusterList ;
60 while( first != last ) {
64 for( In other = first+1 ; other != last ; other ++ ) {
68 if( pred->mergeHits( (*first) , (*other) ) ) {
70 if( (*first)->second == 0 && (*other)->second == 0 ) {
79 else if( (*first)->second != 0 && (*other)->second != 0 ) {
84 if( (*first)->second != (*other)->second )
85 (*first)->second->mergeClusters( (*other)->second ) ;
89 if( (*first)->second != 0 ) {
91 (*first)->second->addHit( (*other) ) ;
95 (*other)->second->addHit( (*first) ) ;
109 for(
typename ClusterList::iterator i = tmp.begin(); i != tmp.end() ; i++ ){
111 if( (*i)->size() > 0 ) {
128 class GenericHit :
public std::pair< T*, GenericCluster<T>* >{
130 typedef T value_type ;
131 typedef std::pair< T*, GenericCluster<T>* > Pair ;
182 this->push_back( hit ) ;
190 (*it)->second = this ;
202 typedef std::vector< GenericHit<T>* > Vector ;
205 for(
typename GenericHitVec::iterator i = Vector::begin() ; i != Vector::end() ; i++)
delete *i ;
214 template <
class T,
class Pred>
215 void addToGenericHitVec(
GenericHitVec<T>& v, LCCollection* col, Pred pred ){
217 for(
int i=0 ; i < col->getNumberOfElements() ; i++ ){
219 T* hit =
dynamic_cast<T*
>( col->getElementAt( i) ) ;
232 template <
class T,
class Pred,
class Order>
233 void addToGenericHitVec(
GenericHitVec<T>& v, LCCollection* col, Pred pred , Order order ){
235 for(
int i=0 ; i < col->getNumberOfElements() ; i++ ){
237 T* hit =
dynamic_cast<T*
>( col->getElementAt( i) ) ;
250 typedef std::list< GenericCluster<T>* > List ;
253 for(
typename GenericClusterVec::iterator i = List::begin() ; i != List::end() ; i++)
delete *i ;
262 template <
class HitClass,
typename PosType >
271 NNDistance(
float dCut) : _dCutSquared( dCut*dCut ) , _dCut(dCut) {}
277 if( std::abs( h0->
Index0 - h1->
Index0 ) > 1 )
return false ;
279 const PosType* pos0 = h0->first->getPosition() ;
280 const PosType* pos1 = h1->first->getPosition() ;
283 ( pos0[0] - pos1[0] ) * ( pos0[0] - pos1[0] ) +
284 ( pos0[1] - pos1[1] ) * ( pos0[1] - pos1[1] ) +
285 ( pos0[2] - pos1[2] ) * ( pos0[2] - pos1[2] )
302 EnergyCut(
double eCut ) : _eCut( eCut ) {}
304 inline bool operator() (T* hit) {
return hit->getEnergy() > _eCut ; }
317 template <
class T,
int N>
321 ZIndex(
float zmin ,
float zmax ) : _zmin( zmin ), _zmax( zmax ) {}
323 inline int operator() (T* hit) {
325 return (
int) std::floor( ( hit->getPosition()[2] - _zmin ) / ( _zmax - _zmin ) * N ) ;
344 ClusterImpl* clu =
new ClusterImpl ;
346 unsigned n = c->size() ;
349 float a[n], x[n], y[n], z[n] ;
353 T* hit = (*hi)->first ;
355 a[i] = hit->getEnergy() ;
356 x[i] = hit->getPosition()[0] ;
357 y[i] = hit->getPosition()[1] ;
358 z[i] = hit->getPosition()[2] ;
360 clu->
addHit( hit , a[i] ) ;
373 Hep3Vector v( d[0], d[1], d[2] ) ;
375 clu->setITheta( v.theta() ) ;
376 clu->setIPhi( v.phi() ) ;
378 std::vector<float> param(5) ;
391 clu->setShape( param ) ;
HitClass hit_type
Required typedef for cluster algorithm.
Definition: NNClusters.h:268
NNDistance(float dCut)
C'tor takes merge distance.
Definition: NNClusters.h:271
float getElipsoid_r1()
largest spatial axis length of the ellipsoid derived by the inertia tensor (by their eigenvalues and ...
Definition: ClusterShapes.h:257
Simple predicate class for computing an index from N bins of the z-coordinate of LCObjects that have ...
Definition: NNClusters.h:318
Templated class for generic hit type objects that are to be clustered with an NN-like clustering algo...
Definition: NNClusters.h:128
void addHit(GenericHit< T > *hit)
Add a hit to this cluster - updates the hit's pointer to cluster.
Definition: NNClusters.h:179
float * getCenterOfGravity()
US spelling of getCentreOfGravity.
Definition: ClusterShapes.h:82
float * getEigenVecInertia()
array of the three main axes of inertia (9 entries) starting with the axis corresponding to the small...
Definition: ClusterShapes.cc:696
Templated class for generic clusters of GenericHits that are clustered with an NN-like clustering alg...
Definition: NNClusters.h:29
float getElipsoid_vol()
volume of the ellipsoid
Definition: ClusterShapes.h:276
float getTotalAmplitude()
returns the accumulated amplitude for the whole cluster (just the sum of the energy in all the entrie...
Definition: ClusterShapes.cc:665
Helper class that creates an lcio::Cluster from a generic cluster with hit types that have a getPosit...
Definition: NNClusters.h:340
GenericCluster(GenericHit< T > *hit)
C'tor that takes the first hit.
Definition: NNClusters.h:174
Helper vector of GenericCluster<T> taking care of memory management.
Definition: NNClusters.h:249
float getWidth()
'mean' width of the cluster perpendicular to the main principal axis, defined as: width := sqrt( 1/To...
Definition: ClusterShapes.cc:708
Simple predicate class for applying an energy cut to the objects of type T.
Definition: NNClusters.h:300
GenericHit(T *hit, int index0=0)
Default c'tor takes a pointer to the original hit type object.
Definition: NNClusters.h:138
GenericHit(T *hit, GenericCluster< T > *cl, int index0=0)
C'tor that also takes a pointer to the cluster this hit belongs to - in case seed hits/clusters are u...
Definition: NNClusters.h:145
Simple predicate class for NN clustering.
Definition: NNClusters.h:263
ZIndex(float zmin, float zmax)
C'tor takes zmin and zmax - NB index can be negative and larger than N.
Definition: NNClusters.h:321
int Index0
Index that can be used to code nearest neighbour bins, e.g.
Definition: NNClusters.h:153
Utility class to derive properties of clusters, such as centre of gravity, axes of inertia...
Definition: ClusterShapes.h:25
Helper vector of GenericHit<T> taking care of memory management, i.e.
Definition: NNClusters.h:201
void mergeClusters(GenericCluster< T > *cl)
Merges all hits from the other cluster cl into this cluster.
Definition: NNClusters.h:187
float getElipsoid_r3()
smallest spatial axis length of the ellipsoid derived by the inertia tensor (by their eigenvalues and...
Definition: ClusterShapes.h:271
float getElipsoid_r2()
medium spatial axis length of the ellipsoid derived by the inertia tensor (by their eigenvalues and e...
Definition: ClusterShapes.h:264
bool mergeHits(GenericHit< HitClass > *h0, GenericHit< HitClass > *h1)
Merge condition: true if distance is less than dCut given in the C'tor.
Definition: NNClusters.h:275