ROOT logo
#ifndef HMDCCELLGROUP_H
#define HMDCCELLGROUP_H

#include "TObject.h"
#include <string.h>

class HMdcCellGroup : public TObject {
 protected:
  static UChar_t nCellsLookUp[256];         //!
  static UChar_t cellPosLookUp[4][256];     //!
  static Bool_t lookUpsInitialized;         //!
  UShort_t *pLayer; //!pointer to layer information.
  
  void initLookups(void);  
  HMdcCellGroup(UShort_t *layerBuffer) {
    if (!lookUpsInitialized) initLookups();
    pLayer=layerBuffer;
  }
  void printCells(Int_t nlays);
 public:
  ~HMdcCellGroup(void) { }
  inline Int_t getNCells(Int_t layer);
  inline Int_t getCell(Int_t layer,Int_t idx);
  inline Int_t getSignId(Int_t layer,Int_t idx);
  inline void  setSignId(Int_t layer,Int_t cell,Int_t t1,Int_t t2=0,Int_t t3=0,Int_t t4=0);
  inline void  setLayerGroup(Int_t layer,UShort_t cl) {pLayer[layer] = cl;}
  Int_t        getLayerListCells(Int_t layer,Int_t *list);
  
  ClassDef(HMdcCellGroup,1) //A group of cells in layers
};

class HMdcCellGroup6 : public HMdcCellGroup {
 protected:
  UShort_t iLayer[6];
 public:
  HMdcCellGroup6(void) : HMdcCellGroup(iLayer) 
    { memset(iLayer,0,6*sizeof(UShort_t)); }
  ~HMdcCellGroup6(void) {}
  void clear(void) { memset(iLayer,0,6*sizeof(UShort_t)); }
  Int_t getSumWires()
  {
      Int_t sum=0;
      for(Int_t i=0;i<6;i++){sum+=getNCells(i);}
      return sum;
  }
  Int_t getNLayers()
  {
      Int_t sum=0;
      for(Int_t i=0;i<6;i++){if(getNCells(i)>0)sum++;}
      return sum;
  }
  void printCellGroup(void) {printCells(6);}
  ClassDef(HMdcCellGroup6,1) //Group of cells in 6 layers
};

class HMdcCellGroup12 : public HMdcCellGroup {
 protected:
  UShort_t iLayer[12];
 public:
  HMdcCellGroup12(void) : HMdcCellGroup(iLayer)
    { memset(iLayer,0,12*sizeof(UShort_t));}
  ~HMdcCellGroup12(void) {}
  void clear(void) { memset(iLayer,0,12*sizeof(UShort_t)); }
  Int_t getSumWires()
  {
      Int_t sum=0;
      for(Int_t i=0;i<12;i++){sum+=getNCells(i);}
      return sum;
  }
  Int_t getSumWires(UInt_t mod)
  {
      Int_t sum=0;
      if(mod==0)for(Int_t i=0;i<6;i++) {sum+=getNCells(i);}
      if(mod==1)for(Int_t i=6;i<12;i++){sum+=getNCells(i);}
      return sum;
  }
  Int_t getNLayers()
  {
      Int_t sum=0;
      for(Int_t i=0;i<12;i++){if(getNCells(i)>0)sum++;}
      return sum;
  }
  Int_t getNLayers(UInt_t mod)
  {
      Int_t sum=0;
      if(mod==0)for(Int_t i=0;i<6;i++){if(getNCells(i)>0)sum++;}
      if(mod==1)for(Int_t i=6;i<12;i++){if(getNCells(i)>0)sum++;}
      return sum;
  }
  void printCellGroup(void) {printCells(12);}
  
  UChar_t getNSharedCells(HMdcCellGroup12 *gr,Int_t& nLayers,Int_t& nLayOr) {        
      Int_t   sum   = 0;
      UChar_t layor = 0;
      nLayOr  = 0;
      nLayers = 0;
      for(Int_t layer=0; layer<12; layer++) {
        UChar_t nsc = getNSharedCells(pLayer[layer],gr->pLayer[layer]);
        if(nsc == 0) continue;
        sum += nsc;
        nLayers++;
        
        Int_t l = layer < 6 ? layer : layer-6;
        if(l > 2) l--;
        Int_t layInd = 1<<l;
        if((layor & layInd) == 0) {
          nLayOr++;
          layor |= layInd;
        }
      }
      return sum; 
  }
  
  UChar_t getNSharedCells(HMdcCellGroup12 *gr) {   
      Int_t   sum   = 0;
      for(Int_t layer=0; layer<12; layer++) if(pLayer[layer]!=0 && gr->pLayer[layer]!=0) {
        sum += getNSharedCells(pLayer[layer],gr->pLayer[layer]);
      }
      return sum; 
  }
  
  private:

  UChar_t getNSharedCells(UShort_t l1, UShort_t l2) {
    UShort_t c1 = l1 >> 8;
    UShort_t c2 = l2 >> 8;
    UShort_t dc = c1>c2 ? c1-c2 : c2-c1;
    if(dc > 4) return 0;
    if     (c1 > c2) l1 <<= dc<<1;
    else if(c2 > c1) l2 <<= dc<<1;
    return nCellsLookUp[l1 & l2 & 0xFF];
  }

  ClassDef(HMdcCellGroup12,1) //group of cells in 12 layers.
};


//----------------------- Inlines ------------------------------
inline Int_t HMdcCellGroup::getNCells(Int_t layer) {
  return nCellsLookUp[pLayer[layer] & 0xFF];
}

inline Int_t HMdcCellGroup::getCell(Int_t layer,Int_t idx) {
  return ((pLayer[layer]>>8) & 0xFF)+cellPosLookUp[idx][pLayer[layer] & 0xFF];
}

inline Int_t HMdcCellGroup::getSignId(Int_t layer,Int_t idx) {
  //Returns 1 for time1 and 2 for time2 in cell basecell+idx; starting with 
  //idx=0
  if (idx < getNCells(layer) ) {
    Int_t shift=cellPosLookUp[idx][pLayer[layer] & 0xFF]*2;
    return (pLayer[layer] >> shift) & 0x3;
  }
  return 0;
}

inline void HMdcCellGroup::setSignId(Int_t layer,Int_t cell,
			      Int_t t1,Int_t t2,Int_t t3,Int_t t4) {
  //Sets the signal ids and base cell number for layer "layer"
  //Input:
  //  layer --> Number of layer to set
  //  cell  --> Number of the first cell fired in this layer
  //  t1 - t4 --> SignalId for cells: "cell"+0, "cell"+1 ... "cell"+4
  //              Possible values are:
  //                0 --> This cell has not fired
  //                1 --> First signal (time/distance) was used
  //                2 --> Second signal (time/distance) was used
  pLayer[layer]=((cell & 0xFF) << 8) | ((t4 & 0x3)<<6) | 
    ((t3 & 0x3)<<4) | ((t2 & 0x3)<<2) | ((t1 & 0x3));
}

#endif
 hmdccellgroup.h:1
 hmdccellgroup.h:2
 hmdccellgroup.h:3
 hmdccellgroup.h:4
 hmdccellgroup.h:5
 hmdccellgroup.h:6
 hmdccellgroup.h:7
 hmdccellgroup.h:8
 hmdccellgroup.h:9
 hmdccellgroup.h:10
 hmdccellgroup.h:11
 hmdccellgroup.h:12
 hmdccellgroup.h:13
 hmdccellgroup.h:14
 hmdccellgroup.h:15
 hmdccellgroup.h:16
 hmdccellgroup.h:17
 hmdccellgroup.h:18
 hmdccellgroup.h:19
 hmdccellgroup.h:20
 hmdccellgroup.h:21
 hmdccellgroup.h:22
 hmdccellgroup.h:23
 hmdccellgroup.h:24
 hmdccellgroup.h:25
 hmdccellgroup.h:26
 hmdccellgroup.h:27
 hmdccellgroup.h:28
 hmdccellgroup.h:29
 hmdccellgroup.h:30
 hmdccellgroup.h:31
 hmdccellgroup.h:32
 hmdccellgroup.h:33
 hmdccellgroup.h:34
 hmdccellgroup.h:35
 hmdccellgroup.h:36
 hmdccellgroup.h:37
 hmdccellgroup.h:38
 hmdccellgroup.h:39
 hmdccellgroup.h:40
 hmdccellgroup.h:41
 hmdccellgroup.h:42
 hmdccellgroup.h:43
 hmdccellgroup.h:44
 hmdccellgroup.h:45
 hmdccellgroup.h:46
 hmdccellgroup.h:47
 hmdccellgroup.h:48
 hmdccellgroup.h:49
 hmdccellgroup.h:50
 hmdccellgroup.h:51
 hmdccellgroup.h:52
 hmdccellgroup.h:53
 hmdccellgroup.h:54
 hmdccellgroup.h:55
 hmdccellgroup.h:56
 hmdccellgroup.h:57
 hmdccellgroup.h:58
 hmdccellgroup.h:59
 hmdccellgroup.h:60
 hmdccellgroup.h:61
 hmdccellgroup.h:62
 hmdccellgroup.h:63
 hmdccellgroup.h:64
 hmdccellgroup.h:65
 hmdccellgroup.h:66
 hmdccellgroup.h:67
 hmdccellgroup.h:68
 hmdccellgroup.h:69
 hmdccellgroup.h:70
 hmdccellgroup.h:71
 hmdccellgroup.h:72
 hmdccellgroup.h:73
 hmdccellgroup.h:74
 hmdccellgroup.h:75
 hmdccellgroup.h:76
 hmdccellgroup.h:77
 hmdccellgroup.h:78
 hmdccellgroup.h:79
 hmdccellgroup.h:80
 hmdccellgroup.h:81
 hmdccellgroup.h:82
 hmdccellgroup.h:83
 hmdccellgroup.h:84
 hmdccellgroup.h:85
 hmdccellgroup.h:86
 hmdccellgroup.h:87
 hmdccellgroup.h:88
 hmdccellgroup.h:89
 hmdccellgroup.h:90
 hmdccellgroup.h:91
 hmdccellgroup.h:92
 hmdccellgroup.h:93
 hmdccellgroup.h:94
 hmdccellgroup.h:95
 hmdccellgroup.h:96
 hmdccellgroup.h:97
 hmdccellgroup.h:98
 hmdccellgroup.h:99
 hmdccellgroup.h:100
 hmdccellgroup.h:101
 hmdccellgroup.h:102
 hmdccellgroup.h:103
 hmdccellgroup.h:104
 hmdccellgroup.h:105
 hmdccellgroup.h:106
 hmdccellgroup.h:107
 hmdccellgroup.h:108
 hmdccellgroup.h:109
 hmdccellgroup.h:110
 hmdccellgroup.h:111
 hmdccellgroup.h:112
 hmdccellgroup.h:113
 hmdccellgroup.h:114
 hmdccellgroup.h:115
 hmdccellgroup.h:116
 hmdccellgroup.h:117
 hmdccellgroup.h:118
 hmdccellgroup.h:119
 hmdccellgroup.h:120
 hmdccellgroup.h:121
 hmdccellgroup.h:122
 hmdccellgroup.h:123
 hmdccellgroup.h:124
 hmdccellgroup.h:125
 hmdccellgroup.h:126
 hmdccellgroup.h:127
 hmdccellgroup.h:128
 hmdccellgroup.h:129
 hmdccellgroup.h:130
 hmdccellgroup.h:131
 hmdccellgroup.h:132
 hmdccellgroup.h:133
 hmdccellgroup.h:134
 hmdccellgroup.h:135
 hmdccellgroup.h:136
 hmdccellgroup.h:137
 hmdccellgroup.h:138
 hmdccellgroup.h:139
 hmdccellgroup.h:140
 hmdccellgroup.h:141
 hmdccellgroup.h:142
 hmdccellgroup.h:143
 hmdccellgroup.h:144
 hmdccellgroup.h:145
 hmdccellgroup.h:146
 hmdccellgroup.h:147
 hmdccellgroup.h:148
 hmdccellgroup.h:149
 hmdccellgroup.h:150
 hmdccellgroup.h:151
 hmdccellgroup.h:152
 hmdccellgroup.h:153
 hmdccellgroup.h:154
 hmdccellgroup.h:155
 hmdccellgroup.h:156
 hmdccellgroup.h:157
 hmdccellgroup.h:158
 hmdccellgroup.h:159
 hmdccellgroup.h:160
 hmdccellgroup.h:161
 hmdccellgroup.h:162
 hmdccellgroup.h:163
 hmdccellgroup.h:164
 hmdccellgroup.h:165
 hmdccellgroup.h:166
 hmdccellgroup.h:167
 hmdccellgroup.h:168
 hmdccellgroup.h:169
 hmdccellgroup.h:170
 hmdccellgroup.h:171
 hmdccellgroup.h:172