StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTriggerData2004.cxx
1 /***************************************************************************
2  *
3  * $Id: StTriggerData2004.cxx,v 2.18 2015/05/20 16:57:00 ullrich Exp $
4  *
5  * Author: Akio Ogawa, Feb 2004
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StTriggerData2004.cxx,v $
13  * Revision 2.18 2015/05/20 16:57:00 ullrich
14  * Correct logic in if statement.
15  *
16  * Revision 2.17 2006/09/20 00:44:55 ullrich
17  * Modified method to return length of L2 results.
18  *
19  * Revision 2.16 2006/09/19 22:53:55 ullrich
20  * Added access method to L2 results.
21  *
22  * Revision 2.15 2006/09/13 23:59:55 ullrich
23  * Added new data member mRun. Removed arg run from ctb(), ctbTraySlat(), zdcSMD()
24  *
25  * Revision 2.14 2006/08/21 19:41:51 ullrich
26  * Add run number as argument to ctb(), ctbTray(), and zdcSMD(). Used 2005 only. (Akio)
27  *
28  * Revision 2.13 2006/02/08 16:29:46 ullrich
29  * Fixed bug in zdcUnAttenuated.
30  *
31  * Revision 2.12 2004/11/30 19:19:12 ullrich
32  * Added new access function for EEMC data (Akio).
33  *
34  * Revision 2.11 2004/11/16 15:58:23 ullrich
35  * Checks for valid pre/post samples added (Akio).
36  *
37  * Revision 2.10 2004/10/20 18:56:22 ullrich
38  * Add method getRawSize().
39  *
40  * Revision 2.9 2004/08/03 17:22:16 ullrich
41  * Major update by Akio and Marco.
42  *
43  * Revision 2.8 2004/07/20 18:02:26 jeromel
44  * Updates from Akio to fix CTB issues.
45  *
46  * Revision 2.7 2004/06/30 00:12:11 ullrich
47  * Added ZDC info to dump().
48  *
49  * Revision 2.6 2004/04/02 01:21:44 jeromel
50  * Proper mapping added (Akio/Aihong)
51  *
52  * Revision 2.5 2004/02/11 01:39:52 ullrich
53  * Use enumeration StBeamDirector for east/west. Add member for ZDC vertex.
54  *
55  * Revision 2.4 2004/01/28 00:31:56 ullrich
56  * Missing value in dsmmap initializer in zdcAtAddress() added.
57  *
58  * Revision 2.3 2004/01/28 00:29:49 ullrich
59  * Methods to retrieve ZDC data added.
60  *
61  * Revision 2.2 2004/01/13 21:00:21 fisyak
62  * remove default parameter set from implimentation, make icc happy
63  *
64  * Revision 2.1 2003/12/23 21:56:51 ullrich
65  * Initial Revision.
66  *
67  *
68  **************************************************************************/
69 #include <string.h>
70 #include <assert.h>
71 #include <iostream>
72 #include "StTriggerData2004.h"
73 #include "StDaqLib/TRG/trgStructures2004.h"
74 
75 ClassImp(StTriggerData2004)
76 
78 {
79  mYear=2004;
80  mData=0;
81 }
82 
83 StTriggerData2004::StTriggerData2004(const TrgDataType2004* data, int run)
84 {
85  mYear=2004;
86  mRun = run;
87  mData= new TrgDataType2004;
88  int npre = data->EvtDesc.npre;
89  int npost = data->EvtDesc.npost;
90  assert(npre >=0);
91  assert(npre <=5);
92  assert(npost>=0);
93  assert(npost<=5);
94  int size = sizeof(EvtDescData2004)+sizeof(TrgSumData2004)
95  + sizeof(RawTrgDet2004)*(npre+npost+1);
96 
97  memcpy(mData,data,size);
98  memset((char*)mData+size,0,sizeof(TrgDataType2004)-size);
99 }
100 
101 unsigned int StTriggerData2004::version() const
102 {
103  return mData->EvtDesc.TrgDataFmtVer;
104 }
105 
106 StTriggerData2004::~StTriggerData2004() {delete mData;}
107 
108 unsigned int StTriggerData2004::token() const
109 {
110  return mData->EvtDesc.TrgToken;
111 }
112 
113 unsigned int StTriggerData2004::triggerWord() const
114 {
115  return mData->EvtDesc.TriggerWord;
116 }
117 
118 unsigned int StTriggerData2004::actionWord() const
119 {
120  return
121  ( (unsigned short)(mData->EvtDesc.actionWdTrgCommand) * 16 * 16 * 16 ) +
122  ( (unsigned short)(mData->EvtDesc.actionWdDaqCommand) * 16 * 16 ) +
123  ( mData->EvtDesc.actionWdDetectorBitMask & 0x00ff ) ;
124 }
125 
126 unsigned int StTriggerData2004::numberOfPreXing() const
127 {
128  return mData->EvtDesc.npre;
129 }
130 
131 unsigned int StTriggerData2004::numberOfPostXing() const
132 {
133  return mData->EvtDesc.npost;
134 }
135 
136 unsigned short StTriggerData2004::busyStatus() const{
137  return mData->EvtDesc.modifiedBusyStatus;
138 }
139 
140 unsigned short StTriggerData2004::dsmInput() const{
141  return mData->EvtDesc.DSMInput;
142 }
143 
144 unsigned short StTriggerData2004::trgToken() const{
145  return mData->EvtDesc.TrgToken;
146 }
147 
148 unsigned short StTriggerData2004::dsmAddress() const{
149  return mData->EvtDesc.DSMAddress;
150 }
151 
152 unsigned short StTriggerData2004::mAddBits() const{
153  return mData->EvtDesc.addBits;
154 }
155 
156 unsigned short StTriggerData2004::bcData(int channel) const{
157  return mData->TrgSum.DSMdata.BCdata[channel];
158 }
159 
160 unsigned short StTriggerData2004::lastDSM(int channel) const{
161  return mData->TrgSum.DSMdata.lastDSM[channel];
162 }
163 
164 unsigned short StTriggerData2004::tcuBits() const
165 {
166  return mData->EvtDesc.DSMInput;
167 }
168 
169 unsigned int StTriggerData2004::bunchCounterHigh() const
170 {
171  return mData->EvtDesc.bunchXing_hi;
172 }
173 
174 unsigned int StTriggerData2004::bunchCounterLow() const
175 {
176  return mData->EvtDesc.bunchXing_lo;
177 }
178 
179 unsigned int StTriggerData2004::bunchId48Bit() const
180 {
181  unsigned long long bxinghi,bxing1,bxinglo, bx;
182  bxinghi = mData->TrgSum.DSMdata.BCdata[3];
183  bxing1 = mData->TrgSum.DSMdata.BCdata[10];
184  bxinglo = (bxing1 << 16) + mData->TrgSum.DSMdata.BCdata[11];
185  bx = (bxinghi << 32) + bxinglo;
186  return (int)(bx % 120);
187 }
188 
189 unsigned int StTriggerData2004::bunchId7Bit() const
190 {
191  int b7=0, b7dat;
192  b7dat = mData->TrgSum.DSMdata.BCdata[2];
193  b7 = b7dat & 0x7f;
194  return b7;
195 }
196 
197 unsigned int StTriggerData2004::spinBit() const
198 {
199  return (mData->TrgSum.DSMdata.lastDSM[7]/16)%256;
200 }
201 
202 unsigned int StTriggerData2004::spinBitYellowFilled() const
203 {
204  unsigned int sb = spinBit();
205  return sb%2;
206 }
207 
208 unsigned int StTriggerData2004::spinBitYellowUp() const
209 {
210  unsigned int sb = spinBit();
211  return (sb/2)%2;
212 }
213 
214 unsigned int StTriggerData2004::spinBitYellowDown() const
215 {
216  unsigned int sb = spinBit();
217  return (sb/4)%2;
218 }
219 
220 unsigned int StTriggerData2004::spinBitYellowUnpol() const
221 {
222  unsigned int sb = spinBit();
223  return (sb/8)%2;
224 }
225 
226 unsigned int StTriggerData2004::spinBitBlueFilled() const
227 {
228  unsigned int sb = spinBit();
229  return (sb/16)%2;
230 }
231 
232 unsigned int StTriggerData2004::spinBitBlueUp() const
233 {
234  unsigned int sb = spinBit();
235  return (sb/32)%2;
236 }
237 
238 unsigned int StTriggerData2004::spinBitBlueDown() const
239 {
240  unsigned int sb = spinBit();
241  return (sb/64)%2;
242 }
243 
244 unsigned int StTriggerData2004::spinBitBlueUnpol() const
245 {
246  unsigned int sb = spinBit();
247  return (sb/128)%2;
248 }
249 
250 unsigned short StTriggerData2004::ctbRaw(int address, int prepost) const
251 {
252  return mData->rawTriggerDet[prepostAddress(prepost)].CTB[address];
253 }
254 
255 unsigned short StTriggerData2004::ctb(int pmt, int prepost) const
256 {
257  static const unsigned char ctbMap[240] = {
258  7, 6, 5, 4, 3, 23, 22, 21, 20, 19,
259  2, 1, 0, 15, 14, 18, 17, 16, 31, 30,
260  13, 12, 11, 10, 9, 29, 28, 27, 26, 25,
261  39, 38, 37, 36, 35, 55, 54, 53, 52, 51,
262  34, 33, 32, 47, 46, 50, 49, 48, 63, 62,
263  45, 44, 43, 42, 41, 61, 60, 59, 58, 57,
264  71, 70, 69, 68, 67, 87, 86, 85, 84, 83,
265  66, 65, 64, 79, 78, 82, 81, 80, 95, 94,
266  77, 76, 75, 74, 73, 93, 92, 91, 90, 89,
267  103, 102, 101, 100, 99, 119, 118, 117, 116, 115,
268  98, 97, 96, 111, 110, 114, 113, 112, 127, 126,
269  109, 108, 107, 106, 105, 125, 124, 123, 122, 121,
270  135, 134, 133, 132, 131, 151, 150, 149, 148, 147,
271  130, 129, 128, 143, 142, 146, 145, 144, 159, 158,
272  141, 140, 139, 138, 137, 157, 156, 155, 154, 153,
273  167, 166, 165, 164, 163, 183, 182, 181, 180, 179,
274  162, 161, 160, 175, 174, 178, 177, 176, 191, 190,
275  173, 172, 171, 170, 169, 189, 188, 187, 186, 185,
276  199, 198, 197, 196, 195, 215, 214, 213, 212, 211,
277  194, 193, 192, 207, 206, 210, 209, 208, 223, 222,
278  205, 204, 203, 202, 201, 221, 220, 219, 218, 217,
279  231, 230, 229, 228, 227, 247, 246, 245, 244, 243,
280  226, 225, 224, 239, 238, 242, 241, 240, 255, 254,
281  237, 236, 235, 234, 233, 253, 252, 251, 250, 249,
282  } ;
283  return mData->rawTriggerDet[prepostAddress(prepost)].CTB[ctbMap[pmt]];
284 }
285 
286 unsigned short StTriggerData2004::ctbTraySlat(int tray, int slat, int prepost) const{
287  static const unsigned char ctbMap[2][120] = {
288  { 109, 108, 107, 106, 105, 7, 6, 5, 4, 3,
289  2, 1, 0, 15, 14, 13, 12, 11, 10, 9,
290  39, 38, 37, 36, 35, 34, 33, 32, 47, 46,
291  45, 44, 43, 42, 41, 71, 70, 69, 68, 67,
292  66, 65, 64, 79, 78, 77, 76, 75, 74, 73,
293  103, 102, 101, 100, 99, 98, 97, 96, 111, 110,
294  141, 140, 139, 138, 137, 167, 166, 165, 164, 163,
295  162, 161, 160, 175, 174, 173, 172, 171, 170, 169,
296  199, 198, 197, 196, 195, 194, 193, 192, 207, 206,
297  205, 204, 203, 202, 201, 231, 230, 229, 228, 227,
298  226, 225, 224, 239, 238, 237, 236, 235, 234, 233,
299  135, 134, 133, 132, 131, 130, 129, 128, 143, 142},
300  { 125, 124, 123, 122, 121, 23, 22, 21, 20, 19,
301  18, 17, 16, 31, 30, 29, 28, 27, 26, 25,
302  55, 54, 53, 52, 51, 50, 49, 48, 63, 62,
303  61, 60, 59, 58, 57, 87, 86, 85, 84, 83,
304  82, 81, 80, 95, 94, 93, 92, 91, 90, 89,
305  119, 118, 117, 116, 115, 114, 113, 112, 127, 126,
306  157, 156, 155, 154, 153, 183, 182, 181, 180, 179,
307  178, 177, 176, 191, 190, 189, 188, 187, 186, 185,
308  215, 214, 213, 212, 211, 210, 209, 208, 223, 222,
309  221, 220, 219, 218, 217, 247, 246, 245, 244, 243,
310  242, 241, 240, 255, 254, 253, 252, 251, 250, 249,
311  151, 150, 149, 148, 147, 146, 145, 144, 159, 158}
312  };
313  int add=prepostAddress(prepost);
314  if(add>=0) return mData->rawTriggerDet[prepostAddress(prepost)].CTB[ctbMap[slat][tray]];
315  else return 0;
316 }
317 
318 unsigned short StTriggerData2004::ctbSum(int prepost) const{
319  unsigned short sum=0;
320  for(int i=1; i<240; i++){sum+=ctb(i,prepost);}
321  return sum;
322 }
323 
324 unsigned short StTriggerData2004::mwc(int pmt, int prepost) const
325 {
326  static const unsigned char mwcMap[96] = {
327  71, 70, 69, 68, 67, 66, 65, 64, 79, 78, 77, 76,
328  95, 94, 93, 92, 87, 86, 85, 84, 83, 82, 81, 80,
329  99, 98, 97, 96, 111, 110, 109, 108, 103, 102, 101, 100,
330  119, 118, 117, 116, 115, 114, 113, 112, 127, 126, 125, 124,
331  7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12,
332  31, 30, 29, 28, 23, 22, 21, 20, 19, 18, 17, 16,
333  35, 34, 33, 32, 47, 46, 45, 44, 39, 38, 37, 36,
334  55, 54, 53, 52, 51, 50, 49, 48, 63, 62, 61, 60,
335  };
336  return mData->rawTriggerDet[prepostAddress(prepost)].MWC[mwcMap[pmt]];
337 }
338 
339 unsigned short StTriggerData2004::bbcADC(StBeamDirection eastwest, int pmt, int prepost) const
340 {
341  static const int q_map[2][24] = {
342  { 8 , 5 , 4 , 40 , 37 , 36 , 7 , 6 ,
343  3 , 2 , 1 , 39 , 38 , 35 , 34 , 33 ,
344  72 , 71 , 70 , 69 , 68 , 67 , 66 , 65 },
345  { 24 , 21 , 20 , 56 , 53 , 52 , 23 , 22 ,
346  19 , 18 , 17 , 55 , 54 , 51 , 50 , 49 ,
347  80 , 79 , 78 , 77 , 76 , 75 , 74 , 73 }
348  };
349  return mData->rawTriggerDet[prepostAddress(prepost)].BBC[q_map[eastwest][pmt-1]-1];
350 }
351 
352 unsigned short StTriggerData2004::bbcTDC(StBeamDirection eastwest, int pmt, int prepost) const
353 {
354  static const int t_map[2][16] ={
355  { 16 , 13 , 12 , 48 , 45 , 44 , 15 , 14 ,
356  11 , 10 , 9 , 47 , 46 , 43 , 42 , 41 },
357  { 32 , 29 , 28 , 64 , 61 , 60 , 31 , 30 ,
358  27 , 26 , 25 , 63 , 62 , 59 , 58 , 57 }
359  };
360  return mData->rawTriggerDet[prepostAddress(prepost)].BBC[t_map[eastwest][pmt-1]-1];
361 }
362 
363 unsigned short StTriggerData2004::bbcADCSum(StBeamDirection eastwest, int prepost) const
364 {
365  int address = prepostAddress(prepost);
366  if(eastwest==east){
367  return
368  mData->rawTriggerDet[address].BBClayer1[7]%2048+
369  mData->rawTriggerDet[address].BBClayer1[3]%2048;
370  }else{
371  return
372  mData->rawTriggerDet[address].BBClayer1[5]%2048+
373  mData->rawTriggerDet[address].BBClayer1[1]%2048;
374  }
375 }
376 
377 unsigned short StTriggerData2004::bbcADCSumLargeTile(StBeamDirection eastwest, int prepost) const
378 {
379  int address = prepostAddress(prepost);
380  if(eastwest==east) { return mData->rawTriggerDet[address].BBClayer1[11]%2048; }
381  else { return mData->rawTriggerDet[address].BBClayer1[10]%2048; }
382 }
383 
384 unsigned short StTriggerData2004::bbcEarliestTDC(StBeamDirection eastwest, int prepost) const
385 {
386  int address = prepostAddress(prepost), t1, t2;
387  if(eastwest==east){
388  t1 = mData->rawTriggerDet[address].BBClayer1[6]%256;
389  t2 = mData->rawTriggerDet[address].BBClayer1[2]%256;
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 StTriggerData2004::bbcTimeDifference() const
398 {
399  return mData->TrgSum.DSMdata.VTX[3]%512;
400 }
401 
402 unsigned short StTriggerData2004::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  { 71, 70, 87, 86, 96, 97, 48,
468  69, 68, 85, 84, 98, 99, 63,
469  67, 66, 83, 82, 100, 101, 62,
470  65, 64, 81, 80, 102, 103, 61,
471  79, 78, 90, 91, 106, 107, 60,
472  77, 76, 92, 93, 108, 109, 59,
473  75, 74, 94, 95, 110, 111, 58},
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  { 7, 6, 5, 4, 3, 2, 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 StTriggerData2004::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 StTriggerData2004::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 StTriggerData2004::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},{1,0,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 StTriggerData2004::fpdLayer2DSMRaw(int channel) const{
557  if(channel<8) return mData->TrgSum.DSMdata.FPD[channel];
558  return 0;
559 }
560 
561 unsigned short StTriggerData2004::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 StTriggerData2004::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 StTriggerData2004::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 StTriggerData2004::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 StTriggerData2004::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 StTriggerData2004::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 
606 unsigned short StTriggerData2004::zdcTDC(StBeamDirection eastwest, int prepost) const
607 {
608  if(eastwest==east) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[8];}
609  if(eastwest==west) {return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[9];}
610  return 0;
611 }
612 
613 unsigned short StTriggerData2004::zdcHardwareSum(int prepost) const
614 {
615  return mData->rawTriggerDet[prepostAddress(prepost)].ZDC[14];
616 }
617 
618 unsigned short StTriggerData2004::zdcSMD(StBeamDirection eastwest, int verthori, int strip, int prepost) const
619 {
620  static const int zdcsmd_map[2][2][8] ={
621  // wrong mapping
622  //{ { 6, 5, 4, 3, 2, 1, 0, 7} ,
623  // {15,14,13,12,11,10, 9, 8} } ,
624  //{ {22,21,20,19,18,17,16,23} ,
625  // {31,30,29,28,27,26,25,24} }
626  // correct mapping from Xzb
627  { { 7, 6, 5, 4, 3, 2, 1, 11} ,
628  { 0,15,14,13,12,8,10, 9} } ,
629  { {23,22,21,20,19,18,17,24} ,
630  {16,31,30,29,28,27,26,25} }
631  };
632  // if(eastwest<0 || eastwest>1) return 0;
633  if(verthori<0 || verthori>1) return 0;
634  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.
635  return mData->rawTriggerDet[prepostAddress(prepost)].ZDCSMD[zdcsmd_map[eastwest][verthori][strip-1]];
636 };
637 
638 unsigned short StTriggerData2004::bemcLayer1DSM(int channel, int prepost) const {
639  const int n_bemc_layer1=48;
640  if (channel<0 || channel >=n_bemc_layer1) {
641  gMessMgr->Warning() << "Barrel DSM layer 1 out of range (" << channel << ")" << endm;
642  return 0;
643  }
644  return mData->rawTriggerDet[prepostAddress(prepost)].BEMClayer1[channel];
645 }
646 
647 unsigned short StTriggerData2004::eemcLayer1DSM(int channel, int prepost) const {
648  const int n_eemc_layer1=48;
649  if (channel<0 || channel >=n_eemc_layer1) {
650  gMessMgr->Warning() << "Endap DSM layer 1 out of range (" << channel << ")" << endm;
651  return 0;
652  }
653  return mData->rawTriggerDet[prepostAddress(prepost)].EEMClayer1[channel];
654 }
655 
656 unsigned short StTriggerData2004::emcLayer2DSM(int channel) const {
657  const int n_emc_layer2=8;
658  if (channel<0 || channel >=n_emc_layer2) {
659  gMessMgr->Warning() << "EMC DSM layer 2 out of range (" << channel << ")" << endm;
660  return 0;
661  }
662  return mData->TrgSum.DSMdata.EMC[channel];
663 }
664 
665 unsigned char StTriggerData2004::bemcHighTower(int patch_id, int prepost) const
666 {
667  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
668  const int m_max_patch=300; // Full barrel
669 
670  if ( patch_id < 0 || patch_id >= m_max_patch) {
671  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
672  return 0;
673  }
674 
675  int dsm=patch_id/10;
676  int channel=patch_id%10;
677  unsigned short trg_word;
678  if (dsm>=15)
679  trg_word=decodeEmc12bit(dsm-15,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCEast);
680  else
681  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCWest);
682  return trg_word & 0x3F;
683 }
684 
685 unsigned char StTriggerData2004::bemcJetPatch (int patch_id, int prepost) const
686 {
687  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
688  const int m_max_patch=300; // Full barrel
689 
690  if ( patch_id < 0 || patch_id >= m_max_patch) {
691  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
692  return 0;
693  }
694 
695  int dsm=patch_id/10;
696  int channel=patch_id%10;
697  unsigned short trg_word;
698  if (dsm>=15)
699  trg_word=decodeEmc12bit(dsm-15,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCEast);
700  else
701  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].BEMCWest);
702  return trg_word >> 6;
703 }
704 
705 unsigned char StTriggerData2004::eemcHighTower(int patch_id, int prepost) const
706 {
707  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
708  const int m_max_patch=90;
709 
710  if ( patch_id < 0 || patch_id >= m_max_patch) {
711  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
712  return 0;
713  }
714 
715  int dsm=patch_id/10;
716  int channel=patch_id%10;
717  unsigned short trg_word;
718  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].EEMC);
719  return trg_word & 0x3F;
720 }
721 
722 unsigned char StTriggerData2004::eemcJetPatch (int patch_id, int prepost) const
723 {
724  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
725  const int m_max_patch=90;
726 
727  if ( patch_id < 0 || patch_id >= m_max_patch) {
728  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
729  return 0;
730  }
731 
732  int dsm=patch_id/10;
733  int channel=patch_id%10;
734  unsigned short trg_word;
735  trg_word=decodeEmc12bit(dsm,channel,mData->rawTriggerDet[prepostAddress(prepost)].EEMC);
736  return trg_word >> 6;
737 }
738 
739 unsigned char StTriggerData2004::bemcHighestTowerADC(int prepost) const
740 {
741  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
742  const int m_max_patch=300; // Full barrel
743  unsigned char h=0;
744  for(int i=1; i<m_max_patch; i++){
745  unsigned char hh=bemcHighTower(i,prepost);
746  if(h>hh) h=hh;
747  }
748  return h;
749 }
750 
751 unsigned char StTriggerData2004::eemcHighestTowerADC(int prepost) const
752 {
753  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
754  const int m_max_patch=90;
755  unsigned char h=0;
756  for(int i=1; i<m_max_patch; i++){
757  unsigned char hh=eemcHighTower(i,prepost);
758  if(h>hh) h=hh;
759  }
760  return h;
761 }
762 
763 void StTriggerData2004::dump() const
764 {
765  printf("***** StTriggerData Dump *****\n");
766  printf(" Year=%d Version=%x\n",year(),version());
767  printf(" %d pre and %d post crossing data available\n",numberOfPreXing(),numberOfPostXing());
768  printf(" Token=%d TriggerWord=%x ActionWord=%x BusyStatus=%x\n",
769  token(), triggerWord(), actionWord(), busyStatus());
770  printf(" TUC Bits=%d : ",tcuBits());
771  for(int i=0; i<16; i++) {printf(" %d",(tcuBits()>>(15-i))%2);}; printf("\n");
772  printf(" BunchId 7bit=%d 48bit=%d\n",bunchId7Bit(), bunchId48Bit());
773  printf(" Spin Bits=%d : ",spinBit());
774  for(int i=0; i<8; i++) {printf(" %d",(spinBit()>>(7-i))%2);}; printf("\n");
775  printf(" CTB ADC : "); for(int i=0; i<240;i++){ printf("%d ",ctb(i,0)); }; printf("\n");
776  printf(" MWC ADC : "); for(int i=0; i<96; i++){ printf("%d ",mwc(i,0)); }; printf("\n");
777  printf(" BBC East ADC : "); for(int i=1; i<=24;i++){ printf("%d ",bbcADC(east,i,0)); }; printf("\n");
778  printf(" BBC West ADC : "); for(int i=1; i<=24;i++){ printf("%d ",bbcADC(west,i,0)); }; printf("\n");
779  printf(" BBC East TAC : "); for(int i=1; i<=16;i++){ printf("%d ",bbcTDC(east,i,0)); }; printf("\n");
780  printf(" BBC West TAC : "); for(int i=1; i<=16;i++){ printf("%d ",bbcTDC(west,i,0)); }; printf("\n");
781  for(int i=-numberOfPreXing(); i<=static_cast<int>(numberOfPostXing()); i++){
782  printf(" BBC Sums %d xing : ",i);
783  printf("East=%d West=%d Large tile East=%d West=%d\n",
784  bbcADCSum(east,i),bbcADCSum(west,i),
785  bbcADCSumLargeTile(east,i),bbcADCSumLargeTile(west,i));
786  }
787  printf(" BBC Earilest : "); printf("East=%d West=%d Difference+256=%d\n",
788  bbcEarliestTDC(east,0),bbcEarliestTDC(west,0),bbcTimeDifference());
789  printf(" FPD East North : ");for(int i=1; i<=49;i++){ printf("%d ",fpd(east,0,i,0)); }; printf("\n");
790  printf(" FPD East South : ");for(int i=1; i<=49;i++){ printf("%d ",fpd(east,1,i,0)); }; printf("\n");
791  printf(" FPD East Top : ");for(int i=1; i<=25;i++){ printf("%d ",fpd(east,2,i,0)); }; printf("\n");
792  printf(" FPD East Bottom : ");for(int i=1; i<=25;i++){ printf("%d ",fpd(east,3,i,0)); }; printf("\n");
793  printf(" FPD East North PS: ");for(int i=1; i<= 7;i++){ printf("%d ",fpd(east,4,i,0)); }; printf("\n");
794  printf(" FPD East South PS: ");for(int i=1; i<= 7;i++){ printf("%d ",fpd(east,5,i,0)); }; printf("\n");
795  printf(" FPD West South : ");for(int i=1; i<=49;i++){ printf("%d ",fpd(west,1,i,0)); }; printf("\n");
796  printf(" FPD West Bottom : ");for(int i=1; i<=25;i++){ printf("%d ",fpd(west,3,i,0)); }; printf("\n");
797  printf(" FPD West South PS: ");for(int i=1; i<= 7;i++){ printf("%d ",fpd(west,5,i,0)); }; printf("\n");
798  printf(" FPD Sums East : ");for(int j=0; j<4 ;j++) printf("%d ",fpdSum(east,j)); printf("\n");
799  printf(" FPD Sums West : ");for(int j=0; j<4 ;j++) printf("%d ",fpdSum(west,j)); printf("\n");
800  printf(" ZDC Sum(A) East : ");printf("%d ",zdcAttenuated(east)); printf("\n");
801  printf(" ZDC Sum(A) West : ");printf("%d ",zdcAttenuated(west)); printf("\n");
802  printf(" ZDC Sum(UA) East : ");printf("%d ",zdcUnAttenuated(east)); printf("\n");
803  printf(" ZDC Sum(UA) West : ");printf("%d ",zdcUnAttenuated(west)); printf("\n");
804  printf("\n");
805  printf("***** StTriggerData Dump *****\n");
806 }
807 
808 char* StTriggerData2004::getTriggerStructure()
809 {
810  return (char*) mData;
811 }
812 
813 TrgDataType2004* StTriggerData2004::getTriggerStructure2004()
814 {
815  return mData;
816 }
817 
818 int StTriggerData2004::getRawSize() const
819 {
820  int npre = numberOfPreXing();
821  int npost = numberOfPostXing();
822  int rawSize=sizeof(EvtDescData2004)+sizeof(TrgSumData2004)
823  + sizeof(RawTrgDet2004)*(npre+npost+1);
824  return rawSize;
825 }
826 
827 unsigned char * StTriggerData2004::getDsm0_EEMC(int prepost) const
828 {
829  return mData->rawTriggerDet[prepostAddress(prepost)].EEMC;
830 }
831 
832 unsigned short int * StTriggerData2004::getDsm1_EEMC(int prepost) const
833 {
834  return mData->rawTriggerDet[prepostAddress(prepost)].EEMClayer1;
835 }
836 
837 unsigned short int * StTriggerData2004::getDsm2_EMC() const
838 {
839  return mData->TrgSum.DSMdata.EMC;
840 }
841 
842 unsigned short int * StTriggerData2004::getDsm3() const
843 {
844  return mData->TrgSum.DSMdata.lastDSM;
845 }
846 
847 unsigned int StTriggerData2004::l2ResultLength() const
848 {
849  return sizeof(mData->TrgSum.L2Result)/sizeof(unsigned int);
850 }
851 
852 const unsigned int* StTriggerData2004::l2Result() const
853 {
854  return mData->TrgSum.L2Result;
855 }