StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBbcTriggerDetector.cxx
1 /***************************************************************************
2  *
3  * $Id: StBbcTriggerDetector.cxx,v 2.14 2009/11/23 16:34:05 fisyak Exp $
4  *
5  * Author: Akio Ogawa, Jan 2002
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StBbcTriggerDetector.cxx,v $
13  * Revision 2.14 2009/11/23 16:34:05 fisyak
14  * Cleanup, remove dependence on dst tables, clean up software monitors
15  *
16  * Revision 2.13 2009/02/03 15:52:12 fisyak
17  * Add include
18  *
19  * Revision 2.12 2008/08/15 17:33:04 ullrich
20  * Modified zVertex(). Implemented calibrated BBC vertex z position code.
21  *
22  * Revision 2.11 2007/10/11 21:39:56 ullrich
23  * Removed unused variable i.
24  *
25  * Revision 2.10 2007/07/11 23:06:45 perev
26  * Cleanup+fix StXXXTriggerDetector
27  *
28  * Revision 2.9 2007/04/24 14:52:23 ullrich
29  * Fixed bug in BBC unpacking (Akio).
30  *
31  * Revision 2.8 2004/11/02 21:20:20 ullrich
32  * Modifications by Akio for Run 5.
33  *
34  * Revision 2.7 2004/08/03 17:22:15 ullrich
35  * Major update by Akio and Marco.
36  *
37  * Revision 2.6 2004/02/11 01:42:09 ullrich
38  * Added new constructor to load data from StTriggerData.
39  *
40  * Revision 2.5 2003/09/02 17:58:05 perev
41  * gcc 3.2 updates + WarnOff
42  *
43  * Revision 2.4 2003/02/05 23:17:34 ullrich
44  * Corrected bug in adcSumWest(). Index needed offset.
45  *
46  * Revision 2.3 2003/01/23 23:23:28 ullrich
47  * Modified to cope with changes in how BBC data is loaded for Run3.
48  *
49  * Revision 2.2 2002/09/25 14:04:17 akio
50  * Bug fix in the service functions, no change in data
51  *
52  * Revision 2.1 2002/01/03 20:57:37 ullrich
53  * Initial Revision.
54  *
55  **************************************************************************/
56 #include <math.h>
57 #include "StBbcTriggerDetector.h"
58 #include "Stiostream.h"
59 #include "tables/St_dst_TrgDet_Table.h"
60 #include "StTriggerData.h"
61 #include "TMath.h"
62 static const char rcsid[] = "$Id: StBbcTriggerDetector.cxx,v 2.14 2009/11/23 16:34:05 fisyak Exp $";
63 
64 ClassImp(StBbcTriggerDetector)
65 
67 {
68  memset(mBeg,0,mEnd-mBeg);
69  mYear=2002;
70  mDSMVTX=0;
71 }
72 
73 StBbcTriggerDetector::StBbcTriggerDetector(const dst_TrgDet_st& t)
74 {
75  int east_q_map[24] = { 8 , 5 , 4 , 40 , 37 , 36 , 7 , 6 ,
76  3 , 2 , 1 , 39 , 38 , 35 , 34 , 33 ,
77  72 , 71 , 70 , 69 , 68 , 67 , 66 , 65 };
78  int east_t_map[16] = { 16 , 13 , 12 , 48 , 45 , 44 , 15 , 14 ,
79  11 , 10 , 9 , 47 , 46 , 43 , 42 , 41 };
80  int west_q_map[24] = { 24 , 21 , 20 , 56 , 53 , 52 , 23 , 22 ,
81  19 , 18 , 17 , 55 , 54 , 51 , 50 , 49 ,
82  80 , 79 , 78 , 77 , 76 , 75 , 74 , 73 };
83  int west_t_map[16] = { 32 , 29 , 28 , 64 , 61 , 60 , 31 , 30 ,
84  27 , 26 , 25 , 63 , 62 , 59 , 58 , 57 };
85 
86  memset(mBeg,0,mEnd-mBeg);
87  int i;
88  mYear=2003;
89  for (i=0; i<24; i++){
90  mAdc[i ] = (unsigned short) t.BBC[east_q_map[i]-1];
91  mAdc[i+24] = (unsigned short) t.BBC[west_q_map[i]-1];
92  }
93  for (i=0; i<16; i++){
94  mTdc[i ] = (unsigned short) t.BBC[east_t_map[i]-1];
95  mTdc[i+24] = (unsigned short) t.BBC[west_t_map[i]-1];
96  }
97  mDSMVTX = 0;
98 }
99 
100 StBbcTriggerDetector::StBbcTriggerDetector(const StTriggerData& t)
101 {
102  //
103  // This is a temporary fix only. In future this
104  // class will become obsolete and users should
105  // get this info from StTriggerData.
106  // This info is only a subset of what is available
107  // in StTriggerData.
108  // tu 2/10/2004
109  //
110  memset(mBeg,0,mEnd-mBeg);
111  int i,maxt;
112  mYear = t.year();
113  if (mYear<2005)
114  maxt=16;
115  else
116  maxt=24;
117 
118  for (i=0; i<24; i++){
119  mAdc[i ] = (unsigned short) t.bbcADC(east, i+1);
120  mAdc[i+24] = (unsigned short) t.bbcADC(west, i+1);
121  }
122  for (i=0; i<maxt; i++){
123  mTdc[i ] = (unsigned short) t.bbcTDC(east, i+1);
124  mTdc[i+24] = (unsigned short) t.bbcTDC(west, i+1);
125  }
126  mDSMVTX=t.bbcTimeDifference();
127 }
128 
129 StBbcTriggerDetector::~StBbcTriggerDetector() {/* noop */}
130 
131 unsigned short
132 StBbcTriggerDetector::adc(unsigned int pmt) const
133 {
134  if (pmt < mMaxPMTs)
135  return mAdc[pmt];
136  else
137  return 9999;
138 }
139 
140 unsigned short
141 StBbcTriggerDetector::tdc(unsigned int pmt) const
142 {
143  if (pmt < mMaxPMTs)
144  return mTdc[pmt];
145  else
146  return 9999;
147 }
148 
149 unsigned short
150 StBbcTriggerDetector::bbcRegister(unsigned int n) const
151 {
152  if (n < mMaxRegisters)
153  return mReg[n];
154  else
155  return 9999;
156 }
157 
158 unsigned short
159 StBbcTriggerDetector::pedestalData(unsigned int n) const
160 {
161  if (n < mMaxPedData)
162  return mPed[n];
163  else
164  return 9999;
165 }
166 
167 unsigned int
168 StBbcTriggerDetector::scalar(unsigned int n) const
169 {
170  if (n < mMaxScalars)
171  return mScl[n];
172  else
173  return 0;
174 }
175 
176 void
177 StBbcTriggerDetector::setAdc(unsigned int pmt, unsigned short val)
178 {
179  if (pmt < mMaxPMTs) mAdc[pmt] = val;
180 }
181 
182 void
183 StBbcTriggerDetector::setTdc(unsigned int pmt, unsigned short val)
184 {
185  if (pmt < mMaxPMTs) mTdc[pmt] = val;
186 }
187 
188 void
189 StBbcTriggerDetector::setRegister(unsigned int id, unsigned short val)
190 {
191  if (id < mMaxRegisters) mReg[id] = val;
192 }
193 
194 void
195 StBbcTriggerDetector::setPedestal(unsigned int id, unsigned short val)
196 {
197  if (id < mMaxPedData) mPed[id] = val;
198 }
199 
200 void
201 StBbcTriggerDetector::setScalar(unsigned int id, unsigned int val)
202 {
203  if (id < mMaxScalars) mScl[id] = val;
204 }
205 
206 int
207 StBbcTriggerDetector::nHitEast()
208 {
209  int nhit=0;
210  if (mYear==2002) {
211  for (int i=0; i<8; i++) {if (tdc(i)>0 && tdc(i)<1500) {nhit++;}}
212  }
213  else if (mYear==2003) {
214  for (int i=0; i<16; i++) {if (adc(i)>5) {nhit++;}}
215  }
216  else {
217  cerr << "StBbcTriggerDetector::nHitEast: No longer supported after 2003. Do not use!" << endl;
218  }
219  return nhit;
220 }
221 
222 int
223 StBbcTriggerDetector::nHitWest()
224 {
225  int nhit=0;
226  if (mYear==2002) {
227  for (int i=0; i<8; i++) {if (tdc(i+16)>0 && tdc(i+16)<1500) {nhit++;}}
228  }
229  else if (mYear==2003) {
230  for (int i=0; i<16; i++) {if (adc(i+24)>5) {nhit++;}}
231  }
232  else{
233  cerr << "StBbcTriggerDetector::nHitWest: No longer supported after 2003. Do not use!" << endl;
234  }
235  return nhit;
236 }
237 
238 int
239 StBbcTriggerDetector::nHitEastLarge()
240 {
241  int nhit=0;
242  if (mYear==2002) {
243  for (int i=8; i<15; i++) {if (tdc(i)>0 && tdc(i)<1500) {nhit++;}} //exclude 15 = clock
244  }
245  else if (mYear==2003) {
246  for (int i=16; i<24; i++) {if (adc(i)>5) {nhit++;}}
247  }
248  else{
249  cerr << "StBbcTriggerDetector::nHitEastlarge: No longer supported after 2003. Do not use!" << endl;
250  }
251  return nhit;
252 }
253 
254 int
255 StBbcTriggerDetector::nHitWestLarge()
256 {
257  int nhit=0;
258  if (mYear==2002) {
259  for (int i=8; i<15; i++) {if (tdc(i+16)>0 && tdc(i+16)<1500) {nhit++;}} //exclude 15 = clock
260  }
261  else if (mYear==2003) {
262  for (int i=16; i<24; i++) {if (adc(i+24)>5) {nhit++;}}
263  }
264  else {
265  cerr << "StBbcTriggerDetector::nHitWestLarge: No longer supported after 2003. Do not use!" << endl;
266  }
267  return nhit;
268 }
269 
270 int
271 StBbcTriggerDetector::nHit() {return nHitEast()+nHitWest();}
272 
273 int
274 StBbcTriggerDetector::nHitLarge() {return nHitEastLarge()+nHitWestLarge();}
275 
276 int
277 StBbcTriggerDetector::nHitAll() {return nHit()+nHitLarge();}
278 
279 int
280 StBbcTriggerDetector::adcSumEast()
281 {
282  int sum=0;
283  if (mYear==2002) {
284  for (int i=0; i<8; i++){sum+=adc(i);}
285  }
286  else if (mYear>=2003) {
287  for (int i=0; i<16; i++){sum+=adc(i);}
288  }
289  return sum;
290 }
291 
292 int
293 StBbcTriggerDetector::adcSumWest()
294 {
295  int sum=0;
296  if (mYear==2002) {
297  for (int i=0; i<8; i++){sum+=adc(i+16);}
298  }
299  else if (mYear>=2003) {
300  for (int i=0; i<16; i++){sum+=adc(i+24);}
301  }
302  return sum;
303 }
304 
305 int
306 StBbcTriggerDetector::adcSumEastLarge()
307 {
308  int sum=0;
309  if (mYear==2002) {
310  for (int i=8; i<15; i++){sum+=adc(i);} //exclude 15 = clock
311  }
312  else if (mYear>=2003) {
313  for (int i=16; i<24; i++){sum+=adc(i);}
314  }
315  return sum;
316 }
317 
318 int
319 StBbcTriggerDetector::adcSumWestLarge()
320 {
321  int sum=0;
322  if (mYear==2002) {
323  for (int i=8; i<15; i++){sum+=adc(i);} //exclude 15 = clock
324  }
325  else if (mYear>=2003) {
326  for (int i=16; i<24; i++){sum+=adc(i+24);}
327  }
328  return sum;
329 }
330 
331 int
332 StBbcTriggerDetector::adcSum(){return adcSumEast()+adcSumWest();}
333 
334 int
335 StBbcTriggerDetector::adcSumLarge(){return adcSumEastLarge()+adcSumWestLarge();}
336 
337 int
338 StBbcTriggerDetector::adcSumAll() {return adcSum()+adcSumLarge();}
339 
340 int
341 StBbcTriggerDetector::tdcEarliestEast()
342 {
343  if (mYear==2002){
344  unsigned short earliest=2000;
345  for (int i=0; i<8; i++){
346  if (tdc(i)>0 && tdc(i)<earliest ) earliest=tdc(i);
347  }
348  if (earliest<2000)
349  return earliest;
350  else
351  return -9999;
352  }
353  else if (mYear==2003){
354  unsigned short earliest=0;
355  for (int i=0; i<16; i++){
356  if (tdc(i)<245 && tdc(i)>earliest && adc(i)>5 ) earliest=tdc(i);
357  }
358  if (earliest>0)
359  return earliest;
360  else
361  return -9999;
362  }
363  else{
364  cerr << "StBbcTriggerDetector::tdcEarliestEast: No longer supported after 2003. Do not use!" << endl;
365  }
366  return -9999;
367 }
368 
369 int
370 StBbcTriggerDetector::tdcEarliestWest()
371 {
372  if (mYear==2002){
373  unsigned short earliest=2000;
374  for (int i=16; i<24; i++){
375  if (tdc(i)>0 && tdc(i)<earliest ) earliest=tdc(i);
376  }
377  if (earliest<2000)
378  return earliest;
379  else
380  return -8888;
381  }
382  else if (mYear==2003){
383  unsigned short earliest=0;
384  for (int i=24; i<40; i++){
385  if (tdc(i)<245 && tdc(i)>earliest && adc(i)>5 ) earliest=tdc(i);
386  }
387  if (earliest>0)
388  return earliest;
389  else
390  return -8888;
391  }
392  else{
393  cerr << "StBbcTriggerDetector::tdcEarliestWest: No longer supported after 2003. Do not use!" << endl;
394  }
395  return -8888;
396 }
397 
398 float
399 StBbcTriggerDetector::zVertex()
400 {
401  if (mYear==2002){
402  unsigned short east=tdcEarliestEast();
403  unsigned short west=tdcEarliestWest();
404  if (east<2000 && west<2000 && east!=0 && west!=0)
405  return (float(east-west))*5.0; //sign for common start
406  else
407  return -9999.0;
408  }
409  else if (mYear==2003){
410  unsigned short east=tdcEarliestEast();
411  unsigned short west=tdcEarliestWest();
412  if (east>0 && west>0)
413  return float(west-east)*3.0; //sign for common stop
414  else
415  return -9999.0;
416  }
417  else{
418  float slope=2.0;
419  float tc[4]={49.89, -3.155, 4.537, -0.1471};
420  float off=-13.77l;
421  float offset[2][16] = {
422  {-2.00982, 4.09827, 4.83372, -4.71373,
423  -8.33428, -8.51657, -2.16193, 14.6726,
424  1.61522, 0.605228, 4.98944, -1.86768,
425  -2.46653, -2.70569, -4.33065, -5.07069},
426  {-4.90599, -2.62884, -2.87498, 5.58336,
427  0.100682, 0.065195, -0.35114, -2.96953,
428  1.2031, 2.94575, -1.93577, -1.13641,
429  1.86768, 4.27345, 7.0431, -1.16071}
430  };
431  float maxtac[2]={0.0, 0.0};
432  for(int iew=0; iew<2; iew++){
433  for(int ich=0; ich<16; ich++){
434  int j=iew*24+ich;
435  float tac = tdc(j) - offset[iew][ich] - (tc[0]+tc[1]/TMath::Exp(-tc[2]*TMath::Power(adc(j),tc[3])))/slope;
436  if(adc(j)>10 && tac<200 && tac>maxtac[iew]) {maxtac[iew]=tac;}
437  }
438  }
439  if(maxtac[0]>0.0 && maxtac[1]>0.0){
440  float zvt=slope*(maxtac[1]-maxtac[0])+off;
441  return zvt;
442  }
443  }
444  return -9999.0;
445 }
446 
447 void
448 StBbcTriggerDetector::dump()
449 {
450  unsigned int i;
451  cout << "BBC data (" << mYear << ") dump" << endl;
452  if (mYear==2002){
453  cout << "East small tile ADC "; for (i=0; i<8; i++){cout << adc(i) << " ";}; cout << endl;
454  cout << "East large tile ADC "; for (i=0; i<8; i++){cout << adc(i+8) << " ";}; cout << endl;
455  cout << "West small tile ADC "; for (i=0; i<8; i++){cout << adc(i+16) << " ";}; cout << endl;
456  cout << "West large tile ADC "; for (i=0; i<8; i++){cout << adc(i+24) << " ";}; cout << endl;
457  cout << "East small tile TDC "; for (i=0; i<8; i++){cout << tdc(i) << " ";}; cout << endl;
458  cout << "East large tile TDC "; for (i=0; i<8; i++){cout << tdc(i+8) << " ";}; cout << endl;
459  cout << "West small tile TDC "; for (i=0; i<8; i++){cout << tdc(i+16) << " ";}; cout << endl;
460  cout << "West large tile TDC "; for (i=0; i<8; i++){cout << tdc(i+24) << " ";}; cout << endl;
461  cout << "Number of hits east " << nHitEast() << " west " << nHitWest() << " Total " << nHit() << endl;
462  cout << "ADC sum east " << adcSumEast() << " west " << adcSumWest() << " Total " << adcSum() << endl;
463  cout << "z vertex position = " << zVertex() << " cm" << endl;
464  cout << "Registers = "; for (i=0; i<mMaxRegisters; i++){cout << bbcRegister(i) << " ";}; cout << endl;
465  cout << "Scalars = "; for (i=0; i<mMaxScalars; i++){cout << scalar(i) << " ";}; cout << endl;
466  }
467  else if (mYear>2002) {
468  cout << "East small tile ADC "; for (i=0; i<16; i++){cout << adc(i) << " ";}; cout << endl;
469  cout << "West small tile ADC "; for (i=0; i<16; i++){cout << adc(i+24) << " ";}; cout << endl;
470  cout << "East small tile TDC "; for (i=0; i<16; i++){cout << tdc(i) << " ";}; cout << endl;
471  cout << "West small tile TDC "; for (i=0; i<16; i++){cout << tdc(i+24) << " ";}; cout << endl;
472  cout << "East large tile ADC "; for (i=0; i<8; i++) {cout << adc(i+16) << " ";}; cout << endl;
473  cout << "West large tile ADC "; for (i=0; i<8; i++) {cout << adc(i+40) << " ";}; cout << endl;
474  if (mYear>2004) {
475  cout << "East large tile TDC "; for (i=0; i<8; i++) {cout << tdc(i+16) << " ";}; cout << endl;
476  cout << "West large tile TDC "; for (i=0; i<8; i++) {cout << tdc(i+40) << " ";}; cout << endl;
477  }
478  cout << "Number of hits east " << nHitEast() << " west " << nHitWest() << " Total " << nHit() << endl;
479  cout << "ADC sum east " << adcSumEast() << " west " << adcSumWest() << " Total " << adcSum() << endl;
480  cout << "Earliest TDC east " << tdcEarliestEast() << " west " << tdcEarliestWest() << endl;
481  cout << "z vertex position = " << zVertex() << " cm" << endl;
482  }
483 }