15 #include "StMessMgr.h"
16 #include "StBTofSortRawHit.h"
18 #include "StBTofCollection.h"
19 #include "StBTofRawHit.h"
20 #include "StBTofDaqMap.h"
21 #include "tables/St_tofTrgWindow_Table.h"
22 #include "tables/St_vpdDelay_Table.h"
24 StBTofSortRawHit::StBTofSortRawHit() {
30 StBTofSortRawHit::~StBTofSortRawHit() {
34 void StBTofSortRawHit::Reset() {
35 for(
int i=0;i<mNTRAY;i++) mRawHitVec[i].clear();
36 memset(mTriggerTime,0,
sizeof(mTriggerTime));
39 void StBTofSortRawHit::Init() {
41 memset(mTriggerTimeWindow,0,
sizeof(mTriggerTimeWindow));
42 memset(mVpdDelay,0,
sizeof(mVpdDelay));
51 LOG_INFO <<
"[StBTofSortRawHit] retrieving BTOF trigger time window cuts" << endm;
52 TDataSet *mDbTOFDataSet = maker->GetDataBase(
"Calibrations/tof/tofTrgWindow");
53 St_tofTrgWindow* tofTrgWindow =
static_cast<St_tofTrgWindow*
>(mDbTOFDataSet->
Find(
"tofTrgWindow"));
55 LOG_ERROR <<
"unable to get tof Module map table" << endm;
58 tofTrgWindow_st* trgWin =
static_cast<tofTrgWindow_st*
>(tofTrgWindow->GetArray());
59 for (Int_t i=0;i<mNTRAY;i++) {
60 mTriggerTimeWindow[i][0] = (Float_t)trgWin[i].trgWindow_Min;
61 mTriggerTimeWindow[i][1] = (Float_t)trgWin[i].trgWindow_Max;
63 LOG_DEBUG <<
" Tray = " << i+1 <<
" Trigger Window = " << mTriggerTimeWindow[i][0] <<
" " << mTriggerTimeWindow[i][1] << endm;
69 if(maker->Debug()) mDebug = kTRUE;
71 LOG_INFO <<
"[StBTofSortRawHit] retrieving VPD delay settings" << endm;
72 mDbTOFDataSet = maker->GetDataBase(
"Calibrations/tof/vpdDelay");
76 St_vpdDelay *vpdDelayTable =
static_cast<St_vpdDelay*
>(mDbTOFDataSet->
Find(
"vpdDelay"));
78 LOG_ERROR <<
"unable to find vpdDelay table" << endm;
81 vpdDelay_st* vpdDelay =
static_cast<vpdDelay_st*
>(vpdDelayTable->GetArray());
83 LOG_ERROR <<
"unable to get vpdDelay data" << endm;
86 for (
int i=0;i<2*mNVPD;i++){
87 mVpdDelay[i] = vpdDelay->delay[i];
93 LOG_WARN <<
"unable to find vpdDelay dataset: assuming Run-9 (200GeV) default values for vpdDelay" << endm;
94 float delay[2*mNVPD]={
95 0,-0.564753,-4.62291,-4.84402,-4.05943,6.32389,-9.4035,-10.3113,-17.0374,-17.3734,-6.04608,-11.9614,-12.7579,8.79609,3.8467,-17.2994,-17.6424,-21.4749,-22.9736,
96 0,-2.1707, -4.8195, -6.5161, -4.3109, 6.3116, -8.8655,-10.1037,-16.5970,-17.9588,-5.2079, -12.1249,-12.2412,8.4001, 5.5702,-16.5936,-16.4152,-21.3076,-21.1452};
98 for (
int i=0;i<2*mNVPD;i++){
99 mVpdDelay[i] = delay[i];
111 if(tofColl && tofColl->tofHeader()) {
112 for(
int i=0;i<mNFIBER;i++) {
113 mTriggerTime[i] = tofColl->tofHeader()->triggerTime(i);
116 LOG_INFO <<
" Trigger Time Stamps " << endm;
117 LOG_INFO << mTriggerTime[0] <<
" " << mTriggerTime[1] <<
" " <<
118 mTriggerTime[2] <<
" " << mTriggerTime[3] << endm;
122 if(tofColl && tofColl->rawHitsPresent()) {
124 StSPtrVecBTofRawHit &tofRawHits = tofColl->tofRawHits();
128 LOG_INFO <<
" INPUT ...... " << endm;
129 for(
size_t i=0; i<tofRawHits.size(); i++) {
130 LOG_INFO <<
" flag=" << tofRawHits[i]->flag()
131 <<
" tray=" << tofRawHits[i]->tray() <<
" channel="
132 << tofRawHits[i]->channel() <<
" tdc="
133 << tofRawHits[i]->tdc() << endm;
138 for(
size_t i=0; i<tofRawHits.size(); i++) {
139 if(!tofRawHits[i]->leadingEdge())
continue;
140 int itray = tofRawHits[i]->tray();
141 int ichan = tofRawHits[i]->channel();
142 int ifiber = tofRawHits[i]->fiberId();
143 if (itray<=0 || itray>mNTRAY || ichan<0 || ichan>=mNCHAN || ifiber<0 || ifiber>=mNFIBER ) {
144 LOG_FATAL <<
" StBTofSortRawHit::setBTofCollection:: "
145 <<
": itray=" << itray
146 <<
": ichan=" << ichan
147 <<
": ifiber=" << ifiber
151 bool iexist = kFALSE;
152 for(
size_t ii=0; ii<mRawHitVec[itray-1].size(); ii++) {
153 if(itray==mRawHitVec[itray-1][ii].tray && ichan==mRawHitVec[itray-1][ii].channel) {
160 aRawHit.fiberId = ifiber;
161 aRawHit.tray = itray;
162 aRawHit.channel = ichan;
163 aRawHit.leadingTdc.push_back(tofRawHits[i]->tdc());
164 for(
size_t j=i+1;j<tofRawHits.size();j++) {
165 if(tofRawHits[j]->leadingEdge() &&
166 itray==tofRawHits[j]->tray() && ichan==tofRawHits[j]->channel()) {
167 aRawHit.leadingTdc.push_back(tofRawHits[j]->tdc());
173 for(
size_t j=0;j<tofRawHits.size();j++) {
174 if(tofRawHits[j]->trailingEdge() &&
175 itray==tofRawHits[j]->tray() && ichan==tofRawHits[j]->channel()) {
176 aRawHit.trailingTdc.push_back(tofRawHits[j]->tdc());
181 LOG_INFO <<
" No Daq Map for VPD, continue!" << endm;
185 for(
size_t j=0;j<tofRawHits.size();j++) {
186 if(tofRawHits[j]->trailingEdge() && itray==tofRawHits[j]->tray()) {
187 int techan = (int)(tofRawHits[j]->channel());
190 aRawHit.trailingTdc.push_back(tofRawHits[j]->tdc());
195 if(aRawHit.trailingTdc.size()) mRawHitVec[itray-1].push_back(aRawHit);
198 LOG_WARN <<
" No Tof Collection !!! " << endm;
202 for(
int i=0;i<122;i++) {
203 for(
size_t m=0;m<mRawHitVec[i].size();m++) {
204 LOG_DEBUG <<
" tray = " << i+1 <<
" " << mRawHitVec[i][m].tray <<
" channel = " << mRawHitVec[i][m].channel << endm;
205 LOG_DEBUG <<
" leading tdcs = ";
206 for(
size_t j=0;j<mRawHitVec[i][m].leadingTdc.size();j++) {
207 LOG_DEBUG <<
" " << mRawHitVec[i][m].leadingTdc[j];
210 LOG_DEBUG <<
" trailing tdcs = ";
211 for(
size_t j=0;j<mRawHitVec[i][m].trailingTdc.size();j++) {
212 LOG_DEBUG <<
" " << mRawHitVec[i][m].trailingTdc[j];
222 for(
size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
223 if( mRawHitVec[tray-1][i].tray == tray )
224 chanVec.push_back(mRawHitVec[tray-1][i].channel);
232 for(
size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
233 if(mRawHitVec[tray-1][i].tray!=tray)
continue;
234 if(mRawHitVec[tray-1][i].channel!=channel)
continue;
235 int fiberId = mRawHitVec[tray-1][i].fiberId;
237 for(
size_t j=0; j<mRawHitVec[tray-1][i].leadingTdc.size(); j++) {
238 float trgTime = 25.*(mTriggerTime[fiberId] & 0xfff);
239 float timeDiff = mRawHitVec[tray-1][i].leadingTdc[j]*25./1024 - trgTime;
240 while(timeDiff<0) timeDiff += 51200;
243 if(timeDiff>=mTriggerTimeWindow[tray-1][0]&&timeDiff<=mTriggerTimeWindow[tray-1][1])
244 leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
247 leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
255 timeDiff -= mVpdDelay[(tray-121)*mNVPD+(iTube-1)];
256 while(timeDiff<0) timeDiff += 51200;
258 double stime = timeDiff;
259 if(stime > ftime+300.){
260 if(timeDiff>=mTriggerTimeWindow[tray-1][0]&&timeDiff<=mTriggerTimeWindow[tray-1][1])
261 leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
266 leTdc.push_back(mRawHitVec[tray-1][i].leadingTdc[j]);
277 for(
size_t i=0 ; i<mRawHitVec[tray-1].size() ; i++) {
278 if(mRawHitVec[tray-1][i].tray!=tray)
continue;
279 if(mRawHitVec[tray-1][i].channel!=channel)
continue;
280 int fiberId = mRawHitVec[tray-1][i].fiberId;
282 for(
size_t j=0; j<mRawHitVec[tray-1][i].trailingTdc.size(); j++) {
283 float trgTime = 25.*(mTriggerTime[fiberId] & 0xfff);
284 float timeDiff = mRawHitVec[tray-1][i].trailingTdc[j]*25./1024 - trgTime;
285 while(timeDiff<0) timeDiff += 51200;
288 if(timeDiff>=mTriggerTimeWindow[tray-1][0]&&timeDiff<=mTriggerTimeWindow[tray-1][1]+25.)
289 teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
292 teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
300 timeDiff -= mVpdDelay[(tray-121)*mNVPD+(iTube-1)];
301 while(timeDiff<0) timeDiff += 51200;
303 double stime = timeDiff;
304 if(stime > ftime+300.){
305 if(timeDiff>=mTriggerTimeWindow[tray-1][0]&&timeDiff<=mTriggerTimeWindow[tray-1][1]+25.)
306 teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
311 teTdc.push_back(mRawHitVec[tray-1][i].trailingTdc[j]);
Int_t TDIGLeChan2WestPMT(const Int_t iTdc)
To convert TDIG leading channel number to west VPD PMT number.
void setBTofCollection(StBTofCollection *tofColl)
set to use the VPD delays
Int_t TDIGLeChan2EastPMT(const Int_t iTdc)
To convert TDIG leading channel number to east VPD PMT number.
Int_t TDIGTeChan2EastPMT(const Int_t iTdc)
To convert TDIG trailing channel number to east VPD PMT number.
IntVec GetValidChannel(int tray)
Returns the valid channel Ids for a tray.
UIntVec GetLeadingTdc(int tray, int channel, bool triggerevent=true)
Returns the leading Tdcs for one channel. triggerevent used as a switch for physical hits selection...
UIntVec GetTrailingTdc(int tray, int channel, bool triggerevent=true)
Returns the trailing Tdcs for one channel. triggerevent used as a switch for physical hits selection...
Int_t TDIGTeChan2WestPMT(const Int_t iTdc)
To convert TDIG trailing channel number to west VPD PMT number.
virtual TDataSet * Find(const char *path) const