StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTofHitMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StTofHitMaker.cxx,v 1.8 2021/05/12 00:08:44 perev Exp $
4  *
5  * Author: Valeri Fine, BNL Feb 2008
6  ***************************************************************************
7  *
8  * Description: Create the TOF data coming from the RTS_READER
9  *
10  * Input: RTS_Reader
11  * Output: TOF data
12  *
13  **************************************************************************/
14 #include "StTofHitMaker.h"
15 
16 #include "TError.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"
25 
26 #ifdef NEW_DAQ_READER
27 # include "StRtsTable.h"
28 # include "DAQ_TOF/daq_tof.h"
29 #else /* NEW_DAQ_READER */
30 # include "RTS/src/DAQ_TOF/tofReader.h"
31 #endif /* NEW_DAQ_READER */
32 
33 #ifdef NEW_DAQ_READER
34 #ifdef tof
35 # error TOF if defined elsewhere
36 #else
37 # define tof (*fTof)
38 #endif
39 #endif /* NEW_DAQ_READER */
40 
41 
42 //_____________________________________________________________
43 #ifndef NEW_DAQ_READER
44 StTofHitMaker::StTofHitMaker(const char *name):StRTSBaseMaker(name)
45  , mStEvent(0),fDaqReader(0), mInitialized(0)
46 #else /* NEW_DAQ_READER */
47 StTofHitMaker::StTofHitMaker(const char *name):StRTSBaseMaker("tof",name)
48  , mStEvent(0),fTof(0), mInitialized(0)
49 #endif /* NEW_DAQ_READER */
50 {
51  LOG_INFO << "StTofHitMaker::ctor" << endm;
52 }
53 
54 //_____________________________________________________________
55 StTofHitMaker::~StTofHitMaker()
56 { }
57 
58 //_____________________________________________________________
59 Int_t StTofHitMaker::InitRun(Int_t runnumber) {
60  // prevent a chain from running this Maker for Run9+ data.
61  if (runnumber>=10000000) {
62  Error (":InitRun"," Wrong BFC configuration for run %d. Use StBTofHitMaker for Run9+ data.", runnumber);
63  mInitialized=(1==0);
64  } else {
65  mInitialized=(1==1);
66  }
67  return 0;
68 }
69 
70 Int_t StTofHitMaker::FinishRun(Int_t runnumber) {
71  // re-initialize this to false
72  mInitialized=(1==0);
73  return 0;
74 }
75 
76 //_____________________________________________________________
78 {
80  StTofCollection *tofCollection = 0;
81  mStEvent = dynamic_cast<StEvent *> (GetInputDS("StEvent"));
82  LOG_INFO << "StTofHitMaker::Make : StEvent has been retrieved "
83  <<mStEvent<< endm;
84 
85  if (mStEvent) {
86  tofCollection = mStEvent->tofCollection();
87 
89  if ( !tofCollection ) {
91  tofCollection = new StTofCollection();
92  mStEvent->setTofCollection(tofCollection);
93  }
94  }
95  return tofCollection;
96 }
97 #ifndef NEW_DAQ_READER
98 //_____________________________________________________________
100 {
102  if (!fDaqReader) {
103  StDAQReader *daqReader = 0;
104  LOG_INFO << "StTofHitMaker::InitReader" << endm;
105  TDataSet *dr = GetDataSet("StDAQReader");
106  if(dr) daqReader = (StDAQReader *)(dr->GetObject());
107 
108  if(daqReader == NULL) {
109  LOG_INFO << "StTofHitMaker::InitRun No daqReader available..." << endm;
110  } else {
111  fDaqReader = daqReader->getFileReader();
112  if(fDaqReader == NULL) {
113  LOG_INFO << "StTofHitMaker::InitRun No evpReader available..." << endm;
114  } else {
115  LOG_INFO << "StTofHitMaker::InitReader: " << fDaqReader << endm;
116  }
117  }
118  }
119  return fDaqReader;
120 }
121 #endif /* ! NEW_DAQ_READER */
122 //_____________________________________________________________
124 {
125  if ( ! mInitialized) return NULL;
127  LOG_INFO << " StTofHitMaker::GetNextRaw()" << endm;
128 #ifndef NEW_DAQ_READER
129 
130  evpReader *evp = InitReader();
131  return (StRtsTable *)(evp ? tofReader((char *)evp) : 0);
132 
133 #else /* NEW_DAQ_READER */
134  StRtsTable *daqTofTable = GetNextLegacy();
135  if (daqTofTable) {
136  fTof = (tof_t*)*DaqDta()->begin();
137  }
138  return daqTofTable;
139 #endif /* NEW_DAQ_READER */
140 }
141 //_____________________________________________________________
143 {
144  if ( ! mInitialized) return 0;
145  StTofCollection *tofCollection = GetTofCollection();
146  LOG_INFO << " getting the tof collection " << tofCollection << endm;
147  if (tofCollection) {
148  if ( GetNextRaw() ) {
149  // uint32_t ddl[4][10000] ; /// content of up to 4 fibers
150  // uint32_t ddl_words[4] ; /// the count of words (32bit) for above
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++ ) {
154  //LOG_INFO<<"TOF:::::: "<<i<<" "<<tof.ddl[rb][i]<<endm;
155  }
156  //
157  }
158 
160  int errorType=UnpackTofRawData();
161  if(errorType>0) LOG_INFO<<"TOF_READER::UnPack Year8 Data ERROR!"<<endm;
162  fillTofDataCollection();
163  fillStEvent();
164 
165  }
166  }
167  return kStOk;
168 }
169 //____________________________________________________
173 //____________________________________________________
174 Int_t StTofHitMaker::UnpackTofRawData()
175 {
177  TofLeadingHits.clear();
178  TofTrailingHits.clear();
179 
180  for(int ifib=0;ifib<4;ifib++){ // 4 fibers
181  int nword=tof.ddl_words[ifib];
182  if(nword <= 0) continue;
183  int halftrayid=-99;
184  int trayid = -99;
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) {
192  }
194  if( (dataword&0xF0000000)>>28 == 0x2) {
195  triggerword= dataword;
196  continue;
197  }
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;
203  continue;
204  }
205  if(halftrayid<0 || trayid<0) continue;
206 
207  int edgeid =int( (dataword & 0xf0000000)>>28 );
208  if((edgeid !=4) && (edgeid!=5)) continue;
209 
210  int tdcid=(dataword & 0x0F000000)>>24;
211  int tdigid=tdcid/4;
212  int tdcchan=(dataword&0x00E00000)>>21;
213  TofRawHit temphit;
215  temphit.fiberid=ifib;
216  temphit.trayID=trayid;
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;
223  if(edgeid == 4) {
224  TofLeadingHits.push_back(temphit);
225  } else if (edgeid==5){
226  TofTrailingHits.push_back(temphit);
227  } else {
228  LOG_INFO<<"StTofHitMaker::Unknown TDC data type ! "<<endm;
229  continue;
230  }
232  }
233  }
235  return -1;
237 }
238 
239 void StTofHitMaker::fillTofDataCollection()
240 {
241 
242  StTofCollection *tofCollection = GetTofCollection();
243 
245  for (unsigned int i=0;i<TofLeadingHits.size();i++){
246  unsigned short flag=1; // 1 - leading; 2 - trailing
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));
252  }
253 
254  for (unsigned int i=0;i<TofTrailingHits.size();i++){
255  unsigned short flag=2; // 1 - leading; 2 - trailing
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));
261 
262  }
263 
264 }
265 
266 //_________________________________________________________________________
268 void StTofHitMaker::fillStEvent() {
269 
270  LOG_INFO << "StTofHitMaker::fillStEvent() Starting..." << endm;
271 
273  if(!tofCollection){
274  tofCollection = new StTofCollection();
275  mStEvent->setTofCollection(tofCollection);
276  }
277 
279  StTofCollection* mtofCollection = mStEvent->tofCollection();
280  if(mtofCollection){
282  if(mtofCollection->rawdataPresent()) {
284  StSPtrVecTofRawData& rawTofVec = mtofCollection->tofRawData();
285  LOG_INFO << " StEvent TofRawDataCollection has " << rawTofVec.size() << " entries..." << endm;
286  }
287  else LOG_INFO << " - StEvent TofRawDataCollection does not Exist" << endm;
288  }
289  else {
290  LOG_INFO << " - StEvent tofCollection does not Exist" << endm;
291  LOG_INFO << " - StEvent tofRawDataCollection does not Exist" << endm;
292  }
293 }
294 
295 /***************************************************************************
296  * Add UnpackTofRawData() to process TOF raw data.
297  * Add fillTofDataCollection to fill TOF data in StEvent Tofcollection.
298  * Revision 1.7, 02/09/2008, Jing liu
299  *
300  * $Log: StTofHitMaker.cxx,v $
301  * Revision 1.8 2021/05/12 00:08:44 perev
302  * Change include directory
303  *
304  * Revision 1.7 2018/02/26 23:26:50 smirnovd
305  * StTof: Remove outdated ClassImp macro
306  *
307  * Revision 1.6 2018/02/26 23:13:20 smirnovd
308  * Move embedded CVS log messages to the end of file
309  *
310  * Revision 1.5 2009/06/09 19:45:36 jeromel
311  * Changes for BT#1428
312  *
313  * Revision 1.4 2009/06/08 17:56:30 geurts
314  * prevent a chain from running this maker on Run9+ data
315  *
316  * Revision 1.3 2008/12/15 21:27:31 fine
317  * Prepare the code for the new DAQ_READER from Tonko
318  *
319  * Revision 1.2 2008/12/02 23:58:44 fine
320  * Adjust the inteface to accnt the new base class
321  *
322  * Revision 1.1 2008/03/11 19:16:26 dongx
323  * first release. TOF offline reader for Run8+
324  *
325  * Revision 1.6 2008/02/01 01:31:07 fine
326  * Synch MAker with EVP_READER
327  *
328  * Revision 1.5 2008/01/30 20:04:35 fine
329  * introdcue the test and tofCollection
330  *
331  * Revision 1.4 2008/01/30 14:01:36 fine
332  * Replicate the tofReader.C code
333  *
334  * Revision 1.3 2008/01/30 04:38:49 fine
335  * Add RTS_READER parameters follow the Jeff's EVP_READER impl
336  *
337  * Revision 1.2 2008/01/29 15:56:48 fine
338  * remove the redundant dependency
339  *
340  * Revision 1.1 2008/01/25 22:30:24 fine
341  * Add the base makr for all RTS-based makers and template for the TofHitMaker
342  *
343  * Revision 1.4 2008/01/12 00:22:01 fine
344  * Update the test macro
345  */
StRtsTable * GetNextRaw()
This is an overloaded member function, provided for convenience.
Definition: FJcore.h:367
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...
Definition: daq_tof.h:7
Definition: tof.h:15
unsigned char fiberid
data word before unpack
Definition: rb.hh:21
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)
Definition: TDataSet.cxx:428
evpReader * InitReader()
virtual StRtsTable * GetNextLegacy()
This is an overloaded member function, provided for convenience.
unsigned char trayID
0 1 2,3
Definition: Stypes.h:41