StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StL0Trigger.cxx
1 /***************************************************************************
2  *
3  * $Id: StL0Trigger.cxx,v 2.12 2006/07/18 14:41:01 ullrich Exp $
4  *
5  * Author: Thomas Ullrich, Sep 1999
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StL0Trigger.cxx,v $
13  * Revision 2.12 2006/07/18 14:41:01 ullrich
14  * Removed 'else if (runNumber < 7000000)'. Originally John Nelson
15  * suggested to replace 7000000 by 8000000 but Akio said that
16  * converting the else if to an else is better for now.
17  *
18  * Revision 2.11 2005/10/10 19:24:38 ullrich
19  * run number range check, and updated for run5.
20  *
21  * Revision 2.10 2004/08/03 17:22:16 ullrich
22  * Major update by Akio and Marco.
23  *
24  * Revision 2.9 2003/07/29 19:50:53 ullrich
25  * Fix for spin bits added.
26  *
27  * Revision 2.8 2003/04/30 20:59:23 ullrich
28  * Modified bunchCrossingId7bit() to deal with run
29  * numbers > 4000000. Code from Eleanor.
30  *
31  * Revision 2.7 2002/11/26 02:19:11 perev
32  * StEventMaker ITTF modif
33  *
34  * Revision 2.6 2002/02/15 00:18:13 ullrich
35  * Changed signature of bunchCrossingId7bit().
36  *
37  * Revision 2.5 2002/01/09 15:37:12 ullrich
38  * Bunch crossing id and spin bit extraction functions added.
39  *
40  * Revision 2.4 2001/07/19 00:04:06 ullrich
41  * Updated to handle new trigger info.
42  *
43  * Revision 2.3 2001/04/05 04:00:51 ullrich
44  * Replaced all (U)Long_t by (U)Int_t and all redundant ROOT typedefs.
45  *
46  * Revision 2.2 1999/12/21 15:08:59 ullrich
47  * Modified to cope with new compiler version on Sun (CC5.0).
48  *
49  * Revision 2.1 1999/10/28 22:25:59 ullrich
50  * Adapted new StArray version. First version to compile on Linux and Sun.
51  *
52  * Revision 2.0 1999/10/12 18:42:24 ullrich
53  * Completely Revised for New Version
54  *
55  **************************************************************************/
56 #include <algorithm>
57 #include "StL0Trigger.h"
58 #include "StTriggerData.h"
59 #include "tables/St_dst_L0_Trigger_Table.h"
60 #include "tables/St_dst_TrgDet_Table.h"
61 
62 #if !defined(ST_NO_NAMESPACES)
63 using std::fill_n;
64 using std::copy;
65 #endif
66 
67 static const char rcsid[] = "$Id: StL0Trigger.cxx,v 2.12 2006/07/18 14:41:01 ullrich Exp $";
68 
69 ClassImp(StL0Trigger)
70 
72 {
73  mMwcCtbMultiplicity = 0;
74  mMwcCtbDipole = 0;
75  mMwcCtbTopology = 0;
76  mMwcCtbMoment = 0;
77  fill_n(mCoarsePixelArray, static_cast<int>(mMaxPixels), 0);
78  mDsmInput = 0;
79  mDetectorBusy = 0;
80  mTriggerToken = 0;
81  mDsmAddress = 0;
82  mAddBits = 0;
83  fill_n(mLastDsmArray, static_cast<unsigned short>(mMaxLastDsm), 0);
84  fill_n(mBcDataArray, static_cast<unsigned short>(mMaxBcData), 0);
85 }
86 
87 void StL0Trigger::set(const dst_L0_Trigger_st *t)
88 {
89  if (!t) return;
90  if (TestBit(1)) return;
91  SetBit(1);
92  mTriggerWord = t->TriggerWd;
93  mTriggerActionWord = t->TriggerActionWd;
94  mMwcCtbMultiplicity = t->MWC_CTB_mul;
95  mMwcCtbDipole = t->MWC_CTB_dipole;
96  mMwcCtbTopology = t->MWC_CTB_topology;
97  mMwcCtbMoment = t->MWC_CTB_moment;
98  copy(t->CPA+0, t->CPA+mMaxPixels, mCoarsePixelArray);
99  mDsmInput = t->DSMInput;
100  mDetectorBusy = t->DetectorBusy;
101  mTriggerToken = t->TrgToken;
102  mDsmAddress = t->DSMAddress;
103  mAddBits = t->addBits;
104 }
105 
106 void StL0Trigger::set(const dst_TrgDet_st* n)
107 {
108  // from dst_TrgDet_st
109  if (!n) return;
110  if (TestBit(2)) return;
111  SetBit(2);
112  copy(n->lastDSM+0, n->lastDSM+mMaxLastDsm, mLastDsmArray);
113  copy(n->BCdata +0, n->BCdata+mMaxBcData , mBcDataArray );
114 }
115 
116 void StL0Trigger::set(const StTriggerData* t)
117 {
118  // from StTriggerData
119  if(t){
120  SetBit(2);
121  mTriggerWord = t->triggerWord();
122  mTriggerActionWord = t->actionWord();
123  mMwcCtbMultiplicity=0;
124  mMwcCtbDipole=0;
125  mMwcCtbTopology=0;
126  mMwcCtbMoment=0;
127  mDsmInput=t->dsmInput();
128  mDetectorBusy=0;
129  mTriggerToken=t->trgToken();
130  mDsmAddress=t->dsmAddress();
131  mAddBits = t->mAddBits();
132  for(int i=0; i<mMaxLastDsm; i++){mLastDsmArray[i]=t->lastDSM(i);}
133  for(int i=0; i<mMaxBcData; i++){mBcDataArray[i]=t->bcData(i);}
134  }
135 }
136 
137 StL0Trigger::~StL0Trigger() { /* noop */ }
138 
139 unsigned int
140 StL0Trigger::coarsePixelArraySize() {return mMaxPixels;}
141 
142 int
143 StL0Trigger::coarsePixelArray(unsigned int i)
144 {
145  if (i < mMaxPixels)
146  return mCoarsePixelArray[i];
147  else
148  return 0;
149 }
150 
151 unsigned int
152 StL0Trigger::lastDsmArraySize() const {return mMaxLastDsm;}
153 
154 unsigned short
155 StL0Trigger::lastDsmArray(unsigned int i)
156 {
157  if (i < mMaxLastDsm)
158  return mLastDsmArray[i];
159  else
160  return 0;
161 }
162 
163 unsigned int
164 StL0Trigger::bcDataArraySize() const {return mMaxBcData;}
165 
166 unsigned short
167 StL0Trigger::bcDataArray(unsigned int i)
168 {
169  if (i < mMaxBcData)
170  return mBcDataArray[i];
171  else
172  return 0;
173 }
174 
175 int
176 StL0Trigger::mwcCtbMultiplicity() const { return mMwcCtbMultiplicity;}
177 
178 int
179 StL0Trigger::mwcCtbDipole() const { return mMwcCtbDipole;}
180 
181 int
182 StL0Trigger::mwcCtbTopology() const { return mMwcCtbTopology;}
183 
184 int
185 StL0Trigger::mwcCtbMoment() const { return mMwcCtbMoment;}
186 
187 unsigned short
188 StL0Trigger::dsmInput() const {return mDsmInput;}
189 
190 unsigned char
191 StL0Trigger::detectorBusy() const {return mDetectorBusy;}
192 
193 unsigned short
194 StL0Trigger::triggerToken() const {return mTriggerToken;}
195 
196 unsigned short
197 StL0Trigger::dsmAddress() const {return mDsmAddress;}
198 
199 unsigned char
200 StL0Trigger::addBits() const {return mAddBits;}
201 
202 void
203 StL0Trigger::setMwcCtbMultiplicity(int val) { mMwcCtbMultiplicity = val; }
204 
205 void
206 StL0Trigger::setMwcCtbDipole(int val) { mMwcCtbDipole = val; }
207 
208 void
209 StL0Trigger::setMwcCtbTopology(int val) { mMwcCtbTopology = val; }
210 
211 void
212 StL0Trigger::setMwcCtbMoment(int val) { mMwcCtbMoment = val; }
213 
214 void
215 StL0Trigger::setCoarsePixelArray(unsigned int i, int val)
216 {
217  if (i < mMaxPixels)
218  mCoarsePixelArray[i] = val;
219 }
220 
221 void
222 StL0Trigger::setDsmInput(unsigned short val) {mDsmInput = val;}
223 
224 void
225 StL0Trigger::setDetectorBusy(unsigned char val) {mDetectorBusy = val;}
226 
227 void
228 StL0Trigger::setTriggerToken(unsigned short val) {mTriggerToken = val;}
229 
230 void
231 StL0Trigger::setDsmAddress(unsigned short val) {mDsmAddress = val;}
232 
233 void
234 StL0Trigger::setAddBits(unsigned char val) {mAddBits = val;}
235 
236 
237 void
238 StL0Trigger::setLastDsmArray(unsigned int i, unsigned short val)
239 {
240  if (i < mMaxLastDsm)
241  mLastDsmArray[i] = val;
242 }
243 
244 void
245 StL0Trigger::setBcDataArray(unsigned int i, unsigned short val)
246 {
247  if (i < mMaxBcData)
248  mBcDataArray[i] = val;
249 }
250 
251 unsigned int
252 StL0Trigger::bunchCrossingId7bit(int runNumber) const
253 {
254  unsigned int b7dat = mBcDataArray[2];
255  //
256  // This code was added after discussions with
257  // Akio, Jamie, and Eleanor. According to
258  // Eleanor it's just the the 7 least significant
259  // bits in mBcDataArray[2]. Jamie tested it and
260  // says it works.
261  // April 30, 2003 (tu)
262  //
263  if (runNumber>4000000)
264  return b7dat & 0x7f;
265 
266  //
267  // This code is the original version from Hank and
268  // since it appears to work (Akio) I leave it as is.
269  // April 30, 2003 (tu)
270  //
271  int b7=0, ibits;
272  if(runNumber<3010000) { ibits=7; } /* before run 3010* this should be 7 */
273  else { ibits=6; }
274 
275  for (int i=0; i<7; i++) {
276  b7 += (!((b7dat>>(ibits-i)) & 0x1) << (i)) & 0x7f;
277  }
278  return b7;
279 }
280 
281 unsigned int
282 StL0Trigger::bunchCrossingId() const
283 {
284  unsigned long long bxinghi,bxing1,bxinglo,bxing,bx0,bx1,bx2;
285  int b120;
286  bxinghi = mBcDataArray[3];
287  bxing1 = mBcDataArray[10];
288  bxinglo = (bxing1 << 16) + mBcDataArray[11];
289  bxing = (bxinghi << 32) + bxinglo;
290  bx0 = bxing;
291  bx1 = bx0/120;
292  bx2 = bx1 * 120;
293  b120 = bx0 - bx2;
294  return static_cast<unsigned int>(b120);
295 }
296 
297 int
298 StL0Trigger::spinBits(int runNumber) const
299 {
300  int ldsm0,spin1,spin2,spin3,spin4;
301  if (runNumber<4000000){
302  ldsm0 = mLastDsmArray[0];
303  spin1 = (ldsm0>>8) & 0x1;
304  spin2 = (ldsm0>>9) & 0x1;
305  spin3 = (ldsm0>>10) & 0x1;
306  spin4 = (ldsm0>>11) & 0x1;
307  return spin1+spin2*2+spin3*4+spin4*8;
308  }
309  else {
310  ldsm0 = (mLastDsmArray[7]/16)%256;
311  spin1 = (ldsm0/ 2)%2;
312  spin2 = (ldsm0/ 4)%2;
313  spin3 = (ldsm0/32)%2;
314  spin4 = (ldsm0/64)%2;
315  return spin1+spin2*2+spin3*4+spin4*8;
316  }
317 }
318 
319 int
320 StL0Trigger::spinBitYellowUp(int runNumber) const
321 {
322  if (runNumber<4000000){
323  return (mLastDsmArray[0]>>8) & 0x1;
324  }
325  else {
326  int ldsm0 = (mLastDsmArray[7]/16)%256;
327  return (ldsm0/2)%2;
328  }
329 }
330 
331 int
332 StL0Trigger::spinBitYellowDown(int runNumber) const
333 {
334  if (runNumber<4000000){
335  return (mLastDsmArray[0]>>9) & 0x1;
336  }
337  else {
338  int ldsm0 = (mLastDsmArray[7]/16)%256;
339  return (ldsm0/ 4)%2;
340  }
341 }
342 
343 int
344 StL0Trigger::spinBitBlueUp(int runNumber) const
345 {
346  if (runNumber<4000000){
347  return (mLastDsmArray[0]>>9) & 0x1;
348  }
349  else {
350  int ldsm0 = (mLastDsmArray[7]/16)%256;
351  return (ldsm0/32)%2;
352  }
353 }
354 
355 int
356 StL0Trigger::spinBitBlueDown(int runNumber) const
357 {
358  if (runNumber<4000000){
359  return (mLastDsmArray[0]>>10) & 0x1;
360  }
361  else {
362  int ldsm0 = (mLastDsmArray[7]/16)%256;
363  return (ldsm0/64)%2;
364  }
365 }