16 #include "StBTofHitMaker.h"
18 #include "StEventTypes.h"
19 #include "StEvent/StBTofCollection.h"
20 #include "StEvent/StBTofHeader.h"
21 #include "StEvent/StBTofRawHit.h"
22 #include "StBTofUtil/StBTofRawHitCollection.h"
23 #include "StBTofUtil/StBTofHitCollection.h"
24 #include "StBTofUtil/StBTofDaqMap.h"
25 #include "StBTofUtil/StBTofINLCorr.h"
26 #include "StEvent/StEvent.h"
27 #include "StDAQMaker/StDAQReader.h"
29 #include "StRtsTable.h"
30 #include "DAQ_TOF/daq_tof.h"
38 , mRawHitCollection(0)
44 LOG_DEBUG <<
"StBTofHitMaker::ctor" << endm;
48 StBTofHitMaker::~StBTofHitMaker()
54 TofLeadingHits.clear();
55 TofTrailingHits.clear();
57 for(
int i=0;i<4;i++) mTriggerTimeStamp[i] = 0;
61 Int_t StBTofHitMaker::Init()
63 LOG_INFO <<
"Initialized conversion parameter VHRBIN2PS = "
64 << VHRBIN2PS <<
"ps/ch" << endm;
70 Int_t StBTofHitMaker::InitRun(Int_t runnumber)
75 LOG_DEBUG <<
"Initializing DAQ map:" << endm;
77 mBTofDaqMap->
Init(
this);
81 LOG_DEBUG <<
"Initializing INL table:" << endm;
85 LOG_DEBUG <<
"Initializing StBTofSortRawHit:" << endm;
87 mBTofSortRawHit->Init(
this, mBTofDaqMap);
90 mYear = (Int_t)runnumber/1e6 - 1;
96 Int_t StBTofHitMaker::FinishRun(Int_t runnumber)
98 if(mBTofDaqMap)
delete mBTofDaqMap;
101 if(mBTofINLCorr)
delete mBTofINLCorr;
123 mStEvent =
dynamic_cast<StEvent *
> (GetInputDS(
"StEvent"));
126 btofCollection = mStEvent->btofCollection();
129 if ( !btofCollection ) {
132 mStEvent->setBTofCollection(btofCollection);
135 else {LOG_WARN <<
"No StEvent found" << endm; }
137 return btofCollection;
142 assert(0 &&
"RTS doesn't provide sector by sector legacy tof banks yet");
153 LOG_DEBUG <<
"GetNextRaw()" << endm;
165 LOG_DEBUG <<
" getting the tof collection " << mBTofCollection << endm;
166 if (mBTofCollection) {
169 int errorType=UnpackTofRawData();
171 LOG_WARN<<
"TOF_READER::UnPack TOF Data ERROR!"<<endm;
173 fillBTofRawHitCollection();
175 fillBTofHitCollection();
187 Int_t StBTofHitMaker::UnpackTofRawData()
192 TofLeadingHits.clear();
193 TofTrailingHits.clear();
195 for(
int ifib=0;ifib<4;ifib++){
196 int nword=fTof->ddl_words[ifib];
197 if(nword <= 0)
continue;
198 int halftrayid = -99;
200 mTriggerTimeStamp[ifib] = 0;
204 for (
int iword=0;iword<nword;iword++) {
205 unsigned int dataword=fTof->ddl[ifib][iword];
209 if( (dataword&0xF0000000)>>28 == 0xD)
continue;
210 if( (dataword&0xF0000000)>>28 == 0xE)
continue;
211 if( (dataword&0xF0000000)>>28 == 0xA) {
215 if( (dataword&0xF0000000)>>28 == 0x2) {
216 if(mTriggerTimeStamp[ifib]==0) mTriggerTimeStamp[ifib] = dataword;
219 if( (dataword&0xF0000000)>>28 == 0xC) {
220 halftrayid = dataword&0x01;
221 trayid = (dataword&0x0FE)>>1;
224 if(halftrayid<0)
continue;
225 if(trayid<1 || trayid >124) {
226 LOG_ERROR<<
"StBTofHitMaker::DATA ERROR!! unexpected trayID ! "<<endm;
229 int edgeid =int( (dataword & 0xf0000000)>>28 );
230 if((edgeid !=4) && (edgeid!=5))
continue;
232 int tdcid=(dataword & 0x0F000000)>>24;
234 int tdcchan=(dataword&0x00E00000)>>21;
237 memset(&temphit,0,
sizeof(temphit));
238 temphit.
fiberid = (UChar_t)ifib;
239 temphit.
trayID = (UChar_t)trayid;
240 unsigned int timeinbin = ((dataword&0x7ffff)<<2)+((dataword>>19)&0x03);
241 temphit.tdc = timeinbin;
244 bool isGMT = (trayid==8) || (trayid==23) || (trayid==93) || (trayid==108);
246 if ((mYear >= 13) && (isGMT) && (halftrayid==0) && (tdigid==0)){
247 temphit.
globaltdcchan = (UChar_t)(tdcchan + (tdcid%4)*8+ 1*24 +halftrayid*96);
250 else if ((mYear >= 13) && (isGMT) && (((halftrayid==0)&&(tdigid==1)) || ((halftrayid==1)&&(tdigid==3)))){
251 LOG_ERROR<<
"Unexpected TDIG-Id (" << tdigid+(4*halftrayid) <<
") in TOF GMT tray (" << trayid <<
"). Should not happen" << endm;
254 temphit.
globaltdcchan = (UChar_t)(tdcchan + (tdcid%4)*8+tdigid*24+halftrayid*96);
262 TofLeadingHits.push_back(temphit);
263 }
else if (edgeid==5){
264 TofTrailingHits.push_back(temphit);
266 LOG_WARN<<
"StBTofHitMaker::Unknown TDC data type ! "<<endm;
281 void StBTofHitMaker::fillBTofRawHitCollection()
284 for (
unsigned int i=0;i<TofLeadingHits.size();i++){
285 char flag = (+1)*(TofLeadingHits[i].fiberid+1);
286 unsigned char trayid = TofLeadingHits[i].trayID;
287 unsigned char chn = TofLeadingHits[i].globaltdcchan;
288 unsigned int tdc = TofLeadingHits[i].tdc;
289 mBTofCollection->addRawHit(
new StBTofRawHit(flag,trayid,chn,tdc));
292 for (
unsigned int i=0;i<TofTrailingHits.size();i++){
293 char flag = (-1)*(TofTrailingHits[i].fiberid+1);
294 unsigned char trayid = TofTrailingHits[i].trayID;
295 unsigned char chn = TofTrailingHits[i].globaltdcchan;
296 unsigned int tdc = TofTrailingHits[i].tdc;
297 mBTofCollection->addRawHit(
new StBTofRawHit(flag,trayid,chn,tdc));
305 void StBTofHitMaker::fillBTofHeader()
310 tofHeader->setTriggerTime(mTriggerTimeStamp[i], i);
312 mBTofCollection->setHeader(tofHeader);
318 void StBTofHitMaker::fillBTofHitCollection()
324 for(
size_t i=0;i<validtray.size();i++) {
325 int trayId = validtray[i];
328 LOG_INFO <<
" Number of fired hits on tray " << trayId <<
" = " << validchannel.size() << endm;
331 for(
size_t iv=0;iv<validchannel.size();iv++) {
332 UIntVec leTdc = mBTofSortRawHit->
GetLeadingTdc(trayId, validchannel[iv], kTRUE);
333 UIntVec teTdc = mBTofSortRawHit->
GetTrailingTdc(trayId, validchannel[iv], kTRUE);
335 if(!leTdc.size() || !teTdc.size())
continue;
337 int chan = validchannel[iv];
339 int moduleId = map[0];
345 unsigned int tmptdc = leTdc[0];
346 int bin = tmptdc&0x3ff;
347 double tmptdc_f = tmptdc + mBTofINLCorr->
getTrayINLCorr(trayId, chan, bin);
348 double letime = tmptdc_f*VHRBIN2PS / 1000.;
352 tmptdc_f = tmptdc + mBTofINLCorr->
getTrayINLCorr(trayId, chan, bin);
353 double tetime = tmptdc_f*VHRBIN2PS / 1000.;
356 aHit->setHardwarePosition(kBTofId);
357 aHit->setTray((UChar_t)trayId);
358 aHit->setModule((UChar_t)moduleId);
359 aHit->setCell((UChar_t)cellId);
360 aHit->setLeadingEdgeTime(letime);
361 aHit->setTrailingEdgeTime(tetime);
362 mBTofCollection->addHit(aHit);
368 for(
int ivpd=0;ivpd<2;ivpd++) {
369 StBeamDirection eastwest = (ivpd==0) ? west : east;
370 int trayId = (ivpd==0) ? mWestVpdTrayId : mEastVpdTrayId;
373 LOG_INFO <<
" Number of fired hits on tray(vpd) " << trayId <<
" = " << validtube.size() << endm;
376 if(!validtube.size())
continue;
377 for(
int i=0;i<mNVPD;i++) {
381 UIntVec leTdc = mBTofSortRawHit->
GetLeadingTdc(trayId, lechan, kTRUE);
382 UIntVec teTdc = mBTofSortRawHit->
GetTrailingTdc(trayId, lechan, kTRUE);
384 if(leTdc.size() && teTdc.size()) {
387 unsigned int tmptdc = leTdc[0];
388 int bin = tmptdc&0x3ff;
389 double tmptdc_f = tmptdc + mBTofINLCorr->
getVpdINLCorr(eastwest, lechan, bin);
390 double letime = tmptdc_f*VHRBIN2PS / 1000.;
394 tmptdc_f = tmptdc + mBTofINLCorr->
getVpdINLCorr(eastwest, techan, bin);
395 double tetime = tmptdc_f*VHRBIN2PS / 1000.;
398 aHit->setTray((UChar_t)trayId);
400 aHit->setCell((UChar_t)tubeId);
401 aHit->setLeadingEdgeTime(letime);
402 aHit->setTrailingEdgeTime(tetime);
403 mBTofCollection->addHit(aHit);
415 void StBTofHitMaker::fillStEvent() {
417 LOG_DEBUG <<
"fillStEvent() Starting..." << endm;
420 if(!mBTofCollection){
421 LOG_WARN <<
"No BTofCollection ... creating one in StEvent" << endm;
423 mStEvent->setBTofCollection(mBTofCollection);
429 if(btofCollection->rawHitsPresent()) {
430 StSPtrVecBTofRawHit& rawTofVec = btofCollection->tofRawHits();
431 LOG_INFO <<
"BTofRawHitCollection: " << rawTofVec.size() <<
" entries" << endm;
433 for(
size_t i=0;i<rawTofVec.size();i++) {
434 LOG_DEBUG << (*rawTofVec[i]) << endm;
439 LOG_INFO <<
"No BTofRawHitCollection" << endm;
442 if(btofCollection->hitsPresent()) {
443 StSPtrVecBTofHit& tofVec = btofCollection->tofHits();
444 LOG_INFO <<
"BTofHitCollection: " << tofVec.size() <<
" entries..." << endm;
446 for(
size_t i=0;i<tofVec.size();i++) {
447 LOG_DEBUG << (*tofVec[i]) << endm;
452 LOG_INFO <<
"No BTofHitCollection" << endm;
457 LOG_WARN <<
"No BTofCollection" << endm;
458 LOG_INFO <<
"No BTofRawHitCollection" << endm;
459 LOG_INFO <<
"No BTofHitCollection" << endm;
void Init(StMaker *maker)
Initial function, need a maker to access the data base.
Int_t numberOfValidTrays()
Returns the number of valid trays.
Int_t WestPMT2TDIGTeChan(const Int_t iTube)
To convert west VPD PMT number to TDIG trailing channel number.
unsigned char globaltdcchan
1,2,......,120,for tray, 121, 122 for upvpd
void Clear(Option_t *option="")
User defined functions.
Int_t WestPMT2TDIGLeChan(const Int_t iTube)
To convert west VPD PMT number to TDIG leading channel number.
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
StBTofHitMaker(const char *name="tof_raw")
Default constructor.
IntVec ValidTrays()
Returns the list of valid tray Ids.
void setBTofCollection(StBTofCollection *tofColl)
set to use the VPD delays
Int_t EastPMT2TDIGTeChan(const Int_t iTube)
To convert east VPD PMT number to TDIG trailing channel number.
unsigned char fiberid
data word before unpack
unsigned int dataword
tdc time (in bin) per hit.
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...
float getTrayINLCorr(int trayId, int globalTdcChan, int bin)
To get the INL correction tables for trays.
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...
StBTofCollection * GetBTofCollection()
void initFromDbase(StMaker *maker)
Initial function to access the data base and retrieve INL tables.
StRtsTable * DaqDta()
Return the current DAQ data block. This member function is provided for convenience.
IntVec TDIGChan2Cell(const Int_t iTdc)
To convert TDIG channel number to module/cell number.
StRtsTable * GetNextRaw()
This is an overloaded member function, provided for convenience.
virtual StRtsTable * GetNextLegacy()
This is an overloaded member function, provided for convenience.
unsigned char trayID
0 1 2,3
Int_t EastPMT2TDIGLeChan(const Int_t iTube)
float getVpdINLCorr(StBeamDirection eastwest, int globalTdcChan, int bin)
To get the INL correction tables for vpds.