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