StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBemcTrigger.cxx
1 //
2 // $Id: StBemcTrigger.cxx,v 1.33 2009/12/03 14:15:59 rfatemi Exp $
3 //
4 //
5 
6 #include "StBemcTrigger.h"
7 #include "StEvent/StEvent.h"
8 #include "StEvent/StEventTypes.h"
9 #include "StEmcUtil/geometry/StEmcGeom.h"
10 #include "StarRoot/TUnixTime.h"
11 #include "StDaqLib/EMC/StEmcDecoder.h"
12 #include "Stiostream.h"
13 #include "St_db_Maker/St_db_Maker.h"
14 #include "tables/St_emcPed_Table.h"
15 #include "StEmcUtil/database/StBemcTables.h"
16 #include "StEmcRawMaker/defines.h"
17 
18 ClassImp(StBemcTrigger);
19 
20 //-------------------------------------------------------------------
21 StBemcTrigger::StBemcTrigger():TObject()
22 {
23  mGeo=StEmcGeom::getEmcGeom("bemc");
24  mEvent = NULL;
25  mDecoder = new StEmcDecoder();
26  resetConf();
27 }
28 //----------------------------------------------------
29 StBemcTrigger::~StBemcTrigger()
30 {}
31 
32 //----------------------------------------------------
33 void StBemcTrigger::resetConf(){
34 
35  PatchMap();
36 
37  mTrigger.HTBits = 3;
38 
39  //set all towers to status good because only offline status is used
40  for(int i = 0;i<kNTowers;i++) mTrigger.TowerStatus[i] = 1;
41  //set all patches to status good because only offline status is used
42  for(int i = 0;i<kNPatches;i++) mTrigger.PatchStatus[i] = 1;
43 
44 
45  mIs2003HT1=-1;
46  mIs2004HT1=-1;
47  mIs2004JP1=-1;
48  mIs2004HT2=-1;
49  mIs2004JP2=-1;
50  mIs2005HT1=-1;
51  mIs2005JP1=-1;
52  mIs2005HT2=-1;
53  mIs2005JP2=-1;
54  mIs2005ADJ=-1;
55  mIs2005JPSI=-1;
56  for ( int matrix=0;matrix<6;matrix++){
57  mIs2006JP0[matrix]=-1;
58  mIs2006HT2[matrix]=-1;
59  mIs2006JP1[matrix]=-1;
60  mIs2006JPSI[matrix]=-1;
61  mIs2006BHTTP[matrix]=-1;
62  }
63  for (int i=0;i<50;i++)
64  {
65  mIsTrig[i]=-1;
66  }
67 
68  HT1_ID_2003=-1;
69  HT1_ID_2004=-1;
70  HT2_ID_2004=-1;
71  JP1_ID_2004=-1;
72  JP2_ID_2004=-1;
73  HT1_ID_2005=-1;
74  HT2_ID_2005=-1;
75  JP1_ID_2005=-1;
76  JP2_ID_2005=-1;
77  ADJ_ID_2005=-1;
78  for (int matrix=0;matrix<6;matrix++){
79  HT2_ID_2006[matrix]=-1;
80  JP0_ID_2006[matrix]=-1;
81  JP1_ID_2006[matrix]=-1;
82  }
83  for (int i=0;i<50;i++)
84  {
85  mTowJetId[i] = -1;
86  }
87 
88  HT1_DSM_2003=-1;
89  HT1_DSM_2004=-1;
90  HT2_DSM_2004=-1;
91  JP1_DSM_2004=-1;
92  JP2_DSM_2004=-1;
93  HT1_DSM_2005=-1;
94  HT2_DSM_2005=-1;
95  JP1_DSM_2005=-1;
96  JP2_DSM_2005=-1;
97  ADJ_DSM_2005=-1;
98  for ( int matrix=0;matrix<6;matrix++){
99  HT2_DSM_2006[matrix]=-1;
100  JP0_DSM_2006[matrix]=-1;
101  JP1_DSM_2006[matrix]=-1;
102  }
103  BETOT_DSM_2006=-1;
104  for (int i=0;i<50;i++)
105  {
106  mDsmAdc[i] = -1;
107  }
108 
109  for(int i=0;i<kNTowers;i++){
110  mHT12005array[i]=-1;
111  mHT22005array[i]=-1;
112  for (int matrix=0;matrix<6;matrix++) mHT22006array[matrix][i]=-1;
113  }
114  for (int i=0;i<kNJet;i++){
115  mJP12005array[i]=-1;
116  mJP22005array[i]=-1;
117  for (int matrix=0;matrix<6;matrix++) mJP02006array[matrix][i]=-1;
118  for (int matrix=0;matrix<6;matrix++) mJP12006array[matrix][i]=-1;
119  }
120 
121  for (int i=0;i<kNJet/2;i++) BL1_ADC_2006[i]=-1;
122 
123  for (int i=0;i<12;i++){
124  mnumHT[i]=0;
125  mnumJP[i]=0;
126  if (i<6) mnumHTTP[i]=0;
127  }
128 
129 }
130 
131 //----------------------------------------------------
132 void StBemcTrigger::zero()
133 {
134  for(int i=0;i<kNPatches;i++)
135  {
136  mTrigger.HT[i] = 0;
137  mTrigger.HTID[i]=0;
138  mTrigger.Patch[i]= 0;
139  }
140 
141  for(int i=0;i<kNJet;i++)
142  {
143  mTrigger.Jet[i]= 0;
144  }
145 
146  mTrigger.Et = 0;
147 
148 }
149 
150 
151 void StBemcTrigger::PatchMap()
152 
153 
154 
156 {
157 
158  for (int i=0;i<20;i++)
159  {
160  JP_TP[0][i]=i+30;
161  JP_TP[1][i]=i+50;
162  JP_TP[2][i]=i+80;
163  JP_TP[3][i]=i+100;
164  JP_TP[4][i]=i+130;
165  JP_TP[5][i]=i;
166  if (i<10)
167  JP_TP[6][i]=i+150;
168  if (i>=10)
169  JP_TP[6][i]=i+290-10;
170  JP_TP[7][i]=i+170;
171  JP_TP[8][i]=i+190;
172  JP_TP[9][i]=i+220;
173  JP_TP[10][i]=i+240;
174  JP_TP[11][i]=i+270;
175  }
176 
177  for (int i=20;i<25;i++)
178  {
179  int j=i-20;
180  int keven=2*j;
181  int kodd=2*j+1;
182  JP_TP[0][i]=20+keven;
183  JP_TP[1][i]=70+kodd;
184  JP_TP[2][i]=70+keven;
185  JP_TP[3][i]=120+kodd;
186  JP_TP[4][i]=120+keven;
187  JP_TP[5][i]=20+kodd;
188  JP_TP[6][i]=160+kodd;
189  JP_TP[7][i]=160+keven;
190  JP_TP[8][i]=210+kodd;
191  JP_TP[9][i]=210+keven;
192  JP_TP[10][i]=260+kodd;
193  JP_TP[11][i]=260+keven;
194  }
195 
196  for (int i=0;i<12;i++)
197  {
198  TString line("JP");
199  line += i;
200  line += " is sum of TP = ";
201  for (int j=0;j<25;j++)
202  {
203  if (j!=24){
204  line += JP_TP[i][j];
205  line += "+";
206  }
207  if (j==24)
208  line += JP_TP[i][j];
209  }
210  LOG_INFO << line << endm;
211  }
212 
213 
214  /****************************************************************************
215  http://www.nikhef.nl/~ogrebeny/emc/files/Towers%20Layout.xls documents
216  the tower->TP->JP correpsondence. Using StEmcDecoder,StEmcGeom and
217  the above spreadsheet I defined JP#s and assigned correct TP's above.
218 
219  JP TOWERS Clock Pos. looking from W -> vertex
220  --- -------- -----------------------------------------
221  0 1-100,2101-2400 12
222  1 101-500 10
223  2 501-900 08
224  3 901-1300 06
225  4 1301-1700 04
226  5 1701-2100 02
227  6 2401-2500,4501-4800 12
228  7 2501-2900 02
229  8 2901-3300 04
230  9 3301-3700 06
231  10 3701-4100 08
232  11 4101-4500 10
233  **************************************************************************/
234 
235 
236  /* mapping of renee's JP ids to StEmcDecoder's ids
237  int renee[12];
238  renee[0] = 5;
239  renee[1] = 0;
240  renee[2] = 1;
241  renee[3] = 2;
242  renee[4] = 3;
243  renee[5] = 4;
244  renee[6] = 7;
245  renee[7] = 6;
246  renee[8] = 11;
247  renee[9] = 10;
248  renee[10] = 9;
249  renee[11] = 8;
250  */
251 
252 }
253 
254 
255 int StBemcTrigger::makeTrigger()
256 {
257  get2003Trigger();
258  get2004Trigger();
259  get2005Trigger();
260  get2006Trigger();
261 
262  //2003 HT1 == 1101+2201
263  mIsTrig[0] =mIs2003HT1;
264  mTowJetId[0]=HT1_ID_2003;
265  mDsmAdc[0] =HT1_DSM_2003;
266 
267  //2003 HT2 == 2202
268  mIsTrig[42] =mIs2003HT2;
269  mTowJetId[42]=HT2_ID_2003;
270  mDsmAdc[42] =HT2_DSM_2003;
271 
272  //2004 HT1 == 45201
273  mIsTrig[1] =mIs2004HT1;
274  mTowJetId[1]=HT1_ID_2004;
275  mDsmAdc[1] =HT1_DSM_2004;
276 
277  //2004 HT2 == 45202
278  mIsTrig[2] =mIs2004HT2;
279  mTowJetId[2]=HT2_ID_2004;
280  mDsmAdc[2] =HT2_DSM_2004;
281 
282  //2004 JP1 == 45206
283  mIsTrig[3] =mIs2004JP1;
284  mTowJetId[3]=JP1_ID_2004;
285  mDsmAdc[3] =JP1_DSM_2004;
286 
287  //2004 JP2 == 45207
288  mIsTrig[4] =mIs2004JP2;
289  mTowJetId[4]=JP2_ID_2004;
290  mDsmAdc[4] =JP2_DSM_2004;
291 
292  //2005 HT1 == 96201
293  mIsTrig[5] =mIs2005HT1;
294  mTowJetId[5]=HT1_ID_2005;
295  mDsmAdc[5] =HT1_DSM_2005;
296  mnumHT[3] =numHT1_2005;
297  for (int i=0;i<numHT1_2005;i++){
298  mHT12005array[i]=HT1_2005_array[i];
299  }
300 
301  //2005 HT2 == 96211
302  mIsTrig[6] =mIs2005HT2;
303  mTowJetId[6]=HT2_ID_2005;
304  mDsmAdc[6] =HT2_DSM_2005;
305  mnumHT[4] =numHT2_2005;
306  for (int i=0;i<numHT2_2005;i++){
307  mHT22005array[i]=HT2_2005_array[i];
308  }
309 
310  //2005 JP1 == 96221
311  mIsTrig[7] =mIs2005JP1;
312  mTowJetId[7]=JP1_ID_2005;
313  mDsmAdc[7] =JP1_DSM_2005;
314  mnumJP[2] =numJP1_2005;
315  for (int i=0;i<numJP1_2005;i++){
316  mJP12005array[i]=JP1_2005_array[i];
317  }
318 
319  //2005 JP2 == 96233
320  mIsTrig[8] =mIs2005JP2;
321  mTowJetId[8]=JP2_ID_2005;
322  mDsmAdc[8] =JP2_DSM_2005;
323  mnumJP[3] =numJP2_2005;
324  for (int i=0;i<numJP2_2005;i++){
325  mJP22005array[i]=JP2_2005_array[i];
326  }
327 
328  //2005 AJP == 96241
329  mIsTrig[9] =mIs2005ADJ;
330  mTowJetId[9]=ADJ_ID_2005;
331  mDsmAdc[9] =ADJ_DSM_2005;
332 
333 
334  //2005 JPSI
335  mIsTrig[10] =mIs2005JPSI;
336  mTowJetId[10]=-1;
337  mDsmAdc[10]=-1;
338  for (int i=0;i<kNJet;i++){
339  mJPSI2005adc[i]=JPSI_2005_ADC[i];
340  mJPSI2005id[i]=JPSI_2005_ID[i];
341  }
342 
343 
344 
345  for (int matrix=0;matrix<6;matrix++){
346 
347  //2006 HT2
348  mIsTrig[11+(matrix*5)] =mIs2006HT2[matrix];
349  mTowJetId[11+(matrix*5)]=HT2_ID_2006[matrix];
350  mDsmAdc[11+(matrix*5)] =HT2_DSM_2006[matrix];
351  mnumHT[5+matrix] =numHT2_2006[matrix];
352  for (int i=0;i<numHT2_2006[matrix];i++){
353  mHT22006array[matrix][i]=HT2_2006_array[matrix][i];
354  }
355 
356  //2006 JP1
357  mIsTrig[12+(matrix*5)] =mIs2006JP0[matrix];
358  mTowJetId[12+(matrix*5)]=JP0_ID_2006[matrix];
359  mDsmAdc[12+(matrix*5)] =JP0_DSM_2006[matrix];
360  mnumJP[5+(matrix*2)] =numJP0_2006[matrix];
361  for (int i=0;i<numJP0_2006[matrix];i++){
362  mJP02006array[matrix][i]=JP0_2006_array[matrix][i];
363  }
364 
365  //2006 JP2
366  mIsTrig[13+(matrix*5)] =mIs2006JP1[matrix];
367  mTowJetId[13+(matrix*5)]=JP1_ID_2006[matrix];
368  mDsmAdc[13+(matrix*5)] =JP1_DSM_2006[matrix];
369  mnumJP[6+(matrix*2)] =numJP1_2006[matrix];
370  for (int i=0;i<numJP1_2006[matrix];i++){
371  mJP12006array[matrix][i]=JP1_2006_array[matrix][i];
372  }
373 
374  //2006 JPSI
375  mIsTrig[14+(matrix*5)] =mIs2006JPSI[matrix];
376  mTowJetId[14+(matrix*5)]=-1;
377  mDsmAdc[14+(matrix*5)]=-1;
378  for (int i=0;i<kNJet;i++){
379  mJPSI2006adc[matrix][i]=JPSI_2006_ADC[matrix][i];
380  mJPSI2006id[matrix][i]=JPSI_2006_ID[matrix][i];
381  }
382 
383  //2006 BHTTP
384  mIsTrig[15+(matrix*5)]=mIs2006BHTTP[matrix];
385  mTowJetId[15+(matrix*5)]=-1;
386  mDsmAdc[15+(matrix*5)]=-1;
387  mnumHTTP[matrix]=0;
388  mnumHTTP[matrix]=numHTTP_2006[matrix];
389  for (int i=0; i<numHTTP_2006[matrix];i++){
390  mHTTP2006arrayHT[matrix][i]=BHTTP_2006_HT[matrix][i];
391  mHTTP2006arrayHTADC[matrix][i]=BHTTP_2006_HT_ADC[matrix][i];
392  mHTTP2006arrayTP[matrix][i]=BHTTP_2006_TP[matrix][i];
393  mHTTP2006arrayTPADC[matrix][i]=BHTTP_2006_TP_ADC[matrix][i];
394  }
395  }
396 
397  //2006 BETOT
398  mIsTrig[41]=-1;
399  mTowJetId[41]=-1;
400  mDsmAdc[41]=BETOT_DSM_2006;
401  for (int i=0; i<(kNJet/2); i++){mBL12006arrayADC[i]=BL1_ADC_2006[i];}
402 
403 
404 
405  return kStOK;
406 }
407 
408 
409 int StBemcTrigger::get2003Trigger()
410 {
411  zero();
412 
413  const int HT1_TH_2003 = 8;
414  const int HT2_TH_2003 = 13;
415 
416  if(!mEvent)
417  return kStWarn;
418  StEmcCollection *emc = mEvent->emcCollection();
419  if(!emc)
420  return kStWarn;
421 
422  int adc12[kNTowers];
423  int adc10[kNTowers];
424  for(int i=0;i<kNTowers;i++)
425  {
426  adc12[i] = 0;
427  adc10[i] = 0;
428  }
429 
430 
431  StEmcDetector* detector=emc->detector(kBarrelEmcTowerId);
432  if(detector)
433  {
434  for(Int_t m=1;m<=60;m++)
435  {
436  StEmcModule* module = detector->module(m);
437  if(module)
438  {
439  StSPtrVecEmcRawHit& rawHit=module->hits();
440  for(UInt_t k=0;k<rawHit.size();k++)
441  if(rawHit[k])
442  {
443  Int_t did;
444  Int_t mod=rawHit[k]->module();
445  Int_t e=rawHit[k]->eta();
446  Int_t s=abs(rawHit[k]->sub());
447  mGeo->getId(mod,e,s,did);
448  if(mTrigger.TowerStatus[did-1]==1)
449  {
450  adc12[did-1]=rawHit[k]->adc();
451  adc10[did-1] = adc12[did-1]>>2;
452  }
453  }
454  }
455  }
456  }
457 
458  else
459  {
460  return kStWarn;
461  }
462 
463 
464 
465  TUnixTime unixTime(mEvent->time());
466  Int_t dat=0,tim=0;
467  unixTime.GetGTime(dat,tim);
468  mDecoder->SetDateTime(dat,tim);
469  mDecoder->SetFixTowerMapBug(true);
470 
471 
472  int HTmax=0;
473  int HTmaxID=-1;
474  for(int i = 0;i<kNPatches;i++)
475  if(mTrigger.PatchStatus[i]==1)
476  {
477  int crate = 0;
478  int seq = 0;
479  int HT = 0;//holder for highest tower in patch
480  int HTID = -1;//id for highest tower in patch
481  int id;//BEMC tower id
482 
483  mDecoder->GetCrateAndSequenceFromTriggerPatch(i,crate,seq);
484 
485  for(int j=seq;j<seq+16;j++)
486  {
487  int stat = mDecoder->GetTowerIdFromCrate(crate,j,id);
488  if(stat==1)
489  {
490  if(adc10[id-1]>=HT)
491  {
492  HT = adc10[id-1];
493  HTID = id;
494  }
495  }
496  }
497 
498  int SHIFT = mTrigger.HTBits;
499  HT = HT >> SHIFT; //shift by 3 bits -> now have 7 bits
500  int HTL = HT & 0x1F;//strip off 5 LB
501  int HTH = HT >> 5;//strip off top 2 HB
502  int B5 = 0;
503  if(HTH>0) B5 = 1; // IF top bits !=0 B5=1
504  mTrigger.HT[i] = HTL+(B5<<5); // Or top bits
505  { LOG_DEBUG <<"Patch number "<<i<<" Tower id = "<<
506  HTID<<" adc12 = "<<adc12[HTID-1]<<" adc10 = "<<
507  adc10[HTID-1]<<" HT = "<<mTrigger.HT[i]<<endm; }
508  if (mTrigger.HT[i]>HTmax)
509  {
510  HTmax=mTrigger.HT[i];
511  HTmaxID=HTID;
512  }
513  }
514 
515  if (HTmax>HT1_TH_2003)
516  {
517  mIs2003HT1=1;
518  HT1_ID_2003=HTmaxID;
519  HT1_DSM_2003=HTmax;
520  }
521  else
522  {
523  mIs2003HT1=0;
524  HT1_ID_2003=HTmaxID;
525  HT1_DSM_2003=HTmax;
526  }
527 
528  if (HTmax>HT2_TH_2003)
529  {
530  mIs2003HT2=1;
531  HT2_ID_2003=HTmaxID;
532  HT2_DSM_2003=HTmax;
533  }
534  else
535  {
536  mIs2003HT2=0;
537  HT2_ID_2003=HTmaxID;
538  HT2_DSM_2003=HTmax;
539  }
540 
541 
542  return kStOK;
543 }
544 
545 
546 //----------------------------------------------------
547 int StBemcTrigger::get2004Trigger()
548 {
549  zero();
550 
551  const int HT1_TH_2004 = 10;//bht0=10,bht1=20,bht2=30
552  const int HT2_TH_2004 = 20;
553  const int JP1_TH_2004 = 40;//bjp0=15,bjp1=40,bjp2=60
554  const int JP2_TH_2004 = 60;
555  const int pedestalTargetValue2004 = 8;
556 
557  if(!mEvent)
558  return kStWarn;
559  StEmcCollection *emc = mEvent->emcCollection();
560  if(!emc)
561  return kStWarn;
562 
563 
564  //This code accesses offline database to get peds. These are NOT == peds
565  //which were used during running. So NO ONLINE INFO is used in this trigger
566  //reconstruction because the online database was not filled for 2004!
567 
568 
569  int adc12[kNTowers];
570  int adc10[kNTowers];
571  int adc08[kNTowers];
572  int ped10[kNTowers];
573  for(int i=0;i<kNTowers;i++)
574  {
575  adc12[i] = 0;
576  adc10[i] = 0;
577  adc08[i] = 0;
578  ped10[i] = 0;
579  }
580 
581  int ped12bit, val12bit,operation;// operation bit for pedestal subtraction
582  // subtract: +1 (default) add: 0
583 
584  StEmcDetector* detector=emc->detector(kBarrelEmcTowerId);
585  if(detector)
586  {
587  for(Int_t m=1;m<=60;m++)
588  {
589  StEmcModule* module = detector->module(m);
590  if(module)
591  {
592  StSPtrVecEmcRawHit& rawHit=module->hits();
593  for(UInt_t k=0;k<rawHit.size();k++)
594  if(rawHit[k])
595  {
596  Int_t did;
597  Int_t mod=rawHit[k]->module();
598  Int_t e=rawHit[k]->eta();
599  Int_t s=abs(rawHit[k]->sub());
600  mGeo->getId(mod,e,s,did);
601  if(mTrigger.TowerStatus[did-1]==1)
602  {
603  adc12[did-1]=rawHit[k]->adc();
604  adc10[did-1] = adc12[did-1]>>2;
605  {
606  //ped12bit = pedestalTable->AdcPedestal[did-1]/100;
608  float NEWped=-1;
609  float NEWrms=-1;
610  mTables ->getPedestal(BTOW,did,0,NEWped,NEWrms);
611  ped12bit=(int) NEWped;
612 
613 
614  operation = 1;
615  ped10[did-1] = ped12bit >> 2;
616  val12bit = ped12bit - pedestalTargetValue2004;
617 
618  if(val12bit < 0)
619  {
620  val12bit = -val12bit;
621  operation = 0;
622  }
623  int val10bit = val12bit/4;
624 
625  //this next line was in the 2004/2005 tcl code
626  //but it seems to be wrong because it results
627  //in ped10==1 at times (ex ADC=71&&ped=39)
628  if (val12bit - val10bit*4 > 2)
629  val10bit+=1;
630  if(val10bit > 15)
631  {
632  // can't subtract/add more than 15 on 10-bit level
633  val10bit = val10bit - 4*((val10bit-11)/4);
634  }
635 
636  if(operation==1)
637  {
638  adc10[did-1] -= val10bit;
639  ped10[did-1] -= val10bit;
640  }
641  else
642  {
643  adc10[did-1] += val10bit;
644  ped10[did-1] += val10bit;
645  }
646  }
647  adc08[did-1] = adc10[did-1]>>2;// adc10[],adc08[] are ped-adjusted
648  }
649  }
650  }
651  }
652  }
653  else
654  {
655  LOG_WARN << "StBemcTrigger::make2004Trigger() -- pointer to StEmcDetector is zero!" << endm;
656  return kStWarn;
657  }
658 
659  // making trigger patches and high towers
660  TUnixTime unixTime(mEvent->time());
661  Int_t dat=0,tim=0;
662  unixTime.GetGTime(dat,tim);
663  mDecoder->SetDateTime(dat,tim);
664  mDecoder->SetFixTowerMapBug(true);
665 
666  int HTmax=0;
667  int HTmaxID=-1;
668  for(int i = 0;i<kNPatches;i++)
669  if(mTrigger.PatchStatus[i]==1)
670  {
671  int crate = 0;
672  int seq = 0;
673  mDecoder->GetCrateAndSequenceFromTriggerPatch(i,crate,seq);
674  int HT = 0;
675  int PA = 0;
676  int HTID = -1;
677  int id;
678  int patchPed = 0;
679  for(int j=seq;j<seq+16;j++)
680  {
681  int stat = mDecoder->GetTowerIdFromCrate(crate,j,id);
682  if(stat==1)
683  {
684  if(adc10[id-1]>=HT)
685  {
686  HT = adc10[id-1];
687  HTID = id;
688 
689  }
690  patchPed+= (ped10[id-1]>>2);
691  PA+=adc08[id-1];
692  }
693  }
694 
695 
696  // now HT=10 bits and patch=12 bits
697  // convert patch sum to 6 bits using LUT
698  // TPsum= TPsum - 0 for 2004 because all TP peds=0
699  // for 2005 all TP peds=16 so TPsum=TPsum-15
700  // The fact that not all peds can be shifted to 2
701  // on 10bit level require us to add up and then
702  // subtract patchPed. But patchPed should==0 usually
703 
704  if(PA >= patchPed)
705  {
706  mTrigger.Patch[i] = PA - patchPed;
707  if(mTrigger.Patch[i] > 62)
708  mTrigger.Patch[i] = 62;
709  }
710 
711  // for HT need to OR top 2 bits and drop top bit
712  // then drop bottom 3 bits
713  int SHIFT = mTrigger.HTBits;
714  HT = HT >> SHIFT;
715  int HTL = HT & 0x1F;
716  int HTH = HT >> 5;
717  int B5 = 0;
718  if(HTH>0)
719  B5 = 1;
720  mTrigger.HT[i] = HTL+(B5<<5);
721  { LOG_DEBUG <<"Patch number "<<i<<" Tower id = "<<HTID<<" adc12 = "<<adc12[HTID-1]<<" adc10 = "
722  <<adc10[HTID-1]<<" adc08 = "<<adc08[HTID-1]<<" HT10 = "<<HT<<" PA12 = "<<PA
723  <<" HT = "<<mTrigger.HT[i]<<" PA = "<<mTrigger.Patch[i]<<endm; }
724  if (mTrigger.HT[i]>HTmax)
725  {
726  HTmax=mTrigger.HT[i];
727  HTmaxID=HTID;
728  }
729  }
730 
731  if (HTmax>HT1_TH_2004)
732  {
733  mIs2004HT1=1;
734  HT1_ID_2004=HTmaxID;
735  HT1_DSM_2004=HTmax;
736  }
737  else
738  {
739  mIs2004HT1=0;
740  HT1_ID_2004=HTmaxID;
741  HT1_DSM_2004=HTmax;
742  }
743  if (HTmax>HT2_TH_2004)
744  {
745  mIs2004HT2=1;
746  HT2_ID_2004=HTmaxID;
747  HT2_DSM_2004=HTmax;
748  }
749  else
750  {
751  mIs2004HT2=0;
752  HT2_ID_2004=HTmaxID;
753  HT2_DSM_2004=HTmax;
754  }
755 
756  for (int i=0;i<300;i++)
757  {
758  trgPatch[i]=0;
759  trgPatch[i]=mTrigger.Patch[i];
760  }
761 
762  // making Jet trigger and Et
763  int JPmax=0;
764  int JPid=0;
765  mTrigger.Et = 0;
766  for(int i = 0;i<kNJet; i++)
767  {
768  int p0 = 0;
769  int p1 = p0+25;
770 
771  mTrigger.Jet[i]= 0;
772  for (int j=p0;j<p1;j++)
773  {
774  int k=JP_TP[i][j];
775  mTrigger.Jet[i]+=mTrigger.Patch[k];
776  }
777 
778  mTrigger.Et+=mTrigger.Jet[i];
779  if (mTrigger.Jet[i]>JPmax)
780  {
781  JPmax=mTrigger.Jet[i];
782  JPid=i;
783  }
784  }
785 
786  if (JPmax>JP1_TH_2004)
787  {
788  mIs2004JP1=1;
789  JP1_ID_2004=JPid;
790  JP1_DSM_2004=JPmax;
791  }
792  else
793  {
794  mIs2004JP1=0;
795  JP1_ID_2004=JPid;
796  JP1_DSM_2004=JPmax;
797  }
798 
799  if (JPmax>JP2_TH_2004)
800  {
801  mIs2004JP2=1;
802  JP2_ID_2004=JPid;
803  JP2_DSM_2004=JPmax;
804  }
805  else
806  {
807  mIs2004JP2=0;
808  JP2_ID_2004=JPid;
809  JP2_DSM_2004=JPmax;
810  }
811 
812 
813  return kStOK;
814 }
815 
816 
817 //----------------------------------------------------
818 int StBemcTrigger::get2005Trigger()
819 {
820  //for 2005 still need to test LUT subtraction
821  //incorporate online peds. trigger masks, DSM masks + LUT tables
822 
823  zero();
824 
825 
826  const int JPSI_TH_2005 = 5;//bht0=5,bht1=13,bht2=17
827  const int HT1_TH_2005 = 13;
828  const int HT2_TH_2005 = 17;
829  const int JP1_TH_2005 = 66;//bjp0=46,bjp1=66,bjp2=84
830  const int JP2_TH_2005 = 84;
831  const int pedestalTargetValue2005 = 24;
832 
833 
834  if(!mEvent)
835  {
836  LOG_WARN << "StBemcTrigger::make2005Trigger() -- no StEvent!" << endm;
837  return kStWarn;
838  }
839  StEmcCollection *emc = mEvent->emcCollection();
840  if(!emc)
841  {
842  LOG_WARN << "StBemcTrigger::make2005Trigger() -- no StEmcCollection!" << endm;
843  return kStWarn;
844  }
845 
846  int adc12[kNTowers];
847  int adc10[kNTowers];
848  int adc08[kNTowers];
849  int ped10[kNTowers];
850  for(int i=0;i<kNTowers;i++){
851  adc12[i] = 0;
852  adc10[i] = 0;
853  adc08[i] = 0;
854  ped10[i] = 0;
855  HT1_2005_array[i]=-1;
856  HT2_2005_array[i]=-1;
857  mHT12005array[i]=-1;
858  mHT22005array[i]=-1;
859  }
860 
861  mnumHT[3]=0;
862  mnumHT[4]=0;
863  mnumJP[2]=0;
864  mnumJP[3]=0;
865  mnumJP[4]=0;
866 
867  for (int i=0;i<kNJet;i++){
868  JP1_2005_array[i]=-1;
869  JP2_2005_array[i]=-1;
870  mJP12005array[i]=-1;
871  mJP22005array[i]=-1;
872  mJPSI2005adc[i]=-1;
873  mJPSI2005id[i]=-1;
874  }
875 
876  numHT1_2005=0;
877  numHT2_2005=0;
878  numJP1_2005=0;
879  numJP2_2005=0;
880  numADJ_2005=0;
881 
882 
883 
884  int ped12bit, val12bit;
885  int operation; // operation bit for pedestal subtraction
886  // subtract: +1 (default)
887  // add: 0
888 
889  StEmcDetector* detector=emc->detector(kBarrelEmcTowerId);
890  if(detector)
891  {
892  for(Int_t m=1;m<=60;m++)
893  {
894  StEmcModule* module = detector->module(m);
895  if(module)
896  {
897  StSPtrVecEmcRawHit& rawHit=module->hits();
898  for(UInt_t k=0;k<rawHit.size();k++)
899  if(rawHit[k])
900  {
901  Int_t did;
902  Int_t mod=rawHit[k]->module();
903  Int_t e=rawHit[k]->eta();
904  Int_t s=abs(rawHit[k]->sub());
905  mGeo->getId(mod,e,s,did);
906  if ((mTrigger.TowerStatus[did-1]==1)&&(mTables->status(BTOW,did,"calib")==1))
907  {
908  adc12[did-1]=rawHit[k]->adc();
909  adc10[did-1] = adc12[did-1]>>2;
910  {
911  // Trigger pedestals were subtracted online.
912  // ped12bit = pedestalTable->AdcPedestal[did-1]/100;
913 
915  float NEWped=-1;
916  float NEWrms=-1;
917  mTables ->getPedestal(BTOW,did,0,NEWped,NEWrms);
918  ped12bit=(int) NEWped;
919 
920  operation = 1;
921  ped10[did-1] = ped12bit >> 2;
922  val12bit = ped12bit - pedestalTargetValue2005;
923  // this is by how much we want to change the ped
924 
925  if(val12bit < 0)
926  {
927  val12bit = -val12bit;
928  operation = 0;
929  }
930  int val10bit = val12bit/4;
931  if(val12bit - val10bit*4 > 2)
932  val10bit+=1;
933  if(val10bit > 15)
934  {
935  // can't subtract/add more than 15 on 10-bit level
936  val10bit = val10bit - 4*((val10bit-11)/4);
937  }
938 
939  if(operation==1)
940  {
941  adc10[did-1] -= val10bit;
942  ped10[did-1] -= val10bit;
943  }
944  else
945  {
946  adc10[did-1] += val10bit;
947  ped10[did-1] += val10bit;
948  }
949  }
950  adc08[did-1] = adc10[did-1]>>2;// adc10[],adc08[] are ped-adj
951  }
952  }
953  }
954  }
955  }
956  else
957  {
958  LOG_WARN << "StBemcTrigger::make2005Trigger() -- pointer to StEmcDetector is zero!" << endm;
959  return kStWarn;
960  }
961 
962  // making trigger patches and high towers
963  TUnixTime unixTime(mEvent->time());
964  Int_t dat=0,tim=0;
965  unixTime.GetGTime(dat,tim);
966  mDecoder->SetDateTime(dat,tim);
967  mDecoder->SetFixTowerMapBug(false);
968 
969  float rped12bit;
970  int HTmax=0;
971  int HTmaxID=-1;
972  for(int i = 0;i<kNPatches;i++)
973  if(mTrigger.PatchStatus[i]==1)
974  {
975  int crate = 0;
976  int seq = 0;
977  mDecoder->GetCrateAndSequenceFromTriggerPatch(i,crate,seq);
978  mTables->getTriggerPedestal(crate,seq,rped12bit);
979  //if (rped12bit!=0) cout<<"rped12bit="<<rped12bit<<endl;
980  int HT = 0;
981  int PA = 0;
982  int HTID = -1;
983  int id;
984  int patchPed = 0;
985  for(int j=seq;j<seq+16;j++)
986  {
987  int stat = mDecoder->GetTowerIdFromCrate(crate,j,id);
988  if(stat==1)
989  {
990  if(adc10[id-1]>=HT)
991  {
992  HT = adc10[id-1];
993  HTID = id;
994  }
995  patchPed+= (ped10[id-1]>>2);
996  PA+=adc08[id-1];
997  }
998 
999  //printf("Patch %d Ped=%d PedSum=%d ADC=%d ADCSum=%d\n",i,ped10[id-1]>>2,patchPed,adc08[id-1],PA);
1000  }
1001 
1002 
1003  // now HT=10 bits and patch=12 bits
1004  // convert patch sum to 6 bits using LUT
1005  // during 2005 LUT's looked like this:
1006  // 0,0,0,...,0,1,2,3,...,63,63,63 -- total 4096 entries
1007  // <-- ped -->
1008  // the number of 0's is equal to patchPed_12bit
1009  if(PA >= patchPed){
1010 
1011  mTrigger.Patch[i] = PA - (patchPed-1);
1012  if(mTrigger.Patch[i] > 62) mTrigger.Patch[i] = 62;
1013  }
1014  if(PA<patchPed) mTrigger.Patch[i]=1;
1015 
1016  // for HT need to OR top 2 bits and take correct bit window
1017  int SHIFT = mTrigger.HTBits;
1018  HT = HT >> SHIFT;
1019  int HTL = HT & 0x1F;
1020  int HTH = HT >> 5;
1021  int B5 = 0;
1022  if(HTH>0) B5 = 1;
1023  mTrigger.HT[i] = HTL+(B5<<5);
1024  mTrigger.HTID[i] = HTID;
1025  { LOG_DEBUG <<"Patch number "<<i<<" Tower id = "<<mTrigger.HTID[i]<<" adc12 = "<<adc12[HTID-1]
1026  <<" adc10 = "<<adc10[HTID-1]<<" adc08 = "<<adc08[HTID-1]<<" HT10 = "<<HT<<" PA12 = "<<PA
1027  <<" HT = "<<mTrigger.HT[i]<<" PA = "<<mTrigger.Patch[i]<<endm; }
1028 
1029  if (mTrigger.HT[i]>HTmax){
1030  HTmax=mTrigger.HT[i];
1031  HTmaxID=HTID;
1032  }
1033 
1034  if (mTrigger.HT[i]>HT1_TH_2005){
1035  HT1_2005_array[numHT1_2005]=HTID;
1036  numHT1_2005++;
1037  LOG_DEBUG<<HTID<<" Passed HT1 threshold="<<numHT1_2005<<" "<<HT1_2005_array[numHT1_2005-1]<<endm;
1038  }
1039 
1040  if (mTrigger.HT[i]>HT2_TH_2005){
1041  HT2_2005_array[numHT2_2005]=HTID;
1042  numHT2_2005++;
1043  LOG_DEBUG<<HTID<<" Passed HT2 threshold="<<numHT2_2005<<" "<<HT2_2005_array[numHT2_2005-1]<<endm;
1044  }
1045 
1046  }
1047 
1048  if (HTmax>HT1_TH_2005)
1049  {
1050  mIs2005HT1=1;
1051  HT1_ID_2005=HTmaxID;
1052  HT1_DSM_2005=HTmax;
1053  }
1054  else
1055  {
1056  mIs2005HT1=0;
1057  HT1_ID_2005=HTmaxID;
1058  HT1_DSM_2005=HTmax;
1059  }
1060  if (HTmax>HT2_TH_2005)
1061  {
1062  mIs2005HT2=1;
1063  HT2_ID_2005=HTmaxID;
1064  HT2_DSM_2005=HTmax;
1065  }
1066  else
1067  {
1068  mIs2005HT2=0;
1069  HT2_ID_2005=HTmaxID;
1070  HT2_DSM_2005=HTmax;
1071  }
1072 
1073  // making Jet trigger and Et
1074  int JPmax=0;
1075  int JPid=0;
1076  mTrigger.Et = 0;
1077  for(int i = 0;i<kNJet; i++)
1078  {
1079  int p0 = 0;
1080  int p1 = p0+25;
1081 
1082  mTrigger.Jet[i]= 0;
1083  for (int j=p0;j<p1;j++)
1084  {
1085  int k=JP_TP[i][j];
1086  mTrigger.Jet[i]+=mTrigger.Patch[k];
1087  }
1088 
1089  mTrigger.Et+=mTrigger.Jet[i];
1090  if (mTrigger.Jet[i]>JPmax)
1091  {
1092  JPmax=mTrigger.Jet[i];
1093  JPid=i;
1094  }
1095 
1096 
1097  if (mTrigger.Jet[i]>JP1_TH_2005)
1098  {
1099  JP1_2005_array[numJP1_2005]=i;
1100  numJP1_2005++;
1101  }
1102 
1103  if (mTrigger.Jet[i]>JP2_TH_2005)
1104  {
1105  JP2_2005_array[numJP2_2005]=i;
1106  numJP2_2005++;
1107  }
1108 
1109  }
1110 
1111  if (JPmax>JP1_TH_2005)
1112  {
1113  mIs2005JP1=1;
1114  JP1_ID_2005=JPid;
1115  JP1_DSM_2005=JPmax;
1116  }
1117  else
1118  {
1119  mIs2005JP1=0;
1120  JP1_ID_2005=JPid;
1121  JP1_DSM_2005=JPmax;
1122  }
1123 
1124  if (JPmax>JP2_TH_2005)
1125  {
1126  mIs2005JP2=1;
1127  JP2_ID_2005=JPid;
1128  JP2_DSM_2005=JPmax;
1129  }
1130  else
1131  {
1132  mIs2005JP2=0;
1133  JP2_ID_2005=JPid;
1134  JP2_DSM_2005=JPmax;
1135  }
1136 
1137 
1138  // making Jpsi trigger
1139  int JpsiPatch[kNJet];
1140  for(int i = 0;i<kNJet; i++)
1141  {
1142  int p0 = 0;
1143  int p1 = p0+25;
1144 
1145  JPSI_2005_ADC[i]=0;
1146  JPSI_2005_ID[i]=0;
1147  JpsiPatch[i]=0;
1148  for (int j=p0;j<p1;j++)
1149  {
1150  int k=JP_TP[i][j];
1151  if (mTrigger.HT[k]>JPSI_2005_ADC[i]) {
1152  JPSI_2005_ADC[i]=mTrigger.HT[k];
1153  JPSI_2005_ID[i]=mTrigger.HTID[k];
1154  }
1155  LOG_DEBUG<<"Jet id="<<i<<" Patch id="<<j<<" PatchHT="<<mTrigger.HT[k]<<" PatchHTID="<<mTrigger.HTID[k]<<" JPSI_2005_ADC="<<JPSI_2005_ADC[i]<<endm;
1156  }
1157  if (JPSI_2005_ADC[i]>JPSI_TH_2005) {
1158  JpsiPatch[i]=1;
1159  }
1160  LOG_DEBUG<<"Final JetPatchHT for JP"<<i<<" is TowID="<<JPSI_2005_ID[i]<<" with ADC= "<<JPSI_2005_ADC[i]<<" and flag="<<JpsiPatch[i]<<endm;
1161  }
1162 
1163  if ((JpsiPatch[0]&&(JpsiPatch[2]||JpsiPatch[3]||JpsiPatch[4])) ||
1164  (JpsiPatch[1]&&(JpsiPatch[3]||JpsiPatch[4]||JpsiPatch[5])) ||
1165  (JpsiPatch[2]&&(JpsiPatch[4]||JpsiPatch[5])) ||
1166  (JpsiPatch[3]&&JpsiPatch[5]) )
1167  {
1168 
1169  mIs2005JPSI=1;
1170  }
1171  else
1172  {
1173  mIs2005JPSI=0;
1174  }
1175 
1176 
1177  return kStOK;
1178 }
1179 
1180 
1181 
1182 int StBemcTrigger::get2006Trigger()
1183 {
1184 
1185 
1186  zero();
1187 
1188  //trigger matrix for 6 different settings in time
1189  const int HT0WEST_TH_2006[6]= { 5, 5, 5, 5, 5, 5};
1190  const int HT0EAST_TH_2006[6]= { 11, 11, 5, 5, 5, 5};
1191  const int HT1WEST_TH_2006[6]= { 12, 12, 16, 18, 16, 16};
1192  const int HT1EAST_TH_2006[6]= { 12, 12, 16, 18, 16, 16};
1193  const int HT2WEST_TH_2006[6]= { 22, 24, 24, 24, 24, 24};
1194  const int HT2EAST_TH_2006[6]= { 24, 24, 24, 24, 24, 24};
1195  const int HTTP0_TH_2006[6] = { 1, 1, 1, 1, 1, 1};
1196  const int HTTP1_TH_2006[6] = { 17, 17, 20, 20, 19, 19};
1197  const int HTTP2_TH_2006[6] = { 31, 31, 31, 31, 31, 31};
1198  const int JP0_TH_2006[6] = { 42, 42, 48, 49, 49, 49};
1199  const int JP1_TH_2006[6] = { 58, 58, 58, 60, 60, 60};
1200  //const int JP2_TH_2006[6] = {110,110,110,110,110,110};
1201  //const int BEMC_ETOT_2006[6] = {109,109,109,109,109,109};
1202 
1203  const int pedestalTargetValue2006 = 24;
1204 
1205 
1206 
1207  if(!mEvent)
1208  {
1209  LOG_WARN << "StBemcTrigger::make2006Trigger() -- no StEvent!" << endm;
1210  return kStWarn;
1211  }
1212 
1213  StEmcCollection *emc = mEvent->emcCollection();
1214  if(!emc)
1215  {
1216  LOG_WARN << "StBemcTrigger::make2006Trigger() -- no StEmcCollection!" << endm;
1217  return kStWarn;
1218  }
1219 
1220 
1221  int adc12[kNTowers];
1222  int adc10[kNTowers];
1223  int adc08[kNTowers];
1224  int ped10[kNTowers];
1225  for(int i = 0; i < kNTowers; ++i)
1226  {
1227 
1228  adc12[i] = 0;
1229  adc10[i] = 0;
1230  adc08[i] = 0;
1231  ped10[i] = 0;
1232  for ( int matrix=0; matrix<6; matrix++){
1233  HT2_2006_array[matrix][i] = -1;
1234  mHT22006array[matrix][i] = -1;
1235  }
1236  }
1237 
1238  for(int i = 0; i < kNJet; ++i)
1239  {
1240  for (int matrix=0;matrix<6;matrix++)
1241  {
1242  JP0_2006_array[matrix][i] = -1;
1243  JP1_2006_array[matrix][i] = -1;
1244  mJP02006array[matrix][i] = -1;
1245  mJP12006array[matrix][i] = -1;
1246  mJPSI2006adc[matrix][i] = -1;
1247  mJPSI2006id[matrix][i] = -1;
1248  }
1249  }
1250 
1251 
1252  for(int i = 0; i < kNPatches; ++i)
1253  {
1254  for (int matrix=0;matrix<6;matrix++)
1255  {
1256  BHTTP_2006_HT[matrix][i]=-1;
1257  BHTTP_2006_HT_ADC[matrix][i]=-1;
1258  BHTTP_2006_TP[matrix][i]=-1;
1259  BHTTP_2006_TP_ADC[matrix][i]=-1;
1260  }
1261  }
1262 
1263  for (int matrix=0;matrix<6;matrix++){
1264  numHT2_2006[matrix]=0;
1265  numJP0_2006[matrix]=0;
1266  numJP1_2006[matrix]=0;
1267  numHTTP_2006[matrix]=0;
1268  }
1269 
1270  int ped12bit, val12bit, operation;
1271  // operation bit for pedestal subtraction
1272  // subtract: +1 (default)
1273  // add: 0
1274 
1275  StEmcDetector* detector=emc->detector(kBarrelEmcTowerId);
1276  if(detector)
1277  {
1278 
1279  for(Int_t m = 1; m <= 120; ++m)
1280  {
1281 
1282  StEmcModule* module = detector->module(m);
1283  if(module)
1284  {
1285 
1286  StSPtrVecEmcRawHit& rawHit=module->hits();
1287  for(UInt_t k = 0; k < rawHit.size(); ++k)
1288  {
1289 
1290  if(rawHit[k])
1291  {
1292 
1293  Int_t did;
1294  Int_t mod=rawHit[k]->module();
1295  Int_t e=rawHit[k]->eta();
1296  Int_t s=abs(rawHit[k]->sub());
1297  mGeo->getId(mod,e,s,did);
1298 
1299  if ((mTrigger.TowerStatus[did-1]==1)&&(mTables->status(BTOW,did,"calib")==1))
1300  {
1301 
1302  adc12[did-1]=rawHit[k]->adc();
1303  adc10[did-1] = adc12[did-1]>>2;
1304 
1305  float NEWped=-1;
1306  float NEWrms=-1;
1307  mTables ->getPedestal(BTOW,did,0,NEWped,NEWrms);
1308  ped12bit=(int) NEWped;
1309 
1310  operation = 1;
1311  ped10[did-1] = ped12bit >> 2;
1312  val12bit = ped12bit - pedestalTargetValue2006;
1313 
1314  if(val12bit < 0)
1315  {
1316  val12bit = -val12bit;
1317  operation = 0;
1318  }
1319 
1320  int val10bit = val12bit/4;
1321  if(val12bit - val10bit*4 > 2) val10bit+=1;
1322 
1323  if(val10bit > 15)
1324  {
1325  // can't subtract/add more than 15 on 10-bit level
1326  val10bit = val10bit - 4*((val10bit-11)/4);
1327  }
1328 
1329  if(operation==1)
1330  {
1331  adc10[did-1] -= val10bit;
1332  ped10[did-1] -= val10bit;
1333  }
1334  else
1335  {
1336  adc10[did-1] += val10bit;
1337  ped10[did-1] += val10bit;
1338  }
1339 
1340  adc08[did-1] = adc10[did-1]>>2;// adc10[],adc08[] are pedestal-adjusted
1341 
1342  }
1343 
1344  }
1345 
1346  }
1347 
1348  }
1349 
1350  }
1351 
1352  }
1353  else
1354  {
1355  LOG_WARN << "StBemcTrigger::make2006Trigger() -- pointer to StEmcDetector is zero!" << endm;
1356  return kStWarn;
1357  }
1358 
1359  // making trigger patches and high towers
1360  TUnixTime unixTime(mEvent->time());
1361  Int_t dat=0,tim=0;
1362  unixTime.GetGTime(dat,tim);
1363  mDecoder->SetDateTime(dat,tim);
1364  mDecoder->SetFixTowerMapBug(false);
1365 
1366  float rped12bit;
1367  int HTmax=0;
1368  int HTmaxID=-1;
1369 
1370  for(int i = 0; i < kNPatches; ++i)
1371  {
1372 
1373  if(mTrigger.PatchStatus[i]==1)
1374  {
1375 
1376  int crate = 0;
1377  int seq = 0;
1378  int HT = 0;
1379  int PA = 0;
1380  int HTID = -1;
1381  int id;
1382  int patchPed = 0;
1383 
1384  mDecoder->GetCrateAndSequenceFromTriggerPatch(i,crate,seq);
1385  mTables->getTriggerPedestal(crate,seq,rped12bit);
1386 
1387  //loop over each tower(j) in the trigger patch (i)
1388  for(int j = seq; j < seq + 16; ++j)
1389  {
1390 
1391  int stat = mDecoder->GetTowerIdFromCrate(crate,j,id);
1392  if(stat == 1)
1393  {
1394 
1395  if(adc10[id-1]>=HT)
1396  {
1397  HT = adc10[id-1];
1398  HTID = id;
1399  }
1400 
1401  patchPed += ped10[id-1] >> 2;
1402  PA += adc08[id-1];
1403  }
1404 
1405  }
1406 
1407  // now HT=10 bits and patch=12 bits
1408  // convert patch sum to 6 bits using LUT
1409  // during 2006 LUT's looked like this:
1410  // 0,0,0,...,0,1,2,3,...,63,63,63 -- total 4096 entries
1411  // <-- ped -->
1412  // the number of 0's is equal to patchPed_12bit
1413  if(PA >= patchPed)
1414  {
1415 
1416  mTrigger.Patch[i] = PA - (patchPed - 1);
1417  if(mTrigger.Patch[i] > 62) mTrigger.Patch[i] = 62;
1418  }
1419  else
1420  {
1421  mTrigger.Patch[i] = 1;
1422  }
1423 
1424  // for HT need to:
1425  //1) drop lowest bits (depends on calibration)
1426  //2) take next 6 LSB as HT 6 bit adc
1427  //3) if 6 or higher bit ==1 need to set all bits high (63)
1428  HT = HT >>(mTrigger.HTBits - 1);
1429  int HTL = HT & 0x1F;//5 LSB
1430  int HTH = HT >> 5; //>= 6 LSB
1431  int B5 = 0;
1432  if(HTH>0) B5 = 1;
1433  mTrigger.HT[i] = HTL+(B5<<5);
1434  mTrigger.HTID[i] = HTID;
1435 
1436  {
1437  LOG_DEBUG <<"Patch number "<<i<<" Tower id = "<<mTrigger.HTID[i]<<" adc12 = "<<adc12[HTID-1]
1438  <<" adc10 = "<<adc10[HTID-1]<<" adc08 = "<<adc08[HTID-1]<<" HT10 = "<<HT<<" PA12 = "<<PA
1439  <<" HT = "<<mTrigger.HT[i]<<" PA = "<<mTrigger.Patch[i]<<endm;
1440  }
1441 
1442  if(mTrigger.HT[i]>HTmax)
1443  {
1444  HTmax=mTrigger.HT[i];
1445  HTmaxID=HTID;
1446  }
1447 
1448  for (int matrix=0; matrix<6; matrix++){
1449 
1450  if (HTID>2400) {//East
1451  if(mTrigger.HT[i]>HT2EAST_TH_2006[matrix])
1452  {
1453  HT2_2006_array[matrix][numHT2_2006[matrix]]=HTID;
1454  numHT2_2006[matrix]++;
1455  }
1456  }
1457 
1458  if (HTID<=2400) {//West
1459  if(mTrigger.HT[i]>HT2WEST_TH_2006[matrix])
1460  {
1461  HT2_2006_array[matrix][numHT2_2006[matrix]]=HTID;
1462  numHT2_2006[matrix]++;
1463  }
1464  }
1465  }
1466  }
1467  }
1468 
1469  //making HT trigger
1470  for (int matrix=0; matrix<6; matrix++){
1471 
1472  if (HTmaxID>2400){//East
1473  if (HTmax > HT2EAST_TH_2006[matrix])
1474  {
1475  mIs2006HT2[matrix]=1;
1476  HT2_ID_2006[matrix]=HTmaxID;
1477  HT2_DSM_2006[matrix]=HTmax;
1478  }
1479  else
1480  {
1481  mIs2006HT2[matrix]=0;
1482  HT2_ID_2006[matrix]=HTmaxID;
1483  HT2_DSM_2006[matrix]=HTmax;
1484  }
1485  }
1486 
1487  if (HTmaxID<=2400){//West
1488  if (HTmax > HT2WEST_TH_2006[matrix])
1489  {
1490  mIs2006HT2[matrix]=1;
1491  HT2_ID_2006[matrix]=HTmaxID;
1492  HT2_DSM_2006[matrix]=HTmax;
1493  }
1494  else
1495  {
1496  mIs2006HT2[matrix]=0;
1497  HT2_ID_2006[matrix]=HTmaxID;
1498  HT2_DSM_2006[matrix]=HTmax;
1499  }
1500  }
1501  }
1502 
1503  // making HTTP trigger
1504  int BHTTPcounter[6];
1505  for ( int matrix=0; matrix<6; matrix++){
1506 
1507  mIs2006BHTTP[matrix]=0;
1508  BHTTPcounter[matrix]=0;
1509 
1510  for(int i = 0; i < kNPatches; ++i)
1511  {
1512 
1513  int HTBIT = -1;
1514  int TPBIT = -1;
1515 
1516  if (kNPatches < 150){ //West
1517  if (mTrigger.HT[i] < HT0WEST_TH_2006[matrix]) HTBIT = 0;
1518  if (mTrigger.HT[i] > HT0WEST_TH_2006[matrix]) HTBIT = 1;
1519  if (mTrigger.HT[i] > HT1WEST_TH_2006[matrix]) HTBIT = 2;
1520  if (mTrigger.HT[i] > HT2WEST_TH_2006[matrix]) HTBIT = 3;
1521  }
1522 
1523  if (kNPatches >= 150){//East
1524  if (mTrigger.HT[i] < HT0EAST_TH_2006[matrix]) HTBIT = 0;
1525  if (mTrigger.HT[i] > HT0EAST_TH_2006[matrix]) HTBIT = 1;
1526  if (mTrigger.HT[i] > HT1EAST_TH_2006[matrix]) HTBIT = 2;
1527  if (mTrigger.HT[i] > HT2EAST_TH_2006[matrix]) HTBIT = 3;
1528  }
1529 
1530  if (mTrigger.Patch[i] < HTTP0_TH_2006[matrix]) TPBIT = 0;
1531  if (mTrigger.Patch[i] > HTTP0_TH_2006[matrix]) TPBIT = 1;
1532  if (mTrigger.Patch[i] > HTTP1_TH_2006[matrix]) TPBIT = 2;
1533  if (mTrigger.Patch[i] > HTTP2_TH_2006[matrix]) TPBIT = 3;
1534 
1535  if( TPBIT >= 2 && HTBIT >= 2)
1536  {
1537  mIs2006BHTTP[matrix] = 1;
1538  BHTTP_2006_TP[matrix][BHTTPcounter[matrix]] = i;
1539  BHTTP_2006_TP_ADC[matrix][BHTTPcounter[matrix]] = mTrigger.Patch[i];
1540  BHTTP_2006_HT[matrix][BHTTPcounter[matrix]] = mTrigger.HTID[i];
1541  BHTTP_2006_HT_ADC[matrix][BHTTPcounter[matrix]] = mTrigger.HT[i];
1542  BHTTPcounter[matrix]++;
1543  }
1544  }
1545  numHTTP_2006[matrix]=BHTTPcounter[matrix];
1546  }
1547 
1548 
1549  // Clear jet patch variables
1550  int JPmax = 0;
1551  int JPid = 0;
1552 
1553  for(int i = 0; i < kNJet; ++i)
1554  {
1555 
1556  mTrigger.Jet[i] = 0;
1557 
1558  for(int sequence = 0; sequence < kN_sequences; ++sequence)
1559  {
1560 
1561  int k = 0;
1562  mDecoder->GetTriggerPatchFromJetPatch(i, sequence, k);
1563  mTrigger.Jet[i] += mTrigger.Patch[k];
1564 
1565  }
1566 
1567  }
1568 
1569  // Check jet patch triggers
1570  for(int i = 0; i < kNJet; ++i)
1571  {
1572 
1573  if(mTrigger.Jet[i] > JPmax)
1574  {
1575  JPmax = mTrigger.Jet[i];
1576  JPid = i;
1577  }
1578 
1579  for (int matrix=0;matrix<6;matrix++){
1580 
1581  if(mTrigger.Jet[i] > JP0_TH_2006[matrix])
1582  {
1583  JP0_2006_array[matrix][numJP0_2006[matrix]] = i;
1584  ++numJP0_2006[matrix];
1585  }
1586 
1587  if(mTrigger.Jet[i] > JP1_TH_2006[matrix])
1588  {
1589  JP1_2006_array[matrix][numJP1_2006[matrix]] = i;
1590  ++numJP1_2006[matrix];
1591  }
1592  }
1593  }
1594 
1595 
1596  for (int matrix=0;matrix<6;matrix++){
1597 
1598  if(JPmax > JP0_TH_2006[matrix])
1599  {
1600  mIs2006JP0[matrix]=1;
1601  JP0_ID_2006[matrix]=JPid;
1602  JP0_DSM_2006[matrix]=JPmax;
1603  }
1604  else
1605  {
1606  mIs2006JP0[matrix]=0;
1607  JP0_ID_2006[matrix]=JPid;
1608  JP0_DSM_2006[matrix]=JPmax;
1609  }
1610 
1611  if(JPmax > JP1_TH_2006[matrix])
1612  {
1613  mIs2006JP1[matrix]=1;
1614  JP1_ID_2006[matrix]=JPid;
1615  JP1_DSM_2006[matrix]=JPmax;
1616  }
1617  else
1618  {
1619  mIs2006JP1[matrix]=0;
1620  JP1_ID_2006[matrix]=JPid;
1621  JP1_DSM_2006[matrix]=JPmax;
1622  }
1623  }
1624 
1625  //making ETOT trigger
1626  //combine 2 JP to form 13 bit adc
1627  //drop 2 LSB
1628  //check if bit 6 or higher == 1
1629  mTrigger.Et = 0;
1630  int EtotSum[6];
1631  for(int i = 0; i < 6; ++i)
1632  {
1633 
1634  EtotSum[i] = 0;
1635  BL1_ADC_2006[i] = 0;
1636  Int_t j = 2*i;
1637  Int_t TempSum = 0;
1638  TempSum = mTrigger.Jet[j] + mTrigger.Jet[j+1];
1639  EtotSum[i]=TempSum >> 2;
1640  if (EtotSum[i]>31) EtotSum[i]=31;
1641  mTrigger.Et += EtotSum[i];
1642  BL1_ADC_2006[i] = EtotSum[i];
1643 
1644  }
1645  BETOT_DSM_2006=mTrigger.Et;
1646 
1647  //
1648  // Making Jpsi trigger
1649  // See http://www.star.bnl.gov/STAR/html/trg_l/TSL/Software/EMC.pdf
1650  //
1651  int JpsiPatch[6][kNJet];
1652  for (int matrix=0;matrix<6;matrix++)
1653  {
1654  for(int i = 0; i < kNJet; ++i)
1655  {
1656 
1657  JPSI_2006_ADC[matrix][i]=0;
1658  JPSI_2006_ID[matrix][i]=0;
1659  JpsiPatch[matrix][i]=0;
1660 
1661  for(int sequence = 0; sequence < kN_sequences; ++sequence)
1662  {
1663 
1664  int k = 0;
1665  mDecoder->GetTriggerPatchFromJetPatch(i, sequence, k);
1666  if(mTrigger.HT[k] > JPSI_2006_ADC[matrix][i])
1667 
1668  {
1669  JPSI_2006_ADC[matrix][i]=mTrigger.HT[k];
1670  JPSI_2006_ID[matrix][i]=mTrigger.HTID[k];
1671  }
1672  }
1673 
1674  if(i < 6)
1675  {
1676  // BEMC West
1677  if(JPSI_2006_ADC[matrix][i] > HT0WEST_TH_2006[matrix]) JpsiPatch[matrix][i] = 1;
1678  }
1679  else
1680  {
1681  // BEMC East
1682  if(JPSI_2006_ADC[matrix][i] > HT0EAST_TH_2006[matrix]) JpsiPatch[matrix][i] = 1;
1683  }
1684 
1685  }
1686 
1687 
1688 
1689  // The J/psi trigger fires if two opposite jet patches have high towers
1690  // above selected thresholds.
1691  // Follow convention in the DSM implementation where vector bits (0-5)
1692  // correspond to positions 2,4,6,8,10,12 o'clock.
1693 
1694 
1695  int ht_jpsi[6]={0,0,0,0,0,0};
1696 
1697  ht_jpsi[4] = JpsiPatch[matrix][0] || JpsiPatch[matrix][6];
1698  ht_jpsi[5] = JpsiPatch[matrix][1] || JpsiPatch[matrix][7];
1699  ht_jpsi[0] = JpsiPatch[matrix][2] || JpsiPatch[matrix][8];
1700  ht_jpsi[1] = JpsiPatch[matrix][3] || JpsiPatch[matrix][9];
1701  ht_jpsi[2] = JpsiPatch[matrix][4] || JpsiPatch[matrix][10];
1702  ht_jpsi[3] = JpsiPatch[matrix][5] || JpsiPatch[matrix][11];
1703 
1704  mIs2006JPSI[matrix] = ((ht_jpsi[0] && (ht_jpsi[2] || ht_jpsi[3] || ht_jpsi[4])) ||
1705  (ht_jpsi[1] && (ht_jpsi[3] || ht_jpsi[4] || ht_jpsi[5])) ||
1706  (ht_jpsi[2] && (ht_jpsi[4] || ht_jpsi[5])) || (ht_jpsi[3] && ht_jpsi[5]));
1707 
1708  }
1709 
1710  return kStOK;
1711 }
int status(int det, int softId, const char *option="") const
int GetTriggerPatchFromJetPatch(int jetPatch, int sequence, int &patchId) const
returns the trigger patch from big jet patch and the sequence in it
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
int GetTowerIdFromCrate(int crate, int sequence, int &softId) const
Get Software Id from Crate number and position in crate for towers.
int GetCrateAndSequenceFromTriggerPatch(int patchId, int &crate, int &sequence) const
returns the crate number and start point for a given trigger patch
Definition: Stypes.h:42
Definition: Stypes.h:40
void getTriggerPedestal(Int_t crate, Int_t index, Float_t &pedestal) const
Return tower pedestal loaded in trigger.
void SetFixTowerMapBug(bool fix)
Sets the tower map bug fix.