00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include <math.h>
00057 #include "StBbcTriggerDetector.h"
00058 #include "Stiostream.h"
00059 #include "tables/St_dst_TrgDet_Table.h"
00060 #include "StTriggerData.h"
00061 #include "TMath.h"
00062 static const char rcsid[] = "$Id: StBbcTriggerDetector.cxx,v 2.14 2009/11/23 16:34:05 fisyak Exp $";
00063
00064 ClassImp(StBbcTriggerDetector)
00065
00066 StBbcTriggerDetector::StBbcTriggerDetector()
00067 {
00068 memset(mBeg,0,mEnd-mBeg);
00069 mYear=2002;
00070 mDSMVTX=0;
00071 }
00072
00073 StBbcTriggerDetector::StBbcTriggerDetector(const dst_TrgDet_st& t)
00074 {
00075 int east_q_map[24] = { 8 , 5 , 4 , 40 , 37 , 36 , 7 , 6 ,
00076 3 , 2 , 1 , 39 , 38 , 35 , 34 , 33 ,
00077 72 , 71 , 70 , 69 , 68 , 67 , 66 , 65 };
00078 int east_t_map[16] = { 16 , 13 , 12 , 48 , 45 , 44 , 15 , 14 ,
00079 11 , 10 , 9 , 47 , 46 , 43 , 42 , 41 };
00080 int west_q_map[24] = { 24 , 21 , 20 , 56 , 53 , 52 , 23 , 22 ,
00081 19 , 18 , 17 , 55 , 54 , 51 , 50 , 49 ,
00082 80 , 79 , 78 , 77 , 76 , 75 , 74 , 73 };
00083 int west_t_map[16] = { 32 , 29 , 28 , 64 , 61 , 60 , 31 , 30 ,
00084 27 , 26 , 25 , 63 , 62 , 59 , 58 , 57 };
00085
00086 memset(mBeg,0,mEnd-mBeg);
00087 int i;
00088 mYear=2003;
00089 for (i=0; i<24; i++){
00090 mAdc[i ] = (unsigned short) t.BBC[east_q_map[i]-1];
00091 mAdc[i+24] = (unsigned short) t.BBC[west_q_map[i]-1];
00092 }
00093 for (i=0; i<16; i++){
00094 mTdc[i ] = (unsigned short) t.BBC[east_t_map[i]-1];
00095 mTdc[i+24] = (unsigned short) t.BBC[west_t_map[i]-1];
00096 }
00097 mDSMVTX = 0;
00098 }
00099
00100 StBbcTriggerDetector::StBbcTriggerDetector(const StTriggerData& t)
00101 {
00102
00103
00104
00105
00106
00107
00108
00109
00110 memset(mBeg,0,mEnd-mBeg);
00111 int i,maxt;
00112 mYear = t.year();
00113 if (mYear<2005)
00114 maxt=16;
00115 else
00116 maxt=24;
00117
00118 for (i=0; i<24; i++){
00119 mAdc[i ] = (unsigned short) t.bbcADC(east, i+1);
00120 mAdc[i+24] = (unsigned short) t.bbcADC(west, i+1);
00121 }
00122 for (i=0; i<maxt; i++){
00123 mTdc[i ] = (unsigned short) t.bbcTDC(east, i+1);
00124 mTdc[i+24] = (unsigned short) t.bbcTDC(west, i+1);
00125 }
00126 mDSMVTX=t.bbcTimeDifference();
00127 }
00128
00129 StBbcTriggerDetector::~StBbcTriggerDetector() {}
00130
00131 unsigned short
00132 StBbcTriggerDetector::adc(unsigned int pmt) const
00133 {
00134 if (pmt < mMaxPMTs)
00135 return mAdc[pmt];
00136 else
00137 return 9999;
00138 }
00139
00140 unsigned short
00141 StBbcTriggerDetector::tdc(unsigned int pmt) const
00142 {
00143 if (pmt < mMaxPMTs)
00144 return mTdc[pmt];
00145 else
00146 return 9999;
00147 }
00148
00149 unsigned short
00150 StBbcTriggerDetector::bbcRegister(unsigned int n) const
00151 {
00152 if (n < mMaxRegisters)
00153 return mReg[n];
00154 else
00155 return 9999;
00156 }
00157
00158 unsigned short
00159 StBbcTriggerDetector::pedestalData(unsigned int n) const
00160 {
00161 if (n < mMaxPedData)
00162 return mPed[n];
00163 else
00164 return 9999;
00165 }
00166
00167 unsigned int
00168 StBbcTriggerDetector::scalar(unsigned int n) const
00169 {
00170 if (n < mMaxScalars)
00171 return mScl[n];
00172 else
00173 return 0;
00174 }
00175
00176 void
00177 StBbcTriggerDetector::setAdc(unsigned int pmt, unsigned short val)
00178 {
00179 if (pmt < mMaxPMTs) mAdc[pmt] = val;
00180 }
00181
00182 void
00183 StBbcTriggerDetector::setTdc(unsigned int pmt, unsigned short val)
00184 {
00185 if (pmt < mMaxPMTs) mTdc[pmt] = val;
00186 }
00187
00188 void
00189 StBbcTriggerDetector::setRegister(unsigned int id, unsigned short val)
00190 {
00191 if (id < mMaxRegisters) mReg[id] = val;
00192 }
00193
00194 void
00195 StBbcTriggerDetector::setPedestal(unsigned int id, unsigned short val)
00196 {
00197 if (id < mMaxPedData) mPed[id] = val;
00198 }
00199
00200 void
00201 StBbcTriggerDetector::setScalar(unsigned int id, unsigned int val)
00202 {
00203 if (id < mMaxScalars) mScl[id] = val;
00204 }
00205
00206 int
00207 StBbcTriggerDetector::nHitEast()
00208 {
00209 int nhit=0;
00210 if (mYear==2002) {
00211 for (int i=0; i<8; i++) {if (tdc(i)>0 && tdc(i)<1500) {nhit++;}}
00212 }
00213 else if (mYear==2003) {
00214 for (int i=0; i<16; i++) {if (adc(i)>5) {nhit++;}}
00215 }
00216 else {
00217 cerr << "StBbcTriggerDetector::nHitEast: No longer supported after 2003. Do not use!" << endl;
00218 }
00219 return nhit;
00220 }
00221
00222 int
00223 StBbcTriggerDetector::nHitWest()
00224 {
00225 int nhit=0;
00226 if (mYear==2002) {
00227 for (int i=0; i<8; i++) {if (tdc(i+16)>0 && tdc(i+16)<1500) {nhit++;}}
00228 }
00229 else if (mYear==2003) {
00230 for (int i=0; i<16; i++) {if (adc(i+24)>5) {nhit++;}}
00231 }
00232 else{
00233 cerr << "StBbcTriggerDetector::nHitWest: No longer supported after 2003. Do not use!" << endl;
00234 }
00235 return nhit;
00236 }
00237
00238 int
00239 StBbcTriggerDetector::nHitEastLarge()
00240 {
00241 int nhit=0;
00242 if (mYear==2002) {
00243 for (int i=8; i<15; i++) {if (tdc(i)>0 && tdc(i)<1500) {nhit++;}}
00244 }
00245 else if (mYear==2003) {
00246 for (int i=16; i<24; i++) {if (adc(i)>5) {nhit++;}}
00247 }
00248 else{
00249 cerr << "StBbcTriggerDetector::nHitEastlarge: No longer supported after 2003. Do not use!" << endl;
00250 }
00251 return nhit;
00252 }
00253
00254 int
00255 StBbcTriggerDetector::nHitWestLarge()
00256 {
00257 int nhit=0;
00258 if (mYear==2002) {
00259 for (int i=8; i<15; i++) {if (tdc(i+16)>0 && tdc(i+16)<1500) {nhit++;}}
00260 }
00261 else if (mYear==2003) {
00262 for (int i=16; i<24; i++) {if (adc(i+24)>5) {nhit++;}}
00263 }
00264 else {
00265 cerr << "StBbcTriggerDetector::nHitWestLarge: No longer supported after 2003. Do not use!" << endl;
00266 }
00267 return nhit;
00268 }
00269
00270 int
00271 StBbcTriggerDetector::nHit() {return nHitEast()+nHitWest();}
00272
00273 int
00274 StBbcTriggerDetector::nHitLarge() {return nHitEastLarge()+nHitWestLarge();}
00275
00276 int
00277 StBbcTriggerDetector::nHitAll() {return nHit()+nHitLarge();}
00278
00279 int
00280 StBbcTriggerDetector::adcSumEast()
00281 {
00282 int sum=0;
00283 if (mYear==2002) {
00284 for (int i=0; i<8; i++){sum+=adc(i);}
00285 }
00286 else if (mYear>=2003) {
00287 for (int i=0; i<16; i++){sum+=adc(i);}
00288 }
00289 return sum;
00290 }
00291
00292 int
00293 StBbcTriggerDetector::adcSumWest()
00294 {
00295 int sum=0;
00296 if (mYear==2002) {
00297 for (int i=0; i<8; i++){sum+=adc(i+16);}
00298 }
00299 else if (mYear>=2003) {
00300 for (int i=0; i<16; i++){sum+=adc(i+24);}
00301 }
00302 return sum;
00303 }
00304
00305 int
00306 StBbcTriggerDetector::adcSumEastLarge()
00307 {
00308 int sum=0;
00309 if (mYear==2002) {
00310 for (int i=8; i<15; i++){sum+=adc(i);}
00311 }
00312 else if (mYear>=2003) {
00313 for (int i=16; i<24; i++){sum+=adc(i);}
00314 }
00315 return sum;
00316 }
00317
00318 int
00319 StBbcTriggerDetector::adcSumWestLarge()
00320 {
00321 int sum=0;
00322 if (mYear==2002) {
00323 for (int i=8; i<15; i++){sum+=adc(i);}
00324 }
00325 else if (mYear>=2003) {
00326 for (int i=16; i<24; i++){sum+=adc(i+24);}
00327 }
00328 return sum;
00329 }
00330
00331 int
00332 StBbcTriggerDetector::adcSum(){return adcSumEast()+adcSumWest();}
00333
00334 int
00335 StBbcTriggerDetector::adcSumLarge(){return adcSumEastLarge()+adcSumWestLarge();}
00336
00337 int
00338 StBbcTriggerDetector::adcSumAll() {return adcSum()+adcSumLarge();}
00339
00340 int
00341 StBbcTriggerDetector::tdcEarliestEast()
00342 {
00343 if (mYear==2002){
00344 unsigned short earliest=2000;
00345 for (int i=0; i<8; i++){
00346 if (tdc(i)>0 && tdc(i)<earliest ) earliest=tdc(i);
00347 }
00348 if (earliest<2000)
00349 return earliest;
00350 else
00351 return -9999;
00352 }
00353 else if (mYear==2003){
00354 unsigned short earliest=0;
00355 for (int i=0; i<16; i++){
00356 if (tdc(i)<245 && tdc(i)>earliest && adc(i)>5 ) earliest=tdc(i);
00357 }
00358 if (earliest>0)
00359 return earliest;
00360 else
00361 return -9999;
00362 }
00363 else{
00364 cerr << "StBbcTriggerDetector::tdcEarliestEast: No longer supported after 2003. Do not use!" << endl;
00365 }
00366 return -9999;
00367 }
00368
00369 int
00370 StBbcTriggerDetector::tdcEarliestWest()
00371 {
00372 if (mYear==2002){
00373 unsigned short earliest=2000;
00374 for (int i=16; i<24; i++){
00375 if (tdc(i)>0 && tdc(i)<earliest ) earliest=tdc(i);
00376 }
00377 if (earliest<2000)
00378 return earliest;
00379 else
00380 return -8888;
00381 }
00382 else if (mYear==2003){
00383 unsigned short earliest=0;
00384 for (int i=24; i<40; i++){
00385 if (tdc(i)<245 && tdc(i)>earliest && adc(i)>5 ) earliest=tdc(i);
00386 }
00387 if (earliest>0)
00388 return earliest;
00389 else
00390 return -8888;
00391 }
00392 else{
00393 cerr << "StBbcTriggerDetector::tdcEarliestWest: No longer supported after 2003. Do not use!" << endl;
00394 }
00395 return -8888;
00396 }
00397
00398 float
00399 StBbcTriggerDetector::zVertex()
00400 {
00401 if (mYear==2002){
00402 unsigned short east=tdcEarliestEast();
00403 unsigned short west=tdcEarliestWest();
00404 if (east<2000 && west<2000 && east!=0 && west!=0)
00405 return (float(east-west))*5.0;
00406 else
00407 return -9999.0;
00408 }
00409 else if (mYear==2003){
00410 unsigned short east=tdcEarliestEast();
00411 unsigned short west=tdcEarliestWest();
00412 if (east>0 && west>0)
00413 return float(west-east)*3.0;
00414 else
00415 return -9999.0;
00416 }
00417 else{
00418 float slope=2.0;
00419 float tc[4]={49.89, -3.155, 4.537, -0.1471};
00420 float off=-13.77l;
00421 float offset[2][16] = {
00422 {-2.00982, 4.09827, 4.83372, -4.71373,
00423 -8.33428, -8.51657, -2.16193, 14.6726,
00424 1.61522, 0.605228, 4.98944, -1.86768,
00425 -2.46653, -2.70569, -4.33065, -5.07069},
00426 {-4.90599, -2.62884, -2.87498, 5.58336,
00427 0.100682, 0.065195, -0.35114, -2.96953,
00428 1.2031, 2.94575, -1.93577, -1.13641,
00429 1.86768, 4.27345, 7.0431, -1.16071}
00430 };
00431 float maxtac[2]={0.0, 0.0};
00432 for(int iew=0; iew<2; iew++){
00433 for(int ich=0; ich<16; ich++){
00434 int j=iew*24+ich;
00435 float tac = tdc(j) - offset[iew][ich] - (tc[0]+tc[1]/TMath::Exp(-tc[2]*TMath::Power(adc(j),tc[3])))/slope;
00436 if(adc(j)>10 && tac<200 && tac>maxtac[iew]) {maxtac[iew]=tac;}
00437 }
00438 }
00439 if(maxtac[0]>0.0 && maxtac[1]>0.0){
00440 float zvt=slope*(maxtac[1]-maxtac[0])+off;
00441 return zvt;
00442 }
00443 }
00444 return -9999.0;
00445 }
00446
00447 void
00448 StBbcTriggerDetector::dump()
00449 {
00450 unsigned int i;
00451 cout << "BBC data (" << mYear << ") dump" << endl;
00452 if (mYear==2002){
00453 cout << "East small tile ADC "; for (i=0; i<8; i++){cout << adc(i) << " ";}; cout << endl;
00454 cout << "East large tile ADC "; for (i=0; i<8; i++){cout << adc(i+8) << " ";}; cout << endl;
00455 cout << "West small tile ADC "; for (i=0; i<8; i++){cout << adc(i+16) << " ";}; cout << endl;
00456 cout << "West large tile ADC "; for (i=0; i<8; i++){cout << adc(i+24) << " ";}; cout << endl;
00457 cout << "East small tile TDC "; for (i=0; i<8; i++){cout << tdc(i) << " ";}; cout << endl;
00458 cout << "East large tile TDC "; for (i=0; i<8; i++){cout << tdc(i+8) << " ";}; cout << endl;
00459 cout << "West small tile TDC "; for (i=0; i<8; i++){cout << tdc(i+16) << " ";}; cout << endl;
00460 cout << "West large tile TDC "; for (i=0; i<8; i++){cout << tdc(i+24) << " ";}; cout << endl;
00461 cout << "Number of hits east " << nHitEast() << " west " << nHitWest() << " Total " << nHit() << endl;
00462 cout << "ADC sum east " << adcSumEast() << " west " << adcSumWest() << " Total " << adcSum() << endl;
00463 cout << "z vertex position = " << zVertex() << " cm" << endl;
00464 cout << "Registers = "; for (i=0; i<mMaxRegisters; i++){cout << bbcRegister(i) << " ";}; cout << endl;
00465 cout << "Scalars = "; for (i=0; i<mMaxScalars; i++){cout << scalar(i) << " ";}; cout << endl;
00466 }
00467 else if (mYear>2002) {
00468 cout << "East small tile ADC "; for (i=0; i<16; i++){cout << adc(i) << " ";}; cout << endl;
00469 cout << "West small tile ADC "; for (i=0; i<16; i++){cout << adc(i+24) << " ";}; cout << endl;
00470 cout << "East small tile TDC "; for (i=0; i<16; i++){cout << tdc(i) << " ";}; cout << endl;
00471 cout << "West small tile TDC "; for (i=0; i<16; i++){cout << tdc(i+24) << " ";}; cout << endl;
00472 cout << "East large tile ADC "; for (i=0; i<8; i++) {cout << adc(i+16) << " ";}; cout << endl;
00473 cout << "West large tile ADC "; for (i=0; i<8; i++) {cout << adc(i+40) << " ";}; cout << endl;
00474 if (mYear>2004) {
00475 cout << "East large tile TDC "; for (i=0; i<8; i++) {cout << tdc(i+16) << " ";}; cout << endl;
00476 cout << "West large tile TDC "; for (i=0; i<8; i++) {cout << tdc(i+40) << " ";}; cout << endl;
00477 }
00478 cout << "Number of hits east " << nHitEast() << " west " << nHitWest() << " Total " << nHit() << endl;
00479 cout << "ADC sum east " << adcSumEast() << " west " << adcSumWest() << " Total " << adcSum() << endl;
00480 cout << "Earliest TDC east " << tdcEarliestEast() << " west " << tdcEarliestWest() << endl;
00481 cout << "z vertex position = " << zVertex() << " cm" << endl;
00482 }
00483 }