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
00057
00058
00059
00060
00061
00063
00086 #include "StTofMaker.h"
00087 #include <stdlib.h>
00088 #include "StMessMgr.h"
00089 #include "StEventTypes.h"
00090 #include "StEvent/StTofData.h"
00091 #include "StEvent/StTofRawData.h"
00092 #include "StTofUtil/StTofGeometry.h"
00093 #include "StTofUtil/StTofDataCollection.h"
00094 #include "StTofUtil/StTofRawDataCollection.h"
00095 #include "StDaqLib/GENERIC/EventReader.hh"
00096 #include "StDaqLib/TOF/TOF_Reader.hh"
00097 #include "StDAQMaker/StDAQReader.h"
00098 #include "tables/St_TofTag_Table.h"
00099 #include "TFile.h"
00100 #include "TH1.h"
00101
00102 ClassImp(StTofMaker)
00103
00104
00105
00106 StTofMaker::StTofMaker(const char *name):StMaker(name) {
00107 drawinit=kFALSE;
00108 mTofGeom = 0;
00109 }
00110
00112 StTofMaker::~StTofMaker(){}
00113
00114
00115
00117 Int_t StTofMaker::Init(){
00118
00119 nAdcHitHisto = new TH1S("tof_nadchit","Crude No. ADC Hits/Event",181,-0.5,180.5);
00120 nTdcHitHisto = new TH1S("tof_ntdchit","Crude No. TDC Hits/Event",185,-0.5,184.5);
00121 return StMaker::Init();
00122 }
00123
00124
00126 Int_t StTofMaker::InitRun(int runnumber){
00127 LOG_INFO << "StTofMaker::InitRun -- initializing TofGeometry --" << endm;
00128 mTofGeom = new StTofGeometry();
00129 mTofGeom->init(this);
00130 return kStOK;
00131 }
00132
00133
00134
00136 Int_t StTofMaker::FinishRun(int runnumber){
00137 LOG_INFO << "StTofMaker::FinishRun -- cleaning up TofGeometry --" << endm;
00138 if (mTofGeom) delete mTofGeom;
00139 mTofGeom=0;
00140 return 0;
00141 }
00142
00143
00144
00145
00147 Int_t StTofMaker::Make(){
00148
00149 LOG_INFO << "StTofMaker::Make() -- All Your Base Are Belong To Us --" << endm;
00150 StTofDataCollection myDataCollection;
00151 mDataCollection = &myDataCollection;
00152 mTofCollectionPresent = 0;
00153 mDataCollectionPresent = 0;
00154
00155
00156 StTofRawDataCollection myRawDataCollection;
00157 mRawDataCollection = &myRawDataCollection;
00158 mRawDataCollectionPresent = 0;
00159
00160
00161
00162 tofTag = -99;
00163 mEvent = (StEvent *) GetInputDS("StEvent");
00164 if (mEvent) {
00165 LOG_INFO << "StTofMaker Checking for Tof and TofData collections ..." << endm;
00166 mTheTofCollection = mEvent->tofCollection();
00167 if(mTheTofCollection) {
00168 mTofCollectionPresent = 1;
00169 LOG_INFO << " + tofCollection Exists" << endm;
00170
00171 if(mTheTofCollection->dataPresent()) {
00172 LOG_INFO << " + tofDataCollection Exists" << endm;
00173 mDataCollectionPresent = 1;
00174 } else if(mTheTofCollection->rawdataPresent()) {
00175 mRawDataCollectionPresent = 1;
00176 }
00177 else LOG_INFO << " - tofDataCollection & tofRawDataCollection does not exist" << endm;
00178
00179 } else {
00180 LOG_INFO << " - tofCollection does not exist" << endm;
00181 LOG_INFO << " - tofDataCollection & tofRawDataCollection does not exist" << endm;
00182 }
00183
00184 if (!mTheTofCollection){
00185 LOG_INFO << "StTofMaker Creating tofCollection in StEvent ... ";
00186 mTheTofCollection = new StTofCollection();
00187 mEvent->setTofCollection(mTheTofCollection);
00188 mTheTofCollection = mEvent->tofCollection();
00189 if (mTheTofCollection) LOG_INFO << "OK"<< endm;
00190 else LOG_INFO << "FAILED" << endm;
00191 }
00192 }
00193 else LOG_INFO << "StTofMaker No StEvent structures detected ... not good!" << endm;
00194
00195
00196
00197
00198 if(!mDataCollectionPresent) {
00199 if (m_Mode ==0) {
00200 LOG_INFO << "StTofMaker Will get real data from TOFpDAQ Reader ... " << endm;
00201 mTheTofData = GetDataSet("StDAQReader");
00202 if (!mTheTofData) {
00203 LOG_INFO << "StTofMaker No StDAQReader dataset. Event skipped" << endm;
00204 return kStWarn;
00205 }
00206 mTheDataReader = (StDAQReader*)(mTheTofData->GetObject());
00207 if (!mTheDataReader) {
00208 LOG_INFO << "StTofMaker No StDAQReader object. Event skipped" << endm;
00209 return kStWarn;
00210 }
00211 if (!(mTheDataReader->TOFPresent())) {
00212 LOG_INFO << "StTofMaker TOF is not in datastream. Event skipped" << endm;
00213 return kStWarn;
00214 }
00215
00216 mTheTofReader = mTheDataReader->getTOFReader();
00217 if (!mTheTofReader) {
00218 LOG_INFO << "StTofMaker Failed to getTofReader()...." << endm;
00219 return kStWarn;
00220 }
00221
00222
00223
00224 #ifdef TOFP_DEBUG
00225 TOF_Reader* MyTest = dynamic_cast<TOF_Reader*>(mTheDataReader->getTOFReader());
00226 if (MyTest) MyTest->printRawData();
00227 if (MyTest->year2Data()) LOG_INFO << "StTofMaker: year2 data - TOFp+pVPD" << endm;
00228 if (MyTest->year3Data()) LOG_INFO << "StTofMaker: year3 data - TOFp+pVPD+TOFr" << endm;
00229 if (MyTest->year4Data()) LOG_INFO << "StTofMaker: year4 data - TOFp+pVPD+TOFrprime" << endm;
00230 if (MyTest->year5Data()) LOG_INFO << "StTofMaker: year5 data - TOFr5+pVPD " << endm;
00231 #endif
00232
00233
00234
00235
00236 if (mTheTofReader->year2Data()||mTheTofReader->year3Data()||mTheTofReader->year4Data()){
00237 int nadchit=0;
00238 int ntdchit=0;
00239 int iStrobe = 0;
00240
00241
00242 int tdcHitMax=1600;
00243 int pvpdStrobeMin=1500;
00244 if (mTheTofReader->year3Data()||mTheTofReader->year4Data()){
00245 tdcHitMax=880;
00246 pvpdStrobeMin=950;
00247 }
00248
00249 for (int i=0;i<48;i++){
00250 unsigned short slatid = mTofGeom->daqToSlatId(i);
00251 unsigned short rawAdc = mTheTofReader->GetAdcFromSlat(i);
00252 unsigned short rawTdc = mTheTofReader->GetTdcFromSlat(i);
00253 short rawTc = 0;
00254 if (i<32) rawTc = mTheTofReader->GetTc(i);
00255 unsigned short rawSc = 0;
00256 if (i<12) rawSc = mTheTofReader->GetSc(i);
00257
00258 StTofData *rawTofData = new StTofData(slatid,rawAdc,rawTdc,rawTc,rawSc,0,0);
00259 mDataCollection->push_back(rawTofData);
00260 if(i<41) {
00261 if (rawAdc> 50) nadchit++;
00262 if (rawTdc<tdcHitMax) ntdchit++;
00263 }
00264 if(i>41) {
00265 if (rawTdc>pvpdStrobeMin) iStrobe++;
00266 }
00267 }
00268 if (mTheTofReader->year3Data()){
00269 for (int i=48;i<132;i++){
00270
00271 unsigned short id = (100-48)+i;
00272 unsigned short rawAdc = mTheTofReader->GetAdc(i);
00273 unsigned short rawTdc = 0;
00274 if (i<120) rawTdc = mTheTofReader->GetTdc(i);
00275
00276 StTofData *rawTofData = new StTofData(id,rawAdc,rawTdc,0,0,0,0);
00277 mDataCollection->push_back(rawTofData);
00278 if ((i>59) && (rawAdc>50)) nadchit++;
00279 if ((i<120) && (rawTdc<tdcHitMax)) ntdchit++;
00280 }
00281 }
00282
00283 if (mTheTofReader->year4Data()){
00284 for (int i=48;i<184;i++){
00285
00286 unsigned short id = (100-48)+i;
00287 unsigned short rawAdc = 0;
00288 if(i<180) {
00289 rawAdc = mTheTofReader->GetAdc(i);
00290 }
00291
00292 unsigned short rawTdc = 0;
00293 rawTdc = mTheTofReader->GetTdc(i);
00294
00295 StTofData *rawTofData = new StTofData(id,rawAdc,rawTdc,0,0,0,0);
00296 mDataCollection->push_back(rawTofData);
00297 if ((i>59) && (rawAdc>50)) nadchit++;
00298 if ((rawTdc<tdcHitMax)) ntdchit++;
00299 }
00300 }
00301
00302
00303
00304
00305 if (iStrobe>4) {
00306 LOG_INFO << "StTofMaker ... Strobe Event:" << iStrobe << endm;
00307 tofTag = -1;
00308 nAdcHitHisto->Fill(-1.);
00309 nTdcHitHisto->Fill(-1.);
00310 } else {
00311 LOG_INFO << "StTofMaker ... Beam Event: ~" << nadchit << " ADC and ~"
00312 << ntdchit << " TDC Raw Hits in TRAY" << endm;
00313 tofTag = nadchit;
00314 nAdcHitHisto->Fill(nadchit);
00315 nTdcHitHisto->Fill(ntdchit);
00316 }
00317
00318
00319 }
00320
00321
00322 if (mTheTofReader->year5Data()){
00323 for (int i=0;i<(int)mTheTofReader->GetNLeadingHits();i++){
00324 unsigned short flag;
00325 unsigned short chn=mTheTofReader->GetLeadingGlobalTdcChan(i);
00326 unsigned int tdc=mTheTofReader->GetLeadingTdc(i);
00327 flag=1;
00328 unsigned short quality = 1;
00329 StTofRawData *rawTofData1 = new StTofRawData(flag,chn,tdc,quality);
00330 mRawDataCollection->push_back(rawTofData1);
00331 }
00332 for (int i=0;i<(int)mTheTofReader->GetNTrailingHits();i++){
00333 unsigned short flag;
00334 unsigned short chn=mTheTofReader->GetTrailingGlobalTdcChan(i);
00335 unsigned int tdc=mTheTofReader->GetTrailingTdc(i);
00336 flag=2;
00337 unsigned short quality = 1;
00338 StTofRawData *rawTofData1 = new StTofRawData(flag,chn,tdc,quality);
00339 mRawDataCollection->push_back(rawTofData1);
00340 }
00341 for (int i=0;i<TOF_MAX_TDC_CHANNELS;i++){
00342 unsigned int rawLdTdc=mTheTofReader->GetLdTdc(i);
00343 unsigned int rawTrTdc=mTheTofReader->GetTrTdc(i);
00344 StTofData *rawTofData = new StTofData(i,0,0,0,0,rawLdTdc,rawTrTdc);
00345 mDataCollection->push_back(rawTofData);
00346 }
00347
00348 }
00349
00350 } else if(m_Mode == 1)
00351 LOG_INFO << "StTofMaker No special action required for DataCollection"<<endm;
00352 else {
00353 LOG_INFO << "WRONG SetMode (" << m_Mode << ")! "
00354 << "... should be either 0 (DAQ reader) or 1(no action, SIM)" << endm;
00355 return kStOK;
00356 }
00357
00358
00359 }
00360
00361
00362
00363 LOG_INFO << "StTofMaker tofTag = " << tofTag << endm;
00364 if (mEvent) storeTag();
00365
00366
00367
00368 if (mEvent) this->fillStEvent();
00369 mDataCollection=0;
00370 LOG_INFO << "StTofMaker::Make() -- see you next event --" << endm;
00371
00372 return kStOK;
00373 }
00374
00375
00376
00378 void StTofMaker::fillStEvent() {
00379
00380 LOG_INFO << "StTofMaker::fillStEvent() Starting..." << endm;
00381
00382
00383 if(!mTheTofCollection){
00384 mTheTofCollection = new StTofCollection();
00385 mEvent->setTofCollection(mTheTofCollection);
00386 }
00387
00388
00389 if(mDataCollectionPresent != 1) {
00390 LOG_INFO << "StTofMaker::fillStEvent() Size of mDataCollection = " << mDataCollection->size() << endm;
00391 for(size_t jj = 0; jj < mDataCollection->size(); jj++)
00392 mTheTofCollection->addData(mDataCollection->getData(jj));
00393 }
00394 if(mRawDataCollectionPresent != 1) {
00395 LOG_INFO << "StTofMaker::fillStEvent() Size of mRawDataCollection = " << mRawDataCollection->size() << endm;
00396 for(size_t jj = 0; jj < mRawDataCollection->size(); jj++)
00397 mTheTofCollection->addRawData(mRawDataCollection->getRawData(jj));
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407 LOG_INFO << "StTofMaker::fillStEvent() Verifying TOF StEvent data ..." << endm;
00408 StTofCollection* mmTheTofCollection = mEvent->tofCollection();
00409 if(mmTheTofCollection){
00410 LOG_INFO << " + StEvent tofCollection Exists" << endm;
00411 if(mmTheTofCollection->dataPresent()) {
00412 LOG_INFO << " + StEvent TofDataCollection Exists" << endm;
00413 StSPtrVecTofData& rawTofVec = mmTheTofCollection->tofData();
00414 #ifdef TOFP_DEBUG
00415 for (size_t i = 0; i < rawTofVec.size(); i++) {
00416 StTofData* p = rawTofVec[i];
00417 LOG_INFO << *p;
00418 }
00419 #endif
00420 LOG_INFO << " StEvent TofDataCollection has " << rawTofVec.size() << " entries..." << endm;
00421 }
00422 else LOG_INFO << " - StEvent TofDataCollection does not Exist" << endm;
00423 }
00424 else {
00425 LOG_INFO << " - StEvent tofCollection does not Exist" << endm;
00426 LOG_INFO << " - StEvent tofDataCollection does not Exist" << endm;
00427 }
00428 }
00429
00430
00432 void StTofMaker::storeTag(){
00433
00434 St_TofTag *tagTable = new St_TofTag("TofTag",1);
00435 if (!tagTable) return;
00436 tagTable->SetNRows(1);
00437
00438
00439 AddData(tagTable,".data");
00440 TofTag_st *pTofTag = tagTable->GetTable();
00441
00442 if (pTofTag) {
00443 pTofTag->tofEventType = tofTag;
00444 LOG_INFO << "StTofMaker::storeTag() tofTag stored" << endm;
00445 }
00446 else
00447 LOG_INFO << "StTofMaker::storeTag() unable to store tofTag" << endm;
00448
00449 }
00450
00451
00453 Int_t StTofMaker::Finish(){
00454
00455 return kStOK;
00456 }