StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTriggerData2022.cxx
1  /***************************************************************************
2  *
3  * $Id: StTriggerData2022.cxx,v 2.4 2020/05/15 15:40:20 ullrich Exp $
4  *
5  * Author: Akio Ogawa, October 13, 2017
6  ***************************************************************************
7  *
8  * Description: Concrete implementation of StTriggerData for 2022.
9  *
10  ***************************************************************************
11  *
12  * $Log: StTriggerData2022.cxx,v $
13  * Revision 2.4 2020/05/15 15:40:20 ullrich
14  * Added protection from corrupt Qt board data (Akio)
15  *
16  * Revision 2.3 2022/07/03 08:30:25 ullrich
17  * correct blue filled bunch bit, and cleaning up unused spin bits (Akio)
18  *
19  * Revision 2.2 2022/06/25 15:50:16 ullrich
20  * Improved QT board error reports/handling. Added EPD access functions. (Akio)
21  *
22  * Revision 2.1 2022/01/07 15:49:06 ullrich
23  * Initial Revision.
24  *
25  *
26  **************************************************************************/
27 #include <string.h>
28 #include <assert.h>
29 #include <iostream>
30 #include "StTriggerData2022.h"
31 
32 ClassImp(StTriggerData2022)
33 
35 {
36  mDebug = 0;
37  // printf("StTriggerData2022 Default Constructor\n");
38 }
39 
40 StTriggerData2022::StTriggerData2022(const TriggerDataBlk2022* data, int run):mData()
41 {
42  //printf("StTriggerData2022 Constructor with trigger data block\n");
43  mYear=2022; mRun = run; mDebug = 0;
44  mData = new TriggerDataBlk2022;
45  readData(data,1);
46 }
47 
48 StTriggerData2022::StTriggerData2022(const TriggerDataBlk2022* data, int run, int bs, int dbg):mData()
49 {
50  mYear=2022; mRun = run; mDebug = dbg;
51  if(mDebug==1) printf("StTriggerData2022 Constructor with trigger data block and byteswap option=%d\n",bs);
52  mData = new TriggerDataBlk2022;
53  readData(data,bs);
54 }
55 
56 void StTriggerData2022::blindRunInfo()
57 {
58  mRun=1000000*int(mRun/1000000);
59  mData->eventNumber = 0;
60  EvtDesc->bunchXing_hi = 0;
61  EvtDesc->bunchXing_lo = 0;
62  L1_DSM->BCdata[2] = 0;
63  L1_DSM->BCdata[3] = 0;
64  L1_DSM->BCdata[10] = 0;
65  L1_DSM->BCdata[11] = 0;
66 }
67 
68 void StTriggerData2022::readData(const TriggerDataBlk2022* data, int bs) {
69  int copyflag=1;
70  if (data==0) {copyflag=0;}
71  if(mDebug==1) printf("StTriggerData2022::readData copyflag=%d byteswap=%d data=%p mData=%p\n",copyflag,bs,data,mData);
72 
73  if (copyflag==1){
74  unsigned int ver = data->FormatVersion;
75  if (bs) swapI(&ver);
76 
77  if (ver == y22FORMAT_VERSION ) {
78  if (mDebug==1) printf("StTriggerData2022: version = 0x%x (0x%x or 0x08121140)\n",ver,y22FORMAT_VERSION);
79  }
80  else {
81  mErrorFlag = mErrorFlag | 0x1;
82  printf("StTriggerData2022: version = 0x%x != (0x%x)\n",ver,y22FORMAT_VERSION);
83  assert(0);
84  }
85 
86  unsigned int size = data->totalTriggerLength;
87  if (bs) swapI(&size);
88  if (size > y22MAX_TRG_BLK_SIZE) {
89  gMessMgr->Warning() << "StTriggerData2022: Data length = " << size
90  << " is bigger than max = " << y22MAX_TRG_BLK_SIZE
91  << endm;
92  assert(0);
93  }
94  if (mDebug==1) printf("StTriggerData2022: size = %d, maxsize = %d\n",size,y22MAX_TRG_BLK_SIZE);
95  memcpy(mData,data,size);
96  memset((char*)mData+size,0,sizeof(TriggerDataBlk2022)-size);
97  }
98 
99  if (bs) swapDataBlk(mData);
100  if (mDebug==1){
101  printf("StTriggerData2022: version = 0x%x (0x%x)\n",mData->FormatVersion,y22FORMAT_VERSION);
102  printf("StTriggerData2022: size = %d, maxsize = %d\n",mData->totalTriggerLength,y22MAX_TRG_BLK_SIZE);
103  printf("EventDesc length=%10d offset=%10d\n",mData->EventDesc_ofl.length,mData->EventDesc_ofl.offset);
104  printf("L1_DSM length=%10d offset=%10d\n",mData->L1_DSM_ofl.length,mData->L1_DSM_ofl.offset);
105  printf("Summary length=%10d offset=%10d\n",mData->Summary_ofl.length,mData->Summary_ofl.offset);
106  }
107 
108  EvtDesc=0; L1_DSM=0; TrgSum=0;
109  if (mData->EventDesc_ofl.length > 0) EvtDesc = (EvtDescData2022*)((char*)mData + mData->EventDesc_ofl.offset);
110  if (mData->L1_DSM_ofl.length > 0) L1_DSM = (L1_DSM_Data2022*)((char*)mData + mData->L1_DSM_ofl.offset);
111  if (mData->Summary_ofl.length > 0) TrgSum = (TrgSumData2022* )((char*)mData + mData->Summary_ofl.offset);
112  if (bs){
113  if (EvtDesc) swapEvtDesc(EvtDesc);
114  if (L1_DSM) swapL1_DSM(L1_DSM);
115  if (TrgSum) swapTrgSum(TrgSum);
116  }
117  if (EvtDesc==0 || L1_DSM==0 || TrgSum==0){
118  mErrorFlag = mErrorFlag | 0x1;
119  gMessMgr->Warning() << "StTriggerData2022: EvtDesc, L1_DSM or TrgSum is missing"
120  <<" mErrorFlag="<<mErrorFlag<<endm;
121  }
122 
123  int npre = numberOfPreXing();
124  int npost = numberOfPostXing();
125  if (npre<0 || npre>10 || npost<0 || npost>10){
126  mErrorFlag = mErrorFlag | 0x2;
127  gMessMgr->Warning() << "StTriggerData2022: Invalid npre/post = "<< npre << " / " << npost
128  <<" mErrorFlag="<<mErrorFlag<<endm;
129  }
130  if (mDebug==1) printf("StTriggerData2022: pre=%d post=%d\n",npre,npost);
131 
132  memset(mBC1,0,sizeof(mBC1));
133  memset(mMXQ,0,sizeof(mMXQ));
134  memset(mMIX,0,sizeof(mMIX));
135  memset(mBCW,0,sizeof(mBCW));
136  memset(mBCE,0,sizeof(mBCE));
137  memset(mEQ3,0,sizeof(mEQ3));
138  memset(mBBC,0,sizeof(mBBC));
139  memset(mBBQ,0,sizeof(mBBQ));
140  memset(mFMS,0,sizeof(mFMS));
141  memset(mQT1,0,sizeof(mQT1));
142  memset(mQT2,0,sizeof(mQT2));
143  memset(mQT3,0,sizeof(mQT3));
144  memset(mQT4,0,sizeof(mQT4));
145  memset(mEQ1,0,sizeof(mEQ1));
146  memset(mEQ2,0,sizeof(mEQ2));
147  memset(mEQ4,0,sizeof(mEQ4));
148  memset(mxq,0,sizeof(mxq)); memset(tmxq,0,sizeof(tmxq));
149  memset(eq3,0,sizeof(eq3)); memset(teq3,0,sizeof(teq3));
150  memset(bbq,0,sizeof(bbq)); memset(tbbq,0,sizeof(tbbq));
151  memset(eq1,0,sizeof(eq1)); memset(teq1,0,sizeof(teq1));
152  memset(eq2,0,sizeof(eq2)); memset(teq2,0,sizeof(teq2));
153  memset(eq4,0,sizeof(eq4)); memset(teq4,0,sizeof(teq4));
155 
156  for (int i=0; i<1+npre+npost; i++) {
157  //printf("Doing prepost = %d\n",i);
158  if (i==0) {
159  offlen = mData->MainX;
160  }
161  else {
162  //printf("Prepost list offset = %d\n",mData->PrePostList[i-1]);
163  if (mData->PrePostList[i-1]==0) continue;
164  offlen = (TrgOfflen2022*) ((char*)mData + mData->PrePostList[i-1]);
165  }
166  if (bs) swapRawDetOfflen(offlen);
167  for(int k=0; k<y22MAX_OFFLEN; k++) {
168  if(static_cast<unsigned int>(offlen[k].length + offlen[k].offset) > static_cast<unsigned int>(mData->totalTriggerLength)) {
169  mErrorFlag = mErrorFlag | (1 << k);
170  gMessMgr->Warning() << "StTriggerData2022: offset ("<<offlen[k].offset<<") + length ("<<offlen[k].length
171  <<") exceeds total size("<<mData->totalTriggerLength<<") for data block id="<<k
172  <<" mErrorFlag="<<mErrorFlag<<endm;
173  }
174  }
175  int j; // j is length of the data for the crate including header. Header size is 8 for DSM, and 12 for QT.
176  // If a crate is in the run but not read out for the event, length would be 12 (8+4 for DSM, 12+0 for QT).
177  // If the crate was not read out (j<=12), leave pointer as NULL, and don't swap.
178  j=offlen[y22BC1_CONF_NUM].length; if (j>12){mBC1[i] = (BELayerBlock2022*)((char*)mData + offlen[y22BC1_CONF_NUM].offset); swapRawDet((DataBlock2022*)mBC1[i],y22BC1_CONF_NUM,j,bs);}
179  j=offlen[y22MXQ_CONF_NUM].length; if (j>12){mMXQ[i] = (QTBlock2022* )((char*)mData + offlen[y22MXQ_CONF_NUM].offset); swapRawDet((DataBlock2022*)mMXQ[i],y22MXQ_CONF_NUM,j,bs);}
180  j=offlen[y22MIX_CONF_NUM].length; if (j>12){mMIX[i] = (MIXBlock2022* )((char*)mData + offlen[y22MIX_CONF_NUM].offset); swapRawDet((DataBlock2022*)mMIX[i],y22MIX_CONF_NUM,j,bs);}
181  j=offlen[y22BCW_CONF_NUM].length; if (j>12){mBCW[i] = (BWestBlock2022* )((char*)mData + offlen[y22BCW_CONF_NUM].offset); swapRawDet((DataBlock2022*)mBCW[i],y22BCW_CONF_NUM,j,bs);}
182  j=offlen[y22BCE_CONF_NUM].length; if (j>12){mBCE[i] = (BEastBlock2022* )((char*)mData + offlen[y22BCE_CONF_NUM].offset); swapRawDet((DataBlock2022*)mBCE[i],y22BCE_CONF_NUM,j,bs);}
183  j=offlen[y22EQ3_CONF_NUM].length; if (j>12){mEQ3[i] = (QTBlock2022* )((char*)mData + offlen[y22EQ3_CONF_NUM].offset); swapRawDet((DataBlock2022*)mEQ3[i],y22EQ3_CONF_NUM,j,bs);}
184  j=offlen[y22BBC_CONF_NUM].length; if (j>12){mBBC[i] = (BBCBlock2022* )((char*)mData + offlen[y22BBC_CONF_NUM].offset); swapRawDet((DataBlock2022*)mBBC[i],y22BBC_CONF_NUM,j,bs);}
185  j=offlen[y22BBQ_CONF_NUM].length; if (j>12){mBBQ[i] = (QTBlock2022* )((char*)mData + offlen[y22BBQ_CONF_NUM].offset); swapRawDet((DataBlock2022*)mBBQ[i],y22BBQ_CONF_NUM,j,bs);}
186  j=offlen[y22FMS_CONF_NUM].length; if (j>12){mFMS[i] = (FMSBlock2022* )((char*)mData + offlen[y22FMS_CONF_NUM].offset); swapRawDet((DataBlock2022*)mFMS[i],y22FMS_CONF_NUM,j,bs);}
187  j=offlen[y22QT1_CONF_NUM].length; if (j>12){mQT1[i] = (QTBlock2022* )((char*)mData + offlen[y22QT1_CONF_NUM].offset); swapRawDet((DataBlock2022*)mQT1[i],y22QT1_CONF_NUM,j,bs);}
188  j=offlen[y22QT2_CONF_NUM].length; if (j>12){mQT2[i] = (QTBlock2022* )((char*)mData + offlen[y22QT2_CONF_NUM].offset); swapRawDet((DataBlock2022*)mQT2[i],y22QT2_CONF_NUM,j,bs);}
189  j=offlen[y22QT3_CONF_NUM].length; if (j>12){mQT3[i] = (QTBlock2022* )((char*)mData + offlen[y22QT3_CONF_NUM].offset); swapRawDet((DataBlock2022*)mQT3[i],y22QT3_CONF_NUM,j,bs);}
190  j=offlen[y22QT4_CONF_NUM].length; if (j>12){mQT4[i] = (QTBlock2022* )((char*)mData + offlen[y22QT4_CONF_NUM].offset); swapRawDet((DataBlock2022*)mQT4[i],y22QT4_CONF_NUM,j,bs);}
191  j=offlen[y22EQ1_CONF_NUM].length; if (j>12){mEQ1[i] = (QTBlock2022* )((char*)mData + offlen[y22EQ1_CONF_NUM].offset); swapRawDet((DataBlock2022*)mEQ1[i],y22EQ1_CONF_NUM,j,bs);}
192  j=offlen[y22EQ2_CONF_NUM].length; if (j>12){mEQ2[i] = (QTBlock2022* )((char*)mData + offlen[y22EQ2_CONF_NUM].offset); swapRawDet((DataBlock2022*)mEQ2[i],y22EQ2_CONF_NUM,j,bs);}
193  j=offlen[y22EQ4_CONF_NUM].length; if (j>12){mEQ4[i] = (QTBlock2022* )((char*)mData + offlen[y22EQ4_CONF_NUM].offset); swapRawDet((DataBlock2022*)mEQ4[i],y22EQ4_CONF_NUM,j,bs);}
194  if (mMXQ[i]) decodeQT(mMXQ[i]->length/4, mMXQ[i]->data, mxq[i], tmxq[i]);
195  if (mEQ3[i]) decodeQT(mEQ3[i]->length/4, mEQ3[i]->data, eq3[i], teq3[i]);
196  if (mBBQ[i]) decodeQT(mBBQ[i]->length/4, mBBQ[i]->data, bbq[i], tbbq[i]);
197  if (mEQ1[i]) decodeQT(mEQ1[i]->length/4, mEQ1[i]->data, eq1[i], teq1[i]);
198  if (mEQ2[i]) decodeQT(mEQ2[i]->length/4, mEQ2[i]->data, eq2[i], teq2[i]);
199  if (mEQ4[i]) decodeQT(mEQ4[i]->length/4, mEQ4[i]->data, eq4[i], teq4[i]);
200  }
201  if (mDebug==1) dump();
202 }
203 
204 StTriggerData2022::~StTriggerData2022() {delete mData;}
205 
206 unsigned int StTriggerData2022::version() const
207 {
208  return EvtDesc->TrgDataFmtVer;
209 }
210 
211 unsigned int StTriggerData2022::eventNumber() const
212 {
213  return mData->eventNumber;
214 }
215 
216 unsigned int StTriggerData2022::token() const
217 {
218  return EvtDesc->TrgToken;
219 }
220 
221 unsigned int StTriggerData2022::triggerWord() const
222 {
223  return 0;
224 }
225 
226 unsigned int StTriggerData2022::actionWord() const
227 {
228  return
229  ( (unsigned short)(EvtDesc->actionWdTrgCommand) * 16 * 16 * 16 ) +
230  ( (unsigned short)(EvtDesc->actionWdDaqCommand) * 16 * 16 ) +
231  ( EvtDesc->actionWdDetectorBitMask & 0x00ff );
232 }
233 
234 
235 unsigned int StTriggerData2022::zdcKillerBit() const{
236  return (EvtDesc->addBits>>4) & 0x1;
237 }
238 
239 unsigned int StTriggerData2022::numberOfPreXing() const
240 {
241  return EvtDesc->npre & 0xf;
242 }
243 
244 unsigned int StTriggerData2022::numberOfPostXing() const
245 {
246  return EvtDesc->npost & 0xf;
247 }
248 
249 unsigned short StTriggerData2022::busyStatus() const
250 {
251  return EvtDesc->internalBusy;
252 }
253 
254 unsigned short StTriggerData2022::dsmInput() const
255 {
256  return EvtDesc->DSMInput;
257 }
258 
259 unsigned short StTriggerData2022::trgToken() const
260 {
261  return EvtDesc->TrgToken;
262 }
263 
264 unsigned short StTriggerData2022::dsmAddress() const
265 {
266  return EvtDesc->DSMAddress;
267 }
268 
269 unsigned short StTriggerData2022::mAddBits() const
270 {
271  return EvtDesc->addBits;
272 }
273 
274 unsigned short StTriggerData2022::bcData(int channel) const
275 {
276  return L1_DSM->BCdata[channel];
277 }
278 
279 unsigned short StTriggerData2022::getTrgDetMask() const
280 {
281  return EvtDesc->trgDetMask;
282 }
283 
284 unsigned int StTriggerData2022::getTrgCrateMask() const
285 {
286  unsigned int p = EvtDesc->npost & 0xfff0;
287  unsigned int r = EvtDesc->res1 & 0x0ff0;
288  return
289  ( ((EvtDesc->npre & 0xfff0) >> 4)
290  + (p << 8)
291  + (r << 20) );
292 }
293 
294 unsigned short StTriggerData2022::lastDSM(int channel) const
295 {
296  return L1_DSM->lastDSM[channel];
297 }
298 
299 
300 unsigned short StTriggerData2022::vertexDSM(int channel) const
301 {
302  int dsmmap[8] = {3,2,1,0,7,6,5,4};
303  if(channel<0 || channel>7) return 0;
304  return L1_DSM->VTX[dsmmap[channel]];
305 }
306 
307 unsigned short StTriggerData2022::tcuBits() const
308 {
309  return EvtDesc->DSMInput;
310 }
311 
312 
313 unsigned int StTriggerData2022::tcuCounter() const
314 {
315  unsigned int hi = EvtDesc->tcuCtrBunch_hi;
316  return (hi << 16) + EvtDesc->DSMAddress;
317 }
318 
319 unsigned int StTriggerData2022::rccCounter(int crate) const
320 {
321  if(crate >= y22L1_CONF_NUM && crate <= y22EQ4_CONF_NUM){
322  return TrgSum->LocalClocks[crate];
323  }
324  return 0;
325 }
326 
327 unsigned long long StTriggerData2022::bunchCounter() const
328 {
329  unsigned long long bxinghi,bxing1,bxinglo, bx;
330  bxinghi = L1_DSM->BCdata[3];
331  bxing1 = L1_DSM->BCdata[10];
332  bxinglo = (bxing1 << 16) + L1_DSM->BCdata[11];
333  bx = (bxinghi << 32) + bxinglo;
334  return bx;
335 }
336 
337 unsigned int StTriggerData2022::bunchCounterHigh() const
338 {
339  return EvtDesc->bunchXing_hi;
340 }
341 
342 unsigned int StTriggerData2022::bunchCounterLow() const
343 {
344  return EvtDesc->bunchXing_lo;
345 }
346 
347 unsigned int StTriggerData2022::bunchId48Bit() const
348 {
349  return (int)(bunchCounter() % 120);
350 }
351 
352 unsigned int StTriggerData2022::bunchId7Bit() const
353 {
354  int b7=0, b7dat;
355  b7dat = L1_DSM->BCdata[2];
356  b7 = b7dat & 0x7f;
357  return b7;
358 }
359 
360 unsigned int StTriggerData2022::revTick1() const
361 {
362  return L1_DSM->BCdata[1] & 0x1;
363 }
364 
365 unsigned int StTriggerData2022::revTick2() const
366 {
367  return L1_DSM->BCdata[12] & 0x1;
368 }
369 
370 unsigned int StTriggerData2022::revTick3() const
371 {
372  return (L1_DSM->lastDSM[4] >> 3) & 0x1;
373 }
374 
375 
376 unsigned int StTriggerData2022::spinBit() const
377 {
378  return (L1_DSM->lastDSM[4]/16)%256;
379 }
380 
381 unsigned int StTriggerData2022::spinBitYellowFilled() const
382 {
383  unsigned int sb = spinBit();
384  return sb%2;
385 }
386 
387 unsigned int StTriggerData2022::spinBitYellowUp() const
388 {
389  return 0;
390 }
391 
392 unsigned int StTriggerData2022::spinBitYellowDown() const
393 {
394  return 0;
395 }
396 
397 unsigned int StTriggerData2022::spinBitYellowUnpol() const
398 {
399  return 0;
400 }
401 
402 unsigned int StTriggerData2022::spinBitBlueFilled() const
403 {
404  unsigned int sb = spinBit();
405  return (sb/4)%2;
406 }
407 
408 unsigned int StTriggerData2022::spinBitBlueUp() const
409 {
410  return 0;
411 }
412 
413 unsigned int StTriggerData2022::spinBitBlueDown() const
414 {
415  return 0;
416 }
417 
418 unsigned int StTriggerData2022::spinBitBlueUnpol() const
419 {
420  return 0;
421 }
422 
423 unsigned short StTriggerData2022::bbcADC(StBeamDirection eastwest, int pmt, int prepost) const
424 {
425  const int addrmap[2][24] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
426  4, 4, 4, 4, 4, 4, 4, 4},
427  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
428  4, 4, 4, 4, 4, 4, 4, 4} };
429  const int chmap[2][24] = { { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
430  0, 1, 2, 3, 8, 9,10,11},
431  { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
432  16,17,18,19,24,25,26,27} };
433  int buffer = prepostAddress(prepost);
434  if (buffer >= 0 && pmt>=1 && pmt<=16) return bbq[buffer][addrmap[eastwest][pmt-1]][chmap[eastwest][pmt-1]];
435  return 0;
436 }
437 
438 unsigned short StTriggerData2022::bbcTDC(StBeamDirection eastwest, int pmt, int prepost) const
439 {
440  const int addrmap[2][24] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
441  4, 4, 4, 4, 4, 4, 4, 4},
442  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
443  4, 4, 4, 4, 4, 4, 4, 4} };
444  const int chmap[2][24] = { { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
445  0, 1, 2, 3, 8, 9,10,11},
446  { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
447  16,17,18,19,24,25,26,27} };
448  int buffer = prepostAddress(prepost);
449  if (buffer >= 0 && pmt>=1 && pmt<=16) return bbq[buffer][addrmap[eastwest][pmt-1]][chmap[eastwest][pmt-1]+4];
450  return 0;
451 }
452 
453 unsigned short StTriggerData2022::bbcTDC5bit(StBeamDirection eastwest, int pmt, int prepost) const
454 {
455  const int addrmap[2][24] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
456  4, 4, 4, 4, 4, 4, 4, 4},
457  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
458  4, 4, 4, 4, 4, 4, 4, 4} };
459  const int chmap[2][24] = { { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
460  0, 1, 2, 3, 8, 9,10,11},
461  { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
462  16,17,18,19,24,25,26,27} };
463  int buffer = prepostAddress(prepost);
464  if (buffer >= 0 && pmt>=1 && pmt<=16) return tbbq[buffer][addrmap[eastwest][pmt-1]][chmap[eastwest][pmt-1]];
465  return 0;
466 }
467 
468 unsigned short StTriggerData2022::bbcADCSum(StBeamDirection eastwest, int prepost) const
469 {
470  unsigned short sum=0;
471  int buffer = prepostAddress(prepost);
472  //if (buffer >= 0) for(int i=1; i<=16; i++) {sum+=bbcADC(eastwest,i,prepost);}
473  if(buffer>=0){
474  if (mBBC[buffer]){
475  if(eastwest==east) { sum = mBBC[buffer]->BBClayer1[3]; }
476  else { sum = mBBC[buffer]->BBClayer1[1]; }
477  }
478  }
479  return sum;
480 }
481 
482 unsigned short StTriggerData2022::bbcADCSumLargeTile(StBeamDirection eastwest, int prepost) const
483 {
484  unsigned short sum=0;
485  //int buffer = prepostAddress(prepost);
486  //if (buffer >= 0) for(int i=17; i<=24; i++) {sum+=bbcADC(eastwest,i,prepost);}
487  return sum;
488 }
489 
490 unsigned short StTriggerData2022::bbcEarliestTDC(StBeamDirection eastwest, int prepost) const
491 {
492  int buffer = prepostAddress(prepost);
493  if (buffer >=0){
494  if (mBBC[buffer]){
495  if (eastwest==east) {return mBBC[buffer]->BBClayer1[2]%4096;}
496  else {return mBBC[buffer]->BBClayer1[0]%4096;}
497  }
498  }
499  return 0;
500 }
501 
502 unsigned short StTriggerData2022::bbcTimeDifference() const
503 {
504  return L1_DSM->VTX[3]%8192;
505 }
506 
507 unsigned short StTriggerData2022::bbcTacSum() const
508 {
509  return (((L1_DSM->VTX[3]) >> 13) & 0x1);
510 }
511 
512 unsigned short StTriggerData2022::bbcEarliestTDCLarge(StBeamDirection eastwest, int prepost) const
513 {
514  //int buffer = prepostAddress(prepost);
515  //if (buffer >=0){
516  // if (mBBC[buffer]){
517  // if (eastwest==east) {return mBBC[buffer]->BBClayer1[11] & 0x0fff;}
518  // else {return ((mBBC[buffer]->BBClayer1[11] & 0xf000) >> 12)
519  // +((mBBC[buffer]->BBClayer1[10] & 0x00ff) << 4 );}
520  // }
521  // }
522  return 0;
523 }
524 
525 unsigned short StTriggerData2022::bbcTimeDifferenceLarge() const
526 {
527  return L1_DSM->VTX[2]%8192;
528 }
529 
530 
531 unsigned short StTriggerData2022::bbcBB101(int ch, int prepost) const
532 {
533  int dsmmap[8] = {3,2,1,0,7,6,5,4};
534  int buffer = prepostAddress(prepost);
535  if (buffer>=0){
536  if (mBBC[buffer]){
537  if(ch>=0 && ch<=7) return mBBC[buffer]->BBClayer1[dsmmap[ch]];
538  }
539  }
540  return 0;
541 }
542 
543 unsigned short StTriggerData2022::bbcBB102(int ch, int prepost) const
544 {
545  int dsmmap[8] = {3,2,1,0,7,6,5,4};
546  int buffer = prepostAddress(prepost);
547  if (buffer>=0){
548  if (mBBC[buffer]){
549  if(ch>=0 && ch<=7) return mBBC[buffer]->BBClayer1[dsmmap[ch]+8];
550  }
551  }
552  return 0;
553 }
554 
555 unsigned short StTriggerData2022::epdTimeDifference() const
556 {
557  return L1_DSM->VTX[6]%8192;
558 }
559 
560 bool StTriggerData2022::epdHitLayer2(StBeamDirection eastwest) const
561 {
562  if(eastwest==east) return (L1_DSM->VTX[6] & 0x40) ? true : false;
563  return (L1_DSM->VTX[6] & 0x80) ? true : false;
564 }
565 
566 unsigned short StTriggerData2022::epdLayer0t(int ch, int prepost) const
567 {
568  int dsmmap[16] = {3,2,1,0,7,6,5,4, 11,10,9,8,15,14,13,12};
569  int buffer = prepostAddress(prepost);
570  if (buffer>=0){
571  if (mBBC[buffer]){
572  if(ch>=0 && ch<16) return mBBC[buffer]->EPDlayer0t[dsmmap[ch]];
573  }
574  }
575  return 0;
576 }
577 
578 unsigned short StTriggerData2022::epdLayer1(int ch, int prepost) const
579 {
580  return epdLayer1a(ch,prepost);
581 }
582 
583 unsigned short StTriggerData2022::epdLayer1a(int ch, int prepost) const
584 {
585  int dsmmap[8] = {3,2,1,0,7,6,5,4};
586  int buffer = prepostAddress(prepost);
587  if (buffer>=0){
588  if (mBBC[buffer]){
589  if(ch>=0 && ch<8) return mBBC[buffer]->EPDlayer1a[dsmmap[ch]];
590  }
591  }
592  return 0;
593 }
594 
595 unsigned short StTriggerData2022::epdEarliestTDC(StBeamDirection eastwest, int prepost) const
596 {
597  int buffer = prepostAddress(prepost);
598  if (buffer>=0){
599  if(eastwest==east){
600  unsigned short dsmEP001OutR = epdLayer1(0, prepost);
601  unsigned short dsmEP001OutL = epdLayer1(1, prepost);
602  unsigned int dsmEP001Out = (dsmEP001OutL<<16) + dsmEP001OutR;
603  int maxTac03 = (dsmEP001Out >> 12) & 0xfff; // max tac from channels 0:3
604  int maxTac47 = (dsmEP001Out >> 0 ) & 0xfff; // max tac from channels 4:7
605  return (maxTac03>maxTac47)?maxTac03:maxTac47;
606  }else{
607  unsigned short dsmEP002OutR = epdLayer1(2, prepost);
608  unsigned short dsmEP002OutL = epdLayer1(3, prepost);
609  unsigned int dsmEP002Out = (dsmEP002OutL<<16) + dsmEP002OutR;
610  int maxTac03 = (dsmEP002Out >> 12) & 0xfff; // max tac from channels 0:3
611  int maxTac47 = (dsmEP002Out >> 0 ) & 0xfff; // max tac from channels 4:7
612  return (maxTac03>maxTac47)?maxTac03:maxTac47;
613  }
614  }
615  return 0;
616 }
617 
618 unsigned short StTriggerData2022::epdNHits(StBeamDirection eastwest, int prepost) const
619 {
620  int buffer = prepostAddress(prepost);
621  if (buffer>=0){
622  if(eastwest==east){
623  unsigned short dsmEP001OutR = epdLayer1(0, prepost);
624  unsigned short dsmEP001OutL = epdLayer1(1, prepost);
625  unsigned int dsmEP001Out = (dsmEP001OutL<<16) + dsmEP001OutR;
626  return (dsmEP001Out >> 24) & 0xff;
627  }else{
628  unsigned short dsmEP002OutR = epdLayer1(2, prepost);
629  unsigned short dsmEP002OutL = epdLayer1(3, prepost);
630  unsigned int dsmEP002Out = (dsmEP002OutL<<16) + dsmEP002OutR;
631  return (dsmEP002Out >> 24) & 0xff;
632  }
633  }
634  return 0;
635 }
636 
637 unsigned short StTriggerData2022::epdLayer0aMult(int ch, int prepost) const{
638  //ch=0-7 (EP003) and ch8-15 (EP004)
639  return epdLayer0a(ch,prepost) & 0x001f;
640 }
641 
642 unsigned short StTriggerData2022::epdLayer0hMult(int ch, int mult12, int prepost) const{
643  if(ch>20) return 0; //ch=0-9 (EP005) and ch10-19(EP006), 12bit each
644  unsigned short dsm=0, c=ch, out=0;
645  if(ch>=10) {dsm=1; c=ch-10;}
646  unsigned short chdiv=c/2;
647  unsigned short chmod=c%2;
648  unsigned short base=dsm*16 + chdiv*3;
649  unsigned short o0=epdLayer0h(base , prepost);
650  unsigned short o1=epdLayer0h(base+1, prepost);
651  unsigned short o2=epdLayer0h(base+2, prepost);
652  if(chmod==0){
653  out = o0 + ((o1 & 0x0f)<<8);
654  }else{
655  out = ((o1 & 0xf0)>>4) + (o2<<4);
656  }
657  if(mult12==0) return out;
658  if(mult12==1) return (out & 0x003f);
659  if(mult12==2) return (out & 0x0fc0) >> 6;
660  return 0;
661 }
662 
663 unsigned short StTriggerData2022::epdNHitsQT(int crate, int qt, int mult12, int prepost) const {
664  //crate=1 for EQ1, crate=2 for EQ2, crate=3 for EQ3
665  //qt=1 for EQ0?1, qt=2 for EQ0?2, ... qt=10 for EQ0?A, qt=11 for EQ0?B
666  //mult12=1 for 1st multiplicity, and mult12=2 for 2nd
667  const unsigned short dsmmap[3][11]={
668  {6,6,6,6,6,6,4,4,4,4,4},
669  {5,5,5,5,5,5,3,3,3,3,3},
670  {5,5,5,3,3,6,6,6,4,4,0}
671  };
672  const unsigned short chmap[3][11]={
673  {0,1,2,3,4,5,0,1,2,3,4},
674  {0,1,2,3,4,5,0,1,2,3,4},
675  {6,7,8,5,7,6,7,8,5,7,0}
676  };
677  if(crate<1 || crate>3) return 0;
678  if(qt<1 || qt>11) return 0;
679  unsigned short dsm=dsmmap[crate-1][qt-1];
680  unsigned short ch=chmap[crate-1][qt-1];
681  if(dsm==3 || dsm==4) return epdLayer0aMult(ch + (dsm-3)*8, prepost);
682  if(dsm==5 || dsm==6) return epdLayer0hMult(ch + (dsm-5)*10, mult12, prepost);
683  return 0;
684 }
685 
686 unsigned short StTriggerData2022::epdLayer1bMult(StBeamDirection eastwest, int ring, int prepost) const
687 {
688  if(eastwest==east){
689  switch(ring){
690  case 1: return (epdLayer1b(0,prepost) & 0x007f);
691  case 2: return (epdLayer1b(0,prepost) & 0x7f00) >> 8;
692  case 5: return (epdLayer1b(1,prepost) & 0x00ff);
693  case 4: return (epdLayer1b(1,prepost) & 0xff00) >> 8;
694  case 3: return (epdLayer1b(2,prepost) & 0x00ff);
695  default: return 0;
696  }
697  }else{
698  switch(ring){
699  case 1: return (epdLayer1b(3,prepost) & 0x007f);
700  case 2: return (epdLayer1b(3,prepost) & 0x7f00) >> 8;
701  case 5: return (epdLayer1b(4,prepost) & 0x00ff);
702  case 4: return (epdLayer1b(4,prepost) & 0xff00) >> 8;
703  case 3: return (epdLayer1b(5,prepost) & 0x00ff);
704  default: return 0;
705  }
706  }
707 }
708 
709 unsigned short StTriggerData2022::epdMultTotal(int prepost) const
710 {
711  return L1_DSM->VTX[6] & 0x00ff;
712 }
713 
714 unsigned short StTriggerData2022::epdMultDiff(int prepost) const
715 {
716  return (L1_DSM->VTX[6] & 0xff00) >> 8;
717 }
718 
719 unsigned short StTriggerData2022::fpd(StBeamDirection eastwest, int module, int pmt, int prepost) const
720 {
721  return 0;
722 }
723 
724 unsigned short StTriggerData2022::fpdSum(StBeamDirection eastwest, int module) const
725 {
726  return 0;
727 }
728 
729 bool StTriggerData2022::zdcPresent(int prepost) const
730 {
731  int buffer = prepostAddress(prepost);
732  if (buffer >= 0) return mBBQ[buffer];
733  return false;
734 }
735 
736 unsigned short StTriggerData2022::zdcAtChannel(int channel, int prepost) const
737 {
738  int buffer = prepostAddress(prepost);
739  if (buffer >= 0 && channel>=0 && channel<32) return bbq[buffer][14][channel];
740  return 0;
741 }
742 
743 unsigned short StTriggerData2022::zdcAtAddress(int address, int prepost) const
744 {
745  return zdcAtChannel(address,prepost);
746 }
747 
748 unsigned short StTriggerData2022::zdcUnAttenuated(StBeamDirection eastwest, int prepost) const
749 {
750  int buffer = prepostAddress(prepost);
751  if (buffer >= 0) {
752  if (eastwest == east) return bbq[buffer][14][2];
753  else return bbq[buffer][14][18];
754  }
755  return 0;
756 }
757 
758 unsigned short StTriggerData2022::zdcAttenuated(StBeamDirection eastwest, int prepost) const
759 {
760  int buffer = prepostAddress(prepost);
761  if (buffer >= 0) {
762  if (eastwest == east) return bbq[buffer][14][3];
763  else return bbq[buffer][14][19];
764  }
765  return 0;
766 }
767 
768 unsigned short StTriggerData2022::zdcADC(StBeamDirection eastwest, int pmt, int prepost) const
769 {
770  int buffer = prepostAddress(prepost);
771  if (buffer >= 0 && pmt>=1 && pmt<=3) {
772  if (eastwest == east) {
773  if (pmt == 1) return bbq[buffer][14][0];
774  if (pmt == 2) return bbq[buffer][14][8];
775  if (pmt == 3) return bbq[buffer][14][9];
776  }
777  else {
778  if (pmt == 1) return bbq[buffer][14][16];
779  if (pmt == 2) return bbq[buffer][14][24];
780  if (pmt == 3) return bbq[buffer][14][25];
781  }
782  }
783  return 0;
784 }
785 
786 unsigned short StTriggerData2022::zdcTDC(StBeamDirection eastwest, int prepost) const
787 {
788  int buffer = prepostAddress(prepost);
789  if (buffer >= 0) {
790  if (eastwest == east) return bbq[buffer][14][6];
791  else return bbq[buffer][14][22];
792  }
793  return 0;
794 }
795 
796 unsigned short StTriggerData2022::zdcPmtTDC(StBeamDirection eastwest, int pmt, int prepost) const
797 {
798  int buffer = prepostAddress(prepost);
799  if (buffer >= 0 && pmt>=1 && pmt<=3) {
800  if (eastwest == east) {
801  if (pmt == 1) return bbq[buffer][14][4];
802  if (pmt == 2) return bbq[buffer][14][12];
803  if (pmt == 3) return bbq[buffer][14][13];
804  }
805  else {
806  if (pmt == 1) return bbq[buffer][14][20];
807  if (pmt == 2) return bbq[buffer][14][28];
808  if (pmt == 3) return bbq[buffer][14][29];
809  }
810  }
811  return 0;
812 }
813 
814 unsigned short StTriggerData2022::zdcHardwareSum(int prepost) const
815 {
816  int buffer = prepostAddress(prepost);
817  if (buffer >= 0) return bbq[buffer][14][11];
818  return 0;
819 }
820 
821 bool StTriggerData2022::zdcSMDPresent(int prepost) const
822 {
823  int buffer = prepostAddress(prepost);
824  if (buffer >= 0) return mMXQ[buffer];
825  return false;
826 }
827 
828 unsigned short StTriggerData2022::zdcSMD(StBeamDirection eastwest, int verthori, int strip, int prepost) const
829 {
830  static const int zdcsmd_map[2][2][8] ={
831  { { 31, 30, 29, 28, 27, 26, 25, 19} ,
832  { 24, 23, 22, 21, 20, 16, 18, 17} } ,
833  { { 15, 14, 13, 12, 11, 10, 9, 2} ,
834  { 8, 7, 6, 5, 4, 3, 0, 1} }
835  };
836  static const int zdcsmd_map2011[2][2][8] ={
837  { {24, 25, 26, 27, 28, 29, 30, 31} ,
838  {16, 17, 18, 19, 20, 21, 22, 23} } ,
839  { {8, 9, 10, 11, 12, 13, 14, 15} ,
840  {0, 1, 2, 3, 4, 5, 6, 7} }
841  };
842  if (verthori<0 || verthori>1) return 0;
843  if (strip<1 || strip>8) return 0;
844  int buffer = prepostAddress(prepost);
845  if (buffer >= 0) {
846  if(mRun<12034085){
847  return mxq[buffer][4][zdcsmd_map[eastwest][verthori][strip-1]];
848  }else{
849  return mxq[buffer][4][zdcsmd_map2011[eastwest][verthori][strip-1]];
850  }
851  }
852  return 0;
853 }
854 
855 unsigned short StTriggerData2022::zdcEarliestTDC(StBeamDirection eastwest, int prepost) const
856 {
857  int buffer = prepostAddress(prepost);
858  if (buffer >=0){
859  if (mBBC[buffer]){
860  if(mRun<12000000){
861  if (eastwest==east) {return ((mBBC[buffer]->ZDClayer1[3] >> 12) % 16) | ((mBBC[buffer]->ZDClayer1[2] % 256) << 4);}
862  else {return (mBBC[buffer]->ZDClayer1[3]) % 4096;}
863  }else{
864  if (eastwest==east) {return ((mBBC[buffer]->ZDClayer1[3] >> 10) % 64) | ((mBBC[buffer]->ZDClayer1[2] % 16) << 6);}
865  else {return (mBBC[buffer]->ZDClayer1[3]) % 1024;}
866  }
867  }
868  }
869  return 0;
870 }
871 
872 bool StTriggerData2022::zdcSumADCaboveThreshold(StBeamDirection eastwest, int prepost) const {
873  int buffer = prepostAddress(prepost);
874  if (buffer >=0){
875  if (mBBC[buffer]){
876  if(mRun<12000000){
877  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (27-16));}
878  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (24-16));}
879  }else{
880  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (25-16));}
881  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (22-16));}
882  }
883  }
884  }
885  return 0;
886 }
887 
888 bool StTriggerData2022::zdcFrontADCaboveThreshold(StBeamDirection eastwest, int prepost) const {
889  int buffer = prepostAddress(prepost);
890  if (buffer >=0){
891  if (mBBC[buffer]){
892  if(mRun<12000000){
893  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (29-16));}
894  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (26-16));}
895  }else{
896  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (23-16));}
897  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (20-16));}
898  }
899  }
900  }
901  return 0;
902 }
903 
904 bool StTriggerData2022::zdcBackADCaboveThreshold(StBeamDirection eastwest, int prepost) const {
905  int buffer = prepostAddress(prepost);
906  if (buffer >=0){
907  if (mBBC[buffer]){
908  if(mRun<12000000){
909  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (28-16));}
910  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (25-16));}
911  }else{
912  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (24-16));}
913  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (21-16));}
914  }
915  }
916  }
917  return 0;
918 }
919 
920 unsigned short StTriggerData2022::zdcTimeDifference() const
921 {
922  return L1_DSM->VTX[1]%256;
923 }
924 
925 bool StTriggerData2022::zdcSumADCaboveThresholdL2(StBeamDirection eastwest) const {
926  return L1_DSM->VTX[1] & (1 << ((eastwest==east) ? 10 : 11));
927 }
928 
929 bool StTriggerData2022::zdcFrontADCaboveThresholdL2(StBeamDirection eastwest) const {
930  return L1_DSM->VTX[1] & (1 << ((eastwest==east) ? 12 : 14));
931 }
932 
933 bool StTriggerData2022::zdcBackADCaboveThresholdL2(StBeamDirection eastwest) const {
934  return L1_DSM->VTX[1] & (1 << ((eastwest==east) ? 13 : 15));
935 }
936 
937 bool StTriggerData2022::zdcSumADCaboveThresholdL3(StBeamDirection eastwest) const {
938  if(mRun<12000000){ return lastDSM(2) & (1 << ((eastwest==east) ? 7 : 8)); }
939  else { return lastDSM(1) & (1 << ((eastwest==east) ? 7 : 8)); }
940 }
941 
942 bool StTriggerData2022::zdcFrontADCaboveThresholdL3(StBeamDirection eastwest) const {
943  if(mRun<12000000){ return lastDSM(2) & (1 << ((eastwest==east) ? 9 : 11)); }
944  else { return lastDSM(1) & (1 << ((eastwest==east) ? 9 : 11)); }
945 }
946 
947 bool StTriggerData2022::zdcBackADCaboveThresholdL3(StBeamDirection eastwest) const {
948  if(mRun<12000000){ return lastDSM(2) & (1 << ((eastwest==east) ? 10 : 12)); }
949  else { return lastDSM(1) & (1 << ((eastwest==east) ? 10 : 12)); }
950 }
951 
952 bool StTriggerData2022::zdcTimeDifferenceInWindow() const
953 {
954  if(mRun<12000000){ return lastDSM(2) & (1 << 6); }
955  else { return lastDSM(1) & (1 << 6); }
956 }
957 
958 unsigned short StTriggerData2022::zdcSMDHighestStrip(StBeamDirection eastwest, int verthori, int prepost) const
959 {
960  if(mRun<12000000) return 0;
961  // copy of the scaler output from ZDC SMD QT is sent to ZD101 J2
962  int buffer = prepostAddress(prepost);
963  if (buffer >=0){
964  if (mBBC[buffer]){
965  if (eastwest==east) {return (mBBC[buffer]->ZDClayer1[1] >> (verthori ? 6 : 9)) % 8;}
966  else {return (mBBC[buffer]->ZDClayer1[1] >> (verthori ? 0 : 3)) % 8;}
967  }
968  }
969  return 0;
970 }
971 
972 unsigned short StTriggerData2022::zdcTruncatedSum(StBeamDirection eastwest, int prepost) const
973 {
974  if(mRun<12000000) return 0;
975  int buffer = prepostAddress(prepost);
976  if (buffer >=0){
977  if (mBBC[buffer]){
978  if (eastwest==east) {return (mBBC[buffer]->ZDClayer1[2] >> (26-16)) % 8;}
979  else {return (mBBC[buffer]->ZDClayer1[2] >> (29-16)) % 8;}
980  }
981  }
982  return 0;
983 }
984 
985 unsigned short StTriggerData2022::pp2ppADC(StBeamDirection eastwest, int vh, int udio, int ch, int prepost) const
986 {
987  static const int map[2][2][2][2] ={ { { { 0, 1}, { 2, 3} } , { {16,17}, {18,19} } , } ,
988  { { { 8, 9}, {10,11} } , { {24,25}, {26,27} } , } };
989  if (vh<0 || vh>1) return 0;
990  if (udio<0 || udio>1) return 0;
991  if (ch<0 || ch>1) return 0;
992  int buffer = prepostAddress(prepost);
993  if (buffer >= 0) return mxq[buffer][2][map[eastwest][vh][udio][ch]];
994  return 0;
995 }
996 
997 unsigned short StTriggerData2022::pp2ppTAC(StBeamDirection eastwest, int vh, int udio, int ch, int prepost) const
998 {
999  static const int map[2][2][2][2] ={ { { { 0, 1}, { 2, 3} } , { {16,17}, {18,19} } , } ,
1000  { { { 8, 9}, {10,11} } , { {24,25}, {26,27} } , } };
1001  if (vh<0 || vh>1) return 0;
1002  if (udio<0 || udio>1) return 0;
1003  if (ch<0 || ch>1) return 0;
1004  int buffer = prepostAddress(prepost);
1005  if (buffer >= 0) return mxq[buffer][2][map[eastwest][vh][udio][ch]+4];
1006  return 0;
1007 }
1008 
1009 unsigned long StTriggerData2022::pp2ppDSM(int prepost) const {
1010  if (prepost!=0) return 0;
1011  return L1_DSM->TOF[7];
1012 }
1013 
1014 unsigned short StTriggerData2022::bemcLayer1DSM(int channel, int prepost) const {
1015  const int n_bemc_layer1=48;
1016  if (channel<0 || channel >=n_bemc_layer1) {
1017  gMessMgr->Warning() << "Barrel DSM layer 1 out of range (" << channel << ")" << endm;
1018  return 0;
1019  }
1020  int buffer = prepostAddress(prepost);
1021  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->BEMClayer1[channel];
1022  return 0;
1023 }
1024 
1025 unsigned short StTriggerData2022::eemcLayer1DSM(int channel, int prepost) const {
1026  const int n_eemc_layer1=16;
1027  if (channel<0 || channel >=n_eemc_layer1) {
1028  gMessMgr->Warning() << "Endap DSM layer 1 out of range (" << channel << ")" << endm;
1029  return 0;
1030  }
1031  int buffer = prepostAddress(prepost);
1032  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->EEMClayer1[channel];
1033  return 0;
1034 }
1035 
1036 unsigned short StTriggerData2022::emcLayer2DSM(int channel) const {
1037  const int n_emc_layer2=8;
1038  if (channel<0 || channel >=n_emc_layer2) {
1039  gMessMgr->Warning() << "EMC DSM layer 2 out of range (" << channel << ")" << endm;
1040  return 0;
1041  }
1042  return L1_DSM->EMC[channel];
1043 }
1044 
1045 unsigned short StTriggerData2022::tpcMaskDSM(int channel) const {
1046  const int n_tpcMask=8;
1047  if (channel<0 || channel >=n_tpcMask) {
1048  gMessMgr->Warning() << "TPCMask DSM out of range (" << channel << ")" << endm;
1049  return 0;
1050  }
1051  return L1_DSM->TPCMask[channel];
1052 }
1053 
1054 unsigned char StTriggerData2022::bemcHighTower(int patch_id, int prepost) const {
1055  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
1056  const int m_max_patch=300; // Full barrel
1057  if ( patch_id < 0 || patch_id >= m_max_patch) {
1058  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
1059  return 0;
1060  }
1061  int buffer = prepostAddress(prepost);
1062  if (buffer >= 0) {
1063  int dsm=patch_id/10;
1064  int channel=patch_id%10;
1065  unsigned short trg_word;
1066  if (dsm>=15) {
1067  if (mBCE[buffer])
1068  trg_word=decodeEmc12bit(dsm-15,channel,mBCE[buffer]->BEMCEast);
1069  else
1070  return 0;
1071  }
1072  else {
1073  if (mBCW[buffer])
1074  trg_word=decodeEmc12bit(dsm,channel,mBCW[buffer]->BEMCWest);
1075  else
1076  return 0;
1077  }
1078  return trg_word & 0x3F;
1079  }
1080  return 0;
1081 }
1082 
1083 unsigned char StTriggerData2022::bemcJetPatch (int patch_id, int prepost) const
1084 {
1085  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
1086  const int m_max_patch=300; // Full barrel
1087  if ( patch_id < 0 || patch_id >= m_max_patch) {
1088  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
1089  return 0;
1090  }
1091  int buffer = prepostAddress(prepost);
1092  if (buffer >= 0) {
1093  int dsm=patch_id/10;
1094  int channel=patch_id%10;
1095  unsigned short trg_word;
1096  if (dsm>=15) {
1097  if (mBCE[buffer])
1098  trg_word=decodeEmc12bit(dsm-15,channel,mBCE[buffer]->BEMCEast);
1099  else
1100  return 0;
1101  }
1102  else {
1103  if (mBCW[buffer])
1104  trg_word=decodeEmc12bit(dsm,channel,mBCW[buffer]->BEMCWest);
1105  else
1106  return 0;
1107  }
1108  return trg_word >> 6;
1109  }
1110  return 0;
1111 }
1112 
1113 
1114 unsigned char StTriggerData2022::eemcHighTower(int patch_id, int prepost) const
1115 {
1116  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
1117  const int m_max_patch=90;
1118  if ( patch_id < 0 || patch_id >= m_max_patch) {
1119  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
1120  return 0;
1121  }
1122  int buffer = prepostAddress(prepost);
1123  if (buffer >= 0 && mBC1[buffer]) {
1124  int dsm=patch_id/10;
1125  int channel=patch_id%10;
1126  unsigned short trg_word = decodeEmc12bit(dsm,channel,mBC1[buffer]->EEMC);
1127  return trg_word & 0x3F;
1128  }
1129  return 0;
1130 }
1131 
1132 unsigned char StTriggerData2022::eemcJetPatch (int patch_id, int prepost) const
1133 {
1134  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
1135  const int m_max_patch=90;
1136  if ( patch_id < 0 || patch_id >= m_max_patch) {
1137  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
1138  return 0;
1139  }
1140  int buffer = prepostAddress(prepost);
1141  if (buffer >= 0 && mBC1[buffer]) {
1142  int dsm=patch_id/10;
1143  int channel=patch_id%10;
1144  unsigned short trg_word = decodeEmc12bit(dsm,channel,mBC1[buffer]->EEMC);
1145  return trg_word >> 6;
1146  }
1147  return 0;
1148 }
1149 
1150 unsigned char StTriggerData2022::bemcHighestTowerADC(int prepost) const {
1151  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
1152  const int m_max_patch=300; // Full barrel
1153  unsigned char h=0;
1154  for (int i=1; i<m_max_patch; i++){
1155  unsigned char hh=bemcHighTower(i,prepost);
1156  if (h>hh) h=hh;
1157  }
1158  return h;
1159 }
1160 
1161 unsigned char StTriggerData2022::eemcHighestTowerADC(int prepost) const {
1162  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
1163  const int m_max_patch=90;
1164  unsigned char h=0;
1165  for (int i=1; i<m_max_patch; i++){
1166  unsigned char hh=eemcHighTower(i,prepost);
1167  if (h>hh) h=hh;
1168  }
1169  return h;
1170 }
1171 
1172 char* StTriggerData2022::getTriggerStructure()
1173 {
1174  return (char*) mData;
1175 }
1176 
1177 TriggerDataBlk2022* StTriggerData2022::getTriggerStructure2022()
1178 {
1179  return mData;
1180 }
1181 
1182 int StTriggerData2022::getRawSize() const
1183 {
1184  return mData->totalTriggerLength;
1185 }
1186 
1187 unsigned char* StTriggerData2022::getDsm0_BEMCE(int prepost) const {
1188  int buffer = prepostAddress(prepost);
1189  if (buffer >= 0) if (mBCE[buffer]) return mBCE[buffer]->BEMCEast;
1190  return 0;
1191 }
1192 
1193 unsigned char* StTriggerData2022::getDsm0_BEMCW(int prepost) const {
1194  int buffer = prepostAddress(prepost);
1195  if (buffer >= 0) if (mBCW[buffer]) return mBCW[buffer]->BEMCWest;
1196  return 0;
1197 }
1198 
1199 unsigned short* StTriggerData2022::getDsm1_BEMC(int prepost) const {
1200  int buffer = prepostAddress(prepost);
1201  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->BEMClayer1;
1202  return 0;
1203 }
1204 
1205 unsigned char* StTriggerData2022::getDsm0_EEMC(int prepost) const {
1206  int buffer = prepostAddress(prepost);
1207  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->EEMC;
1208  return 0;
1209 }
1210 
1211 unsigned short* StTriggerData2022::getDsm1_EEMC(int prepost) const{
1212  int buffer = prepostAddress(prepost);
1213  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->EEMClayer1;
1214  return 0;
1215 }
1216 
1217 unsigned short* StTriggerData2022::getDsm2_EMC() const{
1218  return L1_DSM->EMC;
1219 }
1220 
1221 unsigned short* StTriggerData2022::getDsm3() const{
1222  return L1_DSM->lastDSM;
1223 }
1224 
1225 int StTriggerData2022::L2ResultsOffset(StL2AlgorithmId id) const
1226 {
1227  switch(id) {
1228  default: return -999999999;
1229  }
1230 }
1231 
1232 bool StTriggerData2022::isL2Triggered(StL2TriggerResultType id) const
1233 {
1234  return false;
1235 }
1236 
1237 unsigned int StTriggerData2022::l2ResultLength() const
1238 {
1239  return sizeof(TrgSum->L2Result)/sizeof(unsigned int);
1240 }
1241 
1242 const unsigned int* StTriggerData2022::l2Result() const
1243 {
1244  return TrgSum->L2Result;
1245 }
1246 
1247 unsigned long long StTriggerData2022::l2sum() const
1248 {
1249  //printf("L2sum0=%08o\n",TrgSum->L2Sum[0]);
1250  //printf("L2sum1=%08o\n",TrgSum->L2Sum[1]);
1251  unsigned long long hi = TrgSum->L2Sum[1];
1252  unsigned long long lo = TrgSum->L2Sum[0];
1253  unsigned long long mask=(hi<<32) | lo;
1254  return mask;
1255 }
1256 
1257 unsigned short StTriggerData2022::vpdADC(StBeamDirection eastwest, int pmt, int prepost) const
1258 {
1259  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1260  if (pmt<1 || pmt>16) return 0;
1261  int buffer = prepostAddress(prepost);
1262  if (buffer >= 0) {
1263  if (mRun<=12003001) {return bbq[buffer][10+(int)eastwest*2][map[pmt-1]];}
1264  else {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]];}
1265  }
1266  return 0;
1267 }
1268 
1269 unsigned short StTriggerData2022::vpdTDC(StBeamDirection eastwest, int pmt, int prepost) const
1270 {
1271  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1272  if (pmt<1 || pmt>16) return 0;
1273  int buffer = prepostAddress(prepost);
1274  if (buffer >= 0) {
1275  if (mRun<=12003001) {return bbq[buffer][10+(int)eastwest*2][map[pmt-1]+4];}
1276  else {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]+4];}
1277  }
1278  return 0;
1279 }
1280 
1281 unsigned short StTriggerData2022::vpdADCHighThr(StBeamDirection eastwest, int pmt, int prepost) const
1282 {
1283  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1284  if (pmt<1 || pmt>16) return 0;
1285  int buffer = prepostAddress(prepost);
1286  if (buffer >= 0) {
1287  if (mRun<=12003001) {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]];}
1288  else {return mxq[buffer][6+(int)eastwest*2][map[pmt-1]];}
1289  }
1290  return 0;
1291 }
1292 
1293 unsigned short StTriggerData2022::vpdTDCHighThr(StBeamDirection eastwest, int pmt, int prepost) const
1294 {
1295  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1296  if (pmt<1 || pmt>16) return 0;
1297  int buffer = prepostAddress(prepost);
1298  if (buffer >= 0) {
1299  if (mRun<=12003001) {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]+4];}
1300  else {return mxq[buffer][6+(int)eastwest*2][map[pmt-1]+4];};
1301  }
1302  return 0;
1303 }
1304 
1305 unsigned short StTriggerData2022::vpdEarliestTDC(StBeamDirection eastwest, int prepost) const
1306 {
1307  int buffer = prepostAddress(prepost);
1308  if (buffer >= 0){
1309  if (mBBC[buffer]){
1310  if (mRun<=10096084){
1311  if (eastwest==east) {return mBBC[buffer]->VPD[6]%4096;}
1312  else {return mBBC[buffer]->VPD[4]%4096;}
1313  }
1314  else if(mRun<=12003001) {
1315  if (eastwest==east) {return mBBC[buffer]->VPD[2]%4096;}
1316  else {return mBBC[buffer]->VPD[0]%4096;}
1317  }
1318  else {
1319  if (eastwest==east) {return mBBC[buffer]->VPD[6]%4096;}
1320  else {return mBBC[buffer]->VPD[4]%4096;}
1321  }
1322 
1323  }
1324  }
1325  return 0;
1326 }
1327 
1328 unsigned short StTriggerData2022::vpdEarliestTDCHighThr(StBeamDirection eastwest, int prepost) const
1329 {
1330  int buffer = prepostAddress(prepost);
1331  if (buffer >= 0){
1332  if (mRun<=10365999){
1333  return 0;
1334  }
1335  else if(mRun<=12003001) {
1336  if (mBBC[buffer]){
1337  if (eastwest==east) {return mBBC[buffer]->VPD[6]%4096;}
1338  else {return mBBC[buffer]->VPD[4]%4096;}
1339  }
1340  }else if(mRun<=14001001){
1341  if(mMIX[buffer]){
1342  if (eastwest==east) {return mMIX[buffer]->MTD_P2PLayer1[13] + ((mMIX[buffer]->MTD_P2PLayer1[12]&0x0f)<<8);}
1343  else {return mMIX[buffer]->MTD_P2PLayer1[9] + ((mMIX[buffer]->MTD_P2PLayer1[8]&0x0f)<<8);}
1344  }
1345  }else {
1346  if(mMIX[buffer]){
1347  if (eastwest==east) {return mMIX[buffer]->MTD_P2PLayer1[11] + ((mMIX[buffer]->MTD_P2PLayer1[10]&0xf)<<8);}
1348  else {return (mMIX[buffer]->MTD_P2PLayer1[10]>>4) + ((mMIX[buffer]->MTD_P2PLayer1[9]&0xff)<<4);}
1349  }
1350  }
1351  }
1352  return 0;
1353 }
1354 
1355 unsigned short StTriggerData2022::vpdADCSum(StBeamDirection eastwest, int prepost) const
1356 {
1357  if(eastwest==east){
1358  return (bbcVP101(4,prepost) & 0x7ff);
1359  }else{
1360  return (bbcVP101(6,prepost) & 0x7ff);
1361  }
1362 }
1363 
1364 float StTriggerData2022::vpdMeanTimeDifference(int prepost) const
1365 {
1366  // return L1_DSM->VTX[7]%8192;
1367  unsigned int ne=(bbcVP101(4,prepost) >> 11) & 0x1f;
1368  unsigned int nw=(bbcVP101(6,prepost) >> 11) & 0x1f;
1369  unsigned int se=bbcVP101(5,prepost);
1370  unsigned int sw=bbcVP101(7,prepost);
1371  int nwse=nw*se;
1372  int nesw=ne*sw;
1373  int nenw=ne*nw;
1374  if(nenw>0) return float(nwse-nesw)/float(nenw);
1375  return -2000.0;
1376 }
1377 
1378 unsigned short StTriggerData2022::bbcVP101(int ch, int prepost) const
1379 {
1380  int map[8]={3, 2, 1, 0, 7, 6, 5, 4};
1381  if(ch<0 || ch>7) return 0;
1382  int buffer = prepostAddress(prepost);
1383  if (buffer >= 0 && mBBC[buffer]){
1384  return mBBC[buffer]->VPD[map[ch]];
1385  }
1386  return 0;
1387 }
1388 
1389 
1390 unsigned short StTriggerData2022::dsmTF201Ch(int ch) const // read TF201 data
1391 {
1392  int map[8]={3, 2, 1, 0, 7, 6, 5, 4};
1393  return L1_DSM->TOF[map[ch]]; //ch4-7 currently unused
1394 }
1395 
1396 unsigned short StTriggerData2022::mtd4AtAddress(int address, int prepost) const // read QT4 data
1397 {
1398  if (mRun<=15001001) return 0; // Run-14 onwards...
1399  int buffer = prepostAddress(prepost);
1400  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][14][address];
1401  return 0;
1402 }
1403 
1404 unsigned short StTriggerData2022::fmsADC(int crt, int adr, int ch, int prepost) const
1405 {
1406  int buffer = prepostAddress(prepost);
1407  if (buffer >= 0 && crt>=1 && crt<=8 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1408  switch(crt){
1409  case 0: return bbq[buffer][adr][ch];
1410  case 5: return eq3[buffer][adr][ch];
1411  case 6: return eq1[buffer][adr][ch];
1412  case 7: return eq2[buffer][adr][ch];
1413  case 8: return eq4[buffer][adr][ch];
1414  }
1415  }
1416  return 0;
1417 }
1418 
1419 unsigned short StTriggerData2022::fmsTDC(int crt, int adr, int ch, int prepost) const
1420 {
1421  int buffer = prepostAddress(prepost);
1422  if (buffer >= 0 && crt>=0 && crt<=8 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1423  switch(crt){
1424  case 0: return tbbq[buffer][adr][ch];
1425  case 5: return teq3[buffer][adr][ch];
1426  case 6: return teq1[buffer][adr][ch];
1427  case 7: return teq2[buffer][adr][ch];
1428  case 8: return teq4[buffer][adr][ch];
1429  }
1430  }
1431  return 0;
1432 }
1433 
1434 unsigned short StTriggerData2022::epdADC(int crt, int adr, int ch, int prepost) const
1435 {
1436  int buffer = prepostAddress(prepost);
1437  if (buffer >= 0 && crt>=1 && crt<=4 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1438  switch(crt){
1439  case 1: return eq1[buffer][adr][ch];
1440  case 2: return eq2[buffer][adr][ch];
1441  case 3: return eq3[buffer][adr][ch];
1442  case 4: return eq4[buffer][adr][ch];
1443  }
1444  }
1445  return 0;
1446 }
1447 
1448 unsigned short StTriggerData2022::epdTDC(int crt, int adr, int ch, int prepost) const
1449 {
1450  int buffer = prepostAddress(prepost);
1451  if (buffer >= 0 && crt>=1 && crt<=4 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1452  switch(crt){
1453  case 1: return teq1[buffer][adr][ch];
1454  case 2: return teq2[buffer][adr][ch];
1455  case 3: return teq3[buffer][adr][ch];
1456  case 4: return teq4[buffer][adr][ch];
1457  }
1458  }
1459  return 0;
1460 }
1461 
1462 unsigned short StTriggerData2022::mxqAtSlotAddress(int address, int prepost, int slot) const
1463 {
1464  int buffer = prepostAddress(prepost);
1465  if (buffer >= 0 && address>=0 && address<32){
1466  if (slot >= 0 && slot<16){
1467  return mxq[buffer][slot][address];
1468  }
1469  }
1470  return 0;
1471 }
1472 
1473 unsigned short StTriggerData2022::mtdQtAtCh(int qtid, int address, int prepost) const
1474 { // read all the MTD QTs data, and the range of qtid is 1-8
1475  int map1[4] = {0, 10, 12, 14};
1476  int map2[8] = {0, 9, 10, 11, 12, 13, 14, 15};
1477  int map3[4] = {0, 9, 11, 13};
1478 
1479  int buffer = prepostAddress(prepost);
1480  if(buffer>=0 && qtid>0 && address>=0 && address<32){
1481  if(mRun<=12003001){
1482  if(qtid>1) return 0;
1483  else return mxq[buffer][map1[qtid-1]][address];
1484  }
1485  else if(mRun<=14001001){
1486  if(qtid>2) return 0;
1487  else return mxq[buffer][map1[qtid-1]][address];
1488  }
1489  else if(mRun<=15001001){
1490  if(qtid>3) return 0;
1491  else return mxq[buffer][map1[qtid-1]][address];
1492  }
1493  else if(mRun<=17001001){
1494  if(qtid>4) return 0;
1495  else return mxq[buffer][map1[qtid-1]][address];
1496  }
1497  else if(mRun<=18001001){
1498  if(qtid>8) return 0;
1499  else return mxq[buffer][map2[qtid-1]][address];
1500  }
1501  else{
1502  if(qtid>4) return 0;
1503  else return mxq[buffer][map3[qtid-1]][address];
1504  }
1505  }
1506 
1507  return 0;
1508 }
1509 
1510 unsigned short StTriggerData2022::mtdAtAddress(int address, int prepost) const
1511 {
1512  int buffer = prepostAddress(prepost);
1513  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][0][address];
1514  return 0;
1515 }
1516 
1517 unsigned short StTriggerData2022::mtdgemAtAddress(int address, int prepost) const
1518 {
1519  if (mRun<=12003001) return 0;
1520  int buffer = prepostAddress(prepost);
1521  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][10][address];
1522  return 0;
1523 }
1524 
1525 unsigned short StTriggerData2022::mtd3AtAddress(int address, int prepost) const
1526 {
1527  if (mRun<=14001001) return 0; // Run-13 onwards...
1528  int buffer = prepostAddress(prepost);
1529  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][12][address];
1530  return 0;
1531 }
1532 
1533 
1534 unsigned short StTriggerData2022::mtdAdc(StBeamDirection eastwest, int pmt, int prepost) const
1535 {
1536  //pmt in not used for 2022, it is place holder for next year
1537  int buffer = prepostAddress(prepost);
1538  if (buffer >= 0 && pmt==0){
1539  if (eastwest==east) {
1540  if (mRun<=10133008) return mxq[buffer][0][0];
1541  else return mxq[buffer][0][24];
1542  }
1543  if (eastwest==west) return mxq[buffer][0][8];
1544  }
1545  return 0;
1546 }
1547 
1548 unsigned short StTriggerData2022::mtdTdc(StBeamDirection eastwest, int pmt, int prepost) const
1549 {
1550  //pmt in not used for 2022, it is place holder for next year
1551  int buffer = prepostAddress(prepost);
1552  if (buffer >= 0 && pmt==0){
1553  if (eastwest==east) {
1554  if (mRun<=10133008) return mxq[buffer][0][4];
1555  else return mxq[buffer][0][28];
1556  }
1557  if (eastwest==west) return mxq[buffer][0][12];
1558  }
1559  return 0;
1560 }
1561 
1562 unsigned char StTriggerData2022::mtdDsmAtCh(int ch, int prepost) const
1563 {
1564  int map[16] = {7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8};
1565  //int map2[8] = {3, 2, 1, 0, 7, 6, 5, 4};
1566  int buffer = prepostAddress(prepost);
1567  if (buffer >= 0 && ch>=0){
1568  if(mMIX[buffer]){
1569  if(ch<16){
1570  return mMIX[buffer]->MTD_P2PLayer1[map[ch]];
1571  }else if(ch<32){
1572  //int add= 8 + map2[(ch-16)/2];
1573  unsigned char v=0;
1574  //if(ch%2==0){ v=(unsigned char)((mMIX[buffer]->TPCpreMask[add] & 0xff00)>>8);}
1575  //else { v=(unsigned char)((mMIX[buffer]->TPCpreMask[add] & 0x00ff) );}
1576  return v;
1577  }
1578  }
1579  }
1580  return 0;
1581 }
1582 
1583 bool StTriggerData2022::mtdDsmHit(int pmt, int prepost) const
1584 {
1585  //pmt in not used for 2022, it is place holder for next year
1586  int buffer = prepostAddress(prepost);
1587  if (buffer >= 0){
1588  if(mMIX[buffer]){
1589  if(mRun<10133008 && mRun<11000000){
1590  if( (mMIX[buffer]->MTD_P2PLayer1[5] & 0x1) && (mMIX[buffer]->MTD_P2PLayer1[5] & 0x10) ) return true;
1591  }
1592  else{
1593  if(prepost!=0) return false;
1594  return (L1_DSM->TOF[3] & 0x1);
1595  }
1596  }
1597  }
1598  return false;
1599 }
1600 
1601 unsigned short StTriggerData2022::mtdVpdTacDiff() const
1602 {
1603  return (L1_DSM->TOF[3] & 0x3fff);
1604 }
1605 
1606 unsigned short StTriggerData2022::tofAtAddress(int address, int prepost) const
1607 {
1608  int buffer = prepostAddress(prepost);
1609  if (buffer>=0 && address>=0 && address<48) {
1610  if (mMIX[buffer]) return mMIX[buffer]->TOF[address];
1611  }
1612  return 0;
1613 }
1614 
1615 unsigned short StTriggerData2022::tofTrayMultiplicity(int tray, int prepost) const
1616 {
1617  int dsmmap[8] = {3,2,1,0,7,6,5,4};
1618  int traydsm[120] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5,
1619  5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3,
1620  3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
1621  1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
1622  3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
1623  5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
1624  int traych[120] = { 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3,
1625  2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3,
1626  2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3,
1627  18,19,10,11,12,13,14,15,16,17,18,19,10,11,12,13,14,15,16,17,
1628  18,19,10,11,12,13,14,15,16,17,18,19,10,11,12,13,14,15,16,17,
1629  18,19,10,11,12,13,14,15,16,17,18,19,10,11,12,13,14,15,16,17};
1630  int buffer = prepostAddress(prepost);
1631  if (buffer>=0 && tray>=1 && tray<=120) {
1632  if (mMIX[buffer]) {
1633  int address = traydsm[tray-1]*8 + dsmmap[traych[tray-1]/3];
1634  int ch = traych[tray-1]%3;
1635  return (mMIX[buffer]->TOF[address] >> (5*ch)) & 0x1f;
1636  }
1637  }
1638  return 0;
1639 }
1640 
1641 unsigned short StTriggerData2022::tofMultiplicity(int prepost) const
1642 {
1643  if (prepost==0) return L1_DSM->TOF[1]%8192;
1644  return 0;
1645 }
1646 
1647 void StTriggerData2022::dump() const
1648 {
1649  printf("***** StTriggerData Dump *****\n");
1650  printf(" mDebug=%d mData=%p\n",mDebug,mData);
1651  printf(" Year=%d EvtDesc version=%x header version%x\n",year(),version(),mData->FormatVersion);
1652  printf(" Run#=%d Event#=%d\n",mRun,eventNumber());
1653  printf(" %d pre and %d post crossing data available\n",numberOfPreXing(),numberOfPostXing());
1654  printf(" Token=%d TriggerWord=%x ActionWord=%x BusyStatus=%x\n",
1655  token(), triggerWord(), actionWord(), busyStatus());
1656  printf(" TUC Bits=%d : ",tcuBits());
1657  for (int i=0; i<16; i++) {printf(" %d",(tcuBits()>>(15-i))%2);}; printf("\n");
1658  printf(" BunchId 7bit=%d 48bit=%d\n",bunchId7Bit(), bunchId48Bit());
1659  printf(" Spin Bits=%d : ",spinBit());
1660  for (int i=0; i<8; i++) {printf(" %d",(spinBit()>>(7-i))%2);}; printf("\n");
1661  // printf(" CTB ADC : "); for (int i=0; i<240;i++){ printf("%d ",ctb(i,0)); }; printf("\n");
1662  printf(" BBC East ADC : "); for (int i=1; i<=16;i++){ printf("%2d ",bbcADC(east,i,0)); }; printf("\n");
1663  printf(" BBC East TAC : "); for (int i=1; i<=16;i++){ printf("%2d ",bbcTDC(east,i,0)); }; printf("\n");
1664  printf(" BBC West ADC : "); for (int i=1; i<=16;i++){ printf("%2d ",bbcADC(west,i,0)); }; printf("\n");
1665  printf(" BBC West TAC : "); for (int i=1; i<=16;i++){ printf("%2d ",bbcTDC(west,i,0)); }; printf("\n");
1666  for (int i=-numberOfPreXing(); i<=static_cast<int>(numberOfPostXing()); i++){
1667  printf(" BBC Sums %d xing : ",i);
1668  printf("East=%d West=%d Large tile East=%d West=%d\n",
1669  bbcADCSum(east,i),bbcADCSum(west,i),
1670  bbcADCSumLargeTile(east,i),bbcADCSumLargeTile(west,i));
1671  }
1672  printf(" BBC Earilest : "); printf("East=%d West=%d Difference+256=%d\n",
1673  bbcEarliestTDC(east,0),bbcEarliestTDC(west,0),bbcTimeDifference());
1674  printf(" ZDC Earilest : "); printf("East=%d West=%d Difference=%d\n",
1675  zdcEarliestTDC(east,0),zdcEarliestTDC(west,0),zdcTimeDifference());
1676  printf(" ZDC Sum(A) East : ");printf("%d ",zdcAttenuated(east)); printf("\n");
1677  printf(" ZDC Sum(A) West : ");printf("%d ",zdcAttenuated(west)); printf("\n");
1678  printf(" ZDC Sum(UA) East : ");printf("%d ",zdcUnAttenuated(east)); printf("\n");
1679  printf(" ZDC Sum(UA) West : ");printf("%d ",zdcUnAttenuated(west)); printf("\n");
1680  printf(" VPD E Earliest TAC : %d\n", vpdEarliestTDC(east));
1681  printf(" VPD W Earliest TAC : %d\n", vpdEarliestTDC(west));
1682  printf(" VPD TimeDifference : %d\n", vpdTimeDifference());
1683  printf(" L2 result : \n");
1684  for (int j=0; j<4 ;j++) { for (int k=0; k<16; k++) {printf("%u ",*(l2Result()+j*16+k)); } printf("\n");}
1685  printf("BBClayer1:");
1686  int buffer = prepostAddress(0);
1687  if (buffer >=0){
1688  if (mBBC[buffer]){
1689  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, mBBC[buffer]->BBClayer1[i]);
1690  }
1691  }
1692  printf("\n");
1693  printf("ZDClayer1:");
1694  if (buffer >=0){
1695  if (mBBC[buffer]){
1696  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, mBBC[buffer]->ZDClayer1[i]);
1697  }
1698  }
1699  printf("\n");
1700  printf("VPDlayer1:");
1701  if (buffer >=0){
1702  if (mBBC[buffer]){
1703  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, mBBC[buffer]->VPD[i]);
1704  }
1705  }
1706  printf("TOFMult=%d\n",tofMultiplicity());
1707  printf("\n");
1708 
1709  //EPD
1710  int map[4][16]={ {0x01,0xff, 0x02,0xff, 0x03,0xff, 0x04,0xff, 0x05,0xff, 0x06,0xff, 0x07,0xff, 0x08,0xff},
1711  {0x11,0xff, 0x12,0xff, 0x13,0xff, 0x14,0xff, 0x15,0xff, 0x16,0xff, 0x17,0xff, 0x18,0xff},
1712  {0x21,0xff, 0x22,0xff, 0x23,0xff, 0x24,0xff, 0x25,0xff, 0x26,0xff, 0x27,0xff, 0x28,0xff},
1713  {0x31,0xff, 0x32,0xff, 0x33,0xff, 0x34,0xff, 0x35,0xff, 0x36,0xff, 0x37,0xff, 0x38,0xff}};
1714  int mbc[4][16]={ {0x0c,0xff, 0x0c,0xff, 0x0b,0xff, 0x0b,0xff, 0x0c,0xff, 0x0c,0xff, 0x0d,0xff, 0x0b,0xff},
1715  {0x0c,0xff, 0x0c,0xff, 0x0b,0xff, 0x0b,0xff, 0x0c,0xff, 0x0c,0xff, 0x0d,0xff, 0x0b,0xff},
1716  {0x0c,0xff, 0x0c,0xff, 0x0b,0xff, 0x0b,0xff, 0x0c,0xff, 0x0d,0xff, 0x0b,0xff, 0x0b,0xff},
1717  {0x0c,0xff, 0x0b,0xff, 0x0b,0xff, 0x0b,0xff, 0x0c,0xff, 0x0c,0xff, 0x0d,0xff, 0x0b,0xff}};
1718  int epdm[4][16]; memset(epdm,0,sizeof(epdm));
1719  for(int c=1; c<=4; c++){
1720  for(int s=0; s<16; s++){
1721  int bcd=mbc[c-1][s] & 0x0f;
1722  int eq=map[c-1][s];
1723  if(eq!=0xff){
1724  printf("EQ%1d S=%2d EQ0%02x bd=%1x 1/2 : ",c,s,eq,bcd);
1725  }else{
1726  printf("EQ%1d S=%2d EQ bd= 1/2 : ",c,s);
1727  }
1728  for (int ch=0; ch<32; ch++){
1729  if(ch==16){
1730  if(eq!=0xff){
1731  printf("\nEQ%1d S=%2d EQ0%02x bd=%1x 2/2 : ",c,s,eq,bcd);
1732  }else{
1733  printf("\nEQ%1d S=%2d EQ bd= 1/2 : ",c,s);
1734  }
1735  }
1736  printf("%4d ",epdADC(c,s,ch));
1737  if(map[c-1][s]<0xff){
1738  if(mbc[c-1][s]==0xb){
1739  if(epdADC(c,s,ch)>16) epdm[c-1][s]++;
1740  }else if(mbc[c-1][s]==0xc && (ch/4)%2==0){
1741  if(epdADC(c,s,ch)>16 && epdADC(c,s,ch+4)>300 && epdADC(c,s,ch+4)<2900) epdm[c-1][s]++;
1742  }
1743  }
1744  }
1745  printf(" mult=%d\n",epdm[c-1][s]);
1746  }
1747  }
1748  printf("EP001 TAC+hit: "); for(int c=0; c<8; c++){ printf("%4x ",epdLayer0t(c));} printf("\n");
1749  printf("EP002 TAC+hit: "); for(int c=8; c<16; c++){ printf("%4x ",epdLayer0t(c));} printf("\n");
1750  printf("EP003 Nhit: "); for(int c=0; c<8; c++){ printf("%2d ",epdLayer0aMult(c));} printf("\n");
1751  printf("EP004 Nhit: "); for(int c=8; c<16; c++){ printf("%2d ",epdLayer0aMult(c));} printf("\n");
1752  /*
1753  printf("EP005 Nhit1: "); for(int c=0; c<10; c++){ printf("%2d ",epdLayer0hMult(c,1));} printf("\n");
1754  printf("EP005 Nhit2: "); for(int c=0; c<10; c++){ printf("%2d ",epdLayer0hMult(c,2));} printf("\n");
1755  printf("EP006 Nhit1: "); for(int c=10; c<20; c++){ printf("%2d ",epdLayer0hMult(c,1));} printf("\n");
1756  printf("EP006 Nhit2: "); for(int c=10; c<20; c++){ printf("%2d ",epdLayer0hMult(c,2));} printf("\n");
1757  for(int c=1; c<=3; c++){
1758  for(int q=1; q<=11; q++){
1759  int eq=(c-1)*0x10 + q;
1760  printf("mult-EQ%03x %02x %02x | %02x : %02x\n",eq,epdNHitsQT(c,q,1),epdNHitsQT(c,q,2),epdm[c-1][q],epdNHitsQT(c,q,1)^epdm[c-1][q]);
1761  }
1762  printf("\n");
1763  }
1764  printf("EP102 : "); for(int c=0; c<8; c++){ printf("%04x ", epdLayer1b(c));} printf("\n");
1765  printf("EP102 east Mult : "); for(int r=1; r<=5; r++){ printf("%3d ", epdLayer1bMult(east, r));} printf("\n");
1766  printf("EP102 west Mult : "); for(int r=1; r<=5; r++){ printf("%3d ", epdLayer1bMult(west, r));} printf("\n");
1767  */
1768  printf("EPD(VP201) mult total = %3d diff= %3d\n",epdMultTotal(),epdMultDiff());
1769 
1770  printf("VTX:");
1771  if (L1_DSM){
1772  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, L1_DSM->VTX[i]);
1773  }
1774  printf("\n");
1775  printf("Last DSM:");
1776  if (L1_DSM){
1777  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, L1_DSM->lastDSM[i]);
1778  }
1779  printf("\n");
1780  printf("***** End StTriggerData Dump *****\n");
1781 }
1782 
1783 void StTriggerData2022::swapRawDet(DataBlock2022* data, int name, int hlength,int bs)
1784 {
1785  BELayerBlock2022* bc1;
1786  MIXBlock2022* mix;
1787  BBCBlock2022 *bbc;
1788  QTBlock2022* qtdata;
1789  int header_length = 8;
1790  if(bs) swapI((unsigned int*)&data->length);
1791  switch(name){
1792  case y22MXQ_CONF_NUM : case y22EQ3_CONF_NUM : case y22BBQ_CONF_NUM :
1793  case y22QT1_CONF_NUM : case y22QT2_CONF_NUM : case y22QT3_CONF_NUM : case y22QT4_CONF_NUM :
1794  case y22EQ1_CONF_NUM : case y22EQ2_CONF_NUM : case y22EQ4_CONF_NUM :
1795  header_length = 12; break;
1796  }
1797  if (hlength != data->length + header_length){
1798  mErrorFlag = mErrorFlag | (1 << name);
1799  printf("StTriggerData2022: Error reading Block=%2d [%1c%1c%1c%1c] length %d != %d + %d\n",
1800  name,data->name[0],data->name[1],data->name[2],data->name[3],
1801  hlength,data->length,header_length);
1802  printf("StTriggerData2022: Droping the data block =%2d [%1c%1c%1c%1c] with ErrorFlag=0x%x\n",
1803  name,data->name[0],data->name[1],data->name[2],data->name[3],mErrorFlag);
1804  data=0;
1805  return;
1806  }
1807  if (bs){
1808  switch(name){
1809  case y22BC1_CONF_NUM :
1810  bc1 = (BELayerBlock2022*) data;
1811  swapSSn((unsigned int*)bc1->BEMClayer1,48);
1812  swapSSn((unsigned int*)bc1->EEMClayer1,16);
1813  break;
1814  case y22MIX_CONF_NUM :
1815  mix = (MIXBlock2022*) data;
1816  //swapSSn((unsigned int*)mix->FPDEastNSLayer1,8); //FPDEastNSLayer1 removed
1817  swapSSn((unsigned int*)mix->TOFLayer1,8+48);
1818  break;
1819  case y22BCW_CONF_NUM :
1820  //only char
1821  break;
1822  case y22BCE_CONF_NUM :
1823  //only char
1824  break;
1825  case y22BBC_CONF_NUM :
1826  bbc = (BBCBlock2022*) data;
1827  //use actual length in case DSM2 fake data insert fails and data is short by 8.
1828  swapSSn((unsigned int*)bbc->BBClayer1,(data->length)/2);
1829  //swapSSn((unsigned int*)bbc->BBClayer1,8+8+8+8+16
1830  break;
1831  case y22FMS_CONF_NUM :
1832  //only char
1833  break;
1834  case y22MXQ_CONF_NUM :
1835  case y22EQ3_CONF_NUM :
1836  case y22BBQ_CONF_NUM :
1837  case y22QT1_CONF_NUM :
1838  case y22QT2_CONF_NUM :
1839  case y22QT3_CONF_NUM :
1840  case y22QT4_CONF_NUM :
1841  case y22EQ1_CONF_NUM :
1842  case y22EQ2_CONF_NUM :
1843  case y22EQ4_CONF_NUM :
1844  qtdata = (QTBlock2022*) data;
1845  swapI((unsigned int*)&qtdata->dataLoss);
1846  swapIn(qtdata->data, qtdata->length/4);
1847  break;
1848  }
1849  }
1850  if(mDebug>0)
1851  printf("Read id=%2d name=%1c%1c%1c%1c length=%d\n",
1852  name,data->name[0],data->name[1],data->name[2],data->name[3],data->length);
1853 }
1854 
1855 void StTriggerData2022::Streamer(TBuffer &R__b)
1856 {
1857  // Stream an object of class StTriggerData2022.
1858 
1859  if (R__b.IsReading()) {
1860  R__b.ReadClassBuffer(StTriggerData2022::Class(),this);
1861  // cout << "StTriggerData2022::Streamer read trigger data!!!"<<endl;
1862  if(mData) readData();
1863  }
1864  else {
1865  R__b.WriteClassBuffer(StTriggerData2022::Class(),this);
1866  }
1867 }