Added shared cluster reduction.
authorshahoian <shahoian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 10 May 2013 19:22:38 +0000 (19:22 +0000)
committershahoian <shahoian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 10 May 2013 19:22:38 +0000 (19:22 +0000)
Added cut on global chi2 at each layer
Modified tuning histos filling (requested by #define _ITSU_TUNING_MODE_ in AliITSUAux.h)

13 files changed:
ITS/UPGRADE/AliITSUAux.h
ITS/UPGRADE/AliITSUClusterPix.cxx
ITS/UPGRADE/AliITSUClusterPix.h
ITS/UPGRADE/AliITSURecoLayer.cxx
ITS/UPGRADE/AliITSUSeed.cxx
ITS/UPGRADE/AliITSUSeed.h
ITS/UPGRADE/AliITSUTrackCond.cxx
ITS/UPGRADE/AliITSUTrackCond.h
ITS/UPGRADE/AliITSUTrackHyp.cxx
ITS/UPGRADE/AliITSUTrackerGlo.cxx
ITS/UPGRADE/AliITSUTrackerGlo.h
ITS/UPGRADE/testITSU/MakeITSRecoParam.C
ITS/UPGRADE/testITSU/itsupcdb.tar.gz

index 4199089..04244f7 100644 (file)
 //                                                                   //
 ///////////////////////////////////////////////////////////////////////
 
+#define _ITSU_TUNING_MODE_
 
 class AliITSUGeomTGeo;
 class AliITSsegmentation;
 using namespace TMath;
 
 
+
 namespace AliITSUAux {
   void   BringTo02Pi(double &phi);
   Bool_t OKforPhiMin(double phiMin,double phi);
index ef50bbb..20c8232 100644 (file)
@@ -14,6 +14,7 @@ UInt_t           AliITSUClusterPix::fgMode = 0;
 //_____________________________________________________
 AliITSUClusterPix::AliITSUClusterPix()
   : fCharge(0)
+  , fRecoInfo(0)
   , fNxNzN(0)
 {
   // default constructor
@@ -29,6 +30,7 @@ AliITSUClusterPix::~AliITSUClusterPix()
 AliITSUClusterPix::AliITSUClusterPix(const AliITSUClusterPix& cluster) 
   :AliCluster(cluster)
   ,fCharge(cluster.fCharge)
+  ,fRecoInfo(cluster.fRecoInfo)
   ,fNxNzN(cluster.fNxNzN)
 {
   // copy constructor
@@ -41,6 +43,7 @@ AliITSUClusterPix& AliITSUClusterPix::operator=(const AliITSUClusterPix& cluster
   if(&cluster == this) return *this;
   fNxNzN = cluster.fNxNzN;
   fCharge = cluster.fCharge;
+  fRecoInfo = cluster.fRecoInfo;
   TObject::operator=(cluster);
   AliCluster::operator=(cluster);
   return *this;
index 9e67721..fc2d018 100644 (file)
@@ -73,6 +73,9 @@ class AliITSUClusterPix : public AliCluster
   virtual Bool_t               IsEqual(const TObject* obj)  const;
   virtual Int_t                       Compare(const TObject* obj)  const;
   //
+  UShort_t                     GetRecoInfo()                const {return fRecoInfo;}
+  void                         SetRecoInfo(UShort_t v)            {fRecoInfo = v; ModClUsage(v>0);}
+  //
   Bool_t  HasCommonTrack(const AliCluster* cl)          const;
   //
   static  void                 SetGeom(AliITSUGeomTGeo* gm) {fgGeom = gm;}
@@ -85,12 +88,13 @@ class AliITSUClusterPix : public AliCluster
  protected:
   //
   UShort_t                fCharge;        //  charge (for MC studies only)
+  UShort_t                fRecoInfo;      //! space reserved for reco time manipulations
   Int_t                   fNxNzN;         //  effective cluster size in X (1st byte) and Z (2nd byte) directions 
                                           //  and total Npix(3d byte). 4th byte is used for clusters usage counter
   static UInt_t           fgMode;         //! general mode (sorting mode etc)
   static AliITSUGeomTGeo* fgGeom;         //! pointer on the geometry data
 
-  ClassDef(AliITSUClusterPix,1)
+  ClassDef(AliITSUClusterPix,2)
 };
 
 //______________________________________________________
index 68f3917..4dde66b 100644 (file)
@@ -220,7 +220,7 @@ void AliITSURecoLayer::Build()
   } // ladders
   //
 }
-///*
+
 //______________________________________________________
 Int_t AliITSURecoLayer::FindSensors(const double* impPar, AliITSURecoSens *sensors[AliITSURecoSens::kNNeighbors])
 {
index 74578d9..ab4fe30 100644 (file)
@@ -18,6 +18,10 @@ AliITSUSeed::AliITSUSeed()
   ,fChi2Match(0)
   ,fChi2ITSSA(0)
   ,fParent(0)
+#ifdef _ITSU_TUNING_MODE_ // this is used only for tuning histo filling
+  ,fOrdBranch(0) 
+  ,fOrdCand(0)
+#endif
 {
   // def c-tor
   ResetFMatrix();
@@ -41,6 +45,10 @@ AliITSUSeed::AliITSUSeed(const AliITSUSeed& src)
   ,fChi2Match(src.fChi2Match)
   ,fChi2ITSSA(src.fChi2ITSSA)
   ,fParent(src.fParent) 
+#ifdef _ITSU_TUNING_MODE_ // this is used only for tuning histo filling
+  ,fOrdBranch(src.fOrdBranch) 
+  ,fOrdCand(src.fOrdCand)
+#endif
 {
   // def c-tor
   for (int i=kNFElem;i--;) fFMatrix[i] = src.fFMatrix[i];
@@ -69,7 +77,7 @@ void AliITSUSeed::Print(Option_t* opt) const
 {
   // print seed info
   int lr,cl = GetLrCluster(lr);
-  printf("%cLr%d Nchild: %3d Cl:%4d Chi2Glo:%7.2f(%7.2f) Chi2Cl:%7.2f Penalty: %7.2f Mtc:%6.2f Bwd:%6.2f",IsKilled() ? '-':' ',
+  printf("%cLr%d Nchild: %3d Cl:%4d Chi2Glo:%7.2f(%7.2f) Chi2Cl:%7.2f Penalty: %7.2f Mtc:%6.3f Bwd:%6.3f",IsKilled() ? '-':' ',
         lr,GetNChildren(),cl,GetChi2Glo(),GetChi2GloNrm(),GetChi2Cl(), GetChi2Penalty(), GetChi2ITSTPC(), GetChi2ITSSA());
   printf(" |"); 
   int lrc=0;
index 260a6b0..be8aeb8 100644 (file)
@@ -11,7 +11,7 @@ using namespace AliITSUAux;
 class AliITSUSeed: public AliExternalTrackParam
 {
  public:
-  enum {kKilled=BIT(14),kSave=BIT(15),kFake=BIT(16)};
+  enum {kKilled=BIT(14),kSave=BIT(15),kMark=BIT(16),kFake=BIT(17)};
   enum {kF02,kF04,kF12,kF13,kF14,kF24, kF44,kNFElem}; // non-trivial elems of propagation matrix
   enum {kK00,kK01,kK10,kK11,kK20,kK21,kK30,kK31,kK40,kK41, kNKElem}; // non-trivial elems of gain matrix
   enum {kS00,kS10,kS11,kS20,kS21,kS22,kS30,kS31,kS32,kS33,kS40,kS41,kS42,kS43,kS44,kNSElem}; // elements of 5x5 sym matrix
@@ -31,6 +31,7 @@ class AliITSUSeed: public AliExternalTrackParam
   void            Kill(Bool_t v=kTRUE)                   {SetBit(kKilled, v);}
   void            SetFake(Bool_t v=kTRUE)                {SetBit(kFake, v);}
   void            Save(Bool_t v=kTRUE)                   {SetBit(kSave,v);}
+  void            SetMark(Bool_t v=kTRUE)                {SetBit(kMark,v);}
   void            FlagTree(UInt_t bits, Bool_t v=kTRUE);
   void            SetChi2ITSTPC(Float_t v)               {fChi2Match = v;}
   void            SetChi2ITSSA(Float_t v)                {fChi2ITSSA = v;}
@@ -51,9 +52,11 @@ class AliITSUSeed: public AliExternalTrackParam
   Float_t         GetChi2GloNrm()                  const;
   Float_t         GetChi2ITSTPC()                  const {return fChi2Match;}
   Float_t         GetChi2ITSSA()                   const {return fChi2ITSSA;}
+  Float_t         GetQualityVar()                  const;
   Bool_t          IsKilled()                       const {return TestBit(kKilled);}
   Bool_t          IsFake()                         const {return TestBit(kFake);}
   Bool_t          IsSaved()                        const {return TestBit(kSave);}
+  Bool_t          IsMarked()                       const {return TestBit(kMark);}
   Bool_t          ContainsFake()                   const;
   Int_t           FetchClusterInfo(Int_t *clIDarr) const;
   //
@@ -83,6 +86,17 @@ class AliITSUSeed: public AliExternalTrackParam
   UInt_t          GetNChildren()                                 const {return fNChildren;}
   Int_t           IncChildren()                                        {return ++fNChildren;}
   Int_t           DecChildren()                                        {return --fNChildren;}
+  Double_t        GetResidY()                                    const {return fResid[0];}
+  Double_t        GetResidZ()                                    const {return fResid[1];}
+  //
+#ifdef _ITSU_TUNING_MODE_ // this is used only for tuning histo filling
+  void                  SetOrdBranch(UShort_t v) {fOrdBranch=v;}
+  void                  SetOrdCand(UShort_t v)   {fOrdCand=v;}
+  Int_t                 GetOrdBranch()           const {return fOrdBranch;}
+  Int_t                 GetOrdCand()             const {return fOrdCand;}
+  Double_t              GetPullY()               const {return fResid[0]*Sqrt(fCovIYZ[0]);}
+  Double_t              GetPullZ()               const {return fResid[1]*Sqrt(fCovIYZ[2]);}
+#endif
   //
  protected:
   //
@@ -100,7 +114,12 @@ class AliITSUSeed: public AliExternalTrackParam
   Double_t              fCovIYZ[3];         // inverted matrix of propagation + meas errors = [Hi * Pi|i-1 * Hi^T + Ri]^-1
   Double_t              fResid[2];          // residuals vector
   TObject*              fParent;            // parent track (in higher tree hierarchy)
-  
+  //
+#ifdef _ITSU_TUNING_MODE_ // this is used only for tuning histo filling
+  UShort_t              fOrdBranch;         //! order in the seed branching
+  UShort_t              fOrdCand;           //! order in candidates tree
+#endif
+  //
   ClassDef(AliITSUSeed,1)
 };
 
@@ -182,5 +201,13 @@ inline void AliITSUSeed::FlagTree(UInt_t bits, Bool_t v)
   //
 }
 
+//__________________________________________________________________
+inline Float_t AliITSUSeed::GetQualityVar() const
+{
+  // return variable for quality check (the smaller - the better)
+  //  return GetChi2ITSSA()/Pt(); // this may change! RS
+  return GetChi2GloNrm()/Pt();
+}
+
 
 #endif
index 2fb9d6c..4b6318d 100644 (file)
@@ -10,6 +10,7 @@ Char_t    AliITSUTrackCond::fgkClSharing = 0;
 Int_t     AliITSUTrackCond::fgkMaxBranches = 50;
 Int_t     AliITSUTrackCond::fgkMaxCandidates = 500;
 Float_t   AliITSUTrackCond::fgkMaxTr2ClChi2  = 50.;
+Float_t   AliITSUTrackCond::fgkMaxChi2GloNrm = 50.;
 Float_t   AliITSUTrackCond::fgkMissPenalty  = 2.;
 Float_t   AliITSUTrackCond::fgkMaxMatchChi2 = 15.;
 Float_t   AliITSUTrackCond::fgkMaxITSSAChi2 = 15;
@@ -23,6 +24,7 @@ AliITSUTrackCond::AliITSUTrackCond(int nLayers)
   ,fMaxBranches(0)
   ,fMaxCandidates(0)
   ,fMaxTr2ClChi2(0)
+  ,fMaxChi2GloNrm(0)
   ,fMissPenalty(0)
   ,fNSigmaRoadY(0)
   ,fNSigmaRoadZ(0)
@@ -45,6 +47,7 @@ AliITSUTrackCond::AliITSUTrackCond(const AliITSUTrackCond& src)
   ,fMaxBranches(0)
   ,fMaxCandidates(0)
   ,fMaxTr2ClChi2(0)
+  ,fMaxChi2GloNrm(0)
   ,fMissPenalty(0)
   ,fNSigmaRoadY(0)
   ,fNSigmaRoadZ(0)
@@ -58,6 +61,7 @@ AliITSUTrackCond::AliITSUTrackCond(const AliITSUTrackCond& src)
     SetMaxBranches(i,src.GetMaxBranches(i));
     SetMaxCandidates(i,src.GetMaxCandidates(i));
     SetMaxTr2ClChi2(i,src.GetMaxTr2ClChi2(i));
+    SetMaxChi2GloNrm(i,src.GetMaxChi2GloNrm(i));
     SetMissPenalty(i,src.GetMissPenalty(i));
     SetNSigmaRoadY(i,src.GetNSigmaRoadY(i));
     SetNSigmaRoadZ(i,src.GetNSigmaRoadZ(i));
@@ -82,6 +86,7 @@ AliITSUTrackCond& AliITSUTrackCond::operator=(const AliITSUTrackCond& src)
       SetMaxBranches(i,src.GetMaxBranches(i));
       SetMaxCandidates(i,src.GetMaxCandidates(i));
       SetMaxTr2ClChi2(i,src.GetMaxTr2ClChi2(i));
+      SetMaxChi2GloNrm(i,src.GetMaxChi2GloNrm(i));
       SetMissPenalty(i,src.GetMissPenalty(i));
       SetNSigmaRoadY(i,src.GetNSigmaRoadY(i));
       SetNSigmaRoadZ(i,src.GetNSigmaRoadZ(i));
@@ -102,6 +107,7 @@ void AliITSUTrackCond::SetNLayers(int nLayers)
     delete[] fMaxBranches;
     delete[] fMaxCandidates;
     delete[] fMaxTr2ClChi2;
+    delete[] fMaxChi2GloNrm;
     delete[] fMissPenalty;
     delete[] fNSigmaRoadY;
     delete[] fNSigmaRoadZ;
@@ -113,6 +119,7 @@ void AliITSUTrackCond::SetNLayers(int nLayers)
     fMaxBranches   = new Short_t[fNLayers];
     fMaxCandidates = new Short_t[fNLayers];
     fMaxTr2ClChi2  = new Float_t[fNLayers];
+    fMaxChi2GloNrm = new Float_t[fNLayers];
     fMissPenalty   = new Float_t[fNLayers];
     fNSigmaRoadY   = new Float_t[fNLayers];
     fNSigmaRoadZ   = new Float_t[fNLayers];
@@ -121,6 +128,7 @@ void AliITSUTrackCond::SetNLayers(int nLayers)
       SetMaxBranches(i,fgkMaxBranches);
       SetMaxCandidates(i,fgkMaxCandidates);
       SetMaxTr2ClChi2(i,fgkMaxTr2ClChi2);
+      SetMaxChi2GloNrm(i,fgkMaxChi2GloNrm);
       SetMissPenalty(i,fgkMissPenalty);
       SetNSigmaRoadY(i,-1); // force recalculation
       SetNSigmaRoadZ(i,-1); // force recalculation
@@ -131,6 +139,7 @@ void AliITSUTrackCond::SetNLayers(int nLayers)
     fMaxBranches   = 0;
     fMaxCandidates = 0;
     fMaxTr2ClChi2  = 0;
+    fMaxChi2GloNrm = 0;
     fMissPenalty   = 0;
     fNSigmaRoadY   = 0;
     fNSigmaRoadZ   = 0;
@@ -201,10 +210,10 @@ void AliITSUTrackCond::Print(Option_t*) const
     printf("\n");
     cntCond += kNAuxSz;
   }
-  printf("Cuts:\t%6s\t%6s\t%4s\t%8s\t%8s\t%8s\t%8s\n", "MaxBrn","MaxCnd","ClSh","Chi2Cl","Mis.Pen.","NSig.Y","NSig.Z");
+  printf("Cuts:\t%6s\t%6s\t%4s\t%8s\t%8s\t%8s\t%8s\t%8s\n", "MaxBrn","MaxCnd","ClSh","Chi2Cl","Chi2Glo","Mis.Pen.","NSig.Y","NSig.Z");
   for (int i=0;i<fNLayers;i++) {
-    printf("Lr%2d:\t%6d\t%6d\t%4d\t%8.1f\t%8.2f\t%8.2f\t%8.2f\n",i,
-          fMaxBranches[i],fMaxCandidates[i],fClSharing[i],fMaxTr2ClChi2[i],fMissPenalty[i],fNSigmaRoadY[i],fNSigmaRoadZ[i]);
+    printf("Lr%2d:\t%6d\t%6d\t%4d\t%8.1f\t%8.2f\t%8.2f\t%8.2f\t%8.2f\n",i,
+          fMaxBranches[i],fMaxCandidates[i],fClSharing[i],fMaxTr2ClChi2[i],fMaxChi2GloNrm[i],fMissPenalty[i],fNSigmaRoadY[i],fNSigmaRoadZ[i]);
   }
   //
   printf("ITS/TPC matching MaxChi2: %.3f\n",fMaxITSTPCMatchChi2);
@@ -220,7 +229,7 @@ void AliITSUTrackCond::Init()
   //
   for (int ilr=0;ilr<fNLayers;ilr++) {
     if (IsLayerExcluded(ilr)) continue;
-    float nsig = Sqrt(GetMaxTr2ClChi2(ilr));
+    float nsig = Sqrt(2*GetMaxTr2ClChi2(ilr));
     if (GetNSigmaRoadY(ilr)<0) SetNSigmaRoadY(ilr,nsig);
     if (GetNSigmaRoadZ(ilr)<0) SetNSigmaRoadZ(ilr,nsig);
     //
index 65c2121..24810fc 100644 (file)
@@ -51,6 +51,7 @@ class AliITSUTrackCond : public TObject
   void        SetMaxITSTPCMatchChi2(Float_t v)               {fMaxITSTPCMatchChi2 = v;}
   void        SetMaxITSSAChi2(Float_t v)                     {fMaxITSSAChi2 = v;}
   void        SetMaxTr2ClChi2(Int_t lr, Float_t v)           {fMaxTr2ClChi2[lr] = v;}
+  void        SetMaxChi2GloNrm(Int_t lr, Float_t v)           {fMaxChi2GloNrm[lr] = v;}
   void        SetMissPenalty(Int_t lr,  Float_t v)           {fMissPenalty[lr] = v;}
   void        SetNSigmaRoadY(Int_t lr,  Float_t v)           {fNSigmaRoadY[lr] = v;}
   void        SetNSigmaRoadZ(Int_t lr,  Float_t v)           {fNSigmaRoadZ[lr] = v;}
@@ -60,6 +61,7 @@ class AliITSUTrackCond : public TObject
   Char_t      GetClSharing(Int_t lr)                   const {return fClSharing[lr];}
   Float_t     GetMissPenalty(Int_t lr)                 const {return fMissPenalty[lr];}
   Float_t     GetMaxTr2ClChi2(Int_t lr)                const {return fMaxTr2ClChi2[lr];}
+  Float_t     GetMaxChi2GloNrm(Int_t lr)               const {return fMaxChi2GloNrm[lr];}
   Float_t     GetNSigmaRoadY(Int_t lr)                 const {return fNSigmaRoadY[lr];}
   Float_t     GetNSigmaRoadZ(Int_t lr)                 const {return fNSigmaRoadZ[lr];}
   Bool_t      IsLayerExcluded(Int_t lr)                const {return GetMaxTr2ClChi2(lr)<=0;}
@@ -77,6 +79,7 @@ class AliITSUTrackCond : public TObject
   Short_t*    fMaxBranches;              // [fNLayers] max allowed branches per seed on each layer
   Short_t*    fMaxCandidates;            // [fNLayers] max allowed candidates per TPC seed on each layer
   Float_t*    fMaxTr2ClChi2;             // [fNLayers] max track-to-cluster chi2
+  Float_t*    fMaxChi2GloNrm;            // [fNLayers] max norm global chi2
   Float_t*    fMissPenalty;              // [fNLayers] chi2 penalty for missing hit on the layer
   Float_t*    fNSigmaRoadY;              // [fNLayers] number of sigmas in Y
   Float_t*    fNSigmaRoadZ;              // [fNLayers] number of sigmas in Z
@@ -89,11 +92,12 @@ class AliITSUTrackCond : public TObject
   static Int_t   fgkMaxBranches;          // def max number of branches per seed on current layer 
   static Int_t   fgkMaxCandidates;        // def max number of total candidates on current layer 
   static Float_t fgkMaxTr2ClChi2;         // def track-to-cluster chi2 cut
+  static Float_t fgkMaxChi2GloNrm;        // def global norm chi2 cut
   static Float_t fgkMissPenalty;          // penalty for missing cluster
   static Float_t fgkMaxMatchChi2;         // max acceptable matching chi2
   static Float_t fgkMaxITSSAChi2;         // max acceptable standalone ITS backward fit chi2
   //
-  ClassDef(AliITSUTrackCond,4)           // set of requirements on track hits pattern
+  ClassDef(AliITSUTrackCond,5)           // set of requirements on track hits pattern
 };
 
 
index 7e149fe..aef366c 100644 (file)
@@ -105,9 +105,15 @@ AliITSUSeed* AliITSUTrackHyp::GetWinner() const
 AliITSUSeed* AliITSUTrackHyp::DefineWinner(int lr, int id)
 {
   // assign best candidate
-  if (GetNSeeds(lr)<=id) return 0;
-  fWinner = GetSeed(lr,id);
+  int nsd = GetNSeeds(lr);
+  while ( id<nsd && ( !(fWinner=GetSeed(lr,id)) || fWinner->IsKilled() ) ) {id++; fWinner=0;}
+  if (!fWinner) {
+    //    AliInfo(Form("No winner candidates out of %d for %d",nsd,GetUniqueID()));
+    return 0;
+  }
+  UInt_t idESD = GetUniqueID(); // retain ESDtrackID
   this->AliExternalTrackParam::operator=(*fWinner);
+  SetUniqueID(idESD);
   SetChi2(fWinner->GetChi2GloNrm());
   SetNumberOfClusters(fWinner->GetNLayersHit());
   return fWinner;
index f24ac14..09c7fd6 100644 (file)
@@ -35,7 +35,6 @@
 #include "AliITSUReconstructor.h"
 #include "AliITSReconstructor.h"
 #include "AliITSUSeed.h"
-#include "AliITSUAux.h"
 #include "AliITSUClusterPix.h"
 #include "AliITSUGeomTGeo.h"
 #include "AliCodeTimer.h"
@@ -79,8 +78,9 @@ AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
   ,fCurrActLrID(-1)
   ,fCurrLayer(0)
   ,fTrackPhase(-1)
-#ifdef  _FILL_CONTROL_HISTOS_
-  ,fCHistoArr(0)
+#ifdef  _ITSU_TUNING_MODE_
+  ,fCHistoArrCorr(0)
+  ,fCHistoArrFake(0)
 #endif
 {
   // Default constructor
@@ -96,17 +96,24 @@ AliITSUTrackerGlo::~AliITSUTrackerGlo()
   if (fWorkHyp) fWorkHyp->SetTPCSeed(0); // this hypothesis does not own the seed
   delete fWorkHyp;
   //
-#ifdef  _FILL_CONTROL_HISTOS_
-  if (fCHistoArr) {
+#ifdef  _ITSU_TUNING_MODE_
+  if (fCHistoArrCorr || fCHistoArrFake) {
     TFile* ctrOut = TFile::Open("itsuControlHistos.root","recreate");
     ctrOut->cd();
     AliInfo("Storing control histos");
-    fCHistoArr->Print();
     //    ctrOut->WriteObject(fCHistoArr,"controlH","kSingleKey");
-    fCHistoArr->Write();
+    if (fCHistoArrCorr) {
+      fCHistoArrCorr->Write();
+      delete fCHistoArrCorr;
+    }
+    if (fCHistoArrFake) {
+      fCHistoArrFake->Write();
+      delete fCHistoArrFake;
+    }
     ctrOut->Close();
     delete ctrOut;
-    fCHistoArr = 0;
+    fCHistoArrCorr = 0;
+    fCHistoArrFake = 0;    
   }
 #endif 
   //
@@ -157,8 +164,9 @@ Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
   AliCodeTimerAuto("",0);
   SetTrackingPhase(kClus2Tracks);
   //
-#ifdef  _FILL_CONTROL_HISTOS_
-  if (!fCHistoArr) BookControlHistos();
+#ifdef  _ITSU_TUNING_MODE_
+  if (!fCHistoArrCorr) BookControlHistos("Corr");
+  if (!fCHistoArrFake) BookControlHistos("Fake");
 #endif
   static int evID = 0;
   static TArrayF esdTrPt(fESDIndex.GetSize()); 
@@ -194,7 +202,7 @@ Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
   //
   fITS->ProcessClusters();
   //
-#ifdef  _FILL_CONTROL_HISTOS_
+#ifdef  _ITSU_TUNING_MODE_
   FlagSplitClusters(); // tmp RS
 #endif
   //
@@ -319,7 +327,6 @@ Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent *esdEv)
       if (ndf>0) chi2 /= ndf;
       fCurrHyp->SetChi2(chi2);
       UpdateESDTrack(fCurrHyp,AliESDtrack::kITSout);
-      fCountITSout++;
     }
     else {
       AliDebug(2,Form("Refit Failed for track %d | ESDtrack#%d (MClb:%d)",itr,fCurrESDtrack->GetID(),fCurrESDtrMClb));
@@ -365,7 +372,6 @@ Int_t AliITSUTrackerGlo::RefitInward(AliESDEvent *esdEv)
     if (chi2>0) { // propagate up to inside radius of the beam pipe      
       fCurrHyp->SetChi2(chi2);
       UpdateESDTrack(fCurrHyp,AliESDtrack::kITSrefit);
-      fCountITSrefit++;
     }
     else {
       AliDebug(2,Form("Refit Failed for track %d |ESDtrack#%d (MClb:%d)",itr,fCurrESDtrack->GetID(),fCurrESDtrMClb));
@@ -555,8 +561,10 @@ void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
        double penalty = -fCurrTrackCond->GetMissPenalty(ila);
        // to do: make penalty to account for probability to miss the cluster for good reason
        seedSkp->SetChi2Cl(penalty);
-       AddSeedBranch(seedSkp);
-       //      AddProlongationHypothesis(seedSkp,ila);      
+       if (seedSkp->GetChi2GloNrm()>fCurrTrackCond->GetMaxChi2GloNrm(ila)) {
+         MarkSeedFree(seedSkp);
+       }
+       else AddSeedBranch(seedSkp);
       }
       // transfer the new branches of the seed to the hypothesis container
       if (fNBranchesAdded) ValidateAllowedBranches(maxNBranches);
@@ -922,11 +930,11 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   if (cl->GetLabel(0)>=0) {
     for (int i=0;i<3;i++) if (cl->GetLabel(i)>=0 && cl->GetLabel(i)==currLabel) {goodCl = kTRUE; break;}
   }
-  Bool_t goodSeed = !track->ContainsFake();
   //
   if (TMath::Abs(cl->GetX())>kTolerX) { // if due to the misalingment X is large, propagate track only
     if (!track->PropagateParamOnlyTo(track->GetX()+cl->GetX(),GetBz())) {
-      if (goodCl&&goodSeed && AliDebugLevelClass()>2 ) {
+      //
+      if (AliDebugLevelClass()>2 && goodCl && !track->ContainsFake()) {
        AliDebug(2,Form("Lost good cl on L:%d failed propagation. |ESDtrack#%d (MClb:%d)",lr,fCurrESDtrack->GetID(),fCurrESDtrMClb)); 
        track->Print("etp");
        cl->Print();
@@ -937,25 +945,12 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   double dy = cl->GetY()-track->GetY();
   double dz = cl->GetZ()-track->GetZ();
   //
-#ifdef  _FILL_CONTROL_HISTOS_
-  int hcOffs = (1+fTrackPhase)*kHistosPhase + lr;
-  double htrPt=-1;
-  if (goodCl && (((AliITSUClusterPix*)cl)->GetNPix()>1 || !((AliITSUClusterPix*)cl)->IsSplit()) && goodSeed && fCHistoArr /* && track->GetChi2Penalty()<1e-5*/) {
-    htrPt = track->Pt();
-    ((TH2*)fCHistoArr->At(kHResY+hcOffs))->Fill(htrPt,dy);
-    ((TH2*)fCHistoArr->At(kHResZ+hcOffs))->Fill(htrPt,dz);
-    double errY = track->GetSigmaY2();
-    double errZ = track->GetSigmaZ2();
-    if (errY>0) ((TH2*)fCHistoArr->At(kHResYP+hcOffs))->Fill(htrPt,dy/Sqrt(errY));
-    if (errZ>0) ((TH2*)fCHistoArr->At(kHResZP+hcOffs))->Fill(htrPt,dz/Sqrt(errZ));
-  }
-#endif  
-  //
   double dy2 = dy*dy;
   double tol2 = (track->GetSigmaY2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(lr))*
     fCurrTrackCond->GetNSigmaRoadY(lr)*fCurrTrackCond->GetNSigmaRoadY(lr); // RS TOOPTIMIZE
   if (dy2>tol2) {                          // the clusters are sorted in Z(col) then in Y(row). 
-    if (goodCl&&goodSeed && AliDebugLevelClass()>2) {    
+    //
+    if (AliDebugLevelClass()>2 && goodCl &&  !track->ContainsFake()) {    
       AliDebug(2,Form("Lost good cl: dy2=%e > tol2=%e |ESDtrack#%d (MClb:%d)",dy2,tol2,fCurrESDtrack->GetID(),fCurrESDtrMClb)); 
       track->Print("etp");
       cl->Print();
@@ -970,7 +965,7 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   tol2 = (track->GetSigmaZ2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(lr))*
     fCurrTrackCond->GetNSigmaRoadZ(lr)*fCurrTrackCond->GetNSigmaRoadZ(lr); // RS TOOPTIMIZE
   if (dz2>tol2) {
-    if (goodCl&&goodSeed && AliDebugLevelClass()>2) {
+    if (AliDebugLevelClass()>2 && goodCl &&  !track->ContainsFake()) {
       AliDebug(2,Form("Lost good cl on L:%d : dz2=%e > tol2=%e |ESDtrack#%d (MClb:%d)",lr,dz2,tol2,fCurrESDtrack->GetID(),fCurrESDtrMClb)); 
       track->Print("etp");
       cl->Print();
@@ -984,14 +979,8 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   Double_t cov[3]={cl->GetSigmaY2(), cl->GetSigmaYZ(), cl->GetSigmaZ2()};
   double chi2 = track->GetPredictedChi2(p,cov);
   //
-#ifdef  _FILL_CONTROL_HISTOS_
-  if (htrPt>0) {
-    ((TH2*)fCHistoArr->At(kHChi2Cl+hcOffs))->Fill(htrPt,chi2);
-  }
-#endif
-  //
   if (chi2>fCurrTrackCond->GetMaxTr2ClChi2(lr)) {
-    if (goodCl&&goodSeed && AliDebugLevelClass()>2) {
+    if (AliDebugLevelClass()>2 && goodCl &&  !track->ContainsFake()) {
       AliDebug(2,Form("Lost good cl on L:%d : Chi2=%e > Chi2Max=%e |dy: %+.3e dz: %+.3e |ESDtrack#%d (MClb:%d)\n",
                      lr,chi2,fCurrTrackCond->GetMaxTr2ClChi2(lr),dy,dz,fCurrESDtrack->GetID(),fCurrESDtrMClb)); 
       track->Print("etp");
@@ -1003,7 +992,7 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   //
   track = NewSeedFromPool(track);  // input track will be reused, use its clone for updates
   if (!track->Update()) {
-    if (goodCl&&goodSeed && AliDebugLevelClass()>2) {
+    if (AliDebugLevelClass()>2 && goodCl &&  !track->ContainsFake()) {
       AliDebug(2,Form("Lost good cluster on L:%d : failed to update",lr));
       track->Print("etp");
       cl->Print("");
@@ -1014,6 +1003,18 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
   }
   track->SetChi2Cl(chi2);
   track->SetLrClusterID(lr,clID);
+  //
+  if (track->GetChi2GloNrm()>fCurrTrackCond->GetMaxChi2GloNrm(lr)) {
+    if (AliDebugLevelClass()>2 && goodCl &&  !track->ContainsFake()) {
+      AliDebug(2,Form("Lost good cl on L:%d : Chi2Glo=%e > Chi2Max=%e |dy: %+.3e dz: %+.3e |ESDtrack#%d (MClb:%d)\n",
+                     lr,track->GetChi2GloNrm(),fCurrTrackCond->GetMaxChi2GloNrm(lr),dy,dz,fCurrESDtrack->GetID(),fCurrESDtrMClb)); 
+      track->Print("etp");
+      cl->Print("");
+      PrintSeedClusters(track);
+    }
+    MarkSeedFree(track);
+    return kClusterNotMatching;
+  }
   //  cl->IncreaseClusterUsage(); // do this only for winners
   //
   track->SetFake(!goodCl);
@@ -1022,11 +1023,6 @@ Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
               goodCl,clID,lr,dy,dz2,cl->GetLabel(0),cl->GetLabel(1),cl->GetLabel(2), chi2, track->IsFake() ? '-':'+'));
   //
   AddSeedBranch(track);
-#ifdef  _FILL_CONTROL_HISTOS_
-  if (htrPt>0) {
-    ((TH2*)fCHistoArr->At(kHChi2Nrm+hcOffs))->Fill(htrPt,track->GetChi2GloNrm());
-  }
-#endif
   //
   return kClusterMatching;
 }
@@ -1149,30 +1145,40 @@ Bool_t AliITSUTrackerGlo::FinalizeHypothesis(AliITSUTrackHyp* hyp)
   fCurrHyp = hyp;
   fCurrMass = hyp->GetMass();
   if (!(winner=hyp->DefineWinner())) return kFALSE;
-  FlagSeedClusters(winner,kTRUE);
   CookMCLabel(hyp);
   //
-#ifdef  _FILL_CONTROL_HISTOS_
-  if (fCHistoArr) {
-    TH2* hchimt = 0;
-    TH2* hchiSA = 0;
-    int lb = Abs(hyp->GetESDTrack()->GetTPCLabel());
-    if ( hyp->GetITSLabel()==lb ) {
-      hchimt = (TH2*)fCHistoArr->At(kHChiMatchCorr);
-      hchiSA = (TH2*)fCHistoArr->At(kHChiITSSACorr);
-    }
-    else if ( Abs(hyp->GetITSLabel()) == lb ) hchimt = (TH2*)fCHistoArr->At(kHChiMatchFake);
-    else if ( hyp->GetITSLabel()>=0 ) hchimt = (TH2*)fCHistoArr->At(kHChiMatchCorrMiss);
-    else hchimt = (TH2*)fCHistoArr->At(kHChiMatchFakeMiss);
-    if (!hchiSA) hchiSA =  (TH2*)fCHistoArr->At(kHChiITSSAFake);
-    //    printf("MTStatus: ITS:%+5d TPC:%+5d chimt:%e chi2SA:%e-> %s\n",hyp->GetITSLabel(),lb,winner->GetChi2ITSTPC(),winner->GetChi2ITSSA(),hchimt->GetName());
-    if (hchimt) hchimt->Fill(hyp->GetTPCSeed()->Pt(),winner->GetChi2ITSTPC());
-    if (hchiSA) hchiSA->Fill(hyp->GetTPCSeed()->Pt(),winner->GetChi2ITSSA());      
+#ifdef  _ITSU_TUNING_MODE_  // fill tuning histos
+  TObjArray* dest = hyp->GetLabel()>=0 ? fCHistoArrCorr : fCHistoArrFake;
+  if (dest) {
+    AliITSUSeed* sd = winner;
+    double htrPt = hyp->Pt();
+    do {
+      int clID,lrID;
+      if ( (clID=sd->GetLrCluster(lrID))<0 ) continue;
+      int hcOffs = (1+fTrackPhase)*kHistosPhase + lrID;
+      ((TH2*)dest->At(kHChi2Nrm+hcOffs))->Fill(htrPt,sd->GetChi2GloNrm());
+      ((TH2*)dest->At(kHBestInBranch+hcOffs))->Fill(htrPt,sd->GetOrdBranch());
+      ((TH2*)dest->At(kHBestInCand+hcOffs))->Fill(htrPt,  sd->GetOrdCand());
+      //
+      if (dest==fCHistoArrFake && !sd->IsFake()) continue; // for the fake seeds fill only fake clusters part
+      //
+      ((TH2*)dest->At(kHResY+hcOffs))->Fill(htrPt,sd->GetResidY());
+      ((TH2*)dest->At(kHResZ+hcOffs))->Fill(htrPt,sd->GetResidZ());
+      ((TH2*)dest->At(kHResYP+hcOffs))->Fill(htrPt,sd->GetPullY());
+      ((TH2*)dest->At(kHResZP+hcOffs))->Fill(htrPt,sd->GetPullZ());
+      ((TH2*)dest->At(kHChi2Cl+hcOffs))->Fill(htrPt,sd->GetChi2Cl());
+      //
+    } while((sd=(AliITSUSeed*)sd->GetParent()));
+    //
+    ((TH2*)dest->At(kHChiMatch))->Fill(htrPt,winner->GetChi2ITSTPC());
+    ((TH2*)dest->At(kHChiITSSA))->Fill(htrPt,winner->GetChi2ITSSA());
   }
-#endif    
   //
-  UpdateESDTrack(hyp,AliESDtrack::kITSin);
-  return kTRUE;
+#endif
+  //
+  CheckClusterSharingConflicts(hyp);
+  return hyp->GetWinner();  // winner might change of disappear after resolving conflicts
+  //
 }
 
 //______________________________________________________________________________
@@ -1183,101 +1189,119 @@ void AliITSUTrackerGlo::FinalizeHypotheses()
   AliDebug(2,"TODO");
   //
   int nh = fHypStore.GetEntriesFast();
-  for (int ih=0;ih<nh;ih++) {
-    if (FinalizeHypothesis( GetTrackHyp(ih) )) fCountITSin++;
-  }
+  for (int ih=0;ih<nh;ih++) FinalizeHypothesis(GetTrackHyp(ih));
   //
-  AliITSUSeed* winner = 0;
-
-#ifdef  _FILL_CONTROL_HISTOS_
-  // if requested, collect cluster sharing statistics
-  TH2* hShare = 0;
-  if (fCHistoArr && (hShare=(TH2*)fCHistoArr->At(kHClShare))) {
-    for (int ih=0;ih<nh;ih++) {
-      AliITSUTrackHyp* hyp = GetTrackHyp(ih);
-      if (!hyp || !(winner=hyp->GetWinner())) continue;
-      int lrID = 0;
-      double pt = hyp->Pt();
-      do {
-       int clID = winner->GetLrCluster(lrID);
-       if (clID<0) continue;
-       AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
-       if (!cl->IsClusterShared()) continue;
-       hShare->Fill(pt,winner->IsFake() ? lrID+fNLrActive : lrID);
-      } while ((winner=(AliITSUSeed*)winner->GetParent()));
-    }  
-  }
-#endif  
+  for (int ih=0;ih<nh;ih++) UpdateESDTrack(GetTrackHyp(ih),AliESDtrack::kITSin);
+  //
+}
 
-  if (AliDebugLevelClass()>+2) {
+//______________________________________________________________________________
+void AliITSUTrackerGlo::CheckClusterSharingConflicts(AliITSUTrackHyp* hyp)
+{
+  // remove eventual cluster sharing conflicts
+  AliITSUSeed* winner = 0;
+  if (!(winner=hyp->GetWinner())) return;
+  UShort_t idH = (UShort_t)hyp->GetUniqueID()+1;
+  int lrID,clID;
+  AliITSUSeed* winSD=winner;
+  do {
+    if ( (clID=winSD->GetLrCluster(lrID))<0 ) continue;
+    AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
+    Int_t refID = cl->GetRecoInfo();                // was it already referred by some track (with refID-1 if >0)
+    if (!refID) {cl->SetRecoInfo(idH); continue;}   // if not, refer from track to cluster
+    if (refID==idH) continue;                          // ignore reference to itself
+    // the cluster is already used by other track, need to resolve the conflict
+    AliITSUTrackHyp* hypC = GetTrackHyp(refID-1);   // competitor
+    //    printf("Ref to %d (%p) from %d Cl %d %d\n",refID-1,hypC, idH-1,clID,lrID);
+    AliITSUSeed* winnerC = hypC->GetWinner();
+    if (!winnerC) {
+      printf("Missing winner, ERROR\n");
+      continue;
+    }
     //
-    AliRefArray** refArr = new AliRefArray*[fNLrActive];
-    for (int ilr=0;ilr<fNLrActive;ilr++) refArr[ilr] = new AliRefArray(1000);
-    for (int ih=0;ih<nh;ih++) {
-      AliITSUTrackHyp* hyp = GetTrackHyp(ih);
-      if (!hyp || !(winner=hyp->GetWinner())) continue;
-      int lrID = 0;
+    if (AliDebugLevelClass()>1) { //------------------------ DEBUG -------------------
+      AliInfo(Form("Shared cl#%4d on Lr:%d: Hyp%3d/Q:%6.3f vs Hyp%3d/Q:%6.3f",
+                  clID,lrID,idH-1,winner->GetQualityVar(),refID-1,winnerC->GetQualityVar()));
+      // dump winner of hyp
+      printf("#%4d Pt:%.3f Chi:%6.3f/%6.3f/%6.3f Ncl:%d MCits%+5d MCtpc:%+5d |",
+            idH-1,winner->Pt(),winner->GetChi2GloNrm(),winner->GetChi2ITSTPC(),winner->GetChi2ITSSA(),
+            winner->GetNLayersHit(),hyp->GetITSLabel(),hyp->GetESDTrack()->GetTPCLabel());
+      int prevL=-1;
+      AliITSUSeed* sd = winner;
+      do {
+       int lrs;
+       int clIDt = sd->GetLrCluster(lrs);
+       if (clIDt<0) continue;
+       while( lrs>++prevL ) printf("%4s        ","----");
+       printf("%4d (%5.1f)",clIDt,sd->GetChi2Cl());
+      } while ((sd=(AliITSUSeed*)sd->GetParent()));
+      printf("|\n");
+      // dump winner of hypC
+      printf("#%4d Pt:%.3f Chi:%6.3f/%6.3f/%6.3f Ncl:%d MCits%+5d MCtpc:%+5d |",
+            refID-1,winnerC->Pt(),winnerC->GetChi2GloNrm(),winnerC->GetChi2ITSTPC(),winnerC->GetChi2ITSSA(),
+            winnerC->GetNLayersHit(),hypC->GetITSLabel(),hypC->GetESDTrack()->GetTPCLabel());
+      prevL=-1;
+      sd = winnerC;
       do {
-       int clID = winner->GetLrCluster(lrID);
-       if (clID<0) continue;
-       AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
-       if (!cl->IsClusterShared()) continue;
-       refArr[lrID]->AddReference(clID,ih);
-      } while ((winner=(AliITSUSeed*)winner->GetParent()));
+       int lrs;
+       int clIDt = sd->GetLrCluster(lrs);
+       if (clIDt<0) continue;
+       while( lrs>++prevL ) printf("%4s        ","----");
+       printf("%4d (%5.1f)",clIDt,sd->GetChi2Cl());
+      } while ((sd=(AliITSUSeed*)sd->GetParent()));
+      printf("|\n");
+    }  //-------------------------------------------------- DEBUG -------------------
+    //
+    if (winner->GetQualityVar()<winnerC->GetQualityVar()) { // current tracks is better then competitor track
+      FlagSeedClusters(winnerC,kFALSE,refID); // unflag cluster usage by loser
+      cl->SetRecoInfo(idH);
+      //
+      //if ( hypC->GetLabel()>=0) AliInfo(Form("KILLING CORRECT: %d",refID-1));
+      winnerC->Kill();
+      if (hypC->DefineWinner()) {             // find new winner instead of suppressed candidate
+       CookMCLabel(hypC);
+       CheckClusterSharingConflicts(hypC);   // and check its sharing conflicts again
+       if (winner->IsKilled()) break;        // the current winner might have been killed during check of new winner of hypC!
+      }
     }    
-    UInt_t refs[100];
-    for (int ilr=0;ilr<fNLrActive;ilr++) {
-      int ncl = fITS->GetLayerActive(ilr)->GetNClusters();
-      printf("\nClusterSharingDump: Lr %d (%d cl)\n",ilr,ncl);
-      int cnt = 0;
-      for (int icl=0;icl<ncl;icl++) {
-       if (!refArr[ilr]->HasReference(icl)) continue;
-       int nref = refArr[ilr]->GetReferences(icl,refs,100);
-       printf("--- cl%3d(#%d): NShare=%4d\n",cnt++,icl,nref);     
-       for (int ir=0;ir<nref;ir++) {
-         AliITSUTrackHyp* hyp = GetTrackHyp(refs[ir]);
-         winner = hyp->GetWinner();
-         AliESDtrack* esdTr = hyp->GetESDTrack();
-         printf("#%4d Pt:%.3f Chi:%6.2f Ncl:%d MCits%+5d MCtpc:%+5d ESD:%4d |",
-                refs[ir],winner->Pt(),winner->GetChi2GloNrm(),winner->GetNLayersHit(),
-                hyp->GetITSLabel(),esdTr->GetTPCLabel(),esdTr->GetID());
-         int prevL=-1;
-         do {
-           int lrs;
-           int clID = winner->GetLrCluster(lrs);
-           if (clID<0) continue;
-           while( lrs>++prevL ) printf("%4s        ","----");
-           printf("%4d (%5.1f)",clID,winner->GetChi2Cl());
-         } while ((winner=(AliITSUSeed*)winner->GetParent()));
-         printf("|\n");
-       }
+    else { // competitor hypC is better than the hyp
+      FlagSeedClusters(winner,kFALSE,idH); // unflag cluster usage by loser
+      winner->Kill();
+      //if ( hyp->GetLabel()>=0) AliInfo(Form("KILLING CORRECT: %d",idH-1));
+      if (hyp->DefineWinner()) {
+       CookMCLabel(hyp);
+       CheckClusterSharingConflicts(hyp);
       }
+      break;
     }
-    delete[] refArr;
-  
-  } // debug only
-
+    //   
+  } while ((winSD=(AliITSUSeed*)winSD->GetParent()));
+  //
+  return;
 }
 
 //______________________________________________________________________________
 void AliITSUTrackerGlo::UpdateESDTrack(AliITSUTrackHyp* hyp,Int_t flag)
 {
   // update ESD track with current best hypothesis
+  if (!hyp) return;
   AliESDtrack* esdTr = hyp->GetESDTrack();
   if (!esdTr) return;
   AliITSUSeed* win = hyp->GetWinner();
-  if (!win) return;
+  if (!win || win->IsKilled()) return;
   double chiSav;
   //
   switch (flag) {
   case AliESDtrack::kITSin: 
     esdTr->UpdateTrackParams(hyp,flag); // update kinematics
+    fCountITSin++;
     // TODO: set cluster info
     break;
     //
   case AliESDtrack::kITSout: 
     // here the stored chi2 will correspond to backward ITS-SA fit
     esdTr->UpdateTrackParams(hyp,flag); // update kinematics
+    fCountITSout++;
     // TODO: avoid setting friend
     break;
     //
@@ -1288,6 +1312,7 @@ void AliITSUTrackerGlo::UpdateESDTrack(AliITSUTrackHyp* hyp,Int_t flag)
     hyp->SetChi2(win->GetChi2ITSTPC());
     esdTr->UpdateTrackParams(hyp,flag); // update kinematics
     hyp->SetChi2(chiSav);
+    fCountITSrefit++;
     // TODO: avoid setting cluster info
     break;
   default:
@@ -1382,20 +1407,21 @@ Double_t AliITSUTrackerGlo::RefitTrack(AliExternalTrackParam* trc, Double_t rDes
       double chi2cl = tmpTr.GetPredictedChi2(p,cov);
       chi2 += chi2cl;
       //
-#ifdef  _FILL_CONTROL_HISTOS_
-      int hcOffs = (1+fTrackPhase)*kHistosPhase + ilrA;
-      double htrPt=-1;
-      if (fCHistoArr && fTrackPhase>kClus2Tracks && trc->GetLabel()>=0/* && trc->Charge()>0*/) {
-       htrPt = tmpTr.Pt();
+#ifdef  _ITSU_TUNING_MODE_
+      TObjArray* dest = trc->GetLabel()>=0 ? fCHistoArrCorr : fCHistoArrFake;
+      if (dest && fTrackPhase>kClus2Tracks) {
+       int hcOffs = (1+fTrackPhase)*kHistosPhase + ilrA;
+       //
+       double htrPt = tmpTr.Pt();
        double dy = p[0]-tmpTr.GetY();
        double dz = p[1]-tmpTr.GetZ();
-       ((TH2*)fCHistoArr->At(kHResY+hcOffs))->Fill(htrPt,dy);
-       ((TH2*)fCHistoArr->At(kHResZ+hcOffs))->Fill(htrPt,dz);
+       ((TH2*)dest->At(kHResY+hcOffs))->Fill(htrPt,dy);
+       ((TH2*)dest->At(kHResZ+hcOffs))->Fill(htrPt,dz);
        double errY = tmpTr.GetSigmaY2();
        double errZ = tmpTr.GetSigmaZ2();
-       if (errY>0) ((TH2*)fCHistoArr->At(kHResYP+hcOffs))->Fill(htrPt,dy/Sqrt(errY));
-       if (errZ>0) ((TH2*)fCHistoArr->At(kHResZP+hcOffs))->Fill(htrPt,dz/Sqrt(errZ));
-       ((TH2*)fCHistoArr->At(kHChi2Cl+hcOffs))->Fill(htrPt,chi2cl);
+       if (errY>0) ((TH2*)dest->At(kHResYP+hcOffs))->Fill(htrPt,dy/Sqrt(errY));
+       if (errZ>0) ((TH2*)dest->At(kHResZP+hcOffs))->Fill(htrPt,dz/Sqrt(errZ));
+       ((TH2*)dest->At(kHChi2Cl+hcOffs))->Fill(htrPt,chi2cl);
       }
 #endif  
       //      
@@ -1524,30 +1550,12 @@ void AliITSUTrackerGlo::ValidateAllowedBranches(Int_t acceptMax)
   //  if (nb<fNBranchesAdded) printf("ValidateAllowedBranches: %d of %d (%d) on lr %d\n",nb,fNBranchesAdded,fNCandidatesAdded,ilr);
   // disable unused branches
   AliITSUSeed** branches = &fLayerCandidates[fNCandidatesAdded];
-#ifdef  _FILL_CONTROL_HISTOS_
-  int bestID = -1;
-  for (int ib=0;ib<fNBranchesAdded;ib++) {
-    AliITSUSeed* sd = branches[ib];
-    if (!sd->ContainsFake() && (bestID<0 || sd->Compare(branches[bestID])<0) ) bestID = ib;
-  }
-  if (bestID>=0) {
-    TH2* hb = (TH2*)fCHistoArr->At(kHBestInBranch + (1+fTrackPhase)*kHistosPhase + fCurrActLrID);
-    if (hb) hb->Fill(branches[bestID]->Pt(), bestID);
-  }
+  //
+#ifdef  _ITSU_TUNING_MODE_
+  for (int ib=0;ib<fNBranchesAdded;ib++) branches[ib]->SetOrdBranch(ib);
 #endif
   //
-  for (int ib=nb;ib<fNBranchesAdded;ib++) {
-    //
-#ifdef  _FILL_CONTROL_HISTOS_    
-    if (AliDebugLevelClass()>-2 && !branches[ib]->ContainsFake() /*&& branches[ib]->GetNLayersHit()*/
-       && (bestID<0 || branches[ib]->Compare(branches[bestID])<0 ) ) {
-      printf("Suppress good branch as %d of %d |",ib,fNBranchesAdded); branches[ib]->Print();
-      //      printf("Survivors : \n");
-      //      for (int j=0;j<nb;j++) branches[j]->Print();
-    }
-#endif    
-    MarkSeedFree(branches[ib]);
-  }
+  for (int ib=nb;ib<fNBranchesAdded;ib++) MarkSeedFree(branches[ib]);
   fNCandidatesAdded += nb; // update total candidates counter
   fNBranchesAdded = 0; // reset branches counter
   //
@@ -1573,18 +1581,6 @@ void AliITSUTrackerGlo::ValidateAllowedCandidates(Int_t ilr, Int_t acceptMax)
   for (int i=fNCandidatesAdded;i--;) chi2[i] = fLayerCandidates[i]->GetChi2GloNrm();
   Sort(fNCandidatesAdded,chi2,index,kFALSE);
   //
-#ifdef  _FILL_CONTROL_HISTOS_
-  int bestID = -1;
-  for (int ib=0;ib<fNCandidatesAdded;ib++) {
-    AliITSUSeed* sd = fLayerCandidates[index[ib]];
-    if (!sd->ContainsFake() && (bestID<0 || sd->Compare(fLayerCandidates[index[bestID]])<0) ) bestID = ib;
-  }
-  if (bestID>=0) {
-    TH2* hb = (TH2*)fCHistoArr->At(kHBestInCand + (1+fTrackPhase)*kHistosPhase + fCurrActLrID);
-    if (hb) hb->Fill(fLayerCandidates[index[bestID]]->Pt(), bestID);
-  }
-#endif
-  //
   int nacc=0,nb=0;
   if (ilr>0) { // just take 1st acceptMax candidates
     nb = Min(fNCandidatesAdded,acceptMax);
@@ -1603,18 +1599,8 @@ void AliITSUTrackerGlo::ValidateAllowedCandidates(Int_t ilr, Int_t acceptMax)
     }
     fCurrHyp->SetWinner(wn0); // restore original winner (NULL?)
   }
-  //
   // disable unused candidates
-  for (int ib=nb;ib<fNCandidatesAdded;ib++) {
-    //
-#ifdef  _FILL_CONTROL_HISTOS_
-    if (AliDebugLevelClass()>-2 && !fLayerCandidates[index[ib]]->ContainsFake() /*&& fLayerCandidates[index[ib]]->GetNLayersHit()*/
-       && (bestID<0 || fLayerCandidates[index[ib]]->Compare(fLayerCandidates[index[bestID]])<0 ) ) {
-      printf("Suppress good candidate as %d of %d |",index[ib],fNCandidatesAdded); fLayerCandidates[index[ib]]->Print();
-    }
-#endif
-    MarkSeedFree(fLayerCandidates[index[ib]]);    
-  }
+  for (int ib=nb;ib<fNCandidatesAdded;ib++) MarkSeedFree(fLayerCandidates[index[ib]]);    
   fNCandidatesAdded = 0; // reset candidates counter
   //
 }
@@ -1735,29 +1721,42 @@ void AliITSUTrackerGlo::PrintSeedClusters(const AliITSUSeed* seed, Option_t* opt
 }
 
 //__________________________________________________________________
-void AliITSUTrackerGlo::FlagSeedClusters(const AliITSUSeed* seed, Bool_t flg)
+void AliITSUTrackerGlo::FlagSeedClusters(const AliITSUSeed* seed, Bool_t flg, UShort_t ref)
 {
   // mark used clusters
   int lrID,clID;
   while (seed) {
-    if ( (clID=seed->GetLrCluster(lrID))>=0 ) ((AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID))->ModClUsage(flg);
+    if ( (clID=seed->GetLrCluster(lrID))>=0 ) {
+      AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
+      if (ref) { // do we need to set or delete cluster->track ref?
+       if (flg) {
+         if (!cl->GetRecoInfo()) cl->SetRecoInfo(ref);  // set ref only if cluster already does not refer to other track, inc.counter
+       }
+       else {
+         if (cl->GetRecoInfo()==ref) cl->SetRecoInfo(0); // unset reference only if it refers to ref, decrease counter     
+       }
+      }
+    }
     seed = (AliITSUSeed*)seed->GetParent();
   }
   //
 }
 
-
-
-#ifdef  _FILL_CONTROL_HISTOS_
+#ifdef  _ITSU_TUNING_MODE_
 //__________________________________________________________________
-void AliITSUTrackerGlo::BookControlHistos()
+void AliITSUTrackerGlo::BookControlHistos(const char* pref)
 {
   // book special control histos
-  if (fCHistoArr) return;
+  TString prefS = pref;
+  prefS.ToLower();
+  TObjArray* dest = 0;
+  if      (prefS=="corr") dest = fCHistoArrCorr = new TObjArray();
+  else if (prefS=="fake") dest = fCHistoArrFake = new TObjArray();
+  else    {AliError(Form("Unknown histo set %s is requested",pref)); return;}
+  dest->SetOwner(kTRUE);
+  //
   const int kNResDef=7;
   const double kResDef[kNResDef]={0.05,0.05,0.3, 0.05,1,0.5,1.5};
-  fCHistoArr = new TObjArray();
-  fCHistoArr->SetOwner(kTRUE);
   const double ptMax=10;
   const double plMax=10;
   const double chiMax=100;
@@ -1772,88 +1771,63 @@ void AliITSUTrackerGlo::BookControlHistos()
     for (int ilr=0;ilr<fNLrActive;ilr++) {
       int hoffs = (1+stp)*kHistosPhase + ilr;
       double mxdf = ilr>=kNResDef ? kResDef[kNResDef-1] : kResDef[ilr];
-      ttl = Form("S%d_residY%d",stp,ilr);
+      ttl = Form("S%d_residY%d_%s",stp,ilr,pref);
       TH2F* hdy = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nresbins,-mxdf,mxdf);
-      fCHistoArr->AddAtAndExpand(hdy,hoffs + kHResY);
+      dest->AddAtAndExpand(hdy,hoffs + kHResY);
       hdy->SetDirectory(0);
       //
-      ttl = Form("S%d_residYPull%d",stp,ilr);  
+      ttl = Form("S%d_residYPull%d_%s",stp,ilr,pref);  
       TH2F* hdyp = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nplbins,-plMax,plMax);
-      fCHistoArr->AddAtAndExpand(hdyp,hoffs + kHResYP);
+      dest->AddAtAndExpand(hdyp,hoffs + kHResYP);
       hdyp->SetDirectory(0);
       //
-      ttl = Form("S%d_residZ%d",stp,ilr);      
+      ttl = Form("S%d_residZ%d_%s",stp,ilr,pref);      
       TH2F* hdz = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nresbins,-mxdf,mxdf);
-      fCHistoArr->AddAtAndExpand(hdz,hoffs + kHResZ);
+      dest->AddAtAndExpand(hdz,hoffs + kHResZ);
       hdz->SetDirectory(0);
       //
-      ttl = Form("S%d_residZPull%d",stp,ilr);          
+      ttl = Form("S%d_residZPull%d_%s",stp,ilr,pref);          
       TH2F* hdzp = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nplbins,-plMax,plMax);
       hdzp->SetDirectory(0);
-      fCHistoArr->AddAtAndExpand(hdzp,hoffs + kHResZP);
+      dest->AddAtAndExpand(hdzp,hoffs + kHResZP);
       //
-      ttl = Form("S%d_chi2Cl%d",stp,ilr);              
+      ttl = Form("S%d_chi2Cl%d_%s",stp,ilr,pref);              
       TH2F* hchi = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
       hchi->SetDirectory(0);
-      fCHistoArr->AddAtAndExpand(hchi,hoffs + kHChi2Cl);
+      dest->AddAtAndExpand(hchi,hoffs + kHChi2Cl);
       //
-      ttl = Form("S%d_chi2Nrm%d",stp,ilr);             
+      ttl = Form("S%d_chi2Nrm%d_%s",stp,ilr,pref);             
       TH2F* hchiN = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
       hchiN->SetDirectory(0);
-      fCHistoArr->AddAtAndExpand(hchiN,hoffs + kHChi2Nrm);
+      dest->AddAtAndExpand(hchiN,hoffs + kHChi2Nrm);
       //
       if (stp==0) { // these histos make sense only for clusters2tracks stage
-       ttl = Form("S%d_bestInBranch%d",stp,ilr);               
+       ttl = Form("S%d_bestInBranch%d_%s",stp,ilr,pref);               
        TH2* hnbr = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, maxBr,-0.5,maxBr-0.5);
        hnbr->SetDirectory(0);
-       fCHistoArr->AddAtAndExpand(hnbr,hoffs + kHBestInBranch);
+       dest->AddAtAndExpand(hnbr,hoffs + kHBestInBranch);
        //
-       ttl = Form("S%d_bestInCands%d",stp,ilr);                
+       ttl = Form("S%d_bestInCands%d_%s",stp,ilr,pref);                
        TH2* hncn = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, maxCand,-0.5,maxCand-0.5);
        hncn->SetDirectory(0);
-       fCHistoArr->AddAtAndExpand(hncn,hoffs + kHBestInCand);
+       dest->AddAtAndExpand(hncn,hoffs + kHBestInCand);
        //
       }
     }
   }
   // custom histos
-  ttl = Form("ClSharing");
-  TH2* hclShare = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, 2*fNLrActive,0,2*fNLrActive);
-  hclShare->SetDirectory(0);
-  fCHistoArr->AddAtAndExpand(hclShare,kHClShare);
   //  
   TH2* hchiMatch = 0; 
-  ttl = Form("Chi2MatchCorr");
-  hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
-  hchiMatch->SetDirectory(0);
-  fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchCorr);
-  // 
-  ttl = Form("Chi2MatchFake");
-  hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
-  hchiMatch->SetDirectory(0);
-  fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchFake);
-  // 
-  ttl = Form("Chi2MatchCorrMiss");
+  ttl = Form("Chi2Match_%s",pref);
   hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
   hchiMatch->SetDirectory(0);
-  fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchCorrMiss);
-  // 
-  ttl = Form("Chi2MatchFakeMiss");
-  hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
-  hchiMatch->SetDirectory(0);
-  fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchFakeMiss);
+  dest->AddAtAndExpand(hchiMatch,kHChiMatch);
   // 
   TH2* hchiSA = 0; 
-  ttl = Form("Chi2ITSSACorr");
+  ttl = Form("Chi2ITSSA_%s",pref);
   hchiSA = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins/2,0.,chiMax/2);
   hchiSA->SetDirectory(0);
-  fCHistoArr->AddAtAndExpand(hchiSA,kHChiITSSACorr);
+  dest->AddAtAndExpand(hchiSA,kHChiITSSA);
   // 
-  ttl = Form("Chi2ITSSAFake");
-  hchiSA = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins/2,0.,chiMax/2);
-  hchiSA->SetDirectory(0);
-  fCHistoArr->AddAtAndExpand(hchiSA,kHChiITSSAFake);
-  // 
-
 }
 #endif
index 74cc793..f7e0dd4 100644 (file)
@@ -3,8 +3,6 @@
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-#define _FILL_CONTROL_HISTOS_
-
 //-------------------------------------------------------------------------
 //                ITS upgrade tracker base class
 //-------------------------------------------------------------------------
@@ -13,6 +11,7 @@
 #include "AliITSUSeed.h"
 #include "AliITSUTrackCond.h"
 #include "AliITSUTrackHyp.h"
+#include "AliITSUAux.h"
 #include <TArrayI.h>
 
 class AliITSUReconstructor;
@@ -91,7 +90,7 @@ class AliITSUTrackerGlo : public AliTracker {
   Bool_t                 AddSeedBranch(AliITSUSeed* seed);
   void                   ValidateAllowedBranches(Int_t accMax);
   void                   ValidateAllowedCandidates(Int_t ilr, Int_t accMax);
-  void                   FlagSeedClusters(const AliITSUSeed* seed, Bool_t flg);
+  void                   FlagSeedClusters(const AliITSUSeed* seed, Bool_t flg, UShort_t hypRef);
   //
   AliITSUSeed*           NewSeedFromPool(const AliITSUSeed* src=0);
   void                   ResetSeedsPool();
@@ -100,6 +99,7 @@ class AliITSUTrackerGlo : public AliTracker {
   AliITSUTrackHyp*       GetTrackHyp(Int_t id)               const  {return (AliITSUTrackHyp*)fHypStore.UncheckedAt(id);}
   void                   SetTrackHyp(AliITSUTrackHyp* hyp,Int_t id) {fHypStore.AddAtAndExpand(hyp,id);}
   void                   DeleteLastSeedFromPool()                   {fSeedsPool.RemoveLast();}
+  void                   CheckClusterSharingConflicts(AliITSUTrackHyp* hyp);
   void                   SaveReducedHypothesesTree(AliITSUTrackHyp* dest);
   void                   FinalizeHypotheses();
   Bool_t                 FinalizeHypothesis(AliITSUTrackHyp* hyp);
@@ -151,13 +151,13 @@ class AliITSUTrackerGlo : public AliTracker {
   //
   static const Double_t           fgkToler;        // tracking tolerance
   //
-#ifdef  _FILL_CONTROL_HISTOS_
+#ifdef  _ITSU_TUNING_MODE_
   // this code is only for special histos needed to extract some control parameters
-  void BookControlHistos();
-  TObjArray* fCHistoArr;
+  void BookControlHistos(const char* pref);
+  TObjArray* fCHistoArrCorr;
+  TObjArray* fCHistoArrFake;
   enum {kHResY=0,kHResYP=10,kHResZ=20,kHResZP=30,kHChi2Cl=40,kHChi2Nrm=50,kHBestInBranch=60,kHBestInCand=70};
-  enum {kHClShare=0,kHChiMatchCorr,kHChiMatchFake,kHChiMatchCorrMiss,kHChiMatchFakeMiss,
-       kHChiITSSACorr,kHChiITSSAFake}; // custom histos 
+  enum {kHChiMatch,kHChiITSSA}; // custom histos 
   enum {kHistosPhase=100};
   //
 #endif
@@ -198,7 +198,10 @@ inline void AliITSUTrackerGlo::KillSeed(AliITSUSeed* seed, Bool_t branch)
 inline void AliITSUTrackerGlo::AddProlongationHypothesis(AliITSUSeed* seed, Int_t lr)
 {
   // add new seed prolongation hypothesis 
-  fCurrHyp->AddSeed(seed,lr);
+#ifdef  _ITSU_TUNING_MODE_
+  seed->SetOrdCand(fCurrHyp->GetNSeeds(lr));
+#endif
+  fCurrHyp->AddSeed(seed,lr);  
 }
 
 #endif
index 4ef6236..8097120 100644 (file)
@@ -34,12 +34,13 @@ void MakeITSRecoParam(AliRecoParam::EventSpecie_t default=AliRecoParam::kLowMult
     recoParamArray->AddLast(itsRecoParam);
   }
   //
-  int nBranch[7] = {10,10,10,10,10,10,10}; // max branching for the seed on layer
-  int nCands[7]  = {10,500,500,500,300,200,100}; // max candidates for the TPC seed
-  float tr2clChi2[7] = {50,50,50,50,50,80,100}; // cut on cluster to track chi2 
+  int nBranch[7] = {5,10,15,4,6,6,10}; // max branching for the seed on layer
+  int nCands[7]  = {10,20,25,20,30,15,20}; // max candidates for the TPC seed
+  float tr2clChi2[7] = {20,20,25,25,25,30,40}; // cut on cluster to track chi2 
+  float gloChi2[7]   = {9, 10,15,20,30,30,30}; // cut on seed global norm chi2
   float missPen[7] = {2.,2.,2.,2.,2.,2.,2.};    // missing cluster penalty
-  float maxChi2Match = 15.;
-  float maxChi2SA    = 15.;  
+  float maxChi2Match = 10.;
+  float maxChi2SA    = 10.;  
   //
   {
     AliITSURecoParam * itsRecoParam = AliITSURecoParam::GetLowFluxParam();
@@ -63,6 +64,7 @@ void MakeITSRecoParam(AliRecoParam::EventSpecie_t default=AliRecoParam::kLowMult
       trCond->SetMaxBranches(i,nBranch[i]);    // each seed propagated to given layer can produce max nBranch branches
       trCond->SetMaxCandidates(i,nCands[i]);   // each tpc track may have at most nCands prolongations
       trCond->SetMaxTr2ClChi2(i,tr2clChi2[i]); // cut on cluster to track chi2
+      trCond->SetMaxChi2GloNrm(i,gloChi2[i]);  // cut on cluster to track global chi2
       trCond->SetMissPenalty(i,missPen[i]);    // missing cluster penalty
       //
     }
@@ -114,6 +116,7 @@ void MakeITSRecoParam(AliRecoParam::EventSpecie_t default=AliRecoParam::kLowMult
       trCond->SetMaxBranches(i,nBranch[i]);    // each seed propagated to given layer can produce max nBranch branches
       trCond->SetMaxCandidates(i,nCands[i]);   // each tpc track may have at most nCands prolongations
       trCond->SetMaxTr2ClChi2(i,tr2clChi2[i]);   // cut on cluster to track chi2
+      trCond->SetMaxChi2GloNrm(i,gloChi2[i]);  // cut on cluster to track global chi2
       trCond->SetMissPenalty(i,missPen[i]);    // missing cluster penalty
       //
     }
index 997a649..29fd236 100644 (file)
Binary files a/ITS/UPGRADE/testITSU/itsupcdb.tar.gz and b/ITS/UPGRADE/testITSU/itsupcdb.tar.gz differ