ROOT logo
#ifndef HMDCLOOKUPTB_H
#define HMDCLOOKUPTB_H

#include "TObject.h"
#include "hparset.h"
#include "hmdcgeomobj.h"
#include "hlocation.h"
#include "hmdcsizescells.h"
#include <stdlib.h>

class TH2C;
class TObjArray;
class HCategory;
class HMdcGeomPar;
class HMdcGetContainers;
class HMdcLayerGeomPar;
class HMdcSizesCells;
class HSpecGeomPar;
class HMdcClus;
class HMdcCluster;
class HMdcClustersArrs;
class HMdcList12GroupCells;
class HMdcClFnStack;
class HMdcClFnStacksArr;
class HMdcSecListCells;
class HMdcDriftTimeParSec;
class HMdcLayListCells;
class HStart2GeomPar;

class HMdcLookUpTbCell: public TObject {
  protected:
    UShort_t  nLines;          // Number of lines (Y-dir.) in cell projections 
    UShort_t  line;            // Counter of lines. After filling should be eq.nLines
    UShort_t  yBinMin;         // First line in the projection
    UShort_t  yBinMax;         // Last line in the projection
    UShort_t *xBinMin;         // First X bin in the projection for each Y line
    UShort_t *xBinMax;         // Last X bin in the projection for each Y line
    Float_t   alphaMean;       // [deg.] Mean value for impact angle
    Float_t   distCutFT;       // [mm] Full target projection. =yPrUncerFTarg*dDistCut
    Float_t   distCut1T;       // [mm] One or piece target pr..=yPrUncer1Targ*dDistCut
    Float_t   distCutVF;       // [mm] For vertex finder.      =yPrUncer1Targ*dDistCutVF
    // For each event:
    Double_t  dDistMinCut;     // = tdcTDist - yProjUncer1T*dDistCut
    Double_t  dDistMaxCut;     // = tdcTDist + yProjUncer1T*dDistCut
    Double_t  dDistMinCut2VF;  // = (tdcTDist - yProjUncer1T*dDistCutVF)^2
    Double_t  dDistMaxCut2VF;  // = (tdcTDist + yProjUncer1T*dDistCutVF)^2
  public:
    HMdcLookUpTbCell(void);
    ~HMdcLookUpTbCell(void);
    void     clear(void) {line=0;}
    void     init(Int_t yBinMinT, Int_t yBinMaxT);
    Bool_t   addLine(UShort_t nc1, UShort_t nc2);
    UShort_t getNLines(void) const             {return line;}
    UShort_t getYBinMin(void) const            {return yBinMin;}
    UShort_t getYBinMax(void) const            {return yBinMax;}
    UShort_t getXBinMin(UInt_t yb) const       {return xBinMin[yb];}
    UShort_t getXBinMax(UInt_t yb) const       {return xBinMax[yb];}
    void     setAlphaMean(Double_t al)         {alphaMean = al;}
    Double_t getAlphaMean(void) const          {return alphaMean;}
    void     setDistCutFT(Double_t ct)         {distCutFT = ct;}
    void     setDistCut1T(Double_t ct)         {distCut1T = ct;}
    void     setDistCut1TVF(Double_t ct)       {distCutVF = ct;}
    void     setTdcTDistAndCuts1T(Double_t d);
    void     setTdcTDistAndCutsFT(Double_t d);
    Double_t getDDistMinCut(void) const        {return dDistMinCut;}
    Double_t getDDistMaxCut(void) const        {return dDistMaxCut;}
    Double_t getDDistMinCut2VF(void) const     {return dDistMinCut2VF;}
    Double_t getDDistMaxCut2VF(void) const     {return dDistMaxCut2VF;}
    
    ClassDef(HMdcLookUpTbCell,0)
};

class HMdcLookUpTbLayer: public TObject {
  protected:
    HMdcSizesCellsLayer* pSCellLay;
    HMdcLookUpTbCell*    pLTCellArr; // max 208
    Int_t    nCells;           // Number of cells in layer
    struct DistCalcLuTb {
      Double_t yt;             // Target position in rot.layer
      Double_t zt;             // coordinate system.
      Double_t C1x;            // LookUpTable for min.dist calc
      Double_t C1y;            //
      Double_t C1;             //
      Double_t C2x;            //
      Double_t C2y;            //
      Double_t C2;             //
      Double_t yVertex;        // One of the point in yTp or yt
      Double_t zVertex;        // One of the point in zTp or zt
      Double_t yTp[250];       // Target position in rot.layer
      Double_t zTp[250];       // coordinate system.
    };
    DistCalcLuTb  layPart1;
    DistCalcLuTb *layPart2;
    
    DistCalcLuTb  *currLayPart;
    
    // For vetex finder mode:
    Int_t    lTargPnt;       // Num_of_elements_in_arrays
    Double_t yWirePos;       // = HMdcSizesCellsCell::getWirePos() for the current cell
    Double_t dDmin;          // = HMdcLookUpTbCell::dDistMinCut for the current cell
    Double_t dDmax;          // = HMdcLookUpTbCell::dDistMaxCut for the current cell
    
  public:
    HMdcLookUpTbLayer(Int_t sec, Int_t mod, Int_t layer);
    ~HMdcLookUpTbLayer(void);
    HMdcLookUpTbCell& operator[](Int_t i) {return pLTCellArr[i];}
    Int_t           getSize(void);
    void            setMinDistLUTb(Int_t lPart,HGeomVector& t,Double_t* carr);
    void            setNTargPnts(Int_t n)           {lTargPnt = n;}
    Double_t*       getYTargetArr(void)             {return layPart1.yTp;}
    Double_t*       getZTargetArr(void)             {return layPart1.zTp;}
    Double_t*       getYTargetArrP2(void)           {return layPart2==NULL ? NULL : layPart2->yTp;}
    Double_t*       getZTargetArrP2(void)           {return layPart2==NULL ? NULL : layPart2->zTp;}
    void            setVertexPoint(Int_t vp);
    void            setCurrentCell(Int_t cell);
    inline Bool_t   drTmTest(Double_t xb,Double_t yb) const;
    inline Bool_t   drTmTest2(Double_t xb,Double_t yb,Double_t corr=0.) const;
    inline void     transToRotLay(Double_t xb,Double_t yb,Double_t &ybl,Double_t &zbl) const;
    DistCalcLuTb   *getLayerPart2Par(void)          {return layPart2;}

    ClassDef(HMdcLookUpTbLayer,0)
};

inline Bool_t HMdcLookUpTbLayer::drTmTest(Double_t xb,Double_t yb) const {
  //  xb - x of bin on the project plot
  //  yb - y of bin
  // current val.:  yVertex=yTp[v]; zVertex=zTp[v],  yOffArr,dDmin2,dDmax2
  Double_t y      = currLayPart->C1x*xb + currLayPart->C1y*yb + currLayPart->C1;
  Double_t z      = currLayPart->C2x*xb + currLayPart->C2y*yb + currLayPart->C2;
  Double_t dyDdz  = (y - currLayPart->yVertex)/(z - currLayPart->zVertex);
  Double_t ct     = 1.+dyDdz*dyDdz;
  Double_t dDist2 = y-dyDdz*z - yWirePos;
  dDist2 *= dDist2;
// printf("New: y=%g,z=%g,dDist=%g,dDmin=%g dDmax=%g",y,z,sqrt(dDist2/ct),sqrt(dDmin2),sqrt(dDmax2));
// printf("  %s\n",dDist2>dDmin2*ct && dDist2<dDmax2*ct ? "in":"out");
  return dDist2>dDmin*dDmin*ct && dDist2<dDmax*dDmax*ct;
}

inline Bool_t HMdcLookUpTbLayer::drTmTest2(Double_t xb,Double_t yb,Double_t corr) const {
  // It calculate the same as 
  // HMdcSizesCellsLayer::getDist(target[0],target[1],target[2],
  //                              xb,yb,prPlane.getZOnPlane(xb,yb), cell);
  // xb - x of bin on the project plot
  // yb - y of bin
  // corr - additional cut correction for bin
  
  //// current val.:  yVertex=yTp[v]; zVertex=zTp[v],  yOffArr,dDmin2,dDmax2
  Double_t y      = currLayPart->C1x*xb + currLayPart->C1y*yb + currLayPart->C1;
  Double_t z      = currLayPart->C2x*xb + currLayPart->C2y*yb + currLayPart->C2;
  Double_t dyDdz  = (y - currLayPart->yVertex)/(z - currLayPart->zVertex);
  Double_t ct     = 1.+dyDdz*dyDdz;
  Double_t dDist2 = y-dyDdz*z - yWirePos;
  dDist2 *= dDist2;
  if(corr<=0.) return dDist2>dDmin*dDmin*ct && dDist2<dDmax*dDmax*ct;
  Double_t dDminCorr = dDmin>corr ? dDmin-corr : 0.;
  Double_t dDmaxCorr = dDmax+corr;
  // Cut: Abs(dDist) < (dDist1T + constUncert)*dDistCut*dDCutCorr[mod][lay]+yDDistCorr[y]
  return dDist2>dDminCorr*dDminCorr*ct && dDist2<dDmaxCorr*dDmaxCorr*ct;
}

inline void HMdcLookUpTbLayer::transToRotLay(Double_t xb,Double_t yb,Double_t &ybl,Double_t &zbl) const {
  // xb and yb must be on the project plane and in sec.coor.sys.
  // This function is used in vertex finder only and valid for inner MDC planes!
  ybl = layPart1.C1x*xb + layPart1.C1y*yb + layPart1.C1;
  zbl = layPart1.C2x*xb + layPart1.C2y*yb + layPart1.C2;
}

//-------Mod.-----------------------------

class HMdcLookUpTbMod : public TObject {
  protected:
    TObjArray* array;      // Array of HMdcLookUpTbLayer objects
    Int_t      nLayers;    // Number of working layers
  public:
    HMdcLookUpTbMod(Int_t sec, Int_t mod);
    ~HMdcLookUpTbMod(void);
    HMdcLookUpTbLayer& operator[](Int_t i) {return *static_cast<HMdcLookUpTbLayer*>((*array)[i]);}
    Int_t getSize(void);
    void  setNLayers(Int_t nl) {nLayers=nl;}
    Int_t getNLayers(void)     {return nLayers;}

  ClassDef(HMdcLookUpTbMod,0)
};

//-------Sec.-----------------------------
class HMdcLookUpTbSec : public TObject {
  protected:
    Int_t               sector;          // sector number
    Int_t               segment;         // =0 -inner segment, -1 inner&outer
    Int_t               nSegments;       // num. of segments for clus. finder
    Int_t               nModules;        // num. of modules for cluster finder.
    Int_t               maxNModules;     // num. of modules (eq.2 or 4)
    Bool_t              isCoilOff;
                                         // Size of plot:
    Int_t               nBinX;           // num.bins along axis X,
    Double_t            xLow;            // low edge of X
    Double_t            xUp;             // upper edge of X
    Double_t            xStep;           // step X = (xUp-xLow)/nBinX
    Int_t               nBinY;           // num.bins along axis Y
    Double_t            yLow;            // low edge of Y
    Double_t            yUp;             // upper edge of Y
    Double_t            yStep;           // step Y= (yUp-yLow)/nBinY
    Float_t             xFirstBin;       // x of first bin
    Float_t             yFirstBin;       // y of first bin
    Double_t           *xBinsPos;        // Bins positions
    Double_t           *yBinsPos;        //

    Int_t               size;            // project plot size
    static UChar_t     *hPlMod[4];       // hPlMod[0] - mod.1, ...
    static Int_t        hPlModsSize;     // real length of hPlMod[mod] (can be >size)

    Int_t               sizeBAr;         // Size of the bit array plotBAr (in bytes)
    static Int_t        sizeBArSt;       // sizeBArSt>=sizeBAr;
    static UChar_t     *plotBArSc;       // Bit array (1 bit - 1 bin) (for scaning).
    UInt_t              maxBinBAr4Sc;    // regiong of bins for scaning
    UInt_t              minBinBAr4Sc;    //

    static UChar_t     *plotBArM[4];     // Bit arraies for MDC's.
    UInt_t              maxBinBAr4M[4];  //
    UInt_t              minBinBAr4M[4];  //

    UInt_t*             xMin[4];         // for cleaning proj. plots
    UInt_t*             xMax[4];         //

    HMdcClFnStack      *stack;           // stack
    HMdcClFnStacksArr  *stacksArr;       // array of stacks

    TObjArray          *array;           // array of pointers of type HMdcLookUpTbMod

    HCategory          *fClusCat;        // category of clusters
    HLocation           locClus;         // location of cluster category
    Bool_t              isGeant;         // =kTRUE - geant data
    Bool_t              trackListFlag;   // =kTRUE - filling tracks list in ClusSim
    Bool_t              noFiredCells;    // =kTRUE if no fired cells
    Int_t               maxAmp[4];       // number of fired layes in MDC
    
    HMdcSecListCells*   pListCells;      // list of fired wires in current event
    
    Int_t               minAmp[4];       // max.clus. for mdc1,2,3,4
    Int_t               nMods;           // num. of modules in sector for cl.finding
    Int_t               typeClFinder;    // =0 - finding in all mdc in sec.
                                         // =1 - finding in each mdc indep.
                                         // =2 - combinedchamber+chamber clusters
    Int_t               neighbBins[8];
    HMdcPlane           prPlane;         // Projections plane
    Float_t             target[3];       // target
    Float_t             eTarg[3];        // errors of target position
    HGeomVector         targVc[3];       // [0] First target point in sec.coor.sys.
                                         // [1] Last target point in sec.coor.sys.
                                         // [2] Middle point in sec.coor.sys.
    Bool_t              doVertexFn;      //
    Double_t            dDistCutVF;      // As dDistCut but fo vertex finder. <0. no vertex finder.
    Int_t               levelVertF;      // Level for vertex finder.
    Int_t               levelVertFPP;    // Level for vertex finder project plot.
    Int_t               lTargPnt;        // Num. of target points for vertex finder.
    Int_t               indFirstTPnt;
    Int_t               indLastTPnt;
    HGeomVector         targetPnts[250];
    Double_t            vertZErr;        //
    Int_t              *vertexStat;      // It is HMdcLookUpTb::vertexStat
    Int_t               vertexPoint;     // Result of vertex finder
    

    Int_t               nClusters;       // counter of clusters

    TH2C*               hist;            //
    Int_t               plBining;

    // -- Clusters parameters ---
    HMdcClustersArrs*   pClustersArrs;   // clusters arraies
    Int_t               nModSeg[2];
    Int_t               clusArrSize;     // size of clusArr,clusArrM1,clusArrM2
    HMdcCluster*        clusArr;         // array of clusters parameters
    Int_t               nClsArr;         // counter of clusters in array

    static Short_t*     clusIndM1;       // array of MDC1 clusters indexis
    static Int_t        clIndArrSzM1;    // clusIndM1 array size
    HMdcCluster*        clusArrM1;       // array of clusters parameters in MDC1
    Int_t               nClsArrM1;       // counter of clusters in MDC1
    static Short_t*     clusIndM2;       // array of MDC2 clusters indexis
    static Int_t        clIndArrSzM2;    // clusIndM2 array size
    HMdcCluster*        clusArrM2;       // array of clusters parameters in MDC2
    Int_t               nClsArrM2;       // counter of clusters in MDC2
    
    Int_t               clusArrInd;      // current clus.array index:
                                         // 0-clusArr, 1-clusArrM1, 2-clusArrM2
    HMdcCluster*        cClusArr;        // current clusters array
    Int_t*              cNClusArr;       // current clusters array counter
    Int_t               cSeg;
    Int_t               cMod1;
    Int_t               cMod2;
    UChar_t*            cPlModF;
    UChar_t*            cPlModS;
    Int_t               cMod;
    UChar_t*            cPlMod;
    Short_t*            clusInd;
        
    HMdcLookUpTbMod*    cFMod;           // current module
    UChar_t*            cHPlModM;        // current mod.pr.plot
    HMdcCluster*        clus;            // current cluster
    Bool_t              isClstrInited;   // flag for "clus" object
    UInt_t*             cXMinM;          // current xMin[mod]
    UInt_t*             cXMaxM;          // current xMax[mod]
    UInt_t*             pXMinM;          // xMin[mod] for previous mdc
    UInt_t*             pXMaxM;          // xMax[mod] for previous mdc
    UChar_t*            cPlotBAr;        // current bit array

    Int_t               nLMaxCl;         // cluster region on proj.plane (bins)
    Int_t               nLMinCl;         // nLMinCl-nLMaxCl region of lines
    UShort_t*           xMaxCl;          // regions of x bins for each line
    UShort_t*           xMinCl;          // in nLMinCl-nLMaxCl region

    HMdcClus*           fClus;           // pointer to cluster;
    Int_t               nFirstClust;     // needed for clusters merger
    Bool_t              isSlotAv[2];     // =kFALSE if cluster slot not available

    Int_t               layerOrder[6];   // 
    Int_t               module;          // current MDC module
    Int_t               layer;           // layer
    Int_t               cell;            // cell
    Float_t             tdcTime;         // and time
    UChar_t             add;             //
    HMdcLayListCells*   pLayLCells;
    HMdcLookUpTbLayer*  pLUTLayer;
    HMdcLookUpTbCell*   pLUTCell;
    HMdcSizesCellsSec*  pSCellSec;
    HMdcDriftTimeParSec* pDriftTimeParSec;
    Double_t            constUncert;     // Constant part in LookUpTbCell::yProjUncer
    Double_t            dDCutCorr[4][6]; // Correction for layer cut 
    Double_t            dDistCut;        // Cut:  dDist/yProjUncer < dDistCut*dDCutCorr[mod][layer]
    Double_t           *yDDistCorr;      // Cut correction for y-bins
    Bool_t              useDriftTime;    //
    Char_t              fakeSuppFlag;    // 0-don't do; 1-do; 2-set flag only (don't remove obj.)
    
  public:
    HMdcLookUpTbMod& operator[](Int_t i) {return *static_cast<HMdcLookUpTbMod*>((*array)[i]);}
    Int_t        getSize(void);
    Int_t        getNClusters(void) const            {return nClusters;}
    Int_t        getMaxClus(Int_t m=-1) const;
    Int_t        getNBinX(void) const                {return nBinX;}
    Double_t     getXlow(void) const                 {return xLow;}
    Double_t     getXup(void) const                  {return xUp;}
    Int_t        getNBinY(void) const                {return nBinY;}
    Double_t     getYlow(void) const                 {return yLow;}
    Double_t     getYup(void) const                  {return yUp;}
    void         clearwk(void);
    Int_t        findClusters(Int_t* imax);
    void         setParPlane(const HMdcPlane &plane) {prPlane.setPlanePar(plane);}
    void         setTargetF(const HGeomVector& vec)  {targVc[0]=vec;}
    void         setTargetL(const HGeomVector& vec)  {targVc[1]=vec;}
    HMdcPlane&   getPrPlane(void)                    {return prPlane;}
    const        HGeomVector& getTargetF(void)       {return targVc[0];}
    const        HGeomVector& getTargetL(void)       {return targVc[1];}
    TH2C*        fillTH2C(const Char_t* name,const Char_t* title,Int_t type=0,Int_t bining=2);
    void         setTypeClFinder(Int_t type)         {typeClFinder = type;}
    Int_t        getTypeClFinder(void)               {return typeClFinder;}
    Int_t        xBinNum(Double_t x)                 {return Int_t((x-xLow)/xStep);}
    Int_t        yBinNum(Double_t y)                 {return Int_t((y-yLow)/yStep);}
    Int_t        xBinNumInBounds(Double_t x);
    Int_t        yBinNumInBounds(Double_t y);
    Bool_t       calcXYBounds(Double_t& xL,Double_t& xU,Double_t& yL,Double_t& yU);
    void         setPrPlotSize(Double_t xL,Double_t xU,Double_t yL,Double_t yU);
    
    HMdcLookUpTbSec(Int_t sec, Int_t nSegs, Int_t inBinX, Int_t inBinY);
    void         setClusCat(HCategory* cat)          {fClusCat  = cat;}
    void         setStack(HMdcClFnStack* st)         {stack     = st;}
    void         setStacksArr(HMdcClFnStacksArr* sA) {stacksArr = sA;}
    void         setCoilFlag(Bool_t flg)             {isCoilOff = flg;}
    void         calcTarget(Double_t* targLenInc);
    Bool_t       calcLookUpTb(Bool_t quiet);
    void         fillTrackList(Bool_t fl)            {trackListFlag = fl;}
    void         calcTdcDrDist(void);
    void         findVertex(void);
    void         findSecVertex(void);
    void         setVertexStat(Int_t *vs)            {vertexStat = vs;}
    void         calcVertexFnTarg(Int_t nTrPnts,HGeomVector* trPnts);
    void         setVertexPoint(Int_t vp);
    void         setVertexZErr(Double_t vze)         {vertZErr = vze;}
    
  protected:
    HMdcLookUpTbSec(void) : vertexStat(NULL) {}
    ~HMdcLookUpTbSec(void);
    Bool_t       fillLookUpTb(Int_t m, Int_t l,HMdcTrapPlane& cellPr,
                                               HMdcLookUpTbCell& fCell);
    void         clearPrArrs(void);
    void         clearPrMod(Int_t mod);
    void         clearPrMod(void);
    void         clearPrModInSec(void);
    void         setDrTimeCutYCorr(Double_t corr);
    void         fillClusCat(Int_t mod, Int_t segp, Int_t tpClFndr);
    void         findClusInSeg(Int_t seg);
    void         findClusInSec(void);
    void         findClusInMod(Int_t mod);
    Int_t        getClusterSlot(Int_t seg, HMdcList12GroupCells& list);
    void         fillModWiresList(Int_t mod, HMdcList12GroupCells& list);
    Bool_t       fillModCluster(Int_t mod);
    Bool_t       fillSegCluster(void);
    Bool_t       fillSecCluster(void);
    void         makeModPlot(Int_t mod);
    void         makeSPlot(void);
    void         makeS1PlotAmpCut(void);
    void         makeLayProjV0(void);
    void         makeLayProjV1(void);
    void         makeLayProjV1b(void);
    void         makeLayProjV2(void);
    void         findClusInSeg1(void);
    void         mergeClusInMod(Int_t mod);
    void         mergeClusMod1to2(void);
    void         mergeClusInSeg(void);
    void         mergeClusInSec(void);
    void         testClusMod12toSeg(void);
    void         scanPlotInMod(Int_t mod);
    Bool_t       calcMixedClusterFixedLevel(Int_t nBin);
    Bool_t       calcMixedClusterFloatLevel(Int_t nBin);
    void         scanPlotInSeg1(Int_t seg, UChar_t* plotBAr);
    Bool_t       calcClusterInSecFixedLevel(Int_t nBin);
    Bool_t       calcClusterInSecFloatLevel(Int_t nBin);
    Bool_t       calcClusterInSegFixedLevel(Int_t nBin);
    Bool_t       calcClusterInSegFloatLevel(Int_t nBin);
    Bool_t       calcClusterInSeg1FixedLevel(Int_t nBin);
    Bool_t       calcClusterInSeg1FloatLevel(Int_t nBin);
    void         testSeg1ModClMatching(void);
    Bool_t       calcClusterInModFixedLevel(Int_t nBin);
    Bool_t       calcClusterInModFloatLevel(Int_t nBin);
    void         calcClParam(void);

    void         initCluster(Int_t nBin);
    void         reinitCluster(Int_t nBin);
    void         initCluster(Int_t nBin,UChar_t amp);
    void         reinitCluster(Int_t nBin,UChar_t amp);
    void         addBinInCluster(Int_t nBin,UChar_t wt);
    void         initClusterT2(Int_t nBin,UChar_t amp);
    void         reinitClusterT2(Int_t nBin,UChar_t amp);
    void         addBinInClusterT2(Int_t nBin,UChar_t wt);
    Bool_t       increaseClusterNum(void);
    Bool_t       setLayerVar(void);
    Bool_t       setNextCell(void);
    void         removeGhosts(void);
    void         testBinForVertexF(Int_t bx, Int_t by);
    void         testBinForVertex(Int_t bx, Int_t by);
    void         addToClusCounter(Int_t clusAmp);
    void         markFakesNBins(Int_t clusAmp,Int_t arrSize,Int_t *nUnWiresCut);
    void         markFakes(Int_t clusAmp,Int_t arrSize,Int_t *nRlWiresCut);
    void         markReals(Int_t clusAmp,Int_t arrSize,const Int_t *nUnWiresCut);
    
    inline void  setCurrentArraySec(void);
    inline void  setCurrentArrayMod1(void);
    inline void  setCurrentArrayMod2(void);

  ClassDef(HMdcLookUpTbSec,0)
};

inline void HMdcLookUpTbSec::setCurrentArraySec(void) {
  cClusArr   = clusArr;
  cNClusArr  = &nClsArr;
  clusArrInd = 0;
}

inline void HMdcLookUpTbSec::setCurrentArrayMod1(void) {
  cClusArr   = clusArrM1;
  cNClusArr  = &nClsArrM1;
  clusArrInd = 1;
}

inline void HMdcLookUpTbSec::setCurrentArrayMod2(void) {
  cClusArr   = clusArrM2;
  cNClusArr  = &nClsArrM2;
  clusArrInd = 2;
}

class HMdcLookUpTb : public HParSet {
  protected:
    static HMdcLookUpTb* fMdcLookUpTb;
    TObjArray*           array;           // array of HMdcLookUpTbSec objects
    Bool_t               isCoilOff;
    Int_t                typeClFinder;    // =0 - finding in all mdc in sec.
                                          // =1 - finding in each mdc indep.
                                          // =2 - combinedchamber+chamber clusters
    HMdcGetContainers*   fGetCont;
    HMdcSizesCells*      fSizesCells;
    HMdcGeomPar*         fMdcGeomPar;
    HSpecGeomPar*        fSpecGeomPar;
    HMdcLayerGeomPar*    fLayerGeomPar;
    HStart2GeomPar*      fStartGeomPar;
    HCategory*           fMdcClusCat;     // category of clusters
    Double_t             targLenInc[2];
    Bool_t               quietMode;
    HMdcClFnStack*       stack;           // stack
    HMdcClFnStacksArr*   stacksArr;       // array of stacks
    
    Bool_t               useDriftTime;    //
    Double_t             constUncert;     // Const. part for LookUpTbCell::distCut...
    Double_t             dDCutCorr[4][6]; // Correction for layer cut 
    Double_t             dDistCut;        // Cut:  dDist/yProjUncer < dDistCut*dDCutCorr[mod][lay]
    Double_t             dDistYCorr;      // Cut correction vs Ybin
 
    Int_t                numVFPoins;      // Num. of points for the vertex finder
    Bool_t               use3PointMax;    //
    HGeomVector          targetPnts[250];
    Double_t             vertZErr;        //
    Int_t                vertexStat[250]; // ???
    Int_t                numStartDPoints; // Num. of points of start detector for the vertex finder
    
  public:
    static HMdcLookUpTb* getExObject(void)          {return fMdcLookUpTb;}
    static HMdcLookUpTb* getObject(void);
    static void          deleteCont(void);
    HMdcLookUpTbSec& operator[](Int_t i) {return *static_cast<HMdcLookUpTbSec*>((*array)[i]);}
    Int_t                getSize(void);
    Bool_t               init(HParIo* input,Int_t* set)           {return kTRUE;}
    virtual Bool_t       initContainer(void);
    void                 clear(void);
    void                 setTargLenInc(Double_t lf,Double_t rt);
    void                 setTypeClFinder(Int_t type)              {typeClFinder = type;}
    void                 setIsCoilOffFlag(Bool_t fl)              {isCoilOff = fl;}
    void                 setQuietMode(Bool_t md=kTRUE)            {quietMode = md;}
    void                 fillTrackList(Bool_t fl);
    void                 calcTdcDrDist(void);
    Int_t                findVertex(void);
    Int_t                getNVertexPnts(void) const               {return numVFPoins;}
    Int_t*               getVertexStat(void)                      {return vertexStat;}
    HGeomVector*         getVertexPnts(void)                      {return targetPnts;}

  protected:
    HMdcLookUpTb(const Char_t* name="MdcLookUpTb",
                 const Char_t* title="Cluster finder for MDC plane I&II",
                 const Char_t* context="");
    ~HMdcLookUpTb(void);
    virtual Bool_t       calcPrPlane(Int_t sec);
    virtual Bool_t       calcPlotSize(Int_t sec);
    Bool_t               calcTarget(Int_t sec);
    Bool_t               calcVertexFnTarg(void);

  ClassDef(HMdcLookUpTb,0)
};

#endif  /*!HMDCLOOKUPTB_H*/
 hmdclookuptb.h:1
 hmdclookuptb.h:2
 hmdclookuptb.h:3
 hmdclookuptb.h:4
 hmdclookuptb.h:5
 hmdclookuptb.h:6
 hmdclookuptb.h:7
 hmdclookuptb.h:8
 hmdclookuptb.h:9
 hmdclookuptb.h:10
 hmdclookuptb.h:11
 hmdclookuptb.h:12
 hmdclookuptb.h:13
 hmdclookuptb.h:14
 hmdclookuptb.h:15
 hmdclookuptb.h:16
 hmdclookuptb.h:17
 hmdclookuptb.h:18
 hmdclookuptb.h:19
 hmdclookuptb.h:20
 hmdclookuptb.h:21
 hmdclookuptb.h:22
 hmdclookuptb.h:23
 hmdclookuptb.h:24
 hmdclookuptb.h:25
 hmdclookuptb.h:26
 hmdclookuptb.h:27
 hmdclookuptb.h:28
 hmdclookuptb.h:29
 hmdclookuptb.h:30
 hmdclookuptb.h:31
 hmdclookuptb.h:32
 hmdclookuptb.h:33
 hmdclookuptb.h:34
 hmdclookuptb.h:35
 hmdclookuptb.h:36
 hmdclookuptb.h:37
 hmdclookuptb.h:38
 hmdclookuptb.h:39
 hmdclookuptb.h:40
 hmdclookuptb.h:41
 hmdclookuptb.h:42
 hmdclookuptb.h:43
 hmdclookuptb.h:44
 hmdclookuptb.h:45
 hmdclookuptb.h:46
 hmdclookuptb.h:47
 hmdclookuptb.h:48
 hmdclookuptb.h:49
 hmdclookuptb.h:50
 hmdclookuptb.h:51
 hmdclookuptb.h:52
 hmdclookuptb.h:53
 hmdclookuptb.h:54
 hmdclookuptb.h:55
 hmdclookuptb.h:56
 hmdclookuptb.h:57
 hmdclookuptb.h:58
 hmdclookuptb.h:59
 hmdclookuptb.h:60
 hmdclookuptb.h:61
 hmdclookuptb.h:62
 hmdclookuptb.h:63
 hmdclookuptb.h:64
 hmdclookuptb.h:65
 hmdclookuptb.h:66
 hmdclookuptb.h:67
 hmdclookuptb.h:68
 hmdclookuptb.h:69
 hmdclookuptb.h:70
 hmdclookuptb.h:71
 hmdclookuptb.h:72
 hmdclookuptb.h:73
 hmdclookuptb.h:74
 hmdclookuptb.h:75
 hmdclookuptb.h:76
 hmdclookuptb.h:77
 hmdclookuptb.h:78
 hmdclookuptb.h:79
 hmdclookuptb.h:80
 hmdclookuptb.h:81
 hmdclookuptb.h:82
 hmdclookuptb.h:83
 hmdclookuptb.h:84
 hmdclookuptb.h:85
 hmdclookuptb.h:86
 hmdclookuptb.h:87
 hmdclookuptb.h:88
 hmdclookuptb.h:89
 hmdclookuptb.h:90
 hmdclookuptb.h:91
 hmdclookuptb.h:92
 hmdclookuptb.h:93
 hmdclookuptb.h:94
 hmdclookuptb.h:95
 hmdclookuptb.h:96
 hmdclookuptb.h:97
 hmdclookuptb.h:98
 hmdclookuptb.h:99
 hmdclookuptb.h:100
 hmdclookuptb.h:101
 hmdclookuptb.h:102
 hmdclookuptb.h:103
 hmdclookuptb.h:104
 hmdclookuptb.h:105
 hmdclookuptb.h:106
 hmdclookuptb.h:107
 hmdclookuptb.h:108
 hmdclookuptb.h:109
 hmdclookuptb.h:110
 hmdclookuptb.h:111
 hmdclookuptb.h:112
 hmdclookuptb.h:113
 hmdclookuptb.h:114
 hmdclookuptb.h:115
 hmdclookuptb.h:116
 hmdclookuptb.h:117
 hmdclookuptb.h:118
 hmdclookuptb.h:119
 hmdclookuptb.h:120
 hmdclookuptb.h:121
 hmdclookuptb.h:122
 hmdclookuptb.h:123
 hmdclookuptb.h:124
 hmdclookuptb.h:125
 hmdclookuptb.h:126
 hmdclookuptb.h:127
 hmdclookuptb.h:128
 hmdclookuptb.h:129
 hmdclookuptb.h:130
 hmdclookuptb.h:131
 hmdclookuptb.h:132
 hmdclookuptb.h:133
 hmdclookuptb.h:134
 hmdclookuptb.h:135
 hmdclookuptb.h:136
 hmdclookuptb.h:137
 hmdclookuptb.h:138
 hmdclookuptb.h:139
 hmdclookuptb.h:140
 hmdclookuptb.h:141
 hmdclookuptb.h:142
 hmdclookuptb.h:143
 hmdclookuptb.h:144
 hmdclookuptb.h:145
 hmdclookuptb.h:146
 hmdclookuptb.h:147
 hmdclookuptb.h:148
 hmdclookuptb.h:149
 hmdclookuptb.h:150
 hmdclookuptb.h:151
 hmdclookuptb.h:152
 hmdclookuptb.h:153
 hmdclookuptb.h:154
 hmdclookuptb.h:155
 hmdclookuptb.h:156
 hmdclookuptb.h:157
 hmdclookuptb.h:158
 hmdclookuptb.h:159
 hmdclookuptb.h:160
 hmdclookuptb.h:161
 hmdclookuptb.h:162
 hmdclookuptb.h:163
 hmdclookuptb.h:164
 hmdclookuptb.h:165
 hmdclookuptb.h:166
 hmdclookuptb.h:167
 hmdclookuptb.h:168
 hmdclookuptb.h:169
 hmdclookuptb.h:170
 hmdclookuptb.h:171
 hmdclookuptb.h:172
 hmdclookuptb.h:173
 hmdclookuptb.h:174
 hmdclookuptb.h:175
 hmdclookuptb.h:176
 hmdclookuptb.h:177
 hmdclookuptb.h:178
 hmdclookuptb.h:179
 hmdclookuptb.h:180
 hmdclookuptb.h:181
 hmdclookuptb.h:182
 hmdclookuptb.h:183
 hmdclookuptb.h:184
 hmdclookuptb.h:185
 hmdclookuptb.h:186
 hmdclookuptb.h:187
 hmdclookuptb.h:188
 hmdclookuptb.h:189
 hmdclookuptb.h:190
 hmdclookuptb.h:191
 hmdclookuptb.h:192
 hmdclookuptb.h:193
 hmdclookuptb.h:194
 hmdclookuptb.h:195
 hmdclookuptb.h:196
 hmdclookuptb.h:197
 hmdclookuptb.h:198
 hmdclookuptb.h:199
 hmdclookuptb.h:200
 hmdclookuptb.h:201
 hmdclookuptb.h:202
 hmdclookuptb.h:203
 hmdclookuptb.h:204
 hmdclookuptb.h:205
 hmdclookuptb.h:206
 hmdclookuptb.h:207
 hmdclookuptb.h:208
 hmdclookuptb.h:209
 hmdclookuptb.h:210
 hmdclookuptb.h:211
 hmdclookuptb.h:212
 hmdclookuptb.h:213
 hmdclookuptb.h:214
 hmdclookuptb.h:215
 hmdclookuptb.h:216
 hmdclookuptb.h:217
 hmdclookuptb.h:218
 hmdclookuptb.h:219
 hmdclookuptb.h:220
 hmdclookuptb.h:221
 hmdclookuptb.h:222
 hmdclookuptb.h:223
 hmdclookuptb.h:224
 hmdclookuptb.h:225
 hmdclookuptb.h:226
 hmdclookuptb.h:227
 hmdclookuptb.h:228
 hmdclookuptb.h:229
 hmdclookuptb.h:230
 hmdclookuptb.h:231
 hmdclookuptb.h:232
 hmdclookuptb.h:233
 hmdclookuptb.h:234
 hmdclookuptb.h:235
 hmdclookuptb.h:236
 hmdclookuptb.h:237
 hmdclookuptb.h:238
 hmdclookuptb.h:239
 hmdclookuptb.h:240
 hmdclookuptb.h:241
 hmdclookuptb.h:242
 hmdclookuptb.h:243
 hmdclookuptb.h:244
 hmdclookuptb.h:245
 hmdclookuptb.h:246
 hmdclookuptb.h:247
 hmdclookuptb.h:248
 hmdclookuptb.h:249
 hmdclookuptb.h:250
 hmdclookuptb.h:251
 hmdclookuptb.h:252
 hmdclookuptb.h:253
 hmdclookuptb.h:254
 hmdclookuptb.h:255
 hmdclookuptb.h:256
 hmdclookuptb.h:257
 hmdclookuptb.h:258
 hmdclookuptb.h:259
 hmdclookuptb.h:260
 hmdclookuptb.h:261
 hmdclookuptb.h:262
 hmdclookuptb.h:263
 hmdclookuptb.h:264
 hmdclookuptb.h:265
 hmdclookuptb.h:266
 hmdclookuptb.h:267
 hmdclookuptb.h:268
 hmdclookuptb.h:269
 hmdclookuptb.h:270
 hmdclookuptb.h:271
 hmdclookuptb.h:272
 hmdclookuptb.h:273
 hmdclookuptb.h:274
 hmdclookuptb.h:275
 hmdclookuptb.h:276
 hmdclookuptb.h:277
 hmdclookuptb.h:278
 hmdclookuptb.h:279
 hmdclookuptb.h:280
 hmdclookuptb.h:281
 hmdclookuptb.h:282
 hmdclookuptb.h:283
 hmdclookuptb.h:284
 hmdclookuptb.h:285
 hmdclookuptb.h:286
 hmdclookuptb.h:287
 hmdclookuptb.h:288
 hmdclookuptb.h:289
 hmdclookuptb.h:290
 hmdclookuptb.h:291
 hmdclookuptb.h:292
 hmdclookuptb.h:293
 hmdclookuptb.h:294
 hmdclookuptb.h:295
 hmdclookuptb.h:296
 hmdclookuptb.h:297
 hmdclookuptb.h:298
 hmdclookuptb.h:299
 hmdclookuptb.h:300
 hmdclookuptb.h:301
 hmdclookuptb.h:302
 hmdclookuptb.h:303
 hmdclookuptb.h:304
 hmdclookuptb.h:305
 hmdclookuptb.h:306
 hmdclookuptb.h:307
 hmdclookuptb.h:308
 hmdclookuptb.h:309
 hmdclookuptb.h:310
 hmdclookuptb.h:311
 hmdclookuptb.h:312
 hmdclookuptb.h:313
 hmdclookuptb.h:314
 hmdclookuptb.h:315
 hmdclookuptb.h:316
 hmdclookuptb.h:317
 hmdclookuptb.h:318
 hmdclookuptb.h:319
 hmdclookuptb.h:320
 hmdclookuptb.h:321
 hmdclookuptb.h:322
 hmdclookuptb.h:323
 hmdclookuptb.h:324
 hmdclookuptb.h:325
 hmdclookuptb.h:326
 hmdclookuptb.h:327
 hmdclookuptb.h:328
 hmdclookuptb.h:329
 hmdclookuptb.h:330
 hmdclookuptb.h:331
 hmdclookuptb.h:332
 hmdclookuptb.h:333
 hmdclookuptb.h:334
 hmdclookuptb.h:335
 hmdclookuptb.h:336
 hmdclookuptb.h:337
 hmdclookuptb.h:338
 hmdclookuptb.h:339
 hmdclookuptb.h:340
 hmdclookuptb.h:341
 hmdclookuptb.h:342
 hmdclookuptb.h:343
 hmdclookuptb.h:344
 hmdclookuptb.h:345
 hmdclookuptb.h:346
 hmdclookuptb.h:347
 hmdclookuptb.h:348
 hmdclookuptb.h:349
 hmdclookuptb.h:350
 hmdclookuptb.h:351
 hmdclookuptb.h:352
 hmdclookuptb.h:353
 hmdclookuptb.h:354
 hmdclookuptb.h:355
 hmdclookuptb.h:356
 hmdclookuptb.h:357
 hmdclookuptb.h:358
 hmdclookuptb.h:359
 hmdclookuptb.h:360
 hmdclookuptb.h:361
 hmdclookuptb.h:362
 hmdclookuptb.h:363
 hmdclookuptb.h:364
 hmdclookuptb.h:365
 hmdclookuptb.h:366
 hmdclookuptb.h:367
 hmdclookuptb.h:368
 hmdclookuptb.h:369
 hmdclookuptb.h:370
 hmdclookuptb.h:371
 hmdclookuptb.h:372
 hmdclookuptb.h:373
 hmdclookuptb.h:374
 hmdclookuptb.h:375
 hmdclookuptb.h:376
 hmdclookuptb.h:377
 hmdclookuptb.h:378
 hmdclookuptb.h:379
 hmdclookuptb.h:380
 hmdclookuptb.h:381
 hmdclookuptb.h:382
 hmdclookuptb.h:383
 hmdclookuptb.h:384
 hmdclookuptb.h:385
 hmdclookuptb.h:386
 hmdclookuptb.h:387
 hmdclookuptb.h:388
 hmdclookuptb.h:389
 hmdclookuptb.h:390
 hmdclookuptb.h:391
 hmdclookuptb.h:392
 hmdclookuptb.h:393
 hmdclookuptb.h:394
 hmdclookuptb.h:395
 hmdclookuptb.h:396
 hmdclookuptb.h:397
 hmdclookuptb.h:398
 hmdclookuptb.h:399
 hmdclookuptb.h:400
 hmdclookuptb.h:401
 hmdclookuptb.h:402
 hmdclookuptb.h:403
 hmdclookuptb.h:404
 hmdclookuptb.h:405
 hmdclookuptb.h:406
 hmdclookuptb.h:407
 hmdclookuptb.h:408
 hmdclookuptb.h:409
 hmdclookuptb.h:410
 hmdclookuptb.h:411
 hmdclookuptb.h:412
 hmdclookuptb.h:413
 hmdclookuptb.h:414
 hmdclookuptb.h:415
 hmdclookuptb.h:416
 hmdclookuptb.h:417
 hmdclookuptb.h:418
 hmdclookuptb.h:419
 hmdclookuptb.h:420
 hmdclookuptb.h:421
 hmdclookuptb.h:422
 hmdclookuptb.h:423
 hmdclookuptb.h:424
 hmdclookuptb.h:425
 hmdclookuptb.h:426
 hmdclookuptb.h:427
 hmdclookuptb.h:428
 hmdclookuptb.h:429
 hmdclookuptb.h:430
 hmdclookuptb.h:431
 hmdclookuptb.h:432
 hmdclookuptb.h:433
 hmdclookuptb.h:434
 hmdclookuptb.h:435
 hmdclookuptb.h:436
 hmdclookuptb.h:437
 hmdclookuptb.h:438
 hmdclookuptb.h:439
 hmdclookuptb.h:440
 hmdclookuptb.h:441
 hmdclookuptb.h:442
 hmdclookuptb.h:443
 hmdclookuptb.h:444
 hmdclookuptb.h:445
 hmdclookuptb.h:446
 hmdclookuptb.h:447
 hmdclookuptb.h:448
 hmdclookuptb.h:449
 hmdclookuptb.h:450
 hmdclookuptb.h:451
 hmdclookuptb.h:452
 hmdclookuptb.h:453
 hmdclookuptb.h:454
 hmdclookuptb.h:455
 hmdclookuptb.h:456
 hmdclookuptb.h:457
 hmdclookuptb.h:458
 hmdclookuptb.h:459
 hmdclookuptb.h:460
 hmdclookuptb.h:461
 hmdclookuptb.h:462
 hmdclookuptb.h:463
 hmdclookuptb.h:464
 hmdclookuptb.h:465
 hmdclookuptb.h:466
 hmdclookuptb.h:467
 hmdclookuptb.h:468
 hmdclookuptb.h:469
 hmdclookuptb.h:470
 hmdclookuptb.h:471
 hmdclookuptb.h:472
 hmdclookuptb.h:473
 hmdclookuptb.h:474
 hmdclookuptb.h:475
 hmdclookuptb.h:476
 hmdclookuptb.h:477
 hmdclookuptb.h:478
 hmdclookuptb.h:479
 hmdclookuptb.h:480
 hmdclookuptb.h:481
 hmdclookuptb.h:482
 hmdclookuptb.h:483
 hmdclookuptb.h:484
 hmdclookuptb.h:485
 hmdclookuptb.h:486
 hmdclookuptb.h:487
 hmdclookuptb.h:488
 hmdclookuptb.h:489
 hmdclookuptb.h:490
 hmdclookuptb.h:491
 hmdclookuptb.h:492
 hmdclookuptb.h:493
 hmdclookuptb.h:494
 hmdclookuptb.h:495
 hmdclookuptb.h:496
 hmdclookuptb.h:497
 hmdclookuptb.h:498
 hmdclookuptb.h:499
 hmdclookuptb.h:500
 hmdclookuptb.h:501
 hmdclookuptb.h:502
 hmdclookuptb.h:503
 hmdclookuptb.h:504
 hmdclookuptb.h:505
 hmdclookuptb.h:506
 hmdclookuptb.h:507
 hmdclookuptb.h:508
 hmdclookuptb.h:509
 hmdclookuptb.h:510
 hmdclookuptb.h:511
 hmdclookuptb.h:512
 hmdclookuptb.h:513
 hmdclookuptb.h:514
 hmdclookuptb.h:515
 hmdclookuptb.h:516
 hmdclookuptb.h:517
 hmdclookuptb.h:518
 hmdclookuptb.h:519
 hmdclookuptb.h:520
 hmdclookuptb.h:521
 hmdclookuptb.h:522
 hmdclookuptb.h:523
 hmdclookuptb.h:524
 hmdclookuptb.h:525
 hmdclookuptb.h:526
 hmdclookuptb.h:527
 hmdclookuptb.h:528
 hmdclookuptb.h:529
 hmdclookuptb.h:530
 hmdclookuptb.h:531
 hmdclookuptb.h:532
 hmdclookuptb.h:533
 hmdclookuptb.h:534
 hmdclookuptb.h:535
 hmdclookuptb.h:536
 hmdclookuptb.h:537