StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
qt32b_fms_2009_a.cc
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 14 Jan 2011
5 //
6 
7 #include <algorithm>
8 using namespace std;
9 
10 #include "bits.hh"
11 #include "qt32b_fms_2009_a.hh"
12 #include <stdio.h>
13 
14 void qt32b_fms_2009_a(Board& qt, int t){
15  qt.output[t] = 0;
16 
17  int htadc = 0;
18  int htid = 0;
19 
20  for (int dcard = 0; dcard < 4; ++dcard) {
21  int sum = 0;
22  for (int dch = 7; dch >= 0; --dch) {
23  int id = dcard*8+dch;
24  int adc = qt.channels[t][id];
25  sum += adc;
26  if(adc > 0xfff) {printf("ADC above 4k %d\n",adc); adc = 0x4f;}
27  else {adc = getbits(adc,5,7);}
28  if (adc > htadc) {
29  htadc = adc;
30  htid = id;
31  }
32  }
33  if (sum & ~0x3ff){
34  sum = 0x1f;
35  }else{
36  sum = getbits(sum,5,5);
37  }
38  qt.output[t] |= sum << (dcard*5);
39  }
40 
41  qt.output[t] |= htadc << 20;
42  qt.output[t] |= htid << 27;
43 
44  if(htadc>0)
45  printf("%s %08x sum=%3d %3d %3d %3d ht=%3d htid=%3d\n",
46  qt.name,qt.output[t],
47  getbits(qt.output[t],0 ,5),
48  getbits(qt.output[t],5 ,5),
49  getbits(qt.output[t],10,5),
50  getbits(qt.output[t],15,5),
51  htadc,htid);
52 }
53 
54 void getQtDaughterSum(int qtout, int* sum)
55 {
56  sum[0] = getbits(qtout,0 ,5);
57  sum[1] = getbits(qtout,5 ,5);
58  sum[2] = getbits(qtout,10,5);
59  sum[3] = getbits(qtout,15,5);
60 }
61 
62 int getQtHighTowerAdc(int qtout){
63  return getbits(qtout,20,7);
64 }
65 
66 int getQtHighTowerId(int qtout){
67  return getbits(qtout,27,5);
68 }
69 
70 void getQtSumAndHighTower(int* channels, int* A, int* B, int* C, int* D, int& htadc, int& htid){
71  getQtDaughterSum(channels[3],A);
72  getQtDaughterSum(channels[2],B);
73  getQtDaughterSum(channels[1],C);
74  getQtDaughterSum(channels[0],D);
75 
76  int adc[4], id[4];
77 
78  transform(channels,channels+4,adc,getQtHighTowerAdc);
79  transform(channels,channels+4,id ,getQtHighTowerId );
80 
81  int idx = max_element(adc,adc+4) - adc;
82 
83  htadc = adc[idx];
84  htid = id [idx];
85 }
86 
87 void getQtSumAndHighTower(int* channels, int* I, int* J, int& htadc, int& htid)
88 {
89  getQtDaughterSum(channels[1],I);
90  getQtDaughterSum(channels[0],J);
91 
92  int adc[2], id[2];
93 
94  transform(channels,channels+2,adc,getQtHighTowerAdc);
95  transform(channels,channels+2,id ,getQtHighTowerId );
96 
97  int idx = max_element(adc,adc+2) - adc;
98 
99  htadc = adc[idx];
100  htid = id [idx];
101 }
Definition: Board.hh:14