14 #include "StTofHitMaker.h"
17 #include "StEventTypes.h"
18 #include "StEvent/StTofData.h"
19 #include "StEvent/StTofRawData.h"
20 #include "StTofUtil/StTofDataCollection.h"
21 #include "StTofUtil/StTofRawDataCollection.h"
22 #include "StEvent/StTofRawData.h"
23 #include "StEvent/StEvent.h"
24 #include "StDAQMaker/StDAQReader.h"
27 # include "StRtsTable.h"
28 # include "DAQ_TOF/daq_tof.h"
30 # include "RTS/src/DAQ_TOF/tofReader.h"
35 # error TOF if defined elsewhere
43 #ifndef NEW_DAQ_READER
44 StTofHitMaker::StTofHitMaker(
const char *name):
StRTSBaseMaker(name)
45 , mStEvent(0),fDaqReader(0), mInitialized(0)
48 , mStEvent(0),fTof(0), mInitialized(0)
51 LOG_INFO <<
"StTofHitMaker::ctor" << endm;
55 StTofHitMaker::~StTofHitMaker()
59 Int_t StTofHitMaker::InitRun(Int_t runnumber) {
61 if (runnumber>=10000000) {
62 Error (
":InitRun",
" Wrong BFC configuration for run %d. Use StBTofHitMaker for Run9+ data.", runnumber);
70 Int_t StTofHitMaker::FinishRun(Int_t runnumber) {
81 mStEvent =
dynamic_cast<StEvent *
> (GetInputDS(
"StEvent"));
82 LOG_INFO <<
"StTofHitMaker::Make : StEvent has been retrieved "
86 tofCollection = mStEvent->tofCollection();
89 if ( !tofCollection ) {
92 mStEvent->setTofCollection(tofCollection);
97 #ifndef NEW_DAQ_READER
104 LOG_INFO <<
"StTofHitMaker::InitReader" << endm;
105 TDataSet *dr = GetDataSet(
"StDAQReader");
108 if(daqReader == NULL) {
109 LOG_INFO <<
"StTofHitMaker::InitRun No daqReader available..." << endm;
111 fDaqReader = daqReader->getFileReader();
112 if(fDaqReader == NULL) {
113 LOG_INFO <<
"StTofHitMaker::InitRun No evpReader available..." << endm;
115 LOG_INFO <<
"StTofHitMaker::InitReader: " << fDaqReader << endm;
125 if ( ! mInitialized)
return NULL;
127 LOG_INFO <<
" StTofHitMaker::GetNextRaw()" << endm;
128 #ifndef NEW_DAQ_READER
131 return (
StRtsTable *)(evp ? tofReader((
char *)evp) : 0);
144 if ( ! mInitialized)
return 0;
146 LOG_INFO <<
" getting the tof collection " << tofCollection << endm;
151 for (
int rb =0;
rb < 3;
rb++) {
152 LOG_INFO<<
" Rdo = "<<
rb<<endm;
153 for (
unsigned int i = 0; i<
tof.ddl_words[
rb]; i++ ) {
160 int errorType=UnpackTofRawData();
161 if(errorType>0) LOG_INFO<<
"TOF_READER::UnPack Year8 Data ERROR!"<<endm;
162 fillTofDataCollection();
174 Int_t StTofHitMaker::UnpackTofRawData()
177 TofLeadingHits.clear();
178 TofTrailingHits.clear();
180 for(
int ifib=0;ifib<4;ifib++){
181 int nword=
tof.ddl_words[ifib];
182 if(nword <= 0)
continue;
185 int triggerword = -99;
186 for (
int iword=0;iword<nword;iword++) {
187 int dataword=
tof.ddl[ifib][iword];
189 if( (dataword&0xF0000000)>>28 == 0xD)
continue;
190 if( (dataword&0xF0000000)>>28 == 0xE)
continue;
191 if( (dataword&0xF0000000)>>28 == 0xA) {
194 if( (dataword&0xF0000000)>>28 == 0x2) {
195 triggerword= dataword;
198 if( (dataword&0xF0000000)>>28 == 0xC) {
199 halftrayid = dataword&0x01;
200 trayid = (dataword&0x0FE)>>1;
201 if(trayid==121 && ifib==0) trayid=121;
202 if(trayid==121 && ifib==2) trayid=122;
205 if(halftrayid<0 || trayid<0)
continue;
207 int edgeid =int( (dataword & 0xf0000000)>>28 );
208 if((edgeid !=4) && (edgeid!=5))
continue;
210 int tdcid=(dataword & 0x0F000000)>>24;
212 int tdcchan=(dataword&0x00E00000)>>21;
217 int timeinbin=((dataword&0x7ffff)<<2)+((dataword>>19)&0x03);
218 temphit.tdc=timeinbin;
220 temphit.
globaltdcchan=tdcchan + (tdcid%4)*8+tdigid*24+halftrayid*96;
221 temphit.timestamp=dataword;
222 temphit.triggertimestamp=triggerword;
224 TofLeadingHits.push_back(temphit);
225 }
else if (edgeid==5){
226 TofTrailingHits.push_back(temphit);
228 LOG_INFO<<
"StTofHitMaker::Unknown TDC data type ! "<<endm;
239 void StTofHitMaker::fillTofDataCollection()
245 for (
unsigned int i=0;i<TofLeadingHits.size();i++){
246 unsigned short flag=1;
247 unsigned short trayid=TofLeadingHits[i].trayID;
248 unsigned short chn=TofLeadingHits[i].globaltdcchan;
249 unsigned int tdc=TofLeadingHits[i].tdc;
250 unsigned int triggertime=TofLeadingHits[i].triggertimestamp;
251 tofCollection->addRawData (
new StTofRawData(flag,trayid,chn,tdc,triggertime,1));
254 for (
unsigned int i=0;i<TofTrailingHits.size();i++){
255 unsigned short flag=2;
256 unsigned short trayid=TofTrailingHits[i].trayID;
257 unsigned short chn=TofTrailingHits[i].globaltdcchan;
258 unsigned int tdc=TofTrailingHits[i].tdc;
259 unsigned int triggertime=TofTrailingHits[i].triggertimestamp;
260 tofCollection->addRawData (
new StTofRawData(flag,trayid,chn,tdc,triggertime,1));
268 void StTofHitMaker::fillStEvent() {
270 LOG_INFO <<
"StTofHitMaker::fillStEvent() Starting..." << endm;
275 mStEvent->setTofCollection(tofCollection);
282 if(mtofCollection->rawdataPresent()) {
284 StSPtrVecTofRawData& rawTofVec = mtofCollection->tofRawData();
285 LOG_INFO <<
" StEvent TofRawDataCollection has " << rawTofVec.size() <<
" entries..." << endm;
287 else LOG_INFO <<
" - StEvent TofRawDataCollection does not Exist" << endm;
290 LOG_INFO <<
" - StEvent tofCollection does not Exist" << endm;
291 LOG_INFO <<
" - StEvent tofRawDataCollection does not Exist" << endm;
StRtsTable * GetNextRaw()
This is an overloaded member function, provided for convenience.
unsigned char globaltdcchan
1,2,......,120,for tray, 121, 122 for upvpd
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
unsigned char fiberid
data word before unpack
StTofCollection * GetTofCollection()
StRtsTable * DaqDta()
Return the current DAQ data block. This member function is provided for convenience.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual StRtsTable * GetNextLegacy()
This is an overloaded member function, provided for convenience.
unsigned char trayID
0 1 2,3