HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hmdccellgroup.h
Go to the documentation of this file.
1 #ifndef HMDCCELLGROUP_H
2 #define HMDCCELLGROUP_H
3 
4 #include "TObject.h"
5 #include <string.h>
6 
7 class HMdcCellGroup : public TObject {
8  protected:
9  static UChar_t nCellsLookUp[256]; //!
10  static UChar_t cellPosLookUp[4][256]; //!
11  static Bool_t lookUpsInitialized; //!
12  UShort_t *pLayer; //!pointer to layer information.
13 
14  void initLookups(void);
15  HMdcCellGroup(UShort_t *layerBuffer) {
16  if (!lookUpsInitialized) initLookups();
17  pLayer=layerBuffer;
18  }
19  void printCells(Int_t nlays);
20  public:
21  ~HMdcCellGroup(void) { }
22  inline Int_t getNCells(Int_t layer);
23  inline Int_t getCell(Int_t layer,Int_t idx);
24  inline Int_t getSignId(Int_t layer,Int_t idx);
25  inline void setSignId(Int_t layer,Int_t cell,Int_t t1,Int_t t2=0,Int_t t3=0,Int_t t4=0);
26  inline void setLayerGroup(Int_t layer,UShort_t cl) {pLayer[layer] = cl;}
27  Int_t getLayerListCells(Int_t layer,Int_t *list);
28 
29  ClassDef(HMdcCellGroup,1) //A group of cells in layers
30 };
31 
32 class HMdcCellGroup6 : public HMdcCellGroup {
33  protected:
34  UShort_t iLayer[6];
35  public:
36  HMdcCellGroup6(void) : HMdcCellGroup(iLayer)
37  { memset(iLayer,0,6*sizeof(UShort_t)); }
38  ~HMdcCellGroup6(void) {}
39  void clear(void) { memset(iLayer,0,6*sizeof(UShort_t)); }
40  Int_t getSumWires()
41  {
42  Int_t sum=0;
43  for(Int_t i=0;i<6;i++){sum+=getNCells(i);}
44  return sum;
45  }
46  Int_t getNLayers()
47  {
48  Int_t sum=0;
49  for(Int_t i=0;i<6;i++){if(getNCells(i)>0)sum++;}
50  return sum;
51  }
52  void printCellGroup(void) {printCells(6);}
53  ClassDef(HMdcCellGroup6,1) //Group of cells in 6 layers
54 };
55 
57  protected:
58  UShort_t iLayer[12];
59  public:
61  { memset(iLayer,0,12*sizeof(UShort_t));}
63  void clear(void) { memset(iLayer,0,12*sizeof(UShort_t)); }
64  Int_t getSumWires()
65  {
66  Int_t sum=0;
67  for(Int_t i=0;i<12;i++){sum+=getNCells(i);}
68  return sum;
69  }
70  Int_t getSumWires(UInt_t mod)
71  {
72  Int_t sum=0;
73  if(mod==0)for(Int_t i=0;i<6;i++) {sum+=getNCells(i);}
74  if(mod==1)for(Int_t i=6;i<12;i++){sum+=getNCells(i);}
75  return sum;
76  }
77  Int_t getNLayers()
78  {
79  Int_t sum=0;
80  for(Int_t i=0;i<12;i++){if(getNCells(i)>0)sum++;}
81  return sum;
82  }
83  Int_t getNLayers(UInt_t mod)
84  {
85  Int_t sum=0;
86  if(mod==0)for(Int_t i=0;i<6;i++){if(getNCells(i)>0)sum++;}
87  if(mod==1)for(Int_t i=6;i<12;i++){if(getNCells(i)>0)sum++;}
88  return sum;
89  }
90  void printCellGroup(void) {printCells(12);}
91 
92  UChar_t getNSharedCells(HMdcCellGroup12 *gr,Int_t& nLayers,Int_t& nLayOr) {
93  Int_t sum = 0;
94  UChar_t layor = 0;
95  nLayOr = 0;
96  nLayers = 0;
97  for(Int_t layer=0; layer<12; layer++) {
98  UChar_t nsc = getNSharedCells(pLayer[layer],gr->pLayer[layer]);
99  if(nsc == 0) continue;
100  sum += nsc;
101  nLayers++;
102 
103  Int_t l = layer < 6 ? layer : layer-6;
104  if(l > 2) l--;
105  Int_t layInd = 1<<l;
106  if((layor & layInd) == 0) {
107  nLayOr++;
108  layor |= layInd;
109  }
110  }
111  return sum;
112  }
113 
115  Int_t sum = 0;
116  for(Int_t layer=0; layer<12; layer++) if(pLayer[layer]!=0 && gr->pLayer[layer]!=0) {
117  sum += getNSharedCells(pLayer[layer],gr->pLayer[layer]);
118  }
119  return sum;
120  }
121 
122  private:
123 
124  UChar_t getNSharedCells(UShort_t l1, UShort_t l2) {
125  UShort_t c1 = l1 >> 8;
126  UShort_t c2 = l2 >> 8;
127  UShort_t dc = c1>c2 ? c1-c2 : c2-c1;
128  if(dc > 4) return 0;
129  if (c1 > c2) l1 <<= dc<<1;
130  else if(c2 > c1) l2 <<= dc<<1;
131  return nCellsLookUp[l1 & l2 & 0xFF];
132  }
133 
134  ClassDef(HMdcCellGroup12,1) //group of cells in 12 layers.
135 };
136 
137 
138 //----------------------- Inlines ------------------------------
139 inline Int_t HMdcCellGroup::getNCells(Int_t layer) {
140  return nCellsLookUp[pLayer[layer] & 0xFF];
141 }
142 
143 inline Int_t HMdcCellGroup::getCell(Int_t layer,Int_t idx) {
144  return ((pLayer[layer]>>8) & 0xFF)+cellPosLookUp[idx][pLayer[layer] & 0xFF];
145 }
146 
147 inline Int_t HMdcCellGroup::getSignId(Int_t layer,Int_t idx) {
148  //Returns 1 for time1 and 2 for time2 in cell basecell+idx; starting with
149  //idx=0
150  if (idx < getNCells(layer) ) {
151  Int_t shift=cellPosLookUp[idx][pLayer[layer] & 0xFF]*2;
152  return (pLayer[layer] >> shift) & 0x3;
153  }
154  return 0;
155 }
156 
157 inline void HMdcCellGroup::setSignId(Int_t layer,Int_t cell,
158  Int_t t1,Int_t t2,Int_t t3,Int_t t4) {
159  //Sets the signal ids and base cell number for layer "layer"
160  //Input:
161  // layer --> Number of layer to set
162  // cell --> Number of the first cell fired in this layer
163  // t1 - t4 --> SignalId for cells: "cell"+0, "cell"+1 ... "cell"+4
164  // Possible values are:
165  // 0 --> This cell has not fired
166  // 1 --> First signal (time/distance) was used
167  // 2 --> Second signal (time/distance) was used
168  pLayer[layer]=((cell & 0xFF) << 8) | ((t4 & 0x3)<<6) |
169  ((t3 & 0x3)<<4) | ((t2 & 0x3)<<2) | ((t1 & 0x3));
170 }
171 
172 #endif
Int_t getNLayers()
Definition: hmdccellgroup.h:77
UShort_t * pLayer
Definition: hmdccellgroup.h:12
UChar_t getNSharedCells(UShort_t l1, UShort_t l2)
void printCells(Int_t nlays)
static Bool_t lookUpsInitialized
Definition: hmdccellgroup.h:11
Int_t getSumWires()
Definition: hmdccellgroup.h:64
void printCellGroup(void)
Definition: hmdccellgroup.h:52
Int_t getNLayers(UInt_t mod)
Definition: hmdccellgroup.h:83
Int_t nLayers[6][4]
Definition: mdcEfficiency.C:37
Int_t getLayerListCells(Int_t layer, Int_t *list)
Double_t sum
Int_t getNLayers()
Definition: hmdccellgroup.h:46
~HMdcCellGroup6(void)
Definition: hmdccellgroup.h:38
Int_t getCell(Int_t layer, Int_t idx)
HMdcCellGroup(UShort_t *layerBuffer)
Definition: hmdccellgroup.h:15
Int_t getSumWires()
Definition: hmdccellgroup.h:40
HMdcCellGroup6(void)
Definition: hmdccellgroup.h:36
void setSignId(Int_t layer, Int_t cell, Int_t t1, Int_t t2=0, Int_t t3=0, Int_t t4=0)
UShort_t iLayer[12]
Definition: hmdccellgroup.h:58
void clear(void)
Definition: hmdccellgroup.h:39
UChar_t getNSharedCells(HMdcCellGroup12 *gr, Int_t &nLayers, Int_t &nLayOr)
Definition: hmdccellgroup.h:92
Int_t getSumWires(UInt_t mod)
Definition: hmdccellgroup.h:70
Int_t getNCells(Int_t layer)
~HMdcCellGroup(void)
Definition: hmdccellgroup.h:21
void setLayerGroup(Int_t layer, UShort_t cl)
Definition: hmdccellgroup.h:26
~HMdcCellGroup12(void)
Definition: hmdccellgroup.h:62
void clear(void)
Definition: hmdccellgroup.h:63
static UChar_t cellPosLookUp[4][256]
Definition: hmdccellgroup.h:10
TCanvas c1("HAFT","HADES Acceptance Filter for Theorists", 100, 100, 700, 700)
UShort_t iLayer[6]
Definition: hmdccellgroup.h:34
void printCellGroup(void)
Definition: hmdccellgroup.h:90
UChar_t getNSharedCells(HMdcCellGroup12 *gr)
static UChar_t nCellsLookUp[256]
Definition: hmdccellgroup.h:9
Int_t getSignId(Int_t layer, Int_t idx)
void initLookups(void)
pointer to layer information.