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