00001 #include "GaudiKernel/Kernel.h"
00002 #include "GaudiKernel/IInterface.h"
00003 #include "GaudiKernel/IIncidentSvc.h"
00004 #include "GaudiKernel/Incident.h"
00005 #include "GaudiKernel/IIncidentListener.h"
00006 #include "GaudiKernel/StatusCode.h"
00007 #include "GaudiKernel/SvcFactory.h"
00008 #include "GaudiKernel/MsgStream.h"
00009 #include "GaudiKernel/IDataProviderSvc.h"
00010 #include "GaudiKernel/SmartDataPtr.h"
00011 #include "GaudiKernel/DataSvc.h"
00012 #include "EventModel/EventHeader.h"
00013 #include "Identifier/Identifier.h"
00014 #include "Identifier/TofID.h"
00015 #include "TofRawEvent/TofDigi.h"
00016 #include "TofCaliSvc/ITofCaliSvc.h"
00017 #include "TofQCorrSvc/ITofQCorrSvc.h"
00018 #include "TofQElecSvc/ITofQElecSvc.h"
00019 #include "DetVerSvc/IDetVerSvc.h"
00020 #include "RawDataProviderSvc/TofRawDataProvider.h"
00021
00022 #include "RawEvent/RawDataUtil.h"
00023
00024 #include <cmath>
00025
00026 #include "GaudiKernel/ThreadGaudi.h"
00027
00028
00029 using namespace std;
00030
00031 IDetVerSvc* detVerSvc;
00032 ITofCaliSvc* tofCaliSvc;
00033 ITofQCorrSvc* tofQCorrSvc;
00034 ITofQElecSvc* tofQElecSvc;
00035
00036 TofRawDataProvider::TofRawDataProvider() :
00037 RawDataProviderBase(),
00038 m_hasFilled(0)
00039 {}
00040
00041
00042 TofRawDataProvider::TofRawDataProvider( const char* name ) :
00043 RawDataProviderBase( name ),
00044 m_hasFilled(0)
00045 {}
00046
00047
00048 TofRawDataProvider::~TofRawDataProvider() {
00049 IterTofDataMap iter = m_tofDataMap.begin();
00050 for( ; iter != m_tofDataMap.end(); iter++ ) {
00051 delete (*iter).second;
00052 }
00053 m_tofDataMap.clear();
00054
00055 m_tofDataMapOnline.clear();
00056 m_tofDataVectorOnline.clear();
00057 m_tofDataMapEstime.clear();
00058 m_tofDataVectorEstime.clear();
00059 m_tofDataMapTof.clear();
00060 m_tofDataVectorTof.clear();
00061 m_tofDataMapEmc.clear();
00062 m_tofDataVectorEmc.clear();
00063
00064 return;
00065 }
00066
00067
00068 StatusCode TofRawDataProvider::initialize( bool mode, ISvcLocator* pSvcLoc, IMessageSvc* pMsg ) {
00069 MsgStream log( m_msgSvc, m_name );
00070 RawDataProviderBase::initialize( pSvcLoc,pMsg );
00071
00072
00073 StatusCode sc_det = m_svcLocator->service("DetVerSvc", detVerSvc);
00074 if( sc_det == StatusCode::SUCCESS ) {
00075 log << MSG::INFO << "TofRawDataProvider Get Detector Version Service Sucessfully!" << endreq;
00076 }
00077 else {
00078 log << MSG::ERROR << "TofRawDataProvider Can NOT Retrieve DetVerSvc instance" << endreq;
00079 return StatusCode::FAILURE;
00080 }
00081
00082
00083 StatusCode scc = m_svcLocator->service("TofCaliSvc", tofCaliSvc);
00084 if( scc == StatusCode::SUCCESS ) {
00085 log << MSG::INFO << "TofRec Get Calibration Service Sucessfully!" << endreq;
00086 }
00087 else if(!mode) {
00088 log << MSG::ERROR << "TofRec Get Calibration Service Failed !" << endreq;
00089 return StatusCode::FAILURE;
00090 }
00091
00092
00093 StatusCode scq = m_svcLocator->service("TofQCorrSvc", tofQCorrSvc);
00094 if (scq == StatusCode::SUCCESS) {
00095 log << MSG::INFO << "TofRec Get Q Correction Service Sucessfully!" << endreq;
00096 } else if(!mode){
00097 log << MSG::ERROR << "TofRec Get Q Correction Service Failed !" << endreq;
00098 return StatusCode::FAILURE;
00099 }
00100
00101
00102 StatusCode sce = m_svcLocator->service("TofQElecSvc", tofQElecSvc);
00103 if (sce == StatusCode::SUCCESS) {
00104 log << MSG::INFO << "TofRec Get Q Electronics Calibration Service Sucessfully!" << endreq;
00105 } else if(!mode){
00106 log << MSG::ERROR << "TofRec Get Q Electronics Calibration Service Failed !" << endreq;
00107 return StatusCode::FAILURE;
00108 }
00109
00110 return StatusCode::SUCCESS;
00111 }
00112
00113
00114 void TofRawDataProvider::handle(const Incident& inc){
00115 MsgStream log( m_msgSvc, m_name );
00116 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
00117 if ( inc.type() == "BeginEvent" ){
00118 log << MSG::DEBUG << "Begin Event" << endreq;
00119 IterTofDataMap iter = m_tofDataMap.begin();
00120 for( ; iter != m_tofDataMap.end(); iter++ ) {
00121 delete (*iter).second;
00122 }
00123 IterTofDataMap iterOnline = m_tofDataMapOnline.begin();
00124 for( ; iterOnline != m_tofDataMapOnline.end(); iterOnline++ ) {
00125 delete (*iterOnline).second;
00126 }
00127 m_tofDataMap.clear();
00128 m_tofDataMapOnline.clear();
00129 m_tofDataVectorOnline.clear();
00130 m_tofDataMapEstime.clear();
00131 m_tofDataVectorEstime.clear();
00132 m_tofDataMapTof.clear();
00133 m_tofDataVectorTof.clear();
00134 m_tofDataMapEmc.clear();
00135 m_tofDataVectorEmc.clear();
00136
00137 m_hasFilled = false;
00138 }
00139 return;
00140 }
00141
00142
00143
00144 void TofRawDataProvider::tofDataMapFull() {
00145
00146 MsgStream log(m_msgSvc, m_name);
00147 log << MSG::INFO << "TofRawDataProvider::tofDataMapFull()" << endreq;
00148
00149 if( !m_tofDataMap.empty() ) {
00150
00151 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: m_tofDataMap is NOT empty!" << endreq;
00152
00153 IterTofDataMap iter = m_tofDataMap.begin();
00154 for( ; iter != m_tofDataMap.end(); iter++ ) {
00155 delete (*iter).second;
00156 }
00157 m_tofDataMap.clear();
00158 }
00159
00160 std::string evtDataSvc_name("EventDataSvc");
00161 if(isGaudiThreaded(m_name)){
00162 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
00163 }
00164
00165
00166 IDataProviderSvc* eventSvc;
00167 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(),eventSvc, true );
00168 if( !sc.isSuccess() ) {
00169 log << MSG::FATAL << "TofRawDataProvider::tofDataMapFull: ERROR Could not load EventDataSvc" << endreq;
00170 return;
00171 }
00172
00173
00174 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,"/Event/EventHeader");
00175 if( !eventHeader ) {
00176 log << MSG::FATAL << "TofRawDataProvider could not find Event Header!" << endreq;
00177 return;
00178 }
00179 m_run = eventHeader->runNumber();
00180 m_event = eventHeader->eventNumber();
00181
00182 bool mc = ( m_run < 0 ) ? true:false;
00183 bool qCorr = bool( tofCaliSvc->QCorr() );
00184 qCorr = qCorr && (!mc);
00185 bool qElec = bool( tofCaliSvc->QElec() );
00186 bool misLable = bool( tofCaliSvc->MisLable() );
00187 misLable = ( !mc && misLable );
00188
00189 int identmp = -1;
00190 vector<int> deadId;
00191 for( unsigned int i=0; i<5; i++ ) {
00192 identmp = tofCaliSvc->BrEast(i);
00193 if( identmp != 0x2fffffff ) {
00194 deadId.push_back( identmp );
00195 }
00196 identmp = tofCaliSvc->BrWest(i);
00197 if( identmp != 0x2fffffff ) {
00198 deadId.push_back( identmp );
00199 }
00200 identmp = tofCaliSvc->Endcap(i);
00201 if( identmp != 0x2fffffff ) {
00202 deadId.push_back( identmp );
00203 }
00204 }
00205
00206
00207 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
00208 if( !tofDigiCol ) {
00209 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: Could not find Tof Digi Data!" << endreq;
00210 return;
00211 }
00212
00213 int qnumber = 0;
00214 int tnumber = 0;
00215
00216 std::vector<Adc*> chargeVec;
00217 std::vector<Tdc*> timeVec;
00218
00219 TofDigiCol::iterator iter = tofDigiCol->begin();
00220 for( ; iter != tofDigiCol->end(); iter++ ) {
00221 Identifier iden = (*iter)->identify();
00222 unsigned int iden_value = iden.get_value();
00223
00224 bool sameId = false;
00225 vector<int>::iterator iter_dead = deadId.begin();
00226 for( ; iter_dead != deadId.end(); iter_dead++ ) {
00227 if( iden_value == (*iter_dead) ) {
00228 sameId = true;
00229 break;
00230 }
00231 }
00232 if( sameId ) {
00233 if( mc ) { continue; }
00234 else {
00235 std::string bore;
00236 if( (TofID::barrel_ec(iden))==1 ) { bore=string("Barrel");}
00237 else if( (TofID::barrel_ec(iden))==0 ) { bore=string("East Endcap"); }
00238 else if( (TofID::barrel_ec(iden))==2 ) { bore=string("West Endcap"); }
00239 else if( (TofID::barrel_ec(iden))==3 ) { bore=string("ETF(MRPC)"); }
00240
00241 log << MSG::ERROR << "TofRawDataProvider::tofDataMapFull: Dead Channel Number is not Correct, please check TOF Calibration Constants! " << bore << endreq;
00242 }
00243 }
00244
00245 if( TofID::is_scin(iden) && !(TofID::is_barrel(iden) ) && (TofID::end(iden))==1 ) continue;
00246
00247 unsigned int overflow = (*iter)->getOverflow();
00248 if( TofID::is_scin(iden) && ( ( overflow & 0xfe000000 ) == 0xfe000000 ) ) continue;
00249
00250
00251
00252
00253
00254
00255
00256 if( m_run>=40203 && m_run<=43253 && TofID::is_mrpc( iden ) ) {
00257
00258 if( ( iden_value & 0x2fffffe0 ) == 0x2000c800 ) {
00259 iden_value = 0x2000c900 + ( iden_value & 0x1f );
00260 iden = Identifier( iden_value );
00261 }
00262
00263 if( ( iden_value & 0x2fffffe0 ) == 0x2000c820 ) {
00264 iden_value = 0x2000c8e0 + ( iden_value & 0x1f );
00265 iden = Identifier( iden_value );
00266 }
00267 }
00268
00269
00270
00271
00272
00273 bool multiQ = ( ( overflow & 0x8 ) != 0 );
00274 bool multiT = ( ( overflow & 0x4 ) != 0 );
00275
00276 unsigned int tdcChannel = (*iter)->getTimeChannel();
00277 unsigned int adcChannel = (*iter)->getChargeChannel();
00278 if( TofID::is_scin(iden) && ( ( overflow & 0x2 ) != 0 ) ) {
00279 adcChannel = ( adcChannel | 0x80000 );
00280 }
00281
00282 if( (adcChannel&0x7fffffff) != 0x7fffffff ) {
00283 Adc* adc = new Adc;
00284 if( qCorr ) adc->setCorr();
00285 if( qElec ) adc->setElec();
00286
00287
00288
00289 if( m_run>=40203 && m_run<=43253 && TofID::is_mrpc( iden ) ) {
00290 adcChannel += 0x18000;
00291 }
00292
00293
00294 adc->setValue( iden, adcChannel );
00295 qnumber++;
00296 adc->setNumber( qnumber );
00297 chargeVec.push_back( adc );
00298 }
00299
00300 if( tdcChannel != 0x7fffffff ) {
00301 Tdc* tdc = new Tdc;
00302
00303
00304
00305 if( m_run>=40203 && m_run<=43253 && TofID::is_mrpc( iden ) ) {
00306 tdcChannel += 0x18000;
00307 }
00308
00309
00310 tdc->setValue( tdcChannel );
00311 tnumber++;
00312 tdc->setNumber( tnumber );
00313 timeVec.push_back( tdc );
00314 }
00315
00316 if( multiT || multiQ ) {
00317 TofDigiCol::iterator iter_next = iter + 1;
00318 if( iter_next != tofDigiCol->end() ) {
00319 unsigned int idenNext_value = ((*iter_next)->identify()).get_value();
00320 if( iden_value == idenNext_value ) continue;
00321 }
00322 }
00323
00324 qnumber = 0;
00325 tnumber = 0;
00326
00327 std::vector<PmtData*> pmtDataVec;
00328 if( TofID::is_scin( iden ) ) {
00329 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
00330 for( ; iter_t != timeVec.end(); iter_t++ ) {
00331 int tclock = (*iter_t)->clock();
00332 PmtData* pmt = new PmtData;
00333 pmt->setIdentify( iden.get_value() );
00334 pmt->setTdc( (*iter_t) );
00335 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
00336 for( ; iter_q != chargeVec.end(); iter_q++ ) {
00337 if( (*iter_q)->times() != -1 ) { continue; }
00338 int qclock = (*iter_q)->clock();
00339 if( abs(tclock-qclock)<2 ) {
00340 if( ( pmt->quality() & 0x2 ) != 0 ) {
00341 if( (*iter_q)->value() > pmt->adc() ) {
00342 pmt->qtimesmm();
00343 pmt->setAdc( (*iter_q) );
00344 }
00345 }
00346 else {
00347 pmt->setAdc( (*iter_q) );
00348 }
00349 }
00350 }
00351 pmtDataVec.push_back( pmt );
00352 }
00353
00354 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
00355 for( ; iter_q != chargeVec.end(); iter_q++ ) {
00356 if( (*iter_q)->times() != -1 ) { continue; }
00357 PmtData* pmt = new PmtData;
00358 pmt->setIdentify( iden.get_value() );
00359 pmt->setAdc( (*iter_q) );
00360 pmtDataVec.push_back( pmt );
00361 }
00362
00363 }
00364
00365 if( TofID::is_mrpc( iden ) ) {
00366 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
00367 for( ; iter_t != timeVec.end(); iter_t++ ) {
00368 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
00369 for( ; iter_q != chargeVec.end(); iter_q++ ) {
00370 if( ( (*iter_q)->qtc() - (*iter_t)->value() ) > totForward && ( (*iter_q)->qtc() - (*iter_t)->value() ) < totBackward ) {
00371 PmtData* pmt = new PmtData;
00372 pmt->setIdentify( iden.get_value() );
00373 pmt->setTdc( (*iter_t) );
00374 pmt->setAdc( (*iter_q) );
00375 pmtDataVec.push_back( pmt );
00376 }
00377 }
00378 if( (*iter_t)->times() == -1 ) {
00379 PmtData* pmt = new PmtData;
00380 pmt->setTdc( (*iter_t) );
00381 pmtDataVec.push_back( pmt );
00382 }
00383 }
00384
00385 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
00386 for( ; iter_q != chargeVec.end(); iter_q++ ) {
00387 if( (*iter_q)->times() != -1 ) { continue; }
00388 PmtData* pmt = new PmtData;
00389 pmt->setIdentify( iden.get_value() );
00390 pmt->setAdc( (*iter_q) );
00391 pmtDataVec.push_back( pmt );
00392 }
00393
00394 }
00395
00396 chargeVec.clear();
00397 timeVec.clear();
00398
00399 unsigned int iden_value_key = (iden_value & 0xfffffffe );
00400 if( TofID::is_scin( iden ) ) {
00401 int barrel_ec = TofID::barrel_ec( iden );
00402
00403 int tofid = TofID::phi_module( iden );
00404 int end = TofID::end( iden );
00405 if( ( barrel_ec == 0 ) || ( barrel_ec == 2 ) ) {
00406 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
00407 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
00408 TofData* tof = new TofData;
00409 if( misLable ) {
00410 tof->setMisLable();
00411 if( barrel_ec==2 && tofid==42 ) {
00412 unsigned int iden91 = TofID::getIntID( 2, 0, 91-48, 0 );
00413 iden_value_key = iden91;
00414 iden = TofID::cell_id( iden91 );
00415 }
00416 if( barrel_ec==2 && tofid==43 ) {
00417 unsigned int iden90 = TofID::getIntID( 2, 0, 90-48, 0 );
00418 iden_value_key = iden90;
00419 iden = TofID::cell_id( iden90 );
00420 }
00421 }
00422 tof->setIdentify( iden );
00423 tof->setForward( (*iter_pmt) );
00424 tof->setTMatched( true );
00425 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00426 }
00427 }
00428 else if( barrel_ec == 1 ) {
00429 unsigned int count = m_tofDataMap.count( iden_value_key );
00430 if( count == 0 ) {
00431 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
00432 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
00433 TofData* tof = new TofData;
00434 tof->setIdentify( iden );
00435 if( end == 0 ) {
00436 tof->setForward( (*iter_pmt) );
00437 }
00438 else {
00439 tof->setBackward( (*iter_pmt) );
00440 }
00441 tof->setTMatched( true );
00442 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00443 }
00444 }
00445 else {
00446 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
00447 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
00448 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
00449 bool used = false;
00450 IterTofDataMap iter = range.first;
00451 for( unsigned int tofDataNumber = 0; tofDataNumber < count; tofDataNumber++, iter++ ) {
00452
00453 bool matched = false;
00454 if( end == 0 ) {
00455 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
00456 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
00457 double time1 = (*iter_pmt)->tdc();
00458 double time2 = ((*iter).second)->tdc2();
00459 matched = ( abs(time1-time2)<timeDiff );
00460 }
00461 else {
00462 if( ( ((*iter).second)->quality() & 0x2 ) != 0 ) {
00463 double time1 = (*iter_pmt)->tclock();
00464 double time2 = (*iter_pmt)->qclock();
00465 double time3 = ((*iter).second)->qclock2();
00466 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
00467 }
00468 }
00469 }
00470 else {
00471 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) {
00472 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
00473 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
00474 double time1 = (*iter_pmt)->qclock();
00475 double time2 = ((*iter).second)->tclock2();
00476 double time3 = ((*iter).second)->qclock2();
00477 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
00478 }
00479 }
00480 else {
00481 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
00482 double time1 = (*iter_pmt)->qclock();
00483 double time2 = ((*iter).second)->qclock2();
00484 matched = ( abs(time1-time2)<=tClockDiff );
00485 }
00486 }
00487 }
00488 }
00489
00490 if( matched ) {
00491 used = true;
00492 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
00493 ((*iter).second)->setForward( (*iter_pmt) );
00494 }
00495 else {
00496 TofData* tof = new TofData;
00497 tof->setIdentify( iden );
00498 tof->setForward( (*iter_pmt) );
00499 tof->setBackward( ((*iter).second)->backward() );
00500 tof->setTMatched( true );
00501 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00502 }
00503 }
00504
00505 }
00506 else {
00507 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
00508 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
00509 double time1 = (*iter_pmt)->tdc();
00510 double time2 = ((*iter).second)->tdc1();
00511 matched = ( abs(time1-time2)<timeDiff );
00512 }
00513 else {
00514 if( ( ((*iter).second)->quality() & 0x8 ) != 0 ) {
00515 double time1 = (*iter_pmt)->tclock();
00516 double time2 = (*iter_pmt)->qclock();
00517 double time3 = ((*iter).second)->qclock1();
00518 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
00519 }
00520 }
00521 }
00522 else {
00523 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) {
00524 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
00525 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
00526 double time1 = (*iter_pmt)->qclock();
00527 double time2 = ((*iter).second)->tclock1();
00528 double time3 = ((*iter).second)->qclock1();
00529 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
00530 }
00531 else {
00532 }
00533 }
00534 else {
00535 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
00536 double time1 = (*iter_pmt)->qclock();
00537 double time2 = ((*iter).second)->qclock1();
00538 matched = ( abs(time1-time2)<=tClockDiff );
00539 }
00540 }
00541 }
00542 }
00543
00544 if( matched ) {
00545 used = true;
00546 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
00547 ((*iter).second)->setBackward( (*iter_pmt) );
00548 }
00549 else {
00550 TofData* tof = new TofData;
00551 tof->setIdentify( iden );
00552 tof->setForward( ((*iter).second)->forward() );
00553 tof->setBackward( (*iter_pmt) );
00554 tof->setTMatched( true );
00555 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00556 }
00557 }
00558 }
00559 }
00560
00561 if( ! used ) {
00562 TofData* tof = new TofData;
00563 tof->setIdentify( iden );
00564 if( end == 0 ) {
00565 tof->setForward( (*iter_pmt) );
00566 }
00567 else {
00568 tof->setBackward( (*iter_pmt) );
00569 }
00570 tof->setTMatched( true );
00571 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00572 }
00573 }
00574 }
00575 }
00576 }
00577
00578 if( TofID::is_mrpc( iden ) ) {
00579
00580
00581
00582
00583 int end = TofID::end( iden );
00584
00585 unsigned int count = m_tofDataMap.count( iden_value_key );
00586 if( count == 0 ) {
00587 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
00588 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
00589 TofData* tof = new TofData;
00590 tof->setIdentify( iden );
00591 if( end == 0 ) {
00592 tof->setForward( (*iter_pmt) );
00593 }
00594 else {
00595 tof->setBackward( (*iter_pmt) );
00596 }
00597 tof->setTMatched( true );
00598 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00599 }
00600 }
00601 else {
00602 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
00603 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
00604 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
00605 bool used = false;
00606 IterTofDataMap iter = range.first;
00607 for( unsigned int tofDataNumber = 0; tofDataNumber < count; tofDataNumber++, iter++ ) {
00608 bool matched = false;
00609 if( end == 0 ) {
00610 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
00611 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
00612 double time1 = (*iter_pmt)->tdc();
00613 double time2 = ((*iter).second)->tdc2();
00614 matched = ( abs(time1-time2)<timeDiffMRPC );
00615 }
00616 }
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649 if( matched ) {
00650 used = true;
00651 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
00652 ((*iter).second)->setForward( (*iter_pmt) );
00653 }
00654 else {
00655 TofData* tof = new TofData;
00656 tof->setIdentify( iden );
00657 tof->setForward( (*iter_pmt) );
00658 tof->setBackward( ((*iter).second)->backward() );
00659 tof->setTMatched( true );
00660 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00661 }
00662 }
00663 }
00664 else {
00665 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
00666 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
00667 double time1 = (*iter_pmt)->tdc();
00668 double time2 = ((*iter).second)->tdc1();
00669 matched = ( abs(time1-time2)<timeDiffMRPC );
00670 }
00671 }
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704 if( matched ) {
00705 used = true;
00706 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
00707 ((*iter).second)->setBackward( (*iter_pmt) );
00708 }
00709 else {
00710 TofData* tof = new TofData;
00711 tof->setIdentify( iden );
00712 tof->setForward( ((*iter).second)->forward() );
00713 tof->setBackward( (*iter_pmt) );
00714 tof->setTMatched( true );
00715 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00716 }
00717 }
00718 }
00719 }
00720
00721 if( ! used ) {
00722 TofData* tof = new TofData;
00723 tof->setIdentify( iden );
00724 if( end == 0 ) {
00725 tof->setForward( (*iter_pmt) );
00726 }
00727 else {
00728 tof->setBackward( (*iter_pmt) );
00729 }
00730 tof->setTMatched( true );
00731 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
00732 }
00733 }
00734 }
00735 }
00736
00737 pmtDataVec.clear();
00738
00739 }
00740
00741 return;
00742
00743 }
00744
00745
00746
00747 TofDataMap& TofRawDataProvider::tofDataMapOnlineMode(uint32_t control) {
00748
00749 MsgStream log(m_msgSvc, m_name);
00750 log << MSG::INFO << "TofRawDataProvider::tofDataMapOnlineMode()" << endreq;
00751
00752 if( ! m_tofDataMapOnline.empty() ) {
00753 if(control){
00754 IterTofDataMap iter = m_tofDataMapOnline.begin();
00755 for( ; iter != m_tofDataMapOnline.end(); iter++ ) {
00756 delete (*iter).second;
00757 }
00758 m_tofDataMapOnline.clear();
00759 }
00760 else return m_tofDataMapOnline;
00761 }
00762
00763 std::string evtDataSvc_name("EventDataSvc");
00764 if(isGaudiThreaded(m_name)){
00765 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
00766 }
00767
00768
00769 IDataProviderSvc* eventSvc;
00770 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(), eventSvc, true );
00771 if( !sc.isSuccess() ) {
00772 log << MSG::FATAL << "TofRawDataProvider::tofDataMapOnlineMode(): ERROR Could not load EventDataSvc" << endreq;
00773 return m_tofDataMapOnline;
00774 }
00775
00776
00777 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
00778 if( !tofDigiCol ) {
00779 log << MSG::WARNING << "TofRawDataProvider::tofDataMapOnlineMode(): Could not find Tof Digi Data!" << endreq;
00780 return m_tofDataMapOnline;
00781 }
00782
00783 TofDigiCol::iterator iter = tofDigiCol->begin();
00784 for( ; iter != tofDigiCol->end(); iter++ ) {
00785 unsigned int overflow = (*iter)->getOverflow();
00786 if( ( overflow & 0xfe000000 ) == 0xfe000000 ) continue;
00787
00788
00789
00790 bool noT = ( ( overflow & 0x10 ) != 0 );
00791
00792
00793 if( noT ) continue;
00794
00795 Identifier iden = (*iter)->identify();
00796 unsigned int iden_value = iden.get_value();
00797 int barrel_ec = TofID::barrel_ec(iden);
00798 int id = TofID::phi_module(iden);
00799 int end = TofID::end(iden);
00800
00801 unsigned int tdcChannel = (*iter)->getTimeChannel();
00802 if( tdcChannel == 0x7fffffff ) continue;
00803
00804 Tdc* tdc = new Tdc;
00805 tdc->setValue( tdcChannel );
00806 PmtData* pmt = new PmtData;
00807 pmt->setTdc( tdc );
00808
00809 unsigned int iden_value_key = ( iden_value & 0xfffffffe );
00810 if( barrel_ec == 0 || barrel_ec == 2 ) {
00811 TofData* tof = new TofData;
00812 tof->setIdentify( iden );
00813 tof->setForward( pmt );
00814 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
00815 }
00816 else if( barrel_ec == 1 || barrel_ec == 3 ) {
00817 unsigned int count = m_tofDataMapOnline.count( iden_value_key );
00818
00819 if( count == 0 ) {
00820 TofData* tof = new TofData;
00821 tof->setIdentify( iden );
00822 if( end == 0 ) {
00823 tof->setForward( pmt );
00824 }
00825 else {
00826 tof->setBackward( pmt );
00827 }
00828 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
00829 }
00830 else {
00831 bool used = false;
00832 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMapOnline.equal_range( iden_value_key );
00833 IterTofDataMap iter = range.first;
00834 for( unsigned int i=0; i<count; i++, iter++ ) {
00835 if( ( end == 0 ) && ( ( ( (*iter).second)->quality() & 0x1 ) != 0 ) ) {
00836 double time1 = pmt->tdc();
00837 double time2 = ((*iter).second)->tdc2();
00838 if( ( TofID::is_scin( iden ) && abs(time1-time2)<timeDiff ) || ( TofID::is_scin( iden ) && abs(time1-time2)<timeDiffMRPC ) ) {
00839 used = true;
00840 if( ( ( (*iter).second)->quality() & 0x4 ) == 0 ) {
00841 ((*iter).second)->setForward( pmt );
00842 }
00843 else {
00844 TofData* tof = new TofData;
00845 tof->setIdentify( iden );
00846 tof->setForward( pmt );
00847 tof->setBackward( ((*iter).second)->backward() );
00848 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
00849 }
00850 }
00851 }
00852 else if( ( end == 1 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) {
00853 double time1 = ((*iter).second)->tdc1();
00854 double time2 = pmt->tdc();
00855
00856 if( ( TofID::is_scin( iden ) && abs(time1-time2)<timeDiff ) || ( TofID::is_scin( iden ) && abs(time1-time2)<timeDiffMRPC ) ) {
00857 used = true;
00858 if( ( ( (*iter).second)->quality() & 0x1 ) == 0 ) {
00859 ((*iter).second)->setBackward( pmt );
00860 }
00861 else {
00862 TofData* tof = new TofData;
00863 tof->setIdentify( iden );
00864 tof->setForward( ((*iter).second)->forward() );
00865 tof->setBackward( pmt );
00866 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
00867 }
00868 }
00869 }
00870 }
00871 if( ! used ) {
00872 TofData* tof = new TofData;
00873 tof->setIdentify( iden );
00874 if( end == 0 ) {
00875 tof->setForward( pmt );
00876 }
00877 else {
00878 tof->setBackward( pmt );
00879 }
00880 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
00881 }
00882 }
00883 }
00884 }
00885
00886 return m_tofDataMapOnline;
00887
00888 }
00889
00890
00891 TofDataVector& TofRawDataProvider::tofDataVectorOnlineMode(uint32_t control) {
00892
00893 MsgStream log(m_msgSvc, m_name);
00894 log << MSG::INFO << "TofRawDataProvider::tofDataVectorOnlineMode()" << endreq;
00895
00896 if( m_tofDataVectorOnline.size() != 0 ) {
00897 if(!control) return m_tofDataVectorOnline;
00898 else m_tofDataVectorOnline.clear();
00899 }
00900 TofDataMap tofRawDataMap = TofRawDataProvider::tofDataMapOnlineMode(control);
00901 IterTofDataMap iter = tofRawDataMap.begin();
00902 for( ; iter != tofRawDataMap.end(); iter++ ) {
00903 m_tofDataVectorOnline.push_back( iter->second );
00904 }
00905
00906 return m_tofDataVectorOnline;
00907 }
00908
00909
00910
00911 TofDataMap& TofRawDataProvider::tofDataMapEstime() {
00912
00913 if( !m_hasFilled ) {
00914 TofRawDataProvider::tofDataMapFull();
00915 m_hasFilled = true;
00916 }
00917
00918 if( !m_tofDataMapEstime.empty() ) {
00919 m_tofDataMapEstime.clear();
00920 }
00921
00922 IterTofDataMap iter = m_tofDataMap.begin();
00923 for( ; iter != m_tofDataMap.end(); iter++ ) {
00924 if( ( ( ((*iter).second)->quality() & 0x5 ) != 0 ) && ((*iter).second)->tmatched() ) {
00925 m_tofDataMapEstime.insert( make_pair( (*iter).first, (*iter).second ) );
00926 }
00927 }
00928
00929 iter = m_tofDataMapEstime.begin();
00930 while( iter != m_tofDataMapEstime.end() ) {
00931 unsigned int iden_value = (*iter).first;
00932 unsigned int count = m_tofDataMapEstime.count( iden_value );
00933 for( unsigned int i=0; i != count; i++, iter++ ) {
00934 ((*iter).second)->setTimes( count );
00935 }
00936 }
00937
00938 return m_tofDataMapEstime;
00939 }
00940
00941
00942 TofDataVector& TofRawDataProvider::tofDataVectorEstime() {
00943 if( m_tofDataVectorEstime.size() != 0 ) return m_tofDataVectorEstime;
00944
00945 TofDataMap tofDataMapEstime = TofRawDataProvider::tofDataMapEstime();
00946 IterTofDataMap iter = tofDataMapEstime.begin();
00947 for( ; iter != tofDataMapEstime.end(); iter++ ) {
00948 m_tofDataVectorEstime.push_back( iter->second );
00949 }
00950 return m_tofDataVectorEstime;
00951 }
00952
00953
00954
00955 TofDataMap& TofRawDataProvider::tofDataMapTof( double estime ) {
00956
00957 if( !m_hasFilled ) {
00958 TofRawDataProvider::tofDataMapFull();
00959 m_hasFilled = true;
00960 }
00961
00962 if( !m_tofDataMapTof.empty() ) {
00963 m_tofDataMapTof.clear();
00964 }
00965
00966 IterTofDataMap iter = m_tofDataMap.begin();
00967 for( ; iter != m_tofDataMap.end(); iter++ ) {
00968 if( ( ( ((*iter).second)->quality() & 0xc ) == 0xc ) || ( ( ((*iter).second)->quality() & 0x3 ) == 0x3 ) ) {
00969 if( estime > 1.0e-6 ) {
00970 double tdc1 = ((*iter).second)->tdc1();
00971 double tdc2 = ((*iter).second)->tdc2();
00972 bool forward = ( ( ( estime - tdc1 ) < timeBackward ) && ( ( tdc1 - estime ) < timeForward ) );
00973 bool backward = ( ( ( estime - tdc2 ) < timeBackward ) && ( ( tdc2 - estime ) < timeForward ) );
00974 if( TofID::is_mrpc( TofID::cell_id((*iter).first) ) && m_run>=43680 && m_run<43809 ) {
00975 double offset = -264.0;
00976 forward = ( ( ( estime - tdc1 ) < ( timeBackward - offset ) ) && ( ( tdc1 - estime ) < ( timeForward + offset ) ) );
00977 backward = ( ( ( estime - tdc2 ) < ( timeBackward + offset ) ) && ( ( tdc2 - estime ) < ( timeForward + offset ) ) );
00978 }
00979 if( !forward && !backward ) continue;
00980 }
00981 m_tofDataMapTof.insert( make_pair( (*iter).first, (*iter).second ) );
00982 }
00983 }
00984
00985 iter = m_tofDataMapTof.begin();
00986 while( iter != m_tofDataMapTof.end() ) {
00987 unsigned int iden_value = (*iter).first;
00988 unsigned int count = m_tofDataMapTof.count( iden_value );
00989 for( unsigned int i=0; i != count; i++, iter++ ) {
00990 ((*iter).second)->setTimes( count );
00991 }
00992 }
00993
00994 return m_tofDataMapTof;
00995 }
00996
00997
00998 TofDataVector& TofRawDataProvider::tofDataVectorTof( double estime ) {
00999 if( m_tofDataVectorTof.size() != 0 ) {
01000 m_tofDataVectorTof.clear();
01001 }
01002
01003 TofDataMap tofDataMapTof = TofRawDataProvider::tofDataMapTof( estime );
01004 IterTofDataMap iter = tofDataMapTof.begin();
01005 for( ; iter != tofDataMapTof.end(); iter++ ) {
01006 m_tofDataVectorTof.push_back( iter->second );
01007 }
01008 return m_tofDataVectorTof;
01009 }
01010
01011
01012
01013 TofDataMap& TofRawDataProvider::tofDataMapEmc( double estime ) {
01014
01015 if( !m_hasFilled ) {
01016 TofRawDataProvider::tofDataMapFull();
01017 m_hasFilled = true;
01018 }
01019
01020 if( !m_tofDataMapEmc.empty() ) {
01021 m_tofDataMapEmc.clear();
01022 }
01023
01024 IterTofDataMap iter = m_tofDataMap.begin();
01025 for( ; iter != m_tofDataMap.end(); iter++ ) {
01026 if( ( ((*iter).second)->quality() & 0xa ) != 0 ) {
01027
01028 if( estime > 1.0e-6 ) {
01029 int t0clock = static_cast<int>(estime/24.0);
01030 int clock1 = ((*iter).second)->qclock1();
01031 int clock2 = ((*iter).second)->qclock2();
01032 bool forward = ( ( ( t0clock - clock1 ) < tClockBackward ) && ( ( clock1 - t0clock ) < tClockForward ) );
01033 bool backward = ( ( ( t0clock - clock2 ) < tClockBackward ) && ( ( clock2 - t0clock ) < tClockForward ) );
01034 if( TofID::is_mrpc( TofID::cell_id((*iter).first) ) && m_run>=43680 && m_run<43809 ) {
01035 double offset = -11.0;
01036 forward = ( ( ( t0clock - clock1 ) < ( tClockBackward -offset ) ) && ( ( clock1 - t0clock ) < ( tClockForward + offset ) ) );
01037 backward = ( ( ( t0clock - clock2 ) < ( tClockBackward - offset ) ) && ( ( clock2 - t0clock ) < ( tClockForward + offset ) ) );
01038 }
01039 if( !forward && !backward ) continue;
01040 }
01041
01042 m_tofDataMapEmc.insert( make_pair( (*iter).first, (*iter).second ) );
01043 }
01044 }
01045
01046 iter = m_tofDataMapEmc.begin();
01047 while( iter != m_tofDataMapEmc.end() ) {
01048 unsigned int iden_value = (*iter).first;
01049 unsigned int count = m_tofDataMapEmc.count( iden_value );
01050 for( unsigned int i=0; i != count; i++, iter++ ) {
01051 ((*iter).second)->setTimes( count );
01052 }
01053 }
01054
01055 return m_tofDataMapEmc;
01056 }
01057
01058
01059 TofDataVector& TofRawDataProvider::tofDataVectorEmc( double estime ) {
01060 if( m_tofDataVectorEmc.size() != 0 ) {
01061 m_tofDataVectorEmc.clear();
01062 }
01063
01064 TofDataMap tofDataMapEmc = TofRawDataProvider::tofDataMapEmc( estime );
01065 IterTofDataMap iter = tofDataMapEmc.begin();
01066 for( ; iter != tofDataMapEmc.end(); iter++ ) {
01067 m_tofDataVectorEmc.push_back( iter->second );
01068 }
01069 return m_tofDataVectorEmc;
01070 }