00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include "StTofHitMaker.h"
00057
00058 #include "TError.h"
00059 #include "StEventTypes.h"
00060 #include "StEvent/StTofData.h"
00061 #include "StEvent/StTofRawData.h"
00062 #include "StTofUtil/StTofDataCollection.h"
00063 #include "StTofUtil/StTofRawDataCollection.h"
00064 #include "StEvent/StTofRawData.h"
00065 #include "StEvent/StEvent.h"
00066 #include "StDAQMaker/StDAQReader.h"
00067
00068 #ifdef NEW_DAQ_READER
00069 # include "StRtsTable.h"
00070 # include "DAQ_TOF/daq_tof.h"
00071 #else
00072 # include "RTS/src/EVP_READER/tofReader.h"
00073 #endif
00074
00075 #ifdef NEW_DAQ_READER
00076 #ifdef tof
00077 # error TOF if defined elsewhere
00078 #else
00079 # define tof (*fTof)
00080 #endif
00081 #endif
00082
00083 ClassImp(StTofHitMaker);
00084
00085
00086 #ifndef NEW_DAQ_READER
00087 StTofHitMaker::StTofHitMaker(const char *name):StRTSBaseMaker(name)
00088 , mStEvent(0),fDaqReader(0), mInitialized(0)
00089 #else
00090 StTofHitMaker::StTofHitMaker(const char *name):StRTSBaseMaker("tof",name)
00091 , mStEvent(0),fTof(0), mInitialized(0)
00092 #endif
00093 {
00094 LOG_INFO << "StTofHitMaker::ctor" << endm;
00095 }
00096
00097
00098 StTofHitMaker::~StTofHitMaker()
00099 { }
00100
00101
00102 Int_t StTofHitMaker::InitRun(Int_t runnumber) {
00103
00104 if (runnumber>=10000000) {
00105 Error (":InitRun"," Wrong BFC configuration for run %d. Use StBTofHitMaker for Run9+ data.", runnumber);
00106 mInitialized=(1==0);
00107 } else {
00108 mInitialized=(1==1);
00109 }
00110 return 0;
00111 }
00112
00113 Int_t StTofHitMaker::FinishRun(Int_t runnumber) {
00114
00115 mInitialized=(1==0);
00116 return 0;
00117 }
00118
00119
00120 StTofCollection *StTofHitMaker::GetTofCollection()
00121 {
00123 StTofCollection *tofCollection = 0;
00124 mStEvent = dynamic_cast<StEvent *> (GetInputDS("StEvent"));
00125 LOG_INFO << "StTofHitMaker::Make : StEvent has been retrieved "
00126 <<mStEvent<< endm;
00127
00128 if (mStEvent) {
00129 tofCollection = mStEvent->tofCollection();
00130
00132 if ( !tofCollection ) {
00134 tofCollection = new StTofCollection();
00135 mStEvent->setTofCollection(tofCollection);
00136 }
00137 }
00138 return tofCollection;
00139 }
00140 #ifndef NEW_DAQ_READER
00141
00142 evpReader *StTofHitMaker::InitReader()
00143 {
00145 if (!fDaqReader) {
00146 StDAQReader *daqReader = 0;
00147 LOG_INFO << "StTofHitMaker::InitReader" << endm;
00148 TDataSet *dr = GetDataSet("StDAQReader");
00149 if(dr) daqReader = (StDAQReader *)(dr->GetObject());
00150
00151 if(daqReader == NULL) {
00152 LOG_INFO << "StTofHitMaker::InitRun No daqReader available..." << endm;
00153 } else {
00154 fDaqReader = daqReader->getFileReader();
00155 if(fDaqReader == NULL) {
00156 LOG_INFO << "StTofHitMaker::InitRun No evpReader available..." << endm;
00157 } else {
00158 LOG_INFO << "StTofHitMaker::InitReader: " << fDaqReader << endm;
00159 }
00160 }
00161 }
00162 return fDaqReader;
00163 }
00164 #endif
00165
00166 StRtsTable *StTofHitMaker::GetNextRaw()
00167 {
00168 if ( ! mInitialized) return NULL;
00170 LOG_INFO << " StTofHitMaker::GetNextRaw()" << endm;
00171 #ifndef NEW_DAQ_READER
00172
00173 evpReader *evp = InitReader();
00174 return (StRtsTable *)(evp ? tofReader((char *)evp) : 0);
00175
00176 #else
00177 StRtsTable *daqTofTable = GetNextLegacy();
00178 if (daqTofTable) {
00179 fTof = (tof_t*)*DaqDta()->begin();
00180 }
00181 return daqTofTable;
00182 #endif
00183 }
00184
00185 Int_t StTofHitMaker::Make()
00186 {
00187 if ( ! mInitialized) return 0;
00188 StTofCollection *tofCollection = GetTofCollection();
00189 LOG_INFO << " getting the tof collection " << tofCollection << endm;
00190 if (tofCollection) {
00191 if ( GetNextRaw() ) {
00192
00193
00194 for (int rb =0; rb < 3;rb++) {
00195 LOG_INFO<<" Rdo = "<<rb<<endm;
00196 for (unsigned int i = 0; i<tof.ddl_words[rb]; i++ ) {
00197
00198 }
00199
00200 }
00201
00203 int errorType=UnpackTofRawData();
00204 if(errorType>0) LOG_INFO<<"TOF_READER::UnPack Year8 Data ERROR!"<<endm;
00205 fillTofDataCollection();
00206 fillStEvent();
00207
00208 }
00209 }
00210 return kStOk;
00211 }
00212
00216
00217 Int_t StTofHitMaker::UnpackTofRawData()
00218 {
00220 TofLeadingHits.clear();
00221 TofTrailingHits.clear();
00222
00223 for(int ifib=0;ifib<4;ifib++){
00224 int nword=tof.ddl_words[ifib];
00225 if(nword <= 0) continue;
00226 int halftrayid=-99;
00227 int trayid = -99;
00228 int triggerword = -99;
00229 for (int iword=0;iword<nword;iword++) {
00230 int dataword=tof.ddl[ifib][iword];
00232 if( (dataword&0xF0000000)>>28 == 0xD) continue;
00233 if( (dataword&0xF0000000)>>28 == 0xE) continue;
00234 if( (dataword&0xF0000000)>>28 == 0xA) {
00235
00236 }
00237 if( (dataword&0xF0000000)>>28 == 0x2) {
00238 triggerword= dataword;
00239 continue;
00240 }
00241 if( (dataword&0xF0000000)>>28 == 0xC) {
00242 halftrayid = dataword&0x01;
00243 trayid = (dataword&0x0FE)>>1;
00244 if(trayid==121 && ifib==0) trayid=121;
00245 if(trayid==121 && ifib==2) trayid=122;
00246 continue;
00247 }
00248 if(halftrayid<0 || trayid<0) continue;
00249
00250 int edgeid =int( (dataword & 0xf0000000)>>28 );
00251 if((edgeid !=4) && (edgeid!=5)) continue;
00252
00253 int tdcid=(dataword & 0x0F000000)>>24;
00254 int tdigid=tdcid/4;
00255 int tdcchan=(dataword&0x00E00000)>>21;
00256
00257 TofRawHit temphit;
00258 temphit.fiberid=ifib;
00259 temphit.trayID=trayid;
00260 int timeinbin=((dataword&0x7ffff)<<2)+((dataword>>19)&0x03);
00261 temphit.tdc=timeinbin;
00263 temphit.globaltdcchan=tdcchan + (tdcid%4)*8+tdigid*24+halftrayid*96;
00264 temphit.timestamp=dataword;
00265 temphit.triggertimestamp=triggerword;
00266 if(edgeid == 4) {
00267 TofLeadingHits.push_back(temphit);
00268 } else if (edgeid==5){
00269 TofTrailingHits.push_back(temphit);
00270 } else {
00271 LOG_INFO<<"StTofHitMaker::Unknown TDC data type ! "<<endm;
00272 continue;
00273 }
00275 }
00276
00277 }
00278
00279 return -1;
00280 }
00281
00282 void StTofHitMaker::fillTofDataCollection()
00283 {
00284
00285 StTofCollection *tofCollection = GetTofCollection();
00286
00288 for (unsigned int i=0;i<TofLeadingHits.size();i++){
00289 unsigned short flag=1;
00290 unsigned short trayid=TofLeadingHits[i].trayID;
00291 unsigned short chn=TofLeadingHits[i].globaltdcchan;
00292 unsigned int tdc=TofLeadingHits[i].tdc;
00293 unsigned int triggertime=TofLeadingHits[i].triggertimestamp;
00294 tofCollection->addRawData (new StTofRawData(flag,trayid,chn,tdc,triggertime,1));
00295 }
00296
00297 for (unsigned int i=0;i<TofTrailingHits.size();i++){
00298 unsigned short flag=2;
00299 unsigned short trayid=TofTrailingHits[i].trayID;
00300 unsigned short chn=TofTrailingHits[i].globaltdcchan;
00301 unsigned int tdc=TofTrailingHits[i].tdc;
00302 unsigned int triggertime=TofTrailingHits[i].triggertimestamp;
00303 tofCollection->addRawData (new StTofRawData(flag,trayid,chn,tdc,triggertime,1));
00304
00305 }
00306
00307 }
00308
00309
00311 void StTofHitMaker::fillStEvent() {
00312
00313 LOG_INFO << "StTofHitMaker::fillStEvent() Starting..." << endm;
00314
00316 if(!tofCollection){
00317 tofCollection = new StTofCollection();
00318 mStEvent->setTofCollection(tofCollection);
00319 }
00320
00322 StTofCollection* mtofCollection = mStEvent->tofCollection();
00323 if(mtofCollection){
00325 if(mtofCollection->rawdataPresent()) {
00327 StSPtrVecTofRawData& rawTofVec = mtofCollection->tofRawData();
00328 LOG_INFO << " StEvent TofRawDataCollection has " << rawTofVec.size() << " entries..." << endm;
00329 }
00330 else LOG_INFO << " - StEvent TofRawDataCollection does not Exist" << endm;
00331 }
00332 else {
00333 LOG_INFO << " - StEvent tofCollection does not Exist" << endm;
00334 LOG_INFO << " - StEvent tofRawDataCollection does not Exist" << endm;
00335 }
00336 }