1 #include "BEMC_DSM_decoder.h"
12 int BEMC_DSM_L0_decoder(
const unsigned char* rawDsmL0West,
const unsigned char* rawDsmL0East,
int *HighTower,
int* PatchSum) {
14 if (!rawDsmL0West && !rawDsmL0East)
return 0;
15 int dsm_to_patch[30] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29};
17 int dsm_read_map[16]={7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
18 int tower_map[10]={0,1,2,3,4,5,6,7,8,9};
19 unsigned char dsmby[30][16];
21 for (
int i = 0;i < 30;i++) {
22 for (
int j = 0;j < 16;j++) {
23 int k = (16 * (i % 15)) + j;
24 dsmby[i][j] = (i < 15) ? (rawDsmL0East ? rawDsmL0East[k] : 0) : (rawDsmL0West ? rawDsmL0West[k] : 0);
27 for(
int i = 0;i < 30;i++) {
28 patch = dsm_to_patch[i];
29 for(
int j = 0;j < 16;j++) {
30 int k = dsm_read_map[j];
34 for(
int k = 0;k < 5;k++) {
36 int hi_tower = (ch[nby]) & 0x3f;
37 int sum_tower = ((ch[nby]>>6) & 0x3) + (((ch[nby+1]) & 0xf) << 2);
38 int it = tower_map[nt] + 10*(patch);
39 if (HighTower) HighTower[it] = hi_tower;
40 if (PatchSum) PatchSum[it] = sum_tower;
42 hi_tower = ((ch[nby+1]>>4) & 0xf) + (((ch[nby+2]) & 0x3) << 4);
43 sum_tower = ((ch[nby+2]>>2) & 0x3f);
44 it = tower_map[nt] + 10*(patch);
45 if (HighTower) HighTower[it]=hi_tower;
46 if (PatchSum) PatchSum[it]= sum_tower;
57 int BEMC_DSM_L1_decoder(
const unsigned short* rawDsmL1,
int* HighTowerBits,
int* PatchSum) {
58 if (!rawDsmL1)
return 0;
59 int ch[] = {3, 2, 1, 0, 7, 6, 5, 4};
60 for (
int idsm = 0;idsm < 6;idsm++) {
61 for (
int ichannel = 0;ichannel < 6;ichannel++) {
62 unsigned short channelData = rawDsmL1[(idsm * 8) + ch[ichannel]];
63 if (HighTowerBits) HighTowerBits[(idsm * 6) + ichannel] = (channelData >> 10) & 0x3;
64 if (PatchSum) PatchSum[(idsm * 6) + ichannel] = channelData & (((ichannel == 2) || (ichannel == 3)) ? 0x1f : 0x3f);
74 int BEMC_DSM_L2_decoder(
const unsigned short* rawDsmL2,
int* HighTowerBits,
int* PatchSumBits,
int* PatchSum) {
75 if (!rawDsmL2)
return 0;
76 int ch[] = {3, 2, 1, 0, 7, 6, 5, 4};
77 int JP[] = {6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5};
78 for (
int ich = 0;ich < 6;ich++) {
79 unsigned int data = rawDsmL2[ch[ich]];
81 HighTowerBits[JP[(ich * 2) + 0]] = (data >> 12) & 0x3;
82 HighTowerBits[JP[(ich * 2) + 1]] = (data >> 14) & 0x3;
85 PatchSumBits[JP[(ich * 2) + 0]] = (data >> 8) & 0x3;
86 PatchSumBits[JP[(ich * 2) + 1]] = (data >> 10) & 0x3;
89 PatchSum[ich] = (data >> 0) & 0xf;
101 int BEMC_DSM_L3_decoder(
const unsigned short* rawDsmL3,
int* HighTowerBits,
int* PatchSumBits,
int* BackToBackBit,
int *JPsiTopoBit,
int *JetPatchTopoBit) {
102 if (!rawDsmL3)
return 0;
103 unsigned int data = rawDsmL3[0];
104 if (HighTowerBits) HighTowerBits[0] = (data >> 2) & 0x3;
105 if (PatchSumBits) PatchSumBits[0] = (data >> 0) & 0x3;
106 if (BackToBackBit) BackToBackBit[0] = (data >> 4) & 0x1;
107 if (JPsiTopoBit) JPsiTopoBit[0] = (data >> 5) & 0x1;
108 if (JetPatchTopoBit) JetPatchTopoBit[0] = (data >> 6) & 0x1;
114 int getFEEpedestal(
float towerPedestal,
float pedestalShift,
bool debug) {
146 int operationBit = 1;
147 double ped1 = towerPedestal - pedestalShift;
152 double value2 = ped1 / scale10bits;
153 sprintf(buffer,
"%3.0f", value2);
154 int value1 = atoi(buffer);
155 value2 = ped1 - value1 * scale10bits;
158 sprintf(buffer,
"%3.0f", value2);
159 value1 = atoi(buffer);
162 sprintf(buffer,
"%3.0f",
double(value1 - 11) / scale10bits);
163 int value3 = atoi(buffer);
164 value3 *= scale10bits;
165 value2 = value1 - value3;
166 sprintf(buffer,
"%3.0f", value2);
167 value1 = atoi(buffer);
170 if (operationBit == 1) {
171 value = (value1 & 0x0F) | 0x10;
173 if (operationBit == 0) {
174 value = (value1 & 0x0F);
176 if (debug) cout <<
"Calculating FEE pedestal: pedAdc = " << towerPedestal <<
", shift = " << pedestalShift <<
"; PED = " << value << endl;
180 void simulateFEEaction(
int adc,
int ped,
int bitConv,
int &ht,
int &pa,
bool debug) {
182 int operationBit = ped & 0x10;
183 int pedestal = ped & 0x0F;
185 int adc2 = operationBit ? (adc1 - pedestal) : (adc1 + pedestal);
186 int adc3 = adc2 >> 2;
190 }
else if (bitConv == 1) {
191 int adc4 = ((adc2 >> 1) & 0x1F) | ((adc2 & 0x03C0) ? 0x20 : 0);
193 }
else if (bitConv == 2) {
194 int adc4 = ((adc2 >> 2) & 0x1F) | ((adc2 & 0x0380) ? 0x20 : 0);
196 }
else if (bitConv == 3) {
197 int adc4 = ((adc2 >> 3) & 0x1F) | ((adc2 & 0x0300) ? 0x20 : 0);
209 void simulateFEELUT(
int sum,
int formula,
int lutScale,
int lutPed,
int lutSigma,
int lutUsePowerup,
int parameter4,
int parameter5,
int numberOfMaskedTowers,
int pedestalShift,
int &lut,
bool debug) {
275 if (!((sum + lutPed) & ~0x7F) && (formula == 2) && (lutScale == 1) && (!lutSigma) && (lutUsePowerup) && (pedestalShift == 24)) {
277 static int commonLUT[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
278 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
279 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
280 60, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
281 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
282 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62};
284 lut = commonLUT[sum + lutPed + numberOfMaskedTowers];
288 float scale = lutScale;
290 if (numberOfMaskedTowers != 16) {
291 scale *= (16.0 - numberOfMaskedTowers) / 16.0;
297 if (lutUsePowerup) ped += 15;
299 ped -= numberOfMaskedTowers * ((pedestalShift - 8.0) / 16.0);
301 float value = (sum - ped) / scale;
302 if (value < 0) value = 0;
303 if (value > 62) value = 62;
304 if (sum - ped < lutSigma) value = 0;
305 lut = int(round(value));
306 if (debug) cout <<
"Simulating LUT: sum = " << sum <<
", formula = " << formula <<
", lutPed = " << lutPed <<
", lutScale = " << lutScale <<
", lutUsePowerup = " << lutUsePowerup <<
", numberOfMaskedTowers = " << numberOfMaskedTowers <<
", pedestalShift = " << pedestalShift <<
"; LUT = " << lut << endl;