StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSortTofRawData.cxx
1 #include <iostream>
2 #include "StMessMgr.h"
3 #include "StSortTofRawData.h"
4 #include "StEvent.h"
5 #include "StTofCollection.h"
6 #include "StTofRawData.h"
7 #include "StTofrDaqMap.h"
8 
9 StSortTofRawData::StSortTofRawData() {
10  Reset();
11 }
12 
16 StSortTofRawData::StSortTofRawData(StTofCollection *tofColl) {
17  Reset();
18  Init(tofColl);
19 }
23 StSortTofRawData::StSortTofRawData(StTofCollection *tofColl, StTofrDaqMap *daqMap) {
24  Reset();
25  SetVPDMap(daqMap);
26  InitRun8(tofColl);
27 }
28 
29 StSortTofRawData::~StSortTofRawData() {
30  Reset();
31 }
32 
33 void StSortTofRawData::Reset() {
34  for(unsigned int i=0;i<mNTRAY;i++) mRawHitVec[i].clear();
35 }
36 
38  if(tofColl && tofColl->rawdataPresent()) {
39  StSPtrVecTofRawData &tofRawData = tofColl->tofRawData();
40  for(size_t i=0; i<tofRawData.size(); i++) {
41  if(tofRawData[i]->leteFlag()!=1) continue; // leading
42  // int itray = tofRawData[i]->tray(); /// tray() is not available in Run V
43  int itray = 93;
44  int ichan = tofRawData[i]->channel();
45  bool iexist = kFALSE;
46  for(size_t ii=0; ii<mRawHitVec[0].size(); ii++) {
47  if(itray==mRawHitVec[itray-1][ii].tray && ichan==mRawHitVec[itray-1][ii].channel) {
48  iexist = kTRUE;
49  break;
50  }
51  }
52  if(iexist) continue;
53  TOFRawHit aRawHit;
54  aRawHit.tray = itray;
55  aRawHit.channel = ichan;
56  aRawHit.leadingTdc.push_back((int)(tofRawData[i]->tdc()));
57  for(size_t j=i+1;j<tofRawData.size();j++) {
58  if(tofRawData[j]->leteFlag()==1 &&
59  itray==93 && ichan==tofRawData[j]->channel()) {
60  aRawHit.leadingTdc.push_back((int)(tofRawData[j]->tdc()));
61  }
62  }
63 
64  // trailing
65  for(size_t j=0;j<tofRawData.size();j++) {
66  if(tofRawData[j]->leteFlag()==2 &&
67  itray==93 && ichan==tofRawData[j]->channel()) {
68  aRawHit.trailingTdc.push_back((int)(tofRawData[j]->tdc()));
69  }
70  }
71  if(aRawHit.trailingTdc.size()) mRawHitVec[itray-1].push_back(aRawHit);
72  }
73  } else {
74  gMessMgr->Warning("","OS") << " No Tof Collection !!! " << endm;
75  }
76 }
77 
78 void StSortTofRawData::InitRun8(StTofCollection *tofColl) {
79  if(tofColl && tofColl->rawdataPresent()) {
80 
81  //--added by Zebo
82  //initial time windows
83  for(unsigned int i=0;i<mNTRAY;i++){
84  for(int j=0;j<2;j++) mTimeWindow[i][j] = 0.;
85  if(i>=75&&i<80){
86  mTimeWindow[i][0] = 3270;
87  mTimeWindow[i][1] = 3390;
88  }
89  if(i==120){
90  mTimeWindow[i][0] = 3230;
91  mTimeWindow[i][1] = 3340;
92  }
93  if(i==121){
94  mTimeWindow[i][0] = 3290;
95  mTimeWindow[i][1] = 3400;
96  }
97  }
98  //--end
99  StSPtrVecTofRawData &tofRawData = tofColl->tofRawData();
100  for(size_t i=0; i<tofRawData.size(); i++) {
101  if(tofRawData[i]->leteFlag()!=1) continue; // leading
102  int itray = tofRawData[i]->tray();
103  int ichan = tofRawData[i]->channel();
104  bool iexist = kFALSE;
105  for(size_t ii=0; ii<mRawHitVec[itray-1].size(); ii++) {
106  if(itray==mRawHitVec[itray-1][ii].tray && ichan==mRawHitVec[itray-1][ii].channel) {
107  iexist = kTRUE;
108  break;
109  }
110  }
111  if(iexist) continue;
112  TOFRawHit aRawHit;
113  aRawHit.tray = itray;
114  aRawHit.channel = ichan;
115  aRawHit.triggertime = tofRawData[i]->triggertime();
116  aRawHit.leadingTdc.push_back((int)(tofRawData[i]->tdc()));
117  for(size_t j=i+1;j<tofRawData.size();j++) {
118  if(tofRawData[j]->leteFlag()==1 &&
119  itray==tofRawData[j]->tray() && ichan==tofRawData[j]->channel()) {
120  aRawHit.leadingTdc.push_back((int)(tofRawData[j]->tdc()));
121  }
122  }
123 
124  // trailing
125  if(itray<=120) { // trays
126  for(size_t j=0;j<tofRawData.size();j++) {
127  if(tofRawData[j]->leteFlag()==2 &&
128  itray==tofRawData[j]->tray() && ichan==tofRawData[j]->channel()) {
129  aRawHit.trailingTdc.push_back((int)(tofRawData[j]->tdc()));
130  }
131  }
132  } else {
133  int iTube = (itray==121) ? mTDIGLeChan2WestPMT[ichan] : mTDIGLeChan2EastPMT[ichan];
134  for(size_t j=0;j<tofRawData.size();j++) {
135  if(tofRawData[j]->leteFlag()==2 && itray== tofRawData[j]->tray()) {
136  int jTube = (itray==121) ? mTDIGTeChan2WestPMT[tofRawData[j]->channel()] : mTDIGTeChan2EastPMT[tofRawData[j]->channel()];
137  if(iTube==jTube) {
138  aRawHit.trailingTdc.push_back((int)(tofRawData[j]->tdc()));
139  }
140  }
141  }
142  }
143  if(aRawHit.trailingTdc.size()) mRawHitVec[itray-1].push_back(aRawHit);
144  }
145  } else {
146  gMessMgr->Warning("","OS") << " No Tof Collection !!! " << endm;
147  }
148 }
149 
150 IntVec StSortTofRawData::GetValidChannel() {
151  IntVec chanVec;
152  for(size_t k=0 ; k<mNTRAY; k++){
153  for(size_t i=0 ; i<mRawHitVec[k].size() ; i++) {
154  chanVec.push_back(mRawHitVec[k][i].channel);
155  }
156  }
157  return chanVec;
158 }
159 
160 IntVec StSortTofRawData::GetLeadingTdc(int channel) {
161  IntVec leTdc;
162  for(size_t k=0 ; k<mNTRAY; k++){
163  for(size_t i=0 ; i<mRawHitVec[k].size() ; i++) {
164  if(mRawHitVec[k][i].channel!=channel) continue;
165  leTdc = mRawHitVec[k][i].leadingTdc;
166  }
167  }
168  return leTdc;
169 }
170 
171 IntVec StSortTofRawData::GetTrailingTdc(int channel) {
172  IntVec teTdc;
173  for(size_t k=0 ; k<mNTRAY; k++){
174  for(size_t i=0 ; i<mRawHitVec[k].size() ; i++) {
175  if(mRawHitVec[k][i].channel!=channel) continue;
176  teTdc = mRawHitVec[k][i].trailingTdc;
177  }
178  }
179  return teTdc;
180 }
181 
182 IntVec StSortTofRawData::GetValidChannel(int tray) {
183  IntVec chanVec;
184  for(size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
185  if( mRawHitVec[tray-1][i].tray == tray )
186  chanVec.push_back(mRawHitVec[tray-1][i].channel);
187  }
188  return chanVec;
189 }
190 
191 IntVec StSortTofRawData::GetLeadingTdc(int tray, int channel)
192 {
193  IntVec leTdc;
194  for(size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
195  if(mRawHitVec[tray-1][i].tray!=tray) continue;
196  if(mRawHitVec[tray-1][i].channel!=channel) continue;
197  leTdc = mRawHitVec[tray-1][i].leadingTdc;
198  }
199  return leTdc;
200 }
201 
202 IntVec StSortTofRawData::GetLeadingTdc(int tray, int channel, bool triggerevent)
203 {
204  IntVec leTdc;
205  for(size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
206  if(mRawHitVec[tray-1][i].tray!=tray) continue;
207  if(mRawHitVec[tray-1][i].channel!=channel) continue;
208  double ftime = -1e5;
209  for(size_t j=0; j<mRawHitVec[tray-1][i].leadingTdc.size(); j++) {
210  float trgTime = 25.*(mRawHitVec[tray-1][i].triggertime & 0xfff) - 2775.;
211  float timeDiff = mRawHitVec[tray-1][i].leadingTdc[j]*25./1024 - trgTime;
212  while(timeDiff<0) timeDiff += 51200;
213  if(tray<=120){ //trays, keep all hits
214  if(triggerevent){
215  if(timeDiff>=mTimeWindow[tray-1][0]&&timeDiff<=mTimeWindow[tray-1][1])
216  leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
217  }
218  else {
219  leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
220  }
221  }
222  else {
223  if(triggerevent){ //vpds, keep physical hits in trigger window
224  double stime = timeDiff;
225  if(stime > ftime+300.){ //all hits thereafter within 300ns are not physical
226  if(timeDiff>=mTimeWindow[tray-1][0]&&timeDiff<=mTimeWindow[tray-1][1])
227  leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
228  ftime = stime;
229  }
230  }
231  else {
232  leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
233  }
234  }
235  }
236  }
237  return leTdc;
238 }
239 
240 IntVec StSortTofRawData::GetTrailingTdc(int tray, int channel) {
241  IntVec teTdc;
242  for(size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
243  if(mRawHitVec[tray-1][i].tray!=tray) continue;
244  if(mRawHitVec[tray-1][i].channel!=channel) continue;
245  teTdc = mRawHitVec[tray-1][i].trailingTdc;
246  }
247  return teTdc;
248 }
249 
250 IntVec StSortTofRawData::GetTrailingTdc(int tray, int channel, bool triggerevent)
251 {
252  IntVec teTdc;
253  for(size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
254  if(mRawHitVec[tray-1][i].tray!=tray) continue;
255  if(mRawHitVec[tray-1][i].channel!=channel) continue;
256  double ftime = -1e5;
257  for(size_t j=0; j<mRawHitVec[tray-1][i].trailingTdc.size(); j++) {
258  float trgTime = 25.*(mRawHitVec[tray-1][i].triggertime & 0xfff) - 2775.;
259  float timeDiff = mRawHitVec[tray-1][i].trailingTdc[j]*25./1024 - trgTime;
260  while(timeDiff<0) timeDiff += 51200;
261  if(tray<=120){ //trays, keep all hits
262  if(triggerevent){
263  if(timeDiff>=mTimeWindow[tray-1][0]&&timeDiff<=mTimeWindow[tray-1][1])
264  teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
265  }
266  else {
267  teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
268  }
269  }
270  else {
271  if(triggerevent){ //vpds, keep physical hits in trigger window
272  double stime = timeDiff;
273  if(stime > ftime+300.){ //all hits thereafter within 300ns are not physical
274  if(timeDiff>=mTimeWindow[tray-1][0]&&timeDiff<=mTimeWindow[tray-1][1])
275  teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
276  ftime = stime;
277  }
278  }
279  else {
280  teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
281  }
282  }
283  }
284  }
285  return teTdc;
286 }
287 
288 Int_t StSortTofRawData::GetTriggerTime(int tray, int channel) {
289  Int_t triggertime;
290  for(size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
291  if(mRawHitVec[tray-1][i].tray!=tray) continue;
292  if(mRawHitVec[tray-1][i].channel!=channel) continue;
293  triggertime = mRawHitVec[tray-1][i].triggertime;
294  }
295  return triggertime;
296 }
297 
298 void StSortTofRawData::SetVPDMap(StTofrDaqMap* daqMap) {
299  for(int i=0;i<mNTOF;i++) {
300  mTDIGLeChan2WestPMT[i] = daqMap->TDIGLeChan2WestPMT(i);
301  mTDIGTeChan2WestPMT[i] = daqMap->TDIGTeChan2WestPMT(i);
302  mTDIGLeChan2EastPMT[i] = daqMap->TDIGLeChan2EastPMT(i);
303  mTDIGTeChan2EastPMT[i] = daqMap->TDIGTeChan2EastPMT(i);
304  }
305  return;
306 }
void Init(StTofCollection *)