StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTriggerData2008.cxx
1  /***************************************************************************
2  *
3  * $Id: StTriggerData2008.cxx,v 2.6 2009/11/23 16:34:07 fisyak Exp $
4  *
5  * Author: Akio Ogawa, Nov 2007
6  ***************************************************************************
7  *
8  * Description: Concrete implementation of StTriggerData for 2008.
9  *
10  ***************************************************************************
11  *
12  * $Log: StTriggerData2008.cxx,v $
13  * Revision 2.6 2009/11/23 16:34:07 fisyak
14  * Cleanup, remove dependence on dst tables, clean up software monitors
15  *
16  * Revision 2.5 2009/03/19 02:46:01 ullrich
17  * Add 2nd argument (pre/post) to vpdEarliestTDC().
18  *
19  * Revision 2.4 2008/03/13 16:58:28 ullrich
20  * Move include file from .cxx to .h file
21  *
22  * Revision 2.3 2008/03/10 19:35:31 ullrich
23  * New methods: tofAtAddress() and tofMultiplicity().
24  *
25  * Revision 2.2 2007/12/11 18:11:13 ullrich
26  * Fix bugs in QT decoding (Akio).
27  *
28  * Revision 2.1 2007/11/19 19:32:17 ullrich
29  * Initial Revision.
30  *
31  *
32  **************************************************************************/
33 #include <string.h>
34 #include <assert.h>
35 #include <iostream>
36 #include "StTriggerData2008.h"
37 
38 ClassImp(StTriggerData2008)
39 
41 {
42  mYear=2008;
43  mData=0;
44 }
45 
46 StTriggerData2008::StTriggerData2008(const TrgDataType2008* data, int run)
47 {
48  mYear=2008;
49  mRun = run;
50  mData= new TrgDataType2008;
51  int npre = data->EvtDesc.npre;
52  int npost = data->EvtDesc.npost;
53  assert(npre >=0);
54  assert(npre <=5);
55  assert(npost>=0);
56  assert(npost<=5);
57  int size = sizeof(EvtDescData2008)+sizeof(TrgSumData2008)
58  + sizeof(RawTrgDet2008)*(npre+npost+1);
59  memcpy(mData,data,size);
60  memset((char*)mData+size,0,sizeof(TrgDataType2008)-size);
61  //dump();
62 }
63 
64 unsigned int StTriggerData2008::version() const
65 {
66  return mData->EvtDesc.TrgDataFmtVer;
67 }
68 
69 StTriggerData2008::~StTriggerData2008() {delete mData;}
70 
71 unsigned int StTriggerData2008::token() const
72 {
73  return mData->EvtDesc.TrgToken;
74 }
75 
76 unsigned int StTriggerData2008::triggerWord() const
77 {
78  return mData->EvtDesc.TriggerWord;
79 }
80 
81 unsigned int StTriggerData2008::actionWord() const
82 {
83  return
84  ( (unsigned short)(mData->EvtDesc.actionWdTrgCommand) * 16 * 16 * 16 ) +
85  ( (unsigned short)(mData->EvtDesc.actionWdDaqCommand) * 16 * 16 ) +
86  ( mData->EvtDesc.actionWdDetectorBitMask & 0x00ff ) ;
87 }
88 
89 unsigned int StTriggerData2008::numberOfPreXing() const
90 {
91  return mData->EvtDesc.npre;
92 }
93 
94 unsigned int StTriggerData2008::numberOfPostXing() const
95 {
96  return mData->EvtDesc.npost;
97 }
98 
99 unsigned short StTriggerData2008::busyStatus() const{
100  return mData->EvtDesc.modifiedBusyStatus;
101 }
102 
103 unsigned short StTriggerData2008::dsmInput() const{
104  return mData->EvtDesc.DSMInput;
105 }
106 
107 unsigned short StTriggerData2008::trgToken() const{
108  return mData->EvtDesc.TrgToken;
109 }
110 
111 unsigned short StTriggerData2008::dsmAddress() const{
112  return mData->EvtDesc.DSMAddress;
113 }
114 
115 unsigned short StTriggerData2008::mAddBits() const{
116  return mData->EvtDesc.addBits;
117 }
118 
119 unsigned short StTriggerData2008::bcData(int channel) const{
120  return mData->TrgSum.DSMdata.BCdata[channel];
121 }
122 
123 unsigned short StTriggerData2008::lastDSM(int channel) const{
124  return mData->TrgSum.DSMdata.lastDSM[channel];
125 }
126 
127 unsigned short StTriggerData2008::tcuBits() const
128 {
129  return mData->EvtDesc.DSMInput;
130 }
131 
132 unsigned int StTriggerData2008::bunchCounterHigh() const
133 {
134  return mData->EvtDesc.bunchXing_hi;
135 }
136 
137 unsigned int StTriggerData2008::bunchCounterLow() const
138 {
139  return mData->EvtDesc.bunchXing_lo;
140 }
141 
142 unsigned int StTriggerData2008::bunchId48Bit() const
143 {
144  unsigned long long bxinghi,bxing1,bxinglo, bx;
145  bxinghi = mData->TrgSum.DSMdata.BCdata[3];
146  bxing1 = mData->TrgSum.DSMdata.BCdata[10];
147  bxinglo = (bxing1 << 16) + mData->TrgSum.DSMdata.BCdata[11];
148  bx = (bxinghi << 32) + bxinglo;
149  return (int)(bx % 120);
150 }
151 
152 unsigned int StTriggerData2008::bunchId7Bit() const
153 {
154  int b7=0, b7dat;
155  b7dat = mData->TrgSum.DSMdata.BCdata[2];
156  b7 = b7dat & 0x7f;
157  return b7;
158 }
159 
160 unsigned int StTriggerData2008::spinBit() const
161 {
162  return (mData->TrgSum.DSMdata.lastDSM[7]/16)%256;
163 }
164 
165 unsigned int StTriggerData2008::spinBitYellowFilled() const
166 {
167  unsigned int sb = spinBit();
168  return sb%2;
169 }
170 
171 unsigned int StTriggerData2008::spinBitYellowUp() const
172 {
173  unsigned int sb = spinBit();
174  return (sb/2)%2;
175 }
176 
177 unsigned int StTriggerData2008::spinBitYellowDown() const
178 {
179  unsigned int sb = spinBit();
180  return (sb/4)%2;
181 }
182 
183 unsigned int StTriggerData2008::spinBitYellowUnpol() const
184 {
185  unsigned int sb = spinBit();
186  return (sb/8)%2;
187 }
188 
189 unsigned int StTriggerData2008::spinBitBlueFilled() const
190 {
191  unsigned int sb = spinBit();
192  return (sb/16)%2;
193 }
194 
195 unsigned int StTriggerData2008::spinBitBlueUp() const
196 {
197  unsigned int sb = spinBit();
198  return (sb/32)%2;
199 }
200 
201 unsigned int StTriggerData2008::spinBitBlueDown() const
202 {
203  unsigned int sb = spinBit();
204  return (sb/64)%2;
205 }
206 
207 unsigned int StTriggerData2008::spinBitBlueUnpol() const
208 {
209  unsigned int sb = spinBit();
210  return (sb/128)%2;
211 }
212 
213 unsigned short StTriggerData2008::ctbRaw(int address, int prepost) const
214 {
215  return mData->rawTriggerDet[prepostAddress(prepost)].CTB[address];
216 }
217 
218 unsigned short StTriggerData2008::ctb(int pmt, int prepost) const
219 {
220  static const unsigned char ctbMap[240] = {
221  7, 6, 5, 4, 3, 23, 22, 21, 20, 19,
222  2, 1, 0, 15, 14, 18, 17, 16, 31, 30,
223  13, 12, 11, 10, 9, 29, 28, 27, 26, 25,
224  39, 38, 37, 36, 35, 55, 54, 53, 52, 51,
225  34, 33, 32, 47, 46, 50, 49, 48, 63, 62,
226  45, 44, 43, 42, 41, 61, 60, 59, 58, 57,
227  71, 70, 69, 68, 67, 87, 86, 85, 84, 83,
228  66, 65, 64, 79, 78, 82, 81, 80, 95, 94,
229  77, 76, 75, 74, 73, 93, 92, 91, 90, 89,
230  103, 102, 101, 100, 99, 119, 118, 117, 116, 115,
231  98, 97, 96, 111, 110, 114, 113, 112, 127, 126,
232  109, 108, 107, 106, 105, 125, 124, 123, 122, 121,
233  135, 134, 133, 132, 131, 151, 150, 149, 148, 147,
234  130, 129, 128, 143, 142, 146, 145, 144, 159, 158,
235  141, 140, 139, 138, 137, 157, 156, 155, 154, 153,
236  167, 166, 165, 164, 163, 183, 182, 181, 180, 179,
237  162, 161, 160, 175, 174, 178, 177, 176, 191, 190,
238  173, 172, 171, 170, 169, 189, 188, 187, 186, 185,
239  199, 198, 197, 196, 195, 215, 214, 213, 212, 211,
240  194, 193, 192, 207, 206, 210, 209, 208, 223, 222,
241  205, 204, 203, 202, 201, 221, 220, 219, 218, 217,
242  231, 230, 229, 228, 227, 247, 246, 245, 244, 243,
243  226, 225, 224, 239, 238, 242, 241, 240, 255, 254,
244  237, 236, 235, 234, 233, 253, 252, 251, 250, 249,
245  } ;
246  int v=0;
247  int add=prepostAddress(prepost);
248  if(add>=0) v=mData->rawTriggerDet[add].CTB[ctbMap[pmt]];
249  return v;
250 }
251 
252 unsigned short StTriggerData2008::ctbTraySlat(int tray, int slat, int prepost) const{
253  static const unsigned char ctbMap[2][120] = {
254  { 109, 108, 107, 106, 105, 7, 6, 5, 4, 3,
255  2, 1, 0, 15, 14, 13, 12, 11, 10, 9,
256  39, 38, 37, 36, 35, 34, 33, 32, 47, 46,
257  45, 44, 43, 42, 41, 71, 70, 69, 68, 67,
258  66, 65, 64, 79, 78, 77, 76, 75, 74, 73,
259  103, 102, 101, 100, 99, 98, 97, 96, 111, 110,
260  141, 140, 139, 138, 137, 167, 166, 165, 164, 163,
261  162, 161, 160, 175, 174, 173, 172, 171, 170, 169,
262  199, 198, 197, 196, 195, 194, 193, 192, 207, 206,
263  205, 204, 203, 202, 201, 231, 230, 229, 228, 227,
264  226, 225, 224, 239, 238, 237, 236, 235, 234, 233,
265  135, 134, 133, 132, 131, 130, 129, 128, 143, 142},
266  { 125, 124, 123, 122, 121, 23, 22, 21, 20, 19,
267  18, 17, 16, 31, 30, 29, 28, 27, 26, 25,
268  55, 54, 53, 52, 51, 50, 49, 48, 63, 62,
269  61, 60, 59, 58, 57, 87, 86, 85, 84, 83,
270  82, 81, 80, 95, 94, 93, 92, 91, 90, 89,
271  119, 118, 117, 116, 115, 114, 113, 112, 127, 126,
272  157, 156, 155, 154, 153, 183, 182, 181, 180, 179,
273  178, 177, 176, 191, 190, 189, 188, 187, 186, 185,
274  215, 214, 213, 212, 211, 210, 209, 208, 223, 222,
275  221, 220, 219, 218, 217, 247, 246, 245, 244, 243,
276  242, 241, 240, 255, 254, 253, 252, 251, 250, 249,
277  151, 150, 149, 148, 147, 146, 145, 144, 159, 158}
278  };
279  int v=0;
280  int add=prepostAddress(prepost);
281  if(add>=0) v=mData->rawTriggerDet[add].CTB[ctbMap[slat][tray]];
282  return v;
283 }
284 
285 unsigned short StTriggerData2008::ctbSum(int prepost) const{
286  unsigned short sum=0;
287  for (int i=1; i<240; i++){sum+=ctb(i,prepost);}
288  return sum;
289 }
290 
291 unsigned short StTriggerData2008::bbcADC(StBeamDirection eastwest, int pmt, int prepost) const
292 {
293  static const int q_map[2][24] = {
294  { 8 , 5 , 4 , 40 , 37 , 36 , 7 , 6 ,
295  3 , 2 , 1 , 39 , 38 , 35 , 34 , 33 ,
296  72 , 71 , 70 , 69 , 68 , 67 , 66 , 65 },
297  { 24 , 21 , 20 , 56 , 53 , 52 , 23 , 22 ,
298  19 , 18 , 17 , 55 , 54 , 51 , 50 , 49 ,
299  88 , 87 , 86 , 85 , 84 , 83 , 82 , 81 }
300  };
301  return mData->rawTriggerDet[prepostAddress(prepost)].BBC[q_map[eastwest][pmt-1]-1];
302 }
303 
304 unsigned short StTriggerData2008::bbcTDC(StBeamDirection eastwest, int pmt, int prepost) const
305 {
306  static const int t_map[2][24] ={
307  { 16 , 13 , 12 , 48 , 45 , 44 , 15 , 14 ,
308  11 , 10 , 9 , 47 , 46 , 43 , 42 , 41 ,
309  80 , 79 , 78 , 77 , 76 , 75 , 74 , 73 },
310  { 32 , 29 , 28 , 64 , 61 , 60 , 31 , 30 ,
311  27 , 26 , 25 , 63 , 62 , 59 , 58 , 57 ,
312  96 , 95 , 94 , 93 , 92 , 91 , 90 , 89 }
313  };
314  return mData->rawTriggerDet[prepostAddress(prepost)].BBC[t_map[eastwest][pmt-1]-1];
315 }
316 
317 unsigned short StTriggerData2008::bbcADCSum(StBeamDirection eastwest, int prepost) const
318 {
319  int address = prepostAddress(prepost);
320  if (eastwest==east){
321  return
322  mData->rawTriggerDet[address].BBClayer1[7]%2048+
323  mData->rawTriggerDet[address].BBClayer1[3]%2048;
324  }
325  else {
326  return
327  mData->rawTriggerDet[address].BBClayer1[5]%2048+
328  mData->rawTriggerDet[address].BBClayer1[1]%2048;
329  }
330 }
331 
332 unsigned short StTriggerData2008::bbcADCSumLargeTile(StBeamDirection eastwest, int prepost) const
333 {
334  int address = prepostAddress(prepost);
335  if (eastwest==east) { return mData->rawTriggerDet[address].BBClayer1[11]%2048; }
336  else { return mData->rawTriggerDet[address].BBClayer1[10]%2048; }
337 }
338 
339 unsigned short StTriggerData2008::bbcEarliestTDC(StBeamDirection eastwest, int prepost) const
340 {
341  int address = prepostAddress(prepost), t1, t2;
342  if (eastwest==east){
343  t1 = mData->rawTriggerDet[address].BBClayer1[6]%256;
344  t2 = mData->rawTriggerDet[address].BBClayer1[2]%256;
345  }
346  else {
347  t1 = mData->rawTriggerDet[address].BBClayer1[4]%256;
348  t2 = mData->rawTriggerDet[address].BBClayer1[0]%256;
349  }
350  return (t1>t2) ? t1 : t2;
351 }
352 
353 unsigned short StTriggerData2008::bbcTimeDifference() const
354 {
355  return mData->TrgSum.DSMdata.VTX[3]%512;
356 }
357 
358 unsigned short StTriggerData2008::fpd(StBeamDirection eastwest, int module, int pmt, int prepost) const
359 {
360  static const short fpdmap[2][6][49] = {
361  //East
362  {
363  //East North
364  {39, 38, 37, 36, 35, 34, 33,
365  7, 6, 5, 23, 22, 21, 55,
366  4, 3, 2, 20, 19, 18, 54,
367  1, 0, 15, 17, 16, 31, 53,
368  14, 13, 12, 30, 29, 28, 52,
369  11, 10, 9, 27, 26, 25, 51,
370  32, 47, 46, 45, 44, 43, 42},
371  //East South
372  { 103,101,100, 99, 98, 97, 96,
373  71, 70, 69, 87, 86, 85, 48,
374  68, 67, 66, 84, 83, 82, 63,
375  65, 64, 79, 81, 80, 95, 61,
376  78, 77 ,76, 94, 93, 92, 60,
377  75, 74, 73, 91, 90, 89, 59,
378  111,110,109,108, 107, 106,105},
379  //East Top
380  {135, 134, 133, 132, 131, 130, 129, 128, 143, 142,
381  119, 118, 117, 116, 115, 114, 113, 112,
382  127, 126, 125, 124, 123, 122, 121,
383  -1, -1, -1,
384  -1, -1, -1, -1, -1, -1, -1,
385  -1, -1, -1, -1, -1, -1, -1,
386  -1, -1, -1, -1, -1, -1, -1},
387  //East Bottom
388  {151, 150, 149, 148, 147, 146, 145, 144,
389  159, 158, 157, 156, 155, 154, 153,
390  167, 166, 165, 164, 163, 162, 161, 160, 175, 174,
391  -1, -1, -1,
392  -1, -1, -1, -1, -1, -1, -1,
393  -1, -1, -1, -1, -1, -1, -1,
394  -1, -1, -1, -1, -1, -1, -1},
395  //East North PreShower
396  { 50, 49, 141, 140, 139, 138, 137,
397  -1, -1, -1, -1, -1, -1, -1,
398  -1, -1, -1, -1, -1, -1, -1,
399  -1, -1, -1, -1, -1, -1, -1,
400  -1, -1, -1, -1, -1, -1, -1,
401  -1, -1, -1, -1, -1, -1, -1,
402  -1, -1, -1, -1, -1, -1, -1},
403  //East South PreShower
404  { 58, 57, 173, 172, 171, 170, 169,
405  -1, -1, -1, -1, -1, -1, -1,
406  -1, -1, -1, -1, -1, -1, -1,
407  -1, -1, -1, -1, -1, -1, -1,
408  -1, -1, -1, -1, -1, -1, -1,
409  -1, -1, -1, -1, -1, -1, -1,
410  -1, -1, -1, -1, -1, -1, -1},
411  },
412  //West
413  {
414  //West North
415  { -1, -1, -1, -1, -1, -1, -1,
416  -1, -1, -1, -1, -1, -1, -1,
417  -1, -1, -1, -1, -1, -1, -1,
418  -1, -1, -1, -1, -1, -1, -1,
419  -1, -1, -1, -1, -1, -1, -1,
420  -1, -1, -1, -1, -1, -1, -1,
421  -1, -1, -1, -1, -1, -1, -1},
422  //West South
423  { 71, 70, 87, 86, 96, 97, 48,
424  69, 68, 85, 84, 98, 99, 63,
425  67, 66, 83, 82, 100, 101, 62,
426  65, 64, 81, 80, 102, 103, 61,
427  79, 78, 90, 91, 106, 107, 60,
428  77, 76, 92, 93, 108, 109, 59,
429  75, 74, 94, 95, 110, 111, 58},
430  //West Top
431  { -1, -1, -1, -1, -1, -1, -1,
432  -1, -1, -1, -1, -1, -1, -1,
433  -1, -1, -1, -1, -1, -1, -1,
434  -1, -1, -1, -1, -1, -1, -1,
435  -1, -1, -1, -1, -1, -1, -1,
436  -1, -1, -1, -1, -1, -1, -1,
437  -1, -1, -1, -1, -1, -1, -1},
438  //West Bottom
439  { 77, 70, 69, 68, 67,
440  66, 65, 64, 79, 78,
441  87, 86, 85, 84, 83,
442  82, 81, 80, 95, 94,
443  93, 76, 91, 90, 89,
444  -1, -1, -1,
445  -1, -1, -1, -1, -1, -1, -1,
446  -1, -1, -1, -1, -1, -1, -1,
447  -1, -1, -1, -1, -1, -1, -1},
448  //West North PreShower
449  { -1, -1, -1, -1, -1, -1, -1,
450  -1, -1, -1, -1, -1, -1, -1,
451  -1, -1, -1, -1, -1, -1, -1,
452  -1, -1, -1, -1, -1, -1, -1,
453  -1, -1, -1, -1, -1, -1, -1,
454  -1, -1, -1, -1, -1, -1, -1,
455  -1, -1, -1, -1, -1, -1, -1},
456  //West South PreShower
457  { 7, 6, 5, 4, 3, 2, 1,
458  -1, -1, -1, -1, -1, -1, -1,
459  -1, -1, -1, -1, -1, -1, -1,
460  -1, -1, -1, -1, -1, -1, -1,
461  -1, -1, -1, -1, -1, -1, -1,
462  -1, -1, -1, -1, -1, -1, -1,
463  -1, -1, -1, -1, -1, -1, -1},
464  }
465  };
466  int address = fpdmap[eastwest][module][pmt-1];
467  if (address>=0){
468  if (eastwest==east){
469  if (address<112) return mData->rawTriggerDet[prepostAddress(prepost)].FPDEastNSLayer0[address];
470  else return mData->rawTriggerDet[prepostAddress(prepost)].FPDEastTBLayer0[address-112];
471  }
472  else {
473  return 0;
474  }
475  }
476  else {
477  return 0;
478  }
479 }
480 
481 unsigned short StTriggerData2008::fpdSum(StBeamDirection eastwest, int module) const
482 {
483  static const short map[2][4]={{3,2,1,0},{7,6,5,4}};
484  static const short nbit[2][4]={{16384,16384,8192,8192},{16384,16384,8192,8192}};
485  return mData->TrgSum.DSMdata.FPD[map[eastwest][module]] % nbit[eastwest][module];
486 }
487 
488 unsigned short StTriggerData2008::fpdLayer1DSMRaw(StBeamDirection eastwest, int channel, int prepost) const{
489  if (eastwest==east){
490  if (channel<8) return mData->rawTriggerDet[prepostAddress(prepost)].FPDEastNSLayer1[channel];
491  }
492  return 0;
493 }
494 
495 unsigned short StTriggerData2008::fpdLayer1DSM(StBeamDirection eastwest, int module, int board, int prepost) const{
496  static const short map[4][4]={{3,2,1,0},{7,6,5,4},{3,2,6,7},{1,0,4,5}};
497  if (board<4){
498  if (eastwest==east){
499  if (module<2) return mData->rawTriggerDet[prepostAddress(prepost)].FPDEastNSLayer1[map[module][board]];
500  else return 0;
501  }
502  else{
503  return 0;
504  }
505  }
506  return 0;
507 }
508 
509 unsigned short StTriggerData2008::fpdLayer2DSMRaw(int channel) const{
510  if (channel<8) return mData->TrgSum.DSMdata.FPD[channel];
511  return 0;
512 }
513 
514 unsigned short StTriggerData2008::fpdLayer2DSM(StBeamDirection eastwest, int module) const{
515  static const int dsmmap[2][4]={{3,2,1,0},{7,6,5,4}};
516  if (module<4) return mData->TrgSum.DSMdata.FPD[dsmmap[eastwest][module]];
517  return 0;
518 }
519 
520 unsigned short StTriggerData2008::zdcAtChannel(int channel, int prepost) const
521 {
522  static const int dsmmap[16]={7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
523  if (channel>=0 && channel<16){ return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[dsmmap[channel]]; }
524  return 0;
525 }
526 
527 unsigned short StTriggerData2008::zdcAtAddress(int address, int prepost) const
528 {
529  if (address>=0 && address<16){ return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[address]; }
530  return 0;
531 }
532 
533 unsigned short StTriggerData2008::zdcUnAttenuated(StBeamDirection eastwest, int prepost) const
534 {
535  if (eastwest==east) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[4];} // fixed bug: was 3
536  if (eastwest==west) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[0];}
537  return 0;
538 }
539 
540 unsigned short StTriggerData2008::zdcAttenuated(StBeamDirection eastwest, int prepost) const
541 {
542  if (eastwest==east) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[13];}
543  if (eastwest==west) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[10];}
544  return 0;
545 }
546 
547 unsigned short StTriggerData2008::zdcADC(StBeamDirection eastwest, int pmt, int prepost) const
548 {
549  if (eastwest==east && pmt==1) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[7];}
550  if (eastwest==east && pmt==2) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[6];}
551  if (eastwest==east && pmt==3) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[5];}
552  if (eastwest==west && pmt==1) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[3];}
553  if (eastwest==west && pmt==2) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[2];}
554  if (eastwest==west && pmt==3) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[1];}
555  return 0;
556 
557 }
558 
559 unsigned short StTriggerData2008::zdcTDC(StBeamDirection eastwest, int prepost) const
560 {
561  if (eastwest==east) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[8];}
562  if (eastwest==west) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[9];}
563  return 0;
564 }
565 
566 unsigned short StTriggerData2008::zdcHardwareSum(int prepost) const
567 {
568  return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[14];
569 }
570 
571 unsigned short StTriggerData2008::zdcSMD(StBeamDirection eastwest, int verthori, int strip, int prepost) const
572 {
573  // new map from Gang Wang (gwang@physics.ucla.edu) 2008 March 26
574  static const int zdcsmd_map[2][2][8] ={
575  { { 7, 6, 5, 4, 3, 2, 1,11} ,
576  { 0,15,14,13,12,8, 10, 9} } ,
577  { {23,22,21,20,19,18,17,26} ,
578  {16,31,30,29,28,27,24,25} }
579  };
580  if (verthori<0 || verthori>1) return 0;
581  if (strip<1 || strip>8) return 0; //the last one in vertical strips is for LED. Could be used for Forward counter later. T.A.H.
582  int add=-1;
583  add=zdcsmd_map[eastwest][verthori][strip-1];
584  if(add>=0) return mData->rawTriggerDet[prepostAddress(prepost)].ZDCSMD[add];
585  else return 0;
586 };
587 
588 unsigned short StTriggerData2008::bemcLayer1DSM(int channel, int prepost) const {
589  const int n_bemc_layer1=48;
590  if (channel<0 || channel >=n_bemc_layer1) {
591  gMessMgr->Warning() << "Barrel DSM layer 1 out of range (" << channel << ")" << endm;
592  return 0;
593  }
594  return mData->rawTriggerDet[prepostAddress(prepost)].BEMClayer1[channel];
595 }
596 
597 unsigned short StTriggerData2008::eemcLayer1DSM(int channel, int prepost) const {
598  const int n_eemc_layer1=48;
599  if (channel<0 || channel >=n_eemc_layer1) {
600  gMessMgr->Warning() << "Endap DSM layer 1 out of range (" << channel << ")" << endm;
601  return 0;
602  }
603  return mData->rawTriggerDet[prepostAddress(prepost)].EEMClayer1[channel];
604 }
605 
606 unsigned short StTriggerData2008::emcLayer2DSM(int channel) const {
607  const int n_emc_layer2=8;
608  if (channel<0 || channel >=n_emc_layer2) {
609  gMessMgr->Warning() << "EMC DSM layer 2 out of range (" << channel << ")" << endm;
610  return 0;
611  }
612  return mData->TrgSum.DSMdata.EMC[channel];
613 }
614 
615 unsigned char StTriggerData2008::bemcHighTower(int patch_id, int prepost) const
616 {
617  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
618  const int m_max_patch=300; // Full barrel
619 
620  if ( patch_id < 0 || patch_id >= m_max_patch) {
621  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
622  return 0;
623  }
624 
625  int dsm=patch_id/10;
626  int channel=patch_id%10;
627  unsigned short trg_word;
628  if (dsm>=15)
629  trg_word=decodeEmc12bit(dsm-15,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCEast);
630  else
631  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCWest);
632  return trg_word & 0x3F;
633 }
634 
635 unsigned char StTriggerData2008::bemcJetPatch (int patch_id, int prepost) const
636 {
637  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
638  const int m_max_patch=300; // Full barrel
639 
640  if ( patch_id < 0 || patch_id >= m_max_patch) {
641  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
642  return 0;
643  }
644 
645  int dsm=patch_id/10;
646  int channel=patch_id%10;
647  unsigned short trg_word;
648  if (dsm>=15)
649  trg_word=decodeEmc12bit(dsm-15,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCEast);
650  else
651  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCWest);
652  return trg_word >> 6;
653 }
654 
655 unsigned char StTriggerData2008::eemcHighTower(int patch_id, int prepost) const
656 {
657  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
658  const int m_max_patch=90;
659 
660  if ( patch_id < 0 || patch_id >= m_max_patch) {
661  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
662  return 0;
663  }
664 
665  int dsm=patch_id/10;
666  int channel=patch_id%10;
667  unsigned short trg_word;
668  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].EEMC);
669  return trg_word & 0x3F;
670 }
671 
672 unsigned char StTriggerData2008::eemcJetPatch (int patch_id, int prepost) const
673 {
674  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
675  const int m_max_patch=90;
676 
677  if ( patch_id < 0 || patch_id >= m_max_patch) {
678  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
679  return 0;
680  }
681 
682  int dsm=patch_id/10;
683  int channel=patch_id%10;
684  unsigned short trg_word;
685  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].EEMC);
686  return trg_word >> 6;
687 }
688 
689 unsigned char StTriggerData2008::bemcHighestTowerADC(int prepost) const
690 {
691  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
692  const int m_max_patch=300; // Full barrel
693  unsigned char h=0;
694  for (int i=1; i<m_max_patch; i++){
695  unsigned char hh=bemcHighTower(i,prepost);
696  if (h>hh) h=hh;
697  }
698  return h;
699 }
700 
701 unsigned char StTriggerData2008::eemcHighestTowerADC(int prepost) const
702 {
703  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
704  const int m_max_patch=90;
705  unsigned char h=0;
706  for (int i=1; i<m_max_patch; i++){
707  unsigned char hh=eemcHighTower(i,prepost);
708  if (h>hh) h=hh;
709  }
710  return h;
711 }
712 
713 void StTriggerData2008::dump() const
714 {
715  printf("***** StTriggerData Dump *****\n");
716  printf(" Year=%d Version=%x\n",year(),version());
717  printf(" %d pre and %d post crossing data available\n",numberOfPreXing(),numberOfPostXing());
718  printf(" Token=%d TriggerWord=%x ActionWord=%x BusyStatus=%x\n",
719  token(), triggerWord(), actionWord(), busyStatus());
720  printf(" TUC Bits=%d : ",tcuBits());
721  for (int i=0; i<16; i++) {printf(" %d",(tcuBits()>>(15-i))%2);}; printf("\n");
722  printf(" BunchId 7bit=%d 48bit=%d\n",bunchId7Bit(), bunchId48Bit());
723  printf(" Spin Bits=%d : ",spinBit());
724  for (int i=0; i<8; i++) {printf(" %d",(spinBit()>>(7-i))%2);}; printf("\n");
725  printf(" CTB ADC : "); for (int i=0; i<240;i++){ printf("%d ",ctb(i,0)); }; printf("\n");
726  printf(" BBC East ADC : "); for (int i=1; i<=24;i++){ printf("%d ",bbcADC(east,i,0)); }; printf("\n");
727  printf(" BBC West ADC : "); for (int i=1; i<=24;i++){ printf("%d ",bbcADC(west,i,0)); }; printf("\n");
728  printf(" BBC East TAC : "); for (int i=1; i<=16;i++){ printf("%d ",bbcTDC(east,i,0)); }; printf("\n");
729  printf(" BBC West TAC : "); for (int i=1; i<=16;i++){ printf("%d ",bbcTDC(west,i,0)); }; printf("\n");
730  for (int i=-numberOfPreXing(); i<=static_cast<int>(numberOfPostXing()); i++){
731  printf(" BBC Sums %d xing : ",i);
732  printf("East=%d West=%d Large tile East=%d West=%d\n",
733  bbcADCSum(east,i),bbcADCSum(west,i),
734  bbcADCSumLargeTile(east,i),bbcADCSumLargeTile(west,i));
735  }
736  printf(" BBC Earilest : "); printf("East=%d West=%d Difference+256=%d\n",
737  bbcEarliestTDC(east,0),bbcEarliestTDC(west,0),bbcTimeDifference());
738  printf(" FPD East North : ");for (int i=1; i<=49;i++){ printf("%d ",fpd(east,0,i,0)); }; printf("\n");
739  printf(" FPD East South : ");for (int i=1; i<=49;i++){ printf("%d ",fpd(east,1,i,0)); }; printf("\n");
740  printf(" FPD East Top : ");for (int i=1; i<=25;i++){ printf("%d ",fpd(east,2,i,0)); }; printf("\n");
741  printf(" FPD East Bottom : ");for (int i=1; i<=25;i++){ printf("%d ",fpd(east,3,i,0)); }; printf("\n");
742  printf(" FPD East North PS: ");for (int i=1; i<= 7;i++){ printf("%d ",fpd(east,4,i,0)); }; printf("\n");
743  printf(" FPD East South PS: ");for (int i=1; i<= 7;i++){ printf("%d ",fpd(east,5,i,0)); }; printf("\n");
744  printf(" FPD West South : ");for (int i=1; i<=49;i++){ printf("%d ",fpd(west,1,i,0)); }; printf("\n");
745  printf(" FPD West Bottom : ");for (int i=1; i<=25;i++){ printf("%d ",fpd(west,3,i,0)); }; printf("\n");
746  printf(" FPD West South PS: ");for (int i=1; i<= 7;i++){ printf("%d ",fpd(west,5,i,0)); }; printf("\n");
747  printf(" FPD Sums East : ");for (int j=0; j<4 ;j++) printf("%d ",fpdSum(east,j)); printf("\n");
748  printf(" FPD Sums West : ");for (int j=0; j<4 ;j++) printf("%d ",fpdSum(west,j)); printf("\n");
749  printf(" ZDC Sum(A) East : ");printf("%d ",zdcAttenuated(east)); printf("\n");
750  printf(" ZDC Sum(A) West : ");printf("%d ",zdcAttenuated(west)); printf("\n");
751  printf(" ZDC Sum(UA) East : ");printf("%d ",zdcUnAttenuated(east)); printf("\n");
752  printf(" ZDC Sum(UA) West : ");printf("%d ",zdcUnAttenuated(west)); printf("\n");
753  printf(" VPD E Earliest TAC : %d\n", vpdEarliestTDC(east));
754  printf(" VPD W Earliest TAC : %d\n", vpdEarliestTDC(west));
755  printf(" VPD TimeDifference : %d\n", vpdTimeDifference());
756  printf(" TOF : "); for (int j=0; j<16 ;j++) {printf("%d ",tofAtAddress(j));} printf("\n");
757  printf(" TOF Multiplicity : %d\n",tofMultiplicity());
758  printf(" NQTData=%d\n",nQTdata());
759  printf(" QTLastWord=0x%x\n",(QTdata())[nQTdata()-1]);
760  printf(" L2 result : \n");
761  for (int j=0; j<4 ;j++) { for (int k=0; k<16; k++) {printf("%u ",*(l2Result()+j*16+k)); } printf("\n");}
762  printf("\n");
763  printf("***** StTriggerData Dump *****\n");
764 }
765 
766 char* StTriggerData2008::getTriggerStructure()
767 {
768  return (char*) mData;
769 }
770 
771 TrgDataType2008* StTriggerData2008::getTriggerStructure2008()
772 {
773  return mData;
774 }
775 
776 int StTriggerData2008::getRawSize() const
777 {
778  int npre = numberOfPreXing();
779  int npost = numberOfPostXing();
780  int rawSize=sizeof(EvtDescData2008)+sizeof(TrgSumData2008)
781  + sizeof(RawTrgDet2008)*(npre+npost+1);
782  return rawSize;
783 }
784 
785 unsigned char * StTriggerData2008::getDsm0_EEMC(int prepost) const {
786  return mData->rawTriggerDet[prepostAddress(prepost)].EEMC;
787 }
788 
789 unsigned short int * StTriggerData2008::getDsm1_EEMC(int prepost) const{
790  return mData->rawTriggerDet[prepostAddress(prepost)].EEMClayer1;
791 }
792 
793 unsigned short int * StTriggerData2008::getDsm2_EMC() const{
794  return mData->TrgSum.DSMdata.EMC;
795 }
796 
797 unsigned short int * StTriggerData2008::getDsm3() const{
798  return mData->TrgSum.DSMdata.lastDSM;
799 }
800 
801 int StTriggerData2008::L2ResultsOffset(StL2AlgorithmId id) const
802 {
803  switch(id) {
804  case l2Diagnostic: return L2RESULTS_2008_OFFSET_TRG;
805  case l2EmcCheck: return L2RESULTS_2008_OFFSET_EMC_CHECK;
806  case l2Jpsi: return L2RESULTS_2008_OFFSET_JPSI;
807  case l2Upsilon: return L2RESULTS_2008_OFFSET_UPS;
808  case l2EmcPedestal: return L2RESULTS_2008_OFFSET_EMC_PED;
809  case l2Pi0Gamma: return L2RESULTS_2008_OFFSET_GAMMA;
810  case l2Dijet: return L2RESULTS_2008_OFFSET_DIJET;
811  default: return -999999999;
812  }
813 }
814 
815 bool StTriggerData2008::isL2Triggered(StL2TriggerResultType id) const
816 {
817  return false;
818 
819  /*
820  if(mRun<7000000) return false;
821  if(mRun>7270000) return false;
822 
823  int offset;
824  offset=L2ResultsOffset(l2Dijet);
825  L2jetResults2006 *jet = (L2jetResults2006 *) &(mData->TrgSum.L2Result[offset]);
826  offset=L2ResultsOffset(l2Pi0Gamma);
827  L2gammaResult *gam_bemc = (L2gammaResult *) &(mData->TrgSum.L2Result[offset]);
828  L2gammaResult *gam_eemc = (L2gammaResult *) &(mData->TrgSum.L2Result[offset+2]);
829 
830  switch(id) {
831  case l2Trg2006BEMCGammaPi:
832  return (gam_bemc->trigger & 0x3)==0x3;
833  break;
834  case l2Trg2006BEMCGammaPiRandom:
835  return gam_bemc->trigger & 0x4;
836  break;
837  case l2Trg2006EEMCGammaPi:
838  return (gam_eemc->trigger & 0x3)==0x3;
839  break;
840  case l2Trg2006EEMCGammaPiRandom:
841  return gam_eemc->trigger & 0x4;
842  break;
843  case l2Trg2006MonoJet:
844  return jet->int0.decision & 0x40;
845  break;
846  case l2Trg2006DiJet:
847  return jet->int0.decision & 0x80;
848  break;
849  case l2Trg2006RandomJet:
850  return jet->int0.decision & 0x20;
851  break;
852  default:
853  return false;
854  }
855  */
856 }
857 
858 unsigned int StTriggerData2008::l2ResultLength() const
859 {
860  return sizeof(mData->TrgSum.L2Result)/sizeof(unsigned int);
861 }
862 
863 const unsigned int* StTriggerData2008::l2Result() const
864 {
865  return mData->TrgSum.L2Result;
866 }
867 
868 unsigned short StTriggerData2008::vpdADC(StBeamDirection eastwest, int pmt, int prepost) const
869 {
870  static const int map[2][16] = {
871  { 7, 6, 5, 4, 3, 2, 1, 0,
872  23, 22, 21, 20, 19, 18, 17, 16} ,
873  { 39, 38, 37, 36, 35, 34, 33, 32,
874  55, 54, 53, 52, 51, 50, 49, 48}
875  };
876  return mData->rawTriggerDet[prepostAddress(prepost)].VPD[map[eastwest][pmt-1]];
877 }
878 
879 unsigned short StTriggerData2008::vpdTDC(StBeamDirection eastwest, int pmt, int prepost) const
880 {
881  static const int map[2][16] = {
882  { 15, 14, 13, 12, 11, 10, 9, 8,
883  31, 30, 29, 28, 27, 26, 25, 24} ,
884  { 47, 46, 45, 44, 43, 42, 41, 40,
885  63, 62, 61, 60, 59, 58, 57, 56}
886  };
887  return mData->rawTriggerDet[prepostAddress(prepost)].VPD[map[eastwest][pmt-1]];
888 }
889 
890 unsigned short StTriggerData2008::vpdEarliestTDC(StBeamDirection eastwest, int prepost) const
891 {
892  if(prepost!=0) return 0;
893  int map[2][2] = {{2, 0},{6, 4}};
894  int i1 = map[eastwest][0];
895  int i2 = map[eastwest][1];
896  bool b1 = (mData->TrgSum.DSMdata.VPD[i1] >> 8) & 0x1;
897  bool b2 = (mData->TrgSum.DSMdata.VPD[i2] >> 8) & 0x1;
898  int t1 = mData->TrgSum.DSMdata.VPD[i1] & 0xFF;
899  int t2 = mData->TrgSum.DSMdata.VPD[i2] & 0xFF;
900  if(b1 && b2) {return (t1>t2) ? t1 : t2;}
901  else if(b1) {return t1;}
902  else if(b2) {return t2;}
903  else {return 0;}
904 }
905 
906 unsigned short StTriggerData2008::vpdTimeDifference() const
907 {
908  return mData->TrgSum.DSMdata.CTB[4] & 0x1FF;
909 }
910 
911 unsigned short StTriggerData2008::nQTdata(int prepost) const
912 {
913  return mData->rawTriggerDet[prepostAddress(prepost)].QQTdataBytes/4;
914 }
915 
916 unsigned int* StTriggerData2008::QTdata(int prepost) const
917 {
918  return mData->rawTriggerDet[prepostAddress(prepost)].QQTdata;
919 }
920 
921 unsigned char* StTriggerData2008::getDsm_FMS(int prepost) const {return mData->rawTriggerDet[prepostAddress(prepost)].FPDW;}
922 unsigned char* StTriggerData2008::getDsm01_FMS(int prepost) const {return mData->rawTriggerDet[prepostAddress(prepost)].FPDEastNSLayer0;}
923 unsigned char* StTriggerData2008::getDsm02_FMS(int prepost) const {return mData->rawTriggerDet[prepostAddress(prepost)].FPDEastTBLayer0;}
924 unsigned short int* StTriggerData2008::getDsm1_FMS(int prepost) const {return mData->rawTriggerDet[prepostAddress(prepost)].FPDEastNSLayer1;}
925 unsigned short int* StTriggerData2008::getDsm2_FMS() const {return mData->TrgSum.DSMdata.FPD;}
926 
927 unsigned short StTriggerData2008::mtdAtAddress(int address, int prepost) const
928 {
929  if (address>=0 && address<32){ return mData->rawTriggerDet[prepostAddress(prepost)].MTD[address]; }
930  return 0;
931 }
932 
933 unsigned short StTriggerData2008::mtdAdc(StBeamDirection eastwest, int pmt, int prepost) const
934 {
935  static const int map[2][8] = {
936  { 6, 5, 11, 12, 13, 10, 9, 8},
937  { 7, 4, 3, 2, 1, 0, 15, 14}
938  };
939  if(pmt>=0 && pmt<8) { return mData->rawTriggerDet[prepostAddress(prepost)].MTD[map[eastwest][pmt]]; }
940  return 0;
941 }
942 
943 unsigned short StTriggerData2008::mtdTdc(StBeamDirection eastwest, int pmt, int prepost) const
944 {
945  static const int map[2][8] = {
946  {22,21,27,28,29,26,25,24},
947  {23,20,19,18,17,16,31,30}
948  };
949  if(pmt>=0 && pmt<8) { return mData->rawTriggerDet[prepostAddress(prepost)].MTD[map[eastwest][pmt]]; }
950  return 0;
951 }
952 
953 unsigned short StTriggerData2008::tofAtAddress(int address, int prepost) const
954 {
955  if (address>=0 && address<16){ return mData->rawTriggerDet[prepostAddress(prepost)].TOF[address]; }
956  return 0;
957 }
958 
959 unsigned short StTriggerData2008::tofMultiplicity(int prepost) const
960 {
961  return mData->rawTriggerDet[prepostAddress(prepost)].TOF[8];
962 }