StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPicoMtdTrigger.cxx
1 //
2 // StPicoMtdTrigger stores trigger information related to MTD
3 //
4 
5 // C++ headers
6 #include <bitset>
7 #include <math.h>
8 
9 // PicoDst headers
10 #include "StPicoMessMgr.h"
11 #include "StPicoMtdTrigger.h"
12 
13 ClassImp(StPicoMtdTrigger)
14 
15 //_________________
17  mVpdTacSum(0), mTHUBtime{},
18  mQTtacSum{}, mMT101Tac{}, mMT101Id{}, mTF201TriggerBit(0),
19  mShouldHaveRejectEvent(-1) {
20  /* empty */
21 }
22 
23 //_________________
24 void StPicoMtdTrigger::setQTtacSum(Int_t runnumber, UShort_t mtdQTadc[8][16],
25  UShort_t mtdQTtac[8][16], const int QTtoModule[8][8],
26  const Int_t QTSlewBinEdge[8][16][8],
27  const Int_t QTSlewCorr[8][16][8]) {
28 
29  // Obtain RHIC run year
30  int year = runnumber / 1e6 + 1999;
31  // Oct. 1st (approx. 273rd day) is the start of a new running year
32  if ((runnumber % 1000000) / 1000 >= 273) year += 1;
33 
34  // QT Tac cuts
35  UShort_t mtd_qt_tac_min = 100;
36  if (runnumber >= 16045067) mtd_qt_tac_min = 80;
37  if (runnumber >= 18070005) mtd_qt_tac_min = 200; // change due to new boards
38  UShort_t mtd_qt_tac_diff_range_abs = 600;
39  if (year == 2015) mtd_qt_tac_diff_range_abs = 1023;
40 
41  Int_t j[2] = {0, 0};
42  Int_t a[2] = {0, 0};
43  for (Int_t im = 0; im < kNQTboard; im++) {
44  for (Int_t i = 0; i < 8; i++) {
45  if (year == 2016 && i % 2 == 0) { // moniter channel only used for Run16
46  mQTtacSum[im][i] = 0;
47  continue;
48  }
49 
50  // Apply slewing correction
51  for (Int_t k=0; k<2; k++) {
52  j[k] = mtdQTtac[im][i*2+k];
53  a[k] = mtdQTadc[im][i*2+k];
54 
55  Int_t slew_bin = -1;
56  if (a[k]>0 && a[k]<=QTSlewBinEdge[im][i*2+k][0]) {
57  slew_bin = 0;
58  }
59  else {
60  for (Int_t l=1; l<8; l++) {
61  if (a[k] > QTSlewBinEdge[im][i*2+k][l-1] && a[k]<=QTSlewBinEdge[im][i*2+k][l]) {
62  slew_bin = l;
63  break;
64  }
65  } //for (int l=1; l<8; l++)
66  } //else
67  if (slew_bin >= 0) {
68  j[k] += QTSlewCorr[im][i * 2 + k][slew_bin];
69  }
70  } //for (int k = 0; k < 2; k++)
71 
72  if (j[0] <= mtd_qt_tac_min || j[0] >= mtd_qt_tac_max ||
73  j[1] <= mtd_qt_tac_min || j[1] >= mtd_qt_tac_max ||
74  ::abs(j[0] - j[1]) >= mtd_qt_tac_diff_range_abs) { // no "equal" in online algorithm
75  mQTtacSum[im][i] = 0;
76  continue;
77  }
78 
79  // Apply position correction
80  Int_t module = QTtoModule[im][i];
81  if(module<0) {
82  mQTtacSum[im][i] = 0;
83  continue;
84  }
85  mQTtacSum[im][i] = UShort_t( j[0] + j[1] + abs(module-3)*1./8 * (j[0]-j[1]) );
86  } //for (int i = 0; i < 8; i++)
87  } //for (Int_t im = 0; im < kNQTboard; im++)
88 }
89 
90 //_________________
91 void StPicoMtdTrigger::setMT101(UShort_t mt101Tac[8][2], UShort_t mt101Id[8][2]) {
92  // MT101
93  for (Int_t i = 0; i < kNQTboard; i++) {
94  for(Int_t j = 0; j < 2; j++) {
95  mMT101Tac[i][j] = mt101Tac[i][j];
96  mMT101Id[i][j] = mt101Id[i][j];
97  }
98  }
99 }
100 
101 //_________________
102 void StPicoMtdTrigger::setTF201TriggerBit(Int_t year, UInt_t dsmBit1, UInt_t dsmBit2)
103 {
104  // TF201
105  UInt_t decision = dsmBit1;
106  UInt_t decision2 = dsmBit2;
107  mTF201TriggerBit = 0;
108 
109  for (Int_t i = 0; i < 4; i++) {
110  for (Int_t j = 0; j < 2; j++) {
111  if (year == 2016) {
112  int qt = i * 2;
113  mTF201TriggerBit |= ((decision >> (i * 2 + j + 4)) & 0x1) << (qt * 2 + j);
114  qt = i * 2 + 1;
115  mTF201TriggerBit |= ((decision2 >> (i * 2 + j + 4)) & 0x1) << (qt * 2 + j);
116  }
117  else {
118  int qt = i;
119  mTF201TriggerBit |= ((decision >> (i * 2 + j + 4)) & 0x1) << (qt * 2 + j);
120  }
121  } //for (Int_t j = 0; j < 2; j++)
122  } //for (Int_t i = 0; i < 4; i++)
123 
124  LOG_DEBUG << "input1 = " << (std::bitset<16>) decision << "\n"
125  << "input2 = " << (std::bitset<16>) decision2 << "\n"
126  << "output = " << (std::bitset<16>) mTF201TriggerBit
127  << endm;
128 }
129 
130 //_________________
132  mVpdTacSum = trigger.mVpdTacSum;
133  for(Int_t iIter=0; iIter<2; iIter++) {
134  mTHUBtime[iIter] = trigger.mTHUBtime[iIter];
135  }
136 
137  for(UShort_t iQTboard=0; iQTboard<kNQTboard; iQTboard++) {
138 
139  for(UShort_t iIter=0; iIter<8; iIter++) {
140  mQTtacSum[iQTboard][iIter] = trigger.mQTtacSum[iQTboard][iIter];
141  } //for(UShort_t iIter=0; iIter<8; iIter++)
142 
143  for(UShort_t iIter=0; iIter<2; iIter++) {
144  mMT101Tac[iQTboard][iIter] = trigger.mMT101Tac[iQTboard][iIter];
145  mMT101Id[iQTboard][iIter] = trigger.mMT101Id[iQTboard][iIter];
146  } //for(UShort_t iIter=0; iIter<2; iIter++)
147  } //for(UShort_t iQTboard=0; iQTBoard<kNQTboard; iQTboard++)
148 
149  mTF201TriggerBit = trigger.mTF201TriggerBit;
150  mShouldHaveRejectEvent = trigger.mShouldHaveRejectEvent;
151 }
152 
153 //_________________
155  /* empty */
156 }
157 
158 //_________________
159 void StPicoMtdTrigger::getMaximumQTtac(const Int_t qt, Int_t& pos1, Int_t& pos2) {
160 
161  pos1 = 0;
162  pos2 = 0;
163 
164  if (qt < 1 || qt > kNQTboard) {
165  LOG_ERROR << "Wrong qt board number: " << qt << endm;
166  return;
167  }
168 
169  UShort_t max1 = 0, max2 = 0;
170  for (Int_t i = 0; i < 8; i++) {
171  if (max1 < mQTtacSum[qt - 1][i]) {
172  max2 = max1;
173  pos2 = pos1;
174  max1 = mQTtacSum[qt - 1][i];
175  pos1 = i + 1;
176  }
177  else if (max2 < mQTtacSum[qt - 1][i]) {
178  max2 = mQTtacSum[qt - 1][i];
179  pos2 = i + 1;
180  }
181  } //for (Int_t i = 0; i < 8; i++)
182 }
183 
184 //_________________
185 void StPicoMtdTrigger::Print(const Char_t *option __attribute__((unused)) ) const {
186  LOG_INFO << " VPD TAC sum: " << mVpdTacSum
187  << " THUB time ( " << mTHUBtime[0] << " , " << mTHUBtime[1] << " )" << endm;
188  LOG_INFO << "TCU trigger bit: " << mTF201TriggerBit
189  << " Should have reject event: " << mShouldHaveRejectEvent
190  << endm;
191 }
virtual void Print(const Char_t *option="") const
Print MTD trigger information.
Class storing MTD trigger information including VPD, QT, MT101, TF201.
void setQTtacSum(Int_t runnumber, UShort_t mtdQTadc[8][16], UShort_t mtdQTtac[8][16], const Int_t QTtoModule[8][8], const Int_t QTSlewBinEdge[8][16][8], const Int_t QTSlewCorr[8][16][8])
Set TAC sum (j2+j3) for each position in each QT board.
StPicoMtdTrigger()
Default constructor.
void getMaximumQTtac(const Int_t qt, Int_t &pos1, Int_t &pos2)
virtual ~StPicoMtdTrigger()
Destructor.
void setMT101(UShort_t mt101Tac[8][2], UShort_t mt101Id[8][2])
Set two largest TACsum for all QT boards.
void setTF201TriggerBit(Int_t year, UInt_t dsmBit1, UInt_t dsmBit2)
Set trigger bit in TCU that used for online trigger.