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