180 likes | 436 Views
Evolution of cluster design in the Instrumented Flux Return (IFR) of BaBar. Luca Lista INFN, Sezione di Napoli for the BaBar Computing Group. The Instrumented Flux Return of BaBar. 18-19 layers of Resistive Plate Chambers (RPC) 2 layers of cylindrical RPC inside the coil
E N D
Evolution of cluster design in the Instrumented Flux Return (IFR) of BaBar Luca Lista INFN, Sezione di Napoli for the BaBar Computing Group
The Instrumented Flux Return of BaBar • 18-19 layers of Resistive Plate Chambers (RPC) • 2 layers of cylindrical RPC inside the coil • Digital strip readout, 2-3cm pitch Luca Lista - CHEP '98
Ifr basic reconstruction information • The Ifr reconstruction provides the following basic information strip 1Dcluster 3D cluster Luca Lista - CHEP '98
Clustering in the IFR • The IFR identifies m, p and K0L • The reconstruction information in the IFR is made of clusters of strips which are “close” in space • Details of the pattern information give particle ID discriminating power • Estimate of the impact point provides a determination of the flight direction of the K0L mcluster pcluster Luca Lista - CHEP '98
2D and 3D Clustering • Projective geometry in the planar RPC’s • 2D reconstruction in each projection • 3D association of the two projections Ifr2DCluster Luca Lista - CHEP '98
Early class design • The basic class structure • The initial interface: 1 1..n 1 2 Ifr3DCluster Ifr2DCluster Ifr1DCluster Ifr3DCluster centerOfGravity () : Point covMatrix () : BbrError Ifr2DCluster direction (from : Point) : Vector 1 numberOfHits () : int numberOfHits () : int 2 numberOfStrips () : int numberOfStrips () : int firstLayer () : int firstLayer () : int lastLayer () : int lastLayer () : int hitLayers () : int hitLayer () : int 1 1..n Ifr1DCluster numberOfStrips( ) Luca Lista - CHEP '98
Composite clusters • Cluster segments associated to the same charged track are combined together Ifr3DComposite Ifr3DCluster centerOfGravity () : Point centerOfGravity () : Point covMatrix () : BbrError covMatrix () : BbrError direction (from : Point) : Vector direction (from : Point) : Vector 1..n numberOfHits () : int numberOfHits () : int numberOfStrips () : int numberOfStrips () : int firstLayer () : int firstLayer () : int lastLayer () : int lastLayer () : int hitLayers () : int hitLayers () : int Luca Lista - CHEP '98
Polimorphic clusters • The user shouldn’t care about the detail of the cluster substructure: • just use IfrAbs3D • All clusters implement the same interface. IfrAbs3D centerOfGravity () : Point covMatrix () : BbrError direction (from : Point) : Vector numberOfHits () : int numberOfStrips () : int firstLayer () : int lastLayer () : int hitLayers () : int Ifr3DComposite Ifr3DCluster centerOfGravity () : Point centerOfGravity () : Point covMatrix () : BbrError covMatrix () : BbrError direction (from : Point) : Vector direction (from : Point) : Vector 1..n numberOfHits () : int numberOfHits () : int numberOfStrips () : int numberOfStrips () : int firstLayer () : int firstLayer () : int lastLayer () : int lastLayer () : int hitLayers () : int hitLayers () : int Luca Lista - CHEP '98
Inner RPC clusters • The inner RPC readout layout changed during software evolution: • stereo readout strips • 2D clustering is no longer appropriate • Composite clusters can’t be done of homogeneous elements Luca Lista - CHEP '98
IfrAbs3D Evolution of the cluster model IfrAbs3D () : IfrAbs3D IfrAbs3D (a : const IfrAbs3D&) : IfrAbs3D position () : HepPoint ~IfrAbs3D () numberOfDigis () : int numberOfStrips () : int covMatrix () : BbrError polCovMatrix () : BbrError $polCovMatrix ( : BbrError&, : HepPoint&) : BbrError • Cluster information is intrinsically complex • It is not possible to predict now all the needed functions • The extension of the class functions requires changing the base class interface • Extension to new cluster types? firstLayer () : int lastLayer () : int hitLayers () : int hitLayersI () : int hitsInLayer (n : int) : int stripsInLayer (n : int) : int maxMissed () : int sectionCode () : Ifr::SectionCode component ( : int = 0) : Ifr3DCluster* numberOfComponents () : int numberOfComponents ( : Ifr::SectorCode) : int numberOfComponents ( : Ifr::SectionCode) : int getComposite () : Ifr3DComposite* hasBarrel () : bool hasEndCap () : bool hasFwdCap () : bool hasBwdCap () : bool hasInner () : bool operator == ( : const IfrAbs3D&) : bool number () : unsigned int $resetCounter () : void saveGuts ( : RWvostream&) : void restoreGuts ( : RWvistream&) : void Luca Lista - CHEP '98 1..n Ifr3DComposite Ifr3DCluster
Problems spotted during the development • The cluster class interface growth rate was more than linear with time • Code which used deep information of the cluster pattern tended to “understand” which subclass type it was using (dynamic_cast) • Dependencies on cluster subtypes rather than base class increased • Problems to effectively evolve the design Luca Lista - CHEP '98
Visitor pattern • Each function of the cluster classes is implemented in a separate class for all cluster types • all inherit from IfrClusterVisitor abstract interface • Extending the functionality does not require any change to classe interfaces • just add a new visitor class • Dependency on cluster subclasses is concentrated in the visitor classes • The design is, according to an OO principle, • open to extensions • closed to class interface changes Luca Lista - CHEP '98
Visitor pattern class diagram T 1..n IfrAbs3D IfrClusterVisitor accept (IfrClusterVisitor<T>) : T operate (const Ifr3DCluster*) : T operate (const IfrInner3DCluster*) : T operate (const Ifr3DComposite*) : T operate (const Ifr2DCluster*) : T Ifr3DComposite accept (const IfrClusterVisitor<T>& v) : T IfrClusterVisitor{Hep3Vector} IfrInner3DCluster accept (const IfrClusterVisitor<T>& v) : T Ifr3DCluster accept (const IfrClusterVisitor<T>& v) : T 2 Ifr2DCluster accept (const IfrClusterVisitor<T>& v) : T IfrVstCenterOfGravity operate (const Ifr3DCluster*) : Hep3Vector { operate (const IfrInner3DCluster*) : Hep3Vector return v.operate(this); operate (const Ifr3DComposite*) : Hep3Vector } operate (const Ifr2DCluster*) : Hep3Vector Luca Lista - CHEP '98
Visitors features • New visitors can be added as new subclasses of IfrClusterVisitor<myType> with no other changes • New cluster types can be added without mayor design changes (e.g.: Ifr3DFastCluster) • but all the visitors subclasses should be updated to work on the new cluster subclass • Details can be handled internally: • calibrations, alignments • The code which uses IfrAbs3D and visitors appears to be much more robust than before • a couple of unsolved bugs have been understood and fixed during the migration Luca Lista - CHEP '98
Visitors features (cont.) • Recursive action on Ifr3DCompositecomponents matches the composite pattern • Ifr3DCompositehasnIfrAbs3D’s • A visitor subclass handles a built-in cache mechanism implemented with a hash dictionary. • a visitor “knows” the cluster he has already “visited” • the cache is invalidated at: • destruction of every cluster for the deleted cluster • at the end of every event (to prevent the accumulation of possible memory leaks) Luca Lista - CHEP '98
Available Visitors • Visitors are singleton/multiton • Some of the available visitors are: • IfrVstCenterOfGravity • IfrVstCovMatrix • IfrVstFirstLastLayer • first | last | lastBarrel • IfrVstHasSector • forward | backward | barrel • IfrVstHitLayers • IfrVstHitsInLayer • n = 1, ... ,19 • IfrVstMaxMissed • IfrVstNumberOfStrips • . . . Luca Lista - CHEP '98
Visitors Usage • How to use visitors: IfrAbs3D* ifr; // get a cluster from somewhere // compute center of gravity HepPoint c = ifr->accept( IfrVstCenterOfgravity::instance() ); // has hits in the barrel? bool barrel = ifr->accept(IfrVstHasSector::instance (IfrVstHasSector::barrel) ); // get number of hits in each layer int n[19], i; for (i = 0; i < 19; i++) n[i] = ifr->accept( IfrVstHitsInLayer::instance(i+1) ); // compute max. number of missed layers int maxMiss = ifr->accept( IfrVstMaxMissed::instance() ); Luca Lista - CHEP '98
References • On-line Ifr documentation: • http://www1.na.infn.it/wsubnucl/accel/BaBar/Reco/6.7.3/see IfrData and IfrVisitor packages for class diagram and C++ code • Original proposal document: • http://www1.na.infn.it/wsubnucl/accel/BaBar/Reco/visitors.html Luca Lista - CHEP '98