StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEfeeTP.cxx
1 /**************************************************************
2  * $Id: EEfeeTP.cxx,v 1.3 2011/10/16 17:41:59 pibero Exp $
3  **************************************************************/
4 
5 #include <iostream>
6 #include <assert.h>
7 
8 
9 #include "EEfeeTP.h"
10 
11 
12 //--------------------------------------------------
13 //
14 //--------------------------------------------------
15 EEfeeTP::EEfeeTP( int xcrate, const char *TPname, int lenX, int xcha0L, int xcha0H) {
16  // if TP spans one block of channels set xcha0H<0
17  assert(lenX%2==0);
18  lenCh=lenX;
19  cha0L=xcha0L;
20  cha0H=xcha0H;
21  crateID=xcrate;
22  strncpy(name,TPname,mxTxt);
23  nT=0;
24 }
25 
26 
27 //--------------------------------------------------
28 //--------------------------------------------------
29 void
30 EEfeeTP::clear() {
31  memset(adc12,0,sizeof(adc12));
32  memset(ped4,0,sizeof(ped4));
33  memset(chanID,0,sizeof(chanID));
34  memset(adc10p,0,sizeof(adc10p));
35  memset(adc6,0,sizeof(adc6));
36 
37  nT=0; // could be done just once if masked were used in InitRun
38  HT6b=0;
39  TPsum6b=0;
40  HTchId=-2;
41 }
42 
43 //--------------------------------------------------
44 //--------------------------------------------------
45 void
46 EEfeeTP::compute(int *adcA, int *ped4A, int *maskA, int highTowerMask, int patchSumMask){
47  // input: arrays for the same crate
48 
49  int i;
50  int len=lenCh;
51  if(cha0H>0) len=len/2; // there will be to subsets of channels
52  //...................first pick up the raw ADC from the data block
53  for (i=0; i<len; i++){
54  if( maskA[cha0L+i]) continue;
55  adc12[nT]= adcA[cha0L+i] & 0xfff; // take only lower 12 bits
56  ped4 [nT]=ped4A[cha0L+i];
57  chanID[nT]= cha0L+i;
58  nT++;
59  }
60 
61  if(cha0H>0) { // read another half of channels
62  for (i=0; i<len; i++){
63  if( maskA[cha0H+i]) continue;
64  adc12[nT]= adcA[cha0H+i] & 0xfff; // take only lower 12 bits
65  ped4 [nT]=ped4A[cha0H+i];
66  chanID[nT]= cha0H+i;
67  nT++;
68  }
69  }
70 
71  //.......................Emulate FEE math
72  HTchId=-1;
73  HT6b=0;
74  int TPsum8b=0;
75 
76  for (i=0; i<nT; i++){
77  int adc10=adc12[i]>>2; // shift ADC by 2 bits
78  int x10=adc10+ped4[i]; // ped adjusted 10 bit ADC
79  if ( x10<0) x10=0;
80  x10 &= 0x3ff; // clear higher bits, wrap around
81  adc10p[i]=x10; // store it for QA
82  TPsum8b+=x10 >>2; // shift 10-bit ped adjusted ADC by 2 bits and sum up
83 
84  // .. reduce HT energy to 6 bits, use the highest bit as overflow bit
85  int y=x10;
86  if(( y>>7) & 0x7 ) y |=(1<<7); // set the overflow bit
87  y=( y >> 2 ) & 0x3f; // take bits [7,..,2]
88  adc6[i]=y; // store it for QA
89 
90  if( HT6b < y ) { // search for high tower using 6-bit ADCs
91  HT6b=y;
92  HTchId=chanID[i]; // keep track which tower is HT, for QA
93  }
94 
95  }
96 
97  TPsum6b =TPsum8b - nT + 1; // subtract offset = # towers - 1
98  // take lowest 6 bits of TPsum8b w/ over & underflow protection
99  if (TPsum6b <0 ) TPsum6b=0;
100  if (TPsum6b > 62) TPsum6b=62;
101 
102  if (!highTowerMask) HT6b = 0;
103  if (!patchSumMask) TPsum6b = 0;
104 }
105 
106 
107 //--------------------------------------------------
108 //--------------------------------------------------
109 void
110 EEfeeTP::print( int k) const {
111  printf("EEfeeTP: name=%s nT=%d\n",name,nT);
112  int i;
113  printf(" channel: "); for(i=0;i<nT;i++) printf(" %4d",chanID[i]); printf("\n");
114  printf(" rawADC : "); for(i=0;i<nT;i++) printf(" %4d",adc12[i]);printf("\n");
115  printf(" ped4: "); for(i=0;i<nT;i++) printf(" %4d",ped4[i]);printf("\n");
116  printf(" adc10+p: "); for(i=0;i<nT;i++) printf(" %4d",adc10p[i]);printf("\n");
117  printf(" adc6 : ");
118  for(i=0;i<nT;i++) {
119  printf("%4d",adc6[i]);
120  if(HTchId==chanID[i]) printf("*"); else printf(" ");
121  }
122  printf("\nOUTPUT: HT6b=%d TPsum6b=%d \n",getOutHT(),getOutTPsum());
123 }
124 
125 
126 /*
127  * $Log: EEfeeTP.cxx,v $
128  * Revision 1.3 2011/10/16 17:41:59 pibero
129  * Implement EEMC FEE HT & TP masks
130  *
131  * Revision 1.2 2009/11/19 15:48:40 balewski
132  * add (char*) to many strings to make SL5 happ, few other adjustments
133  *
134  * Revision 1.1 2009/10/12 18:04:26 pibero
135  * Moved StEEmcUtil/EEdsm to StTriggerUtilities/Eemc
136  *
137  * Revision 1.2 2009/02/24 03:56:19 ogrebeny
138  * Corrected const-ness
139  *
140  * Revision 1.1 2007/08/17 01:15:37 balewski
141  * full blown Endcap trigger simu, by Xin
142  *
143  */
144