new design: digits are not data members of AliPHOS anymore (use IndexToObject)
authorschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 4 Apr 2001 13:22:19 +0000 (13:22 +0000)
committerschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 4 Apr 2001 13:22:19 +0000 (13:22 +0000)
12 files changed:
PHOS/AliPHOSPpsdRecPoint.cxx
PHOS/AliPHOSPpsdRecPoint.h
PHOS/AliPHOSRecParticle.cxx
PHOS/AliPHOSRecParticle.h
PHOS/AliPHOSRecPoint.cxx
PHOS/AliPHOSRecPoint.h
PHOS/AliPHOSTrackSegment.cxx
PHOS/AliPHOSTrackSegment.h
PHOS/AliPHOSTrackSegmentMaker.cxx
PHOS/AliPHOSTrackSegmentMaker.h
PHOS/AliPHOSTrackSegmentMakerv1.cxx
PHOS/AliPHOSTrackSegmentMakerv1.h

index f86383a27066ac92729bab22dcd7f6037d573226..efbfd1290f1789b6b10f4b809bd0db9f3960e466 100644 (file)
@@ -36,7 +36,6 @@
 #include "AliPHOSPpsdRecPoint.h"
 #include "AliPHOSCpvRecPoint.h"
 #include "AliRun.h"
-#include "AliPHOSIndexToObject.h"
 
 ClassImp(AliPHOSPpsdRecPoint)
 
@@ -47,7 +46,6 @@ AliPHOSPpsdRecPoint::AliPHOSPpsdRecPoint(void)
 
   fMulDigit = 0 ;  
   fGeom = AliPHOSGeometry::GetInstance() ;  
-  fDelta = ((AliPHOSGeometry *)fGeom)->GetCrystalSize(0) ; 
   fLocPos.SetX(1000000.)  ;      //Local position should be evaluated
 }
 
@@ -77,21 +75,23 @@ void AliPHOSPpsdRecPoint::AddDigit(AliPHOSDigit & digit, Float_t Energy)
 
   fDigitsList[fMulDigit++]  =  digit.GetIndexInList() ; 
   fAmp += Energy ; 
+  EvalPHOSMod(&digit) ;
 }
 
 //____________________________________________________________________________
 Int_t AliPHOSPpsdRecPoint::Compare(const TObject * obj) const
 {
   // Compares according to the position
-  
+  Float_t delta = 1 ; //width of the "Sorting row"
+
   Int_t rv ; 
   
   if( (strcmp(obj->ClassName() , "AliPHOSPpsdRecPoint" )) == 0)  // PPSD Rec Point
     {
      AliPHOSPpsdRecPoint * clu = (AliPHOSPpsdRecPoint *)obj ; 
 
-     Float_t x1 , z1 ;
-     Float_t x2 , z2 ;
+     Float_t x1 , z1 ;    //This rec point
+     Float_t x2 , z2 ;    //
      
      Int_t phosmod1 ;
      Int_t phosmod2 ;
@@ -110,10 +110,10 @@ Int_t AliPHOSPpsdRecPoint::Compare(const TObject * obj) const
        up2 = 1 ;       
 
      TVector3 posloc ;
-     this->GetLocalPosition(posloc) ;
+     GetLocalPosition(posloc) ;
      x1 = posloc.X() ;
      z1 = posloc.Z() ; 
-     phosmod1 = this->GetPHOSMod();  
+     phosmod1 = GetPHOSMod();  
      clu->GetLocalPosition(posloc) ;
      x2 = posloc.X() ;
      z2 = posloc.Z() ; 
@@ -122,12 +122,12 @@ Int_t AliPHOSPpsdRecPoint::Compare(const TObject * obj) const
      if(phosmod1 == phosmod2 ) {
        
        if(up1 == up2 ){
-        Int_t rowdif = (Int_t)TMath::Ceil(x1/fDelta) - (Int_t) TMath::Ceil(x2/fDelta) ;
+        Int_t rowdif = (Int_t)TMath::Ceil(x1/delta) - (Int_t) TMath::Ceil(x2/delta) ;
         
         if (rowdif> 0) 
+          rv = 1 ;
+        else if(rowdif < 0) 
           rv = -1 ;
-      else if(rowdif < 0) 
-       rv = 1 ;
         else if(z1>z2) 
           rv = -1 ;
         else 
@@ -137,9 +137,9 @@ Int_t AliPHOSPpsdRecPoint::Compare(const TObject * obj) const
        else {
         
         if(up1 < up2 ) // Upper level first (up = True or False, True > False)
-          rv = 1 ;   
+          rv = -1 ;   
         else 
-          rv = 1 ;
+          rv = 1 ;
        }
        
      } // if phosmod1 == phosmod2
@@ -158,7 +158,7 @@ Int_t AliPHOSPpsdRecPoint::Compare(const TObject * obj) const
   else
     {
       AliPHOSCpvRecPoint * clu  = (AliPHOSCpvRecPoint *) obj ;   
-      if(this->GetPHOSMod()  < clu->GetPHOSMod() ) 
+      if(GetPHOSMod()  < clu->GetPHOSMod() ) 
        rv = -1 ;
       else 
        rv = 1 ;
@@ -169,18 +169,17 @@ Int_t AliPHOSPpsdRecPoint::Compare(const TObject * obj) const
 }
 
 //____________________________________________________________________________
-void AliPHOSPpsdRecPoint::EvalAll( ){
-  AliPHOSRecPoint::EvalAll() ;
-  EvalLocalPosition( ) ;
+void AliPHOSPpsdRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits ){
+  AliPHOSRecPoint::EvalAll(logWeight,digits) ;
+  EvalLocalPosition(logWeight,digits) ;
+  EvalUp(digits) ;
 }
 
 //____________________________________________________________________________
-void AliPHOSPpsdRecPoint::EvalLocalPosition( )
+void AliPHOSPpsdRecPoint::EvalLocalPosition(Float_t logWeight,TClonesArray * digits )
 {
   // Calculates the local position in the PHOS-PPSD-module corrdinates
   
-  AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ; 
-
   Int_t relid[4] ;
 
   Float_t x = 0. ;
@@ -192,7 +191,7 @@ void AliPHOSPpsdRecPoint::EvalLocalPosition( )
   Int_t iDigit;
 
   for(iDigit = 0; iDigit < fMulDigit; iDigit++) {
-    digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[iDigit]) )
+    digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) 
  
     Float_t xi ;
     Float_t zi ;
@@ -212,29 +211,25 @@ void AliPHOSPpsdRecPoint::EvalLocalPosition( )
 }
 
 //____________________________________________________________________________
-Bool_t AliPHOSPpsdRecPoint::GetUp() const
+void AliPHOSPpsdRecPoint::EvalUp(TClonesArray * digits)
 {
   // Are we in the uper PPSD module ?
 
   Int_t relid[4] ;
   
-  AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ; 
-
   AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
   
   
-  AliPHOSDigit *digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[0]) ) ; 
+  AliPHOSDigit *digit = (AliPHOSDigit *) digits->At(fDigitsList[0]) ; 
   
   phosgeom->AbsToRelNumbering(digit->GetId(),relid);
-  Bool_t up ;
 
   if((Int_t)TMath::Ceil((Float_t)relid[1]/
                        (phosgeom->GetNumberOfModulesPhi()*phosgeom->GetNumberOfModulesZ())-0.0001 ) > 1) 
-    up = kFALSE ;
+    fUp = kFALSE ;
   else  
-    up = kTRUE ;
+    fUp = kTRUE ;
   
-  return up ;
 }
 //______________________________________________________________________________
 void AliPHOSPpsdRecPoint::Paint(Option_t *)
@@ -270,28 +265,12 @@ void AliPHOSPpsdRecPoint::Print(Option_t * option)
   
   cout << "AliPHOSPpsdRecPoint: " << endl ;
   
-  AliPHOSDigit * digit ; 
-  Int_t iDigit;
-  AliPHOSGeometry * phosgeom =  (AliPHOSGeometry *) fGeom ;
-
-  Float_t xi ;
-  Float_t zi ;
-  Int_t relid[4] ; 
-
-  AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ; 
-  for(iDigit=0; iDigit<fMulDigit; iDigit++) {
-    digit = please->GimeDigit( fDigitsList[iDigit] ) ; 
-    if (digit) {
-      phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
-      phosgeom->RelPosInModule(relid, xi, zi);
-      cout << " Id = " << digit->GetId() ;  
-      cout << "  Phos mod = " << relid[0] ;  
-      cout << "  PPSD mod = " << relid[1] ;  
-      cout << "  x = " << xi ;  
-      cout << "  z = " << zi ;  
-      cout << "   Energy = " << digit->GetAmp() << endl ;
-    }
-  }
+  Int_t iDigit; 
+  cout << " Digit{s} # " ; 
+  for(iDigit=0; iDigit<fMulDigit; iDigit++) 
+    cout  << fDigitsList[iDigit] << "  " ;  
+  cout << endl   ;  
+
   cout << "       Multiplicity    = " << fMulDigit  << endl ;
   cout << "       Stored at position " << fIndexInList << endl ; 
 }
index 36bbe4db9d7c6d5aaf36daaf49a20d5a7dec2f2e..f2a101bef9fca6e51d452082b1147f39c2063e70 100644 (file)
@@ -30,21 +30,24 @@ public:
   }
   virtual void AddDigit(AliPHOSDigit & digit, Float_t Energy) ;
   Int_t   Compare(const TObject * obj) const;                    // method to sort clusters
-  void    EvalAll() ;
-  void    EvalLocalPosition() ;              // computes the position in the module of the cluster center
-  Float_t GetDelta(void) const {return fDelta ;  }              // returns the parameter used for sorting
-  Int_t   GetMultiplicity(void) const { return fMulDigit ;  }   // returns the multiplicity of digits at 
-                                                                // the origin of this recpoint
-  Int_t   GetMaximumMultiplicity() const { return   fMaxDigit ; }     // returns the maximum allowed digit multiplicity 
-  Bool_t  GetUp() const ;               // true if cluster is in upper ppsd 
-  Bool_t  IsEmc(void) const {return kFALSE ; }      // tells that this is not a EMC
-  Bool_t  IsSortable() const { return kTRUE ;  }    // tells that this is a sortable object
+
+  void    EvalAll(Float_t LogWeight,TClonesArray * digits) ;
+  void    EvalLocalPosition(Float_t LogWeight,TClonesArray * digits) ;   
+                                                    // computes the position in the module of the cluster center
+  void    EvalUp(TClonesArray * digits) ;              
+
+  Int_t   GetMultiplicity(void)    const { return fMulDigit ;  } // returns the multiplicity of digits at 
+                                                                 // the origin of this recpoint
+  Int_t   GetMaximumMultiplicity() const { return   fMaxDigit ;} // returns the maximum allowed digit multiplicity 
+  Bool_t  GetUp()      const {return fUp;     }    // true if cluster is in upper ppsd 
+  Bool_t  IsEmc(void)  const {return kFALSE ; }    // tells that this is not a EMC
+  Bool_t  IsSortable() const { return kTRUE ; }    // tells that this is a sortable object
   virtual void  Paint(Option_t * option="");
-  void    Print(Option_t * opt = "void") ; 
+  void    Print(Option_t * option) ; 
 
 private:
 
-  Float_t        fDelta ;         // parameter used for sorting
+  Bool_t fUp ; 
   
   ClassDef(AliPHOSPpsdRecPoint,1)  // PPSD RecPoint
 
index 78a406eff28fc36dcc7716a477b268cfa3a29e85..a493f3a799d9351c320796fe2e06d2e2a3210ad4 100644 (file)
 
 #include "AliPHOSRecParticle.h"
 #include "TPad.h"
-#include "AliPHOSIndexToObject.h"
 
 ClassImp(AliPHOSRecParticle)
 
 
-//____________________________________________________________________________
- AliPHOSRecParticle::AliPHOSRecParticle(AliPHOSTrackSegment * ts)
-{
-  // ctor
-  fPHOSTrackSegment = ts->GetIndexInList() ;
-  fIndexInList      = -1 ;
-  Float_t kenergy   = ts->GetEnergy() ; 
-  TVector3 momdir   = ts->GetMomentumDirection() ;
-  fPx               = kenergy * momdir.X() ; 
-  fPy               = kenergy * momdir.Y() ; 
-  fPz               = kenergy * momdir.Z() ; 
-  fType             = kUNDEFINED;  
-  fE                = kenergy ;    // !!! all particles have mass = 0 
-}
-
 //____________________________________________________________________________
  AliPHOSRecParticle::AliPHOSRecParticle(const AliPHOSRecParticle & rp)
 {
@@ -89,53 +72,44 @@ Int_t * AliPHOSRecParticle::GetPrimaries(Int_t & number)
 {
   // Retrieves all the primary particles at the origine of this reconstructed particle
 
-  AliPHOSTrackSegment * ts = GetPHOSTrackSegment() ;
+//   AliPHOSTrackSegment * ts = GetPHOSTrackSegment() ;
 
-  Int_t emcnumber = 0 ; 
-  Int_t * emclist = ts->GetPrimariesEmc(emcnumber) ;
+//   Int_t emcnumber = 0 ; 
+//   Int_t * emclist = ts->GetPrimariesEmc(emcnumber) ;
   
-  Int_t ppsdlnumber = 0 ;
-  Int_t * ppsdllist = ts->GetPrimariesPpsdLow(ppsdlnumber) ;
+//   Int_t ppsdlnumber = 0 ;
+//   Int_t * ppsdllist = ts->GetPrimariesPpsdLow(ppsdlnumber) ;
  
-  Int_t ppsdunumber = 0 ; 
-  Int_t * ppsdulist = ts->GetPrimariesPpsdUp(ppsdunumber) ;
+//   Int_t ppsdunumber = 0 ; 
+//   Int_t * ppsdulist = ts->GetPrimariesPpsdUp(ppsdunumber) ;
 
-  number = emcnumber + ppsdlnumber + ppsdunumber ;
-  Int_t * list   = new Int_t[number] ;
+//   number = emcnumber + ppsdlnumber + ppsdunumber ;
+//   Int_t * list   = new Int_t[number] ;
   
-  Int_t index ; 
-  for ( index = 0 ; index < emcnumber ; index++)
-    list[index] = emclist[index] ;
-
-  Int_t jndex ; 
-  for ( jndex = 0 ; jndex < ppsdlnumber ; jndex++) {
-    assert(index < number) ;
-    list[index] = ppsdllist[jndex] ;
-    index++ ; 
-  }
-
-  for ( jndex = 0 ; jndex < ppsdunumber ; jndex++) {
-    assert(index < number) ;
-    list[index] = ppsdulist[jndex] ;
-    index++ ; 
-  }
-
-  delete emclist ;
-  delete ppsdllist ;
-  delete ppsdulist ;
-
-  return list ; 
+//   Int_t index ; 
+//   for ( index = 0 ; index < emcnumber ; index++)
+//     list[index] = emclist[index] ;
+
+//   Int_t jndex ; 
+//   for ( jndex = 0 ; jndex < ppsdlnumber ; jndex++) {
+//     assert(index < number) ;
+//     list[index] = ppsdllist[jndex] ;
+//     index++ ; 
+//   }
+
+//   for ( jndex = 0 ; jndex < ppsdunumber ; jndex++) {
+//     assert(index < number) ;
+//     list[index] = ppsdulist[jndex] ;
+//     index++ ; 
+//   }
+
+//   delete emclist ;
+//   delete ppsdllist ;
+//   delete ppsdulist ;
+
+  return 0 ; //<--- list ; 
 }
 
-//____________________________________________________________________________
-AliPHOSTrackSegment * AliPHOSRecParticle::GetPHOSTrackSegment() const 
-{
-  // Retrieves the PHOS track segment at the origine of this reconstructed particle
-
-  AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
-  return please->GimeTrackSegment( fPHOSTrackSegment ) ;
-
-}
 
 
 
index 130b613d707762b19b6293263dd052c734dc43b7..39ef741c0b009d06143fbca1ffe01f6ca18bb6a8 100644 (file)
 
 // --- AliRoot header files ---
 
-#include "AliPHOSTrackSegment.h"
 #include "AliPHOSFastRecParticle.h"
 
 class AliPHOSRecParticle : public AliPHOSFastRecParticle {
 
 public:
   
-  AliPHOSRecParticle() {
-    // ctor
-  }
-  AliPHOSRecParticle(AliPHOSTrackSegment * ts) ;  // ctor
+  AliPHOSRecParticle() {  }
   AliPHOSRecParticle(const AliPHOSRecParticle & rp) ;  // ctor
   virtual ~AliPHOSRecParticle(){
     // dtor
   }
-  AliPHOSTrackSegment * GetPHOSTrackSegment() const ; 
-  Int_t                 GetPHOSTrackSegmentIndex(){
-    // Getter 
-    return fPHOSTrackSegment ;
-  }
+
+  Int_t                 GetPHOSTSIndex(){    return fPHOSTrackSegment ;  }
+
   Int_t *               GetPrimaries(Int_t & number) ;
+  
+  void                  SetTraskSegment(Int_t index){fPHOSTrackSegment = index; }
 
   typedef TClonesArray RecParticlesList ; 
   
index e2a9ccf8219df5e61e3ed36a2288c5928e0c3ab7..c05023f37a92da65cf1cf977b284f7167e7e4ba0 100644 (file)
@@ -22,6 +22,7 @@
 
 // --- ROOT system ---
 #include "TPad.h"
+#include "TClonesArray.h"
 
 // --- Standard library ---
 #include <iostream.h>
@@ -32,7 +33,6 @@
 #include "AliPHOSGeometry.h"
 #include "AliPHOSDigit.h"
 #include "AliPHOSRecPoint.h"
-#include "AliPHOSIndexToObject.h"
 
 ClassImp(AliPHOSRecPoint)
 
@@ -44,6 +44,7 @@ AliPHOSRecPoint::AliPHOSRecPoint()
   // ctor
 
   fGeom = (AliPHOSGeometry*) AliPHOSGeometry::GetInstance() ;
+  fMaxTrack = 20 ;
   fPHOSMod = 0;
 }
 
@@ -153,73 +154,74 @@ break;
   }
 }
 //____________________________________________________________________________
-void AliPHOSRecPoint::EvalAll() {
+void AliPHOSRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits) {
   //evaluates (if necessary) all RecPoint data members 
 
-  EvalPHOSMod() ;
+  EvalPrimaries(digits) ;
 }
 //____________________________________________________________________________
-void AliPHOSRecPoint::EvalPHOSMod() 
+void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit
 {
   // Returns the PHOS module in which the RecPoint is found
-  AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ; 
 
+  if( fPHOSMod == 0){
   Int_t relid[4] ; 
   
-  AliPHOSDigit * digit   ;
-  digit = (AliPHOSDigit *) ( please->GimeDigit(fDigitsList[0]) ) ;
   AliPHOSGeometry * phosgeom =  (AliPHOSGeometry *) fGeom ;
 
   phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
   fPHOSMod = relid[0];
+  }
 }
 
 //______________________________________________________________________________
-Int_t * AliPHOSRecPoint::GetPrimaries(Int_t & number) const
+void  AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
 {
-  // Constructs the list of primary particles which have contributed to this RecPoint
+  // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
   
   AliPHOSDigit * digit ;
-  Int_t index ;
-  Int_t maxcounter = 20 ;
-  Int_t counter    = 0 ;
-  Int_t * tempo    = new Int_t[maxcounter] ;
-  AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
-  
+  Int_t * tempo    = new Int_t[fMaxTrack] ;
+
+  Int_t index ;  
   for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
-    digit = please->GimeDigit( fDigitsList[index] ) ; 
+    digit = (AliPHOSDigit *) digits->At( fDigitsList[index] ) ; 
     Int_t nprimaries = digit->GetNprimary() ;
     Int_t * newprimaryarray = new Int_t[nprimaries] ;
     Int_t ii ; 
     for ( ii = 0 ; ii < nprimaries ; ii++)
       newprimaryarray[ii] = digit->GetPrimary(ii+1) ; 
+
     Int_t jndex ;
     for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
-      if ( counter > maxcounter ) {
-       number = - 1 ;
-       cout << "AliPHOSRecPoint::GetNprimaries ERROR > increase maxcounter " << endl ;
+      if ( fMulTrack > fMaxTrack ) {
+       fMulTrack = - 1 ;
+       cout << "AliPHOSRecPoint::GetNprimaries ERROR > increase fMaxTrack " << endl ;
        break ;
       }
       Int_t newprimary = newprimaryarray[jndex] ;
       Int_t kndex ;
       Bool_t already = kFALSE ;
-      for ( kndex = 0 ; kndex < counter ; kndex++ ) { //check if not already stored
+      for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
        if ( newprimary == tempo[kndex] ){
          already = kTRUE ;
          break ;
        }
       } // end of check
       if ( !already) { // store it
-       tempo[counter] = newprimary ; 
-       counter++ ;
+       tempo[fMulTrack] = newprimary ; 
+       fMulTrack++ ;
       } // store it
     } // all primaries in digit
     delete newprimaryarray ; 
   } // all digits
 
-  number = counter ; 
-  return tempo ; 
+  
+  fTracksList = new Int_t[fMulTrack] ;
+  for(index = 0; index < fMulTrack; index++)
+   fTracksList[index] = tempo[index] ;
+  delete tempo ;
+
 }
 
 //______________________________________________________________________________
index 75a11d5e7970a962860a448ecd752a276b923c97..c2adc61b1c70d0bab472f82185c4ab74dbef14c4 100644 (file)
@@ -22,7 +22,6 @@
 #include "AliRecPoint.h"
 #include "AliPHOSDigit.h"
 #include "AliPHOSGeometry.h"
-class AliPHOSGeometry;
 
 class AliPHOSRecPoint : public AliRecPoint {
 
@@ -45,14 +44,16 @@ class AliPHOSRecPoint : public AliRecPoint {
     assert(0==1) ; 
   }
   virtual  void   AddDigit(AliPHOSDigit & digit, Float_t Energy) = 0 ; 
-  virtual Int_t   Compare(const TObject * obj) const {assert(0==1) ; return 1 ;   }   
+  virtual Int_t   Compare(const TObject * obj) const = 0 ;   
   virtual Int_t   DistancetoPrimitive(Int_t px, Int_t py);
   virtual void    Draw(Option_t * option="") ;
   virtual void    ExecuteEvent(Int_t event, Int_t px, Int_t py) ;
-  virtual void    EvalAll(void) ;  
-  virtual void    EvalPHOSMod(void) ;  
+  virtual void    EvalAll(Float_t logWeight,TClonesArray * digits) ;  
+  virtual void    EvalPHOSMod(AliPHOSDigit * digit) ;  
+  virtual void    EvalPrimaries(TClonesArray * digits) ;  
   virtual Int_t   GetPHOSMod(void) const {return fPHOSMod ; }
-  virtual Int_t * GetPrimaries(Int_t & number) const ;
+  virtual Int_t * GetPrimaries(Int_t & number) const {number = fMulTrack ; 
+                                                      return fTracksList ; }
   virtual Bool_t  IsEmc(void)const { return kTRUE ;  } 
   virtual Bool_t  IsSortable() const { 
     // tells that this is a sortable object
index f833b416b1bae20819699b8ec377f7c719cfc099..e00d52a5d0b4d457ef2300115bce56e3f6f72deb 100644 (file)
@@ -23,8 +23,6 @@
 
 // --- ROOT system ---
  
-#include "TVector3.h"
-#include "TPad.h"
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
 
 #include "AliPHOSTrackSegment.h" 
-#include "AliPHOSv0.h"
-#include "AliPHOSIndexToObject.h"
 
 ClassImp(AliPHOSTrackSegment)
 
 //____________________________________________________________________________
 AliPHOSTrackSegment::AliPHOSTrackSegment( AliPHOSEmcRecPoint * emc , 
-                                         AliPHOSPpsdRecPoint * ppsdrp1,
-                                         AliPHOSPpsdRecPoint * ppsdrp2  ) 
+                                         AliPHOSRecPoint * ppsdrp1,
+                                         AliPHOSRecPoint * ppsdrp2  ) 
 {
   // ctor
 
@@ -83,411 +79,31 @@ void AliPHOSTrackSegment::Copy(TObject & obj)
    ( (AliPHOSTrackSegment &)obj ).fPpsdUpRecPoint  = fPpsdUpRecPoint ; 
    ( (AliPHOSTrackSegment &)obj ).fIndexInList     = fIndexInList ; 
 }
-//____________________________________________________________________________
-Int_t AliPHOSTrackSegment::DistancetoPrimitive(Int_t px, Int_t py)
-{
-  // Compute distance from point px,py to  a AliPHOSTrackSegment considered as a Tmarker
-  // Compute the closest distance of approach from point px,py to this marker.
-  // The distance is computed in pixels units.
-  
-  Int_t div = 1 ;  
-  Int_t dist = 9999 ; 
-  
-  TVector3 pos(0.,0.,0.) ;
-  
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
-  AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
-  
-  if ( emcrp != 0 ) {
-    emcrp->GetLocalPosition( pos) ;
-    Float_t x =  pos.X() ;
-    Float_t y =  pos.Z() ;
-    if ( ppsdlrp != 0 ) {
-      ppsdlrp->GetLocalPosition( pos ) ;
-      x +=  pos.X() ;
-      y +=  pos.Z() ;
-      div++ ; 
-    }
-    if ( ppsdurp != 0 ) {
-      ppsdurp->GetLocalPosition( pos ) ;
-      x +=  pos.X() ;
-      y +=  pos.Z() ;
-      div++ ; 
-    }
-    x /= div ; 
-    y /= div ; 
-
-    const Int_t kMaxDiff = 10;
-    Int_t pxm  = gPad->XtoAbsPixel(x);
-    Int_t pym  = gPad->YtoAbsPixel(y);
-    dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
-    
-    if (dist > kMaxDiff) return 9999;
-  }
-  return dist;
-}
-
-//___________________________________________________________________________
- void AliPHOSTrackSegment::Draw(Option_t *option)
- {
-   // Draw this AliPHOSTrackSegment with its current attribute
-   
-   AppendPad(option);
- }
-
-//______________________________________________________________________________
-void AliPHOSTrackSegment::ExecuteEvent(Int_t event, Int_t px, Int_t py)
-{
-  // Execute action corresponding to one event
-  //  This member function is called when a AliPHOSTrackSegment is clicked with the locator
-  //
-  //  If Left button is clicked on AliPHOSRecPoint, the digits are switched on    
-  //  and switched off when the mouse button is released.
-  static TPaveText* textTS = 0 ;
-  
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-
-  if (!gPad->IsEditable()) 
-    return;
-  
-  switch (event) {
-    
-  case kButton1Down:{
-    
-    if (!textTS) {
-      
-      TVector3 pos(0.,0.,0.) ;
-      emcrp->GetLocalPosition(pos) ;
-      textTS = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+5,pos.Z()+15,"") ;
-      Text_t  line1[40] ;
-      sprintf(line1,"See RecParticle for ID") ;
-      textTS ->AddText(line1) ;
-      textTS ->Draw("");
-      gPad->Update() ; 
-    }
-  }
-  
-  break;
-  
-  case kButton1Up:
-    if (textTS) {
-      delete textTS ;
-      textTS = 0 ;
-    }
-    break;  
-  }
-}
-
-//____________________________________________________________________________
-Float_t AliPHOSTrackSegment::GetDistanceInPHOSPlane()
-{
-  // Calculates the distance between the EMC RecPoint and PPSD RecPoint
-  
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
-
-  TVector3 vecEmc ;
-  emcrp->GetLocalPosition(vecEmc) ;
-  
-  TVector3 vecPpsd ;
-  if ( ppsdlrp !=0 ) {
-    if( ppsdlrp->GetMultiplicity() )  
-      ppsdlrp->GetLocalPosition(vecPpsd)  ; 
-    else { 
-      vecPpsd.SetX(10000.) ;
-    } 
-    vecEmc -= vecPpsd ;
-  }
-  Float_t r = vecEmc.Mag();;
-
-  return r ;
-}
-
-//____________________________________________________________________________
-AliPHOSEmcRecPoint * AliPHOSTrackSegment::GetEmcRecPoint() const 
-{
-  // get the EMC recpoint at the origin of this track
-  AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
-  AliPHOSEmcRecPoint * rv = 0 ;
-  if (  fEmcRecPoint > -1 )
-    rv = (AliPHOSEmcRecPoint *)please->GimeRecPoint( fEmcRecPoint, TString("emc") );
-  
-  return rv ;
-
-}
-  
-//____________________________________________________________________________
- Float_t AliPHOSTrackSegment::GetEnergy()
-{ 
-  // Returns energy in EMC
-  
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  
-  return emcrp->GetEnergy() ;
-}   
-
-//____________________________________________________________________________
-TVector3 AliPHOSTrackSegment::GetMomentumDirection() 
-{ 
-  // Calculates the momentum direction:
-  //   1. if only a EMC RecPoint, direction is given by IP and this RecPoint
-  //   2. if a EMC RecPoint and one PPSD RecPoint, direction is given by the line through the 2 recpoints 
-  //   3. if a EMC RecPoint and two PPSD RecPoints, dirrection is given by the average line through 
-  //      the 2 pairs of recpoints  
-  // However because of the poor position resolution of PPSD the direction is always taken as if we were 
-  //  in case 1.
-
-
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  // AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
-  // AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
-
-  TVector3 dir(0,0,0) ; 
-  TMatrix mdummy ;
-
-  TVector3 posEmc ;
-  emcrp->GetGlobalPosition(posEmc, mdummy) ;
-  TVector3 emcglobalpos ;
-  TMatrix  dummy ;
-
-  emcrp->GetGlobalPosition(emcglobalpos, dummy) ;
-
-  
-// The following commeneted code becomes valid once the PPSD provides 
-// a reasonable position resolution, at least as good as EMC ! 
-//   TVector3 ppsdlglobalpos ;
-//   TVector3 ppsduglobalpos ;
-//   if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
-//     fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ; 
-//     dir = emcglobalpos -  ppsdlglobalpos ; 
-//     if( fPpsdUpRecPoint ){ // not looks like a charged       
-//        fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ; 
-//        dir = ( dir +  emcglobalpos -  ppsduglobalpos ) * 0.5 ; 
-//      }
-//   }
-//   else { // looks like a neutral
-//    dir = emcglobalpos ;  
-//  }
-
-  dir = emcglobalpos ;  
-  dir.SetZ( -dir.Z() ) ;   // why ?  
-  dir.SetMag(1.) ;
-    
-  return dir ;  
-}
-
-//____________________________________________________________________________
-Int_t AliPHOSTrackSegment:: GetPHOSMod(void) 
-{
-  // Returns the phos module which contains this track
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  
-  return emcrp->GetPHOSMod();  
-}
-
-//____________________________________________________________________________
-AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdLowRecPoint() const 
-{
-  // Returns the lower PPSD rec point at the origin of this track
-  
-  AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
-  AliPHOSPpsdRecPoint * rv = 0 ;
-  
-  if ( fPpsdLowRecPoint > -1 )
-    rv = (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdLowRecPoint, TString("ppsd") ) ;
-  
-  return rv ; 
-}
-
-//____________________________________________________________________________
-AliPHOSPpsdRecPoint * AliPHOSTrackSegment::GetPpsdUpRecPoint() const 
-{
-  // Returns the lower PPSD rec point at the origin of this track
-
-  AliPHOSIndexToObject * please =  AliPHOSIndexToObject::GetInstance() ;
-  AliPHOSPpsdRecPoint * rv = 0 ;
-  if ( fPpsdUpRecPoint > -1 )
-    rv =  (AliPHOSPpsdRecPoint *)please->GimeRecPoint( fPpsdUpRecPoint, TString("ppsd") ) ;
-
-  return rv ;
-}
-
-//____________________________________________________________________________
-Int_t *  AliPHOSTrackSegment::GetPrimariesEmc(Int_t & number) 
-{ 
-  // Retrieves the primary particle(s) at the origin of the EMC RecPoint
-    
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-
-  Int_t * rv = 0 ; 
-  number = 0 ;
-  if ( emcrp )
-    rv =  emcrp->GetPrimaries(number) ; 
-
-  return rv ; 
-}
-
-//____________________________________________________________________________
-Int_t *  AliPHOSTrackSegment::GetPrimariesPpsdLow(Int_t & number) 
-{ 
-  // Retrieves the primary particle(s) at the origin of the lower PPSD RecPoint
-  
-  AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
-
-  Int_t * rv = 0 ; 
-  number = 0 ;
-  if ( ppsdlrp )
-    rv =  ppsdlrp->GetPrimaries(number) ; 
-
-  return rv ; 
-}
-
-//____________________________________________________________________________
-Int_t *  AliPHOSTrackSegment::GetPrimariesPpsdUp(Int_t & number) 
-{ 
-  // Retrieves the primary particle(s) at the origin of the upper PPSD  RecPoint
-  
-  AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
-
-  Int_t * rv = 0 ; 
-  number = 0 ;
-  if ( ppsdurp )
-    rv =  ppsdurp->GetPrimaries(number) ; 
-
-  return rv ; 
-}
 
 //____________________________________________________________________________
-void AliPHOSTrackSegment::GetPosition( TVector3 & pos ) 
-{  
-  // Returns position of the EMC RecPoint
-  
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  TMatrix dummy ;
-  emcrp->GetGlobalPosition(pos, dummy) ;
-}
-
-
-//______________________________________________________________________________
-void AliPHOSTrackSegment::Paint(Option_t *)
-{
-  // Paint this AliPHOSTrackSegment as a TMarker  with its current attributes
-
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
-  AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
-
-  TVector3 posemc(999., 999., 999.) ;
-  TVector3 posppsdl(999., 999., 999.) ;
-  TVector3 posppsdu(999., 999., 999.) ;
-  
-  emcrp->GetLocalPosition(posemc) ;
-  if (ppsdlrp !=0 ) 
-    ppsdlrp->GetLocalPosition(posppsdl) ;
-  if (ppsdurp !=0 ) 
-    ppsdurp->GetLocalPosition(posppsdu) ;
-  
-  Coord_t xemc   = posemc.X() ;
-  Coord_t yemc   = posemc.Z() ;
-  
-  Coord_t yppsdl = posppsdl.Z() ;
-  Coord_t xppsdl = posppsdl.X() ;
-  
-  Coord_t yppsdu = posppsdu.Z() ;
-  Coord_t xppsdu = posppsdu.X() ;
-  
-  Color_t markercolor = 1 ;
-  Size_t  markersize  = 1.5 ;
-  Style_t markerstyle = 20 ;
-  
-  if (!gPad->IsBatch()) {
-    gVirtualX->SetMarkerColor(markercolor) ;
-    gVirtualX->SetMarkerSize (markersize)  ;
-    gVirtualX->SetMarkerStyle(markerstyle) ;
-  }
-  gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
-  gPad->PaintPolyMarker(1, &xemc, &yemc, "") ;
-  
-  if (xppsdl != 999. && yppsdl != 999. ) {
-    
-    markercolor = 2 ;
-    markersize  = 1.25 ;
-    markerstyle = 21 ;
-    
-    if (!gPad->IsBatch()) {
-      gVirtualX->SetMarkerColor(markercolor) ;
-      gVirtualX->SetMarkerSize (markersize)  ;
-      gVirtualX->SetMarkerStyle(markerstyle) ;
-    }
-    gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
-    gPad->PaintPolyMarker(1, &xppsdl, &yppsdl, "") ;
-  }
-  
-  if (xppsdu != 999. && yppsdu != 999. ) {
-    
-    markercolor = 3 ;
-    markersize  = 1. ;
-    markerstyle = 22 ;
-    
-    if (!gPad->IsBatch()) {
-      gVirtualX->SetMarkerColor(markercolor) ;
-      gVirtualX->SetMarkerSize (markersize)  ;
-      gVirtualX->SetMarkerStyle(markerstyle) ;
-    }
-    gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
-    gPad->PaintPolyMarker(1, &xppsdu, &yppsdu, "") ;
-  }
-}
-
-//____________________________________________________________________________
-void AliPHOSTrackSegment::Print(const char * opt)
+void AliPHOSTrackSegment::Print(Option_t * opt)
 {
   // Print all information on this track Segment
   
-  AliPHOSEmcRecPoint  * emcrp   = GetEmcRecPoint() ; 
-  AliPHOSPpsdRecPoint * ppsdlrp = GetPpsdLowRecPoint() ; 
-  AliPHOSPpsdRecPoint * ppsdurp = GetPpsdUpRecPoint() ; 
-  
-  TVector3 pos ;
-  TMatrix dummy ;  
 
   cout << "--------AliPHOSTrackSegment-------- "<<endl ;
+  cout << "Stored at position " << fIndexInList << endl ;
+  cout << "Emc RecPoint #     " << fEmcRecPoint << endl ;
+  if(fPpsdUpRecPoint >= 0)
+    cout << "CPV RecPoint #      " << fPpsdUpRecPoint << endl ;
+  else
+    cout << "No CPV RecPoint " << endl ;
 
-  if ( emcrp != 0 ) {
-    cout << "******** EMC Reconstructed Point: " << endl;
-    emcrp->Print() ; 
-    
-    emcrp->GetGlobalPosition( pos, dummy ) ;
-    
-    cout << " Global position " << pos.X() << "   " << pos.Y() << "  " << pos.Z() << "      Energy " << emcrp->GetEnergy() << endl ;
-  }
+  if(fPpsdLowRecPoint >= 0)
+    cout << "PPSD RecPoint #     " << fPpsdLowRecPoint << endl ;
+  else
+    cout << "No PPSD RecPoint " << endl ;
+  
+  cout << "------------------------------------ " << endl ; 
   
-  if ( ppsdlrp != 0 ) {
-    cout << "******** PPSD Low Reconstructed Point: " << endl;
-    
-    ppsdlrp->Print() ; 
-    ppsdlrp->GetGlobalPosition( pos , dummy ) ;
-    cout << "    position " << pos.X() << "   " << pos.Y() << "  " << pos.Z() << endl ;
-  }
-
-   if( ppsdurp != 0 ) {
-     cout << "******** PPSD Up Reconstructed Point: " << endl;
-     
-     ppsdurp->Print() ; 
-     ppsdurp->GetGlobalPosition( pos, dummy ) ;
-     cout << "    position " << pos.X() << "   " << pos.Y() << "  " << pos.Z()  << endl ;
-   }
-   
 }
 //____________________________________________________________________________
-void AliPHOSTrackSegment::SetPpsdUpRecPoint(AliPHOSPpsdRecPoint * PpsdUpRecPoint) 
+void AliPHOSTrackSegment::SetCpvRecPoint(AliPHOSRecPoint * PpsdUpRecPoint) 
 {
   // gives an id from its position in the list
   if( PpsdUpRecPoint )  
index f8bb7b73bee2e7d89bbe3bfff7ff980108dc6e33..bb0df8428c6f6922d9d6180ad335d8cefd507e02 100644 (file)
 // --- ROOT system ---
 
 #include "TObject.h"
-#include "TVector3.h"
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
 
 #include "AliPHOSEmcRecPoint.h"
-#include "AliPHOSPpsdRecPoint.h"
+#include "AliPHOSRecPoint.h"
 
 class AliPHOSTrackSegment : public TObject  {
 
 public:
 
-  AliPHOSTrackSegment() {
-    // default ctor
-  } 
+  AliPHOSTrackSegment() {} 
   AliPHOSTrackSegment(AliPHOSEmcRecPoint * EmcRecPoint , 
-                     AliPHOSPpsdRecPoint * PpsdUp, 
-                     AliPHOSPpsdRecPoint * PpsdLow  ) ; // ctor
+                     AliPHOSRecPoint * PpsdUp, 
+                     AliPHOSRecPoint * PpsdLow  ) ; // ctor
   AliPHOSTrackSegment(const AliPHOSTrackSegment & ts) ;  // ctor                   
-  virtual ~AliPHOSTrackSegment() {
-    // dtor
-  } 
+  virtual ~AliPHOSTrackSegment() {  } 
 
   void Copy(TObject & obj) ;  
-  virtual Int_t  DistancetoPrimitive(Int_t px, Int_t py);
-  virtual void   Draw(Option_t * option="") ;
-  virtual void   ExecuteEvent(Int_t event, Int_t px, Int_t py);
-  Float_t GetEnergy() ;   // Returns energy in EMC
-  
-  Float_t GetDistanceInPHOSPlane(void) ;   // Computes in PHOS plane the relative position between EMC and PPSD clusters 
-  virtual Int_t  GetPHOSMod(void) ; 
-  TVector3 GetMomentumDirection() ;        // Returns the momentum direction
-  void    GetPosition( TVector3 & pos ) ;  // Returns positions of hit
-  Int_t * GetPrimariesEmc(Int_t & number) ;
-  Int_t * GetPrimariesPpsdLow(Int_t & number) ;
-  Int_t * GetPrimariesPpsdUp(Int_t & number) ;
-  AliPHOSEmcRecPoint *   GetEmcRecPoint() const ;  
-  Int_t   GetIndexInList() const { 
-    // returns the index of this in the list  
-    return fIndexInList ; 
-  } 
-  Int_t                   GetEmcRecPointIndex() {
-    // return the index of the EMC recpoint at the origine of this 
-    return fEmcRecPoint ; 
-  }
-  AliPHOSPpsdRecPoint *  GetPpsdLowRecPoint() const ;
-  Int_t                  GetPpsdLowRecPointIndex() {
-    // returns the PPSD low recpoint at the origin of this 
-    return fPpsdLowRecPoint ; 
-  }
-  AliPHOSPpsdRecPoint *  GetPpsdUpRecPoint() const ; 
-  Int_t                  GetPpsdUpRecPointIndex() {
-    // returns the PPSD up recpoint at the origin of this 
-    return fPpsdUpRecPoint ; 
-  }
-  virtual void  Paint(Option_t * option="");
-  virtual void  Print(const char *) ;
-  void    SetIndexInList(Int_t val) { 
-    // sets the index value  of this in the list 
-    fIndexInList = val ; 
-  } 
-  void    SetPpsdUpRecPoint(AliPHOSPpsdRecPoint * PpsdUpRecPoint ); //sets PPSD up Rec Point
+
+  Int_t   GetIndexInList() const {    return fIndexInList ;   } 
+  Int_t   GetEmcIndex()const {  return fEmcRecPoint ;   }
+  Int_t   GetPpsdIndex()const{  return fPpsdLowRecPoint;}
+  Int_t   GetCpvIndex()const {  return fPpsdUpRecPoint; }
+
+  virtual void  Print(Option_t * option) ;
+  void    SetIndexInList(Int_t val){ fIndexInList = val ;     } 
+  void    SetCpvRecPoint(AliPHOSRecPoint * PpsdUpRecPoint ); //sets PPSD up Rec Point
 
   typedef TClonesArray TrackSegmentsList ; 
  
index 44f11661b14e93f6604562426afe523c5a4e56ee..34a900189f1c875e70ddd3f6110fdd205dbe2104 100644 (file)
 
 // --- ROOT system ---
 
-#include "TObjArray.h"
-#include "TClonesArray.h"
+#include "TFile.h"
+#include "TROOT.h"
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
-
-#include "AliPHOSTrackSegmentMaker.h"
-#include "AliPHOSTrackSegment.h"
-#include "AliPHOSIndexToObject.h"
-#include "AliPHOSLink.h"
-#include "AliPHOSv0.h"
 #include "AliRun.h"
+#include "AliPHOSTrackSegmentMaker.h"
+#include "AliPHOS.h"
+#include "AliPHOSGeometry.h"
 
 ClassImp( AliPHOSTrackSegmentMaker) 
 
 
 //____________________________________________________________________________
- AliPHOSTrackSegmentMaker:: AliPHOSTrackSegmentMaker() : fNTrackSegments(0)
+ AliPHOSTrackSegmentMaker:: AliPHOSTrackSegmentMaker() : TTask()
 {
-  // ctor
-  fGeom = AliPHOSGeometry::GetInstance() ;
-  fPlease = AliPHOSIndexToObject::GetInstance() ; 
-
 }
+//____________________________________________________________________________
+AliPHOSTrackSegmentMaker::AliPHOSTrackSegmentMaker(char * header,char * branch): TTask("AliPHOSTrackSegmentMaker","")
+{
 
 
+}
+
index 0642ce2f16da49e4c524031a82a38f77d945d292..9b23bbaeb82742fe07c2510b680d506dc866e46c 100644 (file)
 // Associates EMC and PPSD clusters
 // Unfolds the EMC cluster   
 //                  
-//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
+//*-- Author: Dmitri Peressounko (RRC Kurchatov Institute  & SUBATECH)
 
 // --- ROOT system ---
+#include "TTask.h"
+
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
 
-#include "TObjArray.h"
-#include "AliPHOSDigit.h"
-#include "AliPHOSRecPoint.h"
-#include "AliPHOSIndexToObject.h"
-#include "AliPHOSTrackSegment.h"
 
-class  AliPHOSTrackSegmentMaker : public TObject {
+class AliPHOSClusterizer ;
+class AliPHOSGeometry ;
+
+class  AliPHOSTrackSegmentMaker : public TTask {
 
 public:
 
   AliPHOSTrackSegmentMaker() ;                     
+  AliPHOSTrackSegmentMaker(char* headerFile, char* branchTitle = 0) ;                     
   
   virtual ~ AliPHOSTrackSegmentMaker(){
     // dtor 
   } 
 
-  virtual void MakeTrackSegments(DigitsList * DL, 
-                                AliPHOSRecPoint::RecPointsList * emcl, 
-                                AliPHOSRecPoint::RecPointsList * ppsdl,
-                                AliPHOSTrackSegment::TrackSegmentsList * trsl ) = 0 ; // does the job
-  virtual void SetMaxEmcPpsdDistance(Float_t r) = 0 ; 
-  virtual void SetUnfoldFlag() = 0 ;
-  virtual void UnsetUnfoldFlag() = 0 ;
+  virtual void    Exec(Option_t * option) = 0 ;
+  virtual char*   GetRecPointsBranch ()const = 0 ;
+  virtual char*   GetTrackSegmentsBranch ()const = 0 ;
+
+  virtual void    Print(Option_t * option)const = 0;
+  //  virtual void Set...   // method to choose recPoints: along z only, along x ...???
+  //  virtual void SetChoosingAlgirithm() = 0 ;
+  //  virtual void SetMaxEmcCpvDistance(Float_t r) = 0 ; 
+  virtual Bool_t ReadRecPoints() = 0 ; 
+  virtual void SetRecPointsBranch(const char * title) = 0 ;
+  virtual void SetTrackSegmentsBranch(const char * title) = 0 ;
+  virtual void WriteTrackSegments() = 0 ;
   
  protected:
-  
-  Int_t                  fNTrackSegments ; // number of track segments found 
-  AliPHOSGeometry      * fGeom ;           // pointer to PHOS geometry  
-  AliPHOSIndexToObject * fPlease ;         // factory used to convert an index into the associated object
 
   ClassDef( AliPHOSTrackSegmentMaker,1)    // Algorithm class to make PHOS track segments (Base Class)
 
index f430c923caaf5625f43a783952183f6ee0a0c777..50a1c9c1cbfb314617ce867bef3e379fad96d53a 100644 (file)
 //
 
 // --- ROOT system ---
-
-#include "TObjArray.h"
-#include "TClonesArray.h"
-#include "TObjectTable.h"
-
+#include "TROOT.h"
+#include "TFile.h"
+#include "TTree.h"
+#include "TSystem.h"
+#include "TBenchmark.h"
 // --- Standard library ---
 
 #include <iostream.h>
+#include <iomanip.h>
 
 // --- AliRoot header files ---
 
 #include "AliPHOSTrackSegmentMakerv1.h"
-#include "AliPHOSIndexToObject.h"
+#include "AliPHOSClusterizerv1.h"
 #include "AliPHOSTrackSegment.h"
 #include "AliPHOSCpvRecPoint.h"
+#include "AliPHOSPpsdRecPoint.h"
 #include "AliPHOSLink.h"
 #include "AliPHOSv0.h"
 #include "AliRun.h"
 
-extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ; 
-
 ClassImp( AliPHOSTrackSegmentMakerv1) 
 
 
@@ -50,181 +50,165 @@ ClassImp( AliPHOSTrackSegmentMakerv1)
  AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
 {
   // ctor
-
+  SetTitle("version 1") ;
+  SetName("AliPHOSTrackSegmentMaker") ;
   fR0 = 10. ;   
-  //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
-  fDelta = fR0 + fGeom->GetCrystalSize(0) ;
-  if(!gMinuit) gMinuit = new TMinuit(100) ;
-  fUnfoldFlag = kTRUE ; 
+  fEmcFirst = 0 ;    
+  fEmcLast  = 0 ;   
+  fCpvFirst = 0 ;   
+  fCpvLast  = 0 ;   
+  fPpsdFirst= 0 ;   
+  fPpsdLast = 0 ;   
+  fLinkLowArray = 0 ;
+  fLinkUpArray  = 0 ;
+  fIsInitialized = kFALSE ;
 }
-
 //____________________________________________________________________________
- AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
-{ 
-  // dtor
-}
+ AliPHOSTrackSegmentMakerv1::  AliPHOSTrackSegmentMakerv1(const char* headerFile, const char* branchTitle): AliPHOSTrackSegmentMaker()
+{
+  // ctor
+  SetTitle("version 1") ;
+  SetName("AliPHOSTrackSegmentMaker") ;
+  fR0 = 10. ;   
+  fEmcFirst = 0 ;    
+  fEmcLast  = 0 ;   
+  fCpvFirst = 0 ;   
+  fCpvLast  = 0 ;   
+  fPpsdFirst= 0 ;   
+  fPpsdLast = 0 ;   
+
+  fHeaderFileName = headerFile ;
+  fRecPointsBranchTitle = branchTitle ;
+    
+  TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
+  
+  if(file == 0){
+    file = new TFile(fHeaderFileName.Data(),"update") ;
+    gAlice = (AliRun *) file->Get("gAlice") ;
+  }
+  
+  AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;    
+  fGeom  = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
+  
+  fEmcRecPoints = new TObjArray(200) ;
+  fCpvRecPoints = new TObjArray(200) ;
+  fClusterizer  = new AliPHOSClusterizerv1() ;
+  
+  fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
+  
+  fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
+  fLinkUpArray  = new TClonesArray("AliPHOSLink", 1000); 
+  
+  fIsInitialized = kTRUE ;
 
+}
 //____________________________________________________________________________
-Bool_t  AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
-                                   Int_t nPar, Float_t * fitparameters)
-{ 
-  // Calls TMinuit to fit the energy distribution of a cluster with several maxima 
-
-  gMinuit->mncler();                     // Reset Minuit list of paramters
-  gMinuit->SetPrintLevel(-1) ;           // No Printout
-  gMinuit->SetFCN(UnfoldingChiSquare) ;  // To set the address of the minimization function 
-  gMinuit->SetObjectFit(emcRP) ;         // To tranfer pointer to UnfoldingChiSquare
+void  AliPHOSTrackSegmentMakerv1::Init(){
 
-  // filling initial values for fit parameters
-  AliPHOSDigit * digit ;
-
-  Int_t ierflg  = 0; 
-  Int_t index   = 0 ;
-  Int_t nDigits = (Int_t) nPar / 3 ;
-
-  Int_t iDigit ;
-
-
-  for(iDigit = 0; iDigit < nDigits; iDigit++){
-    digit = (AliPHOSDigit *) maxAt[iDigit]; 
-
-    Int_t relid[4] ;
-    Float_t x ;
-    Float_t z ;
-    fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
-    fGeom->RelPosInModule(relid, x, z) ;
-
-    Float_t energy = maxAtEnergy[iDigit] ;
-
-    gMinuit->mnparm(index, "x",  x, 0.1, 0, 0, ierflg) ;
-    index++ ;   
-    if(ierflg != 0){ 
-      cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : x = " << x << endl ;
-      return kFALSE;
-    }
-    gMinuit->mnparm(index, "z",  z, 0.1, 0, 0, ierflg) ;
-    index++ ;   
-    if(ierflg != 0){
-      cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : z = " << z << endl ;
-      return kFALSE;
-    }
-    gMinuit->mnparm(index, "Energy",  energy , 0.05*energy, 0., 4.*energy, ierflg) ;
-    index++ ;   
-    if(ierflg != 0){
-      cout << "PHOS Unfolding>  Unable to set initial value for fit procedure : energy = " << energy << endl ;      
-      return kFALSE;
+  if(!fIsInitialized){
+    if(fHeaderFileName.IsNull())
+      fHeaderFileName = "galice.root" ;
+    
+    
+    TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
+    
+    if(file == 0){
+      file = new TFile(fHeaderFileName.Data(),"update") ;
+      gAlice = (AliRun *) file->Get("gAlice") ;
     }
-  }
+    
+    AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;    
+    fGeom  = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
 
-  Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
-                      //  depends on it. 
-  Double_t p1 = 1.0 ;
-  Double_t p2 = 0.0 ;
 
-  gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ;   // force TMinuit to reduce function calls  
-  gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ;   // force TMinuit to use my gradient  
-  gMinuit->SetMaxIterations(5);
-  gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ;  // No Warnings
+    fEmcRecPoints = new TObjArray(200) ;
+    fCpvRecPoints = new TObjArray(200) ;
+    fClusterizer  = new AliPHOSClusterizerv1() ;
 
-  gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ;    // minimize 
+    
+    fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
 
-  if(ierflg == 4){  // Minimum not found   
-    cout << "PHOS Unfolding>  Fit not converged, cluster abandoned "<< endl ;      
-    return kFALSE ;
-  }            
-  for(index = 0; index < nPar; index++){
-    Double_t err ;
-    Double_t val ;
-    gMinuit->GetParameter(index, val, err) ;    // Returns value and error of parameter index
-    fitparameters[index] = val ;
+    fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
+    fLinkUpArray  = new TClonesArray("AliPHOSLink", 1000); 
+    
+    fIsInitialized = kTRUE ;
    }
+}
 
-  return kTRUE;
-
+//____________________________________________________________________________
+ AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
+{ 
+  // dtor
+  if(fLinkLowArray) delete fLinkLowArray ;
+  if(fLinkUpArray)  delete fLinkUpArray  ;
 }
 
 //____________________________________________________________________________
-void  AliPHOSTrackSegmentMakerv1::FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn, 
-                                               TArrayI * emcOut, 
-                                               AliPHOSRecPoint::RecPointsList * ppsdIn, 
-                                               TArrayI * ppsdOutUp,
-                                               TArrayI * ppsdOutLow, 
-                                               Int_t & phosmod, 
-                                               Int_t & emcStopedAt, 
-                                               Int_t & ppsdStopedAt)
+void  AliPHOSTrackSegmentMakerv1::FillOneModule()
 {
-  // Fill xxxOut arrays with clusters from one PHOS module
+  // Finds bounds in which clusters from one PHOS module are
  
-  AliPHOSEmcRecPoint *  emcRecPoint  ; 
-  AliPHOSPpsdRecPoint * ppsdRecPoint ;
-  Int_t index ;
+
+  //First EMC clusters
+  Int_t totalEmc = fEmcRecPoints->GetEntriesFast() ;
+  for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&  
+       (((AliPHOSRecPoint *) fEmcRecPoints->At(fEmcLast))->GetPHOSMod() == fModule ); 
+      fEmcLast ++)  ;
+  
   
-  Int_t nEmcUnfolded = emcIn->GetEntries() ;
-  emcOut->Set(nEmcUnfolded);
-  Int_t inEmcOut = 0 ;
-  for(index = emcStopedAt; index < nEmcUnfolded; index++){
+  //Now CPV clusters
+  Int_t totalCpv = fCpvRecPoints->GetEntriesFast() ;
 
-    emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
+  if(fModule <= fGeom->GetNCPVModules()){ // in CPV geometry
     
-    if(emcRecPoint->GetPHOSMod() != phosmod )  
-      break ;
+    for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) && 
+         (((AliPHOSRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule ); 
+       fCpvLast ++) ;
     
-    emcOut->AddAt(emcRecPoint->GetIndexInList(),inEmcOut) ;
-    inEmcOut++ ; 
+    fPpsdFirst = fCpvLast ; //To avoid scanning RecPoints between fPpsdFirst and fPpsdLast
+    fPpsdLast  = fCpvLast ; //and to be ready to switch to mixed geometry 
   }
-  emcOut->Set(inEmcOut) ;
-
-  emcStopedAt = index ;
-
-  ppsdOutLow->Set(ppsdIn->GetEntries()) ;
-  ppsdOutUp->Set(ppsdIn->GetEntries()) ;
-  Int_t inPpsdLow = 0;
-  Int_t inPpsdUp = 0;
-  for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
-    ppsdRecPoint = (AliPHOSPpsdRecPoint *) ppsdIn->At(index) ;
-    if(ppsdRecPoint->GetPHOSMod() != phosmod )   
-      break ;
-    if(phosmod <= fGeom->GetNCPVModules())   //in CPV
-      ppsdOutUp->AddAt(index,inPpsdUp++) ;
-    else{                                   //in PPSD
-      if(ppsdRecPoint->GetUp() ) 
-       ppsdOutUp->AddAt(index,inPpsdUp++) ;
-      else  
-       ppsdOutLow->AddAt(index,inPpsdLow++) ;
-    }
+  else{  //in PPSD geometry    
+    fCpvLast = fPpsdLast ;
+    //Upper layer first
+    for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&  
+         (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule ) &&
+         (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetUp()) ; 
+       fCpvLast ++)  ;
+    
+    fPpsdLast= fCpvLast ;
+    for(fPpsdFirst = fPpsdLast; (fPpsdLast < totalCpv)  &&
+         (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetPHOSMod() == fModule ) &&
+         (!((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetUp()) ; 
+       fPpsdLast ++) ;
   }
-  ppsdOutLow->Set(inPpsdLow);
-  ppsdOutUp->Set(inPpsdUp);
-  ppsdStopedAt = index ;
-   
+    
 }
 //____________________________________________________________________________
-Float_t  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
+Float_t  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)
 {
   // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
+  //clusters are sorted in "rows" and "columns" of width 1 cm
+  Float_t delta = 1 ;  // Width of the rows in sorting of RecPoints (in cm)
+                       // if you change this value, change it as well in xxxRecPoint::Compare()
   Float_t r = fR0 ;
  
   TVector3 vecEmc ;
-  TVector3 vecPpsd ;
-  
-  emcclu->GetLocalPosition(vecEmc) ;
-  PpsdClu->GetLocalPosition(vecPpsd)  ; 
-  if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){ 
-    //    if(vecPpsd.X() >= vecEmc.X() - fDelta ){ 
-    //  if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
-       // Correct to difference in CPV and EMC position due to different distance to center.
-       // we assume, that particle moves from center
-       Float_t dCPV = fGeom->GetIPtoOuterCoverDistance();
-       Float_t dEMC = fGeom->GetIPtoCrystalSurface() ;
-       dEMC         = dEMC / dCPV ;
-        vecPpsd = dEMC * vecPpsd  - vecEmc ; 
-        r = vecPpsd.Mag() ;
-       //    } // if  zPpsd >= zEmc - fDelta
+  TVector3 vecCpv ;
+  
+  emcClu->GetLocalPosition(vecEmc) ;
+  cpvClu->GetLocalPosition(vecCpv)  ; 
+
+  if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){ 
+    if(vecCpv.X() <= vecEmc.X() + fR0 + 2*delta ){ 
+
+      vecCpv = vecCpv  - vecEmc ; 
+      r = vecCpv.Mag() ;
       toofar = kFALSE ;
-      //} // if  xPpsd >= xEmc - fDelta
-      // else 
-      //toofar = kTRUE ;
+
+    } // if  xPpsd >= xEmc + ...
+    else 
+      toofar = kTRUE ;
   } 
   else 
     toofar = kTRUE ;
@@ -236,482 +220,408 @@ Float_t  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint *
 }
 
 //____________________________________________________________________________
-void  AliPHOSTrackSegmentMakerv1::MakeLinks(TArrayI * emcRecPoints, TArrayI * ppsdRecPointsUp, 
-                                    TArrayI * ppsdRecPointsLow, TClonesArray * linklowArray, 
-                                    TClonesArray *linkupArray) 
+void  AliPHOSTrackSegmentMakerv1::MakeLinks()
 { 
   // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0 
   
-  
-  AliPHOSPpsdRecPoint * ppsdlow ; 
-  AliPHOSPpsdRecPoint * ppsdup ;
+  fLinkUpArray->Clear() ;    
+  fLinkLowArray->Clear() ;
+
+  AliPHOSRecPoint * ppsd ; 
+  AliPHOSRecPoint * cpv ;
   AliPHOSEmcRecPoint * emcclu ;
 
   Int_t iLinkLow = 0 ;
   Int_t iLinkUp  = 0 ;
   
   Int_t iEmcRP;
-  
-  for(iEmcRP = 0; iEmcRP < emcRecPoints->GetSize(); iEmcRP++ ) {
-    emcclu = (AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emcRecPoints->At(iEmcRP),"emc") ;
-    Bool_t toofar ;
-    
-    Int_t iPpsdLow ;
-    
-    for(iPpsdLow = 0; iPpsdLow < ppsdRecPointsLow->GetSize();iPpsdLow++ ) {
-      
-      ppsdlow = (AliPHOSPpsdRecPoint *) fPlease->GimeRecPoint(ppsdRecPointsLow->At(iPpsdLow),"ppsd") ;
-      Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ;
+  for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
+    emcclu = (AliPHOSEmcRecPoint *) fEmcRecPoints->At(iEmcRP) ;
+
+    Bool_t toofar ;    
+    Int_t iPpsd ;
+    for(iPpsd = fPpsdFirst; iPpsd < fPpsdLast;iPpsd++ ) {
       
+      ppsd = (AliPHOSRecPoint *) fCpvRecPoints->At(iPpsd) ;
+      Float_t r = GetDistanceInPHOSPlane(emcclu, ppsd, toofar) ;
+
       if(toofar) 
        break ;  
-      if(r < fR0){
-       new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcRP, iPpsdLow) ;
-      }
+      if(r < fR0)
+       new ((*fLinkLowArray)[iLinkLow++])  AliPHOSLink(r, iEmcRP, iPpsd) ;
     }
     
-    Int_t iPpsdUp = 0 ;    
-    for(iPpsdUp = 0; iPpsdUp < ppsdRecPointsUp->GetSize();iPpsdUp++ ) { 
+    Int_t iCpv = 0 ;    
+    for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) { 
       
-      ppsdup = (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdRecPointsUp->At(iPpsdUp),"ppsd") ;
-      Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ;
+      cpv = (AliPHOSRecPoint *) fCpvRecPoints->At(iCpv) ;
+      Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
       
       if(toofar)
        break ;  
       if(r < fR0) { 
-       new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iPpsdUp) ;
+       new ((*fLinkUpArray)[iLinkUp++])  AliPHOSLink(r, iEmcRP, iCpv) ;
       }      
     }
   } 
   
-  linklowArray->Sort() ; //first links with smallest distances
-  linkupArray->Sort() ;
+  fLinkLowArray->Sort() ; //first links with smallest distances
+  fLinkUpArray->Sort() ;
 }
 
 //____________________________________________________________________________
-void  AliPHOSTrackSegmentMakerv1::MakePairs(TArrayI * emcRecPoints, 
-                                           TArrayI * ppsdRecPointsUp, 
-                                           TArrayI * ppsdRecPointsLow, 
-                                           TClonesArray * linklowArray, 
-                                           TClonesArray * linkupArray, 
-                                           AliPHOSTrackSegment::TrackSegmentsList * trsl) 
+void  AliPHOSTrackSegmentMakerv1::MakePairs()
 { 
-
-  // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance 
   
-  TIter nextLow(linklowArray) ;
-  TIter nextUp(linkupArray) ;
+  //Make arrays to mark clusters already chousen
+  Int_t * emcExist = 0;
+  if(fEmcLast > fEmcFirst)
+    emcExist = new Int_t[fEmcLast-fEmcFirst] ;
+  
+  Int_t index;
+  for(index = 0; index <fEmcLast-fEmcFirst; index ++)
+    emcExist[index] = 1 ;
+  
+  Bool_t * cpvExist = 0;
+  if(fCpvLast > fCpvFirst)
+    cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
+  for(index = 0; index <fCpvLast-fCpvFirst; index ++)
+    cpvExist[index] = kTRUE ;
+  
+  Bool_t * ppsdExist = 0;
+  if(fPpsdLast > fPpsdFirst)
+    ppsdExist = new Bool_t[fPpsdLast-fPpsdFirst] ;
+  for(index = 0; index <fPpsdLast-fPpsdFirst; index ++)
+    ppsdExist[index] = kTRUE ;
+  
+  // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance 
+  TIter nextLow(fLinkLowArray) ;
+  TIter nextUp(fLinkUpArray) ;
   
   AliPHOSLink * linkLow ;
   AliPHOSLink * linkUp ;
 
-  Int_t emc ;
-  Int_t ppsdLow ;
-  Int_t ppsdUp ;
 
-  AliPHOSPpsdRecPoint * nullpointer = 0 ;
-  ppsdUp = 0 ;
+  AliPHOSRecPoint * nullpointer = 0 ;
 
   while ( (linkLow =  (AliPHOSLink *)nextLow() ) ){
   
-    emc = emcRecPoints->At(linkLow->GetEmc()) ;
-    ppsdLow = ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
-
-    if( (emc >= 0) && (ppsdLow >= 0) ){    // RecPoints not removed yet 
-      
-      new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fPlease->GimeRecPoint(emc,"emc"), 
-                                                         nullpointer, 
-                                                         (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdLow,"ppsd") ) ;
-      ((AliPHOSTrackSegment* )trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);    
+    if( (emcExist[linkLow->GetEmc()-fEmcFirst]> 0) && ppsdExist[linkLow->GetPpsd()-fPpsdFirst]  ){ // RecPoints not removed yet 
+      new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkLow->GetEmc()), 
+                                                nullpointer, 
+                                               (AliPHOSPpsdRecPoint *)fCpvRecPoints->At(linkLow->GetPpsd()) ) ;
+        
+      ((AliPHOSTrackSegment* )fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);    
       //replace index of emc to negative and shifted index of TS      
-      emcRecPoints->AddAt(-2 - fNTrackSegments,linkLow->GetEmc()) ;  
-      //replace index of PPSD Low to negative and shifted index of TS      
-      ppsdRecPointsLow->AddAt(-2 - fNTrackSegments,linkLow->GetPpsd()) ; 
+      emcExist[linkLow->GetEmc()-fEmcFirst] = -2 - fNTrackSegments ;  
+      //mark ppsd as used
+      ppsdExist[linkLow->GetPpsd()-fPpsdFirst] = kFALSE ; 
       fNTrackSegments++ ;
-
     } 
   } 
         
+
   while ( (linkUp =  (AliPHOSLink *)nextUp() ) ){  
-    emc = emcRecPoints->At(linkUp->GetEmc()) ;
-    if(emc != -1){ //without ppsd Up yet 
+    if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet 
 
-      ppsdUp = ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
-      if(ppsdUp >= 0){ //ppsdUp still exist
+      if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
        
-       if(emc >= 0){ //without ppsd Low => create new TS
+       if(emcExist[linkUp->GetEmc()-fEmcFirst] > 0){ //without ppsd Low => create new TS
 
-         fNTrackSegments = trsl->GetEntries() ; 
-         new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"), 
-                                                             (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd"), 
-                                                             nullpointer) ;
-         ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
+         new ((* fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkUp->GetEmc()) , 
+                                                                     (AliPHOSPpsdRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()), 
+                                                                     nullpointer) ;
+         ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
          fNTrackSegments++ ;
        }
        else{ // append ppsd Up to existing TS
-         ((AliPHOSTrackSegment *)trsl->At(-2-emc))->SetPpsdUpRecPoint((AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd"));
+         ((AliPHOSTrackSegment *)fTrackSegments->At(-2-emcExist[linkUp->GetEmc()-fEmcFirst]))->SetCpvRecPoint((AliPHOSCpvRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()));
        }
 
-       emcRecPoints->AddAt(-1,linkUp->GetEmc()) ; //Mark that PPSD Up found 
-       //replace index of PPSD Up to negative and shifted index of TS      
-       ppsdRecPointsUp->AddAt(-2 - fNTrackSegments,linkUp->GetPpsd()) ; 
+       emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc  that Cpv was found 
+       //mark CPV recpoint as already used 
+        cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
       } //if ppsdUp still exist
     } 
   }     
 
-  Int_t iEmcRP ;
-  for(iEmcRP = 0; iEmcRP <emcRecPoints->GetSize() ; iEmcRP++ ){
-    emc = emcRecPoints->At(iEmcRP) ;
-    if(emc >=0 ){
-      ppsdUp = 0;
-      ppsdLow = 0;
-      new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"), 
-                                                         nullpointer, nullpointer ) ;
-      ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
-      fNTrackSegments++;    
+  //look through emc recPoints left without CPV/PPSD
+  if(emcExist){ //if there is emc rec point
+    Int_t iEmcRP ;
+    for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst  ; iEmcRP++ ){
+      if(emcExist[iEmcRP] > 0 ){
+       new ((*fTrackSegments)[fNTrackSegments])  AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fEmcRecPoints->At(iEmcRP+fEmcFirst), 
+                                                                   nullpointer, 
+                                                                   nullpointer ) ;
+       ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
+       fNTrackSegments++;    
+      } 
     }
-    
   }
   
 }
 
 //____________________________________________________________________________
-void  AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl, 
-                                                   AliPHOSRecPoint::RecPointsList * emcl, 
-                                                   AliPHOSRecPoint::RecPointsList * ppsdl, 
-                                                   AliPHOSTrackSegment::TrackSegmentsList * trsl)
+void  AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
 {
   // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
-  
-  Int_t emcStopedAt  = 0 ; 
-  Int_t ppsdStopedAt = 0 ; 
 
-  fNTrackSegments = 0 ; 
-  
-  TArrayI * emcRecPoints     = new TArrayI(1000) ;  // these arrays keep indexes 
-  TArrayI * ppsdRecPointsUp  = new TArrayI(1000) ;  // of RecPoints, which are 
-  TArrayI * ppsdRecPointsLow = new TArrayI(1000) ;  // kept in TClonesArray's emcl, ppsdl, cpv
-  
-  TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 1000);
-  TClonesArray * linkupArray  = new TClonesArray("AliPHOSLink", 1000); 
+  if(! fIsInitialized) Init() ;
 
-  if(fUnfoldFlag){
-    UnfoldAll(dl, emcl) ; // Unfolds all EMC clusters
-    UnfoldAll(dl, ppsdl) ; // Unfolds all CPV clusters
-  }
+  if(strstr(option,"tim"))
+    gBenchmark->Start("PHOSTSMaker");  
 
-  Int_t phosmod  = 1 ;
-  while(phosmod <= fGeom->GetNModules() ){
-    
-    FillOneModule(emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
-    
-    MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ; 
-    
-    MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
-    
-    emcRecPoints->Reset() ;
-    
-    ppsdRecPointsUp->Reset() ;
-    
-    ppsdRecPointsLow->Reset() ;
-    
-    linkupArray->Clear() ;
-    
-    linklowArray->Clear() ;
+  Int_t nEvents = (Int_t) gAlice->TreeE()->GetEntries() ;
+  
+  for(fEvent = 0;fEvent< nEvents; fEvent++){
+    if(!ReadRecPoints())  //reads RecPoints for event fEvent
+      return;
     
-    phosmod++ ; 
-  }
+    for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ){
+      
+      FillOneModule() ; 
+      
+      MakeLinks() ;
+      
+      MakePairs() ;
+      
+    }
 
-  delete emcRecPoints ; 
-  emcRecPoints = 0 ; 
-  
-  delete ppsdRecPointsUp ; 
-  ppsdRecPointsUp = 0 ; 
+    WriteTrackSegments() ;
+    if(strstr(option,"deb"))
+      PrintTrackSegments(option) ;
+  }
 
-  delete ppsdRecPointsLow ; 
-  ppsdRecPointsLow = 0 ; 
+  if(strstr(option,"tim")){
+    gBenchmark->Stop("PHOSTSMaker");
+    cout << "AliPHOSTSMaker:" << endl ;
+    cout << "  took " << gBenchmark->GetCpuTime("PHOSTSMaker") << " seconds for making TS " 
+        <<  gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents << " seconds per event " << endl ;
+    cout << endl ;
+  }
 
-  delete linkupArray ; 
-  linkupArray = 0  ; 
 
-  delete linklowArray ; 
-  linklowArray = 0 ; 
 }
-
 //____________________________________________________________________________
-Double_t  AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
-{ 
-  // Shape of the shower (see PHOS TDR)
-  // If you change this function, change also the gradien evaluation  in ChiSquare()
-
-  Double_t r4    = r*r*r*r ;
-  Double_t r295  = TMath::Power(r, 2.95) ;
-  Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
-  return shape ;
+void AliPHOSTrackSegmentMakerv1::Print(Option_t * option)const {
+  if(fIsInitialized){
+    cout <<  "======== AliPHOSTrackSegmentMakerv1 ========" << endl ;
+    cout <<  "Making Track segments "<< endl ;
+    cout <<  "    Headers file: " << fHeaderFileName.Data() << endl ;
+    cout <<  "    RecPoints branch file name: " <<fRecPointsBranchTitle.Data() << endl ;
+    cout <<  "    TrackSegments Branch file name: " << fTSBranchTitle.Data() << endl ;
+    cout <<  "with parameters: " << endl ;
+    cout <<  "    Maximal EMC - CPV (PPSD) distance " << fR0 << endl ;
+    cout <<  "============================================" << endl ;
+  }
+  else
+    cout << "AliPHOSTrackSegmentMakerv1 not initialized " << endl ;
 }
-
 //____________________________________________________________________________
-void  AliPHOSTrackSegmentMakerv1::UnfoldAll(DigitsList * dl, AliPHOSRecPoint::RecPointsList * emcIn) 
-{
-  // Performs unfolding of all EMC/CPV but NOT ppsd clusters, sorts them and resets indexes in RecPoints
-
-  AliPHOSEmcRecPoint *  emcRecPoint  ; 
-  Int_t index ;
-  Int_t nEmcUnfolded = emcIn->GetEntries() ;
-
-  Int_t nModulesToUnfold ;
+Bool_t AliPHOSTrackSegmentMakerv1::ReadRecPoints(){
+
+  //Make some initializations 
+  fEmcRecPoints->Clear() ;
+  fCpvRecPoints->Clear() ;
+  fTrackSegments->Clear() ;
+  fNTrackSegments = 0 ;
+  fEmcFirst = 0 ;    
+  fEmcLast  = 0 ;   
+  fCpvFirst = 0 ;   
+  fCpvLast  = 0 ;   
+  fPpsdFirst= 0 ;   
+  fPpsdLast = 0 ;   
+
+
+  gAlice->GetEvent(fEvent) ;
+
+  // Get TreeR header from file
+  char treeName[20]; 
+  sprintf(treeName,"TreeR%d",fEvent);
+
+  if(gAlice->TreeR()==0){
+    cout << "Error in AliPHOSTrackSegmentMakerv1 : no "<<treeName << endl  ;
+    cout << "   Do nothing " << endl ;
+    return kFALSE ;
+  }
 
-  if(emcIn->GetEntries() > 0){
+  char * emcBranchName = new char[30];
+  // sprintf(emcBranchName,"PHOSEmcRP%d",fEvent);
+  sprintf(emcBranchName,"PHOSEmcRP");
+  char * cpvBranchName = new char[30];
+  //  sprintf(cpvBranchName,"PHOSCpvRP%d",fEvent);
+  sprintf(cpvBranchName,"PHOSCpvRP");
+  char * cluBranchName = new char[30];
+  //  sprintf(cluBranchName,"AliPHOSClusterizer%d",fEvent);
+  sprintf(cluBranchName,"AliPHOSClusterizer");
+
+  TBranch * emcBranch = 0;
+  TBranch * cpvBranch = 0;
+  TBranch * clusterizerBranch = 0;
+
+  TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
+  Int_t ibranch;
+  Bool_t emcNotFound = kTRUE ;
+  Bool_t cpvNotFound = kTRUE ;  
+  Bool_t clusterizerNotFound = kTRUE ;
+  
+  for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
 
-    if(((AliPHOSRecPoint *)emcIn->At(0))->IsEmc()){
-      nModulesToUnfold = fGeom->GetNModules() ; 
-    }
-    else{
-      nModulesToUnfold = fGeom->GetNCPVModules() ;
+    if(emcNotFound){
+      emcBranch=(TBranch *) branches->At(ibranch) ;
+      if( fRecPointsBranchTitle.CompareTo(emcBranch->GetTitle())==0 )
+       if( strcmp(emcBranch->GetName(),emcBranchName) == 0) {
+         emcNotFound = kFALSE ;
+       }
     }
     
-    for(index = 0 ; index < nEmcUnfolded; index++){
-      
-      emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
-      if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
-       break ;
-      
-      Int_t nMultipl = emcRecPoint->GetMultiplicity() ; 
-      Int_t * maxAt = new Int_t[nMultipl] ;
-      Float_t * maxAtEnergy = new Float_t[nMultipl] ;
-      Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
-      
-      if( nMax > 1 ) {     // if cluster is very flat (no pronounced maximum) then nMax = 0       
-       UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy) ;
-       emcIn->Remove(emcRecPoint); 
-       emcIn->Compress() ;
-       index-- ;
-       nEmcUnfolded-- ;
-      }
-      
-      delete[] maxAt ; 
-      delete[] maxAtEnergy ; 
-    } //Unfolding finished
-   
-    emcIn->Sort() ;
+    if(cpvNotFound){
+      cpvBranch=(TBranch *) branches->At(ibranch) ;
+      if( fRecPointsBranchTitle.CompareTo(cpvBranch->GetTitle())==0 )
+       if( strcmp(cpvBranch->GetName(),cpvBranchName) == 0) 
+         cpvNotFound = kFALSE ;
+    }
     
-    // to set index to new and correct index of old RecPoints
-    for( index = 0 ; index < emcIn->GetEntries() ; index++)
-      ((AliPHOSEmcRecPoint *) emcIn->At(index))->SetIndexInList(index) ;   
+    if(clusterizerNotFound){
+      clusterizerBranch = (TBranch *) branches->At(ibranch) ;
+      if( fRecPointsBranchTitle.CompareTo(clusterizerBranch->GetTitle()) == 0)
+       if( strcmp(clusterizerBranch->GetName(),cluBranchName) == 0) 
+         clusterizerNotFound = kFALSE ;
+    }
     
   }
 
+  if(clusterizerNotFound || emcNotFound || cpvNotFound){
+    cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
+    cout << "    Can't find Branch with RecPoints or Clusterizer " ;
+    cout << "    Do nothing" <<endl  ;
+    return kFALSE ;
+  }
+  
+  emcBranch->SetAddress(&fEmcRecPoints) ;
+  cpvBranch->SetAddress(&fCpvRecPoints) ;
+  clusterizerBranch->SetAddress(&fClusterizer) ;
+  
+  gAlice->TreeR()->GetEvent(0) ;
+  
+  delete emcBranchName;
+  delete cpvBranchName;
+  delete cluBranchName;
+
+  return kTRUE ;
+  
 }
 //____________________________________________________________________________
-void  AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl, 
-                                                AliPHOSRecPoint::RecPointsList * emcIn, 
-                                                AliPHOSEmcRecPoint * iniEmc, 
-                                                Int_t nMax, 
-                                                int * maxAt, 
-                                                Float_t * maxAtEnergy)
-{ 
-  // Performs the unfolding of a cluster with nMax overlapping showers 
-  // This is time consuming (use the (Un)SetUnfolFlag()  )
-
-  Int_t nPar = 3 * nMax ;
-  Float_t * fitparameters = new Float_t[nPar] ;
+void AliPHOSTrackSegmentMakerv1::WriteTrackSegments(){
 
+  char treeName[20]; 
+  sprintf(treeName,"TreeR%d",fEvent);
+  
+  
+  //First, check, if branches already exist
+  TBranch * tsMakerBranch = 0;
+  TBranch * tsBranch = 0;
+  
+  TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
+  Int_t ibranch;
+  Bool_t tsMakerNotFound = kTRUE ;
+  Bool_t tsNotFound = kTRUE ;
+  
+  for(ibranch = 0;(ibranch <branches->GetEntries())&&(tsMakerNotFound||tsNotFound);ibranch++){
+    if(tsMakerNotFound){
+      tsMakerBranch=(TBranch *) branches->At(ibranch) ;
+      if( (strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) &&
+         (fTSBranchTitle.CompareTo( tsMakerBranch->GetTitle())==0 ))
+       tsMakerNotFound = kFALSE ;
+    }
+    if(tsNotFound){
+      tsBranch=(TBranch *) branches->At(ibranch) ;
+      if( (strcmp(tsBranch->GetName(),"PHOSTS") == 0)  &&
+         (fTSBranchTitle.CompareTo( tsBranch->GetTitle())==0 ))
+       tsNotFound = kFALSE ;
+    }
+  }
 
-  Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
-  if( !rv ) {
-    // Fit failed, return and remove cluster
-    delete[] fitparameters ; 
+  if(!(tsMakerNotFound && tsNotFound )){ 
+    cout << "AliPHOSTrackSegmentMakerv1 error:"<< endl ;
+    cout << "       Branches PHOSTS and AliPHOSTrackSegementMaker " << endl ;
+    cout << "       with title '"<<fTSBranchTitle.Data() << "' already exist " << endl ;
+    cout << "       can not overwrite " << endl ;
     return ;
   }
 
-  Float_t xDigit ;
-  Float_t zDigit ;
-  Int_t relid[4] ;
-
-  Int_t nDigits = iniEmc->GetMultiplicity() ;  
-  Float_t xpar  ;
-  Float_t zpar  ;
-  Float_t epar  ;
-  Float_t distance ;
-  Float_t ratio ;
-  Float_t * efit = new Float_t[nDigits] ;
-  Int_t iparam ;
-  Int_t iDigit ;
-  
-  AliPHOSDigit * digit ;
-  Int_t * emcDigits = iniEmc->GetDigitsList() ;
-  Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
-
-  Int_t iRecPoint = emcIn->GetEntries() ;
-
-  for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
-    digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;   
-    fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
-    fGeom->RelPosInModule(relid, xDigit, zDigit) ;
-    efit[iDigit] = 0;
-    iparam = 0 ;
-    
-    while(iparam < nPar ){
-      xpar = fitparameters[iparam] ;
-      zpar = fitparameters[iparam+1] ;
-      epar = fitparameters[iparam+2] ;
-      iparam += 3 ;
-      distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar)  ;
-      distance =  TMath::Sqrt(distance) ;
-      efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
-    }
+  //Make branch in TreeR for TrackSegments 
+  char * filename = 0;
+  if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){   //generating file name
+    filename = new char[strlen(gAlice->GetBaseFile())+20] ;
+    sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ; 
   }
 
-  iparam = 0 ;
-  Float_t eDigit ;
-
-
-  while(iparam < nPar ){
-    xpar = fitparameters[iparam] ;
-    zpar = fitparameters[iparam+1] ;
-    epar = fitparameters[iparam+2] ;
-    iparam += 3 ;
-
-    if(iRecPoint >= emcIn->GetSize())
-      emcIn->Expand(2*iRecPoint) ;
-
-    if(iniEmc->IsEmc()){
-      (*emcIn)[iRecPoint] = new AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
-
-      AliPHOSEmcRecPoint * emcRP ;  
-      emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint);
-      iRecPoint++ ;
-      
-      for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
-       digit = fPlease->GimeDigit( emcDigits[iDigit] ) ; 
-       fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
-       fGeom->RelPosInModule(relid, xDigit, zDigit) ;
-       distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar)  ;
-       distance =  TMath::Sqrt(distance) ;
-       ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ; 
-       eDigit = emcEnergies[iDigit] * ratio ;
-       emcRP->AddDigit( *digit, eDigit ) ;
-      }        
-      emcRP->EvalAll() ;
-    }
-    else{
-      (*emcIn)[iRecPoint] = new AliPHOSCpvRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
-     
-      AliPHOSCpvRecPoint * cpvRP ;  
-      cpvRP = (AliPHOSCpvRecPoint *) emcIn->At(iRecPoint);
-
-      iRecPoint++ ;
-      
-      for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
-       digit = fPlease->GimeDigit( emcDigits[iDigit] ) ; 
-       fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
-       fGeom->RelPosInModule(relid, xDigit, zDigit) ;
-       distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar)  ;
-       distance =  TMath::Sqrt(distance) ;
-       ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ; 
-       eDigit = emcEnergies[iDigit] * ratio ;
-       cpvRP->AddDigit( *digit, eDigit ) ;
-      }
-      cpvRP->EvalAll() ;
-    }
-    
-  }
+  TDirectory *cwd = gDirectory;
   
-  delete[] fitparameters ; 
-  delete[] efit ; 
-
-}
-
-//______________________________________________________________________________
-void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
-{
-  // Calculates th Chi square for the cluster unfolding minimization
-  // Number of parameters, Gradient, Chi squared, parameters, what to do
+  //First TS
+  Int_t bufferSize = 32000 ;    
+  tsBranch = gAlice->TreeR()->Branch("PHOSTS",&fTrackSegments,bufferSize);
+  tsBranch->SetTitle(fTSBranchTitle.Data());
+  if (filename) {
+    tsBranch->SetFile(filename);
+    TIter next( tsBranch->GetListOfBranches());
+    while ((tsBranch=(TBranch*)next())) {
+      tsBranch->SetFile(filename);
+    }   
+    cwd->cd();
+  } 
   
-  AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
-
-  Int_t * emcDigits     = emcRP->GetDigitsList() ;
-
-  Int_t nOfDigits = emcRP->GetDigitsMultiplicity() ; 
-
-  Float_t * emcEnergies = emcRP->GetEnergiesList() ;
-
-  AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
-
-  AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
-
-  fret = 0. ;     
-  Int_t iparam ;
-
-  if(iflag == 2)
-    for(iparam = 0 ; iparam < nPar ; iparam++)    
-      Grad[iparam] = 0 ; // Will evaluate gradient
+  //Second -TSMaker
+  Int_t splitlevel = 0 ;
+  AliPHOSTrackSegmentMakerv1 * ts = this ;
+  tsMakerBranch = gAlice->TreeR()->Branch("AliPHOSTrackSegmentMaker","AliPHOSTrackSegmentMakerv1",
+                                         &ts,bufferSize,splitlevel);
+  tsMakerBranch->SetTitle(fTSBranchTitle.Data());
+  if (filename) {
+    tsMakerBranch->SetFile(filename);
+    TIter next( tsMakerBranch->GetListOfBranches());
+    while ((tsMakerBranch=(TBranch*)next())) {
+      tsMakerBranch->SetFile(filename);
+    }   
+    cwd->cd();
+  } 
   
-  Double_t efit ;    
-
-  AliPHOSDigit * digit ;
-  Int_t iDigit ;
-
-  for( iDigit = 0 ; iDigit < nOfDigits ; iDigit++) {
-
-    digit = please->GimeDigit( emcDigits[iDigit] ) ; 
-
-    Int_t relid[4] ;
-    Float_t xDigit ;
-    Float_t zDigit ;
-
-    geom->AbsToRelNumbering(digit->GetId(), relid) ;
+  gAlice->TreeR()->Fill() ;    
+  gAlice->TreeR()->Write(0,kOverwrite) ;  
+  
+}
 
-    geom->RelPosInModule(relid, xDigit, zDigit) ;
 
-     if(iflag == 2){  // calculate gradient
-       Int_t iParam = 0 ;
-       efit = 0 ;
-       while(iParam < nPar ){
-        Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
-        iParam++ ; 
-        distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ; 
-        distance = TMath::Sqrt( distance ) ; 
-        iParam++ ;      
-        efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
-        iParam++ ;
-       }
-       Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E) 
-       iParam = 0 ;
-       while(iParam < nPar ){
-        Double_t xpar = x[iParam] ;
-        Double_t zpar = x[iParam+1] ;
-        Double_t epar = x[iParam+2] ;
-        Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
-        Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
-        Double_t r4 = dr*dr*dr*dr ;
-        Double_t r295 = TMath::Power(dr,2.95) ;
-        Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
-                                        0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
-        
-        Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ;  // Derivative over x    
-        iParam++ ; 
-        Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ;  // Derivative over z         
-        iParam++ ; 
-        Grad[iParam] += shape ;                                  // Derivative over energy             
-        iParam++ ; 
-       }
-     }
-     efit = 0;
-     iparam = 0 ;
-
-     while(iparam < nPar ){
-       Double_t xpar = x[iparam] ;
-       Double_t zpar = x[iparam+1] ;
-       Double_t epar = x[iparam+2] ;
-       iparam += 3 ;
-       Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar)  ;
-       distance =  TMath::Sqrt(distance) ;
-       efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
-     }
-
-     fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ; 
-     // Here we assume, that sigma = sqrt(E)
+//____________________________________________________________________________
+void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option){
+  
+  cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
+  cout << "       Found " << fTrackSegments->GetEntriesFast() << "  trackSegments " << endl ;
+  
+  if(strstr(option,"all")) {  // printing found TS
+    cout << "TrackSegment # " << "    EMC RP#    " << "    CPV RP#    " << "     PPSD RP#" << endl ; 
+    
+    Int_t index;
+    for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
+      AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ; 
+      cout<<"   "<< setw(4) << ts->GetIndexInList() << "            " 
+         <<setw(4) << ts->GetEmcIndex()<< "            " 
+         <<setw(4) << ts->GetCpvIndex()<< "            " 
+         <<setw(4) << ts->GetPpsdIndex()<< endl ;
+    }  
+    
+    cout << "-------------------------------------------------------"<< endl ;
   }
+}
+//____________________________________________________________________________
+void AliPHOSTrackSegmentMakerv1::SetRecPointsBranch(const char * title){
+  //set the title of RecPoints 
+    fRecPointsBranchTitle = title ;
+
+}
+//____________________________________________________________________________
+void AliPHOSTrackSegmentMakerv1::SetTrackSegmentsBranch(const char * title){
 
+    fTSBranchTitle = title ; 
 }
index 1089c99bbce5b8a99d3e36909a2caa2a833b3611..72ea231d647749d0c09c14c16ee2a641db93567d 100644 (file)
 // --- Standard library ---
 
 // --- AliRoot header files ---
-
-#include "TObjArray.h"
-#include "AliPHOSClusterizer.h"
-#include "AliPHOSEmcRecPoint.h"
-#include "AliPHOSPpsdRecPoint.h"
 #include "AliPHOSTrackSegmentMaker.h"
-#include "TMinuit.h" 
+
+class AliPHOSEmcRecPoint ;
+class AliPHOSRecPoint ;
+
 
 class  AliPHOSTrackSegmentMakerv1 : public AliPHOSTrackSegmentMaker {
 
 public:
 
   AliPHOSTrackSegmentMakerv1() ;                     
+  AliPHOSTrackSegmentMakerv1(const char* headerFile,const char* branchTitle = 0) ;                     
   AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) {
     // cpy ctor: no implementation yet
     // requested by the Coding Convention
-    assert(0==1) ; 
+    abort() ; 
   }
    
   virtual ~ AliPHOSTrackSegmentMakerv1() ; // dtor
   
-  Bool_t  FindFit(AliPHOSEmcRecPoint * emcRP, int * MaxAt, Float_t * maxAtEnergy, 
-                 Int_t NPar, Float_t * FitParametres) ; //Used in UnfoldClusters, calls TMinuit
-  void    FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn, 
-                       TArrayI * emcOut, 
-                       AliPHOSRecPoint::RecPointsList * ppsdIn, 
-                       TArrayI * ppsdOutUp, 
-                       TArrayI * ppsdOutLow, 
-                       Int_t &PHOSModule, 
-                       Int_t & emcStopedAt, 
-                       Int_t & ppsdStopedAt) ; // Fills temporary arrais with clusters from one module  
-  Float_t GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * EmcClu , AliPHOSPpsdRecPoint * Ppsd , Bool_t & TooFar ) ; // see R0
-
-  void    MakeLinks(TArrayI * EmcRecPoints, TArrayI * PpsdRecPointsUp, TArrayI * PpsdRecPointsLow, 
-                   TClonesArray * LinkLowArray, TClonesArray *LinkUpArray) ; //Evaluates distances(links) between EMC and PPSD
-  void    MakePairs(TArrayI * EmcRecPoints, 
-                   TArrayI * PpsdRecPointsUp, 
-                   TArrayI * PpsdRecPointsLow, 
-                   TClonesArray * LinkLowArray, 
-                   TClonesArray * LinkUpArray, 
-                   AliPHOSTrackSegment::TrackSegmentsList * trsl) ; //Finds pairs(triplets) with smallest link
-  void    MakeTrackSegments(DigitsList * DL, 
-                           AliPHOSRecPoint::RecPointsList * emcl, 
-                           AliPHOSRecPoint::RecPointsList * ppsdl, 
-                           AliPHOSTrackSegment::TrackSegmentsList * trsl ) ; // does the job
-  virtual void SetMaxEmcPpsdDistance(Float_t r){ fR0 = r ;}
-  virtual void    SetUnfoldFlag() { fUnfoldFlag = kTRUE ; } ; 
-  static Double_t ShowerShape(Double_t r) ; // Shape of shower used in unfolding; class member function (not object member function)
-  void    UnfoldAll(DigitsList * Dl, AliPHOSRecPoint::RecPointsList * emcIn) ; 
-                                             // Unfolds and sorts all EMC clusters
-  void  UnfoldClusters(DigitsList * DL, 
-                      AliPHOSRecPoint::RecPointsList * emcIn, 
-                      AliPHOSEmcRecPoint * iniEmc, 
-                      Int_t Nmax, 
-                      int * maxAt, 
-                      Float_t * maxAtEnergy ) ; //Unfolds overlaping clusters using TMinuit package
-  virtual void UnsetUnfoldFlag() { fUnfoldFlag = kFALSE ; } 
+  virtual char*  GetRecPointsBranch    (void)const{return (char*)fRecPointsBranchTitle.Data() ;}
+  virtual char*  GetTrackSegmentsBranch(void)const{return (char*)fTSBranchTitle.Data() ;}
+
+  virtual void   Exec(Option_t * option) ;
+          void   FillOneModule() ;       // Finds range in which RecPoints belonging current PHOS module are
+
+          void   MakeLinks() ;           //Evaluates distances(links) between EMC and PPSD
+          void   MakePairs() ;           //Finds pairs(triplets) with smallest link
+  virtual void   Print(Option_t * option) const ;
+  virtual Bool_t ReadRecPoints() ;
+  virtual void   SetMaxEmcPpsdDistance(Float_t r){ fR0 = r ;}
+  virtual void   SetRecPointsBranch(const char * title) ; 
+  virtual void   SetTrackSegmentsBranch(const char * title) ; 
+  virtual void   WriteTrackSegments() ;
 
   AliPHOSTrackSegmentMakerv1 & operator = (const AliPHOSTrackSegmentMakerv1 & )  {
     // assignement operator requested by coding convention
     // but not needed
-    assert(0==1) ;
+    abort() ;
     return *this ; 
   }
 
 private:
+  Float_t GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * EmcClu , AliPHOSRecPoint * Ppsd , Bool_t & TooFar ) ; // see R0
+  void    Init() ;
+  void    PrintTrackSegments(Option_t *option) ;
+
+private:  
+
+  TString fHeaderFileName ;          // name of the file which contains gAlice, Tree headers etc.
+  TString fRecPointsBranchTitle ; // name of the file, where RecPoints branchs are stored
+  TString fTSBranchTitle ;        // name of the file, where TrackSegment branchs is stored
+  AliPHOSClusterizer * fClusterizer ; // !  
+  Int_t                  fNTrackSegments ; // number of track segments found 
+  AliPHOSGeometry      * fGeom ;           //! pointer to PHOS geometry  
+  Int_t          fEvent ;            // ! event being precessed
+  TObjArray    * fEmcRecPoints ;     // ! List of EMC Rec Points
+  TObjArray    * fCpvRecPoints ;     // ! List of CPV/PPSD recPoints
+  TClonesArray * fTrackSegments;     // ! list of final track segments
+
+
+  Bool_t  fIsInitialized ; //
 
-  Float_t fDelta ;     // parameter used for sorting
   Float_t fR0 ;        // Maximum distance between a EMC RecPoint and a PPSD RecPoint   
-  Bool_t fUnfoldFlag ; // Directive to unfold or not the clusters in case of multiple maxima
+
+  TClonesArray * fLinkLowArray ;  //!
+  TClonesArray * fLinkUpArray  ;  //!
+
+
+  Int_t fEmcFirst;     //! Index of first EMC RecPoint belonging to currect PHOS module
+  Int_t fEmcLast ;     //!
+  Int_t fCpvFirst;     //! Cpv upper layer     
+  Int_t fCpvLast;      //! 
+  Int_t fPpsdFirst;    //! Cpv low layer     
+  Int_t fPpsdLast;     //!
+  Int_t fModule ;      //! number of module being processed
 
   ClassDef( AliPHOSTrackSegmentMakerv1,1)  // Implementation version 1 of algorithm class to make PHOS track segments